41 #include "gmock/gmock.h" 42 #include "gtest/gtest.h" 43 #include "gtest/internal/gtest-linked_ptr.h" 46 namespace gmock_more_actions_test {
52 using ::std::tr1::tuple;
53 using ::std::tr1::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;
72 inline short Short(
short n) {
return n; }
73 inline char Char(
char ch) {
return ch; }
91 bool Unary(
int x) {
return x < 0; }
93 const char*
Plus1(
const char* s) {
return s + 1; }
108 const char*
Binary(
const char* input,
short n) {
return input + n; }
112 int Ternary(
int x,
char y,
short z) {
return x + y + z; }
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;
140 int 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;
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;
186 short Unary(
long x) {
return static_cast<short>(value_ + x); }
188 string Binary(
const 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 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) {
279 inline const char*
CharPtr(
const char* s) {
return s; }
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) {
338 TEST(InvokeTest, MethodWithUnusedParameters) {
356 TEST(InvokeTest, FunctionWithCompatibleType) {
393 TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
400 TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
407 TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
415 TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
417 Action<
string(
const char*,
const char*,
const char*,
const char*,
418 const char*,
const char*,
const char*)> a =
427 TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
429 Action<
string(
const char*,
const char*,
const char*,
const char*,
430 const char*,
const char*,
const char*,
const char*)> a =
439 TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
441 Action<
string(
const char*,
const char*,
const char*,
const char*,
442 const char*,
const char*,
const char*,
const char*,
451 TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
453 Action<
string(
const char*,
const char*,
const char*,
const char*,
454 const char*,
const char*,
const char*,
const char*,
464 TEST(InvokeMethodTest, MethodWithCompatibleType) {
484 TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
489 TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
494 TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
499 TEST(SaveArgActionTest, WorksForSameType) {
506 TEST(SaveArgActionTest, WorksForCompatibleType) {
513 TEST(SaveArgPointeeActionTest, WorksForSameType) {
521 TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
529 TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) {
537 TEST(SetArgRefereeActionTest, WorksForSameType) {
540 a1.
Perform(tuple<int&>(value));
544 TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
547 a1.
Perform(tuple<int, int&>(0, value));
551 TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
554 a1.
Perform(tuple<bool, int, int&, const char*>(
true, 0, value,
"hi"));
563 : is_deleted_(is_deleted) {
565 *is_deleted_ =
false;
576 TEST(DeleteArgActionTest, OneArg) {
577 bool is_deleted =
false;
585 TEST(DeleteArgActionTest, TenArgs) {
586 bool is_deleted =
false;
588 const Action<void(
bool,
int,
int,
const char*,
bool,
595 #if GTEST_HAS_EXCEPTIONS 597 TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
602 class MyException {};
604 TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
609 TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
614 #endif // GTEST_HAS_EXCEPTIONS 618 TEST(SetArrayArgumentTest, SetsTheNthArray) {
620 int numbers[] = { 1, 2, 3 };
639 a = SetArrayArgument<2>(letters.begin(), letters.end());
640 std::fill_n(n, 4, 0);
641 std::fill_n(ch, 4,
'\0');
654 TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
656 int numbers[] = { 1, 2, 3 };
670 TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
672 int codes[] = { 97, 98, 99 };
685 TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
686 typedef void MyFunction(
bool, std::back_insert_iterator<std::string>);
695 TEST(ReturnPointeeTest, Works) {
TEST(InvokeTest, Nullary)
string Binary(const string &str, char c) const
string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
void VoidFunctionWithFourArguments(char, int, float, double)
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::IgnoredValue Unused
void VoidTernary(int, char, bool)
string ByNonConstRef(string &s)
int SumOf4(int a, int b, int c, int d)
int operator()(int a, int b, int c, int d, int e)
bool ByConstRef(const string &s)
string Concat4(const char *s1, const char *s2, const char *s3, const char *s4)
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)
int SumOfLast2(Unused, Unused, int a, int b) const
int SumOf5(int a, int b, int c, int d, int e)
internal::WithArgsAction< InnerAction > WithoutArgs(const InnerAction &action)
string Concat7(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7)
int Ternary(int x, bool y, char z)
#define EXPECT_TRUE(condition)
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)
void VoidBinary(int, char)
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)
const char * CharPtr(const char *s)
#define EXPECT_THROW(statement, expected_exception)
DeletionTester(bool *is_deleted)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_FALSE(condition)
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)
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)
int SumOf4(int a, int b, int c, int d) const
int SumOfFirst2(int a, int b, Unused, Unused)
int Ternary(int x, char y, short z)
Result Perform(const ArgumentTuple &args) const
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)
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)
bool StaticAssertTypeEq()
const internal::AnythingMatcher _
internal::WithArgsAction< InnerAction, k > WithArg(const InnerAction &action)
bool ReferencesGlobalDouble(const double &x)
#define EXPECT_EQ(expected, actual)
string Concat5(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5)
const char * Binary(const char *input, short n)
internal::ReturnAction< R > Return(R value)
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)