]> git.saurik.com Git - apt.git/blob - test/libapt/uri_test.cc
deal with hashes in ftparchive more dynamic 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 // Login data
16 U = URI("http://jgg:foo@ualberta.ca/blah");
17 EXPECT_EQ("http", U.Access);
18 EXPECT_EQ("jgg", U.User);
19 EXPECT_EQ("foo", U.Password);
20 EXPECT_EQ(0, U.Port);
21 EXPECT_EQ("ualberta.ca", U.Host);
22 EXPECT_EQ("/blah", U.Path);
23 }
24 TEST(URITest, SingeSlashFile)
25 {
26 URI U("file:/usr/bin/foo");
27 EXPECT_EQ("file", U.Access);
28 EXPECT_EQ("", U.User);
29 EXPECT_EQ("", U.Password);
30 EXPECT_EQ(0, U.Port);
31 EXPECT_EQ("", U.Host);
32 EXPECT_EQ("/usr/bin/foo", U.Path);
33 }
34 TEST(URITest, BasicCDROM)
35 {
36 URI U("cdrom:Moo Cow Rom:/debian");
37 EXPECT_EQ("cdrom", U.Access);
38 EXPECT_EQ("", U.User);
39 EXPECT_EQ("", U.Password);
40 EXPECT_EQ(0, U.Port);
41 EXPECT_EQ("Moo Cow Rom", U.Host);
42 EXPECT_EQ("/debian", U.Path);
43 }
44 TEST(URITest, RelativeGzip)
45 {
46 URI U("gzip:./bar/cow");
47 EXPECT_EQ("gzip", U.Access);
48 EXPECT_EQ("", U.User);
49 EXPECT_EQ("", U.Password);
50 EXPECT_EQ(0, U.Port);
51 EXPECT_EQ(".", U.Host);
52 EXPECT_EQ("/bar/cow", U.Path);
53 }
54 TEST(URITest, NoSlashFTP)
55 {
56 URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
57 EXPECT_EQ("ftp", U.Access);
58 EXPECT_EQ("", U.User);
59 EXPECT_EQ("", U.Password);
60 EXPECT_EQ(0, U.Port);
61 EXPECT_EQ("ftp.fr.debian.org", U.Host);
62 EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
63 }
64 TEST(URITest, RFC2732)
65 {
66 URI U("http://[1080::8:800:200C:417A]/foo");
67 EXPECT_EQ("http", U.Access);
68 EXPECT_EQ("", U.User);
69 EXPECT_EQ("", U.Password);
70 EXPECT_EQ(0, U.Port);
71 EXPECT_EQ("1080::8:800:200C:417A", U.Host);
72 EXPECT_EQ("/foo", U.Path);
73 // with port
74 U = URI("http://[::FFFF:129.144.52.38]:80/index.html");
75 EXPECT_EQ("http", U.Access);
76 EXPECT_EQ("", U.User);
77 EXPECT_EQ("", U.Password);
78 EXPECT_EQ(80, U.Port);
79 EXPECT_EQ("::FFFF:129.144.52.38", U.Host);
80 EXPECT_EQ("/index.html", U.Path);
81 // extra colon
82 U = URI("http://[::FFFF:129.144.52.38:]:80/index.html");
83 EXPECT_EQ("http", U.Access);
84 EXPECT_EQ("", U.User);
85 EXPECT_EQ("", U.Password);
86 EXPECT_EQ(80, U.Port);
87 EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
88 EXPECT_EQ("/index.html", U.Path);
89 // extra colon port
90 U = URI("http://[::FFFF:129.144.52.38:]/index.html");
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("::FFFF:129.144.52.38:", U.Host);
96 EXPECT_EQ("/index.html", U.Path);
97 // My Evil Corruption of RFC 2732 to handle CDROM names!
98 // Fun for the whole family! */
99 U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
100 EXPECT_EQ("cdrom", U.Access);
101 EXPECT_EQ("", U.User);
102 EXPECT_EQ("", U.Password);
103 EXPECT_EQ(0, U.Port);
104 EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host);
105 EXPECT_EQ("/debian/", U.Path);
106 // no brackets
107 U = URI("cdrom:Foo Bar Cow/debian/");
108 EXPECT_EQ("cdrom", U.Access);
109 EXPECT_EQ("", U.User);
110 EXPECT_EQ("", U.Password);
111 EXPECT_EQ(0, U.Port);
112 EXPECT_EQ("Foo Bar Cow", U.Host);
113 EXPECT_EQ("/debian/", U.Path);
114 // percent encoded
115 U = URI("ftp://foo:b%40r@example.org");
116 EXPECT_EQ("foo", U.User);
117 EXPECT_EQ("b@r", U.Password);
118 EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string) U);
119 }