summaryrefslogtreecommitdiff
path: root/libutils/StrongPointer_test.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-12-19 16:32:00 -0800
committerSteven Moreland <smoreland@google.com>2020-01-17 22:50:30 +0000
commit306f8b571302dc9977d6ecd4aeb130ee9ee6dfdc (patch)
treecf84ef51e3fa31b144e7de02d76bf987fe447e5b /libutils/StrongPointer_test.cpp
parente2dad0a29664f3444b3c5cb07aac9e4669c9ee33 (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.cpp15
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);
+}