diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2012-04-16 10:12:38 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-01 08:50:57 +0200 |
commit | 283d5bff3dc8c89bd6c5874710e68b694d47bce6 (patch) | |
tree | 702fa1f6684fbf81d53a6a9db05a19fb9855cf19 /tests | |
parent | 9a107f47ea50f40ce6b9695fba0190b99f76642a (diff) |
Improve QQuickText tests
Test list support and make sure that we paint the text elements.
This should also improve QQuickTextNode code coverage.
Change-Id: I96c24cc452c6a4cf16064d580738e6764d859812
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktext/data/htmlLists.qml | 12 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/overline.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/strikeout.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/underline.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 149 |
5 files changed, 136 insertions, 70 deletions
diff --git a/tests/auto/quick/qquicktext/data/htmlLists.qml b/tests/auto/quick/qquicktext/data/htmlLists.qml new file mode 100644 index 0000000000..18693d2bbb --- /dev/null +++ b/tests/auto/quick/qquicktext/data/htmlLists.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + width: 400 + height: 400 + + Text { + id: myText + textFormat: Text.RichText + objectName: "myText" + } +} diff --git a/tests/auto/quick/qquicktext/data/overline.qml b/tests/auto/quick/qquicktext/data/overline.qml new file mode 100644 index 0000000000..c40cac0774 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/overline.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Item { + width: 200 + height: 200 + + Text { + id: myText + objectName: "myText" + width: 200 + wrapMode: Text.WordWrap + font.overline: true + text: "Testing that maximumLines, visibleLines, and totalLines works properly in the autotests. The quick brown fox jumped over the lazy anything with the letter 'g'." + } +} diff --git a/tests/auto/quick/qquicktext/data/strikeout.qml b/tests/auto/quick/qquicktext/data/strikeout.qml new file mode 100644 index 0000000000..d926d94f06 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/strikeout.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Item { + width: 200 + height: 200 + + Text { + id: myText + objectName: "myText" + width: 200 + wrapMode: Text.WordWrap + font.strikeout: true + text: "Testing that maximumLines, visibleLines, and totalLines works properly in the autotests. The quick brown fox jumped over the lazy anything with the letter 'g'." + } +} diff --git a/tests/auto/quick/qquicktext/data/underline.qml b/tests/auto/quick/qquicktext/data/underline.qml new file mode 100644 index 0000000000..dff97080d5 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/underline.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Item { + width: 200 + height: 200 + + Text { + id: myText + objectName: "myText" + width: 200 + wrapMode: Text.WordWrap + font.underline: true + text: "Testing that maximumLines, visibleLines, and totalLines works properly in the autotests. The quick brown fox jumped over the lazy anything with the letter 'g'." + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index d1899a62b7..a83a10e216 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -137,6 +137,9 @@ private slots: void baselineOffset_data(); void baselineOffset(); + void htmlLists(); + void htmlLists_data(); + private: QStringList standard; QStringList richText; @@ -1198,80 +1201,41 @@ void tst_qquicktext::weight() void tst_qquicktext::underline() { - { - QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().underline(), false); - - delete textObject; - } - { - QString componentStr = "import QtQuick 2.0\nText { font.underline: true; text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().underline(), true); - - delete textObject; - } + QQuickView view(testFileUrl("underline.qml")); + view.show(); + view.requestActivateWindow(); + QTest::qWaitForWindowShown(&view); + QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText"); + QVERIFY(textObject != 0); + QCOMPARE(textObject->font().overline(), false); + QCOMPARE(textObject->font().underline(), true); + QCOMPARE(textObject->font().strikeOut(), false); } void tst_qquicktext::overline() { - { - QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().overline(), false); - - delete textObject; - } - { - QString componentStr = "import QtQuick 2.0\nText { font.overline: true; text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().overline(), true); - - delete textObject; - } + QQuickView view(testFileUrl("overline.qml")); + view.show(); + view.requestActivateWindow(); + QTest::qWaitForWindowShown(&view); + QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText"); + QVERIFY(textObject != 0); + QCOMPARE(textObject->font().overline(), true); + QCOMPARE(textObject->font().underline(), false); + QCOMPARE(textObject->font().strikeOut(), false); } void tst_qquicktext::strikeout() { - { - QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().strikeOut(), false); - - delete textObject; - } - { - QString componentStr = "import QtQuick 2.0\nText { font.strikeout: true; text: \"Hello world!\" }"; - QQmlComponent textComponent(&engine); - textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->font().strikeOut(), true); - - delete textObject; - } + QQuickView view(testFileUrl("strikeout.qml")); + view.show(); + view.requestActivateWindow(); + QTest::qWaitForWindowShown(&view); + QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText"); + QVERIFY(textObject != 0); + QCOMPARE(textObject->font().overline(), false); + QCOMPARE(textObject->font().underline(), false); + QCOMPARE(textObject->font().strikeOut(), true); } void tst_qquicktext::capitalization() @@ -1520,11 +1484,13 @@ void tst_qquicktext::embeddedImages() if (!error.isEmpty()) QTest::ignoreMessage(QtWarningMsg, error.toLatin1()); - QQmlComponent textComponent(&engine, qmlfile); - QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); + QQuickView *view = new QQuickView(qmlfile); + view->show(); + view->requestActivateWindow(); + QTest::qWaitForWindowShown(view); + QQuickText *textObject = qobject_cast<QQuickText*>(view->rootObject()); QVERIFY(textObject != 0); - QTRY_COMPARE(textObject->resourcesLoading(), 0); QPixmap pm(testFile("http/exists.png")); @@ -1537,7 +1503,7 @@ void tst_qquicktext::embeddedImages() QCOMPARE(textObject->height(), 16.0); } - delete textObject; + delete view; } void tst_qquicktext::lineCount() @@ -2939,6 +2905,49 @@ void tst_qquicktext::baselineOffset() } } +void tst_qquicktext::htmlLists() +{ + QFETCH(QString, text); + QFETCH(int, nbLines); + + QQuickView *view = createView(testFile("htmlLists.qml")); + QQuickText *textObject = view->rootObject()->findChild<QQuickText*>("myText"); + + QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); + QVERIFY(textPrivate != 0); + QVERIFY(textPrivate->extra.isAllocated()); + + QVERIFY(textObject != 0); + textObject->setText(text); + + view->show(); + view->requestActivateWindow(); + QTest::qWaitForWindowShown(view); + + QCOMPARE(textPrivate->extra->doc->lineCount(), nbLines); + + delete view; +} + +void tst_qquicktext::htmlLists_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<int>("nbLines"); + + QTest::newRow("ordered list") << "<ol><li>one<li>two<li>three" << 3; + QTest::newRow("ordered list closed") << "<ol><li>one</li></ol>" << 1; + QTest::newRow("ordered list alpha") << "<ol type=\"a\"><li>one</li><li>two</li></ol>" << 2; + QTest::newRow("ordered list upper alpha") << "<ol type=\"A\"><li>one</li><li>two</li></ol>" << 2; + QTest::newRow("ordered list roman") << "<ol type=\"i\"><li>one</li><li>two</li></ol>" << 2; + QTest::newRow("ordered list upper roman") << "<ol type=\"I\"><li>one</li><li>two</li></ol>" << 2; + QTest::newRow("ordered list bad") << "<ol type=\"z\"><li>one</li><li>two</li></ol>" << 2; + QTest::newRow("unordered list") << "<ul><li>one<li>two" << 2; + QTest::newRow("unordered list closed") << "<ul><li>one</li><li>two</li></ul>" << 2; + QTest::newRow("unordered list disc") << "<ul type=\"disc\"><li>one</li><li>two</li></ul>" << 2; + QTest::newRow("unordered list square") << "<ul type=\"square\"><li>one</li><li>two</li></ul>" << 2; + QTest::newRow("unordered list bad") << "<ul type=\"bad\"><li>one</li><li>two</li></ul>" << 2; +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" |