From ccf50893e8086ae15db10296655db23364e55674 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 8 Jan 2015 16:02:07 +0100 Subject: Skip incompatible QTextLayout tests when dpi-scaling is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: BogDan Vatra --- .../auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 4b2970cd17..4fa8575153 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -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 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 tabs; QTextOption::Tab tab; -- cgit v1.2.3