28 #define BOOST_TEST_MODULE transport_iostream_connection 29 #include <boost/test/unit_test.hpp> 58 typedef websocketpp::lib::shared_ptr<type>
ptr;
61 stub_con(
bool is_server,
const websocketpp::lib::shared_ptr<config::alog_type>& a,
const websocketpp::lib::shared_ptr<config::elog_type>& e)
78 websocketpp::lib::bind(
81 websocketpp::lib::placeholders::_1
86 void write(std::vector<websocketpp::transport::buffer> &
bufs) {
89 websocketpp::lib::bind(
92 websocketpp::lib::placeholders::_1
103 websocketpp::lib::bind(
106 websocketpp::lib::placeholders::_1
111 void handle_op(websocketpp::lib::error_code
const & e) {
117 indef_read_size = num_bytes;
118 indef_read_buf = buf;
119 indef_read_len = len;
129 websocketpp::lib::bind(
132 websocketpp::lib::placeholders::_1,
133 websocketpp::lib::placeholders::_2
138 void handle_indef(websocketpp::lib::error_code
const & e,
size_t amt_read) {
140 indef_read_total += amt_read;
147 websocketpp::lib::bind(
150 websocketpp::lib::placeholders::_1
159 websocketpp::lib::error_code
ec;
167 websocketpp::lib::shared_ptr<config::alog_type>
alogger = websocketpp::lib::make_shared<config::alog_type>();
168 websocketpp::lib::shared_ptr<config::elog_type>
elogger = websocketpp::lib::make_shared<config::elog_type>();
173 BOOST_CHECK( !con->is_secure() );
174 BOOST_CHECK_EQUAL( con->get_remote_endpoint(),
"iostream transport" );
183 std::vector<websocketpp::transport::buffer>
bufs;
191 std::stringstream output;
193 con->register_ostream(&output);
197 BOOST_CHECK( !con->ec );
198 BOOST_CHECK_EQUAL( output.str(),
"foo" );
202 o += std::string(buf,len);
203 return websocketpp::lib::error_code();
207 std::vector<websocketpp::transport::buffer>::const_iterator it;
208 for (it = bufs.begin(); it != bufs.end(); it++) {
209 o += std::string((*it).buf, (*it).len);
212 return websocketpp::lib::error_code();
223 con->set_write_handler(websocketpp::lib::bind(
225 websocketpp::lib::ref(output),
226 websocketpp::lib::placeholders::_1,
227 websocketpp::lib::placeholders::_2,
228 websocketpp::lib::placeholders::_3
231 BOOST_CHECK( !con->ec );
232 BOOST_CHECK_EQUAL(output,
"foo");
244 std::stringstream output;
247 con->register_ostream(&output);
249 std::vector<websocketpp::transport::buffer>
bufs;
253 BOOST_CHECK( !con->ec );
254 BOOST_CHECK_EQUAL( output.str(),
"" );
262 con->set_write_handler(websocketpp::lib::bind(
264 websocketpp::lib::ref(output),
265 websocketpp::lib::placeholders::_1,
266 websocketpp::lib::placeholders::_2,
267 websocketpp::lib::placeholders::_3
270 std::vector<websocketpp::transport::buffer>
bufs;
274 BOOST_CHECK( !con->ec );
275 BOOST_CHECK_EQUAL( output,
"" );
279 std::stringstream output;
282 con->register_ostream(&output);
284 std::vector<websocketpp::transport::buffer>
bufs;
286 std::string foo =
"foo";
292 BOOST_CHECK( !con->ec );
293 BOOST_CHECK_EQUAL( output.str(),
"foo" );
300 con->set_write_handler(websocketpp::lib::bind(
302 websocketpp::lib::ref(output),
303 websocketpp::lib::placeholders::_1,
304 websocketpp::lib::placeholders::_2,
305 websocketpp::lib::placeholders::_3
308 std::vector<websocketpp::transport::buffer>
bufs;
310 std::string foo =
"foo";
316 BOOST_CHECK( !con->ec );
317 BOOST_CHECK_EQUAL( output,
"foo" );
321 std::stringstream output;
324 con->register_ostream(&output);
326 std::vector<websocketpp::transport::buffer>
bufs;
328 std::string foo =
"foo";
329 std::string bar =
"bar";
336 BOOST_CHECK( !con->ec );
337 BOOST_CHECK_EQUAL( output.str(),
"foobar" );
344 con->set_write_handler(websocketpp::lib::bind(
346 websocketpp::lib::ref(output),
347 websocketpp::lib::placeholders::_1,
348 websocketpp::lib::placeholders::_2,
349 websocketpp::lib::placeholders::_3
352 std::vector<websocketpp::transport::buffer>
bufs;
354 std::string foo =
"foo";
355 std::string bar =
"bar";
362 BOOST_CHECK( !con->ec );
363 BOOST_CHECK_EQUAL( output,
"foobar" );
370 con->set_vector_write_handler(websocketpp::lib::bind(
372 websocketpp::lib::ref(output),
373 websocketpp::lib::placeholders::_1,
374 websocketpp::lib::placeholders::_2
377 std::vector<websocketpp::transport::buffer>
bufs;
379 std::string foo =
"foo";
380 std::string bar =
"bar";
387 BOOST_CHECK( !con->ec );
388 BOOST_CHECK_EQUAL( output,
"foobar" );
396 con->async_read_at_least(11,buf,10);
405 con->async_read_at_least(5,buf,10);
406 con->async_read_at_least(5,buf,10);
417 con->async_read_at_least(5,buf,10);
420 std::stringstream channel;
423 BOOST_CHECK_EQUAL( channel.tellg(), -1 );
426 std::stringstream channel2;
429 BOOST_CHECK_EQUAL( channel2.tellg(), -1 );
430 BOOST_CHECK( !con->ec );
431 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdexxxxx" );
433 std::stringstream channel3;
436 BOOST_CHECK_EQUAL( channel3.tellg(), 0 );
437 BOOST_CHECK( !con->ec );
438 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdexxxxx" );
439 con->async_read_at_least(1,buf+5,5);
441 BOOST_CHECK_EQUAL( channel3.tellg(), -1 );
442 BOOST_CHECK( !con->ec );
443 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdefxxxx" );
453 con->async_read_at_least(5,buf,5);
456 std::stringstream channel;
457 channel <<
"abcdefg";
459 BOOST_CHECK_EQUAL( channel.tellg(), 5 );
460 BOOST_CHECK( !con->ec );
461 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdexxxxx" );
463 con->async_read_at_least(1,buf+5,5);
465 BOOST_CHECK_EQUAL( channel.tellg(), -1 );
466 BOOST_CHECK( !con->ec );
467 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdefgxxx" );
486 con->async_read_at_least(5,buf,5);
489 char input[10] =
"abcdefg";
490 BOOST_CHECK_EQUAL(con->read_some(input,5), 5);
491 BOOST_CHECK( !con->ec );
492 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdexxxxx" );
494 BOOST_CHECK_EQUAL(con->read_some(input+5,2), 0);
495 BOOST_CHECK( !con->ec );
496 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdexxxxx" );
498 con->async_read_at_least(1,buf+5,5);
499 BOOST_CHECK_EQUAL(con->read_some(input+5,2), 2);
500 BOOST_CHECK( !con->ec );
501 BOOST_CHECK_EQUAL( std::string(buf,10),
"abcdefgxxx" );
510 con->async_read_indef(5,buf,5);
515 char input[11] =
"aaaaabbbbb";
516 BOOST_CHECK_EQUAL(con->read_some(input,10), 5);
517 BOOST_CHECK( !con->ec );
518 BOOST_CHECK_EQUAL( std::string(buf,10),
"aaaaaxxxxx" );
519 BOOST_CHECK_EQUAL( con->indef_read_total, 5 );
523 BOOST_CHECK_EQUAL(con->read_some(input+5,5), 5);
524 BOOST_CHECK( !con->ec );
525 BOOST_CHECK_EQUAL( std::string(buf,10),
"bbbbbxxxxx" );
526 BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
535 con->async_read_indef(5,buf,5);
538 char input[11] =
"aaaaabbbbb";
539 BOOST_CHECK_EQUAL(con->read_all(input,10), 10);
540 BOOST_CHECK( !con->ec );
541 BOOST_CHECK_EQUAL( std::string(buf,10),
"bbbbbxxxxx" );
542 BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
548 con->async_read_at_least(5,buf,5);
557 con->async_read_at_least(5,buf,5);
567 BOOST_CHECK_EQUAL( con->ec, websocketpp::lib::error_code() );
587 con->set_shutdown_handler(NULL);
590 BOOST_CHECK_EQUAL( con->ec, websocketpp::lib::error_code() );
596 BOOST_CHECK_EQUAL(con.use_count(), 1);
600 con->async_read_at_least(5,buf,5);
602 BOOST_CHECK_EQUAL(con.use_count(), 2);
604 char input[10] =
"foo";
605 con->read_some(input,3);
606 BOOST_CHECK_EQUAL(con.use_count(), 2);
608 con->read_some(input,2);
609 BOOST_CHECK_EQUAL( std::string(buf,10),
"foofoxxxxx" );
610 BOOST_CHECK_EQUAL(con.use_count(), 1);
612 con->async_read_at_least(5,buf,5);
613 BOOST_CHECK_EQUAL(con.use_count(), 2);
617 BOOST_CHECK_EQUAL(con.use_count(), 1);
An operation that requires an output stream was attempted before setting one.
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
void async_read_indef(size_t num_bytes, char *buf, size_t len)
lib::error_code make_error_code(error::value e)
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
Concurrency policy that uses std::mutex / boost::mutex.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
void async_shutdown(transport::shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
async_read called while another async_read was in progress
lib::shared_ptr< timer > timer_ptr
underlying transport pass through
Package of log levels for logging access events.
websocketpp::lib::error_code write_handler(std::string &o, websocketpp::connection_hdl, char const *buf, size_t len)
websocketpp::lib::error_code ec
websocketpp::lib::shared_ptr< config::alog_type > alogger
void async_write(char const *buf, size_t len, transport::write_handler handler)
Asyncronous Transport Write.
websocketpp::concurrency::none concurrency_type
Catch-all error for transport policy errors that don't fit in other categories.
void timer_callback_stub(websocketpp::lib::error_code const &)
websocketpp::concurrency::basic concurrency_type
Basic logger that outputs to an ostream.
async_read_at_least call requested more bytes than buffer can store
void write(std::vector< websocketpp::transport::buffer > &bufs)
Namespace for the WebSocket++ project.
void handle_indef(websocketpp::lib::error_code const &e, size_t amt_read)
websocketpp::transport::iostream::connection< config > iostream_con
websocketpp::lib::shared_ptr< type > ptr
stub_con(bool is_server, const websocketpp::lib::shared_ptr< config::alog_type > &a, const websocketpp::lib::shared_ptr< config::elog_type > &e)
A simple utility buffer class.
lib::function< void(lib::asio::error_code const &)> shutdown_handler
ptr get_shared()
Get a shared pointer to this component.
websocketpp::lib::error_code write_handler_error(websocketpp::connection_hdl, char const *, size_t)
websocketpp::lib::error_code vector_write_handler(std::string &o, websocketpp::connection_hdl, std::vector< websocketpp::transport::buffer > const &bufs)
iostream_con::timer_ptr timer_ptr
Package of log levels for logging errors.
void async_read_at_least(size_t num_bytes, char *buf, size_t len)
void handle_async_shutdown(websocketpp::lib::error_code const &e)
BOOST_AUTO_TEST_CASE(basic_http_request)
websocketpp::lib::shared_ptr< config::elog_type > elogger
ptr get_shared()
Get a shared pointer to this component.
websocketpp::lib::error_code sd_handler(websocketpp::connection_hdl)
void handle_op(websocketpp::lib::error_code const &e)
websocketpp::log::basic< concurrency_type, websocketpp::log::alevel > alog_type
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
Unit testing utility error code.
lib::function< void(lib::asio::error_code const &ec, size_t bytes_transferred)> async_write_handler
void write(std::string msg)
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.