From 2ad8d21158df8b9a7e37b0a966f76b52a61f25e6 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 7 Mar 2015 08:39:22 -0800 Subject: strcmp: change all !str[n]cmp to str[n]cmp == 0 Change all !str[n]cmp to be str[n]cmp == 0 consistently across the codebase. Issue #231 Signed-off-by: Ronnie Sahlberg --- test/core/network_benchmarks/low_level_ping_pong.c | 2 +- test/core/security/base64_test.c | 18 ++-- test/core/security/credentials_test.c | 99 +++++++++++----------- test/core/security/json_token_test.c | 38 ++++----- test/core/support/env_test.c | 2 +- 5 files changed, 81 insertions(+), 78 deletions(-) (limited to 'test/core') diff --git a/test/core/network_benchmarks/low_level_ping_pong.c b/test/core/network_benchmarks/low_level_ping_pong.c index a084c55a35..7d74d0e078 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.c +++ b/test/core/network_benchmarks/low_level_ping_pong.c @@ -654,7 +654,7 @@ int main(int argc, char **argv) { } for (i = 0; i < GPR_ARRAY_SIZE(test_strategies); ++i) { - if (!strcmp(test_strategies[i].name, read_strategy)) { + if (strcmp(test_strategies[i].name, read_strategy) == 0) { test_strategy = &test_strategies[i]; } } diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c index bfd5c48777..a922896bc3 100644 --- a/test/core/security/base64_test.c +++ b/test/core/security/base64_test.c @@ -58,8 +58,8 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) { grpc_base64_encode(hello, strlen(hello), url_safe, multiline); gpr_slice hello_slice = grpc_base64_decode(hello_b64, url_safe); GPR_ASSERT(GPR_SLICE_LENGTH(hello_slice) == strlen(hello)); - GPR_ASSERT(!strncmp((const char *)GPR_SLICE_START_PTR(hello_slice), hello, - GPR_SLICE_LENGTH(hello_slice))); + GPR_ASSERT(strncmp((const char *)GPR_SLICE_START_PTR(hello_slice), hello, + GPR_SLICE_LENGTH(hello_slice)) == 0); gpr_slice_unref(hello_slice); gpr_free(hello_b64); @@ -141,31 +141,31 @@ static void test_rfc4648_test_vectors(void) { char *b64; b64 = grpc_base64_encode("", 0, 0, 0); - GPR_ASSERT(!strcmp("", b64)); + GPR_ASSERT(strcmp("", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("f", 1, 0, 0); - GPR_ASSERT(!strcmp("Zg==", b64)); + GPR_ASSERT(strcmp("Zg==", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("fo", 2, 0, 0); - GPR_ASSERT(!strcmp("Zm8=", b64)); + GPR_ASSERT(strcmp("Zm8=", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("foo", 3, 0, 0); - GPR_ASSERT(!strcmp("Zm9v", b64)); + GPR_ASSERT(strcmp("Zm9v", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("foob", 4, 0, 0); - GPR_ASSERT(!strcmp("Zm9vYg==", b64)); + GPR_ASSERT(strcmp("Zm9vYg==", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("fooba", 5, 0, 0); - GPR_ASSERT(!strcmp("Zm9vYmE=", b64)); + GPR_ASSERT(strcmp("Zm9vYmE=", b64) == 0); gpr_free(b64); b64 = grpc_base64_encode("foobar", 6, 0, 0); - GPR_ASSERT(!strcmp("Zm9vYmFy", b64)); + GPR_ASSERT(strcmp("Zm9vYmFy", b64) == 0); gpr_free(b64); } diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index 50ef2d7657..078462410a 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -143,9 +143,10 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) { GRPC_CREDENTIALS_OK); GPR_ASSERT(token_lifetime.tv_sec == 3599); GPR_ASSERT(token_lifetime.tv_nsec == 0); - GPR_ASSERT(!strcmp(grpc_mdstr_as_c_string(token_elem->key), "Authorization")); - GPR_ASSERT(!strcmp(grpc_mdstr_as_c_string(token_elem->value), - "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_")); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(token_elem->key), + "Authorization") == 0); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(token_elem->value), + "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); grpc_mdelem_unref(token_elem); grpc_mdctx_unref(ctx); } @@ -294,15 +295,16 @@ static void test_ssl_oauth2_composite_creds(void) { grpc_composite_credentials_create(ssl_creds, oauth2_creds); grpc_credentials_unref(ssl_creds); grpc_credentials_unref(oauth2_creds); - GPR_ASSERT(!strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE)); + GPR_ASSERT(strcmp(composite_creds->type, + GRPC_CREDENTIALS_TYPE_COMPOSITE) == 0); GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds)); GPR_ASSERT(!grpc_credentials_has_request_metadata_only(composite_creds)); creds_array = grpc_composite_credentials_get_credentials(composite_creds); GPR_ASSERT(creds_array->num_creds == 2); - GPR_ASSERT( - !strcmp(creds_array->creds_array[0]->type, GRPC_CREDENTIALS_TYPE_SSL)); - GPR_ASSERT( - !strcmp(creds_array->creds_array[1]->type, GRPC_CREDENTIALS_TYPE_OAUTH2)); + GPR_ASSERT(strcmp(creds_array->creds_array[0]->type, + GRPC_CREDENTIALS_TYPE_SSL) == 0); + GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, + GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); grpc_credentials_get_request_metadata(composite_creds, test_service_url, check_ssl_oauth2_composite_metadata, composite_creds); @@ -338,17 +340,18 @@ static void test_ssl_oauth2_iam_composite_creds(void) { grpc_credentials_unref(oauth2_creds); grpc_credentials_unref(aux_creds); grpc_credentials_unref(iam_creds); - GPR_ASSERT(!strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE)); + GPR_ASSERT(strcmp(composite_creds->type, + GRPC_CREDENTIALS_TYPE_COMPOSITE) == 0); GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds)); GPR_ASSERT(!grpc_credentials_has_request_metadata_only(composite_creds)); creds_array = grpc_composite_credentials_get_credentials(composite_creds); GPR_ASSERT(creds_array->num_creds == 3); - GPR_ASSERT( - !strcmp(creds_array->creds_array[0]->type, GRPC_CREDENTIALS_TYPE_SSL)); - GPR_ASSERT( - !strcmp(creds_array->creds_array[1]->type, GRPC_CREDENTIALS_TYPE_OAUTH2)); - GPR_ASSERT( - !strcmp(creds_array->creds_array[2]->type, GRPC_CREDENTIALS_TYPE_IAM)); + GPR_ASSERT(strcmp(creds_array->creds_array[0]->type, + GRPC_CREDENTIALS_TYPE_SSL) == 0); + GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, + GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); + GPR_ASSERT(strcmp(creds_array->creds_array[2]->type, + GRPC_CREDENTIALS_TYPE_IAM) == 0); grpc_credentials_get_request_metadata(composite_creds, test_service_url, check_ssl_oauth2_iam_composite_metadata, composite_creds); @@ -359,12 +362,12 @@ static void on_oauth2_creds_get_metadata_success( grpc_credentials_status status) { GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); - GPR_ASSERT( - !strcmp(grpc_mdstr_as_c_string(md_elems[0]->key), "Authorization")); - GPR_ASSERT(!strcmp(grpc_mdstr_as_c_string(md_elems[0]->value), - "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_")); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(md_elems[0]->key), + "Authorization") == 0); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(md_elems[0]->value), + "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); GPR_ASSERT(user_data != NULL); - GPR_ASSERT(!strcmp((const char *)user_data, test_user_data)); + GPR_ASSERT(strcmp((const char *)user_data, test_user_data) == 0); } static void on_oauth2_creds_get_metadata_failure( @@ -373,19 +376,19 @@ static void on_oauth2_creds_get_metadata_failure( GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); GPR_ASSERT(num_md == 0); GPR_ASSERT(user_data != NULL); - GPR_ASSERT(!strcmp((const char *)user_data, test_user_data)); + GPR_ASSERT(strcmp((const char *)user_data, test_user_data) == 0); } static void validate_compute_engine_http_request( const grpc_httpcli_request *request) { GPR_ASSERT(!request->use_ssl); - GPR_ASSERT(!strcmp(request->host, "metadata")); - GPR_ASSERT( - !strcmp(request->path, - "/computeMetadata/v1/instance/service-accounts/default/token")); + GPR_ASSERT(strcmp(request->host, "metadata") == 0); + GPR_ASSERT(strcmp(request->path, + "/computeMetadata/v1/instance/service-accounts/default/token") + == 0); GPR_ASSERT(request->hdr_count == 1); - GPR_ASSERT(!strcmp(request->hdrs[0].key, "Metadata-Flavor")); - GPR_ASSERT(!strcmp(request->hdrs[0].value, "Google")); + GPR_ASSERT(strcmp(request->hdrs[0].key, "Metadata-Flavor") == 0); + GPR_ASSERT(strcmp(request->hdrs[0].value, "Google") == 0); } static int compute_engine_httpcli_get_success_override( @@ -467,19 +470,19 @@ static void validate_jwt_encode_and_sign_params( GPR_ASSERT(json_key->private_key != NULL); GPR_ASSERT(RSA_check_key(json_key->private_key)); GPR_ASSERT(json_key->type != NULL && - !(strcmp(json_key->type, "service_account"))); + strcmp(json_key->type, "service_account") == 0); GPR_ASSERT(json_key->private_key_id != NULL && - !strcmp(json_key->private_key_id, - "e6b5137873db8d2ef81e06a47289e6434ec8a165")); + strcmp(json_key->private_key_id, + "e6b5137873db8d2ef81e06a47289e6434ec8a165") == 0); GPR_ASSERT(json_key->client_id != NULL && - !strcmp(json_key->client_id, - "777-abaslkan11hlb6nmim3bpspl31ud.apps." - "googleusercontent.com")); + strcmp(json_key->client_id, + "777-abaslkan11hlb6nmim3bpspl31ud.apps." + "googleusercontent.com") == 0); GPR_ASSERT(json_key->client_email != NULL && - !strcmp(json_key->client_email, - "777-abaslkan11hlb6nmim3bpspl31ud@developer." - "gserviceaccount.com")); - if (scope != NULL) GPR_ASSERT(!strcmp(scope, test_scope)); + strcmp(json_key->client_email, + "777-abaslkan11hlb6nmim3bpspl31ud@developer." + "gserviceaccount.com") == 0); + if (scope != NULL) GPR_ASSERT(strcmp(scope, test_scope) == 0); GPR_ASSERT(!gpr_time_cmp(token_lifetime, grpc_max_auth_token_lifetime)); } @@ -517,12 +520,12 @@ static void validate_service_account_http_request( GPR_ASSERT(!memcmp(expected_body, body, body_size)); gpr_free(expected_body); GPR_ASSERT(request->use_ssl); - GPR_ASSERT(!strcmp(request->host, "www.googleapis.com")); - GPR_ASSERT(!strcmp(request->path, "/oauth2/v3/token")); + GPR_ASSERT(strcmp(request->host, "www.googleapis.com") == 0); + GPR_ASSERT(strcmp(request->path, "/oauth2/v3/token") == 0); GPR_ASSERT(request->hdr_count == 1); - GPR_ASSERT(!strcmp(request->hdrs[0].key, "Content-Type")); - GPR_ASSERT( - !strcmp(request->hdrs[0].value, "application/x-www-form-urlencoded")); + GPR_ASSERT(strcmp(request->hdrs[0].key, "Content-Type") == 0); + GPR_ASSERT(strcmp(request->hdrs[0].value, + "application/x-www-form-urlencoded") == 0); } static int service_account_httpcli_post_success( @@ -626,12 +629,12 @@ static void on_jwt_creds_get_metadata_success(void *user_data, gpr_asprintf(&expected_md_value, "Bearer %s", test_signed_jwt); GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); - GPR_ASSERT( - !strcmp(grpc_mdstr_as_c_string(md_elems[0]->key), "Authorization")); - GPR_ASSERT( - !strcmp(grpc_mdstr_as_c_string(md_elems[0]->value), expected_md_value)); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(md_elems[0]->key), + "Authorization") == 0); + GPR_ASSERT(strcmp(grpc_mdstr_as_c_string(md_elems[0]->value), + expected_md_value) == 0); GPR_ASSERT(user_data != NULL); - GPR_ASSERT(!strcmp((const char *)user_data, test_user_data)); + GPR_ASSERT(strcmp((const char *)user_data, test_user_data) == 0); gpr_free(expected_md_value); } @@ -642,7 +645,7 @@ static void on_jwt_creds_get_metadata_failure(void *user_data, GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); GPR_ASSERT(num_md == 0); GPR_ASSERT(user_data != NULL); - GPR_ASSERT(!strcmp((const char *)user_data, test_user_data)); + GPR_ASSERT(strcmp((const char *)user_data, test_user_data) == 0); } static void test_jwt_creds_success(void) { diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c index fae911721a..ca5b889102 100644 --- a/test/core/security/json_token_test.c +++ b/test/core/security/json_token_test.c @@ -102,18 +102,18 @@ static void test_parse_json_key_success(void) { grpc_auth_json_key_create_from_string(json_string); GPR_ASSERT(grpc_auth_json_key_is_valid(&json_key)); GPR_ASSERT(json_key.type != NULL && - !(strcmp(json_key.type, "service_account"))); + strcmp(json_key.type, "service_account") == 0); GPR_ASSERT(json_key.private_key_id != NULL && - !strcmp(json_key.private_key_id, - "e6b5137873db8d2ef81e06a47289e6434ec8a165")); + strcmp(json_key.private_key_id, + "e6b5137873db8d2ef81e06a47289e6434ec8a165") == 0); GPR_ASSERT(json_key.client_id != NULL && - !strcmp(json_key.client_id, - "777-abaslkan11hlb6nmim3bpspl31ud.apps." - "googleusercontent.com")); + strcmp(json_key.client_id, + "777-abaslkan11hlb6nmim3bpspl31ud.apps." + "googleusercontent.com") == 0); GPR_ASSERT(json_key.client_email != NULL && - !strcmp(json_key.client_email, - "777-abaslkan11hlb6nmim3bpspl31ud@developer." - "gserviceaccount.com")); + strcmp(json_key.client_email, + "777-abaslkan11hlb6nmim3bpspl31ud@developer." + "gserviceaccount.com") == 0); GPR_ASSERT(json_key.private_key != NULL); gpr_free(json_string); grpc_auth_json_key_destruct(&json_key); @@ -248,15 +248,16 @@ static void check_jwt_header(grpc_json *header) { } GPR_ASSERT(alg != NULL); GPR_ASSERT(alg->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(alg->value, "RS256")); + GPR_ASSERT(strcmp(alg->value, "RS256") == 0); GPR_ASSERT(typ != NULL); GPR_ASSERT(typ->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(typ->value, "JWT")); + GPR_ASSERT(strcmp(typ->value, "JWT") == 0); GPR_ASSERT(kid != NULL); GPR_ASSERT(kid->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(kid->value, "e6b5137873db8d2ef81e06a47289e6434ec8a165")); + GPR_ASSERT(strcmp(kid->value, + "e6b5137873db8d2ef81e06a47289e6434ec8a165") == 0); } static void check_jwt_claim(grpc_json *claim, const char *expected_audience, @@ -290,27 +291,26 @@ static void check_jwt_claim(grpc_json *claim, const char *expected_audience, GPR_ASSERT(iss != NULL); GPR_ASSERT(iss->type == GRPC_JSON_STRING); - GPR_ASSERT( - !strcmp( - iss->value, - "777-abaslkan11hlb6nmim3bpspl31ud@developer.gserviceaccount.com")); + GPR_ASSERT(strcmp(iss->value, + "777-abaslkan11hlb6nmim3bpspl31ud@developer.gserviceaccount.com") + ==0); if (expected_scope != NULL) { GPR_ASSERT(scope != NULL); GPR_ASSERT(sub == NULL); GPR_ASSERT(scope->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(scope->value, expected_scope)); + GPR_ASSERT(strcmp(scope->value, expected_scope) == 0); } else { /* Claims without scope must have a sub. */ GPR_ASSERT(scope == NULL); GPR_ASSERT(sub != NULL); GPR_ASSERT(sub->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(iss->value, sub->value)); + GPR_ASSERT(strcmp(iss->value, sub->value) == 0); } GPR_ASSERT(aud != NULL); GPR_ASSERT(aud->type == GRPC_JSON_STRING); - GPR_ASSERT(!strcmp(aud->value, expected_audience)); + GPR_ASSERT(strcmp(aud->value, expected_audience) == 0); GPR_ASSERT(exp != NULL); GPR_ASSERT(exp->type == GRPC_JSON_NUMBER); diff --git a/test/core/support/env_test.c b/test/core/support/env_test.c index 1f16af87a5..aedf9313f3 100644 --- a/test/core/support/env_test.c +++ b/test/core/support/env_test.c @@ -53,7 +53,7 @@ static void test_setenv_getenv(void) { gpr_setenv(name, value); retrieved_value = gpr_getenv(name); GPR_ASSERT(retrieved_value != NULL); - GPR_ASSERT(!strcmp(value, retrieved_value)); + GPR_ASSERT(strcmp(value, retrieved_value) == 0); gpr_free(retrieved_value); } -- cgit v1.2.3