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