diff options
Diffstat (limited to 'tests/auto/qtquick1/qdeclarativebehaviors')
23 files changed, 904 insertions, 0 deletions
diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/binding.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/binding.qml new file mode 100644 index 0000000000..a452447f31 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/binding.qml @@ -0,0 +1,26 @@ +import QtQuick 1.0 +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 + Behavior on x { NumberAnimation { duration: 800; } } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: movedx + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/color.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/color.qml new file mode 100644 index 0000000000..c4b783a0f0 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/color.qml @@ -0,0 +1,24 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; + color: "green" + Behavior on color { ColorAnimation { duration: 500; } } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "red" + when: clicker.pressed + PropertyChanges { + target: rect + color: "red" + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/cpptrigger.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/cpptrigger.qml new file mode 100644 index 0000000000..88ddfaa1a7 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/cpptrigger.qml @@ -0,0 +1,11 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { NumberAnimation { duration: 500; } } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/delayedRegistration.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/delayedRegistration.qml new file mode 100644 index 0000000000..aa384c335f --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/delayedRegistration.qml @@ -0,0 +1,25 @@ +import QtQuick 1.0 + +Rectangle { + id: container + + width: 400; height: 400; + property Item myItem + + function doCreate() { + myItem = myComponent.createObject(container) + myItem.x = 100 + } + + Component { + id: myComponent + Rectangle { + width: 100 + height: 100 + color: "green" + Behavior on x { NumberAnimation { duration: 500 } } + } + } + + Component.onCompleted: doCreate() +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/disabled.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/disabled.qml new file mode 100644 index 0000000000..f6cfa5e33d --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/disabled.qml @@ -0,0 +1,27 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { + objectName: "MyBehavior"; + enabled: false + NumberAnimation { duration: 200; } + } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/dontStart.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/dontStart.qml new file mode 100644 index 0000000000..e318dd2567 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/dontStart.qml @@ -0,0 +1,18 @@ +import QtQuick 1.0 + +Rectangle { + id: wrapper + width: 600 + height: 400 + + Rectangle { + id: redRect + width: 100; height: 100 + color: Qt.rgba(1,0,0) + Behavior on x { + NumberAnimation {id: myAnim; objectName: "MyAnim"; running: true } + } + + } + +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/empty.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/empty.qml new file mode 100644 index 0000000000..6c78a84540 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/empty.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x {} + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/explicit.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/explicit.qml new file mode 100644 index 0000000000..3baa1ac23a --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/explicit.qml @@ -0,0 +1,26 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { + objectName: "MyBehavior"; + NumberAnimation { target: rect; property: "x"; duration: 500; } + } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/groupProperty.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupProperty.qml new file mode 100644 index 0000000000..ddb5bbd40c --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupProperty.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on pos { PropertyAnimation { duration: 500; } } + } + MouseArea { + 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/qtquick1/qdeclarativebehaviors/data/groupProperty2.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupProperty2.qml new file mode 100644 index 0000000000..c0b71cdb04 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupProperty2.qml @@ -0,0 +1,23 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on pos.x { NumberAnimation { duration: 500; } } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + pos.x: 200; + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/groupedPropertyCrash.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupedPropertyCrash.qml new file mode 100644 index 0000000000..8aa590bca1 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/groupedPropertyCrash.qml @@ -0,0 +1,10 @@ +import QtQuick 1.0 + +Rectangle { + width: 200 + height: 200 + Text { + Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 300; } } + text: "Hello World" + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/loop.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/loop.qml new file mode 100644 index 0000000000..76379c00a2 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/loop.qml @@ -0,0 +1,19 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { NumberAnimation { duration: 200; } } + onXChanged: x = 100; + } + states: State { + name: "moved" + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/nonSelecting2.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/nonSelecting2.qml new file mode 100644 index 0000000000..c5c78d1aa2 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/nonSelecting2.qml @@ -0,0 +1,26 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { + objectName: "MyBehavior"; + NumberAnimation { targets: rect; properties: "y"; duration: 200; } + } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/parent.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/parent.qml new file mode 100644 index 0000000000..d19da298b2 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/parent.qml @@ -0,0 +1,28 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on parent { + SequentialAnimation { + PauseAnimation { duration: 500 } + PropertyAction {} + } + } + } + Item { + id: newParent + objectName: "NewParent" + x: 100 + } + states: State { + name: "reparented" + PropertyChanges { + target: rect + parent: newParent + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/qtbug12295.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/qtbug12295.qml new file mode 100644 index 0000000000..03b542164b --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/qtbug12295.qml @@ -0,0 +1,17 @@ +import QtQuick 1.0 + +Rectangle { + width: 200 + height: 200 + color: "blue" + + Rectangle { + id: myRect + objectName: "myRect" + width: 100 + height: 100 + Behavior on x { + NumberAnimation { duration: 500 } + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/reassignedAnimation.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/reassignedAnimation.qml new file mode 100644 index 0000000000..56ac216c5a --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/reassignedAnimation.qml @@ -0,0 +1,32 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { + id: myBehavior + objectName: "MyBehavior" + NumberAnimation {id: na1; duration: 200 } + } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } + + NumberAnimation {id: na2; duration: 1000 } + Component.onCompleted: { + myBehavior.animation = na2; + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/runningTrue.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/runningTrue.qml new file mode 100644 index 0000000000..25cdf10acf --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/runningTrue.qml @@ -0,0 +1,20 @@ +import QtQuick 1.0 + +Rectangle { + id: root + width:200; height:200 + + property real myValue: 0 + + Rectangle { + anchors.centerIn: parent + width: 100 + height: 100 + color: "green" + smooth: true + rotation: myValue + Behavior on rotation { + RotationAnimation { id: rotAnim; objectName: "rotAnim"; direction: RotationAnimation.Shortest } + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/scripttrigger.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/scripttrigger.qml new file mode 100644 index 0000000000..c05cdaa940 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/scripttrigger.qml @@ -0,0 +1,16 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + + onColorChanged: { + rect.x = 200 + } + + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { NumberAnimation { duration: 800; } } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/simple.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/simple.qml new file mode 100644 index 0000000000..6ba0118660 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/simple.qml @@ -0,0 +1,26 @@ +import QtQuick 1.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + Behavior on x { + objectName: "MyBehavior"; + NumberAnimation {id: na; duration: 500; } + } + } + MouseArea { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/startup.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/startup.qml new file mode 100644 index 0000000000..fca416c08c --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/startup.qml @@ -0,0 +1,17 @@ +import QtQuick 1.0 + +Rectangle { + width: 400 + height: 400 + + Rectangle { + objectName: "innerRect" + height: 100; width: 100; color: "green" + property real targetX: 100 + + x: targetX + Behavior on x { + NumberAnimation {} + } + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/data/startup2.qml b/tests/auto/qtquick1/qdeclarativebehaviors/data/startup2.qml new file mode 100644 index 0000000000..eb627613d4 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/data/startup2.qml @@ -0,0 +1,16 @@ +import QtQuick 1.0 + +Rectangle { + width: 800; + height: 480; + + Text { id:theText; text: "hello world" } + + Rectangle { + objectName: "innerRect" + color: "red" + x: theText.width + Behavior on x { NumberAnimation {} } + width: 100; height: 100 + } +} diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/qdeclarativebehaviors.pro b/tests/auto/qtquick1/qdeclarativebehaviors/qdeclarativebehaviors.pro new file mode 100644 index 0000000000..4fd4ddd8b0 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/qdeclarativebehaviors.pro @@ -0,0 +1,16 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative qtquick1 +SOURCES += tst_qdeclarativebehaviors.cpp +macx:CONFIG -= app_bundle + +symbian: { + importFiles.files = data + importFiles.path = . + DEPLOYMENT += importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +CONFIG += parallel_test + +QT += core-private gui-private declarative-private qtquick1-private diff --git a/tests/auto/qtquick1/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/qtquick1/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp new file mode 100644 index 0000000000..773fc24148 --- /dev/null +++ b/tests/auto/qtquick1/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -0,0 +1,435 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include <qsignalspy.h> +#include <QtDeclarative/qdeclarativeengine.h> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtQuick1/qdeclarativeview.h> +#include <QtQuick1/private/qdeclarativerectangle_p.h> +#include <QtQuick1/private/qdeclarativetext_p.h> +#include <QtQuick1/private/qdeclarativebehavior_p.h> +#include <QtQuick1/private/qdeclarativeanimation_p.h> +#include <QtQuick1/private/qdeclarativeitem_p.h> +#include "../../../shared/util.h" + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + +class tst_qdeclarativebehaviors : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativebehaviors() {} + +private slots: + void simpleBehavior(); + void scriptTriggered(); + void cppTriggered(); + void loop(); + void colorBehavior(); + void parentBehavior(); + void replaceBinding(); + //void transitionOverrides(); + void group(); + void emptyBehavior(); + void explicitSelection(); + void nonSelectingBehavior(); + void reassignedAnimation(); + void disabled(); + void dontStart(); + void startup(); + void groupedPropertyCrash(); + void runningTrue(); + void sameValue(); + void delayedRegistration(); +}; + +void tst_qdeclarativebehaviors::simpleBehavior() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/simple.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + QTRY_VERIFY(qobject_cast<QDeclarative1Behavior*>(rect->findChild<QDeclarative1Behavior*>("MyBehavior"))->animation()); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered + + delete rect; +} + +void tst_qdeclarativebehaviors::scriptTriggered() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/scripttrigger.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + rect->setColor(QColor("red")); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered + + delete rect; +} + +void tst_qdeclarativebehaviors::cppTriggered() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/cpptrigger.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarative1Rectangle *innerRect = qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect")); + QTRY_VERIFY(innerRect); + + innerRect->setProperty("x", 200); + QTRY_VERIFY(innerRect->x() > 0); + QTRY_VERIFY(innerRect->x() < 200); //i.e. the behavior has been triggered + + delete rect; +} + +void tst_qdeclarativebehaviors::loop() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/loop.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + //don't crash + QDeclarativeItemPrivate::get(rect)->setState("moved"); + + delete rect; +} + +void tst_qdeclarativebehaviors::colorBehavior() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/color.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("red"); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->color() != QColor("red")); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->color() != QColor("green")); + //i.e. the behavior has been triggered + + delete rect; +} + +void tst_qdeclarativebehaviors::parentBehavior() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/parent.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("reparented"); + QTRY_VERIFY(rect->findChild<QDeclarative1Rectangle*>("MyRect")->parentItem() != rect->findChild<QDeclarativeItem*>("NewParent")); + QTRY_VERIFY(rect->findChild<QDeclarative1Rectangle*>("MyRect")->parentItem() == rect->findChild<QDeclarativeItem*>("NewParent")); + + delete rect; +} + +void tst_qdeclarativebehaviors::replaceBinding() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/binding.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + QDeclarative1Rectangle *innerRect = qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect")); + QTRY_VERIFY(innerRect); + QTRY_VERIFY(innerRect->x() > 0); + QTRY_VERIFY(innerRect->x() < 200); + //i.e. the behavior has been triggered + QTRY_COMPARE(innerRect->x(), (qreal)200); + rect->setProperty("basex", 10); + QTRY_COMPARE(innerRect->x(), (qreal)200); + rect->setProperty("movedx", 210); + QTRY_COMPARE(innerRect->x(), (qreal)210); + + QDeclarativeItemPrivate::get(rect)->setState(""); + QTRY_VERIFY(innerRect->x() > 10); + QTRY_VERIFY(innerRect->x() < 210); //i.e. the behavior has been triggered + QTRY_COMPARE(innerRect->x(), (qreal)10); + rect->setProperty("movedx", 200); + QTRY_COMPARE(innerRect->x(), (qreal)10); + rect->setProperty("basex", 20); + QTRY_COMPARE(innerRect->x(), (qreal)20); + + delete rect; +} + +void tst_qdeclarativebehaviors::group() +{ + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + //QTest::qWait(200); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered + + delete rect; + } + + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty2.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QTRY_VERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered + + delete rect; + } +} + +void tst_qdeclarativebehaviors::emptyBehavior() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/empty.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + qreal x = qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + + delete rect; +} + +void tst_qdeclarativebehaviors::explicitSelection() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/explicit.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered + + delete rect; +} + +void tst_qdeclarativebehaviors::nonSelectingBehavior() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + qreal x = qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + + delete rect; +} + +void tst_qdeclarativebehaviors::reassignedAnimation() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml")); + QString warning = QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior."; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + QCOMPARE(qobject_cast<QDeclarative1NumberAnimation*>( + rect->findChild<QDeclarative1Behavior*>("MyBehavior")->animation())->duration(), 200); + + delete rect; +} + +void tst_qdeclarativebehaviors::disabled() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + QCOMPARE(rect->findChild<QDeclarative1Behavior*>("MyBehavior")->enabled(), false); + + QDeclarativeItemPrivate::get(rect)->setState("moved"); + qreal x = qobject_cast<QDeclarative1Rectangle*>(rect->findChild<QDeclarative1Rectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + + delete rect; +} + +void tst_qdeclarativebehaviors::dontStart() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml")); + + QString warning = c.url().toString() + ":13:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes."; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarative1AbstractAnimation *myAnim = rect->findChild<QDeclarative1AbstractAnimation*>("MyAnim"); + QVERIFY(myAnim && myAnim->qtAnimation()); + QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + + delete rect; +} + +void tst_qdeclarativebehaviors::startup() +{ + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarative1Rectangle *innerRect = rect->findChild<QDeclarative1Rectangle*>("innerRect"); + QVERIFY(innerRect); + + QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately + + delete rect; + } + + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup2.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarative1Rectangle *innerRect = rect->findChild<QDeclarative1Rectangle*>("innerRect"); + QVERIFY(innerRect); + + QDeclarative1Text *text = rect->findChild<QDeclarative1Text*>(); + QVERIFY(text); + + QCOMPARE(innerRect->x(), text->width()); //should be set immediately + + delete rect; + } +} + +//QTBUG-10799 +void tst_qdeclarativebehaviors::groupedPropertyCrash() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupedPropertyCrash.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); //don't crash +} + +//QTBUG-5491 +void tst_qdeclarativebehaviors::runningTrue() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrue.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarative1AbstractAnimation *animation = rect->findChild<QDeclarative1AbstractAnimation*>("rotAnim"); + QVERIFY(animation); + + QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool))); + rect->setProperty("myValue", 180); + QTRY_VERIFY(runningSpy.count() > 0); +} + +//QTBUG-12295 +void tst_qdeclarativebehaviors::sameValue() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/qtbug12295.qml")); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect); + + QDeclarative1Rectangle *target = rect->findChild<QDeclarative1Rectangle*>("myRect"); + QVERIFY(target); + + target->setX(100); + QCOMPARE(target->x(), qreal(100)); + + target->setProperty("x", 0); + QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); + QTRY_VERIFY(target->x() == qreal(0)); //make sure Behavior has finished. + + target->setX(100); + QCOMPARE(target->x(), qreal(100)); + + //this is the main point of the test -- the behavior needs to be triggered again + //even though we set 0 twice in a row. + target->setProperty("x", 0); + QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); +} + +//QTBUG-18362 +void tst_qdeclarativebehaviors::delayedRegistration() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, SRCDIR "/data/delayedRegistration.qml"); + QDeclarative1Rectangle *rect = qobject_cast<QDeclarative1Rectangle*>(c.create()); + QVERIFY(rect != 0); + + QDeclarativeItem *innerRect = rect->property("myItem").value<QDeclarativeItem*>(); + QVERIFY(innerRect != 0); + + QCOMPARE(innerRect->property("x").toInt(), int(0)); + + QTRY_COMPARE(innerRect->property("x").toInt(), int(100)); +} + +QTEST_MAIN(tst_qdeclarativebehaviors) + +#include "tst_qdeclarativebehaviors.moc" |