2011-04-27 10:05:43 +00:00
/****************************************************************************
* *
2016-01-15 12:36:27 +00:00
* * Copyright ( C ) 2016 The Qt Company Ltd .
* * Contact : https : //www.qt.io/licensing/
2011-04-27 10:05:43 +00:00
* *
* * This file is part of the test suite of the Qt Toolkit .
* *
2016-01-15 12:36:27 +00:00
* * $ QT_BEGIN_LICENSE : GPL - EXCEPT $
2012-09-19 12:28:29 +00:00
* * Commercial License Usage
* * Licensees holding valid commercial Qt licenses may use this file in
* * accordance with the commercial license agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
2015-01-28 08:44:43 +00:00
* * a written agreement between you and The Qt Company . For licensing terms
2016-01-15 12:36:27 +00:00
* * and conditions see https : //www.qt.io/terms-conditions. For further
* * information use the contact form at https : //www.qt.io/contact-us.
2012-09-19 12:28:29 +00:00
* *
2016-01-15 12:36:27 +00:00
* * GNU General Public License Usage
* * Alternatively , this file may be used under the terms of the GNU
* * General Public License version 3 as published by the Free Software
* * Foundation with exceptions as appearing in the file LICENSE . GPL3 - EXCEPT
* * included in the packaging of this file . Please review the following
* * information to ensure the GNU General Public License requirements will
* * be met : https : //www.gnu.org/licenses/gpl-3.0.html.
2011-04-27 10:05:43 +00:00
* *
* * $ QT_END_LICENSE $
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-03-27 05:09:22 +00:00
# include <QtCore/qglobal.h>
# ifdef Q_OS_WIN
# include <QtCore / qt_windows.h>
2014-01-06 20:41:17 +00:00
# ifndef Q_OS_WINRT
2012-03-27 05:09:22 +00:00
# include <oleacc.h>
2014-01-06 20:41:17 +00:00
# endif
2012-03-27 05:09:22 +00:00
# include <servprov.h>
# include <winuser.h>
2012-03-07 10:59:30 +00:00
# ifdef QT_SUPPORTS_IACCESSIBLE2
2014-08-07 08:51:30 +00:00
# include <ia2_api_all.h>
2012-03-27 05:09:22 +00:00
# endif
# endif
2011-04-27 10:05:43 +00:00
# include <QtTest/QtTest>
# include <QtGui>
2011-09-16 12:07:05 +00:00
# include <QtWidgets>
2011-04-27 10:05:43 +00:00
# include <math.h>
2012-03-07 10:59:30 +00:00
# include <qpa/qplatformnativeinterface.h>
2013-03-25 17:07:17 +00:00
# include <qpa/qplatformintegration.h>
# include <qpa/qplatformaccessibility.h>
# include <QtGui/private/qguiapplication_p.h>
2011-04-27 10:05:43 +00:00
2011-08-31 13:21:48 +00:00
# if defined(Q_OS_WIN) && defined(interface)
# undef interface
# endif
2011-04-27 10:05:43 +00:00
# include "QtTest/qtestaccessible.h"
2014-02-18 08:33:36 +00:00
# include <algorithm>
2014-07-03 09:19:21 +00:00
# include "accessiblewidgets.h"
2012-12-18 14:22:48 +00:00
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless ( QWidget * w )
{
Qt : : WindowFlags flags = w - > windowFlags ( ) ;
flags | = Qt : : FramelessWindowHint ;
flags & = ~ ( Qt : : WindowTitleHint | Qt : : WindowSystemMenuHint | Qt : : WindowMinMaxButtonsHint | Qt : : WindowCloseButtonHint ) ;
w - > setWindowFlags ( flags ) ;
}
2011-04-27 10:05:43 +00:00
static inline bool verifyChild ( QWidget * child , QAccessibleInterface * interface ,
int index , const QRect & domain )
{
if ( ! child ) {
qWarning ( " tst_QAccessibility::verifyChild: null pointer to child. " ) ;
return false ;
}
if ( ! interface ) {
qWarning ( " tst_QAccessibility::verifyChild: null pointer to interface. " ) ;
return false ;
}
2011-09-28 13:36:52 +00:00
// Verify that we get a valid QAccessibleInterface for the child.
2013-01-03 16:18:40 +00:00
QAccessibleInterface * childInterface ( QAccessible : : queryAccessibleInterface ( child ) ) ;
2011-09-28 13:36:52 +00:00
if ( ! childInterface ) {
qWarning ( " tst_QAccessibility::verifyChild: Failed to retrieve interface for child. " ) ;
return false ;
}
// QAccessibleInterface::indexOfChild():
// Verify that indexOfChild() returns an index equal to the index passed in
2013-01-03 16:18:40 +00:00
int indexFromIndexOfChild = interface - > indexOfChild ( childInterface ) ;
2011-09-28 13:36:52 +00:00
if ( indexFromIndexOfChild ! = index ) {
qWarning ( " tst_QAccessibility::verifyChild (indexOfChild()): " ) ;
qWarning ( ) < < " Expected: " < < index ;
qWarning ( ) < < " Actual: " < < indexFromIndexOfChild ;
return false ;
}
// Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child).
2013-01-03 16:18:40 +00:00
QAccessibleInterface * navigatedChildInterface ( interface - > child ( index ) ) ;
2012-10-19 17:11:40 +00:00
if ( ! navigatedChildInterface )
2011-09-28 13:36:52 +00:00
return false ;
const QRect rectFromInterface = navigatedChildInterface - > rect ( ) ;
2011-04-27 10:05:43 +00:00
// QAccessibleInterface::childAt():
// Calculate global child position and check that the interface
// returns the correct index for that position.
QPoint globalChildPos = child - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * childAtInterface ( interface - > childAt ( globalChildPos . x ( ) , globalChildPos . y ( ) ) ) ;
2011-11-22 17:08:05 +00:00
if ( ! childAtInterface ) {
2011-04-27 10:05:43 +00:00
qWarning ( " tst_QAccessibility::verifyChild (childAt()): " ) ;
2011-11-22 17:08:05 +00:00
qWarning ( ) < < " Expected: " < < childInterface ;
qWarning ( ) < < " Actual: no child " ;
return false ;
}
if ( childAtInterface - > object ( ) ! = childInterface - > object ( ) ) {
qWarning ( " tst_QAccessibility::verifyChild (childAt()): " ) ;
qWarning ( ) < < " Expected: " < < childInterface ;
qWarning ( ) < < " Actual: " < < childAtInterface ;
2011-04-27 10:05:43 +00:00
return false ;
}
// QAccessibleInterface::rect():
// Calculate global child geometry and check that the interface
// returns a QRect which is equal to the calculated QRect.
const QRect expectedGlobalRect = QRect ( globalChildPos , child - > size ( ) ) ;
if ( expectedGlobalRect ! = rectFromInterface ) {
qWarning ( " tst_QAccessibility::verifyChild (rect()): " ) ;
qWarning ( ) < < " Expected: " < < expectedGlobalRect ;
qWarning ( ) < < " Actual: " < < rectFromInterface ;
return false ;
}
// Verify that the child is within its domain.
if ( ! domain . contains ( rectFromInterface ) ) {
qWarning ( " tst_QAccessibility::verifyChild: Child is not within its domain. " ) ;
return false ;
}
return true ;
}
# define EXPECT(cond) \
do { \
if ( ! errorAt & & ! ( cond ) ) { \
errorAt = __LINE__ ; \
2012-12-20 15:06:48 +00:00
qWarning ( " level: %d, role: %d (%s) " , treelevel , iface - > role ( ) , # cond ) ; \
break ; \
2011-04-27 10:05:43 +00:00
} \
} while ( 0 )
static int verifyHierarchy ( QAccessibleInterface * iface )
{
int errorAt = 0 ;
static int treelevel = 0 ; // for error diagnostics
2013-01-03 16:18:40 +00:00
QAccessibleInterface * if2 = 0 ;
2011-04-27 10:05:43 +00:00
+ + treelevel ;
for ( int i = 0 ; i < iface - > childCount ( ) & & ! errorAt ; + + i ) {
2013-01-03 16:18:40 +00:00
if2 = iface - > child ( i ) ;
2011-10-04 12:20:05 +00:00
EXPECT ( if2 ! = 0 ) ;
2013-01-03 16:18:40 +00:00
EXPECT ( iface - > indexOfChild ( if2 ) = = i ) ;
2012-10-19 17:11:40 +00:00
// navigate Ancestor
2013-01-03 16:18:40 +00:00
QAccessibleInterface * parent = if2 - > parent ( ) ;
2011-10-04 12:20:05 +00:00
EXPECT ( iface - > object ( ) = = parent - > object ( ) ) ;
2013-01-03 16:18:40 +00:00
EXPECT ( iface = = parent ) ;
2012-10-19 17:11:40 +00:00
// verify children
2011-10-04 12:20:05 +00:00
if ( ! errorAt )
2013-01-03 16:18:40 +00:00
errorAt = verifyHierarchy ( if2 ) ;
2011-04-27 10:05:43 +00:00
}
- - treelevel ;
return errorAt ;
}
2011-10-22 20:38:14 +00:00
QRect childRect ( QAccessibleInterface * iface , int index = 0 )
{
2013-01-03 16:18:40 +00:00
return iface - > child ( index ) - > rect ( ) ;
2011-10-22 20:38:14 +00:00
}
2011-04-27 10:05:43 +00:00
class tst_QAccessibility : public QObject
{
Q_OBJECT
public :
tst_QAccessibility ( ) ;
public slots :
void initTestCase ( ) ;
void cleanupTestCase ( ) ;
void init ( ) ;
void cleanup ( ) ;
private slots :
void eventTest ( ) ;
void customWidget ( ) ;
void deletedWidget ( ) ;
2013-03-18 15:02:06 +00:00
void subclassedWidget ( ) ;
2011-04-27 10:05:43 +00:00
2012-01-05 12:57:33 +00:00
void statesStructTest ( ) ;
2011-04-27 10:05:43 +00:00
void navigateHierarchy ( ) ;
2011-09-21 11:38:49 +00:00
void sliderTest ( ) ;
2014-06-23 15:57:34 +00:00
void textAttributes_data ( ) ;
2011-08-16 13:19:09 +00:00
void textAttributes ( ) ;
2011-04-27 10:05:43 +00:00
void hideShowTest ( ) ;
2011-10-06 12:54:49 +00:00
void actionTest ( ) ;
2011-04-27 10:05:43 +00:00
2011-02-17 14:37:43 +00:00
void applicationTest ( ) ;
void mainWindowTest ( ) ;
2014-06-19 16:49:59 +00:00
void subWindowTest ( ) ;
2011-04-27 10:05:43 +00:00
void buttonTest ( ) ;
void scrollBarTest ( ) ;
void tabTest ( ) ;
2011-03-18 16:41:01 +00:00
void tabWidgetTest ( ) ;
2011-04-27 10:05:43 +00:00
void menuTest ( ) ;
void spinBoxTest ( ) ;
void doubleSpinBoxTest ( ) ;
void textEditTest ( ) ;
void textBrowserTest ( ) ;
void mdiAreaTest ( ) ;
void mdiSubWindowTest ( ) ;
void lineEditTest ( ) ;
2014-06-25 13:27:56 +00:00
void lineEditTextFunctions_data ( ) ;
void lineEditTextFunctions ( ) ;
2014-07-03 09:19:21 +00:00
void textInterfaceTest_data ( ) ;
void textInterfaceTest ( ) ;
2012-02-13 13:05:51 +00:00
void groupBoxTest ( ) ;
2011-04-27 10:05:43 +00:00
void dialogButtonBoxTest ( ) ;
void dialTest ( ) ;
void rubberBandTest ( ) ;
void abstractScrollAreaTest ( ) ;
void scrollAreaTest ( ) ;
2011-10-06 03:48:18 +00:00
2011-12-01 20:21:52 +00:00
void listTest ( ) ;
void treeTest ( ) ;
void tableTest ( ) ;
2011-10-06 03:48:18 +00:00
2011-04-27 10:05:43 +00:00
void calendarWidgetTest ( ) ;
void dockWidgetTest ( ) ;
void comboBoxTest ( ) ;
void accessibleName ( ) ;
void labelTest ( ) ;
void accelerators ( ) ;
2012-03-27 05:09:22 +00:00
void bridgeTest ( ) ;
2011-10-11 14:20:47 +00:00
protected slots :
void onClicked ( ) ;
private :
int click_count ;
2011-04-27 10:05:43 +00:00
} ;
QAccessible : : State state ( QWidget * const widget )
{
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface ( QAccessible : : queryAccessibleInterface ( widget ) ) ;
2012-10-19 17:11:40 +00:00
if ( ! iface ) {
2011-04-19 03:55:05 +00:00
qWarning ( ) < < " Cannot get QAccessibleInterface for widget " ;
2012-10-19 17:11:40 +00:00
return QAccessible : : State ( ) ;
}
return iface - > state ( ) ;
2011-04-27 10:05:43 +00:00
}
tst_QAccessibility : : tst_QAccessibility ( )
{
2011-10-11 14:20:47 +00:00
click_count = 0 ;
2011-04-27 10:05:43 +00:00
}
2011-10-11 14:20:47 +00:00
void tst_QAccessibility : : onClicked ( )
{
click_count + + ;
}
2011-04-27 10:05:43 +00:00
void tst_QAccessibility : : initTestCase ( )
{
QTestAccessibility : : initialize ( ) ;
2013-03-25 17:07:17 +00:00
QPlatformIntegration * pfIntegration = QGuiApplicationPrivate : : platformIntegration ( ) ;
2014-05-13 16:08:42 +00:00
if ( ! pfIntegration - > accessibility ( ) )
QSKIP ( " This platform does not support accessibility " ) ;
2013-03-25 17:07:17 +00:00
pfIntegration - > accessibility ( ) - > setActive ( true ) ;
2011-04-27 10:05:43 +00:00
}
void tst_QAccessibility : : cleanupTestCase ( )
{
QTestAccessibility : : cleanup ( ) ;
}
void tst_QAccessibility : : init ( )
{
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : cleanup ( )
{
const EventList list = QTestAccessibility : : events ( ) ;
if ( ! list . isEmpty ( ) ) {
qWarning ( " %d accessibility event(s) were not handled in testfunction '%s': " , list . count ( ) ,
2012-05-02 14:32:26 +00:00
QString ( QTest : : currentTestFunction ( ) ) . toLatin1 ( ) . constData ( ) ) ;
2011-04-27 10:05:43 +00:00
for ( int i = 0 ; i < list . count ( ) ; + + i )
2012-03-07 18:09:33 +00:00
qWarning ( " %d: Object: %p Event: '%s' Child: %d " , i + 1 , list . at ( i ) - > object ( ) ,
2012-03-13 13:11:51 +00:00
qAccessibleEventString ( list . at ( i ) - > type ( ) ) , list . at ( i ) - > child ( ) ) ;
2011-04-27 10:05:43 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : eventTest ( )
{
QPushButton * button = new QPushButton ( 0 ) ;
2013-01-03 16:18:40 +00:00
QAccessible : : queryAccessibleInterface ( button ) ;
2011-04-27 10:05:43 +00:00
button - > setObjectName ( QString ( " Olaf " ) ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( button ) ;
2011-04-27 10:05:43 +00:00
button - > show ( ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent showEvent ( button , QAccessible : : ObjectShow ) ;
2012-07-13 07:45:37 +00:00
// some platforms might send other events first, (such as state change event active=1)
QVERIFY ( QTestAccessibility : : containsEvent ( & showEvent ) ) ;
2011-04-27 10:05:43 +00:00
button - > setFocus ( Qt : : MouseFocusReason ) ;
QTestAccessibility : : clearEvents ( ) ;
QTest : : mouseClick ( button , Qt : : LeftButton , 0 ) ;
2011-02-17 18:56:30 +00:00
button - > setAccessibleName ( " Olaf the second " ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent nameEvent ( button , QAccessible : : NameChanged ) ;
2012-03-12 14:36:31 +00:00
QVERIFY_EVENT ( & nameEvent ) ;
2011-02-17 18:56:30 +00:00
button - > setAccessibleDescription ( " This is a button labeled Olaf " ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent descEvent ( button , QAccessible : : DescriptionChanged ) ;
2012-03-12 14:36:31 +00:00
QVERIFY_EVENT ( & descEvent ) ;
2011-02-17 18:56:30 +00:00
2011-04-27 10:05:43 +00:00
button - > hide ( ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent hideEvent ( button , QAccessible : : ObjectHide ) ;
2012-07-13 07:45:37 +00:00
// some platforms might send other events first, (such as state change event active=1)
QVERIFY ( QTestAccessibility : : containsEvent ( & hideEvent ) ) ;
2011-04-27 10:05:43 +00:00
delete button ;
2013-03-18 19:22:52 +00:00
// Make sure that invalid events don't bring down the system
// these events can be in user code.
QWidget * widget = new QWidget ( ) ;
QAccessibleEvent ev1 ( widget , QAccessible : : Focus ) ;
QAccessible : : updateAccessibility ( & ev1 ) ;
QAccessibleEvent ev2 ( widget , QAccessible : : Focus ) ;
ev2 . setChild ( 7 ) ;
QAccessible : : updateAccessibility ( & ev2 ) ;
delete widget ;
QObject * object = new QObject ( ) ;
2013-03-23 10:43:13 +00:00
QAccessibleEvent ev3 ( object , QAccessible : : Focus ) ;
2013-03-18 19:22:52 +00:00
QAccessible : : updateAccessibility ( & ev3 ) ;
delete object ;
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
void tst_QAccessibility : : customWidget ( )
{
2013-03-18 15:02:06 +00:00
{
2011-04-27 10:05:43 +00:00
QtTestAccessibleWidget * widget = new QtTestAccessibleWidget ( 0 , " Heinz " ) ;
2013-03-18 15:02:06 +00:00
widget - > show ( ) ;
QTest : : qWaitForWindowExposed ( widget ) ;
// By default we create QAccessibleWidget
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( widget ) ;
QVERIFY ( iface ! = 0 ) ;
QVERIFY ( iface - > isValid ( ) ) ;
QCOMPARE ( iface - > object ( ) , ( QObject * ) widget ) ;
QCOMPARE ( iface - > object ( ) - > objectName ( ) , QString ( " Heinz " ) ) ;
QCOMPARE ( iface - > rect ( ) . height ( ) , widget - > height ( ) ) ;
QCOMPARE ( iface - > text ( QAccessible : : Help ) , QString ( ) ) ;
QCOMPARE ( iface - > rect ( ) . height ( ) , widget - > height ( ) ) ;
delete widget ;
}
{
QAccessible : : installFactory ( QtTestAccessibleWidgetIface : : ifaceFactory ) ;
QtTestAccessibleWidget * widget = new QtTestAccessibleWidget ( 0 , " Heinz " ) ;
widget - > show ( ) ;
QTest : : qWaitForWindowExposed ( widget ) ;
2011-04-27 10:05:43 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( widget ) ;
QVERIFY ( iface ! = 0 ) ;
QVERIFY ( iface - > isValid ( ) ) ;
QCOMPARE ( iface - > object ( ) , ( QObject * ) widget ) ;
QCOMPARE ( iface - > object ( ) - > objectName ( ) , QString ( " Heinz " ) ) ;
2013-03-18 15:02:06 +00:00
QCOMPARE ( iface - > rect ( ) . height ( ) , widget - > height ( ) ) ;
// The help text is only set if our factory works
2011-10-22 20:38:14 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Help ) , QString ( " Help yourself " ) ) ;
2011-04-27 10:05:43 +00:00
delete widget ;
2013-03-18 15:02:06 +00:00
}
{
// A subclass of any class should still get the right QAccessibleInterface
QtTestAccessibleWidgetSubclass * subclassedWidget = new QtTestAccessibleWidgetSubclass ( 0 , " Hans " ) ;
QAccessibleInterface * subIface = QAccessible : : queryAccessibleInterface ( subclassedWidget ) ;
QVERIFY ( subIface ! = 0 ) ;
QVERIFY ( subIface - > isValid ( ) ) ;
QCOMPARE ( subIface - > object ( ) , ( QObject * ) subclassedWidget ) ;
QCOMPARE ( subIface - > text ( QAccessible : : Help ) , QString ( " Help yourself " ) ) ;
delete subclassedWidget ;
}
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
void tst_QAccessibility : : deletedWidget ( )
{
QtTestAccessibleWidget * widget = new QtTestAccessibleWidget ( 0 , " Ralf " ) ;
2013-03-18 15:02:06 +00:00
QAccessible : : installFactory ( QtTestAccessibleWidgetIface : : ifaceFactory ) ;
2011-04-27 10:05:43 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( widget ) ;
QVERIFY ( iface ! = 0 ) ;
QVERIFY ( iface - > isValid ( ) ) ;
QCOMPARE ( iface - > object ( ) , ( QObject * ) widget ) ;
delete widget ;
widget = 0 ;
2013-01-03 16:18:40 +00:00
// fixme: QVERIFY(!iface->isValid());
2011-04-27 10:05:43 +00:00
}
2013-03-18 15:02:06 +00:00
void tst_QAccessibility : : subclassedWidget ( )
{
KFooButton button ( " Ploink " , 0 ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & button ) ;
QVERIFY ( iface ) ;
QCOMPARE ( iface - > object ( ) , ( QObject * ) & button ) ;
QCOMPARE ( iface - > text ( QAccessible : : Name ) , button . text ( ) ) ;
QTestAccessibility : : clearEvents ( ) ;
}
2012-01-05 12:57:33 +00:00
void tst_QAccessibility : : statesStructTest ( )
{
QAccessible : : State s1 ;
2012-01-05 17:03:04 +00:00
QVERIFY ( s1 . disabled = = 0 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( s1 . focusable = = 0 ) ;
QVERIFY ( s1 . modal = = 0 ) ;
QAccessible : : State s2 ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( s2 , s1 ) ;
2012-01-05 12:57:33 +00:00
s2 . busy = true ;
QVERIFY ( ! ( s2 = = s1 ) ) ;
s1 . busy = true ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( s2 , s1 ) ;
2012-01-05 12:57:33 +00:00
s1 = QAccessible : : State ( ) ;
QVERIFY ( ! ( s2 = = s1 ) ) ;
s1 = s2 ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( s2 , s1 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( s1 . busy = = 1 ) ;
}
2011-09-21 11:38:49 +00:00
void tst_QAccessibility : : sliderTest ( )
2011-04-27 10:05:43 +00:00
{
{
QSlider * slider = new QSlider ( 0 ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( slider ) ;
2011-04-27 10:05:43 +00:00
slider - > setObjectName ( QString ( " Slidy " ) ) ;
slider - > show ( ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface ( QAccessible : : queryAccessibleInterface ( slider ) ) ;
2012-10-19 17:32:13 +00:00
QVERIFY ( iface ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( iface - > isValid ( ) ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( iface - > childCount ( ) , 0 ) ;
2011-09-26 08:18:30 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : Slider ) ;
2011-04-27 10:05:43 +00:00
2011-09-21 11:38:49 +00:00
QAccessibleValueInterface * valueIface = iface - > valueInterface ( ) ;
QVERIFY ( valueIface ! = 0 ) ;
QCOMPARE ( valueIface - > minimumValue ( ) . toInt ( ) , slider - > minimum ( ) ) ;
QCOMPARE ( valueIface - > maximumValue ( ) . toInt ( ) , slider - > maximum ( ) ) ;
2012-11-03 18:21:12 +00:00
QCOMPARE ( valueIface - > minimumStepSize ( ) . toInt ( ) , slider - > singleStep ( ) ) ;
2011-09-21 11:38:49 +00:00
slider - > setValue ( 50 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , slider - > value ( ) ) ;
slider - > setValue ( 0 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , slider - > value ( ) ) ;
slider - > setValue ( 100 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , slider - > value ( ) ) ;
valueIface - > setCurrentValue ( 77 ) ;
QCOMPARE ( 77 , slider - > value ( ) ) ;
2012-11-03 18:21:12 +00:00
slider - > setSingleStep ( 2 ) ;
QCOMPARE ( valueIface - > minimumStepSize ( ) . toInt ( ) , 2 ) ;
2011-09-21 11:38:49 +00:00
2011-04-27 10:05:43 +00:00
delete slider ;
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : navigateHierarchy ( )
{
{
QWidget * w = new QWidget ( 0 ) ;
w - > setObjectName ( QString ( " Hans " ) ) ;
w - > show ( ) ;
QWidget * w1 = new QWidget ( w ) ;
w1 - > setObjectName ( QString ( " 1 " ) ) ;
w1 - > show ( ) ;
QWidget * w2 = new QWidget ( w ) ;
w2 - > setObjectName ( QString ( " 2 " ) ) ;
w2 - > show ( ) ;
QWidget * w3 = new QWidget ( w ) ;
w3 - > setObjectName ( QString ( " 3 " ) ) ;
w3 - > show ( ) ;
QWidget * w31 = new QWidget ( w3 ) ;
w31 - > setObjectName ( QString ( " 31 " ) ) ;
w31 - > show ( ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * ifaceW ( QAccessible : : queryAccessibleInterface ( w ) ) ;
2012-10-19 17:32:13 +00:00
QVERIFY ( ifaceW ! = 0 ) ;
QVERIFY ( ifaceW - > isValid ( ) ) ;
2011-04-27 10:05:43 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * target = ifaceW - > child ( 14 ) ;
2015-07-24 13:51:48 +00:00
QVERIFY ( ! target ) ;
2013-01-03 16:18:40 +00:00
target = ifaceW - > child ( - 1 ) ;
2015-07-24 13:51:48 +00:00
QVERIFY ( ! target ) ;
2013-01-03 16:18:40 +00:00
target = ifaceW - > child ( 0 ) ;
QAccessibleInterface * interfaceW1 ( ifaceW - > child ( 0 ) ) ;
2011-10-04 12:20:05 +00:00
QVERIFY ( target ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( target - > isValid ( ) ) ;
QCOMPARE ( target - > object ( ) , ( QObject * ) w1 ) ;
2011-09-15 19:41:54 +00:00
QVERIFY ( interfaceW1 ! = 0 ) ;
QVERIFY ( interfaceW1 - > isValid ( ) ) ;
QCOMPARE ( interfaceW1 - > object ( ) , ( QObject * ) w1 ) ;
2011-04-27 10:05:43 +00:00
2013-01-03 16:18:40 +00:00
target = ifaceW - > child ( 2 ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( target ! = 0 ) ;
QVERIFY ( target - > isValid ( ) ) ;
QCOMPARE ( target - > object ( ) , ( QObject * ) w3 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child = target - > child ( 1 ) ;
2015-07-24 13:51:48 +00:00
QVERIFY ( ! child ) ;
2013-01-03 16:18:40 +00:00
child = target - > child ( 0 ) ;
2012-10-19 17:32:13 +00:00
QVERIFY ( child ! = 0 ) ;
QVERIFY ( child - > isValid ( ) ) ;
QCOMPARE ( child - > object ( ) , ( QObject * ) w31 ) ;
2012-01-05 08:51:20 +00:00
2013-01-03 16:18:40 +00:00
ifaceW = QAccessible : : queryAccessibleInterface ( w ) ;
QAccessibleInterface * acc3 ( ifaceW - > child ( 2 ) ) ;
target = acc3 - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( target - > object ( ) , ( QObject * ) w31 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * parent = target - > parent ( ) ;
2012-10-19 17:32:13 +00:00
QVERIFY ( parent ! = 0 ) ;
QVERIFY ( parent - > isValid ( ) ) ;
QCOMPARE ( parent - > object ( ) , ( QObject * ) w3 ) ;
2011-04-27 10:05:43 +00:00
delete w ;
}
QTestAccessibility : : clearEvents ( ) ;
}
# define QSETCOMPARE(thetypename, elements, otherelements) \
QCOMPARE ( ( QSet < thetypename > ( ) < < elements ) , ( QSet < thetypename > ( ) < < otherelements ) )
static QWidget * createWidgets ( )
{
QWidget * w = new QWidget ( ) ;
QHBoxLayout * box = new QHBoxLayout ( w ) ;
int i = 0 ;
box - > addWidget ( new QComboBox ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QPushButton ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
box - > addWidget ( new QHeaderView ( Qt : : Vertical , w ) ) ;
box - > addWidget ( new QTreeView ( w ) ) ;
box - > addWidget ( new QTreeWidget ( w ) ) ;
box - > addWidget ( new QListView ( w ) ) ;
box - > addWidget ( new QListWidget ( w ) ) ;
box - > addWidget ( new QTableView ( w ) ) ;
box - > addWidget ( new QTableWidget ( w ) ) ;
box - > addWidget ( new QCalendarWidget ( w ) ) ;
box - > addWidget ( new QDialogButtonBox ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QGroupBox ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
box - > addWidget ( new QFrame ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QLineEdit ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
box - > addWidget ( new QProgressBar ( w ) ) ;
box - > addWidget ( new QTabWidget ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QCheckBox ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
box - > addWidget ( new QRadioButton ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
box - > addWidget ( new QDial ( w ) ) ;
box - > addWidget ( new QScrollBar ( w ) ) ;
box - > addWidget ( new QSlider ( w ) ) ;
box - > addWidget ( new QDateTimeEdit ( w ) ) ;
box - > addWidget ( new QDoubleSpinBox ( w ) ) ;
box - > addWidget ( new QSpinBox ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QLabel ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
box - > addWidget ( new QLCDNumber ( w ) ) ;
box - > addWidget ( new QStackedWidget ( w ) ) ;
box - > addWidget ( new QToolBox ( w ) ) ;
2015-10-20 14:09:41 +00:00
box - > addWidget ( new QLabel ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
box - > addWidget ( new QTextEdit ( QLatin1String ( " widget text " ) + QString : : number ( i + + ) , w ) ) ;
2011-04-27 10:05:43 +00:00
/* Not in the list
* QAbstractItemView , QGraphicsView , QScrollArea ,
* QToolButton , QDockWidget , QFocusFrame , QMainWindow , QMenu , QMenuBar , QSizeGrip , QSplashScreen , QSplitterHandle ,
2012-03-21 03:21:30 +00:00
* QStatusBar , QSvgWidget , QTabBar , QToolBar , QSplitter
2011-04-27 10:05:43 +00:00
*/
return w ;
}
void tst_QAccessibility : : accessibleName ( )
{
QWidget * toplevel = createWidgets ( ) ;
toplevel - > show ( ) ;
2013-03-18 15:02:06 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( toplevel ) ) ;
2011-04-27 10:05:43 +00:00
QLayout * lout = toplevel - > layout ( ) ;
for ( int i = 0 ; i < lout - > count ( ) ; i + + ) {
QLayoutItem * item = lout - > itemAt ( i ) ;
QWidget * child = item - > widget ( ) ;
QString name = tr ( " Widget Name %1 " ) . arg ( i ) ;
child - > setAccessibleName ( name ) ;
QAccessibleInterface * acc = QAccessible : : queryAccessibleInterface ( child ) ;
2013-03-18 15:02:06 +00:00
QVERIFY ( acc ) ;
2011-09-23 08:28:51 +00:00
QCOMPARE ( acc - > text ( QAccessible : : Name ) , name ) ;
2011-04-27 10:05:43 +00:00
QString desc = tr ( " Widget Description %1 " ) . arg ( i ) ;
child - > setAccessibleDescription ( desc ) ;
2011-09-23 08:28:51 +00:00
QCOMPARE ( acc - > text ( QAccessible : : Description ) , desc ) ;
2011-04-27 10:05:43 +00:00
}
delete toplevel ;
QTestAccessibility : : clearEvents ( ) ;
}
2014-06-23 15:57:34 +00:00
// note: color should probably always be part of the attributes
void tst_QAccessibility : : textAttributes_data ( )
2011-08-16 13:19:09 +00:00
{
2015-01-01 18:23:16 +00:00
QTest : : addColumn < QFont > ( " defaultFont " ) ;
2014-06-23 15:57:34 +00:00
QTest : : addColumn < QString > ( " text " ) ;
QTest : : addColumn < int > ( " offset " ) ;
QTest : : addColumn < int > ( " startOffsetResult " ) ;
QTest : : addColumn < int > ( " endOffsetResult " ) ;
QTest : : addColumn < QStringList > ( " attributeResult " ) ;
2015-01-01 18:23:16 +00:00
static QFont defaultFont ;
defaultFont . setFamily ( " " ) ;
defaultFont . setPointSize ( 13 ) ;
static QFont defaultComplexFont = defaultFont ;
defaultComplexFont . setFamily ( " Arial " ) ;
defaultComplexFont . setPointSize ( 20 ) ;
defaultComplexFont . setWeight ( QFont : : Bold ) ;
defaultComplexFont . setStyle ( QFont : : StyleItalic ) ;
defaultComplexFont . setUnderline ( true ) ;
2015-02-15 21:50:15 +00:00
static QStringList defaults = QString ( " font-style:normal;font-weight:normal;text-align:left;text-position:baseline;font-size:13pt " ) . split ( ' ; ' ) ;
2014-06-23 15:57:34 +00:00
static QStringList bold = defaults ;
bold [ 1 ] = QString : : fromLatin1 ( " font-weight:bold " ) ;
static QStringList italic = defaults ;
italic [ 0 ] = QString : : fromLatin1 ( " font-style:italic " ) ;
static QStringList boldItalic = defaults ;
boldItalic [ 0 ] = QString : : fromLatin1 ( " font-style:italic " ) ;
boldItalic [ 1 ] = QString : : fromLatin1 ( " font-weight:bold " ) ;
static QStringList monospace = defaults ;
monospace . append ( QLatin1String ( " font-family: \" monospace \" " ) ) ;
static QStringList font8pt = defaults ;
2015-02-15 21:50:15 +00:00
font8pt [ 4 ] = ( QLatin1String ( " font-size:8pt " ) ) ;
2014-06-23 15:57:34 +00:00
static QStringList color = defaults ;
color < < QLatin1String ( " color:rgb(240,241,242) " ) < < QLatin1String ( " background-color:rgb(20,240,30) " ) ;
static QStringList rightAlign = defaults ;
rightAlign [ 2 ] = QStringLiteral ( " text-align:right " ) ;
2015-01-01 18:23:16 +00:00
static QStringList defaultFontDifferent = defaults ;
defaultFontDifferent [ 0 ] = QString : : fromLatin1 ( " font-style:italic " ) ;
defaultFontDifferent [ 1 ] = QString : : fromLatin1 ( " font-weight:bold " ) ;
2015-02-15 21:50:15 +00:00
defaultFontDifferent [ 4 ] = QString : : fromLatin1 ( " font-size:20pt " ) ;
defaultFontDifferent . append ( " text-underline-style:solid " ) ;
defaultFontDifferent . append ( " text-underline-type:single " ) ;
2015-01-01 18:23:16 +00:00
defaultFontDifferent . append ( " font-family: \" Arial \" " ) ;
static QStringList defaultFontDifferentBoldItalic = defaultFontDifferent ;
defaultFontDifferentBoldItalic [ 0 ] = QString : : fromLatin1 ( " font-style:italic " ) ;
defaultFontDifferentBoldItalic [ 1 ] = QString : : fromLatin1 ( " font-weight:bold " ) ;
static QStringList defaultFontDifferentMonospace = defaultFontDifferent ;
2015-02-15 21:50:15 +00:00
defaultFontDifferentMonospace [ 7 ] = ( QLatin1String ( " font-family: \" monospace \" " ) ) ;
2015-01-01 18:23:16 +00:00
static QStringList defaultFontDifferentFont8pt = defaultFontDifferent ;
2015-02-15 21:50:15 +00:00
defaultFontDifferentFont8pt [ 4 ] = ( QLatin1String ( " font-size:8pt " ) ) ;
2015-01-01 18:23:16 +00:00
static QStringList defaultFontDifferentColor = defaultFontDifferent ;
defaultFontDifferentColor < < QLatin1String ( " color:rgb(240,241,242) " ) < < QLatin1String ( " background-color:rgb(20,240,30) " ) ;
QTest : : newRow ( " defaults 1 " ) < < defaultFont < < " hello " < < 0 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " defaults 2 " ) < < defaultFont < < " hello " < < 1 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " defaults 3 " ) < < defaultFont < < " hello " < < 4 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " defaults 4 " ) < < defaultFont < < " hello " < < 5 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " offset -1 length " ) < < defaultFont < < " hello " < < - 1 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " offset -2 cursor pos " ) < < defaultFont < < " hello " < < - 2 < < 0 < < 5 < < defaults ;
QTest : : newRow ( " offset -3 " ) < < defaultFont < < " hello " < < - 3 < < - 1 < < - 1 < < QStringList ( ) ;
QTest : : newRow ( " invalid offset 2 " ) < < defaultFont < < " hello " < < 6 < < - 1 < < - 1 < < QStringList ( ) ;
QTest : : newRow ( " invalid offset 3 " ) < < defaultFont < < " " < < 1 < < - 1 < < - 1 < < QStringList ( ) ;
2014-06-23 15:57:34 +00:00
QString boldText = QLatin1String ( " <html><b>bold</b>text " ) ;
2015-01-01 18:23:16 +00:00
QTest : : newRow ( " bold 0 " ) < < defaultFont < < boldText < < 0 < < 0 < < 4 < < bold ;
QTest : : newRow ( " bold 2 " ) < < defaultFont < < boldText < < 2 < < 0 < < 4 < < bold ;
QTest : : newRow ( " bold 3 " ) < < defaultFont < < boldText < < 3 < < 0 < < 4 < < bold ;
QTest : : newRow ( " bold 4 " ) < < defaultFont < < boldText < < 4 < < 4 < < 8 < < defaults ;
QTest : : newRow ( " bold 6 " ) < < defaultFont < < boldText < < 6 < < 4 < < 8 < < defaults ;
2014-06-23 15:57:34 +00:00
QString longText = QLatin1String ( " <html> "
2011-08-16 13:19:09 +00:00
" Hello, <b>this</b> is an <i><b>example</b> text</i>. "
" <span style= \" font-family: monospace \" >Multiple fonts are used.</span> "
" Multiple <span style= \" font-size: 8pt \" >text sizes</span> are used. "
2014-06-23 15:57:34 +00:00
" Let's give some color to <span style= \" color:#f0f1f2; background-color:#14f01e \" >Qt</span>. " ) ;
2015-01-01 18:23:16 +00:00
QTest : : newRow ( " default 5 " ) < < defaultFont < < longText < < 6 < < 0 < < 7 < < defaults ;
QTest : : newRow ( " default 6 " ) < < defaultFont < < longText < < 7 < < 7 < < 11 < < bold ;
QTest : : newRow ( " bold 7 " ) < < defaultFont < < longText < < 10 < < 7 < < 11 < < bold ;
QTest : : newRow ( " bold 8 " ) < < defaultFont < < longText < < 10 < < 7 < < 11 < < bold ;
QTest : : newRow ( " bold italic " ) < < defaultFont < < longText < < 18 < < 18 < < 25 < < boldItalic ;
QTest : : newRow ( " monospace " ) < < defaultFont < < longText < < 34 < < 31 < < 55 < < monospace ;
QTest : : newRow ( " 8pt " ) < < defaultFont < < longText < < 65 < < 64 < < 74 < < font8pt ;
QTest : : newRow ( " color " ) < < defaultFont < < longText < < 110 < < 109 < < 111 < < color ;
// make sure unset font properties default to those of document's default font
QTest : : newRow ( " defaultFont default 5 " ) < < defaultComplexFont < < longText < < 6 < < 0 < < 7 < < defaultFontDifferent ;
QTest : : newRow ( " defaultFont default 6 " ) < < defaultComplexFont < < longText < < 7 < < 7 < < 11 < < defaultFontDifferent ;
QTest : : newRow ( " defaultFont bold 7 " ) < < defaultComplexFont < < longText < < 10 < < 7 < < 11 < < defaultFontDifferent ;
QTest : : newRow ( " defaultFont bold 8 " ) < < defaultComplexFont < < longText < < 10 < < 7 < < 11 < < defaultFontDifferent ;
QTest : : newRow ( " defaultFont bold italic " ) < < defaultComplexFont < < longText < < 18 < < 18 < < 25 < < defaultFontDifferentBoldItalic ;
QTest : : newRow ( " defaultFont monospace " ) < < defaultComplexFont < < longText < < 34 < < 31 < < 55 < < defaultFontDifferentMonospace ;
QTest : : newRow ( " defaultFont 8pt " ) < < defaultComplexFont < < longText < < 65 < < 64 < < 74 < < defaultFontDifferentFont8pt ;
QTest : : newRow ( " defaultFont color " ) < < defaultComplexFont < < longText < < 110 < < 109 < < 111 < < defaultFontDifferentColor ;
2014-06-23 15:57:34 +00:00
QString rightAligned = QLatin1String ( " <html><p align= \" right \" >right</p> " ) ;
2015-01-01 18:23:16 +00:00
QTest : : newRow ( " right aligned 1 " ) < < defaultFont < < rightAligned < < 0 < < 0 < < 5 < < rightAlign ;
QTest : : newRow ( " right aligned 2 " ) < < defaultFont < < rightAligned < < 1 < < 0 < < 5 < < rightAlign ;
QTest : : newRow ( " right aligned 3 " ) < < defaultFont < < rightAligned < < 5 < < 0 < < 5 < < rightAlign ;
2014-06-23 15:57:34 +00:00
// left \n right \n left, make sure bold and alignment borders coincide
QString leftRightLeftAligned = QLatin1String ( " <html><p><b>left</b></p><p align= \" right \" >right</p><p><b>left</b></p> " ) ;
2015-01-01 18:23:16 +00:00
QTest : : newRow ( " left right left aligned 1 " ) < < defaultFont < < leftRightLeftAligned < < 1 < < 0 < < 4 < < bold ;
QTest : : newRow ( " left right left aligned 3 " ) < < defaultFont < < leftRightLeftAligned < < 3 < < 0 < < 4 < < bold ;
QTest : : newRow ( " left right left aligned 4 " ) < < defaultFont < < leftRightLeftAligned < < 4 < < 4 < < 5 < < defaults ;
QTest : : newRow ( " left right left aligned 5 " ) < < defaultFont < < leftRightLeftAligned < < 5 < < 5 < < 10 < < rightAlign ;
QTest : : newRow ( " left right left aligned 8 " ) < < defaultFont < < leftRightLeftAligned < < 8 < < 5 < < 10 < < rightAlign ;
QTest : : newRow ( " left right left aligned 9 " ) < < defaultFont < < leftRightLeftAligned < < 9 < < 5 < < 10 < < rightAlign ;
QTest : : newRow ( " left right left aligned 10 " ) < < defaultFont < < leftRightLeftAligned < < 10 < < 10 < < 11 < < rightAlign ;
QTest : : newRow ( " left right left aligned 11 " ) < < defaultFont < < leftRightLeftAligned < < 11 < < 11 < < 15 < < bold ;
QTest : : newRow ( " left right left aligned 15 " ) < < defaultFont < < leftRightLeftAligned < < 15 < < 11 < < 15 < < bold ;
2015-02-24 16:19:40 +00:00
QTest : : newRow ( " empty with no fragments " ) < < defaultFont < < QString : : fromLatin1 ( " \n \n \n \n " ) < < 0 < < 0 < < 1 < < defaults ;
2014-06-23 15:57:34 +00:00
}
void tst_QAccessibility : : textAttributes ( )
{
{
2015-01-01 18:23:16 +00:00
QFETCH ( QFont , defaultFont ) ;
2014-06-23 15:57:34 +00:00
QFETCH ( QString , text ) ;
QFETCH ( int , offset ) ;
QFETCH ( int , startOffsetResult ) ;
QFETCH ( int , endOffsetResult ) ;
QFETCH ( QStringList , attributeResult ) ;
2011-08-16 13:19:09 +00:00
2014-06-23 15:57:34 +00:00
QTextEdit textEdit ;
2015-01-01 18:23:16 +00:00
textEdit . document ( ) - > setDefaultFont ( defaultFont ) ;
2011-08-16 13:19:09 +00:00
textEdit . setText ( text ) ;
2014-06-23 15:57:34 +00:00
if ( textEdit . document ( ) - > characterCount ( ) > 1 )
textEdit . textCursor ( ) . setPosition ( 1 ) ;
2011-08-16 13:19:09 +00:00
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & textEdit ) ;
QAccessibleTextInterface * textInterface = interface - > textInterface ( ) ;
QVERIFY ( textInterface ) ;
2014-06-23 15:57:34 +00:00
QCOMPARE ( textInterface - > characterCount ( ) , textEdit . toPlainText ( ) . length ( ) ) ;
int startOffset = - 1 ;
int endOffset = - 1 ;
QString attributes = textInterface - > attributes ( offset , & startOffset , & endOffset ) ;
QCOMPARE ( startOffset , startOffsetResult ) ;
QCOMPARE ( endOffset , endOffsetResult ) ;
QStringList attrList = attributes . split ( QChar ( ' ; ' ) , QString : : SkipEmptyParts ) ;
attributeResult . sort ( ) ;
attrList . sort ( ) ;
QCOMPARE ( attrList , attributeResult ) ;
}
QTestAccessibility : : clearEvents ( ) ;
2011-08-16 13:19:09 +00:00
}
2011-04-27 10:05:43 +00:00
void tst_QAccessibility : : hideShowTest ( )
{
QWidget * const window = new QWidget ( ) ;
2012-12-18 14:22:48 +00:00
window - > resize ( 200 , 200 ) ;
2011-04-27 10:05:43 +00:00
QWidget * const child = new QWidget ( window ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( state ( window ) . invisible ) ;
QVERIFY ( state ( child ) . invisible ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
// show() and veryfy that both window and child are not invisible and get ObjectShow events.
window - > show ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! state ( window ) . invisible ) ;
QVERIFY ( ! state ( child ) . invisible ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent show ( window , QAccessible : : ObjectShow ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & show ) ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent showChild ( child , QAccessible : : ObjectShow ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & showChild ) ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
// hide() and veryfy that both window and child are invisible and get ObjectHide events.
window - > hide ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( state ( window ) . invisible ) ;
QVERIFY ( state ( child ) . invisible ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent hide ( window , QAccessible : : ObjectHide ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & hide ) ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent hideChild ( child , QAccessible : : ObjectHide ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & hideChild ) ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
delete window ;
QTestAccessibility : : clearEvents ( ) ;
}
2011-10-06 12:54:49 +00:00
void tst_QAccessibility : : actionTest ( )
2011-04-27 10:05:43 +00:00
{
2011-10-11 14:20:47 +00:00
{
2011-11-01 13:36:20 +00:00
QCOMPARE ( QAccessibleActionInterface : : pressAction ( ) , QString ( QStringLiteral ( " Press " ) ) ) ;
2011-10-06 12:54:49 +00:00
2011-04-19 07:15:24 +00:00
QWidget * widget = new QWidget ;
2011-10-11 14:20:47 +00:00
widget - > setFocusPolicy ( Qt : : NoFocus ) ;
2011-04-19 07:15:24 +00:00
widget - > show ( ) ;
2011-04-27 10:05:43 +00:00
2011-10-11 14:20:47 +00:00
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( widget ) ;
QVERIFY ( interface ) ;
QVERIFY ( interface - > isValid ( ) ) ;
QAccessibleActionInterface * actions = interface - > actionInterface ( ) ;
QVERIFY ( actions ) ;
2011-04-27 10:05:43 +00:00
2011-10-11 14:20:47 +00:00
// no actions by default, except when focusable
QCOMPARE ( actions - > actionNames ( ) , QStringList ( ) ) ;
widget - > setFocusPolicy ( Qt : : StrongFocus ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( actions - > actionNames ( ) , QStringList ( QAccessibleActionInterface : : setFocusAction ( ) ) ) ;
2011-04-27 10:05:43 +00:00
2011-04-19 07:15:24 +00:00
delete widget ;
2011-10-11 14:20:47 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
2011-04-19 07:15:24 +00:00
2011-10-11 14:20:47 +00:00
{
QPushButton * button = new QPushButton ;
2012-12-18 14:22:48 +00:00
setFrameless ( button ) ;
2011-10-11 14:20:47 +00:00
button - > show ( ) ;
2012-07-24 12:29:01 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( button ) ) ;
2011-10-22 20:38:14 +00:00
button - > clearFocus ( ) ;
2011-10-11 14:20:47 +00:00
QCOMPARE ( button - > hasFocus ( ) , false ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( button ) ;
QAccessibleActionInterface * actions = interface - > actionInterface ( ) ;
QVERIFY ( actions ) ;
// Make sure the "primary action" press comes first!
2011-11-01 13:36:20 +00:00
QCOMPARE ( actions - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2011-10-11 14:20:47 +00:00
2011-11-01 13:36:20 +00:00
actions - > doAction ( QAccessibleActionInterface : : setFocusAction ( ) ) ;
2011-10-11 14:20:47 +00:00
QTest : : qWait ( 500 ) ;
QCOMPARE ( button - > hasFocus ( ) , true ) ;
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( onClicked ( ) ) ) ;
QCOMPARE ( click_count , 0 ) ;
2011-11-01 13:36:20 +00:00
actions - > doAction ( QAccessibleActionInterface : : pressAction ( ) ) ;
2011-10-11 14:20:47 +00:00
QTest : : qWait ( 500 ) ;
QCOMPARE ( click_count , 1 ) ;
delete button ;
}
2011-04-19 07:15:24 +00:00
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
2011-02-17 14:37:43 +00:00
void tst_QAccessibility : : applicationTest ( )
{
2013-01-18 16:59:52 +00:00
{
2011-02-17 14:37:43 +00:00
QLatin1String name = QLatin1String ( " My Name " ) ;
qApp - > setApplicationName ( name ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( qApp ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Name ) , name ) ;
2013-01-18 16:59:52 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Description ) , qApp - > applicationFilePath ( ) ) ;
QCOMPARE ( interface - > text ( QAccessible : : Value ) , QString ( ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : Application ) ;
2013-01-18 16:59:52 +00:00
QCOMPARE ( interface - > window ( ) , static_cast < QWindow * > ( 0 ) ) ;
QCOMPARE ( interface - > parent ( ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > focusChild ( ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > indexOfChild ( 0 ) , - 1 ) ;
QCOMPARE ( interface - > child ( 0 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > child ( - 1 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > child ( 1 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > childCount ( ) , 0 ) ;
QWidget widget ;
widget . show ( ) ;
qApp - > setActiveWindow ( & widget ) ;
QVERIFY ( QTest : : qWaitForWindowActive ( & widget ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * widgetIface = QAccessible : : queryAccessibleInterface ( & widget ) ;
2013-01-18 16:59:52 +00:00
QCOMPARE ( interface - > childCount ( ) , 1 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * focus = interface - > focusChild ( ) ;
2013-01-18 16:59:52 +00:00
QCOMPARE ( focus - > object ( ) , & widget ) ;
QCOMPARE ( interface - > indexOfChild ( 0 ) , - 1 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( interface - > indexOfChild ( widgetIface ) , 0 ) ;
QAccessibleInterface * child = interface - > child ( 0 ) ;
2013-01-18 16:59:52 +00:00
QCOMPARE ( child - > object ( ) , & widget ) ;
QCOMPARE ( interface - > child ( - 1 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > child ( 1 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
}
QTestAccessibility : : clearEvents ( ) ;
2011-02-17 14:37:43 +00:00
}
void tst_QAccessibility : : mainWindowTest ( )
{
2012-03-13 19:25:12 +00:00
{
2011-06-27 14:28:50 +00:00
QMainWindow * mw = new QMainWindow ;
mw - > resize ( 300 , 200 ) ;
mw - > show ( ) ; // triggers layout
2012-07-18 11:12:59 +00:00
qApp - > setActiveWindow ( mw ) ;
2011-02-17 14:37:43 +00:00
QLatin1String name = QLatin1String ( " I am the main window " ) ;
2011-06-27 14:28:50 +00:00
mw - > setWindowTitle ( name ) ;
2012-07-18 11:12:59 +00:00
QVERIFY ( QTest : : qWaitForWindowActive ( mw ) ) ;
2012-07-13 07:45:37 +00:00
// The order of events is not really that important.
2012-03-12 18:43:03 +00:00
QAccessibleEvent show ( mw , QAccessible : : ObjectShow ) ;
2012-07-13 07:45:37 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & show ) ) ;
QAccessible : : State activeState ;
activeState . active = true ;
QAccessibleStateChangeEvent active ( mw , activeState ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & active ) ) ;
2011-02-17 14:37:43 +00:00
2012-03-13 19:25:12 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( mw ) ;
QCOMPARE ( iface - > text ( QAccessible : : Name ) , name ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : Window ) ;
QVERIFY ( iface - > state ( ) . active ) ;
2011-06-27 14:28:50 +00:00
delete mw ;
2012-03-13 19:25:12 +00:00
}
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
2012-03-13 19:25:12 +00:00
{
QWindow window ;
window . setGeometry ( 80 , 80 , 40 , 40 ) ;
window . show ( ) ;
2015-07-24 13:51:48 +00:00
QTRY_COMPARE ( QGuiApplication : : focusWindow ( ) , & window ) ;
2012-03-13 19:25:12 +00:00
2014-09-03 11:47:42 +00:00
// We currently don't have an accessible interface for QWindow
// the active state is either in the QMainWindow or QQuickView
QAccessibleInterface * windowIface ( QAccessible : : queryAccessibleInterface ( & window ) ) ;
QVERIFY ( ! windowIface ) ;
2012-03-13 19:25:12 +00:00
QAccessible : : State activeState ;
activeState . active = true ;
2014-09-03 11:47:42 +00:00
// We should still not crash if we somehow end up sending state change events
// Note that we do not QVERIFY_EVENT, as that relies on the updateHandler being
// called, which does not happen/make sense when there's no interface for the event.
QAccessibleStateChangeEvent active ( & window , activeState ) ;
2012-03-13 19:25:12 +00:00
QAccessibleStateChangeEvent deactivate ( & window , activeState ) ;
}
2011-02-17 14:37:43 +00:00
}
2014-06-19 16:49:59 +00:00
// Dialogs and other sub-windows must appear in the
// accessibility hierarchy exactly once as top level objects
void tst_QAccessibility : : subWindowTest ( )
{
{
QWidget mainWidget ;
mainWidget . setGeometry ( 100 , 100 , 100 , 100 ) ;
mainWidget . show ( ) ;
QLabel label ( QStringLiteral ( " Window Contents " ) , & mainWidget ) ;
mainWidget . setLayout ( new QHBoxLayout ( ) ) ;
mainWidget . layout ( ) - > addWidget ( & label ) ;
QDialog d ( & mainWidget ) ;
d . show ( ) ;
QAccessibleInterface * app = QAccessible : : queryAccessibleInterface ( qApp ) ;
QVERIFY ( app ) ;
QCOMPARE ( app - > childCount ( ) , 2 ) ;
QAccessibleInterface * windowIface = QAccessible : : queryAccessibleInterface ( & mainWidget ) ;
QVERIFY ( windowIface ) ;
QCOMPARE ( windowIface - > childCount ( ) , 1 ) ;
QCOMPARE ( app - > child ( 0 ) , windowIface ) ;
QCOMPARE ( windowIface - > parent ( ) , app ) ;
QAccessibleInterface * dialogIface = QAccessible : : queryAccessibleInterface ( & d ) ;
QVERIFY ( dialogIface ) ;
QCOMPARE ( app - > child ( 1 ) , dialogIface ) ;
QCOMPARE ( dialogIface - > parent ( ) , app ) ;
QCOMPARE ( dialogIface - > parent ( ) , app ) ;
}
{
QMainWindow mainWindow ;
mainWindow . setGeometry ( 100 , 100 , 100 , 100 ) ;
mainWindow . show ( ) ;
QLabel label ( QStringLiteral ( " Window Contents " ) , & mainWindow ) ;
mainWindow . setCentralWidget ( & label ) ;
QDialog d ( & mainWindow ) ;
d . show ( ) ;
QAccessibleInterface * app = QAccessible : : queryAccessibleInterface ( qApp ) ;
QVERIFY ( app ) ;
QCOMPARE ( app - > childCount ( ) , 2 ) ;
QAccessibleInterface * windowIface = QAccessible : : queryAccessibleInterface ( & mainWindow ) ;
QVERIFY ( windowIface ) ;
QCOMPARE ( windowIface - > childCount ( ) , 1 ) ;
QCOMPARE ( app - > child ( 0 ) , windowIface ) ;
QAccessibleInterface * dialogIface = QAccessible : : queryAccessibleInterface ( & d ) ;
QVERIFY ( dialogIface ) ;
QCOMPARE ( app - > child ( 1 ) , dialogIface ) ;
QCOMPARE ( dialogIface - > parent ( ) , app ) ;
QCOMPARE ( windowIface - > parent ( ) , app ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
2011-03-14 17:57:27 +00:00
class CounterButton : public QPushButton {
Q_OBJECT
public :
CounterButton ( const QString & name , QWidget * parent )
: QPushButton ( name , parent ) , clickCount ( 0 )
{
connect ( this , SIGNAL ( clicked ( bool ) ) , SLOT ( incClickCount ( ) ) ) ;
}
int clickCount ;
public Q_SLOTS :
void incClickCount ( ) {
+ + clickCount ;
}
} ;
2011-04-27 10:05:43 +00:00
void tst_QAccessibility : : buttonTest ( )
{
2011-03-14 17:57:27 +00:00
QWidget window ;
window . setLayout ( new QVBoxLayout ) ;
2011-04-27 10:05:43 +00:00
// Standard push button
2011-03-14 17:57:27 +00:00
CounterButton pushButton ( " Ok " , & window ) ;
2011-04-27 10:05:43 +00:00
2011-04-04 09:50:31 +00:00
// toggle button
QPushButton toggleButton ( " Toggle " , & window ) ;
toggleButton . setCheckable ( true ) ;
2011-04-27 10:05:43 +00:00
// standard checkbox
2011-03-14 17:57:27 +00:00
QCheckBox checkBox ( " Check me! " , & window ) ;
2011-04-27 10:05:43 +00:00
// tristate checkbox
2011-03-14 17:57:27 +00:00
QCheckBox tristate ( " Tristate! " , & window ) ;
2011-12-30 05:51:05 +00:00
tristate . setTristate ( true ) ;
2011-04-27 10:05:43 +00:00
// radiobutton
2011-03-14 17:57:27 +00:00
QRadioButton radio ( " Radio me! " , & window ) ;
2011-04-27 10:05:43 +00:00
// standard toolbutton
2011-03-14 17:57:27 +00:00
QToolButton toolbutton ( & window ) ;
2011-04-27 10:05:43 +00:00
toolbutton . setText ( " Tool " ) ;
toolbutton . setMinimumSize ( 20 , 20 ) ;
// standard toolbutton
2011-03-14 17:57:27 +00:00
QToolButton toggletool ( & window ) ;
2011-04-04 09:50:31 +00:00
toggletool . setCheckable ( true ) ;
2011-04-27 10:05:43 +00:00
toggletool . setText ( " Toggle " ) ;
toggletool . setMinimumSize ( 20 , 20 ) ;
// test push button
2011-03-14 17:57:27 +00:00
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & pushButton ) ;
QAccessibleActionInterface * actionInterface = interface - > actionInterface ( ) ;
QVERIFY ( actionInterface ! = 0 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : PushButton ) ;
2011-03-14 17:57:27 +00:00
2011-10-11 14:20:47 +00:00
// buttons only have a click action
QCOMPARE ( actionInterface - > actionNames ( ) . size ( ) , 2 ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2011-03-14 17:57:27 +00:00
QCOMPARE ( pushButton . clickCount , 0 ) ;
2011-11-01 13:36:20 +00:00
actionInterface - > doAction ( QAccessibleActionInterface : : pressAction ( ) ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 500 ) ;
2011-03-14 17:57:27 +00:00
QCOMPARE ( pushButton . clickCount , 1 ) ;
// test toggle button
2011-04-04 09:50:31 +00:00
interface = QAccessible : : queryAccessibleInterface ( & toggleButton ) ;
2011-03-14 17:57:27 +00:00
actionInterface = interface - > actionInterface ( ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : CheckBox ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : toggleAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
QCOMPARE ( actionInterface - > localizedActionDescription ( QAccessibleActionInterface : : toggleAction ( ) ) , QString ( " Toggles the state " ) ) ;
2011-04-04 09:50:31 +00:00
QVERIFY ( ! toggleButton . isChecked ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! interface - > state ( ) . checked ) ;
2012-05-22 07:15:38 +00:00
actionInterface - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 500 ) ;
2011-04-04 09:50:31 +00:00
QVERIFY ( toggleButton . isChecked ( ) ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) . at ( 0 ) , QAccessibleActionInterface : : toggleAction ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . checked ) ;
2011-03-14 17:57:27 +00:00
2011-10-06 12:54:49 +00:00
{
// test menu push button
QAction * foo = new QAction ( " Foo " , 0 ) ;
foo - > setShortcut ( QKeySequence ( " Ctrl+F " ) ) ;
QMenu * menu = new QMenu ( ) ;
menu - > addAction ( foo ) ;
QPushButton menuButton ;
2012-12-18 14:22:48 +00:00
setFrameless ( & menuButton ) ;
2011-10-06 12:54:49 +00:00
menuButton . setMenu ( menu ) ;
menuButton . show ( ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & menuButton ) ;
QCOMPARE ( interface - > role ( ) , QAccessible : : ButtonMenu ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . hasPopup ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( interface - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : showMenuAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2011-10-06 12:54:49 +00:00
// showing the menu enters a new event loop...
2011-11-01 13:36:20 +00:00
// interface->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction());
2011-10-06 12:54:49 +00:00
// QTest::qWait(500);
delete menu ;
}
2011-04-27 10:05:43 +00:00
2012-03-07 18:09:33 +00:00
QTestAccessibility : : clearEvents ( ) ;
{
2011-04-27 10:05:43 +00:00
// test check box
2011-03-14 17:57:27 +00:00
interface = QAccessible : : queryAccessibleInterface ( & checkBox ) ;
actionInterface = interface - > actionInterface ( ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : CheckBox ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : toggleAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! interface - > state ( ) . checked ) ;
2012-05-22 07:15:38 +00:00
actionInterface - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
2012-03-07 18:09:33 +00:00
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 500 ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : toggleAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . checked ) ;
2011-03-14 17:57:27 +00:00
QVERIFY ( checkBox . isChecked ( ) ) ;
2012-03-07 18:09:33 +00:00
QAccessible : : State st ;
st . checked = true ;
2012-03-12 18:43:03 +00:00
QAccessibleStateChangeEvent ev ( & checkBox , st ) ;
2012-03-12 14:36:31 +00:00
QVERIFY_EVENT ( & ev ) ;
2012-03-07 18:38:39 +00:00
checkBox . setChecked ( false ) ;
2012-03-12 14:36:31 +00:00
QVERIFY_EVENT ( & ev ) ;
2012-03-07 18:09:33 +00:00
}
2011-03-14 17:57:27 +00:00
2012-03-07 18:38:39 +00:00
{
2011-04-27 10:05:43 +00:00
// test radiobutton
2011-03-14 17:57:27 +00:00
interface = QAccessible : : queryAccessibleInterface ( & radio ) ;
actionInterface = interface - > actionInterface ( ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : RadioButton ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : toggleAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! interface - > state ( ) . checked ) ;
2012-05-22 07:15:38 +00:00
actionInterface - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 500 ) ;
2012-05-22 07:15:38 +00:00
QCOMPARE ( actionInterface - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : toggleAction ( ) < < QAccessibleActionInterface : : setFocusAction ( ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . checked ) ;
2012-03-07 18:38:39 +00:00
QVERIFY ( radio . isChecked ( ) ) ;
QAccessible : : State st ;
st . checked = true ;
2012-03-12 18:43:03 +00:00
QAccessibleStateChangeEvent ev ( & radio , st ) ;
2012-03-12 14:36:31 +00:00
QVERIFY_EVENT ( & ev ) ;
2012-03-07 18:38:39 +00:00
}
2011-03-14 17:57:27 +00:00
// // test standard toolbutton
// QVERIFY(QAccessible::queryAccessibleInterface(&toolbutton, &test));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->role(), QAccessible::PushButton);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->defaultAction(0), QAccessible::Press);
// QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Press"));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->state(), (int)QAccessible::Normal);
2011-03-14 17:57:27 +00:00
// test->release();
// // toggle tool button
// QVERIFY(QAccessible::queryAccessibleInterface(&toggletool, &test));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->role(), QAccessible::CheckBox);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->defaultAction(0), QAccessible::Press);
// QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check"));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->state(), (int)QAccessible::Normal);
2011-03-14 17:57:27 +00:00
// QVERIFY(test->doAction(QAccessible::Press, 0));
// QTest::qWait(500);
// QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Uncheck"));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->state(), (int)QAccessible::Checked);
2011-03-14 17:57:27 +00:00
// test->release();
// // test menu toolbutton
// QVERIFY(QAccessible::queryAccessibleInterface(&menuToolButton, &test));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->role(), QAccessible::ButtonMenu);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->defaultAction(0), 1);
// QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Open"));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->state(), (int)QAccessible::HasPopup);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->actionCount(0), 1);
// QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 0), QString("Press"));
// test->release();
2011-07-06 21:06:42 +00:00
// // test split menu toolbutton
2011-03-14 17:57:27 +00:00
// QVERIFY(QAccessible::queryAccessibleInterface(&splitToolButton, &test));
// QCOMPARE(test->childCount(), 2);
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->role(), QAccessible::ButtonDropDown);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->role(1), QAccessible::PushButton);
// QCOMPARE(test->role(2), QAccessible::ButtonMenu);
// QCOMPARE(test->defaultAction(0), QAccessible::Press);
// QCOMPARE(test->defaultAction(1), QAccessible::Press);
// QCOMPARE(test->defaultAction(2), QAccessible::Press);
// QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Press"));
2011-10-05 07:40:04 +00:00
// QCOMPARE(test->state(), (int)QAccessible::HasPopup);
2011-03-14 17:57:27 +00:00
// QCOMPARE(test->actionCount(0), 1);
// QCOMPARE(test->actionText(1, QAccessible::Name, 0), QString("Open"));
// QCOMPARE(test->actionText(test->defaultAction(1), QAccessible::Name, 1), QString("Press"));
// QCOMPARE(test->state(1), (int)QAccessible::Normal);
// QCOMPARE(test->actionText(test->defaultAction(2), QAccessible::Name, 2), QString("Open"));
// QCOMPARE(test->state(2), (int)QAccessible::HasPopup);
// test->release();
2011-04-27 10:05:43 +00:00
}
void tst_QAccessibility : : scrollBarTest ( )
{
2011-10-04 12:20:05 +00:00
QScrollBar * scrollBar = new QScrollBar ( Qt : : Horizontal ) ;
2011-04-27 10:05:43 +00:00
QAccessibleInterface * const scrollBarInterface = QAccessible : : queryAccessibleInterface ( scrollBar ) ;
QVERIFY ( scrollBarInterface ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( scrollBarInterface - > state ( ) . invisible ) ;
2011-10-04 12:20:05 +00:00
scrollBar - > resize ( 200 , 50 ) ;
2011-04-27 10:05:43 +00:00
scrollBar - > show ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! scrollBarInterface - > state ( ) . invisible ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent show ( scrollBar , QAccessible : : ObjectShow ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & show ) ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
scrollBar - > hide ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( scrollBarInterface - > state ( ) . invisible ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent hide ( scrollBar , QAccessible : : ObjectHide ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & hide ) ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
// Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum.
scrollBar - > show ( ) ;
2011-09-08 17:05:18 +00:00
scrollBar - > setMinimum ( 11 ) ;
scrollBar - > setMaximum ( 111 ) ;
2011-04-27 10:05:43 +00:00
2011-09-08 17:05:18 +00:00
QAccessibleValueInterface * valueIface = scrollBarInterface - > valueInterface ( ) ;
QVERIFY ( valueIface ! = 0 ) ;
QCOMPARE ( valueIface - > minimumValue ( ) . toInt ( ) , scrollBar - > minimum ( ) ) ;
QCOMPARE ( valueIface - > maximumValue ( ) . toInt ( ) , scrollBar - > maximum ( ) ) ;
2011-04-27 10:05:43 +00:00
scrollBar - > setValue ( 50 ) ;
2011-09-08 17:05:18 +00:00
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , scrollBar - > value ( ) ) ;
2011-04-27 10:05:43 +00:00
scrollBar - > setValue ( 0 ) ;
2011-09-08 17:05:18 +00:00
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , scrollBar - > value ( ) ) ;
2011-04-27 10:05:43 +00:00
scrollBar - > setValue ( 100 ) ;
2011-09-08 17:05:18 +00:00
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , scrollBar - > value ( ) ) ;
valueIface - > setCurrentValue ( 77 ) ;
QCOMPARE ( 77 , scrollBar - > value ( ) ) ;
2011-04-27 10:05:43 +00:00
2011-10-04 12:20:05 +00:00
const QRect scrollBarRect = scrollBarInterface - > rect ( ) ;
QVERIFY ( scrollBarRect . isValid ( ) ) ;
2011-04-27 10:05:43 +00:00
2011-10-04 12:20:05 +00:00
delete scrollBar ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : tabTest ( )
{
QTabBar * tabBar = new QTabBar ( ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( tabBar ) ;
2011-04-27 10:05:43 +00:00
tabBar - > show ( ) ;
QAccessibleInterface * const interface = QAccessible : : queryAccessibleInterface ( tabBar ) ;
QVERIFY ( interface ) ;
QCOMPARE ( interface - > childCount ( ) , 2 ) ;
// Test that the Invisible bit for the navigation buttons gets set
// and cleared correctly.
2011-09-26 08:18:30 +00:00
QAccessibleInterface * leftButton = interface - > child ( 0 ) ;
QCOMPARE ( leftButton - > role ( ) , QAccessible : : PushButton ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( leftButton - > state ( ) . invisible ) ;
2011-09-13 14:27:13 +00:00
2011-09-26 08:18:30 +00:00
const int lots = 5 ;
2014-05-07 08:38:10 +00:00
for ( int i = 0 ; i < lots ; + + i ) {
2011-04-27 10:05:43 +00:00
tabBar - > addTab ( " Foo " ) ;
2014-05-07 08:38:10 +00:00
tabBar - > setTabToolTip ( i , QLatin1String ( " Cool tool tip " ) ) ;
tabBar - > setTabWhatsThis ( i , QLatin1String ( " I don't know " ) ) ;
}
2011-04-27 10:05:43 +00:00
2011-09-26 08:18:30 +00:00
QAccessibleInterface * child1 = interface - > child ( 0 ) ;
QAccessibleInterface * child2 = interface - > child ( 1 ) ;
QVERIFY ( child1 ) ;
QCOMPARE ( child1 - > role ( ) , QAccessible : : PageTab ) ;
QVERIFY ( child2 ) ;
QCOMPARE ( child2 - > role ( ) , QAccessible : : PageTab ) ;
2014-05-07 08:38:10 +00:00
QCOMPARE ( child1 - > text ( QAccessible : : Name ) , QLatin1String ( " Foo " ) ) ;
QCOMPARE ( child1 - > text ( QAccessible : : Description ) , QLatin1String ( " Cool tool tip " ) ) ;
QCOMPARE ( child1 - > text ( QAccessible : : Help ) , QLatin1String ( " I don't know " ) ) ;
2015-07-23 11:26:28 +00:00
QVERIFY ( ! ( child1 - > state ( ) . invisible ) ) ;
2011-04-27 10:05:43 +00:00
tabBar - > hide ( ) ;
2011-09-26 08:18:30 +00:00
QCoreApplication : : processEvents ( ) ;
QTest : : qWait ( 100 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( child1 - > state ( ) . invisible ) ;
2011-04-27 10:05:43 +00:00
tabBar - > show ( ) ;
tabBar - > setCurrentIndex ( 0 ) ;
// Test that sending a focus action to a tab does not select it.
2011-10-06 12:54:49 +00:00
// child2->doAction(QAccessible::Focus, 2, QVariantList());
2011-04-27 10:05:43 +00:00
QCOMPARE ( tabBar - > currentIndex ( ) , 0 ) ;
// Test that sending a press action to a tab selects it.
2011-10-06 12:54:49 +00:00
QVERIFY ( child2 - > actionInterface ( ) ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( child2 - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
2011-10-06 12:54:49 +00:00
QCOMPARE ( tabBar - > currentIndex ( ) , 0 ) ;
2011-11-01 13:36:20 +00:00
child2 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : pressAction ( ) ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( tabBar - > currentIndex ( ) , 1 ) ;
2011-09-15 19:41:54 +00:00
2016-01-23 04:19:28 +00:00
// Test that setAccessibleTabName changes a tab's accessible name
tabBar - > setAccessibleTabName ( 0 , " AccFoo " ) ;
tabBar - > setAccessibleTabName ( 1 , " AccBar " ) ;
QCOMPARE ( child1 - > text ( QAccessible : : Name ) , QLatin1String ( " AccFoo " ) ) ;
QCOMPARE ( child2 - > text ( QAccessible : : Name ) , QLatin1String ( " AccBar " ) ) ;
tabBar - > setCurrentIndex ( 0 ) ;
QCOMPARE ( interface - > text ( QAccessible : : Name ) , QLatin1String ( " AccFoo " ) ) ;
tabBar - > setCurrentIndex ( 1 ) ;
QCOMPARE ( interface - > text ( QAccessible : : Name ) , QLatin1String ( " AccBar " ) ) ;
2011-04-27 10:05:43 +00:00
delete tabBar ;
QTestAccessibility : : clearEvents ( ) ;
2011-03-18 16:41:01 +00:00
}
void tst_QAccessibility : : tabWidgetTest ( )
{
QTabWidget * tabWidget = new QTabWidget ( ) ;
tabWidget - > show ( ) ;
// the interface for the tab is just a container for tabbar and stacked widget
QAccessibleInterface * const interface = QAccessible : : queryAccessibleInterface ( tabWidget ) ;
QVERIFY ( interface ) ;
QCOMPARE ( interface - > childCount ( ) , 2 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : Client ) ;
2011-03-18 16:41:01 +00:00
// Create pages, check navigation
QLabel * label1 = new QLabel ( " Page 1 " , tabWidget ) ;
tabWidget - > addTab ( label1 , " Tab 1 " ) ;
QLabel * label2 = new QLabel ( " Page 2 " , tabWidget ) ;
tabWidget - > addTab ( label2 , " Tab 2 " ) ;
QCOMPARE ( interface - > childCount ( ) , 2 ) ;
QAccessibleInterface * tabBarInterface = 0 ;
// there is no special logic to sort the children, so the contents will be 1, the tab bar 2
2011-09-15 19:41:54 +00:00
tabBarInterface = interface - > child ( 1 ) ;
2013-09-20 08:54:59 +00:00
QCOMPARE ( verifyHierarchy ( tabBarInterface ) , 0 ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( tabBarInterface ) ;
QCOMPARE ( tabBarInterface - > childCount ( ) , 4 ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( tabBarInterface - > role ( ) , QAccessible : : PageTabList ) ;
2011-03-18 16:41:01 +00:00
2011-09-15 19:41:54 +00:00
QAccessibleInterface * tabButton1Interface = tabBarInterface - > child ( 0 ) ;
2011-09-13 14:23:33 +00:00
QVERIFY ( tabButton1Interface ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( tabButton1Interface - > role ( ) , QAccessible : : PageTab ) ;
QCOMPARE ( tabButton1Interface - > text ( QAccessible : : Name ) , QLatin1String ( " Tab 1 " ) ) ;
QAccessibleInterface * tabButton2Interface = tabBarInterface - > child ( 1 ) ;
2016-01-23 04:19:28 +00:00
QVERIFY ( tabButton2Interface ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( tabButton2Interface - > role ( ) , QAccessible : : PageTab ) ;
QCOMPARE ( tabButton2Interface - > text ( QAccessible : : Name ) , QLatin1String ( " Tab 2 " ) ) ;
2016-01-23 04:19:28 +00:00
// Test that setAccessibleTabName changes a tab's accessible name
tabWidget - > setCurrentIndex ( 0 ) ;
tabWidget - > tabBar ( ) - > setAccessibleTabName ( 0 , " Acc Tab " ) ;
QCOMPARE ( tabButton1Interface - > role ( ) , QAccessible : : PageTab ) ;
QCOMPARE ( tabButton1Interface - > text ( QAccessible : : Name ) , QLatin1String ( " Acc Tab " ) ) ;
QCOMPARE ( tabBarInterface - > text ( QAccessible : : Name ) , QLatin1String ( " Acc Tab " ) ) ;
2011-09-15 19:41:54 +00:00
QAccessibleInterface * tabButtonLeft = tabBarInterface - > child ( 2 ) ;
QVERIFY ( tabButtonLeft ) ;
QCOMPARE ( tabButtonLeft - > role ( ) , QAccessible : : PushButton ) ;
QCOMPARE ( tabButtonLeft - > text ( QAccessible : : Name ) , QLatin1String ( " Scroll Left " ) ) ;
QAccessibleInterface * tabButtonRight = tabBarInterface - > child ( 3 ) ;
QVERIFY ( tabButtonRight ) ;
QCOMPARE ( tabButtonRight - > role ( ) , QAccessible : : PushButton ) ;
QCOMPARE ( tabButtonRight - > text ( QAccessible : : Name ) , QLatin1String ( " Scroll Right " ) ) ;
2011-03-18 16:41:01 +00:00
2011-09-15 19:41:54 +00:00
QAccessibleInterface * stackWidgetInterface = interface - > child ( 0 ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( stackWidgetInterface ) ;
QCOMPARE ( stackWidgetInterface - > childCount ( ) , 2 ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( stackWidgetInterface - > role ( ) , QAccessible : : LayeredPane ) ;
2011-03-18 16:41:01 +00:00
2011-09-15 19:41:54 +00:00
QAccessibleInterface * stackChild1Interface = stackWidgetInterface - > child ( 0 ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( stackChild1Interface ) ;
2011-04-27 11:03:09 +00:00
# ifndef Q_CC_INTEL
2011-03-18 16:41:01 +00:00
QCOMPARE ( stackChild1Interface - > childCount ( ) , 0 ) ;
2011-04-27 11:03:09 +00:00
# endif
2011-09-15 19:41:54 +00:00
QCOMPARE ( stackChild1Interface - > role ( ) , QAccessible : : StaticText ) ;
QCOMPARE ( stackChild1Interface - > text ( QAccessible : : Name ) , QLatin1String ( " Page 1 " ) ) ;
2011-03-18 16:41:01 +00:00
QCOMPARE ( label1 , stackChild1Interface - > object ( ) ) ;
// Navigation in stack widgets should be consistent
2011-09-15 19:41:54 +00:00
QAccessibleInterface * parent = stackChild1Interface - > parent ( ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( parent ) ;
2011-04-27 11:03:09 +00:00
# ifndef Q_CC_INTEL
2011-03-18 16:41:01 +00:00
QCOMPARE ( parent - > childCount ( ) , 2 ) ;
2011-04-27 11:03:09 +00:00
# endif
2011-10-05 07:40:04 +00:00
QCOMPARE ( parent - > role ( ) , QAccessible : : LayeredPane ) ;
2011-03-18 16:41:01 +00:00
2011-09-15 19:41:54 +00:00
QAccessibleInterface * stackChild2Interface = stackWidgetInterface - > child ( 1 ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( stackChild2Interface ) ;
QCOMPARE ( stackChild2Interface - > childCount ( ) , 0 ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( stackChild2Interface - > role ( ) , QAccessible : : StaticText ) ;
QCOMPARE ( label2 , stackChild2Interface - > object ( ) ) ;
QCOMPARE ( label2 - > text ( ) , stackChild2Interface - > text ( QAccessible : : Name ) ) ;
2011-03-18 16:41:01 +00:00
2011-09-15 19:41:54 +00:00
parent = stackChild2Interface - > parent ( ) ;
2011-03-18 16:41:01 +00:00
QVERIFY ( parent ) ;
2011-04-27 11:03:09 +00:00
# ifndef Q_CC_INTEL
2011-03-18 16:41:01 +00:00
QCOMPARE ( parent - > childCount ( ) , 2 ) ;
2011-04-27 11:03:09 +00:00
# endif
2011-09-15 19:41:54 +00:00
QCOMPARE ( parent - > role ( ) , QAccessible : : LayeredPane ) ;
2011-03-18 16:41:01 +00:00
delete tabWidget ;
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
void tst_QAccessibility : : menuTest ( )
{
{
QMainWindow mw ;
mw . resize ( 300 , 200 ) ;
2016-01-15 14:04:01 +00:00
mw . menuBar ( ) - > setNativeMenuBar ( false ) ;
2011-04-27 10:05:43 +00:00
QMenu * file = mw . menuBar ( ) - > addMenu ( " &File " ) ;
QMenu * fileNew = file - > addMenu ( " &New... " ) ;
fileNew - > menuAction ( ) - > setShortcut ( tr ( " Ctrl+N " ) ) ;
fileNew - > addAction ( " Text file " ) ;
fileNew - > addAction ( " Image file " ) ;
file - > addAction ( " &Open " ) - > setShortcut ( tr ( " Ctrl+O " ) ) ;
file - > addAction ( " &Save " ) - > setShortcut ( tr ( " Ctrl+S " ) ) ;
file - > addSeparator ( ) ;
file - > addAction ( " E&xit " ) - > setShortcut ( tr ( " Alt+F4 " ) ) ;
QMenu * edit = mw . menuBar ( ) - > addMenu ( " &Edit " ) ;
edit - > addAction ( " &Undo " ) - > setShortcut ( tr ( " Ctrl+Z " ) ) ;
edit - > addAction ( " &Redo " ) - > setShortcut ( tr ( " Ctrl+Y " ) ) ;
edit - > addSeparator ( ) ;
edit - > addAction ( " Cu&t " ) - > setShortcut ( tr ( " Ctrl+X " ) ) ;
edit - > addAction ( " &Copy " ) - > setShortcut ( tr ( " Ctrl+C " ) ) ;
edit - > addAction ( " &Paste " ) - > setShortcut ( tr ( " Ctrl+V " ) ) ;
edit - > addAction ( " &Delete " ) - > setShortcut ( tr ( " Del " ) ) ;
edit - > addSeparator ( ) ;
edit - > addAction ( " Pr&operties " ) ;
mw . menuBar ( ) - > addSeparator ( ) ;
QMenu * help = mw . menuBar ( ) - > addMenu ( " &Help " ) ;
help - > addAction ( " &Contents " ) ;
help - > addAction ( " &About " ) ;
mw . menuBar ( ) - > addAction ( " Action! " ) ;
2012-12-20 15:09:39 +00:00
QMenu * childOfMainWindow = new QMenu ( QStringLiteral ( " &Tools " ) , & mw ) ;
childOfMainWindow - > addAction ( " &Options " ) ;
mw . menuBar ( ) - > addMenu ( childOfMainWindow ) ;
2011-04-27 10:05:43 +00:00
mw . show ( ) ; // triggers layout
QTest : : qWait ( 100 ) ;
2012-12-20 15:09:39 +00:00
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & mw ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( verifyHierarchy ( interface ) , 0 ) ;
2012-12-20 15:09:39 +00:00
interface = QAccessible : : queryAccessibleInterface ( mw . menuBar ( ) ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( interface ) ;
2012-12-20 15:09:39 +00:00
QCOMPARE ( interface - > childCount ( ) , 6 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : MenuBar ) ;
2011-09-15 19:41:54 +00:00
QAccessibleInterface * iFile = interface - > child ( 0 ) ;
QAccessibleInterface * iEdit = interface - > child ( 1 ) ;
QAccessibleInterface * iSeparator = interface - > child ( 2 ) ;
QAccessibleInterface * iHelp = interface - > child ( 3 ) ;
QAccessibleInterface * iAction = interface - > child ( 4 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iFile - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iEdit - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iSeparator - > role ( ) , QAccessible : : Separator ) ;
QCOMPARE ( iHelp - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iAction - > role ( ) , QAccessible : : MenuItem ) ;
2012-01-16 11:02:48 +00:00
# ifndef Q_OS_MAC
2011-10-05 07:40:04 +00:00
QCOMPARE ( mw . mapFromGlobal ( interface - > rect ( ) . topLeft ( ) ) , mw . menuBar ( ) - > geometry ( ) . topLeft ( ) ) ;
QCOMPARE ( interface - > rect ( ) . size ( ) , mw . menuBar ( ) - > size ( ) ) ;
QVERIFY ( interface - > rect ( ) . contains ( iFile - > rect ( ) ) ) ;
QVERIFY ( interface - > rect ( ) . contains ( iEdit - > rect ( ) ) ) ;
// QVERIFY(interface->rect().contains(childSeparator->rect())); //separator might be invisible
QVERIFY ( interface - > rect ( ) . contains ( iHelp - > rect ( ) ) ) ;
QVERIFY ( interface - > rect ( ) . contains ( iAction - > rect ( ) ) ) ;
2011-04-27 10:05:43 +00:00
# endif
2011-10-22 20:38:14 +00:00
QCOMPARE ( iFile - > text ( QAccessible : : Name ) , QString ( " File " ) ) ;
QCOMPARE ( iEdit - > text ( QAccessible : : Name ) , QString ( " Edit " ) ) ;
QCOMPARE ( iSeparator - > text ( QAccessible : : Name ) , QString ( ) ) ;
QCOMPARE ( iHelp - > text ( QAccessible : : Name ) , QString ( " Help " ) ) ;
QCOMPARE ( iAction - > text ( QAccessible : : Name ) , QString ( " Action! " ) ) ;
2011-04-27 10:05:43 +00:00
// TODO: Currently not working, task to fix is #100019.
# ifndef Q_OS_MAC
2011-10-22 20:38:14 +00:00
QCOMPARE ( iFile - > text ( QAccessible : : Accelerator ) , tr ( " Alt+F " ) ) ;
QCOMPARE ( iEdit - > text ( QAccessible : : Accelerator ) , tr ( " Alt+E " ) ) ;
QCOMPARE ( iSeparator - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
QCOMPARE ( iHelp - > text ( QAccessible : : Accelerator ) , tr ( " Alt+H " ) ) ;
QCOMPARE ( iAction - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
# endif
2011-10-06 12:54:49 +00:00
QVERIFY ( iFile - > actionInterface ( ) ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( iFile - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-10-06 12:54:49 +00:00
QCOMPARE ( iSeparator - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( iHelp - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : showMenuAction ( ) ) ;
QCOMPARE ( iAction - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
2011-04-27 10:05:43 +00:00
bool menuFade = qApp - > isEffectEnabled ( Qt : : UI_FadeMenu ) ;
int menuFadeDelay = 300 ;
2011-11-01 13:36:20 +00:00
iFile - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-04-27 10:05:43 +00:00
if ( menuFade )
QTest : : qWait ( menuFadeDelay ) ;
2014-03-28 10:05:00 +00:00
QTRY_VERIFY ( file - > isVisible ( ) & & ! edit - > isVisible ( ) & & ! help - > isVisible ( ) ) ;
2011-11-01 13:36:20 +00:00
iEdit - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-04-27 10:05:43 +00:00
if ( menuFade )
QTest : : qWait ( menuFadeDelay ) ;
2014-03-28 10:05:00 +00:00
QTRY_VERIFY ( ! file - > isVisible ( ) & & edit - > isVisible ( ) & & ! help - > isVisible ( ) ) ;
2011-11-01 13:36:20 +00:00
iHelp - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-04-27 10:05:43 +00:00
if ( menuFade )
QTest : : qWait ( menuFadeDelay ) ;
2014-03-28 10:05:00 +00:00
QTRY_VERIFY ( ! file - > isVisible ( ) & & ! edit - > isVisible ( ) & & help - > isVisible ( ) ) ;
2011-11-01 13:36:20 +00:00
iAction - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-04-27 10:05:43 +00:00
if ( menuFade )
QTest : : qWait ( menuFadeDelay ) ;
2014-03-28 10:05:00 +00:00
QTRY_VERIFY ( ! file - > isVisible ( ) & & ! edit - > isVisible ( ) & & ! help - > isVisible ( ) ) ;
2011-04-27 10:05:43 +00:00
2011-10-11 14:20:47 +00:00
QVERIFY ( interface - > actionInterface ( ) ) ;
QCOMPARE ( interface - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) ) ;
2011-04-27 10:05:43 +00:00
interface = QAccessible : : queryAccessibleInterface ( file ) ;
QCOMPARE ( interface - > childCount ( ) , 5 ) ;
2011-09-15 19:41:54 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : PopupMenu ) ;
QAccessibleInterface * iFileNew = interface - > child ( 0 ) ;
QAccessibleInterface * iFileOpen = interface - > child ( 1 ) ;
QAccessibleInterface * iFileSave = interface - > child ( 2 ) ;
QAccessibleInterface * iFileSeparator = interface - > child ( 3 ) ;
QAccessibleInterface * iFileExit = interface - > child ( 4 ) ;
QCOMPARE ( iFileNew - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iFileOpen - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iFileSave - > role ( ) , QAccessible : : MenuItem ) ;
QCOMPARE ( iFileSeparator - > role ( ) , QAccessible : : Separator ) ;
QCOMPARE ( iFileExit - > role ( ) , QAccessible : : MenuItem ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( iFileNew - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : showMenuAction ( ) ) ;
QCOMPARE ( iFileOpen - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
QCOMPARE ( iFileSave - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
2011-10-06 12:54:49 +00:00
QCOMPARE ( iFileSeparator - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) ) ;
2011-11-01 13:36:20 +00:00
QCOMPARE ( iFileExit - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
2011-04-27 10:05:43 +00:00
QAccessibleInterface * iface = 0 ;
QAccessibleInterface * iface2 = 0 ;
// traverse siblings with navigate(Sibling, ...)
2011-11-15 17:32:55 +00:00
iface = interface - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( iface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : MenuItem ) ;
2011-04-27 10:05:43 +00:00
QAccessible : : Role fileRoles [ 5 ] = {
QAccessible : : MenuItem ,
QAccessible : : MenuItem ,
QAccessible : : MenuItem ,
QAccessible : : Separator ,
QAccessible : : MenuItem
} ;
for ( int child = 0 ; child < 5 ; + + child ) {
2012-01-05 08:51:20 +00:00
iface2 = interface - > child ( child ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( iface2 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface2 - > role ( ) , fileRoles [ child ] ) ;
2011-04-27 10:05:43 +00:00
}
// "New" item
2011-11-15 17:32:55 +00:00
iface = interface - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( iface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : MenuItem ) ;
2011-04-27 10:05:43 +00:00
// "New" menu
2011-11-15 17:32:55 +00:00
iface2 = iface - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
iface = iface2 ;
QVERIFY ( iface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : PopupMenu ) ;
2011-04-27 10:05:43 +00:00
// "Text file" menu item
2011-11-15 17:32:55 +00:00
iface2 = iface - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
iface = iface2 ;
QVERIFY ( iface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : MenuItem ) ;
2011-04-27 10:05:43 +00:00
// move mouse pointer away, since that might influence the
// subsequent tests
QTest : : mouseMove ( & mw , QPoint ( - 1 , - 1 ) ) ;
QTest : : qWait ( 100 ) ;
if ( menuFade )
QTest : : qWait ( menuFadeDelay ) ;
2011-09-15 19:41:54 +00:00
2011-11-01 13:36:20 +00:00
iFile - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
iFileNew - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2011-04-27 10:05:43 +00:00
2014-03-28 10:05:00 +00:00
QTRY_VERIFY ( file - > isVisible ( ) ) ;
QTRY_VERIFY ( fileNew - > isVisible ( ) ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( ! edit - > isVisible ( ) ) ;
QVERIFY ( ! help - > isVisible ( ) ) ;
QTestAccessibility : : clearEvents ( ) ;
mw . hide ( ) ;
// Do not crash if the menu don't have a parent
QMenu * menu = new QMenu ;
menu - > addAction ( QLatin1String ( " one " ) ) ;
menu - > addAction ( QLatin1String ( " two " ) ) ;
menu - > addAction ( QLatin1String ( " three " ) ) ;
iface = QAccessible : : queryAccessibleInterface ( menu ) ;
2011-09-15 19:41:54 +00:00
iface2 = iface - > parent ( ) ;
QVERIFY ( iface2 ) ;
QCOMPARE ( iface2 - > role ( ) , QAccessible : : Application ) ;
2011-04-27 10:05:43 +00:00
// caused a *crash*
2011-10-05 07:40:04 +00:00
iface2 - > state ( ) ;
2011-04-27 10:05:43 +00:00
delete menu ;
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : spinBoxTest ( )
{
QSpinBox * const spinBox = new QSpinBox ( ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( spinBox ) ;
2011-10-04 14:46:45 +00:00
spinBox - > setValue ( 3 ) ;
2011-04-27 10:05:43 +00:00
spinBox - > show ( ) ;
QAccessibleInterface * const interface = QAccessible : : queryAccessibleInterface ( spinBox ) ;
QVERIFY ( interface ) ;
2011-10-04 14:46:45 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : SpinBox ) ;
2011-04-27 10:05:43 +00:00
2012-09-13 09:14:13 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( spinBox ) ) ;
2011-04-27 10:05:43 +00:00
const QRect widgetRect = spinBox - > geometry ( ) ;
2011-10-04 14:46:45 +00:00
const QRect accessibleRect = interface - > rect ( ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( accessibleRect , widgetRect ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Value ) , QLatin1String ( " 3 " ) ) ;
2011-04-27 10:05:43 +00:00
2014-06-27 11:23:01 +00:00
// make sure that the line edit is not there
2011-04-27 10:05:43 +00:00
const int numChildren = interface - > childCount ( ) ;
2014-06-27 11:23:01 +00:00
QCOMPARE ( numChildren , 0 ) ;
2015-07-24 13:51:48 +00:00
QVERIFY ( ! interface - > child ( 0 ) ) ;
2011-10-04 14:46:45 +00:00
QVERIFY ( interface - > valueInterface ( ) ) ;
QCOMPARE ( interface - > valueInterface ( ) - > currentValue ( ) . toInt ( ) , 3 ) ;
interface - > valueInterface ( ) - > setCurrentValue ( 23 ) ;
QCOMPARE ( interface - > valueInterface ( ) - > currentValue ( ) . toInt ( ) , 23 ) ;
QCOMPARE ( spinBox - > value ( ) , 23 ) ;
2011-04-27 10:05:43 +00:00
spinBox - > setFocus ( ) ;
QTestAccessibility : : clearEvents ( ) ;
QTest : : keyPress ( spinBox , Qt : : Key_Up ) ;
QTest : : qWait ( 200 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleValueChangeEvent expectedEvent ( spinBox , spinBox - > value ( ) ) ;
2012-03-12 14:36:31 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & expectedEvent ) ) ;
2014-06-27 11:23:01 +00:00
QAccessibleTextInterface * textIface = interface - > textInterface ( ) ;
QVERIFY ( textIface ) ;
2011-04-27 10:05:43 +00:00
delete spinBox ;
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : doubleSpinBoxTest ( )
{
QDoubleSpinBox * doubleSpinBox = new QDoubleSpinBox ;
2012-12-18 14:22:48 +00:00
setFrameless ( doubleSpinBox ) ;
2011-04-27 10:05:43 +00:00
doubleSpinBox - > show ( ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( doubleSpinBox ) ;
QVERIFY ( interface ) ;
2012-09-13 09:14:13 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( doubleSpinBox ) ) ;
2011-04-27 10:05:43 +00:00
const QRect widgetRect = doubleSpinBox - > geometry ( ) ;
2011-10-05 07:40:04 +00:00
const QRect accessibleRect = interface - > rect ( ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( accessibleRect , widgetRect ) ;
// Test that we get valid rects for all the spinbox child interfaces.
const int numChildren = interface - > childCount ( ) ;
2011-10-22 20:38:14 +00:00
for ( int i = 0 ; i < numChildren ; + + i ) {
QAccessibleInterface * childIface = interface - > child ( i ) ;
const QRect childRect = childIface - > rect ( ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( childRect . isValid ( ) ) ;
}
delete doubleSpinBox ;
QTestAccessibility : : clearEvents ( ) ;
}
2012-08-08 14:06:33 +00:00
static QRect characterRect ( const QTextEdit & edit , int offset )
2011-04-27 10:05:43 +00:00
{
2012-08-08 14:06:33 +00:00
QTextBlock block = edit . document ( ) - > findBlock ( offset ) ;
QTextLayout * layout = block . layout ( ) ;
QPointF layoutPosition = layout - > position ( ) ;
int relativeOffset = offset - block . position ( ) ;
QTextLine line = layout - > lineForTextPosition ( relativeOffset ) ;
2015-02-08 08:11:49 +00:00
QTextBlock : : iterator it = block . begin ( ) ;
while ( ! it . fragment ( ) . contains ( offset ) )
+ + it ;
QFontMetrics fm ( it . fragment ( ) . charFormat ( ) . font ( ) ) ;
2012-08-08 14:06:33 +00:00
QChar ch = edit . document ( ) - > characterAt ( offset ) ;
int w = fm . width ( ch ) ;
int h = fm . height ( ) ;
2012-02-07 10:53:31 +00:00
2012-08-08 14:06:33 +00:00
qreal x = line . cursorToX ( relativeOffset ) ;
2015-08-04 16:13:25 +00:00
QRect r ( layoutPosition . x ( ) + x , layoutPosition . y ( ) + line . y ( ) + line . ascent ( ) + fm . descent ( ) - h , w , h ) ;
2012-08-08 14:06:33 +00:00
r . moveTo ( edit . viewport ( ) - > mapToGlobal ( r . topLeft ( ) ) ) ;
return r ;
}
2012-01-20 18:07:54 +00:00
2013-01-04 08:21:35 +00:00
/* The rects does not have to be exactly the same. They may be slightly different due to
different ways of calculating them . By having an acceptable delta , this should also
make the test a bit more resilient against any future changes in the behavior of
characterRect ( ) .
*/
static bool fuzzyRectCompare ( const QRect & a , const QRect & b )
{
static const int MAX_ACCEPTABLE_DELTA = 1 ;
const QMargins delta ( a . left ( ) - b . left ( ) , a . top ( ) - b . top ( ) ,
a . right ( ) - b . right ( ) , a . bottom ( ) - b . bottom ( ) ) ;
return qAbs ( delta . left ( ) ) < = MAX_ACCEPTABLE_DELTA & & qAbs ( delta . top ( ) ) < = MAX_ACCEPTABLE_DELTA
& & qAbs ( delta . right ( ) ) < = MAX_ACCEPTABLE_DELTA & & qAbs ( delta . bottom ( ) ) < = MAX_ACCEPTABLE_DELTA ;
}
2015-07-15 10:24:50 +00:00
static QByteArray msgRectMismatch ( const QRect & a , const QRect & b )
{
QString result ;
QDebug ( & result ) < < a < < " != " < < b ;
return result . toLocal8Bit ( ) ;
}
2012-08-08 14:06:33 +00:00
void tst_QAccessibility : : textEditTest ( )
{
for ( int pass = 0 ; pass < 2 ; + + pass ) {
{
QTextEdit edit ;
2015-02-10 16:49:10 +00:00
edit . setMinimumSize ( 600 , 400 ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( & edit ) ;
2012-08-08 14:06:33 +00:00
int startOffset ;
int endOffset ;
// create two blocks of text. The first block has two lines.
QString text = " <p>hello world.<br/>How are you today?</p><p>I'm fine, thanks</p> " ;
edit . setHtml ( text ) ;
if ( pass = = 1 ) {
QFont font ( " Helvetica " ) ;
font . setPointSizeF ( 12.5 ) ;
font . setWordSpacing ( 1.1 ) ;
2015-02-08 08:11:49 +00:00
edit . document ( ) - > setDefaultFont ( font ) ;
2012-08-08 14:06:33 +00:00
}
edit . show ( ) ;
2015-08-24 11:35:22 +00:00
QTest : : qWaitForWindowExposed ( & edit ) ;
2012-08-08 14:06:33 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & edit ) ;
QCOMPARE ( iface - > text ( QAccessible : : Value ) , edit . toPlainText ( ) ) ;
2014-05-30 12:13:30 +00:00
QVERIFY ( iface - > state ( ) . focusable ) ;
QVERIFY ( ! iface - > state ( ) . selectable ) ;
QVERIFY ( ! iface - > state ( ) . selected ) ;
QVERIFY ( iface - > state ( ) . selectableText ) ;
2014-03-18 16:20:23 +00:00
QAccessibleTextInterface * textIface = iface - > textInterface ( ) ;
QVERIFY ( textIface ) ;
QCOMPARE ( textIface - > textAtOffset ( 8 , QAccessible : : WordBoundary , & startOffset , & endOffset ) , QString ( " world " ) ) ;
2012-08-08 14:06:33 +00:00
QCOMPARE ( startOffset , 6 ) ;
QCOMPARE ( endOffset , 11 ) ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > textAtOffset ( 15 , QAccessible : : LineBoundary , & startOffset , & endOffset ) , QString ( " How are you today? " ) ) ;
2012-08-08 14:06:33 +00:00
QCOMPARE ( startOffset , 13 ) ;
QCOMPARE ( endOffset , 31 ) ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > characterCount ( ) , 48 ) ;
2015-02-08 08:11:49 +00:00
QFontMetrics fm ( edit . document ( ) - > defaultFont ( ) ) ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > characterRect ( 0 ) . size ( ) , QSize ( fm . width ( " h " ) , fm . height ( ) ) ) ;
QCOMPARE ( textIface - > characterRect ( 5 ) . size ( ) , QSize ( fm . width ( " " ) , fm . height ( ) ) ) ;
QCOMPARE ( textIface - > characterRect ( 6 ) . size ( ) , QSize ( fm . width ( " w " ) , fm . height ( ) ) ) ;
2012-08-08 14:06:33 +00:00
int offset = 10 ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > text ( offset , offset + 1 ) , QStringLiteral ( " d " ) ) ;
2015-07-15 10:24:50 +00:00
const QRect actual10 = textIface - > characterRect ( offset ) ;
const QRect expected10 = characterRect ( edit , offset ) ;
QVERIFY2 ( fuzzyRectCompare ( actual10 , expected10 ) , msgRectMismatch ( actual10 , expected10 ) . constData ( ) ) ;
2012-08-08 14:06:33 +00:00
offset = 13 ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > text ( offset , offset + 1 ) , QStringLiteral ( " H " ) ) ;
2015-07-15 10:24:50 +00:00
const QRect actual13 = textIface - > characterRect ( offset ) ;
const QRect expected13 = characterRect ( edit , offset ) ;
QVERIFY2 ( fuzzyRectCompare ( actual13 , expected13 ) , msgRectMismatch ( actual13 , expected13 ) . constData ( ) ) ;
2012-08-08 14:06:33 +00:00
offset = 21 ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > text ( offset , offset + 1 ) , QStringLiteral ( " y " ) ) ;
2015-07-15 10:24:50 +00:00
const QRect actual21 = textIface - > characterRect ( offset ) ;
const QRect expected21 = characterRect ( edit , offset ) ;
QVERIFY2 ( fuzzyRectCompare ( actual21 , expected21 ) , msgRectMismatch ( actual21 , expected21 ) . constData ( ) ) ;
2012-08-08 14:06:33 +00:00
offset = 32 ;
2014-03-18 16:20:23 +00:00
QCOMPARE ( textIface - > text ( offset , offset + 1 ) , QStringLiteral ( " I " ) ) ;
2015-07-15 10:24:50 +00:00
const QRect actual32 = textIface - > characterRect ( offset ) ;
const QRect expected32 = characterRect ( edit , offset ) ;
QVERIFY2 ( fuzzyRectCompare ( actual32 , expected32 ) , msgRectMismatch ( actual32 , expected32 ) . constData ( ) ) ;
2012-08-08 14:06:33 +00:00
QTestAccessibility : : clearEvents ( ) ;
// select text
QTextCursor c = edit . textCursor ( ) ;
c . setPosition ( 2 ) ;
c . setPosition ( 4 , QTextCursor : : KeepAnchor ) ;
edit . setTextCursor ( c ) ;
QAccessibleTextSelectionEvent sel ( & edit , 2 , 4 ) ;
QVERIFY_EVENT ( & sel ) ;
2012-09-13 14:50:31 +00:00
QAccessibleTextCursorEvent cursor ( & edit , 4 ) ;
QVERIFY_EVENT ( & cursor ) ;
2012-08-08 14:06:33 +00:00
edit . selectAll ( ) ;
int end = edit . textCursor ( ) . position ( ) ;
sel . setCursorPosition ( end ) ;
sel . setSelection ( 0 , end ) ;
QVERIFY_EVENT ( & sel ) ;
2014-03-18 16:20:23 +00:00
// check that we have newlines handled
QString poem = QStringLiteral ( " Once upon a midnight dreary, \n while I pondered, weak and weary, \n Over many a quaint and curious volume of forgotten lore \n " ) ;
QAccessibleEditableTextInterface * editableTextIface = iface - > editableTextInterface ( ) ;
QVERIFY ( editableTextIface ) ;
editableTextIface - > replaceText ( 0 , end , poem ) ;
QCOMPARE ( iface - > text ( QAccessible : : Value ) , poem ) ;
QCOMPARE ( textIface - > text ( 0 , poem . size ( ) ) , poem ) ;
QCOMPARE ( textIface - > text ( 28 , 29 ) , QLatin1String ( " \n " ) ) ;
int start ;
QCOMPARE ( textIface - > textAtOffset ( 42 , QAccessible : : LineBoundary , & start , & end ) , QStringLiteral ( " while I pondered, weak and weary, " ) ) ;
QCOMPARE ( start , 29 ) ;
QCOMPARE ( end , 62 ) ;
QCOMPARE ( textIface - > textAtOffset ( 28 , QAccessible : : CharBoundary , & start , & end ) , QLatin1String ( " \n " ) ) ;
QCOMPARE ( start , 28 ) ;
QCOMPARE ( end , 29 ) ;
2014-04-02 17:49:08 +00:00
edit . clear ( ) ;
QTestAccessibility : : clearEvents ( ) ;
// make sure we get notifications when typing text
QTestEventList keys ;
keys . addKeyClick ( ' A ' ) ;
keys . simulate ( & edit ) ;
keys . clear ( ) ;
QAccessibleTextInsertEvent insertA ( & edit , 0 , " A " ) ;
QVERIFY_EVENT ( & insertA ) ;
QAccessibleTextCursorEvent move1 ( & edit , 1 ) ;
QVERIFY_EVENT ( & move1 ) ;
keys . addKeyClick ( ' c ' ) ;
keys . simulate ( & edit ) ;
keys . clear ( ) ;
QAccessibleTextInsertEvent insertC ( & edit , 1 , " c " ) ;
QVERIFY_EVENT ( & insertC ) ;
QAccessibleTextCursorEvent move2 ( & edit , 2 ) ;
QVERIFY_EVENT ( & move2 ) ;
keys . addKeyClick ( Qt : : Key_Backspace ) ;
keys . simulate ( & edit ) ;
keys . clear ( ) ;
// FIXME this should get a proper string instead of space
QAccessibleTextRemoveEvent del ( & edit , 1 , " " ) ;
QVERIFY_EVENT ( & del ) ;
QVERIFY_EVENT ( & move1 ) ;
// it would be nicer to get a text update event, but the current implementation
// instead does remove and insert which is also fine
edit . setText ( QStringLiteral ( " Accessibility rocks " ) ) ;
QAccessibleTextRemoveEvent remove ( & edit , 0 , " " ) ;
QVERIFY_EVENT ( & remove ) ;
QAccessibleTextInsertEvent insert ( & edit , 0 , " Accessibility rocks " ) ;
QVERIFY_EVENT ( & insert ) ;
2012-08-08 14:06:33 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
}
void tst_QAccessibility : : textBrowserTest ( )
{
{
QTextBrowser textBrowser ;
QString text = QLatin1String ( " Hello world \n how are you today? \n " ) ;
textBrowser . setText ( text ) ;
textBrowser . show ( ) ;
2011-09-27 12:28:19 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & textBrowser ) ;
QVERIFY ( iface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : StaticText ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , text ) ;
2011-09-27 12:28:19 +00:00
int startOffset ;
int endOffset ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( iface - > textInterface ( ) - > textAtOffset ( 8 , QAccessible : : WordBoundary , & startOffset , & endOffset ) , QString ( " world " ) ) ;
2011-09-27 12:28:19 +00:00
QCOMPARE ( startOffset , 6 ) ;
QCOMPARE ( endOffset , 11 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( iface - > textInterface ( ) - > textAtOffset ( 14 , QAccessible : : LineBoundary , & startOffset , & endOffset ) , QString ( " how are you today? " ) ) ;
2011-09-27 12:28:19 +00:00
QCOMPARE ( startOffset , 12 ) ;
QCOMPARE ( endOffset , 30 ) ;
QCOMPARE ( iface - > textInterface ( ) - > characterCount ( ) , 31 ) ;
2011-04-27 10:05:43 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : mdiAreaTest ( )
{
{
QMdiArea mdiArea ;
mdiArea . resize ( 400 , 300 ) ;
mdiArea . show ( ) ;
const int subWindowCount = 3 ;
for ( int i = 0 ; i < subWindowCount ; + + i )
mdiArea . addSubWindow ( new QWidget , Qt : : Dialog ) - > show ( ) ;
QList < QMdiSubWindow * > subWindows = mdiArea . subWindowList ( ) ;
QCOMPARE ( subWindows . count ( ) , subWindowCount ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & mdiArea ) ;
QVERIFY ( interface ) ;
QCOMPARE ( interface - > childCount ( ) , subWindowCount ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : mdiSubWindowTest ( )
{
{
QMdiArea mdiArea ;
mdiArea . show ( ) ;
qApp - > setActiveWindow ( & mdiArea ) ;
2012-07-18 11:12:59 +00:00
QVERIFY ( QTest : : qWaitForWindowActive ( & mdiArea ) ) ;
2011-04-27 10:05:43 +00:00
const int subWindowCount = 5 ;
for ( int i = 0 ; i < subWindowCount ; + + i ) {
QMdiSubWindow * window = mdiArea . addSubWindow ( new QPushButton ( " QAccessibilityTest " ) ) ;
2012-10-16 14:53:09 +00:00
window - > setAttribute ( Qt : : WA_LayoutUsesWidgetRect ) ;
2011-04-27 10:05:43 +00:00
window - > show ( ) ;
// Parts of this test requires that the sub windows are placed next
// to each other. In order to achieve that QMdiArea must have
// a width which is larger than subWindow->width() * subWindowCount.
if ( i = = 0 ) {
int minimumWidth = window - > width ( ) * subWindowCount + 20 ;
mdiArea . resize ( mdiArea . size ( ) . expandedTo ( QSize ( minimumWidth , 0 ) ) ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
}
}
QList < QMdiSubWindow * > subWindows = mdiArea . subWindowList ( ) ;
QCOMPARE ( subWindows . count ( ) , subWindowCount ) ;
QMdiSubWindow * testWindow = subWindows . at ( 3 ) ;
QVERIFY ( testWindow ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( testWindow ) ;
// childCount
QVERIFY ( interface ) ;
QCOMPARE ( interface - > childCount ( ) , 1 ) ;
// setText / text
2011-10-22 20:38:14 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Name ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > setWindowTitle ( QLatin1String ( " ReplaceMe " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Name ) , QLatin1String ( " ReplaceMe " ) ) ;
interface - > setText ( QAccessible : : Name , QLatin1String ( " TitleSetOnWindow " ) ) ;
QCOMPARE ( interface - > text ( QAccessible : : Name ) , QLatin1String ( " TitleSetOnWindow " ) ) ;
2011-04-27 10:05:43 +00:00
mdiArea . setActiveSubWindow ( testWindow ) ;
// state
2012-01-05 12:57:33 +00:00
QAccessible : : State state ;
state . focusable = true ;
state . focused = true ;
state . movable = true ;
state . sizeable = true ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > state ( ) , state ) ;
2011-04-27 10:05:43 +00:00
const QRect originalGeometry = testWindow - > geometry ( ) ;
testWindow - > showMaximized ( ) ;
2012-01-05 12:57:33 +00:00
state . sizeable = false ;
state . movable = false ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > state ( ) , state ) ;
2011-04-27 10:05:43 +00:00
testWindow - > showNormal ( ) ;
testWindow - > move ( - 10 , 0 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . offscreen ) ;
2011-04-27 10:05:43 +00:00
testWindow - > setVisible ( false ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . invisible ) ;
2011-04-27 10:05:43 +00:00
testWindow - > setVisible ( true ) ;
testWindow - > setEnabled ( false ) ;
2012-01-05 17:03:04 +00:00
QVERIFY ( interface - > state ( ) . disabled ) ;
2011-04-27 10:05:43 +00:00
testWindow - > setEnabled ( true ) ;
qApp - > setActiveWindow ( & mdiArea ) ;
mdiArea . setActiveSubWindow ( testWindow ) ;
testWindow - > setFocus ( ) ;
QVERIFY ( testWindow - > isAncestorOf ( qApp - > focusWidget ( ) ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( interface - > state ( ) . focused ) ;
2011-04-27 10:05:43 +00:00
testWindow - > setGeometry ( originalGeometry ) ;
// rect
const QPoint globalPos = testWindow - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > rect ( ) , QRect ( globalPos , testWindow - > size ( ) ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > hide ( ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > rect ( ) , QRect ( ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( childRect ( interface ) , QRect ( ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > showMinimized ( ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( childRect ( interface ) , QRect ( ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > showNormal ( ) ;
testWindow - > widget ( ) - > hide ( ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( childRect ( interface ) , QRect ( ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > widget ( ) - > show ( ) ;
const QRect widgetGeometry = testWindow - > contentsRect ( ) ;
const QPoint globalWidgetPos = QPoint ( globalPos . x ( ) + widgetGeometry . x ( ) ,
globalPos . y ( ) + widgetGeometry . y ( ) ) ;
2012-04-17 14:15:16 +00:00
# ifdef Q_OS_MAC
2012-10-16 14:53:09 +00:00
QSKIP ( " QTBUG-22812 " ) ;
2012-04-17 14:15:16 +00:00
# endif
2011-10-22 20:38:14 +00:00
QCOMPARE ( childRect ( interface ) , QRect ( globalWidgetPos , widgetGeometry . size ( ) ) ) ;
2011-04-27 10:05:43 +00:00
// childAt
2011-11-22 17:08:05 +00:00
QCOMPARE ( interface - > childAt ( - 10 , 0 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QCOMPARE ( interface - > childAt ( globalPos . x ( ) , globalPos . y ( ) ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
QAccessibleInterface * child = interface - > childAt ( globalWidgetPos . x ( ) , globalWidgetPos . y ( ) ) ;
QCOMPARE ( child - > role ( ) , QAccessible : : PushButton ) ;
QCOMPARE ( child - > text ( QAccessible : : Name ) , QString ( " QAccessibilityTest " ) ) ;
2011-04-27 10:05:43 +00:00
testWindow - > widget ( ) - > hide ( ) ;
2011-11-22 17:08:05 +00:00
QCOMPARE ( interface - > childAt ( globalWidgetPos . x ( ) , globalWidgetPos . y ( ) ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
2011-04-27 10:05:43 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : lineEditTest ( )
{
2012-01-30 17:52:46 +00:00
QWidget * toplevel = new QWidget ;
{
2011-04-27 10:05:43 +00:00
QLineEdit * le = new QLineEdit ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface ( QAccessible : : queryAccessibleInterface ( le ) ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( iface ) ;
le - > show ( ) ;
QApplication : : processEvents ( ) ;
QCOMPARE ( iface - > childCount ( ) , 0 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( iface - > state ( ) . sizeable ) ;
QVERIFY ( iface - > state ( ) . movable ) ;
2012-01-18 17:23:43 +00:00
QVERIFY ( iface - > state ( ) . focusable ) ;
2014-05-30 12:13:30 +00:00
QVERIFY ( ! iface - > state ( ) . selectable ) ;
QVERIFY ( iface - > state ( ) . selectableText ) ;
2014-04-23 12:56:35 +00:00
QVERIFY ( ! iface - > state ( ) . hasPopup ) ;
2012-01-05 12:57:33 +00:00
QCOMPARE ( bool ( iface - > state ( ) . focused ) , le - > hasFocus ( ) ) ;
2011-04-27 10:05:43 +00:00
QString secret ( QLatin1String ( " secret " ) ) ;
le - > setText ( secret ) ;
le - > setEchoMode ( QLineEdit : : Normal ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( iface - > state ( ) . passwordEdit ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , secret ) ;
2011-04-27 10:05:43 +00:00
le - > setEchoMode ( QLineEdit : : NoEcho ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( iface - > state ( ) . passwordEdit ) ;
2014-06-27 13:05:16 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
le - > setEchoMode ( QLineEdit : : Password ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( iface - > state ( ) . passwordEdit ) ;
2014-06-27 13:05:16 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , QString ( secret . length ( ) , QLatin1Char ( ' * ' ) ) ) ;
2011-04-27 10:05:43 +00:00
le - > setEchoMode ( QLineEdit : : PasswordEchoOnEdit ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( iface - > state ( ) . passwordEdit ) ;
2014-06-27 13:05:16 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , QString ( secret . length ( ) , QLatin1Char ( ' * ' ) ) ) ;
2011-04-27 10:05:43 +00:00
le - > setEchoMode ( QLineEdit : : Normal ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( iface - > state ( ) . passwordEdit ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , secret ) ;
2011-04-27 10:05:43 +00:00
le - > setParent ( toplevel ) ;
toplevel - > show ( ) ;
QApplication : : processEvents ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( iface - > state ( ) . sizeable ) ) ;
QVERIFY ( ! ( iface - > state ( ) . movable ) ) ;
2012-01-18 17:23:43 +00:00
QVERIFY ( iface - > state ( ) . focusable ) ;
2014-05-30 12:13:30 +00:00
QVERIFY ( ! iface - > state ( ) . selectable ) ;
QVERIFY ( ! iface - > state ( ) . selected ) ;
QVERIFY ( iface - > state ( ) . selectableText ) ;
2014-04-23 12:56:35 +00:00
QVERIFY ( ! iface - > state ( ) . hasPopup ) ;
2012-01-05 12:57:33 +00:00
QCOMPARE ( bool ( iface - > state ( ) . focused ) , le - > hasFocus ( ) ) ;
2011-04-27 10:05:43 +00:00
QLineEdit * le2 = new QLineEdit ( toplevel ) ;
le2 - > show ( ) ;
QTest : : qWait ( 100 ) ;
le2 - > activateWindow ( ) ;
QTest : : qWait ( 100 ) ;
le - > setFocus ( Qt : : TabFocusReason ) ;
QTestAccessibility : : clearEvents ( ) ;
le2 - > setFocus ( Qt : : TabFocusReason ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent ev ( le2 , QAccessible : : Focus ) ;
2012-03-12 14:36:31 +00:00
QTRY_VERIFY ( QTestAccessibility : : containsEvent ( & ev ) ) ;
2011-06-03 18:44:37 +00:00
le - > setText ( QLatin1String ( " 500 " ) ) ;
le - > setValidator ( new QIntValidator ( ) ) ;
2011-10-22 20:38:14 +00:00
iface - > setText ( QAccessible : : Value , QLatin1String ( " This text is not a number " ) ) ;
2011-06-03 18:44:37 +00:00
QCOMPARE ( le - > text ( ) , QLatin1String ( " 500 " ) ) ;
2011-04-27 10:05:43 +00:00
delete le ;
delete le2 ;
2012-01-30 17:52:46 +00:00
}
2011-07-05 15:05:11 +00:00
2012-01-30 17:52:46 +00:00
{
// Text interface to get the current text
2011-07-05 15:05:11 +00:00
QString cite = " I always pass on good advice. It is the only thing to do with it. It is never of any use to oneself. --Oscar Wilde " ;
QLineEdit * le3 = new QLineEdit ( cite , toplevel ) ;
2012-01-30 17:52:46 +00:00
le3 - > show ( ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface ( QAccessible : : queryAccessibleInterface ( le3 ) ) ;
2011-07-05 15:05:11 +00:00
QAccessibleTextInterface * textIface = iface - > textInterface ( ) ;
le3 - > deselect ( ) ;
2012-01-30 17:52:46 +00:00
QTestAccessibility : : clearEvents ( ) ;
2011-07-05 15:05:11 +00:00
le3 - > setCursorPosition ( 3 ) ;
QCOMPARE ( textIface - > cursorPosition ( ) , 3 ) ;
2012-01-30 17:52:46 +00:00
2012-03-12 18:43:03 +00:00
QAccessibleTextCursorEvent caretEvent ( le3 , 3 ) ;
2012-03-12 14:36:31 +00:00
QTRY_VERIFY ( QTestAccessibility : : containsEvent ( & caretEvent ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( textIface - > selectionCount ( ) , 0 ) ;
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
2011-07-05 15:05:11 +00:00
2011-06-27 14:28:50 +00:00
int start , end ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( textIface - > text ( 0 , 8 ) , QString : : fromLatin1 ( " I always " ) ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 0 , QAccessible : : CharBoundary , & start , & end ) , QString : : fromLatin1 ( " I " ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 0 ) ;
QCOMPARE ( end , 1 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textBeforeOffset ( 0 , QAccessible : : CharBoundary , & start , & end ) , QString ( ) ) ;
QCOMPARE ( textIface - > textAfterOffset ( 0 , QAccessible : : CharBoundary , & start , & end ) , QString : : fromLatin1 ( " " ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 1 ) ;
QCOMPARE ( end , 2 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : CharBoundary , & start , & end ) , QString : : fromLatin1 ( " a " ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 5 ) ;
QCOMPARE ( end , 6 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textBeforeOffset ( 5 , QAccessible : : CharBoundary , & start , & end ) , QString : : fromLatin1 ( " w " ) ) ;
QCOMPARE ( textIface - > textAfterOffset ( 5 , QAccessible : : CharBoundary , & start , & end ) , QString : : fromLatin1 ( " y " ) ) ;
2011-07-05 15:05:11 +00:00
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " always " ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 2 ) ;
QCOMPARE ( end , 8 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 2 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " always " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 7 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " always " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 8 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 25 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " advice " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 92 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " oneself " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 101 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " . -- " ) ) ;
2011-07-05 15:05:11 +00:00
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textBeforeOffset ( 5 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " " ) ) ;
QCOMPARE ( textIface - > textAfterOffset ( 5 , QAccessible : : WordBoundary , & start , & end ) , QString : : fromLatin1 ( " " ) ) ;
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : SentenceBoundary , & start , & end ) , QString : : fromLatin1 ( " I always pass on good advice. " ) ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 0 ) ;
QCOMPARE ( end , 30 ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textBeforeOffset ( 40 , QAccessible : : SentenceBoundary , & start , & end ) , QString : : fromLatin1 ( " I always pass on good advice. " ) ) ;
QCOMPARE ( textIface - > textAfterOffset ( 5 , QAccessible : : SentenceBoundary , & start , & end ) , QString : : fromLatin1 ( " It is the only thing to do with it. " ) ) ;
2011-07-05 15:05:11 +00:00
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : ParagraphBoundary , & start , & end ) , cite ) ;
2011-07-05 15:05:11 +00:00
QCOMPARE ( start , 0 ) ;
QCOMPARE ( end , cite . length ( ) ) ;
2013-03-05 13:37:37 +00:00
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : LineBoundary , & start , & end ) , cite ) ;
QCOMPARE ( textIface - > textAtOffset ( 5 , QAccessible : : NoBoundary , & start , & end ) , cite ) ;
2011-07-05 15:05:11 +00:00
2012-01-30 17:52:46 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
2012-08-14 10:47:48 +00:00
{
QLineEdit le ( QStringLiteral ( " My characters have geometries. " ) , toplevel ) ;
// characterRect()
le . show ( ) ;
2015-08-24 11:35:22 +00:00
QTest : : qWaitForWindowExposed ( & le ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface ( QAccessible : : queryAccessibleInterface ( & le ) ) ;
2012-08-14 10:47:48 +00:00
QAccessibleTextInterface * textIface = iface - > textInterface ( ) ;
QVERIFY ( textIface ) ;
const QRect lineEditRect = iface - > rect ( ) ;
// Only first 10 characters, check if they are within the bounds of line edit
for ( int i = 0 ; i < 10 ; + + i ) {
QVERIFY ( lineEditRect . contains ( textIface - > characterRect ( i ) ) ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
2012-01-30 17:52:46 +00:00
{
// Test events: cursor movement, selection, text changes
QString text = " Hello, world " ;
QLineEdit * lineEdit = new QLineEdit ( text , toplevel ) ;
lineEdit - > show ( ) ;
QTestAccessibility : : clearEvents ( ) ;
// cursor
lineEdit - > setCursorPosition ( 5 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextCursorEvent cursorEvent ( lineEdit , 5 ) ;
2012-01-30 17:52:46 +00:00
QVERIFY_EVENT ( & cursorEvent ) ;
lineEdit - > setCursorPosition ( 0 ) ;
cursorEvent . setCursorPosition ( 0 ) ;
QVERIFY_EVENT ( & cursorEvent ) ;
// selection
lineEdit - > setSelection ( 2 , 4 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextSelectionEvent sel ( lineEdit , 2 , 2 + 4 ) ;
2012-01-30 17:52:46 +00:00
QVERIFY_EVENT ( & sel ) ;
lineEdit - > selectAll ( ) ;
sel . setSelection ( 0 , lineEdit - > text ( ) . length ( ) ) ;
sel . setCursorPosition ( lineEdit - > text ( ) . length ( ) ) ;
QVERIFY_EVENT ( & sel ) ;
lineEdit - > setSelection ( 10 , - 4 ) ;
QCOMPARE ( lineEdit - > cursorPosition ( ) , 6 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextSelectionEvent sel2 ( lineEdit , 6 , 10 ) ;
2012-01-30 17:52:46 +00:00
sel2 . setCursorPosition ( 6 ) ;
QVERIFY_EVENT ( & sel2 ) ;
lineEdit - > deselect ( ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextSelectionEvent sel3 ( lineEdit , - 1 , - 1 ) ;
2012-01-30 17:52:46 +00:00
sel3 . setCursorPosition ( 6 ) ;
QVERIFY_EVENT ( & sel3 ) ;
// editing
lineEdit - > clear ( ) ;
// FIXME: improve redundant updates
2012-03-12 18:43:03 +00:00
QAccessibleTextRemoveEvent remove ( lineEdit , 0 , text ) ;
2012-01-30 17:52:46 +00:00
QVERIFY_EVENT ( & remove ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextSelectionEvent noSel ( lineEdit , - 1 , - 1 ) ;
2012-01-30 17:52:46 +00:00
QVERIFY_EVENT ( & noSel ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextCursorEvent cursor ( lineEdit , 0 ) ;
2012-01-30 17:52:46 +00:00
QVERIFY_EVENT ( & cursor ) ;
lineEdit - > setText ( " foo " ) ;
cursorEvent . setCursorPosition ( 3 ) ;
QVERIFY_EVENT ( & cursorEvent ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextInsertEvent e ( lineEdit , 0 , " foo " ) ;
2012-01-30 17:52:46 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & e ) ) ;
lineEdit - > setText ( " bar " ) ;
2012-03-12 18:43:03 +00:00
QAccessibleTextUpdateEvent update ( lineEdit , 0 , " foo " , " bar " ) ;
2012-01-30 17:52:46 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & update ) ) ;
2012-03-14 13:01:54 +00:00
// FIXME check what extra events are around and get rid of them
QTestAccessibility : : clearEvents ( ) ;
QTestEventList keys ;
keys . addKeyClick ( ' D ' ) ;
keys . simulate ( lineEdit ) ;
QAccessibleTextInsertEvent insertD ( lineEdit , 3 , " D " ) ;
QVERIFY_EVENT ( & insertD ) ;
keys . clear ( ) ;
keys . addKeyClick ( ' E ' ) ;
keys . simulate ( lineEdit ) ;
QAccessibleTextInsertEvent insertE ( lineEdit , 4 , " E " ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & insertE ) ) ;
keys . clear ( ) ;
keys . addKeyClick ( Qt : : Key_Left ) ;
keys . addKeyClick ( Qt : : Key_Left ) ;
keys . simulate ( lineEdit ) ;
cursorEvent . setCursorPosition ( 4 ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & cursorEvent ) ) ;
cursorEvent . setCursorPosition ( 3 ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & cursorEvent ) ) ;
keys . clear ( ) ;
keys . addKeyClick ( ' C ' ) ;
keys . simulate ( lineEdit ) ;
QAccessibleTextInsertEvent insertC ( lineEdit , 3 , " C " ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & insertC ) ) ;
keys . clear ( ) ;
keys . addKeyClick ( ' O ' ) ;
keys . simulate ( lineEdit ) ;
QAccessibleTextInsertEvent insertO ( lineEdit , 4 , " O " ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & insertO ) ) ;
2012-01-30 17:52:46 +00:00
}
2011-07-05 15:05:11 +00:00
delete toplevel ;
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
2011-04-27 10:05:43 +00:00
}
2014-06-25 13:27:56 +00:00
void tst_QAccessibility : : lineEditTextFunctions_data ( )
{
QTest : : addColumn < QString > ( " text " ) ;
QTest : : addColumn < int > ( " textFunction " ) ; // before = 0, at = 1, after = 2
QTest : : addColumn < int > ( " boundaryType " ) ;
QTest : : addColumn < int > ( " cursorPosition " ) ;
QTest : : addColumn < int > ( " offset " ) ;
QTest : : addColumn < int > ( " expectedStart " ) ;
QTest : : addColumn < int > ( " expectedEnd " ) ;
QTest : : addColumn < QString > ( " expectedText " ) ;
// -2 gives cursor position, -1 is length
// invalid positions will return empty strings and either -1 and -1 or both the cursor position, both is fine
QTest : : newRow ( " char before -2 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 2 < < 2 < < 3 < < " l " ;
QTest : : newRow ( " char at -2 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 2 < < 3 < < 4 < < " l " ;
QTest : : newRow ( " char after -2 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 2 < < 4 < < 5 < < " o " ;
QTest : : newRow ( " char before -1 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 1 < < 4 < < 5 < < " o " ;
QTest : : newRow ( " char at -1 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 1 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char after -1 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < - 1 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char before 0 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 0 < < 0 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char at 0 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 0 < < 0 < < 0 < < 1 < < " h " ;
QTest : : newRow ( " char after 0 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 0 < < 0 < < 1 < < 2 < < " e " ;
QTest : : newRow ( " char before 1 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < 1 < < 0 < < 1 < < " h " ;
QTest : : newRow ( " char at 1 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < 1 < < 1 < < 2 < < " e " ;
QTest : : newRow ( " char after 1 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < 1 < < 2 < < 3 < < " l " ;
QTest : : newRow ( " char before 4 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < 4 < < 3 < < 4 < < " l " ;
QTest : : newRow ( " char at 4 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < 4 < < 4 < < 5 < < " o " ;
QTest : : newRow ( " char after 4 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < 4 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char before 5 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < 5 < < 4 < < 5 < < " o " ;
QTest : : newRow ( " char at 5 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < 5 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char after 5 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < 5 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char before 6 " ) < < " hello " < < 0 < < ( int ) QAccessible : : CharBoundary < < 3 < < 6 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char at 6 " ) < < " hello " < < 1 < < ( int ) QAccessible : : CharBoundary < < 3 < < 6 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " char after 6 " ) < < " hello " < < 2 < < ( int ) QAccessible : : CharBoundary < < 3 < < 6 < < - 1 < < - 1 < < " " ;
for ( int i = - 2 ; i < 6 ; + + i ) {
2015-10-20 14:09:41 +00:00
const QByteArray iB = QByteArray : : number ( i ) ;
QTest : : newRow ( ( " line before " + iB ) . constData ( ) )
< < " hello " < < 0 < < ( int ) QAccessible : : LineBoundary < < 3 < < i < < - 1 < < - 1 < < " " ;
QTest : : newRow ( ( " line at " + iB ) . constData ( ) )
< < " hello " < < 1 < < ( int ) QAccessible : : LineBoundary < < 3 < < i < < 0 < < 5 < < " hello " ;
QTest : : newRow ( ( " line after " + iB ) . constData ( ) )
< < " hello " < < 2 < < ( int ) QAccessible : : LineBoundary < < 3 < < i < < - 1 < < - 1 < < " " ;
2014-06-25 13:27:56 +00:00
}
}
void tst_QAccessibility : : lineEditTextFunctions ( )
{
{
QFETCH ( QString , text ) ;
QFETCH ( int , textFunction ) ;
QFETCH ( int , boundaryType ) ;
QFETCH ( int , cursorPosition ) ;
QFETCH ( int , offset ) ;
QFETCH ( int , expectedStart ) ;
QFETCH ( int , expectedEnd ) ;
QFETCH ( QString , expectedText ) ;
QLineEdit le ;
le . show ( ) ;
le . setText ( text ) ;
le . setCursorPosition ( cursorPosition ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & le ) ;
QVERIFY ( iface ) ;
QAccessibleTextInterface * textIface = iface - > textInterface ( ) ;
QVERIFY ( textIface ) ;
int start = - 33 ;
int end = - 33 ;
QString result ;
switch ( textFunction ) {
case 0 :
result = textIface - > textBeforeOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
case 1 :
result = textIface - > textAtOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
case 2 :
result = textIface - > textAfterOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
}
QCOMPARE ( result , expectedText ) ;
QCOMPARE ( start , expectedStart ) ;
QCOMPARE ( end , expectedEnd ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
2014-07-03 09:19:21 +00:00
void tst_QAccessibility : : textInterfaceTest_data ( )
{
lineEditTextFunctions_data ( ) ;
QString hello = QStringLiteral ( " hello \n world \n end " ) ;
QTest : : newRow ( " multi line at 0 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 0 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line at 1 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 1 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line at 2 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 2 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line at 5 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 5 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line at 6 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 6 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line at 7 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line at 8 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 8 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line at 10 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 10 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line at 11 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 11 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line at 12 " ) < < hello < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 12 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line before 0 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 0 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " multi line before 1 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 1 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " multi line before 2 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 2 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " multi line before 5 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 5 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " multi line before 6 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 6 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line before 7 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line before 8 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 8 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line before 10 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 10 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line before 11 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 11 < < 0 < < 6 < < " hello \n " ;
QTest : : newRow ( " multi line before 12 " ) < < hello < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 12 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line after 0 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 0 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line after 1 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 1 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line after 2 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 2 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line after 5 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 5 < < 6 < < 12 < < " world \n " ;
QTest : : newRow ( " multi line after 6 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 6 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line after 7 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line after 8 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 8 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line after 10 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 10 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line after 11 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 11 < < 12 < < 15 < < " end " ;
QTest : : newRow ( " multi line after 12 " ) < < hello < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 12 < < - 1 < < - 1 < < " " ;
QTest : : newRow ( " before 4 \\ nFoo \\ n " ) < < QStringLiteral ( " \n Foo \n " ) < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 4 < < 0 < < 1 < < " \n " ;
QTest : : newRow ( " at 4 \\ nFoo \\ n " ) < < QStringLiteral ( " \n Foo \n " ) < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 4 < < 1 < < 5 < < " Foo \n " ;
QTest : : newRow ( " after 4 \\ nFoo \\ n " ) < < QStringLiteral ( " \n Foo \n " ) < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 4 < < 5 < < 5 < < " " ;
QTest : : newRow ( " before 4 Foo \\ nBar \\ n " ) < < QStringLiteral ( " Foo \n Bar \n " ) < < 0 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 0 < < 4 < < " Foo \n " ;
QTest : : newRow ( " at 4 Foo \\ nBar \\ n " ) < < QStringLiteral ( " Foo \n Bar \n " ) < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 4 < < 8 < < " Bar \n " ;
QTest : : newRow ( " after 4 Foo \\ nBar \\ n " ) < < QStringLiteral ( " Foo \n Bar \n " ) < < 2 < < ( int ) QAccessible : : LineBoundary < < 0 < < 7 < < 8 < < 8 < < " " ;
QTest : : newRow ( " at 0 Foo \\ n " ) < < QStringLiteral ( " Foo \n " ) < < 1 < < ( int ) QAccessible : : LineBoundary < < 0 < < 0 < < 0 < < 4 < < " Foo \n " ;
}
void tst_QAccessibility : : textInterfaceTest ( )
{
QFETCH ( QString , text ) ;
QFETCH ( int , textFunction ) ;
QFETCH ( int , boundaryType ) ;
QFETCH ( int , cursorPosition ) ;
QFETCH ( int , offset ) ;
QFETCH ( int , expectedStart ) ;
QFETCH ( int , expectedEnd ) ;
QFETCH ( QString , expectedText ) ;
QAccessible : : installFactory ( CustomTextWidgetIface : : ifaceFactory ) ;
CustomTextWidget * w = new CustomTextWidget ( ) ;
w - > text = text ;
w - > cursorPosition = cursorPosition ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( w ) ;
QVERIFY ( iface ) ;
QCOMPARE ( iface - > text ( QAccessible : : Value ) , text ) ;
QAccessibleTextInterface * textIface = iface - > textInterface ( ) ;
QVERIFY ( textIface ) ;
int start = - 33 ;
int end = - 33 ;
QString result ;
switch ( textFunction ) {
case 0 :
result = textIface - > textBeforeOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
case 1 :
result = textIface - > textAtOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
case 2 :
result = textIface - > textAfterOffset ( offset , ( QAccessible : : TextBoundaryType ) boundaryType , & start , & end ) ;
break ;
}
QCOMPARE ( result , expectedText ) ;
QCOMPARE ( start , expectedStart ) ;
QCOMPARE ( end , expectedEnd ) ;
delete w ;
QAccessible : : removeFactory ( CustomTextWidgetIface : : ifaceFactory ) ;
QTestAccessibility : : clearEvents ( ) ;
}
2012-02-13 13:05:51 +00:00
void tst_QAccessibility : : groupBoxTest ( )
{
{
QGroupBox * groupBox = new QGroupBox ( ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( groupBox ) ;
groupBox - > setTitle ( QLatin1String ( " Test QGroupBox " ) ) ;
QAccessibleEvent ev ( groupBox , QAccessible : : NameChanged ) ;
QVERIFY_EVENT ( & ev ) ;
groupBox - > setToolTip ( QLatin1String ( " This group box will be used to test accessibility " ) ) ;
QVBoxLayout * layout = new QVBoxLayout ( ) ;
QRadioButton * rbutton = new QRadioButton ( ) ;
layout - > addWidget ( rbutton ) ;
groupBox - > setLayout ( layout ) ;
QAccessibleInterface * rButtonIface = QAccessible : : queryAccessibleInterface ( rbutton ) ;
QCOMPARE ( iface - > childCount ( ) , 1 ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : Grouping ) ;
QCOMPARE ( iface - > text ( QAccessible : : Name ) , QLatin1String ( " Test QGroupBox " ) ) ;
QCOMPARE ( iface - > text ( QAccessible : : Description ) , QLatin1String ( " This group box will be used to test accessibility " ) ) ;
QVector < QPair < QAccessibleInterface * , QAccessible : : Relation > > relations = rButtonIface - > relations ( ) ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( relations . size ( ) , 1 ) ;
2012-02-13 13:05:51 +00:00
QPair < QAccessibleInterface * , QAccessible : : Relation > relation = relations . first ( ) ;
QCOMPARE ( relation . first - > object ( ) , groupBox ) ;
QCOMPARE ( relation . second , QAccessible : : Label ) ;
delete groupBox ;
}
{
QGroupBox * groupBox = new QGroupBox ( ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( groupBox ) ;
QVERIFY ( ! iface - > state ( ) . checkable ) ;
groupBox - > setCheckable ( true ) ;
groupBox - > setChecked ( false ) ;
QAccessible : : State st ;
st . checked = true ;
QAccessibleStateChangeEvent ev ( groupBox , st ) ;
QVERIFY_EVENT ( & ev ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : CheckBox ) ;
QAccessibleActionInterface * actionIface = iface - > actionInterface ( ) ;
QVERIFY ( actionIface ) ;
QAccessible : : State state = iface - > state ( ) ;
QVERIFY ( state . checkable ) ;
QVERIFY ( ! state . checked ) ;
2012-05-22 07:15:38 +00:00
QVERIFY ( actionIface - > actionNames ( ) . contains ( QAccessibleActionInterface : : toggleAction ( ) ) ) ;
actionIface - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
2012-02-13 13:05:51 +00:00
QVERIFY ( groupBox - > isChecked ( ) ) ;
state = iface - > state ( ) ;
QVERIFY ( state . checked ) ;
QAccessibleStateChangeEvent ev2 ( groupBox , st ) ;
QVERIFY_EVENT ( & ev2 ) ;
delete groupBox ;
}
}
2012-01-05 08:51:20 +00:00
bool accessibleInterfaceLeftOf ( const QAccessibleInterface * a1 , const QAccessibleInterface * a2 )
{
return a1 - > rect ( ) . x ( ) < a2 - > rect ( ) . x ( ) ;
}
bool accessibleInterfaceAbove ( const QAccessibleInterface * a1 , const QAccessibleInterface * a2 )
{
return a1 - > rect ( ) . y ( ) < a2 - > rect ( ) . y ( ) ;
}
2011-04-27 10:05:43 +00:00
void tst_QAccessibility : : dialogButtonBoxTest ( )
{
{
QDialogButtonBox box ( QDialogButtonBox : : Reset |
QDialogButtonBox : : Help |
QDialogButtonBox : : Ok , Qt : : Horizontal ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & box ) ;
QVERIFY ( iface ) ;
box . show ( ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
QApplication : : processEvents ( ) ;
QCOMPARE ( iface - > childCount ( ) , 3 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : Grouping ) ;
2011-04-27 10:05:43 +00:00
QStringList actualOrder ;
QAccessibleInterface * child ;
2011-10-04 12:20:05 +00:00
child = iface - > child ( 0 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child - > role ( ) , QAccessible : : PushButton ) ;
2012-01-05 08:51:20 +00:00
QVector < QAccessibleInterface * > buttons ;
for ( int i = 0 ; i < iface - > childCount ( ) ; + + i )
buttons < < iface - > child ( i ) ;
2014-02-18 08:33:36 +00:00
std : : sort ( buttons . begin ( ) , buttons . end ( ) , accessibleInterfaceLeftOf ) ;
2012-01-05 08:51:20 +00:00
for ( int i = 0 ; i < buttons . count ( ) ; + + i )
actualOrder < < buttons . at ( i ) - > text ( QAccessible : : Name ) ;
2011-04-27 10:05:43 +00:00
QStringList expectedOrder ;
QDialogButtonBox : : ButtonLayout btnlout =
QDialogButtonBox : : ButtonLayout ( QApplication : : style ( ) - > styleHint ( QStyle : : SH_DialogButtonLayout ) ) ;
switch ( btnlout ) {
case QDialogButtonBox : : WinLayout :
expectedOrder < < QDialogButtonBox : : tr ( " Reset " )
< < QDialogButtonBox : : tr ( " OK " )
< < QDialogButtonBox : : tr ( " Help " ) ;
break ;
case QDialogButtonBox : : GnomeLayout :
case QDialogButtonBox : : KdeLayout :
case QDialogButtonBox : : MacLayout :
expectedOrder < < QDialogButtonBox : : tr ( " Help " )
< < QDialogButtonBox : : tr ( " Reset " )
< < QDialogButtonBox : : tr ( " OK " ) ;
break ;
}
QCOMPARE ( actualOrder , expectedOrder ) ;
QApplication : : processEvents ( ) ;
QTestAccessibility : : clearEvents ( ) ;
}
{
QDialogButtonBox box ( QDialogButtonBox : : Reset |
QDialogButtonBox : : Help |
QDialogButtonBox : : Ok , Qt : : Horizontal ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( & box ) ;
2011-04-27 10:05:43 +00:00
// Test up and down navigation
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & box ) ;
QVERIFY ( iface ) ;
box . setOrientation ( Qt : : Vertical ) ;
box . show ( ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
QApplication : : processEvents ( ) ;
QStringList actualOrder ;
2012-01-05 08:51:20 +00:00
QVector < QAccessibleInterface * > buttons ;
for ( int i = 0 ; i < iface - > childCount ( ) ; + + i )
buttons < < iface - > child ( i ) ;
2014-02-18 08:33:36 +00:00
std : : sort ( buttons . begin ( ) , buttons . end ( ) , accessibleInterfaceAbove ) ;
2012-01-05 08:51:20 +00:00
for ( int i = 0 ; i < buttons . count ( ) ; + + i )
actualOrder < < buttons . at ( i ) - > text ( QAccessible : : Name ) ;
2011-04-27 10:05:43 +00:00
QStringList expectedOrder ;
expectedOrder < < QDialogButtonBox : : tr ( " OK " )
< < QDialogButtonBox : : tr ( " Reset " )
< < QDialogButtonBox : : tr ( " Help " ) ;
QCOMPARE ( actualOrder , expectedOrder ) ;
QApplication : : processEvents ( ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : dialTest ( )
{
{
QDial dial ;
2012-12-18 14:22:48 +00:00
setFrameless ( & dial ) ;
2011-09-23 08:28:51 +00:00
dial . setMinimum ( 23 ) ;
dial . setMaximum ( 121 ) ;
dial . setValue ( 42 ) ;
QCOMPARE ( dial . value ( ) , 42 ) ;
2011-04-27 10:05:43 +00:00
dial . show ( ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & dial ) ;
QVERIFY ( interface ) ;
2011-09-23 08:28:51 +00:00
QCOMPARE ( interface - > childCount ( ) , 0 ) ;
2011-04-27 10:05:43 +00:00
2012-09-13 09:14:13 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( & dial ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( interface - > text ( QAccessible : : Value ) , QString : : number ( dial . value ( ) ) ) ;
2011-09-23 08:28:51 +00:00
QCOMPARE ( interface - > rect ( ) , dial . geometry ( ) ) ;
2011-04-27 10:05:43 +00:00
2011-09-23 08:28:51 +00:00
QAccessibleValueInterface * valueIface = interface - > valueInterface ( ) ;
QVERIFY ( valueIface ! = 0 ) ;
QCOMPARE ( valueIface - > minimumValue ( ) . toInt ( ) , dial . minimum ( ) ) ;
QCOMPARE ( valueIface - > maximumValue ( ) . toInt ( ) , dial . maximum ( ) ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , 42 ) ;
dial . setValue ( 50 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , dial . value ( ) ) ;
dial . setValue ( 0 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , dial . value ( ) ) ;
dial . setValue ( 100 ) ;
QCOMPARE ( valueIface - > currentValue ( ) . toInt ( ) , dial . value ( ) ) ;
valueIface - > setCurrentValue ( 77 ) ;
QCOMPARE ( 77 , dial . value ( ) ) ;
2011-04-27 10:05:43 +00:00
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : rubberBandTest ( )
{
QRubberBand rubberBand ( QRubberBand : : Rectangle ) ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & rubberBand ) ;
QVERIFY ( interface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : Border ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : abstractScrollAreaTest ( )
{
{
QAbstractScrollArea abstractScrollArea ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & abstractScrollArea ) ;
QVERIFY ( interface ) ;
2011-10-05 07:40:04 +00:00
QVERIFY ( ! interface - > rect ( ) . isValid ( ) ) ;
2011-11-22 17:08:05 +00:00
QCOMPARE ( interface - > childAt ( 200 , 200 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
2011-04-27 10:05:43 +00:00
abstractScrollArea . resize ( 400 , 400 ) ;
abstractScrollArea . show ( ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
const QRect globalGeometry = QRect ( abstractScrollArea . mapToGlobal ( QPoint ( 0 , 0 ) ) ,
abstractScrollArea . size ( ) ) ;
// Viewport.
QCOMPARE ( interface - > childCount ( ) , 1 ) ;
QWidget * viewport = abstractScrollArea . viewport ( ) ;
QVERIFY ( viewport ) ;
2012-01-09 12:13:33 +00:00
QVERIFY ( verifyChild ( viewport , interface , 0 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
// Horizontal scrollBar.
abstractScrollArea . setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
QWidget * horizontalScrollBar = abstractScrollArea . horizontalScrollBar ( ) ;
2014-10-23 15:44:57 +00:00
// On OS X >= 10.9 the scrollbar will be hidden unless explicitly enabled in the preferences
bool scrollBarsVisible = ! horizontalScrollBar - > style ( ) - > styleHint ( QStyle : : SH_ScrollBar_Transient , 0 , horizontalScrollBar ) ;
int childCount = scrollBarsVisible ? 2 : 1 ;
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QWidget * horizontalScrollBarContainer = horizontalScrollBar - > parentWidget ( ) ;
2014-10-23 15:44:57 +00:00
if ( scrollBarsVisible )
QVERIFY ( verifyChild ( horizontalScrollBarContainer , interface , 1 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
// Horizontal scrollBar widgets.
QLabel * secondLeftLabel = new QLabel ( QLatin1String ( " L2 " ) ) ;
abstractScrollArea . addScrollBarWidget ( secondLeftLabel , Qt : : AlignLeft ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * firstLeftLabel = new QLabel ( QLatin1String ( " L1 " ) ) ;
abstractScrollArea . addScrollBarWidget ( firstLeftLabel , Qt : : AlignLeft ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * secondRightLabel = new QLabel ( QLatin1String ( " R2 " ) ) ;
abstractScrollArea . addScrollBarWidget ( secondRightLabel , Qt : : AlignRight ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * firstRightLabel = new QLabel ( QLatin1String ( " R1 " ) ) ;
abstractScrollArea . addScrollBarWidget ( firstRightLabel , Qt : : AlignRight ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
// Vertical scrollBar.
abstractScrollArea . setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
2014-10-23 15:44:57 +00:00
if ( scrollBarsVisible )
+ + childCount ;
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QWidget * verticalScrollBar = abstractScrollArea . verticalScrollBar ( ) ;
QWidget * verticalScrollBarContainer = verticalScrollBar - > parentWidget ( ) ;
2014-10-23 15:44:57 +00:00
if ( scrollBarsVisible )
QVERIFY ( verifyChild ( verticalScrollBarContainer , interface , 2 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
// Vertical scrollBar widgets.
QLabel * secondTopLabel = new QLabel ( QLatin1String ( " T2 " ) ) ;
abstractScrollArea . addScrollBarWidget ( secondTopLabel , Qt : : AlignTop ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * firstTopLabel = new QLabel ( QLatin1String ( " T1 " ) ) ;
abstractScrollArea . addScrollBarWidget ( firstTopLabel , Qt : : AlignTop ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * secondBottomLabel = new QLabel ( QLatin1String ( " B2 " ) ) ;
abstractScrollArea . addScrollBarWidget ( secondBottomLabel , Qt : : AlignBottom ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QLabel * firstBottomLabel = new QLabel ( QLatin1String ( " B1 " ) ) ;
abstractScrollArea . addScrollBarWidget ( firstBottomLabel , Qt : : AlignBottom ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
// CornerWidget.
2014-10-23 15:44:57 +00:00
+ + childCount ;
2011-04-27 10:05:43 +00:00
abstractScrollArea . setCornerWidget ( new QLabel ( QLatin1String ( " C " ) ) ) ;
2014-10-23 15:44:57 +00:00
QCOMPARE ( interface - > childCount ( ) , childCount ) ;
2011-04-27 10:05:43 +00:00
QWidget * cornerWidget = abstractScrollArea . cornerWidget ( ) ;
2014-10-23 15:44:57 +00:00
if ( scrollBarsVisible )
QVERIFY ( verifyChild ( cornerWidget , interface , 3 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
QCOMPARE ( verifyHierarchy ( interface ) , 0 ) ;
}
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : scrollAreaTest ( )
{
{
QScrollArea scrollArea ;
scrollArea . show ( ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & scrollArea ) ;
QVERIFY ( interface ) ;
QCOMPARE ( interface - > childCount ( ) , 1 ) ; // The viewport.
}
QTestAccessibility : : clearEvents ( ) ;
}
2011-12-01 20:21:52 +00:00
void tst_QAccessibility : : listTest ( )
2011-06-27 14:28:50 +00:00
{
2011-12-08 13:10:46 +00:00
{
2011-06-27 14:28:50 +00:00
QListWidget * listView = new QListWidget ;
listView - > addItem ( " Oslo " ) ;
listView - > addItem ( " Berlin " ) ;
listView - > addItem ( " Brisbane " ) ;
listView - > resize ( 400 , 400 ) ;
listView - > show ( ) ;
QTest : : qWait ( 1 ) ; // Need this for indexOfchild to work.
2011-09-13 13:55:41 +00:00
QCoreApplication : : processEvents ( ) ;
2011-06-27 14:28:50 +00:00
QTest : : qWait ( 100 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( listView ) ;
QCOMPARE ( verifyHierarchy ( iface ) , 0 ) ;
2011-06-27 14:28:50 +00:00
2011-10-05 07:40:04 +00:00
QCOMPARE ( ( int ) iface - > role ( ) , ( int ) QAccessible : : List ) ;
2011-06-27 14:28:50 +00:00
QCOMPARE ( iface - > childCount ( ) , 3 ) ;
2011-12-08 13:10:46 +00:00
{
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child1 = iface - > child ( 0 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( child1 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( child1 ) , 0 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child1 - > text ( QAccessible : : Name ) , QString ( " Oslo " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( child1 - > role ( ) , QAccessible : : ListItem ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child2 = iface - > child ( 1 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( child2 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( child2 ) , 1 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child2 - > text ( QAccessible : : Name ) , QString ( " Berlin " ) ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child3 = iface - > child ( 2 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( child3 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( child3 ) , 2 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child3 - > text ( QAccessible : : Name ) , QString ( " Brisbane " ) ) ;
2011-12-08 13:10:46 +00:00
}
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
// Check for events
QTest : : mouseClick ( listView - > viewport ( ) , Qt : : LeftButton , 0 , listView - > visualItemRect ( listView - > item ( 1 ) ) . center ( ) ) ;
2014-07-01 13:39:32 +00:00
QAccessibleEvent selectionEvent ( listView , QAccessible : : SelectionAdd ) ;
2012-09-22 21:19:44 +00:00
selectionEvent . setChild ( 1 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent focusEvent ( listView , QAccessible : : Focus ) ;
2012-09-22 21:19:44 +00:00
focusEvent . setChild ( 1 ) ;
2012-03-12 18:43:03 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & selectionEvent ) ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & focusEvent ) ) ;
2011-06-27 14:28:50 +00:00
QTest : : mouseClick ( listView - > viewport ( ) , Qt : : LeftButton , 0 , listView - > visualItemRect ( listView - > item ( 2 ) ) . center ( ) ) ;
2012-03-12 18:43:03 +00:00
2014-07-01 13:39:32 +00:00
QAccessibleEvent selectionEvent2 ( listView , QAccessible : : SelectionAdd ) ;
2012-09-22 21:19:44 +00:00
selectionEvent2 . setChild ( 2 ) ;
2012-03-12 18:43:03 +00:00
QAccessibleEvent focusEvent2 ( listView , QAccessible : : Focus ) ;
2012-09-22 21:19:44 +00:00
focusEvent2 . setChild ( 2 ) ;
2012-03-12 18:43:03 +00:00
QVERIFY ( QTestAccessibility : : containsEvent ( & selectionEvent2 ) ) ;
QVERIFY ( QTestAccessibility : : containsEvent ( & focusEvent2 ) ) ;
2011-06-27 14:28:50 +00:00
listView - > addItem ( " Munich " ) ;
QCOMPARE ( iface - > childCount ( ) , 4 ) ;
// table 2
2011-12-01 20:21:52 +00:00
QAccessibleTableInterface * table2 = iface - > tableInterface ( ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( table2 ) ;
QCOMPARE ( table2 - > columnCount ( ) , 1 ) ;
QCOMPARE ( table2 - > rowCount ( ) , 4 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell1 = table2 - > cellAt ( 0 , 0 ) ;
2011-12-08 13:10:46 +00:00
QVERIFY ( cell1 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell1 - > text ( QAccessible : : Name ) , QString ( " Oslo " ) ) ;
2011-12-08 13:10:46 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell4 = table2 - > cellAt ( 3 , 0 ) ;
2011-12-08 13:10:46 +00:00
QVERIFY ( cell4 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell4 - > text ( QAccessible : : Name ) , QString ( " Munich " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cell4 - > role ( ) , QAccessible : : ListItem ) ;
2011-11-29 13:07:46 +00:00
2011-12-01 20:21:52 +00:00
QAccessibleTableCellInterface * cellInterface = cell4 - > tableCellInterface ( ) ;
2011-11-29 13:07:46 +00:00
QVERIFY ( cellInterface ) ;
QCOMPARE ( cellInterface - > rowIndex ( ) , 3 ) ;
QCOMPARE ( cellInterface - > columnIndex ( ) , 0 ) ;
2011-12-08 13:10:46 +00:00
QCOMPARE ( cellInterface - > rowExtent ( ) , 1 ) ;
QCOMPARE ( cellInterface - > columnExtent ( ) , 1 ) ;
QCOMPARE ( cellInterface - > rowHeaderCells ( ) , QList < QAccessibleInterface * > ( ) ) ;
QCOMPARE ( cellInterface - > columnHeaderCells ( ) , QList < QAccessibleInterface * > ( ) ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( cellInterface - > table ( ) - > object ( ) , listView ) ;
2011-12-08 13:10:46 +00:00
listView - > clearSelection ( ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( cell4 - > state ( ) . expandable ) ) ;
QVERIFY ( ( cell4 - > state ( ) . selectable ) ) ;
QVERIFY ( ! ( cell4 - > state ( ) . selected ) ) ;
2011-12-08 13:10:46 +00:00
table2 - > selectRow ( 3 ) ;
QCOMPARE ( listView - > selectedItems ( ) . size ( ) , 1 ) ;
QCOMPARE ( listView - > selectedItems ( ) . at ( 0 ) - > text ( ) , QLatin1String ( " Munich " ) ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( cell4 - > state ( ) . selected ) ;
2011-12-08 13:10:46 +00:00
QVERIFY ( cellInterface - > isSelected ( ) ) ;
QVERIFY ( table2 - > cellAt ( - 1 , 0 ) = = 0 ) ;
QVERIFY ( table2 - > cellAt ( 0 , - 1 ) = = 0 ) ;
QVERIFY ( table2 - > cellAt ( 0 , 1 ) = = 0 ) ;
QVERIFY ( table2 - > cellAt ( 4 , 0 ) = = 0 ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
// verify that unique id stays the same
QAccessible : : Id axidMunich = QAccessible : : uniqueId ( cell4 ) ;
// insertion and deletion of items
listView - > insertItem ( 1 , " Helsinki " ) ;
// list: Oslo, Helsinki, Berlin, Brisbane, Munich
QAccessibleInterface * cellMunich2 = table2 - > cellAt ( 4 , 0 ) ;
QCOMPARE ( cell4 , cellMunich2 ) ;
QCOMPARE ( axidMunich , QAccessible : : uniqueId ( cellMunich2 ) ) ;
delete listView - > takeItem ( 2 ) ;
delete listView - > takeItem ( 2 ) ;
// list: Oslo, Helsinki, Munich
QAccessibleInterface * cellMunich3 = table2 - > cellAt ( 2 , 0 ) ;
QCOMPARE ( cell4 , cellMunich3 ) ;
QCOMPARE ( axidMunich , QAccessible : : uniqueId ( cellMunich3 ) ) ;
2016-10-21 15:14:31 +00:00
delete listView - > takeItem ( 2 ) ;
// list: Oslo, Helsinki
// verify that it doesn't return an invalid item from the cache
QVERIFY ( table2 - > cellAt ( 2 , 0 ) = = 0 ) ;
2013-01-03 16:18:40 +00:00
2011-06-27 14:28:50 +00:00
delete listView ;
2011-12-08 13:10:46 +00:00
}
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
2011-12-01 20:21:52 +00:00
void tst_QAccessibility : : treeTest ( )
2011-06-27 14:28:50 +00:00
{
QTreeWidget * treeView = new QTreeWidget ;
2013-01-18 09:40:38 +00:00
// Empty model (do not crash, etc)
treeView - > setColumnCount ( 0 ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( treeView ) ;
QCOMPARE ( iface - > child ( 0 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
2011-06-27 14:28:50 +00:00
treeView - > setColumnCount ( 2 ) ;
QTreeWidgetItem * header = new QTreeWidgetItem ;
header - > setText ( 0 , " Artist " ) ;
header - > setText ( 1 , " Work " ) ;
treeView - > setHeaderItem ( header ) ;
QTreeWidgetItem * root1 = new QTreeWidgetItem ;
root1 - > setText ( 0 , " Spain " ) ;
treeView - > addTopLevelItem ( root1 ) ;
QTreeWidgetItem * item1 = new QTreeWidgetItem ;
item1 - > setText ( 0 , " Picasso " ) ;
item1 - > setText ( 1 , " Guernica " ) ;
root1 - > addChild ( item1 ) ;
QTreeWidgetItem * item2 = new QTreeWidgetItem ;
item2 - > setText ( 0 , " Tapies " ) ;
item2 - > setText ( 1 , " Ambrosia " ) ;
root1 - > addChild ( item2 ) ;
QTreeWidgetItem * root2 = new QTreeWidgetItem ;
root2 - > setText ( 0 , " Austria " ) ;
treeView - > addTopLevelItem ( root2 ) ;
QTreeWidgetItem * item3 = new QTreeWidgetItem ;
item3 - > setText ( 0 , " Klimt " ) ;
item3 - > setText ( 1 , " The Kiss " ) ;
root2 - > addChild ( item3 ) ;
treeView - > resize ( 400 , 400 ) ;
treeView - > show ( ) ;
2011-09-15 19:41:54 +00:00
2011-09-13 13:55:41 +00:00
QCoreApplication : : processEvents ( ) ;
2011-06-27 14:28:50 +00:00
QTest : : qWait ( 100 ) ;
QCOMPARE ( verifyHierarchy ( iface ) , 0 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( ( int ) iface - > role ( ) , ( int ) QAccessible : : Tree ) ;
2011-06-27 14:28:50 +00:00
// header and 2 rows (the others are not expanded, thus not visible)
QCOMPARE ( iface - > childCount ( ) , 6 ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * header1 = iface - > child ( 0 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( header1 ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( header1 ) , 0 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( header1 - > text ( QAccessible : : Name ) , QString ( " Artist " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( header1 - > role ( ) , QAccessible : : ColumnHeader ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child1 = iface - > child ( 2 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( child1 ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( child1 ) , 2 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child1 - > text ( QAccessible : : Name ) , QString ( " Spain " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( child1 - > role ( ) , QAccessible : : TreeItem ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( child1 - > state ( ) . expanded ) ) ;
2011-06-27 14:28:50 +00:00
QAccessibleInterface * child2 = 0 ;
2011-10-04 12:20:05 +00:00
child2 = iface - > child ( 4 ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( child2 ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( child2 ) , 4 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( child2 - > text ( QAccessible : : Name ) , QString ( " Austria " ) ) ;
2011-06-27 14:28:50 +00:00
2013-09-11 09:09:40 +00:00
bool headerHidden = true ;
do {
treeView - > setHeaderHidden ( headerHidden ) ;
header1 = iface - > child ( 0 ) ;
QCOMPARE ( header1 - > role ( ) , QAccessible : : ColumnHeader ) ;
QCOMPARE ( ! ! header1 - > state ( ) . invisible , headerHidden ) ;
QCOMPARE ( header1 - > text ( QAccessible : : Name ) , QStringLiteral ( " Artist " ) ) ;
header1 = iface - > child ( 1 ) ;
QCOMPARE ( header1 - > role ( ) , QAccessible : : ColumnHeader ) ;
QCOMPARE ( ! ! header1 - > state ( ) . invisible , headerHidden ) ;
QCOMPARE ( header1 - > text ( QAccessible : : Name ) , QStringLiteral ( " Work " ) ) ;
QAccessibleInterface * accSpain = iface - > child ( 2 ) ;
QCOMPARE ( accSpain - > role ( ) , QAccessible : : TreeItem ) ;
QCOMPARE ( iface - > indexOfChild ( accSpain ) , 2 ) ;
headerHidden = ! headerHidden ;
} while ( ! headerHidden ) ;
2013-04-25 13:11:47 +00:00
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
// table 2
2011-12-01 20:21:52 +00:00
QAccessibleTableInterface * table2 = iface - > tableInterface ( ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( table2 ) ;
QCOMPARE ( table2 - > columnCount ( ) , 2 ) ;
QCOMPARE ( table2 - > rowCount ( ) , 2 ) ;
2017-01-16 16:38:45 +00:00
QAccessibleInterface * cell1 = table2 - > cellAt ( 0 , 0 ) ;
QVERIFY ( cell1 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell1 - > text ( QAccessible : : Name ) , QString ( " Spain " ) ) ;
2017-01-16 16:38:45 +00:00
QAccessibleInterface * cell2 = table2 - > cellAt ( 1 , 0 ) ;
QVERIFY ( cell2 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell2 - > text ( QAccessible : : Name ) , QString ( " Austria " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cell2 - > role ( ) , QAccessible : : TreeItem ) ;
2011-12-01 20:21:52 +00:00
QCOMPARE ( cell2 - > tableCellInterface ( ) - > rowIndex ( ) , 1 ) ;
QCOMPARE ( cell2 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( cell2 - > state ( ) . expandable ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( cell2 ) , 4 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( cell2 - > state ( ) . expanded ) ) ;
2011-06-27 14:28:50 +00:00
QCOMPARE ( table2 - > columnDescription ( 1 ) , QString ( " Work " ) ) ;
treeView - > expandAll ( ) ;
2011-09-15 19:41:54 +00:00
// Need this for indexOfchild to work.
2011-09-13 13:55:41 +00:00
QCoreApplication : : processEvents ( ) ;
2011-06-27 14:28:50 +00:00
QTest : : qWait ( 100 ) ;
QCOMPARE ( table2 - > columnCount ( ) , 2 ) ;
QCOMPARE ( table2 - > rowCount ( ) , 5 ) ;
cell1 = table2 - > cellAt ( 1 , 0 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell1 - > text ( QAccessible : : Name ) , QString ( " Picasso " ) ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( cell1 ) , 4 ) ; // 2 header + 2 for root item
2011-06-27 14:28:50 +00:00
cell2 = table2 - > cellAt ( 4 , 0 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell2 - > text ( QAccessible : : Name ) , QString ( " Klimt " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cell2 - > role ( ) , QAccessible : : TreeItem ) ;
2011-12-01 20:21:52 +00:00
QCOMPARE ( cell2 - > tableCellInterface ( ) - > rowIndex ( ) , 4 ) ;
QCOMPARE ( cell2 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
2012-01-05 12:57:33 +00:00
QVERIFY ( ! ( cell2 - > state ( ) . expandable ) ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( cell2 ) , 10 ) ;
2011-06-27 14:28:50 +00:00
2012-10-15 12:22:25 +00:00
QPoint pos = treeView - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
QModelIndex index = treeView - > model ( ) - > index ( 0 , 0 , treeView - > model ( ) - > index ( 1 , 0 ) ) ;
pos + = treeView - > visualRect ( index ) . center ( ) ;
pos + = QPoint ( 0 , treeView - > header ( ) - > height ( ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * childAt2 ( iface - > childAt ( pos . x ( ) , pos . y ( ) ) ) ;
2012-10-15 12:22:25 +00:00
QVERIFY ( childAt2 ) ;
QCOMPARE ( childAt2 - > text ( QAccessible : : Name ) , QString ( " Klimt " ) ) ;
2011-06-27 14:28:50 +00:00
QCOMPARE ( table2 - > columnDescription ( 0 ) , QString ( " Artist " ) ) ;
QCOMPARE ( table2 - > columnDescription ( 1 ) , QString ( " Work " ) ) ;
2012-10-15 12:22:25 +00:00
delete treeView ;
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
2012-10-15 12:22:25 +00:00
// The table used below is this:
// Button (0) | h1 (1) | h2 (2) | h3 (3)
// v1 (4) | 0.0 (5) | 1.0 (6) | 2.0 (7)
// v2 (8) | 0.1 (9) | 1.1 (10) | 2.1 (11)
// v3 (12) | 0.2 (13) | 1.2 (14) | 2.2 (15)
2011-12-01 20:21:52 +00:00
void tst_QAccessibility : : tableTest ( )
2011-06-27 14:28:50 +00:00
{
QTableWidget * tableView = new QTableWidget ( 3 , 3 ) ;
tableView - > setColumnCount ( 3 ) ;
QStringList hHeader ;
hHeader < < " h1 " < < " h2 " < < " h3 " ;
tableView - > setHorizontalHeaderLabels ( hHeader ) ;
QStringList vHeader ;
vHeader < < " v1 " < < " v2 " < < " v3 " ;
tableView - > setVerticalHeaderLabels ( vHeader ) ;
for ( int i = 0 ; i < 9 ; + + i ) {
QTableWidgetItem * item = new QTableWidgetItem ;
item - > setText ( QString : : number ( i / 3 ) + QString ( " . " ) + QString : : number ( i % 3 ) ) ;
tableView - > setItem ( i / 3 , i % 3 , item ) ;
}
tableView - > resize ( 600 , 600 ) ;
tableView - > show ( ) ;
2012-10-15 11:44:40 +00:00
QTest : : qWaitForWindowExposed ( tableView ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( tableView ) ;
QCOMPARE ( verifyHierarchy ( iface ) , 0 ) ;
2011-06-27 14:28:50 +00:00
2012-10-15 11:44:40 +00:00
QCOMPARE ( iface - > role ( ) , QAccessible : : Table ) ;
2011-06-27 14:28:50 +00:00
// header and 2 rows (the others are not expanded, thus not visible)
QCOMPARE ( iface - > childCount ( ) , 9 + 3 + 3 + 1 ) ; // cell+headers+topleft button
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cornerButton ( iface - > child ( 0 ) ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( cornerButton ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( cornerButton ) , 0 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cornerButton - > role ( ) , QAccessible : : Pane ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * h2 ( iface - > child ( 2 ) ) ;
2012-10-15 12:22:25 +00:00
QVERIFY ( h2 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( h2 ) , 2 ) ;
2012-10-15 12:22:25 +00:00
QCOMPARE ( h2 - > text ( QAccessible : : Name ) , QString ( " h2 " ) ) ;
QCOMPARE ( h2 - > role ( ) , QAccessible : : ColumnHeader ) ;
QVERIFY ( ! ( h2 - > state ( ) . expanded ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * v3 ( iface - > child ( 12 ) ) ;
2012-10-15 12:22:25 +00:00
QVERIFY ( v3 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( v3 ) , 12 ) ;
2012-10-15 12:22:25 +00:00
QCOMPARE ( v3 - > text ( QAccessible : : Name ) , QString ( " v3 " ) ) ;
QCOMPARE ( v3 - > role ( ) , QAccessible : : RowHeader ) ;
QVERIFY ( ! ( v3 - > state ( ) . expanded ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child10 ( iface - > child ( 10 ) ) ;
2012-10-15 12:22:25 +00:00
QVERIFY ( child10 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( child10 ) , 10 ) ;
2012-10-15 12:22:25 +00:00
QCOMPARE ( child10 - > text ( QAccessible : : Name ) , QString ( " 1.1 " ) ) ;
QAccessibleTableCellInterface * cell10Iface = child10 - > tableCellInterface ( ) ;
QCOMPARE ( cell10Iface - > rowIndex ( ) , 1 ) ;
QCOMPARE ( cell10Iface - > columnIndex ( ) , 1 ) ;
QPoint pos = tableView - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
pos + = tableView - > visualRect ( tableView - > model ( ) - > index ( 1 , 1 ) ) . center ( ) ;
pos + = QPoint ( tableView - > verticalHeader ( ) - > width ( ) , tableView - > horizontalHeader ( ) - > height ( ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * childAt10 ( iface - > childAt ( pos . x ( ) , pos . y ( ) ) ) ;
2012-10-15 12:22:25 +00:00
QCOMPARE ( childAt10 - > text ( QAccessible : : Name ) , QString ( " 1.1 " ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * child11 ( iface - > child ( 11 ) ) ;
QCOMPARE ( iface - > indexOfChild ( child11 ) , 11 ) ;
2012-10-15 12:22:25 +00:00
QCOMPARE ( child11 - > text ( QAccessible : : Name ) , QString ( " 1.2 " ) ) ;
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
// table 2
2011-12-01 20:21:52 +00:00
QAccessibleTableInterface * table2 = iface - > tableInterface ( ) ;
2011-06-27 14:28:50 +00:00
QVERIFY ( table2 ) ;
QCOMPARE ( table2 - > columnCount ( ) , 3 ) ;
QCOMPARE ( table2 - > rowCount ( ) , 3 ) ;
2017-01-16 16:38:45 +00:00
QAccessibleInterface * cell1 = table2 - > cellAt ( 0 , 0 ) ;
QVERIFY ( cell1 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell1 - > text ( QAccessible : : Name ) , QString ( " 0.0 " ) ) ;
2012-01-09 12:13:33 +00:00
QCOMPARE ( iface - > indexOfChild ( cell1 ) , 5 ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell2 ( table2 - > cellAt ( 0 , 1 ) ) ;
2012-10-15 11:44:40 +00:00
QVERIFY ( cell2 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell2 - > text ( QAccessible : : Name ) , QString ( " 0.1 " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cell2 - > role ( ) , QAccessible : : Cell ) ;
2011-12-01 20:21:52 +00:00
QCOMPARE ( cell2 - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell2 - > tableCellInterface ( ) - > columnIndex ( ) , 1 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( cell2 ) , 6 ) ;
2011-06-27 14:28:50 +00:00
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell3 ( table2 - > cellAt ( 1 , 2 ) ) ;
2012-10-15 11:44:40 +00:00
QVERIFY ( cell3 ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( cell3 - > text ( QAccessible : : Name ) , QString ( " 1.2 " ) ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( cell3 - > role ( ) , QAccessible : : Cell ) ;
2011-12-01 20:21:52 +00:00
QCOMPARE ( cell3 - > tableCellInterface ( ) - > rowIndex ( ) , 1 ) ;
QCOMPARE ( cell3 - > tableCellInterface ( ) - > columnIndex ( ) , 2 ) ;
2013-01-03 16:18:40 +00:00
QCOMPARE ( iface - > indexOfChild ( cell3 ) , 11 ) ;
2011-06-27 14:28:50 +00:00
QCOMPARE ( table2 - > columnDescription ( 0 ) , QString ( " h1 " ) ) ;
QCOMPARE ( table2 - > columnDescription ( 1 ) , QString ( " h2 " ) ) ;
QCOMPARE ( table2 - > columnDescription ( 2 ) , QString ( " h3 " ) ) ;
QCOMPARE ( table2 - > rowDescription ( 0 ) , QString ( " v1 " ) ) ;
QCOMPARE ( table2 - > rowDescription ( 1 ) , QString ( " v2 " ) ) ;
QCOMPARE ( table2 - > rowDescription ( 2 ) , QString ( " v3 " ) ) ;
2012-09-24 12:16:16 +00:00
tableView - > clearSelection ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
QVERIFY ( ! table2 - > selectRow ( 0 ) ) ;
QVERIFY ( ! table2 - > isRowSelected ( 0 ) ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
QVERIFY ( table2 - > selectRow ( 0 ) ) ;
QVERIFY ( table2 - > selectRow ( 1 ) ) ;
QVERIFY ( ! table2 - > isRowSelected ( 0 ) ) ;
tableView - > setSelectionMode ( QAbstractItemView : : MultiSelection ) ;
QVERIFY ( table2 - > selectRow ( 0 ) ) ;
QVERIFY ( table2 - > isRowSelected ( 1 ) ) ;
QVERIFY ( table2 - > unselectRow ( 0 ) ) ;
QVERIFY ( ! table2 - > isRowSelected ( 0 ) ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectColumns ) ;
QVERIFY ( ! table2 - > selectRow ( 0 ) ) ;
QVERIFY ( ! table2 - > isRowSelected ( 0 ) ) ;
tableView - > clearSelection ( ) ;
QCOMPARE ( table2 - > selectedColumnCount ( ) , 0 ) ;
QCOMPARE ( table2 - > selectedRowCount ( ) , 0 ) ;
QVERIFY ( table2 - > selectColumn ( 1 ) ) ;
QVERIFY ( table2 - > isColumnSelected ( 1 ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionMode ( QAbstractItemView : : ContiguousSelection ) ;
table2 - > selectColumn ( 0 ) ;
table2 - > selectColumn ( 2 ) ;
QVERIFY ( ! ( table2 - > isColumnSelected ( 2 ) & & table2 - > isColumnSelected ( 0 ) ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
tableView - > setSelectionMode ( QAbstractItemView : : MultiSelection ) ;
table2 - > selectColumn ( 1 ) ;
table2 - > selectRow ( 1 ) ;
QVERIFY ( table2 - > isColumnSelected ( 1 ) ) ;
QVERIFY ( table2 - > isRowSelected ( 1 ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell4 = table2 - > cellAt ( 2 , 2 ) ;
2012-09-24 09:42:33 +00:00
QVERIFY ( cell1 - > actionInterface ( ) ) ;
QVERIFY ( cell1 - > tableCellInterface ( ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
QVERIFY ( ! cell1 - > tableCellInterface ( ) - > isSelected ( ) ) ;
QVERIFY ( cell1 - > actionInterface ( ) - > actionNames ( ) . contains ( QAccessibleActionInterface : : toggleAction ( ) ) ) ;
cell1 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( cell2 - > tableCellInterface ( ) - > isSelected ( ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectColumns ) ;
cell3 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( cell4 - > tableCellInterface ( ) - > isSelected ( ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
cell1 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( cell1 - > tableCellInterface ( ) - > isSelected ( ) ) ;
cell2 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( ! cell1 - > tableCellInterface ( ) - > isSelected ( ) ) ;
tableView - > clearSelection ( ) ;
tableView - > setSelectionMode ( QAbstractItemView : : MultiSelection ) ;
cell1 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
cell2 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( cell1 - > tableCellInterface ( ) - > isSelected ( ) ) ;
QVERIFY ( cell2 - > tableCellInterface ( ) - > isSelected ( ) ) ;
cell2 - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : toggleAction ( ) ) ;
QVERIFY ( cell1 - > tableCellInterface ( ) - > isSelected ( ) ) ;
QVERIFY ( ! cell2 - > tableCellInterface ( ) - > isSelected ( ) ) ;
2013-01-03 16:18:40 +00:00
QAccessibleInterface * cell00 = table2 - > cellAt ( 0 , 0 ) ;
QAccessible : : Id id00 = QAccessible : : uniqueId ( cell00 ) ;
QVERIFY ( id00 ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
QAccessibleInterface * cell01 = table2 - > cellAt ( 0 , 1 ) ;
QAccessibleInterface * cell02 = table2 - > cellAt ( 0 , 2 ) ;
QAccessible : : Id id02 = QAccessible : : uniqueId ( cell02 ) ;
QVERIFY ( id02 ) ;
QCOMPARE ( cell02 - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell02 - > tableCellInterface ( ) - > columnIndex ( ) , 2 ) ;
QAccessibleInterface * cell20 = table2 - > cellAt ( 2 , 0 ) ;
QAccessible : : Id id20 = QAccessible : : uniqueId ( cell20 ) ;
QVERIFY ( id20 ) ;
QCOMPARE ( cell20 - > tableCellInterface ( ) - > rowIndex ( ) , 2 ) ;
QCOMPARE ( cell20 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
QAccessibleInterface * cell22 = table2 - > cellAt ( 2 , 2 ) ;
QAccessible : : Id id22 = QAccessible : : uniqueId ( cell22 ) ;
QVERIFY ( id22 ) ;
QCOMPARE ( cell22 - > tableCellInterface ( ) - > rowIndex ( ) , 2 ) ;
QCOMPARE ( cell22 - > tableCellInterface ( ) - > columnIndex ( ) , 2 ) ;
// modification: inserting and removing rows/columns
tableView - > insertRow ( 2 ) ;
// Button (0) | h1 (1) | h2 (2) | h3 (3)
// v1 (4) | 0.0 (5) | 1.0 (6) | 2.0 (7)
// v2 (8) | 0.1 (9) | 1.1 (10) | 2.1 (11)
// new (12) | (13) | (14) | (15)
// v3 (16) | 0.2 (17) | 1.2 (18) | 2.2 (19)
QAccessibleInterface * cell00_new = table2 - > cellAt ( 0 , 0 ) ;
QCOMPARE ( cell00 , cell00_new ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
QAccessibleInterface * cell02_new = table2 - > cellAt ( 0 , 2 ) ;
QCOMPARE ( cell02 , cell02_new ) ;
QCOMPARE ( cell02_new - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell02_new - > tableCellInterface ( ) - > columnIndex ( ) , 2 ) ;
QAccessibleInterface * cell20_new = table2 - > cellAt ( 2 , 0 ) ;
QAccessibleInterface * cell30_new = table2 - > cellAt ( 3 , 0 ) ;
QAccessible : : Id id20_new = QAccessible : : uniqueId ( cell20_new ) ;
QVERIFY ( id20_new ! = id20 ) ;
QAccessible : : Id id30_new = QAccessible : : uniqueId ( cell30_new ) ;
QCOMPARE ( id20 , id30_new ) ;
QCOMPARE ( cell20 - > tableCellInterface ( ) - > rowIndex ( ) , 3 ) ;
QCOMPARE ( cell20 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
QAccessibleInterface * cell22_new = table2 - > cellAt ( 2 , 2 ) ;
QAccessibleInterface * cell32_new = table2 - > cellAt ( 3 , 2 ) ;
QAccessible : : Id id22_new = QAccessible : : uniqueId ( cell22_new ) ;
QVERIFY ( id22_new ! = id22 ) ;
QAccessible : : Id id32_new = QAccessible : : uniqueId ( cell32_new ) ;
QCOMPARE ( id22 , id32_new ) ;
QCOMPARE ( cell32_new - > tableCellInterface ( ) - > rowIndex ( ) , 3 ) ;
QCOMPARE ( cell32_new - > tableCellInterface ( ) - > columnIndex ( ) , 2 ) ;
QVERIFY ( table2 - > cellAt ( 0 , 0 ) = = cell1 ) ;
tableView - > insertColumn ( 2 ) ;
// Button (0) | h1 (1) | h2 (2) | (3) | h3 (4)
// v1 (5) | 0.0 (6) | 1.0 (7) | (8) | 2.0 (9)
// v2 (10) | 0.1 (11) | 1.1 (12) | (13) | 2.1 (14)
// new (15) | (16) | (17) | (18) | (19)
// v3 (20) | 0.2 (21) | 1.2 (22) | (23) | 2.2 (24)
cell00_new = table2 - > cellAt ( 0 , 0 ) ;
QCOMPARE ( cell00 , cell00_new ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell00 - > tableCellInterface ( ) - > columnIndex ( ) , 0 ) ;
QAccessibleInterface * cell01_new = table2 - > cellAt ( 0 , 1 ) ;
QCOMPARE ( cell01 , cell01_new ) ;
QCOMPARE ( cell01_new - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell01_new - > tableCellInterface ( ) - > columnIndex ( ) , 1 ) ;
QAccessibleInterface * cell03_new = table2 - > cellAt ( 0 , 3 ) ;
QVERIFY ( cell03_new ) ;
QCOMPARE ( cell03_new - > tableCellInterface ( ) - > rowIndex ( ) , 0 ) ;
QCOMPARE ( cell03_new - > tableCellInterface ( ) - > columnIndex ( ) , 3 ) ;
QCOMPARE ( iface - > indexOfChild ( cell03_new ) , 9 ) ;
QCOMPARE ( cell03_new , cell02 ) ;
cell30_new = table2 - > cellAt ( 3 , 0 ) ;
QCOMPARE ( cell30_new , cell20 ) ;
QCOMPARE ( iface - > indexOfChild ( cell30_new ) , 21 ) ;
2011-06-27 14:28:50 +00:00
2013-09-11 09:09:40 +00:00
{
QTestAccessibility : : clearEvents ( ) ;
QModelIndex index00 = tableView - > model ( ) - > index ( 1 , 1 , tableView - > rootIndex ( ) ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
tableView - > selectionModel ( ) - > select ( index00 , QItemSelectionModel : : ClearAndSelect ) ;
2014-07-01 13:39:32 +00:00
QAccessibleEvent event ( tableView , QAccessible : : SelectionAdd ) ;
2013-09-11 09:09:40 +00:00
event . setChild ( 12 ) ;
QCOMPARE ( QTestAccessibility : : containsEvent ( & event ) , true ) ;
QTestAccessibility : : clearEvents ( ) ;
tableView - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
tableView - > selectionModel ( ) - > select ( index00 , QItemSelectionModel : : ClearAndSelect ) ;
tableView - > horizontalHeader ( ) - > setVisible ( false ) ;
}
delete tableView ;
2013-01-03 16:18:40 +00:00
QVERIFY ( ! QAccessible : : accessibleInterface ( id00 ) ) ;
2011-06-27 14:28:50 +00:00
QTestAccessibility : : clearEvents ( ) ;
2011-11-15 01:36:18 +00:00
}
2011-04-27 10:05:43 +00:00
void tst_QAccessibility : : calendarWidgetTest ( )
{
# ifndef QT_NO_CALENDARWIDGET
{
QCalendarWidget calendarWidget ;
QAccessibleInterface * interface = QAccessible : : queryAccessibleInterface ( & calendarWidget ) ;
QVERIFY ( interface ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( interface - > role ( ) , QAccessible : : Table ) ;
QVERIFY ( ! interface - > rect ( ) . isValid ( ) ) ;
2011-11-22 17:08:05 +00:00
QCOMPARE ( interface - > childAt ( 200 , 200 ) , static_cast < QAccessibleInterface * > ( 0 ) ) ;
2011-04-27 10:05:43 +00:00
calendarWidget . resize ( 400 , 300 ) ;
calendarWidget . show ( ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
QTest : : qWait ( 100 ) ;
# endif
// 1 = navigationBar, 2 = view.
QCOMPARE ( interface - > childCount ( ) , 2 ) ;
const QRect globalGeometry = QRect ( calendarWidget . mapToGlobal ( QPoint ( 0 , 0 ) ) ,
calendarWidget . size ( ) ) ;
2011-09-28 13:36:52 +00:00
QCOMPARE ( interface - > rect ( ) , globalGeometry ) ;
2011-04-27 10:05:43 +00:00
QWidget * navigationBar = 0 ;
foreach ( QObject * child , calendarWidget . children ( ) ) {
if ( child - > objectName ( ) = = QLatin1String ( " qt_calendar_navigationbar " ) ) {
navigationBar = static_cast < QWidget * > ( child ) ;
break ;
}
}
QVERIFY ( navigationBar ) ;
2012-01-09 12:13:33 +00:00
QVERIFY ( verifyChild ( navigationBar , interface , 0 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
QAbstractItemView * calendarView = 0 ;
foreach ( QObject * child , calendarWidget . children ( ) ) {
if ( child - > objectName ( ) = = QLatin1String ( " qt_calendar_calendarview " ) ) {
calendarView = static_cast < QAbstractItemView * > ( child ) ;
break ;
}
}
QVERIFY ( calendarView ) ;
2012-01-09 12:13:33 +00:00
QVERIFY ( verifyChild ( calendarView , interface , 1 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
// Hide navigation bar.
calendarWidget . setNavigationBarVisible ( false ) ;
QCOMPARE ( interface - > childCount ( ) , 1 ) ;
QVERIFY ( ! navigationBar - > isVisible ( ) ) ;
2012-01-09 12:13:33 +00:00
QVERIFY ( verifyChild ( calendarView , interface , 0 , globalGeometry ) ) ;
2011-04-27 10:05:43 +00:00
// Show navigation bar.
calendarWidget . setNavigationBarVisible ( true ) ;
QCOMPARE ( interface - > childCount ( ) , 2 ) ;
QVERIFY ( navigationBar - > isVisible ( ) ) ;
// Navigate to the navigation bar via Child.
2011-10-04 12:20:05 +00:00
QAccessibleInterface * navigationBarInterface = interface - > child ( 0 ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( navigationBarInterface ) ;
QCOMPARE ( navigationBarInterface - > object ( ) , ( QObject * ) navigationBar ) ;
// Navigate to the view via Child.
2011-10-04 12:20:05 +00:00
QAccessibleInterface * calendarViewInterface = interface - > child ( 1 ) ;
2011-04-27 10:05:43 +00:00
QVERIFY ( calendarViewInterface ) ;
QCOMPARE ( calendarViewInterface - > object ( ) , ( QObject * ) calendarView ) ;
2011-10-04 12:20:05 +00:00
QVERIFY ( ! interface - > child ( - 1 ) ) ;
2011-04-27 10:05:43 +00:00
2012-01-06 14:51:53 +00:00
// In order for geometric navigation to work they must share the same parent
QCOMPARE ( navigationBarInterface - > parent ( ) - > object ( ) , calendarViewInterface - > parent ( ) - > object ( ) ) ;
QVERIFY ( navigationBarInterface - > rect ( ) . bottom ( ) < calendarViewInterface - > rect ( ) . top ( ) ) ;
2011-04-27 10:05:43 +00:00
calendarViewInterface = 0 ;
navigationBarInterface = 0 ;
}
QTestAccessibility : : clearEvents ( ) ;
# endif // QT_NO_CALENDARWIDGET
}
void tst_QAccessibility : : dockWidgetTest ( )
{
# ifndef QT_NO_DOCKWIDGET
// Set up a proper main window with two dock widgets
QMainWindow * mw = new QMainWindow ( ) ;
QFrame * central = new QFrame ( mw ) ;
mw - > setCentralWidget ( central ) ;
QMenuBar * mb = new QMenuBar ( mw ) ;
mb - > addAction ( tr ( " &File " ) ) ;
mw - > setMenuBar ( mb ) ;
QDockWidget * dock1 = new QDockWidget ( mw ) ;
2012-10-19 13:08:42 +00:00
dock1 - > setWindowTitle ( " Dock 1 " ) ;
2011-04-27 10:05:43 +00:00
mw - > addDockWidget ( Qt : : LeftDockWidgetArea , dock1 ) ;
QPushButton * pb1 = new QPushButton ( tr ( " Push me " ) , dock1 ) ;
dock1 - > setWidget ( pb1 ) ;
QDockWidget * dock2 = new QDockWidget ( mw ) ;
2012-10-19 13:08:42 +00:00
dock2 - > setWindowTitle ( " Dock 2 " ) ;
2011-04-27 10:05:43 +00:00
mw - > addDockWidget ( Qt : : BottomDockWidgetArea , dock2 ) ;
QPushButton * pb2 = new QPushButton ( tr ( " Push me " ) , dock2 ) ;
dock2 - > setWidget ( pb2 ) ;
2012-10-19 13:08:42 +00:00
dock2 - > setFeatures ( QDockWidget : : DockWidgetClosable ) ;
2011-04-27 10:05:43 +00:00
mw - > resize ( 600 , 400 ) ;
mw - > show ( ) ;
2012-10-19 13:08:42 +00:00
QTest : : qWaitForWindowExposed ( mw ) ;
2011-04-27 10:05:43 +00:00
QAccessibleInterface * accMainWindow = QAccessible : : queryAccessibleInterface ( mw ) ;
// 4 children: menu bar, dock1, dock2, and central widget
QCOMPARE ( accMainWindow - > childCount ( ) , 4 ) ;
QAccessibleInterface * accDock1 = 0 ;
2012-10-19 13:08:42 +00:00
QAccessibleInterface * accDock2 = 0 ;
2011-10-22 20:38:14 +00:00
for ( int i = 0 ; i < 4 ; + + i ) {
2012-10-19 13:08:42 +00:00
QAccessibleInterface * child = accMainWindow - > child ( i ) ;
if ( child & & child - > object ( ) = = dock1 )
accDock1 = child ;
if ( child & & child - > object ( ) = = dock2 )
accDock2 = child ;
2011-04-27 10:05:43 +00:00
}
2012-10-19 13:08:42 +00:00
// Dock widgets consist of
// 0 contents
// 1 close button
// 2 float button
2011-04-27 10:05:43 +00:00
QVERIFY ( accDock1 ) ;
2011-10-05 07:40:04 +00:00
QCOMPARE ( accDock1 - > role ( ) , QAccessible : : Window ) ;
2012-10-19 13:08:42 +00:00
QCOMPARE ( accDock1 - > text ( QAccessible : : Name ) , dock1 - > windowTitle ( ) ) ;
QCOMPARE ( accDock1 - > childCount ( ) , 3 ) ;
QAccessibleInterface * dock1Widget = accDock1 - > child ( 0 ) ;
QCOMPARE ( dock1Widget - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock1Widget - > text ( QAccessible : : Name ) , pb1 - > text ( ) ) ;
# ifdef Q_OS_MAC
QEXPECT_FAIL ( " " , " Dock Widget geometry on Mac seems broken. " , Continue ) ;
# endif
QVERIFY ( accDock1 - > rect ( ) . contains ( dock1Widget - > rect ( ) ) ) ;
QCOMPARE ( accDock1 - > indexOfChild ( dock1Widget ) , 0 ) ;
QCOMPARE ( dock1Widget - > parent ( ) - > object ( ) , dock1 ) ;
QAccessibleInterface * dock1Close = accDock1 - > child ( 1 ) ;
QCOMPARE ( dock1Close - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock1Close - > text ( QAccessible : : Name ) , QDockWidget : : tr ( " Close " ) ) ;
QVERIFY ( accDock1 - > rect ( ) . contains ( dock1Close - > rect ( ) ) ) ;
QCOMPARE ( accDock1 - > indexOfChild ( dock1Close ) , 1 ) ;
QCOMPARE ( dock1Close - > parent ( ) - > object ( ) , dock1 ) ;
QAccessibleInterface * dock1Float = accDock1 - > child ( 2 ) ;
QCOMPARE ( dock1Float - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock1Float - > text ( QAccessible : : Name ) , QDockWidget : : tr ( " Float " ) ) ;
QVERIFY ( accDock1 - > rect ( ) . contains ( dock1Float - > rect ( ) ) ) ;
QCOMPARE ( accDock1 - > indexOfChild ( dock1Float ) , 2 ) ;
QVERIFY ( ! dock1Float - > state ( ) . invisible ) ;
QVERIFY ( accDock2 ) ;
QCOMPARE ( accDock2 - > role ( ) , QAccessible : : Window ) ;
QCOMPARE ( accDock2 - > text ( QAccessible : : Name ) , dock2 - > windowTitle ( ) ) ;
QCOMPARE ( accDock2 - > childCount ( ) , 3 ) ;
QAccessibleInterface * dock2Widget = accDock2 - > child ( 0 ) ;
QCOMPARE ( dock2Widget - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock2Widget - > text ( QAccessible : : Name ) , pb1 - > text ( ) ) ;
# ifdef Q_OS_MAC
QEXPECT_FAIL ( " " , " Dock Widget geometry on Mac seems broken. " , Continue ) ;
# endif
QVERIFY ( accDock2 - > rect ( ) . contains ( dock2Widget - > rect ( ) ) ) ;
QCOMPARE ( accDock2 - > indexOfChild ( dock2Widget ) , 0 ) ;
QAccessibleInterface * dock2Close = accDock2 - > child ( 1 ) ;
QCOMPARE ( dock2Close - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock2Close - > text ( QAccessible : : Name ) , QDockWidget : : tr ( " Close " ) ) ;
QVERIFY ( accDock2 - > rect ( ) . contains ( dock2Close - > rect ( ) ) ) ;
QCOMPARE ( accDock2 - > indexOfChild ( dock2Close ) , 1 ) ;
QVERIFY ( ! dock2Close - > state ( ) . invisible ) ;
QAccessibleInterface * dock2Float = accDock2 - > child ( 2 ) ;
QCOMPARE ( dock2Float - > role ( ) , QAccessible : : Button ) ;
QCOMPARE ( dock2Float - > text ( QAccessible : : Name ) , QDockWidget : : tr ( " Float " ) ) ;
QCOMPARE ( accDock2 - > indexOfChild ( dock2Float ) , 2 ) ;
QVERIFY ( dock2Float - > state ( ) . invisible ) ;
QPoint buttonPoint = pb2 - > mapToGlobal ( QPoint ( pb2 - > width ( ) / 2 , pb2 - > height ( ) / 2 ) ) ;
QAccessibleInterface * childAt = accDock2 - > childAt ( buttonPoint . x ( ) , buttonPoint . y ( ) ) ;
QVERIFY ( childAt ) ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( childAt - > object ( ) , pb2 ) ;
2012-10-19 13:08:42 +00:00
QWidget * close1 = qobject_cast < QWidget * > ( dock1Close - > object ( ) ) ;
QPoint close1ButtonPoint = close1 - > mapToGlobal ( QPoint ( close1 - > width ( ) / 2 , close1 - > height ( ) / 2 ) ) ;
QAccessibleInterface * childAt2 = accDock1 - > childAt ( close1ButtonPoint . x ( ) , close1ButtonPoint . y ( ) ) ;
QVERIFY ( childAt2 ) ;
2015-07-24 13:51:48 +00:00
QCOMPARE ( childAt2 - > object ( ) , close1 ) ;
2012-10-19 13:08:42 +00:00
// custom title bar widget
QDockWidget * dock3 = new QDockWidget ( mw ) ;
dock3 - > setWindowTitle ( " Dock 3 " ) ;
mw - > addDockWidget ( Qt : : LeftDockWidgetArea , dock3 ) ;
QPushButton * pb3 = new QPushButton ( tr ( " Push me " ) , dock3 ) ;
dock3 - > setWidget ( pb3 ) ;
QLabel * titleLabel = new QLabel ( " I am a title widget " ) ;
dock3 - > setTitleBarWidget ( titleLabel ) ;
QAccessibleInterface * accDock3 = accMainWindow - > child ( 4 ) ;
QVERIFY ( accDock3 ) ;
QCOMPARE ( accDock3 - > role ( ) , QAccessible : : Window ) ;
QCOMPARE ( accDock3 - > text ( QAccessible : : Name ) , dock3 - > windowTitle ( ) ) ;
QCOMPARE ( accDock3 - > childCount ( ) , 2 ) ;
QAccessibleInterface * titleWidget = accDock3 - > child ( 1 ) ;
QVERIFY ( titleWidget ) ;
QCOMPARE ( titleWidget - > text ( QAccessible : : Name ) , titleLabel - > text ( ) ) ;
QAccessibleInterface * dock3Widget = accDock3 - > child ( 0 ) ;
QCOMPARE ( dock3Widget - > text ( QAccessible : : Name ) , pb3 - > text ( ) ) ;
2011-10-22 20:38:14 +00:00
2011-04-27 10:05:43 +00:00
delete mw ;
QTestAccessibility : : clearEvents ( ) ;
# endif // QT_NO_DOCKWIDGET
}
void tst_QAccessibility : : comboBoxTest ( )
{
2011-09-15 22:40:41 +00:00
{ // not editable combobox
QComboBox combo ;
combo . addItems ( QStringList ( ) < < " one " < < " two " < < " three " ) ;
2012-10-11 12:46:16 +00:00
// Fully decorated windows have a minimum width of 160 on Windows.
combo . setMinimumWidth ( 200 ) ;
2011-09-15 22:40:41 +00:00
combo . show ( ) ;
2015-08-24 11:35:22 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( & combo ) ) ;
2012-09-13 09:14:13 +00:00
2011-09-15 22:40:41 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & combo ) ;
QCOMPARE ( verifyHierarchy ( iface ) , 0 ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : ComboBox ) ;
QCOMPARE ( iface - > childCount ( ) , 1 ) ;
# ifdef Q_OS_UNIX
2011-09-29 07:39:33 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Name ) , QLatin1String ( " one " ) ) ;
2011-09-15 22:40:41 +00:00
# endif
2011-09-29 07:39:33 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , QLatin1String ( " one " ) ) ;
2011-09-15 22:40:41 +00:00
combo . setCurrentIndex ( 2 ) ;
# ifdef Q_OS_UNIX
2011-09-29 07:39:33 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Name ) , QLatin1String ( " three " ) ) ;
2011-04-27 10:05:43 +00:00
# endif
2011-09-29 07:39:33 +00:00
QCOMPARE ( iface - > text ( QAccessible : : Value ) , QLatin1String ( " three " ) ) ;
2011-09-15 22:40:41 +00:00
QAccessibleInterface * listIface = iface - > child ( 0 ) ;
QCOMPARE ( listIface - > role ( ) , QAccessible : : List ) ;
QCOMPARE ( listIface - > childCount ( ) , 3 ) ;
2011-04-27 10:05:43 +00:00
2011-09-15 22:40:41 +00:00
QVERIFY ( ! combo . view ( ) - > isVisible ( ) ) ;
QVERIFY ( iface - > actionInterface ( ) ) ;
2014-04-22 15:40:58 +00:00
QCOMPARE ( iface - > actionInterface ( ) - > actionNames ( ) , QStringList ( ) < < QAccessibleActionInterface : : showMenuAction ( ) < < QAccessibleActionInterface : : pressAction ( ) ) ;
2011-11-01 13:36:20 +00:00
iface - > actionInterface ( ) - > doAction ( QAccessibleActionInterface : : showMenuAction ( ) ) ;
2012-10-11 12:46:16 +00:00
QTRY_VERIFY ( combo . view ( ) - > isVisible ( ) ) ;
2011-04-27 10:05:43 +00:00
}
2011-09-15 22:40:41 +00:00
{ // editable combobox
QComboBox editableCombo ;
2012-10-11 12:46:16 +00:00
editableCombo . setMinimumWidth ( 200 ) ;
2011-09-15 22:40:41 +00:00
editableCombo . show ( ) ;
editableCombo . setEditable ( true ) ;
editableCombo . addItems ( QStringList ( ) < < " foo " < < " bar " < < " baz " ) ;
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( & editableCombo ) ;
QCOMPARE ( verifyHierarchy ( iface ) , 0 ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : ComboBox ) ;
QCOMPARE ( iface - > childCount ( ) , 2 ) ;
QAccessibleInterface * listIface = iface - > child ( 0 ) ;
QCOMPARE ( listIface - > role ( ) , QAccessible : : List ) ;
QAccessibleInterface * editIface = iface - > child ( 1 ) ;
QCOMPARE ( editIface - > role ( ) , QAccessible : : EditableText ) ;
}
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : labelTest ( )
{
2013-09-25 15:09:17 +00:00
QWidget * window = new QWidget ;
2011-04-27 10:05:43 +00:00
QString text = " Hello World " ;
2013-09-25 15:09:17 +00:00
QLabel * label = new QLabel ( text , window ) ;
2012-12-18 14:22:48 +00:00
setFrameless ( label ) ;
2013-09-25 15:09:17 +00:00
QLineEdit * buddy = new QLineEdit ( window ) ;
label - > setBuddy ( buddy ) ;
window - > resize ( 320 , 200 ) ;
window - > show ( ) ;
2011-04-27 10:05:43 +00:00
2013-09-25 15:09:17 +00:00
QTest : : qWaitForWindowExposed ( window ) ;
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
# endif
QTest : : qWait ( 100 ) ;
QAccessibleInterface * acc_label = QAccessible : : queryAccessibleInterface ( label ) ;
QVERIFY ( acc_label ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( acc_label - > text ( QAccessible : : Name ) , text ) ;
2011-04-27 10:05:43 +00:00
2013-09-25 15:09:17 +00:00
QVector < QPair < QAccessibleInterface * , QAccessible : : Relation > > rels = acc_label - > relations ( ) ;
QCOMPARE ( rels . count ( ) , 1 ) ;
QAccessibleInterface * iface = rels . first ( ) . first ;
QAccessible : : Relation rel = rels . first ( ) . second ;
QCOMPARE ( rel , QAccessible : : Labelled ) ;
QCOMPARE ( iface - > role ( ) , QAccessible : : EditableText ) ;
delete window ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
QPixmap testPixmap ( 50 , 50 ) ;
testPixmap . fill ( ) ;
QLabel imageLabel ;
imageLabel . setPixmap ( testPixmap ) ;
imageLabel . setToolTip ( " Test Description " ) ;
acc_label = QAccessible : : queryAccessibleInterface ( & imageLabel ) ;
QVERIFY ( acc_label ) ;
QAccessibleImageInterface * imageInterface = acc_label - > imageInterface ( ) ;
QVERIFY ( imageInterface ) ;
QCOMPARE ( imageInterface - > imageSize ( ) , testPixmap . size ( ) ) ;
QCOMPARE ( imageInterface - > imageDescription ( ) , QString : : fromLatin1 ( " Test Description " ) ) ;
2012-03-08 09:18:58 +00:00
const QPoint labelPos = imageLabel . mapToGlobal ( QPoint ( 0 , 0 ) ) ;
2013-10-04 13:32:53 +00:00
QCOMPARE ( imageInterface - > imagePosition ( ) , labelPos ) ;
2011-04-27 10:05:43 +00:00
QTestAccessibility : : clearEvents ( ) ;
}
void tst_QAccessibility : : accelerators ( )
{
QWidget * window = new QWidget ;
QHBoxLayout * lay = new QHBoxLayout ( window ) ;
QLabel * label = new QLabel ( tr ( " &Line edit " ) , window ) ;
QLineEdit * le = new QLineEdit ( window ) ;
lay - > addWidget ( label ) ;
lay - > addWidget ( le ) ;
label - > setBuddy ( le ) ;
window - > show ( ) ;
QAccessibleInterface * accLineEdit = QAccessible : : queryAccessibleInterface ( le ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QKeySequence ( Qt : : ALT ) . toString ( QKeySequence : : NativeText ) + QLatin1String ( " L " ) ) ;
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QKeySequence ( Qt : : ALT ) . toString ( QKeySequence : : NativeText ) + QLatin1String ( " L " ) ) ;
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q & " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q && " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q && A " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q &&&A " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QKeySequence ( Qt : : ALT ) . toString ( QKeySequence : : NativeText ) + QLatin1String ( " A " ) ) ;
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q &&A " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QString ( ) ) ;
2011-04-19 06:15:57 +00:00
2012-01-16 11:02:48 +00:00
# if !defined(QT_NO_DEBUG) && !defined(Q_OS_MAC)
2011-04-19 06:15:57 +00:00
QTest : : ignoreMessage ( QtWarningMsg , " QKeySequence::mnemonic: \" Q &A&B \" contains multiple occurrences of '&' " ) ;
2011-04-20 01:39:14 +00:00
# endif
2011-04-27 10:05:43 +00:00
label - > setText ( tr ( " Q &A&B " ) ) ;
2011-10-22 20:38:14 +00:00
QCOMPARE ( accLineEdit - > text ( QAccessible : : Accelerator ) , QKeySequence ( Qt : : ALT ) . toString ( QKeySequence : : NativeText ) + QLatin1String ( " A " ) ) ;
2011-04-27 10:05:43 +00:00
2011-09-13 13:55:41 +00:00
# if defined(Q_OS_UNIX)
QCoreApplication : : processEvents ( ) ;
2011-04-27 10:05:43 +00:00
# endif
QTest : : qWait ( 100 ) ;
delete window ;
QTestAccessibility : : clearEvents ( ) ;
}
2012-03-07 10:59:30 +00:00
# ifdef QT_SUPPORTS_IACCESSIBLE2
static IUnknown * queryIA2 ( IAccessible * acc , const IID & iid )
{
IUnknown * resultInterface = 0 ;
IServiceProvider * pService = 0 ;
HRESULT hr = acc - > QueryInterface ( IID_IServiceProvider , ( void * * ) & pService ) ;
if ( SUCCEEDED ( hr ) ) {
IAccessible2 * pIA2 = 0 ;
hr = pService - > QueryService ( IID_IAccessible , IID_IAccessible2 , ( void * * ) & pIA2 ) ;
if ( SUCCEEDED ( hr ) & & pIA2 ) {
// The control supports IAccessible2.
// pIA2 is the reference to the accessible object's IAccessible2 interface.
hr = pIA2 - > QueryInterface ( iid , ( void * * ) & resultInterface ) ;
pIA2 - > Release ( ) ;
}
// The control supports IAccessible2.
pService - > Release ( ) ;
}
return resultInterface ;
}
# endif
2012-03-27 05:09:22 +00:00
void tst_QAccessibility : : bridgeTest ( )
{
// For now this is a simple test to see if the bridge is working at all.
// Ideally it should be extended to test all aspects of the bridge.
2014-01-06 20:41:17 +00:00
# if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
2012-03-27 05:09:22 +00:00
// First, test MSAA part of bridge
QWidget * window = new QWidget ;
QVBoxLayout * lay = new QVBoxLayout ( window ) ;
QPushButton * button = new QPushButton ( tr ( " Push me " ) , window ) ;
2012-03-07 10:59:30 +00:00
QTextEdit * te = new QTextEdit ( window ) ;
te - > setText ( QLatin1String ( " hello world \n how are you today? \n " ) ) ;
2012-11-01 13:32:46 +00:00
// Add QTableWidget
QTableWidget * tableWidget = new QTableWidget ( 3 , 3 , window ) ;
tableWidget - > setColumnCount ( 3 ) ;
QStringList hHeader ;
hHeader < < " h1 " < < " h2 " < < " h3 " ;
tableWidget - > setHorizontalHeaderLabels ( hHeader ) ;
QStringList vHeader ;
vHeader < < " v1 " < < " v2 " < < " v3 " ;
tableWidget - > setVerticalHeaderLabels ( vHeader ) ;
for ( int i = 0 ; i < 9 ; + + i ) {
QTableWidgetItem * item = new QTableWidgetItem ;
item - > setText ( QString : : number ( i / 3 ) + QString ( " . " ) + QString : : number ( i % 3 ) ) ;
tableWidget - > setItem ( i / 3 , i % 3 , item ) ;
}
tableWidget - > setFixedSize ( 600 , 600 ) ;
2013-09-25 15:09:17 +00:00
QLabel * label = new QLabel ( tr ( " Push my buddy " ) ) ;
label - > setBuddy ( button ) ;
2012-03-27 05:09:22 +00:00
lay - > addWidget ( button ) ;
2012-03-07 10:59:30 +00:00
lay - > addWidget ( te ) ;
2012-11-01 13:32:46 +00:00
lay - > addWidget ( tableWidget ) ;
2013-09-25 15:09:17 +00:00
lay - > addWidget ( label ) ;
2012-03-27 05:09:22 +00:00
window - > show ( ) ;
2012-07-24 12:29:01 +00:00
QVERIFY ( QTest : : qWaitForWindowExposed ( window ) ) ;
2012-03-27 05:09:22 +00:00
2012-03-07 10:59:30 +00:00
/**************************************************
* QPushButton
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-03-27 05:09:22 +00:00
QAccessibleInterface * iface = QAccessible : : queryAccessibleInterface ( button ) ;
QPoint buttonPos = button - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
QRect buttonRect = iface - > rect ( ) ;
QCOMPARE ( buttonRect . topLeft ( ) , buttonPos ) ;
// All set, now test the bridge.
POINT pt ;
pt . x = buttonRect . center ( ) . x ( ) ;
pt . y = buttonRect . center ( ) . y ( ) ;
2012-03-07 10:59:30 +00:00
IAccessible * iaccButton ;
2012-03-27 05:09:22 +00:00
VARIANT varChild ;
2012-03-07 10:59:30 +00:00
HRESULT hr = : : AccessibleObjectFromPoint ( pt , & iaccButton , & varChild ) ;
2012-03-27 05:09:22 +00:00
QVERIFY ( SUCCEEDED ( hr ) ) ;
VARIANT varSELF ;
varSELF . vt = VT_I4 ;
varSELF . lVal = 0 ;
// **** Test get_accRole ****
VARIANT varRole ;
2012-03-07 10:59:30 +00:00
hr = iaccButton - > get_accRole ( varSELF , & varRole ) ;
2012-03-27 05:09:22 +00:00
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( varRole . vt , ( VARTYPE ) VT_I4 ) ;
QCOMPARE ( varRole . lVal , ( LONG ) ROLE_SYSTEM_PUSHBUTTON ) ;
// **** Test accLocation ****
long x , y , w , h ;
2013-02-05 15:43:07 +00:00
// Do not crash on insane arguments.
varChild . lVal = 999 ;
hr = iaccButton - > accLocation ( & x , & y , & w , & h , varChild ) ;
QCOMPARE ( SUCCEEDED ( hr ) , false ) ;
2012-03-07 10:59:30 +00:00
hr = iaccButton - > accLocation ( & x , & y , & w , & h , varSELF ) ;
2012-03-27 05:09:22 +00:00
QCOMPARE ( buttonRect , QRect ( x , y , w , h ) ) ;
2012-03-07 10:59:30 +00:00
# ifdef QT_SUPPORTS_IACCESSIBLE2
2012-03-27 05:09:22 +00:00
// Test IAccessible2 part of bridge
2012-03-07 10:59:30 +00:00
if ( IAccessible2 * ia2Button = ( IAccessible2 * ) queryIA2 ( iaccButton , IID_IAccessible2 ) ) {
// The control supports IAccessible2.
// ia2Button is the reference to the accessible object's IAccessible2 interface.
/***** Test IAccessibleComponent *****/
IAccessibleComponent * ia2Component = 0 ;
hr = ia2Button - > QueryInterface ( IID_IAccessibleComponent , ( void * * ) & ia2Component ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
long x , y ;
hr = ia2Component - > get_locationInParent ( & x , & y ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( button - > pos ( ) , QPoint ( x , y ) ) ;
ia2Component - > Release ( ) ;
/***** Test IAccessibleAction *****/
IAccessibleAction * ia2Action = 0 ;
hr = ia2Button - > QueryInterface ( IID_IAccessibleAction , ( void * * ) & ia2Action ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QVERIFY ( ia2Action ) ;
long nActions ;
ia2Action - > nActions ( & nActions ) ;
QVERIFY ( nActions > = 1 ) ; // "Press" and "SetFocus"
BSTR actionName ;
ia2Action - > get_name ( 0 , & actionName ) ;
QString name ( ( QChar * ) actionName ) ;
2013-09-25 15:09:17 +00:00
: : SysFreeString ( actionName ) ;
2012-03-07 10:59:30 +00:00
QCOMPARE ( name , QAccessibleActionInterface : : pressAction ( ) ) ;
ia2Action - > Release ( ) ;
2013-09-25 15:09:17 +00:00
/***** Test IAccessibleRelation *****/
long nRelations = 0 ;
hr = ia2Button - > get_nRelations ( & nRelations ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( nRelations , ( long ) 1 ) ;
IAccessibleRelation * * relations = ( IAccessibleRelation * * ) : : CoTaskMemAlloc ( sizeof ( IAccessibleRelation * ) * 4 ) ;
hr = ia2Button - > get_relations ( 4 , relations , & nRelations ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( nRelations , ( long ) 1 ) ;
IAccessibleRelation * relation = relations [ 0 ] ;
BSTR relType ;
hr = relation - > get_relationType ( & relType ) ;
QCOMPARE ( QString : : fromWCharArray ( relType ) , QLatin1String ( " labelFor " ) ) ;
: : SysFreeString ( relType ) ;
long nTargets ;
relation - > get_nTargets ( & nTargets ) ;
QCOMPARE ( nTargets , ( long ) 1 ) ;
IAccessible * target ; // target is the label
hr = relation - > get_target ( 0 , ( IUnknown * * ) & target ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
VARIANT varRole ;
hr = target - > get_accRole ( varSELF , & varRole ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
Q_ASSERT ( varRole . vt = = ( VARTYPE ) VT_I4 ) ;
QCOMPARE ( varRole . lVal , ( LONG ) ROLE_SYSTEM_STATICTEXT ) ;
BSTR buttonName ;
hr = target - > get_accName ( varSELF , & buttonName ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( QString : : fromWCharArray ( buttonName ) , QLatin1String ( " Push my buddy " ) ) ;
: : SysFreeString ( buttonName ) ;
: : CoTaskMemFree ( relations ) ;
2012-03-07 10:59:30 +00:00
// Done testing
ia2Button - > Release ( ) ;
}
# endif
iaccButton - > Release ( ) ;
2012-03-27 05:09:22 +00:00
2012-03-07 10:59:30 +00:00
/**************************************************
* QWidget
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
QWindow * windowHandle = window - > windowHandle ( ) ;
QPlatformNativeInterface * platform = QGuiApplication : : platformNativeInterface ( ) ;
HWND hWnd = ( HWND ) platform - > nativeResourceForWindow ( " handle " , windowHandle ) ;
IAccessible * iaccWindow ;
hr = : : AccessibleObjectFromWindow ( hWnd , OBJID_CLIENT , IID_IAccessible , ( void * * ) & iaccWindow ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
hr = iaccWindow - > get_accRole ( varSELF , & varRole ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( varRole . vt , ( VARTYPE ) VT_I4 ) ;
QCOMPARE ( varRole . lVal , ( LONG ) ROLE_SYSTEM_CLIENT ) ;
long nChildren ;
hr = iaccWindow - > get_accChildCount ( & nChildren ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
2013-09-25 15:09:17 +00:00
QCOMPARE ( nChildren , ( long ) 4 ) ;
2012-03-07 10:59:30 +00:00
/**************************************************
* QTextEdit
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Get the second child (the accessible interface for the text edit)
varChild . vt = VT_I4 ;
varChild . lVal = 2 ;
QVERIFY ( iaccWindow ) ;
IAccessible * iaccTextEdit ;
hr = iaccWindow - > get_accChild ( varChild , ( IDispatch * * ) & iaccTextEdit ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QVERIFY ( iaccTextEdit ) ;
hr = iaccTextEdit - > get_accRole ( varSELF , & varRole ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( varRole . vt , ( VARTYPE ) VT_I4 ) ;
QCOMPARE ( varRole . lVal , ( LONG ) ROLE_SYSTEM_TEXT ) ;
# ifdef QT_SUPPORTS_IACCESSIBLE2
if ( IAccessibleEditableText * ia2TextEdit = ( IAccessibleEditableText * ) queryIA2 ( iaccTextEdit , IID_IAccessibleEditableText ) ) {
ia2TextEdit - > copyText ( 6 , 11 ) ;
QCOMPARE ( QApplication : : clipboard ( ) - > text ( ) , QLatin1String ( " world " ) ) ;
ia2TextEdit - > cutText ( 12 , 16 ) ;
QCOMPARE ( QApplication : : clipboard ( ) - > text ( ) , QLatin1String ( " how " ) ) ;
ia2TextEdit - > Release ( ) ;
}
if ( IAccessibleText * ia2Text = ( IAccessibleText * ) queryIA2 ( iaccTextEdit , IID_IAccessibleText ) ) {
BSTR txt ;
hr = ia2Text - > get_text ( 12 , 15 , & txt ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( QString ( ( QChar * ) txt ) , QLatin1String ( " are " ) ) ;
ia2Text - > Release ( ) ;
2012-03-27 05:09:22 +00:00
}
# endif
2012-03-07 10:59:30 +00:00
iaccTextEdit - > Release ( ) ;
2012-03-27 05:09:22 +00:00
2012-11-01 13:32:46 +00:00
/**************************************************
* QTableWidget
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
{
// Get the second child (the accessible interface for the table widget)
varChild . vt = VT_I4 ;
varChild . lVal = 3 ;
QVERIFY ( iaccWindow ) ;
IAccessible * iaccTable = 0 ;
hr = iaccWindow - > get_accChild ( varChild , ( IDispatch * * ) & iaccTable ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QVERIFY ( iaccTable ) ;
hr = iaccTable - > get_accRole ( varSELF , & varRole ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( varRole . vt , ( VARTYPE ) VT_I4 ) ;
QCOMPARE ( varRole . lVal , ( LONG ) ROLE_SYSTEM_TABLE ) ;
# ifdef QT_SUPPORTS_IACCESSIBLE2
IAccessibleTable2 * ia2Table = ( IAccessibleTable2 * ) queryIA2 ( iaccTable , IID_IAccessibleTable2 ) ;
QVERIFY ( ia2Table ) ;
BSTR bstrDescription ;
hr = ia2Table - > get_columnDescription ( 0 , & bstrDescription ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
2013-09-23 13:07:00 +00:00
QCOMPARE ( QString : : fromWCharArray ( bstrDescription ) , QLatin1String ( " h1 " ) ) ;
: : SysFreeString ( bstrDescription ) ;
hr = ia2Table - > get_rowDescription ( 1 , & bstrDescription ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QCOMPARE ( QString : : fromWCharArray ( bstrDescription ) , QLatin1String ( " v2 " ) ) ;
: : SysFreeString ( bstrDescription ) ;
2012-11-01 13:32:46 +00:00
IAccessible * accTableCell = 0 ;
hr = ia2Table - > get_cellAt ( 1 , 2 , ( IUnknown * * ) & accTableCell ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
2013-01-03 16:18:40 +00:00
QVERIFY ( accTableCell ) ;
IAccessibleTableCell * ia2TableCell = ( IAccessibleTableCell * ) queryIA2 ( accTableCell , IID_IAccessibleTableCell ) ;
2012-11-01 13:32:46 +00:00
QVERIFY ( ia2TableCell ) ;
LONG index ;
ia2TableCell - > get_rowIndex ( & index ) ;
QCOMPARE ( index , ( LONG ) 1 ) ;
ia2TableCell - > get_columnIndex ( & index ) ;
QCOMPARE ( index , ( LONG ) 2 ) ;
IAccessible * iaccTableCell = 0 ;
hr = ia2TableCell - > QueryInterface ( IID_IAccessible , ( void * * ) & iaccTableCell ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QVERIFY ( iaccTableCell ) ;
BSTR bstrCellName ;
hr = iaccTableCell - > get_accName ( varSELF , & bstrCellName ) ;
QVERIFY ( SUCCEEDED ( hr ) ) ;
QString cellName ( ( QChar * ) bstrCellName ) ;
QCOMPARE ( cellName , QLatin1String ( " 1.2 " ) ) ;
accTableCell - > Release ( ) ;
iaccTableCell - > Release ( ) ;
ia2TableCell - > Release ( ) ;
ia2Table - > Release ( ) ;
# endif
2013-01-15 13:09:59 +00:00
iaccTable - > Release ( ) ;
2012-11-01 13:32:46 +00:00
}
2012-03-07 10:59:30 +00:00
iaccWindow - > Release ( ) ;
2012-03-27 05:09:22 +00:00
QTestAccessibility : : clearEvents ( ) ;
# endif
}
2011-04-27 10:05:43 +00:00
QTEST_MAIN ( tst_QAccessibility )
# include "tst_qaccessibility.moc"