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