Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: testing/gmock/test/gmock-more-actions_test.cc

Issue 521012: Update gmock and gtest. (Closed)
Patch Set: update readme Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/gmock/test/gmock-matchers_test.cc ('k') | testing/gmock/test/gmock-nice-strict_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 using testing::Return; 58 using testing::Return;
59 using testing::ReturnArg; 59 using testing::ReturnArg;
60 using testing::SaveArg; 60 using testing::SaveArg;
61 using testing::SetArgReferee; 61 using testing::SetArgReferee;
62 using testing::SetArgumentPointee; 62 using testing::SetArgumentPointee;
63 using testing::StaticAssertTypeEq; 63 using testing::StaticAssertTypeEq;
64 using testing::Unused; 64 using testing::Unused;
65 using testing::WithArg; 65 using testing::WithArg;
66 using testing::WithoutArgs; 66 using testing::WithoutArgs;
67 67
68 // For suppressing compiler warnings on conversion possibly losing precision.
69 inline short Short(short n) { return n; } // NOLINT
70 inline char Char(char ch) { return ch; }
71
68 // Sample functions and functors for testing Invoke() and etc. 72 // Sample functions and functors for testing Invoke() and etc.
69 int Nullary() { return 1; } 73 int Nullary() { return 1; }
70 74
71 class NullaryFunctor { 75 class NullaryFunctor {
72 public: 76 public:
73 int operator()() { return 2; } 77 int operator()() { return 2; }
74 }; 78 };
75 79
76 bool g_done = false; 80 bool g_done = false;
77 void VoidNullary() { g_done = true; } 81 void VoidNullary() { g_done = true; }
78 82
79 class VoidNullaryFunctor { 83 class VoidNullaryFunctor {
80 public: 84 public:
81 void operator()() { g_done = true; } 85 void operator()() { g_done = true; }
82 }; 86 };
83 87
84 bool Unary(int x) { return x < 0; } 88 bool Unary(int x) { return x < 0; }
85 89
86 const char* Plus1(const char* s) { return s + 1; } 90 const char* Plus1(const char* s) { return s + 1; }
87 91
88 void VoidUnary(int n) { g_done = true; } 92 void VoidUnary(int /* n */) { g_done = true; }
89 93
90 bool ByConstRef(const string& s) { return s == "Hi"; } 94 bool ByConstRef(const string& s) { return s == "Hi"; }
91 95
92 const double g_double = 0; 96 const double g_double = 0;
93 bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; } 97 bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; }
94 98
95 string ByNonConstRef(string& s) { return s += "+"; } // NOLINT 99 string ByNonConstRef(string& s) { return s += "+"; } // NOLINT
96 100
97 struct UnaryFunctor { 101 struct UnaryFunctor {
98 int operator()(bool x) { return x ? 1 : -1; } 102 int operator()(bool x) { return x ? 1 : -1; }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 TEST(InvokeTest, Unary) { 236 TEST(InvokeTest, Unary) {
233 Action<bool(int)> a = Invoke(Unary); // NOLINT 237 Action<bool(int)> a = Invoke(Unary); // NOLINT
234 EXPECT_FALSE(a.Perform(make_tuple(1))); 238 EXPECT_FALSE(a.Perform(make_tuple(1)));
235 EXPECT_TRUE(a.Perform(make_tuple(-1))); 239 EXPECT_TRUE(a.Perform(make_tuple(-1)));
236 } 240 }
237 241
238 // Tests using Invoke() with a binary function. 242 // Tests using Invoke() with a binary function.
239 TEST(InvokeTest, Binary) { 243 TEST(InvokeTest, Binary) {
240 Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT 244 Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT
241 const char* p = "Hello"; 245 const char* p = "Hello";
242 EXPECT_EQ(p + 2, a.Perform(make_tuple(p, 2))); 246 EXPECT_EQ(p + 2, a.Perform(make_tuple(p, Short(2))));
243 } 247 }
244 248
245 // Tests using Invoke() with a ternary function. 249 // Tests using Invoke() with a ternary function.
246 TEST(InvokeTest, Ternary) { 250 TEST(InvokeTest, Ternary) {
247 Action<int(int, char, short)> a = Invoke(Ternary); // NOLINT 251 Action<int(int, char, short)> a = Invoke(Ternary); // NOLINT
248 EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', 3))); 252 EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', Short(3))));
249 } 253 }
250 254
251 // Tests using Invoke() with a 4-argument function. 255 // Tests using Invoke() with a 4-argument function.
252 TEST(InvokeTest, FunctionThatTakes4Arguments) { 256 TEST(InvokeTest, FunctionThatTakes4Arguments) {
253 Action<int(int, int, int, int)> a = Invoke(SumOf4); // NOLINT 257 Action<int(int, int, int, int)> a = Invoke(SumOf4); // NOLINT
254 EXPECT_EQ(1234, a.Perform(make_tuple(1000, 200, 30, 4))); 258 EXPECT_EQ(1234, a.Perform(make_tuple(1000, 200, 30, 4)));
255 } 259 }
256 260
257 // Tests using Invoke() with a 5-argument function. 261 // Tests using Invoke() with a 5-argument function.
258 TEST(InvokeTest, FunctionThatTakes5Arguments) { 262 TEST(InvokeTest, FunctionThatTakes5Arguments) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Invoke(&foo, &Foo::SumOfLast2); 337 Invoke(&foo, &Foo::SumOfLast2);
334 EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2))); 338 EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2)));
335 339
336 Action<int(char, double, int, int)> a2 = 340 Action<int(char, double, int, int)> a2 =
337 Invoke(&foo, &Foo::SumOfLast2); 341 Invoke(&foo, &Foo::SumOfLast2);
338 EXPECT_EQ(23, a2.Perform(make_tuple('a', 2.5, 20, 3))); 342 EXPECT_EQ(23, a2.Perform(make_tuple('a', 2.5, 20, 3)));
339 } 343 }
340 344
341 // Tests using Invoke() with a functor. 345 // Tests using Invoke() with a functor.
342 TEST(InvokeTest, Functor) { 346 TEST(InvokeTest, Functor) {
343 Action<int(short, char)> a = Invoke(plus<short>()); // NOLINT 347 Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT
344 EXPECT_EQ(3, a.Perform(make_tuple(1, 2))); 348 EXPECT_EQ(3L, a.Perform(make_tuple(1, 2)));
345 } 349 }
346 350
347 // Tests using Invoke(f) as an action of a compatible type. 351 // Tests using Invoke(f) as an action of a compatible type.
348 TEST(InvokeTest, FunctionWithCompatibleType) { 352 TEST(InvokeTest, FunctionWithCompatibleType) {
349 Action<long(int, short, char, bool)> a = Invoke(SumOf4); // NOLINT 353 Action<long(int, short, char, bool)> a = Invoke(SumOf4); // NOLINT
350 EXPECT_EQ(4321, a.Perform(make_tuple(4000, 300, 20, true))); 354 EXPECT_EQ(4321, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
351 } 355 }
352 356
353 // Tests using Invoke() with an object pointer and a method pointer. 357 // Tests using Invoke() with an object pointer and a method pointer.
354 358
355 // Tests using Invoke() with a nullary method. 359 // Tests using Invoke() with a nullary method.
356 TEST(InvokeMethodTest, Nullary) { 360 TEST(InvokeMethodTest, Nullary) {
357 Foo foo; 361 Foo foo;
358 Action<int()> a = Invoke(&foo, &Foo::Nullary); // NOLINT 362 Action<int()> a = Invoke(&foo, &Foo::Nullary); // NOLINT
359 EXPECT_EQ(123, a.Perform(make_tuple())); 363 EXPECT_EQ(123, a.Perform(make_tuple()));
360 } 364 }
(...skipping 10 matching lines...) Expand all
371 Foo foo; 375 Foo foo;
372 Action<string(const string&, char)> a = Invoke(&foo, &Foo::Binary); 376 Action<string(const string&, char)> a = Invoke(&foo, &Foo::Binary);
373 string s("Hell"); 377 string s("Hell");
374 EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o'))); 378 EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o')));
375 } 379 }
376 380
377 // Tests using Invoke() with a ternary method. 381 // Tests using Invoke() with a ternary method.
378 TEST(InvokeMethodTest, Ternary) { 382 TEST(InvokeMethodTest, Ternary) {
379 Foo foo; 383 Foo foo;
380 Action<int(int, bool, char)> a = Invoke(&foo, &Foo::Ternary); // NOLINT 384 Action<int(int, bool, char)> a = Invoke(&foo, &Foo::Ternary); // NOLINT
381 EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, 1))); 385 EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, Char(1))));
382 } 386 }
383 387
384 // Tests using Invoke() with a 4-argument method. 388 // Tests using Invoke() with a 4-argument method.
385 TEST(InvokeMethodTest, MethodThatTakes4Arguments) { 389 TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
386 Foo foo; 390 Foo foo;
387 Action<int(int, int, int, int)> a = Invoke(&foo, &Foo::SumOf4); // NOLINT 391 Action<int(int, int, int, int)> a = Invoke(&foo, &Foo::SumOf4); // NOLINT
388 EXPECT_EQ(1357, a.Perform(make_tuple(1000, 200, 30, 4))); 392 EXPECT_EQ(1357, a.Perform(make_tuple(1000, 200, 30, 4)));
389 } 393 }
390 394
391 // Tests using Invoke() with a 5-argument method. 395 // Tests using Invoke() with a 5-argument method.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 CharPtr("4"), CharPtr("5"), CharPtr("6"), 454 CharPtr("4"), CharPtr("5"), CharPtr("6"),
451 CharPtr("7"), CharPtr("8"), CharPtr("9"), 455 CharPtr("7"), CharPtr("8"), CharPtr("9"),
452 CharPtr("0")))); 456 CharPtr("0"))));
453 } 457 }
454 458
455 // Tests using Invoke(f) as an action of a compatible type. 459 // Tests using Invoke(f) as an action of a compatible type.
456 TEST(InvokeMethodTest, MethodWithCompatibleType) { 460 TEST(InvokeMethodTest, MethodWithCompatibleType) {
457 Foo foo; 461 Foo foo;
458 Action<long(int, short, char, bool)> a = // NOLINT 462 Action<long(int, short, char, bool)> a = // NOLINT
459 Invoke(&foo, &Foo::SumOf4); 463 Invoke(&foo, &Foo::SumOf4);
460 EXPECT_EQ(4444, a.Perform(make_tuple(4000, 300, 20, true))); 464 EXPECT_EQ(4444, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
461 } 465 }
462 466
463 // Tests using WithoutArgs with an action that takes no argument. 467 // Tests using WithoutArgs with an action that takes no argument.
464 TEST(WithoutArgsTest, NoArg) { 468 TEST(WithoutArgsTest, NoArg) {
465 Action<int(int n)> a = WithoutArgs(Invoke(Nullary)); // NOLINT 469 Action<int(int n)> a = WithoutArgs(Invoke(Nullary)); // NOLINT
466 EXPECT_EQ(1, a.Perform(make_tuple(2))); 470 EXPECT_EQ(1, a.Perform(make_tuple(2)));
467 } 471 }
468 472
469 // Tests using WithArg with an action that takes 1 argument. 473 // Tests using WithArg with an action that takes 1 argument.
470 TEST(WithArgTest, OneArg) { 474 TEST(WithArgTest, OneArg) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 std::string letters = "abc"; 659 std::string letters = "abc";
656 Action<MyFunction> a = SetArrayArgument<1>(letters.begin(), letters.end()); 660 Action<MyFunction> a = SetArrayArgument<1>(letters.begin(), letters.end());
657 661
658 std::string s; 662 std::string s;
659 a.Perform(make_tuple(true, back_inserter(s))); 663 a.Perform(make_tuple(true, back_inserter(s)));
660 EXPECT_EQ(letters, s); 664 EXPECT_EQ(letters, s);
661 } 665 }
662 666
663 } // namespace gmock_generated_actions_test 667 } // namespace gmock_generated_actions_test
664 } // namespace testing 668 } // namespace testing
OLDNEW
« no previous file with comments | « testing/gmock/test/gmock-matchers_test.cc ('k') | testing/gmock/test/gmock-nice-strict_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698