loolwsd/test/httpwstest.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
New commits: commit 11e8a9bb4f9413bd50859b555d2f20fd182fc448 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Jan 24 14:58:08 2016 -0500 loolwsd: test improvements Change-Id: Ieeef1019063636cef171cc360f523810f6f989d2 Reviewed-on: https://gerrit.libreoffice.org/21759 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 79dedf9..4228d53 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -23,7 +23,7 @@ /// Tests the HTTP WebSocket API of loolwsd. The server has to be started manually before running this test. class HTTPWSTest : public CPPUNIT_NS::TestFixture { - Poco::URI _uri; + const Poco::URI _uri; Poco::Net::HTTPClientSession _session; Poco::Net::HTTPRequest _request; Poco::Net::HTTPResponse _response; @@ -39,15 +39,28 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testLargePaste(); void testRenderingOptions(); + static void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string); + public: HTTPWSTest() : _uri("http://127.0.0.1:" + std::to_string(ClientPortNumber)), _session(_uri.getHost(), _uri.getPort()), - _request(Poco::Net::HTTPRequest::HTTP_POST, "/ws"), + _request(Poco::Net::HTTPRequest::HTTP_GET, "/ws"), _socket(_session, _request, _response) { } + + void setUp() + { + _socket.shutdown(); + _socket = Poco::Net::WebSocket(_session, _request, _response); + } + + void tearDown() + { + _socket.shutdown(); + } }; void HTTPWSTest::testPaste() @@ -70,7 +83,7 @@ void HTTPWSTest::testPaste() int n; do { - char buffer[100000]; + char buffer[READ_BUFFER_SIZE]; n = _socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0) { @@ -111,9 +124,9 @@ void HTTPWSTest::testLargePaste() int n; do { - char buffer[100000]; + char buffer[READ_BUFFER_SIZE]; n = _socket.receiveFrame(buffer, sizeof(buffer), flags); - if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) + if (n > 0) { std::string line = LOOLProtocol::getFirstLine(buffer, n); std::string prefix = "textselectioncontent: "; @@ -122,6 +135,7 @@ void HTTPWSTest::testLargePaste() } } while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); + sendTextFrame(_socket, "disconnect"); _socket.shutdown(); } @@ -139,7 +153,7 @@ void HTTPWSTest::testRenderingOptions() int n; do { - char buffer[100000]; + char buffer[READ_BUFFER_SIZE]; n = _socket.receiveFrame(buffer, sizeof(buffer), flags); if (n > 0) { @@ -158,10 +172,11 @@ void HTTPWSTest::testRenderingOptions() // Expected format is something like 'type=text parts=2 current=0 width=12808 height=1142'. Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), tokens.count()); - std::string token = tokens[4]; - std::string prefix = "height="; + + const std::string token = tokens[4]; + const std::string prefix = "height="; CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), token.find(prefix)); - int height = std::stoi(token.substr(prefix.size())); + const int height = std::stoi(token.substr(prefix.size())); // HideWhitespace was ignored, this was 32532, should be around 16706. CPPUNIT_ASSERT(height < 20000); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits