|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #ifdef QT3_SUPPORT |
|
44 #include <Qt3Support/Qt3Support> |
|
45 #endif |
|
46 #include <QtTest/QtTest> |
|
47 #ifndef Q_OS_WINCE |
|
48 #include "../../shared/util.h" |
|
49 #include <QtGui> |
|
50 #include <math.h> |
|
51 |
|
52 |
|
53 #include "QtTest/qtestaccessible.h" |
|
54 |
|
55 #if defined(Q_OS_WINCE) |
|
56 extern "C" bool SystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni); |
|
57 #define SPI_GETPLATFORMTYPE 257 |
|
58 inline bool IsValidCEPlatform() { |
|
59 wchar_t tszPlatform[64]; |
|
60 if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(tszPlatform) / sizeof(*tszPlatform), tszPlatform, 0)) { |
|
61 QString platform = QString::fromWCharArray(tszPlatform); |
|
62 if ((platform == QLatin1String("PocketPC")) || (platform == QLatin1String("Smartphone"))) |
|
63 return false; |
|
64 } |
|
65 return true; |
|
66 } |
|
67 #endif |
|
68 |
|
69 static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface, |
|
70 int index, const QRect &domain) |
|
71 { |
|
72 if (!child) { |
|
73 qWarning("tst_QAccessibility::verifyChild: null pointer to child."); |
|
74 return false; |
|
75 } |
|
76 |
|
77 if (!interface) { |
|
78 qWarning("tst_QAccessibility::verifyChild: null pointer to interface."); |
|
79 return false; |
|
80 } |
|
81 |
|
82 // QAccessibleInterface::childAt(): |
|
83 // Calculate global child position and check that the interface |
|
84 // returns the correct index for that position. |
|
85 QPoint globalChildPos = child->mapToGlobal(QPoint(0, 0)); |
|
86 int indexFromChildAt = interface->childAt(globalChildPos.x(), globalChildPos.y()); |
|
87 if (indexFromChildAt != index) { |
|
88 qWarning("tst_QAccessibility::verifyChild (childAt()):"); |
|
89 qWarning() << "Expected:" << index; |
|
90 qWarning() << "Actual: " << indexFromChildAt; |
|
91 return false; |
|
92 } |
|
93 |
|
94 // QAccessibleInterface::rect(): |
|
95 // Calculate global child geometry and check that the interface |
|
96 // returns a QRect which is equal to the calculated QRect. |
|
97 const QRect expectedGlobalRect = QRect(globalChildPos, child->size()); |
|
98 const QRect rectFromInterface = interface->rect(index); |
|
99 if (expectedGlobalRect != rectFromInterface) { |
|
100 qWarning("tst_QAccessibility::verifyChild (rect()):"); |
|
101 qWarning() << "Expected:" << expectedGlobalRect; |
|
102 qWarning() << "Actual: " << rectFromInterface; |
|
103 return false; |
|
104 } |
|
105 |
|
106 // Verify that the child is within its domain. |
|
107 if (!domain.contains(rectFromInterface)) { |
|
108 qWarning("tst_QAccessibility::verifyChild: Child is not within its domain."); |
|
109 return false; |
|
110 } |
|
111 |
|
112 // Verify that we get a valid QAccessibleInterface for the child. |
|
113 QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child); |
|
114 if (!childInterface) { |
|
115 qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child."); |
|
116 return false; |
|
117 } |
|
118 |
|
119 // QAccessibleInterface::indexOfChild(): |
|
120 // Verify that indexOfChild() returns an index equal to the index passed by, |
|
121 // or -1 if child is "Self" (index == 0). |
|
122 int indexFromIndexOfChild = interface->indexOfChild(childInterface); |
|
123 delete childInterface; |
|
124 int expectedIndex = index == 0 ? -1 : index; |
|
125 if (indexFromIndexOfChild != expectedIndex) { |
|
126 qWarning("tst_QAccessibility::verifyChild (indexOfChild()):"); |
|
127 qWarning() << "Expected:" << expectedIndex; |
|
128 qWarning() << "Actual: " << indexFromIndexOfChild; |
|
129 return false; |
|
130 } |
|
131 |
|
132 // Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child). |
|
133 { |
|
134 QAccessibleInterface *navigatedChildInterface = 0; |
|
135 const int status = interface->navigate(QAccessible::Child, index, &navigatedChildInterface); |
|
136 // We are navigating to a separate widget/interface, so status should be 0. |
|
137 if (status != 0) |
|
138 return false; |
|
139 |
|
140 if (navigatedChildInterface == 0) |
|
141 return false; |
|
142 delete navigatedChildInterface; |
|
143 } |
|
144 |
|
145 return true; |
|
146 } |
|
147 |
|
148 static inline int indexOfChild(QAccessibleInterface *parentInterface, QWidget *childWidget) |
|
149 { |
|
150 if (!parentInterface || !childWidget) |
|
151 return -1; |
|
152 QAccessibleInterface *childInterface = QAccessibleInterface::queryAccessibleInterface(childWidget); |
|
153 if (!childInterface) |
|
154 return -1; |
|
155 int index = parentInterface->indexOfChild(childInterface); |
|
156 delete childInterface; |
|
157 return index; |
|
158 } |
|
159 |
|
160 #define EXPECT(cond) \ |
|
161 do { \ |
|
162 if (!errorAt && !(cond)) { \ |
|
163 errorAt = __LINE__; \ |
|
164 qWarning("level: %d, middle: %d, role: %d (%s)", treelevel, middle, iface->role(0), #cond); \ |
|
165 } \ |
|
166 } while (0) |
|
167 |
|
168 static int verifyHierarchy(QAccessibleInterface *iface) |
|
169 { |
|
170 int errorAt = 0; |
|
171 int entry = 0; |
|
172 static int treelevel = 0; // for error diagnostics |
|
173 QAccessibleInterface *middleChild, *if2, *if3; |
|
174 middleChild = 0; |
|
175 ++treelevel; |
|
176 int middle = iface->childCount()/2 + 1; |
|
177 if (iface->childCount() >= 2) { |
|
178 entry = iface->navigate(QAccessible::Child, middle, &middleChild); |
|
179 } |
|
180 for (int i = 0; i < iface->childCount() && !errorAt; ++i) { |
|
181 entry = iface->navigate(QAccessible::Child, i + 1, &if2); |
|
182 if (entry == 0) { |
|
183 // navigate Ancestor... |
|
184 QAccessibleInterface *parent = 0; |
|
185 entry = if2->navigate(QAccessible::Ancestor, 1, &parent); |
|
186 EXPECT(entry == 0 && iface->object() == parent->object()); |
|
187 delete parent; |
|
188 |
|
189 // navigate Sibling... |
|
190 if (middleChild) { |
|
191 entry = if2->navigate(QAccessible::Sibling, middle, &if3); |
|
192 EXPECT(entry == 0 && if3->object() == middleChild->object()); |
|
193 delete if3; |
|
194 EXPECT(iface->indexOfChild(middleChild) == middle); |
|
195 } |
|
196 |
|
197 // verify children... |
|
198 if (!errorAt) |
|
199 errorAt = verifyHierarchy(if2); |
|
200 delete if2; |
|
201 } else { |
|
202 // leaf nodes |
|
203 } |
|
204 } |
|
205 delete middleChild; |
|
206 |
|
207 --treelevel; |
|
208 return errorAt; |
|
209 } |
|
210 |
|
211 |
|
212 //TESTED_FILES= |
|
213 |
|
214 class tst_QAccessibility : public QObject |
|
215 { |
|
216 Q_OBJECT |
|
217 public: |
|
218 tst_QAccessibility(); |
|
219 virtual ~tst_QAccessibility(); |
|
220 |
|
221 public slots: |
|
222 void initTestCase(); |
|
223 void cleanupTestCase(); |
|
224 void init(); |
|
225 void cleanup(); |
|
226 private slots: |
|
227 void eventTest(); |
|
228 void customWidget(); |
|
229 void deletedWidget(); |
|
230 |
|
231 void childCount(); |
|
232 void childAt(); // also indexOfChild |
|
233 void relationTo(); |
|
234 void navigateGeometric(); |
|
235 void navigateHierarchy(); |
|
236 void navigateSlider(); |
|
237 void navigateCovered(); |
|
238 void navigateControllers(); |
|
239 void navigateLabels(); |
|
240 void text(); |
|
241 void setText(); |
|
242 void hideShowTest(); |
|
243 |
|
244 void userActionCount(); |
|
245 void actionText(); |
|
246 void doAction(); |
|
247 |
|
248 void buttonTest(); |
|
249 void sliderTest(); |
|
250 void scrollBarTest(); |
|
251 void tabTest(); |
|
252 void menuTest(); |
|
253 void spinBoxTest(); |
|
254 void doubleSpinBoxTest(); |
|
255 void textEditTest(); |
|
256 void textBrowserTest(); |
|
257 void listViewTest(); |
|
258 void mdiAreaTest(); |
|
259 void mdiSubWindowTest(); |
|
260 void lineEditTest(); |
|
261 void workspaceTest(); |
|
262 void dialogButtonBoxTest(); |
|
263 void dialTest(); |
|
264 void rubberBandTest(); |
|
265 void abstractScrollAreaTest(); |
|
266 void scrollAreaTest(); |
|
267 void tableWidgetTest(); |
|
268 void tableViewTest(); |
|
269 void calendarWidgetTest(); |
|
270 void dockWidgetTest(); |
|
271 void pushButtonTest(); |
|
272 void comboBoxTest(); |
|
273 void accessibleName(); |
|
274 void treeWidgetTest(); |
|
275 void labelTest(); |
|
276 void accelerators(); |
|
277 |
|
278 private: |
|
279 QWidget *createGUI(); |
|
280 }; |
|
281 |
|
282 const double Q_PI = 3.14159265358979323846; |
|
283 |
|
284 QString eventName(const int ev) |
|
285 { |
|
286 switch(ev) { |
|
287 case 0x0001: return "SoundPlayed"; |
|
288 case 0x0002: return "Alert"; |
|
289 case 0x0003: return "ForegroundChanged"; |
|
290 case 0x0004: return "MenuStart"; |
|
291 case 0x0005: return "MenuEnd"; |
|
292 case 0x0006: return "PopupMenuStart"; |
|
293 case 0x0007: return "PopupMenuEnd"; |
|
294 case 0x000C: return "ContextHelpStart"; |
|
295 case 0x000D: return "ContextHelpEnd"; |
|
296 case 0x000E: return "DragDropStart"; |
|
297 case 0x000F: return "DragDropEnd"; |
|
298 case 0x0010: return "DialogStart"; |
|
299 case 0x0011: return "DialogEnd"; |
|
300 case 0x0012: return "ScrollingStart"; |
|
301 case 0x0013: return "ScrollingEnd"; |
|
302 case 0x0018: return "MenuCommand"; |
|
303 case 0x8000: return "ObjectCreated"; |
|
304 case 0x8001: return "ObjectDestroyed"; |
|
305 case 0x8002: return "ObjectShow"; |
|
306 case 0x8003: return "ObjectHide"; |
|
307 case 0x8004: return "ObjectReorder"; |
|
308 case 0x8005: return "Focus"; |
|
309 case 0x8006: return "Selection"; |
|
310 case 0x8007: return "SelectionAdd"; |
|
311 case 0x8008: return "SelectionRemove"; |
|
312 case 0x8009: return "SelectionWithin"; |
|
313 case 0x800A: return "StateChanged"; |
|
314 case 0x800B: return "LocationChanged"; |
|
315 case 0x800C: return "NameChanged"; |
|
316 case 0x800D: return "DescriptionChanged"; |
|
317 case 0x800E: return "ValueChanged"; |
|
318 case 0x800F: return "ParentChanged"; |
|
319 case 0x80A0: return "HelpChanged"; |
|
320 case 0x80B0: return "DefaultActionChanged"; |
|
321 case 0x80C0: return "AcceleratorChanged"; |
|
322 default: return "Unknown Event"; |
|
323 } |
|
324 } |
|
325 |
|
326 static QString stateNames(int state) |
|
327 { |
|
328 QString stateString; |
|
329 if (state == 0x00000000) stateString += " Normal"; |
|
330 if (state & 0x00000001) stateString += " Unavailable"; |
|
331 if (state & 0x00000002) stateString += " Selected"; |
|
332 if (state & 0x00000004) stateString += " Focused"; |
|
333 if (state & 0x00000008) stateString += " Pressed"; |
|
334 if (state & 0x00000010) stateString += " Checked"; |
|
335 if (state & 0x00000020) stateString += " Mixed"; |
|
336 if (state & 0x00000040) stateString += " ReadOnly"; |
|
337 if (state & 0x00000080) stateString += " HotTracked"; |
|
338 if (state & 0x00000100) stateString += " DefaultButton"; |
|
339 if (state & 0x00000200) stateString += " Expanded"; |
|
340 if (state & 0x00000400) stateString += " Collapsed"; |
|
341 if (state & 0x00000800) stateString += " Busy"; |
|
342 if (state & 0x00001000) stateString += " Floating"; |
|
343 if (state & 0x00002000) stateString += " Marqueed"; |
|
344 if (state & 0x00004000) stateString += " Animated"; |
|
345 if (state & 0x00008000) stateString += " Invisible"; |
|
346 if (state & 0x00010000) stateString += " Offscreen"; |
|
347 if (state & 0x00020000) stateString += " Sizeable"; |
|
348 if (state & 0x00040000) stateString += " Moveable"; |
|
349 if (state & 0x00080000) stateString += " SelfVoicing"; |
|
350 if (state & 0x00100000) stateString += " Focusable"; |
|
351 if (state & 0x00200000) stateString += " Selectable"; |
|
352 if (state & 0x00400000) stateString += " Linked"; |
|
353 if (state & 0x00800000) stateString += " Traversed"; |
|
354 if (state & 0x01000000) stateString += " MultiSelectable"; |
|
355 if (state & 0x02000000) stateString += " ExtSelectable"; |
|
356 if (state & 0x04000000) stateString += " AlertLow"; |
|
357 if (state & 0x08000000) stateString += " AlertMedium"; |
|
358 if (state & 0x10000000) stateString += " AlertHigh"; |
|
359 if (state & 0x20000000) stateString += " Protected"; |
|
360 if (state & 0x3fffffff) stateString += " Valid"; |
|
361 |
|
362 if (stateString.isEmpty()) |
|
363 stateString = "Unknown state " + QString::number(state); |
|
364 |
|
365 return stateString; |
|
366 } |
|
367 |
|
368 QAccessible::State state(QWidget * const widget) |
|
369 { |
|
370 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); |
|
371 Q_ASSERT(iface); |
|
372 QAccessible::State state = iface->state(0); |
|
373 delete iface; |
|
374 return state; |
|
375 } |
|
376 |
|
377 void printState(QWidget * const widget) |
|
378 { |
|
379 qDebug() << "State for" << widget->metaObject()->className() << stateNames(state(widget)); |
|
380 } |
|
381 |
|
382 void printState(QAccessibleInterface * const iface, const int child = 0) |
|
383 { |
|
384 qDebug() << "State for" << iface->object()->metaObject()->className() << "child" << child |
|
385 << iface->text(QAccessible::Name, child) << stateNames(iface->state(child)); |
|
386 } |
|
387 |
|
388 |
|
389 class QtTestAccessibleWidget: public QWidget |
|
390 { |
|
391 Q_OBJECT |
|
392 public: |
|
393 QtTestAccessibleWidget(QWidget *parent, const char *name): QWidget(parent) |
|
394 { |
|
395 setObjectName(name); |
|
396 QPalette pal; |
|
397 pal.setColor(backgroundRole(), Qt::black);//black is beautiful |
|
398 setPalette(pal); |
|
399 setFixedSize(5, 5); |
|
400 } |
|
401 }; |
|
402 |
|
403 #ifdef QTEST_ACCESSIBILITY |
|
404 class QtTestAccessibleWidgetIface: public QAccessibleWidget |
|
405 { |
|
406 public: |
|
407 QtTestAccessibleWidgetIface(QtTestAccessibleWidget *w): QAccessibleWidget(w) {} |
|
408 QString text(Text t, int control) const |
|
409 { |
|
410 if (t == Help) |
|
411 return QString::fromLatin1("Help yourself"); |
|
412 return QAccessibleWidget::text(t, control); |
|
413 } |
|
414 static QAccessibleInterface *ifaceFactory(const QString &key, QObject *o) |
|
415 { |
|
416 if (key == "QtTestAccessibleWidget") |
|
417 return new QtTestAccessibleWidgetIface(static_cast<QtTestAccessibleWidget*>(o)); |
|
418 return 0; |
|
419 } |
|
420 }; |
|
421 #endif |
|
422 |
|
423 tst_QAccessibility::tst_QAccessibility() |
|
424 { |
|
425 } |
|
426 |
|
427 tst_QAccessibility::~tst_QAccessibility() |
|
428 { |
|
429 } |
|
430 |
|
431 void tst_QAccessibility::initTestCase() |
|
432 { |
|
433 #ifdef QTEST_ACCESSIBILITY |
|
434 QTestAccessibility::initialize(); |
|
435 QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory); |
|
436 #endif |
|
437 } |
|
438 |
|
439 void tst_QAccessibility::cleanupTestCase() |
|
440 { |
|
441 #ifdef QTEST_ACCESSIBILITY |
|
442 QTestAccessibility::cleanup(); |
|
443 #endif |
|
444 } |
|
445 |
|
446 void tst_QAccessibility::init() |
|
447 { |
|
448 QTestAccessibility::clearEvents(); |
|
449 } |
|
450 |
|
451 void tst_QAccessibility::cleanup() |
|
452 { |
|
453 #ifdef QTEST_ACCESSIBILITY |
|
454 const EventList list = QTestAccessibility::events(); |
|
455 if (!list.isEmpty()) { |
|
456 qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(), |
|
457 QString(QTest::currentTestFunction()).toAscii().constData()); |
|
458 for (int i = 0; i < list.count(); ++i) |
|
459 qWarning(" %d: Object: %p Event: '%s' (%d) Child: %d", i + 1, list.at(i).object, |
|
460 eventName(list.at(i).event).toAscii().constData(), list.at(i).event, list.at(i).child); |
|
461 } |
|
462 QTestAccessibility::clearEvents(); |
|
463 #else |
|
464 QSKIP("Test needs accessibility support.", SkipAll); |
|
465 #endif |
|
466 } |
|
467 |
|
468 void tst_QAccessibility::eventTest() |
|
469 { |
|
470 #ifdef QTEST_ACCESSIBILITY |
|
471 QPushButton* button = new QPushButton(0); |
|
472 button->setObjectName(QString("Olaf")); |
|
473 |
|
474 button->show(); |
|
475 QVERIFY_EVENT(button, 0, QAccessible::ObjectShow); |
|
476 button->setFocus(Qt::MouseFocusReason); |
|
477 QTestAccessibility::clearEvents(); |
|
478 QTest::mouseClick(button, Qt::LeftButton, 0, QPoint(button->width()-7,button->height()-5)); |
|
479 QVERIFY_EVENT(button, 0, QAccessible::StateChanged); |
|
480 QVERIFY_EVENT(button, 0, QAccessible::StateChanged); |
|
481 |
|
482 button->hide(); |
|
483 QVERIFY_EVENT(button, 0, QAccessible::ObjectHide); |
|
484 |
|
485 delete button; |
|
486 #else |
|
487 QSKIP("Test needs accessibility support.", SkipAll); |
|
488 #endif |
|
489 } |
|
490 |
|
491 void tst_QAccessibility::customWidget() |
|
492 { |
|
493 #ifdef QTEST_ACCESSIBILITY |
|
494 QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); |
|
495 |
|
496 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); |
|
497 QVERIFY(iface != 0); |
|
498 QVERIFY(iface->isValid()); |
|
499 QCOMPARE(iface->object(), (QObject*)widget); |
|
500 QCOMPARE(iface->object()->objectName(), QString("Heinz")); |
|
501 QCOMPARE(iface->text(QAccessible::Help, 0), QString("Help yourself")); |
|
502 |
|
503 delete iface; |
|
504 delete widget; |
|
505 #else |
|
506 QSKIP("Test needs accessibility support.", SkipAll); |
|
507 #endif |
|
508 } |
|
509 |
|
510 void tst_QAccessibility::deletedWidget() |
|
511 { |
|
512 #ifdef QTEST_ACCESSIBILITY |
|
513 QtTestAccessibleWidget *widget = new QtTestAccessibleWidget(0, "Ralf"); |
|
514 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); |
|
515 QVERIFY(iface != 0); |
|
516 QVERIFY(iface->isValid()); |
|
517 QCOMPARE(iface->object(), (QObject*)widget); |
|
518 |
|
519 delete widget; |
|
520 widget = 0; |
|
521 QVERIFY(!iface->isValid()); |
|
522 delete iface; |
|
523 #else |
|
524 QSKIP("Test needs accessibility support.", SkipAll); |
|
525 #endif |
|
526 } |
|
527 |
|
528 QWidget *tst_QAccessibility::createGUI() |
|
529 { |
|
530 #if !defined(QT3_SUPPORT) |
|
531 qWarning( "Should never get here without Qt3Support"); |
|
532 return 0; |
|
533 #else |
|
534 # ifdef QTEST_ACCESSIBILITY |
|
535 QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint); |
|
536 QGridLayout *grid = new QGridLayout(toplevel, 2, 2); |
|
537 |
|
538 // topLeft - hierarchies |
|
539 Q3VBox *topLeft = new Q3VBox(toplevel, "topLeft"); |
|
540 topLeft->setSpacing(2); |
|
541 grid->addWidget(topLeft, 0, 0); |
|
542 |
|
543 Q3VButtonGroup *group1 = new Q3VButtonGroup("Title1:", topLeft, "group1"); |
|
544 /*QPushButton *pb1 = */ new QPushButton("Button&1", group1, "pb1"); |
|
545 Q3VButtonGroup *group2 = new Q3VButtonGroup("Title2:", topLeft, "group2"); |
|
546 /*QPushButton *pb2 = */ new QPushButton("Button2", group2, "pb2"); |
|
547 |
|
548 Q3WidgetStack *stack = new Q3WidgetStack(topLeft, "stack"); |
|
549 QLabel *page1 = new QLabel("Page 1", stack, "page1"); |
|
550 stack->addWidget(page1); |
|
551 QLabel *page2 = new QLabel("Page 2", stack, "page2"); |
|
552 stack->addWidget(page2); |
|
553 QLabel *page3 = new QLabel("Page 3", stack, "page3"); |
|
554 stack->addWidget(page3); |
|
555 |
|
556 // topRight - controlling |
|
557 Q3VBox *topRight= new Q3VBox(toplevel, "topRight"); |
|
558 grid->addWidget(topRight, 0, 1); |
|
559 |
|
560 QPushButton *pbOk = new QPushButton("Ok", topRight, "pbOk" ); |
|
561 pbOk->setDefault(TRUE); |
|
562 QSlider *slider = new QSlider(Qt::Horizontal, topRight, "slider"); |
|
563 QLCDNumber *sliderLcd = new QLCDNumber(topRight, "sliderLcd"); |
|
564 QSpinBox *spinBox = new QSpinBox(topRight, "spinBox"); |
|
565 |
|
566 connect(pbOk, SIGNAL(clicked()), toplevel, SLOT(close()) ); |
|
567 connect(slider, SIGNAL(valueChanged(int)), sliderLcd, SLOT(display(int))); |
|
568 connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); |
|
569 |
|
570 spinBox->setValue(50); |
|
571 |
|
572 // bottomLeft - labeling and controlling |
|
573 Q3HBox *bottomLeft = new Q3HBox(toplevel, "bottomLeft"); |
|
574 grid->addWidget(bottomLeft, 1, 0); |
|
575 |
|
576 QLabel *label = new QLabel("This is a &lineedit:", bottomLeft, "label"); |
|
577 QLineEdit *lineedit = new QLineEdit(bottomLeft, "lineedit"); |
|
578 label->setBuddy(lineedit); |
|
579 QLabel *label2 = new QLabel(bottomLeft, "label2"); |
|
580 |
|
581 connect(lineedit, SIGNAL(textChanged(const QString&)), label2, SLOT(setText(const QString&))); |
|
582 |
|
583 Q3VButtonGroup *radiogroup = new Q3VButtonGroup("Exclusive &choices:", bottomLeft, "radiogroup"); |
|
584 QLineEdit *frequency = new QLineEdit(radiogroup, "frequency"); |
|
585 frequency->setText("100 Mhz"); |
|
586 QRadioButton *radioAM = new QRadioButton("&AM", radiogroup, "radioAM"); |
|
587 /* QRadioButton *radioFM = */ new QRadioButton("&FM", radiogroup, "radioFM"); |
|
588 /* QRadioButton *radioSW = */ new QRadioButton("&Shortwave", radiogroup, "radioSW"); |
|
589 |
|
590 // bottomRight - ### empty |
|
591 Q3HBox *bottomRight = new Q3HBox(toplevel, "bottomRight"); |
|
592 grid->addWidget(bottomRight, 1, 1); |
|
593 |
|
594 toplevel->adjustSize(); // sends layout and child events |
|
595 |
|
596 // some tooltips |
|
597 QToolTip::add(label, "A label"); |
|
598 QToolTip::add(lineedit, "A line edit"); |
|
599 // some whatsthis |
|
600 QWhatsThis::add(label, "A label displays static text"); |
|
601 QWhatsThis::add(frequency, "You can enter a single line of text here"); |
|
602 |
|
603 radioAM->setFocus(); |
|
604 QTestAccessibility::clearEvents(); |
|
605 return toplevel; |
|
606 # else |
|
607 Q_ASSERT(0); // this function cannot be called without accessibility support |
|
608 return 0; |
|
609 # endif |
|
610 #endif // !QT3_SUPPORT |
|
611 } |
|
612 |
|
613 void tst_QAccessibility::childAt() |
|
614 { |
|
615 #if !defined(QT3_SUPPORT) |
|
616 QSKIP("This test needs Qt3Support", SkipAll); |
|
617 #else |
|
618 #ifdef QTEST_ACCESSIBILITY |
|
619 QWidget *toplevel = createGUI(); |
|
620 QAccessibleInterface *acc_toplevel = QAccessible::queryAccessibleInterface(toplevel); |
|
621 QVERIFY(acc_toplevel); |
|
622 // this is necessary to have the layout setup correctly |
|
623 toplevel->show(); |
|
624 |
|
625 QObjectList children = toplevel->queryList("QWidget", 0, 0, 0); |
|
626 for (int c = 1; c <= children.count(); ++c) { |
|
627 QWidget *child = qobject_cast<QWidget*>(children.at(c-1)); |
|
628 QAccessibleInterface *acc_child = QAccessible::queryAccessibleInterface(child); |
|
629 QVERIFY(acc_child); |
|
630 QCOMPARE(acc_child->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, QAccessible::Child); |
|
631 |
|
632 QPoint center(child->mapToGlobal(child->rect().center())); |
|
633 QRect childRect(child->geometry()); |
|
634 childRect.moveCenter(center); |
|
635 |
|
636 QCOMPARE(acc_child->rect(0), childRect); |
|
637 QCOMPARE(acc_toplevel->childAt(childRect.center().x(), childRect.center().y()), c); |
|
638 QCOMPARE(acc_toplevel->childAt(childRect.left(), childRect.top()), c); |
|
639 QCOMPARE(acc_toplevel->childAt(childRect.left(), childRect.bottom()), c); |
|
640 QCOMPARE(acc_toplevel->childAt(childRect.right(), childRect.top()), c); |
|
641 QCOMPARE(acc_toplevel->childAt(childRect.right(), childRect.bottom()), c); |
|
642 |
|
643 QCOMPARE(acc_toplevel->indexOfChild(acc_child), c); |
|
644 delete acc_child; |
|
645 } |
|
646 |
|
647 delete acc_toplevel; |
|
648 delete toplevel; |
|
649 QTestAccessibility::clearEvents(); |
|
650 #else |
|
651 QSKIP("Test needs accessibility support.", SkipAll); |
|
652 #endif |
|
653 #endif // !QT3_SUPPORT |
|
654 } |
|
655 |
|
656 void tst_QAccessibility::childCount() |
|
657 { |
|
658 #if !defined(QT3_SUPPORT) |
|
659 QSKIP("This test needs Qt3Support", SkipAll); |
|
660 #else |
|
661 #ifdef QTEST_ACCESSIBILITY |
|
662 QWidget *toplevel = createGUI(); |
|
663 QObject *topLeft = toplevel->child("topLeft"); |
|
664 QObject *topRight = toplevel->child("topRight"); |
|
665 QObject *bottomLeft = toplevel->child("bottomLeft"); |
|
666 QObject *bottomRight = toplevel->child("bottomRight"); |
|
667 |
|
668 QAccessibleInterface* acc_toplevel = QAccessible::queryAccessibleInterface(toplevel); |
|
669 QAccessibleInterface* acc_topLeft = QAccessible::queryAccessibleInterface(topLeft); |
|
670 QAccessibleInterface* acc_topRight = QAccessible::queryAccessibleInterface(topRight); |
|
671 QAccessibleInterface* acc_bottomLeft = QAccessible::queryAccessibleInterface(bottomLeft); |
|
672 QAccessibleInterface* acc_bottomRight = QAccessible::queryAccessibleInterface(bottomRight); |
|
673 |
|
674 QVERIFY(acc_toplevel); |
|
675 QVERIFY(acc_topLeft); |
|
676 QVERIFY(acc_topRight); |
|
677 QVERIFY(acc_bottomLeft); |
|
678 QVERIFY(acc_bottomRight); |
|
679 |
|
680 toplevel->show(); |
|
681 QCOMPARE(acc_toplevel->childCount(), toplevel->queryList("QWidget", 0, 0, 0).count()); |
|
682 QCOMPARE(acc_topLeft->childCount(), topLeft->queryList("QWidget", 0, 0, 0).count()); |
|
683 QCOMPARE(acc_topRight->childCount(), topRight->queryList("QWidget", 0, 0, 0).count()); |
|
684 QCOMPARE(acc_bottomLeft->childCount(), bottomLeft->queryList("QWidget", 0, 0, 0).count()); |
|
685 QCOMPARE(acc_bottomRight->childCount(), bottomRight->queryList("QWidget", 0, 0, 0).count()); |
|
686 |
|
687 delete acc_toplevel; |
|
688 delete acc_topLeft; |
|
689 delete acc_topRight; |
|
690 delete acc_bottomLeft; |
|
691 delete acc_bottomRight; |
|
692 delete toplevel; |
|
693 QTestAccessibility::clearEvents(); |
|
694 #else |
|
695 QSKIP("Test needs accessibility support.", SkipAll); |
|
696 #endif |
|
697 #endif // !QT3_SUPPORT |
|
698 } |
|
699 |
|
700 void tst_QAccessibility::relationTo() |
|
701 { |
|
702 #if !defined(QT3_SUPPORT) |
|
703 QSKIP("This test needs Qt3Support", SkipAll); |
|
704 #else |
|
705 #ifdef QTEST_ACCESSIBILITY |
|
706 QWidget *toplevel = createGUI(); |
|
707 toplevel->resize(400,300); |
|
708 QObject *topLeft = toplevel->child("topLeft"); |
|
709 QObject *topRight = toplevel->child("topRight"); |
|
710 QObject *bottomLeft = toplevel->child("bottomLeft"); |
|
711 QObject *bottomRight = toplevel->child("bottomRight"); |
|
712 |
|
713 toplevel->show(); |
|
714 |
|
715 QAccessibleInterface *acc_toplevel = QAccessible::queryAccessibleInterface(toplevel); |
|
716 |
|
717 QAccessibleInterface *acc_topLeft = QAccessible::queryAccessibleInterface(topLeft); |
|
718 QAccessibleInterface *acc_group1 = QAccessible::queryAccessibleInterface(topLeft->child("group1")); |
|
719 QVERIFY(topLeft->child("group1")); |
|
720 QAccessibleInterface *acc_pb1 = QAccessible::queryAccessibleInterface(topLeft->child("group1")->child("pb1")); |
|
721 QAccessibleInterface *acc_group2 = QAccessible::queryAccessibleInterface(topLeft->child("group2")); |
|
722 QAccessibleInterface *acc_pb2 = 0; |
|
723 QAccessibleInterface *acc_stack = QAccessible::queryAccessibleInterface(topLeft->child("stack")); |
|
724 QAccessibleInterface *acc_page1 = QAccessible::queryAccessibleInterface(topLeft->child("stack")->child("page1")); |
|
725 QAccessibleInterface *acc_page2 = QAccessible::queryAccessibleInterface(topLeft->child("stack")->child("page2")); |
|
726 QAccessibleInterface *acc_page3 = QAccessible::queryAccessibleInterface(topLeft->child("stack")->child("page3")); |
|
727 QAccessibleInterface *acc_topRight = QAccessible::queryAccessibleInterface(topRight); |
|
728 QAccessibleInterface *acc_pbOk = QAccessible::queryAccessibleInterface(topRight->child("pbOk")); |
|
729 QAccessibleInterface *acc_slider = QAccessible::queryAccessibleInterface(topRight->child("slider")); |
|
730 QAccessibleInterface *acc_spinBox = QAccessible::queryAccessibleInterface(topRight->child("spinBox")); |
|
731 QAccessibleInterface *acc_sliderLcd = QAccessible::queryAccessibleInterface(topRight->child("sliderLcd")); |
|
732 |
|
733 QAccessibleInterface *acc_bottomLeft = QAccessible::queryAccessibleInterface(bottomLeft); |
|
734 QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(bottomLeft->child("label")); |
|
735 QAccessibleInterface *acc_lineedit = QAccessible::queryAccessibleInterface(bottomLeft->child("lineedit")); |
|
736 QAccessibleInterface *acc_label2 = QAccessible::queryAccessibleInterface(bottomLeft->child("label2")); |
|
737 QAccessibleInterface *acc_radiogroup = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")); |
|
738 QAccessibleInterface *acc_radioAM = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("radioAM")); |
|
739 QAccessibleInterface *acc_radioFM = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("radioFM")); |
|
740 QAccessibleInterface *acc_radioSW = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("radioSW")); |
|
741 QAccessibleInterface *acc_frequency = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("frequency")); |
|
742 |
|
743 QAccessibleInterface *acc_bottomRight = QAccessible::queryAccessibleInterface(bottomRight); |
|
744 |
|
745 QVERIFY(acc_toplevel); |
|
746 QVERIFY(acc_topLeft); |
|
747 QVERIFY(acc_topRight); |
|
748 QVERIFY(acc_bottomLeft); |
|
749 QVERIFY(acc_bottomRight); |
|
750 QVERIFY(acc_group1); |
|
751 QVERIFY(acc_group2); |
|
752 QVERIFY(acc_stack); |
|
753 QVERIFY(acc_page1); |
|
754 QVERIFY(acc_page2); |
|
755 QVERIFY(acc_page3); |
|
756 QVERIFY(acc_pbOk); |
|
757 QVERIFY(acc_slider); |
|
758 QVERIFY(acc_spinBox); |
|
759 QVERIFY(acc_sliderLcd); |
|
760 QVERIFY(acc_label); |
|
761 QVERIFY(acc_lineedit); |
|
762 QVERIFY(acc_radiogroup); |
|
763 QVERIFY(acc_radioAM); |
|
764 QVERIFY(acc_radioFM); |
|
765 QVERIFY(acc_radioSW); |
|
766 QVERIFY(acc_frequency); |
|
767 |
|
768 // hierachy relations |
|
769 QCOMPARE(acc_toplevel->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
770 QAccessible::Self); |
|
771 QCOMPARE(acc_toplevel->relationTo(1, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
772 QAccessible::Child); |
|
773 QCOMPARE(acc_toplevel->relationTo(0, acc_toplevel, 1) & QAccessible::HierarchyMask, |
|
774 QAccessible::Ancestor); |
|
775 |
|
776 QCOMPARE(acc_toplevel->relationTo(0, acc_topLeft, 0) & QAccessible::HierarchyMask, |
|
777 QAccessible::Ancestor); |
|
778 QCOMPARE(acc_toplevel->relationTo(0, acc_topRight, 0) & QAccessible::HierarchyMask, |
|
779 QAccessible::Ancestor); |
|
780 QCOMPARE(acc_toplevel->relationTo(0, acc_bottomLeft, 0) & QAccessible::HierarchyMask, |
|
781 QAccessible::Ancestor); |
|
782 QCOMPARE(acc_toplevel->relationTo(0, acc_bottomRight, 0) & QAccessible::HierarchyMask, |
|
783 QAccessible::Ancestor); |
|
784 |
|
785 QCOMPARE(acc_toplevel->relationTo(0, acc_group1, 0) & QAccessible::HierarchyMask, |
|
786 QAccessible::Ancestor); |
|
787 QCOMPARE(acc_toplevel->relationTo(0, acc_page1, 0) & QAccessible::HierarchyMask, |
|
788 QAccessible::Ancestor); |
|
789 QCOMPARE(acc_group1->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
790 QAccessible::Descendent); |
|
791 QCOMPARE(acc_stack->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
792 QAccessible::Descendent); |
|
793 QCOMPARE(acc_page1->relationTo(0, acc_stack, 0) & QAccessible::HierarchyMask, |
|
794 QAccessible::Child); |
|
795 QCOMPARE(acc_page1->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
796 QAccessible::Descendent); |
|
797 |
|
798 QCOMPARE(acc_topLeft->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
799 QAccessible::Child); |
|
800 QCOMPARE(acc_topRight->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
801 QAccessible::Child); |
|
802 QCOMPARE(acc_bottomLeft->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
803 QAccessible::Child); |
|
804 QCOMPARE(acc_bottomRight->relationTo(0, acc_toplevel, 0) & QAccessible::HierarchyMask, |
|
805 QAccessible::Child); |
|
806 |
|
807 QCOMPARE(acc_topLeft->relationTo(0, acc_topRight, 0) & QAccessible::HierarchyMask, |
|
808 QAccessible::Sibling); |
|
809 QCOMPARE(acc_topLeft->relationTo(0, acc_bottomLeft, 0) & QAccessible::HierarchyMask, |
|
810 QAccessible::Sibling); |
|
811 QCOMPARE(acc_topLeft->relationTo(0, acc_bottomRight, 0) & QAccessible::HierarchyMask, |
|
812 QAccessible::Sibling); |
|
813 |
|
814 QCOMPARE(acc_pb1->relationTo(0, acc_pb2, 0), QAccessible::Unrelated); |
|
815 |
|
816 // geometrical relations - only valid for siblings |
|
817 QCOMPARE(acc_topLeft->relationTo(0, acc_topRight, 0), QAccessible::Sibling | QAccessible::Left); |
|
818 QCOMPARE(acc_topLeft->relationTo(0, acc_bottomLeft, 0), QAccessible::Sibling | QAccessible::Up); |
|
819 QCOMPARE(acc_topLeft->relationTo(0, acc_bottomRight, 0), QAccessible::Sibling | QAccessible::Left | QAccessible::Up); |
|
820 |
|
821 QCOMPARE(acc_bottomRight->relationTo(0, acc_topLeft, 0), QAccessible::Sibling | QAccessible::Right | QAccessible::Down); |
|
822 QCOMPARE(acc_bottomRight->relationTo(0, acc_topRight, 0), QAccessible::Sibling | QAccessible::Down); |
|
823 QCOMPARE(acc_bottomRight->relationTo(0, acc_bottomLeft, 0), QAccessible::Sibling | QAccessible::Right); |
|
824 #ifdef Q_WS_MAC |
|
825 QEXPECT_FAIL("", "Task 155501", Continue); |
|
826 #endif |
|
827 QCOMPARE(acc_group1->relationTo(0, acc_group2, 0), QAccessible::Sibling | QAccessible::Up); |
|
828 #ifdef Q_WS_MAC |
|
829 QEXPECT_FAIL("", "Task 155501", Continue); |
|
830 #endif |
|
831 QCOMPARE(acc_group2->relationTo(0, acc_group1, 0), QAccessible::Sibling | QAccessible::Down); |
|
832 |
|
833 // Covers/Covered tested in navigateCovered |
|
834 |
|
835 // logical relations - focus |
|
836 QCOMPARE(acc_radioAM->relationTo(0, acc_radioFM, 0) & QAccessible::FocusChild, |
|
837 QAccessible::Unrelated); |
|
838 QCOMPARE(acc_radioAM->relationTo(0, acc_radiogroup, 0) & QAccessible::FocusChild, |
|
839 QAccessible::FocusChild); |
|
840 QCOMPARE(acc_radioAM->relationTo(0, acc_bottomLeft, 0) & QAccessible::FocusChild, |
|
841 QAccessible::FocusChild); |
|
842 QCOMPARE(acc_radioAM->relationTo(0, acc_topLeft, 0) & QAccessible::FocusChild, |
|
843 QAccessible::Unrelated); |
|
844 QCOMPARE(acc_radioAM->relationTo(0, acc_toplevel, 0) & QAccessible::FocusChild, |
|
845 QAccessible::FocusChild); |
|
846 |
|
847 // logical relations - labels |
|
848 QCOMPARE(acc_label->relationTo(0, acc_lineedit, 0) & QAccessible::LogicalMask, |
|
849 QAccessible::Label); |
|
850 QCOMPARE(acc_lineedit->relationTo(0, acc_label, 0) & QAccessible::LogicalMask, |
|
851 QAccessible::Labelled); |
|
852 QCOMPARE(acc_label->relationTo(0, acc_radiogroup, 0) & QAccessible::LogicalMask, |
|
853 QAccessible::Unrelated); |
|
854 QCOMPARE(acc_lineedit->relationTo(0, acc_lineedit, 0) & QAccessible::LogicalMask, |
|
855 QAccessible::Unrelated); |
|
856 |
|
857 QEXPECT_FAIL("", "Make me accessible", Continue); |
|
858 QCOMPARE(acc_radiogroup->relationTo(0, acc_radioAM, 0) & QAccessible::LogicalMask, |
|
859 QAccessible::Label | QAccessible::Controlled); |
|
860 QEXPECT_FAIL("", "Make me accessible", Continue); |
|
861 QCOMPARE(acc_radiogroup->relationTo(0, acc_radioFM, 0) & QAccessible::LogicalMask, |
|
862 QAccessible::Label | QAccessible::Controlled); |
|
863 QEXPECT_FAIL("", "Make me accessible", Continue); |
|
864 QCOMPARE(acc_radiogroup->relationTo(0, acc_radioSW, 0) & QAccessible::LogicalMask, |
|
865 QAccessible::Label | QAccessible::Controlled); |
|
866 QCOMPARE(acc_radiogroup->relationTo(0, acc_frequency, 0) & QAccessible::LogicalMask, |
|
867 QAccessible::Label); |
|
868 QCOMPARE(acc_frequency->relationTo(0, acc_radiogroup, 0) & QAccessible::LogicalMask, |
|
869 QAccessible::Labelled); |
|
870 QCOMPARE(acc_radiogroup->relationTo(0, acc_lineedit, 0) & QAccessible::LogicalMask, |
|
871 QAccessible::Unrelated); |
|
872 |
|
873 // logical relations - controller |
|
874 QCOMPARE(acc_pbOk->relationTo(0, acc_toplevel, 0) & QAccessible::LogicalMask, |
|
875 QAccessible::Controller); |
|
876 QCOMPARE(acc_slider->relationTo(0, acc_sliderLcd, 0) & QAccessible::LogicalMask, |
|
877 QAccessible::Controller); |
|
878 QCOMPARE(acc_spinBox->relationTo(0, acc_slider, 0) & QAccessible::LogicalMask, |
|
879 QAccessible::Controller); |
|
880 QCOMPARE(acc_lineedit->relationTo(0, acc_label2, 0) & QAccessible::LogicalMask, |
|
881 QAccessible::Controller); |
|
882 |
|
883 delete acc_toplevel; |
|
884 delete acc_topLeft; |
|
885 delete acc_group1; |
|
886 delete acc_pb1; |
|
887 delete acc_group2; |
|
888 delete acc_stack; |
|
889 delete acc_page1; |
|
890 delete acc_page2; |
|
891 delete acc_page3; |
|
892 delete acc_topRight; |
|
893 delete acc_pbOk; |
|
894 delete acc_slider; |
|
895 delete acc_spinBox; |
|
896 delete acc_sliderLcd; |
|
897 delete acc_bottomLeft; |
|
898 delete acc_label; |
|
899 delete acc_lineedit; |
|
900 delete acc_label2; |
|
901 delete acc_radiogroup; |
|
902 delete acc_radioAM; |
|
903 delete acc_radioFM; |
|
904 delete acc_radioSW; |
|
905 delete acc_frequency; |
|
906 delete acc_bottomRight; |
|
907 |
|
908 delete toplevel; |
|
909 |
|
910 QTestAccessibility::clearEvents(); |
|
911 #else |
|
912 QSKIP("Test needs accessibility support.", SkipAll); |
|
913 #endif |
|
914 #endif // !QT3_SUPPORT |
|
915 } |
|
916 |
|
917 void tst_QAccessibility::navigateGeometric() |
|
918 { |
|
919 #ifdef QTEST_ACCESSIBILITY |
|
920 { |
|
921 static const int skip = 20; //speed the test up significantly |
|
922 static const double step = Q_PI / 180; |
|
923 QWidget *w = new QWidget(0); |
|
924 w->setObjectName(QString("Josef")); |
|
925 w->setFixedSize(400, 400); |
|
926 |
|
927 // center widget |
|
928 QtTestAccessibleWidget *center = new QtTestAccessibleWidget(w, "Sol"); |
|
929 center->move(200, 200); |
|
930 |
|
931 // arrange 360 widgets around it in a circle |
|
932 QtTestAccessibleWidget *aw = 0; |
|
933 int i; |
|
934 for (i = 0; i < 360; i += skip) { |
|
935 aw = new QtTestAccessibleWidget(w, QString::number(i).toLatin1()); |
|
936 aw->move( int(200.0 + 100.0 * sin(step * (double)i)), int(200.0 + 100.0 * cos(step * (double)i)) ); |
|
937 } |
|
938 |
|
939 aw = new QtTestAccessibleWidget(w, "Earth"); |
|
940 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(center); |
|
941 QAccessibleInterface *target = 0; |
|
942 QVERIFY(iface != 0); |
|
943 QVERIFY(iface->isValid()); |
|
944 |
|
945 w->show(); |
|
946 #if defined(Q_WS_X11) |
|
947 qt_x11_wait_for_window_manager(w); |
|
948 QTest::qWait(100); |
|
949 #endif |
|
950 |
|
951 // let one widget rotate around center |
|
952 for (i = 0; i < 360; i+=skip) { |
|
953 aw->move( int(200.0 + 75.0 * sin(step * (double)i)), int(200.0 + 75.0 * cos(step * (double)i)) ); |
|
954 |
|
955 if (i < 45 || i > 315) { |
|
956 QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0); |
|
957 } else if ( i < 135 ) { |
|
958 QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0); |
|
959 } else if ( i < 225 ) { |
|
960 QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0); |
|
961 } else { |
|
962 QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0); |
|
963 } |
|
964 |
|
965 QVERIFY(target); |
|
966 QVERIFY(target->isValid()); |
|
967 QVERIFY(target->object()); |
|
968 QCOMPARE(target->object()->objectName(), aw->objectName()); |
|
969 delete target; target = 0; |
|
970 } |
|
971 |
|
972 // test invisible widget |
|
973 target = QAccessible::queryAccessibleInterface(aw); |
|
974 QVERIFY(!(target->state(0) & QAccessible::Invisible)); |
|
975 aw->hide(); |
|
976 QVERIFY(target->state(0) & QAccessible::Invisible); |
|
977 delete target; target = 0; |
|
978 |
|
979 aw->move(center->x() + 10, center->y()); |
|
980 QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0); |
|
981 QVERIFY(target); |
|
982 QVERIFY(target->isValid()); |
|
983 QVERIFY(target->object()); |
|
984 QVERIFY(QString(target->object()->objectName()) != "Earth"); |
|
985 delete target; target = 0; |
|
986 |
|
987 aw->move(center->x() - 10, center->y()); |
|
988 QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0); |
|
989 QVERIFY(target); |
|
990 QVERIFY(target->isValid()); |
|
991 QVERIFY(target->object()); |
|
992 QVERIFY(QString(target->object()->objectName()) != "Earth"); |
|
993 delete target; target = 0; |
|
994 |
|
995 aw->move(center->x(), center->y() + 10); |
|
996 QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0); |
|
997 QVERIFY(target); |
|
998 QVERIFY(target->isValid()); |
|
999 QVERIFY(target->object()); |
|
1000 QVERIFY(QString(target->object()->objectName()) != "Earth"); |
|
1001 delete target; target = 0; |
|
1002 |
|
1003 aw->move(center->x(), center->y() - 10); |
|
1004 QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0); |
|
1005 QVERIFY(target); |
|
1006 QVERIFY(target->isValid()); |
|
1007 QVERIFY(target->object()); |
|
1008 QVERIFY(QString(target->object()->objectName()) != "Earth"); |
|
1009 delete target; target = 0; |
|
1010 |
|
1011 delete iface; |
|
1012 delete w; |
|
1013 } |
|
1014 QTestAccessibility::clearEvents(); |
|
1015 #else |
|
1016 QSKIP("Test needs accessibility support.", SkipAll); |
|
1017 #endif |
|
1018 } |
|
1019 |
|
1020 void tst_QAccessibility::navigateSlider() |
|
1021 { |
|
1022 #ifdef QTEST_ACCESSIBILITY |
|
1023 { |
|
1024 QSlider *slider = new QSlider(0); |
|
1025 slider->setObjectName(QString("Slidy")); |
|
1026 slider->show(); |
|
1027 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(slider); |
|
1028 QAccessibleInterface *target = 0; |
|
1029 QVERIFY(iface != 0); |
|
1030 QVERIFY(iface->isValid()); |
|
1031 QCOMPARE(iface->childCount(), 3); |
|
1032 QCOMPARE(iface->navigate(QAccessible::Child, 1, &target), 1); |
|
1033 QVERIFY(target == 0); |
|
1034 QCOMPARE(iface->navigate(QAccessible::Child, 2, &target), 2); |
|
1035 QVERIFY(target == 0); |
|
1036 QCOMPARE(iface->navigate(QAccessible::Child, 3, &target), 3); |
|
1037 QVERIFY(target == 0); |
|
1038 QCOMPARE(iface->navigate(QAccessible::Child, 4, &target), -1); |
|
1039 QVERIFY(target == 0); |
|
1040 QCOMPARE(iface->navigate(QAccessible::Child, 0, &target), -1); |
|
1041 QVERIFY(target == 0); |
|
1042 QCOMPARE(iface->navigate(QAccessible::Child, -42, &target), -1); |
|
1043 QVERIFY(target == 0); |
|
1044 |
|
1045 delete iface; |
|
1046 delete slider; |
|
1047 } |
|
1048 QTestAccessibility::clearEvents(); |
|
1049 #else |
|
1050 QSKIP("Test needs accessibility support.", SkipAll); |
|
1051 #endif |
|
1052 } |
|
1053 |
|
1054 void tst_QAccessibility::navigateCovered() |
|
1055 { |
|
1056 #ifdef QTEST_ACCESSIBILITY |
|
1057 { |
|
1058 QWidget *w = new QWidget(0); |
|
1059 w->setObjectName(QString("Harry")); |
|
1060 QWidget *w1 = new QWidget(w); |
|
1061 w1->setObjectName(QString("1")); |
|
1062 QWidget *w2 = new QWidget(w); |
|
1063 w2->setObjectName(QString("2")); |
|
1064 w->show(); |
|
1065 #if defined(Q_WS_X11) |
|
1066 qt_x11_wait_for_window_manager(w); |
|
1067 QTest::qWait(100); |
|
1068 #endif |
|
1069 |
|
1070 w->setFixedSize(6, 6); |
|
1071 w1->setFixedSize(5, 5); |
|
1072 w2->setFixedSize(5, 5); |
|
1073 w2->move(0, 0); |
|
1074 w1->raise(); |
|
1075 |
|
1076 QAccessibleInterface *iface1 = QAccessible::queryAccessibleInterface(w1); |
|
1077 QVERIFY(iface1 != 0); |
|
1078 QVERIFY(iface1->isValid()); |
|
1079 QAccessibleInterface *iface2 = QAccessible::queryAccessibleInterface(w2); |
|
1080 QVERIFY(iface2 != 0); |
|
1081 QVERIFY(iface2->isValid()); |
|
1082 QAccessibleInterface *iface3 = 0; |
|
1083 |
|
1084 QCOMPARE(iface1->navigate(QAccessible::Covers, -42, &iface3), -1); |
|
1085 QVERIFY(iface3 == 0); |
|
1086 QCOMPARE(iface1->navigate(QAccessible::Covers, 0, &iface3), -1); |
|
1087 QVERIFY(iface3 == 0); |
|
1088 QCOMPARE(iface1->navigate(QAccessible::Covers, 2, &iface3), -1); |
|
1089 QVERIFY(iface3 == 0); |
|
1090 |
|
1091 for (int loop = 0; loop < 2; ++loop) { |
|
1092 for (int x = 0; x < w->width(); ++x) { |
|
1093 for (int y = 0; y < w->height(); ++y) { |
|
1094 w1->move(x, y); |
|
1095 if (w1->geometry().intersects(w2->geometry())) { |
|
1096 QVERIFY(iface1->relationTo(0, iface2, 0) & QAccessible::Covers); |
|
1097 QVERIFY(iface2->relationTo(0, iface1, 0) & QAccessible::Covered); |
|
1098 QCOMPARE(iface1->navigate(QAccessible::Covered, 1, &iface3), 0); |
|
1099 QVERIFY(iface3 != 0); |
|
1100 QVERIFY(iface3->isValid()); |
|
1101 QCOMPARE(iface3->object(), iface2->object()); |
|
1102 delete iface3; iface3 = 0; |
|
1103 QCOMPARE(iface2->navigate(QAccessible::Covers, 1, &iface3), 0); |
|
1104 QVERIFY(iface3 != 0); |
|
1105 QVERIFY(iface3->isValid()); |
|
1106 QCOMPARE(iface3->object(), iface1->object()); |
|
1107 delete iface3; iface3 = 0; |
|
1108 } else { |
|
1109 QVERIFY(!(iface1->relationTo(0, iface2, 0) & QAccessible::Covers)); |
|
1110 QVERIFY(!(iface2->relationTo(0, iface1, 0) & QAccessible::Covered)); |
|
1111 QCOMPARE(iface1->navigate(QAccessible::Covered, 1, &iface3), -1); |
|
1112 QVERIFY(iface3 == 0); |
|
1113 QCOMPARE(iface1->navigate(QAccessible::Covers, 1, &iface3), -1); |
|
1114 QVERIFY(iface3 == 0); |
|
1115 QCOMPARE(iface2->navigate(QAccessible::Covered, 1, &iface3), -1); |
|
1116 QVERIFY(iface3 == 0); |
|
1117 QCOMPARE(iface2->navigate(QAccessible::Covers, 1, &iface3), -1); |
|
1118 QVERIFY(iface3 == 0); |
|
1119 } |
|
1120 } |
|
1121 } |
|
1122 if (!loop) { |
|
1123 // switch children for second loop |
|
1124 w2->raise(); |
|
1125 QAccessibleInterface *temp = iface1; |
|
1126 iface1 = iface2; |
|
1127 iface2 = temp; |
|
1128 } |
|
1129 } |
|
1130 delete iface1; iface1 = 0; |
|
1131 delete iface2; iface2 = 0; |
|
1132 iface1 = QAccessible::queryAccessibleInterface(w1); |
|
1133 QVERIFY(iface1 != 0); |
|
1134 QVERIFY(iface1->isValid()); |
|
1135 iface2 = QAccessible::queryAccessibleInterface(w2); |
|
1136 QVERIFY(iface2 != 0); |
|
1137 QVERIFY(iface2->isValid()); |
|
1138 |
|
1139 w1->move(0,0); |
|
1140 w2->move(0,0); |
|
1141 w1->raise(); |
|
1142 QVERIFY(iface1->relationTo(0, iface2, 0) & QAccessible::Covers); |
|
1143 QVERIFY(iface2->relationTo(0, iface1, 0) & QAccessible::Covered); |
|
1144 QVERIFY(!(iface1->state(0) & QAccessible::Invisible)); |
|
1145 w1->hide(); |
|
1146 QVERIFY(iface1->state(0) & QAccessible::Invisible); |
|
1147 QVERIFY(!(iface1->relationTo(0, iface2, 0) & QAccessible::Covers)); |
|
1148 QVERIFY(!(iface2->relationTo(0, iface1, 0) & QAccessible::Covered)); |
|
1149 QCOMPARE(iface2->navigate(QAccessible::Covered, 1, &iface3), -1); |
|
1150 QVERIFY(iface3 == 0); |
|
1151 QCOMPARE(iface1->navigate(QAccessible::Covers, 1, &iface3), -1); |
|
1152 QVERIFY(iface3 == 0); |
|
1153 |
|
1154 delete iface1; iface1 = 0; |
|
1155 delete iface2; iface2 = 0; |
|
1156 delete w; |
|
1157 } |
|
1158 QTestAccessibility::clearEvents(); |
|
1159 #else |
|
1160 QSKIP("Test needs accessibility support.", SkipAll); |
|
1161 #endif |
|
1162 } |
|
1163 |
|
1164 void tst_QAccessibility::navigateHierarchy() |
|
1165 { |
|
1166 #ifdef QTEST_ACCESSIBILITY |
|
1167 { |
|
1168 QWidget *w = new QWidget(0); |
|
1169 w->setObjectName(QString("Hans")); |
|
1170 w->show(); |
|
1171 QWidget *w1 = new QWidget(w); |
|
1172 w1->setObjectName(QString("1")); |
|
1173 w1->show(); |
|
1174 QWidget *w2 = new QWidget(w); |
|
1175 w2->setObjectName(QString("2")); |
|
1176 w2->show(); |
|
1177 QWidget *w3 = new QWidget(w); |
|
1178 w3->setObjectName(QString("3")); |
|
1179 w3->show(); |
|
1180 QWidget *w31 = new QWidget(w3); |
|
1181 w31->setObjectName(QString("31")); |
|
1182 w31->show(); |
|
1183 |
|
1184 QAccessibleInterface *target = 0; |
|
1185 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(w); |
|
1186 QVERIFY(iface != 0); |
|
1187 QVERIFY(iface->isValid()); |
|
1188 |
|
1189 QCOMPARE(iface->navigate(QAccessible::Sibling, -42, &target), -1); |
|
1190 QVERIFY(target == 0); |
|
1191 QCOMPARE(iface->navigate(QAccessible::Sibling, 42, &target), -1); |
|
1192 QVERIFY(target == 0); |
|
1193 QCOMPARE(iface->navigate(QAccessible::Child, 15, &target), -1); |
|
1194 QVERIFY(target == 0); |
|
1195 QCOMPARE(iface->navigate(QAccessible::Child, 0, &target), -1); |
|
1196 QVERIFY(target == 0); |
|
1197 QCOMPARE(iface->navigate(QAccessible::Child, 1, &target), 0); |
|
1198 QVERIFY(target != 0); |
|
1199 QVERIFY(target->isValid()); |
|
1200 QCOMPARE(target->object(), (QObject*)w1); |
|
1201 delete iface; iface = 0; |
|
1202 |
|
1203 QCOMPARE(target->navigate(QAccessible::Sibling, 0, &iface), -1); |
|
1204 QVERIFY(iface == 0); |
|
1205 QCOMPARE(target->navigate(QAccessible::Sibling, 42, &iface), -1); |
|
1206 QVERIFY(iface == 0); |
|
1207 QCOMPARE(target->navigate(QAccessible::Sibling, -42, &iface), -1); |
|
1208 QVERIFY(iface == 0); |
|
1209 QCOMPARE(target->navigate(QAccessible::Sibling, 2, &iface), 0); |
|
1210 QVERIFY(iface != 0); |
|
1211 QVERIFY(iface->isValid()); |
|
1212 QCOMPARE(iface->object(), (QObject*)w2); |
|
1213 delete target; target = 0; |
|
1214 QCOMPARE(iface->navigate(QAccessible::Sibling, 3, &target), 0); |
|
1215 QVERIFY(target != 0); |
|
1216 QVERIFY(target->isValid()); |
|
1217 QCOMPARE(target->object(), (QObject*)w3); |
|
1218 delete iface; iface = 0; |
|
1219 |
|
1220 QCOMPARE(target->navigate(QAccessible::Child, 1, &iface), 0); |
|
1221 QVERIFY(iface != 0); |
|
1222 QVERIFY(iface->isValid()); |
|
1223 QCOMPARE(iface->object(), (QObject*)w31); |
|
1224 delete target; target = 0; |
|
1225 |
|
1226 QCOMPARE(iface->navigate(QAccessible::Sibling, -1, &target), -1); |
|
1227 QVERIFY(target == 0); |
|
1228 QCOMPARE(iface->navigate(QAccessible::Sibling, 0, &target), -1); |
|
1229 QVERIFY(target == 0); |
|
1230 QCOMPARE(iface->navigate(QAccessible::Sibling, 1, &target), 0); |
|
1231 QVERIFY(target != 0); |
|
1232 QVERIFY(target->isValid()); |
|
1233 QCOMPARE(target->object(), (QObject*)w31); |
|
1234 delete iface; iface = 0; |
|
1235 |
|
1236 QCOMPARE(target->navigate(QAccessible::Ancestor, 42, &iface), -1); |
|
1237 QVERIFY(iface == 0); |
|
1238 QCOMPARE(target->navigate(QAccessible::Ancestor, -1, &iface), -1); |
|
1239 QVERIFY(iface == 0); |
|
1240 QCOMPARE(target->navigate(QAccessible::Ancestor, 0, &iface), -1); |
|
1241 QVERIFY(iface == 0); |
|
1242 QCOMPARE(target->navigate(QAccessible::Ancestor, 1, &iface), 0); |
|
1243 QVERIFY(iface != 0); |
|
1244 QVERIFY(iface->isValid()); |
|
1245 QCOMPARE(iface->object(), (QObject*)w3); |
|
1246 delete iface; iface = 0; |
|
1247 QCOMPARE(target->navigate(QAccessible::Ancestor, 2, &iface), 0); |
|
1248 QVERIFY(iface != 0); |
|
1249 QVERIFY(iface->isValid()); |
|
1250 QCOMPARE(iface->object(), (QObject*)w); |
|
1251 delete iface; iface = 0; |
|
1252 QCOMPARE(target->navigate(QAccessible::Ancestor, 3, &iface), 0); |
|
1253 QVERIFY(iface != 0); |
|
1254 QVERIFY(iface->isValid()); |
|
1255 QCOMPARE(iface->object(), (QObject*)qApp); |
|
1256 delete iface; iface = 0; |
|
1257 delete target; target = 0; |
|
1258 |
|
1259 delete w; |
|
1260 } |
|
1261 QTestAccessibility::clearEvents(); |
|
1262 #else |
|
1263 QSKIP("Test needs accessibility support.", SkipAll); |
|
1264 #endif |
|
1265 } |
|
1266 |
|
1267 #define QSETCOMPARE(thetypename, elements, otherelements) \ |
|
1268 QCOMPARE((QSet<thetypename>() << elements), (QSet<thetypename>() << otherelements)) |
|
1269 |
|
1270 void tst_QAccessibility::navigateControllers() |
|
1271 { |
|
1272 #if !defined(QT3_SUPPORT) |
|
1273 QSKIP("This test needs Qt3Support", SkipAll); |
|
1274 #else |
|
1275 #ifdef QTEST_ACCESSIBILITY |
|
1276 { |
|
1277 Q3VBox vbox; |
|
1278 QSlider slider(&vbox); |
|
1279 QSpinBox spinBox(&vbox); |
|
1280 QLCDNumber lcd1(&vbox); |
|
1281 QLCDNumber lcd2(&vbox); |
|
1282 QLabel label(&vbox); |
|
1283 vbox.show(); |
|
1284 |
|
1285 slider.setObjectName("slider"); |
|
1286 spinBox.setObjectName("spinBox"); |
|
1287 lcd1.setObjectName("lcd1"); |
|
1288 lcd2.setObjectName("lcd2"); |
|
1289 label.setObjectName("label"); |
|
1290 |
|
1291 QTestAccessibility::clearEvents(); |
|
1292 |
|
1293 connect(&slider, SIGNAL(valueChanged(int)), &lcd1, SLOT(display(int))); |
|
1294 connect(&slider, SIGNAL(valueChanged(int)), &lcd2, SLOT(display(int))); |
|
1295 connect(&spinBox, SIGNAL(valueChanged(int)), &lcd2, SLOT(display(int))); |
|
1296 connect(&spinBox, SIGNAL(valueChanged(int)), &lcd1, SLOT(display(int))); |
|
1297 connect(&spinBox, SIGNAL(valueChanged(const QString&)), &label, SLOT(setText(const QString&))); |
|
1298 |
|
1299 QAccessibleInterface *acc_slider = QAccessible::queryAccessibleInterface(&slider); |
|
1300 QAccessibleInterface *acc_spinBox = QAccessible::queryAccessibleInterface(&spinBox); |
|
1301 QAccessibleInterface *acc_lcd1 = QAccessible::queryAccessibleInterface(&lcd1); |
|
1302 QAccessibleInterface *acc_lcd2 = QAccessible::queryAccessibleInterface(&lcd2); |
|
1303 QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(&label); |
|
1304 |
|
1305 QVERIFY(acc_slider->relationTo(0, acc_lcd1, 0) & QAccessible::Controller); |
|
1306 QVERIFY(acc_slider->relationTo(0, acc_lcd2, 0) & QAccessible::Controller); |
|
1307 QVERIFY(acc_spinBox->relationTo(0, acc_lcd1, 0) & QAccessible::Controller); |
|
1308 QVERIFY(acc_spinBox->relationTo(0, acc_lcd2, 0) & QAccessible::Controller); |
|
1309 QVERIFY(acc_spinBox->relationTo(0, acc_label, 0) & QAccessible::Controller); |
|
1310 |
|
1311 QAccessibleInterface *acc_target1, *acc_target2, *acc_target3; |
|
1312 // from controller |
|
1313 QCOMPARE(acc_slider->navigate(QAccessible::Controlled, 0, &acc_target1), -1); |
|
1314 QVERIFY(!acc_target1); |
|
1315 QCOMPARE(acc_slider->navigate(QAccessible::Controlled, 1, &acc_target1), 0); |
|
1316 QCOMPARE(acc_slider->navigate(QAccessible::Controlled, 2, &acc_target2), 0); |
|
1317 QSETCOMPARE(QObject*, acc_lcd1->object() << acc_lcd2->object(), |
|
1318 acc_target1->object() << acc_target2->object()); |
|
1319 delete acc_target1; |
|
1320 delete acc_target2; |
|
1321 |
|
1322 QCOMPARE(acc_slider->navigate(QAccessible::Controlled, 3, &acc_target1), -1); |
|
1323 QVERIFY(!acc_target1); |
|
1324 |
|
1325 QCOMPARE(acc_spinBox->navigate(QAccessible::Controlled, 0, &acc_target1), -1); |
|
1326 QVERIFY(!acc_target1); |
|
1327 QCOMPARE(acc_spinBox->navigate(QAccessible::Controlled, 1, &acc_target1), 0); |
|
1328 QCOMPARE(acc_spinBox->navigate(QAccessible::Controlled, 2, &acc_target2), 0); |
|
1329 QCOMPARE(acc_spinBox->navigate(QAccessible::Controlled, 3, &acc_target3), 0); |
|
1330 QSETCOMPARE(QObject*, acc_lcd1->object() << acc_lcd2->object() << acc_label->object(), |
|
1331 acc_target1->object() << acc_target2->object() << acc_target3->object()); |
|
1332 delete acc_target1; |
|
1333 delete acc_target2; |
|
1334 delete acc_target3; |
|
1335 |
|
1336 QCOMPARE(acc_spinBox->navigate(QAccessible::Controlled, 4, &acc_target1), -1); |
|
1337 QVERIFY(!acc_target1); |
|
1338 |
|
1339 // to controller |
|
1340 QCOMPARE(acc_lcd1->navigate(QAccessible::Controller, 0, &acc_target1), -1); |
|
1341 QVERIFY(!acc_target1); |
|
1342 QCOMPARE(acc_lcd1->navigate(QAccessible::Controller, 1, &acc_target1), 0); |
|
1343 QCOMPARE(acc_lcd1->navigate(QAccessible::Controller, 2, &acc_target2), 0); |
|
1344 QSETCOMPARE(QObject*, acc_slider->object() << acc_spinBox->object(), |
|
1345 acc_target1->object() << acc_target2->object()); |
|
1346 delete acc_target1; |
|
1347 delete acc_target2; |
|
1348 QCOMPARE(acc_lcd1->navigate(QAccessible::Controller, 3, &acc_target1), -1); |
|
1349 QVERIFY(!acc_target1); |
|
1350 |
|
1351 delete acc_label; |
|
1352 delete acc_lcd2; |
|
1353 delete acc_lcd1; |
|
1354 delete acc_spinBox; |
|
1355 delete acc_slider; |
|
1356 } |
|
1357 QTestAccessibility::clearEvents(); |
|
1358 #else |
|
1359 QSKIP("Test needs accessibility support.", SkipAll); |
|
1360 #endif |
|
1361 #endif // !QT3_SUPPORT |
|
1362 } |
|
1363 |
|
1364 void tst_QAccessibility::navigateLabels() |
|
1365 { |
|
1366 #if !defined(QT3_SUPPORT) |
|
1367 QSKIP("This test needs Qt3Support", SkipAll); |
|
1368 #else |
|
1369 #ifdef QTEST_ACCESSIBILITY |
|
1370 { |
|
1371 Q3VBox vbox; |
|
1372 Q3HBox hbox(&vbox); |
|
1373 |
|
1374 QLabel label(&hbox); |
|
1375 label.setText("This is a lineedit:"); |
|
1376 QLineEdit lineedit(&hbox); |
|
1377 label.setBuddy(&lineedit); |
|
1378 |
|
1379 Q3VButtonGroup groupbox(&vbox); |
|
1380 groupbox.setTitle("Be my children!"); |
|
1381 QRadioButton radio(&groupbox); |
|
1382 QLabel label2(&groupbox); |
|
1383 label2.setText("Another lineedit:"); |
|
1384 QLineEdit lineedit2(&groupbox); |
|
1385 label2.setBuddy(&lineedit2); |
|
1386 Q3GroupBox groupbox2(&groupbox); |
|
1387 groupbox2.setTitle("Some grand-children"); |
|
1388 QLineEdit grandchild(&groupbox2); |
|
1389 |
|
1390 Q3GroupBox border(&vbox); |
|
1391 QLineEdit lineedit3(&border); |
|
1392 vbox.show(); |
|
1393 QTestAccessibility::clearEvents(); |
|
1394 |
|
1395 QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(&label); |
|
1396 QAccessibleInterface *acc_lineedit = QAccessible::queryAccessibleInterface(&lineedit); |
|
1397 QAccessibleInterface *acc_groupbox = QAccessible::queryAccessibleInterface(&groupbox); |
|
1398 QAccessibleInterface *acc_radio = QAccessible::queryAccessibleInterface(&radio); |
|
1399 QAccessibleInterface *acc_label2 = QAccessible::queryAccessibleInterface(&label2); |
|
1400 QAccessibleInterface *acc_lineedit2 = QAccessible::queryAccessibleInterface(&lineedit2); |
|
1401 QAccessibleInterface *acc_groupbox2 = QAccessible::queryAccessibleInterface(&groupbox2); |
|
1402 QAccessibleInterface *acc_grandchild = QAccessible::queryAccessibleInterface(&grandchild); |
|
1403 QAccessibleInterface *acc_border = QAccessible::queryAccessibleInterface(&border); |
|
1404 QAccessibleInterface *acc_lineedit3 = QAccessible::queryAccessibleInterface(&lineedit3); |
|
1405 |
|
1406 QVERIFY(acc_label->relationTo(0, acc_lineedit,0) & QAccessible::Label); |
|
1407 QVERIFY(acc_groupbox->relationTo(0, acc_radio,0) & QAccessible::Label); |
|
1408 QVERIFY(acc_groupbox->relationTo(0, acc_lineedit2,0) & QAccessible::Label); |
|
1409 QVERIFY(acc_groupbox->relationTo(0, acc_groupbox2,0) & QAccessible::Label); |
|
1410 QVERIFY(acc_groupbox2->relationTo(0, acc_grandchild,0) & QAccessible::Label); |
|
1411 QVERIFY(!(acc_border->relationTo(0, acc_lineedit3,0) & QAccessible::Label)); |
|
1412 |
|
1413 QAccessibleInterface *acc_target; |
|
1414 // from label |
|
1415 QCOMPARE(acc_label->navigate(QAccessible::Labelled, 0, &acc_target), -1); |
|
1416 QVERIFY(!acc_target); |
|
1417 QCOMPARE(acc_label->navigate(QAccessible::Labelled, 1, &acc_target), 0); |
|
1418 QVERIFY(acc_target->object() == acc_lineedit->object()); |
|
1419 delete acc_target; acc_target = 0; |
|
1420 QCOMPARE(acc_label->navigate(QAccessible::Labelled, 2, &acc_target), -1); |
|
1421 QVERIFY(!acc_target); |
|
1422 |
|
1423 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 0, &acc_target), -1); |
|
1424 QVERIFY(!acc_target); |
|
1425 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 1, &acc_target), 0); |
|
1426 QVERIFY(acc_target->object() == acc_radio->object()); |
|
1427 delete acc_target; acc_target = 0; |
|
1428 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 2, &acc_target), 0); |
|
1429 QVERIFY(acc_target->object() == acc_label2->object()); |
|
1430 delete acc_target; acc_target = 0; |
|
1431 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 3, &acc_target), 0); |
|
1432 QVERIFY(acc_target->object() == acc_lineedit2->object()); |
|
1433 delete acc_target; acc_target = 0; |
|
1434 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 4, &acc_target), 0); |
|
1435 QVERIFY(acc_target->object() == acc_groupbox2->object()); |
|
1436 delete acc_target; acc_target = 0; |
|
1437 QCOMPARE(acc_groupbox->navigate(QAccessible::Labelled, 5, &acc_target), -1); |
|
1438 QVERIFY(!acc_target); |
|
1439 |
|
1440 QCOMPARE(acc_border->navigate(QAccessible::Labelled, 0, &acc_target), -1); |
|
1441 QVERIFY(!acc_target); |
|
1442 QCOMPARE(acc_border->navigate(QAccessible::Labelled, 1, &acc_target), -1); |
|
1443 QVERIFY(!acc_target); |
|
1444 |
|
1445 // to label |
|
1446 QCOMPARE(acc_lineedit->navigate(QAccessible::Label, 0, &acc_target), -1); |
|
1447 QVERIFY(!acc_target); |
|
1448 QCOMPARE(acc_lineedit->navigate(QAccessible::Label, 1, &acc_target), 0); |
|
1449 QVERIFY(acc_target->object() == acc_label->object()); |
|
1450 delete acc_target; acc_target = 0; |
|
1451 QCOMPARE(acc_lineedit->navigate(QAccessible::Label, 2, &acc_target), -1); |
|
1452 QVERIFY(!acc_target); |
|
1453 |
|
1454 QCOMPARE(acc_radio->navigate(QAccessible::Label, 0, &acc_target), -1); |
|
1455 QVERIFY(!acc_target); |
|
1456 QCOMPARE(acc_radio->navigate(QAccessible::Label, 1, &acc_target), 0); |
|
1457 QVERIFY(acc_target->object() == acc_groupbox->object()); |
|
1458 delete acc_target; acc_target = 0; |
|
1459 QCOMPARE(acc_radio->navigate(QAccessible::Label, 2, &acc_target), -1); |
|
1460 QVERIFY(!acc_target); |
|
1461 |
|
1462 QCOMPARE(acc_lineedit2->navigate(QAccessible::Label, 1, &acc_target), 0); |
|
1463 QVERIFY(acc_target->object() == acc_label2->object()); |
|
1464 delete acc_target; acc_target = 0; |
|
1465 QCOMPARE(acc_lineedit2->navigate(QAccessible::Label, 2, &acc_target), 0); |
|
1466 QVERIFY(acc_target->object() == acc_groupbox->object()); |
|
1467 delete acc_target; acc_target = 0; |
|
1468 QCOMPARE(acc_lineedit2->navigate(QAccessible::Label, 3, &acc_target), -1); |
|
1469 QVERIFY(!acc_target); |
|
1470 |
|
1471 QCOMPARE(acc_grandchild->navigate(QAccessible::Label, 1, &acc_target), 0); |
|
1472 QVERIFY(acc_target->object() == acc_groupbox2->object()); |
|
1473 delete acc_target; acc_target = 0; |
|
1474 QCOMPARE(acc_grandchild->navigate(QAccessible::Label, 2, &acc_target), -1); |
|
1475 QVERIFY(!acc_target); |
|
1476 QCOMPARE(acc_grandchild->navigate(QAccessible::Label, 3, &acc_target), -1); |
|
1477 QVERIFY(!acc_target); |
|
1478 |
|
1479 delete acc_label; |
|
1480 delete acc_lineedit; |
|
1481 delete acc_groupbox; |
|
1482 delete acc_radio; |
|
1483 delete acc_label2; |
|
1484 delete acc_lineedit2; |
|
1485 delete acc_groupbox2; |
|
1486 delete acc_grandchild; |
|
1487 delete acc_border; |
|
1488 delete acc_lineedit3; |
|
1489 } |
|
1490 QTestAccessibility::clearEvents(); |
|
1491 #else |
|
1492 QSKIP("Test needs accessibility support.", SkipAll); |
|
1493 #endif |
|
1494 #endif // !QT3_SUPPORT |
|
1495 } |
|
1496 |
|
1497 static QWidget *createWidgets() |
|
1498 { |
|
1499 QWidget *w = new QWidget(); |
|
1500 |
|
1501 QHBoxLayout *box = new QHBoxLayout(w); |
|
1502 |
|
1503 int i = 0; |
|
1504 box->addWidget(new QComboBox(w)); |
|
1505 box->addWidget(new QPushButton(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1506 box->addWidget(new QHeaderView(Qt::Vertical, w)); |
|
1507 box->addWidget(new QTreeView(w)); |
|
1508 box->addWidget(new QTreeWidget(w)); |
|
1509 box->addWidget(new QListView(w)); |
|
1510 box->addWidget(new QListWidget(w)); |
|
1511 box->addWidget(new QTableView(w)); |
|
1512 box->addWidget(new QTableWidget(w)); |
|
1513 box->addWidget(new QCalendarWidget(w)); |
|
1514 box->addWidget(new QDialogButtonBox(w)); |
|
1515 box->addWidget(new QGroupBox(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1516 box->addWidget(new QFrame(w)); |
|
1517 box->addWidget(new QLineEdit(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1518 box->addWidget(new QProgressBar(w)); |
|
1519 box->addWidget(new QTabWidget(w)); |
|
1520 box->addWidget(new QCheckBox(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1521 box->addWidget(new QRadioButton(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1522 box->addWidget(new QDial(w)); |
|
1523 box->addWidget(new QScrollBar(w)); |
|
1524 box->addWidget(new QSlider(w)); |
|
1525 box->addWidget(new QDateTimeEdit(w)); |
|
1526 box->addWidget(new QDoubleSpinBox(w)); |
|
1527 box->addWidget(new QSpinBox(w)); |
|
1528 box->addWidget(new QLabel(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1529 box->addWidget(new QLCDNumber(w)); |
|
1530 box->addWidget(new QStackedWidget(w)); |
|
1531 box->addWidget(new QToolBox(w)); |
|
1532 box->addWidget(new QLabel(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1533 box->addWidget(new QTextEdit(QString::fromAscii("widget text %1").arg(i++), w)); |
|
1534 |
|
1535 /* Not in the list |
|
1536 * QAbstractItemView, QGraphicsView, QScrollArea, |
|
1537 * QToolButton, QDockWidget, QFocusFrame, QMainWindow, QMenu, QMenuBar, QSizeGrip, QSplashScreen, QSplitterHandle, |
|
1538 * QStatusBar, QSvgWidget, QTabBar, QToolBar, QWorkspace, QSplitter |
|
1539 */ |
|
1540 return w; |
|
1541 } |
|
1542 |
|
1543 void tst_QAccessibility::accessibleName() |
|
1544 { |
|
1545 #ifdef QTEST_ACCESSIBILITY |
|
1546 QWidget *toplevel = createWidgets(); |
|
1547 toplevel->show(); |
|
1548 #if defined(Q_WS_X11) |
|
1549 qt_x11_wait_for_window_manager(toplevel); |
|
1550 QTest::qWait(100); |
|
1551 #endif |
|
1552 QLayout *lout = toplevel->layout(); |
|
1553 for (int i = 0; i < lout->count(); i++) { |
|
1554 QLayoutItem *item = lout->itemAt(i); |
|
1555 QWidget *child = item->widget(); |
|
1556 |
|
1557 QString name = tr("Widget Name %1").arg(i); |
|
1558 child->setAccessibleName(name); |
|
1559 QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(child); |
|
1560 QCOMPARE(acc->text(QAccessible::Name, 0), name); |
|
1561 |
|
1562 QString desc = tr("Widget Description %1").arg(i); |
|
1563 child->setAccessibleDescription(desc); |
|
1564 QCOMPARE(acc->text(QAccessible::Description, 0), desc); |
|
1565 |
|
1566 } |
|
1567 |
|
1568 delete toplevel; |
|
1569 QTestAccessibility::clearEvents(); |
|
1570 #else |
|
1571 QSKIP("Test needs accessibility support.", SkipAll); |
|
1572 #endif |
|
1573 } |
|
1574 |
|
1575 void tst_QAccessibility::text() |
|
1576 { |
|
1577 #if !defined(QT3_SUPPORT) |
|
1578 QSKIP("This test needs Qt3Support", SkipAll); |
|
1579 #else |
|
1580 #ifdef QTEST_ACCESSIBILITY |
|
1581 QWidget *toplevel = createGUI(); |
|
1582 toplevel->show(); |
|
1583 #if defined(Q_WS_X11) |
|
1584 qt_x11_wait_for_window_manager(toplevel); |
|
1585 QTest::qWait(100); |
|
1586 #endif |
|
1587 QObject *topLeft = toplevel->child("topLeft"); |
|
1588 QObject *topRight = toplevel->child("topRight"); |
|
1589 QObject *bottomLeft = toplevel->child("bottomLeft"); |
|
1590 |
|
1591 QAccessibleInterface *acc_pb1 = QAccessible::queryAccessibleInterface(topLeft->child("pb1")); |
|
1592 |
|
1593 QAccessibleInterface *acc_pbOk = QAccessible::queryAccessibleInterface(topRight->child("pbOk")); |
|
1594 QAccessibleInterface *acc_slider = QAccessible::queryAccessibleInterface(topRight->child("slider")); |
|
1595 QAccessibleInterface *acc_spinBox = QAccessible::queryAccessibleInterface(topRight->child("spinBox")); |
|
1596 QAccessibleInterface *acc_sliderLcd = QAccessible::queryAccessibleInterface(topRight->child("sliderLcd")); |
|
1597 |
|
1598 QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(bottomLeft->child("label")); |
|
1599 QAccessibleInterface *acc_lineedit = QAccessible::queryAccessibleInterface(bottomLeft->child("lineedit")); |
|
1600 QAccessibleInterface *acc_radiogroup = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")); |
|
1601 QVERIFY(bottomLeft->child("radiogroup")); |
|
1602 QAccessibleInterface *acc_radioAM = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("radioAM")); |
|
1603 QAccessibleInterface *acc_frequency = QAccessible::queryAccessibleInterface(bottomLeft->child("radiogroup")->child("frequency")); |
|
1604 |
|
1605 QVERIFY(acc_pb1); |
|
1606 |
|
1607 QVERIFY(acc_pbOk); |
|
1608 QVERIFY(acc_slider); |
|
1609 QVERIFY(acc_spinBox); |
|
1610 QVERIFY(acc_sliderLcd); |
|
1611 |
|
1612 QVERIFY(acc_label); |
|
1613 QVERIFY(acc_lineedit); |
|
1614 QVERIFY(acc_radiogroup); |
|
1615 QVERIFY(acc_radioAM); |
|
1616 QVERIFY(acc_frequency); |
|
1617 |
|
1618 QVERIFY(acc_label->relationTo(0, acc_lineedit, 0) & QAccessible::Label); |
|
1619 QVERIFY(acc_radiogroup->relationTo(0, acc_frequency, 0) & QAccessible::Label); |
|
1620 QVERIFY(acc_slider->relationTo(0, acc_sliderLcd, 0) & QAccessible::Controller); |
|
1621 QVERIFY(acc_spinBox->relationTo(0, acc_slider, 0) & QAccessible::Controller); |
|
1622 |
|
1623 // Name |
|
1624 QCOMPARE(acc_lineedit->text(QAccessible::Name, 0), acc_label->text(QAccessible::Name,0)); |
|
1625 QCOMPARE(acc_frequency->text(QAccessible::Name, 0), acc_radiogroup->text(QAccessible::Name,0)); |
|
1626 QCOMPARE(acc_sliderLcd->text(QAccessible::Name, 0), acc_slider->text(QAccessible::Value,0)); |
|
1627 QCOMPARE(acc_pbOk->text(QAccessible::Name, 0), QString("Ok")); |
|
1628 QCOMPARE(acc_radioAM->text(QAccessible::Name, 0), QString("AM")); |
|
1629 QCOMPARE(acc_pb1->text(QAccessible::Name, 0), QString("Button1")); |
|
1630 |
|
1631 // Description |
|
1632 QString desc = qobject_cast<QWidget*>(acc_label->object())->toolTip(); |
|
1633 QVERIFY(!desc.isEmpty()); |
|
1634 QCOMPARE(acc_label->text(QAccessible::Description, 0), desc); |
|
1635 desc = qobject_cast<QWidget*>(acc_lineedit->object())->toolTip(); |
|
1636 QVERIFY(!desc.isEmpty()); |
|
1637 QCOMPARE(acc_lineedit->text(QAccessible::Description, 0), desc); |
|
1638 |
|
1639 // Help |
|
1640 QString help = qobject_cast<QWidget*>(acc_label->object())->whatsThis(); |
|
1641 QVERIFY(!help.isEmpty()); |
|
1642 QCOMPARE(acc_label->text(QAccessible::Help, 0), help); |
|
1643 help = qobject_cast<QWidget*>(acc_frequency->object())->whatsThis(); |
|
1644 QVERIFY(!help.isEmpty()); |
|
1645 QCOMPARE(acc_frequency->text(QAccessible::Help, 0), help); |
|
1646 |
|
1647 // Value |
|
1648 QString value = acc_frequency->object()->property("text").toString(); |
|
1649 QVERIFY(!value.isEmpty()); |
|
1650 QCOMPARE(acc_frequency->text(QAccessible::Value, 0), value); |
|
1651 value = acc_slider->object()->property("value").toString(); |
|
1652 QVERIFY(!value.isEmpty()); |
|
1653 QCOMPARE(acc_slider->text(QAccessible::Value, 0), value); |
|
1654 QCOMPARE(acc_spinBox->text(QAccessible::Value, 0), value); |
|
1655 |
|
1656 // Accelerator |
|
1657 QCOMPARE(acc_pbOk->text(QAccessible::Accelerator, 0), Q3Accel::keyToString(Qt::Key_Enter)); |
|
1658 QCOMPARE(acc_pb1->text(QAccessible::Accelerator, 0), Q3Accel::keyToString(Qt::ALT + Qt::Key_1)); |
|
1659 QCOMPARE(acc_lineedit->text(QAccessible::Accelerator, 0), Q3Accel::keyToString(Qt::ALT) + "L"); |
|
1660 QCOMPARE(acc_frequency->text(QAccessible::Accelerator, 0), Q3Accel::keyToString(Qt::ALT) + "C"); |
|
1661 |
|
1662 delete acc_pb1; |
|
1663 delete acc_pbOk; |
|
1664 delete acc_slider; |
|
1665 delete acc_spinBox; |
|
1666 delete acc_sliderLcd; |
|
1667 |
|
1668 delete acc_label; |
|
1669 delete acc_lineedit; |
|
1670 delete acc_radiogroup; |
|
1671 delete acc_radioAM; |
|
1672 delete acc_frequency; |
|
1673 |
|
1674 delete toplevel; |
|
1675 QTestAccessibility::clearEvents(); |
|
1676 |
|
1677 #else |
|
1678 QSKIP("Test needs accessibility support.", SkipAll); |
|
1679 #endif |
|
1680 #endif // !QT3_SUPPORT |
|
1681 } |
|
1682 |
|
1683 void tst_QAccessibility::setText() |
|
1684 { |
|
1685 #if !defined(QT3_SUPPORT) |
|
1686 QSKIP("This test needs Qt3Support", SkipAll); |
|
1687 #else |
|
1688 #ifdef QTEST_ACCESSIBILITY |
|
1689 QWidget *toplevel = createGUI(); |
|
1690 toplevel->show(); |
|
1691 QObject *bottomLeft = toplevel->findChild<QObject *>("bottomLeft"); |
|
1692 |
|
1693 QAccessibleInterface *acc_lineedit = QAccessible::queryAccessibleInterface(bottomLeft->findChild<QLineEdit *>("lineedit")); |
|
1694 // Value, read-write |
|
1695 QString txt = acc_lineedit->text(QAccessible::Value, 0); |
|
1696 QVERIFY(txt.isEmpty()); |
|
1697 txt = QLatin1String("Writable"); |
|
1698 acc_lineedit->setText(QAccessible::Value, 0, txt); |
|
1699 QCOMPARE(acc_lineedit->text(QAccessible::Value, 0), txt); |
|
1700 |
|
1701 // Description, read-only |
|
1702 txt = acc_lineedit->text(QAccessible::Description, 0); |
|
1703 QVERIFY(!txt.isEmpty()); |
|
1704 acc_lineedit->setText(QAccessible::Description, 0, QLatin1String("")); |
|
1705 QCOMPARE(acc_lineedit->text(QAccessible::Description, 0), txt); |
|
1706 |
|
1707 QVERIFY(acc_lineedit); |
|
1708 |
|
1709 delete acc_lineedit; |
|
1710 delete toplevel; |
|
1711 QTestAccessibility::clearEvents(); |
|
1712 |
|
1713 #else |
|
1714 QSKIP("Test needs accessibility support.", SkipAll); |
|
1715 #endif |
|
1716 #endif //QT3_SUPPORT |
|
1717 } |
|
1718 |
|
1719 void tst_QAccessibility::hideShowTest() |
|
1720 { |
|
1721 #ifdef QTEST_ACCESSIBILITY |
|
1722 QWidget * const window = new QWidget(); |
|
1723 QWidget * const child = new QWidget(window); |
|
1724 |
|
1725 QVERIFY(state(window) & QAccessible::Invisible); |
|
1726 QVERIFY(state(child) & QAccessible::Invisible); |
|
1727 |
|
1728 QTestAccessibility::clearEvents(); |
|
1729 |
|
1730 // show() and veryfy that both window and child are not invisible and get ObjectShow events. |
|
1731 window->show(); |
|
1732 QVERIFY(state(window) ^ QAccessible::Invisible); |
|
1733 QVERIFY(state(child) ^ QAccessible::Invisible); |
|
1734 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, 0, QAccessible::ObjectShow))); |
|
1735 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, 0, QAccessible::ObjectShow))); |
|
1736 QTestAccessibility::clearEvents(); |
|
1737 |
|
1738 // hide() and veryfy that both window and child are invisible and get ObjectHide events. |
|
1739 window->hide(); |
|
1740 QVERIFY(state(window) & QAccessible::Invisible); |
|
1741 QVERIFY(state(child) & QAccessible::Invisible); |
|
1742 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, 0, QAccessible::ObjectHide))); |
|
1743 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, 0, QAccessible::ObjectHide))); |
|
1744 QTestAccessibility::clearEvents(); |
|
1745 |
|
1746 delete window; |
|
1747 QTestAccessibility::clearEvents(); |
|
1748 #else |
|
1749 QSKIP("Test needs accessibility support.", SkipAll); |
|
1750 #endif |
|
1751 } |
|
1752 |
|
1753 void tst_QAccessibility::userActionCount() |
|
1754 { |
|
1755 #ifdef QTEST_ACCESSIBILITY |
|
1756 QWidget widget; |
|
1757 |
|
1758 QAccessibleInterface *test = QAccessible::queryAccessibleInterface(&widget); |
|
1759 QVERIFY(test); |
|
1760 QVERIFY(test->isValid()); |
|
1761 QCOMPARE(test->userActionCount(0), 0); |
|
1762 QCOMPARE(test->userActionCount(1), 0); |
|
1763 QCOMPARE(test->userActionCount(-1), 0); |
|
1764 delete test; test = 0; |
|
1765 |
|
1766 QFrame frame; |
|
1767 |
|
1768 test = QAccessible::queryAccessibleInterface(&frame); |
|
1769 QVERIFY(test); |
|
1770 QVERIFY(test->isValid()); |
|
1771 QCOMPARE(test->userActionCount(0), 0); |
|
1772 QCOMPARE(test->userActionCount(1), 0); |
|
1773 QCOMPARE(test->userActionCount(-1), 0); |
|
1774 delete test; test = 0; |
|
1775 |
|
1776 QLineEdit lineEdit; |
|
1777 |
|
1778 test = QAccessible::queryAccessibleInterface(&lineEdit); |
|
1779 QVERIFY(test); |
|
1780 QVERIFY(test->isValid()); |
|
1781 QCOMPARE(test->userActionCount(0), 0); |
|
1782 QCOMPARE(test->userActionCount(1), 0); |
|
1783 QCOMPARE(test->userActionCount(-1), 0); |
|
1784 delete test; test = 0; |
|
1785 #else |
|
1786 QSKIP("Test needs accessibility support.", SkipAll); |
|
1787 #endif |
|
1788 } |
|
1789 |
|
1790 void tst_QAccessibility::actionText() |
|
1791 { |
|
1792 #ifdef QTEST_ACCESSIBILITY |
|
1793 QWidget widget; |
|
1794 widget.show(); |
|
1795 |
|
1796 QAccessibleInterface *test = QAccessible::queryAccessibleInterface(&widget); |
|
1797 QVERIFY(test); |
|
1798 QVERIFY(test->isValid()); |
|
1799 |
|
1800 QCOMPARE(test->actionText(1, QAccessible::Name, 0), QString()); |
|
1801 QCOMPARE(test->actionText(0, QAccessible::Name, 1), QString()); |
|
1802 QCOMPARE(test->actionText(1, QAccessible::Name, 1), QString()); |
|
1803 QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, -1), QString()); |
|
1804 |
|
1805 QCOMPARE(test->actionText(QAccessible::DefaultAction, QAccessible::Name, 0), QString("SetFocus")); |
|
1806 QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, 0), QString("SetFocus")); |
|
1807 |
|
1808 delete test; test = 0; |
|
1809 |
|
1810 #else |
|
1811 QSKIP("Test needs accessibility support.", SkipAll); |
|
1812 #endif |
|
1813 } |
|
1814 |
|
1815 void tst_QAccessibility::doAction() |
|
1816 { |
|
1817 #ifdef QTEST_ACCESSIBILITY |
|
1818 QSKIP("TODO: Implement me", SkipAll); |
|
1819 #else |
|
1820 QSKIP("Test needs accessibility support.", SkipAll); |
|
1821 #endif |
|
1822 } |
|
1823 |
|
1824 void tst_QAccessibility::buttonTest() |
|
1825 { |
|
1826 //#ifdef QTEST_ACCESSIBILITY |
|
1827 #if 0 |
|
1828 QAccessibleInterface *test = 0; |
|
1829 Q3VBox vbox; |
|
1830 |
|
1831 // Standard push button |
|
1832 QPushButton pushButton("Ok", &vbox); |
|
1833 |
|
1834 // toggle push button |
|
1835 QPushButton togglepush("Toggle", &vbox); |
|
1836 togglepush.setToggleButton(TRUE); |
|
1837 |
|
1838 // push button with a menu |
|
1839 QPushButton menuButton("Menu", &vbox); |
|
1840 Q3PopupMenu buttonMenu(&menuButton); |
|
1841 buttonMenu.insertItem("Some item"); |
|
1842 menuButton.setPopup(&buttonMenu); |
|
1843 |
|
1844 // standard checkbox |
|
1845 QCheckBox checkBox("Check me!", &vbox); |
|
1846 |
|
1847 // tristate checkbox |
|
1848 QCheckBox tristate("Tristate!", &vbox); |
|
1849 tristate.setTristate(TRUE); |
|
1850 |
|
1851 // radiobutton |
|
1852 QRadioButton radio("Radio me!", &vbox); |
|
1853 |
|
1854 // standard toolbutton |
|
1855 QToolButton toolbutton(&vbox); |
|
1856 toolbutton.setText("Tool"); |
|
1857 toolbutton.setMinimumSize(20,20); |
|
1858 |
|
1859 // standard toolbutton |
|
1860 QToolButton toggletool(&vbox); |
|
1861 toggletool.setToggleButton(TRUE); |
|
1862 toggletool.setText("Toggle"); |
|
1863 toggletool.setMinimumSize(20,20); |
|
1864 |
|
1865 // menu toolbutton |
|
1866 QToolButton menuToolButton(&vbox); |
|
1867 menuToolButton.setText("Menu Tool"); |
|
1868 Q3PopupMenu toolMenu(&menuToolButton); |
|
1869 toolMenu.insertItem("Some item"); |
|
1870 menuToolButton.setPopup(&toolMenu); |
|
1871 menuToolButton.setMinimumSize(20,20); |
|
1872 |
|
1873 // splitted menu toolbutton |
|
1874 QToolButton splitToolButton(&vbox); |
|
1875 splitToolButton.setTextLabel("Split Tool"); |
|
1876 Q3PopupMenu splitMenu(&splitToolButton); |
|
1877 splitMenu.insertItem("Some item"); |
|
1878 splitToolButton.setPopup(&splitMenu); |
|
1879 splitToolButton.setPopupDelay(0); |
|
1880 splitToolButton.setMinimumSize(20,20); |
|
1881 |
|
1882 // test push button |
|
1883 QVERIFY(QAccessible::queryAccessibleInterface(&pushButton, &test)); |
|
1884 QCOMPARE(test->role(0), QAccessible::PushButton); |
|
1885 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1886 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Press")); |
|
1887 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1888 pushButton.setDown(TRUE); |
|
1889 QCOMPARE(test->state(0), (int)QAccessible::Pressed); |
|
1890 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1891 QTest::qWait(500); |
|
1892 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1893 test->release(); |
|
1894 |
|
1895 // test toggle push button |
|
1896 QVERIFY(QAccessible::queryAccessibleInterface(&togglepush, &test)); |
|
1897 QCOMPARE(test->role(0), QAccessible::CheckBox); |
|
1898 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1899 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1900 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1901 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1902 QTest::qWait(500); |
|
1903 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Uncheck")); |
|
1904 QCOMPARE(test->state(0), (int)QAccessible::Checked); |
|
1905 test->release(); |
|
1906 |
|
1907 // test menu push button |
|
1908 QVERIFY(QAccessible::queryAccessibleInterface(&menuButton, &test)); |
|
1909 QCOMPARE(test->role(0), QAccessible::ButtonMenu); |
|
1910 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1911 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Open")); |
|
1912 QCOMPARE(test->state(0), (int)QAccessible::HasPopup); |
|
1913 test->release(); |
|
1914 |
|
1915 // test check box |
|
1916 QVERIFY(QAccessible::queryAccessibleInterface(&checkBox, &test)); |
|
1917 QCOMPARE(test->role(0), QAccessible::CheckBox); |
|
1918 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1919 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1920 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1921 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1922 QTest::qWait(500); |
|
1923 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Uncheck")); |
|
1924 QCOMPARE(test->state(0), (int)QAccessible::Checked); |
|
1925 test->release(); |
|
1926 |
|
1927 // test tristate check box |
|
1928 QVERIFY(QAccessible::queryAccessibleInterface(&tristate, &test)); |
|
1929 QCOMPARE(test->role(0), QAccessible::CheckBox); |
|
1930 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1931 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Toggle")); |
|
1932 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1933 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1934 QTest::qWait(500); |
|
1935 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1936 QCOMPARE(test->state(0), (int)QAccessible::Mixed); |
|
1937 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1938 QTest::qWait(500); |
|
1939 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Uncheck")); |
|
1940 QCOMPARE(test->state(0), (int)QAccessible::Checked); |
|
1941 test->release(); |
|
1942 |
|
1943 // test radiobutton |
|
1944 QVERIFY(QAccessible::queryAccessibleInterface(&radio, &test)); |
|
1945 QCOMPARE(test->role(0), QAccessible::RadioButton); |
|
1946 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1947 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1948 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1949 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1950 QTest::qWait(500); |
|
1951 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1952 QCOMPARE(test->state(0), (int)QAccessible::Checked); |
|
1953 test->release(); |
|
1954 |
|
1955 // test standard toolbutton |
|
1956 QVERIFY(QAccessible::queryAccessibleInterface(&toolbutton, &test)); |
|
1957 QCOMPARE(test->role(0), QAccessible::PushButton); |
|
1958 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1959 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Press")); |
|
1960 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1961 test->release(); |
|
1962 |
|
1963 // toggle tool button |
|
1964 QVERIFY(QAccessible::queryAccessibleInterface(&toggletool, &test)); |
|
1965 QCOMPARE(test->role(0), QAccessible::CheckBox); |
|
1966 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1967 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Check")); |
|
1968 QCOMPARE(test->state(0), (int)QAccessible::Normal); |
|
1969 QVERIFY(test->doAction(QAccessible::Press, 0)); |
|
1970 QTest::qWait(500); |
|
1971 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Uncheck")); |
|
1972 QCOMPARE(test->state(0), (int)QAccessible::Checked); |
|
1973 test->release(); |
|
1974 |
|
1975 // test menu toolbutton |
|
1976 QVERIFY(QAccessible::queryAccessibleInterface(&menuToolButton, &test)); |
|
1977 QCOMPARE(test->role(0), QAccessible::ButtonMenu); |
|
1978 QCOMPARE(test->defaultAction(0), 1); |
|
1979 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Open")); |
|
1980 QCOMPARE(test->state(0), (int)QAccessible::HasPopup); |
|
1981 QCOMPARE(test->actionCount(0), 1); |
|
1982 QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 0), QString("Press")); |
|
1983 test->release(); |
|
1984 |
|
1985 // test splitted menu toolbutton |
|
1986 QVERIFY(QAccessible::queryAccessibleInterface(&splitToolButton, &test)); |
|
1987 QCOMPARE(test->childCount(), 2); |
|
1988 QCOMPARE(test->role(0), QAccessible::ButtonDropDown); |
|
1989 QCOMPARE(test->role(1), QAccessible::PushButton); |
|
1990 QCOMPARE(test->role(2), QAccessible::ButtonMenu); |
|
1991 QCOMPARE(test->defaultAction(0), QAccessible::Press); |
|
1992 QCOMPARE(test->defaultAction(1), QAccessible::Press); |
|
1993 QCOMPARE(test->defaultAction(2), QAccessible::Press); |
|
1994 QCOMPARE(test->actionText(test->defaultAction(0), QAccessible::Name, 0), QString("Press")); |
|
1995 QCOMPARE(test->state(0), (int)QAccessible::HasPopup); |
|
1996 QCOMPARE(test->actionCount(0), 1); |
|
1997 QCOMPARE(test->actionText(1, QAccessible::Name, 0), QString("Open")); |
|
1998 QCOMPARE(test->actionText(test->defaultAction(1), QAccessible::Name, 1), QString("Press")); |
|
1999 QCOMPARE(test->state(1), (int)QAccessible::Normal); |
|
2000 QCOMPARE(test->actionText(test->defaultAction(2), QAccessible::Name, 2), QString("Open")); |
|
2001 QCOMPARE(test->state(2), (int)QAccessible::HasPopup); |
|
2002 test->release(); |
|
2003 |
|
2004 QTestAccessibility::clearEvents(); |
|
2005 |
|
2006 #else |
|
2007 // QSKIP("Test needs accessibility support.", SkipAll); |
|
2008 QSKIP("No action interface in Qt 4 yet.", SkipAll); |
|
2009 #endif |
|
2010 } |
|
2011 |
|
2012 void tst_QAccessibility::sliderTest() |
|
2013 { |
|
2014 #if !defined(QT3_SUPPORT) |
|
2015 QSKIP("This test needs Qt3Support", SkipAll); |
|
2016 #else |
|
2017 #ifdef QTEST_ACCESSIBILITY |
|
2018 QAccessibleInterface *test = 0; |
|
2019 Q3VBox vbox; |
|
2020 QLabel labelHorizontal("Horizontal", &vbox); |
|
2021 QSlider sliderHorizontal(Qt::Horizontal, &vbox); |
|
2022 labelHorizontal.setBuddy(&sliderHorizontal); |
|
2023 |
|
2024 QLabel labelVertical("Vertical", &vbox); |
|
2025 QSlider sliderVertical(Qt::Vertical, &vbox); |
|
2026 labelVertical.setBuddy(&sliderVertical); |
|
2027 vbox.show(); |
|
2028 |
|
2029 // test horizontal slider |
|
2030 test = QAccessible::queryAccessibleInterface(&sliderHorizontal); |
|
2031 QVERIFY(test); |
|
2032 QCOMPARE(test->childCount(), 3); |
|
2033 QCOMPARE(test->role(0), QAccessible::Slider); |
|
2034 QCOMPARE(test->role(1), QAccessible::PushButton); |
|
2035 QCOMPARE(test->role(2), QAccessible::Indicator); |
|
2036 QCOMPARE(test->role(3), QAccessible::PushButton); |
|
2037 |
|
2038 QCOMPARE(test->text(QAccessible::Name, 0), labelHorizontal.text()); |
|
2039 QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page left")); |
|
2040 QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position")); |
|
2041 QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page right")); |
|
2042 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.value())); |
|
2043 QCOMPARE(test->text(QAccessible::Value, 1), QString()); |
|
2044 QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderHorizontal.value())); |
|
2045 QCOMPARE(test->text(QAccessible::Value, 3), QString()); |
|
2046 // Skip acton tests. |
|
2047 #if 0 |
|
2048 QCOMPARE(test->defaultAction(0), QAccessible::SetFocus); |
|
2049 QCOMPARE(test->defaultAction(1), QAccessible::Press); |
|
2050 QCOMPARE(test->defaultAction(2), QAccessible::NoAction); |
|
2051 QCOMPARE(test->defaultAction(3), QAccessible::Press); |
|
2052 QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, 0), QSlider::tr("Set Focus")); |
|
2053 QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 1), QSlider::tr("Press")); |
|
2054 QCOMPARE(test->actionText(QAccessible::Increase, QAccessible::Name, 2), QSlider::tr("Increase")); |
|
2055 QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease")); |
|
2056 QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press")); |
|
2057 QVERIFY(test->doAction(QAccessible::Press, 3)); |
|
2058 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.pageStep())); |
|
2059 QVERIFY(test->doAction(QAccessible::Press, 3)); |
|
2060 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal.pageStep())); |
|
2061 QVERIFY(test->doAction(QAccessible::Press, 1)); |
|
2062 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.pageStep())); |
|
2063 QVERIFY(test->doAction(QAccessible::Press, 1)); |
|
2064 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); |
|
2065 QVERIFY(test->doAction(QAccessible::Increase, 2)); |
|
2066 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.lineStep())); |
|
2067 QVERIFY(test->doAction(QAccessible::Increase, 2)); |
|
2068 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal.lineStep())); |
|
2069 QVERIFY(test->doAction(QAccessible::Decrease, 2)); |
|
2070 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.lineStep())); |
|
2071 QVERIFY(test->doAction(QAccessible::Decrease, 2)); |
|
2072 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); |
|
2073 #endif |
|
2074 delete test; |
|
2075 |
|
2076 // test vertical slider |
|
2077 test = QAccessible::queryAccessibleInterface(&sliderVertical); |
|
2078 QVERIFY(test); |
|
2079 QCOMPARE(test->childCount(), 3); |
|
2080 QCOMPARE(test->role(0), QAccessible::Slider); |
|
2081 QCOMPARE(test->role(1), QAccessible::PushButton); |
|
2082 QCOMPARE(test->role(2), QAccessible::Indicator); |
|
2083 QCOMPARE(test->role(3), QAccessible::PushButton); |
|
2084 |
|
2085 QCOMPARE(test->text(QAccessible::Name, 0), labelVertical.text()); |
|
2086 QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page up")); |
|
2087 QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position")); |
|
2088 QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page down")); |
|
2089 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.value())); |
|
2090 QCOMPARE(test->text(QAccessible::Value, 1), QString()); |
|
2091 QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderVertical.value())); |
|
2092 QCOMPARE(test->text(QAccessible::Value, 3), QString()); |
|
2093 // Skip acton tests. |
|
2094 #if 0 |
|
2095 QCOMPARE(test->defaultAction(0), QAccessible::SetFocus); |
|
2096 QCOMPARE(test->defaultAction(1), QAccessible::Press); |
|
2097 QCOMPARE(test->defaultAction(2), QAccessible::NoAction); |
|
2098 QCOMPARE(test->defaultAction(3), QAccessible::Press); |
|
2099 QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, 0), QSlider::tr("Set Focus")); |
|
2100 QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 1), QSlider::tr("Press")); |
|
2101 QCOMPARE(test->actionText(QAccessible::Increase, QAccessible::Name, 2), QSlider::tr("Increase")); |
|
2102 QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease")); |
|
2103 QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press")); |
|
2104 QVERIFY(test->doAction(QAccessible::Press, 3)); |
|
2105 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.pageStep())); |
|
2106 QVERIFY(test->doAction(QAccessible::Press, 3)); |
|
2107 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical.pageStep())); |
|
2108 QVERIFY(test->doAction(QAccessible::Press, 1)); |
|
2109 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.pageStep())); |
|
2110 QVERIFY(test->doAction(QAccessible::Press, 1)); |
|
2111 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); |
|
2112 QVERIFY(test->doAction(QAccessible::Increase, 2)); |
|
2113 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.lineStep())); |
|
2114 QVERIFY(test->doAction(QAccessible::Increase, 2)); |
|
2115 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical.lineStep())); |
|
2116 QVERIFY(test->doAction(QAccessible::Decrease, 2)); |
|
2117 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.lineStep())); |
|
2118 QVERIFY(test->doAction(QAccessible::Decrease, 2)); |
|
2119 QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); |
|
2120 #endif |
|
2121 delete test; |
|
2122 |
|
2123 // Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the |
|
2124 // Invisible state bit set. |
|
2125 enum SubControls { PageLeft = 1, Position = 2, PageRight = 3 }; |
|
2126 |
|
2127 QSlider *slider = new QSlider(); |
|
2128 QAccessibleInterface * const sliderInterface = QAccessible::queryAccessibleInterface(slider); |
|
2129 QVERIFY(sliderInterface); |
|
2130 |
|
2131 QVERIFY(sliderInterface->state(0) & QAccessible::Invisible); |
|
2132 QVERIFY(sliderInterface->state(PageLeft) & QAccessible::Invisible); |
|
2133 QVERIFY(sliderInterface->state(Position) & QAccessible::Invisible); |
|
2134 QVERIFY(sliderInterface->state(PageRight) & QAccessible::Invisible); |
|
2135 |
|
2136 slider->show(); |
|
2137 QVERIFY(sliderInterface->state(0) ^ QAccessible::Invisible); |
|
2138 QVERIFY(sliderInterface->state(PageLeft) ^ QAccessible::Invisible); |
|
2139 QVERIFY(sliderInterface->state(Position) ^ QAccessible::Invisible); |
|
2140 QVERIFY(sliderInterface->state(PageRight) ^ QAccessible::Invisible); |
|
2141 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(slider, 0, QAccessible::ObjectShow))); |
|
2142 QTestAccessibility::clearEvents(); |
|
2143 |
|
2144 slider->hide(); |
|
2145 QVERIFY(sliderInterface->state(0) & QAccessible::Invisible); |
|
2146 QVERIFY(sliderInterface->state(PageLeft) & QAccessible::Invisible); |
|
2147 QVERIFY(sliderInterface->state(Position) & QAccessible::Invisible); |
|
2148 QVERIFY(sliderInterface->state(PageRight) & QAccessible::Invisible); |
|
2149 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(slider, 0, QAccessible::ObjectHide))); |
|
2150 QTestAccessibility::clearEvents(); |
|
2151 |
|
2152 // Test that the left/right subcontrols are set to unavailable when the slider is at the minimum/maximum. |
|
2153 slider->show(); |
|
2154 slider->setMinimum(0); |
|
2155 slider->setMaximum(100); |
|
2156 |
|
2157 slider->setValue(50); |
|
2158 QVERIFY(sliderInterface->state(PageLeft) ^ QAccessible::Unavailable); |
|
2159 QVERIFY(sliderInterface->state(Position) ^ QAccessible::Unavailable); |
|
2160 QVERIFY(sliderInterface->state(PageRight) ^ QAccessible::Unavailable); |
|
2161 |
|
2162 slider->setValue(0); |
|
2163 QVERIFY(sliderInterface->state(PageLeft) & QAccessible::Unavailable); |
|
2164 QVERIFY(sliderInterface->state(Position) ^ QAccessible::Unavailable); |
|
2165 QVERIFY(sliderInterface->state(PageRight) ^ QAccessible::Unavailable); |
|
2166 |
|
2167 slider->setValue(100); |
|
2168 QVERIFY(sliderInterface->state(PageLeft) ^ QAccessible::Unavailable); |
|
2169 QVERIFY(sliderInterface->state(Position) ^ QAccessible::Unavailable); |
|
2170 QVERIFY(sliderInterface->state(PageRight) & QAccessible::Unavailable); |
|
2171 |
|
2172 delete sliderInterface; |
|
2173 delete slider; |
|
2174 |
|
2175 // Test that the rects are ok. |
|
2176 { |
|
2177 QSlider *slider = new QSlider(Qt::Horizontal); |
|
2178 slider->show(); |
|
2179 #if defined(Q_WS_X11) |
|
2180 qt_x11_wait_for_window_manager(slider); |
|
2181 QTest::qWait(100); |
|
2182 #endif |
|
2183 QAccessibleInterface * const sliderInterface = QAccessible::queryAccessibleInterface(slider); |
|
2184 QVERIFY(sliderInterface); |
|
2185 |
|
2186 slider->setMinimum(0); |
|
2187 slider->setMaximum(100); |
|
2188 slider->setValue(50); |
|
2189 |
|
2190 const QRect sliderRect = sliderInterface->rect(0); |
|
2191 QVERIFY(sliderRect.isValid()); |
|
2192 |
|
2193 // Verify that the sub-control rects are valid and inside the slider rect. |
|
2194 for (int i = PageLeft; i <= PageRight; ++i) { |
|
2195 const QRect testRect = sliderInterface->rect(i); |
|
2196 QVERIFY(testRect.isValid()); |
|
2197 QVERIFY(sliderRect.contains(testRect)); |
|
2198 } |
|
2199 |
|
2200 delete slider; |
|
2201 delete sliderInterface; |
|
2202 } |
|
2203 |
|
2204 |
|
2205 QTestAccessibility::clearEvents(); |
|
2206 #else |
|
2207 QSKIP("Test needs accessibility support.", SkipAll); |
|
2208 #endif |
|
2209 #endif //!QT3_SUPPORT |
|
2210 } |
|
2211 |
|
2212 void tst_QAccessibility::scrollBarTest() |
|
2213 { |
|
2214 #ifdef QTEST_ACCESSIBILITY |
|
2215 // Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the |
|
2216 // Invisible state bit set. |
|
2217 enum SubControls { LineUp = 1, |
|
2218 PageUp = 2, |
|
2219 Position = 3, |
|
2220 PageDown = 4, |
|
2221 LineDown = 5 |
|
2222 }; |
|
2223 |
|
2224 QScrollBar *scrollBar = new QScrollBar(); |
|
2225 QAccessibleInterface * const scrollBarInterface = QAccessible::queryAccessibleInterface(scrollBar); |
|
2226 QVERIFY(scrollBarInterface); |
|
2227 |
|
2228 QVERIFY(scrollBarInterface->state(0) & QAccessible::Invisible); |
|
2229 QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Invisible); |
|
2230 QVERIFY(scrollBarInterface->state(Position) & QAccessible::Invisible); |
|
2231 QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Invisible); |
|
2232 |
|
2233 scrollBar->show(); |
|
2234 QVERIFY(scrollBarInterface->state(0) ^ QAccessible::Invisible); |
|
2235 QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Invisible); |
|
2236 QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Invisible); |
|
2237 QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Invisible); |
|
2238 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectShow))); |
|
2239 QTestAccessibility::clearEvents(); |
|
2240 |
|
2241 scrollBar->hide(); |
|
2242 QVERIFY(scrollBarInterface->state(0) & QAccessible::Invisible); |
|
2243 QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Invisible); |
|
2244 QVERIFY(scrollBarInterface->state(Position) & QAccessible::Invisible); |
|
2245 QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Invisible); |
|
2246 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectHide))); |
|
2247 QTestAccessibility::clearEvents(); |
|
2248 |
|
2249 // Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum. |
|
2250 scrollBar->show(); |
|
2251 scrollBar->setMinimum(0); |
|
2252 scrollBar->setMaximum(100); |
|
2253 |
|
2254 scrollBar->setValue(50); |
|
2255 QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Unavailable); |
|
2256 QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable); |
|
2257 QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Unavailable); |
|
2258 |
|
2259 scrollBar->setValue(0); |
|
2260 QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Unavailable); |
|
2261 QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable); |
|
2262 QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Unavailable); |
|
2263 |
|
2264 scrollBar->setValue(100); |
|
2265 QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Unavailable); |
|
2266 QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable); |
|
2267 QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Unavailable); |
|
2268 |
|
2269 delete scrollBarInterface; |
|
2270 delete scrollBar; |
|
2271 |
|
2272 // Test that the rects are ok. |
|
2273 { |
|
2274 QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal); |
|
2275 scrollBar->resize(200, 50); |
|
2276 scrollBar->show(); |
|
2277 #if defined(Q_WS_X11) |
|
2278 qt_x11_wait_for_window_manager(scrollBar); |
|
2279 QTest::qWait(100); |
|
2280 #endif |
|
2281 QAccessibleInterface * const scrollBarInterface = QAccessible::queryAccessibleInterface(scrollBar); |
|
2282 QVERIFY(scrollBarInterface); |
|
2283 |
|
2284 scrollBar->setMinimum(0); |
|
2285 scrollBar->setMaximum(100); |
|
2286 scrollBar->setValue(50); |
|
2287 |
|
2288 QApplication::processEvents(); |
|
2289 |
|
2290 const QRect scrollBarRect = scrollBarInterface->rect(0); |
|
2291 QVERIFY(scrollBarRect.isValid()); |
|
2292 |
|
2293 // Verify that the sub-control rects are valid and inside the scrollBar rect. |
|
2294 for (int i = LineUp; i <= LineDown; ++i) { |
|
2295 const QRect testRect = scrollBarInterface->rect(i); |
|
2296 QVERIFY(testRect.isValid()); |
|
2297 QVERIFY(scrollBarRect.contains(testRect)); |
|
2298 } |
|
2299 delete scrollBarInterface; |
|
2300 delete scrollBar; |
|
2301 } |
|
2302 |
|
2303 QTestAccessibility::clearEvents(); |
|
2304 #else |
|
2305 QSKIP("Test needs accessibility support.", SkipAll); |
|
2306 #endif |
|
2307 |
|
2308 } |
|
2309 |
|
2310 void tst_QAccessibility::tabTest() |
|
2311 { |
|
2312 #ifdef QTEST_ACCESSIBILITY |
|
2313 QTabBar *tabBar = new QTabBar(); |
|
2314 tabBar->show(); |
|
2315 |
|
2316 QAccessibleInterface * const interface = QAccessible::queryAccessibleInterface(tabBar); |
|
2317 QVERIFY(interface); |
|
2318 QCOMPARE(interface->childCount(), 2); |
|
2319 interface->doAction(QAccessible::Press, 1); |
|
2320 interface->doAction(QAccessible::Press, 2); |
|
2321 |
|
2322 // Test that the Invisible bit for the navigation buttons gets set |
|
2323 // and cleared correctly. |
|
2324 QVERIFY(interface->state(1) & QAccessible::Invisible); |
|
2325 |
|
2326 const int lots = 10; |
|
2327 for (int i = 0; i < lots; ++i) |
|
2328 tabBar->addTab("Foo"); |
|
2329 |
|
2330 QVERIFY((interface->state(1) & QAccessible::Invisible) == false); |
|
2331 tabBar->hide(); |
|
2332 QVERIFY(interface->state(1) & QAccessible::Invisible); |
|
2333 |
|
2334 tabBar->show(); |
|
2335 tabBar->setCurrentIndex(0); |
|
2336 |
|
2337 // Test that sending a focus action to a tab does not select it. |
|
2338 interface->doAction(QAccessible::Focus, 2, QVariantList()); |
|
2339 QCOMPARE(tabBar->currentIndex(), 0); |
|
2340 |
|
2341 // Test that sending a press action to a tab selects it. |
|
2342 interface->doAction(QAccessible::Press, 2, QVariantList()); |
|
2343 QCOMPARE(tabBar->currentIndex(), 1); |
|
2344 |
|
2345 delete tabBar; |
|
2346 delete interface; |
|
2347 QTestAccessibility::clearEvents(); |
|
2348 #else |
|
2349 QSKIP("Test needs accessibility support.", SkipAll); |
|
2350 #endif |
|
2351 } |
|
2352 |
|
2353 void tst_QAccessibility::menuTest() |
|
2354 { |
|
2355 #ifdef QTEST_ACCESSIBILITY |
|
2356 { |
|
2357 QMainWindow mw; |
|
2358 mw.resize(300, 200); |
|
2359 QMenu *file = mw.menuBar()->addMenu("&File"); |
|
2360 QMenu *fileNew = file->addMenu("&New..."); |
|
2361 fileNew->menuAction()->setShortcut(tr("Ctrl+N")); |
|
2362 fileNew->addAction("Text file"); |
|
2363 fileNew->addAction("Image file"); |
|
2364 file->addAction("&Open")->setShortcut(tr("Ctrl+O")); |
|
2365 file->addAction("&Save")->setShortcut(tr("Ctrl+S")); |
|
2366 file->addSeparator(); |
|
2367 file->addAction("E&xit")->setShortcut(tr("Alt+F4")); |
|
2368 |
|
2369 QMenu *edit = mw.menuBar()->addMenu("&Edit"); |
|
2370 edit->addAction("&Undo")->setShortcut(tr("Ctrl+Z")); |
|
2371 edit->addAction("&Redo")->setShortcut(tr("Ctrl+Y")); |
|
2372 edit->addSeparator(); |
|
2373 edit->addAction("Cu&t")->setShortcut(tr("Ctrl+X")); |
|
2374 edit->addAction("&Copy")->setShortcut(tr("Ctrl+C")); |
|
2375 edit->addAction("&Paste")->setShortcut(tr("Ctrl+V")); |
|
2376 edit->addAction("&Delete")->setShortcut(tr("Del")); |
|
2377 edit->addSeparator(); |
|
2378 edit->addAction("Pr&operties"); |
|
2379 |
|
2380 mw.menuBar()->addSeparator(); |
|
2381 |
|
2382 QMenu *help = mw.menuBar()->addMenu("&Help"); |
|
2383 help->addAction("&Contents"); |
|
2384 help->addAction("&About"); |
|
2385 |
|
2386 mw.menuBar()->addAction("Action!"); |
|
2387 |
|
2388 mw.show(); // triggers layout |
|
2389 QTest::qWait(100); |
|
2390 |
|
2391 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(mw.menuBar()); |
|
2392 |
|
2393 QCOMPARE(verifyHierarchy(interface), 0); |
|
2394 |
|
2395 QVERIFY(interface); |
|
2396 QCOMPARE(interface->childCount(), 5); |
|
2397 QCOMPARE(interface->role(0), QAccessible::MenuBar); |
|
2398 QCOMPARE(interface->role(1), QAccessible::MenuItem); |
|
2399 QCOMPARE(interface->role(2), QAccessible::MenuItem); |
|
2400 QCOMPARE(interface->role(3), QAccessible::Separator); |
|
2401 QCOMPARE(interface->role(4), QAccessible::MenuItem); |
|
2402 QCOMPARE(interface->role(5), QAccessible::MenuItem); |
|
2403 #ifndef Q_WS_MAC |
|
2404 #ifdef Q_OS_WINCE |
|
2405 if (!IsValidCEPlatform()) { |
|
2406 QSKIP("Tests do not work on Mobile platforms due to native menus", SkipAll); |
|
2407 } |
|
2408 #endif |
|
2409 QCOMPARE(mw.mapFromGlobal(interface->rect(0).topLeft()), mw.menuBar()->geometry().topLeft()); |
|
2410 QCOMPARE(interface->rect(0).size(), mw.menuBar()->size()); |
|
2411 |
|
2412 QVERIFY(interface->rect(0).contains(interface->rect(1))); |
|
2413 QVERIFY(interface->rect(0).contains(interface->rect(2))); |
|
2414 // QVERIFY(interface->rect(0).contains(interface->rect(3))); //separator might be invisible |
|
2415 QVERIFY(interface->rect(0).contains(interface->rect(4))); |
|
2416 QVERIFY(interface->rect(0).contains(interface->rect(5))); |
|
2417 #endif |
|
2418 |
|
2419 QCOMPARE(interface->text(QAccessible::Name, 1), QString("File")); |
|
2420 QCOMPARE(interface->text(QAccessible::Name, 2), QString("Edit")); |
|
2421 QCOMPARE(interface->text(QAccessible::Name, 3), QString()); |
|
2422 QCOMPARE(interface->text(QAccessible::Name, 4), QString("Help")); |
|
2423 QCOMPARE(interface->text(QAccessible::Name, 5), QString("Action!")); |
|
2424 |
|
2425 // TODO: Currently not working, task to fix is #100019. |
|
2426 #ifndef Q_OS_MAC |
|
2427 QCOMPARE(interface->text(QAccessible::Accelerator, 1), tr("Alt+F")); |
|
2428 QCOMPARE(interface->text(QAccessible::Accelerator, 2), tr("Alt+E")); |
|
2429 QCOMPARE(interface->text(QAccessible::Accelerator, 4), tr("Alt+H")); |
|
2430 QCOMPARE(interface->text(QAccessible::Accelerator, 3), QString()); |
|
2431 QCOMPARE(interface->text(QAccessible::Accelerator, 4), tr("Alt+H")); |
|
2432 QCOMPARE(interface->text(QAccessible::Accelerator, 5), QString()); |
|
2433 #endif |
|
2434 |
|
2435 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 1), QString("Open")); |
|
2436 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 2), QString("Open")); |
|
2437 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 3), QString()); |
|
2438 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 4), QString("Open")); |
|
2439 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 5), QString("Execute")); |
|
2440 |
|
2441 bool menuFade = qApp->isEffectEnabled(Qt::UI_FadeMenu); |
|
2442 int menuFadeDelay = 300; |
|
2443 interface->doAction(QAccessible::DefaultAction, 1); |
|
2444 if(menuFade) |
|
2445 QTest::qWait(menuFadeDelay); |
|
2446 QVERIFY(file->isVisible() && !edit->isVisible() && !help->isVisible()); |
|
2447 interface->doAction(QAccessible::DefaultAction, 2); |
|
2448 if(menuFade) |
|
2449 QTest::qWait(menuFadeDelay); |
|
2450 QVERIFY(!file->isVisible() && edit->isVisible() && !help->isVisible()); |
|
2451 interface->doAction(QAccessible::DefaultAction, 3); |
|
2452 if(menuFade) |
|
2453 QTest::qWait(menuFadeDelay); |
|
2454 QVERIFY(!file->isVisible() && !edit->isVisible() && !help->isVisible()); |
|
2455 interface->doAction(QAccessible::DefaultAction, 4); |
|
2456 if(menuFade) |
|
2457 QTest::qWait(menuFadeDelay); |
|
2458 QVERIFY(!file->isVisible() && !edit->isVisible() && help->isVisible()); |
|
2459 interface->doAction(QAccessible::DefaultAction, 5); |
|
2460 if(menuFade) |
|
2461 QTest::qWait(menuFadeDelay); |
|
2462 QVERIFY(!file->isVisible() && !edit->isVisible() && !help->isVisible()); |
|
2463 |
|
2464 interface->doAction(QAccessible::DefaultAction, 1); |
|
2465 delete interface; |
|
2466 interface = QAccessible::queryAccessibleInterface(file); |
|
2467 QCOMPARE(interface->childCount(), 5); |
|
2468 QCOMPARE(interface->role(0), QAccessible::PopupMenu); |
|
2469 QCOMPARE(interface->role(1), QAccessible::MenuItem); |
|
2470 QCOMPARE(interface->role(2), QAccessible::MenuItem); |
|
2471 QCOMPARE(interface->role(3), QAccessible::MenuItem); |
|
2472 QCOMPARE(interface->role(4), QAccessible::Separator); |
|
2473 QCOMPARE(interface->role(5), QAccessible::MenuItem); |
|
2474 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 1), QString("Open")); |
|
2475 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 2), QString("Execute")); |
|
2476 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 3), QString("Execute")); |
|
2477 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 4), QString()); |
|
2478 QCOMPARE(interface->actionText(QAccessible::DefaultAction, QAccessible::Name, 5), QString("Execute")); |
|
2479 |
|
2480 QAccessibleInterface *iface = 0; |
|
2481 QAccessibleInterface *iface2 = 0; |
|
2482 |
|
2483 // traverse siblings with navigate(Sibling, ...) |
|
2484 int entry = interface->navigate(QAccessible::Child, 1, &iface); |
|
2485 QCOMPARE(entry, 0); |
|
2486 QVERIFY(iface); |
|
2487 QCOMPARE(iface->role(0), QAccessible::MenuItem); |
|
2488 |
|
2489 QAccessible::Role fileRoles[5] = { |
|
2490 QAccessible::MenuItem, |
|
2491 QAccessible::MenuItem, |
|
2492 QAccessible::MenuItem, |
|
2493 QAccessible::Separator, |
|
2494 QAccessible::MenuItem |
|
2495 }; |
|
2496 for (int child = 0; child < 5; ++child) { |
|
2497 entry = iface->navigate(QAccessible::Sibling, child + 1, &iface2); |
|
2498 QCOMPARE(entry, 0); |
|
2499 QVERIFY(iface2); |
|
2500 QCOMPARE(iface2->role(0), fileRoles[child]); |
|
2501 delete iface2; |
|
2502 } |
|
2503 delete iface; |
|
2504 |
|
2505 // traverse menu items with navigate(Down, ...) |
|
2506 entry = interface->navigate(QAccessible::Child, 1, &iface); |
|
2507 QCOMPARE(entry, 0); |
|
2508 QVERIFY(iface); |
|
2509 QCOMPARE(iface->role(0), QAccessible::MenuItem); |
|
2510 |
|
2511 for (int child = 0; child < 4; ++child) { |
|
2512 entry = iface->navigate(QAccessible::Down, 1, &iface2); |
|
2513 delete iface; |
|
2514 iface = iface2; |
|
2515 QCOMPARE(entry, 0); |
|
2516 QVERIFY(iface); |
|
2517 QCOMPARE(iface->role(0), fileRoles[child + 1]); |
|
2518 } |
|
2519 delete iface; |
|
2520 |
|
2521 // traverse menu items with navigate(Up, ...) |
|
2522 entry = interface->navigate(QAccessible::Child, interface->childCount(), &iface); |
|
2523 QCOMPARE(entry, 0); |
|
2524 QVERIFY(iface); |
|
2525 QCOMPARE(iface->role(0), QAccessible::MenuItem); |
|
2526 |
|
2527 for (int child = 3; child >= 0; --child) { |
|
2528 entry = iface->navigate(QAccessible::Up, 1, &iface2); |
|
2529 delete iface; |
|
2530 iface = iface2; |
|
2531 QCOMPARE(entry, 0); |
|
2532 QVERIFY(iface); |
|
2533 QCOMPARE(iface->role(0), fileRoles[child]); |
|
2534 } |
|
2535 delete iface; |
|
2536 |
|
2537 // "New" item |
|
2538 entry = interface->navigate(QAccessible::Child, 1, &iface); |
|
2539 QCOMPARE(entry, 0); |
|
2540 QVERIFY(iface); |
|
2541 QCOMPARE(iface->role(0), QAccessible::MenuItem); |
|
2542 |
|
2543 // "New" menu |
|
2544 entry = iface->navigate(QAccessible::Child, 1, &iface2); |
|
2545 delete iface; |
|
2546 iface = iface2; |
|
2547 QCOMPARE(entry, 0); |
|
2548 QVERIFY(iface); |
|
2549 QCOMPARE(iface->role(0), QAccessible::PopupMenu); |
|
2550 |
|
2551 // "Text file" menu item |
|
2552 entry = iface->navigate(QAccessible::Child, 1, &iface2); |
|
2553 delete iface; |
|
2554 iface = iface2; |
|
2555 QCOMPARE(entry, 0); |
|
2556 QVERIFY(iface); |
|
2557 QCOMPARE(iface->role(0), QAccessible::MenuItem); |
|
2558 |
|
2559 // Traverse to the menubar. |
|
2560 QAccessibleInterface *ifaceMenuBar = 0; |
|
2561 entry = iface->navigate(QAccessible::Ancestor, 5, &ifaceMenuBar); |
|
2562 QCOMPARE(ifaceMenuBar->role(0), QAccessible::MenuBar); |
|
2563 delete ifaceMenuBar; |
|
2564 |
|
2565 delete iface; |
|
2566 |
|
2567 // move mouse pointer away, since that might influence the |
|
2568 // subsequent tests |
|
2569 QTest::mouseMove(&mw, QPoint(-1, -1)); |
|
2570 QTest::qWait(100); |
|
2571 if (menuFade) |
|
2572 QTest::qWait(menuFadeDelay); |
|
2573 interface->doAction(QAccessible::DefaultAction, 1); |
|
2574 QTestEventLoop::instance().enterLoop(2); |
|
2575 |
|
2576 QVERIFY(file->isVisible()); |
|
2577 QVERIFY(fileNew->isVisible()); |
|
2578 QVERIFY(!edit->isVisible()); |
|
2579 QVERIFY(!help->isVisible()); |
|
2580 |
|
2581 QTestAccessibility::clearEvents(); |
|
2582 mw.hide(); |
|
2583 |
|
2584 |
|
2585 // Do not crash if the menu don't have a parent |
|
2586 QMenu *menu = new QMenu; |
|
2587 menu->addAction(QLatin1String("one")); |
|
2588 menu->addAction(QLatin1String("two")); |
|
2589 menu->addAction(QLatin1String("three")); |
|
2590 iface = QAccessible::queryAccessibleInterface(menu); |
|
2591 QCOMPARE(iface->navigate(QAccessible::Ancestor, 1, &iface2), 0); |
|
2592 QCOMPARE(iface2->role(0), QAccessible::Application); |
|
2593 // caused a *crash* |
|
2594 iface2->state(0); |
|
2595 delete iface2; |
|
2596 delete iface; |
|
2597 delete menu; |
|
2598 |
|
2599 } |
|
2600 QTestAccessibility::clearEvents(); |
|
2601 #else |
|
2602 QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll); |
|
2603 #endif |
|
2604 } |
|
2605 |
|
2606 void tst_QAccessibility::spinBoxTest() |
|
2607 { |
|
2608 #ifdef QTEST_ACCESSIBILITY |
|
2609 QSpinBox * const spinBox = new QSpinBox(); |
|
2610 spinBox->show(); |
|
2611 |
|
2612 QAccessibleInterface * const interface = QAccessible::queryAccessibleInterface(spinBox); |
|
2613 QVERIFY(interface); |
|
2614 |
|
2615 const QRect widgetRect = spinBox->geometry(); |
|
2616 const QRect accessibleRect = interface->rect(0); |
|
2617 QCOMPARE(accessibleRect, widgetRect); |
|
2618 |
|
2619 // Test that we get valid rects for all the spinbox child interfaces. |
|
2620 const int numChildren = interface->childCount(); |
|
2621 for (int i = 1; i <= numChildren; ++i) { |
|
2622 const QRect childRect = interface->rect(i); |
|
2623 QVERIFY(childRect.isNull() == false); |
|
2624 } |
|
2625 |
|
2626 spinBox->setFocus(); |
|
2627 QTestAccessibility::clearEvents(); |
|
2628 QTest::keyPress(spinBox, Qt::Key_Up); |
|
2629 QTest::qWait(200); |
|
2630 EventList events = QTestAccessibility::events(); |
|
2631 QTestAccessibilityEvent expectedEvent(spinBox, 0, (int)QAccessible::ValueChanged); |
|
2632 QVERIFY(events.contains(expectedEvent)); |
|
2633 delete spinBox; |
|
2634 QTestAccessibility::clearEvents(); |
|
2635 #else |
|
2636 QSKIP("Test needs accessibility support.", SkipAll); |
|
2637 #endif |
|
2638 } |
|
2639 |
|
2640 void tst_QAccessibility::doubleSpinBoxTest() |
|
2641 { |
|
2642 #ifdef QTEST_ACCESSIBILITY |
|
2643 QDoubleSpinBox *doubleSpinBox = new QDoubleSpinBox; |
|
2644 doubleSpinBox->show(); |
|
2645 |
|
2646 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(doubleSpinBox); |
|
2647 QVERIFY(interface); |
|
2648 |
|
2649 const QRect widgetRect = doubleSpinBox->geometry(); |
|
2650 const QRect accessibleRect = interface->rect(0); |
|
2651 QCOMPARE(accessibleRect, widgetRect); |
|
2652 |
|
2653 // Test that we get valid rects for all the spinbox child interfaces. |
|
2654 const int numChildren = interface->childCount(); |
|
2655 for (int i = 1; i <= numChildren; ++i) { |
|
2656 const QRect childRect = interface->rect(i); |
|
2657 QVERIFY(childRect.isValid()); |
|
2658 } |
|
2659 |
|
2660 delete doubleSpinBox; |
|
2661 QTestAccessibility::clearEvents(); |
|
2662 #else |
|
2663 QSKIP("Test needs accessibility support.", SkipAll); |
|
2664 #endif |
|
2665 } |
|
2666 |
|
2667 void tst_QAccessibility::textEditTest() |
|
2668 { |
|
2669 #ifdef QTEST_ACCESSIBILITY |
|
2670 { |
|
2671 QTextEdit edit; |
|
2672 QString text = "hello world\nhow are you today?\n"; |
|
2673 edit.setText(text); |
|
2674 edit.show(); |
|
2675 |
|
2676 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&edit); |
|
2677 QCOMPARE(iface->text(QAccessible::Value, 0), text); |
|
2678 QCOMPARE(iface->childCount(), 6); |
|
2679 QCOMPARE(iface->text(QAccessible::Value, 4), QString("hello world")); |
|
2680 QCOMPARE(iface->text(QAccessible::Value, 5), QString("how are you today?")); |
|
2681 QCOMPARE(iface->text(QAccessible::Value, 6), QString()); |
|
2682 } |
|
2683 QTestAccessibility::clearEvents(); |
|
2684 #else |
|
2685 QSKIP("Test needs accessibility support.", SkipAll); |
|
2686 #endif |
|
2687 } |
|
2688 |
|
2689 void tst_QAccessibility::textBrowserTest() |
|
2690 { |
|
2691 #ifdef QTEST_ACCESSIBILITY |
|
2692 { |
|
2693 QTextBrowser textBrowser; |
|
2694 QString text = QLatin1String("Hello world\nhow are you today?\n"); |
|
2695 textBrowser.setText(text); |
|
2696 textBrowser.show(); |
|
2697 |
|
2698 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&textBrowser); |
|
2699 QVERIFY(interface); |
|
2700 QCOMPARE(interface->role(0), QAccessible::StaticText); |
|
2701 QCOMPARE(interface->text(QAccessible::Value, 0), text); |
|
2702 QCOMPARE(interface->childCount(), 6); |
|
2703 QCOMPARE(interface->text(QAccessible::Value, 4), QString("Hello world")); |
|
2704 QCOMPARE(interface->text(QAccessible::Value, 5), QString("how are you today?")); |
|
2705 QCOMPARE(interface->text(QAccessible::Value, 6), QString()); |
|
2706 } |
|
2707 QTestAccessibility::clearEvents(); |
|
2708 #else |
|
2709 QSKIP("Test needs accessibility support.", SkipAll); |
|
2710 #endif |
|
2711 } |
|
2712 |
|
2713 void tst_QAccessibility::listViewTest() |
|
2714 { |
|
2715 #if 1 //def QTEST_ACCESSIBILITY |
|
2716 { |
|
2717 QListView listView; |
|
2718 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&listView); |
|
2719 QVERIFY(iface); |
|
2720 QCOMPARE(iface->childCount(), 1); |
|
2721 delete iface; |
|
2722 } |
|
2723 { |
|
2724 QListWidget listView; |
|
2725 listView.addItem(tr("A")); |
|
2726 listView.addItem(tr("B")); |
|
2727 listView.addItem(tr("C")); |
|
2728 listView.resize(400,400); |
|
2729 listView.show(); |
|
2730 QTest::qWait(1); // Need this for indexOfchild to work. |
|
2731 #if defined(Q_WS_X11) |
|
2732 qt_x11_wait_for_window_manager(&listView); |
|
2733 QTest::qWait(100); |
|
2734 #endif |
|
2735 |
|
2736 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&listView); |
|
2737 QCOMPARE((int)iface->role(0), (int)QAccessible::Client); |
|
2738 QCOMPARE((int)iface->role(1), (int)QAccessible::List); |
|
2739 QCOMPARE(iface->childCount(), 1); |
|
2740 QAccessibleInterface *child; |
|
2741 iface->navigate(QAccessible::Child, 1, &child); |
|
2742 delete iface; |
|
2743 iface = child; |
|
2744 QCOMPARE(iface->text(QAccessible::Name, 1), QString("A")); |
|
2745 QCOMPARE(iface->text(QAccessible::Name, 2), QString("B")); |
|
2746 QCOMPARE(iface->text(QAccessible::Name, 3), QString("C")); |
|
2747 |
|
2748 QCOMPARE(iface->childCount(), 3); |
|
2749 |
|
2750 QAccessibleInterface *childA = 0; |
|
2751 QCOMPARE(iface->navigate(QAccessible::Child, 1, &childA), 0); |
|
2752 QVERIFY(childA); |
|
2753 QCOMPARE(iface->indexOfChild(childA), 1); |
|
2754 QCOMPARE(childA->text(QAccessible::Name, 1), QString("A")); |
|
2755 delete childA; |
|
2756 |
|
2757 QAccessibleInterface *childB = 0; |
|
2758 QCOMPARE(iface->navigate(QAccessible::Child, 2, &childB), 0); |
|
2759 QVERIFY(childB); |
|
2760 QCOMPARE(iface->indexOfChild(childB), 2); |
|
2761 QCOMPARE(childB->text(QAccessible::Name, 1), QString("B")); |
|
2762 delete childB; |
|
2763 |
|
2764 QAccessibleInterface *childC = 0; |
|
2765 QCOMPARE(iface->navigate(QAccessible::Child, 3, &childC), 0); |
|
2766 QVERIFY(childC); |
|
2767 QCOMPARE(iface->indexOfChild(childC), 3); |
|
2768 QCOMPARE(childC->text(QAccessible::Name, 1), QString("C")); |
|
2769 delete childC; |
|
2770 QTestAccessibility::clearEvents(); |
|
2771 |
|
2772 // Check for events |
|
2773 QTest::mouseClick(listView.viewport(), Qt::LeftButton, 0, listView.visualItemRect(listView.item(1)).center()); |
|
2774 QTest::mouseClick(listView.viewport(), Qt::LeftButton, 0, listView.visualItemRect(listView.item(2)).center()); |
|
2775 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView.viewport(), 2, QAccessible::Selection))); |
|
2776 QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView.viewport(), 3, QAccessible::Selection))); |
|
2777 delete iface; |
|
2778 |
|
2779 } |
|
2780 QTestAccessibility::clearEvents(); |
|
2781 #else |
|
2782 QSKIP("Test needs accessibility support.", SkipAll); |
|
2783 #endif |
|
2784 } |
|
2785 |
|
2786 |
|
2787 void tst_QAccessibility::mdiAreaTest() |
|
2788 { |
|
2789 #ifdef QTEST_ACCESSIBILITY |
|
2790 { |
|
2791 QMdiArea mdiArea; |
|
2792 mdiArea.resize(400,300); |
|
2793 mdiArea.show(); |
|
2794 const int subWindowCount = 3; |
|
2795 for (int i = 0; i < subWindowCount; ++i) |
|
2796 mdiArea.addSubWindow(new QWidget, Qt::Dialog)->show(); |
|
2797 |
|
2798 QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); |
|
2799 QCOMPARE(subWindows.count(), subWindowCount); |
|
2800 |
|
2801 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&mdiArea); |
|
2802 QVERIFY(interface); |
|
2803 QCOMPARE(interface->childCount(), subWindowCount); |
|
2804 |
|
2805 // Right, right, right, ... |
|
2806 for (int i = 0; i < subWindowCount; ++i) { |
|
2807 QAccessibleInterface *destination = 0; |
|
2808 int index = interface->navigate(QAccessible::Right, i + 1, &destination); |
|
2809 if (i == subWindowCount - 1) { |
|
2810 QVERIFY(!destination); |
|
2811 QCOMPARE(index, -1); |
|
2812 } else { |
|
2813 QVERIFY(destination); |
|
2814 QCOMPARE(index, 0); |
|
2815 QCOMPARE(destination->object(), (QObject*)subWindows.at(i + 1)); |
|
2816 delete destination; |
|
2817 } |
|
2818 } |
|
2819 |
|
2820 // Left, left, left, ... |
|
2821 for (int i = subWindowCount; i > 0; --i) { |
|
2822 QAccessibleInterface *destination = 0; |
|
2823 int index = interface->navigate(QAccessible::Left, i, &destination); |
|
2824 if (i == 1) { |
|
2825 QVERIFY(!destination); |
|
2826 QCOMPARE(index, -1); |
|
2827 } else { |
|
2828 QVERIFY(destination); |
|
2829 QCOMPARE(index, 0); |
|
2830 QCOMPARE(destination->object(), (QObject*)subWindows.at(i - 2)); |
|
2831 delete destination; |
|
2832 } |
|
2833 } |
|
2834 // ### Add test for Up and Down. |
|
2835 |
|
2836 } |
|
2837 QTestAccessibility::clearEvents(); |
|
2838 #else |
|
2839 QSKIP("Test needs accessibility support.", SkipAll); |
|
2840 #endif |
|
2841 } |
|
2842 |
|
2843 void tst_QAccessibility::mdiSubWindowTest() |
|
2844 { |
|
2845 #ifdef QTEST_ACCESSIBILITY |
|
2846 { |
|
2847 QMdiArea mdiArea; |
|
2848 mdiArea.show(); |
|
2849 qApp->setActiveWindow(&mdiArea); |
|
2850 #if defined(Q_WS_X11) |
|
2851 qt_x11_wait_for_window_manager(&mdiArea); |
|
2852 QTest::qWait(150); |
|
2853 #endif |
|
2854 |
|
2855 bool isSubWindowsPlacedNextToEachOther = false; |
|
2856 const int subWindowCount = 5; |
|
2857 for (int i = 0; i < subWindowCount; ++i) { |
|
2858 QMdiSubWindow *window = mdiArea.addSubWindow(new QPushButton("QAccessibilityTest")); |
|
2859 window->show(); |
|
2860 // Parts of this test requires that the sub windows are placed next |
|
2861 // to each other. In order to achieve that QMdiArea must have |
|
2862 // a width which is larger than subWindow->width() * subWindowCount. |
|
2863 if (i == 0) { |
|
2864 int minimumWidth = window->width() * subWindowCount + 20; |
|
2865 mdiArea.resize(mdiArea.size().expandedTo(QSize(minimumWidth, 0))); |
|
2866 #if defined(Q_WS_X11) |
|
2867 qt_x11_wait_for_window_manager(&mdiArea); |
|
2868 QTest::qWait(100); |
|
2869 #endif |
|
2870 if (mdiArea.width() >= minimumWidth) |
|
2871 isSubWindowsPlacedNextToEachOther = true; |
|
2872 } |
|
2873 } |
|
2874 |
|
2875 QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); |
|
2876 QCOMPARE(subWindows.count(), subWindowCount); |
|
2877 |
|
2878 QMdiSubWindow *testWindow = subWindows.at(3); |
|
2879 QVERIFY(testWindow); |
|
2880 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(testWindow); |
|
2881 |
|
2882 // childCount |
|
2883 QVERIFY(interface); |
|
2884 QCOMPARE(interface->childCount(), 1); |
|
2885 |
|
2886 // setText / text |
|
2887 QCOMPARE(interface->text(QAccessible::Name, 0), QString()); |
|
2888 QCOMPARE(interface->text(QAccessible::Name, 1), QString()); |
|
2889 testWindow->setWindowTitle(QLatin1String("ReplaceMe")); |
|
2890 QCOMPARE(interface->text(QAccessible::Name, 0), QLatin1String("ReplaceMe")); |
|
2891 QCOMPARE(interface->text(QAccessible::Name, 1), QLatin1String("ReplaceMe")); |
|
2892 interface->setText(QAccessible::Name, 0, QLatin1String("TitleSetOnWindow")); |
|
2893 QCOMPARE(interface->text(QAccessible::Name, 0), QLatin1String("TitleSetOnWindow")); |
|
2894 interface->setText(QAccessible::Name, 1, QLatin1String("TitleSetOnChild")); |
|
2895 QCOMPARE(interface->text(QAccessible::Name, 0), QLatin1String("TitleSetOnChild")); |
|
2896 |
|
2897 mdiArea.setActiveSubWindow(testWindow); |
|
2898 |
|
2899 // state |
|
2900 QAccessible::State state = QAccessible::Normal | QAccessible::Focusable | QAccessible::Focused |
|
2901 | QAccessible::Movable | QAccessible::Sizeable; |
|
2902 QCOMPARE(interface->state(0), state); |
|
2903 const QRect originalGeometry = testWindow->geometry(); |
|
2904 testWindow->showMaximized(); |
|
2905 state &= ~QAccessible::Sizeable; |
|
2906 state &= ~QAccessible::Movable; |
|
2907 QCOMPARE(interface->state(0), state); |
|
2908 testWindow->showNormal(); |
|
2909 testWindow->move(-10, 0); |
|
2910 QVERIFY(interface->state(0) & QAccessible::Offscreen); |
|
2911 testWindow->setVisible(false); |
|
2912 QVERIFY(interface->state(0) & QAccessible::Invisible); |
|
2913 testWindow->setVisible(true); |
|
2914 testWindow->setEnabled(false); |
|
2915 QVERIFY(interface->state(0) & QAccessible::Unavailable); |
|
2916 testWindow->setEnabled(true); |
|
2917 qApp->setActiveWindow(&mdiArea); |
|
2918 mdiArea.setActiveSubWindow(testWindow); |
|
2919 testWindow->setFocus(); |
|
2920 QVERIFY(testWindow->isAncestorOf(qApp->focusWidget())); |
|
2921 QVERIFY(interface->state(0) & QAccessible::Focused); |
|
2922 testWindow->setGeometry(originalGeometry); |
|
2923 |
|
2924 if (isSubWindowsPlacedNextToEachOther) { |
|
2925 // This part of the test can only be run if the sub windows are |
|
2926 // placed next to each other. |
|
2927 QAccessibleInterface *destination = 0; |
|
2928 QCOMPARE(interface->navigate(QAccessible::Child, 1, &destination), 0); |
|
2929 QVERIFY(destination); |
|
2930 QCOMPARE(destination->object(), (QObject*)testWindow->widget()); |
|
2931 delete destination; |
|
2932 QCOMPARE(interface->navigate(QAccessible::Left, 0, &destination), 0); |
|
2933 QVERIFY(destination); |
|
2934 QCOMPARE(destination->object(), (QObject*)subWindows.at(2)); |
|
2935 delete destination; |
|
2936 QCOMPARE(interface->navigate(QAccessible::Right, 0, &destination), 0); |
|
2937 QVERIFY(destination); |
|
2938 QCOMPARE(destination->object(), (QObject*)subWindows.at(4)); |
|
2939 delete destination; |
|
2940 } |
|
2941 |
|
2942 // rect |
|
2943 const QPoint globalPos = testWindow->mapToGlobal(QPoint(0, 0)); |
|
2944 QCOMPARE(interface->rect(0), QRect(globalPos, testWindow->size())); |
|
2945 testWindow->hide(); |
|
2946 QCOMPARE(interface->rect(0), QRect()); |
|
2947 QCOMPARE(interface->rect(1), QRect()); |
|
2948 testWindow->showMinimized(); |
|
2949 QCOMPARE(interface->rect(1), QRect()); |
|
2950 testWindow->showNormal(); |
|
2951 testWindow->widget()->hide(); |
|
2952 QCOMPARE(interface->rect(1), QRect()); |
|
2953 testWindow->widget()->show(); |
|
2954 const QRect widgetGeometry = testWindow->contentsRect(); |
|
2955 const QPoint globalWidgetPos = QPoint(globalPos.x() + widgetGeometry.x(), |
|
2956 globalPos.y() + widgetGeometry.y()); |
|
2957 QCOMPARE(interface->rect(1), QRect(globalWidgetPos, widgetGeometry.size())); |
|
2958 |
|
2959 // childAt |
|
2960 QCOMPARE(interface->childAt(-10, 0), -1); |
|
2961 QCOMPARE(interface->childAt(globalPos.x(), globalPos.y()), 0); |
|
2962 QCOMPARE(interface->childAt(globalWidgetPos.x(), globalWidgetPos.y()), 1); |
|
2963 testWindow->widget()->hide(); |
|
2964 QCOMPARE(interface->childAt(globalWidgetPos.x(), globalWidgetPos.y()), 0); |
|
2965 |
|
2966 } |
|
2967 QTestAccessibility::clearEvents(); |
|
2968 #else |
|
2969 QSKIP("Test needs accessibility support.", SkipAll); |
|
2970 #endif |
|
2971 } |
|
2972 |
|
2973 void tst_QAccessibility::lineEditTest() |
|
2974 { |
|
2975 #ifdef QTEST_ACCESSIBILITY |
|
2976 QLineEdit *le = new QLineEdit; |
|
2977 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(le); |
|
2978 QVERIFY(iface); |
|
2979 le->show(); |
|
2980 |
|
2981 QApplication::processEvents(); |
|
2982 QCOMPARE(iface->childCount(), 0); |
|
2983 QVERIFY(iface->state(0) & QAccessible::Sizeable); |
|
2984 QVERIFY(iface->state(0) & QAccessible::Movable); |
|
2985 QCOMPARE(bool(iface->state(0) & QAccessible::Focusable), le->isActiveWindow()); |
|
2986 QVERIFY(iface->state(0) & QAccessible::Selectable); |
|
2987 QVERIFY(iface->state(0) & QAccessible::HasPopup); |
|
2988 QCOMPARE(bool(iface->state(0) & QAccessible::Focused), le->hasFocus()); |
|
2989 |
|
2990 QString secret(QLatin1String("secret")); |
|
2991 le->setText(secret); |
|
2992 le->setEchoMode(QLineEdit::Normal); |
|
2993 QVERIFY(!(iface->state(0) & QAccessible::Protected)); |
|
2994 QCOMPARE(iface->text(QAccessible::Value, 0), secret); |
|
2995 le->setEchoMode(QLineEdit::NoEcho); |
|
2996 QVERIFY(iface->state(0) & QAccessible::Protected); |
|
2997 QVERIFY(iface->text(QAccessible::Value, 0).isEmpty()); |
|
2998 le->setEchoMode(QLineEdit::Password); |
|
2999 QVERIFY(iface->state(0) & QAccessible::Protected); |
|
3000 QVERIFY(iface->text(QAccessible::Value, 0).isEmpty()); |
|
3001 le->setEchoMode(QLineEdit::PasswordEchoOnEdit); |
|
3002 QVERIFY(iface->state(0) & QAccessible::Protected); |
|
3003 QVERIFY(iface->text(QAccessible::Value, 0).isEmpty()); |
|
3004 le->setEchoMode(QLineEdit::Normal); |
|
3005 QVERIFY(!(iface->state(0) & QAccessible::Protected)); |
|
3006 QCOMPARE(iface->text(QAccessible::Value, 0), secret); |
|
3007 |
|
3008 QWidget *toplevel = new QWidget; |
|
3009 le->setParent(toplevel); |
|
3010 toplevel->show(); |
|
3011 QApplication::processEvents(); |
|
3012 QVERIFY(!(iface->state(0) & QAccessible::Sizeable)); |
|
3013 QVERIFY(!(iface->state(0) & QAccessible::Movable)); |
|
3014 QCOMPARE(bool(iface->state(0) & QAccessible::Focusable), le->isActiveWindow()); |
|
3015 QVERIFY(iface->state(0) & QAccessible::Selectable); |
|
3016 QVERIFY(iface->state(0) & QAccessible::HasPopup); |
|
3017 QCOMPARE(bool(iface->state(0) & QAccessible::Focused), le->hasFocus()); |
|
3018 |
|
3019 QLineEdit *le2 = new QLineEdit(toplevel); |
|
3020 le2->show(); |
|
3021 QTest::qWait(100); |
|
3022 le2->activateWindow(); |
|
3023 QTest::qWait(100); |
|
3024 le->setFocus(Qt::TabFocusReason); |
|
3025 QTestAccessibility::clearEvents(); |
|
3026 le2->setFocus(Qt::TabFocusReason); |
|
3027 QTRY_VERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(le2, 0, QAccessible::Focus))); |
|
3028 delete iface; |
|
3029 delete le; |
|
3030 delete le2; |
|
3031 delete toplevel; |
|
3032 QTestAccessibility::clearEvents(); |
|
3033 #else |
|
3034 QSKIP("Test needs accessibility support.", SkipAll); |
|
3035 #endif |
|
3036 } |
|
3037 |
|
3038 void tst_QAccessibility::workspaceTest() |
|
3039 { |
|
3040 #ifdef QTEST_ACCESSIBILITY |
|
3041 { |
|
3042 QWorkspace workspace; |
|
3043 workspace.resize(400,300); |
|
3044 workspace.show(); |
|
3045 const int subWindowCount = 3; |
|
3046 for (int i = 0; i < subWindowCount; ++i) { |
|
3047 QWidget *window = workspace.addWindow(new QWidget); |
|
3048 if (i > 0) |
|
3049 window->move(window->x() + 1, window->y()); |
|
3050 window->show(); |
|
3051 window->resize(70, window->height()); |
|
3052 } |
|
3053 |
|
3054 QWidgetList subWindows = workspace.windowList(); |
|
3055 QCOMPARE(subWindows.count(), subWindowCount); |
|
3056 |
|
3057 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&workspace); |
|
3058 QVERIFY(interface); |
|
3059 QCOMPARE(interface->childCount(), subWindowCount); |
|
3060 |
|
3061 // Right, right, right, ... |
|
3062 for (int i = 0; i < subWindowCount; ++i) { |
|
3063 QAccessibleInterface *destination = 0; |
|
3064 int index = interface->navigate(QAccessible::Right, i + 1, &destination); |
|
3065 if (i == subWindowCount - 1) { |
|
3066 QVERIFY(!destination); |
|
3067 QCOMPARE(index, -1); |
|
3068 } else { |
|
3069 QVERIFY(destination); |
|
3070 QCOMPARE(index, 0); |
|
3071 QCOMPARE(destination->object(), (QObject*)subWindows.at(i + 1)); |
|
3072 delete destination; |
|
3073 } |
|
3074 } |
|
3075 |
|
3076 // Left, left, left, ... |
|
3077 for (int i = subWindowCount; i > 0; --i) { |
|
3078 QAccessibleInterface *destination = 0; |
|
3079 int index = interface->navigate(QAccessible::Left, i, &destination); |
|
3080 if (i == 1) { |
|
3081 QVERIFY(!destination); |
|
3082 QCOMPARE(index, -1); |
|
3083 } else { |
|
3084 QVERIFY(destination); |
|
3085 QCOMPARE(index, 0); |
|
3086 QCOMPARE(destination->object(), (QObject*)subWindows.at(i - 2)); |
|
3087 delete destination; |
|
3088 } |
|
3089 } |
|
3090 // ### Add test for Up and Down. |
|
3091 |
|
3092 } |
|
3093 QTestAccessibility::clearEvents(); |
|
3094 #else |
|
3095 QSKIP("Test needs accessibility support.", SkipAll); |
|
3096 #endif |
|
3097 } |
|
3098 |
|
3099 void tst_QAccessibility::dialogButtonBoxTest() |
|
3100 { |
|
3101 #ifdef QTEST_ACCESSIBILITY |
|
3102 { |
|
3103 QDialogButtonBox box(QDialogButtonBox::Reset | |
|
3104 QDialogButtonBox::Help | |
|
3105 QDialogButtonBox::Ok, Qt::Horizontal); |
|
3106 |
|
3107 |
|
3108 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&box); |
|
3109 QVERIFY(iface); |
|
3110 box.show(); |
|
3111 #if defined(Q_WS_X11) |
|
3112 qt_x11_wait_for_window_manager(&box); |
|
3113 QTest::qWait(100); |
|
3114 #endif |
|
3115 |
|
3116 QApplication::processEvents(); |
|
3117 QCOMPARE(iface->childCount(), 3); |
|
3118 QCOMPARE(iface->role(0), QAccessible::Grouping); |
|
3119 QCOMPARE(iface->role(1), QAccessible::PushButton); |
|
3120 QCOMPARE(iface->role(2), QAccessible::PushButton); |
|
3121 QCOMPARE(iface->role(3), QAccessible::PushButton); |
|
3122 QStringList actualOrder; |
|
3123 QAccessibleInterface *child; |
|
3124 QAccessibleInterface *leftmost; |
|
3125 iface->navigate(QAccessible::Child, 1, &child); |
|
3126 // first find the leftmost button |
|
3127 while (child->navigate(QAccessible::Left, 1, &leftmost) != -1) { |
|
3128 delete child; |
|
3129 child = leftmost; |
|
3130 } |
|
3131 leftmost = child; |
|
3132 |
|
3133 // then traverse from left to right to find the correct order of the buttons |
|
3134 int right = 0; |
|
3135 while (right != -1) { |
|
3136 actualOrder << leftmost->text(QAccessible::Name, 0); |
|
3137 right = leftmost->navigate(QAccessible::Right, 1, &child); |
|
3138 delete leftmost; |
|
3139 leftmost = child; |
|
3140 } |
|
3141 |
|
3142 QStringList expectedOrder; |
|
3143 QDialogButtonBox::ButtonLayout btnlout = |
|
3144 QDialogButtonBox::ButtonLayout(QApplication::style()->styleHint(QStyle::SH_DialogButtonLayout)); |
|
3145 switch (btnlout) { |
|
3146 case QDialogButtonBox::WinLayout: |
|
3147 expectedOrder << QDialogButtonBox::tr("Reset") |
|
3148 << QDialogButtonBox::tr("OK") |
|
3149 << QDialogButtonBox::tr("Help"); |
|
3150 break; |
|
3151 case QDialogButtonBox::GnomeLayout: |
|
3152 case QDialogButtonBox::KdeLayout: |
|
3153 case QDialogButtonBox::MacLayout: |
|
3154 expectedOrder << QDialogButtonBox::tr("Help") |
|
3155 << QDialogButtonBox::tr("Reset") |
|
3156 << QDialogButtonBox::tr("OK"); |
|
3157 break; |
|
3158 } |
|
3159 QCOMPARE(actualOrder, expectedOrder); |
|
3160 delete iface; |
|
3161 QApplication::processEvents(); |
|
3162 QTestAccessibility::clearEvents(); |
|
3163 } |
|
3164 |
|
3165 { |
|
3166 QDialogButtonBox box(QDialogButtonBox::Reset | |
|
3167 QDialogButtonBox::Help | |
|
3168 QDialogButtonBox::Ok, Qt::Horizontal); |
|
3169 |
|
3170 |
|
3171 // Test up and down navigation |
|
3172 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&box); |
|
3173 QVERIFY(iface); |
|
3174 box.setOrientation(Qt::Vertical); |
|
3175 box.show(); |
|
3176 #if defined(Q_WS_X11) |
|
3177 qt_x11_wait_for_window_manager(&box); |
|
3178 QTest::qWait(100); |
|
3179 #endif |
|
3180 |
|
3181 QApplication::processEvents(); |
|
3182 QAccessibleInterface *child; |
|
3183 QStringList actualOrder; |
|
3184 iface->navigate(QAccessible::Child, 1, &child); |
|
3185 // first find the topmost button |
|
3186 QAccessibleInterface *other; |
|
3187 while (child->navigate(QAccessible::Up, 1, &other) != -1) { |
|
3188 delete child; |
|
3189 child = other; |
|
3190 } |
|
3191 other = child; |
|
3192 |
|
3193 // then traverse from top to bottom to find the correct order of the buttons |
|
3194 actualOrder.clear(); |
|
3195 int right = 0; |
|
3196 while (right != -1) { |
|
3197 actualOrder << other->text(QAccessible::Name, 0); |
|
3198 right = other->navigate(QAccessible::Down, 1, &child); |
|
3199 delete other; |
|
3200 other = child; |
|
3201 } |
|
3202 |
|
3203 QStringList expectedOrder; |
|
3204 expectedOrder << QDialogButtonBox::tr("OK") |
|
3205 << QDialogButtonBox::tr("Reset") |
|
3206 << QDialogButtonBox::tr("Help"); |
|
3207 |
|
3208 QCOMPARE(actualOrder, expectedOrder); |
|
3209 delete iface; |
|
3210 QApplication::processEvents(); |
|
3211 |
|
3212 } |
|
3213 QTestAccessibility::clearEvents(); |
|
3214 #else |
|
3215 QSKIP("Test needs accessibility support.", SkipAll); |
|
3216 #endif |
|
3217 } |
|
3218 |
|
3219 void tst_QAccessibility::dialTest() |
|
3220 { |
|
3221 #ifdef QTEST_ACCESSIBILITY |
|
3222 { |
|
3223 QDial dial; |
|
3224 dial.setValue(20); |
|
3225 QCOMPARE(dial.value(), 20); |
|
3226 dial.show(); |
|
3227 #if defined(Q_WS_X11) |
|
3228 qt_x11_wait_for_window_manager(&dial); |
|
3229 QTest::qWait(100); |
|
3230 #endif |
|
3231 |
|
3232 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&dial); |
|
3233 QVERIFY(interface); |
|
3234 |
|
3235 // Child count; 1 = SpeedoMeter, 2 = SliderHandle. |
|
3236 QCOMPARE(interface->childCount(), 2); |
|
3237 |
|
3238 QCOMPARE(interface->role(0), QAccessible::Dial); |
|
3239 QCOMPARE(interface->role(1), QAccessible::Slider); |
|
3240 QCOMPARE(interface->role(2), QAccessible::Indicator); |
|
3241 |
|
3242 QCOMPARE(interface->text(QAccessible::Value, 0), QString::number(dial.value())); |
|
3243 QCOMPARE(interface->text(QAccessible::Value, 1), QString::number(dial.value())); |
|
3244 QCOMPARE(interface->text(QAccessible::Value, 2), QString::number(dial.value())); |
|
3245 QCOMPARE(interface->text(QAccessible::Name, 0), QLatin1String("QDial")); |
|
3246 QCOMPARE(interface->text(QAccessible::Name, 1), QLatin1String("SpeedoMeter")); |
|
3247 QCOMPARE(interface->text(QAccessible::Name, 2), QLatin1String("SliderHandle")); |
|
3248 QCOMPARE(interface->text(QAccessible::Name, 3), QLatin1String("")); |
|
3249 |
|
3250 QCOMPARE(interface->state(1), interface->state(0)); |
|
3251 QCOMPARE(interface->state(2), interface->state(0) | QAccessible::HotTracked); |
|
3252 |
|
3253 // Rect |
|
3254 QCOMPARE(interface->rect(0), dial.geometry()); |
|
3255 QVERIFY(interface->rect(1).isValid()); |
|
3256 QVERIFY(dial.geometry().contains(interface->rect(1))); |
|
3257 QVERIFY(interface->rect(2).isValid()); |
|
3258 QVERIFY(interface->rect(1).contains(interface->rect(2))); |
|
3259 QVERIFY(!interface->rect(3).isValid()); |
|
3260 |
|
3261 } |
|
3262 QTestAccessibility::clearEvents(); |
|
3263 #else |
|
3264 QSKIP("Test needs accessibility support.", SkipAll); |
|
3265 #endif |
|
3266 } |
|
3267 |
|
3268 void tst_QAccessibility::rubberBandTest() |
|
3269 { |
|
3270 #ifdef QTEST_ACCESSIBILITY |
|
3271 QRubberBand rubberBand(QRubberBand::Rectangle); |
|
3272 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&rubberBand); |
|
3273 QVERIFY(interface); |
|
3274 QCOMPARE(interface->role(0), QAccessible::Border); |
|
3275 delete interface; |
|
3276 QTestAccessibility::clearEvents(); |
|
3277 #else |
|
3278 QSKIP("Test needs accessibility support.", SkipAll); |
|
3279 #endif |
|
3280 } |
|
3281 |
|
3282 void tst_QAccessibility::abstractScrollAreaTest() |
|
3283 { |
|
3284 #ifdef QTEST_ACCESSIBILITY |
|
3285 { |
|
3286 QAbstractScrollArea abstractScrollArea; |
|
3287 |
|
3288 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&abstractScrollArea); |
|
3289 QVERIFY(interface); |
|
3290 QVERIFY(!interface->rect(0).isValid()); |
|
3291 QVERIFY(!interface->rect(1).isValid()); |
|
3292 QCOMPARE(interface->childAt(200, 200), -1); |
|
3293 |
|
3294 abstractScrollArea.resize(400, 400); |
|
3295 abstractScrollArea.show(); |
|
3296 #if defined(Q_WS_X11) |
|
3297 qt_x11_wait_for_window_manager(&abstractScrollArea); |
|
3298 QTest::qWait(100); |
|
3299 #endif |
|
3300 const QRect globalGeometry = QRect(abstractScrollArea.mapToGlobal(QPoint(0, 0)), |
|
3301 abstractScrollArea.size()); |
|
3302 |
|
3303 // Viewport. |
|
3304 QCOMPARE(interface->childCount(), 1); |
|
3305 QWidget *viewport = abstractScrollArea.viewport(); |
|
3306 QVERIFY(viewport); |
|
3307 QVERIFY(verifyChild(viewport, interface, 1, globalGeometry)); |
|
3308 |
|
3309 // Horizontal scrollBar. |
|
3310 abstractScrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
|
3311 QCOMPARE(interface->childCount(), 2); |
|
3312 QWidget *horizontalScrollBar = abstractScrollArea.horizontalScrollBar(); |
|
3313 QWidget *horizontalScrollBarContainer = horizontalScrollBar->parentWidget(); |
|
3314 QVERIFY(verifyChild(horizontalScrollBarContainer, interface, 2, globalGeometry)); |
|
3315 |
|
3316 // Horizontal scrollBar widgets. |
|
3317 QLabel *secondLeftLabel = new QLabel(QLatin1String("L2")); |
|
3318 abstractScrollArea.addScrollBarWidget(secondLeftLabel, Qt::AlignLeft); |
|
3319 QCOMPARE(interface->childCount(), 2); |
|
3320 |
|
3321 QLabel *firstLeftLabel = new QLabel(QLatin1String("L1")); |
|
3322 abstractScrollArea.addScrollBarWidget(firstLeftLabel, Qt::AlignLeft); |
|
3323 QCOMPARE(interface->childCount(), 2); |
|
3324 |
|
3325 QLabel *secondRightLabel = new QLabel(QLatin1String("R2")); |
|
3326 abstractScrollArea.addScrollBarWidget(secondRightLabel, Qt::AlignRight); |
|
3327 QCOMPARE(interface->childCount(), 2); |
|
3328 |
|
3329 QLabel *firstRightLabel = new QLabel(QLatin1String("R1")); |
|
3330 abstractScrollArea.addScrollBarWidget(firstRightLabel, Qt::AlignRight); |
|
3331 QCOMPARE(interface->childCount(), 2); |
|
3332 |
|
3333 // Vertical scrollBar. |
|
3334 abstractScrollArea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
|
3335 QCOMPARE(interface->childCount(), 3); |
|
3336 QWidget *verticalScrollBar = abstractScrollArea.verticalScrollBar(); |
|
3337 QWidget *verticalScrollBarContainer = verticalScrollBar->parentWidget(); |
|
3338 QVERIFY(verifyChild(verticalScrollBarContainer, interface, 3, globalGeometry)); |
|
3339 |
|
3340 // Vertical scrollBar widgets. |
|
3341 QLabel *secondTopLabel = new QLabel(QLatin1String("T2")); |
|
3342 abstractScrollArea.addScrollBarWidget(secondTopLabel, Qt::AlignTop); |
|
3343 QCOMPARE(interface->childCount(), 3); |
|
3344 |
|
3345 QLabel *firstTopLabel = new QLabel(QLatin1String("T1")); |
|
3346 abstractScrollArea.addScrollBarWidget(firstTopLabel, Qt::AlignTop); |
|
3347 QCOMPARE(interface->childCount(), 3); |
|
3348 |
|
3349 QLabel *secondBottomLabel = new QLabel(QLatin1String("B2")); |
|
3350 abstractScrollArea.addScrollBarWidget(secondBottomLabel, Qt::AlignBottom); |
|
3351 QCOMPARE(interface->childCount(), 3); |
|
3352 |
|
3353 QLabel *firstBottomLabel = new QLabel(QLatin1String("B1")); |
|
3354 abstractScrollArea.addScrollBarWidget(firstBottomLabel, Qt::AlignBottom); |
|
3355 QCOMPARE(interface->childCount(), 3); |
|
3356 |
|
3357 // CornerWidget. |
|
3358 abstractScrollArea.setCornerWidget(new QLabel(QLatin1String("C"))); |
|
3359 QCOMPARE(interface->childCount(), 4); |
|
3360 QWidget *cornerWidget = abstractScrollArea.cornerWidget(); |
|
3361 QVERIFY(verifyChild(cornerWidget, interface, 4, globalGeometry)); |
|
3362 |
|
3363 // Test navigate. |
|
3364 QAccessibleInterface *target = 0; |
|
3365 |
|
3366 // viewport -> Up -> NOTHING |
|
3367 const int viewportIndex = indexOfChild(interface, viewport); |
|
3368 QVERIFY(viewportIndex != -1); |
|
3369 QCOMPARE(interface->navigate(QAccessible::Up, viewportIndex, &target), -1); |
|
3370 QVERIFY(!target); |
|
3371 |
|
3372 // viewport -> Left -> NOTHING |
|
3373 QCOMPARE(interface->navigate(QAccessible::Left, viewportIndex, &target), -1); |
|
3374 QVERIFY(!target); |
|
3375 |
|
3376 // viewport -> Down -> horizontalScrollBarContainer |
|
3377 const int horizontalScrollBarContainerIndex = indexOfChild(interface, horizontalScrollBarContainer); |
|
3378 QVERIFY(horizontalScrollBarContainerIndex != -1); |
|
3379 QCOMPARE(interface->navigate(QAccessible::Down, viewportIndex, &target), 0); |
|
3380 QVERIFY(target); |
|
3381 QCOMPARE(target->object(), static_cast<QObject *>(horizontalScrollBarContainer)); |
|
3382 delete target; |
|
3383 target = 0; |
|
3384 |
|
3385 // horizontalScrollBarContainer -> Left -> NOTHING |
|
3386 QCOMPARE(interface->navigate(QAccessible::Left, horizontalScrollBarContainerIndex, &target), -1); |
|
3387 QVERIFY(!target); |
|
3388 |
|
3389 // horizontalScrollBarContainer -> Down -> NOTHING |
|
3390 QVERIFY(horizontalScrollBarContainerIndex != -1); |
|
3391 QCOMPARE(interface->navigate(QAccessible::Down, horizontalScrollBarContainerIndex, &target), -1); |
|
3392 QVERIFY(!target); |
|
3393 |
|
3394 // horizontalScrollBarContainer -> Right -> cornerWidget |
|
3395 const int cornerWidgetIndex = indexOfChild(interface, cornerWidget); |
|
3396 QVERIFY(cornerWidgetIndex != -1); |
|
3397 QCOMPARE(interface->navigate(QAccessible::Right, horizontalScrollBarContainerIndex, &target), 0); |
|
3398 QVERIFY(target); |
|
3399 QCOMPARE(target->object(), static_cast<QObject *>(cornerWidget)); |
|
3400 delete target; |
|
3401 target = 0; |
|
3402 |
|
3403 // cornerWidget -> Down -> NOTHING |
|
3404 QCOMPARE(interface->navigate(QAccessible::Down, cornerWidgetIndex, &target), -1); |
|
3405 QVERIFY(!target); |
|
3406 |
|
3407 // cornerWidget -> Right -> NOTHING |
|
3408 QVERIFY(cornerWidgetIndex != -1); |
|
3409 QCOMPARE(interface->navigate(QAccessible::Right, cornerWidgetIndex, &target), -1); |
|
3410 QVERIFY(!target); |
|
3411 |
|
3412 // cornerWidget -> Up -> verticalScrollBarContainer |
|
3413 const int verticalScrollBarContainerIndex = indexOfChild(interface, verticalScrollBarContainer); |
|
3414 QVERIFY(verticalScrollBarContainerIndex != -1); |
|
3415 QCOMPARE(interface->navigate(QAccessible::Up, cornerWidgetIndex, &target), 0); |
|
3416 QVERIFY(target); |
|
3417 QCOMPARE(target->object(), static_cast<QObject *>(verticalScrollBarContainer)); |
|
3418 delete target; |
|
3419 target = 0; |
|
3420 |
|
3421 // verticalScrollBarContainer -> Right -> NOTHING |
|
3422 QCOMPARE(interface->navigate(QAccessible::Right, verticalScrollBarContainerIndex, &target), -1); |
|
3423 QVERIFY(!target); |
|
3424 |
|
3425 // verticalScrollBarContainer -> Up -> NOTHING |
|
3426 QCOMPARE(interface->navigate(QAccessible::Up, verticalScrollBarContainerIndex, &target), -1); |
|
3427 QVERIFY(!target); |
|
3428 |
|
3429 // verticalScrollBarContainer -> Left -> viewport |
|
3430 QCOMPARE(interface->navigate(QAccessible::Left, verticalScrollBarContainerIndex, &target), 0); |
|
3431 QVERIFY(target); |
|
3432 QCOMPARE(target->object(), static_cast<QObject *>(viewport)); |
|
3433 delete target; |
|
3434 target = 0; |
|
3435 |
|
3436 QCOMPARE(verifyHierarchy(interface), 0); |
|
3437 |
|
3438 delete interface; |
|
3439 } |
|
3440 |
|
3441 QTestAccessibility::clearEvents(); |
|
3442 #else |
|
3443 QSKIP("Test needs accessibility support.", SkipAll); |
|
3444 #endif |
|
3445 } |
|
3446 |
|
3447 void tst_QAccessibility::scrollAreaTest() |
|
3448 { |
|
3449 #ifdef QTEST_ACCESSIBILITY |
|
3450 { |
|
3451 QScrollArea scrollArea; |
|
3452 scrollArea.show(); |
|
3453 #if defined(Q_WS_X11) |
|
3454 qt_x11_wait_for_window_manager(&scrollArea); |
|
3455 QTest::qWait(100); |
|
3456 #endif |
|
3457 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&scrollArea); |
|
3458 QVERIFY(interface); |
|
3459 QCOMPARE(interface->childCount(), 1); // The viewport. |
|
3460 delete interface; |
|
3461 } |
|
3462 QTestAccessibility::clearEvents(); |
|
3463 #else |
|
3464 QSKIP("Test needs accessibility support.", SkipAll); |
|
3465 #endif |
|
3466 } |
|
3467 |
|
3468 void tst_QAccessibility::tableWidgetTest() |
|
3469 { |
|
3470 #ifdef QTEST_ACCESSIBILITY |
|
3471 { |
|
3472 QTableWidget *w = new QTableWidget(8,4); |
|
3473 for (int r = 0; r < 8; ++r) { |
|
3474 for (int c = 0; c < 4; ++c) { |
|
3475 w->setItem(r, c, new QTableWidgetItem(tr("%1,%2").arg(c).arg(r))); |
|
3476 } |
|
3477 } |
|
3478 w->resize(100, 100); |
|
3479 w->show(); |
|
3480 #if defined(Q_WS_X11) |
|
3481 qt_x11_wait_for_window_manager(w); |
|
3482 QTest::qWait(100); |
|
3483 #endif |
|
3484 QAccessibleInterface *client = QAccessible::queryAccessibleInterface(w); |
|
3485 QCOMPARE(client->role(0), QAccessible::Client); |
|
3486 QCOMPARE(client->childCount(), 3); |
|
3487 QAccessibleInterface *view = 0; |
|
3488 client->navigate(QAccessible::Child, 1, &view); |
|
3489 QCOMPARE(view->role(0), QAccessible::Table); |
|
3490 QAccessibleInterface *ifRow; |
|
3491 view->navigate(QAccessible::Child, 2, &ifRow); |
|
3492 QCOMPARE(ifRow->role(0), QAccessible::Row); |
|
3493 QAccessibleInterface *item; |
|
3494 int entry = ifRow->navigate(QAccessible::Child, 1, &item); |
|
3495 QCOMPARE(entry, 1); |
|
3496 QCOMPARE(item , (QAccessibleInterface*)0); |
|
3497 QCOMPARE(ifRow->text(QAccessible::Name, 2), QLatin1String("0,0")); |
|
3498 QCOMPARE(ifRow->text(QAccessible::Name, 3), QLatin1String("1,0")); |
|
3499 |
|
3500 QCOMPARE(verifyHierarchy(client), 0); |
|
3501 |
|
3502 delete ifRow; |
|
3503 delete view; |
|
3504 delete client; |
|
3505 delete w; |
|
3506 } |
|
3507 QTestAccessibility::clearEvents(); |
|
3508 #else |
|
3509 QSKIP("Test needs accessibility support.", SkipAll); |
|
3510 #endif |
|
3511 |
|
3512 } |
|
3513 |
|
3514 class QtTestTableModel: public QAbstractTableModel |
|
3515 { |
|
3516 Q_OBJECT |
|
3517 |
|
3518 signals: |
|
3519 void invalidIndexEncountered() const; |
|
3520 |
|
3521 public: |
|
3522 QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) |
|
3523 : QAbstractTableModel(parent), |
|
3524 row_count(rows), |
|
3525 column_count(columns) {} |
|
3526 |
|
3527 int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } |
|
3528 int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } |
|
3529 |
|
3530 QVariant data(const QModelIndex &idx, int role) const |
|
3531 { |
|
3532 if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { |
|
3533 qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; |
|
3534 emit invalidIndexEncountered(); |
|
3535 return QVariant(); |
|
3536 } |
|
3537 |
|
3538 if (role == Qt::DisplayRole || role == Qt::EditRole) |
|
3539 return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0); |
|
3540 |
|
3541 return QVariant(); |
|
3542 } |
|
3543 |
|
3544 void removeLastRow() |
|
3545 { |
|
3546 beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); |
|
3547 --row_count; |
|
3548 endRemoveRows(); |
|
3549 } |
|
3550 |
|
3551 void removeAllRows() |
|
3552 { |
|
3553 beginRemoveRows(QModelIndex(), 0, row_count - 1); |
|
3554 row_count = 0; |
|
3555 endRemoveRows(); |
|
3556 } |
|
3557 |
|
3558 void removeLastColumn() |
|
3559 { |
|
3560 beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); |
|
3561 --column_count; |
|
3562 endRemoveColumns(); |
|
3563 } |
|
3564 |
|
3565 void removeAllColumns() |
|
3566 { |
|
3567 beginRemoveColumns(QModelIndex(), 0, column_count - 1); |
|
3568 column_count = 0; |
|
3569 endRemoveColumns(); |
|
3570 } |
|
3571 |
|
3572 void reset() |
|
3573 { |
|
3574 QAbstractTableModel::reset(); |
|
3575 } |
|
3576 |
|
3577 int row_count; |
|
3578 int column_count; |
|
3579 }; |
|
3580 |
|
3581 class QtTestDelegate : public QItemDelegate |
|
3582 { |
|
3583 public: |
|
3584 QtTestDelegate(QWidget *parent = 0) : QItemDelegate(parent) {} |
|
3585 |
|
3586 virtual QSize sizeHint(const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const |
|
3587 { |
|
3588 return QSize(100,50); |
|
3589 } |
|
3590 }; |
|
3591 |
|
3592 void tst_QAccessibility::tableViewTest() |
|
3593 { |
|
3594 #ifdef QTEST_ACCESSIBILITY |
|
3595 { |
|
3596 QtTestTableModel *model = new QtTestTableModel(3, 4); |
|
3597 QTableView *w = new QTableView(); |
|
3598 w->setModel(model); |
|
3599 w->setItemDelegate(new QtTestDelegate(w)); |
|
3600 w->resize(450,200); |
|
3601 w->resizeColumnsToContents(); |
|
3602 w->resizeRowsToContents(); |
|
3603 w->show(); |
|
3604 #if defined(Q_WS_X11) |
|
3605 qt_x11_wait_for_window_manager(w); |
|
3606 QTest::qWait(100); |
|
3607 #endif |
|
3608 QAccessibleInterface *client = QAccessible::queryAccessibleInterface(w); |
|
3609 QAccessibleInterface *table2; |
|
3610 client->navigate(QAccessible::Child, 1, &table2); |
|
3611 QVERIFY(table2); |
|
3612 QCOMPARE(table2->role(1), QAccessible::Row); |
|
3613 QAccessibleInterface *toprow = 0; |
|
3614 table2->navigate(QAccessible::Child, 1, &toprow); |
|
3615 QVERIFY(toprow); |
|
3616 QCOMPARE(toprow->role(1), QAccessible::RowHeader); |
|
3617 QCOMPARE(toprow->role(2), QAccessible::ColumnHeader); |
|
3618 delete toprow; |
|
3619 |
|
3620 // call childAt() for each child until we reach the bottom, |
|
3621 // and do it for each row in the table |
|
3622 for (int y = 1; y < 5; ++y) { // this includes the special header |
|
3623 for (int x = 1; x < 6; ++x) { |
|
3624 QCOMPARE(client->role(0), QAccessible::Client); |
|
3625 QRect globalRect = client->rect(0); |
|
3626 QVERIFY(globalRect.isValid()); |
|
3627 // make sure we don't hit the vertical header ##### |
|
3628 QPoint p = globalRect.topLeft() + QPoint(8, 8); |
|
3629 p.ry() += 50 * (y - 1); |
|
3630 p.rx() += 100 * (x - 1); |
|
3631 int index = client->childAt(p.x(), p.y()); |
|
3632 QCOMPARE(index, 1); |
|
3633 QCOMPARE(client->role(index), QAccessible::Table); |
|
3634 |
|
3635 // navigate to table/viewport |
|
3636 QAccessibleInterface *table; |
|
3637 client->navigate(QAccessible::Child, index, &table); |
|
3638 QVERIFY(table); |
|
3639 index = table->childAt(p.x(), p.y()); |
|
3640 QCOMPARE(index, y); |
|
3641 QCOMPARE(table->role(index), QAccessible::Row); |
|
3642 QAccessibleInterface *row; |
|
3643 QCOMPARE(table->role(1), QAccessible::Row); |
|
3644 |
|
3645 // navigate to the row |
|
3646 table->navigate(QAccessible::Child, index, &row); |
|
3647 QVERIFY(row); |
|
3648 QCOMPARE(row->role(1), QAccessible::RowHeader); |
|
3649 index = row->childAt(p.x(), p.y()); |
|
3650 QVERIFY(index > 0); |
|
3651 if (x == 1 && y == 1) { |
|
3652 QCOMPARE(row->role(index), QAccessible::RowHeader); |
|
3653 QCOMPARE(row->text(QAccessible::Name, index), QLatin1String("")); |
|
3654 } else if (x > 1 && y > 1) { |
|
3655 QCOMPARE(row->role(index), QAccessible::Cell); |
|
3656 QCOMPARE(row->text(QAccessible::Name, index), QString::fromAscii("[%1,%2,0]").arg(y - 2).arg(x - 2)); |
|
3657 } else if (x == 1) { |
|
3658 QCOMPARE(row->role(index), QAccessible::RowHeader); |
|
3659 QCOMPARE(row->text(QAccessible::Name, index), QString::fromAscii("%1").arg(y - 1)); |
|
3660 } else if (y == 1) { |
|
3661 QCOMPARE(row->role(index), QAccessible::ColumnHeader); |
|
3662 QCOMPARE(row->text(QAccessible::Name, index), QString::fromAscii("%1").arg(x - 1)); |
|
3663 } |
|
3664 delete table; |
|
3665 delete row; |
|
3666 } |
|
3667 } |
|
3668 delete table2; |
|
3669 delete client; |
|
3670 delete w; |
|
3671 delete model; |
|
3672 } |
|
3673 QTestAccessibility::clearEvents(); |
|
3674 #else |
|
3675 QSKIP("Test needs accessibility support.", SkipAll); |
|
3676 #endif |
|
3677 } |
|
3678 |
|
3679 void tst_QAccessibility::calendarWidgetTest() |
|
3680 { |
|
3681 #ifndef QT_NO_CALENDARWIDGET |
|
3682 #ifdef QTEST_ACCESSIBILITY |
|
3683 { |
|
3684 QCalendarWidget calendarWidget; |
|
3685 |
|
3686 QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&calendarWidget); |
|
3687 QVERIFY(interface); |
|
3688 QCOMPARE(interface->role(0), QAccessible::Table); |
|
3689 QVERIFY(!interface->rect(0).isValid()); |
|
3690 QVERIFY(!interface->rect(1).isValid()); |
|
3691 QCOMPARE(interface->childAt(200, 200), -1); |
|
3692 |
|
3693 calendarWidget.resize(400, 300); |
|
3694 calendarWidget.show(); |
|
3695 #if defined(Q_WS_X11) |
|
3696 qt_x11_wait_for_window_manager(&calendarWidget); |
|
3697 QTest::qWait(100); |
|
3698 #endif |
|
3699 |
|
3700 // 1 = navigationBar, 2 = view. |
|
3701 QCOMPARE(interface->childCount(), 2); |
|
3702 |
|
3703 const QRect globalGeometry = QRect(calendarWidget.mapToGlobal(QPoint(0, 0)), |
|
3704 calendarWidget.size()); |
|
3705 QCOMPARE(interface->rect(0), globalGeometry); |
|
3706 |
|
3707 QWidget *navigationBar = 0; |
|
3708 foreach (QObject *child, calendarWidget.children()) { |
|
3709 if (child->objectName() == QLatin1String("qt_calendar_navigationbar")) { |
|
3710 navigationBar = static_cast<QWidget *>(child); |
|
3711 break; |
|
3712 } |
|
3713 } |
|
3714 QVERIFY(navigationBar); |
|
3715 QVERIFY(verifyChild(navigationBar, interface, 1, globalGeometry)); |
|
3716 |
|
3717 QAbstractItemView *calendarView = 0; |
|
3718 foreach (QObject *child, calendarWidget.children()) { |
|
3719 if (child->objectName() == QLatin1String("qt_calendar_calendarview")) { |
|
3720 calendarView = static_cast<QAbstractItemView *>(child); |
|
3721 break; |
|
3722 } |
|
3723 } |
|
3724 QVERIFY(calendarView); |
|
3725 QVERIFY(verifyChild(calendarView, interface, 2, globalGeometry)); |
|
3726 |
|
3727 // Hide navigation bar. |
|
3728 calendarWidget.setNavigationBarVisible(false); |
|
3729 QCOMPARE(interface->childCount(), 1); |
|
3730 QVERIFY(!navigationBar->isVisible()); |
|
3731 |
|
3732 QVERIFY(verifyChild(calendarView, interface, 1, globalGeometry)); |
|
3733 |
|
3734 // Show navigation bar. |
|
3735 calendarWidget.setNavigationBarVisible(true); |
|
3736 QCOMPARE(interface->childCount(), 2); |
|
3737 QVERIFY(navigationBar->isVisible()); |
|
3738 |
|
3739 // Navigate to the navigation bar via Child. |
|
3740 QAccessibleInterface *navigationBarInterface = 0; |
|
3741 QCOMPARE(interface->navigate(QAccessible::Child, 1, &navigationBarInterface), 0); |
|
3742 QVERIFY(navigationBarInterface); |
|
3743 QCOMPARE(navigationBarInterface->object(), (QObject*)navigationBar); |
|
3744 delete navigationBarInterface; |
|
3745 navigationBarInterface = 0; |
|
3746 |
|
3747 // Navigate to the view via Child. |
|
3748 QAccessibleInterface *calendarViewInterface = 0; |
|
3749 QCOMPARE(interface->navigate(QAccessible::Child, 2, &calendarViewInterface), 0); |
|
3750 QVERIFY(calendarViewInterface); |
|
3751 QCOMPARE(calendarViewInterface->object(), (QObject*)calendarView); |
|
3752 delete calendarViewInterface; |
|
3753 calendarViewInterface = 0; |
|
3754 |
|
3755 QAccessibleInterface *doesNotExistsInterface = 0; |
|
3756 QCOMPARE(interface->navigate(QAccessible::Child, 3, &doesNotExistsInterface), -1); |
|
3757 QVERIFY(!doesNotExistsInterface); |
|
3758 |
|
3759 // Navigate from navigation bar -> view (Down). |
|
3760 QCOMPARE(interface->navigate(QAccessible::Down, 1, &calendarViewInterface), 0); |
|
3761 QVERIFY(calendarViewInterface); |
|
3762 QCOMPARE(calendarViewInterface->object(), (QObject*)calendarView); |
|
3763 delete calendarViewInterface; |
|
3764 calendarViewInterface = 0; |
|
3765 |
|
3766 // Navigate from view -> navigation bar (Up). |
|
3767 QCOMPARE(interface->navigate(QAccessible::Up, 2, &navigationBarInterface), 0); |
|
3768 QVERIFY(navigationBarInterface); |
|
3769 QCOMPARE(navigationBarInterface->object(), (QObject*)navigationBar); |
|
3770 delete navigationBarInterface; |
|
3771 navigationBarInterface = 0; |
|
3772 |
|
3773 } |
|
3774 QTestAccessibility::clearEvents(); |
|
3775 #else |
|
3776 QSKIP("Test needs accessibility support.", SkipAll); |
|
3777 #endif |
|
3778 #endif // QT_NO_CALENDARWIDGET |
|
3779 } |
|
3780 |
|
3781 void tst_QAccessibility::dockWidgetTest() |
|
3782 { |
|
3783 #ifndef QT_NO_DOCKWIDGET |
|
3784 |
|
3785 #ifdef QTEST_ACCESSIBILITY |
|
3786 // Set up a proper main window with two dock widgets |
|
3787 QMainWindow *mw = new QMainWindow(); |
|
3788 QFrame *central = new QFrame(mw); |
|
3789 mw->setCentralWidget(central); |
|
3790 QMenuBar *mb = new QMenuBar(mw); |
|
3791 mb->addAction(tr("&File")); |
|
3792 mw->setMenuBar(mb); |
|
3793 |
|
3794 QDockWidget *dock1 = new QDockWidget(mw); |
|
3795 mw->addDockWidget(Qt::LeftDockWidgetArea, dock1); |
|
3796 QPushButton *pb1 = new QPushButton(tr("Push me"), dock1); |
|
3797 dock1->setWidget(pb1); |
|
3798 |
|
3799 QDockWidget *dock2 = new QDockWidget(mw); |
|
3800 mw->addDockWidget(Qt::BottomDockWidgetArea, dock2); |
|
3801 QPushButton *pb2 = new QPushButton(tr("Push me"), dock2); |
|
3802 dock2->setWidget(pb2); |
|
3803 |
|
3804 mw->resize(600,400); |
|
3805 mw->show(); |
|
3806 #if defined(Q_WS_X11) |
|
3807 qt_x11_wait_for_window_manager(mw); |
|
3808 QTest::qWait(100); |
|
3809 #endif |
|
3810 |
|
3811 QAccessibleInterface *accMainWindow = QAccessible::queryAccessibleInterface(mw); |
|
3812 // 4 children: menu bar, dock1, dock2, and central widget |
|
3813 QCOMPARE(accMainWindow->childCount(), 4); |
|
3814 QAccessibleInterface *accDock1 = 0; |
|
3815 for (int i = 1; i <= 4; ++i) { |
|
3816 if (accMainWindow->role(i) == QAccessible::Window) { |
|
3817 accMainWindow->navigate(QAccessible::Child, i, &accDock1); |
|
3818 if (accDock1 && qobject_cast<QDockWidget*>(accDock1->object()) == dock1) { |
|
3819 break; |
|
3820 } else { |
|
3821 delete accDock1; |
|
3822 } |
|
3823 } |
|
3824 } |
|
3825 QVERIFY(accDock1); |
|
3826 QCOMPARE(accDock1->role(0), QAccessible::Window); |
|
3827 QCOMPARE(accDock1->role(1), QAccessible::TitleBar); |
|
3828 QVERIFY(accDock1->rect(0).contains(accDock1->rect(1))); |
|
3829 |
|
3830 QPoint globalPos = dock1->mapToGlobal(QPoint(0,0)); |
|
3831 globalPos.rx()+=5; //### query style |
|
3832 globalPos.ry()+=5; |
|
3833 int entry = accDock1->childAt(globalPos.x(), globalPos.y()); //### |
|
3834 QAccessibleInterface *accTitleBar; |
|
3835 entry = accDock1->navigate(QAccessible::Child, entry, &accTitleBar); |
|
3836 QCOMPARE(accTitleBar->role(0), QAccessible::TitleBar); |
|
3837 QCOMPARE(accDock1->indexOfChild(accTitleBar), 1); |
|
3838 QAccessibleInterface *acc; |
|
3839 entry = accTitleBar->navigate(QAccessible::Ancestor, 1, &acc); |
|
3840 QVERIFY(acc); |
|
3841 QCOMPARE(entry, 0); |
|
3842 QCOMPARE(acc->role(0), QAccessible::Window); |
|
3843 |
|
3844 |
|
3845 delete accTitleBar; |
|
3846 delete accDock1; |
|
3847 delete pb1; |
|
3848 delete pb2; |
|
3849 delete dock1; |
|
3850 delete dock2; |
|
3851 delete mw; |
|
3852 QTestAccessibility::clearEvents(); |
|
3853 #else |
|
3854 QSKIP("Test needs accessibility support.", SkipAll); |
|
3855 #endif |
|
3856 #endif // QT_NO_DOCKWIDGET |
|
3857 } |
|
3858 |
|
3859 void tst_QAccessibility::pushButtonTest() |
|
3860 { |
|
3861 #if !defined(QT3_SUPPORT) |
|
3862 qWarning( "Should never get here without Qt3Support"); |
|
3863 return ; |
|
3864 #else |
|
3865 #ifdef QTEST_ACCESSIBILITY |
|
3866 // Set up a proper main window with two dock widgets |
|
3867 QWidget *toplevel = createGUI(); |
|
3868 QObject *topRight = toplevel->findChild<QObject *>("topRight"); |
|
3869 |
|
3870 toplevel->show(); |
|
3871 #if defined(Q_WS_X11) |
|
3872 qt_x11_wait_for_window_manager(toplevel); |
|
3873 QTest::qWait(100); |
|
3874 #endif |
|
3875 QPushButton *pb = qobject_cast<QPushButton*>(topRight->findChild<QPushButton *>("pbOk")); |
|
3876 QPoint pt = pb->mapToGlobal(pb->geometry().topLeft()); |
|
3877 QRect rect(pt, pb->geometry().size()); |
|
3878 pt = rect.center(); |
|
3879 |
|
3880 QAccessibleInterface *accToplevel = QAccessible::queryAccessibleInterface(toplevel); |
|
3881 QAccessibleInterface *acc; |
|
3882 QAccessibleInterface *acc2; |
|
3883 int entry = accToplevel->childAt(pt.x(), pt.y()); |
|
3884 int child = accToplevel->navigate(QAccessible::Child, entry, &acc); |
|
3885 if (acc) { |
|
3886 entry = acc->childAt(pt.x(), pt.y()); |
|
3887 child = acc->navigate(QAccessible::Child, entry, &acc2); |
|
3888 delete acc; |
|
3889 acc = acc2; |
|
3890 } |
|
3891 QCOMPARE(acc->role(0), QAccessible::PushButton); |
|
3892 QCOMPARE(acc->rect(0), rect); |
|
3893 QCOMPARE(acc->childAt(pt.x(), pt.y()), 0); |
|
3894 |
|
3895 delete acc; |
|
3896 delete accToplevel; |
|
3897 delete toplevel; |
|
3898 QTestAccessibility::clearEvents(); |
|
3899 #else |
|
3900 QSKIP("Test needs accessibility support.", SkipAll); |
|
3901 #endif |
|
3902 #endif //QT3_SUPPORT |
|
3903 } |
|
3904 |
|
3905 void tst_QAccessibility::comboBoxTest() |
|
3906 { |
|
3907 #ifdef QTEST_ACCESSIBILITY |
|
3908 #if defined(Q_OS_WINCE) |
|
3909 if (!IsValidCEPlatform()) { |
|
3910 QSKIP("Test skipped on Windows Mobile test hardware", SkipAll); |
|
3911 } |
|
3912 #endif |
|
3913 QWidget *w = new QWidget(); |
|
3914 QComboBox *cb = new QComboBox(w); |
|
3915 cb->addItems(QStringList() << "one" << "two" << "three"); |
|
3916 w->show(); |
|
3917 #if defined(Q_WS_X11) |
|
3918 qt_x11_wait_for_window_manager(w); |
|
3919 QTest::qWait(100); |
|
3920 #endif |
|
3921 QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(w); |
|
3922 delete acc; |
|
3923 |
|
3924 acc = QAccessible::queryAccessibleInterface(cb); |
|
3925 |
|
3926 QRect accRect = acc->rect(0); |
|
3927 for (int i = 1; i < acc->childCount(); ++i) { |
|
3928 QVERIFY(accRect.contains(acc->rect(i))); |
|
3929 } |
|
3930 QCOMPARE(acc->doAction(QAccessible::Press, 2), true); |
|
3931 QTest::qWait(400); |
|
3932 QAccessibleInterface *accList = 0; |
|
3933 int entry = acc->navigate(QAccessible::Child, 3, &accList); |
|
3934 QCOMPARE(entry, 0); |
|
3935 QAccessibleInterface *acc2 = 0; |
|
3936 entry = accList->navigate(QAccessible::Ancestor, 1, &acc2); |
|
3937 QCOMPARE(entry, 0); |
|
3938 QCOMPARE(verifyHierarchy(acc), 0); |
|
3939 delete acc2; |
|
3940 |
|
3941 delete accList; |
|
3942 delete acc; |
|
3943 delete w; |
|
3944 |
|
3945 QTestAccessibility::clearEvents(); |
|
3946 #else |
|
3947 QSKIP("Test needs accessibility support.", SkipAll); |
|
3948 #endif |
|
3949 |
|
3950 } |
|
3951 |
|
3952 void tst_QAccessibility::treeWidgetTest() |
|
3953 { |
|
3954 #ifdef QTEST_ACCESSIBILITY |
|
3955 QWidget *w = new QWidget; |
|
3956 QTreeWidget *tree = new QTreeWidget(w); |
|
3957 QHBoxLayout *l = new QHBoxLayout(w); |
|
3958 l->addWidget(tree); |
|
3959 for (int i = 0; i < 10; ++i) { |
|
3960 QStringList strings = QStringList() << QString::fromAscii("row: %1").arg(i) |
|
3961 << QString("column 1") << QString("column 2"); |
|
3962 |
|
3963 tree->addTopLevelItem(new QTreeWidgetItem(strings)); |
|
3964 } |
|
3965 w->show(); |
|
3966 // QTest::qWait(1000); |
|
3967 #if defined(Q_WS_X11) |
|
3968 qt_x11_wait_for_window_manager(w); |
|
3969 QTest::qWait(100); |
|
3970 #endif |
|
3971 |
|
3972 QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(tree); |
|
3973 QAccessibleInterface *accViewport = 0; |
|
3974 int entry = acc->navigate(QAccessible::Child, 1, &accViewport); |
|
3975 QVERIFY(accViewport); |
|
3976 QCOMPARE(entry, 0); |
|
3977 QAccessibleInterface *accTreeItem = 0; |
|
3978 entry = accViewport->navigate(QAccessible::Child, 1, &accTreeItem); |
|
3979 QCOMPARE(entry, 0); |
|
3980 |
|
3981 QAccessibleInterface *accTreeItem2 = 0; |
|
3982 entry = accTreeItem->navigate(QAccessible::Sibling, 3, &accTreeItem2); |
|
3983 QCOMPARE(entry, 0); |
|
3984 QCOMPARE(accTreeItem2->text(QAccessible::Name, 0), QLatin1String("row: 1")); |
|
3985 |
|
3986 // test selected/focused state |
|
3987 QItemSelectionModel *selModel = tree->selectionModel(); |
|
3988 QVERIFY(selModel); |
|
3989 selModel->select(QItemSelection(tree->model()->index(0, 0), tree->model()->index(3, 0)), QItemSelectionModel::Select); |
|
3990 selModel->setCurrentIndex(tree->model()->index(1, 0), QItemSelectionModel::Current); |
|
3991 |
|
3992 for (int i = 1; i < 10 ; ++i) { |
|
3993 QAccessible::State expected; |
|
3994 if (i <= 5 && i >= 2) |
|
3995 expected = QAccessible::Selected; |
|
3996 if (i == 3) |
|
3997 expected |= QAccessible::Focused; |
|
3998 |
|
3999 QCOMPARE(accViewport->state(i) & (QAccessible::Focused | QAccessible::Selected), expected); |
|
4000 } |
|
4001 |
|
4002 // Test sanity of its navigation functions |
|
4003 QCOMPARE(verifyHierarchy(acc), 0); |
|
4004 |
|
4005 delete accTreeItem2; |
|
4006 delete accTreeItem; |
|
4007 delete accViewport; |
|
4008 delete acc; |
|
4009 delete w; |
|
4010 |
|
4011 QTestAccessibility::clearEvents(); |
|
4012 #else |
|
4013 QSKIP("Test needs accessibility support.", SkipAll); |
|
4014 #endif |
|
4015 } |
|
4016 |
|
4017 void tst_QAccessibility::labelTest() |
|
4018 { |
|
4019 #ifdef QTEST_ACCESSIBILITY |
|
4020 QString text = "Hello World"; |
|
4021 QLabel *label = new QLabel(text); |
|
4022 label->show(); |
|
4023 |
|
4024 #if defined(Q_WS_X11) |
|
4025 qt_x11_wait_for_window_manager(label); |
|
4026 #endif |
|
4027 QTest::qWait(100); |
|
4028 |
|
4029 QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(label); |
|
4030 QVERIFY(acc_label); |
|
4031 |
|
4032 QCOMPARE(acc_label->text(QAccessible::Name, 0), text); |
|
4033 |
|
4034 delete acc_label; |
|
4035 delete label; |
|
4036 QTestAccessibility::clearEvents(); |
|
4037 #else |
|
4038 QSKIP("Test needs accessibility support.", SkipAll); |
|
4039 #endif |
|
4040 } |
|
4041 |
|
4042 void tst_QAccessibility::accelerators() |
|
4043 { |
|
4044 #ifdef QTEST_ACCESSIBILITY |
|
4045 QWidget *window = new QWidget; |
|
4046 QHBoxLayout *lay = new QHBoxLayout(window); |
|
4047 QLabel *label = new QLabel(tr("&Line edit"), window); |
|
4048 QLineEdit *le = new QLineEdit(window); |
|
4049 lay->addWidget(label); |
|
4050 lay->addWidget(le); |
|
4051 label->setBuddy(le); |
|
4052 |
|
4053 window->show(); |
|
4054 |
|
4055 QAccessibleInterface *accLineEdit = QAccessible::queryAccessibleInterface(le); |
|
4056 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString() + QLatin1String("L")); |
|
4057 label->setText(tr("Q &")); |
|
4058 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); |
|
4059 label->setText(tr("Q &&")); |
|
4060 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); |
|
4061 label->setText(tr("Q && A")); |
|
4062 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); |
|
4063 label->setText(tr("Q &&&A")); |
|
4064 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString() + QLatin1String("A")); |
|
4065 label->setText(tr("Q &&A")); |
|
4066 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); |
|
4067 label->setText(tr("Q &A&B")); |
|
4068 QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString() + QLatin1String("A")); |
|
4069 |
|
4070 #if defined(Q_WS_X11) |
|
4071 qt_x11_wait_for_window_manager(window); |
|
4072 #endif |
|
4073 QTest::qWait(100); |
|
4074 delete window; |
|
4075 QTestAccessibility::clearEvents(); |
|
4076 #else |
|
4077 QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll); |
|
4078 #endif |
|
4079 } |
|
4080 |
|
4081 |
|
4082 QTEST_MAIN(tst_QAccessibility) |
|
4083 |
|
4084 #else // Q_OS_WINCE |
|
4085 |
|
4086 QTEST_NOOP_MAIN |
|
4087 |
|
4088 #endif // Q_OS_WINCE |
|
4089 |
|
4090 #include "tst_qaccessibility.moc" |