[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-1-0' - 2 commits - loolwsd/LOOLWSD.cpp loolwsd/test

Pranav Kant pranavk at collabora.co.uk
Thu Jul 21 07:42:12 UTC 2016


 loolwsd/LOOLWSD.cpp                      |    5 ++--
 loolwsd/test/integration-http-server.cpp |   37 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit bbf8e4033d4ab99b1938ad5ebe1600126aaa5b42
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jul 21 12:52:14 2016 +0530

    loolwsd: Restore test for convert-to API
    
    This got accidently removed in
    8e266391f13a7daa3b074ba2ae33ac4958d39ae0
    
    Change-Id: I3d03b1b75f05f5855397e46a7fccc30c794ca151
    (cherry picked from commit f684e505da11f0c800910cafde7d49de0bb5a568)

diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 09482e1..13b4213 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -45,6 +45,7 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testLoleafletPost);
     CPPUNIT_TEST(testScriptsAndLinksGet);
     CPPUNIT_TEST(testScriptsAndLinksPost);
+    CPPUNIT_TEST(testConvertTo);
 
     // This should be the last test:
     CPPUNIT_TEST(testNoExtraLoolKitsLeft);
@@ -58,6 +59,7 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
     void testLoleafletPost();
     void testScriptsAndLinksGet();
     void testScriptsAndLinksPost();
+    void testConvertTo();
 
     void testNoExtraLoolKitsLeft();
 
@@ -231,6 +233,41 @@ void HTTPServerTest::testScriptsAndLinksPost()
     assertHTTPFilesExist(_uri, link, html);
 }
 
+void HTTPServerTest::testConvertTo()
+{
+    const auto srcPath = Util::getTempFilePath(TDOC, "hello.odt");
+    std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
+
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/lool/convert-to");
+    Poco::Net::HTMLForm form;
+    form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
+    form.set("format", "txt");
+    form.addPart("data", new Poco::Net::FilePartSource(srcPath));
+    form.prepareSubmit(request);
+    // If this results in a Poco::Net::ConnectionRefusedException, loolwsd is not running.
+    form.write(session->sendRequest(request));
+
+    Poco::Net::HTTPResponse response;
+    std::stringstream actualStream;
+    // receiveResponse() resulted in a Poco::Net::NoMessageException.
+    std::istream& responseStream = session->receiveResponse(response);
+    Poco::StreamCopier::copyStream(responseStream, actualStream);
+
+    std::ifstream fileStream(TDOC "/hello.txt");
+    std::stringstream expectedStream;
+    expectedStream << fileStream.rdbuf();
+
+    // Remove the temp files.
+    Util::removeFile(srcPath);
+
+    // In some cases the result is prefixed with (the UTF-8 encoding of) the Unicode BOM
+    // (U+FEFF). Skip that.
+    std::string actualString = actualStream.str();
+    if (actualString.size() > 3 && actualString[0] == '\xEF' && actualString[1] == '\xBB' && actualString[2] == '\xBF')
+        actualString = actualString.substr(3);
+    CPPUNIT_ASSERT_EQUAL(expectedStream.str(), actualString);
+}
+
 void HTTPServerTest::testNoExtraLoolKitsLeft()
 {
     const auto countNow = countLoolKitProcesses(_initialLoolKitCount);
commit 4ef0788cf34f23c6f2aa9d6feb499966938bc8c5
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jul 21 12:33:14 2016 +0530

    loolwsd: Fix convert-to regression; fix incorrect filepath formed
    
    Regressed with 886af28bc2f6d1d27bf78de09978f3858d2db705
    
    Poco::URI::encode appends to given string, and encodedTo already
    had content leading to incorrect path. Use a new std::string variable.
    
    Change-Id: Ia72ff60ed9cf7f14ff649416a2ceeeda13ff6197
    (cherry picked from commit 39645c974d38c9494ec773ac493b2b7590e803fd)

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e5d41cc..7583537 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -417,8 +417,9 @@ private:
                     if (!resultURL.getPath().empty())
                     {
                         const std::string mimeType = "application/octet-stream";
-                        URI::encode(resultURL.getPath(), "", encodedTo);
-                        response.sendFile(encodedTo, mimeType);
+                        std::string encodedFilePath;
+                        URI::encode(resultURL.getPath(), "", encodedFilePath);
+                        response.sendFile(encodedFilePath, mimeType);
                         sent = true;
                     }
 


More information about the Libreoffice-commits mailing list