Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind_helpers.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace base { | |
| 12 | |
| 13 TEST(BindHelpersTest, UnwrapUnretained) { | |
| 14 int i = 0; | |
| 15 auto unretained = Unretained(&i); | |
| 16 EXPECT_EQ(&i, internal::Unwrap(unretained)); | |
|
dcheng
2016/08/19 04:32:15
I feel like we should be testing this at a higher
tzik
2016/08/23 04:00:15
Ok, I updated bind_unittest.cc for Repeating and O
| |
| 17 EXPECT_EQ(&i, internal::Unwrap(std::move(unretained))); | |
| 18 } | |
| 19 | |
| 20 TEST(BindHelpersTest, UnwrapConstRef) { | |
| 21 int p = 0; | |
| 22 auto const_ref = ConstRef(p); | |
| 23 EXPECT_EQ(&p, &internal::Unwrap(const_ref)); | |
| 24 EXPECT_EQ(&p, &internal::Unwrap(std::move(const_ref))); | |
| 25 } | |
| 26 | |
| 27 TEST(BindHelpersTest, UnwrapRetainedRef) { | |
| 28 auto p = make_scoped_refptr(new RefCountedData<int>); | |
| 29 auto retained_ref = RetainedRef(p); | |
| 30 EXPECT_EQ(p.get(), internal::Unwrap(retained_ref)); | |
| 31 EXPECT_EQ(p.get(), internal::Unwrap(std::move(retained_ref))); | |
| 32 } | |
| 33 | |
| 34 TEST(BindHelpersTest, UnwrapOwned) { | |
| 35 int* p = new int; | |
| 36 auto owned = Owned(p); | |
| 37 EXPECT_EQ(p, internal::Unwrap(owned)); | |
| 38 EXPECT_EQ(p, internal::Unwrap(std::move(owned))); | |
| 39 } | |
| 40 | |
| 41 TEST(BindHelpersTest, UnwrapPassed) { | |
| 42 int* p = new int; | |
| 43 auto passed = Passed(WrapUnique(p)); | |
| 44 EXPECT_EQ(p, internal::Unwrap(passed).get()); | |
| 45 | |
| 46 p = new int; | |
| 47 EXPECT_EQ(p, internal::Unwrap(Passed(WrapUnique(p))).get()); | |
| 48 } | |
| 49 | |
| 50 } // namespace base | |
| OLD | NEW |