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

Unified Diff: webrtc/base/ptr_util_unittest.cc

Issue 2757893003: Add MakeUnique from chromium and change StunMessage::AddAttribute to take a unique_ptr. (Closed)
Patch Set: add ptr_util.h to rtc_base_approved build target Created 3 years, 9 months 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
« no previous file with comments | « webrtc/base/ptr_util.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/ptr_util_unittest.cc
diff --git a/webrtc/base/ptr_util_unittest.cc b/webrtc/base/ptr_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..22669c52f5609782b532c5cb5f935f5709374273
--- /dev/null
+++ b/webrtc/base/ptr_util_unittest.cc
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2017 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/base/ptr_util.h"
+
+#include <stddef.h>
+#include <string>
+
+#include "webrtc/base/gunit.h"
+
+namespace rtc {
+
+namespace {
+
+class DeleteCounter {
+ public:
+ DeleteCounter() { ++count_; }
+ ~DeleteCounter() { --count_; }
+
+ static size_t count() { return count_; }
+
+ private:
+ static size_t count_;
+};
+
+size_t DeleteCounter::count_ = 0;
+
+} // namespace
+
+TEST(PtrUtilTest, WrapUnique) {
+ EXPECT_EQ(0u, DeleteCounter::count());
+ DeleteCounter* counter = new DeleteCounter;
+ EXPECT_EQ(1u, DeleteCounter::count());
+ std::unique_ptr<DeleteCounter> owned_counter = WrapUnique(counter);
+ EXPECT_EQ(1u, DeleteCounter::count());
+ owned_counter.reset();
+ 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());
+}
+
+} // namespace rtc
« no previous file with comments | « webrtc/base/ptr_util.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698