diff options
Diffstat (limited to 'tests/auto')
30 files changed, 612 insertions, 214 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) diff --git a/tests/auto/declarative/qmlbindengine/enums.1.qml b/tests/auto/declarative/qmlbindengine/enums.1.qml new file mode 100644 index 0000000..6351823 --- /dev/null +++ b/tests/auto/declarative/qmlbindengine/enums.1.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import Qt.test 1.0 as Namespace + +MyQmlObject { + // Enums from non-namespaced type + property int a: MyQmlObject.EnumValue1 + property int b: MyQmlObject.EnumValue2 + property int c: MyQmlObject.EnumValue3 + property int d: MyQmlObject.EnumValue4 + + // Enums from namespaced type + property int e: Namespace.MyQmlObject.EnumValue1 + property int f: Namespace.MyQmlObject.EnumValue2 + property int g: Namespace.MyQmlObject.EnumValue3 + property int h: Namespace.MyQmlObject.EnumValue4 + + // Test that enums don't mask attached properties + property int i: MyQmlObject.value + property int j: Namespace.MyQmlObject.value +} diff --git a/tests/auto/declarative/qmlbindengine/testtypes.h b/tests/auto/declarative/qmlbindengine/testtypes.h index f5b309e..f27c0b0 100644 --- a/tests/auto/declarative/qmlbindengine/testtypes.h +++ b/tests/auto/declarative/qmlbindengine/testtypes.h @@ -5,9 +5,21 @@ #include <QtDeclarative/qml.h> #include <QtDeclarative/qmlexpression.h> +class MyQmlAttachedObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value CONSTANT) +public: + MyQmlAttachedObject(QObject *parent) : QObject(parent) {} + + int value() const { return 19; } +}; + class MyQmlObject : public QObject { Q_OBJECT + Q_ENUMS(MyEnum) + Q_ENUMS(MyEnum2) Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) @@ -15,6 +27,9 @@ class MyQmlObject : public QObject public: MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0) {} + enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; + enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; + bool trueProperty() const { return true; } bool falseProperty() const { return false; } @@ -39,6 +54,10 @@ public: bool methodIntCalled() const { return m_methodIntCalled; } QString string() const { return m_string; } + + static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) { + return new MyQmlAttachedObject(o); + } signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c); diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp index 01cb54b..80373fe 100644 --- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp +++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp @@ -38,6 +38,7 @@ private slots: void objectPropertiesTriggerReeval(); void deferredProperties(); void extensionObjects(); + void enums(); private: QmlEngine engine; @@ -366,6 +367,24 @@ void tst_qmlbindengine::extensionObjects() QCOMPARE(object->baseProperty(), 92); } +void tst_qmlbindengine::enums() +{ + QmlComponent component(&engine, TEST_FILE("enums.1.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("a").toInt(), 0); + QCOMPARE(object->property("b").toInt(), 1); + QCOMPARE(object->property("c").toInt(), 2); + QCOMPARE(object->property("d").toInt(), 3); + QCOMPARE(object->property("e").toInt(), 0); + QCOMPARE(object->property("f").toInt(), 1); + QCOMPARE(object->property("g").toInt(), 2); + QCOMPARE(object->property("h").toInt(), 3); + QCOMPARE(object->property("i").toInt(), 19); + QCOMPARE(object->property("j").toInt(), 19); +} + QTEST_MAIN(tst_qmlbindengine) #include "tst_qmlbindengine.moc" diff --git a/tests/auto/declarative/qmlparser/invalidID.6.errors.txt b/tests/auto/declarative/qmlparser/invalidID.6.errors.txt new file mode 100644 index 0000000..861e3d7 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.6.errors.txt @@ -0,0 +1 @@ +3:9:id conflicts with type name diff --git a/tests/auto/declarative/qmlparser/invalidID.6.qml b/tests/auto/declarative/qmlparser/invalidID.6.qml new file mode 100644 index 0000000..ea34007 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.6.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + id: MyQmlObject +} + diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index e953717..4f2a1f5 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -143,6 +143,7 @@ void tst_qmlparser::errors_data() QTest::newRow("invalidID.3") << "invalidID.3.qml" << "invalidID.3.errors.txt" << false; QTest::newRow("invalidID.4") << "invalidID.4.qml" << "invalidID.4.errors.txt" << false; QTest::newRow("invalidID.5") << "invalidID.5.qml" << "invalidID.5.errors.txt" << false; + QTest::newRow("invalidID.6") << "invalidID.6.qml" << "invalidID.6.errors.txt" << false; QTest::newRow("unsupportedProperty") << "unsupportedProperty.qml" << "unsupportedProperty.errors.txt" << false; diff --git a/tests/auto/declarative/simplecanvasitem/data/test.qml b/tests/auto/declarative/simplecanvasitem/data/test.qml deleted file mode 100644 index 8fbbc2e..0000000 --- a/tests/auto/declarative/simplecanvasitem/data/test.qml +++ /dev/null @@ -1,60 +0,0 @@ -import Qt 4.6 - -Item { - width: 320 - height: 480 - Rect { - color: "blue" - x: 20 - y: 20 - width: 20 - height: 20 - Rect { - color: "black" - x: 20 - y: 20 - width: 10 - height: 10 - } - } - Rect { - color: "red" - x: 40 - y: 20 - width: 20 - height: 20 - } - Rect { - color: "green" - x: 60 - y: 20 - width: 20 - height: 20 - } - Rect { - color: "yellow" - x: 20 - y: 40 - width: 20 - height: 20 - } - Rect { - color: "purple" - x: 20 - y: 60 - width: 20 - height: 20 - } - Rect { - color: "white" - x: 40 - y: 40 - width: 20 - height: 20 - } - Rect { - anchors.fill: parent - color: "gray" - z: -1 - } -} diff --git a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp b/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp deleted file mode 100644 index cce4df1..0000000 --- a/tests/auto/declarative/simplecanvasitem/tst_simplecanvasitem.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include <QtTest/QtTest> -#include <qfxview.h> -#include <qfxitem.h> -#include <qsimplecanvasitem.h> - -/* - Note: this autotest is specifically to test SimpleCanvasItem as a component of - Qt Declarative, and therefore will have all items created in XML. -*/ -class tst_SimpleCanvasItem : public QObject -{ - Q_OBJECT -public: - tst_SimpleCanvasItem(); - -private slots: - void test_pos(); - void test_scenePos(); -private: - QFxView *createView(const QString &filename); -}; - -tst_SimpleCanvasItem::tst_SimpleCanvasItem() -{ -} - -void tst_SimpleCanvasItem::test_pos() -{ - QFxView *canvas = createView(SRCDIR "/data/test.qml"); - canvas->execute(); - qApp->processEvents(); - QSimpleCanvasItem* root = qobject_cast<QSimpleCanvasItem*>(canvas->root()); - QVERIFY(root); - - QCOMPARE(root->pos(), QPointF(0,0)); - QCOMPARE(root->children().at(0)->pos(), QPointF(20,20)); - QCOMPARE(root->children().at(0)->children().at(0)->pos(), QPointF(20,20)); - QCOMPARE(root->children().at(2)->pos(), QPointF(60,20)); - QCOMPARE(root->children().at(3)->pos(), QPointF(20,40)); - QCOMPARE(root->children().at(5)->pos(), QPointF(40,40)); -} - -void tst_SimpleCanvasItem::test_scenePos() -{ - QFxView *canvas = createView(SRCDIR "/data/test.qml"); - canvas->execute(); - qApp->processEvents(); - QSimpleCanvasItem* root = qobject_cast<QSimpleCanvasItem*>(canvas->root()); - QVERIFY(root); - -#ifdef CANVAS_GL - QCOMPARE(root->transform(), QMatrix4x4()); -#else - QCOMPARE(root->transform(), QTransform()); -#endif - QCOMPARE(root->scenePos(), QPointF(0,0)); - QCOMPARE(root->children().at(0)->scenePos(), QPointF(20,20)); - QCOMPARE(root->children().at(0)->children().at(0)->scenePos(), QPointF(40,40)); - QCOMPARE(root->children().at(2)->scenePos(), QPointF(60,20)); - QCOMPARE(root->children().at(3)->scenePos(), QPointF(20,40)); - QCOMPARE(root->children().at(5)->scenePos(), QPointF(40,40)); -} - -QFxView *tst_SimpleCanvasItem::createView(const QString &filename) -{ - QFxView *canvas = new QFxView(0); - canvas->setFixedSize(240,320); - - QFile file(filename); - file.open(QFile::ReadOnly); - QString xml = file.readAll(); - canvas->setQml(xml, filename); - - return canvas; -} - -QTEST_MAIN(tst_SimpleCanvasItem) - -#include "tst_simplecanvasitem.moc" diff --git a/tests/auto/declarative/states/data/basicBinding.qml b/tests/auto/declarative/states/data/basicBinding.qml new file mode 100644 index 0000000..930a6b2 --- /dev/null +++ b/tests/auto/declarative/states/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/states/data/basicBinding2.qml b/tests/auto/declarative/states/data/basicBinding2.qml new file mode 100644 index 0000000..6bfaf5a --- /dev/null +++ b/tests/auto/declarative/states/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" } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicBinding3.qml b/tests/auto/declarative/states/data/basicBinding3.qml new file mode 100644 index 0000000..344bfae --- /dev/null +++ b/tests/auto/declarative/states/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 } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicBinding4.qml b/tests/auto/declarative/states/data/basicBinding4.qml new file mode 100644 index 0000000..f0b72bd --- /dev/null +++ b/tests/auto/declarative/states/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/states/data/basicChanges.qml b/tests/auto/declarative/states/data/basicChanges.qml new file mode 100644 index 0000000..8d560c6 --- /dev/null +++ b/tests/auto/declarative/states/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" } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicChanges2.qml b/tests/auto/declarative/states/data/basicChanges2.qml new file mode 100644 index 0000000..0f8783a --- /dev/null +++ b/tests/auto/declarative/states/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" } + }] +}
\ No newline at end of file diff --git a/tests/auto/declarative/states/data/basicChanges3.qml b/tests/auto/declarative/states/data/basicChanges3.qml new file mode 100644 index 0000000..2a5ca5d --- /dev/null +++ b/tests/auto/declarative/states/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/states/data/basicExtension.qml b/tests/auto/declarative/states/data/basicExtension.qml new file mode 100644 index 0000000..230e00b --- /dev/null +++ b/tests/auto/declarative/states/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 } + }] +}
\ No newline at end of file diff --git a/tests/auto/declarative/states/data/fakeExtension.qml b/tests/auto/declarative/states/data/fakeExtension.qml new file mode 100644 index 0000000..3d85c4f --- /dev/null +++ b/tests/auto/declarative/states/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" } + }] +}
\ No newline at end of file diff --git a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro b/tests/auto/declarative/states/states.pro index f4aea32..0474ea5 100644 --- a/tests/auto/declarative/simplecanvasitem/simplecanvasitem.pro +++ b/tests/auto/declarative/states/states.pro @@ -1,7 +1,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative -contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl -SOURCES += tst_simplecanvasitem.cpp +SOURCES += tst_states.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp new file mode 100644 index 0000000..3a61bd6 --- /dev/null +++ b/tests/auto/declarative/states/tst_states.cpp @@ -0,0 +1,267 @@ +#include <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qfxrect.h> + +class tst_states : public QObject +{ + Q_OBJECT +public: + tst_states() {} + +private slots: + void basicChanges(); + void basicExtension(); + void basicBinding(); +}; + +void tst_states::basicChanges() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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"); + QFxRect *rect = qobject_cast<QFxRect*>(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")); + } +} + +QTEST_MAIN(tst_states) + +#include "tst_states.moc" |