1 #include <gtest/gtest.h>
2 #include "../LUrlParser.h"
4 using LUrlParser::clParseURL
;
7 class UrlTest
: public ::testing::Test
{
14 TEST_F(UrlTest
, example
) {
16 clParseURL URL
= clParseURL::ParseURL( "https://John:Dow@github.com:80/corporateshark/LUrlParser" );
17 ASSERT_TRUE(URL
.IsValid());
18 ASSERT_EQ("https", URL
.m_Scheme
);
19 ASSERT_EQ("github.com", URL
.m_Host
);
20 ASSERT_EQ("80", URL
.m_Port
);
21 ASSERT_EQ("corporateshark/LUrlParser", URL
.m_Path
);
22 ASSERT_EQ("", URL
.m_Query
);
25 TEST_F(UrlTest
, cases
) {
27 clParseURL URL
= clParseURL::ParseURL( "HTTPS://ESPN.com/BOLD/PATH?a=A&B=b" );
28 ASSERT_TRUE(URL
.IsValid());
30 ASSERT_EQ("https", URL
.m_Scheme
); // notice it's now lowercase
31 ASSERT_EQ("ESPN.com", URL
.m_Host
); // case unchanged
32 ASSERT_EQ("BOLD/PATH", URL
.m_Path
);
33 ASSERT_EQ("a=A&B=b", URL
.m_Query
);
36 TEST_F(UrlTest
, ipv6
) {
38 clParseURL URL
= clParseURL::ParseURL( "https://[fe80::9a01:a7ff:feb1:7dc9]:80/corporateshark/LUrlParser" );
39 ASSERT_TRUE(URL
.IsValid());
40 ASSERT_EQ("[fe80::9a01:a7ff:feb1:7dc9]", URL
.m_Host
);
43 TEST_F(UrlTest
, ipv4
) {
45 clParseURL URL
= clParseURL::ParseURL( "https://10.0.3.243/corporateshark/LUrlParser" );
46 ASSERT_TRUE(URL
.IsValid());
47 ASSERT_EQ("10.0.3.243", URL
.m_Host
);
50 TEST_F(UrlTest
, parens
) {
52 clParseURL URL
= clParseURL::ParseURL( "https://en.wikipedia.org/wiki/Joe_Malone_(ice_hockey)" );
53 ASSERT_TRUE(URL
.IsValid());
54 ASSERT_EQ("wiki/Joe_Malone_(ice_hockey)", URL
.m_Path
);
57 TEST_F(UrlTest
, trailingdot
) {
59 clParseURL URL
= clParseURL::ParseURL( "http://foo.com/blah_blah." );
60 ASSERT_TRUE(URL
.IsValid());
61 ASSERT_EQ("blah_blah.", URL
.m_Path
);
63 URL
= clParseURL::ParseURL( "http://foo.com/blah_blah/." );
64 ASSERT_TRUE(URL
.IsValid());
65 ASSERT_EQ("blah_blah/.", URL
.m_Path
);
68 TEST_F(UrlTest
, specialchars
) {
70 clParseURL URL
= clParseURL::ParseURL( "https://duckduckgo.com/?q=mark+twain&atb=v23_c&ia=web" );
71 ASSERT_TRUE(URL
.IsValid());
72 ASSERT_EQ("q=mark+twain&atb=v23_c&ia=web", URL
.m_Query
);
75 TEST_F(UrlTest
, escapechars
) {
77 clParseURL URL
= clParseURL::ParseURL( "https://duckduckgo.com/?q=mark%20twain" );
78 ASSERT_TRUE(URL
.IsValid());
79 ASSERT_EQ("q=mark%20twain", URL
.m_Query
);
82 /* // these currently still return valid
84 TEST_F(UrlTest, controlchars) {
87 URL = clParseURL::ParseURL( "https://en.wikipedia.org/bell\007/" );
88 ASSERT_FALSE(URL.IsValid());
90 URL = clParseURL::ParseURL( "https://en.wikipedia.org/line\njere/" );
91 ASSERT_FALSE(URL.IsValid());
95 int main(int argc
, char **argv
) {
96 ::testing::InitGoogleTest(&argc
, argv
);
97 int status
= RUN_ALL_TESTS();