aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/gprpp
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2018-07-26 14:30:58 -0700
committerGravatar Mark D. Roth <roth@google.com>2018-07-26 14:30:58 -0700
commit87e772fa7bf8f29666031d490a61a36aeeb845ae (patch)
treedab42358501634753522dc7d3d9581faf0309976 /test/core/gprpp
parent334d47ee0d0c910d81544164ed44db89ba2eca43 (diff)
Fix RefCountedPtr to handle polymorphism.
Diffstat (limited to 'test/core/gprpp')
-rw-r--r--test/core/gprpp/ref_counted_ptr_test.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc
index aa30b72282..6df6e348c6 100644
--- a/test/core/gprpp/ref_counted_ptr_test.cc
+++ b/test/core/gprpp/ref_counted_ptr_test.cc
@@ -127,7 +127,7 @@ TEST(RefCountedPtr, ResetFromNonNullToNull) {
TEST(RefCountedPtr, ResetFromNullToNull) {
RefCountedPtr<Foo> foo;
EXPECT_EQ(nullptr, foo.get());
- foo.reset(nullptr);
+ foo.reset();
EXPECT_EQ(nullptr, foo.get());
}
@@ -175,6 +175,30 @@ TEST(RefCountedPtr, RefCountedWithTracing) {
foo->Unref(DEBUG_LOCATION, "foo");
}
+class Parent : public RefCounted<Parent> {
+ public:
+ Parent() {}
+};
+
+class Child : public Parent {
+ public:
+ Child() {}
+};
+
+void FunctionTakingParent(RefCountedPtr<Parent> o) {}
+
+void FunctionTakingChild(RefCountedPtr<Child> o) {}
+
+TEST(RefCountedPtr, CanPassChildToFunctionExpectingParent) {
+ RefCountedPtr<Child> child = MakeRefCounted<Child>();
+ FunctionTakingParent(child);
+}
+
+TEST(RefCountedPtr, CanPassChildToFunctionExpectingChild) {
+ RefCountedPtr<Child> child = MakeRefCounted<Child>();
+ FunctionTakingChild(child);
+}
+
} // namespace
} // namespace testing
} // namespace grpc_core