]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/http/span_body.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / beast / test / beast / http / span_body.cpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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/http/span_body.hpp>
12
13 #include <boost/beast/http/message.hpp>
14 #include <boost/beast/unit_test/suite.hpp>
15
16 namespace boost {
17 namespace beast {
18 namespace http {
19
20 struct span_body_test
21 : public beast::unit_test::suite
22 {
23 void
24 testSpanBody()
25 {
26 {
27 using B = span_body<char const>;
28 request<B> req;
29
30 BEAST_EXPECT(req.body().size() == 0);
31 BEAST_EXPECT(B::size(req.body()) == 0);
32
33 req.body() = B::value_type("xyz", 3);
34 BEAST_EXPECT(req.body().size() == 3);
35 BEAST_EXPECT(B::size(req.body()) == 3);
36
37 B::writer r{req, req.body()};
38 error_code ec;
39 r.init(ec);
40 BEAST_EXPECTS(! ec, ec.message());
41 auto const buf = r.get(ec);
42 BEAST_EXPECTS(! ec, ec.message());
43 if(! BEAST_EXPECT(buf != boost::none))
44 return;
45 BEAST_EXPECT(boost::asio::buffer_size(buf->first) == 3);
46 BEAST_EXPECT(! buf->second);
47 }
48 {
49 char buf[5];
50 using B = span_body<char>;
51 request<B> req;
52 req.body() = span<char>{buf, sizeof(buf)};
53 B::reader w{req, req.body()};
54 error_code ec;
55 w.init(boost::none, ec);
56 BEAST_EXPECTS(! ec, ec.message());
57 w.put(boost::asio::const_buffer{
58 "123", 3}, ec);
59 BEAST_EXPECTS(! ec, ec.message());
60 BEAST_EXPECT(buf[0] == '1');
61 BEAST_EXPECT(buf[1] == '2');
62 BEAST_EXPECT(buf[2] == '3');
63 w.put(boost::asio::const_buffer{
64 "456", 3}, ec);
65 BEAST_EXPECTS(ec == error::buffer_overflow, ec.message());
66 }
67 }
68
69 void
70 run() override
71 {
72 testSpanBody();
73 }
74 };
75
76 BEAST_DEFINE_TESTSUITE(beast,http,span_body);
77
78 } // http
79 } // beast
80 } // boost