| 1 |
// Copyright (c) Glyn Matthews 2012-2016. |
| 2 |
// Distributed under the Boost Software License, Version 1.0. |
| 3 |
// (See accompanying file LICENSE_1_0.txt or copy at |
| 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
#include <gtest/gtest.h> |
| 7 |
#include <network/uri.hpp> |
| 8 |
|
| 9 |
|
| 10 |
TEST(uri_make_relative_test, opaque_uri) { |
| 11 |
network::uri uri_1("mailto:[email protected]"); |
| 12 |
network::uri uri_2("mailto:[email protected]"); |
| 13 |
ASSERT_EQ(uri_2, uri_1.make_relative(uri_2)); |
| 14 |
} |
| 15 |
|
| 16 |
TEST(uri_make_relative_test, simple_test) { |
| 17 |
network::uri uri_1("http://www.example.com/"); |
| 18 |
network::uri uri_2("http://www.example.com/path/"); |
| 19 |
ASSERT_EQ("/path/", uri_1.make_relative(uri_2)); |
| 20 |
} |
| 21 |
|
| 22 |
TEST(uri_make_relative_test, simple_test_with_different_authority) { |
| 23 |
network::uri uri_1("http://www.example.com/"); |
| 24 |
network::uri uri_2("http://www.example.org/path/"); |
| 25 |
ASSERT_EQ("http://www.example.org/path/", uri_1.make_relative(uri_2)); |
| 26 |
} |
| 27 |
|
| 28 |
TEST(uri_make_relative_test, simple_test_is_relative) { |
| 29 |
network::uri uri_1("http://www.example.com/"); |
| 30 |
network::uri uri_2("http://www.example.com/path/"); |
| 31 |
ASSERT_FALSE(uri_1.make_relative(uri_2).is_absolute()); |
| 32 |
} |
| 33 |
|
| 34 |
TEST(uri_make_relative_test, simple_test_is_hierarchical) { |
| 35 |
network::uri uri_1("http://www.example.com/"); |
| 36 |
network::uri uri_2("http://www.example.com/path/"); |
| 37 |
ASSERT_FALSE(uri_1.make_relative(uri_2).is_opaque()); |
| 38 |
} |
| 39 |
|
| 40 |
TEST(uri_make_relative_test, simple_test_with_query) { |
| 41 |
network::uri uri_1("http://www.example.com/"); |
| 42 |
network::uri uri_2("http://www.example.com/path/?key=value"); |
| 43 |
ASSERT_EQ("/path/?key=value", uri_1.make_relative(uri_2)); |
| 44 |
} |
| 45 |
|
| 46 |
TEST(uri_make_relative_test, simple_test_with_fragment) { |
| 47 |
network::uri uri_1("http://www.example.com/"); |
| 48 |
network::uri uri_2("http://www.example.com/path/#fragment"); |
| 49 |
ASSERT_EQ("/path/#fragment", uri_1.make_relative(uri_2)); |
| 50 |
} |
| 51 |
|
| 52 |
TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization) { |
| 53 |
network::uri uri_1("http://www.example.com/"); |
| 54 |
network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/"); |
| 55 |
ASSERT_EQ("/~foobar_69/", uri_1.make_relative(uri_2)); |
| 56 |
} |
| 57 |
|
| 58 |
TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization_with_query) { |
| 59 |
network::uri uri_1("http://www.example.com/"); |
| 60 |
network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/?key=value"); |
| 61 |
ASSERT_EQ("/~foobar_69/?key=value", uri_1.make_relative(uri_2)); |
| 62 |
} |
| 63 |
|
| 64 |
TEST(uri_make_relative_test, make_relative_with_percent_encoding_normalization_with_fragment) { |
| 65 |
network::uri uri_1("http://www.example.com/"); |
| 66 |
network::uri uri_2("http://www.example.com/%7E%66%6F%6F%62%61%72%5F%36%39/#fragment"); |
| 67 |
ASSERT_EQ("/~foobar_69/#fragment", uri_1.make_relative(uri_2)); |
| 68 |
} |