summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2012-10-26 14:20:05 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-28 12:29:35 (GMT)
commitc6e3cea94c2b36aebb76b90b8354a04caa2f9c60 (patch)
tree4cd35fbc0c0a0e43bf3700ba9c2e233a9d6fc18d
parent7d5574202ed67b57b1c4df21ab6eb3695c14df37 (diff)
downloadQt-c6e3cea94c2b36aebb76b90b8354a04caa2f9c60.zip
Qt-c6e3cea94c2b36aebb76b90b8354a04caa2f9c60.tar.gz
Qt-c6e3cea94c2b36aebb76b90b8354a04caa2f9c60.tar.bz2
Make textEditTest more tolerant wrt characterRect verification
Should become more stable due to two changes: 1. When QAccessibleTextWidget::characterRect() calculates the height, make sure the leading is not included. 2. Accept a small error (1) on height and width. It there is an error on the height or width, dump diagnostics This makes it pass with all Latin fonts on my system (roughly ~150 fonts), where it didn't before. Change-Id: I964207bad1f3ceb0103129501bdc857aff5885d2 Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
-rw-r--r--src/plugins/accessible/widgets/qaccessiblewidgets.cpp7
-rw-r--r--tests/auto/qaccessibility/tst_qaccessibility.cpp69
2 files changed, 68 insertions, 8 deletions
diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
index 590f603..0360e0c 100644
--- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
@@ -1433,8 +1433,13 @@ QRect QAccessibleTextWidget::characterRect(int offset, CoordinateType coordType)
r.setWidth(averageCharWidth);
}
+ int height = line.height();
+
+ // make sure that height does not include leading. (only ascent + descent + 1)
+ if (line.leadingIncluded())
+ height -= qRound(line.leading());
r = QRect(layoutPosition.x() + x, layoutPosition.y() + line.y(),
- w, line.height());
+ w, height);
if (coordType == RelativeToScreen) {
r.moveTo(viewport()->mapToGlobal(r.topLeft()));
diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp
index ed69901..d47eb06 100644
--- a/tests/auto/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp
@@ -2720,6 +2720,27 @@ void tst_QAccessibility::doubleSpinBoxTest()
QTestAccessibility::clearEvents();
}
+static void dumpTextDiagnostics(const QTextEdit &edit, int offset)
+{
+ qDebug() << "Incorrect result, font:" << edit.currentFont().toString();
+ QFontMetricsF fm(edit.currentFont());
+ qDebug() << "QFontMetricsF: " << fm.ascent() << fm.descent() << fm.height();
+
+ QTextBlock block = edit.document()->findBlock(offset);
+ QVERIFY(block.isValid());
+ QTextLayout *layout = block.layout();
+ QPointF layoutPosition = layout->position();
+ QTextLine line = layout->lineForTextPosition(offset);
+ qDebug() << "QTextLine: " << line.ascent() << line.descent() << line.height() << line.leading();
+ qDebug() << block.text();
+
+ // Reported to only be a problem on Ubuntu Oneiric. Verify that.
+#if defined(Q_WS_X11) && defined(UBUNTU_ONEIRIC)
+ qDebug() << "UBUNTU_ONEIRIC";
+#endif
+
+}
+
void tst_QAccessibility::textEditTest()
{
{
@@ -2743,13 +2764,47 @@ void tst_QAccessibility::textEditTest()
QCOMPARE(endOffset, 30);
QCOMPARE(iface->text(QAccessible::Value, 6), QString());
QCOMPARE(iface->textInterface()->characterCount(), 31);
- QFontMetrics fm(edit.font());
-#if defined(Q_WS_X11) && defined(UBUNTU_ONEIRIC)
- QEXPECT_FAIL("", "QTBUG-26499", Abort);
-#endif
- QCOMPARE(iface->textInterface()->characterRect(0, QAccessible2::RelativeToParent).size(), QSize(fm.width("h"), fm.height()));
- QCOMPARE(iface->textInterface()->characterRect(5, QAccessible2::RelativeToParent).size(), QSize(fm.width(" "), fm.height()));
- QCOMPARE(iface->textInterface()->characterRect(6, QAccessible2::RelativeToParent).size(), QSize(fm.width("w"), fm.height()));
+ QFontMetrics fm(edit.currentFont());
+
+ // Test for
+ // QAccessibleTextInterface::characterRect() and
+ ///QAccessibleTextInterface::offsetAtPoint()
+ struct {
+ int offset;
+ char ch;
+ } testdata[] = {
+ {0, 'h'},
+ {4, 'o'},
+ // skip space, it might be too narrow to reliably hit it
+ {6, 'w'}
+ };
+
+ const int expectedHeight = fm.height(); //ascent + descent + 1
+
+ for (int i = 0; i < 3; ++i) {
+ int offset = testdata[i].offset;
+ QRect rect = iface->textInterface()->characterRect(offset, QAccessible2::RelativeToParent);
+ QVERIFY(rect.isValid());
+ const QSize actualSize = rect.size();
+ const int widthDelta = actualSize.width() - fm.width(QChar(testdata[i].ch));
+ const int heightDelta = actualSize.height() - expectedHeight;
+ // The deltas should really be 0, but it seems that it fails for some fonts
+ // Dump some diagnostics if that is the case
+ if (heightDelta || widthDelta)
+ dumpTextDiagnostics(edit, offset);
+
+ QVERIFY(qAbs(widthDelta) <= 1);
+
+ if (qAbs(heightDelta) == 1) {
+ qDebug() << "Result is off by one, accepted. (" << actualSize.height() << expectedHeight << ")";
+ } else {
+ QCOMPARE(actualSize.height(), expectedHeight);
+ }
+ // Width must be >= 3 in order for rect.center() to not end up on one of the edges. They are not reliable.
+ if (rect.width() >= 3) {
+ QCOMPARE(iface->textInterface()->offsetAtPoint(rect.center(), QAccessible2::RelativeToParent), offset);
+ }
+ }
iface->editableTextInterface()->copyText(6, 11);
QCOMPARE(QApplication::clipboard()->text(), QLatin1String("world"));