src/server/test/uri.c

changeset 385
a1f4cb076d2f
parent 355
4a7dd7ff92c9
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "uri.h"
30
31 #include "../util/util.h"
32
33
34 UCX_TEST(test_util_uri_escape_alphanum) {
35 char *str1 = "/test/path/abc/";
36 char str_enc[512];
37
38 UCX_TEST_BEGIN;
39
40 char *test = util_uri_escape(str_enc, str1);
41 UCX_TEST_ASSERT(test, "util_uri_escape returned NULL");
42 UCX_TEST_ASSERT(!strcasecmp(test, str1), "test != str1");
43
44 UCX_TEST_END;
45 }
46
47 UCX_TEST(test_util_uri_escape_space) {
48 char *str1 = "/test/space in path/";
49 char *str_enc_expected = "/test/space%20in%20path/";
50 char str_enc[512];
51
52 UCX_TEST_BEGIN;
53
54 char *test = util_uri_escape(str_enc, str1);
55 UCX_TEST_ASSERT(test, "util_uri_escape returned NULL");
56 UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result");
57
58 UCX_TEST_END;
59 }
60
61 UCX_TEST(test_util_uri_escape_latin) {
62 char *str1 = "/test/path/öäütestß/";
63 char *str_enc_expected = "/test/path/%C3%B6%C3%A4%C3%BCtest%C3%9F/";
64
65 char *str2 = "€";
66 char *str2_enc_expected = "%E2%82%AC";
67
68 char str_enc[512];
69
70 UCX_TEST_BEGIN;
71
72 // test 1
73 char *test = util_uri_escape(str_enc, str1);
74 UCX_TEST_ASSERT(test, "util_uri_escape returned NULL");
75 UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result");
76
77 // test 2
78 test = util_uri_escape(str_enc, str2);
79 UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL");
80 UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result");
81
82 UCX_TEST_END;
83 }
84
85 UCX_TEST(test_util_uri_escape_kanji) {
86 char *str1 = "漢字";
87 char *str1_enc_expected = "%E6%BC%A2%E5%AD%97";
88
89 char *str2 = "/test/エンコーディング/漢字/";
90 char *str2_enc_expected = "/test/%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0/%E6%BC%A2%E5%AD%97/";
91
92 char str_enc[512];
93
94 UCX_TEST_BEGIN;
95
96 // test 1
97 char *test = util_uri_escape(str_enc, str1);
98 UCX_TEST_ASSERT(test, "util_uri_escape returned NULL");
99 UCX_TEST_ASSERT(!strcasecmp(test, str1_enc_expected), "unexpected result");
100
101 // test 2
102 test = util_uri_escape(str_enc, str2);
103 UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL");
104 UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result");
105
106 UCX_TEST_END;
107 }
108

mercurial