Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
client.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <websocketpp/random/random_device.hpp>
#include <websocketpp/config/core.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/http/request.hpp>
Include dependency graph for client.cpp:

Go to the source code of this file.

Classes

struct  stub_config
 

Macros

#define BOOST_TEST_MODULE   client
 

Typedefs

typedef websocketpp::client< stub_configclient
 

Functions

 BOOST_AUTO_TEST_CASE (invalid_uri)
 
 BOOST_AUTO_TEST_CASE (unsecure_endpoint)
 
 BOOST_AUTO_TEST_CASE (get_connection)
 
 BOOST_AUTO_TEST_CASE (connect_con)
 
 BOOST_AUTO_TEST_CASE (select_subprotocol)
 
 BOOST_AUTO_TEST_CASE (add_subprotocols_invalid)
 
 BOOST_AUTO_TEST_CASE (add_subprotocols)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   client

Definition at line 28 of file client.cpp.

Typedef Documentation

◆ client

Definition at line 64 of file client.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( add_subprotocols )

Definition at line 168 of file client.cpp.

168 {
169 client c;
170 websocketpp::lib::error_code ec;
171 std::stringstream out;
172 std::string o;
173
174 c.register_ostream(&out);
175
176 connection_ptr con = c.get_connection("ws://localhost/", ec);
177 BOOST_CHECK( con );
178
179 con->add_subprotocol("foo",ec);
180 BOOST_CHECK( !ec );
181
182 BOOST_CHECK_NO_THROW( con->add_subprotocol("bar") );
183
184 c.connect(con);
185
186 o = out.str();
188 r.consume(o.data(),o.size());
189
190 BOOST_CHECK( r.ready() );
191 BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Protocol"), "foo, bar");
192}
const mie::Vuint & r
Definition bn.cpp:28
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
client::connection_ptr connection_ptr
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( add_subprotocols_invalid )

Definition at line 151 of file client.cpp.

151 {
152 client c;
153 websocketpp::lib::error_code ec;
155
156 connection_ptr con = c.get_connection("ws://localhost/", ec);
157 BOOST_CHECK( con );
158
159 con->add_subprotocol("",ec);
160 BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
161 BOOST_CHECK_THROW( con->add_subprotocol("") , websocketpp::exception );
162
163 con->add_subprotocol("foo,bar",ec);
164 BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
165 BOOST_CHECK_THROW( con->add_subprotocol("foo,bar") , websocketpp::exception );
166}
@ invalid_subprotocol
Invalid subprotocol.
Definition error.hpp:89
lib::error_code make_error_code(error::value e)
Definition error.hpp:235
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( connect_con )

Definition at line 98 of file client.cpp.

98 {
99 client c;
100 websocketpp::lib::error_code ec;
101 std::stringstream out;
102 std::string o;
103
104 c.register_ostream(&out);
105
106 connection_ptr con = c.get_connection("ws://localhost/", ec);
107 c.connect(con);
108
109 o = out.str();
111 r.consume(o.data(),o.size());
112
113 BOOST_CHECK( r.ready() );
114 BOOST_CHECK_EQUAL( r.get_method(), "GET");
115 BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1");
116 BOOST_CHECK_EQUAL( r.get_uri(), "/");
117
118 BOOST_CHECK_EQUAL( r.get_header("Host"), "localhost");
119 BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Version"), "13");
120 BOOST_CHECK_EQUAL( r.get_header("Connection"), "Upgrade");
121 BOOST_CHECK_EQUAL( r.get_header("Upgrade"), "websocket");
122
123 // Key is randomly generated & User-Agent will change so just check that
124 // they are not empty.
125 BOOST_CHECK_NE( r.get_header("Sec-WebSocket-Key"), "");
126 BOOST_CHECK_NE( r.get_header("User-Agent"), "" );
127
128 // connection should have written out an opening handshake request and be in
129 // the read response internal state
130
131 // TODO: more tests related to reading the HTTP response
132 std::stringstream channel2;
133 channel2 << "e\r\n\r\n";
134 channel2 >> *con;
135}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( get_connection )

Definition at line 85 of file client.cpp.

85 {
86 client c;
87 websocketpp::lib::error_code ec;
88
89 connection_ptr con = c.get_connection("ws://localhost/", ec);
90
91 BOOST_CHECK( con );
92 BOOST_CHECK_EQUAL( con->get_host() , "localhost" );
93 BOOST_CHECK_EQUAL( con->get_port() , 80 );
94 BOOST_CHECK_EQUAL( con->get_secure() , false );
95 BOOST_CHECK_EQUAL( con->get_resource() , "/" );
96}
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( invalid_uri )

Definition at line 67 of file client.cpp.

67 {
68 client c;
69 websocketpp::lib::error_code ec;
70
71 connection_ptr con = c.get_connection("foo", ec);
72
74}
@ invalid_uri
An invalid uri was supplied.
Definition error.hpp:65
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/7]

BOOST_AUTO_TEST_CASE ( select_subprotocol )

Definition at line 137 of file client.cpp.

137 {
138 client c;
139 websocketpp::lib::error_code ec;
141
142 connection_ptr con = c.get_connection("ws://localhost/", ec);
143
144 BOOST_CHECK( con );
145
146 con->select_subprotocol("foo",ec);
147 BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::server_only) );
148 BOOST_CHECK_THROW( con->select_subprotocol("foo") , websocketpp::exception );
149}
@ server_only
Attempted to use a server specific feature on a client endpoint.
Definition error.hpp:108
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( unsecure_endpoint )

Definition at line 76 of file client.cpp.

76 {
77 client c;
78 websocketpp::lib::error_code ec;
79
80 connection_ptr con = c.get_connection("wss://localhost/", ec);
81
83}
@ endpoint_not_secure
Attempted to open a secure connection with an insecure endpoint.
Definition error.hpp:57
Here is the call graph for this function: