diff --git a/test/allocator_unittest.cc b/test/allocator_unittest.cc index dd4fe6d093..37a3f2e650 100644 --- a/test/allocator_unittest.cc +++ b/test/allocator_unittest.cc @@ -276,9 +276,9 @@ static void TestAtomicOps() { static void TestCalloc(size_t n, size_t s, bool ok) { char* p = reinterpret_cast(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(NULL), p) << + EXPECT_NE(static_cast(nullptr), p) << "calloc(n, s) should succeed"; for (size_t i = 0; i < n*s; i++) { EXPECT_EQ('\0', p[i]); @@ -301,7 +301,7 @@ static void TestOneNewWithoutExceptions(void* (*func)(size_t), // success test try { void* ptr = (*func)(kNotTooBig); - EXPECT_NE(reinterpret_cast(NULL), ptr) << + EXPECT_NE(static_cast(nullptr), ptr) << "allocation should not have failed."; } catch(...) { EXPECT_EQ(0, 1) << "allocation threw unexpected exception."; @@ -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."; @@ -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); } } @@ -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(malloc(size)); - EXPECT_NE(static_cast(NULL), ptr); + EXPECT_NE(static_cast(nullptr), ptr); ptr = reinterpret_cast(realloc(ptr, 0)); - EXPECT_NE(static_cast(NULL), ptr); + EXPECT_NE(static_cast(nullptr), ptr); if (ptr) free(ptr); } @@ -466,7 +466,7 @@ 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(_recalloc(NULL, 1, src_size)); + reinterpret_cast(_recalloc(nullptr, 1, src_size)); EXPECT_TRUE(IsZeroed(src, src_size)); Fill(src, src_size); unsigned char* dst = @@ -474,7 +474,7 @@ TEST(Allocators, Recalloc) { 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); } } diff --git a/test/at_exit_unittest.cc b/test/at_exit_unittest.cc index 997c0b68d7..80a08ed321 100644 --- a/test/at_exit_unittest.cc +++ b/test/at_exit_unittest.cc @@ -29,7 +29,7 @@ void ExpectCounter1IsZero(void* unused) { } void ExpectParamIsNull(void* param) { - EXPECT_EQ(static_cast(NULL), param); + EXPECT_EQ(static_cast(nullptr), param); } void ExpectParamIsCounter(void* param) { @@ -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); @@ -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); @@ -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(); diff --git a/test/baidu_thread_local_unittest.cpp b/test/baidu_thread_local_unittest.cpp index 4cc629f3e8..2d2426489b 100644 --- a/test/baidu_thread_local_unittest.cpp +++ b/test/baidu_thread_local_unittest.cpp @@ -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]; @@ -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*) { @@ -89,7 +89,7 @@ void* yell(void*) { EXPECT_EQ(p, butil::get_thread_local()); EXPECT_EQ(2, YellObj::nc); EXPECT_EQ(0, YellObj::nd); - return NULL; + return nullptr; } TEST_F(BaiduThreadLocalTest, get_thread_local) { @@ -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); } @@ -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"); } @@ -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; @@ -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; @@ -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)); @@ -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); } diff --git a/test/baidu_time_unittest.cpp b/test/baidu_time_unittest.cpp index d57418959a..72448b072d 100644 --- a/test/baidu_time_unittest.cpp +++ b/test/baidu_time_unittest.cpp @@ -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); diff --git a/test/bounded_queue_unittest.cc b/test/bounded_queue_unittest.cc index 556e84ed63..4185f3860c 100644 --- a/test/bounded_queue_unittest.cc +++ b/test/bounded_queue_unittest.cc @@ -29,8 +29,8 @@ TEST(BoundedQueueTest, sanity) { butil::BoundedQueue 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)); diff --git a/test/brpc_block_pool_unittest.cpp b/test/brpc_block_pool_unittest.cpp index f65f2a00ce..28b9d55313 100644 --- a/test/brpc_block_pool_unittest.cpp +++ b/test/brpc_block_pool_unittest.cpp @@ -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(); @@ -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) { @@ -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) { @@ -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); @@ -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(); diff --git a/test/brpc_builtin_service_unittest.cpp b/test/brpc_builtin_service_unittest.cpp index da4d6f1026..e4f61e702f 100644 --- a/test/brpc_builtin_service_unittest.cpp +++ b/test/brpc_builtin_service_unittest.cpp @@ -236,7 +236,7 @@ class BuiltinServiceTest : public ::testing::Test{ SetUpController(&cntl, use_html); butil::EndPoint ep; ASSERT_EQ(0, str2endpoint("127.0.0.1:9798", &ep)); - ASSERT_EQ(0, _server.Start(ep, NULL)); + ASSERT_EQ(0, _server.Start(ep, nullptr)); int self_port = -1; const int cfd = tcp_connect(ep, &self_port); ASSERT_GT(cfd, 0); @@ -388,9 +388,9 @@ class BuiltinServiceTest : public ::testing::Test{ brpc::SERVER_OWNS_SERVICE)); butil::EndPoint ep; ASSERT_EQ(0, str2endpoint("127.0.0.1:9748", &ep)); - ASSERT_EQ(0, _server.Start(ep, NULL)); + ASSERT_EQ(0, _server.Start(ep, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init(ep, NULL)); + ASSERT_EQ(0, channel.Init(ep, nullptr)); test::EchoService_Stub stub(&channel); int64_t log_id = 1234567890; char querystr_buf[128]; @@ -402,7 +402,7 @@ class BuiltinServiceTest : public ::testing::Test{ brpc::Controller echo_cntl; echo_req.set_message("hello"); echo_cntl.set_log_id(++log_id); - stub.Echo(&echo_cntl, &echo_req, &echo_res, NULL); + stub.Echo(&echo_cntl, &echo_req, &echo_res, nullptr); EXPECT_FALSE(echo_cntl.Failed()); // Wait for level db to commit span information @@ -426,7 +426,7 @@ class BuiltinServiceTest : public ::testing::Test{ echo_req.set_message("hello"); echo_req.set_sleep_us(150000); echo_cntl.set_log_id(++log_id); - stub.Echo(&echo_cntl, &echo_req, &echo_res, NULL); + stub.Echo(&echo_cntl, &echo_req, &echo_res, nullptr); EXPECT_FALSE(echo_cntl.Failed()); // Wait for level db to commit span information @@ -450,7 +450,7 @@ class BuiltinServiceTest : public ::testing::Test{ std::string request_str(1500, 'a'); echo_req.set_message(request_str); echo_cntl.set_log_id(++log_id); - stub.Echo(&echo_cntl, &echo_req, &echo_res, NULL); + stub.Echo(&echo_cntl, &echo_req, &echo_res, nullptr); EXPECT_FALSE(echo_cntl.Failed()); // Wait for level db to commit span information @@ -473,7 +473,7 @@ class BuiltinServiceTest : public ::testing::Test{ brpc::Controller echo_cntl; echo_req.set_message("hello"); echo_cntl.set_log_id(++log_id); - stub.Echo(&echo_cntl, &echo_req, &echo_res, NULL); + stub.Echo(&echo_cntl, &echo_req, &echo_res, nullptr); EXPECT_FALSE(echo_cntl.Failed()); // Wait for level db to commit span information @@ -560,7 +560,7 @@ TEST_F(BuiltinServiceTest, customized_health) { ASSERT_EQ(0, chan.Init("127.0.0.1:9798", &copt)); brpc::Controller cntl; cntl.http_request().uri() = "/health"; - chan.CallMethod(NULL, &cntl, &req, &res, NULL); + chan.CallMethod(nullptr, &cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ("i'm ok", cntl.response_attachment()); } @@ -597,14 +597,14 @@ TEST_F(BuiltinServiceTest, normal_grpc_health) { brpc::Channel chan; ASSERT_EQ(0, chan.Init("127.0.0.1:9798", &copt)); grpc::health::v1::Health_Stub stub(&chan); - stub.Check(&cntl, &request, &response, NULL); + stub.Check(&cntl, &request, &response, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ(response.status(), grpc::health::v1::HealthCheckResponse_ServingStatus_SERVING); response.Clear(); brpc::Controller cntl1; cntl1.http_request().uri() = "/grpc.health.v1.Health/Check"; - chan.CallMethod(NULL, &cntl1, &request, &response, NULL); + chan.CallMethod(nullptr, &cntl1, &request, &response, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ(response.status(), grpc::health::v1::HealthCheckResponse_ServingStatus_SERVING); } @@ -626,7 +626,7 @@ TEST_F(BuiltinServiceTest, customized_grpc_health) { ASSERT_EQ(0, chan.Init("127.0.0.1:9798", &copt)); grpc::health::v1::Health_Stub stub(&chan); - stub.Check(&cntl, &request, &response, NULL); + stub.Check(&cntl, &request, &response, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ(response.status(), grpc::health::v1::HealthCheckResponse_ServingStatus_UNKNOWN); @@ -653,7 +653,7 @@ TEST_F(BuiltinServiceTest, list) { void* sleep_thread(void*) { sleep(1); - return NULL; + return nullptr; } TEST_F(BuiltinServiceTest, threads) { @@ -663,12 +663,12 @@ TEST_F(BuiltinServiceTest, threads) { brpc::Controller cntl; ClosureChecker done; pthread_t tid; - ASSERT_EQ(0, pthread_create(&tid, NULL, sleep_thread, NULL)); + ASSERT_EQ(0, pthread_create(&tid, nullptr, sleep_thread, nullptr)); service.default_method(&cntl, &req, &res, &done); EXPECT_FALSE(cntl.Failed()); // Doesn't work under gcc 4.8.2 // CheckContent(cntl, "sleep_thread"); - pthread_join(tid, NULL); + pthread_join(tid, nullptr); } TEST_F(BuiltinServiceTest, vlog) { @@ -693,7 +693,7 @@ TEST_F(BuiltinServiceTest, bad_method) { TEST_F(BuiltinServiceTest, vars) { // Start server to show bvars inside - ASSERT_EQ(0, _server.Start("127.0.0.1:9798", NULL)); + ASSERT_EQ(0, _server.Start("127.0.0.1:9798", nullptr)); brpc::VarsService service; brpc::VarsRequest req; brpc::VarsResponse res; @@ -734,7 +734,7 @@ TEST_F(BuiltinServiceTest, pprof) { ClosureChecker done; brpc::Controller cntl; cntl.http_request().uri().SetQuery("seconds", "1"); - service.profile(&cntl, NULL, NULL, &done); + service.profile(&cntl, nullptr, nullptr, &done); // Just for loading symbols in gperftools/profiler.h ProfilerFlush(); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); @@ -743,28 +743,28 @@ TEST_F(BuiltinServiceTest, pprof) { { ClosureChecker done; brpc::Controller cntl; - service.heap(&cntl, NULL, NULL, &done); + service.heap(&cntl, nullptr, nullptr, &done); const int rc = getenv("TCMALLOC_SAMPLE_PARAMETER") != nullptr ? 0 : brpc::ENOMETHOD; EXPECT_EQ(rc, cntl.ErrorCode()) << cntl.ErrorText(); } { ClosureChecker done; brpc::Controller cntl; - service.growth(&cntl, NULL, NULL, &done); + service.growth(&cntl, nullptr, nullptr, &done); // linked tcmalloc in UT EXPECT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText(); } { ClosureChecker done; brpc::Controller cntl; - service.symbol(&cntl, NULL, NULL, &done); + service.symbol(&cntl, nullptr, nullptr, &done); EXPECT_FALSE(cntl.Failed()); CheckContent(cntl, "num_symbols"); } { ClosureChecker done; brpc::Controller cntl; - service.cmdline(&cntl, NULL, NULL, &done); + service.cmdline(&cntl, nullptr, nullptr, &done); EXPECT_FALSE(cntl.Failed()); CheckContent(cntl, "brpc_builtin_service_unittest"); } @@ -832,7 +832,7 @@ TEST_F(BuiltinServiceTest, ids) { } { bthread_id_t id; - EXPECT_EQ(0, bthread_id_create(&id, NULL, NULL)); + EXPECT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); ClosureChecker done; brpc::Controller cntl; std::string id_string; @@ -846,7 +846,7 @@ TEST_F(BuiltinServiceTest, ids) { void* dummy_bthread(void*) { bthread_usleep(1000000); - return NULL; + return nullptr; } @@ -858,7 +858,7 @@ void* bthread_trace(void*) { while (!g_bthread_trace_stop) { bthread_usleep(1000 * 100); } - return NULL; + return nullptr; } #endif // BRPC_BTHREAD_TRACER @@ -919,7 +919,7 @@ TEST_F(BuiltinServiceTest, bthreads) { } { bthread_t th; - EXPECT_EQ(0, bthread_start_background(&th, NULL, dummy_bthread, NULL)); + EXPECT_EQ(0, bthread_start_background(&th, nullptr, dummy_bthread, nullptr)); ClosureChecker done; brpc::Controller cntl; std::string id_string; @@ -934,7 +934,7 @@ TEST_F(BuiltinServiceTest, bthreads) { bool ok = false, check_all_ok = false; for (int i = 0; i < 10; ++i) { bthread_t th; - EXPECT_EQ(0, bthread_start_background(&th, NULL, bthread_trace, NULL)); + EXPECT_EQ(0, bthread_start_background(&th, nullptr, bthread_trace, nullptr)); while (!g_bthread_trace_start) { bthread_usleep(1000 * 10); } @@ -952,7 +952,7 @@ TEST_F(BuiltinServiceTest, bthreads) { content.find("bthread_trace") != std::string::npos; check_all_ok = check_all_bthreads(th, true) && check_all_bthreads(th, false); g_bthread_trace_stop = true; - bthread_join(th, NULL); + bthread_join(th, nullptr); // the `bthread_trace` bthread should not be queried now EXPECT_TRUE(!check_all_bthreads(th, true) && !check_all_bthreads(th, false)); if (ok && check_all_ok) { diff --git a/test/brpc_channel_unittest.cpp b/test/brpc_channel_unittest.cpp index 6f4540d6a2..997859ef76 100644 --- a/test/brpc_channel_unittest.cpp +++ b/test/brpc_channel_unittest.cpp @@ -71,7 +71,7 @@ namespace { void* RunClosure(void* arg) { google::protobuf::Closure* done = (google::protobuf::Closure*)arg; done->Run(); - return NULL; + return nullptr; } void MarkCalled(bool* called) { @@ -127,7 +127,7 @@ static bool VerifyMyRequest(const brpc::InputMessageBase* msg_base) { if (meta.has_authentication_data()) { // Credential MUST only appear in the first packet - EXPECT_TRUE(NULL == ptr->auth_context()); + EXPECT_TRUE(nullptr == ptr->auth_context()); EXPECT_EQ(meta.authentication_data(), MOCK_CREDENTIAL); MyAuthenticator authenticator; return authenticator.VerifyCredential( @@ -267,8 +267,8 @@ class ChannelTest : public ::testing::Test{ { brpc::policy::ParseRpcMessage, brpc::SerializeRequestDefault, brpc::policy::PackRpcRequest, - NULL, ProcessRpcRequest, - VerifyMyRequest, NULL, NULL, + nullptr, ProcessRpcRequest, + VerifyMyRequest, nullptr, nullptr, brpc::CONNECTION_TYPE_ALL, "baidu_std" }; ASSERT_EQ(0, RegisterProtocol((brpc::ProtocolType)30, dummy_protocol)); } @@ -321,7 +321,7 @@ class ChannelTest : public ::testing::Test{ int64_t, brpc::Controller*, brpc::RpcPBMessages*, const brpc::Server*, brpc::MethodStatus*, int64_t, std::shared_ptr>( &brpc::policy::SendRpcResponse, meta.correlation_id(), cntl, - messages, &ts->_dummy, NULL, -1, nullptr); + messages, &ts->_dummy, nullptr, -1, nullptr); ts->_svc.CallMethod(method, cntl, req, res, done); } @@ -334,7 +334,7 @@ class ChannelTest : public ::testing::Test{ return -1; } } - if (_messenger.StartAccept(listening_fd, -1, NULL, false) != 0) { + if (_messenger.StartAccept(listening_fd, -1, nullptr, false) != 0) { return -1; } return 0; @@ -348,7 +348,7 @@ class ChannelTest : public ::testing::Test{ void SetUpChannel(brpc::Channel* channel, bool single_server, bool short_connection, - const brpc::Authenticator* auth = NULL, + const brpc::Authenticator* auth = nullptr, std::string connection_group = std::string(), bool use_backup_request_policy = false, brpc::ProtocolType protocol = brpc::PROTOCOL_BAIDU_STD) { @@ -374,7 +374,7 @@ class ChannelTest : public ::testing::Test{ brpc::Controller* cntl, test::EchoRequest* req, test::EchoResponse* res, bool async, bool destroy = false) { - google::protobuf::Closure* done = NULL; + google::protobuf::Closure* done = nullptr; brpc::CallId sync_id = { 0 }; if (async) { sync_id = cntl->call_id(); @@ -394,7 +394,7 @@ class ChannelTest : public ::testing::Test{ brpc::Controller* cntl, test::ComboRequest* req, test::ComboResponse* res, bool async, bool destroy = false) { - google::protobuf::Closure* done = NULL; + google::protobuf::Closure* done = nullptr; brpc::CallId sync_id = { 0 }; if (async) { sync_id = cntl->call_id(); @@ -441,7 +441,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -469,7 +469,7 @@ class ChannelTest : public ::testing::Test{ for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -504,9 +504,9 @@ class ChannelTest : public ::testing::Test{ << single_server << ", " << async << ", " << short_connection; const uint64_t receiving_socket_id = res.receiving_socket_id(); EXPECT_EQ(0, cntl.sub_count()); - EXPECT_TRUE(NULL == cntl.sub(-1)); - EXPECT_TRUE(NULL == cntl.sub(0)); - EXPECT_TRUE(NULL == cntl.sub(1)); + EXPECT_TRUE(nullptr == cntl.sub(-1)); + EXPECT_TRUE(nullptr == cntl.sub(0)); + EXPECT_TRUE(nullptr == cntl.sub(1)); EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); if (short_connection) { // Sleep to let `_messenger' detect `Socket' being `SetFailed' @@ -534,7 +534,7 @@ class ChannelTest : public ::testing::Test{ // A different connection_group does not reuse the connection brpc::Channel channel3; SetUpChannel(&channel3, single_server, short_connection, - NULL, "another_group"); + nullptr, "another_group"); cntl.Reset(); req.Clear(); res.Clear(); @@ -549,7 +549,7 @@ class ChannelTest : public ::testing::Test{ // note that the leading/trailing spaces should be trimed. brpc::Channel channel4; SetUpChannel(&channel4, single_server, short_connection, - NULL, " another_group "); + nullptr, " another_group "); cntl.Reset(); req.Clear(); res.Clear(); @@ -601,7 +601,7 @@ class ChannelTest : public ::testing::Test{ dynamic_cast(req_base); test::ComboResponse* res = dynamic_cast(res_base); if (method->name() != "ComboEcho" || - res == NULL || req == NULL || + res == nullptr || req == nullptr || req->requests_size() <= channel_index) { return brpc::SubCall::Bad(); } @@ -649,7 +649,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - new SetCode, NULL)); + new SetCode, nullptr)); } brpc::Controller cntl; test::EchoRequest req; @@ -700,7 +700,7 @@ class ChannelTest : public ::testing::Test{ subchan, // subchan should be deleted (for only once) ((i % 2) ? brpc::DOESNT_OWN_CHANNEL : brpc::OWNS_CHANNEL), - set_code, NULL)); + set_code, nullptr)); } ASSERT_EQ((int)NCHANS, set_code->ref_count()); brpc::Controller cntl; @@ -747,7 +747,7 @@ class ChannelTest : public ::testing::Test{ for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; test::EchoRequest req; @@ -790,7 +790,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - new SetCodeOnEven, NULL)); + new SetCodeOnEven, nullptr)); } brpc::Controller cntl; test::EchoRequest req; @@ -804,7 +804,7 @@ class ChannelTest : public ::testing::Test{ EXPECT_EQ(NCHANS, (size_t)cntl.sub_count()); for (int i = 0; i < cntl.sub_count(); ++i) { if (i % 2) { - EXPECT_TRUE(NULL == cntl.sub(i)) << "i=" << i; + EXPECT_TRUE(nullptr == cntl.sub(i)) << "i=" << i; } else { EXPECT_TRUE(cntl.sub(i) && !cntl.sub(i)->Failed()) << "i=" << i; } @@ -904,7 +904,7 @@ class ChannelTest : public ::testing::Test{ for (size_t i = 0; i < NCHANS; ++i) { SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( - &subchans[i], brpc::DOESNT_OWN_CHANNEL, fast_call_mapper, NULL)); + &subchans[i], brpc::DOESNT_OWN_CHANNEL, fast_call_mapper, nullptr)); } brpc::Controller cntl; test::EchoRequest req; @@ -952,7 +952,7 @@ class ChannelTest : public ::testing::Test{ } LOG(INFO) << "Start to cancel cid=" << arg->cid.value; brpc::StartCancel(arg->cid); - return NULL; + return nullptr; } @@ -993,7 +993,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1006,8 +1006,8 @@ class ChannelTest : public ::testing::Test{ CallMethod(&channel, &cntl, &req, &res, async); EXPECT_EQ(ECANCELED, cntl.ErrorCode()) << cntl.ErrorText(); EXPECT_EQ(NCHANS, (size_t)cntl.sub_count()); - EXPECT_TRUE(NULL == cntl.sub(1)); - EXPECT_TRUE(NULL == cntl.sub(0)); + EXPECT_TRUE(nullptr == cntl.sub(1)); + EXPECT_TRUE(nullptr == cntl.sub(0)); StopAndJoin(); } @@ -1021,11 +1021,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1058,18 +1058,18 @@ class ChannelTest : public ::testing::Test{ ASSERT_TRUE(cid.value != 0); pthread_t th; CancelerArg carg = { 10000, cid }; - ASSERT_EQ(0, pthread_create(&th, NULL, Canceler, &carg)); + ASSERT_EQ(0, pthread_create(&th, nullptr, Canceler, &carg)); req.set_sleep_us(carg.sleep_before_cancel_us * 2); butil::Timer tm; tm.start(); CallMethod(&channel, &cntl, &req, &res, async); tm.stop(); EXPECT_LT(labs(tm.u_elapsed() - carg.sleep_before_cancel_us), 10000); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_join(th, nullptr)); EXPECT_EQ(ECANCELED, cntl.ErrorCode()); EXPECT_EQ(0, cntl.sub_count()); - EXPECT_TRUE(NULL == cntl.sub(1)); - EXPECT_TRUE(NULL == cntl.sub(0)); + EXPECT_TRUE(nullptr == cntl.sub(1)); + EXPECT_TRUE(nullptr == cntl.sub(0)); StopAndJoin(); } @@ -1088,7 +1088,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1099,14 +1099,14 @@ class ChannelTest : public ::testing::Test{ ASSERT_TRUE(cid.value != 0); pthread_t th; CancelerArg carg = { 10000, cid }; - ASSERT_EQ(0, pthread_create(&th, NULL, Canceler, &carg)); + ASSERT_EQ(0, pthread_create(&th, nullptr, Canceler, &carg)); req.set_sleep_us(carg.sleep_before_cancel_us * 2); butil::Timer tm; tm.start(); CallMethod(&channel, &cntl, &req, &res, async); tm.stop(); EXPECT_LT(labs(tm.u_elapsed() - carg.sleep_before_cancel_us), 10000); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_join(th, nullptr)); EXPECT_EQ(ECANCELED, cntl.ErrorCode()); EXPECT_EQ(NCHANS, (size_t)cntl.sub_count()); for (int i = 0; i < cntl.sub_count(); ++i) { @@ -1126,11 +1126,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1141,14 +1141,14 @@ class ChannelTest : public ::testing::Test{ ASSERT_TRUE(cid.value != 0); pthread_t th; CancelerArg carg = { 10000, cid }; - ASSERT_EQ(0, pthread_create(&th, NULL, Canceler, &carg)); + ASSERT_EQ(0, pthread_create(&th, nullptr, Canceler, &carg)); req.set_sleep_us(carg.sleep_before_cancel_us * 2); butil::Timer tm; tm.start(); CallMethod(&channel, &cntl, &req, &res, async); tm.stop(); EXPECT_LT(labs(tm.u_elapsed() - carg.sleep_before_cancel_us), 10000); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_join(th, nullptr)); EXPECT_EQ(ECANCELED, cntl.ErrorCode()); EXPECT_EQ(1, cntl.sub_count()); EXPECT_EQ(ECANCELED, cntl.sub(0)->ErrorCode()); @@ -1193,7 +1193,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1272,7 +1272,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1293,11 +1293,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1348,7 +1348,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1398,7 +1398,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - ((i % 2) ? new MakeTheRequestTimeout : NULL), NULL)); + ((i % 2) ? new MakeTheRequestTimeout : nullptr), nullptr)); } brpc::Controller cntl; @@ -1432,11 +1432,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1467,11 +1467,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1512,11 +1512,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 8; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, false, false); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } const int kRounds = 150; @@ -1592,7 +1592,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1624,7 +1624,7 @@ class ChannelTest : public ::testing::Test{ for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1675,7 +1675,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } brpc::Controller cntl; @@ -1699,11 +1699,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 5; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } brpc::Controller cntl; @@ -1759,7 +1759,7 @@ class ChannelTest : public ::testing::Test{ brpc::Channel* subchan = new brpc::Channel(); SetUpChannel(subchan, single_server, short_connection); ASSERT_EQ(0, channel->AddChannel( - subchan, brpc::OWNS_CHANNEL, NULL, NULL)); + subchan, brpc::OWNS_CHANNEL, nullptr, nullptr)); } brpc::Controller cntl; @@ -1787,11 +1787,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 5; ASSERT_EQ(0, StartAccept(_ep)); brpc::SelectiveChannel* channel = new brpc::SelectiveChannel; - ASSERT_EQ(0, channel->Init("rr", NULL)); + ASSERT_EQ(0, channel->Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel(); SetUpChannel(subchan, single_server, short_connection); - ASSERT_EQ(0, channel->AddChannel(subchan, NULL)); + ASSERT_EQ(0, channel->AddChannel(subchan, nullptr)); } brpc::Controller cntl; @@ -1875,11 +1875,11 @@ class ChannelTest : public ::testing::Test{ google::protobuf::Closure* thrd_func = brpc::NewCallback( this, &ChannelTest::RPCThread, (brpc::ChannelBase*)&channel, async); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } if (short_connection) { @@ -1906,7 +1906,7 @@ class ChannelTest : public ::testing::Test{ SetUpChannel(&subchans[i], single_server, short_connection, &auth); ASSERT_EQ(0, channel.AddChannel( &subchans[i], brpc::DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } const int NUM = 10; @@ -1915,11 +1915,11 @@ class ChannelTest : public ::testing::Test{ google::protobuf::Closure* thrd_func = brpc::NewCallback( this, &ChannelTest::RPCThread, (brpc::ChannelBase*)&channel, async); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } if (short_connection) { @@ -1941,11 +1941,11 @@ class ChannelTest : public ::testing::Test{ const size_t NCHANS = 5; brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* subchan = new brpc::Channel; SetUpChannel(subchan, single_server, short_connection, &auth); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)) << "i=" << i; + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)) << "i=" << i; } const int NUM = 10; @@ -1954,11 +1954,11 @@ class ChannelTest : public ::testing::Test{ google::protobuf::Closure* thrd_func = brpc::NewCallback( this, &ChannelTest::RPCThread, (brpc::ChannelBase*)&channel, async); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } if (short_connection) { @@ -2080,7 +2080,7 @@ class ChannelTest : public ::testing::Test{ auto args = static_cast(void_args); args->channel_test->TestRetryBackoff(args->async, args->short_connection, args->fixed_backoff, false); - return NULL; + return nullptr; } void TestRetryBackoff(bool async, bool short_connection, bool fixed_backoff, @@ -2203,7 +2203,7 @@ class ChannelTest : public ::testing::Test{ << std::endl; brpc::Channel channel; - SetUpChannel(&channel, single_server, short_connection, NULL, "", true); + SetUpChannel(&channel, single_server, short_connection, nullptr, "", true); const int RETRY_NUM = 1; test::EchoRequest req; @@ -2285,21 +2285,21 @@ TEST_F(ChannelTest, intrusive_ptr_sanity) { TEST_F(ChannelTest, init_as_single_server) { { brpc::Channel channel; - ASSERT_EQ(-1, channel.Init("127.0.0.1:12345:asdf", NULL)); - ASSERT_EQ(-1, channel.Init("127.0.0.1:99999", NULL)); - ASSERT_EQ(0, channel.Init("127.0.0.1:8888", NULL)); + ASSERT_EQ(-1, channel.Init("127.0.0.1:12345:asdf", nullptr)); + ASSERT_EQ(-1, channel.Init("127.0.0.1:99999", nullptr)); + ASSERT_EQ(0, channel.Init("127.0.0.1:8888", nullptr)); } { brpc::Channel channel; - ASSERT_EQ(-1, channel.Init("127.0.0.1asdf", 12345, NULL)); - ASSERT_EQ(-1, channel.Init("127.0.0.1", 99999, NULL)); - ASSERT_EQ(0, channel.Init("127.0.0.1", 8888, NULL)); + ASSERT_EQ(-1, channel.Init("127.0.0.1asdf", 12345, nullptr)); + ASSERT_EQ(-1, channel.Init("127.0.0.1", 99999, nullptr)); + ASSERT_EQ(0, channel.Init("127.0.0.1", 8888, nullptr)); } butil::EndPoint ep; brpc::Channel channel; ASSERT_EQ(0, str2endpoint("127.0.0.1:8888", &ep)); - ASSERT_EQ(0, channel.Init(ep, NULL)); + ASSERT_EQ(0, channel.Init(ep, nullptr)); ASSERT_TRUE(channel.SingleServer()); ASSERT_EQ(ep, channel._server_address); @@ -2310,7 +2310,7 @@ TEST_F(ChannelTest, init_as_single_server) { const int NUM = 10; brpc::Channel channels[NUM]; for (int i = 0; i < 10; ++i) { - ASSERT_EQ(0, channels[i].Init(ep, NULL)); + ASSERT_EQ(0, channels[i].Init(ep, nullptr)); // Share the same server socket ASSERT_EQ(id, channels[i]._server_id); } @@ -2318,12 +2318,12 @@ TEST_F(ChannelTest, init_as_single_server) { TEST_F(ChannelTest, init_using_unknown_naming_service) { brpc::Channel channel; - ASSERT_EQ(-1, channel.Init("unknown://unknown", "unknown", NULL)); + ASSERT_EQ(-1, channel.Init("unknown://unknown", "unknown", nullptr)); } TEST_F(ChannelTest, init_using_unexist_fns) { brpc::Channel channel; - ASSERT_EQ(-1, channel.Init("fiLe://no_such_file", "rr", NULL)); + ASSERT_EQ(-1, channel.Init("fiLe://no_such_file", "rr", nullptr)); } TEST_F(ChannelTest, init_using_empty_fns) { @@ -2338,7 +2338,7 @@ TEST_F(ChannelTest, init_using_empty_fns) { ASSERT_EQ(0, server_list.save("blahblah")); // No valid address. - ASSERT_EQ(-1, channel.Init(naming_url.c_str(), "rr", NULL)); + ASSERT_EQ(-1, channel.Init(naming_url.c_str(), "rr", nullptr)); } TEST_F(ChannelTest, init_using_empty_lns) { @@ -2356,12 +2356,12 @@ TEST_F(ChannelTest, init_using_naming_service) { ASSERT_EQ(0, server_list.save("127.0.0.1:8888")); std::string naming_url = std::string("filE://") + server_list.fname(); // Rr are intended to test case-insensitivity. - ASSERT_EQ(0, channel->Init(naming_url.c_str(), "Rr", NULL)); + ASSERT_EQ(0, channel->Init(naming_url.c_str(), "Rr", nullptr)); ASSERT_FALSE(channel->SingleServer()); brpc::LoadBalancerWithNaming* lb = dynamic_cast(channel->_lb.get()); - ASSERT_TRUE(lb != NULL); + ASSERT_TRUE(lb != nullptr); brpc::NamingServiceThread* ns = lb->_nsthread_ptr.get(); { @@ -2369,10 +2369,10 @@ TEST_F(ChannelTest, init_using_naming_service) { brpc::Channel channels[NUM]; for (int i = 0; i < NUM; ++i) { // Share the same naming thread - ASSERT_EQ(0, channels[i].Init(naming_url.c_str(), "rr", NULL)); + ASSERT_EQ(0, channels[i].Init(naming_url.c_str(), "rr", nullptr)); brpc::LoadBalancerWithNaming* lb2 = dynamic_cast(channels[i]._lb.get()); - ASSERT_TRUE(lb2 != NULL); + ASSERT_TRUE(lb2 != nullptr); ASSERT_EQ(ns, lb2->_nsthread_ptr.get()); } } @@ -2508,7 +2508,7 @@ TEST_F(ChannelTest, uninitialized_selective_channel) { req.set_message(__FUNCTION__); brpc::Controller sync_cntl; - ::test::EchoService::Stub(&channel).Echo(&sync_cntl, &req, &res, NULL); + ::test::EchoService::Stub(&channel).Echo(&sync_cntl, &req, &res, nullptr); EXPECT_EQ(EINVAL, sync_cntl.ErrorCode()) << sync_cntl.ErrorText(); brpc::Controller async_cntl; @@ -2522,7 +2522,7 @@ TEST_F(ChannelTest, uninitialized_selective_channel) { TEST_F(ChannelTest, empty_selective_channel) { brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); brpc::Controller cntl; test::EchoRequest req; @@ -2548,7 +2548,7 @@ TEST_F(ChannelTest, returns_bad_parallel) { brpc::Channel* subchan = new brpc::Channel(); SetUpChannel(subchan, true, false); ASSERT_EQ(0, channel.AddChannel( - subchan, brpc::OWNS_CHANNEL, new BadCall, NULL)); + subchan, brpc::OWNS_CHANNEL, new BadCall, nullptr)); } brpc::Controller cntl; @@ -2575,7 +2575,7 @@ TEST_F(ChannelTest, skip_all_channels) { brpc::Channel* subchan = new brpc::Channel(); SetUpChannel(subchan, true, false); ASSERT_EQ(0, channel.AddChannel( - subchan, brpc::OWNS_CHANNEL, new SkipCall, NULL)); + subchan, brpc::OWNS_CHANNEL, new SkipCall, nullptr)); } brpc::Controller cntl; @@ -2587,7 +2587,7 @@ TEST_F(ChannelTest, skip_all_channels) { EXPECT_EQ(ECANCELED, cntl.ErrorCode()) << cntl.ErrorText(); EXPECT_EQ((int)NCHANS, cntl.sub_count()); for (int i = 0; i < cntl.sub_count(); ++i) { - EXPECT_TRUE(NULL == cntl.sub(i)) << "i=" << i; + EXPECT_TRUE(nullptr == cntl.sub(i)) << "i=" << i; } } @@ -2620,8 +2620,8 @@ TEST_F(ChannelTest, http_header_parallel_channels) { brpc::ParallelChannel channel; for (size_t i = 0; i < NCHANS; ++i) { brpc::Channel* sub_chan = new brpc::Channel(); - SetUpChannel(sub_chan, true, false, NULL, "", false, brpc::PROTOCOL_HTTP); - ASSERT_EQ(0, channel.AddChannel(sub_chan, brpc::OWNS_CHANNEL, new EchoHttpHeader, NULL)); + SetUpChannel(sub_chan, true, false, nullptr, "", false, brpc::PROTOCOL_HTTP); + ASSERT_EQ(0, channel.AddChannel(sub_chan, brpc::OWNS_CHANNEL, new EchoHttpHeader, nullptr)); } brpc::Controller cntl; @@ -2635,7 +2635,7 @@ TEST_F(ChannelTest, http_header_parallel_channels) { ASSERT_EQ((int)NCHANS, cntl.sub_count()); for (int i = 0; i < cntl.sub_count(); ++i) { const brpc::Controller* sub_cntl = cntl.sub(i); - ASSERT_TRUE(NULL != sub_cntl) << "i=" << i; + ASSERT_TRUE(nullptr != sub_cntl) << "i=" << i; ASSERT_EQ(std::to_string(i), *sub_cntl->http_response().GetHeader(ECHO_HTTP_HEADER)); } } @@ -3014,7 +3014,7 @@ TEST_F(ChannelTest, retry_backoff) { new TestRetryBackoffInfo(this, j, k, l)); // Retry backoff in bthread. bthread_start_background(&th, &attr, TestRetryBackoffBthread, test_retry_backoff.get()); - bthread_join(th, NULL); + bthread_join(th, nullptr); } else { // Retry backoff in pthread. TestRetryBackoff(j, k, l, true); @@ -3049,17 +3049,17 @@ TEST_F(ChannelTest, selective_channel_ignores_late_subdone_after_timeout) { DelayedCloseEchoService service; brpc::Server server; ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start("127.0.0.1:0", NULL)); + ASSERT_EQ(0, server.Start("127.0.0.1:0", nullptr)); brpc::SelectiveChannel channel; - ASSERT_EQ(0, channel.Init("rr", NULL)); + ASSERT_EQ(0, channel.Init("rr", nullptr)); brpc::ChannelOptions options; options.timeout_ms = 100; for (int i = 0; i < 2; ++i) { brpc::Channel* sub_channel = new brpc::Channel; ASSERT_EQ(0, sub_channel->Init(server.listen_address(), &options)); - ASSERT_EQ(0, channel.AddChannel(sub_channel, NULL)); + ASSERT_EQ(0, channel.AddChannel(sub_channel, nullptr)); } brpc::Controller cntl; @@ -3088,7 +3088,7 @@ TEST_F(ChannelTest, selective_channel_ignores_late_subdone_after_timeout) { } TEST_F(ChannelTest, multiple_threads_single_channel) { - srand(time(NULL)); + srand(time(nullptr)); ASSERT_EQ(0, StartAccept(_ep)); MyAuthenticator auth; const int NUM = 10; @@ -3106,18 +3106,18 @@ TEST_F(ChannelTest, multiple_threads_single_channel) { << " async=" << async << std::endl; brpc::Channel channel; SetUpChannel(&channel, single_server, - short_connection, (need_auth ? &auth : NULL)); + short_connection, (need_auth ? &auth : nullptr)); for (int i = 0; i < NUM; ++i) { google::protobuf::Closure* thrd_func = brpc::NewCallback( this, &ChannelTest::RPCThread, (brpc::ChannelBase*)&channel, (bool)async, COUNT); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } } } @@ -3125,7 +3125,7 @@ TEST_F(ChannelTest, multiple_threads_single_channel) { } TEST_F(ChannelTest, multiple_threads_multiple_channels) { - srand(time(NULL)); + srand(time(nullptr)); ASSERT_EQ(0, StartAccept(_ep)); MyAuthenticator auth; const int NUM = 10; @@ -3148,12 +3148,12 @@ TEST_F(ChannelTest, multiple_threads_multiple_channels) { ChannelTest, ChannelTest*, bool, bool, bool, const brpc::Authenticator*, int> (this, &ChannelTest::RPCThread, single_server, - async, short_connection, (need_auth ? &auth : NULL), COUNT); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, + async, short_connection, (need_auth ? &auth : nullptr), COUNT); + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } } } @@ -3202,7 +3202,7 @@ TEST_F(ChannelTest, sizeof) { brpc::Channel g_chan; TEST_F(ChannelTest, global_channel_should_quit_successfully) { - g_chan.Init("bns://qa-pbrpc.SAT.tjyx", "rr", NULL); + g_chan.Init("bns://qa-pbrpc.SAT.tjyx", "rr", nullptr); } TEST_F(ChannelTest, unused_call_id) { @@ -3306,49 +3306,49 @@ class RateLimitedBackupPolicyTest : public ::testing::Test {}; TEST_F(RateLimitedBackupPolicyTest, InvalidBackupRequestMs) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = -2; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidMaxBackupRatioZero) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.max_backup_ratio = 0.0; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidMaxBackupRatioNegative) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.max_backup_ratio = -0.1; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidMaxBackupRatioAboveOne) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.max_backup_ratio = 1.001; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidWindowSizeTooSmall) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.window_size_seconds = 0; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidWindowSizeTooLarge) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.window_size_seconds = 3601; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, InvalidUpdateIntervalTooSmall) { brpc::RateLimitedBackupPolicyOptions opts; opts.backup_request_ms = 100; opts.update_interval_seconds = 0; - ASSERT_EQ(NULL, brpc::CreateRateLimitedBackupPolicy(opts)); + ASSERT_EQ(nullptr, brpc::CreateRateLimitedBackupPolicy(opts)); } TEST_F(RateLimitedBackupPolicyTest, ValidMinusOneBackupRequestMsInherits) { @@ -3356,8 +3356,8 @@ TEST_F(RateLimitedBackupPolicyTest, ValidMinusOneBackupRequestMsInherits) { opts.backup_request_ms = -1; std::unique_ptr p( brpc::CreateRateLimitedBackupPolicy(opts)); - ASSERT_TRUE(p != NULL); - ASSERT_EQ(-1, p->GetBackupRequestMs(NULL)); + ASSERT_TRUE(p != nullptr); + ASSERT_EQ(-1, p->GetBackupRequestMs(nullptr)); } TEST_F(RateLimitedBackupPolicyTest, ValidMaxRatioAtBoundary) { @@ -3366,12 +3366,12 @@ TEST_F(RateLimitedBackupPolicyTest, ValidMaxRatioAtBoundary) { opts.max_backup_ratio = 1.0; std::unique_ptr p( brpc::CreateRateLimitedBackupPolicy(opts)); - ASSERT_TRUE(p != NULL); + ASSERT_TRUE(p != nullptr); // With max_backup_ratio=1.0 and true cold start (total==0, backup==0), // ShouldAllow() sets ratio=0.0 (free pass). The conservative ratio=1.0 // path only applies when backup>0 but total==0 (latency spike with no // completions yet). At absolute cold start DoBackup() must return true. - ASSERT_TRUE(p->DoBackup(NULL)); // cold start: ratio=0.0 < 1.0, allow + ASSERT_TRUE(p->DoBackup(nullptr)); // cold start: ratio=0.0 < 1.0, allow } TEST_F(RateLimitedBackupPolicyTest, ColdStartAllowsBackup) { @@ -3381,8 +3381,8 @@ TEST_F(RateLimitedBackupPolicyTest, ColdStartAllowsBackup) { opts.update_interval_seconds = 1; std::unique_ptr p( brpc::CreateRateLimitedBackupPolicy(opts)); - ASSERT_TRUE(p != NULL); - ASSERT_TRUE(p->DoBackup(NULL)); + ASSERT_TRUE(p != nullptr); + ASSERT_TRUE(p->DoBackup(nullptr)); } // After the first backup fires (backup_count=1, total_count=0), once the @@ -3397,14 +3397,14 @@ TEST_F(RateLimitedBackupPolicyTest, AfterColdStartBackupSuppressedUntilRpcComple opts.update_interval_seconds = 1; std::unique_ptr p( brpc::CreateRateLimitedBackupPolicy(opts)); - ASSERT_TRUE(p != NULL); + ASSERT_TRUE(p != nullptr); // First call fires (cold start: total=0, backup=0 → ratio=0.0 → allow). - ASSERT_TRUE(p->DoBackup(NULL)); + ASSERT_TRUE(p->DoBackup(nullptr)); // Wait for the update interval to elapse so the ratio refreshes. // After refresh: total=0 but backup=1 → conservative path sets ratio=1.0, // which is >= max_backup_ratio (0.1), so DoBackup() must return false. bthread_usleep(1200000); // 1.2s > update_interval_seconds=1 - ASSERT_FALSE(p->DoBackup(NULL)); + ASSERT_FALSE(p->DoBackup(nullptr)); } // After the ratio rises above the threshold, calling OnRPCEnd() many times @@ -3418,24 +3418,24 @@ TEST_F(RateLimitedBackupPolicyTest, OnRPCEndDrivesRatioDownAndReAllows) { opts.update_interval_seconds = 1; std::unique_ptr p( brpc::CreateRateLimitedBackupPolicy(opts)); - ASSERT_TRUE(p != NULL); + ASSERT_TRUE(p != nullptr); // Fire many backup decisions so backup_count >> total_count, // pushing the ratio above max_backup_ratio. for (int i = 0; i < 20; ++i) { - p->DoBackup(NULL); + p->DoBackup(nullptr); } // Wait for update interval so the ratio is refreshed above threshold. bthread_usleep(1200000); // 1.2s - ASSERT_FALSE(p->DoBackup(NULL)); + ASSERT_FALSE(p->DoBackup(nullptr)); // Now complete many more RPCs than backups fired to bring ratio below 0.5. // 20 backup decisions already counted; need total_count > 20/0.5 = 40. for (int i = 0; i < 50; ++i) { - p->OnRPCEnd(NULL); + p->OnRPCEnd(nullptr); } // Wait for the ratio cache to refresh. bthread_usleep(1200000); // 1.2s // Ratio is now ~20/50 = 0.4 < max_backup_ratio (0.5), so backup is re-allowed. - ASSERT_TRUE(p->DoBackup(NULL)); + ASSERT_TRUE(p->DoBackup(nullptr)); } } //namespace diff --git a/test/brpc_checksum_unittest.cpp b/test/brpc_checksum_unittest.cpp index f8b86b33ad..7d5a2665f8 100644 --- a/test/brpc_checksum_unittest.cpp +++ b/test/brpc_checksum_unittest.cpp @@ -43,10 +43,10 @@ TEST_F(ChecksumAttachmentTest, verify_succeeds_when_body_only) { butil::IOBuf body; body.append("request body"); - brpc::ChecksumIn compute_in{&body, &cntl, NULL}; + brpc::ChecksumIn compute_in{&body, &cntl, nullptr}; brpc::policy::Crc32cCompute(compute_in); - brpc::ChecksumIn verify_in{&body, &cntl, NULL}; + brpc::ChecksumIn verify_in{&body, &cntl, nullptr}; EXPECT_TRUE(brpc::policy::Crc32cVerify(verify_in)); } @@ -94,7 +94,7 @@ TEST_F(ChecksumAttachmentTest, verify_fails_when_attachment_dropped) { // ...but receiver (e.g. due to a mismatched // request/response_checksum_attachment() setting) verifies body only. - brpc::ChecksumIn verify_in{&body, &cntl, NULL}; + brpc::ChecksumIn verify_in{&body, &cntl, nullptr}; EXPECT_FALSE(brpc::policy::Crc32cVerify(verify_in)); } @@ -152,7 +152,7 @@ class ChecksumAttachmentEndToEndTest : public ::testing::Test { protected: void SetUp() override { ASSERT_EQ(0, server_.AddService(&svc_, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server_.Start(port_, NULL)); + ASSERT_EQ(0, server_.Start(port_, nullptr)); brpc::ChannelOptions options; ASSERT_EQ(0, channel_.Init(butil::EndPoint(butil::my_ip(), port_), &options)); @@ -180,7 +180,7 @@ TEST_F(ChecksumAttachmentEndToEndTest, request_checksum_with_attachment) { test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, NULL); + test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); @@ -196,7 +196,7 @@ TEST_F(ChecksumAttachmentEndToEndTest, response_checksum_with_attachment) { test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, NULL); + test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); @@ -214,7 +214,7 @@ TEST_F(ChecksumAttachmentEndToEndTest, both_directions_checksum_with_attachment) test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, NULL); + test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); @@ -234,7 +234,7 @@ TEST_F(ChecksumAttachmentEndToEndTest, checksum_without_attachment_still_works) test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, NULL); + test::EchoService::Stub(&channel_).Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ("received " + std::string(__FUNCTION__), res.message()); diff --git a/test/brpc_coroutine_unittest.cpp b/test/brpc_coroutine_unittest.cpp index 1df2c3a0e4..0d54956056 100644 --- a/test/brpc_coroutine_unittest.cpp +++ b/test/brpc_coroutine_unittest.cpp @@ -182,7 +182,7 @@ TEST_F(CoroutineTest, coroutine) { brpc::Server server; EchoServiceImpl service; server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE); - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; diff --git a/test/brpc_couchbase_unittest.cpp b/test/brpc_couchbase_unittest.cpp index febf31c55c..f6c819089b 100644 --- a/test/brpc_couchbase_unittest.cpp +++ b/test/brpc_couchbase_unittest.cpp @@ -57,7 +57,7 @@ TEST_F(CouchbaseUnitTest, RejectOversizedResponseBeforeBufferingBody) { couchbase_buf.append(&couchbase_header, sizeof(couchbase_header)); EXPECT_EQ(brpc::PARSE_ERROR_TOO_BIG_DATA, brpc::policy::ParseCouchbaseMessage( - &couchbase_buf, socket.get(), false, NULL).error()); + &couchbase_buf, socket.get(), false, nullptr).error()); } diff --git a/test/brpc_esp_protocol_unittest.cpp b/test/brpc_esp_protocol_unittest.cpp index d4cab7c47d..1832608b2a 100644 --- a/test/brpc_esp_protocol_unittest.cpp +++ b/test/brpc_esp_protocol_unittest.cpp @@ -78,7 +78,7 @@ class EspTest : public ::testing::Test{ brpc::policy::SerializeEspRequest(&req_buf, &cntl, &req); butil::IOBuf packet_buf; - brpc::policy::PackEspRequest(&packet_buf, NULL, cntl.call_id().value, NULL, &cntl, req_buf, NULL); + brpc::policy::PackEspRequest(&packet_buf, nullptr, cntl.call_id().value, nullptr, &cntl, req_buf, nullptr); packet_buf.cut_into_file_descriptor(_pipe_fds[1], packet_buf.size()); } @@ -107,7 +107,7 @@ TEST_F(EspTest, complete_flow) { const brpc::Authenticator* auth = brpc::policy::global_esp_authenticator(); butil::IOBuf packet_buf; - brpc::policy::PackEspRequest(&packet_buf, NULL, cntl.call_id().value, NULL, &cntl, req_buf, auth); + brpc::policy::PackEspRequest(&packet_buf, nullptr, cntl.call_id().value, nullptr, &cntl, req_buf, auth); std::string auth_str; auth->GenerateCredential(&auth_str); @@ -121,7 +121,7 @@ TEST_F(EspTest, complete_flow) { response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseEspMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseEspMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); @@ -145,7 +145,7 @@ TEST_F(EspTest, wrong_response_head) { response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseEspMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseEspMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); diff --git a/test/brpc_event_dispatcher_unittest.cpp b/test/brpc_event_dispatcher_unittest.cpp index dcca305fef..bf3f187586 100644 --- a/test/brpc_event_dispatcher_unittest.cpp +++ b/test/brpc_event_dispatcher_unittest.cpp @@ -55,7 +55,7 @@ TEST_F(EventDispatcherTest, versioned_ref) { struct UserData; -UserData* g_user_data = NULL; +UserData* g_user_data = nullptr; struct UserData : public brpc::VersionedRefWithId { explicit UserData(Forbidden f) @@ -72,7 +72,7 @@ struct UserData : public brpc::VersionedRefWithId { void BeforeRecycled() { count.store(0, butil::memory_order_relaxed); - g_user_data = NULL; + g_user_data = nullptr; } void BeforeAdditionalRefReleased() { @@ -117,7 +117,7 @@ void* VRefThread(void* arg) { while (!vref_thread_stop) { TestVRef(id); } - return NULL; + return nullptr; } TEST_F(EventDispatcherTest, versioned_ref_with_id) { @@ -140,14 +140,14 @@ TEST_F(EventDispatcherTest, versioned_ref_with_id) { const size_t thread_num = 8; pthread_t tid[thread_num]; for (auto& i : tid) { - ASSERT_EQ(0, pthread_create(&i, NULL, VRefThread, (void*)id)); + ASSERT_EQ(0, pthread_create(&i, nullptr, VRefThread, (void*)id)); } sleep(2); vref_thread_stop = true; for (const auto i : tid) { - pthread_join(i, NULL); + pthread_join(i, nullptr); } ASSERT_EQ(2, ptr->nref()); @@ -299,7 +299,7 @@ void* client_thread(void* arg) { } free(buf); EXPECT_EQ(0, close(m->fd)); - return NULL; + return nullptr; } inline uint32_t fmix32 ( uint32_t h ) { @@ -345,7 +345,7 @@ TEST_F(EventDispatcherTest, dispatch_tasks) { cm[i]->fd = fds[i * 2 + 1]; cm[i]->times = 0; cm[i]->bytes = 0; - ASSERT_EQ(0, pthread_create(&cth[i], NULL, client_thread, cm[i])); + ASSERT_EQ(0, pthread_create(&cth[i], nullptr, client_thread, cm[i])); } LOG(INFO) << "Begin to profile... (5 seconds)"; @@ -369,7 +369,7 @@ TEST_F(EventDispatcherTest, dispatch_tasks) { client_stop = true; for (size_t i = 0; i < NCLIENT; ++i) { - pthread_join(cth[i], NULL); + pthread_join(cth[i], nullptr); } sleep(1); diff --git a/test/brpc_extension_unittest.cpp b/test/brpc_extension_unittest.cpp index eea238ee9c..367f80aafa 100644 --- a/test/brpc_extension_unittest.cpp +++ b/test/brpc_extension_unittest.cpp @@ -51,7 +51,7 @@ const int g_foo = 10; const int g_bar = 20; TEST_F(ExtensionTest, basic) { - ConstIntExtension()->Register("foo", NULL); + ConstIntExtension()->Register("foo", nullptr); ConstIntExtension()->Register("foo", &g_foo); ConstIntExtension()->Register("bar", &g_bar); diff --git a/test/brpc_grpc_protocol_unittest.cpp b/test/brpc_grpc_protocol_unittest.cpp index 5a9752ea23..5a1bc8df9b 100644 --- a/test/brpc_grpc_protocol_unittest.cpp +++ b/test/brpc_grpc_protocol_unittest.cpp @@ -103,7 +103,7 @@ class GrpcTest : public ::testing::Test { protected: GrpcTest() { EXPECT_EQ(0, _server.AddService(&_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, _server.Start(g_server_addr.c_str(), NULL)); + EXPECT_EQ(0, _server.Start(g_server_addr.c_str(), nullptr)); brpc::ChannelOptions options; options.protocol = g_protocol; options.timeout_ms = g_timeout_ms; @@ -126,7 +126,7 @@ class GrpcTest : public ::testing::Test { req.set_return_error(false); test::GrpcService_Stub stub(&_channel); - stub.Method(&cntl, &req, &res, NULL); + stub.Method(&cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorCode() << ": " << cntl.ErrorText(); EXPECT_EQ(res.message(), g_prefix + g_req); } @@ -180,7 +180,7 @@ TEST_F(GrpcTest, return_error) { req.set_gzip(false); req.set_return_error(true); test::GrpcService_Stub stub(&_channel); - stub.Method(&cntl, &req, &res, NULL); + stub.Method(&cntl, &req, &res, nullptr); EXPECT_TRUE(cntl.Failed()); EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL); EXPECT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with(butil::string_printf("%s", g_prefix.c_str()))); @@ -200,7 +200,7 @@ TEST_F(GrpcTest, RpcTimedOut) { req.set_gzip(false); req.set_return_error(false); test::GrpcService_Stub stub(&_channel); - stub.MethodTimeOut(&cntl, &req, &res, NULL); + stub.MethodTimeOut(&cntl, &req, &res, nullptr); EXPECT_TRUE(cntl.Failed()); EXPECT_EQ(cntl.ErrorCode(), brpc::ERPCTIMEDOUT); } @@ -213,7 +213,7 @@ TEST_F(GrpcTest, MethodNotExist) { req.set_gzip(false); req.set_return_error(false); test::GrpcService_Stub stub(&_channel); - stub.MethodNotExist(&cntl, &req, &res, NULL); + stub.MethodNotExist(&cntl, &req, &res, nullptr); EXPECT_TRUE(cntl.Failed()); EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL); ASSERT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with("Method MethodNotExist() not implemented.")); @@ -245,11 +245,11 @@ TEST_F(GrpcTest, GrpcTimeOut) { req.set_message(g_req); req.set_gzip(false); req.set_return_error(false); - req.set_timeout_us((int64_t)(strtol(timeouts[i+1], NULL, 10))); + req.set_timeout_us((int64_t)(strtol(timeouts[i+1], nullptr, 10))); cntl.set_timeout_ms(-1); cntl.http_request().SetHeader("grpc-timeout", timeouts[i]); test::GrpcService_Stub stub(&_channel); - stub.Method(&cntl, &req, &res, NULL); + stub.Method(&cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()); } @@ -264,7 +264,7 @@ TEST_F(GrpcTest, GrpcTimeOut) { req.set_timeout_us(9876000); cntl.set_timeout_ms(9876); test::GrpcService_Stub stub(&_channel); - stub.Method(&cntl, &req, &res, NULL); + stub.Method(&cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()); } @@ -278,7 +278,7 @@ TEST_F(GrpcTest, GrpcTimeOut) { req.set_return_error(false); req.set_timeout_us(g_timeout_ms * 1000); test::GrpcService_Stub stub(&_channel); - stub.Method(&cntl, &req, &res, NULL); + stub.Method(&cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()); } } diff --git a/test/brpc_h2_unsent_message_unittest.cpp b/test/brpc_h2_unsent_message_unittest.cpp index 1c7b985aed..a8cd8da2c5 100644 --- a/test/brpc_h2_unsent_message_unittest.cpp +++ b/test/brpc_h2_unsent_message_unittest.cpp @@ -248,7 +248,7 @@ TEST(H2UnsentMessage, request_throughput) { brpc::Controller cntl; butil::IOBuf request_buf; cntl.http_request().uri() = "0.0.0.0:8010/HttpService/Echo"; - brpc::policy::SerializeHttpRequest(&request_buf, &cntl, NULL); + brpc::policy::SerializeHttpRequest(&request_buf, &cntl, nullptr); brpc::SocketId id; brpc::SocketUniquePtr h2_client_sock; @@ -258,7 +258,7 @@ TEST(H2UnsentMessage, request_throughput) { EXPECT_EQ(0, brpc::Socket::Address(id, &h2_client_sock)); brpc::policy::H2Context* ctx = - new brpc::policy::H2Context(h2_client_sock.get(), NULL); + new brpc::policy::H2Context(h2_client_sock.get(), nullptr); CHECK_EQ(ctx->Init(), 0); h2_client_sock->initialize_parsing_context(&ctx); ctx->_last_sent_stream_id = 0; diff --git a/test/brpc_hpack_unittest.cpp b/test/brpc_hpack_unittest.cpp index 48d3ae52eb..98d8664836 100644 --- a/test/brpc_hpack_unittest.cpp +++ b/test/brpc_hpack_unittest.cpp @@ -49,8 +49,8 @@ TEST_F(HPackTest, many_dynamic_table_size_updates) { const pid_t pid = fork(); ASSERT_GE(pid, 0); if (pid == 0) { - if (freopen("/dev/null", "w", stdout) == NULL || - freopen("/dev/null", "w", stderr) == NULL) { + if (freopen("/dev/null", "w", stdout) == nullptr || + freopen("/dev/null", "w", stderr) == nullptr) { exit(1); } @@ -62,15 +62,15 @@ TEST_F(HPackTest, many_dynamic_table_size_updates) { exit(3); } pthread_t tid; - if (pthread_create(&tid, &attr, DecodeManyDynamicTableSizeUpdates, NULL) != 0) { + if (pthread_create(&tid, &attr, DecodeManyDynamicTableSizeUpdates, nullptr) != 0) { exit(4); } pthread_attr_destroy(&attr); - void* ret = NULL; + void* ret = nullptr; if (pthread_join(tid, &ret) != 0) { exit(5); } - exit(ret == NULL ? 0 : 6); + exit(ret == nullptr ? 0 : 6); } int status = 0; ASSERT_EQ(pid, waitpid(pid, &status, 0)); diff --git a/test/brpc_http_message_unittest.cpp b/test/brpc_http_message_unittest.cpp index 9933a8d1bb..bd2ac5ed91 100644 --- a/test/brpc_http_message_unittest.cpp +++ b/test/brpc_http_message_unittest.cpp @@ -151,7 +151,7 @@ TEST(HttpMessageTest, request_sanity) { ASSERT_TRUE(header.GetHeader("log-id")); ASSERT_EQ("456", *header.GetHeader("log-id")); - ASSERT_TRUE(NULL != header.GetHeader("Authorization")); + ASSERT_TRUE(nullptr != header.GetHeader("Authorization")); ASSERT_EQ("test", *header.GetHeader("Authorization")); } @@ -429,19 +429,19 @@ TEST(HttpMessageTest, find_method_property_by_uri) { brpc::Server server; ASSERT_EQ(0, server.AddService(new test::EchoService(), brpc::SERVER_OWNS_SERVICE)); - ASSERT_EQ(0, server.Start(9237, NULL)); + ASSERT_EQ(0, server.Start(9237, nullptr)); std::string unknown_method; - brpc::Server::MethodProperty* mp = NULL; + brpc::Server::MethodProperty* mp = nullptr; - mp = FindMethodPropertyByURI("", &server, NULL); + mp = FindMethodPropertyByURI("", &server, nullptr); ASSERT_TRUE(mp); ASSERT_EQ("index", mp->method->service()->name()); - mp = FindMethodPropertyByURI("/", &server, NULL); + mp = FindMethodPropertyByURI("/", &server, nullptr); ASSERT_TRUE(mp); ASSERT_EQ("index", mp->method->service()->name()); - mp = FindMethodPropertyByURI("//", &server, NULL); + mp = FindMethodPropertyByURI("//", &server, nullptr); ASSERT_TRUE(mp); ASSERT_EQ("index", mp->method->service()->name()); @@ -649,14 +649,14 @@ TEST(HttpMessageTest, serialize_http_response) { // Content is cleared. CHECK(content.empty()); - // NULL content + // nullptr content header.SetHeader("Content-Length", "100"); - MakeRawHttpResponse(&response, &header, NULL); + MakeRawHttpResponse(&response, &header, nullptr); ASSERT_EQ("HTTP/1.1 200 OK\r\nFoo: Bar\r\nContent-Length: 100\r\n\r\n", response) << butil::ToPrintable(response); header.SetHeader("Transfer-Encoding", "chunked"); - MakeRawHttpResponse(&response, &header, NULL); + MakeRawHttpResponse(&response, &header, nullptr); ASSERT_EQ("HTTP/1.1 200 OK\r\nFoo: Bar\r\nTransfer-Encoding: chunked\r\n\r\n", response) << butil::ToPrintable(response); header.RemoveHeader("Transfer-Encoding"); @@ -669,7 +669,7 @@ TEST(HttpMessageTest, serialize_http_response) { header.SetHeader("Content-Length", "100"); header.SetHeader("Transfer-Encoding", "chunked"); - MakeRawHttpResponse(&response, &header, NULL); + MakeRawHttpResponse(&response, &header, nullptr); ASSERT_EQ("HTTP/1.1 200 OK\r\nFoo: Bar\r\nTransfer-Encoding: chunked\r\n\r\n", response) << butil::ToPrintable(response); header.RemoveHeader("Transfer-Encoding"); @@ -731,7 +731,7 @@ TEST(HttpMessageTest, http_1_1_request_without_host) { brpc::HttpMessage http_message; ASSERT_GE(http_message.ParseFromIOBuf(request), 0); - ASSERT_GE(http_message.ParseFromArray(NULL, 0), 0); + ASSERT_GE(http_message.ParseFromArray(nullptr, 0), 0); ASSERT_TRUE(http_message.Completed()); ASSERT_EQ("text/plain", http_message.header().content_type()); } diff --git a/test/brpc_http_rpc_protocol_unittest.cpp b/test/brpc_http_rpc_protocol_unittest.cpp index 97de699547..df5c838f5b 100644 --- a/test/brpc_http_rpc_protocol_unittest.cpp +++ b/test/brpc_http_rpc_protocol_unittest.cpp @@ -118,7 +118,7 @@ class MyEchoService : public ::test::EchoService { const std::string* sleep_ms_str = cntl->http_request().uri().GetQuery("sleep_ms"); if (sleep_ms_str) { - bthread_usleep(strtol(sleep_ms_str->data(), NULL, 10) * 1000); + bthread_usleep(strtol(sleep_ms_str->data(), nullptr, 10) * 1000); } res->set_message(EXP_RESPONSE); } @@ -157,7 +157,7 @@ class HttpTest : public ::testing::Test{ virtual void TearDown() {}; void VerifyMessage(brpc::InputMessageBase* msg, bool expect) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -183,7 +183,7 @@ class HttpTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -203,7 +203,7 @@ class HttpTest : public ::testing::Test{ test::EchoRequest req; req.set_message(EXP_REQUEST); butil::IOBufAsZeroCopyOutputStream req_stream(&msg->body()); - EXPECT_TRUE(json2pb::ProtoMessageToJson(req, &req_stream, NULL)); + EXPECT_TRUE(json2pb::ProtoMessageToJson(req, &req_stream, nullptr)); return msg; } @@ -257,7 +257,7 @@ class HttpTest : public ::testing::Test{ void CallVersion(brpc::Channel* channel, brpc::Controller* cntl) { cntl->http_request().uri() = "/status"; cntl->http_request().set_method(brpc::HTTP_METHOD_GET); - channel->CallMethod(NULL, cntl, NULL, NULL, NULL); + channel->CallMethod(nullptr, cntl, nullptr, nullptr, nullptr); } void CallHttpEcho(brpc::Channel* channel, brpc::Controller* cntl) { @@ -267,7 +267,7 @@ class HttpTest : public ::testing::Test{ cntl->http_request().uri() = "/EchoService/Echo"; cntl->http_request().set_method(brpc::HTTP_METHOD_POST); cntl->http_request().set_content_type("application/json"); - channel->CallMethod(NULL, cntl, &req, &res, NULL); + channel->CallMethod(nullptr, cntl, &req, &res, nullptr); } @@ -279,7 +279,7 @@ class HttpTest : public ::testing::Test{ test::EchoResponse res; res.set_message(EXP_RESPONSE); butil::IOBufAsZeroCopyOutputStream res_stream(&msg->body()); - EXPECT_TRUE(json2pb::ProtoMessageToJson(res, &res_stream, NULL)); + EXPECT_TRUE(json2pb::ProtoMessageToJson(res, &res_stream, nullptr)); return msg; } @@ -296,7 +296,7 @@ class HttpTest : public ::testing::Test{ EXPECT_EQ((ssize_t)bytes_in_pipe, buf.append_from_file_descriptor(_pipe_fds[0], 1024)); brpc::ParseResult pr = - brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, NULL); + brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, nullptr); EXPECT_EQ(brpc::PARSE_OK, pr.error()); brpc::policy::HttpContext* msg = static_cast(pr.message()); @@ -314,9 +314,9 @@ class HttpTest : public ::testing::Test{ ASSERT_FALSE(cntl->Failed()); brpc::policy::H2UnsentRequest* h2_req = brpc::policy::H2UnsentRequest::New(cntl); cntl->_current_call.stream_user_data = h2_req; - brpc::SocketMessage* socket_message = NULL; - brpc::policy::PackH2Request(NULL, &socket_message, cntl->call_id().value, - NULL, cntl, request_buf, NULL); + brpc::SocketMessage* socket_message = nullptr; + brpc::policy::PackH2Request(nullptr, &socket_message, cntl->call_id().value, + nullptr, cntl, request_buf, nullptr); butil::Status st = socket_message->AppendAndDestroySelf(out, _h2_client_sock.get()); ASSERT_TRUE(st.ok()); *h2_stream_id = h2_req->_stream_id; @@ -352,7 +352,7 @@ TEST_F(HttpTest, reject_oversized_http_body) { buf.append("POST / HTTP/1.1\r\nContent-Length: 5\r\n\r\nhello"); brpc::ParseResult result = - brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, NULL); + brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, nullptr); EXPECT_EQ(brpc::PARSE_ERROR_NOT_ENOUGH_DATA, result.error()); int bytes_in_pipe = 0; ASSERT_EQ(0, ioctl(_pipe_fds[0], FIONREAD, &bytes_in_pipe)); @@ -371,7 +371,7 @@ TEST_F(HttpTest, reject_oversized_chunked_http_body) { "3\r\nabc\r\n2\r\nde\r\n0\r\n\r\n"); brpc::ParseResult result = - brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, NULL); + brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, nullptr); EXPECT_EQ(brpc::PARSE_ERROR_NOT_ENOUGH_DATA, result.error()); int bytes_in_pipe = 0; ASSERT_EQ(0, ioctl(_pipe_fds[0], FIONREAD, &bytes_in_pipe)); @@ -517,7 +517,7 @@ TEST_F(HttpTest, builtin_auth_policy_on_public_and_internal_port) { brpc::Controller cntl; cntl.http_request().uri() = "/status"; cntl.http_request().set_method(brpc::HTTP_METHOD_GET); - chan.CallMethod(NULL, &cntl, NULL, NULL, NULL); + chan.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()) << cntl.ErrorText(); ASSERT_EQ(brpc::HTTP_STATUS_FORBIDDEN, cntl.http_response().status_code()); @@ -533,7 +533,7 @@ TEST_F(HttpTest, builtin_auth_policy_on_public_and_internal_port) { brpc::Controller cntl; cntl.http_request().uri() = "/status"; cntl.http_request().set_method(brpc::HTTP_METHOD_GET); - chan.CallMethod(NULL, &cntl, NULL, NULL, NULL); + chan.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(brpc::HTTP_STATUS_OK, cntl.http_response().status_code()); } @@ -670,13 +670,13 @@ TEST_F(HttpTest, complete_flow) { brpc::policy::SerializeHttpRequest(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackHttpRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, cntl._method, &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Verify and handle request brpc::ParseResult req_pr = - brpc::policy::ParseHttpMessage(&total_buf, _socket.get(), false, NULL); + brpc::policy::ParseHttpMessage(&total_buf, _socket.get(), false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); VerifyMessage(req_msg, true); @@ -686,7 +686,7 @@ TEST_F(HttpTest, complete_flow) { butil::IOPortal response_buf; response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseHttpMessage(&response_buf, _socket.get(), false, NULL); + brpc::policy::ParseHttpMessage(&response_buf, _socket.get(), false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); ProcessMessage(brpc::policy::ProcessHttpResponse, res_msg, false); @@ -699,7 +699,7 @@ TEST_F(HttpTest, chunked_uploading) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); // Send request via curl using chunked encoding const std::string req = "{\"message\":\"hello\"}"; @@ -755,12 +755,12 @@ class DownloadServiceImpl : public ::test::DownloadService { ? brpc::FORCE_STOP : brpc::WAIT_FOR_STOP); butil::intrusive_ptr pa = cntl->CreateProgressiveAttachment(stop_style); - if (pa == NULL) { + if (pa == nullptr) { cntl->SetFailed("The socket was just failed"); return; } if (_done_place == DONE_BEFORE_CREATE_PA) { - done_guard.reset(NULL); + done_guard.reset(nullptr); } ASSERT_GT(PA_DATA_LEN, 8u); // long enough to hold a 64-bit decimal. char buf[PA_DATA_LEN]; @@ -782,12 +782,12 @@ class DownloadServiceImpl : public ::test::DownloadService { ++c; } if (_done_place == DONE_AFTER_CREATE_PA_BEFORE_DESTROY_PA) { - done_guard.reset(NULL); + done_guard.reset(nullptr); } LOG(INFO) << "Destroy pa=" << pa.get(); - pa.reset(NULL); + pa.reset(nullptr); if (_done_place == DONE_AFTER_DESTROY_PA) { - done_guard.reset(NULL); + done_guard.reset(nullptr); } } @@ -803,7 +803,7 @@ class DownloadServiceImpl : public ::test::DownloadService { ? brpc::FORCE_STOP : brpc::WAIT_FOR_STOP); butil::intrusive_ptr pa = cntl->CreateProgressiveAttachment(stop_style); - if (pa == NULL) { + if (pa == nullptr) { cntl->SetFailed("The socket was just failed"); return; } @@ -824,7 +824,7 @@ class DownloadServiceImpl : public ::test::DownloadService { // The remote client will not receive the data written to the // progressive attachment when the controller failed. cntl->SetFailed("Intentionally set controller failed"); - done_guard.reset(NULL); + done_guard.reset(nullptr); // Return value of Write after controller has failed should // be less than zero. @@ -850,7 +850,7 @@ TEST_F(HttpTest, read_chunked_response_normally) { brpc::Server server; DownloadServiceImpl svc; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); for (int i = 0; i < 3; ++i) { svc.set_done_place((DonePlace)i); @@ -860,7 +860,7 @@ TEST_F(HttpTest, read_chunked_response_normally) { ASSERT_EQ(0, channel.Init(butil::EndPoint(butil::my_ip(), port), &options)); brpc::Controller cntl; cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); std::string expected(PA_DATA_LEN, 0); @@ -874,7 +874,7 @@ TEST_F(HttpTest, read_failed_chunked_response) { brpc::Server server; DownloadServiceImpl svc; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -884,7 +884,7 @@ TEST_F(HttpTest, read_failed_chunked_response) { brpc::Controller cntl; cntl.http_request().uri() = "/DownloadService/DownloadFailed"; cntl.response_will_be_read_progressively(); - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); EXPECT_TRUE(cntl.response_attachment().empty()); ASSERT_TRUE(cntl.Failed()); ASSERT_NE(cntl.ErrorText().find("HTTP/1.1 500 Internal Server Error"), @@ -955,7 +955,7 @@ TEST_F(HttpTest, read_long_body_progressively) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); { brpc::Channel channel; brpc::ChannelOptions options; @@ -965,7 +965,7 @@ TEST_F(HttpTest, read_long_body_progressively) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); reader.reset(new ReadBody); @@ -1003,7 +1003,7 @@ TEST_F(HttpTest, read_short_body_progressively) { const int NREP = 10000; DownloadServiceImpl svc(DONE_BEFORE_CREATE_PA, NREP); EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); { brpc::Channel channel; brpc::ChannelOptions options; @@ -1013,7 +1013,7 @@ TEST_F(HttpTest, read_short_body_progressively) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); reader.reset(new ReadBody); @@ -1042,7 +1042,7 @@ TEST_F(HttpTest, read_progressively_after_cntl_destroys) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); { brpc::Channel channel; brpc::ChannelOptions options; @@ -1052,7 +1052,7 @@ TEST_F(HttpTest, read_progressively_after_cntl_destroys) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); reader.reset(new ReadBody); @@ -1088,7 +1088,7 @@ TEST_F(HttpTest, read_progressively_after_long_delay) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); { brpc::Channel channel; brpc::ChannelOptions options; @@ -1098,7 +1098,7 @@ TEST_F(HttpTest, read_progressively_after_long_delay) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); LOG(INFO) << "Sleep 3 seconds to make PA at server-side full"; @@ -1136,7 +1136,7 @@ TEST_F(HttpTest, skip_progressive_reading) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; options.protocol = brpc::PROTOCOL_HTTP; @@ -1145,7 +1145,7 @@ TEST_F(HttpTest, skip_progressive_reading) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); } @@ -1177,7 +1177,7 @@ TEST_F(HttpTest, failed_on_read_one_part) { DownloadServiceImpl svc(DONE_BEFORE_CREATE_PA, std::numeric_limits::max()); EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; options.protocol = brpc::PROTOCOL_HTTP; @@ -1186,7 +1186,7 @@ TEST_F(HttpTest, failed_on_read_one_part) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); cntl.ReadProgressiveAttachmentBy(new AlwaysFailRead); @@ -1203,7 +1203,7 @@ TEST_F(HttpTest, broken_socket_stops_progressive_reading) { DownloadServiceImpl svc(DONE_BEFORE_CREATE_PA, std::numeric_limits::max()); EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -1213,7 +1213,7 @@ TEST_F(HttpTest, broken_socket_stops_progressive_reading) { brpc::Controller cntl; cntl.response_will_be_read_progressively(); cntl.http_request().uri() = "/DownloadService/Download"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().empty()); reader.reset(new ReadBody); @@ -1315,7 +1315,7 @@ class UploadServiceImpl : public ::test::UploadService { private: void check_header(brpc::Controller* cntl) { const std::string* test_header = cntl->http_request().GetHeader(TEST_PROGRESSIVE_HEADER); - CHECK(test_header != NULL); + CHECK(test_header != nullptr); CHECK_EQ(*test_header, TEST_PROGRESSIVE_HEADER_VAL); } }; @@ -1328,7 +1328,7 @@ TEST_F(HttpTest, server_end_read_short_body_progressively) { UploadServiceImpl upsvc; brpc::Server server; EXPECT_EQ(0, server.AddService(&upsvc, opt)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -1353,7 +1353,7 @@ TEST_F(HttpTest, server_end_read_short_body_progressively) { } ++c; } - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()); } @@ -1367,7 +1367,7 @@ TEST_F(HttpTest, server_end_read_failed) { UploadServiceImpl upsvc; brpc::Server server; EXPECT_EQ(0, server.AddService(&upsvc, opt)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -1392,7 +1392,7 @@ TEST_F(HttpTest, server_end_read_failed) { } ++c; } - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); } #endif // BUTIL_USE_ASAN @@ -1401,7 +1401,7 @@ TEST_F(HttpTest, http2_sanity) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -1417,7 +1417,7 @@ TEST_F(HttpTest, http2_sanity) { big_req.set_message(message); cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.http_request().uri() = "/EchoService/Echo"; - channel.CallMethod(NULL, &cntl, &big_req, &res, NULL); + channel.CallMethod(nullptr, &cntl, &big_req, &res, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(EXP_RESPONSE, res.message()); @@ -1431,7 +1431,7 @@ TEST_F(HttpTest, http2_sanity) { cntl.http_request().set_content_type("application/json"); cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.http_request().uri() = "/EchoService/Echo"; - channel.CallMethod(NULL, &cntl, &req, &res, NULL); + channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(EXP_RESPONSE, res.message()); } @@ -1440,7 +1440,7 @@ TEST_F(HttpTest, http2_sanity) { brpc::SocketUniquePtr main_ptr; brpc::SocketUniquePtr agent_ptr; EXPECT_EQ(brpc::Socket::Address(channel._server_id, &main_ptr), 0); - EXPECT_EQ(main_ptr->GetAgentSocket(&agent_ptr, NULL), 0); + EXPECT_EQ(main_ptr->GetAgentSocket(&agent_ptr, nullptr), 0); brpc::policy::H2Context* ctx = static_cast(agent_ptr->parsing_context()); ASSERT_GT(ctx->_remote_window_left.load(butil::memory_order_relaxed), brpc::H2Settings::DEFAULT_INITIAL_WINDOW_SIZE / 2); @@ -1465,7 +1465,7 @@ TEST_F(HttpTest, http2_ping) { res_out.append(pingbuf, sizeof(pingbuf)); // parse response brpc::ParseResult res_pr = - brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_TRUE(res_pr.is_ok()); // process response ProcessMessage(brpc::policy::ProcessHttpResponse, res_pr.message(), false); @@ -1495,7 +1495,7 @@ TEST_F(HttpTest, http2_rst_before_header) { MakeH2EchoResponseBuf(&res_out, h2_stream_id); // parse response brpc::ParseResult res_pr = - brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_TRUE(res_pr.is_ok()); // process response ProcessMessage(brpc::policy::ProcessHttpResponse, res_pr.message(), false); @@ -1519,7 +1519,7 @@ TEST_F(HttpTest, http2_rst_after_header_and_data) { res_out.append(rstbuf, sizeof(rstbuf)); // parse response brpc::ParseResult res_pr = - brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_TRUE(res_pr.is_ok()); // process response ProcessMessage(brpc::policy::ProcessHttpResponse, res_pr.message(), false); @@ -1543,7 +1543,7 @@ TEST_F(HttpTest, http2_window_used_up_buffers_request) { brpc::policy::SerializeFrameHead(settingsbuf, nb, brpc::policy::H2_FRAME_SETTINGS, 0, 0); butil::IOBuf buf; buf.append(settingsbuf, brpc::policy::FRAME_HEAD_SIZE + nb); - brpc::policy::ParseH2Message(&buf, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&buf, _h2_client_sock.get(), false, nullptr); brpc::policy::H2Context* ctx = static_cast( _h2_client_sock->parsing_context()); @@ -1551,9 +1551,9 @@ TEST_F(HttpTest, http2_window_used_up_buffers_request) { for (int i = 0; i <= nsuc; i++) { brpc::policy::H2UnsentRequest* h2_req = brpc::policy::H2UnsentRequest::New(&cntl); cntl._current_call.stream_user_data = h2_req; - brpc::SocketMessage* socket_message = NULL; - brpc::policy::PackH2Request(NULL, &socket_message, cntl.call_id().value, - NULL, &cntl, request_buf, NULL); + brpc::SocketMessage* socket_message = nullptr; + brpc::policy::PackH2Request(nullptr, &socket_message, cntl.call_id().value, + nullptr, &cntl, request_buf, nullptr); butil::IOBuf dummy; butil::Status st = socket_message->AppendAndDestroySelf(&dummy, _h2_client_sock.get()); ASSERT_TRUE(st.ok()); @@ -1579,12 +1579,12 @@ TEST_F(HttpTest, http2_settings) { butil::IOBuf buf; buf.append(settingsbuf, brpc::policy::FRAME_HEAD_SIZE + nb); - brpc::policy::H2Context* ctx = new brpc::policy::H2Context(_socket.get(), NULL); + brpc::policy::H2Context* ctx = new brpc::policy::H2Context(_socket.get(), nullptr); CHECK_EQ(ctx->Init(), 0); _socket->initialize_parsing_context(&ctx); ctx->_conn_state = brpc::policy::H2_CONNECTION_READY; // parse settings - brpc::policy::ParseH2Message(&buf, _socket.get(), false, NULL); + brpc::policy::ParseH2Message(&buf, _socket.get(), false, nullptr); butil::IOPortal response_buf; CHECK_EQ(response_buf.append_from_file_descriptor(_pipe_fds[0], 1024), @@ -1619,11 +1619,11 @@ TEST_F(HttpTest, http2_goaway_with_debug_data) { buf.append(goawaybuf, brpc::policy::FRAME_HEAD_SIZE + payload_size); brpc::policy::H2Context* ctx = - new brpc::policy::H2Context(_h2_client_sock.get(), NULL); + new brpc::policy::H2Context(_h2_client_sock.get(), nullptr); CHECK_EQ(ctx->Init(), 0); _h2_client_sock->initialize_parsing_context(&ctx); ctx->_conn_state = brpc::policy::H2_CONNECTION_READY; - brpc::policy::ParseH2Message(&buf, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&buf, _h2_client_sock.get(), false, nullptr); // Reading the debug data instead would leave -1 here, which disables the // `_goaway_stream_id >= 0' check in TryToInsertStream. @@ -1657,7 +1657,7 @@ TEST_F(HttpTest, http2_not_closing_socket_when_rpc_timeout) { const int port = 8923; brpc::Server server; EXPECT_EQ(0, server.AddService(&_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; options.protocol = "h2"; @@ -1671,7 +1671,7 @@ TEST_F(HttpTest, http2_not_closing_socket_when_rpc_timeout) { brpc::Controller cntl; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.http_request().uri() = "/EchoService/Echo"; - channel.CallMethod(NULL, &cntl, &req, &res, NULL); + channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(EXP_RESPONSE, res.message()); } @@ -1685,7 +1685,7 @@ TEST_F(HttpTest, http2_not_closing_socket_when_rpc_timeout) { cntl.set_timeout_ms(50); cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.http_request().uri() = "/EchoService/Echo?sleep_ms=300"; - channel.CallMethod(NULL, &cntl, &req, &res, NULL); + channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); ASSERT_TRUE(cntl.Failed()); brpc::SocketUniquePtr ptr; @@ -1698,7 +1698,7 @@ TEST_F(HttpTest, http2_not_closing_socket_when_rpc_timeout) { brpc::Controller cntl; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.http_request().uri() = "/EchoService/Echo"; - channel.CallMethod(NULL, &cntl, &req, &res, NULL); + channel.CallMethod(nullptr, &cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(EXP_RESPONSE, res.message()); brpc::SocketUniquePtr ptr; @@ -1790,7 +1790,7 @@ TEST_F(HttpTest, http2_header_after_data) { } // parse response brpc::ParseResult res_pr = - brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_TRUE(res_pr.is_ok()); // process response ProcessMessage(brpc::policy::ProcessHttpResponse, res_pr.message(), false); @@ -1822,22 +1822,22 @@ TEST_F(HttpTest, http2_goaway_sanity) { res_out.append(goawaybuf, sizeof(goawaybuf)); // parse response brpc::ParseResult res_pr = - brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_TRUE(res_pr.is_ok()); // process response ProcessMessage(brpc::policy::ProcessHttpResponse, res_pr.message(), false); ASSERT_TRUE(!cntl.Failed()); // parse GOAWAY - res_pr = brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, NULL); + res_pr = brpc::policy::ParseH2Message(&res_out, _h2_client_sock.get(), false, nullptr); ASSERT_EQ(res_pr.error(), brpc::PARSE_ERROR_NOT_ENOUGH_DATA); // Since GOAWAY has been received, the next request should fail brpc::policy::H2UnsentRequest* h2_req = brpc::policy::H2UnsentRequest::New(&cntl); cntl._current_call.stream_user_data = h2_req; - brpc::SocketMessage* socket_message = NULL; - brpc::policy::PackH2Request(NULL, &socket_message, cntl.call_id().value, - NULL, &cntl, butil::IOBuf(), NULL); + brpc::SocketMessage* socket_message = nullptr; + brpc::policy::PackH2Request(nullptr, &socket_message, cntl.call_id().value, + nullptr, &cntl, butil::IOBuf(), nullptr); butil::IOBuf dummy; butil::Status st = socket_message->AppendAndDestroySelf(&dummy, _h2_client_sock.get()); ASSERT_EQ(st.error_code(), brpc::ELOGOFF); @@ -1874,10 +1874,10 @@ TEST_F(HttpTest, http2_handle_goaway_streams) { ids.push_back(cntl.call_id()); cntl.set_timeout_ms(-1); cntl.http_request().uri() = "/it-doesnt-matter"; - channel.CallMethod(NULL, &cntl, NULL, NULL, done); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, done); } - int servfd = accept(listenfd, NULL, NULL); + int servfd = accept(listenfd, nullptr, nullptr); ASSERT_GT(servfd, 0); // Sleep for a while to make sure that server has received all data. bthread_usleep(2000); @@ -2044,7 +2044,7 @@ TEST_F(HttpTest, proto_text_content_type) { cntl.Reset(); cntl.http_request().set_content_type("application/proto-text"); res.Clear(); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(EXP_RESPONSE, res.message()); ASSERT_EQ("application/proto-text", cntl.http_response().content_type()); @@ -2120,7 +2120,7 @@ class HttpServiceImpl : public ::test::HttpService { brpc::ClosureGuard done_guard(done); brpc::Controller* cntl = static_cast(cntl_base); const std::string* expect = cntl->http_request().GetHeader("Expect"); - ASSERT_TRUE(expect != NULL); + ASSERT_TRUE(expect != nullptr); ASSERT_EQ("100-continue", *expect); ASSERT_EQ(cntl->http_request().method(), brpc::HTTP_METHOD_POST); cntl->response_attachment().append("world"); @@ -2132,7 +2132,7 @@ TEST_F(HttpTest, http_head) { brpc::Server server; HttpServiceImpl svc; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; brpc::ChannelOptions options; @@ -2143,7 +2143,7 @@ TEST_F(HttpTest, http_head) { cntl.http_request().set_method(brpc::HTTP_METHOD_HEAD); cntl.http_request().uri().set_path("/HttpService/Head"); cntl.http_request().SetHeader("x-db-index", butil::IntToString(i)); - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); if (i % 2 == 0) { @@ -2180,7 +2180,7 @@ void MakeHttpRequestHeaders(butil::IOBuf* out, //the request-target consists of only the host name and port number of //the tunnel destination, seperated by a colon. For example, //Host: server.example.com:80 - if (h->GetHeader("host") == NULL) { + if (h->GetHeader("host") == nullptr) { os << "Host: "; if (!uri.host().empty()) { os << uri.host(); @@ -2200,15 +2200,15 @@ void MakeHttpRequestHeaders(butil::IOBuf* out, it != h->HeaderEnd(); ++it) { os << it->first << ": " << it->second << BRPC_CRLF; } - if (h->GetHeader("Accept") == NULL) { + if (h->GetHeader("Accept") == nullptr) { os << "Accept: */*" BRPC_CRLF; } // The fake "curl" user-agent may let servers return plain-text results. - if (h->GetHeader("User-Agent") == NULL) { + if (h->GetHeader("User-Agent") == nullptr) { os << "User-Agent: brpc/1.0 curl/7.0" BRPC_CRLF; } const std::string& user_info = h->uri().user_info(); - if (!user_info.empty() && h->GetHeader("Authorization") == NULL) { + if (!user_info.empty() && h->GetHeader("Authorization") == nullptr) { // NOTE: just assume user_info is well formatted, namely // ":". Users are very unlikely to add extra // characters in this part and even if users did, most of them are @@ -2243,7 +2243,7 @@ void ReadOneResponse(brpc::SocketUniquePtr& sock, bthread_usleep(1000); continue; } - brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&read_buf, sock.get(), false, NULL); + brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&read_buf, sock.get(), false, nullptr); ASSERT_TRUE(pr.error() == brpc::PARSE_ERROR_NOT_ENOUGH_DATA || pr.is_ok()); if (pr.is_ok()) { imsg_guard.reset(static_cast(pr.message())); @@ -2258,7 +2258,7 @@ TEST_F(HttpTest, http_expect) { brpc::Server server; HttpServiceImpl svc; EXPECT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - EXPECT_EQ(0, server.Start(port, NULL)); + EXPECT_EQ(0, server.Start(port, nullptr)); butil::EndPoint ep; ASSERT_EQ(0, butil::str2endpoint("127.0.0.1:8923", &ep)); @@ -2339,7 +2339,7 @@ TEST_F(HttpTest, grpc_auth_failed_response) { h2_msg->Init(h2_ctx, 1); // stream_id = 1 // Set socket and arg using existing test pattern - if (h2_msg->_socket == NULL) { + if (h2_msg->_socket == nullptr) { _socket->ReAddress(&h2_msg->_socket); } h2_msg->_arg = &_server; @@ -2419,7 +2419,7 @@ TEST_F(HttpTest, http10_auth_failed_response) { EXPECT_EQ((ssize_t)bytes_in_pipe, buf.append_from_file_descriptor(_pipe_fds[0], 1024)); // Parse HTTP/1.0 response and verify format - brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, NULL); + brpc::ParseResult pr = brpc::policy::ParseHttpMessage(&buf, _socket.get(), false, nullptr); EXPECT_EQ(brpc::PARSE_OK, pr.error()); brpc::policy::HttpContext* response_msg = static_cast(pr.message()); @@ -2435,12 +2435,12 @@ TEST_F(HttpTest, http10_auth_failed_response) { // Verify HTTP headers for HTTP/1.0 const std::string* content_length = response_msg->header().GetHeader("Content-Length"); - EXPECT_TRUE(content_length != NULL); + EXPECT_TRUE(content_length != nullptr); EXPECT_GT(std::stoi(*content_length), 0); // Content-Type may not always be set for error responses, check if present const std::string* content_type = response_msg->header().GetHeader("Content-Type"); - if (content_type != NULL) { + if (content_type != nullptr) { // If present, should contain text EXPECT_TRUE(content_type->find("text") != std::string::npos); } diff --git a/test/brpc_hulu_pbrpc_protocol_unittest.cpp b/test/brpc_hulu_pbrpc_protocol_unittest.cpp index d00b9d4528..e33d860e72 100644 --- a/test/brpc_hulu_pbrpc_protocol_unittest.cpp +++ b/test/brpc_hulu_pbrpc_protocol_unittest.cpp @@ -116,7 +116,7 @@ class HuluTest : public ::testing::Test{ virtual void TearDown() {}; void VerifyMessage(brpc::InputMessageBase* msg) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -125,7 +125,7 @@ class HuluTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket.get()->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -176,7 +176,7 @@ class HuluTest : public ::testing::Test{ butil::IOPortal buf; EXPECT_EQ((ssize_t)bytes_in_pipe, buf.append_from_file_descriptor(_pipe_fds[0], 1024)); - brpc::ParseResult pr = brpc::policy::ParseHuluMessage(&buf, NULL, false, NULL); + brpc::ParseResult pr = brpc::policy::ParseHuluMessage(&buf, nullptr, false, nullptr); EXPECT_EQ(brpc::PARSE_OK, pr.error()); brpc::policy::MostCommonMessage* msg = static_cast(pr.message()); @@ -200,13 +200,13 @@ class HuluTest : public ::testing::Test{ brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackHuluRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); brpc::ParseResult req_pr = - brpc::policy::ParseHuluMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseHuluMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessHuluRequest, req_msg, false); @@ -290,13 +290,13 @@ TEST_F(HuluTest, complete_flow) { ASSERT_FALSE(cntl.Failed()); cntl.request_attachment().append(EXP_REQUEST); brpc::policy::PackHuluRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Verify and handle request brpc::ParseResult req_pr = - brpc::policy::ParseHuluMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseHuluMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); VerifyMessage(req_msg); @@ -306,7 +306,7 @@ TEST_F(HuluTest, complete_flow) { butil::IOPortal response_buf; response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseHuluMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseHuluMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); ProcessMessage(brpc::policy::ProcessHuluResponse, res_msg, false); @@ -327,13 +327,13 @@ TEST_F(HuluTest, close_in_callback) { brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackHuluRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Handle request brpc::ParseResult req_pr = - brpc::policy::ParseHuluMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseHuluMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessHuluRequest, req_msg, false); diff --git a/test/brpc_input_messenger_unittest.cpp b/test/brpc_input_messenger_unittest.cpp index ae4afb6fb1..fcf233b154 100644 --- a/test/brpc_input_messenger_unittest.cpp +++ b/test/brpc_input_messenger_unittest.cpp @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) { brpc::SerializeRequestDefault, brpc::policy::PackHuluRequest, EmptyProcessHuluRequest, EmptyProcessHuluRequest, - NULL, NULL, NULL, + nullptr, nullptr, nullptr, brpc::CONNECTION_TYPE_ALL, "dummy_hulu" }; EXPECT_EQ(0, RegisterProtocol((brpc::ProtocolType)30, dummy_protocol)); return RUN_ALL_TESTS(); @@ -106,14 +106,14 @@ void* client_thread(void* arg) { butil::fd_guard fd(butil::unix_socket_connect(socket_name)); if (fd < 0) { PLOG(FATAL) << "Fail to connect to " << socket_name; - return NULL; + return nullptr; } #else butil::EndPoint point(butil::IP_ANY, 7878); - butil::fd_guard fd(butil::tcp_connect(point, NULL)); + butil::fd_guard fd(butil::tcp_connect(point, nullptr)); if (fd < 0) { PLOG(FATAL) << "Fail to connect to " << point; - return NULL; + return nullptr; } #endif @@ -132,7 +132,7 @@ void* client_thread(void* arg) { if (n < 0) { if (errno != EINTR) { PLOG(FATAL) << "Fail to write fd=" << fd; - return NULL; + return nullptr; } } else { ++m->times; @@ -144,7 +144,7 @@ void* client_thread(void* arg) { } } free(buf); - return NULL; + return nullptr; } TEST_F(MessengerTest, dispatch_tasks) { @@ -156,7 +156,7 @@ TEST_F(MessengerTest, dispatch_tasks) { const brpc::InputMessageHandler pairs[] = { { brpc::policy::ParseHuluMessage, - EmptyProcessHuluRequest, NULL, NULL, "dummy_hulu" } + EmptyProcessHuluRequest, nullptr, nullptr, "dummy_hulu" } }; for (size_t i = 0; i < NEPOLL; ++i) { @@ -170,14 +170,14 @@ TEST_F(MessengerTest, dispatch_tasks) { ASSERT_TRUE(listening_fd > 0); butil::make_non_blocking(listening_fd); ASSERT_EQ(0, messenger[i].AddHandler(pairs[0])); - ASSERT_EQ(0, messenger[i].StartAccept(listening_fd, -1, NULL, false)); + ASSERT_EQ(0, messenger[i].StartAccept(listening_fd, -1, nullptr, false)); } for (size_t i = 0; i < NCLIENT; ++i) { cm[i] = new ClientMeta; cm[i]->times = 0; cm[i]->bytes = 0; - ASSERT_EQ(0, pthread_create(&cth[i], NULL, client_thread, cm[i])); + ASSERT_EQ(0, pthread_create(&cth[i], nullptr, client_thread, cm[i])); } sleep(1); @@ -211,7 +211,7 @@ TEST_F(MessengerTest, dispatch_tasks) { << "/s"; for (size_t i = 0; i < NCLIENT; ++i) { - pthread_join(cth[i], NULL); + pthread_join(cth[i], nullptr); printf("joined client %lu\n", i); } for (size_t i = 0; i < NEPOLL; ++i) { diff --git a/test/brpc_interceptor_unittest.cpp b/test/brpc_interceptor_unittest.cpp index 6238c3fefd..ca9ab40f11 100644 --- a/test/brpc_interceptor_unittest.cpp +++ b/test/brpc_interceptor_unittest.cpp @@ -118,7 +118,7 @@ class InterceptorTest : public ::testing::Test { ::test::EchoResponse& res) { for (g_index = 0; g_index < 1000; ++g_index) { brpc::Controller cntl; - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); if (g_index % 2 == 0) { ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(EREJECT, cntl.ErrorCode()); @@ -190,7 +190,7 @@ TEST_F(InterceptorTest, sanity) { for (g_index = 0; g_index < 1000; ++g_index) { brpc::Controller cntl; brpc::NsheadMessage response; - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); if (g_index % 2 == 0) { ASSERT_EQ(NSHEAD_EXP_RESPONSE, response.body.to_string()); } else { diff --git a/test/brpc_load_balancer_unittest.cpp b/test/brpc_load_balancer_unittest.cpp index 1b326a8ff0..8748625c73 100644 --- a/test/brpc_load_balancer_unittest.cpp +++ b/test/brpc_load_balancer_unittest.cpp @@ -155,7 +155,7 @@ void* DBDBthread(void* arg) { bthread_usleep(100 * 1000); } - return NULL; + return nullptr; } template @@ -170,7 +170,7 @@ void DBDMultiBthread() { bthread_t tids[10000]; for (size_t i = 0; i < ARRAY_SIZE(tids); ++i) { - ASSERT_EQ(0, bthread_start_urgent(&tids[i], NULL, DBDBthread, &d)); + ASSERT_EQ(0, bthread_start_urgent(&tids[i], nullptr, DBDBthread, &d)); } // Modify during reading. @@ -183,7 +183,7 @@ void DBDMultiBthread() { } exitFlag = true; for (size_t i = 0; i < ARRAY_SIZE(tids); ++i) { - ASSERT_EQ(0, bthread_join(tids[i], NULL)); + ASSERT_EQ(0, bthread_join(tids[i], nullptr)); } } @@ -216,7 +216,7 @@ struct BAIDU_CACHELINE_ALIGNMENT PerfArgs { int64_t elapse_ns; bool ready; - PerfArgs() : dbd(NULL), counter(0), elapse_ns(0), ready(false) {} + PerfArgs() : dbd(nullptr), counter(0), elapse_ns(0), ready(false) {} }; template @@ -241,7 +241,7 @@ void* read_dbd(void* void_arg) { } t.stop(); args->elapse_ns = t.n_elapsed(); - return NULL; + return nullptr; } template @@ -256,7 +256,7 @@ void PerfTest(int thread_num, bool modify_during_reading) { std::vector> args(thread_num); for (int i = 0; i < thread_num; ++i) { args[i].dbd = &dbd; - ASSERT_EQ(0, pthread_create(&threads[i], NULL, read_dbd, &args[i])); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, read_dbd, &args[i])); } while (true) { bool all_ready = true; @@ -291,7 +291,7 @@ void PerfTest(int thread_num, bool modify_during_reading) { int64_t wait_time = 0; int64_t count = 0; for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); wait_time += args[i].elapse_ns; count += args[i].counter; } @@ -372,7 +372,7 @@ static void ValidateLALB(LALB& lalb, size_t N) { for (size_t R = 0; R < 2; ++R) { ASSERT_EQ((int64_t*)d[R].weight_tree[i].left, &lalb._left_weights[i]); size_t* pindex = d[R].server_map.seek(d[R].weight_tree[i].server_id); - ASSERT_TRUE(pindex != NULL && *pindex == i); + ASSERT_TRUE(pindex != nullptr && *pindex == i); } total += d[0].weight_tree[i].weight->volatile_value(); } @@ -435,7 +435,7 @@ void* select_server(void* arg) { brpc::LoadBalancer* c = sa->lb; brpc::SocketUniquePtr ptr; CountMap *selected_count = new CountMap; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); uint32_t rand_seed = rand(); if (sa->hash) { @@ -468,8 +468,8 @@ class SaveRecycle : public brpc::SocketUser { TEST_F(LoadBalancerTest, update_while_selection) { for (size_t round = 0; round < 5; ++round) { - brpc::LoadBalancer* lb = NULL; - SelectArg sa = { NULL, NULL}; + brpc::LoadBalancer* lb = nullptr; + SelectArg sa = { nullptr, nullptr}; bool is_lalb = false; if (round == 0) { lb = new brpc::policy::RoundRobinLoadBalancer; @@ -488,7 +488,7 @@ TEST_F(LoadBalancerTest, update_while_selection) { // Accessing empty lb should result in error. brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, true, 0, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, true, 0, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(ENODATA, lb->SelectServer(in, &out)); @@ -528,7 +528,7 @@ TEST_F(LoadBalancerTest, update_while_selection) { butil::Timer tm; tm.start(); for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, select_server, &sa)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, select_server, &sa)); } std::vector removed; const size_t REP = 200; @@ -610,8 +610,8 @@ TEST_F(LoadBalancerTest, update_while_selection) { TEST_F(LoadBalancerTest, fairness) { for (size_t round = 0; round < 6; ++round) { - brpc::LoadBalancer* lb = NULL; - SelectArg sa = { NULL, NULL}; + brpc::LoadBalancer* lb = nullptr; + SelectArg sa = { nullptr, nullptr}; if (round == 0) { lb = new brpc::policy::RoundRobinLoadBalancer; } else if (round == 1) { @@ -661,7 +661,7 @@ TEST_F(LoadBalancerTest, fairness) { } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, select_server, &sa)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, select_server, &sa)); } bthread_usleep(10000); ProfilerStart((lb_name + ".prof").c_str()); @@ -794,7 +794,7 @@ TEST_F(LoadBalancerTest, consistent_hashing) { const size_t SELECT_TIMES = 1000000; std::map times; brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; ::brpc::LoadBalancer::SelectOut out(&ptr); for (size_t i = 0; i < SELECT_TIMES; ++i) { in.has_request_code = true; @@ -871,7 +871,7 @@ TEST_F(LoadBalancerTest, weighted_round_robin) { // consistent with weight configured. std::map select_result; brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); int total_weight = 12; std::vector select_servers; @@ -983,7 +983,7 @@ TEST_F(LoadBalancerTest, weighted_randomized) { // weight randomized with weight configured. std::map select_result; brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); int run_times = configed_weight_sum * 100; std::vector select_servers; @@ -1051,7 +1051,7 @@ TEST_F(LoadBalancerTest, weighted_randomized_equal_weight) { std::map select_result; brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); const int run_times = 40000; for (int i = 0; i < run_times; ++i) { @@ -1104,7 +1104,7 @@ TEST_F(LoadBalancerTest, health_check_no_valid_server) { // Without setting anything, the lb should work fine for (int i = 0; i < 4; ++i) { brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(0, lb->SelectServer(in, &out)); } @@ -1114,7 +1114,7 @@ TEST_F(LoadBalancerTest, health_check_no_valid_server) { ptr->_ninflight_app_health_check.store(1, butil::memory_order_relaxed); for (int i = 0; i < 4; ++i) { brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(0, lb->SelectServer(in, &out)); // After putting server[0] into health check state, the only choice is servers[1] @@ -1125,7 +1125,7 @@ TEST_F(LoadBalancerTest, health_check_no_valid_server) { ptr->_ninflight_app_health_check.store(1, butil::memory_order_relaxed); for (int i = 0; i < 4; ++i) { brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); // There is no server available ASSERT_EQ(EHOSTDOWN, lb->SelectServer(in, &out)); @@ -1140,7 +1140,7 @@ TEST_F(LoadBalancerTest, health_check_no_valid_server) { bool get_server2 = false; for (int i = 0; i < 20; ++i) { brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(0, lb->SelectServer(in, &out)); if (ptr->remote_side().port == 8832) { @@ -1181,7 +1181,7 @@ TEST_F(LoadBalancerTest, revived_from_all_failed_sanity) { lb->AddServer(id); } brpc::SocketUniquePtr sptr; - brpc::LoadBalancer::SelectIn in = { 0, false, true, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { 0, false, true, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&sptr); ASSERT_EQ(0, lb->SelectServer(in, &out)); @@ -1312,7 +1312,7 @@ TEST_F(LoadBalancerTest, revived_from_all_failed_intergrated) { { // trigger one server to health check brpc::Controller cntl; - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); } // This sleep make one server revived 700ms earlier than the other server, which // can make the server down again if no request limit policy are applied here. @@ -1320,20 +1320,20 @@ TEST_F(LoadBalancerTest, revived_from_all_failed_intergrated) { { // trigger the other server to health check brpc::Controller cntl; - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); } butil::EndPoint point(butil::IP_ANY, 7777); EchoServiceImpl service; brpc::Server server; ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(point, NULL)); + ASSERT_EQ(0, server.Start(point, nullptr)); butil::EndPoint point2(butil::IP_ANY, 7778); EchoServiceImpl service2; brpc::Server server2; ASSERT_EQ(0, server2.AddService(&service2, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server2.Start(point2, NULL)); + ASSERT_EQ(0, server2.Start(point2, nullptr)); int64_t start_ms = butil::cpuwide_time_ms(); while ((butil::cpuwide_time_ms() - start_ms) < 3500) { @@ -1413,7 +1413,7 @@ TEST_F(LoadBalancerTest, la_records_latency_with_consistent_time_source) { const std::string s = os.str(); const size_t p = s.find("avg_latency="); if (p == std::string::npos) return -1; - return strtoll(s.c_str() + p + strlen("avg_latency="), NULL, 10); + return strtoll(s.c_str() + p + strlen("avg_latency="), nullptr, 10); }; // Drive a few "RPCs": pick a server, sleep ~2ms, feed back. begin_time_us @@ -1422,11 +1422,11 @@ TEST_F(LoadBalancerTest, la_records_latency_with_consistent_time_source) { for (int i = 0; i < 8; ++i) { const int64_t begin_us = butil::gettimeofday_us(); brpc::SocketUniquePtr ptr; - brpc::LoadBalancer::SelectIn in = { begin_us, true, false, 0u, NULL }; + brpc::LoadBalancer::SelectIn in = { begin_us, true, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(0, lalb.SelectServer(in, &out)); bthread_usleep(2000); - brpc::LoadBalancer::CallInfo ci = { begin_us, id.id, 0, NULL }; + brpc::LoadBalancer::CallInfo ci = { begin_us, id.id, 0, nullptr }; lalb.Feedback(ci); } diff --git a/test/brpc_mcpack2pb_unittest.cpp b/test/brpc_mcpack2pb_unittest.cpp index 6718cae93b..c0261540d3 100644 --- a/test/brpc_mcpack2pb_unittest.cpp +++ b/test/brpc_mcpack2pb_unittest.cpp @@ -47,7 +47,7 @@ TEST(Mcpack2pbParserTest, StringFieldWithZeroValueSize) { mcpack2pb::ObjectIterator it1(&stream, body.size() - stream.popped_bytes()); bool found_content = false; - for (; it1 != NULL; ++it1) { + for (; it1 != nullptr; ++it1) { if (it1->name == "content") { found_content = true; break; @@ -57,9 +57,9 @@ TEST(Mcpack2pbParserTest, StringFieldWithZeroValueSize) { ASSERT_EQ(mcpack2pb::FIELD_ARRAY, it1->value.type()); mcpack2pb::ArrayIterator it2(it1->value); - ASSERT_TRUE(it2 != NULL); + ASSERT_TRUE(it2 != nullptr); bool found_service_name = false; - for (mcpack2pb::ObjectIterator it3(*it2); it3 != NULL; ++it3) { + for (mcpack2pb::ObjectIterator it3(*it2); it3 != nullptr; ++it3) { if (it3->name == "service_name") { found_service_name = true; ASSERT_EQ(mcpack2pb::FIELD_STRING, it3->value.type()); @@ -94,7 +94,7 @@ TEST(Mcpack2pbParserTest, ParseStringField) { ASSERT_NE(0u, mcpack2pb::unbox(&stream)); mcpack2pb::ObjectIterator it(&stream, body.size() - stream.popped_bytes()); - ASSERT_TRUE(it != NULL); + ASSERT_TRUE(it != nullptr); EXPECT_EQ("msg", it->name.as_string()); ASSERT_EQ(mcpack2pb::FIELD_STRING, it->value.type()); std::string value; diff --git a/test/brpc_memcache_unittest.cpp b/test/brpc_memcache_unittest.cpp index 3b7e676bdd..76c4ca4b53 100644 --- a/test/brpc_memcache_unittest.cpp +++ b/test/brpc_memcache_unittest.cpp @@ -58,7 +58,7 @@ TEST(MemcacheParserTest, RejectOversizedResponseBeforeBufferingBody) { buf.append(&header, sizeof(header)); EXPECT_EQ(brpc::PARSE_ERROR_TOO_BIG_DATA, brpc::policy::ParseMemcacheMessage( - &buf, socket.get(), false, NULL).error()); + &buf, socket.get(), false, nullptr).error()); } @@ -137,7 +137,7 @@ static void RunMemcached() { puts("[Starting memcached]"); char* const argv[] = { (char*)MEMCACHED_BIN, (char*)"-p", (char*)MEMCACHED_PORT, - NULL }; + nullptr }; if (execvp(MEMCACHED_BIN, argv) < 0) { puts("Fail to run " MEMCACHED_BIN); exit(1); @@ -173,14 +173,14 @@ TEST_F(MemcacheTest, sanity) { // Clear all contents in MC which is still holding older data after // restarting in Ubuntu 18.04 (mc=1.5.6) request.Flush(0); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(response.PopFlush()); cntl.Reset(); request.Clear(); request.Get("hello"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); std::string value; uint32_t flags = 0; @@ -191,7 +191,7 @@ TEST_F(MemcacheTest, sanity) { cntl.Reset(); request.Clear(); request.Set("hello", "world", 0xdeadbeef, 10, 0); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(response.PopSet(&cas_value)) << response.LastError(); ASSERT_EQ("", response.LastError()); @@ -199,7 +199,7 @@ TEST_F(MemcacheTest, sanity) { cntl.Reset(); request.Clear(); request.Get("hello"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_TRUE(response.PopGet(&value, &flags, &cas_value)); ASSERT_EQ("", response.LastError()); @@ -211,7 +211,7 @@ TEST_F(MemcacheTest, sanity) { request.Clear(); request.Set("hello", "world2", 0xdeadbeef, 10, cas_value/*intended match*/); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); uint64_t cas_value2 = 0; ASSERT_TRUE(response.PopSet(&cas_value2)) << response.LastError(); @@ -220,7 +220,7 @@ TEST_F(MemcacheTest, sanity) { request.Clear(); request.Set("hello", "world3", 0xdeadbeef, 10, cas_value2 + 1/*intended unmatch*/); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); uint64_t cas_value3 = ~0; ASSERT_FALSE(response.PopSet(&cas_value3)); @@ -243,7 +243,7 @@ TEST_F(MemcacheTest, incr_and_decr) { request.Increment("counter1", 2, 10, 10); request.Decrement("counter1", 1, 10, 10); request.Increment("counter1", 3, 10, 10); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); uint64_t new_value1 = 0; uint64_t cas_value1 = 0; @@ -276,7 +276,7 @@ TEST_F(MemcacheTest, version) { brpc::MemcacheResponse response; brpc::Controller cntl; request.Version(); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); std::string version; ASSERT_TRUE(response.PopVersion(&version)) << response.LastError(); diff --git a/test/brpc_mongo_protocol_unittest.cpp b/test/brpc_mongo_protocol_unittest.cpp index 64e3bf394c..68e4acdc7a 100644 --- a/test/brpc_mongo_protocol_unittest.cpp +++ b/test/brpc_mongo_protocol_unittest.cpp @@ -115,7 +115,7 @@ class MongoTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; diff --git a/test/brpc_mysql_auth_handshake_unittest.cpp b/test/brpc_mysql_auth_handshake_unittest.cpp index 98450834ce..7c8cd7c56a 100644 --- a/test/brpc_mysql_auth_handshake_unittest.cpp +++ b/test/brpc_mysql_auth_handshake_unittest.cpp @@ -507,7 +507,7 @@ static const char* const kSpawnPwPassword = "brpc_test_password"; static bool IsSpawnedServer() { return g_mysqld_pid > 0; } // Returns the first non-empty-password credential matching |use_ssl|, or -// NULL when the active server exposes none (so the caller can skip). +// nullptr when the active server exposes none (so the caller can skip). static const AuthCase* FindNonEmptyCase(bool use_ssl) { for (size_t i = 0; i < g_auth_cases.size(); ++i) { if (!g_auth_cases[i].password.empty() && @@ -515,7 +515,7 @@ static const AuthCase* FindNonEmptyCase(bool use_ssl) { return &g_auth_cases[i]; } } - return NULL; + return nullptr; } // Absolute path to the throwaway data directory. mysqld resolves a @@ -523,7 +523,7 @@ static const AuthCase* FindNonEmptyCase(bool use_ssl) { // directory), so the path handed to mysqld must be absolute. static std::string TestDataDir() { char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { + if (getcwd(cwd, sizeof(cwd)) == nullptr) { return std::string("/tmp/mysql_data_for_test"); } return std::string(cwd) + "/mysql_data_for_test"; @@ -642,7 +642,7 @@ static void RunMysqlServer() { (char*)logerr_arg.c_str(), (char*)"--mysqlx=OFF", (char*)"--bind-address=127.0.0.1", - NULL }; + nullptr }; if (execvp(MYSQLD_BIN, argv) < 0) { puts("Fail to run " MYSQLD_BIN); exit(1); @@ -696,7 +696,7 @@ static void RunMysqlServer() { // Reads exactly |n| bytes into |buf|. When |ssl| is non-null the bytes // come from the SSL session; otherwise from the raw fd. Returns true on // success. -static bool ReadFull(int fd, char* buf, size_t n, SSL* ssl = NULL) { +static bool ReadFull(int fd, char* buf, size_t n, SSL* ssl = nullptr) { size_t off = 0; while (off < n) { ssize_t r = ssl ? SSL_read(ssl, buf + off, static_cast(n - off)) @@ -714,7 +714,7 @@ static bool ReadFull(int fd, char* buf, size_t n, SSL* ssl = NULL) { // Writes all of |data| (over SSL when |ssl| is non-null). Returns true // on success. -static bool WriteFull(int fd, const std::string& data, SSL* ssl = NULL) { +static bool WriteFull(int fd, const std::string& data, SSL* ssl = nullptr) { size_t off = 0; while (off < data.size()) { ssize_t w = ssl ? SSL_write(ssl, data.data() + off, @@ -734,7 +734,7 @@ static bool WriteFull(int fd, const std::string& data, SSL* ssl = NULL) { // Reads one MySQL packet (4-byte header + payload). On success stores // the payload in *payload, the sequence id in *seq, and returns true. static bool ReadPacket(int fd, std::string* payload, uint8_t* seq, - SSL* ssl = NULL) { + SSL* ssl = nullptr) { char hdr[kPacketHeaderLen]; if (!ReadFull(fd, hdr, sizeof(hdr), ssl)) { return false; @@ -754,7 +754,7 @@ static bool ReadPacket(int fd, std::string* payload, uint8_t* seq, // Frames |payload| with a packet header carrying |seq| and writes it. static bool WritePacket(int fd, const std::string& payload, uint8_t seq, - SSL* ssl = NULL) { + SSL* ssl = nullptr) { std::string out; PacketHeader header; header.payload_len = static_cast(payload.size()); @@ -771,7 +771,7 @@ static const uint32_t kClientSSL = 0x00000800; // Sends the MySQL SSLRequest packet (the 32-byte HandshakeResponse41 // fixed prefix with CLIENT_SSL set, no username) at sequence |seq|, then // performs a SSL client handshake on |fd|. Returns the SSL* on success -// (caller owns it) or NULL on failure. +// (caller owns it) or nullptr on failure. static SSL* UpgradeToSSL(int fd, uint32_t capability_flags, uint8_t seq) { // SSLRequest payload: 4B caps + 4B max_packet_size + 1B charset + 23B // reserved = 32 bytes, with CLIENT_SSL set. @@ -785,26 +785,26 @@ static SSL* UpgradeToSSL(int fd, uint32_t capability_flags, uint8_t seq) { payload.push_back(static_cast(0x21)); // charset utf8_general_ci payload.append(23, '\0'); if (!WritePacket(fd, payload, seq)) { - return NULL; + return nullptr; } // One client SSL_CTX for the whole process; certificate not verified // (mysqld's auto-generated cert is self-signed). - static SSL_CTX* ctx = NULL; - if (ctx == NULL) { + static SSL_CTX* ctx = nullptr; + if (ctx == nullptr) { ctx = SSL_CTX_new(TLS_client_method()); - if (ctx == NULL) { - return NULL; + if (ctx == nullptr) { + return nullptr; } - SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); + SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nullptr); } SSL* ssl = SSL_new(ctx); - if (ssl == NULL) { - return NULL; + if (ssl == nullptr) { + return nullptr; } SSL_set_fd(ssl, fd); if (SSL_connect(ssl) != 1) { SSL_free(ssl); - return NULL; + return nullptr; } return ssl; } @@ -863,7 +863,7 @@ static LoginTrace PerformSha2Login(int fd, const std::string& user, const std::string& initial_plugin = std::string()) { LoginTrace t; - SSL* ssl = NULL; + SSL* ssl = nullptr; std::string payload; uint8_t seq = 0; if (!ReadPacket(fd, &payload, &seq)) { // greeting is always plaintext @@ -899,7 +899,7 @@ static LoginTrace PerformSha2Login(int fd, const std::string& user, uint8_t next_seq = static_cast(seq + 1); if (use_ssl) { ssl = UpgradeToSSL(fd, resp.capability_flags, next_seq); - if (ssl == NULL) { + if (ssl == nullptr) { t.err = "SSL upgrade (SSLRequest + SSL_connect) failed"; goto done; } @@ -1038,7 +1038,7 @@ static LoginTrace PerformSha2Login(int fd, const std::string& user, goto done; } done: - if (ssl != NULL) { + if (ssl != nullptr) { SSL_shutdown(ssl); SSL_free(ssl); } @@ -1129,14 +1129,14 @@ TEST_F(MysqlHandshakeServerTest, AuthenticatesEmptyPasswordFastPath) { puts("Skipped due to absence of mysqld"); return; } - const AuthCase* empty = NULL; + const AuthCase* empty = nullptr; for (size_t i = 0; i < g_auth_cases.size(); ++i) { if (g_auth_cases[i].password.empty() && !g_auth_cases[i].use_ssl) { empty = &g_auth_cases[i]; break; } } - if (empty == NULL) { + if (empty == nullptr) { puts("Skipped: no empty-password credential on this server"); return; } @@ -1159,7 +1159,7 @@ TEST_F(MysqlHandshakeServerTest, FullAuthenticationNotSSL) { return; } const AuthCase* c = FindNonEmptyCase(/*use_ssl=*/false); - if (c == NULL) { + if (c == nullptr) { puts("Skipped: no non-empty-password credential for plaintext " "full-auth (need a running server with -mysql_password, or the " "mysql client for the spawned account)"); @@ -1194,7 +1194,7 @@ TEST_F(MysqlHandshakeServerTest, FullAuthenticationSSL) { return; } const AuthCase* c = FindNonEmptyCase(/*use_ssl=*/true); - if (c == NULL) { + if (c == nullptr) { puts("Skipped: no non-empty-password credential for SSL full-auth"); return; } diff --git a/test/brpc_mysql_auth_packet_unittest.cpp b/test/brpc_mysql_auth_packet_unittest.cpp index aefe2c1e69..0fd9ed1a81 100644 --- a/test/brpc_mysql_auth_packet_unittest.cpp +++ b/test/brpc_mysql_auth_packet_unittest.cpp @@ -217,7 +217,7 @@ TEST(LenencStringTest, NonNull_SetsIsNullFalse) { } TEST(LenencStringTest, EmptyIsNotNull) { - // Empty string (lenenc 0x00) must NOT be reported as NULL. + // Empty string (lenenc 0x00) must NOT be reported as nullptr. std::string buf; EncodeLengthEncodedString(butil::StringPiece(""), &buf); std::string out = "stale"; diff --git a/test/brpc_mysql_connection_type_unittest.cpp b/test/brpc_mysql_connection_type_unittest.cpp index cc068ae65b..4aa89ea59b 100644 --- a/test/brpc_mysql_connection_type_unittest.cpp +++ b/test/brpc_mysql_connection_type_unittest.cpp @@ -109,7 +109,7 @@ static std::string g_password; static std::string TestDataDir() { char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { + if (getcwd(cwd, sizeof(cwd)) == nullptr) { return std::string("/tmp/mysql_conn_type_data_for_test"); } return std::string(cwd) + "/mysql_conn_type_data_for_test"; @@ -213,7 +213,7 @@ static void StartServerOnce() { (char*)logerr_arg.c_str(), (char*)"--mysqlx=OFF", (char*)"--bind-address=127.0.0.1", - NULL}; + nullptr}; if (execvp(MYSQLD_BIN, argv) < 0) { puts("Fail to run " MYSQLD_BIN); exit(1); @@ -262,7 +262,7 @@ class MysqlConnectionTypeTest : public testing::Test { "integration test (set -mysql_use_running_server " "or install mysqld)"; } - brpc::policy::MysqlAuthenticator* auth = NULL; + brpc::policy::MysqlAuthenticator* auth = nullptr; ASSERT_EQ(0, InitShortChannel(&_channel, &auth)); _auth.reset(auth); } @@ -288,7 +288,7 @@ TEST_F(MysqlConnectionTypeTest, PreparedStatementUnderShortRePreparesAndSucceeds for (int iter = 0; iter < 5; ++iter) { brpc::MysqlStatementUniquePtr stmt = brpc::NewMysqlStatement(_channel, "SELECT ? AS v"); - ASSERT_TRUE(stmt != NULL) << "iter " << iter; + ASSERT_TRUE(stmt != nullptr) << "iter " << iter; ASSERT_EQ(1u, stmt->param_count()) << "iter " << iter; const int32_t bound = (int32_t)(40 + iter); @@ -297,7 +297,7 @@ TEST_F(MysqlConnectionTypeTest, PreparedStatementUnderShortRePreparesAndSucceeds brpc::MysqlResponse resp; brpc::Controller cntl; - _channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + _channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << "iter " << iter << ": " << cntl.ErrorText(); ASSERT_GE(resp.reply_size(), 1) << "iter " << iter; @@ -330,7 +330,7 @@ TEST_F(MysqlConnectionTypeTest, PlainQueryUnderShortMustSucceed) { brpc::MysqlResponse resp; brpc::Controller cntl; - _channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + _channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(resp.reply_size(), 1); diff --git a/test/brpc_mysql_pool_concurrency_unittest.cpp b/test/brpc_mysql_pool_concurrency_unittest.cpp index a942a02873..4534710e7c 100644 --- a/test/brpc_mysql_pool_concurrency_unittest.cpp +++ b/test/brpc_mysql_pool_concurrency_unittest.cpp @@ -134,7 +134,7 @@ static std::string g_schema; static std::string TestDataDir() { char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { + if (getcwd(cwd, sizeof(cwd)) == nullptr) { return std::string("/tmp/mysql_pool_conc_data_for_test"); } return std::string(cwd) + "/mysql_pool_conc_data_for_test"; @@ -240,7 +240,7 @@ static void StartServerOnce() { (char*)logerr_arg.c_str(), (char*)"--mysqlx=OFF", (char*)"--bind-address=127.0.0.1", - NULL}; + nullptr}; if (execvp(MYSQLD_BIN, argv) < 0) { puts("Fail to run " MYSQLD_BIN); exit(1); @@ -269,7 +269,7 @@ static bool RunPlain(brpc::Channel& channel, const std::string& sql, return false; } brpc::Controller cntl; - channel.CallMethod(NULL, &cntl, &req, resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, resp, nullptr); if (cntl.Failed()) { if (err) *err = "rpc failed: " + cntl.ErrorText(); return false; @@ -300,7 +300,7 @@ static bool RunInTx(brpc::Channel& channel, const brpc::MysqlTransaction* tx, return false; } brpc::Controller cntl; - channel.CallMethod(NULL, &cntl, &req, resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, resp, nullptr); if (cntl.Failed()) { if (err) *err = "rpc failed: " + cntl.ErrorText(); return false; @@ -375,7 +375,7 @@ class MysqlPoolConcurrencyTest : public testing::Test { << "failed to set gflag max_connection_pool_size"; // Create the schema over a schema-less channel, then bind to it. - brpc::policy::MysqlAuthenticator* setup_auth = NULL; + brpc::policy::MysqlAuthenticator* setup_auth = nullptr; ASSERT_EQ(0, InitPooledChannel(&_setup_channel, &setup_auth, "")); _setup_auth.reset(setup_auth); brpc::MysqlResponse resp; @@ -384,7 +384,7 @@ class MysqlPoolConcurrencyTest : public testing::Test { "CREATE DATABASE IF NOT EXISTS " + g_schema, &resp, &err)) << err; - brpc::policy::MysqlAuthenticator* auth = NULL; + brpc::policy::MysqlAuthenticator* auth = nullptr; ASSERT_EQ(0, InitPooledChannel(&_channel, &auth, g_schema)); _auth.reset(auth); } @@ -414,7 +414,7 @@ static bool WU_TxnCommitVisible(brpc::Channel& ch, const std::string& table, brpc::MysqlResponse resp; brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(ch, brpc::MysqlTransactionOptions()); - if (tx == NULL) { *err = "WU1: NewMysqlTransaction NULL"; return false; } + if (tx == nullptr) { *err = "WU1: NewMysqlTransaction NULL"; return false; } if (!RunInTx(ch, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d, '%s')", table.c_str(), id, name), @@ -453,7 +453,7 @@ static bool WU_TxnRollbackDiscards(brpc::Channel& ch, const std::string& table, brpc::MysqlResponse resp; brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(ch, brpc::MysqlTransactionOptions()); - if (tx == NULL) { *err = "WU2: NewMysqlTransaction NULL"; return false; } + if (tx == nullptr) { *err = "WU2: NewMysqlTransaction NULL"; return false; } if (!RunInTx(ch, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d, 'cory')", table.c_str(), id), @@ -486,7 +486,7 @@ static bool WU_TxnReadsOwnWrite(brpc::Channel& ch, const std::string& table, brpc::MysqlResponse resp; brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(ch, brpc::MysqlTransactionOptions()); - if (tx == NULL) { *err = "WU3: NewMysqlTransaction NULL"; return false; } + if (tx == nullptr) { *err = "WU3: NewMysqlTransaction NULL"; return false; } if (!RunInTx(ch, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d, '%s')", table.c_str(), id, name), @@ -524,13 +524,13 @@ static bool WU_PreparedBindInt(brpc::Channel& ch, const std::string& table, brpc::MysqlStatementUniquePtr stmt = brpc::NewMysqlStatement( ch, butil::string_printf("SELECT name FROM %s WHERE id=?", table.c_str())); - if (stmt == NULL) { *err = "WU4: NewMysqlStatement NULL"; return false; } + if (stmt == nullptr) { *err = "WU4: NewMysqlStatement NULL"; return false; } if (stmt->param_count() != 1u) { *err = "WU4: param_count != 1"; return false; } brpc::MysqlRequest req(stmt.get()); if (!req.AddParam((int32_t)id)) { *err = "WU4: AddParam failed"; return false; } brpc::Controller cntl; - ch.CallMethod(NULL, &cntl, &req, &resp, NULL); + ch.CallMethod(nullptr, &cntl, &req, &resp, nullptr); if (cntl.Failed()) { *err = "WU4 rpc: " + cntl.ErrorText(); return false; } if (resp.reply_size() < 1 || !resp.reply(0).is_resultset()) { *err = "WU4: not a resultset"; return false; @@ -556,7 +556,7 @@ static bool WU_PreparedArithmetic(brpc::Channel& ch, int worker, int iter, const long long expect = (long long)a + b; brpc::MysqlStatementUniquePtr stmt = brpc::NewMysqlStatement(ch, "SELECT CAST(? AS SIGNED) + CAST(? AS SIGNED)"); - if (stmt == NULL) { *err = "WU5: NewMysqlStatement NULL"; return false; } + if (stmt == nullptr) { *err = "WU5: NewMysqlStatement NULL"; return false; } if (stmt->param_count() != 2u) { *err = "WU5: param_count != 2"; return false; } brpc::MysqlRequest req(stmt.get()); @@ -565,7 +565,7 @@ static bool WU_PreparedArithmetic(brpc::Channel& ch, int worker, int iter, } brpc::MysqlResponse resp; brpc::Controller cntl; - ch.CallMethod(NULL, &cntl, &req, &resp, NULL); + ch.CallMethod(nullptr, &cntl, &req, &resp, nullptr); if (cntl.Failed()) { *err = "WU5 rpc: " + cntl.ErrorText(); return false; } if (resp.reply_size() < 1 || !resp.reply(0).is_resultset() || resp.reply(0).row_count() != 1u) { @@ -609,11 +609,11 @@ void* MixWorker(void* p) { if (!ok) { a->error = butil::string_printf("worker %d iter %d pick %d: %s", a->worker_id, iter, pick, err.c_str()); - return NULL; + return nullptr; } ++a->completed; } - return NULL; + return nullptr; } // TEST 1: many bthreads, each looping ~50x over a mix of the reused work @@ -640,11 +640,11 @@ TEST_F(MysqlPoolConcurrencyTest, ManyWorkersMixedScenarios) { std::vector threads(kWorkers); for (int w = 0; w < kWorkers; ++w) { - ASSERT_EQ(0, bthread_start_background(&threads[w], NULL, MixWorker, + ASSERT_EQ(0, bthread_start_background(&threads[w], nullptr, MixWorker, &args[w])); } for (int w = 0; w < kWorkers; ++w) { - bthread_join(threads[w], NULL); + bthread_join(threads[w], nullptr); } for (int w = 0; w < kWorkers; ++w) { @@ -683,22 +683,22 @@ void* AffinityWorker(void* p) { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(*a->channel, brpc::MysqlTransactionOptions()); - if (tx == NULL) { a->error = "NewMysqlTransaction NULL"; return NULL; } + if (tx == nullptr) { a->error = "NewMysqlTransaction NULL"; return nullptr; } a->socket_id = tx->GetSocketId(); brpc::MysqlResponse resp; if (!RunInTx(*a->channel, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d)", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (resp.reply(0).is_error()) { a->error = "INSERT err: " + resp.reply(0).error().msg().as_string(); - return NULL; + return nullptr; } // Read inside the txn: must see exactly our own row (per-worker table). if (!RunInTx(*a->channel, tx.get(), butil::string_printf("SELECT v FROM %s", a->table.c_str()), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; a->row_count = ResultRowCount(resp); if (a->row_count == 1) { long long v = 0; @@ -708,7 +708,7 @@ void* AffinityWorker(void* p) { } a->committed = tx->commit(); if (!a->committed) a->error = "commit failed"; - return NULL; + return nullptr; } // TEST 2 (focused check a): two transactions in parallel must hold DIFFERENT @@ -733,10 +733,10 @@ TEST_F(MysqlPoolConcurrencyTest, TwoTransactionsHoldDifferentPinnedSockets) { AffinityWorkerArgs a1{&_channel, t1, 30900 + iter, 0, -1, -1, false, ""}; bthread_t b0, b1; - ASSERT_EQ(0, bthread_start_background(&b0, NULL, AffinityWorker, &a0)); - ASSERT_EQ(0, bthread_start_background(&b1, NULL, AffinityWorker, &a1)); - bthread_join(b0, NULL); - bthread_join(b1, NULL); + ASSERT_EQ(0, bthread_start_background(&b0, nullptr, AffinityWorker, &a0)); + ASSERT_EQ(0, bthread_start_background(&b1, nullptr, AffinityWorker, &a1)); + bthread_join(b0, nullptr); + bthread_join(b1, nullptr); ASSERT_TRUE(a0.error.empty()) << "iter " << iter << " txn0: " << a0.error; ASSERT_TRUE(a1.error.empty()) << "iter " << iter << " txn1: " << a1.error; @@ -781,10 +781,10 @@ void* PreparedWorker(void* p) { if (!WU_PreparedArithmetic(*a->channel, a->base, k, &err)) { a->ok = false; a->error = err; - return NULL; + return nullptr; } } - return NULL; + return nullptr; } // TEST 3 (focused check b): one transaction + one prepared statement in @@ -805,10 +805,10 @@ TEST_F(MysqlPoolConcurrencyTest, TransactionPlusPreparedInParallel) { PreparedWorkerArgs pa{&_channel, 200 + iter, true, ""}; bthread_t bt, bp; - ASSERT_EQ(0, bthread_start_background(&bt, NULL, AffinityWorker, &ta)); - ASSERT_EQ(0, bthread_start_background(&bp, NULL, PreparedWorker, &pa)); - bthread_join(bt, NULL); - bthread_join(bp, NULL); + ASSERT_EQ(0, bthread_start_background(&bt, nullptr, AffinityWorker, &ta)); + ASSERT_EQ(0, bthread_start_background(&bp, nullptr, PreparedWorker, &pa)); + bthread_join(bt, nullptr); + bthread_join(bp, nullptr); ASSERT_TRUE(ta.error.empty()) << "iter " << iter << " txn: " << ta.error; ASSERT_TRUE(pa.ok) << "iter " << iter << " prepared: " << pa.error; @@ -862,7 +862,7 @@ void* PinnedTxnWorker(void* p) { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(*a->channel, brpc::MysqlTransactionOptions()); - if (tx == NULL) { a->error = "NewMysqlTransaction NULL"; return NULL; } + if (tx == nullptr) { a->error = "NewMysqlTransaction NULL"; return nullptr; } brpc::MysqlResponse resp; @@ -871,10 +871,10 @@ void* PinnedTxnWorker(void* p) { if (!RunInTx(*a->channel, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d, 'nova')", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (resp.reply(0).is_error()) { a->error = "INSERT err: " + resp.reply(0).error().msg().as_string(); - return NULL; + return nullptr; } // Statement 2: SELECT our own (uncommitted) row back. @@ -882,11 +882,11 @@ void* PinnedTxnWorker(void* p) { if (!RunInTx(*a->channel, tx.get(), butil::string_printf("SELECT name FROM %s WHERE id=%d", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (ResultRowCount(resp) != 1 || resp.reply(0).next().field(0).string().as_string() != "nova") { a->error = "SELECT-own-row did not read back its own write"; - return NULL; + return nullptr; } // Statement 3: UPDATE our own row. @@ -894,10 +894,10 @@ void* PinnedTxnWorker(void* p) { if (!RunInTx(*a->channel, tx.get(), butil::string_printf("UPDATE %s SET name='zephyr' WHERE id=%d", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (resp.reply(0).is_error()) { a->error = "UPDATE err: " + resp.reply(0).error().msg().as_string(); - return NULL; + return nullptr; } // Statement 4: SELECT the updated value back. @@ -905,16 +905,16 @@ void* PinnedTxnWorker(void* p) { if (!RunInTx(*a->channel, tx.get(), butil::string_printf("SELECT name FROM %s WHERE id=%d", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (ResultRowCount(resp) != 1 || resp.reply(0).next().field(0).string().as_string() != "zephyr") { a->error = "SELECT after UPDATE saw wrong value"; - return NULL; + return nullptr; } // Discard so the per-worker table is empty for the next outer-loop pass. - if (!tx->rollback()) { a->error = "rollback failed"; return NULL; } - return NULL; + if (!tx->rollback()) { a->error = "rollback failed"; return nullptr; } + return nullptr; } // TEST A: ConcurrentTxnsStayPinned (the most important check) @@ -958,11 +958,11 @@ TEST_F(MysqlPoolConcurrencyTest, ConcurrentTxnsStayPinned) { std::vector threads(kTxns); for (int w = 0; w < kTxns; ++w) { - ASSERT_EQ(0, bthread_start_background(&threads[w], NULL, + ASSERT_EQ(0, bthread_start_background(&threads[w], nullptr, PinnedTxnWorker, &args[w])); } for (int w = 0; w < kTxns; ++w) { - bthread_join(threads[w], NULL); + bthread_join(threads[w], nullptr); } // No worker errored. @@ -1018,23 +1018,23 @@ void* AbortWorker(void* p) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction( *a->channel, brpc::MysqlTransactionOptions()); - if (tx == NULL) { a->error = "NewMysqlTransaction NULL"; return NULL; } + if (tx == nullptr) { a->error = "NewMysqlTransaction NULL"; return nullptr; } brpc::MysqlResponse resp; if (!RunInTx(*a->channel, tx.get(), butil::string_printf("INSERT INTO %s VALUES (%d, 'quill')", a->table.c_str(), a->id), - &resp, &a->error)) return NULL; + &resp, &a->error)) return nullptr; if (resp.reply(0).is_error()) { a->error = "INSERT err: " + resp.reply(0).error().msg().as_string(); - return NULL; + return nullptr; } if (a->mode == 0) { - if (!tx->rollback()) { a->error = "explicit rollback failed"; return NULL; } + if (!tx->rollback()) { a->error = "explicit rollback failed"; return nullptr; } } // mode 1: fall off the end of this scope -> tx dtor auto-rollbacks. } - return NULL; + return nullptr; } // TEST B: ConcurrentTxnAbortAndAutoRollback @@ -1071,11 +1071,11 @@ TEST_F(MysqlPoolConcurrencyTest, ConcurrentTxnAbortAndAutoRollback) { std::vector threads(kWorkersB); for (int w = 0; w < kWorkersB; ++w) { - ASSERT_EQ(0, bthread_start_background(&threads[w], NULL, + ASSERT_EQ(0, bthread_start_background(&threads[w], nullptr, AbortWorker, &args[w])); } for (int w = 0; w < kWorkersB; ++w) { - bthread_join(threads[w], NULL); + bthread_join(threads[w], nullptr); } for (int w = 0; w < kWorkersB; ++w) { @@ -1122,12 +1122,12 @@ void* ReserveWorker(void* p) { for (int k = 0; k < 8; ++k) { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction( *a->channel, brpc::MysqlTransactionOptions()); - if (tx == NULL) { a->error = "reserve: NewMysqlTransaction NULL"; return NULL; } + if (tx == nullptr) { a->error = "reserve: NewMysqlTransaction NULL"; return nullptr; } brpc::MysqlResponse resp; - if (!RunInTx(*a->channel, tx.get(), "SELECT 1", &resp, &a->error)) return NULL; - if (!tx->rollback()) { a->error = "reserve: rollback failed"; return NULL; } + if (!RunInTx(*a->channel, tx.get(), "SELECT 1", &resp, &a->error)) return nullptr; + if (!tx->rollback()) { a->error = "reserve: rollback failed"; return nullptr; } } - return NULL; + return nullptr; } // Execute a shared prepared statement S with a fresh INT param and verify the @@ -1146,23 +1146,23 @@ void* StmtExecWorker(void* p) { for (int k = 0; k < 12; ++k) { const int32_t v = a->base + k; brpc::MysqlRequest req(a->stmt); - if (!req.AddParam(v)) { a->error = "AddParam failed"; return NULL; } + if (!req.AddParam(v)) { a->error = "AddParam failed"; return nullptr; } brpc::MysqlResponse resp; brpc::Controller cntl; - a->channel->CallMethod(NULL, &cntl, &req, &resp, NULL); - if (cntl.Failed()) { a->error = "rpc: " + cntl.ErrorText(); return NULL; } + a->channel->CallMethod(nullptr, &cntl, &req, &resp, nullptr); + if (cntl.Failed()) { a->error = "rpc: " + cntl.ErrorText(); return nullptr; } if (resp.reply_size() < 1 || !resp.reply(0).is_resultset() || resp.reply(0).row_count() != 1u) { - a->error = "bad resultset for S"; return NULL; + a->error = "bad resultset for S"; return nullptr; } long long got = 0; if (!FieldToLongLong(resp.reply(0).next().field(0), &got) || got != v) { a->error = butil::string_printf( "S returned wrong value (got %lld want %d)", got, v); - return NULL; + return nullptr; } } - return NULL; + return nullptr; } // TEST C: PreparedRePreparesWhenConnectionStolen @@ -1192,7 +1192,7 @@ TEST_F(MysqlPoolConcurrencyTest, PreparedRePreparesWhenConnectionStolen) { brpc::MysqlStatementUniquePtr S = brpc::NewMysqlStatement(_channel, "SELECT CAST(? AS SIGNED) AS v"); - ASSERT_TRUE(S != NULL); + ASSERT_TRUE(S != nullptr); ASSERT_EQ(1u, S->param_count()); // Execute S once to cache its stmt_id on whatever connection it lands on. @@ -1200,7 +1200,7 @@ TEST_F(MysqlPoolConcurrencyTest, PreparedRePreparesWhenConnectionStolen) { brpc::MysqlRequest req(S.get()); ASSERT_TRUE(req.AddParam((int32_t)140000)); brpc::Controller cntl; - _channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + _channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(resp.reply_size() >= 1 && resp.reply(0).is_resultset()); long long got = 0; @@ -1218,7 +1218,7 @@ TEST_F(MysqlPoolConcurrencyTest, PreparedRePreparesWhenConnectionStolen) { for (int w = 0; w < kReservers; ++w) { res_args[w].channel = &_channel; - ASSERT_EQ(0, bthread_start_background(&res_threads[w], NULL, + ASSERT_EQ(0, bthread_start_background(&res_threads[w], nullptr, ReserveWorker, &res_args[w])); } for (int w = 0; w < kExecutors; ++w) { @@ -1226,14 +1226,14 @@ TEST_F(MysqlPoolConcurrencyTest, PreparedRePreparesWhenConnectionStolen) { exec_args[w].stmt = S.get(); // Unique param ranges per worker+loop so a wrong value is unambiguous. exec_args[w].base = 141000 + loop * 1000 + w * 100; - ASSERT_EQ(0, bthread_start_background(&exec_threads[w], NULL, + ASSERT_EQ(0, bthread_start_background(&exec_threads[w], nullptr, StmtExecWorker, &exec_args[w])); } for (int w = 0; w < kReservers; ++w) { - bthread_join(res_threads[w], NULL); + bthread_join(res_threads[w], nullptr); } for (int w = 0; w < kExecutors; ++w) { - bthread_join(exec_threads[w], NULL); + bthread_join(exec_threads[w], nullptr); } for (int w = 0; w < kReservers; ++w) { diff --git a/test/brpc_mysql_prepared_integration_unittest.cpp b/test/brpc_mysql_prepared_integration_unittest.cpp index e14aea0026..a6f153aa45 100644 --- a/test/brpc_mysql_prepared_integration_unittest.cpp +++ b/test/brpc_mysql_prepared_integration_unittest.cpp @@ -23,7 +23,7 @@ // raw socket; here we drive the actual client stack a user would use. // // Each fat test chains several prepared-statement behaviors (param counting, -// binding, typed fetch, re-execution, NULL handling, error paths) so the +// binding, typed fetch, re-execution, nullptr handling, error paths) so the // test boundaries reflect our own grouping of the client surface. // // HARNESS: Reuses the self-spawned / already-running mysqld pattern @@ -104,7 +104,7 @@ static bool g_schema_ready = false; static std::string TestDataDir() { char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { + if (getcwd(cwd, sizeof(cwd)) == nullptr) { return std::string("/tmp/mysql_ps_data_for_test"); } return std::string(cwd) + "/mysql_ps_data_for_test"; @@ -212,7 +212,7 @@ static void StartServerOnce() { (char*)logerr_arg.c_str(), (char*)"--mysqlx=OFF", (char*)"--bind-address=127.0.0.1", - NULL}; + nullptr}; if (execvp(MYSQLD_BIN, argv) < 0) { puts("Fail to run " MYSQLD_BIN); exit(1); @@ -265,7 +265,7 @@ static bool RunPlainQuery(brpc::Channel* channel, const std::string& sql) { } brpc::MysqlResponse response; brpc::Controller cntl; - channel->CallMethod(NULL, &cntl, &request, &response, NULL); + channel->CallMethod(nullptr, &cntl, &request, &response, nullptr); if (cntl.Failed()) { return false; } @@ -361,7 +361,7 @@ TEST_F(MysqlPreparedTest, ParamCountsAndNoParamSelect) { brpc::MysqlRequest request(s.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -384,7 +384,7 @@ TEST_F(MysqlPreparedTest, BindAndExecuteIntStringAndArithmetic) { ASSERT_TRUE(request.AddParam((int32_t)417)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -403,7 +403,7 @@ TEST_F(MysqlPreparedTest, BindAndExecuteIntStringAndArithmetic) { ASSERT_TRUE(request.AddParam(butil::StringPiece("cobalt"))); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -429,7 +429,7 @@ TEST_F(MysqlPreparedTest, BindAndExecuteIntStringAndArithmetic) { ASSERT_TRUE(request.AddParam((int32_t)28)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -465,7 +465,7 @@ TEST_F(MysqlPreparedTest, ReExecuteAndTypedColumnFetch) { ASSERT_TRUE(request.AddParam(c.id)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -484,7 +484,7 @@ TEST_F(MysqlPreparedTest, ReExecuteAndTypedColumnFetch) { ASSERT_TRUE(request.AddParam((int32_t)528)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -529,7 +529,7 @@ TEST_F(MysqlPreparedTest, NullColumnAndLiteralNullAreNil) { ASSERT_TRUE(request.AddParam((int32_t)639)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -538,14 +538,14 @@ TEST_F(MysqlPreparedTest, NullColumnAndLiteralNullAreNil) { EXPECT_TRUE(r.next().field(0).is_nil()); } - // A literal NULL in the SELECT list also comes back nil. + // A literal nullptr in the SELECT list also comes back nil. { PREPARE_OR_FAIL(s, "SELECT NULL"); EXPECT_EQ(0u, s->param_count()); brpc::MysqlRequest request(s.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -573,7 +573,7 @@ TEST_F(MysqlPreparedTest, MalformedAndParamMismatchSurfaceErrors) { brpc::MysqlRequest request(s.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); if (cntl.Failed()) { SUCCEED() << "execute of malformed statement failed as expected: " << cntl.ErrorText(); @@ -592,7 +592,7 @@ TEST_F(MysqlPreparedTest, MalformedAndParamMismatchSurfaceErrors) { brpc::MysqlRequest request(s.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); if (cntl.Failed()) { SUCCEED() << "mismatched param count failed the RPC as expected: " << cntl.ErrorText(); @@ -618,7 +618,7 @@ TEST_F(MysqlPreparedTest, StatementReuseAndIndependentStatement) { brpc::MysqlRequest request(s1.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); @@ -644,7 +644,7 @@ TEST_F(MysqlPreparedTest, StatementReuseAndIndependentStatement) { ASSERT_TRUE(request.AddParam((int32_t)417)); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); ASSERT_TRUE(response.reply(0).is_resultset()); @@ -704,7 +704,7 @@ TEST_F(MysqlPreparedTest, BinaryTimeAndDateTimeParsing) { // DATE column: only the date part on the wire (len==4) -> "YYYY-MM-DD". {"SELECT CAST('2021-03-04' AS DATE)", "2021-03-04"}, // TIME zero value: encoded with len==0 (no field bytes on the wire). - // This must surface as the zero string "00:00:00", NOT as NULL. + // This must surface as the zero string "00:00:00", NOT as nullptr. {"SELECT CAST('00:00:00' AS TIME)", "00:00:00"}, }; @@ -715,7 +715,7 @@ TEST_F(MysqlPreparedTest, BinaryTimeAndDateTimeParsing) { brpc::MysqlRequest request(s.get()); brpc::MysqlResponse response; brpc::Controller cntl; - channel_.CallMethod(NULL, &cntl, &request, &response, NULL); + channel_.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_GE(response.reply_size(), 1u); const brpc::MysqlReply& r = response.reply(0); diff --git a/test/brpc_mysql_txn_integration_unittest.cpp b/test/brpc_mysql_txn_integration_unittest.cpp index 3d2325ae53..5d55429907 100644 --- a/test/brpc_mysql_txn_integration_unittest.cpp +++ b/test/brpc_mysql_txn_integration_unittest.cpp @@ -95,7 +95,7 @@ static std::string s_password; static std::string TestDataDir() { char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { + if (getcwd(cwd, sizeof(cwd)) == nullptr) { return std::string("/tmp/mysql_txn_data_for_test"); } return std::string(cwd) + "/mysql_txn_data_for_test"; @@ -199,7 +199,7 @@ static void RunMysqlServer() { (char*)logerr_arg.c_str(), (char*)"--mysqlx=OFF", (char*)"--bind-address=127.0.0.1", - NULL}; + nullptr}; if (execvp(MYSQLD_BIN, argv) < 0) { puts("Fail to run " MYSQLD_BIN); exit(1); @@ -232,7 +232,7 @@ static bool RunPlain(brpc::Channel& channel, const std::string& sql, return false; } brpc::Controller cntl; - channel.CallMethod(NULL, &cntl, &req, resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, resp, nullptr); return !cntl.Failed(); } @@ -245,7 +245,7 @@ static bool RunInTx(brpc::Channel& channel, const brpc::MysqlTransaction* tx, return false; } brpc::Controller cntl; - channel.CallMethod(NULL, &cntl, &req, resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, resp, nullptr); return !cntl.Failed(); } @@ -353,7 +353,7 @@ TEST_F(MysqlTxnIntegrationTest, CommitPublishesRollbackRestores) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL) << "failed to start transaction"; + ASSERT_TRUE(tx != nullptr) << "failed to start transaction"; ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (3107, 'quill')", &resp)); @@ -377,7 +377,7 @@ TEST_F(MysqlTxnIntegrationTest, CommitPublishesRollbackRestores) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (5288, 'brindle')", &resp)); @@ -391,7 +391,7 @@ TEST_F(MysqlTxnIntegrationTest, CommitPublishesRollbackRestores) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); ASSERT_TRUE(RunInTx(_channel, tx.get(), "DELETE FROM " + Table() + " WHERE id = 3107", &resp)); EXPECT_TRUE(ExpectOk(resp)); @@ -414,7 +414,7 @@ TEST_F(MysqlTxnIntegrationTest, CommitPublishesRollbackRestores) { TEST_F(MysqlTxnIntegrationTest, OwnWriteVisibleOthersIsolated) { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); brpc::MysqlResponse resp; ASSERT_TRUE(RunInTx(_channel, tx.get(), @@ -465,7 +465,7 @@ TEST_F(MysqlTxnIntegrationTest, AutocommitOnDurableOffRollbackable) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); ASSERT_TRUE(RunInTx(_channel, tx.get(), "SET autocommit = 0", &resp)); EXPECT_TRUE(ExpectOk(resp)); ASSERT_TRUE(RunInTx(_channel, tx.get(), @@ -491,7 +491,7 @@ TEST_F(MysqlTxnIntegrationTest, GroupedInsertsThenSavepointPartialUndo) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (211, 'one')", &resp)); @@ -518,7 +518,7 @@ TEST_F(MysqlTxnIntegrationTest, GroupedInsertsThenSavepointPartialUndo) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (901, 'kept')", &resp)); @@ -565,7 +565,7 @@ TEST_F(MysqlTxnIntegrationTest, DuplicateKeyAndReadOnlyWriteReportErr) { { brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, brpc::MysqlTransactionOptions()); - ASSERT_TRUE(tx != NULL); + ASSERT_TRUE(tx != nullptr); // Duplicate-key insert -> ERR packet (errno 1062, ER_DUP_ENTRY). ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (1505, 'clash')", @@ -585,7 +585,7 @@ TEST_F(MysqlTxnIntegrationTest, DuplicateKeyAndReadOnlyWriteReportErr) { opts.readonly = true; brpc::MysqlTransactionUniquePtr tx = brpc::NewMysqlTransaction(_channel, opts); - ASSERT_TRUE(tx != NULL) << "failed to start read-only transaction"; + ASSERT_TRUE(tx != nullptr) << "failed to start read-only transaction"; ASSERT_TRUE(RunInTx(_channel, tx.get(), "INSERT INTO " + Table() + " VALUES (1777, 'nope')", &resp)); diff --git a/test/brpc_naming_service_filter_unittest.cpp b/test/brpc_naming_service_filter_unittest.cpp index 387aeb5355..e036384edf 100644 --- a/test/brpc_naming_service_filter_unittest.cpp +++ b/test/brpc_naming_service_filter_unittest.cpp @@ -66,7 +66,7 @@ TEST_F(NamingServiceFilterTest, sanity) { ASSERT_EQ(0, butil::hostname2endpoint("10.128.0.1:1234", &ep)); for (int i = 0; i < 10; ++i) { brpc::SocketUniquePtr tmp_sock; - brpc::LoadBalancer::SelectIn sel_in = { 0, false, false, 0, NULL }; + brpc::LoadBalancer::SelectIn sel_in = { 0, false, false, 0, nullptr }; brpc::LoadBalancer::SelectOut sel_out(&tmp_sock); ASSERT_EQ(0, channel._lb->SelectServer(sel_in, &sel_out)); ASSERT_EQ(ep, tmp_sock->remote_side()); diff --git a/test/brpc_naming_service_unittest.cpp b/test/brpc_naming_service_unittest.cpp index 0ba2be6692..30c41923d3 100644 --- a/test/brpc_naming_service_unittest.cpp +++ b/test/brpc_naming_service_unittest.cpp @@ -237,11 +237,11 @@ TEST(NamingServiceTest, remotefile) { brpc::Server server1; UserNamingServiceImpl svc1; ASSERT_EQ(0, server1.AddService(&svc1, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start("localhost:8635", NULL)); + ASSERT_EQ(0, server1.Start("localhost:8635", nullptr)); brpc::Server server2; UserNamingServiceImpl svc2; ASSERT_EQ(0, server2.AddService(&svc2, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server2.Start("localhost:8636", NULL)); + ASSERT_EQ(0, server2.Start("localhost:8636", nullptr)); butil::EndPoint n1; ASSERT_EQ(0, butil::str2endpoint("0.0.0.0:8635", &n1)); @@ -449,7 +449,7 @@ TEST(NamingServiceTest, consul_with_backup_file) { ASSERT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE, restful_map.c_str())); - ASSERT_EQ(0, server.Start("localhost:8500", NULL)); + ASSERT_EQ(0, server.Start("localhost:8500", nullptr)); bthread_usleep(5000000); @@ -664,7 +664,7 @@ TEST(NamingServiceTest, discovery_sanity) { "/discovery/cancel => Cancel"; ASSERT_EQ(0, server.AddService(&svc, brpc::SERVER_DOESNT_OWN_SERVICE, rest_mapping.c_str())); - ASSERT_EQ(0, server.Start("localhost:8635", NULL)); + ASSERT_EQ(0, server.Start("localhost:8635", nullptr)); brpc::policy::DiscoveryNamingService dcns; std::vector servers; diff --git a/test/brpc_nova_pbrpc_protocol_unittest.cpp b/test/brpc_nova_pbrpc_protocol_unittest.cpp index cfc41bd699..2d9da47a4b 100644 --- a/test/brpc_nova_pbrpc_protocol_unittest.cpp +++ b/test/brpc_nova_pbrpc_protocol_unittest.cpp @@ -104,7 +104,7 @@ class NovaTest : public ::testing::Test{ virtual void TearDown() {}; void VerifyMessage(brpc::InputMessageBase* msg) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -113,7 +113,7 @@ class NovaTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -222,13 +222,13 @@ TEST_F(NovaTest, complete_flow) { brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackNovaRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Verify and handle request brpc::ParseResult req_pr = - brpc::policy::ParseNsheadMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); VerifyMessage(req_msg); @@ -238,7 +238,7 @@ TEST_F(NovaTest, complete_flow) { butil::IOPortal response_buf; response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseNsheadMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); ProcessMessage(brpc::policy::ProcessNovaResponse, res_msg, false); @@ -261,13 +261,13 @@ TEST_F(NovaTest, close_in_callback) { brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackNovaRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Handle request brpc::ParseResult req_pr = - brpc::policy::ParseNsheadMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessNsheadRequest, req_msg, false); diff --git a/test/brpc_p2c_ewma_load_balancer_unittest.cpp b/test/brpc_p2c_ewma_load_balancer_unittest.cpp index 922bfc3997..43532cacdb 100644 --- a/test/brpc_p2c_ewma_load_balancer_unittest.cpp +++ b/test/brpc_p2c_ewma_load_balancer_unittest.cpp @@ -61,7 +61,7 @@ brpc::ServerId CreateServer(const char* addr, const char* tag = "") { // Report a call that took `latency_us' back to the load balancer. void FeedbackLatency(brpc::LoadBalancer* lb, brpc::SocketId server_id, int64_t latency_us, int error_code = 0, - const brpc::Controller* cntl = NULL) { + const brpc::Controller* cntl = nullptr) { brpc::LoadBalancer::CallInfo info; info.begin_time_us = butil::gettimeofday_us() - latency_us; info.server_id = server_id; @@ -79,13 +79,13 @@ class P2CEwmaLoadBalancerTest : public ::testing::Test { _lb->Destroy(); } - int Select(brpc::SocketUniquePtr* ptr, bool* need_feedback = NULL, - const brpc::ExcludedServers* excluded = NULL) { + int Select(brpc::SocketUniquePtr* ptr, bool* need_feedback = nullptr, + const brpc::ExcludedServers* excluded = nullptr) { brpc::LoadBalancer::SelectIn in = { butil::gettimeofday_us(), true, false, 0u, excluded }; brpc::LoadBalancer::SelectOut out(ptr); const int rc = _lb->SelectServer(in, &out); - if (need_feedback != NULL) { + if (need_feedback != nullptr) { *need_feedback = out.need_feedback; } return rc; @@ -207,7 +207,7 @@ TEST_F(P2CEwmaLoadBalancerTest, weighted_split_by_inflight) { const brpc::ServerId w4 = CreateServer("127.0.0.1:7789", "4"); brpc::policy::P2CEwmaLoadBalancer* lb = _lb->New(butil::StringPiece("choices=3")); - ASSERT_TRUE(lb != NULL); + ASSERT_TRUE(lb != nullptr); ASSERT_TRUE(lb->AddServer(w1)); ASSERT_TRUE(lb->AddServer(w2)); ASSERT_TRUE(lb->AddServer(w4)); @@ -217,7 +217,7 @@ TEST_F(P2CEwmaLoadBalancerTest, weighted_split_by_inflight) { for (int i = 0; i < kRounds; ++i) { brpc::SocketUniquePtr ptr; brpc::LoadBalancer::SelectIn in = { - butil::gettimeofday_us(), true, false, 0u, NULL }; + butil::gettimeofday_us(), true, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); ASSERT_EQ(0, lb->SelectServer(in, &out)); ++counts[ptr->id()]; @@ -274,28 +274,28 @@ TEST_F(P2CEwmaLoadBalancerTest, excluded_servers) { excluded->Add(a.id); for (int i = 0; i < 20; ++i) { brpc::SocketUniquePtr ptr; - ASSERT_EQ(0, Select(&ptr, NULL, excluded)); + ASSERT_EQ(0, Select(&ptr, nullptr, excluded)); ASSERT_EQ(b.id, ptr->id()); FeedbackLatency(_lb, b.id, 1000); } // All servers excluded: still take the last chance instead of failing. excluded->Add(b.id); brpc::SocketUniquePtr ptr; - ASSERT_EQ(0, Select(&ptr, NULL, excluded)); + ASSERT_EQ(0, Select(&ptr, nullptr, excluded)); brpc::ExcludedServers::Destroy(excluded); } TEST_F(P2CEwmaLoadBalancerTest, invalid_parameters) { brpc::LoadBalancer* lb = _lb->New(butil::StringPiece("")); - ASSERT_TRUE(lb != NULL); + ASSERT_TRUE(lb != nullptr); lb->Destroy(); lb = _lb->New(butil::StringPiece("choices=4 tau_ms=5000")); - ASSERT_TRUE(lb != NULL); + ASSERT_TRUE(lb != nullptr); lb->Destroy(); - ASSERT_TRUE(_lb->New(butil::StringPiece("choices=1")) == NULL); - ASSERT_TRUE(_lb->New(butil::StringPiece("choices=abc")) == NULL); - ASSERT_TRUE(_lb->New(butil::StringPiece("tau_ms=0")) == NULL); - ASSERT_TRUE(_lb->New(butil::StringPiece("unknown=1")) == NULL); + ASSERT_TRUE(_lb->New(butil::StringPiece("choices=1")) == nullptr); + ASSERT_TRUE(_lb->New(butil::StringPiece("choices=abc")) == nullptr); + ASSERT_TRUE(_lb->New(butil::StringPiece("tau_ms=0")) == nullptr); + ASSERT_TRUE(_lb->New(butil::StringPiece("unknown=1")) == nullptr); } struct ChurnArg { @@ -309,7 +309,7 @@ void* SelectAndFeedback(void* void_arg) { while (!arg->stop.load(butil::memory_order_relaxed)) { brpc::SocketUniquePtr ptr; brpc::LoadBalancer::SelectIn in = { - butil::gettimeofday_us(), true, false, 0u, NULL }; + butil::gettimeofday_us(), true, false, 0u, nullptr }; brpc::LoadBalancer::SelectOut out(&ptr); if (arg->lb->SelectServer(in, &out) == 0) { arg->nselected.fetch_add(1, butil::memory_order_relaxed); @@ -318,7 +318,7 @@ void* SelectAndFeedback(void* void_arg) { } } } - return NULL; + return nullptr; } TEST_F(P2CEwmaLoadBalancerTest, concurrent_select_with_churn) { @@ -337,7 +337,7 @@ TEST_F(P2CEwmaLoadBalancerTest, concurrent_select_with_churn) { pthread_t threads[4]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { ASSERT_EQ(0, pthread_create( - &threads[i], NULL, SelectAndFeedback, &arg)); + &threads[i], nullptr, SelectAndFeedback, &arg)); } // Churn membership while selections are running. const int64_t stop_at_us = butil::gettimeofday_us() + 1000000L; @@ -347,7 +347,7 @@ TEST_F(P2CEwmaLoadBalancerTest, concurrent_select_with_churn) { } arg.stop.store(true); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_join(threads[i], NULL)); + ASSERT_EQ(0, pthread_join(threads[i], nullptr)); } LOG(INFO) << "selected " << arg.nselected.load() << " times"; ASSERT_GT(arg.nselected.load(), 0u); @@ -372,7 +372,7 @@ TEST_F(P2CEwmaLoadBalancerTest, error_punish_is_capped) { const std::string desc = os.str(); const size_t pos = desc.find("ewma_us="); ASSERT_NE(std::string::npos, pos) << desc; - const int64_t ewma_us = strtoll(desc.c_str() + pos + 8, NULL, 10); + const int64_t ewma_us = strtoll(desc.c_str() + pos + 8, nullptr, 10); ASSERT_LE(ewma_us, brpc::policy::FLAGS_p2c_max_punish_ms * 1000L) << desc; } @@ -391,7 +391,7 @@ void* FeedbackHammer(void* void_arg) { ++n; } arg->nfeedback.fetch_add(n, butil::memory_order_relaxed); - return NULL; + return nullptr; } TEST_F(P2CEwmaLoadBalancerTest, feedback_lock_overhead) { @@ -409,12 +409,12 @@ TEST_F(P2CEwmaLoadBalancerTest, feedback_lock_overhead) { const int64_t begin_us = butil::gettimeofday_us(); for (size_t i = 0; i < nthread; ++i) { ASSERT_EQ(0, pthread_create( - &threads[i], NULL, FeedbackHammer, &arg)); + &threads[i], nullptr, FeedbackHammer, &arg)); } usleep(500 * 1000); arg.stop.store(true); for (size_t i = 0; i < nthread; ++i) { - ASSERT_EQ(0, pthread_join(threads[i], NULL)); + ASSERT_EQ(0, pthread_join(threads[i], nullptr)); } const int64_t elapsed_us = butil::gettimeofday_us() - begin_us; const size_t n = arg.nfeedback.load(); diff --git a/test/brpc_prometheus_metrics_unittest.cpp b/test/brpc_prometheus_metrics_unittest.cpp index 471fd40a3c..166d6f80a6 100644 --- a/test/brpc_prometheus_metrics_unittest.cpp +++ b/test/brpc_prometheus_metrics_unittest.cpp @@ -59,7 +59,7 @@ TEST(PrometheusMetrics, sanity) { brpc::Server server; DummyEchoServiceImpl echo_svc; ASSERT_EQ(0, server.AddService(&echo_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start("127.0.0.1:8614", NULL)); + ASSERT_EQ(0, server.Start("127.0.0.1:8614", nullptr)); const std::list labels = {"label1", "label2"}; bvar::MultiDimension > my_madder("madder", labels); @@ -84,7 +84,7 @@ TEST(PrometheusMetrics, sanity) { ASSERT_EQ(0, channel.Init("127.0.0.1:8614", &channel_opts)); brpc::Controller cntl; cntl.http_request().uri() = "/brpc_metrics"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()); std::string res = cntl.response_attachment().to_string(); LOG(INFO) << "output:\n" << res; diff --git a/test/brpc_proto_unittest.cpp b/test/brpc_proto_unittest.cpp index 88ed40dac9..d4e6aa82eb 100644 --- a/test/brpc_proto_unittest.cpp +++ b/test/brpc_proto_unittest.cpp @@ -36,11 +36,11 @@ void BuildDependency(const FileDescriptor *file_desc, DescriptorPool *pool) { BuildDependency(fd, pool); FileDescriptorProto proto; fd->CopyTo(&proto); - ASSERT_TRUE(pool->BuildFile(proto) != NULL); + ASSERT_TRUE(pool->BuildFile(proto) != nullptr); } FileDescriptorProto proto; file_desc->CopyTo(&proto); - ASSERT_TRUE(pool->BuildFile(proto) != NULL); + ASSERT_TRUE(pool->BuildFile(proto) != nullptr); } TEST(ProtoTest, proto) { @@ -53,14 +53,14 @@ TEST(ProtoTest, proto) { FileDescriptorProto file_desc_proto; file_desc->CopyTo(&file_desc_proto); const FileDescriptor *new_file_desc = pool.BuildFile(file_desc_proto); - ASSERT_TRUE(new_file_desc != NULL); + ASSERT_TRUE(new_file_desc != nullptr); const Descriptor *new_desc = new_file_desc->FindMessageTypeByName(desc->name()); - ASSERT_TRUE(new_desc != NULL); + ASSERT_TRUE(new_desc != nullptr); meta.set_correlation_id(123); std::string data; ASSERT_TRUE(meta.SerializeToString(&data)); std::unique_ptr msg(factory.GetPrototype(new_desc)->New()); - ASSERT_TRUE(msg != NULL); + ASSERT_TRUE(msg != nullptr); ASSERT_TRUE(msg->ParseFromString(data)); ASSERT_TRUE(msg->SerializeToString(&data)); policy::RpcMeta new_meta; diff --git a/test/brpc_protobuf_json_unittest.cpp b/test/brpc_protobuf_json_unittest.cpp index b5ad0bb2dd..eeadc4f7d2 100644 --- a/test/brpc_protobuf_json_unittest.cpp +++ b/test/brpc_protobuf_json_unittest.cpp @@ -52,7 +52,7 @@ class ProtobufJsonTest : public testing::Test { inline int64_t gettimeofday_us() { timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); return now.tv_sec * 1000000L + now.tv_usec; } @@ -265,7 +265,7 @@ TEST_F(ProtobufJsonTest, json_to_pb_unicode_case) { ASSERT_TRUE(!info1.compare(info2)); butil::IOBuf buf; butil::IOBufAsZeroCopyOutputStream stream(&buf); - bool res = json2pb::ProtoMessageToJson(address_book, &stream, NULL); + bool res = json2pb::ProtoMessageToJson(address_book, &stream, nullptr); ASSERT_TRUE(res); butil::IOBufAsZeroCopyInputStream stream2(buf); AddressBook address_book_test3; @@ -830,7 +830,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_normal_case) { printf("----------test pb to json------------\n\n"); json2pb::Pb2JsonOptions option; option.bytes_to_base64 = true; - bool ret = json2pb::ProtoMessageToJson(address_book, &info1, option, NULL); + bool ret = json2pb::ProtoMessageToJson(address_book, &info1, option, nullptr); ASSERT_TRUE(ret); #ifndef RAPIDJSON_VERSION_0_1 @@ -856,7 +856,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_normal_case) { { json2pb::Pb2JsonOptions option; option.bytes_to_base64 = true; - ret = ProtoMessageToJson(address_book, &info1, option, NULL); + ret = ProtoMessageToJson(address_book, &info1, option, nullptr); } ASSERT_TRUE(ret); @@ -884,7 +884,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_normal_case) { json2pb::Pb2JsonOptions option; option.bytes_to_base64 = true; option.enum_option = json2pb::OUTPUT_ENUM_BY_NUMBER; - ret = ProtoMessageToJson(address_book, &info1, option, NULL); + ret = ProtoMessageToJson(address_book, &info1, option, nullptr); } ASSERT_TRUE(ret); @@ -1021,7 +1021,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { printf("----------test pb to json------------\n\n"); json2pb::Pb2JsonOptions option; option.bytes_to_base64 = true; - ASSERT_TRUE(ProtoMessageToJson(json_data, &info1, option, NULL)); + ASSERT_TRUE(ProtoMessageToJson(json_data, &info1, option, nullptr)); #ifndef RAPIDJSON_VERSION_0_1 ASSERT_STREQ("{\"info\":[\"this is json data's info\",\"this is a test\"],\"type\":80000," "\"data:array\":[200,300],\"judge\":true,\"spur\":3.45,\"@Content_Test%@\":" @@ -1041,8 +1041,8 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { std::string info3; JsonContextBodyEncDec data1; - json2pb::JsonToProtoMessage(info1, &data1, NULL); - json2pb::ProtoMessageToJson(data1, &info3, NULL); + json2pb::JsonToProtoMessage(info1, &data1, nullptr); + json2pb::ProtoMessageToJson(data1, &info3, nullptr); ASSERT_STREQ(info1.data(), info3.data()); printf("----------test single repeated pb to json array------------\n\n"); @@ -1062,7 +1062,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { std::string info4; option.single_repeated_to_array = false; - ASSERT_TRUE(ProtoMessageToJson(single_repeated_json_data, &info4, option, NULL)); + ASSERT_TRUE(ProtoMessageToJson(single_repeated_json_data, &info4, option, nullptr)); #ifndef RAPIDJSON_VERSION_0_1 ASSERT_STREQ("{\"person\":[" "{\"name\":\"foo\",\"id\":1,\"json_body\":" @@ -1085,7 +1085,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { std::string info5; option.single_repeated_to_array = true; - ASSERT_TRUE(ProtoMessageToJson(single_repeated_json_data, &info5, option, NULL)); + ASSERT_TRUE(ProtoMessageToJson(single_repeated_json_data, &info5, option, nullptr)); #ifndef RAPIDJSON_VERSION_0_1 ASSERT_STREQ("[{\"name\":\"foo\",\"id\":1,\"json_body\":" "{\"info\":[\"this is json data's info\",\"this is a test\"],\"type\":80000," @@ -1109,8 +1109,8 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { std::string info6; AddressBookEncDec data2; // object -> pb - json2pb::JsonToProtoMessage(info4, &data2, NULL); - json2pb::ProtoMessageToJson(data2, &info6, option, NULL); + json2pb::JsonToProtoMessage(info4, &data2, nullptr); + json2pb::ProtoMessageToJson(data2, &info6, option, nullptr); ASSERT_STREQ(info6.data(), info5.data()); @@ -1119,13 +1119,13 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode) { json2pb::Json2PbOptions option2; option2.array_to_single_repeated = true; // array -> pb - json2pb::JsonToProtoMessage(info5, &data3, option2, NULL); - json2pb::ProtoMessageToJson(data3, &info7, option, NULL); + json2pb::JsonToProtoMessage(info5, &data3, option2, nullptr); + json2pb::ProtoMessageToJson(data3, &info7, option, nullptr); ASSERT_STREQ(info7.data(), info5.data()); std::string info8; option.single_repeated_to_array = false; - json2pb::ProtoMessageToJson(data3, &info8, option, NULL); + json2pb::ProtoMessageToJson(data3, &info8, option, nullptr); ASSERT_STREQ(info8.data(), info4.data()); } @@ -1183,7 +1183,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_control_char_case) { { json2pb::Pb2JsonOptions option; option.bytes_to_base64 = false; - ret = ProtoMessageToJson(address_book, &info1, option, NULL); + ret = ProtoMessageToJson(address_book, &info1, option, nullptr); ASSERT_TRUE(ret); } @@ -1212,7 +1212,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_control_char_case) { { json2pb::Pb2JsonOptions option; option.bytes_to_base64 = true; - ret = ProtoMessageToJson(address_book, &info1, option, NULL); + ret = ProtoMessageToJson(address_book, &info1, option, nullptr); ASSERT_TRUE(ret); } @@ -1242,7 +1242,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_control_char_case) { json2pb::Pb2JsonOptions option; option.enum_option = json2pb::OUTPUT_ENUM_BY_NUMBER; option.bytes_to_base64 = false; - ret = ProtoMessageToJson(address_book, &info1, option, NULL); + ret = ProtoMessageToJson(address_book, &info1, option, nullptr); ASSERT_TRUE(ret); } @@ -1313,7 +1313,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_unicode_case) { ASSERT_TRUE(ret); butil::IOBuf buf; butil::IOBufAsZeroCopyOutputStream stream(&buf); - bool res = json2pb::ProtoMessageToJson(address_book, &stream, NULL); + bool res = json2pb::ProtoMessageToJson(address_book, &stream, nullptr); ASSERT_TRUE(res); ASSERT_TRUE(!info1.compare(buf.to_string())); } @@ -1451,18 +1451,18 @@ TEST_F(ProtobufJsonTest, pb_to_json_perf_case) { float avg_time1 = 0; float avg_time2 = 0; const int times = 100000; - ASSERT_TRUE(json2pb::ProtoMessageToJson(address_book, &info1, NULL)); + ASSERT_TRUE(json2pb::ProtoMessageToJson(address_book, &info1, nullptr)); for (int i = 0; i < times; i++) { std::string info3; AddressBook data1; timer.start(); - res = json2pb::JsonToProtoMessage(info1, &data1, NULL); + res = json2pb::JsonToProtoMessage(info1, &data1, nullptr); timer.stop(); avg_time1 += timer.u_elapsed(); ASSERT_TRUE(res); timer.start(); - res = json2pb::ProtoMessageToJson(data1, &info3, NULL); + res = json2pb::ProtoMessageToJson(data1, &info3, nullptr); timer.stop(); avg_time2 += timer.u_elapsed(); ASSERT_TRUE(res); @@ -1501,7 +1501,7 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode_perf_case) { printf("text:%s\n", text.data()); - ASSERT_TRUE(json2pb::ProtoMessageToJson(json_data, &info1, NULL)); + ASSERT_TRUE(json2pb::ProtoMessageToJson(json_data, &info1, nullptr)); printf("----------test pb to json encode decode performance------------\n\n"); ProfilerStart("pb_to_json_encode_decode_perf.prof"); @@ -1515,13 +1515,13 @@ TEST_F(ProtobufJsonTest, pb_to_json_encode_decode_perf_case) { std::string info3; JsonContextBody json_body; timer.start(); - res = json2pb::JsonToProtoMessage(info1, &json_body, NULL); + res = json2pb::JsonToProtoMessage(info1, &json_body, nullptr); timer.stop(); avg_time1 += timer.u_elapsed(); ASSERT_TRUE(res); timer.start(); - res = json2pb::ProtoMessageToJson(json_body, &info3, NULL); + res = json2pb::ProtoMessageToJson(json_body, &info3, nullptr); timer.stop(); avg_time2 += timer.u_elapsed(); ASSERT_TRUE(res); diff --git a/test/brpc_public_pbrpc_protocol_unittest.cpp b/test/brpc_public_pbrpc_protocol_unittest.cpp index e92f5ed917..f89ae4a6dd 100644 --- a/test/brpc_public_pbrpc_protocol_unittest.cpp +++ b/test/brpc_public_pbrpc_protocol_unittest.cpp @@ -111,7 +111,7 @@ class PublicPbrpcTest : public ::testing::Test{ virtual void TearDown() {}; void VerifyMessage(brpc::InputMessageBase* msg) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -120,7 +120,7 @@ class PublicPbrpcTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -179,7 +179,7 @@ class PublicPbrpcTest : public ::testing::Test{ butil::IOPortal buf; EXPECT_EQ((ssize_t)bytes_in_pipe, buf.append_from_file_descriptor(_pipe_fds[0], 1024)); - brpc::ParseResult pr = brpc::policy::ParseNsheadMessage(&buf, NULL, false, NULL); + brpc::ParseResult pr = brpc::policy::ParseNsheadMessage(&buf, nullptr, false, nullptr); EXPECT_EQ(brpc::PARSE_OK, pr.error()); brpc::policy::MostCommonMessage* msg = static_cast(pr.message()); @@ -276,13 +276,13 @@ TEST_F(PublicPbrpcTest, complete_flow) { brpc::policy::SerializePublicPbrpcRequest(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackPublicPbrpcRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Verify and handle request brpc::ParseResult req_pr = - brpc::policy::ParseNsheadMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); VerifyMessage(req_msg); @@ -292,7 +292,7 @@ TEST_F(PublicPbrpcTest, complete_flow) { butil::IOPortal response_buf; response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseNsheadMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); ProcessMessage(brpc::policy::ProcessPublicPbrpcResponse, res_msg, false); @@ -313,13 +313,13 @@ TEST_F(PublicPbrpcTest, close_in_callback) { brpc::policy::SerializePublicPbrpcRequest(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackPublicPbrpcRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Handle request brpc::ParseResult req_pr = - brpc::policy::ParseNsheadMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseNsheadMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessNsheadRequest, req_msg, false); diff --git a/test/brpc_rdma_unittest.cpp b/test/brpc_rdma_unittest.cpp index 2ecd1f3cac..9c52acb797 100644 --- a/test/brpc_rdma_unittest.cpp +++ b/test/brpc_rdma_unittest.cpp @@ -148,13 +148,13 @@ class RdmaTest : public ::testing::Test { std::vector sids; _server._am->ListConnections(&sids); if (index >= sids.size()) { - return NULL; + return nullptr; } SocketUniquePtr s; if (Socket::Address(sids[index], &s) == 0) { return s.get(); } - return NULL; + return nullptr; } butil::TempFile _server_list; @@ -203,7 +203,7 @@ TEST_F(RdmaTest, client_close_before_hello_send) { ASSERT_EQ(rdma::RdmaEndpoint::UNINIT, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -242,7 +242,7 @@ TEST_F(RdmaTest, client_close_during_hello_send) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; uint8_t data[8]; butil::fd_guard sockfd1(socket(AF_INET, SOCK_STREAM, 0)); @@ -260,7 +260,7 @@ TEST_F(RdmaTest, client_close_during_hello_send) { ASSERT_EQ(rdma::RdmaEndpoint::UNINIT, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd2(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd2 >= 0); @@ -274,7 +274,7 @@ TEST_F(RdmaTest, client_close_during_hello_send) { ASSERT_EQ(rdma::RdmaEndpoint::S_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd2); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd3(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd3 >= 0); @@ -293,7 +293,7 @@ TEST_F(RdmaTest, client_close_during_hello_send) { ASSERT_EQ(rdma::RdmaEndpoint::S_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd3); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -305,7 +305,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_len) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; butil::fd_guard sockfd1(socket(AF_INET, SOCK_STREAM, 0)); @@ -321,7 +321,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_len) { memset(data + 4, 0, 36); ASSERT_EQ(36, write(sockfd1, data + 4, 36)); // Write invalid length. usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd2(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd2 >= 0); @@ -338,7 +338,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_len) { memset(data + 6, 0, 34); ASSERT_EQ(36, write(sockfd2, data + 4, 36)); // write invalid length usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -350,7 +350,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_version) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; uint16_t len = butil::HostToNet16(rdma::HELLO_V2_MSG_LEN_MIN); uint16_t ver = butil::HostToNet16(1); @@ -385,7 +385,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_version) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); sockfd1.reset(-1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd2(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd2 >= 0); @@ -411,7 +411,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_version) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); sockfd2.reset(-1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -423,7 +423,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_sq_rq_block_size) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; uint32_t flags = butil::HostToNet32(0); rdma::v2_wire::HelloMessage msg{}; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; @@ -454,7 +454,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_sq_rq_block_size) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); sockfd1.reset(-1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); msg.sq_size = 16; msg.rq_size = 10; @@ -479,7 +479,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_sq_rq_block_size) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); sockfd2.reset(-1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); msg.sq_size = 16; msg.rq_size = 16; @@ -504,7 +504,7 @@ TEST_F(RdmaTest, client_hello_msg_invalid_sq_rq_block_size) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); sockfd3.reset(-1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -516,7 +516,7 @@ TEST_F(RdmaTest, client_close_after_qp_build) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; rdma::v2_wire::HelloMessage msg{}; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; msg.msg_len = rdma::HELLO_V2_MSG_LEN_MIN; @@ -541,7 +541,7 @@ TEST_F(RdmaTest, client_close_after_qp_build) { ASSERT_EQ(rdma::RdmaEndpoint::S_ACK_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -553,7 +553,7 @@ TEST_F(RdmaTest, client_close_during_ack_send) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; rdma::v2_wire::HelloMessage msg{}; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; msg.msg_len = rdma::HELLO_V2_MSG_LEN_MIN; @@ -585,7 +585,7 @@ TEST_F(RdmaTest, client_close_during_ack_send) { ASSERT_EQ(rdma::RdmaEndpoint::ESTABLISHED, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -597,7 +597,7 @@ TEST_F(RdmaTest, client_close_after_ack_send) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; rdma::v2_wire::HelloMessage msg{}; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; msg.msg_len = rdma::HELLO_V2_MSG_LEN_MIN; @@ -630,7 +630,7 @@ TEST_F(RdmaTest, client_close_after_ack_send) { ASSERT_EQ(RdmaTransport::RDMA_OFF, static_cast(s->_transport.get())->_rdma_state); close(sockfd1); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd2(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd2 >= 0); @@ -650,7 +650,7 @@ TEST_F(RdmaTest, client_close_after_ack_send) { ASSERT_EQ(rdma::RdmaEndpoint::ESTABLISHED, static_cast(s->_transport.get())->_rdma_ep->_state); close(sockfd2); usleep(100000); // wait for server to handle the msg - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -662,7 +662,7 @@ TEST_F(RdmaTest, client_send_data_on_tcp_after_ack_send) { bzero((char*)&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(PORT); - Socket* s = NULL; + Socket* s = nullptr; rdma::v2_wire::HelloMessage msg{}; uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; msg.msg_len = rdma::HELLO_V2_MSG_LEN_MIN; @@ -694,7 +694,7 @@ TEST_F(RdmaTest, client_send_data_on_tcp_after_ack_send) { ASSERT_EQ(rdma::RdmaEndpoint::FALLBACK_TCP, static_cast(s->_transport.get())->_rdma_ep->_state); ASSERT_EQ(sizeof(flags), write(sockfd1, &flags, sizeof(flags))); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); butil::fd_guard sockfd2(socket(AF_INET, SOCK_STREAM, 0)); ASSERT_TRUE(sockfd2 >= 0); @@ -714,7 +714,7 @@ TEST_F(RdmaTest, client_send_data_on_tcp_after_ack_send) { ASSERT_EQ(rdma::RdmaEndpoint::ESTABLISHED, static_cast(s->_transport.get())->_rdma_ep->_state); ASSERT_EQ(sizeof(flags), write(sockfd2, &flags, sizeof(flags))); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -743,7 +743,7 @@ TEST_F(RdmaTest, server_miss_before_hello_send) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); bthread_id_join(cntl.call_id()); @@ -774,7 +774,7 @@ TEST_F(RdmaTest, server_close_before_hello_send) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -810,7 +810,7 @@ TEST_F(RdmaTest, server_miss_during_magic_str) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -845,7 +845,7 @@ TEST_F(RdmaTest, server_close_during_magic_str) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -883,7 +883,7 @@ TEST_F(RdmaTest, server_hello_invalid_magic_str) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -919,7 +919,7 @@ TEST_F(RdmaTest, server_miss_during_hello_msg) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -954,7 +954,7 @@ TEST_F(RdmaTest, server_close_during_hello_msg) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -992,7 +992,7 @@ TEST_F(RdmaTest, server_hello_invalid_msg_len) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1032,7 +1032,7 @@ TEST_F(RdmaTest, server_hello_invalid_version) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1075,7 +1075,7 @@ TEST_F(RdmaTest, server_hello_invalid_sq_rq_size) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1127,7 +1127,7 @@ TEST_F(RdmaTest, server_miss_after_ack) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1179,7 +1179,7 @@ TEST_F(RdmaTest, server_close_after_ack) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1232,7 +1232,7 @@ TEST_F(RdmaTest, server_send_data_on_tcp_after_ack) { ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); ASSERT_EQ(rdma::RdmaEndpoint::C_HELLO_WAIT, static_cast(s->_transport.get())->_rdma_ep->_state); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; ASSERT_EQ(rdma::HELLO_V2_MSG_LEN_MIN, read(acc_fd, data, rdma::HELLO_V2_MSG_LEN_MIN)); @@ -1282,7 +1282,7 @@ TEST_F(RdmaTest, v2_client_hello_bytes_baseline) { SocketUniquePtr s; ASSERT_EQ(0, Socket::Address(cntl._single_server_id, &s)); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); uint8_t data[rdma::HELLO_V2_MSG_LEN_MIN]; @@ -1369,7 +1369,7 @@ TEST_F(RdmaTest, v2_server_hello_bytes_baseline) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -1386,7 +1386,7 @@ TEST_F(RdmaTest, v2_server_drains_tail_then_reads_ack) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); ASSERT_EQ(rdma::RdmaEndpoint::UNINIT, static_cast(s->_transport.get())->_rdma_ep->_state); // Build a v2 hello with msg_len = 48 (40 base + 8B zero tail). @@ -1416,7 +1416,7 @@ TEST_F(RdmaTest, v2_server_drains_tail_then_reads_ack) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -1433,7 +1433,7 @@ TEST_F(RdmaTest, v2_server_rejects_oversized_msg_len) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); ASSERT_EQ(rdma::RdmaEndpoint::UNINIT, static_cast(s->_transport.get())->_rdma_ep->_state); // Build a v2 hello with msg_len = 4097 (HELLO_V2_MSG_LEN_MAX + 1). @@ -1456,7 +1456,7 @@ TEST_F(RdmaTest, v2_server_rejects_oversized_msg_len) { usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); sockfd.reset(-1); usleep(100000); @@ -1535,7 +1535,7 @@ TEST_F(RdmaTest, v3_client_hello_bytes_baseline) { google::protobuf::Closure* done = DoNothing(); ::test::EchoService::Stub(&channel).Echo(&cntl, &req, &res, done); - butil::fd_guard acc_fd(accept(sockfd, NULL, NULL)); + butil::fd_guard acc_fd(accept(sockfd, nullptr, nullptr)); ASSERT_TRUE(acc_fd >= 0); // [0..4) magic "RDM3" @@ -1626,7 +1626,7 @@ TEST_F(RdmaTest, v3_server_hello_bytes_baseline) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -1643,14 +1643,14 @@ TEST_F(RdmaTest, v3_server_rejects_zero_pb_size) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); // "RDM3" + pb_size = 0 (4B big-endian zero). uint8_t buf[8] = {'R', 'D', 'M', '3', 0, 0, 0, 0}; ASSERT_EQ(8, write(sockfd, buf, 8)); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); sockfd.reset(-1); StopServer(); @@ -1668,7 +1668,7 @@ TEST_F(RdmaTest, v3_server_rejects_oversized_pb_size) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); uint8_t buf[8]; memcpy(buf, "RDM3", 4); @@ -1679,7 +1679,7 @@ TEST_F(RdmaTest, v3_server_rejects_oversized_pb_size) { ASSERT_EQ(8, write(sockfd, buf, 8)); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); sockfd.reset(-1); StopServer(); @@ -1697,7 +1697,7 @@ TEST_F(RdmaTest, v3_server_rejects_invalid_pb_bytes) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); // "RDM3" + pb_size = 8 + 8 bytes of 0xff (invalid protobuf body). uint8_t buf[16]; @@ -1708,7 +1708,7 @@ TEST_F(RdmaTest, v3_server_rejects_invalid_pb_bytes) { ASSERT_EQ(16, write(sockfd, buf, 16)); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); sockfd.reset(-1); StopServer(); @@ -1726,7 +1726,7 @@ TEST_F(RdmaTest, v3_server_invalid_sq_size_falls_back) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); rdma::RdmaHello msg = MakeValidV3Hello(); msg.set_sq_size(0); // invalid: < MIN_QP_SIZE (16) @@ -1760,7 +1760,7 @@ TEST_F(RdmaTest, v3_server_invalid_sq_size_falls_back) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -1820,7 +1820,7 @@ TEST_F(RdmaTest, v3_server_accepts_client_hello_with_ece) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); rdma::RdmaHello msg = MakeValidV3HelloWithEce(0x02c9, 0x1, 0x0); std::string packet = MakeV3Packet(msg); @@ -1843,7 +1843,7 @@ TEST_F(RdmaTest, v3_server_accepts_client_hello_with_ece) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -1862,7 +1862,7 @@ TEST_F(RdmaTest, v3_server_reply_has_no_ece_when_disabled) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); rdma::RdmaHello msg = MakeValidV3HelloWithEce(0x02c9, 0x1, 0x0); std::string packet = MakeV3Packet(msg); @@ -1899,7 +1899,7 @@ TEST_F(RdmaTest, v3_server_reply_has_no_ece_without_hw_negotiation) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); rdma::RdmaHello msg = MakeValidV3HelloWithEce(0x02c9, 0x1, 0x0); std::string packet = MakeV3Packet(msg); @@ -1983,7 +1983,7 @@ TEST_F(RdmaTest, server_alloc_resource_fail_fallback_tcp) { ASSERT_EQ(0, connect(sockfd, (sockaddr*)&addr, sizeof(sockaddr))); usleep(100000); // wait for server to handle the msg Socket* s = GetSocketFromServer(0); - ASSERT_TRUE(s != NULL); + ASSERT_TRUE(s != nullptr); ASSERT_EQ(rdma::RdmaEndpoint::UNINIT, static_cast(s->_transport.get())->_rdma_ep->_state); @@ -2021,7 +2021,7 @@ TEST_F(RdmaTest, server_alloc_resource_fail_fallback_tcp) { sockfd.reset(-1); usleep(100000); - ASSERT_EQ(NULL, GetSocketFromServer(0)); + ASSERT_EQ(nullptr, GetSocketFromServer(0)); StopServer(); } @@ -2066,17 +2066,17 @@ TEST_F(RdmaTest, server_option_invalid) { ASSERT_EQ(-1, server.Start(PORT, &options)); // nshead and rdma are incompatible - options.rtmp_service = NULL; + options.rtmp_service = nullptr; options.nshead_service = (NsheadService*)1; ASSERT_EQ(-1, server.Start(PORT, &options)); // mongo and rdma are incompatible - options.nshead_service = NULL; + options.nshead_service = nullptr; options.mongo_service_adaptor = (MongoServiceAdaptor*)1; ASSERT_EQ(-1, server.Start(PORT, &options)); // ssl and rdma are incompatible - options.mongo_service_adaptor = NULL; + options.mongo_service_adaptor = nullptr; options.mutable_ssl_options()->default_cert.certificate = "test"; ASSERT_EQ(-1, server.Start(PORT, &options)); } @@ -2638,7 +2638,7 @@ TEST_P(RdmaRpcTest, verbs_error_handling) { sge.lkey = 1; // incorrect lkey wr.sg_list = &sge; wr.num_sge = 1; - ibv_send_wr* bad = NULL; + ibv_send_wr* bad = nullptr; auto rdma_transport = static_cast(s->_transport.get()); ibv_post_send(rdma_transport->_rdma_ep->_resource->qp, &wr, &bad); bthread_id_join(cntl.call_id()); @@ -2664,15 +2664,15 @@ TEST_P(RdmaRpcTest, rdma_use_parallel_channel) { ASSERT_EQ(0, subchans[i].Init(_naming_url.c_str(), "rR", &opts)); ASSERT_EQ(0, channel.AddChannel( &subchans[i], DOESNT_OWN_CHANNEL, - NULL, NULL)); + nullptr, nullptr)); } - ASSERT_EQ(0, channel.Init(NULL)); + ASSERT_EQ(0, channel.Init(nullptr)); Controller cntl; test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - ::test::EchoService::Stub(&channel).Echo(&cntl, &req, &res, NULL); + ::test::EchoService::Stub(&channel).Echo(&cntl, &req, &res, nullptr); ASSERT_EQ(0, cntl.ErrorCode()); ASSERT_EQ(NCHANS, (size_t)cntl.sub_count()); @@ -2695,14 +2695,14 @@ TEST_P(RdmaRpcTest, rdma_use_selective_channel) { for (size_t i = 0; i < NCHANS; ++i) { Channel* subchan = new Channel; ASSERT_EQ(0, subchan->Init(_naming_url.c_str(), "rR", &opts)); - ASSERT_EQ(0, channel.AddChannel(subchan, NULL)); + ASSERT_EQ(0, channel.AddChannel(subchan, nullptr)); } Controller cntl; test::EchoRequest req; test::EchoResponse res; req.set_message(__FUNCTION__); - ::test::EchoService::Stub(&channel).Echo(&cntl, &req, &res, NULL); + ::test::EchoService::Stub(&channel).Echo(&cntl, &req, &res, nullptr); ASSERT_EQ(0, cntl.ErrorCode()) << cntl.ErrorText(); ASSERT_EQ(1, cntl.sub_count()); @@ -2732,7 +2732,7 @@ TEST_P(RdmaRpcTest, send_rpcs_with_user_defined_iobuf) { butil::IOBuf attach; void* data = malloc(4096);; - attach.append_user_data(data, 4096, NULL); + attach.append_user_data(data, 4096, nullptr); req[0].set_message(__FUNCTION__); cntl[0].request_attachment().append(attach); google::protobuf::Closure* done = DoNothing(); diff --git a/test/brpc_redis_cluster_unittest.cpp b/test/brpc_redis_cluster_unittest.cpp index 34a6d9ba6e..478bd92d0b 100644 --- a/test/brpc_redis_cluster_unittest.cpp +++ b/test/brpc_redis_cluster_unittest.cpp @@ -159,11 +159,11 @@ class Session : public brpc::Destroyable { }; static Session* GetOrCreateSession(brpc::RedisConnContext* ctx) { - if (ctx == NULL) { - return NULL; + if (ctx == nullptr) { + return nullptr; } Session* s = static_cast(ctx->get_session()); - if (s == NULL) { + if (s == nullptr) { s = new Session; ctx->reset_session(s); } @@ -187,7 +187,7 @@ class AskingHandler : public brpc::RedisCommandHandler { brpc::RedisReply* output, bool /*flush_batched*/) override { Session* s = GetOrCreateSession(ctx); - if (s != NULL) { + if (s != nullptr) { s->asking = true; } output->SetStatus("OK"); @@ -366,7 +366,7 @@ class KVCommandHandler : public brpc::RedisCommandHandler { } if (_data->node_id == _data->meta->ask_to) { Session* s = GetOrCreateSession(ctx); - if (s == NULL || !s->asking) { + if (s == nullptr || !s->asking) { output->SetError("ERR ASKING required"); return brpc::REDIS_CMD_HANDLED; } @@ -552,7 +552,7 @@ TEST_F(RedisClusterChannelTest, basic_routing_and_multi_key_commands) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("mset %s v0 %s v1", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -564,7 +564,7 @@ TEST_F(RedisClusterChannelTest, basic_routing_and_multi_key_commands) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("mget %s %s", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_array()); @@ -578,7 +578,7 @@ TEST_F(RedisClusterChannelTest, basic_routing_and_multi_key_commands) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("exists %s %s", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, resp.reply(0).integer()); } @@ -588,7 +588,7 @@ TEST_F(RedisClusterChannelTest, basic_routing_and_multi_key_commands) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("del %s %s", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, resp.reply(0).integer()); } @@ -609,7 +609,7 @@ TEST_F(RedisClusterChannelTest, moved_redirection) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", moved_key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -633,7 +633,7 @@ TEST_F(RedisClusterChannelTest, ask_redirection) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", _meta->ask_key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -658,7 +658,7 @@ TEST_F(RedisClusterChannelTest, ask_redirection_does_not_override_slot_cache) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", _meta->ask_key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -676,7 +676,7 @@ TEST_F(RedisClusterChannelTest, cluster_nodes_fallback) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("set %s vv", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(resp.reply(0).is_string()); ASSERT_EQ("OK", resp.reply(0).data()); @@ -697,7 +697,7 @@ TEST_F(RedisClusterChannelTest, eval_and_evalsha) { "eval", "return 1", "2", key0, key1 }; ASSERT_TRUE(req.AddCommandByComponents(parts, sizeof(parts) / sizeof(parts[0]))); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_error()); @@ -710,7 +710,7 @@ TEST_F(RedisClusterChannelTest, eval_and_evalsha) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("evalsha abcdef 1 %s arg1", key0.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -727,7 +727,7 @@ TEST_F(RedisClusterChannelTest, redirect_retry_limit) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", _meta->redirect_loop_key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_NE(std::string::npos, cntl.ErrorText().find("redirect")); } @@ -749,7 +749,7 @@ TEST_F(RedisClusterChannelTest, async_call) { bthread::CountdownEvent event(1); Done done(&event); - channel.CallMethod(NULL, &cntl, &req, &resp, &done); + channel.CallMethod(nullptr, &cntl, &req, &resp, &done); event.wait(); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); @@ -775,7 +775,7 @@ TEST_F(RedisClusterChannelTest, pipeline_order_with_mixed_commands) { ASSERT_TRUE(req.AddCommand("unlink %s %s", key0.c_str(), key1.c_str())); ASSERT_TRUE(req.AddCommand("mget %s %s", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(6, resp.reply_size()); ASSERT_EQ("OK", resp.reply(0).data()); @@ -806,7 +806,7 @@ TEST_F(RedisClusterChannelTest, transaction_commands_are_not_supported) { brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("multi")); ASSERT_TRUE(req.AddCommand("exec")); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_error()); @@ -827,7 +827,7 @@ TEST_F(RedisClusterChannelTest, eval_argument_validation) { "eval", "return 1", "abc", "k1" }; ASSERT_TRUE(req.AddCommandByComponents(parts, sizeof(parts) / sizeof(parts[0]))); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_error()); @@ -843,7 +843,7 @@ TEST_F(RedisClusterChannelTest, eval_argument_validation) { "eval", "return 1", "2", "k1" }; ASSERT_TRUE(req.AddCommandByComponents(parts, sizeof(parts) / sizeof(parts[0]))); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_error()); @@ -864,7 +864,7 @@ TEST_F(RedisClusterChannelTest, async_failure_propagation) { bthread::CountdownEvent event(1); Done done(&event); - channel.CallMethod(NULL, &cntl, &req, &resp, &done); + channel.CallMethod(nullptr, &cntl, &req, &resp, &done); event.wait(); ASSERT_TRUE(cntl.Failed()); @@ -886,7 +886,7 @@ TEST_F(RedisClusterChannelTest, max_redirect_zero_fails_on_single_redirect) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_NE(std::string::npos, cntl.ErrorText().find("redirect")); @@ -912,7 +912,7 @@ TEST_F(RedisClusterChannelTest, redirect_with_refresh_failure_still_returns_repl brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(resp.reply(0).is_string()); ASSERT_EQ("moved-value", resp.reply(0).data()); @@ -955,7 +955,7 @@ TEST_F(RedisClusterChannelTest, pipeline_with_ask_and_moved_keeps_order) { ASSERT_TRUE(req.AddCommand("get %s", moved_key.c_str())); ASSERT_TRUE(req.AddCommand("get %s", ask_key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(3, resp.reply_size()); ASSERT_EQ("ask-value", resp.reply(0).data()); @@ -984,7 +984,7 @@ TEST_F(RedisClusterChannelTest, fallback_to_nodes_then_recover_to_slots) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("recover-value", resp.reply(0).data()); ASSERT_GT(_meta->slots_calls.load(std::memory_order_relaxed), before_slots); @@ -1000,7 +1000,7 @@ TEST_F(RedisClusterChannelTest, cluster_slots_empty_host_uses_seed_host) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("set %s host-fallback-value", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("OK", resp.reply(0).data()); } @@ -1036,7 +1036,7 @@ TEST_F(RedisClusterChannelTest, ping_without_key_uses_any_endpoint) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("ping")); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -1053,7 +1053,7 @@ TEST_F(RedisClusterChannelTest, wrong_argument_count_commands_return_error_reply ASSERT_TRUE(req.AddCommand("mget")); ASSERT_TRUE(req.AddCommand("mset only_key")); ASSERT_TRUE(req.AddCommand("del")); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(3, resp.reply_size()); @@ -1073,7 +1073,7 @@ TEST_F(RedisClusterChannelTest, malformed_redirect_error_is_returned_directly) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); @@ -1101,7 +1101,7 @@ TEST_F(RedisClusterChannelTest, cluster_nodes_parser_ignores_migration_tokens) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("set %s from-nodes", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("OK", resp.reply(0).data()); } @@ -1117,7 +1117,7 @@ TEST_F(RedisClusterChannelTest, eval_numkeys_zero_routes_without_slot) { "eval", "return 'ok'", "0", "arg1" }; ASSERT_TRUE(req.AddCommandByComponents(parts, sizeof(parts) / sizeof(parts[0]))); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); @@ -1146,7 +1146,7 @@ TEST_F(RedisClusterChannelTest, mset_stops_after_subcommand_error) { key_ok.c_str(), key_err.c_str(), key_tail.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); @@ -1159,7 +1159,7 @@ TEST_F(RedisClusterChannelTest, mset_stops_after_subcommand_error) { brpc::RedisResponse get_resp; brpc::Controller get_cntl; ASSERT_TRUE(get_req.AddCommand("get %s", key_ok.c_str())); - channel.CallMethod(NULL, &get_cntl, &get_req, &get_resp, NULL); + channel.CallMethod(nullptr, &get_cntl, &get_req, &get_resp, nullptr); ASSERT_FALSE(get_cntl.Failed()) << get_cntl.ErrorText(); ASSERT_TRUE(get_resp.reply(0).is_string()); ASSERT_EQ("v0", get_resp.reply(0).data()); @@ -1169,7 +1169,7 @@ TEST_F(RedisClusterChannelTest, mset_stops_after_subcommand_error) { brpc::RedisResponse get_resp; brpc::Controller get_cntl; ASSERT_TRUE(get_req.AddCommand("get %s", key_tail.c_str())); - channel.CallMethod(NULL, &get_cntl, &get_req, &get_resp, NULL); + channel.CallMethod(nullptr, &get_cntl, &get_req, &get_resp, nullptr); ASSERT_FALSE(get_cntl.Failed()) << get_cntl.ErrorText(); ASSERT_TRUE(get_resp.reply(0).is_nil()); } @@ -1201,7 +1201,7 @@ TEST_F(RedisClusterChannelTest, integer_aggregate_stops_after_subcommand_error) brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("unlink %s %s %s", key0.c_str(), key_err.c_str(), key_tail.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); @@ -1213,7 +1213,7 @@ TEST_F(RedisClusterChannelTest, integer_aggregate_stops_after_subcommand_error) brpc::RedisResponse get_resp; brpc::Controller get_cntl; ASSERT_TRUE(get_req.AddCommand("get %s", key_tail.c_str())); - channel.CallMethod(NULL, &get_cntl, &get_req, &get_resp, NULL); + channel.CallMethod(nullptr, &get_cntl, &get_req, &get_resp, nullptr); ASSERT_FALSE(get_cntl.Failed()) << get_cntl.ErrorText(); ASSERT_TRUE(get_resp.reply(0).is_string()); ASSERT_EQ("vtail", get_resp.reply(0).data()); @@ -1267,7 +1267,7 @@ TEST_F(RedisClusterChannelTest, async_concurrent_calls_with_mixed_redirections) expected[i] = "normal-v"; } ASSERT_TRUE(requests[i]->AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, + channel.CallMethod(nullptr, controllers[i].get(), requests[i].get(), responses[i].get(), @@ -1299,7 +1299,7 @@ TEST_F(RedisClusterChannelTest, hashtag_keys_route_for_multi_key_commands) { brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("mset %s v0 %s v1", key0.c_str(), key1.c_str())); ASSERT_TRUE(req.AddCommand("mget %s %s", key0.c_str(), key1.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, resp.reply_size()); @@ -1321,7 +1321,7 @@ TEST_F(RedisClusterChannelTest, missing_key_get_returns_nil_reply) { brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); @@ -1358,7 +1358,7 @@ TEST_F(RedisClusterChannelTest, pipeline_with_string_nil_error_and_string) { ASSERT_TRUE(req.AddCommand("get %s", key_nil.c_str())); ASSERT_TRUE(req.AddCommand("get %s", key_err.c_str())); ASSERT_TRUE(req.AddCommand("get %s", key_ok.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, resp.reply_size()); @@ -1379,7 +1379,7 @@ TEST_F(RedisClusterChannelTest, empty_request_should_fail) { brpc::RedisRequest req; brpc::RedisResponse resp; brpc::Controller cntl; - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_NE(std::string::npos, cntl.ErrorText().find("no redis command")); } @@ -1401,7 +1401,7 @@ TEST_F(RedisClusterChannelTest, pipeline_continues_after_command_error_reply) { brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key_err.c_str())); ASSERT_TRUE(req.AddCommand("get %s", key_ok.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, resp.reply_size()); @@ -1429,7 +1429,7 @@ TEST_F(RedisClusterChannelTest, redirect_updates_slot_cache_even_when_refresh_fa brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("value-on-node1", resp.reply(0).data()); @@ -1437,7 +1437,7 @@ TEST_F(RedisClusterChannelTest, redirect_updates_slot_cache_even_when_refresh_fa brpc::RedisResponse resp2; brpc::Controller cntl2; ASSERT_TRUE(req2.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl2, &req2, &resp2, NULL); + channel.CallMethod(nullptr, &cntl2, &req2, &resp2, nullptr); ASSERT_FALSE(cntl2.Failed()) << cntl2.ErrorText(); ASSERT_EQ("value-on-node1", resp2.reply(0).data()); @@ -1491,7 +1491,7 @@ TEST_F(RedisClusterChannelTest, periodic_refresh_updates_slot_cache_on_topology_ brpc::RedisResponse resp; brpc::Controller cntl; ASSERT_TRUE(req.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl, &req, &resp, NULL); + channel.CallMethod(nullptr, &cntl, &req, &resp, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, resp.reply_size()); ASSERT_TRUE(resp.reply(0).is_string()); @@ -1508,7 +1508,7 @@ TEST_F(RedisClusterChannelTest, periodic_refresh_updates_slot_cache_on_topology_ brpc::RedisResponse resp2; brpc::Controller cntl2; ASSERT_TRUE(req2.AddCommand("get %s", key.c_str())); - channel.CallMethod(NULL, &cntl2, &req2, &resp2, NULL); + channel.CallMethod(nullptr, &cntl2, &req2, &resp2, nullptr); ASSERT_FALSE(cntl2.Failed()) << cntl2.ErrorText(); ASSERT_EQ(1, resp2.reply_size()); ASSERT_TRUE(resp2.reply(0).is_string()); @@ -1540,7 +1540,7 @@ TEST_F(RedisClusterChannelTest, async_pipeline_mixed_commands) { bthread::CountdownEvent event(1); Done done(&event); - channel.CallMethod(NULL, &cntl, &req, &resp, &done); + channel.CallMethod(nullptr, &cntl, &req, &resp, &done); event.wait(); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); diff --git a/test/brpc_redis_unittest.cpp b/test/brpc_redis_unittest.cpp index dc0f9d5595..f4830d045a 100644 --- a/test/brpc_redis_unittest.cpp +++ b/test/brpc_redis_unittest.cpp @@ -89,7 +89,7 @@ static void RunRedisServer() { puts("[Starting redis-server]"); char* const argv[] = { (char*)REDIS_SERVER_BIN, (char*)"--port", (char*)REDIS_SERVER_PORT, - NULL }; + nullptr }; unlink("dump.rdb"); if (execvp(REDIS_SERVER_BIN, argv) < 0) { puts("Fail to run " REDIS_SERVER_BIN); @@ -185,7 +185,7 @@ TEST_F(RedisTest, sanity) { brpc::Controller cntl; ASSERT_TRUE(request.AddCommand("get hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_NIL, response.reply(0).type()) @@ -195,7 +195,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); request.AddCommand("set hello world"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -205,7 +205,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); ASSERT_TRUE(request.AddCommand("get hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()); @@ -215,7 +215,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); request.AddCommand("set hello world2"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -225,7 +225,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); ASSERT_TRUE(request.AddCommand("get hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()); @@ -235,7 +235,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); ASSERT_TRUE(request.AddCommand("del hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(brpc::REDIS_REPLY_INTEGER, response.reply(0).type()); ASSERT_EQ(1, response.reply(0).integer()); @@ -244,7 +244,7 @@ TEST_F(RedisTest, sanity) { request.Clear(); response.Clear(); ASSERT_TRUE(request.AddCommand("get %s", "hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_NIL, response.reply(0).type()); @@ -274,7 +274,7 @@ TEST_F(RedisTest, keys_with_spaces) { ASSERT_TRUE(request.AddCommand("get 'hello2 world2'")); ASSERT_TRUE(request.AddCommand("get 'hello3 world3'")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(7, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -315,7 +315,7 @@ TEST_F(RedisTest, incr_and_decr) { request.AddCommand("decr counter1"); request.AddCommand("incrby counter1 %d", 10); request.AddCommand("decrby counter1 %d", 20); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_INTEGER, response.reply(0).type()); @@ -356,7 +356,7 @@ TEST_F(RedisTest, by_components) { request.AddCommandByComponents(comp3, arraysize(comp3)); request.AddCommandByComponents(comp4, arraysize(comp4)); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_INTEGER, response.reply(0).type()); @@ -408,7 +408,7 @@ TEST_F(RedisTest, auth) { request.AddCommand("auth %s", passwd1.c_str()); request.AddCommand("get mykey"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -432,7 +432,7 @@ TEST_F(RedisTest, auth) { brpc::Controller cntl; request.AddCommand("get mykey"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_ERROR, response.reply(0).type()); @@ -455,7 +455,7 @@ TEST_F(RedisTest, auth) { request.AddCommand("get mykey"); request.AddCommand("config set requirepass %s", passwd2.c_str()); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()); @@ -478,7 +478,7 @@ TEST_F(RedisTest, auth) { brpc::Controller cntl; request.AddCommand("get mykey"); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()) << response.reply(0); @@ -1178,7 +1178,7 @@ TEST_F(RedisTest, server_sanity) { ASSERT_TRUE(request.AddCommand("set key2 value2")); ASSERT_TRUE(request.AddCommand("get key2")); ASSERT_TRUE(request.AddCommand("xxxcommand key2")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(7, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_NIL, response.reply(0).type()); @@ -1208,7 +1208,7 @@ TEST_F(RedisTest, server_sanity) { ASSERT_TRUE(request.AddCommand("set key4 \"\"")); ASSERT_TRUE(request.AddCommand("get key3")); ASSERT_TRUE(request.AddCommand("get key4")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, response.reply_size()); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -1230,12 +1230,12 @@ void* incr_thread(void* arg) { brpc::RedisResponse response; brpc::Controller cntl; EXPECT_TRUE(request.AddCommand("incr count")); - c->CallMethod(NULL, &cntl, &request, &response, NULL); + c->CallMethod(nullptr, &cntl, &request, &response, nullptr); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ(1, response.reply_size()); EXPECT_TRUE(response.reply(0).is_integer()) << response.reply(0); } - return NULL; + return nullptr; } TEST_F(RedisTest, server_concurrency) { @@ -1264,12 +1264,12 @@ TEST_F(RedisTest, server_concurrency) { channels.push_back(new brpc::Channel); ASSERT_EQ(0, channels.back()->Init("127.0.0.1", server.listen_address().port, &options)); bthread_t bth; - ASSERT_EQ(bthread_start_background(&bth, NULL, incr_thread, channels.back()), 0); + ASSERT_EQ(bthread_start_background(&bth, nullptr, incr_thread, channels.back()), 0); bths.push_back(bth); } for (int i = 0; i < N; ++i) { - bthread_join(bths[i], NULL); + bthread_join(bths[i], nullptr); delete channels[i]; } ASSERT_EQ(int_map["count"], 10 * 5000LL); @@ -1359,7 +1359,7 @@ TEST_F(RedisTest, server_command_continue) { brpc::Controller cntl; ASSERT_TRUE(request.AddCommand("set hello world")); ASSERT_TRUE(request.AddCommand("get hello")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, response.reply_size()); ASSERT_STREQ("world", response.reply(1).c_str()); @@ -1375,7 +1375,7 @@ TEST_F(RedisTest, server_command_continue) { ASSERT_TRUE(request.AddCommand("incr hello 1")); } ASSERT_TRUE(request.AddCommand("exec")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_EQ(13, response.reply_size()); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); @@ -1400,7 +1400,7 @@ TEST_F(RedisTest, server_command_continue) { ASSERT_TRUE(request.AddCommand("get hello2")); ASSERT_TRUE(request.AddCommand("set key1 value1")); ASSERT_TRUE(request.AddCommand("get key1")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_STREQ("world", response.reply(0).c_str()); ASSERT_EQ(brpc::REDIS_REPLY_NIL, response.reply(1).type()); @@ -1447,7 +1447,7 @@ TEST_F(RedisTest, server_handle_pipeline) { ASSERT_TRUE(request.AddCommand("set key1 world")); ASSERT_TRUE(request.AddCommand("set key2 world")); ASSERT_TRUE(request.AddCommand("get key2")); - channel.CallMethod(NULL, &cntl, &request, &response, NULL); + channel.CallMethod(nullptr, &cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(8, response.reply_size()); ASSERT_EQ(1, rsimpl->_batch_count); diff --git a/test/brpc_rtmp_unittest.cpp b/test/brpc_rtmp_unittest.cpp index 286f8a87de..9fce391986 100644 --- a/test/brpc_rtmp_unittest.cpp +++ b/test/brpc_rtmp_unittest.cpp @@ -269,7 +269,7 @@ class PlayingDummyStream : public brpc::RtmpServerStream { << " ms before responding play request"; bthread_usleep(_sleep_ms * 1000L); } - int rc = bthread_start_background(&_play_thread, NULL, + int rc = bthread_start_background(&_play_thread, nullptr, RunSendData, this); if (rc) { status->set_error(rc, "Fail to create thread"); @@ -279,7 +279,7 @@ class PlayingDummyStream : public brpc::RtmpServerStream { if (!_state.compare_exchange_strong(expected, STATE_PLAYING)) { if (expected == STATE_STOPPED) { bthread_stop(_play_thread); - bthread_join(_play_thread, NULL); + bthread_join(_play_thread, nullptr); } else { CHECK(false) << "Impossible"; } @@ -290,7 +290,7 @@ class PlayingDummyStream : public brpc::RtmpServerStream { LOG(INFO) << "OnStop of PlayingDummyStream=" << this; if (_state.exchange(STATE_STOPPED) == STATE_PLAYING) { bthread_stop(_play_thread); - bthread_join(_play_thread, NULL); + bthread_join(_play_thread, nullptr); } } @@ -299,7 +299,7 @@ class PlayingDummyStream : public brpc::RtmpServerStream { private: static void* RunSendData(void* arg) { ((PlayingDummyStream*)arg)->SendData(); - return NULL; + return nullptr; } butil::atomic _state; @@ -421,7 +421,7 @@ class PublishStream : public brpc::RtmpServerStream { class PublishService : public brpc::RtmpService { public: PublishService(int64_t sleep_ms = 0) : _sleep_ms(sleep_ms) { - pthread_mutex_init(&_mutex, NULL); + pthread_mutex_init(&_mutex, nullptr); } ~PublishService() { pthread_mutex_destroy(&_mutex); @@ -824,7 +824,7 @@ TEST(RtmpTest, abort_message_naming_own_chunk_stream) { brpc::SocketUniquePtr sock; ASSERT_EQ(0, brpc::Socket::Address(id, &sock)); - brpc::policy::RtmpContext ctx(NULL, NULL); + brpc::policy::RtmpContext ctx(nullptr, nullptr); ctx.SetState(sock->remote_side(), brpc::policy::RtmpContext::STATE_RECEIVED_C2); diff --git a/test/brpc_server_unittest.cpp b/test/brpc_server_unittest.cpp index 1012ce25d7..ed0268e853 100644 --- a/test/brpc_server_unittest.cpp +++ b/test/brpc_server_unittest.cpp @@ -75,13 +75,13 @@ extern bool SerializeRpcMessage(const google::protobuf::Message& serializer, Controller& cntl, ContentType content_type, CompressType compress_type, ChecksumType checksum_type, butil::IOBuf* buf, - const butil::IOBuf* checksum_attachment = NULL); + const butil::IOBuf* checksum_attachment = nullptr); extern bool DeserializeRpcMessage(const butil::IOBuf& deserializer, Controller& cntl, ContentType content_type, CompressType compress_type, ChecksumType checksum_type, google::protobuf::Message* message, - const butil::IOBuf* checksum_attachment = NULL); + const butil::IOBuf* checksum_attachment = nullptr); } } @@ -90,7 +90,7 @@ namespace { void* RunClosure(void* arg) { google::protobuf::Closure* done = (google::protobuf::Closure*)arg; done->Run(); - return NULL; + return nullptr; } bool g_verify_success = true; @@ -145,7 +145,7 @@ class EchoServiceImpl : public test::EchoService { if (cntl->has_request_user_fields()) { ASSERT_TRUE(!cntl->request_user_fields()->empty()); std::string* val = cntl->request_user_fields()->seek(EXP_USER_FIELD_KEY); - ASSERT_TRUE(val != NULL); + ASSERT_TRUE(val != nullptr); ASSERT_EQ(*val, EXP_USER_FIELD_VALUE); cntl->response_user_fields()->insert(EXP_USER_FIELD_KEY, EXP_USER_FIELD_VALUE); } @@ -216,26 +216,26 @@ class ServerTest : public ::testing::Test{ TEST_F(ServerTest, sanity) { { brpc::Server server; - ASSERT_EQ(-1, server.Start("127.0.0.1:12345:asdf", NULL)); - ASSERT_EQ(-1, server.Start("127.0.0.1:99999", NULL)); - ASSERT_EQ(0, server.Start("127.0.0.1:8613", NULL)); + ASSERT_EQ(-1, server.Start("127.0.0.1:12345:asdf", nullptr)); + ASSERT_EQ(-1, server.Start("127.0.0.1:99999", nullptr)); + ASSERT_EQ(0, server.Start("127.0.0.1:8613", nullptr)); } { brpc::Server server; // accept hostname as well. - ASSERT_EQ(0, server.Start("localhost:8613", NULL)); + ASSERT_EQ(0, server.Start("localhost:8613", nullptr)); } { brpc::Server server; - ASSERT_EQ(0, server.Start("localhost:0", NULL)); + ASSERT_EQ(0, server.Start("localhost:0", nullptr)); // port should be replaced with the actually used one. ASSERT_NE(0, server.listen_address().port); } { brpc::Server server; - ASSERT_EQ(-1, server.Start(99999, NULL)); - ASSERT_EQ(0, server.Start(8613, NULL)); + ASSERT_EQ(-1, server.Start(99999, nullptr)); + ASSERT_EQ(0, server.Start(8613, nullptr)); } { brpc::Server server; @@ -244,7 +244,7 @@ TEST_F(ServerTest, sanity) { ASSERT_EQ(-1, server.Start("127.0.0.1:8613", &options)); ASSERT_FALSE(server.IsRunning()); // Revert server's status // And release the listen port - ASSERT_EQ(0, server.Start("127.0.0.1:8613", NULL)); + ASSERT_EQ(0, server.Start("127.0.0.1:8613", nullptr)); } { brpc::Server server; @@ -252,7 +252,7 @@ TEST_F(ServerTest, sanity) { ASSERT_EQ(0, server.Start(brpc::PortRange(8000, 9000), &options)); ASSERT_TRUE(server.IsRunning()); ASSERT_EQ(0ul, server.service_count()); - ASSERT_TRUE(NULL == server.first_service()); + ASSERT_TRUE(nullptr == server.first_service()); ASSERT_EQ(0, server.Stop(0)); ASSERT_EQ(0, server.Join()); } @@ -267,7 +267,7 @@ TEST_F(ServerTest, sanity) { ASSERT_TRUE(server.IsRunning()); ASSERT_EQ(&auth, server.options().auth); ASSERT_EQ(0ul, server.service_count()); - ASSERT_TRUE(NULL == server.first_service()); + ASSERT_TRUE(nullptr == server.first_service()); std::vector services; server.ListServices(&services); @@ -402,7 +402,7 @@ TEST_F(ServerTest, empty_enabled_protocols) { test::EchoResponse res; req.set_message(EXP_REQUEST); test::EchoService_Stub stub(&chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(0, server.Stop(0)); @@ -428,7 +428,7 @@ TEST_F(ServerTest, only_allow_protocols_in_enabled_protocols) { copt.protocol = "http"; ASSERT_EQ(0, http_channel.Init(ep, &copt)); cntl.Reset(); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); // Unmatched protocols are not allowed. @@ -440,7 +440,7 @@ TEST_F(ServerTest, only_allow_protocols_in_enabled_protocols) { cntl.Reset(); req.set_message(EXP_REQUEST); test::EchoService_Stub stub(&chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_TRUE(cntl.ErrorText().find("Got EOF of ") != std::string::npos); @@ -453,7 +453,7 @@ TEST_F(ServerTest, services_in_different_ns) { brpc::Server server1; EchoServiceV1 service_v1; ASSERT_EQ(0, server1.AddService(&service_v1, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; @@ -462,14 +462,14 @@ TEST_F(ServerTest, services_in_different_ns) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(1, service_v1.ncalled.load()); cntl.Reset(); cntl.http_request().uri() = "/v1.EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(2, service_v1.ncalled.load()); //Stop the server to add another service. @@ -483,20 +483,20 @@ TEST_F(ServerTest, services_in_different_ns) { ASSERT_EQ(-1, server1.AddService(&service_v2, brpc::SERVER_DOESNT_OWN_SERVICE)); #else ASSERT_EQ(0, server1.AddService(&service_v2, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); //sleep(3); // wait for HC cntl.Reset(); cntl.http_request().uri() = "/v2.EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"value\":33}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(1, service_v2.ncalled.load()); cntl.Reset(); cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"value\":33}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(2, service_v2.ncalled.load()); server1.Stop(0); @@ -509,7 +509,7 @@ TEST_F(ServerTest, various_forms_of_uri_paths) { brpc::Server server1; EchoServiceV1 service_v1; ASSERT_EQ(0, server1.AddService(&service_v1, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; @@ -518,7 +518,7 @@ TEST_F(ServerTest, various_forms_of_uri_paths) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(1, service_v1.ncalled.load()); @@ -526,7 +526,7 @@ TEST_F(ServerTest, various_forms_of_uri_paths) { cntl.http_request().uri() = "/EchoService///Echo//"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << cntl.response_attachment(); ASSERT_EQ(2, service_v1.ncalled.load()); @@ -534,7 +534,7 @@ TEST_F(ServerTest, various_forms_of_uri_paths) { cntl.http_request().uri() = "/EchoService /Echo/"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EREQUEST, cntl.ErrorCode()); LOG(INFO) << "Expected error: " << cntl.ErrorText(); @@ -545,7 +545,7 @@ TEST_F(ServerTest, various_forms_of_uri_paths) { cntl.http_request().uri() = "/EchoService/Echo/Foo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(3, service_v1.ncalled.load()); @@ -559,14 +559,14 @@ TEST_F(ServerTest, missing_required_fields) { brpc::Server server1; EchoServiceV1 service_v1; ASSERT_EQ(0, server1.AddService(&service_v1, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Controller cntl; cntl.http_request().uri() = "/EchoService/Echo"; - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()); LOG(INFO) << cntl.ErrorText(); @@ -576,7 +576,7 @@ TEST_F(ServerTest, missing_required_fields) { cntl.Reset(); cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_BAD_REQUEST, cntl.http_response().status_code()); @@ -586,7 +586,7 @@ TEST_F(ServerTest, missing_required_fields) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message2\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_BAD_REQUEST, cntl.http_response().status_code()); @@ -601,14 +601,14 @@ TEST_F(ServerTest, disallow_http_body_to_pb) { svc_opt.allow_http_body_to_pb = false; svc_opt.restful_mappings = "/access_echo1=>Echo"; ASSERT_EQ(0, server1.AddService(&service_v1, svc_opt)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Controller cntl; cntl.http_request().uri() = "/access_echo1"; - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_INTERNAL_SERVER_ERROR, @@ -619,7 +619,7 @@ TEST_F(ServerTest, disallow_http_body_to_pb) { cntl.http_request().uri() = "/access_echo1"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("heheda"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("heheda", cntl.response_attachment()); ASSERT_EQ(2, service_v1.ncalled.load()); @@ -748,7 +748,7 @@ TEST_F(ServerTest, restful_mapping) { ASSERT_FALSE(server10._global_restful_map); // Access services - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; @@ -759,7 +759,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(0, service_v1.ncalled.load()); @@ -768,7 +768,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v1/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment()); @@ -778,7 +778,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v3/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"bar\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"bar_v1\"}", cntl.response_attachment()); @@ -788,7 +788,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = " //v1///echo//// "; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"hello\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(3, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"hello_v1\"}", cntl.response_attachment()); @@ -798,7 +798,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v3/echo/anything"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EHTTP, cntl.ErrorCode()); LOG(INFO) << "Expected error: " << cntl.ErrorText(); @@ -809,7 +809,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v2/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"hehe\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(4, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"hehe_v1\"}", cntl.response_attachment()); @@ -819,7 +819,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v2/echo/anything"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"good\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(5, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"good_v1\"}", cntl.response_attachment()); @@ -828,7 +828,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v4_echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"hoho\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(6, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"hoho_v1\"}", cntl.response_attachment()); @@ -837,7 +837,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v5/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"xyz\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(7, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"xyz_v1\"}", cntl.response_attachment()); @@ -846,7 +846,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"xyz\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(8, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"xyz_v1\"}", cntl.response_attachment()); @@ -855,7 +855,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/echo/test"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"xyz\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, service_v1.ncalled_echo2.load()); ASSERT_EQ("{\"message\":\"xyz_v1_Echo2\"}", cntl.response_attachment()); @@ -864,7 +864,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/abc/heheda/def"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"abc_heheda\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, service_v1.ncalled_echo3.load()); ASSERT_EQ("{\"message\":\"abc_heheda_v1_Echo3\"}", cntl.response_attachment()); @@ -873,7 +873,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/abc/def"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"abc\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(2, service_v1.ncalled_echo3.load()); ASSERT_EQ("{\"message\":\"abc_v1_Echo3\"}", cntl.response_attachment()); @@ -883,7 +883,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/abc/heheda/def2"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"xyz\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(2, service_v1.ncalled_echo3.load()); @@ -891,7 +891,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/echo/1.flv"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"1.flv\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("{\"message\":\"1.flv_v1_Echo4\"}", cntl.response_attachment()); ASSERT_EQ(1, service_v1.ncalled_echo4.load()); @@ -900,7 +900,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "//v6//d.flv//"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"d.flv\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("{\"message\":\"d.flv_v1_Echo5\"}", cntl.response_attachment()); ASSERT_EQ(1, service_v1.ncalled_echo5.load()); @@ -910,7 +910,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "//d.flv//"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"d.flv\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("{\"message\":\"d.flv_v1\"}", cntl.response_attachment()); ASSERT_EQ(9, service_v1.ncalled.load()); @@ -919,7 +919,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v7/e.flv"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"e.flv\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("{\"message\":\"e.flv_v1\"}", cntl.response_attachment()); ASSERT_EQ(10, service_v1.ncalled.load()); @@ -928,7 +928,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v0/f.flv"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"f.flv\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ("{\"message\":\"f.flv_v1\"}", cntl.response_attachment()); ASSERT_EQ(11, service_v1.ncalled.load()); @@ -938,21 +938,21 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/v6/ech/1.ts"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"1.ts\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); //Stop the server. server1.Stop(0); server1.Join(); - ASSERT_EQ(0, server10.Start(port, NULL)); + ASSERT_EQ(0, server10.Start(port, nullptr)); // access v1.Echo via /v1/echo. cntl.Reset(); cntl.http_request().uri() = "/v1/echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(12, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment()); @@ -962,7 +962,7 @@ TEST_F(ServerTest, restful_mapping) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(13, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment()); @@ -986,7 +986,7 @@ TEST_F(ServerTest, http_error_code) { brpc::Server server1; EchoServiceV1 service_v1; ASSERT_EQ(0, server1.AddService(&service_v1, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; @@ -994,7 +994,7 @@ TEST_F(ServerTest, http_error_code) { ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Controller cntl; cntl.http_request().uri() = "/EchoService/Echo"; - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::EREQUEST, cntl.ErrorCode()); LOG(INFO) << cntl.ErrorText(); @@ -1010,14 +1010,14 @@ TEST_F(ServerTest, http_error_code) { svc_opt.allow_http_body_to_pb = false; svc_opt.restful_mappings = "/access_echo1=>Echo"; ASSERT_EQ(0, server1.AddService(&service_v1, svc_opt)); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Controller cntl; cntl.http_request().uri() = "/access_echo1"; - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::ERESPONSE, cntl.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_INTERNAL_SERVER_ERROR, @@ -1059,7 +1059,7 @@ TEST_F(ServerTest, http_error_code) { ASSERT_TRUE(server1._global_restful_map); ASSERT_EQ(1UL, server1._global_restful_map->size()); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; @@ -1068,7 +1068,7 @@ TEST_F(ServerTest, http_error_code) { cntl.http_request().uri() = "/v3/echo/anything"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(brpc::ENOMETHOD, cntl.ErrorCode()); LOG(INFO) << "Expected error: " << cntl.ErrorText(); @@ -1085,21 +1085,21 @@ TEST_F(ServerTest, http_error_code) { server1.MaxConcurrencyOf(&service1, "Echo") = 2; ASSERT_EQ(2, server1.MaxConcurrencyOf(&service1, "Echo")); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Channel normal_channel; - ASSERT_EQ(0, normal_channel.Init("0.0.0.0", port, NULL)); + ASSERT_EQ(0, normal_channel.Init("0.0.0.0", port, nullptr)); test::EchoService_Stub stub(&normal_channel); brpc::Controller cntl1; cntl1.http_request().uri() = "/EchoService/Echo"; cntl1.http_request().set_method(brpc::HTTP_METHOD_POST); cntl1.request_attachment().append("{\"message\":\"hello\",\"sleep_us\":100000}"); - http_channel.CallMethod(NULL, &cntl1, NULL, NULL, brpc::DoNothing()); + http_channel.CallMethod(nullptr, &cntl1, nullptr, nullptr, brpc::DoNothing()); brpc::Controller cntl2; test::EchoRequest req; @@ -1115,7 +1115,7 @@ TEST_F(ServerTest, http_error_code) { cntl3.http_request().uri() = "/EchoService/Echo"; cntl3.http_request().set_method(brpc::HTTP_METHOD_POST); cntl3.request_attachment().append("{\"message\":\"hello\"}"); - http_channel.CallMethod(NULL, &cntl3, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl3, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl3.Failed()); ASSERT_EQ(brpc::ELIMIT, cntl3.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_SERVICE_UNAVAILABLE, cntl3.http_response().status_code()); @@ -1140,9 +1140,9 @@ TEST_F(ServerTest, conflict_name_between_restful_mapping_and_builtin) { brpc::SERVER_DOESNT_OWN_SERVICE, "/status/hello => Echo")); ASSERT_EQ(1u, server1.service_count()); - ASSERT_TRUE(server1._global_restful_map == NULL); + ASSERT_TRUE(server1._global_restful_map == nullptr); - ASSERT_EQ(-1, server1.Start(port, NULL)); + ASSERT_EQ(-1, server1.Start(port, nullptr)); } TEST_F(ServerTest, restful_mapping_is_tried_after_others) { @@ -1159,7 +1159,7 @@ TEST_F(ServerTest, restful_mapping_is_tried_after_others) { ASSERT_TRUE(server1._global_restful_map); ASSERT_EQ(1UL, server1._global_restful_map->size()); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; @@ -1169,7 +1169,7 @@ TEST_F(ServerTest, restful_mapping_is_tried_after_others) { // accessing /status should be OK. brpc::Controller cntl; cntl.http_request().uri() = "/status"; - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.response_attachment().to_string().find( service_v1.GetDescriptor()->full_name()) != std::string::npos) @@ -1180,7 +1180,7 @@ TEST_F(ServerTest, restful_mapping_is_tried_after_others) { cntl.http_request().uri() = "/EchoService/Echo"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl.Failed()); ASSERT_EQ(0, service_v1.ncalled.load()); @@ -1189,7 +1189,7 @@ TEST_F(ServerTest, restful_mapping_is_tried_after_others) { cntl.http_request().uri() = "/non_exist"; cntl.http_request().set_method(brpc::HTTP_METHOD_POST); cntl.request_attachment().append("{\"message\":\"foo\"}"); - http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(1, service_v1.ncalled.load()); ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment()); @@ -1218,12 +1218,12 @@ TEST_F(ServerTest, add_remove_service) { test::EchoService::descriptor()->name()) == &echo_svc); ASSERT_TRUE(server.FindServiceByFullName( test::EchoService::descriptor()->full_name()) == &echo_svc); - ASSERT_TRUE(NULL == server.FindServiceByFullName( + ASSERT_TRUE(nullptr == server.FindServiceByFullName( test::EchoService::descriptor()->name())); butil::EndPoint ep; ASSERT_EQ(0, str2endpoint("127.0.0.1:8613", &ep)); - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); ASSERT_EQ(1ul, server.service_count()); ASSERT_TRUE(server.first_service() == &echo_svc); @@ -1251,7 +1251,7 @@ TEST_F(ServerTest, add_remove_service) { void SendSleepRPC(butil::EndPoint ep, int sleep_ms, bool succ) { brpc::Channel channel; - ASSERT_EQ(0, channel.Init(ep, NULL)); + ASSERT_EQ(0, channel.Init(ep, nullptr)); brpc::Controller cntl; test::EchoRequest req; @@ -1261,7 +1261,7 @@ void SendSleepRPC(butil::EndPoint ep, int sleep_ms, bool succ) { req.set_sleep_us(sleep_ms * 1000); } test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); if (succ) { EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText() << " latency=" << cntl.latency_us(); @@ -1278,7 +1278,7 @@ TEST_F(ServerTest, close_idle_connections) { ASSERT_EQ(0, str2endpoint("127.0.0.1:9776", &ep)); ASSERT_EQ(0, server.Start(ep, &opt)); - const int cfd = tcp_connect(ep, NULL); + const int cfd = tcp_connect(ep, nullptr); ASSERT_GT(cfd, 0); usleep(10000); brpc::ServerStatistics stat; @@ -1301,12 +1301,12 @@ TEST_F(ServerTest, logoff_and_multiple_start) { // Server::Stop(-1) { - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); bthread_t tid; const int64_t old_count = echo_svc.count.load(butil::memory_order_relaxed); google::protobuf::Closure* thrd_func = brpc::NewCallback(SendSleepRPC, ep, 100, true); - EXPECT_EQ(0, bthread_start_background(&tid, NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, bthread_start_background(&tid, nullptr, RunClosure, thrd_func)); while (echo_svc.count.load(butil::memory_order_relaxed) == old_count) { bthread_usleep(1000); } @@ -1315,18 +1315,18 @@ TEST_F(ServerTest, logoff_and_multiple_start) { ASSERT_EQ(0, server.Join()); timer.stop(); EXPECT_TRUE(labs(timer.m_elapsed() - 100) < 15) << timer.m_elapsed(); - bthread_join(tid, NULL); + bthread_join(tid, nullptr); } // Server::Stop(0) { ++ep.port; - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); bthread_t tid; const int64_t old_count = echo_svc.count.load(butil::memory_order_relaxed); google::protobuf::Closure* thrd_func = brpc::NewCallback(SendSleepRPC, ep, 100, true); - EXPECT_EQ(0, bthread_start_background(&tid, NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, bthread_start_background(&tid, nullptr, RunClosure, thrd_func)); while (echo_svc.count.load(butil::memory_order_relaxed) == old_count) { bthread_usleep(1000); } @@ -1338,18 +1338,18 @@ TEST_F(ServerTest, logoff_and_multiple_start) { // Assertion will fail since EchoServiceImpl::Echo is holding // additional reference to the `Socket' // EXPECT_TRUE(timer.m_elapsed() < 15) << timer.m_elapsed(); - bthread_join(tid, NULL); + bthread_join(tid, nullptr); } // Server::Stop(timeout) where timeout < g_sleep_ms { ++ep.port; - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); bthread_t tid; const int64_t old_count = echo_svc.count.load(butil::memory_order_relaxed); google::protobuf::Closure* thrd_func = brpc::NewCallback(SendSleepRPC, ep, 100, true); - EXPECT_EQ(0, bthread_start_background(&tid, NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, bthread_start_background(&tid, nullptr, RunClosure, thrd_func)); while (echo_svc.count.load(butil::memory_order_relaxed) == old_count) { bthread_usleep(1000); } @@ -1361,18 +1361,18 @@ TEST_F(ServerTest, logoff_and_multiple_start) { // Assertion will fail since EchoServiceImpl::Echo is holding // additional reference to the `Socket' // EXPECT_TRUE(labs(timer.m_elapsed() - 50) < 15) << timer.m_elapsed(); - bthread_join(tid, NULL); + bthread_join(tid, nullptr); } // Server::Stop(timeout) where timeout > g_sleep_ms { ++ep.port; - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); bthread_t tid; const int64_t old_count = echo_svc.count.load(butil::memory_order_relaxed); google::protobuf::Closure* thrd_func = brpc::NewCallback(SendSleepRPC, ep, 100, true); - EXPECT_EQ(0, bthread_start_background(&tid, NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, bthread_start_background(&tid, nullptr, RunClosure, thrd_func)); while (echo_svc.count.load(butil::memory_order_relaxed) == old_count) { bthread_usleep(1000); } @@ -1381,13 +1381,13 @@ TEST_F(ServerTest, logoff_and_multiple_start) { ASSERT_EQ(0, server.Join()); timer.stop(); EXPECT_TRUE(labs(timer.m_elapsed() - 100) < 15) << timer.m_elapsed(); - bthread_join(tid, NULL); + bthread_join(tid, nullptr); } } void SendMultipleRPC(butil::EndPoint ep, int count) { brpc::Channel channel; - EXPECT_EQ(0, channel.Init(ep, NULL)); + EXPECT_EQ(0, channel.Init(ep, nullptr)); for (int i = 0; i < count; ++i) { brpc::Controller cntl; @@ -1395,7 +1395,7 @@ void SendMultipleRPC(butil::EndPoint ep, int count) { test::EchoResponse res; req.set_message(EXP_REQUEST); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); EXPECT_EQ(EXP_RESPONSE, res.message()) << cntl.ErrorText(); } @@ -1408,7 +1408,7 @@ TEST_F(ServerTest, serving_requests) { brpc::SERVER_DOESNT_OWN_SERVICE)); butil::EndPoint ep; ASSERT_EQ(0, str2endpoint("127.0.0.1:8613", &ep)); - ASSERT_EQ(0, server.Start(ep, NULL)); + ASSERT_EQ(0, server.Start(ep, nullptr)); const int NUM = 1; const int COUNT = 1; @@ -1416,10 +1416,10 @@ TEST_F(ServerTest, serving_requests) { for (int i = 0; i < NUM; ++i) { google::protobuf::Closure* thrd_func = brpc::NewCallback(SendMultipleRPC, ep, COUNT); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } ASSERT_EQ(NUM * COUNT, echo_svc.count.load()); ASSERT_EQ(0, server.Stop(0)); @@ -1453,10 +1453,10 @@ TEST_F(ServerTest, range_start) { } brpc::Server server; - EXPECT_EQ(-1, server.Start("0.0.0.0", brpc::PortRange(START_PORT, END_PORT - 1), NULL)); + EXPECT_EQ(-1, server.Start("0.0.0.0", brpc::PortRange(START_PORT, END_PORT - 1), nullptr)); // note: add an extra port after END_PORT to detect the bug that the // probing does not stop at the first valid port(END_PORT). - EXPECT_EQ(0, server.Start("0.0.0.0", brpc::PortRange(START_PORT, END_PORT + 1/*note*/), NULL)); + EXPECT_EQ(0, server.Start("0.0.0.0", brpc::PortRange(START_PORT, END_PORT + 1/*note*/), nullptr)); EXPECT_EQ(END_PORT, server.listen_address().port); } @@ -1496,7 +1496,7 @@ TEST_F(ServerTest, base64_to_string) { service_opt.pb_bytes_to_base64 = (i == 0); ASSERT_EQ(0, server.AddService(&echo_svc, service_opt)); - ASSERT_EQ(0, server.Start(8613, NULL)); + ASSERT_EQ(0, server.Start(8613, nullptr)); brpc::Channel chan; brpc::ChannelOptions opt; @@ -1511,7 +1511,7 @@ TEST_F(ServerTest, base64_to_string) { test::BytesRequest req; test::BytesResponse res; req.set_databytes(EXP_REQUEST); - chan.CallMethod(NULL, &cntl, &req, &res, NULL); + chan.CallMethod(nullptr, &cntl, &req, &res, nullptr); EXPECT_FALSE(cntl.Failed()); EXPECT_EQ(EXP_REQUEST, res.databytes()); server.Stop(0); @@ -1527,7 +1527,7 @@ TEST_F(ServerTest, single_repeated_to_array) { service_opt.pb_single_repeated_to_array = (i == 0); ASSERT_EQ(0, server.AddService(&echo_svc, service_opt)); - ASSERT_EQ(0, server.Start(8613, NULL)); + ASSERT_EQ(0, server.Start(8613, nullptr)); for (int j = 0; j < 2; ++j) { brpc::Channel chan; @@ -1544,7 +1544,7 @@ TEST_F(ServerTest, single_repeated_to_array) { req.add_requests()->set_message("bar"); test::ComboResponse res; - chan.CallMethod(NULL, &cntl, &req, &res, NULL); + chan.CallMethod(nullptr, &cntl, &req, &res, nullptr); if (i == j) { EXPECT_FALSE(cntl.Failed()); EXPECT_EQ(res.responses_size(), req.requests_size()); @@ -1566,7 +1566,7 @@ TEST_F(ServerTest, too_big_message) { brpc::Server server; ASSERT_EQ(0, server.AddService(&echo_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(8613, NULL)); + ASSERT_EQ(0, server.Start(8613, nullptr)); #if !BRPC_WITH_GLOG logging::StringSink log_str; @@ -1574,13 +1574,13 @@ TEST_F(ServerTest, too_big_message) { #endif brpc::Channel chan; - ASSERT_EQ(0, chan.Init("localhost:8613", NULL)); + ASSERT_EQ(0, chan.Init("localhost:8613", nullptr)); brpc::Controller cntl; test::EchoRequest req; test::EchoResponse res; req.mutable_message()->resize(brpc::FLAGS_max_body_size + 1); test::EchoService_Stub stub(&chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); EXPECT_TRUE(cntl.Failed()); #if !BRPC_WITH_GLOG @@ -1606,21 +1606,21 @@ TEST_F(ServerTest, max_concurrency) { server1.MaxConcurrencyOf(&service1, "Echo") = 2; ASSERT_EQ(2, server1.MaxConcurrencyOf(&service1, "Echo")); - ASSERT_EQ(0, server1.Start(port, NULL)); + ASSERT_EQ(0, server1.Start(port, nullptr)); brpc::Channel http_channel; brpc::ChannelOptions chan_options; chan_options.protocol = "http"; ASSERT_EQ(0, http_channel.Init("0.0.0.0", port, &chan_options)); brpc::Channel normal_channel; - ASSERT_EQ(0, normal_channel.Init("0.0.0.0", port, NULL)); + ASSERT_EQ(0, normal_channel.Init("0.0.0.0", port, nullptr)); test::EchoService_Stub stub(&normal_channel); brpc::Controller cntl1; cntl1.http_request().uri() = "/EchoService/Echo"; cntl1.http_request().set_method(brpc::HTTP_METHOD_POST); cntl1.request_attachment().append("{\"message\":\"hello\",\"sleep_us\":100000}"); - http_channel.CallMethod(NULL, &cntl1, NULL, NULL, brpc::DoNothing()); + http_channel.CallMethod(nullptr, &cntl1, nullptr, nullptr, brpc::DoNothing()); brpc::Controller cntl2; test::EchoRequest req; @@ -1636,14 +1636,14 @@ TEST_F(ServerTest, max_concurrency) { cntl3.http_request().uri() = "/EchoService/Echo"; cntl3.http_request().set_method(brpc::HTTP_METHOD_POST); cntl3.request_attachment().append("{\"message\":\"hello\"}"); - http_channel.CallMethod(NULL, &cntl3, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl3, nullptr, nullptr, nullptr); ASSERT_TRUE(cntl3.Failed()); ASSERT_EQ(brpc::EHTTP, cntl3.ErrorCode()); ASSERT_EQ(brpc::HTTP_STATUS_SERVICE_UNAVAILABLE, cntl3.http_response().status_code()); brpc::Controller cntl4; req.clear_sleep_us(); - stub.Echo(&cntl4, &req, NULL, NULL); + stub.Echo(&cntl4, &req, nullptr, nullptr); ASSERT_TRUE(cntl4.Failed()); ASSERT_EQ(brpc::ELIMIT, cntl4.ErrorCode()); @@ -1656,11 +1656,11 @@ TEST_F(ServerTest, max_concurrency) { cntl3.http_request().uri() = "/EchoService/Echo"; cntl3.http_request().set_method(brpc::HTTP_METHOD_POST); cntl3.request_attachment().append("{\"message\":\"hello\"}"); - http_channel.CallMethod(NULL, &cntl3, NULL, NULL, NULL); + http_channel.CallMethod(nullptr, &cntl3, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl3.Failed()) << cntl3.ErrorText(); cntl4.Reset(); - stub.Echo(&cntl4, &req, NULL, NULL); + stub.Echo(&cntl4, &req, nullptr, nullptr); ASSERT_FALSE(cntl4.Failed()) << cntl4.ErrorText(); } @@ -1669,10 +1669,10 @@ TEST_F(ServerTest, user_fields) { brpc::Server server; EchoServiceImpl service; ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(port, NULL)); + ASSERT_EQ(0, server.Start(port, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("0.0.0.0", port, NULL)); + ASSERT_EQ(0, channel.Init("0.0.0.0", port, nullptr)); test::EchoService_Stub stub(&channel); brpc::Controller cntl; @@ -1680,13 +1680,13 @@ TEST_F(ServerTest, user_fields) { test::EchoRequest req; test::EchoResponse res; req.set_message("hello"); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(cntl.has_response_user_fields()); ASSERT_TRUE(!cntl.response_user_fields()->empty()); std::string* val = cntl.response_user_fields()->seek(EXP_USER_FIELD_KEY); - ASSERT_TRUE(val != NULL); + ASSERT_TRUE(val != nullptr); ASSERT_EQ(*val, EXP_USER_FIELD_VALUE); } @@ -1754,7 +1754,7 @@ void TestBaiduMasterService(brpc::Channel& channel, brpc::CompressType compress_ cntl.request_attachment().append(EXP_REQUEST); cntl.set_request_compress_type(compress_type); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(EXP_RESPONSE, res.message()); ASSERT_EQ(EXP_RESPONSE, cntl.response_attachment().to_string()); @@ -1816,7 +1816,7 @@ void TestGenericCall(brpc::Channel& channel, brpc::ContentType content_type, test::EchoService::descriptor()->FindMethodByName("Echo")->name()); cntl.reset_sampled_request(sampled_request); - channel.CallMethod(NULL, &cntl, &serialized_request, &serialized_response, NULL); + channel.CallMethod(nullptr, &cntl, &serialized_request, &serialized_response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_TRUE(brpc::policy::DeserializeRpcMessage( @@ -1883,7 +1883,7 @@ TEST_F(ServerTest, generic_call) { } struct DefaultRpcPBMessages : public brpc::RpcPBMessages { - DefaultRpcPBMessages() : request(NULL), response(NULL) {} + DefaultRpcPBMessages() : request(nullptr), response(nullptr) {} ::google::protobuf::Message* Request() override { return request; } ::google::protobuf::Message* Response() override { return response; } @@ -1909,8 +1909,8 @@ class TestRpcPBMessageFactory : public brpc::RpcPBMessageFactory { auto test_messages = static_cast(messages); butil::return_object(static_cast(test_messages->request)); butil::return_object(static_cast(test_messages->response)); - test_messages->request = NULL; - test_messages->response = NULL; + test_messages->request = nullptr; + test_messages->response = nullptr; butil::return_object(test_messages); } }; @@ -1935,7 +1935,7 @@ TEST_F(ServerTest, rpc_pb_message_factory) { v1::EchoResponse res; req.set_message(EXP_REQUEST); v1::EchoService_Stub stub(&baidu_chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(EXP_REQUEST + "_v1", res.message()); } @@ -1949,7 +1949,7 @@ TEST_F(ServerTest, rpc_pb_message_factory) { cntl.request_attachment().append( butil::string_printf(R"({"message":"%s"})", EXP_REQUEST.c_str())); v1::EchoService_Stub stub(&http_chan); - stub.Echo(&cntl, NULL, NULL, NULL); + stub.Echo(&cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(butil::string_printf(R"({"message":"%s_v1"})", EXP_REQUEST.c_str()), cntl.response_attachment().to_string()); @@ -1979,7 +1979,7 @@ TEST_F(ServerTest, arena_rpc_pb_message_factory) { v3::EchoResponse res; req.set_message(EXP_REQUEST); v3::EchoService_Stub stub(&baidu_chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(EXP_RESPONSE, res.message()); } @@ -1993,7 +1993,7 @@ TEST_F(ServerTest, arena_rpc_pb_message_factory) { cntl.request_attachment().append( butil::string_printf(R"({"message":"%s"})", EXP_REQUEST.c_str())); v3::EchoService_Stub stub(&http_chan); - stub.Echo(&cntl, NULL, NULL, NULL); + stub.Echo(&cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); ASSERT_EQ(butil::string_printf(R"({"message":"%s"})", EXP_RESPONSE.c_str()), cntl.response_attachment().to_string()); @@ -2016,7 +2016,7 @@ void TestBaiduStdAuth(const butil::EndPoint& ep, test::EchoResponse res; req.set_message(EXP_REQUEST); test::EchoService_Stub stub(&chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_EQ(cntl.Failed(), failed) << cntl.ErrorText(); ASSERT_EQ(cntl.ErrorCode(), error_code); } @@ -2034,7 +2034,7 @@ void TestHttpAuth(const butil::EndPoint& ep, cntl.request_attachment().append(R"({"message": "hello"})"); cntl.http_request().set_method(brpc::HTTP_METHOD_POST); test::EchoService_Stub stub(&chan); - chan.CallMethod(NULL, &cntl, NULL, NULL, NULL); + chan.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_EQ(cntl.Failed(), failed) << cntl.ErrorText(); ASSERT_EQ(cntl.http_response().status_code(), status_code); } @@ -2084,7 +2084,7 @@ void TestClientHost(const butil::EndPoint& ep, test::EchoResponse res; req.set_message(EXP_REQUEST); test::EchoService_Stub stub(&chan); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_EQ(cntl.Failed(), failed) << cntl.ErrorText(); ASSERT_EQ(cntl.ErrorCode(), error_code); } diff --git a/test/brpc_socket_map_unittest.cpp b/test/brpc_socket_map_unittest.cpp index d40db0e723..c946c7d16b 100644 --- a/test/brpc_socket_map_unittest.cpp +++ b/test/brpc_socket_map_unittest.cpp @@ -49,7 +49,7 @@ void* worker(void*) { } } } - return NULL; + return nullptr; } class SocketMapTest : public ::testing::Test{ @@ -91,10 +91,10 @@ TEST_F(SocketMapTest, idle_timeout) { brpc::FLAGS_defer_close_second = TIMEOUT; pthread_t tids[NTHREAD]; for (int i = 0; i < NTHREAD; ++i) { - ASSERT_EQ(0, pthread_create(&tids[i], NULL, worker, NULL)); + ASSERT_EQ(0, pthread_create(&tids[i], nullptr, worker, nullptr)); } for (int i = 0; i < NTHREAD; ++i) { - ASSERT_EQ(0, pthread_join(tids[i], NULL)); + ASSERT_EQ(0, pthread_join(tids[i], nullptr)); } brpc::SocketId id; // Socket still exists since it has not reached timeout yet @@ -124,7 +124,7 @@ TEST_F(SocketMapTest, idle_timeout) { main_ptr.reset(); id = ptr->id(); ptr->ReturnToPool(); - ptr.reset(NULL); + ptr.reset(nullptr); usleep(TIMEOUT * 1000000L + 2000000L); // Pooled connection should be `ReleaseAdditionalReference', // which destroyed the Socket. As a result `GetSocketFromPool' diff --git a/test/brpc_socket_unittest.cpp b/test/brpc_socket_unittest.cpp index d032bd617d..2da9adf3d2 100644 --- a/test/brpc_socket_unittest.cpp +++ b/test/brpc_socket_unittest.cpp @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) { brpc::SerializeRequestDefault, brpc::policy::PackHuluRequest, EchoProcessHuluRequest, EchoProcessHuluRequest, - NULL, NULL, NULL, + nullptr, nullptr, nullptr, brpc::CONNECTION_TYPE_ALL, "dummy_hulu" }; EXPECT_EQ(0, RegisterProtocol((brpc::ProtocolType)30, dummy_protocol)); return RUN_ALL_TESTS(); @@ -107,13 +107,13 @@ class SocketTest : public ::testing::Test{ }; }; -brpc::Socket* global_sock = NULL; +brpc::Socket* global_sock = nullptr; class CheckRecycle : public brpc::SocketUser { void BeforeRecycle(brpc::Socket* s) { ASSERT_TRUE(global_sock); ASSERT_EQ(global_sock, s); - global_sock = NULL; + global_sock = nullptr; delete this; } }; @@ -141,7 +141,7 @@ TEST_F(SocketTest, not_recycle_until_zero_nref) { ASSERT_EQ(0, s->SetFailed()); ASSERT_EQ(s.get(), global_sock); } - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); brpc::SocketUniquePtr ptr; @@ -161,7 +161,7 @@ void* auth_fighter(void* arg) { } else { EXPECT_EQ(AUTH_ERR, auth_error); } - return NULL; + return nullptr; } TEST_F(SocketTest, authentication) { @@ -173,10 +173,10 @@ TEST_F(SocketTest, authentication) { bthread_t th[64]; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, bthread_start_urgent(&th[i], NULL, auth_fighter, s.get())); + ASSERT_EQ(0, bthread_start_urgent(&th[i], nullptr, auth_fighter, s.get())); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, bthread_join(th[i], NULL)); + ASSERT_EQ(0, bthread_join(th[i], nullptr)); } // Only one fighter wins ASSERT_EQ(1, winner_count.load()); @@ -186,13 +186,13 @@ TEST_F(SocketTest, authentication) { ASSERT_NE(0, s->FightAuthentication(&auth_error)); ASSERT_EQ(AUTH_ERR, auth_error); // Socket has been `SetFailed' when authentication failed - ASSERT_TRUE(brpc::Socket::Address(s->id(), NULL)); + ASSERT_TRUE(brpc::Socket::Address(s->id(), nullptr)); } static butil::atomic g_called_seq(1); class MyMessage : public brpc::SocketMessage { public: - MyMessage(const char* str, size_t len, int* called = NULL) + MyMessage(const char* str, size_t len, int* called = nullptr) : _str(str), _len(len), _called(called) {} private: butil::Status AppendAndDestroySelf(butil::IOBuf* out_buf, brpc::Socket*) { @@ -295,7 +295,7 @@ TEST_F(SocketTest, single_threaded_write) { } ASSERT_EQ(0, s->SetFailed()); } - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); } @@ -310,7 +310,7 @@ void EchoProcessHuluRequest(brpc::InputMessageBase* msg_base) { class MyConnect : public brpc::AppConnect { public: - MyConnect() : _done(NULL), _data(NULL), _called_start_connect(false) {} + MyConnect() : _done(nullptr), _data(nullptr), _called_start_connect(false) {} void StartConnect(const brpc::Socket*, void (*done)(int err, void* data), void* data) { @@ -339,7 +339,7 @@ TEST_F(SocketTest, single_threaded_connect_and_write) { ANNOTATE_LEAKING_OBJECT_PTR(messenger); const brpc::InputMessageHandler pairs[] = { { brpc::policy::ParseHuluMessage, - EchoProcessHuluRequest, NULL, NULL, "dummy_hulu" } + EchoProcessHuluRequest, nullptr, nullptr, "dummy_hulu" } }; int listening_fd = -1; @@ -354,7 +354,7 @@ TEST_F(SocketTest, single_threaded_connect_and_write) { ASSERT_GT(listening_fd, 0) << berror(); ASSERT_EQ(0, butil::make_non_blocking(listening_fd)); ASSERT_EQ(0, messenger->AddHandler(pairs[0])); - ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, NULL, false)); + ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, nullptr, false)); brpc::SocketId id = 8888; brpc::SocketOptions options; @@ -422,7 +422,7 @@ TEST_F(SocketTest, single_threaded_connect_and_write) { } ASSERT_EQ(0, s->SetFailed()); } - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); // The id is invalid. brpc::SocketUniquePtr ptr; ASSERT_EQ(-1, brpc::Socket::Address(id, &ptr)); @@ -457,12 +457,12 @@ void* FailedWriter(void* void_arg) { brpc::SocketUniquePtr sock; if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); - return NULL; + return nullptr; } char buf[32]; for (size_t i = 0; i < arg->times; ++i) { bthread_id_t id; - EXPECT_EQ(0, bthread_id_create(&id, NULL, NULL)); + EXPECT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); snprintf(buf, sizeof(buf), "%0" BAIDU_SYMBOLSTR(NUMBER_WIDTH) "lu", i + arg->offset); butil::IOBuf src; @@ -475,7 +475,7 @@ void* FailedWriter(void* void_arg) { // calls `SetFailed' making others' error_code=EINVAL //EXPECT_EQ(ECONNREFUSED, error_code); } - return NULL; + return nullptr; } TEST_F(SocketTest, fail_to_connect) { @@ -500,17 +500,17 @@ TEST_F(SocketTest, fail_to_connect) { args[i].times = REP; args[i].offset = i * REP; args[i].socket_id = id; - ASSERT_EQ(0, pthread_create(&th[i], NULL, FailedWriter, &args[i])); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, FailedWriter, &args[i])); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } ASSERT_EQ(-1, s->SetFailed()); // already SetFailed ASSERT_EQ(-1, s->fd()); } // KeepWrite is possibly still running. int64_t start_time = butil::cpuwide_time_us(); - while (global_sock != NULL) { + while (global_sock != nullptr) { bthread_usleep(1000); ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L) << "Too long!"; } @@ -571,11 +571,11 @@ TEST_F(SocketTest, not_health_check_when_nref_hits_0) { s->ReleaseHCRelatedReference(); } // StartHealthCheck is possibly still running. Spin until global_sock - // is NULL(set in CheckRecycle::BeforeRecycle). Notice that you should + // is nullptr(set in CheckRecycle::BeforeRecycle). Notice that you should // not spin until Socket::Status(id) becomes -1 and assert global_sock - // to be NULL because invalidating id happens before calling BeforeRecycle. + // to be nullptr because invalidating id happens before calling BeforeRecycle. const int64_t start_time = butil::cpuwide_time_us(); - while (global_sock != NULL) { + while (global_sock != nullptr) { bthread_usleep(1000); ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L); } @@ -618,7 +618,7 @@ TEST_F(SocketTest, app_level_health_check) { { brpc::Controller cntl; cntl.http_request().uri() = "/"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); EXPECT_TRUE(cntl.Failed()); ASSERT_EQ(ECONNREFUSED, cntl.ErrorCode()); } @@ -637,14 +637,14 @@ TEST_F(SocketTest, app_level_health_check) { brpc::Server server; HealthCheckTestServiceImpl hc_service; ASSERT_EQ(0, server.AddService(&hc_service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(point, NULL)); + ASSERT_EQ(0, server.Start(point, nullptr)); for (int i = 0; i < 4; ++i) { // although ::connect would succeed, the stall in hc_service makes // the health check rpc fail. brpc::Controller cntl; cntl.http_request().uri() = "/"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_EQ(EHOSTDOWN, cntl.ErrorCode()); bthread_usleep(1000000 /*1s*/); } @@ -654,7 +654,7 @@ TEST_F(SocketTest, app_level_health_check) { { brpc::Controller cntl; cntl.http_request().uri() = "/"; - channel.CallMethod(NULL, &cntl, NULL, NULL, NULL); + channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr); ASSERT_FALSE(cntl.Failed()); ASSERT_GT(cntl.response_attachment().size(), (size_t)0); } @@ -679,7 +679,7 @@ TEST_F(SocketTest, health_check) { options.user = new CheckRecycle; options.health_check_interval_s = kCheckInteval/*s*/; ASSERT_EQ(0, brpc::Socket::Create(options, &id)); - brpc::Socket* s = NULL; + brpc::Socket* s = nullptr; { brpc::SocketUniquePtr ptr; ASSERT_EQ(0, brpc::Socket::Address(id, &ptr)); @@ -751,14 +751,14 @@ TEST_F(SocketTest, health_check) { const brpc::InputMessageHandler pairs[] = { { brpc::policy::ParseHuluMessage, - EchoProcessHuluRequest, NULL, NULL, "dummy_hulu" } + EchoProcessHuluRequest, nullptr, nullptr, "dummy_hulu" } }; int listening_fd = tcp_listen(point); ASSERT_TRUE(listening_fd > 0); butil::make_non_blocking(listening_fd); ASSERT_EQ(0, messenger->AddHandler(pairs[0])); - ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, NULL, false)); + ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, nullptr, false)); int64_t start_time = butil::cpuwide_time_us(); nref = -1; @@ -807,7 +807,7 @@ TEST_F(SocketTest, health_check) { ASSERT_EQ(0, brpc::Socket::SetFailed(id)); // StartHealthCheck is possibly still addressing the Socket. start_time = butil::cpuwide_time_us(); - while (global_sock != NULL) { + while (global_sock != nullptr) { bthread_usleep(1000); ASSERT_LT(butil::cpuwide_time_us(), start_time + 1000000L); } @@ -823,7 +823,7 @@ void* Writer(void* void_arg) { brpc::SocketUniquePtr sock; if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); - return NULL; + return nullptr; } char buf[32]; for (size_t i = 0; i < arg->times; ++i) { @@ -843,7 +843,7 @@ void* Writer(void* void_arg) { break; } } - return NULL; + return nullptr; } TEST_F(SocketTest, multi_threaded_write) { @@ -879,7 +879,7 @@ TEST_F(SocketTest, multi_threaded_write) { args[i].times = REP; args[i].offset = i * REP; args[i].socket_id = id; - ASSERT_EQ(0, pthread_create(&th[i], NULL, Writer, &args[i])); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, Writer, &args[i])); } if (k == 1) { @@ -909,7 +909,7 @@ TEST_F(SocketTest, multi_threaded_write) { char buf[NUMBER_WIDTH + 1]; dest.copy_to(buf, NUMBER_WIDTH); buf[sizeof(buf)-1] = 0; - result.push_back(strtol(buf, NULL, 10)); + result.push_back(strtol(buf, nullptr, 10)); dest.pop_front(NUMBER_WIDTH); } if (result.size() >= REP * ARRAY_SIZE(th)) { @@ -917,7 +917,7 @@ TEST_F(SocketTest, multi_threaded_write) { } } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } ASSERT_TRUE(dest.empty()); bthread::g_task_control->print_rq_sizes(std::cout); @@ -934,7 +934,7 @@ TEST_F(SocketTest, multi_threaded_write) { ASSERT_EQ(0, s->SetFailed()); s.release()->Dereference(); - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); } } @@ -944,7 +944,7 @@ void* FastWriter(void* void_arg) { brpc::SocketUniquePtr sock; if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); - return NULL; + return nullptr; } char buf[] = "hello reader side!"; int64_t begin_ts = butil::cpuwide_time_us(); @@ -970,7 +970,7 @@ void* FastWriter(void* void_arg) { int64_t total_time = end_ts - begin_ts; printf("total=%ld count=%ld nretry=%ld\n", (long)total_time * 1000/ c, (long)c, (long)nretry); - return NULL; + return nullptr; } struct ReaderArg { @@ -994,7 +994,7 @@ void* reader(void* void_arg) { arg->nread += nr; } free(buf); - return NULL; + return nullptr; } TEST_F(SocketTest, multi_threaded_write_perf) { @@ -1026,12 +1026,12 @@ TEST_F(SocketTest, multi_threaded_write_perf) { args[i].times = REP; args[i].offset = i * REP; args[i].socket_id = id; - bthread_start_background(&th[i], NULL, FastWriter, &args[i]); + bthread_start_background(&th[i], nullptr, FastWriter, &args[i]); } pthread_t rth; ReaderArg reader_arg = { fds[0], 0 }; - pthread_create(&rth, NULL, reader, &reader_arg); + pthread_create(&rth, nullptr, reader, &reader_arg); butil::Timer tm; ProfilerStart("write.prof"); @@ -1048,12 +1048,12 @@ TEST_F(SocketTest, multi_threaded_write_perf) { args[i].times = 0; } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, bthread_join(th[i], NULL)); + ASSERT_EQ(0, bthread_join(th[i], nullptr)); } ASSERT_EQ(0, s->SetFailed()); s.release()->Dereference(); - pthread_join(rth, NULL); - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + pthread_join(rth, nullptr); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); } @@ -1297,7 +1297,7 @@ TEST_F(SocketTest, keepalive_input_message) { } ASSERT_GT(listening_fd, 0) << berror(); ASSERT_EQ(0, butil::make_non_blocking(listening_fd)); - ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, NULL, false)); + ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, nullptr, false)); int default_keepalive = 0; int default_keepalive_idle = 0; @@ -1491,7 +1491,7 @@ TEST_F(SocketTest, socket_buffer_options_before_connect) { ASSERT_EQ(0, brpc::Socket::Address(id, &ptr)) << "id=" << id; const timespec duetime = butil::milliseconds_from_now(1000); - butil::fd_guard connected_fd(ptr->Connect(&duetime, NULL, NULL)); + butil::fd_guard connected_fd(ptr->Connect(&duetime, nullptr, nullptr)); ASSERT_GT(connected_fd, 0); CheckSocketBufferValues(connected_fd, expected); @@ -1510,12 +1510,12 @@ TEST_F(SocketTest, socket_buffer_options_before_accept) { butil::EndPoint point; ASSERT_EQ(0, str2endpoint("127.0.0.1:0", &point)); brpc::Server server; - ASSERT_EQ(0, server.Start(point, NULL)); + ASSERT_EQ(0, server.Start(point, nullptr)); point = server.listen_address(); brpc::Acceptor* messenger = brpc::ServerPrivateAccessor(&server).acceptor(); - ASSERT_TRUE(messenger != NULL); + ASSERT_TRUE(messenger != nullptr); ASSERT_GT(messenger->listened_fd(), 0); CheckSocketBufferValues(messenger->listened_fd(), expected); @@ -1581,7 +1581,7 @@ TEST_F(SocketTest, tcp_user_timeout) { } ASSERT_GT(listening_fd, 0) << berror(); ASSERT_EQ(0, butil::make_non_blocking(listening_fd)); - ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, NULL, false)); + ASSERT_EQ(0, messenger->StartAccept(listening_fd, -1, nullptr, false)); { brpc::SocketOptions options; @@ -1678,7 +1678,7 @@ TEST_F(SocketTest, notify_on_success) { pthread_t rth; ReaderArg reader_arg = { fds[0], 0 }; - pthread_create(&rth, NULL, reader, &reader_arg); + pthread_create(&rth, nullptr, reader, &reader_arg); size_t success_count = 0; char buf[] = "hello reader side!"; @@ -1706,9 +1706,9 @@ TEST_F(SocketTest, notify_on_success) { ASSERT_EQ(0, s->SetFailed()); s.release()->Dereference(); - pthread_join(rth, NULL); + pthread_join(rth, nullptr); ASSERT_EQ(REP, success_count); - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); } @@ -1737,7 +1737,7 @@ void* ShutdownWriter(void* void_arg) { brpc::SocketUniquePtr sock; if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { LOG(INFO) << "Fail to address SocketId=" << arg->socket_id; - return NULL; + return nullptr; } for (size_t c = 0; c < arg->times; ++c) { bthread_id_t write_id; @@ -1758,7 +1758,7 @@ void* ShutdownWriter(void* void_arg) { } } } - return NULL; + return nullptr; } void TestShutdownWrite() { @@ -1787,7 +1787,7 @@ void TestShutdownWrite() { pthread_t rth; ReaderArg reader_arg = { fds[0], 0 }; - pthread_create(&rth, NULL, reader, &reader_arg); + pthread_create(&rth, nullptr, reader, &reader_arg); bthread_t th[3]; ShutdownWriterArg args[ARRAY_SIZE(th)]; @@ -1796,11 +1796,11 @@ void TestShutdownWrite() { args[i].socket_id = id; args[i].total_count = 0; args[i].success_count = 0; - bthread_start_background(&th[i], NULL, ShutdownWriter, &args[i]); + bthread_start_background(&th[i], nullptr, ShutdownWriter, &args[i]); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, bthread_join(th[i], NULL)); + ASSERT_EQ(0, bthread_join(th[i], nullptr)); } bthread_usleep(50 * 1000); @@ -1808,8 +1808,8 @@ void TestShutdownWrite() { ASSERT_FALSE(s->Failed()); ASSERT_EQ(0, s->SetFailed()); s.release()->Dereference(); - pthread_join(rth, NULL); - ASSERT_EQ((brpc::Socket*)NULL, global_sock); + pthread_join(rth, nullptr); + ASSERT_EQ((brpc::Socket*)nullptr, global_sock); close(fds[0]); size_t total_count = 0; diff --git a/test/brpc_sofa_pbrpc_protocol_unittest.cpp b/test/brpc_sofa_pbrpc_protocol_unittest.cpp index 3996de0e7c..5a44e89c89 100644 --- a/test/brpc_sofa_pbrpc_protocol_unittest.cpp +++ b/test/brpc_sofa_pbrpc_protocol_unittest.cpp @@ -109,7 +109,7 @@ class SofaTest : public ::testing::Test{ virtual void TearDown() {}; void VerifyMessage(brpc::InputMessageBase* msg) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -118,7 +118,7 @@ class SofaTest : public ::testing::Test{ void ProcessMessage(void (*process)(brpc::InputMessageBase*), brpc::InputMessageBase* msg, bool set_eof) { - if (msg->_socket == NULL) { + if (msg->_socket == nullptr) { _socket->ReAddress(&msg->_socket); } msg->_arg = &_server; @@ -169,7 +169,7 @@ class SofaTest : public ::testing::Test{ butil::IOPortal buf; EXPECT_EQ((ssize_t)bytes_in_pipe, buf.append_from_file_descriptor(_pipe_fds[0], 1024)); - brpc::ParseResult pr = brpc::policy::ParseSofaMessage(&buf, NULL, false, NULL); + brpc::ParseResult pr = brpc::policy::ParseSofaMessage(&buf, nullptr, false, nullptr); EXPECT_EQ(brpc::PARSE_OK, pr.error()); brpc::policy::MostCommonMessage* msg = static_cast(pr.message()); @@ -193,13 +193,13 @@ class SofaTest : public ::testing::Test{ brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackSofaRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); brpc::ParseResult req_pr = - brpc::policy::ParseSofaMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseSofaMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessSofaRequest, req_msg, false); @@ -307,13 +307,13 @@ TEST_F(SofaTest, complete_flow) { brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackSofaRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Verify and handle request brpc::ParseResult req_pr = - brpc::policy::ParseSofaMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseSofaMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); VerifyMessage(req_msg); @@ -323,7 +323,7 @@ TEST_F(SofaTest, complete_flow) { butil::IOPortal response_buf; response_buf.append_from_file_descriptor(_pipe_fds[0], 1024); brpc::ParseResult res_pr = - brpc::policy::ParseSofaMessage(&response_buf, NULL, false, NULL); + brpc::policy::ParseSofaMessage(&response_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, res_pr.error()); brpc::InputMessageBase* res_msg = res_pr.message(); ProcessMessage(brpc::policy::ProcessSofaResponse, res_msg, false); @@ -344,13 +344,13 @@ TEST_F(SofaTest, close_in_callback) { brpc::SerializeRequestDefault(&request_buf, &cntl, &req); ASSERT_FALSE(cntl.Failed()); brpc::policy::PackSofaRequest( - &total_buf, NULL, cntl.call_id().value, + &total_buf, nullptr, cntl.call_id().value, test::EchoService::descriptor()->method(0), &cntl, request_buf, &_auth); ASSERT_FALSE(cntl.Failed()); // Handle request brpc::ParseResult req_pr = - brpc::policy::ParseSofaMessage(&total_buf, NULL, false, NULL); + brpc::policy::ParseSofaMessage(&total_buf, nullptr, false, nullptr); ASSERT_EQ(brpc::PARSE_OK, req_pr.error()); brpc::InputMessageBase* req_msg = req_pr.message(); ProcessMessage(brpc::policy::ProcessSofaRequest, req_msg, false); @@ -372,7 +372,7 @@ TEST_F(SofaTest, reject_oversized_body) { butil::IOBuf buf; AppendSofaTestHeader(&buf, 0, body_size, body_size); brpc::ParseResult pr = - brpc::policy::ParseSofaMessage(&buf, _socket.get(), false, NULL); + brpc::policy::ParseSofaMessage(&buf, _socket.get(), false, nullptr); ASSERT_EQ(brpc::PARSE_ERROR_TOO_BIG_DATA, pr.error()); } @@ -383,7 +383,7 @@ TEST_F(SofaTest, reject_oversized_meta) { butil::IOBuf buf; AppendSofaTestHeader(&buf, meta_size, 0, meta_size); brpc::ParseResult pr = - brpc::policy::ParseSofaMessage(&buf, _socket.get(), false, NULL); + brpc::policy::ParseSofaMessage(&buf, _socket.get(), false, nullptr); ASSERT_EQ(brpc::PARSE_ERROR_TOO_BIG_DATA, pr.error()); } } //namespace diff --git a/test/brpc_ssl_unittest.cpp b/test/brpc_ssl_unittest.cpp index a6f7affc7c..6825709e91 100644 --- a/test/brpc_ssl_unittest.cpp +++ b/test/brpc_ssl_unittest.cpp @@ -91,7 +91,7 @@ class SSLTest : public ::testing::Test{ void* RunClosure(void* arg) { google::protobuf::Closure* done = (google::protobuf::Closure*)arg; done->Run(); - return NULL; + return nullptr; } void SendMultipleRPC(brpc::Channel* channel, int count) { @@ -101,7 +101,7 @@ void SendMultipleRPC(brpc::Channel* channel, int count) { test::EchoResponse res; req.set_message(EXP_REQUEST); test::EchoService_Stub stub(channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); EXPECT_EQ(EXP_RESPONSE, res.message()) << cntl.ErrorText(); } @@ -135,7 +135,7 @@ TEST_F(SSLTest, sanity) { brpc::Controller cntl; test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); EXPECT_EQ(EXP_RESPONSE, res.message()) << cntl.ErrorText(); } @@ -152,10 +152,10 @@ TEST_F(SSLTest, sanity) { for (int i = 0; i < NUM; ++i) { google::protobuf::Closure* thrd_func = brpc::NewCallback(SendMultipleRPC, &channel, COUNT); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } } { @@ -169,10 +169,10 @@ TEST_F(SSLTest, sanity) { for (int i = 0; i < NUM; ++i) { google::protobuf::Closure* thrd_func = brpc::NewCallback(SendMultipleRPC, &channel, COUNT); - EXPECT_EQ(0, pthread_create(&tids[i], NULL, RunClosure, thrd_func)); + EXPECT_EQ(0, pthread_create(&tids[i], nullptr, RunClosure, thrd_func)); } for (int i = 0; i < NUM; ++i) { - pthread_join(tids[i], NULL); + pthread_join(tids[i], nullptr); } } @@ -210,18 +210,18 @@ TEST_F(SSLTest, force_ssl) { brpc::Controller cntl; test::EchoService_Stub stub(&channel); test::EchoResponse res; - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_EQ(EXP_RESPONSE, res.message()) << cntl.ErrorText(); } { brpc::Channel channel; - ASSERT_EQ(0, channel.Init("localhost", port, NULL)); + ASSERT_EQ(0, channel.Init("localhost", port, nullptr)); brpc::Controller cntl; test::EchoService_Stub stub(&channel); test::EchoResponse res; - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); ASSERT_TRUE(cntl.Failed()); } @@ -239,7 +239,7 @@ void CallServerWithExpectedPeerName(int port, const char* server_address, brpc::VerifyMode::VERIFY_PEER; options.mutable_ssl_options()->verify.verify_depth = 1; options.mutable_ssl_options()->verify.ca_file_path = "cert1.crt"; - if (expected_peer_name != NULL) { + if (expected_peer_name != nullptr) { options.mutable_ssl_options()->verify.expected_peer_name = expected_peer_name; } std::string url = server_address; @@ -251,7 +251,7 @@ void CallServerWithExpectedPeerName(int port, const char* server_address, req.set_message(EXP_REQUEST); brpc::Controller cntl; test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &req, &res, NULL); + stub.Echo(&cntl, &req, &res, nullptr); if (expect_success) { EXPECT_FALSE(cntl.Failed()) << cntl.ErrorText(); EXPECT_EQ(EXP_RESPONSE, res.message()); @@ -274,8 +274,8 @@ TEST_F(SSLTest, verify_peer_name) { &echo_svc, brpc::SERVER_DOESNT_OWN_SERVICE)); ASSERT_EQ(0, server.Start(port, &server_options)); - CallServerWithExpectedPeerName(port, "https://localhost", NULL, true); - CallServerWithExpectedPeerName(port, "https://127.0.0.1", NULL, false); + CallServerWithExpectedPeerName(port, "https://localhost", nullptr, true); + CallServerWithExpectedPeerName(port, "https://127.0.0.1", nullptr, false); CallServerWithExpectedPeerName( port, "https://localhost", "wrong.local", false); @@ -286,11 +286,11 @@ TEST_F(SSLTest, verify_peer_name) { TEST_F(SSLTest, expected_peer_name_requires_peer_verification) { brpc::ChannelSSLOptions options; options.verify.expected_peer_name = "localhost"; - EXPECT_EQ(NULL, brpc::CreateClientSSLContext(options)); + EXPECT_EQ(nullptr, brpc::CreateClientSSLContext(options)); options.verify.verify_depth = 1; options.verify.verify_mode = brpc::VerifyMode::VERIFY_NONE; - EXPECT_EQ(NULL, brpc::CreateClientSSLContext(options)); + EXPECT_EQ(nullptr, brpc::CreateClientSSLContext(options)); } TEST_F(SSLTest, peer_name_verification_capability) { @@ -311,7 +311,7 @@ void ProcessResponse(brpc::InputMessageBase* msg_base) { ASSERT_EQ(0, response_meta.error_code()) << response_meta.error_text(); const brpc::CallId cid = { static_cast(meta.correlation_id()) }; - brpc::Controller* cntl = NULL; + brpc::Controller* cntl = nullptr; ASSERT_EQ(0, bthread_id_lock(cid, (void**)&cntl)); ASSERT_NE(nullptr, cntl); ASSERT_TRUE(brpc::ParsePbFromIOBuf(cntl->response(), msg->payload)); @@ -321,14 +321,14 @@ void ProcessResponse(brpc::InputMessageBase* msg_base) { TEST_F(SSLTest, connect_on_create) { brpc::Protocol dummy_protocol = { brpc::policy::ParseRpcMessage, brpc::SerializeRequestDefault, - brpc::policy::PackRpcRequest,NULL, ProcessResponse, - NULL, NULL, NULL, brpc::CONNECTION_TYPE_ALL, "ssl_ut_baidu" + brpc::policy::PackRpcRequest,nullptr, ProcessResponse, + nullptr, nullptr, nullptr, brpc::CONNECTION_TYPE_ALL, "ssl_ut_baidu" }; ASSERT_EQ(0, RegisterProtocol((brpc::ProtocolType)30, dummy_protocol)); brpc::InputMessageHandler dummy_handler ={ dummy_protocol.parse, dummy_protocol.process_response, - NULL, NULL, dummy_protocol.name + nullptr, nullptr, dummy_protocol.name }; brpc::InputMessenger messenger; ASSERT_EQ(0, messenger.AddHandler(dummy_handler)); @@ -378,9 +378,9 @@ TEST_F(SSLTest, connect_on_create) { cntl._response = &res; const brpc::CallId correlation_id = cntl.call_id(); brpc::SerializeRequestDefault(&request_body, &cntl, &req); - brpc::policy::PackRpcRequest(&request_buf, NULL, correlation_id.value, + brpc::policy::PackRpcRequest(&request_buf, nullptr, correlation_id.value, test::EchoService_Stub::descriptor()->method(0), - &cntl, request_body, NULL); + &cntl, request_body, nullptr); ASSERT_EQ(0, ptr->Write(&request_buf)); brpc::Join(correlation_id); ASSERT_EQ(EXP_RESPONSE, res.message()); @@ -408,7 +408,7 @@ void CheckCert(const char* cname, const char* cert) { ASSERT_EQ(0, brpc::Socket::Address(ids[0], &sock)); X509* x509 = sock->GetPeerCertificate(); - ASSERT_TRUE(x509 != NULL); + ASSERT_TRUE(x509 != nullptr); std::vector cnames; brpc::ExtractHostnames(x509, &cnames); ASSERT_EQ(cert, cnames[0]) << x509; @@ -528,7 +528,7 @@ void* ssl_perf_client(void* arg) { << size * REP / tm.u_elapsed() << "M/s" << ", latency=" << tm.u_elapsed() / REP << "us"; } - return NULL; + return nullptr; } void* ssl_perf_server(void* arg) { @@ -541,23 +541,23 @@ void* ssl_perf_server(void* arg) { SSL_read(ssl, buf, size); } } - return NULL; + return nullptr; } TEST_F(SSLTest, ssl_perf) { const butil::EndPoint ep(butil::IP_ANY, 5961); butil::fd_guard listenfd(butil::tcp_listen(ep)); ASSERT_GT(listenfd, 0); - int clifd = tcp_connect(ep, NULL); + int clifd = tcp_connect(ep, nullptr); ASSERT_GT(clifd, 0); - int servfd = accept(listenfd, NULL, NULL); + int servfd = accept(listenfd, nullptr, nullptr); ASSERT_GT(servfd, 0); brpc::ChannelSSLOptions opt; SSL_CTX* cli_ctx = brpc::CreateClientSSLContext(opt); SSL_CTX* serv_ctx = brpc::CreateServerSSLContext("cert1.crt", "cert1.key", - brpc::SSLOptions(), NULL, NULL); + brpc::SSLOptions(), nullptr, nullptr); SSL* cli_ssl = brpc::CreateSSLSession(cli_ctx, 0, clifd, false); #if defined(SSL_CTRL_SET_TLSEXT_HOSTNAME) || defined(USE_MESALINK) SSL_set_tlsext_host_name(cli_ssl, "localhost"); @@ -565,10 +565,10 @@ TEST_F(SSLTest, ssl_perf) { SSL* serv_ssl = brpc::CreateSSLSession(serv_ctx, 0, servfd, true); pthread_t cpid; pthread_t spid; - ASSERT_EQ(0, pthread_create(&cpid, NULL, ssl_perf_client, cli_ssl)); - ASSERT_EQ(0, pthread_create(&spid, NULL, ssl_perf_server , serv_ssl)); - ASSERT_EQ(0, pthread_join(cpid, NULL)); - ASSERT_EQ(0, pthread_join(spid, NULL)); + ASSERT_EQ(0, pthread_create(&cpid, nullptr, ssl_perf_client, cli_ssl)); + ASSERT_EQ(0, pthread_create(&spid, nullptr, ssl_perf_server , serv_ssl)); + ASSERT_EQ(0, pthread_join(cpid, nullptr)); + ASSERT_EQ(0, pthread_join(spid, nullptr)); SSL_free(cli_ssl); SSL_free(serv_ssl); @@ -584,7 +584,7 @@ TEST_F(SSLTest, ssl_perf) { void* tls13_do_handshake(void* arg) { SSL* ssl = (SSL*)arg; EXPECT_EQ(1, SSL_do_handshake(ssl)); - return NULL; + return nullptr; } TEST_F(SSLTest, tls13_protocol_string) { @@ -592,9 +592,9 @@ TEST_F(SSLTest, tls13_protocol_string) { const butil::EndPoint ep(butil::IP_ANY, 8613); butil::fd_guard listenfd(butil::tcp_listen(ep)); ASSERT_GT(listenfd, 0); - int clifd = tcp_connect(ep, NULL); + int clifd = tcp_connect(ep, nullptr); ASSERT_GT(clifd, 0); - int servfd = accept(listenfd, NULL, NULL); + int servfd = accept(listenfd, nullptr, nullptr); ASSERT_GT(servfd, 0); brpc::ChannelSSLOptions opt; @@ -603,7 +603,7 @@ TEST_F(SSLTest, tls13_protocol_string) { ASSERT_NE(nullptr, cli_ctx); SSL_CTX* serv_ctx = brpc::CreateServerSSLContext("cert1.crt", "cert1.key", - brpc::SSLOptions(), NULL, NULL); + brpc::SSLOptions(), nullptr, nullptr); ASSERT_NE(nullptr, serv_ctx); SSL* cli_ssl = brpc::CreateSSLSession(cli_ctx, 0, clifd, false); #if defined(SSL_CTRL_SET_TLSEXT_HOSTNAME) || defined(USE_MESALINK) @@ -614,13 +614,13 @@ TEST_F(SSLTest, tls13_protocol_string) { ASSERT_NE(nullptr, serv_ssl); pthread_t cpid; pthread_t spid; - ASSERT_EQ(0, pthread_create(&cpid, NULL, tls13_do_handshake, cli_ssl)); - ASSERT_EQ(0, pthread_create(&spid, NULL, tls13_do_handshake, serv_ssl)); - ASSERT_EQ(0, pthread_join(cpid, NULL)); - ASSERT_EQ(0, pthread_join(spid, NULL)); + ASSERT_EQ(0, pthread_create(&cpid, nullptr, tls13_do_handshake, cli_ssl)); + ASSERT_EQ(0, pthread_create(&spid, nullptr, tls13_do_handshake, serv_ssl)); + ASSERT_EQ(0, pthread_join(cpid, nullptr)); + ASSERT_EQ(0, pthread_join(spid, nullptr)); const char* version = SSL_get_version(cli_ssl); - ASSERT_TRUE(version != NULL); + ASSERT_TRUE(version != nullptr); EXPECT_STREQ("TLSv1.3", version) << "negotiated protocol=" << version; SSL_free(cli_ssl); @@ -637,7 +637,7 @@ TEST_F(SSLTest, tls13_protocol_string) { brpc::ChannelSSLOptions opt; opt.protocols = "TLSv1.3"; SSL_CTX* ctx = brpc::CreateClientSSLContext(opt); - ASSERT_TRUE(ctx != NULL); + ASSERT_TRUE(ctx != nullptr); SSL_CTX_free(ctx); } diff --git a/test/brpc_streaming_rpc_unittest.cpp b/test/brpc_streaming_rpc_unittest.cpp index a759bae560..46401d6db0 100644 --- a/test/brpc_streaming_rpc_unittest.cpp +++ b/test/brpc_streaming_rpc_unittest.cpp @@ -41,7 +41,7 @@ class MyServiceWithStream : public test::EchoService { public: MyServiceWithStream(const brpc::StreamOptions& options) : _options(options) - , _after_accept_stream(NULL) + , _after_accept_stream(nullptr) {} MyServiceWithStream(const brpc::StreamOptions& options, AfterAcceptStream* after_accept_stream) @@ -50,7 +50,7 @@ class MyServiceWithStream : public test::EchoService { {} MyServiceWithStream() : _options() - , _after_accept_stream(NULL) + , _after_accept_stream(nullptr) {} void Echo(::google::protobuf::RpcController* controller, @@ -150,7 +150,7 @@ static void* SendTwoMessagesOnServerExtraStream(void* arg) { // the remote settings are ready. Check the acquire flag first // before reading the non-atomic host pointer. if (s->_connected.load(butil::memory_order_acquire) && - s->_host_socket != NULL) { + s->_host_socket != nullptr) { connected = true; break; } @@ -162,7 +162,7 @@ static void* SendTwoMessagesOnServerExtraStream(void* arg) { state->server_first_write_rc.store(ETIMEDOUT, std::memory_order_relaxed); state->server_second_write_rc.store(ETIMEDOUT, std::memory_order_relaxed); state->server_write_done.store(true, std::memory_order_release); - return NULL; + return nullptr; } // 1) Send a payload exactly equal to max_buf_size(64). @@ -192,7 +192,7 @@ static void* SendTwoMessagesOnServerExtraStream(void* arg) { } state->server_second_write_rc.store(rc, std::memory_order_relaxed); state->server_write_done.store(true, std::memory_order_release); - return NULL; + return nullptr; } class MyServiceWithBatchStream : public test::EchoService { @@ -249,15 +249,15 @@ TEST_F(StreamingRpcTest, sanity) { brpc::Server server; MyServiceWithStream service; ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; - ASSERT_EQ(0, StreamCreate(&request_stream, cntl, NULL)); + ASSERT_EQ(0, StreamCreate(&request_stream, cntl, nullptr)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; usleep(10); brpc::StreamClose(request_stream); @@ -276,10 +276,10 @@ TEST_F(StreamingRpcTest, batch_create_stream_feedback_race) { brpc::Server server; MyServiceWithBatchStream service(server_stream_opt, &state); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamIds request_streams; @@ -302,7 +302,7 @@ TEST_F(StreamingRpcTest, batch_create_stream_feedback_race) { } if (state.server_send_tid) { - bthread_join(state.server_send_tid, NULL); + bthread_join(state.server_send_tid, nullptr); } server.Stop(0); server.Join(); @@ -347,7 +347,7 @@ struct HandlerControl { class OrderedInputHandler : public brpc::StreamInputHandler { public: - explicit OrderedInputHandler(HandlerControl *cntl = NULL) + explicit OrderedInputHandler(HandlerControl *cntl = nullptr) : _expected_next_value(0) , _failed(false) , _stopped(false) @@ -407,9 +407,9 @@ TEST_F(StreamingRpcTest, received_in_order) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; @@ -417,7 +417,7 @@ TEST_F(StreamingRpcTest, received_in_order) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; const int N = 10000; for (int i = 0; i < N; ++i) { @@ -455,9 +455,9 @@ TEST_F(StreamingRpcTest, block) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::ScopedStream stream_guard(request_stream); @@ -465,7 +465,7 @@ TEST_F(StreamingRpcTest, block) { request_stream_options.max_buf_size = sizeof(uint32_t) * N; ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; for (int i = 0; i < N; ++i) { @@ -488,7 +488,7 @@ TEST_F(StreamingRpcTest, block) { hc.block = true; // async wait for (int i = N; i < N + N; ++i) { - ASSERT_EQ(0, brpc::StreamWait(request_stream, NULL)); + ASSERT_EQ(0, brpc::StreamWait(request_stream, nullptr)); int network = htonl(i); butil::IOBuf out; out.append(&network, sizeof(network)); @@ -500,7 +500,7 @@ TEST_F(StreamingRpcTest, block) { hc.block = false; std::pair p = std::make_pair(false, 0); usleep(10); - brpc::StreamWait(request_stream, NULL, on_writable, &p); + brpc::StreamWait(request_stream, nullptr, on_writable, &p); while (!p.first) { usleep(100); } @@ -554,9 +554,9 @@ TEST_F(StreamingRpcTest, auto_close_if_host_socket_closed) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; @@ -564,7 +564,7 @@ TEST_F(StreamingRpcTest, auto_close_if_host_socket_closed) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; { @@ -573,7 +573,7 @@ TEST_F(StreamingRpcTest, auto_close_if_host_socket_closed) { brpc::Stream* s = ptr.get(); ASSERT_TRUE(s->_connected.load(butil::memory_order_acquire)); brpc::Socket* host_socket = s->_host_socket; - ASSERT_TRUE(host_socket != NULL); + ASSERT_TRUE(host_socket != nullptr); host_socket->SetFailed(); } @@ -597,9 +597,9 @@ TEST_F(StreamingRpcTest, failed_when_rst) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; @@ -607,7 +607,7 @@ TEST_F(StreamingRpcTest, failed_when_rst) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; const int N = 10000; for (int i = 0; i < N; ++i) { @@ -625,7 +625,7 @@ TEST_F(StreamingRpcTest, failed_when_rst) { ASSERT_EQ(0, brpc::Stream::Address(request_stream, &ptr)); brpc::Stream* s = ptr.get(); ASSERT_TRUE(s->_connected.load(butil::memory_order_acquire)); - ASSERT_TRUE(s->_host_socket != NULL); + ASSERT_TRUE(s->_host_socket != nullptr); brpc::policy::SendStreamRst(s->_host_socket, s->_remote_settings.stream_id()); } @@ -652,9 +652,9 @@ TEST_F(StreamingRpcTest, idle_timeout) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; @@ -662,7 +662,7 @@ TEST_F(StreamingRpcTest, idle_timeout) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; usleep(10 * 1000 + 800); ASSERT_EQ(0, brpc::StreamClose(request_stream)); @@ -741,9 +741,9 @@ TEST_F(StreamingRpcTest, ping_pong) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; @@ -754,7 +754,7 @@ TEST_F(StreamingRpcTest, ping_pong) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; int send = 0; butil::IOBuf out; @@ -795,9 +795,9 @@ TEST_F(StreamingRpcTest, server_send_data_before_run_done) { brpc::Server server; MyServiceWithStream service(opt, &after_accept); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); OrderedInputHandler handler; brpc::StreamOptions request_stream_options; request_stream_options.handler = &handler; @@ -806,7 +806,7 @@ TEST_F(StreamingRpcTest, server_send_data_before_run_done) { ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; // wait flushing all the pending messages while (handler._expected_next_value != N) { @@ -829,16 +829,16 @@ TEST_F(StreamingRpcTest, segment_stream_data_automatically) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; brpc::StreamOptions request_stream_options; ASSERT_EQ(0, StreamCreate(&request_stream, cntl, &request_stream_options)); brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText() << " request_stream=" << request_stream; const int N = 1000; for (int i = 0; i < N; ++i) { @@ -854,7 +854,7 @@ TEST_F(StreamingRpcTest, segment_stream_data_automatically) { ASSERT_EQ(0, brpc::Stream::Address(request_stream, &ptr)); ASSERT_TRUE(ptr->_connected.load(butil::memory_order_acquire)); brpc::Socket* host_socket = ptr->_host_socket; - ASSERT_TRUE(host_socket != NULL); + ASSERT_TRUE(host_socket != nullptr); host_socket->ReAddress(&host_socket_ptr); } @@ -884,11 +884,11 @@ TEST_F(StreamingRpcTest, create_request_stream_twice_on_same_controller_returns_ brpc::Controller cntl; brpc::StreamId first_stream = brpc::INVALID_STREAM_ID; - ASSERT_EQ(0, brpc::StreamCreate(&first_stream, cntl, NULL)); + ASSERT_EQ(0, brpc::StreamCreate(&first_stream, cntl, nullptr)); brpc::ScopedStream stream_guard(first_stream); brpc::StreamId second_stream = brpc::INVALID_STREAM_ID; - ASSERT_EQ(-1, brpc::StreamCreate(&second_stream, cntl, NULL)); + ASSERT_EQ(-1, brpc::StreamCreate(&second_stream, cntl, nullptr)); ASSERT_EQ(brpc::INVALID_STREAM_ID, second_stream); } @@ -1020,10 +1020,10 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream) { brpc::Server server; MyServiceWithExtraStream service(server_stream_opt, STREAM_COUNT, N); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamOptions client_stream_opt; @@ -1034,7 +1034,7 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream) { ASSERT_EQ(STREAM_COUNT, request_streams.size()); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); // Every stream, including the extra streams, must end up connected with a valid host_socket. @@ -1046,7 +1046,7 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream) { return false; } brpc::Stream* s = ptr.get(); - return s->_host_socket != NULL && + return s->_host_socket != nullptr && s->_connected.load(butil::memory_order_acquire); }, 5000)) << "stream_index=" << i; } @@ -1101,10 +1101,10 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream_upstream_only) { // n = 0: server never sends downstream data on any accepted stream. MyServiceWithExtraStream service(server_stream_opt, STREAM_COUNT, 0); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; // No downstream handler is needed on the client side. @@ -1116,7 +1116,7 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream_upstream_only) { ASSERT_EQ(STREAM_COUNT, request_streams.size()); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); // Without any downstream data, extra streams have no chance to get their @@ -1131,7 +1131,7 @@ TEST_F(StreamingRpcTest, batch_create_extra_stream_upstream_only) { return false; } brpc::Stream* s = ptr.get(); - return s->_host_socket != NULL && + return s->_host_socket != nullptr && s->_connected.load(butil::memory_order_acquire); }, 5000)) << "stream_index=" << i; } @@ -1198,10 +1198,10 @@ TEST_F(StreamingRpcTest, unconsumed_bytes_reclaimed_on_stream_close) { brpc::Server server; MyServiceWithStream service(opt); ASSERT_EQ(0, server.AddService(&service, brpc::SERVER_DOESNT_OWN_SERVICE)); - ASSERT_EQ(0, server.Start(9007, NULL)); + ASSERT_EQ(0, server.Start(9007, nullptr)); brpc::Channel channel; - ASSERT_EQ(0, channel.Init("127.0.0.1:9007", NULL)); + ASSERT_EQ(0, channel.Init("127.0.0.1:9007", nullptr)); brpc::Controller cntl; brpc::StreamId request_stream; @@ -1211,7 +1211,7 @@ TEST_F(StreamingRpcTest, unconsumed_bytes_reclaimed_on_stream_close) { brpc::ScopedStream stream_guard(request_stream); test::EchoService_Stub stub(&channel); - stub.Echo(&cntl, &request, &response, NULL); + stub.Echo(&cntl, &request, &response, nullptr); ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); brpc::SocketUniquePtr host_socket; @@ -1219,7 +1219,7 @@ TEST_F(StreamingRpcTest, unconsumed_bytes_reclaimed_on_stream_close) { brpc::StreamUniquePtr ptr; ASSERT_EQ(0, brpc::Stream::Address(request_stream, &ptr)); ASSERT_TRUE(ptr->_connected.load(butil::memory_order_acquire)); - ASSERT_TRUE(ptr->_host_socket != NULL); + ASSERT_TRUE(ptr->_host_socket != nullptr); ptr->_host_socket->ReAddress(&host_socket); } int64_t baseline = host_socket->_total_streams_unconsumed_size.load( diff --git a/test/brpc_ubring_unittest.cpp b/test/brpc_ubring_unittest.cpp index 4340e7a060..14b2ef1b71 100644 --- a/test/brpc_ubring_unittest.cpp +++ b/test/brpc_ubring_unittest.cpp @@ -182,14 +182,14 @@ TEST_F(UBShmEndpointTest, construct_initial_state) { TEST_F(UBShmEndpointTest, allocate_client_resources_real_shm) { brpc::ubring::SHM local_trx_shm = - {NULL, 4 * 1024 * 1024, 0, {0}, (uint32_t)_socket->fd()}; + {nullptr, 4 * 1024 * 1024, 0, {0}, (uint32_t)_socket->fd()}; int ret = _ep->AllocateClientResources(&local_trx_shm, "UBRING_ut_client"); EXPECT_EQ(0, ret); } TEST_F(UBShmEndpointTest, reset_cleans_up_resources) { brpc::ubring::SHM local_trx_shm = - {NULL, 4 * 1024 * 1024, 0, {0}, (uint32_t)_socket->fd()}; + {nullptr, 4 * 1024 * 1024, 0, {0}, (uint32_t)_socket->fd()}; _ep->AllocateClientResources(&local_trx_shm, "UBRING_ut_reset"); _ep->Reset(); } diff --git a/test/bthread_butex_unittest.cpp b/test/bthread_butex_unittest.cpp index 8f2f4f5f3f..730eac7b4e 100644 --- a/test/bthread_butex_unittest.cpp +++ b/test/bthread_butex_unittest.cpp @@ -47,13 +47,13 @@ TEST(ButexTest, wait_on_already_timedout_butex) { void* sleeper(void* arg) { bthread_usleep((uint64_t)arg); - return NULL; + return nullptr; } void* joiner(void* arg) { const long t1 = butil::gettimeofday_us(); for (bthread_t* th = (bthread_t*)arg; *th; ++th) { - if (0 != bthread_join(*th, NULL)) { + if (0 != bthread_join(*th, nullptr)) { LOG(FATAL) << "fail to join thread_" << th - (bthread_t*)arg; } long elp = butil::gettimeofday_us() - t1; @@ -63,9 +63,9 @@ void* joiner(void* arg) { << bthread_self() << "]"; } for (bthread_t* th = (bthread_t*)arg; *th; ++th) { - EXPECT_EQ(0, bthread_join(*th, NULL)); + EXPECT_EQ(0, bthread_join(*th, nullptr)); } - return NULL; + return nullptr; } struct A { @@ -97,18 +97,18 @@ TEST(ButexTest, join) { } th[N] = 0; // joiner will join tids in `th' until seeing 0. for (size_t i = 0; i < M; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&jth[i], NULL, joiner, th)); + ASSERT_EQ(0, bthread_start_urgent(&jth[i], nullptr, joiner, th)); } for (size_t i = 0; i < M; ++i) { - ASSERT_EQ(0, pthread_create(&pth[i], NULL, joiner, th)); + ASSERT_EQ(0, pthread_create(&pth[i], nullptr, joiner, th)); } for (size_t i = 0; i < M; ++i) { - ASSERT_EQ(0, bthread_join(jth[i], NULL)) + ASSERT_EQ(0, bthread_join(jth[i], nullptr)) << "i=" << i << " error=" << berror(); } for (size_t i = 0; i < M; ++i) { - ASSERT_EQ(0, pthread_join(pth[i], NULL)); + ASSERT_EQ(0, pthread_join(pth[i], nullptr)); } } @@ -132,7 +132,7 @@ void* waiter(void* arg) { EXPECT_EQ(wa->expected_result, errno) << bthread_self(); } LOG(INFO) << "after wait, time=" << (t2-t1) << "us"; - return NULL; + return nullptr; } TEST(ButexTest, sanity) { @@ -152,10 +152,10 @@ TEST(ButexTest, sanity) { unmatched_arg->expected_value = *b1 + 1; unmatched_arg->expected_result = EWOULDBLOCK; unmatched_arg->butex = b1; - unmatched_arg->ptimeout = NULL; - pthread_create(&t2, NULL, waiter, unmatched_arg); + unmatched_arg->ptimeout = nullptr; + pthread_create(&t2, nullptr, waiter, unmatched_arg); bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, waiter, unmatched_arg)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, waiter, unmatched_arg)); const timespec abstime = butil::seconds_from_now(1); for (size_t i = 0; i < 4*N; ++i) { @@ -163,15 +163,15 @@ TEST(ButexTest, sanity) { args[i].butex = b1; if ((i % 2) == 0) { args[i].expected_result = 0; - args[i].ptimeout = NULL; + args[i].ptimeout = nullptr; } else { args[i].expected_result = ETIMEDOUT; args[i].ptimeout = &abstime; } if (i < 2*N) { - pthread_create(&t1, NULL, waiter, &args[i]); + pthread_create(&t1, nullptr, waiter, &args[i]); } else { - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, waiter, &args[i])); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, waiter, &args[i])); } } @@ -203,7 +203,7 @@ void* wait_butex(void* void_arg) { } else { EXPECT_EQ(0, rc); } - return NULL; + return nullptr; } TEST(ButexTest, wait_without_stop) { @@ -219,7 +219,7 @@ TEST(ButexTest, wait_without_stop) { tm.start(); ASSERT_EQ(0, bthread_start_urgent(&th, &attr, wait_butex, &arg)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); ASSERT_LT(labs(tm.m_elapsed() - WAIT_MSEC), 250); @@ -243,7 +243,7 @@ TEST(ButexTest, stop_after_running) { ASSERT_EQ(0, bthread_start_urgent(&th, &attr, wait_butex, &arg)); ASSERT_EQ(0, bthread_usleep(SLEEP_MSEC * 1000L)); ASSERT_EQ(0, bthread_stop(th)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); ASSERT_LT(labs(tm.m_elapsed() - SLEEP_MSEC), 25); @@ -270,7 +270,7 @@ TEST(ButexTest, stop_before_running) { ASSERT_EQ(0, bthread_start_background(&th, &attr, wait_butex, &arg)); ASSERT_EQ(0, bthread_stop(th)); bthread_flush(); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); ASSERT_LT(tm.m_elapsed(), 5); @@ -282,8 +282,8 @@ TEST(ButexTest, stop_before_running) { } void* join_the_waiter(void* arg) { - EXPECT_EQ(0, bthread_join((bthread_t)arg, NULL)); - return NULL; + EXPECT_EQ(0, bthread_join((bthread_t)arg, nullptr)); + return nullptr; } TEST(ButexTest, join_cant_be_wakeup) { @@ -298,7 +298,7 @@ TEST(ButexTest, join_cant_be_wakeup) { (i == 0 ? BTHREAD_ATTR_PTHREAD : BTHREAD_ATTR_NORMAL); tm.start(); bthread_t th, th2; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, wait_butex, &arg)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, wait_butex, &arg)); ASSERT_EQ(0, bthread_start_urgent(&th2, &attr, join_the_waiter, (void*)th)); ASSERT_EQ(0, bthread_stop(th2)); ASSERT_EQ(0, bthread_usleep(WAIT_MSEC / 2 * 1000L)); @@ -306,8 +306,8 @@ TEST(ButexTest, join_cant_be_wakeup) { ASSERT_TRUE(bthread::TaskGroup::exists(th2)); ASSERT_EQ(0, bthread_usleep(WAIT_MSEC / 2 * 1000L)); ASSERT_EQ(0, bthread_stop(th)); - ASSERT_EQ(0, bthread_join(th2, NULL)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th2, nullptr)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); ASSERT_LT(tm.m_elapsed(), WAIT_MSEC + 15); ASSERT_EQ(EINVAL, bthread_stop(th)); @@ -330,7 +330,7 @@ TEST(ButexTest, stop_after_slept) { &th, &attr, sleeper, (void*)(SLEEP_MSEC*1000L))); ASSERT_EQ(0, bthread_usleep(WAIT_MSEC * 1000L)); ASSERT_EQ(0, bthread_stop(th)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); if (attr.stack_type == BTHREAD_STACKTYPE_PTHREAD) { ASSERT_LT(labs(tm.m_elapsed() - SLEEP_MSEC), 15); @@ -355,7 +355,7 @@ TEST(ButexTest, stop_just_when_sleeping) { ASSERT_EQ(0, bthread_start_urgent( &th, &attr, sleeper, (void*)(SLEEP_MSEC*1000L))); ASSERT_EQ(0, bthread_stop(th)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); if (attr.stack_type == BTHREAD_STACKTYPE_PTHREAD) { ASSERT_LT(labs(tm.m_elapsed() - SLEEP_MSEC), 15); @@ -382,7 +382,7 @@ TEST(ButexTest, stop_before_sleeping) { (void*)(SLEEP_MSEC*1000L))); ASSERT_EQ(0, bthread_stop(th)); bthread_flush(); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); if (attr.stack_type == BTHREAD_STACKTYPE_PTHREAD) { @@ -408,7 +408,7 @@ void* trigger_signal(void* arg) { } const long t2 = butil::gettimeofday_us(); LOG(INFO) << "trigger signal thread end, elapsed=" << (t2-t1) << "us"; - return NULL; + return nullptr; } TEST(ButexTest, wait_with_signal_triggered) { @@ -429,17 +429,17 @@ TEST(ButexTest, wait_with_signal_triggered) { waiter_args.expected_result = ETIMEDOUT; waiter_args.ptimeout = &abstime; tm.start(); - pthread_create(&waiter_th, NULL, waiter, &waiter_args); - pthread_create(&tigger_th, NULL, trigger_signal, &waiter_th); + pthread_create(&waiter_th, nullptr, waiter, &waiter_args); + pthread_create(&tigger_th, nullptr, trigger_signal, &waiter_th); - ASSERT_EQ(0, pthread_join(waiter_th, NULL)); + ASSERT_EQ(0, pthread_join(waiter_th, nullptr)); tm.stop(); auto wait_elapsed_ms = tm.m_elapsed();; LOG(INFO) << "waiter thread end, elapsed " << wait_elapsed_ms << " ms"; ASSERT_LT(labs(wait_elapsed_ms - WAIT_MSEC), 250); - ASSERT_EQ(0, pthread_join(tigger_th, NULL)); + ASSERT_EQ(0, pthread_join(tigger_th, nullptr)); bthread::butex_destroy(butex); } diff --git a/test/bthread_cond_bug_unittest.cpp b/test/bthread_cond_bug_unittest.cpp index 90881f5669..96b67e4064 100644 --- a/test/bthread_cond_bug_unittest.cpp +++ b/test/bthread_cond_bug_unittest.cpp @@ -123,10 +123,10 @@ void* consume_func(void* arg) { TEST(BthreadCondBugTest, test_bug) { bthread_t tids[PRODUCER_NUM]; for (int i = 0; i < PRODUCER_NUM; i++) { - bthread_start_background(&tids[i], NULL, produce_func, (void*)(int64_t)i); + bthread_start_background(&tids[i], nullptr, produce_func, (void*)(int64_t)i); } bthread_t tid; - bthread_start_background(&tid, NULL, consume_func, NULL); + bthread_start_background(&tid, nullptr, consume_func, nullptr); int64_t ret = (int64_t)print_func(nullptr); diff --git a/test/bthread_cond_unittest.cpp b/test/bthread_cond_unittest.cpp index f2dcddfe8c..85181691e5 100644 --- a/test/bthread_cond_unittest.cpp +++ b/test/bthread_cond_unittest.cpp @@ -46,7 +46,7 @@ void* signaler(void* void_arg) { bthread_usleep(SIGNAL_INTERVAL_US); bthread_cond_signal(&a->c); } - return NULL; + return nullptr; } void* waiter(void* void_arg) { @@ -60,13 +60,13 @@ void* waiter(void* void_arg) { wake_time.push_back(butil::gettimeofday_us()); } bthread_mutex_unlock(&a->m); - return NULL; + return nullptr; } TEST(CondTest, sanity) { Arg a; - ASSERT_EQ(0, bthread_mutex_init(&a.m, NULL)); - ASSERT_EQ(0, bthread_cond_init(&a.c, NULL)); + ASSERT_EQ(0, bthread_mutex_init(&a.m, nullptr)); + ASSERT_EQ(0, bthread_cond_init(&a.c, nullptr)); // has no effect ASSERT_EQ(0, bthread_cond_signal(&a.c)); @@ -79,11 +79,11 @@ TEST(CondTest, sanity) { bthread_t wth[8]; const size_t NW = ARRAY_SIZE(wth); for (size_t i = 0; i < NW; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&wth[i], NULL, waiter, &a)); + ASSERT_EQ(0, bthread_start_urgent(&wth[i], nullptr, waiter, &a)); } bthread_t sth; - ASSERT_EQ(0, bthread_start_urgent(&sth, NULL, signaler, &a)); + ASSERT_EQ(0, bthread_start_urgent(&sth, nullptr, signaler, &a)); bthread_usleep(SIGNAL_INTERVAL_US * 200); @@ -96,9 +96,9 @@ TEST(CondTest, sanity) { bthread_cond_signal(&a.c); } - bthread_join(sth, NULL); + bthread_join(sth, nullptr); for (size_t i = 0; i < NW; ++i) { - bthread_join(wth[i], NULL); + bthread_join(wth[i], nullptr); } printf("wake up for %lu times\n", wake_tid.size()); @@ -150,7 +150,7 @@ void* cv_signaler(void* void_arg) { bthread_usleep(SIGNAL_INTERVAL_US); a->cond.notify_one(); } - return NULL; + return nullptr; } void* cv_bmutex_waiter(void* void_arg) { @@ -159,7 +159,7 @@ void* cv_bmutex_waiter(void* void_arg) { while (!stop) { a->cond.wait(lck); } - return NULL; + return nullptr; } void* cv_mutex_waiter(void* void_arg) { @@ -168,7 +168,7 @@ void* cv_mutex_waiter(void* void_arg) { while (!stop) { a->cond.wait(lck); } - return NULL; + return nullptr; } @@ -177,7 +177,7 @@ void* cv_bmutex_waiter_with_pred(void* void_arg) { std::unique_lock lck(*a->mutex.native_handler()); a->cond.wait(lck, [&] { return a->ready; }); WrapperArg::wake_time.fetch_add(1); - return NULL; + return nullptr; } void* cv_mutex_waiter_with_pred(void* void_arg) { @@ -185,7 +185,7 @@ void* cv_mutex_waiter_with_pred(void* void_arg) { std::unique_lock lck(a->mutex); a->cond.wait(lck, [&] { return a->ready; }); WrapperArg::wake_time.fetch_add(1); - return NULL; + return nullptr; } #define COND_IN_PTHREAD @@ -203,22 +203,22 @@ TEST(CondTest, cpp_wrapper) { pthread_t signal_thread; WrapperArg a; for (size_t i = 0; i < ARRAY_SIZE(bmutex_waiter_threads); ++i) { - ASSERT_EQ(0, pthread_create(&bmutex_waiter_threads[i], NULL, + ASSERT_EQ(0, pthread_create(&bmutex_waiter_threads[i], nullptr, cv_bmutex_waiter, &a)); - ASSERT_EQ(0, pthread_create(&mutex_waiter_threads[i], NULL, + ASSERT_EQ(0, pthread_create(&mutex_waiter_threads[i], nullptr, cv_mutex_waiter, &a)); } - ASSERT_EQ(0, pthread_create(&signal_thread, NULL, cv_signaler, &a)); + ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, cv_signaler, &a)); bthread_usleep(100L * 1000); { BAIDU_SCOPED_LOCK(a.mutex); stop = true; } - pthread_join(signal_thread, NULL); + pthread_join(signal_thread, nullptr); a.cond.notify_all(); for (size_t i = 0; i < ARRAY_SIZE(bmutex_waiter_threads); ++i) { - pthread_join(bmutex_waiter_threads[i], NULL); - pthread_join(mutex_waiter_threads[i], NULL); + pthread_join(bmutex_waiter_threads[i], nullptr); + pthread_join(mutex_waiter_threads[i], nullptr); } } @@ -230,12 +230,12 @@ TEST(CondTest, cpp_wrapper2) { pthread_t signal_thread; WrapperArg a; for (size_t i = 0; i < ARRAY_SIZE(bmutex_waiter_threads); ++i) { - ASSERT_EQ(0, pthread_create(&bmutex_waiter_threads[i], NULL, + ASSERT_EQ(0, pthread_create(&bmutex_waiter_threads[i], nullptr, cv_bmutex_waiter_with_pred, &a)); - ASSERT_EQ(0, pthread_create(&mutex_waiter_threads[i], NULL, + ASSERT_EQ(0, pthread_create(&mutex_waiter_threads[i], nullptr, cv_mutex_waiter_with_pred, &a)); } - ASSERT_EQ(0, pthread_create(&signal_thread, NULL, cv_signaler, &a)); + ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, cv_signaler, &a)); bthread_usleep(100L * 1000); ASSERT_EQ(WrapperArg::wake_time, 0); { @@ -244,11 +244,11 @@ TEST(CondTest, cpp_wrapper2) { a.ready = true; } - pthread_join(signal_thread, NULL); + pthread_join(signal_thread, nullptr); a.cond.notify_all(); for (size_t i = 0; i < ARRAY_SIZE(bmutex_waiter_threads); ++i) { - pthread_join(bmutex_waiter_threads[i], NULL); - pthread_join(mutex_waiter_threads[i], NULL); + pthread_join(bmutex_waiter_threads[i], nullptr); + pthread_join(mutex_waiter_threads[i], nullptr); } ASSERT_EQ(WrapperArg::wake_time, 16); } @@ -305,7 +305,7 @@ void *ping_pong_thread(void* arg) { ++local_count; } a->total_count.fetch_add(local_count); - return NULL; + return nullptr; } TEST(CondTest, ping_pong) { @@ -315,14 +315,14 @@ TEST(CondTest, ping_pong) { bthread_t threads[2]; ProfilerStart("cond.prof"); for (int i = 0; i < 2; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&threads[i], NULL, ping_pong_thread, &arg)); + ASSERT_EQ(0, bthread_start_urgent(&threads[i], nullptr, ping_pong_thread, &arg)); } usleep(1000 * 1000); arg.stopped = true; arg.sig1.notify(); arg.sig2.notify(); for (int i = 0; i < 2; ++i) { - ASSERT_EQ(0, bthread_join(threads[i], NULL)); + ASSERT_EQ(0, bthread_join(threads[i], nullptr)); } ProfilerStop(); LOG(INFO) << "total_count=" << arg.total_count.load(); @@ -351,7 +351,7 @@ void* wait_thread(void* arg) { ba->wait_cond.wait(lck); } } - return NULL; + return nullptr; } void* broadcast_thread(void* arg) { @@ -366,7 +366,7 @@ void* broadcast_thread(void* arg) { --ba->rounds; ba->wait_cond.notify_all(); } - return NULL; + return nullptr; } void* disturb_thread(void* arg) { @@ -376,7 +376,7 @@ void* disturb_thread(void* arg) { lck.unlock(); lck.lock(); } - return NULL; + return nullptr; } TEST(CondTest, mixed_usage) { @@ -389,30 +389,30 @@ TEST(CondTest, mixed_usage) { bthread_t normal_threads[NTHREADS]; for (int i = 0; i < NTHREADS; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&normal_threads[i], NULL, wait_thread, &ba)); + ASSERT_EQ(0, bthread_start_urgent(&normal_threads[i], nullptr, wait_thread, &ba)); } pthread_t pthreads[NTHREADS]; for (int i = 0; i < NTHREADS; ++i) { - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, wait_thread, &ba)); } pthread_t broadcast; pthread_t disturb; - ASSERT_EQ(0, pthread_create(&broadcast, NULL, broadcast_thread, &ba)); - ASSERT_EQ(0, pthread_create(&disturb, NULL, disturb_thread, &ba)); + ASSERT_EQ(0, pthread_create(&broadcast, nullptr, broadcast_thread, &ba)); + ASSERT_EQ(0, pthread_create(&disturb, nullptr, disturb_thread, &ba)); for (int i = 0; i < NTHREADS; ++i) { - bthread_join(normal_threads[i], NULL); - pthread_join(pthreads[i], NULL); + bthread_join(normal_threads[i], nullptr); + pthread_join(pthreads[i], nullptr); } - pthread_join(broadcast, NULL); - pthread_join(disturb, NULL); + pthread_join(broadcast, nullptr); + pthread_join(disturb, nullptr); } class BthreadCond { public: BthreadCond() { - bthread_cond_init(&_cond, NULL); - bthread_mutex_init(&_mutex, NULL); + bthread_cond_init(&_cond, nullptr); + bthread_mutex_init(&_mutex, nullptr); _count = 1; } ~BthreadCond() { @@ -457,7 +457,7 @@ void* usleep_thread(void *) { while (!g_stop) { bthread_usleep(1000L * 1000L); } - return NULL; + return nullptr; } void* wait_cond_thread(void* arg) { @@ -465,7 +465,7 @@ void* wait_cond_thread(void* arg) { started_wait = true; c->Wait(); ended_wait = true; - return NULL; + return nullptr; } static void launch_many_bthreads() { @@ -480,7 +480,7 @@ static void launch_many_bthreads() { tm.start(); for (size_t i = 0; i < 32768; ++i) { bthread_t t0; - ASSERT_EQ(0, bthread_start_background(&t0, NULL, usleep_thread, NULL)); + ASSERT_EQ(0, bthread_start_background(&t0, nullptr, usleep_thread, nullptr)); tids.push_back(t0); } tm.stop(); @@ -488,10 +488,10 @@ static void launch_many_bthreads() { usleep(3 * 1000 * 1000L); c.Signal(); g_stop = true; - bthread_join(tid, NULL); + bthread_join(tid, nullptr); for (size_t i = 0; i < tids.size(); ++i) { LOG_EVERY_SECOND(INFO) << "Joined " << i << " threads"; - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } LOG_EVERY_SECOND(INFO) << "Joined " << tids.size() << " threads"; } @@ -503,14 +503,14 @@ TEST(CondTest, too_many_bthreads_from_pthread) { static void* run_launch_many_bthreads(void*) { launch_many_bthreads(); - return NULL; + return nullptr; } TEST(CondTest, too_many_bthreads_from_bthread) { bthread_setconcurrency(16); bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, run_launch_many_bthreads, NULL)); - bthread_join(th, NULL); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, run_launch_many_bthreads, nullptr)); + bthread_join(th, nullptr); } #endif // BUTIL_USE_ASAN } // namespace diff --git a/test/bthread_countdown_event_unittest.cpp b/test/bthread_countdown_event_unittest.cpp index bed8f17e37..f6fa5f1e3c 100644 --- a/test/bthread_countdown_event_unittest.cpp +++ b/test/bthread_countdown_event_unittest.cpp @@ -32,7 +32,7 @@ void *signaler(void *arg) { Arg* a = (Arg*)arg; a->num_sig.fetch_sub(1, butil::memory_order_relaxed); a->event.signal(); - return NULL; + return nullptr; } TEST(CountdonwEventTest, sanity) { @@ -43,14 +43,14 @@ TEST(CountdonwEventTest, sanity) { a.event.reset(n); for (int i = 0; i < n; ++i) { bthread_t tid; - ASSERT_EQ(0, bthread_start_urgent(&tid, NULL, signaler, &a)); + ASSERT_EQ(0, bthread_start_urgent(&tid, nullptr, signaler, &a)); tids.push_back(tid); } a.event.wait(); ASSERT_EQ(0, a.num_sig.load(butil::memory_order_relaxed)); } for (size_t i = 0; i < tids.size(); ++i) { - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } } diff --git a/test/bthread_dispatcher_unittest.cpp b/test/bthread_dispatcher_unittest.cpp index 411c392e62..0696df9aff 100644 --- a/test/bthread_dispatcher_unittest.cpp +++ b/test/bthread_dispatcher_unittest.cpp @@ -86,11 +86,11 @@ void* process_thread(void* arg) { continue; } else { PLOG(FATAL) << "Fail to read fd=" << m->fd; - return NULL; + return nullptr; } } else { LOG(FATAL) << "Another end closed fd=" << m->fd; - return NULL; + return nullptr; } } while (1); @@ -103,7 +103,7 @@ void* process_thread(void* arg) { break; } } while (1); - return NULL; + return nullptr; } void* epoll_thread(void* arg) { @@ -126,7 +126,7 @@ void* epoll_thread(void* arg) { } #elif defined(OS_MACOSX) timespec ts = { 0, 100L * 1000L * 1000L }; - const int n = kevent(em->epfd, NULL, 0, e, ARRAY_SIZE(e), &ts); + const int n = kevent(em->epfd, nullptr, 0, e, ARRAY_SIZE(e), &ts); if (n == 0) { continue; } @@ -162,7 +162,7 @@ void* epoll_thread(void* arg) { } } } - return NULL; + return nullptr; } void* client_thread(void* arg) { @@ -190,7 +190,7 @@ void* client_thread(void* arg) { if (n < 0) { if (errno != EINTR) { PLOG(FATAL) << "Fail to write fd=" << m->fd; - return NULL; + return nullptr; } } else { ++m->times; @@ -202,7 +202,7 @@ void* client_thread(void* arg) { } } free(buf); - return NULL; + return nullptr; } inline uint32_t fmix32 ( uint32_t h ) { @@ -257,14 +257,14 @@ TEST(DispatcherTest, dispatch_tasks) { #elif defined(OS_MACOSX) struct kevent kqueue_event; EV_SET(&kqueue_event, m->fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, m); - ASSERT_EQ(0, kevent(m->epfd, &kqueue_event, 1, NULL, 0, NULL)); + ASSERT_EQ(0, kevent(m->epfd, &kqueue_event, 1, nullptr, 0, nullptr)); #endif cm[i] = new ClientMeta; cm[i]->fd = fds[i * 2 + 1]; cm[i]->times = 0; cm[i]->bytes = 0; - ASSERT_EQ(0, pthread_create(&cth[i], NULL, client_thread, cm[i])); + ASSERT_EQ(0, pthread_create(&cth[i], nullptr, client_thread, cm[i])); } ProfilerStart("dispatcher.prof"); @@ -276,9 +276,9 @@ TEST(DispatcherTest, dispatch_tasks) { em[i] = m; m->epfd = epfd[i]; #ifdef RUN_EPOLL_IN_BTHREAD - ASSERT_EQ(0, bthread_start_background(ð[i], NULL, epoll_thread, m)); + ASSERT_EQ(0, bthread_start_background(ð[i], nullptr, epoll_thread, m)); #else - ASSERT_EQ(0, pthread_create(ð[i], NULL, epoll_thread, m)); + ASSERT_EQ(0, pthread_create(ð[i], nullptr, epoll_thread, m)); #endif } @@ -304,16 +304,16 @@ TEST(DispatcherTest, dispatch_tasks) { client_stop = true; for (size_t i = 0; i < NCLIENT; ++i) { - pthread_join(cth[i], NULL); + pthread_join(cth[i], nullptr); } server_stop = true; // epoll_thread polls server_stop with a finite timeout, so it exits on its // own without needing an external fd to wake up epoll_wait. for (size_t i = 0; i < NEPOLL; ++i) { #ifdef RUN_EPOLL_IN_BTHREAD - bthread_join(eth[i], NULL); + bthread_join(eth[i], nullptr); #else - pthread_join(eth[i], NULL); + pthread_join(eth[i], nullptr); #endif } bthread::stop_and_join_epoll_threads(); diff --git a/test/bthread_execution_queue_unittest.cpp b/test/bthread_execution_queue_unittest.cpp index 1baaa77761..2e19a7b2fe 100644 --- a/test/bthread_execution_queue_unittest.cpp +++ b/test/bthread_execution_queue_unittest.cpp @@ -37,12 +37,12 @@ struct LongIntTask { long value; bthread::CountdownEvent* event; LongIntTask(long v) - : value(v), event(NULL) + : value(v), event(nullptr) {} LongIntTask(long v, bthread::CountdownEvent* e) : value(v), event(e) {} - LongIntTask() : value(0), event(NULL) {} + LongIntTask() : value(0), event(nullptr) {} }; int add(void* meta, bthread::TaskIterator &iter) { @@ -166,7 +166,7 @@ void* push_thread(void *arg) { timer.start(); int num = 0; bthread::CountdownEvent e; - LongIntTask t(num, pa->wait_task_completed ? &e : NULL); + LongIntTask t(num, pa->wait_task_completed ? &e : nullptr); if (pa->wait_task_completed) { e.reset(1); } @@ -182,7 +182,7 @@ void* push_thread(void *arg) { pa->expected_value.fetch_add(sum, butil::memory_order_relaxed); pa->total_num.fetch_add(num); pa->total_time.fetch_add(timer.n_elapsed()); - return NULL; + return nullptr; } void* push_thread_which_addresses_execq(void *arg) { @@ -203,7 +203,7 @@ void* push_thread_which_addresses_execq(void *arg) { pa->expected_value.fetch_add(sum, butil::memory_order_relaxed); pa->total_num.fetch_add(num); pa->total_time.fetch_add(timer.n_elapsed()); - return NULL; + return nullptr; } void test_performance(bool use_pthread) { @@ -227,12 +227,12 @@ void test_performance(bool use_pthread) { pa.stopped = false; ProfilerStart("execq.prof"); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &push_thread_which_addresses_execq, &pa); + pthread_create(&threads[i], nullptr, &push_thread_which_addresses_execq, &pa); } usleep(500 * 1000); ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } ProfilerStop(); ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -253,12 +253,12 @@ void test_performance(bool use_pthread) { pa.stopped = false; ProfilerStart("execq_id.prof"); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &push_thread, &pa); + pthread_create(&threads[i], nullptr, &push_thread, &pa); } usleep(500 * 1000); ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } ProfilerStop(); ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -335,7 +335,7 @@ void test_execute_urgent(bool use_pthread) { pa.stopped = false; pa.wait_task_completed = true; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &push_thread, &pa); + pthread_create(&threads[i], nullptr, &push_thread, &pa); } g_suspending = false; usleep(1000); @@ -354,7 +354,7 @@ void test_execute_urgent(bool use_pthread) { pa.stopped = true; ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } LOG(INFO) << "result=" << result; ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -419,7 +419,7 @@ void* push_thread_with_id(void* arg) { for (int i = 0; i < 100000; ++i) { bthread::execution_queue_execute(id, ((long)thread_id << 32) | i); } - return NULL; + return nullptr; } int check_order(void* meta, bthread::TaskIterator& iter) { @@ -451,10 +451,10 @@ void test_multi_threaded_order(bool use_pthread) { check_order, &disorder_times)); pthread_t threads[12]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &push_thread_with_id, (void *)queue_id.value); + pthread_create(&threads[i], nullptr, &push_thread_with_id, (void *)queue_id.value); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -513,7 +513,7 @@ void *run_first_tasks(void* arg) { task.thread_id = pthread_self(); EXPECT_EQ(0, bthread::execution_queue_execute( queue_id, task, &bthread::TASK_OPTIONS_INPLACE)); - return NULL; + return nullptr; } int stuck_and_check_running_thread(void* arg, bthread::TaskIterator& iter) { @@ -526,7 +526,7 @@ int stuck_and_check_running_thread(void* arg, bthread::TaskIterator futex->store(1); bthread::futex_wake_private(futex, 1); while (futex->load() != 2) { - bthread::futex_wait_private(futex, 1, NULL); + bthread::futex_wait_private(futex, 1, nullptr); } ++iter; EXPECT_FALSE(iter); @@ -553,9 +553,9 @@ void test_should_start_new_thread_on_more_tasks(bool use_pthread) { stuck_and_check_running_thread, (void*)&futex)); pthread_t thread; - ASSERT_EQ(0, pthread_create(&thread, NULL, run_first_tasks, (void*)queue_id.value)); + ASSERT_EQ(0, pthread_create(&thread, nullptr, run_first_tasks, (void*)queue_id.value)); while (futex.load() != 1) { - bthread::futex_wait_private(&futex, 0, NULL); + bthread::futex_wait_private(&futex, 0, nullptr); } for (size_t i = 0; i < 100; ++i) { InPlaceTask task; @@ -584,7 +584,7 @@ void* inplace_push_thread(void* arg) { bthread::execution_queue_execute(id, ((long)thread_id << 32) | i, &bthread::TASK_OPTIONS_INPLACE); } - return NULL; + return nullptr; } void test_inplace_and_order(bool use_pthread) { @@ -602,10 +602,10 @@ void test_inplace_and_order(bool use_pthread) { check_order, &disorder_times)); pthread_t threads[12]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &inplace_push_thread, (void *)queue_id.value); + pthread_create(&threads[i], nullptr, &inplace_push_thread, (void *)queue_id.value); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -657,14 +657,14 @@ void test_cancel(bool use_pthread) { add_with_suspend2, &result)); g_suspending = false; bthread::TaskHandle handle0; - ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, -100, NULL, &handle0)); + ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, -100, nullptr, &handle0)); while (!g_suspending) { usleep(10); } ASSERT_EQ(1, bthread::execution_queue_cancel(handle0)); ASSERT_EQ(1, bthread::execution_queue_cancel(handle0)); bthread::TaskHandle handle1; - ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, 100, NULL, &handle1)); + ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, 100, nullptr, &handle1)); ASSERT_EQ(0, bthread::execution_queue_cancel(handle1)); g_suspending = false; ASSERT_EQ(-1, bthread::execution_queue_cancel(handle1)); @@ -686,7 +686,7 @@ struct CancelSelf { int cancel_self(void* /*meta*/, bthread::TaskIterator& iter) { for (; iter; ++iter) { - while ((*iter)->handle == NULL) { + while ((*iter)->handle == nullptr) { usleep(10); } EXPECT_EQ(1, bthread::execution_queue_cancel(*(*iter)->handle.load())); @@ -706,11 +706,11 @@ void test_cancel_self(bool use_pthread) { LOG(INFO) << "================ bthread ================"; } ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, - cancel_self, NULL)); + cancel_self, nullptr)); CancelSelf task; - task.handle = NULL; + task.handle = nullptr; bthread::TaskHandle handle; - ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, &task, NULL, &handle)); + ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, &task, nullptr, &handle)); task.handle.store(&handle); ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); @@ -768,7 +768,7 @@ void test_random_cancel(bool use_pthread) { m.succ_times.store(0); m.fail_times.store(0); m.race_times.store(0); - ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, NULL, + ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, nullptr, add_with_cancel, &m)); int64_t expected = 0; for (int i = 0; i < 100000; ++i) { @@ -776,7 +776,7 @@ void test_random_cancel(bool use_pthread) { AddTask t; t.value = i; t.cancel_task = false; - ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, t, NULL, &h)); + ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, t, nullptr, &h)); const int r = butil::fast_rand_less_than(4); expected += i; if (r == 0) { @@ -787,7 +787,7 @@ void test_random_cancel(bool use_pthread) { t.cancel_task = true; t.cancel_value = i; t.handle = h; - ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, t, NULL)); + ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, t, nullptr)); } else if (r == 2) { t.cancel_task = true; t.cancel_value = i; diff --git a/test/bthread_fd_unittest.cpp b/test/bthread_fd_unittest.cpp index 1f68ffc4bf..02c579c168 100644 --- a/test/bthread_fd_unittest.cpp +++ b/test/bthread_fd_unittest.cpp @@ -92,13 +92,13 @@ void* process_thread(void* arg) { ssize_t n = read(m->fd, &count, sizeof(count)); if (n != sizeof(count)) { LOG(FATAL) << "Should not happen in this test"; - return NULL; + return nullptr; } count += NCLIENT; //printf("write result=%lu to fd=%d\n", count, m->fd); if (write(m->fd, &count, sizeof(count)) != sizeof(count)) { LOG(FATAL) << "Should not happen in this test"; - return NULL; + return nullptr; } #ifdef CREATE_THREAD_TO_PROCESS # if defined(OS_LINUX) @@ -110,10 +110,10 @@ void* process_thread(void* arg) { struct kevent kqueue_event; EV_SET(&kqueue_event, m->fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, m); - kevent(m->epfd, &kqueue_event, 1, NULL, 0, NULL); + kevent(m->epfd, &kqueue_event, 1, nullptr, 0, nullptr); # endif #endif - return NULL; + return nullptr; } void* epoll_thread(void* arg) { @@ -148,7 +148,7 @@ void* epoll_thread(void* arg) { } # endif #elif defined(OS_MACOSX) - const int n = kevent(epfd, NULL, 0, e, ARRAY_SIZE(e), NULL); + const int n = kevent(epfd, nullptr, 0, e, ARRAY_SIZE(e), nullptr); if (stop) { break; } @@ -190,7 +190,7 @@ void* epoll_thread(void* arg) { } #endif } - return NULL; + return nullptr; } void* client_thread(void* arg) { @@ -198,7 +198,7 @@ void* client_thread(void* arg) { for (size_t i = 0; i < m->times; ++i) { if (write(m->fd, &m->count, sizeof(m->count)) != sizeof(m->count)) { LOG(FATAL) << "Should not happen in this test"; - return NULL; + return nullptr; } #ifdef RUN_CLIENT_IN_BTHREAD ssize_t rc; @@ -216,10 +216,10 @@ void* client_thread(void* arg) { #endif if (rc != sizeof(m->count)) { PLOG(FATAL) << "Should not happen in this test, rc=" << rc; - return NULL; + return nullptr; } } - return NULL; + return nullptr; } inline uint32_t fmix32 ( uint32_t h ) { @@ -295,7 +295,7 @@ TEST(FDTest, ping_pong) { #if defined(OS_LINUX) ASSERT_EQ(0, epoll_ctl(m->epfd, EPOLL_CTL_ADD, m->fd, &evt)); #elif defined(OS_MACOSX) - ASSERT_EQ(0, kevent(m->epfd, &kqueue_event, 1, NULL, 0, NULL)); + ASSERT_EQ(0, kevent(m->epfd, &kqueue_event, 1, nullptr, 0, nullptr)); #endif cm[i].reset(new ClientMeta); cm[i]->fd = fds[i * 2 + 1]; @@ -303,9 +303,9 @@ TEST(FDTest, ping_pong) { cm[i]->times = REP; #ifdef RUN_CLIENT_IN_BTHREAD butil::make_non_blocking(cm[i]->fd); - ASSERT_EQ(0, bthread_start_urgent(&cth[i], NULL, client_thread, cm[i].get())); + ASSERT_EQ(0, bthread_start_urgent(&cth[i], nullptr, client_thread, cm[i].get())); #else - ASSERT_EQ(0, pthread_create(&cth[i], NULL, client_thread, cm[i].get())); + ASSERT_EQ(0, pthread_create(&cth[i], nullptr, client_thread, cm[i].get())); #endif } @@ -318,17 +318,17 @@ TEST(FDTest, ping_pong) { EpollMeta* em = em_arr[i].get(); em->epfd = epfd[i]; #ifdef RUN_EPOLL_IN_BTHREAD - ASSERT_EQ(0, bthread_start_urgent(ð[i], epoll_thread, em, NULL); + ASSERT_EQ(0, bthread_start_urgent(ð[i], epoll_thread, em, nullptr); #else - ASSERT_EQ(0, pthread_create(ð[i], NULL, epoll_thread, em)); + ASSERT_EQ(0, pthread_create(ð[i], nullptr, epoll_thread, em)); #endif } for (size_t i = 0; i < NCLIENT; ++i) { #ifdef RUN_CLIENT_IN_BTHREAD - bthread_join(cth[i], NULL); + bthread_join(cth[i], nullptr); #else - pthread_join(cth[i], NULL); + pthread_join(cth[i], nullptr); #endif ASSERT_EQ(i + REP * NCLIENT, cm[i]->count); } @@ -338,17 +338,17 @@ TEST(FDTest, ping_pong) { stop = true; for (size_t i = 0; i < NEPOLL; ++i) { #if defined(OS_LINUX) - epoll_event evt = { EPOLLOUT, { NULL } }; + epoll_event evt = { EPOLLOUT, { nullptr } }; ASSERT_EQ(0, epoll_ctl(epfd[i], EPOLL_CTL_ADD, 0, &evt)); #elif defined(OS_MACOSX) struct kevent kqueue_event; - EV_SET(&kqueue_event, 0, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, NULL); - ASSERT_EQ(0, kevent(epfd[i], &kqueue_event, 1, NULL, 0, NULL)); + EV_SET(&kqueue_event, 0, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, nullptr); + ASSERT_EQ(0, kevent(epfd[i], &kqueue_event, 1, nullptr, 0, nullptr)); #endif #ifdef RUN_EPOLL_IN_BTHREAD - bthread_join(eth[i], NULL); + bthread_join(eth[i], nullptr); #else - pthread_join(eth[i], NULL); + pthread_join(eth[i], nullptr); #endif } //bthread::stop_and_join_epoll_threads(); @@ -371,7 +371,7 @@ TEST(FDTest, mod_closed_fd) { int new_fd[2]; int fd[2]; ASSERT_EQ(0, pipe(fd)); - epoll_event e = { EPOLLIN, { NULL } }; + epoll_event e = { EPOLLIN, { nullptr } }; errno = 0; ASSERT_EQ(-1, epoll_ctl(epfd, EPOLL_CTL_MOD, fd[0], &e)); ASSERT_EQ(ENOENT, errno); @@ -402,7 +402,7 @@ TEST(FDTest, mod_closed_fd) { TEST(FDTest, add_existing_fd) { #if defined(OS_LINUX) const int epfd = epoll_create(1024); - epoll_event e = { EPOLLIN, { NULL } }; + epoll_event e = { EPOLLIN, { nullptr } }; ASSERT_EQ(0, epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &e)); errno = 0; ASSERT_EQ(-1, epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &e)); @@ -419,12 +419,12 @@ void* epoll_waiter(void* arg) { } #elif defined(OS_MACOSX) struct kevent e; - if (1 == kevent((int)(intptr_t)arg, NULL, 0, &e, 1, NULL)) { + if (1 == kevent((int)(intptr_t)arg, nullptr, 0, &e, 1, nullptr)) { std::cout << e.flags << std::endl; } #endif std::cout << pthread_self() << " quits" << std::endl; - return NULL; + return nullptr; } TEST(FDTest, interrupt_pthread) { @@ -434,22 +434,22 @@ TEST(FDTest, interrupt_pthread) { const int epfd = kqueue(); #endif pthread_t th, th2; - ASSERT_EQ(0, pthread_create(&th, NULL, epoll_waiter, (void*)(intptr_t)epfd)); - ASSERT_EQ(0, pthread_create(&th2, NULL, epoll_waiter, (void*)(intptr_t)epfd)); + ASSERT_EQ(0, pthread_create(&th, nullptr, epoll_waiter, (void*)(intptr_t)epfd)); + ASSERT_EQ(0, pthread_create(&th2, nullptr, epoll_waiter, (void*)(intptr_t)epfd)); bthread_usleep(100000L); std::cout << "wake up " << th << std::endl; bthread::interrupt_pthread(th); bthread_usleep(100000L); std::cout << "wake up " << th2 << std::endl; bthread::interrupt_pthread(th2); - pthread_join(th, NULL); - pthread_join(th2, NULL); + pthread_join(th, nullptr); + pthread_join(th2, nullptr); } void* close_the_fd(void* arg) { bthread_usleep(10000/*10ms*/); EXPECT_EQ(0, bthread_close(*(int*)arg)); - return NULL; + return nullptr; } TEST(FDTest, invalid_epoll_events) { @@ -462,9 +462,9 @@ TEST(FDTest, invalid_epoll_events) { ASSERT_EQ(EINVAL, errno); errno = 0; #if defined(OS_LINUX) - ASSERT_EQ(-1, bthread_fd_timedwait(-1, EPOLLIN, NULL)); + ASSERT_EQ(-1, bthread_fd_timedwait(-1, EPOLLIN, nullptr)); #elif defined(OS_MACOSX) - ASSERT_EQ(-1, bthread_fd_timedwait(-1, EVFILT_READ, NULL)); + ASSERT_EQ(-1, bthread_fd_timedwait(-1, EVFILT_READ, nullptr)); #endif ASSERT_EQ(EINVAL, errno); @@ -475,7 +475,7 @@ TEST(FDTest, invalid_epoll_events) { ASSERT_EQ(EINVAL, errno); #endif bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, close_the_fd, &fds[1])); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, close_the_fd, &fds[1])); butil::Timer tm; tm.start(); #if defined(OS_LINUX) @@ -485,7 +485,7 @@ TEST(FDTest, invalid_epoll_events) { #endif tm.stop(); ASSERT_LT(tm.m_elapsed(), 20); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_close(fds[0])); } @@ -496,20 +496,20 @@ void* wait_for_the_fd(void* arg) { #elif defined(OS_MACOSX) bthread_fd_timedwait(*(int*)arg, EVFILT_READ, &ts); #endif - return NULL; + return nullptr; } TEST(FDTest, timeout) { int fds[2]; ASSERT_EQ(0, pipe(fds)); pthread_t th; - ASSERT_EQ(0, pthread_create(&th, NULL, wait_for_the_fd, &fds[0])); + ASSERT_EQ(0, pthread_create(&th, nullptr, wait_for_the_fd, &fds[0])); bthread_t bth; - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, wait_for_the_fd, &fds[0])); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, wait_for_the_fd, &fds[0])); butil::Timer tm; tm.start(); - ASSERT_EQ(0, pthread_join(th, NULL)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, pthread_join(th, nullptr)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); tm.stop(); ASSERT_LT(tm.m_elapsed(), 80); ASSERT_EQ(0, bthread_close(fds[0])); @@ -520,19 +520,19 @@ TEST(FDTest, close_should_wakeup_waiter) { int fds[2]; ASSERT_EQ(0, pipe(fds)); bthread_t bth; - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, wait_for_the_fd, &fds[0])); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, wait_for_the_fd, &fds[0])); butil::Timer tm; tm.start(); ASSERT_EQ(0, bthread_close(fds[0])); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); tm.stop(); ASSERT_LT(tm.m_elapsed(), 5); // Launch again, should quit soon due to EBADF #if defined(OS_LINUX) - ASSERT_EQ(-1, bthread_fd_timedwait(fds[0], EPOLLIN, NULL)); + ASSERT_EQ(-1, bthread_fd_timedwait(fds[0], EPOLLIN, nullptr)); #elif defined(OS_MACOSX) - ASSERT_EQ(-1, bthread_fd_timedwait(fds[0], EVFILT_READ, NULL)); + ASSERT_EQ(-1, bthread_fd_timedwait(fds[0], EVFILT_READ, nullptr)); #endif ASSERT_EQ(EBADF, errno); @@ -617,7 +617,7 @@ void TestConnectInterruptImpl(bool timed) { int rc; if (timed) { int64_t start_ms = butil::cpuwide_time_ms(); - butil::tcp_connect(ep, NULL); + butil::tcp_connect(ep, nullptr); int64_t connect_ms = butil::cpuwide_time_ms() - start_ms; LOG(INFO) << "Connect to " << ep << ", cost " << connect_ms << "ms"; @@ -628,7 +628,7 @@ void TestConnectInterruptImpl(bool timed) { } else { rc = bthread_timed_connect( sockfd, (struct sockaddr*) &serv_addr, - serv_addr_size, NULL); + serv_addr_size, nullptr); } ASSERT_EQ(0, rc) << "errno=" << errno; ASSERT_EQ(0, butil::is_connected(sockfd)); @@ -638,14 +638,14 @@ void TestConnectInterruptImpl(bool timed) { void* ConnectThread(void* arg) { bool timed = *(bool*)arg; TestConnectInterruptImpl(timed); - return NULL; + return nullptr; } void TestConnectInterrupt(bool timed) { bthread_t tid; - ASSERT_EQ(0, bthread_start_background(&tid, NULL, ConnectThread, &timed)); + ASSERT_EQ(0, bthread_start_background(&tid, nullptr, ConnectThread, &timed)); ASSERT_EQ(0, bthread_stop(tid)); - ASSERT_EQ(0, bthread_join(tid, NULL)); + ASSERT_EQ(0, bthread_join(tid, nullptr)); } TEST(FDTest, interrupt) { diff --git a/test/bthread_futex_unittest.cpp b/test/bthread_futex_unittest.cpp index 0ed5685ca3..a9742755c9 100644 --- a/test/bthread_futex_unittest.cpp +++ b/test/bthread_futex_unittest.cpp @@ -57,7 +57,7 @@ void* read_thread(void* arg) { } ++nthread; - bthread::futex_wait_private(m/*lock1*/, 0/*consumed_njob*/, NULL); + bthread::futex_wait_private(m/*lock1*/, 0/*consumed_njob*/, nullptr); --nthread; } return new int(njob); @@ -68,7 +68,7 @@ TEST(FutexTest, rdlock_performance) { butil::atomic lock1(0); pthread_t rth[8]; for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) { - ASSERT_EQ(0, pthread_create(&rth[i], NULL, read_thread, &lock1)); + ASSERT_EQ(0, pthread_create(&rth[i], nullptr, read_thread, &lock1)); } const int64_t t1 = butil::cpuwide_time_ns(); @@ -113,8 +113,8 @@ TEST(FutexTest, futex_wake_before_wait) { } void* dummy_waiter(void* lock) { - bthread::futex_wait_private(lock, 0, NULL); - return NULL; + bthread::futex_wait_private(lock, 0, nullptr); + return nullptr; } TEST(FutexTest, futex_wake_many_waiters_perf) { @@ -122,7 +122,7 @@ TEST(FutexTest, futex_wake_many_waiters_perf) { int lock1 = 0; size_t N = 0; pthread_t th; - for (; N < 1000 && !pthread_create(&th, NULL, dummy_waiter, &lock1); ++N) {} + for (; N < 1000 && !pthread_create(&th, nullptr, dummy_waiter, &lock1); ++N) {} sleep(1); int nwakeup = 0; @@ -161,7 +161,7 @@ void* waker(void* lock) { tm.stop(); EXPECT_EQ(0, nwakeup); printf("futex_wake nop = %" PRId64 "ns\n", tm.n_elapsed() / REP); - return NULL; + return nullptr; } void* batch_waker(void* lock) { @@ -186,7 +186,7 @@ void* batch_waker(void* lock) { tm.stop(); EXPECT_EQ(0, nwakeup); printf("futex_wake nop = %" PRId64 "ns\n", tm.n_elapsed() / REP); - return NULL; + return nullptr; } TEST(FutexTest, many_futex_wake_nop_perf) { @@ -194,17 +194,17 @@ TEST(FutexTest, many_futex_wake_nop_perf) { int lock1; std::cout << "[Direct wake]" << std::endl; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, waker, &lock1)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, waker, &lock1)); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } std::cout << "[Batch wake]" << std::endl; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, batch_waker, &lock1)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, batch_waker, &lock1)); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } } } // namespace diff --git a/test/bthread_id_unittest.cpp b/test/bthread_id_unittest.cpp index 6cd668a723..59352ba5d3 100644 --- a/test/bthread_id_unittest.cpp +++ b/test/bthread_id_unittest.cpp @@ -42,7 +42,7 @@ struct SignalArg { void* signaller(void* void_arg) { SignalArg arg = *(SignalArg*)void_arg; bthread_usleep(arg.sleep_us_before_fight); - void* data = NULL; + void* data = nullptr; int rc = bthread_id_trylock(arg.id, &data); if (rc == 0) { EXPECT_EQ(0xdead, *(int*)data); @@ -53,14 +53,14 @@ void* signaller(void* void_arg) { return void_arg; } else { EXPECT_TRUE(EBUSY == rc || EINVAL == rc); - return NULL; + return nullptr; } } TEST(BthreadIdTest, join_after_destroy) { bthread_id_t id1; int x = 0xdead; - ASSERT_EQ(0, bthread_id_create_ranged(&id1, &x, NULL, 2)); + ASSERT_EQ(0, bthread_id_create_ranged(&id1, &x, nullptr, 2)); bthread_id_t id2 = { id1.value + 1 }; ASSERT_EQ(get_version(id1), bthread::id_value(id1)); ASSERT_EQ(get_version(id1), bthread::id_value(id2)); @@ -70,13 +70,13 @@ TEST(BthreadIdTest, join_after_destroy) { args[i].sleep_us_before_fight = 0; args[i].sleep_us_before_signal = 0; args[i].id = (i == 0 ? id1 : id2); - ASSERT_EQ(0, pthread_create(&th[i], NULL, signaller, &args[i])); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, signaller, &args[i])); } void* ret[ARRAY_SIZE(th)]; size_t non_null_ret = 0; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { ASSERT_EQ(0, pthread_join(th[i], &ret[i])); - non_null_ret += (ret[i] != NULL); + non_null_ret += (ret[i] != nullptr); } ASSERT_EQ(1UL, non_null_ret); ASSERT_EQ(0, bthread_id_join(id1)); @@ -89,7 +89,7 @@ TEST(BthreadIdTest, join_after_destroy) { TEST(BthreadIdTest, join_before_destroy) { bthread_id_t id1; int x = 0xdead; - ASSERT_EQ(0, bthread_id_create(&id1, &x, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, &x, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); pthread_t th[8]; SignalArg args[ARRAY_SIZE(th)]; @@ -97,7 +97,7 @@ TEST(BthreadIdTest, join_before_destroy) { args[i].sleep_us_before_fight = 10000; args[i].sleep_us_before_signal = 0; args[i].id = id1; - ASSERT_EQ(0, pthread_create(&th[i], NULL, signaller, &args[i])); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, signaller, &args[i])); } ASSERT_EQ(0, bthread_id_join(id1)); ASSERT_EQ(0xdead + 1, x); @@ -107,7 +107,7 @@ TEST(BthreadIdTest, join_before_destroy) { size_t non_null_ret = 0; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { ASSERT_EQ(0, pthread_join(th[i], &ret[i])); - non_null_ret += (ret[i] != NULL); + non_null_ret += (ret[i] != nullptr); } ASSERT_EQ(1UL, non_null_ret); } @@ -149,7 +149,7 @@ TEST(BthreadIdTest, error_is_destroy_ranged) { TEST(BthreadIdTest, default_error_is_destroy) { bthread_id_t id1; - ASSERT_EQ(0, bthread_id_create(&id1, NULL, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, nullptr, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); ASSERT_EQ(0, bthread_id_error(id1, EBADF)); ASSERT_EQ(get_version(id1) + 4, bthread::id_value(id1)); @@ -157,7 +157,7 @@ TEST(BthreadIdTest, default_error_is_destroy) { TEST(BthreadIdTest, doubly_destroy) { bthread_id_t id1; - ASSERT_EQ(0, bthread_id_create_ranged(&id1, NULL, NULL, 2)); + ASSERT_EQ(0, bthread_id_create_ranged(&id1, nullptr, nullptr, 2)); bthread_id_t id2 = { id1.value + 1 }; ASSERT_EQ(get_version(id1), bthread::id_value(id1)); ASSERT_EQ(get_version(id1), bthread::id_value(id2)); @@ -189,7 +189,7 @@ TEST(BthreadIdTest, many_error) { for (int i = 0; i < N; ++i) { ASSERT_EQ(i, result[i]); } - ASSERT_EQ(0, bthread_id_trylock(id1, NULL)); + ASSERT_EQ(0, bthread_id_trylock(id1, nullptr)); ASSERT_EQ(get_version(id1) + 1, bthread::id_value(id1)); for (int i = 0; i < N; ++i) { ASSERT_EQ(0, bthread_id_error(id1, err++)); @@ -203,7 +203,7 @@ TEST(BthreadIdTest, many_error) { } result.clear(); - ASSERT_EQ(0, bthread_id_trylock(id1, NULL)); + ASSERT_EQ(0, bthread_id_trylock(id1, nullptr)); ASSERT_EQ(get_version(id1) + 1, bthread::id_value(id1)); for (int i = 0; i < N; ++i) { ASSERT_EQ(0, bthread_id_error(id1, err++)); @@ -216,55 +216,55 @@ static void* locker(void* arg) { bthread_id_t id = { (uintptr_t)arg }; butil::Timer tm; tm.start(); - EXPECT_EQ(0, bthread_id_lock(id, NULL)); + EXPECT_EQ(0, bthread_id_lock(id, nullptr)); bthread_usleep(2000); EXPECT_EQ(0, bthread_id_unlock(id)); tm.stop(); LOG(INFO) << "Unlocked, tm=" << tm.u_elapsed(); - return NULL; + return nullptr; } TEST(BthreadIdTest, id_lock) { bthread_id_t id1; - ASSERT_EQ(0, bthread_id_create(&id1, NULL, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, nullptr, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); pthread_t th[8]; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, locker, + ASSERT_EQ(0, pthread_create(&th[i], nullptr, locker, (void*)id1.value)); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } } static void* failed_locker(void* arg) { bthread_id_t id = { (uintptr_t)arg }; - int rc = bthread_id_lock(id, NULL); + int rc = bthread_id_lock(id, nullptr); if (rc == 0) { bthread_usleep(2000); EXPECT_EQ(0, bthread_id_unlock_and_destroy(id)); return (void*)1; } else { EXPECT_EQ(EINVAL, rc); - return NULL; + return nullptr; } } TEST(BthreadIdTest, id_lock_and_destroy) { bthread_id_t id1; - ASSERT_EQ(0, bthread_id_create(&id1, NULL, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, nullptr, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); pthread_t th[8]; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, failed_locker, + ASSERT_EQ(0, pthread_create(&th[i], nullptr, failed_locker, (void*)id1.value)); } int non_null = 0; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - void* ret = NULL; + void* ret = nullptr; ASSERT_EQ(0, pthread_join(th[i], &ret)); - non_null += (ret != NULL); + non_null += (ret != nullptr); } ASSERT_EQ(1, non_null); } @@ -272,7 +272,7 @@ TEST(BthreadIdTest, id_lock_and_destroy) { TEST(BthreadIdTest, join_after_destroy_before_unlock) { bthread_id_t id1; int x = 0xdead; - ASSERT_EQ(0, bthread_id_create(&id1, &x, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, &x, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); pthread_t th[8]; SignalArg args[ARRAY_SIZE(th)]; @@ -280,7 +280,7 @@ TEST(BthreadIdTest, join_after_destroy_before_unlock) { args[i].sleep_us_before_fight = 0; args[i].sleep_us_before_signal = 20000; args[i].id = id1; - ASSERT_EQ(0, pthread_create(&th[i], NULL, signaller, &args[i])); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, signaller, &args[i])); } bthread_usleep(10000); // join() waits until destroy() is called. @@ -292,7 +292,7 @@ TEST(BthreadIdTest, join_after_destroy_before_unlock) { size_t non_null_ret = 0; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { ASSERT_EQ(0, pthread_join(th[i], &ret[i])); - non_null_ret += (ret[i] != NULL); + non_null_ret += (ret[i] != nullptr); } ASSERT_EQ(1UL, non_null_ret); } @@ -307,13 +307,13 @@ void* stopped_waiter(void* void_arg) { args->thread_started = true; EXPECT_EQ(0, bthread_id_join(args->id)); EXPECT_EQ(get_version(args->id) + 4, bthread::id_value(args->id)); - return NULL; + return nullptr; } TEST(BthreadIdTest, stop_a_wait_after_fight_before_signal) { bthread_id_t id1; int x = 0xdead; - ASSERT_EQ(0, bthread_id_create(&id1, &x, NULL)); + ASSERT_EQ(0, bthread_id_create(&id1, &x, nullptr)); ASSERT_EQ(get_version(id1), bthread::id_value(id1)); void* data; ASSERT_EQ(0, bthread_id_trylock(id1, &data)); @@ -323,7 +323,7 @@ TEST(BthreadIdTest, stop_a_wait_after_fight_before_signal) { for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { args[i].id = id1; args[i].thread_started = false; - ASSERT_EQ(0, bthread_start_urgent(&th[i], NULL, stopped_waiter, &args[i])); + ASSERT_EQ(0, bthread_start_urgent(&th[i], nullptr, stopped_waiter, &args[i])); } // stop does not wake up bthread_id_join for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { @@ -336,7 +336,7 @@ TEST(BthreadIdTest, stop_a_wait_after_fight_before_signal) { // destroy the id to end the joinings. ASSERT_EQ(0, bthread_id_unlock_and_destroy(id1)); for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, bthread_join(th[i], NULL)); + ASSERT_EQ(0, bthread_join(th[i], nullptr)); } } @@ -344,7 +344,7 @@ void* waiter(void* arg) { bthread_id_t id = { (uintptr_t)arg }; EXPECT_EQ(0, bthread_id_join(id)); EXPECT_EQ(get_version(id) + 4, bthread::id_value(id)); - return NULL; + return nullptr; } int handle_data(bthread_id_t id, void* data, int error_code) { @@ -367,14 +367,14 @@ TEST(BthreadIdTest, list_signal) { } pthread_t th[ARRAY_SIZE(id)]; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, waiter, (void*)(intptr_t)id[i].value)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, waiter, (void*)(intptr_t)id[i].value)); } bthread_usleep(10000); ASSERT_EQ(0, bthread_id_list_reset(&list, EBADF)); for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { ASSERT_EQ((int)(i + 1), data[i]); - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); // already reset. ASSERT_EQ((int)(i + 1), data[i]); } @@ -388,16 +388,16 @@ int error_without_unlock(bthread_id_t, void *, int) { TEST(BthreadIdTest, status) { bthread_id_t id; - bthread_id_create(&id, NULL, NULL); + bthread_id_create(&id, nullptr, nullptr); bthread::id_status(id, std::cout); - bthread_id_lock(id, NULL); + bthread_id_lock(id, nullptr); bthread_id_error(id, 123); bthread_id_error(id, 256); bthread_id_error(id, 1256); bthread::id_status(id, std::cout); bthread_id_unlock_and_destroy(id); - bthread_id_create(&id, NULL, error_without_unlock); - bthread_id_lock(id, NULL); + bthread_id_create(&id, nullptr, error_without_unlock); + bthread_id_lock(id, nullptr); bthread::id_status(id, std::cout); bthread_id_error(id, 12); bthread::id_status(id, std::cout); @@ -408,11 +408,11 @@ TEST(BthreadIdTest, status) { TEST(BthreadIdTest, reset_range) { bthread_id_t id; - ASSERT_EQ(0, bthread_id_create(&id, NULL, NULL)); - ASSERT_EQ(0, bthread_id_lock_and_reset_range(id, NULL, 1000)); + ASSERT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); + ASSERT_EQ(0, bthread_id_lock_and_reset_range(id, nullptr, 1000)); bthread::id_status(id, std::cout); bthread_id_unlock(id); - ASSERT_EQ(0, bthread_id_lock_and_reset_range(id, NULL, 300)); + ASSERT_EQ(0, bthread_id_lock_and_reset_range(id, nullptr, 300)); bthread::id_status(id, std::cout); bthread_id_unlock_and_destroy(id); } @@ -427,71 +427,71 @@ struct FailToLockIdArgs { static void* fail_to_lock_id(void* args_in) { FailToLockIdArgs* args = (FailToLockIdArgs*)args_in; butil::Timer tm; - EXPECT_EQ(args->expected_return, bthread_id_lock(args->id, NULL)); + EXPECT_EQ(args->expected_return, bthread_id_lock(args->id, nullptr)); any_thread_quit = true; - return NULL; + return nullptr; } TEST(BthreadIdTest, about_to_destroy_before_locking) { bthread_id_t id; - ASSERT_EQ(0, bthread_id_create(&id, NULL, NULL)); - ASSERT_EQ(0, bthread_id_lock(id, NULL)); + ASSERT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); + ASSERT_EQ(0, bthread_id_lock(id, nullptr)); ASSERT_EQ(0, bthread_id_about_to_destroy(id)); pthread_t pth; bthread_t bth; FailToLockIdArgs args = { id, EPERM }; - ASSERT_EQ(0, pthread_create(&pth, NULL, fail_to_lock_id, &args)); - ASSERT_EQ(0, bthread_start_background(&bth, NULL, fail_to_lock_id, &args)); + ASSERT_EQ(0, pthread_create(&pth, nullptr, fail_to_lock_id, &args)); + ASSERT_EQ(0, bthread_start_background(&bth, nullptr, fail_to_lock_id, &args)); // The threads should quit soon. - pthread_join(pth, NULL); - bthread_join(bth, NULL); + pthread_join(pth, nullptr); + bthread_join(bth, nullptr); bthread::id_status(id, std::cout); ASSERT_EQ(0, bthread_id_unlock_and_destroy(id)); } static void* succeed_to_lock_id(void* arg) { bthread_id_t id = *(bthread_id_t*)arg; - EXPECT_EQ(0, bthread_id_lock(id, NULL)); + EXPECT_EQ(0, bthread_id_lock(id, nullptr)); EXPECT_EQ(0, bthread_id_unlock(id)); - return NULL; + return nullptr; } TEST(BthreadIdTest, about_to_destroy_cancelled) { bthread_id_t id; - ASSERT_EQ(0, bthread_id_create(&id, NULL, NULL)); - ASSERT_EQ(0, bthread_id_lock(id, NULL)); + ASSERT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); + ASSERT_EQ(0, bthread_id_lock(id, nullptr)); ASSERT_EQ(0, bthread_id_about_to_destroy(id)); ASSERT_EQ(0, bthread_id_unlock(id)); pthread_t pth; bthread_t bth; - ASSERT_EQ(0, pthread_create(&pth, NULL, succeed_to_lock_id, &id)); - ASSERT_EQ(0, bthread_start_background(&bth, NULL, succeed_to_lock_id, &id)); + ASSERT_EQ(0, pthread_create(&pth, nullptr, succeed_to_lock_id, &id)); + ASSERT_EQ(0, bthread_start_background(&bth, nullptr, succeed_to_lock_id, &id)); // The threads should quit soon. - pthread_join(pth, NULL); - bthread_join(bth, NULL); + pthread_join(pth, nullptr); + bthread_join(bth, nullptr); bthread::id_status(id, std::cout); - ASSERT_EQ(0, bthread_id_lock(id, NULL)); + ASSERT_EQ(0, bthread_id_lock(id, nullptr)); ASSERT_EQ(0, bthread_id_unlock_and_destroy(id)); } TEST(BthreadIdTest, about_to_destroy_during_locking) { bthread_id_t id; - ASSERT_EQ(0, bthread_id_create(&id, NULL, NULL)); - ASSERT_EQ(0, bthread_id_lock(id, NULL)); + ASSERT_EQ(0, bthread_id_create(&id, nullptr, nullptr)); + ASSERT_EQ(0, bthread_id_lock(id, nullptr)); any_thread_quit = false; pthread_t pth; bthread_t bth; FailToLockIdArgs args = { id, EPERM }; - ASSERT_EQ(0, pthread_create(&pth, NULL, fail_to_lock_id, &args)); - ASSERT_EQ(0, bthread_start_background(&bth, NULL, fail_to_lock_id, &args)); + ASSERT_EQ(0, pthread_create(&pth, nullptr, fail_to_lock_id, &args)); + ASSERT_EQ(0, bthread_start_background(&bth, nullptr, fail_to_lock_id, &args)); usleep(100000); ASSERT_FALSE(any_thread_quit); ASSERT_EQ(0, bthread_id_about_to_destroy(id)); // The threads should quit soon. - pthread_join(pth, NULL); - bthread_join(bth, NULL); + pthread_join(pth, nullptr); + bthread_join(bth, nullptr); bthread::id_status(id, std::cout); ASSERT_EQ(0, bthread_id_unlock_and_destroy(id)); } @@ -564,7 +564,7 @@ TEST(BthreadIdTest, error_with_descriptions) { // Call bthread_id_error on an id created by bthread_id_create ++branch_counter; expected_code = ECONNRESET; - ASSERT_EQ(0, bthread_id_lock(id1, NULL)); + ASSERT_EQ(0, bthread_id_lock(id1, nullptr)); ASSERT_EQ(0, bthread_id_error(id1, expected_code)); ASSERT_EQ(0, bthread_id_unlock(id1)); ASSERT_EQ(branch_counter, branch_tags[1]); @@ -573,7 +573,7 @@ TEST(BthreadIdTest, error_with_descriptions) { ++branch_counter; expected_code = ENOSPC; expected_desc = "description3"; - ASSERT_EQ(0, bthread_id_lock(id2, NULL)); + ASSERT_EQ(0, bthread_id_lock(id2, nullptr)); ASSERT_EQ(0, bthread_id_error2(id2, expected_code, expected_desc)); ASSERT_EQ(0, bthread_id_unlock(id2)); ASSERT_EQ(branch_counter, branch_tags[3]); @@ -583,13 +583,13 @@ TEST(BthreadIdTest, error_with_descriptions) { ++branch_counter; expected_code = ESTOP; expected_desc = ""; - ASSERT_EQ(0, bthread_id_lock(id2, NULL)); + ASSERT_EQ(0, bthread_id_lock(id2, nullptr)); ASSERT_EQ(0, bthread_id_error(id2, expected_code)); ASSERT_EQ(0, bthread_id_unlock(id2)); ASSERT_EQ(branch_counter, branch_tags[2]); // Call bthread_id_error2 on an id created by bthread_id_create ++branch_counter; - ASSERT_EQ(0, bthread_id_lock(id1, NULL)); + ASSERT_EQ(0, bthread_id_lock(id1, nullptr)); ASSERT_EQ(0, bthread_id_error2(id1, expected_code, "")); ASSERT_EQ(0, bthread_id_unlock(id1)); ASSERT_EQ(branch_counter, branch_tags[0]); diff --git a/test/bthread_key_unittest.cpp b/test/bthread_key_unittest.cpp index 92f4aacace..f0bfadec42 100644 --- a/test/bthread_key_unittest.cpp +++ b/test/bthread_key_unittest.cpp @@ -97,9 +97,9 @@ static void worker1_impl(Counters* cs) { for (size_t i = 0; i < arraysize(k); ++i) { ws[i] = new CountersWrapper(cs, k[i]); } - // Get just-created tls should return NULL. + // Get just-created tls should return nullptr. for (size_t i = 0; i < arraysize(k); ++i) { - ASSERT_EQ(NULL, bthread_getspecific(k[i])); + ASSERT_EQ(nullptr, bthread_getspecific(k[i])); } for (size_t i = 0; i < arraysize(k); ++i) { cs->ncreate.fetch_add(1, butil::memory_order_relaxed); @@ -118,7 +118,7 @@ static void worker1_impl(Counters* cs) { static void* worker1(void* arg) { worker1_impl(static_cast(arg)); - return NULL; + return nullptr; } TEST(KeyTest, creating_key_in_parallel) { @@ -126,16 +126,16 @@ TEST(KeyTest, creating_key_in_parallel) { pthread_t th[8]; bthread_t bth[8]; for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, worker1, &args)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, worker1, &args)); } for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_start_background(&bth[i], NULL, worker1, &args)); + ASSERT_EQ(0, bthread_start_background(&bth[i], nullptr, worker1, &args)); } for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_join(bth[i], NULL)); + ASSERT_EQ(0, bthread_join(bth[i], nullptr)); } ASSERT_EQ(arraysize(th) + arraysize(bth), args.nenterthread.load(butil::memory_order_relaxed)); @@ -158,13 +158,13 @@ void dtor2(void* arg) { // NOTE: returns void to use ASSERT static void worker2_impl(bthread_key_t k) { - ASSERT_EQ(NULL, bthread_getspecific(k)); + ASSERT_EQ(nullptr, bthread_getspecific(k)); ASSERT_EQ(0, bthread_setspecific(k, (void*)seq.fetch_add(1))); } static void* worker2(void* arg) { worker2_impl(*static_cast(arg)); - return NULL; + return nullptr; } TEST(KeyTest, use_one_key_in_different_threads) { @@ -174,17 +174,17 @@ TEST(KeyTest, use_one_key_in_different_threads) { pthread_t th[16]; for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, worker2, &k)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, worker2, &k)); } bthread_t bth[1]; for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_start_urgent(&bth[i], NULL, worker2, &k)); + ASSERT_EQ(0, bthread_start_urgent(&bth[i], nullptr, worker2, &k)); } for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_join(bth[i], NULL)); + ASSERT_EQ(0, bthread_join(bth[i], nullptr)); } ASSERT_EQ(arraysize(th) + arraysize(bth), seqs.size()); std::sort(seqs.begin(), seqs.end()); @@ -202,9 +202,9 @@ struct Keys { void* const DUMMY_PTR = (void*)1; void use_invalid_keys_impl(const Keys* keys) { - ASSERT_EQ(NULL, bthread_getspecific(keys->invalid_key)); - // valid key returns NULL as well. - ASSERT_EQ(NULL, bthread_getspecific(keys->valid_key)); + ASSERT_EQ(nullptr, bthread_getspecific(keys->invalid_key)); + // valid key returns nullptr as well. + ASSERT_EQ(nullptr, bthread_getspecific(keys->valid_key)); // both pthread_setspecific(of nptl) and bthread_setspecific should find // the key is invalid. @@ -212,42 +212,42 @@ void use_invalid_keys_impl(const Keys* keys) { ASSERT_EQ(0, bthread_setspecific(keys->valid_key, DUMMY_PTR)); // Print error again. - ASSERT_EQ(NULL, bthread_getspecific(keys->invalid_key)); + ASSERT_EQ(nullptr, bthread_getspecific(keys->invalid_key)); ASSERT_EQ(DUMMY_PTR, bthread_getspecific(keys->valid_key)); } void* use_invalid_keys(void* args) { use_invalid_keys_impl(static_cast(args)); - return NULL; + return nullptr; } TEST(KeyTest, use_invalid_keys) { Keys keys; - ASSERT_EQ(0, bthread_key_create(&keys.valid_key, NULL)); + ASSERT_EQ(0, bthread_key_create(&keys.valid_key, nullptr)); // intended to be a created but invalid key. keys.invalid_key.index = keys.valid_key.index; keys.invalid_key.version = 123; pthread_t th; bthread_t bth; - ASSERT_EQ(0, pthread_create(&th, NULL, use_invalid_keys, &keys)); - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, use_invalid_keys, &keys)); - ASSERT_EQ(0, pthread_join(th, NULL)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, pthread_create(&th, nullptr, use_invalid_keys, &keys)); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, use_invalid_keys, &keys)); + ASSERT_EQ(0, pthread_join(th, nullptr)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); ASSERT_EQ(0, bthread_key_delete(keys.valid_key)); } TEST(KeyTest, reuse_key) { bthread_key_t key; - ASSERT_EQ(0, bthread_key_create(&key, NULL)); - ASSERT_EQ(NULL, bthread_getspecific(key)); + ASSERT_EQ(0, bthread_key_create(&key, nullptr)); + ASSERT_EQ(nullptr, bthread_getspecific(key)); ASSERT_EQ(0, bthread_setspecific(key, (void*)1)); ASSERT_EQ(0, bthread_key_delete(key)); // delete key before clearing TLS. bthread_key_t key2; - ASSERT_EQ(0, bthread_key_create(&key2, NULL)); + ASSERT_EQ(0, bthread_key_create(&key2, nullptr)); ASSERT_EQ(key.index, key2.index); - // The slot is not NULL, the impl must check version and return NULL. - ASSERT_EQ(NULL, bthread_getspecific(key2)); + // The slot is not nullptr, the impl must check version and return nullptr. + ASSERT_EQ(nullptr, bthread_getspecific(key2)); } // NOTE: sid is short for 'set in dtor'. @@ -259,8 +259,8 @@ struct SidData { static void sid_dtor(void* tls){ SidData* data = (SidData*)tls; - // Should already be set NULL. - ASSERT_EQ(NULL, bthread_getspecific(data->key)); + // Should already be set nullptr. + ASSERT_EQ(nullptr, bthread_getspecific(data->key)); if (++data->seq < data->end_seq){ ASSERT_EQ(0, bthread_setspecific(data->key, data)); } @@ -272,7 +272,7 @@ static void sid_thread_impl(SidData* data) { static void* sid_thread(void* args) { sid_thread_impl((SidData*)args); - return NULL; + return nullptr; } TEST(KeyTest, set_in_dtor) { @@ -286,14 +286,14 @@ TEST(KeyTest, set_in_dtor) { pthread_t pth; bthread_t bth; bthread_t bth2; - ASSERT_EQ(0, pthread_create(&pth, NULL, sid_thread, &pth_data)); - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, sid_thread, &bth_data)); + ASSERT_EQ(0, pthread_create(&pth, nullptr, sid_thread, &pth_data)); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, sid_thread, &bth_data)); ASSERT_EQ(0, bthread_start_urgent(&bth2, &BTHREAD_ATTR_PTHREAD, sid_thread, &bth2_data)); - ASSERT_EQ(0, pthread_join(pth, NULL)); - ASSERT_EQ(0, bthread_join(bth, NULL)); - ASSERT_EQ(0, bthread_join(bth2, NULL)); + ASSERT_EQ(0, pthread_join(pth, nullptr)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); + ASSERT_EQ(0, bthread_join(bth2, nullptr)); ASSERT_EQ(0, bthread_key_delete(key)); @@ -321,15 +321,15 @@ struct SBATLS { void* set_before_anybth(void* args); void set_before_anybth_impl(SBAData* data) { - ASSERT_EQ(NULL, bthread_getspecific(data->key)); + ASSERT_EQ(nullptr, bthread_getspecific(data->key)); SBATLS *tls = new SBATLS; tls->ndestroy = &data->ndestroy; ASSERT_EQ(0, bthread_setspecific(data->key, tls)); ASSERT_EQ(tls, bthread_getspecific(data->key)); if (data->level++ == 0) { bthread_t bth; - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, set_before_anybth, data)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, set_before_anybth, data)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); ASSERT_EQ(1, data->ndestroy); } else { bthread_usleep(1000); @@ -339,7 +339,7 @@ void set_before_anybth_impl(SBAData* data) { void* set_before_anybth(void* args) { set_before_anybth_impl((SBAData*)args); - return NULL; + return nullptr; } TEST(KeyTest, set_tls_before_creating_any_bthread) { @@ -350,8 +350,8 @@ TEST(KeyTest, set_tls_before_creating_any_bthread) { data.key = key; data.level = 0; data.ndestroy = 0; - ASSERT_EQ(0, pthread_create(&th, NULL, set_before_anybth, &data)); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_create(&th, nullptr, set_before_anybth, &data)); + ASSERT_EQ(0, pthread_join(th, nullptr)); ASSERT_EQ(0, bthread_key_delete(key)); ASSERT_EQ(2, data.level); ASSERT_EQ(2, data.ndestroy); @@ -367,7 +367,7 @@ struct PoolData { bool use_same_keytable = false; static void pool_thread_impl(PoolData* data) { - if (NULL == bthread_getspecific(data->key)) { + if (nullptr == bthread_getspecific(data->key)) { ASSERT_EQ(0, bthread_setspecific(data->key, data)); } else { use_same_keytable = true; @@ -376,13 +376,13 @@ static void pool_thread_impl(PoolData* data) { static void* pool_thread(void* args) { pool_thread_impl((PoolData*)args); - return NULL; + return nullptr; } static void pool_dtor(void* tls){ PoolData* data = (PoolData*)tls; - // Should already be set NULL. - ASSERT_EQ(NULL, bthread_getspecific(data->key)); + // Should already be set nullptr. + ASSERT_EQ(nullptr, bthread_getspecific(data->key)); if (++data->seq < data->end_seq){ ASSERT_EQ(0, bthread_setspecific(data->key, data)); } @@ -403,16 +403,16 @@ TEST(KeyTest, using_pool) { bthread_attr_t attr2 = attr; attr2.stack_type = BTHREAD_STACKTYPE_PTHREAD; - PoolData bth_data = { key, NULL, 0, 3 }; + PoolData bth_data = { key, nullptr, 0, 3 }; bthread_t bth; ASSERT_EQ(0, bthread_start_urgent(&bth, &attr, pool_thread, &bth_data)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); ASSERT_EQ(0, bth_data.seq); - PoolData bth2_data = { key, NULL, 0, 3 }; + PoolData bth2_data = { key, nullptr, 0, 3 }; bthread_t bth2; ASSERT_EQ(0, bthread_start_urgent(&bth2, &attr2, pool_thread, &bth2_data)); - ASSERT_EQ(0, bthread_join(bth2, NULL)); + ASSERT_EQ(0, bthread_join(bth2, nullptr)); ASSERT_EQ(0, bth2_data.seq); ASSERT_EQ(0, bthread_keytable_pool_destroy(&pool)); @@ -438,7 +438,7 @@ static void pool_dtor2(void* tls) { } static void usleep_thread_impl(PoolData2* data) { - if (NULL == bthread_getspecific(data->key)) { + if (nullptr == bthread_getspecific(data->key)) { PoolData2* data_new = new PoolData2(); ASSERT_EQ(0, bthread_setspecific(data->key, data_new)); } @@ -450,7 +450,7 @@ static void usleep_thread_impl(PoolData2* data) { static void* usleep_thread(void* args) { std::unique_ptr data((PoolData2*)args); usleep_thread_impl(data.get()); - return NULL; + return nullptr; } static void launch_many_bthreads(PoolData2* data) { @@ -466,14 +466,14 @@ static void launch_many_bthreads(PoolData2* data) { usleep(3 * 1000 * 1000L); for (size_t i = 0; i < tids.size(); ++i) { - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } } static void* run_launch_many_bthreads(void* args) { PoolData2* data = (PoolData2*)args; launch_many_bthreads(data); - return NULL; + return nullptr; } TEST(KeyTest, frequently_borrow_keytable_when_using_pool) { @@ -488,7 +488,7 @@ TEST(KeyTest, frequently_borrow_keytable_when_using_pool) { bthread_t bth; ASSERT_EQ(0, bthread_start_urgent(&bth, &data.attr, run_launch_many_bthreads, &data)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); std::cout << "Free keytable size is " << bthread_keytable_pool_size(&test_pool) << " use keytable size is 25000" << std::endl; @@ -516,7 +516,7 @@ static void return_thread_impl() { static void* return_thread(void*) { return_thread_impl(); - return NULL; + return nullptr; } static void borrow_thread_impl() { @@ -529,7 +529,7 @@ static void borrow_thread_impl() { static void* borrow_thread(void*) { borrow_thread_impl(); - return NULL; + return nullptr; } TEST(KeyTest, borrow_and_return_keytable_when_using_pool) { @@ -544,18 +544,18 @@ TEST(KeyTest, borrow_and_return_keytable_when_using_pool) { bthread_t return_bth[8]; for (size_t i = 0; i < arraysize(borrow_bth); ++i) { ASSERT_EQ(0, bthread_start_background(&borrow_bth[i], &attr, - borrow_thread, NULL)); + borrow_thread, nullptr)); } for (size_t i = 0; i < arraysize(return_bth); ++i) { ASSERT_EQ(0, bthread_start_background(&return_bth[i], &attr, - return_thread, NULL)); + return_thread, nullptr)); } for (size_t i = 0; i < arraysize(borrow_bth); ++i) { - ASSERT_EQ(0, bthread_join(borrow_bth[i], NULL)); + ASSERT_EQ(0, bthread_join(borrow_bth[i], nullptr)); } for (size_t i = 0; i < arraysize(return_bth); ++i) { - ASSERT_EQ(0, bthread_join(return_bth[i], NULL)); + ASSERT_EQ(0, bthread_join(return_bth[i], nullptr)); } for (size_t i = 0; i < table_list.size(); i++) { @@ -578,13 +578,13 @@ static void lid_dtor(void* tls) { } static void lid_worker_impl(bthread_key_t key) { - ASSERT_EQ(NULL, bthread_getspecific(key)); + ASSERT_EQ(nullptr, bthread_getspecific(key)); ASSERT_EQ(0, bthread_setspecific(key, (void*)lid_seq.fetch_add(1))); } static void* lid_worker(void* arg) { lid_worker_impl(*static_cast(arg)); - return NULL; + return nullptr; } TEST(KeyTest, use_bthread_mutex_in_dtor) { @@ -597,17 +597,17 @@ TEST(KeyTest, use_bthread_mutex_in_dtor) { bthread_t bth[8]; for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_start_urgent(&bth[i], NULL, lid_worker, &key)); + ASSERT_EQ(0, bthread_start_urgent(&bth[i], nullptr, lid_worker, &key)); } pthread_t th[8]; for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, lid_worker, &key)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, lid_worker, &key)); } for (size_t i = 0; i < arraysize(bth); ++i) { - ASSERT_EQ(0, bthread_join(bth[i], NULL)); + ASSERT_EQ(0, bthread_join(bth[i], nullptr)); } for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } ASSERT_EQ(arraysize(th) + arraysize(bth), lid_seqs.size()); std::sort(lid_seqs.begin(), lid_seqs.end()); diff --git a/test/bthread_list_unittest.cpp b/test/bthread_list_unittest.cpp index efcfbf4b0e..ce490d5be7 100644 --- a/test/bthread_list_unittest.cpp +++ b/test/bthread_list_unittest.cpp @@ -25,7 +25,7 @@ namespace { void* sleeper(void* arg) { bthread_usleep((long)arg); - return NULL; + return nullptr; } TEST(ListTest, join_thread_by_list) { @@ -35,7 +35,7 @@ TEST(ListTest, join_thread_by_list) { for (size_t i = 0; i < 10; ++i) { bthread_t th; ASSERT_EQ(0, bthread_start_urgent( - &th, NULL, sleeper, (void*)10000/*10ms*/)); + &th, nullptr, sleeper, (void*)10000/*10ms*/)); ASSERT_EQ(0, bthread_list_add(&list, th)); tids.push_back(th); } @@ -51,7 +51,7 @@ TEST(ListTest, join_a_destroyed_list) { ASSERT_EQ(0, bthread_list_init(&list, 0, 0)); bthread_t th; ASSERT_EQ(0, bthread_start_urgent( - &th, NULL, sleeper, (void*)10000/*10ms*/)); + &th, nullptr, sleeper, (void*)10000/*10ms*/)); ASSERT_EQ(0, bthread_list_add(&list, th)); ASSERT_EQ(0, bthread_list_join(&list)); bthread_list_destroy(&list); diff --git a/test/bthread_mutex_unittest.cpp b/test/bthread_mutex_unittest.cpp index 121f1ebb91..9849442160 100644 --- a/test/bthread_mutex_unittest.cpp +++ b/test/bthread_mutex_unittest.cpp @@ -41,34 +41,34 @@ void* locker(void* arg) { pthread_numeric_id(), ++c, butil::cpuwide_time_ms() - start_time); bthread_usleep(10000); bthread_mutex_unlock(m); - return NULL; + return nullptr; } TEST(MutexTest, sanity) { bthread_mutex_t m; - ASSERT_EQ(0, bthread_mutex_init(&m, NULL)); + ASSERT_EQ(0, bthread_mutex_init(&m, nullptr)); ASSERT_EQ(0u, *get_butex(m)); ASSERT_EQ(0, bthread_mutex_lock(&m)); ASSERT_EQ(1u, *get_butex(m)); bthread_t th1; - ASSERT_EQ(0, bthread_start_urgent(&th1, NULL, locker, &m)); + ASSERT_EQ(0, bthread_start_urgent(&th1, nullptr, locker, &m)); usleep(5000); // wait for locker to run. ASSERT_EQ(257u, *get_butex(m)); // contention ASSERT_EQ(0, bthread_mutex_unlock(&m)); - ASSERT_EQ(0, bthread_join(th1, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); ASSERT_EQ(0u, *get_butex(m)); ASSERT_EQ(0, bthread_mutex_destroy(&m)); } TEST(MutexTest, used_in_pthread) { bthread_mutex_t m; - ASSERT_EQ(0, bthread_mutex_init(&m, NULL)); + ASSERT_EQ(0, bthread_mutex_init(&m, nullptr)); pthread_t th[8]; for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, locker, &m)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, locker, &m)); } for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - pthread_join(th[i], NULL); + pthread_join(th[i], nullptr); } ASSERT_EQ(0u, *get_butex(m)); ASSERT_EQ(0, bthread_mutex_destroy(&m)); @@ -77,25 +77,25 @@ TEST(MutexTest, used_in_pthread) { void* do_locks(void *arg) { struct timespec t = { -2, 0 }; EXPECT_EQ(ETIMEDOUT, bthread_mutex_timedlock((bthread_mutex_t*)arg, &t)); - return NULL; + return nullptr; } TEST(MutexTest, timedlock) { bthread_cond_t c; bthread_mutex_t m1; bthread_mutex_t m2; - ASSERT_EQ(0, bthread_cond_init(&c, NULL)); - ASSERT_EQ(0, bthread_mutex_init(&m1, NULL)); - ASSERT_EQ(0, bthread_mutex_init(&m2, NULL)); + ASSERT_EQ(0, bthread_cond_init(&c, nullptr)); + ASSERT_EQ(0, bthread_mutex_init(&m1, nullptr)); + ASSERT_EQ(0, bthread_mutex_init(&m2, nullptr)); struct timespec t = { -2, 0 }; bthread_mutex_lock (&m1); bthread_mutex_lock (&m2); bthread_t pth; - ASSERT_EQ(0, bthread_start_urgent(&pth, NULL, do_locks, &m1)); + ASSERT_EQ(0, bthread_start_urgent(&pth, nullptr, do_locks, &m1)); ASSERT_EQ(ETIMEDOUT, bthread_cond_timedwait(&c, &m2, &t)); - ASSERT_EQ(0, bthread_join(pth, NULL)); + ASSERT_EQ(0, bthread_join(pth, nullptr)); bthread_mutex_unlock(&m1); bthread_mutex_unlock(&m2); bthread_mutex_destroy(&m1); @@ -150,7 +150,7 @@ struct BAIDU_CACHELINE_ALIGNMENT PerfArgs { int64_t elapse_ns; bool ready; - PerfArgs() : mutex(NULL), counter(0), elapse_ns(0), ready(false) {} + PerfArgs() : mutex(nullptr), counter(0), elapse_ns(0), ready(false) {} }; template @@ -171,7 +171,7 @@ void* add_with_mutex(void* void_arg) { } t.stop(); args->elapse_ns = t.n_elapsed(); - return NULL; + return nullptr; } int g_prof_name_counter = 0; @@ -189,7 +189,7 @@ void PerfTest(Mutex* mutex, std::vector > args(thread_num); for (int i = 0; i < thread_num; ++i) { args[i].mutex = mutex; - create_fn(&threads[i], NULL, add_with_mutex, &args[i]); + create_fn(&threads[i], nullptr, add_with_mutex, &args[i]); } while (true) { bool all_ready = true; @@ -214,7 +214,7 @@ void PerfTest(Mutex* mutex, int64_t wait_time = 0; int64_t count = 0; for (int i = 0; i < thread_num; ++i) { - join_fn(threads[i], NULL); + join_fn(threads[i], nullptr); wait_time += args[i].elapse_ns; count += args[i].counter; } @@ -228,16 +228,16 @@ void PerfTest(Mutex* mutex, TEST(MutexTest, performance) { const int thread_num = 12; butil::Mutex base_mutex; - PerfTest(&base_mutex, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(&base_mutex, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); + PerfTest(&base_mutex, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(&base_mutex, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); bthread::FastPthreadMutex fast_mutex; - PerfTest(&fast_mutex, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(&fast_mutex, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); + PerfTest(&fast_mutex, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(&fast_mutex, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); bthread::Mutex bth_mutex; - PerfTest(&bth_mutex, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(&bth_mutex, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); + PerfTest(&bth_mutex, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(&bth_mutex, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); } template @@ -247,7 +247,7 @@ void* loop_until_stopped(void* arg) { BAIDU_SCOPED_LOCK(*m); bthread_usleep(20); } - return NULL; + return nullptr; } TEST(MutexTest, mix_thread_types) { @@ -263,19 +263,19 @@ TEST(MutexTest, mix_thread_types) { // true, thus loop_until_stopped spins forever) bthread_setconcurrency(M); for (int i = 0; i < N; ++i) { - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, loop_until_stopped, &m)); + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, loop_until_stopped, &m)); } for (int i = 0; i < M; ++i) { - const bthread_attr_t *attr = i % 2 ? NULL : &BTHREAD_ATTR_PTHREAD; + const bthread_attr_t *attr = i % 2 ? nullptr : &BTHREAD_ATTR_PTHREAD; ASSERT_EQ(0, bthread_start_urgent(&bthreads[i], attr, loop_until_stopped, &m)); } bthread_usleep(1000L * 1000); g_stopped = true; for (int i = 0; i < M; ++i) { - bthread_join(bthreads[i], NULL); + bthread_join(bthreads[i], nullptr); } for (int i = 0; i < N; ++i) { - pthread_join(pthreads[i], NULL); + pthread_join(pthreads[i], nullptr); } } @@ -283,7 +283,7 @@ void* do_fast_pthread_timedlock(void *arg) { struct timespec t = { -2, 0 }; EXPECT_FALSE(((bthread::FastPthreadMutex*)arg)->timed_lock(&t)); EXPECT_EQ(ETIMEDOUT, errno); - return NULL; + return nullptr; } TEST(MutexTest, fast_pthread_mutex) { @@ -298,8 +298,8 @@ TEST(MutexTest, fast_pthread_mutex) { ASSERT_FALSE(mutex.timed_lock(&t)); ASSERT_EQ(ETIMEDOUT, errno); pthread_t th; - ASSERT_EQ(0, pthread_create(&th, NULL, do_fast_pthread_timedlock, &mutex)); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_create(&th, nullptr, do_fast_pthread_timedlock, &mutex)); + ASSERT_EQ(0, pthread_join(th, nullptr)); } { std::unique_lock lck1; @@ -314,13 +314,13 @@ TEST(MutexTest, fast_pthread_mutex) { const int N = 16; pthread_t pthreads[N]; for (int i = 0; i < N; ++i) { - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, loop_until_stopped, &mutex)); } bthread_usleep(1000L * 1000); g_stopped = true; for (int i = 0; i < N; ++i) { - pthread_join(pthreads[i], NULL); + pthread_join(pthreads[i], nullptr); } } @@ -328,13 +328,13 @@ TEST(MutexTest, fast_pthread_mutex) { void* do_pthread_timedlock(void *arg) { struct timespec t = { -2, 0 }; EXPECT_EQ(ETIMEDOUT, pthread_mutex_timedlock((pthread_mutex_t*)arg, &t)); - return NULL; + return nullptr; } #endif TEST(MutexTest, pthread_mutex) { pthread_mutex_t mutex; - ASSERT_EQ(0, pthread_mutex_init(&mutex, NULL)); + ASSERT_EQ(0, pthread_mutex_init(&mutex, nullptr)); ASSERT_EQ(0, pthread_mutex_trylock(&mutex)); ASSERT_EQ(0, pthread_mutex_unlock(&mutex)); ASSERT_EQ(0, pthread_mutex_lock(&mutex)); @@ -346,8 +346,8 @@ TEST(MutexTest, pthread_mutex) { struct timespec t = { -2, 0 }; ASSERT_EQ(ETIMEDOUT, pthread_mutex_timedlock(&mutex, &t)); pthread_t th; - ASSERT_EQ(0, pthread_create(&th, NULL, do_pthread_timedlock, &mutex)); - ASSERT_EQ(0, pthread_join(th, NULL)); + ASSERT_EQ(0, pthread_create(&th, nullptr, do_pthread_timedlock, &mutex)); + ASSERT_EQ(0, pthread_join(th, nullptr)); #endif } ASSERT_EQ(0, pthread_mutex_trylock(&mutex)); @@ -356,13 +356,13 @@ TEST(MutexTest, pthread_mutex) { const int N = 16; pthread_t pthreads[N]; for (int i = 0; i < N; ++i) { - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, loop_until_stopped, &mutex)); } bthread_usleep(1000L * 1000); g_stopped = true; for (int i = 0; i < N; ++i) { - pthread_join(pthreads[i], NULL); + pthread_join(pthreads[i], nullptr); } } diff --git a/test/bthread_once_unittest.cpp b/test/bthread_once_unittest.cpp index 618798e8c4..13dd0f8ff5 100644 --- a/test/bthread_once_unittest.cpp +++ b/test/bthread_once_unittest.cpp @@ -44,19 +44,19 @@ void bthread_once_task() { void* first_bthread_once_task(void*) { g_bthread_once_started = true; bthread_once_task(); - return NULL; + return nullptr; } void* other_bthread_once_task(void*) { bthread_once_task(); - return NULL; + return nullptr; } TEST(BthreadOnceTest, once) { bthread_t bid; ASSERT_EQ(0, bthread_start_background( - &bid, NULL, first_bthread_once_task, NULL)); + &bid, nullptr, first_bthread_once_task, nullptr)); while (!g_bthread_once_started) { bthread_usleep(1000); } @@ -67,14 +67,14 @@ TEST(BthreadOnceTest, once) { std::vector bids(concurrency * 100); for (auto& id : bids) { ASSERT_EQ(0, bthread_start_background( - &id, NULL, other_bthread_once_task, NULL)); + &id, nullptr, other_bthread_once_task, nullptr)); } bthread_once_task(); for (auto& id : bids) { - bthread_join(id, NULL); + bthread_join(id, nullptr); } - bthread_join(bid, NULL); + bthread_join(bid, nullptr); } bool g_bthread_started = false; @@ -98,13 +98,13 @@ void get_bthread_singleton() { void* first_get_bthread_singleton(void*) { g_bthread_started = true; get_bthread_singleton(); - return NULL; + return nullptr; } void* get_bthread_singleton(void*) { get_bthread_singleton(); - return NULL; + return nullptr; } // Singleton will definitely not cause deadlock, @@ -112,7 +112,7 @@ void* get_bthread_singleton(void*) { TEST(BthreadOnceTest, singleton) { bthread_t bid; ASSERT_EQ(0, bthread_start_background( - &bid, NULL, first_get_bthread_singleton, NULL)); + &bid, nullptr, first_get_bthread_singleton, nullptr)); while (!g_bthread_started) { bthread_usleep(1000); } @@ -123,14 +123,14 @@ TEST(BthreadOnceTest, singleton) { std::vector bids(concurrency * 100); for (auto& id : bids) { ASSERT_EQ(0, bthread_start_background( - &id, NULL, get_bthread_singleton, NULL)); + &id, nullptr, get_bthread_singleton, nullptr)); } get_bthread_singleton(); for (auto& id : bids) { - bthread_join(id, NULL); + bthread_join(id, nullptr); } - bthread_join(bid, NULL); + bthread_join(bid, nullptr); } } \ No newline at end of file diff --git a/test/bthread_ping_pong_unittest.cpp b/test/bthread_ping_pong_unittest.cpp index 76f559b4df..e842b146e0 100644 --- a/test/bthread_ping_pong_unittest.cpp +++ b/test/bthread_ping_pong_unittest.cpp @@ -78,7 +78,7 @@ void* pipe_player(void* void_arg) { } ++arg->counter; } - return NULL; + return nullptr; } static const int INITIAL_FUTEX_VALUE = 0; @@ -87,28 +87,28 @@ void* futex_player(void* void_arg) { PlayerArg* arg = static_cast(void_arg); int counter = INITIAL_FUTEX_VALUE; while (!stop) { - int rc = bthread::futex_wait_private(arg->wait_addr, counter, NULL); + int rc = bthread::futex_wait_private(arg->wait_addr, counter, nullptr); ++counter; ++*arg->wake_addr; bthread::futex_wake_private(arg->wake_addr, 1); ++arg->counter; arg->wakeup += (rc == 0); } - return NULL; + return nullptr; } void* butex_player(void* void_arg) { PlayerArg* arg = static_cast(void_arg); int counter = INITIAL_FUTEX_VALUE; while (!stop) { - int rc = bthread::butex_wait(arg->wait_addr, counter, NULL); + int rc = bthread::butex_wait(arg->wait_addr, counter, nullptr); ++counter; ++*arg->wake_addr; bthread::butex_wake(arg->wake_addr); ++arg->counter; arg->wakeup += (rc == 0); } - return NULL; + return nullptr; } TEST(PingPongTest, ping_pong) { @@ -161,14 +161,14 @@ TEST(PingPongTest, ping_pong) { pthread_t th1, th2; bthread_t bth1, bth2; if (!FLAGS_use_futex && !FLAGS_use_butex) { - ASSERT_EQ(0, pthread_create(&th1, NULL, pipe_player, arg1)); - ASSERT_EQ(0, pthread_create(&th2, NULL, pipe_player, arg2)); + ASSERT_EQ(0, pthread_create(&th1, nullptr, pipe_player, arg1)); + ASSERT_EQ(0, pthread_create(&th2, nullptr, pipe_player, arg2)); } else if (FLAGS_use_futex) { - ASSERT_EQ(0, pthread_create(&th1, NULL, futex_player, arg1)); - ASSERT_EQ(0, pthread_create(&th2, NULL, futex_player, arg2)); + ASSERT_EQ(0, pthread_create(&th1, nullptr, futex_player, arg1)); + ASSERT_EQ(0, pthread_create(&th2, nullptr, futex_player, arg2)); } else if (FLAGS_use_butex) { - ASSERT_EQ(0, bthread_start_background(&bth1, NULL, butex_player, arg1)); - ASSERT_EQ(0, bthread_start_background(&bth2, NULL, butex_player, arg2)); + ASSERT_EQ(0, bthread_start_background(&bth1, nullptr, butex_player, arg1)); + ASSERT_EQ(0, bthread_start_background(&bth2, nullptr, butex_player, arg2)); } else { ASSERT_TRUE(false); } diff --git a/test/bthread_priority_queue_unittest.cpp b/test/bthread_priority_queue_unittest.cpp index 42f6dd85db..6dcdc9e3bd 100644 --- a/test/bthread_priority_queue_unittest.cpp +++ b/test/bthread_priority_queue_unittest.cpp @@ -51,13 +51,13 @@ void* priority_task_fn(void* arg) { g_executed_ids.insert(ta->id); } delete ta; - return NULL; + return nullptr; } void* normal_task_fn(void* /*arg*/) { // Just a normal task that does nothing, used as a filler bthread_usleep(1000); - return NULL; + return nullptr; } class PriorityQueueTest : public ::testing::Test { @@ -87,7 +87,7 @@ TEST_F(PriorityQueueTest, e2e_priority_tasks_all_executed) { } for (int i = 0; i < N; ++i) { - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } ASSERT_EQ(N, g_priority_count.load()); @@ -116,14 +116,14 @@ TEST_F(PriorityQueueTest, mixed_priority_and_normal_tasks) { ASSERT_EQ(0, bthread_start_background(&tid, &priority_attr, priority_task_fn, arg)); } else { - ASSERT_EQ(0, bthread_start_background(&tid, NULL, - normal_task_fn, NULL)); + ASSERT_EQ(0, bthread_start_background(&tid, nullptr, + normal_task_fn, nullptr)); } tids.push_back(tid); } for (auto tid : tids) { - bthread_join(tid, NULL); + bthread_join(tid, nullptr); } ASSERT_EQ(N_PRIORITY, g_priority_count.load()); @@ -153,7 +153,7 @@ TEST_F(PriorityQueueTest, start_foreground_priority_to_run) { for (int i = 0; i < ea->n_tasks; ++i) { TaskArg* ta = new TaskArg{i}; bthread_t child; - int rc = bthread_start_urgent(&child, NULL, priority_task_fn, ta); + int rc = bthread_start_urgent(&child, nullptr, priority_task_fn, ta); if (rc != 0) { delete ta; ea->error_code = rc; @@ -162,9 +162,9 @@ TEST_F(PriorityQueueTest, start_foreground_priority_to_run) { children.push_back(child); } for (auto child : children) { - bthread_join(child, NULL); + bthread_join(child, nullptr); } - return NULL; + return nullptr; }; bthread_attr_t priority_attr = BTHREAD_ATTR_NORMAL; @@ -173,7 +173,7 @@ TEST_F(PriorityQueueTest, start_foreground_priority_to_run) { bthread_t ed_tid; ASSERT_EQ(0, bthread_start_background(&ed_tid, &priority_attr, ed_fn, &ed_arg)); - ASSERT_EQ(0, bthread_join(ed_tid, NULL)); + ASSERT_EQ(0, bthread_join(ed_tid, nullptr)); ASSERT_EQ(0, ed_arg.error_code); ASSERT_EQ(N, g_priority_count.load()); @@ -209,7 +209,7 @@ TEST_F(PriorityQueueTest, multiple_eds_concurrent_preempt) { TaskArg* ta = new TaskArg{id}; bthread_t child; const int rc = bthread_start_urgent( - &child, NULL, priority_task_fn, ta); + &child, nullptr, priority_task_fn, ta); if (rc != 0) { delete ta; ea->error_code = rc; @@ -219,9 +219,9 @@ TEST_F(PriorityQueueTest, multiple_eds_concurrent_preempt) { ea->resume_count->fetch_add(1, std::memory_order_relaxed); } for (auto c : children) { - bthread_join(c, NULL); + bthread_join(c, nullptr); } - return NULL; + return nullptr; }; bthread_attr_t priority_attr = BTHREAD_ATTR_NORMAL; @@ -236,7 +236,7 @@ TEST_F(PriorityQueueTest, multiple_eds_concurrent_preempt) { } for (int i = 0; i < NUM_EDS; ++i) { - ASSERT_EQ(0, bthread_join(ed_tids[i], NULL)); + ASSERT_EQ(0, bthread_join(ed_tids[i], nullptr)); ASSERT_EQ(0, ed_args[i].error_code); } diff --git a/test/bthread_rwlock_unittest.cpp b/test/bthread_rwlock_unittest.cpp index 9a88051c1a..58a60d4a55 100644 --- a/test/bthread_rwlock_unittest.cpp +++ b/test/bthread_rwlock_unittest.cpp @@ -32,7 +32,7 @@ void* rdlocker(void* arg) { butil::cpuwide_time_ms() - start_time); bthread_usleep(10000); bthread_rwlock_unlock(rw); - return NULL; + return nullptr; } void* wrlocker(void* arg) { @@ -43,12 +43,12 @@ void* wrlocker(void* arg) { butil::cpuwide_time_ms() - start_time); bthread_usleep(10000); bthread_rwlock_unlock(rw); - return NULL; + return nullptr; } TEST(RWLockTest, sanity) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); ASSERT_EQ(0, bthread_rwlock_rdlock(&rw)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_wrlock(&rw)); @@ -56,31 +56,31 @@ TEST(RWLockTest, sanity) { bthread_t rdth; bthread_t rwth; - ASSERT_EQ(0, bthread_start_urgent(&rdth, NULL, rdlocker, &rw)); - ASSERT_EQ(0, bthread_start_urgent(&rwth, NULL, wrlocker, &rw)); + ASSERT_EQ(0, bthread_start_urgent(&rdth, nullptr, rdlocker, &rw)); + ASSERT_EQ(0, bthread_start_urgent(&rwth, nullptr, wrlocker, &rw)); - ASSERT_EQ(0, bthread_join(rdth, NULL)); - ASSERT_EQ(0, bthread_join(rwth, NULL)); + ASSERT_EQ(0, bthread_join(rdth, nullptr)); + ASSERT_EQ(0, bthread_join(rwth, nullptr)); ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); } TEST(RWLockTest, used_in_pthread) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); pthread_t rdth[8]; pthread_t wrth[8]; for (size_t i = 0; i < ARRAY_SIZE(rdth); ++i) { - ASSERT_EQ(0, pthread_create(&rdth[i], NULL, rdlocker, &rw)); + ASSERT_EQ(0, pthread_create(&rdth[i], nullptr, rdlocker, &rw)); } for (size_t i = 0; i < ARRAY_SIZE(wrth); ++i) { - ASSERT_EQ(0, pthread_create(&wrth[i], NULL, wrlocker, &rw)); + ASSERT_EQ(0, pthread_create(&wrth[i], nullptr, wrlocker, &rw)); } for (size_t i = 0; i < ARRAY_SIZE(rdth); ++i) { - pthread_join(rdth[i], NULL); + pthread_join(rdth[i], nullptr); } for (size_t i = 0; i < ARRAY_SIZE(rdth); ++i) { - pthread_join(wrth[i], NULL); + pthread_join(wrth[i], nullptr); } ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); } @@ -88,31 +88,31 @@ TEST(RWLockTest, used_in_pthread) { void* do_timedrdlock(void *arg) { struct timespec t = { -2, 0 }; EXPECT_EQ(ETIMEDOUT, bthread_rwlock_timedrdlock((bthread_rwlock_t*)arg, &t)); - return NULL; + return nullptr; } void* do_timedwrlock(void *arg) { struct timespec t = { -2, 0 }; EXPECT_EQ(ETIMEDOUT, bthread_rwlock_timedwrlock((bthread_rwlock_t*)arg, &t)); LOG(INFO) << 10; - return NULL; + return nullptr; } TEST(RWLockTest, timedlock) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); ASSERT_EQ(0, bthread_rwlock_rdlock(&rw)); bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_timedwrlock, &rw)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_timedwrlock, &rw)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_wrlock(&rw)); - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_timedwrlock, &rw)); - ASSERT_EQ(0, bthread_join(th, NULL)); - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_timedrdlock, &rw)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_timedwrlock, &rw)); + ASSERT_EQ(0, bthread_join(th, nullptr)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_timedrdlock, &rw)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); } @@ -126,45 +126,45 @@ void* do_tryrdlock(void *arg) { auto trylock_args = (TrylockArgs*)arg; EXPECT_EQ(trylock_args->rc, bthread_rwlock_tryrdlock(trylock_args->rw)); if (0 != trylock_args->rc) { - return NULL; + return nullptr; } EXPECT_EQ(trylock_args->rc, bthread_rwlock_unlock(trylock_args->rw)); - return NULL; + return nullptr; } void* do_trywrlock(void *arg) { auto trylock_args = (TrylockArgs*)arg; EXPECT_EQ(trylock_args->rc, bthread_rwlock_trywrlock(trylock_args->rw)); if (0 != trylock_args->rc) { - return NULL; + return nullptr; } EXPECT_EQ(trylock_args->rc, bthread_rwlock_unlock(trylock_args->rw)); - return NULL; + return nullptr; } TEST(RWLockTest, trylock) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); ASSERT_EQ(0, bthread_rwlock_tryrdlock(&rw)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_rdlock(&rw)); bthread_t th; TrylockArgs args{&rw, 0}; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_tryrdlock, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_tryrdlock, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); args.rc = EBUSY; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_trywrlock, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_trywrlock, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_trywrlock(&rw)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_wrlock(&rw)); - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_tryrdlock, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_trywrlock, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_tryrdlock, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_trywrlock, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); @@ -238,13 +238,13 @@ void* loop_until_stopped(void* arg) { while (!g_stopped) { args->op(args->rw, 20); } - return NULL; + return nullptr; } TEST(RWLockTest, mix_thread_types) { g_stopped = false; bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); const int N = 16; const int M = N * 2; @@ -263,7 +263,7 @@ TEST(RWLockTest, mix_thread_types) { } else { args.push_back({&rw, write_op}); } - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, loop_until_stopped, &args.back())); + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, loop_until_stopped, &args.back())); } for (int i = 0; i < M; ++i) { @@ -272,16 +272,16 @@ TEST(RWLockTest, mix_thread_types) { } else { args.push_back({&rw, write_op}); } - const bthread_attr_t* attr = i % 2 ? NULL : &BTHREAD_ATTR_PTHREAD; + const bthread_attr_t* attr = i % 2 ? nullptr : &BTHREAD_ATTR_PTHREAD; ASSERT_EQ(0, bthread_start_urgent(&bthreads[i], attr, loop_until_stopped, &args.back())); } bthread_usleep(1000L * 1000); g_stopped = true; for (int i = 0; i < M; ++i) { - bthread_join(bthreads[i], NULL); + bthread_join(bthreads[i], nullptr); } for (int i = 0; i < N; ++i) { - pthread_join(pthreads[i], NULL); + pthread_join(pthreads[i], nullptr); } ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); @@ -302,7 +302,7 @@ void* wp_writer_fn(void* arg) { a->my_order = a->order->fetch_add(1, butil::memory_order_relaxed); bthread_usleep(a->hold_us); EXPECT_EQ(0, bthread_rwlock_unlock(a->rw)); - return NULL; + return nullptr; } void* wp_reader_fn(void* arg) { @@ -311,7 +311,7 @@ void* wp_reader_fn(void* arg) { a->my_order = a->order->fetch_add(1, butil::memory_order_relaxed); bthread_usleep(a->hold_us); EXPECT_EQ(0, bthread_rwlock_unlock(a->rw)); - return NULL; + return nullptr; } // Verifies the writer-priority invariant guarded by the order @@ -321,7 +321,7 @@ void* wp_reader_fn(void* arg) { TEST(RWLockTest, writer_priority) { bthread_setconcurrency(8); bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); // (1) Main thread holds the read lock first. ASSERT_EQ(0, bthread_rwlock_rdlock(&rw)); @@ -334,22 +334,22 @@ TEST(RWLockTest, writer_priority) { // lock is held. Sleep long enough for it to fetch_add into // writer_wait_count and reach the butex_wait on `lock_word'. bthread_t wth; - ASSERT_EQ(0, bthread_start_urgent(&wth, NULL, wp_writer_fn, &warg)); + ASSERT_EQ(0, bthread_start_urgent(&wth, nullptr, wp_writer_fn, &warg)); bthread_usleep(50 * 1000); // (3) Now spawn a fresh reader. By writer-priority it MUST observe // writer_wait_count > 0 and park on it (NOT join the active read // lock). bthread_t r2th; - ASSERT_EQ(0, bthread_start_urgent(&r2th, NULL, wp_reader_fn, &r2arg)); + ASSERT_EQ(0, bthread_start_urgent(&r2th, nullptr, wp_reader_fn, &r2arg)); bthread_usleep(50 * 1000); // (4) Release the original read lock. The writer should win the race // and complete BEFORE the queued reader. ASSERT_EQ(0, bthread_rwlock_unlock(&rw)); - bthread_join(wth, NULL); - bthread_join(r2th, NULL); + bthread_join(wth, nullptr); + bthread_join(r2th, nullptr); EXPECT_GE(warg.my_order, 0); EXPECT_GE(r2arg.my_order, 0); @@ -365,7 +365,7 @@ void* wp_timed_wrlock_short(void* arg) { auto* rw = (bthread_rwlock_t*)arg; timespec ts = butil::milliseconds_from_now(50); EXPECT_EQ(ETIMEDOUT, bthread_rwlock_timedwrlock(rw, &ts)); - return NULL; + return nullptr; } // Verifies the cleanup path of rwlock_wrlock_cleanup(): after multiple @@ -374,7 +374,7 @@ void* wp_timed_wrlock_short(void* arg) { TEST(RWLockTest, wrlock_failure_does_not_leak_writer_count) { bthread_setconcurrency(8); bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); // Hold the read lock so every wrlock attempt must block on `lock_word'. ASSERT_EQ(0, bthread_rwlock_rdlock(&rw)); @@ -382,11 +382,11 @@ TEST(RWLockTest, wrlock_failure_does_not_leak_writer_count) { const int N = 8; bthread_t wth[N]; for (int i = 0; i < N; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&wth[i], NULL, wp_timed_wrlock_short, &rw)); + ASSERT_EQ(0, bthread_start_urgent(&wth[i], nullptr, wp_timed_wrlock_short, &rw)); } // Wait for all timed wrlock attempts to time out and run cleanup. for (int i = 0; i < N; ++i) { - bthread_join(wth[i], NULL); + bthread_join(wth[i], nullptr); } // Release the read lock; from this point on no writer is in flight, @@ -431,7 +431,7 @@ void* dc_worker(void* arg) { EXPECT_EQ(0, bthread_rwlock_unlock(a->rw)); } } - return NULL; + return nullptr; } // Verifies the release/acquire memory ordering pair on `lock_word'. @@ -441,7 +441,7 @@ void* dc_worker(void* arg) { // threads, causing the final counter to disagree with total writer ops. TEST(RWLockTest, data_consistency) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); g_stopped = false; const int W = 4; @@ -457,7 +457,7 @@ TEST(RWLockTest, data_consistency) { args[i].local_inc = 0; args[i].observed_max = -1; args[i].is_writer = (i < W); - ASSERT_EQ(0, bthread_start_urgent(&threads[i], NULL, dc_worker, &args[i])); + ASSERT_EQ(0, bthread_start_urgent(&threads[i], nullptr, dc_worker, &args[i])); } bthread_usleep(500 * 1000); @@ -465,7 +465,7 @@ TEST(RWLockTest, data_consistency) { int64_t total_inc = 0; for (int i = 0; i < W + R; ++i) { - bthread_join(threads[i], NULL); + bthread_join(threads[i], nullptr); if (args[i].is_writer) { total_inc += args[i].local_inc; } @@ -493,7 +493,7 @@ void* ws_reader_loop(void* arg) { bthread_usleep(100); EXPECT_EQ(0, bthread_rwlock_unlock(rw)); } - return NULL; + return nullptr; } // Verifies that under a continuous read load, a writer can still acquire @@ -502,14 +502,14 @@ void* ws_reader_loop(void* arg) { // wrlock() must yield, ensuring the writer never starves. TEST(RWLockTest, no_writer_starvation) { bthread_rwlock_t rw; - ASSERT_EQ(0, bthread_rwlock_init(&rw, NULL)); + ASSERT_EQ(0, bthread_rwlock_init(&rw, nullptr)); g_stopped = false; const int R = 16; bthread_setconcurrency(R + 4); bthread_t rth[R]; for (int i = 0; i < R; ++i) { - ASSERT_EQ(0, bthread_start_urgent(&rth[i], NULL, ws_reader_loop, &rw)); + ASSERT_EQ(0, bthread_start_urgent(&rth[i], nullptr, ws_reader_loop, &rw)); } // Let the readers ramp up and saturate the lock. @@ -529,7 +529,7 @@ TEST(RWLockTest, no_writer_starvation) { g_stopped = true; for (int i = 0; i < R; ++i) { - bthread_join(rth[i], NULL); + bthread_join(rth[i], nullptr); } ASSERT_EQ(0, bthread_rwlock_destroy(&rw)); } @@ -540,7 +540,7 @@ struct BAIDU_CACHELINE_ALIGNMENT PerfArgs { int64_t elapse_ns; bool ready; - PerfArgs() : rw(NULL), counter(0), elapse_ns(0), ready(false) {} + PerfArgs() : rw(nullptr), counter(0), elapse_ns(0), ready(false) {} }; template @@ -566,7 +566,7 @@ void* add_with_mutex(void* void_arg) { } t.stop(); args->elapse_ns = t.n_elapsed(); - return NULL; + return nullptr; } int g_prof_name_counter = 0; @@ -582,15 +582,15 @@ void PerfTest(uint32_t writer_ratio, ThreadId* /*dummy*/, int thread_num, std::vector threads(thread_num); std::vector args(thread_num); bthread_rwlock_t rw; - bthread_rwlock_init(&rw, NULL); + bthread_rwlock_init(&rw, nullptr); int writer_num = thread_num * writer_ratio / 100; int reader_num = thread_num - writer_num; for (int i = 0; i < thread_num; ++i) { args[i].rw = &rw; if (i < writer_num) { - ASSERT_EQ(0, create_fn(&threads[i], NULL, add_with_mutex, &args[i])); + ASSERT_EQ(0, create_fn(&threads[i], nullptr, add_with_mutex, &args[i])); } else { - ASSERT_EQ(0, create_fn(&threads[i], NULL, add_with_mutex, &args[i])); + ASSERT_EQ(0, create_fn(&threads[i], nullptr, add_with_mutex, &args[i])); } } while (true) { @@ -619,7 +619,7 @@ void PerfTest(uint32_t writer_ratio, ThreadId* /*dummy*/, int thread_num, int64_t write_wait_time = 0; int64_t write_count = 0; for (int i = 0; i < thread_num; ++i) { - ASSERT_EQ(0, join_fn(threads[i], NULL)); + ASSERT_EQ(0, join_fn(threads[i], nullptr)); if (i < writer_num) { write_wait_time += args[i].elapse_ns; write_count += args[i].counter; @@ -643,12 +643,12 @@ void PerfTest(uint32_t writer_ratio, ThreadId* /*dummy*/, int thread_num, TEST(RWLockTest, performance) { bthread_setconcurrency(16); const int thread_num = 12; - PerfTest(0, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(0, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); - PerfTest(10, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(20, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); - PerfTest(100, (pthread_t*)NULL, thread_num, pthread_create, pthread_join); - PerfTest(100, (bthread_t*)NULL, thread_num, bthread_start_background, bthread_join); + PerfTest(0, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(0, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); + PerfTest(10, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(20, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); + PerfTest(100, (pthread_t*)nullptr, thread_num, pthread_create, pthread_join); + PerfTest(100, (bthread_t*)nullptr, thread_num, bthread_start_background, bthread_join); } @@ -674,31 +674,31 @@ void* read_thread(void* arg) { } void* write_thread(void*) { - return NULL; + return nullptr; } TEST(RWLockTest, pthread_rdlock_performance) { #ifdef CHECK_RWLOCK pthread_rwlock_t lock1; - ASSERT_EQ(0, pthread_rwlock_init(&lock1, NULL)); + ASSERT_EQ(0, pthread_rwlock_init(&lock1, nullptr)); #else pthread_mutex_t lock1; - ASSERT_EQ(0, pthread_mutex_init(&lock1, NULL)); + ASSERT_EQ(0, pthread_mutex_init(&lock1, nullptr)); #endif pthread_t rth[16]; pthread_t wth; for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) { - ASSERT_EQ(0, pthread_create(&rth[i], NULL, read_thread, &lock1)); + ASSERT_EQ(0, pthread_create(&rth[i], nullptr, read_thread, &lock1)); } - ASSERT_EQ(0, pthread_create(&wth, NULL, write_thread, &lock1)); + ASSERT_EQ(0, pthread_create(&wth, nullptr, write_thread, &lock1)); for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) { - long* res = NULL; + long* res = nullptr; pthread_join(rth[i], (void**)&res); printf("read thread %lu = %ldns\n", i, *res); delete res; } - pthread_join(wth, NULL); + pthread_join(wth, nullptr); #ifdef CHECK_RWLOCK pthread_rwlock_destroy(&lock1); #else diff --git a/test/bthread_sched_yield_unittest.cpp b/test/bthread_sched_yield_unittest.cpp index ac4e7e300d..f43a5c8e4c 100644 --- a/test/bthread_sched_yield_unittest.cpp +++ b/test/bthread_sched_yield_unittest.cpp @@ -31,7 +31,7 @@ void* spinner(void*) { cpu_relax(); } printf("spinned %ld\n", counter); - return NULL; + return nullptr; } void* yielder(void*) { @@ -40,7 +40,7 @@ void* yielder(void*) { sched_yield(); } printf("sched_yield %d\n", counter); - return NULL; + return nullptr; } TEST(SchedYieldTest, sched_yield_when_all_core_busy) { @@ -48,17 +48,17 @@ TEST(SchedYieldTest, sched_yield_when_all_core_busy) { const int kNumCores = sysconf(_SC_NPROCESSORS_ONLN); ASSERT_TRUE(kNumCores > 0); pthread_t th0; - pthread_create(&th0, NULL, yielder, NULL); + pthread_create(&th0, nullptr, yielder, nullptr); pthread_t th[kNumCores]; for (int i = 0; i < kNumCores; ++i) { - pthread_create(&th[i], NULL, spinner, NULL); + pthread_create(&th[i], nullptr, spinner, nullptr); } sleep(1); stop = true; for (int i = 0; i < kNumCores; ++i) { - pthread_join(th[i], NULL); + pthread_join(th[i], nullptr); } - pthread_join(th0, NULL); + pthread_join(th0, nullptr); } } // namespace diff --git a/test/bthread_semaphore_unittest.cpp b/test/bthread_semaphore_unittest.cpp index ef9e5e5e5d..d0391dcfcd 100644 --- a/test/bthread_semaphore_unittest.cpp +++ b/test/bthread_semaphore_unittest.cpp @@ -28,7 +28,7 @@ void* sem_waiter(void* arg) { for (size_t i = 0; i < SEM_COUNT; ++i) { bthread_sem_wait(sem); } - return NULL; + return nullptr; } void* sem_poster(void* arg) { @@ -37,7 +37,7 @@ void* sem_poster(void* arg) { for (size_t i = 0; i < SEM_COUNT; ++i) { bthread_sem_post(sem); } - return NULL; + return nullptr; } TEST(SemaphoreTest, sanity) { @@ -49,10 +49,10 @@ TEST(SemaphoreTest, sanity) { bthread_t waiter_th; bthread_t poster_th; - ASSERT_EQ(0, bthread_start_urgent(&waiter_th, NULL, sem_waiter, &sem)); - ASSERT_EQ(0, bthread_start_urgent(&poster_th, NULL, sem_poster, &sem)); - ASSERT_EQ(0, bthread_join(waiter_th, NULL)); - ASSERT_EQ(0, bthread_join(poster_th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&waiter_th, nullptr, sem_waiter, &sem)); + ASSERT_EQ(0, bthread_start_urgent(&poster_th, nullptr, sem_poster, &sem)); + ASSERT_EQ(0, bthread_join(waiter_th, nullptr)); + ASSERT_EQ(0, bthread_join(poster_th, nullptr)); ASSERT_EQ(0, bthread_sem_destroy(&sem)); } @@ -66,16 +66,16 @@ TEST(SemaphoreTest, used_in_pthread) { pthread_t waiter_th[8]; pthread_t poster_th[8]; for (auto& th : waiter_th) { - ASSERT_EQ(0, pthread_create(&th, NULL, sem_waiter, &sem)); + ASSERT_EQ(0, pthread_create(&th, nullptr, sem_waiter, &sem)); } for (auto& th : poster_th) { - ASSERT_EQ(0, pthread_create(&th, NULL, sem_poster, &sem)); + ASSERT_EQ(0, pthread_create(&th, nullptr, sem_poster, &sem)); } for (auto& th : waiter_th) { - pthread_join(th, NULL); + pthread_join(th, nullptr); } for (auto& th : poster_th) { - pthread_join(th, NULL); + pthread_join(th, nullptr); } ASSERT_EQ(0, bthread_sem_destroy(&sem)); @@ -84,15 +84,15 @@ TEST(SemaphoreTest, used_in_pthread) { void* do_timedwait(void *arg) { struct timespec t = { -2, 0 }; EXPECT_EQ(ETIMEDOUT, bthread_sem_timedwait((bthread_sem_t*)arg, &t)); - return NULL; + return nullptr; } TEST(SemaphoreTest, timedwait) { bthread_sem_t sem; ASSERT_EQ(0, bthread_sem_init(&sem, 0)); bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_timedwait, &sem)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_timedwait, &sem)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_sem_destroy(&sem)); } @@ -105,7 +105,7 @@ struct TryWaitArgs { void* do_trywait(void *arg) { auto trylock_args = (TryWaitArgs*)arg; EXPECT_EQ(trylock_args->rc, bthread_sem_trywait(trylock_args->sem)); - return NULL; + return nullptr; } TEST(SemaphoreTest, trywait) { @@ -120,11 +120,11 @@ TEST(SemaphoreTest, trywait) { ASSERT_EQ(0, bthread_sem_post(&sem)); bthread_t th; TryWaitArgs args{ &sem, 0}; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_trywait, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_trywait, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); args.rc = EAGAIN; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, do_trywait, &args)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, do_trywait, &args)); + ASSERT_EQ(0, bthread_join(th, nullptr)); ASSERT_EQ(0, bthread_sem_destroy(&sem)); } @@ -157,7 +157,7 @@ void* loop_until_stopped(void* arg) { for (size_t i = 0; i < SEM_COUNT; ++i) { args->op(args->sem, 20); } - return NULL; + return nullptr; } TEST(SemaphoreTest, mix_thread_types) { @@ -182,7 +182,7 @@ TEST(SemaphoreTest, mix_thread_types) { } else { args.push_back({ &sem, post_op }); } - ASSERT_EQ(0, pthread_create(&pthreads[i], NULL, loop_until_stopped, &args.back())); + ASSERT_EQ(0, pthread_create(&pthreads[i], nullptr, loop_until_stopped, &args.back())); } for (int i = 0; i < M; ++i) { @@ -191,14 +191,14 @@ TEST(SemaphoreTest, mix_thread_types) { } else { args.push_back({ &sem, post_op }); } - const bthread_attr_t* attr = i % 2 ? NULL : &BTHREAD_ATTR_PTHREAD; + const bthread_attr_t* attr = i % 2 ? nullptr : &BTHREAD_ATTR_PTHREAD; ASSERT_EQ(0, bthread_start_urgent(&bthreads[i], attr, loop_until_stopped, &args.back())); } for (bthread_t bthread : bthreads) { - bthread_join(bthread, NULL); + bthread_join(bthread, nullptr); } for (pthread_t pthread : pthreads) { - pthread_join(pthread, NULL); + pthread_join(pthread, nullptr); } ASSERT_EQ(0, bthread_sem_destroy(&sem)); diff --git a/test/bthread_setconcurrency_unittest.cpp b/test/bthread_setconcurrency_unittest.cpp index 0843918f0e..e07239e87b 100644 --- a/test/bthread_setconcurrency_unittest.cpp +++ b/test/bthread_setconcurrency_unittest.cpp @@ -33,7 +33,7 @@ namespace bthread { namespace { void* dummy(void*) { - return NULL; + return nullptr; } TEST(BthreadTest, setconcurrency) { @@ -48,7 +48,7 @@ TEST(BthreadTest, setconcurrency) { ASSERT_EQ(BTHREAD_MIN_CONCURRENCY + 1, bthread_getconcurrency()); ASSERT_EQ(0, bthread_setconcurrency(BTHREAD_MIN_CONCURRENCY)); // smaller value bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, dummy, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, dummy, nullptr)); ASSERT_EQ(BTHREAD_MIN_CONCURRENCY + 1, bthread_getconcurrency()); ASSERT_EQ(0, bthread_setconcurrency(BTHREAD_MIN_CONCURRENCY + 5)); ASSERT_EQ(BTHREAD_MIN_CONCURRENCY + 5, bthread_getconcurrency()); @@ -72,9 +72,9 @@ static void *odd_thread(void *) { npthreads.fetch_add(1); } bthread::butex_wake_all(even); - bthread::butex_wait(odd, 0, NULL); + bthread::butex_wait(odd, 0, nullptr); } - return NULL; + return nullptr; } static void *even_thread(void *) { @@ -85,24 +85,24 @@ static void *even_thread(void *) { npthreads.fetch_add(1); } bthread::butex_wake_all(odd); - bthread::butex_wait(even, 0, NULL); + bthread::butex_wait(even, 0, nullptr); } - return NULL; + return nullptr; } TEST(BthreadTest, setconcurrency_with_running_bthread) { odd = bthread::butex_create_checked >(); even = bthread::butex_create_checked >(); - ASSERT_TRUE(odd != NULL && even != NULL); + ASSERT_TRUE(odd != nullptr && even != nullptr); *odd = 0; *even = 0; std::vector tids; const int N = 200; for (int i = 0; i < N; ++i) { bthread_t tid; - bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, odd_thread, NULL); + bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, odd_thread, nullptr); tids.push_back(tid); - bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, even_thread, NULL); + bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, even_thread, nullptr); tids.push_back(tid); } for (int i = 100; i <= N; ++i) { @@ -116,7 +116,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) { bthread::butex_wake_all(odd); bthread::butex_wake_all(even); for (size_t i = 0; i < tids.size(); ++i) { - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } LOG(INFO) << "All bthreads has quit"; ASSERT_EQ(2*N, nbthreads); @@ -127,14 +127,14 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) { void* sleep_proc(void*) { usleep(100000); - return NULL; + return nullptr; } void* add_concurrency_proc(void*) { bthread_t tid; - bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, sleep_proc, NULL); - bthread_join(tid, NULL); - return NULL; + bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, sleep_proc, nullptr); + bthread_join(tid, nullptr); + return nullptr; } bool set_min_concurrency(int num) { @@ -176,16 +176,16 @@ TEST(BthreadTest, min_concurrency) { std::vector tids; for (int i = 0; i < conn; ++i) { bthread_t tid; - bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, sleep_proc, NULL); + bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, sleep_proc, nullptr); tids.push_back(tid); } for (int i = 0; i < add_conn; ++i) { bthread_t tid; - bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, add_concurrency_proc, NULL); + bthread_start_background(&tid, &BTHREAD_ATTR_SMALL, add_concurrency_proc, nullptr); tids.push_back(tid); } for (size_t i = 0; i < tids.size(); ++i) { - bthread_join(tids[i], NULL); + bthread_join(tids[i], nullptr); } ASSERT_EQ(conn + add_conn, bthread_getconcurrency()); ASSERT_EQ(conn + add_conn, bthread::g_task_control->concurrency()); diff --git a/test/bthread_timer_thread_unittest.cpp b/test/bthread_timer_thread_unittest.cpp index c8d70ce35b..c37c74cab5 100644 --- a/test/bthread_timer_thread_unittest.cpp +++ b/test/bthread_timer_thread_unittest.cpp @@ -36,7 +36,7 @@ long timespec_diff_us(const timespec& ts1, const timespec& ts2) { class TimeKeeper { public: TimeKeeper(timespec run_time) - : _expect_run_time(run_time), _name(NULL), _sleep_ms(0) {} + : _expect_run_time(run_time), _name(nullptr), _sleep_ms(0) {} TimeKeeper(timespec run_time, const char* name/*must be string constant*/) : _expect_run_time(run_time), _name(name), _sleep_ms(0) {} TimeKeeper(timespec run_time, const char* name/*must be string constant*/, @@ -109,7 +109,7 @@ class TimeKeeper { TEST(TimerThreadTest, RunTasks) { bthread::TimerThread timer_thread; - ASSERT_EQ(0, timer_thread.start(NULL)); + ASSERT_EQ(0, timer_thread.start(nullptr)); timespec _2s_later = butil::seconds_from_now(2); TimeKeeper keeper1(_2s_later, "keeper1"); @@ -167,7 +167,7 @@ TEST(TimerThreadTest, start_after_schedule) { TimeKeeper keeper(past_time, "keeper1"); keeper.schedule(&timer_thread); ASSERT_EQ(bthread::TimerThread::INVALID_TASK_ID, keeper._task_id); - ASSERT_EQ(0, timer_thread.start(NULL)); + ASSERT_EQ(0, timer_thread.start(nullptr)); keeper.schedule(&timer_thread); ASSERT_NE(bthread::TimerThread::INVALID_TASK_ID, keeper._task_id); timespec current_time = butil::seconds_from_now(0); @@ -221,7 +221,7 @@ TEST(TimerThreadTest, schedule_and_unschedule_in_task) { TimeKeeper keeper4(past_time, "keeper4"); TimeKeeper keeper5(_500ms_after, "keeper5", 10000/*10s*/); - ASSERT_EQ(0, timer_thread.start(NULL)); + ASSERT_EQ(0, timer_thread.start(nullptr)); keeper1.schedule(&timer_thread); // start keeper1 keeper3.schedule(&timer_thread); // start keeper3 timespec keeper3_addtime = butil::seconds_from_now(0); @@ -288,7 +288,7 @@ TEST(TimerThreadTest, sweep_unscheduled_tasks_in_heap) { ScopedFlag sweep_flag("brpc_timer_heap_sweep_min_size", "512"); bthread::TimerThread timer_thread; - ASSERT_EQ(0, timer_thread.start(NULL)); + ASSERT_EQ(0, timer_thread.start(nullptr)); // Run far enough in the future that these tasks never fire on their own. const timespec far = butil::seconds_from_now(100000); @@ -300,11 +300,11 @@ TEST(TimerThreadTest, sweep_unscheduled_tasks_in_heap) { std::vector ids; ids.reserve(kBatch); for (size_t i = 0; i < kBatch; ++i) { - ids.push_back(timer_thread.schedule(noop_routine, NULL, far)); + ids.push_back(timer_thread.schedule(noop_routine, nullptr, far)); } // A near-term task forces the timer thread to wake up and consume the // buckets, so the far tasks above land in the heap (alive). - timer_thread.schedule(noop_routine, NULL, + timer_thread.schedule(noop_routine, nullptr, butil::milliseconds_from_now(1)); usleep(20000); // let the timer thread consume the buckets @@ -315,7 +315,7 @@ TEST(TimerThreadTest, sweep_unscheduled_tasks_in_heap) { } // Another near-term task wakes the timer thread again, triggering the // sweep that reclaims the dead tasks. - timer_thread.schedule(noop_routine, NULL, + timer_thread.schedule(noop_routine, nullptr, butil::milliseconds_from_now(1)); usleep(20000); @@ -346,12 +346,12 @@ TEST(TimerThreadTest, periodic_wakeup_drains_buckets) { ScopedFlag wakeup_flag("brpc_timer_max_wakeup_interval_ms", "50"); bthread::TimerThread timer_thread; - ASSERT_EQ(0, timer_thread.start(NULL)); + ASSERT_EQ(0, timer_thread.start(nullptr)); // Anchor task an hour out: it becomes the nearest task, so the tasks below // (with even later run_times) are never the "earliest" and thus never wake // the timer via schedule() -- only the periodic wakeup can drain them. - timer_thread.schedule(noop_routine, NULL, butil::seconds_from_now(3600)); + timer_thread.schedule(noop_routine, nullptr, butil::seconds_from_now(3600)); usleep(100000); // let the anchor be consumed into the heap // Only the anchor is in the heap so far. ASSERT_EQ(1, timer_thread._npending.load(butil::memory_order_relaxed)); @@ -360,7 +360,7 @@ TEST(TimerThreadTest, periodic_wakeup_drains_buckets) { // of these wake the timer. const int kN = 2000; for (int i = 0; i < kN; ++i) { - timer_thread.schedule(noop_routine, NULL, + timer_thread.schedule(noop_routine, nullptr, butil::seconds_from_now(3600 + 1 + i)); } diff --git a/test/bthread_unittest.cpp b/test/bthread_unittest.cpp index b6d5ca7f6e..2d1afa0011 100644 --- a/test/bthread_unittest.cpp +++ b/test/bthread_unittest.cpp @@ -67,8 +67,8 @@ void* unrelated_pthread(void*) { TEST_F(BthreadTest, unrelated_pthread) { pthread_t th; - ASSERT_EQ(0, pthread_create(&th, NULL, unrelated_pthread, NULL)); - void* ret = NULL; + ASSERT_EQ(0, pthread_create(&th, nullptr, unrelated_pthread, nullptr)); + void* ret = nullptr; ASSERT_EQ(0, pthread_join(th, &ret)); ASSERT_EQ(1, (intptr_t)ret); } @@ -89,7 +89,7 @@ static void f(intptr_t param) { } TEST_F(BthreadTest, context_sanity) { - fcm = NULL; + fcm = nullptr; std::size_t size(8192); void* sp = malloc(size); @@ -106,7 +106,7 @@ TEST_F(BthreadTest, context_sanity) { TEST_F(BthreadTest, call_bthread_functions_before_tls_created) { ASSERT_EQ(0, bthread_usleep(1000)); - ASSERT_EQ(EINVAL, bthread_join(0, NULL)); + ASSERT_EQ(EINVAL, bthread_join(0, nullptr)); ASSERT_EQ(0UL, bthread_self()); } @@ -117,14 +117,14 @@ void* sleep_for_awhile(void* arg) { LOG(INFO) << "sleep_for_awhile(" << arg << ")"; bthread_usleep(100000L); LOG(INFO) << "sleep_for_awhile(" << arg << ") wakes up"; - return NULL; + return nullptr; } void* just_exit(void* arg) { LOG(INFO) << "just_exit(" << arg << ")"; - bthread_exit(NULL); + bthread_exit(nullptr); EXPECT_TRUE(false) << "just_exit(" << arg << ") should never be here"; - return NULL; + return nullptr; } void* repeated_sleep(void* arg) { @@ -133,7 +133,7 @@ void* repeated_sleep(void* arg) { LOG(INFO) << "repeated_sleep(" << arg << ") i=" << i; bthread_usleep(1000000L); } - return NULL; + return nullptr; } void* spin_and_log(void* arg) { @@ -146,22 +146,22 @@ void* spin_and_log(void* arg) { LOG(INFO) << "spin_and_log(" << arg << ")=" << i++; } } - return NULL; + return nullptr; } void* do_nothing(void* arg) { LOG(INFO) << "do_nothing(" << arg << ")"; - return NULL; + return nullptr; } void* launcher(void* arg) { LOG(INFO) << "launcher(" << arg << ")"; for (size_t i = 0; !stop; ++i) { bthread_t th; - bthread_start_urgent(&th, NULL, do_nothing, (void*)i); + bthread_start_urgent(&th, nullptr, do_nothing, (void*)i); bthread_usleep(1000000L); } - return NULL; + return nullptr; } void* stopper(void*) { @@ -171,32 +171,32 @@ void* stopper(void*) { bthread_usleep(5*1000000L); LOG(INFO) << "about to stop"; stop = true; - return NULL; + return nullptr; } void* misc(void* arg) { LOG(INFO) << "misc(" << arg << ")"; bthread_t th[8]; - EXPECT_EQ(0, bthread_start_urgent(&th[0], NULL, sleep_for_awhile, (void*)2)); - EXPECT_EQ(0, bthread_start_urgent(&th[1], NULL, just_exit, (void*)3)); - EXPECT_EQ(0, bthread_start_urgent(&th[2], NULL, repeated_sleep, (void*)4)); - EXPECT_EQ(0, bthread_start_urgent(&th[3], NULL, repeated_sleep, (void*)68)); - EXPECT_EQ(0, bthread_start_urgent(&th[4], NULL, spin_and_log, (void*)5)); - EXPECT_EQ(0, bthread_start_urgent(&th[5], NULL, spin_and_log, (void*)85)); - EXPECT_EQ(0, bthread_start_urgent(&th[6], NULL, launcher, (void*)6)); - EXPECT_EQ(0, bthread_start_urgent(&th[7], NULL, stopper, NULL)); + EXPECT_EQ(0, bthread_start_urgent(&th[0], nullptr, sleep_for_awhile, (void*)2)); + EXPECT_EQ(0, bthread_start_urgent(&th[1], nullptr, just_exit, (void*)3)); + EXPECT_EQ(0, bthread_start_urgent(&th[2], nullptr, repeated_sleep, (void*)4)); + EXPECT_EQ(0, bthread_start_urgent(&th[3], nullptr, repeated_sleep, (void*)68)); + EXPECT_EQ(0, bthread_start_urgent(&th[4], nullptr, spin_and_log, (void*)5)); + EXPECT_EQ(0, bthread_start_urgent(&th[5], nullptr, spin_and_log, (void*)85)); + EXPECT_EQ(0, bthread_start_urgent(&th[6], nullptr, launcher, (void*)6)); + EXPECT_EQ(0, bthread_start_urgent(&th[7], nullptr, stopper, nullptr)); for (size_t i = 0; i < ARRAY_SIZE(th); ++i) { - EXPECT_EQ(0, bthread_join(th[i], NULL)); + EXPECT_EQ(0, bthread_join(th[i], nullptr)); } - return NULL; + return nullptr; } TEST_F(BthreadTest, sanity) { LOG(INFO) << "main thread " << pthread_self(); bthread_t th1; - ASSERT_EQ(0, bthread_start_urgent(&th1, NULL, misc, (void*)1)); + ASSERT_EQ(0, bthread_start_urgent(&th1, nullptr, misc, (void*)1)); LOG(INFO) << "back to main thread " << th1 << " " << pthread_self(); - ASSERT_EQ(0, bthread_join(th1, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); } const size_t BT_SIZE = 64; @@ -216,13 +216,13 @@ void * tf (void*) { if (call_do_bt () != 57) { return (void *) 1L; } - return NULL; + return nullptr; } TEST_F(BthreadTest, backtrace) { bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, tf, NULL)); - ASSERT_EQ(0, bthread_join (th, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, tf, nullptr)); + ASSERT_EQ(0, bthread_join (th, nullptr)); char **text = backtrace_symbols (bt_array, bt_cnt); ASSERT_TRUE(text); @@ -235,42 +235,42 @@ TEST_F(BthreadTest, backtrace) { void* show_self(void*) { EXPECT_NE(0ul, bthread_self()); LOG(INFO) << "bthread_self=" << bthread_self(); - return NULL; + return nullptr; } TEST_F(BthreadTest, bthread_self) { ASSERT_EQ(0ul, bthread_self()); bthread_t bth; - ASSERT_EQ(0, bthread_start_urgent(&bth, NULL, show_self, NULL)); - ASSERT_EQ(0, bthread_join(bth, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&bth, nullptr, show_self, nullptr)); + ASSERT_EQ(0, bthread_join(bth, nullptr)); } void* join_self(void*) { - EXPECT_EQ(EINVAL, bthread_join(bthread_self(), NULL)); - return NULL; + EXPECT_EQ(EINVAL, bthread_join(bthread_self(), nullptr)); + return nullptr; } TEST_F(BthreadTest, bthread_join) { // Invalid tid - ASSERT_EQ(EINVAL, bthread_join(0, NULL)); + ASSERT_EQ(EINVAL, bthread_join(0, nullptr)); // Unexisting tid - ASSERT_EQ(EINVAL, bthread_join((bthread_t)-1, NULL)); + ASSERT_EQ(EINVAL, bthread_join((bthread_t)-1, nullptr)); // Joining self bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, join_self, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, join_self, nullptr)); } void* change_errno(void* arg) { errno = (intptr_t)arg; - return NULL; + return nullptr; } TEST_F(BthreadTest, errno_not_changed) { bthread_t th; errno = 1; - bthread_start_urgent(&th, NULL, change_errno, (void*)(intptr_t)2); + bthread_start_urgent(&th, nullptr, change_errno, (void*)(intptr_t)2); ASSERT_EQ(1, errno); } @@ -290,7 +290,7 @@ void* adding_func(void* arg) { } else { s->fetch_add(1); } - return NULL; + return nullptr; } TEST_F(BthreadTest, small_threads) { @@ -325,7 +325,7 @@ TEST_F(BthreadTest, small_threads) { ProfilerStop(); } for (size_t i = 0; i < N; ++i) { - bthread_join(th[i], NULL); + bthread_join(th[i], nullptr); } LOG(INFO) << "[Round " << j + 1 << "] bthread_start_urgent takes " << tm.n_elapsed()/N << "ns, sum=" << s; @@ -342,13 +342,13 @@ void* bthread_starter(void* void_counter) { std::vector ths; while (!stop.load(butil::memory_order_relaxed)) { bthread_t th; - EXPECT_EQ(0, bthread_start_urgent(&th, NULL, adding_func, void_counter)); + EXPECT_EQ(0, bthread_start_urgent(&th, nullptr, adding_func, void_counter)); ths.push_back(th); } for (size_t i = 0; i < ths.size(); ++i) { - EXPECT_EQ(0, bthread_join(ths[i], NULL)); + EXPECT_EQ(0, bthread_join(ths[i], nullptr)); } - return NULL; + return nullptr; } struct BAIDU_CACHELINE_ALIGNMENT AlignedCounter { @@ -372,14 +372,14 @@ TEST_F(BthreadTest, start_bthreads_frequently) { for (int i = 0; i < cur_con; ++i) { counters[i].value = 0; ASSERT_EQ(0, bthread_start_urgent( - &th[i], NULL, bthread_starter, &counters[i].value)); + &th[i], nullptr, bthread_starter, &counters[i].value)); } butil::Timer tm; tm.start(); bthread_usleep(200000L); stop = true; for (int i = 0; i < cur_con; ++i) { - bthread_join(th[i], NULL); + bthread_join(th[i], nullptr); } tm.stop(); size_t sum = 0; @@ -396,7 +396,7 @@ TEST_F(BthreadTest, start_bthreads_frequently) { void* log_start_latency(void* void_arg) { butil::Timer* tm = static_cast(void_arg); tm->stop(); - return NULL; + return nullptr; } TEST_F(BthreadTest, start_latency_when_high_idle) { @@ -408,13 +408,13 @@ TEST_F(BthreadTest, start_latency_when_high_idle) { butil::Timer tm; tm.start(); bthread_t th; - bthread_start_urgent(&th, NULL, log_start_latency, &tm); - bthread_join(th, NULL); + bthread_start_urgent(&th, nullptr, log_start_latency, &tm); + bthread_join(th, nullptr); bthread_t th2; butil::Timer tm2; tm2.start(); - bthread_start_background(&th2, NULL, log_start_latency, &tm2); - bthread_join(th2, NULL); + bthread_start_background(&th2, nullptr, log_start_latency, &tm2); + bthread_join(th2, nullptr); if (!warmup) { ++REP; elp1 += tm.n_elapsed(); @@ -429,18 +429,18 @@ TEST_F(BthreadTest, start_latency_when_high_idle) { void* sleep_for_awhile_with_sleep(void* arg) { bthread_usleep((intptr_t)arg); - return NULL; + return nullptr; } TEST_F(BthreadTest, stop_sleep) { bthread_t th; ASSERT_EQ(0, bthread_start_urgent( - &th, NULL, sleep_for_awhile_with_sleep, (void*)1000000L)); + &th, nullptr, sleep_for_awhile_with_sleep, (void*)1000000L)); butil::Timer tm; tm.start(); bthread_usleep(10000); ASSERT_EQ(0, bthread_stop(th)); - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); tm.stop(); ASSERT_LE(labs(tm.m_elapsed() - 10), 10); } @@ -453,34 +453,34 @@ TEST_F(BthreadTest, bthread_exit) { bthread_t th5; const bthread_attr_t attr = BTHREAD_ATTR_PTHREAD; - ASSERT_EQ(0, bthread_start_urgent(&th1, NULL, just_exit, NULL)); - ASSERT_EQ(0, bthread_start_background(&th2, NULL, just_exit, NULL)); - ASSERT_EQ(0, pthread_create(&th3, NULL, just_exit, NULL)); - EXPECT_EQ(0, bthread_start_urgent(&th4, &attr, just_exit, NULL)); - EXPECT_EQ(0, bthread_start_background(&th5, &attr, just_exit, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th1, nullptr, just_exit, nullptr)); + ASSERT_EQ(0, bthread_start_background(&th2, nullptr, just_exit, nullptr)); + ASSERT_EQ(0, pthread_create(&th3, nullptr, just_exit, nullptr)); + EXPECT_EQ(0, bthread_start_urgent(&th4, &attr, just_exit, nullptr)); + EXPECT_EQ(0, bthread_start_background(&th5, &attr, just_exit, nullptr)); - ASSERT_EQ(0, bthread_join(th1, NULL)); - ASSERT_EQ(0, bthread_join(th2, NULL)); - ASSERT_EQ(0, pthread_join(th3, NULL)); - ASSERT_EQ(0, bthread_join(th4, NULL)); - ASSERT_EQ(0, bthread_join(th5, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); + ASSERT_EQ(0, bthread_join(th2, nullptr)); + ASSERT_EQ(0, pthread_join(th3, nullptr)); + ASSERT_EQ(0, bthread_join(th4, nullptr)); + ASSERT_EQ(0, bthread_join(th5, nullptr)); } TEST_F(BthreadTest, bthread_equal) { bthread_t th1; - ASSERT_EQ(0, bthread_start_urgent(&th1, NULL, do_nothing, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th1, nullptr, do_nothing, nullptr)); bthread_t th2; - ASSERT_EQ(0, bthread_start_urgent(&th2, NULL, do_nothing, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&th2, nullptr, do_nothing, nullptr)); ASSERT_EQ(0, bthread_equal(th1, th2)); bthread_t th3 = th2; ASSERT_EQ(1, bthread_equal(th3, th2)); - ASSERT_EQ(0, bthread_join(th1, NULL)); - ASSERT_EQ(0, bthread_join(th2, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); + ASSERT_EQ(0, bthread_join(th2, nullptr)); } void* mark_run(void* run) { *static_cast(run) = pthread_self(); - return NULL; + return nullptr; } void* check_sleep(void* pthread_task) { @@ -506,12 +506,12 @@ void* check_sleep(void* pthread_task) { // current thread. EXPECT_EQ(pid, run); // should run in the same pthread } - EXPECT_EQ(0, bthread_join(th1, NULL)); + EXPECT_EQ(0, bthread_join(th1, nullptr)); if (pthread_task) { EXPECT_EQ(pid, pthread_self()); EXPECT_NE((pthread_t)0, run); // the mark_run should run. } - return NULL; + return nullptr; } TEST_F(BthreadTest, bthread_usleep) { @@ -522,29 +522,29 @@ TEST_F(BthreadTest, bthread_usleep) { bthread_t th1; ASSERT_EQ(0, bthread_start_urgent(&th1, &BTHREAD_ATTR_PTHREAD, check_sleep, (void*)1)); - ASSERT_EQ(0, bthread_join(th1, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); bthread_t th2; - ASSERT_EQ(0, bthread_start_urgent(&th2, NULL, + ASSERT_EQ(0, bthread_start_urgent(&th2, nullptr, check_sleep, (void*)0)); - ASSERT_EQ(0, bthread_join(th2, NULL)); + ASSERT_EQ(0, bthread_join(th2, nullptr)); } static const bthread_attr_t BTHREAD_ATTR_NORMAL_WITH_SPAN = -{ BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, NULL, BTHREAD_TAG_INVALID }; +{ BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, nullptr, BTHREAD_TAG_INVALID }; void* test_parent_span(void* p) { uint64_t *q = (uint64_t *)p; *q = (uint64_t)(bthread::tls_bls_ptr()->rpcz_parent_span); LOG(INFO) << "span id in thread is " << *q; - return NULL; + return nullptr; } void* test_grandson_parent_span(void* p) { uint64_t* q = (uint64_t*)p; *q = (uint64_t)(bthread::tls_bls_ptr()->rpcz_parent_span); LOG(INFO) << "parent span id in thread is " << *q; - return NULL; + return nullptr; } void* test_son_parent_span(void* p) { @@ -554,8 +554,8 @@ void* test_son_parent_span(void* p) { bthread_t th; uint64_t multi_p; bthread_start_urgent(&th, &BTHREAD_ATTR_NORMAL_WITH_SPAN, test_grandson_parent_span, &multi_p); - bthread_join(th, NULL); - return NULL; + bthread_join(th, nullptr); + return nullptr; } static uint64_t targets[] = {0xBADBEB0UL, 0xBADBEB1UL, 0xBADBEB2UL, 0xBADBEB3UL}; @@ -583,11 +583,11 @@ TEST_F(BthreadTest, test_span) { bthread::tls_bls_ptr()->rpcz_parent_span = (void*)target; bthread_t th1; ASSERT_EQ(0, bthread_start_urgent(&th1, &BTHREAD_ATTR_NORMAL_WITH_SPAN, test_parent_span, &p1)); - ASSERT_EQ(0, bthread_join(th1, NULL)); + ASSERT_EQ(0, bthread_join(th1, nullptr)); bthread_t th2; - ASSERT_EQ(0, bthread_start_background(&th2, NULL, test_parent_span, &p2)); - ASSERT_EQ(0, bthread_join(th2, NULL)); + ASSERT_EQ(0, bthread_start_background(&th2, nullptr, test_parent_span, &p2)); + ASSERT_EQ(0, bthread_join(th2, nullptr)); ASSERT_EQ(p1, target); ASSERT_NE(p2, target); @@ -604,36 +604,36 @@ TEST_F(BthreadTest, test_span) { test_son_parent_span, &multi_p1)); ASSERT_EQ(0, bthread_start_background(&multi_th2, &BTHREAD_ATTR_NORMAL_WITH_SPAN, test_son_parent_span, &multi_p2)); - ASSERT_EQ(0, bthread_join(multi_th1, NULL)); - ASSERT_EQ(0, bthread_join(multi_th2, NULL)); + ASSERT_EQ(0, bthread_join(multi_th1, nullptr)); + ASSERT_EQ(0, bthread_join(multi_th2, nullptr)); ASSERT_NE(multi_p1, multi_p2); ASSERT_NE(std::find(targets, targets + 4, multi_p1), targets + 4); ASSERT_NE(std::find(targets, targets + 4, multi_p2), targets + 4); - ASSERT_EQ(0, bthread_set_span_funcs(NULL, NULL, NULL)); + ASSERT_EQ(0, bthread_set_span_funcs(nullptr, nullptr, nullptr)); } void* dummy_thread(void*) { - return NULL; + return nullptr; } TEST_F(BthreadTest, too_many_nosignal_threads) { for (size_t i = 0; i < 100000; ++i) { bthread_attr_t attr = BTHREAD_ATTR_NORMAL | BTHREAD_NOSIGNAL; bthread_t tid; - ASSERT_EQ(0, bthread_start_urgent(&tid, &attr, dummy_thread, NULL)); + ASSERT_EQ(0, bthread_start_urgent(&tid, &attr, dummy_thread, nullptr)); } } static void* yield_thread(void*) { bthread_yield(); - return NULL; + return nullptr; } TEST_F(BthreadTest, yield_single_thread) { bthread_t tid; - ASSERT_EQ(0, bthread_start_background(&tid, NULL, yield_thread, NULL)); - ASSERT_EQ(0, bthread_join(tid, NULL)); + ASSERT_EQ(0, bthread_start_background(&tid, nullptr, yield_thread, nullptr)); + ASSERT_EQ(0, bthread_join(tid, nullptr)); } #ifdef BRPC_BTHREAD_TRACER @@ -643,7 +643,7 @@ void spin_and_log_trace() { start = false; stop = false; bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, spin_and_log, (void*)1)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, spin_and_log, (void*)1)); while (!start) { usleep(10 * 1000); } @@ -653,7 +653,7 @@ void spin_and_log_trace() { ok = st1.find("spin_and_log") != std::string::npos; stop = true; - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); std::string st2 = bthread::stack_trace(th); LOG(INFO) << "ended bthread stack trace:\n" << st2; @@ -672,7 +672,7 @@ void repeated_sleep_trace() { start = false; stop = false; bthread_t th; - ASSERT_EQ(0, bthread_start_urgent(&th, NULL, repeated_sleep, (void*)1)); + ASSERT_EQ(0, bthread_start_urgent(&th, nullptr, repeated_sleep, (void*)1)); while (!start) { usleep(10 * 1000); } @@ -682,7 +682,7 @@ void repeated_sleep_trace() { ok = st1.find("repeated_sleep") != std::string::npos; stop = true; - ASSERT_EQ(0, bthread_join(th, NULL)); + ASSERT_EQ(0, bthread_join(th, nullptr)); std::string st2 = bthread::stack_trace(th); LOG(INFO) << "ended bthread stack trace:\n" << st2; diff --git a/test/bthread_work_stealing_queue_unittest.cpp b/test/bthread_work_stealing_queue_unittest.cpp index a8b110371d..c6738e8208 100644 --- a/test/bthread_work_stealing_queue_unittest.cpp +++ b/test/bthread_work_stealing_queue_unittest.cpp @@ -63,7 +63,7 @@ void* push_thread(void* arg) { } } } - return NULL; + return nullptr; } void* pop_thread(void* arg) { @@ -90,24 +90,24 @@ TEST(WSQTest, sanity) { pthread_t rth[8]; pthread_t wth, pop_th; for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) { - ASSERT_EQ(0, pthread_create(&rth[i], NULL, steal_thread, &q)); + ASSERT_EQ(0, pthread_create(&rth[i], nullptr, steal_thread, &q)); } - ASSERT_EQ(0, pthread_create(&wth, NULL, push_thread, &q)); - ASSERT_EQ(0, pthread_create(&pop_th, NULL, pop_thread, &q)); + ASSERT_EQ(0, pthread_create(&wth, nullptr, push_thread, &q)); + ASSERT_EQ(0, pthread_create(&pop_th, nullptr, pop_thread, &q)); std::vector values; values.reserve(N); size_t nstolen = 0, npopped = 0; for (size_t i = 0; i < ARRAY_SIZE(rth); ++i) { - std::vector* res = NULL; + std::vector* res = nullptr; pthread_join(rth[i], (void**)&res); for (size_t j = 0; j < res->size(); ++j, ++nstolen) { values.push_back((*res)[j]); } delete res; } - pthread_join(wth, NULL); - std::vector* res = NULL; + pthread_join(wth, nullptr); + std::vector* res = nullptr; pthread_join(pop_th, (void**)&res); for (size_t j = 0; j < res->size(); ++j, ++npopped) { values.push_back((*res)[j]); diff --git a/test/bvar_agent_group_unittest.cpp b/test/bvar_agent_group_unittest.cpp index 8d9eaff91f..925aba78b4 100644 --- a/test/bvar_agent_group_unittest.cpp +++ b/test/bvar_agent_group_unittest.cpp @@ -49,9 +49,9 @@ class AgentGroupTest : public testing::Test { static void *thread_counter(void *arg) { int id = (int)((long)arg); agent_type *item = AgentGroup::get_or_create_tls_agent(id); - if (item == NULL) { + if (item == nullptr) { EXPECT_TRUE(false); - return NULL; + return nullptr; } butil::Timer timer; timer.start(); @@ -77,7 +77,7 @@ TEST_F(AgentGroupTest, test_sanity) { int id = AgentGroup::create_new_agent(); ASSERT_TRUE(id >= 0) << id; agent_type *element = AgentGroup::get_or_create_tls_agent(id); - ASSERT_TRUE(element != NULL); + ASSERT_TRUE(element != nullptr); AgentGroup::destroy_agent(id); } @@ -107,7 +107,7 @@ TEST_F(AgentGroupTest, test_perf) { for (size_t j = 0; j < id_num; ++j) { agent_type *agent = AgentGroup::get_or_create_tls_agent(ids[j]); - ASSERT_TRUE(agent != NULL) << ids[j]; + ASSERT_TRUE(agent != nullptr) << ids[j]; } } timer.stop(); @@ -124,7 +124,7 @@ TEST_F(AgentGroupTest, test_all_perf) { ASSERT_TRUE(id >= 0) << id; pthread_t threads[24]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &thread_counter, (void *)id); + pthread_create(&threads[i], nullptr, &thread_counter, (void *)id); } long totol_time = 0; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { @@ -137,7 +137,7 @@ TEST_F(AgentGroupTest, test_all_perf) { totol_time = 0; g_counter.store(0, butil::memory_order_relaxed); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, global_add, (void *)id); + pthread_create(&threads[i], nullptr, global_add, (void *)id); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { void *ret; diff --git a/test/bvar_lock_timer_unittest.cpp b/test/bvar_lock_timer_unittest.cpp index c4299b55d3..63846697a5 100644 --- a/test/bvar_lock_timer_unittest.cpp +++ b/test/bvar_lock_timer_unittest.cpp @@ -111,7 +111,7 @@ TEST_F(LockTimerTest, pthread_mutex_and_cond) { ASSERT_EQ(1u, recorder.count()); timespec due_time = butil::milliseconds_from_now(10); pthread_cond_t cond; - ASSERT_EQ(0, pthread_cond_init(&cond, NULL)); + ASSERT_EQ(0, pthread_cond_init(&cond, nullptr)); pthread_cond_timedwait(&cond, &(pthread_mutex_t&)mutex, &due_time); pthread_cond_timedwait(&cond, &mutex.mutex(), &due_time); ASSERT_EQ(0, pthread_cond_destroy(&cond)); @@ -130,7 +130,7 @@ void *signal_lock_thread(void *arg) { usleep(10); } } - return NULL; + return nullptr; } TEST_F(LockTimerTest, signal_lock_time) { @@ -138,22 +138,22 @@ TEST_F(LockTimerTest, signal_lock_time) { MutexWithRecorder m0(r0); pthread_t threads[4]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, signal_lock_thread >, &m0)); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } LOG(INFO) << r0; ASSERT_EQ(OPS_PER_THREAD * ARRAY_SIZE(threads), (size_t)r0.get_value().num); LatencyRecorder r1; MutexWithLatencyRecorder m1(r1); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, signal_lock_thread >, &m1)); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } LOG(INFO) << r1._latency; ASSERT_EQ(OPS_PER_THREAD * ARRAY_SIZE(threads), (size_t)r1.count()); @@ -174,7 +174,7 @@ void *double_lock_thread(void *arg) { butil::double_lock(lck0, lck1); usleep(10); } - return NULL; + return nullptr; } TEST_F(LockTimerTest, double_lock_time) { @@ -187,11 +187,11 @@ TEST_F(LockTimerTest, double_lock_time) { arg.m1.set_recorder(r1); pthread_t threads[4]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, double_lock_thread, &arg)); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } ASSERT_EQ(OPS_PER_THREAD * ARRAY_SIZE(threads), (size_t)r0.get_value().num); ASSERT_EQ(OPS_PER_THREAD * ARRAY_SIZE(threads), (size_t)r1.count()); @@ -207,11 +207,11 @@ TEST_F(LockTimerTest, double_lock_time) { arg1.m0.set_recorder(r1); arg1.m1.set_recorder(r0); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, double_lock_thread, &arg1)); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } #if !WITH_BABYLON_COUNTER ASSERT_EQ(OPS_PER_THREAD * ARRAY_SIZE(threads), (size_t)r0.get_value().num); diff --git a/test/bvar_multi_dimension_unittest.cpp b/test/bvar_multi_dimension_unittest.cpp index a04ab4b78e..aa37e6e485 100644 --- a/test/bvar_multi_dimension_unittest.cpp +++ b/test/bvar_multi_dimension_unittest.cpp @@ -59,11 +59,11 @@ static long start_perf_test_with_madder(size_t num_thread, bvar::Adder EXPECT_TRUE(adder->valid()); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &thread_adder, (void *)adder); + pthread_create(&threads[i], nullptr, &thread_adder, (void *)adder); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { - void *ret = NULL; + void *ret = nullptr; pthread_join(threads[i], &ret); totol_time += (long)ret; } @@ -87,11 +87,11 @@ static long start_perf_test_with_mmaxer(size_t num_thread, bvar::Maxer EXPECT_TRUE(maxer->valid()); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &thread_maxer, (void *)maxer); + pthread_create(&threads[i], nullptr, &thread_maxer, (void *)maxer); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { - void *ret = NULL; + void *ret = nullptr; pthread_join(threads[i], &ret); totol_time += (long)ret; } @@ -115,11 +115,11 @@ static long start_perf_test_with_mminer(size_t num_thread, bvar::Miner EXPECT_TRUE(miner->valid()); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &thread_miner, (void *)miner); + pthread_create(&threads[i], nullptr, &thread_miner, (void *)miner); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { - void *ret = NULL; + void *ret = nullptr; pthread_join(threads[i], &ret); totol_time += (long)ret; } @@ -143,11 +143,11 @@ static long start_perf_test_with_mintrecorder(size_t num_thread, bvar::IntRecord EXPECT_TRUE(intrecorder->valid()); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &thread_intrecorder, (void *)intrecorder); + pthread_create(&threads[i], nullptr, &thread_intrecorder, (void *)intrecorder); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { - void *ret = NULL; + void *ret = nullptr; pthread_join(threads[i], &ret); totol_time += (long)ret; } @@ -500,10 +500,10 @@ TEST_F(MultiDimensionTest, test_hash) { class MyStringView { public: - MyStringView() : _ptr(NULL), _len(0) {} + MyStringView() : _ptr(nullptr), _len(0) {} MyStringView(const char* str) : _ptr(str), - _len(str == NULL ? 0 : strlen(str)) {} + _len(str == nullptr ? 0 : strlen(str)) {} #if __cplusplus >= 201703L MyStringView(const std::string_view& str) : _ptr(str.data()), _len(str.size()) {} @@ -518,7 +518,7 @@ class MyStringView { // Converts to `std::basic_string`. explicit operator std::string() const { - if (NULL == _ptr) { + if (nullptr == _ptr) { return {}; } return {_ptr, size()}; @@ -526,7 +526,7 @@ class MyStringView { // Converts to butil::StringPiece. explicit operator butil::StringPiece() const { - if (NULL == _ptr) { + if (nullptr == _ptr) { return {}; } return {_ptr, size()}; @@ -621,7 +621,7 @@ void* get_shared_adder_thread(void* arg) { EXPECT_NE(nullptr, adder); *adder << 1; } - return NULL; + return nullptr; } void* delete_shared_adder_thread(void* arg) { @@ -630,7 +630,7 @@ void* delete_shared_adder_thread(void* arg) { while (!g_shared_stop) { my_madder->delete_stats(g_labels_value); } - return NULL; + return nullptr; } TEST_F(MultiDimensionTest, shared) { @@ -651,15 +651,15 @@ TEST_F(MultiDimensionTest, shared) { const int get_num = 8; std::vector get_threads(get_num); for (int i = 0; i < get_num; ++i) { - ASSERT_EQ(0, pthread_create(&get_threads[i], NULL, get_shared_adder_thread, &my_madder)); + ASSERT_EQ(0, pthread_create(&get_threads[i], nullptr, get_shared_adder_thread, &my_madder)); } pthread_t delete_thread; - ASSERT_EQ(0, pthread_create(&delete_thread, NULL, delete_shared_adder_thread, &my_madder)); + ASSERT_EQ(0, pthread_create(&delete_thread, nullptr, delete_shared_adder_thread, &my_madder)); usleep(100 * 1000); // 100ms g_shared_stop = true; for (int i = 0; i < get_num; ++i) { - ASSERT_EQ(0, pthread_join(get_threads[i], NULL)); + ASSERT_EQ(0, pthread_join(get_threads[i], nullptr)); } - ASSERT_EQ(0, pthread_join(delete_thread, NULL)); + ASSERT_EQ(0, pthread_join(delete_thread, nullptr)); } diff --git a/test/bvar_percentile_unittest.cpp b/test/bvar_percentile_unittest.cpp index d9d01846a1..83e09ef99b 100644 --- a/test/bvar_percentile_unittest.cpp +++ b/test/bvar_percentile_unittest.cpp @@ -164,7 +164,7 @@ TEST_F(PercentileTest, combine_of) { bvar::detail::PercentileSamples<510> g; g.combine_of(result.begin(), result.end()); for (size_t i = 0; i < bvar::detail::NUM_INTERVALS; ++i) { - if (g._intervals[i] == NULL) { + if (g._intervals[i] == nullptr) { continue; } bvar::detail::PercentileInterval<510>& p = *g._intervals[i]; diff --git a/test/bvar_recorder_unittest.cpp b/test/bvar_recorder_unittest.cpp index a385b9b7bd..e383c410cc 100644 --- a/test/bvar_recorder_unittest.cpp +++ b/test/bvar_recorder_unittest.cpp @@ -200,7 +200,7 @@ TEST(RecorderTest, perf) { ASSERT_TRUE(recorder.valid()); pthread_t threads[8]; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_create(&threads[i], NULL, &thread_counter, (void *)&recorder); + pthread_create(&threads[i], nullptr, &thread_counter, (void *)&recorder); } long totol_time = 0; for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { diff --git a/test/bvar_reducer_unittest.cpp b/test/bvar_reducer_unittest.cpp index 5bd3477ce5..02923d92c5 100644 --- a/test/bvar_reducer_unittest.cpp +++ b/test/bvar_reducer_unittest.cpp @@ -90,7 +90,7 @@ static long start_perf_test_with_atomic(size_t num_thread) { butil::atomic counter(0); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &add_atomic, (void *)&counter); + pthread_create(&threads[i], nullptr, &add_atomic, (void *)&counter); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { @@ -108,11 +108,11 @@ static long start_perf_test_with_adder(size_t num_thread) { EXPECT_TRUE(reducer.valid()); pthread_t threads[num_thread]; for (size_t i = 0; i < num_thread; ++i) { - pthread_create(&threads[i], NULL, &thread_counter, (void *)&reducer); + pthread_create(&threads[i], nullptr, &thread_counter, (void *)&reducer); } long totol_time = 0; for (size_t i = 0; i < num_thread; ++i) { - void *ret = NULL; + void *ret = nullptr; pthread_join(threads[i], &ret); totol_time += (long)ret; } @@ -308,13 +308,13 @@ TEST_F(ReducerTest, non_primitive_mt) { pthread_t th[8]; g_stop = false; for (size_t i = 0; i < arraysize(th); ++i) { - pthread_create(&th[i], NULL, string_appender, &cater); + pthread_create(&th[i], nullptr, string_appender, &cater); } usleep(50000); g_stop = true; butil::hash_map appended_count; for (size_t i = 0; i < arraysize(th); ++i) { - StringAppenderResult* res = NULL; + StringAppenderResult* res = nullptr; pthread_join(th[i], (void**)&res); appended_count[th[i]] = res->count; delete res; @@ -322,7 +322,7 @@ TEST_F(ReducerTest, non_primitive_mt) { butil::hash_map got_count; std::string res = cater.get_value(); for (butil::StringSplitter sp(res.c_str(), '.'); sp; ++sp) { - char* endptr = NULL; + char* endptr = nullptr; ++got_count[(pthread_t)strtoll(sp.field(), &endptr, 10)]; ASSERT_EQ(27LL, sp.field() + sp.length() - endptr) << butil::StringPiece(sp.field(), sp.length()); diff --git a/test/bvar_sampler_unittest.cpp b/test/bvar_sampler_unittest.cpp index 0a521a498e..40cc22d997 100644 --- a/test/bvar_sampler_unittest.cpp +++ b/test/bvar_sampler_unittest.cpp @@ -110,7 +110,7 @@ static void* check(void*) { for (int i = 0; i < N; ++i) { s[i]->destroy(); } - return NULL; + return nullptr; } TEST(SamplerTest, multi_threaded) { @@ -121,10 +121,10 @@ TEST(SamplerTest, multi_threaded) { pthread_t th[10]; DebugSampler::_s_ndestroy = 0; for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_create(&th[i], NULL, check, NULL)); + ASSERT_EQ(0, pthread_create(&th[i], nullptr, check, nullptr)); } for (size_t i = 0; i < arraysize(th); ++i) { - ASSERT_EQ(0, pthread_join(th[i], NULL)); + ASSERT_EQ(0, pthread_join(th[i], nullptr)); } sleep(1); EXPECT_EQ(100 * arraysize(th), (size_t)DebugSampler::_s_ndestroy); diff --git a/test/bvar_variable_unittest.cpp b/test/bvar_variable_unittest.cpp index 55a0e4b6bd..b24c3057b5 100644 --- a/test/bvar_variable_unittest.cpp +++ b/test/bvar_variable_unittest.cpp @@ -216,7 +216,7 @@ TEST_F(VariableTest, dump) { // Nothing to dump yet. bvar::FLAGS_bvar_log_dumpped = true; - ASSERT_EQ(0, bvar::Variable::dump_exposed(&d, NULL)); + ASSERT_EQ(0, bvar::Variable::dump_exposed(&d, nullptr)); ASSERT_TRUE(d._list.empty()); bvar::Adder v2("var2"); @@ -227,9 +227,9 @@ TEST_F(VariableTest, dump) { bvar::Adder v4("foo.bar.BaNaNa", "var4"); v4 << 4; bvar::BasicPassiveStatus v5( - "foo::bar::Car_Rot", "var5", print_int, NULL); + "foo::bar::Car_Rot", "var5", print_int, nullptr); - ASSERT_EQ(5, bvar::Variable::dump_exposed(&d, NULL)); + ASSERT_EQ(5, bvar::Variable::dump_exposed(&d, nullptr)); ASSERT_EQ(5UL, d._list.size()); int i = 0; ASSERT_EQ("foo_bar_apple_var3", d._list[i++ / 2].first); diff --git a/test/condition_variable_unittest.cc b/test/condition_variable_unittest.cc index ef3e4f04ea..459b61acc6 100644 --- a/test/condition_variable_unittest.cc +++ b/test/condition_variable_unittest.cc @@ -194,9 +194,9 @@ void ALLOW_UNUSED BackInTime(Lock* lock) { AutoLock auto_lock(*lock); timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); tv.tv_sec -= kDiscontinuitySeconds; - settimeofday(&tv, NULL); + settimeofday(&tv, nullptr); } #endif diff --git a/test/crash_logging_unittest.cc b/test/crash_logging_unittest.cc index d0fa432449..cb3e02b533 100644 --- a/test/crash_logging_unittest.cc +++ b/test/crash_logging_unittest.cc @@ -11,7 +11,7 @@ namespace { -std::map* key_values_ = NULL; +std::map* key_values_ = nullptr; } // namespace @@ -28,7 +28,7 @@ class CrashLoggingTest : public testing::Test { butil::debug::ResetCrashLoggingForTesting(); delete key_values_; - key_values_ = NULL; + key_values_ = nullptr; } private: diff --git a/test/endpoint_unittest.cpp b/test/endpoint_unittest.cpp index af3098f475..ef8fd4ea73 100644 --- a/test/endpoint_unittest.cpp +++ b/test/endpoint_unittest.cpp @@ -191,9 +191,9 @@ static void test_listen_connect(const std::string& server_addr, const std::strin int listen_fd = butil::tcp_listen(point); ASSERT_GT(listen_fd, 0); pthread_t pid; - pthread_create(&pid, NULL, server_proc, (void*)(int64_t)listen_fd); + pthread_create(&pid, nullptr, server_proc, (void*)(int64_t)listen_fd); - int fd = butil::tcp_connect(point, NULL); + int fd = butil::tcp_connect(point, nullptr); ASSERT_GT(fd, 0); butil::EndPoint point2; @@ -275,11 +275,11 @@ TEST(EndPointTest, unix_socket) { TEST(EndPointTest, original_endpoint) { butil::EndPoint ep; ASSERT_FALSE(ExtendedEndPoint::is_extended(ep)); - ASSERT_EQ(NULL, ExtendedEndPoint::address(ep)); + ASSERT_EQ(nullptr, ExtendedEndPoint::address(ep)); ASSERT_EQ(0, butil::str2endpoint("1.2.3.4:5678", &ep)); ASSERT_FALSE(ExtendedEndPoint::is_extended(ep)); - ASSERT_EQ(NULL, ExtendedEndPoint::address(ep)); + ASSERT_EQ(nullptr, ExtendedEndPoint::address(ep)); // ctor & dtor { @@ -504,15 +504,15 @@ TEST(EndPointTest, tcp_connect) { ASSERT_EQ(0, butil::hostname2endpoint(g_hostname1, 80, &ep1)); ASSERT_EQ(0, butil::hostname2endpoint(g_hostname2, 80, &ep2)); { - butil::fd_guard sockfd(butil::tcp_connect(ep1, NULL)); + butil::fd_guard sockfd(butil::tcp_connect(ep1, nullptr)); ASSERT_LE(0, sockfd) << "errno=" << errno; } { - butil::fd_guard sockfd(butil::tcp_connect(ep1, NULL, 1000)); + butil::fd_guard sockfd(butil::tcp_connect(ep1, nullptr, 1000)); ASSERT_LE(0, sockfd) << "errno=" << errno; } { - butil::fd_guard sockfd(butil::tcp_connect(ep2, NULL, 1)); + butil::fd_guard sockfd(butil::tcp_connect(ep2, nullptr, 1)); ASSERT_EQ(-1, sockfd) << "errno=" << errno; ASSERT_EQ(ETIMEDOUT, errno); } @@ -525,7 +525,7 @@ TEST(EndPointTest, tcp_connect) { ASSERT_LE(0, sockfd); bool is_blocking = butil::is_blocking(sockfd); ASSERT_EQ(0, butil::pthread_timed_connect( - sockfd, (struct sockaddr*) &serv_addr, serv_addr_size, NULL)); + sockfd, (struct sockaddr*) &serv_addr, serv_addr_size, nullptr)); ASSERT_EQ(is_blocking, butil::is_blocking(sockfd)); } @@ -562,7 +562,7 @@ void TestConnectInterruptImpl(bool timed) { int rc; if (timed) { int64_t start_ms = butil::cpuwide_time_ms(); - butil::tcp_connect(ep, NULL); + butil::tcp_connect(ep, nullptr); int64_t connect_ms = butil::cpuwide_time_ms() - start_ms; LOG(INFO) << "Connect to " << ep << ", cost " << connect_ms << "ms"; @@ -573,7 +573,7 @@ void TestConnectInterruptImpl(bool timed) { } else { rc = butil::pthread_timed_connect( sockfd, (struct sockaddr*) &serv_addr, - serv_addr_size, NULL); + serv_addr_size, nullptr); } ASSERT_EQ(0, rc) << "errno=" << errno; ASSERT_EQ(0, butil::is_connected(sockfd)); @@ -582,7 +582,7 @@ void TestConnectInterruptImpl(bool timed) { void* ConnectThread(void* arg) { bool timed = *(bool*)arg; TestConnectInterruptImpl(timed); - return NULL; + return nullptr; } void do_nothing_handler(int) {} @@ -594,7 +594,7 @@ void register_sigurg() { void TestConnectInterrupt(bool timed) { g_connect_startd = false; pthread_t tid; - ASSERT_EQ(0, pthread_create(&tid, NULL, ConnectThread, &timed)); + ASSERT_EQ(0, pthread_create(&tid, nullptr, ConnectThread, &timed)); while (g_connect_startd) { usleep(1000); @@ -602,7 +602,7 @@ void TestConnectInterrupt(bool timed) { ASSERT_EQ(0, pthread_kill(tid, SIGURG)); - pthread_join(tid, NULL); + pthread_join(tid, nullptr); } TEST(EndPointTest, interrupt) { diff --git a/test/environment_unittest.cc b/test/environment_unittest.cc index 63a28a32a3..a5b6fcb969 100644 --- a/test/environment_unittest.cc +++ b/test/environment_unittest.cc @@ -124,39 +124,39 @@ TEST_F(EnvironmentTest, AlterEnvironment) { #else TEST_F(EnvironmentTest, AlterEnvironment) { - const char* const empty[] = { NULL }; - const char* const a2[] = { "A=2", NULL }; + const char* const empty[] = { nullptr }; + const char* const a2[] = { "A=2", nullptr }; EnvironmentMap changes; scoped_ptr e; e = AlterEnvironment(empty, changes).Pass(); - EXPECT_TRUE(e[0] == NULL); + EXPECT_TRUE(e[0] == nullptr); changes["A"] = "1"; e = AlterEnvironment(empty, changes); EXPECT_EQ(std::string("A=1"), e[0]); - EXPECT_TRUE(e[1] == NULL); + EXPECT_TRUE(e[1] == nullptr); changes.clear(); changes["A"] = std::string(); e = AlterEnvironment(empty, changes); - EXPECT_TRUE(e[0] == NULL); + EXPECT_TRUE(e[0] == nullptr); changes.clear(); e = AlterEnvironment(a2, changes); EXPECT_EQ(std::string("A=2"), e[0]); - EXPECT_TRUE(e[1] == NULL); + EXPECT_TRUE(e[1] == nullptr); changes.clear(); changes["A"] = "1"; e = AlterEnvironment(a2, changes); EXPECT_EQ(std::string("A=1"), e[0]); - EXPECT_TRUE(e[1] == NULL); + EXPECT_TRUE(e[1] == nullptr); changes.clear(); changes["A"] = std::string(); e = AlterEnvironment(a2, changes); - EXPECT_TRUE(e[0] == NULL); + EXPECT_TRUE(e[0] == nullptr); } #endif diff --git a/test/file_unittest.cc b/test/file_unittest.cc index 706b289ebd..e25d903221 100644 --- a/test/file_unittest.cc +++ b/test/file_unittest.cc @@ -453,10 +453,10 @@ TEST(FileTest, GetInfoForDirectory) { ::CreateFile(empty_dir.value().c_str(), FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, + nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. - NULL)); + nullptr)); ASSERT_TRUE(dir.IsValid()); butil::File::Info info; diff --git a/test/file_util_unittest.cc b/test/file_util_unittest.cc index a323a72c8e..736ba0566d 100644 --- a/test/file_util_unittest.cc +++ b/test/file_util_unittest.cc @@ -105,7 +105,7 @@ bool SetReparsePoint(HANDLE source, const FilePath& target_path) { int data_size = data->ReparseDataLength + 8; if (!DeviceIoControl(source, FSCTL_SET_REPARSE_POINT, &buffer, data_size, - NULL, 0, &returned, NULL)) { + nullptr, 0, &returned, nullptr)) { return false; } return true; @@ -117,8 +117,8 @@ bool DeleteReparsePoint(HANDLE source) { DWORD returned; REPARSE_DATA_BUFFER data = {0}; data.ReparseTag = 0xa0000003; - if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0, - &returned, NULL)) { + if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, nullptr, 0, + &returned, nullptr)) { return false; } return true; @@ -133,10 +133,10 @@ class ReparsePoint { ::CreateFile(source.value().c_str(), FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, + nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. - NULL)); + nullptr)); created_ = dir_.IsValid() && SetReparsePoint(dir_, target); } @@ -1654,7 +1654,7 @@ TEST_F(FileUtilTest, GetTempDirTest) { size_t original_tmp_size; TCHAR* original_tmp; ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); - // original_tmp may be NULL. + // original_tmp may be nullptr. for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { FilePath path; @@ -2094,9 +2094,9 @@ TEST_F(FileUtilTest, ReadFileToString) { EXPECT_TRUE(ReadFileToString(file_path, &data, 6)); EXPECT_EQ("0123", data); - EXPECT_TRUE(ReadFileToString(file_path, NULL, 6)); + EXPECT_TRUE(ReadFileToString(file_path, nullptr, 6)); - EXPECT_TRUE(ReadFileToString(file_path, NULL)); + EXPECT_TRUE(ReadFileToString(file_path, nullptr)); data = "temp"; EXPECT_FALSE(ReadFileToString(file_path_dangerous, &data)); diff --git a/test/flat_map_unittest.cpp b/test/flat_map_unittest.cpp index 2721d57e92..811713b385 100644 --- a/test/flat_map_unittest.cpp +++ b/test/flat_map_unittest.cpp @@ -237,7 +237,7 @@ TEST_F(FlatMapTest, seek_by_string_piece) { ASSERT_TRUE(m.seek(k2)); ASSERT_EQ(2, *m.seek(k2)); butil::StringPiece k3("heheda"); - ASSERT_TRUE(m.seek(k3) == NULL); + ASSERT_TRUE(m.seek(k3) == nullptr); } TEST_F(FlatMapTest, to_lower) { @@ -351,7 +351,7 @@ TEST_F(FlatMapTest, make_sure_all_methods_compile) { ASSERT_EQ(100, m1[1]); ASSERT_EQ(3u, m1.size()); ASSERT_TRUE(m1.seek(3)); - ASSERT_EQ(NULL, m1.seek(4)); + ASSERT_EQ(nullptr, m1.seek(4)); ASSERT_EQ(1u, m1.erase(3)); ASSERT_EQ(0u, m1.erase(4)); ASSERT_EQ(2u, m1.size()); @@ -379,7 +379,7 @@ TEST_F(FlatMapTest, make_sure_all_methods_compile) { s1.insert(1); ASSERT_TRUE(s1.seek(1)); ASSERT_EQ(2u, s1.size()); - ASSERT_EQ(NULL, s1.seek(3)); + ASSERT_EQ(nullptr, s1.seek(3)); ASSERT_EQ(0u, s1.erase(3)); ASSERT_EQ(2u, s1.size()); ASSERT_EQ(1u, s1.erase(2)); @@ -540,8 +540,8 @@ TEST_F(FlatMapTest, fast_iterator) { ASSERT_EQ(0, m1.init(1)); ASSERT_EQ(0, m2.init(16384)); - ASSERT_EQ(NULL, m1._thumbnail); - ASSERT_TRUE(NULL != m2._thumbnail); + ASSERT_EQ(nullptr, m1._thumbnail); + ASSERT_TRUE(nullptr != m2._thumbnail); const size_t N = 170; std::vector keys; @@ -616,7 +616,7 @@ typedef butil::FlatMap PositionHintMap; static void fill_position_hint_map(PositionHintMap* map, std::vector* keys) { - srand(time(NULL)); + srand(time(nullptr)); const size_t N = 5; if (!map->initialized()) { ASSERT_EQ(0, map->init(N * 3 / 2, 80)); @@ -665,7 +665,7 @@ TEST_F(FlatMapTest, do_nothing_during_iteration) { } struct RemoveInsertVisitedOnPause { - RemoveInsertVisitedOnPause() : keys(NULL), map(NULL) { + RemoveInsertVisitedOnPause() : keys(nullptr), map(nullptr) { removed_keys.init(32); inserted_keys.init(32); } @@ -721,7 +721,7 @@ TEST_F(FlatMapTest, erase_insert_visited_during_iteration) { } struct RemoveHintedOnPause { - RemoveHintedOnPause() : map(NULL) { + RemoveHintedOnPause() : map(nullptr) { removed_keys.init(32); } void operator()(const PositionHintMap::PositionHint& hint) { @@ -764,7 +764,7 @@ TEST_F(FlatMapTest, erase_hinted_during_iteration) { struct RemoveInsertUnvisitedOnPause { RemoveInsertUnvisitedOnPause() - : keys_out(NULL), all_keys(NULL), map(NULL) { + : keys_out(nullptr), all_keys(nullptr), map(nullptr) { removed_keys.init(32); inserted_keys.init(32); } @@ -889,7 +889,7 @@ TEST_F(FlatMapTest, perf_cmp_with_map_storing_pointers) { sum = 0; tm.start(); for (size_t i = 0; i < r.size(); ++i) { - sum += (m2.seek(r[i]) != NULL); + sum += (m2.seek(r[i]) != nullptr); } tm.stop(); LOG(INFO) << "FlatMap takes " << tm.n_elapsed()/r.size(); @@ -973,7 +973,7 @@ TEST_F(FlatMapTest, key_value_are_not_constructed_before_first_insertion) { const Key k1 = 1; ASSERT_EQ(1, n_con_key); ASSERT_EQ(0, n_cp_con_key); - ASSERT_EQ(NULL, m.seek(k1)); + ASSERT_EQ(nullptr, m.seek(k1)); ASSERT_EQ(0u, m.erase(k1)); ASSERT_EQ(1, n_con_key); ASSERT_EQ(0, n_cp_con_key); @@ -984,7 +984,7 @@ TEST_F(FlatMapTest, key_value_are_not_constructed_before_first_insertion) { TEST_F(FlatMapTest, manipulate_uninitialized_map) { butil::FlatMap m; ASSERT_TRUE(m.initialized()); - ASSERT_EQ(NULL, m.seek(1)); + ASSERT_EQ(nullptr, m.seek(1)); ASSERT_EQ(0u, m.erase(1)); ASSERT_EQ(0u, m.size()); ASSERT_TRUE(m.empty()); @@ -1088,7 +1088,7 @@ TEST_F(FlatMapTest, sanity) { ASSERT_TRUE(p && *p == 10); ASSERT_EQ(0UL, m._pool.count_allocated()); - ASSERT_EQ(NULL, m.seek(k2)); + ASSERT_EQ(nullptr, m.seek(k2)); // Override m[k1] = 100; @@ -1113,7 +1113,7 @@ TEST_F(FlatMapTest, sanity) { p = m.seek(k2); ASSERT_TRUE(p && *p == 30); - ASSERT_EQ(NULL, m.seek(2049)); + ASSERT_EQ(nullptr, m.seek(2049)); Map::iterator it = m.begin(); ASSERT_EQ(k1, it->first); @@ -1128,7 +1128,7 @@ TEST_F(FlatMapTest, sanity) { ASSERT_EQ(1UL, m.erase(k1)); ASSERT_EQ(2UL, m.size()); ASSERT_FALSE(m.empty()); - ASSERT_EQ(NULL, m.seek(k1)); + ASSERT_EQ(nullptr, m.seek(k1)); ASSERT_EQ(30, *m.seek(k2)); ASSERT_EQ(20, *m.seek(k3)); ASSERT_EQ(1UL, m._pool.count_allocated()); @@ -1144,9 +1144,9 @@ TEST_F(FlatMapTest, sanity) { m.clear(); ASSERT_EQ(m.size(), 0ul); ASSERT_TRUE(m.empty()); - ASSERT_EQ(NULL, m.seek(k1)); - ASSERT_EQ(NULL, m.seek(k2)); - ASSERT_EQ(NULL, m.seek(k3)); + ASSERT_EQ(nullptr, m.seek(k1)); + ASSERT_EQ(nullptr, m.seek(k2)); + ASSERT_EQ(nullptr, m.seek(k3)); } TEST_F(FlatMapTest, random_insert_erase) { @@ -1197,7 +1197,7 @@ TEST_F(FlatMapTest, random_insert_erase) { it != ref[i].end(); ++it) { Value* p_value = ht[i].seek(it->first); - ASSERT_TRUE (p_value != NULL); + ASSERT_TRUE (p_value != nullptr); ASSERT_EQ (it->second, p_value->x_); } ASSERT_EQ (ht[i].size(), ref[i].size()); diff --git a/test/fuzzing/fuzz_baidu_rpc.cpp b/test/fuzzing/fuzz_baidu_rpc.cpp index 0302f0cc9e..860746896b 100644 --- a/test/fuzzing/fuzz_baidu_rpc.cpp +++ b/test/fuzzing/fuzz_baidu_rpc.cpp @@ -33,9 +33,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseRpcMessage(&buf, sock, false, NULL); + brpc::policy::ParseRpcMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_common.h b/test/fuzzing/fuzz_common.h index 604306babd..765d6a4d9e 100644 --- a/test/fuzzing/fuzz_common.h +++ b/test/fuzzing/fuzz_common.h @@ -21,7 +21,7 @@ #include "brpc/socket.h" #include "butil/endpoint.h" -// Create a valid Socket for use in fuzz harnesses that need a non-NULL Socket*. +// Create a valid Socket for use in fuzz harnesses that need a non-nullptr Socket*. // Returns a raw Socket* that remains valid for the lifetime of the process // (held by the static SocketUniquePtr). inline brpc::Socket* get_fuzz_socket() { diff --git a/test/fuzzing/fuzz_couchbase.cpp b/test/fuzzing/fuzz_couchbase.cpp index 8807005339..f623c2ba4d 100644 --- a/test/fuzzing/fuzz_couchbase.cpp +++ b/test/fuzzing/fuzz_couchbase.cpp @@ -33,9 +33,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseCouchbaseMessage(&buf, sock, false, NULL); + brpc::policy::ParseCouchbaseMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_esp.cpp b/test/fuzzing/fuzz_esp.cpp index d1c6649d86..9a26db86cf 100644 --- a/test/fuzzing/fuzz_esp.cpp +++ b/test/fuzzing/fuzz_esp.cpp @@ -34,10 +34,10 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseEspMessage(&buf, sock, false, NULL); + brpc::policy::ParseEspMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_hulu.cpp b/test/fuzzing/fuzz_hulu.cpp index 50cc62b31f..74f9bec2bf 100644 --- a/test/fuzzing/fuzz_hulu.cpp +++ b/test/fuzzing/fuzz_hulu.cpp @@ -34,10 +34,10 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseHuluMessage(&buf, sock, false, NULL); + brpc::policy::ParseHuluMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_memcache.cpp b/test/fuzzing/fuzz_memcache.cpp index b60d527f5d..52bfbfab55 100644 --- a/test/fuzzing/fuzz_memcache.cpp +++ b/test/fuzzing/fuzz_memcache.cpp @@ -33,9 +33,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseMemcacheMessage(&buf, sock, false, NULL); + brpc::policy::ParseMemcacheMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_mongo.cpp b/test/fuzzing/fuzz_mongo.cpp index 88db824ede..18edc9362d 100644 --- a/test/fuzzing/fuzz_mongo.cpp +++ b/test/fuzzing/fuzz_mongo.cpp @@ -33,9 +33,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseMongoMessage(&buf, sock, false, NULL); + brpc::policy::ParseMongoMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_shead.cpp b/test/fuzzing/fuzz_shead.cpp index 720b4e8e50..fd5d8c9b72 100644 --- a/test/fuzzing/fuzz_shead.cpp +++ b/test/fuzzing/fuzz_shead.cpp @@ -34,10 +34,10 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseNsheadMessage(&buf, sock, false, NULL); + brpc::policy::ParseNsheadMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_sofa.cpp b/test/fuzzing/fuzz_sofa.cpp index a5dc418ec3..84f39ec967 100644 --- a/test/fuzzing/fuzz_sofa.cpp +++ b/test/fuzzing/fuzz_sofa.cpp @@ -36,9 +36,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseSofaMessage(&buf, sock, false, NULL); + brpc::policy::ParseSofaMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_streaming.cpp b/test/fuzzing/fuzz_streaming.cpp index 0b58d7b9e1..e8b79b8a1d 100644 --- a/test/fuzzing/fuzz_streaming.cpp +++ b/test/fuzzing/fuzz_streaming.cpp @@ -33,9 +33,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) buf.append(input); brpc::Socket* sock = get_fuzz_socket(); - if (sock == NULL) { + if (sock == nullptr) { return 0; } - brpc::policy::ParseStreamingMessage(&buf, sock, false, NULL); + brpc::policy::ParseStreamingMessage(&buf, sock, false, nullptr); return 0; } diff --git a/test/fuzzing/fuzz_thrift.cpp b/test/fuzzing/fuzz_thrift.cpp index c7ecd4323c..c3928ffe53 100644 --- a/test/fuzzing/fuzz_thrift.cpp +++ b/test/fuzzing/fuzz_thrift.cpp @@ -31,6 +31,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) butil::IOBuf buf; buf.append(input); - brpc::policy::ParseThriftMessage(&buf, NULL, false, NULL); + brpc::policy::ParseThriftMessage(&buf, nullptr, false, nullptr); return 0; } diff --git a/test/iobuf_unittest.cpp b/test/iobuf_unittest.cpp index ddd5b59974..9f9cc38722 100644 --- a/test/iobuf_unittest.cpp +++ b/test/iobuf_unittest.cpp @@ -64,7 +64,7 @@ const size_t BLOCK_OVERHEAD = 32; //impl dependent const size_t DEFAULT_PAYLOAD = butil::GetDefaultBlockSize() - BLOCK_OVERHEAD; void check_tls_block() { - ASSERT_EQ((butil::IOBuf::Block*)NULL, butil::iobuf::get_tls_block_head()); + ASSERT_EQ((butil::IOBuf::Block*)nullptr, butil::iobuf::get_tls_block_head()); printf("tls_block of butil::IOBuf was deleted\n"); } const int ALLOW_UNUSED check_dummy = butil::thread_atexit(check_tls_block); @@ -235,10 +235,10 @@ TEST_F(IOBufTest, append) { butil::IOBuf b; ASSERT_EQ(0UL, b.length()); ASSERT_TRUE(b.empty()); - ASSERT_EQ(-1, b.append(NULL)); + ASSERT_EQ(-1, b.append(nullptr)); ASSERT_EQ(0, b.append("")); ASSERT_EQ(0, b.append(std::string())); - ASSERT_EQ(-1, b.append(NULL, 1)); + ASSERT_EQ(-1, b.append(nullptr, 1)); ASSERT_EQ(0, b.append("dummy", 0)); ASSERT_EQ(0UL, b.length()); ASSERT_TRUE(b.empty()); @@ -793,7 +793,7 @@ TEST_F(IOBufTest, cut_multiple_into_fd_tiny) { for (size_t j = 0; j < ARRAY_SIZE(b1); ++j) { ASSERT_TRUE(b1[j]->empty()); delete (butil::IOPortal*)b1[j]; - b1[j] = NULL; + b1[j] = nullptr; } ASSERT_EQ((ssize_t)ref.length(), b2.append_from_file_descriptor(fds[0], LONG_MAX)); @@ -1074,13 +1074,13 @@ TEST_F(IOBufTest, conversion_with_protobuf) { butil::IOBufAsZeroCopyInputStream in_wrapper(buf); ASSERT_EQ(0, in_wrapper.ByteCount()); { - const void* dummy_blk = NULL; + const void* dummy_blk = nullptr; int dummy_size = 0; ASSERT_TRUE(in_wrapper.Next(&dummy_blk, &dummy_size)); ASSERT_EQ(dummy_size, in_wrapper.ByteCount()); in_wrapper.BackUp(1); ASSERT_EQ(dummy_size - 1, in_wrapper.ByteCount()); - const void* dummy_blk2 = NULL; + const void* dummy_blk2 = nullptr; int dummy_size2 = 0; ASSERT_TRUE(in_wrapper.Next(&dummy_blk2, &dummy_size2)); ASSERT_EQ(1, dummy_size2); @@ -1124,12 +1124,12 @@ TEST_F(IOBufTest, extended_backup) { butil::IOBufAsZeroCopyOutputStream out_stream2(&src); butil::IOBufAsZeroCopyOutputStream & out_stream = (i == 0 ? out_stream1 : out_stream2); - void* blk1 = NULL; + void* blk1 = nullptr; int size1 = 0; ASSERT_TRUE(out_stream.Next(&blk1, &size1)); ASSERT_EQ(PLDSIZE, size1); ASSERT_EQ(size1, out_stream.ByteCount()); - void* blk2 = NULL; + void* blk2 = nullptr; int size2 = 0; ASSERT_TRUE(out_stream.Next(&blk2, &size2)); ASSERT_EQ(PLDSIZE, size2); @@ -1137,7 +1137,7 @@ TEST_F(IOBufTest, extended_backup) { // BackUp a size that's valid for all ZeroCopyOutputStream out_stream.BackUp(PLDSIZE / 2); ASSERT_EQ(size1 + size2 - PLDSIZE / 2, out_stream.ByteCount()); - void* blk3 = NULL; + void* blk3 = nullptr; int size3 = 0; ASSERT_TRUE(out_stream.Next(&blk3, &size3)); ASSERT_EQ((char*)blk2 + PLDSIZE / 2, blk3); @@ -1147,7 +1147,7 @@ TEST_F(IOBufTest, extended_backup) { // BackUp a size that's undefined in regular ZeroCopyOutputStream out_stream.BackUp(PLDSIZE * 2); ASSERT_EQ(0, out_stream.ByteCount()); - void* blk4 = NULL; + void* blk4 = nullptr; int size4 = 0; ASSERT_TRUE(out_stream.Next(&blk4, &size4)); ASSERT_EQ(PLDSIZE, size4); @@ -1155,7 +1155,7 @@ TEST_F(IOBufTest, extended_backup) { if (i == 1) { ASSERT_EQ(blk1, blk4); } - void* blk5 = NULL; + void* blk5 = nullptr; int size5 = 0; ASSERT_TRUE(out_stream.Next(&blk5, &size5)); ASSERT_EQ(PLDSIZE, size5); @@ -1172,7 +1172,7 @@ TEST_F(IOBufTest, backup_iobuf_never_called_next) { // to check. butil::IOBuf dummy; butil::IOBufAsZeroCopyOutputStream dummy_stream(&dummy); - void* dummy_data = NULL; + void* dummy_data = nullptr; int dummy_size = 0; ASSERT_TRUE(dummy_stream.Next(&dummy_data, &dummy_size)); } @@ -1186,19 +1186,19 @@ TEST_F(IOBufTest, backup_iobuf_never_called_next) { ASSERT_EQ(-1, out_stream.ByteCount()); ASSERT_EQ(DEFAULT_PAYLOAD * 2 - 1, src.size()); ASSERT_EQ(2u, src.backing_block_num()); - void* data0 = NULL; + void* data0 = nullptr; int size0 = 0; ASSERT_TRUE(out_stream.Next(&data0, &size0)); ASSERT_EQ(1, size0); ASSERT_EQ(0, out_stream.ByteCount()); ASSERT_EQ(2u, src.backing_block_num()); - void* data1 = NULL; + void* data1 = nullptr; int size1 = 0; ASSERT_TRUE(out_stream.Next(&data1, &size1)); ASSERT_EQ(size1, out_stream.ByteCount()); ASSERT_EQ(3u, src.backing_block_num()); ASSERT_EQ(N + size1, src.size()); - void* data2 = NULL; + void* data2 = nullptr; int size2 = 0; ASSERT_TRUE(out_stream.Next(&data2, &size2)); ASSERT_EQ(size1 + size2, out_stream.ByteCount()); @@ -1219,7 +1219,7 @@ void *backup_thread(void *arg) { butil::IOBufAsZeroCopyOutputStream *wrapper = (butil::IOBufAsZeroCopyOutputStream *)arg; wrapper->BackUp(1024); - return NULL; + return nullptr; } TEST_F(IOBufTest, backup_in_another_thread) { @@ -1239,8 +1239,8 @@ TEST_F(IOBufTest, backup_in_another_thread) { ASSERT_TRUE(wrapper.Next(&data, &len)); alloc_size += len; pthread_t tid; - pthread_create(&tid, NULL, backup_thread, &wrapper); - pthread_join(tid, NULL); + pthread_create(&tid, nullptr, backup_thread, &wrapper); + pthread_join(tid, nullptr); } ASSERT_EQ(alloc_size - 1024 * 10, buf.length()); } @@ -1361,7 +1361,7 @@ void* cut_into_fd(void* arg) { CHECK_EQ(out.pcut_into_file_descriptor(fd, offset + sizeof(int) * i), (ssize_t)sizeof(int)); } - return NULL; + return nullptr; } TEST_F(IOBufTest, cut_into_fd_with_offset_multithreaded) { @@ -1371,10 +1371,10 @@ TEST_F(IOBufTest, cut_into_fd_with_offset_multithreaded) { long fd = open(".out.txt", O_RDWR | O_CREAT | O_TRUNC, 0644); ASSERT_TRUE(fd >= 0) << berror(); for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, cut_into_fd, (void*)fd)); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, cut_into_fd, (void*)fd)); } for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } for (int i = 0; i < number_per_thread * (int)ARRAY_SIZE(threads); ++i) { off_t offset = i * sizeof(int); @@ -1437,7 +1437,7 @@ TEST_F(IOBufTest, iterate_bytes) { std::string saved_a = a.to_string(); size_t n = 0; butil::IOBufBytesIterator it(a); - for (; it != NULL; ++it, ++n) { + for (; it != nullptr; ++it, ++n) { ASSERT_EQ(saved_a[n], *it); } ASSERT_EQ(saved_a.size(), n); @@ -1445,7 +1445,7 @@ TEST_F(IOBufTest, iterate_bytes) { // append more to the iobuf, iterator should still be ended. a.append(", this is iobuf"); - ASSERT_TRUE(it == NULL); + ASSERT_TRUE(it == nullptr); // append more-than-one-block data to the iobuf for (int i = 0; i < 1024; ++i) { @@ -1453,7 +1453,7 @@ TEST_F(IOBufTest, iterate_bytes) { } saved_a = a.to_string(); n = 0; - for (butil::IOBufBytesIterator it2(a); it2 != NULL; it2++/*intended post++*/, ++n) { + for (butil::IOBufBytesIterator it2(a); it2 != nullptr; it2++/*intended post++*/, ++n) { ASSERT_EQ(saved_a[n], *it2); } ASSERT_EQ(saved_a.size(), n); @@ -1587,7 +1587,7 @@ TEST_F(IOBufTest, copy_to_string_from_iterator) { ASSERT_EQ(nc, b0.length()); } -static void* my_free_params = NULL; +static void* my_free_params = nullptr; static void my_free(void* m) { free(m); my_free_params = m; @@ -1603,7 +1603,7 @@ TEST_F(IOBufTest, append_user_data_and_consume) { data[i * REP + j] = (char)i; } } - my_free_params = NULL; + my_free_params = nullptr; ASSERT_EQ(0, b0.append_user_data(data, len, my_free)); ASSERT_EQ(1UL, b0._ref_num()); butil::IOBuf::BlockRef r = b0._front_ref(); @@ -1690,7 +1690,7 @@ TEST_F(IOBufTest, append_user_data_and_share) { data[i * REP + j] = (char)i; } } - my_free_params = NULL; + my_free_params = nullptr; ASSERT_EQ(0, b0.append_user_data(data, len, my_free)); ASSERT_EQ(1UL, b0._ref_num()); butil::IOBuf::BlockRef r = b0._front_ref(); @@ -1711,7 +1711,7 @@ TEST_F(IOBufTest, append_user_data_and_share) { ASSERT_TRUE(b0.empty()); } } - ASSERT_EQ(NULL, my_free_params); + ASSERT_EQ(nullptr, my_free_params); for (int i = 0; i < 256; ++i) { std::string out = bufs[i].to_string(); ASSERT_EQ((size_t)REP, out.size()); @@ -1755,11 +1755,11 @@ TEST_F(IOBufTest, share_tls_block) { ASSERT_NE(b, b2); butil::iobuf::release_tls_block_chain(b); ASSERT_EQ(b, butil::iobuf::share_tls_block()); - // After releasing b, now tls block is b(not full) -> b2(full) -> NULL + // After releasing b, now tls block is b(not full) -> b2(full) -> nullptr for (size_t i = 0; i < butil::iobuf::block_cap(b); i++) { buf.push_back('x'); } - // now tls block is b(full) -> b2(full) -> NULL + // now tls block is b(full) -> b2(full) -> nullptr butil::IOBuf::Block* head_block = butil::iobuf::share_tls_block(); ASSERT_EQ(0u, butil::iobuf::block_size(head_block)); ASSERT_NE(b, head_block); @@ -1906,7 +1906,7 @@ TEST_F(IOBufTest, single_iobuf) { size_t total_len = sizeof(src_str); strncpy(usr_str, src_str + 8, total_len - 8); buf1.append(src_str, 8); - buf1.append_user_data(usr_str, total_len - 8, NULL); + buf1.append_user_data(usr_str, total_len - 8, nullptr); ASSERT_EQ(2, buf1.backing_block_num()); butil::SingleIOBuf sbuf; ASSERT_EQ(0, sbuf.backing_block_num()); @@ -1928,9 +1928,9 @@ TEST_F(IOBufTest, single_iobuf) { ASSERT_EQ(0, sbuf2.get_length()); void* buf = sbuf.allocate(1024); - ASSERT_TRUE(NULL != buf); + ASSERT_TRUE(nullptr != buf); buf = sbuf.reallocate_downward(16384, 0, 0); - ASSERT_TRUE(NULL != buf); + ASSERT_TRUE(nullptr != buf); s_len = sbuf.get_length(); ASSERT_EQ(16384, s_len); @@ -1963,8 +1963,8 @@ TEST_F(IOBufTest, single_iobuf_assign_large_multi_block) { char* d2 = (char*)malloc(n2); memset(d2, 'b', n2); butil::IOBuf buf; - buf.append_user_data(d1, n1, NULL); - buf.append_user_data(d2, n2, NULL); + buf.append_user_data(d1, n1, nullptr); + buf.append_user_data(d2, n2, nullptr); ASSERT_EQ(2, buf.backing_block_num()); butil::SingleIOBuf sbuf; diff --git a/test/lazy_instance_unittest.cc b/test/lazy_instance_unittest.cc index a416f1d60c..8003c8defe 100644 --- a/test/lazy_instance_unittest.cc +++ b/test/lazy_instance_unittest.cc @@ -105,7 +105,7 @@ namespace { // It accepts a bool* and sets the bool to true when the dtor runs. class DeleteLogger { public: - DeleteLogger() : deleted_(NULL) {} + DeleteLogger() : deleted_(nullptr) {} ~DeleteLogger() { *deleted_ = true; } void SetDeletedPtr(bool* deleted) { diff --git a/test/linked_list_unittest.cc b/test/linked_list_unittest.cc index 57d96332d2..c72f82a2ea 100644 --- a/test/linked_list_unittest.cc +++ b/test/linked_list_unittest.cc @@ -65,12 +65,12 @@ TEST(LinkedList, Empty) { LinkedList list; EXPECT_EQ(list.end(), list.head()); EXPECT_EQ(list.end(), list.tail()); - ExpectListContents(list, 0, NULL); + ExpectListContents(list, 0, nullptr); } TEST(LinkedList, Append) { LinkedList list; - ExpectListContents(list, 0, NULL); + ExpectListContents(list, 0, nullptr); Node n1(1); list.Append(&n1); @@ -159,7 +159,7 @@ TEST(LinkedList, RemoveFromList) { n2.RemoveFromList(); n4.RemoveFromList(); - ExpectListContents(list, 0, NULL); + ExpectListContents(list, 0, nullptr); EXPECT_EQ(list.end(), list.head()); EXPECT_EQ(list.end(), list.tail()); diff --git a/test/linked_ptr_unittest.cc b/test/linked_ptr_unittest.cc index 18f51cbb6e..06e21184bc 100644 --- a/test/linked_ptr_unittest.cc +++ b/test/linked_ptr_unittest.cc @@ -38,18 +38,18 @@ TEST(LinkedPtrTest, Test) { linked_ptr a0, a1, a2; a0 = a0; a1 = a2; - ASSERT_EQ(a0.get(), static_cast(NULL)); - ASSERT_EQ(a1.get(), static_cast(NULL)); - ASSERT_EQ(a2.get(), static_cast(NULL)); - ASSERT_TRUE(a0 == NULL); - ASSERT_TRUE(a1 == NULL); - ASSERT_TRUE(a2 == NULL); + ASSERT_EQ(a0.get(), static_cast(nullptr)); + ASSERT_EQ(a1.get(), static_cast(nullptr)); + ASSERT_EQ(a2.get(), static_cast(nullptr)); + ASSERT_TRUE(a0 == nullptr); + ASSERT_TRUE(a1 == nullptr); + ASSERT_TRUE(a2 == nullptr); { linked_ptr a3(new A); a0 = a3; ASSERT_TRUE(a0 == a3); - ASSERT_TRUE(a0 != NULL); + ASSERT_TRUE(a0 != nullptr); ASSERT_TRUE(a0.get() == a3); ASSERT_TRUE(a0 == a3.get()); linked_ptr a4(a0); @@ -62,7 +62,7 @@ TEST(LinkedPtrTest, Test) { linked_ptr a6(b0); ASSERT_TRUE(b0 == a6); ASSERT_TRUE(a6 == b0); - ASSERT_TRUE(b0 != NULL); + ASSERT_TRUE(b0 != nullptr); a5 = b0; a5 = b0; a3->Use(); diff --git a/test/logging_unittest.cc b/test/logging_unittest.cc index 3a7576ff48..c1fea6ef19 100644 --- a/test/logging_unittest.cc +++ b/test/logging_unittest.cc @@ -39,7 +39,7 @@ class LogStateSaver { ~LogStateSaver() { SetMinLogLevel(old_min_log_level_); - SetLogAssertHandler(NULL); + SetLogAssertHandler(nullptr); log_sink_call_count = 0; } @@ -492,8 +492,8 @@ int g_prof_name_counter = 0; butil::atomic test_logging_count(0); void* test_async_log(void* arg) { - if (arg == NULL) { - return NULL; + if (arg == nullptr) { + return nullptr; } auto log = (std::string*)(arg); while (!g_stopped) { @@ -501,7 +501,7 @@ void* test_async_log(void* arg) { test_logging_count.fetch_add(1); } - return NULL; + return nullptr; } TEST_F(LoggingTest, async_log) { @@ -518,14 +518,14 @@ TEST_F(LoggingTest, async_log) { int thread_num = 8; pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, test_async_log, &log)); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, test_async_log, &log)); } usleep(1000 * 500); g_stopped = true; for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } // Wait for async log thread to flush all logs to file. sleep(15); @@ -534,7 +534,7 @@ TEST_F(LoggingTest, async_log) { std::string cmd = butil::string_printf("grep -c %s %s", log.c_str(), temp_file.fname()); ASSERT_LE(0, butil::read_command_output(oss, cmd.c_str())); - uint64_t log_count = std::strtol(oss.str().c_str(), NULL, 10); + uint64_t log_count = std::strtol(oss.str().c_str(), nullptr, 10); ASSERT_EQ(log_count, test_logging_count.load()); FLAGS_async_log = saved_async_log; @@ -547,7 +547,7 @@ struct BAIDU_CACHELINE_ALIGNMENT PerfArgs { int64_t elapse_ns; bool ready; - PerfArgs() : log(NULL), counter(0), elapse_ns(0), ready(false) {} + PerfArgs() : log(nullptr), counter(0), elapse_ns(0), ready(false) {} }; void* test_log(void* void_arg) { @@ -573,7 +573,7 @@ void* test_log(void* void_arg) { t.stop(); args->elapse_ns = t.n_elapsed(); args->counter = counter; - return NULL; + return nullptr; } void PerfTest(int thread_num, const std::string& log, bool async) { @@ -585,7 +585,7 @@ void PerfTest(int thread_num, const std::string& log, bool async) { std::vector args(thread_num); for (int i = 0; i < thread_num; ++i) { args[i].log = &log; - ASSERT_EQ(0, pthread_create(&threads[i], NULL, test_log, &args[i])); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, test_log, &args[i])); } while (true) { bool all_ready = true; @@ -611,7 +611,7 @@ void PerfTest(int thread_num, const std::string& log, bool async) { int64_t wait_time = 0; int64_t count = 0; for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); wait_time += args[i].elapse_ns; count += args[i].counter; } diff --git a/test/memory_unittest.cc b/test/memory_unittest.cc index 6413b82826..9ceae89e7e 100644 --- a/test/memory_unittest.cc +++ b/test/memory_unittest.cc @@ -40,7 +40,7 @@ TEST(ProcessMemoryTest, GetModuleFromAddress) { // // kConstantInModule is a constant in this file and // therefore within the unit test EXE. - EXPECT_EQ(::GetModuleHandle(NULL), + EXPECT_EQ(::GetModuleHandle(nullptr), butil::GetModuleFromAddress( const_cast(&kConstantInModule))); @@ -63,7 +63,7 @@ TEST(ProcessMemoryTest, EnableLFH) { return; } HMODULE kernel32 = GetModuleHandle(L"kernel32.dll"); - ASSERT_TRUE(kernel32 != NULL); + ASSERT_TRUE(kernel32 != nullptr); HeapQueryFn heap_query = reinterpret_cast(GetProcAddress( kernel32, "HeapQueryInformation")); @@ -71,7 +71,7 @@ TEST(ProcessMemoryTest, EnableLFH) { // On Windows 2000, the function is not exported. This is not a reason to // fail but we won't be able to retrieves information about the heap, so we // should stop here. - if (heap_query == NULL) + if (heap_query == nullptr) return; HANDLE heaps[1024] = { 0 }; @@ -110,10 +110,10 @@ TEST(ProcessMemoryTest, EnableLFH) { TEST(ProcessMemoryTest, MacMallocFailureDoesNotTerminate) { // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit // code and lack of the error string. The number of bytes is one less than - // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and + // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns nullptr and // does not call through malloc_error_break(). See the comment at // EnableTerminationOnOutOfMemory() for more information. - void* buf = NULL; + void* buf = nullptr; ASSERT_EXIT( { butil::EnableTerminationOnOutOfMemory(); @@ -165,7 +165,7 @@ int tc_set_new_mode(int mode); class OutOfMemoryTest : public testing::Test { public: OutOfMemoryTest() - : value_(NULL), + : value_(nullptr), // Make test size as large as possible minus a few pages so // that alignment or other rounding doesn't make it wrap. test_size_(std::numeric_limits::max() - 12 * 1024), @@ -224,7 +224,7 @@ TEST_F(OutOfMemoryDeathTest, Malloc) { TEST_F(OutOfMemoryDeathTest, Realloc) { ASSERT_DEATH({ SetUpInDeathAssert(); - value_ = realloc(NULL, test_size_); + value_ = realloc(nullptr, test_size_); }, ""); } @@ -267,7 +267,7 @@ TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) { // This tests that the run-time symbol resolution is overriding malloc for // shared libraries (including libc itself) as well as for our code. std::string format = butil::StringPrintf("%%%zud", test_size_); - char *value = NULL; + char *value = nullptr; ASSERT_DEATH({ SetUpInDeathAssert(); EXPECT_EQ(-1, asprintf(&value, format.c_str(), 0)); @@ -306,7 +306,7 @@ TEST_F(OutOfMemoryDeathTest, ReallocPurgeable) { malloc_zone_t* zone = malloc_default_purgeable_zone(); ASSERT_DEATH({ SetUpInDeathAssert(); - value_ = malloc_zone_realloc(zone, NULL, test_size_); + value_ = malloc_zone_realloc(zone, nullptr, test_size_); }, ""); } @@ -403,16 +403,16 @@ class OutOfMemoryHandledTest : public OutOfMemoryTest { #if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) TEST_F(OutOfMemoryHandledTest, UncheckedMalloc) { EXPECT_TRUE(butil::UncheckedMalloc(kSafeMallocSize, &value_)); - EXPECT_TRUE(value_ != NULL); + EXPECT_TRUE(value_ != nullptr); free(value_); EXPECT_FALSE(butil::UncheckedMalloc(test_size_, &value_)); - EXPECT_TRUE(value_ == NULL); + EXPECT_TRUE(value_ == nullptr); } TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) { EXPECT_TRUE(butil::UncheckedCalloc(1, kSafeMallocSize, &value_)); - EXPECT_TRUE(value_ != NULL); + EXPECT_TRUE(value_ != nullptr); const char* bytes = static_cast(value_); for (size_t i = 0; i < kSafeMallocSize; ++i) EXPECT_EQ(0, bytes[i]); @@ -420,14 +420,14 @@ TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) { EXPECT_TRUE( butil::UncheckedCalloc(kSafeCallocItems, kSafeCallocSize, &value_)); - EXPECT_TRUE(value_ != NULL); + EXPECT_TRUE(value_ != nullptr); bytes = static_cast(value_); for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) EXPECT_EQ(0, bytes[i]); free(value_); EXPECT_FALSE(butil::UncheckedCalloc(1, test_size_, &value_)); - EXPECT_TRUE(value_ == NULL); + EXPECT_TRUE(value_ == nullptr); } #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) diff --git a/test/mpsc_queue_unittest.cc b/test/mpsc_queue_unittest.cc index c651e3a0aa..eae2f6f27c 100644 --- a/test/mpsc_queue_unittest.cc +++ b/test/mpsc_queue_unittest.cc @@ -29,13 +29,13 @@ void* ProduceThread(void* arg) { for (uint i = 0; i < MAX_COUNT; ++i) { q->Enqueue(i); } - return NULL; + return nullptr; } void* ConsumeThread1(void* arg) { auto q = (butil::MPSCQueue*)arg; Consume(*q, true); - return NULL; + return nullptr; } TEST(MPSCQueueTest, spsc_single_thread) { @@ -49,12 +49,12 @@ TEST(MPSCQueueTest, spsc_single_thread) { TEST(MPSCQueueTest, spsc_multi_thread) { butil::MPSCQueue q; pthread_t produce_tid; - ASSERT_EQ(0, pthread_create(&produce_tid, NULL, ProduceThread, &q)); + ASSERT_EQ(0, pthread_create(&produce_tid, nullptr, ProduceThread, &q)); pthread_t consume_tid; - ASSERT_EQ(0, pthread_create(&consume_tid, NULL, ConsumeThread1, &q)); + ASSERT_EQ(0, pthread_create(&consume_tid, nullptr, ConsumeThread1, &q)); - pthread_join(produce_tid, NULL); - pthread_join(consume_tid, NULL); + pthread_join(produce_tid, nullptr); + pthread_join(consume_tid, nullptr); } @@ -68,7 +68,7 @@ void* MultiProduceThread(void* arg) { } q->Enqueue(i); } - return NULL; + return nullptr; } butil::Mutex g_mutex; @@ -98,7 +98,7 @@ void Consume2(butil::MPSCQueue& q) { void* ConsumeThread2(void* arg) { auto q = (butil::MPSCQueue*)arg; Consume2(*q); - return NULL; + return nullptr; } TEST(MPSCQueueTest, mpsc_multi_thread) { @@ -107,16 +107,16 @@ TEST(MPSCQueueTest, mpsc_multi_thread) { int thread_num = 8; pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, MultiProduceThread, &q)); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, MultiProduceThread, &q)); } pthread_t consume_tid; - ASSERT_EQ(0, pthread_create(&consume_tid, NULL, ConsumeThread2, &q)); + ASSERT_EQ(0, pthread_create(&consume_tid, nullptr, ConsumeThread2, &q)); for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); } - pthread_join(consume_tid, NULL); + pthread_join(consume_tid, nullptr); } diff --git a/test/multiprocess_func_list.h b/test/multiprocess_func_list.h index f806d53c93..8f7e8430c5 100644 --- a/test/multiprocess_func_list.h +++ b/test/multiprocess_func_list.h @@ -52,7 +52,7 @@ int InvokeChildProcessTest(std::string test_name); // This macro creates a global MultiProcessTest::AppendMultiProcessTest object // whose constructor does the work of adding the global mapping. #define MULTIPROCESS_TEST_MAIN(test_main) \ - MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, NULL) + MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, nullptr) // Same as above but lets callers specify a setup method that is run in the // child process, just before the main function is run. This facilitates diff --git a/test/object_pool_unittest.cpp b/test/object_pool_unittest.cpp index d7fecf5edf..366b052240 100644 --- a/test/object_pool_unittest.cpp +++ b/test/object_pool_unittest.cpp @@ -289,7 +289,7 @@ void* get_and_return_int(void*) { (size_t)pthread_self(), j, tm1.n_elapsed()/(double)N, tm2.n_elapsed()/(double)N); } - return NULL; + return nullptr; } void* new_and_delete_int(void*) { @@ -326,29 +326,29 @@ void* new_and_delete_int(void*) { tm2.n_elapsed()/(double)N); } - return NULL; + return nullptr; } TEST_F(ObjectPoolTest, get_and_return_int_single_thread) { - get_and_return_int(NULL); - new_and_delete_int(NULL); + get_and_return_int(nullptr); + new_and_delete_int(nullptr); } TEST_F(ObjectPoolTest, get_and_return_int_multiple_threads) { pthread_t tid[16]; for (size_t i = 0; i < ARRAY_SIZE(tid); ++i) { - ASSERT_EQ(0, pthread_create(&tid[i], NULL, get_and_return_int, NULL)); + ASSERT_EQ(0, pthread_create(&tid[i], nullptr, get_and_return_int, nullptr)); } for (size_t i = 0; i < ARRAY_SIZE(tid); ++i) { - pthread_join(tid[i], NULL); + pthread_join(tid[i], nullptr); } pthread_t tid2[16]; for (size_t i = 0; i < ARRAY_SIZE(tid2); ++i) { - ASSERT_EQ(0, pthread_create(&tid2[i], NULL, new_and_delete_int, NULL)); + ASSERT_EQ(0, pthread_create(&tid2[i], nullptr, new_and_delete_int, nullptr)); } for (size_t i = 0; i < ARRAY_SIZE(tid2); ++i) { - pthread_join(tid2[i], NULL); + pthread_join(tid2[i], nullptr); } std::cout << describe_objects() << std::endl; diff --git a/test/popen_unittest.cpp b/test/popen_unittest.cpp index 81d4cdecb5..776456097f 100644 --- a/test/popen_unittest.cpp +++ b/test/popen_unittest.cpp @@ -106,7 +106,7 @@ static void* counter_thread(void* args) { while (!ca->stop) { ++ca->counter; } - return NULL; + return nullptr; } static int fork_thread(void* arg) { @@ -119,18 +119,18 @@ const int CHILD_STACK_SIZE = 64 * 1024; TEST(PopenTest, does_vfork_suspend_all_threads) { pthread_t tid; CounterArg ca = { 0 , false }; - ASSERT_EQ(0, pthread_create(&tid, NULL, counter_thread, &ca)); + ASSERT_EQ(0, pthread_create(&tid, nullptr, counter_thread, &ca)); usleep(100 * 1000); char* child_stack_mem = (char*)malloc(CHILD_STACK_SIZE); void* child_stack = child_stack_mem + CHILD_STACK_SIZE; const int64_t counter_before_fork = ca.counter; - pid_t cpid = clone(fork_thread, child_stack, CLONE_VFORK, NULL); + pid_t cpid = clone(fork_thread, child_stack, CLONE_VFORK, nullptr); const int64_t counter_after_fork = ca.counter; usleep(100 * 1000); const int64_t counter_after_sleep = ca.counter; int ws; ca.stop = true; - pthread_join(tid, NULL); + pthread_join(tid, nullptr); std::cout << "bc=" << counter_before_fork << " ac=" << counter_after_fork << " as=" << counter_after_sleep << std::endl; diff --git a/test/recordio_unittest.cpp b/test/recordio_unittest.cpp index ed1dfece09..aec156522b 100644 --- a/test/recordio_unittest.cpp +++ b/test/recordio_unittest.cpp @@ -75,7 +75,7 @@ class StringWriter : public butil::IWriter { TEST(RecordIOTest, empty_record) { butil::Record r; ASSERT_EQ((size_t)0, r.MetaCount()); - ASSERT_TRUE(r.Meta("foo") == NULL); + ASSERT_TRUE(r.Meta("foo") == nullptr); ASSERT_FALSE(r.RemoveMeta("foo")); ASSERT_TRUE(r.Payload().empty()); ASSERT_TRUE(r.MutablePayload()->empty()); @@ -106,7 +106,7 @@ TEST(RecordIOTest, manipulate_record) { ASSERT_TRUE(r1.RemoveMeta("foo")); ASSERT_EQ((size_t)1, r1.MetaCount()); - ASSERT_TRUE(r1.Meta("foo") == NULL); + ASSERT_TRUE(r1.Meta("foo") == nullptr); ASSERT_EQ(foo_val, r2.Meta("foo")); ASSERT_EQ("foo_data", *foo_val); @@ -119,7 +119,7 @@ TEST(RecordIOTest, invalid_name) { } name[sizeof(name) - 1] = 0; butil::Record r; - ASSERT_EQ(NULL, r.MutableMeta(name)); + ASSERT_EQ(nullptr, r.MutableMeta(name)); } TEST(RecordIOTest, write_read_basic) { @@ -180,7 +180,7 @@ TEST(RecordIOTest, write_read_basic) { ASSERT_EQ("bar_data", *r4.MetaAt(1).data); ASSERT_EQ("payload_data", r4.Payload()); - ASSERT_FALSE(rr.ReadNext(NULL)); + ASSERT_FALSE(rr.ReadNext(nullptr)); ASSERT_EQ((int)butil::RecordReader::END_OF_READER, rr.last_error()); ASSERT_EQ(sw.str().size(), rr.offset()); } @@ -224,7 +224,7 @@ TEST(RecordIOTest, incomplete_reader) { ASSERT_EQ("bar_data", *r3.MetaAt(1).data); ASSERT_TRUE(r3.Payload().empty()); - ASSERT_FALSE(rr.ReadNext(NULL)); + ASSERT_FALSE(rr.ReadNext(nullptr)); ASSERT_EQ(EAGAIN, rr.last_error()); ASSERT_EQ(sw.str().size(), rr.offset()); } diff --git a/test/ref_counted_memory_unittest.cc b/test/ref_counted_memory_unittest.cc index c9bf40ba7b..796d1e47f3 100644 --- a/test/ref_counted_memory_unittest.cc +++ b/test/ref_counted_memory_unittest.cc @@ -83,7 +83,7 @@ TEST(RefCountedMemoryUnitTest, Equals) { TEST(RefCountedMemoryUnitTest, EqualsNull) { std::string s("str"); scoped_refptr mem = RefCountedString::TakeString(&s); - EXPECT_FALSE(mem->Equals(NULL)); + EXPECT_FALSE(mem->Equals(nullptr)); } } // namespace butil diff --git a/test/ref_counted_unittest.cc b/test/ref_counted_unittest.cc index 7415ba3e84..da82219de8 100644 --- a/test/ref_counted_unittest.cc +++ b/test/ref_counted_unittest.cc @@ -28,7 +28,7 @@ class ScopedRefPtrToSelf : public butil::RefCounted { static bool was_destroyed() { return was_destroyed_; } - void SelfDestruct() { self_ptr_ = NULL; } + void SelfDestruct() { self_ptr_ = nullptr; } private: friend class butil::RefCounted; diff --git a/test/resource_pool_unittest.cpp b/test/resource_pool_unittest.cpp index 9a56ff3bb5..7bbac85be2 100644 --- a/test/resource_pool_unittest.cpp +++ b/test/resource_pool_unittest.cpp @@ -331,7 +331,7 @@ void* get_and_return_int(void*) { printf("[%lu:%d] get=%.1f return=%.1f\n", pthread_self(), j, tm1.n_elapsed()/(double)N, tm2.n_elapsed()/(double)N); } - return NULL; + return nullptr; } void* new_and_delete_int(void*) { @@ -367,29 +367,29 @@ void* new_and_delete_int(void*) { pthread_self(), j, tm1.n_elapsed()/(double)N, tm2.n_elapsed()/(double)N); } - return NULL; + return nullptr; } TEST_F(ResourcePoolTest, get_and_return_int_single_thread) { - get_and_return_int(NULL); - new_and_delete_int(NULL); + get_and_return_int(nullptr); + new_and_delete_int(nullptr); } TEST_F(ResourcePoolTest, get_and_return_int_multiple_threads) { pthread_t tid[16]; for (size_t i = 0; i < ARRAY_SIZE(tid); ++i) { - ASSERT_EQ(0, pthread_create(&tid[i], NULL, get_and_return_int, NULL)); + ASSERT_EQ(0, pthread_create(&tid[i], nullptr, get_and_return_int, nullptr)); } for (size_t i = 0; i < ARRAY_SIZE(tid); ++i) { - pthread_join(tid[i], NULL); + pthread_join(tid[i], nullptr); } pthread_t tid2[16]; for (size_t i = 0; i < ARRAY_SIZE(tid2); ++i) { - ASSERT_EQ(0, pthread_create(&tid2[i], NULL, new_and_delete_int, NULL)); + ASSERT_EQ(0, pthread_create(&tid2[i], nullptr, new_and_delete_int, nullptr)); } for (size_t i = 0; i < ARRAY_SIZE(tid2); ++i) { - pthread_join(tid2[i], NULL); + pthread_join(tid2[i], nullptr); } std::cout << describe_resources() << std::endl; diff --git a/test/safe_sprintf_unittest.cc b/test/safe_sprintf_unittest.cc index 21da00a5a0..46d681e3f1 100644 --- a/test/safe_sprintf_unittest.cc +++ b/test/safe_sprintf_unittest.cc @@ -368,7 +368,7 @@ void PrintLongString(char* buf, size_t sz) { // - test zero-padding and truncating %x hexadecimal numbers. // - test outputting and truncating %d MININT. // - test outputting and truncating %p arbitrary pointer values. - // - test outputting, padding and truncating NULL-pointer %s strings. + // - test outputting, padding and truncating nullptr-pointer %s strings. char* out = tmp.get(); size_t out_sz = sz; size_t len; @@ -380,7 +380,7 @@ void PrintLongString(char* buf, size_t sz) { "A%2cong %s: %%d %010X %d %p%7s", 'l', "string", #endif 0xDEADBEEF, std::numeric_limits::min(), - PrintLongString, static_cast(NULL)) + 1; + PrintLongString, static_cast(nullptr)) + 1; // Various sanity checks: // The numbered of characters needed to print the full string should always diff --git a/test/scoped_locale.cc b/test/scoped_locale.cc index eef133f180..3db92cff75 100644 --- a/test/scoped_locale.cc +++ b/test/scoped_locale.cc @@ -11,8 +11,8 @@ namespace butil { ScopedLocale::ScopedLocale(const std::string& locale) { - prev_locale_ = setlocale(LC_ALL, NULL); - EXPECT_TRUE(setlocale(LC_ALL, locale.c_str()) != NULL) << + prev_locale_ = setlocale(LC_ALL, nullptr); + EXPECT_TRUE(setlocale(LC_ALL, locale.c_str()) != nullptr) << "Failed to set locale: " << locale; } diff --git a/test/scoped_ptr_unittest.cc b/test/scoped_ptr_unittest.cc index 8fe2acc5e2..86af29e38f 100644 --- a/test/scoped_ptr_unittest.cc +++ b/test/scoped_ptr_unittest.cc @@ -21,7 +21,7 @@ class ConDecLoggerParent { class ConDecLogger : public ConDecLoggerParent { public: - ConDecLogger() : ptr_(NULL) { } + ConDecLogger() : ptr_(nullptr) { } explicit ConDecLogger(int* ptr) { SetPtr(ptr); } virtual ~ConDecLogger() { --*ptr_; } @@ -489,7 +489,7 @@ TEST(ScopedPtrTest, CustomDeleter) { // Test reset() and release(). deletes = 0; { - scoped_ptr scoper(NULL, + scoped_ptr scoper(nullptr, CountingDeleter(&deletes)); EXPECT_FALSE(scoper.get()); EXPECT_FALSE(scoper.release()); @@ -563,9 +563,9 @@ TEST(ScopedPtrTest, CustomDeleter) { // Test swap(), ==, !=, and type-safe Boolean. { - scoped_ptr scoper1(NULL, + scoped_ptr scoper1(nullptr, CountingDeleter(&deletes)); - scoped_ptr scoper2(NULL, + scoped_ptr scoper2(nullptr, CountingDeleter(&deletes)); EXPECT_TRUE(scoper1 == scoper2.get()); EXPECT_FALSE(scoper1 != scoper2.get()); diff --git a/test/scoped_vector_unittest.cc b/test/scoped_vector_unittest.cc index be0e99e5c4..415edec03e 100644 --- a/test/scoped_vector_unittest.cc +++ b/test/scoped_vector_unittest.cc @@ -66,7 +66,7 @@ class LifeCycleWatcher : public LifeCycleObject::Observer { // LifeCycleWatcher. virtual void OnLifeCycleConstruct(LifeCycleObject* object) OVERRIDE { ASSERT_EQ(LC_INITIAL, life_cycle_state_); - ASSERT_EQ(NULL, constructed_life_cycle_object_.get()); + ASSERT_EQ(nullptr, constructed_life_cycle_object_.get()); life_cycle_state_ = LC_CONSTRUCTED; constructed_life_cycle_object_.reset(object); } diff --git a/test/security_unittest.cc b/test/security_unittest.cc index 739b6c7438..91c2d27b9f 100644 --- a/test/security_unittest.cc +++ b/test/security_unittest.cc @@ -78,9 +78,9 @@ bool IsTcMallocBypassed() { } bool CallocDiesOnOOM() { -// The sanitizers' calloc dies on OOM instead of returning NULL. +// The sanitizers' calloc dies on OOM instead of returning nullptr. // The wrapper function in butil/process_util_linux.cc that is used when we -// compile without TCMalloc will just die on OOM instead of returning NULL. +// compile without TCMalloc will just die on OOM instead of returning nullptr. #if defined(ADDRESS_SANITIZER) || \ defined(MEMORY_SANITIZER) || \ defined(THREAD_SANITIZER) || \ @@ -219,8 +219,8 @@ bool CallocReturnsNull(size_t nmemb, size_t size) { static_cast(calloc(nmemb, size))); // We need the call to HideValueFromCompiler(): we have seen LLVM // optimize away the call to calloc() entirely and assume - // the pointer to not be NULL. - return HideValueFromCompiler(array_pointer.get()) == NULL; + // the pointer to not be nullptr. + return HideValueFromCompiler(array_pointer.get()) == nullptr; } // Test if calloc() can overflow. @@ -268,13 +268,13 @@ TEST(SecurityTest, TCMALLOC_TEST(RandomMemoryAllocations)) { ASSERT_EQ(munmap(default_mmap_heap_address, kPageSize), 0); void* brk_heap_address = sbrk(0); ASSERT_NE(brk_heap_address, reinterpret_cast(-1)); - ASSERT_TRUE(brk_heap_address != NULL); + ASSERT_TRUE(brk_heap_address != nullptr); // 1 MB should get us past what TCMalloc pre-allocated before initializing // the sophisticated allocators. size_t kAllocSize = 1<<20; scoped_ptr ptr( static_cast(malloc(kAllocSize))); - ASSERT_TRUE(ptr != NULL); + ASSERT_TRUE(ptr != nullptr); // If two pointers are separated by less than 512MB, they are considered // to be in the same area. // Our random pointer could be anywhere within 0x3fffffffffff (46bits), diff --git a/test/shared_memory_unittest.cc b/test/shared_memory_unittest.cc index 09b09365c3..bbdeec63fd 100644 --- a/test/shared_memory_unittest.cc +++ b/test/shared_memory_unittest.cc @@ -106,7 +106,7 @@ class MultipleLockThread : public PlatformThread::Delegate { // PlatformThread::Delegate interface. virtual void ThreadMain() OVERRIDE { const uint32_t kDataSize = sizeof(int); - SharedMemoryHandle handle = NULL; + SharedMemoryHandle handle = nullptr; { SharedMemory memory1; EXPECT_TRUE(memory1.CreateNamedDeprecated( @@ -170,8 +170,8 @@ TEST(SharedMemoryTest, OpenClose) { EXPECT_NE(memory1.memory(), memory2.memory()); // Compare the pointers. // Make sure we don't segfault. (it actually happened!) - ASSERT_NE(memory1.memory(), static_cast(NULL)); - ASSERT_NE(memory2.memory(), static_cast(NULL)); + ASSERT_NE(memory1.memory(), static_cast(nullptr)); + ASSERT_NE(memory2.memory(), static_cast(nullptr)); // Write data to the first memory segment, verify contents of second. memset(memory1.memory(), '1', kDataSize); @@ -419,7 +419,7 @@ TEST(SharedMemoryTest, ShareReadOnly) { errno = 0; void* writable = mmap( - NULL, contents.size(), PROT_READ | PROT_WRITE, MAP_SHARED, handle.fd, 0); + nullptr, contents.size(), PROT_READ | PROT_WRITE, MAP_SHARED, handle.fd, 0); int mmap_errno = errno; EXPECT_EQ(MAP_FAILED, writable) << "It shouldn't be possible to re-mmap the descriptor writable."; @@ -428,7 +428,7 @@ TEST(SharedMemoryTest, ShareReadOnly) { EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); #elif defined(OS_WIN) - EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) + EXPECT_EQ(nullptr, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) << "Shouldn't be able to map memory writable."; HANDLE temp_handle; @@ -482,7 +482,7 @@ TEST(SharedMemoryTest, MapAt) { SharedMemory memory; ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize)); uint32_t* ptr = static_cast(memory.memory()); - ASSERT_NE(ptr, static_cast(NULL)); + ASSERT_NE(ptr, static_cast(nullptr)); for (size_t i = 0; i < kCount; ++i) { ptr[i] = i; @@ -494,7 +494,7 @@ TEST(SharedMemoryTest, MapAt) { ASSERT_TRUE(memory.MapAt(offset, kDataSize - offset)); offset /= sizeof(uint32_t); ptr = static_cast(memory.memory()); - ASSERT_NE(ptr, static_cast(NULL)); + ASSERT_NE(ptr, static_cast(nullptr)); for (size_t i = offset; i < kCount; ++i) { EXPECT_EQ(ptr[i - offset], i); } diff --git a/test/singleton_unittest.cc b/test/singleton_unittest.cc index 9881165878..b8d157644b 100644 --- a/test/singleton_unittest.cc +++ b/test/singleton_unittest.cc @@ -59,7 +59,7 @@ struct CallbackTrait : public DefaultSingletonTraits { class CallbackSingleton { public: - CallbackSingleton() : callback_(NULL) { } + CallbackSingleton() : callback_(nullptr) { } CallbackFunc callback_; }; @@ -238,7 +238,7 @@ TEST_F(SingletonTest, Basic) { DeleteLeakySingleton(); // The static singleton can't be acquired post-atexit. - EXPECT_EQ(NULL, GetStaticSingleton()); + EXPECT_EQ(nullptr, GetStaticSingleton()); { butil::ShadowingAtExitManager sem; diff --git a/test/stack_container_unittest.cc b/test/stack_container_unittest.cc index c245a92c80..895b12417c 100644 --- a/test/stack_container_unittest.cc +++ b/test/stack_container_unittest.cc @@ -88,7 +88,7 @@ TEST(StackContainer, VectorDoubleDelete) { EXPECT_EQ(alive, 1); Dummy* dummy_unref = dummy.get(); - dummy = NULL; + dummy = nullptr; EXPECT_EQ(alive, 1); Container::iterator itr = std::find(vect->begin(), vect->end(), dummy_unref); diff --git a/test/string_number_conversions_unittest.cc b/test/string_number_conversions_unittest.cc index 7d1e9a6232..67641005d7 100644 --- a/test/string_number_conversions_unittest.cc +++ b/test/string_number_conversions_unittest.cc @@ -786,7 +786,7 @@ TEST(StringNumberConversionsTest, DoubleToString) { } TEST(StringNumberConversionsTest, HexEncode) { - std::string hex(HexEncode(NULL, 0)); + std::string hex(HexEncode(nullptr, 0)); EXPECT_EQ(hex.length(), 0U); unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; hex = HexEncode(bytes, sizeof(bytes)); diff --git a/test/string_piece_unittest.cc b/test/string_piece_unittest.cc index 5b65c696d4..cc27d1fd5b 100644 --- a/test/string_piece_unittest.cc +++ b/test/string_piece_unittest.cc @@ -156,7 +156,7 @@ TYPED_TEST(CommonStringPieceTest, CheckSTL) { ASSERT_EQ(*d.data(), static_cast('f')); ASSERT_EQ(d.data()[5], static_cast('r')); - ASSERT_TRUE(e.data() == NULL); + ASSERT_TRUE(e.data() == nullptr); ASSERT_EQ(*a.begin(), static_cast('a')); ASSERT_EQ(*(b.begin() + 2), static_cast('c')); @@ -185,7 +185,7 @@ TYPED_TEST(CommonStringPieceTest, CheckSTL) { d.clear(); ASSERT_EQ(d.size(), 0U); ASSERT_TRUE(d.empty()); - ASSERT_TRUE(d.data() == NULL); + ASSERT_TRUE(d.data() == nullptr); ASSERT_TRUE(d.begin() == d.end()); ASSERT_GE(a.max_size(), a.capacity()); @@ -508,11 +508,11 @@ TYPED_TEST(CommonStringPieceTest, CheckCustom) { ASSERT_EQ(c, a); c.set(foobar.c_str(), 0); ASSERT_EQ(c, e); - c.set(foobar.c_str(), 7); // Note, has an embedded NULL + c.set(foobar.c_str(), 7); // Note, has an embedded nullptr ASSERT_NE(c, a); // as_string - TypeParam s3(a.as_string().c_str(), 7); // Note, has an embedded NULL + TypeParam s3(a.as_string().c_str(), 7); // Note, has an embedded nullptr ASSERT_TRUE(c == s3); TypeParam s4(e.as_string()); ASSERT_TRUE(s4.empty()); @@ -581,12 +581,12 @@ TEST(StringPieceTest, CheckCustom) { TYPED_TEST(CommonStringPieceTest, CheckNULL) { // we used to crash here, but now we don't. - BasicStringPiece s(NULL); - ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); + BasicStringPiece s(nullptr); + ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)nullptr); ASSERT_EQ(s.size(), 0U); - s.set(NULL); - ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)NULL); + s.set(nullptr); + ASSERT_EQ(s.data(), (const typename TypeParam::value_type*)nullptr); ASSERT_EQ(s.size(), 0U); TypeParam str = s.as_string(); @@ -676,8 +676,8 @@ TYPED_TEST(CommonStringPieceTest, CheckConstructors) { BasicStringPiece(str.c_str(), 5)); ASSERT_TRUE(empty == BasicStringPiece(str.c_str(), static_cast::size_type>(0))); - ASSERT_TRUE(empty == BasicStringPiece(NULL)); - ASSERT_TRUE(empty == BasicStringPiece(NULL, + ASSERT_TRUE(empty == BasicStringPiece(nullptr)); + ASSERT_TRUE(empty == BasicStringPiece(nullptr, static_cast::size_type>(0))); ASSERT_TRUE(empty == BasicStringPiece()); ASSERT_TRUE(str == BasicStringPiece(str.begin(), str.end())); diff --git a/test/string_splitter_unittest.cpp b/test/string_splitter_unittest.cpp index c3b66a24c0..bac31c43e7 100644 --- a/test/string_splitter_unittest.cpp +++ b/test/string_splitter_unittest.cpp @@ -36,13 +36,13 @@ TEST_F(StringSplitterTest, sanity) { const char* str = "hello there! man "; butil::StringSplitter ss(str, ' '); // "hello" - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(5ul, ss.length()); ASSERT_EQ(ss.field(), str); // "there!" ++ss; - ASSERT_NE(ss, (void*)NULL); + ASSERT_NE(ss, (void*)nullptr); ASSERT_EQ(6ul, ss.length()); ASSERT_EQ(ss.field(), str+6); @@ -363,31 +363,31 @@ TEST_F(StringSplitterTest, non_null_terminated_string) { butil::StringSplitter ss(buf, buf + len, ' '); // "a" - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(1ul, ss.length()); ASSERT_EQ(ss.field(), buf + 2); // "non" ++ss; - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(3ul, ss.length()); ASSERT_EQ(ss.field(), buf + 4); // "null" ++ss; - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(4ul, ss.length()); ASSERT_EQ(ss.field(), buf + 9); // "terminated" ++ss; - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(10ul, ss.length()); ASSERT_EQ(ss.field(), buf + 16); // "string" ++ss; - ASSERT_TRUE(ss != NULL); + ASSERT_TRUE(ss != nullptr); ASSERT_EQ(6ul, ss.length()); ASSERT_EQ(ss.field(), buf + 28); @@ -403,7 +403,7 @@ TEST_F(StringSplitterTest, key_value_pairs_splitter_sanity) { std::string kvstr = "key1=value1&&&key2=value2&key3=value3&===&key4=&=&=value5"; for (int i = 0 ; i < 3; ++i) { // Test three constructors - butil::KeyValuePairsSplitter* psplitter = NULL; + butil::KeyValuePairsSplitter* psplitter = nullptr; if (i == 0) { psplitter = new butil::KeyValuePairsSplitter(kvstr, '&', '='); } else if (i == 1) { diff --git a/test/string_util_unittest.cc b/test/string_util_unittest.cc index 0b60af2eba..d9567b6581 100644 --- a/test/string_util_unittest.cc +++ b/test/string_util_unittest.cc @@ -871,7 +871,7 @@ TEST(StringUtilTest, ReplaceStringPlaceholdersTooFew) { string16 formatted = ReplaceStringPlaceholders( - ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$1g,$2h,$3i"), subst, NULL); + ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$1g,$2h,$3i"), subst, nullptr); EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,d,e,f,9ag,8bh,7ci")); } @@ -890,7 +890,7 @@ TEST(StringUtilTest, ReplaceStringPlaceholders) { string16 formatted = ReplaceStringPlaceholders( - ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i"), subst, NULL); + ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i"), subst, nullptr); EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii")); } @@ -915,7 +915,7 @@ TEST(StringUtilTest, ReplaceStringPlaceholdersMoreThan9Replacements) { string16 formatted = ReplaceStringPlaceholders( ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i," - "$10j,$11k,$12l,$13m,$14n,$1"), subst, NULL); + "$10j,$11k,$12l,$13m,$14n,$1"), subst, nullptr); EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh," "1ii,0jj,-1kk,-2ll,-3mm,-4nn,9a")); @@ -935,7 +935,7 @@ TEST(StringUtilTest, StdStringReplaceStringPlaceholders) { std::string formatted = ReplaceStringPlaceholders( - "$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i", subst, NULL); + "$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i", subst, nullptr); EXPECT_EQ(formatted, "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii"); } @@ -945,7 +945,7 @@ TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) { subst.push_back("a"); subst.push_back("b"); subst.push_back("c"); - EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, NULL), + EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, nullptr), "$1 $$2 $$$3"); } diff --git a/test/synchronous_event_unittest.cpp b/test/synchronous_event_unittest.cpp index 96b3c22190..54768a0831 100644 --- a/test/synchronous_event_unittest.cpp +++ b/test/synchronous_event_unittest.cpp @@ -40,7 +40,7 @@ std::vector > result; class FooObserver : public FooEvent::Observer { public: - FooObserver() : another_ob(NULL) {} + FooObserver() : another_ob(nullptr) {} void on_event(int x, int* p) { ++*p; diff --git a/test/thread_key_unittest.cpp b/test/thread_key_unittest.cpp index 06cbabaad6..681bb3e298 100644 --- a/test/thread_key_unittest.cpp +++ b/test/thread_key_unittest.cpp @@ -57,14 +57,14 @@ TEST(ThreadLocalTest, sanity) { for (int i = 0; i < 5; ++i) { std::unique_ptr data(new int(1)); int *raw_data = data.get(); - ASSERT_EQ(0, butil::thread_key_create(key, NULL)); + ASSERT_EQ(0, butil::thread_key_create(key, nullptr)); - ASSERT_EQ(NULL, butil::thread_getspecific(key)); + ASSERT_EQ(nullptr, butil::thread_getspecific(key)); ASSERT_EQ(0, butil::thread_setspecific(key, (void *)raw_data)); ASSERT_EQ(raw_data, butil::thread_getspecific(key)); ASSERT_EQ(0, butil::thread_key_delete(key)); - ASSERT_EQ(NULL, butil::thread_getspecific(key)); + ASSERT_EQ(nullptr, butil::thread_getspecific(key)); ASSERT_NE(0, butil::thread_setspecific(key, (void *)raw_data)); } } @@ -92,7 +92,7 @@ TEST(ThreadLocalTest, thread_key_seq) { if (keys.empty() || create) { for (uint64_t j = 0; j < num; ++j) { keys.emplace_back(); - ASSERT_EQ(0, butil::thread_key_create(keys.back(), NULL)); + ASSERT_EQ(0, butil::thread_key_create(keys.back(), nullptr)); ASSERT_TRUE(!KEY_UNUSED(keys.back()._seq)); if (keys.back()._id >= seqs.size()) { seqs.resize(keys.back()._id + 1); @@ -115,11 +115,11 @@ TEST(ThreadLocalTest, thread_key_seq) { void* THreadKeyCreateAndDeleteFunc(void*) { while (!g_stopped) { ThreadKey key; - EXPECT_EQ(0, butil::thread_key_create(key, NULL)); + EXPECT_EQ(0, butil::thread_key_create(key, nullptr)); EXPECT_TRUE(!KEY_UNUSED(key._seq)); EXPECT_EQ(0, butil::thread_key_delete(key)); } - return NULL; + return nullptr; } TEST(ThreadLocalTest, thread_key_create_and_delete) { @@ -128,12 +128,12 @@ TEST(ThreadLocalTest, thread_key_create_and_delete) { const int thread_num = 8; pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, THreadKeyCreateAndDeleteFunc, NULL)); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, THreadKeyCreateAndDeleteFunc, nullptr)); } sleep(2); g_stopped = true; for (const auto& thread : threads) { - pthread_join(thread, NULL); + pthread_join(thread, nullptr); } } @@ -141,39 +141,39 @@ void* ThreadLocalFunc(void* arg) { auto thread_locals = (std::vector*>*)arg; std::vector expects(thread_locals->size(), 0); for (auto tl : *thread_locals) { - EXPECT_TRUE(tl->get() != NULL); + EXPECT_TRUE(tl->get() != nullptr); *(tl->get()) = 0; } while (!g_stopped) { uint64_t index = fast_rand_less_than(thread_locals->size()); - EXPECT_TRUE((*thread_locals)[index]->get() != NULL); + EXPECT_TRUE((*thread_locals)[index]->get() != nullptr); EXPECT_EQ(*((*thread_locals)[index]->get()), expects[index]); ++(*((*thread_locals)[index]->get())); ++expects[index]; bthread_usleep(10); } - return NULL; + return nullptr; } TEST(ThreadLocalTest, thread_local_multi_thread) { g_stopped = false; int thread_local_num = 20480; - std::vector*> args(thread_local_num, NULL); + std::vector*> args(thread_local_num, nullptr); for (int i = 0; i < thread_local_num; ++i) { args[i] = new ThreadLocal(); - ASSERT_TRUE(args[i]->get() != NULL); + ASSERT_TRUE(args[i]->get() != nullptr); } const int thread_num = 8; pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { - ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadLocalFunc, &args)); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, ThreadLocalFunc, &args)); } sleep(2); g_stopped = true; for (const auto& thread : threads) { - pthread_join(thread, NULL); + pthread_join(thread, nullptr); } for (auto tl : args) { delete tl; @@ -196,7 +196,7 @@ void* ThreadLocalForEachFunc(void* arg) { counter->reset(local_counter); } } - return NULL; + return nullptr; } TEST(ThreadLocalTest, thread_local_for_each) { @@ -206,13 +206,13 @@ TEST(ThreadLocalTest, thread_local_for_each) { pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { ASSERT_EQ(0, pthread_create( - &threads[i], NULL, ThreadLocalForEachFunc, &counter)); + &threads[i], nullptr, ThreadLocalForEachFunc, &counter)); } sleep(2); g_stopped = true; for (const auto& thread : threads) { - pthread_join(thread, NULL); + pthread_join(thread, nullptr); } int count = 0; counter.for_each([&count](butil::atomic* c) { @@ -234,7 +234,7 @@ void* ThreadKeyFunc(void* arg) { std::vector> owned_data; owned_data.reserve(thread_keys.size()); for (auto key : thread_keys) { - EXPECT_TRUE(butil::thread_getspecific(*key) == NULL); + EXPECT_TRUE(butil::thread_getspecific(*key) == nullptr); owned_data.emplace_back(new int(0)); EXPECT_EQ(0, butil::thread_setspecific(*key, owned_data.back().get())); EXPECT_EQ(*(static_cast(butil::thread_getspecific(*key))), 0); @@ -243,7 +243,7 @@ void* ThreadKeyFunc(void* arg) { uint64_t index = fast_rand_less_than(thread_keys.size()); auto data = static_cast(butil::thread_getspecific(*thread_keys[index])); - EXPECT_TRUE(data != NULL); + EXPECT_TRUE(data != nullptr); EXPECT_EQ(*data, expects[index]); ++(*data); ++expects[index]; @@ -256,10 +256,10 @@ void* ThreadKeyFunc(void* arg) { } for (auto key : thread_keys) { - EXPECT_TRUE(butil::thread_getspecific(*key) == NULL) + EXPECT_TRUE(butil::thread_getspecific(*key) == nullptr) << butil::thread_getspecific(*key); } - return NULL; + return nullptr; } TEST(ThreadLocalTest, thread_key_multi_thread) { @@ -274,7 +274,7 @@ TEST(ThreadLocalTest, thread_key_multi_thread) { ASSERT_EQ(0, butil::thread_key_create(*thread_keys.back(), [](void* data) { delete static_cast(data); })); - ASSERT_TRUE(butil::thread_getspecific(*thread_keys.back()) == NULL); + ASSERT_TRUE(butil::thread_getspecific(*thread_keys.back()) == nullptr); owned_data.emplace_back(new int(0)); ASSERT_EQ(0, butil::thread_setspecific(*thread_keys.back(), owned_data.back().get())); ASSERT_EQ(*(static_cast(butil::thread_getspecific(*thread_keys.back()))), 0); @@ -284,7 +284,7 @@ TEST(ThreadLocalTest, thread_key_multi_thread) { pthread_t threads[thread_num]; for (int i = 0; i < thread_num; ++i) { args[i].thread_keys = thread_keys; - ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadKeyFunc, &args[i])); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, ThreadKeyFunc, &args[i])); } sleep(5); @@ -304,12 +304,12 @@ TEST(ThreadLocalTest, thread_key_multi_thread) { } for (auto key : thread_keys) { ASSERT_EQ(0, butil::thread_key_delete(*key)); - ASSERT_TRUE(butil::thread_getspecific(*key) == NULL); + ASSERT_TRUE(butil::thread_getspecific(*key) == nullptr); } g_deleted = true; for (const auto& thread : threads) { - ASSERT_EQ(0, pthread_join(thread, NULL)); + ASSERT_EQ(0, pthread_join(thread, nullptr)); } for (auto key : thread_keys) { delete key; @@ -325,7 +325,7 @@ struct BAIDU_CACHELINE_ALIGNMENT ThreadKeyPerfArgs { bool ready; ThreadKeyPerfArgs() - : thread_key(NULL) + : thread_key(nullptr) , is_pthread_key(true) , counter(0) , elapse_ns(0) @@ -359,7 +359,7 @@ void* ThreadKeyPerfFunc(void* void_arg) { } t.stop(); args->elapse_ns = t.n_elapsed(); - return NULL; + return nullptr; } @@ -369,9 +369,9 @@ void ThreadKeyPerfTest(int thread_num, bool test_pthread_key) { pthread_key_t pthread_key; butil::ThreadKey thread_key; if (test_pthread_key) { - ASSERT_EQ(0, pthread_key_create(&pthread_key, NULL)); + ASSERT_EQ(0, pthread_key_create(&pthread_key, nullptr)); } else { - ASSERT_EQ(0, butil::thread_key_create(thread_key, NULL)); + ASSERT_EQ(0, butil::thread_key_create(thread_key, nullptr)); } pthread_t threads[thread_num]; std::vector args(thread_num); @@ -383,7 +383,7 @@ void ThreadKeyPerfTest(int thread_num, bool test_pthread_key) { args[i].thread_key = &thread_key; args[i].is_pthread_key = false; } - ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadKeyPerfFunc, &args[i])); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, ThreadKeyPerfFunc, &args[i])); } while (true) { bool all_ready = true; @@ -405,7 +405,7 @@ void ThreadKeyPerfTest(int thread_num, bool test_pthread_key) { int64_t wait_time = 0; int64_t count = 0; for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); wait_time += args[i].elapse_ns; count += args[i].counter; } @@ -427,14 +427,14 @@ struct BAIDU_CACHELINE_ALIGNMENT ThreadLocalPerfArgs { bool ready; ThreadLocalPerfArgs() - : tl(NULL) , counter(0) + : tl(nullptr) , counter(0) , elapse_ns(0) , ready(false) {} }; void* ThreadLocalPerfFunc(void* void_arg) { auto args = (ThreadLocalPerfArgs*)void_arg; args->ready = true; - EXPECT_TRUE(args->tl->get() != NULL); + EXPECT_TRUE(args->tl->get() != nullptr); butil::Timer t; while (!g_stopped) { if (g_started) { @@ -449,7 +449,7 @@ void* ThreadLocalPerfFunc(void* void_arg) { } t.stop(); args->elapse_ns = t.n_elapsed(); - return NULL; + return nullptr; } void ThreadLocalPerfTest(int thread_num) { @@ -460,7 +460,7 @@ void ThreadLocalPerfTest(int thread_num) { std::vector args(thread_num); for (int i = 0; i < thread_num; ++i) { args[i].tl = &tl; - ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadLocalPerfFunc, &args[i])); + ASSERT_EQ(0, pthread_create(&threads[i], nullptr, ThreadLocalPerfFunc, &args[i])); } while (true) { bool all_ready = true; @@ -482,7 +482,7 @@ void ThreadLocalPerfTest(int thread_num) { int64_t wait_time = 0; int64_t count = 0; for (int i = 0; i < thread_num; ++i) { - pthread_join(threads[i], NULL); + pthread_join(threads[i], nullptr); wait_time += args[i].elapse_ns; count += args[i].counter; } diff --git a/test/thread_local_storage_unittest.cc b/test/thread_local_storage_unittest.cc index a9a53480aa..3bc0a2a61e 100644 --- a/test/thread_local_storage_unittest.cc +++ b/test/thread_local_storage_unittest.cc @@ -59,8 +59,8 @@ class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate { void ThreadLocalStorageCleanup(void *value) { int *ptr = reinterpret_cast(value); - // Destructors should never be called with a NULL. - ASSERT_NE(reinterpret_cast(NULL), ptr); + // Destructors should never be called with a nullptr. + ASSERT_NE(static_cast(nullptr), ptr); if (*ptr == kFinalTlsValue) return; // We've been called enough times. ASSERT_LT(kFinalTlsValue, *ptr); diff --git a/test/thread_local_unittest.cc b/test/thread_local_unittest.cc index 92a0280095..7371938daa 100644 --- a/test/thread_local_unittest.cc +++ b/test/thread_local_unittest.cc @@ -31,7 +31,7 @@ class SetThreadLocal : public ThreadLocalTesterBase { public: SetThreadLocal(TLPType* tlp, butil::WaitableEvent* done) : ThreadLocalTesterBase(tlp, done), - val_(NULL) { + val_(nullptr) { } virtual ~SetThreadLocal() {} @@ -51,7 +51,7 @@ class GetThreadLocal : public ThreadLocalTesterBase { public: GetThreadLocal(TLPType* tlp, butil::WaitableEvent* done) : ThreadLocalTesterBase(tlp, done), - ptr_(NULL) { + ptr_(nullptr) { } virtual ~GetThreadLocal() {} @@ -70,7 +70,7 @@ class GetThreadLocal : public ThreadLocalTesterBase { } // namespace // In this test, we start 2 threads which will access a ThreadLocalPointer. We -// make sure the default is NULL, and the pointers are unique to the threads. +// make sure the default is nullptr, and the pointers are unique to the threads. TEST(ThreadLocalTest, Pointer) { butil::DelegateSimpleThreadPool tp1("ThreadLocalTest tp1", 1); butil::DelegateSimpleThreadPool tp2("ThreadLocalTest tp1", 1); @@ -88,18 +88,18 @@ TEST(ThreadLocalTest, Pointer) { GetThreadLocal getter(&tlp, &done); getter.set_ptr(&tls_val); - // Check that both threads defaulted to NULL. + // Check that both threads defaulted to nullptr. tls_val = kBogusPointer; done.Reset(); tp1.AddWork(&getter); done.Wait(); - EXPECT_EQ(static_cast(NULL), tls_val); + EXPECT_EQ(static_cast(nullptr), tls_val); tls_val = kBogusPointer; done.Reset(); tp2.AddWork(&getter); done.Wait(); - EXPECT_EQ(static_cast(NULL), tls_val); + EXPECT_EQ(static_cast(nullptr), tls_val); SetThreadLocal setter(&tlp, &done); @@ -110,18 +110,18 @@ TEST(ThreadLocalTest, Pointer) { tp1.AddWork(&setter); done.Wait(); - tls_val = NULL; + tls_val = nullptr; done.Reset(); tp1.AddWork(&getter); done.Wait(); EXPECT_EQ(kBogusPointer, tls_val); - // Make sure thread 2 is still NULL + // Make sure thread 2 is still nullptr tls_val = kBogusPointer; done.Reset(); tp2.AddWork(&getter); done.Wait(); - EXPECT_EQ(static_cast(NULL), tls_val); + EXPECT_EQ(static_cast(nullptr), tls_val); // Set thread 2 to kBogusPointer + 1. setter.set_value(kBogusPointer + 1); @@ -130,14 +130,14 @@ TEST(ThreadLocalTest, Pointer) { tp2.AddWork(&setter); done.Wait(); - tls_val = NULL; + tls_val = nullptr; done.Reset(); tp2.AddWork(&getter); done.Wait(); EXPECT_EQ(kBogusPointer + 1, tls_val); // Make sure thread 1 is still kBogusPointer. - tls_val = NULL; + tls_val = nullptr; done.Reset(); tp1.AddWork(&getter); done.Wait(); diff --git a/test/time_unittest.cc b/test/time_unittest.cc index 2622e20b7c..0280df6db6 100644 --- a/test/time_unittest.cc +++ b/test/time_unittest.cc @@ -38,7 +38,7 @@ class TimeTest : public testing::Test { 0, // day of year (ignored, output only) -1, // DST in effect, -1 tells mktime to figure it out 0, - NULL + nullptr }; time_t converted_time = mktime(&local_comparison_tm); @@ -56,7 +56,7 @@ class TimeTest : public testing::Test { // Test conversions to/from time_t and exploding/unexploding. TEST_F(TimeTest, TimeT) { // C library time and exploded time. - time_t now_t_1 = time(NULL); + time_t now_t_1 = time(nullptr); struct tm tms; #if defined(OS_WIN) localtime_s(&tms, &now_t_1); diff --git a/test/weak_ptr_unittest.cc b/test/weak_ptr_unittest.cc index a4be37f01b..f621819526 100644 --- a/test/weak_ptr_unittest.cc +++ b/test/weak_ptr_unittest.cc @@ -51,13 +51,13 @@ TEST(WeakPtrFactoryTest, Comparison) { TEST(WeakPtrFactoryTest, OutOfScope) { WeakPtr ptr; - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); { int data; WeakPtrFactory factory(&data); ptr = factory.GetWeakPtr(); } - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); } TEST(WeakPtrFactoryTest, Multiple) { @@ -70,8 +70,8 @@ TEST(WeakPtrFactoryTest, Multiple) { EXPECT_EQ(&data, a.get()); EXPECT_EQ(&data, b.get()); } - EXPECT_EQ(NULL, a.get()); - EXPECT_EQ(NULL, b.get()); + EXPECT_EQ(nullptr, a.get()); + EXPECT_EQ(nullptr, b.get()); } TEST(WeakPtrFactoryTest, MultipleStaged) { @@ -83,9 +83,9 @@ TEST(WeakPtrFactoryTest, MultipleStaged) { { WeakPtr b = factory.GetWeakPtr(); } - EXPECT_TRUE(NULL != a.get()); + EXPECT_TRUE(nullptr != a.get()); } - EXPECT_EQ(NULL, a.get()); + EXPECT_EQ(nullptr, a.get()); } TEST(WeakPtrFactoryTest, Dereference) { @@ -125,7 +125,7 @@ TEST(WeakPtrTest, InvalidateWeakPtrs) { EXPECT_EQ(&data, ptr.get()); EXPECT_TRUE(factory.HasWeakPtrs()); factory.InvalidateWeakPtrs(); - EXPECT_EQ(NULL, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); EXPECT_FALSE(factory.HasWeakPtrs()); // Test that the factory can create new weak pointers after a @@ -135,7 +135,7 @@ TEST(WeakPtrTest, InvalidateWeakPtrs) { EXPECT_EQ(&data, ptr2.get()); EXPECT_TRUE(factory.HasWeakPtrs()); factory.InvalidateWeakPtrs(); - EXPECT_EQ(NULL, ptr2.get()); + EXPECT_EQ(nullptr, ptr2.get()); EXPECT_FALSE(factory.HasWeakPtrs()); }