46namespace gmock_more_actions_test {
51using testing::make_tuple;
53using testing::tuple_element;
57using testing::DeleteArg;
60using testing::ReturnArg;
61using testing::ReturnPointee;
62using testing::SaveArg;
63using testing::SaveArgPointee;
64using testing::SetArgReferee;
72inline short Short(
short n) {
return n; }
73inline char Char(
char ch) {
return ch; }
91bool Unary(
int x) {
return x < 0; }
93const char*
Plus1(
const char*
s) {
return s + 1; }
108const char*
Binary(
const char* input,
short n) {
return input + n; }
112int Ternary(
int x,
char y,
short z) {
return x + y + z; }
116int SumOf4(
int a,
int b,
int c,
int d) {
return a + b + c +
d; }
122std::string
Concat4(
const char* s1,
const char* s2,
const char* s3,
124 return std::string(s1) + s2 + s3 + s4;
127int SumOf5(
int a,
int b,
int c,
int d,
int e) {
return a + b + c +
d + e; }
131 return a + b + c +
d + e;
135std::string
Concat5(
const char* s1,
const char* s2,
const char* s3,
136 const char* s4,
const char* s5) {
137 return std::string(s1) + s2 + s3 + s4 + s5;
140int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
141 return a + b + c +
d + e +
f;
146 return a + b + c +
d + e +
f;
150std::string
Concat6(
const char* s1,
const char* s2,
const char* s3,
151 const char* s4,
const char* s5,
const char* s6) {
152 return std::string(s1) + s2 + s3 + s4 + s5 + s6;
155std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
156 const char* s4,
const char* s5,
const char* s6,
158 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
161std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
167std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
173std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
186 short Unary(
long x) {
return static_cast<short>(value_ + x); }
188 std::string
Binary(
const std::string& str,
char c)
const {
return str + c; }
190 int Ternary(
int x,
bool y,
char z) {
return value_ + x + y*z; }
192 int SumOf4(
int a,
int b,
int c,
int d)
const {
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; }
200 int SumOf6(
int a,
int b,
int c,
int d,
int e,
int f) {
201 return a + b + c +
d + e +
f;
204 std::string
Concat7(
const char* s1,
const char* s2,
const char* s3,
205 const char* s4,
const char* s5,
const char* s6,
207 return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
210 std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
216 std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
222 std::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 std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
249 const char*
p =
"Hello";
260TEST(InvokeTest, FunctionThatTakes4Arguments) {
262 EXPECT_EQ(1234,
a.Perform(make_tuple(1000, 200, 30, 4)));
266TEST(InvokeTest, FunctionThatTakes5Arguments) {
268 EXPECT_EQ(12345,
a.Perform(make_tuple(10000, 2000, 300, 40, 5)));
272TEST(InvokeTest, FunctionThatTakes6Arguments) {
274 EXPECT_EQ(123456,
a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6)));
282TEST(InvokeTest, FunctionThatTakes7Arguments) {
283 Action<std::string(
const char*,
const char*,
const char*,
const char*,
284 const char*,
const char*,
const char*)>
293TEST(InvokeTest, FunctionThatTakes8Arguments) {
294 Action<std::string(
const char*,
const char*,
const char*,
const char*,
295 const char*,
const char*,
const char*,
const char*)>
304TEST(InvokeTest, FunctionThatTakes9Arguments) {
305 Action<std::string(
const char*,
const char*,
const char*,
const char*,
306 const char*,
const char*,
const char*,
const char*,
316TEST(InvokeTest, FunctionThatTakes10Arguments) {
317 Action<std::string(
const char*,
const char*,
const char*,
const char*,
318 const char*,
const char*,
const char*,
const char*,
319 const char*,
const char*)>
329TEST(InvokeTest, FunctionWithUnusedParameters) {
331 tuple<int, int, double, std::string> dummy =
332 make_tuple(10, 2, 5.6, std::string(
"hi"));
335 Action<int(
int,
int,
bool,
int*)> a2 =
337 EXPECT_EQ(23, a2.
Perform(make_tuple(20, 3,
true,
static_cast<int*
>(NULL))));
341TEST(InvokeTest, MethodWithUnusedParameters) {
346 Action<int(
char,
double,
int,
int)> a2 =
358TEST(InvokeTest, FunctionWithCompatibleType) {
383 std::string
s(
"Hell");
384 tuple<std::string, char> dummy = make_tuple(
s,
'o');
396TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
399 EXPECT_EQ(1357,
a.Perform(make_tuple(1000, 200, 30, 4)));
403TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
406 EXPECT_EQ(12345,
a.Perform(make_tuple(10000, 2000, 300, 40, 5)));
410TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
412 Action<int(
int,
int,
int,
int,
int,
int)>
a =
414 EXPECT_EQ(123456,
a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6)));
418TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
420 Action<std::string(
const char*,
const char*,
const char*,
const char*,
421 const char*,
const char*,
const char*)>
430TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
432 Action<std::string(
const char*,
const char*,
const char*,
const char*,
433 const char*,
const char*,
const char*,
const char*)>
442TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
444 Action<std::string(
const char*,
const char*,
const char*,
const char*,
445 const char*,
const char*,
const char*,
const char*,
455TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
457 Action<std::string(
const char*,
const char*,
const char*,
const char*,
458 const char*,
const char*,
const char*,
const char*,
459 const char*,
const char*)>
469TEST(InvokeMethodTest, MethodWithCompatibleType) {
471 Action<long(
int,
short,
char,
bool)>
a =
489TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
490 const Action<int(
int)>
a = ReturnArg<0>();
494TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
495 const Action<bool(
bool,
bool,
bool)>
a = ReturnArg<0>();
499TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
500 const Action<std::string(
int,
int, std::string,
int)>
a = ReturnArg<2>();
501 EXPECT_EQ(
"seven",
a.Perform(make_tuple(5, 6, std::string(
"seven"), 8)));
504TEST(SaveArgActionTest, WorksForSameType) {
506 const Action<void(
int n)> a1 = SaveArg<0>(&result);
511TEST(SaveArgActionTest, WorksForCompatibleType) {
513 const Action<void(
bool,
char)> a1 = SaveArg<1>(&result);
514 a1.
Perform(make_tuple(
true,
'a'));
518TEST(SaveArgPointeeActionTest, WorksForSameType) {
521 const Action<void(
const int*)> a1 = SaveArgPointee<0>(&result);
526TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
529 const Action<void(
bool,
char*)> a1 = SaveArgPointee<1>(&result);
534TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) {
542TEST(SetArgRefereeActionTest, WorksForSameType) {
544 const Action<void(
int&)> a1 = SetArgReferee<0>(1);
549TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
551 const Action<void(
int,
int&)> a1 = SetArgReferee<1>(
'a');
556TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
558 const Action<void(
bool,
int,
int&,
const char*)> a1 = SetArgReferee<2>(
'a');
559 a1.
Perform(tuple<bool, int, int&, const char*>(
true, 0,
value,
"hi"));
568 : is_deleted_(is_deleted) {
570 *is_deleted_ =
false;
581TEST(DeleteArgActionTest, OneArg) {
582 bool is_deleted =
false;
590TEST(DeleteArgActionTest, TenArgs) {
591 bool is_deleted =
false;
593 const Action<void(
bool,
int,
int,
const char*,
bool,
596 a1.
Perform(make_tuple(
true, 5, 6,
CharPtr(
"hi"),
false, 7, 8, 9, 10, t));
600#if GTEST_HAS_EXCEPTIONS
602TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
603 const Action<void(
int n)>
a = Throw(
'a');
609TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
614TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
623TEST(SetArrayArgumentTest, SetsTheNthArray) {
624 typedef void MyFunction(
bool,
int*,
char*);
625 int numbers[] = { 1, 2, 3 };
632 a.Perform(make_tuple(
true, pn, pch));
643 std::string letters =
"abc";
644 a = SetArrayArgument<2>(letters.begin(), letters.end());
645 std::fill_n(n, 4, 0);
646 std::fill_n(ch, 4,
'\0');
647 a.Perform(make_tuple(
true, pn, pch));
659TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
660 typedef void MyFunction(
bool,
int*);
661 int numbers[] = { 1, 2, 3 };
666 a.Perform(make_tuple(
true, pn));
675TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
676 typedef void MyFunction(
bool,
int*);
677 char chars[] = { 97, 98, 99 };
680 int codes[4] = { 111, 222, 333, 444 };
682 a.Perform(make_tuple(
true, pcodes));
690TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
691 typedef void MyFunction(
bool, std::back_insert_iterator<std::string>);
692 std::string letters =
"abc";
696 a.Perform(make_tuple(
true, back_inserter(
s)));
700TEST(ReturnPointeeTest, Works) {
702 const Action<int()>
a = ReturnPointee(&n);
Result Perform(ArgumentTuple args) const
DeletionTester(bool *is_deleted)
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)
#define EXPECT_EQ(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_TRUE(condition)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
@ Throw
Throw an error if any extra arguments were given.
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)
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)
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)
std::string Concat6(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
std::string Concat4(const char *s1, const char *s2, const char *s3, const char *s4)
const char * Plus1(const char *s)
void VoidFunctionWithFourArguments(char, int, float, double)
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)
void VoidTernary(int, char, bool)
std::string ByNonConstRef(std::string &s)
const char * Binary(const char *input, short n)
std::string Concat5(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
bool ReferencesGlobalDouble(const double &x)
void VoidBinary(int, char)
internal::WithArgsAction< InnerAction, k > WithArg(const InnerAction &action)
PolymorphicAction< internal::ReturnVoidAction > Return()
const internal::AnythingMatcher _
bool StaticAssertTypeEq()
internal::WithArgsAction< InnerAction > WithoutArgs(const InnerAction &action)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
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)