36#pragma warning(disable : 4577)
51namespace gmock_more_actions_test {
68inline short Short(
short n) {
return n; }
78bool ByConstRef(
const std::string& s) {
return s ==
"Hi"; }
87const char*
Binary(
const char* input,
short n) {
return input + n; }
91int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c + d; }
95int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
99 return a + b + c + d + e;
103int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
104 return a + b + c + d + e + f;
109 return a + b + c + d + e + f;
113std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
114 const char* s4,
const char* s5,
const char* s6,
116 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
119std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
120 const char* s4,
const char* s5,
const char* s6,
121 const char* s7,
const char* s8) {
122 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
125std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
126 const char* s4,
const char* s5,
const char* s6,
127 const char* s7,
const char* s8,
const char* s9) {
128 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
131std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
132 const char* s4,
const char* s5,
const char* s6,
133 const char* s7,
const char* s8,
const char* s9,
135 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
144 short Unary(
long x) {
return static_cast<short>(value_ +
x); }
146 std::string
Binary(
const std::string& str,
char c)
const {
return str + c; }
150 int SumOf4(
int a,
int b,
int c,
int d)
const {
151 return a + b + c + d + value_;
156 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
158 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
159 return a + b + c + d + e + f;
162 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
163 const char* s4,
const char* s5,
const char* s6,
165 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
168 std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
169 const char* s4,
const char* s5,
const char* s6,
170 const char* s7,
const char* s8) {
171 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
174 std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
175 const char* s4,
const char* s5,
const char* s6,
176 const char* s7,
const char* s8,
const char* s9) {
177 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
180 std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
181 const char* s4,
const char* s5,
const char* s6,
182 const char* s7,
const char* s8,
const char* s9,
184 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
207 const char*
p =
"Hello";
218TEST(InvokeTest, FunctionThatTakes4Arguments) {
224TEST(InvokeTest, FunctionThatTakes5Arguments) {
230TEST(InvokeTest, FunctionThatTakes6Arguments) {
233 a.
Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
238inline const char*
CharPtr(
const char* s) {
return s; }
241TEST(InvokeTest, FunctionThatTakes7Arguments) {
242 Action<std::string(
const char*,
const char*,
const char*,
const char*,
243 const char*,
const char*,
const char*)>
252TEST(InvokeTest, FunctionThatTakes8Arguments) {
253 Action<std::string(
const char*,
const char*,
const char*,
const char*,
254 const char*,
const char*,
const char*,
const char*)>
263TEST(InvokeTest, FunctionThatTakes9Arguments) {
264 Action<std::string(
const char*,
const char*,
const char*,
const char*,
265 const char*,
const char*,
const char*,
const char*,
275TEST(InvokeTest, FunctionThatTakes10Arguments) {
276 Action<std::string(
const char*,
const char*,
const char*,
const char*,
277 const char*,
const char*,
const char*,
const char*,
278 const char*,
const char*)>
288TEST(InvokeTest, FunctionWithUnusedParameters) {
290 std::tuple<int, int, double, std::string> dummy =
291 std::make_tuple(10, 2, 5.6, std::string(
"hi"));
294 Action<int(
int,
int,
bool,
int*)> a2 =
297 23, a2.
Perform(std::make_tuple(20, 3,
true,
static_cast<int*
>(
nullptr))));
301TEST(InvokeTest, MethodWithUnusedParameters) {
306 Action<int(
char,
double,
int,
int)> a2 =
318TEST(InvokeTest, FunctionWithCompatibleType) {
343 std::string s(
"Hell");
344 std::tuple<std::string, char> dummy = std::make_tuple(s,
'o');
356TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
363TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
370TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
372 Action<int(
int,
int,
int,
int,
int,
int)> a =
375 a.
Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
379TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
381 Action<std::string(
const char*,
const char*,
const char*,
const char*,
382 const char*,
const char*,
const char*)>
391TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
393 Action<std::string(
const char*,
const char*,
const char*,
const char*,
394 const char*,
const char*,
const char*,
const char*)>
403TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
405 Action<std::string(
const char*,
const char*,
const char*,
const char*,
406 const char*,
const char*,
const char*,
const char*,
416TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
418 Action<std::string(
const char*,
const char*,
const char*,
const char*,
419 const char*,
const char*,
const char*,
const char*,
420 const char*,
const char*)>
430TEST(InvokeMethodTest, MethodWithCompatibleType) {
432 Action<long(
int,
short,
char,
bool)> a =
450TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
451 const Action<int(
int)> a = ReturnArg<0>();
455TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
456 const Action<bool(
bool,
bool,
bool)> a = ReturnArg<0>();
460TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
461 const Action<std::string(
int,
int, std::string,
int)> a = ReturnArg<2>();
462 EXPECT_EQ(
"seven", a.
Perform(std::make_tuple(5, 6, std::string(
"seven"), 8)));
465TEST(SaveArgActionTest, WorksForSameType) {
467 const Action<void(
int n)> a1 = SaveArg<0>(&result);
468 a1.
Perform(std::make_tuple(5));
472TEST(SaveArgActionTest, WorksForCompatibleType) {
474 const Action<void(
bool,
char)> a1 = SaveArg<1>(&result);
475 a1.
Perform(std::make_tuple(
true,
'a'));
479TEST(SaveArgPointeeActionTest, WorksForSameType) {
482 const Action<void(
const int*)> a1 = SaveArgPointee<0>(&result);
487TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
490 const Action<void(
bool,
char*)> a1 = SaveArgPointee<1>(&result);
495TEST(SetArgRefereeActionTest, WorksForSameType) {
497 const Action<void(
int&)> a1 = SetArgReferee<0>(1);
502TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
504 const Action<void(
int,
int&)> a1 = SetArgReferee<1>(
'a');
509TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
511 const Action<void(
bool,
int,
int&,
const char*)> a1 = SetArgReferee<2>(
'a');
512 a1.
Perform(std::tuple<bool, int, int&, const char*>(
true, 0,
value,
"hi"));
521 : is_deleted_(is_deleted) {
523 *is_deleted_ =
false;
534TEST(DeleteArgActionTest, OneArg) {
535 bool is_deleted =
false;
539 a1.
Perform(std::make_tuple(t));
543TEST(DeleteArgActionTest, TenArgs) {
544 bool is_deleted =
false;
546 const Action<void(
bool,
int,
int,
const char*,
bool,
549 a1.
Perform(std::make_tuple(
true, 5, 6,
CharPtr(
"hi"),
false, 7, 8, 9, 10, t));
553#if GTEST_HAS_EXCEPTIONS
555TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
556 const Action<void(
int n)> a = Throw(
'a');
562TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
563 const Action<double(
char ch)> a = Throw(MyException());
564 EXPECT_THROW(a.Perform(std::make_tuple(
'0')), MyException);
567TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
568 const Action<double()> a = Throw(MyException());
569 EXPECT_THROW(a.Perform(std::make_tuple()), MyException);
575 virtual void Func() {}
578class MockObject :
public Object {
580 ~MockObject()
override {}
584TEST(ThrowActionTest, Times0) {
589 ON_CALL(m, Func()).WillByDefault([] {
throw "something"; });
603TEST(SetArrayArgumentTest, SetsTheNthArray) {
605 int numbers[] = { 1, 2, 3 };
612 a.
Perform(std::make_tuple(
true, pn, pch));
623 std::string letters =
"abc";
624 a = SetArrayArgument<2>(letters.begin(), letters.end());
625 std::fill_n(n, 4, 0);
626 std::fill_n(
ch, 4,
'\0');
627 a.
Perform(std::make_tuple(
true, pn, pch));
639TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
641 int numbers[] = { 1, 2, 3 };
646 a.
Perform(std::make_tuple(
true, pn));
655TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
657 char chars[] = { 97, 98, 99 };
660 int codes[4] = { 111, 222, 333, 444 };
662 a.
Perform(std::make_tuple(
true, pcodes));
670TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
671 using MyFunction = void(
bool, std::back_insert_iterator<std::string>);
672 std::string letters =
"abc";
676 a.
Perform(std::make_tuple(
true, back_inserter(s)));
680TEST(ReturnPointeeTest, Works) {
692TEST(InvokeArgumentTest, Function0) {
693 Action<int(
int,
int (*)())> a = InvokeArgument<1>();
698TEST(InvokeArgumentTest, Functor1) {
704TEST(InvokeArgumentTest, Function5) {
705 Action<int(
int (*)(
int,
int,
int,
int,
int))> a =
706 InvokeArgument<0>(10000, 2000, 300, 40, 5);
711TEST(InvokeArgumentTest, Functor5) {
713 InvokeArgument<0>(10000, 2000, 300, 40, 5);
718TEST(InvokeArgumentTest, Function6) {
719 Action<int(
int (*)(
int,
int,
int,
int,
int,
int))> a =
720 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
725TEST(InvokeArgumentTest, Functor6) {
727 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
732TEST(InvokeArgumentTest, Function7) {
733 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
734 const char*,
const char*,
const char*,
736 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7");
741TEST(InvokeArgumentTest, Function8) {
742 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
743 const char*,
const char*,
const char*,
744 const char*,
const char*))>
745 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8");
750TEST(InvokeArgumentTest, Function9) {
751 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
752 const char*,
const char*,
const char*,
753 const char*,
const char*,
const char*))>
754 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9");
759TEST(InvokeArgumentTest, Function10) {
760 Action<std::string(std::string(*)(
761 const char*,
const char*,
const char*,
const char*,
const char*,
762 const char*,
const char*,
const char*,
const char*,
const char*))>
763 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0");
768TEST(InvokeArgumentTest, ByPointerFunction) {
769 Action<
const char*(
const char* (*)(
const char* input,
short n))>
770 a = InvokeArgument<0>(
static_cast<const char*
>(
"Hi"),
Short(1));
776TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
777 Action<
const char*(
const char* (*)(
const char* input,
short n))>
778 a = InvokeArgument<0>(
"Hi",
Short(1));
783TEST(InvokeArgumentTest, ByConstReferenceFunction) {
784 Action<bool(
bool (*function)(
const std::string& s))> a =
785 InvokeArgument<0>(std::string(
"Hi"));
794TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
795 Action<bool(
bool (*)(
const double&
x))> a =
801 a = InvokeArgument<0>(
ByRef(
x));
817 Action<int(
int*,
int*)> a =
DoAll(SetArgPointee<0>(1),
818 SetArgPointee<1>(2),
Return(3));
828 Action<int(
int*,
int*,
char*)> a =
829 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
840 char a =
'\0', b =
'\0';
842 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
843 SetArgPointee<3>(
'b'),
Return(3));
854 char a =
'\0', b =
'\0', c =
'\0';
856 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
857 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'),
Return(3));
869 char a =
'\0', b =
'\0', c =
'\0', d =
'\0';
870 Action<int(
int*,
int*,
char*,
char*,
char*,
char*)>
action =
871 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
872 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'), SetArgPointee<5>(
'd'),
886 char a =
'\0', b =
'\0', c =
'\0', d =
'\0', e =
'\0';
887 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
890 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
891 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'),
892 SetArgPointee<5>(
'd'), SetArgPointee<6>(
'e'),
Return(3));
893 EXPECT_EQ(3,
action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e)));
906 char a =
'\0', b =
'\0', c =
'\0', d =
'\0', e =
'\0', f =
'\0';
907 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
909 action =
DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2),
910 SetArgPointee<2>(
'a'), SetArgPointee<3>(
'b'),
911 SetArgPointee<4>(
'c'), SetArgPointee<5>(
'd'),
912 SetArgPointee<6>(
'e'), SetArgPointee<7>(
'f'),
Return(3));
913 EXPECT_EQ(3,
action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f)));
927 char a =
'\0', b =
'\0', c =
'\0', d =
'\0';
928 char e =
'\0', f =
'\0', g =
'\0';
929 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
930 char*,
char*,
char*)>
932 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
933 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'),
934 SetArgPointee<5>(
'd'), SetArgPointee<6>(
'e'),
935 SetArgPointee<7>(
'f'), SetArgPointee<8>(
'g'),
Return(3));
937 3,
action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g)));
950 bool ran_first =
false;
952 DoAll([&] { ran_first =
true; }, [&] {
return ran_first; });
957 bool ran_first =
false;
958 Action<int(std::unique_ptr<int>)> a =
960 [](std::unique_ptr<int>
p) {
return *
p; });
965TEST(DoAllTest, ImplicitlyConvertsActionArguments) {
966 bool ran_first =
false;
969 Action<void(std::vector<int>)> first = [&] { ran_first =
true; };
970 Action<int(std::vector<int>)> a =
971 DoAll(first, [](std::vector<int> arg) {
return arg.front(); });
984#pragma warning(disable : 4100)
985#pragma warning(disable : 4503)
993TEST(ActionMacroTest, WorksWhenNotReferencingArguments) {
994 Action<double()> a1 = Return5();
997 Action<int(
double,
bool)> a2 = Return5();
1004TEST(ActionMacroTest, WorksWhenReturningVoid) {
1005 Action<void(
int,
int*)> a1 = IncrementArg1();
1007 a1.
Perform(std::make_tuple(5, &n));
1014 StaticAssertTypeEq<int*, arg2_type>();
1015 arg2_type temp = arg2;
1019TEST(ActionMacroTest, CanReferenceArgumentType) {
1020 Action<void(
int,
bool,
int*)> a1 = IncrementArg2();
1022 a1.
Perform(std::make_tuple(5,
false, &n));
1029 StaticAssertTypeEq<std::tuple<int, char, int*>, args_type>();
1030 args_type args_copy = args;
1031 return std::get<0>(args_copy) + std::get<1>(args_copy);
1034TEST(ActionMacroTest, CanReferenceArgumentTuple) {
1035 Action<int(
int,
char,
int*)> a1 = Sum2();
1044int Dummy(
bool flag) {
return flag ? 1 : 0; }
1049 StaticAssertTypeEq<int(bool), function_type>();
1050 function_type* fp = &Dummy;
1054TEST(ActionMacroTest, CanReferenceMockFunctionType) {
1055 Action<int(
bool)> a1 = InvokeDummy();
1063 StaticAssertTypeEq<int, return_type>();
1064 return_type result = Dummy(
true);
1068TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) {
1069 Action<int(
bool)> a1 = InvokeDummy2();
1076 StaticAssertTypeEq<const bool&, arg1_type>();
1080TEST(ActionMacroTest, WorksForConstReferenceArg) {
1081 Action<
const bool*(int,
const bool&)> a = ReturnAddrOfConstBoolReferenceArg();
1082 const bool b =
false;
1083 EXPECT_EQ(&b, a.Perform(std::tuple<int, const bool&>(0, b)));
1088 StaticAssertTypeEq<int&, arg0_type>();
1092TEST(ActionMacroTest, WorksForNonConstReferenceArg) {
1093 Action<
int*(
int&, bool, int)> a = ReturnAddrOfIntReferenceArg();
1095 EXPECT_EQ(&n, a.Perform(std::tuple<int&, bool, int>(n,
true, 1)));
1099namespace action_test {
1103TEST(ActionMacroTest, WorksInNamespace) {
1104 Action<int(
int,
int)> a1 = action_test::Sum();
1112TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) {
1113 Action<int(
int)> a1 = PlusTwo();
1116 Action<double(
float,
void*)> a2 = PlusTwo();
1124TEST(ActionPMacroTest, DefinesParameterizedAction) {
1125 Action<int(
int m,
bool t)> a1 = Plus(9);
1132 arg0_type t1 = arg0;
1137TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
1138 Action<int(
char m,
bool t)> a1 = TypedPlus(9);
1144TEST(ActionPMacroTest, WorksInCompatibleMockFunction) {
1145 Action<std::string(
const std::string& s)> a1 = Plus(
"tail");
1146 const std::string re =
"re";
1147 std::tuple<const std::string> dummy = std::make_tuple(re);
1154ACTION(OverloadedAction) {
return arg0 ? arg1 :
"hello"; }
1157 return arg0 ? arg1 : default_value;
1161 return arg0 ? true_value : false_value;
1164TEST(ActionMacroTest, CanDefineOverloadedActions) {
1165 using MyAction =
Action<
const char*(bool,
const char*)>;
1167 const MyAction a1 = OverloadedAction();
1171 const MyAction a2 = OverloadedAction(
"hi");
1175 const MyAction a3 = OverloadedAction(
"hi",
"you");
1184TEST(ActionPnMacroTest, WorksFor3Parameters) {
1185 Action<double(
int m,
bool t)> a1 = Plus(100, 20, 3.4);
1188 Action<std::string(
const std::string& s)> a2 = Plus(
"tail",
"-",
">");
1189 const std::string re =
"re";
1190 std::tuple<const std::string> dummy = std::make_tuple(re);
1194ACTION_P4(Plus, p0, p1, p2, p3) {
return arg0 + p0 + p1 + p2 + p3; }
1196TEST(ActionPnMacroTest, WorksFor4Parameters) {
1197 Action<int(
int)> a1 = Plus(1, 2, 3, 4);
1201ACTION_P5(Plus, p0, p1, p2, p3, p4) {
return arg0 + p0 + p1 + p2 + p3 + p4; }
1203TEST(ActionPnMacroTest, WorksFor5Parameters) {
1204 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5);
1209 return arg0 + p0 + p1 + p2 + p3 + p4 + p5;
1212TEST(ActionPnMacroTest, WorksFor6Parameters) {
1213 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6);
1218 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6;
1221TEST(ActionPnMacroTest, WorksFor7Parameters) {
1222 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7);
1223 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a1.
Perform(std::make_tuple(10)));
1227 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7;
1230TEST(ActionPnMacroTest, WorksFor8Parameters) {
1231 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8);
1232 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8,
1233 a1.
Perform(std::make_tuple(10)));
1237 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
1240TEST(ActionPnMacroTest, WorksFor9Parameters) {
1241 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9);
1242 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9,
1243 a1.
Perform(std::make_tuple(10)));
1246ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
1247 arg0_type t0 = arg0;
1248 last_param_type t9 = last_param;
1249 return t0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + t9;
1252TEST(ActionPnMacroTest, WorksFor10Parameters) {
1253 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
1254 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10,
1255 a1.
Perform(std::make_tuple(10)));
1262 std::string prefix_str(prefix);
1263 char suffix_char =
static_cast<char>(suffix);
1264 return prefix_str + arg0 + suffix_char;
1267TEST(ActionPnMacroTest, SimpleTypePromotion) {
1268 Action<std::string(
const char*)> no_promo =
1269 PadArgument(std::string(
"foo"),
'r');
1270 Action<std::string(
const char*)> promo =
1271 PadArgument(
"foo",
static_cast<int>(
'r'));
1282 std::stringstream ss;
1292template <
typename T1,
typename T2>
1296ConcatImplActionP3<std::string, T1, T2>
Concat(
const std::string& a,
T1 b,
1303 return ConcatImpl(a, b, c);
1308 return ConcatImpl<std::string, T1, T2>(a, b, c);
1314template <
typename T1,
typename T2>
1316 return ConcatImpl(a, b, c);
1319TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) {
1320 Action<
const std::string()> a1 =
Concat(
"Hello",
"1", 2);
1333TEST(ActionPnMacroTest, TypesAreCorrect) {
1335 DoFooAction a0 = DoFoo();
1338 DoFooActionP<int> a1 = DoFoo(1);
1342 DoFooActionP2<int, char> a2 = DoFoo(1,
'2');
1343 PlusActionP3<int, int, char> a3 = Plus(1, 2,
'3');
1344 PlusActionP4<int, int, int, char> a4 = Plus(1, 2, 3,
'4');
1345 PlusActionP5<int, int, int, int, char> a5 = Plus(1, 2, 3, 4,
'5');
1346 PlusActionP6<int, int, int, int, int, char> a6 = Plus(1, 2, 3, 4, 5,
'6');
1347 PlusActionP7<int, int, int, int, int, int, char> a7 =
1348 Plus(1, 2, 3, 4, 5, 6,
'7');
1349 PlusActionP8<int, int, int, int, int, int, int, char> a8 =
1350 Plus(1, 2, 3, 4, 5, 6, 7,
'8');
1351 PlusActionP9<int, int, int, int, int, int, int, int, char> a9 =
1352 Plus(1, 2, 3, 4, 5, 6, 7, 8,
'9');
1353 PlusActionP10<int, int, int, int, int, int, int, int, int, char> a10 =
1354 Plus(1, 2, 3, 4, 5, 6, 7, 8, 9,
'0');
1376ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
1377 return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
1380TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) {
1381 int x = 1,
y = 2,
z = 3;
1382 const std::tuple<> empty = std::make_tuple();
1384 Action<int()> a = Plus1<int&>(
x);
1387 a = Plus2<const int&, int&>(
x,
y);
1390 a = Plus3<int&, const int&, int&>(
x,
y,
z);
1393 int n[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1394 a = Plus10<
const int&,
int&,
const int&,
int&,
const int&,
int&,
const int&,
1395 int&,
const int&,
int&>(n[0], n[1], n[2], n[3], n[4], n[5], n[6],
1403 int a8,
int a9,
int a10)
1404 :
value_(a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10) {}
1410 AND_0_VALUE_PARAMS()) {
1414TEST(ActionTemplateTest, WorksWithoutValueParam) {
1415 const Action<
int*()> a = CreateNew<int>();
1416 int*
p = a.Perform(std::make_tuple());
1422 AND_1_VALUE_PARAMS(a0)) {
1426TEST(ActionTemplateTest, WorksWithValueParams) {
1427 const Action<
int*()> a = CreateNew<int>(42);
1428 int*
p = a.Perform(std::make_tuple());
1435 AND_0_VALUE_PARAMS()) {
1436 delete std::get<k>(args);
1449TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
1454 a.
Perform(std::make_tuple(&n, resetter));
1460 HAS_1_TEMPLATE_PARAMS(template <typename Pointee>
class,
1462 AND_1_VALUE_PARAMS(pointee)) {
1463 return Pointer<pointee_type>(
new pointee_type(pointee));
1466TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) {
1468 ReturnSmartPointer<std::shared_ptr>(42);
1469 std::shared_ptr<int>
p = a.Perform(std::make_tuple());
1474template <
typename T1,
typename T2,
typename T3,
int k4,
bool k5,
1475 unsigned int k6,
typename T7,
typename T8,
typename T9>
1483 HAS_10_TEMPLATE_PARAMS(
typename,
T1,
typename,
T2,
typename,
T3,
1484 int, k4,
bool, k5,
unsigned int, k6,
1485 class, T7,
class, T8,
class, T9,
1486 template <typename T>
class, T10),
1487 AND_1_VALUE_PARAMS(
value)) {
1491TEST(ActionTemplateTest, WorksFor10TemplateParameters) {
1493 char, unsigned,
int>;
1494 const Action<Giant()> a = ReturnGiant<int, bool, double, 5,
true, 6, char,
1495 unsigned, int, std::shared_ptr>(42);
1496 Giant giant = a.
Perform(std::make_tuple());
1502 AND_10_VALUE_PARAMS(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)) {
1503 return static_cast<Number
>(v1) + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10;
1506TEST(ActionTemplateTest, WorksFor10ValueParameters) {
1507 const Action<int()> a = ReturnSum<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
1519 AND_2_VALUE_PARAMS(v1, v2)) {
1520 return static_cast<Number
>(v1) + v2;
1524 AND_3_VALUE_PARAMS(v1, v2, v3)) {
1525 return static_cast<Number
>(v1) + v2 + v3;
1529 AND_4_VALUE_PARAMS(v1, v2, v3, v4)) {
1530 return static_cast<Number
>(v1) + v2 + v3 + v4 + k;
1533TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
1534 const Action<int()> a0 = ReturnSum();
1535 const Action<int()> a1 = ReturnSum(1);
1536 const Action<int()> a2 = ReturnSum<int>(1, 2);
1537 const Action<int()> a3 = ReturnSum<int>(1, 2, 3);
1538 const Action<int()> a4 = ReturnSum<int, 10000>(2000, 300, 40, 5);
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)
#define EXPECT_EQ(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_FALSE(condition)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_INTENTIONAL_CONST_COND_POP_()
internal::DeleteArgAction< k > DeleteArg()
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
internal::SaveArgAction< k, Ptr > SaveArg(Ptr pointer)
internal::SaveArgPointeeAction< k, Ptr > SaveArgPointee(Ptr pointer)
internal::SetArgRefereeAction< k, typename std::decay< T >::type > SetArgReferee(T &&value)
internal::ReturnPointeeAction< Ptr > ReturnPointee(Ptr pointer)
inline ::std::reference_wrapper< T > ByRef(T &l_value)
internal::DoAllAction< typename std::decay< Action >::type... > DoAll(Action &&... action)
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
internal::ReturnArgAction< k > ReturnArg()
internal::WithArgsAction< typename std::decay< InnerAction >::type, k > WithArg(InnerAction &&action)
internal::ReturnAction< R > Return(R value)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
int SumOf6(int a, int b, int c, int d, int e, int f)
const char * CharPtr(const char *s)
std::string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
ACTION_P4(Plus, p0, p1, p2, p3)
std::string Concat9(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, const char *s9)
ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6)
bool ByConstRef(const std::string &s)
int SumOf5(int a, int b, int c, int d, int e)
int SumOf4(int a, int b, int c, int d)
std::string Concat10(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, const char *s9, const char *s10)
ACTION_TEMPLATE(CreateNew, HAS_1_TEMPLATE_PARAMS(typename, T), AND_0_VALUE_PARAMS())
TEST(InvokeTest, Nullary)
ACTION_P5(Plus, p0, p1, p2, p3, p4)
ConcatImplActionP3< std::string, T1, T2 > Concat(const std::string &a, T1 b, T2 c)
std::string Concat8(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8)
int SumOfFirst2(int a, int b, Unused, Unused)
int Ternary(int x, char y, short z)
ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8)
ACTION_P2(OverloadedAction, true_value, false_value)
const char * Binary(const char *input, short n)
bool ReferencesGlobalDouble(const double &x)
ACTION_P6(Plus, p0, p1, p2, p3, p4, p5)
ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param)
ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7)
Result Perform(ArgumentTuple args) const
int operator()(int a, int b, int c, int d, int e)
int operator()(int a, int b, int c, int d, int e, int f)
std::string Concat8(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8)
int SumOf6(int a, int b, int c, int d, int e, int f)
int SumOf5(int a, int b, int c, int d, int e)
std::string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
int SumOf4(int a, int b, int c, int d) const
std::string Binary(const std::string &str, char c) const
std::string Concat9(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, const char *s9)
int SumOfLast2(Unused, Unused, int a, int b) const
std::string Concat10(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, const char *s9, const char *s10)
int Ternary(int x, bool y, char z)
DeletionTester(bool *is_deleted)
TenArgConstructorClass(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10)
BoolResetter(bool *value)
GiantTemplate(int a_value)