Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test/allocator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ static void TestAtomicOps() {
static void TestCalloc(size_t n, size_t s, bool ok) {
char* p = reinterpret_cast<char*>(calloc(n, s));
if (!ok) {
EXPECT_EQ(NULL, p) << "calloc(n, s) should not succeed";
EXPECT_EQ(nullptr, p) << "calloc(n, s) should not succeed";
} else {
EXPECT_NE(reinterpret_cast<void*>(NULL), p) <<
EXPECT_NE(static_cast<void*>(nullptr), p) <<
"calloc(n, s) should succeed";
for (size_t i = 0; i < n*s; i++) {
EXPECT_EQ('\0', p[i]);
Expand All @@ -301,7 +301,7 @@ static void TestOneNewWithoutExceptions(void* (*func)(size_t),
// success test
try {
void* ptr = (*func)(kNotTooBig);
EXPECT_NE(reinterpret_cast<void*>(NULL), ptr) <<
EXPECT_NE(static_cast<void*>(nullptr), ptr) <<
"allocation should not have failed.";
} catch(...) {
EXPECT_EQ(0, 1) << "allocation threw unexpected exception.";
Expand All @@ -310,7 +310,7 @@ static void TestOneNewWithoutExceptions(void* (*func)(size_t),
// failure test
try {
void* rv = (*func)(kTooBig);
EXPECT_EQ(NULL, rv);
EXPECT_EQ(nullptr, rv);
EXPECT_FALSE(should_throw) << "allocation should have thrown.";
} catch(...) {
EXPECT_TRUE(should_throw) << "allocation threw unexpected exception.";
Expand Down Expand Up @@ -422,7 +422,7 @@ TEST(Allocators, Realloc2) {
EXPECT_TRUE(Valid(dst, min(src_size, dst_size)));
Fill(dst, dst_size);
EXPECT_TRUE(Valid(dst, dst_size));
if (dst != NULL) free(dst);
if (dst != nullptr) free(dst);
}
}

Expand All @@ -449,12 +449,12 @@ TEST(Allocators, Realloc2) {
}

TEST(Allocators, ReallocZero) {
// Test that realloc to zero does not return NULL.
// Test that realloc to zero does not return nullptr.
for (int size = 0; size >= 0; size = NextSize(size)) {
char* ptr = reinterpret_cast<char*>(malloc(size));
EXPECT_NE(static_cast<char*>(NULL), ptr);
EXPECT_NE(static_cast<char*>(nullptr), ptr);
ptr = reinterpret_cast<char*>(realloc(ptr, 0));
EXPECT_NE(static_cast<char*>(NULL), ptr);
EXPECT_NE(static_cast<char*>(nullptr), ptr);
if (ptr)
free(ptr);
}
Expand All @@ -466,15 +466,15 @@ TEST(Allocators, Recalloc) {
for (int src_size = 0; src_size >= 0; src_size = NextSize(src_size)) {
for (int dst_size = 0; dst_size >= 0; dst_size = NextSize(dst_size)) {
unsigned char* src =
reinterpret_cast<unsigned char*>(_recalloc(NULL, 1, src_size));
reinterpret_cast<unsigned char*>(_recalloc(nullptr, 1, src_size));
EXPECT_TRUE(IsZeroed(src, src_size));
Fill(src, src_size);
unsigned char* dst =
reinterpret_cast<unsigned char*>(_recalloc(src, 1, dst_size));
EXPECT_TRUE(Valid(dst, min(src_size, dst_size)));
Fill(dst, dst_size);
EXPECT_TRUE(Valid(dst, dst_size));
if (dst != NULL)
if (dst != nullptr)
free(dst);
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/at_exit_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ExpectCounter1IsZero(void* unused) {
}

void ExpectParamIsNull(void* param) {
EXPECT_EQ(static_cast<void*>(NULL), param);
EXPECT_EQ(static_cast<void*>(nullptr), param);
}

void ExpectParamIsCounter(void* param) {
Expand All @@ -47,9 +47,9 @@ class AtExitTest : public testing::Test {

TEST_F(AtExitTest, Basic) {
ZeroTestCounters();
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter2, NULL);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, nullptr);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter2, nullptr);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, nullptr);

EXPECT_EQ(0, g_test_counter_1);
EXPECT_EQ(0, g_test_counter_2);
Expand All @@ -60,9 +60,9 @@ TEST_F(AtExitTest, Basic) {

TEST_F(AtExitTest, LIFOOrder) {
ZeroTestCounters();
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, NULL);
butil::AtExitManager::RegisterCallback(&ExpectCounter1IsZero, NULL);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter2, NULL);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter1, nullptr);
butil::AtExitManager::RegisterCallback(&ExpectCounter1IsZero, nullptr);
butil::AtExitManager::RegisterCallback(&IncrementTestCounter2, nullptr);

EXPECT_EQ(0, g_test_counter_1);
EXPECT_EQ(0, g_test_counter_2);
Expand All @@ -72,7 +72,7 @@ TEST_F(AtExitTest, LIFOOrder) {
}

TEST_F(AtExitTest, Param) {
butil::AtExitManager::RegisterCallback(&ExpectParamIsNull, NULL);
butil::AtExitManager::RegisterCallback(&ExpectParamIsNull, nullptr);
butil::AtExitManager::RegisterCallback(&ExpectParamIsCounter,
&g_test_counter_1);
butil::AtExitManager::ProcessCallbacksNow();
Expand Down
46 changes: 23 additions & 23 deletions test/baidu_thread_local_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace {

BAIDU_THREAD_LOCAL int * dummy = NULL;
BAIDU_THREAD_LOCAL int * dummy = nullptr;
const size_t NTHREAD = 8;
static bool processed[NTHREAD+1];
static bool deleted[NTHREAD+1];
Expand Down Expand Up @@ -70,15 +70,15 @@ void* foo(void* arg) {
x = arg;
usleep(10000);
printf("x=%p\n", x);
return NULL;
return nullptr;
}

TEST_F(BaiduThreadLocalTest, thread_local_keyword) {
pthread_t th[2];
pthread_create(&th[0], NULL, foo, (void*)1);
pthread_create(&th[1], NULL, foo, (void*)2);
pthread_join(th[0], NULL);
pthread_join(th[1], NULL);
pthread_create(&th[0], nullptr, foo, (void*)1);
pthread_create(&th[1], nullptr, foo, (void*)2);
pthread_join(th[0], nullptr);
pthread_join(th[1], nullptr);
}

void* yell(void*) {
Expand All @@ -89,7 +89,7 @@ void* yell(void*) {
EXPECT_EQ(p, butil::get_thread_local<YellObj>());
EXPECT_EQ(2, YellObj::nc);
EXPECT_EQ(0, YellObj::nd);
return NULL;
return nullptr;
}

TEST_F(BaiduThreadLocalTest, get_thread_local) {
Expand All @@ -103,8 +103,8 @@ TEST_F(BaiduThreadLocalTest, get_thread_local) {
ASSERT_EQ(1, YellObj::nc);
ASSERT_EQ(0, YellObj::nd);
pthread_t th;
ASSERT_EQ(0, pthread_create(&th, NULL, yell, NULL));
pthread_join(th, NULL);
ASSERT_EQ(0, pthread_create(&th, nullptr, yell, nullptr));
pthread_join(th, nullptr);
EXPECT_EQ(2, YellObj::nc);
EXPECT_EQ(1, YellObj::nd);
}
Expand All @@ -113,7 +113,7 @@ void delete_dummy(void* arg) {
*(bool*)arg = true;
if (dummy) {
delete dummy;
dummy = NULL;
dummy = nullptr;
} else {
printf("dummy is NULL\n");
}
Expand All @@ -122,15 +122,15 @@ void delete_dummy(void* arg) {
void* proc_dummy(void* arg) {
bool *p = (bool*)arg;
*p = true;
EXPECT_TRUE(dummy == NULL);
EXPECT_TRUE(dummy == nullptr);
dummy = new int(p - processed);
butil::thread_atexit(delete_dummy, deleted + (p - processed));
return NULL;
return nullptr;
}

TEST_F(BaiduThreadLocalTest, sanity) {
errno = 0;
ASSERT_EQ(-1, butil::thread_atexit(NULL));
ASSERT_EQ(-1, butil::thread_atexit(nullptr));
ASSERT_EQ(EINVAL, errno);

processed[NTHREAD] = false;
Expand All @@ -141,18 +141,18 @@ TEST_F(BaiduThreadLocalTest, sanity) {
for (size_t i = 0; i < NTHREAD; ++i) {
processed[i] = false;
deleted[i] = false;
ASSERT_EQ(0, pthread_create(&th[i], NULL, proc_dummy, processed + i));
ASSERT_EQ(0, pthread_create(&th[i], nullptr, proc_dummy, processed + i));
}
for (size_t i = 0; i < NTHREAD; ++i) {
ASSERT_EQ(0, pthread_join(th[i], NULL));
ASSERT_EQ(0, pthread_join(th[i], nullptr));
ASSERT_TRUE(processed[i]);
ASSERT_TRUE(deleted[i]);
}
}

static std::ostringstream* oss = NULL;
static std::ostringstream* oss = nullptr;
inline std::ostringstream& get_oss() {
if (oss == NULL) {
if (oss == nullptr) {
oss = new std::ostringstream;
}
return *oss;
Expand Down Expand Up @@ -181,8 +181,8 @@ static void check_result() {
}

TEST_F(BaiduThreadLocalTest, call_order_and_cancel) {
butil::thread_atexit_cancel(NULL);
butil::thread_atexit_cancel(NULL, NULL);
butil::thread_atexit_cancel(nullptr);
butil::thread_atexit_cancel(nullptr, nullptr);

ASSERT_EQ(0, butil::thread_atexit(check_result));

Expand All @@ -192,12 +192,12 @@ TEST_F(BaiduThreadLocalTest, call_order_and_cancel) {
ASSERT_EQ(0, butil::thread_atexit(fun3, (void*)1));
ASSERT_EQ(0, butil::thread_atexit(fun3, (void*)1));
ASSERT_EQ(0, butil::thread_atexit(fun3, (void*)2));
ASSERT_EQ(0, butil::thread_atexit(fun4, NULL));
ASSERT_EQ(0, butil::thread_atexit(fun4, nullptr));

butil::thread_atexit_cancel(NULL);
butil::thread_atexit_cancel(NULL, NULL);
butil::thread_atexit_cancel(nullptr);
butil::thread_atexit_cancel(nullptr, nullptr);
butil::thread_atexit_cancel(fun1);
butil::thread_atexit_cancel(fun3, NULL);
butil::thread_atexit_cancel(fun3, nullptr);
butil::thread_atexit_cancel(fun3, (void*)1);
}

Expand Down
2 changes: 1 addition & 1 deletion test/baidu_time_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST(BaiduTimeTest, cost_of_timer) {

t1.start();
for (size_t i = 0; i < N; ++i) {
time(NULL);
time(nullptr);
}
t1.stop();
printf("time(NULL) takes %" PRId64 "ns\n", t1.n_elapsed() / N);
Expand Down
4 changes: 2 additions & 2 deletions test/bounded_queue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TEST(BoundedQueueTest, sanity) {
butil::BoundedQueue<int> q(storage, sizeof(storage), butil::NOT_OWN_STORAGE);
ASSERT_EQ(0ul, q.size());
ASSERT_TRUE(q.empty());
ASSERT_TRUE(NULL == q.top());
ASSERT_TRUE(NULL == q.bottom());
ASSERT_TRUE(nullptr == q.top());
ASSERT_TRUE(nullptr == q.bottom());
for (int i = 1; i <= N; ++i) {
if (i % 2 == 0) {
ASSERT_TRUE(q.push(i));
Expand Down
26 changes: 13 additions & 13 deletions test/brpc_block_pool_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ TEST_F(BlockPoolTest, single_thread) {
void* buf[num];
for (size_t i = 0; i < num; ++i) {
buf[i] = AllocBlock(GetBlockSize(0));
EXPECT_TRUE(buf[i] != NULL);
EXPECT_TRUE(buf[i] != nullptr);
EXPECT_EQ(0, GetBlockType(buf[i]));
}
for (size_t i = 0; i < num; ++i) {
DeallocBlock(buf[i]);
buf[i] = NULL;
buf[i] = nullptr;
}
for (size_t i = 0; i < num; ++i) {
buf[i] = AllocBlock(GetBlockSize(0) + 1);
EXPECT_TRUE(buf[i] != NULL);
EXPECT_TRUE(buf[i] != nullptr);
EXPECT_EQ(1, GetBlockType(buf[i]));
}
for (int i = num - 1; i >= 0; --i) {
DeallocBlock(buf[i]);
buf[i] = NULL;
buf[i] = nullptr;
}
for (size_t i = 0; i < num; ++i) {
buf[i] = AllocBlock(GetBlockSize(2));
EXPECT_TRUE(buf[i] != NULL);
EXPECT_TRUE(buf[i] != nullptr);
EXPECT_EQ(2, GetBlockType(buf[i]));
}
for (int i = num - 1; i >= 0; --i) {
DeallocBlock(buf[i]);
buf[i] = NULL;
buf[i] = nullptr;
}

DestroyBlockPool();
Expand All @@ -95,12 +95,12 @@ static void* AllocAndDealloc(void* arg) {
int iterations = 1000;
while (iterations > 0) {
void* buf = AllocBlock(len);
EXPECT_TRUE(buf != NULL);
EXPECT_TRUE(buf != nullptr);
EXPECT_EQ(i % 3, GetBlockType(buf));
DeallocBlock(buf);
--iterations;
}
return NULL;
return nullptr;
}

TEST_F(BlockPoolTest, multiple_thread) {
Expand Down Expand Up @@ -137,7 +137,7 @@ TEST_F(BlockPoolTest, extend) {
void* buf[num];
for (size_t i = 0; i < num; ++i) {
buf[i] = AllocBlock(65537);
EXPECT_TRUE(buf[i] != NULL);
EXPECT_TRUE(buf[i] != nullptr);
}
EXPECT_EQ(16, GetRegionNum());
for (size_t i = 0; i < num; ++i) {
Expand All @@ -160,7 +160,7 @@ TEST_F(BlockPoolTest, memory_not_enough) {
void* buf[num];
for (size_t i = 0; i < num; ++i) {
buf[i] = AllocBlock(65537);
EXPECT_TRUE(buf[i] != NULL);
EXPECT_TRUE(buf[i] != nullptr);
}
EXPECT_EQ(2, GetRegionNum());
void* tmp = AllocBlock(65536);
Expand All @@ -182,15 +182,15 @@ TEST_F(BlockPoolTest, invalid_use) {
EXPECT_TRUE(InitBlockPool(DummyCallback));

void* buf = AllocBlock(0);
EXPECT_EQ(NULL, buf);
EXPECT_EQ(nullptr, buf);
EXPECT_EQ(EINVAL, errno);

buf = AllocBlock(GetBlockSize(2) + 1);
EXPECT_EQ(NULL, buf);
EXPECT_EQ(nullptr, buf);
EXPECT_EQ(EINVAL, errno);

errno = 0;
DeallocBlock(NULL);
DeallocBlock(nullptr);
EXPECT_EQ(EINVAL, errno);

DestroyBlockPool();
Expand Down
Loading
Loading