Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
dcheng | 2ba07d1f | 2015-12-14 20:07:14 | [diff] [blame] | 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/memory/ptr_util.h" |
| 6 | |
avi | 9beac25 | 2015-12-24 08:44:47 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
dcheng | 2ba07d1f | 2015-12-14 20:07:14 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
| 11 | namespace base { |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | class DeleteCounter { |
| 16 | public: |
| 17 | DeleteCounter() { ++count_; } |
| 18 | ~DeleteCounter() { --count_; } |
| 19 | |
| 20 | static size_t count() { return count_; } |
| 21 | |
| 22 | private: |
| 23 | static size_t count_; |
| 24 | }; |
| 25 | |
| 26 | size_t DeleteCounter::count_ = 0; |
| 27 | |
| 28 | } // namespace |
| 29 | |
| 30 | TEST(PtrUtilTest, WrapUnique) { |
| 31 | EXPECT_EQ(0u, DeleteCounter::count()); |
| 32 | DeleteCounter* counter = new DeleteCounter; |
| 33 | EXPECT_EQ(1u, DeleteCounter::count()); |
| 34 | std::unique_ptr<DeleteCounter> owned_counter = WrapUnique(counter); |
| 35 | EXPECT_EQ(1u, DeleteCounter::count()); |
| 36 | owned_counter.reset(); |
| 37 | EXPECT_EQ(0u, DeleteCounter::count()); |
| 38 | } |
| 39 | |
dcheng | 2ba07d1f | 2015-12-14 20:07:14 | [diff] [blame] | 40 | } // namespace base |