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 From 10207df5018a9495849abd7bbd2fa615aab20260 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 4 Nov 2009 09:18:13 +1000 Subject: Don't rely on imprecise boundingRect for space around text for outlines. Fixes tst_visual(flickable) --- src/declarative/graphicsitems/qmlgraphicstext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 6790923..d640fc9 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -534,7 +534,7 @@ void QmlGraphicsTextPrivate::updateSize() void QmlGraphicsTextPrivate::drawOutline() { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); @@ -558,7 +558,7 @@ void QmlGraphicsTextPrivate::drawOutline() void QmlGraphicsTextPrivate::drawOutline(int yOffset) { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); -- cgit v0.12 From 1c558dafd37f2e750ce9a672ba245f36dda8b42c Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 09:18:40 +1000 Subject: autotests. --- tests/auto/declarative/behaviors/tst_behaviors.cpp | 8 +++----- .../declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 29c631d..da910d9 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -225,11 +225,9 @@ void tst_behaviors::reassignedAnimation() QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - - rect->setState("moved"); - QTest::qWait(200 + 100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered + QCOMPARE(qobject_cast( + qobject_cast( + rect->findChild("MyBehavior"))->animation())->duration(), 200); } QTEST_MAIN(tst_behaviors) diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index a7211bd..9be77e8 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -55,6 +55,7 @@ public: private slots: void insert(); void operatorInsert(); + void operatorValue(); void clear(); void changed(); void count(); @@ -66,6 +67,7 @@ void tst_QmlPropertyMap::insert() map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); @@ -88,6 +90,20 @@ void tst_QmlPropertyMap::operatorInsert() QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } +void tst_QmlPropertyMap::operatorValue() +{ + QmlPropertyMap map; + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + QCOMPARE(map[QLatin1String("key1")], map.value(QLatin1String("key1"))); + QCOMPARE(map[QLatin1String("key2")], map.value(QLatin1String("key2"))); +} + void tst_QmlPropertyMap::clear() { QmlPropertyMap map; @@ -98,6 +114,7 @@ void tst_QmlPropertyMap::clear() map.clear(QLatin1String("key1")); QVERIFY(map.keys().count() == 1); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -143,6 +160,7 @@ void tst_QmlPropertyMap::count() //clearing doesn't remove the key map.clear(QLatin1String("key3")); QCOMPARE(map.count(), 3); + QCOMPARE(map.size(), map.count()); } QTEST_MAIN(tst_QmlPropertyMap) -- cgit v0.12 From a200f90d19a8d233e92311d881644424dcde31de Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 09:42:17 +1000 Subject: update .pro file --- tests/auto/declarative/declarative.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 73269e1..86cf175 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlfontloader \ qmllanguage \ qmllist \ qmllistaccessor \ -- cgit v0.12 From 162f9d19231612f2b5ae55156ecfd449d3f2f8d7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 4 Nov 2009 10:33:45 +1000 Subject: Fix moving items in visual item model. --- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 32 ++++-- .../graphicsitems/qmlgraphicsvisualitemmodel_p.h | 1 + tests/auto/declarative/listview/data/listview.qml | 4 +- tests/auto/declarative/listview/tst_listview.cpp | 120 +++++++++++++++++++++ 4 files changed, 149 insertions(+), 8 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 686c0da..80b2458 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -617,6 +617,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -654,6 +656,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); return; } if ((d->m_visualItemModel = qvariant_cast(model))) { @@ -978,9 +982,10 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { + int diff = from > to ? count : -count; if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + from - to; + int index = iter.key() + diff; iter = d->m_cache.erase(iter); items.insert(index, objRef); @@ -996,20 +1001,35 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) emit itemsMoved(from, to, count); } -void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &parent, int begin, int end) { - _q_itemsInserted(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsInserted(begin, end - begin + 1); } -void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &parent, int begin, int end) { - _q_itemsRemoved(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsRemoved(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) +{ + const int count = sourceEnd - sourceStart + 1; + if (!destinationParent.isValid() && !sourceParent.isValid()) { + _q_itemsMoved(sourceStart, destinationRow, count); + } else if (!sourceParent.isValid()) { + _q_itemsRemoved(sourceStart, count); + } else if (!destinationParent.isValid()) { + _q_itemsInserted(destinationRow, count); + } } void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) { Q_D(QmlGraphicsVisualDataModel); - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); + if (!begin.parent().isValid()) + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index 8b0a8f5..3ff2a74 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -183,6 +183,7 @@ private Q_SLOTS: void _q_itemsMoved(int from, int to, int count); void _q_rowsInserted(const QModelIndex &,int,int); void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); void _q_createdPackage(int index, QmlPackage *package); void _q_destroyingPackage(QmlPackage *package); diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml index 9039b55..b7b838b 100644 --- a/tests/auto/declarative/listview/data/listview.qml +++ b/tests/auto/declarative/listview/data/listview.qml @@ -6,7 +6,7 @@ Rectangle { color: "#ffffff" resources: [ Component { - id: Delegate + id: myDelegate Rectangle { id: wrapper objectName: "wrapper" @@ -41,6 +41,6 @@ Rectangle { width: 240 height: 320 model: testModel - delegate: Delegate + delegate: myDelegate } } diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 42d4900..441138b 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -66,11 +66,15 @@ private slots: void qListModelInterface_removed(); void qAbstractItemModel_removed(); + void qListModelInterface_moved(); + void qAbstractItemModel_moved(); + private: template void items(); template void changed(); template void inserted(); template void removed(); + template void moved(); QmlView *createView(const QString &filename); template T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); @@ -140,6 +144,11 @@ public: emit itemsRemoved(index, 1); } + void moveItem(int from, int to) { + list.move(from, to); + emit itemsMoved(from, to, 1); + } + void modifyItem(int index, const QString &name, const QString &number) { list[index] = QPair(name, number); emit itemsChanged(index, 1, roles()); @@ -195,6 +204,12 @@ public: emit endRemoveRows(); } + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + void modifyItem(int idx, const QString &name, const QString &number) { list[idx] = QPair(name, number); emit dataChanged(index(idx,0), index(idx,0)); @@ -454,6 +469,100 @@ void tst_QmlGraphicsListView::removed() delete canvas; } +template +void tst_QmlGraphicsListView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 4); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem(viewport, "textName", 4); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(4)); + number = findItem(viewport, "textNumber", 4); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(4)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setViewportY(80); + + // move outside visible area + model.moveItem(1, 18); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(20, 4); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items(); @@ -494,6 +603,17 @@ void tst_QmlGraphicsListView::qAbstractItemModel_removed() removed(); } +void tst_QmlGraphicsListView::qListModelInterface_moved() +{ + moved(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_moved() +{ + moved(); +} + + QmlView *tst_QmlGraphicsListView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); -- cgit v0.12 From 5971999e08e0a6f41e200c20d3ceb5720732ce6b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 11:35:29 +1000 Subject: QmlGraphicsBorderImage autotests --- tests/auto/declarative/declarative.pro | 1 + .../qmlgraphicsborderimage/data/colors-round.sci | 7 + .../qmlgraphicsborderimage/data/colors.png | Bin 0 -> 1655 bytes .../qmlgraphicsborderimage.pro | 8 + .../tst_qmlgraphicsborderimage.cpp | 162 +++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors.png create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 86cf175..321e91b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlgraphicsborderimage \ qmlfontloader \ qmllanguage \ qmllist \ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci new file mode 100644 index 0000000..5d2f49f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:colors.png diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png new file mode 100644 index 0000000..dfb62f3 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png differ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro new file mode 100644 index 0000000..82da769 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsborderimage.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp new file mode 100644 index 0000000..809d9fd --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** 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 + +class tst_qmlgraphicsborderimage : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicsborderimage(); + +private slots: + void simple(); + void resized(); + void smooth(); + void tileModes(); + void sciFile(); + +private: + QmlEngine engine; +}; + +tst_qmlgraphicsborderimage::tst_qmlgraphicsborderimage() +{ +} + +void tst_qmlgraphicsborderimage::simple() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 120); + QVERIFY(obj->height() == 120); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::resized() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::smooth() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->smoothTransform() == true); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::tileModes() +{ + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 100; height: 300; horizontalTileMode: BorderImage.Repeat; verticalTileMode: BorderImage.Repeat }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 100); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Repeat); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; + } + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 150; horizontalTileMode: BorderImage.Round; verticalTileMode: BorderImage.Round }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 150); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Round); + + delete obj; + } +} + +void tst_qmlgraphicsborderimage::sciFile() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors-round.sci\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->border()->left() == 10); + QVERIFY(obj->border()->top() == 20); + QVERIFY(obj->border()->right() == 30); + QVERIFY(obj->border()->bottom() == 40); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; +} + +QTEST_MAIN(tst_qmlgraphicsborderimage) + +#include "tst_qmlgraphicsborderimage.moc" -- cgit v0.12 From 8b94bb526e11acca4a479e6e31375128c2b6163c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 10:58:07 +1000 Subject: Basic autotest for QmlGraphicsParticles --- .../qmlgraphicsparticles/data/particle.png | Bin 0 -> 262 bytes .../qmlgraphicsparticles/data/particles.qml | 15 +++ .../qmlgraphicsparticles/qmlgraphicsparticles.pro | 8 ++ .../tst_qmlgraphicsparticles.cpp | 122 +++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particle.png create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particles.qml create mode 100644 tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro create mode 100644 tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particle.png b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png new file mode 100644 index 0000000..defbde5 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png differ diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml new file mode 100644 index 0000000..dccd2c7 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle{ + width: 100 + height: 100 + color: "black" + objectName: "rect" + Particles { id: particles + objectName: "particles" + width:1; height:1; anchors.centerIn: parent; opacity: 1 + lifeSpan: 100; lifeSpanDeviation: 20; count:1000; + fadeInDuration: 20; fadeOutDuration: 20; + angle: 0; angleDeviation: 360; velocity: 500; velocityDeviation:30 + source: "particle.png" + } +} diff --git a/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro new file mode 100644 index 0000000..94eeb4e --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsparticles.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp new file mode 100644 index 0000000..e50437a --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 + +class tst_QmlGraphicsParticles : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsParticles(); + +private slots: + void properties(); + void runs(); +private: + QmlView *createView(const QString &filename); + +}; + +tst_QmlGraphicsParticles::tst_QmlGraphicsParticles() +{ +} + +void tst_QmlGraphicsParticles::properties() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + + particles->setSource(QUrl("file://" SRCDIR "/data/particle.png")); + QCOMPARE(particles->source(), QUrl("file://" SRCDIR "/data/particle.png")); + + particles->setLifeSpanDeviation(1000); + QCOMPARE(particles->lifeSpanDeviation(), 1000); + + particles->setFadeInDuration(1000); + QCOMPARE(particles->fadeInDuration(), 1000); + + particles->setFadeOutDuration(1000); + QCOMPARE(particles->fadeOutDuration(), 1000); + + particles->setAngle(100.0); + QCOMPARE(particles->angle(), 100.0); + + particles->setAngleDeviation(100.0); + QCOMPARE(particles->angleDeviation(), 100.0); + + particles->setVelocity(100.0); + QCOMPARE(particles->velocity(), 100.0); + + particles->setVelocityDeviation(100.0); + QCOMPARE(particles->velocityDeviation(), 100.0); + + particles->setEmitting(false); + QCOMPARE(particles->emitting(), false); +} + +void tst_QmlGraphicsParticles::runs() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash. +} + +QmlView *tst_QmlGraphicsParticles::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + canvas->execute(); + + return canvas; +} +QTEST_MAIN(tst_QmlGraphicsParticles) + +#include "tst_qmlgraphicsparticles.moc" -- cgit v0.12