diff options
author | Yi Kong | 2018-07-16 20:11:34 -0500 |
---|---|---|
committer | Yi Kong | 2018-07-16 20:11:34 -0500 |
commit | e1731a4f2e05f1abb4a45602067708851eaf1e14 (patch) | |
tree | 339c0ce3d3de7d6f5e0fb9bdada9b6210d1d470f /libutils/tests | |
parent | 895acebe946e34d2626716c5c4d7d7f2cc28c39d (diff) | |
download | platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.gz platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.xz platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.zip |
[libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
Diffstat (limited to 'libutils/tests')
-rw-r--r-- | libutils/tests/Looper_test.cpp | 8 | ||||
-rw-r--r-- | libutils/tests/LruCache_test.cpp | 12 | ||||
-rw-r--r-- | libutils/tests/Vector_test.cpp | 6 |
3 files changed, 13 insertions, 13 deletions
diff --git a/libutils/tests/Looper_test.cpp b/libutils/tests/Looper_test.cpp index 8ebcfaf5a..2282ced3d 100644 --- a/libutils/tests/Looper_test.cpp +++ b/libutils/tests/Looper_test.cpp | |||
@@ -339,7 +339,7 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) { | |||
339 | Pipe pipe; | 339 | Pipe pipe; |
340 | 340 | ||
341 | pipe.writeSignal(); | 341 | pipe.writeSignal(); |
342 | mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, NULL, expectedData); | 342 | mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, nullptr, expectedData); |
343 | 343 | ||
344 | StopWatch stopWatch("pollOnce"); | 344 | StopWatch stopWatch("pollOnce"); |
345 | int fd; | 345 | int fd; |
@@ -364,7 +364,7 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) { | |||
364 | 364 | ||
365 | TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) { | 365 | TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) { |
366 | Pipe pipe; | 366 | Pipe pipe; |
367 | int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, NULL, NULL); | 367 | int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, nullptr, nullptr); |
368 | 368 | ||
369 | EXPECT_EQ(1, result) | 369 | EXPECT_EQ(1, result) |
370 | << "addFd should return 1 because FD was added"; | 370 | << "addFd should return 1 because FD was added"; |
@@ -372,7 +372,7 @@ TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) { | |||
372 | 372 | ||
373 | TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) { | 373 | TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) { |
374 | Pipe pipe; | 374 | Pipe pipe; |
375 | int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, NULL, NULL); | 375 | int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, nullptr, nullptr); |
376 | 376 | ||
377 | EXPECT_EQ(-1, result) | 377 | EXPECT_EQ(-1, result) |
378 | << "addFd should return -1 because arguments were invalid"; | 378 | << "addFd should return -1 because arguments were invalid"; |
@@ -381,7 +381,7 @@ TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) { | |||
381 | TEST_F(LooperTest, AddFd_WhenNoCallbackAndAllowNonCallbacksIsFalse_ReturnsError) { | 381 | TEST_F(LooperTest, AddFd_WhenNoCallbackAndAllowNonCallbacksIsFalse_ReturnsError) { |
382 | Pipe pipe; | 382 | Pipe pipe; |
383 | sp<Looper> looper = new Looper(false /*allowNonCallbacks*/); | 383 | sp<Looper> looper = new Looper(false /*allowNonCallbacks*/); |
384 | int result = looper->addFd(pipe.receiveFd, 0, 0, NULL, NULL); | 384 | int result = looper->addFd(pipe.receiveFd, 0, 0, nullptr, nullptr); |
385 | 385 | ||
386 | EXPECT_EQ(-1, result) | 386 | EXPECT_EQ(-1, result) |
387 | << "addFd should return -1 because arguments were invalid"; | 387 | << "addFd should return -1 because arguments were invalid"; |
diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp index 4e885bba4..c4d917b40 100644 --- a/libutils/tests/LruCache_test.cpp +++ b/libutils/tests/LruCache_test.cpp | |||
@@ -110,7 +110,7 @@ template<> inline android::hash_t hash_type(const KeyFailsOnCopy& value) { | |||
110 | 110 | ||
111 | class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> { | 111 | class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> { |
112 | public: | 112 | public: |
113 | EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(NULL) { } | 113 | EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(nullptr) { } |
114 | ~EntryRemovedCallback() {} | 114 | ~EntryRemovedCallback() {} |
115 | void operator()(SimpleKey& k, StringValue& v) { | 115 | void operator()(SimpleKey& k, StringValue& v) { |
116 | callbackCount += 1; | 116 | callbackCount += 1; |
@@ -153,7 +153,7 @@ protected: | |||
153 | TEST_F(LruCacheTest, Empty) { | 153 | TEST_F(LruCacheTest, Empty) { |
154 | LruCache<SimpleKey, StringValue> cache(100); | 154 | LruCache<SimpleKey, StringValue> cache(100); |
155 | 155 | ||
156 | EXPECT_EQ(NULL, cache.get(0)); | 156 | EXPECT_EQ(nullptr, cache.get(0)); |
157 | EXPECT_EQ(0u, cache.size()); | 157 | EXPECT_EQ(0u, cache.size()); |
158 | } | 158 | } |
159 | 159 | ||
@@ -175,7 +175,7 @@ TEST_F(LruCacheTest, MaxCapacity) { | |||
175 | cache.put(1, "one"); | 175 | cache.put(1, "one"); |
176 | cache.put(2, "two"); | 176 | cache.put(2, "two"); |
177 | cache.put(3, "three"); | 177 | cache.put(3, "three"); |
178 | EXPECT_EQ(NULL, cache.get(1)); | 178 | EXPECT_EQ(nullptr, cache.get(1)); |
179 | EXPECT_STREQ("two", cache.get(2)); | 179 | EXPECT_STREQ("two", cache.get(2)); |
180 | EXPECT_STREQ("three", cache.get(3)); | 180 | EXPECT_STREQ("three", cache.get(3)); |
181 | EXPECT_EQ(2u, cache.size()); | 181 | EXPECT_EQ(2u, cache.size()); |
@@ -188,7 +188,7 @@ TEST_F(LruCacheTest, RemoveLru) { | |||
188 | cache.put(2, "two"); | 188 | cache.put(2, "two"); |
189 | cache.put(3, "three"); | 189 | cache.put(3, "three"); |
190 | cache.removeOldest(); | 190 | cache.removeOldest(); |
191 | EXPECT_EQ(NULL, cache.get(1)); | 191 | EXPECT_EQ(nullptr, cache.get(1)); |
192 | EXPECT_STREQ("two", cache.get(2)); | 192 | EXPECT_STREQ("two", cache.get(2)); |
193 | EXPECT_STREQ("three", cache.get(3)); | 193 | EXPECT_STREQ("three", cache.get(3)); |
194 | EXPECT_EQ(2u, cache.size()); | 194 | EXPECT_EQ(2u, cache.size()); |
@@ -203,7 +203,7 @@ TEST_F(LruCacheTest, GetUpdatesLru) { | |||
203 | EXPECT_STREQ("one", cache.get(1)); | 203 | EXPECT_STREQ("one", cache.get(1)); |
204 | cache.removeOldest(); | 204 | cache.removeOldest(); |
205 | EXPECT_STREQ("one", cache.get(1)); | 205 | EXPECT_STREQ("one", cache.get(1)); |
206 | EXPECT_EQ(NULL, cache.get(2)); | 206 | EXPECT_EQ(nullptr, cache.get(2)); |
207 | EXPECT_STREQ("three", cache.get(3)); | 207 | EXPECT_STREQ("three", cache.get(3)); |
208 | EXPECT_EQ(2u, cache.size()); | 208 | EXPECT_EQ(2u, cache.size()); |
209 | } | 209 | } |
@@ -230,7 +230,7 @@ TEST_F(LruCacheTest, StressTest) { | |||
230 | int index = random() % kNumKeys; | 230 | int index = random() % kNumKeys; |
231 | uint32_t key = hash_int(index); | 231 | uint32_t key = hash_int(index); |
232 | const char *val = cache.get(key); | 232 | const char *val = cache.get(key); |
233 | if (val != NULL) { | 233 | if (val != nullptr) { |
234 | EXPECT_EQ(strings[index], val); | 234 | EXPECT_EQ(strings[index], val); |
235 | hitCount++; | 235 | hitCount++; |
236 | } else { | 236 | } else { |
diff --git a/libutils/tests/Vector_test.cpp b/libutils/tests/Vector_test.cpp index e074a921d..5336c40c3 100644 --- a/libutils/tests/Vector_test.cpp +++ b/libutils/tests/Vector_test.cpp | |||
@@ -98,7 +98,7 @@ TEST_F(VectorTest, _grow_OverflowSize) { | |||
98 | 98 | ||
99 | // Checks that the size calculation (not the capacity calculation) doesn't | 99 | // Checks that the size calculation (not the capacity calculation) doesn't |
100 | // overflow : the size here will be (1 + SIZE_MAX). | 100 | // overflow : the size here will be (1 + SIZE_MAX). |
101 | EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size overflow"); | 101 | EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, SIZE_MAX), "new_size overflow"); |
102 | } | 102 | } |
103 | 103 | ||
104 | TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { | 104 | TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { |
@@ -106,14 +106,14 @@ TEST_F(VectorTest, _grow_OverflowCapacityDoubling) { | |||
106 | 106 | ||
107 | // This should fail because the calculated capacity will overflow even though | 107 | // This should fail because the calculated capacity will overflow even though |
108 | // the size of the vector doesn't. | 108 | // the size of the vector doesn't. |
109 | EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity overflow"); | 109 | EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, (SIZE_MAX - 1)), "new_capacity overflow"); |
110 | } | 110 | } |
111 | 111 | ||
112 | TEST_F(VectorTest, _grow_OverflowBufferAlloc) { | 112 | TEST_F(VectorTest, _grow_OverflowBufferAlloc) { |
113 | Vector<int> vector; | 113 | Vector<int> vector; |
114 | // This should fail because the capacity * sizeof(int) overflows, even | 114 | // This should fail because the capacity * sizeof(int) overflows, even |
115 | // though the capacity itself doesn't. | 115 | // though the capacity itself doesn't. |
116 | EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); | 116 | EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, (SIZE_MAX / 2)), "new_alloc_size overflow"); |
117 | } | 117 | } |
118 | 118 | ||
119 | TEST_F(VectorTest, editArray_Shared) { | 119 | TEST_F(VectorTest, editArray_Shared) { |