]>
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
);
15 EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string
)U
);
17 U
= URI("http://jgg:foo@ualberta.ca/blah");
18 EXPECT_EQ("http", U
.Access
);
19 EXPECT_EQ("jgg", U
.User
);
20 EXPECT_EQ("foo", U
.Password
);
22 EXPECT_EQ("ualberta.ca", U
.Host
);
23 EXPECT_EQ("/blah", U
.Path
);
24 EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string
)U
);
26 TEST(URITest
, SingeSlashFile
)
28 URI
U("file:/usr/bin/foo");
29 EXPECT_EQ("file", U
.Access
);
30 EXPECT_EQ("", U
.User
);
31 EXPECT_EQ("", U
.Password
);
33 EXPECT_EQ("", U
.Host
);
34 EXPECT_EQ("/usr/bin/foo", U
.Path
);
35 EXPECT_EQ("file:/usr/bin/foo", (std::string
)U
);
37 TEST(URITest
, BasicCDROM
)
39 URI
U("cdrom:Moo Cow Rom:/debian");
40 EXPECT_EQ("cdrom", U
.Access
);
41 EXPECT_EQ("", U
.User
);
42 EXPECT_EQ("", U
.Password
);
44 EXPECT_EQ("Moo Cow Rom", U
.Host
);
45 EXPECT_EQ("/debian", U
.Path
);
46 EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string
)U
);
48 TEST(URITest
, RelativeGzip
)
50 URI
U("gzip:./bar/cow");
51 EXPECT_EQ("gzip", U
.Access
);
52 EXPECT_EQ("", U
.User
);
53 EXPECT_EQ("", U
.Password
);
55 EXPECT_EQ(".", U
.Host
);
56 EXPECT_EQ("/bar/cow", U
.Path
);
57 EXPECT_EQ("gzip://./bar/cow", (std::string
)U
);
59 TEST(URITest
, NoSlashFTP
)
61 URI
U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
62 EXPECT_EQ("ftp", U
.Access
);
63 EXPECT_EQ("", U
.User
);
64 EXPECT_EQ("", U
.Password
);
66 EXPECT_EQ("ftp.fr.debian.org", U
.Host
);
67 EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U
.Path
);
68 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string
)U
);
70 TEST(URITest
, RFC2732
)
72 URI
U("http://[1080::8:800:200C:417A]/foo");
73 EXPECT_EQ("http", U
.Access
);
74 EXPECT_EQ("", U
.User
);
75 EXPECT_EQ("", U
.Password
);
77 EXPECT_EQ("1080::8:800:200C:417A", U
.Host
);
78 EXPECT_EQ("/foo", U
.Path
);
79 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string
)U
);
81 U
= URI("http://[::FFFF:129.144.52.38]:80/index.html");
82 EXPECT_EQ("http", U
.Access
);
83 EXPECT_EQ("", U
.User
);
84 EXPECT_EQ("", U
.Password
);
85 EXPECT_EQ(80, U
.Port
);
86 EXPECT_EQ("::FFFF:129.144.52.38", U
.Host
);
87 EXPECT_EQ("/index.html", U
.Path
);
88 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string
)U
);
90 U
= URI("http://[::FFFF:129.144.52.38:]:80/index.html");
91 EXPECT_EQ("http", U
.Access
);
92 EXPECT_EQ("", U
.User
);
93 EXPECT_EQ("", U
.Password
);
94 EXPECT_EQ(80, U
.Port
);
95 EXPECT_EQ("::FFFF:129.144.52.38:", U
.Host
);
96 EXPECT_EQ("/index.html", U
.Path
);
97 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string
)U
);
99 U
= URI("http://[::FFFF:129.144.52.38:]/index.html");
100 EXPECT_EQ("http", U
.Access
);
101 EXPECT_EQ("", U
.User
);
102 EXPECT_EQ("", U
.Password
);
103 EXPECT_EQ(0, U
.Port
);
104 EXPECT_EQ("::FFFF:129.144.52.38:", U
.Host
);
105 EXPECT_EQ("/index.html", U
.Path
);
106 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string
)U
);
107 // My Evil Corruption of RFC 2732 to handle CDROM names!
108 // Fun for the whole family! */
109 U
= URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
110 EXPECT_EQ("cdrom", U
.Access
);
111 EXPECT_EQ("", U
.User
);
112 EXPECT_EQ("", U
.Password
);
113 EXPECT_EQ(0, U
.Port
);
114 EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U
.Host
);
115 EXPECT_EQ("/debian/", U
.Path
);
116 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string
)U
);
118 U
= URI("cdrom:Foo Bar Cow/debian/");
119 EXPECT_EQ("cdrom", U
.Access
);
120 EXPECT_EQ("", U
.User
);
121 EXPECT_EQ("", U
.Password
);
122 EXPECT_EQ(0, U
.Port
);
123 EXPECT_EQ("Foo Bar Cow", U
.Host
);
124 EXPECT_EQ("/debian/", U
.Path
);
125 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string
)U
);
127 U
= URI("ftp://foo:b%40r@example.org");
128 EXPECT_EQ("foo", U
.User
);
129 EXPECT_EQ("b@r", U
.Password
);
130 EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string
) U
);