gmock-actions.h
Go to the documentation of this file.
1 // Copyright 2007, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 
31 // Google Mock - a framework for writing C++ mock classes.
32 //
33 // This file implements some commonly used actions.
34 
35 // GOOGLETEST_CM0002 DO NOT DELETE
36 
37 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
38 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
39 
40 #ifndef _WIN32_WCE
41 # include <errno.h>
42 #endif
43 
44 #include <algorithm>
45 #include <functional>
46 #include <memory>
47 #include <string>
48 #include <type_traits>
49 #include <utility>
50 
53 
54 #ifdef _MSC_VER
55 # pragma warning(push)
56 # pragma warning(disable:4100)
57 #endif
58 
59 namespace testing {
60 
61 // To implement an action Foo, define:
62 // 1. a class FooAction that implements the ActionInterface interface, and
63 // 2. a factory function that creates an Action object from a
64 // const FooAction*.
65 //
66 // The two-level delegation design follows that of Matcher, providing
67 // consistency for extension developers. It also eases ownership
68 // management as Action objects can now be copied like plain values.
69 
70 namespace internal {
71 
72 // BuiltInDefaultValueGetter<T, true>::Get() returns a
73 // default-constructed T value. BuiltInDefaultValueGetter<T,
74 // false>::Get() crashes with an error.
75 //
76 // This primary template is used when kDefaultConstructible is true.
77 template <typename T, bool kDefaultConstructible>
79  static T Get() { return T(); }
80 };
81 template <typename T>
83  static T Get() {
84  Assert(false, __FILE__, __LINE__,
85  "Default action undefined for the function return type.");
86  return internal::Invalid<T>();
87  // The above statement will never be reached, but is required in
88  // order for this function to compile.
89  }
90 };
91 
92 // BuiltInDefaultValue<T>::Get() returns the "built-in" default value
93 // for type T, which is NULL when T is a raw pointer type, 0 when T is
94 // a numeric type, false when T is bool, or "" when T is string or
95 // std::string. In addition, in C++11 and above, it turns a
96 // default-constructed T value if T is default constructible. For any
97 // other type T, the built-in default T value is undefined, and the
98 // function will abort the process.
99 template <typename T>
101  public:
102  // This function returns true iff type T has a built-in default value.
103  static bool Exists() {
105  }
106 
107  static T Get() {
110  }
111 };
112 
113 // This partial specialization says that we use the same built-in
114 // default value for T and const T.
115 template <typename T>
117  public:
118  static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
119  static T Get() { return BuiltInDefaultValue<T>::Get(); }
120 };
121 
122 // This partial specialization defines the default values for pointer
123 // types.
124 template <typename T>
126  public:
127  static bool Exists() { return true; }
128  static T* Get() { return nullptr; }
129 };
130 
131 // The following specializations define the default values for
132 // specific types we care about.
133 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
134  template <> \
135  class BuiltInDefaultValue<type> { \
136  public: \
137  static bool Exists() { return true; } \
138  static type Get() { return value; } \
139  }
140 
142 #if GTEST_HAS_GLOBAL_STRING
144 #endif // GTEST_HAS_GLOBAL_STRING
150 
151 // There's no need for a default action for signed wchar_t, as that
152 // type is the same as wchar_t for gcc, and invalid for MSVC.
153 //
154 // There's also no need for a default action for unsigned wchar_t, as
155 // that type is the same as unsigned int for gcc, and invalid for
156 // MSVC.
157 #if GMOCK_WCHAR_T_IS_NATIVE_
158 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
159 #endif
160 
161 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
162 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
165 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
166 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
171 
172 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
173 
174 } // namespace internal
175 
176 // When an unexpected function call is encountered, Google Mock will
177 // let it return a default value if the user has specified one for its
178 // return type, or if the return type has a built-in default value;
179 // otherwise Google Mock won't know what value to return and will have
180 // to abort the process.
181 //
182 // The DefaultValue<T> class allows a user to specify the
183 // default value for a type T that is both copyable and publicly
184 // destructible (i.e. anything that can be used as a function return
185 // type). The usage is:
186 //
187 // // Sets the default value for type T to be foo.
188 // DefaultValue<T>::Set(foo);
189 template <typename T>
191  public:
192  // Sets the default value for type T; requires T to be
193  // copy-constructable and have a public destructor.
194  static void Set(T x) {
195  delete producer_;
197  }
198 
199  // Provides a factory function to be called to generate the default value.
200  // This method can be used even if T is only move-constructible, but it is not
201  // limited to that case.
202  typedef T (*FactoryFunction)();
203  static void SetFactory(FactoryFunction factory) {
204  delete producer_;
205  producer_ = new FactoryValueProducer(factory);
206  }
207 
208  // Unsets the default value for type T.
209  static void Clear() {
210  delete producer_;
211  producer_ = nullptr;
212  }
213 
214  // Returns true iff the user has set the default value for type T.
215  static bool IsSet() { return producer_ != nullptr; }
216 
217  // Returns true if T has a default return value set by the user or there
218  // exists a built-in default value.
219  static bool Exists() {
221  }
222 
223  // Returns the default value for type T if the user has set one;
224  // otherwise returns the built-in default value. Requires that Exists()
225  // is true, which ensures that the return value is well-defined.
226  static T Get() {
228  : producer_->Produce();
229  }
230 
231  private:
233  public:
234  virtual ~ValueProducer() {}
235  virtual T Produce() = 0;
236  };
237 
239  public:
241  T Produce() override { return value_; }
242 
243  private:
244  const T value_;
246  };
247 
249  public:
251  : factory_(factory) {}
252  T Produce() override { return factory_(); }
253 
254  private:
257  };
258 
260 };
261 
262 // This partial specialization allows a user to set default values for
263 // reference types.
264 template <typename T>
265 class DefaultValue<T&> {
266  public:
267  // Sets the default value for type T&.
268  static void Set(T& x) { // NOLINT
269  address_ = &x;
270  }
271 
272  // Unsets the default value for type T&.
273  static void Clear() { address_ = nullptr; }
274 
275  // Returns true iff the user has set the default value for type T&.
276  static bool IsSet() { return address_ != nullptr; }
277 
278  // Returns true if T has a default return value set by the user or there
279  // exists a built-in default value.
280  static bool Exists() {
281  return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
282  }
283 
284  // Returns the default value for type T& if the user has set one;
285  // otherwise returns the built-in default value if there is one;
286  // otherwise aborts the process.
287  static T& Get() {
288  return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get()
289  : *address_;
290  }
291 
292  private:
293  static T* address_;
294 };
295 
296 // This specialization allows DefaultValue<void>::Get() to
297 // compile.
298 template <>
300  public:
301  static bool Exists() { return true; }
302  static void Get() {}
303 };
304 
305 // Points to the user-set default value for type T.
306 template <typename T>
307 typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr;
308 
309 // Points to the user-set default value for type T&.
310 template <typename T>
311 T* DefaultValue<T&>::address_ = nullptr;
312 
313 // Implement this interface to define an action for function type F.
314 template <typename F>
316  public:
319 
321  virtual ~ActionInterface() {}
322 
323  // Performs the action. This method is not const, as in general an
324  // action can have side effects and be stateful. For example, a
325  // get-the-next-element-from-the-collection action will need to
326  // remember the current element.
327  virtual Result Perform(const ArgumentTuple& args) = 0;
328 
329  private:
331 };
332 
333 // An Action<F> is a copyable and IMMUTABLE (except by assignment)
334 // object that represents an action to be taken when a mock function
335 // of type F is called. The implementation of Action<T> is just a
336 // std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
337 // You can view an object implementing ActionInterface<F> as a
338 // concrete action (including its current state), and an Action<F>
339 // object as a handle to it.
340 template <typename F>
341 class Action {
342  // Adapter class to allow constructing Action from a legacy ActionInterface.
343  // New code should create Actions from functors instead.
344  struct ActionAdapter {
345  // Adapter must be copyable to satisfy std::function requirements.
346  ::std::shared_ptr<ActionInterface<F>> impl_;
347 
348  template <typename... Args>
350  return impl_->Perform(
351  ::std::forward_as_tuple(::std::forward<Args>(args)...));
352  }
353  };
354 
355  public:
358 
359  // Constructs a null Action. Needed for storing Action objects in
360  // STL containers.
361  Action() {}
362 
363  // Construct an Action from a specified callable.
364  // This cannot take std::function directly, because then Action would not be
365  // directly constructible from lambda (it would require two conversions).
366  template <typename G,
367  typename = typename ::std::enable_if<
368  ::std::is_constructible<::std::function<F>, G>::value>::type>
369  Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
370 
371  // Constructs an Action from its implementation.
372  explicit Action(ActionInterface<F>* impl)
373  : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
374 
375  // This constructor allows us to turn an Action<Func> object into an
376  // Action<F>, as long as F's arguments can be implicitly converted
377  // to Func's and Func's return type can be implicitly converted to F's.
378  template <typename Func>
379  explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
380 
381  // Returns true iff this is the DoDefault() action.
382  bool IsDoDefault() const { return fun_ == nullptr; }
383 
384  // Performs the action. Note that this method is const even though
385  // the corresponding method in ActionInterface is not. The reason
386  // is that a const Action<F> means that it cannot be re-bound to
387  // another concrete action, not that the concrete action it binds to
388  // cannot change state. (Think of the difference between a const
389  // pointer and a pointer to const.)
391  if (IsDoDefault()) {
392  internal::IllegalDoDefault(__FILE__, __LINE__);
393  }
394  return internal::Apply(fun_, ::std::move(args));
395  }
396 
397  private:
398  template <typename G>
399  friend class Action;
400 
401  // fun_ is an empty function iff this is the DoDefault() action.
402  ::std::function<F> fun_;
403 };
404 
405 // The PolymorphicAction class template makes it easy to implement a
406 // polymorphic action (i.e. an action that can be used in mock
407 // functions of than one type, e.g. Return()).
408 //
409 // To define a polymorphic action, a user first provides a COPYABLE
410 // implementation class that has a Perform() method template:
411 //
412 // class FooAction {
413 // public:
414 // template <typename Result, typename ArgumentTuple>
415 // Result Perform(const ArgumentTuple& args) const {
416 // // Processes the arguments and returns a result, using
417 // // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
418 // }
419 // ...
420 // };
421 //
422 // Then the user creates the polymorphic action using
423 // MakePolymorphicAction(object) where object has type FooAction. See
424 // the definition of Return(void) and SetArgumentPointee<N>(value) for
425 // complete examples.
426 template <typename Impl>
428  public:
429  explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
430 
431  template <typename F>
432  operator Action<F>() const {
433  return Action<F>(new MonomorphicImpl<F>(impl_));
434  }
435 
436  private:
437  template <typename F>
438  class MonomorphicImpl : public ActionInterface<F> {
439  public:
442 
443  explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
444 
445  Result Perform(const ArgumentTuple& args) override {
446  return impl_.template Perform<Result>(args);
447  }
448 
449  private:
450  Impl impl_;
451 
453  };
454 
455  Impl impl_;
456 
458 };
459 
460 // Creates an Action from its implementation and returns it. The
461 // created Action object owns the implementation.
462 template <typename F>
464  return Action<F>(impl);
465 }
466 
467 // Creates a polymorphic action from its implementation. This is
468 // easier to use than the PolymorphicAction<Impl> constructor as it
469 // doesn't require you to explicitly write the template argument, e.g.
470 //
471 // MakePolymorphicAction(foo);
472 // vs
473 // PolymorphicAction<TypeOfFoo>(foo);
474 template <typename Impl>
476  return PolymorphicAction<Impl>(impl);
477 }
478 
479 namespace internal {
480 
481 // Helper struct to specialize ReturnAction to execute a move instead of a copy
482 // on return. Useful for move-only types, but could be used on any type.
483 template <typename T>
485  explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
487 };
488 
489 // Implements the polymorphic Return(x) action, which can be used in
490 // any function that returns the type of x, regardless of the argument
491 // types.
492 //
493 // Note: The value passed into Return must be converted into
494 // Function<F>::Result when this action is cast to Action<F> rather than
495 // when that action is performed. This is important in scenarios like
496 //
497 // MOCK_METHOD1(Method, T(U));
498 // ...
499 // {
500 // Foo foo;
501 // X x(&foo);
502 // EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
503 // }
504 //
505 // In the example above the variable x holds reference to foo which leaves
506 // scope and gets destroyed. If copying X just copies a reference to foo,
507 // that copy will be left with a hanging reference. If conversion to T
508 // makes a copy of foo, the above code is safe. To support that scenario, we
509 // need to make sure that the type conversion happens inside the EXPECT_CALL
510 // statement, and conversion of the result of Return to Action<T(U)> is a
511 // good place for that.
512 //
513 // The real life example of the above scenario happens when an invocation
514 // of gtl::Container() is passed into Return.
515 //
516 template <typename R>
518  public:
519  // Constructs a ReturnAction object from the value to be returned.
520  // 'value' is passed by value instead of by const reference in order
521  // to allow Return("string literal") to compile.
522  explicit ReturnAction(R value) : value_(new R(std::move(value))) {}
523 
524  // This template type conversion operator allows Return(x) to be
525  // used in ANY function that returns x's type.
526  template <typename F>
527  operator Action<F>() const { // NOLINT
528  // Assert statement belongs here because this is the best place to verify
529  // conditions on F. It produces the clearest error messages
530  // in most compilers.
531  // Impl really belongs in this scope as a local class but can't
532  // because MSVC produces duplicate symbols in different translation units
533  // in this case. Until MS fixes that bug we put Impl into the class scope
534  // and put the typedef both here (for use in assert statement) and
535  // in the Impl class. But both definitions must be the same.
536  typedef typename Function<F>::Result Result;
539  use_ReturnRef_instead_of_Return_to_return_a_reference);
540  static_assert(!std::is_void<Result>::value,
541  "Can't use Return() on an action expected to return `void`.");
542  return Action<F>(new Impl<R, F>(value_));
543  }
544 
545  private:
546  // Implements the Return(x) action for a particular function type F.
547  template <typename R_, typename F>
548  class Impl : public ActionInterface<F> {
549  public:
550  typedef typename Function<F>::Result Result;
552 
553  // The implicit cast is necessary when Result has more than one
554  // single-argument constructor (e.g. Result is std::vector<int>) and R
555  // has a type conversion operator template. In that case, value_(value)
556  // won't compile as the compiler doesn't known which constructor of
557  // Result to call. ImplicitCast_ forces the compiler to convert R to
558  // Result without considering explicit constructors, thus resolving the
559  // ambiguity. value_ is then initialized using its copy constructor.
560  explicit Impl(const std::shared_ptr<R>& value)
563 
564  Result Perform(const ArgumentTuple&) override { return value_; }
565 
566  private:
568  Result_cannot_be_a_reference_type);
569  // We save the value before casting just in case it is being cast to a
570  // wrapper type.
573 
575  };
576 
577  // Partially specialize for ByMoveWrapper. This version of ReturnAction will
578  // move its contents instead.
579  template <typename R_, typename F>
580  class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
581  public:
582  typedef typename Function<F>::Result Result;
584 
585  explicit Impl(const std::shared_ptr<R>& wrapper)
586  : performed_(false), wrapper_(wrapper) {}
587 
588  Result Perform(const ArgumentTuple&) override {
589  GTEST_CHECK_(!performed_)
590  << "A ByMove() action should only be performed once.";
591  performed_ = true;
592  return std::move(wrapper_->payload);
593  }
594 
595  private:
597  const std::shared_ptr<R> wrapper_;
598 
600  };
601 
602  const std::shared_ptr<R> value_;
603 
605 };
606 
607 // Implements the ReturnNull() action.
609  public:
610  // Allows ReturnNull() to be used in any pointer-returning function. In C++11
611  // this is enforced by returning nullptr, and in non-C++11 by asserting a
612  // pointer type on compile time.
613  template <typename Result, typename ArgumentTuple>
614  static Result Perform(const ArgumentTuple&) {
615  return nullptr;
616  }
617 };
618 
619 // Implements the Return() action.
621  public:
622  // Allows Return() to be used in any void-returning function.
623  template <typename Result, typename ArgumentTuple>
624  static void Perform(const ArgumentTuple&) {
626  }
627 };
628 
629 // Implements the polymorphic ReturnRef(x) action, which can be used
630 // in any function that returns a reference to the type of x,
631 // regardless of the argument types.
632 template <typename T>
634  public:
635  // Constructs a ReturnRefAction object from the reference to be returned.
636  explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
637 
638  // This template type conversion operator allows ReturnRef(x) to be
639  // used in ANY function that returns a reference to x's type.
640  template <typename F>
641  operator Action<F>() const {
642  typedef typename Function<F>::Result Result;
643  // Asserts that the function return type is a reference. This
644  // catches the user error of using ReturnRef(x) when Return(x)
645  // should be used, and generates some helpful error message.
647  use_Return_instead_of_ReturnRef_to_return_a_value);
648  return Action<F>(new Impl<F>(ref_));
649  }
650 
651  private:
652  // Implements the ReturnRef(x) action for a particular function type F.
653  template <typename F>
654  class Impl : public ActionInterface<F> {
655  public:
656  typedef typename Function<F>::Result Result;
658 
659  explicit Impl(T& ref) : ref_(ref) {} // NOLINT
660 
661  Result Perform(const ArgumentTuple&) override { return ref_; }
662 
663  private:
664  T& ref_;
665 
667  };
668 
669  T& ref_;
670 
672 };
673 
674 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
675 // used in any function that returns a reference to the type of x,
676 // regardless of the argument types.
677 template <typename T>
679  public:
680  // Constructs a ReturnRefOfCopyAction object from the reference to
681  // be returned.
682  explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
683 
684  // This template type conversion operator allows ReturnRefOfCopy(x) to be
685  // used in ANY function that returns a reference to x's type.
686  template <typename F>
687  operator Action<F>() const {
688  typedef typename Function<F>::Result Result;
689  // Asserts that the function return type is a reference. This
690  // catches the user error of using ReturnRefOfCopy(x) when Return(x)
691  // should be used, and generates some helpful error message.
694  use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
695  return Action<F>(new Impl<F>(value_));
696  }
697 
698  private:
699  // Implements the ReturnRefOfCopy(x) action for a particular function type F.
700  template <typename F>
701  class Impl : public ActionInterface<F> {
702  public:
703  typedef typename Function<F>::Result Result;
705 
706  explicit Impl(const T& value) : value_(value) {} // NOLINT
707 
708  Result Perform(const ArgumentTuple&) override { return value_; }
709 
710  private:
712 
714  };
715 
716  const T value_;
717 
719 };
720 
721 // Implements the polymorphic DoDefault() action.
723  public:
724  // This template type conversion operator allows DoDefault() to be
725  // used in any function.
726  template <typename F>
727  operator Action<F>() const { return Action<F>(); } // NOLINT
728 };
729 
730 // Implements the Assign action to set a given pointer referent to a
731 // particular value.
732 template <typename T1, typename T2>
734  public:
735  AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
736 
737  template <typename Result, typename ArgumentTuple>
738  void Perform(const ArgumentTuple& /* args */) const {
739  *ptr_ = value_;
740  }
741 
742  private:
743  T1* const ptr_;
744  const T2 value_;
745 
747 };
748 
749 #if !GTEST_OS_WINDOWS_MOBILE
750 
751 // Implements the SetErrnoAndReturn action to simulate return from
752 // various system calls and libc functions.
753 template <typename T>
755  public:
756  SetErrnoAndReturnAction(int errno_value, T result)
757  : errno_(errno_value),
758  result_(result) {}
759  template <typename Result, typename ArgumentTuple>
760  Result Perform(const ArgumentTuple& /* args */) const {
761  errno = errno_;
762  return result_;
763  }
764 
765  private:
766  const int errno_;
767  const T result_;
768 
770 };
771 
772 #endif // !GTEST_OS_WINDOWS_MOBILE
773 
774 // Implements the SetArgumentPointee<N>(x) action for any function
775 // whose N-th argument (0-based) is a pointer to x's type. The
776 // template parameter kIsProto is true iff type A is ProtocolMessage,
777 // proto2::Message, or a sub-class of those.
778 template <size_t N, typename A, bool kIsProto>
780  public:
781  // Constructs an action that sets the variable pointed to by the
782  // N-th function argument to 'value'.
783  explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
784 
785  template <typename Result, typename ArgumentTuple>
786  void Perform(const ArgumentTuple& args) const {
788  *::std::get<N>(args) = value_;
789  }
790 
791  private:
792  const A value_;
793 
795 };
796 
797 template <size_t N, typename Proto>
798 class SetArgumentPointeeAction<N, Proto, true> {
799  public:
800  // Constructs an action that sets the variable pointed to by the
801  // N-th function argument to 'proto'. Both ProtocolMessage and
802  // proto2::Message have the CopyFrom() method, so the same
803  // implementation works for both.
804  explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
805  proto_->CopyFrom(proto);
806  }
807 
808  template <typename Result, typename ArgumentTuple>
809  void Perform(const ArgumentTuple& args) const {
811  ::std::get<N>(args)->CopyFrom(*proto_);
812  }
813 
814  private:
815  const std::shared_ptr<Proto> proto_;
816 
818 };
819 
820 // Implements the Invoke(object_ptr, &Class::Method) action.
821 template <class Class, typename MethodPtr>
823  Class* const obj_ptr;
824  const MethodPtr method_ptr;
825 
826  template <typename... Args>
827  auto operator()(Args&&... args) const
828  -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
829  return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
830  }
831 };
832 
833 // Implements the InvokeWithoutArgs(f) action. The template argument
834 // FunctionImpl is the implementation type of f, which can be either a
835 // function pointer or a functor. InvokeWithoutArgs(f) can be used as an
836 // Action<F> as long as f's type is compatible with F.
837 template <typename FunctionImpl>
839  FunctionImpl function_impl;
840 
841  // Allows InvokeWithoutArgs(f) to be used as any action whose type is
842  // compatible with f.
843  template <typename... Args>
844  auto operator()(const Args&...) -> decltype(function_impl()) {
845  return function_impl();
846  }
847 };
848 
849 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
850 template <class Class, typename MethodPtr>
852  Class* const obj_ptr;
853  const MethodPtr method_ptr;
854 
855  using ReturnType = typename std::result_of<MethodPtr(Class*)>::type;
856 
857  template <typename... Args>
858  ReturnType operator()(const Args&...) const {
859  return (obj_ptr->*method_ptr)();
860  }
861 };
862 
863 // Implements the IgnoreResult(action) action.
864 template <typename A>
866  public:
867  explicit IgnoreResultAction(const A& action) : action_(action) {}
868 
869  template <typename F>
870  operator Action<F>() const {
871  // Assert statement belongs here because this is the best place to verify
872  // conditions on F. It produces the clearest error messages
873  // in most compilers.
874  // Impl really belongs in this scope as a local class but can't
875  // because MSVC produces duplicate symbols in different translation units
876  // in this case. Until MS fixes that bug we put Impl into the class scope
877  // and put the typedef both here (for use in assert statement) and
878  // in the Impl class. But both definitions must be the same.
879  typedef typename internal::Function<F>::Result Result;
880 
881  // Asserts at compile time that F returns void.
883 
884  return Action<F>(new Impl<F>(action_));
885  }
886 
887  private:
888  template <typename F>
889  class Impl : public ActionInterface<F> {
890  public:
893 
894  explicit Impl(const A& action) : action_(action) {}
895 
896  void Perform(const ArgumentTuple& args) override {
897  // Performs the action and ignores its result.
899  }
900 
901  private:
902  // Type OriginalFunction is the same as F except that its return
903  // type is IgnoredValue.
906 
908 
910  };
911 
912  const A action_;
913 
915 };
916 
917 template <typename InnerAction, size_t... I>
919  InnerAction action;
920 
921  // The inner action could be anything convertible to Action<X>.
922  // We use the conversion operator to detect the signature of the inner Action.
923  template <typename R, typename... Args>
924  operator Action<R(Args...)>() const { // NOLINT
925  Action<R(typename std::tuple_element<I, std::tuple<Args...>>::type...)>
926  converted(action);
927 
928  return [converted](Args... args) -> R {
929  return converted.Perform(std::forward_as_tuple(
930  std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
931  };
932  }
933 };
934 
935 template <typename... Actions>
936 struct DoAllAction {
937  private:
938  template <typename... Args, size_t... I>
939  std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const {
940  return {std::get<I>(actions)...};
941  }
942 
943  public:
944  std::tuple<Actions...> actions;
945 
946  template <typename R, typename... Args>
947  operator Action<R(Args...)>() const { // NOLINT
948  struct Op {
949  std::vector<Action<void(Args...)>> converted;
950  Action<R(Args...)> last;
951  R operator()(Args... args) const {
952  auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
953  for (auto& a : converted) {
954  a.Perform(tuple_args);
955  }
956  return last.Perform(tuple_args);
957  }
958  };
959  return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()),
960  std::get<sizeof...(Actions) - 1>(actions)};
961  }
962 };
963 
964 } // namespace internal
965 
966 // An Unused object can be implicitly constructed from ANY value.
967 // This is handy when defining actions that ignore some or all of the
968 // mock function arguments. For example, given
969 //
970 // MOCK_METHOD3(Foo, double(const string& label, double x, double y));
971 // MOCK_METHOD3(Bar, double(int index, double x, double y));
972 //
973 // instead of
974 //
975 // double DistanceToOriginWithLabel(const string& label, double x, double y) {
976 // return sqrt(x*x + y*y);
977 // }
978 // double DistanceToOriginWithIndex(int index, double x, double y) {
979 // return sqrt(x*x + y*y);
980 // }
981 // ...
982 // EXPECT_CALL(mock, Foo("abc", _, _))
983 // .WillOnce(Invoke(DistanceToOriginWithLabel));
984 // EXPECT_CALL(mock, Bar(5, _, _))
985 // .WillOnce(Invoke(DistanceToOriginWithIndex));
986 //
987 // you could write
988 //
989 // // We can declare any uninteresting argument as Unused.
990 // double DistanceToOrigin(Unused, double x, double y) {
991 // return sqrt(x*x + y*y);
992 // }
993 // ...
994 // EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
995 // EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
997 
998 // Creates an action that does actions a1, a2, ..., sequentially in
999 // each invocation.
1000 template <typename... Action>
1002  Action&&... action) {
1003  return {std::forward_as_tuple(std::forward<Action>(action)...)};
1004 }
1005 
1006 // WithArg<k>(an_action) creates an action that passes the k-th
1007 // (0-based) argument of the mock function to an_action and performs
1008 // it. It adapts an action accepting one argument to one that accepts
1009 // multiple arguments. For convenience, we also provide
1010 // WithArgs<k>(an_action) (defined below) as a synonym.
1011 template <size_t k, typename InnerAction>
1013 WithArg(InnerAction&& action) {
1014  return {std::forward<InnerAction>(action)};
1015 }
1016 
1017 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1018 // the selected arguments of the mock function to an_action and
1019 // performs it. It serves as an adaptor between actions with
1020 // different argument lists.
1021 template <size_t k, size_t... ks, typename InnerAction>
1023 WithArgs(InnerAction&& action) {
1024  return {std::forward<InnerAction>(action)};
1025 }
1026 
1027 // WithoutArgs(inner_action) can be used in a mock function with a
1028 // non-empty argument list to perform inner_action, which takes no
1029 // argument. In other words, it adapts an action accepting no
1030 // argument to one that accepts (and ignores) arguments.
1031 template <typename InnerAction>
1033 WithoutArgs(InnerAction&& action) {
1034  return {std::forward<InnerAction>(action)};
1035 }
1036 
1037 // Creates an action that returns 'value'. 'value' is passed by value
1038 // instead of const reference - otherwise Return("string literal")
1039 // will trigger a compiler error about using array as initializer.
1040 template <typename R>
1042  return internal::ReturnAction<R>(std::move(value));
1043 }
1044 
1045 // Creates an action that returns NULL.
1048 }
1049 
1050 // Creates an action that returns from a void function.
1053 }
1054 
1055 // Creates an action that returns the reference to a variable.
1056 template <typename R>
1059 }
1060 
1061 // Creates an action that returns the reference to a copy of the
1062 // argument. The copy is created when the action is constructed and
1063 // lives as long as the action.
1064 template <typename R>
1067 }
1068 
1069 // Modifies the parent action (a Return() action) to perform a move of the
1070 // argument instead of a copy.
1071 // Return(ByMove()) actions can only be executed once and will assert this
1072 // invariant.
1073 template <typename R>
1075  return internal::ByMoveWrapper<R>(std::move(x));
1076 }
1077 
1078 // Creates an action that does the default action for the give mock function.
1080  return internal::DoDefaultAction();
1081 }
1082 
1083 // Creates an action that sets the variable pointed by the N-th
1084 // (0-based) function argument to 'value'.
1085 template <size_t N, typename T>
1086 PolymorphicAction<
1087  internal::SetArgumentPointeeAction<
1089 SetArgPointee(const T& x) {
1092 }
1093 
1094 template <size_t N>
1095 PolymorphicAction<
1096  internal::SetArgumentPointeeAction<N, const char*, false> >
1097 SetArgPointee(const char* p) {
1099  N, const char*, false>(p));
1100 }
1101 
1102 template <size_t N>
1103 PolymorphicAction<
1104  internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
1105 SetArgPointee(const wchar_t* p) {
1107  N, const wchar_t*, false>(p));
1108 }
1109 
1110 // The following version is DEPRECATED.
1111 template <size_t N, typename T>
1112 PolymorphicAction<
1113  internal::SetArgumentPointeeAction<
1118 }
1119 
1120 // Creates an action that sets a pointer referent to a given value.
1121 template <typename T1, typename T2>
1124 }
1125 
1126 #if !GTEST_OS_WINDOWS_MOBILE
1127 
1128 // Creates an action that sets errno and returns the appropriate error.
1129 template <typename T>
1130 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
1131 SetErrnoAndReturn(int errval, T result) {
1132  return MakePolymorphicAction(
1133  internal::SetErrnoAndReturnAction<T>(errval, result));
1134 }
1135 
1136 #endif // !GTEST_OS_WINDOWS_MOBILE
1137 
1138 // Various overloads for Invoke().
1139 
1140 // Legacy function.
1141 // Actions can now be implicitly constructed from callables. No need to create
1142 // wrapper objects.
1143 // This function exists for backwards compatibility.
1144 template <typename FunctionImpl>
1145 typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
1146  return std::forward<FunctionImpl>(function_impl);
1147 }
1148 
1149 // Creates an action that invokes the given method on the given object
1150 // with the mock function's arguments.
1151 template <class Class, typename MethodPtr>
1153  MethodPtr method_ptr) {
1154  return {obj_ptr, method_ptr};
1155 }
1156 
1157 // Creates an action that invokes 'function_impl' with no argument.
1158 template <typename FunctionImpl>
1160 InvokeWithoutArgs(FunctionImpl function_impl) {
1161  return {std::move(function_impl)};
1162 }
1163 
1164 // Creates an action that invokes the given method on the given object
1165 // with no argument.
1166 template <class Class, typename MethodPtr>
1168  Class* obj_ptr, MethodPtr method_ptr) {
1169  return {obj_ptr, method_ptr};
1170 }
1171 
1172 // Creates an action that performs an_action and throws away its
1173 // result. In other words, it changes the return type of an_action to
1174 // void. an_action MUST NOT return void, or the code won't compile.
1175 template <typename A>
1177  return internal::IgnoreResultAction<A>(an_action);
1178 }
1179 
1180 // Creates a reference wrapper for the given L-value. If necessary,
1181 // you can explicitly specify the type of the reference. For example,
1182 // suppose 'derived' is an object of type Derived, ByRef(derived)
1183 // would wrap a Derived&. If you want to wrap a const Base& instead,
1184 // where Base is a base class of Derived, just write:
1185 //
1186 // ByRef<const Base>(derived)
1187 //
1188 // N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper.
1189 // However, it may still be used for consistency with ByMove().
1190 template <typename T>
1191 inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT
1192  return ::std::reference_wrapper<T>(l_value);
1193 }
1194 
1195 } // namespace testing
1196 
1197 #ifdef _MSC_VER
1198 # pragma warning(pop)
1199 #endif
1200 
1201 
1202 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
testing::internal::DoDefaultAction
Definition: gmock-actions.h:722
testing::internal::ReturnAction::Impl::Perform
Result Perform(const ArgumentTuple &) override
Definition: gmock-actions.h:564
testing::internal::ReturnAction::Impl::ArgumentTuple
Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:551
testing::internal::Int64
TypeWithSize< 8 >::Int Int64
Definition: gtest-port.h:2243
testing::internal::ReturnRefAction::Impl::ArgumentTuple
Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:657
testing::DefaultValue< T & >::Set
static void Set(T &x)
Definition: gmock-actions.h:268
testing
Definition: gmock-actions.h:59
forward
static int forward(class zmq::socket_base_t *from_, class zmq::socket_base_t *to_, class zmq::socket_base_t *capture_, zmq::msg_t *msg_, stats_socket &recving, stats_socket &sending)
Definition: proxy.cpp:89
testing::DefaultValue::FixedValueProducer::value_
const T value_
Definition: gmock-actions.h:244
testing::internal::SetErrnoAndReturnAction::result_
const T result_
Definition: gmock-actions.h:767
testing::internal::ReturnAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(ReturnAction)
testing::internal::IgnoreResultAction::Impl::ArgumentTuple
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:892
testing::DefaultValue::FixedValueProducer::Produce
T Produce() override
Definition: gmock-actions.h:241
testing::ActionInterface::GTEST_DISALLOW_COPY_AND_ASSIGN_
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface)
testing::internal::IllegalDoDefault
GTEST_API_ void IllegalDoDefault(const char *file, int line)
Definition: gmock-internal-utils.cc:189
testing::internal::SetArgumentPointeeAction
Definition: gmock-actions.h:779
testing::internal::CompileAssertTypesEqual
Definition: gtest-internal.h:879
benchmarks.python.py_benchmark.const
const
Definition: py_benchmark.py:14
testing::internal::AssignAction::value_
const T2 value_
Definition: gmock-actions.h:744
testing::DefaultValue::FactoryValueProducer
Definition: gmock-actions.h:248
testing::internal::IgnoreResultAction::Impl::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(Impl)
testing::internal::ReturnVoidAction::Perform
static void Perform(const ArgumentTuple &)
Definition: gmock-actions.h:624
testing::internal::IgnoreResultAction::Impl::OriginalFunction
internal::Function< F >::MakeResultIgnoredValue OriginalFunction
Definition: gmock-actions.h:905
testing::internal::ReturnAction
Definition: gmock-actions.h:517
testing::DefaultValue< T & >::Exists
static bool Exists()
Definition: gmock-actions.h:280
testing::internal::AssignAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(AssignAction)
testing::DefaultValue::Set
static void Set(T x)
Definition: gmock-actions.h:194
testing::PolymorphicAction::MonomorphicImpl::ArgumentTuple
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:441
testing::internal::ReturnRefOfCopyAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction)
testing::DoAll
internal::DoAllAction< typename std::decay< Action >::type... > DoAll(Action &&... action)
Definition: gmock-actions.h:1001
testing::DefaultValue
Definition: gmock-actions.h:190
testing::Action::Action
Action(G &&fun)
Definition: gmock-actions.h:369
gmock-internal-utils.h
testing::DefaultValue< void >::Get
static void Get()
Definition: gmock-actions.h:302
testing::PolymorphicAction::PolymorphicAction
PolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:429
testing::DefaultValue::FactoryValueProducer::GTEST_DISALLOW_COPY_AND_ASSIGN_
GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer)
testing::MakeAction
Action< F > MakeAction(ActionInterface< F > *impl)
Definition: gmock-actions.h:463
testing::internal::ReturnVoidAction
Definition: gmock-actions.h:620
testing::internal::ReturnRefOfCopyAction::Impl::Result
Function< F >::Result Result
Definition: gmock-actions.h:703
testing::PolymorphicAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(PolymorphicAction)
testing::DefaultValue::FactoryFunction
T(* FactoryFunction)()
Definition: gmock-actions.h:202
testing::internal::ReturnNullAction
Definition: gmock-actions.h:608
testing::internal::ReturnRefAction::Impl::Perform
Result Perform(const ArgumentTuple &) override
Definition: gmock-actions.h:661
testing::internal::IgnoreResultAction::Impl
Definition: gmock-actions.h:889
testing::Assign
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
Definition: gmock-actions.h:1122
testing::internal::ReturnRefAction::Impl::Result
Function< F >::Result Result
Definition: gmock-actions.h:656
testing::internal::IgnoreResultAction::Impl::Impl
Impl(const A &action)
Definition: gmock-actions.h:894
testing::PolymorphicAction
Definition: gmock-actions.h:427
testing::PolymorphicAction::MonomorphicImpl::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(MonomorphicImpl)
testing::internal::BuiltInDefaultValue< T * >::Exists
static bool Exists()
Definition: gmock-actions.h:127
testing::internal::bool_constant< std::is_convertible< const T *, const ::ProtocolMessage * >::value||std::is_convertible< const T *, const ::proto2::Message * >::value >::value
static const bool value
Definition: gtest-port.h:1952
testing::PolymorphicAction::impl_
Impl impl_
Definition: gmock-actions.h:455
testing::internal::Apply
auto Apply(F &&f, Tuple &&args) -> decltype(ApplyImpl(std::forward< F >(f), std::forward< Tuple >(args), make_int_pack< std::tuple_size< Tuple >::value >()))
Definition: gmock-internal-utils.h:525
testing::PolymorphicAction::MonomorphicImpl
Definition: gmock-actions.h:438
testing::DefaultValue::SetFactory
static void SetFactory(FactoryFunction factory)
Definition: gmock-actions.h:203
testing::MakePolymorphicAction
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:475
testing::internal::SetErrnoAndReturnAction::SetErrnoAndReturnAction
SetErrnoAndReturnAction(int errno_value, T result)
Definition: gmock-actions.h:756
testing::PolymorphicAction::MonomorphicImpl::Result
internal::Function< F >::Result Result
Definition: gmock-actions.h:440
testing::internal::InvokeMethodWithoutArgsAction
Definition: gmock-actions.h:851
testing::Action::ActionAdapter::impl_
::std::shared_ptr< ActionInterface< F > > impl_
Definition: gmock-actions.h:346
testing::internal::ReturnRefOfCopyAction::Impl::ArgumentTuple
Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:704
testing::internal::Function
Definition: gmock-internal-utils.h:546
testing::DefaultValue< T & >::IsSet
static bool IsSet()
Definition: gmock-actions.h:276
testing::internal::ReturnRefOfCopyAction::Impl::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(Impl)
testing::ReturnNull
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
Definition: gmock-actions.h:1046
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
testing::ByRef
inline ::std::reference_wrapper< T > ByRef(T &l_value)
Definition: gmock-actions.h:1191
GTEST_COMPILE_ASSERT_
#define GTEST_COMPILE_ASSERT_(expr, msg)
Definition: gtest-port.h:852
errno
int errno
testing::InvokeWithoutArgs
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
Definition: gmock-actions.h:1160
testing::internal::ReturnAction::Impl::GTEST_COMPILE_ASSERT_
GTEST_COMPILE_ASSERT_(!is_reference< Result >::value, Result_cannot_be_a_reference_type)
testing::DefaultValue::ValueProducer
Definition: gmock-actions.h:232
testing::internal::ReturnRefOfCopyAction::Impl::Impl
Impl(const T &value)
Definition: gmock-actions.h:706
testing::internal::DoAllAction::actions
std::tuple< Actions... > actions
Definition: gmock-actions.h:944
testing::internal::WithArgsAction
Definition: gmock-actions.h:918
testing::internal::BuiltInDefaultValueGetter< T, false >::Get
static T Get()
Definition: gmock-actions.h:83
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::wrapper_
const std::shared_ptr< R > wrapper_
Definition: gmock-actions.h:597
x
GLint GLenum GLint x
Definition: glcorearb.h:2834
testing::internal::ByMoveWrapper::payload
T payload
Definition: gmock-actions.h:486
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::Impl
Impl(const std::shared_ptr< R > &wrapper)
Definition: gmock-actions.h:585
T
#define T(upbtypeconst, upbtype, ctype, default_value)
testing::internal::ReturnRefAction::Impl::Impl
Impl(T &ref)
Definition: gmock-actions.h:659
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::ArgumentTuple
Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:583
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::Perform
Result Perform(const ArgumentTuple &) override
Definition: gmock-actions.h:588
testing::internal::InvokeMethodWithoutArgsAction::operator()
ReturnType operator()(const Args &...) const
Definition: gmock-actions.h:858
testing::WithArgs
internal::WithArgsAction< typename std::decay< InnerAction >::type, k, ks... > WithArgs(InnerAction &&action)
Definition: gmock-actions.h:1023
testing::internal::IndexSequence
Definition: gtest-internal.h:1181
testing::internal::ReturnAction::value_
const std::shared_ptr< R > value_
Definition: gmock-actions.h:602
testing::internal::BuiltInDefaultValue::Exists
static bool Exists()
Definition: gmock-actions.h:103
testing::internal::SetArgumentPointeeAction::Perform
void Perform(const ArgumentTuple &args) const
Definition: gmock-actions.h:786
testing::SetErrnoAndReturn
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
Definition: gmock-actions.h:1131
testing::internal::ReturnRefAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(ReturnRefAction)
testing::internal::IgnoreResultAction
Definition: gmock-actions.h:865
testing::internal::IgnoreResultAction::Impl::Result
internal::Function< F >::Result Result
Definition: gmock-actions.h:891
testing::internal::BuiltInDefaultValueGetter::Get
static T Get()
Definition: gmock-actions.h:79
testing::DefaultValue::FactoryValueProducer::FactoryValueProducer
FactoryValueProducer(FactoryFunction factory)
Definition: gmock-actions.h:250
testing::WithoutArgs
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
Definition: gmock-actions.h:1033
testing::internal::ReturnRefOfCopyAction::Impl::Perform
Result Perform(const ArgumentTuple &) override
Definition: gmock-actions.h:708
testing::Action::Action
Action(const Action< Func > &action)
Definition: gmock-actions.h:379
testing::Invoke
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
Definition: gmock-actions.h:1145
testing::internal::BuiltInDefaultValue< const T >::Exists
static bool Exists()
Definition: gmock-actions.h:118
testing::DefaultValue::ValueProducer::Produce
virtual T Produce()=0
testing::internal::ReturnRefOfCopyAction::value_
const T value_
Definition: gmock-actions.h:716
testing::internal::SetArgumentPointeeAction< N, Proto, true >::SetArgumentPointeeAction
SetArgumentPointeeAction(const Proto &proto)
Definition: gmock-actions.h:804
testing::DefaultValue< T & >::Clear
static void Clear()
Definition: gmock-actions.h:273
testing::internal::ReturnRefOfCopyAction
Definition: gmock-actions.h:678
testing::internal::InvokeMethodWithoutArgsAction::method_ptr
const MethodPtr method_ptr
Definition: gmock-actions.h:853
benchmarks.python.py_benchmark.action
action
Definition: py_benchmark.py:13
GTEST_CHECK_
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1036
testing::internal::SetArgumentPointeeAction::value_
const A value_
Definition: gmock-actions.h:792
A
Definition: logging_striptest_main.cc:56
testing::internal::IgnoreResultAction::action_
const A action_
Definition: gmock-actions.h:912
testing::DefaultValue::Exists
static bool Exists()
Definition: gmock-actions.h:219
testing::internal::ReturnRefOfCopyAction::ReturnRefOfCopyAction
ReturnRefOfCopyAction(const T &value)
Definition: gmock-actions.h:682
testing::DefaultValue::FixedValueProducer
Definition: gmock-actions.h:238
gmock-port.h
testing::internal::MakeIndexSequence
Definition: gtest-internal.h:1200
testing::internal::BuiltInDefaultValue< T * >::Get
static T * Get()
Definition: gmock-actions.h:128
testing::internal::ByMoveWrapper::ByMoveWrapper
ByMoveWrapper(T value)
Definition: gmock-actions.h:485
testing::DefaultValue::ValueProducer::~ValueProducer
virtual ~ValueProducer()
Definition: gmock-actions.h:234
testing::internal::ReturnRefAction::Impl::ref_
T & ref_
Definition: gmock-actions.h:664
testing::Action::ArgumentTuple
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:357
testing::internal::GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void,)
testing::ReturnRefOfCopy
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
Definition: gmock-actions.h:1065
p
const char * p
Definition: gmock-matchers_test.cc:3863
testing::Action::Action
Action(ActionInterface< F > *impl)
Definition: gmock-actions.h:372
testing::internal::ReturnNullAction::Perform
static Result Perform(const ArgumentTuple &)
Definition: gmock-actions.h:614
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::Result
Function< F >::Result Result
Definition: gmock-actions.h:582
testing::internal::BuiltInDefaultValue
Definition: gmock-actions.h:100
testing::DefaultValue::IsSet
static bool IsSet()
Definition: gmock-actions.h:215
testing::internal::InvokeMethodWithoutArgsAction::obj_ptr
Class *const obj_ptr
Definition: gmock-actions.h:852
testing::internal::AssignAction::Perform
void Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:738
testing::DefaultValue::FactoryValueProducer::Produce
T Produce() override
Definition: gmock-actions.h:252
testing::internal::BuiltInDefaultValue< const T >::Get
static T Get()
Definition: gmock-actions.h:119
testing::internal::SetErrnoAndReturnAction::errno_
const int errno_
Definition: gmock-actions.h:766
testing::ReturnRef
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition: gmock-actions.h:1057
testing::internal::DoAllAction::Convert
std::vector< Action< void(Args...)> > Convert(IndexSequence< I... >) const
Definition: gmock-actions.h:939
testing::Action
Definition: gmock-actions.h:341
testing::internal::ReturnAction::Impl::value_
Result value_
Definition: gmock-actions.h:572
testing::internal::ReturnAction::Impl::Result
Function< F >::Result Result
Definition: gmock-actions.h:550
F
#define F(msg, field)
Definition: ruby/ext/google/protobuf_c/upb.c:9347
testing::SetArgumentPointee
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgumentPointee(const T &x)
Definition: gmock-actions.h:1115
testing::ActionInterface::~ActionInterface
virtual ~ActionInterface()
Definition: gmock-actions.h:321
testing::internal::InvokeWithoutArgsAction::function_impl
FunctionImpl function_impl
Definition: gmock-actions.h:839
testing::internal::ReturnRefAction::Impl::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(Impl)
testing::internal::IgnoreResultAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(IgnoreResultAction)
testing::internal::InvokeWithoutArgsAction
Definition: gmock-actions.h:838
testing::internal::ReturnAction::ReturnAction
ReturnAction(R value)
Definition: gmock-actions.h:522
testing::PolymorphicAction::MonomorphicImpl::impl_
Impl impl_
Definition: gmock-actions.h:450
testing::internal::is_reference
Definition: gmock-internal-utils.h:356
testing::internal::ReturnRefAction::ReturnRefAction
ReturnRefAction(T &ref)
Definition: gmock-actions.h:636
testing::internal::WithArgsAction::action
InnerAction action
Definition: gmock-actions.h:919
testing::internal::SetArgumentPointeeAction::SetArgumentPointeeAction
SetArgumentPointeeAction(const A &value)
Definition: gmock-actions.h:783
testing::internal::AssignAction::ptr_
T1 *const ptr_
Definition: gmock-actions.h:743
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
testing::internal::ReturnAction::Impl< ByMoveWrapper< R_ >, F >::performed_
bool performed_
Definition: gmock-actions.h:596
testing::ActionInterface::Result
internal::Function< F >::Result Result
Definition: gmock-actions.h:317
testing::internal::UInt64
TypeWithSize< 8 >::UInt UInt64
Definition: gtest-port.h:2244
testing::WithArg
internal::WithArgsAction< typename std::decay< InnerAction >::type, k > WithArg(InnerAction &&action)
Definition: gmock-actions.h:1013
testing::internal::SetArgumentPointeeAction< N, Proto, true >::Perform
void Perform(const ArgumentTuple &args) const
Definition: gmock-actions.h:809
testing::internal::AssignAction::AssignAction
AssignAction(T1 *ptr, T2 value)
Definition: gmock-actions.h:735
testing::Action::fun_
::std::function< F > fun_
Definition: gmock-actions.h:402
type
GLenum type
Definition: glcorearb.h:2695
testing::Action::IsDoDefault
bool IsDoDefault() const
Definition: gmock-actions.h:382
testing::DefaultValue::FixedValueProducer::FixedValueProducer
FixedValueProducer(T value)
Definition: gmock-actions.h:240
testing::internal::InvokeMethodAction::obj_ptr
Class *const obj_ptr
Definition: gmock-actions.h:823
testing::ActionInterface::ArgumentTuple
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:318
testing::ActionInterface::Perform
virtual Result Perform(const ArgumentTuple &args)=0
testing::internal::Assert
void Assert(bool condition, const char *file, int line)
Definition: gmock-internal-utils.h:292
testing::internal::ReturnAction::Impl::Impl
Impl(const std::shared_ptr< R > &value)
Definition: gmock-actions.h:560
testing::SetArgPointee
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
Definition: gmock-actions.h:1089
testing::internal::IsAProtocolMessage
Definition: gtest-internal.h:927
testing::internal::ReturnRefAction::ref_
T & ref_
Definition: gmock-actions.h:669
Args
Args({7, 6, 3})
testing::DefaultValue::FactoryValueProducer::factory_
const FactoryFunction factory_
Definition: gmock-actions.h:255
testing::internal::InvokeMethodAction::operator()
auto operator()(Args &&... args) const -> decltype((obj_ptr-> *method_ptr)(std::forward< Args >(args)...))
Definition: gmock-actions.h:827
testing::internal::IgnoreResultAction::Impl::action_
const Action< OriginalFunction > action_
Definition: gmock-actions.h:907
testing::internal::IgnoreResultAction::Impl::Perform
void Perform(const ArgumentTuple &args) override
Definition: gmock-actions.h:896
std
testing::DefaultValue< void >::Exists
static bool Exists()
Definition: gmock-actions.h:301
testing::internal::DoAllAction
Definition: gmock-actions.h:936
testing::internal::IgnoreResultAction::IgnoreResultAction
IgnoreResultAction(const A &action)
Definition: gmock-actions.h:867
testing::DefaultValue::producer_
static ValueProducer * producer_
Definition: gmock-actions.h:259
testing::Action::Action
Action()
Definition: gmock-actions.h:361
testing::Action::Perform
Result Perform(ArgumentTuple args) const
Definition: gmock-actions.h:390
testing::DefaultValue::FixedValueProducer::GTEST_DISALLOW_COPY_AND_ASSIGN_
GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer)
testing::internal::SetArgumentPointeeAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction)
testing::internal::ReturnRefAction::Impl
Definition: gmock-actions.h:654
testing::internal::IgnoredValue
Definition: gtest-internal.h:111
testing::internal::SetErrnoAndReturnAction::Perform
Result Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:760
testing::internal::ReturnRefOfCopyAction::Impl::value_
T value_
Definition: gmock-actions.h:711
testing::Action::ActionAdapter::operator()
internal::Function< F >::Result operator()(Args &&... args)
Definition: gmock-actions.h:349
true
#define true
Definition: cJSON.c:65
internal
Definition: any.pb.h:40
testing::Return
internal::ReturnAction< R > Return(R value)
Definition: gmock-actions.h:1041
val
GLuint GLfloat * val
Definition: glcorearb.h:3604
testing::DefaultValue::Clear
static void Clear()
Definition: gmock-actions.h:209
testing::internal::BuiltInDefaultValue::Get
static T Get()
Definition: gmock-actions.h:107
testing::Action::ActionAdapter
Definition: gmock-actions.h:344
testing::internal::InvokeWithoutArgsAction::operator()
auto operator()(const Args &...) -> decltype(function_impl())
Definition: gmock-actions.h:844
testing::internal::ImplicitCast_
To ImplicitCast_(To x)
Definition: gtest-port.h:1108
testing::DoDefault
internal::DoDefaultAction DoDefault()
Definition: gmock-actions.h:1079
testing::internal::ReturnAction::Impl::GTEST_DISALLOW_COPY_AND_ASSIGN_
GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl)
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
testing::DefaultValue< T & >::Get
static T & Get()
Definition: gmock-actions.h:287
testing::internal::ReturnRefAction
Definition: gmock-actions.h:633
testing::internal::SetErrnoAndReturnAction::GTEST_DISALLOW_ASSIGN_
GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction)
testing::internal::SetErrnoAndReturnAction
Definition: gmock-actions.h:754
testing::IgnoreResult
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
Definition: gmock-actions.h:1176
false
#define false
Definition: cJSON.c:70
ref
GLint ref
Definition: glcorearb.h:2789
testing::internal::InvokeMethodWithoutArgsAction::ReturnType
typename std::result_of< MethodPtr(Class *)>::type ReturnType
Definition: gmock-actions.h:855
testing::internal::AssignAction
Definition: gmock-actions.h:733
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:3228
testing::PolymorphicAction::MonomorphicImpl::MonomorphicImpl
MonomorphicImpl(const Impl &impl)
Definition: gmock-actions.h:443
testing::DefaultValue::Get
static T Get()
Definition: gmock-actions.h:226
testing::Unused
internal::IgnoredValue Unused
Definition: gmock-actions.h:996
testing::internal::ByMoveWrapper
Definition: gmock-actions.h:484
testing::ByMove
internal::ByMoveWrapper< R > ByMove(R x)
Definition: gmock-actions.h:1074
testing::internal::ReturnAction::Impl
Definition: gmock-actions.h:548
testing::internal::BuiltInDefaultValueGetter
Definition: gmock-actions.h:78
testing::internal::ReturnAction::Impl::value_before_cast_
R value_before_cast_
Definition: gmock-actions.h:571
testing::ActionInterface
Definition: gmock-actions.h:315
testing::Action::Result
internal::Function< F >::Result Result
Definition: gmock-actions.h:356
testing::DefaultValue< T & >::address_
static T * address_
Definition: gmock-actions.h:293
testing::internal::InvokeMethodAction
Definition: gmock-actions.h:822
benchmarks.python.py_benchmark.args
args
Definition: py_benchmark.py:24
testing::ActionInterface::ActionInterface
ActionInterface()
Definition: gmock-actions.h:320
testing::internal::ReturnRefOfCopyAction::Impl
Definition: gmock-actions.h:701
testing::PolymorphicAction::MonomorphicImpl::Perform
Result Perform(const ArgumentTuple &args) override
Definition: gmock-actions.h:445
testing::internal::SetArgumentPointeeAction< N, Proto, true >::proto_
const std::shared_ptr< Proto > proto_
Definition: gmock-actions.h:815
testing::internal::InvokeMethodAction::method_ptr
const MethodPtr method_ptr
Definition: gmock-actions.h:824


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:52