gmock.h
Go to the documentation of this file.
00001 // Copyright 2007, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 
00032 // Google Mock - a framework for writing C++ mock classes.
00033 //
00034 // This is the main header file a user should include.
00035 
00036 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
00037 #define GMOCK_INCLUDE_GMOCK_GMOCK_H_
00038 
00039 // This file implements the following syntax:
00040 //
00041 //   ON_CALL(mock_object.Method(...))
00042 //     .With(...) ?
00043 //     .WillByDefault(...);
00044 //
00045 // where With() is optional and WillByDefault() must appear exactly
00046 // once.
00047 //
00048 //   EXPECT_CALL(mock_object.Method(...))
00049 //     .With(...) ?
00050 //     .Times(...) ?
00051 //     .InSequence(...) *
00052 //     .WillOnce(...) *
00053 //     .WillRepeatedly(...) ?
00054 //     .RetiresOnSaturation() ? ;
00055 //
00056 // where all clauses are optional and WillOnce() can be repeated.
00057 
00058 // Copyright 2007, Google Inc.
00059 // All rights reserved.
00060 //
00061 // Redistribution and use in source and binary forms, with or without
00062 // modification, are permitted provided that the following conditions are
00063 // met:
00064 //
00065 //     * Redistributions of source code must retain the above copyright
00066 // notice, this list of conditions and the following disclaimer.
00067 //     * Redistributions in binary form must reproduce the above
00068 // copyright notice, this list of conditions and the following disclaimer
00069 // in the documentation and/or other materials provided with the
00070 // distribution.
00071 //     * Neither the name of Google Inc. nor the names of its
00072 // contributors may be used to endorse or promote products derived from
00073 // this software without specific prior written permission.
00074 //
00075 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00076 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00077 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00078 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00079 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00080 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00081 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00082 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00083 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00084 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00085 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00086 //
00087 // Author: wan@google.com (Zhanyong Wan)
00088 
00089 // Google Mock - a framework for writing C++ mock classes.
00090 //
00091 // This file implements some commonly used actions.
00092 
00093 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
00094 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
00095 
00096 #ifndef _WIN32_WCE
00097 # include <errno.h>
00098 #endif
00099 
00100 #include <algorithm>
00101 #include <string>
00102 
00103 // Copyright 2007, Google Inc.
00104 // All rights reserved.
00105 //
00106 // Redistribution and use in source and binary forms, with or without
00107 // modification, are permitted provided that the following conditions are
00108 // met:
00109 //
00110 //     * Redistributions of source code must retain the above copyright
00111 // notice, this list of conditions and the following disclaimer.
00112 //     * Redistributions in binary form must reproduce the above
00113 // copyright notice, this list of conditions and the following disclaimer
00114 // in the documentation and/or other materials provided with the
00115 // distribution.
00116 //     * Neither the name of Google Inc. nor the names of its
00117 // contributors may be used to endorse or promote products derived from
00118 // this software without specific prior written permission.
00119 //
00120 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00121 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00122 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00123 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00124 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00125 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00126 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00127 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00128 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00129 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00130 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00131 //
00132 // Author: wan@google.com (Zhanyong Wan)
00133 
00134 // Google Mock - a framework for writing C++ mock classes.
00135 //
00136 // This file defines some utilities useful for implementing Google
00137 // Mock.  They are subject to change without notice, so please DO NOT
00138 // USE THEM IN USER CODE.
00139 
00140 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
00141 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
00142 
00143 #include <stdio.h>
00144 #include <ostream>  // NOLINT
00145 #include <string>
00146 
00147 // This file was GENERATED by command:
00148 //     pump.py gmock-generated-internal-utils.h.pump
00149 // DO NOT EDIT BY HAND!!!
00150 
00151 // Copyright 2007, Google Inc.
00152 // All rights reserved.
00153 //
00154 // Redistribution and use in source and binary forms, with or without
00155 // modification, are permitted provided that the following conditions are
00156 // met:
00157 //
00158 //     * Redistributions of source code must retain the above copyright
00159 // notice, this list of conditions and the following disclaimer.
00160 //     * Redistributions in binary form must reproduce the above
00161 // copyright notice, this list of conditions and the following disclaimer
00162 // in the documentation and/or other materials provided with the
00163 // distribution.
00164 //     * Neither the name of Google Inc. nor the names of its
00165 // contributors may be used to endorse or promote products derived from
00166 // this software without specific prior written permission.
00167 //
00168 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00169 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00170 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00171 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00172 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00173 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00174 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00175 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00176 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00177 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00178 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00179 //
00180 // Author: wan@google.com (Zhanyong Wan)
00181 
00182 // Google Mock - a framework for writing C++ mock classes.
00183 //
00184 // This file contains template meta-programming utility classes needed
00185 // for implementing Google Mock.
00186 
00187 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
00188 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
00189 
00190 // Copyright 2008, Google Inc.
00191 // All rights reserved.
00192 //
00193 // Redistribution and use in source and binary forms, with or without
00194 // modification, are permitted provided that the following conditions are
00195 // met:
00196 //
00197 //     * Redistributions of source code must retain the above copyright
00198 // notice, this list of conditions and the following disclaimer.
00199 //     * Redistributions in binary form must reproduce the above
00200 // copyright notice, this list of conditions and the following disclaimer
00201 // in the documentation and/or other materials provided with the
00202 // distribution.
00203 //     * Neither the name of Google Inc. nor the names of its
00204 // contributors may be used to endorse or promote products derived from
00205 // this software without specific prior written permission.
00206 //
00207 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00208 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00209 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00210 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00211 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00212 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00213 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00214 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00215 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00216 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00217 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00218 //
00219 // Author: vadimb@google.com (Vadim Berman)
00220 //
00221 // Low-level types and utilities for porting Google Mock to various
00222 // platforms.  They are subject to change without notice.  DO NOT USE
00223 // THEM IN USER CODE.
00224 
00225 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
00226 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
00227 
00228 #include <assert.h>
00229 #include <stdlib.h>
00230 #include <iostream>
00231 
00232 // Most of the types needed for porting Google Mock are also required
00233 // for Google Test and are defined in gtest-port.h.
00234 #include "gtest/gtest.h"
00235 
00236 // To avoid conditional compilation everywhere, we make it
00237 // gmock-port.h's responsibility to #include the header implementing
00238 // tr1/tuple.  gmock-port.h does this via gtest-port.h, which is
00239 // guaranteed to pull in the tuple header.
00240 
00241 // For MS Visual C++, check the compiler version. At least VS 2003 is
00242 // required to compile Google Mock.
00243 #if defined(_MSC_VER) && _MSC_VER < 1310
00244 # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
00245 #endif
00246 
00247 // Macro for referencing flags.  This is public as we want the user to
00248 // use this syntax to reference Google Mock flags.
00249 #define GMOCK_FLAG(name) FLAGS_gmock_##name
00250 
00251 // Macros for declaring flags.
00252 #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
00253 #define GMOCK_DECLARE_int32_(name) \
00254     extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
00255 #define GMOCK_DECLARE_string_(name) \
00256     extern GTEST_API_ ::std::string GMOCK_FLAG(name)
00257 
00258 // Macros for defining flags.
00259 #define GMOCK_DEFINE_bool_(name, default_val, doc) \
00260     GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
00261 #define GMOCK_DEFINE_int32_(name, default_val, doc) \
00262     GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
00263 #define GMOCK_DEFINE_string_(name, default_val, doc) \
00264     GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
00265 
00266 #endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
00267 
00268 namespace testing {
00269 
00270 template <typename T>
00271 class Matcher;
00272 
00273 namespace internal {
00274 
00275 // An IgnoredValue object can be implicitly constructed from ANY value.
00276 // This is used in implementing the IgnoreResult(a) action.
00277 class IgnoredValue {
00278  public:
00279   // This constructor template allows any value to be implicitly
00280   // converted to IgnoredValue.  The object has no data member and
00281   // doesn't try to remember anything about the argument.  We
00282   // deliberately omit the 'explicit' keyword in order to allow the
00283   // conversion to be implicit.
00284   template <typename T>
00285   IgnoredValue(const T& /* ignored */) {}  // NOLINT(runtime/explicit)
00286 };
00287 
00288 // MatcherTuple<T>::type is a tuple type where each field is a Matcher
00289 // for the corresponding field in tuple type T.
00290 template <typename Tuple>
00291 struct MatcherTuple;
00292 
00293 template <>
00294 struct MatcherTuple< ::std::tr1::tuple<> > {
00295   typedef ::std::tr1::tuple< > type;
00296 };
00297 
00298 template <typename A1>
00299 struct MatcherTuple< ::std::tr1::tuple<A1> > {
00300   typedef ::std::tr1::tuple<Matcher<A1> > type;
00301 };
00302 
00303 template <typename A1, typename A2>
00304 struct MatcherTuple< ::std::tr1::tuple<A1, A2> > {
00305   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2> > type;
00306 };
00307 
00308 template <typename A1, typename A2, typename A3>
00309 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3> > {
00310   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
00311 };
00312 
00313 template <typename A1, typename A2, typename A3, typename A4>
00314 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4> > {
00315   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
00316       Matcher<A4> > type;
00317 };
00318 
00319 template <typename A1, typename A2, typename A3, typename A4, typename A5>
00320 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
00321   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00322       Matcher<A5> > type;
00323 };
00324 
00325 template <typename A1, typename A2, typename A3, typename A4, typename A5,
00326     typename A6>
00327 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
00328   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00329       Matcher<A5>, Matcher<A6> > type;
00330 };
00331 
00332 template <typename A1, typename A2, typename A3, typename A4, typename A5,
00333     typename A6, typename A7>
00334 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
00335   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00336       Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
00337 };
00338 
00339 template <typename A1, typename A2, typename A3, typename A4, typename A5,
00340     typename A6, typename A7, typename A8>
00341 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
00342   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00343       Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
00344 };
00345 
00346 template <typename A1, typename A2, typename A3, typename A4, typename A5,
00347     typename A6, typename A7, typename A8, typename A9>
00348 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
00349   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00350       Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
00351 };
00352 
00353 template <typename A1, typename A2, typename A3, typename A4, typename A5,
00354     typename A6, typename A7, typename A8, typename A9, typename A10>
00355 struct MatcherTuple< ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
00356     A10> > {
00357   typedef ::std::tr1::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
00358       Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
00359       Matcher<A10> > type;
00360 };
00361 
00362 // Template struct Function<F>, where F must be a function type, contains
00363 // the following typedefs:
00364 //
00365 //   Result:               the function's return type.
00366 //   ArgumentN:            the type of the N-th argument, where N starts with 1.
00367 //   ArgumentTuple:        the tuple type consisting of all parameters of F.
00368 //   ArgumentMatcherTuple: the tuple type consisting of Matchers for all
00369 //                         parameters of F.
00370 //   MakeResultVoid:       the function type obtained by substituting void
00371 //                         for the return type of F.
00372 //   MakeResultIgnoredValue:
00373 //                         the function type obtained by substituting Something
00374 //                         for the return type of F.
00375 template <typename F>
00376 struct Function;
00377 
00378 template <typename R>
00379 struct Function<R()> {
00380   typedef R Result;
00381   typedef ::std::tr1::tuple<> ArgumentTuple;
00382   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00383   typedef void MakeResultVoid();
00384   typedef IgnoredValue MakeResultIgnoredValue();
00385 };
00386 
00387 template <typename R, typename A1>
00388 struct Function<R(A1)>
00389     : Function<R()> {
00390   typedef A1 Argument1;
00391   typedef ::std::tr1::tuple<A1> ArgumentTuple;
00392   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00393   typedef void MakeResultVoid(A1);
00394   typedef IgnoredValue MakeResultIgnoredValue(A1);
00395 };
00396 
00397 template <typename R, typename A1, typename A2>
00398 struct Function<R(A1, A2)>
00399     : Function<R(A1)> {
00400   typedef A2 Argument2;
00401   typedef ::std::tr1::tuple<A1, A2> ArgumentTuple;
00402   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00403   typedef void MakeResultVoid(A1, A2);
00404   typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
00405 };
00406 
00407 template <typename R, typename A1, typename A2, typename A3>
00408 struct Function<R(A1, A2, A3)>
00409     : Function<R(A1, A2)> {
00410   typedef A3 Argument3;
00411   typedef ::std::tr1::tuple<A1, A2, A3> ArgumentTuple;
00412   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00413   typedef void MakeResultVoid(A1, A2, A3);
00414   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
00415 };
00416 
00417 template <typename R, typename A1, typename A2, typename A3, typename A4>
00418 struct Function<R(A1, A2, A3, A4)>
00419     : Function<R(A1, A2, A3)> {
00420   typedef A4 Argument4;
00421   typedef ::std::tr1::tuple<A1, A2, A3, A4> ArgumentTuple;
00422   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00423   typedef void MakeResultVoid(A1, A2, A3, A4);
00424   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
00425 };
00426 
00427 template <typename R, typename A1, typename A2, typename A3, typename A4,
00428     typename A5>
00429 struct Function<R(A1, A2, A3, A4, A5)>
00430     : Function<R(A1, A2, A3, A4)> {
00431   typedef A5 Argument5;
00432   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
00433   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00434   typedef void MakeResultVoid(A1, A2, A3, A4, A5);
00435   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
00436 };
00437 
00438 template <typename R, typename A1, typename A2, typename A3, typename A4,
00439     typename A5, typename A6>
00440 struct Function<R(A1, A2, A3, A4, A5, A6)>
00441     : Function<R(A1, A2, A3, A4, A5)> {
00442   typedef A6 Argument6;
00443   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
00444   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00445   typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
00446   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
00447 };
00448 
00449 template <typename R, typename A1, typename A2, typename A3, typename A4,
00450     typename A5, typename A6, typename A7>
00451 struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
00452     : Function<R(A1, A2, A3, A4, A5, A6)> {
00453   typedef A7 Argument7;
00454   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
00455   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00456   typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
00457   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
00458 };
00459 
00460 template <typename R, typename A1, typename A2, typename A3, typename A4,
00461     typename A5, typename A6, typename A7, typename A8>
00462 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
00463     : Function<R(A1, A2, A3, A4, A5, A6, A7)> {
00464   typedef A8 Argument8;
00465   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
00466   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00467   typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
00468   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
00469 };
00470 
00471 template <typename R, typename A1, typename A2, typename A3, typename A4,
00472     typename A5, typename A6, typename A7, typename A8, typename A9>
00473 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
00474     : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
00475   typedef A9 Argument9;
00476   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
00477   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00478   typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
00479   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
00480       A9);
00481 };
00482 
00483 template <typename R, typename A1, typename A2, typename A3, typename A4,
00484     typename A5, typename A6, typename A7, typename A8, typename A9,
00485     typename A10>
00486 struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
00487     : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
00488   typedef A10 Argument10;
00489   typedef ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
00490       A10> ArgumentTuple;
00491   typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
00492   typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
00493   typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
00494       A9, A10);
00495 };
00496 
00497 }  // namespace internal
00498 
00499 }  // namespace testing
00500 
00501 #endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
00502 
00503 namespace testing {
00504 namespace internal {
00505 
00506 // Converts an identifier name to a space-separated list of lower-case
00507 // words.  Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
00508 // treated as one word.  For example, both "FooBar123" and
00509 // "foo_bar_123" are converted to "foo bar 123".
00510 GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
00511 
00512 // PointeeOf<Pointer>::type is the type of a value pointed to by a
00513 // Pointer, which can be either a smart pointer or a raw pointer.  The
00514 // following default implementation is for the case where Pointer is a
00515 // smart pointer.
00516 template <typename Pointer>
00517 struct PointeeOf {
00518   // Smart pointer classes define type element_type as the type of
00519   // their pointees.
00520   typedef typename Pointer::element_type type;
00521 };
00522 // This specialization is for the raw pointer case.
00523 template <typename T>
00524 struct PointeeOf<T*> { typedef T type; };  // NOLINT
00525 
00526 // GetRawPointer(p) returns the raw pointer underlying p when p is a
00527 // smart pointer, or returns p itself when p is already a raw pointer.
00528 // The following default implementation is for the smart pointer case.
00529 template <typename Pointer>
00530 inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
00531   return p.get();
00532 }
00533 // This overloaded version is for the raw pointer case.
00534 template <typename Element>
00535 inline Element* GetRawPointer(Element* p) { return p; }
00536 
00537 // This comparator allows linked_ptr to be stored in sets.
00538 template <typename T>
00539 struct LinkedPtrLessThan {
00540   bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
00541                   const ::testing::internal::linked_ptr<T>& rhs) const {
00542     return lhs.get() < rhs.get();
00543   }
00544 };
00545 
00546 // Symbian compilation can be done with wchar_t being either a native
00547 // type or a typedef.  Using Google Mock with OpenC without wchar_t
00548 // should require the definition of _STLP_NO_WCHAR_T.
00549 //
00550 // MSVC treats wchar_t as a native type usually, but treats it as the
00551 // same as unsigned short when the compiler option /Zc:wchar_t- is
00552 // specified.  It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
00553 // is a native type.
00554 #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
00555     (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
00556 // wchar_t is a typedef.
00557 #else
00558 # define GMOCK_WCHAR_T_IS_NATIVE_ 1
00559 #endif
00560 
00561 // signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
00562 // Using them is a bad practice and not portable.  So DON'T use them.
00563 //
00564 // Still, Google Mock is designed to work even if the user uses signed
00565 // wchar_t or unsigned wchar_t (obviously, assuming the compiler
00566 // supports them).
00567 //
00568 // To gcc,
00569 //   wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
00570 #ifdef __GNUC__
00571 // signed/unsigned wchar_t are valid types.
00572 # define GMOCK_HAS_SIGNED_WCHAR_T_ 1
00573 #endif
00574 
00575 // In what follows, we use the term "kind" to indicate whether a type
00576 // is bool, an integer type (excluding bool), a floating-point type,
00577 // or none of them.  This categorization is useful for determining
00578 // when a matcher argument type can be safely converted to another
00579 // type in the implementation of SafeMatcherCast.
00580 enum TypeKind {
00581   kBool, kInteger, kFloatingPoint, kOther
00582 };
00583 
00584 // KindOf<T>::value is the kind of type T.
00585 template <typename T> struct KindOf {
00586   enum { value = kOther };  // The default kind.
00587 };
00588 
00589 // This macro declares that the kind of 'type' is 'kind'.
00590 #define GMOCK_DECLARE_KIND_(type, kind) \
00591   template <> struct KindOf<type> { enum { value = kind }; }
00592 
00593 GMOCK_DECLARE_KIND_(bool, kBool);
00594 
00595 // All standard integer types.
00596 GMOCK_DECLARE_KIND_(char, kInteger);
00597 GMOCK_DECLARE_KIND_(signed char, kInteger);
00598 GMOCK_DECLARE_KIND_(unsigned char, kInteger);
00599 GMOCK_DECLARE_KIND_(short, kInteger);  // NOLINT
00600 GMOCK_DECLARE_KIND_(unsigned short, kInteger);  // NOLINT
00601 GMOCK_DECLARE_KIND_(int, kInteger);
00602 GMOCK_DECLARE_KIND_(unsigned int, kInteger);
00603 GMOCK_DECLARE_KIND_(long, kInteger);  // NOLINT
00604 GMOCK_DECLARE_KIND_(unsigned long, kInteger);  // NOLINT
00605 
00606 #if GMOCK_WCHAR_T_IS_NATIVE_
00607 GMOCK_DECLARE_KIND_(wchar_t, kInteger);
00608 #endif
00609 
00610 // Non-standard integer types.
00611 GMOCK_DECLARE_KIND_(Int64, kInteger);
00612 GMOCK_DECLARE_KIND_(UInt64, kInteger);
00613 
00614 // All standard floating-point types.
00615 GMOCK_DECLARE_KIND_(float, kFloatingPoint);
00616 GMOCK_DECLARE_KIND_(double, kFloatingPoint);
00617 GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
00618 
00619 #undef GMOCK_DECLARE_KIND_
00620 
00621 // Evaluates to the kind of 'type'.
00622 #define GMOCK_KIND_OF_(type) \
00623   static_cast< ::testing::internal::TypeKind>( \
00624       ::testing::internal::KindOf<type>::value)
00625 
00626 // Evaluates to true iff integer type T is signed.
00627 #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
00628 
00629 // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
00630 // is true iff arithmetic type From can be losslessly converted to
00631 // arithmetic type To.
00632 //
00633 // It's the user's responsibility to ensure that both From and To are
00634 // raw (i.e. has no CV modifier, is not a pointer, and is not a
00635 // reference) built-in arithmetic types, kFromKind is the kind of
00636 // From, and kToKind is the kind of To; the value is
00637 // implementation-defined when the above pre-condition is violated.
00638 template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
00639 struct LosslessArithmeticConvertibleImpl : public false_type {};
00640 
00641 // Converting bool to bool is lossless.
00642 template <>
00643 struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
00644     : public true_type {};  // NOLINT
00645 
00646 // Converting bool to any integer type is lossless.
00647 template <typename To>
00648 struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
00649     : public true_type {};  // NOLINT
00650 
00651 // Converting bool to any floating-point type is lossless.
00652 template <typename To>
00653 struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
00654     : public true_type {};  // NOLINT
00655 
00656 // Converting an integer to bool is lossy.
00657 template <typename From>
00658 struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
00659     : public false_type {};  // NOLINT
00660 
00661 // Converting an integer to another non-bool integer is lossless iff
00662 // the target type's range encloses the source type's range.
00663 template <typename From, typename To>
00664 struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
00665     : public bool_constant<
00666       // When converting from a smaller size to a larger size, we are
00667       // fine as long as we are not converting from signed to unsigned.
00668       ((sizeof(From) < sizeof(To)) &&
00669        (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
00670       // When converting between the same size, the signedness must match.
00671       ((sizeof(From) == sizeof(To)) &&
00672        (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {};  // NOLINT
00673 
00674 #undef GMOCK_IS_SIGNED_
00675 
00676 // Converting an integer to a floating-point type may be lossy, since
00677 // the format of a floating-point number is implementation-defined.
00678 template <typename From, typename To>
00679 struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
00680     : public false_type {};  // NOLINT
00681 
00682 // Converting a floating-point to bool is lossy.
00683 template <typename From>
00684 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
00685     : public false_type {};  // NOLINT
00686 
00687 // Converting a floating-point to an integer is lossy.
00688 template <typename From, typename To>
00689 struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
00690     : public false_type {};  // NOLINT
00691 
00692 // Converting a floating-point to another floating-point is lossless
00693 // iff the target type is at least as big as the source type.
00694 template <typename From, typename To>
00695 struct LosslessArithmeticConvertibleImpl<
00696   kFloatingPoint, From, kFloatingPoint, To>
00697     : public bool_constant<sizeof(From) <= sizeof(To)> {};  // NOLINT
00698 
00699 // LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
00700 // type From can be losslessly converted to arithmetic type To.
00701 //
00702 // It's the user's responsibility to ensure that both From and To are
00703 // raw (i.e. has no CV modifier, is not a pointer, and is not a
00704 // reference) built-in arithmetic types; the value is
00705 // implementation-defined when the above pre-condition is violated.
00706 template <typename From, typename To>
00707 struct LosslessArithmeticConvertible
00708     : public LosslessArithmeticConvertibleImpl<
00709   GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {};  // NOLINT
00710 
00711 // This interface knows how to report a Google Mock failure (either
00712 // non-fatal or fatal).
00713 class FailureReporterInterface {
00714  public:
00715   // The type of a failure (either non-fatal or fatal).
00716   enum FailureType {
00717     kNonfatal, kFatal
00718   };
00719 
00720   virtual ~FailureReporterInterface() {}
00721 
00722   // Reports a failure that occurred at the given source file location.
00723   virtual void ReportFailure(FailureType type, const char* file, int line,
00724                              const string& message) = 0;
00725 };
00726 
00727 // Returns the failure reporter used by Google Mock.
00728 GTEST_API_ FailureReporterInterface* GetFailureReporter();
00729 
00730 // Asserts that condition is true; aborts the process with the given
00731 // message if condition is false.  We cannot use LOG(FATAL) or CHECK()
00732 // as Google Mock might be used to mock the log sink itself.  We
00733 // inline this function to prevent it from showing up in the stack
00734 // trace.
00735 inline void Assert(bool condition, const char* file, int line,
00736                    const string& msg) {
00737   if (!condition) {
00738     GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
00739                                         file, line, msg);
00740   }
00741 }
00742 inline void Assert(bool condition, const char* file, int line) {
00743   Assert(condition, file, line, "Assertion failed.");
00744 }
00745 
00746 // Verifies that condition is true; generates a non-fatal failure if
00747 // condition is false.
00748 inline void Expect(bool condition, const char* file, int line,
00749                    const string& msg) {
00750   if (!condition) {
00751     GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
00752                                         file, line, msg);
00753   }
00754 }
00755 inline void Expect(bool condition, const char* file, int line) {
00756   Expect(condition, file, line, "Expectation failed.");
00757 }
00758 
00759 // Severity level of a log.
00760 enum LogSeverity {
00761   kInfo = 0,
00762   kWarning = 1
00763 };
00764 
00765 // Valid values for the --gmock_verbose flag.
00766 
00767 // All logs (informational and warnings) are printed.
00768 const char kInfoVerbosity[] = "info";
00769 // Only warnings are printed.
00770 const char kWarningVerbosity[] = "warning";
00771 // No logs are printed.
00772 const char kErrorVerbosity[] = "error";
00773 
00774 // Returns true iff a log with the given severity is visible according
00775 // to the --gmock_verbose flag.
00776 GTEST_API_ bool LogIsVisible(LogSeverity severity);
00777 
00778 // Prints the given message to stdout iff 'severity' >= the level
00779 // specified by the --gmock_verbose flag.  If stack_frames_to_skip >=
00780 // 0, also prints the stack trace excluding the top
00781 // stack_frames_to_skip frames.  In opt mode, any positive
00782 // stack_frames_to_skip is treated as 0, since we don't know which
00783 // function calls will be inlined by the compiler and need to be
00784 // conservative.
00785 GTEST_API_ void Log(LogSeverity severity,
00786                     const string& message,
00787                     int stack_frames_to_skip);
00788 
00789 // TODO(wan@google.com): group all type utilities together.
00790 
00791 // Type traits.
00792 
00793 // is_reference<T>::value is non-zero iff T is a reference type.
00794 template <typename T> struct is_reference : public false_type {};
00795 template <typename T> struct is_reference<T&> : public true_type {};
00796 
00797 // type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
00798 template <typename T1, typename T2> struct type_equals : public false_type {};
00799 template <typename T> struct type_equals<T, T> : public true_type {};
00800 
00801 // remove_reference<T>::type removes the reference from type T, if any.
00802 template <typename T> struct remove_reference { typedef T type; };  // NOLINT
00803 template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
00804 
00805 // DecayArray<T>::type turns an array type U[N] to const U* and preserves
00806 // other types.  Useful for saving a copy of a function argument.
00807 template <typename T> struct DecayArray { typedef T type; };  // NOLINT
00808 template <typename T, size_t N> struct DecayArray<T[N]> {
00809   typedef const T* type;
00810 };
00811 // Sometimes people use arrays whose size is not available at the use site
00812 // (e.g. extern const char kNamePrefix[]).  This specialization covers that
00813 // case.
00814 template <typename T> struct DecayArray<T[]> {
00815   typedef const T* type;
00816 };
00817 
00818 // Invalid<T>() returns an invalid value of type T.  This is useful
00819 // when a value of type T is needed for compilation, but the statement
00820 // will not really be executed (or we don't care if the statement
00821 // crashes).
00822 template <typename T>
00823 inline T Invalid() {
00824   return const_cast<typename remove_reference<T>::type&>(
00825       *static_cast<volatile typename remove_reference<T>::type*>(NULL));
00826 }
00827 template <>
00828 inline void Invalid<void>() {}
00829 
00830 // Given a raw type (i.e. having no top-level reference or const
00831 // modifier) RawContainer that's either an STL-style container or a
00832 // native array, class StlContainerView<RawContainer> has the
00833 // following members:
00834 //
00835 //   - type is a type that provides an STL-style container view to
00836 //     (i.e. implements the STL container concept for) RawContainer;
00837 //   - const_reference is a type that provides a reference to a const
00838 //     RawContainer;
00839 //   - ConstReference(raw_container) returns a const reference to an STL-style
00840 //     container view to raw_container, which is a RawContainer.
00841 //   - Copy(raw_container) returns an STL-style container view of a
00842 //     copy of raw_container, which is a RawContainer.
00843 //
00844 // This generic version is used when RawContainer itself is already an
00845 // STL-style container.
00846 template <class RawContainer>
00847 class StlContainerView {
00848  public:
00849   typedef RawContainer type;
00850   typedef const type& const_reference;
00851 
00852   static const_reference ConstReference(const RawContainer& container) {
00853     // Ensures that RawContainer is not a const type.
00854     testing::StaticAssertTypeEq<RawContainer,
00855         GTEST_REMOVE_CONST_(RawContainer)>();
00856     return container;
00857   }
00858   static type Copy(const RawContainer& container) { return container; }
00859 };
00860 
00861 // This specialization is used when RawContainer is a native array type.
00862 template <typename Element, size_t N>
00863 class StlContainerView<Element[N]> {
00864  public:
00865   typedef GTEST_REMOVE_CONST_(Element) RawElement;
00866   typedef internal::NativeArray<RawElement> type;
00867   // NativeArray<T> can represent a native array either by value or by
00868   // reference (selected by a constructor argument), so 'const type'
00869   // can be used to reference a const native array.  We cannot
00870   // 'typedef const type& const_reference' here, as that would mean
00871   // ConstReference() has to return a reference to a local variable.
00872   typedef const type const_reference;
00873 
00874   static const_reference ConstReference(const Element (&array)[N]) {
00875     // Ensures that Element is not a const type.
00876     testing::StaticAssertTypeEq<Element, RawElement>();
00877 #if GTEST_OS_SYMBIAN
00878     // The Nokia Symbian compiler confuses itself in template instantiation
00879     // for this call without the cast to Element*:
00880     // function call '[testing::internal::NativeArray<char *>].NativeArray(
00881     //     {lval} const char *[4], long, testing::internal::RelationToSource)'
00882     //     does not match
00883     // 'testing::internal::NativeArray<char *>::NativeArray(
00884     //     char *const *, unsigned int, testing::internal::RelationToSource)'
00885     // (instantiating: 'testing::internal::ContainsMatcherImpl
00886     //     <const char * (&)[4]>::Matches(const char * (&)[4]) const')
00887     // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
00888     //     ConstReference(const char * (&)[4])')
00889     // (and though the N parameter type is mismatched in the above explicit
00890     // conversion of it doesn't help - only the conversion of the array).
00891     return type(const_cast<Element*>(&array[0]), N, kReference);
00892 #else
00893     return type(array, N, kReference);
00894 #endif  // GTEST_OS_SYMBIAN
00895   }
00896   static type Copy(const Element (&array)[N]) {
00897 #if GTEST_OS_SYMBIAN
00898     return type(const_cast<Element*>(&array[0]), N, kCopy);
00899 #else
00900     return type(array, N, kCopy);
00901 #endif  // GTEST_OS_SYMBIAN
00902   }
00903 };
00904 
00905 // This specialization is used when RawContainer is a native array
00906 // represented as a (pointer, size) tuple.
00907 template <typename ElementPointer, typename Size>
00908 class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > {
00909  public:
00910   typedef GTEST_REMOVE_CONST_(
00911       typename internal::PointeeOf<ElementPointer>::type) RawElement;
00912   typedef internal::NativeArray<RawElement> type;
00913   typedef const type const_reference;
00914 
00915   static const_reference ConstReference(
00916       const ::std::tr1::tuple<ElementPointer, Size>& array) {
00917     using ::std::tr1::get;
00918     return type(get<0>(array), get<1>(array), kReference);
00919   }
00920   static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) {
00921     using ::std::tr1::get;
00922     return type(get<0>(array), get<1>(array), kCopy);
00923   }
00924 };
00925 
00926 // The following specialization prevents the user from instantiating
00927 // StlContainer with a reference type.
00928 template <typename T> class StlContainerView<T&>;
00929 
00930 // A type transform to remove constness from the first part of a pair.
00931 // Pairs like that are used as the value_type of associative containers,
00932 // and this transform produces a similar but assignable pair.
00933 template <typename T>
00934 struct RemoveConstFromKey {
00935   typedef T type;
00936 };
00937 
00938 // Partially specialized to remove constness from std::pair<const K, V>.
00939 template <typename K, typename V>
00940 struct RemoveConstFromKey<std::pair<const K, V> > {
00941   typedef std::pair<K, V> type;
00942 };
00943 
00944 // Mapping from booleans to types. Similar to boost::bool_<kValue> and
00945 // std::integral_constant<bool, kValue>.
00946 template <bool kValue>
00947 struct BooleanConstant {};
00948 
00949 }  // namespace internal
00950 }  // namespace testing
00951 
00952 #endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
00953 
00954 namespace testing {
00955 
00956 // To implement an action Foo, define:
00957 //   1. a class FooAction that implements the ActionInterface interface, and
00958 //   2. a factory function that creates an Action object from a
00959 //      const FooAction*.
00960 //
00961 // The two-level delegation design follows that of Matcher, providing
00962 // consistency for extension developers.  It also eases ownership
00963 // management as Action objects can now be copied like plain values.
00964 
00965 namespace internal {
00966 
00967 template <typename F1, typename F2>
00968 class ActionAdaptor;
00969 
00970 // BuiltInDefaultValue<T>::Get() returns the "built-in" default
00971 // value for type T, which is NULL when T is a pointer type, 0 when T
00972 // is a numeric type, false when T is bool, or "" when T is string or
00973 // std::string.  For any other type T, this value is undefined and the
00974 // function will abort the process.
00975 template <typename T>
00976 class BuiltInDefaultValue {
00977  public:
00978   // This function returns true iff type T has a built-in default value.
00979   static bool Exists() { return false; }
00980   static T Get() {
00981     Assert(false, __FILE__, __LINE__,
00982            "Default action undefined for the function return type.");
00983     return internal::Invalid<T>();
00984     // The above statement will never be reached, but is required in
00985     // order for this function to compile.
00986   }
00987 };
00988 
00989 // This partial specialization says that we use the same built-in
00990 // default value for T and const T.
00991 template <typename T>
00992 class BuiltInDefaultValue<const T> {
00993  public:
00994   static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
00995   static T Get() { return BuiltInDefaultValue<T>::Get(); }
00996 };
00997 
00998 // This partial specialization defines the default values for pointer
00999 // types.
01000 template <typename T>
01001 class BuiltInDefaultValue<T*> {
01002  public:
01003   static bool Exists() { return true; }
01004   static T* Get() { return NULL; }
01005 };
01006 
01007 // The following specializations define the default values for
01008 // specific types we care about.
01009 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
01010   template <> \
01011   class BuiltInDefaultValue<type> { \
01012    public: \
01013     static bool Exists() { return true; } \
01014     static type Get() { return value; } \
01015   }
01016 
01017 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, );  // NOLINT
01018 #if GTEST_HAS_GLOBAL_STRING
01019 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
01020 #endif  // GTEST_HAS_GLOBAL_STRING
01021 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
01022 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
01023 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
01024 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
01025 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
01026 
01027 // There's no need for a default action for signed wchar_t, as that
01028 // type is the same as wchar_t for gcc, and invalid for MSVC.
01029 //
01030 // There's also no need for a default action for unsigned wchar_t, as
01031 // that type is the same as unsigned int for gcc, and invalid for
01032 // MSVC.
01033 #if GMOCK_WCHAR_T_IS_NATIVE_
01034 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U);  // NOLINT
01035 #endif
01036 
01037 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U);  // NOLINT
01038 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0);     // NOLINT
01039 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
01040 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
01041 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL);  // NOLINT
01042 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L);     // NOLINT
01043 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
01044 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
01045 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
01046 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
01047 
01048 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
01049 
01050 }  // namespace internal
01051 
01052 // When an unexpected function call is encountered, Google Mock will
01053 // let it return a default value if the user has specified one for its
01054 // return type, or if the return type has a built-in default value;
01055 // otherwise Google Mock won't know what value to return and will have
01056 // to abort the process.
01057 //
01058 // The DefaultValue<T> class allows a user to specify the
01059 // default value for a type T that is both copyable and publicly
01060 // destructible (i.e. anything that can be used as a function return
01061 // type).  The usage is:
01062 //
01063 //   // Sets the default value for type T to be foo.
01064 //   DefaultValue<T>::Set(foo);
01065 template <typename T>
01066 class DefaultValue {
01067  public:
01068   // Sets the default value for type T; requires T to be
01069   // copy-constructable and have a public destructor.
01070   static void Set(T x) {
01071     delete value_;
01072     value_ = new T(x);
01073   }
01074 
01075   // Unsets the default value for type T.
01076   static void Clear() {
01077     delete value_;
01078     value_ = NULL;
01079   }
01080 
01081   // Returns true iff the user has set the default value for type T.
01082   static bool IsSet() { return value_ != NULL; }
01083 
01084   // Returns true if T has a default return value set by the user or there
01085   // exists a built-in default value.
01086   static bool Exists() {
01087     return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
01088   }
01089 
01090   // Returns the default value for type T if the user has set one;
01091   // otherwise returns the built-in default value if there is one;
01092   // otherwise aborts the process.
01093   static T Get() {
01094     return value_ == NULL ?
01095         internal::BuiltInDefaultValue<T>::Get() : *value_;
01096   }
01097 
01098  private:
01099   static const T* value_;
01100 };
01101 
01102 // This partial specialization allows a user to set default values for
01103 // reference types.
01104 template <typename T>
01105 class DefaultValue<T&> {
01106  public:
01107   // Sets the default value for type T&.
01108   static void Set(T& x) {  // NOLINT
01109     address_ = &x;
01110   }
01111 
01112   // Unsets the default value for type T&.
01113   static void Clear() {
01114     address_ = NULL;
01115   }
01116 
01117   // Returns true iff the user has set the default value for type T&.
01118   static bool IsSet() { return address_ != NULL; }
01119 
01120   // Returns true if T has a default return value set by the user or there
01121   // exists a built-in default value.
01122   static bool Exists() {
01123     return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
01124   }
01125 
01126   // Returns the default value for type T& if the user has set one;
01127   // otherwise returns the built-in default value if there is one;
01128   // otherwise aborts the process.
01129   static T& Get() {
01130     return address_ == NULL ?
01131         internal::BuiltInDefaultValue<T&>::Get() : *address_;
01132   }
01133 
01134  private:
01135   static T* address_;
01136 };
01137 
01138 // This specialization allows DefaultValue<void>::Get() to
01139 // compile.
01140 template <>
01141 class DefaultValue<void> {
01142  public:
01143   static bool Exists() { return true; }
01144   static void Get() {}
01145 };
01146 
01147 // Points to the user-set default value for type T.
01148 template <typename T>
01149 const T* DefaultValue<T>::value_ = NULL;
01150 
01151 // Points to the user-set default value for type T&.
01152 template <typename T>
01153 T* DefaultValue<T&>::address_ = NULL;
01154 
01155 // Implement this interface to define an action for function type F.
01156 template <typename F>
01157 class ActionInterface {
01158  public:
01159   typedef typename internal::Function<F>::Result Result;
01160   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
01161 
01162   ActionInterface() {}
01163   virtual ~ActionInterface() {}
01164 
01165   // Performs the action.  This method is not const, as in general an
01166   // action can have side effects and be stateful.  For example, a
01167   // get-the-next-element-from-the-collection action will need to
01168   // remember the current element.
01169   virtual Result Perform(const ArgumentTuple& args) = 0;
01170 
01171  private:
01172   GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
01173 };
01174 
01175 // An Action<F> is a copyable and IMMUTABLE (except by assignment)
01176 // object that represents an action to be taken when a mock function
01177 // of type F is called.  The implementation of Action<T> is just a
01178 // linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
01179 // Don't inherit from Action!
01180 //
01181 // You can view an object implementing ActionInterface<F> as a
01182 // concrete action (including its current state), and an Action<F>
01183 // object as a handle to it.
01184 template <typename F>
01185 class Action {
01186  public:
01187   typedef typename internal::Function<F>::Result Result;
01188   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
01189 
01190   // Constructs a null Action.  Needed for storing Action objects in
01191   // STL containers.
01192   Action() : impl_(NULL) {}
01193 
01194   // Constructs an Action from its implementation.  A NULL impl is
01195   // used to represent the "do-default" action.
01196   explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
01197 
01198   // Copy constructor.
01199   Action(const Action& action) : impl_(action.impl_) {}
01200 
01201   // This constructor allows us to turn an Action<Func> object into an
01202   // Action<F>, as long as F's arguments can be implicitly converted
01203   // to Func's and Func's return type can be implicitly converted to
01204   // F's.
01205   template <typename Func>
01206   explicit Action(const Action<Func>& action);
01207 
01208   // Returns true iff this is the DoDefault() action.
01209   bool IsDoDefault() const { return impl_.get() == NULL; }
01210 
01211   // Performs the action.  Note that this method is const even though
01212   // the corresponding method in ActionInterface is not.  The reason
01213   // is that a const Action<F> means that it cannot be re-bound to
01214   // another concrete action, not that the concrete action it binds to
01215   // cannot change state.  (Think of the difference between a const
01216   // pointer and a pointer to const.)
01217   Result Perform(const ArgumentTuple& args) const {
01218     internal::Assert(
01219         !IsDoDefault(), __FILE__, __LINE__,
01220         "You are using DoDefault() inside a composite action like "
01221         "DoAll() or WithArgs().  This is not supported for technical "
01222         "reasons.  Please instead spell out the default action, or "
01223         "assign the default action to an Action variable and use "
01224         "the variable in various places.");
01225     return impl_->Perform(args);
01226   }
01227 
01228  private:
01229   template <typename F1, typename F2>
01230   friend class internal::ActionAdaptor;
01231 
01232   internal::linked_ptr<ActionInterface<F> > impl_;
01233 };
01234 
01235 // The PolymorphicAction class template makes it easy to implement a
01236 // polymorphic action (i.e. an action that can be used in mock
01237 // functions of than one type, e.g. Return()).
01238 //
01239 // To define a polymorphic action, a user first provides a COPYABLE
01240 // implementation class that has a Perform() method template:
01241 //
01242 //   class FooAction {
01243 //    public:
01244 //     template <typename Result, typename ArgumentTuple>
01245 //     Result Perform(const ArgumentTuple& args) const {
01246 //       // Processes the arguments and returns a result, using
01247 //       // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
01248 //     }
01249 //     ...
01250 //   };
01251 //
01252 // Then the user creates the polymorphic action using
01253 // MakePolymorphicAction(object) where object has type FooAction.  See
01254 // the definition of Return(void) and SetArgumentPointee<N>(value) for
01255 // complete examples.
01256 template <typename Impl>
01257 class PolymorphicAction {
01258  public:
01259   explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
01260 
01261   template <typename F>
01262   operator Action<F>() const {
01263     return Action<F>(new MonomorphicImpl<F>(impl_));
01264   }
01265 
01266  private:
01267   template <typename F>
01268   class MonomorphicImpl : public ActionInterface<F> {
01269    public:
01270     typedef typename internal::Function<F>::Result Result;
01271     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
01272 
01273     explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
01274 
01275     virtual Result Perform(const ArgumentTuple& args) {
01276       return impl_.template Perform<Result>(args);
01277     }
01278 
01279    private:
01280     Impl impl_;
01281 
01282     GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
01283   };
01284 
01285   Impl impl_;
01286 
01287   GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
01288 };
01289 
01290 // Creates an Action from its implementation and returns it.  The
01291 // created Action object owns the implementation.
01292 template <typename F>
01293 Action<F> MakeAction(ActionInterface<F>* impl) {
01294   return Action<F>(impl);
01295 }
01296 
01297 // Creates a polymorphic action from its implementation.  This is
01298 // easier to use than the PolymorphicAction<Impl> constructor as it
01299 // doesn't require you to explicitly write the template argument, e.g.
01300 //
01301 //   MakePolymorphicAction(foo);
01302 // vs
01303 //   PolymorphicAction<TypeOfFoo>(foo);
01304 template <typename Impl>
01305 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
01306   return PolymorphicAction<Impl>(impl);
01307 }
01308 
01309 namespace internal {
01310 
01311 // Allows an Action<F2> object to pose as an Action<F1>, as long as F2
01312 // and F1 are compatible.
01313 template <typename F1, typename F2>
01314 class ActionAdaptor : public ActionInterface<F1> {
01315  public:
01316   typedef typename internal::Function<F1>::Result Result;
01317   typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
01318 
01319   explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
01320 
01321   virtual Result Perform(const ArgumentTuple& args) {
01322     return impl_->Perform(args);
01323   }
01324 
01325  private:
01326   const internal::linked_ptr<ActionInterface<F2> > impl_;
01327 
01328   GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
01329 };
01330 
01331 // Implements the polymorphic Return(x) action, which can be used in
01332 // any function that returns the type of x, regardless of the argument
01333 // types.
01334 //
01335 // Note: The value passed into Return must be converted into
01336 // Function<F>::Result when this action is cast to Action<F> rather than
01337 // when that action is performed. This is important in scenarios like
01338 //
01339 // MOCK_METHOD1(Method, T(U));
01340 // ...
01341 // {
01342 //   Foo foo;
01343 //   X x(&foo);
01344 //   EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
01345 // }
01346 //
01347 // In the example above the variable x holds reference to foo which leaves
01348 // scope and gets destroyed.  If copying X just copies a reference to foo,
01349 // that copy will be left with a hanging reference.  If conversion to T
01350 // makes a copy of foo, the above code is safe. To support that scenario, we
01351 // need to make sure that the type conversion happens inside the EXPECT_CALL
01352 // statement, and conversion of the result of Return to Action<T(U)> is a
01353 // good place for that.
01354 //
01355 template <typename R>
01356 class ReturnAction {
01357  public:
01358   // Constructs a ReturnAction object from the value to be returned.
01359   // 'value' is passed by value instead of by const reference in order
01360   // to allow Return("string literal") to compile.
01361   explicit ReturnAction(R value) : value_(value) {}
01362 
01363   // This template type conversion operator allows Return(x) to be
01364   // used in ANY function that returns x's type.
01365   template <typename F>
01366   operator Action<F>() const {
01367     // Assert statement belongs here because this is the best place to verify
01368     // conditions on F. It produces the clearest error messages
01369     // in most compilers.
01370     // Impl really belongs in this scope as a local class but can't
01371     // because MSVC produces duplicate symbols in different translation units
01372     // in this case. Until MS fixes that bug we put Impl into the class scope
01373     // and put the typedef both here (for use in assert statement) and
01374     // in the Impl class. But both definitions must be the same.
01375     typedef typename Function<F>::Result Result;
01376     GTEST_COMPILE_ASSERT_(
01377         !internal::is_reference<Result>::value,
01378         use_ReturnRef_instead_of_Return_to_return_a_reference);
01379     return Action<F>(new Impl<F>(value_));
01380   }
01381 
01382  private:
01383   // Implements the Return(x) action for a particular function type F.
01384   template <typename F>
01385   class Impl : public ActionInterface<F> {
01386    public:
01387     typedef typename Function<F>::Result Result;
01388     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
01389 
01390     // The implicit cast is necessary when Result has more than one
01391     // single-argument constructor (e.g. Result is std::vector<int>) and R
01392     // has a type conversion operator template.  In that case, value_(value)
01393     // won't compile as the compiler doesn't known which constructor of
01394     // Result to call.  ImplicitCast_ forces the compiler to convert R to
01395     // Result without considering explicit constructors, thus resolving the
01396     // ambiguity. value_ is then initialized using its copy constructor.
01397     explicit Impl(R value)
01398         : value_(::testing::internal::ImplicitCast_<Result>(value)) {}
01399 
01400     virtual Result Perform(const ArgumentTuple&) { return value_; }
01401 
01402    private:
01403     GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value,
01404                           Result_cannot_be_a_reference_type);
01405     Result value_;
01406 
01407     GTEST_DISALLOW_ASSIGN_(Impl);
01408   };
01409 
01410   R value_;
01411 
01412   GTEST_DISALLOW_ASSIGN_(ReturnAction);
01413 };
01414 
01415 // Implements the ReturnNull() action.
01416 class ReturnNullAction {
01417  public:
01418   // Allows ReturnNull() to be used in any pointer-returning function.
01419   template <typename Result, typename ArgumentTuple>
01420   static Result Perform(const ArgumentTuple&) {
01421     GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
01422                           ReturnNull_can_be_used_to_return_a_pointer_only);
01423     return NULL;
01424   }
01425 };
01426 
01427 // Implements the Return() action.
01428 class ReturnVoidAction {
01429  public:
01430   // Allows Return() to be used in any void-returning function.
01431   template <typename Result, typename ArgumentTuple>
01432   static void Perform(const ArgumentTuple&) {
01433     CompileAssertTypesEqual<void, Result>();
01434   }
01435 };
01436 
01437 // Implements the polymorphic ReturnRef(x) action, which can be used
01438 // in any function that returns a reference to the type of x,
01439 // regardless of the argument types.
01440 template <typename T>
01441 class ReturnRefAction {
01442  public:
01443   // Constructs a ReturnRefAction object from the reference to be returned.
01444   explicit ReturnRefAction(T& ref) : ref_(ref) {}  // NOLINT
01445 
01446   // This template type conversion operator allows ReturnRef(x) to be
01447   // used in ANY function that returns a reference to x's type.
01448   template <typename F>
01449   operator Action<F>() const {
01450     typedef typename Function<F>::Result Result;
01451     // Asserts that the function return type is a reference.  This
01452     // catches the user error of using ReturnRef(x) when Return(x)
01453     // should be used, and generates some helpful error message.
01454     GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
01455                           use_Return_instead_of_ReturnRef_to_return_a_value);
01456     return Action<F>(new Impl<F>(ref_));
01457   }
01458 
01459  private:
01460   // Implements the ReturnRef(x) action for a particular function type F.
01461   template <typename F>
01462   class Impl : public ActionInterface<F> {
01463    public:
01464     typedef typename Function<F>::Result Result;
01465     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
01466 
01467     explicit Impl(T& ref) : ref_(ref) {}  // NOLINT
01468 
01469     virtual Result Perform(const ArgumentTuple&) {
01470       return ref_;
01471     }
01472 
01473    private:
01474     T& ref_;
01475 
01476     GTEST_DISALLOW_ASSIGN_(Impl);
01477   };
01478 
01479   T& ref_;
01480 
01481   GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
01482 };
01483 
01484 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
01485 // used in any function that returns a reference to the type of x,
01486 // regardless of the argument types.
01487 template <typename T>
01488 class ReturnRefOfCopyAction {
01489  public:
01490   // Constructs a ReturnRefOfCopyAction object from the reference to
01491   // be returned.
01492   explicit ReturnRefOfCopyAction(const T& value) : value_(value) {}  // NOLINT
01493 
01494   // This template type conversion operator allows ReturnRefOfCopy(x) to be
01495   // used in ANY function that returns a reference to x's type.
01496   template <typename F>
01497   operator Action<F>() const {
01498     typedef typename Function<F>::Result Result;
01499     // Asserts that the function return type is a reference.  This
01500     // catches the user error of using ReturnRefOfCopy(x) when Return(x)
01501     // should be used, and generates some helpful error message.
01502     GTEST_COMPILE_ASSERT_(
01503         internal::is_reference<Result>::value,
01504         use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
01505     return Action<F>(new Impl<F>(value_));
01506   }
01507 
01508  private:
01509   // Implements the ReturnRefOfCopy(x) action for a particular function type F.
01510   template <typename F>
01511   class Impl : public ActionInterface<F> {
01512    public:
01513     typedef typename Function<F>::Result Result;
01514     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
01515 
01516     explicit Impl(const T& value) : value_(value) {}  // NOLINT
01517 
01518     virtual Result Perform(const ArgumentTuple&) {
01519       return value_;
01520     }
01521 
01522    private:
01523     T value_;
01524 
01525     GTEST_DISALLOW_ASSIGN_(Impl);
01526   };
01527 
01528   const T value_;
01529 
01530   GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
01531 };
01532 
01533 // Implements the polymorphic DoDefault() action.
01534 class DoDefaultAction {
01535  public:
01536   // This template type conversion operator allows DoDefault() to be
01537   // used in any function.
01538   template <typename F>
01539   operator Action<F>() const { return Action<F>(NULL); }
01540 };
01541 
01542 // Implements the Assign action to set a given pointer referent to a
01543 // particular value.
01544 template <typename T1, typename T2>
01545 class AssignAction {
01546  public:
01547   AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
01548 
01549   template <typename Result, typename ArgumentTuple>
01550   void Perform(const ArgumentTuple& /* args */) const {
01551     *ptr_ = value_;
01552   }
01553 
01554  private:
01555   T1* const ptr_;
01556   const T2 value_;
01557 
01558   GTEST_DISALLOW_ASSIGN_(AssignAction);
01559 };
01560 
01561 #if !GTEST_OS_WINDOWS_MOBILE
01562 
01563 // Implements the SetErrnoAndReturn action to simulate return from
01564 // various system calls and libc functions.
01565 template <typename T>
01566 class SetErrnoAndReturnAction {
01567  public:
01568   SetErrnoAndReturnAction(int errno_value, T result)
01569       : errno_(errno_value),
01570         result_(result) {}
01571   template <typename Result, typename ArgumentTuple>
01572   Result Perform(const ArgumentTuple& /* args */) const {
01573     errno = errno_;
01574     return result_;
01575   }
01576 
01577  private:
01578   const int errno_;
01579   const T result_;
01580 
01581   GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
01582 };
01583 
01584 #endif  // !GTEST_OS_WINDOWS_MOBILE
01585 
01586 // Implements the SetArgumentPointee<N>(x) action for any function
01587 // whose N-th argument (0-based) is a pointer to x's type.  The
01588 // template parameter kIsProto is true iff type A is ProtocolMessage,
01589 // proto2::Message, or a sub-class of those.
01590 template <size_t N, typename A, bool kIsProto>
01591 class SetArgumentPointeeAction {
01592  public:
01593   // Constructs an action that sets the variable pointed to by the
01594   // N-th function argument to 'value'.
01595   explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
01596 
01597   template <typename Result, typename ArgumentTuple>
01598   void Perform(const ArgumentTuple& args) const {
01599     CompileAssertTypesEqual<void, Result>();
01600     *::std::tr1::get<N>(args) = value_;
01601   }
01602 
01603  private:
01604   const A value_;
01605 
01606   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
01607 };
01608 
01609 template <size_t N, typename Proto>
01610 class SetArgumentPointeeAction<N, Proto, true> {
01611  public:
01612   // Constructs an action that sets the variable pointed to by the
01613   // N-th function argument to 'proto'.  Both ProtocolMessage and
01614   // proto2::Message have the CopyFrom() method, so the same
01615   // implementation works for both.
01616   explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
01617     proto_->CopyFrom(proto);
01618   }
01619 
01620   template <typename Result, typename ArgumentTuple>
01621   void Perform(const ArgumentTuple& args) const {
01622     CompileAssertTypesEqual<void, Result>();
01623     ::std::tr1::get<N>(args)->CopyFrom(*proto_);
01624   }
01625 
01626  private:
01627   const internal::linked_ptr<Proto> proto_;
01628 
01629   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
01630 };
01631 
01632 // Implements the InvokeWithoutArgs(f) action.  The template argument
01633 // FunctionImpl is the implementation type of f, which can be either a
01634 // function pointer or a functor.  InvokeWithoutArgs(f) can be used as an
01635 // Action<F> as long as f's type is compatible with F (i.e. f can be
01636 // assigned to a tr1::function<F>).
01637 template <typename FunctionImpl>
01638 class InvokeWithoutArgsAction {
01639  public:
01640   // The c'tor makes a copy of function_impl (either a function
01641   // pointer or a functor).
01642   explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
01643       : function_impl_(function_impl) {}
01644 
01645   // Allows InvokeWithoutArgs(f) to be used as any action whose type is
01646   // compatible with f.
01647   template <typename Result, typename ArgumentTuple>
01648   Result Perform(const ArgumentTuple&) { return function_impl_(); }
01649 
01650  private:
01651   FunctionImpl function_impl_;
01652 
01653   GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
01654 };
01655 
01656 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
01657 template <class Class, typename MethodPtr>
01658 class InvokeMethodWithoutArgsAction {
01659  public:
01660   InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
01661       : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
01662 
01663   template <typename Result, typename ArgumentTuple>
01664   Result Perform(const ArgumentTuple&) const {
01665     return (obj_ptr_->*method_ptr_)();
01666   }
01667 
01668  private:
01669   Class* const obj_ptr_;
01670   const MethodPtr method_ptr_;
01671 
01672   GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
01673 };
01674 
01675 // Implements the IgnoreResult(action) action.
01676 template <typename A>
01677 class IgnoreResultAction {
01678  public:
01679   explicit IgnoreResultAction(const A& action) : action_(action) {}
01680 
01681   template <typename F>
01682   operator Action<F>() const {
01683     // Assert statement belongs here because this is the best place to verify
01684     // conditions on F. It produces the clearest error messages
01685     // in most compilers.
01686     // Impl really belongs in this scope as a local class but can't
01687     // because MSVC produces duplicate symbols in different translation units
01688     // in this case. Until MS fixes that bug we put Impl into the class scope
01689     // and put the typedef both here (for use in assert statement) and
01690     // in the Impl class. But both definitions must be the same.
01691     typedef typename internal::Function<F>::Result Result;
01692 
01693     // Asserts at compile time that F returns void.
01694     CompileAssertTypesEqual<void, Result>();
01695 
01696     return Action<F>(new Impl<F>(action_));
01697   }
01698 
01699  private:
01700   template <typename F>
01701   class Impl : public ActionInterface<F> {
01702    public:
01703     typedef typename internal::Function<F>::Result Result;
01704     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
01705 
01706     explicit Impl(const A& action) : action_(action) {}
01707 
01708     virtual void Perform(const ArgumentTuple& args) {
01709       // Performs the action and ignores its result.
01710       action_.Perform(args);
01711     }
01712 
01713    private:
01714     // Type OriginalFunction is the same as F except that its return
01715     // type is IgnoredValue.
01716     typedef typename internal::Function<F>::MakeResultIgnoredValue
01717         OriginalFunction;
01718 
01719     const Action<OriginalFunction> action_;
01720 
01721     GTEST_DISALLOW_ASSIGN_(Impl);
01722   };
01723 
01724   const A action_;
01725 
01726   GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
01727 };
01728 
01729 // A ReferenceWrapper<T> object represents a reference to type T,
01730 // which can be either const or not.  It can be explicitly converted
01731 // from, and implicitly converted to, a T&.  Unlike a reference,
01732 // ReferenceWrapper<T> can be copied and can survive template type
01733 // inference.  This is used to support by-reference arguments in the
01734 // InvokeArgument<N>(...) action.  The idea was from "reference
01735 // wrappers" in tr1, which we don't have in our source tree yet.
01736 template <typename T>
01737 class ReferenceWrapper {
01738  public:
01739   // Constructs a ReferenceWrapper<T> object from a T&.
01740   explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {}  // NOLINT
01741 
01742   // Allows a ReferenceWrapper<T> object to be implicitly converted to
01743   // a T&.
01744   operator T&() const { return *pointer_; }
01745  private:
01746   T* pointer_;
01747 };
01748 
01749 // Allows the expression ByRef(x) to be printed as a reference to x.
01750 template <typename T>
01751 void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
01752   T& value = ref;
01753   UniversalPrinter<T&>::Print(value, os);
01754 }
01755 
01756 // Does two actions sequentially.  Used for implementing the DoAll(a1,
01757 // a2, ...) action.
01758 template <typename Action1, typename Action2>
01759 class DoBothAction {
01760  public:
01761   DoBothAction(Action1 action1, Action2 action2)
01762       : action1_(action1), action2_(action2) {}
01763 
01764   // This template type conversion operator allows DoAll(a1, ..., a_n)
01765   // to be used in ANY function of compatible type.
01766   template <typename F>
01767   operator Action<F>() const {
01768     return Action<F>(new Impl<F>(action1_, action2_));
01769   }
01770 
01771  private:
01772   // Implements the DoAll(...) action for a particular function type F.
01773   template <typename F>
01774   class Impl : public ActionInterface<F> {
01775    public:
01776     typedef typename Function<F>::Result Result;
01777     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
01778     typedef typename Function<F>::MakeResultVoid VoidResult;
01779 
01780     Impl(const Action<VoidResult>& action1, const Action<F>& action2)
01781         : action1_(action1), action2_(action2) {}
01782 
01783     virtual Result Perform(const ArgumentTuple& args) {
01784       action1_.Perform(args);
01785       return action2_.Perform(args);
01786     }
01787 
01788    private:
01789     const Action<VoidResult> action1_;
01790     const Action<F> action2_;
01791 
01792     GTEST_DISALLOW_ASSIGN_(Impl);
01793   };
01794 
01795   Action1 action1_;
01796   Action2 action2_;
01797 
01798   GTEST_DISALLOW_ASSIGN_(DoBothAction);
01799 };
01800 
01801 }  // namespace internal
01802 
01803 // An Unused object can be implicitly constructed from ANY value.
01804 // This is handy when defining actions that ignore some or all of the
01805 // mock function arguments.  For example, given
01806 //
01807 //   MOCK_METHOD3(Foo, double(const string& label, double x, double y));
01808 //   MOCK_METHOD3(Bar, double(int index, double x, double y));
01809 //
01810 // instead of
01811 //
01812 //   double DistanceToOriginWithLabel(const string& label, double x, double y) {
01813 //     return sqrt(x*x + y*y);
01814 //   }
01815 //   double DistanceToOriginWithIndex(int index, double x, double y) {
01816 //     return sqrt(x*x + y*y);
01817 //   }
01818 //   ...
01819 //   EXEPCT_CALL(mock, Foo("abc", _, _))
01820 //       .WillOnce(Invoke(DistanceToOriginWithLabel));
01821 //   EXEPCT_CALL(mock, Bar(5, _, _))
01822 //       .WillOnce(Invoke(DistanceToOriginWithIndex));
01823 //
01824 // you could write
01825 //
01826 //   // We can declare any uninteresting argument as Unused.
01827 //   double DistanceToOrigin(Unused, double x, double y) {
01828 //     return sqrt(x*x + y*y);
01829 //   }
01830 //   ...
01831 //   EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
01832 //   EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
01833 typedef internal::IgnoredValue Unused;
01834 
01835 // This constructor allows us to turn an Action<From> object into an
01836 // Action<To>, as long as To's arguments can be implicitly converted
01837 // to From's and From's return type cann be implicitly converted to
01838 // To's.
01839 template <typename To>
01840 template <typename From>
01841 Action<To>::Action(const Action<From>& from)
01842     : impl_(new internal::ActionAdaptor<To, From>(from)) {}
01843 
01844 // Creates an action that returns 'value'.  'value' is passed by value
01845 // instead of const reference - otherwise Return("string literal")
01846 // will trigger a compiler error about using array as initializer.
01847 template <typename R>
01848 internal::ReturnAction<R> Return(R value) {
01849   return internal::ReturnAction<R>(value);
01850 }
01851 
01852 // Creates an action that returns NULL.
01853 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
01854   return MakePolymorphicAction(internal::ReturnNullAction());
01855 }
01856 
01857 // Creates an action that returns from a void function.
01858 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
01859   return MakePolymorphicAction(internal::ReturnVoidAction());
01860 }
01861 
01862 // Creates an action that returns the reference to a variable.
01863 template <typename R>
01864 inline internal::ReturnRefAction<R> ReturnRef(R& x) {  // NOLINT
01865   return internal::ReturnRefAction<R>(x);
01866 }
01867 
01868 // Creates an action that returns the reference to a copy of the
01869 // argument.  The copy is created when the action is constructed and
01870 // lives as long as the action.
01871 template <typename R>
01872 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
01873   return internal::ReturnRefOfCopyAction<R>(x);
01874 }
01875 
01876 // Creates an action that does the default action for the give mock function.
01877 inline internal::DoDefaultAction DoDefault() {
01878   return internal::DoDefaultAction();
01879 }
01880 
01881 // Creates an action that sets the variable pointed by the N-th
01882 // (0-based) function argument to 'value'.
01883 template <size_t N, typename T>
01884 PolymorphicAction<
01885   internal::SetArgumentPointeeAction<
01886     N, T, internal::IsAProtocolMessage<T>::value> >
01887 SetArgPointee(const T& x) {
01888   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
01889       N, T, internal::IsAProtocolMessage<T>::value>(x));
01890 }
01891 
01892 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
01893 // This overload allows SetArgPointee() to accept a string literal.
01894 // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
01895 // this overload from the templated version and emit a compile error.
01896 template <size_t N>
01897 PolymorphicAction<
01898   internal::SetArgumentPointeeAction<N, const char*, false> >
01899 SetArgPointee(const char* p) {
01900   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
01901       N, const char*, false>(p));
01902 }
01903 
01904 template <size_t N>
01905 PolymorphicAction<
01906   internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
01907 SetArgPointee(const wchar_t* p) {
01908   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
01909       N, const wchar_t*, false>(p));
01910 }
01911 #endif
01912 
01913 // The following version is DEPRECATED.
01914 template <size_t N, typename T>
01915 PolymorphicAction<
01916   internal::SetArgumentPointeeAction<
01917     N, T, internal::IsAProtocolMessage<T>::value> >
01918 SetArgumentPointee(const T& x) {
01919   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
01920       N, T, internal::IsAProtocolMessage<T>::value>(x));
01921 }
01922 
01923 // Creates an action that sets a pointer referent to a given value.
01924 template <typename T1, typename T2>
01925 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
01926   return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
01927 }
01928 
01929 #if !GTEST_OS_WINDOWS_MOBILE
01930 
01931 // Creates an action that sets errno and returns the appropriate error.
01932 template <typename T>
01933 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
01934 SetErrnoAndReturn(int errval, T result) {
01935   return MakePolymorphicAction(
01936       internal::SetErrnoAndReturnAction<T>(errval, result));
01937 }
01938 
01939 #endif  // !GTEST_OS_WINDOWS_MOBILE
01940 
01941 // Various overloads for InvokeWithoutArgs().
01942 
01943 // Creates an action that invokes 'function_impl' with no argument.
01944 template <typename FunctionImpl>
01945 PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
01946 InvokeWithoutArgs(FunctionImpl function_impl) {
01947   return MakePolymorphicAction(
01948       internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
01949 }
01950 
01951 // Creates an action that invokes the given method on the given object
01952 // with no argument.
01953 template <class Class, typename MethodPtr>
01954 PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
01955 InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
01956   return MakePolymorphicAction(
01957       internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
01958           obj_ptr, method_ptr));
01959 }
01960 
01961 // Creates an action that performs an_action and throws away its
01962 // result.  In other words, it changes the return type of an_action to
01963 // void.  an_action MUST NOT return void, or the code won't compile.
01964 template <typename A>
01965 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
01966   return internal::IgnoreResultAction<A>(an_action);
01967 }
01968 
01969 // Creates a reference wrapper for the given L-value.  If necessary,
01970 // you can explicitly specify the type of the reference.  For example,
01971 // suppose 'derived' is an object of type Derived, ByRef(derived)
01972 // would wrap a Derived&.  If you want to wrap a const Base& instead,
01973 // where Base is a base class of Derived, just write:
01974 //
01975 //   ByRef<const Base>(derived)
01976 template <typename T>
01977 inline internal::ReferenceWrapper<T> ByRef(T& l_value) {  // NOLINT
01978   return internal::ReferenceWrapper<T>(l_value);
01979 }
01980 
01981 }  // namespace testing
01982 
01983 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
01984 // Copyright 2007, Google Inc.
01985 // All rights reserved.
01986 //
01987 // Redistribution and use in source and binary forms, with or without
01988 // modification, are permitted provided that the following conditions are
01989 // met:
01990 //
01991 //     * Redistributions of source code must retain the above copyright
01992 // notice, this list of conditions and the following disclaimer.
01993 //     * Redistributions in binary form must reproduce the above
01994 // copyright notice, this list of conditions and the following disclaimer
01995 // in the documentation and/or other materials provided with the
01996 // distribution.
01997 //     * Neither the name of Google Inc. nor the names of its
01998 // contributors may be used to endorse or promote products derived from
01999 // this software without specific prior written permission.
02000 //
02001 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
02002 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
02003 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
02004 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
02005 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
02006 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
02007 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
02008 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
02009 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
02010 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
02011 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
02012 //
02013 // Author: wan@google.com (Zhanyong Wan)
02014 
02015 // Google Mock - a framework for writing C++ mock classes.
02016 //
02017 // This file implements some commonly used cardinalities.  More
02018 // cardinalities can be defined by the user implementing the
02019 // CardinalityInterface interface if necessary.
02020 
02021 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
02022 #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
02023 
02024 #include <limits.h>
02025 #include <ostream>  // NOLINT
02026 
02027 namespace testing {
02028 
02029 // To implement a cardinality Foo, define:
02030 //   1. a class FooCardinality that implements the
02031 //      CardinalityInterface interface, and
02032 //   2. a factory function that creates a Cardinality object from a
02033 //      const FooCardinality*.
02034 //
02035 // The two-level delegation design follows that of Matcher, providing
02036 // consistency for extension developers.  It also eases ownership
02037 // management as Cardinality objects can now be copied like plain values.
02038 
02039 // The implementation of a cardinality.
02040 class CardinalityInterface {
02041  public:
02042   virtual ~CardinalityInterface() {}
02043 
02044   // Conservative estimate on the lower/upper bound of the number of
02045   // calls allowed.
02046   virtual int ConservativeLowerBound() const { return 0; }
02047   virtual int ConservativeUpperBound() const { return INT_MAX; }
02048 
02049   // Returns true iff call_count calls will satisfy this cardinality.
02050   virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
02051 
02052   // Returns true iff call_count calls will saturate this cardinality.
02053   virtual bool IsSaturatedByCallCount(int call_count) const = 0;
02054 
02055   // Describes self to an ostream.
02056   virtual void DescribeTo(::std::ostream* os) const = 0;
02057 };
02058 
02059 // A Cardinality is a copyable and IMMUTABLE (except by assignment)
02060 // object that specifies how many times a mock function is expected to
02061 // be called.  The implementation of Cardinality is just a linked_ptr
02062 // to const CardinalityInterface, so copying is fairly cheap.
02063 // Don't inherit from Cardinality!
02064 class GTEST_API_ Cardinality {
02065  public:
02066   // Constructs a null cardinality.  Needed for storing Cardinality
02067   // objects in STL containers.
02068   Cardinality() {}
02069 
02070   // Constructs a Cardinality from its implementation.
02071   explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
02072 
02073   // Conservative estimate on the lower/upper bound of the number of
02074   // calls allowed.
02075   int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
02076   int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
02077 
02078   // Returns true iff call_count calls will satisfy this cardinality.
02079   bool IsSatisfiedByCallCount(int call_count) const {
02080     return impl_->IsSatisfiedByCallCount(call_count);
02081   }
02082 
02083   // Returns true iff call_count calls will saturate this cardinality.
02084   bool IsSaturatedByCallCount(int call_count) const {
02085     return impl_->IsSaturatedByCallCount(call_count);
02086   }
02087 
02088   // Returns true iff call_count calls will over-saturate this
02089   // cardinality, i.e. exceed the maximum number of allowed calls.
02090   bool IsOverSaturatedByCallCount(int call_count) const {
02091     return impl_->IsSaturatedByCallCount(call_count) &&
02092         !impl_->IsSatisfiedByCallCount(call_count);
02093   }
02094 
02095   // Describes self to an ostream
02096   void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
02097 
02098   // Describes the given actual call count to an ostream.
02099   static void DescribeActualCallCountTo(int actual_call_count,
02100                                         ::std::ostream* os);
02101 
02102  private:
02103   internal::linked_ptr<const CardinalityInterface> impl_;
02104 };
02105 
02106 // Creates a cardinality that allows at least n calls.
02107 GTEST_API_ Cardinality AtLeast(int n);
02108 
02109 // Creates a cardinality that allows at most n calls.
02110 GTEST_API_ Cardinality AtMost(int n);
02111 
02112 // Creates a cardinality that allows any number of calls.
02113 GTEST_API_ Cardinality AnyNumber();
02114 
02115 // Creates a cardinality that allows between min and max calls.
02116 GTEST_API_ Cardinality Between(int min, int max);
02117 
02118 // Creates a cardinality that allows exactly n calls.
02119 GTEST_API_ Cardinality Exactly(int n);
02120 
02121 // Creates a cardinality from its implementation.
02122 inline Cardinality MakeCardinality(const CardinalityInterface* c) {
02123   return Cardinality(c);
02124 }
02125 
02126 }  // namespace testing
02127 
02128 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
02129 // This file was GENERATED by a script.  DO NOT EDIT BY HAND!!!
02130 
02131 // Copyright 2007, Google Inc.
02132 // All rights reserved.
02133 //
02134 // Redistribution and use in source and binary forms, with or without
02135 // modification, are permitted provided that the following conditions are
02136 // met:
02137 //
02138 //     * Redistributions of source code must retain the above copyright
02139 // notice, this list of conditions and the following disclaimer.
02140 //     * Redistributions in binary form must reproduce the above
02141 // copyright notice, this list of conditions and the following disclaimer
02142 // in the documentation and/or other materials provided with the
02143 // distribution.
02144 //     * Neither the name of Google Inc. nor the names of its
02145 // contributors may be used to endorse or promote products derived from
02146 // this software without specific prior written permission.
02147 //
02148 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
02149 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
02150 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
02151 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
02152 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
02153 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
02154 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
02155 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
02156 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
02157 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
02158 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
02159 //
02160 // Author: wan@google.com (Zhanyong Wan)
02161 
02162 // Google Mock - a framework for writing C++ mock classes.
02163 //
02164 // This file implements some commonly used variadic actions.
02165 
02166 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
02167 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
02168 
02169 
02170 namespace testing {
02171 namespace internal {
02172 
02173 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
02174 // function or method with the unpacked values, where F is a function
02175 // type that takes N arguments.
02176 template <typename Result, typename ArgumentTuple>
02177 class InvokeHelper;
02178 
02179 template <typename R>
02180 class InvokeHelper<R, ::std::tr1::tuple<> > {
02181  public:
02182   template <typename Function>
02183   static R Invoke(Function function, const ::std::tr1::tuple<>&) {
02184     return function();
02185   }
02186 
02187   template <class Class, typename MethodPtr>
02188   static R InvokeMethod(Class* obj_ptr,
02189                         MethodPtr method_ptr,
02190                         const ::std::tr1::tuple<>&) {
02191     return (obj_ptr->*method_ptr)();
02192   }
02193 };
02194 
02195 template <typename R, typename A1>
02196 class InvokeHelper<R, ::std::tr1::tuple<A1> > {
02197  public:
02198   template <typename Function>
02199   static R Invoke(Function function, const ::std::tr1::tuple<A1>& args) {
02200     using ::std::tr1::get;
02201     return function(get<0>(args));
02202   }
02203 
02204   template <class Class, typename MethodPtr>
02205   static R InvokeMethod(Class* obj_ptr,
02206                         MethodPtr method_ptr,
02207                         const ::std::tr1::tuple<A1>& args) {
02208     using ::std::tr1::get;
02209     return (obj_ptr->*method_ptr)(get<0>(args));
02210   }
02211 };
02212 
02213 template <typename R, typename A1, typename A2>
02214 class InvokeHelper<R, ::std::tr1::tuple<A1, A2> > {
02215  public:
02216   template <typename Function>
02217   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2>& args) {
02218     using ::std::tr1::get;
02219     return function(get<0>(args), get<1>(args));
02220   }
02221 
02222   template <class Class, typename MethodPtr>
02223   static R InvokeMethod(Class* obj_ptr,
02224                         MethodPtr method_ptr,
02225                         const ::std::tr1::tuple<A1, A2>& args) {
02226     using ::std::tr1::get;
02227     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
02228   }
02229 };
02230 
02231 template <typename R, typename A1, typename A2, typename A3>
02232 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3> > {
02233  public:
02234   template <typename Function>
02235   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2,
02236       A3>& args) {
02237     using ::std::tr1::get;
02238     return function(get<0>(args), get<1>(args), get<2>(args));
02239   }
02240 
02241   template <class Class, typename MethodPtr>
02242   static R InvokeMethod(Class* obj_ptr,
02243                         MethodPtr method_ptr,
02244                         const ::std::tr1::tuple<A1, A2, A3>& args) {
02245     using ::std::tr1::get;
02246     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args));
02247   }
02248 };
02249 
02250 template <typename R, typename A1, typename A2, typename A3, typename A4>
02251 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4> > {
02252  public:
02253   template <typename Function>
02254   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3,
02255       A4>& args) {
02256     using ::std::tr1::get;
02257     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args));
02258   }
02259 
02260   template <class Class, typename MethodPtr>
02261   static R InvokeMethod(Class* obj_ptr,
02262                         MethodPtr method_ptr,
02263                         const ::std::tr1::tuple<A1, A2, A3, A4>& args) {
02264     using ::std::tr1::get;
02265     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02266         get<3>(args));
02267   }
02268 };
02269 
02270 template <typename R, typename A1, typename A2, typename A3, typename A4,
02271     typename A5>
02272 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5> > {
02273  public:
02274   template <typename Function>
02275   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02276       A5>& args) {
02277     using ::std::tr1::get;
02278     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02279         get<4>(args));
02280   }
02281 
02282   template <class Class, typename MethodPtr>
02283   static R InvokeMethod(Class* obj_ptr,
02284                         MethodPtr method_ptr,
02285                         const ::std::tr1::tuple<A1, A2, A3, A4, A5>& args) {
02286     using ::std::tr1::get;
02287     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02288         get<3>(args), get<4>(args));
02289   }
02290 };
02291 
02292 template <typename R, typename A1, typename A2, typename A3, typename A4,
02293     typename A5, typename A6>
02294 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6> > {
02295  public:
02296   template <typename Function>
02297   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02298       A5, A6>& args) {
02299     using ::std::tr1::get;
02300     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02301         get<4>(args), get<5>(args));
02302   }
02303 
02304   template <class Class, typename MethodPtr>
02305   static R InvokeMethod(Class* obj_ptr,
02306                         MethodPtr method_ptr,
02307                         const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6>& args) {
02308     using ::std::tr1::get;
02309     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02310         get<3>(args), get<4>(args), get<5>(args));
02311   }
02312 };
02313 
02314 template <typename R, typename A1, typename A2, typename A3, typename A4,
02315     typename A5, typename A6, typename A7>
02316 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7> > {
02317  public:
02318   template <typename Function>
02319   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02320       A5, A6, A7>& args) {
02321     using ::std::tr1::get;
02322     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02323         get<4>(args), get<5>(args), get<6>(args));
02324   }
02325 
02326   template <class Class, typename MethodPtr>
02327   static R InvokeMethod(Class* obj_ptr,
02328                         MethodPtr method_ptr,
02329                         const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6,
02330                             A7>& args) {
02331     using ::std::tr1::get;
02332     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02333         get<3>(args), get<4>(args), get<5>(args), get<6>(args));
02334   }
02335 };
02336 
02337 template <typename R, typename A1, typename A2, typename A3, typename A4,
02338     typename A5, typename A6, typename A7, typename A8>
02339 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
02340  public:
02341   template <typename Function>
02342   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02343       A5, A6, A7, A8>& args) {
02344     using ::std::tr1::get;
02345     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02346         get<4>(args), get<5>(args), get<6>(args), get<7>(args));
02347   }
02348 
02349   template <class Class, typename MethodPtr>
02350   static R InvokeMethod(Class* obj_ptr,
02351                         MethodPtr method_ptr,
02352                         const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7,
02353                             A8>& args) {
02354     using ::std::tr1::get;
02355     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02356         get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args));
02357   }
02358 };
02359 
02360 template <typename R, typename A1, typename A2, typename A3, typename A4,
02361     typename A5, typename A6, typename A7, typename A8, typename A9>
02362 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
02363  public:
02364   template <typename Function>
02365   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02366       A5, A6, A7, A8, A9>& args) {
02367     using ::std::tr1::get;
02368     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02369         get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args));
02370   }
02371 
02372   template <class Class, typename MethodPtr>
02373   static R InvokeMethod(Class* obj_ptr,
02374                         MethodPtr method_ptr,
02375                         const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
02376                             A9>& args) {
02377     using ::std::tr1::get;
02378     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02379         get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
02380         get<8>(args));
02381   }
02382 };
02383 
02384 template <typename R, typename A1, typename A2, typename A3, typename A4,
02385     typename A5, typename A6, typename A7, typename A8, typename A9,
02386     typename A10>
02387 class InvokeHelper<R, ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
02388     A10> > {
02389  public:
02390   template <typename Function>
02391   static R Invoke(Function function, const ::std::tr1::tuple<A1, A2, A3, A4,
02392       A5, A6, A7, A8, A9, A10>& args) {
02393     using ::std::tr1::get;
02394     return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02395         get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
02396         get<9>(args));
02397   }
02398 
02399   template <class Class, typename MethodPtr>
02400   static R InvokeMethod(Class* obj_ptr,
02401                         MethodPtr method_ptr,
02402                         const ::std::tr1::tuple<A1, A2, A3, A4, A5, A6, A7, A8,
02403                             A9, A10>& args) {
02404     using ::std::tr1::get;
02405     return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args),
02406         get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args),
02407         get<8>(args), get<9>(args));
02408   }
02409 };
02410 
02411 // CallableHelper has static methods for invoking "callables",
02412 // i.e. function pointers and functors.  It uses overloading to
02413 // provide a uniform interface for invoking different kinds of
02414 // callables.  In particular, you can use:
02415 //
02416 //   CallableHelper<R>::Call(callable, a1, a2, ..., an)
02417 //
02418 // to invoke an n-ary callable, where R is its return type.  If an
02419 // argument, say a2, needs to be passed by reference, you should write
02420 // ByRef(a2) instead of a2 in the above expression.
02421 template <typename R>
02422 class CallableHelper {
02423  public:
02424   // Calls a nullary callable.
02425   template <typename Function>
02426   static R Call(Function function) { return function(); }
02427 
02428   // Calls a unary callable.
02429 
02430   // We deliberately pass a1 by value instead of const reference here
02431   // in case it is a C-string literal.  If we had declared the
02432   // parameter as 'const A1& a1' and write Call(function, "Hi"), the
02433   // compiler would've thought A1 is 'char[3]', which causes trouble
02434   // when you need to copy a value of type A1.  By declaring the
02435   // parameter as 'A1 a1', the compiler will correctly infer that A1
02436   // is 'const char*' when it sees Call(function, "Hi").
02437   //
02438   // Since this function is defined inline, the compiler can get rid
02439   // of the copying of the arguments.  Therefore the performance won't
02440   // be hurt.
02441   template <typename Function, typename A1>
02442   static R Call(Function function, A1 a1) { return function(a1); }
02443 
02444   // Calls a binary callable.
02445   template <typename Function, typename A1, typename A2>
02446   static R Call(Function function, A1 a1, A2 a2) {
02447     return function(a1, a2);
02448   }
02449 
02450   // Calls a ternary callable.
02451   template <typename Function, typename A1, typename A2, typename A3>
02452   static R Call(Function function, A1 a1, A2 a2, A3 a3) {
02453     return function(a1, a2, a3);
02454   }
02455 
02456   // Calls a 4-ary callable.
02457   template <typename Function, typename A1, typename A2, typename A3,
02458       typename A4>
02459   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) {
02460     return function(a1, a2, a3, a4);
02461   }
02462 
02463   // Calls a 5-ary callable.
02464   template <typename Function, typename A1, typename A2, typename A3,
02465       typename A4, typename A5>
02466   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
02467     return function(a1, a2, a3, a4, a5);
02468   }
02469 
02470   // Calls a 6-ary callable.
02471   template <typename Function, typename A1, typename A2, typename A3,
02472       typename A4, typename A5, typename A6>
02473   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
02474     return function(a1, a2, a3, a4, a5, a6);
02475   }
02476 
02477   // Calls a 7-ary callable.
02478   template <typename Function, typename A1, typename A2, typename A3,
02479       typename A4, typename A5, typename A6, typename A7>
02480   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
02481       A7 a7) {
02482     return function(a1, a2, a3, a4, a5, a6, a7);
02483   }
02484 
02485   // Calls a 8-ary callable.
02486   template <typename Function, typename A1, typename A2, typename A3,
02487       typename A4, typename A5, typename A6, typename A7, typename A8>
02488   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
02489       A7 a7, A8 a8) {
02490     return function(a1, a2, a3, a4, a5, a6, a7, a8);
02491   }
02492 
02493   // Calls a 9-ary callable.
02494   template <typename Function, typename A1, typename A2, typename A3,
02495       typename A4, typename A5, typename A6, typename A7, typename A8,
02496       typename A9>
02497   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
02498       A7 a7, A8 a8, A9 a9) {
02499     return function(a1, a2, a3, a4, a5, a6, a7, a8, a9);
02500   }
02501 
02502   // Calls a 10-ary callable.
02503   template <typename Function, typename A1, typename A2, typename A3,
02504       typename A4, typename A5, typename A6, typename A7, typename A8,
02505       typename A9, typename A10>
02506   static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6,
02507       A7 a7, A8 a8, A9 a9, A10 a10) {
02508     return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
02509   }
02510 };  // class CallableHelper
02511 
02512 // An INTERNAL macro for extracting the type of a tuple field.  It's
02513 // subject to change without notice - DO NOT USE IN USER CODE!
02514 #define GMOCK_FIELD_(Tuple, N) \
02515     typename ::std::tr1::tuple_element<N, Tuple>::type
02516 
02517 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
02518 // type of an n-ary function whose i-th (1-based) argument type is the
02519 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
02520 // type, and whose return type is Result.  For example,
02521 //   SelectArgs<int, ::std::tr1::tuple<bool, char, double, long>, 0, 3>::type
02522 // is int(bool, long).
02523 //
02524 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
02525 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
02526 // For example,
02527 //   SelectArgs<int, ::std::tr1::tuple<bool, char, double>, 2, 0>::Select(
02528 //       ::std::tr1::make_tuple(true, 'a', 2.5))
02529 // returns ::std::tr1::tuple (2.5, true).
02530 //
02531 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
02532 // in the range [0, 10].  Duplicates are allowed and they don't have
02533 // to be in an ascending or descending order.
02534 
02535 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02536     int k4, int k5, int k6, int k7, int k8, int k9, int k10>
02537 class SelectArgs {
02538  public:
02539   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02540       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02541       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
02542       GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
02543       GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9),
02544       GMOCK_FIELD_(ArgumentTuple, k10));
02545   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02546   static SelectedArgs Select(const ArgumentTuple& args) {
02547     using ::std::tr1::get;
02548     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02549         get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
02550         get<k8>(args), get<k9>(args), get<k10>(args));
02551   }
02552 };
02553 
02554 template <typename Result, typename ArgumentTuple>
02555 class SelectArgs<Result, ArgumentTuple,
02556                  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
02557  public:
02558   typedef Result type();
02559   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02560   static SelectedArgs Select(const ArgumentTuple& /* args */) {
02561     using ::std::tr1::get;
02562     return SelectedArgs();
02563   }
02564 };
02565 
02566 template <typename Result, typename ArgumentTuple, int k1>
02567 class SelectArgs<Result, ArgumentTuple,
02568                  k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
02569  public:
02570   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1));
02571   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02572   static SelectedArgs Select(const ArgumentTuple& args) {
02573     using ::std::tr1::get;
02574     return SelectedArgs(get<k1>(args));
02575   }
02576 };
02577 
02578 template <typename Result, typename ArgumentTuple, int k1, int k2>
02579 class SelectArgs<Result, ArgumentTuple,
02580                  k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> {
02581  public:
02582   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02583       GMOCK_FIELD_(ArgumentTuple, k2));
02584   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02585   static SelectedArgs Select(const ArgumentTuple& args) {
02586     using ::std::tr1::get;
02587     return SelectedArgs(get<k1>(args), get<k2>(args));
02588   }
02589 };
02590 
02591 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3>
02592 class SelectArgs<Result, ArgumentTuple,
02593                  k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> {
02594  public:
02595   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02596       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3));
02597   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02598   static SelectedArgs Select(const ArgumentTuple& args) {
02599     using ::std::tr1::get;
02600     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args));
02601   }
02602 };
02603 
02604 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02605     int k4>
02606 class SelectArgs<Result, ArgumentTuple,
02607                  k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> {
02608  public:
02609   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02610       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02611       GMOCK_FIELD_(ArgumentTuple, k4));
02612   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02613   static SelectedArgs Select(const ArgumentTuple& args) {
02614     using ::std::tr1::get;
02615     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02616         get<k4>(args));
02617   }
02618 };
02619 
02620 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02621     int k4, int k5>
02622 class SelectArgs<Result, ArgumentTuple,
02623                  k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> {
02624  public:
02625   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02626       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02627       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5));
02628   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02629   static SelectedArgs Select(const ArgumentTuple& args) {
02630     using ::std::tr1::get;
02631     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02632         get<k4>(args), get<k5>(args));
02633   }
02634 };
02635 
02636 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02637     int k4, int k5, int k6>
02638 class SelectArgs<Result, ArgumentTuple,
02639                  k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> {
02640  public:
02641   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02642       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02643       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
02644       GMOCK_FIELD_(ArgumentTuple, k6));
02645   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02646   static SelectedArgs Select(const ArgumentTuple& args) {
02647     using ::std::tr1::get;
02648     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02649         get<k4>(args), get<k5>(args), get<k6>(args));
02650   }
02651 };
02652 
02653 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02654     int k4, int k5, int k6, int k7>
02655 class SelectArgs<Result, ArgumentTuple,
02656                  k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> {
02657  public:
02658   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02659       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02660       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
02661       GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7));
02662   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02663   static SelectedArgs Select(const ArgumentTuple& args) {
02664     using ::std::tr1::get;
02665     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02666         get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args));
02667   }
02668 };
02669 
02670 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02671     int k4, int k5, int k6, int k7, int k8>
02672 class SelectArgs<Result, ArgumentTuple,
02673                  k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> {
02674  public:
02675   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02676       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02677       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
02678       GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
02679       GMOCK_FIELD_(ArgumentTuple, k8));
02680   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02681   static SelectedArgs Select(const ArgumentTuple& args) {
02682     using ::std::tr1::get;
02683     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02684         get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
02685         get<k8>(args));
02686   }
02687 };
02688 
02689 template <typename Result, typename ArgumentTuple, int k1, int k2, int k3,
02690     int k4, int k5, int k6, int k7, int k8, int k9>
02691 class SelectArgs<Result, ArgumentTuple,
02692                  k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> {
02693  public:
02694   typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1),
02695       GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3),
02696       GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5),
02697       GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7),
02698       GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9));
02699   typedef typename Function<type>::ArgumentTuple SelectedArgs;
02700   static SelectedArgs Select(const ArgumentTuple& args) {
02701     using ::std::tr1::get;
02702     return SelectedArgs(get<k1>(args), get<k2>(args), get<k3>(args),
02703         get<k4>(args), get<k5>(args), get<k6>(args), get<k7>(args),
02704         get<k8>(args), get<k9>(args));
02705   }
02706 };
02707 
02708 #undef GMOCK_FIELD_
02709 
02710 // Implements the WithArgs action.
02711 template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1,
02712     int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
02713     int k9 = -1, int k10 = -1>
02714 class WithArgsAction {
02715  public:
02716   explicit WithArgsAction(const InnerAction& action) : action_(action) {}
02717 
02718   template <typename F>
02719   operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
02720 
02721  private:
02722   template <typename F>
02723   class Impl : public ActionInterface<F> {
02724    public:
02725     typedef typename Function<F>::Result Result;
02726     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
02727 
02728     explicit Impl(const InnerAction& action) : action_(action) {}
02729 
02730     virtual Result Perform(const ArgumentTuple& args) {
02731       return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4,
02732           k5, k6, k7, k8, k9, k10>::Select(args));
02733     }
02734 
02735    private:
02736     typedef typename SelectArgs<Result, ArgumentTuple,
02737         k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
02738 
02739     Action<InnerFunctionType> action_;
02740   };
02741 
02742   const InnerAction action_;
02743 
02744   GTEST_DISALLOW_ASSIGN_(WithArgsAction);
02745 };
02746 
02747 // A macro from the ACTION* family (defined later in this file)
02748 // defines an action that can be used in a mock function.  Typically,
02749 // these actions only care about a subset of the arguments of the mock
02750 // function.  For example, if such an action only uses the second
02751 // argument, it can be used in any mock function that takes >= 2
02752 // arguments where the type of the second argument is compatible.
02753 //
02754 // Therefore, the action implementation must be prepared to take more
02755 // arguments than it needs.  The ExcessiveArg type is used to
02756 // represent those excessive arguments.  In order to keep the compiler
02757 // error messages tractable, we define it in the testing namespace
02758 // instead of testing::internal.  However, this is an INTERNAL TYPE
02759 // and subject to change without notice, so a user MUST NOT USE THIS
02760 // TYPE DIRECTLY.
02761 struct ExcessiveArg {};
02762 
02763 // A helper class needed for implementing the ACTION* macros.
02764 template <typename Result, class Impl>
02765 class ActionHelper {
02766  public:
02767   static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) {
02768     using ::std::tr1::get;
02769     return impl->template gmock_PerformImpl<>(args, ExcessiveArg(),
02770         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02771         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02772         ExcessiveArg());
02773   }
02774 
02775   template <typename A0>
02776   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0>& args) {
02777     using ::std::tr1::get;
02778     return impl->template gmock_PerformImpl<A0>(args, get<0>(args),
02779         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02780         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02781         ExcessiveArg());
02782   }
02783 
02784   template <typename A0, typename A1>
02785   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1>& args) {
02786     using ::std::tr1::get;
02787     return impl->template gmock_PerformImpl<A0, A1>(args, get<0>(args),
02788         get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02789         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02790         ExcessiveArg());
02791   }
02792 
02793   template <typename A0, typename A1, typename A2>
02794   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2>& args) {
02795     using ::std::tr1::get;
02796     return impl->template gmock_PerformImpl<A0, A1, A2>(args, get<0>(args),
02797         get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(),
02798         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02799         ExcessiveArg());
02800   }
02801 
02802   template <typename A0, typename A1, typename A2, typename A3>
02803   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2,
02804       A3>& args) {
02805     using ::std::tr1::get;
02806     return impl->template gmock_PerformImpl<A0, A1, A2, A3>(args, get<0>(args),
02807         get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(),
02808         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02809         ExcessiveArg());
02810   }
02811 
02812   template <typename A0, typename A1, typename A2, typename A3, typename A4>
02813   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3,
02814       A4>& args) {
02815     using ::std::tr1::get;
02816     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4>(args,
02817         get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
02818         ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02819         ExcessiveArg());
02820   }
02821 
02822   template <typename A0, typename A1, typename A2, typename A3, typename A4,
02823       typename A5>
02824   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
02825       A5>& args) {
02826     using ::std::tr1::get;
02827     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5>(args,
02828         get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
02829         get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(),
02830         ExcessiveArg());
02831   }
02832 
02833   template <typename A0, typename A1, typename A2, typename A3, typename A4,
02834       typename A5, typename A6>
02835   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
02836       A5, A6>& args) {
02837     using ::std::tr1::get;
02838     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6>(args,
02839         get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args),
02840         get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(),
02841         ExcessiveArg());
02842   }
02843 
02844   template <typename A0, typename A1, typename A2, typename A3, typename A4,
02845       typename A5, typename A6, typename A7>
02846   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
02847       A5, A6, A7>& args) {
02848     using ::std::tr1::get;
02849     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6,
02850         A7>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02851         get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(),
02852         ExcessiveArg());
02853   }
02854 
02855   template <typename A0, typename A1, typename A2, typename A3, typename A4,
02856       typename A5, typename A6, typename A7, typename A8>
02857   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
02858       A5, A6, A7, A8>& args) {
02859     using ::std::tr1::get;
02860     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7,
02861         A8>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02862         get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
02863         ExcessiveArg());
02864   }
02865 
02866   template <typename A0, typename A1, typename A2, typename A3, typename A4,
02867       typename A5, typename A6, typename A7, typename A8, typename A9>
02868   static Result Perform(Impl* impl, const ::std::tr1::tuple<A0, A1, A2, A3, A4,
02869       A5, A6, A7, A8, A9>& args) {
02870     using ::std::tr1::get;
02871     return impl->template gmock_PerformImpl<A0, A1, A2, A3, A4, A5, A6, A7, A8,
02872         A9>(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args),
02873         get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args),
02874         get<9>(args));
02875   }
02876 };
02877 
02878 }  // namespace internal
02879 
02880 // Various overloads for Invoke().
02881 
02882 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
02883 // the selected arguments of the mock function to an_action and
02884 // performs it.  It serves as an adaptor between actions with
02885 // different argument lists.  C++ doesn't support default arguments for
02886 // function templates, so we have to overload it.
02887 template <int k1, typename InnerAction>
02888 inline internal::WithArgsAction<InnerAction, k1>
02889 WithArgs(const InnerAction& action) {
02890   return internal::WithArgsAction<InnerAction, k1>(action);
02891 }
02892 
02893 template <int k1, int k2, typename InnerAction>
02894 inline internal::WithArgsAction<InnerAction, k1, k2>
02895 WithArgs(const InnerAction& action) {
02896   return internal::WithArgsAction<InnerAction, k1, k2>(action);
02897 }
02898 
02899 template <int k1, int k2, int k3, typename InnerAction>
02900 inline internal::WithArgsAction<InnerAction, k1, k2, k3>
02901 WithArgs(const InnerAction& action) {
02902   return internal::WithArgsAction<InnerAction, k1, k2, k3>(action);
02903 }
02904 
02905 template <int k1, int k2, int k3, int k4, typename InnerAction>
02906 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4>
02907 WithArgs(const InnerAction& action) {
02908   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action);
02909 }
02910 
02911 template <int k1, int k2, int k3, int k4, int k5, typename InnerAction>
02912 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>
02913 WithArgs(const InnerAction& action) {
02914   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action);
02915 }
02916 
02917 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction>
02918 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>
02919 WithArgs(const InnerAction& action) {
02920   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action);
02921 }
02922 
02923 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
02924     typename InnerAction>
02925 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7>
02926 WithArgs(const InnerAction& action) {
02927   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6,
02928       k7>(action);
02929 }
02930 
02931 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
02932     typename InnerAction>
02933 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8>
02934 WithArgs(const InnerAction& action) {
02935   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7,
02936       k8>(action);
02937 }
02938 
02939 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
02940     int k9, typename InnerAction>
02941 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9>
02942 WithArgs(const InnerAction& action) {
02943   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
02944       k9>(action);
02945 }
02946 
02947 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
02948     int k9, int k10, typename InnerAction>
02949 inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
02950     k9, k10>
02951 WithArgs(const InnerAction& action) {
02952   return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8,
02953       k9, k10>(action);
02954 }
02955 
02956 // Creates an action that does actions a1, a2, ..., sequentially in
02957 // each invocation.
02958 template <typename Action1, typename Action2>
02959 inline internal::DoBothAction<Action1, Action2>
02960 DoAll(Action1 a1, Action2 a2) {
02961   return internal::DoBothAction<Action1, Action2>(a1, a2);
02962 }
02963 
02964 template <typename Action1, typename Action2, typename Action3>
02965 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
02966     Action3> >
02967 DoAll(Action1 a1, Action2 a2, Action3 a3) {
02968   return DoAll(a1, DoAll(a2, a3));
02969 }
02970 
02971 template <typename Action1, typename Action2, typename Action3,
02972     typename Action4>
02973 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
02974     internal::DoBothAction<Action3, Action4> > >
02975 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) {
02976   return DoAll(a1, DoAll(a2, a3, a4));
02977 }
02978 
02979 template <typename Action1, typename Action2, typename Action3,
02980     typename Action4, typename Action5>
02981 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
02982     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
02983     Action5> > > >
02984 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) {
02985   return DoAll(a1, DoAll(a2, a3, a4, a5));
02986 }
02987 
02988 template <typename Action1, typename Action2, typename Action3,
02989     typename Action4, typename Action5, typename Action6>
02990 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
02991     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
02992     internal::DoBothAction<Action5, Action6> > > > >
02993 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) {
02994   return DoAll(a1, DoAll(a2, a3, a4, a5, a6));
02995 }
02996 
02997 template <typename Action1, typename Action2, typename Action3,
02998     typename Action4, typename Action5, typename Action6, typename Action7>
02999 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
03000     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
03001     internal::DoBothAction<Action5, internal::DoBothAction<Action6,
03002     Action7> > > > > >
03003 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
03004     Action7 a7) {
03005   return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7));
03006 }
03007 
03008 template <typename Action1, typename Action2, typename Action3,
03009     typename Action4, typename Action5, typename Action6, typename Action7,
03010     typename Action8>
03011 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
03012     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
03013     internal::DoBothAction<Action5, internal::DoBothAction<Action6,
03014     internal::DoBothAction<Action7, Action8> > > > > > >
03015 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
03016     Action7 a7, Action8 a8) {
03017   return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8));
03018 }
03019 
03020 template <typename Action1, typename Action2, typename Action3,
03021     typename Action4, typename Action5, typename Action6, typename Action7,
03022     typename Action8, typename Action9>
03023 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
03024     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
03025     internal::DoBothAction<Action5, internal::DoBothAction<Action6,
03026     internal::DoBothAction<Action7, internal::DoBothAction<Action8,
03027     Action9> > > > > > > >
03028 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
03029     Action7 a7, Action8 a8, Action9 a9) {
03030   return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9));
03031 }
03032 
03033 template <typename Action1, typename Action2, typename Action3,
03034     typename Action4, typename Action5, typename Action6, typename Action7,
03035     typename Action8, typename Action9, typename Action10>
03036 inline internal::DoBothAction<Action1, internal::DoBothAction<Action2,
03037     internal::DoBothAction<Action3, internal::DoBothAction<Action4,
03038     internal::DoBothAction<Action5, internal::DoBothAction<Action6,
03039     internal::DoBothAction<Action7, internal::DoBothAction<Action8,
03040     internal::DoBothAction<Action9, Action10> > > > > > > > >
03041 DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
03042     Action7 a7, Action8 a8, Action9 a9, Action10 a10) {
03043   return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10));
03044 }
03045 
03046 }  // namespace testing
03047 
03048 // The ACTION* family of macros can be used in a namespace scope to
03049 // define custom actions easily.  The syntax:
03050 //
03051 //   ACTION(name) { statements; }
03052 //
03053 // will define an action with the given name that executes the
03054 // statements.  The value returned by the statements will be used as
03055 // the return value of the action.  Inside the statements, you can
03056 // refer to the K-th (0-based) argument of the mock function by
03057 // 'argK', and refer to its type by 'argK_type'.  For example:
03058 //
03059 //   ACTION(IncrementArg1) {
03060 //     arg1_type temp = arg1;
03061 //     return ++(*temp);
03062 //   }
03063 //
03064 // allows you to write
03065 //
03066 //   ...WillOnce(IncrementArg1());
03067 //
03068 // You can also refer to the entire argument tuple and its type by
03069 // 'args' and 'args_type', and refer to the mock function type and its
03070 // return type by 'function_type' and 'return_type'.
03071 //
03072 // Note that you don't need to specify the types of the mock function
03073 // arguments.  However rest assured that your code is still type-safe:
03074 // you'll get a compiler error if *arg1 doesn't support the ++
03075 // operator, or if the type of ++(*arg1) isn't compatible with the
03076 // mock function's return type, for example.
03077 //
03078 // Sometimes you'll want to parameterize the action.   For that you can use
03079 // another macro:
03080 //
03081 //   ACTION_P(name, param_name) { statements; }
03082 //
03083 // For example:
03084 //
03085 //   ACTION_P(Add, n) { return arg0 + n; }
03086 //
03087 // will allow you to write:
03088 //
03089 //   ...WillOnce(Add(5));
03090 //
03091 // Note that you don't need to provide the type of the parameter
03092 // either.  If you need to reference the type of a parameter named
03093 // 'foo', you can write 'foo_type'.  For example, in the body of
03094 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
03095 // of 'n'.
03096 //
03097 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
03098 // multi-parameter actions.
03099 //
03100 // For the purpose of typing, you can view
03101 //
03102 //   ACTION_Pk(Foo, p1, ..., pk) { ... }
03103 //
03104 // as shorthand for
03105 //
03106 //   template <typename p1_type, ..., typename pk_type>
03107 //   FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
03108 //
03109 // In particular, you can provide the template type arguments
03110 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
03111 // although usually you can rely on the compiler to infer the types
03112 // for you automatically.  You can assign the result of expression
03113 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
03114 // pk_type>.  This can be useful when composing actions.
03115 //
03116 // You can also overload actions with different numbers of parameters:
03117 //
03118 //   ACTION_P(Plus, a) { ... }
03119 //   ACTION_P2(Plus, a, b) { ... }
03120 //
03121 // While it's tempting to always use the ACTION* macros when defining
03122 // a new action, you should also consider implementing ActionInterface
03123 // or using MakePolymorphicAction() instead, especially if you need to
03124 // use the action a lot.  While these approaches require more work,
03125 // they give you more control on the types of the mock function
03126 // arguments and the action parameters, which in general leads to
03127 // better compiler error messages that pay off in the long run.  They
03128 // also allow overloading actions based on parameter types (as opposed
03129 // to just based on the number of parameters).
03130 //
03131 // CAVEAT:
03132 //
03133 // ACTION*() can only be used in a namespace scope.  The reason is
03134 // that C++ doesn't yet allow function-local types to be used to
03135 // instantiate templates.  The up-coming C++0x standard will fix this.
03136 // Once that's done, we'll consider supporting using ACTION*() inside
03137 // a function.
03138 //
03139 // MORE INFORMATION:
03140 //
03141 // To learn more about using these macros, please search for 'ACTION'
03142 // on http://code.google.com/p/googlemock/wiki/CookBook.
03143 
03144 // An internal macro needed for implementing ACTION*().
03145 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
03146     const args_type& args GTEST_ATTRIBUTE_UNUSED_, \
03147     arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \
03148     arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \
03149     arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \
03150     arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \
03151     arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \
03152     arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \
03153     arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \
03154     arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \
03155     arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \
03156     arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_
03157 
03158 // Sometimes you want to give an action explicit template parameters
03159 // that cannot be inferred from its value parameters.  ACTION() and
03160 // ACTION_P*() don't support that.  ACTION_TEMPLATE() remedies that
03161 // and can be viewed as an extension to ACTION() and ACTION_P*().
03162 //
03163 // The syntax:
03164 //
03165 //   ACTION_TEMPLATE(ActionName,
03166 //                   HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
03167 //                   AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
03168 //
03169 // defines an action template that takes m explicit template
03170 // parameters and n value parameters.  name_i is the name of the i-th
03171 // template parameter, and kind_i specifies whether it's a typename,
03172 // an integral constant, or a template.  p_i is the name of the i-th
03173 // value parameter.
03174 //
03175 // Example:
03176 //
03177 //   // DuplicateArg<k, T>(output) converts the k-th argument of the mock
03178 //   // function to type T and copies it to *output.
03179 //   ACTION_TEMPLATE(DuplicateArg,
03180 //                   HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
03181 //                   AND_1_VALUE_PARAMS(output)) {
03182 //     *output = T(std::tr1::get<k>(args));
03183 //   }
03184 //   ...
03185 //     int n;
03186 //     EXPECT_CALL(mock, Foo(_, _))
03187 //         .WillOnce(DuplicateArg<1, unsigned char>(&n));
03188 //
03189 // To create an instance of an action template, write:
03190 //
03191 //   ActionName<t1, ..., t_m>(v1, ..., v_n)
03192 //
03193 // where the ts are the template arguments and the vs are the value
03194 // arguments.  The value argument types are inferred by the compiler.
03195 // If you want to explicitly specify the value argument types, you can
03196 // provide additional template arguments:
03197 //
03198 //   ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
03199 //
03200 // where u_i is the desired type of v_i.
03201 //
03202 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
03203 // number of value parameters, but not on the number of template
03204 // parameters.  Without the restriction, the meaning of the following
03205 // is unclear:
03206 //
03207 //   OverloadedAction<int, bool>(x);
03208 //
03209 // Are we using a single-template-parameter action where 'bool' refers
03210 // to the type of x, or are we using a two-template-parameter action
03211 // where the compiler is asked to infer the type of x?
03212 //
03213 // Implementation notes:
03214 //
03215 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
03216 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
03217 // implementing ACTION_TEMPLATE.  The main trick we use is to create
03218 // new macro invocations when expanding a macro.  For example, we have
03219 //
03220 //   #define ACTION_TEMPLATE(name, template_params, value_params)
03221 //       ... GMOCK_INTERNAL_DECL_##template_params ...
03222 //
03223 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
03224 // to expand to
03225 //
03226 //       ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
03227 //
03228 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
03229 // preprocessor will continue to expand it to
03230 //
03231 //       ... typename T ...
03232 //
03233 // This technique conforms to the C++ standard and is portable.  It
03234 // allows us to implement action templates using O(N) code, where N is
03235 // the maximum number of template/value parameters supported.  Without
03236 // using it, we'd have to devote O(N^2) amount of code to implement all
03237 // combinations of m and n.
03238 
03239 // Declares the template parameters.
03240 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
03241 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
03242     name1) kind0 name0, kind1 name1
03243 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03244     kind2, name2) kind0 name0, kind1 name1, kind2 name2
03245 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03246     kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
03247     kind3 name3
03248 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03249     kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
03250     kind2 name2, kind3 name3, kind4 name4
03251 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03252     kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
03253     kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
03254 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03255     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
03256     name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
03257     kind5 name5, kind6 name6
03258 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03259     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
03260     kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
03261     kind4 name4, kind5 name5, kind6 name6, kind7 name7
03262 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03263     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
03264     kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
03265     kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
03266     kind8 name8
03267 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
03268     name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
03269     name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
03270     kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
03271     kind6 name6, kind7 name7, kind8 name8, kind9 name9
03272 
03273 // Lists the template parameters.
03274 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
03275 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
03276     name1) name0, name1
03277 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03278     kind2, name2) name0, name1, name2
03279 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03280     kind2, name2, kind3, name3) name0, name1, name2, name3
03281 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03282     kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
03283     name4
03284 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03285     kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
03286     name2, name3, name4, name5
03287 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03288     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
03289     name6) name0, name1, name2, name3, name4, name5, name6
03290 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03291     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
03292     kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
03293 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
03294     kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
03295     kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
03296     name6, name7, name8
03297 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
03298     name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
03299     name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
03300     name3, name4, name5, name6, name7, name8, name9
03301 
03302 // Declares the types of value parameters.
03303 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
03304 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
03305 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
03306     typename p0##_type, typename p1##_type
03307 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
03308     typename p0##_type, typename p1##_type, typename p2##_type
03309 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
03310     typename p0##_type, typename p1##_type, typename p2##_type, \
03311     typename p3##_type
03312 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
03313     typename p0##_type, typename p1##_type, typename p2##_type, \
03314     typename p3##_type, typename p4##_type
03315 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
03316     typename p0##_type, typename p1##_type, typename p2##_type, \
03317     typename p3##_type, typename p4##_type, typename p5##_type
03318 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03319     p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
03320     typename p3##_type, typename p4##_type, typename p5##_type, \
03321     typename p6##_type
03322 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03323     p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
03324     typename p3##_type, typename p4##_type, typename p5##_type, \
03325     typename p6##_type, typename p7##_type
03326 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03327     p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
03328     typename p3##_type, typename p4##_type, typename p5##_type, \
03329     typename p6##_type, typename p7##_type, typename p8##_type
03330 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03331     p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
03332     typename p2##_type, typename p3##_type, typename p4##_type, \
03333     typename p5##_type, typename p6##_type, typename p7##_type, \
03334     typename p8##_type, typename p9##_type
03335 
03336 // Initializes the value parameters.
03337 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
03338     ()
03339 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
03340     (p0##_type gmock_p0) : p0(gmock_p0)
03341 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
03342     (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
03343 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
03344     (p0##_type gmock_p0, p1##_type gmock_p1, \
03345         p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
03346 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
03347     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03348         p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03349         p3(gmock_p3)
03350 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
03351     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03352         p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
03353         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
03354 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
03355     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03356         p3##_type gmock_p3, p4##_type gmock_p4, \
03357         p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03358         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
03359 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
03360     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03361         p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
03362         p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03363         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
03364 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
03365     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03366         p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
03367         p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
03368         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
03369         p7(gmock_p7)
03370 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03371     p7, p8)\
03372     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03373         p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
03374         p6##_type gmock_p6, p7##_type gmock_p7, \
03375         p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03376         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
03377         p8(gmock_p8)
03378 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03379     p7, p8, p9)\
03380     (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03381         p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
03382         p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
03383         p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03384         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
03385         p8(gmock_p8), p9(gmock_p9)
03386 
03387 // Declares the fields for storing the value parameters.
03388 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
03389 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
03390 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
03391     p1##_type p1;
03392 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
03393     p1##_type p1; p2##_type p2;
03394 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
03395     p1##_type p1; p2##_type p2; p3##_type p3;
03396 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
03397     p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
03398 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
03399     p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
03400     p5##_type p5;
03401 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03402     p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
03403     p5##_type p5; p6##_type p6;
03404 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03405     p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
03406     p5##_type p5; p6##_type p6; p7##_type p7;
03407 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03408     p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
03409     p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
03410 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03411     p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
03412     p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
03413     p9##_type p9;
03414 
03415 // Lists the value parameters.
03416 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
03417 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
03418 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
03419 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
03420 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
03421 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
03422     p2, p3, p4
03423 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
03424     p1, p2, p3, p4, p5
03425 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03426     p6) p0, p1, p2, p3, p4, p5, p6
03427 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03428     p7) p0, p1, p2, p3, p4, p5, p6, p7
03429 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03430     p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
03431 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03432     p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
03433 
03434 // Lists the value parameter types.
03435 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
03436 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
03437 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
03438     p1##_type
03439 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
03440     p1##_type, p2##_type
03441 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
03442     p0##_type, p1##_type, p2##_type, p3##_type
03443 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
03444     p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
03445 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
03446     p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
03447 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03448     p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
03449     p6##_type
03450 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03451     p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
03452     p5##_type, p6##_type, p7##_type
03453 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03454     p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
03455     p5##_type, p6##_type, p7##_type, p8##_type
03456 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03457     p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
03458     p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
03459 
03460 // Declares the value parameters.
03461 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
03462 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
03463 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
03464     p1##_type p1
03465 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
03466     p1##_type p1, p2##_type p2
03467 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
03468     p1##_type p1, p2##_type p2, p3##_type p3
03469 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
03470     p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
03471 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
03472     p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
03473     p5##_type p5
03474 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
03475     p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
03476     p5##_type p5, p6##_type p6
03477 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03478     p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
03479     p5##_type p5, p6##_type p6, p7##_type p7
03480 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03481     p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
03482     p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
03483 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03484     p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
03485     p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
03486     p9##_type p9
03487 
03488 // The suffix of the class template implementing the action template.
03489 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
03490 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
03491 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
03492 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
03493 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
03494 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
03495 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
03496 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
03497 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03498     p7) P8
03499 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03500     p7, p8) P9
03501 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
03502     p7, p8, p9) P10
03503 
03504 // The name of the class template implementing the action template.
03505 #define GMOCK_ACTION_CLASS_(name, value_params)\
03506     GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
03507 
03508 #define ACTION_TEMPLATE(name, template_params, value_params)\
03509   template <GMOCK_INTERNAL_DECL_##template_params\
03510             GMOCK_INTERNAL_DECL_TYPE_##value_params>\
03511   class GMOCK_ACTION_CLASS_(name, value_params) {\
03512    public:\
03513     GMOCK_ACTION_CLASS_(name, value_params)\
03514         GMOCK_INTERNAL_INIT_##value_params {}\
03515     template <typename F>\
03516     class gmock_Impl : public ::testing::ActionInterface<F> {\
03517      public:\
03518       typedef F function_type;\
03519       typedef typename ::testing::internal::Function<F>::Result return_type;\
03520       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03521           args_type;\
03522       explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
03523       virtual return_type Perform(const args_type& args) {\
03524         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03525             Perform(this, args);\
03526       }\
03527       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03528           typename arg3_type, typename arg4_type, typename arg5_type, \
03529           typename arg6_type, typename arg7_type, typename arg8_type, \
03530           typename arg9_type>\
03531       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03532           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03533           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03534           arg9_type arg9) const;\
03535       GMOCK_INTERNAL_DEFN_##value_params\
03536      private:\
03537       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03538     };\
03539     template <typename F> operator ::testing::Action<F>() const {\
03540       return ::testing::Action<F>(\
03541           new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
03542     }\
03543     GMOCK_INTERNAL_DEFN_##value_params\
03544    private:\
03545     GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
03546   };\
03547   template <GMOCK_INTERNAL_DECL_##template_params\
03548             GMOCK_INTERNAL_DECL_TYPE_##value_params>\
03549   inline GMOCK_ACTION_CLASS_(name, value_params)<\
03550       GMOCK_INTERNAL_LIST_##template_params\
03551       GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
03552           GMOCK_INTERNAL_DECL_##value_params) {\
03553     return GMOCK_ACTION_CLASS_(name, value_params)<\
03554         GMOCK_INTERNAL_LIST_##template_params\
03555         GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
03556             GMOCK_INTERNAL_LIST_##value_params);\
03557   }\
03558   template <GMOCK_INTERNAL_DECL_##template_params\
03559             GMOCK_INTERNAL_DECL_TYPE_##value_params>\
03560   template <typename F>\
03561   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03562       typename arg3_type, typename arg4_type, typename arg5_type, \
03563       typename arg6_type, typename arg7_type, typename arg8_type, \
03564       typename arg9_type>\
03565   typename ::testing::internal::Function<F>::Result\
03566       GMOCK_ACTION_CLASS_(name, value_params)<\
03567           GMOCK_INTERNAL_LIST_##template_params\
03568           GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
03569               gmock_PerformImpl(\
03570           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03571 
03572 #define ACTION(name)\
03573   class name##Action {\
03574    public:\
03575     name##Action() {}\
03576     template <typename F>\
03577     class gmock_Impl : public ::testing::ActionInterface<F> {\
03578      public:\
03579       typedef F function_type;\
03580       typedef typename ::testing::internal::Function<F>::Result return_type;\
03581       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03582           args_type;\
03583       gmock_Impl() {}\
03584       virtual return_type Perform(const args_type& args) {\
03585         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03586             Perform(this, args);\
03587       }\
03588       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03589           typename arg3_type, typename arg4_type, typename arg5_type, \
03590           typename arg6_type, typename arg7_type, typename arg8_type, \
03591           typename arg9_type>\
03592       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03593           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03594           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03595           arg9_type arg9) const;\
03596      private:\
03597       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03598     };\
03599     template <typename F> operator ::testing::Action<F>() const {\
03600       return ::testing::Action<F>(new gmock_Impl<F>());\
03601     }\
03602    private:\
03603     GTEST_DISALLOW_ASSIGN_(name##Action);\
03604   };\
03605   inline name##Action name() {\
03606     return name##Action();\
03607   }\
03608   template <typename F>\
03609   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03610       typename arg3_type, typename arg4_type, typename arg5_type, \
03611       typename arg6_type, typename arg7_type, typename arg8_type, \
03612       typename arg9_type>\
03613   typename ::testing::internal::Function<F>::Result\
03614       name##Action::gmock_Impl<F>::gmock_PerformImpl(\
03615           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03616 
03617 #define ACTION_P(name, p0)\
03618   template <typename p0##_type>\
03619   class name##ActionP {\
03620    public:\
03621     name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
03622     template <typename F>\
03623     class gmock_Impl : public ::testing::ActionInterface<F> {\
03624      public:\
03625       typedef F function_type;\
03626       typedef typename ::testing::internal::Function<F>::Result return_type;\
03627       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03628           args_type;\
03629       explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
03630       virtual return_type Perform(const args_type& args) {\
03631         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03632             Perform(this, args);\
03633       }\
03634       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03635           typename arg3_type, typename arg4_type, typename arg5_type, \
03636           typename arg6_type, typename arg7_type, typename arg8_type, \
03637           typename arg9_type>\
03638       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03639           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03640           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03641           arg9_type arg9) const;\
03642       p0##_type p0;\
03643      private:\
03644       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03645     };\
03646     template <typename F> operator ::testing::Action<F>() const {\
03647       return ::testing::Action<F>(new gmock_Impl<F>(p0));\
03648     }\
03649     p0##_type p0;\
03650    private:\
03651     GTEST_DISALLOW_ASSIGN_(name##ActionP);\
03652   };\
03653   template <typename p0##_type>\
03654   inline name##ActionP<p0##_type> name(p0##_type p0) {\
03655     return name##ActionP<p0##_type>(p0);\
03656   }\
03657   template <typename p0##_type>\
03658   template <typename F>\
03659   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03660       typename arg3_type, typename arg4_type, typename arg5_type, \
03661       typename arg6_type, typename arg7_type, typename arg8_type, \
03662       typename arg9_type>\
03663   typename ::testing::internal::Function<F>::Result\
03664       name##ActionP<p0##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03665           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03666 
03667 #define ACTION_P2(name, p0, p1)\
03668   template <typename p0##_type, typename p1##_type>\
03669   class name##ActionP2 {\
03670    public:\
03671     name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
03672         p1(gmock_p1) {}\
03673     template <typename F>\
03674     class gmock_Impl : public ::testing::ActionInterface<F> {\
03675      public:\
03676       typedef F function_type;\
03677       typedef typename ::testing::internal::Function<F>::Result return_type;\
03678       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03679           args_type;\
03680       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
03681           p1(gmock_p1) {}\
03682       virtual return_type Perform(const args_type& args) {\
03683         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03684             Perform(this, args);\
03685       }\
03686       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03687           typename arg3_type, typename arg4_type, typename arg5_type, \
03688           typename arg6_type, typename arg7_type, typename arg8_type, \
03689           typename arg9_type>\
03690       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03691           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03692           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03693           arg9_type arg9) const;\
03694       p0##_type p0;\
03695       p1##_type p1;\
03696      private:\
03697       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03698     };\
03699     template <typename F> operator ::testing::Action<F>() const {\
03700       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
03701     }\
03702     p0##_type p0;\
03703     p1##_type p1;\
03704    private:\
03705     GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
03706   };\
03707   template <typename p0##_type, typename p1##_type>\
03708   inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
03709       p1##_type p1) {\
03710     return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
03711   }\
03712   template <typename p0##_type, typename p1##_type>\
03713   template <typename F>\
03714   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03715       typename arg3_type, typename arg4_type, typename arg5_type, \
03716       typename arg6_type, typename arg7_type, typename arg8_type, \
03717       typename arg9_type>\
03718   typename ::testing::internal::Function<F>::Result\
03719       name##ActionP2<p0##_type, p1##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03720           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03721 
03722 #define ACTION_P3(name, p0, p1, p2)\
03723   template <typename p0##_type, typename p1##_type, typename p2##_type>\
03724   class name##ActionP3 {\
03725    public:\
03726     name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
03727         p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
03728     template <typename F>\
03729     class gmock_Impl : public ::testing::ActionInterface<F> {\
03730      public:\
03731       typedef F function_type;\
03732       typedef typename ::testing::internal::Function<F>::Result return_type;\
03733       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03734           args_type;\
03735       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
03736           p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
03737       virtual return_type Perform(const args_type& args) {\
03738         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03739             Perform(this, args);\
03740       }\
03741       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03742           typename arg3_type, typename arg4_type, typename arg5_type, \
03743           typename arg6_type, typename arg7_type, typename arg8_type, \
03744           typename arg9_type>\
03745       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03746           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03747           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03748           arg9_type arg9) const;\
03749       p0##_type p0;\
03750       p1##_type p1;\
03751       p2##_type p2;\
03752      private:\
03753       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03754     };\
03755     template <typename F> operator ::testing::Action<F>() const {\
03756       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
03757     }\
03758     p0##_type p0;\
03759     p1##_type p1;\
03760     p2##_type p2;\
03761    private:\
03762     GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
03763   };\
03764   template <typename p0##_type, typename p1##_type, typename p2##_type>\
03765   inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
03766       p1##_type p1, p2##_type p2) {\
03767     return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
03768   }\
03769   template <typename p0##_type, typename p1##_type, typename p2##_type>\
03770   template <typename F>\
03771   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03772       typename arg3_type, typename arg4_type, typename arg5_type, \
03773       typename arg6_type, typename arg7_type, typename arg8_type, \
03774       typename arg9_type>\
03775   typename ::testing::internal::Function<F>::Result\
03776       name##ActionP3<p0##_type, p1##_type, \
03777           p2##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03778           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03779 
03780 #define ACTION_P4(name, p0, p1, p2, p3)\
03781   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03782       typename p3##_type>\
03783   class name##ActionP4 {\
03784    public:\
03785     name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
03786         p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
03787         p2(gmock_p2), p3(gmock_p3) {}\
03788     template <typename F>\
03789     class gmock_Impl : public ::testing::ActionInterface<F> {\
03790      public:\
03791       typedef F function_type;\
03792       typedef typename ::testing::internal::Function<F>::Result return_type;\
03793       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03794           args_type;\
03795       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03796           p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03797           p3(gmock_p3) {}\
03798       virtual return_type Perform(const args_type& args) {\
03799         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03800             Perform(this, args);\
03801       }\
03802       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03803           typename arg3_type, typename arg4_type, typename arg5_type, \
03804           typename arg6_type, typename arg7_type, typename arg8_type, \
03805           typename arg9_type>\
03806       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03807           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03808           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03809           arg9_type arg9) const;\
03810       p0##_type p0;\
03811       p1##_type p1;\
03812       p2##_type p2;\
03813       p3##_type p3;\
03814      private:\
03815       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03816     };\
03817     template <typename F> operator ::testing::Action<F>() const {\
03818       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
03819     }\
03820     p0##_type p0;\
03821     p1##_type p1;\
03822     p2##_type p2;\
03823     p3##_type p3;\
03824    private:\
03825     GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
03826   };\
03827   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03828       typename p3##_type>\
03829   inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
03830       p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
03831       p3##_type p3) {\
03832     return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p1, \
03833         p2, p3);\
03834   }\
03835   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03836       typename p3##_type>\
03837   template <typename F>\
03838   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03839       typename arg3_type, typename arg4_type, typename arg5_type, \
03840       typename arg6_type, typename arg7_type, typename arg8_type, \
03841       typename arg9_type>\
03842   typename ::testing::internal::Function<F>::Result\
03843       name##ActionP4<p0##_type, p1##_type, p2##_type, \
03844           p3##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03845           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03846 
03847 #define ACTION_P5(name, p0, p1, p2, p3, p4)\
03848   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03849       typename p3##_type, typename p4##_type>\
03850   class name##ActionP5 {\
03851    public:\
03852     name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
03853         p2##_type gmock_p2, p3##_type gmock_p3, \
03854         p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03855         p3(gmock_p3), p4(gmock_p4) {}\
03856     template <typename F>\
03857     class gmock_Impl : public ::testing::ActionInterface<F> {\
03858      public:\
03859       typedef F function_type;\
03860       typedef typename ::testing::internal::Function<F>::Result return_type;\
03861       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03862           args_type;\
03863       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03864           p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
03865           p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
03866       virtual return_type Perform(const args_type& args) {\
03867         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03868             Perform(this, args);\
03869       }\
03870       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03871           typename arg3_type, typename arg4_type, typename arg5_type, \
03872           typename arg6_type, typename arg7_type, typename arg8_type, \
03873           typename arg9_type>\
03874       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03875           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03876           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03877           arg9_type arg9) const;\
03878       p0##_type p0;\
03879       p1##_type p1;\
03880       p2##_type p2;\
03881       p3##_type p3;\
03882       p4##_type p4;\
03883      private:\
03884       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03885     };\
03886     template <typename F> operator ::testing::Action<F>() const {\
03887       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
03888     }\
03889     p0##_type p0;\
03890     p1##_type p1;\
03891     p2##_type p2;\
03892     p3##_type p3;\
03893     p4##_type p4;\
03894    private:\
03895     GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
03896   };\
03897   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03898       typename p3##_type, typename p4##_type>\
03899   inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
03900       p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
03901       p4##_type p4) {\
03902     return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
03903         p4##_type>(p0, p1, p2, p3, p4);\
03904   }\
03905   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03906       typename p3##_type, typename p4##_type>\
03907   template <typename F>\
03908   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03909       typename arg3_type, typename arg4_type, typename arg5_type, \
03910       typename arg6_type, typename arg7_type, typename arg8_type, \
03911       typename arg9_type>\
03912   typename ::testing::internal::Function<F>::Result\
03913       name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
03914           p4##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03915           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03916 
03917 #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
03918   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03919       typename p3##_type, typename p4##_type, typename p5##_type>\
03920   class name##ActionP6 {\
03921    public:\
03922     name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
03923         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
03924         p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03925         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
03926     template <typename F>\
03927     class gmock_Impl : public ::testing::ActionInterface<F> {\
03928      public:\
03929       typedef F function_type;\
03930       typedef typename ::testing::internal::Function<F>::Result return_type;\
03931       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
03932           args_type;\
03933       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
03934           p3##_type gmock_p3, p4##_type gmock_p4, \
03935           p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
03936           p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
03937       virtual return_type Perform(const args_type& args) {\
03938         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
03939             Perform(this, args);\
03940       }\
03941       template <typename arg0_type, typename arg1_type, typename arg2_type, \
03942           typename arg3_type, typename arg4_type, typename arg5_type, \
03943           typename arg6_type, typename arg7_type, typename arg8_type, \
03944           typename arg9_type>\
03945       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
03946           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
03947           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
03948           arg9_type arg9) const;\
03949       p0##_type p0;\
03950       p1##_type p1;\
03951       p2##_type p2;\
03952       p3##_type p3;\
03953       p4##_type p4;\
03954       p5##_type p5;\
03955      private:\
03956       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
03957     };\
03958     template <typename F> operator ::testing::Action<F>() const {\
03959       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
03960     }\
03961     p0##_type p0;\
03962     p1##_type p1;\
03963     p2##_type p2;\
03964     p3##_type p3;\
03965     p4##_type p4;\
03966     p5##_type p5;\
03967    private:\
03968     GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
03969   };\
03970   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03971       typename p3##_type, typename p4##_type, typename p5##_type>\
03972   inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
03973       p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
03974       p3##_type p3, p4##_type p4, p5##_type p5) {\
03975     return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
03976         p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
03977   }\
03978   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03979       typename p3##_type, typename p4##_type, typename p5##_type>\
03980   template <typename F>\
03981   template <typename arg0_type, typename arg1_type, typename arg2_type, \
03982       typename arg3_type, typename arg4_type, typename arg5_type, \
03983       typename arg6_type, typename arg7_type, typename arg8_type, \
03984       typename arg9_type>\
03985   typename ::testing::internal::Function<F>::Result\
03986       name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
03987           p5##_type>::gmock_Impl<F>::gmock_PerformImpl(\
03988           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
03989 
03990 #define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\
03991   template <typename p0##_type, typename p1##_type, typename p2##_type, \
03992       typename p3##_type, typename p4##_type, typename p5##_type, \
03993       typename p6##_type>\
03994   class name##ActionP7 {\
03995    public:\
03996     name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
03997         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
03998         p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
03999         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
04000         p6(gmock_p6) {}\
04001     template <typename F>\
04002     class gmock_Impl : public ::testing::ActionInterface<F> {\
04003      public:\
04004       typedef F function_type;\
04005       typedef typename ::testing::internal::Function<F>::Result return_type;\
04006       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
04007           args_type;\
04008       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
04009           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
04010           p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
04011           p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
04012       virtual return_type Perform(const args_type& args) {\
04013         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
04014             Perform(this, args);\
04015       }\
04016       template <typename arg0_type, typename arg1_type, typename arg2_type, \
04017           typename arg3_type, typename arg4_type, typename arg5_type, \
04018           typename arg6_type, typename arg7_type, typename arg8_type, \
04019           typename arg9_type>\
04020       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
04021           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
04022           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
04023           arg9_type arg9) const;\
04024       p0##_type p0;\
04025       p1##_type p1;\
04026       p2##_type p2;\
04027       p3##_type p3;\
04028       p4##_type p4;\
04029       p5##_type p5;\
04030       p6##_type p6;\
04031      private:\
04032       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
04033     };\
04034     template <typename F> operator ::testing::Action<F>() const {\
04035       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
04036           p6));\
04037     }\
04038     p0##_type p0;\
04039     p1##_type p1;\
04040     p2##_type p2;\
04041     p3##_type p3;\
04042     p4##_type p4;\
04043     p5##_type p5;\
04044     p6##_type p6;\
04045    private:\
04046     GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
04047   };\
04048   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04049       typename p3##_type, typename p4##_type, typename p5##_type, \
04050       typename p6##_type>\
04051   inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
04052       p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
04053       p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
04054       p6##_type p6) {\
04055     return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
04056         p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
04057   }\
04058   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04059       typename p3##_type, typename p4##_type, typename p5##_type, \
04060       typename p6##_type>\
04061   template <typename F>\
04062   template <typename arg0_type, typename arg1_type, typename arg2_type, \
04063       typename arg3_type, typename arg4_type, typename arg5_type, \
04064       typename arg6_type, typename arg7_type, typename arg8_type, \
04065       typename arg9_type>\
04066   typename ::testing::internal::Function<F>::Result\
04067       name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
04068           p5##_type, p6##_type>::gmock_Impl<F>::gmock_PerformImpl(\
04069           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
04070 
04071 #define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\
04072   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04073       typename p3##_type, typename p4##_type, typename p5##_type, \
04074       typename p6##_type, typename p7##_type>\
04075   class name##ActionP8 {\
04076    public:\
04077     name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
04078         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
04079         p5##_type gmock_p5, p6##_type gmock_p6, \
04080         p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
04081         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
04082         p7(gmock_p7) {}\
04083     template <typename F>\
04084     class gmock_Impl : public ::testing::ActionInterface<F> {\
04085      public:\
04086       typedef F function_type;\
04087       typedef typename ::testing::internal::Function<F>::Result return_type;\
04088       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
04089           args_type;\
04090       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
04091           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
04092           p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
04093           p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
04094           p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
04095       virtual return_type Perform(const args_type& args) {\
04096         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
04097             Perform(this, args);\
04098       }\
04099       template <typename arg0_type, typename arg1_type, typename arg2_type, \
04100           typename arg3_type, typename arg4_type, typename arg5_type, \
04101           typename arg6_type, typename arg7_type, typename arg8_type, \
04102           typename arg9_type>\
04103       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
04104           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
04105           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
04106           arg9_type arg9) const;\
04107       p0##_type p0;\
04108       p1##_type p1;\
04109       p2##_type p2;\
04110       p3##_type p3;\
04111       p4##_type p4;\
04112       p5##_type p5;\
04113       p6##_type p6;\
04114       p7##_type p7;\
04115      private:\
04116       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
04117     };\
04118     template <typename F> operator ::testing::Action<F>() const {\
04119       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
04120           p6, p7));\
04121     }\
04122     p0##_type p0;\
04123     p1##_type p1;\
04124     p2##_type p2;\
04125     p3##_type p3;\
04126     p4##_type p4;\
04127     p5##_type p5;\
04128     p6##_type p6;\
04129     p7##_type p7;\
04130    private:\
04131     GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
04132   };\
04133   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04134       typename p3##_type, typename p4##_type, typename p5##_type, \
04135       typename p6##_type, typename p7##_type>\
04136   inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
04137       p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
04138       p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
04139       p6##_type p6, p7##_type p7) {\
04140     return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
04141         p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
04142         p6, p7);\
04143   }\
04144   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04145       typename p3##_type, typename p4##_type, typename p5##_type, \
04146       typename p6##_type, typename p7##_type>\
04147   template <typename F>\
04148   template <typename arg0_type, typename arg1_type, typename arg2_type, \
04149       typename arg3_type, typename arg4_type, typename arg5_type, \
04150       typename arg6_type, typename arg7_type, typename arg8_type, \
04151       typename arg9_type>\
04152   typename ::testing::internal::Function<F>::Result\
04153       name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
04154           p5##_type, p6##_type, \
04155           p7##_type>::gmock_Impl<F>::gmock_PerformImpl(\
04156           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
04157 
04158 #define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\
04159   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04160       typename p3##_type, typename p4##_type, typename p5##_type, \
04161       typename p6##_type, typename p7##_type, typename p8##_type>\
04162   class name##ActionP9 {\
04163    public:\
04164     name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
04165         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
04166         p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
04167         p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
04168         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
04169         p8(gmock_p8) {}\
04170     template <typename F>\
04171     class gmock_Impl : public ::testing::ActionInterface<F> {\
04172      public:\
04173       typedef F function_type;\
04174       typedef typename ::testing::internal::Function<F>::Result return_type;\
04175       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
04176           args_type;\
04177       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
04178           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
04179           p6##_type gmock_p6, p7##_type gmock_p7, \
04180           p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
04181           p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
04182           p7(gmock_p7), p8(gmock_p8) {}\
04183       virtual return_type Perform(const args_type& args) {\
04184         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
04185             Perform(this, args);\
04186       }\
04187       template <typename arg0_type, typename arg1_type, typename arg2_type, \
04188           typename arg3_type, typename arg4_type, typename arg5_type, \
04189           typename arg6_type, typename arg7_type, typename arg8_type, \
04190           typename arg9_type>\
04191       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
04192           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
04193           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
04194           arg9_type arg9) const;\
04195       p0##_type p0;\
04196       p1##_type p1;\
04197       p2##_type p2;\
04198       p3##_type p3;\
04199       p4##_type p4;\
04200       p5##_type p5;\
04201       p6##_type p6;\
04202       p7##_type p7;\
04203       p8##_type p8;\
04204      private:\
04205       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
04206     };\
04207     template <typename F> operator ::testing::Action<F>() const {\
04208       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
04209           p6, p7, p8));\
04210     }\
04211     p0##_type p0;\
04212     p1##_type p1;\
04213     p2##_type p2;\
04214     p3##_type p3;\
04215     p4##_type p4;\
04216     p5##_type p5;\
04217     p6##_type p6;\
04218     p7##_type p7;\
04219     p8##_type p8;\
04220    private:\
04221     GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
04222   };\
04223   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04224       typename p3##_type, typename p4##_type, typename p5##_type, \
04225       typename p6##_type, typename p7##_type, typename p8##_type>\
04226   inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
04227       p4##_type, p5##_type, p6##_type, p7##_type, \
04228       p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
04229       p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
04230       p8##_type p8) {\
04231     return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
04232         p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
04233         p3, p4, p5, p6, p7, p8);\
04234   }\
04235   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04236       typename p3##_type, typename p4##_type, typename p5##_type, \
04237       typename p6##_type, typename p7##_type, typename p8##_type>\
04238   template <typename F>\
04239   template <typename arg0_type, typename arg1_type, typename arg2_type, \
04240       typename arg3_type, typename arg4_type, typename arg5_type, \
04241       typename arg6_type, typename arg7_type, typename arg8_type, \
04242       typename arg9_type>\
04243   typename ::testing::internal::Function<F>::Result\
04244       name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
04245           p5##_type, p6##_type, p7##_type, \
04246           p8##_type>::gmock_Impl<F>::gmock_PerformImpl(\
04247           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
04248 
04249 #define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\
04250   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04251       typename p3##_type, typename p4##_type, typename p5##_type, \
04252       typename p6##_type, typename p7##_type, typename p8##_type, \
04253       typename p9##_type>\
04254   class name##ActionP10 {\
04255    public:\
04256     name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
04257         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
04258         p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
04259         p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
04260         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
04261         p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
04262     template <typename F>\
04263     class gmock_Impl : public ::testing::ActionInterface<F> {\
04264      public:\
04265       typedef F function_type;\
04266       typedef typename ::testing::internal::Function<F>::Result return_type;\
04267       typedef typename ::testing::internal::Function<F>::ArgumentTuple\
04268           args_type;\
04269       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
04270           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
04271           p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
04272           p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
04273           p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
04274           p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
04275       virtual return_type Perform(const args_type& args) {\
04276         return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
04277             Perform(this, args);\
04278       }\
04279       template <typename arg0_type, typename arg1_type, typename arg2_type, \
04280           typename arg3_type, typename arg4_type, typename arg5_type, \
04281           typename arg6_type, typename arg7_type, typename arg8_type, \
04282           typename arg9_type>\
04283       return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
04284           arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
04285           arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
04286           arg9_type arg9) const;\
04287       p0##_type p0;\
04288       p1##_type p1;\
04289       p2##_type p2;\
04290       p3##_type p3;\
04291       p4##_type p4;\
04292       p5##_type p5;\
04293       p6##_type p6;\
04294       p7##_type p7;\
04295       p8##_type p8;\
04296       p9##_type p9;\
04297      private:\
04298       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
04299     };\
04300     template <typename F> operator ::testing::Action<F>() const {\
04301       return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
04302           p6, p7, p8, p9));\
04303     }\
04304     p0##_type p0;\
04305     p1##_type p1;\
04306     p2##_type p2;\
04307     p3##_type p3;\
04308     p4##_type p4;\
04309     p5##_type p5;\
04310     p6##_type p6;\
04311     p7##_type p7;\
04312     p8##_type p8;\
04313     p9##_type p9;\
04314    private:\
04315     GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
04316   };\
04317   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04318       typename p3##_type, typename p4##_type, typename p5##_type, \
04319       typename p6##_type, typename p7##_type, typename p8##_type, \
04320       typename p9##_type>\
04321   inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
04322       p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
04323       p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
04324       p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
04325       p9##_type p9) {\
04326     return name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
04327         p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
04328         p1, p2, p3, p4, p5, p6, p7, p8, p9);\
04329   }\
04330   template <typename p0##_type, typename p1##_type, typename p2##_type, \
04331       typename p3##_type, typename p4##_type, typename p5##_type, \
04332       typename p6##_type, typename p7##_type, typename p8##_type, \
04333       typename p9##_type>\
04334   template <typename F>\
04335   template <typename arg0_type, typename arg1_type, typename arg2_type, \
04336       typename arg3_type, typename arg4_type, typename arg5_type, \
04337       typename arg6_type, typename arg7_type, typename arg8_type, \
04338       typename arg9_type>\
04339   typename ::testing::internal::Function<F>::Result\
04340       name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
04341           p5##_type, p6##_type, p7##_type, p8##_type, \
04342           p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
04343           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
04344 
04345 namespace testing {
04346 
04347 // The ACTION*() macros trigger warning C4100 (unreferenced formal
04348 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
04349 // the macro definition, as the warnings are generated when the macro
04350 // is expanded and macro expansion cannot contain #pragma.  Therefore
04351 // we suppress them here.
04352 #ifdef _MSC_VER
04353 # pragma warning(push)
04354 # pragma warning(disable:4100)
04355 #endif
04356 
04357 // Various overloads for InvokeArgument<N>().
04358 //
04359 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
04360 // (0-based) argument, which must be a k-ary callable, of the mock
04361 // function, with arguments a1, a2, ..., a_k.
04362 //
04363 // Notes:
04364 //
04365 //   1. The arguments are passed by value by default.  If you need to
04366 //   pass an argument by reference, wrap it inside ByRef().  For
04367 //   example,
04368 //
04369 //     InvokeArgument<1>(5, string("Hello"), ByRef(foo))
04370 //
04371 //   passes 5 and string("Hello") by value, and passes foo by
04372 //   reference.
04373 //
04374 //   2. If the callable takes an argument by reference but ByRef() is
04375 //   not used, it will receive the reference to a copy of the value,
04376 //   instead of the original value.  For example, when the 0-th
04377 //   argument of the mock function takes a const string&, the action
04378 //
04379 //     InvokeArgument<0>(string("Hello"))
04380 //
04381 //   makes a copy of the temporary string("Hello") object and passes a
04382 //   reference of the copy, instead of the original temporary object,
04383 //   to the callable.  This makes it easy for a user to define an
04384 //   InvokeArgument action from temporary values and have it performed
04385 //   later.
04386 
04387 ACTION_TEMPLATE(InvokeArgument,
04388                 HAS_1_TEMPLATE_PARAMS(int, k),
04389                 AND_0_VALUE_PARAMS()) {
04390   return internal::CallableHelper<return_type>::Call(
04391       ::std::tr1::get<k>(args));
04392 }
04393 
04394 ACTION_TEMPLATE(InvokeArgument,
04395                 HAS_1_TEMPLATE_PARAMS(int, k),
04396                 AND_1_VALUE_PARAMS(p0)) {
04397   return internal::CallableHelper<return_type>::Call(
04398       ::std::tr1::get<k>(args), p0);
04399 }
04400 
04401 ACTION_TEMPLATE(InvokeArgument,
04402                 HAS_1_TEMPLATE_PARAMS(int, k),
04403                 AND_2_VALUE_PARAMS(p0, p1)) {
04404   return internal::CallableHelper<return_type>::Call(
04405       ::std::tr1::get<k>(args), p0, p1);
04406 }
04407 
04408 ACTION_TEMPLATE(InvokeArgument,
04409                 HAS_1_TEMPLATE_PARAMS(int, k),
04410                 AND_3_VALUE_PARAMS(p0, p1, p2)) {
04411   return internal::CallableHelper<return_type>::Call(
04412       ::std::tr1::get<k>(args), p0, p1, p2);
04413 }
04414 
04415 ACTION_TEMPLATE(InvokeArgument,
04416                 HAS_1_TEMPLATE_PARAMS(int, k),
04417                 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
04418   return internal::CallableHelper<return_type>::Call(
04419       ::std::tr1::get<k>(args), p0, p1, p2, p3);
04420 }
04421 
04422 ACTION_TEMPLATE(InvokeArgument,
04423                 HAS_1_TEMPLATE_PARAMS(int, k),
04424                 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
04425   return internal::CallableHelper<return_type>::Call(
04426       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4);
04427 }
04428 
04429 ACTION_TEMPLATE(InvokeArgument,
04430                 HAS_1_TEMPLATE_PARAMS(int, k),
04431                 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
04432   return internal::CallableHelper<return_type>::Call(
04433       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5);
04434 }
04435 
04436 ACTION_TEMPLATE(InvokeArgument,
04437                 HAS_1_TEMPLATE_PARAMS(int, k),
04438                 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
04439   return internal::CallableHelper<return_type>::Call(
04440       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
04441 }
04442 
04443 ACTION_TEMPLATE(InvokeArgument,
04444                 HAS_1_TEMPLATE_PARAMS(int, k),
04445                 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
04446   return internal::CallableHelper<return_type>::Call(
04447       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
04448 }
04449 
04450 ACTION_TEMPLATE(InvokeArgument,
04451                 HAS_1_TEMPLATE_PARAMS(int, k),
04452                 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
04453   return internal::CallableHelper<return_type>::Call(
04454       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8);
04455 }
04456 
04457 ACTION_TEMPLATE(InvokeArgument,
04458                 HAS_1_TEMPLATE_PARAMS(int, k),
04459                 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
04460   return internal::CallableHelper<return_type>::Call(
04461       ::std::tr1::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
04462 }
04463 
04464 // Various overloads for ReturnNew<T>().
04465 //
04466 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
04467 // instance of type T, constructed on the heap with constructor arguments
04468 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
04469 ACTION_TEMPLATE(ReturnNew,
04470                 HAS_1_TEMPLATE_PARAMS(typename, T),
04471                 AND_0_VALUE_PARAMS()) {
04472   return new T();
04473 }
04474 
04475 ACTION_TEMPLATE(ReturnNew,
04476                 HAS_1_TEMPLATE_PARAMS(typename, T),
04477                 AND_1_VALUE_PARAMS(p0)) {
04478   return new T(p0);
04479 }
04480 
04481 ACTION_TEMPLATE(ReturnNew,
04482                 HAS_1_TEMPLATE_PARAMS(typename, T),
04483                 AND_2_VALUE_PARAMS(p0, p1)) {
04484   return new T(p0, p1);
04485 }
04486 
04487 ACTION_TEMPLATE(ReturnNew,
04488                 HAS_1_TEMPLATE_PARAMS(typename, T),
04489                 AND_3_VALUE_PARAMS(p0, p1, p2)) {
04490   return new T(p0, p1, p2);
04491 }
04492 
04493 ACTION_TEMPLATE(ReturnNew,
04494                 HAS_1_TEMPLATE_PARAMS(typename, T),
04495                 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
04496   return new T(p0, p1, p2, p3);
04497 }
04498 
04499 ACTION_TEMPLATE(ReturnNew,
04500                 HAS_1_TEMPLATE_PARAMS(typename, T),
04501                 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
04502   return new T(p0, p1, p2, p3, p4);
04503 }
04504 
04505 ACTION_TEMPLATE(ReturnNew,
04506                 HAS_1_TEMPLATE_PARAMS(typename, T),
04507                 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
04508   return new T(p0, p1, p2, p3, p4, p5);
04509 }
04510 
04511 ACTION_TEMPLATE(ReturnNew,
04512                 HAS_1_TEMPLATE_PARAMS(typename, T),
04513                 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
04514   return new T(p0, p1, p2, p3, p4, p5, p6);
04515 }
04516 
04517 ACTION_TEMPLATE(ReturnNew,
04518                 HAS_1_TEMPLATE_PARAMS(typename, T),
04519                 AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
04520   return new T(p0, p1, p2, p3, p4, p5, p6, p7);
04521 }
04522 
04523 ACTION_TEMPLATE(ReturnNew,
04524                 HAS_1_TEMPLATE_PARAMS(typename, T),
04525                 AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
04526   return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
04527 }
04528 
04529 ACTION_TEMPLATE(ReturnNew,
04530                 HAS_1_TEMPLATE_PARAMS(typename, T),
04531                 AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
04532   return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
04533 }
04534 
04535 #ifdef _MSC_VER
04536 # pragma warning(pop)
04537 #endif
04538 
04539 }  // namespace testing
04540 
04541 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
04542 // This file was GENERATED by command:
04543 //     pump.py gmock-generated-function-mockers.h.pump
04544 // DO NOT EDIT BY HAND!!!
04545 
04546 // Copyright 2007, Google Inc.
04547 // All rights reserved.
04548 //
04549 // Redistribution and use in source and binary forms, with or without
04550 // modification, are permitted provided that the following conditions are
04551 // met:
04552 //
04553 //     * Redistributions of source code must retain the above copyright
04554 // notice, this list of conditions and the following disclaimer.
04555 //     * Redistributions in binary form must reproduce the above
04556 // copyright notice, this list of conditions and the following disclaimer
04557 // in the documentation and/or other materials provided with the
04558 // distribution.
04559 //     * Neither the name of Google Inc. nor the names of its
04560 // contributors may be used to endorse or promote products derived from
04561 // this software without specific prior written permission.
04562 //
04563 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
04564 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
04565 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
04566 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
04567 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
04568 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
04569 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
04570 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
04571 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
04572 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
04573 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
04574 //
04575 // Author: wan@google.com (Zhanyong Wan)
04576 
04577 // Google Mock - a framework for writing C++ mock classes.
04578 //
04579 // This file implements function mockers of various arities.
04580 
04581 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
04582 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
04583 
04584 // Copyright 2007, Google Inc.
04585 // All rights reserved.
04586 //
04587 // Redistribution and use in source and binary forms, with or without
04588 // modification, are permitted provided that the following conditions are
04589 // met:
04590 //
04591 //     * Redistributions of source code must retain the above copyright
04592 // notice, this list of conditions and the following disclaimer.
04593 //     * Redistributions in binary form must reproduce the above
04594 // copyright notice, this list of conditions and the following disclaimer
04595 // in the documentation and/or other materials provided with the
04596 // distribution.
04597 //     * Neither the name of Google Inc. nor the names of its
04598 // contributors may be used to endorse or promote products derived from
04599 // this software without specific prior written permission.
04600 //
04601 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
04602 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
04603 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
04604 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
04605 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
04606 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
04607 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
04608 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
04609 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
04610 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
04611 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
04612 //
04613 // Author: wan@google.com (Zhanyong Wan)
04614 
04615 // Google Mock - a framework for writing C++ mock classes.
04616 //
04617 // This file implements the ON_CALL() and EXPECT_CALL() macros.
04618 //
04619 // A user can use the ON_CALL() macro to specify the default action of
04620 // a mock method.  The syntax is:
04621 //
04622 //   ON_CALL(mock_object, Method(argument-matchers))
04623 //       .With(multi-argument-matcher)
04624 //       .WillByDefault(action);
04625 //
04626 //  where the .With() clause is optional.
04627 //
04628 // A user can use the EXPECT_CALL() macro to specify an expectation on
04629 // a mock method.  The syntax is:
04630 //
04631 //   EXPECT_CALL(mock_object, Method(argument-matchers))
04632 //       .With(multi-argument-matchers)
04633 //       .Times(cardinality)
04634 //       .InSequence(sequences)
04635 //       .After(expectations)
04636 //       .WillOnce(action)
04637 //       .WillRepeatedly(action)
04638 //       .RetiresOnSaturation();
04639 //
04640 // where all clauses are optional, and .InSequence()/.After()/
04641 // .WillOnce() can appear any number of times.
04642 
04643 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
04644 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
04645 
04646 #include <map>
04647 #include <set>
04648 #include <sstream>
04649 #include <string>
04650 #include <vector>
04651 
04652 #if GTEST_HAS_EXCEPTIONS
04653 # include <stdexcept>  // NOLINT
04654 #endif
04655 
04656 // Copyright 2007, Google Inc.
04657 // All rights reserved.
04658 //
04659 // Redistribution and use in source and binary forms, with or without
04660 // modification, are permitted provided that the following conditions are
04661 // met:
04662 //
04663 //     * Redistributions of source code must retain the above copyright
04664 // notice, this list of conditions and the following disclaimer.
04665 //     * Redistributions in binary form must reproduce the above
04666 // copyright notice, this list of conditions and the following disclaimer
04667 // in the documentation and/or other materials provided with the
04668 // distribution.
04669 //     * Neither the name of Google Inc. nor the names of its
04670 // contributors may be used to endorse or promote products derived from
04671 // this software without specific prior written permission.
04672 //
04673 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
04674 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
04675 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
04676 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
04677 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
04678 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
04679 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
04680 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
04681 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
04682 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
04683 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
04684 //
04685 // Author: wan@google.com (Zhanyong Wan)
04686 
04687 // Google Mock - a framework for writing C++ mock classes.
04688 //
04689 // This file implements some commonly used argument matchers.  More
04690 // matchers can be defined by the user implementing the
04691 // MatcherInterface<T> interface if necessary.
04692 
04693 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
04694 #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
04695 
04696 #include <math.h>
04697 #include <algorithm>
04698 #include <iterator>
04699 #include <limits>
04700 #include <ostream>  // NOLINT
04701 #include <sstream>
04702 #include <string>
04703 #include <utility>
04704 #include <vector>
04705 
04706 
04707 #if GTEST_LANG_CXX11
04708 #include <initializer_list>  // NOLINT -- must be after gtest.h
04709 #endif
04710 
04711 namespace testing {
04712 
04713 // To implement a matcher Foo for type T, define:
04714 //   1. a class FooMatcherImpl that implements the
04715 //      MatcherInterface<T> interface, and
04716 //   2. a factory function that creates a Matcher<T> object from a
04717 //      FooMatcherImpl*.
04718 //
04719 // The two-level delegation design makes it possible to allow a user
04720 // to write "v" instead of "Eq(v)" where a Matcher is expected, which
04721 // is impossible if we pass matchers by pointers.  It also eases
04722 // ownership management as Matcher objects can now be copied like
04723 // plain values.
04724 
04725 // MatchResultListener is an abstract class.  Its << operator can be
04726 // used by a matcher to explain why a value matches or doesn't match.
04727 //
04728 // TODO(wan@google.com): add method
04729 //   bool InterestedInWhy(bool result) const;
04730 // to indicate whether the listener is interested in why the match
04731 // result is 'result'.
04732 class MatchResultListener {
04733  public:
04734   // Creates a listener object with the given underlying ostream.  The
04735   // listener does not own the ostream, and does not dereference it
04736   // in the constructor or destructor.
04737   explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
04738   virtual ~MatchResultListener() = 0;  // Makes this class abstract.
04739 
04740   // Streams x to the underlying ostream; does nothing if the ostream
04741   // is NULL.
04742   template <typename T>
04743   MatchResultListener& operator<<(const T& x) {
04744     if (stream_ != NULL)
04745       *stream_ << x;
04746     return *this;
04747   }
04748 
04749   // Returns the underlying ostream.
04750   ::std::ostream* stream() { return stream_; }
04751 
04752   // Returns true iff the listener is interested in an explanation of
04753   // the match result.  A matcher's MatchAndExplain() method can use
04754   // this information to avoid generating the explanation when no one
04755   // intends to hear it.
04756   bool IsInterested() const { return stream_ != NULL; }
04757 
04758  private:
04759   ::std::ostream* const stream_;
04760 
04761   GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
04762 };
04763 
04764 inline MatchResultListener::~MatchResultListener() {
04765 }
04766 
04767 // An instance of a subclass of this knows how to describe itself as a
04768 // matcher.
04769 class MatcherDescriberInterface {
04770  public:
04771   virtual ~MatcherDescriberInterface() {}
04772 
04773   // Describes this matcher to an ostream.  The function should print
04774   // a verb phrase that describes the property a value matching this
04775   // matcher should have.  The subject of the verb phrase is the value
04776   // being matched.  For example, the DescribeTo() method of the Gt(7)
04777   // matcher prints "is greater than 7".
04778   virtual void DescribeTo(::std::ostream* os) const = 0;
04779 
04780   // Describes the negation of this matcher to an ostream.  For
04781   // example, if the description of this matcher is "is greater than
04782   // 7", the negated description could be "is not greater than 7".
04783   // You are not required to override this when implementing
04784   // MatcherInterface, but it is highly advised so that your matcher
04785   // can produce good error messages.
04786   virtual void DescribeNegationTo(::std::ostream* os) const {
04787     *os << "not (";
04788     DescribeTo(os);
04789     *os << ")";
04790   }
04791 };
04792 
04793 // The implementation of a matcher.
04794 template <typename T>
04795 class MatcherInterface : public MatcherDescriberInterface {
04796  public:
04797   // Returns true iff the matcher matches x; also explains the match
04798   // result to 'listener' if necessary (see the next paragraph), in
04799   // the form of a non-restrictive relative clause ("which ...",
04800   // "whose ...", etc) that describes x.  For example, the
04801   // MatchAndExplain() method of the Pointee(...) matcher should
04802   // generate an explanation like "which points to ...".
04803   //
04804   // Implementations of MatchAndExplain() should add an explanation of
04805   // the match result *if and only if* they can provide additional
04806   // information that's not already present (or not obvious) in the
04807   // print-out of x and the matcher's description.  Whether the match
04808   // succeeds is not a factor in deciding whether an explanation is
04809   // needed, as sometimes the caller needs to print a failure message
04810   // when the match succeeds (e.g. when the matcher is used inside
04811   // Not()).
04812   //
04813   // For example, a "has at least 10 elements" matcher should explain
04814   // what the actual element count is, regardless of the match result,
04815   // as it is useful information to the reader; on the other hand, an
04816   // "is empty" matcher probably only needs to explain what the actual
04817   // size is when the match fails, as it's redundant to say that the
04818   // size is 0 when the value is already known to be empty.
04819   //
04820   // You should override this method when defining a new matcher.
04821   //
04822   // It's the responsibility of the caller (Google Mock) to guarantee
04823   // that 'listener' is not NULL.  This helps to simplify a matcher's
04824   // implementation when it doesn't care about the performance, as it
04825   // can talk to 'listener' without checking its validity first.
04826   // However, in order to implement dummy listeners efficiently,
04827   // listener->stream() may be NULL.
04828   virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
04829 
04830   // Inherits these methods from MatcherDescriberInterface:
04831   //   virtual void DescribeTo(::std::ostream* os) const = 0;
04832   //   virtual void DescribeNegationTo(::std::ostream* os) const;
04833 };
04834 
04835 // A match result listener that stores the explanation in a string.
04836 class StringMatchResultListener : public MatchResultListener {
04837  public:
04838   StringMatchResultListener() : MatchResultListener(&ss_) {}
04839 
04840   // Returns the explanation accumulated so far.
04841   internal::string str() const { return ss_.str(); }
04842 
04843   // Clears the explanation accumulated so far.
04844   void Clear() { ss_.str(""); }
04845 
04846  private:
04847   ::std::stringstream ss_;
04848 
04849   GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
04850 };
04851 
04852 namespace internal {
04853 
04854 // A match result listener that ignores the explanation.
04855 class DummyMatchResultListener : public MatchResultListener {
04856  public:
04857   DummyMatchResultListener() : MatchResultListener(NULL) {}
04858 
04859  private:
04860   GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
04861 };
04862 
04863 // A match result listener that forwards the explanation to a given
04864 // ostream.  The difference between this and MatchResultListener is
04865 // that the former is concrete.
04866 class StreamMatchResultListener : public MatchResultListener {
04867  public:
04868   explicit StreamMatchResultListener(::std::ostream* os)
04869       : MatchResultListener(os) {}
04870 
04871  private:
04872   GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
04873 };
04874 
04875 // An internal class for implementing Matcher<T>, which will derive
04876 // from it.  We put functionalities common to all Matcher<T>
04877 // specializations here to avoid code duplication.
04878 template <typename T>
04879 class MatcherBase {
04880  public:
04881   // Returns true iff the matcher matches x; also explains the match
04882   // result to 'listener'.
04883   bool MatchAndExplain(T x, MatchResultListener* listener) const {
04884     return impl_->MatchAndExplain(x, listener);
04885   }
04886 
04887   // Returns true iff this matcher matches x.
04888   bool Matches(T x) const {
04889     DummyMatchResultListener dummy;
04890     return MatchAndExplain(x, &dummy);
04891   }
04892 
04893   // Describes this matcher to an ostream.
04894   void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
04895 
04896   // Describes the negation of this matcher to an ostream.
04897   void DescribeNegationTo(::std::ostream* os) const {
04898     impl_->DescribeNegationTo(os);
04899   }
04900 
04901   // Explains why x matches, or doesn't match, the matcher.
04902   void ExplainMatchResultTo(T x, ::std::ostream* os) const {
04903     StreamMatchResultListener listener(os);
04904     MatchAndExplain(x, &listener);
04905   }
04906 
04907   // Returns the describer for this matcher object; retains ownership
04908   // of the describer, which is only guaranteed to be alive when
04909   // this matcher object is alive.
04910   const MatcherDescriberInterface* GetDescriber() const {
04911     return impl_.get();
04912   }
04913 
04914  protected:
04915   MatcherBase() {}
04916 
04917   // Constructs a matcher from its implementation.
04918   explicit MatcherBase(const MatcherInterface<T>* impl)
04919       : impl_(impl) {}
04920 
04921   virtual ~MatcherBase() {}
04922 
04923  private:
04924   // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
04925   // interfaces.  The former dynamically allocates a chunk of memory
04926   // to hold the reference count, while the latter tracks all
04927   // references using a circular linked list without allocating
04928   // memory.  It has been observed that linked_ptr performs better in
04929   // typical scenarios.  However, shared_ptr can out-perform
04930   // linked_ptr when there are many more uses of the copy constructor
04931   // than the default constructor.
04932   //
04933   // If performance becomes a problem, we should see if using
04934   // shared_ptr helps.
04935   ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
04936 };
04937 
04938 }  // namespace internal
04939 
04940 // A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
04941 // object that can check whether a value of type T matches.  The
04942 // implementation of Matcher<T> is just a linked_ptr to const
04943 // MatcherInterface<T>, so copying is fairly cheap.  Don't inherit
04944 // from Matcher!
04945 template <typename T>
04946 class Matcher : public internal::MatcherBase<T> {
04947  public:
04948   // Constructs a null matcher.  Needed for storing Matcher objects in STL
04949   // containers.  A default-constructed matcher is not yet initialized.  You
04950   // cannot use it until a valid value has been assigned to it.
04951   Matcher() {}
04952 
04953   // Constructs a matcher from its implementation.
04954   explicit Matcher(const MatcherInterface<T>* impl)
04955       : internal::MatcherBase<T>(impl) {}
04956 
04957   // Implicit constructor here allows people to write
04958   // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
04959   Matcher(T value);  // NOLINT
04960 };
04961 
04962 // The following two specializations allow the user to write str
04963 // instead of Eq(str) and "foo" instead of Eq("foo") when a string
04964 // matcher is expected.
04965 template <>
04966 class GTEST_API_ Matcher<const internal::string&>
04967     : public internal::MatcherBase<const internal::string&> {
04968  public:
04969   Matcher() {}
04970 
04971   explicit Matcher(const MatcherInterface<const internal::string&>* impl)
04972       : internal::MatcherBase<const internal::string&>(impl) {}
04973 
04974   // Allows the user to write str instead of Eq(str) sometimes, where
04975   // str is a string object.
04976   Matcher(const internal::string& s);  // NOLINT
04977 
04978   // Allows the user to write "foo" instead of Eq("foo") sometimes.
04979   Matcher(const char* s);  // NOLINT
04980 };
04981 
04982 template <>
04983 class GTEST_API_ Matcher<internal::string>
04984     : public internal::MatcherBase<internal::string> {
04985  public:
04986   Matcher() {}
04987 
04988   explicit Matcher(const MatcherInterface<internal::string>* impl)
04989       : internal::MatcherBase<internal::string>(impl) {}
04990 
04991   // Allows the user to write str instead of Eq(str) sometimes, where
04992   // str is a string object.
04993   Matcher(const internal::string& s);  // NOLINT
04994 
04995   // Allows the user to write "foo" instead of Eq("foo") sometimes.
04996   Matcher(const char* s);  // NOLINT
04997 };
04998 
04999 #if GTEST_HAS_STRING_PIECE_
05000 // The following two specializations allow the user to write str
05001 // instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
05002 // matcher is expected.
05003 template <>
05004 class GTEST_API_ Matcher<const StringPiece&>
05005     : public internal::MatcherBase<const StringPiece&> {
05006  public:
05007   Matcher() {}
05008 
05009   explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
05010       : internal::MatcherBase<const StringPiece&>(impl) {}
05011 
05012   // Allows the user to write str instead of Eq(str) sometimes, where
05013   // str is a string object.
05014   Matcher(const internal::string& s);  // NOLINT
05015 
05016   // Allows the user to write "foo" instead of Eq("foo") sometimes.
05017   Matcher(const char* s);  // NOLINT
05018 
05019   // Allows the user to pass StringPieces directly.
05020   Matcher(StringPiece s);  // NOLINT
05021 };
05022 
05023 template <>
05024 class GTEST_API_ Matcher<StringPiece>
05025     : public internal::MatcherBase<StringPiece> {
05026  public:
05027   Matcher() {}
05028 
05029   explicit Matcher(const MatcherInterface<StringPiece>* impl)
05030       : internal::MatcherBase<StringPiece>(impl) {}
05031 
05032   // Allows the user to write str instead of Eq(str) sometimes, where
05033   // str is a string object.
05034   Matcher(const internal::string& s);  // NOLINT
05035 
05036   // Allows the user to write "foo" instead of Eq("foo") sometimes.
05037   Matcher(const char* s);  // NOLINT
05038 
05039   // Allows the user to pass StringPieces directly.
05040   Matcher(StringPiece s);  // NOLINT
05041 };
05042 #endif  // GTEST_HAS_STRING_PIECE_
05043 
05044 // The PolymorphicMatcher class template makes it easy to implement a
05045 // polymorphic matcher (i.e. a matcher that can match values of more
05046 // than one type, e.g. Eq(n) and NotNull()).
05047 //
05048 // To define a polymorphic matcher, a user should provide an Impl
05049 // class that has a DescribeTo() method and a DescribeNegationTo()
05050 // method, and define a member function (or member function template)
05051 //
05052 //   bool MatchAndExplain(const Value& value,
05053 //                        MatchResultListener* listener) const;
05054 //
05055 // See the definition of NotNull() for a complete example.
05056 template <class Impl>
05057 class PolymorphicMatcher {
05058  public:
05059   explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
05060 
05061   // Returns a mutable reference to the underlying matcher
05062   // implementation object.
05063   Impl& mutable_impl() { return impl_; }
05064 
05065   // Returns an immutable reference to the underlying matcher
05066   // implementation object.
05067   const Impl& impl() const { return impl_; }
05068 
05069   template <typename T>
05070   operator Matcher<T>() const {
05071     return Matcher<T>(new MonomorphicImpl<T>(impl_));
05072   }
05073 
05074  private:
05075   template <typename T>
05076   class MonomorphicImpl : public MatcherInterface<T> {
05077    public:
05078     explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
05079 
05080     virtual void DescribeTo(::std::ostream* os) const {
05081       impl_.DescribeTo(os);
05082     }
05083 
05084     virtual void DescribeNegationTo(::std::ostream* os) const {
05085       impl_.DescribeNegationTo(os);
05086     }
05087 
05088     virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
05089       return impl_.MatchAndExplain(x, listener);
05090     }
05091 
05092    private:
05093     const Impl impl_;
05094 
05095     GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
05096   };
05097 
05098   Impl impl_;
05099 
05100   GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
05101 };
05102 
05103 // Creates a matcher from its implementation.  This is easier to use
05104 // than the Matcher<T> constructor as it doesn't require you to
05105 // explicitly write the template argument, e.g.
05106 //
05107 //   MakeMatcher(foo);
05108 // vs
05109 //   Matcher<const string&>(foo);
05110 template <typename T>
05111 inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
05112   return Matcher<T>(impl);
05113 }
05114 
05115 // Creates a polymorphic matcher from its implementation.  This is
05116 // easier to use than the PolymorphicMatcher<Impl> constructor as it
05117 // doesn't require you to explicitly write the template argument, e.g.
05118 //
05119 //   MakePolymorphicMatcher(foo);
05120 // vs
05121 //   PolymorphicMatcher<TypeOfFoo>(foo);
05122 template <class Impl>
05123 inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
05124   return PolymorphicMatcher<Impl>(impl);
05125 }
05126 
05127 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
05128 // and MUST NOT BE USED IN USER CODE!!!
05129 namespace internal {
05130 
05131 // The MatcherCastImpl class template is a helper for implementing
05132 // MatcherCast().  We need this helper in order to partially
05133 // specialize the implementation of MatcherCast() (C++ allows
05134 // class/struct templates to be partially specialized, but not
05135 // function templates.).
05136 
05137 // This general version is used when MatcherCast()'s argument is a
05138 // polymorphic matcher (i.e. something that can be converted to a
05139 // Matcher but is not one yet; for example, Eq(value)) or a value (for
05140 // example, "hello").
05141 template <typename T, typename M>
05142 class MatcherCastImpl {
05143  public:
05144   static Matcher<T> Cast(M polymorphic_matcher_or_value) {
05145     // M can be a polymorhic matcher, in which case we want to use
05146     // its conversion operator to create Matcher<T>.  Or it can be a value
05147     // that should be passed to the Matcher<T>'s constructor.
05148     //
05149     // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
05150     // polymorphic matcher because it'll be ambiguous if T has an implicit
05151     // constructor from M (this usually happens when T has an implicit
05152     // constructor from any type).
05153     //
05154     // It won't work to unconditionally implict_cast
05155     // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
05156     // a user-defined conversion from M to T if one exists (assuming M is
05157     // a value).
05158     return CastImpl(
05159         polymorphic_matcher_or_value,
05160         BooleanConstant<
05161             internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
05162   }
05163 
05164  private:
05165   static Matcher<T> CastImpl(M value, BooleanConstant<false>) {
05166     // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
05167     // matcher.  It must be a value then.  Use direct initialization to create
05168     // a matcher.
05169     return Matcher<T>(ImplicitCast_<T>(value));
05170   }
05171 
05172   static Matcher<T> CastImpl(M polymorphic_matcher_or_value,
05173                              BooleanConstant<true>) {
05174     // M is implicitly convertible to Matcher<T>, which means that either
05175     // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
05176     // from M.  In both cases using the implicit conversion will produce a
05177     // matcher.
05178     //
05179     // Even if T has an implicit constructor from M, it won't be called because
05180     // creating Matcher<T> would require a chain of two user-defined conversions
05181     // (first to create T from M and then to create Matcher<T> from T).
05182     return polymorphic_matcher_or_value;
05183   }
05184 };
05185 
05186 // This more specialized version is used when MatcherCast()'s argument
05187 // is already a Matcher.  This only compiles when type T can be
05188 // statically converted to type U.
05189 template <typename T, typename U>
05190 class MatcherCastImpl<T, Matcher<U> > {
05191  public:
05192   static Matcher<T> Cast(const Matcher<U>& source_matcher) {
05193     return Matcher<T>(new Impl(source_matcher));
05194   }
05195 
05196  private:
05197   class Impl : public MatcherInterface<T> {
05198    public:
05199     explicit Impl(const Matcher<U>& source_matcher)
05200         : source_matcher_(source_matcher) {}
05201 
05202     // We delegate the matching logic to the source matcher.
05203     virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
05204       return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
05205     }
05206 
05207     virtual void DescribeTo(::std::ostream* os) const {
05208       source_matcher_.DescribeTo(os);
05209     }
05210 
05211     virtual void DescribeNegationTo(::std::ostream* os) const {
05212       source_matcher_.DescribeNegationTo(os);
05213     }
05214 
05215    private:
05216     const Matcher<U> source_matcher_;
05217 
05218     GTEST_DISALLOW_ASSIGN_(Impl);
05219   };
05220 };
05221 
05222 // This even more specialized version is used for efficiently casting
05223 // a matcher to its own type.
05224 template <typename T>
05225 class MatcherCastImpl<T, Matcher<T> > {
05226  public:
05227   static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
05228 };
05229 
05230 }  // namespace internal
05231 
05232 // In order to be safe and clear, casting between different matcher
05233 // types is done explicitly via MatcherCast<T>(m), which takes a
05234 // matcher m and returns a Matcher<T>.  It compiles only when T can be
05235 // statically converted to the argument type of m.
05236 template <typename T, typename M>
05237 inline Matcher<T> MatcherCast(M matcher) {
05238   return internal::MatcherCastImpl<T, M>::Cast(matcher);
05239 }
05240 
05241 // Implements SafeMatcherCast().
05242 //
05243 // We use an intermediate class to do the actual safe casting as Nokia's
05244 // Symbian compiler cannot decide between
05245 // template <T, M> ... (M) and
05246 // template <T, U> ... (const Matcher<U>&)
05247 // for function templates but can for member function templates.
05248 template <typename T>
05249 class SafeMatcherCastImpl {
05250  public:
05251   // This overload handles polymorphic matchers and values only since
05252   // monomorphic matchers are handled by the next one.
05253   template <typename M>
05254   static inline Matcher<T> Cast(M polymorphic_matcher_or_value) {
05255     return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
05256   }
05257 
05258   // This overload handles monomorphic matchers.
05259   //
05260   // In general, if type T can be implicitly converted to type U, we can
05261   // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
05262   // contravariant): just keep a copy of the original Matcher<U>, convert the
05263   // argument from type T to U, and then pass it to the underlying Matcher<U>.
05264   // The only exception is when U is a reference and T is not, as the
05265   // underlying Matcher<U> may be interested in the argument's address, which
05266   // is not preserved in the conversion from T to U.
05267   template <typename U>
05268   static inline Matcher<T> Cast(const Matcher<U>& matcher) {
05269     // Enforce that T can be implicitly converted to U.
05270     GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
05271                           T_must_be_implicitly_convertible_to_U);
05272     // Enforce that we are not converting a non-reference type T to a reference
05273     // type U.
05274     GTEST_COMPILE_ASSERT_(
05275         internal::is_reference<T>::value || !internal::is_reference<U>::value,
05276         cannot_convert_non_referentce_arg_to_reference);
05277     // In case both T and U are arithmetic types, enforce that the
05278     // conversion is not lossy.
05279     typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
05280     typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
05281     const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
05282     const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
05283     GTEST_COMPILE_ASSERT_(
05284         kTIsOther || kUIsOther ||
05285         (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
05286         conversion_of_arithmetic_types_must_be_lossless);
05287     return MatcherCast<T>(matcher);
05288   }
05289 };
05290 
05291 template <typename T, typename M>
05292 inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
05293   return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
05294 }
05295 
05296 // A<T>() returns a matcher that matches any value of type T.
05297 template <typename T>
05298 Matcher<T> A();
05299 
05300 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
05301 // and MUST NOT BE USED IN USER CODE!!!
05302 namespace internal {
05303 
05304 // If the explanation is not empty, prints it to the ostream.
05305 inline void PrintIfNotEmpty(const internal::string& explanation,
05306                             ::std::ostream* os) {
05307   if (explanation != "" && os != NULL) {
05308     *os << ", " << explanation;
05309   }
05310 }
05311 
05312 // Returns true if the given type name is easy to read by a human.
05313 // This is used to decide whether printing the type of a value might
05314 // be helpful.
05315 inline bool IsReadableTypeName(const string& type_name) {
05316   // We consider a type name readable if it's short or doesn't contain
05317   // a template or function type.
05318   return (type_name.length() <= 20 ||
05319           type_name.find_first_of("<(") == string::npos);
05320 }
05321 
05322 // Matches the value against the given matcher, prints the value and explains
05323 // the match result to the listener. Returns the match result.
05324 // 'listener' must not be NULL.
05325 // Value cannot be passed by const reference, because some matchers take a
05326 // non-const argument.
05327 template <typename Value, typename T>
05328 bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
05329                           MatchResultListener* listener) {
05330   if (!listener->IsInterested()) {
05331     // If the listener is not interested, we do not need to construct the
05332     // inner explanation.
05333     return matcher.Matches(value);
05334   }
05335 
05336   StringMatchResultListener inner_listener;
05337   const bool match = matcher.MatchAndExplain(value, &inner_listener);
05338 
05339   UniversalPrint(value, listener->stream());
05340 #if GTEST_HAS_RTTI
05341   const string& type_name = GetTypeName<Value>();
05342   if (IsReadableTypeName(type_name))
05343     *listener->stream() << " (of type " << type_name << ")";
05344 #endif
05345   PrintIfNotEmpty(inner_listener.str(), listener->stream());
05346 
05347   return match;
05348 }
05349 
05350 // An internal helper class for doing compile-time loop on a tuple's
05351 // fields.
05352 template <size_t N>
05353 class TuplePrefix {
05354  public:
05355   // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
05356   // iff the first N fields of matcher_tuple matches the first N
05357   // fields of value_tuple, respectively.
05358   template <typename MatcherTuple, typename ValueTuple>
05359   static bool Matches(const MatcherTuple& matcher_tuple,
05360                       const ValueTuple& value_tuple) {
05361     using ::std::tr1::get;
05362     return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
05363         && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
05364   }
05365 
05366   // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
05367   // describes failures in matching the first N fields of matchers
05368   // against the first N fields of values.  If there is no failure,
05369   // nothing will be streamed to os.
05370   template <typename MatcherTuple, typename ValueTuple>
05371   static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
05372                                      const ValueTuple& values,
05373                                      ::std::ostream* os) {
05374     using ::std::tr1::tuple_element;
05375     using ::std::tr1::get;
05376 
05377     // First, describes failures in the first N - 1 fields.
05378     TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
05379 
05380     // Then describes the failure (if any) in the (N - 1)-th (0-based)
05381     // field.
05382     typename tuple_element<N - 1, MatcherTuple>::type matcher =
05383         get<N - 1>(matchers);
05384     typedef typename tuple_element<N - 1, ValueTuple>::type Value;
05385     Value value = get<N - 1>(values);
05386     StringMatchResultListener listener;
05387     if (!matcher.MatchAndExplain(value, &listener)) {
05388       // TODO(wan): include in the message the name of the parameter
05389       // as used in MOCK_METHOD*() when possible.
05390       *os << "  Expected arg #" << N - 1 << ": ";
05391       get<N - 1>(matchers).DescribeTo(os);
05392       *os << "\n           Actual: ";
05393       // We remove the reference in type Value to prevent the
05394       // universal printer from printing the address of value, which
05395       // isn't interesting to the user most of the time.  The
05396       // matcher's MatchAndExplain() method handles the case when
05397       // the address is interesting.
05398       internal::UniversalPrint(value, os);
05399       PrintIfNotEmpty(listener.str(), os);
05400       *os << "\n";
05401     }
05402   }
05403 };
05404 
05405 // The base case.
05406 template <>
05407 class TuplePrefix<0> {
05408  public:
05409   template <typename MatcherTuple, typename ValueTuple>
05410   static bool Matches(const MatcherTuple& /* matcher_tuple */,
05411                       const ValueTuple& /* value_tuple */) {
05412     return true;
05413   }
05414 
05415   template <typename MatcherTuple, typename ValueTuple>
05416   static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
05417                                      const ValueTuple& /* values */,
05418                                      ::std::ostream* /* os */) {}
05419 };
05420 
05421 // TupleMatches(matcher_tuple, value_tuple) returns true iff all
05422 // matchers in matcher_tuple match the corresponding fields in
05423 // value_tuple.  It is a compiler error if matcher_tuple and
05424 // value_tuple have different number of fields or incompatible field
05425 // types.
05426 template <typename MatcherTuple, typename ValueTuple>
05427 bool TupleMatches(const MatcherTuple& matcher_tuple,
05428                   const ValueTuple& value_tuple) {
05429   using ::std::tr1::tuple_size;
05430   // Makes sure that matcher_tuple and value_tuple have the same
05431   // number of fields.
05432   GTEST_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
05433                         tuple_size<ValueTuple>::value,
05434                         matcher_and_value_have_different_numbers_of_fields);
05435   return TuplePrefix<tuple_size<ValueTuple>::value>::
05436       Matches(matcher_tuple, value_tuple);
05437 }
05438 
05439 // Describes failures in matching matchers against values.  If there
05440 // is no failure, nothing will be streamed to os.
05441 template <typename MatcherTuple, typename ValueTuple>
05442 void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
05443                                 const ValueTuple& values,
05444                                 ::std::ostream* os) {
05445   using ::std::tr1::tuple_size;
05446   TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
05447       matchers, values, os);
05448 }
05449 
05450 // TransformTupleValues and its helper.
05451 //
05452 // TransformTupleValuesHelper hides the internal machinery that
05453 // TransformTupleValues uses to implement a tuple traversal.
05454 template <typename Tuple, typename Func, typename OutIter>
05455 class TransformTupleValuesHelper {
05456  private:
05457   typedef typename ::std::tr1::tuple_size<Tuple> TupleSize;
05458 
05459  public:
05460   // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
05461   // Returns the final value of 'out' in case the caller needs it.
05462   static OutIter Run(Func f, const Tuple& t, OutIter out) {
05463     return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
05464   }
05465 
05466  private:
05467   template <typename Tup, size_t kRemainingSize>
05468   struct IterateOverTuple {
05469     OutIter operator() (Func f, const Tup& t, OutIter out) const {
05470       *out++ = f(::std::tr1::get<TupleSize::value - kRemainingSize>(t));
05471       return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
05472     }
05473   };
05474   template <typename Tup>
05475   struct IterateOverTuple<Tup, 0> {
05476     OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
05477       return out;
05478     }
05479   };
05480 };
05481 
05482 // Successively invokes 'f(element)' on each element of the tuple 't',
05483 // appending each result to the 'out' iterator. Returns the final value
05484 // of 'out'.
05485 template <typename Tuple, typename Func, typename OutIter>
05486 OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
05487   return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
05488 }
05489 
05490 // Implements A<T>().
05491 template <typename T>
05492 class AnyMatcherImpl : public MatcherInterface<T> {
05493  public:
05494   virtual bool MatchAndExplain(
05495       T /* x */, MatchResultListener* /* listener */) const { return true; }
05496   virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
05497   virtual void DescribeNegationTo(::std::ostream* os) const {
05498     // This is mostly for completeness' safe, as it's not very useful
05499     // to write Not(A<bool>()).  However we cannot completely rule out
05500     // such a possibility, and it doesn't hurt to be prepared.
05501     *os << "never matches";
05502   }
05503 };
05504 
05505 // Implements _, a matcher that matches any value of any
05506 // type.  This is a polymorphic matcher, so we need a template type
05507 // conversion operator to make it appearing as a Matcher<T> for any
05508 // type T.
05509 class AnythingMatcher {
05510  public:
05511   template <typename T>
05512   operator Matcher<T>() const { return A<T>(); }
05513 };
05514 
05515 // Implements a matcher that compares a given value with a
05516 // pre-supplied value using one of the ==, <=, <, etc, operators.  The
05517 // two values being compared don't have to have the same type.
05518 //
05519 // The matcher defined here is polymorphic (for example, Eq(5) can be
05520 // used to match an int, a short, a double, etc).  Therefore we use
05521 // a template type conversion operator in the implementation.
05522 //
05523 // We define this as a macro in order to eliminate duplicated source
05524 // code.
05525 //
05526 // The following template definition assumes that the Rhs parameter is
05527 // a "bare" type (i.e. neither 'const T' nor 'T&').
05528 #define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \
05529     name, op, relation, negated_relation) \
05530   template <typename Rhs> class name##Matcher { \
05531    public: \
05532     explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
05533     template <typename Lhs> \
05534     operator Matcher<Lhs>() const { \
05535       return MakeMatcher(new Impl<Lhs>(rhs_)); \
05536     } \
05537    private: \
05538     template <typename Lhs> \
05539     class Impl : public MatcherInterface<Lhs> { \
05540      public: \
05541       explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \
05542       virtual bool MatchAndExplain(\
05543           Lhs lhs, MatchResultListener* /* listener */) const { \
05544         return lhs op rhs_; \
05545       } \
05546       virtual void DescribeTo(::std::ostream* os) const { \
05547         *os << relation  " "; \
05548         UniversalPrint(rhs_, os); \
05549       } \
05550       virtual void DescribeNegationTo(::std::ostream* os) const { \
05551         *os << negated_relation  " "; \
05552         UniversalPrint(rhs_, os); \
05553       } \
05554      private: \
05555       Rhs rhs_; \
05556       GTEST_DISALLOW_ASSIGN_(Impl); \
05557     }; \
05558     Rhs rhs_; \
05559     GTEST_DISALLOW_ASSIGN_(name##Matcher); \
05560   }
05561 
05562 // Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
05563 // respectively.
05564 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");
05565 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >=");
05566 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >");
05567 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <=");
05568 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <");
05569 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to");
05570 
05571 #undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
05572 
05573 // Implements the polymorphic IsNull() matcher, which matches any raw or smart
05574 // pointer that is NULL.
05575 class IsNullMatcher {
05576  public:
05577   template <typename Pointer>
05578   bool MatchAndExplain(const Pointer& p,
05579                        MatchResultListener* /* listener */) const {
05580     return GetRawPointer(p) == NULL;
05581   }
05582 
05583   void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
05584   void DescribeNegationTo(::std::ostream* os) const {
05585     *os << "isn't NULL";
05586   }
05587 };
05588 
05589 // Implements the polymorphic NotNull() matcher, which matches any raw or smart
05590 // pointer that is not NULL.
05591 class NotNullMatcher {
05592  public:
05593   template <typename Pointer>
05594   bool MatchAndExplain(const Pointer& p,
05595                        MatchResultListener* /* listener */) const {
05596     return GetRawPointer(p) != NULL;
05597   }
05598 
05599   void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
05600   void DescribeNegationTo(::std::ostream* os) const {
05601     *os << "is NULL";
05602   }
05603 };
05604 
05605 // Ref(variable) matches any argument that is a reference to
05606 // 'variable'.  This matcher is polymorphic as it can match any
05607 // super type of the type of 'variable'.
05608 //
05609 // The RefMatcher template class implements Ref(variable).  It can
05610 // only be instantiated with a reference type.  This prevents a user
05611 // from mistakenly using Ref(x) to match a non-reference function
05612 // argument.  For example, the following will righteously cause a
05613 // compiler error:
05614 //
05615 //   int n;
05616 //   Matcher<int> m1 = Ref(n);   // This won't compile.
05617 //   Matcher<int&> m2 = Ref(n);  // This will compile.
05618 template <typename T>
05619 class RefMatcher;
05620 
05621 template <typename T>
05622 class RefMatcher<T&> {
05623   // Google Mock is a generic framework and thus needs to support
05624   // mocking any function types, including those that take non-const
05625   // reference arguments.  Therefore the template parameter T (and
05626   // Super below) can be instantiated to either a const type or a
05627   // non-const type.
05628  public:
05629   // RefMatcher() takes a T& instead of const T&, as we want the
05630   // compiler to catch using Ref(const_value) as a matcher for a
05631   // non-const reference.
05632   explicit RefMatcher(T& x) : object_(x) {}  // NOLINT
05633 
05634   template <typename Super>
05635   operator Matcher<Super&>() const {
05636     // By passing object_ (type T&) to Impl(), which expects a Super&,
05637     // we make sure that Super is a super type of T.  In particular,
05638     // this catches using Ref(const_value) as a matcher for a
05639     // non-const reference, as you cannot implicitly convert a const
05640     // reference to a non-const reference.
05641     return MakeMatcher(new Impl<Super>(object_));
05642   }
05643 
05644  private:
05645   template <typename Super>
05646   class Impl : public MatcherInterface<Super&> {
05647    public:
05648     explicit Impl(Super& x) : object_(x) {}  // NOLINT
05649 
05650     // MatchAndExplain() takes a Super& (as opposed to const Super&)
05651     // in order to match the interface MatcherInterface<Super&>.
05652     virtual bool MatchAndExplain(
05653         Super& x, MatchResultListener* listener) const {
05654       *listener << "which is located @" << static_cast<const void*>(&x);
05655       return &x == &object_;
05656     }
05657 
05658     virtual void DescribeTo(::std::ostream* os) const {
05659       *os << "references the variable ";
05660       UniversalPrinter<Super&>::Print(object_, os);
05661     }
05662 
05663     virtual void DescribeNegationTo(::std::ostream* os) const {
05664       *os << "does not reference the variable ";
05665       UniversalPrinter<Super&>::Print(object_, os);
05666     }
05667 
05668    private:
05669     const Super& object_;
05670 
05671     GTEST_DISALLOW_ASSIGN_(Impl);
05672   };
05673 
05674   T& object_;
05675 
05676   GTEST_DISALLOW_ASSIGN_(RefMatcher);
05677 };
05678 
05679 // Polymorphic helper functions for narrow and wide string matchers.
05680 inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
05681   return String::CaseInsensitiveCStringEquals(lhs, rhs);
05682 }
05683 
05684 inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
05685                                          const wchar_t* rhs) {
05686   return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
05687 }
05688 
05689 // String comparison for narrow or wide strings that can have embedded NUL
05690 // characters.
05691 template <typename StringType>
05692 bool CaseInsensitiveStringEquals(const StringType& s1,
05693                                  const StringType& s2) {
05694   // Are the heads equal?
05695   if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
05696     return false;
05697   }
05698 
05699   // Skip the equal heads.
05700   const typename StringType::value_type nul = 0;
05701   const size_t i1 = s1.find(nul), i2 = s2.find(nul);
05702 
05703   // Are we at the end of either s1 or s2?
05704   if (i1 == StringType::npos || i2 == StringType::npos) {
05705     return i1 == i2;
05706   }
05707 
05708   // Are the tails equal?
05709   return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
05710 }
05711 
05712 // String matchers.
05713 
05714 // Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
05715 template <typename StringType>
05716 class StrEqualityMatcher {
05717  public:
05718   StrEqualityMatcher(const StringType& str, bool expect_eq,
05719                      bool case_sensitive)
05720       : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
05721 
05722   // Accepts pointer types, particularly:
05723   //   const char*
05724   //   char*
05725   //   const wchar_t*
05726   //   wchar_t*
05727   template <typename CharType>
05728   bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
05729     if (s == NULL) {
05730       return !expect_eq_;
05731     }
05732     return MatchAndExplain(StringType(s), listener);
05733   }
05734 
05735   // Matches anything that can convert to StringType.
05736   //
05737   // This is a template, not just a plain function with const StringType&,
05738   // because StringPiece has some interfering non-explicit constructors.
05739   template <typename MatcheeStringType>
05740   bool MatchAndExplain(const MatcheeStringType& s,
05741                        MatchResultListener* /* listener */) const {
05742     const StringType& s2(s);
05743     const bool eq = case_sensitive_ ? s2 == string_ :
05744         CaseInsensitiveStringEquals(s2, string_);
05745     return expect_eq_ == eq;
05746   }
05747 
05748   void DescribeTo(::std::ostream* os) const {
05749     DescribeToHelper(expect_eq_, os);
05750   }
05751 
05752   void DescribeNegationTo(::std::ostream* os) const {
05753     DescribeToHelper(!expect_eq_, os);
05754   }
05755 
05756  private:
05757   void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
05758     *os << (expect_eq ? "is " : "isn't ");
05759     *os << "equal to ";
05760     if (!case_sensitive_) {
05761       *os << "(ignoring case) ";
05762     }
05763     UniversalPrint(string_, os);
05764   }
05765 
05766   const StringType string_;
05767   const bool expect_eq_;
05768   const bool case_sensitive_;
05769 
05770   GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
05771 };
05772 
05773 // Implements the polymorphic HasSubstr(substring) matcher, which
05774 // can be used as a Matcher<T> as long as T can be converted to a
05775 // string.
05776 template <typename StringType>
05777 class HasSubstrMatcher {
05778  public:
05779   explicit HasSubstrMatcher(const StringType& substring)
05780       : substring_(substring) {}
05781 
05782   // Accepts pointer types, particularly:
05783   //   const char*
05784   //   char*
05785   //   const wchar_t*
05786   //   wchar_t*
05787   template <typename CharType>
05788   bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
05789     return s != NULL && MatchAndExplain(StringType(s), listener);
05790   }
05791 
05792   // Matches anything that can convert to StringType.
05793   //
05794   // This is a template, not just a plain function with const StringType&,
05795   // because StringPiece has some interfering non-explicit constructors.
05796   template <typename MatcheeStringType>
05797   bool MatchAndExplain(const MatcheeStringType& s,
05798                        MatchResultListener* /* listener */) const {
05799     const StringType& s2(s);
05800     return s2.find(substring_) != StringType::npos;
05801   }
05802 
05803   // Describes what this matcher matches.
05804   void DescribeTo(::std::ostream* os) const {
05805     *os << "has substring ";
05806     UniversalPrint(substring_, os);
05807   }
05808 
05809   void DescribeNegationTo(::std::ostream* os) const {
05810     *os << "has no substring ";
05811     UniversalPrint(substring_, os);
05812   }
05813 
05814  private:
05815   const StringType substring_;
05816 
05817   GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
05818 };
05819 
05820 // Implements the polymorphic StartsWith(substring) matcher, which
05821 // can be used as a Matcher<T> as long as T can be converted to a
05822 // string.
05823 template <typename StringType>
05824 class StartsWithMatcher {
05825  public:
05826   explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
05827   }
05828 
05829   // Accepts pointer types, particularly:
05830   //   const char*
05831   //   char*
05832   //   const wchar_t*
05833   //   wchar_t*
05834   template <typename CharType>
05835   bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
05836     return s != NULL && MatchAndExplain(StringType(s), listener);
05837   }
05838 
05839   // Matches anything that can convert to StringType.
05840   //
05841   // This is a template, not just a plain function with const StringType&,
05842   // because StringPiece has some interfering non-explicit constructors.
05843   template <typename MatcheeStringType>
05844   bool MatchAndExplain(const MatcheeStringType& s,
05845                        MatchResultListener* /* listener */) const {
05846     const StringType& s2(s);
05847     return s2.length() >= prefix_.length() &&
05848         s2.substr(0, prefix_.length()) == prefix_;
05849   }
05850 
05851   void DescribeTo(::std::ostream* os) const {
05852     *os << "starts with ";
05853     UniversalPrint(prefix_, os);
05854   }
05855 
05856   void DescribeNegationTo(::std::ostream* os) const {
05857     *os << "doesn't start with ";
05858     UniversalPrint(prefix_, os);
05859   }
05860 
05861  private:
05862   const StringType prefix_;
05863 
05864   GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
05865 };
05866 
05867 // Implements the polymorphic EndsWith(substring) matcher, which
05868 // can be used as a Matcher<T> as long as T can be converted to a
05869 // string.
05870 template <typename StringType>
05871 class EndsWithMatcher {
05872  public:
05873   explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
05874 
05875   // Accepts pointer types, particularly:
05876   //   const char*
05877   //   char*
05878   //   const wchar_t*
05879   //   wchar_t*
05880   template <typename CharType>
05881   bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
05882     return s != NULL && MatchAndExplain(StringType(s), listener);
05883   }
05884 
05885   // Matches anything that can convert to StringType.
05886   //
05887   // This is a template, not just a plain function with const StringType&,
05888   // because StringPiece has some interfering non-explicit constructors.
05889   template <typename MatcheeStringType>
05890   bool MatchAndExplain(const MatcheeStringType& s,
05891                        MatchResultListener* /* listener */) const {
05892     const StringType& s2(s);
05893     return s2.length() >= suffix_.length() &&
05894         s2.substr(s2.length() - suffix_.length()) == suffix_;
05895   }
05896 
05897   void DescribeTo(::std::ostream* os) const {
05898     *os << "ends with ";
05899     UniversalPrint(suffix_, os);
05900   }
05901 
05902   void DescribeNegationTo(::std::ostream* os) const {
05903     *os << "doesn't end with ";
05904     UniversalPrint(suffix_, os);
05905   }
05906 
05907  private:
05908   const StringType suffix_;
05909 
05910   GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
05911 };
05912 
05913 // Implements polymorphic matchers MatchesRegex(regex) and
05914 // ContainsRegex(regex), which can be used as a Matcher<T> as long as
05915 // T can be converted to a string.
05916 class MatchesRegexMatcher {
05917  public:
05918   MatchesRegexMatcher(const RE* regex, bool full_match)
05919       : regex_(regex), full_match_(full_match) {}
05920 
05921   // Accepts pointer types, particularly:
05922   //   const char*
05923   //   char*
05924   //   const wchar_t*
05925   //   wchar_t*
05926   template <typename CharType>
05927   bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
05928     return s != NULL && MatchAndExplain(internal::string(s), listener);
05929   }
05930 
05931   // Matches anything that can convert to internal::string.
05932   //
05933   // This is a template, not just a plain function with const internal::string&,
05934   // because StringPiece has some interfering non-explicit constructors.
05935   template <class MatcheeStringType>
05936   bool MatchAndExplain(const MatcheeStringType& s,
05937                        MatchResultListener* /* listener */) const {
05938     const internal::string& s2(s);
05939     return full_match_ ? RE::FullMatch(s2, *regex_) :
05940         RE::PartialMatch(s2, *regex_);
05941   }
05942 
05943   void DescribeTo(::std::ostream* os) const {
05944     *os << (full_match_ ? "matches" : "contains")
05945         << " regular expression ";
05946     UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
05947   }
05948 
05949   void DescribeNegationTo(::std::ostream* os) const {
05950     *os << "doesn't " << (full_match_ ? "match" : "contain")
05951         << " regular expression ";
05952     UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
05953   }
05954 
05955  private:
05956   const internal::linked_ptr<const RE> regex_;
05957   const bool full_match_;
05958 
05959   GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
05960 };
05961 
05962 // Implements a matcher that compares the two fields of a 2-tuple
05963 // using one of the ==, <=, <, etc, operators.  The two fields being
05964 // compared don't have to have the same type.
05965 //
05966 // The matcher defined here is polymorphic (for example, Eq() can be
05967 // used to match a tuple<int, short>, a tuple<const long&, double>,
05968 // etc).  Therefore we use a template type conversion operator in the
05969 // implementation.
05970 //
05971 // We define this as a macro in order to eliminate duplicated source
05972 // code.
05973 #define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \
05974   class name##2Matcher { \
05975    public: \
05976     template <typename T1, typename T2> \
05977     operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \
05978       return MakeMatcher(new Impl< ::std::tr1::tuple<T1, T2> >); \
05979     } \
05980     template <typename T1, typename T2> \
05981     operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \
05982       return MakeMatcher(new Impl<const ::std::tr1::tuple<T1, T2>&>); \
05983     } \
05984    private: \
05985     template <typename Tuple> \
05986     class Impl : public MatcherInterface<Tuple> { \
05987      public: \
05988       virtual bool MatchAndExplain( \
05989           Tuple args, \
05990           MatchResultListener* /* listener */) const { \
05991         return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \
05992       } \
05993       virtual void DescribeTo(::std::ostream* os) const { \
05994         *os << "are " relation;                                 \
05995       } \
05996       virtual void DescribeNegationTo(::std::ostream* os) const { \
05997         *os << "aren't " relation; \
05998       } \
05999     }; \
06000   }
06001 
06002 // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively.
06003 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair");
06004 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
06005     Ge, >=, "a pair where the first >= the second");
06006 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
06007     Gt, >, "a pair where the first > the second");
06008 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
06009     Le, <=, "a pair where the first <= the second");
06010 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
06011     Lt, <, "a pair where the first < the second");
06012 GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair");
06013 
06014 #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_
06015 
06016 // Implements the Not(...) matcher for a particular argument type T.
06017 // We do not nest it inside the NotMatcher class template, as that
06018 // will prevent different instantiations of NotMatcher from sharing
06019 // the same NotMatcherImpl<T> class.
06020 template <typename T>
06021 class NotMatcherImpl : public MatcherInterface<T> {
06022  public:
06023   explicit NotMatcherImpl(const Matcher<T>& matcher)
06024       : matcher_(matcher) {}
06025 
06026   virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
06027     return !matcher_.MatchAndExplain(x, listener);
06028   }
06029 
06030   virtual void DescribeTo(::std::ostream* os) const {
06031     matcher_.DescribeNegationTo(os);
06032   }
06033 
06034   virtual void DescribeNegationTo(::std::ostream* os) const {
06035     matcher_.DescribeTo(os);
06036   }
06037 
06038  private:
06039   const Matcher<T> matcher_;
06040 
06041   GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
06042 };
06043 
06044 // Implements the Not(m) matcher, which matches a value that doesn't
06045 // match matcher m.
06046 template <typename InnerMatcher>
06047 class NotMatcher {
06048  public:
06049   explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
06050 
06051   // This template type conversion operator allows Not(m) to be used
06052   // to match any type m can match.
06053   template <typename T>
06054   operator Matcher<T>() const {
06055     return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
06056   }
06057 
06058  private:
06059   InnerMatcher matcher_;
06060 
06061   GTEST_DISALLOW_ASSIGN_(NotMatcher);
06062 };
06063 
06064 // Implements the AllOf(m1, m2) matcher for a particular argument type
06065 // T. We do not nest it inside the BothOfMatcher class template, as
06066 // that will prevent different instantiations of BothOfMatcher from
06067 // sharing the same BothOfMatcherImpl<T> class.
06068 template <typename T>
06069 class BothOfMatcherImpl : public MatcherInterface<T> {
06070  public:
06071   BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
06072       : matcher1_(matcher1), matcher2_(matcher2) {}
06073 
06074   virtual void DescribeTo(::std::ostream* os) const {
06075     *os << "(";
06076     matcher1_.DescribeTo(os);
06077     *os << ") and (";
06078     matcher2_.DescribeTo(os);
06079     *os << ")";
06080   }
06081 
06082   virtual void DescribeNegationTo(::std::ostream* os) const {
06083     *os << "(";
06084     matcher1_.DescribeNegationTo(os);
06085     *os << ") or (";
06086     matcher2_.DescribeNegationTo(os);
06087     *os << ")";
06088   }
06089 
06090   virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
06091     // If either matcher1_ or matcher2_ doesn't match x, we only need
06092     // to explain why one of them fails.
06093     StringMatchResultListener listener1;
06094     if (!matcher1_.MatchAndExplain(x, &listener1)) {
06095       *listener << listener1.str();
06096       return false;
06097     }
06098 
06099     StringMatchResultListener listener2;
06100     if (!matcher2_.MatchAndExplain(x, &listener2)) {
06101       *listener << listener2.str();
06102       return false;
06103     }
06104 
06105     // Otherwise we need to explain why *both* of them match.
06106     const internal::string s1 = listener1.str();
06107     const internal::string s2 = listener2.str();
06108 
06109     if (s1 == "") {
06110       *listener << s2;
06111     } else {
06112       *listener << s1;
06113       if (s2 != "") {
06114         *listener << ", and " << s2;
06115       }
06116     }
06117     return true;
06118   }
06119 
06120  private:
06121   const Matcher<T> matcher1_;
06122   const Matcher<T> matcher2_;
06123 
06124   GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
06125 };
06126 
06127 #if GTEST_LANG_CXX11
06128 // MatcherList provides mechanisms for storing a variable number of matchers in
06129 // a list structure (ListType) and creating a combining matcher from such a
06130 // list.
06131 // The template is defined recursively using the following template paramters:
06132 //   * kSize is the length of the MatcherList.
06133 //   * Head is the type of the first matcher of the list.
06134 //   * Tail denotes the types of the remaining matchers of the list.
06135 template <int kSize, typename Head, typename... Tail>
06136 struct MatcherList {
06137   typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
06138   typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
06139 
06140   // BuildList stores variadic type values in a nested pair structure.
06141   // Example:
06142   // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
06143   // the corresponding result of type pair<int, pair<string, float>>.
06144   static ListType BuildList(const Head& matcher, const Tail&... tail) {
06145     return ListType(matcher, MatcherListTail::BuildList(tail...));
06146   }
06147 
06148   // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
06149   // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
06150   // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
06151   // constructor taking two Matcher<T>s as input.
06152   template <typename T, template <typename /* T */> class CombiningMatcher>
06153   static Matcher<T> CreateMatcher(const ListType& matchers) {
06154     return Matcher<T>(new CombiningMatcher<T>(
06155         SafeMatcherCast<T>(matchers.first),
06156         MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
06157             matchers.second)));
06158   }
06159 };
06160 
06161 // The following defines the base case for the recursive definition of
06162 // MatcherList.
06163 template <typename Matcher1, typename Matcher2>
06164 struct MatcherList<2, Matcher1, Matcher2> {
06165   typedef ::std::pair<Matcher1, Matcher2> ListType;
06166 
06167   static ListType BuildList(const Matcher1& matcher1,
06168                             const Matcher2& matcher2) {
06169     return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
06170   }
06171 
06172   template <typename T, template <typename /* T */> class CombiningMatcher>
06173   static Matcher<T> CreateMatcher(const ListType& matchers) {
06174     return Matcher<T>(new CombiningMatcher<T>(
06175         SafeMatcherCast<T>(matchers.first),
06176         SafeMatcherCast<T>(matchers.second)));
06177   }
06178 };
06179 
06180 // VariadicMatcher is used for the variadic implementation of
06181 // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
06182 // CombiningMatcher<T> is used to recursively combine the provided matchers
06183 // (of type Args...).
06184 template <template <typename T> class CombiningMatcher, typename... Args>
06185 class VariadicMatcher {
06186  public:
06187   VariadicMatcher(const Args&... matchers)  // NOLINT
06188       : matchers_(MatcherListType::BuildList(matchers...)) {}
06189 
06190   // This template type conversion operator allows an
06191   // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
06192   // all of the provided matchers (Matcher1, Matcher2, ...) can match.
06193   template <typename T>
06194   operator Matcher<T>() const {
06195     return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
06196         matchers_);
06197   }
06198 
06199  private:
06200   typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
06201 
06202   const typename MatcherListType::ListType matchers_;
06203 
06204   GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
06205 };
06206 
06207 template <typename... Args>
06208 using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
06209 
06210 #endif  // GTEST_LANG_CXX11
06211 
06212 // Used for implementing the AllOf(m_1, ..., m_n) matcher, which
06213 // matches a value that matches all of the matchers m_1, ..., and m_n.
06214 template <typename Matcher1, typename Matcher2>
06215 class BothOfMatcher {
06216  public:
06217   BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
06218       : matcher1_(matcher1), matcher2_(matcher2) {}
06219 
06220   // This template type conversion operator allows a
06221   // BothOfMatcher<Matcher1, Matcher2> object to match any type that
06222   // both Matcher1 and Matcher2 can match.
06223   template <typename T>
06224   operator Matcher<T>() const {
06225     return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
06226                                                SafeMatcherCast<T>(matcher2_)));
06227   }
06228 
06229  private:
06230   Matcher1 matcher1_;
06231   Matcher2 matcher2_;
06232 
06233   GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
06234 };
06235 
06236 // Implements the AnyOf(m1, m2) matcher for a particular argument type
06237 // T.  We do not nest it inside the AnyOfMatcher class template, as
06238 // that will prevent different instantiations of AnyOfMatcher from
06239 // sharing the same EitherOfMatcherImpl<T> class.
06240 template <typename T>
06241 class EitherOfMatcherImpl : public MatcherInterface<T> {
06242  public:
06243   EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
06244       : matcher1_(matcher1), matcher2_(matcher2) {}
06245 
06246   virtual void DescribeTo(::std::ostream* os) const {
06247     *os << "(";
06248     matcher1_.DescribeTo(os);
06249     *os << ") or (";
06250     matcher2_.DescribeTo(os);
06251     *os << ")";
06252   }
06253 
06254   virtual void DescribeNegationTo(::std::ostream* os) const {
06255     *os << "(";
06256     matcher1_.DescribeNegationTo(os);
06257     *os << ") and (";
06258     matcher2_.DescribeNegationTo(os);
06259     *os << ")";
06260   }
06261 
06262   virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
06263     // If either matcher1_ or matcher2_ matches x, we just need to
06264     // explain why *one* of them matches.
06265     StringMatchResultListener listener1;
06266     if (matcher1_.MatchAndExplain(x, &listener1)) {
06267       *listener << listener1.str();
06268       return true;
06269     }
06270 
06271     StringMatchResultListener listener2;
06272     if (matcher2_.MatchAndExplain(x, &listener2)) {
06273       *listener << listener2.str();
06274       return true;
06275     }
06276 
06277     // Otherwise we need to explain why *both* of them fail.
06278     const internal::string s1 = listener1.str();
06279     const internal::string s2 = listener2.str();
06280 
06281     if (s1 == "") {
06282       *listener << s2;
06283     } else {
06284       *listener << s1;
06285       if (s2 != "") {
06286         *listener << ", and " << s2;
06287       }
06288     }
06289     return false;
06290   }
06291 
06292  private:
06293   const Matcher<T> matcher1_;
06294   const Matcher<T> matcher2_;
06295 
06296   GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
06297 };
06298 
06299 #if GTEST_LANG_CXX11
06300 // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
06301 template <typename... Args>
06302 using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
06303 
06304 #endif  // GTEST_LANG_CXX11
06305 
06306 // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
06307 // matches a value that matches at least one of the matchers m_1, ...,
06308 // and m_n.
06309 template <typename Matcher1, typename Matcher2>
06310 class EitherOfMatcher {
06311  public:
06312   EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
06313       : matcher1_(matcher1), matcher2_(matcher2) {}
06314 
06315   // This template type conversion operator allows a
06316   // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
06317   // both Matcher1 and Matcher2 can match.
06318   template <typename T>
06319   operator Matcher<T>() const {
06320     return Matcher<T>(new EitherOfMatcherImpl<T>(
06321         SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
06322   }
06323 
06324  private:
06325   Matcher1 matcher1_;
06326   Matcher2 matcher2_;
06327 
06328   GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
06329 };
06330 
06331 // Used for implementing Truly(pred), which turns a predicate into a
06332 // matcher.
06333 template <typename Predicate>
06334 class TrulyMatcher {
06335  public:
06336   explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
06337 
06338   // This method template allows Truly(pred) to be used as a matcher
06339   // for type T where T is the argument type of predicate 'pred'.  The
06340   // argument is passed by reference as the predicate may be
06341   // interested in the address of the argument.
06342   template <typename T>
06343   bool MatchAndExplain(T& x,  // NOLINT
06344                        MatchResultListener* /* listener */) const {
06345     // Without the if-statement, MSVC sometimes warns about converting
06346     // a value to bool (warning 4800).
06347     //
06348     // We cannot write 'return !!predicate_(x);' as that doesn't work
06349     // when predicate_(x) returns a class convertible to bool but
06350     // having no operator!().
06351     if (predicate_(x))
06352       return true;
06353     return false;
06354   }
06355 
06356   void DescribeTo(::std::ostream* os) const {
06357     *os << "satisfies the given predicate";
06358   }
06359 
06360   void DescribeNegationTo(::std::ostream* os) const {
06361     *os << "doesn't satisfy the given predicate";
06362   }
06363 
06364  private:
06365   Predicate predicate_;
06366 
06367   GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
06368 };
06369 
06370 // Used for implementing Matches(matcher), which turns a matcher into
06371 // a predicate.
06372 template <typename M>
06373 class MatcherAsPredicate {
06374  public:
06375   explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
06376 
06377   // This template operator() allows Matches(m) to be used as a
06378   // predicate on type T where m is a matcher on type T.
06379   //
06380   // The argument x is passed by reference instead of by value, as
06381   // some matcher may be interested in its address (e.g. as in
06382   // Matches(Ref(n))(x)).
06383   template <typename T>
06384   bool operator()(const T& x) const {
06385     // We let matcher_ commit to a particular type here instead of
06386     // when the MatcherAsPredicate object was constructed.  This
06387     // allows us to write Matches(m) where m is a polymorphic matcher
06388     // (e.g. Eq(5)).
06389     //
06390     // If we write Matcher<T>(matcher_).Matches(x) here, it won't
06391     // compile when matcher_ has type Matcher<const T&>; if we write
06392     // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
06393     // when matcher_ has type Matcher<T>; if we just write
06394     // matcher_.Matches(x), it won't compile when matcher_ is
06395     // polymorphic, e.g. Eq(5).
06396     //
06397     // MatcherCast<const T&>() is necessary for making the code work
06398     // in all of the above situations.
06399     return MatcherCast<const T&>(matcher_).Matches(x);
06400   }
06401 
06402  private:
06403   M matcher_;
06404 
06405   GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
06406 };
06407 
06408 // For implementing ASSERT_THAT() and EXPECT_THAT().  The template
06409 // argument M must be a type that can be converted to a matcher.
06410 template <typename M>
06411 class PredicateFormatterFromMatcher {
06412  public:
06413   explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {}
06414 
06415   // This template () operator allows a PredicateFormatterFromMatcher
06416   // object to act as a predicate-formatter suitable for using with
06417   // Google Test's EXPECT_PRED_FORMAT1() macro.
06418   template <typename T>
06419   AssertionResult operator()(const char* value_text, const T& x) const {
06420     // We convert matcher_ to a Matcher<const T&> *now* instead of
06421     // when the PredicateFormatterFromMatcher object was constructed,
06422     // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
06423     // know which type to instantiate it to until we actually see the
06424     // type of x here.
06425     //
06426     // We write SafeMatcherCast<const T&>(matcher_) instead of
06427     // Matcher<const T&>(matcher_), as the latter won't compile when
06428     // matcher_ has type Matcher<T> (e.g. An<int>()).
06429     // We don't write MatcherCast<const T&> either, as that allows
06430     // potentially unsafe downcasting of the matcher argument.
06431     const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
06432     StringMatchResultListener listener;
06433     if (MatchPrintAndExplain(x, matcher, &listener))
06434       return AssertionSuccess();
06435 
06436     ::std::stringstream ss;
06437     ss << "Value of: " << value_text << "\n"
06438        << "Expected: ";
06439     matcher.DescribeTo(&ss);
06440     ss << "\n  Actual: " << listener.str();
06441     return AssertionFailure() << ss.str();
06442   }
06443 
06444  private:
06445   const M matcher_;
06446 
06447   GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
06448 };
06449 
06450 // A helper function for converting a matcher to a predicate-formatter
06451 // without the user needing to explicitly write the type.  This is
06452 // used for implementing ASSERT_THAT() and EXPECT_THAT().
06453 template <typename M>
06454 inline PredicateFormatterFromMatcher<M>
06455 MakePredicateFormatterFromMatcher(const M& matcher) {
06456   return PredicateFormatterFromMatcher<M>(matcher);
06457 }
06458 
06459 // Implements the polymorphic floating point equality matcher, which matches
06460 // two float values using ULP-based approximation or, optionally, a
06461 // user-specified epsilon.  The template is meant to be instantiated with
06462 // FloatType being either float or double.
06463 template <typename FloatType>
06464 class FloatingEqMatcher {
06465  public:
06466   // Constructor for FloatingEqMatcher.
06467   // The matcher's input will be compared with rhs.  The matcher treats two
06468   // NANs as equal if nan_eq_nan is true.  Otherwise, under IEEE standards,
06469   // equality comparisons between NANs will always return false.  We specify a
06470   // negative max_abs_error_ term to indicate that ULP-based approximation will
06471   // be used for comparison.
06472   FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) :
06473     rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
06474   }
06475 
06476   // Constructor that supports a user-specified max_abs_error that will be used
06477   // for comparison instead of ULP-based approximation.  The max absolute
06478   // should be non-negative.
06479   FloatingEqMatcher(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
06480     rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {
06481     GTEST_CHECK_(max_abs_error >= 0)
06482         << ", where max_abs_error is" << max_abs_error;
06483   }
06484 
06485   // Implements floating point equality matcher as a Matcher<T>.
06486   template <typename T>
06487   class Impl : public MatcherInterface<T> {
06488    public:
06489     Impl(FloatType rhs, bool nan_eq_nan, FloatType max_abs_error) :
06490       rhs_(rhs), nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {}
06491 
06492     virtual bool MatchAndExplain(T value,
06493                                  MatchResultListener* /* listener */) const {
06494       const FloatingPoint<FloatType> lhs(value), rhs(rhs_);
06495 
06496       // Compares NaNs first, if nan_eq_nan_ is true.
06497       if (lhs.is_nan() || rhs.is_nan()) {
06498         if (lhs.is_nan() && rhs.is_nan()) {
06499           return nan_eq_nan_;
06500         }
06501         // One is nan; the other is not nan.
06502         return false;
06503       }
06504       if (HasMaxAbsError()) {
06505         // We perform an equality check so that inf will match inf, regardless
06506         // of error bounds.  If the result of value - rhs_ would result in
06507         // overflow or if either value is inf, the default result is infinity,
06508         // which should only match if max_abs_error_ is also infinity.
06509         return value == rhs_ || fabs(value - rhs_) <= max_abs_error_;
06510       } else {
06511         return lhs.AlmostEquals(rhs);
06512       }
06513     }
06514 
06515     virtual void DescribeTo(::std::ostream* os) const {
06516       // os->precision() returns the previously set precision, which we
06517       // store to restore the ostream to its original configuration
06518       // after outputting.
06519       const ::std::streamsize old_precision = os->precision(
06520           ::std::numeric_limits<FloatType>::digits10 + 2);
06521       if (FloatingPoint<FloatType>(rhs_).is_nan()) {
06522         if (nan_eq_nan_) {
06523           *os << "is NaN";
06524         } else {
06525           *os << "never matches";
06526         }
06527       } else {
06528         *os << "is approximately " << rhs_;
06529         if (HasMaxAbsError()) {
06530           *os << " (absolute error <= " << max_abs_error_ << ")";
06531         }
06532       }
06533       os->precision(old_precision);
06534     }
06535 
06536     virtual void DescribeNegationTo(::std::ostream* os) const {
06537       // As before, get original precision.
06538       const ::std::streamsize old_precision = os->precision(
06539           ::std::numeric_limits<FloatType>::digits10 + 2);
06540       if (FloatingPoint<FloatType>(rhs_).is_nan()) {
06541         if (nan_eq_nan_) {
06542           *os << "isn't NaN";
06543         } else {
06544           *os << "is anything";
06545         }
06546       } else {
06547         *os << "isn't approximately " << rhs_;
06548         if (HasMaxAbsError()) {
06549           *os << " (absolute error > " << max_abs_error_ << ")";
06550         }
06551       }
06552       // Restore original precision.
06553       os->precision(old_precision);
06554     }
06555 
06556    private:
06557     bool HasMaxAbsError() const {
06558       return max_abs_error_ >= 0;
06559     }
06560 
06561     const FloatType rhs_;
06562     const bool nan_eq_nan_;
06563     // max_abs_error will be used for value comparison when >= 0.
06564     const FloatType max_abs_error_;
06565 
06566     GTEST_DISALLOW_ASSIGN_(Impl);
06567   };
06568 
06569   // The following 3 type conversion operators allow FloatEq(rhs) and
06570   // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a
06571   // Matcher<const float&>, or a Matcher<float&>, but nothing else.
06572   // (While Google's C++ coding style doesn't allow arguments passed
06573   // by non-const reference, we may see them in code not conforming to
06574   // the style.  Therefore Google Mock needs to support them.)
06575   operator Matcher<FloatType>() const {
06576     return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_, max_abs_error_));
06577   }
06578 
06579   operator Matcher<const FloatType&>() const {
06580     return MakeMatcher(
06581         new Impl<const FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
06582   }
06583 
06584   operator Matcher<FloatType&>() const {
06585     return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_, max_abs_error_));
06586   }
06587 
06588  private:
06589   const FloatType rhs_;
06590   const bool nan_eq_nan_;
06591   // max_abs_error will be used for value comparison when >= 0.
06592   const FloatType max_abs_error_;
06593 
06594   GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
06595 };
06596 
06597 // Implements the Pointee(m) matcher for matching a pointer whose
06598 // pointee matches matcher m.  The pointer can be either raw or smart.
06599 template <typename InnerMatcher>
06600 class PointeeMatcher {
06601  public:
06602   explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
06603 
06604   // This type conversion operator template allows Pointee(m) to be
06605   // used as a matcher for any pointer type whose pointee type is
06606   // compatible with the inner matcher, where type Pointer can be
06607   // either a raw pointer or a smart pointer.
06608   //
06609   // The reason we do this instead of relying on
06610   // MakePolymorphicMatcher() is that the latter is not flexible
06611   // enough for implementing the DescribeTo() method of Pointee().
06612   template <typename Pointer>
06613   operator Matcher<Pointer>() const {
06614     return MakeMatcher(new Impl<Pointer>(matcher_));
06615   }
06616 
06617  private:
06618   // The monomorphic implementation that works for a particular pointer type.
06619   template <typename Pointer>
06620   class Impl : public MatcherInterface<Pointer> {
06621    public:
06622     typedef typename PointeeOf<GTEST_REMOVE_CONST_(  // NOLINT
06623         GTEST_REMOVE_REFERENCE_(Pointer))>::type Pointee;
06624 
06625     explicit Impl(const InnerMatcher& matcher)
06626         : matcher_(MatcherCast<const Pointee&>(matcher)) {}
06627 
06628     virtual void DescribeTo(::std::ostream* os) const {
06629       *os << "points to a value that ";
06630       matcher_.DescribeTo(os);
06631     }
06632 
06633     virtual void DescribeNegationTo(::std::ostream* os) const {
06634       *os << "does not point to a value that ";
06635       matcher_.DescribeTo(os);
06636     }
06637 
06638     virtual bool MatchAndExplain(Pointer pointer,
06639                                  MatchResultListener* listener) const {
06640       if (GetRawPointer(pointer) == NULL)
06641         return false;
06642 
06643       *listener << "which points to ";
06644       return MatchPrintAndExplain(*pointer, matcher_, listener);
06645     }
06646 
06647    private:
06648     const Matcher<const Pointee&> matcher_;
06649 
06650     GTEST_DISALLOW_ASSIGN_(Impl);
06651   };
06652 
06653   const InnerMatcher matcher_;
06654 
06655   GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
06656 };
06657 
06658 // Implements the Field() matcher for matching a field (i.e. member
06659 // variable) of an object.
06660 template <typename Class, typename FieldType>
06661 class FieldMatcher {
06662  public:
06663   FieldMatcher(FieldType Class::*field,
06664                const Matcher<const FieldType&>& matcher)
06665       : field_(field), matcher_(matcher) {}
06666 
06667   void DescribeTo(::std::ostream* os) const {
06668     *os << "is an object whose given field ";
06669     matcher_.DescribeTo(os);
06670   }
06671 
06672   void DescribeNegationTo(::std::ostream* os) const {
06673     *os << "is an object whose given field ";
06674     matcher_.DescribeNegationTo(os);
06675   }
06676 
06677   template <typename T>
06678   bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
06679     return MatchAndExplainImpl(
06680         typename ::testing::internal::
06681             is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
06682         value, listener);
06683   }
06684 
06685  private:
06686   // The first argument of MatchAndExplainImpl() is needed to help
06687   // Symbian's C++ compiler choose which overload to use.  Its type is
06688   // true_type iff the Field() matcher is used to match a pointer.
06689   bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
06690                            MatchResultListener* listener) const {
06691     *listener << "whose given field is ";
06692     return MatchPrintAndExplain(obj.*field_, matcher_, listener);
06693   }
06694 
06695   bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
06696                            MatchResultListener* listener) const {
06697     if (p == NULL)
06698       return false;
06699 
06700     *listener << "which points to an object ";
06701     // Since *p has a field, it must be a class/struct/union type and
06702     // thus cannot be a pointer.  Therefore we pass false_type() as
06703     // the first argument.
06704     return MatchAndExplainImpl(false_type(), *p, listener);
06705   }
06706 
06707   const FieldType Class::*field_;
06708   const Matcher<const FieldType&> matcher_;
06709 
06710   GTEST_DISALLOW_ASSIGN_(FieldMatcher);
06711 };
06712 
06713 // Implements the Property() matcher for matching a property
06714 // (i.e. return value of a getter method) of an object.
06715 template <typename Class, typename PropertyType>
06716 class PropertyMatcher {
06717  public:
06718   // The property may have a reference type, so 'const PropertyType&'
06719   // may cause double references and fail to compile.  That's why we
06720   // need GTEST_REFERENCE_TO_CONST, which works regardless of
06721   // PropertyType being a reference or not.
06722   typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
06723 
06724   PropertyMatcher(PropertyType (Class::*property)() const,
06725                   const Matcher<RefToConstProperty>& matcher)
06726       : property_(property), matcher_(matcher) {}
06727 
06728   void DescribeTo(::std::ostream* os) const {
06729     *os << "is an object whose given property ";
06730     matcher_.DescribeTo(os);
06731   }
06732 
06733   void DescribeNegationTo(::std::ostream* os) const {
06734     *os << "is an object whose given property ";
06735     matcher_.DescribeNegationTo(os);
06736   }
06737 
06738   template <typename T>
06739   bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
06740     return MatchAndExplainImpl(
06741         typename ::testing::internal::
06742             is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
06743         value, listener);
06744   }
06745 
06746  private:
06747   // The first argument of MatchAndExplainImpl() is needed to help
06748   // Symbian's C++ compiler choose which overload to use.  Its type is
06749   // true_type iff the Property() matcher is used to match a pointer.
06750   bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
06751                            MatchResultListener* listener) const {
06752     *listener << "whose given property is ";
06753     // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
06754     // which takes a non-const reference as argument.
06755     RefToConstProperty result = (obj.*property_)();
06756     return MatchPrintAndExplain(result, matcher_, listener);
06757   }
06758 
06759   bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
06760                            MatchResultListener* listener) const {
06761     if (p == NULL)
06762       return false;
06763 
06764     *listener << "which points to an object ";
06765     // Since *p has a property method, it must be a class/struct/union
06766     // type and thus cannot be a pointer.  Therefore we pass
06767     // false_type() as the first argument.
06768     return MatchAndExplainImpl(false_type(), *p, listener);
06769   }
06770 
06771   PropertyType (Class::*property_)() const;
06772   const Matcher<RefToConstProperty> matcher_;
06773 
06774   GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
06775 };
06776 
06777 // Type traits specifying various features of different functors for ResultOf.
06778 // The default template specifies features for functor objects.
06779 // Functor classes have to typedef argument_type and result_type
06780 // to be compatible with ResultOf.
06781 template <typename Functor>
06782 struct CallableTraits {
06783   typedef typename Functor::result_type ResultType;
06784   typedef Functor StorageType;
06785 
06786   static void CheckIsValid(Functor /* functor */) {}
06787   template <typename T>
06788   static ResultType Invoke(Functor f, T arg) { return f(arg); }
06789 };
06790 
06791 // Specialization for function pointers.
06792 template <typename ArgType, typename ResType>
06793 struct CallableTraits<ResType(*)(ArgType)> {
06794   typedef ResType ResultType;
06795   typedef ResType(*StorageType)(ArgType);
06796 
06797   static void CheckIsValid(ResType(*f)(ArgType)) {
06798     GTEST_CHECK_(f != NULL)
06799         << "NULL function pointer is passed into ResultOf().";
06800   }
06801   template <typename T>
06802   static ResType Invoke(ResType(*f)(ArgType), T arg) {
06803     return (*f)(arg);
06804   }
06805 };
06806 
06807 // Implements the ResultOf() matcher for matching a return value of a
06808 // unary function of an object.
06809 template <typename Callable>
06810 class ResultOfMatcher {
06811  public:
06812   typedef typename CallableTraits<Callable>::ResultType ResultType;
06813 
06814   ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
06815       : callable_(callable), matcher_(matcher) {
06816     CallableTraits<Callable>::CheckIsValid(callable_);
06817   }
06818 
06819   template <typename T>
06820   operator Matcher<T>() const {
06821     return Matcher<T>(new Impl<T>(callable_, matcher_));
06822   }
06823 
06824  private:
06825   typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
06826 
06827   template <typename T>
06828   class Impl : public MatcherInterface<T> {
06829    public:
06830     Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
06831         : callable_(callable), matcher_(matcher) {}
06832 
06833     virtual void DescribeTo(::std::ostream* os) const {
06834       *os << "is mapped by the given callable to a value that ";
06835       matcher_.DescribeTo(os);
06836     }
06837 
06838     virtual void DescribeNegationTo(::std::ostream* os) const {
06839       *os << "is mapped by the given callable to a value that ";
06840       matcher_.DescribeNegationTo(os);
06841     }
06842 
06843     virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const {
06844       *listener << "which is mapped by the given callable to ";
06845       // Cannot pass the return value (for example, int) to
06846       // MatchPrintAndExplain, which takes a non-const reference as argument.
06847       ResultType result =
06848           CallableTraits<Callable>::template Invoke<T>(callable_, obj);
06849       return MatchPrintAndExplain(result, matcher_, listener);
06850     }
06851 
06852    private:
06853     // Functors often define operator() as non-const method even though
06854     // they are actualy stateless. But we need to use them even when
06855     // 'this' is a const pointer. It's the user's responsibility not to
06856     // use stateful callables with ResultOf(), which does't guarantee
06857     // how many times the callable will be invoked.
06858     mutable CallableStorageType callable_;
06859     const Matcher<ResultType> matcher_;
06860 
06861     GTEST_DISALLOW_ASSIGN_(Impl);
06862   };  // class Impl
06863 
06864   const CallableStorageType callable_;
06865   const Matcher<ResultType> matcher_;
06866 
06867   GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
06868 };
06869 
06870 // Implements a matcher that checks the size of an STL-style container.
06871 template <typename SizeMatcher>
06872 class SizeIsMatcher {
06873  public:
06874   explicit SizeIsMatcher(const SizeMatcher& size_matcher)
06875        : size_matcher_(size_matcher) {
06876   }
06877 
06878   template <typename Container>
06879   operator Matcher<Container>() const {
06880     return MakeMatcher(new Impl<Container>(size_matcher_));
06881   }
06882 
06883   template <typename Container>
06884   class Impl : public MatcherInterface<Container> {
06885    public:
06886     typedef internal::StlContainerView<
06887          GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
06888     typedef typename ContainerView::type::size_type SizeType;
06889     explicit Impl(const SizeMatcher& size_matcher)
06890         : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
06891 
06892     virtual void DescribeTo(::std::ostream* os) const {
06893       *os << "size ";
06894       size_matcher_.DescribeTo(os);
06895     }
06896     virtual void DescribeNegationTo(::std::ostream* os) const {
06897       *os << "size ";
06898       size_matcher_.DescribeNegationTo(os);
06899     }
06900 
06901     virtual bool MatchAndExplain(Container container,
06902                                  MatchResultListener* listener) const {
06903       SizeType size = container.size();
06904       StringMatchResultListener size_listener;
06905       const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
06906       *listener
06907           << "whose size " << size << (result ? " matches" : " doesn't match");
06908       PrintIfNotEmpty(size_listener.str(), listener->stream());
06909       return result;
06910     }
06911 
06912    private:
06913     const Matcher<SizeType> size_matcher_;
06914     GTEST_DISALLOW_ASSIGN_(Impl);
06915   };
06916 
06917  private:
06918   const SizeMatcher size_matcher_;
06919   GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
06920 };
06921 
06922 // Implements an equality matcher for any STL-style container whose elements
06923 // support ==. This matcher is like Eq(), but its failure explanations provide
06924 // more detailed information that is useful when the container is used as a set.
06925 // The failure message reports elements that are in one of the operands but not
06926 // the other. The failure messages do not report duplicate or out-of-order
06927 // elements in the containers (which don't properly matter to sets, but can
06928 // occur if the containers are vectors or lists, for example).
06929 //
06930 // Uses the container's const_iterator, value_type, operator ==,
06931 // begin(), and end().
06932 template <typename Container>
06933 class ContainerEqMatcher {
06934  public:
06935   typedef internal::StlContainerView<Container> View;
06936   typedef typename View::type StlContainer;
06937   typedef typename View::const_reference StlContainerReference;
06938 
06939   // We make a copy of rhs in case the elements in it are modified
06940   // after this matcher is created.
06941   explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) {
06942     // Makes sure the user doesn't instantiate this class template
06943     // with a const or reference type.
06944     (void)testing::StaticAssertTypeEq<Container,
06945         GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
06946   }
06947 
06948   void DescribeTo(::std::ostream* os) const {
06949     *os << "equals ";
06950     UniversalPrint(rhs_, os);
06951   }
06952   void DescribeNegationTo(::std::ostream* os) const {
06953     *os << "does not equal ";
06954     UniversalPrint(rhs_, os);
06955   }
06956 
06957   template <typename LhsContainer>
06958   bool MatchAndExplain(const LhsContainer& lhs,
06959                        MatchResultListener* listener) const {
06960     // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
06961     // that causes LhsContainer to be a const type sometimes.
06962     typedef internal::StlContainerView<GTEST_REMOVE_CONST_(LhsContainer)>
06963         LhsView;
06964     typedef typename LhsView::type LhsStlContainer;
06965     StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
06966     if (lhs_stl_container == rhs_)
06967       return true;
06968 
06969     ::std::ostream* const os = listener->stream();
06970     if (os != NULL) {
06971       // Something is different. Check for extra values first.
06972       bool printed_header = false;
06973       for (typename LhsStlContainer::const_iterator it =
06974                lhs_stl_container.begin();
06975            it != lhs_stl_container.end(); ++it) {
06976         if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) ==
06977             rhs_.end()) {
06978           if (printed_header) {
06979             *os << ", ";
06980           } else {
06981             *os << "which has these unexpected elements: ";
06982             printed_header = true;
06983           }
06984           UniversalPrint(*it, os);
06985         }
06986       }
06987 
06988       // Now check for missing values.
06989       bool printed_header2 = false;
06990       for (typename StlContainer::const_iterator it = rhs_.begin();
06991            it != rhs_.end(); ++it) {
06992         if (internal::ArrayAwareFind(
06993                 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
06994             lhs_stl_container.end()) {
06995           if (printed_header2) {
06996             *os << ", ";
06997           } else {
06998             *os << (printed_header ? ",\nand" : "which")
06999                 << " doesn't have these expected elements: ";
07000             printed_header2 = true;
07001           }
07002           UniversalPrint(*it, os);
07003         }
07004       }
07005     }
07006 
07007     return false;
07008   }
07009 
07010  private:
07011   const StlContainer rhs_;
07012 
07013   GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
07014 };
07015 
07016 // A comparator functor that uses the < operator to compare two values.
07017 struct LessComparator {
07018   template <typename T, typename U>
07019   bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
07020 };
07021 
07022 // Implements WhenSortedBy(comparator, container_matcher).
07023 template <typename Comparator, typename ContainerMatcher>
07024 class WhenSortedByMatcher {
07025  public:
07026   WhenSortedByMatcher(const Comparator& comparator,
07027                       const ContainerMatcher& matcher)
07028       : comparator_(comparator), matcher_(matcher) {}
07029 
07030   template <typename LhsContainer>
07031   operator Matcher<LhsContainer>() const {
07032     return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
07033   }
07034 
07035   template <typename LhsContainer>
07036   class Impl : public MatcherInterface<LhsContainer> {
07037    public:
07038     typedef internal::StlContainerView<
07039          GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
07040     typedef typename LhsView::type LhsStlContainer;
07041     typedef typename LhsView::const_reference LhsStlContainerReference;
07042     // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
07043     // so that we can match associative containers.
07044     typedef typename RemoveConstFromKey<
07045         typename LhsStlContainer::value_type>::type LhsValue;
07046 
07047     Impl(const Comparator& comparator, const ContainerMatcher& matcher)
07048         : comparator_(comparator), matcher_(matcher) {}
07049 
07050     virtual void DescribeTo(::std::ostream* os) const {
07051       *os << "(when sorted) ";
07052       matcher_.DescribeTo(os);
07053     }
07054 
07055     virtual void DescribeNegationTo(::std::ostream* os) const {
07056       *os << "(when sorted) ";
07057       matcher_.DescribeNegationTo(os);
07058     }
07059 
07060     virtual bool MatchAndExplain(LhsContainer lhs,
07061                                  MatchResultListener* listener) const {
07062       LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
07063       ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
07064                                                lhs_stl_container.end());
07065       ::std::sort(
07066            sorted_container.begin(), sorted_container.end(), comparator_);
07067 
07068       if (!listener->IsInterested()) {
07069         // If the listener is not interested, we do not need to
07070         // construct the inner explanation.
07071         return matcher_.Matches(sorted_container);
07072       }
07073 
07074       *listener << "which is ";
07075       UniversalPrint(sorted_container, listener->stream());
07076       *listener << " when sorted";
07077 
07078       StringMatchResultListener inner_listener;
07079       const bool match = matcher_.MatchAndExplain(sorted_container,
07080                                                   &inner_listener);
07081       PrintIfNotEmpty(inner_listener.str(), listener->stream());
07082       return match;
07083     }
07084 
07085    private:
07086     const Comparator comparator_;
07087     const Matcher<const ::std::vector<LhsValue>&> matcher_;
07088 
07089     GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
07090   };
07091 
07092  private:
07093   const Comparator comparator_;
07094   const ContainerMatcher matcher_;
07095 
07096   GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
07097 };
07098 
07099 // Implements Pointwise(tuple_matcher, rhs_container).  tuple_matcher
07100 // must be able to be safely cast to Matcher<tuple<const T1&, const
07101 // T2&> >, where T1 and T2 are the types of elements in the LHS
07102 // container and the RHS container respectively.
07103 template <typename TupleMatcher, typename RhsContainer>
07104 class PointwiseMatcher {
07105  public:
07106   typedef internal::StlContainerView<RhsContainer> RhsView;
07107   typedef typename RhsView::type RhsStlContainer;
07108   typedef typename RhsStlContainer::value_type RhsValue;
07109 
07110   // Like ContainerEq, we make a copy of rhs in case the elements in
07111   // it are modified after this matcher is created.
07112   PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
07113       : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
07114     // Makes sure the user doesn't instantiate this class template
07115     // with a const or reference type.
07116     (void)testing::StaticAssertTypeEq<RhsContainer,
07117         GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
07118   }
07119 
07120   template <typename LhsContainer>
07121   operator Matcher<LhsContainer>() const {
07122     return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
07123   }
07124 
07125   template <typename LhsContainer>
07126   class Impl : public MatcherInterface<LhsContainer> {
07127    public:
07128     typedef internal::StlContainerView<
07129          GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
07130     typedef typename LhsView::type LhsStlContainer;
07131     typedef typename LhsView::const_reference LhsStlContainerReference;
07132     typedef typename LhsStlContainer::value_type LhsValue;
07133     // We pass the LHS value and the RHS value to the inner matcher by
07134     // reference, as they may be expensive to copy.  We must use tuple
07135     // instead of pair here, as a pair cannot hold references (C++ 98,
07136     // 20.2.2 [lib.pairs]).
07137     typedef ::std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
07138 
07139     Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
07140         // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
07141         : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
07142           rhs_(rhs) {}
07143 
07144     virtual void DescribeTo(::std::ostream* os) const {
07145       *os << "contains " << rhs_.size()
07146           << " values, where each value and its corresponding value in ";
07147       UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
07148       *os << " ";
07149       mono_tuple_matcher_.DescribeTo(os);
07150     }
07151     virtual void DescribeNegationTo(::std::ostream* os) const {
07152       *os << "doesn't contain exactly " << rhs_.size()
07153           << " values, or contains a value x at some index i"
07154           << " where x and the i-th value of ";
07155       UniversalPrint(rhs_, os);
07156       *os << " ";
07157       mono_tuple_matcher_.DescribeNegationTo(os);
07158     }
07159 
07160     virtual bool MatchAndExplain(LhsContainer lhs,
07161                                  MatchResultListener* listener) const {
07162       LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
07163       const size_t actual_size = lhs_stl_container.size();
07164       if (actual_size != rhs_.size()) {
07165         *listener << "which contains " << actual_size << " values";
07166         return false;
07167       }
07168 
07169       typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
07170       typename RhsStlContainer::const_iterator right = rhs_.begin();
07171       for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
07172         const InnerMatcherArg value_pair(*left, *right);
07173 
07174         if (listener->IsInterested()) {
07175           StringMatchResultListener inner_listener;
07176           if (!mono_tuple_matcher_.MatchAndExplain(
07177                   value_pair, &inner_listener)) {
07178             *listener << "where the value pair (";
07179             UniversalPrint(*left, listener->stream());
07180             *listener << ", ";
07181             UniversalPrint(*right, listener->stream());
07182             *listener << ") at index #" << i << " don't match";
07183             PrintIfNotEmpty(inner_listener.str(), listener->stream());
07184             return false;
07185           }
07186         } else {
07187           if (!mono_tuple_matcher_.Matches(value_pair))
07188             return false;
07189         }
07190       }
07191 
07192       return true;
07193     }
07194 
07195    private:
07196     const Matcher<InnerMatcherArg> mono_tuple_matcher_;
07197     const RhsStlContainer rhs_;
07198 
07199     GTEST_DISALLOW_ASSIGN_(Impl);
07200   };
07201 
07202  private:
07203   const TupleMatcher tuple_matcher_;
07204   const RhsStlContainer rhs_;
07205 
07206   GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
07207 };
07208 
07209 // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
07210 template <typename Container>
07211 class QuantifierMatcherImpl : public MatcherInterface<Container> {
07212  public:
07213   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
07214   typedef StlContainerView<RawContainer> View;
07215   typedef typename View::type StlContainer;
07216   typedef typename View::const_reference StlContainerReference;
07217   typedef typename StlContainer::value_type Element;
07218 
07219   template <typename InnerMatcher>
07220   explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
07221       : inner_matcher_(
07222            testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
07223 
07224   // Checks whether:
07225   // * All elements in the container match, if all_elements_should_match.
07226   // * Any element in the container matches, if !all_elements_should_match.
07227   bool MatchAndExplainImpl(bool all_elements_should_match,
07228                            Container container,
07229                            MatchResultListener* listener) const {
07230     StlContainerReference stl_container = View::ConstReference(container);
07231     size_t i = 0;
07232     for (typename StlContainer::const_iterator it = stl_container.begin();
07233          it != stl_container.end(); ++it, ++i) {
07234       StringMatchResultListener inner_listener;
07235       const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
07236 
07237       if (matches != all_elements_should_match) {
07238         *listener << "whose element #" << i
07239                   << (matches ? " matches" : " doesn't match");
07240         PrintIfNotEmpty(inner_listener.str(), listener->stream());
07241         return !all_elements_should_match;
07242       }
07243     }
07244     return all_elements_should_match;
07245   }
07246 
07247  protected:
07248   const Matcher<const Element&> inner_matcher_;
07249 
07250   GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
07251 };
07252 
07253 // Implements Contains(element_matcher) for the given argument type Container.
07254 // Symmetric to EachMatcherImpl.
07255 template <typename Container>
07256 class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
07257  public:
07258   template <typename InnerMatcher>
07259   explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
07260       : QuantifierMatcherImpl<Container>(inner_matcher) {}
07261 
07262   // Describes what this matcher does.
07263   virtual void DescribeTo(::std::ostream* os) const {
07264     *os << "contains at least one element that ";
07265     this->inner_matcher_.DescribeTo(os);
07266   }
07267 
07268   virtual void DescribeNegationTo(::std::ostream* os) const {
07269     *os << "doesn't contain any element that ";
07270     this->inner_matcher_.DescribeTo(os);
07271   }
07272 
07273   virtual bool MatchAndExplain(Container container,
07274                                MatchResultListener* listener) const {
07275     return this->MatchAndExplainImpl(false, container, listener);
07276   }
07277 
07278  private:
07279   GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
07280 };
07281 
07282 // Implements Each(element_matcher) for the given argument type Container.
07283 // Symmetric to ContainsMatcherImpl.
07284 template <typename Container>
07285 class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
07286  public:
07287   template <typename InnerMatcher>
07288   explicit EachMatcherImpl(InnerMatcher inner_matcher)
07289       : QuantifierMatcherImpl<Container>(inner_matcher) {}
07290 
07291   // Describes what this matcher does.
07292   virtual void DescribeTo(::std::ostream* os) const {
07293     *os << "only contains elements that ";
07294     this->inner_matcher_.DescribeTo(os);
07295   }
07296 
07297   virtual void DescribeNegationTo(::std::ostream* os) const {
07298     *os << "contains some element that ";
07299     this->inner_matcher_.DescribeNegationTo(os);
07300   }
07301 
07302   virtual bool MatchAndExplain(Container container,
07303                                MatchResultListener* listener) const {
07304     return this->MatchAndExplainImpl(true, container, listener);
07305   }
07306 
07307  private:
07308   GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
07309 };
07310 
07311 // Implements polymorphic Contains(element_matcher).
07312 template <typename M>
07313 class ContainsMatcher {
07314  public:
07315   explicit ContainsMatcher(M m) : inner_matcher_(m) {}
07316 
07317   template <typename Container>
07318   operator Matcher<Container>() const {
07319     return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
07320   }
07321 
07322  private:
07323   const M inner_matcher_;
07324 
07325   GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
07326 };
07327 
07328 // Implements polymorphic Each(element_matcher).
07329 template <typename M>
07330 class EachMatcher {
07331  public:
07332   explicit EachMatcher(M m) : inner_matcher_(m) {}
07333 
07334   template <typename Container>
07335   operator Matcher<Container>() const {
07336     return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
07337   }
07338 
07339  private:
07340   const M inner_matcher_;
07341 
07342   GTEST_DISALLOW_ASSIGN_(EachMatcher);
07343 };
07344 
07345 // Implements Key(inner_matcher) for the given argument pair type.
07346 // Key(inner_matcher) matches an std::pair whose 'first' field matches
07347 // inner_matcher.  For example, Contains(Key(Ge(5))) can be used to match an
07348 // std::map that contains at least one element whose key is >= 5.
07349 template <typename PairType>
07350 class KeyMatcherImpl : public MatcherInterface<PairType> {
07351  public:
07352   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
07353   typedef typename RawPairType::first_type KeyType;
07354 
07355   template <typename InnerMatcher>
07356   explicit KeyMatcherImpl(InnerMatcher inner_matcher)
07357       : inner_matcher_(
07358           testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
07359   }
07360 
07361   // Returns true iff 'key_value.first' (the key) matches the inner matcher.
07362   virtual bool MatchAndExplain(PairType key_value,
07363                                MatchResultListener* listener) const {
07364     StringMatchResultListener inner_listener;
07365     const bool match = inner_matcher_.MatchAndExplain(key_value.first,
07366                                                       &inner_listener);
07367     const internal::string explanation = inner_listener.str();
07368     if (explanation != "") {
07369       *listener << "whose first field is a value " << explanation;
07370     }
07371     return match;
07372   }
07373 
07374   // Describes what this matcher does.
07375   virtual void DescribeTo(::std::ostream* os) const {
07376     *os << "has a key that ";
07377     inner_matcher_.DescribeTo(os);
07378   }
07379 
07380   // Describes what the negation of this matcher does.
07381   virtual void DescribeNegationTo(::std::ostream* os) const {
07382     *os << "doesn't have a key that ";
07383     inner_matcher_.DescribeTo(os);
07384   }
07385 
07386  private:
07387   const Matcher<const KeyType&> inner_matcher_;
07388 
07389   GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
07390 };
07391 
07392 // Implements polymorphic Key(matcher_for_key).
07393 template <typename M>
07394 class KeyMatcher {
07395  public:
07396   explicit KeyMatcher(M m) : matcher_for_key_(m) {}
07397 
07398   template <typename PairType>
07399   operator Matcher<PairType>() const {
07400     return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
07401   }
07402 
07403  private:
07404   const M matcher_for_key_;
07405 
07406   GTEST_DISALLOW_ASSIGN_(KeyMatcher);
07407 };
07408 
07409 // Implements Pair(first_matcher, second_matcher) for the given argument pair
07410 // type with its two matchers. See Pair() function below.
07411 template <typename PairType>
07412 class PairMatcherImpl : public MatcherInterface<PairType> {
07413  public:
07414   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
07415   typedef typename RawPairType::first_type FirstType;
07416   typedef typename RawPairType::second_type SecondType;
07417 
07418   template <typename FirstMatcher, typename SecondMatcher>
07419   PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
07420       : first_matcher_(
07421             testing::SafeMatcherCast<const FirstType&>(first_matcher)),
07422         second_matcher_(
07423             testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
07424   }
07425 
07426   // Describes what this matcher does.
07427   virtual void DescribeTo(::std::ostream* os) const {
07428     *os << "has a first field that ";
07429     first_matcher_.DescribeTo(os);
07430     *os << ", and has a second field that ";
07431     second_matcher_.DescribeTo(os);
07432   }
07433 
07434   // Describes what the negation of this matcher does.
07435   virtual void DescribeNegationTo(::std::ostream* os) const {
07436     *os << "has a first field that ";
07437     first_matcher_.DescribeNegationTo(os);
07438     *os << ", or has a second field that ";
07439     second_matcher_.DescribeNegationTo(os);
07440   }
07441 
07442   // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second'
07443   // matches second_matcher.
07444   virtual bool MatchAndExplain(PairType a_pair,
07445                                MatchResultListener* listener) const {
07446     if (!listener->IsInterested()) {
07447       // If the listener is not interested, we don't need to construct the
07448       // explanation.
07449       return first_matcher_.Matches(a_pair.first) &&
07450              second_matcher_.Matches(a_pair.second);
07451     }
07452     StringMatchResultListener first_inner_listener;
07453     if (!first_matcher_.MatchAndExplain(a_pair.first,
07454                                         &first_inner_listener)) {
07455       *listener << "whose first field does not match";
07456       PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
07457       return false;
07458     }
07459     StringMatchResultListener second_inner_listener;
07460     if (!second_matcher_.MatchAndExplain(a_pair.second,
07461                                          &second_inner_listener)) {
07462       *listener << "whose second field does not match";
07463       PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
07464       return false;
07465     }
07466     ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
07467                    listener);
07468     return true;
07469   }
07470 
07471  private:
07472   void ExplainSuccess(const internal::string& first_explanation,
07473                       const internal::string& second_explanation,
07474                       MatchResultListener* listener) const {
07475     *listener << "whose both fields match";
07476     if (first_explanation != "") {
07477       *listener << ", where the first field is a value " << first_explanation;
07478     }
07479     if (second_explanation != "") {
07480       *listener << ", ";
07481       if (first_explanation != "") {
07482         *listener << "and ";
07483       } else {
07484         *listener << "where ";
07485       }
07486       *listener << "the second field is a value " << second_explanation;
07487     }
07488   }
07489 
07490   const Matcher<const FirstType&> first_matcher_;
07491   const Matcher<const SecondType&> second_matcher_;
07492 
07493   GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
07494 };
07495 
07496 // Implements polymorphic Pair(first_matcher, second_matcher).
07497 template <typename FirstMatcher, typename SecondMatcher>
07498 class PairMatcher {
07499  public:
07500   PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
07501       : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
07502 
07503   template <typename PairType>
07504   operator Matcher<PairType> () const {
07505     return MakeMatcher(
07506         new PairMatcherImpl<PairType>(
07507             first_matcher_, second_matcher_));
07508   }
07509 
07510  private:
07511   const FirstMatcher first_matcher_;
07512   const SecondMatcher second_matcher_;
07513 
07514   GTEST_DISALLOW_ASSIGN_(PairMatcher);
07515 };
07516 
07517 // Implements ElementsAre() and ElementsAreArray().
07518 template <typename Container>
07519 class ElementsAreMatcherImpl : public MatcherInterface<Container> {
07520  public:
07521   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
07522   typedef internal::StlContainerView<RawContainer> View;
07523   typedef typename View::type StlContainer;
07524   typedef typename View::const_reference StlContainerReference;
07525   typedef typename StlContainer::value_type Element;
07526 
07527   // Constructs the matcher from a sequence of element values or
07528   // element matchers.
07529   template <typename InputIter>
07530   ElementsAreMatcherImpl(InputIter first, InputIter last) {
07531     while (first != last) {
07532       matchers_.push_back(MatcherCast<const Element&>(*first++));
07533     }
07534   }
07535 
07536   // Describes what this matcher does.
07537   virtual void DescribeTo(::std::ostream* os) const {
07538     if (count() == 0) {
07539       *os << "is empty";
07540     } else if (count() == 1) {
07541       *os << "has 1 element that ";
07542       matchers_[0].DescribeTo(os);
07543     } else {
07544       *os << "has " << Elements(count()) << " where\n";
07545       for (size_t i = 0; i != count(); ++i) {
07546         *os << "element #" << i << " ";
07547         matchers_[i].DescribeTo(os);
07548         if (i + 1 < count()) {
07549           *os << ",\n";
07550         }
07551       }
07552     }
07553   }
07554 
07555   // Describes what the negation of this matcher does.
07556   virtual void DescribeNegationTo(::std::ostream* os) const {
07557     if (count() == 0) {
07558       *os << "isn't empty";
07559       return;
07560     }
07561 
07562     *os << "doesn't have " << Elements(count()) << ", or\n";
07563     for (size_t i = 0; i != count(); ++i) {
07564       *os << "element #" << i << " ";
07565       matchers_[i].DescribeNegationTo(os);
07566       if (i + 1 < count()) {
07567         *os << ", or\n";
07568       }
07569     }
07570   }
07571 
07572   virtual bool MatchAndExplain(Container container,
07573                                MatchResultListener* listener) const {
07574     // To work with stream-like "containers", we must only walk
07575     // through the elements in one pass.
07576 
07577     const bool listener_interested = listener->IsInterested();
07578 
07579     // explanations[i] is the explanation of the element at index i.
07580     ::std::vector<internal::string> explanations(count());
07581     StlContainerReference stl_container = View::ConstReference(container);
07582     typename StlContainer::const_iterator it = stl_container.begin();
07583     size_t exam_pos = 0;
07584     bool mismatch_found = false;  // Have we found a mismatched element yet?
07585 
07586     // Go through the elements and matchers in pairs, until we reach
07587     // the end of either the elements or the matchers, or until we find a
07588     // mismatch.
07589     for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
07590       bool match;  // Does the current element match the current matcher?
07591       if (listener_interested) {
07592         StringMatchResultListener s;
07593         match = matchers_[exam_pos].MatchAndExplain(*it, &s);
07594         explanations[exam_pos] = s.str();
07595       } else {
07596         match = matchers_[exam_pos].Matches(*it);
07597       }
07598 
07599       if (!match) {
07600         mismatch_found = true;
07601         break;
07602       }
07603     }
07604     // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
07605 
07606     // Find how many elements the actual container has.  We avoid
07607     // calling size() s.t. this code works for stream-like "containers"
07608     // that don't define size().
07609     size_t actual_count = exam_pos;
07610     for (; it != stl_container.end(); ++it) {
07611       ++actual_count;
07612     }
07613 
07614     if (actual_count != count()) {
07615       // The element count doesn't match.  If the container is empty,
07616       // there's no need to explain anything as Google Mock already
07617       // prints the empty container.  Otherwise we just need to show
07618       // how many elements there actually are.
07619       if (listener_interested && (actual_count != 0)) {
07620         *listener << "which has " << Elements(actual_count);
07621       }
07622       return false;
07623     }
07624 
07625     if (mismatch_found) {
07626       // The element count matches, but the exam_pos-th element doesn't match.
07627       if (listener_interested) {
07628         *listener << "whose element #" << exam_pos << " doesn't match";
07629         PrintIfNotEmpty(explanations[exam_pos], listener->stream());
07630       }
07631       return false;
07632     }
07633 
07634     // Every element matches its expectation.  We need to explain why
07635     // (the obvious ones can be skipped).
07636     if (listener_interested) {
07637       bool reason_printed = false;
07638       for (size_t i = 0; i != count(); ++i) {
07639         const internal::string& s = explanations[i];
07640         if (!s.empty()) {
07641           if (reason_printed) {
07642             *listener << ",\nand ";
07643           }
07644           *listener << "whose element #" << i << " matches, " << s;
07645           reason_printed = true;
07646         }
07647       }
07648     }
07649     return true;
07650   }
07651 
07652  private:
07653   static Message Elements(size_t count) {
07654     return Message() << count << (count == 1 ? " element" : " elements");
07655   }
07656 
07657   size_t count() const { return matchers_.size(); }
07658 
07659   ::std::vector<Matcher<const Element&> > matchers_;
07660 
07661   GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
07662 };
07663 
07664 // Connectivity matrix of (elements X matchers), in element-major order.
07665 // Initially, there are no edges.
07666 // Use NextGraph() to iterate over all possible edge configurations.
07667 // Use Randomize() to generate a random edge configuration.
07668 class GTEST_API_ MatchMatrix {
07669  public:
07670   MatchMatrix(size_t num_elements, size_t num_matchers)
07671       : num_elements_(num_elements),
07672         num_matchers_(num_matchers),
07673         matched_(num_elements_* num_matchers_, 0) {
07674   }
07675 
07676   size_t LhsSize() const { return num_elements_; }
07677   size_t RhsSize() const { return num_matchers_; }
07678   bool HasEdge(size_t ilhs, size_t irhs) const {
07679     return matched_[SpaceIndex(ilhs, irhs)] == 1;
07680   }
07681   void SetEdge(size_t ilhs, size_t irhs, bool b) {
07682     matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
07683   }
07684 
07685   // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
07686   // adds 1 to that number; returns false if incrementing the graph left it
07687   // empty.
07688   bool NextGraph();
07689 
07690   void Randomize();
07691 
07692   string DebugString() const;
07693 
07694  private:
07695   size_t SpaceIndex(size_t ilhs, size_t irhs) const {
07696     return ilhs * num_matchers_ + irhs;
07697   }
07698 
07699   size_t num_elements_;
07700   size_t num_matchers_;
07701 
07702   // Each element is a char interpreted as bool. They are stored as a
07703   // flattened array in lhs-major order, use 'SpaceIndex()' to translate
07704   // a (ilhs, irhs) matrix coordinate into an offset.
07705   ::std::vector<char> matched_;
07706 };
07707 
07708 typedef ::std::pair<size_t, size_t> ElementMatcherPair;
07709 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
07710 
07711 // Returns a maximum bipartite matching for the specified graph 'g'.
07712 // The matching is represented as a vector of {element, matcher} pairs.
07713 GTEST_API_ ElementMatcherPairs
07714 FindMaxBipartiteMatching(const MatchMatrix& g);
07715 
07716 GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
07717                             MatchResultListener* listener);
07718 
07719 // Untyped base class for implementing UnorderedElementsAre.  By
07720 // putting logic that's not specific to the element type here, we
07721 // reduce binary bloat and increase compilation speed.
07722 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
07723  protected:
07724   // A vector of matcher describers, one for each element matcher.
07725   // Does not own the describers (and thus can be used only when the
07726   // element matchers are alive).
07727   typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
07728 
07729   // Describes this UnorderedElementsAre matcher.
07730   void DescribeToImpl(::std::ostream* os) const;
07731 
07732   // Describes the negation of this UnorderedElementsAre matcher.
07733   void DescribeNegationToImpl(::std::ostream* os) const;
07734 
07735   bool VerifyAllElementsAndMatchersAreMatched(
07736       const ::std::vector<string>& element_printouts,
07737       const MatchMatrix& matrix,
07738       MatchResultListener* listener) const;
07739 
07740   MatcherDescriberVec& matcher_describers() {
07741     return matcher_describers_;
07742   }
07743 
07744   static Message Elements(size_t n) {
07745     return Message() << n << " element" << (n == 1 ? "" : "s");
07746   }
07747 
07748  private:
07749   MatcherDescriberVec matcher_describers_;
07750 
07751   GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
07752 };
07753 
07754 // Implements unordered ElementsAre and unordered ElementsAreArray.
07755 template <typename Container>
07756 class UnorderedElementsAreMatcherImpl
07757     : public MatcherInterface<Container>,
07758       public UnorderedElementsAreMatcherImplBase {
07759  public:
07760   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
07761   typedef internal::StlContainerView<RawContainer> View;
07762   typedef typename View::type StlContainer;
07763   typedef typename View::const_reference StlContainerReference;
07764   typedef typename StlContainer::const_iterator StlContainerConstIterator;
07765   typedef typename StlContainer::value_type Element;
07766 
07767   // Constructs the matcher from a sequence of element values or
07768   // element matchers.
07769   template <typename InputIter>
07770   UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
07771     for (; first != last; ++first) {
07772       matchers_.push_back(MatcherCast<const Element&>(*first));
07773       matcher_describers().push_back(matchers_.back().GetDescriber());
07774     }
07775   }
07776 
07777   // Describes what this matcher does.
07778   virtual void DescribeTo(::std::ostream* os) const {
07779     return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
07780   }
07781 
07782   // Describes what the negation of this matcher does.
07783   virtual void DescribeNegationTo(::std::ostream* os) const {
07784     return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
07785   }
07786 
07787   virtual bool MatchAndExplain(Container container,
07788                                MatchResultListener* listener) const {
07789     StlContainerReference stl_container = View::ConstReference(container);
07790     ::std::vector<string> element_printouts;
07791     MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
07792                                          stl_container.end(),
07793                                          &element_printouts,
07794                                          listener);
07795 
07796     const size_t actual_count = matrix.LhsSize();
07797     if (actual_count == 0 && matchers_.empty()) {
07798       return true;
07799     }
07800     if (actual_count != matchers_.size()) {
07801       // The element count doesn't match.  If the container is empty,
07802       // there's no need to explain anything as Google Mock already
07803       // prints the empty container. Otherwise we just need to show
07804       // how many elements there actually are.
07805       if (actual_count != 0 && listener->IsInterested()) {
07806         *listener << "which has " << Elements(actual_count);
07807       }
07808       return false;
07809     }
07810 
07811     return VerifyAllElementsAndMatchersAreMatched(element_printouts,
07812                                                   matrix, listener) &&
07813            FindPairing(matrix, listener);
07814   }
07815 
07816  private:
07817   typedef ::std::vector<Matcher<const Element&> > MatcherVec;
07818 
07819   template <typename ElementIter>
07820   MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
07821                               ::std::vector<string>* element_printouts,
07822                               MatchResultListener* listener) const {
07823     element_printouts->clear();
07824     ::std::vector<char> did_match;
07825     size_t num_elements = 0;
07826     for (; elem_first != elem_last; ++num_elements, ++elem_first) {
07827       if (listener->IsInterested()) {
07828         element_printouts->push_back(PrintToString(*elem_first));
07829       }
07830       for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
07831         did_match.push_back(Matches(matchers_[irhs])(*elem_first));
07832       }
07833     }
07834 
07835     MatchMatrix matrix(num_elements, matchers_.size());
07836     ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
07837     for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
07838       for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
07839         matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
07840       }
07841     }
07842     return matrix;
07843   }
07844 
07845   MatcherVec matchers_;
07846 
07847   GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
07848 };
07849 
07850 // Functor for use in TransformTuple.
07851 // Performs MatcherCast<Target> on an input argument of any type.
07852 template <typename Target>
07853 struct CastAndAppendTransform {
07854   template <typename Arg>
07855   Matcher<Target> operator()(const Arg& a) const {
07856     return MatcherCast<Target>(a);
07857   }
07858 };
07859 
07860 // Implements UnorderedElementsAre.
07861 template <typename MatcherTuple>
07862 class UnorderedElementsAreMatcher {
07863  public:
07864   explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
07865       : matchers_(args) {}
07866 
07867   template <typename Container>
07868   operator Matcher<Container>() const {
07869     typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
07870     typedef typename internal::StlContainerView<RawContainer>::type View;
07871     typedef typename View::value_type Element;
07872     typedef ::std::vector<Matcher<const Element&> > MatcherVec;
07873     MatcherVec matchers;
07874     matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
07875     TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
07876                          ::std::back_inserter(matchers));
07877     return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
07878                            matchers.begin(), matchers.end()));
07879   }
07880 
07881  private:
07882   const MatcherTuple matchers_;
07883   GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
07884 };
07885 
07886 // Implements ElementsAre.
07887 template <typename MatcherTuple>
07888 class ElementsAreMatcher {
07889  public:
07890   explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
07891 
07892   template <typename Container>
07893   operator Matcher<Container>() const {
07894     typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
07895     typedef typename internal::StlContainerView<RawContainer>::type View;
07896     typedef typename View::value_type Element;
07897     typedef ::std::vector<Matcher<const Element&> > MatcherVec;
07898     MatcherVec matchers;
07899     matchers.reserve(::std::tr1::tuple_size<MatcherTuple>::value);
07900     TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
07901                          ::std::back_inserter(matchers));
07902     return MakeMatcher(new ElementsAreMatcherImpl<Container>(
07903                            matchers.begin(), matchers.end()));
07904   }
07905 
07906  private:
07907   const MatcherTuple matchers_;
07908   GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
07909 };
07910 
07911 // Implements UnorderedElementsAreArray().
07912 template <typename T>
07913 class UnorderedElementsAreArrayMatcher {
07914  public:
07915   UnorderedElementsAreArrayMatcher() {}
07916 
07917   template <typename Iter>
07918   UnorderedElementsAreArrayMatcher(Iter first, Iter last)
07919       : matchers_(first, last) {}
07920 
07921   template <typename Container>
07922   operator Matcher<Container>() const {
07923     return MakeMatcher(
07924         new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
07925                                                        matchers_.end()));
07926   }
07927 
07928  private:
07929   ::std::vector<T> matchers_;
07930 
07931   GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
07932 };
07933 
07934 // Implements ElementsAreArray().
07935 template <typename T>
07936 class ElementsAreArrayMatcher {
07937  public:
07938   template <typename Iter>
07939   ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
07940 
07941   template <typename Container>
07942   operator Matcher<Container>() const {
07943     return MakeMatcher(new ElementsAreMatcherImpl<Container>(
07944         matchers_.begin(), matchers_.end()));
07945   }
07946 
07947  private:
07948   const ::std::vector<T> matchers_;
07949 
07950   GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
07951 };
07952 
07953 // Returns the description for a matcher defined using the MATCHER*()
07954 // macro where the user-supplied description string is "", if
07955 // 'negation' is false; otherwise returns the description of the
07956 // negation of the matcher.  'param_values' contains a list of strings
07957 // that are the print-out of the matcher's parameters.
07958 GTEST_API_ string FormatMatcherDescription(bool negation,
07959                                            const char* matcher_name,
07960                                            const Strings& param_values);
07961 
07962 }  // namespace internal
07963 
07964 // ElementsAreArray(first, last)
07965 // ElementsAreArray(pointer, count)
07966 // ElementsAreArray(array)
07967 // ElementsAreArray(vector)
07968 // ElementsAreArray({ e1, e2, ..., en })
07969 //
07970 // The ElementsAreArray() functions are like ElementsAre(...), except
07971 // that they are given a homogeneous sequence rather than taking each
07972 // element as a function argument. The sequence can be specified as an
07973 // array, a pointer and count, a vector, an initializer list, or an
07974 // STL iterator range. In each of these cases, the underlying sequence
07975 // can be either a sequence of values or a sequence of matchers.
07976 //
07977 // All forms of ElementsAreArray() make a copy of the input matcher sequence.
07978 
07979 template <typename Iter>
07980 inline internal::ElementsAreArrayMatcher<
07981     typename ::std::iterator_traits<Iter>::value_type>
07982 ElementsAreArray(Iter first, Iter last) {
07983   typedef typename ::std::iterator_traits<Iter>::value_type T;
07984   return internal::ElementsAreArrayMatcher<T>(first, last);
07985 }
07986 
07987 template <typename T>
07988 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
07989     const T* pointer, size_t count) {
07990   return ElementsAreArray(pointer, pointer + count);
07991 }
07992 
07993 template <typename T, size_t N>
07994 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
07995     const T (&array)[N]) {
07996   return ElementsAreArray(array, N);
07997 }
07998 
07999 template <typename T, typename A>
08000 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
08001     const ::std::vector<T, A>& vec) {
08002   return ElementsAreArray(vec.begin(), vec.end());
08003 }
08004 
08005 #if GTEST_LANG_CXX11
08006 template <typename T>
08007 inline internal::ElementsAreArrayMatcher<T>
08008 ElementsAreArray(::std::initializer_list<T> xs) {
08009   return ElementsAreArray(xs.begin(), xs.end());
08010 }
08011 #endif
08012 
08013 // UnorderedElementsAreArray(first, last)
08014 // UnorderedElementsAreArray(pointer, count)
08015 // UnorderedElementsAreArray(array)
08016 // UnorderedElementsAreArray(vector)
08017 // UnorderedElementsAreArray({ e1, e2, ..., en })
08018 //
08019 // The UnorderedElementsAreArray() functions are like
08020 // ElementsAreArray(...), but allow matching the elements in any order.
08021 template <typename Iter>
08022 inline internal::UnorderedElementsAreArrayMatcher<
08023     typename ::std::iterator_traits<Iter>::value_type>
08024 UnorderedElementsAreArray(Iter first, Iter last) {
08025   typedef typename ::std::iterator_traits<Iter>::value_type T;
08026   return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
08027 }
08028 
08029 template <typename T>
08030 inline internal::UnorderedElementsAreArrayMatcher<T>
08031 UnorderedElementsAreArray(const T* pointer, size_t count) {
08032   return UnorderedElementsAreArray(pointer, pointer + count);
08033 }
08034 
08035 template <typename T, size_t N>
08036 inline internal::UnorderedElementsAreArrayMatcher<T>
08037 UnorderedElementsAreArray(const T (&array)[N]) {
08038   return UnorderedElementsAreArray(array, N);
08039 }
08040 
08041 template <typename T, typename A>
08042 inline internal::UnorderedElementsAreArrayMatcher<T>
08043 UnorderedElementsAreArray(const ::std::vector<T, A>& vec) {
08044   return UnorderedElementsAreArray(vec.begin(), vec.end());
08045 }
08046 
08047 #if GTEST_LANG_CXX11
08048 template <typename T>
08049 inline internal::UnorderedElementsAreArrayMatcher<T>
08050 UnorderedElementsAreArray(::std::initializer_list<T> xs) {
08051   return UnorderedElementsAreArray(xs.begin(), xs.end());
08052 }
08053 #endif
08054 
08055 // _ is a matcher that matches anything of any type.
08056 //
08057 // This definition is fine as:
08058 //
08059 //   1. The C++ standard permits using the name _ in a namespace that
08060 //      is not the global namespace or ::std.
08061 //   2. The AnythingMatcher class has no data member or constructor,
08062 //      so it's OK to create global variables of this type.
08063 //   3. c-style has approved of using _ in this case.
08064 const internal::AnythingMatcher _ = {};
08065 // Creates a matcher that matches any value of the given type T.
08066 template <typename T>
08067 inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
08068 
08069 // Creates a matcher that matches any value of the given type T.
08070 template <typename T>
08071 inline Matcher<T> An() { return A<T>(); }
08072 
08073 // Creates a polymorphic matcher that matches anything equal to x.
08074 // Note: if the parameter of Eq() were declared as const T&, Eq("foo")
08075 // wouldn't compile.
08076 template <typename T>
08077 inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
08078 
08079 // Constructs a Matcher<T> from a 'value' of type T.  The constructed
08080 // matcher matches any value that's equal to 'value'.
08081 template <typename T>
08082 Matcher<T>::Matcher(T value) { *this = Eq(value); }
08083 
08084 // Creates a monomorphic matcher that matches anything with type Lhs
08085 // and equal to rhs.  A user may need to use this instead of Eq(...)
08086 // in order to resolve an overloading ambiguity.
08087 //
08088 // TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
08089 // or Matcher<T>(x), but more readable than the latter.
08090 //
08091 // We could define similar monomorphic matchers for other comparison
08092 // operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
08093 // it yet as those are used much less than Eq() in practice.  A user
08094 // can always write Matcher<T>(Lt(5)) to be explicit about the type,
08095 // for example.
08096 template <typename Lhs, typename Rhs>
08097 inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
08098 
08099 // Creates a polymorphic matcher that matches anything >= x.
08100 template <typename Rhs>
08101 inline internal::GeMatcher<Rhs> Ge(Rhs x) {
08102   return internal::GeMatcher<Rhs>(x);
08103 }
08104 
08105 // Creates a polymorphic matcher that matches anything > x.
08106 template <typename Rhs>
08107 inline internal::GtMatcher<Rhs> Gt(Rhs x) {
08108   return internal::GtMatcher<Rhs>(x);
08109 }
08110 
08111 // Creates a polymorphic matcher that matches anything <= x.
08112 template <typename Rhs>
08113 inline internal::LeMatcher<Rhs> Le(Rhs x) {
08114   return internal::LeMatcher<Rhs>(x);
08115 }
08116 
08117 // Creates a polymorphic matcher that matches anything < x.
08118 template <typename Rhs>
08119 inline internal::LtMatcher<Rhs> Lt(Rhs x) {
08120   return internal::LtMatcher<Rhs>(x);
08121 }
08122 
08123 // Creates a polymorphic matcher that matches anything != x.
08124 template <typename Rhs>
08125 inline internal::NeMatcher<Rhs> Ne(Rhs x) {
08126   return internal::NeMatcher<Rhs>(x);
08127 }
08128 
08129 // Creates a polymorphic matcher that matches any NULL pointer.
08130 inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
08131   return MakePolymorphicMatcher(internal::IsNullMatcher());
08132 }
08133 
08134 // Creates a polymorphic matcher that matches any non-NULL pointer.
08135 // This is convenient as Not(NULL) doesn't compile (the compiler
08136 // thinks that that expression is comparing a pointer with an integer).
08137 inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
08138   return MakePolymorphicMatcher(internal::NotNullMatcher());
08139 }
08140 
08141 // Creates a polymorphic matcher that matches any argument that
08142 // references variable x.
08143 template <typename T>
08144 inline internal::RefMatcher<T&> Ref(T& x) {  // NOLINT
08145   return internal::RefMatcher<T&>(x);
08146 }
08147 
08148 // Creates a matcher that matches any double argument approximately
08149 // equal to rhs, where two NANs are considered unequal.
08150 inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
08151   return internal::FloatingEqMatcher<double>(rhs, false);
08152 }
08153 
08154 // Creates a matcher that matches any double argument approximately
08155 // equal to rhs, including NaN values when rhs is NaN.
08156 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
08157   return internal::FloatingEqMatcher<double>(rhs, true);
08158 }
08159 
08160 // Creates a matcher that matches any double argument approximately equal to
08161 // rhs, up to the specified max absolute error bound, where two NANs are
08162 // considered unequal.  The max absolute error bound must be non-negative.
08163 inline internal::FloatingEqMatcher<double> DoubleNear(
08164     double rhs, double max_abs_error) {
08165   return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
08166 }
08167 
08168 // Creates a matcher that matches any double argument approximately equal to
08169 // rhs, up to the specified max absolute error bound, including NaN values when
08170 // rhs is NaN.  The max absolute error bound must be non-negative.
08171 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
08172     double rhs, double max_abs_error) {
08173   return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
08174 }
08175 
08176 // Creates a matcher that matches any float argument approximately
08177 // equal to rhs, where two NANs are considered unequal.
08178 inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
08179   return internal::FloatingEqMatcher<float>(rhs, false);
08180 }
08181 
08182 // Creates a matcher that matches any float argument approximately
08183 // equal to rhs, including NaN values when rhs is NaN.
08184 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
08185   return internal::FloatingEqMatcher<float>(rhs, true);
08186 }
08187 
08188 // Creates a matcher that matches any float argument approximately equal to
08189 // rhs, up to the specified max absolute error bound, where two NANs are
08190 // considered unequal.  The max absolute error bound must be non-negative.
08191 inline internal::FloatingEqMatcher<float> FloatNear(
08192     float rhs, float max_abs_error) {
08193   return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
08194 }
08195 
08196 // Creates a matcher that matches any float argument approximately equal to
08197 // rhs, up to the specified max absolute error bound, including NaN values when
08198 // rhs is NaN.  The max absolute error bound must be non-negative.
08199 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
08200     float rhs, float max_abs_error) {
08201   return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
08202 }
08203 
08204 // Creates a matcher that matches a pointer (raw or smart) that points
08205 // to a value that matches inner_matcher.
08206 template <typename InnerMatcher>
08207 inline internal::PointeeMatcher<InnerMatcher> Pointee(
08208     const InnerMatcher& inner_matcher) {
08209   return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
08210 }
08211 
08212 // Creates a matcher that matches an object whose given field matches
08213 // 'matcher'.  For example,
08214 //   Field(&Foo::number, Ge(5))
08215 // matches a Foo object x iff x.number >= 5.
08216 template <typename Class, typename FieldType, typename FieldMatcher>
08217 inline PolymorphicMatcher<
08218   internal::FieldMatcher<Class, FieldType> > Field(
08219     FieldType Class::*field, const FieldMatcher& matcher) {
08220   return MakePolymorphicMatcher(
08221       internal::FieldMatcher<Class, FieldType>(
08222           field, MatcherCast<const FieldType&>(matcher)));
08223   // The call to MatcherCast() is required for supporting inner
08224   // matchers of compatible types.  For example, it allows
08225   //   Field(&Foo::bar, m)
08226   // to compile where bar is an int32 and m is a matcher for int64.
08227 }
08228 
08229 // Creates a matcher that matches an object whose given property
08230 // matches 'matcher'.  For example,
08231 //   Property(&Foo::str, StartsWith("hi"))
08232 // matches a Foo object x iff x.str() starts with "hi".
08233 template <typename Class, typename PropertyType, typename PropertyMatcher>
08234 inline PolymorphicMatcher<
08235   internal::PropertyMatcher<Class, PropertyType> > Property(
08236     PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
08237   return MakePolymorphicMatcher(
08238       internal::PropertyMatcher<Class, PropertyType>(
08239           property,
08240           MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
08241   // The call to MatcherCast() is required for supporting inner
08242   // matchers of compatible types.  For example, it allows
08243   //   Property(&Foo::bar, m)
08244   // to compile where bar() returns an int32 and m is a matcher for int64.
08245 }
08246 
08247 // Creates a matcher that matches an object iff the result of applying
08248 // a callable to x matches 'matcher'.
08249 // For example,
08250 //   ResultOf(f, StartsWith("hi"))
08251 // matches a Foo object x iff f(x) starts with "hi".
08252 // callable parameter can be a function, function pointer, or a functor.
08253 // Callable has to satisfy the following conditions:
08254 //   * It is required to keep no state affecting the results of
08255 //     the calls on it and make no assumptions about how many calls
08256 //     will be made. Any state it keeps must be protected from the
08257 //     concurrent access.
08258 //   * If it is a function object, it has to define type result_type.
08259 //     We recommend deriving your functor classes from std::unary_function.
08260 template <typename Callable, typename ResultOfMatcher>
08261 internal::ResultOfMatcher<Callable> ResultOf(
08262     Callable callable, const ResultOfMatcher& matcher) {
08263   return internal::ResultOfMatcher<Callable>(
08264           callable,
08265           MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
08266               matcher));
08267   // The call to MatcherCast() is required for supporting inner
08268   // matchers of compatible types.  For example, it allows
08269   //   ResultOf(Function, m)
08270   // to compile where Function() returns an int32 and m is a matcher for int64.
08271 }
08272 
08273 // String matchers.
08274 
08275 // Matches a string equal to str.
08276 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
08277     StrEq(const internal::string& str) {
08278   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
08279       str, true, true));
08280 }
08281 
08282 // Matches a string not equal to str.
08283 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
08284     StrNe(const internal::string& str) {
08285   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
08286       str, false, true));
08287 }
08288 
08289 // Matches a string equal to str, ignoring case.
08290 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
08291     StrCaseEq(const internal::string& str) {
08292   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
08293       str, true, false));
08294 }
08295 
08296 // Matches a string not equal to str, ignoring case.
08297 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
08298     StrCaseNe(const internal::string& str) {
08299   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
08300       str, false, false));
08301 }
08302 
08303 // Creates a matcher that matches any string, std::string, or C string
08304 // that contains the given substring.
08305 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
08306     HasSubstr(const internal::string& substring) {
08307   return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
08308       substring));
08309 }
08310 
08311 // Matches a string that starts with 'prefix' (case-sensitive).
08312 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
08313     StartsWith(const internal::string& prefix) {
08314   return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
08315       prefix));
08316 }
08317 
08318 // Matches a string that ends with 'suffix' (case-sensitive).
08319 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
08320     EndsWith(const internal::string& suffix) {
08321   return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
08322       suffix));
08323 }
08324 
08325 // Matches a string that fully matches regular expression 'regex'.
08326 // The matcher takes ownership of 'regex'.
08327 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
08328     const internal::RE* regex) {
08329   return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
08330 }
08331 inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
08332     const internal::string& regex) {
08333   return MatchesRegex(new internal::RE(regex));
08334 }
08335 
08336 // Matches a string that contains regular expression 'regex'.
08337 // The matcher takes ownership of 'regex'.
08338 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
08339     const internal::RE* regex) {
08340   return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
08341 }
08342 inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
08343     const internal::string& regex) {
08344   return ContainsRegex(new internal::RE(regex));
08345 }
08346 
08347 #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
08348 // Wide string matchers.
08349 
08350 // Matches a string equal to str.
08351 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
08352     StrEq(const internal::wstring& str) {
08353   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
08354       str, true, true));
08355 }
08356 
08357 // Matches a string not equal to str.
08358 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
08359     StrNe(const internal::wstring& str) {
08360   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
08361       str, false, true));
08362 }
08363 
08364 // Matches a string equal to str, ignoring case.
08365 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
08366     StrCaseEq(const internal::wstring& str) {
08367   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
08368       str, true, false));
08369 }
08370 
08371 // Matches a string not equal to str, ignoring case.
08372 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
08373     StrCaseNe(const internal::wstring& str) {
08374   return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
08375       str, false, false));
08376 }
08377 
08378 // Creates a matcher that matches any wstring, std::wstring, or C wide string
08379 // that contains the given substring.
08380 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
08381     HasSubstr(const internal::wstring& substring) {
08382   return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
08383       substring));
08384 }
08385 
08386 // Matches a string that starts with 'prefix' (case-sensitive).
08387 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
08388     StartsWith(const internal::wstring& prefix) {
08389   return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
08390       prefix));
08391 }
08392 
08393 // Matches a string that ends with 'suffix' (case-sensitive).
08394 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
08395     EndsWith(const internal::wstring& suffix) {
08396   return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
08397       suffix));
08398 }
08399 
08400 #endif  // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
08401 
08402 // Creates a polymorphic matcher that matches a 2-tuple where the
08403 // first field == the second field.
08404 inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
08405 
08406 // Creates a polymorphic matcher that matches a 2-tuple where the
08407 // first field >= the second field.
08408 inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
08409 
08410 // Creates a polymorphic matcher that matches a 2-tuple where the
08411 // first field > the second field.
08412 inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
08413 
08414 // Creates a polymorphic matcher that matches a 2-tuple where the
08415 // first field <= the second field.
08416 inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
08417 
08418 // Creates a polymorphic matcher that matches a 2-tuple where the
08419 // first field < the second field.
08420 inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
08421 
08422 // Creates a polymorphic matcher that matches a 2-tuple where the
08423 // first field != the second field.
08424 inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
08425 
08426 // Creates a matcher that matches any value of type T that m doesn't
08427 // match.
08428 template <typename InnerMatcher>
08429 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
08430   return internal::NotMatcher<InnerMatcher>(m);
08431 }
08432 
08433 // Returns a matcher that matches anything that satisfies the given
08434 // predicate.  The predicate can be any unary function or functor
08435 // whose return type can be implicitly converted to bool.
08436 template <typename Predicate>
08437 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
08438 Truly(Predicate pred) {
08439   return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
08440 }
08441 
08442 // Returns a matcher that matches the container size. The container must
08443 // support both size() and size_type which all STL-like containers provide.
08444 // Note that the parameter 'size' can be a value of type size_type as well as
08445 // matcher. For instance:
08446 //   EXPECT_THAT(container, SizeIs(2));     // Checks container has 2 elements.
08447 //   EXPECT_THAT(container, SizeIs(Le(2));  // Checks container has at most 2.
08448 template <typename SizeMatcher>
08449 inline internal::SizeIsMatcher<SizeMatcher>
08450 SizeIs(const SizeMatcher& size_matcher) {
08451   return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
08452 }
08453 
08454 // Returns a matcher that matches an equal container.
08455 // This matcher behaves like Eq(), but in the event of mismatch lists the
08456 // values that are included in one container but not the other. (Duplicate
08457 // values and order differences are not explained.)
08458 template <typename Container>
08459 inline PolymorphicMatcher<internal::ContainerEqMatcher<  // NOLINT
08460                             GTEST_REMOVE_CONST_(Container)> >
08461     ContainerEq(const Container& rhs) {
08462   // This following line is for working around a bug in MSVC 8.0,
08463   // which causes Container to be a const type sometimes.
08464   typedef GTEST_REMOVE_CONST_(Container) RawContainer;
08465   return MakePolymorphicMatcher(
08466       internal::ContainerEqMatcher<RawContainer>(rhs));
08467 }
08468 
08469 // Returns a matcher that matches a container that, when sorted using
08470 // the given comparator, matches container_matcher.
08471 template <typename Comparator, typename ContainerMatcher>
08472 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
08473 WhenSortedBy(const Comparator& comparator,
08474              const ContainerMatcher& container_matcher) {
08475   return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
08476       comparator, container_matcher);
08477 }
08478 
08479 // Returns a matcher that matches a container that, when sorted using
08480 // the < operator, matches container_matcher.
08481 template <typename ContainerMatcher>
08482 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
08483 WhenSorted(const ContainerMatcher& container_matcher) {
08484   return
08485       internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
08486           internal::LessComparator(), container_matcher);
08487 }
08488 
08489 // Matches an STL-style container or a native array that contains the
08490 // same number of elements as in rhs, where its i-th element and rhs's
08491 // i-th element (as a pair) satisfy the given pair matcher, for all i.
08492 // TupleMatcher must be able to be safely cast to Matcher<tuple<const
08493 // T1&, const T2&> >, where T1 and T2 are the types of elements in the
08494 // LHS container and the RHS container respectively.
08495 template <typename TupleMatcher, typename Container>
08496 inline internal::PointwiseMatcher<TupleMatcher,
08497                                   GTEST_REMOVE_CONST_(Container)>
08498 Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
08499   // This following line is for working around a bug in MSVC 8.0,
08500   // which causes Container to be a const type sometimes.
08501   typedef GTEST_REMOVE_CONST_(Container) RawContainer;
08502   return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
08503       tuple_matcher, rhs);
08504 }
08505 
08506 // Matches an STL-style container or a native array that contains at
08507 // least one element matching the given value or matcher.
08508 //
08509 // Examples:
08510 //   ::std::set<int> page_ids;
08511 //   page_ids.insert(3);
08512 //   page_ids.insert(1);
08513 //   EXPECT_THAT(page_ids, Contains(1));
08514 //   EXPECT_THAT(page_ids, Contains(Gt(2)));
08515 //   EXPECT_THAT(page_ids, Not(Contains(4)));
08516 //
08517 //   ::std::map<int, size_t> page_lengths;
08518 //   page_lengths[1] = 100;
08519 //   EXPECT_THAT(page_lengths,
08520 //               Contains(::std::pair<const int, size_t>(1, 100)));
08521 //
08522 //   const char* user_ids[] = { "joe", "mike", "tom" };
08523 //   EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
08524 template <typename M>
08525 inline internal::ContainsMatcher<M> Contains(M matcher) {
08526   return internal::ContainsMatcher<M>(matcher);
08527 }
08528 
08529 // Matches an STL-style container or a native array that contains only
08530 // elements matching the given value or matcher.
08531 //
08532 // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
08533 // the messages are different.
08534 //
08535 // Examples:
08536 //   ::std::set<int> page_ids;
08537 //   // Each(m) matches an empty container, regardless of what m is.
08538 //   EXPECT_THAT(page_ids, Each(Eq(1)));
08539 //   EXPECT_THAT(page_ids, Each(Eq(77)));
08540 //
08541 //   page_ids.insert(3);
08542 //   EXPECT_THAT(page_ids, Each(Gt(0)));
08543 //   EXPECT_THAT(page_ids, Not(Each(Gt(4))));
08544 //   page_ids.insert(1);
08545 //   EXPECT_THAT(page_ids, Not(Each(Lt(2))));
08546 //
08547 //   ::std::map<int, size_t> page_lengths;
08548 //   page_lengths[1] = 100;
08549 //   page_lengths[2] = 200;
08550 //   page_lengths[3] = 300;
08551 //   EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
08552 //   EXPECT_THAT(page_lengths, Each(Key(Le(3))));
08553 //
08554 //   const char* user_ids[] = { "joe", "mike", "tom" };
08555 //   EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
08556 template <typename M>
08557 inline internal::EachMatcher<M> Each(M matcher) {
08558   return internal::EachMatcher<M>(matcher);
08559 }
08560 
08561 // Key(inner_matcher) matches an std::pair whose 'first' field matches
08562 // inner_matcher.  For example, Contains(Key(Ge(5))) can be used to match an
08563 // std::map that contains at least one element whose key is >= 5.
08564 template <typename M>
08565 inline internal::KeyMatcher<M> Key(M inner_matcher) {
08566   return internal::KeyMatcher<M>(inner_matcher);
08567 }
08568 
08569 // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
08570 // matches first_matcher and whose 'second' field matches second_matcher.  For
08571 // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
08572 // to match a std::map<int, string> that contains exactly one element whose key
08573 // is >= 5 and whose value equals "foo".
08574 template <typename FirstMatcher, typename SecondMatcher>
08575 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
08576 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
08577   return internal::PairMatcher<FirstMatcher, SecondMatcher>(
08578       first_matcher, second_matcher);
08579 }
08580 
08581 // Returns a predicate that is satisfied by anything that matches the
08582 // given matcher.
08583 template <typename M>
08584 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
08585   return internal::MatcherAsPredicate<M>(matcher);
08586 }
08587 
08588 // Returns true iff the value matches the matcher.
08589 template <typename T, typename M>
08590 inline bool Value(const T& value, M matcher) {
08591   return testing::Matches(matcher)(value);
08592 }
08593 
08594 // Matches the value against the given matcher and explains the match
08595 // result to listener.
08596 template <typename T, typename M>
08597 inline bool ExplainMatchResult(
08598     M matcher, const T& value, MatchResultListener* listener) {
08599   return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
08600 }
08601 
08602 #if GTEST_LANG_CXX11
08603 // Define variadic matcher versions. They are overloaded in
08604 // gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
08605 template <typename... Args>
08606 inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
08607   return internal::AllOfMatcher<Args...>(matchers...);
08608 }
08609 
08610 template <typename... Args>
08611 inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
08612   return internal::AnyOfMatcher<Args...>(matchers...);
08613 }
08614 
08615 #endif  // GTEST_LANG_CXX11
08616 
08617 // AllArgs(m) is a synonym of m.  This is useful in
08618 //
08619 //   EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
08620 //
08621 // which is easier to read than
08622 //
08623 //   EXPECT_CALL(foo, Bar(_, _)).With(Eq());
08624 template <typename InnerMatcher>
08625 inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
08626 
08627 // These macros allow using matchers to check values in Google Test
08628 // tests.  ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
08629 // succeed iff the value matches the matcher.  If the assertion fails,
08630 // the value and the description of the matcher will be printed.
08631 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
08632     ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
08633 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
08634     ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
08635 
08636 }  // namespace testing
08637 
08638 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
08639 
08640 namespace testing {
08641 
08642 // An abstract handle of an expectation.
08643 class Expectation;
08644 
08645 // A set of expectation handles.
08646 class ExpectationSet;
08647 
08648 // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
08649 // and MUST NOT BE USED IN USER CODE!!!
08650 namespace internal {
08651 
08652 // Implements a mock function.
08653 template <typename F> class FunctionMocker;
08654 
08655 // Base class for expectations.
08656 class ExpectationBase;
08657 
08658 // Implements an expectation.
08659 template <typename F> class TypedExpectation;
08660 
08661 // Helper class for testing the Expectation class template.
08662 class ExpectationTester;
08663 
08664 // Base class for function mockers.
08665 template <typename F> class FunctionMockerBase;
08666 
08667 // Protects the mock object registry (in class Mock), all function
08668 // mockers, and all expectations.
08669 //
08670 // The reason we don't use more fine-grained protection is: when a
08671 // mock function Foo() is called, it needs to consult its expectations
08672 // to see which one should be picked.  If another thread is allowed to
08673 // call a mock function (either Foo() or a different one) at the same
08674 // time, it could affect the "retired" attributes of Foo()'s
08675 // expectations when InSequence() is used, and thus affect which
08676 // expectation gets picked.  Therefore, we sequence all mock function
08677 // calls to ensure the integrity of the mock objects' states.
08678 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
08679 
08680 // Untyped base class for ActionResultHolder<R>.
08681 class UntypedActionResultHolderBase;
08682 
08683 // Abstract base class of FunctionMockerBase.  This is the
08684 // type-agnostic part of the function mocker interface.  Its pure
08685 // virtual methods are implemented by FunctionMockerBase.
08686 class GTEST_API_ UntypedFunctionMockerBase {
08687  public:
08688   UntypedFunctionMockerBase();
08689   virtual ~UntypedFunctionMockerBase();
08690 
08691   // Verifies that all expectations on this mock function have been
08692   // satisfied.  Reports one or more Google Test non-fatal failures
08693   // and returns false if not.
08694   bool VerifyAndClearExpectationsLocked()
08695       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
08696 
08697   // Clears the ON_CALL()s set on this mock function.
08698   virtual void ClearDefaultActionsLocked()
08699       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
08700 
08701   // In all of the following Untyped* functions, it's the caller's
08702   // responsibility to guarantee the correctness of the arguments'
08703   // types.
08704 
08705   // Performs the default action with the given arguments and returns
08706   // the action's result.  The call description string will be used in
08707   // the error message to describe the call in the case the default
08708   // action fails.
08709   // L = *
08710   virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
08711       const void* untyped_args,
08712       const string& call_description) const = 0;
08713 
08714   // Performs the given action with the given arguments and returns
08715   // the action's result.
08716   // L = *
08717   virtual UntypedActionResultHolderBase* UntypedPerformAction(
08718       const void* untyped_action,
08719       const void* untyped_args) const = 0;
08720 
08721   // Writes a message that the call is uninteresting (i.e. neither
08722   // explicitly expected nor explicitly unexpected) to the given
08723   // ostream.
08724   virtual void UntypedDescribeUninterestingCall(
08725       const void* untyped_args,
08726       ::std::ostream* os) const
08727           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
08728 
08729   // Returns the expectation that matches the given function arguments
08730   // (or NULL is there's no match); when a match is found,
08731   // untyped_action is set to point to the action that should be
08732   // performed (or NULL if the action is "do default"), and
08733   // is_excessive is modified to indicate whether the call exceeds the
08734   // expected number.
08735   virtual const ExpectationBase* UntypedFindMatchingExpectation(
08736       const void* untyped_args,
08737       const void** untyped_action, bool* is_excessive,
08738       ::std::ostream* what, ::std::ostream* why)
08739           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
08740 
08741   // Prints the given function arguments to the ostream.
08742   virtual void UntypedPrintArgs(const void* untyped_args,
08743                                 ::std::ostream* os) const = 0;
08744 
08745   // Sets the mock object this mock method belongs to, and registers
08746   // this information in the global mock registry.  Will be called
08747   // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
08748   // method.
08749   // TODO(wan@google.com): rename to SetAndRegisterOwner().
08750   void RegisterOwner(const void* mock_obj)
08751       GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
08752 
08753   // Sets the mock object this mock method belongs to, and sets the
08754   // name of the mock function.  Will be called upon each invocation
08755   // of this mock function.
08756   void SetOwnerAndName(const void* mock_obj, const char* name)
08757       GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
08758 
08759   // Returns the mock object this mock method belongs to.  Must be
08760   // called after RegisterOwner() or SetOwnerAndName() has been
08761   // called.
08762   const void* MockObject() const
08763       GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
08764 
08765   // Returns the name of this mock method.  Must be called after
08766   // SetOwnerAndName() has been called.
08767   const char* Name() const
08768       GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
08769 
08770   // Returns the result of invoking this mock function with the given
08771   // arguments.  This function can be safely called from multiple
08772   // threads concurrently.  The caller is responsible for deleting the
08773   // result.
08774   const UntypedActionResultHolderBase* UntypedInvokeWith(
08775       const void* untyped_args)
08776           GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
08777 
08778  protected:
08779   typedef std::vector<const void*> UntypedOnCallSpecs;
08780 
08781   typedef std::vector<internal::linked_ptr<ExpectationBase> >
08782   UntypedExpectations;
08783 
08784   // Returns an Expectation object that references and co-owns exp,
08785   // which must be an expectation on this mock function.
08786   Expectation GetHandleOf(ExpectationBase* exp);
08787 
08788   // Address of the mock object this mock method belongs to.  Only
08789   // valid after this mock method has been called or
08790   // ON_CALL/EXPECT_CALL has been invoked on it.
08791   const void* mock_obj_;  // Protected by g_gmock_mutex.
08792 
08793   // Name of the function being mocked.  Only valid after this mock
08794   // method has been called.
08795   const char* name_;  // Protected by g_gmock_mutex.
08796 
08797   // All default action specs for this function mocker.
08798   UntypedOnCallSpecs untyped_on_call_specs_;
08799 
08800   // All expectations for this function mocker.
08801   UntypedExpectations untyped_expectations_;
08802 };  // class UntypedFunctionMockerBase
08803 
08804 // Untyped base class for OnCallSpec<F>.
08805 class UntypedOnCallSpecBase {
08806  public:
08807   // The arguments are the location of the ON_CALL() statement.
08808   UntypedOnCallSpecBase(const char* a_file, int a_line)
08809       : file_(a_file), line_(a_line), last_clause_(kNone) {}
08810 
08811   // Where in the source file was the default action spec defined?
08812   const char* file() const { return file_; }
08813   int line() const { return line_; }
08814 
08815  protected:
08816   // Gives each clause in the ON_CALL() statement a name.
08817   enum Clause {
08818     // Do not change the order of the enum members!  The run-time
08819     // syntax checking relies on it.
08820     kNone,
08821     kWith,
08822     kWillByDefault
08823   };
08824 
08825   // Asserts that the ON_CALL() statement has a certain property.
08826   void AssertSpecProperty(bool property, const string& failure_message) const {
08827     Assert(property, file_, line_, failure_message);
08828   }
08829 
08830   // Expects that the ON_CALL() statement has a certain property.
08831   void ExpectSpecProperty(bool property, const string& failure_message) const {
08832     Expect(property, file_, line_, failure_message);
08833   }
08834 
08835   const char* file_;
08836   int line_;
08837 
08838   // The last clause in the ON_CALL() statement as seen so far.
08839   // Initially kNone and changes as the statement is parsed.
08840   Clause last_clause_;
08841 };  // class UntypedOnCallSpecBase
08842 
08843 // This template class implements an ON_CALL spec.
08844 template <typename F>
08845 class OnCallSpec : public UntypedOnCallSpecBase {
08846  public:
08847   typedef typename Function<F>::ArgumentTuple ArgumentTuple;
08848   typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
08849 
08850   // Constructs an OnCallSpec object from the information inside
08851   // the parenthesis of an ON_CALL() statement.
08852   OnCallSpec(const char* a_file, int a_line,
08853              const ArgumentMatcherTuple& matchers)
08854       : UntypedOnCallSpecBase(a_file, a_line),
08855         matchers_(matchers),
08856         // By default, extra_matcher_ should match anything.  However,
08857         // we cannot initialize it with _ as that triggers a compiler
08858         // bug in Symbian's C++ compiler (cannot decide between two
08859         // overloaded constructors of Matcher<const ArgumentTuple&>).
08860         extra_matcher_(A<const ArgumentTuple&>()) {
08861   }
08862 
08863   // Implements the .With() clause.
08864   OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
08865     // Makes sure this is called at most once.
08866     ExpectSpecProperty(last_clause_ < kWith,
08867                        ".With() cannot appear "
08868                        "more than once in an ON_CALL().");
08869     last_clause_ = kWith;
08870 
08871     extra_matcher_ = m;
08872     return *this;
08873   }
08874 
08875   // Implements the .WillByDefault() clause.
08876   OnCallSpec& WillByDefault(const Action<F>& action) {
08877     ExpectSpecProperty(last_clause_ < kWillByDefault,
08878                        ".WillByDefault() must appear "
08879                        "exactly once in an ON_CALL().");
08880     last_clause_ = kWillByDefault;
08881 
08882     ExpectSpecProperty(!action.IsDoDefault(),
08883                        "DoDefault() cannot be used in ON_CALL().");
08884     action_ = action;
08885     return *this;
08886   }
08887 
08888   // Returns true iff the given arguments match the matchers.
08889   bool Matches(const ArgumentTuple& args) const {
08890     return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
08891   }
08892 
08893   // Returns the action specified by the user.
08894   const Action<F>& GetAction() const {
08895     AssertSpecProperty(last_clause_ == kWillByDefault,
08896                        ".WillByDefault() must appear exactly "
08897                        "once in an ON_CALL().");
08898     return action_;
08899   }
08900 
08901  private:
08902   // The information in statement
08903   //
08904   //   ON_CALL(mock_object, Method(matchers))
08905   //       .With(multi-argument-matcher)
08906   //       .WillByDefault(action);
08907   //
08908   // is recorded in the data members like this:
08909   //
08910   //   source file that contains the statement => file_
08911   //   line number of the statement            => line_
08912   //   matchers                                => matchers_
08913   //   multi-argument-matcher                  => extra_matcher_
08914   //   action                                  => action_
08915   ArgumentMatcherTuple matchers_;
08916   Matcher<const ArgumentTuple&> extra_matcher_;
08917   Action<F> action_;
08918 };  // class OnCallSpec
08919 
08920 // Possible reactions on uninteresting calls.
08921 enum CallReaction {
08922   kAllow,
08923   kWarn,
08924   kFail,
08925   kDefault = kWarn  // By default, warn about uninteresting calls.
08926 };
08927 
08928 }  // namespace internal
08929 
08930 // Utilities for manipulating mock objects.
08931 class GTEST_API_ Mock {
08932  public:
08933   // The following public methods can be called concurrently.
08934 
08935   // Tells Google Mock to ignore mock_obj when checking for leaked
08936   // mock objects.
08937   static void AllowLeak(const void* mock_obj)
08938       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08939 
08940   // Verifies and clears all expectations on the given mock object.
08941   // If the expectations aren't satisfied, generates one or more
08942   // Google Test non-fatal failures and returns false.
08943   static bool VerifyAndClearExpectations(void* mock_obj)
08944       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08945 
08946   // Verifies all expectations on the given mock object and clears its
08947   // default actions and expectations.  Returns true iff the
08948   // verification was successful.
08949   static bool VerifyAndClear(void* mock_obj)
08950       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08951 
08952  private:
08953   friend class internal::UntypedFunctionMockerBase;
08954 
08955   // Needed for a function mocker to register itself (so that we know
08956   // how to clear a mock object).
08957   template <typename F>
08958   friend class internal::FunctionMockerBase;
08959 
08960   template <typename M>
08961   friend class NiceMock;
08962 
08963   template <typename M>
08964   friend class NaggyMock;
08965 
08966   template <typename M>
08967   friend class StrictMock;
08968 
08969   // Tells Google Mock to allow uninteresting calls on the given mock
08970   // object.
08971   static void AllowUninterestingCalls(const void* mock_obj)
08972       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08973 
08974   // Tells Google Mock to warn the user about uninteresting calls on
08975   // the given mock object.
08976   static void WarnUninterestingCalls(const void* mock_obj)
08977       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08978 
08979   // Tells Google Mock to fail uninteresting calls on the given mock
08980   // object.
08981   static void FailUninterestingCalls(const void* mock_obj)
08982       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08983 
08984   // Tells Google Mock the given mock object is being destroyed and
08985   // its entry in the call-reaction table should be removed.
08986   static void UnregisterCallReaction(const void* mock_obj)
08987       GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08988 
08989   // Returns the reaction Google Mock will have on uninteresting calls
08990   // made on the given mock object.
08991   static internal::CallReaction GetReactionOnUninterestingCalls(
08992       const void* mock_obj)
08993           GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
08994 
08995   // Verifies that all expectations on the given mock object have been
08996   // satisfied.  Reports one or more Google Test non-fatal failures
08997   // and returns false if not.
08998   static bool VerifyAndClearExpectationsLocked(void* mock_obj)
08999       GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
09000 
09001   // Clears all ON_CALL()s set on the given mock object.
09002   static void ClearDefaultActionsLocked(void* mock_obj)
09003       GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
09004 
09005   // Registers a mock object and a mock method it owns.
09006   static void Register(
09007       const void* mock_obj,
09008       internal::UntypedFunctionMockerBase* mocker)
09009           GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
09010 
09011   // Tells Google Mock where in the source code mock_obj is used in an
09012   // ON_CALL or EXPECT_CALL.  In case mock_obj is leaked, this
09013   // information helps the user identify which object it is.
09014   static void RegisterUseByOnCallOrExpectCall(
09015       const void* mock_obj, const char* file, int line)
09016           GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
09017 
09018   // Unregisters a mock method; removes the owning mock object from
09019   // the registry when the last mock method associated with it has
09020   // been unregistered.  This is called only in the destructor of
09021   // FunctionMockerBase.
09022   static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
09023       GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
09024 };  // class Mock
09025 
09026 // An abstract handle of an expectation.  Useful in the .After()
09027 // clause of EXPECT_CALL() for setting the (partial) order of
09028 // expectations.  The syntax:
09029 //
09030 //   Expectation e1 = EXPECT_CALL(...)...;
09031 //   EXPECT_CALL(...).After(e1)...;
09032 //
09033 // sets two expectations where the latter can only be matched after
09034 // the former has been satisfied.
09035 //
09036 // Notes:
09037 //   - This class is copyable and has value semantics.
09038 //   - Constness is shallow: a const Expectation object itself cannot
09039 //     be modified, but the mutable methods of the ExpectationBase
09040 //     object it references can be called via expectation_base().
09041 //   - The constructors and destructor are defined out-of-line because
09042 //     the Symbian WINSCW compiler wants to otherwise instantiate them
09043 //     when it sees this class definition, at which point it doesn't have
09044 //     ExpectationBase available yet, leading to incorrect destruction
09045 //     in the linked_ptr (or compilation errors if using a checking
09046 //     linked_ptr).
09047 class GTEST_API_ Expectation {
09048  public:
09049   // Constructs a null object that doesn't reference any expectation.
09050   Expectation();
09051 
09052   ~Expectation();
09053 
09054   // This single-argument ctor must not be explicit, in order to support the
09055   //   Expectation e = EXPECT_CALL(...);
09056   // syntax.
09057   //
09058   // A TypedExpectation object stores its pre-requisites as
09059   // Expectation objects, and needs to call the non-const Retire()
09060   // method on the ExpectationBase objects they reference.  Therefore
09061   // Expectation must receive a *non-const* reference to the
09062   // ExpectationBase object.
09063   Expectation(internal::ExpectationBase& exp);  // NOLINT
09064 
09065   // The compiler-generated copy ctor and operator= work exactly as
09066   // intended, so we don't need to define our own.
09067 
09068   // Returns true iff rhs references the same expectation as this object does.
09069   bool operator==(const Expectation& rhs) const {
09070     return expectation_base_ == rhs.expectation_base_;
09071   }
09072 
09073   bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
09074 
09075  private:
09076   friend class ExpectationSet;
09077   friend class Sequence;
09078   friend class ::testing::internal::ExpectationBase;
09079   friend class ::testing::internal::UntypedFunctionMockerBase;
09080 
09081   template <typename F>
09082   friend class ::testing::internal::FunctionMockerBase;
09083 
09084   template <typename F>
09085   friend class ::testing::internal::TypedExpectation;
09086 
09087   // This comparator is needed for putting Expectation objects into a set.
09088   class Less {
09089    public:
09090     bool operator()(const Expectation& lhs, const Expectation& rhs) const {
09091       return lhs.expectation_base_.get() < rhs.expectation_base_.get();
09092     }
09093   };
09094 
09095   typedef ::std::set<Expectation, Less> Set;
09096 
09097   Expectation(
09098       const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
09099 
09100   // Returns the expectation this object references.
09101   const internal::linked_ptr<internal::ExpectationBase>&
09102   expectation_base() const {
09103     return expectation_base_;
09104   }
09105 
09106   // A linked_ptr that co-owns the expectation this handle references.
09107   internal::linked_ptr<internal::ExpectationBase> expectation_base_;
09108 };
09109 
09110 // A set of expectation handles.  Useful in the .After() clause of
09111 // EXPECT_CALL() for setting the (partial) order of expectations.  The
09112 // syntax:
09113 //
09114 //   ExpectationSet es;
09115 //   es += EXPECT_CALL(...)...;
09116 //   es += EXPECT_CALL(...)...;
09117 //   EXPECT_CALL(...).After(es)...;
09118 //
09119 // sets three expectations where the last one can only be matched
09120 // after the first two have both been satisfied.
09121 //
09122 // This class is copyable and has value semantics.
09123 class ExpectationSet {
09124  public:
09125   // A bidirectional iterator that can read a const element in the set.
09126   typedef Expectation::Set::const_iterator const_iterator;
09127 
09128   // An object stored in the set.  This is an alias of Expectation.
09129   typedef Expectation::Set::value_type value_type;
09130 
09131   // Constructs an empty set.
09132   ExpectationSet() {}
09133 
09134   // This single-argument ctor must not be explicit, in order to support the
09135   //   ExpectationSet es = EXPECT_CALL(...);
09136   // syntax.
09137   ExpectationSet(internal::ExpectationBase& exp) {  // NOLINT
09138     *this += Expectation(exp);
09139   }
09140 
09141   // This single-argument ctor implements implicit conversion from
09142   // Expectation and thus must not be explicit.  This allows either an
09143   // Expectation or an ExpectationSet to be used in .After().
09144   ExpectationSet(const Expectation& e) {  // NOLINT
09145     *this += e;
09146   }
09147 
09148   // The compiler-generator ctor and operator= works exactly as
09149   // intended, so we don't need to define our own.
09150 
09151   // Returns true iff rhs contains the same set of Expectation objects
09152   // as this does.
09153   bool operator==(const ExpectationSet& rhs) const {
09154     return expectations_ == rhs.expectations_;
09155   }
09156 
09157   bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
09158 
09159   // Implements the syntax
09160   //   expectation_set += EXPECT_CALL(...);
09161   ExpectationSet& operator+=(const Expectation& e) {
09162     expectations_.insert(e);
09163     return *this;
09164   }
09165 
09166   int size() const { return static_cast<int>(expectations_.size()); }
09167 
09168   const_iterator begin() const { return expectations_.begin(); }
09169   const_iterator end() const { return expectations_.end(); }
09170 
09171  private:
09172   Expectation::Set expectations_;
09173 };
09174 
09175 
09176 // Sequence objects are used by a user to specify the relative order
09177 // in which the expectations should match.  They are copyable (we rely
09178 // on the compiler-defined copy constructor and assignment operator).
09179 class GTEST_API_ Sequence {
09180  public:
09181   // Constructs an empty sequence.
09182   Sequence() : last_expectation_(new Expectation) {}
09183 
09184   // Adds an expectation to this sequence.  The caller must ensure
09185   // that no other thread is accessing this Sequence object.
09186   void AddExpectation(const Expectation& expectation) const;
09187 
09188  private:
09189   // The last expectation in this sequence.  We use a linked_ptr here
09190   // because Sequence objects are copyable and we want the copies to
09191   // be aliases.  The linked_ptr allows the copies to co-own and share
09192   // the same Expectation object.
09193   internal::linked_ptr<Expectation> last_expectation_;
09194 };  // class Sequence
09195 
09196 // An object of this type causes all EXPECT_CALL() statements
09197 // encountered in its scope to be put in an anonymous sequence.  The
09198 // work is done in the constructor and destructor.  You should only
09199 // create an InSequence object on the stack.
09200 //
09201 // The sole purpose for this class is to support easy definition of
09202 // sequential expectations, e.g.
09203 //
09204 //   {
09205 //     InSequence dummy;  // The name of the object doesn't matter.
09206 //
09207 //     // The following expectations must match in the order they appear.
09208 //     EXPECT_CALL(a, Bar())...;
09209 //     EXPECT_CALL(a, Baz())...;
09210 //     ...
09211 //     EXPECT_CALL(b, Xyz())...;
09212 //   }
09213 //
09214 // You can create InSequence objects in multiple threads, as long as
09215 // they are used to affect different mock objects.  The idea is that
09216 // each thread can create and set up its own mocks as if it's the only
09217 // thread.  However, for clarity of your tests we recommend you to set
09218 // up mocks in the main thread unless you have a good reason not to do
09219 // so.
09220 class GTEST_API_ InSequence {
09221  public:
09222   InSequence();
09223   ~InSequence();
09224  private:
09225   bool sequence_created_;
09226 
09227   GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence);  // NOLINT
09228 } GTEST_ATTRIBUTE_UNUSED_;
09229 
09230 namespace internal {
09231 
09232 // Points to the implicit sequence introduced by a living InSequence
09233 // object (if any) in the current thread or NULL.
09234 GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
09235 
09236 // Base class for implementing expectations.
09237 //
09238 // There are two reasons for having a type-agnostic base class for
09239 // Expectation:
09240 //
09241 //   1. We need to store collections of expectations of different
09242 //   types (e.g. all pre-requisites of a particular expectation, all
09243 //   expectations in a sequence).  Therefore these expectation objects
09244 //   must share a common base class.
09245 //
09246 //   2. We can avoid binary code bloat by moving methods not depending
09247 //   on the template argument of Expectation to the base class.
09248 //
09249 // This class is internal and mustn't be used by user code directly.
09250 class GTEST_API_ ExpectationBase {
09251  public:
09252   // source_text is the EXPECT_CALL(...) source that created this Expectation.
09253   ExpectationBase(const char* file, int line, const string& source_text);
09254 
09255   virtual ~ExpectationBase();
09256 
09257   // Where in the source file was the expectation spec defined?
09258   const char* file() const { return file_; }
09259   int line() const { return line_; }
09260   const char* source_text() const { return source_text_.c_str(); }
09261   // Returns the cardinality specified in the expectation spec.
09262   const Cardinality& cardinality() const { return cardinality_; }
09263 
09264   // Describes the source file location of this expectation.
09265   void DescribeLocationTo(::std::ostream* os) const {
09266     *os << FormatFileLocation(file(), line()) << " ";
09267   }
09268 
09269   // Describes how many times a function call matching this
09270   // expectation has occurred.
09271   void DescribeCallCountTo(::std::ostream* os) const
09272       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
09273 
09274   // If this mock method has an extra matcher (i.e. .With(matcher)),
09275   // describes it to the ostream.
09276   virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
09277 
09278  protected:
09279   friend class ::testing::Expectation;
09280   friend class UntypedFunctionMockerBase;
09281 
09282   enum Clause {
09283     // Don't change the order of the enum members!
09284     kNone,
09285     kWith,
09286     kTimes,
09287     kInSequence,
09288     kAfter,
09289     kWillOnce,
09290     kWillRepeatedly,
09291     kRetiresOnSaturation
09292   };
09293 
09294   typedef std::vector<const void*> UntypedActions;
09295 
09296   // Returns an Expectation object that references and co-owns this
09297   // expectation.
09298   virtual Expectation GetHandle() = 0;
09299 
09300   // Asserts that the EXPECT_CALL() statement has the given property.
09301   void AssertSpecProperty(bool property, const string& failure_message) const {
09302     Assert(property, file_, line_, failure_message);
09303   }
09304 
09305   // Expects that the EXPECT_CALL() statement has the given property.
09306   void ExpectSpecProperty(bool property, const string& failure_message) const {
09307     Expect(property, file_, line_, failure_message);
09308   }
09309 
09310   // Explicitly specifies the cardinality of this expectation.  Used
09311   // by the subclasses to implement the .Times() clause.
09312   void SpecifyCardinality(const Cardinality& cardinality);
09313 
09314   // Returns true iff the user specified the cardinality explicitly
09315   // using a .Times().
09316   bool cardinality_specified() const { return cardinality_specified_; }
09317 
09318   // Sets the cardinality of this expectation spec.
09319   void set_cardinality(const Cardinality& a_cardinality) {
09320     cardinality_ = a_cardinality;
09321   }
09322 
09323   // The following group of methods should only be called after the
09324   // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
09325   // the current thread.
09326 
09327   // Retires all pre-requisites of this expectation.
09328   void RetireAllPreRequisites()
09329       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
09330 
09331   // Returns true iff this expectation is retired.
09332   bool is_retired() const
09333       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09334     g_gmock_mutex.AssertHeld();
09335     return retired_;
09336   }
09337 
09338   // Retires this expectation.
09339   void Retire()
09340       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09341     g_gmock_mutex.AssertHeld();
09342     retired_ = true;
09343   }
09344 
09345   // Returns true iff this expectation is satisfied.
09346   bool IsSatisfied() const
09347       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09348     g_gmock_mutex.AssertHeld();
09349     return cardinality().IsSatisfiedByCallCount(call_count_);
09350   }
09351 
09352   // Returns true iff this expectation is saturated.
09353   bool IsSaturated() const
09354       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09355     g_gmock_mutex.AssertHeld();
09356     return cardinality().IsSaturatedByCallCount(call_count_);
09357   }
09358 
09359   // Returns true iff this expectation is over-saturated.
09360   bool IsOverSaturated() const
09361       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09362     g_gmock_mutex.AssertHeld();
09363     return cardinality().IsOverSaturatedByCallCount(call_count_);
09364   }
09365 
09366   // Returns true iff all pre-requisites of this expectation are satisfied.
09367   bool AllPrerequisitesAreSatisfied() const
09368       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
09369 
09370   // Adds unsatisfied pre-requisites of this expectation to 'result'.
09371   void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
09372       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
09373 
09374   // Returns the number this expectation has been invoked.
09375   int call_count() const
09376       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09377     g_gmock_mutex.AssertHeld();
09378     return call_count_;
09379   }
09380 
09381   // Increments the number this expectation has been invoked.
09382   void IncrementCallCount()
09383       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09384     g_gmock_mutex.AssertHeld();
09385     call_count_++;
09386   }
09387 
09388   // Checks the action count (i.e. the number of WillOnce() and
09389   // WillRepeatedly() clauses) against the cardinality if this hasn't
09390   // been done before.  Prints a warning if there are too many or too
09391   // few actions.
09392   void CheckActionCountIfNotDone() const
09393       GTEST_LOCK_EXCLUDED_(mutex_);
09394 
09395   friend class ::testing::Sequence;
09396   friend class ::testing::internal::ExpectationTester;
09397 
09398   template <typename Function>
09399   friend class TypedExpectation;
09400 
09401   // Implements the .Times() clause.
09402   void UntypedTimes(const Cardinality& a_cardinality);
09403 
09404   // This group of fields are part of the spec and won't change after
09405   // an EXPECT_CALL() statement finishes.
09406   const char* file_;          // The file that contains the expectation.
09407   int line_;                  // The line number of the expectation.
09408   const string source_text_;  // The EXPECT_CALL(...) source text.
09409   // True iff the cardinality is specified explicitly.
09410   bool cardinality_specified_;
09411   Cardinality cardinality_;            // The cardinality of the expectation.
09412   // The immediate pre-requisites (i.e. expectations that must be
09413   // satisfied before this expectation can be matched) of this
09414   // expectation.  We use linked_ptr in the set because we want an
09415   // Expectation object to be co-owned by its FunctionMocker and its
09416   // successors.  This allows multiple mock objects to be deleted at
09417   // different times.
09418   ExpectationSet immediate_prerequisites_;
09419 
09420   // This group of fields are the current state of the expectation,
09421   // and can change as the mock function is called.
09422   int call_count_;  // How many times this expectation has been invoked.
09423   bool retired_;    // True iff this expectation has retired.
09424   UntypedActions untyped_actions_;
09425   bool extra_matcher_specified_;
09426   bool repeated_action_specified_;  // True if a WillRepeatedly() was specified.
09427   bool retires_on_saturation_;
09428   Clause last_clause_;
09429   mutable bool action_count_checked_;  // Under mutex_.
09430   mutable Mutex mutex_;  // Protects action_count_checked_.
09431 
09432   GTEST_DISALLOW_ASSIGN_(ExpectationBase);
09433 };  // class ExpectationBase
09434 
09435 // Impements an expectation for the given function type.
09436 template <typename F>
09437 class TypedExpectation : public ExpectationBase {
09438  public:
09439   typedef typename Function<F>::ArgumentTuple ArgumentTuple;
09440   typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
09441   typedef typename Function<F>::Result Result;
09442 
09443   TypedExpectation(FunctionMockerBase<F>* owner,
09444                    const char* a_file, int a_line, const string& a_source_text,
09445                    const ArgumentMatcherTuple& m)
09446       : ExpectationBase(a_file, a_line, a_source_text),
09447         owner_(owner),
09448         matchers_(m),
09449         // By default, extra_matcher_ should match anything.  However,
09450         // we cannot initialize it with _ as that triggers a compiler
09451         // bug in Symbian's C++ compiler (cannot decide between two
09452         // overloaded constructors of Matcher<const ArgumentTuple&>).
09453         extra_matcher_(A<const ArgumentTuple&>()),
09454         repeated_action_(DoDefault()) {}
09455 
09456   virtual ~TypedExpectation() {
09457     // Check the validity of the action count if it hasn't been done
09458     // yet (for example, if the expectation was never used).
09459     CheckActionCountIfNotDone();
09460     for (UntypedActions::const_iterator it = untyped_actions_.begin();
09461          it != untyped_actions_.end(); ++it) {
09462       delete static_cast<const Action<F>*>(*it);
09463     }
09464   }
09465 
09466   // Implements the .With() clause.
09467   TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
09468     if (last_clause_ == kWith) {
09469       ExpectSpecProperty(false,
09470                          ".With() cannot appear "
09471                          "more than once in an EXPECT_CALL().");
09472     } else {
09473       ExpectSpecProperty(last_clause_ < kWith,
09474                          ".With() must be the first "
09475                          "clause in an EXPECT_CALL().");
09476     }
09477     last_clause_ = kWith;
09478 
09479     extra_matcher_ = m;
09480     extra_matcher_specified_ = true;
09481     return *this;
09482   }
09483 
09484   // Implements the .Times() clause.
09485   TypedExpectation& Times(const Cardinality& a_cardinality) {
09486     ExpectationBase::UntypedTimes(a_cardinality);
09487     return *this;
09488   }
09489 
09490   // Implements the .Times() clause.
09491   TypedExpectation& Times(int n) {
09492     return Times(Exactly(n));
09493   }
09494 
09495   // Implements the .InSequence() clause.
09496   TypedExpectation& InSequence(const Sequence& s) {
09497     ExpectSpecProperty(last_clause_ <= kInSequence,
09498                        ".InSequence() cannot appear after .After(),"
09499                        " .WillOnce(), .WillRepeatedly(), or "
09500                        ".RetiresOnSaturation().");
09501     last_clause_ = kInSequence;
09502 
09503     s.AddExpectation(GetHandle());
09504     return *this;
09505   }
09506   TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
09507     return InSequence(s1).InSequence(s2);
09508   }
09509   TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
09510                                const Sequence& s3) {
09511     return InSequence(s1, s2).InSequence(s3);
09512   }
09513   TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
09514                                const Sequence& s3, const Sequence& s4) {
09515     return InSequence(s1, s2, s3).InSequence(s4);
09516   }
09517   TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
09518                                const Sequence& s3, const Sequence& s4,
09519                                const Sequence& s5) {
09520     return InSequence(s1, s2, s3, s4).InSequence(s5);
09521   }
09522 
09523   // Implements that .After() clause.
09524   TypedExpectation& After(const ExpectationSet& s) {
09525     ExpectSpecProperty(last_clause_ <= kAfter,
09526                        ".After() cannot appear after .WillOnce(),"
09527                        " .WillRepeatedly(), or "
09528                        ".RetiresOnSaturation().");
09529     last_clause_ = kAfter;
09530 
09531     for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
09532       immediate_prerequisites_ += *it;
09533     }
09534     return *this;
09535   }
09536   TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
09537     return After(s1).After(s2);
09538   }
09539   TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
09540                           const ExpectationSet& s3) {
09541     return After(s1, s2).After(s3);
09542   }
09543   TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
09544                           const ExpectationSet& s3, const ExpectationSet& s4) {
09545     return After(s1, s2, s3).After(s4);
09546   }
09547   TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
09548                           const ExpectationSet& s3, const ExpectationSet& s4,
09549                           const ExpectationSet& s5) {
09550     return After(s1, s2, s3, s4).After(s5);
09551   }
09552 
09553   // Implements the .WillOnce() clause.
09554   TypedExpectation& WillOnce(const Action<F>& action) {
09555     ExpectSpecProperty(last_clause_ <= kWillOnce,
09556                        ".WillOnce() cannot appear after "
09557                        ".WillRepeatedly() or .RetiresOnSaturation().");
09558     last_clause_ = kWillOnce;
09559 
09560     untyped_actions_.push_back(new Action<F>(action));
09561     if (!cardinality_specified()) {
09562       set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
09563     }
09564     return *this;
09565   }
09566 
09567   // Implements the .WillRepeatedly() clause.
09568   TypedExpectation& WillRepeatedly(const Action<F>& action) {
09569     if (last_clause_ == kWillRepeatedly) {
09570       ExpectSpecProperty(false,
09571                          ".WillRepeatedly() cannot appear "
09572                          "more than once in an EXPECT_CALL().");
09573     } else {
09574       ExpectSpecProperty(last_clause_ < kWillRepeatedly,
09575                          ".WillRepeatedly() cannot appear "
09576                          "after .RetiresOnSaturation().");
09577     }
09578     last_clause_ = kWillRepeatedly;
09579     repeated_action_specified_ = true;
09580 
09581     repeated_action_ = action;
09582     if (!cardinality_specified()) {
09583       set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
09584     }
09585 
09586     // Now that no more action clauses can be specified, we check
09587     // whether their count makes sense.
09588     CheckActionCountIfNotDone();
09589     return *this;
09590   }
09591 
09592   // Implements the .RetiresOnSaturation() clause.
09593   TypedExpectation& RetiresOnSaturation() {
09594     ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
09595                        ".RetiresOnSaturation() cannot appear "
09596                        "more than once.");
09597     last_clause_ = kRetiresOnSaturation;
09598     retires_on_saturation_ = true;
09599 
09600     // Now that no more action clauses can be specified, we check
09601     // whether their count makes sense.
09602     CheckActionCountIfNotDone();
09603     return *this;
09604   }
09605 
09606   // Returns the matchers for the arguments as specified inside the
09607   // EXPECT_CALL() macro.
09608   const ArgumentMatcherTuple& matchers() const {
09609     return matchers_;
09610   }
09611 
09612   // Returns the matcher specified by the .With() clause.
09613   const Matcher<const ArgumentTuple&>& extra_matcher() const {
09614     return extra_matcher_;
09615   }
09616 
09617   // Returns the action specified by the .WillRepeatedly() clause.
09618   const Action<F>& repeated_action() const { return repeated_action_; }
09619 
09620   // If this mock method has an extra matcher (i.e. .With(matcher)),
09621   // describes it to the ostream.
09622   virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
09623     if (extra_matcher_specified_) {
09624       *os << "    Expected args: ";
09625       extra_matcher_.DescribeTo(os);
09626       *os << "\n";
09627     }
09628   }
09629 
09630  private:
09631   template <typename Function>
09632   friend class FunctionMockerBase;
09633 
09634   // Returns an Expectation object that references and co-owns this
09635   // expectation.
09636   virtual Expectation GetHandle() {
09637     return owner_->GetHandleOf(this);
09638   }
09639 
09640   // The following methods will be called only after the EXPECT_CALL()
09641   // statement finishes and when the current thread holds
09642   // g_gmock_mutex.
09643 
09644   // Returns true iff this expectation matches the given arguments.
09645   bool Matches(const ArgumentTuple& args) const
09646       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09647     g_gmock_mutex.AssertHeld();
09648     return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
09649   }
09650 
09651   // Returns true iff this expectation should handle the given arguments.
09652   bool ShouldHandleArguments(const ArgumentTuple& args) const
09653       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09654     g_gmock_mutex.AssertHeld();
09655 
09656     // In case the action count wasn't checked when the expectation
09657     // was defined (e.g. if this expectation has no WillRepeatedly()
09658     // or RetiresOnSaturation() clause), we check it when the
09659     // expectation is used for the first time.
09660     CheckActionCountIfNotDone();
09661     return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
09662   }
09663 
09664   // Describes the result of matching the arguments against this
09665   // expectation to the given ostream.
09666   void ExplainMatchResultTo(
09667       const ArgumentTuple& args,
09668       ::std::ostream* os) const
09669           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09670     g_gmock_mutex.AssertHeld();
09671 
09672     if (is_retired()) {
09673       *os << "         Expected: the expectation is active\n"
09674           << "           Actual: it is retired\n";
09675     } else if (!Matches(args)) {
09676       if (!TupleMatches(matchers_, args)) {
09677         ExplainMatchFailureTupleTo(matchers_, args, os);
09678       }
09679       StringMatchResultListener listener;
09680       if (!extra_matcher_.MatchAndExplain(args, &listener)) {
09681         *os << "    Expected args: ";
09682         extra_matcher_.DescribeTo(os);
09683         *os << "\n           Actual: don't match";
09684 
09685         internal::PrintIfNotEmpty(listener.str(), os);
09686         *os << "\n";
09687       }
09688     } else if (!AllPrerequisitesAreSatisfied()) {
09689       *os << "         Expected: all pre-requisites are satisfied\n"
09690           << "           Actual: the following immediate pre-requisites "
09691           << "are not satisfied:\n";
09692       ExpectationSet unsatisfied_prereqs;
09693       FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
09694       int i = 0;
09695       for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
09696            it != unsatisfied_prereqs.end(); ++it) {
09697         it->expectation_base()->DescribeLocationTo(os);
09698         *os << "pre-requisite #" << i++ << "\n";
09699       }
09700       *os << "                   (end of pre-requisites)\n";
09701     } else {
09702       // This line is here just for completeness' sake.  It will never
09703       // be executed as currently the ExplainMatchResultTo() function
09704       // is called only when the mock function call does NOT match the
09705       // expectation.
09706       *os << "The call matches the expectation.\n";
09707     }
09708   }
09709 
09710   // Returns the action that should be taken for the current invocation.
09711   const Action<F>& GetCurrentAction(
09712       const FunctionMockerBase<F>* mocker,
09713       const ArgumentTuple& args) const
09714           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09715     g_gmock_mutex.AssertHeld();
09716     const int count = call_count();
09717     Assert(count >= 1, __FILE__, __LINE__,
09718            "call_count() is <= 0 when GetCurrentAction() is "
09719            "called - this should never happen.");
09720 
09721     const int action_count = static_cast<int>(untyped_actions_.size());
09722     if (action_count > 0 && !repeated_action_specified_ &&
09723         count > action_count) {
09724       // If there is at least one WillOnce() and no WillRepeatedly(),
09725       // we warn the user when the WillOnce() clauses ran out.
09726       ::std::stringstream ss;
09727       DescribeLocationTo(&ss);
09728       ss << "Actions ran out in " << source_text() << "...\n"
09729          << "Called " << count << " times, but only "
09730          << action_count << " WillOnce()"
09731          << (action_count == 1 ? " is" : "s are") << " specified - ";
09732       mocker->DescribeDefaultActionTo(args, &ss);
09733       Log(kWarning, ss.str(), 1);
09734     }
09735 
09736     return count <= action_count ?
09737         *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
09738         repeated_action();
09739   }
09740 
09741   // Given the arguments of a mock function call, if the call will
09742   // over-saturate this expectation, returns the default action;
09743   // otherwise, returns the next action in this expectation.  Also
09744   // describes *what* happened to 'what', and explains *why* Google
09745   // Mock does it to 'why'.  This method is not const as it calls
09746   // IncrementCallCount().  A return value of NULL means the default
09747   // action.
09748   const Action<F>* GetActionForArguments(
09749       const FunctionMockerBase<F>* mocker,
09750       const ArgumentTuple& args,
09751       ::std::ostream* what,
09752       ::std::ostream* why)
09753           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
09754     g_gmock_mutex.AssertHeld();
09755     if (IsSaturated()) {
09756       // We have an excessive call.
09757       IncrementCallCount();
09758       *what << "Mock function called more times than expected - ";
09759       mocker->DescribeDefaultActionTo(args, what);
09760       DescribeCallCountTo(why);
09761 
09762       // TODO(wan@google.com): allow the user to control whether
09763       // unexpected calls should fail immediately or continue using a
09764       // flag --gmock_unexpected_calls_are_fatal.
09765       return NULL;
09766     }
09767 
09768     IncrementCallCount();
09769     RetireAllPreRequisites();
09770 
09771     if (retires_on_saturation_ && IsSaturated()) {
09772       Retire();
09773     }
09774 
09775     // Must be done after IncrementCount()!
09776     *what << "Mock function call matches " << source_text() <<"...\n";
09777     return &(GetCurrentAction(mocker, args));
09778   }
09779 
09780   // All the fields below won't change once the EXPECT_CALL()
09781   // statement finishes.
09782   FunctionMockerBase<F>* const owner_;
09783   ArgumentMatcherTuple matchers_;
09784   Matcher<const ArgumentTuple&> extra_matcher_;
09785   Action<F> repeated_action_;
09786 
09787   GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
09788 };  // class TypedExpectation
09789 
09790 // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
09791 // specifying the default behavior of, or expectation on, a mock
09792 // function.
09793 
09794 // Note: class MockSpec really belongs to the ::testing namespace.
09795 // However if we define it in ::testing, MSVC will complain when
09796 // classes in ::testing::internal declare it as a friend class
09797 // template.  To workaround this compiler bug, we define MockSpec in
09798 // ::testing::internal and import it into ::testing.
09799 
09800 // Logs a message including file and line number information.
09801 GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
09802                                 const char* file, int line,
09803                                 const string& message);
09804 
09805 template <typename F>
09806 class MockSpec {
09807  public:
09808   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
09809   typedef typename internal::Function<F>::ArgumentMatcherTuple
09810       ArgumentMatcherTuple;
09811 
09812   // Constructs a MockSpec object, given the function mocker object
09813   // that the spec is associated with.
09814   explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
09815       : function_mocker_(function_mocker) {}
09816 
09817   // Adds a new default action spec to the function mocker and returns
09818   // the newly created spec.
09819   internal::OnCallSpec<F>& InternalDefaultActionSetAt(
09820       const char* file, int line, const char* obj, const char* call) {
09821     LogWithLocation(internal::kInfo, file, line,
09822         string("ON_CALL(") + obj + ", " + call + ") invoked");
09823     return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
09824   }
09825 
09826   // Adds a new expectation spec to the function mocker and returns
09827   // the newly created spec.
09828   internal::TypedExpectation<F>& InternalExpectedAt(
09829       const char* file, int line, const char* obj, const char* call) {
09830     const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
09831     LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
09832     return function_mocker_->AddNewExpectation(
09833         file, line, source_text, matchers_);
09834   }
09835 
09836  private:
09837   template <typename Function>
09838   friend class internal::FunctionMocker;
09839 
09840   void SetMatchers(const ArgumentMatcherTuple& matchers) {
09841     matchers_ = matchers;
09842   }
09843 
09844   // The function mocker that owns this spec.
09845   internal::FunctionMockerBase<F>* const function_mocker_;
09846   // The argument matchers specified in the spec.
09847   ArgumentMatcherTuple matchers_;
09848 
09849   GTEST_DISALLOW_ASSIGN_(MockSpec);
09850 };  // class MockSpec
09851 
09852 // MSVC warns about using 'this' in base member initializer list, so
09853 // we need to temporarily disable the warning.  We have to do it for
09854 // the entire class to suppress the warning, even though it's about
09855 // the constructor only.
09856 
09857 #ifdef _MSC_VER
09858 # pragma warning(push)          // Saves the current warning state.
09859 # pragma warning(disable:4355)  // Temporarily disables warning 4355.
09860 #endif  // _MSV_VER
09861 
09862 // C++ treats the void type specially.  For example, you cannot define
09863 // a void-typed variable or pass a void value to a function.
09864 // ActionResultHolder<T> holds a value of type T, where T must be a
09865 // copyable type or void (T doesn't need to be default-constructable).
09866 // It hides the syntactic difference between void and other types, and
09867 // is used to unify the code for invoking both void-returning and
09868 // non-void-returning mock functions.
09869 
09870 // Untyped base class for ActionResultHolder<T>.
09871 class UntypedActionResultHolderBase {
09872  public:
09873   virtual ~UntypedActionResultHolderBase() {}
09874 
09875   // Prints the held value as an action's result to os.
09876   virtual void PrintAsActionResult(::std::ostream* os) const = 0;
09877 };
09878 
09879 // This generic definition is used when T is not void.
09880 template <typename T>
09881 class ActionResultHolder : public UntypedActionResultHolderBase {
09882  public:
09883   explicit ActionResultHolder(T a_value) : value_(a_value) {}
09884 
09885   // The compiler-generated copy constructor and assignment operator
09886   // are exactly what we need, so we don't need to define them.
09887 
09888   // Returns the held value and deletes this object.
09889   T GetValueAndDelete() const {
09890     T retval(value_);
09891     delete this;
09892     return retval;
09893   }
09894 
09895   // Prints the held value as an action's result to os.
09896   virtual void PrintAsActionResult(::std::ostream* os) const {
09897     *os << "\n          Returns: ";
09898     // T may be a reference type, so we don't use UniversalPrint().
09899     UniversalPrinter<T>::Print(value_, os);
09900   }
09901 
09902   // Performs the given mock function's default action and returns the
09903   // result in a new-ed ActionResultHolder.
09904   template <typename F>
09905   static ActionResultHolder* PerformDefaultAction(
09906       const FunctionMockerBase<F>* func_mocker,
09907       const typename Function<F>::ArgumentTuple& args,
09908       const string& call_description) {
09909     return new ActionResultHolder(
09910         func_mocker->PerformDefaultAction(args, call_description));
09911   }
09912 
09913   // Performs the given action and returns the result in a new-ed
09914   // ActionResultHolder.
09915   template <typename F>
09916   static ActionResultHolder*
09917   PerformAction(const Action<F>& action,
09918                 const typename Function<F>::ArgumentTuple& args) {
09919     return new ActionResultHolder(action.Perform(args));
09920   }
09921 
09922  private:
09923   T value_;
09924 
09925   // T could be a reference type, so = isn't supported.
09926   GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
09927 };
09928 
09929 // Specialization for T = void.
09930 template <>
09931 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
09932  public:
09933   void GetValueAndDelete() const { delete this; }
09934 
09935   virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
09936 
09937   // Performs the given mock function's default action and returns NULL;
09938   template <typename F>
09939   static ActionResultHolder* PerformDefaultAction(
09940       const FunctionMockerBase<F>* func_mocker,
09941       const typename Function<F>::ArgumentTuple& args,
09942       const string& call_description) {
09943     func_mocker->PerformDefaultAction(args, call_description);
09944     return NULL;
09945   }
09946 
09947   // Performs the given action and returns NULL.
09948   template <typename F>
09949   static ActionResultHolder* PerformAction(
09950       const Action<F>& action,
09951       const typename Function<F>::ArgumentTuple& args) {
09952     action.Perform(args);
09953     return NULL;
09954   }
09955 };
09956 
09957 // The base of the function mocker class for the given function type.
09958 // We put the methods in this class instead of its child to avoid code
09959 // bloat.
09960 template <typename F>
09961 class FunctionMockerBase : public UntypedFunctionMockerBase {
09962  public:
09963   typedef typename Function<F>::Result Result;
09964   typedef typename Function<F>::ArgumentTuple ArgumentTuple;
09965   typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
09966 
09967   FunctionMockerBase() : current_spec_(this) {}
09968 
09969   // The destructor verifies that all expectations on this mock
09970   // function have been satisfied.  If not, it will report Google Test
09971   // non-fatal failures for the violations.
09972   virtual ~FunctionMockerBase()
09973         GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
09974     MutexLock l(&g_gmock_mutex);
09975     VerifyAndClearExpectationsLocked();
09976     Mock::UnregisterLocked(this);
09977     ClearDefaultActionsLocked();
09978   }
09979 
09980   // Returns the ON_CALL spec that matches this mock function with the
09981   // given arguments; returns NULL if no matching ON_CALL is found.
09982   // L = *
09983   const OnCallSpec<F>* FindOnCallSpec(
09984       const ArgumentTuple& args) const {
09985     for (UntypedOnCallSpecs::const_reverse_iterator it
09986              = untyped_on_call_specs_.rbegin();
09987          it != untyped_on_call_specs_.rend(); ++it) {
09988       const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
09989       if (spec->Matches(args))
09990         return spec;
09991     }
09992 
09993     return NULL;
09994   }
09995 
09996   // Performs the default action of this mock function on the given
09997   // arguments and returns the result. Asserts (or throws if
09998   // exceptions are enabled) with a helpful call descrption if there
09999   // is no valid return value. This method doesn't depend on the
10000   // mutable state of this object, and thus can be called concurrently
10001   // without locking.
10002   // L = *
10003   Result PerformDefaultAction(const ArgumentTuple& args,
10004                               const string& call_description) const {
10005     const OnCallSpec<F>* const spec =
10006         this->FindOnCallSpec(args);
10007     if (spec != NULL) {
10008       return spec->GetAction().Perform(args);
10009     }
10010     const string message = call_description +
10011         "\n    The mock function has no default action "
10012         "set, and its return type has no default value set.";
10013 #if GTEST_HAS_EXCEPTIONS
10014     if (!DefaultValue<Result>::Exists()) {
10015       throw std::runtime_error(message);
10016     }
10017 #else
10018     Assert(DefaultValue<Result>::Exists(), "", -1, message);
10019 #endif
10020     return DefaultValue<Result>::Get();
10021   }
10022 
10023   // Performs the default action with the given arguments and returns
10024   // the action's result.  The call description string will be used in
10025   // the error message to describe the call in the case the default
10026   // action fails.  The caller is responsible for deleting the result.
10027   // L = *
10028   virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
10029       const void* untyped_args,  // must point to an ArgumentTuple
10030       const string& call_description) const {
10031     const ArgumentTuple& args =
10032         *static_cast<const ArgumentTuple*>(untyped_args);
10033     return ResultHolder::PerformDefaultAction(this, args, call_description);
10034   }
10035 
10036   // Performs the given action with the given arguments and returns
10037   // the action's result.  The caller is responsible for deleting the
10038   // result.
10039   // L = *
10040   virtual UntypedActionResultHolderBase* UntypedPerformAction(
10041       const void* untyped_action, const void* untyped_args) const {
10042     // Make a copy of the action before performing it, in case the
10043     // action deletes the mock object (and thus deletes itself).
10044     const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
10045     const ArgumentTuple& args =
10046         *static_cast<const ArgumentTuple*>(untyped_args);
10047     return ResultHolder::PerformAction(action, args);
10048   }
10049 
10050   // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
10051   // clears the ON_CALL()s set on this mock function.
10052   virtual void ClearDefaultActionsLocked()
10053       GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10054     g_gmock_mutex.AssertHeld();
10055 
10056     // Deleting our default actions may trigger other mock objects to be
10057     // deleted, for example if an action contains a reference counted smart
10058     // pointer to that mock object, and that is the last reference. So if we
10059     // delete our actions within the context of the global mutex we may deadlock
10060     // when this method is called again. Instead, make a copy of the set of
10061     // actions to delete, clear our set within the mutex, and then delete the
10062     // actions outside of the mutex.
10063     UntypedOnCallSpecs specs_to_delete;
10064     untyped_on_call_specs_.swap(specs_to_delete);
10065 
10066     g_gmock_mutex.Unlock();
10067     for (UntypedOnCallSpecs::const_iterator it =
10068              specs_to_delete.begin();
10069          it != specs_to_delete.end(); ++it) {
10070       delete static_cast<const OnCallSpec<F>*>(*it);
10071     }
10072 
10073     // Lock the mutex again, since the caller expects it to be locked when we
10074     // return.
10075     g_gmock_mutex.Lock();
10076   }
10077 
10078  protected:
10079   template <typename Function>
10080   friend class MockSpec;
10081 
10082   typedef ActionResultHolder<Result> ResultHolder;
10083 
10084   // Returns the result of invoking this mock function with the given
10085   // arguments.  This function can be safely called from multiple
10086   // threads concurrently.
10087   Result InvokeWith(const ArgumentTuple& args)
10088         GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10089     return static_cast<const ResultHolder*>(
10090         this->UntypedInvokeWith(&args))->GetValueAndDelete();
10091   }
10092 
10093   // Adds and returns a default action spec for this mock function.
10094   OnCallSpec<F>& AddNewOnCallSpec(
10095       const char* file, int line,
10096       const ArgumentMatcherTuple& m)
10097           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10098     Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10099     OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
10100     untyped_on_call_specs_.push_back(on_call_spec);
10101     return *on_call_spec;
10102   }
10103 
10104   // Adds and returns an expectation spec for this mock function.
10105   TypedExpectation<F>& AddNewExpectation(
10106       const char* file,
10107       int line,
10108       const string& source_text,
10109       const ArgumentMatcherTuple& m)
10110           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10111     Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
10112     TypedExpectation<F>* const expectation =
10113         new TypedExpectation<F>(this, file, line, source_text, m);
10114     const linked_ptr<ExpectationBase> untyped_expectation(expectation);
10115     untyped_expectations_.push_back(untyped_expectation);
10116 
10117     // Adds this expectation into the implicit sequence if there is one.
10118     Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
10119     if (implicit_sequence != NULL) {
10120       implicit_sequence->AddExpectation(Expectation(untyped_expectation));
10121     }
10122 
10123     return *expectation;
10124   }
10125 
10126   // The current spec (either default action spec or expectation spec)
10127   // being described on this function mocker.
10128   MockSpec<F>& current_spec() { return current_spec_; }
10129 
10130  private:
10131   template <typename Func> friend class TypedExpectation;
10132 
10133   // Some utilities needed for implementing UntypedInvokeWith().
10134 
10135   // Describes what default action will be performed for the given
10136   // arguments.
10137   // L = *
10138   void DescribeDefaultActionTo(const ArgumentTuple& args,
10139                                ::std::ostream* os) const {
10140     const OnCallSpec<F>* const spec = FindOnCallSpec(args);
10141 
10142     if (spec == NULL) {
10143       *os << (internal::type_equals<Result, void>::value ?
10144               "returning directly.\n" :
10145               "returning default value.\n");
10146     } else {
10147       *os << "taking default action specified at:\n"
10148           << FormatFileLocation(spec->file(), spec->line()) << "\n";
10149     }
10150   }
10151 
10152   // Writes a message that the call is uninteresting (i.e. neither
10153   // explicitly expected nor explicitly unexpected) to the given
10154   // ostream.
10155   virtual void UntypedDescribeUninterestingCall(
10156       const void* untyped_args,
10157       ::std::ostream* os) const
10158           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10159     const ArgumentTuple& args =
10160         *static_cast<const ArgumentTuple*>(untyped_args);
10161     *os << "Uninteresting mock function call - ";
10162     DescribeDefaultActionTo(args, os);
10163     *os << "    Function call: " << Name();
10164     UniversalPrint(args, os);
10165   }
10166 
10167   // Returns the expectation that matches the given function arguments
10168   // (or NULL is there's no match); when a match is found,
10169   // untyped_action is set to point to the action that should be
10170   // performed (or NULL if the action is "do default"), and
10171   // is_excessive is modified to indicate whether the call exceeds the
10172   // expected number.
10173   //
10174   // Critical section: We must find the matching expectation and the
10175   // corresponding action that needs to be taken in an ATOMIC
10176   // transaction.  Otherwise another thread may call this mock
10177   // method in the middle and mess up the state.
10178   //
10179   // However, performing the action has to be left out of the critical
10180   // section.  The reason is that we have no control on what the
10181   // action does (it can invoke an arbitrary user function or even a
10182   // mock function) and excessive locking could cause a dead lock.
10183   virtual const ExpectationBase* UntypedFindMatchingExpectation(
10184       const void* untyped_args,
10185       const void** untyped_action, bool* is_excessive,
10186       ::std::ostream* what, ::std::ostream* why)
10187           GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
10188     const ArgumentTuple& args =
10189         *static_cast<const ArgumentTuple*>(untyped_args);
10190     MutexLock l(&g_gmock_mutex);
10191     TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
10192     if (exp == NULL) {  // A match wasn't found.
10193       this->FormatUnexpectedCallMessageLocked(args, what, why);
10194       return NULL;
10195     }
10196 
10197     // This line must be done before calling GetActionForArguments(),
10198     // which will increment the call count for *exp and thus affect
10199     // its saturation status.
10200     *is_excessive = exp->IsSaturated();
10201     const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
10202     if (action != NULL && action->IsDoDefault())
10203       action = NULL;  // Normalize "do default" to NULL.
10204     *untyped_action = action;
10205     return exp;
10206   }
10207 
10208   // Prints the given function arguments to the ostream.
10209   virtual void UntypedPrintArgs(const void* untyped_args,
10210                                 ::std::ostream* os) const {
10211     const ArgumentTuple& args =
10212         *static_cast<const ArgumentTuple*>(untyped_args);
10213     UniversalPrint(args, os);
10214   }
10215 
10216   // Returns the expectation that matches the arguments, or NULL if no
10217   // expectation matches them.
10218   TypedExpectation<F>* FindMatchingExpectationLocked(
10219       const ArgumentTuple& args) const
10220           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10221     g_gmock_mutex.AssertHeld();
10222     for (typename UntypedExpectations::const_reverse_iterator it =
10223              untyped_expectations_.rbegin();
10224          it != untyped_expectations_.rend(); ++it) {
10225       TypedExpectation<F>* const exp =
10226           static_cast<TypedExpectation<F>*>(it->get());
10227       if (exp->ShouldHandleArguments(args)) {
10228         return exp;
10229       }
10230     }
10231     return NULL;
10232   }
10233 
10234   // Returns a message that the arguments don't match any expectation.
10235   void FormatUnexpectedCallMessageLocked(
10236       const ArgumentTuple& args,
10237       ::std::ostream* os,
10238       ::std::ostream* why) const
10239           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10240     g_gmock_mutex.AssertHeld();
10241     *os << "\nUnexpected mock function call - ";
10242     DescribeDefaultActionTo(args, os);
10243     PrintTriedExpectationsLocked(args, why);
10244   }
10245 
10246   // Prints a list of expectations that have been tried against the
10247   // current mock function call.
10248   void PrintTriedExpectationsLocked(
10249       const ArgumentTuple& args,
10250       ::std::ostream* why) const
10251           GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
10252     g_gmock_mutex.AssertHeld();
10253     const int count = static_cast<int>(untyped_expectations_.size());
10254     *why << "Google Mock tried the following " << count << " "
10255          << (count == 1 ? "expectation, but it didn't match" :
10256              "expectations, but none matched")
10257          << ":\n";
10258     for (int i = 0; i < count; i++) {
10259       TypedExpectation<F>* const expectation =
10260           static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
10261       *why << "\n";
10262       expectation->DescribeLocationTo(why);
10263       if (count > 1) {
10264         *why << "tried expectation #" << i << ": ";
10265       }
10266       *why << expectation->source_text() << "...\n";
10267       expectation->ExplainMatchResultTo(args, why);
10268       expectation->DescribeCallCountTo(why);
10269     }
10270   }
10271 
10272   // The current spec (either default action spec or expectation spec)
10273   // being described on this function mocker.
10274   MockSpec<F> current_spec_;
10275 
10276   // There is no generally useful and implementable semantics of
10277   // copying a mock object, so copying a mock is usually a user error.
10278   // Thus we disallow copying function mockers.  If the user really
10279   // wants to copy a mock object, he should implement his own copy
10280   // operation, for example:
10281   //
10282   //   class MockFoo : public Foo {
10283   //    public:
10284   //     // Defines a copy constructor explicitly.
10285   //     MockFoo(const MockFoo& src) {}
10286   //     ...
10287   //   };
10288   GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
10289 };  // class FunctionMockerBase
10290 
10291 #ifdef _MSC_VER
10292 # pragma warning(pop)  // Restores the warning state.
10293 #endif  // _MSV_VER
10294 
10295 // Implements methods of FunctionMockerBase.
10296 
10297 // Verifies that all expectations on this mock function have been
10298 // satisfied.  Reports one or more Google Test non-fatal failures and
10299 // returns false if not.
10300 
10301 // Reports an uninteresting call (whose description is in msg) in the
10302 // manner specified by 'reaction'.
10303 void ReportUninterestingCall(CallReaction reaction, const string& msg);
10304 
10305 }  // namespace internal
10306 
10307 // The style guide prohibits "using" statements in a namespace scope
10308 // inside a header file.  However, the MockSpec class template is
10309 // meant to be defined in the ::testing namespace.  The following line
10310 // is just a trick for working around a bug in MSVC 8.0, which cannot
10311 // handle it if we define MockSpec in ::testing.
10312 using internal::MockSpec;
10313 
10314 // Const(x) is a convenient function for obtaining a const reference
10315 // to x.  This is useful for setting expectations on an overloaded
10316 // const mock method, e.g.
10317 //
10318 //   class MockFoo : public FooInterface {
10319 //    public:
10320 //     MOCK_METHOD0(Bar, int());
10321 //     MOCK_CONST_METHOD0(Bar, int&());
10322 //   };
10323 //
10324 //   MockFoo foo;
10325 //   // Expects a call to non-const MockFoo::Bar().
10326 //   EXPECT_CALL(foo, Bar());
10327 //   // Expects a call to const MockFoo::Bar().
10328 //   EXPECT_CALL(Const(foo), Bar());
10329 template <typename T>
10330 inline const T& Const(const T& x) { return x; }
10331 
10332 // Constructs an Expectation object that references and co-owns exp.
10333 inline Expectation::Expectation(internal::ExpectationBase& exp)  // NOLINT
10334     : expectation_base_(exp.GetHandle().expectation_base()) {}
10335 
10336 }  // namespace testing
10337 
10338 // A separate macro is required to avoid compile errors when the name
10339 // of the method used in call is a result of macro expansion.
10340 // See CompilesWithMethodNameExpandedFromMacro tests in
10341 // internal/gmock-spec-builders_test.cc for more details.
10342 #define GMOCK_ON_CALL_IMPL_(obj, call) \
10343     ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
10344                                                     #obj, #call)
10345 #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
10346 
10347 #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
10348     ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
10349 #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
10350 
10351 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
10352 
10353 namespace testing {
10354 namespace internal {
10355 
10356 template <typename F>
10357 class FunctionMockerBase;
10358 
10359 // Note: class FunctionMocker really belongs to the ::testing
10360 // namespace.  However if we define it in ::testing, MSVC will
10361 // complain when classes in ::testing::internal declare it as a
10362 // friend class template.  To workaround this compiler bug, we define
10363 // FunctionMocker in ::testing::internal and import it into ::testing.
10364 template <typename F>
10365 class FunctionMocker;
10366 
10367 template <typename R>
10368 class FunctionMocker<R()> : public
10369     internal::FunctionMockerBase<R()> {
10370  public:
10371   typedef R F();
10372   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10373 
10374   MockSpec<F>& With() {
10375     return this->current_spec();
10376   }
10377 
10378   R Invoke() {
10379     // Even though gcc and MSVC don't enforce it, 'this->' is required
10380     // by the C++ standard [14.6.4] here, as the base class type is
10381     // dependent on the template argument (and thus shouldn't be
10382     // looked into when resolving InvokeWith).
10383     return this->InvokeWith(ArgumentTuple());
10384   }
10385 };
10386 
10387 template <typename R, typename A1>
10388 class FunctionMocker<R(A1)> : public
10389     internal::FunctionMockerBase<R(A1)> {
10390  public:
10391   typedef R F(A1);
10392   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10393 
10394   MockSpec<F>& With(const Matcher<A1>& m1) {
10395     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1));
10396     return this->current_spec();
10397   }
10398 
10399   R Invoke(A1 a1) {
10400     // Even though gcc and MSVC don't enforce it, 'this->' is required
10401     // by the C++ standard [14.6.4] here, as the base class type is
10402     // dependent on the template argument (and thus shouldn't be
10403     // looked into when resolving InvokeWith).
10404     return this->InvokeWith(ArgumentTuple(a1));
10405   }
10406 };
10407 
10408 template <typename R, typename A1, typename A2>
10409 class FunctionMocker<R(A1, A2)> : public
10410     internal::FunctionMockerBase<R(A1, A2)> {
10411  public:
10412   typedef R F(A1, A2);
10413   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10414 
10415   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
10416     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2));
10417     return this->current_spec();
10418   }
10419 
10420   R Invoke(A1 a1, A2 a2) {
10421     // Even though gcc and MSVC don't enforce it, 'this->' is required
10422     // by the C++ standard [14.6.4] here, as the base class type is
10423     // dependent on the template argument (and thus shouldn't be
10424     // looked into when resolving InvokeWith).
10425     return this->InvokeWith(ArgumentTuple(a1, a2));
10426   }
10427 };
10428 
10429 template <typename R, typename A1, typename A2, typename A3>
10430 class FunctionMocker<R(A1, A2, A3)> : public
10431     internal::FunctionMockerBase<R(A1, A2, A3)> {
10432  public:
10433   typedef R F(A1, A2, A3);
10434   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10435 
10436   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10437       const Matcher<A3>& m3) {
10438     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3));
10439     return this->current_spec();
10440   }
10441 
10442   R Invoke(A1 a1, A2 a2, A3 a3) {
10443     // Even though gcc and MSVC don't enforce it, 'this->' is required
10444     // by the C++ standard [14.6.4] here, as the base class type is
10445     // dependent on the template argument (and thus shouldn't be
10446     // looked into when resolving InvokeWith).
10447     return this->InvokeWith(ArgumentTuple(a1, a2, a3));
10448   }
10449 };
10450 
10451 template <typename R, typename A1, typename A2, typename A3, typename A4>
10452 class FunctionMocker<R(A1, A2, A3, A4)> : public
10453     internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
10454  public:
10455   typedef R F(A1, A2, A3, A4);
10456   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10457 
10458   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10459       const Matcher<A3>& m3, const Matcher<A4>& m4) {
10460     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4));
10461     return this->current_spec();
10462   }
10463 
10464   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
10465     // Even though gcc and MSVC don't enforce it, 'this->' is required
10466     // by the C++ standard [14.6.4] here, as the base class type is
10467     // dependent on the template argument (and thus shouldn't be
10468     // looked into when resolving InvokeWith).
10469     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
10470   }
10471 };
10472 
10473 template <typename R, typename A1, typename A2, typename A3, typename A4,
10474     typename A5>
10475 class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
10476     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
10477  public:
10478   typedef R F(A1, A2, A3, A4, A5);
10479   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10480 
10481   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10482       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
10483     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4,
10484         m5));
10485     return this->current_spec();
10486   }
10487 
10488   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
10489     // Even though gcc and MSVC don't enforce it, 'this->' is required
10490     // by the C++ standard [14.6.4] here, as the base class type is
10491     // dependent on the template argument (and thus shouldn't be
10492     // looked into when resolving InvokeWith).
10493     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
10494   }
10495 };
10496 
10497 template <typename R, typename A1, typename A2, typename A3, typename A4,
10498     typename A5, typename A6>
10499 class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
10500     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
10501  public:
10502   typedef R F(A1, A2, A3, A4, A5, A6);
10503   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10504 
10505   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10506       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10507       const Matcher<A6>& m6) {
10508     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10509         m6));
10510     return this->current_spec();
10511   }
10512 
10513   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
10514     // Even though gcc and MSVC don't enforce it, 'this->' is required
10515     // by the C++ standard [14.6.4] here, as the base class type is
10516     // dependent on the template argument (and thus shouldn't be
10517     // looked into when resolving InvokeWith).
10518     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
10519   }
10520 };
10521 
10522 template <typename R, typename A1, typename A2, typename A3, typename A4,
10523     typename A5, typename A6, typename A7>
10524 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
10525     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
10526  public:
10527   typedef R F(A1, A2, A3, A4, A5, A6, A7);
10528   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10529 
10530   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10531       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10532       const Matcher<A6>& m6, const Matcher<A7>& m7) {
10533     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10534         m6, m7));
10535     return this->current_spec();
10536   }
10537 
10538   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
10539     // Even though gcc and MSVC don't enforce it, 'this->' is required
10540     // by the C++ standard [14.6.4] here, as the base class type is
10541     // dependent on the template argument (and thus shouldn't be
10542     // looked into when resolving InvokeWith).
10543     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
10544   }
10545 };
10546 
10547 template <typename R, typename A1, typename A2, typename A3, typename A4,
10548     typename A5, typename A6, typename A7, typename A8>
10549 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
10550     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
10551  public:
10552   typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
10553   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10554 
10555   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10556       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10557       const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
10558     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10559         m6, m7, m8));
10560     return this->current_spec();
10561   }
10562 
10563   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
10564     // Even though gcc and MSVC don't enforce it, 'this->' is required
10565     // by the C++ standard [14.6.4] here, as the base class type is
10566     // dependent on the template argument (and thus shouldn't be
10567     // looked into when resolving InvokeWith).
10568     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
10569   }
10570 };
10571 
10572 template <typename R, typename A1, typename A2, typename A3, typename A4,
10573     typename A5, typename A6, typename A7, typename A8, typename A9>
10574 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
10575     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
10576  public:
10577   typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
10578   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10579 
10580   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10581       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10582       const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10583       const Matcher<A9>& m9) {
10584     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10585         m6, m7, m8, m9));
10586     return this->current_spec();
10587   }
10588 
10589   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
10590     // Even though gcc and MSVC don't enforce it, 'this->' is required
10591     // by the C++ standard [14.6.4] here, as the base class type is
10592     // dependent on the template argument (and thus shouldn't be
10593     // looked into when resolving InvokeWith).
10594     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9));
10595   }
10596 };
10597 
10598 template <typename R, typename A1, typename A2, typename A3, typename A4,
10599     typename A5, typename A6, typename A7, typename A8, typename A9,
10600     typename A10>
10601 class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
10602     internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> {
10603  public:
10604   typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
10605   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
10606 
10607   MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
10608       const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
10609       const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
10610       const Matcher<A9>& m9, const Matcher<A10>& m10) {
10611     this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
10612         m6, m7, m8, m9, m10));
10613     return this->current_spec();
10614   }
10615 
10616   R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
10617       A10 a10) {
10618     // Even though gcc and MSVC don't enforce it, 'this->' is required
10619     // by the C++ standard [14.6.4] here, as the base class type is
10620     // dependent on the template argument (and thus shouldn't be
10621     // looked into when resolving InvokeWith).
10622     return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9,
10623         a10));
10624   }
10625 };
10626 
10627 }  // namespace internal
10628 
10629 // The style guide prohibits "using" statements in a namespace scope
10630 // inside a header file.  However, the FunctionMocker class template
10631 // is meant to be defined in the ::testing namespace.  The following
10632 // line is just a trick for working around a bug in MSVC 8.0, which
10633 // cannot handle it if we define FunctionMocker in ::testing.
10634 using internal::FunctionMocker;
10635 
10636 // GMOCK_RESULT_(tn, F) expands to the result type of function type F.
10637 // We define this as a variadic macro in case F contains unprotected
10638 // commas (the same reason that we use variadic macros in other places
10639 // in this file).
10640 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10641 #define GMOCK_RESULT_(tn, ...) \
10642     tn ::testing::internal::Function<__VA_ARGS__>::Result
10643 
10644 // The type of argument N of the given function type.
10645 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10646 #define GMOCK_ARG_(tn, N, ...) \
10647     tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
10648 
10649 // The matcher type for argument N of the given function type.
10650 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10651 #define GMOCK_MATCHER_(tn, N, ...) \
10652     const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
10653 
10654 // The variable for mocking the given method.
10655 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10656 #define GMOCK_MOCKER_(arity, constness, Method) \
10657     GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
10658 
10659 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10660 #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
10661   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10662       ) constness { \
10663     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10664         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10665             == 0), \
10666         this_method_does_not_take_0_arguments); \
10667     GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
10668     return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
10669   } \
10670   ::testing::MockSpec<__VA_ARGS__>& \
10671       gmock_##Method() constness { \
10672     GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
10673     return GMOCK_MOCKER_(0, constness, Method).With(); \
10674   } \
10675   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
10676       Method)
10677 
10678 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10679 #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
10680   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10681       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10682     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10683         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10684             == 1), \
10685         this_method_does_not_take_1_argument); \
10686     GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
10687     return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
10688   } \
10689   ::testing::MockSpec<__VA_ARGS__>& \
10690       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
10691     GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
10692     return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
10693   } \
10694   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
10695       Method)
10696 
10697 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10698 #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
10699   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10700       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10701       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10702     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10703         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10704             == 2), \
10705         this_method_does_not_take_2_arguments); \
10706     GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
10707     return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
10708   } \
10709   ::testing::MockSpec<__VA_ARGS__>& \
10710       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10711                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
10712     GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
10713     return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
10714   } \
10715   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
10716       Method)
10717 
10718 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10719 #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
10720   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10721       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10722       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10723       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10724     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10725         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10726             == 3), \
10727         this_method_does_not_take_3_arguments); \
10728     GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
10729     return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
10730         gmock_a3); \
10731   } \
10732   ::testing::MockSpec<__VA_ARGS__>& \
10733       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10734                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10735                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
10736     GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
10737     return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
10738         gmock_a3); \
10739   } \
10740   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \
10741       Method)
10742 
10743 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10744 #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
10745   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10746       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10747       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10748       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10749       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10750     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10751         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10752             == 4), \
10753         this_method_does_not_take_4_arguments); \
10754     GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
10755     return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
10756         gmock_a3, gmock_a4); \
10757   } \
10758   ::testing::MockSpec<__VA_ARGS__>& \
10759       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10760                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10761                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10762                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
10763     GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
10764     return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
10765         gmock_a3, gmock_a4); \
10766   } \
10767   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \
10768       Method)
10769 
10770 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10771 #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
10772   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10773       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10774       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10775       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10776       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10777       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10778     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10779         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10780             == 5), \
10781         this_method_does_not_take_5_arguments); \
10782     GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
10783     return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
10784         gmock_a3, gmock_a4, gmock_a5); \
10785   } \
10786   ::testing::MockSpec<__VA_ARGS__>& \
10787       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10788                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10789                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10790                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10791                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
10792     GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
10793     return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
10794         gmock_a3, gmock_a4, gmock_a5); \
10795   } \
10796   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \
10797       Method)
10798 
10799 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10800 #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
10801   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10802       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10803       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10804       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10805       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10806       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10807       GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10808     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10809         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10810             == 6), \
10811         this_method_does_not_take_6_arguments); \
10812     GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
10813     return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
10814         gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10815   } \
10816   ::testing::MockSpec<__VA_ARGS__>& \
10817       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10818                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10819                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10820                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10821                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10822                      GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
10823     GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
10824     return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
10825         gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
10826   } \
10827   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \
10828       Method)
10829 
10830 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10831 #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
10832   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10833       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10834       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10835       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10836       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10837       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10838       GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10839       GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10840     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10841         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10842             == 7), \
10843         this_method_does_not_take_7_arguments); \
10844     GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
10845     return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
10846         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10847   } \
10848   ::testing::MockSpec<__VA_ARGS__>& \
10849       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10850                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10851                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10852                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10853                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10854                      GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10855                      GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
10856     GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
10857     return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
10858         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
10859   } \
10860   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \
10861       Method)
10862 
10863 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10864 #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
10865   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10866       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10867       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10868       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10869       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10870       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10871       GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10872       GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10873       GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10874     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10875         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10876             == 8), \
10877         this_method_does_not_take_8_arguments); \
10878     GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
10879     return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
10880         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10881   } \
10882   ::testing::MockSpec<__VA_ARGS__>& \
10883       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10884                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10885                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10886                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10887                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10888                      GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10889                      GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10890                      GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
10891     GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
10892     return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
10893         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
10894   } \
10895   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \
10896       Method)
10897 
10898 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10899 #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
10900   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10901       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10902       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10903       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10904       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10905       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10906       GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10907       GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10908       GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10909       GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10910     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10911         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10912             == 9), \
10913         this_method_does_not_take_9_arguments); \
10914     GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
10915     return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
10916         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10917         gmock_a9); \
10918   } \
10919   ::testing::MockSpec<__VA_ARGS__>& \
10920       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10921                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10922                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10923                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10924                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10925                      GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10926                      GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10927                      GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10928                      GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
10929     GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
10930     return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
10931         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
10932         gmock_a9); \
10933   } \
10934   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \
10935       Method)
10936 
10937 // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
10938 #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
10939   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
10940       GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
10941       GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
10942       GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
10943       GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
10944       GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
10945       GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
10946       GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
10947       GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
10948       GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
10949       GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
10950     GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size<                          \
10951         tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
10952             == 10), \
10953         this_method_does_not_take_10_arguments); \
10954     GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
10955     return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
10956         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10957         gmock_a10); \
10958   } \
10959   ::testing::MockSpec<__VA_ARGS__>& \
10960       gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
10961                      GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
10962                      GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
10963                      GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
10964                      GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
10965                      GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
10966                      GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
10967                      GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
10968                      GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
10969                      GMOCK_MATCHER_(tn, 10, \
10970                          __VA_ARGS__) gmock_a10) constness { \
10971     GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
10972     return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
10973         gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
10974         gmock_a10); \
10975   } \
10976   mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \
10977       Method)
10978 
10979 #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__)
10980 #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__)
10981 #define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
10982 #define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__)
10983 #define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__)
10984 #define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__)
10985 #define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__)
10986 #define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__)
10987 #define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__)
10988 #define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__)
10989 #define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__)
10990 
10991 #define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__)
10992 #define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__)
10993 #define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__)
10994 #define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__)
10995 #define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__)
10996 #define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__)
10997 #define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__)
10998 #define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__)
10999 #define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__)
11000 #define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__)
11001 #define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__)
11002 
11003 #define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__)
11004 #define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__)
11005 #define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__)
11006 #define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__)
11007 #define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__)
11008 #define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__)
11009 #define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__)
11010 #define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__)
11011 #define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__)
11012 #define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__)
11013 #define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__)
11014 
11015 #define MOCK_CONST_METHOD0_T(m, ...) \
11016     GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__)
11017 #define MOCK_CONST_METHOD1_T(m, ...) \
11018     GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__)
11019 #define MOCK_CONST_METHOD2_T(m, ...) \
11020     GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__)
11021 #define MOCK_CONST_METHOD3_T(m, ...) \
11022     GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__)
11023 #define MOCK_CONST_METHOD4_T(m, ...) \
11024     GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__)
11025 #define MOCK_CONST_METHOD5_T(m, ...) \
11026     GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__)
11027 #define MOCK_CONST_METHOD6_T(m, ...) \
11028     GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__)
11029 #define MOCK_CONST_METHOD7_T(m, ...) \
11030     GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__)
11031 #define MOCK_CONST_METHOD8_T(m, ...) \
11032     GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__)
11033 #define MOCK_CONST_METHOD9_T(m, ...) \
11034     GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__)
11035 #define MOCK_CONST_METHOD10_T(m, ...) \
11036     GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__)
11037 
11038 #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11039     GMOCK_METHOD0_(, , ct, m, __VA_ARGS__)
11040 #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11041     GMOCK_METHOD1_(, , ct, m, __VA_ARGS__)
11042 #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11043     GMOCK_METHOD2_(, , ct, m, __VA_ARGS__)
11044 #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11045     GMOCK_METHOD3_(, , ct, m, __VA_ARGS__)
11046 #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11047     GMOCK_METHOD4_(, , ct, m, __VA_ARGS__)
11048 #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11049     GMOCK_METHOD5_(, , ct, m, __VA_ARGS__)
11050 #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11051     GMOCK_METHOD6_(, , ct, m, __VA_ARGS__)
11052 #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11053     GMOCK_METHOD7_(, , ct, m, __VA_ARGS__)
11054 #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11055     GMOCK_METHOD8_(, , ct, m, __VA_ARGS__)
11056 #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11057     GMOCK_METHOD9_(, , ct, m, __VA_ARGS__)
11058 #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11059     GMOCK_METHOD10_(, , ct, m, __VA_ARGS__)
11060 
11061 #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
11062     GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__)
11063 #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
11064     GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__)
11065 #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
11066     GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__)
11067 #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
11068     GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__)
11069 #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
11070     GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__)
11071 #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
11072     GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__)
11073 #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
11074     GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__)
11075 #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
11076     GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__)
11077 #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
11078     GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__)
11079 #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
11080     GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__)
11081 #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
11082     GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__)
11083 
11084 #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11085     GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__)
11086 #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11087     GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__)
11088 #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11089     GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__)
11090 #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11091     GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__)
11092 #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11093     GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__)
11094 #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11095     GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__)
11096 #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11097     GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__)
11098 #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11099     GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__)
11100 #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11101     GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__)
11102 #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11103     GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__)
11104 #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11105     GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__)
11106 
11107 #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
11108     GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__)
11109 #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
11110     GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__)
11111 #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
11112     GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__)
11113 #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
11114     GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__)
11115 #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
11116     GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__)
11117 #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
11118     GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__)
11119 #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
11120     GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__)
11121 #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
11122     GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__)
11123 #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
11124     GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__)
11125 #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
11126     GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__)
11127 #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
11128     GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__)
11129 
11130 // A MockFunction<F> class has one mock method whose type is F.  It is
11131 // useful when you just want your test code to emit some messages and
11132 // have Google Mock verify the right messages are sent (and perhaps at
11133 // the right times).  For example, if you are exercising code:
11134 //
11135 //   Foo(1);
11136 //   Foo(2);
11137 //   Foo(3);
11138 //
11139 // and want to verify that Foo(1) and Foo(3) both invoke
11140 // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
11141 //
11142 // TEST(FooTest, InvokesBarCorrectly) {
11143 //   MyMock mock;
11144 //   MockFunction<void(string check_point_name)> check;
11145 //   {
11146 //     InSequence s;
11147 //
11148 //     EXPECT_CALL(mock, Bar("a"));
11149 //     EXPECT_CALL(check, Call("1"));
11150 //     EXPECT_CALL(check, Call("2"));
11151 //     EXPECT_CALL(mock, Bar("a"));
11152 //   }
11153 //   Foo(1);
11154 //   check.Call("1");
11155 //   Foo(2);
11156 //   check.Call("2");
11157 //   Foo(3);
11158 // }
11159 //
11160 // The expectation spec says that the first Bar("a") must happen
11161 // before check point "1", the second Bar("a") must happen after check
11162 // point "2", and nothing should happen between the two check
11163 // points. The explicit check points make it easy to tell which
11164 // Bar("a") is called by which call to Foo().
11165 template <typename F>
11166 class MockFunction;
11167 
11168 template <typename R>
11169 class MockFunction<R()> {
11170  public:
11171   MockFunction() {}
11172 
11173   MOCK_METHOD0_T(Call, R());
11174 
11175  private:
11176   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11177 };
11178 
11179 template <typename R, typename A0>
11180 class MockFunction<R(A0)> {
11181  public:
11182   MockFunction() {}
11183 
11184   MOCK_METHOD1_T(Call, R(A0));
11185 
11186  private:
11187   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11188 };
11189 
11190 template <typename R, typename A0, typename A1>
11191 class MockFunction<R(A0, A1)> {
11192  public:
11193   MockFunction() {}
11194 
11195   MOCK_METHOD2_T(Call, R(A0, A1));
11196 
11197  private:
11198   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11199 };
11200 
11201 template <typename R, typename A0, typename A1, typename A2>
11202 class MockFunction<R(A0, A1, A2)> {
11203  public:
11204   MockFunction() {}
11205 
11206   MOCK_METHOD3_T(Call, R(A0, A1, A2));
11207 
11208  private:
11209   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11210 };
11211 
11212 template <typename R, typename A0, typename A1, typename A2, typename A3>
11213 class MockFunction<R(A0, A1, A2, A3)> {
11214  public:
11215   MockFunction() {}
11216 
11217   MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
11218 
11219  private:
11220   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11221 };
11222 
11223 template <typename R, typename A0, typename A1, typename A2, typename A3,
11224     typename A4>
11225 class MockFunction<R(A0, A1, A2, A3, A4)> {
11226  public:
11227   MockFunction() {}
11228 
11229   MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
11230 
11231  private:
11232   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11233 };
11234 
11235 template <typename R, typename A0, typename A1, typename A2, typename A3,
11236     typename A4, typename A5>
11237 class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
11238  public:
11239   MockFunction() {}
11240 
11241   MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
11242 
11243  private:
11244   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11245 };
11246 
11247 template <typename R, typename A0, typename A1, typename A2, typename A3,
11248     typename A4, typename A5, typename A6>
11249 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
11250  public:
11251   MockFunction() {}
11252 
11253   MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
11254 
11255  private:
11256   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11257 };
11258 
11259 template <typename R, typename A0, typename A1, typename A2, typename A3,
11260     typename A4, typename A5, typename A6, typename A7>
11261 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
11262  public:
11263   MockFunction() {}
11264 
11265   MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
11266 
11267  private:
11268   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11269 };
11270 
11271 template <typename R, typename A0, typename A1, typename A2, typename A3,
11272     typename A4, typename A5, typename A6, typename A7, typename A8>
11273 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
11274  public:
11275   MockFunction() {}
11276 
11277   MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
11278 
11279  private:
11280   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11281 };
11282 
11283 template <typename R, typename A0, typename A1, typename A2, typename A3,
11284     typename A4, typename A5, typename A6, typename A7, typename A8,
11285     typename A9>
11286 class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
11287  public:
11288   MockFunction() {}
11289 
11290   MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
11291 
11292  private:
11293   GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
11294 };
11295 
11296 }  // namespace testing
11297 
11298 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
11299 // This file was GENERATED by command:
11300 //     pump.py gmock-generated-nice-strict.h.pump
11301 // DO NOT EDIT BY HAND!!!
11302 
11303 // Copyright 2008, Google Inc.
11304 // All rights reserved.
11305 //
11306 // Redistribution and use in source and binary forms, with or without
11307 // modification, are permitted provided that the following conditions are
11308 // met:
11309 //
11310 //     * Redistributions of source code must retain the above copyright
11311 // notice, this list of conditions and the following disclaimer.
11312 //     * Redistributions in binary form must reproduce the above
11313 // copyright notice, this list of conditions and the following disclaimer
11314 // in the documentation and/or other materials provided with the
11315 // distribution.
11316 //     * Neither the name of Google Inc. nor the names of its
11317 // contributors may be used to endorse or promote products derived from
11318 // this software without specific prior written permission.
11319 //
11320 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11321 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11322 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11323 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11324 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11325 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11326 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11327 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11328 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11329 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11330 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11331 //
11332 // Author: wan@google.com (Zhanyong Wan)
11333 
11334 // Implements class templates NiceMock, NaggyMock, and StrictMock.
11335 //
11336 // Given a mock class MockFoo that is created using Google Mock,
11337 // NiceMock<MockFoo> is a subclass of MockFoo that allows
11338 // uninteresting calls (i.e. calls to mock methods that have no
11339 // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
11340 // that prints a warning when an uninteresting call occurs, and
11341 // StrictMock<MockFoo> is a subclass of MockFoo that treats all
11342 // uninteresting calls as errors.
11343 //
11344 // Currently a mock is naggy by default, so MockFoo and
11345 // NaggyMock<MockFoo> behave like the same.  However, we will soon
11346 // switch the default behavior of mocks to be nice, as that in general
11347 // leads to more maintainable tests.  When that happens, MockFoo will
11348 // stop behaving like NaggyMock<MockFoo> and start behaving like
11349 // NiceMock<MockFoo>.
11350 //
11351 // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
11352 // their respective base class, with up-to 10 arguments.  Therefore
11353 // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
11354 // where MockFoo has a constructor that accepts (int, const char*),
11355 // for example.
11356 //
11357 // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
11358 // and StrictMock<MockFoo> only works for mock methods defined using
11359 // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
11360 // If a mock method is defined in a base class of MockFoo, the "nice"
11361 // or "strict" modifier may not affect it, depending on the compiler.
11362 // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
11363 // supported.
11364 //
11365 // Another known limitation is that the constructors of the base mock
11366 // cannot have arguments passed by non-const reference, which are
11367 // banned by the Google C++ style guide anyway.
11368 
11369 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11370 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11371 
11372 
11373 namespace testing {
11374 
11375 template <class MockClass>
11376 class NiceMock : public MockClass {
11377  public:
11378   // We don't factor out the constructor body to a common method, as
11379   // we have to avoid a possible clash with members of MockClass.
11380   NiceMock() {
11381     ::testing::Mock::AllowUninterestingCalls(
11382         internal::ImplicitCast_<MockClass*>(this));
11383   }
11384 
11385   // C++ doesn't (yet) allow inheritance of constructors, so we have
11386   // to define it for each arity.
11387   template <typename A1>
11388   explicit NiceMock(const A1& a1) : MockClass(a1) {
11389     ::testing::Mock::AllowUninterestingCalls(
11390         internal::ImplicitCast_<MockClass*>(this));
11391   }
11392   template <typename A1, typename A2>
11393   NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11394     ::testing::Mock::AllowUninterestingCalls(
11395         internal::ImplicitCast_<MockClass*>(this));
11396   }
11397 
11398   template <typename A1, typename A2, typename A3>
11399   NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11400     ::testing::Mock::AllowUninterestingCalls(
11401         internal::ImplicitCast_<MockClass*>(this));
11402   }
11403 
11404   template <typename A1, typename A2, typename A3, typename A4>
11405   NiceMock(const A1& a1, const A2& a2, const A3& a3,
11406       const A4& a4) : MockClass(a1, a2, a3, a4) {
11407     ::testing::Mock::AllowUninterestingCalls(
11408         internal::ImplicitCast_<MockClass*>(this));
11409   }
11410 
11411   template <typename A1, typename A2, typename A3, typename A4, typename A5>
11412   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11413       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11414     ::testing::Mock::AllowUninterestingCalls(
11415         internal::ImplicitCast_<MockClass*>(this));
11416   }
11417 
11418   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11419       typename A6>
11420   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11421       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11422     ::testing::Mock::AllowUninterestingCalls(
11423         internal::ImplicitCast_<MockClass*>(this));
11424   }
11425 
11426   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11427       typename A6, typename A7>
11428   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11429       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11430       a6, a7) {
11431     ::testing::Mock::AllowUninterestingCalls(
11432         internal::ImplicitCast_<MockClass*>(this));
11433   }
11434 
11435   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11436       typename A6, typename A7, typename A8>
11437   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11438       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11439       a2, a3, a4, a5, a6, a7, a8) {
11440     ::testing::Mock::AllowUninterestingCalls(
11441         internal::ImplicitCast_<MockClass*>(this));
11442   }
11443 
11444   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11445       typename A6, typename A7, typename A8, typename A9>
11446   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11447       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11448       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11449     ::testing::Mock::AllowUninterestingCalls(
11450         internal::ImplicitCast_<MockClass*>(this));
11451   }
11452 
11453   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11454       typename A6, typename A7, typename A8, typename A9, typename A10>
11455   NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11456       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11457       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11458     ::testing::Mock::AllowUninterestingCalls(
11459         internal::ImplicitCast_<MockClass*>(this));
11460   }
11461 
11462   virtual ~NiceMock() {
11463     ::testing::Mock::UnregisterCallReaction(
11464         internal::ImplicitCast_<MockClass*>(this));
11465   }
11466 
11467  private:
11468   GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
11469 };
11470 
11471 template <class MockClass>
11472 class NaggyMock : public MockClass {
11473  public:
11474   // We don't factor out the constructor body to a common method, as
11475   // we have to avoid a possible clash with members of MockClass.
11476   NaggyMock() {
11477     ::testing::Mock::WarnUninterestingCalls(
11478         internal::ImplicitCast_<MockClass*>(this));
11479   }
11480 
11481   // C++ doesn't (yet) allow inheritance of constructors, so we have
11482   // to define it for each arity.
11483   template <typename A1>
11484   explicit NaggyMock(const A1& a1) : MockClass(a1) {
11485     ::testing::Mock::WarnUninterestingCalls(
11486         internal::ImplicitCast_<MockClass*>(this));
11487   }
11488   template <typename A1, typename A2>
11489   NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11490     ::testing::Mock::WarnUninterestingCalls(
11491         internal::ImplicitCast_<MockClass*>(this));
11492   }
11493 
11494   template <typename A1, typename A2, typename A3>
11495   NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11496     ::testing::Mock::WarnUninterestingCalls(
11497         internal::ImplicitCast_<MockClass*>(this));
11498   }
11499 
11500   template <typename A1, typename A2, typename A3, typename A4>
11501   NaggyMock(const A1& a1, const A2& a2, const A3& a3,
11502       const A4& a4) : MockClass(a1, a2, a3, a4) {
11503     ::testing::Mock::WarnUninterestingCalls(
11504         internal::ImplicitCast_<MockClass*>(this));
11505   }
11506 
11507   template <typename A1, typename A2, typename A3, typename A4, typename A5>
11508   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11509       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11510     ::testing::Mock::WarnUninterestingCalls(
11511         internal::ImplicitCast_<MockClass*>(this));
11512   }
11513 
11514   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11515       typename A6>
11516   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11517       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11518     ::testing::Mock::WarnUninterestingCalls(
11519         internal::ImplicitCast_<MockClass*>(this));
11520   }
11521 
11522   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11523       typename A6, typename A7>
11524   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11525       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11526       a6, a7) {
11527     ::testing::Mock::WarnUninterestingCalls(
11528         internal::ImplicitCast_<MockClass*>(this));
11529   }
11530 
11531   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11532       typename A6, typename A7, typename A8>
11533   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11534       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11535       a2, a3, a4, a5, a6, a7, a8) {
11536     ::testing::Mock::WarnUninterestingCalls(
11537         internal::ImplicitCast_<MockClass*>(this));
11538   }
11539 
11540   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11541       typename A6, typename A7, typename A8, typename A9>
11542   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11543       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11544       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11545     ::testing::Mock::WarnUninterestingCalls(
11546         internal::ImplicitCast_<MockClass*>(this));
11547   }
11548 
11549   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11550       typename A6, typename A7, typename A8, typename A9, typename A10>
11551   NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11552       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11553       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11554     ::testing::Mock::WarnUninterestingCalls(
11555         internal::ImplicitCast_<MockClass*>(this));
11556   }
11557 
11558   virtual ~NaggyMock() {
11559     ::testing::Mock::UnregisterCallReaction(
11560         internal::ImplicitCast_<MockClass*>(this));
11561   }
11562 
11563  private:
11564   GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
11565 };
11566 
11567 template <class MockClass>
11568 class StrictMock : public MockClass {
11569  public:
11570   // We don't factor out the constructor body to a common method, as
11571   // we have to avoid a possible clash with members of MockClass.
11572   StrictMock() {
11573     ::testing::Mock::FailUninterestingCalls(
11574         internal::ImplicitCast_<MockClass*>(this));
11575   }
11576 
11577   // C++ doesn't (yet) allow inheritance of constructors, so we have
11578   // to define it for each arity.
11579   template <typename A1>
11580   explicit StrictMock(const A1& a1) : MockClass(a1) {
11581     ::testing::Mock::FailUninterestingCalls(
11582         internal::ImplicitCast_<MockClass*>(this));
11583   }
11584   template <typename A1, typename A2>
11585   StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
11586     ::testing::Mock::FailUninterestingCalls(
11587         internal::ImplicitCast_<MockClass*>(this));
11588   }
11589 
11590   template <typename A1, typename A2, typename A3>
11591   StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
11592     ::testing::Mock::FailUninterestingCalls(
11593         internal::ImplicitCast_<MockClass*>(this));
11594   }
11595 
11596   template <typename A1, typename A2, typename A3, typename A4>
11597   StrictMock(const A1& a1, const A2& a2, const A3& a3,
11598       const A4& a4) : MockClass(a1, a2, a3, a4) {
11599     ::testing::Mock::FailUninterestingCalls(
11600         internal::ImplicitCast_<MockClass*>(this));
11601   }
11602 
11603   template <typename A1, typename A2, typename A3, typename A4, typename A5>
11604   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11605       const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
11606     ::testing::Mock::FailUninterestingCalls(
11607         internal::ImplicitCast_<MockClass*>(this));
11608   }
11609 
11610   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11611       typename A6>
11612   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11613       const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
11614     ::testing::Mock::FailUninterestingCalls(
11615         internal::ImplicitCast_<MockClass*>(this));
11616   }
11617 
11618   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11619       typename A6, typename A7>
11620   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11621       const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
11622       a6, a7) {
11623     ::testing::Mock::FailUninterestingCalls(
11624         internal::ImplicitCast_<MockClass*>(this));
11625   }
11626 
11627   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11628       typename A6, typename A7, typename A8>
11629   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11630       const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
11631       a2, a3, a4, a5, a6, a7, a8) {
11632     ::testing::Mock::FailUninterestingCalls(
11633         internal::ImplicitCast_<MockClass*>(this));
11634   }
11635 
11636   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11637       typename A6, typename A7, typename A8, typename A9>
11638   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11639       const A5& a5, const A6& a6, const A7& a7, const A8& a8,
11640       const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
11641     ::testing::Mock::FailUninterestingCalls(
11642         internal::ImplicitCast_<MockClass*>(this));
11643   }
11644 
11645   template <typename A1, typename A2, typename A3, typename A4, typename A5,
11646       typename A6, typename A7, typename A8, typename A9, typename A10>
11647   StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
11648       const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
11649       const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
11650     ::testing::Mock::FailUninterestingCalls(
11651         internal::ImplicitCast_<MockClass*>(this));
11652   }
11653 
11654   virtual ~StrictMock() {
11655     ::testing::Mock::UnregisterCallReaction(
11656         internal::ImplicitCast_<MockClass*>(this));
11657   }
11658 
11659  private:
11660   GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
11661 };
11662 
11663 // The following specializations catch some (relatively more common)
11664 // user errors of nesting nice and strict mocks.  They do NOT catch
11665 // all possible errors.
11666 
11667 // These specializations are declared but not defined, as NiceMock,
11668 // NaggyMock, and StrictMock cannot be nested.
11669 
11670 template <typename MockClass>
11671 class NiceMock<NiceMock<MockClass> >;
11672 template <typename MockClass>
11673 class NiceMock<NaggyMock<MockClass> >;
11674 template <typename MockClass>
11675 class NiceMock<StrictMock<MockClass> >;
11676 
11677 template <typename MockClass>
11678 class NaggyMock<NiceMock<MockClass> >;
11679 template <typename MockClass>
11680 class NaggyMock<NaggyMock<MockClass> >;
11681 template <typename MockClass>
11682 class NaggyMock<StrictMock<MockClass> >;
11683 
11684 template <typename MockClass>
11685 class StrictMock<NiceMock<MockClass> >;
11686 template <typename MockClass>
11687 class StrictMock<NaggyMock<MockClass> >;
11688 template <typename MockClass>
11689 class StrictMock<StrictMock<MockClass> >;
11690 
11691 }  // namespace testing
11692 
11693 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
11694 // This file was GENERATED by command:
11695 //     pump.py gmock-generated-matchers.h.pump
11696 // DO NOT EDIT BY HAND!!!
11697 
11698 // Copyright 2008, Google Inc.
11699 // All rights reserved.
11700 //
11701 // Redistribution and use in source and binary forms, with or without
11702 // modification, are permitted provided that the following conditions are
11703 // met:
11704 //
11705 //     * Redistributions of source code must retain the above copyright
11706 // notice, this list of conditions and the following disclaimer.
11707 //     * Redistributions in binary form must reproduce the above
11708 // copyright notice, this list of conditions and the following disclaimer
11709 // in the documentation and/or other materials provided with the
11710 // distribution.
11711 //     * Neither the name of Google Inc. nor the names of its
11712 // contributors may be used to endorse or promote products derived from
11713 // this software without specific prior written permission.
11714 //
11715 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11716 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11717 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11718 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11719 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11720 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11721 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11722 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11723 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11724 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11725 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11726 
11727 // Google Mock - a framework for writing C++ mock classes.
11728 //
11729 // This file implements some commonly used variadic matchers.
11730 
11731 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11732 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
11733 
11734 #include <iterator>
11735 #include <sstream>
11736 #include <string>
11737 #include <vector>
11738 
11739 namespace testing {
11740 namespace internal {
11741 
11742 // The type of the i-th (0-based) field of Tuple.
11743 #define GMOCK_FIELD_TYPE_(Tuple, i) \
11744     typename ::std::tr1::tuple_element<i, Tuple>::type
11745 
11746 // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
11747 // tuple of type Tuple.  It has two members:
11748 //
11749 //   type: a tuple type whose i-th field is the ki-th field of Tuple.
11750 //   GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
11751 //
11752 // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
11753 //
11754 //   type is tuple<int, bool>, and
11755 //   GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
11756 
11757 template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11758     int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11759     int k9 = -1>
11760 class TupleFields;
11761 
11762 // This generic version is used when there are 10 selectors.
11763 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11764     int k7, int k8, int k9>
11765 class TupleFields {
11766  public:
11767   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11768       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11769       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11770       GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11771       GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
11772       GMOCK_FIELD_TYPE_(Tuple, k9)> type;
11773   static type GetSelectedFields(const Tuple& t) {
11774     using ::std::tr1::get;
11775     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11776         get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
11777   }
11778 };
11779 
11780 // The following specialization is used for 0 ~ 9 selectors.
11781 
11782 template <class Tuple>
11783 class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11784  public:
11785   typedef ::std::tr1::tuple<> type;
11786   static type GetSelectedFields(const Tuple& /* t */) {
11787     using ::std::tr1::get;
11788     return type();
11789   }
11790 };
11791 
11792 template <class Tuple, int k0>
11793 class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
11794  public:
11795   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
11796   static type GetSelectedFields(const Tuple& t) {
11797     using ::std::tr1::get;
11798     return type(get<k0>(t));
11799   }
11800 };
11801 
11802 template <class Tuple, int k0, int k1>
11803 class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
11804  public:
11805   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11806       GMOCK_FIELD_TYPE_(Tuple, k1)> type;
11807   static type GetSelectedFields(const Tuple& t) {
11808     using ::std::tr1::get;
11809     return type(get<k0>(t), get<k1>(t));
11810   }
11811 };
11812 
11813 template <class Tuple, int k0, int k1, int k2>
11814 class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
11815  public:
11816   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11817       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
11818   static type GetSelectedFields(const Tuple& t) {
11819     using ::std::tr1::get;
11820     return type(get<k0>(t), get<k1>(t), get<k2>(t));
11821   }
11822 };
11823 
11824 template <class Tuple, int k0, int k1, int k2, int k3>
11825 class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
11826  public:
11827   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11828       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11829       GMOCK_FIELD_TYPE_(Tuple, k3)> type;
11830   static type GetSelectedFields(const Tuple& t) {
11831     using ::std::tr1::get;
11832     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
11833   }
11834 };
11835 
11836 template <class Tuple, int k0, int k1, int k2, int k3, int k4>
11837 class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
11838  public:
11839   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11840       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11841       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
11842   static type GetSelectedFields(const Tuple& t) {
11843     using ::std::tr1::get;
11844     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
11845   }
11846 };
11847 
11848 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
11849 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
11850  public:
11851   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11852       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11853       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11854       GMOCK_FIELD_TYPE_(Tuple, k5)> type;
11855   static type GetSelectedFields(const Tuple& t) {
11856     using ::std::tr1::get;
11857     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11858         get<k5>(t));
11859   }
11860 };
11861 
11862 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
11863 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
11864  public:
11865   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11866       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11867       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11868       GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
11869   static type GetSelectedFields(const Tuple& t) {
11870     using ::std::tr1::get;
11871     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11872         get<k5>(t), get<k6>(t));
11873   }
11874 };
11875 
11876 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11877     int k7>
11878 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
11879  public:
11880   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11881       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11882       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11883       GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11884       GMOCK_FIELD_TYPE_(Tuple, k7)> type;
11885   static type GetSelectedFields(const Tuple& t) {
11886     using ::std::tr1::get;
11887     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11888         get<k5>(t), get<k6>(t), get<k7>(t));
11889   }
11890 };
11891 
11892 template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
11893     int k7, int k8>
11894 class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
11895  public:
11896   typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
11897       GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
11898       GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
11899       GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
11900       GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
11901   static type GetSelectedFields(const Tuple& t) {
11902     using ::std::tr1::get;
11903     return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
11904         get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
11905   }
11906 };
11907 
11908 #undef GMOCK_FIELD_TYPE_
11909 
11910 // Implements the Args() matcher.
11911 template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
11912     int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
11913     int k9 = -1>
11914 class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
11915  public:
11916   // ArgsTuple may have top-level const or reference modifiers.
11917   typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
11918   typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
11919       k6, k7, k8, k9>::type SelectedArgs;
11920   typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
11921 
11922   template <typename InnerMatcher>
11923   explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
11924       : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
11925 
11926   virtual bool MatchAndExplain(ArgsTuple args,
11927                                MatchResultListener* listener) const {
11928     const SelectedArgs& selected_args = GetSelectedArgs(args);
11929     if (!listener->IsInterested())
11930       return inner_matcher_.Matches(selected_args);
11931 
11932     PrintIndices(listener->stream());
11933     *listener << "are " << PrintToString(selected_args);
11934 
11935     StringMatchResultListener inner_listener;
11936     const bool match = inner_matcher_.MatchAndExplain(selected_args,
11937                                                       &inner_listener);
11938     PrintIfNotEmpty(inner_listener.str(), listener->stream());
11939     return match;
11940   }
11941 
11942   virtual void DescribeTo(::std::ostream* os) const {
11943     *os << "are a tuple ";
11944     PrintIndices(os);
11945     inner_matcher_.DescribeTo(os);
11946   }
11947 
11948   virtual void DescribeNegationTo(::std::ostream* os) const {
11949     *os << "are a tuple ";
11950     PrintIndices(os);
11951     inner_matcher_.DescribeNegationTo(os);
11952   }
11953 
11954  private:
11955   static SelectedArgs GetSelectedArgs(ArgsTuple args) {
11956     return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
11957         k9>::GetSelectedFields(args);
11958   }
11959 
11960   // Prints the indices of the selected fields.
11961   static void PrintIndices(::std::ostream* os) {
11962     *os << "whose fields (";
11963     const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
11964     for (int i = 0; i < 10; i++) {
11965       if (indices[i] < 0)
11966         break;
11967 
11968       if (i >= 1)
11969         *os << ", ";
11970 
11971       *os << "#" << indices[i];
11972     }
11973     *os << ") ";
11974   }
11975 
11976   const MonomorphicInnerMatcher inner_matcher_;
11977 
11978   GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
11979 };
11980 
11981 template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
11982     int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
11983     int k8 = -1, int k9 = -1>
11984 class ArgsMatcher {
11985  public:
11986   explicit ArgsMatcher(const InnerMatcher& inner_matcher)
11987       : inner_matcher_(inner_matcher) {}
11988 
11989   template <typename ArgsTuple>
11990   operator Matcher<ArgsTuple>() const {
11991     return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
11992         k6, k7, k8, k9>(inner_matcher_));
11993   }
11994 
11995  private:
11996   const InnerMatcher inner_matcher_;
11997 
11998   GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
11999 };
12000 
12001 // A set of metafunctions for computing the result type of AllOf.
12002 // AllOf(m1, ..., mN) returns
12003 // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
12004 
12005 // Although AllOf isn't defined for one argument, AllOfResult1 is defined
12006 // to simplify the implementation.
12007 template <typename M1>
12008 struct AllOfResult1 {
12009   typedef M1 type;
12010 };
12011 
12012 template <typename M1, typename M2>
12013 struct AllOfResult2 {
12014   typedef BothOfMatcher<
12015       typename AllOfResult1<M1>::type,
12016       typename AllOfResult1<M2>::type
12017   > type;
12018 };
12019 
12020 template <typename M1, typename M2, typename M3>
12021 struct AllOfResult3 {
12022   typedef BothOfMatcher<
12023       typename AllOfResult1<M1>::type,
12024       typename AllOfResult2<M2, M3>::type
12025   > type;
12026 };
12027 
12028 template <typename M1, typename M2, typename M3, typename M4>
12029 struct AllOfResult4 {
12030   typedef BothOfMatcher<
12031       typename AllOfResult2<M1, M2>::type,
12032       typename AllOfResult2<M3, M4>::type
12033   > type;
12034 };
12035 
12036 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12037 struct AllOfResult5 {
12038   typedef BothOfMatcher<
12039       typename AllOfResult2<M1, M2>::type,
12040       typename AllOfResult3<M3, M4, M5>::type
12041   > type;
12042 };
12043 
12044 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12045     typename M6>
12046 struct AllOfResult6 {
12047   typedef BothOfMatcher<
12048       typename AllOfResult3<M1, M2, M3>::type,
12049       typename AllOfResult3<M4, M5, M6>::type
12050   > type;
12051 };
12052 
12053 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12054     typename M6, typename M7>
12055 struct AllOfResult7 {
12056   typedef BothOfMatcher<
12057       typename AllOfResult3<M1, M2, M3>::type,
12058       typename AllOfResult4<M4, M5, M6, M7>::type
12059   > type;
12060 };
12061 
12062 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12063     typename M6, typename M7, typename M8>
12064 struct AllOfResult8 {
12065   typedef BothOfMatcher<
12066       typename AllOfResult4<M1, M2, M3, M4>::type,
12067       typename AllOfResult4<M5, M6, M7, M8>::type
12068   > type;
12069 };
12070 
12071 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12072     typename M6, typename M7, typename M8, typename M9>
12073 struct AllOfResult9 {
12074   typedef BothOfMatcher<
12075       typename AllOfResult4<M1, M2, M3, M4>::type,
12076       typename AllOfResult5<M5, M6, M7, M8, M9>::type
12077   > type;
12078 };
12079 
12080 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12081     typename M6, typename M7, typename M8, typename M9, typename M10>
12082 struct AllOfResult10 {
12083   typedef BothOfMatcher<
12084       typename AllOfResult5<M1, M2, M3, M4, M5>::type,
12085       typename AllOfResult5<M6, M7, M8, M9, M10>::type
12086   > type;
12087 };
12088 
12089 // A set of metafunctions for computing the result type of AnyOf.
12090 // AnyOf(m1, ..., mN) returns
12091 // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
12092 
12093 // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
12094 // to simplify the implementation.
12095 template <typename M1>
12096 struct AnyOfResult1 {
12097   typedef M1 type;
12098 };
12099 
12100 template <typename M1, typename M2>
12101 struct AnyOfResult2 {
12102   typedef EitherOfMatcher<
12103       typename AnyOfResult1<M1>::type,
12104       typename AnyOfResult1<M2>::type
12105   > type;
12106 };
12107 
12108 template <typename M1, typename M2, typename M3>
12109 struct AnyOfResult3 {
12110   typedef EitherOfMatcher<
12111       typename AnyOfResult1<M1>::type,
12112       typename AnyOfResult2<M2, M3>::type
12113   > type;
12114 };
12115 
12116 template <typename M1, typename M2, typename M3, typename M4>
12117 struct AnyOfResult4 {
12118   typedef EitherOfMatcher<
12119       typename AnyOfResult2<M1, M2>::type,
12120       typename AnyOfResult2<M3, M4>::type
12121   > type;
12122 };
12123 
12124 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12125 struct AnyOfResult5 {
12126   typedef EitherOfMatcher<
12127       typename AnyOfResult2<M1, M2>::type,
12128       typename AnyOfResult3<M3, M4, M5>::type
12129   > type;
12130 };
12131 
12132 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12133     typename M6>
12134 struct AnyOfResult6 {
12135   typedef EitherOfMatcher<
12136       typename AnyOfResult3<M1, M2, M3>::type,
12137       typename AnyOfResult3<M4, M5, M6>::type
12138   > type;
12139 };
12140 
12141 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12142     typename M6, typename M7>
12143 struct AnyOfResult7 {
12144   typedef EitherOfMatcher<
12145       typename AnyOfResult3<M1, M2, M3>::type,
12146       typename AnyOfResult4<M4, M5, M6, M7>::type
12147   > type;
12148 };
12149 
12150 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12151     typename M6, typename M7, typename M8>
12152 struct AnyOfResult8 {
12153   typedef EitherOfMatcher<
12154       typename AnyOfResult4<M1, M2, M3, M4>::type,
12155       typename AnyOfResult4<M5, M6, M7, M8>::type
12156   > type;
12157 };
12158 
12159 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12160     typename M6, typename M7, typename M8, typename M9>
12161 struct AnyOfResult9 {
12162   typedef EitherOfMatcher<
12163       typename AnyOfResult4<M1, M2, M3, M4>::type,
12164       typename AnyOfResult5<M5, M6, M7, M8, M9>::type
12165   > type;
12166 };
12167 
12168 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12169     typename M6, typename M7, typename M8, typename M9, typename M10>
12170 struct AnyOfResult10 {
12171   typedef EitherOfMatcher<
12172       typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
12173       typename AnyOfResult5<M6, M7, M8, M9, M10>::type
12174   > type;
12175 };
12176 
12177 }  // namespace internal
12178 
12179 // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
12180 // fields of it matches a_matcher.  C++ doesn't support default
12181 // arguments for function templates, so we have to overload it.
12182 template <typename InnerMatcher>
12183 inline internal::ArgsMatcher<InnerMatcher>
12184 Args(const InnerMatcher& matcher) {
12185   return internal::ArgsMatcher<InnerMatcher>(matcher);
12186 }
12187 
12188 template <int k1, typename InnerMatcher>
12189 inline internal::ArgsMatcher<InnerMatcher, k1>
12190 Args(const InnerMatcher& matcher) {
12191   return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
12192 }
12193 
12194 template <int k1, int k2, typename InnerMatcher>
12195 inline internal::ArgsMatcher<InnerMatcher, k1, k2>
12196 Args(const InnerMatcher& matcher) {
12197   return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
12198 }
12199 
12200 template <int k1, int k2, int k3, typename InnerMatcher>
12201 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
12202 Args(const InnerMatcher& matcher) {
12203   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
12204 }
12205 
12206 template <int k1, int k2, int k3, int k4, typename InnerMatcher>
12207 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
12208 Args(const InnerMatcher& matcher) {
12209   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
12210 }
12211 
12212 template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
12213 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
12214 Args(const InnerMatcher& matcher) {
12215   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
12216 }
12217 
12218 template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
12219 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
12220 Args(const InnerMatcher& matcher) {
12221   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
12222 }
12223 
12224 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
12225     typename InnerMatcher>
12226 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
12227 Args(const InnerMatcher& matcher) {
12228   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
12229       k7>(matcher);
12230 }
12231 
12232 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12233     typename InnerMatcher>
12234 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
12235 Args(const InnerMatcher& matcher) {
12236   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
12237       k8>(matcher);
12238 }
12239 
12240 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12241     int k9, typename InnerMatcher>
12242 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
12243 Args(const InnerMatcher& matcher) {
12244   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12245       k9>(matcher);
12246 }
12247 
12248 template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
12249     int k9, int k10, typename InnerMatcher>
12250 inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
12251     k10>
12252 Args(const InnerMatcher& matcher) {
12253   return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
12254       k9, k10>(matcher);
12255 }
12256 
12257 // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
12258 // n elements, where the i-th element in the container must
12259 // match the i-th argument in the list.  Each argument of
12260 // ElementsAre() can be either a value or a matcher.  We support up to
12261 // 10 arguments.
12262 //
12263 // The use of DecayArray in the implementation allows ElementsAre()
12264 // to accept string literals, whose type is const char[N], but we
12265 // want to treat them as const char*.
12266 //
12267 // NOTE: Since ElementsAre() cares about the order of the elements, it
12268 // must not be used with containers whose elements's order is
12269 // undefined (e.g. hash_map).
12270 
12271 inline internal::ElementsAreMatcher<
12272     std::tr1::tuple<> >
12273 ElementsAre() {
12274   typedef std::tr1::tuple<> Args;
12275   return internal::ElementsAreMatcher<Args>(Args());
12276 }
12277 
12278 template <typename T1>
12279 inline internal::ElementsAreMatcher<
12280     std::tr1::tuple<
12281         typename internal::DecayArray<T1>::type> >
12282 ElementsAre(const T1& e1) {
12283   typedef std::tr1::tuple<
12284       typename internal::DecayArray<T1>::type> Args;
12285   return internal::ElementsAreMatcher<Args>(Args(e1));
12286 }
12287 
12288 template <typename T1, typename T2>
12289 inline internal::ElementsAreMatcher<
12290     std::tr1::tuple<
12291         typename internal::DecayArray<T1>::type,
12292         typename internal::DecayArray<T2>::type> >
12293 ElementsAre(const T1& e1, const T2& e2) {
12294   typedef std::tr1::tuple<
12295       typename internal::DecayArray<T1>::type,
12296       typename internal::DecayArray<T2>::type> Args;
12297   return internal::ElementsAreMatcher<Args>(Args(e1, e2));
12298 }
12299 
12300 template <typename T1, typename T2, typename T3>
12301 inline internal::ElementsAreMatcher<
12302     std::tr1::tuple<
12303         typename internal::DecayArray<T1>::type,
12304         typename internal::DecayArray<T2>::type,
12305         typename internal::DecayArray<T3>::type> >
12306 ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12307   typedef std::tr1::tuple<
12308       typename internal::DecayArray<T1>::type,
12309       typename internal::DecayArray<T2>::type,
12310       typename internal::DecayArray<T3>::type> Args;
12311   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
12312 }
12313 
12314 template <typename T1, typename T2, typename T3, typename T4>
12315 inline internal::ElementsAreMatcher<
12316     std::tr1::tuple<
12317         typename internal::DecayArray<T1>::type,
12318         typename internal::DecayArray<T2>::type,
12319         typename internal::DecayArray<T3>::type,
12320         typename internal::DecayArray<T4>::type> >
12321 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12322   typedef std::tr1::tuple<
12323       typename internal::DecayArray<T1>::type,
12324       typename internal::DecayArray<T2>::type,
12325       typename internal::DecayArray<T3>::type,
12326       typename internal::DecayArray<T4>::type> Args;
12327   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12328 }
12329 
12330 template <typename T1, typename T2, typename T3, typename T4, typename T5>
12331 inline internal::ElementsAreMatcher<
12332     std::tr1::tuple<
12333         typename internal::DecayArray<T1>::type,
12334         typename internal::DecayArray<T2>::type,
12335         typename internal::DecayArray<T3>::type,
12336         typename internal::DecayArray<T4>::type,
12337         typename internal::DecayArray<T5>::type> >
12338 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12339     const T5& e5) {
12340   typedef std::tr1::tuple<
12341       typename internal::DecayArray<T1>::type,
12342       typename internal::DecayArray<T2>::type,
12343       typename internal::DecayArray<T3>::type,
12344       typename internal::DecayArray<T4>::type,
12345       typename internal::DecayArray<T5>::type> Args;
12346   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12347 }
12348 
12349 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12350     typename T6>
12351 inline internal::ElementsAreMatcher<
12352     std::tr1::tuple<
12353         typename internal::DecayArray<T1>::type,
12354         typename internal::DecayArray<T2>::type,
12355         typename internal::DecayArray<T3>::type,
12356         typename internal::DecayArray<T4>::type,
12357         typename internal::DecayArray<T5>::type,
12358         typename internal::DecayArray<T6>::type> >
12359 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12360     const T5& e5, const T6& e6) {
12361   typedef std::tr1::tuple<
12362       typename internal::DecayArray<T1>::type,
12363       typename internal::DecayArray<T2>::type,
12364       typename internal::DecayArray<T3>::type,
12365       typename internal::DecayArray<T4>::type,
12366       typename internal::DecayArray<T5>::type,
12367       typename internal::DecayArray<T6>::type> Args;
12368   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
12369 }
12370 
12371 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12372     typename T6, typename T7>
12373 inline internal::ElementsAreMatcher<
12374     std::tr1::tuple<
12375         typename internal::DecayArray<T1>::type,
12376         typename internal::DecayArray<T2>::type,
12377         typename internal::DecayArray<T3>::type,
12378         typename internal::DecayArray<T4>::type,
12379         typename internal::DecayArray<T5>::type,
12380         typename internal::DecayArray<T6>::type,
12381         typename internal::DecayArray<T7>::type> >
12382 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12383     const T5& e5, const T6& e6, const T7& e7) {
12384   typedef std::tr1::tuple<
12385       typename internal::DecayArray<T1>::type,
12386       typename internal::DecayArray<T2>::type,
12387       typename internal::DecayArray<T3>::type,
12388       typename internal::DecayArray<T4>::type,
12389       typename internal::DecayArray<T5>::type,
12390       typename internal::DecayArray<T6>::type,
12391       typename internal::DecayArray<T7>::type> Args;
12392   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
12393 }
12394 
12395 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12396     typename T6, typename T7, typename T8>
12397 inline internal::ElementsAreMatcher<
12398     std::tr1::tuple<
12399         typename internal::DecayArray<T1>::type,
12400         typename internal::DecayArray<T2>::type,
12401         typename internal::DecayArray<T3>::type,
12402         typename internal::DecayArray<T4>::type,
12403         typename internal::DecayArray<T5>::type,
12404         typename internal::DecayArray<T6>::type,
12405         typename internal::DecayArray<T7>::type,
12406         typename internal::DecayArray<T8>::type> >
12407 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12408     const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12409   typedef std::tr1::tuple<
12410       typename internal::DecayArray<T1>::type,
12411       typename internal::DecayArray<T2>::type,
12412       typename internal::DecayArray<T3>::type,
12413       typename internal::DecayArray<T4>::type,
12414       typename internal::DecayArray<T5>::type,
12415       typename internal::DecayArray<T6>::type,
12416       typename internal::DecayArray<T7>::type,
12417       typename internal::DecayArray<T8>::type> Args;
12418   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12419       e8));
12420 }
12421 
12422 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12423     typename T6, typename T7, typename T8, typename T9>
12424 inline internal::ElementsAreMatcher<
12425     std::tr1::tuple<
12426         typename internal::DecayArray<T1>::type,
12427         typename internal::DecayArray<T2>::type,
12428         typename internal::DecayArray<T3>::type,
12429         typename internal::DecayArray<T4>::type,
12430         typename internal::DecayArray<T5>::type,
12431         typename internal::DecayArray<T6>::type,
12432         typename internal::DecayArray<T7>::type,
12433         typename internal::DecayArray<T8>::type,
12434         typename internal::DecayArray<T9>::type> >
12435 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12436     const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12437   typedef std::tr1::tuple<
12438       typename internal::DecayArray<T1>::type,
12439       typename internal::DecayArray<T2>::type,
12440       typename internal::DecayArray<T3>::type,
12441       typename internal::DecayArray<T4>::type,
12442       typename internal::DecayArray<T5>::type,
12443       typename internal::DecayArray<T6>::type,
12444       typename internal::DecayArray<T7>::type,
12445       typename internal::DecayArray<T8>::type,
12446       typename internal::DecayArray<T9>::type> Args;
12447   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12448       e8, e9));
12449 }
12450 
12451 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12452     typename T6, typename T7, typename T8, typename T9, typename T10>
12453 inline internal::ElementsAreMatcher<
12454     std::tr1::tuple<
12455         typename internal::DecayArray<T1>::type,
12456         typename internal::DecayArray<T2>::type,
12457         typename internal::DecayArray<T3>::type,
12458         typename internal::DecayArray<T4>::type,
12459         typename internal::DecayArray<T5>::type,
12460         typename internal::DecayArray<T6>::type,
12461         typename internal::DecayArray<T7>::type,
12462         typename internal::DecayArray<T8>::type,
12463         typename internal::DecayArray<T9>::type,
12464         typename internal::DecayArray<T10>::type> >
12465 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12466     const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12467     const T10& e10) {
12468   typedef std::tr1::tuple<
12469       typename internal::DecayArray<T1>::type,
12470       typename internal::DecayArray<T2>::type,
12471       typename internal::DecayArray<T3>::type,
12472       typename internal::DecayArray<T4>::type,
12473       typename internal::DecayArray<T5>::type,
12474       typename internal::DecayArray<T6>::type,
12475       typename internal::DecayArray<T7>::type,
12476       typename internal::DecayArray<T8>::type,
12477       typename internal::DecayArray<T9>::type,
12478       typename internal::DecayArray<T10>::type> Args;
12479   return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
12480       e8, e9, e10));
12481 }
12482 
12483 // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
12484 // that matches n elements in any order.  We support up to n=10 arguments.
12485 
12486 inline internal::UnorderedElementsAreMatcher<
12487     std::tr1::tuple<> >
12488 UnorderedElementsAre() {
12489   typedef std::tr1::tuple<> Args;
12490   return internal::UnorderedElementsAreMatcher<Args>(Args());
12491 }
12492 
12493 template <typename T1>
12494 inline internal::UnorderedElementsAreMatcher<
12495     std::tr1::tuple<
12496         typename internal::DecayArray<T1>::type> >
12497 UnorderedElementsAre(const T1& e1) {
12498   typedef std::tr1::tuple<
12499       typename internal::DecayArray<T1>::type> Args;
12500   return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
12501 }
12502 
12503 template <typename T1, typename T2>
12504 inline internal::UnorderedElementsAreMatcher<
12505     std::tr1::tuple<
12506         typename internal::DecayArray<T1>::type,
12507         typename internal::DecayArray<T2>::type> >
12508 UnorderedElementsAre(const T1& e1, const T2& e2) {
12509   typedef std::tr1::tuple<
12510       typename internal::DecayArray<T1>::type,
12511       typename internal::DecayArray<T2>::type> Args;
12512   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
12513 }
12514 
12515 template <typename T1, typename T2, typename T3>
12516 inline internal::UnorderedElementsAreMatcher<
12517     std::tr1::tuple<
12518         typename internal::DecayArray<T1>::type,
12519         typename internal::DecayArray<T2>::type,
12520         typename internal::DecayArray<T3>::type> >
12521 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
12522   typedef std::tr1::tuple<
12523       typename internal::DecayArray<T1>::type,
12524       typename internal::DecayArray<T2>::type,
12525       typename internal::DecayArray<T3>::type> Args;
12526   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
12527 }
12528 
12529 template <typename T1, typename T2, typename T3, typename T4>
12530 inline internal::UnorderedElementsAreMatcher<
12531     std::tr1::tuple<
12532         typename internal::DecayArray<T1>::type,
12533         typename internal::DecayArray<T2>::type,
12534         typename internal::DecayArray<T3>::type,
12535         typename internal::DecayArray<T4>::type> >
12536 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
12537   typedef std::tr1::tuple<
12538       typename internal::DecayArray<T1>::type,
12539       typename internal::DecayArray<T2>::type,
12540       typename internal::DecayArray<T3>::type,
12541       typename internal::DecayArray<T4>::type> Args;
12542   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
12543 }
12544 
12545 template <typename T1, typename T2, typename T3, typename T4, typename T5>
12546 inline internal::UnorderedElementsAreMatcher<
12547     std::tr1::tuple<
12548         typename internal::DecayArray<T1>::type,
12549         typename internal::DecayArray<T2>::type,
12550         typename internal::DecayArray<T3>::type,
12551         typename internal::DecayArray<T4>::type,
12552         typename internal::DecayArray<T5>::type> >
12553 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12554     const T5& e5) {
12555   typedef std::tr1::tuple<
12556       typename internal::DecayArray<T1>::type,
12557       typename internal::DecayArray<T2>::type,
12558       typename internal::DecayArray<T3>::type,
12559       typename internal::DecayArray<T4>::type,
12560       typename internal::DecayArray<T5>::type> Args;
12561   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
12562 }
12563 
12564 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12565     typename T6>
12566 inline internal::UnorderedElementsAreMatcher<
12567     std::tr1::tuple<
12568         typename internal::DecayArray<T1>::type,
12569         typename internal::DecayArray<T2>::type,
12570         typename internal::DecayArray<T3>::type,
12571         typename internal::DecayArray<T4>::type,
12572         typename internal::DecayArray<T5>::type,
12573         typename internal::DecayArray<T6>::type> >
12574 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12575     const T5& e5, const T6& e6) {
12576   typedef std::tr1::tuple<
12577       typename internal::DecayArray<T1>::type,
12578       typename internal::DecayArray<T2>::type,
12579       typename internal::DecayArray<T3>::type,
12580       typename internal::DecayArray<T4>::type,
12581       typename internal::DecayArray<T5>::type,
12582       typename internal::DecayArray<T6>::type> Args;
12583   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12584       e6));
12585 }
12586 
12587 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12588     typename T6, typename T7>
12589 inline internal::UnorderedElementsAreMatcher<
12590     std::tr1::tuple<
12591         typename internal::DecayArray<T1>::type,
12592         typename internal::DecayArray<T2>::type,
12593         typename internal::DecayArray<T3>::type,
12594         typename internal::DecayArray<T4>::type,
12595         typename internal::DecayArray<T5>::type,
12596         typename internal::DecayArray<T6>::type,
12597         typename internal::DecayArray<T7>::type> >
12598 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12599     const T5& e5, const T6& e6, const T7& e7) {
12600   typedef std::tr1::tuple<
12601       typename internal::DecayArray<T1>::type,
12602       typename internal::DecayArray<T2>::type,
12603       typename internal::DecayArray<T3>::type,
12604       typename internal::DecayArray<T4>::type,
12605       typename internal::DecayArray<T5>::type,
12606       typename internal::DecayArray<T6>::type,
12607       typename internal::DecayArray<T7>::type> Args;
12608   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12609       e6, e7));
12610 }
12611 
12612 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12613     typename T6, typename T7, typename T8>
12614 inline internal::UnorderedElementsAreMatcher<
12615     std::tr1::tuple<
12616         typename internal::DecayArray<T1>::type,
12617         typename internal::DecayArray<T2>::type,
12618         typename internal::DecayArray<T3>::type,
12619         typename internal::DecayArray<T4>::type,
12620         typename internal::DecayArray<T5>::type,
12621         typename internal::DecayArray<T6>::type,
12622         typename internal::DecayArray<T7>::type,
12623         typename internal::DecayArray<T8>::type> >
12624 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12625     const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
12626   typedef std::tr1::tuple<
12627       typename internal::DecayArray<T1>::type,
12628       typename internal::DecayArray<T2>::type,
12629       typename internal::DecayArray<T3>::type,
12630       typename internal::DecayArray<T4>::type,
12631       typename internal::DecayArray<T5>::type,
12632       typename internal::DecayArray<T6>::type,
12633       typename internal::DecayArray<T7>::type,
12634       typename internal::DecayArray<T8>::type> Args;
12635   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12636       e6, e7, e8));
12637 }
12638 
12639 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12640     typename T6, typename T7, typename T8, typename T9>
12641 inline internal::UnorderedElementsAreMatcher<
12642     std::tr1::tuple<
12643         typename internal::DecayArray<T1>::type,
12644         typename internal::DecayArray<T2>::type,
12645         typename internal::DecayArray<T3>::type,
12646         typename internal::DecayArray<T4>::type,
12647         typename internal::DecayArray<T5>::type,
12648         typename internal::DecayArray<T6>::type,
12649         typename internal::DecayArray<T7>::type,
12650         typename internal::DecayArray<T8>::type,
12651         typename internal::DecayArray<T9>::type> >
12652 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12653     const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
12654   typedef std::tr1::tuple<
12655       typename internal::DecayArray<T1>::type,
12656       typename internal::DecayArray<T2>::type,
12657       typename internal::DecayArray<T3>::type,
12658       typename internal::DecayArray<T4>::type,
12659       typename internal::DecayArray<T5>::type,
12660       typename internal::DecayArray<T6>::type,
12661       typename internal::DecayArray<T7>::type,
12662       typename internal::DecayArray<T8>::type,
12663       typename internal::DecayArray<T9>::type> Args;
12664   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12665       e6, e7, e8, e9));
12666 }
12667 
12668 template <typename T1, typename T2, typename T3, typename T4, typename T5,
12669     typename T6, typename T7, typename T8, typename T9, typename T10>
12670 inline internal::UnorderedElementsAreMatcher<
12671     std::tr1::tuple<
12672         typename internal::DecayArray<T1>::type,
12673         typename internal::DecayArray<T2>::type,
12674         typename internal::DecayArray<T3>::type,
12675         typename internal::DecayArray<T4>::type,
12676         typename internal::DecayArray<T5>::type,
12677         typename internal::DecayArray<T6>::type,
12678         typename internal::DecayArray<T7>::type,
12679         typename internal::DecayArray<T8>::type,
12680         typename internal::DecayArray<T9>::type,
12681         typename internal::DecayArray<T10>::type> >
12682 UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
12683     const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
12684     const T10& e10) {
12685   typedef std::tr1::tuple<
12686       typename internal::DecayArray<T1>::type,
12687       typename internal::DecayArray<T2>::type,
12688       typename internal::DecayArray<T3>::type,
12689       typename internal::DecayArray<T4>::type,
12690       typename internal::DecayArray<T5>::type,
12691       typename internal::DecayArray<T6>::type,
12692       typename internal::DecayArray<T7>::type,
12693       typename internal::DecayArray<T8>::type,
12694       typename internal::DecayArray<T9>::type,
12695       typename internal::DecayArray<T10>::type> Args;
12696   return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
12697       e6, e7, e8, e9, e10));
12698 }
12699 
12700 // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
12701 // sub-matchers.  AllOf is called fully qualified to prevent ADL from firing.
12702 
12703 template <typename M1, typename M2>
12704 inline typename internal::AllOfResult2<M1, M2>::type
12705 AllOf(M1 m1, M2 m2) {
12706   return typename internal::AllOfResult2<M1, M2>::type(
12707       m1,
12708       m2);
12709 }
12710 
12711 template <typename M1, typename M2, typename M3>
12712 inline typename internal::AllOfResult3<M1, M2, M3>::type
12713 AllOf(M1 m1, M2 m2, M3 m3) {
12714   return typename internal::AllOfResult3<M1, M2, M3>::type(
12715       m1,
12716       ::testing::AllOf(m2, m3));
12717 }
12718 
12719 template <typename M1, typename M2, typename M3, typename M4>
12720 inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
12721 AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12722   return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
12723       ::testing::AllOf(m1, m2),
12724       ::testing::AllOf(m3, m4));
12725 }
12726 
12727 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12728 inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
12729 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12730   return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
12731       ::testing::AllOf(m1, m2),
12732       ::testing::AllOf(m3, m4, m5));
12733 }
12734 
12735 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12736     typename M6>
12737 inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
12738 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12739   return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
12740       ::testing::AllOf(m1, m2, m3),
12741       ::testing::AllOf(m4, m5, m6));
12742 }
12743 
12744 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12745     typename M6, typename M7>
12746 inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12747 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12748   return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12749       ::testing::AllOf(m1, m2, m3),
12750       ::testing::AllOf(m4, m5, m6, m7));
12751 }
12752 
12753 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12754     typename M6, typename M7, typename M8>
12755 inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12756 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12757   return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12758       ::testing::AllOf(m1, m2, m3, m4),
12759       ::testing::AllOf(m5, m6, m7, m8));
12760 }
12761 
12762 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12763     typename M6, typename M7, typename M8, typename M9>
12764 inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12765 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12766   return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12767       M9>::type(
12768       ::testing::AllOf(m1, m2, m3, m4),
12769       ::testing::AllOf(m5, m6, m7, m8, m9));
12770 }
12771 
12772 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12773     typename M6, typename M7, typename M8, typename M9, typename M10>
12774 inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12775     M10>::type
12776 AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12777   return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12778       M10>::type(
12779       ::testing::AllOf(m1, m2, m3, m4, m5),
12780       ::testing::AllOf(m6, m7, m8, m9, m10));
12781 }
12782 
12783 // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
12784 // sub-matchers.  AnyOf is called fully qualified to prevent ADL from firing.
12785 
12786 template <typename M1, typename M2>
12787 inline typename internal::AnyOfResult2<M1, M2>::type
12788 AnyOf(M1 m1, M2 m2) {
12789   return typename internal::AnyOfResult2<M1, M2>::type(
12790       m1,
12791       m2);
12792 }
12793 
12794 template <typename M1, typename M2, typename M3>
12795 inline typename internal::AnyOfResult3<M1, M2, M3>::type
12796 AnyOf(M1 m1, M2 m2, M3 m3) {
12797   return typename internal::AnyOfResult3<M1, M2, M3>::type(
12798       m1,
12799       ::testing::AnyOf(m2, m3));
12800 }
12801 
12802 template <typename M1, typename M2, typename M3, typename M4>
12803 inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
12804 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
12805   return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
12806       ::testing::AnyOf(m1, m2),
12807       ::testing::AnyOf(m3, m4));
12808 }
12809 
12810 template <typename M1, typename M2, typename M3, typename M4, typename M5>
12811 inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
12812 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
12813   return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
12814       ::testing::AnyOf(m1, m2),
12815       ::testing::AnyOf(m3, m4, m5));
12816 }
12817 
12818 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12819     typename M6>
12820 inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
12821 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
12822   return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
12823       ::testing::AnyOf(m1, m2, m3),
12824       ::testing::AnyOf(m4, m5, m6));
12825 }
12826 
12827 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12828     typename M6, typename M7>
12829 inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
12830 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
12831   return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
12832       ::testing::AnyOf(m1, m2, m3),
12833       ::testing::AnyOf(m4, m5, m6, m7));
12834 }
12835 
12836 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12837     typename M6, typename M7, typename M8>
12838 inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
12839 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
12840   return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
12841       ::testing::AnyOf(m1, m2, m3, m4),
12842       ::testing::AnyOf(m5, m6, m7, m8));
12843 }
12844 
12845 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12846     typename M6, typename M7, typename M8, typename M9>
12847 inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
12848 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
12849   return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
12850       M9>::type(
12851       ::testing::AnyOf(m1, m2, m3, m4),
12852       ::testing::AnyOf(m5, m6, m7, m8, m9));
12853 }
12854 
12855 template <typename M1, typename M2, typename M3, typename M4, typename M5,
12856     typename M6, typename M7, typename M8, typename M9, typename M10>
12857 inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12858     M10>::type
12859 AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
12860   return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
12861       M10>::type(
12862       ::testing::AnyOf(m1, m2, m3, m4, m5),
12863       ::testing::AnyOf(m6, m7, m8, m9, m10));
12864 }
12865 
12866 }  // namespace testing
12867 
12868 
12869 // The MATCHER* family of macros can be used in a namespace scope to
12870 // define custom matchers easily.
12871 //
12872 // Basic Usage
12873 // ===========
12874 //
12875 // The syntax
12876 //
12877 //   MATCHER(name, description_string) { statements; }
12878 //
12879 // defines a matcher with the given name that executes the statements,
12880 // which must return a bool to indicate if the match succeeds.  Inside
12881 // the statements, you can refer to the value being matched by 'arg',
12882 // and refer to its type by 'arg_type'.
12883 //
12884 // The description string documents what the matcher does, and is used
12885 // to generate the failure message when the match fails.  Since a
12886 // MATCHER() is usually defined in a header file shared by multiple
12887 // C++ source files, we require the description to be a C-string
12888 // literal to avoid possible side effects.  It can be empty, in which
12889 // case we'll use the sequence of words in the matcher name as the
12890 // description.
12891 //
12892 // For example:
12893 //
12894 //   MATCHER(IsEven, "") { return (arg % 2) == 0; }
12895 //
12896 // allows you to write
12897 //
12898 //   // Expects mock_foo.Bar(n) to be called where n is even.
12899 //   EXPECT_CALL(mock_foo, Bar(IsEven()));
12900 //
12901 // or,
12902 //
12903 //   // Verifies that the value of some_expression is even.
12904 //   EXPECT_THAT(some_expression, IsEven());
12905 //
12906 // If the above assertion fails, it will print something like:
12907 //
12908 //   Value of: some_expression
12909 //   Expected: is even
12910 //     Actual: 7
12911 //
12912 // where the description "is even" is automatically calculated from the
12913 // matcher name IsEven.
12914 //
12915 // Argument Type
12916 // =============
12917 //
12918 // Note that the type of the value being matched (arg_type) is
12919 // determined by the context in which you use the matcher and is
12920 // supplied to you by the compiler, so you don't need to worry about
12921 // declaring it (nor can you).  This allows the matcher to be
12922 // polymorphic.  For example, IsEven() can be used to match any type
12923 // where the value of "(arg % 2) == 0" can be implicitly converted to
12924 // a bool.  In the "Bar(IsEven())" example above, if method Bar()
12925 // takes an int, 'arg_type' will be int; if it takes an unsigned long,
12926 // 'arg_type' will be unsigned long; and so on.
12927 //
12928 // Parameterizing Matchers
12929 // =======================
12930 //
12931 // Sometimes you'll want to parameterize the matcher.  For that you
12932 // can use another macro:
12933 //
12934 //   MATCHER_P(name, param_name, description_string) { statements; }
12935 //
12936 // For example:
12937 //
12938 //   MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
12939 //
12940 // will allow you to write:
12941 //
12942 //   EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
12943 //
12944 // which may lead to this message (assuming n is 10):
12945 //
12946 //   Value of: Blah("a")
12947 //   Expected: has absolute value 10
12948 //     Actual: -9
12949 //
12950 // Note that both the matcher description and its parameter are
12951 // printed, making the message human-friendly.
12952 //
12953 // In the matcher definition body, you can write 'foo_type' to
12954 // reference the type of a parameter named 'foo'.  For example, in the
12955 // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
12956 // 'value_type' to refer to the type of 'value'.
12957 //
12958 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
12959 // support multi-parameter matchers.
12960 //
12961 // Describing Parameterized Matchers
12962 // =================================
12963 //
12964 // The last argument to MATCHER*() is a string-typed expression.  The
12965 // expression can reference all of the matcher's parameters and a
12966 // special bool-typed variable named 'negation'.  When 'negation' is
12967 // false, the expression should evaluate to the matcher's description;
12968 // otherwise it should evaluate to the description of the negation of
12969 // the matcher.  For example,
12970 //
12971 //   using testing::PrintToString;
12972 //
12973 //   MATCHER_P2(InClosedRange, low, hi,
12974 //       string(negation ? "is not" : "is") + " in range [" +
12975 //       PrintToString(low) + ", " + PrintToString(hi) + "]") {
12976 //     return low <= arg && arg <= hi;
12977 //   }
12978 //   ...
12979 //   EXPECT_THAT(3, InClosedRange(4, 6));
12980 //   EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12981 //
12982 // would generate two failures that contain the text:
12983 //
12984 //   Expected: is in range [4, 6]
12985 //   ...
12986 //   Expected: is not in range [2, 4]
12987 //
12988 // If you specify "" as the description, the failure message will
12989 // contain the sequence of words in the matcher name followed by the
12990 // parameter values printed as a tuple.  For example,
12991 //
12992 //   MATCHER_P2(InClosedRange, low, hi, "") { ... }
12993 //   ...
12994 //   EXPECT_THAT(3, InClosedRange(4, 6));
12995 //   EXPECT_THAT(3, Not(InClosedRange(2, 4)));
12996 //
12997 // would generate two failures that contain the text:
12998 //
12999 //   Expected: in closed range (4, 6)
13000 //   ...
13001 //   Expected: not (in closed range (2, 4))
13002 //
13003 // Types of Matcher Parameters
13004 // ===========================
13005 //
13006 // For the purpose of typing, you can view
13007 //
13008 //   MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
13009 //
13010 // as shorthand for
13011 //
13012 //   template <typename p1_type, ..., typename pk_type>
13013 //   FooMatcherPk<p1_type, ..., pk_type>
13014 //   Foo(p1_type p1, ..., pk_type pk) { ... }
13015 //
13016 // When you write Foo(v1, ..., vk), the compiler infers the types of
13017 // the parameters v1, ..., and vk for you.  If you are not happy with
13018 // the result of the type inference, you can specify the types by
13019 // explicitly instantiating the template, as in Foo<long, bool>(5,
13020 // false).  As said earlier, you don't get to (or need to) specify
13021 // 'arg_type' as that's determined by the context in which the matcher
13022 // is used.  You can assign the result of expression Foo(p1, ..., pk)
13023 // to a variable of type FooMatcherPk<p1_type, ..., pk_type>.  This
13024 // can be useful when composing matchers.
13025 //
13026 // While you can instantiate a matcher template with reference types,
13027 // passing the parameters by pointer usually makes your code more
13028 // readable.  If, however, you still want to pass a parameter by
13029 // reference, be aware that in the failure message generated by the
13030 // matcher you will see the value of the referenced object but not its
13031 // address.
13032 //
13033 // Explaining Match Results
13034 // ========================
13035 //
13036 // Sometimes the matcher description alone isn't enough to explain why
13037 // the match has failed or succeeded.  For example, when expecting a
13038 // long string, it can be very helpful to also print the diff between
13039 // the expected string and the actual one.  To achieve that, you can
13040 // optionally stream additional information to a special variable
13041 // named result_listener, whose type is a pointer to class
13042 // MatchResultListener:
13043 //
13044 //   MATCHER_P(EqualsLongString, str, "") {
13045 //     if (arg == str) return true;
13046 //
13047 //     *result_listener << "the difference: "
13049 //     return false;
13050 //   }
13051 //
13052 // Overloading Matchers
13053 // ====================
13054 //
13055 // You can overload matchers with different numbers of parameters:
13056 //
13057 //   MATCHER_P(Blah, a, description_string1) { ... }
13058 //   MATCHER_P2(Blah, a, b, description_string2) { ... }
13059 //
13060 // Caveats
13061 // =======
13062 //
13063 // When defining a new matcher, you should also consider implementing
13064 // MatcherInterface or using MakePolymorphicMatcher().  These
13065 // approaches require more work than the MATCHER* macros, but also
13066 // give you more control on the types of the value being matched and
13067 // the matcher parameters, which may leads to better compiler error
13068 // messages when the matcher is used wrong.  They also allow
13069 // overloading matchers based on parameter types (as opposed to just
13070 // based on the number of parameters).
13071 //
13072 // MATCHER*() can only be used in a namespace scope.  The reason is
13073 // that C++ doesn't yet allow function-local types to be used to
13074 // instantiate templates.  The up-coming C++0x standard will fix this.
13075 // Once that's done, we'll consider supporting using MATCHER*() inside
13076 // a function.
13077 //
13078 // More Information
13079 // ================
13080 //
13081 // To learn more about using these macros, please search for 'MATCHER'
13082 // on http://code.google.com/p/googlemock/wiki/CookBook.
13083 
13084 #define MATCHER(name, description)\
13085   class name##Matcher {\
13086    public:\
13087     template <typename arg_type>\
13088     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13089      public:\
13090       gmock_Impl()\
13091            {}\
13092       virtual bool MatchAndExplain(\
13093           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13094       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13095         *gmock_os << FormatDescription(false);\
13096       }\
13097       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13098         *gmock_os << FormatDescription(true);\
13099       }\
13100      private:\
13101       ::testing::internal::string FormatDescription(bool negation) const {\
13102         const ::testing::internal::string gmock_description = (description);\
13103         if (!gmock_description.empty())\
13104           return gmock_description;\
13105         return ::testing::internal::FormatMatcherDescription(\
13106             negation, #name, \
13107             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13108                 ::std::tr1::tuple<>()));\
13109       }\
13110       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13111     };\
13112     template <typename arg_type>\
13113     operator ::testing::Matcher<arg_type>() const {\
13114       return ::testing::Matcher<arg_type>(\
13115           new gmock_Impl<arg_type>());\
13116     }\
13117     name##Matcher() {\
13118     }\
13119    private:\
13120     GTEST_DISALLOW_ASSIGN_(name##Matcher);\
13121   };\
13122   inline name##Matcher name() {\
13123     return name##Matcher();\
13124   }\
13125   template <typename arg_type>\
13126   bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
13127       arg_type arg, \
13128       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13129           const
13130 
13131 #define MATCHER_P(name, p0, description)\
13132   template <typename p0##_type>\
13133   class name##MatcherP {\
13134    public:\
13135     template <typename arg_type>\
13136     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13137      public:\
13138       explicit gmock_Impl(p0##_type gmock_p0)\
13139            : p0(gmock_p0) {}\
13140       virtual bool MatchAndExplain(\
13141           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13142       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13143         *gmock_os << FormatDescription(false);\
13144       }\
13145       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13146         *gmock_os << FormatDescription(true);\
13147       }\
13148       p0##_type p0;\
13149      private:\
13150       ::testing::internal::string FormatDescription(bool negation) const {\
13151         const ::testing::internal::string gmock_description = (description);\
13152         if (!gmock_description.empty())\
13153           return gmock_description;\
13154         return ::testing::internal::FormatMatcherDescription(\
13155             negation, #name, \
13156             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13157                 ::std::tr1::tuple<p0##_type>(p0)));\
13158       }\
13159       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13160     };\
13161     template <typename arg_type>\
13162     operator ::testing::Matcher<arg_type>() const {\
13163       return ::testing::Matcher<arg_type>(\
13164           new gmock_Impl<arg_type>(p0));\
13165     }\
13166     name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
13167     }\
13168     p0##_type p0;\
13169    private:\
13170     GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
13171   };\
13172   template <typename p0##_type>\
13173   inline name##MatcherP<p0##_type> name(p0##_type p0) {\
13174     return name##MatcherP<p0##_type>(p0);\
13175   }\
13176   template <typename p0##_type>\
13177   template <typename arg_type>\
13178   bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13179       arg_type arg, \
13180       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13181           const
13182 
13183 #define MATCHER_P2(name, p0, p1, description)\
13184   template <typename p0##_type, typename p1##_type>\
13185   class name##MatcherP2 {\
13186    public:\
13187     template <typename arg_type>\
13188     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13189      public:\
13190       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
13191            : p0(gmock_p0), p1(gmock_p1) {}\
13192       virtual bool MatchAndExplain(\
13193           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13194       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13195         *gmock_os << FormatDescription(false);\
13196       }\
13197       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13198         *gmock_os << FormatDescription(true);\
13199       }\
13200       p0##_type p0;\
13201       p1##_type p1;\
13202      private:\
13203       ::testing::internal::string FormatDescription(bool negation) const {\
13204         const ::testing::internal::string gmock_description = (description);\
13205         if (!gmock_description.empty())\
13206           return gmock_description;\
13207         return ::testing::internal::FormatMatcherDescription(\
13208             negation, #name, \
13209             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13210                 ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\
13211       }\
13212       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13213     };\
13214     template <typename arg_type>\
13215     operator ::testing::Matcher<arg_type>() const {\
13216       return ::testing::Matcher<arg_type>(\
13217           new gmock_Impl<arg_type>(p0, p1));\
13218     }\
13219     name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
13220         p1(gmock_p1) {\
13221     }\
13222     p0##_type p0;\
13223     p1##_type p1;\
13224    private:\
13225     GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
13226   };\
13227   template <typename p0##_type, typename p1##_type>\
13228   inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
13229       p1##_type p1) {\
13230     return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
13231   }\
13232   template <typename p0##_type, typename p1##_type>\
13233   template <typename arg_type>\
13234   bool name##MatcherP2<p0##_type, \
13235       p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13236       arg_type arg, \
13237       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13238           const
13239 
13240 #define MATCHER_P3(name, p0, p1, p2, description)\
13241   template <typename p0##_type, typename p1##_type, typename p2##_type>\
13242   class name##MatcherP3 {\
13243    public:\
13244     template <typename arg_type>\
13245     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13246      public:\
13247       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
13248            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
13249       virtual bool MatchAndExplain(\
13250           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13251       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13252         *gmock_os << FormatDescription(false);\
13253       }\
13254       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13255         *gmock_os << FormatDescription(true);\
13256       }\
13257       p0##_type p0;\
13258       p1##_type p1;\
13259       p2##_type p2;\
13260      private:\
13261       ::testing::internal::string FormatDescription(bool negation) const {\
13262         const ::testing::internal::string gmock_description = (description);\
13263         if (!gmock_description.empty())\
13264           return gmock_description;\
13265         return ::testing::internal::FormatMatcherDescription(\
13266             negation, #name, \
13267             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13268                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
13269                     p2)));\
13270       }\
13271       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13272     };\
13273     template <typename arg_type>\
13274     operator ::testing::Matcher<arg_type>() const {\
13275       return ::testing::Matcher<arg_type>(\
13276           new gmock_Impl<arg_type>(p0, p1, p2));\
13277     }\
13278     name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
13279         p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
13280     }\
13281     p0##_type p0;\
13282     p1##_type p1;\
13283     p2##_type p2;\
13284    private:\
13285     GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
13286   };\
13287   template <typename p0##_type, typename p1##_type, typename p2##_type>\
13288   inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
13289       p1##_type p1, p2##_type p2) {\
13290     return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
13291   }\
13292   template <typename p0##_type, typename p1##_type, typename p2##_type>\
13293   template <typename arg_type>\
13294   bool name##MatcherP3<p0##_type, p1##_type, \
13295       p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13296       arg_type arg, \
13297       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13298           const
13299 
13300 #define MATCHER_P4(name, p0, p1, p2, p3, description)\
13301   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13302       typename p3##_type>\
13303   class name##MatcherP4 {\
13304    public:\
13305     template <typename arg_type>\
13306     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13307      public:\
13308       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13309           p3##_type gmock_p3)\
13310            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
13311       virtual bool MatchAndExplain(\
13312           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13313       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13314         *gmock_os << FormatDescription(false);\
13315       }\
13316       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13317         *gmock_os << FormatDescription(true);\
13318       }\
13319       p0##_type p0;\
13320       p1##_type p1;\
13321       p2##_type p2;\
13322       p3##_type p3;\
13323      private:\
13324       ::testing::internal::string FormatDescription(bool negation) const {\
13325         const ::testing::internal::string gmock_description = (description);\
13326         if (!gmock_description.empty())\
13327           return gmock_description;\
13328         return ::testing::internal::FormatMatcherDescription(\
13329             negation, #name, \
13330             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13331                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
13332                     p3##_type>(p0, p1, p2, p3)));\
13333       }\
13334       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13335     };\
13336     template <typename arg_type>\
13337     operator ::testing::Matcher<arg_type>() const {\
13338       return ::testing::Matcher<arg_type>(\
13339           new gmock_Impl<arg_type>(p0, p1, p2, p3));\
13340     }\
13341     name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
13342         p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
13343         p2(gmock_p2), p3(gmock_p3) {\
13344     }\
13345     p0##_type p0;\
13346     p1##_type p1;\
13347     p2##_type p2;\
13348     p3##_type p3;\
13349    private:\
13350     GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
13351   };\
13352   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13353       typename p3##_type>\
13354   inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13355       p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13356       p3##_type p3) {\
13357     return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
13358         p1, p2, p3);\
13359   }\
13360   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13361       typename p3##_type>\
13362   template <typename arg_type>\
13363   bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
13364       p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13365       arg_type arg, \
13366       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13367           const
13368 
13369 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
13370   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13371       typename p3##_type, typename p4##_type>\
13372   class name##MatcherP5 {\
13373    public:\
13374     template <typename arg_type>\
13375     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13376      public:\
13377       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13378           p3##_type gmock_p3, p4##_type gmock_p4)\
13379            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13380                p4(gmock_p4) {}\
13381       virtual bool MatchAndExplain(\
13382           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13383       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13384         *gmock_os << FormatDescription(false);\
13385       }\
13386       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13387         *gmock_os << FormatDescription(true);\
13388       }\
13389       p0##_type p0;\
13390       p1##_type p1;\
13391       p2##_type p2;\
13392       p3##_type p3;\
13393       p4##_type p4;\
13394      private:\
13395       ::testing::internal::string FormatDescription(bool negation) const {\
13396         const ::testing::internal::string gmock_description = (description);\
13397         if (!gmock_description.empty())\
13398           return gmock_description;\
13399         return ::testing::internal::FormatMatcherDescription(\
13400             negation, #name, \
13401             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13402                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13403                     p4##_type>(p0, p1, p2, p3, p4)));\
13404       }\
13405       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13406     };\
13407     template <typename arg_type>\
13408     operator ::testing::Matcher<arg_type>() const {\
13409       return ::testing::Matcher<arg_type>(\
13410           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
13411     }\
13412     name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
13413         p2##_type gmock_p2, p3##_type gmock_p3, \
13414         p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13415         p3(gmock_p3), p4(gmock_p4) {\
13416     }\
13417     p0##_type p0;\
13418     p1##_type p1;\
13419     p2##_type p2;\
13420     p3##_type p3;\
13421     p4##_type p4;\
13422    private:\
13423     GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
13424   };\
13425   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13426       typename p3##_type, typename p4##_type>\
13427   inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13428       p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13429       p4##_type p4) {\
13430     return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13431         p4##_type>(p0, p1, p2, p3, p4);\
13432   }\
13433   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13434       typename p3##_type, typename p4##_type>\
13435   template <typename arg_type>\
13436   bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
13437       p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13438       arg_type arg, \
13439       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13440           const
13441 
13442 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
13443   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13444       typename p3##_type, typename p4##_type, typename p5##_type>\
13445   class name##MatcherP6 {\
13446    public:\
13447     template <typename arg_type>\
13448     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13449      public:\
13450       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13451           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
13452            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13453                p4(gmock_p4), p5(gmock_p5) {}\
13454       virtual bool MatchAndExplain(\
13455           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13456       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13457         *gmock_os << FormatDescription(false);\
13458       }\
13459       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13460         *gmock_os << FormatDescription(true);\
13461       }\
13462       p0##_type p0;\
13463       p1##_type p1;\
13464       p2##_type p2;\
13465       p3##_type p3;\
13466       p4##_type p4;\
13467       p5##_type p5;\
13468      private:\
13469       ::testing::internal::string FormatDescription(bool negation) const {\
13470         const ::testing::internal::string gmock_description = (description);\
13471         if (!gmock_description.empty())\
13472           return gmock_description;\
13473         return ::testing::internal::FormatMatcherDescription(\
13474             negation, #name, \
13475             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13476                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13477                     p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
13478       }\
13479       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13480     };\
13481     template <typename arg_type>\
13482     operator ::testing::Matcher<arg_type>() const {\
13483       return ::testing::Matcher<arg_type>(\
13484           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
13485     }\
13486     name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
13487         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13488         p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13489         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
13490     }\
13491     p0##_type p0;\
13492     p1##_type p1;\
13493     p2##_type p2;\
13494     p3##_type p3;\
13495     p4##_type p4;\
13496     p5##_type p5;\
13497    private:\
13498     GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
13499   };\
13500   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13501       typename p3##_type, typename p4##_type, typename p5##_type>\
13502   inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13503       p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
13504       p3##_type p3, p4##_type p4, p5##_type p5) {\
13505     return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
13506         p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
13507   }\
13508   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13509       typename p3##_type, typename p4##_type, typename p5##_type>\
13510   template <typename arg_type>\
13511   bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13512       p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13513       arg_type arg, \
13514       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13515           const
13516 
13517 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
13518   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13519       typename p3##_type, typename p4##_type, typename p5##_type, \
13520       typename p6##_type>\
13521   class name##MatcherP7 {\
13522    public:\
13523     template <typename arg_type>\
13524     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13525      public:\
13526       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13527           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13528           p6##_type gmock_p6)\
13529            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13530                p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
13531       virtual bool MatchAndExplain(\
13532           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13533       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13534         *gmock_os << FormatDescription(false);\
13535       }\
13536       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13537         *gmock_os << FormatDescription(true);\
13538       }\
13539       p0##_type p0;\
13540       p1##_type p1;\
13541       p2##_type p2;\
13542       p3##_type p3;\
13543       p4##_type p4;\
13544       p5##_type p5;\
13545       p6##_type p6;\
13546      private:\
13547       ::testing::internal::string FormatDescription(bool negation) const {\
13548         const ::testing::internal::string gmock_description = (description);\
13549         if (!gmock_description.empty())\
13550           return gmock_description;\
13551         return ::testing::internal::FormatMatcherDescription(\
13552             negation, #name, \
13553             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13554                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13555                     p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
13556                     p6)));\
13557       }\
13558       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13559     };\
13560     template <typename arg_type>\
13561     operator ::testing::Matcher<arg_type>() const {\
13562       return ::testing::Matcher<arg_type>(\
13563           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
13564     }\
13565     name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
13566         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13567         p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
13568         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
13569         p6(gmock_p6) {\
13570     }\
13571     p0##_type p0;\
13572     p1##_type p1;\
13573     p2##_type p2;\
13574     p3##_type p3;\
13575     p4##_type p4;\
13576     p5##_type p5;\
13577     p6##_type p6;\
13578    private:\
13579     GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
13580   };\
13581   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13582       typename p3##_type, typename p4##_type, typename p5##_type, \
13583       typename p6##_type>\
13584   inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13585       p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
13586       p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13587       p6##_type p6) {\
13588     return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
13589         p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
13590   }\
13591   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13592       typename p3##_type, typename p4##_type, typename p5##_type, \
13593       typename p6##_type>\
13594   template <typename arg_type>\
13595   bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13596       p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13597       arg_type arg, \
13598       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13599           const
13600 
13601 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
13602   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13603       typename p3##_type, typename p4##_type, typename p5##_type, \
13604       typename p6##_type, typename p7##_type>\
13605   class name##MatcherP8 {\
13606    public:\
13607     template <typename arg_type>\
13608     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13609      public:\
13610       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13611           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13612           p6##_type gmock_p6, p7##_type gmock_p7)\
13613            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13614                p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
13615       virtual bool MatchAndExplain(\
13616           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13617       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13618         *gmock_os << FormatDescription(false);\
13619       }\
13620       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13621         *gmock_os << FormatDescription(true);\
13622       }\
13623       p0##_type p0;\
13624       p1##_type p1;\
13625       p2##_type p2;\
13626       p3##_type p3;\
13627       p4##_type p4;\
13628       p5##_type p5;\
13629       p6##_type p6;\
13630       p7##_type p7;\
13631      private:\
13632       ::testing::internal::string FormatDescription(bool negation) const {\
13633         const ::testing::internal::string gmock_description = (description);\
13634         if (!gmock_description.empty())\
13635           return gmock_description;\
13636         return ::testing::internal::FormatMatcherDescription(\
13637             negation, #name, \
13638             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13639                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13640                     p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
13641                     p3, p4, p5, p6, p7)));\
13642       }\
13643       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13644     };\
13645     template <typename arg_type>\
13646     operator ::testing::Matcher<arg_type>() const {\
13647       return ::testing::Matcher<arg_type>(\
13648           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
13649     }\
13650     name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
13651         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13652         p5##_type gmock_p5, p6##_type gmock_p6, \
13653         p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13654         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13655         p7(gmock_p7) {\
13656     }\
13657     p0##_type p0;\
13658     p1##_type p1;\
13659     p2##_type p2;\
13660     p3##_type p3;\
13661     p4##_type p4;\
13662     p5##_type p5;\
13663     p6##_type p6;\
13664     p7##_type p7;\
13665    private:\
13666     GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
13667   };\
13668   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13669       typename p3##_type, typename p4##_type, typename p5##_type, \
13670       typename p6##_type, typename p7##_type>\
13671   inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13672       p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
13673       p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
13674       p6##_type p6, p7##_type p7) {\
13675     return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
13676         p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
13677         p6, p7);\
13678   }\
13679   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13680       typename p3##_type, typename p4##_type, typename p5##_type, \
13681       typename p6##_type, typename p7##_type>\
13682   template <typename arg_type>\
13683   bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13684       p5##_type, p6##_type, \
13685       p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13686       arg_type arg, \
13687       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13688           const
13689 
13690 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
13691   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13692       typename p3##_type, typename p4##_type, typename p5##_type, \
13693       typename p6##_type, typename p7##_type, typename p8##_type>\
13694   class name##MatcherP9 {\
13695    public:\
13696     template <typename arg_type>\
13697     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13698      public:\
13699       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13700           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13701           p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
13702            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13703                p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13704                p8(gmock_p8) {}\
13705       virtual bool MatchAndExplain(\
13706           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13707       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13708         *gmock_os << FormatDescription(false);\
13709       }\
13710       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13711         *gmock_os << FormatDescription(true);\
13712       }\
13713       p0##_type p0;\
13714       p1##_type p1;\
13715       p2##_type p2;\
13716       p3##_type p3;\
13717       p4##_type p4;\
13718       p5##_type p5;\
13719       p6##_type p6;\
13720       p7##_type p7;\
13721       p8##_type p8;\
13722      private:\
13723       ::testing::internal::string FormatDescription(bool negation) const {\
13724         const ::testing::internal::string gmock_description = (description);\
13725         if (!gmock_description.empty())\
13726           return gmock_description;\
13727         return ::testing::internal::FormatMatcherDescription(\
13728             negation, #name, \
13729             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13730                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13731                     p4##_type, p5##_type, p6##_type, p7##_type, \
13732                     p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
13733       }\
13734       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13735     };\
13736     template <typename arg_type>\
13737     operator ::testing::Matcher<arg_type>() const {\
13738       return ::testing::Matcher<arg_type>(\
13739           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
13740     }\
13741     name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
13742         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13743         p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13744         p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
13745         p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13746         p8(gmock_p8) {\
13747     }\
13748     p0##_type p0;\
13749     p1##_type p1;\
13750     p2##_type p2;\
13751     p3##_type p3;\
13752     p4##_type p4;\
13753     p5##_type p5;\
13754     p6##_type p6;\
13755     p7##_type p7;\
13756     p8##_type p8;\
13757    private:\
13758     GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
13759   };\
13760   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13761       typename p3##_type, typename p4##_type, typename p5##_type, \
13762       typename p6##_type, typename p7##_type, typename p8##_type>\
13763   inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13764       p4##_type, p5##_type, p6##_type, p7##_type, \
13765       p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13766       p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
13767       p8##_type p8) {\
13768     return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
13769         p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
13770         p3, p4, p5, p6, p7, p8);\
13771   }\
13772   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13773       typename p3##_type, typename p4##_type, typename p5##_type, \
13774       typename p6##_type, typename p7##_type, typename p8##_type>\
13775   template <typename arg_type>\
13776   bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
13777       p5##_type, p6##_type, p7##_type, \
13778       p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13779       arg_type arg, \
13780       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13781           const
13782 
13783 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
13784   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13785       typename p3##_type, typename p4##_type, typename p5##_type, \
13786       typename p6##_type, typename p7##_type, typename p8##_type, \
13787       typename p9##_type>\
13788   class name##MatcherP10 {\
13789    public:\
13790     template <typename arg_type>\
13791     class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
13792      public:\
13793       gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
13794           p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
13795           p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
13796           p9##_type gmock_p9)\
13797            : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
13798                p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
13799                p8(gmock_p8), p9(gmock_p9) {}\
13800       virtual bool MatchAndExplain(\
13801           arg_type arg, ::testing::MatchResultListener* result_listener) const;\
13802       virtual void DescribeTo(::std::ostream* gmock_os) const {\
13803         *gmock_os << FormatDescription(false);\
13804       }\
13805       virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
13806         *gmock_os << FormatDescription(true);\
13807       }\
13808       p0##_type p0;\
13809       p1##_type p1;\
13810       p2##_type p2;\
13811       p3##_type p3;\
13812       p4##_type p4;\
13813       p5##_type p5;\
13814       p6##_type p6;\
13815       p7##_type p7;\
13816       p8##_type p8;\
13817       p9##_type p9;\
13818      private:\
13819       ::testing::internal::string FormatDescription(bool negation) const {\
13820         const ::testing::internal::string gmock_description = (description);\
13821         if (!gmock_description.empty())\
13822           return gmock_description;\
13823         return ::testing::internal::FormatMatcherDescription(\
13824             negation, #name, \
13825             ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
13826                 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
13827                     p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13828                     p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
13829       }\
13830       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
13831     };\
13832     template <typename arg_type>\
13833     operator ::testing::Matcher<arg_type>() const {\
13834       return ::testing::Matcher<arg_type>(\
13835           new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
13836     }\
13837     name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
13838         p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
13839         p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
13840         p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
13841         p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
13842         p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
13843     }\
13844     p0##_type p0;\
13845     p1##_type p1;\
13846     p2##_type p2;\
13847     p3##_type p3;\
13848     p4##_type p4;\
13849     p5##_type p5;\
13850     p6##_type p6;\
13851     p7##_type p7;\
13852     p8##_type p8;\
13853     p9##_type p9;\
13854    private:\
13855     GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
13856   };\
13857   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13858       typename p3##_type, typename p4##_type, typename p5##_type, \
13859       typename p6##_type, typename p7##_type, typename p8##_type, \
13860       typename p9##_type>\
13861   inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13862       p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13863       p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
13864       p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
13865       p9##_type p9) {\
13866     return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13867         p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
13868         p1, p2, p3, p4, p5, p6, p7, p8, p9);\
13869   }\
13870   template <typename p0##_type, typename p1##_type, typename p2##_type, \
13871       typename p3##_type, typename p4##_type, typename p5##_type, \
13872       typename p6##_type, typename p7##_type, typename p8##_type, \
13873       typename p9##_type>\
13874   template <typename arg_type>\
13875   bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
13876       p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
13877       p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
13878       arg_type arg, \
13879       ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
13880           const
13881 
13882 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
13883 // Copyright 2007, Google Inc.
13884 // All rights reserved.
13885 //
13886 // Redistribution and use in source and binary forms, with or without
13887 // modification, are permitted provided that the following conditions are
13888 // met:
13889 //
13890 //     * Redistributions of source code must retain the above copyright
13891 // notice, this list of conditions and the following disclaimer.
13892 //     * Redistributions in binary form must reproduce the above
13893 // copyright notice, this list of conditions and the following disclaimer
13894 // in the documentation and/or other materials provided with the
13895 // distribution.
13896 //     * Neither the name of Google Inc. nor the names of its
13897 // contributors may be used to endorse or promote products derived from
13898 // this software without specific prior written permission.
13899 //
13900 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13901 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13902 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13903 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13904 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13905 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13906 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13907 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13908 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13909 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13910 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13911 //
13912 // Author: wan@google.com (Zhanyong Wan)
13913 
13914 // Google Mock - a framework for writing C++ mock classes.
13915 //
13916 // This file implements some actions that depend on gmock-generated-actions.h.
13917 
13918 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13919 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
13920 
13921 #include <algorithm>
13922 
13923 
13924 namespace testing {
13925 namespace internal {
13926 
13927 // Implements the Invoke(f) action.  The template argument
13928 // FunctionImpl is the implementation type of f, which can be either a
13929 // function pointer or a functor.  Invoke(f) can be used as an
13930 // Action<F> as long as f's type is compatible with F (i.e. f can be
13931 // assigned to a tr1::function<F>).
13932 template <typename FunctionImpl>
13933 class InvokeAction {
13934  public:
13935   // The c'tor makes a copy of function_impl (either a function
13936   // pointer or a functor).
13937   explicit InvokeAction(FunctionImpl function_impl)
13938       : function_impl_(function_impl) {}
13939 
13940   template <typename Result, typename ArgumentTuple>
13941   Result Perform(const ArgumentTuple& args) {
13942     return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
13943   }
13944 
13945  private:
13946   FunctionImpl function_impl_;
13947 
13948   GTEST_DISALLOW_ASSIGN_(InvokeAction);
13949 };
13950 
13951 // Implements the Invoke(object_ptr, &Class::Method) action.
13952 template <class Class, typename MethodPtr>
13953 class InvokeMethodAction {
13954  public:
13955   InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
13956       : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
13957 
13958   template <typename Result, typename ArgumentTuple>
13959   Result Perform(const ArgumentTuple& args) const {
13960     return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
13961         obj_ptr_, method_ptr_, args);
13962   }
13963 
13964  private:
13965   Class* const obj_ptr_;
13966   const MethodPtr method_ptr_;
13967 
13968   GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
13969 };
13970 
13971 }  // namespace internal
13972 
13973 // Various overloads for Invoke().
13974 
13975 // Creates an action that invokes 'function_impl' with the mock
13976 // function's arguments.
13977 template <typename FunctionImpl>
13978 PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
13979     FunctionImpl function_impl) {
13980   return MakePolymorphicAction(
13981       internal::InvokeAction<FunctionImpl>(function_impl));
13982 }
13983 
13984 // Creates an action that invokes the given method on the given object
13985 // with the mock function's arguments.
13986 template <class Class, typename MethodPtr>
13987 PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
13988     Class* obj_ptr, MethodPtr method_ptr) {
13989   return MakePolymorphicAction(
13990       internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
13991 }
13992 
13993 // WithoutArgs(inner_action) can be used in a mock function with a
13994 // non-empty argument list to perform inner_action, which takes no
13995 // argument.  In other words, it adapts an action accepting no
13996 // argument to one that accepts (and ignores) arguments.
13997 template <typename InnerAction>
13998 inline internal::WithArgsAction<InnerAction>
13999 WithoutArgs(const InnerAction& action) {
14000   return internal::WithArgsAction<InnerAction>(action);
14001 }
14002 
14003 // WithArg<k>(an_action) creates an action that passes the k-th
14004 // (0-based) argument of the mock function to an_action and performs
14005 // it.  It adapts an action accepting one argument to one that accepts
14006 // multiple arguments.  For convenience, we also provide
14007 // WithArgs<k>(an_action) (defined below) as a synonym.
14008 template <int k, typename InnerAction>
14009 inline internal::WithArgsAction<InnerAction, k>
14010 WithArg(const InnerAction& action) {
14011   return internal::WithArgsAction<InnerAction, k>(action);
14012 }
14013 
14014 // The ACTION*() macros trigger warning C4100 (unreferenced formal
14015 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
14016 // the macro definition, as the warnings are generated when the macro
14017 // is expanded and macro expansion cannot contain #pragma.  Therefore
14018 // we suppress them here.
14019 #ifdef _MSC_VER
14020 # pragma warning(push)
14021 # pragma warning(disable:4100)
14022 #endif
14023 
14024 // Action ReturnArg<k>() returns the k-th argument of the mock function.
14025 ACTION_TEMPLATE(ReturnArg,
14026                 HAS_1_TEMPLATE_PARAMS(int, k),
14027                 AND_0_VALUE_PARAMS()) {
14028   return std::tr1::get<k>(args);
14029 }
14030 
14031 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
14032 // mock function to *pointer.
14033 ACTION_TEMPLATE(SaveArg,
14034                 HAS_1_TEMPLATE_PARAMS(int, k),
14035                 AND_1_VALUE_PARAMS(pointer)) {
14036   *pointer = ::std::tr1::get<k>(args);
14037 }
14038 
14039 // Action SaveArgPointee<k>(pointer) saves the value pointed to
14040 // by the k-th (0-based) argument of the mock function to *pointer.
14041 ACTION_TEMPLATE(SaveArgPointee,
14042                 HAS_1_TEMPLATE_PARAMS(int, k),
14043                 AND_1_VALUE_PARAMS(pointer)) {
14044   *pointer = *::std::tr1::get<k>(args);
14045 }
14046 
14047 // Action SetArgReferee<k>(value) assigns 'value' to the variable
14048 // referenced by the k-th (0-based) argument of the mock function.
14049 ACTION_TEMPLATE(SetArgReferee,
14050                 HAS_1_TEMPLATE_PARAMS(int, k),
14051                 AND_1_VALUE_PARAMS(value)) {
14052   typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
14053   // Ensures that argument #k is a reference.  If you get a compiler
14054   // error on the next line, you are using SetArgReferee<k>(value) in
14055   // a mock function whose k-th (0-based) argument is not a reference.
14056   GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
14057                         SetArgReferee_must_be_used_with_a_reference_argument);
14058   ::std::tr1::get<k>(args) = value;
14059 }
14060 
14061 // Action SetArrayArgument<k>(first, last) copies the elements in
14062 // source range [first, last) to the array pointed to by the k-th
14063 // (0-based) argument, which can be either a pointer or an
14064 // iterator. The action does not take ownership of the elements in the
14065 // source range.
14066 ACTION_TEMPLATE(SetArrayArgument,
14067                 HAS_1_TEMPLATE_PARAMS(int, k),
14068                 AND_2_VALUE_PARAMS(first, last)) {
14069   // Microsoft compiler deprecates ::std::copy, so we want to suppress warning
14070   // 4996 (Function call with parameters that may be unsafe) there.
14071 #ifdef _MSC_VER
14072 # pragma warning(push)          // Saves the current warning state.
14073 # pragma warning(disable:4996)  // Temporarily disables warning 4996.
14074 #endif
14075   ::std::copy(first, last, ::std::tr1::get<k>(args));
14076 #ifdef _MSC_VER
14077 # pragma warning(pop)           // Restores the warning state.
14078 #endif
14079 }
14080 
14081 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
14082 // function.
14083 ACTION_TEMPLATE(DeleteArg,
14084                 HAS_1_TEMPLATE_PARAMS(int, k),
14085                 AND_0_VALUE_PARAMS()) {
14086   delete ::std::tr1::get<k>(args);
14087 }
14088 
14089 // This action returns the value pointed to by 'pointer'.
14090 ACTION_P(ReturnPointee, pointer) { return *pointer; }
14091 
14092 // Action Throw(exception) can be used in a mock function of any type
14093 // to throw the given exception.  Any copyable value can be thrown.
14094 #if GTEST_HAS_EXCEPTIONS
14095 
14096 // Suppresses the 'unreachable code' warning that VC generates in opt modes.
14097 # ifdef _MSC_VER
14098 #  pragma warning(push)          // Saves the current warning state.
14099 #  pragma warning(disable:4702)  // Temporarily disables warning 4702.
14100 # endif
14101 ACTION_P(Throw, exception) { throw exception; }
14102 # ifdef _MSC_VER
14103 #  pragma warning(pop)           // Restores the warning state.
14104 # endif
14105 
14106 #endif  // GTEST_HAS_EXCEPTIONS
14107 
14108 #ifdef _MSC_VER
14109 # pragma warning(pop)
14110 #endif
14111 
14112 }  // namespace testing
14113 
14114 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
14115 // Copyright 2013, Google Inc.
14116 // All rights reserved.
14117 //
14118 // Redistribution and use in source and binary forms, with or without
14119 // modification, are permitted provided that the following conditions are
14120 // met:
14121 //
14122 //     * Redistributions of source code must retain the above copyright
14123 // notice, this list of conditions and the following disclaimer.
14124 //     * Redistributions in binary form must reproduce the above
14125 // copyright notice, this list of conditions and the following disclaimer
14126 // in the documentation and/or other materials provided with the
14127 // distribution.
14128 //     * Neither the name of Google Inc. nor the names of its
14129 // contributors may be used to endorse or promote products derived from
14130 // this software without specific prior written permission.
14131 //
14132 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14133 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14134 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14135 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14136 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14137 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14138 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14139 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14140 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14141 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14142 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14143 //
14144 // Author: marcus.boerger@google.com (Marcus Boerger)
14145 
14146 // Google Mock - a framework for writing C++ mock classes.
14147 //
14148 // This file implements some matchers that depend on gmock-generated-matchers.h.
14149 //
14150 // Note that tests are implemented in gmock-matchers_test.cc rather than
14151 // gmock-more-matchers-test.cc.
14152 
14153 #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
14154 #define GMOCK_GMOCK_MORE_MATCHERS_H_
14155 
14156 
14157 namespace testing {
14158 
14159 // Defines a matcher that matches an empty container. The container must
14160 // support both size() and empty(), which all STL-like containers provide.
14161 MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
14162   if (arg.empty()) {
14163     return true;
14164   }
14165   *result_listener << "whose size is " << arg.size();
14166   return false;
14167 }
14168 
14169 }  // namespace testing
14170 
14171 #endif  // GMOCK_GMOCK_MORE_MATCHERS_H_
14172 
14173 namespace testing {
14174 
14175 // Declares Google Mock flags that we want a user to use programmatically.
14176 GMOCK_DECLARE_bool_(catch_leaked_mocks);
14177 GMOCK_DECLARE_string_(verbose);
14178 
14179 // Initializes Google Mock.  This must be called before running the
14180 // tests.  In particular, it parses the command line for the flags
14181 // that Google Mock recognizes.  Whenever a Google Mock flag is seen,
14182 // it is removed from argv, and *argc is decremented.
14183 //
14184 // No value is returned.  Instead, the Google Mock flag variables are
14185 // updated.
14186 //
14187 // Since Google Test is needed for Google Mock to work, this function
14188 // also initializes Google Test and parses its flags, if that hasn't
14189 // been done.
14190 GTEST_API_ void InitGoogleMock(int* argc, char** argv);
14191 
14192 // This overloaded version can be used in Windows programs compiled in
14193 // UNICODE mode.
14194 GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
14195 
14196 }  // namespace testing
14197 
14198 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_H_


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:43