tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / toolkit / qa / cppunit / a11y / XAccessibleContextTester.cxx
blob9d7fdb992eae54b25104f7114c8679f560230acc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XAccessibleContextTester.hxx"
22 #include <cppunit/TestAssert.h>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
27 #include <test/a11y/AccessibilityTools.hxx>
29 /**
30 * @brief Tries to get every child and checks its parent.
32 * Checks that the parent of every child and the tested component are the same object.
34 void XAccessibleContextTester::testGetAccessibleChild()
36 sal_Int64 count = mxContext->getAccessibleChildCount();
37 for (sal_Int64 i = 0; i < count && i < AccessibilityTools::MAX_CHILDREN; i++)
39 auto child = mxContext->getAccessibleChild(i);
40 auto childCtx = child->getAccessibleContext();
42 std::cout << " Child " << i << ": " << AccessibilityTools::debugString(childCtx)
43 << std::endl;
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("child's parent context is not parent's context!",
46 childCtx->getAccessibleParent()->getAccessibleContext(),
47 mxContext);
51 /**
52 * @brief Calls the method.
54 * Checks that the child count is non-negative.
56 void XAccessibleContextTester::testGetAccessibleChildCount()
58 sal_Int64 childCount = mxContext->getAccessibleChildCount();
59 std::cout << childCount << " children found." << std::endl;
60 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int64>(0), childCount);
63 /**
64 * @brief Get the accessible description of the component.
66 void XAccessibleContextTester::testGetAccessibleDescription()
68 auto desc = mxContext->getAccessibleDescription();
69 std::cout << "The description is '" << desc << "'" << std::endl;
72 /**
73 * @brief Checks the index in parent
75 * Checks that the parent's child and the tested component are the same objects.
77 * Retrieves the index of tested component in its parent.
78 * Then gets the parent's child by this index and compares
79 * it with tested component.
81 void XAccessibleContextTester::testGetAccessibleIndexInParent()
83 sal_Int64 idx = mxContext->getAccessibleIndexInParent();
84 std::cout << "The index in parent is " << idx << std::endl;
86 auto parent = mxContext->getAccessibleParent();
87 CPPUNIT_ASSERT(parent.is());
88 auto parentCtx = parent->getAccessibleContext();
89 CPPUNIT_ASSERT_EQUAL_MESSAGE("Parent's child context at our index is not us!", mxContext,
90 parentCtx->getAccessibleChild(idx)->getAccessibleContext());
93 /**
94 * @brief Get the accessible name of the component.
96 void XAccessibleContextTester::testGetAccessibleName()
98 auto name = mxContext->getAccessibleName();
99 std::cout << "The name is '" << name << "'" << std::endl;
103 * @brief Just gets the parent.
105 * Checks that the parent is not null.
107 void XAccessibleContextTester::testGetAccessibleParent()
109 // assume that the component is not ROOT
110 auto parent = mxContext->getAccessibleParent();
111 std::cout << "The parent is " << AccessibilityTools::debugString(parent) << std::endl;
112 CPPUNIT_ASSERT_MESSAGE("parent is not set", parent.is());
116 * @brief Just gets the relation set.
118 * Checks that the relation set is not null.
120 void XAccessibleContextTester::testGetAccessibleRelationSet()
122 auto relSet = mxContext->getAccessibleRelationSet();
123 CPPUNIT_ASSERT_MESSAGE("relation set is not set", relSet.is());
127 * @brief Get the accessible role of component.
129 * Checks that the role is a non-negative number.
131 void XAccessibleContextTester::testGetAccessibleRole()
133 sal_Int32 role = mxContext->getAccessibleRole();
134 std::cout << "The role is " << role << " (" << AccessibilityTools::getRoleName(role) << ")"
135 << std::endl;
136 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), role);
140 * @brief Just gets the state set.
142 * Checks that the state set is not null.
144 void XAccessibleContextTester::testGetAccessibleStateSet()
146 sal_Int64 stateSet = mxContext->getAccessibleStateSet();
147 std::cout << "The state set is: " << AccessibilityTools::debugAccessibleStateSet(stateSet)
148 << std::endl;
152 * @brief Gets the locale.
154 * Checks that @c Country and @c Language fields of locale structure are not empty.
156 void XAccessibleContextTester::testGetLocale()
158 auto loc = mxContext->getLocale();
159 std::cout << "The locale is " << loc.Language << "," << loc.Country << std::endl;
160 CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), loc.Language.getLength());
161 CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), loc.Country.getLength());
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */