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 <stddef.h> 8 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace base { 12 13 namespace { 14 15 class DeleteCounter { 16 public: DeleteCounter()17 DeleteCounter() { ++count_; } ~DeleteCounter()18 ~DeleteCounter() { --count_; } 19 count()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 TEST(PtrUtilTest,WrapUnique)30TEST(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 40 } // namespace base 41