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

Unified 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 side-by-side diff with in-line comments
Download patch
« base/memory/ptr_util.h ('K') | « base/memory/ptr_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ptr_util_unittest.cc
diff --git a/base/memory/ptr_util_unittest.cc b/base/memory/ptr_util_unittest.cc
index ecf99bff954a383cdc60d854c33c4c97b6cf1f4b..e5b7a15b1aed643be5168c66a8d4ca85204949ca 100644
--- a/base/memory/ptr_util_unittest.cc
+++ b/base/memory/ptr_util_unittest.cc
@@ -35,4 +35,34 @@ TEST(PtrUtilTest, WrapUnique) {
EXPECT_EQ(0u, DeleteCounter::count());
}
+TEST(PtrUtilTest, MakeUniqueScalar) {
+ auto s = MakeUnique<std::string>();
+ EXPECT_EQ("", *s);
+
+ auto s2 = MakeUnique<std::string>("test");
+ EXPECT_EQ("test", *s2);
+}
+
+TEST(PtrUtilTest, MakeUniqueScalarWithMoveOnlyType) {
+ using MoveOnly = std::unique_ptr<std::string>;
+ auto p = MakeUnique<MoveOnly>(MakeUnique<std::string>("test"));
+ EXPECT_EQ("test", **p);
+}
+
+TEST(PtrUtilTest, MakeUniqueArray) {
+ EXPECT_EQ(0u, DeleteCounter::count());
+ auto a = MakeUnique<DeleteCounter[]>(5);
+ EXPECT_EQ(5u, DeleteCounter::count());
+ a.reset();
+ EXPECT_EQ(0u, DeleteCounter::count());
+}
+
+#if 0
+// TODO(dcheng): Move this into a nocompile test.
+TEST(PtrUtilTest, MakeUniqueArrayWithKnownBounds) {
+ auto a = MakeUnique<DeleteCounter[1]>();
+ auto b = MakeUnique<DeleteCounter[1]>(1);
+}
+#endif
+
} // namespace base
« 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