Files
boost_beast/test/beast/websocket/stream.cpp

207 lines
4.6 KiB
C++
Raw Normal View History

//
2019-02-21 07:00:31 -08:00
// Copyright (c) 2016-2019 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)
//
2017-07-20 13:40:34 -07:00
// Official repository: https://github.com/boostorg/beast
//
// Test that header file is self-contained.
2017-07-20 13:40:34 -07:00
#include <boost/beast/websocket/stream.hpp>
2019-02-13 08:00:07 -08:00
#include <boost/beast/core/tcp_stream.hpp>
#include <boost/asio/strand.hpp>
2017-08-24 06:21:30 -07:00
#include "test.hpp"
2017-07-20 13:40:34 -07:00
namespace boost {
namespace beast {
namespace websocket {
2017-08-24 06:21:30 -07:00
class stream_test : public websocket_test_suite
{
public:
2019-02-13 08:00:07 -08:00
void
testGetSetOption()
{
net::io_context ioc;
stream<test::stream> ws(ioc);
{
ws.set_option(
stream_base::decorator(
[](request_type&)
{
}));
ws.set_option(
stream_base::decorator(
[](response_type&)
{
}));
}
2019-02-13 08:00:07 -08:00
{
ws.set_option(
stream_base::timeout::suggested(
2019-02-13 08:00:07 -08:00
role_type::client));
ws.set_option(
stream_base::timeout::suggested(
2019-02-13 08:00:07 -08:00
role_type::server));
ws.set_option({
std::chrono::seconds(30),
std::chrono::seconds(300),
true});
stream_base::timeout opt;
ws.get_option(opt);
ws.set_option(opt);
}
}
2017-08-22 18:08:56 -07:00
void
testOptions()
{
{
std::seed_seq ss{42};
seed_prng(ss);
}
stream<test::stream> ws{ioc_};
2017-08-22 18:08:56 -07:00
ws.auto_fragment(true);
2019-03-05 08:47:02 -08:00
ws.write_buffer_bytes(2048);
2017-08-22 18:08:56 -07:00
ws.binary(false);
ws.read_message_max(1 * 1024 * 1024);
try
{
2019-03-05 08:47:02 -08:00
ws.write_buffer_bytes(7);
2017-08-22 18:08:56 -07:00
fail();
}
catch(std::exception const&)
{
pass();
}
ws.secure_prng(true);
ws.secure_prng(false);
auto const bad =
[&](permessage_deflate const& pmd)
{
stream<test::stream> ws{ioc_};
try
{
ws.set_option(pmd);
fail("", __FILE__, __LINE__);
}
catch(std::exception const&)
{
pass();
}
};
{
permessage_deflate pmd;
pmd.server_max_window_bits = 16;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.server_max_window_bits = 8;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.client_max_window_bits = 16;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.client_max_window_bits = 8;
bad(pmd);
}
2017-07-29 17:47:04 -07:00
{
permessage_deflate pmd;
pmd.compLevel = -1;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.compLevel = 10;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.memLevel = 0;
bad(pmd);
}
{
permessage_deflate pmd;
pmd.memLevel = 10;
bad(pmd);
}
}
2019-02-13 08:00:07 -08:00
void
testJavadoc()
{
net::io_context ioc;
{
2019-03-02 05:22:02 -08:00
websocket::stream<tcp_stream> ws{net::make_strand(ioc)};
2019-02-13 08:00:07 -08:00
}
{
websocket::stream<tcp_stream> ws(ioc);
2019-02-13 08:00:07 -08:00
}
}
void
run() override
{
2017-05-23 12:33:31 -07:00
BOOST_STATIC_ASSERT(std::is_constructible<
stream<test::stream>, net::io_context&>::value);
2017-05-23 12:33:31 -07:00
BOOST_STATIC_ASSERT(std::is_move_constructible<
2017-08-24 06:21:30 -07:00
stream<test::stream>>::value);
2019-02-27 15:02:00 -08:00
#if 0
2017-05-23 12:33:31 -07:00
BOOST_STATIC_ASSERT(std::is_move_assignable<
2017-08-24 06:21:30 -07:00
stream<test::stream>>::value);
2019-02-27 15:02:00 -08:00
#endif
2017-05-23 12:33:31 -07:00
BOOST_STATIC_ASSERT(std::is_constructible<
2017-08-24 06:21:30 -07:00
stream<test::stream&>, test::stream&>::value);
// VFALCO Should these be allowed for NextLayer references?
2017-05-23 12:33:31 -07:00
BOOST_STATIC_ASSERT(std::is_move_constructible<
2017-08-24 06:21:30 -07:00
stream<test::stream&>>::value);
2019-02-27 15:02:00 -08:00
#if 0
BOOST_STATIC_ASSERT(std::is_move_assignable<
2017-08-24 06:21:30 -07:00
stream<test::stream&>>::value);
2019-02-27 15:02:00 -08:00
#endif
2016-06-10 15:48:39 -04:00
log << "sizeof(websocket::stream) == " <<
sizeof(websocket::stream<test::stream&>) << std::endl;
log << "sizeof(websocket::stream::impl_type) == " <<
sizeof(websocket::stream<test::stream&>::impl_type) << std::endl;
testOptions();
2019-02-13 08:00:07 -08:00
testJavadoc();
}
};
2017-08-01 17:01:57 -07:00
BEAST_DEFINE_TESTSUITE(beast,websocket,stream);
} // websocket
} // beast
2017-07-20 13:40:34 -07:00
} // boost