diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-09 17:51:47 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-09 17:51:47 (GMT) |
commit | 969b61f508294d1f683e09e78641127d0f0def05 (patch) | |
tree | 35ec77453b23327556643d6674d99b26c19e6ad6 /tests/auto/declarative/behaviors | |
parent | 6165ab0203fa80d31f3488ead7e7f7c088c8668c (diff) | |
parent | 3071bbd9eb9833d19c6dd43b52079b6a8e1722b2 (diff) | |
download | Qt-969b61f508294d1f683e09e78641127d0f0def05.zip Qt-969b61f508294d1f683e09e78641127d0f0def05.tar.gz Qt-969b61f508294d1f683e09e78641127d0f0def05.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-qml: (3355 commits)
Get test compiling
Remove unimplemented methods from header
Properly insert objects into the context's object list
Missed a file
Compile
Replace QList<>* support with QmlListProperty
Remove old implicit module support.
Use networkAccessManagerFactory() for worker threads too.
Connect to localhost instead of QHostAddress::Any. Fixes test on Windows.
Support the other validators
Add empty constructor for validators.
Add getter functions to QAbstractDynamicMetaObject and QmlOpenMetaObjectType
Document QtObject
Changed define name to reflect change in Creator.
re-enable QT_USE_FAST_CONCATENATION
XMLHttpRequest collection bug
For local fonts, we can just addApplicationFont() rather than loading data.
The virtual keyboard is now working for TextEdit and TextInput components.
Fix viewport size update.
Make transformOrigin Center by default
...
Diffstat (limited to 'tests/auto/declarative/behaviors')
16 files changed, 612 insertions, 0 deletions
diff --git a/tests/auto/declarative/behaviors/behaviors.pro b/tests/auto/declarative/behaviors/behaviors.pro new file mode 100644 index 0000000..8886b0c --- /dev/null +++ b/tests/auto/declarative/behaviors/behaviors.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_behaviors.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/behaviors/data/binding.qml b/tests/auto/declarative/behaviors/data/binding.qml new file mode 100644 index 0000000..e0c3321 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/binding.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + property real basex : 0 + property real movedx: 200 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: basex + x: Behavior { NumberAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: movedx + } + } +} diff --git a/tests/auto/declarative/behaviors/data/color.qml b/tests/auto/declarative/behaviors/data/color.qml new file mode 100644 index 0000000..6598703 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/color.qml @@ -0,0 +1,24 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; + color: "green" + color: Behavior { ColorAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "red" + when: clicker.pressed + PropertyChanges { + target: rect + color: "red" + } + } +} diff --git a/tests/auto/declarative/behaviors/data/cpptrigger.qml b/tests/auto/declarative/behaviors/data/cpptrigger.qml new file mode 100644 index 0000000..ba507c4 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/cpptrigger.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + } +} diff --git a/tests/auto/declarative/behaviors/data/disabled.qml b/tests/auto/declarative/behaviors/data/disabled.qml new file mode 100644 index 0000000..e7b8d51 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/disabled.qml @@ -0,0 +1,27 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + enabled: false + NumberAnimation { duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/empty.qml b/tests/auto/declarative/behaviors/data/empty.qml new file mode 100644 index 0000000..412e26c --- /dev/null +++ b/tests/auto/declarative/behaviors/data/empty.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior {} + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/groupProperty.qml b/tests/auto/declarative/behaviors/data/groupProperty.qml new file mode 100644 index 0000000..4f127c1 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/groupProperty.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + pos: Behavior { PropertyAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + pos: Qt.point(200,0); + } + } +} diff --git a/tests/auto/declarative/behaviors/data/groupProperty2.qml b/tests/auto/declarative/behaviors/data/groupProperty2.qml new file mode 100644 index 0000000..19d70b6 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/groupProperty2.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + pos.x: Behavior { NumberAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + pos.x: 200; + } + } +} diff --git a/tests/auto/declarative/behaviors/data/loop.qml b/tests/auto/declarative/behaviors/data/loop.qml new file mode 100644 index 0000000..5f2c057 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/loop.qml @@ -0,0 +1,19 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + onXChanged: x = 100; + } + states: State { + name: "moved" + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/nonSelecting.qml b/tests/auto/declarative/behaviors/data/nonSelecting.qml new file mode 100644 index 0000000..ba36d93 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/nonSelecting.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { target: rect; property: "x"; duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/nonSelecting2.qml b/tests/auto/declarative/behaviors/data/nonSelecting2.qml new file mode 100644 index 0000000..e9849eb --- /dev/null +++ b/tests/auto/declarative/behaviors/data/nonSelecting2.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { matchTargets: rect; matchProperties: "y"; duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/parent.qml b/tests/auto/declarative/behaviors/data/parent.qml new file mode 100644 index 0000000..4f4911b --- /dev/null +++ b/tests/auto/declarative/behaviors/data/parent.qml @@ -0,0 +1,28 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + parent: Behavior { + SequentialAnimation { + PauseAnimation { duration: 200 } + PropertyAction {} + } + } + } + Item { + id: newParent + objectName: "NewParent" + x: 100 + } + states: State { + name: "reparented" + PropertyChanges { + target: rect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/behaviors/data/reassignedAnimation.qml b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml new file mode 100644 index 0000000..693a595 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml @@ -0,0 +1,27 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior" + NumberAnimation { duration: 200 } + NumberAnimation { duration: 1000 } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/scripttrigger.qml b/tests/auto/declarative/behaviors/data/scripttrigger.qml new file mode 100644 index 0000000..4383a0b --- /dev/null +++ b/tests/auto/declarative/behaviors/data/scripttrigger.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + + onColorChanged: { + rect.x = 200 + } + + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + } +} diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml new file mode 100644 index 0000000..37c3915 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp new file mode 100644 index 0000000..fd84596 --- /dev/null +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -0,0 +1,281 @@ +/**************************************************************************** +** +** 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 <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmlview.h> +#include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlbehavior_p.h> +#include <private/qmlanimation_p.h> + +class tst_behaviors : public QObject +{ + Q_OBJECT +public: + tst_behaviors() {} + +private slots: + void simpleBehavior(); + void scriptTriggered(); + void cppTriggered(); + void loop(); + void colorBehavior(); + void parentBehavior(); + void replaceBinding(); + //void transitionOverrides(); + void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); + void disabled(); +}; + +void tst_behaviors::simpleBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/simple.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + QVERIFY(qobject_cast<QmlBehavior*>(rect->findChild<QmlBehavior*>("MyBehavior"))->animation()); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::scriptTriggered() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/scripttrigger.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setColor(QColor("red")); + QTest::qWait(100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::cppTriggered() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/cpptrigger.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect); + + innerRect->setProperty("x", 200); + QTest::qWait(100); + qreal x = innerRect->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::loop() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/loop.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + //don't crash + rect->setState("moved"); +} + +void tst_behaviors::colorBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/color.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("red"); + QTest::qWait(100); + QColor color = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->color(); + QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered +} + +void tst_behaviors::parentBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/parent.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("reparented"); + QTest::qWait(100); + QmlGraphicsItem *newParent = rect->findChild<QmlGraphicsItem*>("NewParent"); + QmlGraphicsItem *parent = rect->findChild<QmlGraphicsRectangle*>("MyRect")->parentItem(); + QVERIFY(parent != newParent); + QTest::qWait(300); + parent = rect->findChild<QmlGraphicsRectangle*>("MyRect")->parentItem(); + QVERIFY(parent == newParent); +} + +void tst_behaviors::replaceBinding() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/binding.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect); + qreal x = innerRect->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)200); + rect->setProperty("basex", 10); + QCOMPARE(innerRect->x(), (qreal)200); + rect->setProperty("movedx", 210); + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)210); + + rect->setState(""); + QTest::qWait(100); + x = innerRect->x(); + QVERIFY(x > 10 && x < 210); //i.e. the behavior has been triggered + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)10); + rect->setProperty("movedx", 200); + QCOMPARE(innerRect->x(), (qreal)10); + rect->setProperty("basex", 20); + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)20); +} + +void tst_behaviors::group() +{ + { + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty2.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + } +} + +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + { + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + } +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, QString("QML Behavior (" + QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:12) Can't change the animation assigned to a Behavior.").toUtf8().constData()); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + QCOMPARE(qobject_cast<QmlNumberAnimation*>( + qobject_cast<QmlBehavior*>( + rect->findChild<QmlBehavior*>("MyBehavior"))->animation())->duration(), 200); +} + +void tst_behaviors::disabled() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + QCOMPARE(rect->findChild<QmlBehavior*>("MyBehavior")->enabled(), false); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + +} + +QTEST_MAIN(tst_behaviors) + +#include "tst_behaviors.moc" |