Index: base/memory/ref_counted_unittest.cc |
diff --git a/base/memory/ref_counted_unittest.cc b/base/memory/ref_counted_unittest.cc |
index 65c15d26ab1142a15cbd4e419e7badadbe5e6849..e4b0877a305b1aa276f862efe3304fba4426e710 100644 |
--- a/base/memory/ref_counted_unittest.cc |
+++ b/base/memory/ref_counted_unittest.cc |
@@ -6,6 +6,7 @@ |
#include <utility> |
+#include "base/test/gtest_util.h" |
#include "base/test/opaque_ref_counted.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -122,6 +123,17 @@ scoped_refptr<SelfAssign> Overloaded(scoped_refptr<SelfAssign> self_assign) { |
return self_assign; |
} |
+class InitialRefCountIsOne : public base::RefCounted<InitialRefCountIsOne> { |
+ public: |
+ static constexpr base::subtle::StartRefCountFromOneTag kRefCountPreference = |
+ base::subtle::kStartRefCountFromOneTag; |
tzik
2017/03/30 13:16:28
We should probably replace this with a macro.
dcheng
2017/03/30 21:15:25
Sounds good to me.
(To give some background conte
|
+ |
+ InitialRefCountIsOne() {} |
+ |
+ private: |
+ friend class base::RefCounted<InitialRefCountIsOne>; |
+ ~InitialRefCountIsOne() {} |
+}; |
} // end namespace |
@@ -528,3 +540,24 @@ TEST(RefCountedUnitTest, TestOverloadResolutionMove) { |
scoped_refptr<Other> other2(other); |
EXPECT_EQ(other2, Overloaded(std::move(other))); |
} |
+ |
+TEST(RefCountedUnitTest, TestInitialRefCountIsOne) { |
+ scoped_refptr<InitialRefCountIsOne> obj = |
+ base::MakeShared<InitialRefCountIsOne>(); |
+ obj = nullptr; |
+ |
+ scoped_refptr<InitialRefCountIsOne> obj2 = |
+ base::AdoptRef(new InitialRefCountIsOne); |
+ obj2 = nullptr; |
+} |
+ |
+TEST(RefCountedDeathTest, TestAdoptRef) { |
+ EXPECT_DCHECK_DEATH(make_scoped_refptr(new InitialRefCountIsOne)); |
+ |
+ InitialRefCountIsOne* ptr = nullptr; |
+ EXPECT_DCHECK_DEATH(base::AdoptRef(ptr)); |
+ |
+ scoped_refptr<InitialRefCountIsOne> obj = |
+ base::MakeShared<InitialRefCountIsOne>(); |
+ EXPECT_DCHECK_DEATH(base::AdoptRef(obj.get())); |
+} |