1#include "lldb/Utility/UriParser.h"
2#include "gtest/gtest.h"
3
4using namespace lldb_private;
5
6TEST(UriParserTest, Minimal) {
7 EXPECT_EQ((URI{"x", "y", std::nullopt, "/"}), URI::Parse("x://y"));
8}
9
10TEST(UriParserTest, MinimalPort) {
11 EXPECT_EQ((URI{"x", "y", 1, "/"}), URI::Parse("x://y:1"));
12}
13
14TEST(UriParserTest, MinimalPath) {
15 EXPECT_EQ((URI{"x", "y", std::nullopt, "/"}), URI::Parse("x://y/"));
16}
17
18TEST(UriParserTest, MinimalPortPath) {
19 EXPECT_EQ((URI{"x", "y", 1, "/"}), URI::Parse("x://y:1/"));
20}
21
22TEST(UriParserTest, LongPath) {
23 EXPECT_EQ((URI{"x", "y", std::nullopt, "/abc/def/xyz"}),
24 URI::Parse("x://y/abc/def/xyz"));
25}
26
27TEST(UriParserTest, TypicalPortPathIPv4) {
28 EXPECT_EQ((URI{"connect", "192.168.100.132", 5432, "/"}),
29 URI::Parse("connect://192.168.100.132:5432/"));
30}
31
32TEST(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
38TEST(UriParserTest, BracketedHostnamePort) {
39 EXPECT_EQ((URI{"connect", "192.168.100.132", 5432, "/"}),
40 URI::Parse("connect://[192.168.100.132]:5432/"));
41}
42
43TEST(UriParserTest, BracketedHostname) {
44 EXPECT_EQ((URI{"connect", "192.168.100.132", std::nullopt, "/"}),
45 URI::Parse("connect://[192.168.100.132]"));
46}
47
48TEST(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
54TEST(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
61TEST(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
66TEST(UriParserTest, SchemeHostSeparator) {
67 EXPECT_EQ(std::nullopt, URI::Parse("x:/y"));
68}
69
70TEST(UriParserTest, SchemeHostSeparator2) {
71 EXPECT_EQ(std::nullopt, URI::Parse("x:y"));
72}
73
74TEST(UriParserTest, SchemeHostSeparator3) {
75 EXPECT_EQ(std::nullopt, URI::Parse("x//y"));
76}
77
78TEST(UriParserTest, SchemeHostSeparator4) {
79 EXPECT_EQ(std::nullopt, URI::Parse("x/y"));
80}
81
82TEST(UriParserTest, BadPort) {
83 EXPECT_EQ(std::nullopt, URI::Parse("x://y:a/"));
84}
85
86TEST(UriParserTest, BadPort2) {
87 EXPECT_EQ(std::nullopt, URI::Parse("x://y:5432a/"));
88}
89
90TEST(UriParserTest, Empty) { EXPECT_EQ(std::nullopt, URI::Parse("")); }
91
92TEST(UriParserTest, PortOverflow) {
93 EXPECT_EQ(std::nullopt,
94 URI::Parse("x://"
95 "y:"
96 "0123456789012345678901234567890123456789012345678"
97 "9012345678901234567890123456789012345678901234567"
98 "89/"));
99}
100

source code of lldb/unittests/Utility/UriParserTest.cpp