2016-04-30 13:00:33 -04:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2016-04-30 13:00:33 -04: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
|
|
|
|
|
//
|
2016-04-30 13:00:33 -04:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/websocket/stream.hpp>
|
2016-04-30 13:00:33 -04:00
|
|
|
|
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"
|
2016-04-30 13:00:33 -04:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2016-04-30 13:00:33 -04:00
|
|
|
namespace beast {
|
|
|
|
|
namespace websocket {
|
|
|
|
|
|
2017-08-24 06:21:30 -07:00
|
|
|
class stream_test : public websocket_test_suite
|
2016-04-30 13:00:33 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2019-02-13 08:00:07 -08:00
|
|
|
void
|
|
|
|
|
testGetSetOption()
|
|
|
|
|
{
|
|
|
|
|
net::io_context ioc;
|
|
|
|
|
stream<test::stream> ws(ioc);
|
|
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
{
|
|
|
|
|
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(
|
2019-02-26 09:42:07 -08:00
|
|
|
stream_base::timeout::suggested(
|
2019-02-13 08:00:07 -08:00
|
|
|
role_type::client));
|
|
|
|
|
|
|
|
|
|
ws.set_option(
|
2019-02-26 09:42:07 -08:00
|
|
|
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()
|
|
|
|
|
{
|
2018-07-05 16:47:07 -07:00
|
|
|
{
|
|
|
|
|
std::seed_seq ss{42};
|
|
|
|
|
seed_prng(ss);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 07:39:52 -07:00
|
|
|
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();
|
2016-05-04 17:27:50 -04:00
|
|
|
}
|
|
|
|
|
|
2018-07-05 16:47:07 -07:00
|
|
|
ws.secure_prng(true);
|
|
|
|
|
ws.secure_prng(false);
|
|
|
|
|
|
2017-08-31 17:52:09 -07:00
|
|
|
auto const bad =
|
|
|
|
|
[&](permessage_deflate const& pmd)
|
|
|
|
|
{
|
2017-09-07 07:39:52 -07:00
|
|
|
stream<test::stream> ws{ioc_};
|
2017-08-31 17:52:09 -07:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ws.set_option(pmd);
|
|
|
|
|
fail("", __FILE__, __LINE__);
|
|
|
|
|
}
|
|
|
|
|
catch(std::exception const&)
|
|
|
|
|
{
|
|
|
|
|
pass();
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-24 18:41:25 -04:00
|
|
|
|
2017-08-31 17:52:09 -07:00
|
|
|
{
|
|
|
|
|
permessage_deflate pmd;
|
|
|
|
|
pmd.server_max_window_bits = 16;
|
|
|
|
|
bad(pmd);
|
|
|
|
|
}
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2017-08-01 20:15:07 -07:00
|
|
|
{
|
2017-08-31 17:52:09 -07:00
|
|
|
permessage_deflate pmd;
|
|
|
|
|
pmd.server_max_window_bits = 8;
|
|
|
|
|
bad(pmd);
|
|
|
|
|
}
|
2017-08-01 20:15:07 -07:00
|
|
|
|
|
|
|
|
{
|
2017-08-31 17:52:09 -07:00
|
|
|
permessage_deflate pmd;
|
|
|
|
|
pmd.client_max_window_bits = 16;
|
|
|
|
|
bad(pmd);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-01 20:15:07 -07:00
|
|
|
{
|
2017-08-31 17:52:09 -07:00
|
|
|
permessage_deflate pmd;
|
|
|
|
|
pmd.client_max_window_bits = 8;
|
|
|
|
|
bad(pmd);
|
|
|
|
|
}
|
2017-07-29 17:47:04 -07:00
|
|
|
|
2017-08-31 17:52:09 -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-01 20:15:07 -07:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
{
|
2019-02-18 12:42:24 -08:00
|
|
|
websocket::stream<tcp_stream> ws(ioc);
|
2019-02-13 08:00:07 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 17:41:27 -07:00
|
|
|
void
|
|
|
|
|
run() override
|
2016-04-30 13:00:33 -04:00
|
|
|
{
|
2017-05-23 12:33:31 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<
|
2018-11-30 14:58:38 -08:00
|
|
|
stream<test::stream>, net::io_context&>::value);
|
2016-05-07 17:06:46 -04:00
|
|
|
|
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);
|
2016-04-30 13:00:33 -04:00
|
|
|
|
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
|
2016-04-30 13:00:33 -04:00
|
|
|
|
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);
|
2016-04-30 13:00:33 -04:00
|
|
|
|
2019-01-19 07:24:00 -08:00
|
|
|
// 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
|
2019-01-19 07:24:00 -08: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
|
2016-05-04 17:27:50 -04:00
|
|
|
|
2016-06-10 15:48:39 -04:00
|
|
|
log << "sizeof(websocket::stream) == " <<
|
2017-08-16 19:25:02 -07:00
|
|
|
sizeof(websocket::stream<test::stream&>) << std::endl;
|
2019-01-19 07:24:00 -08:00
|
|
|
log << "sizeof(websocket::stream::impl_type) == " <<
|
|
|
|
|
sizeof(websocket::stream<test::stream&>::impl_type) << std::endl;
|
2017-08-16 19:25:02 -07:00
|
|
|
|
2016-10-24 18:41:25 -04:00
|
|
|
testOptions();
|
2019-02-13 08:00:07 -08:00
|
|
|
testJavadoc();
|
2016-04-30 13:00:33 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,websocket,stream);
|
2016-04-30 13:00:33 -04:00
|
|
|
|
|
|
|
|
} // websocket
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|