test: Merge SwAccessibleTestBase and AccessibleTestBase

Change-Id: Ic62bd287406326f4c3d3e0702850fe0337f17686
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175762
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli 2024-10-28 22:43:09 +01:00
parent a38a22c7e5
commit e5a1742dcd
10 changed files with 161 additions and 232 deletions

View file

@ -37,6 +37,10 @@ namespace test
{
class OOO_DLLPUBLIC_TEST AccessibleTestBase : public test::BootstrapFixture
{
private:
void collectText(const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext,
rtl::OUStringBuffer& buffer, bool onlyChildren = false);
protected:
css::uno::Reference<css::frame::XDesktop2> mxDesktop;
css::uno::Reference<css::lang::XComponent> mxDocument;
@ -51,6 +55,18 @@ protected:
virtual css::uno::Reference<css::accessibility::XAccessibleContext>
getDocumentAccessibleContext();
static css::uno::Reference<css::accessibility::XAccessibleContext> getPreviousFlowingSibling(
const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext);
static css::uno::Reference<css::accessibility::XAccessibleContext> getNextFlowingSibling(
const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext);
/** Collects contents of @p xContext in a dummy markup form */
OUString
collectText(const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext);
/** Collects contents of the current document */
OUString collectText() { return collectText(getDocumentAccessibleContext()); }
void documentPostKeyEvent(int nType, int nCharCode, int nKeyCode)
{
vcl::ITiledRenderable* pTiledRenderable

View file

@ -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 <test/testdllapi.hxx>
#include <deque>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
#include "accessibletestbase.hxx"
namespace test
{
class OOO_DLLPUBLIC_TEST SwAccessibleTestBase : public AccessibleTestBase
{
private:
void collectText(const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext,
rtl::OUStringBuffer& buffer, bool onlyChildren = false);
protected:
static css::uno::Reference<css::accessibility::XAccessibleContext> getPreviousFlowingSibling(
const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext);
static css::uno::Reference<css::accessibility::XAccessibleContext> getNextFlowingSibling(
const css::uno::Reference<css::accessibility::XAccessibleContext>& 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<css::uno::Reference<css::accessibility::XAccessibleContext>> getAllChildren(
const css::uno::Reference<css::accessibility::XAccessibleContext>& xContext) override;
/** Collects contents of @p xContext in a dummy markup form */
OUString
collectText(const css::uno::Reference<css::accessibility::XAccessibleContext>& 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: */

View file

@ -14,11 +14,10 @@
#include <vcl/scheduler.hxx>
#include <test/a11y/accessibletestbase.hxx>
#include <test/a11y/swaccessibletestbase.hxx>
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();

View file

@ -11,12 +11,12 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>
#include <test/a11y/swaccessibletestbase.hxx>
#include <test/a11y/accessibletestbase.hxx>
#include <test/a11y/AccessibilityTools.hxx>
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"<PARAGRAPH>hello</PARAGRAPH>"_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"<PARAGRAPH>1</PARAGRAPH>"_ustr, collectText());
}
CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestMenuInsertPageBreak)
CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestMenuInsertPageBreak)
{
load(u"private:factory/swriter"_ustr);

View file

@ -12,7 +12,7 @@
#include <vcl/scheduler.hxx>
#include <test/a11y/swaccessibletestbase.hxx>
#include <test/a11y/accessibletestbase.hxx>
#include <test/a11y/AccessibilityTools.hxx>
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"<PARAGRAPH>!</PARAGRAPH>"_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"<PARAGRAPH>https://libreoffice.org/</PARAGRAPH>"_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"<PARAGRAPH>#Test Bookmark 1 Bookmark </PARAGRAPH>"_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"<PARAGRAPH/><PARAGRAPH/>"_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);

View file

@ -16,13 +16,13 @@
#include <vcl/scheduler.hxx>
#include <test/a11y/swaccessibletestbase.hxx>
#include <test/a11y/accessibletestbase.hxx>
#include <test/a11y/AccessibilityTools.hxx>
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);

View file

@ -11,13 +11,13 @@
#include <com/sun/star/accessibility/XAccessibleText.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <test/a11y/swaccessibletestbase.hxx>
#include <test/a11y/accessibletestbase.hxx>
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);

View file

@ -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 \

View file

@ -11,6 +11,9 @@
#include <string>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/accessibility/XAccessibleText.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/XAccessible.hpp>
@ -29,6 +32,7 @@
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <rtl/ustrbuf.hxx>
#include <vcl/idle.hxx>
#include <vcl/scheduler.hxx>
#include <vcl/svapp.hxx>
@ -109,6 +113,126 @@ test::AccessibleTestBase::getDocumentAccessibleContext()
});
}
uno::Reference<accessibility::XAccessibleContext>
test::AccessibleTestBase::getPreviousFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
return getFirstRelationTargetOfType(xContext,
accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM);
}
uno::Reference<accessibility::XAccessibleContext> test::AccessibleTestBase::getNextFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& 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<uno::Reference<accessibility::XAccessibleContext>>
test::AccessibleTestBase::getAllChildren(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
/* first, get all "natural" children */
std::deque<uno::Reference<accessibility::XAccessibleContext>> 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<accessibility::XAccessibleContext>& 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"&quot;") + "\"");
}
buffer.append('>');
}
auto openTagLength = buffer.getLength();
uno::Reference<accessibility::XAccessibleText> 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("</" + roleName + ">");
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<accessibility::XAccessibleContext>& xContext)
{
rtl::OUStringBuffer buf;
collectText(xContext, buf, isDocumentRole(xContext->getAccessibleRole()));
return buf.makeStringAndClear();
}
uno::Reference<accessibility::XAccessibleContext>
test::AccessibleTestBase::getFirstRelationTargetOfType(
const uno::Reference<accessibility::XAccessibleContext>& xContext, sal_Int16 relationType)
@ -135,22 +259,6 @@ test::AccessibleTestBase::getFirstRelationTargetOfType(
return nullptr;
}
std::deque<uno::Reference<accessibility::XAccessibleContext>>
test::AccessibleTestBase::getAllChildren(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
std::deque<uno::Reference<accessibility::XAccessibleContext>> 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<accessibility::XAccessibleContext>& xContext, const int depth)

View file

@ -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 <test/a11y/swaccessibletestbase.hxx>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/accessibility/XAccessibleText.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <rtl/ustrbuf.hxx>
#include <test/a11y/AccessibilityTools.hxx>
using namespace css;
uno::Reference<accessibility::XAccessibleContext>
test::SwAccessibleTestBase::getPreviousFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
return getFirstRelationTargetOfType(xContext,
accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM);
}
uno::Reference<accessibility::XAccessibleContext> test::SwAccessibleTestBase::getNextFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& 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<uno::Reference<accessibility::XAccessibleContext>>
test::SwAccessibleTestBase::getAllChildren(
const uno::Reference<accessibility::XAccessibleContext>& 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<accessibility::XAccessibleContext>& 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"&quot;") + "\"");
}
buffer.append('>');
}
auto openTagLength = buffer.getLength();
uno::Reference<accessibility::XAccessibleText> 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("</" + roleName + ">");
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<accessibility::XAccessibleContext>& 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: */