sw/Library_swqahelper.mk | 2 sw/qa/extras/tiledrendering/tiledrenderingmodeltestbase.cxx | 240 ------------ sw/qa/inc/swtiledrenderingtest.hxx | 63 +++ sw/qa/unit/swtiledrenderingtest.cxx | 223 +++++++++++ 4 files changed, 289 insertions(+), 239 deletions(-)
New commits: commit 335d041133fc86ab475ed9f85dd4123ffc925dba Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 2 08:18:26 2025 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 2 09:20:01 2025 +0100 sw: move SwTiledRenderingTest to Library_swqahelper Towards not including .cxx files in Writer tests. Change-Id: I92b3eb6d2208ba10797d0363fca53df5acc98324 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179598 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/Library_swqahelper.mk b/sw/Library_swqahelper.mk index ec379d979658..aa0f05575340 100644 --- a/sw/Library_swqahelper.mk +++ b/sw/Library_swqahelper.mk @@ -12,6 +12,7 @@ $(eval $(call gb_Library_Library,swqahelper)) $(eval $(call gb_Library_set_include,swqahelper,\ -I$(SRCDIR)/sw/inc \ -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ -I$(SRCDIR)/sw/qa/inc \ $$(INCLUDE) \ )) @@ -66,6 +67,7 @@ $(eval $(call gb_Library_use_libraries,swqahelper,\ $(eval $(call gb_Library_add_exception_objects,swqahelper,\ sw/qa/unit/swmodeltestbase \ + sw/qa/unit/swtiledrenderingtest \ )) # vim: set noet sw=4 ts=4: diff --git a/sw/qa/extras/tiledrendering/tiledrenderingmodeltestbase.cxx b/sw/qa/extras/tiledrendering/tiledrenderingmodeltestbase.cxx index 96bfd851ce0c..3d902b99b39d 100644 --- a/sw/qa/extras/tiledrendering/tiledrenderingmodeltestbase.cxx +++ b/sw/qa/extras/tiledrendering/tiledrenderingmodeltestbase.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <swmodeltestbase.hxx> +#include <swtiledrenderingtest.hxx> #include <com/sun/star/frame/DispatchResultState.hpp> #include <com/sun/star/frame/XDispatchResultListener.hpp> @@ -23,244 +23,6 @@ #include <unotxdoc.hxx> #include <wrtsh.hxx> -/// Testsuite for the SwXTextDocument methods implementing the vcl::ITiledRenderable interface. -class SwTiledRenderingTest : public SwModelTestBase -{ -public: - SwTiledRenderingTest(); - virtual void setUp() override; - virtual void tearDown() override; - -protected: - SwXTextDocument* createDoc(const char* pName = nullptr); - void setupLibreOfficeKitViewCallback(SfxViewShell* pViewShell); - static void callback(int nType, const char* pPayload, void* pData); - void callbackImpl(int nType, const char* pPayload); - // First invalidation. - tools::Rectangle m_aInvalidation; - /// Union of all invalidations. - tools::Rectangle m_aInvalidations; - Size m_aDocumentSize; - OString m_aTextSelection; - bool m_bFound; - std::vector<OString> m_aSearchResultSelection; - std::vector<int> m_aSearchResultPart; - int m_nSelectionBeforeSearchResult; - int m_nSelectionAfterSearchResult; - int m_nInvalidations; - int m_nRedlineTableSizeChanged; - int m_nRedlineTableEntryModified; - int m_nTrackedChangeIndex; - bool m_bFullInvalidateSeen; - OString m_sHyperlinkText; - OString m_sHyperlinkLink; - OString m_aFormFieldButton; - OString m_aContentControl; - OString m_ShapeSelection; - struct - { - std::string text; - std::string rect; - } m_aTooltip; - TestLokCallbackWrapper m_callbackWrapper; -}; - -SwTiledRenderingTest::SwTiledRenderingTest() - : SwModelTestBase(u"/sw/qa/extras/tiledrendering/data/"_ustr) - , m_bFound(true) - , m_nSelectionBeforeSearchResult(0) - , m_nSelectionAfterSearchResult(0) - , m_nInvalidations(0) - , m_nRedlineTableSizeChanged(0) - , m_nRedlineTableEntryModified(0) - , m_nTrackedChangeIndex(-1) - , m_bFullInvalidateSeen(false) - , m_callbackWrapper(&callback, this) -{ -} - -void SwTiledRenderingTest::setUp() -{ - SwModelTestBase::setUp(); - - SwGlobals::ensure(); - SwModule::get()->ClearRedlineAuthors(); - - comphelper::LibreOfficeKit::setActive(true); -} - -void SwTiledRenderingTest::tearDown() -{ - if (mxComponent.is()) - { - SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); - if (pWrtShell) - { - pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(nullptr); - } - mxComponent->dispose(); - mxComponent.clear(); - } - m_callbackWrapper.clear(); - comphelper::LibreOfficeKit::setActive(false); - - test::BootstrapFixture::tearDown(); -} - -SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) -{ - if (!pName) - createSwDoc(); - else - createSwDoc(pName); - - SwXTextDocument* pTextDocument = getSwTextDoc(); - pTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); - return pTextDocument; -} - -void SwTiledRenderingTest::setupLibreOfficeKitViewCallback(SfxViewShell* pViewShell) -{ - pViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); - m_callbackWrapper.setLOKViewId(SfxLokHelper::getView(pViewShell)); -} - -void SwTiledRenderingTest::callback(int nType, const char* pPayload, void* pData) -{ - static_cast<SwTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload); -} - -void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) -{ - OString aPayload(pPayload); - switch (nType) - { - case LOK_CALLBACK_INVALIDATE_TILES: - { - tools::Rectangle aInvalidation; - uno::Sequence<OUString> aSeq - = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); - if (std::string_view("EMPTY") == pPayload) - { - m_bFullInvalidateSeen = true; - return; - } - - CPPUNIT_ASSERT(aSeq.getLength() == 4 || aSeq.getLength() == 5); - aInvalidation.SetLeft(aSeq[0].toInt32()); - aInvalidation.SetTop(aSeq[1].toInt32()); - aInvalidation.setWidth(aSeq[2].toInt32()); - aInvalidation.setHeight(aSeq[3].toInt32()); - if (m_aInvalidation.IsEmpty()) - { - m_aInvalidation = aInvalidation; - } - m_aInvalidations.Union(aInvalidation); - ++m_nInvalidations; - } - break; - case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED: - { - uno::Sequence<OUString> aSeq - = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeq.getLength()); - m_aDocumentSize.setWidth(aSeq[0].toInt32()); - m_aDocumentSize.setHeight(aSeq[1].toInt32()); - } - break; - case LOK_CALLBACK_TEXT_SELECTION: - { - m_aTextSelection = pPayload; - if (m_aSearchResultSelection.empty()) - ++m_nSelectionBeforeSearchResult; - else - ++m_nSelectionAfterSearchResult; - } - break; - case LOK_CALLBACK_SEARCH_NOT_FOUND: - { - m_bFound = false; - } - break; - case LOK_CALLBACK_SEARCH_RESULT_SELECTION: - { - m_aSearchResultSelection.clear(); - boost::property_tree::ptree aTree; - std::stringstream aStream(pPayload); - boost::property_tree::read_json(aStream, aTree); - for (const boost::property_tree::ptree::value_type& rValue : - aTree.get_child("searchResultSelection")) - { - m_aSearchResultSelection.emplace_back( - rValue.second.get<std::string>("rectangles").c_str()); - m_aSearchResultPart.push_back( - std::atoi(rValue.second.get<std::string>("part").c_str())); - } - } - break; - case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED: - { - ++m_nRedlineTableSizeChanged; - } - break; - case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED: - { - ++m_nRedlineTableEntryModified; - } - break; - case LOK_CALLBACK_STATE_CHANGED: - { - OString aTrackedChangeIndexPrefix(".uno:TrackedChangeIndex="_ostr); - if (aPayload.startsWith(aTrackedChangeIndexPrefix)) - { - OString sIndex = aPayload.copy(aTrackedChangeIndexPrefix.getLength()); - if (sIndex.isEmpty()) - m_nTrackedChangeIndex = -1; - else - m_nTrackedChangeIndex = sIndex.toInt32(); - } - } - break; - case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR: - { - if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) - { - boost::property_tree::ptree aTree; - std::stringstream aStream(pPayload); - boost::property_tree::read_json(aStream, aTree); - boost::property_tree::ptree& aChild = aTree.get_child("hyperlink"); - m_sHyperlinkText = OString(aChild.get("text", "")); - m_sHyperlinkLink = OString(aChild.get("link", "")); - } - } - break; - case LOK_CALLBACK_FORM_FIELD_BUTTON: - { - m_aFormFieldButton = OString(pPayload); - } - break; - case LOK_CALLBACK_CONTENT_CONTROL: - { - m_aContentControl = OString(pPayload); - } - break; - case LOK_CALLBACK_GRAPHIC_SELECTION: - { - m_ShapeSelection = OString(pPayload); - } - break; - case LOK_CALLBACK_TOOLTIP: - { - std::stringstream aStream(pPayload); - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - m_aTooltip.text = aTree.get_child("text").get_value<std::string>(); - m_aTooltip.rect = aTree.get_child("rectangle").get_value<std::string>(); - } - break; - } -} - /// A view callback tracks callbacks invoked on one specific view. class ViewCallback final { diff --git a/sw/qa/inc/swtiledrenderingtest.hxx b/sw/qa/inc/swtiledrenderingtest.hxx new file mode 100644 index 000000000000..5150db235052 --- /dev/null +++ b/sw/qa/inc/swtiledrenderingtest.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#ifndef INCLUDED_SW_QA_INC_SWTILEDRENDERINGTEST_HXX +#define INCLUDED_SW_QA_INC_SWTILEDRENDERINGTEST_HXX + +#include "swmodeltestbase.hxx" + +#include <test/lokcallback.hxx> + +#include "swqahelperdllapi.h" + +/// Testsuite for the SwXTextDocument methods implementing the vcl::ITiledRenderable interface. +class SWQAHELPER_DLLPUBLIC SwTiledRenderingTest : public SwModelTestBase +{ +public: + SwTiledRenderingTest(); + virtual void setUp() override; + virtual void tearDown() override; + +protected: + SwXTextDocument* createDoc(const char* pName = nullptr); + void setupLibreOfficeKitViewCallback(SfxViewShell* pViewShell); + static void callback(int nType, const char* pPayload, void* pData); + void callbackImpl(int nType, const char* pPayload); + // First invalidation. + tools::Rectangle m_aInvalidation; + /// Union of all invalidations. + tools::Rectangle m_aInvalidations; + Size m_aDocumentSize; + OString m_aTextSelection; + bool m_bFound; + std::vector<OString> m_aSearchResultSelection; + std::vector<int> m_aSearchResultPart; + int m_nSelectionBeforeSearchResult; + int m_nSelectionAfterSearchResult; + int m_nInvalidations; + int m_nRedlineTableSizeChanged; + int m_nRedlineTableEntryModified; + int m_nTrackedChangeIndex; + bool m_bFullInvalidateSeen; + OString m_sHyperlinkText; + OString m_sHyperlinkLink; + OString m_aFormFieldButton; + OString m_aContentControl; + OString m_ShapeSelection; + struct + { + std::string text; + std::string rect; + } m_aTooltip; + TestLokCallbackWrapper m_callbackWrapper; +}; + +#endif // INCLUDED_SW_QA_INC_SWTILEDRENDERINGTEST_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/unit/swtiledrenderingtest.cxx b/sw/qa/unit/swtiledrenderingtest.cxx new file mode 100644 index 000000000000..8aa80f1c68a3 --- /dev/null +++ b/sw/qa/unit/swtiledrenderingtest.cxx @@ -0,0 +1,223 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <swtiledrenderingtest.hxx> + +#include <boost/property_tree/json_parser.hpp> + +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <comphelper/lok.hxx> +#include <comphelper/string.hxx> +#include <sfx2/lokhelper.hxx> + +#include <docsh.hxx> +#include <swdll.hxx> +#include <swmodule.hxx> +#include <unotxdoc.hxx> +#include <wrtsh.hxx> + +using namespace css; + +SwTiledRenderingTest::SwTiledRenderingTest() + : SwModelTestBase(u"/sw/qa/extras/tiledrendering/data/"_ustr) + , m_bFound(true) + , m_nSelectionBeforeSearchResult(0) + , m_nSelectionAfterSearchResult(0) + , m_nInvalidations(0) + , m_nRedlineTableSizeChanged(0) + , m_nRedlineTableEntryModified(0) + , m_nTrackedChangeIndex(-1) + , m_bFullInvalidateSeen(false) + , m_callbackWrapper(&callback, this) +{ +} + +void SwTiledRenderingTest::setUp() +{ + SwModelTestBase::setUp(); + + SwGlobals::ensure(); + SwModule::get()->ClearRedlineAuthors(); + + comphelper::LibreOfficeKit::setActive(true); +} + +void SwTiledRenderingTest::tearDown() +{ + if (mxComponent.is()) + { + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + if (pWrtShell) + { + pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(nullptr); + } + mxComponent->dispose(); + mxComponent.clear(); + } + m_callbackWrapper.clear(); + comphelper::LibreOfficeKit::setActive(false); + + test::BootstrapFixture::tearDown(); +} + +SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) +{ + if (!pName) + createSwDoc(); + else + createSwDoc(pName); + + SwXTextDocument* pTextDocument = getSwTextDoc(); + pTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + return pTextDocument; +} + +void SwTiledRenderingTest::setupLibreOfficeKitViewCallback(SfxViewShell* pViewShell) +{ + pViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); + m_callbackWrapper.setLOKViewId(SfxLokHelper::getView(pViewShell)); +} + +void SwTiledRenderingTest::callback(int nType, const char* pPayload, void* pData) +{ + static_cast<SwTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload); +} + +void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) +{ + OString aPayload(pPayload); + switch (nType) + { + case LOK_CALLBACK_INVALIDATE_TILES: + { + tools::Rectangle aInvalidation; + uno::Sequence<OUString> aSeq + = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); + if (std::string_view("EMPTY") == pPayload) + { + m_bFullInvalidateSeen = true; + return; + } + + CPPUNIT_ASSERT(aSeq.getLength() == 4 || aSeq.getLength() == 5); + aInvalidation.SetLeft(aSeq[0].toInt32()); + aInvalidation.SetTop(aSeq[1].toInt32()); + aInvalidation.setWidth(aSeq[2].toInt32()); + aInvalidation.setHeight(aSeq[3].toInt32()); + if (m_aInvalidation.IsEmpty()) + { + m_aInvalidation = aInvalidation; + } + m_aInvalidations.Union(aInvalidation); + ++m_nInvalidations; + } + break; + case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED: + { + uno::Sequence<OUString> aSeq + = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeq.getLength()); + m_aDocumentSize.setWidth(aSeq[0].toInt32()); + m_aDocumentSize.setHeight(aSeq[1].toInt32()); + } + break; + case LOK_CALLBACK_TEXT_SELECTION: + { + m_aTextSelection = pPayload; + if (m_aSearchResultSelection.empty()) + ++m_nSelectionBeforeSearchResult; + else + ++m_nSelectionAfterSearchResult; + } + break; + case LOK_CALLBACK_SEARCH_NOT_FOUND: + { + m_bFound = false; + } + break; + case LOK_CALLBACK_SEARCH_RESULT_SELECTION: + { + m_aSearchResultSelection.clear(); + boost::property_tree::ptree aTree; + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, aTree); + for (const boost::property_tree::ptree::value_type& rValue : + aTree.get_child("searchResultSelection")) + { + m_aSearchResultSelection.emplace_back( + rValue.second.get<std::string>("rectangles").c_str()); + m_aSearchResultPart.push_back( + std::atoi(rValue.second.get<std::string>("part").c_str())); + } + } + break; + case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED: + { + ++m_nRedlineTableSizeChanged; + } + break; + case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED: + { + ++m_nRedlineTableEntryModified; + } + break; + case LOK_CALLBACK_STATE_CHANGED: + { + OString aTrackedChangeIndexPrefix(".uno:TrackedChangeIndex="_ostr); + if (aPayload.startsWith(aTrackedChangeIndexPrefix)) + { + OString sIndex = aPayload.copy(aTrackedChangeIndexPrefix.getLength()); + if (sIndex.isEmpty()) + m_nTrackedChangeIndex = -1; + else + m_nTrackedChangeIndex = sIndex.toInt32(); + } + } + break; + case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR: + { + if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) + { + boost::property_tree::ptree aTree; + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, aTree); + boost::property_tree::ptree& aChild = aTree.get_child("hyperlink"); + m_sHyperlinkText = OString(aChild.get("text", "")); + m_sHyperlinkLink = OString(aChild.get("link", "")); + } + } + break; + case LOK_CALLBACK_FORM_FIELD_BUTTON: + { + m_aFormFieldButton = OString(pPayload); + } + break; + case LOK_CALLBACK_CONTENT_CONTROL: + { + m_aContentControl = OString(pPayload); + } + break; + case LOK_CALLBACK_GRAPHIC_SELECTION: + { + m_ShapeSelection = OString(pPayload); + } + break; + case LOK_CALLBACK_TOOLTIP: + { + std::stringstream aStream(pPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + m_aTooltip.text = aTree.get_child("text").get_value<std::string>(); + m_aTooltip.rect = aTree.get_child("rectangle").get_value<std::string>(); + } + break; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */