Skip incompatible QTextLayout tests when dpi-scaling is used

On e.g. Android, the tabs will be scaled by DPI. This breaks the
logic in the QTextLayout tests for tabs. It's not possible to
just scale the expected sizes either, since the whole text layout
will be affected by font sizes and scaling, and it's difficult to
predict where characters will land on different platforms and
resolutions.

To avoid breaking this test on other platforms, we just skip them
when we know they will break. Since the code tested is
cross-platform, this will hopefully not have any significant
impact on our coverage.

Change-Id: I65d6c33c9c6724665983a17f99eadcf1baedcc20
Reviewed-by: Tony Sarajärvi <tony.sarajarvi@digia.com>
Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2015-01-08 16:02:07 +01:00
parent d30c446d35
commit ccf50893e8

View File

@ -1280,6 +1280,13 @@ void tst_QTextLayout::smallTextLengthWrapAtWordBoundaryOrAnywhere()
void tst_QTextLayout::testDefaultTabs()
{
QTextLayout layout("Foo\tBar\ta slightly longer text\tend.", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
layout.beginLayout();
QTextLine line = layout.createLine();
@ -1322,6 +1329,13 @@ void tst_QTextLayout::testDefaultTabs()
void tst_QTextLayout::testTabs()
{
QTextLayout layout("Foo\tBar.", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
QTextOption option = layout.textOption();
option.setTabStop(150);
@ -1339,6 +1353,13 @@ void tst_QTextLayout::testTabs()
void tst_QTextLayout::testMultilineTab()
{
QTextLayout layout("Lorem ipsum dolor sit\tBar.", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
// test if this works on the second line.
layout.beginLayout();
@ -1348,12 +1369,20 @@ void tst_QTextLayout::testMultilineTab()
line.setLineWidth(220.);
layout.endLayout();
QCOMPARE(line.cursorToX(22), 80.);
}
void tst_QTextLayout::testMultiTab()
{
QTextLayout layout("Foo\t\t\tBar.", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
layout.beginLayout();
QTextLine line = layout.createLine();
@ -1367,6 +1396,13 @@ void tst_QTextLayout::testTabsInAlignedParag()
{
QTextLayout layout("Foo\tsome more words", testFont);
layout.setCacheEnabled(true);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
QTextOption option = layout.textOption();
// right
option.setAlignment(Qt::AlignRight);
@ -1426,6 +1462,12 @@ void tst_QTextLayout::testRightTab()
*/
layout.setCacheEnabled(true);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs;
QTextOption::Tab tab;
@ -1463,6 +1505,13 @@ void tst_QTextLayout::testRightTab()
void tst_QTextLayout::testCenteredTab()
{
QTextLayout layout("Foo\tBar", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
// test if centering the tab works. We expect the center of 'Bar.' to be at the tab point.
QTextOption option = layout.textOption();
@ -1484,6 +1533,13 @@ void tst_QTextLayout::testCenteredTab()
void tst_QTextLayout::testDelimiterTab()
{
QTextLayout layout("Foo\tBar. Barrabas", testFont);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
layout.setCacheEnabled(true);
// try the different delimiter characters to see if the alignment works there.
QTextOption option = layout.textOption();
@ -1537,6 +1593,12 @@ void tst_QTextLayout::tabsForRtl()
*/
layout.setCacheEnabled(true);
QFont font = layout.font();
QFontPrivate *fd = QFontPrivate::get(font);
qreal dpiScale = qreal(fd->dpi) / qreal(qt_defaultDpiY());
if (!qFuzzyCompare(dpiScale, 1.0))
QSKIP("Test logic does not work when tabs are scaled by dpi");
QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs;
QTextOption::Tab tab;