46 namespace gmock_more_actions_test {
53 using testing::tuple_element;
57 using testing::DeleteArg;
60 using testing::ReturnArg;
61 using testing::ReturnPointee;
62 using testing::SaveArg;
63 using testing::SaveArgPointee;
64 using testing::SetArgReferee;
73 inline char Char(
char ch) {
return ch; }
93 const char*
Plus1(
const char*
s) {
return s + 1; }
116 int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c + d; }
122 string Concat4(
const char* s1,
const char* s2,
const char* s3,
124 return string(s1) + s2 + s3 + s4;
127 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d +
e; }
131 return a + b + c + d +
e;
135 string Concat5(
const char* s1,
const char* s2,
const char* s3,
136 const char* s4,
const char* s5) {
137 return string(s1) + s2 + s3 + s4 + s5;
141 return a + b + c + d + e +
f;
146 return a + b + c + d + e +
f;
150 string Concat6(
const char* s1,
const char* s2,
const char* s3,
151 const char* s4,
const char* s5,
const char* s6) {
152 return string(s1) + s2 + s3 + s4 + s5 + s6;
155 string Concat7(
const char* s1,
const char* s2,
const char* s3,
156 const char* s4,
const char* s5,
const char* s6,
158 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
161 string Concat8(
const char* s1,
const char* s2,
const char* s3,
162 const char* s4,
const char* s5,
const char* s6,
163 const char* s7,
const char* s8) {
164 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
167 string Concat9(
const char* s1,
const char* s2,
const char* s3,
168 const char* s4,
const char* s5,
const char* s6,
169 const char* s7,
const char* s8,
const char* s9) {
170 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
173 string Concat10(
const char* s1,
const char* s2,
const char* s3,
174 const char* s4,
const char* s5,
const char* s6,
175 const char* s7,
const char* s8,
const char* s9,
177 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
188 string Binary(
const string&
str,
char c)
const {
return str +
c; }
193 return a + b + c + d +
value_;
198 int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c + d +
e; }
201 return a + b + c + d + e +
f;
204 string Concat7(
const char* s1,
const char* s2,
const char* s3,
205 const char* s4,
const char* s5,
const char* s6,
207 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
210 string Concat8(
const char* s1,
const char* s2,
const char* s3,
211 const char* s4,
const char* s5,
const char* s6,
212 const char* s7,
const char* s8) {
213 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
216 string Concat9(
const char* s1,
const char* s2,
const char* s3,
217 const char* s4,
const char* s5,
const char* s6,
218 const char* s7,
const char* s8,
const char* s9) {
219 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
222 string Concat10(
const char* s1,
const char* s2,
const char* s3,
223 const char* s4,
const char* s5,
const char* s6,
224 const char* s7,
const char* s8,
const char* s9,
226 return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
249 const char*
p =
"Hello";
260 TEST(InvokeTest, FunctionThatTakes4Arguments) {
266 TEST(InvokeTest, FunctionThatTakes5Arguments) {
272 TEST(InvokeTest, FunctionThatTakes6Arguments) {
282 TEST(InvokeTest, FunctionThatTakes7Arguments) {
283 Action<
string(
const char*,
const char*,
const char*,
const char*,
284 const char*,
const char*,
const char*)>
a =
293 TEST(InvokeTest, FunctionThatTakes8Arguments) {
294 Action<
string(
const char*,
const char*,
const char*,
const char*,
295 const char*,
const char*,
const char*,
const char*)>
a =
304 TEST(InvokeTest, FunctionThatTakes9Arguments) {
305 Action<
string(
const char*,
const char*,
const char*,
const char*,
306 const char*,
const char*,
const char*,
const char*,
315 TEST(InvokeTest, FunctionThatTakes10Arguments) {
316 Action<
string(
const char*,
const char*,
const char*,
const char*,
317 const char*,
const char*,
const char*,
const char*,
327 TEST(InvokeTest, FunctionWithUnusedParameters) {
332 tuple<int, int, double, const string&>(10, 2, 5.6, s)));
340 TEST(InvokeTest, MethodWithUnusedParameters) {
358 TEST(InvokeTest, FunctionWithCompatibleType) {
385 tuple<const string&, char>(s,
'o')));
396 TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
403 TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
410 TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
418 TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
420 Action<
string(
const char*,
const char*,
const char*,
const char*,
421 const char*,
const char*,
const char*)>
a =
430 TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
432 Action<
string(
const char*,
const char*,
const char*,
const char*,
433 const char*,
const char*,
const char*,
const char*)>
a =
442 TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
444 Action<
string(
const char*,
const char*,
const char*,
const char*,
445 const char*,
const char*,
const char*,
const char*,
454 TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
456 Action<
string(
const char*,
const char*,
const char*,
const char*,
457 const char*,
const char*,
const char*,
const char*,
467 TEST(InvokeMethodTest, MethodWithCompatibleType) {
487 TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
492 TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
497 TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
502 TEST(SaveArgActionTest, WorksForSameType) {
509 TEST(SaveArgActionTest, WorksForCompatibleType) {
516 TEST(SaveArgPointeeActionTest, WorksForSameType) {
524 TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
532 TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) {
540 TEST(SetArgRefereeActionTest, WorksForSameType) {
543 a1.
Perform(tuple<int&>(value));
547 TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
550 a1.
Perform(tuple<int, int&>(0, value));
554 TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
557 a1.
Perform(tuple<bool, int, int&, const char*>(
true, 0, value,
"hi"));
579 TEST(DeleteArgActionTest, OneArg) {
580 bool is_deleted =
false;
588 TEST(DeleteArgActionTest, TenArgs) {
589 bool is_deleted =
false;
591 const Action<void(
bool,
int,
int,
const char*,
bool,
598 #if GTEST_HAS_EXCEPTIONS
600 TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
605 class MyException {};
607 TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
608 const Action<double(char ch)> a = Throw(MyException());
612 TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
613 const Action<double()> a = Throw(MyException());
617 #endif // GTEST_HAS_EXCEPTIONS
621 TEST(SetArrayArgumentTest, SetsTheNthArray) {
623 int numbers[] = { 1, 2, 3 };
642 a = SetArrayArgument<2>(letters.begin(), letters.end());
643 std::fill_n(n, 4, 0);
644 std::fill_n(ch, 4,
'\0');
657 TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
659 int numbers[] = { 1, 2, 3 };
673 TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
675 char chars[] = { 97, 98, 99 };
678 int codes[4] = { 111, 222, 333, 444 };
688 TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
689 typedef void MyFunction(
bool, std::back_insert_iterator<std::string>);
698 TEST(ReturnPointeeTest, Works) {