From 87e772fa7bf8f29666031d490a61a36aeeb845ae Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 26 Jul 2018 14:30:58 -0700 Subject: Fix RefCountedPtr to handle polymorphism. --- test/core/gprpp/ref_counted_ptr_test.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'test/core/gprpp') 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; 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 { + public: + Parent() {} +}; + +class Child : public Parent { + public: + Child() {} +}; + +void FunctionTakingParent(RefCountedPtr o) {} + +void FunctionTakingChild(RefCountedPtr o) {} + +TEST(RefCountedPtr, CanPassChildToFunctionExpectingParent) { + RefCountedPtr child = MakeRefCounted(); + FunctionTakingParent(child); +} + +TEST(RefCountedPtr, CanPassChildToFunctionExpectingChild) { + RefCountedPtr child = MakeRefCounted(); + FunctionTakingChild(child); +} + } // namespace } // namespace testing } // namespace grpc_core -- cgit v1.2.3