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

Unified Diff: base/memory/ref_counted_unittest.cc

Issue 9021020: Fix scoped_refptr assignment operator in the case of having it as a member. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored as joth suggests Created 9 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
« no previous file with comments | « base/memory/ref_counted.h ('k') | no next file » | 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 dcc292f00ddfb024780f2fee88f9daf8dc5793c8..6aa84e17b863942367fc4bf7a6243688b17cfa66 100644
--- a/base/memory/ref_counted_unittest.cc
+++ b/base/memory/ref_counted_unittest.cc
@@ -22,6 +22,27 @@ class CheckDerivedMemberAccess : public scoped_refptr<SelfAssign> {
}
};
+class ScopedRefPtrToSelf : public base::RefCounted<ScopedRefPtrToSelf> {
+ public:
+ ScopedRefPtrToSelf()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(self_ptr_(this)) {
+ }
+ ~ScopedRefPtrToSelf() { was_destroyed_ = true; }
+
+ static bool was_destroyed() { return was_destroyed_; }
+
+ void SelfDestruct() { self_ptr_ = NULL; }
+
+ private:
+ friend class base::RefCounted<ScopedRefPtrToSelf>;
+
+ static bool was_destroyed_;
+
+ scoped_refptr<ScopedRefPtrToSelf> self_ptr_;
+};
+
+bool ScopedRefPtrToSelf::was_destroyed_ = false;
+
} // end namespace
TEST(RefCountedUnitTest, TestSelfAssignment) {
@@ -34,3 +55,10 @@ TEST(RefCountedUnitTest, TestSelfAssignment) {
TEST(RefCountedUnitTest, ScopedRefPtrMemberAccess) {
CheckDerivedMemberAccess check;
}
+
+TEST(RefCountedUnitTest, ScopedRefPtrToSelf) {
+ ScopedRefPtrToSelf* check = new ScopedRefPtrToSelf();
+ EXPECT_FALSE(ScopedRefPtrToSelf::was_destroyed());
+ check->SelfDestruct();
+ EXPECT_TRUE(ScopedRefPtrToSelf::was_destroyed());
+}
« no previous file with comments | « base/memory/ref_counted.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698