]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/beast/test/beast/core/string_param.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / beast / test / beast / core / string_param.cpp
CommitLineData
b32b8144 1//
92f5a8d4 2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
b32b8144
FG
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// Official repository: https://github.com/boostorg/beast
8//
9
10// Test that header file is self-contained.
11#include <boost/beast/core/string_param.hpp>
12
92f5a8d4 13#include <boost/beast/_experimental/unit_test/suite.hpp>
b32b8144
FG
14#include <boost/beast/core/detail/type_traits.hpp>
15
16namespace boost {
17namespace beast {
18
19class string_param_test : public unit_test::suite
20{
21public:
22 struct nop {};
23
24 void
25 check(string_param const& v, string_view s)
26 {
27 BEAST_EXPECT(static_cast<string_view>(v) == s);
28 }
29
30 class repeater
31 {
32 std::size_t n_;
33
34 public:
35 explicit
36 repeater(std::size_t n)
37 : n_(n)
38 {
39 }
40
41 friend
42 std::ostream&
43 operator<<(std::ostream& os, repeater const& v)
44 {
45 return os << std::string(v.n_, '*');
46 }
47 };
48
49 void
50 testConversion()
51 {
52 // Make sure things convert correctly
53 check(std::string("hello"), "hello");
54 check("xyz", "xyz");
55 check(1, "1");
56 check(12, "12");
57 check(123, "123");
58 check(1234, "1234");
59 check(12345, "12345");
60 check({"a", "b"}, "ab");
61 check({1, 2, 3}, "123");
62 }
63
64 void
65 testStaticOstream()
66 {
67 // exercise static_ostream for coverage
68 std::string s(500, '*');
69 check(repeater{500}, s);
70 }
71
72 void
73 run() override
74 {
75 testConversion();
76 testStaticOstream();
77 }
78};
79
80BEAST_DEFINE_TESTSUITE(beast,core,string_param);
81
82} // beast
83} // boost