| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 std::move(cb3).Run(); | 1296 std::move(cb3).Run(); |
| 1297 std::move(cb5).Run(); | 1297 std::move(cb5).Run(); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 TEST_F(BindTest, OnceCallback) { | 1300 TEST_F(BindTest, OnceCallback) { |
| 1301 // Check if Callback variants have declarations of conversions as expected. | 1301 // Check if Callback variants have declarations of conversions as expected. |
| 1302 // Copy constructor and assignment of RepeatingCallback. | 1302 // Copy constructor and assignment of RepeatingCallback. |
| 1303 static_assert(std::is_constructible< | 1303 static_assert(std::is_constructible< |
| 1304 RepeatingClosure, const RepeatingClosure&>::value, | 1304 RepeatingClosure, const RepeatingClosure&>::value, |
| 1305 "RepeatingClosure should be copyable."); | 1305 "RepeatingClosure should be copyable."); |
| 1306 static_assert(is_assignable< | 1306 static_assert( |
| 1307 RepeatingClosure, const RepeatingClosure&>::value, | 1307 std::is_assignable<RepeatingClosure, const RepeatingClosure&>::value, |
| 1308 "RepeatingClosure should be copy-assignable."); | 1308 "RepeatingClosure should be copy-assignable."); |
| 1309 | 1309 |
| 1310 // Move constructor and assignment of RepeatingCallback. | 1310 // Move constructor and assignment of RepeatingCallback. |
| 1311 static_assert(std::is_constructible< | 1311 static_assert(std::is_constructible< |
| 1312 RepeatingClosure, RepeatingClosure&&>::value, | 1312 RepeatingClosure, RepeatingClosure&&>::value, |
| 1313 "RepeatingClosure should be movable."); | 1313 "RepeatingClosure should be movable."); |
| 1314 static_assert(is_assignable< | 1314 static_assert(std::is_assignable<RepeatingClosure, RepeatingClosure&&>::value, |
| 1315 RepeatingClosure, RepeatingClosure&&>::value, | 1315 "RepeatingClosure should be move-assignable"); |
| 1316 "RepeatingClosure should be move-assignable"); | |
| 1317 | 1316 |
| 1318 // Conversions from OnceCallback to RepeatingCallback. | 1317 // Conversions from OnceCallback to RepeatingCallback. |
| 1319 static_assert(!std::is_constructible< | 1318 static_assert(!std::is_constructible< |
| 1320 RepeatingClosure, const OnceClosure&>::value, | 1319 RepeatingClosure, const OnceClosure&>::value, |
| 1321 "OnceClosure should not be convertible to RepeatingClosure."); | 1320 "OnceClosure should not be convertible to RepeatingClosure."); |
| 1322 static_assert(!is_assignable< | 1321 static_assert( |
| 1323 RepeatingClosure, const OnceClosure&>::value, | 1322 !std::is_assignable<RepeatingClosure, const OnceClosure&>::value, |
| 1324 "OnceClosure should not be convertible to RepeatingClosure."); | 1323 "OnceClosure should not be convertible to RepeatingClosure."); |
| 1325 | 1324 |
| 1326 // Destructive conversions from OnceCallback to RepeatingCallback. | 1325 // Destructive conversions from OnceCallback to RepeatingCallback. |
| 1327 static_assert(!std::is_constructible< | 1326 static_assert(!std::is_constructible< |
| 1328 RepeatingClosure, OnceClosure&&>::value, | 1327 RepeatingClosure, OnceClosure&&>::value, |
| 1329 "OnceClosure should not be convertible to RepeatingClosure."); | 1328 "OnceClosure should not be convertible to RepeatingClosure."); |
| 1330 static_assert(!is_assignable< | 1329 static_assert(!std::is_assignable<RepeatingClosure, OnceClosure&&>::value, |
| 1331 RepeatingClosure, OnceClosure&&>::value, | 1330 "OnceClosure should not be convertible to RepeatingClosure."); |
| 1332 "OnceClosure should not be convertible to RepeatingClosure."); | |
| 1333 | 1331 |
| 1334 // Copy constructor and assignment of OnceCallback. | 1332 // Copy constructor and assignment of OnceCallback. |
| 1335 static_assert(!std::is_constructible< | 1333 static_assert(!std::is_constructible< |
| 1336 OnceClosure, const OnceClosure&>::value, | 1334 OnceClosure, const OnceClosure&>::value, |
| 1337 "OnceClosure should not be copyable."); | 1335 "OnceClosure should not be copyable."); |
| 1338 static_assert(!is_assignable< | 1336 static_assert(!std::is_assignable<OnceClosure, const OnceClosure&>::value, |
| 1339 OnceClosure, const OnceClosure&>::value, | 1337 "OnceClosure should not be copy-assignable"); |
| 1340 "OnceClosure should not be copy-assignable"); | |
| 1341 | 1338 |
| 1342 // Move constructor and assignment of OnceCallback. | 1339 // Move constructor and assignment of OnceCallback. |
| 1343 static_assert(std::is_constructible< | 1340 static_assert(std::is_constructible< |
| 1344 OnceClosure, OnceClosure&&>::value, | 1341 OnceClosure, OnceClosure&&>::value, |
| 1345 "OnceClosure should be movable."); | 1342 "OnceClosure should be movable."); |
| 1346 static_assert(is_assignable< | 1343 static_assert(std::is_assignable<OnceClosure, OnceClosure&&>::value, |
| 1347 OnceClosure, OnceClosure&&>::value, | 1344 "OnceClosure should be move-assignable."); |
| 1348 "OnceClosure should be move-assignable."); | |
| 1349 | 1345 |
| 1350 // Conversions from RepeatingCallback to OnceCallback. | 1346 // Conversions from RepeatingCallback to OnceCallback. |
| 1351 static_assert(std::is_constructible< | 1347 static_assert(std::is_constructible< |
| 1352 OnceClosure, const RepeatingClosure&>::value, | 1348 OnceClosure, const RepeatingClosure&>::value, |
| 1353 "RepeatingClosure should be convertible to OnceClosure."); | 1349 "RepeatingClosure should be convertible to OnceClosure."); |
| 1354 static_assert(is_assignable< | 1350 static_assert(std::is_assignable<OnceClosure, const RepeatingClosure&>::value, |
| 1355 OnceClosure, const RepeatingClosure&>::value, | 1351 "RepeatingClosure should be convertible to OnceClosure."); |
| 1356 "RepeatingClosure should be convertible to OnceClosure."); | |
| 1357 | 1352 |
| 1358 // Destructive conversions from RepeatingCallback to OnceCallback. | 1353 // Destructive conversions from RepeatingCallback to OnceCallback. |
| 1359 static_assert(std::is_constructible< | 1354 static_assert(std::is_constructible< |
| 1360 OnceClosure, RepeatingClosure&&>::value, | 1355 OnceClosure, RepeatingClosure&&>::value, |
| 1361 "RepeatingClosure should be convertible to OnceClosure."); | 1356 "RepeatingClosure should be convertible to OnceClosure."); |
| 1362 static_assert(is_assignable< | 1357 static_assert(std::is_assignable<OnceClosure, RepeatingClosure&&>::value, |
| 1363 OnceClosure, RepeatingClosure&&>::value, | 1358 "RepeatingClosure should be covretible to OnceClosure."); |
| 1364 "RepeatingClosure should be covretible to OnceClosure."); | |
| 1365 | 1359 |
| 1366 OnceClosure cb = BindOnce(&VoidPolymorphic<>::Run); | 1360 OnceClosure cb = BindOnce(&VoidPolymorphic<>::Run); |
| 1367 std::move(cb).Run(); | 1361 std::move(cb).Run(); |
| 1368 | 1362 |
| 1369 // RepeatingCallback should be convertible to OnceCallback. | 1363 // RepeatingCallback should be convertible to OnceCallback. |
| 1370 OnceClosure cb2 = BindRepeating(&VoidPolymorphic<>::Run); | 1364 OnceClosure cb2 = BindRepeating(&VoidPolymorphic<>::Run); |
| 1371 std::move(cb2).Run(); | 1365 std::move(cb2).Run(); |
| 1372 | 1366 |
| 1373 RepeatingClosure cb3 = BindRepeating(&VoidPolymorphic<>::Run); | 1367 RepeatingClosure cb3 = BindRepeating(&VoidPolymorphic<>::Run); |
| 1374 cb = cb3; | 1368 cb = cb3; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 | 1404 |
| 1411 // Test null callbacks cause a DCHECK. | 1405 // Test null callbacks cause a DCHECK. |
| 1412 TEST(BindDeathTest, NullCallback) { | 1406 TEST(BindDeathTest, NullCallback) { |
| 1413 base::Callback<void(int)> null_cb; | 1407 base::Callback<void(int)> null_cb; |
| 1414 ASSERT_TRUE(null_cb.is_null()); | 1408 ASSERT_TRUE(null_cb.is_null()); |
| 1415 EXPECT_DCHECK_DEATH(base::Bind(null_cb, 42)); | 1409 EXPECT_DCHECK_DEATH(base::Bind(null_cb, 42)); |
| 1416 } | 1410 } |
| 1417 | 1411 |
| 1418 } // namespace | 1412 } // namespace |
| 1419 } // namespace base | 1413 } // namespace base |
| OLD | NEW |