From c76771b32384d82bcbe24da2df1f5a834a8620b1 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 20 Jan 2013 08:56:38 -0600 Subject: [PATCH] splits connection test into two translation units --- test/connection/SConscript | 6 ++-- test/connection/connection.cpp | 52 +--------------------------- test/connection/connection_tu2.cpp | 54 +++++++++++++++++++++++++++++ test/connection/connection_tu2.hpp | 55 ++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 53 deletions(-) create mode 100644 test/connection/connection_tu2.cpp create mode 100644 test/connection/connection_tu2.hpp diff --git a/test/connection/SConscript b/test/connection/SConscript index 42562f75a4..67633dc8b0 100644 --- a/test/connection/SConscript +++ b/test/connection/SConscript @@ -13,11 +13,13 @@ env_cpp11 = env_cpp11.Clone () BOOST_LIBS = boostlibs(['unit_test_framework','regex','system'],env) + [platform_libs] objs = env.Object('connection_boost.o', ["connection.cpp"], LIBS = BOOST_LIBS) -prgs = env.Program('test_connection_boost', ["connection_boost.o"], LIBS = BOOST_LIBS) +objs = env.Object('connection_tu2_boost.o', ["connection_tu2.cpp"], LIBS = BOOST_LIBS) +prgs = env.Program('test_connection_boost', ["connection_boost.o","connection_tu2_boost.o"], LIBS = BOOST_LIBS) if env_cpp11.has_key('WSPP_CPP11_ENABLED'): BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework'],env_cpp11) + [platform_libs] + [polyfill_libs] objs += env_cpp11.Object('connection_stl.o', ["connection.cpp"], LIBS = BOOST_LIBS_CPP11) - prgs += env_cpp11.Program('test_connection_stl', ["connection_stl.o"], LIBS = BOOST_LIBS_CPP11) + objs += env_cpp11.Object('connection_tu2_stl.o', ["connection_tu2.cpp"], LIBS = BOOST_LIBS_CPP11) + prgs += env_cpp11.Program('test_connection_stl', ["connection_stl.o","connection_tu2_stl.o"], LIBS = BOOST_LIBS_CPP11) Return('prgs') diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp index cc359ea2c6..9f7f4c543e 100644 --- a/test/connection/connection.cpp +++ b/test/connection/connection.cpp @@ -28,57 +28,7 @@ #define BOOST_TEST_MODULE connection #include -#include -#include - -// Test Environment: -// server, no TLS, no locks, iostream based transport -#include -#include - -typedef websocketpp::server server; -typedef websocketpp::config::core::message_type::ptr message_ptr; - -using websocketpp::lib::placeholders::_1; -using websocketpp::lib::placeholders::_2; -using websocketpp::lib::bind; - -/*class echo_handler : public server::handler { - bool validate(connection_ptr con) { - std::cout << "handler validate" << std::endl; - if (con->get_origin() != "http://www.example.com") { - con->set_status(websocketpp::http::status_code::FORBIDDEN); - return false; - } - return true; - } -};*/ - -void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { - s->send(hdl, msg->get_payload(), msg->get_opcode()); -} - -std::string run_server_test(std::string input) { - server test_server; - server::connection_ptr con; - - test_server.set_message_handler(bind(&on_message,&test_server,::_1,::_2)); - - std::stringstream output; - - test_server.register_ostream(&output); - - con = test_server.get_connection(); - - con->start(); - - std::stringstream channel; - - channel << input; - channel >> *con; - - return output.str(); -} +#include "connection_tu2.hpp" // NOTE: these tests currently test against hardcoded output values. I am not // sure how problematic this will be. If issues arise like order of headers the diff --git a/test/connection/connection_tu2.cpp b/test/connection/connection_tu2.cpp new file mode 100644 index 0000000000..76f4ddd83d --- /dev/null +++ b/test/connection/connection_tu2.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013, 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. + * + */ + +#include "connection_tu2.hpp" + +void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { + s->send(hdl, msg->get_payload(), msg->get_opcode()); +} + +std::string run_server_test(std::string input) { + server test_server; + server::connection_ptr con; + + test_server.set_message_handler(bind(&on_message,&test_server,::_1,::_2)); + + std::stringstream output; + + test_server.register_ostream(&output); + + con = test_server.get_connection(); + + con->start(); + + std::stringstream channel; + + channel << input; + channel >> *con; + + return output.str(); +} \ No newline at end of file diff --git a/test/connection/connection_tu2.hpp b/test/connection/connection_tu2.hpp new file mode 100644 index 0000000000..bbc1cb738c --- /dev/null +++ b/test/connection/connection_tu2.hpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013, 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. + * + */ + +#include +#include + +// Test Environment: +// server, no TLS, no locks, iostream based transport +#include +#include + +typedef websocketpp::server server; +typedef websocketpp::config::core::message_type::ptr message_ptr; + +using websocketpp::lib::placeholders::_1; +using websocketpp::lib::placeholders::_2; +using websocketpp::lib::bind; + +/*class echo_handler : public server::handler { + bool validate(connection_ptr con) { + std::cout << "handler validate" << std::endl; + if (con->get_origin() != "http://www.example.com") { + con->set_status(websocketpp::http::status_code::FORBIDDEN); + return false; + } + return true; + } +};*/ + +void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg); +std::string run_server_test(std::string input); \ No newline at end of file