From 8fe5a832b02ea6c5113c573f5b9c23e58049a4d2 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 21 Jul 2022 15:58:16 +0200 Subject: 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 --- include/test/a11y/AccessibilityTools.hxx | 158 ++++++ .../accessibility/accessible_relation_set.cxx | 67 +-- test/Library_subsequenttest.mk | 1 + test/source/a11y/AccessibilityTools.cxx | 571 +++++++++++++++++++++ toolkit/CppunitTest_toolkit_a11y.mk | 2 +- toolkit/qa/cppunit/a11y/AccessibilityTools.cxx | 542 ------------------- toolkit/qa/cppunit/a11y/AccessibilityTools.hxx | 155 ------ .../qa/cppunit/a11y/AccessibleStatusBarTest.cxx | 2 +- .../qa/cppunit/a11y/XAccessibleComponentTester.cxx | 2 +- .../qa/cppunit/a11y/XAccessibleComponentTester.hxx | 2 +- .../qa/cppunit/a11y/XAccessibleContextTester.cxx | 2 +- .../a11y/XAccessibleEventBroadcasterTester.cxx | 2 +- 12 files changed, 751 insertions(+), 755 deletions(-) create mode 100644 include/test/a11y/AccessibilityTools.hxx create mode 100644 test/source/a11y/AccessibilityTools.cxx delete mode 100644 toolkit/qa/cppunit/a11y/AccessibilityTools.cxx delete mode 100644 toolkit/qa/cppunit/a11y/AccessibilityTools.hxx diff --git a/include/test/a11y/AccessibilityTools.hxx b/include/test/a11y/AccessibilityTools.hxx new file mode 100644 index 000000000000..e56c68c9bebb --- /dev/null +++ b/include/test/a11y/AccessibilityTools.hxx @@ -0,0 +1,158 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include +#include + +class OOO_DLLPUBLIC_TEST AccessibilityTools +{ +public: + /** Maximum number of children to work on. This is especially useful for + * Calc which has a million elements, if not more. */ + static const sal_Int32 MAX_CHILDREN = 500; + + static css::uno::Reference + getAccessibleObjectForRole(const css::uno::Reference& xacc, + sal_Int16 role); + + static bool equals(const css::uno::Reference& xacc1, + const css::uno::Reference& xacc2); + static bool equals(const css::uno::Reference& xctx1, + const css::uno::Reference& xctx2); + + 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) + { + return debugString(x.get()); + } + + template static std::string debugString(const T& x) { return debugString(&x); } + + template static std::string debugString(const T* p) + { + /* only the forwarding to debugName() might actually dereference @c p, + * and we rely on specializations to be as constant as possible and not + * violate the cast here. In practice it'll be the case for all types + * handle if we carefully write the specializations. In most case the + * specialization could take a const itself if the methods were + * properly marked const, but well. */ + return debugString(const_cast(p)); + } + + template static std::string debugString(T* p) + { + CPPUNIT_NS::OStringStream ost; + + ost << "(" << static_cast(p) << ")"; + if (p != nullptr) + ost << " " << debugName(p); + + return ost.str(); + } + + static OUString debugAccessibleStateSet(sal_Int64 p); + + /** + * @brief Process events until a condition or a timeout + * @param cUntilCallback Callback condition + * @param nTimeoutMs Maximum time in ms to wait for condition + * @returns @c true if the condition was met, or @c false if the timeout + * has been reached. + * + * Processes events until idle, and either until the given condition + * becomes @c true or a timeout is reached. + * + * This is similar to Scheduler::ProcessEventsToIdle() but awaits a + * condition up to a timeout. This is useful if the waited-on condition + * might happen after the first idle time. The timeout helps in case the + * condition is not satisfied in reasonable time. + * + * @p cUntilCallback is called each time the scheduler reaches idle to check + * whether the condition is met. + * + * Example: + * @code + * ProcessEvents([&]() { return taskHasRun; }); + * @endcode + * + * @see Scheduler::ProcessEventsToIdle() + */ + static bool Await(const std::function& cUntilCallback, sal_uInt64 nTimeoutMs = 3000); + + /** + * @brief Process events for a given time + * @param nTimeoutMs Time to dispatch events for + * + * Process events for a given time. This can be useful if waiting is in + * order but there is no actual condition to wait on (e.g. expect + * something *not* to happen). This similar in spirit to + * @c sleep(nTimeoutMs), but dispatches events during the wait. + * + * This function should be used sparsely because waiting a given time is + * rarely a good solution for a problem, but in some specific situations + * there is no better alternative (like, again, waiting for something not + * to happen). + */ + static void Wait(sal_uInt64 nTimeoutMs); + +private: + static OUString debugName(css::accessibility::XAccessibleContext* xctx); + static OUString debugName(css::accessibility::XAccessible* xacc); + static OUString debugName(const css::accessibility::AccessibleEventObject* evobj); +}; + +CPPUNIT_NS_BEGIN +/* How to generate those automatically? We don't want to match all types + * not to mess up cppunit for types we don't support */ +#define AT_ASSERTION_TRAITS(T) \ + template <> struct assertion_traits> \ + { \ + static bool equal(const css::uno::Reference& x, const css::uno::Reference& y) \ + { \ + return AccessibilityTools::equals(x, y); \ + } \ + \ + static std::string toString(const css::uno::Reference& x) \ + { \ + return AccessibilityTools::debugString(x); \ + } \ + } + +AT_ASSERTION_TRAITS(css::accessibility::XAccessible); +AT_ASSERTION_TRAITS(css::accessibility::XAccessibleContext); + +#undef AT_ASSERTION_TRAITS + +CPPUNIT_NS_END + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ 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/test/source/a11y/AccessibilityTools.cxx b/test/source/a11y/AccessibilityTools.cxx new file mode 100644 index 000000000000..f727bd41087f --- /dev/null +++ b/test/source/a11y/AccessibilityTools.cxx @@ -0,0 +1,571 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace css; + +css::uno::Reference +AccessibilityTools::getAccessibleObjectForRole( + const css::uno::Reference& xacc, sal_Int16 role) +{ + css::uno::Reference ac = xacc->getAccessibleContext(); + bool isShowing = ac->getAccessibleStateSet() & accessibility::AccessibleStateType::SHOWING; + + if ((ac->getAccessibleRole() == role) && isShowing) + { + return ac; + } + else + { + int count = ac->getAccessibleChildCount(); + + for (int i = 0; i < count && i < AccessibilityTools::MAX_CHILDREN; i++) + { + css::uno::Reference ac2 + = AccessibilityTools::getAccessibleObjectForRole(ac->getAccessibleChild(i), role); + if (ac2.is()) + return ac2; + } + } + return nullptr; +} + +bool AccessibilityTools::equals(const uno::Reference& xacc1, + const uno::Reference& xacc2) +{ + if (!xacc1.is() || !xacc2.is()) + return xacc1.is() == xacc2.is(); + return equals(xacc1->getAccessibleContext(), xacc2->getAccessibleContext()); +} + +bool AccessibilityTools::equals(const uno::Reference& xctx1, + const uno::Reference& xctx2) +{ + if (!xctx1.is() || !xctx2.is()) + return xctx1.is() == xctx2.is(); + + if (xctx1->getAccessibleRole() != xctx2->getAccessibleRole()) + return false; + + if (xctx1->getAccessibleName() != xctx2->getAccessibleName()) + return false; + + if (xctx1->getAccessibleDescription() != xctx2->getAccessibleDescription()) + return false; + + if (xctx1->getAccessibleChildCount() != xctx2->getAccessibleChildCount()) + return false; + + /* this one was not in the Java version */ + if (xctx1->getAccessibleIndexInParent() != xctx2->getAccessibleIndexInParent()) + return false; + + return equals(xctx1->getAccessibleParent(), xctx2->getAccessibleParent()); +} + +OUString AccessibilityTools::getRoleName(const sal_Int16 role) +{ + switch (role) + { + case accessibility::AccessibleRole::UNKNOWN: + return "UNKNOWN"; + case accessibility::AccessibleRole::ALERT: + return "ALERT"; + case accessibility::AccessibleRole::BUTTON_DROPDOWN: + return "BUTTON_DROPDOWN"; + case accessibility::AccessibleRole::BUTTON_MENU: + return "BUTTON_MENU"; + case accessibility::AccessibleRole::CANVAS: + return "CANVAS"; + case accessibility::AccessibleRole::CAPTION: + return "CAPTION"; + case accessibility::AccessibleRole::CHART: + return "CHART"; + case accessibility::AccessibleRole::CHECK_BOX: + return "CHECK_BOX"; + case accessibility::AccessibleRole::CHECK_MENU_ITEM: + return "CHECK_MENU_ITEM"; + case accessibility::AccessibleRole::COLOR_CHOOSER: + return "COLOR_CHOOSER"; + case accessibility::AccessibleRole::COLUMN_HEADER: + return "COLUMN_HEADER"; + case accessibility::AccessibleRole::COMBO_BOX: + return "COMBO_BOX"; + case accessibility::AccessibleRole::COMMENT: + return "COMMENT"; + case accessibility::AccessibleRole::COMMENT_END: + return "COMMENT_END"; + case accessibility::AccessibleRole::DATE_EDITOR: + return "DATE_EDITOR"; + case accessibility::AccessibleRole::DESKTOP_ICON: + return "DESKTOP_ICON"; + case accessibility::AccessibleRole::DESKTOP_PANE: + return "DESKTOP_PANE"; + case accessibility::AccessibleRole::DIALOG: + return "DIALOG"; + case accessibility::AccessibleRole::DIRECTORY_PANE: + return "DIRECTORY_PANE"; + case accessibility::AccessibleRole::DOCUMENT: + return "DOCUMENT"; + case accessibility::AccessibleRole::DOCUMENT_PRESENTATION: + return "DOCUMENT_PRESENTATION"; + case accessibility::AccessibleRole::DOCUMENT_SPREADSHEET: + return "DOCUMENT_SPREADSHEET"; + case accessibility::AccessibleRole::DOCUMENT_TEXT: + return "DOCUMENT_TEXT"; + case accessibility::AccessibleRole::EDIT_BAR: + return "EDIT_BAR"; + case accessibility::AccessibleRole::EMBEDDED_OBJECT: + return "EMBEDDED_OBJECT"; + case accessibility::AccessibleRole::END_NOTE: + return "END_NOTE"; + case accessibility::AccessibleRole::FILE_CHOOSER: + return "FILE_CHOOSER"; + case accessibility::AccessibleRole::FILLER: + return "FILLER"; + case accessibility::AccessibleRole::FONT_CHOOSER: + return "FONT_CHOOSER"; + case accessibility::AccessibleRole::FOOTER: + return "FOOTER"; + case accessibility::AccessibleRole::FOOTNOTE: + return "FOOTNOTE"; + case accessibility::AccessibleRole::FORM: + return "FORM"; + case accessibility::AccessibleRole::FRAME: + return "FRAME"; + case accessibility::AccessibleRole::GLASS_PANE: + return "GLASS_PANE"; + case accessibility::AccessibleRole::GRAPHIC: + return "GRAPHIC"; + case accessibility::AccessibleRole::GROUP_BOX: + return "GROUP_BOX"; + case accessibility::AccessibleRole::HEADER: + return "HEADER"; + case accessibility::AccessibleRole::HEADING: + return "HEADING"; + case accessibility::AccessibleRole::HYPER_LINK: + return "HYPER_LINK"; + case accessibility::AccessibleRole::ICON: + return "ICON"; + case accessibility::AccessibleRole::IMAGE_MAP: + return "IMAGE_MAP"; + case accessibility::AccessibleRole::INTERNAL_FRAME: + return "INTERNAL_FRAME"; + case accessibility::AccessibleRole::LABEL: + return "LABEL"; + case accessibility::AccessibleRole::LAYERED_PANE: + return "LAYERED_PANE"; + case accessibility::AccessibleRole::LIST: + return "LIST"; + case accessibility::AccessibleRole::LIST_ITEM: + return "LIST_ITEM"; + case accessibility::AccessibleRole::MENU: + return "MENU"; + case accessibility::AccessibleRole::MENU_BAR: + return "MENU_BAR"; + case accessibility::AccessibleRole::MENU_ITEM: + return "MENU_ITEM"; + case accessibility::AccessibleRole::NOTE: + return "NOTE"; + case accessibility::AccessibleRole::OPTION_PANE: + return "OPTION_PANE"; + case accessibility::AccessibleRole::PAGE: + return "PAGE"; + case accessibility::AccessibleRole::PAGE_TAB: + return "PAGE_TAB"; + case accessibility::AccessibleRole::PAGE_TAB_LIST: + return "PAGE_TAB_LIST"; + case accessibility::AccessibleRole::PANEL: + return "PANEL"; + case accessibility::AccessibleRole::PARAGRAPH: + return "PARAGRAPH"; + case accessibility::AccessibleRole::PASSWORD_TEXT: + return "PASSWORD_TEXT"; + case accessibility::AccessibleRole::POPUP_MENU: + return "POPUP_MENU"; + case accessibility::AccessibleRole::PROGRESS_BAR: + return "PROGRESS_BAR"; + case accessibility::AccessibleRole::PUSH_BUTTON: + return "PUSH_BUTTON"; + case accessibility::AccessibleRole::RADIO_BUTTON: + return "RADIO_BUTTON"; + case accessibility::AccessibleRole::RADIO_MENU_ITEM: + return "RADIO_MENU_ITEM"; + case accessibility::AccessibleRole::ROOT_PANE: + return "ROOT_PANE"; + case accessibility::AccessibleRole::ROW_HEADER: + return "ROW_HEADER"; + case accessibility::AccessibleRole::RULER: + return "RULER"; + case accessibility::AccessibleRole::SCROLL_BAR: + return "SCROLL_BAR"; + case accessibility::AccessibleRole::SCROLL_PANE: + return "SCROLL_PANE"; + case accessibility::AccessibleRole::SECTION: + return "SECTION"; + case accessibility::AccessibleRole::SEPARATOR: + return "SEPARATOR"; + case accessibility::AccessibleRole::SHAPE: + return "SHAPE"; + case accessibility::AccessibleRole::SLIDER: + return "SLIDER"; + case accessibility::AccessibleRole::SPIN_BOX: + return "SPIN_BOX"; + case accessibility::AccessibleRole::SPLIT_PANE: + return "SPLIT_PANE"; + case accessibility::AccessibleRole::STATIC: + return "STATIC"; + case accessibility::AccessibleRole::STATUS_BAR: + return "STATUS_BAR"; + case accessibility::AccessibleRole::TABLE: + return "TABLE"; + case accessibility::AccessibleRole::TABLE_CELL: + return "TABLE_CELL"; + case accessibility::AccessibleRole::TEXT: + return "TEXT"; + case accessibility::AccessibleRole::TEXT_FRAME: + return "TEXT_FRAME"; + case accessibility::AccessibleRole::TOGGLE_BUTTON: + return "TOGGLE_BUTTON"; + case accessibility::AccessibleRole::TOOL_BAR: + return "TOOL_BAR"; + case accessibility::AccessibleRole::TOOL_TIP: + return "TOOL_TIP"; + case accessibility::AccessibleRole::TREE: + return "TREE"; + case accessibility::AccessibleRole::TREE_ITEM: + return "TREE_ITEM"; + case accessibility::AccessibleRole::TREE_TABLE: + return "TREE_TABLE"; + case accessibility::AccessibleRole::VIEW_PORT: + return "VIEW_PORT"; + case accessibility::AccessibleRole::WINDOW: + return "WINDOW"; + }; + return "unknown"; +} + +OUString AccessibilityTools::debugAccessibleStateSet(const sal_Int64 nCombinedState) +{ + OUString combinedName; + + for (int i = 0; i < 63; i++) + { + sal_Int64 state = sal_Int64(1) << i; + if (!(state & nCombinedState)) + continue; + OUString name; + switch (state) + { + case accessibility::AccessibleStateType::ACTIVE: + name = "ACTIVE"; + break; + case accessibility::AccessibleStateType::ARMED: + name = "ARMED"; + break; + case accessibility::AccessibleStateType::BUSY: + name = "BUSY"; + break; + case accessibility::AccessibleStateType::CHECKED: + name = "CHECKED"; + break; + case accessibility::AccessibleStateType::COLLAPSE: + name = "COLLAPSE"; + break; + case accessibility::AccessibleStateType::DEFAULT: + name = "DEFAULT"; + break; + case accessibility::AccessibleStateType::DEFUNC: + name = "DEFUNC"; + break; + case accessibility::AccessibleStateType::EDITABLE: + name = "EDITABLE"; + break; + case accessibility::AccessibleStateType::ENABLED: + name = "ENABLED"; + break; + case accessibility::AccessibleStateType::EXPANDABLE: + name = "EXPANDABLE"; + break; + case accessibility::AccessibleStateType::EXPANDED: + name = "EXPANDED"; + break; + case accessibility::AccessibleStateType::FOCUSABLE: + name = "FOCUSABLE"; + break; + case accessibility::AccessibleStateType::FOCUSED: + name = "FOCUSED"; + break; + case accessibility::AccessibleStateType::HORIZONTAL: + name = "HORIZONTAL"; + break; + case accessibility::AccessibleStateType::ICONIFIED: + name = "ICONIFIED"; + break; + case accessibility::AccessibleStateType::INDETERMINATE: + name = "INDETERMINATE"; + break; + case accessibility::AccessibleStateType::INVALID: + name = "INVALID"; + break; + case accessibility::AccessibleStateType::MANAGES_DESCENDANTS: + name = "MANAGES_DESCENDANTS"; + break; + case accessibility::AccessibleStateType::MODAL: + name = "MODAL"; + break; + case accessibility::AccessibleStateType::MOVEABLE: + name = "MOVEABLE"; + break; + case accessibility::AccessibleStateType::MULTI_LINE: + name = "MULTI_LINE"; + break; + case accessibility::AccessibleStateType::MULTI_SELECTABLE: + name = "MULTI_SELECTABLE"; + break; + case accessibility::AccessibleStateType::OFFSCREEN: + name = "OFFSCREEN"; + break; + case accessibility::AccessibleStateType::OPAQUE: + name = "OPAQUE"; + break; + case accessibility::AccessibleStateType::PRESSED: + name = "PRESSED"; + break; + case accessibility::AccessibleStateType::RESIZABLE: + name = "RESIZABLE"; + break; + case accessibility::AccessibleStateType::SELECTABLE: + name = "SELECTABLE"; + break; + case accessibility::AccessibleStateType::SELECTED: + name = "SELECTED"; + break; + case accessibility::AccessibleStateType::SENSITIVE: + name = "SENSITIVE"; + break; + case accessibility::AccessibleStateType::SHOWING: + name = "SHOWING"; + break; + case accessibility::AccessibleStateType::SINGLE_LINE: + name = "SINGLE_LINE"; + break; + case accessibility::AccessibleStateType::STALE: + name = "STALE"; + break; + case accessibility::AccessibleStateType::TRANSIENT: + name = "TRANSIENT"; + break; + case accessibility::AccessibleStateType::VERTICAL: + name = "VERTICAL"; + break; + case accessibility::AccessibleStateType::VISIBLE: + name = "VISIBLE"; + break; + } + if (combinedName.getLength()) + combinedName += " | "; + combinedName += name; + } + + if (combinedName.isEmpty()) + return "unknown"; + return combinedName; +} + +OUString AccessibilityTools::getEventIdName(const sal_Int16 event_id) +{ + switch (event_id) + { + case accessibility::AccessibleEventId::ACTION_CHANGED: + return "ACTION_CHANGED"; + case accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED: + return "ACTIVE_DESCENDANT_CHANGED"; + case accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS: + return "ACTIVE_DESCENDANT_CHANGED_NOFOCUS"; + case accessibility::AccessibleEventId::BOUNDRECT_CHANGED: + return "BOUNDRECT_CHANGED"; + case accessibility::AccessibleEventId::CARET_CHANGED: + return "CARET_CHANGED"; + case accessibility::AccessibleEventId::CHILD: + return "CHILD"; + case accessibility::AccessibleEventId::COLUMN_CHANGED: + return "COLUMN_CHANGED"; + case accessibility::AccessibleEventId::CONTENT_FLOWS_FROM_RELATION_CHANGED: + return "CONTENT_FLOWS_FROM_RELATION_CHANGED"; + case accessibility::AccessibleEventId::CONTENT_FLOWS_TO_RELATION_CHANGED: + return "CONTENT_FLOWS_TO_RELATION_CHANGED"; + case accessibility::AccessibleEventId::CONTROLLED_BY_RELATION_CHANGED: + return "CONTROLLED_BY_RELATION_CHANGED"; + case accessibility::AccessibleEventId::CONTROLLER_FOR_RELATION_CHANGED: + return "CONTROLLER_FOR_RELATION_CHANGED"; + case accessibility::AccessibleEventId::DESCRIPTION_CHANGED: + return "DESCRIPTION_CHANGED"; + case accessibility::AccessibleEventId::HYPERTEXT_CHANGED: + return "HYPERTEXT_CHANGED"; + case accessibility::AccessibleEventId::INVALIDATE_ALL_CHILDREN: + return "INVALIDATE_ALL_CHILDREN"; + case accessibility::AccessibleEventId::LABELED_BY_RELATION_CHANGED: + return "LABELED_BY_RELATION_CHANGED"; + case accessibility::AccessibleEventId::LABEL_FOR_RELATION_CHANGED: + return "LABEL_FOR_RELATION_CHANGED"; + case accessibility::AccessibleEventId::LISTBOX_ENTRY_COLLAPSED: + return "LISTBOX_ENTRY_COLLAPSED"; + case accessibility::AccessibleEventId::LISTBOX_ENTRY_EXPANDED: + return "LISTBOX_ENTRY_EXPANDED"; + case accessibility::AccessibleEventId::MEMBER_OF_RELATION_CHANGED: + return "MEMBER_OF_RELATION_CHANGED"; + case accessibility::AccessibleEventId::NAME_CHANGED: + return "NAME_CHANGED"; + case accessibility::AccessibleEventId::PAGE_CHANGED: + return "PAGE_CHANGED"; + case accessibility::AccessibleEventId::ROLE_CHANGED: + return "ROLE_CHANGED"; + case accessibility::AccessibleEventId::SECTION_CHANGED: + return "SECTION_CHANGED"; + case accessibility::AccessibleEventId::SELECTION_CHANGED: + return "SELECTION_CHANGED"; + case accessibility::AccessibleEventId::SELECTION_CHANGED_ADD: + return "SELECTION_CHANGED_ADD"; + case accessibility::AccessibleEventId::SELECTION_CHANGED_REMOVE: + return "SELECTION_CHANGED_REMOVE"; + case accessibility::AccessibleEventId::SELECTION_CHANGED_WITHIN: + return "SELECTION_CHANGED_WITHIN"; + case accessibility::AccessibleEventId::STATE_CHANGED: + return "STATE_CHANGED"; + case accessibility::AccessibleEventId::SUB_WINDOW_OF_RELATION_CHANGED: + return "SUB_WINDOW_OF_RELATION_CHANGED"; + case accessibility::AccessibleEventId::TABLE_CAPTION_CHANGED: + return "TABLE_CAPTION_CHANGED"; + case accessibility::AccessibleEventId::TABLE_COLUMN_DESCRIPTION_CHANGED: + return "TABLE_COLUMN_DESCRIPTION_CHANGED"; + case accessibility::AccessibleEventId::TABLE_COLUMN_HEADER_CHANGED: + return "TABLE_COLUMN_HEADER_CHANGED"; + case accessibility::AccessibleEventId::TABLE_MODEL_CHANGED: + return "TABLE_MODEL_CHANGED"; + case accessibility::AccessibleEventId::TABLE_ROW_DESCRIPTION_CHANGED: + return "TABLE_ROW_DESCRIPTION_CHANGED"; + case accessibility::AccessibleEventId::TABLE_ROW_HEADER_CHANGED: + return "TABLE_ROW_HEADER_CHANGED"; + case accessibility::AccessibleEventId::TABLE_SUMMARY_CHANGED: + return "TABLE_SUMMARY_CHANGED"; + case accessibility::AccessibleEventId::TEXT_ATTRIBUTE_CHANGED: + return "TEXT_ATTRIBUTE_CHANGED"; + case accessibility::AccessibleEventId::TEXT_CHANGED: + return "TEXT_CHANGED"; + case accessibility::AccessibleEventId::TEXT_SELECTION_CHANGED: + return "TEXT_SELECTION_CHANGED"; + case accessibility::AccessibleEventId::VALUE_CHANGED: + return "VALUE_CHANGED"; + case accessibility::AccessibleEventId::VISIBLE_DATA_CHANGED: + return "VISIBLE_DATA_CHANGED"; + } + 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=\"" + + ctx->getAccessibleName() + "\" description=\"" + ctx->getAccessibleDescription() + + "\""; +} + +OUString AccessibilityTools::debugName(accessibility::XAccessible* acc) +{ + return debugName(acc->getAccessibleContext().get()); +} + +OUString AccessibilityTools::debugName(const accessibility::AccessibleEventObject* evobj) +{ + return "(AccessibleEventObject) { id=" + getEventIdName(evobj->EventId) + + " old=" + evobj->OldValue.getValueTypeName() + + " new=" + evobj->NewValue.getValueTypeName() + " }"; +} + +bool AccessibilityTools::Await(const std::function& cUntilCallback, sal_uInt64 nTimeoutMs) +{ + bool success = false; + Timer aTimer("wait for event"); + aTimer.SetTimeout(nTimeoutMs); + aTimer.Start(); + do + { + Scheduler::ProcessEventsToIdle(); + success = cUntilCallback(); + } while (!success && aTimer.IsActive()); + SAL_WARN_IF(!success, "test", "timeout reached"); + return success; +} + +void AccessibilityTools::Wait(sal_uInt64 nTimeoutMs) +{ + Timer aTimer("wait for event"); + aTimer.SetTimeout(nTimeoutMs); + aTimer.Start(); + std::cout << "waiting for " << nTimeoutMs << "ms... "; + do + { + Scheduler::ProcessEventsToIdle(); + } while (aTimer.IsActive()); + std::cout << "ok." << std::endl; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ 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/AccessibilityTools.cxx b/toolkit/qa/cppunit/a11y/AccessibilityTools.cxx deleted file mode 100644 index 816e9b82b168..000000000000 --- a/toolkit/qa/cppunit/a11y/AccessibilityTools.cxx +++ /dev/null @@ -1,542 +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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "AccessibilityTools.hxx" - -#include -#include -#include -#include -#include - -#include -#include -#include - -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) -{ - css::uno::Reference ac = xacc->getAccessibleContext(); - bool isShowing = ac->getAccessibleStateSet() & accessibility::AccessibleStateType::SHOWING; - - if ((ac->getAccessibleRole() == role) && isShowing) - { - return ac; - } - else - { - int count = ac->getAccessibleChildCount(); - - for (int i = 0; i < count && i < AccessibilityTools::MAX_CHILDREN; i++) - { - css::uno::Reference ac2 - = AccessibilityTools::getAccessibleObjectForRole(ac->getAccessibleChild(i), role); - if (ac2.is()) - return ac2; - } - } - return nullptr; -} -/* FIXME: end copy */ - -bool AccessibilityTools::equals(const uno::Reference& xacc1, - const uno::Reference& xacc2) -{ - if (!xacc1.is() || !xacc2.is()) - return xacc1.is() == xacc2.is(); - return equals(xacc1->getAccessibleContext(), xacc2->getAccessibleContext()); -} - -bool AccessibilityTools::equals(const uno::Reference& xctx1, - const uno::Reference& xctx2) -{ - if (!xctx1.is() || !xctx2.is()) - return xctx1.is() == xctx2.is(); - - if (xctx1->getAccessibleRole() != xctx2->getAccessibleRole()) - return false; - - if (xctx1->getAccessibleName() != xctx2->getAccessibleName()) - return false; - - if (xctx1->getAccessibleDescription() != xctx2->getAccessibleDescription()) - return false; - - if (xctx1->getAccessibleChildCount() != xctx2->getAccessibleChildCount()) - return false; - - /* this one was not in the Java version */ - if (xctx1->getAccessibleIndexInParent() != xctx2->getAccessibleIndexInParent()) - return false; - - return equals(xctx1->getAccessibleParent(), xctx2->getAccessibleParent()); -} - -OUString AccessibilityTools::getRoleName(const sal_Int16 role) -{ - switch (role) - { - case accessibility::AccessibleRole::UNKNOWN: - return "UNKNOWN"; - case accessibility::AccessibleRole::ALERT: - return "ALERT"; - case accessibility::AccessibleRole::BUTTON_DROPDOWN: - return "BUTTON_DROPDOWN"; - case accessibility::AccessibleRole::BUTTON_MENU: - return "BUTTON_MENU"; - case accessibility::AccessibleRole::CANVAS: - return "CANVAS"; - case accessibility::AccessibleRole::CAPTION: - return "CAPTION"; - case accessibility::AccessibleRole::CHART: - return "CHART"; - case accessibility::AccessibleRole::CHECK_BOX: - return "CHECK_BOX"; - case accessibility::AccessibleRole::CHECK_MENU_ITEM: - return "CHECK_MENU_ITEM"; - case accessibility::AccessibleRole::COLOR_CHOOSER: - return "COLOR_CHOOSER"; - case accessibility::AccessibleRole::COLUMN_HEADER: - return "COLUMN_HEADER"; - case accessibility::AccessibleRole::COMBO_BOX: - return "COMBO_BOX"; - case accessibility::AccessibleRole::COMMENT: - return "COMMENT"; - case accessibility::AccessibleRole::COMMENT_END: - return "COMMENT_END"; - case accessibility::AccessibleRole::DATE_EDITOR: - return "DATE_EDITOR"; - case accessibility::AccessibleRole::DESKTOP_ICON: - return "DESKTOP_ICON"; - case accessibility::AccessibleRole::DESKTOP_PANE: - return "DESKTOP_PANE"; - case accessibility::AccessibleRole::DIALOG: - return "DIALOG"; - case accessibility::AccessibleRole::DIRECTORY_PANE: - return "DIRECTORY_PANE"; - case accessibility::AccessibleRole::DOCUMENT: - return "DOCUMENT"; - case accessibility::AccessibleRole::DOCUMENT_PRESENTATION: - return "DOCUMENT_PRESENTATION"; - case accessibility::AccessibleRole::DOCUMENT_SPREADSHEET: - return "DOCUMENT_SPREADSHEET"; - case accessibility::AccessibleRole::DOCUMENT_TEXT: - return "DOCUMENT_TEXT"; - case accessibility::AccessibleRole::EDIT_BAR: - return "EDIT_BAR"; - case accessibility::AccessibleRole::EMBEDDED_OBJECT: - return "EMBEDDED_OBJECT"; - case accessibility::AccessibleRole::END_NOTE: - return "END_NOTE"; - case accessibility::AccessibleRole::FILE_CHOOSER: - return "FILE_CHOOSER"; - case accessibility::AccessibleRole::FILLER: - return "FILLER"; - case accessibility::AccessibleRole::FONT_CHOOSER: - return "FONT_CHOOSER"; - case accessibility::AccessibleRole::FOOTER: - return "FOOTER"; - case accessibility::AccessibleRole::FOOTNOTE: - return "FOOTNOTE"; - case accessibility::AccessibleRole::FORM: - return "FORM"; - case accessibility::AccessibleRole::FRAME: - return "FRAME"; - case accessibility::AccessibleRole::GLASS_PANE: - return "GLASS_PANE"; - case accessibility::AccessibleRole::GRAPHIC: - return "GRAPHIC"; - case accessibility::AccessibleRole::GROUP_BOX: - return "GROUP_BOX"; - case accessibility::AccessibleRole::HEADER: - return "HEADER"; - case accessibility::AccessibleRole::HEADING: - return "HEADING"; - case accessibility::AccessibleRole::HYPER_LINK: - return "HYPER_LINK"; - case accessibility::AccessibleRole::ICON: - return "ICON"; - case accessibility::AccessibleRole::IMAGE_MAP: - return "IMAGE_MAP"; - case accessibility::AccessibleRole::INTERNAL_FRAME: - return "INTERNAL_FRAME"; - case accessibility::AccessibleRole::LABEL: - return "LABEL"; - case accessibility::AccessibleRole::LAYERED_PANE: - return "LAYERED_PANE"; - case accessibility::AccessibleRole::LIST: - return "LIST"; - case accessibility::AccessibleRole::LIST_ITEM: - return "LIST_ITEM"; - case accessibility::AccessibleRole::MENU: - return "MENU"; - case accessibility::AccessibleRole::MENU_BAR: - return "MENU_BAR"; - case accessibility::AccessibleRole::MENU_ITEM: - return "MENU_ITEM"; - case accessibility::AccessibleRole::NOTE: - return "NOTE"; - case accessibility::AccessibleRole::OPTION_PANE: - return "OPTION_PANE"; - case accessibility::AccessibleRole::PAGE: - return "PAGE"; - case accessibility::AccessibleRole::PAGE_TAB: - return "PAGE_TAB"; - case accessibility::AccessibleRole::PAGE_TAB_LIST: - return "PAGE_TAB_LIST"; - case accessibility::AccessibleRole::PANEL: - return "PANEL"; - case accessibility::AccessibleRole::PARAGRAPH: - return "PARAGRAPH"; - case accessibility::AccessibleRole::PASSWORD_TEXT: - return "PASSWORD_TEXT"; - case accessibility::AccessibleRole::POPUP_MENU: - return "POPUP_MENU"; - case accessibility::AccessibleRole::PROGRESS_BAR: - return "PROGRESS_BAR"; - case accessibility::AccessibleRole::PUSH_BUTTON: - return "PUSH_BUTTON"; - case accessibility::AccessibleRole::RADIO_BUTTON: - return "RADIO_BUTTON"; - case accessibility::AccessibleRole::RADIO_MENU_ITEM: - return "RADIO_MENU_ITEM"; - case accessibility::AccessibleRole::ROOT_PANE: - return "ROOT_PANE"; - case accessibility::AccessibleRole::ROW_HEADER: - return "ROW_HEADER"; - case accessibility::AccessibleRole::RULER: - return "RULER"; - case accessibility::AccessibleRole::SCROLL_BAR: - return "SCROLL_BAR"; - case accessibility::AccessibleRole::SCROLL_PANE: - return "SCROLL_PANE"; - case accessibility::AccessibleRole::SECTION: - return "SECTION"; - case accessibility::AccessibleRole::SEPARATOR: - return "SEPARATOR"; - case accessibility::AccessibleRole::SHAPE: - return "SHAPE"; - case accessibility::AccessibleRole::SLIDER: - return "SLIDER"; - case accessibility::AccessibleRole::SPIN_BOX: - return "SPIN_BOX"; - case accessibility::AccessibleRole::SPLIT_PANE: - return "SPLIT_PANE"; - case accessibility::AccessibleRole::STATIC: - return "STATIC"; - case accessibility::AccessibleRole::STATUS_BAR: - return "STATUS_BAR"; - case accessibility::AccessibleRole::TABLE: - return "TABLE"; - case accessibility::AccessibleRole::TABLE_CELL: - return "TABLE_CELL"; - case accessibility::AccessibleRole::TEXT: - return "TEXT"; - case accessibility::AccessibleRole::TEXT_FRAME: - return "TEXT_FRAME"; - case accessibility::AccessibleRole::TOGGLE_BUTTON: - return "TOGGLE_BUTTON"; - case accessibility::AccessibleRole::TOOL_BAR: - return "TOOL_BAR"; - case accessibility::AccessibleRole::TOOL_TIP: - return "TOOL_TIP"; - case accessibility::AccessibleRole::TREE: - return "TREE"; - case accessibility::AccessibleRole::TREE_ITEM: - return "TREE_ITEM"; - case accessibility::AccessibleRole::TREE_TABLE: - return "TREE_TABLE"; - case accessibility::AccessibleRole::VIEW_PORT: - return "VIEW_PORT"; - case accessibility::AccessibleRole::WINDOW: - return "WINDOW"; - }; - return "unknown"; -} - -OUString AccessibilityTools::debugAccessibleStateSet(const sal_Int64 nCombinedState) -{ - OUString combinedName; - - for (int i = 0; i < 63; i++) - { - sal_Int64 state = sal_Int64(1) << i; - if (!(state & nCombinedState)) - continue; - OUString name; - switch (state) - { - case accessibility::AccessibleStateType::ACTIVE: - name = "ACTIVE"; - break; - case accessibility::AccessibleStateType::ARMED: - name = "ARMED"; - break; - case accessibility::AccessibleStateType::BUSY: - name = "BUSY"; - break; - case accessibility::AccessibleStateType::CHECKED: - name = "CHECKED"; - break; - case accessibility::AccessibleStateType::COLLAPSE: - name = "COLLAPSE"; - break; - case accessibility::AccessibleStateType::DEFAULT: - name = "DEFAULT"; - break; - case accessibility::AccessibleStateType::DEFUNC: - name = "DEFUNC"; - break; - case accessibility::AccessibleStateType::EDITABLE: - name = "EDITABLE"; - break; - case accessibility::AccessibleStateType::ENABLED: - name = "ENABLED"; - break; - case accessibility::AccessibleStateType::EXPANDABLE: - name = "EXPANDABLE"; - break; - case accessibility::AccessibleStateType::EXPANDED: - name = "EXPANDED"; - break; - case accessibility::AccessibleStateType::FOCUSABLE: - name = "FOCUSABLE"; - break; - case accessibility::AccessibleStateType::FOCUSED: - name = "FOCUSED"; - break; - case accessibility::AccessibleStateType::HORIZONTAL: - name = "HORIZONTAL"; - break; - case accessibility::AccessibleStateType::ICONIFIED: - name = "ICONIFIED"; - break; - case accessibility::AccessibleStateType::INDETERMINATE: - name = "INDETERMINATE"; - break; - case accessibility::AccessibleStateType::INVALID: - name = "INVALID"; - break; - case accessibility::AccessibleStateType::MANAGES_DESCENDANTS: - name = "MANAGES_DESCENDANTS"; - break; - case accessibility::AccessibleStateType::MODAL: - name = "MODAL"; - break; - case accessibility::AccessibleStateType::MOVEABLE: - name = "MOVEABLE"; - break; - case accessibility::AccessibleStateType::MULTI_LINE: - name = "MULTI_LINE"; - break; - case accessibility::AccessibleStateType::MULTI_SELECTABLE: - name = "MULTI_SELECTABLE"; - break; - case accessibility::AccessibleStateType::OFFSCREEN: - name = "OFFSCREEN"; - break; - case accessibility::AccessibleStateType::OPAQUE: - name = "OPAQUE"; - break; - case accessibility::AccessibleStateType::PRESSED: - name = "PRESSED"; - break; - case accessibility::AccessibleStateType::RESIZABLE: - name = "RESIZABLE"; - break; - case accessibility::AccessibleStateType::SELECTABLE: - name = "SELECTABLE"; - break; - case accessibility::AccessibleStateType::SELECTED: - name = "SELECTED"; - break; - case accessibility::AccessibleStateType::SENSITIVE: - name = "SENSITIVE"; - break; - case accessibility::AccessibleStateType::SHOWING: - name = "SHOWING"; - break; - case accessibility::AccessibleStateType::SINGLE_LINE: - name = "SINGLE_LINE"; - break; - case accessibility::AccessibleStateType::STALE: - name = "STALE"; - break; - case accessibility::AccessibleStateType::TRANSIENT: - name = "TRANSIENT"; - break; - case accessibility::AccessibleStateType::VERTICAL: - name = "VERTICAL"; - break; - case accessibility::AccessibleStateType::VISIBLE: - name = "VISIBLE"; - break; - } - if (combinedName.getLength()) - combinedName += " | "; - combinedName += name; - } - - if (combinedName.isEmpty()) - return "unknown"; - return combinedName; -} - -OUString AccessibilityTools::getEventIdName(const sal_Int16 event_id) -{ - switch (event_id) - { - case accessibility::AccessibleEventId::ACTION_CHANGED: - return "ACTION_CHANGED"; - case accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED: - return "ACTIVE_DESCENDANT_CHANGED"; - case accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS: - return "ACTIVE_DESCENDANT_CHANGED_NOFOCUS"; - case accessibility::AccessibleEventId::BOUNDRECT_CHANGED: - return "BOUNDRECT_CHANGED"; - case accessibility::AccessibleEventId::CARET_CHANGED: - return "CARET_CHANGED"; - case accessibility::AccessibleEventId::CHILD: - return "CHILD"; - case accessibility::AccessibleEventId::COLUMN_CHANGED: - return "COLUMN_CHANGED"; - case accessibility::AccessibleEventId::CONTENT_FLOWS_FROM_RELATION_CHANGED: - return "CONTENT_FLOWS_FROM_RELATION_CHANGED"; - case accessibility::AccessibleEventId::CONTENT_FLOWS_TO_RELATION_CHANGED: - return "CONTENT_FLOWS_TO_RELATION_CHANGED"; - case accessibility::AccessibleEventId::CONTROLLED_BY_RELATION_CHANGED: - return "CONTROLLED_BY_RELATION_CHANGED"; - case accessibility::AccessibleEventId::CONTROLLER_FOR_RELATION_CHANGED: - return "CONTROLLER_FOR_RELATION_CHANGED"; - case accessibility::AccessibleEventId::DESCRIPTION_CHANGED: - return "DESCRIPTION_CHANGED"; - case accessibility::AccessibleEventId::HYPERTEXT_CHANGED: - return "HYPERTEXT_CHANGED"; - case accessibility::AccessibleEventId::INVALIDATE_ALL_CHILDREN: - return "INVALIDATE_ALL_CHILDREN"; - case accessibility::AccessibleEventId::LABELED_BY_RELATION_CHANGED: - return "LABELED_BY_RELATION_CHANGED"; - case accessibility::AccessibleEventId::LABEL_FOR_RELATION_CHANGED: - return "LABEL_FOR_RELATION_CHANGED"; - case accessibility::AccessibleEventId::LISTBOX_ENTRY_COLLAPSED: - return "LISTBOX_ENTRY_COLLAPSED"; - case accessibility::AccessibleEventId::LISTBOX_ENTRY_EXPANDED: - return "LISTBOX_ENTRY_EXPANDED"; - case accessibility::AccessibleEventId::MEMBER_OF_RELATION_CHANGED: - return "MEMBER_OF_RELATION_CHANGED"; - case accessibility::AccessibleEventId::NAME_CHANGED: - return "NAME_CHANGED"; - case accessibility::AccessibleEventId::PAGE_CHANGED: - return "PAGE_CHANGED"; - case accessibility::AccessibleEventId::ROLE_CHANGED: - return "ROLE_CHANGED"; - case accessibility::AccessibleEventId::SECTION_CHANGED: - return "SECTION_CHANGED"; - case accessibility::AccessibleEventId::SELECTION_CHANGED: - return "SELECTION_CHANGED"; - case accessibility::AccessibleEventId::SELECTION_CHANGED_ADD: - return "SELECTION_CHANGED_ADD"; - case accessibility::AccessibleEventId::SELECTION_CHANGED_REMOVE: - return "SELECTION_CHANGED_REMOVE"; - case accessibility::AccessibleEventId::SELECTION_CHANGED_WITHIN: - return "SELECTION_CHANGED_WITHIN"; - case accessibility::AccessibleEventId::STATE_CHANGED: - return "STATE_CHANGED"; - case accessibility::AccessibleEventId::SUB_WINDOW_OF_RELATION_CHANGED: - return "SUB_WINDOW_OF_RELATION_CHANGED"; - case accessibility::AccessibleEventId::TABLE_CAPTION_CHANGED: - return "TABLE_CAPTION_CHANGED"; - case accessibility::AccessibleEventId::TABLE_COLUMN_DESCRIPTION_CHANGED: - return "TABLE_COLUMN_DESCRIPTION_CHANGED"; - case accessibility::AccessibleEventId::TABLE_COLUMN_HEADER_CHANGED: - return "TABLE_COLUMN_HEADER_CHANGED"; - case accessibility::AccessibleEventId::TABLE_MODEL_CHANGED: - return "TABLE_MODEL_CHANGED"; - case accessibility::AccessibleEventId::TABLE_ROW_DESCRIPTION_CHANGED: - return "TABLE_ROW_DESCRIPTION_CHANGED"; - case accessibility::AccessibleEventId::TABLE_ROW_HEADER_CHANGED: - return "TABLE_ROW_HEADER_CHANGED"; - case accessibility::AccessibleEventId::TABLE_SUMMARY_CHANGED: - return "TABLE_SUMMARY_CHANGED"; - case accessibility::AccessibleEventId::TEXT_ATTRIBUTE_CHANGED: - return "TEXT_ATTRIBUTE_CHANGED"; - case accessibility::AccessibleEventId::TEXT_CHANGED: - return "TEXT_CHANGED"; - case accessibility::AccessibleEventId::TEXT_SELECTION_CHANGED: - return "TEXT_SELECTION_CHANGED"; - case accessibility::AccessibleEventId::VALUE_CHANGED: - return "VALUE_CHANGED"; - case accessibility::AccessibleEventId::VISIBLE_DATA_CHANGED: - return "VISIBLE_DATA_CHANGED"; - } - return "unknown"; -} - -OUString AccessibilityTools::debugName(accessibility::XAccessibleContext* ctx) -{ - return "role=" + AccessibilityTools::getRoleName(ctx->getAccessibleRole()) + " name=\"" - + ctx->getAccessibleName() + "\" description=\"" + ctx->getAccessibleDescription() - + "\""; -} - -OUString AccessibilityTools::debugName(accessibility::XAccessible* acc) -{ - return debugName(acc->getAccessibleContext().get()); -} - -OUString AccessibilityTools::debugName(const accessibility::AccessibleEventObject* evobj) -{ - return "(AccessibleEventObject) { id=" + getEventIdName(evobj->EventId) - + " old=" + evobj->OldValue.getValueTypeName() - + " new=" + evobj->NewValue.getValueTypeName() + " }"; -} - -bool AccessibilityTools::Await(const std::function& cUntilCallback, sal_uInt64 nTimeoutMs) -{ - bool success = false; - Timer aTimer("wait for event"); - aTimer.SetTimeout(nTimeoutMs); - aTimer.Start(); - do - { - Scheduler::ProcessEventsToIdle(); - success = cUntilCallback(); - } while (!success && aTimer.IsActive()); - SAL_WARN_IF(!success, "test", "timeout reached"); - return success; -} - -void AccessibilityTools::Wait(sal_uInt64 nTimeoutMs) -{ - Timer aTimer("wait for event"); - aTimer.SetTimeout(nTimeoutMs); - aTimer.Start(); - std::cout << "waiting for " << nTimeoutMs << "ms... "; - do - { - Scheduler::ProcessEventsToIdle(); - } while (aTimer.IsActive()); - std::cout << "ok." << std::endl; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/toolkit/qa/cppunit/a11y/AccessibilityTools.hxx b/toolkit/qa/cppunit/a11y/AccessibilityTools.hxx deleted file mode 100644 index 96afe4377f94..000000000000 --- a/toolkit/qa/cppunit/a11y/AccessibilityTools.hxx +++ /dev/null @@ -1,155 +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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#pragma once - -#include -#include - -#include - -#include -#include -#include - -class AccessibilityTools -{ -public: - /** Maximum number of children to work on. This is especially useful for - * Calc which has a million elements, if not more. */ - static const sal_Int32 MAX_CHILDREN = 500; - - static css::uno::Reference - getAccessibleObjectForRole(const css::uno::Reference& xacc, - sal_Int16 role); - - static bool equals(const css::uno::Reference& xacc1, - const css::uno::Reference& xacc2); - static bool equals(const css::uno::Reference& xctx1, - const css::uno::Reference& xctx2); - - static OUString getRoleName(const sal_Int16 role); - static OUString getStateName(const sal_Int16 state); - static OUString getEventIdName(const sal_Int16 event_id); - - template static std::string debugString(const css::uno::Reference& x) - { - return debugString(x.get()); - } - - template static std::string debugString(const T& x) { return debugString(&x); } - - template static std::string debugString(const T* p) - { - /* only the forwarding to debugName() might actually dereference @c p, - * and we rely on specializations to be as constant as possible and not - * violate the cast here. In practice it'll be the case for all types - * handle if we carefully write the specializations. In most case the - * specialization could take a const itself if the methods were - * properly marked const, but well. */ - return debugString(const_cast(p)); - } - - template static std::string debugString(T* p) - { - CPPUNIT_NS::OStringStream ost; - - ost << "(" << static_cast(p) << ")"; - if (p != nullptr) - ost << " " << debugName(p); - - return ost.str(); - } - - static OUString debugAccessibleStateSet(sal_Int64 p); - - /** - * @brief Process events until a condition or a timeout - * @param cUntilCallback Callback condition - * @param nTimeoutMs Maximum time in ms to wait for condition - * @returns @c true if the condition was met, or @c false if the timeout - * has been reached. - * - * Processes events until idle, and either until the given condition - * becomes @c true or a timeout is reached. - * - * This is similar to Scheduler::ProcessEventsToIdle() but awaits a - * condition up to a timeout. This is useful if the waited-on condition - * might happen after the first idle time. The timeout helps in case the - * condition is not satisfied in reasonable time. - * - * @p cUntilCallback is called each time the scheduler reaches idle to check - * whether the condition is met. - * - * Example: - * @code - * ProcessEvents([&]() { return taskHasRun; }); - * @endcode - * - * @see Scheduler::ProcessEventsToIdle() - */ - static bool Await(const std::function& cUntilCallback, sal_uInt64 nTimeoutMs = 3000); - - /** - * @brief Process events for a given time - * @param nTimeoutMs Time to dispatch events for - * - * Process events for a given time. This can be useful if waiting is in - * order but there is no actual condition to wait on (e.g. expect - * something *not* to happen). This similar in spirit to - * @c sleep(nTimeoutMs), but dispatches events during the wait. - * - * This function should be used sparsely because waiting a given time is - * rarely a good solution for a problem, but in some specific situations - * there is no better alternative (like, again, waiting for something not - * to happen). - */ - static void Wait(sal_uInt64 nTimeoutMs); - -private: - static OUString debugName(css::accessibility::XAccessibleContext* xctx); - static OUString debugName(css::accessibility::XAccessible* xacc); - static OUString debugName(const css::accessibility::AccessibleEventObject* evobj); -}; - -CPPUNIT_NS_BEGIN -/* How to generate those automatically? We don't want to match all types - * not to mess up cppunit for types we don't support */ -#define AT_ASSERTION_TRAITS(T) \ - template <> struct assertion_traits> \ - { \ - static bool equal(const css::uno::Reference& x, const css::uno::Reference& y) \ - { \ - return AccessibilityTools::equals(x, y); \ - } \ - \ - static std::string toString(const css::uno::Reference& x) \ - { \ - return AccessibilityTools::debugString(x); \ - } \ - } - -AT_ASSERTION_TRAITS(css::accessibility::XAccessible); -AT_ASSERTION_TRAITS(css::accessibility::XAccessibleContext); - -#undef AT_ASSERTION_TRAITS - -CPPUNIT_NS_END - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ 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; -- cgit v1.2.3