diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-11-04 08:34:38 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-11-04 08:34:44 +0100 |
commit | cd75e2c5f47f51eee2308abc46b959a362fab59e (patch) | |
tree | 55b50867c11cb7701f22548a958ef17b1b56480d | |
parent | 2017b7284bbc487f489bfb6374876096537f5c17 (diff) |
Convert render shape tests to a new-style one
So that they are in-process, which means it's easier to debug when they
fail.
Change-Id: I4acbfaa32f6c771d860c0ff2782024b176690ee5
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/UnitRenderShape.cpp | 210 | ||||
-rw-r--r-- | test/httpwstest.cpp | 151 |
3 files changed, 214 insertions, 151 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index fa0fd6524..4907ae898 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -27,6 +27,7 @@ noinst_LTLIBRARIES = \ unit-load-torture.la \ unit-rendering-options.la \ unit-password-protected.la \ + unit-render-shape.la \ unit-wopi-loadencoded.la unit-wopi-temp.la MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy @@ -137,6 +138,8 @@ unit_rendering_options_la_SOURCES = UnitRenderingOptions.cpp unit_rendering_options_la_LIBADD = $(CPPUNIT_LIBS) 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) if HAVE_LO_PATH SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp @@ -162,6 +165,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t unit-load-torture.la \ unit-rendering-options.la \ unit-password-protected.la \ + unit-render-shape.la \ unit-wopi-loadencoded.la unit-wopi-temp.la # TESTS = unit-client.la # TESTS += unit-admin.la diff --git a/test/UnitRenderShape.cpp b/test/UnitRenderShape.cpp new file mode 100644 index 000000000..b15e94358 --- /dev/null +++ b/test/UnitRenderShape.cpp @@ -0,0 +1,210 @@ +/* -*- 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> + +class LOOLWebSocket; + +namespace +{ +/** + * Strips <desc>...</desc> strings from an SVG, some of which are only in debug builds, so breaks + * comparison with a fixed reference. + */ +void stripDescriptions(std::vector<char>& svg) +{ + static const std::string startDesc("<desc>"); + static const std::string endDesc("</desc>"); + static const std::string selfClose("/>"); + + while (true) + { + const auto itStart + = std::search(svg.begin(), svg.end(), startDesc.begin(), startDesc.end()); + if (itStart == svg.end()) + return; + + const auto itClose + = std::search(itStart + 1, svg.end(), selfClose.begin(), selfClose.end()); + + const auto itEnd = std::search(itStart + 1, svg.end(), endDesc.begin(), endDesc.end()); + + if (itEnd != svg.end() && itClose != svg.end()) + { + if (itEnd < itClose) + svg.erase(itStart, itEnd + endDesc.size()); + else + svg.erase(itStart, itClose + selfClose.size()); + } + else if (itEnd != svg.end()) + { + svg.erase(itStart, itEnd + endDesc.size()); + } + else if (itClose != svg.end()) + { + svg.erase(itStart, itClose + selfClose.size()); + } + else + { + // No more closing tags; possibly broken, as we found an opening tag. + return; + } + } +} +} + +/// Render shape testcase. +class UnitRenderShape : public UnitWSD +{ + TestResult testRenderShapeSelectionImpress(); + TestResult testRenderShapeSelectionWriter(); + TestResult testRenderShapeSelectionWriterImage(); + +public: + void invokeTest() override; +}; + +UnitBase::TestResult UnitRenderShape::testRenderShapeSelectionImpress() +{ + const char* testname = "testRenderShapeSelectionImpress "; + try + { + std::string documentPath, documentURL; + helpers::getDocumentPathAndURL("shapes.odp", documentPath, documentURL, testname); + + std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket( + Poco::URI(helpers::getTestServerURI()), documentURL, testname); + + int major = 0; + int minor = 0; + helpers::getServerVersion(socket, major, minor, testname); + if (major != 6 || minor != 0) + { + TST_LOG("Skipping test on incompatible client [" << major << '.' << minor + << "], expected [6.0]."); + return TestResult::Ok; + } + + helpers::selectAll(socket, testname); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + helpers::sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); + std::vector<char> responseSVG + = helpers::getResponseMessage(socket, "shapeselectioncontent:", testname); + CPPUNIT_ASSERT(!responseSVG.empty()); + auto it = std::find(responseSVG.begin(), responseSVG.end(), '\n'); + if (it != responseSVG.end()) + responseSVG.erase(responseSVG.begin(), ++it); + + stripDescriptions(responseSVG); + + CPPUNIT_ASSERT(helpers::svgMatch(testname, responseSVG, "shapes_impress.svg")); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } + + return TestResult::Ok; +} + +UnitBase::TestResult UnitRenderShape::testRenderShapeSelectionWriter() +{ + const char* testname = "testRenderShapeSelectionWriter "; + try + { + std::string documentPath, documentURL; + helpers::getDocumentPathAndURL("shape.odt", documentPath, documentURL, testname); + + std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket( + Poco::URI(helpers::getTestServerURI()), documentURL, testname); + + // Select the shape with SHIFT + F4 + helpers::sendKeyPress(socket, 0, 771 | helpers::SpecialKey::skShift, testname); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + helpers::sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); + std::vector<char> responseSVG + = helpers::getResponseMessage(socket, "shapeselectioncontent:", testname); + CPPUNIT_ASSERT(!responseSVG.empty()); + auto it = std::find(responseSVG.begin(), responseSVG.end(), '\n'); + if (it != responseSVG.end()) + responseSVG.erase(responseSVG.begin(), ++it); + + stripDescriptions(responseSVG); + + CPPUNIT_ASSERT(helpers::svgMatch(testname, responseSVG, "shapes_writer.svg")); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } + return TestResult::Ok; +} + +UnitBase::TestResult UnitRenderShape::testRenderShapeSelectionWriterImage() +{ + const char* testname = "testRenderShapeSelectionWriterImage "; + try + { + std::string documentPath, documentURL; + helpers::getDocumentPathAndURL("non-shape-image.odt", documentPath, documentURL, testname); + + std::shared_ptr<LOOLWebSocket> socket = helpers::loadDocAndGetSocket( + Poco::URI(helpers::getTestServerURI()), documentURL, testname); + + // Select the shape with SHIFT + F4 + helpers::sendKeyPress(socket, 0, 771 | helpers::SpecialKey::skShift, testname); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + helpers::sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); + std::vector<char> responseSVG + = helpers::getResponseMessage(socket, "shapeselectioncontent:", testname); + CPPUNIT_ASSERT(!responseSVG.empty()); + auto it = std::find(responseSVG.begin(), responseSVG.end(), '\n'); + if (it != responseSVG.end()) + responseSVG.erase(responseSVG.begin(), ++it); + + stripDescriptions(responseSVG); + + CPPUNIT_ASSERT(helpers::svgMatch(testname, responseSVG, "non_shape_writer_image.svg")); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } + + return TestResult::Ok; +} + +void UnitRenderShape::invokeTest() +{ + UnitBase::TestResult result = testRenderShapeSelectionImpress(); + if (result != TestResult::Ok) + exitTest(result); + + result = testRenderShapeSelectionWriter(); + if (result != TestResult::Ok) + exitTest(result); + + result = testRenderShapeSelectionWriterImage(); + if (result != TestResult::Ok) + exitTest(result); + + exitTest(TestResult::Ok); +} + +UnitBase* unit_create_wsd(void) { return new UnitRenderShape(); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp index d7a7b9100..e49e54a60 100644 --- a/test/httpwstest.cpp +++ b/test/httpwstest.cpp @@ -52,52 +52,6 @@ using namespace helpers; -namespace -{ -/** - * Strips <desc>...</desc> strings from an SVG, some of which are only in debug builds, so breaks - * comparison with a fixed reference. - */ -void stripDescriptions(std::vector<char>& svg) -{ - static const std::string startDesc("<desc>"); - static const std::string endDesc("</desc>"); - static const std::string selfClose("/>"); - - while (true) - { - const auto itStart = std::search(svg.begin(), svg.end(), startDesc.begin(), startDesc.end()); - if (itStart == svg.end()) - return; - - const auto itClose = std::search(itStart + 1, svg.end(), selfClose.begin(), selfClose.end()); - - const auto itEnd = std::search(itStart + 1, svg.end(), endDesc.begin(), endDesc.end()); - - if (itEnd != svg.end() && itClose != svg.end()) - { - if (itEnd < itClose) - svg.erase(itStart, itEnd + endDesc.size()); - else - svg.erase(itStart, itClose + selfClose.size()); - } - else if (itEnd != svg.end()) - { - svg.erase(itStart, itEnd + endDesc.size()); - } - else if (itClose != svg.end()) - { - svg.erase(itStart, itClose + selfClose.size()); - } - else - { - // No more closing tags; possibly broken, as we found an opening tag. - return; - } - } -} -} - /// Tests the HTTP WebSocket API of loolwsd. The server has to be started manually before running this test. class HTTPWSTest : public CPPUNIT_NS::TestFixture { @@ -148,9 +102,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testAlertAllUsers); CPPUNIT_TEST(testViewInfoMsg); CPPUNIT_TEST(testUndoConflict); - CPPUNIT_TEST(testRenderShapeSelectionImpress); - CPPUNIT_TEST(testRenderShapeSelectionWriter); - CPPUNIT_TEST(testRenderShapeSelectionWriterImage); CPPUNIT_TEST_SUITE_END(); @@ -196,9 +147,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testAlertAllUsers(); void testViewInfoMsg(); void testUndoConflict(); - void testRenderShapeSelectionImpress(); - void testRenderShapeSelectionWriter(); - void testRenderShapeSelectionWriterImage(); void loadDoc(const std::string& documentURL, const std::string& testname); @@ -2342,105 +2290,6 @@ void HTTPWSTest::testUndoConflict() } } -void HTTPWSTest::testRenderShapeSelectionImpress() -{ - const char* testname = "testRenderShapeSelectionImpress "; - try - { - std::string documentPath, documentURL; - getDocumentPathAndURL("shapes.odp", documentPath, documentURL, testname); - - std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname); - - int major = 0; - int minor = 0; - getServerVersion(socket, major, minor, testname); - if (major != 6 || minor != 0) - { - TST_LOG("Skipping test on incompatible client [" - << major << '.' << minor << "], expected [6.0]."); - return; - } - - selectAll(socket, testname); - std::this_thread::sleep_for(std::chrono::milliseconds(250)); - sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); - std::vector<char> responseSVG = getResponseMessage(socket, "shapeselectioncontent:", testname); - CPPUNIT_ASSERT(!responseSVG.empty()); - auto it = std::find(responseSVG.begin(), responseSVG.end(),'\n'); - if (it != responseSVG.end()) - responseSVG.erase(responseSVG.begin(), ++it); - - stripDescriptions(responseSVG); - - CPPUNIT_ASSERT(svgMatch(testname, responseSVG, "shapes_impress.svg")); - } - catch (const Poco::Exception& exc) - { - CPPUNIT_FAIL(exc.displayText()); - } -} - -void HTTPWSTest::testRenderShapeSelectionWriter() -{ - const char* testname = "testRenderShapeSelectionWriter "; - try - { - std::string documentPath, documentURL; - getDocumentPathAndURL("shape.odt", documentPath, documentURL, testname); - - std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname); - - // Select the shape with SHIFT + F4 - sendKeyPress(socket, 0, 771 | skShift, testname); - std::this_thread::sleep_for(std::chrono::milliseconds(250)); - sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); - std::vector<char> responseSVG = getResponseMessage(socket, "shapeselectioncontent:", testname); - CPPUNIT_ASSERT(!responseSVG.empty()); - auto it = std::find(responseSVG.begin(), responseSVG.end(),'\n'); - if (it != responseSVG.end()) - responseSVG.erase(responseSVG.begin(), ++it); - - stripDescriptions(responseSVG); - - CPPUNIT_ASSERT(svgMatch(testname, responseSVG, "shapes_writer.svg")); - } - catch (const Poco::Exception& exc) - { - CPPUNIT_FAIL(exc.displayText()); - } -} - -void HTTPWSTest::testRenderShapeSelectionWriterImage() -{ - const char* testname = "testRenderShapeSelectionWriterImage "; - try - { - std::string documentPath, documentURL; - getDocumentPathAndURL("non-shape-image.odt", documentPath, documentURL, testname); - - std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname); - - // Select the shape with SHIFT + F4 - sendKeyPress(socket, 0, 771 | skShift, testname); - std::this_thread::sleep_for(std::chrono::milliseconds(250)); - sendTextFrame(socket, "rendershapeselection mimetype=image/svg+xml", testname); - std::vector<char> responseSVG = getResponseMessage(socket, "shapeselectioncontent:", testname); - CPPUNIT_ASSERT(!responseSVG.empty()); - auto it = std::find(responseSVG.begin(), responseSVG.end(),'\n'); - if (it != responseSVG.end()) - responseSVG.erase(responseSVG.begin(), ++it); - - stripDescriptions(responseSVG); - - CPPUNIT_ASSERT(svgMatch(testname, responseSVG, "non_shape_writer_image.svg")); - } - catch (const Poco::Exception& exc) - { - CPPUNIT_FAIL(exc.displayText()); - } -} - CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |