diff options
15 files changed, 562 insertions, 383 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 000ceb3..da46456 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -26,6 +26,7 @@ SUBDIRS += \ qmlgraphicsitem \ # Cover qmlgraphicsborderimage \ # Cover qmlgraphicsparticles \ # Cover + qmlgraphicspositioners \ # Cover qmlgraphicstext \ # Cover qmlgraphicswebview \ # Cover qmlinfo \ # Cover diff --git a/tests/auto/declarative/layouts/data/layouts.qml b/tests/auto/declarative/layouts/data/layouts.qml new file mode 100644 index 0000000..ccc8cfe --- /dev/null +++ b/tests/auto/declarative/layouts/data/layouts.qml @@ -0,0 +1,34 @@ +import Qt 4.6 + +Item { + id: resizable + width:300 + height:300 + + GraphicsObjectContainer { + anchors.fill:parent + + QGraphicsWidget { + size.width:parent.width + size.height:parent.height + + layout: QGraphicsLinearLayout { + spacing: 0 + LayoutItem { + objectName: "left" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { objectName: "yellowRect"; color: "yellow"; anchors.fill: parent } + } + LayoutItem { + objectName: "right" + minimumSize: "100x100" + maximumSize: "400x400" + preferredSize: "200x200" + Rectangle { objectName: "greenRect"; color: "green"; anchors.fill: parent } + } + } + } + } +} diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index c0c067a..f619b57 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -41,7 +41,7 @@ #include <QtTest/QtTest> #include <private/qlistmodelinterface_p.h> #include <qmlview.h> -#include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlgraphicslayoutitem_p.h> #include <qmlexpression.h> class tst_QmlGraphicsLayouts : public QObject @@ -51,17 +51,9 @@ public: tst_QmlGraphicsLayouts(); private slots: - void test_horizontal(); - void test_horizontal_spacing(); - void test_horizontal_animated(); - void test_vertical(); - void test_vertical_spacing(); - void test_vertical_animated(); - void test_grid(); - void test_grid_spacing(); - void test_grid_animated(); + void test_qml();//GraphicsLayout set up in Qml + void test_cpp();//GraphicsLayout set up in C++ - void test_repeater(); private: QmlView *createView(const QString &filename); }; @@ -70,385 +62,61 @@ tst_QmlGraphicsLayouts::tst_QmlGraphicsLayouts() { } -void tst_QmlGraphicsLayouts::test_horizontal() +void tst_QmlGraphicsLayouts::test_qml() { - QmlView *canvas = createView(SRCDIR "/data/horizontal.qml"); + QmlView *canvas = createView(SRCDIR "/data/layouts.qml"); canvas->execute(); qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 70.0); - QCOMPARE(three->y(), 0.0); + QmlGraphicsLayoutItem *left = qobject_cast<QmlGraphicsLayoutItem*>(canvas->root()->findChild<QmlGraphicsItem*>("left")); + QVERIFY(left != 0); + + QmlGraphicsLayoutItem *right = qobject_cast<QmlGraphicsLayoutItem*>(canvas->root()->findChild<QmlGraphicsItem*>("right")); + QVERIFY(right != 0); + + qreal gvMargin = 9.0; + //Preferred Size + canvas->root()->setWidth(300 + 2*gvMargin); + canvas->root()->setHeight(300 + 2*gvMargin); + + QCOMPARE(left->x(), gvMargin); + QCOMPARE(left->y(), gvMargin); + QCOMPARE(left->width(), 100.0); + QCOMPARE(left->height(), 300.0); + + QCOMPARE(right->x(), 100.0 + gvMargin); + QCOMPARE(right->y(), 0.0 + gvMargin); + QCOMPARE(right->width(), 200.0); + QCOMPARE(right->height(), 300.0); + + //Minimum Size + canvas->root()->setWidth(10+2*gvMargin); + canvas->root()->setHeight(10+2*gvMargin); + + QCOMPARE(left->x(), gvMargin); + QCOMPARE(left->width(), 100.0); + QCOMPARE(left->height(), 100.0); + + QCOMPARE(right->x(), 100.0 + gvMargin); + QCOMPARE(right->width(), 100.0); + QCOMPARE(right->height(), 100.0); + + //Maximum Size + canvas->root()->setWidth(1000 + 2*gvMargin); + canvas->root()->setHeight(1000 + 2*gvMargin); + + QCOMPARE(left->x(), gvMargin); + QCOMPARE(left->width(), 300.0); + QCOMPARE(left->height(), 300.0); + + QCOMPARE(right->x(), 300.0 + gvMargin); + QCOMPARE(right->width(), 400.0); + QCOMPARE(right->height(), 400.0); } -void tst_QmlGraphicsLayouts::test_horizontal_spacing() +void tst_QmlGraphicsLayouts::test_cpp() { - QmlView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 60.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 90.0); - QCOMPARE(three->y(), 0.0); -} - -void tst_QmlGraphicsLayouts::test_horizontal_animated() -{ - QmlView *canvas = createView(SRCDIR "/data/horizontal-animated.qml"); - - canvas->execute(); - qApp->processEvents(); - - QTest::qWait(0);//Let the animation start - //Note that one and three animate in - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - QCOMPARE(one->x(), -100.0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - QCOMPARE(two->x(), 0.0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - QCOMPARE(three->x(), -100.0); - - QTest::qWait(300);//Let the animation complete - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 50.0); - QCOMPARE(three->y(), 0.0); - - //Add 'two' - two->setOpacity(1.0); - QCOMPARE(two->opacity(), 1.0); - QTest::qWait(0);//Let the animation start - QCOMPARE(two->x(), -100.0); - QCOMPARE(three->x(), 50.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(three->x(), 100.0); - - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(three->x(), 100.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(three->x(), 50.0); -} - -void tst_QmlGraphicsLayouts::test_vertical() -{ - QmlView *canvas = createView(SRCDIR "/data/vertical.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->x(), 0.0); - QCOMPARE(three->y(), 60.0); -} - -void tst_QmlGraphicsLayouts::test_vertical_spacing() -{ - QmlView *canvas = createView(SRCDIR "/data/vertical-spacing.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(two->y(), 60.0); - QCOMPARE(three->x(), 0.0); - QCOMPARE(three->y(), 80.0); -} - -void tst_QmlGraphicsLayouts::test_vertical_animated() -{ - QmlView *canvas = createView(SRCDIR "/data/vertical-animated.qml"); - - canvas->execute(); - qApp->processEvents(); - - QTest::qWait(0);//Let the animation start - //Note that one and three animate in - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - QCOMPARE(one->y(), -100.0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - QCOMPARE(two->y(), 0.0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - QCOMPARE(three->y(), -100.0); - - QTest::qWait(300);//Let the animation complete - - QCOMPARE(one->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(three->y(), 50.0); - QCOMPARE(three->x(), 0.0); - - //Add 'two' - two->setOpacity(1.0); - QCOMPARE(two->opacity(), 1.0); - QTest::qWait(0);//Let the animation start - QCOMPARE(two->y(), -100.0); - QCOMPARE(three->y(), 50.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->y(), 100.0); - - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->y(), 100.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->y(), 50.0); -} - -void tst_QmlGraphicsLayouts::test_grid() -{ - QmlView *canvas = createView("data/grid.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); - QVERIFY(four != 0); - QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); - QVERIFY(five != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 70.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 0.0); - QCOMPARE(four->y(), 50.0); - QCOMPARE(five->x(), 50.0); - QCOMPARE(five->y(), 50.0); -} - -void tst_QmlGraphicsLayouts::test_grid_spacing() -{ - QmlView *canvas = createView("data/grid-spacing.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); - QVERIFY(four != 0); - QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); - QVERIFY(five != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 54.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 78.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 0.0); - QCOMPARE(four->y(), 54.0); - QCOMPARE(five->x(), 54.0); - QCOMPARE(five->y(), 54.0); -} - -void tst_QmlGraphicsLayouts::test_grid_animated() -{ - QmlView *canvas = createView(SRCDIR "/data/grid-animated.qml"); - canvas->execute(); - qApp->processEvents(); - - QTest::qWait(0);//Let the animation start - //Note that all but two animate in - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - QCOMPARE(one->x(), -100.0); - QCOMPARE(one->y(), -100.0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(two->y(), 0.0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - QCOMPARE(three->x(), -100.0); - QCOMPARE(three->y(), -100.0); - - QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); - QVERIFY(four != 0); - QCOMPARE(four->x(), -100.0); - QCOMPARE(four->y(), -100.0); - - QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); - QVERIFY(five != 0); - QCOMPARE(five->x(), -100.0); - QCOMPARE(five->y(), -100.0); - - QTest::qWait(300);//Let the animation complete - - QCOMPARE(one->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(three->x(), 50.0); - QCOMPARE(four->y(), 0.0); - QCOMPARE(four->x(), 100.0); - QCOMPARE(five->y(), 50.0); - QCOMPARE(five->x(), 0.0); - - //Add 'two' - two->setOpacity(1.0); - QCOMPARE(two->opacity(), 1.0); - QTest::qWait(0);//Let the animation start - QCOMPARE(two->x(), -100.0); - QCOMPARE(two->y(), -100.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 50.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 100.0); - QCOMPARE(four->y(), 0.0); - QCOMPARE(five->x(), 0.0); - QCOMPARE(five->y(), 50.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 100.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 0.0); - QCOMPARE(four->y(), 50.0); - QCOMPARE(five->x(), 50.0); - QCOMPARE(five->y(), 50.0); - - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 100.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 0.0); - QCOMPARE(four->y(), 50.0); - QCOMPARE(five->x(), 50.0); - QCOMPARE(five->y(), 50.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 50.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 100.0); - QCOMPARE(four->y(), 0.0); - QCOMPARE(five->x(), 0.0); - QCOMPARE(five->y(), 50.0); -} - -void tst_QmlGraphicsLayouts::test_repeater() -{ - QmlView *canvas = createView("data/repeater.qml"); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); - QVERIFY(one != 0); - - QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); - QVERIFY(two != 0); - - QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); - QVERIFY(three != 0); - - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 100.0); - QCOMPARE(three->y(), 0.0); + //TODO: Waiting on QT-2407 to write this test } QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename) diff --git a/tests/auto/declarative/layouts/data/grid-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml index 6b128ce..6b128ce 100644 --- a/tests/auto/declarative/layouts/data/grid-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml diff --git a/tests/auto/declarative/layouts/data/grid-spacing.qml b/tests/auto/declarative/qmlgraphicspositioners/data/grid-spacing.qml index 5b4a30d..5b4a30d 100644 --- a/tests/auto/declarative/layouts/data/grid-spacing.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/grid-spacing.qml diff --git a/tests/auto/declarative/layouts/data/grid.qml b/tests/auto/declarative/qmlgraphicspositioners/data/grid.qml index 830df6a..830df6a 100644 --- a/tests/auto/declarative/layouts/data/grid.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/grid.qml diff --git a/tests/auto/declarative/layouts/data/horizontal-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml index c29d6df..c29d6df 100644 --- a/tests/auto/declarative/layouts/data/horizontal-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml diff --git a/tests/auto/declarative/layouts/data/horizontal-spacing.qml b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-spacing.qml index 32bf775..32bf775 100644 --- a/tests/auto/declarative/layouts/data/horizontal-spacing.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-spacing.qml diff --git a/tests/auto/declarative/layouts/data/horizontal.qml b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal.qml index 06ae151..06ae151 100644 --- a/tests/auto/declarative/layouts/data/horizontal.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal.qml diff --git a/tests/auto/declarative/layouts/data/repeater.qml b/tests/auto/declarative/qmlgraphicspositioners/data/repeater.qml index 2bc5e94..2bc5e94 100644 --- a/tests/auto/declarative/layouts/data/repeater.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/repeater.qml diff --git a/tests/auto/declarative/layouts/data/vertical-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml index fcbc5f7..fcbc5f7 100644 --- a/tests/auto/declarative/layouts/data/vertical-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml diff --git a/tests/auto/declarative/layouts/data/vertical-spacing.qml b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-spacing.qml index 69a8256..69a8256 100644 --- a/tests/auto/declarative/layouts/data/vertical-spacing.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-spacing.qml diff --git a/tests/auto/declarative/layouts/data/vertical.qml b/tests/auto/declarative/qmlgraphicspositioners/data/vertical.qml index 856c180..856c180 100644 --- a/tests/auto/declarative/layouts/data/vertical.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/vertical.qml diff --git a/tests/auto/declarative/qmlgraphicspositioners/qmlgraphicspositioners.pro b/tests/auto/declarative/qmlgraphicspositioners/qmlgraphicspositioners.pro new file mode 100644 index 0000000..d151026 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspositioners/qmlgraphicspositioners.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlgraphicspositioners.cpp +macx:CONFIG -= app_bundle + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp new file mode 100644 index 0000000..aca3579 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -0,0 +1,469 @@ +/**************************************************************************** +** +** 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 <QtTest/QtTest> +#include <private/qlistmodelinterface_p.h> +#include <qmlview.h> +#include <private/qmlgraphicsrectangle_p.h> +#include <qmlexpression.h> + +class tst_QmlGraphicsPositioners : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsPositioners(); + +private slots: + void test_horizontal(); + void test_horizontal_spacing(); + void test_horizontal_animated(); + void test_vertical(); + void test_vertical_spacing(); + void test_vertical_animated(); + void test_grid(); + void test_grid_spacing(); + void test_grid_animated(); + + void test_repeater(); +private: + QmlView *createView(const QString &filename); +}; + +tst_QmlGraphicsPositioners::tst_QmlGraphicsPositioners() +{ +} + +void tst_QmlGraphicsPositioners::test_horizontal() +{ + QmlView *canvas = createView(SRCDIR "/data/horizontal.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); +} + +void tst_QmlGraphicsPositioners::test_horizontal_spacing() +{ + QmlView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 60.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 90.0); + QCOMPARE(three->y(), 0.0); +} + +void tst_QmlGraphicsPositioners::test_horizontal_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/horizontal-animated.qml"); + + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that one and three animate in + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 100.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 100.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(three->x(), 50.0); +} + +void tst_QmlGraphicsPositioners::test_vertical() +{ + QmlView *canvas = createView(SRCDIR "/data/vertical.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); +} + +void tst_QmlGraphicsPositioners::test_vertical_spacing() +{ + QmlView *canvas = createView(SRCDIR "/data/vertical-spacing.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 60.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 80.0); +} + +void tst_QmlGraphicsPositioners::test_vertical_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/vertical-animated.qml"); + + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that one and three animate in + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->y(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->y(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->y(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(three->x(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->y(), -100.0); + QCOMPARE(three->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 100.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 100.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->y(), 50.0); +} + +void tst_QmlGraphicsPositioners::test_grid() +{ + QmlView *canvas = createView("data/grid.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); + QVERIFY(four != 0); + QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); +} + +void tst_QmlGraphicsPositioners::test_grid_spacing() +{ + QmlView *canvas = createView("data/grid-spacing.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); + QVERIFY(four != 0); + QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 54.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 78.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 54.0); + QCOMPARE(five->x(), 54.0); + QCOMPARE(five->y(), 54.0); +} + +void tst_QmlGraphicsPositioners::test_grid_animated() +{ + QmlView *canvas = createView(SRCDIR "/data/grid-animated.qml"); + canvas->execute(); + qApp->processEvents(); + + QTest::qWait(0);//Let the animation start + //Note that all but two animate in + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 0.0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QTest::qWait(300);//Let the animation complete + + QCOMPARE(one->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(five->y(), 50.0); + QCOMPARE(five->x(), 0.0); + + //Add 'two' + two->setOpacity(1.0); + QCOMPARE(two->opacity(), 1.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 0.0); + QCOMPARE(five->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + + //Remove 'two' + two->setOpacity(0.0); + QCOMPARE(two->opacity(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + QTest::qWait(300);//Let the animation complete + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 0.0); + QCOMPARE(five->y(), 50.0); +} + +void tst_QmlGraphicsPositioners::test_repeater() +{ + QmlView *canvas = createView("data/repeater.qml"); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one"); + QVERIFY(one != 0); + + QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two"); + QVERIFY(two != 0); + + QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 100.0); + QCOMPARE(three->y(), 0.0); +} + +QmlView *tst_QmlGraphicsPositioners::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString xml = file.readAll(); + canvas->setQml(xml, filename); + + return canvas; +} + + +QTEST_MAIN(tst_QmlGraphicsPositioners) + +#include "tst_qmlgraphicspositioners.moc" |