diff options
Diffstat (limited to 'tests/auto/quick/qquicktext/tst_qquicktext.cpp')
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 100 |
1 files changed, 56 insertions, 44 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index bdff985027..f31859ee49 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -64,6 +59,7 @@ public: tst_qquicktext(); private slots: + void cleanup(); void text(); void width(); void wrap(); @@ -151,6 +147,9 @@ private slots: void padding(); + void zeroWidthAndElidedDoesntRender(); + + void hAlignWidthDependsOnImplicitWidth_data(); void hAlignWidthDependsOnImplicitWidth(); @@ -175,6 +174,11 @@ private: int numberOfNonWhitePixels(int fromX, int toX, const QImage &image); }; +void tst_qquicktext::cleanup() +{ + QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); +} + tst_qquicktext::tst_qquicktext() { standard << "the quick brown fox jumped over the lazy dog" @@ -557,7 +561,7 @@ void tst_qquicktext::multilineElide_data() void tst_qquicktext::multilineElide() { QFETCH(QQuickText::TextFormat, format); - QQuickView *window = createView(testFile("multilineelide.qml")); + QScopedPointer<QQuickView> window(createView(testFile("multilineelide.qml"))); QQuickText *myText = qobject_cast<QQuickText*>(window->rootObject()); QVERIFY(myText != 0); @@ -601,8 +605,6 @@ void tst_qquicktext::multilineElide() // change line height myText->setLineHeight(1.1); QCOMPARE(myText->lineCount(), 1); - - delete window; } void tst_qquicktext::implicitElide_data() @@ -764,7 +766,7 @@ void tst_qquicktext::horizontalAlignment_RightToLeft() dummy.showFullScreen(); // so make test window a second window. #endif - QQuickView *window = createView(testFile("horizontalAlignment_RightToLeft.qml")); + QScopedPointer<QQuickView> window(createView(testFile("horizontalAlignment_RightToLeft.qml"))); QQuickText *text = window->rootObject()->findChild<QQuickText*>("text"); QVERIFY(text != 0); window->showNormal(); @@ -867,7 +869,7 @@ void tst_qquicktext::horizontalAlignment_RightToLeft() text->setHAlign(QQuickText::AlignRight); QCOMPARE(text->hAlign(), QQuickText::AlignRight); - delete window; + window.reset(); // alignment of Text with no text set to it QString componentStr = "import QtQuick 2.0\nText {}"; @@ -917,8 +919,10 @@ void tst_qquicktext::hAlignImplicitWidth() // Try to check whether alignment works by checking the number of black // pixels in the thirds of the grabbed image. - const int windowWidth = 220; - const int textWidth = qCeil(text->implicitWidth()); + // QQuickWindow::grabWindow() scales the returned image by the devicePixelRatio of the screen. + const qreal devicePixelRatio = view.screen()->devicePixelRatio(); + const int windowWidth = 220 * devicePixelRatio; + const int textWidth = qCeil(text->implicitWidth()) * devicePixelRatio; QVERIFY2(textWidth < windowWidth, "System font too large."); const int sectionWidth = textWidth / 3; const int centeredSection1 = (windowWidth - textWidth) / 2; @@ -2106,7 +2110,7 @@ void tst_qquicktext::embeddedImages() void tst_qquicktext::lineCount() { - QQuickView *window = createView(testFile("lineCount.qml")); + QScopedPointer<QQuickView> window(createView(testFile("lineCount.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2129,13 +2133,11 @@ void tst_qquicktext::lineCount() QCOMPARE(myText->lineCount(), 2); QCOMPARE(myText->truncated(), true); QCOMPARE(myText->maximumLineCount(), 2); - - delete window; } void tst_qquicktext::lineHeight() { - QQuickView *window = createView(testFile("lineHeight.qml")); + QScopedPointer<QQuickView> window(createView(testFile("lineHeight.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2162,8 +2164,6 @@ void tst_qquicktext::lineHeight() myText->setLineHeightMode(QQuickText::FixedHeight); myText->setLineHeight(10); QCOMPARE(myText->height(), myText->lineCount() * 10.0); - - delete window; } void tst_qquicktext::implicitSize_data() @@ -2735,7 +2735,7 @@ void tst_qquicktext::clipRect() void tst_qquicktext::lineLaidOut() { - QQuickView *window = createView(testFile("lineLayout.qml")); + QScopedPointer<QQuickView> window(createView(testFile("lineLayout.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2755,17 +2755,15 @@ void tst_qquicktext::lineLaidOut() QCOMPARE(r.height(), qreal(20)); } } - - delete window; } void tst_qquicktext::lineLaidOutRelayout() { - QQuickView *window = createView(testFile("lineLayoutRelayout.qml")); + QScopedPointer<QQuickView> window(createView(testFile("lineLayoutRelayout.qml"))); window->show(); window->requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2789,13 +2787,11 @@ void tst_qquicktext::lineLaidOutRelayout() } y += line.height(); } - - delete window; } void tst_qquicktext::lineLaidOutHAlign() { - QQuickView *window = createView(testFile("lineLayoutHAlign.qml")); + QScopedPointer<QQuickView> window(createView(testFile("lineLayoutHAlign.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2806,8 +2802,6 @@ void tst_qquicktext::lineLaidOutHAlign() QCOMPARE(textPrivate->layout.lineCount(), 1); QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().x() < 0.0); - - delete window; } void tst_qquicktext::imgTagsBaseUrl_data() @@ -2967,7 +2961,7 @@ void tst_qquicktext::imgTagsMultipleImages() void tst_qquicktext::imgTagsElide() { - QQuickView *window = createView(testFile("imgTagsElide.qml")); + QScopedPointer<QQuickView> window(createView(testFile("imgTagsElide.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -2978,12 +2972,11 @@ void tst_qquicktext::imgTagsElide() QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); delete myText; - delete window; } void tst_qquicktext::imgTagsUpdates() { - QQuickView *window = createView(testFile("imgTagsUpdates.qml")); + QScopedPointer<QQuickView> window(createView(testFile("imgTagsUpdates.qml"))); QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); @@ -3005,7 +2998,6 @@ void tst_qquicktext::imgTagsUpdates() QCOMPARE(spy.count(), 3); delete myText; - delete window; } void tst_qquicktext::imgTagsError() @@ -4173,6 +4165,26 @@ void tst_qquicktext::padding() delete root; } +void tst_qquicktext::zeroWidthAndElidedDoesntRender() +{ + // Tests QTBUG-34990 + + QQmlComponent component(&engine, testFile("ellipsisText.qml")); + + QScopedPointer<QObject> object(component.create()); + + QQuickText *text = qobject_cast<QQuickText *>(object.data()); + QVERIFY(text); + + QCOMPARE(text->contentWidth(), 0.0); + + QQuickText *reference = text->findChild<QQuickText *>("elidedRef"); + QVERIFY(reference); + + text->setWidth(10); + QCOMPARE(text->contentWidth(), reference->contentWidth()); +} + void tst_qquicktext::hAlignWidthDependsOnImplicitWidth_data() { QTest::addColumn<QQuickText::HAlignment>("horizontalAlignment"); |