45 namespace gmock_more_actions_test {
52 using testing::DeleteArg;
55 using testing::ReturnArg;
56 using testing::ReturnPointee;
57 using testing::SaveArg;
58 using testing::SaveArgPointee;
59 using testing::SetArgReferee;
65 inline short Short(
short n) {
return n; }
86 const char*
Plus1(
const char* s) {
return s + 1; }
90 bool ByConstRef(
const std::string& s) {
return s ==
"Hi"; }
101 const char*
Binary(
const char* input,
short n) {
return input + n; }
109 int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c + d; }
115 std::string
Concat4(
const char* s1,
const char* s2,
const char* s3,
117 return std::string(s1) + s2 + s3 + s4;
120 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
124 return a + b + c + d + e;
128 std::string
Concat5(
const char* s1,
const char* s2,
const char* s3,
129 const char* s4,
const char* s5) {
130 return std::string(s1) + s2 + s3 + s4 + s5;
133 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
134 return a + b + c + d + e + f;
139 return a + b + c + d + e + f;
143 std::string
Concat6(
const char* s1,
const char* s2,
const char* s3,
144 const char* s4,
const char* s5,
const char* s6) {
145 return std::string(s1) + s2 + s3 + s4 + s5 + s6;
148 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
149 const char* s4,
const char* s5,
const char* s6,
151 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
154 std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
155 const char* s4,
const char* s5,
const char* s6,
156 const char* s7,
const char* s8) {
157 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
160 std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
161 const char* s4,
const char* s5,
const char* s6,
162 const char* s7,
const char* s8,
const char* s9) {
163 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
166 std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
167 const char* s4,
const char* s5,
const char* s6,
168 const char* s7,
const char* s8,
const char* s9,
170 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
181 std::string
Binary(
const std::string& str,
char c)
const {
return str +
c; }
186 return a + b + c + d +
value_;
191 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d + e; }
193 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
194 return a + b + c + d + e + f;
197 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
198 const char* s4,
const char* s5,
const char* s6,
200 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
203 std::string
Concat8(
const char* s1,
const char* s2,
const char* s3,
204 const char* s4,
const char* s5,
const char* s6,
205 const char* s7,
const char* s8) {
206 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
209 std::string
Concat9(
const char* s1,
const char* s2,
const char* s3,
210 const char* s4,
const char* s5,
const char* s6,
211 const char* s7,
const char* s8,
const char* s9) {
212 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
215 std::string
Concat10(
const char* s1,
const char* s2,
const char* s3,
216 const char* s4,
const char* s5,
const char* s6,
217 const char* s7,
const char* s8,
const char* s9,
219 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
242 const char*
p =
"Hello";
253 TEST(InvokeTest, FunctionThatTakes4Arguments) {
259 TEST(InvokeTest, FunctionThatTakes5Arguments) {
265 TEST(InvokeTest, FunctionThatTakes6Arguments) {
268 a.
Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
273 inline const char*
CharPtr(
const char* s) {
return s; }
276 TEST(InvokeTest, FunctionThatTakes7Arguments) {
277 Action<std::string(
const char*,
const char*,
const char*,
const char*,
278 const char*,
const char*,
const char*)>
287 TEST(InvokeTest, FunctionThatTakes8Arguments) {
288 Action<std::string(
const char*,
const char*,
const char*,
const char*,
289 const char*,
const char*,
const char*,
const char*)>
298 TEST(InvokeTest, FunctionThatTakes9Arguments) {
299 Action<std::string(
const char*,
const char*,
const char*,
const char*,
300 const char*,
const char*,
const char*,
const char*,
310 TEST(InvokeTest, FunctionThatTakes10Arguments) {
311 Action<std::string(
const char*,
const char*,
const char*,
const char*,
312 const char*,
const char*,
const char*,
const char*,
313 const char*,
const char*)>
323 TEST(InvokeTest, FunctionWithUnusedParameters) {
325 std::tuple<int, int, double, std::string> dummy =
326 std::make_tuple(10, 2, 5.6, std::string(
"hi"));
332 23, a2.Perform(std::make_tuple(20, 3,
true, static_cast<int*>(
nullptr))));
336 TEST(InvokeTest, MethodWithUnusedParameters) {
343 EXPECT_EQ(23, a2.Perform(std::make_tuple(
'a', 2.5, 20, 3)));
353 TEST(InvokeTest, FunctionWithCompatibleType) {
378 std::string s(
"Hell");
379 std::tuple<std::string, char> dummy = std::make_tuple(s,
'o');
391 TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
398 TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
405 TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
410 a.
Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
414 TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
416 Action<std::string(
const char*,
const char*,
const char*,
const char*,
417 const char*,
const char*,
const char*)>
426 TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
428 Action<std::string(
const char*,
const char*,
const char*,
const char*,
429 const char*,
const char*,
const char*,
const char*)>
438 TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
440 Action<std::string(
const char*,
const char*,
const char*,
const char*,
441 const char*,
const char*,
const char*,
const char*,
451 TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
453 Action<std::string(
const char*,
const char*,
const char*,
const char*,
454 const char*,
const char*,
const char*,
const char*,
455 const char*,
const char*)>
465 TEST(InvokeMethodTest, MethodWithCompatibleType) {
485 TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
490 TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
495 TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
497 EXPECT_EQ(
"seven", a.
Perform(std::make_tuple(5, 6, std::string(
"seven"), 8)));
500 TEST(SaveArgActionTest, WorksForSameType) {
503 a1.
Perform(std::make_tuple(5));
507 TEST(SaveArgActionTest, WorksForCompatibleType) {
510 a1.
Perform(std::make_tuple(
true,
'a'));
514 TEST(SaveArgPointeeActionTest, WorksForSameType) {
518 a1.
Perform(std::make_tuple(&value));
522 TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
526 a1.
Perform(std::make_tuple(
true, &value));
530 TEST(SetArgRefereeActionTest, WorksForSameType) {
533 a1.
Perform(std::tuple<int&>(value));
537 TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
540 a1.
Perform(std::tuple<int, int&>(0, value));
544 TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
547 a1.
Perform(std::tuple<bool, int, int&, const char*>(
true, 0, value,
"hi"));
569 TEST(DeleteArgActionTest, OneArg) {
570 bool is_deleted =
false;
574 a1.
Perform(std::make_tuple(t));
578 TEST(DeleteArgActionTest, TenArgs) {
579 bool is_deleted =
false;
581 const Action<
void(
bool,
int,
int,
const char*,
bool,
584 a1.
Perform(std::make_tuple(
true, 5, 6,
CharPtr(
"hi"),
false, 7, 8, 9, 10, t));
588 #if GTEST_HAS_EXCEPTIONS
590 TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
595 class MyException {};
597 TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
598 const Action<double(char ch)> a = Throw(MyException());
599 EXPECT_THROW(a.Perform(std::make_tuple(
'0')), MyException);
602 TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
603 const Action<double()> a = Throw(MyException());
604 EXPECT_THROW(a.Perform(std::make_tuple()), MyException);
607 #endif // GTEST_HAS_EXCEPTIONS
611 TEST(SetArrayArgumentTest, SetsTheNthArray) {
613 int numbers[] = { 1, 2, 3 };
620 a.
Perform(std::make_tuple(
true, pn, pch));
631 std::string letters =
"abc";
632 a = SetArrayArgument<2>(letters.begin(), letters.end());
633 std::fill_n(n, 4, 0);
634 std::fill_n(ch, 4,
'\0');
635 a.
Perform(std::make_tuple(
true, pn, pch));
647 TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
649 int numbers[] = { 1, 2, 3 };
654 a.
Perform(std::make_tuple(
true, pn));
663 TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
665 char chars[] = { 97, 98, 99 };
668 int codes[4] = { 111, 222, 333, 444 };
670 a.
Perform(std::make_tuple(
true, pcodes));
678 TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
679 typedef void MyFunction(
bool, std::back_insert_iterator<std::string>);
680 std::string letters =
"abc";
684 a.
Perform(std::make_tuple(
true, back_inserter(s)));
688 TEST(ReturnPointeeTest, Works) {
TEST(InvokeTest, Nullary)
std::string ByNonConstRef(std::string &s)
void VoidFunctionWithFourArguments(char, int, float, double)
internal::IgnoredValue Unused
void VoidTernary(int, char, bool)
#define EXPECT_THROW(statement, expected_exception)
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 SumOf4(int a, int b, int c, int d)
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)
int SumOf6(int a, int b, int c, int d, int e, int f)
std::string Concat5(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
int SumOfLast2(Unused, Unused, int a, int b) const
int SumOf5(int a, int b, int c, int d, int e)
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)
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 Ternary(int x, bool y, char z)
void VoidBinary(int, char)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
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)
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
DeletionTester(bool *is_deleted)
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
std::string Concat6(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
int SumOf5(int a, int b, int c, int d, int e)
int SumOf6(int a, int b, int c, int d, int e, int f)
ADVar foo(double d, ADVar x, ADVar y)
const char * Plus1(const char *s)
int SumOf4(int a, int b, int c, int d) const
int SumOfFirst2(int a, int b, Unused, Unused)
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)
bool ByConstRef(const std::string &s)
internal::ReturnAction< R > Return(R value)
int Ternary(int x, char y, short z)
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_EQ(val1, val2)
std::string Concat4(const char *s1, const char *s2, const char *s3, const char *s4)
internal::WithArgsAction< typename std::decay< InnerAction >::type, k > WithArg(InnerAction &&action)
#define EXPECT_TRUE(condition)
std::string Binary(const std::string &str, char c) const
#define EXPECT_FALSE(condition)
bool ReferencesGlobalDouble(const double &x)
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)
Result Perform(ArgumentTuple args) const
const char * Binary(const char *input, short n)
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)