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

Side by Side Diff: testing/gmock/test/gmock_link_test.h

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_leak_test_.cc ('k') | testing/gmock/test/gmock_output_test.py » ('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 2009, Google Inc. 1 // Copyright 2009, 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 virtual int& IntRefFromString(char* str) = 0; 199 virtual int& IntRefFromString(char* str) = 0;
200 virtual void VoidFromFunc(void(*)(char*)) = 0; 200 virtual void VoidFromFunc(void(*)(char*)) = 0;
201 virtual void VoidFromIntRef(int& n) = 0; 201 virtual void VoidFromIntRef(int& n) = 0;
202 virtual void VoidFromFloat(float n) = 0; 202 virtual void VoidFromFloat(float n) = 0;
203 virtual void VoidFromDouble(double n) = 0; 203 virtual void VoidFromDouble(double n) = 0;
204 virtual void VoidFromVector(const std::vector<int>& v) = 0; 204 virtual void VoidFromVector(const std::vector<int>& v) = 0;
205 }; 205 };
206 206
207 class Mock: public Interface { 207 class Mock: public Interface {
208 public: 208 public:
209 Mock() {}
210
209 MOCK_METHOD1(VoidFromString, void(char* str)); 211 MOCK_METHOD1(VoidFromString, void(char* str));
210 MOCK_METHOD1(StringFromString, char*(char* str)); 212 MOCK_METHOD1(StringFromString, char*(char* str));
211 MOCK_METHOD1(IntFromString, int(char* str)); 213 MOCK_METHOD1(IntFromString, int(char* str));
212 MOCK_METHOD1(IntRefFromString, int&(char* str)); 214 MOCK_METHOD1(IntRefFromString, int&(char* str));
213 MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str))); 215 MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
214 MOCK_METHOD1(VoidFromIntRef, void(int& n)); 216 MOCK_METHOD1(VoidFromIntRef, void(int& n));
215 MOCK_METHOD1(VoidFromFloat, void(float n)); 217 MOCK_METHOD1(VoidFromFloat, void(float n));
216 MOCK_METHOD1(VoidFromDouble, void(double n)); 218 MOCK_METHOD1(VoidFromDouble, void(double n));
217 MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v)); 219 MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
220
221 private:
222 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
218 }; 223 };
219 224
220 class InvokeHelper { 225 class InvokeHelper {
221 public: 226 public:
222 static void StaticVoidFromVoid() {} 227 static void StaticVoidFromVoid() {}
223 void VoidFromVoid() {} 228 void VoidFromVoid() {}
224 static void StaticVoidFromString(char*) {} 229 static void StaticVoidFromString(char*) {}
225 void VoidFromString(char*) {} 230 void VoidFromString(char*) {}
226 static int StaticIntFromString(char*) { return 1; } 231 static int StaticIntFromString(char*) { return 1; }
227 static bool StaticBoolFromString(const char*) { return true; } 232 static bool StaticBoolFromString(const char*) { return true; }
228 }; 233 };
229 234
230 class FieldHelper { 235 class FieldHelper {
231 public: 236 public:
232 FieldHelper(int field) : field_(field) {} 237 FieldHelper(int a_field) : field_(a_field) {}
233 int field() const { return field_; } 238 int field() const { return field_; }
234 int field_; // NOLINT -- need external access to field_ to test 239 int field_; // NOLINT -- need external access to field_ to test
235 // the Field matcher. 240 // the Field matcher.
236 }; 241 };
237 242
238 // Tests the linkage of the ReturnVoid action. 243 // Tests the linkage of the ReturnVoid action.
239 TEST(LinkTest, TestReturnVoid) { 244 TEST(LinkTest, TestReturnVoid) {
240 Mock mock; 245 Mock mock;
241 246
242 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return()); 247 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 #if GTEST_HAS_EXCEPTIONS 408 #if GTEST_HAS_EXCEPTIONS
404 // Tests the linkage of the Throw action. 409 // Tests the linkage of the Throw action.
405 TEST(LinkTest, TestThrow) { 410 TEST(LinkTest, TestThrow) {
406 Mock mock; 411 Mock mock;
407 412
408 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42)); 413 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
409 EXPECT_THROW(mock.VoidFromString(NULL), int); 414 EXPECT_THROW(mock.VoidFromString(NULL), int);
410 } 415 }
411 #endif // GTEST_HAS_EXCEPTIONS 416 #endif // GTEST_HAS_EXCEPTIONS
412 417
418 // The ACTION*() macros trigger warning C4100 (unreferenced formal
419 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
420 // the macro definition, as the warnings are generated when the macro
421 // is expanded and macro expansion cannot contain #pragma. Therefore
422 // we suppress them here.
423 #ifdef _MSC_VER
424 #pragma warning(push)
425 #pragma warning(disable:4100)
426 #endif
427
413 // Tests the linkage of actions created using ACTION macro. 428 // Tests the linkage of actions created using ACTION macro.
414 namespace { 429 namespace {
415 ACTION(Return1) { return 1; } 430 ACTION(Return1) { return 1; }
416 } 431 }
417 432
418 TEST(LinkTest, TestActionMacro) { 433 TEST(LinkTest, TestActionMacro) {
419 Mock mock; 434 Mock mock;
420 435
421 EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1()); 436 EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
422 mock.IntFromString(NULL); 437 mock.IntFromString(NULL);
(...skipping 11 matching lines...) Expand all
434 mock.IntFromString(NULL); 449 mock.IntFromString(NULL);
435 } 450 }
436 451
437 // Tests the linkage of actions created using ACTION_P2 macro. 452 // Tests the linkage of actions created using ACTION_P2 macro.
438 namespace { 453 namespace {
439 ACTION_P2(ReturnEqualsEitherOf, first, second) { 454 ACTION_P2(ReturnEqualsEitherOf, first, second) {
440 return arg0 == first || arg0 == second; 455 return arg0 == first || arg0 == second;
441 } 456 }
442 } 457 }
443 458
459 #ifdef _MSC_VER
460 #pragma warning(pop)
461 #endif
462
444 TEST(LinkTest, TestActionP2Macro) { 463 TEST(LinkTest, TestActionP2Macro) {
445 Mock mock; 464 Mock mock;
446 char ch = 'x'; 465 char ch = 'x';
447 466
448 EXPECT_CALL(mock, IntFromString(_)) 467 EXPECT_CALL(mock, IntFromString(_))
449 .WillOnce(ReturnEqualsEitherOf("one", "two")); 468 .WillOnce(ReturnEqualsEitherOf("one", "two"));
450 mock.IntFromString(&ch); 469 mock.IntFromString(&ch);
451 } 470 }
452 471
453 // Tests the linkage of the "_" matcher. 472 // Tests the linkage of the "_" matcher.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 EXPECT_FALSE(m.Matches(1)); 664 EXPECT_FALSE(m.Matches(1));
646 } 665 }
647 666
648 // Tests the linkage of the MatcherCast<T>() function. 667 // Tests the linkage of the MatcherCast<T>() function.
649 TEST(LinkTest, TestMatcherCast) { 668 TEST(LinkTest, TestMatcherCast) {
650 Matcher<const char*> m = MatcherCast<const char*>(_); 669 Matcher<const char*> m = MatcherCast<const char*>(_);
651 EXPECT_TRUE(m.Matches(NULL)); 670 EXPECT_TRUE(m.Matches(NULL));
652 } 671 }
653 672
654 #endif // GMOCK_TEST_GMOCK_LINK_TEST_H_ 673 #endif // GMOCK_TEST_GMOCK_LINK_TEST_H_
OLDNEW
« no previous file with comments | « testing/gmock/test/gmock_leak_test_.cc ('k') | testing/gmock/test/gmock_output_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698