summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/animations/data/badproperty1.qml6
-rw-r--r--tests/auto/declarative/animations/data/badtype1.qml4
-rw-r--r--tests/auto/declarative/animations/data/badtype2.qml4
-rw-r--r--tests/auto/declarative/animations/data/badtype3.qml4
-rw-r--r--tests/auto/declarative/animations/data/badtype4.qml9
-rw-r--r--tests/auto/declarative/animations/data/color.qml12
-rw-r--r--tests/auto/declarative/animations/data/dotproperty.qml6
-rw-r--r--tests/auto/declarative/animations/data/mixedtype1.qml8
-rw-r--r--tests/auto/declarative/animations/data/mixedtype2.qml6
-rw-r--r--tests/auto/declarative/animations/data/number.qml12
-rw-r--r--tests/auto/declarative/animations/tst_animations.cpp155
11 files changed, 153 insertions, 73 deletions
diff --git a/tests/auto/declarative/animations/data/badproperty1.qml b/tests/auto/declarative/animations/data/badproperty1.qml
index b88cd6f..a01753e 100644
--- a/tests/auto/declarative/animations/data/badproperty1.qml
+++ b/tests/auto/declarative/animations/data/badproperty1.qml
@@ -1,10 +1,10 @@
import Qt 4.6
-Rect {
+Rectangle {
id: Wrapper
width: 240
height: 320
- Rect {
+ Rectangle {
id: MyRect
color: "red"
width: 50; height: 50
@@ -16,7 +16,7 @@ Rect {
}
states: State {
name: "state1"
- SetProperties { target: MyRect; pen.color: "blue" }
+ PropertyChanges { target: MyRect; pen.color: "blue" }
}
transitions: Transition {
ColorAnimation { target: MyRect; to: "red"; properties: "pen.colr"; duration: 1000 }
diff --git a/tests/auto/declarative/animations/data/badtype1.qml b/tests/auto/declarative/animations/data/badtype1.qml
index 00db39e..1e689d5 100644
--- a/tests/auto/declarative/animations/data/badtype1.qml
+++ b/tests/auto/declarative/animations/data/badtype1.qml
@@ -1,9 +1,9 @@
import Qt 4.6
-Rect {
+Rectangle {
width: 240
height: 320
- Rect {
+ Rectangle {
color: "red"
width: 50; height: 50
x: 100; y: 100
diff --git a/tests/auto/declarative/animations/data/badtype2.qml b/tests/auto/declarative/animations/data/badtype2.qml
index eeaaefc..e97194d 100644
--- a/tests/auto/declarative/animations/data/badtype2.qml
+++ b/tests/auto/declarative/animations/data/badtype2.qml
@@ -1,9 +1,9 @@
import Qt 4.6
-Rect {
+Rectangle {
width: 240
height: 320
- Rect {
+ Rectangle {
color: "red"
width: 50; height: 50
x: 100; y: 100
diff --git a/tests/auto/declarative/animations/data/badtype3.qml b/tests/auto/declarative/animations/data/badtype3.qml
index cbb1a4d..b2d738f 100644
--- a/tests/auto/declarative/animations/data/badtype3.qml
+++ b/tests/auto/declarative/animations/data/badtype3.qml
@@ -1,9 +1,9 @@
import Qt 4.6
-Rect {
+Rectangle {
width: 240
height: 320
- Rect {
+ Rectangle {
color: "red"
color: ColorAnimation { from: 10; to: 15; running: true; }
width: 50; height: 50
diff --git a/tests/auto/declarative/animations/data/badtype4.qml b/tests/auto/declarative/animations/data/badtype4.qml
index 3e046fc..0c0a636 100644
--- a/tests/auto/declarative/animations/data/badtype4.qml
+++ b/tests/auto/declarative/animations/data/badtype4.qml
@@ -1,10 +1,10 @@
import Qt 4.6
-Rect {
+Rectangle {
id: Wrapper
width: 240
height: 320
- Rect {
+ Rectangle {
id: MyRect
color: "red"
width: 50; height: 50
@@ -16,10 +16,11 @@ Rect {
}
states: State {
name: "state1"
- SetProperties { target: MyRect; x: 200; color: "blue" }
+ PropertyChanges { target: MyRect; x: 200; color: "blue" }
}
transitions: Transition {
+ //comment out each in turn to make sure each only animates the relevant property
ColorAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color
- //NumberAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color
+ NumberAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color
}
}
diff --git a/tests/auto/declarative/animations/data/color.qml b/tests/auto/declarative/animations/data/color.qml
deleted file mode 100644
index 8a9ab8a..0000000
--- a/tests/auto/declarative/animations/data/color.qml
+++ /dev/null
@@ -1,12 +0,0 @@
-import Qt 4.6
-
-Rect {
- width: 240
- height: 320
- Rect {
- color: "red"
- color: PropertyAnimation { to: "green"; running: true }
- width: 50; height: 50
- x: 100; y: 100
- }
-}
diff --git a/tests/auto/declarative/animations/data/dotproperty.qml b/tests/auto/declarative/animations/data/dotproperty.qml
index 25076b8..ee076c2 100644
--- a/tests/auto/declarative/animations/data/dotproperty.qml
+++ b/tests/auto/declarative/animations/data/dotproperty.qml
@@ -1,10 +1,10 @@
import Qt 4.6
-Rect {
+Rectangle {
id: Wrapper
width: 240
height: 320
- Rect {
+ Rectangle {
id: MyRect
color: "red"
width: 50; height: 50
@@ -16,7 +16,7 @@ Rect {
}
states: State {
name: "state1"
- SetProperties { target: MyRect; pen.color: "blue" }
+ PropertyChanges { target: MyRect; pen.color: "blue" }
}
transitions: Transition {
ColorAnimation { properties: "pen.color"; duration: 1000 }
diff --git a/tests/auto/declarative/animations/data/mixedtype1.qml b/tests/auto/declarative/animations/data/mixedtype1.qml
index 8b8262b..ed50582 100644
--- a/tests/auto/declarative/animations/data/mixedtype1.qml
+++ b/tests/auto/declarative/animations/data/mixedtype1.qml
@@ -1,10 +1,10 @@
import Qt 4.6
-Rect {
+Rectangle {
id: Wrapper
width: 240
height: 320
- Rect {
+ Rectangle {
id: MyRect
color: "red"
width: 50; height: 50
@@ -16,9 +16,9 @@ Rect {
}
states: State {
name: "state1"
- SetProperties { target: MyRect; x: 200; width: 40 }
+ PropertyChanges { target: MyRect; x: 200; border.width: 10 }
}
transitions: Transition {
- PropertyAnimation { properties: "x,width"; duration: 1000 } //x is real, width is int
+ PropertyAnimation { properties: "x,border.width"; duration: 1000 } //x is real, border.width is int
}
}
diff --git a/tests/auto/declarative/animations/data/mixedtype2.qml b/tests/auto/declarative/animations/data/mixedtype2.qml
index 95b8ed7..4854c2e 100644
--- a/tests/auto/declarative/animations/data/mixedtype2.qml
+++ b/tests/auto/declarative/animations/data/mixedtype2.qml
@@ -1,10 +1,10 @@
import Qt 4.6
-Rect {
+Rectangle {
id: Wrapper
width: 240
height: 320
- Rect {
+ Rectangle {
id: MyRect
color: "red"
width: 50; height: 50
@@ -16,7 +16,7 @@ Rect {
}
states: State {
name: "state1"
- SetProperties { target: MyRect; x: 200; color: "blue" }
+ PropertyChanges { target: MyRect; x: 200; color: "blue" }
}
transitions: Transition {
PropertyAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color
diff --git a/tests/auto/declarative/animations/data/number.qml b/tests/auto/declarative/animations/data/number.qml
deleted file mode 100644
index bde1168..0000000
--- a/tests/auto/declarative/animations/data/number.qml
+++ /dev/null
@@ -1,12 +0,0 @@
-import Qt 4.6
-
-Rect {
- width: 240
- height: 320
- Rect {
- color: "red"
- width: 50; height: 50
- x: 100; y: 100
- x: PropertyAnimation { from: 0; to: 200; duration: 1000; running: true }
- }
-}
diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp
index 889d9b7..8e1abc6 100644
--- a/tests/auto/declarative/animations/tst_animations.cpp
+++ b/tests/auto/declarative/animations/tst_animations.cpp
@@ -3,6 +3,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qfxview.h>
#include <QtDeclarative/qfxrect.h>
+#include <QtDeclarative/QmlNumberAnimation>
class tst_animations : public QObject
{
@@ -11,11 +12,87 @@ public:
tst_animations() {}
private slots:
+ void simpleNumber();
+ void simpleColor();
+ void alwaysRunToEnd();
+ void dotProperty();
void badTypes();
void badProperties();
- //void mixedTypes();
+ void mixedTypes();
};
+void tst_animations::simpleNumber()
+{
+ QFxRect rect;
+ QmlNumberAnimation animation;
+ animation.setTarget(&rect);
+ animation.setProperty("x");
+ animation.setTo(200);
+ animation.start();
+ QTest::qWait(animation.duration() + 50);
+ QCOMPARE(rect.x(), qreal(200));
+
+ rect.setX(0);
+ animation.start();
+ animation.pause();
+ animation.setCurrentTime(125);
+ QCOMPARE(rect.x(), qreal(100));
+}
+
+void tst_animations::simpleColor()
+{
+ QFxRect rect;
+ QmlColorAnimation animation;
+ animation.setTarget(&rect);
+ animation.setProperty("color");
+ animation.setTo(QColor("red"));
+ animation.start();
+ QTest::qWait(animation.duration() + 50);
+ QCOMPARE(rect.color(), QColor("red"));
+
+ rect.setColor(QColor("blue"));
+ animation.start();
+ animation.pause();
+ animation.setCurrentTime(125);
+ QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1));
+}
+
+void tst_animations::alwaysRunToEnd()
+{
+ QFxRect rect;
+ QmlPropertyAnimation animation;
+ animation.setTarget(&rect);
+ animation.setProperty("x");
+ animation.setTo(200);
+ animation.setDuration(1000);
+ animation.setRepeat(true);
+ animation.setAlwaysRunToEnd(true);
+ animation.start();
+ QTest::qWait(1500);
+ animation.stop();
+ QVERIFY(rect.x() != qreal(200));
+ QTest::qWait(500 + 50);
+ QCOMPARE(rect.x(), qreal(200));
+}
+
+void tst_animations::dotProperty()
+{
+ QFxRect rect;
+ QmlNumberAnimation animation;
+ animation.setTarget(&rect);
+ animation.setProperty("border.width");
+ animation.setTo(10);
+ animation.start();
+ QTest::qWait(animation.duration() + 50);
+ QCOMPARE(rect.border()->width(), 10);
+
+ rect.border()->setWidth(1);
+ animation.start();
+ animation.pause();
+ animation.setCurrentTime(125);
+ QCOMPARE(rect.border()->width(), 5);
+}
+
void tst_animations::badTypes()
{
//don't crash
@@ -50,47 +127,73 @@ void tst_animations::badTypes()
QVERIFY(c.errors().count() == 1);
QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected"));
}
+
+ //don't crash
+ {
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype4.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("state1");
+ QTest::qWait(1000 + 50);
+ QFxRect *myRect = qobject_cast<QFxRect*>(rect->QGraphicsObject::children().at(3)); //### not robust
+ QVERIFY(myRect);
+ QCOMPARE(myRect->x(),qreal(200));
+ }
}
void tst_animations::badProperties()
{
- //don't crash (should be runtime error)
+ //make sure we get a runtime error
{
- QFxView *view = new QFxView;
- view->setUrl(QUrl("file://" SRCDIR "/data/badproperty1.qml"));
-
- view->execute();
- qApp->processEvents();
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badproperty1.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
- delete view;
+ QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\" ");
+ rect->setState("state1");
}
}
-/*//test animating mixed types with property animation
- //for example, int + real; color + real; etc
+//test animating mixed types with property animation in a transition
+//for example, int + real; color + real; etc
void tst_animations::mixedTypes()
{
- //### this one isn't real robust because width will likely change to real as well
+ //assumes border.width stats a real -- not real robust
{
- QFxView *view = new QFxView;
- view->setUrl(QUrl("file://" SRCDIR "/data/mixedtype1.qml"));
-
- view->execute();
- qApp->processEvents();
-
- delete view;
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype1.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("state1");
+ QTest::qWait(500);
+ QFxRect *myRect = qobject_cast<QFxRect*>(rect->QGraphicsObject::children().at(3)); //### not robust
+ QVERIFY(myRect);
+
+ //rather inexact -- is there a better way?
+ QVERIFY(myRect->x() > 100 && myRect->x() < 200);
+ QVERIFY(myRect->border()->width() > 1 && myRect->border()->width() < 10);
}
{
- QFxView *view = new QFxView;
- view->setUrl(QUrl("file://" SRCDIR "/data/mixedtype2.qml"));
-
- view->execute();
- qApp->processEvents();
-
- delete view;
+ QmlEngine engine;
+ QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype2.qml"));
+ QFxRect *rect = qobject_cast<QFxRect*>(c.create());
+ QVERIFY(rect);
+
+ rect->setState("state1");
+ QTest::qWait(500);
+ QFxRect *myRect = qobject_cast<QFxRect*>(rect->QGraphicsObject::children().at(3)); //### not robust
+ QVERIFY(myRect);
+
+ //rather inexact -- is there a better way?
+ QVERIFY(myRect->x() > 100 && myRect->x() < 200);
+ QVERIFY(myRect->color() != QColor("red") && myRect->color() != QColor("blue"));
}
-}*/
+}
QTEST_MAIN(tst_animations)