Files
beast/test/doc/core_examples.cpp

85 lines
2.2 KiB
C++
Raw Normal View History

2017-06-08 22:03:58 -07:00
//
2017-07-24 09:42:36 -07:00
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2017-06-08 22:03:58 -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-06-08 22:03:58 -07:00
2017-06-24 22:24:39 -07:00
#include "example/common/detect_ssl.hpp"
2017-06-08 22:03:58 -07:00
2017-07-20 13:40:34 -07:00
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/ostream.hpp>
2017-08-15 22:20:13 -07:00
#include <boost/beast/test/stream.hpp>
2017-07-20 13:40:34 -07:00
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
2017-06-08 22:03:58 -07:00
2017-07-20 13:40:34 -07:00
namespace boost {
2017-06-08 22:03:58 -07:00
namespace beast {
2017-07-28 18:59:14 -07:00
class examples_test
2017-06-08 22:03:58 -07:00
: public beast::unit_test::suite
, public beast::test::enable_yield_to
{
public:
void
testDetect()
{
char buf[4];
buf[0] = 0x16;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 0))));
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 1))));
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 2))));
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 3))));
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 4)));
buf[0] = 0;
2017-07-25 12:35:54 -07:00
BEAST_EXPECT(! is_ssl_handshake(
2017-06-08 22:03:58 -07:00
boost::asio::buffer(buf, 1)));
}
void
testRead()
{
{
test::stream ts{ioc_, "\x16***"};
2017-06-08 22:03:58 -07:00
error_code ec;
flat_buffer b;
2017-08-15 22:20:13 -07:00
auto const result = detect_ssl(ts, b, ec);
2017-07-25 12:35:54 -07:00
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(result);
2017-06-08 22:03:58 -07:00
}
yield_to(
[&](yield_context yield)
{
test::stream ts{ioc_, "\x16***"};
2017-06-08 22:03:58 -07:00
error_code ec;
flat_buffer b;
2017-08-15 22:20:13 -07:00
auto const result =
async_detect_ssl(ts, b, yield[ec]);
2017-07-25 12:35:54 -07:00
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(result);
2017-06-08 22:03:58 -07:00
});
}
void
run()
{
testDetect();
testRead();
}
};
2017-08-01 17:01:57 -07:00
BEAST_DEFINE_TESTSUITE(beast,core,examples);
2017-06-08 22:03:58 -07:00
} // beast
2017-07-20 13:40:34 -07:00
} // boost