test/Makefile.am | 8 ++ test/UnitWOPIVersionRestore.cpp | 119 ++++++++++++++++++++++++++++++++++++++++ test/WopiTestServer.hpp | 4 + 3 files changed, 128 insertions(+), 3 deletions(-)
New commits: commit 5bd4d6781813e0a91edc527cb33b4d4eb0f84c2d Author: Pranav Kant <pran...@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 diff --git a/test/Makefile.am b/test/Makefile.am index d7894bd9..1184f31f 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) @@ -85,6 +87,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 @@ -98,7 +102,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 0d18520e..feaf0c17 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 { commit 4aa496e9131958585f604796424d911207425b98 Author: Pranav Kant <pran...@collabora.co.uk> Date: Thu Feb 8 17:43:54 2018 +0530 Unused variable Change-Id: Ice363f65d2ce3af818cf28396449b6d0402d6fc7 diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp index f5cc4c82..0d18520e 100644 --- a/test/WopiTestServer.hpp +++ b/test/WopiTestServer.hpp @@ -44,7 +44,6 @@ public: _wopiSrc = ""; Poco::URI::encode(wopiURL.toString(), ":/?", _wopiSrc); - Poco::URI loolUri(helpers::getTestServerURI()); LOG_INF("Connecting to the fake WOPI server: /lool/" << _wopiSrc << "/ws"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits