summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/behaviors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/behaviors')
-rw-r--r--tests/auto/declarative/behaviors/behaviors.pro5
-rw-r--r--tests/auto/declarative/behaviors/data/binding.qml26
-rw-r--r--tests/auto/declarative/behaviors/data/color.qml24
-rw-r--r--tests/auto/declarative/behaviors/data/cpptrigger.qml11
-rw-r--r--tests/auto/declarative/behaviors/data/groupProperty.qml23
-rw-r--r--tests/auto/declarative/behaviors/data/groupProperty2.qml23
-rw-r--r--tests/auto/declarative/behaviors/data/loop.qml19
-rw-r--r--tests/auto/declarative/behaviors/data/scripttrigger.qml16
-rw-r--r--tests/auto/declarative/behaviors/data/simple.qml23
-rw-r--r--tests/auto/declarative/behaviors/tst_behaviors.cpp154
10 files changed, 324 insertions, 0 deletions
diff --git a/tests/auto/declarative/behaviors/behaviors.pro b/tests/auto/declarative/behaviors/behaviors.pro
new file mode 100644
index 0000000..c96d2c0
--- /dev/null
+++ b/tests/auto/declarative/behaviors/behaviors.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative
+SOURCES += tst_behaviors.cpp
+
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/behaviors/data/binding.qml b/tests/auto/declarative/behaviors/data/binding.qml
new file mode 100644
index 0000000..e0c3321
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/binding.qml
@@ -0,0 +1,26 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ property real basex : 0
+ property real movedx: 200
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ x: basex
+ x: Behavior { NumberAnimation { duration: 200; } }
+ }
+ MouseRegion {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "moved"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ x: movedx
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/color.qml b/tests/auto/declarative/behaviors/data/color.qml
new file mode 100644
index 0000000..6598703
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/color.qml
@@ -0,0 +1,24 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100;
+ color: "green"
+ color: Behavior { ColorAnimation { duration: 200; } }
+ }
+ MouseRegion {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "red"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ color: "red"
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/cpptrigger.qml b/tests/auto/declarative/behaviors/data/cpptrigger.qml
new file mode 100644
index 0000000..ba507c4
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/cpptrigger.qml
@@ -0,0 +1,11 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ x: Behavior { NumberAnimation { duration: 200; } }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/groupProperty.qml b/tests/auto/declarative/behaviors/data/groupProperty.qml
new file mode 100644
index 0000000..4f127c1
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/groupProperty.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ pos: Behavior { PropertyAnimation { duration: 200; } }
+ }
+ MouseRegion {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "moved"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ pos: Qt.point(200,0);
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/groupProperty2.qml b/tests/auto/declarative/behaviors/data/groupProperty2.qml
new file mode 100644
index 0000000..19d70b6
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/groupProperty2.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ pos.x: Behavior { NumberAnimation { duration: 200; } }
+ }
+ MouseRegion {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "moved"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ pos.x: 200;
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/loop.qml b/tests/auto/declarative/behaviors/data/loop.qml
new file mode 100644
index 0000000..5f2c057
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/loop.qml
@@ -0,0 +1,19 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ x: Behavior { NumberAnimation { duration: 200; } }
+ onXChanged: x = 100;
+ }
+ states: State {
+ name: "moved"
+ PropertyChanges {
+ target: rect
+ x: 200
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/scripttrigger.qml b/tests/auto/declarative/behaviors/data/scripttrigger.qml
new file mode 100644
index 0000000..4383a0b
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/scripttrigger.qml
@@ -0,0 +1,16 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+
+ onColorChanged: {
+ rect.x = 200
+ }
+
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ x: Behavior { NumberAnimation { duration: 200; } }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml
new file mode 100644
index 0000000..a715f7b
--- /dev/null
+++ b/tests/auto/declarative/behaviors/data/simple.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+Rectangle {
+ width: 400
+ height: 400
+ Rectangle {
+ id: rect
+ objectName: "MyRect"
+ width: 100; height: 100; color: "green"
+ x: Behavior { NumberAnimation { duration: 200; } }
+ }
+ MouseRegion {
+ id: clicker
+ anchors.fill: parent
+ }
+ states: State {
+ name: "moved"
+ when: clicker.pressed
+ PropertyChanges {
+ target: rect
+ x: 200
+ }
+ }
+}
diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp
new file mode 100644
index 0000000..7bfadf6
--- /dev/null
+++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp
@@ -0,0 +1,154 @@
+#include <qtest.h>
+#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlcomponent.h>
+#include <QtDeclarative/qmlview.h>
+#include <QtDeclarative/qfxrect.h>
+#include <QtDeclarative/QmlNumberAnimation>
+
+class tst_behaviors : public QObject
+{
+ Q_OBJECT
+public:
+ tst_behaviors() {}
+
+private slots:
+ void simpleBehavior();
+ void scriptTriggered();
+ void cppTriggered();
+ void loop();
+ void colorBehavior();
+ void replaceBinding();
+ //void transitionOverrides();
+ void group();
+};
+
+void tst_behaviors::simpleBehavior()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ QTest::qWait(100);
+ qreal x = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"))->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+}
+
+void tst_behaviors::scriptTriggered()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/scripttrigger.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setColor(QColor("red"));
+ QTest::qWait(100);
+ qreal x = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"))->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+}
+
+void tst_behaviors::cppTriggered()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/cpptrigger.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ QFxRect *innerRect = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"));
+ QVERIFY(innerRect);
+
+ innerRect->setProperty("x", 200);
+ QTest::qWait(100);
+ qreal x = innerRect->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+}
+
+void tst_behaviors::loop()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/loop.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ //don't crash
+ rect->setState("moved");
+}
+
+void tst_behaviors::colorBehavior()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/color.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("red");
+ QTest::qWait(100);
+ QColor color = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"))->color();
+ QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered
+}
+
+void tst_behaviors::replaceBinding()
+{
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/binding.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ QTest::qWait(100);
+ QFxRect *innerRect = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"));
+ QVERIFY(innerRect);
+ qreal x = innerRect->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+ QTest::qWait(300);
+ QCOMPARE(innerRect->x(), (qreal)200);
+ rect->setProperty("basex", 10);
+ QCOMPARE(innerRect->x(), (qreal)200);
+ rect->setProperty("movedx", 210);
+ QTest::qWait(300);
+ QCOMPARE(innerRect->x(), (qreal)210);
+
+ rect->setState("");
+ QTest::qWait(100);
+ x = innerRect->x();
+ QVERIFY(x > 10 && x < 210); //i.e. the behavior has been triggered
+ QTest::qWait(300);
+ QCOMPARE(innerRect->x(), (qreal)10);
+ rect->setProperty("movedx", 200);
+ QCOMPARE(innerRect->x(), (qreal)10);
+ rect->setProperty("basex", 20);
+ QTest::qWait(300);
+ QCOMPARE(innerRect->x(), (qreal)20);
+}
+
+void tst_behaviors::group()
+{
+ {
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ QTest::qWait(100);
+ qreal x = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"))->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+ }
+
+ {
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty2.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("moved");
+ QTest::qWait(100);
+ qreal x = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("MyRect"))->x();
+ QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered
+ }
+}
+
+QTEST_MAIN(tst_behaviors)
+
+#include "tst_behaviors.moc"