test/Makefile.am | 4 + test/UnitEachView.cpp | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/httpwstest.cpp | 108 ---------------------------- 3 files changed, 196 insertions(+), 108 deletions(-)
New commits: commit 3cf185a5767ced554d58eeb29bff8fd5a7553ff6 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Nov 12 08:47:39 2019 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Nov 12 08:47:47 2019 +0100 Convert "each view" tests to a new-style one So that they are in-process, which means it's easier to debug when they fail. Change-Id: Ia16009f6047acdba531a7bfc50419dfb8ad0ca29 diff --git a/test/Makefile.am b/test/Makefile.am index f3d4fcf6f..243939595 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -28,6 +28,7 @@ noinst_LTLIBRARIES = \ unit-rendering-options.la \ unit-password-protected.la \ unit-render-shape.la \ + unit-each-view.la \ unit-wopi-loadencoded.la unit-wopi-temp.la MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy @@ -142,6 +143,8 @@ unit_password_protected_la_SOURCES = UnitPasswordProtected.cpp unit_password_protected_la_LIBADD = $(CPPUNIT_LIBS) unit_render_shape_la_SOURCES = UnitRenderShape.cpp unit_render_shape_la_LIBADD = $(CPPUNIT_LIBS) +unit_each_view_la_SOURCES = UnitEachView.cpp +unit_each_view_la_LIBADD = $(CPPUNIT_LIBS) if HAVE_LO_PATH SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp @@ -168,6 +171,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t unit-rendering-options.la \ unit-password-protected.la \ unit-render-shape.la \ + unit-each-view.la \ unit-wopi-loadencoded.la unit-wopi-temp.la # TESTS = unit-client.la # TESTS += unit-admin.la diff --git a/test/UnitEachView.cpp b/test/UnitEachView.cpp new file mode 100644 index 000000000..40f4b1302 --- /dev/null +++ b/test/UnitEachView.cpp @@ -0,0 +1,192 @@ +/* -*- 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 <string> + +#include <Poco/URI.h> +#include <cppunit/TestAssert.h> + +#include <Unit.hpp> +#include <Util.hpp> +#include <helpers.hpp> + +// Include config.h last, so the test server URI is still HTTP, even in SSL builds. +#include <config.h> + +class LOOLWebSocket; + +namespace +{ +void testEachView(const std::string& doc, const std::string& type, const std::string& protocol, + const std::string& protocolView, const std::string& testname) +{ + const std::string view = testname + "view %d -> "; + const std::string error = testname + "view %d, did not receive a %s message as expected"; + + try + { + // Load a document + std::string documentPath, documentURL; + helpers::getDocumentPathAndURL(doc, documentPath, documentURL, testname); + + int itView = 0; + std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket( + Poco::URI(helpers::getTestServerURI()), documentURL, Poco::format(view, itView)); + + // Check document size + helpers::sendTextFrame(socket, "status", Poco::format(view, itView)); + auto response + = helpers::assertResponseString(socket, "status:", Poco::format(view, itView)); + int docPart = -1; + int docParts = 0; + int docHeight = 0; + int docWidth = 0; + int docViewId = -1; + helpers::parseDocSize(response.substr(7), type, docPart, docParts, docWidth, docHeight, + docViewId); + + // Send click message + std::string text; + Poco::format(text, "mouse type=%s x=%d y=%d count=1 buttons=1 modifier=0", + std::string("buttondown"), docWidth / 2, docHeight / 6); + helpers::sendTextFrame(socket, text, Poco::format(view, itView)); + text.clear(); + + Poco::format(text, "mouse type=%s x=%d y=%d count=1 buttons=1 modifier=0", + std::string("buttonup"), docWidth / 2, docHeight / 6); + helpers::sendTextFrame(socket, text, Poco::format(view, itView)); + response = helpers::getResponseString(socket, protocol, Poco::format(view, itView)); + CPPUNIT_ASSERT_MESSAGE(Poco::format(error, itView, protocol), !response.empty()); + + // Connect and load 0..N Views, where N<=limit + std::vector<std::shared_ptr<LOOLWebSocket>> views; + static_assert(MAX_DOCUMENTS >= 2, "MAX_DOCUMENTS must be at least 2"); + const int limit = std::min(4, MAX_DOCUMENTS - 1); // +1 connection above + for (itView = 0; itView < limit; ++itView) + { + views.emplace_back(helpers::loadDocAndGetSocket( + Poco::URI(helpers::getTestServerURI()), documentURL, Poco::format(view, itView))); + } + + // main view should receive response each view + itView = 0; + for (const auto& socketView : views) + { + helpers::getResponseString(socket, protocolView, Poco::format(view, itView)); + CPPUNIT_ASSERT_MESSAGE(Poco::format(error, itView, protocolView), !response.empty()); + ++itView; + (void)socketView; + } + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } + catch (const std::exception& exc) + { + CPPUNIT_FAIL(exc.what()); + } +} +} + +/// Test suite that asserts a state for each view. +class UnitEachView : public UnitWSD +{ + TestResult testInvalidateViewCursor(); + TestResult testViewCursorVisible(); + TestResult testCellViewCursor(); + TestResult testGraphicViewSelectionWriter(); + TestResult testGraphicViewSelectionCalc(); + TestResult testGraphicViewSelectionImpress(); + +public: + UnitEachView(); + void invokeTest() override; +}; + +UnitBase::TestResult UnitEachView::testInvalidateViewCursor() +{ + testEachView("viewcursor.odp", "presentation", + "invalidatecursor:", "invalidateviewcursor:", "invalidateViewCursor "); + return TestResult::Ok; +} + +UnitBase::TestResult UnitEachView::testViewCursorVisible() +{ + testEachView("viewcursor.odp", "presentation", + "cursorvisible:", "viewcursorvisible:", "viewCursorVisible "); + return TestResult::Ok; +} + +UnitBase::TestResult UnitEachView::testCellViewCursor() +{ + testEachView("empty.ods", "spreadsheet", "cellcursor:", "cellviewcursor:", "cellViewCursor"); + return TestResult::Ok; +} + +UnitBase::TestResult UnitEachView::testGraphicViewSelectionWriter() +{ + testEachView("graphicviewselection.odt", "text", + "graphicselection:", "graphicviewselection:", "graphicViewSelection-odt "); + return TestResult::Ok; +} + +UnitBase::TestResult UnitEachView::testGraphicViewSelectionCalc() +{ + testEachView("graphicviewselection.ods", "spreadsheet", + "graphicselection:", "graphicviewselection:", "graphicViewSelection-ods "); + return TestResult::Ok; +} + +UnitBase::TestResult UnitEachView::testGraphicViewSelectionImpress() +{ + testEachView("graphicviewselection.odp", "presentation", + "graphicselection:", "graphicviewselection:", "graphicViewSelection-odp "); + return TestResult::Ok; +} + +UnitEachView::UnitEachView() +{ + // Double of the default. + setTimeout(60 * 1000); +} + +void UnitEachView::invokeTest() +{ + UnitBase::TestResult result = testInvalidateViewCursor(); + if (result != TestResult::Ok) + exitTest(result); + + result = testViewCursorVisible(); + if (result != TestResult::Ok) + exitTest(result); + + result = testCellViewCursor(); + if (result != TestResult::Ok) + exitTest(result); + + result = testGraphicViewSelectionWriter(); + if (result != TestResult::Ok) + exitTest(result); + + result = testGraphicViewSelectionCalc(); + if (result != TestResult::Ok) + exitTest(result); + + result = testGraphicViewSelectionImpress(); + if (result != TestResult::Ok) + exitTest(result); + + exitTest(TestResult::Ok); +} + +UnitBase* unit_create_wsd(void) { return new UnitEachView(); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp index bd5c11ec9..92276cd46 100644 --- a/test/httpwstest.cpp +++ b/test/httpwstest.cpp @@ -90,12 +90,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testStateUnoCommandImpress); // FIXME CPPUNIT_TEST(testColumnRowResize); // FIXME CPPUNIT_TEST(testOptimalResize); - CPPUNIT_TEST(testInvalidateViewCursor); - CPPUNIT_TEST(testViewCursorVisible); - CPPUNIT_TEST(testCellViewCursor); - CPPUNIT_TEST(testGraphicViewSelectionWriter); - CPPUNIT_TEST(testGraphicViewSelectionCalc); - CPPUNIT_TEST(testGraphicViewSelectionImpress); CPPUNIT_TEST(testGraphicInvalidate); CPPUNIT_TEST(testCursorPosition); CPPUNIT_TEST(testAlertAllUsers); @@ -135,12 +129,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testStateUnoCommandImpress(); void testColumnRowResize(); void testOptimalResize(); - void testInvalidateViewCursor(); - void testViewCursorVisible(); - void testCellViewCursor(); - void testGraphicViewSelectionWriter(); - void testGraphicViewSelectionCalc(); - void testGraphicViewSelectionImpress(); void testGraphicInvalidate(); void testCursorPosition(); void testAlertAllUsers(); @@ -171,7 +159,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testStateChanged(const std::string& filename, std::set<std::string>& vecComands); double getColRowSize(const std::string& property, const std::string& message, int index); double getColRowSize(const std::shared_ptr<LOOLWebSocket>& socket, const std::string& item, int index, const std::string& testname); - void testEachView(const std::string& doc, const std::string& type, const std::string& protocol, const std::string& view, const std::string& testname); public: HTTPWSTest() @@ -1956,101 +1943,6 @@ void HTTPWSTest::testOptimalResize() } } -void HTTPWSTest::testEachView(const std::string& doc, const std::string& type, - const std::string& protocol, const std::string& protocolView, - const std::string& testname) -{ - const std::string view = testname + "view %d -> "; - const std::string error = testname + "view %d, did not receive a %s message as expected"; - - try - { - // Load a document - std::string documentPath, documentURL; - getDocumentPathAndURL(doc, documentPath, documentURL, testname); - - int itView = 0; - std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, Poco::format(view, itView)); - - // Check document size - sendTextFrame(socket, "status", Poco::format(view, itView)); - auto response = assertResponseString(socket, "status:", Poco::format(view, itView)); - int docPart = -1; - int docParts = 0; - int docHeight = 0; - int docWidth = 0; - int docViewId = -1; - parseDocSize(response.substr(7), type, docPart, docParts, docWidth, docHeight, docViewId); - - // Send click message - std::string text; - Poco::format(text, "mouse type=%s x=%d y=%d count=1 buttons=1 modifier=0", std::string("buttondown"), docWidth/2, docHeight/6); - sendTextFrame(socket, text, Poco::format(view, itView)); - text.clear(); - - Poco::format(text, "mouse type=%s x=%d y=%d count=1 buttons=1 modifier=0", std::string("buttonup"), docWidth/2, docHeight/6); - sendTextFrame(socket, text, Poco::format(view, itView)); - response = getResponseString(socket, protocol, Poco::format(view, itView)); - CPPUNIT_ASSERT_MESSAGE(Poco::format(error, itView, protocol), !response.empty()); - - // Connect and load 0..N Views, where N<=limit - std::vector<std::shared_ptr<LOOLWebSocket>> views; - static_assert(MAX_DOCUMENTS >= 2, "MAX_DOCUMENTS must be at least 2"); - const int limit = std::min(4, MAX_DOCUMENTS - 1); // +1 connection above - for (itView = 0; itView < limit; ++itView) - { - views.emplace_back(loadDocAndGetSocket(_uri, documentURL, Poco::format(view, itView))); - } - - // main view should receive response each view - itView = 0; - for (const auto& socketView : views) - { - getResponseString(socket, protocolView, Poco::format(view, itView)); - CPPUNIT_ASSERT_MESSAGE(Poco::format(error, itView, protocolView), !response.empty()); - ++itView; (void)socketView; - } - } - catch (const Poco::Exception& exc) - { - CPPUNIT_FAIL(exc.displayText()); - } - catch (const std::exception& exc) - { - CPPUNIT_FAIL(exc.what()); - } -} - -void HTTPWSTest::testInvalidateViewCursor() -{ - testEachView("viewcursor.odp", "presentation", "invalidatecursor:", "invalidateviewcursor:", "invalidateViewCursor "); -} - -void HTTPWSTest::testViewCursorVisible() -{ - testEachView("viewcursor.odp", "presentation", "cursorvisible:", "viewcursorvisible:", "viewCursorVisible "); -} - -void HTTPWSTest::testCellViewCursor() -{ - testEachView("empty.ods", "spreadsheet", "cellcursor:", "cellviewcursor:", "cellViewCursor"); -} - -void HTTPWSTest::testGraphicViewSelectionWriter() -{ - testEachView("graphicviewselection.odt", "text", "graphicselection:", "graphicviewselection:", "graphicViewSelection-odt "); -} - -void HTTPWSTest::testGraphicViewSelectionCalc() -{ - testEachView("graphicviewselection.ods", "spreadsheet", "graphicselection:", "graphicviewselection:", "graphicViewSelection-ods "); -} - -void HTTPWSTest::testGraphicViewSelectionImpress() -{ - testEachView("graphicviewselection.odp", "presentation", "graphicselection:", "graphicviewselection:", "graphicViewSelection-odp "); -} - void HTTPWSTest::testGraphicInvalidate() { const char* testname = "graphicInvalidate "; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits