43 #include <type_traits>
56 #if defined(_MSC_VER) && (_MSC_VER == 1900)
65 using ::testing::internal::BuiltInDefaultValue;
67 TEST(TypeTraits, Negation) {
69 static_assert(std::is_base_of<std::false_type,
70 internal::negation<std::true_type>>::
value,
73 static_assert(std::is_base_of<std::true_type,
74 internal::negation<std::false_type>>::
value,
79 static_assert(std::is_base_of<
81 internal::negation<std::integral_constant<int, 0>>>::
value,
84 static_assert(std::is_base_of<
86 internal::negation<std::integral_constant<int, 1>>>::
value,
89 static_assert(std::is_base_of<
91 internal::negation<std::integral_constant<int, -1>>>::
value,
104 struct MyFalse : std::integral_constant<int, 0> {};
107 struct MyTrue : std::integral_constant<int, -1> {};
109 TEST(TypeTraits, Conjunction) {
111 static_assert(std::is_base_of<std::true_type, internal::conjunction<>>::
value,
116 std::is_base_of<MyFalse<0>, internal::conjunction<MyFalse<0>>>::
value,
120 std::is_base_of<MyTrue<0>, internal::conjunction<MyTrue<0>>>::
value,
"");
124 std::is_base_of<MyFalse<1>, internal::conjunction<MyTrue<0>, MyFalse<1>,
129 std::is_base_of<MyFalse<1>, internal::conjunction<MyTrue<0>, MyFalse<1>,
137 std::is_base_of<MyFalse<1>, internal::conjunction<MyTrue<0>, MyFalse<1>,
143 std::is_base_of<MyTrue<2>, internal::conjunction<MyTrue<0>, MyTrue<1>,
148 TEST(TypeTraits, Disjunction) {
151 std::is_base_of<std::false_type, internal::disjunction<>>::
value,
"");
155 std::is_base_of<MyFalse<0>, internal::disjunction<MyFalse<0>>>::
value,
159 std::is_base_of<MyTrue<0>, internal::disjunction<MyTrue<0>>>::
value,
"");
163 std::is_base_of<MyTrue<1>, internal::disjunction<MyFalse<0>, MyTrue<1>,
168 std::is_base_of<MyTrue<1>, internal::disjunction<MyFalse<0>, MyTrue<1>,
176 std::is_base_of<MyTrue<1>, internal::disjunction<MyFalse<0>, MyTrue<1>,
182 std::is_base_of<MyFalse<2>, internal::disjunction<MyFalse<0>, MyFalse<1>,
187 TEST(TypeTraits, IsInvocableRV) {
189 int operator()()
const {
return 0; }
190 void operator()(
int) & {}
191 std::string operator()(
int) && {
return ""; };
225 #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
226 GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
229 NonMoveable() =
default;
230 NonMoveable(NonMoveable&&) =
delete;
233 static_assert(!std::is_move_constructible_v<NonMoveable>);
236 NonMoveable operator()() {
return NonMoveable(); }
247 #endif // C++17 and above
257 TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) {
258 EXPECT_TRUE(BuiltInDefaultValue<int*>::Get() ==
nullptr);
259 EXPECT_TRUE(BuiltInDefaultValue<const char*>::Get() ==
nullptr);
260 EXPECT_TRUE(BuiltInDefaultValue<void*>::Get() ==
nullptr);
264 TEST(BuiltInDefaultValueTest, ExistsForPointerTypes) {
266 EXPECT_TRUE(BuiltInDefaultValue<const char*>::Exists());
272 TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
273 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned char>::Get());
274 EXPECT_EQ(0, BuiltInDefaultValue<signed char>::Get());
275 EXPECT_EQ(0, BuiltInDefaultValue<char>::Get());
276 #if GMOCK_WCHAR_T_IS_NATIVE_
277 #if !defined(__WCHAR_UNSIGNED__)
278 EXPECT_EQ(0, BuiltInDefaultValue<wchar_t>::Get());
280 EXPECT_EQ(0U, BuiltInDefaultValue<wchar_t>::Get());
283 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned short>::Get());
284 EXPECT_EQ(0, BuiltInDefaultValue<signed short>::Get());
285 EXPECT_EQ(0, BuiltInDefaultValue<short>::Get());
286 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned int>::Get());
287 EXPECT_EQ(0, BuiltInDefaultValue<signed int>::Get());
288 EXPECT_EQ(0, BuiltInDefaultValue<int>::Get());
289 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long>::Get());
290 EXPECT_EQ(0, BuiltInDefaultValue<signed long>::Get());
291 EXPECT_EQ(0, BuiltInDefaultValue<long>::Get());
292 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long long>::Get());
293 EXPECT_EQ(0, BuiltInDefaultValue<signed long long>::Get());
294 EXPECT_EQ(0, BuiltInDefaultValue<long long>::Get());
295 EXPECT_EQ(0, BuiltInDefaultValue<float>::Get());
296 EXPECT_EQ(0, BuiltInDefaultValue<double>::Get());
301 TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
302 EXPECT_TRUE(BuiltInDefaultValue<unsigned char>::Exists());
303 EXPECT_TRUE(BuiltInDefaultValue<signed char>::Exists());
305 #if GMOCK_WCHAR_T_IS_NATIVE_
306 EXPECT_TRUE(BuiltInDefaultValue<wchar_t>::Exists());
308 EXPECT_TRUE(BuiltInDefaultValue<unsigned short>::Exists());
309 EXPECT_TRUE(BuiltInDefaultValue<signed short>::Exists());
311 EXPECT_TRUE(BuiltInDefaultValue<unsigned int>::Exists());
312 EXPECT_TRUE(BuiltInDefaultValue<signed int>::Exists());
314 EXPECT_TRUE(BuiltInDefaultValue<unsigned long>::Exists());
315 EXPECT_TRUE(BuiltInDefaultValue<signed long>::Exists());
317 EXPECT_TRUE(BuiltInDefaultValue<unsigned long long>::Exists());
318 EXPECT_TRUE(BuiltInDefaultValue<signed long long>::Exists());
319 EXPECT_TRUE(BuiltInDefaultValue<long long>::Exists());
321 EXPECT_TRUE(BuiltInDefaultValue<double>::Exists());
325 TEST(BuiltInDefaultValueTest, IsFalseForBool) {
330 TEST(BuiltInDefaultValueTest, BoolExists) {
336 TEST(BuiltInDefaultValueTest, IsEmptyStringForString) {
337 EXPECT_EQ(
"", BuiltInDefaultValue<::std::string>::Get());
342 TEST(BuiltInDefaultValueTest, ExistsForString) {
343 EXPECT_TRUE(BuiltInDefaultValue<::std::string>::Exists());
348 TEST(BuiltInDefaultValueTest, WorksForConstTypes) {
349 EXPECT_EQ(
"", BuiltInDefaultValue<const std::string>::Get());
350 EXPECT_EQ(0, BuiltInDefaultValue<const int>::Get());
351 EXPECT_TRUE(BuiltInDefaultValue<char* const>::Get() ==
nullptr);
356 class MyDefaultConstructible {
358 MyDefaultConstructible() :
value_(42) {}
367 class MyNonDefaultConstructible {
370 explicit MyNonDefaultConstructible(
int a_value) :
value_(a_value) {}
378 TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
379 EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
382 TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
383 EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().
value());
386 TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
387 EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
391 TEST(BuiltInDefaultValueDeathTest, IsUndefinedForReferences) {
396 TEST(BuiltInDefaultValueDeathTest, IsUndefinedForNonDefaultConstructibleType) {
398 { BuiltInDefaultValue<MyNonDefaultConstructible>::Get(); },
"");
402 TEST(DefaultValueTest, IsInitiallyUnset) {
404 EXPECT_FALSE(DefaultValue<MyDefaultConstructible>::IsSet());
405 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::IsSet());
409 TEST(DefaultValueTest, CanBeSetAndUnset) {
411 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::Exists());
415 MyNonDefaultConstructible(42));
418 EXPECT_EQ(42, DefaultValue<const MyNonDefaultConstructible>::Get().
value());
421 EXPECT_TRUE(DefaultValue<const MyNonDefaultConstructible>::Exists());
427 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::IsSet());
430 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::Exists());
436 TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
439 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible>::IsSet());
440 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible>::Exists());
448 TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
449 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
450 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() ==
nullptr);
451 DefaultValue<std::unique_ptr<int>>::SetFactory(
452 [] {
return std::make_unique<int>(42); });
453 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
454 std::unique_ptr<int>
i = DefaultValue<std::unique_ptr<int>>::Get();
464 TEST(DefaultValueOfReferenceTest, IsInitiallyUnset) {
466 EXPECT_FALSE(DefaultValue<MyDefaultConstructible&>::IsSet());
467 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
471 TEST(DefaultValueOfReferenceTest, IsInitiallyNotExisting) {
473 EXPECT_FALSE(DefaultValue<MyDefaultConstructible&>::Exists());
474 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::Exists());
478 TEST(DefaultValueOfReferenceTest, CanBeSetAndUnset) {
481 MyNonDefaultConstructible
x(42);
485 EXPECT_TRUE(DefaultValue<MyNonDefaultConstructible&>::Exists());
487 EXPECT_EQ(&n, &(DefaultValue<const int&>::Get()));
488 EXPECT_EQ(&
x, &(DefaultValue<MyNonDefaultConstructible&>::Get()));
494 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::Exists());
497 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
503 TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
505 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
515 typedef int MyGlobalFunction(
bool,
int);
517 class MyActionImpl :
public ActionInterface<MyGlobalFunction> {
519 int Perform(
const std::tuple<bool, int>& args)
override {
520 return std::get<0>(args) ? std::get<1>(args) : 0;
524 TEST(ActionInterfaceTest, CanBeImplementedByDefiningPerform) {
525 MyActionImpl my_action_impl;
526 (
void)my_action_impl;
530 Action<MyGlobalFunction> action =
MakeAction(
new MyActionImpl);
537 EXPECT_EQ(5, action.Perform(std::make_tuple(
true, 5)));
542 TEST(ActionTest, CanBeConstructedFromActionInterface) {
543 Action<MyGlobalFunction> action(
new MyActionImpl);
547 TEST(ActionTest, DelegatesWorkToActionInterface) {
548 const Action<MyGlobalFunction> action(
new MyActionImpl);
550 EXPECT_EQ(5, action.Perform(std::make_tuple(
true, 5)));
551 EXPECT_EQ(0, action.Perform(std::make_tuple(
false, 1)));
555 TEST(ActionTest, IsCopyable) {
556 Action<MyGlobalFunction> a1(
new MyActionImpl);
557 Action<MyGlobalFunction> a2(a1);
560 EXPECT_EQ(5, a1.Perform(std::make_tuple(
true, 5)));
561 EXPECT_EQ(0, a1.Perform(std::make_tuple(
false, 1)));
564 EXPECT_EQ(5, a2.Perform(std::make_tuple(
true, 5)));
565 EXPECT_EQ(0, a2.Perform(std::make_tuple(
false, 1)));
570 EXPECT_EQ(5, a1.Perform(std::make_tuple(
true, 5)));
571 EXPECT_EQ(0, a1.Perform(std::make_tuple(
false, 1)));
574 EXPECT_EQ(5, a2.Perform(std::make_tuple(
true, 5)));
575 EXPECT_EQ(0, a2.Perform(std::make_tuple(
false, 1)));
581 class IsNotZero :
public ActionInterface<bool(int)> {
583 bool Perform(
const std::tuple<int>& arg)
override {
584 return std::get<0>(arg) != 0;
588 TEST(ActionTest, CanBeConvertedToOtherActionType) {
589 const Action<bool(int)> a1(
new IsNotZero);
590 const Action<int(char)> a2 = Action<int(char)>(a1);
591 EXPECT_EQ(1, a2.Perform(std::make_tuple(
'a')));
592 EXPECT_EQ(0, a2.Perform(std::make_tuple(
'\0')));
599 class ReturnSecondArgumentAction {
604 template <
typename Result,
typename ArgumentTuple>
605 Result Perform(
const ArgumentTuple& args) {
606 return std::get<1>(args);
612 class ReturnZeroFromNullaryFunctionAction {
621 template <
typename Result>
622 Result Perform(
const std::tuple<>&)
const {
630 PolymorphicAction<ReturnSecondArgumentAction> ReturnSecondArgument() {
634 PolymorphicAction<ReturnZeroFromNullaryFunctionAction>
635 ReturnZeroFromNullaryFunction() {
641 TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) {
642 Action<int(bool, int, double)> a1 = ReturnSecondArgument();
643 EXPECT_EQ(5, a1.Perform(std::make_tuple(
false, 5, 2.0)));
648 TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) {
649 Action<int()> a1 = ReturnZeroFromNullaryFunction();
650 EXPECT_EQ(0, a1.Perform(std::make_tuple()));
652 Action<void*()> a2 = ReturnZeroFromNullaryFunction();
653 EXPECT_TRUE(a2.Perform(std::make_tuple()) ==
nullptr);
658 TEST(ReturnTest, WorksForVoid) {
659 const Action<void(int)> ret =
Return();
660 return ret.Perform(std::make_tuple(1));
664 TEST(ReturnTest, ReturnsGivenValue) {
665 Action<int()> ret =
Return(1);
666 EXPECT_EQ(1, ret.Perform(std::make_tuple()));
669 EXPECT_EQ(-5, ret.Perform(std::make_tuple()));
673 TEST(ReturnTest, AcceptsStringLiteral) {
674 Action<const char*()> a1 =
Return(
"Hello");
677 Action<std::string()> a2 =
Return(
"world");
678 EXPECT_EQ(
"world", a2.Perform(std::make_tuple()));
684 TEST(ReturnTest, SupportsReferenceLikeReturnType) {
687 const std::vector<int>* v;
688 Result(
const std::vector<int>& vec) : v(&vec) {}
699 MockFunction<Result()> mock;
701 .WillOnce(
Return(std::vector<int>{17, 19, 23}))
702 .WillRepeatedly(
Return(std::vector<int>{29, 31, 37}));
705 Field(&Result::v, Pointee(ElementsAre(17, 19, 23))));
708 Field(&Result::v, Pointee(ElementsAre(29, 31, 37))));
711 TEST(ReturnTest, PrefersConversionOperator) {
721 explicit Out(
const int val) :
x(val) {}
722 explicit Out(
const In&) :
x(0) {}
726 operator Out()
const {
return Out{19}; }
737 MockFunction<Out()> mock;
746 TEST(ReturnTest, ConversionRequiresConstLvalueReference) {
748 using U = std::reference_wrapper<const int>;
753 MockFunction<U()> mock;
764 TEST(ReturnTest, ConversionRequiresMutableLvalueReference) {
785 using RA = decltype(
Return(std::string()));
787 static_assert(!std::is_convertible<RA, Action<S()>>::
value,
"");
789 static_assert(!std::is_convertible<RA, OnceAction<S()>>::
value,
"");
793 TEST(ReturnTest, MoveOnlyResultType) {
796 MockFunction<std::unique_ptr<int>()> mock;
799 .WillOnce(
Return(std::unique_ptr<int>(
new int(17))));
806 static_assert(!std::is_convertible<decltype(
Return(std::unique_ptr<int>())),
807 Action<std::unique_ptr<int>()>>::
value,
817 struct Derived :
public Base {
818 bool operator==(
const Derived&) {
return true; }
821 TEST(ReturnTest, IsCovariant) {
824 Action<Base*()> ret =
Return(&base);
825 EXPECT_EQ(&base, ret.Perform(std::make_tuple()));
828 EXPECT_EQ(&derived, ret.Perform(std::make_tuple()));
837 explicit FromType(
bool* is_converted) :
converted_(is_converted) {}
838 bool* converted()
const {
return converted_; }
847 ToType(
const FromType&
x) { *x.converted() =
true; }
850 TEST(ReturnTest, ConvertsArgumentWhenConverted) {
851 bool converted =
false;
852 FromType
x(&converted);
853 Action<ToType()> action(
Return(
x));
854 EXPECT_TRUE(converted) <<
"Return must convert its argument in its own "
855 <<
"conversion operator.";
857 action.Perform(std::tuple<>());
858 EXPECT_FALSE(converted) <<
"Action must NOT convert its argument "
859 <<
"when performed.";
863 TEST(ReturnNullTest, WorksInPointerReturningFunction) {
865 EXPECT_TRUE(a1.Perform(std::make_tuple()) ==
nullptr);
867 const Action<const char*(bool)> a2 =
ReturnNull();
868 EXPECT_TRUE(a2.Perform(std::make_tuple(
true)) ==
nullptr);
873 TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
874 const Action<std::unique_ptr<const int>()> a1 =
ReturnNull();
875 EXPECT_TRUE(a1.Perform(std::make_tuple()) ==
nullptr);
877 const Action<std::shared_ptr<int>(std::string)> a2 =
ReturnNull();
878 EXPECT_TRUE(a2.Perform(std::make_tuple(
"foo")) ==
nullptr);
882 TEST(ReturnRefTest, WorksForReference) {
884 const Action<const int&(bool)> ret =
ReturnRef(n);
886 EXPECT_EQ(&n, &ret.Perform(std::make_tuple(
true)));
890 TEST(ReturnRefTest, IsCovariant) {
894 EXPECT_EQ(&base, &a.Perform(std::make_tuple()));
897 EXPECT_EQ(&derived, &a.Perform(std::make_tuple()));
900 template <
typename T,
typename = decltype(ReturnRef(std::declval<T&&>()))>
901 bool CanCallReturnRef(
T&&) {
904 bool CanCallReturnRef(
Unused) {
return false; }
907 TEST(ReturnRefTest, WorksForNonTemporary) {
908 int scalar_value = 123;
911 std::string non_scalar_value(
"ABC");
914 const int const_scalar_value{321};
917 const std::string const_non_scalar_value(
"CBA");
918 EXPECT_TRUE(CanCallReturnRef(const_non_scalar_value));
922 TEST(ReturnRefTest, DoesNotWorkForTemporary) {
923 auto scalar_value = []() ->
int {
return 123; };
926 auto non_scalar_value = []() -> std::string {
return "ABC"; };
931 EXPECT_FALSE(CanCallReturnRef(static_cast<const int>(321)));
933 auto const_non_scalar_value = []() ->
const std::string {
return "CBA"; };
934 EXPECT_FALSE(CanCallReturnRef(const_non_scalar_value()));
938 TEST(ReturnRefOfCopyTest, WorksForReference) {
942 EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
943 EXPECT_EQ(42, ret.Perform(std::make_tuple()));
946 EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
947 EXPECT_EQ(42, ret.Perform(std::make_tuple()));
951 TEST(ReturnRefOfCopyTest, IsCovariant) {
955 EXPECT_NE(&base, &a.Perform(std::make_tuple()));
958 EXPECT_NE(&derived, &a.Perform(std::make_tuple()));
962 TEST(ReturnRoundRobinTest, WorksForInitList) {
965 EXPECT_EQ(1, ret.Perform(std::make_tuple()));
966 EXPECT_EQ(2, ret.Perform(std::make_tuple()));
967 EXPECT_EQ(3, ret.Perform(std::make_tuple()));
968 EXPECT_EQ(1, ret.Perform(std::make_tuple()));
969 EXPECT_EQ(2, ret.Perform(std::make_tuple()));
970 EXPECT_EQ(3, ret.Perform(std::make_tuple()));
974 TEST(ReturnRoundRobinTest, WorksForVector) {
975 std::vector<double> v = {4.4, 5.5, 6.6};
978 EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
979 EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
980 EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
981 EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
982 EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
983 EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
990 MockClass() =
default;
996 MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
999 int(
const std::unique_ptr<int>&, std::unique_ptr<int>));
1002 MockClass(
const MockClass&) =
delete;
1003 MockClass& operator=(
const MockClass&) =
delete;
1008 TEST(DoDefaultTest, ReturnsBuiltInDefaultValueByDefault) {
1016 TEST(DoDefaultDeathTest, DiesForUnknowType) {
1019 #if GTEST_HAS_EXCEPTIONS
1029 void VoidFunc(
bool ) {}
1031 TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
1045 TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) {
1054 TEST(DoDefaultTest, DoesWhatOnCallSpecifies) {
1062 TEST(DoDefaultTest, CannotBeUsedInOnCall) {
1068 "DoDefault() cannot be used in ON_CALL()");
1073 TEST(SetArgPointeeTest, SetsTheNthPointee) {
1075 Action<MyFunction> a = SetArgPointee<1>(2);
1079 a.Perform(std::make_tuple(
true, &n, &ch));
1083 a = SetArgPointee<2>(
'a');
1086 a.Perform(std::make_tuple(
true, &n, &ch));
1092 TEST(SetArgPointeeTest, AcceptsStringLiteral) {
1093 typedef void MyFunction(std::string*,
const char**);
1094 Action<MyFunction> a = SetArgPointee<0>(
"hi");
1096 const char* ptr =
nullptr;
1097 a.Perform(std::make_tuple(&str, &ptr));
1101 a = SetArgPointee<1>(
"world");
1103 a.Perform(std::make_tuple(&str, &ptr));
1108 TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
1110 Action<MyFunction> a = SetArgPointee<0>(L
"world");
1111 const wchar_t* ptr =
nullptr;
1112 a.Perform(std::make_tuple(&ptr));
1115 #if GTEST_HAS_STD_WSTRING
1117 typedef void MyStringFunction(std::wstring*);
1118 Action<MyStringFunction> a2 = SetArgPointee<0>(L
"world");
1119 std::wstring str = L
"";
1120 a2.Perform(std::make_tuple(&str));
1127 TEST(SetArgPointeeTest, AcceptsCharPointer) {
1128 typedef void MyFunction(
bool, std::string*,
const char**);
1129 const char*
const hi =
"hi";
1130 Action<MyFunction> a = SetArgPointee<1>(hi);
1132 const char* ptr =
nullptr;
1133 a.Perform(std::make_tuple(
true, &str, &ptr));
1137 char world_array[] =
"world";
1138 char*
const world = world_array;
1139 a = SetArgPointee<2>(world);
1141 a.Perform(std::make_tuple(
true, &str, &ptr));
1146 TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
1147 typedef void MyFunction(
bool,
const wchar_t**);
1148 const wchar_t*
const hi = L
"hi";
1149 Action<MyFunction> a = SetArgPointee<1>(hi);
1150 const wchar_t* ptr =
nullptr;
1151 a.Perform(std::make_tuple(
true, &ptr));
1154 #if GTEST_HAS_STD_WSTRING
1156 typedef void MyStringFunction(
bool, std::wstring*);
1157 wchar_t world_array[] = L
"world";
1158 wchar_t*
const world = world_array;
1159 Action<MyStringFunction> a2 = SetArgPointee<1>(world);
1161 a2.Perform(std::make_tuple(
true, &str));
1168 TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
1170 Action<MyFunction> a = SetArgumentPointee<1>(2);
1174 a.Perform(std::make_tuple(
true, &n, &ch));
1178 a = SetArgumentPointee<2>(
'a');
1181 a.Perform(std::make_tuple(
true, &n, &ch));
1189 class NullaryFunctor {
1191 int operator()() {
return 2; }
1195 void VoidNullary() { g_done =
true; }
1197 class VoidNullaryFunctor {
1199 void operator()() { g_done =
true; }
1202 short Short(
short n) {
return n; }
1203 char Char(
char ch) {
return ch; }
1205 const char*
CharPtr(
const char* s) {
return s; }
1207 bool Unary(
int x) {
return x < 0; }
1209 const char*
Binary(
const char* input,
short n) {
return input + n; }
1211 void VoidBinary(
int,
char) { g_done =
true; }
1213 int Ternary(
int x,
char y,
short z) {
return x + y +
z; }
1215 int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c + d; }
1228 TEST(InvokeWithoutArgsTest, Function) {
1231 EXPECT_EQ(1, a.Perform(std::make_tuple(2)));
1235 EXPECT_EQ(1, a2.Perform(std::make_tuple(2, 3.5)));
1240 a3.Perform(std::make_tuple(1));
1245 TEST(InvokeWithoutArgsTest, Functor) {
1248 EXPECT_EQ(2, a.Perform(std::make_tuple()));
1251 Action<int(int, double, char)> a2 =
1253 EXPECT_EQ(2, a2.Perform(std::make_tuple(3, 3.5,
'a')));
1258 a3.Perform(std::make_tuple());
1265 Action<int(bool, char)> a =
1267 EXPECT_EQ(123, a.Perform(std::make_tuple(
true,
'a')));
1271 TEST(IgnoreResultTest, PolymorphicAction) {
1273 a.Perform(std::make_tuple(1));
1283 TEST(IgnoreResultTest, MonomorphicAction) {
1286 a.Perform(std::make_tuple());
1292 MyNonDefaultConstructible ReturnMyNonDefaultConstructible(
double ) {
1294 return MyNonDefaultConstructible(42);
1297 TEST(IgnoreResultTest, ActionReturningClass) {
1299 Action<void(int)> a =
1301 a.Perform(std::make_tuple(2));
1305 TEST(AssignTest, Int) {
1307 Action<void(int)> a =
Assign(&x, 5);
1308 a.Perform(std::make_tuple(0));
1312 TEST(AssignTest, String) {
1314 Action<void(void)> a =
Assign(&x,
"Hello, world");
1315 a.Perform(std::make_tuple());
1319 TEST(AssignTest, CompatibleTypes) {
1321 Action<void(int)> a =
Assign(&x, 5);
1322 a.Perform(std::make_tuple(0));
1327 TEST(
DoAll, SupportsRefQualifiedActions) {
1328 struct InitialAction {
1329 void operator()(
const int arg) && {
EXPECT_EQ(17, arg); }
1332 struct FinalAction {
1333 int operator()() && {
return 19; }
1336 MockFunction<int(int)> mock;
1338 EXPECT_EQ(19, mock.AsStdFunction()(17));
1345 TEST(
DoAll, ProvidesLvalueReferencesToInitialActions) {
1351 struct InitialAction {
1352 void operator()(Obj&)
const {
FAIL() <<
"Unexpected call"; }
1353 void operator()(
const Obj&)
const {}
1354 void operator()(Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1355 void operator()(
const Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1358 MockFunction<void(Obj)> mock;
1360 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](Obj&&) {}))
1361 .WillRepeatedly(
DoAll(InitialAction{}, InitialAction{}, [](Obj&&) {}));
1363 mock.AsStdFunction()(Obj{});
1364 mock.AsStdFunction()(Obj{});
1370 struct InitialAction {
1371 void operator()(Obj&)
const {
FAIL() <<
"Unexpected call"; }
1372 void operator()(
const Obj&)
const {}
1373 void operator()(Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1374 void operator()(
const Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1377 MockFunction<void(const Obj&)> mock;
1379 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](
const Obj&) {}))
1381 DoAll(InitialAction{}, InitialAction{}, [](
const Obj&) {}));
1383 mock.AsStdFunction()(Obj{});
1384 mock.AsStdFunction()(Obj{});
1390 struct InitialAction {
1391 void operator()(Obj&)
const {}
1392 void operator()(Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1395 MockFunction<void(Obj&)> mock;
1397 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](Obj&) {}))
1398 .WillRepeatedly(
DoAll(InitialAction{}, InitialAction{}, [](Obj&) {}));
1401 mock.AsStdFunction()(obj);
1402 mock.AsStdFunction()(obj);
1409 struct InitialAction {
1410 void operator()(Obj&)
const {}
1411 void operator()(Obj&&)
const {
FAIL() <<
"Unexpected call"; }
1414 MockFunction<void(Obj&&)> mock;
1416 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](Obj&&) {}))
1417 .WillRepeatedly(
DoAll(InitialAction{}, InitialAction{}, [](Obj&&) {}));
1419 mock.AsStdFunction()(Obj{});
1420 mock.AsStdFunction()(Obj{});
1425 struct InitialAction {
1426 void operator()(Obj&) && {}
1429 MockFunction<void(Obj&)> mock;
1431 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](Obj&) {}));
1434 mock.AsStdFunction()(obj);
1438 struct InitialAction {
1439 void operator()(Obj&) && {}
1442 MockFunction<void(Obj&&)> mock;
1444 .WillOnce(
DoAll(InitialAction{}, InitialAction{}, [](Obj&&) {}));
1446 mock.AsStdFunction()(Obj{});
1452 TEST(
DoAll, SupportsTypeErasedActions) {
1454 const Action<void()> initial_action = [] {};
1455 const Action<int()> final_action = [] {
return 17; };
1457 MockFunction<int()> mock;
1459 .WillOnce(
DoAll(initial_action, initial_action, final_action))
1460 .WillRepeatedly(
DoAll(initial_action, initial_action, final_action));
1466 struct FinalAction {
1467 FinalAction() =
default;
1468 FinalAction(FinalAction&&) =
default;
1470 int operator()() && {
return 17; }
1474 .WillOnce(
DoAll(initial_action, initial_action, FinalAction{}));
1484 TEST(
DoAll, ConvertibleToOnceActionWithUserProvidedActionConversion) {
1486 struct CustomFinal final {
1487 operator Action<int()>() {
1491 operator Action<int(int, char)>() {
1497 OnceAction<int()> action =
DoAll(CustomFinal{});
1498 EXPECT_EQ(17, std::move(action).Call());
1502 OnceAction<int(int, char)> action =
DoAll(CustomFinal{});
1503 EXPECT_EQ(19, std::move(action).Call(0, 0));
1507 struct CustomInitial final {
1508 operator Action<void()>() {
1512 operator Action<void(int, char)>() {
1518 OnceAction<int()> action =
DoAll(CustomInitial{}, CustomFinal{});
1519 EXPECT_EQ(17, std::move(action).Call());
1523 OnceAction<int(int, char)> action =
DoAll(CustomInitial{}, CustomFinal{});
1524 EXPECT_EQ(19, std::move(action).Call(0, 0));
1529 TEST(WithArgsTest, OneArg) {
1530 Action<bool(double x, int n)> a = WithArgs<1>(
Invoke(
Unary));
1536 TEST(WithArgsTest, TwoArgs) {
1537 Action<const char*(const char* s, double x, short n)> a =
1539 const char s[] =
"Hello";
1544 std::string operator()()
const {
return {}; }
1545 template <
typename... I>
1546 std::string operator()(
const char* a, I...
i)
const {
1547 return a + ConcatAll()(
i...);
1552 TEST(WithArgsTest, TenArgs) {
1553 Action<std::string(const char*, const char*, const char*, const char*)> a =
1554 WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(
Invoke(ConcatAll{}));
1561 class SubtractAction :
public ActionInterface<int(int, int)> {
1563 int Perform(
const std::tuple<int, int>& args)
override {
1564 return std::get<0>(args) - std::get<1>(args);
1568 TEST(WithArgsTest, NonInvokeAction) {
1569 Action<int(const std::string&, int, int)> a =
1570 WithArgs<2, 1>(
MakeAction(
new SubtractAction));
1571 std::tuple<std::string, int, int> dummy =
1572 std::make_tuple(std::string(
"hi"), 2, 10);
1577 TEST(WithArgsTest, Identity) {
1578 Action<int(int x, char y, short z)> a =
1584 TEST(WithArgsTest, RepeatedArguments) {
1585 Action<int(bool, int m, int n)> a =
1587 EXPECT_EQ(4, a.Perform(std::make_tuple(
false, 1, 10)));
1591 TEST(WithArgsTest, ReversedArgumentOrder) {
1592 Action<const char*(short n, const char* input)> a =
1594 const char s[] =
"Hello";
1599 TEST(WithArgsTest, ArgsOfCompatibleTypes) {
1600 Action<long(short x, char y, double z, char c)> a =
1603 a.Perform(std::make_tuple(
Short(100),
Char(20), 5.6,
Char(3))));
1607 TEST(WithArgsTest, VoidAction) {
1608 Action<void(double x, char c, int n)> a = WithArgs<2, 1>(
Invoke(VoidBinary));
1610 a.Perform(std::make_tuple(1.5,
'a', 3));
1614 TEST(WithArgsTest, ReturnReference) {
1615 Action<int&(int&, void*)> aa = WithArgs<0>([](
int&
a) ->
int& {
return a; });
1617 const int& res = aa.Perform(std::forward_as_tuple(i,
nullptr));
1621 TEST(WithArgsTest, InnerActionWithConversion) {
1622 Action<Derived*()> inner = [] {
return nullptr; };
1624 MockFunction<Base*(double)> mock;
1629 EXPECT_EQ(
nullptr, mock.AsStdFunction()(1.1));
1630 EXPECT_EQ(
nullptr, mock.AsStdFunction()(1.1));
1635 TEST(WithArgsTest, RefQualifiedInnerAction) {
1637 int operator()(
const int arg) && {
1643 MockFunction<int(int, int)> mock;
1644 EXPECT_CALL(mock, Call).WillOnce(WithArg<1>(SomeAction{}));
1645 EXPECT_EQ(19, mock.AsStdFunction()(0, 17));
1648 #ifndef GTEST_OS_WINDOWS_MOBILE
1652 void SetUp()
override { errno = 0; }
1653 void TearDown()
override { errno = 0; }
1656 TEST_F(SetErrnoAndReturnTest, Int) {
1658 EXPECT_EQ(-5, a.Perform(std::make_tuple()));
1662 TEST_F(SetErrnoAndReturnTest, Ptr) {
1665 EXPECT_EQ(&x, a.Perform(std::make_tuple()));
1669 TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
1675 #endif // !GTEST_OS_WINDOWS_MOBILE
1680 TEST(ByRefTest, IsCopyable) {
1681 const std::string s1 =
"Hi";
1682 const std::string s2 =
"Hello";
1684 auto ref_wrapper =
ByRef(s1);
1685 const std::string& r1 = ref_wrapper;
1689 ref_wrapper =
ByRef(s2);
1690 const std::string& r2 = ref_wrapper;
1693 auto ref_wrapper1 =
ByRef(s1);
1695 ref_wrapper = ref_wrapper1;
1696 const std::string& r3 = ref_wrapper;
1701 TEST(ByRefTest, ConstValue) {
1705 const int& const_ref =
ByRef(n);
1710 TEST(ByRefTest, NonConstValue) {
1714 int& ref =
ByRef(n);
1718 const int& const_ref =
ByRef(n);
1723 TEST(ByRefTest, ExplicitType) {
1725 const int& r1 = ByRef<const int>(n);
1732 Derived& r2 = ByRef<Derived>(d);
1735 const Derived& r3 = ByRef<const Derived>(d);
1738 Base& r4 = ByRef<Base>(d);
1741 const Base& r5 = ByRef<const Base>(d);
1752 TEST(ByRefTest, PrintsCorrectly) {
1754 ::std::stringstream
expected, actual;
1757 EXPECT_EQ(expected.str(), actual.str());
1760 struct UnaryConstructorClass {
1761 explicit UnaryConstructorClass(
int v) :
value(v) {}
1767 Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000);
1768 UnaryConstructorClass*
c = a.Perform(std::make_tuple());
1773 TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
1774 Action<UnaryConstructorClass*(bool, int)> a =
1775 ReturnNew<UnaryConstructorClass>(4000);
1776 UnaryConstructorClass*
c = a.Perform(std::make_tuple(
false, 5));
1781 TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) {
1782 Action<const UnaryConstructorClass*()> a =
1783 ReturnNew<UnaryConstructorClass>(4000);
1784 const UnaryConstructorClass* c = a.Perform(std::make_tuple());
1789 class TenArgConstructorClass {
1791 TenArgConstructorClass(
int a1,
int a2,
int a3,
int a4,
int a5,
int a6,
int a7,
1792 int a8,
int a9,
int a10)
1793 :
value_(a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10) {}
1798 TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
1799 Action<TenArgConstructorClass*()> a = ReturnNew<TenArgConstructorClass>(
1800 1000000000, 200000000, 30000000, 4000000, 500000, 60000, 7000, 800, 90,
1802 TenArgConstructorClass* c = a.Perform(std::make_tuple());
1807 std::unique_ptr<int> UniquePtrSource() {
return std::make_unique<int>(19); }
1809 std::vector<std::unique_ptr<int>> VectorUniquePtrSource() {
1810 std::vector<std::unique_ptr<int>> out;
1811 out.emplace_back(
new int(7));
1815 TEST(MockMethodTest, CanReturnMoveOnlyValue_Return) {
1817 std::unique_ptr<int>
i(
new int(19));
1821 Derived* d =
new Derived;
1823 .WillOnce(
Return(
ByMove(std::unique_ptr<Derived>(d))));
1825 std::unique_ptr<int> result1 = mock.MakeUnique();
1828 std::vector<std::unique_ptr<int>> vresult = mock.MakeVectorUnique();
1833 std::unique_ptr<Base> result2 = mock.MakeUniqueBase();
1837 TEST(MockMethodTest, CanReturnMoveOnlyValue_DoAllReturn) {
1838 testing::MockFunction<void()> mock_function;
1840 std::unique_ptr<int>
i(
new int(19));
1844 &testing::MockFunction<
void()>::Call),
1847 std::unique_ptr<int> result1 = mock.MakeUnique();
1851 TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
1855 DefaultValue<std::unique_ptr<int>>::SetFactory(
1856 [] {
return std::make_unique<int>(42); });
1861 .WillRepeatedly(
Invoke(VectorUniquePtrSource));
1862 std::unique_ptr<int> result1 = mock.MakeUnique();
1864 std::unique_ptr<int> result2 = mock.MakeUnique();
1868 std::vector<std::unique_ptr<int>> vresult = mock.MakeVectorUnique();
1874 TEST(MockMethodTest, CanTakeMoveOnlyValue) {
1876 auto make = [](
int i) {
return std::make_unique<int>(
i); };
1878 EXPECT_CALL(mock, TakeUnique(
_)).WillRepeatedly([](std::unique_ptr<int> i) {
1885 EXPECT_CALL(mock, TakeUnique(testing::Pointee(7)))
1887 .RetiresOnSaturation();
1890 .RetiresOnSaturation();
1893 EXPECT_EQ(-7, mock.TakeUnique(make(7)));
1899 auto lvalue = make(6);
1901 .WillOnce([](
const std::unique_ptr<int>& i, std::unique_ptr<int> j) {
1904 EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7)));
1907 std::unique_ptr<int> saved;
1908 EXPECT_CALL(mock, TakeUnique(
_)).WillOnce([&saved](std::unique_ptr<int> i) {
1909 saved = std::move(i);
1912 EXPECT_EQ(0, mock.TakeUnique(make(42)));
1919 TEST(MockMethodTest, ActionHasRvalueRefQualifiedCallOperator) {
1921 int operator()() && {
return 17; }
1926 MockFunction<int()> mock;
1934 MockFunction<int(int)> mock;
1945 TEST(MockMethodTest, ActionHasMultipleCallOperators) {
1947 int operator()() && {
return 17; }
1948 int operator()() const& {
return 19; }
1953 MockFunction<int()> mock;
1954 EXPECT_CALL(mock, Call).WillOnce(ReturnInt()).WillRepeatedly(ReturnInt());
1963 MockFunction<int(int)> mock;
1964 EXPECT_CALL(mock, Call).WillOnce(ReturnInt()).WillRepeatedly(ReturnInt());
1974 TEST(MockMethodTest, MoveOnlyAction) {
1978 Return17() =
default;
1979 Return17(Return17&&) =
default;
1981 Return17(
const Return17&) =
delete;
1982 Return17 operator=(
const Return17&) =
delete;
1984 int operator()() && {
return 17; }
1987 MockFunction<int()> mock;
1995 Return17() =
default;
1996 Return17(Return17&&) =
default;
1998 Return17(
const Return17&) =
delete;
1999 Return17 operator=(
const Return17&) =
delete;
2001 int operator()()
const {
return 17; }
2004 MockFunction<int()> mock;
2012 TEST(MockMethodTest, ActionReturnsIgnoredValue) {
2014 int operator()()
const {
return 0; }
2017 MockFunction<void()> mock;
2018 EXPECT_CALL(mock, Call).WillOnce(ReturnInt()).WillRepeatedly(ReturnInt());
2020 mock.AsStdFunction()();
2021 mock.AsStdFunction()();
2026 TEST(MockMethodTest, WillOnceCanAcceptLvalueReference) {
2027 MockFunction<int()> mock;
2029 const auto action = [] {
return 17; };
2037 struct StaticAssertSingleArgument {
2038 template <
typename... Args>
2039 static constexpr
bool CheckArgs() {
2040 static_assert(
sizeof...(Args) == 1,
"");
2044 template <
typename... Args,
bool = CheckArgs<Args...>()>
2045 int operator()(Args...)
const {
2054 TEST(MockMethodTest, ActionSwallowsAllArguments) {
2055 MockFunction<int(int)> mock;
2057 .WillOnce(StaticAssertSingleArgument{})
2058 .WillRepeatedly(StaticAssertSingleArgument{});
2064 struct ActionWithTemplatedConversionOperators {
2065 template <
typename... Args>
2066 operator OnceAction<int(Args...)>() && {
2067 return [] {
return 17; };
2070 template <
typename... Args>
2071 operator Action<int(Args...)>()
const {
2072 return [] {
return 19; };
2079 TEST(MockMethodTest, ActionHasTemplatedConversionOperators) {
2080 MockFunction<int()> mock;
2082 .WillOnce(ActionWithTemplatedConversionOperators{})
2083 .WillRepeatedly(ActionWithTemplatedConversionOperators{});
2091 int Add(
int val,
int& ref,
int* ptr) {
2092 int result = val + ref + *ptr;
2098 int Deref(std::unique_ptr<int> ptr) {
return *ptr; }
2101 template <
typename T>
2107 std::unique_ptr<int> UniqueInt(
int i) {
return std::make_unique<int>(
i); }
2109 TEST(FunctorActionTest, ActionFromFunction) {
2110 Action<int(int, int&, int*)> a = &
Add;
2111 int x = 1,
y = 2,
z = 3;
2112 EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x,
y, &
z)));
2116 Action<int(std::unique_ptr<int>)> a1 = &Deref;
2117 EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7))));
2120 TEST(FunctorActionTest, ActionFromLambda) {
2121 Action<int(bool, int)> a1 = [](
bool b,
int i) {
return b ? i : 0; };
2122 EXPECT_EQ(5, a1.Perform(std::make_tuple(
true, 5)));
2123 EXPECT_EQ(0, a1.Perform(std::make_tuple(
false, 5)));
2125 std::unique_ptr<int> saved;
2126 Action<void(std::unique_ptr<int>)> a2 = [&saved](std::unique_ptr<int>
p) {
2127 saved = std::move(p);
2129 a2.Perform(std::make_tuple(UniqueInt(5)));
2133 TEST(FunctorActionTest, PolymorphicFunctor) {
2134 Action<int(int)> ai =
Double();
2135 EXPECT_EQ(2, ai.Perform(std::make_tuple(1)));
2136 Action<double(double)> ad =
Double();
2137 EXPECT_EQ(3.0, ad.Perform(std::make_tuple(1.5)));
2140 TEST(FunctorActionTest, TypeConversion) {
2142 const Action<bool(int)> a1 = [](
int i) {
return i > 1; };
2143 const Action<int(bool)> a2 = Action<int(bool)>(a1);
2144 EXPECT_EQ(1, a1.Perform(std::make_tuple(42)));
2145 EXPECT_EQ(0, a2.Perform(std::make_tuple(42)));
2148 const Action<bool(std::string)> s1 = [](std::string s) {
return !s.empty(); };
2149 const Action<int(const char*)> s2 = Action<int(const char*)>(s1);
2150 EXPECT_EQ(0, s2.Perform(std::make_tuple(
"")));
2151 EXPECT_EQ(1, s2.Perform(std::make_tuple(
"hello")));
2154 const Action<bool(std::string)> x1 = [](
Unused) {
return 42; };
2155 const Action<bool(std::string)> x2 = [] {
return 42; };
2156 EXPECT_TRUE(x1.Perform(std::make_tuple(
"hello")));
2157 EXPECT_TRUE(x2.Perform(std::make_tuple(
"hello")));
2160 std::function<int()>
f = [] {
return 7; };
2161 Action<int(int)> d = f;
2163 EXPECT_EQ(7, d.Perform(std::make_tuple(1)));
2166 Action<void(int)>(
nullptr);
2169 TEST(FunctorActionTest, UnusedArguments) {
2171 Action<int(int, double y, double z)> a = [](
int i,
Unused,
Unused) {
2174 std::tuple<int, double, double> dummy = std::make_tuple(3, 7.3, 9.44);
2179 TEST(MoveOnlyArgumentsTest, ReturningActions) {
2180 Action<int(std::unique_ptr<int>)> a =
Return(1);
2181 EXPECT_EQ(1, a.Perform(std::make_tuple(
nullptr)));
2184 EXPECT_EQ(7, a.Perform(std::make_tuple(
nullptr)));
2186 Action<void(std::unique_ptr<int>,
int*)> a2 = testing::SetArgPointee<1>(3);
2188 a2.Perform(std::make_tuple(
nullptr, &x));
2194 TEST(ActionMacro, LargeArity) {
2196 1,
testing::Action<
int(
int)>(ReturnArity()).Perform(std::make_tuple(0)));
2199 testing::Action<
int(
int,
int,
int,
int,
int,
int,
int,
int,
int,
int)>(
2201 .Perform(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)));
2204 testing::Action<
int(
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
2205 int,
int,
int,
int,
int,
int,
int,
int,
int)>(
2207 .Perform(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
2208 14, 15, 16, 17, 18, 19)));
2214 #if defined(_MSC_VER) && (_MSC_VER == 1900)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
GTEST_DISABLE_MSC_WARNINGS_POP_() TEST(LinkTest
internal::IgnoredValue Unused
#define EXPECT_NONFATAL_FAILURE(statement, substr)
internal::ReturnRoundRobinAction< T > ReturnRoundRobin(std::vector< T > vals)
int SumOf4(int a, int b, int c, int d)
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
TEST_F(TestInfoTest, Names)
#define EXPECT_NE(val1, val2)
#define MOCK_METHOD0(m,...)
internal::DoAllAction< typename std::decay< Action >::type...> DoAll(Action &&...action)
#define ON_CALL(obj, call)
#define EXPECT_ANY_THROW(statement)
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
is_callable_r_impl< void, R, F, Args...> is_callable_r
#define MOCK_METHOD2(m,...)
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
inline::std::reference_wrapper< T > ByRef(T &l_value)
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
internal::ReturnRefAction< R > ReturnRef(R &x)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
const char * CharPtr(const char *s)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
FloatingPoint< double > Double
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
TEST(GTestEnvVarTest, Dummy)
void UniversalPrint(const T &value,::std::ostream *os)
ADVar foo(double d, ADVar x, ADVar y)
#define EXPECT_STREQ(s1, s2)
#define MOCK_METHOD1(m,...)
#define EXPECT_THAT(value, matcher)
internal::DoDefaultAction DoDefault()
internal::ReturnAction< R > Return(R value)
int Ternary(int x, char y, short z)
#define EXPECT_CALL(obj, call)
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
#define EXPECT_EQ(val1, val2)
internal::ByMoveWrapper< R > ByMove(R x)
#define EXPECT_TRUE(condition)
static void Print(const T &value,::std::ostream *os)
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
#define EXPECT_FALSE(condition)
AssertionResult IsNull(const char *str)
const char * Binary(const char *input, short n)
Action< F > MakeAction(ActionInterface< F > *impl)
static ExpectedAnswer expected[4]