File: test_neturl.ml

package info (click to toggle)
netstring 0.10.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,000 kB
  • ctags: 895
  • sloc: ml: 8,389; xml: 416; makefile: 188; sh: 103
file content (969 lines) | stat: -rw-r--r-- 24,738 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
#directory "..";;
#load "netstring.cma";;

open Neturl;;


let expect_malformed_url f =
  try ignore(f()); false with Malformed_URL -> true;;

let works f =
  not (expect_malformed_url f)
;;

(**********************************************************************)
(* extract_url_scheme                                                 *)
(**********************************************************************)

let t001 () =
  extract_url_scheme "a:bc" = "a" &&
  extract_url_scheme "A:bc" = "a" &&
  extract_url_scheme "a:b:c" = "a" &&
  extract_url_scheme "a+b-c:d:e" = "a+b-c"
;;


let t002 () =
  let test s =
    try ignore(extract_url_scheme s); false with Malformed_URL -> true
  in
  test "a" &&
  test "a/b:c" &&
  test "%61:b" &&
  test "a%3ab"
;;

(**********************************************************************)
(* url_syntax                                                         *)
(**********************************************************************)

let hashtbl_for_all f h =
  let b = ref true in
  Hashtbl.iter
    (fun k v -> b := !b && f k v)
    h;
  !b
;;

let t010 () =
  url_syntax_is_valid null_url_syntax &&
  url_syntax_is_valid ip_url_syntax &&
  hashtbl_for_all
    (fun _ syn ->
       url_syntax_is_valid syn
    )
    common_url_syntax
;;

let t011 () =
  url_syntax_is_valid (partial_url_syntax null_url_syntax) &&
  url_syntax_is_valid (partial_url_syntax ip_url_syntax) &&
  hashtbl_for_all
    (fun _ syn ->
       url_syntax_is_valid (partial_url_syntax syn)
    )
    common_url_syntax
;;

let t012 () =
  let f = fun _ -> true in
  let syn =
    { url_enable_scheme    = Url_part_not_recognized;
      url_enable_user      = Url_part_required;
      url_enable_password  = Url_part_allowed;
      url_enable_host      = Url_part_required;
      url_enable_port      = Url_part_not_recognized;
      url_enable_path      = Url_part_required;
      url_enable_param     = Url_part_not_recognized;
      url_enable_query     = Url_part_not_recognized;
      url_enable_fragment  = Url_part_required;
      url_enable_other     = Url_part_not_recognized;
      url_accepts_8bits    = false;
      url_is_valid         = f;
    } in
  let syn' = partial_url_syntax syn in
  
  (syn'.url_enable_scheme    = Url_part_not_recognized) &&
  (syn'.url_enable_user      = Url_part_allowed) &&
  (syn'.url_enable_password  = Url_part_allowed) &&
  (syn'.url_enable_host      = Url_part_allowed) &&
  (syn'.url_enable_port      = Url_part_not_recognized) &&
  (syn'.url_enable_path      = Url_part_allowed) &&
  (syn'.url_enable_param     = Url_part_not_recognized) &&
  (syn'.url_enable_query     = Url_part_not_recognized) &&
  (syn'.url_enable_fragment  = Url_part_allowed) &&
  (syn'.url_enable_other     = Url_part_not_recognized) &&
  (syn'.url_is_valid        == f) &&

  url_syntax_is_valid syn &&
  url_syntax_is_valid syn'
;;

(**********************************************************************)
(* make_url                                                           *)
(**********************************************************************)

let t020 () =
  (* Basic functionality: *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  let u1 = make_url
	     (* default: not encoded *)
	     ~scheme:"http"
	     ~user:"U"
	     ~password:"%()~$@"
	     ~host:"a.b.c"
	     ~port:81
	     ~path:["";"?";""]
	     http_syn in

  url_provides 
    ~scheme:true ~user:true ~password:true ~host:true ~port:true ~path:true 
    u1 &&

  not
    (url_provides
       ~scheme:true ~user:true ~password:true ~host:true ~port:true ~path:true 
       ~query:true u1) &&

  (url_syntax_of_url u1 == http_syn) &&

  (url_scheme   u1 = "http") &&
  (url_user     u1 = "U") &&
  (url_password u1 = "%()~$@") &&
  (url_host     u1 = "a.b.c") &&
  (url_port     u1 = 81) &&
  (url_path     u1 = ["";"?";""]) &&

  (url_user     ~encoded:true u1 = "U") &&
  (url_password ~encoded:true u1 = "%25()%7E$%40") &&
  (url_path     ~encoded:true u1 = ["";"%3F";""]) &&

  string_of_url u1 = "http://U:%25()%7E$%40@a.b.c:81/%3F/"
;;


let t021 () =
  (* Basic functionality: *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  let u1 = make_url
	     ~encoded:true
	     ~scheme:"http"
	     ~user:"%55"
	     ~password:"%25()%7e$%40"
	     ~host:"a.b.c"
	     ~port:81
	     ~path:["";"%3F";""]
	     http_syn in

  url_provides 
    ~scheme:true ~user:true ~password:true ~host:true ~port:true ~path:true 
    u1 &&

  not
    (url_provides
       ~scheme:true ~user:true ~password:true ~host:true ~port:true ~path:true 
       ~query:true u1) &&

  (url_syntax_of_url u1 == http_syn) &&

  (url_scheme   u1 = "http") &&
  (url_user     u1 = "U") &&
  (url_password u1 = "%()~$@") &&
  (url_host     u1 = "a.b.c") &&
  (url_port     u1 = 81) &&
  (url_path     u1 = ["";"?";""]) &&

  (url_user     ~encoded:true u1 = "%55") &&
  (url_password ~encoded:true u1 = "%25()%7e$%40") &&
  (url_path     ~encoded:true u1 = ["";"%3F";""]) &&

  string_of_url u1 = "http://%55:%25()%7e$%40@a.b.c:81/%3F/"
;;


(* NEGATIVE TESTS *)

let t030 () =
  (* It is not possible to add a component which is not recognized *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"http"
	 ~user:"U"
	 ~password:"%()~$@"
	 ~host:"a.b.c"
	 ~port:81
	 ~path:["";"?";""]
	 ~fragment:"abc"
	 http_syn)
;;


let t031 () =
  (* It is not possible to put malformed '%'-encodings into the URL *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  works                      (* reference *)
    (fun () ->
       make_url
	 ~encoded:true
	 ~scheme:"http"
	 ~user:"U"
	 ~password:"XX"
	 ~host:"a.b.c"
	 ~port:81
	 ~path:["";"a";""]
	 http_syn) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~encoded:true
	 ~scheme:"http"
	 ~user:"U"
	 ~password:"%XX"
	 ~host:"a.b.c"
	 ~port:81
	 ~path:["";"a";""]
	 http_syn) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~encoded:true
	 ~scheme:"http"
	 ~user:"U"
	 ~password:"%X"
	 ~host:"a.b.c"
	 ~port:81
	 ~path:["";"a";""]
	 http_syn) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~encoded:true
	 ~scheme:"http"
	 ~user:"U"
	 ~password:"%"
	 ~host:"a.b.c"
	 ~port:81
	 ~path:["";"a";""]
	 http_syn) 
;;

let t032 () =
  (* It is not possible to put unsafe characters into the URL *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  let make c =
    make_url
      ~encoded:true
      ~scheme:"http"
      ~user:"U"
      ~password:(String.make 1 c)
      ~host:"a.b.c"
      ~port:81
      ~path:["";"a";""]
      http_syn
  in

  works (fun () -> make 'a') &&                   (* reference *)

  (* List of unsafe characters taken from RFC1738: *)
  expect_malformed_url (fun () -> make '<') && 
  expect_malformed_url (fun () -> make '>') && 
  expect_malformed_url (fun () -> make '"') && 
  expect_malformed_url (fun () -> make '#') && 
    (* Note: '#' would be considered as reserved if fragments were enabled *)
  expect_malformed_url (fun () -> make '%') && 
  expect_malformed_url (fun () -> make '{') && 
  expect_malformed_url (fun () -> make '}') && 
  expect_malformed_url (fun () -> make '|') && 
  expect_malformed_url (fun () -> make '\\') && 
  expect_malformed_url (fun () -> make '^') && 
  expect_malformed_url (fun () -> make '[') && 
  expect_malformed_url (fun () -> make ']') && 
  expect_malformed_url (fun () -> make '`') &&
  expect_malformed_url (fun () -> make '~') &&
    (* Note: '~' is considered as safe in paths: *)
  works 
    (fun () ->
    make_url
      ~encoded:true
      ~scheme:"http"
      ~user:"U"
      ~password:"a"
      ~host:"a.b.c"
      ~port:81
      ~path:["";"~";""]
      http_syn)
;;

let t033 () =
  (* It is not possible to put reserved characters into the URL *)
  let http_syn = Hashtbl.find common_url_syntax "http" in

  let make_password c =
    make_url
      ~encoded:true
      ~scheme:"http"
      ~user:"U"
      ~password:(String.make 1 c)
      ~host:"a.b.c"
      ~port:81
      ~path:["";"a";""]
      http_syn
  in
  let make_path c =
    make_url
      ~encoded:true
      ~scheme:"http"
      ~user:"U"
      ~password:"a"
      ~host:"a.b.c"
      ~port:81
      ~path:["";String.make 1 c;""]
      http_syn
  in
  let make_query c =
    make_url
      ~encoded:true
      ~scheme:"http"
      ~user:"U"
      ~password:"a"
      ~host:"a.b.c"
      ~port:81
      ~path:["";"a";""]
      ~query:(String.make 1 c)
      http_syn
  in

  (* Note: There is a difference between RFC 1738 and RFC 1808 regarding
   * which characters are reserved. RFC 1808 defines a fixed set of characters
   * as reserved while RFC 1738 defines the reserved characters depending
   * on the scheme.
   * This implementation of URLs follows RFC 1738 (because of practical
   * reasons).
   *)

  works (fun () -> make_password 'a') &&                   (* reference *)
  works (fun () -> make_path 'a') &&
  works (fun () -> make_query 'a') &&

  expect_malformed_url (fun () -> make_password ':') && 
  expect_malformed_url (fun () -> make_password '@') && 
  expect_malformed_url (fun () -> make_password '/') && 
  works                (fun () -> make_password ';') &&
  works                (fun () -> make_password '?') &&
  works                (fun () -> make_password '=') &&
  works                (fun () -> make_password '&') &&

  (* Note: ';' is allowed in path and query because parameters are not
   * recognized in HTTP syntax.
   *)

  expect_malformed_url (fun () -> make_path '/') && 
  expect_malformed_url (fun () -> make_path '?') && 
  works                (fun () -> make_path ':') && 
  works                (fun () -> make_path '@') && 
  works                (fun () -> make_path ';') && 
  works                (fun () -> make_path '=') && 
  works                (fun () -> make_path '&') && 

  expect_malformed_url (fun () -> make_query '?') && 
  works                (fun () -> make_query '/') && 
  works                (fun () -> make_query ':') && 
  works                (fun () -> make_query '@') && 
  works                (fun () -> make_query ';') && 
  works                (fun () -> make_query '=') && 
  works                (fun () -> make_query '&')
;;


let t034 () =
  (* It is not possible to create a URL with a password, but without user;
   * and neither to create a URL with a port, but without host;
   * and neither to create a URL with a user, but without host
   *)

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"http"
	 ~password:"a"
	 ~host:"a.b.c"
	 ~path:["";"a";""]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"http"
	 ~user:"U"
	 ~path:["";"a";""]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"http"
	 ~port:81
	 ~path:["";"a";""]
	 ip_url_syntax)
;;


let t035 () =
  (* It is not possible to create a URL with illegal scheme prefix *)
  
  (* reference: *)
  works
    (fun () ->
       make_url
	 ~scheme:"a"
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:":"
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"a=b"
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"a%62b"
	 ip_url_syntax) &&
 
  expect_malformed_url
    (fun () ->
       make_url
	 ~scheme:"a&b"
	 ip_url_syntax)
;;


let t036 () =
  (* It is not possible to have a path with double slashes *)
  
  (* reference: *)
  works
    (fun () ->
       make_url
	 ~path:["";"a";""]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~path:["";""]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~path:["a";"";""]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~path:["";"";"a"]
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~path:["a";"";"a"]
	 ip_url_syntax)
;;


let t037 () =
  (* It is not possible to have port numbers outside 0..65535 *)
  
  (* reference: *)
  works
    (fun () ->
       make_url
	 ~host:"a"
	 ~port:1
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~host:"a"
	 ~port:(-1)
	 ip_url_syntax) &&

  expect_malformed_url
    (fun () ->
       make_url
	 ~host:"a"
	 ~port:65536
	 ip_url_syntax)
;;


let t038 () =
  (* Several cases which are not allowed. *)
  
  expect_malformed_url
    (fun () ->
       make_url
	 ~host:"a"
	 ~path:["a"]
	 ip_url_syntax
    ) &&                       (* illegal: host + relative path *)

  expect_malformed_url
    (fun () ->
       make_url
	 ~host:"a"
	 ~path:[]
	 ~param:["x"]
	 ip_url_syntax
    ) &&                       (* illegal: host + no path + params *)

  expect_malformed_url
    (fun () ->
       make_url
	 ~host:"a"
	 ~path:[]
	 ~query:"x"
	 ip_url_syntax
    )                          (* illegal: host + no path + query *)
;;

(**********************************************************************)
(* url_of_string                                                      *)
(**********************************************************************)

let t050 () =
  (* absolute URLs with ip_url_syntax *)
  let identical s =
    string_of_url (url_of_string ip_url_syntax s) = s in

  let fails s =
    try ignore(url_of_string ip_url_syntax s); false 
    with Malformed_URL -> true
  in

  identical "http:" &&

  identical "http://host" &&
  identical "http://user@host" &&
  identical "http://user:password@host" &&
  identical "http://user@host:99" &&
  identical "http://user:password@host:99" &&

  identical "http://host/" &&
  identical "http://user@host/" &&
  identical "http://user:password@host/" &&
  identical "http://user@host:99/" &&
  identical "http://user:password@host:99/" &&

  identical "http://host/a/b" &&
  identical "http://user@host/a/b" &&
  identical "http://user:password@host/a/b" &&
  identical "http://user@host:99/a/b" &&
  identical "http://user:password@host:99/a/b" &&

  identical "http://host/a/b/" &&
  identical "http://user@host/a/b/" &&
  identical "http://user:password@host/a/b/" &&
  identical "http://user@host:99/a/b/" &&
  identical "http://user:password@host:99/a/b/" &&

  identical "http://host/?a=b&c=d" &&
  identical "http://user@host/?a=b&c=d" &&
  identical "http://user:password@host/?a=b&c=d" &&
  identical "http://user@host:99/?a=b&c=d" &&
  identical "http://user:password@host:99/?a=b&c=d" &&

  fails "http://host?a=b&c=d" &&
  fails "http://user@host?a=b&c=d" &&
  fails "http://user:password@host?a=b&c=d" &&
  fails "http://user@host:99?a=b&c=d" &&
  fails "http://user:password@host:99?a=b&c=d" &&

  identical "http://host/?a=/&c=/" &&
  identical "http://user@host/?a=/&c=/" &&
  identical "http://user:password@host/?a=/&c=/" &&
  identical "http://user@host:99/?a=/&c=/" &&
  identical "http://user:password@host:99/?a=/&c=/" &&

  identical "http://host/;a;b" &&
  identical "http://user@host/;a;b" &&
  identical "http://user:password@host/;a;b" &&
  identical "http://user@host:99/;a;b" &&
  identical "http://user:password@host:99/;a;b" &&

  fails "http://host;a;b" &&
  fails "http://user@host;a;b" &&
  fails "http://user:password@host;a;b" &&
  fails "http://user@host:99;a;b" &&
  fails "http://user:password@host:99;a;b" &&

  identical "http://host/;a;b?a=b&c=d" &&
  identical "http://user@host/;a;b?a=b&c=d" &&
  identical "http://user:password@host/;a;b?a=b&c=d" &&
  identical "http://user@host:99/;a;b?a=b&c=d" &&
  identical "http://user:password@host:99/;a;b?a=b&c=d" &&

  identical "http:#f" &&

  identical "http://host#f" &&
  identical "http://user@host#f" &&
  identical "http://user:password@host#f" &&
  identical "http://user@host:99#f" &&
  identical "http://user:password@host:99#f" &&

  identical "http://host/;a;b?a=b&c=d#f" &&
  identical "http://user@host/;a;b?a=b&c=d#f" &&
  identical "http://user:password@host/;a;b?a=b&c=d#f" &&
  identical "http://user@host:99/;a;b?a=b&c=d#f" &&
  identical "http://user:password@host:99/;a;b?a=b&c=d#f" &&

  true
;;


let t051 () =
  (* relative URLs with ip_url_syntax *)
  let identical s =
    string_of_url (url_of_string ip_url_syntax s) = s in

  let fails s =
    try ignore(url_of_string ip_url_syntax s); false 
    with Malformed_URL -> true
  in

  identical "//host" &&
  identical "//user@host" &&
  identical "//user:password@host" &&
  identical "//user@host:99" &&
  identical "//user:password@host:99" &&

  identical "//host/" &&
  identical "//user@host/" &&
  identical "//user:password@host/" &&
  identical "//user@host:99/" &&
  identical "//user:password@host:99/" &&

  identical "//host#f" &&
  identical "//user@host#f" &&
  identical "//user:password@host#f" &&
  identical "//user@host:99#f" &&
  identical "//user:password@host:99#f" &&

  identical "/" &&
  identical "/a" &&
  identical "/a/" &&
  identical "/a/a" &&

  identical "/;a;b" &&
  identical "/a;a;b" &&
  identical "/a/;a;b" &&
  identical "/a/a;a;b" &&

  identical "/?a=b&c=d" &&
  identical "/a?a=b&c=d" &&
  identical "/a/?a=b&c=d" &&
  identical "/a/a?a=b&c=d" &&

  identical "/;a;b?a=b&c=d" &&
  identical "/a;a;b?a=b&c=d" &&
  identical "/a/;a;b?a=b&c=d" &&
  identical "/a/a;a;b?a=b&c=d" &&

  identical "/#f" &&
  identical "/a#f" &&
  identical "/a/#f" &&
  identical "/a/a#f" &&

  identical "/;a;b#f" &&
  identical "/a;a;b#f" &&
  identical "/a/;a;b#f" &&
  identical "/a/a;a;b#f" &&

  identical "/;a;b?a=b&c=d#f" &&
  identical "/a;a;b?a=b&c=d#f" &&
  identical "/a/;a;b?a=b&c=d#f" &&
  identical "/a/a;a;b?a=b&c=d#f" &&

  identical "" &&
  identical "a" &&
  identical "a/" &&
  identical "a/a" &&

  identical ";a;b" &&
  identical "a;a;b" &&
  identical "a/;a;b" &&
  identical "a/a;a;b" &&

  identical "?a=b&c=d" &&
  identical "a?a=b&c=d" &&
  identical "a/?a=b&c=d" &&
  identical "a/a?a=b&c=d" &&

  identical ";a;b?a=b&c=d" &&
  identical "a;a;b?a=b&c=d" &&
  identical "a/;a;b?a=b&c=d" &&
  identical "a/a;a;b?a=b&c=d" &&

  identical "#f" &&
  identical "a#f" &&
  identical "a/#f" &&
  identical "a/a#f" &&

  identical ";a;b#f" &&
  identical "a;a;b#f" &&
  identical "a/;a;b#f" &&
  identical "a/a;a;b#f" &&

  identical ";a;b?a=b&c=d#f" &&
  identical "a;a;b?a=b&c=d#f" &&
  identical "a/;a;b?a=b&c=d#f" &&
  identical "a/a;a;b?a=b&c=d#f" &&

  identical "." &&
  identical "./" &&
  identical "./a" &&

  identical ".;a;b" &&
  identical "./;a;b" &&
  identical "./a;a;b" &&

  identical ".?a=b&c=d" &&
  identical "./?a=b&c=d" &&
  identical "./a?a=b&c=d" &&

  identical ".;a;b?a=b&c=d" &&
  identical "./;a;b?a=b&c=d" &&
  identical "./a;a;b?a=b&c=d" &&

  identical ".#f" &&
  identical "./#f" &&
  identical "./a#f" &&

  identical ".;a;b#f" &&
  identical "./;a;b#f" &&
  identical "./a;a;b#f" &&

  identical ".;a;b?a=b&c=d#f" &&
  identical "./;a;b?a=b&c=d#f" &&
  identical "./a;a;b?a=b&c=d#f" &&

  identical ".." &&
  identical "../" &&
  identical "../a" &&

  identical "..;a;b" &&
  identical "../;a;b" &&
  identical "../a;a;b" &&

  identical "..?a=b&c=d" &&
  identical "../?a=b&c=d" &&
  identical "../a?a=b&c=d" &&

  identical "..;a;b?a=b&c=d" &&
  identical "../;a;b?a=b&c=d" &&
  identical "../a;a;b?a=b&c=d" &&

  identical "..#f" &&
  identical "../#f" &&
  identical "../a#f" &&

  identical "..;a;b#f" &&
  identical "../;a;b#f" &&
  identical "../a;a;b#f" &&

  identical "..;a;b?a=b&c=d#f" &&
  identical "../;a;b?a=b&c=d#f" &&
  identical "../a;a;b?a=b&c=d#f" &&

  string_of_url
    (make_url ~path:["a:b"] ip_url_syntax) = "a%3Ab" &&

  string_of_url
    (make_url ~encoded:true ~path:["a:b"] ip_url_syntax) = "./a:b" &&

  true
;;


let t052 () =
  (* mailto: URLs *)
  let mailto_syn = Hashtbl.find common_url_syntax "mailto" in

  let identical s =
    string_of_url (url_of_string mailto_syn s) = s in

  let fails s =
    try ignore(url_of_string mailto_syn s); false 
    with Malformed_URL -> true
  in

  identical "mailto:user@host" &&
  identical "mailto:user@host;?;?" &&
  fails     "mailto:user@host#f"
;;

(**********************************************************************)
(* split_path/join_path/norm_path:                                    *)
(**********************************************************************)

let t060 () =
  (split_path "" = []) &&
  (split_path "/" = [ "" ]) &&
  (split_path "/a" = [ ""; "a" ]) &&
  (split_path "a" = [ "a" ]) &&
  (split_path "a/" = [ "a"; "" ]) &&
  (split_path "/a/" = [ ""; "a"; "" ]) &&
  (split_path "/a/b" = [ ""; "a"; "b" ]) &&
  (split_path "/a/b/" = [ ""; "a"; "b"; "" ]) &&
  (split_path "/a/b/c" = [ ""; "a"; "b"; "c" ]) &&

  (join_path [] = "") &&
  (join_path [ "" ] = "/") &&
  (join_path [ ""; "a" ] = "/a") &&
  (join_path [ "a" ] = "a") &&
  (join_path [ "a"; "" ] = "a/") &&
  (join_path [ ""; "a"; "" ] = "/a/") &&
  (join_path [ ""; "a"; "b" ] = "/a/b") &&
  (join_path [ ""; "a"; "b"; "" ] = "/a/b/") &&
  (join_path [ ""; "a"; "b"; "c" ] = "/a/b/c") &&

  true
;;


let t061 () =
  (norm_path ["."] = []) &&
  (norm_path ["."; ""] = []) &&
  (norm_path ["a"; "."] = ["a"; ""]) &&
  (norm_path ["a"; "b"; "."] = ["a"; "b"; ""]) &&
  (norm_path ["a"; "b"; ".."] = ["a"; ""]) &&
  (norm_path ["a"; "."; "b"; "."] = ["a"; "b"; ""]) &&
  (norm_path [".."] = [".."; ""]) &&
  (norm_path [".."; ""] = [".."; ""]) &&
  (norm_path ["a"; "b"; ".."; "c" ] = ["a"; "c"]) &&
  (norm_path ["a"; "b"; ".."; "c"; ""] = ["a"; "c"; ""]) &&
  (norm_path ["";"";"a";"";"b"] = [""; "a"; "b"]) &&
  (norm_path ["a"; "b"; ""; ".."; "c"; ""] = ["a"; "c"; ""]) &&
  (norm_path ["a"; ".."] = []) &&
  (norm_path ["";""] = [""]) &&
  (norm_path [""] = [""]) &&
  (norm_path [] = []) &&

  true
;;
		  
(**********************************************************************)
(* apply_relative_url:                                                *)
(**********************************************************************)

let t070() =
  (* Examples taken from RFC 1808 *)
  let url = url_of_string ip_url_syntax in
  let base = url "http://a/b/c/d;p?q#f" in
  let aru = apply_relative_url base in

  (aru (url "g:h")     = url "g:h") &&
  (aru (url "g")       = url "http://a/b/c/g") &&
  (aru (url "./g")     = url "http://a/b/c/g") &&
  (aru (url "g/")      = url "http://a/b/c/g/") &&
  (aru (url "/g")      = url "http://a/g") &&
  (aru (url "//g")     = url "http://g") &&
  (aru (url "?y")      = url "http://a/b/c/d;p?y") &&
  (aru (url "g?y")     = url "http://a/b/c/g?y") &&
  (aru (url "g?y/./x") = url "http://a/b/c/g?y/./x") &&
  (aru (url "#s")      = url "http://a/b/c/d;p?q#s") &&
  (aru (url "g#s")     = url "http://a/b/c/g#s") &&
  (aru (url "g#s/./x") = url "http://a/b/c/g#s/./x") &&
  (aru (url "g?y#s")   = url "http://a/b/c/g?y#s") &&
  (aru (url ";x")      = url "http://a/b/c/d;x") &&
  (aru (url "g;x")     = url "http://a/b/c/g;x") &&
  (aru (url "g;x?y#s") = url "http://a/b/c/g;x?y#s") &&
  (aru (url ".")       = url "http://a/b/c/") &&
  (aru (url "./")      = url "http://a/b/c/") &&
  (aru (url "..")      = url "http://a/b/") &&
  (aru (url "../")     = url "http://a/b/") &&
  (aru (url "../g")    = url "http://a/b/g") &&
  (aru (url "../..")   = url "http://a/") &&
  (aru (url "../../")  = url "http://a/") &&
  (aru (url "../../g") = url "http://a/g") &&

  (aru (url "")              = url "http://a/b/c/d;p?q#f") &&
  (aru (url "../../../g")    = url "http://a/../g") &&
  (aru (url "../../../../g") = url "http://a/../../g") &&
  (aru (url "/./g")          = url "http://a/./g") &&
  (aru (url "/../g")         = url "http://a/../g") &&
  (aru (url "g.")            = url "http://a/b/c/g.") &&
  (aru (url ".g")            = url "http://a/b/c/.g") &&
  (aru (url "g..")           = url "http://a/b/c/g..") &&
  (aru (url "..g")           = url "http://a/b/c/..g") &&
  (aru (url "./../g")        = url "http://a/b/g") &&
  (aru (url "./g/.")         = url "http://a/b/c/g/") &&
  (aru (url "g/./h")         = url "http://a/b/c/g/h") &&
  (aru (url "g/../h")        = url "http://a/b/c/h") &&
  (aru (url "http:g")        = url "http:g") &&
  (aru (url "http:")         = url "http:") &&

  true
;;
  

(**********************************************************************)

let test f n =
  if f() then
    print_endline ("Test " ^ n ^ " ok")
  else 
    print_endline ("Test " ^ n ^ " FAILED!!!!");
  flush stdout
;;

test t001 "001";
test t002 "002";

test t010 "010";
test t011 "011";
test t012 "012";

test t020 "020";
test t021 "021";

test t030 "030";
test t031 "031";
test t032 "032";
test t033 "033";
test t034 "034";
test t035 "035";
test t036 "036";
test t037 "037";
test t038 "038";

test t050 "050";
test t051 "051";
test t052 "052";

test t060 "060";
test t061 "061";

test t070 "070";
()
;;