From 447fea7eb02972f189a468782aa1f48ab796611a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 16:56:54 +1000 Subject: add some QmlGraphicsText tests --- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 67 ++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 173a3b4..49fc757 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -64,6 +64,7 @@ private slots: void font(); void style(); void color(); + void smooth(); private: QStringList standard; @@ -211,30 +212,34 @@ void tst_qfxtext::wrap() { // XXX Poor coverage - should at least be testing an expected height. + int textHeight = 0; // for specified width and wrap set true { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); QCOMPARE(textObject->width(), 300.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } } @@ -317,7 +322,6 @@ void tst_qfxtext::verticalAlignment() QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } @@ -339,7 +343,7 @@ void tst_qfxtext::verticalAlignment() void tst_qfxtext::font() { //test size, then bold, then italic, then family - { + { QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); @@ -349,6 +353,16 @@ void tst_qfxtext::font() QCOMPARE(textObject->font().italic(), false); } + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + { QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -391,12 +405,12 @@ void tst_qfxtext::style() //test style for (int i = 0; i < styles.size(); i++) { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor()); + QCOMPARE(textObject->styleColor(), QColor("white")); } } @@ -448,6 +462,41 @@ void tst_qfxtext::color() QCOMPARE(textObject->color(), testColor); } } + +void tst_qfxtext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + QTEST_MAIN(tst_qfxtext) #include "tst_qfxtext.moc" -- cgit v0.12 From 8dbea8ec48084b27c56f7d263c38c84ff03ebc3d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:08:45 +1000 Subject: qmlgraphicstext tests --- tests/auto/declarative/qfxtext/qfxtext.pro | 5 - tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 502 --------------------- .../qmlgraphicstext/qmlgraphicstext.pro | 5 + .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 500 ++++++++++++++++++++ 4 files changed, 505 insertions(+), 507 deletions(-) delete mode 100644 tests/auto/declarative/qfxtext/qfxtext.pro delete mode 100644 tests/auto/declarative/qfxtext/tst_qfxtext.cpp create mode 100644 tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro create mode 100644 tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qfxtext/qfxtext.pro deleted file mode 100644 index 1f3fe37..0000000 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui -macx:CONFIG -= app_bundle - -SOURCES += tst_qfxtext.cpp diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp deleted file mode 100644 index 49fc757..0000000 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -class tst_qfxtext : public QObject - -{ - Q_OBJECT -public: - tst_qfxtext(); - -private slots: - void text(); - void width(); - void wrap(); - void elide(); - - // ### these tests may be trivial - void horizontalAlignment(); - void verticalAlignment(); - void font(); - void style(); - void color(); - void smooth(); - -private: - QStringList standard; - QStringList richText; - - QStringList horizontalAlignmentmentStrings; - QStringList verticalAlignmentmentStrings; - - QList verticalAlignmentments; - QList horizontalAlignmentments; - - QStringList styleStrings; - QList styles; - - QStringList colorStrings; - - QmlEngine engine; -}; - -tst_qfxtext::tst_qfxtext() -{ - standard << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox\n jumped over the lazy dog"; - - richText << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox
jumped over the lazy dog
"; - - horizontalAlignmentmentStrings << "AlignLeft" - << "AlignRight" - << "AlignHCenter"; - - verticalAlignmentmentStrings << "AlignTop" - << "AlignBottom" - << "AlignVCenter"; - - horizontalAlignmentments << Qt::AlignLeft - << Qt::AlignRight - << Qt::AlignHCenter; - - verticalAlignmentments << Qt::AlignTop - << Qt::AlignBottom - << Qt::AlignVCenter; - - styleStrings << "Normal" - << "Outline" - << "Raised" - << "Sunken"; - - styles << QmlGraphicsText::Normal - << QmlGraphicsText::Outline - << QmlGraphicsText::Raised - << QmlGraphicsText::Sunken; - - colorStrings << "aliceblue" - << "antiquewhite" - << "aqua" - << "darkkhaki" - << "darkolivegreen" - << "dimgray" - << "palevioletred" - << "lightsteelblue" - << "#000000" - << "#AAAAAA" - << "#FFFFFF" - << "#2AC05F"; - // - // need a different test to do alpha channel test - // << "#AA0011DD" - // << "#00F16B11"; - // -} - -void tst_qfxtext::text() -{ - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), QString("")); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), standard.at(i)); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QString expected = richText.at(i); - QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); - } -} - -void tst_qfxtext::width() -{ - // uses Font metrics to find the width for standard and document to find the width for rich - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 0.); - } - - for (int i = 0; i < standard.size(); i++) - { - QFont f; - QFontMetrics fm(f); - int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(metricWidth)); - } - - for (int i = 0; i < richText.size(); i++) - { - QTextDocument document; - document.setHtml(richText.at(i)); - document.setDocumentMargin(0); - - int documentWidth = document.idealWidth(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(documentWidth)); - } -} - -void tst_qfxtext::wrap() -{ - // XXX Poor coverage - should at least be testing an expected height. - - int textHeight = 0; - // for specified width and wrap set true - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - textHeight = textObject->height(); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - -} - -void tst_qfxtext::elide() -{ - for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { - const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; - - // XXX Poor coverage. - - { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - // richtext - does nothing - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - } -} - -//the alignment tests may be trivial o.oa -void tst_qfxtext::horizontalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::verticalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::font() -{ - //test size, then bold, then italic, then family - { - QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pointSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pixelSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().bold(), true); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().italic(), true); - QCOMPARE(textObject->font().bold(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("Helvetica")); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("")); - } -} - -void tst_qfxtext::style() -{ - //test style - for (int i = 0; i < styles.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor("white")); - } -} - -void tst_qfxtext::color() -{ - //test style - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor()); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); - // default color to black? - QCOMPARE(textObject->color(), QColor("black")); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - for (int j = 0; j < colorStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); - } - } - { - QString colorStr = "#AA001234"; - QColor testColor("#001234"); - testColor.setAlpha(170); - - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), testColor); - } -} - -void tst_qfxtext::smooth() -{ - for (int i = 0; i < standard.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } - for (int i = 0; i < richText.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } -} - -QTEST_MAIN(tst_qfxtext) - -#include "tst_qfxtext.moc" diff --git a/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro new file mode 100644 index 0000000..1d8c59f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp new file mode 100644 index 0000000..d53de59 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -0,0 +1,500 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +class tst_qmlgraphicstext : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicstext(); + +private slots: + void text(); + void width(); + void wrap(); + void elide(); + + // ### these tests may be trivial + void horizontalAlignment(); + void verticalAlignment(); + void font(); + void style(); + void color(); + void smooth(); + +private: + QStringList standard; + QStringList richText; + + QStringList horizontalAlignmentmentStrings; + QStringList verticalAlignmentmentStrings; + + QList verticalAlignmentments; + QList horizontalAlignmentments; + + QStringList styleStrings; + QList styles; + + QStringList colorStrings; + + QmlEngine engine; +}; + +tst_qmlgraphicstext::tst_qmlgraphicstext() +{ + standard << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox\n jumped over the lazy dog"; + + richText << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox
jumped over the lazy dog
"; + + horizontalAlignmentmentStrings << "AlignLeft" + << "AlignRight" + << "AlignHCenter"; + + verticalAlignmentmentStrings << "AlignTop" + << "AlignBottom" + << "AlignVCenter"; + + horizontalAlignmentments << Qt::AlignLeft + << Qt::AlignRight + << Qt::AlignHCenter; + + verticalAlignmentments << Qt::AlignTop + << Qt::AlignBottom + << Qt::AlignVCenter; + + styleStrings << "Normal" + << "Outline" + << "Raised" + << "Sunken"; + + styles << QmlGraphicsText::Normal + << QmlGraphicsText::Outline + << QmlGraphicsText::Raised + << QmlGraphicsText::Sunken; + + colorStrings << "aliceblue" + << "antiquewhite" + << "aqua" + << "darkkhaki" + << "darkolivegreen" + << "dimgray" + << "palevioletred" + << "lightsteelblue" + << "#000000" + << "#AAAAAA" + << "#FFFFFF" + << "#2AC05F"; + // + // need a different test to do alpha channel test + // << "#AA0011DD" + // << "#00F16B11"; + // +} + +void tst_qmlgraphicstext::text() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), QString("")); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), standard.at(i)); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QString expected = richText.at(i); + QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + } +} + +void tst_qmlgraphicstext::width() +{ + // uses Font metrics to find the width for standard and document to find the width for rich + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 0.); + } + + for (int i = 0; i < standard.size(); i++) + { + QFont f; + QFontMetrics fm(f); + int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(metricWidth)); + } + + for (int i = 0; i < richText.size(); i++) + { + QTextDocument document; + document.setHtml(richText.at(i)); + document.setDocumentMargin(0); + + int documentWidth = document.idealWidth(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(documentWidth)); + } +} + +void tst_qmlgraphicstext::wrap() +{ + int textHeight = 0; + // for specified width and wrap set true + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + +} + +void tst_qmlgraphicstext::elide() +{ + for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { + const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; + QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + + // XXX Poor coverage. + + { + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + // richtext - does nothing + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + } +} + +//the alignment tests may be trivial o.oa +void tst_qmlgraphicstext::horizontalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::verticalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::font() +{ + //test size, then bold, then italic, then family + { + QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pointSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().bold(), true); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().italic(), true); + QCOMPARE(textObject->font().bold(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("Helvetica")); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("")); + } +} + +void tst_qmlgraphicstext::style() +{ + //test style + for (int i = 0; i < styles.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->style(), (int)styles.at(i)); + QCOMPARE(textObject->styleColor(), QColor("white")); + } +} + +void tst_qmlgraphicstext::color() +{ + //test style + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor()); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); + // default color to black? + QCOMPARE(textObject->color(), QColor("black")); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + for (int j = 0; j < colorStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); + } + } + { + QString colorStr = "#AA001234"; + QColor testColor("#001234"); + testColor.setAlpha(170); + + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), testColor); + } +} + +void tst_qmlgraphicstext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + +QTEST_MAIN(tst_qmlgraphicstext) + +#include "tst_qmlgraphicstext.moc" -- cgit v0.12 From 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:50:26 +1000 Subject: QmlFontLoader tests --- .../declarative/qmlfontloader/data/Fontin-Bold.ttf | Bin 0 -> 30916 bytes .../declarative/qmlfontloader/qmlfontloader.pro | 5 ++ .../qmlfontloader/tst_qmlfontloader.cpp | 89 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf create mode 100644 tests/auto/declarative/qmlfontloader/qmlfontloader.pro create mode 100644 tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf new file mode 100644 index 0000000..f6a33b0 Binary files /dev/null and b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf differ diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro new file mode 100644 index 0000000..0ecfde0 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp new file mode 100644 index 0000000..a65ecf4 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include + +class tst_qmlfontloader : public QObject + +{ + Q_OBJECT +public: + tst_qmlfontloader(); + +private slots: + void namedfont(); + void localfont(); + +private slots: + +private: + QmlEngine engine; +}; + +tst_qmlfontloader::tst_qmlfontloader() +{ +} + +void tst_qmlfontloader::namedfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Helvetica")); +} + +void tst_qmlfontloader::localfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Fontin")); +} + +QTEST_MAIN(tst_qmlfontloader) + +#include "tst_qmlfontloader.moc" -- cgit v0.12 From 0cda0d00f95cbcd292f4b1f5ed4a47d43e0ac825 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 18:29:34 +1000 Subject: QmlMetaType test --- tests/auto/declarative/declarative.pro | 1 + tests/auto/declarative/qmlmetatype/qmlmetatype.pro | 6 + .../declarative/qmlmetatype/tst_qmlmetatype.cpp | 220 +++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 tests/auto/declarative/qmlmetatype/qmlmetatype.pro create mode 100644 tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 0d55391..26e8346 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -23,6 +23,7 @@ SUBDIRS += anchors \ qmllist \ qmllistaccessor \ qmlmetaproperty \ + qmlmetatype \ qmlpropertymap \ qmltimer \ repeater \ diff --git a/tests/auto/declarative/qmlmetatype/qmlmetatype.pro b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro new file mode 100644 index 0000000..3a9a400 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/qmlmetatype.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlmetatype.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp new file mode 100644 index 0000000..06a47c0 --- /dev/null +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlmetatype : public QObject +{ + Q_OBJECT +public: + tst_qmlmetatype() {} + +private slots: + void copy(); +}; + +#define COPY_TEST(cpptype, metatype, value, defaultvalue) \ +{ \ + cpptype v = (value); cpptype v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, 0)); \ + QVERIFY(v == (defaultvalue)); \ + QVERIFY(QmlMetaType::copy(QMetaType:: metatype, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +#define QT_COPY_TEST(type, value) \ +{ \ + type v = (value); type v2 = (value); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, 0)); \ + QVERIFY(v == (type ())); \ + QVERIFY(QmlMetaType::copy(QMetaType:: type, &v, &v2)); \ + QVERIFY(v == (value)); \ +} + +void tst_qmlmetatype::copy() +{ + QVERIFY(QmlMetaType::copy(QMetaType::Void, 0, 0)); + + COPY_TEST(bool, Bool, true, false); + COPY_TEST(int, Int, 10, 0); + COPY_TEST(unsigned int, UInt, 10, 0); + COPY_TEST(long long, LongLong, 10, 0); + COPY_TEST(unsigned long long, ULongLong, 10, 0); + COPY_TEST(double, Double, 19.2, 0); + + QT_COPY_TEST(QChar, QChar('a')); + + QVariantMap variantMap; + variantMap.insert("Hello World!", QVariant(10)); + QT_COPY_TEST(QVariantMap, variantMap); + + QT_COPY_TEST(QVariantList, QVariantList() << QVariant(19.2)); + QT_COPY_TEST(QString, QString("QML Rocks!")); + QT_COPY_TEST(QStringList, QStringList() << "QML" << "Rocks"); + QT_COPY_TEST(QByteArray, QByteArray("0x1102DDD")); + QT_COPY_TEST(QBitArray, QBitArray(102, true)); + QT_COPY_TEST(QDate, QDate::currentDate()); + QT_COPY_TEST(QTime, QTime::currentTime()); + QT_COPY_TEST(QDateTime, QDateTime::currentDateTime()); + QT_COPY_TEST(QUrl, QUrl("http://www.nokia.com")); + QT_COPY_TEST(QLocale, QLocale(QLocale::English, QLocale::Australia)); + QT_COPY_TEST(QRect, QRect(-10, 10, 102, 99)); + QT_COPY_TEST(QRectF, QRectF(-10.2, 1.2, 102, 99.6)); + QT_COPY_TEST(QSize, QSize(100, 2)); + QT_COPY_TEST(QSizeF, QSizeF(20.2, -100234.2)); + QT_COPY_TEST(QLine, QLine(0, 0, 100, 100)); + QT_COPY_TEST(QLineF, QLineF(-10.2, 0, 103, 1)); + QT_COPY_TEST(QPoint, QPoint(-1912, 1613)); + QT_COPY_TEST(QPointF, QPointF(-908.1, 1612)); + QT_COPY_TEST(QRegExp, QRegExp("(\\d+)(?:\\s*)(cm|inch)")); + + QVariantHash variantHash; + variantHash.insert("Hello World!", QVariant(19)); + QT_COPY_TEST(QVariantHash, variantHash); + +#ifdef QT3_SUPPORT + QT_COPY_TEST(QColorGroup, QColorGroup(Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red, Qt::red)); +#endif + + QT_COPY_TEST(QFont, QFont("Helvetica", 1024)); + + { + QPixmap v = QPixmap(100, 100); QPixmap v2 = QPixmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap, &v, 0)); + QVERIFY(v.size() == QPixmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QPixmap , &v, &v2)); + QVERIFY(v.size() == QPixmap(100,100).size()); + } + + QT_COPY_TEST(QBrush, QBrush(Qt::blue)); + QT_COPY_TEST(QColor, QColor("lightsteelblue")); + QT_COPY_TEST(QPalette, QPalette(Qt::green)); + + { + QPixmap icon(100, 100); + + QIcon v = QIcon(icon); QIcon v2 = QIcon(icon); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon, &v, 0)); + QVERIFY(v.isNull() == QIcon().isNull()); + QVERIFY(QmlMetaType::copy(QMetaType::QIcon , &v, &v2)); + QVERIFY(v.isNull() == QIcon(icon).isNull()); + } + + { + QImage v = QImage(100, 100, QImage::Format_RGB32); + QImage v2 = QImage(100, 100, QImage::Format_RGB32); + QVERIFY(QmlMetaType::copy(QMetaType::QImage, &v, 0)); + QVERIFY(v.size() == QImage().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QImage , &v, &v2)); + QVERIFY(v.size() == QImage(100,100, QImage::Format_RGB32).size()); + } + + QT_COPY_TEST(QPolygon, QPolygon(QRect(100, 100, 200, 103))); + QT_COPY_TEST(QRegion, QRegion(QRect(0, 10, 99, 87))); + + { + QBitmap v = QBitmap(100, 100); QBitmap v2 = QBitmap(100, 100); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap, &v, 0)); + QVERIFY(v.size() == QBitmap().size()); + QVERIFY(QmlMetaType::copy(QMetaType::QBitmap , &v, &v2)); + QVERIFY(v.size() == QBitmap(100,100).size()); + } + + { + QCursor v = QCursor(Qt::SizeFDiagCursor); QCursor v2 = QCursor(Qt::SizeFDiagCursor); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor, &v, 0)); + QVERIFY(v.shape() == QCursor().shape()); + QVERIFY(QmlMetaType::copy(QMetaType::QCursor , &v, &v2)); + QVERIFY(v.shape() == QCursor(Qt::SizeFDiagCursor).shape()); + } + + QT_COPY_TEST(QSizePolicy, QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum)); + QT_COPY_TEST(QKeySequence, QKeySequence("Ctrl+O")); + QT_COPY_TEST(QPen, QPen(Qt::red)); + QT_COPY_TEST(QTextLength, QTextLength(QTextLength::FixedLength, 10.2)); + QT_COPY_TEST(QMatrix, QMatrix().translate(10, 10)); + QT_COPY_TEST(QTransform, QTransform().translate(10, 10)); + QT_COPY_TEST(QMatrix4x4, QMatrix4x4().translate(10, 10)); + QT_COPY_TEST(QVector2D, QVector2D(10.2, 1)); + QT_COPY_TEST(QVector3D, QVector3D(10.2, 1, -2)); + QT_COPY_TEST(QVector4D, QVector4D(10.2, 1, -2, 1.2)); + QT_COPY_TEST(QQuaternion, QQuaternion(1.0, 10.2, 1, -2)); + + int voidValue; + COPY_TEST(void *, VoidStar, (void *)&voidValue, (void *)0); + COPY_TEST(long, Long, 10, 0); + COPY_TEST(short, Short, 10, 0); + COPY_TEST(char, Char, 'a', 0); + COPY_TEST(unsigned long, ULong, 10, 0); + COPY_TEST(unsigned short, UShort, 10, 0); + COPY_TEST(unsigned char, UChar, 'a', 0); + COPY_TEST(float, Float, 10.5, 0); + + QObject objectValue; + QWidget widgetValue; + COPY_TEST(QObject *, QObjectStar, &objectValue, 0); + COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); + COPY_TEST(qreal, QReal, 10.2, 0); + + +#if 0 + enum Type { + + QReal = 0, + User = 256 + }; +#endif +} + +QTEST_MAIN(tst_qmlmetatype) + +#include "tst_qmlmetatype.moc" -- cgit v0.12 From feeb75edbbe0912f1719cf405be5927da6890d47 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 18:32:14 +1000 Subject: autotests --- .../qmlfontloader/tst_qmlfontloader.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index a65ecf4..464ae5d 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -42,6 +42,7 @@ #include #include #include +#include "../../../shared/util.h" class tst_qmlfontloader : public QObject @@ -51,8 +52,10 @@ public: tst_qmlfontloader(); private slots: + void nofont(); void namedfont(); void localfont(); + void webfont(); private slots: @@ -64,6 +67,16 @@ tst_qmlfontloader::tst_qmlfontloader() { } +void tst_qmlfontloader::nofont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("")); +} + void tst_qmlfontloader::namedfont() { QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; @@ -84,6 +97,16 @@ void tst_qmlfontloader::localfont() QCOMPARE(fontObject->name(), QString("Fontin")); } +void tst_qmlfontloader::webfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("Starburst")); +} + QTEST_MAIN(tst_qmlfontloader) #include "tst_qmlfontloader.moc" -- cgit v0.12 From d5c34887e0a563511ff124b497e5e869a64cda34 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:14:58 +1000 Subject: Fix incorrect assert QT-2432 --- src/declarative/qml/qmlcompiler.cpp | 2 +- tests/auto/declarative/qmllanguage/data/crash2.qml | 5 +++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmllanguage/data/crash2.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index b93a9b3..3253e72 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2366,7 +2366,7 @@ bool QmlCompiler::buildBinding(QmlParser::Value *value, QmlParser::Property *prop, const BindingContext &ctxt) { - Q_ASSERT(prop->index); + Q_ASSERT(prop->index != -1); Q_ASSERT(prop->parent); Q_ASSERT(prop->parent->metaObject()); diff --git a/tests/auto/declarative/qmllanguage/data/crash2.qml b/tests/auto/declarative/qmllanguage/data/crash2.qml new file mode 100644 index 0000000..ae6f650 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/crash2.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + objectName: "Hello" + "World" +} diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 128fa87..da586d9 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -123,6 +123,7 @@ private slots: // regression tests for crashes void crash1(); + void crash2(); private: QmlEngine engine; @@ -1152,6 +1153,11 @@ void tst_qmllanguage::crash1() QmlComponent component(&engine, "Component {}"); } +void tst_qmllanguage::crash2() +{ + QmlComponent component(&engine, TEST_FILE("crash2.qml")); +} + QTEST_MAIN(tst_qmllanguage) #include "tst_qmllanguage.moc" -- cgit v0.12 From 337263994aafa64fd96d503d49a8a3316bdb1827 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:18 +1000 Subject: Remove dead code --- tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp index 06a47c0..ed102a5 100644 --- a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -204,15 +204,6 @@ void tst_qmlmetatype::copy() COPY_TEST(QObject *, QObjectStar, &objectValue, 0); COPY_TEST(QWidget *, QWidgetStar, &widgetValue, 0); COPY_TEST(qreal, QReal, 10.2, 0); - - -#if 0 - enum Type { - - QReal = 0, - User = 256 - }; -#endif } QTEST_MAIN(tst_qmlmetatype) -- cgit v0.12 From a36694346164f0865e16003745839279dad7f61e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 3 Nov 2009 19:16:37 +1000 Subject: qfxtext -> qmlgraphicstext --- tests/auto/declarative/declarative.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 26e8346..73269e1 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -11,7 +11,6 @@ SUBDIRS += anchors \ pathview \ qfxloader \ qfxpixmapcache \ - qfxtext \ qfxtextedit \ qfxtextinput \ qfxwebview \ @@ -19,6 +18,7 @@ SUBDIRS += anchors \ qmlcontext \ qmldom \ qmlecmascript \ + qmlgraphicstext \ qmllanguage \ qmllist \ qmllistaccessor \ -- cgit v0.12 From d6d473534fdb08a417cc113368742c0ec011a97e Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 22:14:36 +1000 Subject: more qmlfontloader tests --- src/declarative/extra/qmlfontloader.cpp | 2 ++ .../auto/declarative/qmlfontloader/data/dummy.ttf | 0 .../declarative/qmlfontloader/qmlfontloader.pro | 3 ++ .../qmlfontloader/tst_qmlfontloader.cpp | 32 ++++++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlfontloader/data/dummy.ttf diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp index 8c17d0f..e8db649 100644 --- a/src/declarative/extra/qmlfontloader.cpp +++ b/src/declarative/extra/qmlfontloader.cpp @@ -163,6 +163,8 @@ void QmlFontLoader::setName(const QString &name) return; d->name = name; emit nameChanged(); + d->status = Ready; + emit statusChanged(); } /*! diff --git a/tests/auto/declarative/qmlfontloader/data/dummy.ttf b/tests/auto/declarative/qmlfontloader/data/dummy.ttf new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro index 0ecfde0..bc89639 100644 --- a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -3,3 +3,6 @@ contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle SOURCES += tst_qmlfontloader.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 464ae5d..4bbc595 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -55,7 +55,9 @@ private slots: void nofont(); void namedfont(); void localfont(); + void faillocalfont(); void webfont(); + void failwebfont(); private slots: @@ -75,6 +77,7 @@ void tst_qmlfontloader::nofont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null); } void tst_qmlfontloader::namedfont() @@ -85,16 +88,29 @@ void tst_qmlfontloader::namedfont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("Helvetica")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } void tst_qmlfontloader::localfont() { - QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); QmlFontLoader *fontObject = qobject_cast(component.create()); QVERIFY(fontObject != 0); - QCOMPARE(fontObject->name(), QString("Fontin")); + QTRY_COMPARE(fontObject->name(), QString("Fontin")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::faillocalfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } void tst_qmlfontloader::webfont() @@ -105,6 +121,18 @@ void tst_qmlfontloader::webfont() QVERIFY(fontObject != 0); QTRY_COMPARE(fontObject->name(), QString("Starburst")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::failwebfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } QTEST_MAIN(tst_qmlfontloader) -- cgit v0.12 From d1a1d5df2ec9e34cdbed340685fc8e8dd8e9bece Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 26 Oct 2009 12:40:33 +0100 Subject: introduce int QTextDocument::available{Undo,Redo}Steps() const; Formerly, QTextDocument::revision() could be used to guesstimate the number of available undo steps that was used in Qt Creator to store cursor positions in parallel to the actual text contents. Now that revision() is strictly increasing, another means is needed, therefore the new functions providing the needed data. Reviewed-by: mae --- src/gui/text/qtextdocument.cpp | 27 +++++++++++++++++++++++++++ src/gui/text/qtextdocument.h | 3 +++ src/gui/text/qtextdocument_p.h | 3 +++ 3 files changed, 33 insertions(+) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6978b6c..1aad385 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -958,6 +958,8 @@ QString QTextDocument::defaultStyleSheet() const /*! Returns true if undo is available; otherwise returns false. + + \sa isRedoAvailable(), availableUndoSteps() */ bool QTextDocument::isUndoAvailable() const { @@ -967,6 +969,8 @@ bool QTextDocument::isUndoAvailable() const /*! Returns true if redo is available; otherwise returns false. + + \sa isUndoAvailable(), availableRedoSteps() */ bool QTextDocument::isRedoAvailable() const { @@ -974,6 +978,29 @@ bool QTextDocument::isRedoAvailable() const return d->isRedoAvailable(); } +/*! \since 4.6 + + Returns the number of available undo steps. + + \sa isUndoAvailable() +*/ +int QTextDocument::availableUndoSteps() const +{ + Q_D(const QTextDocument); + return d->availableUndoSteps(); +} + +/*! \since 4.6 + + Returns the number of available redo steps. + + \sa isRedoAvailable() +*/ +int QTextDocument::availableRedoSteps() const +{ + Q_D(const QTextDocument); + return d->availableRedoSteps(); +} /*! \since 4.4 diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e52716a..d217a4d 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -142,6 +142,9 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; + int availableUndoSteps() const; + int availableRedoSteps() const; + int revision() const; void setDocumentLayout(QAbstractTextDocumentLayout *layout); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index ce25c57..c10855b 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -212,6 +212,9 @@ public: inline bool isUndoAvailable() const { return undoEnabled && undoState > 0; } inline bool isRedoAvailable() const { return undoEnabled && undoState < undoStack.size(); } + inline int availableUndoSteps() const { return undoEnabled ? undoState : 0; } + inline int availableRedoSteps() const { return undoEnabled ? qMax(undoStack.size() - undoState - 1, 0) : 0; } + inline QString buffer() const { return text; } QString plainText() const; inline int length() const { return fragments.length(); } -- cgit v0.12 From 356fe6a0474c07dc6dd8ffd9b52f1e2060e3a450 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 08:28:17 +1000 Subject: Add missing files. --- tests/auto/declarative/animatedimage/data/stickman.qml | 5 +++++ tests/auto/declarative/animatedimage/data/stickmanpause.qml | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/auto/declarative/animatedimage/data/stickman.qml create mode 100644 tests/auto/declarative/animatedimage/data/stickmanpause.qml diff --git a/tests/auto/declarative/animatedimage/data/stickman.qml b/tests/auto/declarative/animatedimage/data/stickman.qml new file mode 100644 index 0000000..a70db5d --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickman.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" +} diff --git a/tests/auto/declarative/animatedimage/data/stickmanpause.qml b/tests/auto/declarative/animatedimage/data/stickmanpause.qml new file mode 100644 index 0000000..7ab17d4 --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickmanpause.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" + paused: true + currentFrame: 2 +} -- cgit v0.12 From 7ca289fbbef4e8337124ce9e086b2c5b517ecbaa Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 09:12:19 +1000 Subject: tests fixes --- .../qmlfontloader/tst_qmlfontloader.cpp | 26 ++++++------ .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 47 ++++++++++++++++++---- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 4bbc595..efc86cd 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -52,12 +52,12 @@ public: tst_qmlfontloader(); private slots: - void nofont(); - void namedfont(); - void localfont(); - void faillocalfont(); - void webfont(); - void failwebfont(); + void noFont(); + void namedFont(); + void localFont(); + void failLocalFont(); + void webFont(); + void failWebFont(); private slots: @@ -69,7 +69,7 @@ tst_qmlfontloader::tst_qmlfontloader() { } -void tst_qmlfontloader::nofont() +void tst_qmlfontloader::noFont() { QString componentStr = "import Qt 4.6\nFontLoader { }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -78,9 +78,11 @@ void tst_qmlfontloader::nofont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null); + + delete fontObject; } -void tst_qmlfontloader::namedfont() +void tst_qmlfontloader::namedFont() { QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -91,7 +93,7 @@ void tst_qmlfontloader::namedfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::localfont() +void tst_qmlfontloader::localFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -102,7 +104,7 @@ void tst_qmlfontloader::localfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::faillocalfont() +void tst_qmlfontloader::failLocalFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -113,7 +115,7 @@ void tst_qmlfontloader::faillocalfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } -void tst_qmlfontloader::webfont() +void tst_qmlfontloader::webFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -124,7 +126,7 @@ void tst_qmlfontloader::webfont() QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::failwebfont() +void tst_qmlfontloader::failWebFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index d53de59..b9c12ee 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -57,6 +57,7 @@ private slots: void width(); void wrap(); void elide(); + void textFormat(); // ### these tests may be trivial void horizontalAlignment(); @@ -145,6 +146,9 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); + QVERIFY(textObject->width() == 0); + + delete textObject; } for (int i = 0; i < standard.size(); i++) @@ -155,6 +159,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), standard.at(i)); + QVERIFY(textObject->width() > 0); } for (int i = 0; i < richText.size(); i++) @@ -166,6 +171,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QString expected = richText.at(i); QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + QVERIFY(textObject->width() > 0); } } @@ -176,6 +182,7 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 0.); } @@ -189,7 +196,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(metricWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); } for (int i = 0; i < richText.size(); i++) @@ -204,7 +213,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(documentWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); } } @@ -217,6 +228,8 @@ void tst_qmlgraphicstext::wrap() QmlGraphicsText *textObject = qobject_cast(textComponent.create()); textHeight = textObject->height(); + QVERIFY(textObject != 0); + QVERIFY(textObject->wrap() == true); QCOMPARE(textObject->width(), 300.); } @@ -226,6 +239,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -236,6 +250,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -246,38 +261,56 @@ void tst_qmlgraphicstext::elide() { for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + QString elide = "elide: Text." + QString(elidename[int(m)]) + ";"; // XXX Poor coverage. { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 100 }").toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } // richtext - does nothing for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } } } +void tst_qmlgraphicstext::textFormat() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.RichText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); + } + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.PlainText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); + } +} + //the alignment tests may be trivial o.oa void tst_qmlgraphicstext::horizontalAlignment() { -- cgit v0.12