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

Unified Diff: base/memory/ref_counted_unittest.cc

Issue 2723423002: Start BindStateBase ref count from 1 instead of 0 (Closed)
Patch Set: s/MAKE_REF_COUNT_START_FROM_ONE/REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE()/ 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 | « base/memory/ref_counted_delete_on_sequence.h ('k') | base/memory/ref_counted_unittest.nc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..515f4227eabca63c059e86366f749e64f2943337 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,16 @@ scoped_refptr<SelfAssign> Overloaded(scoped_refptr<SelfAssign> self_assign) {
return self_assign;
}
+class InitialRefCountIsOne : public base::RefCounted<InitialRefCountIsOne> {
+ public:
+ REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE();
+
+ InitialRefCountIsOne() {}
+
+ private:
+ friend class base::RefCounted<InitialRefCountIsOne>;
+ ~InitialRefCountIsOne() {}
+};
} // end namespace
@@ -528,3 +539,30 @@ 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>();
+ EXPECT_TRUE(obj->HasOneRef());
+ obj = nullptr;
+
+ scoped_refptr<InitialRefCountIsOne> obj2 =
+ base::AdoptRef(new InitialRefCountIsOne);
+ EXPECT_TRUE(obj2->HasOneRef());
+ obj2 = nullptr;
+
+ scoped_refptr<Other> obj3 = base::MakeShared<Other>();
+ EXPECT_TRUE(obj3->HasOneRef());
+ obj3 = 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()));
+}
« no previous file with comments | « base/memory/ref_counted_delete_on_sequence.h ('k') | base/memory/ref_counted_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698