Files
beast/test/core/doc_examples.cpp

90 lines
2.4 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>
#include <boost/beast/test/pipe_stream.hpp>
#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 {
namespace http {
class doc_core_samples_test
: 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::pipe p{ios_};
ostream(p.server.buffer) <<
"\x16***";
error_code ec;
flat_buffer b;
auto const result = detect_ssl(p.server, 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::pipe p{ios_};
ostream(p.server.buffer) <<
"\x16***";
error_code ec;
flat_buffer b;
auto const result = async_detect_ssl(p.server, 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-07-20 13:40:34 -07:00
BOOST_BEAST_DEFINE_TESTSUITE(doc_core_samples,core,beast);
2017-06-08 22:03:58 -07:00
} // http
} // beast
2017-07-20 13:40:34 -07:00
} // boost