1
- #include "test-lib .h"
1
+ #include "unit-test .h"
2
2
#include "urlmatch.h"
3
3
4
4
static void check_url_normalizable (const char * url , unsigned int normalizable )
5
5
{
6
6
char * url_norm = url_normalize (url , NULL );
7
7
8
- if (!check_int (normalizable , = = , url_norm ? 1 : 0 ))
9
- test_msg ("input url: %s" , url );
8
+ cl_assert_equal_i (normalizable , url_norm ? 1 : 0 );
10
9
free (url_norm );
11
10
}
12
11
13
12
static void check_normalized_url (const char * url , const char * expect )
14
13
{
15
14
char * url_norm = url_normalize (url , NULL );
16
15
17
- if (!check_str (url_norm , expect ))
18
- test_msg ("input url: %s" , url );
16
+ cl_assert_equal_s (url_norm , expect );
19
17
free (url_norm );
20
18
}
21
19
@@ -26,13 +24,9 @@ static void compare_normalized_urls(const char *url1, const char *url2,
26
24
char * url2_norm = url_normalize (url2 , NULL );
27
25
28
26
if (equal ) {
29
- if (!check_str (url1_norm , url2_norm ))
30
- test_msg ("input url1: %s\n input url2: %s" , url1 ,
31
- url2 );
32
- } else if (!check_int (strcmp (url1_norm , url2_norm ), != , 0 )) {
33
- test_msg (" normalized url1: %s\n normalized url2: %s\n"
34
- " input url1: %s\n input url2: %s" ,
35
- url1_norm , url2_norm , url1 , url2 );
27
+ cl_assert_equal_s (url1_norm , url2_norm );
28
+ } else {
29
+ cl_assert (strcmp (url1_norm , url2_norm ) != 0 );
36
30
}
37
31
free (url1_norm );
38
32
free (url2_norm );
@@ -43,14 +37,12 @@ static void check_normalized_url_length(const char *url, size_t len)
43
37
struct url_info info ;
44
38
char * url_norm = url_normalize (url , & info );
45
39
46
- if (!check_int (info .url_len , = = , len ))
47
- test_msg (" input url: %s\n normalized url: %s" , url ,
48
- url_norm );
40
+ cl_assert_equal_i (info .url_len , len );
49
41
free (url_norm );
50
42
}
51
43
52
44
/* Note that only "file:" URLs should be allowed without a host */
53
- static void t_url_scheme (void )
45
+ void test_urlmatch_normalization__scheme (void )
54
46
{
55
47
check_url_normalizable ("" , 0 );
56
48
check_url_normalizable ("_" , 0 );
@@ -73,7 +65,7 @@ static void t_url_scheme(void)
73
65
check_normalized_url ("AbCdeF://x.Y" , "abcdef://x.y/" );
74
66
}
75
67
76
- static void t_url_authority (void )
68
+ void test_urlmatch_normalization__authority (void )
77
69
{
78
70
check_url_normalizable ("scheme://user:pass@" , 0 );
79
71
check_url_normalizable ("scheme://?" , 0 );
@@ -109,7 +101,7 @@ static void t_url_authority(void)
109
101
check_url_normalizable ("scheme://invalid....:[" , 0 );
110
102
}
111
103
112
- static void t_url_port (void )
104
+ void test_urlmatch_normalization__port (void )
113
105
{
114
106
check_url_normalizable (
"xyz://[email protected] :" ,
1 );
115
107
check_url_normalizable (
"xyz://[email protected] :456/" ,
1 );
@@ -139,7 +131,7 @@ static void t_url_port(void)
139
131
check_url_normalizable ("xyz://[::1]:030f/" , 0 );
140
132
}
141
133
142
- static void t_url_port_normalization (void )
134
+ void test_urlmatch_normalization__port_normalization (void )
143
135
{
144
136
check_normalized_url ("http://x:800" , "http://x:800/" );
145
137
check_normalized_url ("http://x:0800" , "http://x:800/" );
@@ -154,7 +146,7 @@ static void t_url_port_normalization(void)
154
146
check_normalized_url ("https://x:000000443" , "https://x/" );
155
147
}
156
148
157
- static void t_url_general_escape (void )
149
+ void test_urlmatch_normalization__general_escape (void )
158
150
{
159
151
check_url_normalizable ("http://x.y?%fg" , 0 );
160
152
check_normalized_url ("X://W/%7e%41^%3a" , "x://w/~A%5E%3A" );
@@ -164,7 +156,7 @@ static void t_url_general_escape(void)
164
156
check_normalized_url ("X://W?!" , "x://w/?!" );
165
157
}
166
158
167
- static void t_url_high_bit (void )
159
+ void test_urlmatch_normalization__high_bit (void )
168
160
{
169
161
check_normalized_url (
170
162
"x://q/\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f\x10\x11\x12" ,
@@ -198,26 +190,26 @@ static void t_url_high_bit(void)
198
190
"x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" );
199
191
}
200
192
201
- static void t_url_utf8_escape (void )
193
+ void test_urlmatch_normalization__utf8_escape (void )
202
194
{
203
195
check_normalized_url (
204
196
"x://q/\xc2\x80\xdf\xbf\xe0\xa0\x80\xef\xbf\xbd\xf0\x90\x80\x80\xf0\xaf\xbf\xbd" ,
205
197
"x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD" );
206
198
}
207
199
208
- static void t_url_username_pass (void )
200
+ void test_urlmatch_normalization__username_pass (void )
209
201
{
210
202
check_normalized_url ("x://%41%62(^):%70+d@foo" , "x://Ab(%5E):p+d@foo/" );
211
203
}
212
204
213
- static void t_url_length (void )
205
+ void test_urlmatch_normalization__length (void )
214
206
{
215
207
check_normalized_url_length (
"Http://%4d%65:%4d^%[email protected] " ,
25 );
216
208
check_normalized_url_length (
"http://%41:%[email protected] /%61/" ,
17 );
217
209
check_normalized_url_length ("http://@x.y/^" , 15 );
218
210
}
219
211
220
- static void t_url_dots (void )
212
+ void test_urlmatch_normalization__dots (void )
221
213
{
222
214
check_normalized_url ("x://y/." , "x://y/" );
223
215
check_normalized_url ("x://y/./" , "x://y/" );
@@ -244,7 +236,7 @@ static void t_url_dots(void)
244
236
* "http://foo" specifies neither a user name nor a password.
245
237
* So they should not be equivalent.
246
238
*/
247
- static void t_url_equivalents (void )
239
+ void test_urlmatch_normalization__equivalents (void )
248
240
{
249
241
compare_normalized_urls ("httP://x" , "Http://X/" , 1 );
250
242
compare_normalized_urls (
"Http://%4d%65:%4d^%[email protected] " ,
"hTTP://Me:%4D^[email protected] :80/" ,
1 );
@@ -253,19 +245,3 @@ static void t_url_equivalents(void)
253
245
compare_normalized_urls ("https://@x.y/^/../abc" , "httpS://@x.y:0443/abc" , 1 );
254
246
compare_normalized_urls ("https://@x.y/^/.." , "httpS://@x.y:0443/" , 1 );
255
247
}
256
-
257
- int cmd_main (int argc UNUSED , const char * * argv UNUSED )
258
- {
259
- TEST (t_url_scheme (), "url scheme" );
260
- TEST (t_url_authority (), "url authority" );
261
- TEST (t_url_port (), "url port checks" );
262
- TEST (t_url_port_normalization (), "url port normalization" );
263
- TEST (t_url_general_escape (), "url general escapes" );
264
- TEST (t_url_high_bit (), "url high-bit escapes" );
265
- TEST (t_url_utf8_escape (), "url utf8 escapes" );
266
- TEST (t_url_username_pass (), "url username/password escapes" );
267
- TEST (t_url_length (), "url normalized lengths" );
268
- TEST (t_url_dots (), "url . and .. segments" );
269
- TEST (t_url_equivalents (), "url equivalents" );
270
- return test_done ();
271
- }
0 commit comments