From 8fe5a832b02ea6c5113c573f5b9c23e58049a4d2 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 21 Jul 2022 15:58:16 +0200 Subject: [PATCH] Make AccessibilityTools available more widely and use it Move AccessibilityTools helper to test/ and use it in accessible_relation_set test replacing the copied over feature and consolidating the test as well. Change-Id: Ia5ea69bb08bb2a86e3eb6c3dba2ab182b612561d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137307 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- .../test}/a11y/AccessibilityTools.hxx | 5 +- .../accessibility/accessible_relation_set.cxx | 67 +++++-------------- test/Library_subsequenttest.mk | 1 + .../source}/a11y/AccessibilityTools.cxx | 35 +++++++++- toolkit/CppunitTest_toolkit_a11y.mk | 2 +- .../cppunit/a11y/AccessibleStatusBarTest.cxx | 2 +- .../a11y/XAccessibleComponentTester.cxx | 2 +- .../a11y/XAccessibleComponentTester.hxx | 2 +- .../cppunit/a11y/XAccessibleContextTester.cxx | 2 +- .../XAccessibleEventBroadcasterTester.cxx | 2 +- 10 files changed, 58 insertions(+), 62 deletions(-) rename {toolkit/qa/cppunit => include/test}/a11y/AccessibilityTools.hxx (97%) rename {toolkit/qa/cppunit => test/source}/a11y/AccessibilityTools.cxx (94%) diff --git a/toolkit/qa/cppunit/a11y/AccessibilityTools.hxx b/include/test/a11y/AccessibilityTools.hxx similarity index 97% rename from toolkit/qa/cppunit/a11y/AccessibilityTools.hxx rename to include/test/a11y/AccessibilityTools.hxx index 96afe4377f94..e56c68c9bebb 100644 --- a/toolkit/qa/cppunit/a11y/AccessibilityTools.hxx +++ b/include/test/a11y/AccessibilityTools.hxx @@ -19,6 +19,8 @@ #pragma once +#include + #include #include @@ -28,7 +30,7 @@ #include #include -class AccessibilityTools +class OOO_DLLPUBLIC_TEST AccessibilityTools { public: /** Maximum number of children to work on. This is especially useful for @@ -47,6 +49,7 @@ public: static OUString getRoleName(const sal_Int16 role); static OUString getStateName(const sal_Int16 state); static OUString getEventIdName(const sal_Int16 event_id); + static OUString getRelationTypeName(const sal_Int16 rel_type); template static std::string debugString(const css::uno::Reference& x) { diff --git a/sw/qa/extras/accessibility/accessible_relation_set.cxx b/sw/qa/extras/accessibility/accessible_relation_set.cxx index ce053c95b07b..3839a61d0504 100644 --- a/sw/qa/extras/accessibility/accessible_relation_set.cxx +++ b/sw/qa/extras/accessibility/accessible_relation_set.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -33,54 +34,13 @@ #include #include +#include + using namespace com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::accessibility; using namespace css::lang; -namespace -{ -class AccessibilityTools -{ -public: - static css::uno::Reference - getAccessibleObjectForRole(const css::uno::Reference& xacc, - sal_Int16 role); -}; -} - -css::uno::Reference -AccessibilityTools::getAccessibleObjectForRole( - const css::uno::Reference& xacc, sal_Int16 role) -{ - css::uno::Reference ac = xacc->getAccessibleContext(); - bool isShowing = ac->getAccessibleStateSet() & AccessibleStateType::SHOWING; - - if ((ac->getAccessibleRole() == role) && isShowing) - { - return ac; - } - else - { - int k = ac->getAccessibleChildCount(); - if (ac->getAccessibleChildCount() > 100) - { - k = 50; - } - - for (int i = 0; i < k; i++) - { - css::uno::Reference ac2 - = AccessibilityTools::getAccessibleObjectForRole(ac->getAccessibleChild(i), role); - if (ac2.is()) - { - return ac2; - } - } - } - return nullptr; -} - class AccessibleRelationSet : public UnoApiTest { public: @@ -137,9 +97,6 @@ AccessibleRelationSet::init(uno::Reference& par void AccessibleRelationSet::contents_flows_to_and_from() { //contents_flows_to - std::vector types{ "INVALID", "CONTENT_FLOWS_FROM", "CONTENT_FLOWS_TO", - "CONTROLLED_BY", "CONTROLLER_FOR", "LABEL_FOR", - "LABELED_BY", "MEMBER_OF", "SUB_WINDOW_OF" }; css::uno::Reference para1; css::uno::Reference para2; @@ -160,8 +117,10 @@ void AccessibleRelationSet::contents_flows_to_and_from() css::uno::Reference adummy( set->getRelation(0).TargetSet[0], uno::UNO_QUERY_THROW); atarget = adummy; - CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 0", types[2], - types[firstrelation]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 0", + AccessibilityTools::getRelationTypeName( + accessibility::AccessibleRelationType::CONTENT_FLOWS_TO), + AccessibilityTools::getRelationTypeName(firstrelation)); css::uno::Reference paraText2(para2, uno::UNO_QUERY_THROW); @@ -221,15 +180,19 @@ void AccessibleRelationSet::contents_flows_to_and_from() } } - CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 1", types[1], - types[relationtypes[0]]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 1", + AccessibilityTools::getRelationTypeName( + accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM), + AccessibilityTools::getRelationTypeName(relationtypes[0])); css::uno::Reference paraText1(para1, uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct target paragraph", atargets[0]->getText(), paraText1->getText()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 3", types[2], - types[relationtypes[1]]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct relation type for paragraph 3", + AccessibilityTools::getRelationTypeName( + accessibility::AccessibleRelationType::CONTENT_FLOWS_TO), + AccessibilityTools::getRelationTypeName(relationtypes[1])); css::uno::Reference paraText3(para3, uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL_MESSAGE("didn't gain correct target paragraph", atargets[1]->getText(), diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index 0715cc47af63..9b35eda003ba 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -42,6 +42,7 @@ $(eval $(call gb_Library_use_externals,subsequenttest,\ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/unoapi_test \ test/source/calc_unoapi_test \ + test/source/a11y/AccessibilityTools \ test/source/beans/xpropertyset \ test/source/chart/xchartdata \ test/source/container/xchild \ diff --git a/toolkit/qa/cppunit/a11y/AccessibilityTools.cxx b/test/source/a11y/AccessibilityTools.cxx similarity index 94% rename from toolkit/qa/cppunit/a11y/AccessibilityTools.cxx rename to test/source/a11y/AccessibilityTools.cxx index 816e9b82b168..f727bd41087f 100644 --- a/toolkit/qa/cppunit/a11y/AccessibilityTools.cxx +++ b/test/source/a11y/AccessibilityTools.cxx @@ -17,9 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "AccessibilityTools.hxx" +#include #include +#include #include #include #include @@ -31,7 +32,6 @@ using namespace css; -/* FIXME: mostly copied from sw/qa/extras/accessibility/accessible_relation_set.cxx */ css::uno::Reference AccessibilityTools::getAccessibleObjectForRole( const css::uno::Reference& xacc, sal_Int16 role) @@ -57,7 +57,6 @@ AccessibilityTools::getAccessibleObjectForRole( } return nullptr; } -/* FIXME: end copy */ bool AccessibilityTools::equals(const uno::Reference& xacc1, const uno::Reference& xacc2) @@ -492,6 +491,36 @@ OUString AccessibilityTools::getEventIdName(const sal_Int16 event_id) return "unknown"; } +OUString AccessibilityTools::getRelationTypeName(const sal_Int16 rel_type) +{ + switch (rel_type) + { + case accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM: + return "CONTENT_FLOWS_FROM"; + case accessibility::AccessibleRelationType::CONTENT_FLOWS_TO: + return "CONTENT_FLOWS_TO"; + case accessibility::AccessibleRelationType::CONTROLLED_BY: + return "CONTROLLED_BY"; + case accessibility::AccessibleRelationType::CONTROLLER_FOR: + return "CONTROLLER_FOR"; + case accessibility::AccessibleRelationType::DESCRIBED_BY: + return "DESCRIBED_BY"; + case accessibility::AccessibleRelationType::INVALID: + return "INVALID"; + case accessibility::AccessibleRelationType::LABELED_BY: + return "LABELED_BY"; + case accessibility::AccessibleRelationType::LABEL_FOR: + return "LABEL_FOR"; + case accessibility::AccessibleRelationType::MEMBER_OF: + return "MEMBER_OF"; + case accessibility::AccessibleRelationType::NODE_CHILD_OF: + return "NODE_CHILD_OF"; + case accessibility::AccessibleRelationType::SUB_WINDOW_OF: + return "SUB_WINDOW_OF"; + } + return "unknown"; +} + OUString AccessibilityTools::debugName(accessibility::XAccessibleContext* ctx) { return "role=" + AccessibilityTools::getRoleName(ctx->getAccessibleRole()) + " name=\"" diff --git a/toolkit/CppunitTest_toolkit_a11y.mk b/toolkit/CppunitTest_toolkit_a11y.mk index 06468a49c286..4b8c60b0a6e6 100644 --- a/toolkit/CppunitTest_toolkit_a11y.mk +++ b/toolkit/CppunitTest_toolkit_a11y.mk @@ -11,7 +11,6 @@ $(eval $(call gb_CppunitTest_CppunitTest,toolkit_a11y)) $(eval $(call gb_CppunitTest_add_exception_objects,toolkit_a11y, \ toolkit/qa/cppunit/a11y/AccessibleStatusBarTest \ - toolkit/qa/cppunit/a11y/AccessibilityTools \ toolkit/qa/cppunit/a11y/XAccessibleComponentTester \ toolkit/qa/cppunit/a11y/XAccessibleContextTester \ toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester \ @@ -25,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,toolkit_a11y, \ cppuhelper \ sal \ salhelper \ + subsequenttest \ test \ tk \ tl \ diff --git a/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx b/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx index 822223a740b9..20d8b42f8c0c 100644 --- a/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx +++ b/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx @@ -38,7 +38,7 @@ #include #include -#include "AccessibilityTools.hxx" +#include #include "XAccessibleComponentTester.hxx" #include "XAccessibleContextTester.hxx" #include "XAccessibleExtendedComponentTester.hxx" diff --git a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx index 3c743d3223da..4e9ed7a1ee00 100644 --- a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx +++ b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx @@ -30,7 +30,7 @@ #include -#include "AccessibilityTools.hxx" +#include using namespace css; diff --git a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx index ba84fbbac50d..5965374a3f84 100644 --- a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx +++ b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx @@ -23,7 +23,7 @@ #include #include -#include "AccessibilityTools.hxx" +#include class XAccessibleComponentTester { diff --git a/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx index b330d5ba9544..e9b605c73956 100644 --- a/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx +++ b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx @@ -24,7 +24,7 @@ #include #include -#include "AccessibilityTools.hxx" +#include /** * @brief Tries to get every child and checks its parent. diff --git a/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx index 1ac5d4e3b56b..852c91c341be 100644 --- a/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx +++ b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx @@ -38,7 +38,7 @@ #include #include -#include "AccessibilityTools.hxx" +#include using namespace css;