2 * Copyright (c) 2015, Peter Thorson. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //#define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_MODULE endpoint
29 #include <boost/test/unit_test.hpp>
34 #include <websocketpp/config/asio.hpp>
35 #include <websocketpp/server.hpp>
37 BOOST_AUTO_TEST_CASE( construct_server_iostream ) {
38 websocketpp::server<websocketpp::config::core> s;
41 BOOST_AUTO_TEST_CASE( construct_server_asio_plain ) {
42 websocketpp::server<websocketpp::config::asio> s;
45 BOOST_AUTO_TEST_CASE( construct_server_asio_tls ) {
46 websocketpp::server<websocketpp::config::asio_tls> s;
49 BOOST_AUTO_TEST_CASE( initialize_server_asio ) {
50 websocketpp::server<websocketpp::config::asio> s;
54 BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) {
55 websocketpp::server<websocketpp::config::asio> s;
56 boost::asio::io_service ios;
60 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
61 BOOST_AUTO_TEST_CASE( move_construct_server_core ) {
62 websocketpp::server<websocketpp::config::core> s1;
64 websocketpp::server<websocketpp::config::core> s2(std::move(s1));
68 // temporary disable because library doesn't pass
69 BOOST_AUTO_TEST_CASE( emplace ) {
70 std::stringstream out1;
71 std::stringstream out2;
73 std::vector<websocketpp::server<websocketpp::config::asio_tls>> v;
78 v[0].get_alog().set_ostream(&out1);
79 v[0].get_alog().set_ostream(&out2);
81 v[0].get_alog().write(websocketpp::log::alevel::app,"devel0");
82 v[1].get_alog().write(websocketpp::log::alevel::app,"devel1");
83 BOOST_CHECK( out1.str().size() > 0 );
84 BOOST_CHECK( out2.str().size() > 0 );
87 #endif // _WEBSOCKETPP_MOVE_SEMANTICS_
89 struct endpoint_extension {
90 endpoint_extension() : extension_value(5) {}
92 int extension_method() {
93 return extension_value;
96 bool is_server() const {
103 struct stub_config : public websocketpp::config::core {
104 typedef core::concurrency_type concurrency_type;
106 typedef core::request_type request_type;
107 typedef core::response_type response_type;
109 typedef core::message_type message_type;
110 typedef core::con_msg_manager_type con_msg_manager_type;
111 typedef core::endpoint_msg_manager_type endpoint_msg_manager_type;
113 typedef core::alog_type alog_type;
114 typedef core::elog_type elog_type;
116 typedef core::rng_type rng_type;
118 typedef core::transport_type transport_type;
120 typedef endpoint_extension endpoint_base;
123 BOOST_AUTO_TEST_CASE( endpoint_extensions ) {
124 websocketpp::server<stub_config> s;
126 BOOST_CHECK_EQUAL( s.extension_value, 5 );
127 BOOST_CHECK_EQUAL( s.extension_method(), 5 );
129 BOOST_CHECK( s.is_server() );
132 BOOST_AUTO_TEST_CASE( listen_after_listen_failure ) {
133 using websocketpp::transport::asio::error::make_error_code;
134 using websocketpp::transport::asio::error::pass_through;
136 websocketpp::server<websocketpp::config::asio> server1;
137 websocketpp::server<websocketpp::config::asio> server2;
139 websocketpp::lib::error_code ec;
144 boost::asio::ip::tcp::endpoint ep1(boost::asio::ip::address::from_string("127.0.0.1"), 12345);
145 boost::asio::ip::tcp::endpoint ep2(boost::asio::ip::address::from_string("127.0.0.1"), 23456);
147 server1.listen(ep1, ec);
150 server2.listen(ep1, ec);
151 BOOST_REQUIRE_EQUAL(ec, make_error_code(pass_through));
153 server2.listen(ep2, ec);