]> git.saurik.com Git - apt.git/blob - test/libapt/uri_test.cc
accept ../ on the cmdline as start for a deb file as well
[apt.git] / test / libapt / uri_test.cc
1 #include <config.h>
2 #include <apt-pkg/strutl.h>
3 #include <string>
4 #include <gtest/gtest.h>
5
6 TEST(URITest, BasicHTTP)
7 {
8 URI U("http://www.debian.org:90/temp/test");
9 EXPECT_EQ("http", U.Access);
10 EXPECT_EQ("", U.User);
11 EXPECT_EQ("", U.Password);
12 EXPECT_EQ(90, U.Port);
13 EXPECT_EQ("www.debian.org", U.Host);
14 EXPECT_EQ("/temp/test", U.Path);
15 EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string)U);
16 EXPECT_EQ("http://www.debian.org:90", URI::SiteOnly(U));
17 EXPECT_EQ("http://www.debian.org:90/temp/test", URI::ArchiveOnly(U));
18 EXPECT_EQ("http://www.debian.org:90/temp/test", URI::NoUserPassword(U));
19 // Login data
20 U = URI("http://jgg:foo@ualberta.ca/blah");
21 EXPECT_EQ("http", U.Access);
22 EXPECT_EQ("jgg", U.User);
23 EXPECT_EQ("foo", U.Password);
24 EXPECT_EQ(0, U.Port);
25 EXPECT_EQ("ualberta.ca", U.Host);
26 EXPECT_EQ("/blah", U.Path);
27 EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string)U);
28 EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U));
29 EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U));
30 EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U));
31 }
32 TEST(URITest, SingeSlashFile)
33 {
34 URI U("file:/usr/bin/foo");
35 EXPECT_EQ("file", U.Access);
36 EXPECT_EQ("", U.User);
37 EXPECT_EQ("", U.Password);
38 EXPECT_EQ(0, U.Port);
39 EXPECT_EQ("", U.Host);
40 EXPECT_EQ("/usr/bin/foo", U.Path);
41 EXPECT_EQ("file:/usr/bin/foo", (std::string)U);
42 EXPECT_EQ("file:", URI::SiteOnly(U));
43 EXPECT_EQ("file:/usr/bin/foo", URI::ArchiveOnly(U));
44 EXPECT_EQ("file:/usr/bin/foo", URI::NoUserPassword(U));
45 }
46 TEST(URITest, BasicCDROM)
47 {
48 URI U("cdrom:Moo Cow Rom:/debian");
49 EXPECT_EQ("cdrom", U.Access);
50 EXPECT_EQ("", U.User);
51 EXPECT_EQ("", U.Password);
52 EXPECT_EQ(0, U.Port);
53 EXPECT_EQ("Moo Cow Rom", U.Host);
54 EXPECT_EQ("/debian", U.Path);
55 EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string)U);
56 EXPECT_EQ("cdrom://Moo Cow Rom", URI::SiteOnly(U));
57 EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::ArchiveOnly(U));
58 EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::NoUserPassword(U));
59 }
60 TEST(URITest, RelativeGzip)
61 {
62 URI U("gzip:./bar/cow");
63 EXPECT_EQ("gzip", U.Access);
64 EXPECT_EQ("", U.User);
65 EXPECT_EQ("", U.Password);
66 EXPECT_EQ(0, U.Port);
67 EXPECT_EQ(".", U.Host);
68 EXPECT_EQ("/bar/cow", U.Path);
69 EXPECT_EQ("gzip://./bar/cow", (std::string)U);
70 EXPECT_EQ("gzip://.", URI::SiteOnly(U));
71 EXPECT_EQ("gzip://./bar/cow", URI::ArchiveOnly(U));
72 EXPECT_EQ("gzip://./bar/cow", URI::NoUserPassword(U));
73 }
74 TEST(URITest, NoSlashFTP)
75 {
76 URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
77 EXPECT_EQ("ftp", U.Access);
78 EXPECT_EQ("", U.User);
79 EXPECT_EQ("", U.Password);
80 EXPECT_EQ(0, U.Port);
81 EXPECT_EQ("ftp.fr.debian.org", U.Host);
82 EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
83 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string)U);
84 EXPECT_EQ("ftp://ftp.fr.debian.org", URI::SiteOnly(U));
85 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::ArchiveOnly(U));
86 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::NoUserPassword(U));
87 }
88 TEST(URITest, RFC2732)
89 {
90 URI U("http://[1080::8:800:200C:417A]/foo");
91 EXPECT_EQ("http", U.Access);
92 EXPECT_EQ("", U.User);
93 EXPECT_EQ("", U.Password);
94 EXPECT_EQ(0, U.Port);
95 EXPECT_EQ("1080::8:800:200C:417A", U.Host);
96 EXPECT_EQ("/foo", U.Path);
97 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string)U);
98 EXPECT_EQ("http://[1080::8:800:200C:417A]", URI::SiteOnly(U));
99 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::ArchiveOnly(U));
100 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::NoUserPassword(U));
101 // with port
102 U = URI("http://[::FFFF:129.144.52.38]:80/index.html");
103 EXPECT_EQ("http", U.Access);
104 EXPECT_EQ("", U.User);
105 EXPECT_EQ("", U.Password);
106 EXPECT_EQ(80, U.Port);
107 EXPECT_EQ("::FFFF:129.144.52.38", U.Host);
108 EXPECT_EQ("/index.html", U.Path);
109 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string)U);
110 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80", URI::SiteOnly(U));
111 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::ArchiveOnly(U));
112 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::NoUserPassword(U));
113 // extra colon
114 U = URI("http://[::FFFF:129.144.52.38:]:80/index.html");
115 EXPECT_EQ("http", U.Access);
116 EXPECT_EQ("", U.User);
117 EXPECT_EQ("", U.Password);
118 EXPECT_EQ(80, U.Port);
119 EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
120 EXPECT_EQ("/index.html", U.Path);
121 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string)U);
122 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80", URI::SiteOnly(U));
123 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::ArchiveOnly(U));
124 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::NoUserPassword(U));
125 // extra colon port
126 U = URI("http://[::FFFF:129.144.52.38:]/index.html");
127 EXPECT_EQ("http", U.Access);
128 EXPECT_EQ("", U.User);
129 EXPECT_EQ("", U.Password);
130 EXPECT_EQ(0, U.Port);
131 EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
132 EXPECT_EQ("/index.html", U.Path);
133 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string)U);
134 EXPECT_EQ("http://[::FFFF:129.144.52.38:]", URI::SiteOnly(U));
135 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::ArchiveOnly(U));
136 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::NoUserPassword(U));
137 // My Evil Corruption of RFC 2732 to handle CDROM names!
138 // Fun for the whole family! */
139 U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
140 EXPECT_EQ("cdrom", U.Access);
141 EXPECT_EQ("", U.User);
142 EXPECT_EQ("", U.Password);
143 EXPECT_EQ(0, U.Port);
144 EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host);
145 EXPECT_EQ("/debian/", U.Path);
146 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string)U);
147 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]", URI::SiteOnly(U));
148 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian", URI::ArchiveOnly(U));
149 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", URI::NoUserPassword(U));
150 // no brackets
151 U = URI("cdrom:Foo Bar Cow/debian/");
152 EXPECT_EQ("cdrom", U.Access);
153 EXPECT_EQ("", U.User);
154 EXPECT_EQ("", U.Password);
155 EXPECT_EQ(0, U.Port);
156 EXPECT_EQ("Foo Bar Cow", U.Host);
157 EXPECT_EQ("/debian/", U.Path);
158 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string)U);
159 EXPECT_EQ("cdrom://Foo Bar Cow", URI::SiteOnly(U));
160 EXPECT_EQ("cdrom://Foo Bar Cow/debian", URI::ArchiveOnly(U));
161 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", URI::NoUserPassword(U));
162 // percent encoded
163 U = URI("ftp://foo:b%40r@example.org");
164 EXPECT_EQ("foo", U.User);
165 EXPECT_EQ("b@r", U.Password);
166 EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string) U);
167 EXPECT_EQ("ftp://example.org", URI::SiteOnly(U));
168 EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U));
169 EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U));
170 }