aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/gprpp
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2018-02-06 07:58:17 -0800
committerGravatar Mark D. Roth <roth@google.com>2018-02-06 07:58:17 -0800
commit08d9f3df3038a88d7ae69aa9e65da29e296946d2 (patch)
treed5c58f8a6f5ec4ee33283815821cafd854a24bf7 /test/core/gprpp
parent007f1197ac6376cd6a77dca141966ba3aceec9aa (diff)
Change Ref() methods to return a RefCountedPtr<>.
Diffstat (limited to 'test/core/gprpp')
-rw-r--r--test/core/gprpp/orphanable_test.cc20
-rw-r--r--test/core/gprpp/ref_counted_ptr_test.cc7
-rw-r--r--test/core/gprpp/ref_counted_test.cc13
3 files changed, 25 insertions, 15 deletions
diff --git a/test/core/gprpp/orphanable_test.cc b/test/core/gprpp/orphanable_test.cc
index ff2f6d8bc2..ad6b9ac867 100644
--- a/test/core/gprpp/orphanable_test.cc
+++ b/test/core/gprpp/orphanable_test.cc
@@ -58,18 +58,19 @@ TEST(MakeOrphanable, WithParameters) {
EXPECT_EQ(5, foo->value());
}
-class Bar : public InternallyRefCounted {
+class Bar : public InternallyRefCounted<Bar> {
public:
Bar() : Bar(0) {}
explicit Bar(int value) : value_(value) {}
void Orphan() override { Unref(); }
int value() const { return value_; }
- void StartWork() { Ref(); }
- void FinishWork() { Unref(); }
+ void StartWork() { self_ref_ = Ref(); }
+ void FinishWork() { self_ref_.reset(); }
private:
int value_;
+ RefCountedPtr<Bar> self_ref_;
};
TEST(OrphanablePtr, InternallyRefCounted) {
@@ -82,19 +83,24 @@ TEST(OrphanablePtr, InternallyRefCounted) {
// things build properly in both debug and non-debug cases.
DebugOnlyTraceFlag baz_tracer(true, "baz");
-class Baz : public InternallyRefCountedWithTracing {
+class Baz : public InternallyRefCountedWithTracing<Baz> {
public:
Baz() : Baz(0) {}
explicit Baz(int value)
- : InternallyRefCountedWithTracing(&baz_tracer), value_(value) {}
+ : InternallyRefCountedWithTracing<Baz>(&baz_tracer), value_(value) {}
void Orphan() override { Unref(); }
int value() const { return value_; }
- void StartWork() { Ref(DEBUG_LOCATION, "work"); }
- void FinishWork() { Unref(DEBUG_LOCATION, "work"); }
+ void StartWork() { self_ref_ = Ref(DEBUG_LOCATION, "work"); }
+ void FinishWork() {
+ // This is a little ugly, but it makes the logged ref and unref match up.
+ self_ref_.release();
+ Unref(DEBUG_LOCATION, "work");
+ }
private:
int value_;
+ RefCountedPtr<Baz> self_ref_;
};
TEST(OrphanablePtr, InternallyRefCountedWithTracing) {
diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc
index f1f13f3183..2e398a7722 100644
--- a/test/core/gprpp/ref_counted_ptr_test.cc
+++ b/test/core/gprpp/ref_counted_ptr_test.cc
@@ -30,7 +30,7 @@ namespace grpc_core {
namespace testing {
namespace {
-class Foo : public RefCounted {
+class Foo : public RefCounted<Foo> {
public:
Foo() : value_(0) {}
@@ -163,14 +163,15 @@ TEST(MakeRefCounted, Args) {
TraceFlag foo_tracer(true, "foo");
-class FooWithTracing : public RefCountedWithTracing {
+class FooWithTracing : public RefCountedWithTracing<FooWithTracing> {
public:
FooWithTracing() : RefCountedWithTracing(&foo_tracer) {}
};
TEST(RefCountedPtr, RefCountedWithTracing) {
RefCountedPtr<FooWithTracing> foo(New<FooWithTracing>());
- foo->Ref(DEBUG_LOCATION, "foo");
+ RefCountedPtr<FooWithTracing> foo2 = foo->Ref(DEBUG_LOCATION, "foo");
+ foo2.release();
foo->Unref(DEBUG_LOCATION, "foo");
}
diff --git a/test/core/gprpp/ref_counted_test.cc b/test/core/gprpp/ref_counted_test.cc
index b1b0fee5c0..f85a2e4675 100644
--- a/test/core/gprpp/ref_counted_test.cc
+++ b/test/core/gprpp/ref_counted_test.cc
@@ -27,7 +27,7 @@ namespace grpc_core {
namespace testing {
namespace {
-class Foo : public RefCounted {
+class Foo : public RefCounted<Foo> {
public:
Foo() {}
};
@@ -39,7 +39,8 @@ TEST(RefCounted, Basic) {
TEST(RefCounted, ExtraRef) {
Foo* foo = New<Foo>();
- foo->Ref();
+ RefCountedPtr<Foo> foop = foo->Ref();
+ foop.release();
foo->Unref();
foo->Unref();
}
@@ -48,17 +49,19 @@ TEST(RefCounted, ExtraRef) {
// things build properly in both debug and non-debug cases.
DebugOnlyTraceFlag foo_tracer(true, "foo");
-class FooWithTracing : public RefCountedWithTracing {
+class FooWithTracing : public RefCountedWithTracing<FooWithTracing> {
public:
FooWithTracing() : RefCountedWithTracing(&foo_tracer) {}
};
TEST(RefCountedWithTracing, Basic) {
FooWithTracing* foo = New<FooWithTracing>();
- foo->Ref(DEBUG_LOCATION, "extra_ref");
+ RefCountedPtr<FooWithTracing> foop = foo->Ref(DEBUG_LOCATION, "extra_ref");
+ foop.release();
foo->Unref(DEBUG_LOCATION, "extra_ref");
// Can use the no-argument methods, too.
- foo->Ref();
+ foop = foo->Ref();
+ foop.release();
foo->Unref();
foo->Unref(DEBUG_LOCATION, "original_ref");
}