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

Side by Side Diff: base/gmock_unittest.cc

Issue 1302233003: Replace gmock's deprecated SetArgumentPointee with SetArgPointee. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017 Created 3 years, 7 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 | « no previous file | base/nix/xdg_util_unittest.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This test is a simple sanity check to make sure gmock is able to build/link 5 // This test is a simple sanity check to make sure gmock is able to build/link
6 // correctly. It just instantiates a mock object and runs through a couple of 6 // correctly. It just instantiates a mock object and runs through a couple of
7 // the basic mock features. 7 // the basic mock features.
8 8
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 // Gmock matchers and actions that we use below. 12 // Gmock matchers and actions that we use below.
13 using testing::AnyOf; 13 using testing::AnyOf;
14 using testing::Eq; 14 using testing::Eq;
15 using testing::Return; 15 using testing::Return;
16 using testing::SetArgumentPointee; 16 using testing::SetArgPointee;
17 using testing::WithArg; 17 using testing::WithArg;
18 using testing::_; 18 using testing::_;
19 19
20 namespace { 20 namespace {
21 21
22 // Simple class that we can mock out the behavior for. Everything is virtual 22 // Simple class that we can mock out the behavior for. Everything is virtual
23 // for easy mocking. 23 // for easy mocking.
24 class SampleClass { 24 class SampleClass {
25 public: 25 public:
26 SampleClass() {} 26 SampleClass() {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 EXPECT_CALL(mock, ReturnNothingConstly()).Times(2); 78 EXPECT_CALL(mock, ReturnNothingConstly()).Times(2);
79 mock.ReturnNothingConstly(); 79 mock.ReturnNothingConstly();
80 mock.ReturnNothingConstly(); 80 mock.ReturnNothingConstly();
81 } 81 }
82 82
83 TEST(GmockTest, AssignArgument) { 83 TEST(GmockTest, AssignArgument) {
84 // Capture an argument for examination. 84 // Capture an argument for examination.
85 MockSampleClass mock; 85 MockSampleClass mock;
86 86
87 EXPECT_CALL(mock, OutputParam(_)) 87 EXPECT_CALL(mock, OutputParam(_)).WillRepeatedly(SetArgPointee<0>(5));
88 .WillRepeatedly(SetArgumentPointee<0>(5));
89 88
90 int arg = 0; 89 int arg = 0;
91 mock.OutputParam(&arg); 90 mock.OutputParam(&arg);
92 EXPECT_EQ(5, arg); 91 EXPECT_EQ(5, arg);
93 } 92 }
94 93
95 TEST(GmockTest, SideEffects) { 94 TEST(GmockTest, SideEffects) {
96 // Capture an argument for examination. 95 // Capture an argument for examination.
97 MockSampleClass mock; 96 MockSampleClass mock;
98 97
99 EXPECT_CALL(mock, OutputParam(_)) 98 EXPECT_CALL(mock, OutputParam(_)).WillRepeatedly(SetArgPointee<0>(5));
100 .WillRepeatedly(SetArgumentPointee<0>(5));
101 99
102 int arg = 0; 100 int arg = 0;
103 mock.OutputParam(&arg); 101 mock.OutputParam(&arg);
104 EXPECT_EQ(5, arg); 102 EXPECT_EQ(5, arg);
105 } 103 }
106 104
107 TEST(GmockTest, CustomAction_ReturnSecond) { 105 TEST(GmockTest, CustomAction_ReturnSecond) {
108 // Test a mock of the ReturnSecond behavior using an action that provides an 106 // Test a mock of the ReturnSecond behavior using an action that provides an
109 // alternate implementation of the function. Danger here though, this is 107 // alternate implementation of the function. Danger here though, this is
110 // starting to add too much behavior of the mock, which means the mock 108 // starting to add too much behavior of the mock, which means the mock
(...skipping 17 matching lines...) Expand all
128 EXPECT_CALL(mock, ReturnSecond(_, AnyOf(Eq(4), Eq(5)))) 126 EXPECT_CALL(mock, ReturnSecond(_, AnyOf(Eq(4), Eq(5))))
129 .WillRepeatedly(WithArg<1>(ReturnVal())); 127 .WillRepeatedly(WithArg<1>(ReturnVal()));
130 EXPECT_EQ(4, mock.ReturnSecond(-1, 4)); 128 EXPECT_EQ(4, mock.ReturnSecond(-1, 4));
131 EXPECT_EQ(5, mock.ReturnSecond(0, 5)); 129 EXPECT_EQ(5, mock.ReturnSecond(0, 5));
132 EXPECT_EQ(4, mock.ReturnSecond(0xdeadbeef, 4)); 130 EXPECT_EQ(4, mock.ReturnSecond(0xdeadbeef, 4));
133 EXPECT_EQ(4, mock.ReturnSecond(112358, 4)); 131 EXPECT_EQ(4, mock.ReturnSecond(112358, 4));
134 EXPECT_EQ(5, mock.ReturnSecond(1337, 5)); 132 EXPECT_EQ(5, mock.ReturnSecond(1337, 5));
135 } 133 }
136 134
137 } // namespace 135 } // namespace
OLDNEW
« no previous file with comments | « no previous file | base/nix/xdg_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698