diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-02-11 21:35:45 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-02-11 22:49:39 (GMT) |
commit | fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd (patch) | |
tree | 28c25d69001ef4dd4181ddf465b373491a61932b /tests/auto/declarative/qmlstates | |
parent | 6e0c76a209b87e306e48266962f5668237e63c62 (diff) | |
download | Qt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.zip Qt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.tar.gz Qt-fe9e91d5b9a5504fdc00f53abd5972621e7fa7dd.tar.bz2 |
Adds qml prefix to all declarative autotests
Diffstat (limited to 'tests/auto/declarative/qmlstates')
35 files changed, 1515 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlstates/data/ExtendedRectangle.qml b/tests/auto/declarative/qmlstates/data/ExtendedRectangle.qml new file mode 100644 index 0000000..8d64663 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/ExtendedRectangle.qml @@ -0,0 +1,19 @@ +import Qt 4.6 +Rectangle { + id: extendedRect + objectName: "extendedRect" + property color extendedColor: "orange" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: { + extendedRect.color = "green" + extendedColor = "green" + } + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/anchorChanges.qml b/tests/auto/declarative/qmlstates/data/anchorChanges.qml new file mode 100644 index 0000000..7dce889 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/anchorChanges.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Rectangle { + id: container + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + id: ancCh + target: myRect; + reset: "left" + right: container.right + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/anchorChanges2.qml b/tests/auto/declarative/qmlstates/data/anchorChanges2.qml new file mode 100644 index 0000000..545345e --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/anchorChanges2.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + target: myRect; + reset: "left" + right: parent.right + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/anchorChanges3.qml b/tests/auto/declarative/qmlstates/data/anchorChanges3.qml new file mode 100644 index 0000000..9d5b317 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/anchorChanges3.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + id: container + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + color: "green"; + anchors.left: parent.left + anchors.right: rightGuideline.left + anchors.top: topGuideline.top + anchors.bottom: container.bottom + } + Item { objectName: "LeftGuideline"; id: leftGuideline; x: 10 } + Item { id: rightGuideline; x: 150 } + Item { id: topGuideline; y: 10 } + Item { objectName: "BottomGuideline"; id: bottomGuideline; y: 150 } + states: State { + name: "reanchored" + AnchorChanges { + target: myRect; + left: leftGuideline.left + right: container.right + top: container.top + bottom: bottomGuideline.bottom + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/anchorChanges4.qml b/tests/auto/declarative/qmlstates/data/anchorChanges4.qml new file mode 100644 index 0000000..f128989 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/anchorChanges4.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + color: "green"; + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + } + Item { objectName: "LeftGuideline"; id: leftGuideline; x: 10 } + Item { objectName: "BottomGuideline"; id: bottomGuideline; y: 150 } + states: State { + name: "reanchored" + AnchorChanges { + target: myRect; + horizontalCenter: bottomGuideline.horizontalCenter + verticalCenter: leftGuideline.verticalCenter + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/anchorChanges5.qml b/tests/auto/declarative/qmlstates/data/anchorChanges5.qml new file mode 100644 index 0000000..4e6d34b --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/anchorChanges5.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + color: "green"; + anchors.horizontalCenter: parent.horizontalCenter + anchors.baseline: parent.baseline + } + Item { objectName: "LeftGuideline"; id: leftGuideline; x: 10 } + Item { objectName: "BottomGuideline"; id: bottomGuideline; y: 150 } + states: State { + name: "reanchored" + AnchorChanges { + target: myRect; + horizontalCenter: bottomGuideline.horizontalCenter + baseline: leftGuideline.baseline + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/autoStateAtStartupRestoreBug.qml b/tests/auto/declarative/qmlstates/data/autoStateAtStartupRestoreBug.qml new file mode 100644 index 0000000..693a5c5 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/autoStateAtStartupRestoreBug.qml @@ -0,0 +1,18 @@ +import Qt 4.6 + +Item { + id: root + property int input: 1 + property int test: 9 + + states: [ + State { + name: "portrait" + when: root.input == 1 + PropertyChanges { + target: root + test: 3 + } + } + ] +} diff --git a/tests/auto/declarative/qmlstates/data/basicBinding.qml b/tests/auto/declarative/qmlstates/data/basicBinding.qml new file mode 100644 index 0000000..6528113 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicBinding.qml @@ -0,0 +1,12 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + + property color sourceColor: "blue" + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: sourceColor } + } +} diff --git a/tests/auto/declarative/qmlstates/data/basicBinding2.qml b/tests/auto/declarative/qmlstates/data/basicBinding2.qml new file mode 100644 index 0000000..2e7b4cf --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicBinding2.qml @@ -0,0 +1,12 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + + property color sourceColor: "red" + width: 100; height: 100 + color: sourceColor + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + } +} diff --git a/tests/auto/declarative/qmlstates/data/basicBinding3.qml b/tests/auto/declarative/qmlstates/data/basicBinding3.qml new file mode 100644 index 0000000..a3c47d9 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicBinding3.qml @@ -0,0 +1,13 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + + property color sourceColor: "red" + property color sourceColor2: "blue" + width: 100; height: 100 + color: sourceColor + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: sourceColor2 } + } +} diff --git a/tests/auto/declarative/qmlstates/data/basicBinding4.qml b/tests/auto/declarative/qmlstates/data/basicBinding4.qml new file mode 100644 index 0000000..1f52d0e --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicBinding4.qml @@ -0,0 +1,17 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + + property color sourceColor: "blue" + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: myRectangle; color: sourceColor } + }, + State { + name: "green" + PropertyChanges { target: myRectangle; color: "green" } + }] +} diff --git a/tests/auto/declarative/qmlstates/data/basicChanges.qml b/tests/auto/declarative/qmlstates/data/basicChanges.qml new file mode 100644 index 0000000..88ea256 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicChanges.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + } +} diff --git a/tests/auto/declarative/qmlstates/data/basicChanges2.qml b/tests/auto/declarative/qmlstates/data/basicChanges2.qml new file mode 100644 index 0000000..4dd293f --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicChanges2.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + }, + State { + name: "green" + PropertyChanges { target: myRectangle; color: "green" } + }] +} diff --git a/tests/auto/declarative/qmlstates/data/basicChanges3.qml b/tests/auto/declarative/qmlstates/data/basicChanges3.qml new file mode 100644 index 0000000..62ab1d5 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicChanges3.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + }, + State { + name: "bordered" + PropertyChanges { target: myRectangle; border.width: 2 } + }] +} diff --git a/tests/auto/declarative/qmlstates/data/basicExtension.qml b/tests/auto/declarative/qmlstates/data/basicExtension.qml new file mode 100644 index 0000000..1836f8a --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/basicExtension.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + }, + State { + name: "bordered" + extend: "blue" + PropertyChanges { target: myRectangle; border.width: 2 } + }] +} diff --git a/tests/auto/declarative/qmlstates/data/deleting.qml b/tests/auto/declarative/qmlstates/data/deleting.qml new file mode 100644 index 0000000..3da0b12 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/deleting.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue"; objectName: "pc1" } + PropertyChanges { target: myRectangle; radius: 5; objectName: "pc2" } + } +} diff --git a/tests/auto/declarative/qmlstates/data/deletingState.qml b/tests/auto/declarative/qmlstates/data/deletingState.qml new file mode 100644 index 0000000..a5e8ed3 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/deletingState.qml @@ -0,0 +1,13 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + StateGroup { + id: stateGroup + states: State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/explicit.qml b/tests/auto/declarative/qmlstates/data/explicit.qml new file mode 100644 index 0000000..7543f84 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/explicit.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + property color sourceColor: "blue" + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { + objectName: "changes" + target: myRectangle; explicit: true + color: sourceColor + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/fakeExtension.qml b/tests/auto/declarative/qmlstates/data/fakeExtension.qml new file mode 100644 index 0000000..c7975e1 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/fakeExtension.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: [ + State { + name: "blue" + PropertyChanges { target: myRectangle; color: "blue" } + }, + State { + name: "green" + extend: "blue" + PropertyChanges { target: myRectangle; color: "green" } + }] +} diff --git a/tests/auto/declarative/qmlstates/data/illegalTempState.qml b/tests/auto/declarative/qmlstates/data/illegalTempState.qml new file mode 100644 index 0000000..2702be4 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/illegalTempState.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + id: card + width: 100; height: 100 + + states: [ + State { + name: "placed" + PropertyChanges { target: card; state: "idle" } + }, + State { + name: "idle" + } + ] + + MouseRegion { + anchors.fill: parent + onClicked: card.state = "placed" + } +} diff --git a/tests/auto/declarative/qmlstates/data/legalTempState.qml b/tests/auto/declarative/qmlstates/data/legalTempState.qml new file mode 100644 index 0000000..54c97b9 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/legalTempState.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Rectangle { + id: card + width: 100; height: 100 + + states: [ + State { + name: "placed" + onCompleted: card.state = "idle" + StateChangeScript { script: console.log("entering placed") } + }, + State { + name: "idle" + StateChangeScript { script: console.log("entering idle") } + } + ] + + MouseRegion { + anchors.fill: parent + onClicked: card.state = "placed" + } +} diff --git a/tests/auto/declarative/qmlstates/data/nonExistantProp.qml b/tests/auto/declarative/qmlstates/data/nonExistantProp.qml new file mode 100644 index 0000000..a5dd86a --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/nonExistantProp.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: myRectangle; colr: "blue" } + } +} diff --git a/tests/auto/declarative/qmlstates/data/parentChange.qml b/tests/auto/declarative/qmlstates/data/parentChange.qml new file mode 100644 index 0000000..087da6b --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/parentChange.qml @@ -0,0 +1,37 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: clickable + anchors.fill: parent + } + + Item { + x: -100; y: -50 + Item { + id: newParent + objectName: "NewParent" + x: 248; y: 360 + } + } + + states: State { + name: "reparented" + when: clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/parentChange2.qml b/tests/auto/declarative/qmlstates/data/parentChange2.qml new file mode 100644 index 0000000..f0b00f5 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/parentChange2.qml @@ -0,0 +1,31 @@ +import Qt 4.6 + +Rectangle { + id: newParent + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: clickable + anchors.fill: parent + } + + states: State { + name: "reparented" + when: clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/parentChange3.qml b/tests/auto/declarative/qmlstates/data/parentChange3.qml new file mode 100644 index 0000000..2aa507c --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/parentChange3.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + transformOrigin: "Center" + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + transformOrigin: "BottomLeft" + color: "red" + } + } + MouseRegion { + id: clickable + anchors.fill: parent + } + + Item { + x: 200; y: 200 + rotation: 52; + scale: 2 + Item { + id: newParent + x: 100; y: 100 + } + } + + states: State { + name: "reparented" + when: clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/parentChange4.qml b/tests/auto/declarative/qmlstates/data/parentChange4.qml new file mode 100644 index 0000000..d00274b --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/parentChange4.qml @@ -0,0 +1,30 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5; y: 5 + width: 100; height: 100 + color: "red" + } + MouseRegion { + id: clickable + anchors.fill: parent + } + + Item { + id: newParent + transform: Scale { xScale: .5; yScale: .7} + } + + states: State { + name: "reparented" + when: clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/parentChange5.qml b/tests/auto/declarative/qmlstates/data/parentChange5.qml new file mode 100644 index 0000000..f75e2a3 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/parentChange5.qml @@ -0,0 +1,30 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5; y: 5 + width: 100; height: 100 + color: "red" + } + MouseRegion { + id: clickable + anchors.fill: parent + } + + Item { + id: newParent + transform: Rotation { angle: 30; axis { x: 0; y: 1; z: 0 } } + } + + states: State { + name: "reparented" + when: clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/propertyErrors.qml b/tests/auto/declarative/qmlstates/data/propertyErrors.qml new file mode 100644 index 0000000..080e833 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/propertyErrors.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: myRectangle; colr: "blue"; wantsFocus: true } + } +} diff --git a/tests/auto/declarative/qmlstates/data/restoreEntryValues.qml b/tests/auto/declarative/qmlstates/data/restoreEntryValues.qml new file mode 100644 index 0000000..088c608 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/restoreEntryValues.qml @@ -0,0 +1,14 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { + target: myRectangle + restoreEntryValues: false + color: "blue" + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/script.qml b/tests/auto/declarative/qmlstates/data/script.qml new file mode 100644 index 0000000..3c5f33e --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/script.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: myRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + StateChangeScript { script: myRectangle.color = "blue"; } + } +} diff --git a/tests/auto/declarative/qmlstates/data/signalOverride.qml b/tests/auto/declarative/qmlstates/data/signalOverride.qml new file mode 100644 index 0000000..5ba1566 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/signalOverride.qml @@ -0,0 +1,18 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + + onDidSomething: color = "blue" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: color = "green" + } + } +} diff --git a/tests/auto/declarative/qmlstates/data/signalOverride2.qml b/tests/auto/declarative/qmlstates/data/signalOverride2.qml new file mode 100644 index 0000000..527e165 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/signalOverride2.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + onDidSomething: color = "blue" + width: 100; height: 100 + ExtendedRectangle {} +} diff --git a/tests/auto/declarative/qmlstates/data/signalOverrideCrash.qml b/tests/auto/declarative/qmlstates/data/signalOverrideCrash.qml new file mode 100644 index 0000000..702fa86 --- /dev/null +++ b/tests/auto/declarative/qmlstates/data/signalOverrideCrash.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + + width: 100; height: 100 + states: State { + name: "overridden" + PropertyChanges { + target: rect + onDidSomething: rect.state = "" + } + } +} diff --git a/tests/auto/declarative/qmlstates/qmlstates.pro b/tests/auto/declarative/qmlstates/qmlstates.pro new file mode 100644 index 0000000..538734a --- /dev/null +++ b/tests/auto/declarative/qmlstates/qmlstates.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlstates.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlstates/tst_qmlstates.cpp b/tests/auto/declarative/qmlstates/tst_qmlstates.cpp new file mode 100644 index 0000000..9e3387f --- /dev/null +++ b/tests/auto/declarative/qmlstates/tst_qmlstates.cpp @@ -0,0 +1,887 @@ +/**************************************************************************** +** +** 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 <private/qmlgraphicsanchors_p_p.h> +#include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlpropertychanges_p.h> +#include <private/qmlstategroup_p.h> + +class tst_states : public QObject +{ + Q_OBJECT +public: + tst_states() {} + +private: + static QByteArray fullDataPath(const QString &path); + +private slots: + void basicChanges(); + void basicExtension(); + void basicBinding(); + void signalOverride(); + void signalOverrideCrash(); + void parentChange(); + void parentChangeErrors(); + void anchorChanges(); + void anchorChanges2(); + void anchorChanges3(); + void anchorChanges4(); + void anchorChanges5(); + void script(); + void restoreEntryValues(); + void explicitChanges(); + void propertyErrors(); + void incorrectRestoreBug(); + void autoStateAtStartupRestoreBug(); + void deletingChange(); + void deletingState(); + void tempState(); + void illegalTempState(); + void nonExistantProperty(); +}; + +QByteArray tst_states::fullDataPath(const QString &path) +{ + return QUrl::fromLocalFile(SRCDIR + path).toString().toUtf8(); +} + +void tst_states::basicChanges() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),2); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + //### we should be checking that this is an implicit rather than explicit 1 (which currently fails) + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),2); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + } +} + +void tst_states::basicExtension() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),2); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),1); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + + rect->setState("bordered"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->border()->width(),2); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->border()->width(),1); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + } +} + +void tst_states::basicBinding() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("green")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("red")); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor2", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor2", QColor("green")); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("yellow")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + rect->setProperty("sourceColor", QColor("purple")); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("purple")); + + rect->setState("green"); + QCOMPARE(rect->color(),QColor("green")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + } +} + +class MyRect : public QmlGraphicsRectangle +{ + Q_OBJECT +public: + MyRect() {} + void doSomething() { emit didSomething(); } +Q_SIGNALS: + void didSomething(); +}; + +QML_DECLARE_TYPE(MyRect) +QML_DEFINE_TYPE(Qt.test, 1, 0, MyRectangle,MyRect); + +void tst_states::signalOverride() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride.qml"); + MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("green")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride2.qml"); + MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("white")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("extendedRect")); + + innerRect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(innerRect->color(),QColor("green")); + QCOMPARE(innerRect->property("extendedColor").value<QColor>(),QColor("green")); + } +} + +void tst_states::signalOverrideCrash() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverrideCrash.qml"); + MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); + QVERIFY(rect != 0); + + rect->setState("overridden"); + rect->doSomething(); +} + +void tst_states::parentChange() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlParentChange *pChange = qobject_cast<QmlParentChange*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(pChange != 0); + QmlGraphicsItem *nParent = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("NewParent")); + QVERIFY(nParent != 0); + + QCOMPARE(pChange->parent(), nParent); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(-133)); + QCOMPARE(innerRect->y(), qreal(-300)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange2.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(15)); + QCOMPARE(innerRect->scale(), qreal(.5)); + QEXPECT_FAIL("", "QTBUG-2919", Continue); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(12.4148145657)); + QEXPECT_FAIL("", "QTBUG-2919", Continue); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(10.6470476128)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange3.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(-37)); + QCOMPARE(innerRect->scale(), qreal(.25)); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-217.305)); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-164.413)); + + rect->setState(""); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(5)); + QEXPECT_FAIL("", "QTBUG-2919", Continue); + QCOMPARE(innerRect->y(), qreal(0)); + } +} + +void tst_states::parentChangeErrors() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange4.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QTest::ignoreMessage(QtWarningMsg, QByteArray("QML ParentChange (" + fullDataPath("/data/parentChange4.qml") + ":25:9) Unable to preserve appearance under non-uniform scale").constData()); + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(5)); + QCOMPARE(innerRect->y(), qreal(5)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange5.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QTest::ignoreMessage(QtWarningMsg, QByteArray("QML ParentChange (" + fullDataPath("/data/parentChange5.qml") + ":25:9) Unable to preserve appearance under complex transform").constData()); + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(5)); + QCOMPARE(innerRect->y(), qreal(5)); + } +} + +void tst_states::anchorChanges() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + QCOMPARE(aChanges->reset(), QString("left")); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->right().item, rect->right().item); + QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + + delete rect; +} + +void tst_states::anchorChanges2() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("right"); + QEXPECT_FAIL("", "QTBUG-5338", Continue); + QCOMPARE(innerRect->x(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + + delete rect; +} + +void tst_states::anchorChanges3() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->left().item, leftGuideline->left().item); + QCOMPARE(aChanges->left().anchorLine, leftGuideline->left().anchorLine); + QCOMPARE(aChanges->right().item, rect->right().item); + QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->top().item, rect->top().item); + QCOMPARE(aChanges->top().anchorLine, rect->top().anchorLine); + QCOMPARE(aChanges->bottom().item, bottomGuideline->bottom().item); + QCOMPARE(aChanges->bottom().anchorLine, bottomGuideline->bottom().anchorLine); + + QCOMPARE(innerRect->x(), qreal(10)); + QCOMPARE(innerRect->y(), qreal(0)); + QCOMPARE(innerRect->width(), qreal(190)); + QCOMPARE(innerRect->height(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(0)); + QCOMPARE(innerRect->y(), qreal(10)); + QCOMPARE(innerRect->width(), qreal(150)); + QCOMPARE(innerRect->height(), qreal(190)); + + delete rect; +} + +void tst_states::anchorChanges4() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges4.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->verticalCenter().item, leftGuideline->verticalCenter().item); + QCOMPARE(aChanges->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); + + delete rect; +} + +void tst_states::anchorChanges5() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges5.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->baseline().item, leftGuideline->baseline().item); + QCOMPARE(aChanges->baseline().anchorLine, leftGuideline->baseline().anchorLine); + + delete rect; +} + +void tst_states::script() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/script.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("blue")); // a script isn't reverted + } +} + +void tst_states::restoreEntryValues() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/restoreEntryValues.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("blue")); +} + +void tst_states::explicitChanges() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/explicit.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + qmlExecuteDeferred(rect->states()->at(0)); + QmlPropertyChanges *changes = qobject_cast<QmlPropertyChanges*>(rect->findChild<QmlPropertyChanges*>("changes")); + QVERIFY(changes != 0); + QVERIFY(changes->isExplicit()); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setProperty("sourceColor", QColor("green")); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + rect->setProperty("sourceColor", QColor("yellow")); + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("yellow")); +} + +void tst_states::propertyErrors() +{ + QmlEngine engine; + QmlComponent rectComponent(&engine, SRCDIR "/data/propertyErrors.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + QTest::ignoreMessage(QtWarningMsg, QByteArray("QML PropertyChanges (" + fullDataPath("/data/propertyErrors.qml") + ":8:9) Cannot assign to non-existant property \"colr\"").constData()); + QTest::ignoreMessage(QtWarningMsg, QByteArray("QML PropertyChanges (" + fullDataPath("/data/propertyErrors.qml") + ":8:9) Cannot assign to read-only property \"wantsFocus\"").constData()); + rect->setState("blue"); +} + +void tst_states::incorrectRestoreBug() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + // make sure if we change the base state value, we then restore to it correctly + rect->setColor(QColor("green")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("green")); +} + +void tst_states::autoStateAtStartupRestoreBug() +{ + QmlEngine engine; + + QmlComponent component(&engine, SRCDIR "/data/autoStateAtStartupRestoreBug.qml"); + QObject *obj = component.create(); + + QVERIFY(obj != 0); + QCOMPARE(obj->property("test").toInt(), 3); + + obj->setProperty("input", 2); + + QCOMPARE(obj->property("test").toInt(), 9); + + delete obj; +} + +void tst_states::deletingChange() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deleting.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->radius(),qreal(5)); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(0)); + + QmlPropertyChanges *pc = rect->findChild<QmlPropertyChanges*>("pc1"); + QVERIFY(pc != 0); + delete pc; + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + qmlExecuteDeferred(state); + QCOMPARE(state->changes()->count(), 1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(5)); + + delete rect; +} + +void tst_states::deletingState() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deletingState.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlStateGroup *sg = rect->findChild<QmlStateGroup*>(); + QVERIFY(sg != 0); + QVERIFY(sg->findState("blue") != 0); + + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + sg->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + delete state; + + QVERIFY(sg->findState("blue") == 0); + + //### should we warn that state doesn't exist + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + + delete rect; +} + +void tst_states::tempState() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/legalTempState.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QTest::ignoreMessage(QtDebugMsg, "entering placed"); + QTest::ignoreMessage(QtDebugMsg, "entering idle"); + rect->setState("placed"); + QCOMPARE(rect->state(), QLatin1String("idle")); +} + +void tst_states::illegalTempState() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/illegalTempState.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QTest::ignoreMessage(QtWarningMsg, "Can't apply a state change as part of a state definition. "); + rect->setState("placed"); + QCOMPARE(rect->state(), QLatin1String("placed")); +} + +void tst_states::nonExistantProperty() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/nonExistantProp.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QTest::ignoreMessage(QtWarningMsg, QByteArray("QML PropertyChanges (" + fullDataPath("/data/nonExistantProp.qml") + ":9:9) Cannot assign to non-existant property \"colr\"").constData()); + rect->setState("blue"); + QCOMPARE(rect->state(), QLatin1String("blue")); +} + +QTEST_MAIN(tst_states) + +#include "tst_states.moc" |