Debian Codegraph @

crt/aws-c-sdkutils/tests/endpoints_util_tests.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/common/byte_buf.h>
7 #include <aws/common/string.h>
8 #include <aws/sdkutils/private/endpoints_util.h>
9 #include <aws/testing/aws_test_harness.h>
10
11 AWS_TEST_CASE(endpoints_uri_normalize_path, s_test_uri_normalize_path)
12 static int s_test_uri_normalize_path(struct aws_allocator *allocator, void *ctx) {
13 (void)ctx;
14
15 struct aws_byte_buf buf1;
16 ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("/"), &buf1));
17 ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf1, "/"));
18 aws_byte_buf_clean_up(&buf1);
19
20 struct aws_byte_buf buf2;
21 ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("aaa"), &buf2));
22 ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf2, "/aaa/"));
23 aws_byte_buf_clean_up(&buf2);
24
25 struct aws_byte_buf buf3;
26 ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("aaa/"), &buf3));
27 ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf3, "/aaa/"));
28 aws_byte_buf_clean_up(&buf3);
29
30 struct aws_byte_buf buf4;
31 ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("/aaa"), &buf4));
32 ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf4, "/aaa/"));
33 aws_byte_buf_clean_up(&buf4);
34
35 struct aws_byte_buf buf5;
36 ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str(""), &buf5));
37 ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf5, "/"));
38 aws_byte_buf_clean_up(&buf5);
39
40 return AWS_OP_SUCCESS;
41 }
42
43 int s_resolve_cb(struct aws_byte_cursor template, void *user_data, struct aws_owning_cursor *out_resolved) {
44 (void)template;
45 (void)user_data;
46 *out_resolved = aws_endpoints_non_owning_cursor_create(aws_byte_cursor_from_c_str("test"));
47 return AWS_OP_SUCCESS;
48 }
49
50 AWS_TEST_CASE(
51 endpoints_byte_buf_init_from_resolved_templated_string,
52 s_test_byte_buf_init_from_resolved_templated_string)
53 static int s_test_byte_buf_init_from_resolved_templated_string(struct aws_allocator *allocator, void *ctx) {
54 (void)ctx;
55
56 struct aws_byte_buf buf;
57
58 ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
59 allocator, &buf, aws_byte_cursor_from_c_str("{e} a {b}{c} a {d}"), s_resolve_cb, NULL, false));
60 ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "test a testtest a test");
61 aws_byte_buf_clean_up(&buf);
62
63 ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
64 allocator,
65 &buf,
66 aws_byte_cursor_from_c_str("{ \"a\": \"{b} {d} \", \"c\": \" {e} \"}"),
67 s_resolve_cb,
68 NULL,
69 true));
70 ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "{ \"a\": \"test test \", \"c\": \" test \"}");
71 aws_byte_buf_clean_up(&buf);
72
73 ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
74 allocator, &buf, aws_byte_cursor_from_c_str("a \" {b} \" a"), s_resolve_cb, NULL, false));
75 ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "a \" test \" a");
76 aws_byte_buf_clean_up(&buf);
77
78 ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
79 allocator, &buf, aws_byte_cursor_from_c_str("{ \"a\": \"a \\\" {b} \\\" a\" }"), s_resolve_cb, NULL, true));
80 ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "{ \"a\": \"a \\\" test \\\" a\" }");
81 aws_byte_buf_clean_up(&buf);
82
83 return AWS_OP_SUCCESS;
84 }