diff --git a/src/core/handshaker/http_connect/http_connect_handshaker.cc b/src/core/handshaker/http_connect/http_connect_handshaker.cc index 1b1a1198cfb..0868190ef65 100644 --- a/src/core/handshaker/http_connect/http_connect_handshaker.cc +++ b/src/core/handshaker/http_connect/http_connect_handshaker.cc @@ -189,7 +189,7 @@ bool HttpConnectHandshaker::OnReadDoneLocked(absl::Status error) { // Add buffer to parser. while (args_->read_buffer.Count() > 0) { Slice slice = args_->read_buffer.TakeFirst(); - if (slice.length() > 0) { + if (!slice.empty()) { size_t body_start_offset = 0; error = grpc_http_parser_parse(&http_parser_, slice.c_slice(), &body_start_offset); diff --git a/src/core/lib/gprpp/status_helper.cc b/src/core/lib/gprpp/status_helper.cc index 40db6dc0cfc..a2a5160e2f1 100644 --- a/src/core/lib/gprpp/status_helper.cc +++ b/src/core/lib/gprpp/status_helper.cc @@ -342,7 +342,7 @@ google_rpc_Status* StatusToProto(const absl::Status& status, upb_Arena* arena) { PercentEncodingType::Compatible); char* message_percent = reinterpret_cast( upb_Arena_Malloc(arena, message_percent_slice.length())); - if (message_percent_slice.length() > 0) { + if (!message_percent_slice.empty()) { memcpy(message_percent, message_percent_slice.data(), message_percent_slice.length()); } diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 7244144abee..7c8236b3850 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -539,7 +539,7 @@ void MaybeAddToBody(const char* field_name, const char* field, grpc_error_handle LoadTokenFile(const char* path, grpc_slice* token) { auto slice = LoadFile(path, /*add_null_terminator=*/true); if (!slice.ok()) return slice.status(); - if (slice->length() == 0) { + if (slice->empty()) { LOG(ERROR) << "Token file " << path << " is empty"; return GRPC_ERROR_CREATE("Token file is empty."); } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 099b8ca2141..d229e279a61 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -111,7 +111,7 @@ gpr_once g_once_init_callbacks = GPR_ONCE_INIT; void InitGlobalCallbacks() { if (!g_callbacks) { - g_callbacks.reset(new DefaultGlobalCallbacks()); + g_callbacks = std::make_shared(); } } diff --git a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc index 52eff1798ec..54cf3d599e8 100644 --- a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc +++ b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc @@ -185,7 +185,7 @@ int WriteBytes(int sockfd, int& saved_errno, std::string write_bytes) { return ret; } write_bytes = write_bytes.substr(ret, std::string::npos); - } while (write_bytes.length() > 0); + } while (!write_bytes.empty()); return original_write_length; } } // namespace diff --git a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h index dc6de649e71..52e9953c2b1 100644 --- a/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h +++ b/test/core/event_engine/test_suite/posix/oracle_event_engine_posix.h @@ -92,7 +92,7 @@ class PosixOracleEndpoint : public EventEngine::Endpoint { absl::AnyInvocable&& on_complete) : bytes_to_write_(ExtractSliceBufferIntoString(buffer)), on_complete_(std::move(on_complete)) {} - bool IsValid() { return bytes_to_write_.length() > 0; } + bool IsValid() { return !bytes_to_write_.empty(); } std::string GetBytesToWrite() const { return bytes_to_write_; } void operator()(absl::Status status) { if (on_complete_ != nullptr) { diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index f561ec70a20..073b67dcbfe 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -167,7 +167,7 @@ class CallbackTestServiceImpl : public EchoTestService::CallbackService { // adding this variance in Status return value just to improve coverage in // this test. auto* reactor = context->DefaultReactor(); - if (request->message().length() > 0) { + if (!request->message().empty()) { response->set_message(request->message()); reactor->Finish(Status::OK); } else { diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index 0c23abc6c51..079dca44feb 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -290,7 +290,7 @@ ServerUnaryReactor* CallbackTestServiceImpl::Echo( } } if (req_->has_param() && - (req_->param().expected_client_identity().length() > 0 || + (!req_->param().expected_client_identity().empty() || req_->param().check_auth_context())) { internal::CheckServerAuthContext( ctx_, req_->param().expected_transport_security_type(), diff --git a/test/cpp/end2end/test_service_impl.h b/test/cpp/end2end/test_service_impl.h index 05511373302..84cb324e46b 100644 --- a/test/cpp/end2end/test_service_impl.h +++ b/test/cpp/end2end/test_service_impl.h @@ -256,7 +256,7 @@ class TestMultipleServiceImpl : public RpcService { } } if (request->has_param() && - (request->param().expected_client_identity().length() > 0 || + (!request->param().expected_client_identity().empty() || request->param().check_auth_context())) { internal::CheckServerAuthContext( context, request->param().expected_transport_security_type(), diff --git a/test/cpp/ext/otel/otel_test_library.cc b/test/cpp/ext/otel/otel_test_library.cc index e16ff6b9980..7bc0daac261 100644 --- a/test/cpp/ext/otel/otel_test_library.cc +++ b/test/cpp/ext/otel/otel_test_library.cc @@ -19,6 +19,7 @@ #include "test/cpp/ext/otel/otel_test_library.h" #include +#include #include "absl/functional/any_invocable.h" #include "gmock/gmock.h" @@ -289,7 +290,7 @@ OpenTelemetryPluginEnd2EndTest::ConfigureOTBuilder( if (options.use_meter_provider) { auto meter_provider = std::make_shared(); - reader.reset(new grpc::testing::MockMetricReader); + reader = std::make_shared(); meter_provider->AddMetricReader(reader); ot_builder->SetMeterProvider(std::move(meter_provider)); } diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index b43879c9a2c..a87d8b7d2cd 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -253,7 +253,7 @@ int main(int argc, char** argv) { server_addresses); // Parse test cases and weights - if (absl::GetFlag(FLAGS_test_cases).length() == 0) { + if (absl::GetFlag(FLAGS_test_cases).empty()) { LOG(ERROR) << "No test cases supplied"; return 1; } diff --git a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc index b79df3ed4d1..14299ebb5b2 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong_chaotic_good.cc @@ -35,7 +35,7 @@ class ChaoticGoodFixture : public BaseFixture { const FixtureConfiguration& config = FixtureConfiguration()) { auto address = MakeAddress(&port_); ServerBuilder b; - if (address.length() > 0) { + if (!address.empty()) { b.AddListeningPort(address, ChaoticGoodInsecureServerCredentials()); } cq_ = b.AddCompletionQueue(true); @@ -44,7 +44,7 @@ class ChaoticGoodFixture : public BaseFixture { server_ = b.BuildAndStart(); ChannelArguments args; config.ApplyCommonChannelArguments(&args); - if (address.length() > 0) { + if (!address.empty()) { channel_ = grpc::CreateCustomChannel( address, ChaoticGoodInsecureChannelCredentials(), args); } else { diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 664fa70a25a..8ded4de82cc 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -77,7 +77,7 @@ class FullstackFixture : public BaseFixture { FullstackFixture(Service* service, const FixtureConfiguration& config, const std::string& address) { ServerBuilder b; - if (address.length() > 0) { + if (!address.empty()) { b.AddListeningPort(address, InsecureServerCredentials()); } cq_ = b.AddCompletionQueue(true); @@ -86,7 +86,7 @@ class FullstackFixture : public BaseFixture { server_ = b.BuildAndStart(); ChannelArguments args; config.ApplyCommonChannelArguments(&args); - if (address.length() > 0) { + if (!address.empty()) { channel_ = grpc::CreateCustomChannel(address, InsecureChannelCredentials(), args); } else { diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index d330fa9eb03..d7d6c5baf5c 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -468,7 +468,7 @@ std::unique_ptr RunScenario( client_config.add_server_targets(cli_target.c_str()); } } - if (qps_server_target_override.length() > 0) { + if (!qps_server_target_override.empty()) { // overriding the qps server target only makes since if there is <= 1 // servers CHECK_LE(num_servers, 1u); diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 95c8bc3d83b..8f171274bb4 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -653,7 +653,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, fprintf(stderr, "Request sent.\n"); } } else { - if (line.length() == 0) { + if (line.empty()) { request_text = request_ss.str(); request_ss.str(std::string()); request_ss.clear(); @@ -786,7 +786,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } } } else { - if (line.length() == 0) { + if (line.empty()) { request_text = request_ss.str(); request_ss.str(std::string()); request_ss.clear();