diff options
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/security/credentials_test.c | 27 | ||||
-rw-r--r-- | test/core/surface/byte_buffer_reader_test.c | 37 |
2 files changed, 64 insertions, 0 deletions
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index b2b7cfdb6e..9af76be257 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -31,8 +31,10 @@ * */ +#include <grpc/support/port_platform.h> #include "src/core/security/credentials.h" +#include <stdlib.h> #include <string.h> #include "src/core/httpcli/httpcli.h" @@ -1013,6 +1015,30 @@ static void test_metadata_plugin_failure(void) { grpc_exec_ctx_finish(&exec_ctx); } +static void test_get_well_known_google_credentials_file_path(void) { +#ifdef GPR_POSIX_FILE + char *path; + char *old_home = gpr_getenv("HOME"); + gpr_setenv("HOME", "/tmp"); + path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path != NULL); + GPR_ASSERT(0 == strcmp("/tmp/.config/" GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY + "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE, + path)); + gpr_free(path); +#if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV) + unsetenv("HOME"); + path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path == NULL); +#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */ + gpr_setenv("HOME", old_home); +#else /* GPR_POSIX_FILE */ + char *path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path != NULL); + gpr_free(path); +#endif +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_empty_md_store(); @@ -1043,5 +1069,6 @@ int main(int argc, char **argv) { test_google_default_creds_access_token(); test_metadata_plugin_success(); test_metadata_plugin_failure(); + test_get_well_known_google_credentials_file_path(); return 0; } diff --git a/test/core/surface/byte_buffer_reader_test.c b/test/core/surface/byte_buffer_reader_test.c index 6b41698717..c87fbdc897 100644 --- a/test/core/surface/byte_buffer_reader_test.c +++ b/test/core/surface/byte_buffer_reader_test.c @@ -217,6 +217,42 @@ static void test_readall(void) { grpc_byte_buffer_destroy(buffer); } +static void test_byte_buffer_copy(void) { + char *lotsa_as[512]; + char *lotsa_bs[1024]; + gpr_slice slices[2]; + grpc_byte_buffer *buffer; + grpc_byte_buffer *copied_buffer; + grpc_byte_buffer_reader reader; + gpr_slice slice_out; + + LOG_TEST("test_byte_buffer_copy"); + + memset(lotsa_as, 'a', 512); + memset(lotsa_bs, 'b', 1024); + /* use slices large enough to overflow inlining */ + slices[0] = gpr_slice_malloc(512); + memcpy(GPR_SLICE_START_PTR(slices[0]), lotsa_as, 512); + slices[1] = gpr_slice_malloc(1024); + memcpy(GPR_SLICE_START_PTR(slices[1]), lotsa_bs, 1024); + + buffer = grpc_raw_byte_buffer_create(slices, 2); + gpr_slice_unref(slices[0]); + gpr_slice_unref(slices[1]); + copied_buffer = grpc_byte_buffer_copy(buffer); + + grpc_byte_buffer_reader_init(&reader, copied_buffer); + slice_out = grpc_byte_buffer_reader_readall(&reader); + + GPR_ASSERT(GPR_SLICE_LENGTH(slice_out) == 512 + 1024); + GPR_ASSERT(memcmp(GPR_SLICE_START_PTR(slice_out), lotsa_as, 512) == 0); + GPR_ASSERT(memcmp(&(GPR_SLICE_START_PTR(slice_out)[512]), lotsa_bs, 1024) == + 0); + gpr_slice_unref(slice_out); + grpc_byte_buffer_destroy(buffer); + grpc_byte_buffer_destroy(copied_buffer); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_read_one_slice(); @@ -225,6 +261,7 @@ int main(int argc, char **argv) { test_read_gzip_compressed_slice(); test_read_deflate_compressed_slice(); test_byte_buffer_from_reader(); + test_byte_buffer_copy(); test_readall(); return 0; } |