Debian Codegraph @

test/core/slice/slice_string_helpers_test.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include "src/core/lib/slice/slice_string_helpers.h"
20
21 #include "gtest/gtest.h"
22
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
25
26 #include "src/core/lib/gpr/string.h"
27
28 #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x)
29
30 static void expect_slice_dump(grpc_slice slice, uint32_t flags,
31 const char* result) {
32 char* got = grpc_dump_slice(slice, flags);
33 ASSERT_STREQ(got, result);
34 gpr_free(got);
35 grpc_slice_unref(slice);
36 }
37
38 TEST(SliceStringHelpersTest, DumpSlice) {
39 static const char* text = "HELLO WORLD!";
40 static const char* long_text =
41 "It was a bright cold day in April, and the clocks were striking "
42 "thirteen. Winston Smith, his chin nuzzled into his breast in an effort "
43 "to escape the vile wind, slipped quickly through the glass doors of "
44 "Victory Mansions, though not quickly enough to prevent a swirl of "
45 "gritty dust from entering along with him.";
46
47 LOG_TEST_NAME("test_dump_slice");
48
49 expect_slice_dump(grpc_slice_from_copied_string(text), GPR_DUMP_ASCII, text);
50 expect_slice_dump(grpc_slice_from_copied_string(long_text), GPR_DUMP_ASCII,
51 long_text);
52 expect_slice_dump(grpc_slice_from_copied_buffer("\x01", 1), GPR_DUMP_HEX,
53 "01");
54 expect_slice_dump(grpc_slice_from_copied_buffer("\x01", 1),
55 GPR_DUMP_HEX | GPR_DUMP_ASCII, "01 '.'");
56 }
57
58 int main(int argc, char** argv) {
59 ::testing::InitGoogleTest(&argc, argv);
60 return RUN_ALL_TESTS();
61 }