1 | #include "lldb/Utility/UriParser.h" |
2 | #include "gtest/gtest.h" |
3 | |
4 | using namespace lldb_private; |
5 | |
6 | TEST(UriParserTest, Minimal) { |
7 | EXPECT_EQ((URI{"x" , "y" , std::nullopt, "/" }), URI::Parse("x://y" )); |
8 | } |
9 | |
10 | TEST(UriParserTest, MinimalPort) { |
11 | EXPECT_EQ((URI{"x" , "y" , 1, "/" }), URI::Parse("x://y:1" )); |
12 | } |
13 | |
14 | TEST(UriParserTest, MinimalPath) { |
15 | EXPECT_EQ((URI{"x" , "y" , std::nullopt, "/" }), URI::Parse("x://y/" )); |
16 | } |
17 | |
18 | TEST(UriParserTest, MinimalPortPath) { |
19 | EXPECT_EQ((URI{"x" , "y" , 1, "/" }), URI::Parse("x://y:1/" )); |
20 | } |
21 | |
22 | TEST(UriParserTest, LongPath) { |
23 | EXPECT_EQ((URI{"x" , "y" , std::nullopt, "/abc/def/xyz" }), |
24 | URI::Parse("x://y/abc/def/xyz" )); |
25 | } |
26 | |
27 | TEST(UriParserTest, TypicalPortPathIPv4) { |
28 | EXPECT_EQ((URI{"connect" , "192.168.100.132" , 5432, "/" }), |
29 | URI::Parse("connect://192.168.100.132:5432/" )); |
30 | } |
31 | |
32 | TEST(UriParserTest, TypicalPortPathIPv6) { |
33 | EXPECT_EQ( |
34 | (URI{"connect" , "2601:600:107f:db64:a42b:4faa:284:3082" , 5432, "/" }), |
35 | URI::Parse("connect://[2601:600:107f:db64:a42b:4faa:284:3082]:5432/" )); |
36 | } |
37 | |
38 | TEST(UriParserTest, BracketedHostnamePort) { |
39 | EXPECT_EQ((URI{"connect" , "192.168.100.132" , 5432, "/" }), |
40 | URI::Parse("connect://[192.168.100.132]:5432/" )); |
41 | } |
42 | |
43 | TEST(UriParserTest, BracketedHostname) { |
44 | EXPECT_EQ((URI{"connect" , "192.168.100.132" , std::nullopt, "/" }), |
45 | URI::Parse("connect://[192.168.100.132]" )); |
46 | } |
47 | |
48 | TEST(UriParserTest, BracketedHostnameWithPortIPv4) { |
49 | // Android device over IPv4: port is a part of the hostname. |
50 | EXPECT_EQ((URI{"connect" , "192.168.100.132:1234" , std::nullopt, "/" }), |
51 | URI::Parse("connect://[192.168.100.132:1234]" )); |
52 | } |
53 | |
54 | TEST(UriParserTest, BracketedHostnameWithPortIPv6) { |
55 | // Android device over IPv6: port is a part of the hostname. |
56 | EXPECT_EQ((URI{"connect" , "[2601:600:107f:db64:a42b:4faa:284]:1234" , |
57 | std::nullopt, "/" }), |
58 | URI::Parse("connect://[[2601:600:107f:db64:a42b:4faa:284]:1234]" )); |
59 | } |
60 | |
61 | TEST(UriParserTest, BracketedHostnameWithColon) { |
62 | EXPECT_EQ((URI{"connect" , "192.168.100.132:5555" , 1234, "/" }), |
63 | URI::Parse("connect://[192.168.100.132:5555]:1234" )); |
64 | } |
65 | |
66 | TEST(UriParserTest, SchemeHostSeparator) { |
67 | EXPECT_EQ(std::nullopt, URI::Parse("x:/y" )); |
68 | } |
69 | |
70 | TEST(UriParserTest, SchemeHostSeparator2) { |
71 | EXPECT_EQ(std::nullopt, URI::Parse("x:y" )); |
72 | } |
73 | |
74 | TEST(UriParserTest, SchemeHostSeparator3) { |
75 | EXPECT_EQ(std::nullopt, URI::Parse("x//y" )); |
76 | } |
77 | |
78 | TEST(UriParserTest, SchemeHostSeparator4) { |
79 | EXPECT_EQ(std::nullopt, URI::Parse("x/y" )); |
80 | } |
81 | |
82 | TEST(UriParserTest, BadPort) { |
83 | EXPECT_EQ(std::nullopt, URI::Parse("x://y:a/" )); |
84 | } |
85 | |
86 | TEST(UriParserTest, BadPort2) { |
87 | EXPECT_EQ(std::nullopt, URI::Parse("x://y:5432a/" )); |
88 | } |
89 | |
90 | TEST(UriParserTest, Empty) { EXPECT_EQ(std::nullopt, URI::Parse("" )); } |
91 | |
92 | TEST(UriParserTest, PortOverflow) { |
93 | EXPECT_EQ(std::nullopt, |
94 | URI::Parse("x://" |
95 | "y:" |
96 | "0123456789012345678901234567890123456789012345678" |
97 | "9012345678901234567890123456789012345678901234567" |
98 | "89/" )); |
99 | } |
100 | |