Skip to content

Commit

Permalink
Add C++17 like variant for test code
Browse files Browse the repository at this point in the history
This patch allows to use variant from test code without Boost and
C++17.
  • Loading branch information
windowsair authored and laudrup committed Jan 26, 2024
1 parent f79d39a commit cc11ec2
Show file tree
Hide file tree
Showing 4 changed files with 2,765 additions and 21 deletions.
2 changes: 1 addition & 1 deletion test/handshake_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ TEST_CASE("failing handshakes") {
[&buffer, &server_stream](const error_code&, std::size_t length) {
tls_record rec(net::buffer(buffer, length));
REQUIRE(rec.type == tls_record::record_type::handshake);
auto handshake = boost::get<tls_handshake>(rec.message);
auto handshake = variant::get<tls_handshake>(rec.message);
REQUIRE(handshake.type == tls_handshake::handshake_type::client_hello);
// Echoing the client_hello message back should cause the handshake to fail
net::write(server_stream, net::buffer(buffer));
Expand Down
36 changes: 21 additions & 15 deletions test/tls_record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

#include "unittest.hpp"

#include <boost/variant.hpp>
#if __cplusplus >= 201703L || (defined _MSVC_LANG && _MSVC_LANG >= 201703L)
#include <variant>
namespace variant = std;
#else
#include "utils/impl/variant.hpp"
namespace variant = nonstd;
#endif

#include <cstdint>

Expand Down Expand Up @@ -83,16 +89,16 @@ struct tls_handshake {
// TODO: Implement
};

using message_type = boost::variant<hello_request,
client_hello,
server_hello,
certificate,
server_key_exchange,
certificate_request,
server_done,
certificate_verify,
client_key_exchange,
finished>;
using message_type = variant::variant<hello_request,
client_hello,
server_hello,
certificate,
server_key_exchange,
certificate_request,
server_done,
certificate_verify,
client_key_exchange,
finished>;

tls_handshake(net::const_buffer data);

Expand All @@ -113,10 +119,10 @@ struct tls_record {
application_data = 0x17
};

using message_type = boost::variant<tls_change_cipher_spec,
tls_alert,
tls_handshake,
tls_application_data>;
using message_type = variant::variant<tls_change_cipher_spec,
tls_alert,
tls_handshake,
tls_application_data>;
tls_record(net::const_buffer data);

record_type type;
Expand Down
5 changes: 0 additions & 5 deletions test/unittest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

#include <boost/wintls/detail/config.hpp>

// Workaround missing include in boost 1.76 and 1.77 in beast::test::stream
#if (BOOST_VERSION / 100 % 1000) == 77 || (BOOST_VERSION / 100 % 1000) == 76
#include <boost/make_shared.hpp>
#endif

#include "utils/stream.hpp"
#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio/ssl.hpp>
Expand Down
Loading

0 comments on commit cc11ec2

Please sign in to comment.