Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: base/memory/ptr_util_unittest.cc

Issue 1532433002: Add base::MakeUnique to mirror C++14's std::make_unique. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/memory/ptr_util.h ('K') | « base/memory/ptr_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 10
(...skipping 17 matching lines...) Expand all
28 TEST(PtrUtilTest, WrapUnique) { 28 TEST(PtrUtilTest, WrapUnique) {
29 EXPECT_EQ(0u, DeleteCounter::count()); 29 EXPECT_EQ(0u, DeleteCounter::count());
30 DeleteCounter* counter = new DeleteCounter; 30 DeleteCounter* counter = new DeleteCounter;
31 EXPECT_EQ(1u, DeleteCounter::count()); 31 EXPECT_EQ(1u, DeleteCounter::count());
32 std::unique_ptr<DeleteCounter> owned_counter = WrapUnique(counter); 32 std::unique_ptr<DeleteCounter> owned_counter = WrapUnique(counter);
33 EXPECT_EQ(1u, DeleteCounter::count()); 33 EXPECT_EQ(1u, DeleteCounter::count());
34 owned_counter.reset(); 34 owned_counter.reset();
35 EXPECT_EQ(0u, DeleteCounter::count()); 35 EXPECT_EQ(0u, DeleteCounter::count());
36 } 36 }
37 37
38 TEST(PtrUtilTest, MakeUniqueScalar) {
39 auto s = MakeUnique<std::string>();
40 EXPECT_EQ("", *s);
41
42 auto s2 = MakeUnique<std::string>("test");
43 EXPECT_EQ("test", *s2);
44 }
45
46 TEST(PtrUtilTest, MakeUniqueScalarWithMoveOnlyType) {
47 using MoveOnly = std::unique_ptr<std::string>;
48 auto p = MakeUnique<MoveOnly>(MakeUnique<std::string>("test"));
49 EXPECT_EQ("test", **p);
50 }
51
52 TEST(PtrUtilTest, MakeUniqueArray) {
53 EXPECT_EQ(0u, DeleteCounter::count());
54 auto a = MakeUnique<DeleteCounter[]>(5);
55 EXPECT_EQ(5u, DeleteCounter::count());
56 a.reset();
57 EXPECT_EQ(0u, DeleteCounter::count());
58 }
59
60 #if 0
61 // TODO(dcheng): Move this into a nocompile test.
62 TEST(PtrUtilTest, MakeUniqueArrayWithKnownBounds) {
63 auto a = MakeUnique<DeleteCounter[1]>();
64 auto b = MakeUnique<DeleteCounter[1]>(1);
65 }
66 #endif
67
38 } // namespace base 68 } // namespace base
OLDNEW
« base/memory/ptr_util.h ('K') | « base/memory/ptr_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698