aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/Utility/UriParserTest.cpp
blob: 9923d3a9af936c7d5ed48b0b2b51cfa3cc186aa3 (plain)
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
#include "lldb/Utility/UriParser.h"
#include "gtest/gtest.h"

using namespace lldb_private;

TEST(UriParserTest, Minimal) {
  EXPECT_EQ((URI{"x", "y", std::nullopt, "/"}), URI::Parse("x://y"));
}

TEST(UriParserTest, MinimalPort) {
  EXPECT_EQ((URI{"x", "y", 1, "/"}), URI::Parse("x://y:1"));
}

TEST(UriParserTest, MinimalPath) {
  EXPECT_EQ((URI{"x", "y", std::nullopt, "/"}), URI::Parse("x://y/"));
}

TEST(UriParserTest, MinimalPortPath) {
  EXPECT_EQ((URI{"x", "y", 1, "/"}), URI::Parse("x://y:1/"));
}

TEST(UriParserTest, LongPath) {
  EXPECT_EQ((URI{"x", "y", std::nullopt, "/abc/def/xyz"}),
            URI::Parse("x://y/abc/def/xyz"));
}

TEST(UriParserTest, TypicalPortPathIPv4) {
  EXPECT_EQ((URI{"connect", "192.168.100.132", 5432, "/"}),
            URI::Parse("connect://192.168.100.132:5432/"));
}

TEST(UriParserTest, TypicalPortPathIPv6) {
  EXPECT_EQ(
      (URI{"connect", "2601:600:107f:db64:a42b:4faa:284:3082", 5432, "/"}),
      URI::Parse("connect://[2601:600:107f:db64:a42b:4faa:284:3082]:5432/"));
}

TEST(UriParserTest, BracketedHostnamePort) {
  EXPECT_EQ((URI{"connect", "192.168.100.132", 5432, "/"}),
            URI::Parse("connect://[192.168.100.132]:5432/"));
}

TEST(UriParserTest, BracketedHostname) {
  EXPECT_EQ((URI{"connect", "192.168.100.132", std::nullopt, "/"}),
            URI::Parse("connect://[192.168.100.132]"));
}

TEST(UriParserTest, BracketedHostnameWithPortIPv4) {
  // Android device over IPv4: port is a part of the hostname.
  EXPECT_EQ((URI{"connect", "192.168.100.132:1234", std::nullopt, "/"}),
            URI::Parse("connect://[192.168.100.132:1234]"));
}

TEST(UriParserTest, BracketedHostnameWithPortIPv6) {
  // Android device over IPv6: port is a part of the hostname.
  EXPECT_EQ((URI{"connect", "[2601:600:107f:db64:a42b:4faa:284]:1234",
                 std::nullopt, "/"}),
            URI::Parse("connect://[[2601:600:107f:db64:a42b:4faa:284]:1234]"));
}

TEST(UriParserTest, BracketedHostnameWithColon) {
  EXPECT_EQ((URI{"connect", "192.168.100.132:5555", 1234, "/"}),
            URI::Parse("connect://[192.168.100.132:5555]:1234"));
}

TEST(UriParserTest, SchemeHostSeparator) {
  EXPECT_EQ(std::nullopt, URI::Parse("x:/y"));
}

TEST(UriParserTest, SchemeHostSeparator2) {
  EXPECT_EQ(std::nullopt, URI::Parse("x:y"));
}

TEST(UriParserTest, SchemeHostSeparator3) {
  EXPECT_EQ(std::nullopt, URI::Parse("x//y"));
}

TEST(UriParserTest, SchemeHostSeparator4) {
  EXPECT_EQ(std::nullopt, URI::Parse("x/y"));
}

TEST(UriParserTest, BadPort) {
  EXPECT_EQ(std::nullopt, URI::Parse("x://y:a/"));
}

TEST(UriParserTest, BadPort2) {
  EXPECT_EQ(std::nullopt, URI::Parse("x://y:5432a/"));
}

TEST(UriParserTest, Empty) { EXPECT_EQ(std::nullopt, URI::Parse("")); }

TEST(UriParserTest, PortOverflow) {
  EXPECT_EQ(std::nullopt,
            URI::Parse("x://"
                       "y:"
                       "0123456789012345678901234567890123456789012345678"
                       "9012345678901234567890123456789012345678901234567"
                       "89/"));
}