From 283d5bff3dc8c89bd6c5874710e68b694d47bce6 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 16 Apr 2012 10:12:38 +1000 Subject: [PATCH] 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 --- tests/auto/quick/qquicktext/data/htmlLists.qml | 12 ++ tests/auto/quick/qquicktext/data/overline.qml | 15 +++ tests/auto/quick/qquicktext/data/strikeout.qml | 15 +++ tests/auto/quick/qquicktext/data/underline.qml | 15 +++ tests/auto/quick/qquicktext/tst_qquicktext.cpp | 149 +++++++++++++----------- 5 files changed, 136 insertions(+), 70 deletions(-) create mode 100644 tests/auto/quick/qquicktext/data/htmlLists.qml create mode 100644 tests/auto/quick/qquicktext/data/overline.qml create mode 100644 tests/auto/quick/qquicktext/data/strikeout.qml create mode 100644 tests/auto/quick/qquicktext/data/underline.qml diff --git a/tests/auto/quick/qquicktext/data/htmlLists.qml b/tests/auto/quick/qquicktext/data/htmlLists.qml new file mode 100644 index 0000000..18693d2 --- /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 0000000..c40cac0 --- /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 0000000..d926d94 --- /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 0000000..dff9708 --- /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 d1899a6..a83a10e 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(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(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("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(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(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("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(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(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("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(textComponent.create()); + QQuickView *view = new QQuickView(qmlfile); + view->show(); + view->requestActivateWindow(); + QTest::qWaitForWindowShown(view); + QQuickText *textObject = qobject_cast(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("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("text"); + QTest::addColumn("nbLines"); + + QTest::newRow("ordered list") << "
  1. one
  2. two
  3. three" << 3; + QTest::newRow("ordered list closed") << "
    1. one
    " << 1; + QTest::newRow("ordered list alpha") << "
    1. one
    2. two
    " << 2; + QTest::newRow("ordered list upper alpha") << "
    1. one
    2. two
    " << 2; + QTest::newRow("ordered list roman") << "
    1. one
    2. two
    " << 2; + QTest::newRow("ordered list upper roman") << "
    1. one
    2. two
    " << 2; + QTest::newRow("ordered list bad") << "
    1. one
    2. two
    " << 2; + QTest::newRow("unordered list") << "
    • one
    • two" << 2; + QTest::newRow("unordered list closed") << "
      • one
      • two
      " << 2; + QTest::newRow("unordered list disc") << "
      • one
      • two
      " << 2; + QTest::newRow("unordered list square") << "
      • one
      • two
      " << 2; + QTest::newRow("unordered list bad") << "
      • one
      • two
      " << 2; +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" -- 1.7.2.5