[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - test/Makefile.am test/UnitWOPIVersionRestore.cpp test/WopiTestServer.hpp
Pranav Kant
pranavk at collabora.co.uk
Thu Feb 15 13:15:07 UTC 2018
test/Makefile.am | 8 ++
test/UnitWOPIVersionRestore.cpp | 119 ++++++++++++++++++++++++++++++++++++++++
test/WopiTestServer.hpp | 3 +
3 files changed, 128 insertions(+), 2 deletions(-)
New commits:
commit 61892b58eaa414c44ba9cc750cd4fc33c1be8d6e
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Feb 8 19:54:37 2018 +0530
versionrestore: unit test; checks if wsd saves a modified document
See comment for more details
Change-Id: If79537c4ca61926f06015ad6827a473d18a2a79f
(cherry picked from commit 5bd4d6781813e0a91edc527cb33b4d4eb0f84c2d)
Reviewed-on: https://gerrit.libreoffice.org/49755
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 4808573a..1e5e16dc 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,7 +17,9 @@ noinst_LTLIBRARIES = \
unit-storage.la unit-client.la \
unit-admin.la unit-tilecache.la \
unit-fuzz.la unit-oob.la unit-oauth.la \
- unit-wopi.la unit-wopi-saveas.la unit-wopi-ownertermination.la
+ unit-wopi.la unit-wopi-saveas.la \
+ unit-wopi-ownertermination.la unit-wopi-versionrestore.la
+
MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
AM_LDFLAGS = -pthread -module $(MAGIC_TO_FORCE_SHLIB_CREATION) $(ZLIB_LIBS)
@@ -84,6 +86,8 @@ unit_wopi_saveas_la_SOURCES = UnitWOPISaveAs.cpp
unit_wopi_saveas_la_LIBADD = $(CPPUNIT_LIBS)
unit_wopi_ownertermination_la_SOURCES = UnitWopiOwnertermination.cpp
unit_wopi_ownertermination_la_LIBADD = $(CPPUNIT_LIBS)
+unit_wopi_versionrestore_la_SOURCES = UnitWOPIVersionRestore.cpp
+unit_wopi_versionrestore_la_LIBADD = $(CPPUNIT_LIBS)
if HAVE_LO_PATH
SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -97,7 +101,7 @@ check-local:
./run_unit.sh --log-file test.log --trs-file test.trs
# FIXME 2: unit-oob.la fails with symbol undefined:
# UnitWSD::testHandleRequest(UnitWSD::TestRequest, UnitHTTPServerRequest&, UnitHTTPServerResponse&) ,
-TESTS = unit-prefork.la unit-tilecache.la unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la unit-wopi-ownertermination.la
+TESTS = unit-prefork.la unit-tilecache.la unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la unit-wopi-ownertermination.la unit-wopi-versionrestore.la
# TESTS = unit-client.la
# TESTS += unit-admin.la
# TESTS += unit-storage.la
diff --git a/test/UnitWOPIVersionRestore.cpp b/test/UnitWOPIVersionRestore.cpp
new file mode 100644
index 00000000..fb0c9400
--- /dev/null
+++ b/test/UnitWOPIVersionRestore.cpp
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "config.h"
+
+#include "WopiTestServer.hpp"
+#include "Log.hpp"
+#include "Unit.hpp"
+#include "UnitHTTP.hpp"
+#include "helpers.hpp"
+
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Timestamp.h>
+#include <Poco/Util/LayeredConfiguration.h>
+
+
+/*
+ * 1) Modifies a current document
+ * 2) Issue a version restore request
+ * 3) Wait for the ack from wsd
+ * 4) checks, after getting ack from wsd, if it saved our unsaved changes
+ */
+class UnitWOPIVersionRestore : public WopiTestServer
+{
+ enum class Phase
+ {
+ Load,
+ Modify,
+ VersionRestoreRequest,
+ VersionRestoreAck,
+ Polling
+ } _phase;
+
+ bool _isDocumentSaved = false;
+
+public:
+ UnitWOPIVersionRestore() :
+ _phase(Phase::Load)
+ {
+ }
+
+ void assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
+ {
+ if (_phase == Phase::Polling)
+ {
+ _isDocumentSaved = true;
+ }
+ }
+
+ bool filterSendMessage(const char* data, const size_t len, const WSOpCode /* code */, const bool /* flush */, int& /*unitReturn*/) override
+ {
+ std::string message(data, len);
+ if (message == "close: versionrestore: prerestore_ack")
+ {
+ _phase = Phase::VersionRestoreAck;
+ }
+
+ return false;
+ }
+
+ void invokeTest() override
+ {
+ constexpr char testName[] = "UnitWOPIVersionRestore";
+
+ switch (_phase)
+ {
+ case Phase::Load:
+ {
+ initWebsocket("/wopi/files/0?access_token=anything");
+
+ helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName);
+
+ _phase = Phase::Modify;
+ break;
+ }
+ case Phase::Modify:
+ {
+ helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "key type=input char=97 key=0", testName);
+ helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "key type=up char=0 key=512", testName);
+
+ _phase = Phase::VersionRestoreRequest;
+ SocketPoll::wakeupWorld();
+ break;
+ }
+ case Phase::VersionRestoreRequest:
+ {
+ // tell wsd that we are about to restore
+ helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "versionrestore prerestore", testName);
+ _phase = Phase::Polling;
+ break;
+ }
+ case Phase::VersionRestoreAck:
+ {
+ if (_isDocumentSaved)
+ exitTest(TestResult::Ok);
+
+ break;
+ }
+ case Phase::Polling:
+ {
+ // just wait for the results
+ break;
+ }
+ }
+ }
+};
+
+UnitBase *unit_create_wsd(void)
+{
+ return new UnitWOPIVersionRestore();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index f5cc4c82..aea66662 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -13,11 +13,14 @@
#include "Log.hpp"
#include "Unit.hpp"
#include "UnitHTTP.hpp"
+
+
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeFormatter.h>
#include <Poco/JSON/Object.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/URI.h>
+#include <Poco/Timestamp.h>
class WopiTestServer : public UnitWSD
{
More information about the Libreoffice-commits
mailing list