52namespace gmock_more_actions_test {
69inline short Short(
short n) {
return n; }
79bool ByConstRef(
const std::string& s) {
return s ==
"Hi"; }
88const char*
Binary(
const char* input,
short n) {
return input + n; }
92int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c + d; }
96int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
100 return a + b + c + d + e;
104int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
105 return a + b + c + d + e + f;
110 return a + b + c + d + e + f;
114std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
115 const char* s4,
const char* s5,
const char* s6,
117 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
120std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
121 const char* s4,
const char* s5,
const char* s6,
122 const char* s7,
const char* s8) {
123 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
126std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
127 const char* s4,
const char* s5,
const char* s6,
128 const char* s7,
const char* s8,
const char* s9) {
129 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
132std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
133 const char* s4,
const char* s5,
const char* s6,
134 const char* s7,
const char* s8,
const char* s9,
136 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
145 short Unary(
long x) {
return static_cast<short>(value_ +
x); }
147 std::string
Binary(
const std::string& str,
char c)
const {
return str + c; }
151 int SumOf4(
int a,
int b,
int c,
int d)
const {
152 return a + b + c + d + value_;
157 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
159 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
160 return a + b + c + d + e + f;
163 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
164 const char* s4,
const char* s5,
const char* s6,
166 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
169 std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
170 const char* s4,
const char* s5,
const char* s6,
171 const char* s7,
const char* s8) {
172 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
175 std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
176 const char* s4,
const char* s5,
const char* s6,
177 const char* s7,
const char* s8,
const char* s9) {
178 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
181 std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
182 const char* s4,
const char* s5,
const char* s6,
183 const char* s7,
const char* s8,
const char* s9,
185 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
195 EXPECT_EQ(1, a.Perform(std::make_tuple()));
207 Action<
const char*(
const char*, short)> a = Invoke(
Binary);
208 const char*
p =
"Hello";
219TEST(InvokeTest, FunctionThatTakes4Arguments) {
221 EXPECT_EQ(1234, a.Perform(std::make_tuple(1000, 200, 30, 4)));
225TEST(InvokeTest, FunctionThatTakes5Arguments) {
226 Action<int(
int,
int,
int,
int,
int)> a = Invoke(
SumOf5);
227 EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
231TEST(InvokeTest, FunctionThatTakes6Arguments) {
232 Action<int(
int,
int,
int,
int,
int,
int)> a = Invoke(
SumOf6);
234 a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
239inline const char*
CharPtr(
const char* s) {
return s; }
242TEST(InvokeTest, FunctionThatTakes7Arguments) {
243 Action<std::string(
const char*,
const char*,
const char*,
const char*,
244 const char*,
const char*,
const char*)>
253TEST(InvokeTest, FunctionThatTakes8Arguments) {
254 Action<std::string(
const char*,
const char*,
const char*,
const char*,
255 const char*,
const char*,
const char*,
const char*)>
264TEST(InvokeTest, FunctionThatTakes9Arguments) {
265 Action<std::string(
const char*,
const char*,
const char*,
const char*,
266 const char*,
const char*,
const char*,
const char*,
269 EXPECT_EQ(
"123456789", a.Perform(std::make_tuple(
276TEST(InvokeTest, FunctionThatTakes10Arguments) {
277 Action<std::string(
const char*,
const char*,
const char*,
const char*,
278 const char*,
const char*,
const char*,
const char*,
279 const char*,
const char*)>
289TEST(InvokeTest, FunctionWithUnusedParameters) {
291 std::tuple<int, int, double, std::string> dummy =
292 std::make_tuple(10, 2, 5.6, std::string(
"hi"));
297 23, a2.Perform(std::make_tuple(20, 3,
true,
static_cast<int*
>(
nullptr))));
301TEST(InvokeTest, MethodWithUnusedParameters) {
303 Action<int(std::string,
bool,
int,
int)> a1 = Invoke(&
foo, &Foo::SumOfLast2);
306 Action<int(
char,
double,
int,
int)> a2 = Invoke(&
foo, &Foo::SumOfLast2);
307 EXPECT_EQ(23, a2.Perform(std::make_tuple(
'a', 2.5, 20, 3)));
312 Action<long(
long,
int)> a = Invoke(plus<long>());
313 EXPECT_EQ(3L, a.Perform(std::make_tuple(1, 2)));
317TEST(InvokeTest, FunctionWithCompatibleType) {
318 Action<long(
int,
short,
char,
bool)> a = Invoke(
SumOf4);
325TEST(InvokeMethodTest, Nullary) {
327 Action<int()> a = Invoke(&
foo, &Foo::Nullary);
328 EXPECT_EQ(123, a.Perform(std::make_tuple()));
334 Action<short(
long)> a = Invoke(&
foo, &Foo::Unary);
335 EXPECT_EQ(4123, a.Perform(std::make_tuple(4000)));
339TEST(InvokeMethodTest, Binary) {
341 Action<std::string(
const std::string&,
char)> a = Invoke(&
foo, &Foo::Binary);
342 std::string s(
"Hell");
343 std::tuple<std::string, char> dummy = std::make_tuple(s,
'o');
348TEST(InvokeMethodTest, Ternary) {
350 Action<int(
int,
bool,
char)> a = Invoke(&
foo, &Foo::Ternary);
351 EXPECT_EQ(1124, a.Perform(std::make_tuple(1000,
true,
Char(1))));
355TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
357 Action<int(
int,
int,
int,
int)> a = Invoke(&
foo, &Foo::SumOf4);
358 EXPECT_EQ(1357, a.Perform(std::make_tuple(1000, 200, 30, 4)));
362TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
364 Action<int(
int,
int,
int,
int,
int)> a =
365 Invoke(&
foo, &Foo::SumOf5);
366 EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
370TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
372 Action<int(
int,
int,
int,
int,
int,
int)> a =
373 Invoke(&
foo, &Foo::SumOf6);
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*)>
383 a = Invoke(&
foo, &Foo::Concat7);
391TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
393 Action<std::string(
const char*,
const char*,
const char*,
const char*,
394 const char*,
const char*,
const char*,
const char*)>
395 a = Invoke(&
foo, &Foo::Concat8);
403TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
405 Action<std::string(
const char*,
const char*,
const char*,
const char*,
406 const char*,
const char*,
const char*,
const char*,
408 a = Invoke(&
foo, &Foo::Concat9);
409 EXPECT_EQ(
"123456789", a.Perform(std::make_tuple(
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*)>
421 a = Invoke(&
foo, &Foo::Concat10);
430TEST(InvokeMethodTest, MethodWithCompatibleType) {
432 Action<long(
int,
short,
char,
bool)> a =
433 Invoke(&
foo, &Foo::SumOf4);
440 EXPECT_EQ(1, a.Perform(std::make_tuple(2)));
445 Action<bool(
double x,
int n)> b = WithArg<1>(Invoke(
Unary));
450TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
451 const Action<int(
int)> a = ReturnArg<0>();
452 EXPECT_EQ(5, a.Perform(std::make_tuple(5)));
455TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
456 const Action<bool(
bool,
bool,
bool)> a = ReturnArg<0>();
457 EXPECT_TRUE(a.Perform(std::make_tuple(
true,
false,
false)));
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(ReturnArgActionTest, WorksForNonConstRefArg0) {
466 const Action<std::string&(std::string&)> a = ReturnArg<0>();
467 std::string s =
"12345";
468 EXPECT_EQ(&s, &a.Perform(std::forward_as_tuple(s)));
471TEST(SaveArgActionTest, WorksForSameType) {
473 const Action<void(
int n)> a1 = SaveArg<0>(&result);
474 a1.Perform(std::make_tuple(5));
478TEST(SaveArgActionTest, WorksForCompatibleType) {
480 const Action<void(
bool,
char)> a1 = SaveArg<1>(&result);
481 a1.Perform(std::make_tuple(
true,
'a'));
485TEST(SaveArgPointeeActionTest, WorksForSameType) {
488 const Action<void(
const int*)> a1 = SaveArgPointee<0>(&result);
489 a1.Perform(std::make_tuple(&
value));
493TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
496 const Action<void(
bool,
char*)> a1 = SaveArgPointee<1>(&result);
497 a1.Perform(std::make_tuple(
true, &
value));
501TEST(SetArgRefereeActionTest, WorksForSameType) {
503 const Action<void(
int&)> a1 = SetArgReferee<0>(1);
504 a1.Perform(std::tuple<int&>(
value));
508TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
510 const Action<void(
int,
int&)> a1 = SetArgReferee<1>(
'a');
511 a1.Perform(std::tuple<int, int&>(0,
value));
515TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
517 const Action<void(
bool,
int,
int&,
const char*)> a1 = SetArgReferee<2>(
'a');
518 a1.Perform(std::tuple<bool, int, int&, const char*>(
true, 0,
value,
"hi"));
528 *is_deleted_ =
false;
537TEST(DeleteArgActionTest, OneArg) {
538 bool is_deleted =
false;
542 a1.Perform(std::make_tuple(t));
546TEST(DeleteArgActionTest, TenArgs) {
547 bool is_deleted =
false;
549 const Action<void(
bool,
int,
int,
const char*,
bool,
int,
int,
int,
int,
553 a1.Perform(std::make_tuple(
true, 5, 6,
CharPtr(
"hi"),
false, 7, 8, 9, 10, t));
557#if GTEST_HAS_EXCEPTIONS
559TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
560 const Action<void(
int n)> a = Throw(
'a');
566TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
567 const Action<double(
char ch)> a = Throw(MyException());
568 EXPECT_THROW(a.Perform(std::make_tuple(
'0')), MyException);
571TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
572 const Action<double()> a = Throw(MyException());
573 EXPECT_THROW(a.Perform(std::make_tuple()), MyException);
579 virtual void Func() {}
582class MockObject :
public Object {
584 ~MockObject()
override {}
588TEST(ThrowActionTest, Times0) {
593 ON_CALL(m, Func()).WillByDefault([] {
throw "something"; });
607TEST(SetArrayArgumentTest, SetsTheNthArray) {
608 using MyFunction = void(
bool,
int*,
char*);
609 int numbers[] = {1, 2, 3};
616 a.Perform(std::make_tuple(
true, pn, pch));
627 std::string letters =
"abc";
628 a = SetArrayArgument<2>(letters.begin(), letters.end());
629 std::fill_n(n, 4, 0);
630 std::fill_n(
ch, 4,
'\0');
631 a.Perform(std::make_tuple(
true, pn, pch));
643TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
644 using MyFunction = void(
bool,
int*);
645 int numbers[] = {1, 2, 3};
650 a.Perform(std::make_tuple(
true, pn));
659TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
660 using MyFunction = void(
bool,
int*);
661 char chars[] = {97, 98, 99};
664 int codes[4] = {111, 222, 333, 444};
666 a.Perform(std::make_tuple(
true, pcodes));
674TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
675 using MyFunction = void(
bool, std::back_insert_iterator<std::string>);
676 std::string letters =
"abc";
680 a.Perform(std::make_tuple(
true, std::back_inserter(s)));
684TEST(ReturnPointeeTest, Works) {
686 const Action<int()> a = ReturnPointee(&n);
687 EXPECT_EQ(42, a.Perform(std::make_tuple()));
690 EXPECT_EQ(43, a.Perform(std::make_tuple()));
696TEST(InvokeArgumentTest, Function0) {
697 Action<int(
int,
int (*)())> a = InvokeArgument<1>();
702TEST(InvokeArgumentTest, Functor1) {
708TEST(InvokeArgumentTest, Function5) {
709 Action<int(
int (*)(
int,
int,
int,
int,
int))> a =
710 InvokeArgument<0>(10000, 2000, 300, 40, 5);
715TEST(InvokeArgumentTest, Functor5) {
717 InvokeArgument<0>(10000, 2000, 300, 40, 5);
722TEST(InvokeArgumentTest, Function6) {
723 Action<int(
int (*)(
int,
int,
int,
int,
int,
int))> a =
724 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
729TEST(InvokeArgumentTest, Functor6) {
731 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
736TEST(InvokeArgumentTest, Function7) {
737 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
738 const char*,
const char*,
const char*,
740 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7");
745TEST(InvokeArgumentTest, Function8) {
746 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
747 const char*,
const char*,
const char*,
748 const char*,
const char*))>
749 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8");
754TEST(InvokeArgumentTest, Function9) {
755 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
756 const char*,
const char*,
const char*,
757 const char*,
const char*,
const char*))>
758 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9");
763TEST(InvokeArgumentTest, Function10) {
764 Action<std::string(std::string(*)(
765 const char*,
const char*,
const char*,
const char*,
const char*,
766 const char*,
const char*,
const char*,
const char*,
const char*))>
767 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0");
772TEST(InvokeArgumentTest, ByPointerFunction) {
773 Action<
const char*(
const char* (*)(
const char* input,
short n))>
774 a = InvokeArgument<0>(
static_cast<const char*
>(
"Hi"),
Short(1));
780TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
781 Action<
const char*(
const char* (*)(
const char* input,
short n))>
782 a = InvokeArgument<0>(
"Hi",
Short(1));
787TEST(InvokeArgumentTest, ByConstReferenceFunction) {
788 Action<bool(
bool (*function)(
const std::string& s))> a =
789 InvokeArgument<0>(std::string(
"Hi"));
798TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
799 Action<bool(
bool (*)(
const double&
x))> a =
805 a = InvokeArgument<0>(
ByRef(
x));
812 Action<int(
int*)> a = DoAll(SetArgPointee<0>(1),
814 EXPECT_EQ(2, a.Perform(std::make_tuple(&n)));
821 Action<int(
int*,
int*)> a = DoAll(SetArgPointee<0>(1),
822 SetArgPointee<1>(2), Return(3));
823 EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n)));
832 Action<int(
int*,
int*,
char*)> a =
833 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
835 EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n, &
ch)));
844 char a =
'\0', b =
'\0';
845 Action<int(
int*,
int*,
char*,
char*)> action =
846 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
847 SetArgPointee<3>(
'b'), Return(3));
848 EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b)));
858 char a =
'\0', b =
'\0', c =
'\0';
859 Action<int(
int*,
int*,
char*,
char*,
char*)> action =
860 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
861 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'), Return(3));
862 EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c)));
873 char a =
'\0', b =
'\0', c =
'\0', d =
'\0';
874 Action<int(
int*,
int*,
char*,
char*,
char*,
char*)> action =
875 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
876 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'), SetArgPointee<5>(
'd'),
878 EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d)));
890 char a =
'\0', b =
'\0', c =
'\0', d =
'\0', e =
'\0';
891 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
894 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
895 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'),
896 SetArgPointee<5>(
'd'), SetArgPointee<6>(
'e'), Return(3));
897 EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e)));
910 char a =
'\0', b =
'\0', c =
'\0', d =
'\0', e =
'\0', f =
'\0';
911 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
913 action = DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2),
914 SetArgPointee<2>(
'a'), SetArgPointee<3>(
'b'),
915 SetArgPointee<4>(
'c'), SetArgPointee<5>(
'd'),
916 SetArgPointee<6>(
'e'), SetArgPointee<7>(
'f'), Return(3));
917 EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f)));
931 char a =
'\0', b =
'\0', c =
'\0', d =
'\0';
932 char e =
'\0', f =
'\0', g =
'\0';
933 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
934 char*,
char*,
char*)>
936 DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2), SetArgPointee<2>(
'a'),
937 SetArgPointee<3>(
'b'), SetArgPointee<4>(
'c'),
938 SetArgPointee<5>(
'd'), SetArgPointee<6>(
'e'),
939 SetArgPointee<7>(
'f'), SetArgPointee<8>(
'g'), Return(3));
941 3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g)));
954 bool ran_first =
false;
956 DoAll([&] { ran_first =
true; }, [&] {
return ran_first; });
961 bool ran_first =
false;
962 Action<int(std::unique_ptr<int>)> a =
963 DoAll(InvokeWithoutArgs([&] { ran_first =
true; }),
964 [](std::unique_ptr<int>
p) {
return *
p; });
965 EXPECT_EQ(7, a.Perform(std::make_tuple(std::unique_ptr<int>(
new int(7)))));
969TEST(DoAllTest, ImplicitlyConvertsActionArguments) {
970 bool ran_first =
false;
973 Action<void(std::vector<int>)> first = [&] { ran_first =
true; };
974 Action<int(std::vector<int>)> a =
975 DoAll(first, [](std::vector<int> arg) {
return arg.front(); });
976 EXPECT_EQ(7, a.Perform(std::make_tuple(std::vector<int>{7})));
993TEST(ActionMacroTest, WorksWhenNotReferencingArguments) {
994 Action<double()> a1 = Return5();
997 Action<int(
double,
bool)> a2 = Return5();
998 EXPECT_EQ(5, a2.Perform(std::make_tuple(1,
true)));
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();
1037 EXPECT_EQ(11, a1.Perform(std::make_tuple(5,
Char(6), &dummy)));
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();
1056 EXPECT_EQ(1, a1.Perform(std::make_tuple(
true)));
1057 EXPECT_EQ(1, a1.Perform(std::make_tuple(
false)));
1063 StaticAssertTypeEq<int, return_type>();
1064 return_type result = Dummy(
true);
1068TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) {
1069 Action<int(
bool)> a1 = InvokeDummy2();
1070 EXPECT_EQ(1, a1.Perform(std::make_tuple(
true)));
1071 EXPECT_EQ(1, a1.Perform(std::make_tuple(
false)));
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();
1105 EXPECT_EQ(3, a1.Perform(std::make_tuple(1, 2)));
1112TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) {
1113 Action<int(
int)> a1 = PlusTwo();
1114 EXPECT_EQ(4, a1.Perform(std::make_tuple(2)));
1116 Action<double(
float,
void*)> a2 = PlusTwo();
1124TEST(ActionPMacroTest, DefinesParameterizedAction) {
1125 Action<int(
int m,
bool t)> a1 = Plus(9);
1126 EXPECT_EQ(10, a1.Perform(std::make_tuple(1,
true)));
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);
1191 EXPECT_EQ(
"retail->", a2.Perform(dummy));
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);
1198 EXPECT_EQ(10 + 1 + 2 + 3 + 4, a1.Perform(std::make_tuple(10)));
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);
1205 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5, a1.Perform(std::make_tuple(10)));
1209 return arg0 + p0 + p1 + p2 + p3 + p4 + p5;
1212TEST(ActionPnMacroTest, WorksFor6Parameters) {
1213 Action<int(
int)> a1 = Plus(1, 2, 3, 4, 5, 6);
1214 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6, a1.Perform(std::make_tuple(10)));
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>
1315ConcatImplActionP3<T1, int, T2>
Concat(T1 a,
int b, T2 c) {
1316 return ConcatImpl(a, b, c);
1319TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) {
1320 Action<
const std::string()> a1 =
Concat(
"Hello",
"1", 2);
1321 EXPECT_EQ(
"Hello12", a1.Perform(std::make_tuple()));
1324 EXPECT_EQ(
"123", a1.Perform(std::make_tuple()));
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);
1508 EXPECT_EQ(55, a.Perform(std::make_tuple()));
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);
1539 EXPECT_EQ(0, a0.Perform(std::make_tuple()));
1540 EXPECT_EQ(1, a1.Perform(std::make_tuple()));
1541 EXPECT_EQ(3, a2.Perform(std::make_tuple()));
1542 EXPECT_EQ(6, a3.Perform(std::make_tuple()));
1543 EXPECT_EQ(12345, a4.Perform(std::make_tuple()));
Definition gmock-actions.h:717
Definition gmock-more-actions_test.cc:1440
BoolResetter(bool *value)
Definition gmock-more-actions_test.cc:1442
~BoolResetter()
Definition gmock-more-actions_test.cc:1443
Definition gmock-more-actions_test.cc:524
DeletionTester(bool *is_deleted)
Definition gmock-more-actions_test.cc:526
~DeletionTester()
Definition gmock-more-actions_test.cc:531
Definition gmock-more-actions_test.cc:139
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)
Definition gmock-more-actions_test.cc:169
int SumOf6(int a, int b, int c, int d, int e, int f)
Definition gmock-more-actions_test.cc:159
int SumOf5(int a, int b, int c, int d, int e)
Definition gmock-more-actions_test.cc:157
std::string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
Definition gmock-more-actions_test.cc:163
short Unary(long x)
Definition gmock-more-actions_test.cc:145
int SumOf4(int a, int b, int c, int d) const
Definition gmock-more-actions_test.cc:151
std::string Binary(const std::string &str, char c) const
Definition gmock-more-actions_test.cc:147
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)
Definition gmock-more-actions_test.cc:175
int SumOfLast2(Unused, Unused, int a, int b) const
Definition gmock-more-actions_test.cc:155
Foo()
Definition gmock-more-actions_test.cc:141
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)
Definition gmock-more-actions_test.cc:181
int Nullary() const
Definition gmock-more-actions_test.cc:143
int Ternary(int x, bool y, char z)
Definition gmock-more-actions_test.cc:149
Definition gmock-more-actions_test.cc:1400
int value_
Definition gmock-more-actions_test.cc:1405
TenArgConstructorClass(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10)
Definition gmock-more-actions_test.cc:1402
Definition gtest-internal.h:127
pRC::Float<> T
Definition externs_nonTT.hpp:1
#define ACTION_P9(name,...)
Definition gmock-actions.h:2287
#define ACTION_P5(name,...)
Definition gmock-actions.h:2275
#define ACTION_P8(name,...)
Definition gmock-actions.h:2284
#define ACTION_P7(name,...)
Definition gmock-actions.h:2281
#define ACTION_P3(name,...)
Definition gmock-actions.h:2269
#define ACTION(name)
Definition gmock-actions.h:2238
#define ACTION_P6(name,...)
Definition gmock-actions.h:2278
#define ACTION_P10(name,...)
Definition gmock-actions.h:2290
#define ACTION_P2(name,...)
Definition gmock-actions.h:2266
#define ACTION_P4(name,...)
Definition gmock-actions.h:2272
#define ACTION_P(name,...)
Definition gmock-actions.h:2263
int value
Definition gmock-actions_test.cc:1714
#define MOCK_METHOD(...)
Definition gmock-function-mocker.h:111
Uncopyable z
Definition gmock-matchers-containers_test.cc:378
const double y
Definition gmock-matchers-containers_test.cc:377
int x
Definition gmock-matchers-containers_test.cc:376
const char * p
Definition gmock-matchers-containers_test.cc:379
char ch
Definition gmock-matchers-containers_test.cc:384
#define ACTION_TEMPLATE(name, template_params, value_params)
Definition gmock-more-actions.h:515
#define EXPECT_CALL(obj, call)
Definition gmock-spec-builders.h:2145
#define ON_CALL(obj, call)
Definition gmock-spec-builders.h:2142
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
Definition gtest-port.h:787
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition gtest-port.h:360
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition gtest-port.h:361
#define GTEST_INTENTIONAL_CONST_COND_POP_()
Definition gtest-port.h:789
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:217
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1868
#define EXPECT_THROW(statement, expected_exception)
Definition gtest.h:1775
#define EXPECT_DOUBLE_EQ(val1, val2)
Definition gtest.h:1973
#define TEST(test_suite_name, test_name)
Definition gtest.h:2176
#define EXPECT_TRUE(condition)
Definition gtest.h:1807
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1937
#define EXPECT_FALSE(condition)
Definition gtest.h:1811
Definition googletest-output-test_.cc:471
short Short(short n)
Definition gmock-more-actions_test.cc:69
int SumOf6(int a, int b, int c, int d, int e, int f)
Definition gmock-more-actions_test.cc:104
const char * CharPtr(const char *s)
Definition gmock-more-actions_test.cc:239
std::string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
Definition gmock-more-actions_test.cc:114
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)
Definition gmock-more-actions_test.cc:126
bool ByConstRef(const std::string &s)
Definition gmock-more-actions_test.cc:79
int SumOf5(int a, int b, int c, int d, int e)
Definition gmock-more-actions_test.cc:96
int SumOf4(int a, int b, int c, int d)
Definition gmock-more-actions_test.cc:92
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)
Definition gmock-more-actions_test.cc:132
const double g_double
Definition gmock-more-actions_test.cc:81
ConcatImplActionP3< std::string, T1, T2 > Concat(const std::string &a, T1 b, T2 c)
Definition gmock-more-actions_test.cc:1296
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)
Definition gmock-more-actions_test.cc:120
int SumOfFirst2(int a, int b, Unused, Unused)
Definition gmock-more-actions_test.cc:94
bool Unary(int x)
Definition gmock-more-actions_test.cc:77
bool g_done
Definition gmock-more-actions_test.cc:75
int Ternary(int x, char y, short z)
Definition gmock-more-actions_test.cc:90
int Nullary()
Definition gmock-more-actions_test.cc:73
const char * Binary(const char *input, short n)
Definition gmock-more-actions_test.cc:88
bool ReferencesGlobalDouble(const double &x)
Definition gmock-more-actions_test.cc:82
char Char(char ch)
Definition gmock-more-actions_test.cc:70
Definition gmock-actions.h:151
internal::DeleteArgAction< k > DeleteArg()
Definition gmock-actions.h:2049
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
Definition gmock-actions.h:1815
internal::SaveArgAction< k, Ptr > SaveArg(Ptr pointer)
Definition gmock-actions.h:2016
internal::SaveArgPointeeAction< k, Ptr > SaveArgPointee(Ptr pointer)
Definition gmock-actions.h:2023
internal::SetArgRefereeAction< k, typename std::decay< T >::type > SetArgReferee(T &&value)
Definition gmock-actions.h:2030
internal::ReturnPointeeAction< Ptr > ReturnPointee(Ptr pointer)
Definition gmock-actions.h:2055
inline ::std::reference_wrapper< T > ByRef(T &l_value)
Definition gmock-actions.h:1994
internal::ReturnArgAction< k > ReturnArg()
Definition gmock-actions.h:2009
internal::WithArgsAction< typename std::decay< InnerAction >::type, k > WithArg(InnerAction &&action)
Definition gmock-actions.h:1795
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
Definition gmock-actions.h:1948
Definition gmock-more-actions_test.cc:1476
int value
Definition gmock-more-actions_test.cc:1479
GiantTemplate(int a_value)
Definition gmock-more-actions_test.cc:1478
Definition gmock-more-actions_test.cc:98
int operator()(int a, int b, int c, int d, int e)
Definition gmock-more-actions_test.cc:99
Definition gmock-more-actions_test.cc:108
int operator()(int a, int b, int c, int d, int e, int f)
Definition gmock-more-actions_test.cc:109
Definition gmock-more-actions_test.cc:84
int operator()(bool x)
Definition gmock-more-actions_test.cc:85