aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktext/tst_qquicktext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquicktext/tst_qquicktext.cpp')
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp100
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 50c75046a6..5ee811fd37 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();
+
+
private:
QStringList standard;
QStringList richText;
@@ -172,6 +171,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"
@@ -554,7 +558,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);
@@ -598,8 +602,6 @@ void tst_qquicktext::multilineElide()
// change line height
myText->setLineHeight(1.1);
QCOMPARE(myText->lineCount(), 1);
-
- delete window;
}
void tst_qquicktext::implicitElide_data()
@@ -761,7 +763,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();
@@ -864,7 +866,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 {}";
@@ -914,8 +916,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;
@@ -2103,7 +2107,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);
@@ -2126,13 +2130,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);
@@ -2159,8 +2161,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()
@@ -2732,7 +2732,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);
@@ -2752,17 +2752,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);
@@ -2786,13 +2784,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);
@@ -2803,8 +2799,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()
@@ -2964,7 +2958,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);
@@ -2975,12 +2969,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);
@@ -3002,7 +2995,6 @@ void tst_qquicktext::imgTagsUpdates()
QCOMPARE(spy.count(), 3);
delete myText;
- delete window;
}
void tst_qquicktext::imgTagsError()
@@ -4158,6 +4150,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());
+}
+
QTEST_MAIN(tst_qquicktext)
#include "tst_qquicktext.moc"