[Libreoffice-commits] online.git: loolwsd/test
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Mar 30 02:06:51 UTC 2016
loolwsd/test/httpwstest.cpp | 138 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 130 insertions(+), 8 deletions(-)
New commits:
commit 494b90e5415a753ef586785f5256b9a03f5b0e03
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue Mar 29 21:29:53 2016 -0400
loolwsd: new unittests
Change-Id: I935dbc79df638a7481f851b3e7b42703b97b93ec
Reviewed-on: https://gerrit.libreoffice.org/23648
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 143c556..d01aa4d 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -38,8 +38,9 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE(HTTPWSTest);
CPPUNIT_TEST(testLoad);
- CPPUNIT_TEST(testLoad);
+ CPPUNIT_TEST(testBadLoad);
CPPUNIT_TEST(testReload);
+ //CPPUNIT_TEST(testSaveOnDisconnect);
CPPUNIT_TEST(testExcelLoad);
CPPUNIT_TEST(testPaste);
CPPUNIT_TEST(testLargePaste);
@@ -52,7 +53,9 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE_END();
void testLoad();
+ void testBadLoad();
void testReload();
+ void testSaveOnDisconnect();
void testExcelLoad();
void testPaste();
void testLargePaste();
@@ -110,7 +113,7 @@ void HTTPWSTest::testLoad()
try
{
// Load a document and get its status.
- const std::string documentPath = Util::getTempFilePath(TDOC, "hide-whitespace.odt");
+ const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
_tmpFilePath = documentPath;
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
@@ -129,22 +132,66 @@ void HTTPWSTest::testLoad()
{
char buffer[READ_BUFFER_SIZE];
n = socket.receiveFrame(buffer, sizeof(buffer), flags);
- std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+ std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl;
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
- std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
- std::string line = LOOLProtocol::getFirstLine(buffer, n);
- std::string prefix = "status: ";
+ std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
+ const std::string line = LOOLProtocol::getFirstLine(buffer, n);
+ const std::string prefix = "status: ";
if (line.find(prefix) == 0)
{
status = line.substr(prefix.length());
// Might be too strict, consider something flexible instread.
- CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=2 current=0 width=12808 height=32532"), status);
+ CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status);
break;
}
}
}
while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+
+ sendTextFrame(socket, "disconnect");
+ socket.shutdown();
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_ASSERT_MESSAGE(exc.displayText(), false);
+ }
+}
+
+void HTTPWSTest::testBadLoad()
+{
+ try
+ {
+ // Load a document and get its status.
+ const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
+ _tmpFilePath = documentPath;
+ const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
+ Poco::Net::WebSocket socket(session, request, _response);
+
+ // Before loading request status.
+ sendTextFrame(socket, "status");
+
+ int flags;
+ int n;
+ do
+ {
+ char buffer[READ_BUFFER_SIZE];
+ n = socket.receiveFrame(buffer, sizeof(buffer), flags);
+ std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl;
+ if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+ {
+ std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
+ const std::string line = LOOLProtocol::getFirstLine(buffer, n);
+ CPPUNIT_ASSERT_EQUAL(std::string("error: cmd=status kind=nodocloaded"), line);
+ break;
+ }
+ }
+ while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+
+ sendTextFrame(socket, "disconnect");
socket.shutdown();
}
catch (const Poco::Exception& exc)
@@ -161,6 +208,81 @@ void HTTPWSTest::testReload()
}
}
+void HTTPWSTest::testSaveOnDisconnect()
+{
+ try
+ {
+ // Load a document and get its status.
+ const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
+ _tmpFilePath = documentPath;
+ const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
+ Poco::Net::WebSocket socket(session, request, _response);
+
+ sendTextFrame(socket, "load url=" + documentURL);
+ CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
+
+ sendTextFrame(socket, "uno .uno:SelectAll");
+ sendTextFrame(socket, "uno .uno:Delete");
+ sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
+
+ socket.shutdown();
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_ASSERT_MESSAGE(exc.displayText(), false);
+ }
+
+ try
+ {
+ // Load the same document and check that the last changes (pasted text) is saved.
+ const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
+ _tmpFilePath = documentPath;
+ const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
+ Poco::Net::WebSocket socket(session, request, _response);
+
+ sendTextFrame(socket, "load url=" + documentURL);
+ sendTextFrame(socket, "status");
+ CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
+
+ // Check if the document contains the pasted text.
+ sendTextFrame(socket, "uno .uno:SelectAll");
+ sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8");
+ std::string selection;
+ int flags;
+ int n;
+ do
+ {
+ char buffer[READ_BUFFER_SIZE];
+ n = socket.receiveFrame(buffer, sizeof(buffer), flags);
+ std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+ if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+ {
+ std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
+ const std::string line = LOOLProtocol::getFirstLine(buffer, n);
+ const std::string prefix = "textselectioncontent: ";
+ if (line.find(prefix) == 0)
+ {
+ selection = line.substr(prefix.length());
+ break;
+ }
+ }
+ }
+ while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+ socket.shutdown();
+ CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection);
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_ASSERT_MESSAGE(exc.displayText(), false);
+ }
+}
+
void HTTPWSTest::testExcelLoad()
{
try
@@ -214,7 +336,7 @@ void HTTPWSTest::testPaste()
{
try
{
- // Load a document and make it empty.
+ // Load a document and make it empty, then paste some text into it.
const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
_tmpFilePath = documentPath;
const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
More information about the Libreoffice-commits
mailing list