File: endpoints_util_tests.c

package info (click to toggle)
aws-crt-python 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 75,932 kB
  • sloc: ansic: 418,984; python: 23,626; makefile: 6,035; sh: 4,075; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (84 lines) | stat: -rw-r--r-- 3,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/byte_buf.h>
#include <aws/common/string.h>
#include <aws/sdkutils/private/endpoints_util.h>
#include <aws/testing/aws_test_harness.h>

AWS_TEST_CASE(endpoints_uri_normalize_path, s_test_uri_normalize_path)
static int s_test_uri_normalize_path(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;

    struct aws_byte_buf buf1;
    ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("/"), &buf1));
    ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf1, "/"));
    aws_byte_buf_clean_up(&buf1);

    struct aws_byte_buf buf2;
    ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("aaa"), &buf2));
    ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf2, "/aaa/"));
    aws_byte_buf_clean_up(&buf2);

    struct aws_byte_buf buf3;
    ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("aaa/"), &buf3));
    ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf3, "/aaa/"));
    aws_byte_buf_clean_up(&buf3);

    struct aws_byte_buf buf4;
    ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str("/aaa"), &buf4));
    ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf4, "/aaa/"));
    aws_byte_buf_clean_up(&buf4);

    struct aws_byte_buf buf5;
    ASSERT_SUCCESS(aws_byte_buf_init_from_normalized_uri_path(allocator, aws_byte_cursor_from_c_str(""), &buf5));
    ASSERT_TRUE(aws_byte_buf_eq_c_str(&buf5, "/"));
    aws_byte_buf_clean_up(&buf5);

    return AWS_OP_SUCCESS;
}

int s_resolve_cb(struct aws_byte_cursor template, void *user_data, struct aws_owning_cursor *out_resolved) {
    (void)template;
    (void)user_data;
    *out_resolved = aws_endpoints_non_owning_cursor_create(aws_byte_cursor_from_c_str("test"));
    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(
    endpoints_byte_buf_init_from_resolved_templated_string,
    s_test_byte_buf_init_from_resolved_templated_string)
static int s_test_byte_buf_init_from_resolved_templated_string(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;

    struct aws_byte_buf buf;

    ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
        allocator, &buf, aws_byte_cursor_from_c_str("{e} a {b}{c} a {d}"), s_resolve_cb, NULL, false));
    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "test a testtest a test");
    aws_byte_buf_clean_up(&buf);

    ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
        allocator,
        &buf,
        aws_byte_cursor_from_c_str("{ \"a\": \"{b} {d} \", \"c\": \" {e} \"}"),
        s_resolve_cb,
        NULL,
        true));
    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "{ \"a\": \"test test \", \"c\": \" test \"}");
    aws_byte_buf_clean_up(&buf);

    ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
        allocator, &buf, aws_byte_cursor_from_c_str("a \" {b} \" a"), s_resolve_cb, NULL, false));
    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "a \" test \" a");
    aws_byte_buf_clean_up(&buf);

    ASSERT_SUCCESS(aws_byte_buf_init_from_resolved_templated_string(
        allocator, &buf, aws_byte_cursor_from_c_str("{ \"a\": \"a \\\" {b} \\\" a\" }"), s_resolve_cb, NULL, true));
    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(aws_byte_cursor_from_buf(&buf), "{ \"a\": \"a \\\" test \\\" a\" }");
    aws_byte_buf_clean_up(&buf);

    return AWS_OP_SUCCESS;
}