Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-07 08:19:49

0001 // Copyright 2007, Google Inc.
0002 // All rights reserved.
0003 //
0004 // Redistribution and use in source and binary forms, with or without
0005 // modification, are permitted provided that the following conditions are
0006 // met:
0007 //
0008 //     * Redistributions of source code must retain the above copyright
0009 // notice, this list of conditions and the following disclaimer.
0010 //     * Redistributions in binary form must reproduce the above
0011 // copyright notice, this list of conditions and the following disclaimer
0012 // in the documentation and/or other materials provided with the
0013 // distribution.
0014 //     * Neither the name of Google Inc. nor the names of its
0015 // contributors may be used to endorse or promote products derived from
0016 // this software without specific prior written permission.
0017 //
0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 //
0030 // Author: wan@google.com (Zhanyong Wan)
0031 
0032 // Google Mock - a framework for writing C++ mock classes.
0033 //
0034 // This file implements some commonly used actions.
0035 
0036 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
0037 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
0038 
0039 #ifndef _WIN32_WCE
0040 # include <errno.h>
0041 #endif
0042 
0043 #include <algorithm>
0044 #include <string>
0045 
0046 #include "gmock/internal/gmock-internal-utils.h"
0047 #include "gmock/internal/gmock-port.h"
0048 
0049 #if GTEST_HAS_STD_TYPE_TRAITS_  // Defined by gtest-port.h via gmock-port.h.
0050 #include <type_traits>
0051 #endif
0052 
0053 namespace testing {
0054 
0055 // To implement an action Foo, define:
0056 //   1. a class FooAction that implements the ActionInterface interface, and
0057 //   2. a factory function that creates an Action object from a
0058 //      const FooAction*.
0059 //
0060 // The two-level delegation design follows that of Matcher, providing
0061 // consistency for extension developers.  It also eases ownership
0062 // management as Action objects can now be copied like plain values.
0063 
0064 namespace internal {
0065 
0066 template <typename F1, typename F2>
0067 class ActionAdaptor;
0068 
0069 // BuiltInDefaultValueGetter<T, true>::Get() returns a
0070 // default-constructed T value.  BuiltInDefaultValueGetter<T,
0071 // false>::Get() crashes with an error.
0072 //
0073 // This primary template is used when kDefaultConstructible is true.
0074 template <typename T, bool kDefaultConstructible>
0075 struct BuiltInDefaultValueGetter {
0076   static T Get() { return T(); }
0077 };
0078 template <typename T>
0079 struct BuiltInDefaultValueGetter<T, false> {
0080   static T Get() {
0081     Assert(false, __FILE__, __LINE__,
0082            "Default action undefined for the function return type.");
0083     return internal::Invalid<T>();
0084     // The above statement will never be reached, but is required in
0085     // order for this function to compile.
0086   }
0087 };
0088 
0089 // BuiltInDefaultValue<T>::Get() returns the "built-in" default value
0090 // for type T, which is NULL when T is a raw pointer type, 0 when T is
0091 // a numeric type, false when T is bool, or "" when T is string or
0092 // std::string.  In addition, in C++11 and above, it turns a
0093 // default-constructed T value if T is default constructible.  For any
0094 // other type T, the built-in default T value is undefined, and the
0095 // function will abort the process.
0096 template <typename T>
0097 class BuiltInDefaultValue {
0098  public:
0099 #if GTEST_HAS_STD_TYPE_TRAITS_
0100   // This function returns true iff type T has a built-in default value.
0101   static bool Exists() {
0102     return ::std::is_default_constructible<T>::value;
0103   }
0104 
0105   static T Get() {
0106     return BuiltInDefaultValueGetter<
0107         T, ::std::is_default_constructible<T>::value>::Get();
0108   }
0109 
0110 #else  // GTEST_HAS_STD_TYPE_TRAITS_
0111   // This function returns true iff type T has a built-in default value.
0112   static bool Exists() {
0113     return false;
0114   }
0115 
0116   static T Get() {
0117     return BuiltInDefaultValueGetter<T, false>::Get();
0118   }
0119 
0120 #endif  // GTEST_HAS_STD_TYPE_TRAITS_
0121 };
0122 
0123 // This partial specialization says that we use the same built-in
0124 // default value for T and const T.
0125 template <typename T>
0126 class BuiltInDefaultValue<const T> {
0127  public:
0128   static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
0129   static T Get() { return BuiltInDefaultValue<T>::Get(); }
0130 };
0131 
0132 // This partial specialization defines the default values for pointer
0133 // types.
0134 template <typename T>
0135 class BuiltInDefaultValue<T*> {
0136  public:
0137   static bool Exists() { return true; }
0138   static T* Get() { return NULL; }
0139 };
0140 
0141 // The following specializations define the default values for
0142 // specific types we care about.
0143 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
0144   template <> \
0145   class BuiltInDefaultValue<type> { \
0146    public: \
0147     static bool Exists() { return true; } \
0148     static type Get() { return value; } \
0149   }
0150 
0151 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, );  // NOLINT
0152 #if GTEST_HAS_GLOBAL_STRING
0153 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
0154 #endif  // GTEST_HAS_GLOBAL_STRING
0155 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
0156 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
0157 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
0158 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
0159 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
0160 
0161 // There's no need for a default action for signed wchar_t, as that
0162 // type is the same as wchar_t for gcc, and invalid for MSVC.
0163 //
0164 // There's also no need for a default action for unsigned wchar_t, as
0165 // that type is the same as unsigned int for gcc, and invalid for
0166 // MSVC.
0167 #if GMOCK_WCHAR_T_IS_NATIVE_
0168 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U);  // NOLINT
0169 #endif
0170 
0171 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U);  // NOLINT
0172 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0);     // NOLINT
0173 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
0174 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
0175 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL);  // NOLINT
0176 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L);     // NOLINT
0177 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
0178 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
0179 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
0180 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
0181 
0182 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
0183 
0184 }  // namespace internal
0185 
0186 // When an unexpected function call is encountered, Google Mock will
0187 // let it return a default value if the user has specified one for its
0188 // return type, or if the return type has a built-in default value;
0189 // otherwise Google Mock won't know what value to return and will have
0190 // to abort the process.
0191 //
0192 // The DefaultValue<T> class allows a user to specify the
0193 // default value for a type T that is both copyable and publicly
0194 // destructible (i.e. anything that can be used as a function return
0195 // type).  The usage is:
0196 //
0197 //   // Sets the default value for type T to be foo.
0198 //   DefaultValue<T>::Set(foo);
0199 template <typename T>
0200 class DefaultValue {
0201  public:
0202   // Sets the default value for type T; requires T to be
0203   // copy-constructable and have a public destructor.
0204   static void Set(T x) {
0205     delete producer_;
0206     producer_ = new FixedValueProducer(x);
0207   }
0208 
0209   // Provides a factory function to be called to generate the default value.
0210   // This method can be used even if T is only move-constructible, but it is not
0211   // limited to that case.
0212   typedef T (*FactoryFunction)();
0213   static void SetFactory(FactoryFunction factory) {
0214     delete producer_;
0215     producer_ = new FactoryValueProducer(factory);
0216   }
0217 
0218   // Unsets the default value for type T.
0219   static void Clear() {
0220     delete producer_;
0221     producer_ = NULL;
0222   }
0223 
0224   // Returns true iff the user has set the default value for type T.
0225   static bool IsSet() { return producer_ != NULL; }
0226 
0227   // Returns true if T has a default return value set by the user or there
0228   // exists a built-in default value.
0229   static bool Exists() {
0230     return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
0231   }
0232 
0233   // Returns the default value for type T if the user has set one;
0234   // otherwise returns the built-in default value. Requires that Exists()
0235   // is true, which ensures that the return value is well-defined.
0236   static T Get() {
0237     return producer_ == NULL ?
0238         internal::BuiltInDefaultValue<T>::Get() : producer_->Produce();
0239   }
0240 
0241  private:
0242   class ValueProducer {
0243    public:
0244     virtual ~ValueProducer() {}
0245     virtual T Produce() = 0;
0246   };
0247 
0248   class FixedValueProducer : public ValueProducer {
0249    public:
0250     explicit FixedValueProducer(T value) : value_(value) {}
0251     virtual T Produce() { return value_; }
0252 
0253    private:
0254     const T value_;
0255     GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
0256   };
0257 
0258   class FactoryValueProducer : public ValueProducer {
0259    public:
0260     explicit FactoryValueProducer(FactoryFunction factory)
0261         : factory_(factory) {}
0262     virtual T Produce() { return factory_(); }
0263 
0264    private:
0265     const FactoryFunction factory_;
0266     GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
0267   };
0268 
0269   static ValueProducer* producer_;
0270 };
0271 
0272 // This partial specialization allows a user to set default values for
0273 // reference types.
0274 template <typename T>
0275 class DefaultValue<T&> {
0276  public:
0277   // Sets the default value for type T&.
0278   static void Set(T& x) {  // NOLINT
0279     address_ = &x;
0280   }
0281 
0282   // Unsets the default value for type T&.
0283   static void Clear() {
0284     address_ = NULL;
0285   }
0286 
0287   // Returns true iff the user has set the default value for type T&.
0288   static bool IsSet() { return address_ != NULL; }
0289 
0290   // Returns true if T has a default return value set by the user or there
0291   // exists a built-in default value.
0292   static bool Exists() {
0293     return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
0294   }
0295 
0296   // Returns the default value for type T& if the user has set one;
0297   // otherwise returns the built-in default value if there is one;
0298   // otherwise aborts the process.
0299   static T& Get() {
0300     return address_ == NULL ?
0301         internal::BuiltInDefaultValue<T&>::Get() : *address_;
0302   }
0303 
0304  private:
0305   static T* address_;
0306 };
0307 
0308 // This specialization allows DefaultValue<void>::Get() to
0309 // compile.
0310 template <>
0311 class DefaultValue<void> {
0312  public:
0313   static bool Exists() { return true; }
0314   static void Get() {}
0315 };
0316 
0317 // Points to the user-set default value for type T.
0318 template <typename T>
0319 typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL;
0320 
0321 // Points to the user-set default value for type T&.
0322 template <typename T>
0323 T* DefaultValue<T&>::address_ = NULL;
0324 
0325 // Implement this interface to define an action for function type F.
0326 template <typename F>
0327 class ActionInterface {
0328  public:
0329   typedef typename internal::Function<F>::Result Result;
0330   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0331 
0332   ActionInterface() {}
0333   virtual ~ActionInterface() {}
0334 
0335   // Performs the action.  This method is not const, as in general an
0336   // action can have side effects and be stateful.  For example, a
0337   // get-the-next-element-from-the-collection action will need to
0338   // remember the current element.
0339   virtual Result Perform(const ArgumentTuple& args) = 0;
0340 
0341  private:
0342   GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
0343 };
0344 
0345 // An Action<F> is a copyable and IMMUTABLE (except by assignment)
0346 // object that represents an action to be taken when a mock function
0347 // of type F is called.  The implementation of Action<T> is just a
0348 // linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
0349 // Don't inherit from Action!
0350 //
0351 // You can view an object implementing ActionInterface<F> as a
0352 // concrete action (including its current state), and an Action<F>
0353 // object as a handle to it.
0354 template <typename F>
0355 class Action {
0356  public:
0357   typedef typename internal::Function<F>::Result Result;
0358   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0359 
0360   // Constructs a null Action.  Needed for storing Action objects in
0361   // STL containers.
0362   Action() : impl_(NULL) {}
0363 
0364   // Constructs an Action from its implementation.  A NULL impl is
0365   // used to represent the "do-default" action.
0366   explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
0367 
0368   // Copy constructor.
0369   Action(const Action& action) : impl_(action.impl_) {}
0370 
0371   // This constructor allows us to turn an Action<Func> object into an
0372   // Action<F>, as long as F's arguments can be implicitly converted
0373   // to Func's and Func's return type can be implicitly converted to
0374   // F's.
0375   template <typename Func>
0376   explicit Action(const Action<Func>& action);
0377 
0378   // Returns true iff this is the DoDefault() action.
0379   bool IsDoDefault() const { return impl_.get() == NULL; }
0380 
0381   // Performs the action.  Note that this method is const even though
0382   // the corresponding method in ActionInterface is not.  The reason
0383   // is that a const Action<F> means that it cannot be re-bound to
0384   // another concrete action, not that the concrete action it binds to
0385   // cannot change state.  (Think of the difference between a const
0386   // pointer and a pointer to const.)
0387   Result Perform(const ArgumentTuple& args) const {
0388     internal::Assert(
0389         !IsDoDefault(), __FILE__, __LINE__,
0390         "You are using DoDefault() inside a composite action like "
0391         "DoAll() or WithArgs().  This is not supported for technical "
0392         "reasons.  Please instead spell out the default action, or "
0393         "assign the default action to an Action variable and use "
0394         "the variable in various places.");
0395     return impl_->Perform(args);
0396   }
0397 
0398  private:
0399   template <typename F1, typename F2>
0400   friend class internal::ActionAdaptor;
0401 
0402   internal::linked_ptr<ActionInterface<F> > impl_;
0403 };
0404 
0405 // The PolymorphicAction class template makes it easy to implement a
0406 // polymorphic action (i.e. an action that can be used in mock
0407 // functions of than one type, e.g. Return()).
0408 //
0409 // To define a polymorphic action, a user first provides a COPYABLE
0410 // implementation class that has a Perform() method template:
0411 //
0412 //   class FooAction {
0413 //    public:
0414 //     template <typename Result, typename ArgumentTuple>
0415 //     Result Perform(const ArgumentTuple& args) const {
0416 //       // Processes the arguments and returns a result, using
0417 //       // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
0418 //     }
0419 //     ...
0420 //   };
0421 //
0422 // Then the user creates the polymorphic action using
0423 // MakePolymorphicAction(object) where object has type FooAction.  See
0424 // the definition of Return(void) and SetArgumentPointee<N>(value) for
0425 // complete examples.
0426 template <typename Impl>
0427 class PolymorphicAction {
0428  public:
0429   explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
0430 
0431   template <typename F>
0432   operator Action<F>() const {
0433     return Action<F>(new MonomorphicImpl<F>(impl_));
0434   }
0435 
0436  private:
0437   template <typename F>
0438   class MonomorphicImpl : public ActionInterface<F> {
0439    public:
0440     typedef typename internal::Function<F>::Result Result;
0441     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0442 
0443     explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
0444 
0445     virtual Result Perform(const ArgumentTuple& args) {
0446       return impl_.template Perform<Result>(args);
0447     }
0448 
0449    private:
0450     Impl impl_;
0451 
0452     GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
0453   };
0454 
0455   Impl impl_;
0456 
0457   GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
0458 };
0459 
0460 // Creates an Action from its implementation and returns it.  The
0461 // created Action object owns the implementation.
0462 template <typename F>
0463 Action<F> MakeAction(ActionInterface<F>* impl) {
0464   return Action<F>(impl);
0465 }
0466 
0467 // Creates a polymorphic action from its implementation.  This is
0468 // easier to use than the PolymorphicAction<Impl> constructor as it
0469 // doesn't require you to explicitly write the template argument, e.g.
0470 //
0471 //   MakePolymorphicAction(foo);
0472 // vs
0473 //   PolymorphicAction<TypeOfFoo>(foo);
0474 template <typename Impl>
0475 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
0476   return PolymorphicAction<Impl>(impl);
0477 }
0478 
0479 namespace internal {
0480 
0481 // Allows an Action<F2> object to pose as an Action<F1>, as long as F2
0482 // and F1 are compatible.
0483 template <typename F1, typename F2>
0484 class ActionAdaptor : public ActionInterface<F1> {
0485  public:
0486   typedef typename internal::Function<F1>::Result Result;
0487   typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
0488 
0489   explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
0490 
0491   virtual Result Perform(const ArgumentTuple& args) {
0492     return impl_->Perform(args);
0493   }
0494 
0495  private:
0496   const internal::linked_ptr<ActionInterface<F2> > impl_;
0497 
0498   GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
0499 };
0500 
0501 // Helper struct to specialize ReturnAction to execute a move instead of a copy
0502 // on return. Useful for move-only types, but could be used on any type.
0503 template <typename T>
0504 struct ByMoveWrapper {
0505   explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
0506   T payload;
0507 };
0508 
0509 // Implements the polymorphic Return(x) action, which can be used in
0510 // any function that returns the type of x, regardless of the argument
0511 // types.
0512 //
0513 // Note: The value passed into Return must be converted into
0514 // Function<F>::Result when this action is cast to Action<F> rather than
0515 // when that action is performed. This is important in scenarios like
0516 //
0517 // MOCK_METHOD1(Method, T(U));
0518 // ...
0519 // {
0520 //   Foo foo;
0521 //   X x(&foo);
0522 //   EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
0523 // }
0524 //
0525 // In the example above the variable x holds reference to foo which leaves
0526 // scope and gets destroyed.  If copying X just copies a reference to foo,
0527 // that copy will be left with a hanging reference.  If conversion to T
0528 // makes a copy of foo, the above code is safe. To support that scenario, we
0529 // need to make sure that the type conversion happens inside the EXPECT_CALL
0530 // statement, and conversion of the result of Return to Action<T(U)> is a
0531 // good place for that.
0532 //
0533 template <typename R>
0534 class ReturnAction {
0535  public:
0536   // Constructs a ReturnAction object from the value to be returned.
0537   // 'value' is passed by value instead of by const reference in order
0538   // to allow Return("string literal") to compile.
0539   explicit ReturnAction(R value) : value_(new R(internal::move(value))) {}
0540 
0541   // This template type conversion operator allows Return(x) to be
0542   // used in ANY function that returns x's type.
0543   template <typename F>
0544   operator Action<F>() const {
0545     // Assert statement belongs here because this is the best place to verify
0546     // conditions on F. It produces the clearest error messages
0547     // in most compilers.
0548     // Impl really belongs in this scope as a local class but can't
0549     // because MSVC produces duplicate symbols in different translation units
0550     // in this case. Until MS fixes that bug we put Impl into the class scope
0551     // and put the typedef both here (for use in assert statement) and
0552     // in the Impl class. But both definitions must be the same.
0553     typedef typename Function<F>::Result Result;
0554     GTEST_COMPILE_ASSERT_(
0555         !is_reference<Result>::value,
0556         use_ReturnRef_instead_of_Return_to_return_a_reference);
0557     return Action<F>(new Impl<R, F>(value_));
0558   }
0559 
0560  private:
0561   // Implements the Return(x) action for a particular function type F.
0562   template <typename R_, typename F>
0563   class Impl : public ActionInterface<F> {
0564    public:
0565     typedef typename Function<F>::Result Result;
0566     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0567 
0568     // The implicit cast is necessary when Result has more than one
0569     // single-argument constructor (e.g. Result is std::vector<int>) and R
0570     // has a type conversion operator template.  In that case, value_(value)
0571     // won't compile as the compiler doesn't known which constructor of
0572     // Result to call.  ImplicitCast_ forces the compiler to convert R to
0573     // Result without considering explicit constructors, thus resolving the
0574     // ambiguity. value_ is then initialized using its copy constructor.
0575     explicit Impl(const linked_ptr<R>& value)
0576         : value_before_cast_(*value),
0577           value_(ImplicitCast_<Result>(value_before_cast_)) {}
0578 
0579     virtual Result Perform(const ArgumentTuple&) { return value_; }
0580 
0581    private:
0582     GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
0583                           Result_cannot_be_a_reference_type);
0584     // We save the value before casting just in case it is being cast to a
0585     // wrapper type.
0586     R value_before_cast_;
0587     Result value_;
0588 
0589     GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
0590   };
0591 
0592   // Partially specialize for ByMoveWrapper. This version of ReturnAction will
0593   // move its contents instead.
0594   template <typename R_, typename F>
0595   class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
0596    public:
0597     typedef typename Function<F>::Result Result;
0598     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0599 
0600     explicit Impl(const linked_ptr<R>& wrapper)
0601         : performed_(false), wrapper_(wrapper) {}
0602 
0603     virtual Result Perform(const ArgumentTuple&) {
0604       GTEST_CHECK_(!performed_)
0605           << "A ByMove() action should only be performed once.";
0606       performed_ = true;
0607       return internal::move(wrapper_->payload);
0608     }
0609 
0610    private:
0611     bool performed_;
0612     const linked_ptr<R> wrapper_;
0613 
0614     GTEST_DISALLOW_ASSIGN_(Impl);
0615   };
0616 
0617   const linked_ptr<R> value_;
0618 
0619   GTEST_DISALLOW_ASSIGN_(ReturnAction);
0620 };
0621 
0622 // Implements the ReturnNull() action.
0623 class ReturnNullAction {
0624  public:
0625   // Allows ReturnNull() to be used in any pointer-returning function. In C++11
0626   // this is enforced by returning nullptr, and in non-C++11 by asserting a
0627   // pointer type on compile time.
0628   template <typename Result, typename ArgumentTuple>
0629   static Result Perform(const ArgumentTuple&) {
0630 #if GTEST_LANG_CXX11
0631     return nullptr;
0632 #else
0633     GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
0634                           ReturnNull_can_be_used_to_return_a_pointer_only);
0635     return NULL;
0636 #endif  // GTEST_LANG_CXX11
0637   }
0638 };
0639 
0640 // Implements the Return() action.
0641 class ReturnVoidAction {
0642  public:
0643   // Allows Return() to be used in any void-returning function.
0644   template <typename Result, typename ArgumentTuple>
0645   static void Perform(const ArgumentTuple&) {
0646     CompileAssertTypesEqual<void, Result>();
0647   }
0648 };
0649 
0650 // Implements the polymorphic ReturnRef(x) action, which can be used
0651 // in any function that returns a reference to the type of x,
0652 // regardless of the argument types.
0653 template <typename T>
0654 class ReturnRefAction {
0655  public:
0656   // Constructs a ReturnRefAction object from the reference to be returned.
0657   explicit ReturnRefAction(T& ref) : ref_(ref) {}  // NOLINT
0658 
0659   // This template type conversion operator allows ReturnRef(x) to be
0660   // used in ANY function that returns a reference to x's type.
0661   template <typename F>
0662   operator Action<F>() const {
0663     typedef typename Function<F>::Result Result;
0664     // Asserts that the function return type is a reference.  This
0665     // catches the user error of using ReturnRef(x) when Return(x)
0666     // should be used, and generates some helpful error message.
0667     GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
0668                           use_Return_instead_of_ReturnRef_to_return_a_value);
0669     return Action<F>(new Impl<F>(ref_));
0670   }
0671 
0672  private:
0673   // Implements the ReturnRef(x) action for a particular function type F.
0674   template <typename F>
0675   class Impl : public ActionInterface<F> {
0676    public:
0677     typedef typename Function<F>::Result Result;
0678     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0679 
0680     explicit Impl(T& ref) : ref_(ref) {}  // NOLINT
0681 
0682     virtual Result Perform(const ArgumentTuple&) {
0683       return ref_;
0684     }
0685 
0686    private:
0687     T& ref_;
0688 
0689     GTEST_DISALLOW_ASSIGN_(Impl);
0690   };
0691 
0692   T& ref_;
0693 
0694   GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
0695 };
0696 
0697 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
0698 // used in any function that returns a reference to the type of x,
0699 // regardless of the argument types.
0700 template <typename T>
0701 class ReturnRefOfCopyAction {
0702  public:
0703   // Constructs a ReturnRefOfCopyAction object from the reference to
0704   // be returned.
0705   explicit ReturnRefOfCopyAction(const T& value) : value_(value) {}  // NOLINT
0706 
0707   // This template type conversion operator allows ReturnRefOfCopy(x) to be
0708   // used in ANY function that returns a reference to x's type.
0709   template <typename F>
0710   operator Action<F>() const {
0711     typedef typename Function<F>::Result Result;
0712     // Asserts that the function return type is a reference.  This
0713     // catches the user error of using ReturnRefOfCopy(x) when Return(x)
0714     // should be used, and generates some helpful error message.
0715     GTEST_COMPILE_ASSERT_(
0716         internal::is_reference<Result>::value,
0717         use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
0718     return Action<F>(new Impl<F>(value_));
0719   }
0720 
0721  private:
0722   // Implements the ReturnRefOfCopy(x) action for a particular function type F.
0723   template <typename F>
0724   class Impl : public ActionInterface<F> {
0725    public:
0726     typedef typename Function<F>::Result Result;
0727     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0728 
0729     explicit Impl(const T& value) : value_(value) {}  // NOLINT
0730 
0731     virtual Result Perform(const ArgumentTuple&) {
0732       return value_;
0733     }
0734 
0735    private:
0736     T value_;
0737 
0738     GTEST_DISALLOW_ASSIGN_(Impl);
0739   };
0740 
0741   const T value_;
0742 
0743   GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
0744 };
0745 
0746 // Implements the polymorphic DoDefault() action.
0747 class DoDefaultAction {
0748  public:
0749   // This template type conversion operator allows DoDefault() to be
0750   // used in any function.
0751   template <typename F>
0752   operator Action<F>() const { return Action<F>(NULL); }
0753 };
0754 
0755 // Implements the Assign action to set a given pointer referent to a
0756 // particular value.
0757 template <typename T1, typename T2>
0758 class AssignAction {
0759  public:
0760   AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
0761 
0762   template <typename Result, typename ArgumentTuple>
0763   void Perform(const ArgumentTuple& /* args */) const {
0764     *ptr_ = value_;
0765   }
0766 
0767  private:
0768   T1* const ptr_;
0769   const T2 value_;
0770 
0771   GTEST_DISALLOW_ASSIGN_(AssignAction);
0772 };
0773 
0774 #if !GTEST_OS_WINDOWS_MOBILE
0775 
0776 // Implements the SetErrnoAndReturn action to simulate return from
0777 // various system calls and libc functions.
0778 template <typename T>
0779 class SetErrnoAndReturnAction {
0780  public:
0781   SetErrnoAndReturnAction(int errno_value, T result)
0782       : errno_(errno_value),
0783         result_(result) {}
0784   template <typename Result, typename ArgumentTuple>
0785   Result Perform(const ArgumentTuple& /* args */) const {
0786     errno = errno_;
0787     return result_;
0788   }
0789 
0790  private:
0791   const int errno_;
0792   const T result_;
0793 
0794   GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
0795 };
0796 
0797 #endif  // !GTEST_OS_WINDOWS_MOBILE
0798 
0799 // Implements the SetArgumentPointee<N>(x) action for any function
0800 // whose N-th argument (0-based) is a pointer to x's type.  The
0801 // template parameter kIsProto is true iff type A is ProtocolMessage,
0802 // proto2::Message, or a sub-class of those.
0803 template <size_t N, typename A, bool kIsProto>
0804 class SetArgumentPointeeAction {
0805  public:
0806   // Constructs an action that sets the variable pointed to by the
0807   // N-th function argument to 'value'.
0808   explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
0809 
0810   template <typename Result, typename ArgumentTuple>
0811   void Perform(const ArgumentTuple& args) const {
0812     CompileAssertTypesEqual<void, Result>();
0813     *::testing::get<N>(args) = value_;
0814   }
0815 
0816  private:
0817   const A value_;
0818 
0819   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
0820 };
0821 
0822 template <size_t N, typename Proto>
0823 class SetArgumentPointeeAction<N, Proto, true> {
0824  public:
0825   // Constructs an action that sets the variable pointed to by the
0826   // N-th function argument to 'proto'.  Both ProtocolMessage and
0827   // proto2::Message have the CopyFrom() method, so the same
0828   // implementation works for both.
0829   explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
0830     proto_->CopyFrom(proto);
0831   }
0832 
0833   template <typename Result, typename ArgumentTuple>
0834   void Perform(const ArgumentTuple& args) const {
0835     CompileAssertTypesEqual<void, Result>();
0836     ::testing::get<N>(args)->CopyFrom(*proto_);
0837   }
0838 
0839  private:
0840   const internal::linked_ptr<Proto> proto_;
0841 
0842   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
0843 };
0844 
0845 // Implements the InvokeWithoutArgs(f) action.  The template argument
0846 // FunctionImpl is the implementation type of f, which can be either a
0847 // function pointer or a functor.  InvokeWithoutArgs(f) can be used as an
0848 // Action<F> as long as f's type is compatible with F (i.e. f can be
0849 // assigned to a tr1::function<F>).
0850 template <typename FunctionImpl>
0851 class InvokeWithoutArgsAction {
0852  public:
0853   // The c'tor makes a copy of function_impl (either a function
0854   // pointer or a functor).
0855   explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
0856       : function_impl_(function_impl) {}
0857 
0858   // Allows InvokeWithoutArgs(f) to be used as any action whose type is
0859   // compatible with f.
0860   template <typename Result, typename ArgumentTuple>
0861   Result Perform(const ArgumentTuple&) { return function_impl_(); }
0862 
0863  private:
0864   FunctionImpl function_impl_;
0865 
0866   GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
0867 };
0868 
0869 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
0870 template <class Class, typename MethodPtr>
0871 class InvokeMethodWithoutArgsAction {
0872  public:
0873   InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
0874       : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
0875 
0876   template <typename Result, typename ArgumentTuple>
0877   Result Perform(const ArgumentTuple&) const {
0878     return (obj_ptr_->*method_ptr_)();
0879   }
0880 
0881  private:
0882   Class* const obj_ptr_;
0883   const MethodPtr method_ptr_;
0884 
0885   GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
0886 };
0887 
0888 // Implements the IgnoreResult(action) action.
0889 template <typename A>
0890 class IgnoreResultAction {
0891  public:
0892   explicit IgnoreResultAction(const A& action) : action_(action) {}
0893 
0894   template <typename F>
0895   operator Action<F>() const {
0896     // Assert statement belongs here because this is the best place to verify
0897     // conditions on F. It produces the clearest error messages
0898     // in most compilers.
0899     // Impl really belongs in this scope as a local class but can't
0900     // because MSVC produces duplicate symbols in different translation units
0901     // in this case. Until MS fixes that bug we put Impl into the class scope
0902     // and put the typedef both here (for use in assert statement) and
0903     // in the Impl class. But both definitions must be the same.
0904     typedef typename internal::Function<F>::Result Result;
0905 
0906     // Asserts at compile time that F returns void.
0907     CompileAssertTypesEqual<void, Result>();
0908 
0909     return Action<F>(new Impl<F>(action_));
0910   }
0911 
0912  private:
0913   template <typename F>
0914   class Impl : public ActionInterface<F> {
0915    public:
0916     typedef typename internal::Function<F>::Result Result;
0917     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0918 
0919     explicit Impl(const A& action) : action_(action) {}
0920 
0921     virtual void Perform(const ArgumentTuple& args) {
0922       // Performs the action and ignores its result.
0923       action_.Perform(args);
0924     }
0925 
0926    private:
0927     // Type OriginalFunction is the same as F except that its return
0928     // type is IgnoredValue.
0929     typedef typename internal::Function<F>::MakeResultIgnoredValue
0930         OriginalFunction;
0931 
0932     const Action<OriginalFunction> action_;
0933 
0934     GTEST_DISALLOW_ASSIGN_(Impl);
0935   };
0936 
0937   const A action_;
0938 
0939   GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
0940 };
0941 
0942 // A ReferenceWrapper<T> object represents a reference to type T,
0943 // which can be either const or not.  It can be explicitly converted
0944 // from, and implicitly converted to, a T&.  Unlike a reference,
0945 // ReferenceWrapper<T> can be copied and can survive template type
0946 // inference.  This is used to support by-reference arguments in the
0947 // InvokeArgument<N>(...) action.  The idea was from "reference
0948 // wrappers" in tr1, which we don't have in our source tree yet.
0949 template <typename T>
0950 class ReferenceWrapper {
0951  public:
0952   // Constructs a ReferenceWrapper<T> object from a T&.
0953   explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {}  // NOLINT
0954 
0955   // Allows a ReferenceWrapper<T> object to be implicitly converted to
0956   // a T&.
0957   operator T&() const { return *pointer_; }
0958  private:
0959   T* pointer_;
0960 };
0961 
0962 // Allows the expression ByRef(x) to be printed as a reference to x.
0963 template <typename T>
0964 void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
0965   T& value = ref;
0966   UniversalPrinter<T&>::Print(value, os);
0967 }
0968 
0969 // Does two actions sequentially.  Used for implementing the DoAll(a1,
0970 // a2, ...) action.
0971 template <typename Action1, typename Action2>
0972 class DoBothAction {
0973  public:
0974   DoBothAction(Action1 action1, Action2 action2)
0975       : action1_(action1), action2_(action2) {}
0976 
0977   // This template type conversion operator allows DoAll(a1, ..., a_n)
0978   // to be used in ANY function of compatible type.
0979   template <typename F>
0980   operator Action<F>() const {
0981     return Action<F>(new Impl<F>(action1_, action2_));
0982   }
0983 
0984  private:
0985   // Implements the DoAll(...) action for a particular function type F.
0986   template <typename F>
0987   class Impl : public ActionInterface<F> {
0988    public:
0989     typedef typename Function<F>::Result Result;
0990     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0991     typedef typename Function<F>::MakeResultVoid VoidResult;
0992 
0993     Impl(const Action<VoidResult>& action1, const Action<F>& action2)
0994         : action1_(action1), action2_(action2) {}
0995 
0996     virtual Result Perform(const ArgumentTuple& args) {
0997       action1_.Perform(args);
0998       return action2_.Perform(args);
0999     }
1000 
1001    private:
1002     const Action<VoidResult> action1_;
1003     const Action<F> action2_;
1004 
1005     GTEST_DISALLOW_ASSIGN_(Impl);
1006   };
1007 
1008   Action1 action1_;
1009   Action2 action2_;
1010 
1011   GTEST_DISALLOW_ASSIGN_(DoBothAction);
1012 };
1013 
1014 }  // namespace internal
1015 
1016 // An Unused object can be implicitly constructed from ANY value.
1017 // This is handy when defining actions that ignore some or all of the
1018 // mock function arguments.  For example, given
1019 //
1020 //   MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1021 //   MOCK_METHOD3(Bar, double(int index, double x, double y));
1022 //
1023 // instead of
1024 //
1025 //   double DistanceToOriginWithLabel(const string& label, double x, double y) {
1026 //     return sqrt(x*x + y*y);
1027 //   }
1028 //   double DistanceToOriginWithIndex(int index, double x, double y) {
1029 //     return sqrt(x*x + y*y);
1030 //   }
1031 //   ...
1032 //   EXEPCT_CALL(mock, Foo("abc", _, _))
1033 //       .WillOnce(Invoke(DistanceToOriginWithLabel));
1034 //   EXEPCT_CALL(mock, Bar(5, _, _))
1035 //       .WillOnce(Invoke(DistanceToOriginWithIndex));
1036 //
1037 // you could write
1038 //
1039 //   // We can declare any uninteresting argument as Unused.
1040 //   double DistanceToOrigin(Unused, double x, double y) {
1041 //     return sqrt(x*x + y*y);
1042 //   }
1043 //   ...
1044 //   EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
1045 //   EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
1046 typedef internal::IgnoredValue Unused;
1047 
1048 // This constructor allows us to turn an Action<From> object into an
1049 // Action<To>, as long as To's arguments can be implicitly converted
1050 // to From's and From's return type cann be implicitly converted to
1051 // To's.
1052 template <typename To>
1053 template <typename From>
1054 Action<To>::Action(const Action<From>& from)
1055     : impl_(new internal::ActionAdaptor<To, From>(from)) {}
1056 
1057 // Creates an action that returns 'value'.  'value' is passed by value
1058 // instead of const reference - otherwise Return("string literal")
1059 // will trigger a compiler error about using array as initializer.
1060 template <typename R>
1061 internal::ReturnAction<R> Return(R value) {
1062   return internal::ReturnAction<R>(internal::move(value));
1063 }
1064 
1065 // Creates an action that returns NULL.
1066 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
1067   return MakePolymorphicAction(internal::ReturnNullAction());
1068 }
1069 
1070 // Creates an action that returns from a void function.
1071 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
1072   return MakePolymorphicAction(internal::ReturnVoidAction());
1073 }
1074 
1075 // Creates an action that returns the reference to a variable.
1076 template <typename R>
1077 inline internal::ReturnRefAction<R> ReturnRef(R& x) {  // NOLINT
1078   return internal::ReturnRefAction<R>(x);
1079 }
1080 
1081 // Creates an action that returns the reference to a copy of the
1082 // argument.  The copy is created when the action is constructed and
1083 // lives as long as the action.
1084 template <typename R>
1085 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
1086   return internal::ReturnRefOfCopyAction<R>(x);
1087 }
1088 
1089 // Modifies the parent action (a Return() action) to perform a move of the
1090 // argument instead of a copy.
1091 // Return(ByMove()) actions can only be executed once and will assert this
1092 // invariant.
1093 template <typename R>
1094 internal::ByMoveWrapper<R> ByMove(R x) {
1095   return internal::ByMoveWrapper<R>(internal::move(x));
1096 }
1097 
1098 // Creates an action that does the default action for the give mock function.
1099 inline internal::DoDefaultAction DoDefault() {
1100   return internal::DoDefaultAction();
1101 }
1102 
1103 // Creates an action that sets the variable pointed by the N-th
1104 // (0-based) function argument to 'value'.
1105 template <size_t N, typename T>
1106 PolymorphicAction<
1107   internal::SetArgumentPointeeAction<
1108     N, T, internal::IsAProtocolMessage<T>::value> >
1109 SetArgPointee(const T& x) {
1110   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1111       N, T, internal::IsAProtocolMessage<T>::value>(x));
1112 }
1113 
1114 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
1115 // This overload allows SetArgPointee() to accept a string literal.
1116 // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
1117 // this overload from the templated version and emit a compile error.
1118 template <size_t N>
1119 PolymorphicAction<
1120   internal::SetArgumentPointeeAction<N, const char*, false> >
1121 SetArgPointee(const char* p) {
1122   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1123       N, const char*, false>(p));
1124 }
1125 
1126 template <size_t N>
1127 PolymorphicAction<
1128   internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
1129 SetArgPointee(const wchar_t* p) {
1130   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1131       N, const wchar_t*, false>(p));
1132 }
1133 #endif
1134 
1135 // The following version is DEPRECATED.
1136 template <size_t N, typename T>
1137 PolymorphicAction<
1138   internal::SetArgumentPointeeAction<
1139     N, T, internal::IsAProtocolMessage<T>::value> >
1140 SetArgumentPointee(const T& x) {
1141   return MakePolymorphicAction(internal::SetArgumentPointeeAction<
1142       N, T, internal::IsAProtocolMessage<T>::value>(x));
1143 }
1144 
1145 // Creates an action that sets a pointer referent to a given value.
1146 template <typename T1, typename T2>
1147 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
1148   return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
1149 }
1150 
1151 #if !GTEST_OS_WINDOWS_MOBILE
1152 
1153 // Creates an action that sets errno and returns the appropriate error.
1154 template <typename T>
1155 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
1156 SetErrnoAndReturn(int errval, T result) {
1157   return MakePolymorphicAction(
1158       internal::SetErrnoAndReturnAction<T>(errval, result));
1159 }
1160 
1161 #endif  // !GTEST_OS_WINDOWS_MOBILE
1162 
1163 // Various overloads for InvokeWithoutArgs().
1164 
1165 // Creates an action that invokes 'function_impl' with no argument.
1166 template <typename FunctionImpl>
1167 PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
1168 InvokeWithoutArgs(FunctionImpl function_impl) {
1169   return MakePolymorphicAction(
1170       internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
1171 }
1172 
1173 // Creates an action that invokes the given method on the given object
1174 // with no argument.
1175 template <class Class, typename MethodPtr>
1176 PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
1177 InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
1178   return MakePolymorphicAction(
1179       internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
1180           obj_ptr, method_ptr));
1181 }
1182 
1183 // Creates an action that performs an_action and throws away its
1184 // result.  In other words, it changes the return type of an_action to
1185 // void.  an_action MUST NOT return void, or the code won't compile.
1186 template <typename A>
1187 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
1188   return internal::IgnoreResultAction<A>(an_action);
1189 }
1190 
1191 // Creates a reference wrapper for the given L-value.  If necessary,
1192 // you can explicitly specify the type of the reference.  For example,
1193 // suppose 'derived' is an object of type Derived, ByRef(derived)
1194 // would wrap a Derived&.  If you want to wrap a const Base& instead,
1195 // where Base is a base class of Derived, just write:
1196 //
1197 //   ByRef<const Base>(derived)
1198 template <typename T>
1199 inline internal::ReferenceWrapper<T> ByRef(T& l_value) {  // NOLINT
1200   return internal::ReferenceWrapper<T>(l_value);
1201 }
1202 
1203 }  // namespace testing
1204 
1205 #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_