summaryrefslogtreecommitdiffstats
path: root/toolkit/qa/cppunit/a11y
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/qa/cppunit/a11y')
-rw-r--r--toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx139
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx291
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx66
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx164
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleContextTester.hxx62
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx185
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.hxx54
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.cxx53
-rw-r--r--toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.hxx50
9 files changed, 1064 insertions, 0 deletions
diff --git a/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx b/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx
new file mode 100644
index 0000000000..5bf522fb2e
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/AccessibleStatusBarTest.cxx
@@ -0,0 +1,139 @@
+/* -*- 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 <string>
+
+#include <com/sun/star/accessibility/AccessibleRole.hpp>
+#include <com/sun/star/accessibility/XAccessible.hpp>
+#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <rtl/ustrbuf.hxx>
+#include <test/a11y/accessibletestbase.hxx>
+#include <vcl/scheduler.hxx>
+
+#include <test/a11y/AccessibilityTools.hxx>
+#include "XAccessibleComponentTester.hxx"
+#include "XAccessibleContextTester.hxx"
+#include "XAccessibleExtendedComponentTester.hxx"
+#include "XAccessibleEventBroadcasterTester.hxx"
+
+using namespace css;
+
+namespace
+{
+class AccessibleStatusBarTest : public test::AccessibleTestBase
+{
+private:
+ uno::Reference<accessibility::XAccessibleContext>
+ getTestObject(const uno::Reference<awt::XWindow>& xWindow);
+ void runAllTests();
+ void testDocument(std::string_view sKind);
+
+ void testWriterDoc() { testDocument("swriter"); }
+ void testMathDoc() { testDocument("smath"); }
+ void testDrawDoc() { testDocument("sdraw"); }
+ void testImpressDoc() { testDocument("simpress"); }
+ void testCalcDoc() { testDocument("scalc"); }
+
+public:
+ CPPUNIT_TEST_SUITE(AccessibleStatusBarTest);
+ CPPUNIT_TEST(testWriterDoc);
+ CPPUNIT_TEST(testMathDoc);
+ CPPUNIT_TEST(testDrawDoc);
+ CPPUNIT_TEST(testImpressDoc);
+ CPPUNIT_TEST(testCalcDoc);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+uno::Reference<accessibility::XAccessibleContext>
+AccessibleStatusBarTest::getTestObject(const uno::Reference<awt::XWindow>& xWindow)
+{
+ uno::Reference<accessibility::XAccessible> xAccessible(xWindow, uno::UNO_QUERY_THROW);
+ std::cout << "got accessible: " << xAccessible << std::endl;
+ std::cout << "accessible name: " << AccessibilityTools::debugString(xAccessible) << std::endl;
+
+ auto xContext = AccessibilityTools::getAccessibleObjectForRole(
+ xAccessible, accessibility::AccessibleRole::STATUS_BAR);
+ std::cout << "got context: " << xContext << std::endl;
+ std::cout << "context name: " << AccessibilityTools::debugString(xContext) << std::endl;
+
+ Scheduler::ProcessEventsToIdle(); // not sure why?
+
+ uno::Reference<lang::XServiceInfo> xSI(xContext, uno::UNO_QUERY_THROW);
+ std::cout << "implementation name: " << xSI->getImplementationName() << std::endl;
+ auto serviceNames = xSI->getSupportedServiceNames();
+ std::cout << "has " << serviceNames.size() << " services:" << std::endl;
+ for (auto& service : serviceNames)
+ std::cout << " * service: " << service << std::endl;
+
+ return xContext;
+}
+
+void AccessibleStatusBarTest::runAllTests()
+{
+ auto xContext = getTestObject(mxWindow);
+
+ uno::Reference<accessibility::XAccessibleComponent> xAccessibleComponent(xContext,
+ uno::UNO_QUERY_THROW);
+ XAccessibleComponentTester componentTester(xAccessibleComponent);
+ componentTester.testAll();
+
+ XAccessibleContextTester contextTester(xContext);
+ contextTester.testAll();
+
+ uno::Reference<accessibility::XAccessibleExtendedComponent> xAccessibleExtendedComponent(
+ xContext, uno::UNO_QUERY_THROW);
+ XAccessibleExtendedComponentTester extendedComponentTester(xAccessibleExtendedComponent);
+ extendedComponentTester.testAll();
+
+ uno::Reference<accessibility::XAccessibleEventBroadcaster> xAccessibleEventBroadcaster(
+ xContext, uno::UNO_QUERY_THROW);
+ XAccessibleEventBroadcasterTester eventBroadcasterTester(xAccessibleEventBroadcaster, mxWindow);
+ eventBroadcasterTester.testAll();
+}
+
+void AccessibleStatusBarTest::testDocument(std::string_view sKind)
+{
+ rtl::OUStringBuffer sURL("private:factory/");
+ sURL.appendAscii(sKind.data(), sKind.length());
+
+ load(sURL.makeStringAndClear());
+
+ std::cout << "got document: " << mxDocument << std::endl;
+
+ Scheduler::ProcessEventsToIdle();
+
+ runAllTests();
+
+ // close document
+ close();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AccessibleStatusBarTest);
+} // namespace
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx
new file mode 100644
index 0000000000..fa5fb9f705
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.cxx
@@ -0,0 +1,291 @@
+/* -*- 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 "XAccessibleComponentTester.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <com/sun/star/accessibility/AccessibleStateType.hpp>
+#include <com/sun/star/accessibility/XAccessible.hpp>
+#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+#include <com/sun/star/awt/Point.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <tools/color.hxx>
+
+#include <test/a11y/AccessibilityTools.hxx>
+
+using namespace css;
+
+/**
+ * @brief Checks the component's bounds
+ *
+ * Checks the X and Y coordinates are non-negative, and that the width and
+ * height are greater than 0.
+ *
+ * Coherence with @c getLocation() is tested in the test for the
+ * latter.
+ */
+void XAccessibleComponentTester::testBounds()
+{
+ auto bounds = mxComponent->getBounds();
+ std::cout << "bounds: " << bounds.Width << "x" << bounds.Height << std::showpos << bounds.X
+ << bounds.Y << std::noshowpos << std::endl;
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), bounds.X);
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), bounds.Y);
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), bounds.Width);
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), bounds.Height);
+}
+
+/**
+ * @brief Tests results of XAccessibleComponent::getSize()
+ *
+ * Succeeds if the size is the same as in bounds.
+ */
+void XAccessibleComponentTester::testSize()
+{
+ auto bounds = mxComponent->getBounds();
+ auto size = mxComponent->getSize();
+ CPPUNIT_ASSERT_EQUAL(bounds.Width, size.Width);
+ CPPUNIT_ASSERT_EQUAL(bounds.Height, size.Height);
+}
+
+/**
+ * @brief Tests results of XAccessibleComponent::getBounds()
+ *
+ * First checks 4 inner bounds (upper, lower, left and right) of component
+ * bounding box to contain at least one point of the component. Second 4 outer
+ * bounds are checked to not contain any component points.
+ *
+ * Succeeds if inner bounds contain component points and outer bounds don't
+ * contain any component points.
+ */
+void XAccessibleComponentTester::testContainsPoint()
+{
+ auto bounds = mxComponent->getBounds();
+
+ /* upper end */
+ int curX = 0;
+ while (!mxComponent->containsPoint(awt::Point(curX, 0)) && curX < bounds.Width)
+ curX++;
+ CPPUNIT_ASSERT_MESSAGE("Upper bound of box contains no component points", curX < bounds.Width);
+ std::cout << "Upper bound of box contains point (" << curX << ",0)" << std::endl;
+ /* lower end */
+ curX = 0;
+ while (!mxComponent->containsPoint(awt::Point(curX, bounds.Height - 1)) && curX < bounds.Width)
+ curX++;
+ CPPUNIT_ASSERT_MESSAGE("Lower bound of box contains no component points", curX < bounds.Width);
+ std::cout << "Lower bound of box contains point (" << curX << "," << (bounds.Height - 1) << ")"
+ << std::endl;
+ /* left end */
+ int curY = 0;
+ while (!mxComponent->containsPoint(awt::Point(0, curY)) && curY < bounds.Height)
+ curY++;
+ CPPUNIT_ASSERT_MESSAGE("Left bound of box contains no component points", curY < bounds.Height);
+ std::cout << "Left bound of box contains point (0," << curY << ")" << std::endl;
+ /* right end */
+ curY = 0;
+ while (!mxComponent->containsPoint(awt::Point(bounds.Width - 1, curY)) && curY < bounds.Height)
+ curY++;
+ CPPUNIT_ASSERT_MESSAGE("Right bound of box contains no component points", curY < bounds.Height);
+ std::cout << "Right bound of box contains point (" << (bounds.Width - 1) << "," << curY << ")"
+ << std::endl;
+ /* no match outside the bounds */
+ for (int x = -1; x <= bounds.Width; x++)
+ {
+ CPPUNIT_ASSERT_MESSAGE("Outer upper bound CONTAINS a component point",
+ !mxComponent->containsPoint(awt::Point(x, -1)));
+ CPPUNIT_ASSERT_MESSAGE("Outer lower bound CONTAINS a component point",
+ !mxComponent->containsPoint(awt::Point(x, bounds.Height)));
+ }
+ for (int y = -1; y <= bounds.Height; y++)
+ {
+ CPPUNIT_ASSERT_MESSAGE("Outer left bound CONTAINS a component point",
+ !mxComponent->containsPoint(awt::Point(-1, y)));
+ CPPUNIT_ASSERT_MESSAGE("Outer right bound CONTAINS a component point",
+ !mxComponent->containsPoint(awt::Point(bounds.Width, y)));
+ }
+}
+
+/**
+ * @brief Tests results of XAccessibleComponent::getAccessibleAtPoint()
+ *
+ * Iterates through all children which implement
+ * <code>XAccessibleComponent</code> (if they exist) determines their
+ * boundaries and tries to get each child by <code>getAccessibleAtPoint</code>
+ * passing point which belongs to the child.
+ * Also the point is checked which doesn't belong to child boundary box.
+ *
+ * Succeeds if in the first cases the right children are returned, and in the
+ * second <code>null</code> or another child is returned.
+ */
+void XAccessibleComponentTester::testAccessibleAtPoint()
+{
+ sal_Int64 count = mxContext->getAccessibleChildCount();
+ std::cout << "Found " << count << " children" << std::endl;
+ for (sal_Int64 i = 0; i < count && i < AccessibilityTools::MAX_CHILDREN; i++)
+ {
+ auto child = mxContext->getAccessibleChild(i);
+ uno::Reference<accessibility::XAccessibleContext> childContext(
+ child->getAccessibleContext(), uno::UNO_SET_THROW);
+ std::cout << "* Found child: " << AccessibilityTools::debugString(child) << std::endl;
+ std::cout << " states: "
+ << AccessibilityTools::debugAccessibleStateSet(
+ childContext->getAccessibleStateSet())
+ << std::endl;
+ uno::Reference<accessibility::XAccessibleComponent> xChildComponent(childContext,
+ uno::UNO_QUERY);
+ std::cout << " component: " << xChildComponent << std::endl;
+ if (!xChildComponent)
+ continue;
+
+ auto childBounds = xChildComponent->getBounds();
+ if (childBounds.X == -1)
+ continue;
+ std::cout << " bounds: " << childBounds.Width << "x" << childBounds.Height << std::showpos
+ << childBounds.X << childBounds.Y << std::noshowpos << std::endl;
+
+ std::cout << "finding the point which lies on the component" << std::endl;
+ int curX = 0;
+ int curY = 0;
+ while (!xChildComponent->containsPoint(awt::Point(curX, curY)) && curX < childBounds.Width)
+ {
+ curX++;
+ curY++;
+ }
+ if (curX >= childBounds.Width)
+ {
+ std::cout << "Couldn't find a point with contains" << std::endl;
+ continue;
+ }
+ else
+ {
+ std::cout << "Child found at point +" << childBounds.X + curX << "+"
+ << childBounds.Y + curY << std::endl;
+ }
+
+ // trying the point laying on child
+ auto xAccAtPoint
+ = mxComponent->getAccessibleAtPoint(awt::Point(childBounds.X, childBounds.Y));
+ CPPUNIT_ASSERT_MESSAGE("Child not found at point", xAccAtPoint.is());
+ if (!AccessibilityTools::equals(child, xAccAtPoint))
+ {
+ auto idxExpected = childContext->getAccessibleIndexInParent();
+ auto idxResult = xAccAtPoint->getAccessibleContext()->getAccessibleIndexInParent();
+ std::cout << "The child found (" << AccessibilityTools::debugString(xAccAtPoint)
+ << ") is not the expected one (" << AccessibilityTools::debugString(child)
+ << ")" << std::endl;
+ if (idxExpected < idxResult)
+ {
+ std::cout << "-- it probably is hidden behind? Skipping." << std::endl;
+ }
+ else
+ {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("The child found is NOT the expected one", child,
+ xAccAtPoint);
+ }
+ }
+
+ // trying the point NOT laying on child
+ xAccAtPoint
+ = mxComponent->getAccessibleAtPoint(awt::Point(childBounds.X - 1, childBounds.Y - 1));
+ if (xAccAtPoint.is())
+ {
+ CPPUNIT_ASSERT_MESSAGE("Child found OUTSIDE its bounds",
+ !AccessibilityTools::equals(child, xAccAtPoint));
+ }
+ }
+}
+
+/**
+ * @brief Tests results of XAccessibleComponent::getLocation()
+ *
+ * Succeeds if the location is the same as location of boundary obtained by
+ * the <code>getBounds()</code> method.
+ */
+void XAccessibleComponentTester::testLocation()
+{
+ auto bounds = mxComponent->getBounds();
+ auto location = mxComponent->getLocation();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Invalid X location", bounds.X, location.X);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Invalid Y location", bounds.Y, location.Y);
+}
+
+/**
+ * @brief Tests results of XAccessibleComponent::getLocationOnScreen()
+ * @returns @c true on success.
+ *
+ * Get the screen location of the component and its parent
+ * (if it exists and supports <code>XAccessibleComponent</code>).
+ *
+ * Succeeds component screen location equals to screen location of its parent
+ * plus location of the component relative to the parent.
+ */
+void XAccessibleComponentTester::testLocationOnScreen()
+{
+ auto location = mxComponent->getLocationOnScreen();
+ std::cout << "location on screen: +" << location.X << "+" << location.Y << std::endl;
+
+ auto xParent = mxContext->getAccessibleParent();
+ if (!xParent.is())
+ std::cout << "No parent" << std::endl;
+ else
+ {
+ std::cout << "Found parent: " << AccessibilityTools::debugString(xParent) << std::endl;
+ uno::Reference<accessibility::XAccessibleComponent> xParentComponent(
+ xParent->getAccessibleContext(), uno::UNO_QUERY);
+ if (!xParentComponent.is())
+ std::cout << "Parent is not a Component" << std::endl;
+ else
+ {
+ auto bounds = mxComponent->getBounds();
+ auto parentLocation = xParentComponent->getLocationOnScreen();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Invalid X screen location", parentLocation.X + bounds.X,
+ location.X);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Invalid Y screen location", parentLocation.Y + bounds.Y,
+ location.Y);
+ }
+ }
+}
+
+/**
+ * Just calls the method.
+ */
+void XAccessibleComponentTester::testGrabFocus() { mxComponent->grabFocus(); }
+
+/**
+ * Just calls the method.
+ */
+void XAccessibleComponentTester::testGetForeground()
+{
+ auto color = mxComponent->getForeground();
+ std::cout << "foreground color: " << Color(ColorAlpha, color) << std::endl;
+}
+
+/**
+ * Just calls the method.
+ */
+void XAccessibleComponentTester::testGetBackground()
+{
+ auto color = mxComponent->getBackground();
+ std::cout << "background color: " << Color(ColorAlpha, color) << std::endl;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx
new file mode 100644
index 0000000000..5965374a3f
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleComponentTester.hxx
@@ -0,0 +1,66 @@
+/* -*- 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 <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+
+#include <test/a11y/AccessibilityTools.hxx>
+
+class XAccessibleComponentTester
+{
+private:
+ const css::uno::Reference<css::accessibility::XAccessibleComponent> mxComponent;
+ const css::uno::Reference<css::accessibility::XAccessibleContext> mxContext;
+
+public:
+ XAccessibleComponentTester(
+ const css::uno::Reference<css::accessibility::XAccessibleComponent>& component)
+ : mxComponent(component)
+ , mxContext(component, css::uno::UNO_QUERY_THROW)
+ {
+ }
+
+ void testBounds();
+ void testSize();
+ void testContainsPoint();
+ void testAccessibleAtPoint();
+ void testLocation();
+ void testLocationOnScreen();
+ void testGrabFocus();
+ void testGetForeground();
+ void testGetBackground();
+
+ void testAll()
+ {
+ testBounds();
+ testSize();
+ testContainsPoint();
+ testAccessibleAtPoint();
+ testLocation();
+ testLocationOnScreen();
+ testGrabFocus();
+ testGetForeground();
+ testGetBackground();
+ }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx
new file mode 100644
index 0000000000..9d7fdb992e
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.cxx
@@ -0,0 +1,164 @@
+/* -*- 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 "XAccessibleContextTester.hxx"
+
+#include <cppunit/TestAssert.h>
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+
+#include <test/a11y/AccessibilityTools.hxx>
+
+/**
+ * @brief Tries to get every child and checks its parent.
+ *
+ * Checks that the parent of every child and the tested component are the same object.
+ */
+void XAccessibleContextTester::testGetAccessibleChild()
+{
+ sal_Int64 count = mxContext->getAccessibleChildCount();
+ for (sal_Int64 i = 0; i < count && i < AccessibilityTools::MAX_CHILDREN; i++)
+ {
+ auto child = mxContext->getAccessibleChild(i);
+ auto childCtx = child->getAccessibleContext();
+
+ std::cout << " Child " << i << ": " << AccessibilityTools::debugString(childCtx)
+ << std::endl;
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("child's parent context is not parent's context!",
+ childCtx->getAccessibleParent()->getAccessibleContext(),
+ mxContext);
+ }
+}
+
+/**
+ * @brief Calls the method.
+ *
+ * Checks that the child count is non-negative.
+ */
+void XAccessibleContextTester::testGetAccessibleChildCount()
+{
+ sal_Int64 childCount = mxContext->getAccessibleChildCount();
+ std::cout << childCount << " children found." << std::endl;
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int64>(0), childCount);
+}
+
+/**
+ * @brief Get the accessible description of the component.
+ */
+void XAccessibleContextTester::testGetAccessibleDescription()
+{
+ auto desc = mxContext->getAccessibleDescription();
+ std::cout << "The description is '" << desc << "'" << std::endl;
+}
+
+/**
+ * @brief Checks the index in parent
+ *
+ * Checks that the parent's child and the tested component are the same objects.
+ *
+ * Retrieves the index of tested component in its parent.
+ * Then gets the parent's child by this index and compares
+ * it with tested component.
+ */
+void XAccessibleContextTester::testGetAccessibleIndexInParent()
+{
+ sal_Int64 idx = mxContext->getAccessibleIndexInParent();
+ std::cout << "The index in parent is " << idx << std::endl;
+
+ auto parent = mxContext->getAccessibleParent();
+ CPPUNIT_ASSERT(parent.is());
+ auto parentCtx = parent->getAccessibleContext();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Parent's child context at our index is not us!", mxContext,
+ parentCtx->getAccessibleChild(idx)->getAccessibleContext());
+}
+
+/**
+ * @brief Get the accessible name of the component.
+ */
+void XAccessibleContextTester::testGetAccessibleName()
+{
+ auto name = mxContext->getAccessibleName();
+ std::cout << "The name is '" << name << "'" << std::endl;
+}
+
+/**
+ * @brief Just gets the parent.
+ *
+ * Checks that the parent is not null.
+ */
+void XAccessibleContextTester::testGetAccessibleParent()
+{
+ // assume that the component is not ROOT
+ auto parent = mxContext->getAccessibleParent();
+ std::cout << "The parent is " << AccessibilityTools::debugString(parent) << std::endl;
+ CPPUNIT_ASSERT_MESSAGE("parent is not set", parent.is());
+}
+
+/**
+ * @brief Just gets the relation set.
+ *
+ * Checks that the relation set is not null.
+ */
+void XAccessibleContextTester::testGetAccessibleRelationSet()
+{
+ auto relSet = mxContext->getAccessibleRelationSet();
+ CPPUNIT_ASSERT_MESSAGE("relation set is not set", relSet.is());
+}
+
+/**
+ * @brief Get the accessible role of component.
+ *
+ * Checks that the role is a non-negative number.
+ */
+void XAccessibleContextTester::testGetAccessibleRole()
+{
+ sal_Int32 role = mxContext->getAccessibleRole();
+ std::cout << "The role is " << role << " (" << AccessibilityTools::getRoleName(role) << ")"
+ << std::endl;
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), role);
+}
+
+/**
+ * @brief Just gets the state set.
+ *
+ * Checks that the state set is not null.
+ */
+void XAccessibleContextTester::testGetAccessibleStateSet()
+{
+ sal_Int64 stateSet = mxContext->getAccessibleStateSet();
+ std::cout << "The state set is: " << AccessibilityTools::debugAccessibleStateSet(stateSet)
+ << std::endl;
+}
+
+/**
+ * @brief Gets the locale.
+ *
+ * Checks that @c Country and @c Language fields of locale structure are not empty.
+ */
+void XAccessibleContextTester::testGetLocale()
+{
+ auto loc = mxContext->getLocale();
+ std::cout << "The locale is " << loc.Language << "," << loc.Country << std::endl;
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), loc.Language.getLength());
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), loc.Country.getLength());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleContextTester.hxx b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.hxx
new file mode 100644
index 0000000000..b399028cf8
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleContextTester.hxx
@@ -0,0 +1,62 @@
+/* -*- 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 <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+
+class XAccessibleContextTester
+{
+protected:
+ const css::uno::Reference<css::accessibility::XAccessibleContext> mxContext;
+
+public:
+ XAccessibleContextTester(const css::uno::Reference<css::accessibility::XAccessibleContext>& ctx)
+ : mxContext(ctx)
+ {
+ }
+
+ void testGetAccessibleChild();
+ void testGetAccessibleChildCount();
+ void testGetAccessibleDescription();
+ void testGetAccessibleIndexInParent();
+ void testGetAccessibleName();
+ void testGetAccessibleParent();
+ void testGetAccessibleRelationSet();
+ void testGetAccessibleRole();
+ void testGetAccessibleStateSet();
+ void testGetLocale();
+
+ void testAll()
+ {
+ testGetAccessibleChild();
+ testGetAccessibleChildCount();
+ testGetAccessibleDescription();
+ testGetAccessibleIndexInParent();
+ testGetAccessibleName();
+ testGetAccessibleParent();
+ testGetAccessibleRelationSet();
+ testGetAccessibleRole();
+ testGetAccessibleStateSet();
+ testGetLocale();
+ }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx
new file mode 100644
index 0000000000..852c91c341
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.cxx
@@ -0,0 +1,185 @@
+/* -*- 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 "XAccessibleEventBroadcasterTester.hxx"
+
+#include <iostream>
+
+#include <cppunit/TestAssert.h>
+
+#include <com/sun/star/accessibility/AccessibleEventObject.hpp>
+#include <com/sun/star/accessibility/AccessibleStateType.hpp>
+#include <com/sun/star/accessibility/XAccessible.hpp>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
+#include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
+#include <com/sun/star/awt/PosSize.hpp>
+#include <com/sun/star/awt/Rectangle.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/lang/EventObject.hpp>
+
+#include <cppuhelper/implbase.hxx>
+#include <rtl/ref.hxx>
+#include <sal/log.hxx>
+
+#include <test/a11y/AccessibilityTools.hxx>
+
+using namespace css;
+
+namespace
+{
+class EvListener : public cppu::WeakImplHelper<accessibility::XAccessibleEventListener>
+{
+public:
+ bool mbGotEvent;
+
+ EvListener()
+ : mbGotEvent(false)
+ {
+ }
+
+ // XEventListener
+ virtual void SAL_CALL disposing(const lang::EventObject&) override {}
+
+ // XAccessibleEventListener
+ virtual void SAL_CALL notifyEvent(const accessibility::AccessibleEventObject& aEvent) override
+ {
+ std::cout << "Listener got event: " << AccessibilityTools::debugString(aEvent) << std::endl;
+ uno::Reference<accessibility::XAccessible> xOld(aEvent.OldValue, uno::UNO_QUERY);
+ if (xOld.is())
+ std::cout << "Old: " << AccessibilityTools::debugString(xOld) << std::endl;
+
+ uno::Reference<accessibility::XAccessible> xNew(aEvent.NewValue, uno::UNO_QUERY);
+ if (xNew.is())
+ std::cout << "New: " << AccessibilityTools::debugString(xNew) << std::endl;
+
+ mbGotEvent = true;
+ }
+};
+}
+
+XAccessibleEventBroadcasterTester::XAccessibleEventBroadcasterTester(
+ const uno::Reference<accessibility::XAccessibleEventBroadcaster>& xBroadcaster,
+ const uno::Reference<awt::XWindow>& xWindow)
+ : mxBroadcaster(xBroadcaster)
+ , mxWindow(xWindow)
+{
+}
+
+bool XAccessibleEventBroadcasterTester::isTransient(
+ const uno::Reference<accessibility::XAccessibleEventBroadcaster> xBroadcaster)
+{
+ uno::Reference<accessibility::XAccessibleContext> xCtx(xBroadcaster, uno::UNO_QUERY_THROW);
+ return isTransient(xCtx);
+}
+
+bool XAccessibleEventBroadcasterTester::isTransient(
+ const uno::Reference<accessibility::XAccessibleContext> xCtx)
+{
+ return ((xCtx->getAccessibleStateSet() & accessibility::AccessibleStateType::TRANSIENT)
+ && (xCtx->getAccessibleParent()->getAccessibleContext()->getAccessibleStateSet()
+ & accessibility::AccessibleStateType::MANAGES_DESCENDANTS));
+}
+
+/**
+ * @brief Generates an event on @c mxBroadcaster.
+ *
+ * This method indirectly alters the state of @c mxBroadcaster so that an
+ * accessible event will be fired for it. It can be called as many times as
+ * needed and triggers an event each time.
+ */
+void XAccessibleEventBroadcasterTester::fireEvent()
+{
+ awt::Rectangle newPosSize = mxWindow->getPosSize();
+ newPosSize.Width = newPosSize.Width - 20;
+ newPosSize.Height = newPosSize.Height - 20;
+ newPosSize.X = newPosSize.X + 20;
+ newPosSize.Y = newPosSize.Y + 20;
+ mxWindow->setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width, newPosSize.Height,
+ awt::PosSize::POSSIZE);
+}
+
+/**
+ * @brief Adds a listener and fires events by mean of object relation.
+ *
+ * Asserts that the listener was properly called.
+ */
+void XAccessibleEventBroadcasterTester::testAddEventListener()
+{
+ rtl::Reference<EvListener> xListener(new EvListener);
+ mxBroadcaster->addAccessibleEventListener(xListener);
+ bool transient = isTransient(mxBroadcaster);
+
+ std::cout << "firing event" << std::endl;
+ fireEvent();
+
+ AccessibilityTools::Await([&xListener]() { return xListener->mbGotEvent; });
+
+ if (!transient)
+ CPPUNIT_ASSERT_MESSAGE("listener wasn't called", xListener->mbGotEvent);
+ else
+ CPPUNIT_ASSERT_MESSAGE("Object is Transient, listener isn't expected to be called",
+ !xListener->mbGotEvent);
+
+ mxBroadcaster->removeAccessibleEventListener(xListener);
+}
+
+/**
+ * @brief Similar to @c testAddEventListener() but also removes the listener
+ *
+ * Adds an event listener just like @c testAddEventListener(), and then removes it and verifies an
+ * event doesn't trigger the supposedly removed listener.
+ *
+ * @see testAddEventListener()
+ */
+void XAccessibleEventBroadcasterTester::testRemoveEventListener()
+{
+ /* there is nothing we can really test for transient objects */
+ if (isTransient(mxBroadcaster))
+ {
+ std::cerr << "could not test removing listener on transient object " << mxBroadcaster
+ << std::endl;
+ return;
+ }
+
+ rtl::Reference<EvListener> xListener(new EvListener);
+ mxBroadcaster->addAccessibleEventListener(xListener);
+
+ std::cout << "firing event (with listener)" << std::endl;
+ fireEvent();
+
+ AccessibilityTools::Await([&xListener]() { return xListener->mbGotEvent; });
+
+ CPPUNIT_ASSERT_MESSAGE("listener wasn't called", xListener->mbGotEvent);
+
+ /* reset listener, remove it and try again */
+ xListener->mbGotEvent = false;
+
+ std::cout << "removing listener" << std::endl;
+ mxBroadcaster->removeAccessibleEventListener(xListener);
+
+ std::cout << "firing event (without listener)" << std::endl;
+ fireEvent();
+
+ AccessibilityTools::Wait(500);
+
+ CPPUNIT_ASSERT_MESSAGE("removed listener was called", !xListener->mbGotEvent);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.hxx b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.hxx
new file mode 100644
index 0000000000..0fc7c23bd3
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleEventBroadcasterTester.hxx
@@ -0,0 +1,54 @@
+/* -*- 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 <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+
+class XAccessibleEventBroadcasterTester
+{
+private:
+ const css::uno::Reference<css::accessibility::XAccessibleEventBroadcaster> mxBroadcaster;
+ const css::uno::Reference<css::awt::XWindow> mxWindow;
+
+ static bool isTransient(
+ const css::uno::Reference<css::accessibility::XAccessibleEventBroadcaster> xBroadcaster);
+ static bool isTransient(const css::uno::Reference<css::accessibility::XAccessibleContext> xCtx);
+
+ void fireEvent();
+
+public:
+ XAccessibleEventBroadcasterTester(
+ const css::uno::Reference<css::accessibility::XAccessibleEventBroadcaster>& xBroadcaster,
+ const css::uno::Reference<css::awt::XWindow>& xWindow);
+
+ void testAddEventListener();
+ void testRemoveEventListener();
+
+ void testAll()
+ {
+ testAddEventListener();
+ testRemoveEventListener();
+ }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.cxx b/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.cxx
new file mode 100644
index 0000000000..a7137c4ba5
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.cxx
@@ -0,0 +1,53 @@
+/* -*- 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 "XAccessibleExtendedComponentTester.hxx"
+
+#include <iostream>
+
+#include <com/sun/star/accessibility/XAccessibleExtendedComponent.hpp>
+
+/**
+ * @brief Just calls the method.
+ */
+void XAccessibleExtendedComponentTester::testGetFont()
+{
+ auto font = mxExtendedComponent->getFont();
+ std::cout << "font: " << font << std::endl;
+}
+
+/**
+ * @brief Just calls the method.
+ */
+void XAccessibleExtendedComponentTester::testGetTitledBorderText()
+{
+ auto titleBorderText = mxExtendedComponent->getTitledBorderText();
+ std::cout << "getTitledBorderText(): '" << titleBorderText << "'" << std::endl;
+}
+
+/**
+ * @brief Just calls the method.
+ */
+void XAccessibleExtendedComponentTester::testGetToolTipText()
+{
+ auto toolTipText = mxExtendedComponent->getToolTipText();
+ std::cout << "getToolTipText(): '" << toolTipText << "'" << std::endl;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.hxx b/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.hxx
new file mode 100644
index 0000000000..1297052822
--- /dev/null
+++ b/toolkit/qa/cppunit/a11y/XAccessibleExtendedComponentTester.hxx
@@ -0,0 +1,50 @@
+/* -*- 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 <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/accessibility/XAccessibleExtendedComponent.hpp>
+
+class XAccessibleExtendedComponentTester
+{
+protected:
+ const css::uno::Reference<css::accessibility::XAccessibleExtendedComponent> mxExtendedComponent;
+
+public:
+ XAccessibleExtendedComponentTester(
+ const css::uno::Reference<css::accessibility::XAccessibleExtendedComponent>&
+ extendedComponent)
+ : mxExtendedComponent(extendedComponent)
+ {
+ }
+
+ void testGetFont();
+ void testGetTitledBorderText();
+ void testGetToolTipText();
+
+ void testAll()
+ {
+ testGetFont();
+ testGetTitledBorderText();
+ testGetToolTipText();
+ }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */