aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/compression/algorithm_test.cc
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/compression/algorithm_test.cc
parentc563b583cb9b7fecc33971581368796d2df4759d (diff)
rename all test core files to cc and a lot of C++ style conversions
Diffstat (limited to 'test/core/compression/algorithm_test.cc')
-rw-r--r--test/core/compression/algorithm_test.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc
new file mode 100644
index 0000000000..4ca979e30f
--- /dev/null
+++ b/test/core/compression/algorithm_test.cc
@@ -0,0 +1,100 @@
+/*
+ *
+ * Copyright 2015 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "src/core/lib/compression/algorithm_metadata.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
+
+#include "src/core/lib/slice/slice_internal.h"
+#include "src/core/lib/transport/static_metadata.h"
+#include "test/core/util/test_config.h"
+
+static void test_algorithm_mesh(void) {
+ int i;
+
+ gpr_log(GPR_DEBUG, "test_algorithm_mesh");
+
+ for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
+ const char *name;
+ grpc_compression_algorithm parsed;
+ grpc_slice mdstr;
+ grpc_mdelem mdelem;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GPR_ASSERT(
+ grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name));
+ GPR_ASSERT(grpc_compression_algorithm_parse(
+ grpc_slice_from_static_string(name), &parsed));
+ GPR_ASSERT((int)parsed == i);
+ mdstr = grpc_slice_from_copied_string(name);
+ GPR_ASSERT(grpc_slice_eq(mdstr, grpc_compression_algorithm_slice(parsed)));
+ GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr));
+ mdelem = grpc_compression_encoding_mdelem(parsed);
+ GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr));
+ GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING));
+ grpc_slice_unref_internal(&exec_ctx, mdstr);
+ GRPC_MDELEM_UNREF(&exec_ctx, mdelem);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+
+ /* test failure */
+ GPR_ASSERT(GRPC_MDISNULL(
+ grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT)));
+}
+
+static void test_algorithm_failure(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_slice mdstr;
+
+ gpr_log(GPR_DEBUG, "test_algorithm_failure");
+
+ GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT,
+ NULL) == 0);
+ GPR_ASSERT(
+ grpc_compression_algorithm_name(static_cast<grpc_compression_algorithm>(
+ GRPC_COMPRESS_ALGORITHMS_COUNT + 1),
+ NULL) == 0);
+ mdstr = grpc_slice_from_static_string("this-is-an-invalid-algorithm");
+ GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) ==
+ GRPC_COMPRESS_ALGORITHMS_COUNT);
+ GPR_ASSERT(grpc_slice_eq(
+ grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT),
+ grpc_empty_slice()));
+ GPR_ASSERT(grpc_slice_eq(
+ grpc_compression_algorithm_slice(static_cast<grpc_compression_algorithm>(
+ static_cast<int>(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)),
+ grpc_empty_slice()));
+ grpc_slice_unref_internal(&exec_ctx, mdstr);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+
+ test_algorithm_mesh();
+ test_algorithm_failure();
+
+ grpc_shutdown();
+
+ return 0;
+}