diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-05-19 04:45:49 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-05-19 04:45:49 (GMT) |
commit | f9aa68b172ddcaa63e5a1bc4d91649d0734d3b15 (patch) | |
tree | e5835bd78f8b9415918a016c642de778ec445e46 /tests/auto/declarative/anchors | |
parent | b176adc2665ef4b94f30ba5fd8d85a5913b0bbbb (diff) | |
download | Qt-f9aa68b172ddcaa63e5a1bc4d91649d0734d3b15.zip Qt-f9aa68b172ddcaa63e5a1bc4d91649d0734d3b15.tar.gz Qt-f9aa68b172ddcaa63e5a1bc4d91649d0734d3b15.tar.bz2 |
Add a basic anchoring autotest.
Diffstat (limited to 'tests/auto/declarative/anchors')
-rw-r--r-- | tests/auto/declarative/anchors/data/anchors.qml | 115 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/tst_anchors.cpp | 75 |
2 files changed, 188 insertions, 2 deletions
diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml new file mode 100644 index 0000000..6a87390 --- /dev/null +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -0,0 +1,115 @@ +Rect { + color: "white" + width: 240 + height: 320 + Rect { id: MasterRect; x: 26; width: 96; height: 20; color: "red" } + Rect { + id: Rect1 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.left + } + Rect { + id: Rect2 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.right + } + Rect { + id: Rect3 + y: 20; width: 10; height: 10 + anchors.left: MasterRect.horizontalCenter + } + Rect { + id: Rect4 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.left + } + Rect { + id: Rect5 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.right + } + Rect { + id: Rect6 + y: 30; width: 10; height: 10 + anchors.right: MasterRect.horizontalCenter + } + Rect { + id: Rect7 + y: 50; width: 10; height: 10 + anchors.left: parent.left + } + Rect { + id: Rect8 + y: 50; width: 10; height: 10 + anchors.left: parent.right + } + Rect { + id: Rect9 + y: 50; width: 10; height: 10 + anchors.left: parent.horizontalCenter + } + Rect { + id: Rect10 + y: 60; width: 10; height: 10 + anchors.right: parent.left + } + Rect { + id: Rect11 + y: 60; width: 10; height: 10 + anchors.right: parent.right + } + Rect { + id: Rect12 + y: 60; width: 10; height: 10 + anchors.right: parent.horizontalCenter + } + Rect { + id: Rect13 + x: 200; width: 10; height: 10 + anchors.top: MasterRect.bottom + } + Rect { + id: Rect14 + width: 10; height: 10; color: "steelblue" + anchors.verticalCenter: parent.verticalCenter + } + Rect { + id: Rect15 + y: 200; height: 10 + anchors.left: MasterRect.left + anchors.right: MasterRect.right + } + Rect { + id: Rect16 + y: 220; height: 10 + anchors.left: MasterRect.left + anchors.horizontalCenter: MasterRect.right + } + Rect { + id: Rect17 + y: 240; height: 10 + anchors.right: MasterRect.right + anchors.horizontalCenter: MasterRect.left + } + Rect { + id: Rect18 + x: 180; width: 10 + anchors.top: MasterRect.bottom + anchors.bottom: Rect12.top + } + Rect { + id: Rect19 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.horizontalCenter + } + Rect { + id: Rect20 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.right + } + Rect { + id: Rect21 + y: 70; width: 10; height: 10 + anchors.horizontalCenter: parent.left + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 683a7b9..8087d6e 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -2,8 +2,7 @@ #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qfxview.h> -#include <QtDeclarative/qfximage.h> -#include <QtDeclarative/qfxtext.h> +#include <QtDeclarative/qfxrect.h> class tst_anchors : public QObject { @@ -11,10 +10,82 @@ class tst_anchors : public QObject public: tst_anchors() {} + template<typename T> + T *findItem(QFxItem *parent, const QString &id); + private slots: + void basicAnchors(); void loops(); }; +/* + Find an item with the specified id. +*/ +template<typename T> +T *tst_anchors::findItem(QFxItem *parent, const QString &id) +{ + const QMetaObject &mo = T::staticMetaObject; + for (int i = 0; i < parent->QSimpleCanvasItem::children().count(); ++i) { + QFxItem *item = qobject_cast<QFxItem*>(parent->QSimpleCanvasItem::children().at(i)); + if (mo.cast(item) && (id.isEmpty() || item->id() == id)) { + return static_cast<T*>(item); + } + item = findItem<T>(item, id); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + +void tst_anchors::basicAnchors() +{ + QFxView *view = new QFxView; + view->setUrl(QUrl("file://" SRCDIR "/data/anchors.qml")); + + view->execute(); + qApp->processEvents(); + + //sibling horizontal + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect1"))->x(), 26.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect2"))->x(), 122.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect3"))->x(), 74.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect4"))->x(), 16.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect5"))->x(), 112.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect6"))->x(), 64.0); + + //parent horizontal + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect7"))->x(), 0.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect8"))->x(), 240.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect9"))->x(), 120.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect10"))->x(), -10.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect11"))->x(), 230.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect12"))->x(), 110.0); + + //vertical + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect13"))->y(), 20.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect14"))->y(), 155.0); + + //stretch + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect15"))->x(), 26.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect15"))->width(), 96.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect16"))->x(), 26.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect16"))->width(), 192.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect17"))->x(), -70.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect17"))->width(), 192.0); + + //vertical stretch + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect18"))->y(), 20.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect18"))->height(), 40.0); + + //more parent horizontal + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect19"))->x(), 115.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect20"))->x(), 235.0); + QCOMPARE(findItem<QFxRect>(view->root(), QLatin1String("Rect21"))->x(), -5.0); + + delete view; +} + // mostly testing that we don't crash void tst_anchors::loops() { |