Initial Commit - Lesson 31 (Commit #1)
This commit is contained in:
32
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/SConscript
vendored
Normal file
32
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/SConscript
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
## asio transport unit tests
|
||||
##
|
||||
|
||||
Import('env')
|
||||
Import('env_cpp11')
|
||||
Import('boostlibs')
|
||||
Import('platform_libs')
|
||||
Import('polyfill_libs')
|
||||
Import('tls_libs')
|
||||
|
||||
env = env.Clone ()
|
||||
env_cpp11 = env_cpp11.Clone ()
|
||||
|
||||
BOOST_LIBS = boostlibs(['unit_test_framework','system','thread','chrono'],env) + [platform_libs] + [tls_libs]
|
||||
|
||||
objs = env.Object('base_boost.o', ["base.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('timers_boost.o', ["timers.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('security_boost.o', ["security.cpp"], LIBS = BOOST_LIBS)
|
||||
prgs = env.Program('test_base_boost', ["base_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_timers_boost', ["timers_boost.o"], LIBS = BOOST_LIBS)
|
||||
prgs += env.Program('test_security_boost', ["security_boost.o"], LIBS = BOOST_LIBS)
|
||||
|
||||
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework','system'],env_cpp11) + [platform_libs] + [polyfill_libs] + [tls_libs]
|
||||
objs += env_cpp11.Object('base_stl.o', ["base.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('timers_stl.o', ["timers.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('security_stl.o', ["security.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_base_stl', ["base_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_timers_stl', ["timers_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_security_stl', ["security_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
|
||||
Return('prgs')
|
||||
49
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/base.cpp
vendored
Normal file
49
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/base.cpp
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_asio_base
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <websocketpp/transport/asio/base.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( blank_error ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
BOOST_CHECK( !ec );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( asio_error ) {
|
||||
using websocketpp::transport::asio::error::make_error_code;
|
||||
using websocketpp::transport::asio::error::general;
|
||||
|
||||
websocketpp::lib::error_code ec = make_error_code(general);
|
||||
|
||||
BOOST_CHECK( ec == general );
|
||||
BOOST_CHECK( ec.value() == 1 );
|
||||
}
|
||||
69
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/security.cpp
vendored
Normal file
69
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/security.cpp
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_asio_base
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <websocketpp/common/type_traits.hpp>
|
||||
|
||||
#include <websocketpp/transport/asio/security/none.hpp>
|
||||
#include <websocketpp/transport/asio/security/tls.hpp>
|
||||
|
||||
template <typename base>
|
||||
struct dummy_con : public base {
|
||||
websocketpp::lib::error_code test() {
|
||||
return this->translate_ec(websocketpp::lib::asio::error_code());
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( translated_ec_none ) {
|
||||
dummy_con<websocketpp::transport::asio::basic_socket::connection> tscon;
|
||||
|
||||
// If the current configuration settings result in the library error type and the asio
|
||||
// error type being the same, then the code should pass through natively. Otherwise
|
||||
// we should get a generic pass through error.
|
||||
if(websocketpp::lib::is_same<websocketpp::lib::error_code,websocketpp::lib::asio::error_code>::value) {
|
||||
BOOST_CHECK_EQUAL( tscon.test(), websocketpp::lib::error_code() );
|
||||
} else {
|
||||
BOOST_CHECK_EQUAL( tscon.test(), websocketpp::transport::error::make_error_code(websocketpp::transport::error::pass_through) );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( translated_ec_tls ) {
|
||||
dummy_con<websocketpp::transport::asio::tls_socket::connection> tscon;
|
||||
|
||||
// If the current configuration settings result in the library error type and the asio
|
||||
// error type being the same, then the code should pass through natively. Otherwise
|
||||
// we should get a generic pass through error.
|
||||
if(websocketpp::lib::is_same<websocketpp::lib::error_code,websocketpp::lib::asio::error_code>::value) {
|
||||
BOOST_CHECK_EQUAL( tscon.test(), websocketpp::lib::error_code() );
|
||||
} else {
|
||||
BOOST_CHECK_EQUAL( tscon.test(), websocketpp::transport::error::make_error_code(websocketpp::transport::error::pass_through) );
|
||||
}
|
||||
}
|
||||
194
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/timers.cpp
vendored
Normal file
194
Plugins/GameLiftServerSDK/ThirdParty/websocketpp/test/transport/asio/timers.cpp
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_asio_timers
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
|
||||
#include <websocketpp/transport/asio/endpoint.hpp>
|
||||
#include <websocketpp/transport/asio/security/tls.hpp>
|
||||
|
||||
// Concurrency
|
||||
#include <websocketpp/concurrency/none.hpp>
|
||||
|
||||
// HTTP
|
||||
#include <websocketpp/http/request.hpp>
|
||||
#include <websocketpp/http/response.hpp>
|
||||
|
||||
// Loggers
|
||||
#include <websocketpp/logger/stub.hpp>
|
||||
//#include <websocketpp/logger/basic.hpp>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
// Accept a connection, read data, and discard until EOF
|
||||
void run_dummy_server(int port) {
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
try {
|
||||
boost::asio::io_service io_service;
|
||||
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port));
|
||||
tcp::socket socket(io_service);
|
||||
|
||||
acceptor.accept(socket);
|
||||
for (;;) {
|
||||
char data[512];
|
||||
boost::system::error_code ec;
|
||||
socket.read_some(boost::asio::buffer(data), ec);
|
||||
if (ec == boost::asio::error::eof) {
|
||||
break;
|
||||
} else if (ec) {
|
||||
// other error
|
||||
throw ec;
|
||||
}
|
||||
}
|
||||
} catch (std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (boost::system::error_code & ec) {
|
||||
std::cout << ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the specified time period then fail the test
|
||||
void run_test_timer(long value) {
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::deadline_timer t(ios,boost::posix_time::milliseconds(value));
|
||||
boost::system::error_code ec;
|
||||
t.wait(ec);
|
||||
BOOST_FAIL( "Test timed out" );
|
||||
}
|
||||
|
||||
struct config {
|
||||
typedef websocketpp::concurrency::none concurrency_type;
|
||||
//typedef websocketpp::log::basic<concurrency_type,websocketpp::log::alevel> alog_type;
|
||||
typedef websocketpp::log::stub alog_type;
|
||||
typedef websocketpp::log::stub elog_type;
|
||||
typedef websocketpp::http::parser::request request_type;
|
||||
typedef websocketpp::http::parser::response response_type;
|
||||
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
|
||||
|
||||
static const bool enable_multithreading = true;
|
||||
|
||||
static const long timeout_socket_pre_init = 1000;
|
||||
static const long timeout_proxy = 1000;
|
||||
static const long timeout_socket_post_init = 1000;
|
||||
static const long timeout_dns_resolve = 1000;
|
||||
static const long timeout_connect = 1000;
|
||||
static const long timeout_socket_shutdown = 1000;
|
||||
};
|
||||
|
||||
// Mock context that does no validation
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
context_ptr on_tls_init(websocketpp::connection_hdl) {
|
||||
return context_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::sslv23));
|
||||
}
|
||||
|
||||
// Mock connection
|
||||
struct mock_con: public websocketpp::transport::asio::connection<config> {
|
||||
typedef websocketpp::transport::asio::connection<config> base;
|
||||
|
||||
mock_con(bool a, const websocketpp::lib::shared_ptr<config::alog_type>& b,
|
||||
const websocketpp::lib::shared_ptr<config::elog_type>& c)
|
||||
: base(a,b,c) {}
|
||||
|
||||
void start() {
|
||||
base::init(websocketpp::lib::bind(&mock_con::handle_start,this,
|
||||
websocketpp::lib::placeholders::_1));
|
||||
}
|
||||
|
||||
void handle_start(const websocketpp::lib::error_code& ec) {
|
||||
using websocketpp::transport::asio::socket::make_error_code;
|
||||
using websocketpp::transport::asio::socket::error::tls_handshake_timeout;
|
||||
|
||||
BOOST_CHECK_EQUAL( ec, make_error_code(tls_handshake_timeout) );
|
||||
|
||||
base::cancel_socket();
|
||||
}
|
||||
};
|
||||
|
||||
typedef websocketpp::transport::asio::connection<config> con_type;
|
||||
typedef websocketpp::lib::shared_ptr<mock_con> connection_ptr;
|
||||
|
||||
struct mock_endpoint : public websocketpp::transport::asio::endpoint<config> {
|
||||
typedef websocketpp::transport::asio::endpoint<config> base;
|
||||
|
||||
mock_endpoint()
|
||||
: alog(websocketpp::lib::make_shared<config::alog_type>())
|
||||
, elog(websocketpp::lib::make_shared<config::elog_type>())
|
||||
{
|
||||
alog->set_channels(websocketpp::log::alevel::all);
|
||||
base::init_logging(alog,elog);
|
||||
init_asio();
|
||||
}
|
||||
|
||||
void connect(std::string u) {
|
||||
m_con.reset(new mock_con(false,alog,elog));
|
||||
websocketpp::uri_ptr uri(new websocketpp::uri(u));
|
||||
|
||||
BOOST_CHECK( uri->get_valid() );
|
||||
BOOST_CHECK_EQUAL( base::init(m_con), websocketpp::lib::error_code() );
|
||||
|
||||
base::async_connect(
|
||||
m_con,
|
||||
uri,
|
||||
websocketpp::lib::bind(
|
||||
&mock_endpoint::handle_connect,
|
||||
this,
|
||||
m_con,
|
||||
websocketpp::lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void handle_connect(connection_ptr con, websocketpp::lib::error_code const & ec)
|
||||
{
|
||||
BOOST_CHECK( !ec );
|
||||
con->start();
|
||||
}
|
||||
|
||||
connection_ptr m_con;
|
||||
websocketpp::lib::shared_ptr<config::alog_type> alog;
|
||||
websocketpp::lib::shared_ptr<config::elog_type> elog;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( tls_handshake_timeout ) {
|
||||
websocketpp::lib::thread dummy_server(websocketpp::lib::bind(&run_dummy_server,9005));
|
||||
websocketpp::lib::thread timer(websocketpp::lib::bind(&run_test_timer,5000));
|
||||
dummy_server.detach();
|
||||
timer.detach();
|
||||
|
||||
sleep(1); // give the server thread some time to start
|
||||
|
||||
mock_endpoint endpoint;
|
||||
endpoint.set_tls_init_handler(&on_tls_init);
|
||||
endpoint.connect("wss://localhost:9005");
|
||||
endpoint.run();
|
||||
}
|
||||
Reference in New Issue
Block a user