proxygen
ParseURLTest.cpp File Reference

Go to the source code of this file.

Functions

void testParseURL (const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
 
void testHostIsIpAddress (const string &url, const bool expected)
 
 TEST (ParseURL, HostNoBrackets)
 
 TEST (ParseURL, FullyFormedURL)
 
 TEST (ParseURL, ValidNonHttpScheme)
 
 TEST (ParseURL, InvalidScheme)
 
 TEST (ParseURL, NoScheme)
 
 TEST (ParseURL, NoSchemeIP)
 
 TEST (ParseURL, PathOnly)
 
 TEST (ParseURL, QueryIsURL)
 
 TEST (ParseURL, InvalidURL)
 
 TEST (ParseURL, IsHostIPAddress)
 

Function Documentation

TEST ( ParseURL  ,
HostNoBrackets   
)

Definition at line 46 of file ParseURLTest.cpp.

References EXPECT_EQ, proxygen::ParseURL::host(), and proxygen::ParseURL::hostNoBrackets().

46  {
47  ParseURL p("/bar");
48 
49  EXPECT_EQ("", p.host());
50  EXPECT_EQ("", p.hostNoBrackets());
51 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( ParseURL  ,
FullyFormedURL   
)

Definition at line 53 of file ParseURLTest.cpp.

References testParseURL().

53  {
54  testParseURL("http://localhost:80/foo?bar#qqq", "http", "/foo", "bar",
55  "localhost", 80, "localhost:80");
56  testParseURL("http://localhost:80/foo?bar", "http", "/foo", "bar",
57  "localhost", 80, "localhost:80");
58  testParseURL("http://localhost:80/foo", "http", "/foo", "",
59  "localhost", 80, "localhost:80");
60  testParseURL("http://localhost:80/", "http", "/", "",
61  "localhost", 80, "localhost:80");
62  testParseURL("http://localhost:80", "http", "", "",
63  "localhost", 80, "localhost:80");
64  testParseURL("http://localhost", "http", "", "",
65  "localhost", 0, "localhost");
66  testParseURL("http://[2401:db00:2110:3051:face:0:3f:0]/", "http", "/", "",
67  "[2401:db00:2110:3051:face:0:3f:0]", 0,
68  "[2401:db00:2110:3051:face:0:3f:0]");
69 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
ValidNonHttpScheme   
)

Definition at line 71 of file ParseURLTest.cpp.

References testParseURL().

71  {
72  testParseURL("https://localhost:80/foo?bar#qqq", "https", "/foo", "bar",
73  "localhost", 80, "localhost:80");
74  testParseURL("rtmp://localhost:80/foo?bar#qqq", "rtmp", "/foo", "bar",
75  "localhost", 80, "localhost:80");
76  testParseURL("ftp://localhost:80/foo?bar#qqq", "ftp", "/foo", "bar",
77  "localhost", 80, "localhost:80");
78  testParseURL("proxygen://localhost:80/foo?bar#qqq", "proxygen", "/foo", "bar",
79  "localhost", 80, "localhost:80");
80  testParseURL("test://localhost:80/foo?bar#qqq", "test", "/foo", "bar",
81  "localhost", 80, "localhost:80");
82 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
InvalidScheme   
)

Definition at line 84 of file ParseURLTest.cpp.

References testParseURL().

84  {
85  testParseURL("test123://localhost:80", "", "", "", "", 0, "", false);
86  testParseURL("test.1://localhost:80", "", "", "", "", 0, "", false);
87  testParseURL("://localhost:80", "", "", "", "", 0, "", false);
88  testParseURL("123://localhost:80", "", "", "", "", 0, "", false);
89  testParseURL("---://localhost:80", "", "", "", "", 0, "", false);
90 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
NoScheme   
)

Definition at line 92 of file ParseURLTest.cpp.

References testParseURL().

92  {
93  testParseURL("localhost:80/foo?bar#qqq", "", "/foo", "bar",
94  "localhost", 80, "localhost:80");
95  testParseURL("localhost:80/foo?bar", "", "/foo", "bar",
96  "localhost", 80, "localhost:80");
97  testParseURL("localhost:80/foo", "", "/foo", "",
98  "localhost", 80, "localhost:80");
99  testParseURL("localhost:80/", "", "/", "",
100  "localhost", 80, "localhost:80");
101  testParseURL("localhost:80", "", "", "",
102  "localhost", 80, "localhost:80");
103  testParseURL("localhost", "", "", "",
104  "localhost", 0, "localhost");
105 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
NoSchemeIP   
)

Definition at line 107 of file ParseURLTest.cpp.

References testParseURL().

107  {
108  testParseURL("1.2.3.4:54321/foo?bar#qqq", "",
109  "/foo", "bar", "1.2.3.4", 54321, "1.2.3.4:54321");
110  testParseURL("[::1]:80/foo?bar", "", "/foo", "bar", "[::1]", 80, "[::1]:80");
111  testParseURL("[::1]/foo?bar", "", "/foo", "bar", "[::1]", 0, "[::1]");
112 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
PathOnly   
)

Definition at line 114 of file ParseURLTest.cpp.

References testParseURL().

114  {
115  testParseURL("/f/o/o?bar#qqq", "", "/f/o/o", "bar", "", 0, "");
116  testParseURL("/f/o/o?bar", "", "/f/o/o", "bar", "", 0, "");
117  testParseURL("/f/o/o", "", "/f/o/o", "", "", 0, "");
118  testParseURL("/", "", "/", "", "", 0, "");
119  testParseURL("?foo=bar", "", "", "foo=bar", "", 0, "");
120  testParseURL("?#", "", "", "", "", 0, "");
121  testParseURL("#/foo/bar", "", "", "", "", 0, "");
122 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
QueryIsURL   
)

Definition at line 124 of file ParseURLTest.cpp.

References testParseURL().

124  {
125  testParseURL("/?ids=http://vlc.afreecodec.com/download/", "",
126  "/", "ids=http://vlc.afreecodec.com/download/", "", 0, "");
127  testParseURL("/plugins/facepile.php?href=http://www.vakan.nl/hotels",
128  "", "/plugins/facepile.php",
129  "href=http://www.vakan.nl/hotels", "", 0, "");
130 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
InvalidURL   
)

Definition at line 132 of file ParseURLTest.cpp.

References testParseURL().

132  {
133  testParseURL("http://tel:198433511/", "", "", "", "", 0, "", false);
134  testParseURL("localhost:80/foo#bar?qqq", "", "", "", "", 0, "", false);
135  testParseURL("#?", "", "", "", "", 0, "", false);
136  testParseURL("#?hello", "", "", "", "", 0, "", false);
137  testParseURL("[::1/foo?bar", "", "", "", "", 0, "", false);
138  testParseURL("", "", "", "", "", 0, "", false);
139  testParseURL("http://tel:198433511/test\n", "", "", "", "", 0, "", false);
140  testParseURL("/test\n", "", "", "", "", 0, "", false);
141 }
void testParseURL(const string &url, const string &expectedScheme, const string &expectedPath, const string &expectedQuery, const string &expectedHost, const uint16_t expectedPort, const string &expectedAuthority, const bool expectedValid=true)
TEST ( ParseURL  ,
IsHostIPAddress   
)

Definition at line 143 of file ParseURLTest.cpp.

References testHostIsIpAddress().

143  {
144  testHostIsIpAddress("http://127.0.0.1:80", true);
145  testHostIsIpAddress("127.0.0.1", true);
146  testHostIsIpAddress("http://[::1]:80", true);
147  testHostIsIpAddress("[::1]", true);
148  testHostIsIpAddress("[::AB]", true);
149 
150  testHostIsIpAddress("http://localhost:80", false);
151  testHostIsIpAddress("http://localhost", false);
152  testHostIsIpAddress("localhost", false);
153  testHostIsIpAddress("1.2.3.-1", false);
154  testHostIsIpAddress("1.2.3.999", false);
155  testHostIsIpAddress("::1", false);
156  testHostIsIpAddress("[::99999999]", false);
157 
158  // invalid url
159  testHostIsIpAddress("", false);
160  testHostIsIpAddress("127.0.0.1:80/foo#bar?qqq", false);
161 }
void testHostIsIpAddress(const string &url, const bool expected)
void testHostIsIpAddress ( const string url,
const bool  expected 
)

Definition at line 41 of file ParseURLTest.cpp.

References EXPECT_EQ, and proxygen::ParseURL::hostIsIPAddress().

Referenced by TEST().

41  {
42  ParseURL u(url);
43  EXPECT_EQ(expected, u.hostIsIPAddress());
44 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void testParseURL ( const string url,
const string expectedScheme,
const string expectedPath,
const string expectedQuery,
const string expectedHost,
const uint16_t  expectedPort,
const string expectedAuthority,
const bool  expectedValid = true 
)

Definition at line 16 of file ParseURLTest.cpp.

References proxygen::ParseURL::authority(), EXPECT_EQ, proxygen::ParseURL::host(), proxygen::ParseURL::path(), proxygen::ParseURL::port(), proxygen::ParseURL::query(), proxygen::ParseURL::scheme(), proxygen::ParseURL::url(), and proxygen::ParseURL::valid().

Referenced by TEST().

23  {
24  ParseURL u(url);
25 
26  if (expectedValid) {
27  EXPECT_EQ(url, u.url());
28  EXPECT_EQ(expectedScheme, u.scheme());
29  EXPECT_EQ(expectedPath, u.path());
30  EXPECT_EQ(expectedQuery, u.query());
31  EXPECT_EQ(expectedHost, u.host());
32  EXPECT_EQ(expectedPort, u.port());
33  EXPECT_EQ(expectedAuthority, u.authority());
34  EXPECT_EQ(expectedValid, u.valid());
35  } else {
36  // invalid, do not need to test values
37  EXPECT_EQ(expectedValid, u.valid());
38  }
39 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922