Fix accessibility character rect tests

textEditTest in qaccessibility test was using QTextEdit::setCurrentFont
on second pass, but that did not change the font used for text in any way.
I don't know what was the purpose. So I changed it into something that
made sense to me and actually tests text with a different font on second pass.

Also fixed characterRect function in tests to use correct font/format.

Change-Id: I843c5b29f8048196ec3405b6717655e77b567dbb
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
bb10
Boris Dušek 2015-03-17 23:02:23 +01:00
parent 898ca6ff76
commit 551f39bac5
1 changed files with 6 additions and 3 deletions

View File

@ -1716,7 +1716,10 @@ static QRect characterRect(const QTextEdit &edit, int offset)
QPointF layoutPosition = layout->position();
int relativeOffset = offset - block.position();
QTextLine line = layout->lineForTextPosition(relativeOffset);
QFontMetrics fm(edit.currentFont());
QTextBlock::iterator it = block.begin();
while (!it.fragment().contains(offset))
++it;
QFontMetrics fm(it.fragment().charFormat().font());
QChar ch = edit.document()->characterAt(offset);
int w = fm.width(ch);
int h = fm.height();
@ -1759,7 +1762,7 @@ void tst_QAccessibility::textEditTest()
QFont font("Helvetica");
font.setPointSizeF(12.5);
font.setWordSpacing(1.1);
edit.setCurrentFont(font);
edit.document()->setDefaultFont(font);
}
edit.show();
@ -1781,7 +1784,7 @@ void tst_QAccessibility::textEditTest()
QCOMPARE(startOffset, 13);
QCOMPARE(endOffset, 31);
QCOMPARE(textIface->characterCount(), 48);
QFontMetrics fm(edit.currentFont());
QFontMetrics fm(edit.document()->defaultFont());
QCOMPARE(textIface->characterRect(0).size(), QSize(fm.width("h"), fm.height()));
QCOMPARE(textIface->characterRect(5).size(), QSize(fm.width(" "), fm.height()));
QCOMPARE(textIface->characterRect(6).size(), QSize(fm.width("w"), fm.height()));