aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/compression
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:51:52 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2016-03-17 22:51:52 -0700
commit13c2f6e69d04804b4c1cba6380b54f6adb80cee0 (patch)
tree5b62e2d0c5bb267e12e125ea5421c3e96c483157 /test/core/compression
parent921f4b0a6e0c77f8c1d0f48b72d7087a21f5e311 (diff)
Implemented compression level algorithms properly (as a function of the accepted algorithms by the call's peer.
Diffstat (limited to 'test/core/compression')
-rw-r--r--test/core/compression/compression_test.c102
1 files changed, 91 insertions, 11 deletions
diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c
index 26d7b2b6cc..5d8231fd7f 100644
--- a/test/core/compression/compression_test.c
+++ b/test/core/compression/compression_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -93,18 +93,98 @@ static void test_compression_algorithm_name(void) {
}
static void test_compression_algorithm_for_level(void) {
- size_t i;
- grpc_compression_level levels[] = {
- GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_LOW,
- GRPC_COMPRESS_LEVEL_MED, GRPC_COMPRESS_LEVEL_HIGH};
- grpc_compression_algorithm algorithms[] = {
- GRPC_COMPRESS_NONE, GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE,
- GRPC_COMPRESS_DEFLATE};
gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level");
- for (i = 0; i < GPR_ARRAY_SIZE(levels); i++) {
- GPR_ASSERT(algorithms[i] ==
- grpc_compression_algorithm_for_level(levels[i]));
+ {
+ /* accept only identity (aka none) */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept only gzip */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept only deflate */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept gzip and deflate */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
}
}