From 9a5dd525723363dc4230595c85f4406f27d5c0f2 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 17 Nov 2009 15:37:51 +1000 Subject: AnchorChanges test --- tests/auto/declarative/states/data/anchorChanges.qml | 1 + tests/auto/declarative/states/tst_states.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tests/auto/declarative/states/data/anchorChanges.qml b/tests/auto/declarative/states/data/anchorChanges.qml index bb17840..4afdee3 100644 --- a/tests/auto/declarative/states/data/anchorChanges.qml +++ b/tests/auto/declarative/states/data/anchorChanges.qml @@ -14,6 +14,7 @@ Rectangle { states: State { name: "right" AnchorChanges { + id: AncCh target: myRect; reset: "left" right: container.right diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index fe90191..0e0a72a 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -479,8 +479,12 @@ void tst_states::anchorChanges() QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); + QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); + rect->setState("right"); QCOMPARE(innerRect->x(), qreal(150)); + QCOMPARE(aChanges->reset(), QString("left")); rect->setState(""); QCOMPARE(innerRect->x(), qreal(5)); -- cgit v0.12 From 4e126f5222a3c62a46037c4ac40743f9f2ee9026 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 17 Nov 2009 16:13:06 +1000 Subject: tests --- src/declarative/qml/qmlvmemetaobject.cpp | 12 ++------ .../data/DynamicPropertiesNestedType.qml | 6 ++++ .../qmllanguage/data/dynamicProperties.qml | 1 + .../qmllanguage/data/dynamicPropertiesNested.qml | 9 ++++++ .../qmllanguage/data/dynamicSignalsAndSlots.qml | 3 ++ .../qmllanguage/data/listProperties.qml | 9 ++++++ .../declarative/qmllanguage/tst_qmllanguage.cpp | 34 ++++++++++++++++++++++ 7 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/DynamicPropertiesNestedType.qml create mode 100644 tests/auto/declarative/qmllanguage/data/dynamicPropertiesNested.qml create mode 100644 tests/auto/declarative/qmllanguage/data/listProperties.qml diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index ed28d78..3f5dd475 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -108,15 +108,7 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QPair pair = interceptors.value(id); int valueIndex = pair.first; QmlPropertyValueInterceptor *vi = pair.second; - QVariant::Type type = QVariant::Invalid; - if (id >= propOffset) { - id -= propOffset; - if (id < metaData->propertyCount) { - type = data[id].type(); - } - } else { - type = property(id).type(); - } + QVariant::Type type = property(id).type(); if (type != QVariant::Invalid) { if (valueIndex != -1) { @@ -129,6 +121,8 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) valueType->setValue(QVariant(type, a[0])); QMetaProperty valueProp = valueType->metaObject()->property(valueIndex); vi->write(valueProp.read(valueType)); + + if (!ep) delete valueType; return -1; } else { vi->write(QVariant(type, a[0])); 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 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() -- cgit v0.12 From 9e0d916e7102cd3451f57242d7ed13d0ab9cfe22 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 17 Nov 2009 16:38:34 +1000 Subject: Make compile, forgot to add some files --- tests/auto/declarative/shared/debugutil.cpp | 173 ++++++++++++++++++++++++++++ tests/auto/declarative/shared/debugutil_p.h | 142 +++++++++++++++++++++++ 2 files changed, 315 insertions(+) create mode 100644 tests/auto/declarative/shared/debugutil.cpp create mode 100644 tests/auto/declarative/shared/debugutil_p.h 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 +#include +#include + +#include +#include + +#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(); +} + +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 &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(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 +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + + +class QmlDebugTestData : public QObject +{ + Q_OBJECT +public: + QmlDebugTestData(QEventLoop *el); + + ~QmlDebugTestData(); + + QmlEngine *engine; + QmlDebugConnection *conn; + + int exitCode; + QEventLoop *loop; + + QList 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 &qml = QList()); +} + +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; +}; + + -- cgit v0.12 From 00ba769bd417ff005a5e9854bfcc5dbd0acd9848 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 17 Nov 2009 16:40:29 +1000 Subject: AnchorChanges autotests --- src/declarative/graphicsitems/qmlgraphicsitem.h | 17 +- .../auto/declarative/states/data/anchorChanges.qml | 4 +- .../declarative/states/data/anchorChanges2.qml | 4 +- .../declarative/states/data/anchorChanges3.qml | 28 ++-- .../declarative/states/data/anchorChanges4.qml | 22 +++ .../declarative/states/data/anchorChanges5.qml | 22 +++ tests/auto/declarative/states/tst_states.cpp | 183 +++++++++++++++------ 7 files changed, 207 insertions(+), 73 deletions(-) create mode 100644 tests/auto/declarative/states/data/anchorChanges4.qml create mode 100644 tests/auto/declarative/states/data/anchorChanges5.qml diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index 11d6e2e..d092896 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -157,6 +157,14 @@ public: bool keepMouseGrab() const; void setKeepMouseGrab(bool); + QmlGraphicsAnchorLine left() const; + QmlGraphicsAnchorLine right() const; + QmlGraphicsAnchorLine horizontalCenter() const; + QmlGraphicsAnchorLine top() const; + QmlGraphicsAnchorLine bottom() const; + QmlGraphicsAnchorLine verticalCenter() const; + QmlGraphicsAnchorLine baseline() const; + Q_SIGNALS: void widthChanged(); void heightChanged(); @@ -193,15 +201,6 @@ protected: QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent = 0); private: - // ### public? - QmlGraphicsAnchorLine left() const; - QmlGraphicsAnchorLine right() const; - QmlGraphicsAnchorLine horizontalCenter() const; - QmlGraphicsAnchorLine top() const; - QmlGraphicsAnchorLine bottom() const; - QmlGraphicsAnchorLine verticalCenter() const; - QmlGraphicsAnchorLine baseline() const; - friend class QmlStatePrivate; friend class QmlGraphicsAnchors; Q_DISABLE_COPY(QmlGraphicsItem) diff --git a/tests/auto/declarative/states/data/anchorChanges.qml b/tests/auto/declarative/states/data/anchorChanges.qml index 4afdee3..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 @@ -17,7 +17,7 @@ Rectangle { 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 1588d4c..671ca33 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -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,67 +476,153 @@ void tst_states::anchorChanges() { QmlEngine engine; - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); - QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); - QVERIFY(rect != 0); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); - QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); - QVERIFY(innerRect != 0); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); - QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); - QVERIFY(aChanges != 0); + QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QVERIFY(aChanges != 0); - rect->setState("right"); - QCOMPARE(innerRect->x(), qreal(150)); - QCOMPARE(aChanges->reset(), QString("left")); + 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); - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(5)); + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); - delete rect; - } + delete rect; +} - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); - QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); - QVERIFY(rect != 0); +void tst_states::anchorChanges2() +{ + QmlEngine engine; - QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); - QVERIFY(innerRect != 0); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); - rect->setState("right"); - QEXPECT_FAIL("", "QTBUG-5338", Continue); - QCOMPARE(innerRect->x(), qreal(150)); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(5)); + rect->setState("right"); + QEXPECT_FAIL("", "QTBUG-5338", Continue); + QCOMPARE(innerRect->x(), qreal(150)); - delete rect; - } + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); - { - QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); - QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); - QVERIFY(rect != 0); + delete rect; +} - QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); - QVERIFY(innerRect != 0); +void tst_states::anchorChanges3() +{ + QmlEngine engine; - rect->setState("reanchored"); - QCOMPARE(innerRect->x(), qreal(10)); - QCOMPARE(innerRect->y(), qreal(0)); - QCOMPARE(innerRect->width(), qreal(190)); - QCOMPARE(innerRect->height(), qreal(150)); + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges3.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); - rect->setState(""); - QCOMPARE(innerRect->x(), qreal(0)); - QCOMPARE(innerRect->y(), qreal(10)); - QCOMPARE(innerRect->width(), qreal(150)); - QCOMPARE(innerRect->height(), qreal(190)); + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); - delete rect; - } + QmlGraphicsItem *leftGuideline = qobject_cast(rect->findChild("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast(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(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast(rect->findChild("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast(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(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + QmlGraphicsItem *leftGuideline = qobject_cast(rect->findChild("LeftGuideline")); + QVERIFY(leftGuideline != 0); + + QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); + QVERIFY(bottomGuideline != 0); + + QmlAnchorChanges *aChanges = qobject_cast(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() -- cgit v0.12