aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquick2/qdeclarativebehaviors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtquick2/qdeclarativebehaviors')
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/binding.qml26
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/color.qml24
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/cpptrigger.qml11
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/delayedRegistration.qml25
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/disabled.qml27
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/dontStart.qml18
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/empty.qml23
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/explicit.qml26
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty.qml23
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty2.qml23
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/groupedPropertyCrash.qml10
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/loop.qml19
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/nonSelecting2.qml26
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/parent.qml28
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/qtbug12295.qml17
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/reassignedAnimation.qml32
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/runningTrue.qml20
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/scripttrigger.qml16
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/simple.qml26
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/startOnCompleted.qml15
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/startup.qml17
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/startup2.qml16
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/data/valueType.qml13
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/qdeclarativebehaviors.pro12
-rw-r--r--tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp474
25 files changed, 967 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/data/binding.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/binding.qml
new file mode 100644
index 0000000000..5aceefa743
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/binding.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/color.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/color.qml
new file mode 100644
index 0000000000..a318578a9b
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/color.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/cpptrigger.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/cpptrigger.qml
new file mode 100644
index 0000000000..f033ec5aeb
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/cpptrigger.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/delayedRegistration.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/delayedRegistration.qml
new file mode 100644
index 0000000000..ed35a308f7
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/delayedRegistration.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/disabled.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/disabled.qml
new file mode 100644
index 0000000000..20860d8dde
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/disabled.qml
@@ -0,0 +1,27 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/dontStart.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/dontStart.qml
new file mode 100644
index 0000000000..38e1ea9d9e
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/dontStart.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/empty.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/empty.qml
new file mode 100644
index 0000000000..d8f115390a
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/empty.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/explicit.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/explicit.qml
new file mode 100644
index 0000000000..20875c30e3
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/explicit.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/groupProperty.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty.qml
new file mode 100644
index 0000000000..a05ab7d54b
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/groupProperty2.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty2.qml
new file mode 100644
index 0000000000..2f3de5131c
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupProperty2.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ Behavior on border.width { NumberAnimation { duration: 500; } }
+ }
+ MouseArea {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "moved"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ border.width: 4;
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/data/groupedPropertyCrash.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupedPropertyCrash.qml
new file mode 100644
index 0000000000..6835902bc5
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/groupedPropertyCrash.qml
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 200
+ height: 200
+ Text {
+ Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 300; } }
+ text: "Hello World"
+ }
+}
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/data/loop.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/loop.qml
new file mode 100644
index 0000000000..3e8d88734d
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/loop.qml
@@ -0,0 +1,19 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/nonSelecting2.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/nonSelecting2.qml
new file mode 100644
index 0000000000..6357094cfe
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/nonSelecting2.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/parent.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/parent.qml
new file mode 100644
index 0000000000..f8c2731d86
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/parent.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/qtbug12295.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/qtbug12295.qml
new file mode 100644
index 0000000000..c6bef581a4
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/qtbug12295.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/reassignedAnimation.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/reassignedAnimation.qml
new file mode 100644
index 0000000000..5731cb3efd
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/reassignedAnimation.qml
@@ -0,0 +1,32 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/runningTrue.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/runningTrue.qml
new file mode 100644
index 0000000000..4fd1136f3a
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/runningTrue.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/scripttrigger.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/scripttrigger.qml
new file mode 100644
index 0000000000..ff71f2b1b0
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/scripttrigger.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/simple.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/simple.qml
new file mode 100644
index 0000000000..c64a6e1928
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/simple.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/startOnCompleted.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/startOnCompleted.qml
new file mode 100644
index 0000000000..fdc3779a5c
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/startOnCompleted.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: innerRect
+ width: 100; height: 100
+ color: "green"
+ Behavior on x { NumberAnimation {} }
+ }
+
+ Component.onCompleted: innerRect.x = 100
+}
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/data/startup.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/startup.qml
new file mode 100644
index 0000000000..9fa74ca39e
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/startup.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/startup2.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/startup2.qml
new file mode 100644
index 0000000000..0654ef3644
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/startup2.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.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/qtquick2/qdeclarativebehaviors/data/valueType.qml b/tests/auto/qtquick2/qdeclarativebehaviors/data/valueType.qml
new file mode 100644
index 0000000000..7bc8297dc7
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/data/valueType.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+Rectangle {
+ width: 400
+ height: 400
+
+ color.r: 1
+ color.g: 0
+ color.b: 1
+
+ Behavior on color.r { NumberAnimation { duration: 500; } }
+
+ function changeR() { color.r = 0 }
+}
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/qdeclarativebehaviors.pro b/tests/auto/qtquick2/qdeclarativebehaviors/qdeclarativebehaviors.pro
new file mode 100644
index 0000000000..3ac9446a4c
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/qdeclarativebehaviors.pro
@@ -0,0 +1,12 @@
+CONFIG += testcase
+TARGET = tst_qdeclarativebehaviors
+SOURCES += tst_qdeclarativebehaviors.cpp
+macx:CONFIG -= app_bundle
+
+testDataFiles.files = data
+testDataFiles.path = .
+DEPLOYMENT += testDataFiles
+
+CONFIG += parallel_test
+
+QT += core-private gui-private v8-private declarative-private quick-private opengl-private testlib
diff --git a/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp
new file mode 100644
index 0000000000..526a23f262
--- /dev/null
+++ b/tests/auto/qtquick2/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp
@@ -0,0 +1,474 @@
+/****************************************************************************
+**
+** 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 <QtTest/QtTest>
+#include <qsignalspy.h>
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/private/qquickrectangle_p.h>
+#include <QtQuick/private/qquicktext_p.h>
+#include <QtQuick/private/qdeclarativebehavior_p.h>
+#include <QtQuick/private/qdeclarativeanimation_p.h>
+#include <private/qquickitem_p.h>
+#include "../../shared/util.h"
+
+class tst_qdeclarativebehaviors : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qdeclarativebehaviors() {}
+
+private slots:
+ void init() { qApp->processEvents(); } //work around animation timer bug (QTBUG-22865)
+ void simpleBehavior();
+ void scriptTriggered();
+ void cppTriggered();
+ void loop();
+ void colorBehavior();
+ void parentBehavior();
+ void replaceBinding();
+ //void transitionOverrides();
+ void group();
+ void valueType();
+ void emptyBehavior();
+ void explicitSelection();
+ void nonSelectingBehavior();
+ void reassignedAnimation();
+ void disabled();
+ void dontStart();
+ void startup();
+ void groupedPropertyCrash();
+ void runningTrue();
+ void sameValue();
+ void delayedRegistration();
+ void startOnCompleted();
+};
+
+void tst_qdeclarativebehaviors::simpleBehavior()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("simple.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+ QTRY_VERIFY(qobject_cast<QDeclarativeBehavior*>(rect->findChild<QDeclarativeBehavior*>("MyBehavior"))->animation());
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200);
+ //i.e. the behavior has been triggered
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::scriptTriggered()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("scripttrigger.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ rect->setColor(QColor("red"));
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200);
+ //i.e. the behavior has been triggered
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::cppTriggered()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("cpptrigger.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("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(TESTDATA("loop.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ //don't crash
+ QQuickItemPrivate::get(rect)->setState("moved");
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::colorBehavior()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("color.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("red");
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("red"));
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("green"));
+ //i.e. the behavior has been triggered
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::parentBehavior()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("parent.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("reparented");
+ QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() != rect->findChild<QQuickItem*>("NewParent"));
+ QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() == rect->findChild<QQuickItem*>("NewParent"));
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::replaceBinding()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("binding.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("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);
+
+ QQuickItemPrivate::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()
+{
+ /* XXX TODO Create a test element for this case.
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("groupProperty.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ qDebug() << c.errorString();
+ QTRY_VERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ //QTest::qWait(200);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200);
+ //i.e. the behavior has been triggered
+
+ delete rect;
+ }
+ */
+
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("groupProperty2.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QTRY_VERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() > 0);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() < 4);
+ //i.e. the behavior has been triggered
+
+ delete rect;
+ }
+}
+
+void tst_qdeclarativebehaviors::valueType()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("valueType.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ //QTBUG-20827
+ QCOMPARE(rect->color(), QColor::fromRgb(255,0,255));
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::emptyBehavior()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("empty.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //should change immediately
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::explicitSelection()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("explicit.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0);
+ QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200);
+ //i.e. the behavior has been triggered
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::nonSelectingBehavior()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("nonSelecting2.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //should change immediately
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::reassignedAnimation()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("reassignedAnimation.qml")));
+ QString warning = QUrl::fromLocalFile(TESTDATA("reassignedAnimation.qml")).toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior.";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+ QCOMPARE(qobject_cast<QDeclarativeNumberAnimation*>(
+ rect->findChild<QDeclarativeBehavior*>("MyBehavior")->animation())->duration(), 200);
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::disabled()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("disabled.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+ QCOMPARE(rect->findChild<QDeclarativeBehavior*>("MyBehavior")->enabled(), false);
+
+ QQuickItemPrivate::get(rect)->setState("moved");
+ qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x();
+ QCOMPARE(x, qreal(200)); //should change immediately
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::dontStart()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("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));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim");
+ QVERIFY(myAnim && myAnim->qtAnimation());
+ QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
+
+ delete rect;
+}
+
+void tst_qdeclarativebehaviors::startup()
+{
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("startup.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect");
+ QVERIFY(innerRect);
+
+ QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately
+
+ delete rect;
+ }
+
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("startup2.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect");
+ QVERIFY(innerRect);
+
+ QQuickText *text = rect->findChild<QQuickText*>();
+ 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(TESTDATA("groupedPropertyCrash.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect); //don't crash
+
+ delete rect;
+}
+
+//QTBUG-5491
+void tst_qdeclarativebehaviors::runningTrue()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("runningTrue.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QDeclarativeAbstractAnimation *animation = rect->findChild<QDeclarativeAbstractAnimation*>("rotAnim");
+ QVERIFY(animation);
+
+ QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool)));
+ rect->setProperty("myValue", 180);
+ QTRY_VERIFY(runningSpy.count() > 0);
+
+ delete rect;
+}
+
+//QTBUG-12295
+void tst_qdeclarativebehaviors::sameValue()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("qtbug12295.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QQuickRectangle *target = rect->findChild<QQuickRectangle*>("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));
+
+ delete rect;
+}
+
+//QTBUG-18362
+void tst_qdeclarativebehaviors::delayedRegistration()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("delayedRegistration.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect != 0);
+
+ QQuickItem *innerRect = rect->property("myItem").value<QQuickItem*>();
+ QVERIFY(innerRect != 0);
+
+ QCOMPARE(innerRect->property("x").toInt(), int(0));
+
+ QTRY_COMPARE(innerRect->property("x").toInt(), int(100));
+}
+
+//QTBUG-22555
+void tst_qdeclarativebehaviors::startOnCompleted()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("startOnCompleted.qml")));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect != 0);
+
+ QQuickItem *innerRect = rect->findChild<QQuickRectangle*>();
+ QVERIFY(innerRect != 0);
+
+ QCOMPARE(innerRect->property("x").toInt(), int(0));
+
+ QTRY_COMPARE(innerRect->property("x").toInt(), int(100));
+
+ delete rect;
+}
+
+QTEST_MAIN(tst_qdeclarativebehaviors)
+
+#include "tst_qdeclarativebehaviors.moc"