36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 37 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 49 #if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h. 50 #include <type_traits> 66 template <
typename F1,
typename F2>
74 template <
typename T,
bool kDefaultConstructible>
76 static T
Get() {
return T(); }
81 Assert(
false, __FILE__, __LINE__,
82 "Default action undefined for the function return type.");
83 return internal::Invalid<T>();
99 #if GTEST_HAS_STD_TYPE_TRAITS_ 101 static bool Exists() {
102 return ::std::is_default_constructible<T>::value;
107 T, ::std::is_default_constructible<T>::value>
::Get();
110 #else // GTEST_HAS_STD_TYPE_TRAITS_ 120 #endif // GTEST_HAS_STD_TYPE_TRAITS_ 125 template <
typename T>
134 template <
typename T>
138 static T*
Get() {
return NULL; }
143 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 145 class BuiltInDefaultValue<type> { \ 147 static bool Exists() { return true; } \ 148 static type Get() { return value; } \ 152 #if GTEST_HAS_GLOBAL_STRING 154 #endif // GTEST_HAS_GLOBAL_STRING 167 #if GMOCK_WCHAR_T_IS_NATIVE_ 182 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 199 template <
typename T>
206 producer_ =
new FixedValueProducer(x);
212 typedef T (*FactoryFunction)();
215 producer_ =
new FactoryValueProducer(factory);
225 static bool IsSet() {
return producer_ != NULL; }
237 return producer_ == NULL ?
242 class ValueProducer {
244 virtual ~ValueProducer() {}
245 virtual T Produce() = 0;
248 class FixedValueProducer :
public ValueProducer {
250 explicit FixedValueProducer(T value) : value_(value) {}
251 virtual T Produce() {
return value_; }
258 class FactoryValueProducer :
public ValueProducer {
260 explicit FactoryValueProducer(FactoryFunction factory)
261 : factory_(factory) {}
262 virtual T Produce() {
return factory_(); }
265 const FactoryFunction factory_;
269 static ValueProducer* producer_;
274 template <
typename T>
288 static bool IsSet() {
return address_ != NULL; }
300 return address_ == NULL ?
318 template <
typename T>
322 template <
typename T>
326 template <
typename F>
339 virtual Result Perform(
const ArgumentTuple&
args) = 0;
354 template <
typename F>
375 template <
typename Func>
389 !IsDoDefault(), __FILE__, __LINE__,
390 "You are using DoDefault() inside a composite action like " 391 "DoAll() or WithArgs(). This is not supported for technical " 392 "reasons. Please instead spell out the default action, or " 393 "assign the default action to an Action variable and use " 394 "the variable in various places.");
395 return impl_->Perform(args);
399 template <
typename F1,
typename F2>
426 template <
typename Impl>
431 template <
typename F>
433 return Action<F>(
new MonomorphicImpl<F>(impl_));
437 template <
typename F>
443 explicit MonomorphicImpl(
const Impl& impl) : impl_(impl) {}
445 virtual Result Perform(
const ArgumentTuple&
args) {
446 return impl_.template Perform<Result>(
args);
462 template <
typename F>
474 template <
typename Impl>
483 template <
typename F1,
typename F2>
492 return impl_->Perform(args);
503 template <
typename T>
533 template <
typename R>
543 template <
typename F>
556 use_ReturnRef_instead_of_Return_to_return_a_reference);
557 return Action<F>(
new Impl<R, F>(value_));
562 template <
typename R_,
typename F>
576 : value_before_cast_(*value),
577 value_(ImplicitCast_<Result>(value_before_cast_)) {}
579 virtual Result Perform(
const ArgumentTuple&) {
return value_; }
583 Result_cannot_be_a_reference_type);
586 R value_before_cast_;
594 template <
typename R_,
typename F>
601 : performed_(
false), wrapper_(wrapper) {}
603 virtual Result Perform(
const ArgumentTuple&) {
605 <<
"A ByMove() action should only be performed once.";
628 template <
typename Result,
typename ArgumentTuple>
634 ReturnNull_can_be_used_to_return_a_pointer_only);
636 #endif // GTEST_LANG_CXX11 644 template <
typename Result,
typename ArgumentTuple>
653 template <
typename T>
661 template <
typename F>
668 use_Return_instead_of_ReturnRef_to_return_a_value);
674 template <
typename F>
680 explicit Impl(T& ref) : ref_(ref) {}
682 virtual Result Perform(
const ArgumentTuple&) {
700 template <
typename T>
709 template <
typename F>
717 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
723 template <
typename F>
729 explicit Impl(
const T& value) : value_(value) {}
731 virtual Result Perform(
const ArgumentTuple&) {
751 template <
typename F>
757 template <
typename T1,
typename T2>
762 template <
typename Result,
typename ArgumentTuple>
774 #if !GTEST_OS_WINDOWS_MOBILE 778 template <
typename T>
782 : errno_(errno_value),
784 template <
typename Result,
typename ArgumentTuple>
797 #endif // !GTEST_OS_WINDOWS_MOBILE 803 template <
size_t N,
typename A,
bool kIsProto>
810 template <
typename Result,
typename ArgumentTuple>
813 *::testing::get<N>(
args) = value_;
822 template <
size_t N,
typename Proto>
830 proto_->CopyFrom(proto);
833 template <
typename Result,
typename ArgumentTuple>
836 ::testing::get<N>(
args)->CopyFrom(*proto_);
850 template <
typename FunctionImpl>
856 : function_impl_(function_impl) {}
860 template <
typename Result,
typename ArgumentTuple>
861 Result
Perform(
const ArgumentTuple&) {
return function_impl_(); }
864 FunctionImpl function_impl_;
870 template <
class Class,
typename MethodPtr>
874 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
876 template <
typename Result,
typename ArgumentTuple>
878 return (obj_ptr_->*method_ptr_)();
882 Class*
const obj_ptr_;
883 const MethodPtr method_ptr_;
889 template <
typename A>
894 template <
typename F>
913 template <
typename F>
919 explicit Impl(
const A&
action) : action_(action) {}
921 virtual void Perform(
const ArgumentTuple&
args) {
923 action_.Perform(args);
949 template <
typename T>
957 operator T&()
const {
return *pointer_; }
963 template <
typename T>
971 template <
typename Action1,
typename Action2>
975 : action1_(action1), action2_(action2) {}
979 template <
typename F>
981 return Action<F>(
new Impl<F>(action1_, action2_));
986 template <
typename F>
994 : action1_(action1), action2_(action2) {}
996 virtual Result Perform(
const ArgumentTuple&
args) {
997 action1_.Perform(args);
998 return action2_.Perform(args);
1052 template <
typename To>
1053 template <
typename From>
1055 : impl_(new internal::ActionAdaptor<To, From>(from)) {}
1060 template <
typename R>
1076 template <
typename R>
1084 template <
typename R>
1093 template <
typename R>
1105 template <
size_t N,
typename T>
1114 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) 1123 N,
const char*,
false>(p));
1131 N,
const wchar_t*,
false>(p));
1136 template <
size_t N,
typename T>
1146 template <
typename T1,
typename T2>
1151 #if !GTEST_OS_WINDOWS_MOBILE 1154 template <
typename T>
1161 #endif // !GTEST_OS_WINDOWS_MOBILE 1166 template <
typename FunctionImpl>
1175 template <
class Class,
typename MethodPtr>
1180 obj_ptr, method_ptr));
1186 template <
typename A>
1198 template <
typename T>
1205 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ Definition: gmock-actions.h:890
def args
Definition: android_test.py:111
static bool Exists()
Definition: gmock-actions.h:229
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
Definition: gmock-actions.h:1066
Definition: gmock-actions.h:53
Result Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:785
internal::IgnoredValue Unused
Definition: gmock-actions.h:1046
static void Get()
Definition: gmock-actions.h:314
Definition: gtest-internal.h:772
ActionAdaptor(const Action< F2 > &from)
Definition: gmock-actions.h:489
T payload
Definition: gmock-actions.h:506
Definition: gmock-actions.h:747
static bool IsSet()
Definition: gmock-actions.h:288
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
Definition: gmock-actions.h:1147
Definition: gmock-actions.h:200
Action
Error action.
Definition: ErrorCallbackInterface.h:50
PolymorphicAction< internal::SetArgumentPointeeAction< N, const wchar_t *, false > > SetArgPointee(const wchar_t *p)
Definition: gmock-actions.h:1129
Definition: gmock-actions.h:623
Action(ActionInterface< F > *impl)
Definition: gmock-actions.h:366
Definition: gmock-actions.h:355
::std::string string
Definition: gtest-port.h:1097
void Perform(const ArgumentTuple &args) const
Definition: gmock-actions.h:811
Definition: gmock-actions.h:654
internal::Function< F >::Result Result
Definition: gmock-actions.h:357
Definition: gtest-port.h:2213
Definition: gmock-actions.h:758
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:330
DoBothAction(Action1 action1, Action2 action2)
Definition: gmock-actions.h:974
SetErrnoAndReturnAction(int errno_value, T result)
Definition: gmock-actions.h:781
Definition: gmock-actions.h:504
SetArgumentPointeeAction(const Proto &proto)
Definition: gmock-actions.h:829
static void Perform(const ArgumentTuple &)
Definition: gmock-actions.h:645
static void Set(T &x)
Definition: gmock-actions.h:278
static T * Get()
Definition: gmock-actions.h:138
PolymorphicAction< internal::InvokeMethodWithoutArgsAction< Class, MethodPtr > > InvokeWithoutArgs(Class *obj_ptr, MethodPtr method_ptr)
Definition: gmock-actions.h:1177
Definition: gmock-actions.h:972
static T Get()
Definition: gmock-actions.h:129
internal::Function< F1 >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:487
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:358
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:475
#define GTEST_DISALLOW_ASSIGN_(type)
Definition: gtest-port.h:869
IgnoreResultAction(const A &action)
Definition: gmock-actions.h:892
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
Definition: gmock-actions.h:1156
static bool Exists()
Definition: gmock-actions.h:313
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition: gmock-actions.h:1077
Definition: gmock-actions.h:779
static void Set(T x)
Definition: gmock-actions.h:204
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgumentPointee(const T &x)
Definition: gmock-actions.h:1140
ByMoveWrapper(T value)
Definition: gmock-actions.h:505
Action()
Definition: gmock-actions.h:362
static void Print(const T &value, ::std::ostream *os)
Definition: gtest-printers.h:698
#define GTEST_COMPILE_ASSERT_(expr, msg)
Definition: gtest-port.h:1032
static T & Get()
Definition: gmock-actions.h:299
static bool IsSet()
Definition: gmock-actions.h:225
Definition: gtest-linked_ptr.h:146
InvokeWithoutArgsAction(FunctionImpl function_impl)
Definition: gmock-actions.h:855
virtual Result Perform(const ArgumentTuple &args)
Definition: gmock-actions.h:491
static bool Exists()
Definition: gmock-actions.h:128
Definition: gmock-actions.h:97
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1295
Definition: gmock-actions.h:67
static void Clear()
Definition: gmock-actions.h:283
internal::Function< F1 >::Result Result
Definition: gmock-actions.h:486
PolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:429
Action(const Action &action)
Definition: gmock-actions.h:369
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
Definition: gmock-actions.h:1085
internal::ReferenceWrapper< T > ByRef(T &l_value)
Definition: gmock-actions.h:1199
static void Clear()
Definition: gmock-actions.h:219
Definition: gmock-actions.h:851
static T Get()
Definition: gmock-actions.h:76
Result Perform(const ArgumentTuple &)
Definition: gmock-actions.h:861
static bool Exists()
Definition: gmock-actions.h:292
Definition: gmock-actions.h:701
virtual ~ActionInterface()
Definition: gmock-actions.h:333
Definition: gmock-internal-utils.h:340
SetArgumentPointeeAction(const A &value)
Definition: gmock-actions.h:808
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void,)
Definition: gmock-actions.h:804
internal::Function< F >::Result Result
Definition: gmock-actions.h:329
AssignAction(T1 *ptr, T2 value)
Definition: gmock-actions.h:760
static T Get()
Definition: gmock-actions.h:116
PolymorphicAction< internal::ReturnVoidAction > Return()
Definition: gmock-actions.h:1071
Definition: gmock-generated-internal-utils.h:55
Definition: gtest-internal.h:903
bool IsDoDefault() const
Definition: gmock-actions.h:379
Definition: gmock-actions.h:427
Definition: gmock-actions.h:75
Definition: gmock-actions.h:871
ActionInterface()
Definition: gmock-actions.h:332
internal::DoDefaultAction DoDefault()
Definition: gmock-actions.h:1099
Definition: gmock-generated-internal-utils.h:154
void Assert(bool condition, const char *file, int line)
Definition: gmock-internal-utils.h:288
Definition: gmock-actions.h:534
Matcher< T > A()
Definition: gmock-matchers.h:3732
Definition: gmock-actions.h:327
void PrintTo(const ReferenceWrapper< T > &ref, ::std::ostream *os)
Definition: gmock-actions.h:964
static bool Exists()
Definition: gmock-actions.h:112
void Perform(const ArgumentTuple &args) const
Definition: gmock-actions.h:834
static bool Exists()
Definition: gmock-actions.h:137
const
Definition: upload.py:398
InvokeMethodWithoutArgsAction(Class *obj_ptr, MethodPtr method_ptr)
Definition: gmock-actions.h:873
ReferenceWrapper(T &l_value)
Definition: gmock-actions.h:953
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:874
internal::ByMoveWrapper< R > ByMove(R x)
Definition: gmock-actions.h:1094
TypeWithSize< 8 >::UInt UInt64
Definition: gtest-port.h:2497
Definition: gmock-actions.h:950
static T Get()
Definition: gmock-actions.h:80
static T Get()
Definition: gmock-actions.h:236
static Result Perform(const ArgumentTuple &)
Definition: gmock-actions.h:629
Result Perform(const ArgumentTuple &args) const
Definition: gmock-actions.h:387
static void SetFactory(FactoryFunction factory)
Definition: gmock-actions.h:213
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
Definition: gmock-actions.h:1187
TypeWithSize< 8 >::Int Int64
Definition: gtest-port.h:2496
Result Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:877
ReturnRefAction(T &ref)
Definition: gmock-actions.h:657
Definition: gmock-actions.h:641
const T & move(const T &t)
Definition: gtest-port.h:1317
void Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:763
ReturnAction(R value)
Definition: gmock-actions.h:539
Action< F > MakeAction(ActionInterface< F > *impl)
Definition: gmock-actions.h:463
ReturnRefOfCopyAction(const T &value)
Definition: gmock-actions.h:705
action
Definition: upload.py:393