[Libreoffice-commits] online.git: test/httpwstest.cpp test/Makefile.am test/UnitLoad.cpp

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 22 08:07:53 UTC 2019


 test/Makefile.am    |    4 
 test/UnitLoad.cpp   |  211 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/httpwstest.cpp |  136 ---------------------------------
 3 files changed, 215 insertions(+), 136 deletions(-)

New commits:
commit 0580f51f851558d2012d9548d82e1bf6aa3235f8
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 22 09:07:24 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 22 09:07:33 2019 +0100

    Convert doc load tests to a new-style one
    
    So that they are in-process, which means it's easier to debug when they
    fail.
    
    Change-Id: I2dcef46ec76e1f971172d1c29adf09103cfeaa7b

diff --git a/test/Makefile.am b/test/Makefile.am
index 30632a1f6..e10a58b21 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -31,6 +31,7 @@ noinst_LTLIBRARIES = \
 	unit-each-view.la \
 	unit-session.la \
 	unit-uno-command.la \
+	unit-load.la \
 	unit-wopi-loadencoded.la unit-wopi-temp.la
 
 MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
@@ -151,6 +152,8 @@ unit_session_la_SOURCES = UnitSession.cpp
 unit_session_la_LIBADD = $(CPPUNIT_LIBS)
 unit_uno_command_la_SOURCES = UnitUNOCommand.cpp
 unit_uno_command_la_LIBADD = $(CPPUNIT_LIBS)
+unit_load_la_SOURCES = UnitUNOCommand.cpp
+unit_load_la_LIBADD = $(CPPUNIT_LIBS)
 
 if HAVE_LO_PATH
 SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -180,6 +183,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
 	unit-each-view.la \
 	unit-session.la \
 	unit-uno-command.la \
+	unit-load.la \
 	unit-wopi-loadencoded.la unit-wopi-temp.la
 # TESTS = unit-client.la
 # TESTS += unit-admin.la
diff --git a/test/UnitLoad.cpp b/test/UnitLoad.cpp
new file mode 100644
index 000000000..bb549b732
--- /dev/null
+++ b/test/UnitLoad.cpp
@@ -0,0 +1,211 @@
+/* -*- 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 <memory>
+#include <ostream>
+#include <set>
+#include <string>
+
+#include <Poco/Exception.h>
+#include <Poco/RegularExpression.h>
+#include <Poco/URI.h>
+#include <cppunit/TestAssert.h>
+
+#include <Unit.hpp>
+#include <helpers.hpp>
+
+class LOOLWebSocket;
+
+namespace
+{
+void loadDoc(const std::string& documentURL, const std::string& testname)
+{
+    try
+    {
+        // Load a document and wait for the status.
+        // Don't replace with helpers, so we catch status.
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+        Poco::URI uri(helpers::getTestServerURI());
+        Poco::Net::HTTPResponse response;
+        std::shared_ptr<LOOLWebSocket> socket
+            = helpers::connectLOKit(uri, request, response, testname);
+        helpers::sendTextFrame(socket, "load url=" + documentURL, testname);
+
+        helpers::assertResponseString(socket, "status:", testname);
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+}
+}
+
+/// Test suite for loading.
+class UnitLoad : public UnitWSD
+{
+    TestResult testConnectNoLoad();
+    TestResult testLoadSimple();
+    TestResult testBadLoad();
+    TestResult testExcelLoad();
+    TestResult testReload();
+
+public:
+    void invokeTest() override;
+};
+
+UnitBase::TestResult UnitLoad::testConnectNoLoad()
+{
+    const char* testname1 = "connectNoLoad-1 ";
+    const char* testname2 = "connectNoLoad-2 ";
+    const char* testname3 = "connectNoLoad-3 ";
+
+    std::string documentPath, documentURL;
+    helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, "connectNoLoad ");
+
+    // Connect and disconnect without loading.
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+    TST_LOG_NAME(testname1, "Connecting first to disconnect without loading.");
+    Poco::Net::HTTPResponse response;
+    Poco::URI uri(helpers::getTestServerURI());
+    std::shared_ptr<LOOLWebSocket> socket
+        = helpers::connectLOKit(uri, request, response, testname1);
+    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket);
+    TST_LOG_NAME(testname1, "Disconnecting first.");
+    socket.reset();
+
+    // Connect and load first view.
+    TST_LOG_NAME(testname2, "Connecting second to load first view.");
+    std::shared_ptr<LOOLWebSocket> socket1
+        = helpers::connectLOKit(uri, request, response, testname2);
+    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket1);
+    helpers::sendTextFrame(socket1, "load url=" + documentURL, testname2);
+    CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL,
+                           helpers::isDocumentLoaded(socket1, testname2));
+
+    // Connect but don't load second view.
+    TST_LOG_NAME(testname3, "Connecting third to disconnect without loading.");
+    std::shared_ptr<LOOLWebSocket> socket2
+        = helpers::connectLOKit(uri, request, response, testname3);
+    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket2);
+    TST_LOG_NAME(testname3, "Disconnecting third.");
+    socket2.reset();
+
+    TST_LOG_NAME(testname2, "Getting status from first view.");
+    helpers::sendTextFrame(socket1, "status", testname2);
+    helpers::assertResponseString(socket1, "status:", testname2);
+
+    TST_LOG_NAME(testname2, "Disconnecting second.");
+    socket1.reset();
+    return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitLoad::testLoadSimple()
+{
+    const char* testname = "loadSimple ";
+
+    std::string documentPath, documentURL;
+    helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
+    loadDoc(documentURL, "load ");
+    return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitLoad::testBadLoad()
+{
+    const char* testname = "badLoad ";
+    try
+    {
+        // Load a document and get its status.
+        std::string documentPath, documentURL;
+        helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
+
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+        Poco::URI uri(helpers::getTestServerURI());
+        Poco::Net::HTTPResponse response;
+        std::shared_ptr<LOOLWebSocket> socket
+            = helpers::connectLOKit(uri, request, response, testname);
+
+        // Before loading request status.
+        helpers::sendTextFrame(socket, "status");
+
+        const auto line = helpers::assertResponseString(socket, "error:", testname);
+        CPPUNIT_ASSERT_EQUAL(std::string("error: cmd=status kind=nodocloaded"), line);
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+    return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitLoad::testExcelLoad()
+{
+    const char* testname = "excelLoad ";
+    try
+    {
+        // Load a document and get status.
+        Poco::URI uri(helpers::getTestServerURI());
+        std::shared_ptr<LOOLWebSocket> socket
+            = helpers::loadDocAndGetSocket("timeline.xlsx", uri, testname);
+
+        helpers::sendTextFrame(socket, "status", testname);
+        const auto status = helpers::assertResponseString(socket, "status:", testname);
+
+        // Expected format is something like 'status: type=text parts=2 current=0 width=12808 height=1142 viewid=0\n...'.
+        std::vector<std::string> tokens(LOOLProtocol::tokenize(status, ' '));
+        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), tokens.size());
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+    return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitLoad::testReload()
+{
+    const char* testname = "reload ";
+
+    std::string documentPath, documentURL;
+    helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
+    for (int i = 0; i < 3; ++i)
+    {
+        TST_LOG("loading #" << (i + 1));
+        loadDoc(documentURL, testname);
+    }
+    return TestResult::Ok;
+}
+
+void UnitLoad::invokeTest()
+{
+    UnitBase::TestResult result = testConnectNoLoad();
+    if (result != TestResult::Ok)
+        exitTest(result);
+
+    result = testLoadSimple();
+    if (result != TestResult::Ok)
+        exitTest(result);
+
+    result = testLoadSimple();
+    if (result != TestResult::Ok)
+        exitTest(result);
+
+    result = testExcelLoad();
+    if (result != TestResult::Ok)
+        exitTest(result);
+
+    result = testReload();
+    if (result != TestResult::Ok)
+        exitTest(result);
+
+    exitTest(TestResult::Ok);
+}
+
+UnitBase* unit_create_wsd(void) { return new UnitLoad(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp
index 2a7a3db9b..5410c3b50 100644
--- a/test/httpwstest.cpp
+++ b/test/httpwstest.cpp
@@ -41,15 +41,10 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE(HTTPWSTest);
 
     CPPUNIT_TEST(testCloseAfterClose);
-    CPPUNIT_TEST(testConnectNoLoad);
-    CPPUNIT_TEST(testLoadSimple);
-    CPPUNIT_TEST(testBadLoad);
-    CPPUNIT_TEST(testReload);
     CPPUNIT_TEST(testGetTextSelection);
     CPPUNIT_TEST(testSaveOnDisconnect);
     CPPUNIT_TEST(testSavePassiveOnDisconnect);
     CPPUNIT_TEST(testReloadWhileDisconnecting);
-    CPPUNIT_TEST(testExcelLoad);
     CPPUNIT_TEST(testPasteBlank);
     CPPUNIT_TEST(testInsertDelete);
     CPPUNIT_TEST(testInactiveClient);
@@ -73,15 +68,10 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
     void testCloseAfterClose();
-    void testConnectNoLoad();
-    void testLoadSimple();
-    void testBadLoad();
-    void testReload();
     void testGetTextSelection();
     void testSaveOnDisconnect();
     void testSavePassiveOnDisconnect();
     void testReloadWhileDisconnecting();
-    void testExcelLoad();
     void testPasteBlank();
     void testInsertDelete();
     void testInactiveClient();
@@ -102,8 +92,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     void testViewInfoMsg();
     void testUndoConflict();
 
-    void loadDoc(const std::string& documentURL, const std::string& testname);
-
     void getPartHashCodes(const std::string& testname,
                           const std::string& response,
                           std::vector<std::string>& parts);
@@ -213,109 +201,6 @@ void HTTPWSTest::testCloseAfterClose()
     }
 }
 
-void HTTPWSTest::loadDoc(const std::string& documentURL, const std::string& testname)
-{
-    try
-    {
-        // Load a document and wait for the status.
-        // Don't replace with helpers, so we catch status.
-        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
-        std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-        sendTextFrame(socket, "load url=" + documentURL, testname);
-
-        assertResponseString(socket, "status:", testname);
-    }
-    catch (const Poco::Exception& exc)
-    {
-        CPPUNIT_FAIL(exc.displayText());
-    }
-}
-
-void HTTPWSTest::testConnectNoLoad()
-{
-    const char* testname1 = "connectNoLoad-1 ";
-    const char* testname2 = "connectNoLoad-2 ";
-    const char* testname3 = "connectNoLoad-3 ";
-
-    std::string documentPath, documentURL;
-    getDocumentPathAndURL("hello.odt", documentPath, documentURL, "connectNoLoad ");
-
-    // Connect and disconnect without loading.
-    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
-    TST_LOG_NAME(testname1, "Connecting first to disconnect without loading.");
-    std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname1);
-    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket);
-    TST_LOG_NAME(testname1, "Disconnecting first.");
-    socket.reset();
-
-    // Connect and load first view.
-    TST_LOG_NAME(testname2, "Connecting second to load first view.");
-    std::shared_ptr<LOOLWebSocket> socket1 = connectLOKit(_uri, request, _response, testname2);
-    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket1);
-    sendTextFrame(socket1, "load url=" + documentURL, testname2);
-    CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket1, testname2));
-
-    // Connect but don't load second view.
-    TST_LOG_NAME(testname3, "Connecting third to disconnect without loading.");
-    std::shared_ptr<LOOLWebSocket> socket2 = connectLOKit(_uri, request, _response, testname3);
-    CPPUNIT_ASSERT_MESSAGE("Failed to connect.", socket2);
-    TST_LOG_NAME(testname3, "Disconnecting third.");
-    socket2.reset();
-
-    TST_LOG_NAME(testname2, "Getting status from first view.");
-    sendTextFrame(socket1, "status", testname2);
-    assertResponseString(socket1, "status:", testname2);
-
-    TST_LOG_NAME(testname2, "Disconnecting second.");
-    socket1.reset();
-}
-
-void HTTPWSTest::testLoadSimple()
-{
-    const char* testname = "loadSimple ";
-
-    std::string documentPath, documentURL;
-    getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
-    loadDoc(documentURL, "load ");
-}
-
-void HTTPWSTest::testBadLoad()
-{
-    const char* testname = "badLoad ";
-    try
-    {
-        // Load a document and get its status.
-        std::string documentPath, documentURL;
-        getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
-
-        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
-        std::shared_ptr<LOOLWebSocket> socket = connectLOKit(_uri, request, _response, testname);
-
-        // Before loading request status.
-        sendTextFrame(socket, "status");
-
-        const auto line = assertResponseString(socket, "error:", testname);
-        CPPUNIT_ASSERT_EQUAL(std::string("error: cmd=status kind=nodocloaded"), line);
-    }
-    catch (const Poco::Exception& exc)
-    {
-        CPPUNIT_FAIL(exc.displayText());
-    }
-}
-
-void HTTPWSTest::testReload()
-{
-    const char* testname = "reload ";
-
-    std::string documentPath, documentURL;
-    getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
-    for (int i = 0; i < 3; ++i)
-    {
-        TST_LOG("loading #" << (i+1));
-        loadDoc(documentURL, testname);
-    }
-}
-
 void HTTPWSTest::testGetTextSelection()
 {
     const char* testname = "getTextSelection ";
@@ -511,27 +396,6 @@ void HTTPWSTest::testReloadWhileDisconnecting()
     }
 }
 
-void HTTPWSTest::testExcelLoad()
-{
-    const char* testname = "excelLoad ";
-    try
-    {
-        // Load a document and get status.
-        std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket("timeline.xlsx", _uri, testname);
-
-        sendTextFrame(socket, "status", testname);
-        const auto status = assertResponseString(socket, "status:", testname);
-
-        // Expected format is something like 'status: type=text parts=2 current=0 width=12808 height=1142 viewid=0\n...'.
-        std::vector<std::string> tokens(LOOLProtocol::tokenize(status, ' '));
-        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), tokens.size());
-    }
-    catch (const Poco::Exception& exc)
-    {
-        CPPUNIT_FAIL(exc.displayText());
-    }
-}
-
 void HTTPWSTest::testPasteBlank()
 {
     const char* testname = "pasteBlank ";


More information about the Libreoffice-commits mailing list