aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/tsi
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-10-23 15:33:21 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2017-10-25 16:23:01 -0700
commit34a57d0346afe95e11104462c30dc468b0cb0b89 (patch)
tree67db15f7b8b361e0618199dc55215f3b4d626201 /test/core/tsi
parentc563b583cb9b7fecc33971581368796d2df4759d (diff)
rename all test core files to cc and a lot of C++ style conversions
Diffstat (limited to 'test/core/tsi')
-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
4 files changed, 48 insertions, 31 deletions
diff --git a/test/core/tsi/fake_transport_security_test.c b/test/core/tsi/fake_transport_security_test.cc
index 11be8802b7..6561028860 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 2399b054b1..27b2049dd8 100644
--- a/test/core/tsi/ssl_transport_security_test.c
+++ b/test/core/tsi/ssl_transport_security_test.cc
@@ -326,8 +326,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;
@@ -339,12 +339,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 =
@@ -352,11 +354,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 =
@@ -380,11 +384,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);
@@ -431,7 +436,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);
}
@@ -440,7 +446,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);
}
@@ -495,8 +502,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 27932a8169..c1be1e952d 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 329b2371bf..454b79c0cc 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. */
@@ -429,7 +433,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,
@@ -440,7 +444,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,
@@ -458,7 +462,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)];
}
@@ -473,7 +478,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
@@ -548,8 +555,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;