OLD | NEW |
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 #if defined(BASE_CALLBACK_H_) | 7 #if defined(BASE_CALLBACK_H_) |
8 // We explicitly do not want to include callback.h so people are not tempted | 8 // We explicitly do not want to include callback.h so people are not tempted |
9 // to use bind.h in a headerfile for getting the Callback types. | 9 // to use bind.h in a headerfile for getting the Callback types. |
10 #error "base/bind.h should avoid pulling in callback.h by default." | 10 #error "base/bind.h should avoid pulling in callback.h by default." |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 // Used by the static functions to perform expectations. | 206 // Used by the static functions to perform expectations. |
207 static StrictMock<NoRef>* static_func_mock_ptr; | 207 static StrictMock<NoRef>* static_func_mock_ptr; |
208 | 208 |
209 private: | 209 private: |
210 DISALLOW_COPY_AND_ASSIGN(BindTest); | 210 DISALLOW_COPY_AND_ASSIGN(BindTest); |
211 }; | 211 }; |
212 | 212 |
213 StrictMock<NoRef>* BindTest::static_func_mock_ptr; | 213 StrictMock<NoRef>* BindTest::static_func_mock_ptr; |
214 | 214 |
215 // Ensure we can create unbound callbacks. We need this to be able to store | |
216 // them in class members that can be initialized later. | |
217 TEST_F(BindTest, DefaultConstruction) { | |
218 Callback<void(void)> c0; | |
219 Callback<void(int)> c1; | |
220 Callback<void(int,int)> c2; | |
221 Callback<void(int,int,int)> c3; | |
222 Callback<void(int,int,int,int)> c4; | |
223 Callback<void(int,int,int,int,int)> c5; | |
224 Callback<void(int,int,int,int,int,int)> c6; | |
225 } | |
226 | |
227 // Sanity check that we can instantiate a callback for each arity. | 215 // Sanity check that we can instantiate a callback for each arity. |
228 TEST_F(BindTest, ArityTest) { | 216 TEST_F(BindTest, ArityTest) { |
229 Callback<int(void)> c0 = Bind(&Sum, 32, 16, 8, 4, 2, 1); | 217 Callback<int(void)> c0 = Bind(&Sum, 32, 16, 8, 4, 2, 1); |
230 EXPECT_EQ(63, c0.Run()); | 218 EXPECT_EQ(63, c0.Run()); |
231 | 219 |
232 Callback<int(int)> c1 = Bind(&Sum, 32, 16, 8, 4, 2); | 220 Callback<int(int)> c1 = Bind(&Sum, 32, 16, 8, 4, 2); |
233 EXPECT_EQ(75, c1.Run(13)); | 221 EXPECT_EQ(75, c1.Run(13)); |
234 | 222 |
235 Callback<int(int,int)> c2 = Bind(&Sum, 32, 16, 8, 4); | 223 Callback<int(int,int)> c2 = Bind(&Sum, 32, 16, 8, 4); |
236 EXPECT_EQ(85, c2.Run(13, 12)); | 224 EXPECT_EQ(85, c2.Run(13, 12)); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // - Refcounted types should not be bound as a raw pointer. | 576 // - Refcounted types should not be bound as a raw pointer. |
589 // HasRef for_raw_ptr; | 577 // HasRef for_raw_ptr; |
590 // Callback<void(void)> ref_count_as_raw_ptr = | 578 // Callback<void(void)> ref_count_as_raw_ptr = |
591 // Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); | 579 // Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); |
592 // ASSERT_EQ(&for_raw_ptr, ref_count_as_raw_ptr.Run()); | 580 // ASSERT_EQ(&for_raw_ptr, ref_count_as_raw_ptr.Run()); |
593 | 581 |
594 } | 582 } |
595 | 583 |
596 } // namespace | 584 } // namespace |
597 } // namespace base | 585 } // namespace base |
OLD | NEW |