2017-05-03 15:29:23 -07:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-05-03 15:29:23 -07:00
|
|
|
//
|
|
|
|
|
// 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)
|
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
|
//
|
2017-05-03 15:29:23 -07:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/ostream.hpp>
|
2017-05-03 15:29:23 -07:00
|
|
|
|
2018-04-24 10:55:39 -07:00
|
|
|
#include <boost/beast/core/buffers_to_string.hpp>
|
2018-12-16 11:30:34 -08:00
|
|
|
#include <boost/beast/core/flat_buffer.hpp>
|
|
|
|
|
#include <boost/beast/core/flat_static_buffer.hpp>
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/multi_buffer.hpp>
|
2019-02-05 09:08:25 -08:00
|
|
|
#include <boost/beast/core/string.hpp>
|
2018-11-11 14:07:55 -08:00
|
|
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
2017-05-03 15:29:23 -07:00
|
|
|
#include <ostream>
|
|
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2017-05-03 15:29:23 -07:00
|
|
|
namespace beast {
|
|
|
|
|
|
|
|
|
|
class ostream_test : public beast::unit_test::suite
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-05-08 07:09:36 -07:00
|
|
|
void
|
2018-12-16 11:30:34 -08:00
|
|
|
testOstream()
|
2017-05-03 15:29:23 -07:00
|
|
|
{
|
2018-12-16 11:30:34 -08:00
|
|
|
string_view const s = "0123456789abcdef";
|
|
|
|
|
BEAST_EXPECT(s.size() == 16);
|
|
|
|
|
|
|
|
|
|
// overflow
|
2017-05-08 07:09:36 -07:00
|
|
|
{
|
2018-12-16 11:30:34 -08:00
|
|
|
flat_static_buffer<16> b;
|
2017-05-08 07:09:36 -07:00
|
|
|
ostream(b) << s;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
2017-05-08 07:09:36 -07:00
|
|
|
}
|
2018-12-16 11:30:34 -08:00
|
|
|
|
|
|
|
|
// max_size
|
|
|
|
|
{
|
|
|
|
|
flat_static_buffer<16> b;
|
|
|
|
|
auto os = ostream(b);
|
|
|
|
|
os << s;
|
|
|
|
|
os << '*';
|
|
|
|
|
BEAST_EXPECT(os.bad());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// max_size (exception
|
|
|
|
|
{
|
|
|
|
|
flat_static_buffer<16> b;
|
|
|
|
|
auto os = ostream(b);
|
|
|
|
|
os.exceptions(os.badbit);
|
|
|
|
|
os << s;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
os << '*';
|
|
|
|
|
fail("missing exception", __FILE__, __LINE__);
|
|
|
|
|
}
|
|
|
|
|
catch(std::ios_base::failure const&)
|
|
|
|
|
{
|
|
|
|
|
pass();
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
|
fail("wrong exception", __FILE__, __LINE__);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
run() override
|
|
|
|
|
{
|
|
|
|
|
testOstream();
|
2017-05-03 15:29:23 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,core,ostream);
|
2017-05-03 15:29:23 -07:00
|
|
|
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|