diff options
Diffstat (limited to 'test/core/tsi')
-rw-r--r-- | test/core/tsi/BUILD | 14 | ||||
-rw-r--r-- | test/core/tsi/fake_transport_security_test.cc (renamed from test/core/tsi/fake_transport_security_test.c) | 7 | ||||
-rw-r--r-- | test/core/tsi/ssl_transport_security_test.cc (renamed from test/core/tsi/ssl_transport_security_test.c) | 37 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test.cc (renamed from test/core/tsi/transport_security_test.c) | 2 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test_lib.cc (renamed from test/core/tsi/transport_security_test_lib.c) | 33 | ||||
-rw-r--r-- | test/core/tsi/transport_security_test_lib.h | 8 |
6 files changed, 55 insertions, 46 deletions
diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD index 0c5509dda6..e28c0b5f84 100644 --- a/test/core/tsi/BUILD +++ b/test/core/tsi/BUILD @@ -20,7 +20,7 @@ grpc_package(name = "test/core/tsi") grpc_cc_library( name = "transport_security_test_lib", - srcs = ["transport_security_test_lib.c"], + srcs = ["transport_security_test_lib.cc"], hdrs = ["transport_security_test_lib.h"], deps = [ "//:grpc", @@ -30,8 +30,8 @@ grpc_cc_library( grpc_cc_test( name = "fake_transport_security_test", - srcs = ["fake_transport_security_test.c"], - language = "C", + srcs = ["fake_transport_security_test.cc"], + language = "C++", deps = [ ":transport_security_test_lib", "//:grpc", @@ -44,7 +44,7 @@ grpc_cc_test( grpc_cc_test( name = "ssl_transport_security_test", - srcs = ["ssl_transport_security_test.c"], + srcs = ["ssl_transport_security_test.cc"], data = [ "//src/core/tsi/test_creds:badclient.key", "//src/core/tsi/test_creds:badclient.pem", @@ -58,7 +58,7 @@ grpc_cc_test( "//src/core/tsi/test_creds:server1.key", "//src/core/tsi/test_creds:server1.pem", ], - language = "C", + language = "C++", deps = [ ":transport_security_test_lib", "//:grpc", @@ -70,8 +70,8 @@ grpc_cc_test( grpc_cc_test( name = "transport_security_test", - srcs = ["transport_security_test.c"], - language = "C", + srcs = ["transport_security_test.cc"], + language = "C++", deps = [ "//:grpc", "//:gpr", diff --git a/test/core/tsi/fake_transport_security_test.c b/test/core/tsi/fake_transport_security_test.cc index 39b36cd848..32b0f898af 100644 --- a/test/core/tsi/fake_transport_security_test.c +++ b/test/core/tsi/fake_transport_security_test.cc @@ -64,7 +64,8 @@ static const struct tsi_test_fixture_vtable vtable = { fake_test_destruct}; static tsi_test_fixture* fake_tsi_test_fixture_create() { - fake_tsi_test_fixture* fake_fixture = gpr_zalloc(sizeof(*fake_fixture)); + fake_tsi_test_fixture* fake_fixture = + static_cast<fake_tsi_test_fixture*>(gpr_zalloc(sizeof(*fake_fixture))); tsi_test_fixture_init(&fake_fixture->base); fake_fixture->base.vtable = &vtable; return &fake_fixture->base; @@ -91,8 +92,8 @@ void fake_tsi_test_do_handshake() { } void fake_tsi_test_do_round_trip_for_all_configs() { - unsigned int* bit_array = - gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS); + unsigned int* bit_array = static_cast<unsigned int*>( + gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); for (unsigned int val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) { unsigned int v = val; diff --git a/test/core/tsi/ssl_transport_security_test.c b/test/core/tsi/ssl_transport_security_test.cc index ad133bcd6c..0903ce8625 100644 --- a/test/core/tsi/ssl_transport_security_test.c +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -324,8 +324,8 @@ static const struct tsi_test_fixture_vtable vtable = { ssl_test_destruct}; static char* load_file(const char* dir_path, const char* file_name) { - char* file_path = - gpr_zalloc(sizeof(char) * (strlen(dir_path) + strlen(file_name) + 1)); + char* file_path = static_cast<char*>( + gpr_zalloc(sizeof(char) * (strlen(dir_path) + strlen(file_name) + 1))); memcpy(file_path, dir_path, strlen(dir_path)); memcpy(file_path + strlen(dir_path), file_name, strlen(file_name)); grpc_slice slice; @@ -337,12 +337,14 @@ static char* load_file(const char* dir_path, const char* file_name) { } static tsi_test_fixture* ssl_tsi_test_fixture_create() { - ssl_tsi_test_fixture* ssl_fixture = gpr_zalloc(sizeof(*ssl_fixture)); + ssl_tsi_test_fixture* ssl_fixture = + static_cast<ssl_tsi_test_fixture*>(gpr_zalloc(sizeof(*ssl_fixture))); tsi_test_fixture_init(&ssl_fixture->base); ssl_fixture->base.test_unused_bytes = false; ssl_fixture->base.vtable = &vtable; /* Create ssl_key_cert_lib. */ - ssl_key_cert_lib* key_cert_lib = gpr_zalloc(sizeof(*key_cert_lib)); + ssl_key_cert_lib* key_cert_lib = + static_cast<ssl_key_cert_lib*>(gpr_zalloc(sizeof(*key_cert_lib))); key_cert_lib->use_bad_server_cert = false; key_cert_lib->use_bad_client_cert = false; key_cert_lib->server_num_key_cert_pairs = @@ -350,11 +352,13 @@ static tsi_test_fixture* ssl_tsi_test_fixture_create() { key_cert_lib->bad_server_num_key_cert_pairs = SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM; key_cert_lib->server_pem_key_cert_pairs = - gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * - key_cert_lib->server_num_key_cert_pairs); + static_cast<tsi_ssl_pem_key_cert_pair*>( + gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * + key_cert_lib->server_num_key_cert_pairs)); key_cert_lib->bad_server_pem_key_cert_pairs = - gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * - key_cert_lib->bad_server_num_key_cert_pairs); + static_cast<tsi_ssl_pem_key_cert_pair*>( + gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) * + key_cert_lib->bad_server_num_key_cert_pairs)); key_cert_lib->server_pem_key_cert_pairs[0].private_key = load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.key"); key_cert_lib->server_pem_key_cert_pairs[0].cert_chain = @@ -378,11 +382,12 @@ static tsi_test_fixture* ssl_tsi_test_fixture_create() { key_cert_lib->root_cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "ca.pem"); ssl_fixture->key_cert_lib = key_cert_lib; /* Create ssl_alpn_lib. */ - ssl_alpn_lib* alpn_lib = gpr_zalloc(sizeof(*alpn_lib)); + ssl_alpn_lib* alpn_lib = + static_cast<ssl_alpn_lib*>(gpr_zalloc(sizeof(*alpn_lib))); alpn_lib->server_alpn_protocols = - gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM); + static_cast<char**>(gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); alpn_lib->client_alpn_protocols = - gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM); + static_cast<char**>(gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM)); alpn_lib->server_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN1); alpn_lib->server_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3); alpn_lib->client_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN2); @@ -429,7 +434,8 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() { /* server1 cert contains "waterzooi.test.google.be" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; - ssl_fixture->server_name_indication = "waterzooi.test.google.be"; + ssl_fixture->server_name_indication = + const_cast<char*>("waterzooi.test.google.be"); tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); } @@ -438,7 +444,8 @@ void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() { /* server1 cert contains "*.test.google.fr" in SAN. */ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture; - ssl_fixture->server_name_indication = "juju.test.google.fr"; + ssl_fixture->server_name_indication = + const_cast<char*>("juju.test.google.fr"); tsi_test_do_handshake(fixture); tsi_test_fixture_destroy(fixture); } @@ -493,8 +500,8 @@ void ssl_tsi_test_do_handshake_alpn_client_server_ok() { } void ssl_tsi_test_do_round_trip_for_all_configs() { - unsigned int* bit_array = - gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS); + unsigned int* bit_array = static_cast<unsigned int*>( + gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); for (unsigned int val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) { unsigned int v = val; diff --git a/test/core/tsi/transport_security_test.c b/test/core/tsi/transport_security_test.cc index f99afd8101..39adf2fab6 100644 --- a/test/core/tsi/transport_security_test.c +++ b/test/core/tsi/transport_security_test.cc @@ -200,7 +200,7 @@ typedef struct { } parsed_names; name_list* name_list_add(const char* n) { - name_list* result = gpr_malloc(sizeof(name_list)); + name_list* result = static_cast<name_list*>(gpr_malloc(sizeof(name_list))); result->name = n; result->next = NULL; return result; diff --git a/test/core/tsi/transport_security_test_lib.c b/test/core/tsi/transport_security_test_lib.cc index 090f0cf79e..af8316873e 100644 --- a/test/core/tsi/transport_security_test_lib.c +++ b/test/core/tsi/transport_security_test_lib.cc @@ -57,10 +57,12 @@ static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture, bool is_client) { GPR_ASSERT(fixture != NULL); GPR_ASSERT(fixture->config != NULL); - handshaker_args* args = gpr_zalloc(sizeof(*args)); + handshaker_args* args = + static_cast<handshaker_args*>(gpr_zalloc(sizeof(*args))); args->fixture = fixture; args->handshake_buffer_size = fixture->handshake_buffer_size; - args->handshake_buffer = gpr_zalloc(args->handshake_buffer_size); + args->handshake_buffer = + static_cast<unsigned char*>(gpr_zalloc(args->handshake_buffer_size)); args->is_client = is_client; args->error = GRPC_ERROR_NONE; return args; @@ -181,7 +183,8 @@ static void send_message_to_peer(tsi_test_fixture* fixture, GPR_ASSERT(fixture->config != NULL); GPR_ASSERT(protector != NULL); tsi_test_frame_protector_config* config = fixture->config; - unsigned char* protected_buffer = gpr_zalloc(config->protected_buffer_size); + unsigned char* protected_buffer = + static_cast<unsigned char*>(gpr_zalloc(config->protected_buffer_size)); size_t message_size = is_client ? config->client_message_size : config->server_message_size; uint8_t* message = @@ -238,9 +241,10 @@ static void receive_message_from_peer(tsi_test_fixture* fixture, size_t read_from_peer_size = 0; tsi_result result = TSI_OK; bool done = false; - unsigned char* read_buffer = gpr_zalloc(config->read_buffer_allocated_size); - unsigned char* message_buffer = - gpr_zalloc(config->message_buffer_allocated_size); + unsigned char* read_buffer = static_cast<unsigned char*>( + gpr_zalloc(config->read_buffer_allocated_size)); + unsigned char* message_buffer = static_cast<unsigned char*>( + gpr_zalloc(config->message_buffer_allocated_size)); /* Do unprotect on data received from peer. */ while (!done && result == TSI_OK) { /* Receive data from peer. */ @@ -432,7 +436,7 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { /* Client sends a message to server. */ send_message_to_peer(fixture, client_frame_protector, true /* is_client */); unsigned char* server_received_message = - gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE); + static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); size_t server_received_message_size = 0; receive_message_from_peer( fixture, server_frame_protector, server_received_message, @@ -443,7 +447,7 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { /* Server sends a message to client. */ send_message_to_peer(fixture, server_frame_protector, false /* is_client */); unsigned char* client_received_message = - gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE); + static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); size_t client_received_message_size = 0; receive_message_from_peer( fixture, client_frame_protector, client_received_message, @@ -461,7 +465,8 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { static unsigned char* generate_random_message(size_t size) { size_t i; unsigned char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; - unsigned char* output = gpr_zalloc(sizeof(unsigned char) * size); + unsigned char* output = + static_cast<unsigned char*>(gpr_zalloc(sizeof(unsigned char) * size)); for (i = 0; i < size - 1; ++i) { output[i] = chars[rand() % (int)(sizeof(chars) - 1)]; } @@ -476,7 +481,9 @@ tsi_test_frame_protector_config* tsi_test_frame_protector_config_create( bool use_default_client_max_output_protected_frame_size, bool use_default_server_max_output_protected_frame_size, bool use_default_handshake_buffer_size) { - tsi_test_frame_protector_config* config = gpr_zalloc(sizeof(*config)); + tsi_test_frame_protector_config* config = + static_cast<tsi_test_frame_protector_config*>( + gpr_zalloc(sizeof(*config))); /* Set the value for read_buffer_allocated_size. */ config->read_buffer_allocated_size = use_default_read_buffer_allocated_size @@ -551,8 +558,10 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture) { fixture->config = tsi_test_frame_protector_config_create( true, true, true, true, true, true, true, true); fixture->handshake_buffer_size = TSI_TEST_DEFAULT_BUFFER_SIZE; - fixture->client_channel = gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE); - fixture->server_channel = gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE); + fixture->client_channel = + static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + fixture->server_channel = + static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); fixture->bytes_written_to_client_channel = 0; fixture->bytes_written_to_server_channel = 0; fixture->bytes_read_from_client_channel = 0; diff --git a/test/core/tsi/transport_security_test_lib.h b/test/core/tsi/transport_security_test_lib.h index d067b6d3dd..9b07448cc5 100644 --- a/test/core/tsi/transport_security_test_lib.h +++ b/test/core/tsi/transport_security_test_lib.h @@ -23,10 +23,6 @@ #include <grpc/support/sync.h> -#ifdef __cplusplus -extern "C" { -#endif - #define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE 32 #define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE 128 #define TSI_TEST_SMALL_READ_BUFFER_ALLOCATED_SIZE 41 @@ -175,8 +171,4 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture); the client and server switching its role. */ void tsi_test_do_round_trip(tsi_test_fixture* fixture); -#ifdef __cplusplus -} -#endif - #endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_ |