| 1 |
// Copyright 2016 Glyn Matthews. |
| 2 |
// Distributed under the Boost Software License, Version 1.0. |
| 3 |
// (See accompanying file LICENSE_1_0.txt of copy at |
| 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
#include <iterator> |
| 7 |
#include <gtest/gtest.h> |
| 8 |
#include "test_uri.hpp" |
| 9 |
#include "string_utility.hpp" |
| 10 |
|
| 11 |
// scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) |
| 12 |
|
| 13 |
TEST(uri_parse_test, test_valid_scheme) { |
| 14 |
test::uri uri("http://[email protected]:80/path?query#fragment"); |
| 15 |
EXPECT_TRUE(uri.parse_uri()); |
| 16 |
ASSERT_TRUE(uri.has_scheme()); |
| 17 |
EXPECT_EQ("http", uri.scheme()); |
| 18 |
} |
| 19 |
|
| 20 |
TEST(uri_parse_test, test_scheme_beginning_with_a_colon) { |
| 21 |
test::uri uri(":http://[email protected]:80/path?query#fragment"); |
| 22 |
EXPECT_FALSE(uri.parse_uri()); |
| 23 |
ASSERT_FALSE(uri.has_scheme()); |
| 24 |
} |
| 25 |
|
| 26 |
TEST(uri_parse_test, test_scheme_beginning_with_a_number) { |
| 27 |
test::uri uri("8http://[email protected]:80/path?query#fragment"); |
| 28 |
EXPECT_FALSE(uri.parse_uri()); |
| 29 |
} |
| 30 |
|
| 31 |
TEST(uri_parse_test, test_scheme_with_a_minus) { |
| 32 |
test::uri uri("ht-tp://[email protected]:80/path?query#fragment"); |
| 33 |
EXPECT_TRUE(uri.parse_uri()); |
| 34 |
ASSERT_TRUE(uri.has_scheme()); |
| 35 |
EXPECT_EQ("ht-tp", uri.scheme()); |
| 36 |
} |
| 37 |
|
| 38 |
TEST(uri_parse_test, test_scheme_with_a_plus) { |
| 39 |
test::uri uri("ht+tp://[email protected]:80/path?query#fragment"); |
| 40 |
EXPECT_TRUE(uri.parse_uri()); |
| 41 |
ASSERT_TRUE(uri.has_scheme()); |
| 42 |
EXPECT_EQ("ht+tp", uri.scheme()); |
| 43 |
} |
| 44 |
|
| 45 |
TEST(uri_parse_test, test_scheme_with_a_dot) { |
| 46 |
test::uri uri("ht.tp://[email protected]:80/path?query#fragment"); |
| 47 |
EXPECT_TRUE(uri.parse_uri()); |
| 48 |
ASSERT_TRUE(uri.has_scheme()); |
| 49 |
EXPECT_EQ("ht.tp", uri.scheme()); |
| 50 |
} |
| 51 |
|
| 52 |
TEST(uri_parse_test, test_scheme_with_a_number) { |
| 53 |
test::uri uri("http1://[email protected]:80/path?query#fragment"); |
| 54 |
EXPECT_TRUE(uri.parse_uri()); |
| 55 |
ASSERT_TRUE(uri.has_scheme()); |
| 56 |
EXPECT_EQ("http1", uri.scheme()); |
| 57 |
} |
| 58 |
|
| 59 |
TEST(uri_parse_test, test_scheme_with_an_invalid_character) { |
| 60 |
test::uri uri("http$://[email protected]:80/path?query#fragment"); |
| 61 |
EXPECT_FALSE(uri.parse_uri()); |
| 62 |
} |
| 63 |
|
| 64 |
TEST(uri_parse_test, test_scheme_with_capital_letters) { |
| 65 |
test::uri uri("HTTP://[email protected]:80/path?query#fragment"); |
| 66 |
EXPECT_TRUE(uri.parse_uri()); |
| 67 |
ASSERT_TRUE(uri.has_scheme()); |
| 68 |
EXPECT_EQ("HTTP", uri.scheme()); |
| 69 |
} |
| 70 |
|
| 71 |
TEST(uri_parse_test, test_scheme_with_a_percent) { |
| 72 |
test::uri uri("ht%tp://[email protected]:80/path?query#fragment"); |
| 73 |
EXPECT_FALSE(uri.parse_uri()); |
| 74 |
} |
| 75 |
|
| 76 |
TEST(uri_parse_test, test_scheme_with_a_valid_percent_encoded_character) { |
| 77 |
test::uri uri("ht%00tp://[email protected]:80/path?query#fragment"); |
| 78 |
EXPECT_FALSE(uri.parse_uri()); |
| 79 |
} |