diff --git a/Release/tests/functional/websockets/client/send_msg_tests.cpp b/Release/tests/functional/websockets/client/send_msg_tests.cpp index e99bccd03c..eed1dedf94 100644 --- a/Release/tests/functional/websockets/client/send_msg_tests.cpp +++ b/Release/tests/functional/websockets/client/send_msg_tests.cpp @@ -104,16 +104,32 @@ SUITE(send_msg_tests) } template - pplx::task send_pong_msg_helper(SocketClientClass & client, web::uri uri, test_websocket_server & server) + pplx::task send_ping_msg_helper(SocketClientClass & client, web::uri uri, test_websocket_server & server, + const std::string& body = "") { server.next_message( - [](test_websocket_msg msg) // Handler to verify the message sent by the client. - { websocket_asserts::assert_message_equals(msg, "", test_websocket_message_type::WEB_SOCKET_PONG_TYPE); }); + [body](test_websocket_msg msg) // Handler to verify the message sent by the client. + { websocket_asserts::assert_message_equals(msg, body, test_websocket_message_type::WEB_SOCKET_PING_TYPE); }); client.connect(uri).wait(); websocket_outgoing_message msg; - msg.set_pong_message(); + msg.set_ping_message(body); + return client.send(msg); + } + + template + pplx::task send_pong_msg_helper(SocketClientClass & client, web::uri uri, test_websocket_server & server, + const std::string& body = "") + { + server.next_message( + [body](test_websocket_msg msg) // Handler to verify the message sent by the client. + { websocket_asserts::assert_message_equals(msg, body, test_websocket_message_type::WEB_SOCKET_PONG_TYPE); }); + + client.connect(uri).wait(); + + websocket_outgoing_message msg; + msg.set_pong_message(body); return client.send(msg); } @@ -493,6 +509,24 @@ SUITE(send_msg_tests) } #if !defined(__cplusplus_winrt) + // Send a ping message to the server + TEST_FIXTURE(uri_address, send_ping_msg) + { + test_websocket_server server; + websocket_client client; + send_ping_msg_helper(client, m_uri, server).wait(); + client.close().wait(); + } + + // Send a ping message to the server with a body + TEST_FIXTURE(uri_address, send_ping_msg_body) + { + test_websocket_server server; + websocket_client client; + send_ping_msg_helper(client, m_uri, server, "abcdefghijklmnopqrstuvwxyz").wait(); + client.close().wait(); + } + // Send an unsolicited pong message to the server TEST_FIXTURE(uri_address, send_pong_msg) { @@ -502,6 +536,15 @@ SUITE(send_msg_tests) client.close().wait(); } + // Send an unsolicited pong message to the server with a body + TEST_FIXTURE(uri_address, send_pong_msg_body) + { + test_websocket_server server; + websocket_client client; + send_pong_msg_helper(client, m_uri, server, "abcdefghijklmnopqrstuvwxyz").wait(); + client.close().wait(); + } + // Send an unsolicited pong message to the server with websocket_callback_client TEST_FIXTURE(uri_address, send_pong_msg_callback_client) { diff --git a/Release/tests/functional/websockets/utilities/test_websocket_server.cpp b/Release/tests/functional/websockets/utilities/test_websocket_server.cpp index 151d03bca0..863376f22a 100644 --- a/Release/tests/functional/websockets/utilities/test_websocket_server.cpp +++ b/Release/tests/functional/websockets/utilities/test_websocket_server.cpp @@ -122,6 +122,20 @@ class _test_websocket_server m_server_connected.set_exception(std::runtime_error("Connection attempt failed.")); }); + m_srv.set_ping_handler([this](websocketpp::connection_hdl hdl, std::string input) { + auto fn = m_test_srv->get_next_message_handler(); + assert(fn); + + test_websocket_msg wsmsg; + + wsmsg.set_data(std::vector(input.begin(), input.end())); + + wsmsg.set_msg_type(WEB_SOCKET_PING_TYPE); + fn(wsmsg); + + return true; + }); + m_srv.set_pong_handler([this](websocketpp::connection_hdl hdl, std::string input) { auto fn = m_test_srv->get_next_message_handler(); assert(fn); diff --git a/Release/tests/functional/websockets/utilities/test_websocket_server.h b/Release/tests/functional/websockets/utilities/test_websocket_server.h index 50489e1a9d..23fbea12e2 100644 --- a/Release/tests/functional/websockets/utilities/test_websocket_server.h +++ b/Release/tests/functional/websockets/utilities/test_websocket_server.h @@ -46,6 +46,7 @@ enum test_websocket_message_type WEB_SOCKET_UTF8_MESSAGE_TYPE, WEB_SOCKET_UTF8_FRAGMENT_TYPE, WEB_SOCKET_CLOSE_TYPE, + WEB_SOCKET_PING_TYPE, WEB_SOCKET_PONG_TYPE };