[Libreoffice-commits] online.git: loolwsd/test
Mike Kaganski
mike.kaganski at collabora.com
Tue Jun 14 22:20:55 UTC 2016
loolwsd/test/TileCacheTests.cpp | 172 ++++++++++++++++++++++++++++++++++++++++
loolwsd/test/data/empty.odg |binary
loolwsd/test/data/empty.odp |binary
loolwsd/test/data/empty.ods |binary
loolwsd/test/data/empty.odt |binary
loolwsd/test/helpers.hpp | 60 +++++++++++++
6 files changed, 232 insertions(+)
New commits:
commit 9ef285cc3363b20bb87aa88bbffdd6a4f46c50fa
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date: Thu May 12 19:23:37 2016 +1000
loolwsd unit test: invalidate tiles while typing
This test simulates characters and combined characters being
typed to loolwsd, and verifies that each causes tile(s)
invaliations
Change-Id: I670659de3a9eb71e94c366c96e69e6efd4338c38
Reviewed-on: https://gerrit.libreoffice.org/24928
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index 7dac6b3..c7a70d7 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -40,6 +40,8 @@ class TileCacheTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testSimultaneousTilesRenderedJustOnce);
#endif
CPPUNIT_TEST(testLoad12ods);
+ CPPUNIT_TEST(testTileInvalidateWriter);
+ CPPUNIT_TEST(testTileInvalidateCalc);
CPPUNIT_TEST_SUITE_END();
@@ -51,6 +53,9 @@ class TileCacheTests : public CPPUNIT_NS::TestFixture
void testClientPartCalc();
void testSimultaneousTilesRenderedJustOnce();
void testLoad12ods();
+ void testTileInvalidateWriter();
+ void testWriterAnyKey();
+ void testTileInvalidateCalc();
void checkTiles(Poco::Net::WebSocket& socket,
const std::string& type);
@@ -544,6 +549,173 @@ void TileCacheTests::checkBlackTiles(Poco::Net::WebSocket& socket, const int /*p
#endif
}
+void TileCacheTests::testTileInvalidateWriter()
+{
+ std::string documentPath, documentURL;
+ getDocumentPathAndURL("empty.odt", documentPath, documentURL);
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+
+ auto socket = *loadDocAndGetSocket(_uri, documentURL);
+
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !getResponseMessage(socket, "invalidatetiles:").empty());
+
+ std::string text = "Test. Now go 3 \"Enters\":\n\n\nNow after the enters, goes this text";
+ for (char ch : text)
+ {
+ sendChar(socket, ch); // Send ordinary characters and wait for response -> one tile invalidation for each
+ auto response = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response.empty());
+ }
+
+ text = "\n\n\n";
+ for (char ch : text)
+ {
+ sendChar(socket, ch, skCtrl); // Send 3 Ctrl+Enter -> 3 new pages; I see 3 tiles invalidated for each
+ assertResponseLine(socket, "invalidatetiles:");
+ assertResponseLine(socket, "invalidatetiles:");
+ assertResponseLine(socket, "invalidatetiles:");
+ }
+
+ text = "abcde";
+ for (char ch : text)
+ {
+ sendChar(socket, ch);
+ auto response = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response.empty());
+ }
+
+ CPPUNIT_ASSERT_MESSAGE("received unexpected invalidatetiles: message", getResponseMessage(socket, "invalidatetiles:").empty());
+
+ // TODO: implement a random-sequence "monkey test"
+}
+
+// This isn't yet used
+void TileCacheTests::testWriterAnyKey()
+{
+ std::string documentPath, documentURL;
+ getDocumentPathAndURL("empty.odt", documentPath, documentURL);
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+
+ auto socket = *loadDocAndGetSocket(_uri, documentURL);
+
+ // Now test "usual" keycodes (TODO: whole 32-bit range)
+ for (int i=0; i<0x1000; ++i)
+ {
+ std::stringstream ss("Keycode ");
+ ss << i;
+ auto s = ss.str();
+ std::stringstream fn("saveas url=");
+ fn << documentURL << i << ".odt format= options=";
+ auto f = fn.str();
+
+ const int istart = 474;
+ sendText(socket, "\n"+s+"\n");
+ sendKeyEvent(socket, "input", 0, i);
+ sendKeyEvent(socket, "up", 0, i);
+ sendText(socket, "\nEnd "+s+"\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Shift:\n");
+ sendKeyEvent(socket, "input", 0, i|skShift);
+ sendKeyEvent(socket, "up", 0, i|skShift);
+ sendText(socket, "\nEnd "+s+" With Shift\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Ctrl:\n");
+ sendKeyEvent(socket, "input", 0, i|skCtrl);
+ sendKeyEvent(socket, "up", 0, i|skCtrl);
+ sendText(socket, "\nEnd "+s+" With Ctrl\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Alt:\n");
+ sendKeyEvent(socket, "input", 0, i|skAlt);
+ sendKeyEvent(socket, "up", 0, i|skAlt);
+ sendText(socket, "\nEnd "+s+" With Alt\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Shift+Ctrl:\n");
+ sendKeyEvent(socket, "input", 0, i|skShift|skCtrl);
+ sendKeyEvent(socket, "up", 0, i|skShift|skCtrl);
+ sendText(socket, "\nEnd "+s+" With Shift+Ctrl\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Shift+Alt:\n");
+ sendKeyEvent(socket, "input", 0, i|skShift|skAlt);
+ sendKeyEvent(socket, "up", 0, i|skShift|skAlt);
+ sendText(socket, "\nEnd "+s+" With Shift+Alt\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Ctrl+Alt:\n");
+ sendKeyEvent(socket, "input", 0, i|skCtrl|skAlt);
+ sendKeyEvent(socket, "up", 0, i|skCtrl|skAlt);
+ sendText(socket, "\nEnd "+s+" With Ctrl+Alt\n");
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ sendText(socket, "\n"+s+" With Shift+Ctrl+Alt:\n");
+ sendKeyEvent(socket, "input", 0, i|skShift|skCtrl|skAlt);
+ sendKeyEvent(socket, "up", 0, i|skShift|skCtrl|skAlt);
+ sendText(socket, "\nEnd "+s+" With Shift+Ctrl+Alt\n");
+
+ if (i>=istart)
+ sendTextFrame(socket, f);
+
+ // This is to allow server to process the input, and check that everything is still OK
+ sendTextFrame(socket, "status");
+ getResponseMessage(socket, "status:");
+ }
+ // sendTextFrame(socket, "saveas url=file:///tmp/emptyempty.odt format= options=");
+}
+
+void TileCacheTests::testTileInvalidateCalc()
+{
+ std::string documentPath, documentURL;
+ getDocumentPathAndURL("empty.ods", documentPath, documentURL);
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+
+ auto socket = *loadDocAndGetSocket(_uri, documentURL);
+
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !getResponseMessage(socket, "invalidatetiles:").empty());
+
+ std::string text = "Test. Now go 3 \"Enters\":\n\n\nNow after the enters, goes this text";
+ for (char ch : text)
+ {
+ sendChar(socket, ch); // Send ordinary characters -> one tile invalidation for each
+ auto response = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response.empty());
+ }
+
+ text = "\n\n\n";
+ for (char ch : text)
+ {
+ sendChar(socket, ch, skCtrl); // Send 3 Ctrl+Enter -> 3 new pages; I see 3 tiles invalidated for each
+ auto response1 = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response1.empty());
+ auto response2 = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response2.empty());
+ auto response3 = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response3.empty());
+ }
+
+ text = "abcde";
+ for (char ch : text)
+ {
+ sendChar(socket, ch);
+ auto response = getResponseMessage(socket, "invalidatetiles:");
+ CPPUNIT_ASSERT_MESSAGE("did not receive a invalidatetiles: message as expected", !response.empty());
+ }
+
+ CPPUNIT_ASSERT_MESSAGE("received unexpected invalidatetiles: message", getResponseMessage(socket, "invalidatetiles:").empty());
+
+ socket.shutdown();
+}
+
void TileCacheTests::checkTiles(Poco::Net::WebSocket& socket, const std::string& docType)
{
const std::string current = "current=";
diff --git a/loolwsd/test/data/empty.odg b/loolwsd/test/data/empty.odg
new file mode 100755
index 0000000..b7dfa67
Binary files /dev/null and b/loolwsd/test/data/empty.odg differ
diff --git a/loolwsd/test/data/empty.odp b/loolwsd/test/data/empty.odp
new file mode 100755
index 0000000..5f4840e
Binary files /dev/null and b/loolwsd/test/data/empty.odp differ
diff --git a/loolwsd/test/data/empty.ods b/loolwsd/test/data/empty.ods
new file mode 100755
index 0000000..86414ec
Binary files /dev/null and b/loolwsd/test/data/empty.ods differ
diff --git a/loolwsd/test/data/empty.odt b/loolwsd/test/data/empty.odt
new file mode 100755
index 0000000..6b07475
Binary files /dev/null and b/loolwsd/test/data/empty.odt differ
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index eec98ac..54fac74 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -468,6 +468,66 @@ std::vector<char> getTileMessage(Poco::Net::WebSocket& ws, const std::string& na
return std::vector<char>();
}
+enum SpecialKey { skNone=0, skShift=0x1000, skCtrl=0x2000, skAlt=0x4000 };
+
+inline int getCharChar(char ch, SpecialKey specialKeys)
+{
+ // Some primitive code just suitable to basic needs of specific test.
+ // TODO: improve as appropriate.
+ if (specialKeys & (skCtrl | skAlt))
+ return 0;
+
+ switch (ch)
+ {
+ case '\x0a': // Enter
+ return 13;
+ default:
+ return ch;
+ }
+}
+
+inline int getCharKey(char ch, SpecialKey specialKeys)
+{
+ // Some primitive code just suitable to basic needs of specific test.
+ // TODO: improve as appropriate.
+ int result;
+ switch (ch)
+ {
+ case '\x0a': // Enter
+ result = 1280;
+ break;
+ default:
+ result = ch;
+ }
+ return result | specialKeys;
+}
+
+inline void sendKeyEvent(Poco::Net::WebSocket& socket, const char* type, int chr, int key)
+{
+ std::ostringstream ssIn;
+ ssIn << "key type=" << type << " char=" << chr << " key=" << key;
+ sendTextFrame(socket, ssIn.str());
+}
+
+inline void sendKeyPress(Poco::Net::WebSocket& socket, int chr, int key)
+{
+ sendKeyEvent(socket, "input", chr, key);
+ sendKeyEvent(socket, "up", chr, key);
+}
+
+inline void sendChar(Poco::Net::WebSocket& socket, char ch, SpecialKey specialKeys=skNone)
+{
+ sendKeyPress(socket, getCharChar(ch, specialKeys), getCharKey(ch, specialKeys));
+}
+
+inline void sendText(Poco::Net::WebSocket& socket, const std::string& text)
+{
+ for (char ch : text)
+ {
+ sendChar(socket, ch);
+ }
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list