diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-17 06:39:13 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-17 06:39:13 (GMT) |
commit | 10bfafde6e893b0ef9e747fb7c6bffcf11f5c112 (patch) | |
tree | 64f5a8c9ba5458489db8439295ae71af0b6346ea /tests | |
parent | b7fe8bdad08cc87130a131c657af4cdeaa6efa79 (diff) | |
parent | cee1c78e0def34a0c4303ce70dc8611fd775a912 (diff) | |
download | Qt-10bfafde6e893b0ef9e747fb7c6bffcf11f5c112.zip Qt-10bfafde6e893b0ef9e747fb7c6bffcf11f5c112.tar.gz Qt-10bfafde6e893b0ef9e747fb7c6bffcf11f5c112.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
14 files changed, 578 insertions, 61 deletions
diff --git a/tests/auto/declarative/qmllanguage/data/DynamicPropertiesNestedType.qml b/tests/auto/declarative/qmllanguage/data/DynamicPropertiesNestedType.qml new file mode 100644 index 0000000..5c2edb4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/DynamicPropertiesNestedType.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + property int super_a: 10 + property int super_c: 14 +} diff --git a/tests/auto/declarative/qmllanguage/data/dynamicProperties.qml b/tests/auto/declarative/qmllanguage/data/dynamicProperties.qml index f93e446..17fa974 100644 --- a/tests/auto/declarative/qmllanguage/data/dynamicProperties.qml +++ b/tests/auto/declarative/qmllanguage/data/dynamicProperties.qml @@ -7,6 +7,7 @@ Object { property real realProperty: -19.9 property string stringProperty: "Hello World!" property color colorProperty: "red" + property url urlProperty: "main.qml" property date dateProperty: "1945-09-02" property var varProperty: "Hello World!" property variant variantProperty: 12 diff --git a/tests/auto/declarative/qmllanguage/data/dynamicPropertiesNested.qml b/tests/auto/declarative/qmllanguage/data/dynamicPropertiesNested.qml new file mode 100644 index 0000000..7bfab67 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/dynamicPropertiesNested.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +DynamicPropertiesNestedType { + property int a: 13 + property int b: 12 + + super_a: 11 +} + diff --git a/tests/auto/declarative/qmllanguage/data/dynamicSignalsAndSlots.qml b/tests/auto/declarative/qmllanguage/data/dynamicSignalsAndSlots.qml index b0ca970..72ec218 100644 --- a/tests/auto/declarative/qmllanguage/data/dynamicSignalsAndSlots.qml +++ b/tests/auto/declarative/qmllanguage/data/dynamicSignalsAndSlots.qml @@ -4,4 +4,7 @@ Object { function slot1() {} signal signal2 function slot2() {} + + property int test: 0 + function slot3(a) { print(1921); test = a; } } diff --git a/tests/auto/declarative/qmllanguage/data/listProperties.qml b/tests/auto/declarative/qmllanguage/data/listProperties.qml new file mode 100644 index 0000000..c39ceae --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/listProperties.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Object { + property list<Object> listProperty + property int test: listProperty.length + + listProperty: [ Object{}, Object {} ] +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index d5c5c4d..892d2eb 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -91,6 +91,8 @@ private slots: void idProperty(); void assignSignal(); void dynamicProperties(); + void dynamicPropertiesNested(); + void listProperties(); void dynamicObjectProperties(); void dynamicSignalsAndSlots(); void simpleBindings(); @@ -554,12 +556,40 @@ void tst_qmllanguage::dynamicProperties() QCOMPARE(object->property("doubleProperty"), QVariant(-10.1)); QCOMPARE(object->property("realProperty"), QVariant((qreal)-19.9)); QCOMPARE(object->property("stringProperty"), QVariant("Hello World!")); + QCOMPARE(object->property("urlProperty"), QVariant(TEST_FILE("main.qml"))); QCOMPARE(object->property("colorProperty"), QVariant(QColor("red"))); QCOMPARE(object->property("dateProperty"), QVariant(QDate(1945, 9, 2))); QCOMPARE(object->property("varProperty"), QVariant("Hello World!")); QCOMPARE(object->property("variantProperty"), QVariant(12)); } +// Test that nested types can use dynamic properties +void tst_qmllanguage::dynamicPropertiesNested() +{ + QmlComponent component(&engine, TEST_FILE("dynamicPropertiesNested.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("super_a").toInt(), 11); // Overridden + QCOMPARE(object->property("super_c").toInt(), 14); // Inherited + QCOMPARE(object->property("a").toInt(), 13); // New + QCOMPARE(object->property("b").toInt(), 12); // New + + delete object; +} + +// Tests the creation and assignment to dynamic list properties +void tst_qmllanguage::listProperties() +{ + QmlComponent component(&engine, TEST_FILE("listProperties.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toInt(), 2); +} + // Tests the creation and assignment of dynamic object properties // ### Not complete void tst_qmllanguage::dynamicObjectProperties() @@ -584,6 +614,10 @@ void tst_qmllanguage::dynamicSignalsAndSlots() QVERIFY(object->metaObject()->indexOfMethod("signal2()") != -1); QVERIFY(object->metaObject()->indexOfMethod("slot1()") != -1); QVERIFY(object->metaObject()->indexOfMethod("slot2()") != -1); + + QCOMPARE(object->property("test").toInt(), 0); + QMetaObject::invokeMethod(object, "slot3", Qt::DirectConnection, Q_ARG(QVariant, QVariant(10))); + QCOMPARE(object->property("test").toInt(), 10); } void tst_qmllanguage::simpleBindings() diff --git a/tests/auto/declarative/shared/debugutil.cpp b/tests/auto/declarative/shared/debugutil.cpp new file mode 100644 index 0000000..7008529 --- /dev/null +++ b/tests/auto/declarative/shared/debugutil.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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 <QSignalSpy> +#include <QEventLoop> +#include <QTimer> + +#include <private/qmldebugclient_p.h> +#include <private/qmldebugservice_p.h> + +#include "debugutil_p.h" + +bool QmlDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { + QEventLoop loop; + QTimer timer; + QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + QObject::connect(receiver, member, &loop, SLOT(quit())); + timer.start(timeout); + loop.exec(); + return timer.isActive(); +} + + +QmlDebugTestData::QmlDebugTestData(QEventLoop *el) + : exitCode(-1), loop(el) +{ +} + +QmlDebugTestData::~QmlDebugTestData() +{ + qDeleteAll(items); +} + +void QmlDebugTestData::testsFinished(int code) +{ + exitCode = code; + loop->quit(); +} + + + +QmlDebugTestService::QmlDebugTestService(const QString &s, QObject *parent) + : QmlDebugService(s, parent), enabled(false) +{ +} + +void QmlDebugTestService::messageReceived(const QByteArray &ba) +{ + sendMessage(ba); +} + +void QmlDebugTestService::enabledChanged(bool e) +{ + emit enabledStateChanged(); + enabled = e; +} + + +QmlDebugTestClient::QmlDebugTestClient(const QString &s, QmlDebugConnection *c) + : QmlDebugClient(s, c) +{ +} + +QByteArray QmlDebugTestClient::waitForResponse() +{ + QSignalSpy spy(this, SIGNAL(serverMessage(QByteArray))); + QmlDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); + if (spy.count() == 0) { + qWarning() << "tst_QmlDebugClient: no response from server!"; + return QByteArray(); + } + return spy.at(0).at(0).value<QByteArray>(); +} + +void QmlDebugTestClient::messageReceived(const QByteArray &ba) +{ + emit serverMessage(ba); +} + + +tst_QmlDebug_Thread::tst_QmlDebug_Thread(QmlDebugTestData *data, QmlTestFactory *factory) + : m_ready(false), m_data(data), m_factory(factory) +{ +} + +void tst_QmlDebug_Thread::run() +{ + QTest::qWait(1000); + + QmlDebugConnection conn; + conn.connectToHost("127.0.0.1", 3768); + bool ok = conn.waitForConnected(5000); + Q_ASSERT(ok); + + while (!m_ready) + QTest::qWait(100); + + m_data->conn = &conn; + + Q_ASSERT(m_factory); + QObject *test = m_factory->createTest(m_data); + Q_ASSERT(test); + int code = QTest::qExec(test); + emit testsFinished(code); +} + + +int QmlDebugTest::runTests(QmlTestFactory *factory, const QList<QByteArray> &qml) +{ + qputenv("QML_DEBUG_SERVER_PORT", "3768"); + + QEventLoop loop; + QmlDebugTestData data(&loop); + + tst_QmlDebug_Thread thread(&data, factory); + QObject::connect(&thread, SIGNAL(testsFinished(int)), &data, SLOT(testsFinished(int))); + thread.start(); + + QmlEngine engine; // blocks until client connects + + foreach (const QByteArray &code, qml) { + QmlComponent c(&engine, code, QUrl("file://")); + Q_ASSERT(c.isReady()); // fails if bad syntax + data.items << qobject_cast<QmlGraphicsItem*>(c.create()); + } + + // start the test + data.engine = &engine; + thread.m_ready = true; + + loop.exec(); + + return data.exitCode; +} + + diff --git a/tests/auto/declarative/shared/debugutil_p.h b/tests/auto/declarative/shared/debugutil_p.h new file mode 100644 index 0000000..665aeda --- /dev/null +++ b/tests/auto/declarative/shared/debugutil_p.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 <QSignalSpy> +#include <QEventLoop> +#include <QPointer> +#include <QTimer> +#include <QThread> +#include <QTest> + +#include <QtDeclarative/qmlengine.h> + +#include <private/qmldebugclient_p.h> +#include <private/qmldebugservice_p.h> +#include <private/qmlgraphicsitem_p.h> + + +class QmlDebugTestData : public QObject +{ + Q_OBJECT +public: + QmlDebugTestData(QEventLoop *el); + + ~QmlDebugTestData(); + + QmlEngine *engine; + QmlDebugConnection *conn; + + int exitCode; + QEventLoop *loop; + + QList<QmlGraphicsItem *> items; + +public slots: + void testsFinished(int code); +}; + + +class QmlTestFactory +{ +public: + QmlTestFactory() {} + virtual ~QmlTestFactory() {} + + virtual QObject *createTest(QmlDebugTestData *data) = 0; +}; + + +namespace QmlDebugTest { + + bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); + + int runTests(QmlTestFactory *factory, const QList<QByteArray> &qml = QList<QByteArray>()); +} + +class QmlDebugTestService : public QmlDebugService +{ + Q_OBJECT +public: + QmlDebugTestService(const QString &s, QObject *parent = 0); + bool enabled; + +signals: + void enabledStateChanged(); + +protected: + virtual void messageReceived(const QByteArray &ba); + + virtual void enabledChanged(bool e); +}; + +class QmlDebugTestClient : public QmlDebugClient +{ + Q_OBJECT +public: + QmlDebugTestClient(const QString &s, QmlDebugConnection *c); + + QByteArray waitForResponse(); + +signals: + void serverMessage(const QByteArray &); + +protected: + virtual void messageReceived(const QByteArray &ba); +}; + +class tst_QmlDebug_Thread : public QThread +{ + Q_OBJECT +public: + tst_QmlDebug_Thread(QmlDebugTestData *data, QmlTestFactory *factory); + + void run(); + + bool m_ready; + +signals: + void testsFinished(int); + +private: + QmlDebugTestData *m_data; + QmlTestFactory *m_factory; +}; + + diff --git a/tests/auto/declarative/states/data/anchorChanges.qml b/tests/auto/declarative/states/data/anchorChanges.qml index bb17840..3d94f36 100644 --- a/tests/auto/declarative/states/data/anchorChanges.qml +++ b/tests/auto/declarative/states/data/anchorChanges.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rectangle { - id: container + id: Container width: 200; height: 200 Rectangle { id: myRect @@ -14,9 +14,10 @@ Rectangle { states: State { name: "right" AnchorChanges { + id: AncCh target: myRect; reset: "left" - right: container.right + right: Container.right } } } diff --git a/tests/auto/declarative/states/data/anchorChanges2.qml b/tests/auto/declarative/states/data/anchorChanges2.qml index 545345e..2e13628 100644 --- a/tests/auto/declarative/states/data/anchorChanges2.qml +++ b/tests/auto/declarative/states/data/anchorChanges2.qml @@ -3,7 +3,7 @@ import Qt 4.6 Rectangle { width: 200; height: 200 Rectangle { - id: myRect + id: MyRect objectName: "MyRect" width: 50; height: 50 color: "green"; @@ -13,7 +13,7 @@ Rectangle { states: State { name: "right" AnchorChanges { - target: myRect; + target: MyRect; reset: "left" right: parent.right } diff --git a/tests/auto/declarative/states/data/anchorChanges3.qml b/tests/auto/declarative/states/data/anchorChanges3.qml index 8a74595..cf85472 100644 --- a/tests/auto/declarative/states/data/anchorChanges3.qml +++ b/tests/auto/declarative/states/data/anchorChanges3.qml @@ -1,29 +1,29 @@ import Qt 4.6 Rectangle { - id: container + id: Container width: 200; height: 200 Rectangle { - id: myRect + id: MyRect objectName: "MyRect" color: "green"; anchors.left: parent.left - anchors.right: rightGuideline.left - anchors.top: topGuideline.top - anchors.bottom: container.bottom + anchors.right: RightGuideline.left + anchors.top: TopGuideline.top + anchors.bottom: Container.bottom } - Item { id: leftGuideline; x: 10 } - Item { id: rightGuideline; x: 150 } - Item { id: topGuideline; y: 10 } - Item { id: bottomGuideline; y: 150 } + Item { objectName: "LeftGuideline"; id: LeftGuideline; x: 10 } + Item { id: RightGuideline; x: 150 } + Item { id: TopGuideline; y: 10 } + Item { objectName: "BottomGuideline"; id: BottomGuideline; y: 150 } states: State { name: "reanchored" AnchorChanges { - target: myRect; - left: leftGuideline.left - right: container.right - top: container.top - bottom: bottomGuideline.bottom + target: MyRect; + left: LeftGuideline.left + right: Container.right + top: Container.top + bottom: BottomGuideline.bottom } } } diff --git a/tests/auto/declarative/states/data/anchorChanges4.qml b/tests/auto/declarative/states/data/anchorChanges4.qml new file mode 100644 index 0000000..717f506 --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges4.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: MyRect + objectName: "MyRect" + color: "green"; + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + } + Item { objectName: "LeftGuideline"; id: LeftGuideline; x: 10 } + Item { objectName: "BottomGuideline"; id: BottomGuideline; y: 150 } + states: State { + name: "reanchored" + AnchorChanges { + target: MyRect; + horizontalCenter: BottomGuideline.horizontalCenter + verticalCenter: LeftGuideline.verticalCenter + } + } +} diff --git a/tests/auto/declarative/states/data/anchorChanges5.qml b/tests/auto/declarative/states/data/anchorChanges5.qml new file mode 100644 index 0000000..ef5f041 --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges5.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: MyRect + objectName: "MyRect" + color: "green"; + anchors.horizontalCenter: parent.horizontalCenter + anchors.baseline: parent.baseline + } + Item { objectName: "LeftGuideline"; id: LeftGuideline; x: 10 } + Item { objectName: "BottomGuideline"; id: BottomGuideline; y: 150 } + states: State { + name: "reanchored" + AnchorChanges { + target: MyRect; + horizontalCenter: BottomGuideline.horizontalCenter + baseline: LeftGuideline.baseline + } + } +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 4f8b9c2..671ca33 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -41,6 +41,7 @@ #include <qtest.h> #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> +#include <private/qmlgraphicsanchors_p_p.h> #include <private/qmlgraphicsrectangle_p.h> #include <private/qmlpropertychanges_p.h> @@ -59,6 +60,10 @@ private slots: void parentChange(); void parentChangeErrors(); void anchorChanges(); + void anchorChanges2(); + void anchorChanges3(); + void anchorChanges4(); + void anchorChanges5(); void script(); void restoreEntryValues(); void explicitChanges(); @@ -471,63 +476,153 @@ void tst_states::anchorChanges() { QmlEngine engine; - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); - QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); - QVERIFY(rect != 0); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); - QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); - QVERIFY(innerRect != 0); + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); - rect->setState("right"); - QCOMPARE(innerRect->x(), qreal(150)); + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(5)); + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + QCOMPARE(aChanges->reset(), QString("left")); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->right().item, rect->right().item); + QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); - delete rect; - } + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); - QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); - QVERIFY(rect != 0); + delete rect; +} - QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); - QVERIFY(innerRect != 0); +void tst_states::anchorChanges2() +{ + QmlEngine engine; - rect->setState("right"); - QEXPECT_FAIL("", "QTBUG-5338", Continue); - QCOMPARE(innerRect->x(), qreal(150)); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(5)); + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); - delete rect; - } + rect->setState("right"); + QEXPECT_FAIL("", "QTBUG-5338", Continue); + QCOMPARE(innerRect->x(), qreal(150)); - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); - QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); - QVERIFY(rect != 0); + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); - QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); - QVERIFY(innerRect != 0); + delete rect; +} - rect->setState("reanchored"); - QCOMPARE(innerRect->x(), qreal(10)); - QCOMPARE(innerRect->y(), qreal(0)); - QCOMPARE(innerRect->width(), qreal(190)); - QCOMPARE(innerRect->height(), qreal(150)); +void tst_states::anchorChanges3() +{ + QmlEngine engine; - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(0)); - QCOMPARE(innerRect->y(), qreal(10)); - QCOMPARE(innerRect->width(), qreal(150)); - QCOMPARE(innerRect->height(), qreal(190)); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); - delete rect; - } + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->left().item, leftGuideline->left().item); + QCOMPARE(aChanges->left().anchorLine, leftGuideline->left().anchorLine); + QCOMPARE(aChanges->right().item, rect->right().item); + QCOMPARE(aChanges->right().anchorLine, rect->right().anchorLine); + QCOMPARE(aChanges->top().item, rect->top().item); + QCOMPARE(aChanges->top().anchorLine, rect->top().anchorLine); + QCOMPARE(aChanges->bottom().item, bottomGuideline->bottom().item); + QCOMPARE(aChanges->bottom().anchorLine, bottomGuideline->bottom().anchorLine); + + QCOMPARE(innerRect->x(), qreal(10)); + QCOMPARE(innerRect->y(), qreal(0)); + QCOMPARE(innerRect->width(), qreal(190)); + QCOMPARE(innerRect->height(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(0)); + QCOMPARE(innerRect->y(), qreal(10)); + QCOMPARE(innerRect->width(), qreal(150)); + QCOMPARE(innerRect->height(), qreal(190)); + + delete rect; +} + +void tst_states::anchorChanges4() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges4.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->verticalCenter().item, leftGuideline->verticalCenter().item); + QCOMPARE(aChanges->verticalCenter().anchorLine, leftGuideline->verticalCenter().anchorLine); + + delete rect; +} + +void tst_states::anchorChanges5() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges5.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast<QmlGraphicsItem*>(rect->findChild<QmlGraphicsItem*>("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast<QmlAnchorChanges*>(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + + rect->setState("reanchored"); + QCOMPARE(aChanges->object(), innerRect); + QCOMPARE(aChanges->horizontalCenter().item, bottomGuideline->horizontalCenter().item); + QCOMPARE(aChanges->horizontalCenter().anchorLine, bottomGuideline->horizontalCenter().anchorLine); + QCOMPARE(aChanges->baseline().item, leftGuideline->baseline().item); + QCOMPARE(aChanges->baseline().anchorLine, leftGuideline->baseline().anchorLine); + + delete rect; } void tst_states::script() |