-
-static inline bool verifyChild(QWidget *child, QAccessibleInterface *iface,
- int index, const QRect &domain)
-{
- if (!child) {
- qWarning("tst_QAccessibility::verifyChild: null pointer to child.");
- return false;
- }
-
- if (!iface) {
- qWarning("tst_QAccessibility::verifyChild: null pointer to interface.");
- return false;
- }
-
- // Verify that we get a valid QAccessibleInterface for the child.
- QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child);
- if (!childInterface) {
- qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child.");
- return false;
- }
-
- // QAccessibleInterface::indexOfChild():
- // Verify that indexOfChild() returns an index equal to the index passed in
- int indexFromIndexOfChild = iface->indexOfChild(childInterface);
- delete childInterface;
- if (indexFromIndexOfChild != index) {
- qWarning("tst_QAccessibility::verifyChild (indexOfChild()):");
- qWarning() << "Expected:" << index;
- qWarning() << "Actual: " << indexFromIndexOfChild;
- return false;
- }
-
- // Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child).
- QAccessibleInterface *navigatedChildInterface = iface->child(index - 1);
- if (navigatedChildInterface == 0)
- return false;
-
- const QRect rectFromInterface = navigatedChildInterface->rect();
- delete navigatedChildInterface;
-
- // QAccessibleInterface::childAt():
- // Calculate global child position and check that the interface
- // returns the correct index for that position.
- QPoint globalChildPos = child->mapToGlobal(QPoint(0, 0));
- QAccessibleInterface *childAtInterface = iface->childAt(globalChildPos.x(), globalChildPos.y());
- if (!childAtInterface) {
- qWarning("tst_QAccessibility::verifyChild (childAt()):");
- qWarning() << "Expected:" << childInterface;
- qWarning() << "Actual: no child";
- return false;
- }
- if (childAtInterface->object() != childInterface->object()) {
- qWarning("tst_QAccessibility::verifyChild (childAt()):");
- qWarning() << "Expected:" << childInterface;
- qWarning() << "Actual: " << childAtInterface;
- return false;
- }
- delete childInterface;
- delete childAtInterface;
-
- // Verify that the child is within its domain.
- if (!domain.contains(rectFromInterface)) {
- qWarning("tst_QAccessibility::verifyChild: Child is not within its domain.");
- return false;
- }
-
- return true;
-}
-
-static inline int indexOfChild(QAccessibleInterface *parentInterface, QWidget *childWidget)
-{
- if (!parentInterface || !childWidget)
- return -1;
- QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(childWidget);
- if (!childInterface)
- return -1;
- int index = parentInterface->indexOfChild(childInterface);
- delete childInterface;
- return index;
-}
-