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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
// Test that header file is self-contained.
#include <boost/url/static_url.hpp>
#include <boost/url/parse.hpp>
#include <boost/url/url.hpp>
#include <boost/url/url_view.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/static_assert.hpp>
#include "test_suite.hpp"
#include <iostream>
#include <type_traits>
namespace boost {
namespace urls {
struct static_url_test
{
BOOST_STATIC_ASSERT(
std::is_default_constructible<
static_url<10>>::value);
BOOST_STATIC_ASSERT(
std::is_copy_constructible<
static_url<10>>::value);
BOOST_STATIC_ASSERT(
std::is_copy_assignable<
static_url<10>>::value);
BOOST_STATIC_ASSERT(
std::is_convertible<
static_url<10>, url_view>::value);
BOOST_STATIC_ASSERT(
std::is_convertible<
static_url<10>, url>::value);
void
testSpecial()
{
// static_url()
{
static_url<1024> u;
BOOST_TEST_EQ(*u.c_str(), '\0');
BOOST_TEST(u.buffer().empty());
}
// static_url(core::string_view)
{
// invalid
BOOST_TEST_THROWS(
static_url<1024>("$:$"),
system::system_error);
// too large
BOOST_TEST_THROWS(
static_url<2>("http://www.example.com"),
system::system_error);
// URI
BOOST_TEST_NO_THROW(
static_url<128>("http://www.example.com"));
// relative-ref
BOOST_TEST_NO_THROW(
static_url<128>("path/to/file.txt"));
}
// static_url(static_url)
// static_url(url_view_base)
{
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
static_url<20> u1(u0);
BOOST_TEST_EQ(u0.buffer(), u1.buffer());
BOOST_TEST_NE(u0.buffer().data(), s.data());
BOOST_TEST_NE(u1.buffer().data(), s.data());
}
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
static_url<32> u1(u0);
BOOST_TEST_EQ(u0.buffer(), u1.buffer());
}
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
BOOST_TEST_THROWS(
static_url<8>(u0), system::system_error);
}
BOOST_TEST_EQ(
static_url<24>(url_view(
"/path/to/file.txt")).buffer(),
"/path/to/file.txt");
BOOST_TEST_EQ(
static_url<24>(url(
"/path/to/file.txt")).buffer(),
"/path/to/file.txt");
}
// operator=(static_url)
// operator=(url_view_base)
{
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
static_url<20> u1;
u1 = u0;
BOOST_TEST_EQ(u0.buffer(), u1.buffer());
BOOST_TEST_NE(u0.buffer().data(), s.data());
BOOST_TEST_NE(u1.buffer().data(), s.data());
}
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
static_url<32> u1;
u1 = u0;
BOOST_TEST_EQ(u0.buffer(), u1.buffer());
}
{
core::string_view s = "/path/to/file.txt";
static_url<24> u0(s);
static_url<8> u1;
BOOST_TEST_THROWS(u1 = u0, system::system_error);
}
{
static_url<24> u("http://www.example.com");
u = url_view("/path/to/file.txt");
BOOST_TEST_EQ(u.buffer(), "/path/to/file.txt");
}
{
static_url<24> u("http://www.example.com");
u = url("/path/to/file.txt");
BOOST_TEST_EQ(u.buffer(), "/path/to/file.txt");
}
}
}
void
testOstream()
{
{
static_url<64> u("http://example.com");
std::stringstream ss;
ss << u;
BOOST_TEST(ss.str() ==
"http://example.com");
}
}
void
testJavadocs()
{
// {class}
{
static_url< 1024 > u( "https://www.example.com" );
ignore_unused(u);
}
// static_url()
{
static_url< 1024 > u;
ignore_unused(u);
}
// static_url(core::string_view)
{
static_url< 1024 > u( "https://www.example.com" );
ignore_unused(u);
}
}
void
run()
{
testSpecial();
testOstream();
testJavadocs();
}
};
TEST_SUITE(
static_url_test,
"boost.url.static_url");
} // urls
} // boost
|