1- #include  "test-lib .h" 
1+ #include  "unit-test .h" 
22#include  "urlmatch.h" 
33
44static  void  check_url_normalizable (const  char  * url , unsigned int   normalizable )
55{
66	char  * url_norm  =  url_normalize (url , NULL );
77
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 );
109	free (url_norm );
1110}
1211
1312static  void  check_normalized_url (const  char  * url , const  char  * expect )
1413{
1514	char  * url_norm  =  url_normalize (url , NULL );
1615
17- 	if  (!check_str (url_norm , expect ))
18- 		test_msg ("input url: %s" , url );
16+ 	cl_assert_equal_s (url_norm , expect );
1917	free (url_norm );
2018}
2119
@@ -26,13 +24,9 @@ static void compare_normalized_urls(const char *url1, const char *url2,
2624	char  * url2_norm  =  url_normalize (url2 , NULL );
2725
2826	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 );
3630	}
3731	free (url1_norm );
3832	free (url2_norm );
@@ -43,14 +37,12 @@ static void check_normalized_url_length(const char *url, size_t len)
4337	struct  url_info  info ;
4438	char  * url_norm  =  url_normalize (url , & info );
4539
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 );
4941	free (url_norm );
5042}
5143
5244/* 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 )
5446{
5547	check_url_normalizable ("" , 0 );
5648	check_url_normalizable ("_" , 0 );
@@ -73,7 +65,7 @@ static void t_url_scheme(void)
7365	check_normalized_url ("AbCdeF://x.Y" , "abcdef://x.y/" );
7466}
7567
76- static   void  t_url_authority (void )
68+ void  test_urlmatch_normalization__authority (void )
7769{
7870	check_url_normalizable ("scheme://user:pass@" , 0 );
7971	check_url_normalizable ("scheme://?" , 0 );
@@ -109,7 +101,7 @@ static void t_url_authority(void)
109101	check_url_normalizable ("scheme://invalid....:[" , 0 );
110102}
111103
112- static   void  t_url_port (void )
104+ void  test_urlmatch_normalization__port (void )
113105{
114106	check_url_normalizable (
"xyz://[email protected] :" , 
1 );
 115107	check_url_normalizable (
"xyz://[email protected] :456/" , 
1 );
 @@ -139,7 +131,7 @@ static void t_url_port(void)
139131	check_url_normalizable ("xyz://[::1]:030f/" , 0 );
140132}
141133
142- static   void  t_url_port_normalization (void )
134+ void  test_urlmatch_normalization__port_normalization (void )
143135{
144136	check_normalized_url ("http://x:800" , "http://x:800/" );
145137	check_normalized_url ("http://x:0800" , "http://x:800/" );
@@ -154,7 +146,7 @@ static void t_url_port_normalization(void)
154146	check_normalized_url ("https://x:000000443" , "https://x/" );
155147}
156148
157- static   void  t_url_general_escape (void )
149+ void  test_urlmatch_normalization__general_escape (void )
158150{
159151	check_url_normalizable ("http://x.y?%fg" , 0 );
160152	check_normalized_url ("X://W/%7e%41^%3a" , "x://w/~A%5E%3A" );
@@ -164,7 +156,7 @@ static void t_url_general_escape(void)
164156	check_normalized_url ("X://W?!" , "x://w/?!" );
165157}
166158
167- static   void  t_url_high_bit (void )
159+ void  test_urlmatch_normalization__high_bit (void )
168160{
169161	check_normalized_url (
170162		"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)
198190		"x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" );
199191}
200192
201- static   void  t_url_utf8_escape (void )
193+ void  test_urlmatch_normalization__utf8_escape (void )
202194{
203195	check_normalized_url (
204196		"x://q/\xc2\x80\xdf\xbf\xe0\xa0\x80\xef\xbf\xbd\xf0\x90\x80\x80\xf0\xaf\xbf\xbd" ,
205197		"x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD" );
206198}
207199
208- static   void  t_url_username_pass (void )
200+ void  test_urlmatch_normalization__username_pass (void )
209201{
210202	check_normalized_url ("x://%41%62(^):%70+d@foo" , "x://Ab(%5E):p+d@foo/" );
211203}
212204
213- static   void  t_url_length (void )
205+ void  test_urlmatch_normalization__length (void )
214206{
215207	check_normalized_url_length (
"Http://%4d%65:%4d^%[email protected] " , 
25 );
 216208	check_normalized_url_length (
"http://%41:%[email protected] /%61/" , 
17 );
 217209	check_normalized_url_length ("http://@x.y/^" , 15 );
218210}
219211
220- static   void  t_url_dots (void )
212+ void  test_urlmatch_normalization__dots (void )
221213{
222214	check_normalized_url ("x://y/." , "x://y/" );
223215	check_normalized_url ("x://y/./" , "x://y/" );
@@ -244,7 +236,7 @@ static void t_url_dots(void)
244236 * "http://foo" specifies neither a user name nor a password. 
245237 * So they should not be equivalent. 
246238 */ 
247- static   void  t_url_equivalents (void )
239+ void  test_urlmatch_normalization__equivalents (void )
248240{
249241	compare_normalized_urls ("httP://x" , "Http://X/" , 1 );
250242	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)
253245	compare_normalized_urls ("https://@x.y/^/../abc" , "httpS://@x.y:0443/abc" , 1 );
254246	compare_normalized_urls ("https://@x.y/^/.." , "httpS://@x.y:0443/" , 1 );
255247}
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