Loading libutils/tests/Android.bp +25 −15 Original line number Diff line number Diff line Loading @@ -18,33 +18,43 @@ cc_test { name: "libutils_tests", host_supported: true, srcs: [ "BlobCache_test.cpp", "BitSet_test.cpp", "Looper_test.cpp", "LruCache_test.cpp", "RefBase_test.cpp", "String8_test.cpp", "StrongPointer_test.cpp", "SystemClock_test.cpp", "Unicode_test.cpp", "Vector_test.cpp", ], target: { android: { srcs: [ "BlobCache_test.cpp", "SystemClock_test.cpp", ], shared_libs: [ "libz", "liblog", "libcutils", "libutils", ], } cc_test_host { name: "libutils_tests_host", srcs: ["Vector_test.cpp"], }, host: { static_libs: [ "libutils", "liblog", ], }, }, cflags: [ "-Wall", "-Wextra", "-Werror", ], } libutils/tests/StrongPointer_test.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -21,13 +21,13 @@ using namespace android; class Foo : public LightRefBase<Foo> { class SPFoo : public LightRefBase<SPFoo> { public: explicit Foo(bool* deleted_check) : mDeleted(deleted_check) { explicit SPFoo(bool* deleted_check) : mDeleted(deleted_check) { *mDeleted = false; } ~Foo() { ~SPFoo() { *mDeleted = true; } private: Loading @@ -36,13 +36,13 @@ private: TEST(StrongPointer, move) { bool isDeleted; Foo* foo = new Foo(&isDeleted); SPFoo* foo = new SPFoo(&isDeleted); ASSERT_EQ(0, foo->getStrongCount()); ASSERT_FALSE(isDeleted) << "Already deleted...?"; sp<Foo> sp1(foo); sp<SPFoo> sp1(foo); ASSERT_EQ(1, foo->getStrongCount()); { sp<Foo> sp2 = std::move(sp1); sp<SPFoo> sp2 = std::move(sp1); ASSERT_EQ(1, foo->getStrongCount()) << "std::move failed, incremented refcnt"; ASSERT_EQ(nullptr, sp1.get()) << "std::move failed, sp1 is still valid"; // The strong count isn't increasing, let's double check the old object Loading @@ -52,7 +52,7 @@ TEST(StrongPointer, move) { ASSERT_FALSE(isDeleted) << "deleted too early! still has a reference!"; { // Now let's double check it deletes on time sp<Foo> sp2 = std::move(sp1); sp<SPFoo> sp2 = std::move(sp1); } ASSERT_TRUE(isDeleted) << "foo was leaked!"; } Loading
libutils/tests/Android.bp +25 −15 Original line number Diff line number Diff line Loading @@ -18,33 +18,43 @@ cc_test { name: "libutils_tests", host_supported: true, srcs: [ "BlobCache_test.cpp", "BitSet_test.cpp", "Looper_test.cpp", "LruCache_test.cpp", "RefBase_test.cpp", "String8_test.cpp", "StrongPointer_test.cpp", "SystemClock_test.cpp", "Unicode_test.cpp", "Vector_test.cpp", ], target: { android: { srcs: [ "BlobCache_test.cpp", "SystemClock_test.cpp", ], shared_libs: [ "libz", "liblog", "libcutils", "libutils", ], } cc_test_host { name: "libutils_tests_host", srcs: ["Vector_test.cpp"], }, host: { static_libs: [ "libutils", "liblog", ], }, }, cflags: [ "-Wall", "-Wextra", "-Werror", ], }
libutils/tests/StrongPointer_test.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -21,13 +21,13 @@ using namespace android; class Foo : public LightRefBase<Foo> { class SPFoo : public LightRefBase<SPFoo> { public: explicit Foo(bool* deleted_check) : mDeleted(deleted_check) { explicit SPFoo(bool* deleted_check) : mDeleted(deleted_check) { *mDeleted = false; } ~Foo() { ~SPFoo() { *mDeleted = true; } private: Loading @@ -36,13 +36,13 @@ private: TEST(StrongPointer, move) { bool isDeleted; Foo* foo = new Foo(&isDeleted); SPFoo* foo = new SPFoo(&isDeleted); ASSERT_EQ(0, foo->getStrongCount()); ASSERT_FALSE(isDeleted) << "Already deleted...?"; sp<Foo> sp1(foo); sp<SPFoo> sp1(foo); ASSERT_EQ(1, foo->getStrongCount()); { sp<Foo> sp2 = std::move(sp1); sp<SPFoo> sp2 = std::move(sp1); ASSERT_EQ(1, foo->getStrongCount()) << "std::move failed, incremented refcnt"; ASSERT_EQ(nullptr, sp1.get()) << "std::move failed, sp1 is still valid"; // The strong count isn't increasing, let's double check the old object Loading @@ -52,7 +52,7 @@ TEST(StrongPointer, move) { ASSERT_FALSE(isDeleted) << "deleted too early! still has a reference!"; { // Now let's double check it deletes on time sp<Foo> sp2 = std::move(sp1); sp<SPFoo> sp2 = std::move(sp1); } ASSERT_TRUE(isDeleted) << "foo was leaked!"; }