]> git.saurik.com Git - apt.git/blame - test/libapt/uri_test.cc
rename Calculate- to GetIndexTargets and use it as official API
[apt.git] / test / libapt / uri_test.cc
CommitLineData
453b82a3 1#include <config.h>
bf5438c1 2#include <apt-pkg/strutl.h>
453b82a3 3#include <string>
f00832cc 4#include <gtest/gtest.h>
453b82a3 5
f00832cc
DK
6TEST(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);
b8eba208 15 EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string)U);
f00832cc
DK
16 // Login data
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);
21 EXPECT_EQ(0, U.Port);
22 EXPECT_EQ("ualberta.ca", U.Host);
23 EXPECT_EQ("/blah", U.Path);
b8eba208 24 EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string)U);
f00832cc
DK
25}
26TEST(URITest, SingeSlashFile)
27{
28 URI U("file:/usr/bin/foo");
29 EXPECT_EQ("file", U.Access);
30 EXPECT_EQ("", U.User);
31 EXPECT_EQ("", U.Password);
32 EXPECT_EQ(0, U.Port);
33 EXPECT_EQ("", U.Host);
34 EXPECT_EQ("/usr/bin/foo", U.Path);
b8eba208 35 EXPECT_EQ("file:/usr/bin/foo", (std::string)U);
f00832cc
DK
36}
37TEST(URITest, BasicCDROM)
38{
39 URI U("cdrom:Moo Cow Rom:/debian");
40 EXPECT_EQ("cdrom", U.Access);
41 EXPECT_EQ("", U.User);
42 EXPECT_EQ("", U.Password);
43 EXPECT_EQ(0, U.Port);
44 EXPECT_EQ("Moo Cow Rom", U.Host);
45 EXPECT_EQ("/debian", U.Path);
b8eba208 46 EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string)U);
f00832cc
DK
47}
48TEST(URITest, RelativeGzip)
49{
50 URI U("gzip:./bar/cow");
51 EXPECT_EQ("gzip", U.Access);
52 EXPECT_EQ("", U.User);
53 EXPECT_EQ("", U.Password);
54 EXPECT_EQ(0, U.Port);
55 EXPECT_EQ(".", U.Host);
56 EXPECT_EQ("/bar/cow", U.Path);
b8eba208 57 EXPECT_EQ("gzip://./bar/cow", (std::string)U);
f00832cc
DK
58}
59TEST(URITest, NoSlashFTP)
60{
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);
65 EXPECT_EQ(0, U.Port);
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);
b8eba208 68 EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string)U);
f00832cc
DK
69}
70TEST(URITest, RFC2732)
71{
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);
76 EXPECT_EQ(0, U.Port);
77 EXPECT_EQ("1080::8:800:200C:417A", U.Host);
78 EXPECT_EQ("/foo", U.Path);
b8eba208 79 EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string)U);
f00832cc
DK
80 // with port
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);
b8eba208 88 EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string)U);
f00832cc
DK
89 // extra colon
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);
b8eba208 97 EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string)U);
f00832cc
DK
98 // extra colon port
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);
b8eba208 106 EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string)U);
f00832cc
DK
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);
b8eba208 116 EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string)U);
f00832cc
DK
117 // no brackets
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);
b8eba208 125 EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string)U);
f00832cc
DK
126 // percent encoded
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);
bf5438c1 131}