[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - test/UnitOAuth.cpp test/UnitWOPI.cpp test/WopiTestServer.hpp

Jan Holesovsky kendy at collabora.com
Mon Oct 2 17:09:04 UTC 2017


 test/UnitOAuth.cpp      |   18 +++++-------------
 test/UnitWOPI.cpp       |   14 ++------------
 test/WopiTestServer.hpp |   22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 25 deletions(-)

New commits:
commit e442a828fa9d3f87862931c20720bca20b55b062
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Sep 27 19:57:22 2017 +0200

    WopiTestServer: Share more code.
    
    Change-Id: Ied539169f96608adb7095682bd8f0b7a70d28491
    Reviewed-on: https://gerrit.libreoffice.org/42877
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/test/UnitOAuth.cpp b/test/UnitOAuth.cpp
index dfba4aa1..dcd2de65 100644
--- a/test/UnitOAuth.cpp
+++ b/test/UnitOAuth.cpp
@@ -98,20 +98,12 @@ public:
             case Phase::LoadToken:
             case Phase::LoadHeader:
             {
-                Poco::URI wopiURL(helpers::getTestServerURI() +
-                        ((_phase == Phase::LoadToken)? "/wopi/files/0?access_token=s3hn3ct0k3v":
-                                                   "/wopi/files/1?access_header=Authorization: Basic basic=="));
-                //wopiURL.setPort(_wopiSocket->address().port());
-                std::string wopiSrc;
-                Poco::URI::encode(wopiURL.toString(), ":/?", wopiSrc);
-                Poco::URI loolUri(helpers::getTestServerURI());
-
-                LOG_INF("Connecting to the fake WOPI server: /lool/" << wopiSrc << "/ws");
-
-                std::unique_ptr<UnitWebSocket> ws(new UnitWebSocket("/lool/" + wopiSrc + "/ws"));
-                assert(ws.get());
+                if (_phase == Phase::LoadToken)
+                    initWebsocket("/wopi/files/0?access_token=s3hn3ct0k3v");
+                else
+                    initWebsocket("/wopi/files/1?access_header=Authorization: Basic basic==");
 
-                helpers::sendTextFrame(*ws->getLOOLWebSocket(), "load url=" + wopiSrc, testName);
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName);
 
                 if (_phase == Phase::LoadToken)
                     _phase = Phase::LoadHeader;
diff --git a/test/UnitWOPI.cpp b/test/UnitWOPI.cpp
index fade8d0f..a1c7cbda 100644
--- a/test/UnitWOPI.cpp
+++ b/test/UnitWOPI.cpp
@@ -36,8 +36,6 @@ class UnitWOPI : public WopiTestServer
     bool _finishedSaveUnmodified;
     bool _finishedSaveModified;
 
-    std::unique_ptr<UnitWebSocket> _ws;
-
 public:
     UnitWOPI() :
         _phase(Phase::LoadAndSave),
@@ -78,17 +76,9 @@ public:
         {
             case Phase::LoadAndSave:
             {
-                Poco::URI wopiURL(helpers::getTestServerURI() + "/wopi/files/0?access_token=anything");
-                std::string wopiSrc;
-                Poco::URI::encode(wopiURL.toString(), ":/?", wopiSrc);
-                Poco::URI loolUri(helpers::getTestServerURI());
-
-                LOG_INF("Connecting to the fake WOPI server: /lool/" << wopiSrc << "/ws");
-
-                _ws.reset(new UnitWebSocket("/lool/" + wopiSrc + "/ws"));
-                assert(_ws.get());
+                initWebsocket("/wopi/files/0?access_token=anything");
 
-                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + wopiSrc, testName);
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName);
                 helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "save dontTerminateEdit=1 dontSaveIfUnmodified=0", testName);
 
                 _phase = Phase::Modify;
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index 5ac79e81..a3851b5d 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -9,6 +9,7 @@
 
 #include "config.h"
 
+#include "helpers.hpp"
 #include "Log.hpp"
 #include "Unit.hpp"
 #include "UnitHTTP.hpp"
@@ -20,11 +21,32 @@
 
 class WopiTestServer : public UnitWSD
 {
+protected:
+    /// The WOPISrc URL.
+    std::string _wopiSrc;
+
+    /// Websocket to communicate.
+    std::unique_ptr<UnitWebSocket> _ws;
+
 public:
     WopiTestServer() : UnitWSD()
     {
     }
 
+    void initWebsocket(std::string wopiName)
+    {
+        Poco::URI wopiURL(helpers::getTestServerURI() + wopiName);
+
+        _wopiSrc = "";
+        Poco::URI::encode(wopiURL.toString(), ":/?", _wopiSrc);
+        Poco::URI loolUri(helpers::getTestServerURI());
+
+        LOG_INF("Connecting to the fake WOPI server: /lool/" << _wopiSrc << "/ws");
+
+        _ws.reset(new UnitWebSocket("/lool/" + _wopiSrc + "/ws"));
+        assert(_ws.get());
+    }
+
     virtual void assertCheckFileInfoRequest(const Poco::Net::HTTPRequest& request) = 0;
 
     virtual void assertGetFileRequest(const Poco::Net::HTTPRequest& request) = 0;


More information about the Libreoffice-commits mailing list