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 #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
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
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
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
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
109