From 401d69aa946b68c3d58f46c1c12b1ef5533025a5 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 18 Feb 2020 14:03:05 -0800 Subject: libutils: introduce sp::make This is in preparation of doing what we did for SharedRefBase (hiding operator new) so that clients can't accidentally construct shared_ptr/unique_ptr or any other alternative memory management scheme which would conflict with RefBase. You can see what ultimately happened to SharedRefBase in frameworks/native CL 10d9ddf2e3da3ba3a425fb8396aaaec728e5fbdb. The goal for this: - promote use of 'sp::make' over 'sp .. = new T' - make 'operator new' a private member of RefBase Bug: 138956784 Test: libutils_test Change-Id: I47f4d28edbf7534730c7b6fb1de748dd60f34e11 --- libutils/StrongPointer_test.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'libutils/StrongPointer_test.cpp') diff --git a/libutils/StrongPointer_test.cpp b/libutils/StrongPointer_test.cpp index 7b2e37f27..d37c1de6f 100644 --- a/libutils/StrongPointer_test.cpp +++ b/libutils/StrongPointer_test.cpp @@ -36,10 +36,8 @@ private: TEST(StrongPointer, move) { bool isDeleted; - SPFoo* foo = new SPFoo(&isDeleted); - ASSERT_EQ(0, foo->getStrongCount()); - ASSERT_FALSE(isDeleted) << "Already deleted...?"; - sp sp1(foo); + sp sp1 = sp::make(&isDeleted); + SPFoo* foo = sp1.get(); ASSERT_EQ(1, foo->getStrongCount()); { sp sp2 = std::move(sp1); @@ -65,7 +63,7 @@ TEST(StrongPointer, NullptrComparison) { TEST(StrongPointer, PointerComparison) { bool isDeleted; - sp foo = new SPFoo(&isDeleted); + sp foo = sp::make(&isDeleted); ASSERT_EQ(foo.get(), foo); ASSERT_EQ(foo, foo.get()); ASSERT_NE(nullptr, foo); -- cgit v1.2.3