diff options
author | 2015-12-09 17:25:10 -0800 | |
---|---|---|
committer | 2015-12-09 17:25:10 -0800 | |
commit | e9fa31141d972f320c8c0df48f1a77c5e75c9573 (patch) | |
tree | 198126c28956d8649bb1c60bd81a923dabfb2a3b /test/core/compression | |
parent | 3ff5d2dd6be6496db1ae45fd957747a5a5c2181b (diff) |
Further coverage for compression
Diffstat (limited to 'test/core/compression')
-rw-r--r-- | test/core/compression/message_compress_test.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 70359a3f69..131b5e7f65 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -148,26 +148,53 @@ static gpr_slice create_test_value(test_value id) { return gpr_slice_from_copied_string("bad value"); } -static void test_bad_data(void) { +static void test_tiny_data_compress(void) { gpr_slice_buffer input; gpr_slice_buffer output; grpc_compression_algorithm i; gpr_slice_buffer_init(&input); gpr_slice_buffer_init(&output); - gpr_slice_buffer_add(&input, gpr_slice_from_copied_string( - "this is not valid compressed input")); + gpr_slice_buffer_add(&input, create_test_value(ONE_A)); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; - GPR_ASSERT(0 == grpc_msg_decompress(i, &input, &output)); - GPR_ASSERT(0 == output.count); + GPR_ASSERT(0 == grpc_msg_compress(i, &input, &output)); + GPR_ASSERT(1 == output.count); } gpr_slice_buffer_destroy(&input); gpr_slice_buffer_destroy(&output); } +static void test_bad_data_decompress(void) { + gpr_slice_buffer input; + gpr_slice_buffer corrupted; + gpr_slice_buffer output; + size_t idx; + const gpr_uint32 bad = 0xdeadbeef; + + gpr_slice_buffer_init(&input); + gpr_slice_buffer_init(&corrupted); + gpr_slice_buffer_init(&output); + gpr_slice_buffer_add(&input, create_test_value(ONE_MB_A)); + + /* compress it */ + grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); + /* corrupt the output by smashing the CRC */ + GPR_ASSERT(corrupted.count > 1); + GPR_ASSERT(GPR_SLICE_LENGTH(corrupted.slices[1]) > 8); + idx = GPR_SLICE_LENGTH(corrupted.slices[1]) - 8; + memcpy(GPR_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4); + + /* try (and fail) to decompress the corrupted compresed buffer */ + GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); + + gpr_slice_buffer_destroy(&input); + gpr_slice_buffer_destroy(&corrupted); + gpr_slice_buffer_destroy(&output); +} + static void test_bad_compression_algorithm(void) { gpr_slice_buffer input; gpr_slice_buffer output; @@ -234,7 +261,8 @@ int main(int argc, char **argv) { } } - test_bad_data(); + test_tiny_data_compress(); + test_bad_data_decompress(); test_bad_compression_algorithm(); test_bad_decompression_algorithm(); grpc_shutdown(); |