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

Unified Diff: base/memory/ref_counted_unittest.cc

Issue 758803002: Enable boolean testing of scoped_refptr<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup-defs
Patch Set: Newline Created 6 years, 1 month 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 7e73bde1155db44e11eb2bdf071091782a648ce6..f75cd38f19c86d530237200e37792a2cde9480eb 100644
--- a/base/memory/ref_counted_unittest.cc
+++ b/base/memory/ref_counted_unittest.cc
@@ -10,9 +10,19 @@
namespace {
class SelfAssign : public base::RefCounted<SelfAssign> {
+ protected:
+ virtual ~SelfAssign() {}
+
+ private:
friend class base::RefCounted<SelfAssign>;
+};
+
+class Derived : public SelfAssign {
+ protected:
+ ~Derived() override {}
- ~SelfAssign() {}
+ private:
+ friend class base::RefCounted<Derived>;
};
class CheckDerivedMemberAccess : public scoped_refptr<SelfAssign> {
@@ -72,3 +82,34 @@ TEST(RefCountedUnitTest, ScopedRefPtrToOpaque) {
base::TestOpaqueRefCounted(p);
base::TestOpaqueRefCounted(q);
}
+
+TEST(RefCountedUnitTest, BooleanTesting) {
+ scoped_refptr<SelfAssign> p;
+ EXPECT_FALSE(p);
+ p = new SelfAssign;
+ EXPECT_TRUE(p);
+}
+
+TEST(RefCountedUnitTest, Equality) {
+ scoped_refptr<SelfAssign> p1(new SelfAssign);
+ scoped_refptr<SelfAssign> p2(new SelfAssign);
+
+ EXPECT_EQ(p1, p1);
+ EXPECT_EQ(p2, p2);
+
+ EXPECT_NE(p1, p2);
+ EXPECT_NE(p2, p1);
+}
+
+TEST(RefCountedUnitTest, ConvertibleEquality) {
+ scoped_refptr<Derived> p1(new Derived);
+ scoped_refptr<SelfAssign> p2;
+
+ EXPECT_NE(p1, p2);
+ EXPECT_NE(p2, p1);
+
+ p2 = p1;
+
+ EXPECT_EQ(p1, p2);
+ EXPECT_EQ(p2, p1);
+}
« 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