]> git.saurik.com Git - apt.git/blob - test/libapt/uri_test.cc
Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage
[apt.git] / test / libapt / uri_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/strutl.h>
4
5 #include <string>
6
7 #include "assert.h"
8
9 int main() {
10 // Basic stuff
11 {
12 URI U("http://www.debian.org:90/temp/test");
13 equals("http", U.Access);
14 equals("", U.User);
15 equals("", U.Password);
16 equals(90, U.Port);
17 equals("www.debian.org", U.Host);
18 equals("/temp/test", U.Path);
19 } {
20 URI U("http://jgg:foo@ualberta.ca/blah");
21 equals("http", U.Access);
22 equals("jgg", U.User);
23 equals("foo", U.Password);
24 equals(0, U.Port);
25 equals("ualberta.ca", U.Host);
26 equals("/blah", U.Path);
27 } {
28 URI U("file:/usr/bin/foo");
29 equals("file", U.Access);
30 equals("", U.User);
31 equals("", U.Password);
32 equals(0, U.Port);
33 equals("", U.Host);
34 equals("/usr/bin/foo", U.Path);
35 } {
36 URI U("cdrom:Moo Cow Rom:/debian");
37 equals("cdrom", U.Access);
38 equals("", U.User);
39 equals("", U.Password);
40 equals(0, U.Port);
41 equals("Moo Cow Rom", U.Host);
42 equals("/debian", U.Path);
43 } {
44 URI U("gzip:./bar/cow");
45 equals("gzip", U.Access);
46 equals("", U.User);
47 equals("", U.Password);
48 equals(0, U.Port);
49 equals(".", U.Host);
50 equals("/bar/cow", U.Path);
51 } {
52 URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
53 equals("ftp", U.Access);
54 equals("", U.User);
55 equals("", U.Password);
56 equals(0, U.Port);
57 equals("ftp.fr.debian.org", U.Host);
58 equals("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
59 }
60
61 // RFC 2732 stuff
62 {
63 URI U("http://[1080::8:800:200C:417A]/foo");
64 equals("http", U.Access);
65 equals("", U.User);
66 equals("", U.Password);
67 equals(0, U.Port);
68 equals("1080::8:800:200C:417A", U.Host);
69 equals("/foo", U.Path);
70 } {
71 URI U("http://[::FFFF:129.144.52.38]:80/index.html");
72 equals("http", U.Access);
73 equals("", U.User);
74 equals("", U.Password);
75 equals(80, U.Port);
76 equals("::FFFF:129.144.52.38", U.Host);
77 equals("/index.html", U.Path);
78 } {
79 URI U("http://[::FFFF:129.144.52.38:]:80/index.html");
80 equals("http", U.Access);
81 equals("", U.User);
82 equals("", U.Password);
83 equals(80, U.Port);
84 equals("::FFFF:129.144.52.38:", U.Host);
85 equals("/index.html", U.Path);
86 } {
87 URI U("http://[::FFFF:129.144.52.38:]/index.html");
88 equals("http", U.Access);
89 equals("", U.User);
90 equals("", U.Password);
91 equals(0, U.Port);
92 equals("::FFFF:129.144.52.38:", U.Host);
93 equals("/index.html", U.Path);
94 }
95 /* My Evil Corruption of RFC 2732 to handle CDROM names! Fun for
96 the whole family! */
97 {
98 URI U("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
99 equals("cdrom", U.Access);
100 equals("", U.User);
101 equals("", U.Password);
102 equals(0, U.Port);
103 equals("The Debian 1.2 disk, 1/2 R1:6", U.Host);
104 equals("/debian/", U.Path);
105 } {
106 URI U("cdrom:Foo Bar Cow/debian/");
107 equals("cdrom", U.Access);
108 equals("", U.User);
109 equals("", U.Password);
110 equals(0, U.Port);
111 equals("Foo Bar Cow", U.Host);
112 equals("/debian/", U.Path);
113 }
114
115 // Percent-encoding.
116 {
117 URI U("ftp://foo:b%40r@example.org");
118 equals("foo", U.User);
119 equals("b@r", U.Password);
120 equals("ftp://foo:b%40r@example.org/", (std::string) U);
121 }
122
123 return 0;
124 }