blob: ecf99bff954a383cdc60d854c33c4c97b6cf1f4b [file] [log] [blame]
dcheng2ba07d1f2015-12-14 20:07:141// 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
9namespace base {
10
11namespace {
12
13class 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
24size_t DeleteCounter::count_ = 0;
25
26} // namespace
27
28TEST(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