45 namespace gmock_generated_actions_test {
61 inline short Short(
short n) {
return n; }
69 bool ByConstRef(
const std::string& s) {
return s ==
"Hi"; }
78 const char*
Binary(
const char* input,
short n) {
return input + n; }
80 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
84 return a + b + c + d + e;
88 std::string
Concat5(
const char* s1,
const char* s2,
const char* s3,
89 const char* s4,
const char* s5) {
90 return std::string(s1) + s2 + s3 + s4 + s5;
93 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
94 return a + b + c + d + e + f;
99 return a + b + c + d + e + f;
103 std::string
Concat6(
const char* s1,
const char* s2,
const char* s3,
104 const char* s4,
const char* s5,
const char* s6) {
105 return std::string(s1) + s2 + s3 + s4 + s5 + s6;
108 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
109 const char* s4,
const char* s5,
const char* s6,
111 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
114 std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
115 const char* s4,
const char* s5,
const char* s6,
116 const char* s7,
const char* s8) {
117 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
120 std::string
Concat9(
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,
const char* s9) {
123 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
126 std::string
Concat10(
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,
130 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
135 inline const char*
CharPtr(
const char* s) {
return s; }
140 TEST(InvokeArgumentTest, Function0) {
146 TEST(InvokeArgumentTest, Functor1) {
152 TEST(InvokeArgumentTest, Function5) {
154 InvokeArgument<0>(10000, 2000, 300, 40, 5);
159 TEST(InvokeArgumentTest, Functor5) {
161 InvokeArgument<0>(10000, 2000, 300, 40, 5);
166 TEST(InvokeArgumentTest, Function6) {
168 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
173 TEST(InvokeArgumentTest, Functor6) {
175 InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
180 TEST(InvokeArgumentTest, Function7) {
181 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
182 const char*,
const char*,
const char*,
184 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7");
189 TEST(InvokeArgumentTest, Function8) {
190 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
191 const char*,
const char*,
const char*,
192 const char*,
const char*))>
193 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8");
198 TEST(InvokeArgumentTest, Function9) {
199 Action<std::string(std::string(*)(
const char*,
const char*,
const char*,
200 const char*,
const char*,
const char*,
201 const char*,
const char*,
const char*))>
202 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9");
207 TEST(InvokeArgumentTest, Function10) {
208 Action<std::string(std::string(*)(
209 const char*,
const char*,
const char*,
const char*,
const char*,
210 const char*,
const char*,
const char*,
const char*,
const char*))>
211 a = InvokeArgument<0>(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0");
216 TEST(InvokeArgumentTest, ByPointerFunction) {
218 InvokeArgument<0>(
static_cast<const char*
>(
"Hi"),
Short(1));
224 TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
226 InvokeArgument<0>(
"Hi",
Short(1));
231 TEST(InvokeArgumentTest, ByConstReferenceFunction) {
233 InvokeArgument<0>(std::string(
"Hi"));
242 TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
249 a = InvokeArgument<0>(
ByRef(x));
263 TEST(DoAllTest, ThreeActions) {
278 DoAll(SetArgPointee<0>(1),
280 SetArgPointee<2>(
'a'),
291 char a =
'\0', b =
'\0';
293 DoAll(SetArgPointee<0>(1),
295 SetArgPointee<2>(
'a'),
296 SetArgPointee<3>(
'b'),
308 char a =
'\0', b =
'\0',
c =
'\0';
310 DoAll(SetArgPointee<0>(1),
312 SetArgPointee<2>(
'a'),
313 SetArgPointee<3>(
'b'),
314 SetArgPointee<4>(
'c'),
325 TEST(DoAllTest, SevenActions) {
327 char a =
'\0', b =
'\0',
c =
'\0', d =
'\0';
329 DoAll(SetArgPointee<0>(1),
331 SetArgPointee<2>(
'a'),
332 SetArgPointee<3>(
'b'),
333 SetArgPointee<4>(
'c'),
334 SetArgPointee<5>(
'd'),
346 TEST(DoAllTest, EightActions) {
348 char a =
'\0', b =
'\0',
c =
'\0', d =
'\0', e =
'\0';
349 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
351 DoAll(SetArgPointee<0>(1),
353 SetArgPointee<2>(
'a'),
354 SetArgPointee<3>(
'b'),
355 SetArgPointee<4>(
'c'),
356 SetArgPointee<5>(
'd'),
357 SetArgPointee<6>(
'e'),
372 char a =
'\0', b =
'\0',
c =
'\0', d =
'\0', e =
'\0',
f =
'\0';
373 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
374 char*,
char*)> action =
375 DoAll(SetArgPointee<0>(1),
377 SetArgPointee<2>(
'a'),
378 SetArgPointee<3>(
'b'),
379 SetArgPointee<4>(
'c'),
380 SetArgPointee<5>(
'd'),
381 SetArgPointee<6>(
'e'),
382 SetArgPointee<7>(
'f'),
398 char a =
'\0', b =
'\0',
c =
'\0', d =
'\0';
399 char e =
'\0',
f =
'\0',
g =
'\0';
400 Action<int(
int*,
int*,
char*,
char*,
char*,
char*,
401 char*,
char*,
char*)> action =
402 DoAll(SetArgPointee<0>(1),
404 SetArgPointee<2>(
'a'),
405 SetArgPointee<3>(
'b'),
406 SetArgPointee<4>(
'c'),
407 SetArgPointee<5>(
'd'),
408 SetArgPointee<6>(
'e'),
409 SetArgPointee<7>(
'f'),
410 SetArgPointee<8>(
'g'),
413 3, action.
Perform(std::make_tuple(&m, &
n, &a, &b, &
c, &d, &e, &
f, &
g)));
432 # pragma warning(push)
433 # pragma warning(disable:4100)
434 # pragma warning(disable:4503)
442 TEST(ActionMacroTest, WorksWhenNotReferencingArguments) {
447 EXPECT_EQ(5, a2.Perform(std::make_tuple(1,
true)));
453 TEST(ActionMacroTest, WorksWhenReturningVoid) {
456 a1.
Perform(std::make_tuple(5, &n));
463 StaticAssertTypeEq<int*, arg2_type>();
464 arg2_type temp = arg2;
468 TEST(ActionMacroTest, CanReferenceArgumentType) {
471 a1.
Perform(std::make_tuple(5,
false, &n));
478 StaticAssertTypeEq<std::tuple<int, char, int*>, args_type>();
479 args_type args_copy = args;
480 return std::get<0>(args_copy) + std::get<1>(args_copy);
483 TEST(ActionMacroTest, CanReferenceArgumentTuple) {
491 int Dummy(
bool flag) {
return flag? 1 : 0; }
494 StaticAssertTypeEq<int(bool), function_type>();
495 function_type* fp = &
Dummy;
499 TEST(ActionMacroTest, CanReferenceMockFunctionType) {
508 StaticAssertTypeEq<int, return_type>();
509 return_type result =
Dummy(
true);
513 TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) {
520 ACTION(ReturnAddrOfConstBoolReferenceArg) {
521 StaticAssertTypeEq<const bool&, arg1_type>();
525 TEST(ActionMacroTest, WorksForConstReferenceArg) {
527 const bool b =
false;
533 StaticAssertTypeEq<int&, arg0_type>();
537 TEST(ActionMacroTest, WorksForNonConstReferenceArg) {
544 namespace action_test {
548 TEST(ActionMacroTest, WorksInNamespace) {
557 TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) {
569 TEST(ActionPMacroTest, DefinesParameterizedAction) {
582 TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
589 TEST(ActionPMacroTest, WorksInCompatibleMockFunction) {
591 const std::string re =
"re";
592 std::tuple<const std::string> dummy = std::make_tuple(re);
599 ACTION(OverloadedAction) {
return arg0 ? arg1 :
"hello"; }
602 return arg0 ? arg1 : default_value;
606 return arg0 ? true_value : false_value;
609 TEST(ActionMacroTest, CanDefineOverloadedActions) {
612 const MyAction a1 = OverloadedAction();
616 const MyAction a2 = OverloadedAction(
"hi");
620 const MyAction a3 = OverloadedAction(
"hi",
"you");
629 TEST(ActionPnMacroTest, WorksFor3Parameters) {
634 const std::string re =
"re";
635 std::tuple<const std::string> dummy = std::make_tuple(re);
636 EXPECT_EQ(
"retail->", a2.Perform(dummy));
639 ACTION_P4(Plus, p0, p1, p2, p3) {
return arg0 + p0 + p1 + p2 + p3; }
641 TEST(ActionPnMacroTest, WorksFor4Parameters) {
646 ACTION_P5(Plus, p0, p1, p2, p3, p4) {
return arg0 + p0 + p1 + p2 + p3 + p4; }
648 TEST(ActionPnMacroTest, WorksFor5Parameters) {
654 return arg0 + p0 + p1 + p2 + p3 + p4 + p5;
657 TEST(ActionPnMacroTest, WorksFor6Parameters) {
663 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6;
666 TEST(ActionPnMacroTest, WorksFor7Parameters) {
672 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7;
675 TEST(ActionPnMacroTest, WorksFor8Parameters) {
677 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8,
678 a1.
Perform(std::make_tuple(10)));
682 return arg0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
685 TEST(ActionPnMacroTest, WorksFor9Parameters) {
687 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9,
688 a1.
Perform(std::make_tuple(10)));
691 ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
693 last_param_type t9 = last_param;
694 return t0 + p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + t9;
697 TEST(ActionPnMacroTest, WorksFor10Parameters) {
699 EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10,
700 a1.
Perform(std::make_tuple(10)));
707 std::string prefix_str(prefix);
708 char suffix_char =
static_cast<char>(suffix);
709 return prefix_str + arg0 + suffix_char;
712 TEST(ActionPnMacroTest, SimpleTypePromotion) {
714 PadArgument(std::string(
"foo"),
'r');
716 PadArgument(
"foo", static_cast<int>(
'r'));
727 std::stringstream ss;
737 template <
typename T1,
typename T2>
741 ConcatImplActionP3<std::string, T1, T2>
748 return ConcatImpl(a, b, c);
753 return ConcatImpl<std::string, T1, T2>(
a, b,
c);
759 template <
typename T1,
typename T2>
760 ConcatImplActionP3<T1, int, T2>
762 return ConcatImpl(a, b, c);
765 TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) {
770 EXPECT_EQ(
"123", a1.Perform(std::make_tuple()));
779 TEST(ActionPnMacroTest, TypesAreCorrect) {
781 DoFooAction a0 = DoFoo();
784 DoFooActionP<int> a1 = DoFoo(1);
788 DoFooActionP2<int, char> a2 = DoFoo(1,
'2');
789 PlusActionP3<int, int, char> a3 =
Plus(1, 2,
'3');
790 PlusActionP4<int, int, int, char> a4 =
Plus(1, 2, 3,
'4');
791 PlusActionP5<int, int, int, int, char> a5 =
Plus(1, 2, 3, 4,
'5');
792 PlusActionP6<int, int, int, int, int, char> a6 =
Plus(1, 2, 3, 4, 5,
'6');
793 PlusActionP7<int, int, int, int, int, int, char> a7 =
794 Plus(1, 2, 3, 4, 5, 6,
'7');
795 PlusActionP8<int, int, int, int, int, int, int, char> a8 =
796 Plus(1, 2, 3, 4, 5, 6, 7,
'8');
797 PlusActionP9<int, int, int, int, int, int, int, int, char> a9 =
798 Plus(1, 2, 3, 4, 5, 6, 7, 8,
'9');
799 PlusActionP10<int, int, int, int, int, int, int, int, int, char> a10 =
800 Plus(1, 2, 3, 4, 5, 6, 7, 8, 9,
'0');
822 ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
823 return a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
826 TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) {
827 int x = 1,
y = 2,
z = 3;
828 const std::tuple<> empty = std::make_tuple();
833 a = Plus2<const int&, int&>(
x,
y);
836 a = Plus3<int&, const int&, int&>(
x,
y,
z);
839 int n[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
840 a = Plus10<
const int&,
int&,
const int&,
int&,
const int&,
int&,
const int&,
841 int&,
const int&,
int&>(n[0], n[1], n[2], n[3], n[4], n[5], n[6], n[7],
850 int a6,
int a7,
int a8,
int a9,
int a10)
851 :
value_(a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10) {
858 HAS_1_TEMPLATE_PARAMS(
typename,
T),
859 AND_0_VALUE_PARAMS()) {
863 TEST(ActionTemplateTest, WorksWithoutValueParam) {
865 int*
p = a.
Perform(std::make_tuple());
871 HAS_1_TEMPLATE_PARAMS(
typename,
T),
872 AND_1_VALUE_PARAMS(a0)) {
876 TEST(ActionTemplateTest, WorksWithValueParams) {
878 int*
p = a.
Perform(std::make_tuple());
885 HAS_1_TEMPLATE_PARAMS(
int, k),
886 AND_0_VALUE_PARAMS()) {
887 delete std::get<k>(args);
899 TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
904 a.
Perform(std::make_tuple(&n, resetter));
910 HAS_1_TEMPLATE_PARAMS(template <typename Pointee>
class,
912 AND_1_VALUE_PARAMS(pointee)) {
913 return Pointer<pointee_type>(
new pointee_type(pointee));
916 TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) {
918 ReturnSmartPointer<std::shared_ptr>(42);
919 std::shared_ptr<int>
p =
a.Perform(std::make_tuple());
924 template <
typename T1,
typename T2,
typename T3,
int k4,
bool k5,
925 unsigned int k6,
typename T7,
typename T8,
typename T9>
933 HAS_10_TEMPLATE_PARAMS(
943 template <typename T>
class, T10),
944 AND_1_VALUE_PARAMS(
value)) {
948 TEST(ActionTemplateTest, WorksFor10TemplateParameters) {
950 char, unsigned,
int>;
952 unsigned, int, std::shared_ptr>(42);
953 Giant giant = a.
Perform(std::make_tuple());
959 HAS_1_TEMPLATE_PARAMS(
typename, Number),
960 AND_10_VALUE_PARAMS(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)) {
961 return static_cast<Number
>(v1) + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10;
964 TEST(ActionTemplateTest, WorksFor10ValueParameters) {
965 const Action<int()> a = ReturnSum<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
977 HAS_1_TEMPLATE_PARAMS(
typename, Number),
978 AND_2_VALUE_PARAMS(v1, v2)) {
979 return static_cast<Number
>(v1) + v2;
983 HAS_1_TEMPLATE_PARAMS(
typename, Number),
984 AND_3_VALUE_PARAMS(v1, v2, v3)) {
985 return static_cast<Number
>(v1) + v2 + v3;
989 HAS_2_TEMPLATE_PARAMS(
typename, Number,
int, k),
990 AND_4_VALUE_PARAMS(v1, v2, v3, v4)) {
991 return static_cast<Number
>(v1) + v2 + v3 + v4 + k;
994 TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
999 const Action<int()> a4 = ReturnSum<int, 10000>(2000, 300, 40, 5);
1003 EXPECT_EQ(6, a3.Perform(std::make_tuple()));
1004 EXPECT_EQ(12345, a4.Perform(std::make_tuple()));
int SumOf5(int a, int b, int c, int d, int e)
GiantTemplate(int a_value)
int operator()(int a, int b, int c, int d, int e, int f)
#define EXPECT_DOUBLE_EQ(val1, val2)
TEST(InvokeArgumentTest, Function0)
internal::IgnoredValue Unused
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_P2(OverloadedAction, true_value, false_value)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
BoolResetter(bool *value)
bool ReferencesGlobalDouble(const double &x)
ACTION_TEMPLATE(CreateNew, HAS_1_TEMPLATE_PARAMS(typename, T), AND_0_VALUE_PARAMS())
ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6)
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)
internal::DoAllAction< typename std::decay< Action >::type...> DoAll(Action &&...action)
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)
inline::std::reference_wrapper< T > ByRef(T &l_value)
int operator()(int a, int b, int c, int d, int e)
ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
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
double Plus(double a, double b)
ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8)
TenArgConstructorClass(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10)
ACTION_P5(Plus, p0, p1, p2, p3, p4)
int SumOf6(int a, int b, int c, int d, int e, int f)
ACTION_P6(Plus, p0, p1, p2, p3, p4, p5)
std::string Concat6(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
const char * Plus1(const char *s)
#define EXPECT_STREQ(s1, s2)
const char * Binary(const char *input, short n)
bool ByConstRef(const std::string &s)
internal::SetArgumentPointeeAction< N, T > SetArgPointee(T value)
const char * CharPtr(const char *s)
internal::ReturnAction< R > Return(R value)
ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7)
#define EXPECT_EQ(val1, val2)
ACTION_P4(Plus, p0, p1, p2, p3)
ConcatImplActionP3< std::string, T1, T2 > Concat(const std::string &a, T1 b, T2 c)
std::string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
#define EXPECT_TRUE(condition)
constexpr bool StaticAssertTypeEq() noexcept
#define EXPECT_FALSE(condition)
Result Perform(ArgumentTuple args) const
#define GTEST_INTENTIONAL_CONST_COND_POP_()
std::string Concat5(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)