fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / websocketpp-0.7.0 / test / endpoint / endpoint.cpp
1 /*
2  * Copyright (c) 2015, Peter Thorson. All rights reserved.
3  *
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.
14  *
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.
25  *
26  */
27 //#define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_MODULE endpoint
29 #include <boost/test/unit_test.hpp>
30
31 #include <iostream>
32 #include <sstream>
33
34 #include <websocketpp/config/asio.hpp>
35 #include <websocketpp/server.hpp>
36
37 BOOST_AUTO_TEST_CASE( construct_server_iostream ) {
38     websocketpp::server<websocketpp::config::core> s;
39 }
40
41 BOOST_AUTO_TEST_CASE( construct_server_asio_plain ) {
42     websocketpp::server<websocketpp::config::asio> s;
43 }
44
45 BOOST_AUTO_TEST_CASE( construct_server_asio_tls ) {
46     websocketpp::server<websocketpp::config::asio_tls> s;
47 }
48
49 BOOST_AUTO_TEST_CASE( initialize_server_asio ) {
50     websocketpp::server<websocketpp::config::asio> s;
51     s.init_asio();
52 }
53
54 BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) {
55     websocketpp::server<websocketpp::config::asio> s;
56     boost::asio::io_service ios;
57     s.init_asio(&ios);
58 }
59
60 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
61 BOOST_AUTO_TEST_CASE( move_construct_server_core ) {
62     websocketpp::server<websocketpp::config::core> s1;
63     
64     websocketpp::server<websocketpp::config::core> s2(std::move(s1));
65 }
66
67 /*
68 // temporary disable because library doesn't pass
69 BOOST_AUTO_TEST_CASE( emplace ) {
70     std::stringstream out1;
71     std::stringstream out2;
72     
73     std::vector<websocketpp::server<websocketpp::config::asio_tls>> v;
74     
75     v.emplace_back();
76     v.emplace_back();
77     
78     v[0].get_alog().set_ostream(&out1);
79     v[0].get_alog().set_ostream(&out2);
80     
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 );
85 }*/
86
87 #endif // _WEBSOCKETPP_MOVE_SEMANTICS_
88
89 struct endpoint_extension {
90     endpoint_extension() : extension_value(5) {}
91
92     int extension_method() {
93         return extension_value;
94     }
95
96     bool is_server() const {
97         return false;
98     }
99
100     int extension_value;
101 };
102
103 struct stub_config : public websocketpp::config::core {
104     typedef core::concurrency_type concurrency_type;
105
106     typedef core::request_type request_type;
107     typedef core::response_type response_type;
108
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;
112
113     typedef core::alog_type alog_type;
114     typedef core::elog_type elog_type;
115
116     typedef core::rng_type rng_type;
117
118     typedef core::transport_type transport_type;
119
120     typedef endpoint_extension endpoint_base;
121 };
122
123 BOOST_AUTO_TEST_CASE( endpoint_extensions ) {
124     websocketpp::server<stub_config> s;
125
126     BOOST_CHECK_EQUAL( s.extension_value, 5 );
127     BOOST_CHECK_EQUAL( s.extension_method(), 5 );
128
129     BOOST_CHECK( s.is_server() );
130 }
131
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;
135
136     websocketpp::server<websocketpp::config::asio> server1;
137     websocketpp::server<websocketpp::config::asio> server2;
138
139     websocketpp::lib::error_code ec;
140
141     server1.init_asio();
142     server2.init_asio();
143
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);
146
147     server1.listen(ep1, ec);
148     BOOST_CHECK(!ec);
149
150     server2.listen(ep1, ec);
151     BOOST_REQUIRE_EQUAL(ec, make_error_code(pass_through));
152
153     server2.listen(ep2, ec);
154     BOOST_CHECK(!ec);
155 }