diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-10 07:32:50 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-10 07:32:50 (GMT) |
commit | 0a276390bb1c7e27bdaebb6d4eb22ab992c88aad (patch) | |
tree | 41cf76412e679ac3ba77b60a43bb403042894f48 /tests/auto/declarative | |
parent | 08b3d0ae11392528af3c39766023ffd2d116eb6b (diff) | |
parent | bbc3cc762e98a551dbbe9bd6923194e39d9c0c20 (diff) | |
download | Qt-0a276390bb1c7e27bdaebb6d4eb22ab992c88aad.zip Qt-0a276390bb1c7e27bdaebb6d4eb22ab992c88aad.tar.gz Qt-0a276390bb1c7e27bdaebb6d4eb22ab992c88aad.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests/auto/declarative')
26 files changed, 1009 insertions, 146 deletions
diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml index 765e5b6..b3fba30 100644 --- a/tests/auto/declarative/anchors/data/anchors.qml +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -4,130 +4,130 @@ Rectangle { color: "white" width: 240 height: 320 - Rectangle { id: MasterRect; objectName: "MasterRect"; x: 26; width: 96; height: 20; color: "red" } + Rectangle { id: masterRect; objectName: "masterRect"; x: 26; width: 96; height: 20; color: "red" } Rectangle { - id: Rect1; objectName: "Rect1" + id: rect1; objectName: "rect1" y: 20; width: 10; height: 10 - anchors.left: MasterRect.left + anchors.left: masterRect.left } Rectangle { - id: Rect2; objectName: "Rect2" + id: rect2; objectName: "rect2" y: 20; width: 10; height: 10 - anchors.left: MasterRect.right + anchors.left: masterRect.right } Rectangle { - id: Rect3; objectName: "Rect3" + id: rect3; objectName: "rect3" y: 20; width: 10; height: 10 - anchors.left: MasterRect.horizontalCenter + anchors.left: masterRect.horizontalCenter } Rectangle { - id: Rect4; objectName: "Rect4" + id: rect4; objectName: "rect4" y: 30; width: 10; height: 10 - anchors.right: MasterRect.left + anchors.right: masterRect.left } Rectangle { - id: Rect5; objectName: "Rect5" + id: rect5; objectName: "rect5" y: 30; width: 10; height: 10 - anchors.right: MasterRect.right + anchors.right: masterRect.right } Rectangle { - id: Rect6; objectName: "Rect6" + id: rect6; objectName: "rect6" y: 30; width: 10; height: 10 - anchors.right: MasterRect.horizontalCenter + anchors.right: masterRect.horizontalCenter } Rectangle { - id: Rect7; objectName: "Rect7" + id: rect7; objectName: "rect7" y: 50; width: 10; height: 10 anchors.left: parent.left } Rectangle { - id: Rect8; objectName: "Rect8" + id: rect8; objectName: "rect8" y: 50; width: 10; height: 10 anchors.left: parent.right } Rectangle { - id: Rect9; objectName: "Rect9" + id: rect9; objectName: "rect9" y: 50; width: 10; height: 10 anchors.left: parent.horizontalCenter } Rectangle { - id: Rect10; objectName: "Rect10" + id: rect10; objectName: "rect10" y: 60; width: 10; height: 10 anchors.right: parent.left } Rectangle { - id: Rect11; objectName: "Rect11" + id: rect11; objectName: "rect11" y: 60; width: 10; height: 10 anchors.right: parent.right } Rectangle { - id: Rect12; objectName: "Rect12" + id: rect12; objectName: "rect12" y: 60; width: 10; height: 10 anchors.right: parent.horizontalCenter } Rectangle { - id: Rect13; objectName: "Rect13" + id: rect13; objectName: "rect13" x: 200; width: 10; height: 10 - anchors.top: MasterRect.bottom + anchors.top: masterRect.bottom } Rectangle { - id: Rect14; objectName: "Rect14" + id: rect14; objectName: "rect14" width: 10; height: 10; color: "steelblue" anchors.verticalCenter: parent.verticalCenter } Rectangle { - id: Rect15; objectName: "Rect15" + id: rect15; objectName: "rect15" y: 200; height: 10 - anchors.left: MasterRect.left - anchors.right: MasterRect.right + anchors.left: masterRect.left + anchors.right: masterRect.right } Rectangle { - id: Rect16; objectName: "Rect16" + id: rect16; objectName: "rect16" y: 220; height: 10 - anchors.left: MasterRect.left - anchors.horizontalCenter: MasterRect.right + anchors.left: masterRect.left + anchors.horizontalCenter: masterRect.right } Rectangle { - id: Rect17; objectName: "Rect17" + id: rect17; objectName: "rect17" y: 240; height: 10 - anchors.right: MasterRect.right - anchors.horizontalCenter: MasterRect.left + anchors.right: masterRect.right + anchors.horizontalCenter: masterRect.left } Rectangle { - id: Rect18; objectName: "Rect18" + id: rect18; objectName: "rect18" x: 180; width: 10 - anchors.top: MasterRect.bottom + anchors.top: masterRect.bottom anchors.bottom: Rect12.top } Rectangle { - id: Rect19; objectName: "Rect19" + id: rect19; objectName: "rect19" y: 70; width: 10; height: 10 anchors.horizontalCenter: parent.horizontalCenter } Rectangle { - id: Rect20; objectName: "Rect20" + id: rect20; objectName: "rect20" y: 70; width: 10; height: 10 anchors.horizontalCenter: parent.right } Rectangle { - id: Rect21; objectName: "Rect21" + id: rect21; objectName: "rect21" y: 70; width: 10; height: 10 anchors.horizontalCenter: parent.left } Rectangle { - id: Rect22; objectName: "Rect22" + id: rect22; objectName: "rect22" width: 10; height: 10 - anchors.centerIn: MasterRect + anchors.centerIn: masterRect } Rectangle { - id: Rect23; objectName: "Rect23" - anchors.left: MasterRect.left + id: rect23; objectName: "rect23" + anchors.left: masterRect.left anchors.leftMargin: 5 - anchors.right: MasterRect.right + anchors.right: masterRect.right anchors.rightMargin: 5 - anchors.top: MasterRect.top + anchors.top: masterRect.top anchors.topMargin: 5 - anchors.bottom: MasterRect.bottom + anchors.bottom: masterRect.bottom anchors.bottomMargin: 5 } Text { diff --git a/tests/auto/declarative/anchors/data/illegal1.qml b/tests/auto/declarative/anchors/data/illegal1.qml index 0a960d0..53af443 100644 --- a/tests/auto/declarative/anchors/data/illegal1.qml +++ b/tests/auto/declarative/anchors/data/illegal1.qml @@ -3,10 +3,10 @@ import Qt 4.6 Rectangle { id: rect width: 120; height: 200; color: "white" - Rectangle { id: TheRect; width: 100; height: 100 } + Rectangle { id: theRect; width: 100; height: 100 } Rectangle { - anchors.left: TheRect.left - anchors.right: TheRect.right - anchors.horizontalCenter: TheRect.horizontalCenter + anchors.left: theRect.left + anchors.right: theRect.right + anchors.horizontalCenter: theRect.horizontalCenter } } diff --git a/tests/auto/declarative/anchors/data/illegal2.qml b/tests/auto/declarative/anchors/data/illegal2.qml index 2497738..978be52 100644 --- a/tests/auto/declarative/anchors/data/illegal2.qml +++ b/tests/auto/declarative/anchors/data/illegal2.qml @@ -3,11 +3,11 @@ import Qt 4.6 Rectangle { id: rect width: 120; height: 200; color: "white" - Text { id: Text1; text: "Hello" } + Text { id: text1; text: "Hello" } Text { - id: Text2; - anchors.baseline: Text1.baseline; - anchors.top: Text1.top; + id: text2; + anchors.baseline: text1.baseline; + anchors.top: text1.top; text: "World" } } diff --git a/tests/auto/declarative/anchors/data/illegal3.qml b/tests/auto/declarative/anchors/data/illegal3.qml index 27b2e4d..065ceb5 100644 --- a/tests/auto/declarative/anchors/data/illegal3.qml +++ b/tests/auto/declarative/anchors/data/illegal3.qml @@ -4,9 +4,9 @@ Rectangle { id: rect width: 120; height: 200; color: "white" Item { - Rectangle { id: TheRect; width: 100; height: 100 } + Rectangle { id: theRect; width: 100; height: 100 } } Rectangle { - anchors.left: TheRect.left + anchors.left: theRect.left } } diff --git a/tests/auto/declarative/anchors/data/loop1.qml b/tests/auto/declarative/anchors/data/loop1.qml index ef6b63d..a266612 100644 --- a/tests/auto/declarative/anchors/data/loop1.qml +++ b/tests/auto/declarative/anchors/data/loop1.qml @@ -3,6 +3,6 @@ import Qt 4.6 Rectangle { id: rect width: 120; height: 200; color: "white" - Text { id: Text1; anchors.right: Text2.right; text: "Hello" } - Text { id: Text2; anchors.right: Text1.right; anchors.rightMargin: 10; text: "World" } + Text { id: text1; anchors.right: text2.right; text: "Hello" } + Text { id: text2; anchors.right: text1.right; anchors.rightMargin: 10; text: "World" } } diff --git a/tests/auto/declarative/anchors/data/loop2.qml b/tests/auto/declarative/anchors/data/loop2.qml index 2445a15..acb57cd 100644 --- a/tests/auto/declarative/anchors/data/loop2.qml +++ b/tests/auto/declarative/anchors/data/loop2.qml @@ -6,15 +6,15 @@ Rectangle { height: 600; Image { - id: Image1 + id: image1 source: "http://labs.trolltech.com/blogs/wp-content/uploads/2009/03/3311388091_ac2a257feb.jpg" - anchors.right: Image2.left + anchors.right: image2.left } Image { - id: Image2 + id: image2 source: "http://labs.trolltech.com/blogs/wp-content/uploads/2009/03/oslo_groupphoto.jpg" - anchors.left: Image1.right + anchors.left: image1.right anchors.leftMargin: 20 } } diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 4c85d2d..34c1e01 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -97,51 +97,51 @@ void tst_anchors::basicAnchors() qApp->processEvents(); //sibling horizontal - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect1"))->x(), 26.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect2"))->x(), 122.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect3"))->x(), 74.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect4"))->x(), 16.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect5"))->x(), 112.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect6"))->x(), 64.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect1"))->x(), 26.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect2"))->x(), 122.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect3"))->x(), 74.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect4"))->x(), 16.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect5"))->x(), 112.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect6"))->x(), 64.0); //parent horizontal - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect7"))->x(), 0.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect8"))->x(), 240.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect9"))->x(), 120.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect10"))->x(), -10.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect11"))->x(), 230.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect12"))->x(), 110.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect7"))->x(), 0.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect8"))->x(), 240.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect9"))->x(), 120.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect10"))->x(), -10.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect11"))->x(), 230.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect12"))->x(), 110.0); //vertical - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect13"))->y(), 20.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect14"))->y(), 155.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect13"))->y(), 20.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect14"))->y(), 155.0); //stretch - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect15"))->x(), 26.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect15"))->width(), 96.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect16"))->x(), 26.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect16"))->width(), 192.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect17"))->x(), -70.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect17"))->width(), 192.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect15"))->x(), 26.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect15"))->width(), 96.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect16"))->x(), 26.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect16"))->width(), 192.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect17"))->x(), -70.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect17"))->width(), 192.0); //vertical stretch - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect18"))->y(), 20.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect18"))->height(), 40.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect18"))->y(), 20.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect18"))->height(), 40.0); //more parent horizontal - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect19"))->x(), 115.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect20"))->x(), 235.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect21"))->x(), -5.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect19"))->x(), 115.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect20"))->x(), 235.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect21"))->x(), -5.0); //centerIn - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect22"))->x(), 69.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect22"))->y(), 5.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect22"))->x(), 69.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect22"))->y(), 5.0); //margins - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect23"))->x(), 31.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect23"))->y(), 5.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect23"))->width(), 86.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("Rect23"))->height(), 10.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->x(), 31.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->y(), 5.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->width(), 86.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("rect23"))->height(), 10.0); //baseline QmlGraphicsText *text1 = findItem<QmlGraphicsText>(view->root(), QLatin1String("text1")); diff --git a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro new file mode 100644 index 0000000..61f821e --- /dev/null +++ b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmldebug.cpp diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp new file mode 100644 index 0000000..7c52a19 --- /dev/null +++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp @@ -0,0 +1,797 @@ +/**************************************************************************** +** +** 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 <qtest.h> +#include <QSignalSpy> +#include <QTimer> +#include <QHostAddress> +#include <QDebug> +#include <QThread> + +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcontext.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmlexpression.h> +#include <QtDeclarative/qmlmetatype.h> +#include <QtDeclarative/qmlmetaproperty.h> +#include <QtDeclarative/qmlbinding.h> + +#include <private/qmldebug_p.h> +#include <private/qmlenginedebug_p.h> +#include <private/qmldebugclient_p.h> +#include <private/qmldebugservice_p.h> +#include <private/qmlgraphicsrectangle_p.h> + + +class tst_QmlDebug : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebug(QmlDebugConnection *conn, QmlEngine *engine, QmlGraphicsItem *rootItem) + : m_conn(conn), m_dbg(0), m_engine(engine), m_rootItem(rootItem) {} + +protected slots: + void saveValueChange(const QByteArray &ba, const QVariant &v) + { + m_savedValueChanges[ba] = v; + } + +private: + QmlDebugObjectReference findRootObject(); + QmlDebugPropertyReference findProperty(const QList<QmlDebugPropertyReference> &props, const QString &name) const; + QObject *findObjectWithId(const QObjectList &objects, int id) const; + void waitForQuery(QmlDebugQuery *query); + + void recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const; + + void recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const; + void recursiveCompareContexts(const QmlDebugContextReference &a, const QmlDebugContextReference &b) const; + void compareProperties(const QmlDebugPropertyReference &a, const QmlDebugPropertyReference &b) const; + + QmlDebugConnection *m_conn; + QmlEngineDebug *m_dbg; + QmlEngine *m_engine; + QmlGraphicsItem *m_rootItem; + QHash<QByteArray, QVariant> m_savedValueChanges; + +private slots: + void initTestCase(); + + void watch_property(); + void watch_object(); + void watch_expression(); + void watch_expression_data(); + + void queryAvailableEngines(); + void queryRootContexts(); + void queryObject(); + void queryObject_data(); + void queryExpressionResult(); + void queryExpressionResult_data(); + + void tst_QmlDebugFileReference(); + void tst_QmlDebugEngineReference(); + void tst_QmlDebugObjectReference(); + void tst_QmlDebugContextReference(); + void tst_QmlDebugPropertyReference(); +}; + +QmlDebugObjectReference tst_QmlDebug::findRootObject() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + if (q_engines->engines().count() == 0) + return QmlDebugObjectReference(); + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + if (q_context->rootContext().objects().count() == 0) + return QmlDebugObjectReference(); + QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); + waitForQuery(q_obj); + + QmlDebugObjectReference result = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + return result; +} + +QmlDebugPropertyReference tst_QmlDebug::findProperty(const QList<QmlDebugPropertyReference> &props, const QString &name) const +{ + foreach(const QmlDebugPropertyReference &p, props) { + if (p.name() == name) + return p; + } + return QmlDebugPropertyReference(); +} + +QObject *tst_QmlDebug::findObjectWithId(const QObjectList &objects, int id) const +{ + foreach (QObject *o, objects) { + if (id == QmlDebugService::idForObject(o)) + return o; + } + return 0; +} + +void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) +{ + QVERIFY(query); + QCOMPARE(query->parent(), this); + QEventLoop loop; + QTimer timer; + QVERIFY(query->state() == QmlDebugQuery::Waiting); + connect(query, SIGNAL(stateChanged(State)), &loop, SLOT(quit())); + connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + timer.start(5000); + loop.exec(); + if (!timer.isActive()) + QFAIL("query timed out"); +} + +void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const +{ + const QMetaObject *meta = o->metaObject(); + + QmlType *type = QmlMetaType::qmlType(o->metaObject()); + QString className = type ? type->qmlTypeName() : QString(); + className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); + + QCOMPARE(oref.debugId(), QmlDebugService::idForObject(o)); + QCOMPARE(oref.name(), o->objectName()); + QCOMPARE(oref.className(), className); + QCOMPARE(oref.contextDebugId(), QmlDebugService::idForObject(qmlContext(o))); + + foreach (const QmlDebugObjectReference &cref, oref.children()) { + // ignore children with no context + if (cref.contextDebugId() < 0) + continue; + + QObject *childObject = findObjectWithId(o->children(), cref.debugId()); + QVERIFY2(childObject, qPrintable(QString("Can't find QObject* for %1").arg(cref.className()))); + + if (recursive) + recursiveObjectTest(childObject, cref, true); + } + + foreach (const QmlDebugPropertyReference &p, oref.properties()) { + QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); + QVERIFY(pmeta.isValid()); + + QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); + + if (pmeta.type() < QVariant::UserType) // TODO test complex types + QCOMPARE(p.value(), pmeta.read(o)); + + if (p.name() == "parent") + QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QmlGraphicsItem*"); + else + QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); + + QmlAbstractBinding *binding = QmlMetaProperty(o, p.name()).binding(); + if (binding) + QCOMPARE(binding->expression(), p.binding()); + + QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + } +} + +void tst_QmlDebug::recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const +{ + QCOMPARE(a.debugId(), b.debugId()); + QCOMPARE(a.className(), b.className()); + QCOMPARE(a.name(), b.name()); + QCOMPARE(a.contextDebugId(), b.contextDebugId()); + + QCOMPARE(a.source().url(), b.source().url()); + QCOMPARE(a.source().lineNumber(), b.source().lineNumber()); + QCOMPARE(a.source().columnNumber(), b.source().columnNumber()); + + QCOMPARE(a.properties().count(), b.properties().count()); + QCOMPARE(a.children().count(), b.children().count()); + + QList<QmlDebugPropertyReference> aprops = a.properties(); + QList<QmlDebugPropertyReference> bprops = b.properties(); + + for (int i=0; i<aprops.count(); i++) + compareProperties(aprops[i], bprops[i]); + + for (int i=0; i<a.children().count(); i++) + recursiveCompareObjects(a.children()[i], b.children()[i]); +} + +void tst_QmlDebug::recursiveCompareContexts(const QmlDebugContextReference &a, const QmlDebugContextReference &b) const +{ + QCOMPARE(a.debugId(), b.debugId()); + QCOMPARE(a.name(), b.name()); + QCOMPARE(a.objects().count(), b.objects().count()); + QCOMPARE(a.contexts().count(), b.contexts().count()); + + for (int i=0; i<a.objects().count(); i++) + recursiveCompareObjects(a.objects()[i], b.objects()[i]); + + for (int i=0; i<a.contexts().count(); i++) + recursiveCompareContexts(a.contexts()[i], b.contexts()[i]); +} + +void tst_QmlDebug::compareProperties(const QmlDebugPropertyReference &a, const QmlDebugPropertyReference &b) const +{ + QCOMPARE(a.objectDebugId(), b.objectDebugId()); + QCOMPARE(a.name(), b.name()); + QCOMPARE(a.value(), b.value()); + QCOMPARE(a.valueTypeName(), b.valueTypeName()); + QCOMPARE(a.binding(), b.binding()); + QCOMPARE(a.hasNotifySignal(), b.hasNotifySignal()); +} + +void tst_QmlDebug::initTestCase() +{ + m_dbg = new QmlEngineDebug(m_conn, this); +} + +void tst_QmlDebug::watch_property() +{ + QmlDebugObjectReference obj = findRootObject(); + QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); + + QmlDebugPropertyWatch *watch = m_dbg->addWatch(prop, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->name(), prop.name()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + QEventLoop loop; + QTimer timer; + connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit())); + connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + + int origWidth = m_rootItem->property("width").toInt(); + timer.start(5000); + m_rootItem->setProperty("width", origWidth*2); + loop.exec(); + + if (!timer.isActive()) + QFAIL("Did not receive valueChanged() for property"); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get a signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.at(0).at(0).value<QByteArray>(), prop.name().toUtf8()); + QCOMPARE(spy.at(0).at(1).value<QVariant>(), qVariantFromValue(origWidth*2)); +} + +void tst_QmlDebug::watch_object() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); + waitForQuery(q_obj); + + QmlDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + QmlDebugWatch *watch = m_dbg->addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + + m_savedValueChanges.clear(); + connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), + SLOT(saveValueChange(QByteArray,QVariant))); + + int origWidth = m_rootItem->property("width").toInt(); + int origHeight = m_rootItem->property("height").toInt(); + m_rootItem->setProperty("width", origWidth*2); + m_rootItem->setProperty("height", origHeight*2); + + QEventLoop loop; + QTimer timer; + timer.start(5000); + while (timer.isActive() && + (!m_savedValueChanges.contains("width") || !m_savedValueChanges.contains("height"))) { + loop.processEvents(QEventLoop::AllEvents, 50); + } + + QVariant newWidth = m_savedValueChanges["width"]; + QVariant newHeight = m_savedValueChanges["height"]; + + m_dbg->removeWatch(watch); + delete watch; + + // since watch has been removed, restoring the original values should not trigger a valueChanged() + m_savedValueChanges.clear(); + m_rootItem->setProperty("width", origWidth); + m_rootItem->setProperty("height", origHeight); + QTest::qWait(100); + QCOMPARE(m_savedValueChanges.count(), 0); + + if (newWidth.isNull() || newHeight.isNull()) { + QString s = QString("Did not receive both width and height changes (width=%1, height=%2)") + .arg(newWidth.toString()).arg(newHeight.toString()); + QFAIL(qPrintable(s)); + } + + QCOMPARE(newWidth, qVariantFromValue(origWidth*2)); + QCOMPARE(newHeight, qVariantFromValue(origHeight*2)); +} + +void tst_QmlDebug::watch_expression() +{ + QFETCH(QString, expr); + QFETCH(int, increment); + QFETCH(int, incrementCount); + + int origWidth = m_rootItem->property("width").toInt(); + + QmlDebugObjectReference obj = findRootObject(); + + QmlDebugObjectExpressionWatch *watch = m_dbg->addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->expression(), expr); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value + + int width = origWidth; + for (int i=0; i<incrementCount+1; i++) { + QTimer timer; + timer.start(5000); + if (i > 0) { + width += increment; + m_rootItem->setProperty("width", width); + } + QEventLoop loop; + connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit())); + loop.exec(); + if (!timer.isActive()) + QFAIL("Did not receive valueChanged() signal for expression"); + } + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get a signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), expectedSpyCount); + + width = origWidth + increment; + for (int i=0; i<spy.count(); i++) { + QCOMPARE(spy.at(i).at(1).value<QVariant>().toInt(), width); + width += increment; + } +} + +void tst_QmlDebug::watch_expression_data() +{ + QTest::addColumn<QString>("expr"); + QTest::addColumn<int>("increment"); + QTest::addColumn<int>("incrementCount"); + + QTest::newRow("width") << "width" << 0 << 0; + QTest::newRow("width+10") << "width + 10" << 10 << 5; +} + +void tst_QmlDebug::queryAvailableEngines() +{ + QmlDebugEnginesQuery *q_engines; + + QmlEngineDebug unconnected(0); + q_engines = unconnected.queryAvailableEngines(0); + QCOMPARE(q_engines->state(), QmlDebugQuery::Error); + delete q_engines; + + q_engines = m_dbg->queryAvailableEngines(this); + delete q_engines; + + q_engines = m_dbg->queryAvailableEngines(this); + QVERIFY(q_engines->engines().isEmpty()); + waitForQuery(q_engines); + + // TODO test multiple engines + QList<QmlDebugEngineReference> engines = q_engines->engines(); + QCOMPARE(engines.count(), 1); + + foreach(const QmlDebugEngineReference &e, engines) { + QCOMPARE(e.debugId(), QmlDebugService::idForObject(m_engine)); + QCOMPARE(e.name(), m_engine->objectName()); + } + + delete q_engines; +} + +void tst_QmlDebug::queryRootContexts() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + int engineId = q_engines->engines()[0].debugId(); + + QmlDebugRootContextQuery *q_context; + + QmlEngineDebug unconnected(0); + q_context = unconnected.queryRootContexts(engineId, this); + QCOMPARE(q_context->state(), QmlDebugQuery::Error); + delete q_context; + + q_context = m_dbg->queryRootContexts(engineId, this); + delete q_context; + + q_context = m_dbg->queryRootContexts(engineId, this); + waitForQuery(q_context); + + QmlContext *actualContext = m_engine->rootContext(); + QmlDebugContextReference context = q_context->rootContext(); + QCOMPARE(context.debugId(), QmlDebugService::idForObject(actualContext)); + QCOMPARE(context.name(), actualContext->objectName()); + + QCOMPARE(context.objects().count(), 2); // 2 objects created for engine in main() + + // root context query sends only root object data - it doesn't fill in + // the children or property info + QCOMPARE(context.objects()[0].properties().count(), 0); + QCOMPARE(context.objects()[0].children().count(), 0); + + // TODO have multiple contexts + QCOMPARE(context.contexts().count(), 0); + + delete q_engines; + delete q_context; +} + +void tst_QmlDebug::queryObject() +{ + QFETCH(bool, recursive); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + QmlDebugObjectReference rootObject = q_context->rootContext().objects()[0]; + + QmlDebugObjectQuery *q_obj = 0; + + QmlEngineDebug unconnected(0); + q_obj = recursive ? unconnected.queryObjectRecursive(rootObject, this) : unconnected.queryObject(rootObject, this); + QCOMPARE(q_obj->state(), QmlDebugQuery::Error); + delete q_obj; + + q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); + delete q_obj; + + q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); + waitForQuery(q_obj); + + QmlDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + // check source as defined in main() + QmlDebugFileReference source = obj.source(); + QCOMPARE(source.url(), QUrl("file://")); + QCOMPARE(source.lineNumber(), 2); + QCOMPARE(source.columnNumber(), 1); + + // generically test all properties, children and childrens' properties + recursiveObjectTest(m_rootItem, obj, recursive); + + if (recursive) { + foreach(const QmlDebugObjectReference &child, obj.children()) + QVERIFY(child.properties().count() > 0); + + QmlDebugObjectReference rect; + QmlDebugObjectReference text; + foreach (const QmlDebugObjectReference &child, obj.children()) { + if (child.className() == "Rectangle") + rect = child; + else if (child.className() == "Text") + text = child; + } + + // test specific property values + QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500)); + QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600)); + QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + + QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + + } else { + foreach(const QmlDebugObjectReference &child, obj.children()) + QCOMPARE(child.properties().count(), 0); + } +} + +void tst_QmlDebug::queryObject_data() +{ + QTest::addColumn<bool>("recursive"); + + QTest::newRow("non-recursive") << false; + QTest::newRow("recursive") << true; +} + +void tst_QmlDebug::queryExpressionResult() +{ + QFETCH(QString, expr); + QFETCH(QVariant, result); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + int objectId = q_context->rootContext().objects()[0].debugId(); + + QmlDebugExpressionQuery *q_expr; + + QmlEngineDebug unconnected(0); + q_expr = unconnected.queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->state(), QmlDebugQuery::Error); + delete q_expr; + + q_expr = m_dbg->queryExpressionResult(objectId, expr, this); + delete q_expr; + + q_expr = m_dbg->queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->expression(), expr); + waitForQuery(q_expr); + + QCOMPARE(q_expr->result(), result); + + delete q_engines; + delete q_context; + delete q_expr; +} + +void tst_QmlDebug::queryExpressionResult_data() +{ + QTest::addColumn<QString>("expr"); + QTest::addColumn<QVariant>("result"); + + QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); + QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); + QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("<undefined>")); +} + +void tst_QmlDebug::tst_QmlDebugFileReference() +{ + QmlDebugFileReference ref; + QVERIFY(ref.url().isEmpty()); + QCOMPARE(ref.lineNumber(), -1); + QCOMPARE(ref.columnNumber(), -1); + + ref.setUrl(QUrl("http://test")); + QCOMPARE(ref.url(), QUrl("http://test")); + ref.setLineNumber(1); + QCOMPARE(ref.lineNumber(), 1); + ref.setColumnNumber(1); + QCOMPARE(ref.columnNumber(), 1); + + QmlDebugFileReference copy(ref); + QmlDebugFileReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugFileReference &r, (QList<QmlDebugFileReference>() << copy << copyAssign)) { + QCOMPARE(r.url(), ref.url()); + QCOMPARE(r.lineNumber(), ref.lineNumber()); + QCOMPARE(r.columnNumber(), ref.columnNumber()); + } +} + +void tst_QmlDebug::tst_QmlDebugEngineReference() +{ + QmlDebugEngineReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + + ref = QmlDebugEngineReference(1); + QCOMPARE(ref.debugId(), 1); + QVERIFY(ref.name().isEmpty()); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + ref = q_engines->engines()[0]; + delete q_engines; + + QmlDebugEngineReference copy(ref); + QmlDebugEngineReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugEngineReference &r, (QList<QmlDebugEngineReference>() << copy << copyAssign)) { + QCOMPARE(r.debugId(), ref.debugId()); + QCOMPARE(r.name(), ref.name()); + } +} + +void tst_QmlDebug::tst_QmlDebugObjectReference() +{ + QmlDebugObjectReference ref; + QCOMPARE(ref.debugId(), -1); + QCOMPARE(ref.className(), QString()); + QCOMPARE(ref.name(), QString()); + QCOMPARE(ref.contextDebugId(), -1); + QVERIFY(ref.properties().isEmpty()); + QVERIFY(ref.children().isEmpty()); + + QmlDebugFileReference source = ref.source(); + QVERIFY(source.url().isEmpty()); + QVERIFY(source.lineNumber() < 0); + QVERIFY(source.columnNumber() < 0); + + ref = QmlDebugObjectReference(1); + QCOMPARE(ref.debugId(), 1); + + QmlDebugObjectReference rootObject = findRootObject(); + QmlDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); + waitForQuery(query); + ref = query->object(); + delete query; + + QVERIFY(ref.debugId() >= 0); + + QmlDebugObjectReference copy(ref); + QmlDebugObjectReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugObjectReference &r, (QList<QmlDebugObjectReference>() << copy << copyAssign)) + recursiveCompareObjects(r, ref); +} + +void tst_QmlDebug::tst_QmlDebugContextReference() +{ + QmlDebugContextReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + QVERIFY(ref.objects().isEmpty()); + QVERIFY(ref.contexts().isEmpty()); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + ref = q_context->rootContext(); + delete q_engines; + delete q_context; + QVERIFY(ref.debugId() >= 0); + + QmlDebugContextReference copy(ref); + QmlDebugContextReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugContextReference &r, (QList<QmlDebugContextReference>() << copy << copyAssign)) + recursiveCompareContexts(r, ref); +} + +void tst_QmlDebug::tst_QmlDebugPropertyReference() +{ + QmlDebugObjectReference rootObject = findRootObject(); + QmlDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); + waitForQuery(query); + QmlDebugObjectReference obj = query->object(); + delete query; +} + +class TestRunnerThread : public QThread +{ + Q_OBJECT +public: + void run() { + QTest::qWait(1000); + connectToEngine(); + } + + QPointer<QmlEngine> m_engine; + QPointer<QmlGraphicsItem> m_item; + +signals: + void testsFinished(); + +public slots: + + void connectToEngine() + { + QmlDebugConnection conn; + conn.connectToHost("127.0.0.1", 3768); + bool ok = conn.waitForConnected(5000); + Q_ASSERT(ok); + while (!m_engine && !m_item) + QTest::qWait(50); + + tst_QmlDebug test(&conn, m_engine, m_item); + QTest::qExec(&test); + emit testsFinished(); + } +}; + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + qputenv("QML_DEBUG_SERVER_PORT", "3768"); + + TestRunnerThread thread; + QObject::connect(&thread, SIGNAL(testsFinished()), qApp, SLOT(quit())); + thread.start(); + + QmlEngine engine; // blocks until client connects + + QmlComponent component(&engine, + "import Qt 4.6\n" + "Item {\n" + "width: 10; height: 20;\n" + "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" + "Text { color: blueRect.color; }" + "}\n", + QUrl("file://")); + Q_ASSERT(component.isReady()); + QObject *o = component.create(); + QObject::connect(&thread, SIGNAL(testsFinished()), o, SLOT(deleteLater())); + + // allows us to test that multiple contexts can be detected + QObject *o2 = component.create(); + QObject::connect(&thread, SIGNAL(testsFinished()), o2, SLOT(deleteLater())); + + // start the test + thread.m_engine = &engine; + thread.m_item = qobject_cast<QmlGraphicsItem*>(o); + + return app.exec(); + +} + +//QTEST_MAIN(tst_QmlDebug) + +#include "tst_qmldebug.moc" diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index d1194d9..3106f90 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -13,7 +13,7 @@ SUBDIRS += \ numberformatter \ # Cover parserstress \ # Cover pathview \ # Cover - qfxloader \ # Cover + qmlgraphicsloader \ # Cover qmetaobjectbuilder \ # Cover qmlbinding \ # Cover qmlconnection \ # Cover diff --git a/tests/auto/declarative/qfxloader/NoResize.qml b/tests/auto/declarative/qmlgraphicsloader/NoResize.qml index cfbb55a..cfbb55a 100644 --- a/tests/auto/declarative/qfxloader/NoResize.qml +++ b/tests/auto/declarative/qmlgraphicsloader/NoResize.qml diff --git a/tests/auto/declarative/qfxloader/Rect120x60.qml b/tests/auto/declarative/qmlgraphicsloader/Rect120x60.qml index aa4b0c2..aa4b0c2 100644 --- a/tests/auto/declarative/qfxloader/Rect120x60.qml +++ b/tests/auto/declarative/qmlgraphicsloader/Rect120x60.qml diff --git a/tests/auto/declarative/qfxloader/SetSourceComponent.qml b/tests/auto/declarative/qmlgraphicsloader/SetSourceComponent.qml index 1db56c4..1db56c4 100644 --- a/tests/auto/declarative/qfxloader/SetSourceComponent.qml +++ b/tests/auto/declarative/qmlgraphicsloader/SetSourceComponent.qml diff --git a/tests/auto/declarative/qfxloader/SizeToItem.qml b/tests/auto/declarative/qmlgraphicsloader/SizeToItem.qml index b52fa03..b52fa03 100644 --- a/tests/auto/declarative/qfxloader/SizeToItem.qml +++ b/tests/auto/declarative/qmlgraphicsloader/SizeToItem.qml diff --git a/tests/auto/declarative/qfxloader/SizeToLoader.qml b/tests/auto/declarative/qmlgraphicsloader/SizeToLoader.qml index 1a107e1..1a107e1 100644 --- a/tests/auto/declarative/qfxloader/SizeToLoader.qml +++ b/tests/auto/declarative/qmlgraphicsloader/SizeToLoader.qml diff --git a/tests/auto/declarative/qfxloader/qfxloader.pro b/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro index aee52cc..8be8cdf 100644 --- a/tests/auto/declarative/qfxloader/qfxloader.pro +++ b/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxloader.cpp +SOURCES += tst_qmlgraphicsloader.cpp DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp index 9a3da90..8fda991 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp @@ -43,15 +43,16 @@ #include <QtDeclarative/qmlcomponent.h> #include <private/qmlgraphicsloader_p.h> -class tst_qfxloader : public QObject +class tst_QmlGraphicsLoader : public QObject { Q_OBJECT public: - tst_qfxloader(); + tst_QmlGraphicsLoader(); private slots: void url(); + void invalidUrl(); void component(); void clear(); void urlToComponent(); @@ -77,23 +78,25 @@ inline QUrl TEST_FILE(const char *filename) } */ -tst_qfxloader::tst_qfxloader() +tst_QmlGraphicsLoader::tst_QmlGraphicsLoader() { } -void tst_qfxloader::url() +void tst_QmlGraphicsLoader::url() { QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item()); + QVERIFY(loader->source() == QUrl("file://" SRCDIR "/Rect120x60.qml")); QCOMPARE(loader->progress(), 1.0); + QCOMPARE(loader->status(), QmlGraphicsLoader::Ready); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); delete loader; } -void tst_qfxloader::component() +void tst_QmlGraphicsLoader::component() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); @@ -103,36 +106,75 @@ void tst_qfxloader::component() QVERIFY(loader); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); + QCOMPARE(loader->status(), QmlGraphicsLoader::Ready); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); delete loader; } -void tst_qfxloader::clear() +void tst_QmlGraphicsLoader::invalidUrl() { - QmlComponent component(&engine, QByteArray( - "import Qt 4.6\n" - " Loader { id: loader\n" - " source: 'Rect120x60.qml'\n" - " Timer { interval: 200; running: true; onTriggered: loader.source = '' }\n" - " }") - , QUrl("file://" SRCDIR "/")); +// QTest::ignoreMessage(QtWarningMsg, "(:-1: File error for URL file://" SRCDIR "/IDontExist.qml)"); + + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"IDontExist.qml\" }"), QUrl("file://" SRCDIR "/")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); - QVERIFY(loader->item()); - QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); - - QTest::qWait(500); - QVERIFY(loader->item() == 0); - QCOMPARE(loader->progress(), 0.0); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(loader->status(), QmlGraphicsLoader::Error); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); delete loader; } -void tst_qfxloader::urlToComponent() +void tst_QmlGraphicsLoader::clear() +{ + { + QmlComponent component(&engine, QByteArray( + "import Qt 4.6\n" + " Loader { id: loader\n" + " source: 'Rect120x60.qml'\n" + " Timer { interval: 200; running: true; onTriggered: loader.source = '' }\n" + " }") + , QUrl("file://" SRCDIR "/")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QVERIFY(loader != 0); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + QTest::qWait(500); + + QVERIFY(loader->item() == 0); + QCOMPARE(loader->progress(), 0.0); + QCOMPARE(loader->status(), QmlGraphicsLoader::Null); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); + + delete loader; + } + { + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); + QVERIFY(item); + + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(item->QGraphicsObject::children().at(1)); + QVERIFY(loader); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + loader->setSourceComponent(0); + + QVERIFY(loader->item() == 0); + QCOMPARE(loader->progress(), 0.0); + QCOMPARE(loader->status(), QmlGraphicsLoader::Null); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); + + delete loader; + } +} + +void tst_QmlGraphicsLoader::urlToComponent() { QmlComponent component(&engine, QByteArray("import Qt 4.6\n" "Loader {\n" @@ -154,7 +196,7 @@ void tst_qfxloader::urlToComponent() delete loader; } -void tst_qfxloader::componentToUrl() +void tst_QmlGraphicsLoader::componentToUrl() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); @@ -176,20 +218,37 @@ void tst_qfxloader::componentToUrl() delete loader; } -void tst_qfxloader::sizeLoaderToItem() +void tst_QmlGraphicsLoader::sizeLoaderToItem() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); + QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeLoaderToItem); QCOMPARE(loader->width(), 120.0); QCOMPARE(loader->height(), 60.0); + + // Check resize + QmlGraphicsItem *rect = loader->item(); + QVERIFY(rect); + rect->setWidth(150); + rect->setHeight(45); + QCOMPARE(loader->width(), 150.0); + QCOMPARE(loader->height(), 45.0); + + // Switch mode + loader->setResizeMode(QmlGraphicsLoader::SizeItemToLoader); + loader->setWidth(180); + loader->setHeight(30); + QCOMPARE(rect->width(), 180.0); + QCOMPARE(rect->height(), 30.0); } -void tst_qfxloader::sizeItemToLoader() +void tst_QmlGraphicsLoader::sizeItemToLoader() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); + QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeItemToLoader); QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); @@ -197,9 +256,15 @@ void tst_qfxloader::sizeItemToLoader() QVERIFY(rect); QCOMPARE(rect->width(), 200.0); QCOMPARE(rect->height(), 80.0); + + // Check resize + loader->setWidth(180); + loader->setHeight(30); + QCOMPARE(rect->width(), 180.0); + QCOMPARE(rect->height(), 30.0); } -void tst_qfxloader::noResize() +void tst_QmlGraphicsLoader::noResize() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); @@ -213,6 +278,6 @@ void tst_qfxloader::noResize() QCOMPARE(rect->height(), 60.0); } -QTEST_MAIN(tst_qfxloader) +QTEST_MAIN(tst_QmlGraphicsLoader) -#include "tst_qfxloader.moc" +#include "tst_qmlgraphicsloader.moc" diff --git a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-horizontal.qml b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-horizontal.qml index 2b4f55d..1a7366d 100644 --- a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-horizontal.qml +++ b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-horizontal.qml @@ -5,7 +5,7 @@ Rectangle { width: 600; height: 300 ListModel { - id: List + id: list ListElement { dayColor: "steelblue" } ListElement { dayColor: "blue" } ListElement { dayColor: "yellow" } @@ -16,22 +16,22 @@ Rectangle { } Flickable { - id: Flick + id: flickable anchors.fill: parent; viewportWidth: row.width Row { id: row Repeater { - model: List + model: list Rectangle { width: 200; height: 300; color: dayColor } } } } Rectangle { radius: 3 - y: Flick.height-8 + y: flickable.height-8 height: 8 - x: Flick.visibleArea.xPosition * Flick.width - width: Flick.visibleArea.widthRatio * Flick.width + x: flickable.visibleArea.xPosition * flickable.width + width: flickable.visibleArea.widthRatio * flickable.width } } diff --git a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml index 0d6bbed..a1885c4 100644 --- a/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml +++ b/tests/auto/declarative/visual/qmlgraphicsflickable/flickable-vertical.qml @@ -5,7 +5,7 @@ Rectangle { width: 300; height: 600 ListModel { - id: List + id: list ListElement { dayColor: "steelblue" } ListElement { dayColor: "blue" } ListElement { dayColor: "yellow" } @@ -22,7 +22,7 @@ Rectangle { Column { id: column Repeater { - model: List + model: list Rectangle { width: 300; height: 200; color: dayColor } } } diff --git a/tests/auto/declarative/visual/qmlgraphicstext/elide/elide.qml b/tests/auto/declarative/visual/qmlgraphicstext/elide/elide.qml index 3c9ea5b..fa6b5da 100644 --- a/tests/auto/declarative/visual/qmlgraphicstext/elide/elide.qml +++ b/tests/auto/declarative/visual/qmlgraphicstext/elide/elide.qml @@ -5,12 +5,12 @@ Rectangle { height: childrenRect.height Column { width: 80 - height: MyText.height*4 + height: myText.height*4 Text { elide: "ElideLeft" text: "aaa bbb ccc ddd eee fff" width: 80 - id: MyText + id: myText } Text { elide: "ElideMiddle" diff --git a/tests/auto/declarative/visual/qmlgraphicstext/elide/multilength.qml b/tests/auto/declarative/visual/qmlgraphicstext/elide/multilength.qml index fa74cc4..081971c 100644 --- a/tests/auto/declarative/visual/qmlgraphicstext/elide/multilength.qml +++ b/tests/auto/declarative/visual/qmlgraphicstext/elide/multilength.qml @@ -5,12 +5,12 @@ Rectangle { height: 50 color: "lightBlue" Rectangle { - width: MyText.width - height: MyText.height + width: myText.width + height: myText.height color: "white" anchors.centerIn: parent Text { - id: MyText + id: myText width: NumberAnimation { from: 500; to: 0; running: true; repeat: true; duration: 1000 } elide: "ElideRight" text: "Brevity is the soul of wit, and tediousness the limbs and outward flourishes.\x9CBrevity is a great charm of eloquence.\x9CBe concise!\x9CSHHHHHHHHHHHHHHHHHHHHHHHHHHHH" diff --git a/tests/auto/declarative/visual/repeater/basic1.qml b/tests/auto/declarative/visual/repeater/basic1.qml index f6899e8..acb669c 100644 --- a/tests/auto/declarative/visual/repeater/basic1.qml +++ b/tests/auto/declarative/visual/repeater/basic1.qml @@ -4,7 +4,6 @@ Rectangle { color: "blue" width: 300 height: 200 - id: Page Row { Repeater { delegate: Rectangle { diff --git a/tests/auto/declarative/visual/repeater/basic2.qml b/tests/auto/declarative/visual/repeater/basic2.qml index 15a1e91..3323da5 100644 --- a/tests/auto/declarative/visual/repeater/basic2.qml +++ b/tests/auto/declarative/visual/repeater/basic2.qml @@ -4,9 +4,8 @@ Rectangle { color: "blue" width: 300 height: 200 - id: Page Component { - id: Delegate + id: delegate Rectangle { color: "red" width: 100 @@ -18,7 +17,7 @@ Rectangle { } Row { Repeater { - delegate: Delegate + delegate: delegate model: ListModel { ListElement { name: "January" diff --git a/tests/auto/declarative/visual/repeater/basic3.qml b/tests/auto/declarative/visual/repeater/basic3.qml index 4680534..cb57d49 100644 --- a/tests/auto/declarative/visual/repeater/basic3.qml +++ b/tests/auto/declarative/visual/repeater/basic3.qml @@ -4,9 +4,8 @@ Rectangle { color: "blue" width: 300 height: 200 - id: Page ListModel { - id: DataSource + id: dataSource ListElement { name: "January" } @@ -16,7 +15,7 @@ Rectangle { } Row { Repeater { - model: DataSource + model: dataSource delegate: Rectangle { color: "red" width: 100 diff --git a/tests/auto/declarative/visual/repeater/basic4.qml b/tests/auto/declarative/visual/repeater/basic4.qml index 6172493..f31de2c 100644 --- a/tests/auto/declarative/visual/repeater/basic4.qml +++ b/tests/auto/declarative/visual/repeater/basic4.qml @@ -4,9 +4,8 @@ Rectangle { color: "blue" width: 300 height: 200 - id: Page ListModel { - id: DataSource + id: dataSource ListElement { name: "January" } @@ -15,7 +14,7 @@ Rectangle { } } Component { - id: Delegate + id: delegate Rectangle { color: "red" width: 100 @@ -27,8 +26,8 @@ Rectangle { } Row { Repeater { - model: DataSource - delegate: Delegate + model: dataSource + delegate: delegate } } } diff --git a/tests/auto/declarative/visual/scriptAction/scriptAction.qml b/tests/auto/declarative/visual/scriptAction/scriptAction.qml index b1254e2..872701b 100644 --- a/tests/auto/declarative/visual/scriptAction/scriptAction.qml +++ b/tests/auto/declarative/visual/scriptAction/scriptAction.qml @@ -8,13 +8,13 @@ Rectangle { color: "red" } MouseRegion { - id: Clickable + id: clickable anchors.fill: parent } states: State { name: "state1" - when: Clickable.pressed + when: clickable.pressed PropertyChanges { target: myRect x: 50; y: 50 |