1 #include "lldb/Utility/UriParser.h"
2 #include "gtest/gtest.h"
4 using namespace lldb_private
;
6 TEST(UriParserTest
, Minimal
) {
7 EXPECT_EQ((URI
{"x", "y", std::nullopt
, "/"}), URI::Parse("x://y"));
10 TEST(UriParserTest
, MinimalPort
) {
11 EXPECT_EQ((URI
{"x", "y", 1, "/"}), URI::Parse("x://y:1"));
14 TEST(UriParserTest
, MinimalPath
) {
15 EXPECT_EQ((URI
{"x", "y", std::nullopt
, "/"}), URI::Parse("x://y/"));
18 TEST(UriParserTest
, MinimalPortPath
) {
19 EXPECT_EQ((URI
{"x", "y", 1, "/"}), URI::Parse("x://y:1/"));
22 TEST(UriParserTest
, LongPath
) {
23 EXPECT_EQ((URI
{"x", "y", std::nullopt
, "/abc/def/xyz"}),
24 URI::Parse("x://y/abc/def/xyz"));
27 TEST(UriParserTest
, TypicalPortPathIPv4
) {
28 EXPECT_EQ((URI
{"connect", "192.168.100.132", 5432, "/"}),
29 URI::Parse("connect://192.168.100.132:5432/"));
32 TEST(UriParserTest
, TypicalPortPathIPv6
) {
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/"));
38 TEST(UriParserTest
, BracketedHostnamePort
) {
39 EXPECT_EQ((URI
{"connect", "192.168.100.132", 5432, "/"}),
40 URI::Parse("connect://[192.168.100.132]:5432/"));
43 TEST(UriParserTest
, BracketedHostname
) {
44 EXPECT_EQ((URI
{"connect", "192.168.100.132", std::nullopt
, "/"}),
45 URI::Parse("connect://[192.168.100.132]"));
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]"));
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",
58 URI::Parse("connect://[[2601:600:107f:db64:a42b:4faa:284]:1234]"));
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"));
66 TEST(UriParserTest
, SchemeHostSeparator
) {
67 EXPECT_EQ(std::nullopt
, URI::Parse("x:/y"));
70 TEST(UriParserTest
, SchemeHostSeparator2
) {
71 EXPECT_EQ(std::nullopt
, URI::Parse("x:y"));
74 TEST(UriParserTest
, SchemeHostSeparator3
) {
75 EXPECT_EQ(std::nullopt
, URI::Parse("x//y"));
78 TEST(UriParserTest
, SchemeHostSeparator4
) {
79 EXPECT_EQ(std::nullopt
, URI::Parse("x/y"));
82 TEST(UriParserTest
, BadPort
) {
83 EXPECT_EQ(std::nullopt
, URI::Parse("x://y:a/"));
86 TEST(UriParserTest
, BadPort2
) {
87 EXPECT_EQ(std::nullopt
, URI::Parse("x://y:5432a/"));
90 TEST(UriParserTest
, Empty
) { EXPECT_EQ(std::nullopt
, URI::Parse("")); }
92 TEST(UriParserTest
, PortOverflow
) {
93 EXPECT_EQ(std::nullopt
,
96 "0123456789012345678901234567890123456789012345678"
97 "9012345678901234567890123456789012345678901234567"