diff options
author | Steven Moreland <smoreland@google.com> | 2019-12-19 16:32:00 -0800 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2020-01-17 22:50:30 +0000 |
commit | 306f8b571302dc9977d6ecd4aeb130ee9ee6dfdc (patch) | |
tree | cf84ef51e3fa31b144e7de02d76bf987fe447e5b /libutils/StrongPointer_test.cpp | |
parent | e2dad0a29664f3444b3c5cb07aac9e4669c9ee33 (diff) |
libutils: sp lh comparison w/ pointer
Perhaps the better question is, why have I 100s of times, typed
"ASSERT_NE(nullptr, foo)" for sp<> foo, and got a compiler error and
then change it to "foo.get()". This CL so we can stop wasting cycles
with that error.
Fixes: 147842528
Test: libutils_test
Change-Id: Id63b29d2a1ff3077201a62b69d864c5a826c47e0
Diffstat (limited to 'libutils/StrongPointer_test.cpp')
-rw-r--r-- | libutils/StrongPointer_test.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libutils/StrongPointer_test.cpp b/libutils/StrongPointer_test.cpp index 153cf9683..7b2e37f27 100644 --- a/libutils/StrongPointer_test.cpp +++ b/libutils/StrongPointer_test.cpp @@ -56,3 +56,18 @@ TEST(StrongPointer, move) { } ASSERT_TRUE(isDeleted) << "foo was leaked!"; } + +TEST(StrongPointer, NullptrComparison) { + sp<SPFoo> foo; + ASSERT_EQ(foo, nullptr); + ASSERT_EQ(nullptr, foo); +} + +TEST(StrongPointer, PointerComparison) { + bool isDeleted; + sp<SPFoo> foo = new SPFoo(&isDeleted); + ASSERT_EQ(foo.get(), foo); + ASSERT_EQ(foo, foo.get()); + ASSERT_NE(nullptr, foo); + ASSERT_NE(foo, nullptr); +} |