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

Side by Side Diff: base/bind_unittest.cc

Issue 8073012: Callback API Change: Allow Bind() to take a Callback<> and bind all its free parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/bind_internal.h.pump ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/bind.h" 5 #include "base/bind.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 147
148 int ArrayGet(const int array[], int n) { 148 int ArrayGet(const int array[], int n) {
149 return array[n]; 149 return array[n];
150 } 150 }
151 151
152 int Sum(int a, int b, int c, int d, int e, int f) { 152 int Sum(int a, int b, int c, int d, int e, int f) {
153 return a + b + c + d + e + f; 153 return a + b + c + d + e + f;
154 } 154 }
155 155
156 void OutputSum(int* output, int a, int b, int c, int d, int e) {
157 *output = a + b + c + d + e;
158 }
159
156 const char* CStringIdentity(const char* s) { 160 const char* CStringIdentity(const char* s) {
157 return s; 161 return s;
158 } 162 }
159 163
160 int GetCopies(const CopyCounter& counter) { 164 int GetCopies(const CopyCounter& counter) {
161 return counter.copies(); 165 return counter.copies();
162 } 166 }
163 167
164 int UnwrapNoRefParent(NoRefParent p) { 168 int UnwrapNoRefParent(NoRefParent p) {
165 return p.value; 169 return p.value;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 Callback<int(int,int,int,int)> c4 = Bind(&Sum, 32, 16); 240 Callback<int(int,int,int,int)> c4 = Bind(&Sum, 32, 16);
237 EXPECT_EQ(94, c4.Run(13, 12, 11, 10)); 241 EXPECT_EQ(94, c4.Run(13, 12, 11, 10));
238 242
239 Callback<int(int,int,int,int,int)> c5 = Bind(&Sum, 32); 243 Callback<int(int,int,int,int,int)> c5 = Bind(&Sum, 32);
240 EXPECT_EQ(87, c5.Run(13, 12, 11, 10, 9)); 244 EXPECT_EQ(87, c5.Run(13, 12, 11, 10, 9));
241 245
242 Callback<int(int,int,int,int,int,int)> c6 = Bind(&Sum); 246 Callback<int(int,int,int,int,int,int)> c6 = Bind(&Sum);
243 EXPECT_EQ(69, c6.Run(13, 12, 11, 10, 9, 14)); 247 EXPECT_EQ(69, c6.Run(13, 12, 11, 10, 9, 14));
244 } 248 }
245 249
250 // Bind should be able to take existing Callbacks and convert to a Closure.
251 TEST_F(BindTest, CallbackBindMore) {
252 int output = 0;
253 Closure c;
254
255 Callback<void(int)> c1 = Bind(&OutputSum, &output, 16, 8, 4, 2);
256 c = Bind(c1, 10);
257 c.Run();
258 EXPECT_EQ(40, output);
259
260 Callback<void(int,int)> c2 = Bind(&OutputSum, &output, 16, 8, 4);
261 c = Bind(c2, 10, 9);
262 c.Run();
263 EXPECT_EQ(47, output);
264
265 Callback<void(int,int,int)> c3 = Bind(&OutputSum, &output, 16, 8);
266 c = Bind(c3, 10, 9, 8);
267 c.Run();
268 EXPECT_EQ(51, output);
269
270 Callback<void(int,int,int,int)> c4 = Bind(&OutputSum, &output, 16);
271 c = Bind(c4, 10, 9, 8, 7);
272 c.Run();
273 EXPECT_EQ(50, output);
274
275 Callback<void(int,int,int,int,int)> c5 = Bind(&OutputSum, &output);
276 c = Bind(c5, 10, 9, 8, 7, 6);
277 c.Run();
278 EXPECT_EQ(40, output);
279 }
280
246 // Function type support. 281 // Function type support.
247 // - Normal function. 282 // - Normal function.
248 // - Normal function bound with non-refcounted first argument. 283 // - Normal function bound with non-refcounted first argument.
249 // - Method bound to non-const object. 284 // - Method bound to non-const object.
250 // - Const method bound to non-const object. 285 // - Const method bound to non-const object.
251 // - Const method bound to const object. 286 // - Const method bound to const object.
252 // - Derived classes can be used with pointers to non-virtual base functions. 287 // - Derived classes can be used with pointers to non-virtual base functions.
253 // - Derived classes can be used with pointers to virtual base functions (and 288 // - Derived classes can be used with pointers to virtual base functions (and
254 // preserve virtual dispatch). 289 // preserve virtual dispatch).
255 TEST_F(BindTest, FunctionTypeSupport) { 290 TEST_F(BindTest, FunctionTypeSupport) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); 639 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1);
605 EXPECT_EQ(1, fastcall_cb.Run()); 640 EXPECT_EQ(1, fastcall_cb.Run());
606 641
607 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); 642 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2);
608 EXPECT_EQ(2, stdcall_cb.Run()); 643 EXPECT_EQ(2, stdcall_cb.Run());
609 } 644 }
610 #endif 645 #endif
611 646
612 } // namespace 647 } // namespace
613 } // namespace base 648 } // namespace base
OLDNEW
« no previous file with comments | « base/bind_internal.h.pump ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698