]>
git.saurik.com Git - apt.git/blob - test/libapt/uri_test.cc
2 #include <apt-pkg/strutl.h>
4 #include <gtest/gtest.h>
6 TEST(URITest
, BasicHTTP
)
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
);
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
);
21 EXPECT_EQ("ualberta.ca", U
.Host
);
22 EXPECT_EQ("/blah", U
.Path
);
24 TEST(URITest
, SingeSlashFile
)
26 URI
U("file:/usr/bin/foo");
27 EXPECT_EQ("file", U
.Access
);
28 EXPECT_EQ("", U
.User
);
29 EXPECT_EQ("", U
.Password
);
31 EXPECT_EQ("", U
.Host
);
32 EXPECT_EQ("/usr/bin/foo", U
.Path
);
34 TEST(URITest
, BasicCDROM
)
36 URI
U("cdrom:Moo Cow Rom:/debian");
37 EXPECT_EQ("cdrom", U
.Access
);
38 EXPECT_EQ("", U
.User
);
39 EXPECT_EQ("", U
.Password
);
41 EXPECT_EQ("Moo Cow Rom", U
.Host
);
42 EXPECT_EQ("/debian", U
.Path
);
44 TEST(URITest
, RelativeGzip
)
46 URI
U("gzip:./bar/cow");
47 EXPECT_EQ("gzip", U
.Access
);
48 EXPECT_EQ("", U
.User
);
49 EXPECT_EQ("", U
.Password
);
51 EXPECT_EQ(".", U
.Host
);
52 EXPECT_EQ("/bar/cow", U
.Path
);
54 TEST(URITest
, NoSlashFTP
)
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
);
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
);
64 TEST(URITest
, RFC2732
)
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
);
71 EXPECT_EQ("1080::8:800:200C:417A", U
.Host
);
72 EXPECT_EQ("/foo", U
.Path
);
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
);
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
);
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
);
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
);
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
);
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
);