diff options
Diffstat (limited to 'libutils/StrongPointer_test.cpp')
-rw-r--r-- | libutils/StrongPointer_test.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libutils/StrongPointer_test.cpp b/libutils/StrongPointer_test.cpp index d37c1de6f..29f6bd4bb 100644 --- a/libutils/StrongPointer_test.cpp +++ b/libutils/StrongPointer_test.cpp @@ -21,8 +21,8 @@ using namespace android; -class SPFoo : public LightRefBase<SPFoo> { -public: +class SPFoo : virtual public RefBase { + public: explicit SPFoo(bool* deleted_check) : mDeleted(deleted_check) { *mDeleted = false; } @@ -69,3 +69,14 @@ TEST(StrongPointer, PointerComparison) { ASSERT_NE(nullptr, foo); ASSERT_NE(foo, nullptr); } + +TEST(StrongPointer, AssertStrongRefExists) { + // uses some other refcounting method, or non at all + bool isDeleted; + SPFoo* foo = new SPFoo(&isDeleted); + + // can only get a valid sp<> object when you construct it as an sp<> object + EXPECT_DEATH(sp<SPFoo>::fromExisting(foo), ""); + + delete foo; +} |