diff --git a/include/test/a11y/accessibletestbase.hxx b/include/test/a11y/accessibletestbase.hxx index e23c2e12467e..6983a9b66d0f 100644 --- a/include/test/a11y/accessibletestbase.hxx +++ b/include/test/a11y/accessibletestbase.hxx @@ -37,6 +37,10 @@ namespace test { class OOO_DLLPUBLIC_TEST AccessibleTestBase : public test::BootstrapFixture { +private: + void collectText(const css::uno::Reference& xContext, + rtl::OUStringBuffer& buffer, bool onlyChildren = false); + protected: css::uno::Reference mxDesktop; css::uno::Reference mxDocument; @@ -51,6 +55,18 @@ protected: virtual css::uno::Reference getDocumentAccessibleContext(); + static css::uno::Reference getPreviousFlowingSibling( + const css::uno::Reference& xContext); + static css::uno::Reference getNextFlowingSibling( + const css::uno::Reference& xContext); + + /** Collects contents of @p xContext in a dummy markup form */ + OUString + collectText(const css::uno::Reference& xContext); + + /** Collects contents of the current document */ + OUString collectText() { return collectText(getDocumentAccessibleContext()); } + void documentPostKeyEvent(int nType, int nCharCode, int nKeyCode) { vcl::ITiledRenderable* pTiledRenderable diff --git a/include/test/a11y/swaccessibletestbase.hxx b/include/test/a11y/swaccessibletestbase.hxx deleted file mode 100644 index a8ed42a4dcef..000000000000 --- a/include/test/a11y/swaccessibletestbase.hxx +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- 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/. - */ - -#pragma once - -#include - -#include - -#include -#include - -#include -#include - -#include "accessibletestbase.hxx" - -namespace test -{ -class OOO_DLLPUBLIC_TEST SwAccessibleTestBase : public AccessibleTestBase -{ -private: - void collectText(const css::uno::Reference& xContext, - rtl::OUStringBuffer& buffer, bool onlyChildren = false); - -protected: - static css::uno::Reference getPreviousFlowingSibling( - const css::uno::Reference& xContext); - static css::uno::Reference getNextFlowingSibling( - const css::uno::Reference& xContext); - - /** - * This fetches regular children plus siblings linked with FLOWS_TO/FLOWS_FROM which are not - * already in the regular children set. This is required because most offscreen children of the - * document contents are not listed as part of their parent children, but as FLOWS_* reference - * from one to the next. - * There is currently no guarantee all children will be listed, and it is fairly likely - * offscreen frames and tables might be missing for example. - */ - virtual std::deque> getAllChildren( - const css::uno::Reference& xContext) override; - - /** Collects contents of @p xContext in a dummy markup form */ - OUString - collectText(const css::uno::Reference& xContext); - - /** Collects contents of the current document */ - OUString collectText() { return collectText(getDocumentAccessibleContext()); } -}; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sd/qa/unit/a11y/layout.cxx b/sd/qa/unit/a11y/layout.cxx index 7b7f26174432..9fd2abf07aca 100644 --- a/sd/qa/unit/a11y/layout.cxx +++ b/sd/qa/unit/a11y/layout.cxx @@ -14,11 +14,10 @@ #include #include -#include using namespace css; -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestImpressDefaultStructure) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestImpressDefaultStructure) { load(u"private:factory/simpress"_ustr); Scheduler::ProcessEventsToIdle(); @@ -64,7 +63,7 @@ CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestImpressDefaultLayout) } // test a11y tree order is stable (https://bugs.documentfoundation.org/show_bug.cgi?id=150064) -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, tdf150064) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, tdf150064) { loadFromSrc(u"/sd/qa/unit/a11y/data/tdf150064.fodp"_ustr); Scheduler::ProcessEventsToIdle(); diff --git a/sw/qa/extras/accessibility/basics.cxx b/sw/qa/extras/accessibility/basics.cxx index a6006480c84e..e4d3a479378d 100644 --- a/sw/qa/extras/accessibility/basics.cxx +++ b/sw/qa/extras/accessibility/basics.cxx @@ -11,12 +11,12 @@ #include #include -#include +#include #include using namespace css; -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestBasicStructure) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestBasicStructure) { loadFromSrc(u"/sw/qa/python/testdocuments/xtextcontent.odt"_ustr); auto xContext = getDocumentAccessibleContext(); @@ -36,7 +36,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestBasicStructure) collectText(xContext)); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeSimple) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestTypeSimple) { load(u"private:factory/swriter"_ustr); auto xContext = getDocumentAccessibleContext(); @@ -52,7 +52,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeSimple) CPPUNIT_ASSERT_EQUAL(u"hello"_ustr, collectText(xContext)); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeMultiPara) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestTypeMultiPara) { load(u"private:factory/swriter"_ustr); auto xContext = getDocumentAccessibleContext(); @@ -70,14 +70,14 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeMultiPara) collectText(xContext)); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestMenuInsertPageNumber) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestMenuInsertPageNumber) { load(u"private:factory/swriter"_ustr); CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Field", u"Page Number")); CPPUNIT_ASSERT_EQUAL(u"1"_ustr, collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestMenuInsertPageBreak) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestMenuInsertPageBreak) { load(u"private:factory/swriter"_ustr); diff --git a/sw/qa/extras/accessibility/dialogs.cxx b/sw/qa/extras/accessibility/dialogs.cxx index 451b90ce1206..18662ce7cd9b 100644 --- a/sw/qa/extras/accessibility/dialogs.cxx +++ b/sw/qa/extras/accessibility/dialogs.cxx @@ -12,7 +12,7 @@ #include -#include +#include #include using namespace css; @@ -20,7 +20,7 @@ using namespace css; // FIXME: dialog API doesn't work on macos yet #if !defined(MACOSX) -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSpecialCharactersDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestSpecialCharactersDialog) { load(u"private:factory/swriter"_ustr); @@ -58,7 +58,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSpecialCharactersDialo } /* checks for the fix from https://gerrit.libreoffice.org/c/core/+/147660 */ -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestSpecialCharactersDialogFocus) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestSpecialCharactersDialogFocus) { load(u"private:factory/swriter"_ustr); @@ -89,7 +89,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestSpecialCharactersDialogFocu CPPUNIT_ASSERT_EQUAL(u"!"_ustr, collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestHyperlinkDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestHyperlinkDialog) { load(u"private:factory/swriter"_ustr); @@ -112,7 +112,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestHyperlinkDialog) CPPUNIT_ASSERT_EQUAL(u"https://libreoffice.org/"_ustr, collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestBookmarkDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestBookmarkDialog) { load(u"private:factory/swriter"_ustr); @@ -135,7 +135,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestBookmarkDialog) CPPUNIT_ASSERT_EQUAL(u"#Test Bookmark 1 Bookmark "_ustr, collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSectionDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestSectionDialog) { load(u"private:factory/swriter"_ustr); @@ -153,7 +153,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSectionDialog) CPPUNIT_ASSERT_EQUAL(u""_ustr, collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFontworkDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestFontworkDialog) { load(u"private:factory/swriter"_ustr); @@ -173,7 +173,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFontworkDialog) collectText()); } -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFrameDialog) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestFrameDialog) { load(u"private:factory/swriter"_ustr); diff --git a/sw/qa/extras/accessibility/tdf155705.cxx b/sw/qa/extras/accessibility/tdf155705.cxx index c145c7b2c858..5e4a536f9b6a 100644 --- a/sw/qa/extras/accessibility/tdf155705.cxx +++ b/sw/qa/extras/accessibility/tdf155705.cxx @@ -16,13 +16,13 @@ #include -#include +#include #include using namespace css; /* This test only works if spell checking is available for en_US */ -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, tdf155705) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, tdf155705) { loadFromSrc(u"/sw/qa/extras/accessibility/testdocuments/tdf155705.fodt"_ustr); diff --git a/sw/qa/extras/accessibility/unicode.cxx b/sw/qa/extras/accessibility/unicode.cxx index 0130ee1dc48f..291c6413ed55 100644 --- a/sw/qa/extras/accessibility/unicode.cxx +++ b/sw/qa/extras/accessibility/unicode.cxx @@ -11,13 +11,13 @@ #include #include -#include +#include using namespace css; using namespace accessibility; // Checks fetching multi-unit characters -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestUnicodeSP) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestUnicodeSP) { loadFromSrc(u"/sw/qa/extras/accessibility/testdocuments/unicode.fodf"_ustr); @@ -41,7 +41,7 @@ CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestUnicodeSP) } // Checks getTextBehindIndex() with multi-unit characters -CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestUnicodeSPBehindIndex) +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestUnicodeSPBehindIndex) { loadFromSrc(u"/sw/qa/extras/accessibility/testdocuments/unicode.fodf"_ustr); diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index f306904b321e..6a7abe7eb3f2 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -49,7 +49,6 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/a11y/AccessibilityTools \ test/source/a11y/accessibletestbase \ test/source/a11y/eventposter \ - test/source/a11y/swaccessibletestbase \ test/source/beans/xpropertyset \ test/source/chart/xchartdata \ test/source/container/xchild \ diff --git a/test/source/a11y/accessibletestbase.cxx b/test/source/a11y/accessibletestbase.cxx index 5d8f50c90f10..e80130810ab0 100644 --- a/test/source/a11y/accessibletestbase.cxx +++ b/test/source/a11y/accessibletestbase.cxx @@ -11,6 +11,9 @@ #include +#include +#include +#include #include #include #include @@ -29,6 +32,7 @@ #include #include +#include #include #include #include @@ -109,6 +113,126 @@ test::AccessibleTestBase::getDocumentAccessibleContext() }); } +uno::Reference +test::AccessibleTestBase::getPreviousFlowingSibling( + const uno::Reference& xContext) +{ + return getFirstRelationTargetOfType(xContext, + accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM); +} + +uno::Reference test::AccessibleTestBase::getNextFlowingSibling( + const uno::Reference& xContext) +{ + return getFirstRelationTargetOfType(xContext, + accessibility::AccessibleRelationType::CONTENT_FLOWS_TO); +} + +/* Care has to be taken not to walk sideways as the relation is also used + * with children of nested containers (possibly as the "natural"/"perceived" flow?). */ +std::deque> +test::AccessibleTestBase::getAllChildren( + const uno::Reference& xContext) +{ + /* first, get all "natural" children */ + std::deque> children; + auto childCount = xContext->getAccessibleChildCount(); + + for (sal_Int64 i = 0; i < childCount && i < AccessibilityTools::MAX_CHILDREN; i++) + { + auto child = xContext->getAccessibleChild(i); + children.push_back(child->getAccessibleContext()); + } + + if (!children.size()) + return children; + + /* then, try and find flowing siblings at the same levels that are not included in the list */ + /* first, backwards: */ + auto child = getPreviousFlowingSibling(children.front()); + while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN) + { + auto childParent = child->getAccessibleParent(); + if (childParent.is() + && AccessibilityTools::equals(xContext, childParent->getAccessibleContext())) + children.push_front(child); + child = getPreviousFlowingSibling(child); + } + /* then forward */ + child = getNextFlowingSibling(children.back()); + while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN) + { + auto childParent = child->getAccessibleParent(); + if (childParent.is() + && AccessibilityTools::equals(xContext, childParent->getAccessibleContext())) + children.push_back(child); + child = getNextFlowingSibling(child); + } + + return children; +} + +void test::AccessibleTestBase::collectText( + const uno::Reference& xContext, rtl::OUStringBuffer& buffer, + bool onlyChildren) +{ + const auto& roleName = AccessibilityTools::getRoleName(xContext->getAccessibleRole()); + + std::cout << "collecting text for child of role " << roleName << "..." << std::endl; + + if (!onlyChildren) + { + const struct + { + std::u16string_view name; + rtl::OUString value; + } attrs[] = { + { u"name", xContext->getAccessibleName() }, + { u"description", xContext->getAccessibleDescription() }, + }; + + buffer.append('<'); + buffer.append(roleName); + for (auto& attr : attrs) + { + if (attr.value.getLength() == 0) + continue; + buffer.append(' '); + buffer.append(attr.name); + buffer.append(u"=\"" + attr.value.replaceAll(u"\"", u""") + "\""); + } + buffer.append('>'); + } + auto openTagLength = buffer.getLength(); + + uno::Reference xText(xContext, uno::UNO_QUERY); + if (xText.is()) + buffer.append(xText->getText()); + + for (auto& childContext : getAllChildren(xContext)) + collectText(childContext, buffer); + + if (!onlyChildren) + { + if (buffer.getLength() != openTagLength) + buffer.append(""); + else + { + /* there was no content, so make is a short tag for more concise output */ + buffer[openTagLength - 1] = '/'; + buffer.append('>'); + } + } +} + +OUString test::AccessibleTestBase::collectText( + const uno::Reference& xContext) +{ + rtl::OUStringBuffer buf; + collectText(xContext, buf, isDocumentRole(xContext->getAccessibleRole())); + return buf.makeStringAndClear(); +} + uno::Reference test::AccessibleTestBase::getFirstRelationTargetOfType( const uno::Reference& xContext, sal_Int16 relationType) @@ -135,22 +259,6 @@ test::AccessibleTestBase::getFirstRelationTargetOfType( return nullptr; } -std::deque> -test::AccessibleTestBase::getAllChildren( - const uno::Reference& xContext) -{ - std::deque> children; - auto childCount = xContext->getAccessibleChildCount(); - - for (sal_Int64 i = 0; i < childCount && i < AccessibilityTools::MAX_CHILDREN; i++) - { - auto child = xContext->getAccessibleChild(i); - children.push_back(child->getAccessibleContext()); - } - - return children; -} - /** Prints the tree of accessible objects starting at @p xContext to stdout */ void test::AccessibleTestBase::dumpA11YTree( const uno::Reference& xContext, const int depth) diff --git a/test/source/a11y/swaccessibletestbase.cxx b/test/source/a11y/swaccessibletestbase.cxx deleted file mode 100644 index b43d65c0cf78..000000000000 --- a/test/source/a11y/swaccessibletestbase.cxx +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- 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 - -#include -#include -#include -#include - -#include - -#include - -using namespace css; - -uno::Reference -test::SwAccessibleTestBase::getPreviousFlowingSibling( - const uno::Reference& xContext) -{ - return getFirstRelationTargetOfType(xContext, - accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM); -} - -uno::Reference test::SwAccessibleTestBase::getNextFlowingSibling( - const uno::Reference& xContext) -{ - return getFirstRelationTargetOfType(xContext, - accessibility::AccessibleRelationType::CONTENT_FLOWS_TO); -} - -/* Care has to be taken not to walk sideways as the relation is also used - * with children of nested containers (possibly as the "natural"/"perceived" flow?). */ -std::deque> -test::SwAccessibleTestBase::getAllChildren( - const uno::Reference& xContext) -{ - /* first, get all "natural" children */ - auto children = AccessibleTestBase::getAllChildren(xContext); - if (!children.size()) - return children; - - /* then, try and find flowing siblings at the same levels that are not included in the list */ - /* first, backwards: */ - auto child = getPreviousFlowingSibling(children.front()); - while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN) - { - auto childParent = child->getAccessibleParent(); - if (childParent.is() - && AccessibilityTools::equals(xContext, childParent->getAccessibleContext())) - children.push_front(child); - child = getPreviousFlowingSibling(child); - } - /* then forward */ - child = getNextFlowingSibling(children.back()); - while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN) - { - auto childParent = child->getAccessibleParent(); - if (childParent.is() - && AccessibilityTools::equals(xContext, childParent->getAccessibleContext())) - children.push_back(child); - child = getNextFlowingSibling(child); - } - - return children; -} - -void test::SwAccessibleTestBase::collectText( - const uno::Reference& xContext, rtl::OUStringBuffer& buffer, - bool onlyChildren) -{ - const auto& roleName = AccessibilityTools::getRoleName(xContext->getAccessibleRole()); - - std::cout << "collecting text for child of role " << roleName << "..." << std::endl; - - if (!onlyChildren) - { - const struct - { - std::u16string_view name; - rtl::OUString value; - } attrs[] = { - { u"name", xContext->getAccessibleName() }, - { u"description", xContext->getAccessibleDescription() }, - }; - - buffer.append('<'); - buffer.append(roleName); - for (auto& attr : attrs) - { - if (attr.value.getLength() == 0) - continue; - buffer.append(' '); - buffer.append(attr.name); - buffer.append(u"=\"" + attr.value.replaceAll(u"\"", u""") + "\""); - } - buffer.append('>'); - } - auto openTagLength = buffer.getLength(); - - uno::Reference xText(xContext, uno::UNO_QUERY); - if (xText.is()) - buffer.append(xText->getText()); - - for (auto& childContext : getAllChildren(xContext)) - collectText(childContext, buffer); - - if (!onlyChildren) - { - if (buffer.getLength() != openTagLength) - buffer.append(""); - else - { - /* there was no content, so make is a short tag for more concise output */ - buffer[openTagLength - 1] = '/'; - buffer.append('>'); - } - } -} - -OUString test::SwAccessibleTestBase::collectText( - const uno::Reference& xContext) -{ - rtl::OUStringBuffer buf; - collectText(xContext, buf, isDocumentRole(xContext->getAccessibleRole())); - return buf.makeStringAndClear(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */