From 2be50b7e174350469ee5507f7e346ff0705e876f Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sat, 30 Apr 2022 12:29:23 -0400 Subject: [PATCH] wsd: test: refactor test filename Change-Id: Ida6c181afc98928e6a5dca5b6928f900668a5ea7 Signed-off-by: Ashod Nakashian --- test/UnitWOPISlow.cpp | 13 ++++++++++++- test/WopiTestServer.hpp | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/UnitWOPISlow.cpp b/test/UnitWOPISlow.cpp index 28bb3143e..3e83ad4a9 100644 --- a/test/UnitWOPISlow.cpp +++ b/test/UnitWOPISlow.cpp @@ -63,6 +63,17 @@ public: setFileContent(Util::toString(data)); } + /// Given a URI, returns the filename. + std::string getFilename(const Poco::URI& uri) const override + { + if (uri.getPath() == (getRootPath() + LargeDocumentFilename)) + { + return LargeDocumentFilename; + } + + return WopiTestServer::getFilename(uri); + } + bool handleHttpRequest(const Poco::Net::HTTPRequest& request, Poco::MemoryInputStream& message, std::shared_ptr& socket) override { @@ -84,7 +95,7 @@ public: assertCheckFileInfoRequest(request); Poco::JSON::Object::Ptr fileInfo = new Poco::JSON::Object(); - fileInfo->set("BaseFileName", LargeDocumentFilename); + fileInfo->set("BaseFileName", getFilename(uriReq)); fileInfo->set("Size", getFileContent().size()); fileInfo->set("Version", "1.0"); fileInfo->set("OwnerId", "test"); diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp index 6d8ffd69b..f3956c1ad 100644 --- a/test/WopiTestServer.hpp +++ b/test/WopiTestServer.hpp @@ -163,6 +163,19 @@ protected: { } + /// Given a URI, returns the filename. + virtual std::string getFilename(const Poco::URI& uri) const + { + return uri.getPath() == (getRootPath() + "3") ? "he%llo.txt" : "hello.txt"; + } + + /// Returns the virtual root-path that we serve. + static const std::string& getRootPath() + { + static const std::string RootPath = "/wopi/files/"; + return RootPath; + } + void configure(Poco::Util::LayeredConfiguration& config) override { UnitWSD::configure(config); @@ -201,9 +214,8 @@ protected: assertCheckFileInfoRequest(request); - const std::string fileName(uriReq.getPath() == "/wopi/files/3" ? "he%llo.txt" : "hello.txt"); Poco::JSON::Object::Ptr fileInfo = new Poco::JSON::Object(); - fileInfo->set("BaseFileName", fileName); + fileInfo->set("BaseFileName", getFilename(uriReq)); fileInfo->set("Size", getFileContent().size()); fileInfo->set("Version", "1.0"); fileInfo->set("OwnerId", "test");