aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2018-07-27 08:04:24 -0700
committerGravatar Mark D. Roth <roth@google.com>2018-07-27 08:04:24 -0700
commit326f82e5e25a8144cc0566cf2cf61bcdc0cd25f4 (patch)
tree8c8ddc5a2b793856cc03d1b3f112fe799b9df527 /test
parent78aca7bf85fee5eb9c47b430ce20452cec1faf2d (diff)
A bit of cleanup and add more tests.
Diffstat (limited to 'test')
-rw-r--r--test/core/gprpp/ref_counted_ptr_test.cc57
1 files changed, 45 insertions, 12 deletions
diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc
index 6df6e348c6..1e030c5ba3 100644
--- a/test/core/gprpp/ref_counted_ptr_test.cc
+++ b/test/core/gprpp/ref_counted_ptr_test.cc
@@ -175,28 +175,61 @@ TEST(RefCountedPtr, RefCountedWithTracing) {
foo->Unref(DEBUG_LOCATION, "foo");
}
-class Parent : public RefCounted<Parent> {
+class BaseClass : public RefCounted<BaseClass> {
public:
- Parent() {}
+ BaseClass() {}
};
-class Child : public Parent {
+class Subclass : public BaseClass {
public:
- Child() {}
+ Subclass() {}
};
-void FunctionTakingParent(RefCountedPtr<Parent> o) {}
+void FunctionTakingBaseClass(RefCountedPtr<BaseClass> p) {}
-void FunctionTakingChild(RefCountedPtr<Child> o) {}
+void FunctionTakingSubclass(RefCountedPtr<Subclass> p) {}
-TEST(RefCountedPtr, CanPassChildToFunctionExpectingParent) {
- RefCountedPtr<Child> child = MakeRefCounted<Child>();
- FunctionTakingParent(child);
+TEST(RefCountedPtr, ConstructFromSubclass) {
+ RefCountedPtr<BaseClass> p(New<Subclass>());
}
-TEST(RefCountedPtr, CanPassChildToFunctionExpectingChild) {
- RefCountedPtr<Child> child = MakeRefCounted<Child>();
- FunctionTakingChild(child);
+TEST(RefCountedPtr, CopyAssignFromSubclass) {
+ RefCountedPtr<BaseClass> b;
+ EXPECT_EQ(nullptr, b.get());
+ RefCountedPtr<Subclass> s = MakeRefCounted<Subclass>();
+ b = s;
+ EXPECT_NE(nullptr, b.get());
+}
+
+TEST(RefCountedPtr, MoveAssignFromSubclass) {
+ RefCountedPtr<BaseClass> b;
+ EXPECT_EQ(nullptr, b.get());
+ RefCountedPtr<Subclass> s = MakeRefCounted<Subclass>();
+ b = std::move(s);
+ EXPECT_NE(nullptr, b.get());
+}
+
+TEST(RefCountedPtr, ResetFromSubclass) {
+ RefCountedPtr<BaseClass> b;
+ EXPECT_EQ(nullptr, b.get());
+ b.reset(New<Subclass>());
+ EXPECT_NE(nullptr, b.get());
+}
+
+TEST(RefCountedPtr, EqualityWithSubclass) {
+ Subclass* s = New<Subclass>();
+ RefCountedPtr<BaseClass> b(s);
+ EXPECT_EQ(b, s);
+}
+
+TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingBaseClass) {
+ RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>();
+ FunctionTakingBaseClass(p);
+}
+
+TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingSubclass) {
+ RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>();
+ FunctionTakingSubclass(p);
}
} // namespace