diff options
Diffstat (limited to 'tests/auto/quick/qquicktext/tst_qquicktext.cpp')
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 1f7d000bda..8fcdcca5a2 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -3278,12 +3278,12 @@ void tst_qquicktext::imgTagsAlign_data() QTest::addColumn<QString>("src"); QTest::addColumn<int>("imgHeight"); QTest::addColumn<QString>("align"); - QTest::newRow("heart-bottom") << "data/images/heart200.png" << 181 << "bottom"; - QTest::newRow("heart-middle") << "data/images/heart200.png" << 181 << "middle"; - QTest::newRow("heart-top") << "data/images/heart200.png" << 181 << "top"; - QTest::newRow("starfish-bottom") << "data/images/starfish_2.png" << 217 << "bottom"; - QTest::newRow("starfish-middle") << "data/images/starfish_2.png" << 217 << "middle"; - QTest::newRow("starfish-top") << "data/images/starfish_2.png" << 217 << "top"; + QTest::newRow("heart-bottom") << "images/heart200.png" << 181 << "bottom"; + QTest::newRow("heart-middle") << "images/heart200.png" << 181 << "middle"; + QTest::newRow("heart-top") << "images/heart200.png" << 181 << "top"; + QTest::newRow("starfish-bottom") << "images/starfish_2.png" << 217 << "bottom"; + QTest::newRow("starfish-middle") << "images/starfish_2.png" << 217 << "middle"; + QTest::newRow("starfish-top") << "images/starfish_2.png" << 217 << "top"; } void tst_qquicktext::imgTagsAlign() @@ -3293,7 +3293,7 @@ void tst_qquicktext::imgTagsAlign() QFETCH(QString, align); QString componentStr = "import QtQuick 2.0\nText { text: \"This is a test <img src=\\\"" + src + "\\\" align=\\\"" + align + "\\\"> of image.\" }"; QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(".")); + textComponent.setData(componentStr.toLatin1(), testFileUrl(".")); QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != nullptr); @@ -3315,10 +3315,10 @@ void tst_qquicktext::imgTagsAlign() void tst_qquicktext::imgTagsMultipleImages() { - QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"data/images/starfish_2.png\\\" width=\\\"60\\\" height=\\\"60\\\" > and another one<img src=\\\"data/images/heart200.png\\\" width=\\\"85\\\" height=\\\"85\\\">.\" }"; + QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"images/starfish_2.png\\\" width=\\\"60\\\" height=\\\"60\\\" > and another one<img src=\\\"images/heart200.png\\\" width=\\\"85\\\" height=\\\"85\\\">.\" }"; QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(".")); + textComponent.setData(componentStr.toLatin1(), testFileUrl(".")); QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != nullptr); @@ -3374,11 +3374,15 @@ void tst_qquicktext::imgTagsUpdates() void tst_qquicktext::imgTagsError() { - QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"data/images/starfish_2.pn\\\" width=\\\"60\\\" height=\\\"60\\\">.\" }"; + QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"images/starfish_2.pn\\\" width=\\\"60\\\" height=\\\"60\\\">.\" }"; QQmlComponent textComponent(&engine); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:2:1: QML Text: Cannot open: file:data/images/starfish_2.pn"); - textComponent.setData(componentStr.toLatin1(), QUrl("file:")); + const QString expectedMessage( + testFileUrl(".").toString() + + ":2:1: QML Text: Cannot open: " + + testFileUrl("images/starfish_2.pn").toString()); + QTest::ignoreMessage(QtWarningMsg, expectedMessage.toLatin1()); + textComponent.setData(componentStr.toLatin1(), testFileUrl(".")); QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != nullptr); @@ -3626,6 +3630,46 @@ void tst_qquicktext::fontSizeMode() myText->setElideMode(QQuickText::ElideNone); QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + + // Growing height needs to update the baselineOffset when AlignBottom is used + // and text is NOT wrapped + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::Fit); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + + int baselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() * 2); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QVERIFY(myText->baselineOffset() > baselineOffset); + + // Growing height needs to update the baselineOffset when AlignBottom is used + // and the text is wrapped + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::Fit); + myText->setWrapMode(QQuickText::NoWrap); + myText->resetMaximumLineCount(); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + + baselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() * 2); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QVERIFY(myText->baselineOffset() > baselineOffset); + + // Check baselineOffset for the HorizontalFit case + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::HorizontalFit); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QSignalSpy baselineOffsetSpy(myText, SIGNAL(baselineOffsetChanged(qreal))); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + const qreal oldBaselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() + 42); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QCOMPARE(baselineOffsetSpy.count(), 1); + QCOMPARE(myText->baselineOffset(), oldBaselineOffset + 42); + myText->setHeight(myText->height() - 42); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QCOMPARE(baselineOffsetSpy.count(), 2); + QCOMPARE(myText->baselineOffset(), oldBaselineOffset); } void tst_qquicktext::fontSizeModeMultiline_data() |