2017-06-10 15:56:48 -07:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot 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)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
|
|
|
|
#include <beast/core/string_param.hpp>
|
|
|
|
|
|
|
|
|
|
#include <beast/unit_test/suite.hpp>
|
|
|
|
|
#include <beast/core/detail/type_traits.hpp>
|
|
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
|
|
|
|
|
class string_param_test : public unit_test::suite
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct nop {};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
check(string_param const& v, string_view s)
|
|
|
|
|
{
|
2017-06-22 16:49:46 -07:00
|
|
|
BEAST_EXPECT(static_cast<string_view>(v) == s);
|
2017-06-10 15:56:48 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-19 08:14:09 -07:00
|
|
|
class repeater
|
|
|
|
|
{
|
|
|
|
|
std::size_t n_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit
|
|
|
|
|
repeater(std::size_t n)
|
|
|
|
|
: n_(n)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend
|
|
|
|
|
std::ostream&
|
|
|
|
|
operator<<(std::ostream& os, repeater const& v)
|
|
|
|
|
{
|
|
|
|
|
return os << std::string(v.n_, '*');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-10 15:56:48 -07:00
|
|
|
void
|
2017-06-19 08:14:09 -07:00
|
|
|
testConversion()
|
2017-06-10 15:56:48 -07:00
|
|
|
{
|
2017-06-19 08:14:09 -07:00
|
|
|
// Make sure things convert correctly
|
2017-06-10 15:56:48 -07:00
|
|
|
check(std::string("hello"), "hello");
|
|
|
|
|
check("xyz", "xyz");
|
|
|
|
|
check(1, "1");
|
|
|
|
|
check(12, "12");
|
|
|
|
|
check(123, "123");
|
|
|
|
|
check(1234, "1234");
|
|
|
|
|
check(12345, "12345");
|
2017-06-22 16:49:46 -07:00
|
|
|
check({"a", "b"}, "ab");
|
|
|
|
|
check({1, 2, 3}, "123");
|
2017-06-10 15:56:48 -07:00
|
|
|
}
|
2017-06-19 08:14:09 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
testStaticOstream()
|
|
|
|
|
{
|
|
|
|
|
// exercise static_ostream for coverage
|
|
|
|
|
std::string s(500, '*');
|
|
|
|
|
check(repeater{500}, s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
run() override
|
|
|
|
|
{
|
|
|
|
|
testConversion();
|
|
|
|
|
testStaticOstream();
|
|
|
|
|
}
|
2017-06-10 15:56:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BEAST_DEFINE_TESTSUITE(string_param,core,beast);
|
|
|
|
|
|
|
|
|
|
} // beast
|