From 8f4589c88cf55284c6593a43202b2ac7fbd6ea73 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 13 Nov 2009 18:06:38 +1000 Subject: doc --- doc/src/declarative/globalobject.qdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 3cf1ca3..dc08c28 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -126,8 +126,6 @@ This function attempts to open the specified \c target url in an external applic \section3 Qt.md5(data) This function returns a hex string of the md5 hash of \c data. -\endlist - \section1 Dynamic Object Creation The following functions on the global object allow you to dynamically create QML items from files or strings. -- cgit v0.12 From 7e25debbe245b93e529f902c2b99bd0e772571fd Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 13 Nov 2009 18:10:27 +1000 Subject: doc --- src/declarative/graphicsitems/qmlgraphicsborderimage.cpp | 2 -- src/declarative/graphicsitems/qmlgraphicsimage.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp index 04e79f9..e1039f4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp @@ -58,8 +58,6 @@ QML_DEFINE_TYPE(Qt,4,6,BorderImage,QmlGraphicsBorderImage) \snippet snippets/declarative/border-image.qml 0 \image BorderImage.png - - \sa examples/declarative/border-image */ /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsimage.cpp b/src/declarative/graphicsitems/qmlgraphicsimage.cpp index 89b50a1..42fd910 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimage.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsimage.cpp @@ -182,8 +182,6 @@ void QmlGraphicsImagePrivate::setPixmap(const QPixmap &pixmap) \endlist \image declarative-image_fillMode.gif - \sa examples/declarative/fillmode - \sa examples/declarative/aspectratio */ QmlGraphicsImage::FillMode QmlGraphicsImage::fillMode() const { -- cgit v0.12 From 50fe472e600dedf81dfa959d74b945947ed3938e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 13 Nov 2009 18:11:33 +1000 Subject: doc cleanup --- doc/src/declarative/qtprogrammers.qdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/src/declarative/qtprogrammers.qdoc b/doc/src/declarative/qtprogrammers.qdoc index 6892005..7b1ab44 100644 --- a/doc/src/declarative/qtprogrammers.qdoc +++ b/doc/src/declarative/qtprogrammers.qdoc @@ -130,8 +130,6 @@ As an example, imagine you decided to make a generic tab widget item to be used through your application suite wherever information is in such quantity that it needs to be divided up into pages. -To do this in QML, ... \todo example of container definition. - A significant difference in the parenting concept with QML compare to QWidgets is that while child items are positioned relative to their parents, there is no requirement that they be wholy contained ("clipped") to -- cgit v0.12 From 274cb027444e26d465888842310000963b06aae9 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 16 Nov 2009 13:12:53 +1000 Subject: Web service integration example - Google Maps --- .../declarative/webview/content/Mapping/Map.qml | 20 +++++++++ .../declarative/webview/content/Mapping/map.html | 47 ++++++++++++++++++++++ examples/declarative/webview/googleMaps.qml | 31 ++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 examples/declarative/webview/content/Mapping/Map.qml create mode 100755 examples/declarative/webview/content/Mapping/map.html create mode 100644 examples/declarative/webview/googleMaps.qml diff --git a/examples/declarative/webview/content/Mapping/Map.qml b/examples/declarative/webview/content/Mapping/Map.qml new file mode 100644 index 0000000..9bde031 --- /dev/null +++ b/examples/declarative/webview/content/Mapping/Map.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +Item { + id: page + property real latitude: -34.397 + property real longitude: 150.644 + property string address: "" + WebView { + id: map + anchors.fill: parent + url: "map.html" + javaScriptWindowObjects: Object { + WebView.windowObjectName: "qml" + property real lat: page.latitude + property real lng: page.longitude + property string address: page.address + onAddressChanged: {map.evaluateJavaScript("goToAddress()")} + } + } +} diff --git a/examples/declarative/webview/content/Mapping/map.html b/examples/declarative/webview/content/Mapping/map.html new file mode 100755 index 0000000..8afa21c --- /dev/null +++ b/examples/declarative/webview/content/Mapping/map.html @@ -0,0 +1,47 @@ + + + + + + + +
+ + diff --git a/examples/declarative/webview/googleMaps.qml b/examples/declarative/webview/googleMaps.qml new file mode 100644 index 0000000..b5b13bb --- /dev/null +++ b/examples/declarative/webview/googleMaps.qml @@ -0,0 +1,31 @@ +// This example demonstrates how Web services such as Google Maps can be +// abstracted as QML types. Here we have a "Mapping" module with a "Map" +// type. The Map type has an address property. Setting that property moves +// the map. The underlying implementation uses WebView and the Google Maps +// API, but users from QML don't need to understand the implementation in +// order to create a Map. + +import Qt 4.6 +import "content/Mapping" + +Map { + id: map + width: 300 + height: 300 + address: "Paris" + Rectangle { + color: "white" + width: input.width + 20 + height: input.height + 4 + radius: 5 + anchors.bottom: parent.bottom + anchors.bottomMargin: 5 + x: 70 + TextInput { + id: input + text: map.address + anchors.centerIn: parent + Keys.onReturnPressed: map.address = input.text + } + } +} -- cgit v0.12 From fda2044359c3361b6b525d21fc455160d0ea746a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 16 Nov 2009 15:19:32 +1000 Subject: doc --- src/declarative/graphicsitems/qmlgraphicswebview.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 00fdd6d..c8bb504 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -368,8 +368,13 @@ void QmlGraphicsWebView::setPreferredHeight(int ih) } /*! - Evaluates the \a scriptSource JavaScript inside the main frame - context and returns the result of the last executed statement. + \qmlmethod bool WebView::evaluateJavaScript(string) + + Evaluates the \a scriptSource JavaScript inside the context of the + main web frame, and returns the result of the last executed statement. + + Note that this JavaScript does \e not have any access to QML objects + except as made available as windowObjects. */ QVariant QmlGraphicsWebView::evaluateJavaScript(const QString &scriptSource) { -- cgit v0.12 From a62fbc821c3c32c0ebe63a77f2705d6f1db67394 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 16 Nov 2009 15:28:35 +1000 Subject: Use QDir::separator() and follow no-trailing-slash convention. Fixes QTBUG-5841 --- src/declarative/qml/qmlengine.cpp | 15 ++++++++------- src/declarative/qml/qmlsqldatabase.cpp | 3 ++- tests/auto/declarative/qmlengine/tst_qmlengine.cpp | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 66d4990..c8848fd 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -112,11 +112,6 @@ struct StaticQtMetaObject : public QObject { return &static_cast (0)->staticQtMetaObject; } }; -static QString userLocalDataPath(const QString& app) -{ - return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/") + app; -} - QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0), @@ -130,7 +125,9 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) scriptEngine.newQMetaObject(StaticQtMetaObject::get()); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); - offlineStoragePath = userLocalDataPath(QLatin1String("QML/OfflineStorage")); + offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + + QDir::separator() + QLatin1String("QML") + + QDir::separator() + QLatin1String("OfflineStorage"); qt_add_qmlxmlhttprequest(&scriptEngine); qt_add_qmlsqldatabase(&scriptEngine); @@ -1265,8 +1262,12 @@ void QmlEngine::addImportPath(const QString& path) QmlGraphicsWebView and the SQL databases created with openDatabase() are stored here. - The default is QML/OfflineStorage/ in the platform-standard + The default is QML/OfflineStorage in the platform-standard user application data directory. + + Note that the path may not currently exist on the filesystem, so + callers wanting to \e create new files at this location should create + it first - see QDir::mkpath(). */ void QmlEngine::setOfflineStoragePath(const QString& dir) { diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index c7d2e12..330d904 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -337,7 +337,8 @@ static QScriptValue qmlsqldatabase_open(QScriptContext *context, QScriptEngine * database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); } if (!database.isOpen()) { - QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + QLatin1String("/Databases/"); + QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath + + QDir::separator() + QLatin1String("Databases") + QDir::separator(); QDir().mkpath(basename); basename += dbid; database.setDatabaseName(basename+QLatin1String(".sqlite")); diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp index ef1eee5..e060e7f 100644 --- a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -159,10 +159,18 @@ void tst_qmlengine::contextForObject() void tst_qmlengine::offlineStoragePath() { + // Without these set, QDesktopServices::storageLocation returns + // strings with extra "//" at the end. We set them to ignore this problem. + qApp->setApplicationName("tst_qmlengine"); + qApp->setOrganizationName("Nokia"); + qApp->setOrganizationDomain("nokia.com"); + QmlEngine engine; QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); + dir.mkpath("QML"); dir.cd("QML"); + dir.mkpath("OfflineStorage"); dir.cd("OfflineStorage"); QCOMPARE(engine.offlineStoragePath(), dir.path()); -- cgit v0.12 From 39b2302dbed5fe510d71c1bde3864a79c1a4c9d0 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 17 Nov 2009 10:46:53 +1000 Subject: NOTIFY on children changed --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 7 +++++++ src/declarative/graphicsitems/qmlgraphicsitem.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index ca45f62..fb6afb1 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -1428,6 +1428,11 @@ QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject */ /*! + \fn void QmlGraphicsItem::childrenChanged() + \internal +*/ + +/*! \fn void QmlGraphicsItem::focusChanged() \internal */ @@ -2692,6 +2697,8 @@ QVariant QmlGraphicsItem::itemChange(GraphicsItemChange change, { if (change == ItemParentHasChanged) { emit parentChanged(); + } else if (change == ItemChildAddedChange || change == ItemChildRemovedChange) { + emit childrenChanged(); } return QGraphicsItem::itemChange(change, value); diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index 2ac43b5..11d6e2e 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -69,7 +69,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) Q_PROPERTY(QmlList *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) + Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) Q_PROPERTY(QmlList* states READ states DESIGNABLE false) Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) @@ -160,6 +160,7 @@ public: Q_SIGNALS: void widthChanged(); void heightChanged(); + void childrenChanged(); void childrenRectChanged(); void baselineOffsetChanged(); void stateChanged(const QString &); -- cgit v0.12 From 31d01e174c3a3a1bba2ec9bf40cdc22d4053d8ec Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 17 Nov 2009 11:51:40 +1000 Subject: More animation autotests. --- src/declarative/util/qmlanimation.cpp | 50 +++++----- src/declarative/util/qmlanimation_p.h | 2 +- src/declarative/util/qmlanimation_p_p.h | 2 +- .../auto/declarative/animations/tst_animations.cpp | 105 +++++++++++++++++++++ 4 files changed, 130 insertions(+), 29 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index d78f0a1..780bc82 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -QEasingCurve stringToCurve(const QString &curve) +static QEasingCurve stringToCurve(const QString &curve, QObject *obj) { QEasingCurve easingCurve; @@ -73,8 +73,7 @@ QEasingCurve stringToCurve(const QString &curve) if (hasParams) { QString easeName = curve.trimmed(); if (!easeName.endsWith(QLatin1Char(')'))) { - qWarning("QEasingCurve: Unmatched perenthesis in easing function '%s'", - qPrintable(curve)); + qmlInfo(obj) << obj->tr("Unmatched parenthesis in easing function \"%1\"").arg(curve); return easingCurve; } @@ -83,8 +82,8 @@ QEasingCurve stringToCurve(const QString &curve) easeName.mid(idx + 1, easeName.length() - 1 - idx - 1); normalizedCurve = easeName.left(idx); if (!normalizedCurve.startsWith(QLatin1String("ease"))) { - qWarning("QEasingCurve: Easing function '%s' must start with 'ease'", - qPrintable(curve)); + qmlInfo(obj) << obj->tr("Easing function \"%1\" must start with \"ease\"").arg(curve); + return easingCurve; } props = prop_str.split(QLatin1Char(',')); @@ -98,9 +97,8 @@ QEasingCurve stringToCurve(const QString &curve) int value = me.keyToValue(normalizedCurve.toUtf8().constData()); if (value < 0) { - qWarning("QEasingCurve: Unknown easing curve '%s'", - qPrintable(curve)); - value = 0; + qmlInfo(obj) << obj->tr("Unknown easing curve \"%1\"").arg(curve); + return easingCurve; } easingCurve.setType((QEasingCurve::Type)value); @@ -109,9 +107,8 @@ QEasingCurve stringToCurve(const QString &curve) int sep = str.indexOf(QLatin1Char(':')); if (sep == -1) { - qWarning("QEasingCurve: Improperly specified property in easing function '%s'", - qPrintable(curve)); - return easingCurve; + qmlInfo(obj) << obj->tr("Improperly specified parameter in easing function \"%1\"").arg(curve); + continue; } QString propName = str.left(sep).trimmed(); @@ -119,9 +116,8 @@ QEasingCurve stringToCurve(const QString &curve) qreal propValue = str.mid(sep + 1).trimmed().toDouble(&isOk); if (propName.isEmpty() || !isOk) { - qWarning("QEasingCurve: Improperly specified property in easing function '%s'", - qPrintable(curve)); - return easingCurve; + qmlInfo(obj) << obj->tr("Improperly specified parameter in easing function \"%1\"").arg(curve); + continue; } if (propName == QLatin1String("amplitude")) { @@ -130,10 +126,12 @@ QEasingCurve stringToCurve(const QString &curve) easingCurve.setPeriod(propValue); } else if (propName == QLatin1String("overshoot")) { easingCurve.setOvershoot(propValue); + } else { + qmlInfo(obj) << obj->tr("Unknown easing parameter \"%1\"").arg(propName); + continue; } } } - return easingCurve; } @@ -219,16 +217,14 @@ void QmlAbstractAnimationPrivate::commence() } } -//### make static? -QmlMetaProperty QmlAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str) +QmlMetaProperty QmlAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj) { - Q_Q(QmlAbstractAnimation); QmlMetaProperty prop = QmlMetaProperty::createProperty(obj, str); if (!prop.isValid()) { - qmlInfo(q) << QmlAbstractAnimation::tr("Cannot animate non-existant property \"%1\"").arg(str); + qmlInfo(infoObj) << QmlAbstractAnimation::tr("Cannot animate non-existant property \"%1\"").arg(str); return QmlMetaProperty(); } else if (!prop.isWritable()) { - qmlInfo(q) << QmlAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str); + qmlInfo(infoObj) << QmlAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str); return QmlMetaProperty(); } return prop; @@ -436,7 +432,7 @@ void QmlAbstractAnimation::setTarget(QObject *o) d->target = o; if (d->target && !d->propertyName.isEmpty()) { - d->userProperty = d->createProperty(d->target, d->propertyName); + d->userProperty = d->createProperty(d->target, d->propertyName, this); } else { d->userProperty.invalidate(); } @@ -458,7 +454,7 @@ void QmlAbstractAnimation::setProperty(const QString &n) d->propertyName = n; if (d->target && !d->propertyName.isEmpty()) { - d->userProperty = d->createProperty(d->target, d->propertyName); + d->userProperty = d->createProperty(d->target, d->propertyName, this); } else { d->userProperty.invalidate(); } @@ -652,7 +648,7 @@ int QmlPauseAnimation::duration() const void QmlPauseAnimation::setDuration(int duration) { if (duration < 0) { - qWarning("QmlPauseAnimation: Cannot set a duration of < 0"); + qmlInfo(this) << tr("Cannot set a duration of < 0"); return; } @@ -1029,7 +1025,7 @@ void QmlPropertyAction::transition(QmlStateActions &actions, if (hasTarget && d->value.isValid()) { Action myAction; - myAction.property = d->createProperty(target(), d->propertyName); + myAction.property = d->createProperty(target(), d->propertyName, this); if (myAction.property.isValid()) { myAction.toValue = d->value; data->actions << myAction; @@ -1630,7 +1626,7 @@ int QmlPropertyAnimation::duration() const void QmlPropertyAnimation::setDuration(int duration) { if (duration < 0) { - qWarning("QmlPropertyAnimation: Cannot set a duration of < 0"); + qmlInfo(this) << tr("Cannot set a duration of < 0"); return; } @@ -1872,7 +1868,7 @@ void QmlPropertyAnimation::setEasing(const QString &e) return; d->easing = e; - d->va->setEasingCurve(stringToCurve(d->easing)); + d->va->setEasingCurve(stringToCurve(d->easing, this)); emit easingChanged(e); } @@ -2114,7 +2110,7 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, //an explicit animation has been specified if (hasTarget && d->toIsDefined) { Action myAction; - myAction.property = d->createProperty(target(), d->propertyName); + myAction.property = d->createProperty(target(), d->propertyName, this); if (myAction.property.isValid()) { if (d->fromIsDefined) { d->convertVariant(d->from, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index f126dee..87b6703 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -136,7 +136,7 @@ private Q_SLOTS: }; class QmlPauseAnimationPrivate; -class QmlPauseAnimation : public QmlAbstractAnimation +class Q_AUTOTEST_EXPORT QmlPauseAnimation : public QmlAbstractAnimation { Q_OBJECT Q_DECLARE_PRIVATE(QmlPauseAnimation) diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index e50415f..27c0cd7 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -208,7 +208,7 @@ public: QmlMetaProperty property; QmlAnimationGroup *group; - QmlMetaProperty createProperty(QObject *obj, const QString &str); + static QmlMetaProperty createProperty(QObject *obj, const QString &str, QObject *infoObj); }; class QmlPauseAnimationPrivate : public QmlAbstractAnimationPrivate diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 2692cb6..2506337 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -57,6 +57,8 @@ private slots: void simpleNumber(); void simpleColor(); void alwaysRunToEnd(); + void complete(); + void resume(); void dotProperty(); void badTypes(); void badProperties(); @@ -64,6 +66,7 @@ private slots: void properties(); void propertiesTransition(); void easingStringConversion(); + void invalidDuration(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -96,6 +99,7 @@ void tst_animations::simpleProperty() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); + QVERIFY(animation.currentTime() == 125); QCOMPARE(rect.pos(), QPointF(100,100)); } @@ -120,6 +124,7 @@ void tst_animations::simpleNumber() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); + QVERIFY(animation.currentTime() == 125); QCOMPARE(rect.x(), qreal(100)); } @@ -144,6 +149,7 @@ void tst_animations::simpleColor() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); + QVERIFY(animation.currentTime() == 125); QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1)); } @@ -157,6 +163,8 @@ void tst_animations::alwaysRunToEnd() animation.setDuration(1000); animation.setRepeat(true); animation.setAlwaysRunToEnd(true); + QVERIFY(animation.repeat() == true); + QVERIFY(animation.alwaysRunToEnd() == true); animation.start(); QTest::qWait(1500); animation.stop(); @@ -165,6 +173,54 @@ void tst_animations::alwaysRunToEnd() QTIMED_COMPARE(rect.x(), qreal(200)); } +void tst_animations::complete() +{ + QmlGraphicsRectangle rect; + QmlPropertyAnimation animation; + animation.setTarget(&rect); + animation.setProperty("x"); + animation.setFrom(1); + animation.setTo(200); + animation.setDuration(500); + QVERIFY(animation.from() == 1); + animation.start(); + QTest::qWait(50); + animation.stop(); + QVERIFY(rect.x() != qreal(200)); + animation.start(); + QTest::qWait(50); + QVERIFY(animation.isRunning()); + animation.complete(); + QCOMPARE(rect.x(), qreal(200)); +} + +void tst_animations::resume() +{ + QmlGraphicsRectangle rect; + QmlPropertyAnimation animation; + animation.setTarget(&rect); + animation.setProperty("x"); + animation.setFrom(10); + animation.setTo(200); + animation.setDuration(500); + QVERIFY(animation.from() == 10); + + animation.start(); + QTest::qWait(50); + animation.pause(); + qreal x = rect.x(); + QVERIFY(x != qreal(200)); + QVERIFY(animation.isRunning()); + QVERIFY(animation.isPaused()); + + animation.resume(); + QVERIFY(animation.isRunning()); + QVERIFY(!animation.isPaused()); + QTest::qWait(50); + animation.stop(); + QVERIFY(rect.x() > x); +} + void tst_animations::dotProperty() { QmlGraphicsRectangle rect; @@ -180,6 +236,7 @@ void tst_animations::dotProperty() animation.start(); animation.pause(); animation.setCurrentTime(125); + QVERIFY(animation.currentTime() == 125); QCOMPARE(rect.border()->width(), 5); } @@ -427,6 +484,7 @@ void tst_animations::easingStringConversion() { QmlNumberAnimation *animation = new QmlNumberAnimation; animation->setEasing("easeInOutQuad"); + QCOMPARE(animation->easing(),QLatin1String("easeInOutQuad")); QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::InOutQuad)); animation->setEasing("OutQuad"); @@ -436,9 +494,56 @@ void tst_animations::easingStringConversion() QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutBounce); QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); + animation->setEasing("easeOutElastic(amplitude: 5, period: 3)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutElastic); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().period(), qreal(3)); + + animation->setEasing("easeInOutBack(overshoot: 2)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutBack); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().overshoot(), qreal(2)); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Unmatched parenthesis in easing function \"easeInOutBack(overshoot: 2\""); + animation->setEasing("easeInOutBack(overshoot: 2"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Easing function \"InOutBack(overshoot: 2)\" must start with \"ease\""); + animation->setEasing("InOutBack(overshoot: 2)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Unknown easing curve \"NonExistantEase\""); + animation->setEasing("NonExistantEase"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude 5)\""); + animation->setEasing("easeInOutElastic(amplitude 5)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude: yes)\""); + animation->setEasing("easeInOutElastic(amplitude: yes)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); + QVERIFY(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude() != qreal(5)); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (unknown location) Unknown easing parameter \"nonexistantproperty\""); + animation->setEasing("easeOutQuad(nonexistantproperty: 12)"); + QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutQuad); + delete animation; } +void tst_animations::invalidDuration() +{ + QmlPropertyAnimation *animation = new QmlPropertyAnimation; + QTest::ignoreMessage(QtWarningMsg, "QML QmlPropertyAnimation (unknown location) Cannot set a duration of < 0"); + animation->setDuration(-1); + QCOMPARE(animation->duration(), 250); + + QmlPauseAnimation *pauseAnimation = new QmlPauseAnimation; + QTest::ignoreMessage(QtWarningMsg, "QML QmlPauseAnimation (unknown location) Cannot set a duration of < 0"); + pauseAnimation->setDuration(-1); + QCOMPARE(pauseAnimation->duration(), 250); +} + QTEST_MAIN(tst_animations) #include "tst_animations.moc" -- cgit v0.12 From 8000f8cd4087b03b91d641ffec3fb9f805d4b342 Mon Sep 17 00:00:00 2001 From: Bill King Date: Tue, 17 Nov 2009 12:58:43 +1000 Subject: Documentation fix. Reviewed-by: Martin Jones --- doc/src/declarative/focus.qdoc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index 6eca667..8061a7c 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -75,12 +75,12 @@ Item { \endlist -See also the \l {Keys}{Keys attached property} and {KeyNavigation}{KeyNavigation attached property}. +See also the \l {Keys}{Keys attached property} and \l {KeyNavigation}{KeyNavigation attached property}. \section1 Querying the Active Focus Item Whether or not an \l Item has \e {active focus} can be queried through the -read-only property \c {Item::focus}. For example, here we have a \l Text +property \c {Item::focus}. For example, here we have a \l Text element whose text is determined by whether or not it has \e {active focus}. \code @@ -191,10 +191,11 @@ This problem is fundamentally one of visibility. The \c {MyWidget} components each set their \c {keyHandler} Items as focused as that is all they can do - they don't know how they are going to be used, but they do know that when they're in use their \c {keyHandler} element is what needs focus. Likewise -the code that uses the \c {MyWidget}'s sets the second \c {MyWidget} as -focused because, while it doesn't know exactly how the \c {MyWidget} is -implemented, it knows that it wants the second one to be focused. No one piece -of code knows everything about the other, which is exactly how it should be. +the code that uses the two \c {MyWidgets} sets the second \c {MyWidget} as +focused. While it doesn't know exactly how the \c {MyWidget} is +implemented, it knows that it wants the second one to be focused. This allows us +to achieve encapsulation, allowing each widget to focus on it's appropriate behaviour +itself. To solve this problem - allowing components to care about what they know about and ignore everything else - the QML items introduce a concept known as a -- cgit v0.12 From d9d764056e69619f09171de554526cbddadefea8 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 17 Nov 2009 13:11:53 +1000 Subject: Error checking and tests for them in ListModel --- src/declarative/util/qmllistmodel.cpp | 22 ++++++++++++++-------- .../declarative/qmllistmodel/tst_qmllistmodel.cpp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 9e91147..a3c5c59 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -483,6 +483,10 @@ void QmlListModel::remove(int index) */ void QmlListModel::insert(int index, const QScriptValue& valuemap) { + if (!valuemap.isObject() || valuemap.isArray()) { + qmlInfo(this) << tr("insert: value is not an object"); + return; + } if (!_root) _root = new ModelNode; if (index >= _root->values.count() || index<0) { @@ -517,8 +521,10 @@ void QmlListModel::move(int from, int to, int n) { if (n==0 || from==to) return; - if (from+n > count() || to+n > count() || from < 0 || to < 0) + if (from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0) { qmlInfo(this) << tr("move: out of range"); + return; + } int origfrom=from; // preserve actual move, so any animations are correct int origto=to; int orign=n; @@ -564,7 +570,7 @@ void QmlListModel::move(int from, int to, int n) */ void QmlListModel::append(const QScriptValue& valuemap) { - if (!valuemap.isObject()) { + if (!valuemap.isObject() || valuemap.isArray()) { qmlInfo(this) << tr("append: value is not an object"); return; } @@ -636,9 +642,11 @@ QScriptValue QmlListModel::get(int index) const */ void QmlListModel::set(int index, const QScriptValue& valuemap) { - if (!_root) - _root = new ModelNode; - if ( index > _root->values.count()) { + if (!valuemap.isObject() || valuemap.isArray()) { + qmlInfo(this) << tr("set: value is not an object"); + return; + } + if ( !_root || index > _root->values.count()) { qmlInfo(this) << tr("set: index %1 out of range").arg(index); return; } @@ -677,9 +685,7 @@ void QmlListModel::set(int index, const QScriptValue& valuemap) */ void QmlListModel::set(int index, const QString& property, const QVariant& value) { - if (!_root) - _root = new ModelNode; - if ( index >= _root->values.count()) { + if ( !_root || index >= _root->values.count()) { qmlInfo(this) << tr("set: index %1 out of range").arg(index); return; } diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp index 3222d42..80efd94 100644 --- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp +++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp @@ -64,10 +64,14 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("count") << "count" << 0 << ""; + QTest::newRow("get1") << "{get(0)}" << 0 << "QML QmlListModel (unknown location) get: index 0 out of range"; + QTest::newRow("append1") << "{append({'foo':123});count}" << 1 << ""; QTest::newRow("append2") << "{append({'foo':123,'bar':456});count}" << 1 << ""; QTest::newRow("append3a") << "{append({'foo':123});append({'foo':456});get(0).foo}" << 123 << ""; QTest::newRow("append3b") << "{append({'foo':123});append({'foo':456});get(1).foo}" << 456 << ""; + QTest::newRow("append4a") << "{append(123)}" << 0 << "QML QmlListModel (unknown location) append: value is not an object"; + QTest::newRow("append4b") << "{append([1,2,3])}" << 0 << "QML QmlListModel (unknown location) append: value is not an object"; QTest::newRow("clear1") << "{append({'foo':456});clear();count}" << 0 << ""; QTest::newRow("clear2") << "{append({'foo':123});append({'foo':456});clear();count}" << 0 << ""; @@ -78,6 +82,9 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("remove2b") << "{append({'foo':123});append({'foo':456});remove(0);get(0).foo}" << 456 << ""; QTest::newRow("remove2c") << "{append({'foo':123});append({'foo':456});remove(1);get(0).foo}" << 123 << ""; QTest::newRow("remove3") << "{append({'foo':123});remove(0);get(0).foo}" << 0 << "QML QmlListModel (unknown location) get: index 0 out of range"; + QTest::newRow("remove4a") << "{remove(0)}" << 0 << "QML QmlListModel (unknown location) remove: index 0 out of range"; + QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0)}" << 0 << "QML QmlListModel (unknown location) remove: index 0 out of range"; + QTest::newRow("remove4c") << "{append({'foo':123});remove(1)}" << 0 << "QML QmlListModel (unknown location) remove: index 1 out of range"; QTest::newRow("insert1") << "{insert(0,{'foo':123});count}" << 1 << ""; QTest::newRow("insert2") << "{insert(1,{'foo':123});count}" << 0 << "QML QmlListModel (unknown location) insert: index 1 out of range"; @@ -87,16 +94,23 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("insert3d") << "{append({'foo':123});insert(0,{'foo':456});get(0).foo}" << 456 << ""; QTest::newRow("insert3e") << "{append({'foo':123});insert(0,{'foo':456});get(1).foo}" << 123 << ""; QTest::newRow("insert4") << "{append({'foo':123});insert(-1,{'foo':456})}" << 0 << "QML QmlListModel (unknown location) insert: index -1 out of range"; + QTest::newRow("insert5a") << "{insert(0,123)}" << 0 << "QML QmlListModel (unknown location) insert: value is not an object"; + QTest::newRow("insert5b") << "{insert(0,[1,2,3])}" << 0 << "QML QmlListModel (unknown location) insert: value is not an object"; QTest::newRow("set1") << "{append({'foo':123});set(0,{'foo':456});count}" << 1 << ""; QTest::newRow("set2") << "{append({'foo':123});set(0,{'foo':456});get(0).foo}" << 456 << ""; QTest::newRow("set3a") << "{append({'foo':123,'bar':456});set(0,{'foo':999});get(0).foo}" << 999 << ""; QTest::newRow("set3b") << "{append({'foo':123,'bar':456});set(0,{'foo':999});get(0).bar}" << 456 << ""; + QTest::newRow("set4a") << "{set(0,{'foo':456})}" << 0 << "QML QmlListModel (unknown location) set: index 0 out of range"; + QTest::newRow("set5a") << "{append({'foo':123,'bar':456});set(0,123)}" << 0 << "QML QmlListModel (unknown location) set: value is not an object"; + QTest::newRow("set5b") << "{append({'foo':123,'bar':456});set(0,[1,2,3])}" << 0 << "QML QmlListModel (unknown location) set: value is not an object"; QTest::newRow("setprop1") << "{append({'foo':123});set(0,'foo',456);count}" << 1 << ""; QTest::newRow("setprop2") << "{append({'foo':123});set(0,'foo',456);get(0).foo}" << 456 << ""; QTest::newRow("setprop3a") << "{append({'foo':123,'bar':456});set(0,'foo',999);get(0).foo}" << 999 << ""; QTest::newRow("setprop3b") << "{append({'foo':123,'bar':456});set(0,'foo',999);get(0).bar}" << 456 << ""; + QTest::newRow("setprop4a") << "{set(0,'foo',456)}" << 0 << "QML QmlListModel (unknown location) set: index 0 out of range"; + QTest::newRow("setprop4a") << "{append({'foo':123,'bar':456});set(1,'foo',456)}" << 0 << "QML QmlListModel (unknown location) set: index 1 out of range"; QTest::newRow("move1a") << "{append({'foo':123});append({'foo':456});move(0,1,1);count}" << 2 << ""; QTest::newRow("move1b") << "{append({'foo':123});append({'foo':456});move(0,1,1);get(0).foo}" << 456 << ""; @@ -107,6 +121,10 @@ void tst_QmlListModel::dynamic_data() QTest::newRow("move2b") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(0).foo}" << 789 << ""; QTest::newRow("move2c") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(1).foo}" << 123 << ""; QTest::newRow("move2d") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,1,2);get(2).foo}" << 456 << ""; + QTest::newRow("move3a") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,3)}" << 0 << "QML QmlListModel (unknown location) move: out of range"; + QTest::newRow("move3b") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,-1,1)}" << 0 << "QML QmlListModel (unknown location) move: out of range"; + QTest::newRow("move3c") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(1,0,-1)}" << 0 << "QML QmlListModel (unknown location) move: out of range"; + QTest::newRow("move3d") << "{append({'foo':123});append({'foo':456});append({'foo':789});move(0,3,1)}" << 0 << "QML QmlListModel (unknown location) move: out of range"; // Structured model -- cgit v0.12 From 3307ee4fdf5c79a7f93f4edc8820990bf3432cf0 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 17 Nov 2009 13:24:54 +1000 Subject: Add offset tests and more invalid anchor tests --- tests/auto/declarative/anchors/data/anchors.qml | 18 +++++ tests/auto/declarative/anchors/data/illegal1.qml | 12 --- tests/auto/declarative/anchors/data/illegal2.qml | 13 ---- tests/auto/declarative/anchors/data/illegal3.qml | 12 --- tests/auto/declarative/anchors/tst_anchors.cpp | 96 +++++++++++++++++------- 5 files changed, 86 insertions(+), 65 deletions(-) delete mode 100644 tests/auto/declarative/anchors/data/illegal1.qml delete mode 100644 tests/auto/declarative/anchors/data/illegal2.qml delete mode 100644 tests/auto/declarative/anchors/data/illegal3.qml diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml index b880762..b64d0b0 100644 --- a/tests/auto/declarative/anchors/data/anchors.qml +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -130,6 +130,24 @@ Rectangle { anchors.bottom: masterRect.bottom anchors.bottomMargin: 5 } + Rectangle { + id: rect24; objectName: "rect24" + width: 10; height: 10 + anchors.horizontalCenter: masterRect.left + anchors.horizontalCenterOffset: width/2 + } + Rectangle { + id: rect25; objectName: "rect25" + width: 10; height: 10 + anchors.verticalCenter: rect12.top + anchors.verticalCenterOffset: height/2 + } + Rectangle { + id: rect26; objectName: "rect26" + width: 10; height: 10 + anchors.baseline: masterRect.top + anchors.baselineOffset: height/2 + } Text { id: text1; objectName: "text1" y: 200; diff --git a/tests/auto/declarative/anchors/data/illegal1.qml b/tests/auto/declarative/anchors/data/illegal1.qml deleted file mode 100644 index 53af443..0000000 --- a/tests/auto/declarative/anchors/data/illegal1.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Rectangle { id: theRect; width: 100; height: 100 } - Rectangle { - 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 deleted file mode 100644 index 978be52..0000000 --- a/tests/auto/declarative/anchors/data/illegal2.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Text { id: text1; text: "Hello" } - Text { - 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 deleted file mode 100644 index 065ceb5..0000000 --- a/tests/auto/declarative/anchors/data/illegal3.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: rect - width: 120; height: 200; color: "white" - Item { - Rectangle { id: theRect; width: 100; height: 100 } - } - Rectangle { - anchors.left: theRect.left - } -} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 34c1e01..22f8327 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -60,6 +60,7 @@ private slots: void basicAnchors(); void loops(); void illegalSets(); + void illegalSets_data(); void reset(); void nullItem(); void crash1(); @@ -143,6 +144,11 @@ void tst_anchors::basicAnchors() QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->width(), 86.0); QCOMPARE(findItem(view->root(), QLatin1String("rect23"))->height(), 10.0); + // offsets + QCOMPARE(findItem(view->root(), QLatin1String("rect24"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("rect25"))->y(), 60.0); + QCOMPARE(findItem(view->root(), QLatin1String("rect26"))->y(), 5.0); + //baseline QmlGraphicsText *text1 = findItem(view->root(), QLatin1String("text1")); QmlGraphicsText *text2 = findItem(view->root(), QLatin1String("text2")); @@ -185,44 +191,71 @@ void tst_anchors::loops() void tst_anchors::illegalSets() { - { - QmlView *view = new QmlView; + QFETCH(QString, qml); + QFETCH(QString, warning); + + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1()); + + QmlEngine engine; + QmlComponent component(&engine, QByteArray("import Qt 4.6\n" + qml.toUtf8()), QUrl("file://")); + if (!component.isReady()) + qWarning() << "Test errors:" << component.errors(); + QVERIFY(component.isReady()); + QObject *o = component.create(); + delete o; +} - view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); +void tst_anchors::illegalSets_data() +{ + QTest::addColumn("qml"); + QTest::addColumn("warning"); - QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - qApp->processEvents(); + QTest::newRow("H - too many anchors") + << "Rectangle { id: rect; Rectangle { anchors.left: rect.left; anchors.right: rect.right; anchors.horizontalCenter: rect.horizontalCenter } }" + << "QML QmlGraphicsRectangle (file::2:23) Can't specify left, right, and hcenter anchors."; - delete view; - } + QTest::newRow("H - anchor to V") + << "Rectangle { Rectangle { anchors.left: parent.top } }" + << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a horizontal edge to a vertical edge."; - { - QmlView *view = new QmlView; + QTest::newRow("H - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.left: rect.left } }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; - view->setUrl(QUrl("file://" SRCDIR "/data/illegal2.qml")); + QTest::newRow("H - anchor to self") + << "Rectangle { id: rect; anchors.left: rect.left }" + << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self."; - QString expect = "QML QmlGraphicsText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - //qApp->processEvents(); - delete view; - } + QTest::newRow("V - too many anchors") + << "Rectangle { id: rect; Rectangle { anchors.top: rect.top; anchors.bottom: rect.bottom; anchors.verticalCenter: rect.verticalCenter } }" + << "QML QmlGraphicsRectangle (file::2:23) Can't specify top, bottom, and vcenter anchors."; - { - QmlView *view = new QmlView; + QTest::newRow("V - too many anchors with baseline") + << "Rectangle { Text { id: text1; text: \"Hello\" } Text { anchors.baseline: text1.baseline; anchors.top: text1.top; } }" + << "QML QmlGraphicsText (file::2:47) Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; - view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); + QTest::newRow("V - anchor to H") + << "Rectangle { Rectangle { anchors.top: parent.left } }" + << "QML QmlGraphicsRectangle (file::2:13) Can't anchor a vertical edge to a horizontal edge."; - QString expect = "QML QmlGraphicsRectangle (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; - QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); - view->execute(); - //qApp->processEvents(); + QTest::newRow("V - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.top: rect.top } }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; - delete view; - } + QTest::newRow("V - anchor to self") + << "Rectangle { id: rect; anchors.top: rect.top }" + << "QML QmlGraphicsRectangle (file::2:1) Can't anchor item to self."; + + + QTest::newRow("centerIn - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.centerIn: rect} }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; + + + QTest::newRow("fill - anchor to non parent/sibling") + << "Rectangle { Item { Rectangle { id: rect } } Rectangle { anchors.fill: rect} }" + << "QML QmlGraphicsRectangle (file::2:45) Can't anchor to an item that isn't a parent or sibling."; } void tst_anchors::reset() @@ -243,10 +276,17 @@ void tst_anchors::reset() void tst_anchors::nullItem() { QmlGraphicsAnchorLine anchor; + QmlGraphicsItem *item; QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item."); - QmlGraphicsItem *item = new QmlGraphicsItem; + item = new QmlGraphicsItem; + item->anchors()->setLeft(anchor); + delete item; + + QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item."); + item = new QmlGraphicsItem; item->anchors()->setBottom(anchor); + delete item; } void tst_anchors::crash1() -- cgit v0.12 From 987819bf3d28e18a51ad9f654bf25903650d7ee4 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 17 Nov 2009 13:33:07 +1000 Subject: QmlInstruction autotest --- src/declarative/qml/qmlcompileddata.cpp | 6 +- src/declarative/qml/qmlcompiler_p.h | 2 +- src/declarative/qml/qmlinstruction.cpp | 111 ++-- src/declarative/qml/qmlinstruction_p.h | 2 +- src/declarative/qml/qmlrefcount_p.h | 2 +- tests/auto/declarative/declarative.pro | 1 + .../declarative/qmlinstruction/qmlinstruction.pro | 6 + .../qmlinstruction/tst_qmlinstruction.cpp | 609 +++++++++++++++++++++ 8 files changed, 686 insertions(+), 53 deletions(-) create mode 100644 tests/auto/declarative/qmlinstruction/qmlinstruction.pro create mode 100644 tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp diff --git a/src/declarative/qml/qmlcompileddata.cpp b/src/declarative/qml/qmlcompileddata.cpp index f587053..44d2745 100644 --- a/src/declarative/qml/qmlcompileddata.cpp +++ b/src/declarative/qml/qmlcompileddata.cpp @@ -197,12 +197,12 @@ void QmlCompiledData::dumpInstructions() { if (!name.isEmpty()) qWarning() << name; - qWarning() << "Index\tLine\tOperation\t\tData1\tData2\t\tComments"; - qWarning() << "-------------------------------------------------------------------------------"; + qWarning().nospace() << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments"; + qWarning().nospace() << "-------------------------------------------------------------------------------"; for (int ii = 0; ii < bytecode.count(); ++ii) { dump(&bytecode[ii], ii); } - qWarning() << "-------------------------------------------------------------------------------"; + qWarning().nospace() << "-------------------------------------------------------------------------------"; } diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index 8f28ac9..9597753 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -73,7 +73,7 @@ class QmlComponent; class QmlContext; class QScriptProgram; -class QmlCompiledData : public QmlRefCount +class Q_AUTOTEST_EXPORT QmlCompiledData : public QmlRefCount { public: QmlCompiledData(); diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index dd075a8..6bab1c4 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -54,145 +54,162 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx) switch(instr->type) { case QmlInstruction::Init: - qWarning() << idx << "\t" << line << "\t" << "INIT"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "INIT"; break; case QmlInstruction::CreateObject: - qWarning() << idx << "\t" << line << "\t" << "CREATE\t\t\t" << instr->create.type << "\t\t\t" << types.at(instr->create.type).className; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "CREATE\t\t\t" << instr->create.type << "\t\t\t" << types.at(instr->create.type).className; break; case QmlInstruction::SetId: - qWarning() << idx << "\t" << line << "\t" << "SETID\t\t\t" << instr->setId.value << "\t\t\t\t" << primitives.at(instr->setId.value); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "SETID\t\t\t" << instr->setId.value << "\t\t\t" << primitives.at(instr->setId.value); break; case QmlInstruction::SetDefault: - qWarning() << idx << "\t" << line << "\t" << "SET_DEFAULT"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "SET_DEFAULT"; break; case QmlInstruction::CreateComponent: - qWarning() << idx << "\t" << line << "\t" << "CREATE_COMPONENT\t" << instr->createComponent.count; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "CREATE_COMPONENT\t" << instr->createComponent.count; break; case QmlInstruction::StoreMetaObject: - qWarning() << idx << "\t" << line << "\t" << "STORE_META\t\t" << instr->storeMeta.data << "\t"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_META\t\t" << instr->storeMeta.data; break; + case QmlInstruction::StoreFloat: - qWarning() << idx << "\t" << line << "\t" << "STORE_FLOAT\t\t" << instr->storeFloat.propertyIndex << "\t" << instr->storeFloat.value; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_FLOAT\t\t" << instr->storeFloat.propertyIndex << "\t" << instr->storeFloat.value; break; case QmlInstruction::StoreDouble: - qWarning() << idx << "\t" << line << "\t" << "STORE_DOUBLE\t\t" << instr->storeDouble.propertyIndex << "\t" << instr->storeDouble.value; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_DOUBLE\t\t" << instr->storeDouble.propertyIndex << "\t" << instr->storeDouble.value; break; case QmlInstruction::StoreInteger: - qWarning() << idx << "\t" << line << "\t" << "STORE_INTEGER\t\t" << instr->storeInteger.propertyIndex << "\t" << instr->storeInteger.value; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_INTEGER\t\t" << instr->storeInteger.propertyIndex << "\t" << instr->storeInteger.value; break; case QmlInstruction::StoreBool: - qWarning() << idx << "\t" << line << "\t" << "STORE_BOOL\t\t" << instr->storeBool.propertyIndex << "\t" << instr->storeBool.value; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_BOOL\t\t" << instr->storeBool.propertyIndex << "\t" << instr->storeBool.value; break; case QmlInstruction::StoreString: - qWarning() << idx << "\t" << line << "\t" << "STORE_STRING\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_STRING\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); break; case QmlInstruction::StoreUrl: - qWarning() << idx << "\t" << line << "\t" << "STORE_URL\t\t" << instr->storeUrl.propertyIndex << "\t" << instr->storeUrl.value << "\t\t" << primitives.at(instr->storeUrl.value); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_URL\t\t" << instr->storeUrl.propertyIndex << "\t" << instr->storeUrl.value << "\t\t" << primitives.at(instr->storeUrl.value); break; case QmlInstruction::StoreColor: - qWarning() << idx << "\t" << line << "\t" << "STORE_COLOR\t\t" << instr->storeColor.propertyIndex << "\t" << QString::number(instr->storeColor.value, 16); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_COLOR\t\t" << instr->storeColor.propertyIndex << "\t\t\t" << QString::number(instr->storeColor.value, 16); break; case QmlInstruction::StoreDate: - qWarning() << idx << "\t" << line << "\t" << "STORE_DATE\t\t" << instr->storeDate.propertyIndex << "\t" << instr->storeDate.value; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_DATE\t\t" << instr->storeDate.propertyIndex << "\t" << instr->storeDate.value; break; case QmlInstruction::StoreTime: - qWarning() << idx << "\t" << line << "\t" << "STORE_TIME\t\t" << instr->storeTime.propertyIndex << "\t" << instr->storeTime.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_TIME\t\t" << instr->storeTime.propertyIndex << "\t" << instr->storeTime.valueIndex; break; case QmlInstruction::StoreDateTime: - qWarning() << idx << "\t" << line << "\t" << "STORE_DATETIME\t\t" << instr->storeDateTime.propertyIndex << "\t" << instr->storeDateTime.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_DATETIME\t\t" << instr->storeDateTime.propertyIndex << "\t" << instr->storeDateTime.valueIndex; break; case QmlInstruction::StorePoint: - qWarning() << idx << "\t" << line << "\t" << "STORE_POINT\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_POINT\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; break; case QmlInstruction::StorePointF: - qWarning() << idx << "\t" << line << "\t" << "STORE_POINTF\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_POINTF\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; break; case QmlInstruction::StoreSize: - qWarning() << idx << "\t" << line << "\t" << "STORE_SIZE\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SIZE\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; break; case QmlInstruction::StoreSizeF: - qWarning() << idx << "\t" << line << "\t" << "STORE_SIZEF\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SIZEF\t\t" << instr->storeRealPair.propertyIndex << "\t" << instr->storeRealPair.valueIndex; break; case QmlInstruction::StoreRect: - qWarning() << idx << "\t" << line << "\t" << "STORE_RECT\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_RECT\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex; break; case QmlInstruction::StoreRectF: - qWarning() << idx << "\t" << line << "\t" << "STORE_RECTF\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_RECTF\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex; break; case QmlInstruction::StoreVector3D: - qWarning() << idx << "\t" << line << "\t" << "STORE_VECTOR3D\t\t" << instr->storeVector3D.propertyIndex << "\t" << instr->storeVector3D.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VECTOR3D\t\t" << instr->storeVector3D.propertyIndex << "\t" << instr->storeVector3D.valueIndex; break; case QmlInstruction::StoreVariant: - qWarning() << idx << "\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); break; case QmlInstruction::StoreObject: - qWarning() << idx << "\t" << line << "\t" << "STORE_OBJECT\t\t" << instr->storeObject.propertyIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT\t\t" << instr->storeObject.propertyIndex; break; case QmlInstruction::StoreVariantObject: - qWarning() << idx << "\t" << line << "\t" << "STORE_VARIANT_OBJECT\t" << instr->storeObject.propertyIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VARIANT_OBJECT\t" << instr->storeObject.propertyIndex; break; case QmlInstruction::StoreInterface: - qWarning() << idx << "\t" << line << "\t" << "STORE_INTERFACE\t\t" << instr->storeObject.propertyIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_INTERFACE\t\t" << instr->storeObject.propertyIndex; break; + case QmlInstruction::StoreSignal: - qWarning() << idx << "\t" << line << "\t" << "STORE_SIGNAL\t\t" << instr->storeSignal.signalIndex << "\t" << instr->storeSignal.value << "\t\t" << primitives.at(instr->storeSignal.value); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SIGNAL\t\t" << instr->storeSignal.signalIndex << "\t" << instr->storeSignal.value << "\t\t" << primitives.at(instr->storeSignal.value); + break; + case QmlInstruction::StoreScript: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SCRIPT\t\t" << instr->storeScript.value << "\t" << instr->storeScript.fileName << "\t" << instr->storeScript.lineNumber; break; + case QmlInstruction::StoreScriptString: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_SCRIPT_STRING\t" << instr->storeScriptString.propertyIndex << "\t" << instr->storeScriptString.value << "\t" << instr->storeScriptString.scope; + break; + case QmlInstruction::AssignSignalObject: - qWarning() << idx << "\t" << line << "\t" << "ASSIGN_SIGNAL_OBJECT\t" << instr->assignSignalObject.signal << "\t\t\t" << datas.at(instr->assignSignalObject.signal); + qWarning().nospace() << idx << "\t\t" << line << "\t" << "ASSIGN_SIGNAL_OBJECT\t" << instr->assignSignalObject.signal << "\t\t\t" << datas.at(instr->assignSignalObject.signal); break; case QmlInstruction::AssignCustomType: - qWarning() << idx << "\t" << line << "\t" << "ASSIGN_CUSTOMTYPE\t\t" << instr->assignCustomType.propertyIndex << "\t" << instr->assignCustomType.valueIndex; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "ASSIGN_CUSTOMTYPE\t" << instr->assignCustomType.propertyIndex << "\t" << instr->assignCustomType.valueIndex; break; + case QmlInstruction::StoreBinding: - qWarning() << idx << "\t" << line << "\t" << "STORE_COMPILED_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t\t" << instr->assignBinding.context; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_COMPILED_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context; + break; + case QmlInstruction::StoreIdOptBinding: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_ID_OPT_BINDING\t" << instr->assignIdOptBinding.property << "\t" << instr->assignIdOptBinding.id; + break; + case QmlInstruction::StoreObjPropBinding: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJ_PROP_BINDING\t" << instr->assignObjPropBinding.property << "\t" << instr->assignObjPropBinding.contextIdx << "\t" << instr->assignObjPropBinding.context << "\t" << instr->assignObjPropBinding.notifyIdx; break; case QmlInstruction::StoreValueSource: - qWarning() << idx << "\t" << line << "\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property << "\t" << instr->assignValueSource.castValue; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property << "\t" << instr->assignValueSource.castValue; break; case QmlInstruction::StoreValueInterceptor: - qWarning() << idx << "\t" << line << "\t" << "STORE_VALUE_INTERCEPTOR\t" << instr->assignValueInterceptor.property << "\t" << instr->assignValueInterceptor.castValue; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VALUE_INTERCEPTOR\t" << instr->assignValueInterceptor.property << "\t" << instr->assignValueInterceptor.castValue; break; + case QmlInstruction::BeginObject: - qWarning() << idx << "\t" << line << "\t" << "BEGIN\t\t\t" << instr->begin.castValue; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "BEGIN\t\t\t" << instr->begin.castValue; break; case QmlInstruction::StoreObjectQmlList: - qWarning() << idx << "\t" << line << "\t" << "STORE_OBJECT_QMLLIST"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT_QMLLIST"; break; case QmlInstruction::StoreObjectQList: - qWarning() << idx << "\t" << line << "\t" << "STORE_OBJECT_QLIST"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT_QLIST"; break; case QmlInstruction::AssignObjectList: - qWarning() << idx << "\t" << line << "\t" << "ASSIGN_OBJECT_LIST\t"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "ASSIGN_OBJECT_LIST"; break; case QmlInstruction::FetchAttached: - qWarning() << idx << "\t" << line << "\t" << "FETCH_ATTACHED\t\t" << instr->fetchAttached.id; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_ATTACHED\t\t" << instr->fetchAttached.id; break; case QmlInstruction::FetchQmlList: - qWarning() << idx << "\t" << line << "\t" << "FETCH_QMLLIST\t\t" << instr->fetchQmlList.property << "\t" << instr->fetchQmlList.type; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_QMLLIST\t\t" << instr->fetchQmlList.property << "\t" << instr->fetchQmlList.type; break; case QmlInstruction::FetchQList: - qWarning() << idx << "\t" << line << "\t" << "FETCH_QLIST\t\t" << instr->fetch.property; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_QLIST\t\t" << instr->fetch.property; break; case QmlInstruction::FetchObject: - qWarning() << idx << "\t" << line << "\t" << "FETCH\t\t\t" << instr->fetch.property; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH\t\t\t" << instr->fetch.property; break; case QmlInstruction::FetchValueType: - qWarning() << idx << "\t" << line << "\t" << "FETCH_VALUE\t\t" << instr->fetchValue.property << "\t" << instr->fetchValue.type; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_VALUE\t\t" << instr->fetchValue.property << "\t" << instr->fetchValue.type; break; case QmlInstruction::PopFetchedObject: - qWarning() << idx << "\t" << line << "\t" << "POP"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "POP"; break; case QmlInstruction::PopQList: - qWarning() << idx << "\t" << line << "\t" << "POP_QLIST"; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "POP_QLIST"; break; case QmlInstruction::PopValueType: - qWarning() << idx << "\t" << line << "\t" << "POP_VALUE\t\t" << instr->fetchValue.property << "\t" << instr->fetchValue.type; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "POP_VALUE\t\t" << instr->fetchValue.property << "\t" << instr->fetchValue.type; break; case QmlInstruction::Defer: - qWarning() << idx << "\t" << line << "\t" << "DEFER" << "\t\t" << instr->defer.deferCount; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "DEFER" << "\t\t\t" << instr->defer.deferCount; break; default: - qWarning() << idx << "\t" << line << "\t" << "XXX UNKOWN INSTRUCTION" << "\t" << instr->type; + qWarning().nospace() << idx << "\t\t" << line << "\t" << "XXX UNKOWN INSTRUCTION" << "\t" << instr->type; break; } } diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 15e4fdf..50d4b62 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -194,7 +194,7 @@ public: int property; int owner; int castValue; - } assignValueInterceptor; //### merge with above + } assignValueInterceptor; struct { int property; int value; diff --git a/src/declarative/qml/qmlrefcount_p.h b/src/declarative/qml/qmlrefcount_p.h index cd6afd3..7448042 100644 --- a/src/declarative/qml/qmlrefcount_p.h +++ b/src/declarative/qml/qmlrefcount_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QmlRefCount +class Q_AUTOTEST_EXPORT QmlRefCount { public: QmlRefCount(); diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index ec2c7d0..c0e4b6b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -36,6 +36,7 @@ SUBDIRS += \ qmlgraphicstextinput \ # Cover qmlgraphicswebview \ # Cover qmlinfo \ # Cover + qmlinstruction \ # Cover qmllanguage \ # Cover qmllist \ # Cover qmllistaccessor \ # Cover diff --git a/tests/auto/declarative/qmlinstruction/qmlinstruction.pro b/tests/auto/declarative/qmlinstruction/qmlinstruction.pro new file mode 100644 index 0000000..41be488 --- /dev/null +++ b/tests/auto/declarative/qmlinstruction/qmlinstruction.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative script +SOURCES += tst_qmlinstruction.cpp +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp b/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp new file mode 100644 index 0000000..f493e0e --- /dev/null +++ b/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp @@ -0,0 +1,609 @@ +/**************************************************************************** +** +** 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 + +class tst_qmlinstruction : public QObject +{ + Q_OBJECT +public: + tst_qmlinstruction() {} + +private slots: + void dump(); +}; + +static QStringList messages; +static void msgHandler(QtMsgType, const char *msg) +{ + messages << QLatin1String(msg); +} + +void tst_qmlinstruction::dump() +{ + QmlCompiledData *data = new QmlCompiledData; + { + QmlInstruction i; + i.line = 0; + i.type = QmlInstruction::Init; + data->bytecode << i; + } + + { + QmlCompiledData::TypeReference ref; + ref.className = "Test"; + data->types << ref; + + QmlInstruction i; + i.line = 1; + i.type = QmlInstruction::CreateObject; + i.create.type = 0; + i.create.data = -1; + i.create.bindingBits = -1; + i.create.column = 10; + data->bytecode << i; + } + + { + data->primitives << "testId"; + + QmlInstruction i; + i.line = 2; + i.type = QmlInstruction::SetId; + i.setId.value = 0; + i.setId.index = 0; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 3; + i.type = QmlInstruction::SetDefault; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 4; + i.type = QmlInstruction::CreateComponent; + i.createComponent.count = 3; + i.createComponent.column = 4; + i.createComponent.endLine = 14; + i.createComponent.metaObject = 0; + + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 5; + i.type = QmlInstruction::StoreMetaObject; + i.storeMeta.data = 3; + i.storeMeta.aliasData = 6; + i.storeMeta.propertyCache = 7; + + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 6; + i.type = QmlInstruction::StoreFloat; + i.storeFloat.propertyIndex = 3; + i.storeFloat.value = 11.3; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 7; + i.type = QmlInstruction::StoreDouble; + i.storeDouble.propertyIndex = 4; + i.storeDouble.value = 14.8; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 8; + i.type = QmlInstruction::StoreInteger; + i.storeInteger.propertyIndex = 5; + i.storeInteger.value = 9; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 9; + i.type = QmlInstruction::StoreBool; + i.storeBool.propertyIndex = 6; + i.storeBool.value = true; + + data->bytecode << i; + } + + { + data->primitives << "Test String"; + QmlInstruction i; + i.line = 10; + i.type = QmlInstruction::StoreString; + i.storeString.propertyIndex = 7; + i.storeString.value = 1; + data->bytecode << i; + } + + { + data->primitives << "http://www.nokia.com"; + QmlInstruction i; + i.line = 11; + i.type = QmlInstruction::StoreUrl; + i.storeUrl.propertyIndex = 8; + i.storeUrl.value = 2; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 12; + i.type = QmlInstruction::StoreColor; + i.storeColor.propertyIndex = 9; + i.storeColor.value = 0xFF00FF00; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 13; + i.type = QmlInstruction::StoreDate; + i.storeDate.propertyIndex = 10; + i.storeDate.value = 9; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 14; + i.type = QmlInstruction::StoreTime; + i.storeTime.propertyIndex = 11; + i.storeTime.valueIndex = 33; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 15; + i.type = QmlInstruction::StoreDateTime; + i.storeDateTime.propertyIndex = 12; + i.storeDateTime.valueIndex = 44; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 16; + i.type = QmlInstruction::StorePoint; + i.storeRealPair.propertyIndex = 13; + i.storeRealPair.valueIndex = 3; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 17; + i.type = QmlInstruction::StorePointF; + i.storeRealPair.propertyIndex = 14; + i.storeRealPair.valueIndex = 9; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 18; + i.type = QmlInstruction::StoreSize; + i.storeRealPair.propertyIndex = 15; + i.storeRealPair.valueIndex = 8; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 19; + i.type = QmlInstruction::StoreSizeF; + i.storeRealPair.propertyIndex = 16; + i.storeRealPair.valueIndex = 99; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 20; + i.type = QmlInstruction::StoreRect; + i.storeRect.propertyIndex = 17; + i.storeRect.valueIndex = 2; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 21; + i.type = QmlInstruction::StoreRectF; + i.storeRect.propertyIndex = 18; + i.storeRect.valueIndex = 19; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 22; + i.type = QmlInstruction::StoreVector3D; + i.storeVector3D.propertyIndex = 19; + i.storeVector3D.valueIndex = 9; + data->bytecode << i; + } + + { + data->primitives << "color(1, 1, 1, 1)"; + QmlInstruction i; + i.line = 23; + i.type = QmlInstruction::StoreVariant; + i.storeString.propertyIndex = 20; + i.storeString.value = 3; + + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 24; + i.type = QmlInstruction::StoreObject; + i.storeObject.propertyIndex = 21; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 25; + i.type = QmlInstruction::StoreVariantObject; + i.storeObject.propertyIndex = 22; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 26; + i.type = QmlInstruction::StoreInterface; + i.storeObject.propertyIndex = 23; + data->bytecode << i; + } + + { + data->primitives << "print(1921)"; + + QmlInstruction i; + i.line = 27; + i.type = QmlInstruction::StoreSignal; + i.storeSignal.signalIndex = 2; + i.storeSignal.value = 4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 28; + i.type = QmlInstruction::StoreScript; + i.storeScript.value = 2; + i.storeScript.fileName = 18; + i.storeScript.lineNumber = 28; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 29; + i.type = QmlInstruction::StoreScriptString; + i.storeScriptString.propertyIndex = 24; + i.storeScriptString.value = 3; + i.storeScriptString.scope = 1; + data->bytecode << i; + } + + { + data->datas << "mySignal"; + + QmlInstruction i; + i.line = 30; + i.type = QmlInstruction::AssignSignalObject; + i.assignSignalObject.signal = 0; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 31; + i.type = QmlInstruction::AssignCustomType; + i.assignCustomType.propertyIndex = 25; + i.assignCustomType.valueIndex = 4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 32; + i.type = QmlInstruction::StoreBinding; + i.assignBinding.property = 26; + i.assignBinding.value = 3; + i.assignBinding.context = 2; + i.assignBinding.owner = 0; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 33; + i.type = QmlInstruction::StoreIdOptBinding; + i.assignIdOptBinding.property = 27; + i.assignIdOptBinding.id = 2; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 34; + i.type = QmlInstruction::StoreObjPropBinding; + i.assignObjPropBinding.property = 28; + i.assignObjPropBinding.contextIdx = 3; + i.assignObjPropBinding.context = 7; + i.assignObjPropBinding.notifyIdx = 4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 35; + i.type = QmlInstruction::StoreValueSource; + i.assignValueSource.property = 29; + i.assignValueSource.owner = 1; + i.assignValueSource.castValue = 4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 36; + i.type = QmlInstruction::StoreValueInterceptor; + i.assignValueInterceptor.property = 30; + i.assignValueInterceptor.owner = 2; + i.assignValueInterceptor.castValue = -4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 37; + i.type = QmlInstruction::BeginObject; + i.begin.castValue = 4; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 38; + i.type = QmlInstruction::StoreObjectQmlList; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 39; + i.type = QmlInstruction::StoreObjectQList; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 40; + i.type = QmlInstruction::AssignObjectList; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 41; + i.type = QmlInstruction::FetchAttached; + i.fetchAttached.id = 23; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 42; + i.type = QmlInstruction::FetchQmlList; + i.fetchQmlList.property = 31; + i.fetchQmlList.type = 3; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 43; + i.type = QmlInstruction::FetchQList; + i.fetch.property = 32; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 44; + i.type = QmlInstruction::FetchObject; + i.fetch.property = 33; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 45; + i.type = QmlInstruction::FetchValueType; + i.fetchValue.property = 34; + i.fetchValue.type = 6; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 46; + i.type = QmlInstruction::PopFetchedObject; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 47; + i.type = QmlInstruction::PopQList; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 48; + i.type = QmlInstruction::PopValueType; + i.fetchValue.property = 35; + i.fetchValue.type = 8; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 49; + i.type = QmlInstruction::Defer; + i.defer.deferCount = 7; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = -1; + i.type = QmlInstruction::Defer; + i.defer.deferCount = 7; + data->bytecode << i; + } + + { + QmlInstruction i; + i.line = 50; + i.type = (QmlInstruction::Type)(QmlInstruction::Defer + 1); // Non-existant + data->bytecode << i; + } + + QStringList expect; + expect + << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments" + << "-------------------------------------------------------------------------------" + << "0\t\t0\tINIT" + << "1\t\t1\tCREATE\t\t\t0\t\t\t\"Test\"" + << "2\t\t2\tSETID\t\t\t0\t\t\t\"testId\"" + << "3\t\t3\tSET_DEFAULT" + << "4\t\t4\tCREATE_COMPONENT\t3" + << "5\t\t5\tSTORE_META\t\t3" + << "6\t\t6\tSTORE_FLOAT\t\t3\t11.3" + << "7\t\t7\tSTORE_DOUBLE\t\t4\t14.8" + << "8\t\t8\tSTORE_INTEGER\t\t5\t9" + << "9\t\t9\tSTORE_BOOL\t\t6\ttrue" + << "10\t\t10\tSTORE_STRING\t\t7\t1\t\t\"Test String\"" + << "11\t\t11\tSTORE_URL\t\t8\t2\t\t\"http://www.nokia.com\"" + << "12\t\t12\tSTORE_COLOR\t\t9\t\t\t\"ff00ff00\"" + << "13\t\t13\tSTORE_DATE\t\t10\t9" + << "14\t\t14\tSTORE_TIME\t\t11\t33" + << "15\t\t15\tSTORE_DATETIME\t\t12\t44" + << "16\t\t16\tSTORE_POINT\t\t13\t3" + << "17\t\t17\tSTORE_POINTF\t\t14\t9" + << "18\t\t18\tSTORE_SIZE\t\t15\t8" + << "19\t\t19\tSTORE_SIZEF\t\t16\t99" + << "20\t\t20\tSTORE_RECT\t\t17\t2" + << "21\t\t21\tSTORE_RECTF\t\t18\t19" + << "22\t\t22\tSTORE_VECTOR3D\t\t19\t9" + << "23\t\t23\tSTORE_VARIANT\t\t20\t3\t\t\"color(1, 1, 1, 1)\"" + << "24\t\t24\tSTORE_OBJECT\t\t21" + << "25\t\t25\tSTORE_VARIANT_OBJECT\t22" + << "26\t\t26\tSTORE_INTERFACE\t\t23" + << "27\t\t27\tSTORE_SIGNAL\t\t2\t4\t\t\"print(1921)\"" + << "28\t\t28\tSTORE_SCRIPT\t\t2\t18\t28" + << "29\t\t29\tSTORE_SCRIPT_STRING\t24\t3\t1" + << "30\t\t30\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\"" + << "31\t\t31\tASSIGN_CUSTOMTYPE\t25\t4" + << "32\t\t32\tSTORE_COMPILED_BINDING\t26\t3\t2" + << "33\t\t33\tSTORE_ID_OPT_BINDING\t27\t2" + << "34\t\t34\tSTORE_OBJ_PROP_BINDING\t28\t3\t7\t4" + << "35\t\t35\tSTORE_VALUE_SOURCE\t29\t4" + << "36\t\t36\tSTORE_VALUE_INTERCEPTOR\t30\t-4" + << "37\t\t37\tBEGIN\t\t\t4" + << "38\t\t38\tSTORE_OBJECT_QMLLIST" + << "39\t\t39\tSTORE_OBJECT_QLIST" + << "40\t\t40\tASSIGN_OBJECT_LIST" + << "41\t\t41\tFETCH_ATTACHED\t\t23" + << "42\t\t42\tFETCH_QMLLIST\t\t31\t3" + << "43\t\t43\tFETCH_QLIST\t\t32" + << "44\t\t44\tFETCH\t\t\t33" + << "45\t\t45\tFETCH_VALUE\t\t34\t6" + << "46\t\t46\tPOP" + << "47\t\t47\tPOP_QLIST" + << "48\t\t48\tPOP_VALUE\t\t35\t8" + << "49\t\t49\tDEFER\t\t\t7" + << "50\t\tNA\tDEFER\t\t\t7" + << "51\t\t50\tXXX UNKOWN INSTRUCTION\t50" + << "-------------------------------------------------------------------------------"; + + messages = QStringList(); + QtMsgHandler old = qInstallMsgHandler(msgHandler); + data->dumpInstructions(); + qInstallMsgHandler(old); + + QCOMPARE(messages.count(), expect.count()); + for (int ii = 0; ii < messages.count(); ++ii) { + QCOMPARE(messages.at(ii), expect.at(ii)); + } + + data->release(); +} + +QTEST_MAIN(tst_qmlinstruction) + +#include "tst_qmlinstruction.moc" -- cgit v0.12 From a493a5e104579c0a7908fc600be1fd622d6447ae Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 17 Nov 2009 13:47:16 +1000 Subject: Move debugger tests out of debugger/ subdir --- tests/auto/declarative/debugger/debugger.pro | 5 - tests/auto/declarative/debugger/debugutil.cpp | 173 ----- tests/auto/declarative/debugger/debugutil_p.h | 142 ---- .../declarative/debugger/qmldebug/qmldebug.pro | 7 - .../declarative/debugger/qmldebug/tst_qmldebug.cpp | 831 --------------------- .../debugger/qmldebugclient/qmldebugclient.pro | 7 - .../debugger/qmldebugclient/tst_qmldebugclient.cpp | 156 ---- .../debugger/qmldebugservice/qmldebugservice.pro | 7 - .../qmldebugservice/tst_qmldebugservice.cpp | 189 ----- .../debugger/qpacketprotocol/qpacketprotocol.pro | 7 - .../qpacketprotocol/tst_qpacketprotocol.cpp | 270 ------- tests/auto/declarative/declarative.pro | 7 +- tests/auto/declarative/qmldebug/qmldebug.pro | 7 + tests/auto/declarative/qmldebug/tst_qmldebug.cpp | 831 +++++++++++++++++++++ .../declarative/qmldebugclient/qmldebugclient.pro | 7 + .../qmldebugclient/tst_qmldebugclient.cpp | 156 ++++ .../qmldebugservice/qmldebugservice.pro | 7 + .../qmldebugservice/tst_qmldebugservice.cpp | 189 +++++ .../qpacketprotocol/qpacketprotocol.pro | 7 + .../qpacketprotocol/tst_qpacketprotocol.cpp | 270 +++++++ 20 files changed, 1478 insertions(+), 1797 deletions(-) delete mode 100644 tests/auto/declarative/debugger/debugger.pro delete mode 100644 tests/auto/declarative/debugger/debugutil.cpp delete mode 100644 tests/auto/declarative/debugger/debugutil_p.h delete mode 100644 tests/auto/declarative/debugger/qmldebug/qmldebug.pro delete mode 100644 tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp delete mode 100644 tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro delete mode 100644 tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp delete mode 100644 tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro delete mode 100644 tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp delete mode 100644 tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro delete mode 100644 tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp create mode 100644 tests/auto/declarative/qmldebug/qmldebug.pro create mode 100644 tests/auto/declarative/qmldebug/tst_qmldebug.cpp create mode 100644 tests/auto/declarative/qmldebugclient/qmldebugclient.pro create mode 100644 tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp create mode 100644 tests/auto/declarative/qmldebugservice/qmldebugservice.pro create mode 100644 tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp create mode 100644 tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro create mode 100644 tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp diff --git a/tests/auto/declarative/debugger/debugger.pro b/tests/auto/declarative/debugger/debugger.pro deleted file mode 100644 index a341ca9..0000000 --- a/tests/auto/declarative/debugger/debugger.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS += qmldebug \ - qmldebugclient \ - qmldebugservice \ - qpacketprotocol diff --git a/tests/auto/declarative/debugger/debugutil.cpp b/tests/auto/declarative/debugger/debugutil.cpp deleted file mode 100644 index 7008529..0000000 --- a/tests/auto/declarative/debugger/debugutil.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** 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/debugger/debugutil_p.h b/tests/auto/declarative/debugger/debugutil_p.h deleted file mode 100644 index 665aeda..0000000 --- a/tests/auto/declarative/debugger/debugutil_p.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** 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; -}; - - diff --git a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro deleted file mode 100644 index 0af30e1..0000000 --- a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebug.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp deleted file mode 100644 index 70404f6..0000000 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ /dev/null @@ -1,831 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "../debugutil_p.h" - -Q_DECLARE_METATYPE(QmlDebugWatch::State) - - -class tst_QmlDebug : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebug(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - m_rootItem = data->items[0]; - } - -private: - QmlDebugObjectReference findRootObject(); - QmlDebugPropertyReference findProperty(const QList &props, const QString &name) 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; - -private slots: - void initTestCase(); - - void watch_property(); - void watch_object(); - void watch_expression(); - void watch_expression_data(); - void watch_context(); - void watch_file(); - - 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 &props, const QString &name) const -{ - foreach(const QmlDebugPropertyReference &p, props) { - if (p.name() == name) - return p; - } - return QmlDebugPropertyReference(); -} - -void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) -{ - QVERIFY(query); - QCOMPARE(query->parent(), this); - QVERIFY(query->state() == QmlDebugQuery::Waiting); - if (!QmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) - 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))); - - const QObjectList &children = o->children(); - for (int i=0; i= 0); - - QmlDebugObjectReference cref; - foreach (const QmlDebugObjectReference &ref, oref.children()) { - if (ref.debugId() == debugId) { - cref = ref; - break; - } - } - QVERIFY(cref.debugId() >= 0); - - if (recursive) - recursiveObjectTest(child, cref, true); - } - - foreach (const QmlDebugPropertyReference &p, oref.properties()) { - QCOMPARE(p.objectDebugId(), QmlDebugService::idForObject(o)); - - // signal properties are fake - they are generated from QmlBoundSignal children - if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { - QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); - QVERIFY(p.valueTypeName().isEmpty()); - QVERIFY(p.binding().isEmpty()); - QVERIFY(!p.hasNotifySignal()); - continue; - } - - QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); - - 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()); - - QVERIFY(pmeta.isValid()); - } -} - -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 aprops = a.properties(); - QList bprops = b.properties(); - - for (int i=0; i(); -} - -void tst_QmlDebug::watch_property() -{ - QmlDebugObjectReference obj = findRootObject(); - QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); - - QmlDebugPropertyWatch *watch; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(prop, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugPropertyReference(), this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - 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))); - - int origWidth = m_rootItem->property("width").toInt(); - m_rootItem->setProperty("width", origWidth*2); - - // stateChanged() is received before valueChanged() - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - QCOMPARE(spy.count(), 1); - - m_dbg->removeWatch(watch); - delete watch; - - // restore original value and verify spy doesn't get additional 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(), prop.name().toUtf8()); - QCOMPARE(spy.at(0).at(1).value(), 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; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(obj, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugObjectReference(), this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, this); - QCOMPARE(watch->state(), QmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - - QSignalSpy spy(watch, SIGNAL(valueChanged(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); - - // stateChanged() is received before any valueChanged() signals - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - QVERIFY(spy.count() > 0); - - int newWidth = -1; - int newHeight = -1; - for (int i=0; i() == "width") - newWidth = values[1].value().toInt(); - else if (values[0].value() == "height") - newHeight = values[1].value().toInt(); - - } - - m_dbg->removeWatch(watch); - delete watch; - - // since watch has been removed, restoring the original values should not trigger a valueChanged() - spy.clear(); - m_rootItem->setProperty("width", origWidth); - m_rootItem->setProperty("height", origHeight); - QTest::qWait(100); - QCOMPARE(spy.count(), 0); - - QCOMPARE(newWidth, origWidth * 2); - QCOMPARE(newHeight, 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; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(obj, expr, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugObjectReference(), expr, this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->expression(), expr); - - QSignalSpy spyState(watch, SIGNAL(stateChanged(QmlDebugWatch::State))); - - 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 0) { - width += increment; - m_rootItem->setProperty("width", width); - } - if (!QmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) - QFAIL("Did not receive valueChanged() for expression"); - } - - if (spyState.count() == 0) - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(spyState.count(), 1); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - - 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().toInt(), width); - width += increment; - } -} - -void tst_QmlDebug::watch_expression_data() -{ - QTest::addColumn("expr"); - QTest::addColumn("increment"); - QTest::addColumn("incrementCount"); - - QTest::newRow("width") << "width" << 0 << 0; - QTest::newRow("width+10") << "width + 10" << 10 << 5; -} - -void tst_QmlDebug::watch_context() -{ - QmlDebugContextReference c; - QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(c, QString(), this)); -} - -void tst_QmlDebug::watch_file() -{ - QmlDebugFileReference f; - QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(f, this)); -} - -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 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 qml component objects created for context 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); - - QCOMPARE(context.contexts().count(), 1); - QVERIFY(context.contexts()[0].debugId() >= 0); - QCOMPARE(context.contexts()[0].name(), QString("tst_QmlDebug_childContext")); - - 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("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); // check immediate deletion is ok - - 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("expr"); - QTest::addColumn("result"); - - QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); - QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); - QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); -} - -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() << 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() << 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() << 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() << 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; - - QmlDebugPropertyReference ref = findProperty(obj.properties(), "scale"); - QVERIFY(ref.objectDebugId() > 0); - QVERIFY(!ref.name().isEmpty()); - QVERIFY(!ref.value().isNull()); - QVERIFY(!ref.valueTypeName().isEmpty()); - QVERIFY(!ref.binding().isEmpty()); - QVERIFY(ref.hasNotifySignal()); - - QmlDebugPropertyReference copy(ref); - QmlDebugPropertyReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugPropertyReference &r, (QList() << copy << copyAssign)) - compareProperties(r, ref); -} - - -class tst_QmlDebug_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) - { - QmlContext *c = new QmlContext(data->engine->rootContext()); - c->setObjectName("tst_QmlDebug_childContext"); - return new tst_QmlDebug(data); - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QList qml; - qml << "import Qt 4.6\n" - "Item {" - "width: 10; height: 20; scale: blueRect.scale;" - "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" - "Text { color: blueRect.color; }" - "MouseRegion {" - "onEntered: { print('hello') }" - "}" - "}"; - // add second component to test multiple root contexts - qml << "import Qt 4.6\n" - "Item {}"; - tst_QmlDebug_Factory factory; - return QmlDebugTest::runTests(&factory, qml); -} - -//QTEST_MAIN(tst_QmlDebug) - -#include "tst_qmldebug.moc" diff --git a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro b/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro deleted file mode 100644 index c0aa7b2..0000000 --- a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebugclient.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp deleted file mode 100644 index 6c4a1a3..0000000 --- a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -#include "../debugutil_p.h" - -class tst_QmlDebugClient : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebugClient(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - } - - QmlDebugConnection *m_conn; - QmlEngine *m_engine; - -private slots: - void name(); - void isEnabled(); - void setEnabled(); - void isConnected(); - void sendMessage(); -}; - -void tst_QmlDebugClient::name() -{ - QString name = "tst_QmlDebugClient::name()"; - - QmlDebugClient client(name, m_conn); - QCOMPARE(client.name(), name); -} - -void tst_QmlDebugClient::isEnabled() -{ - QmlDebugClient client("tst_QmlDebugClient::isEnabled()", m_conn); - QCOMPARE(client.isEnabled(), false); -} - -void tst_QmlDebugClient::setEnabled() -{ - QmlDebugTestService service("tst_QmlDebugClient::setEnabled()"); - QmlDebugTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); - - QCOMPARE(service.isEnabled(), false); - - client.setEnabled(true); - QCOMPARE(client.isEnabled(), true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), true); - - client.setEnabled(false); - QCOMPARE(client.isEnabled(), false); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), false); -} - -void tst_QmlDebugClient::isConnected() -{ - QmlDebugClient client1("tst_QmlDebugClient::isConnected() A", m_conn); - QCOMPARE(client1.isConnected(), true); - - QmlDebugConnection conn; - QmlDebugClient client2("tst_QmlDebugClient::isConnected() B", &conn); - QCOMPARE(client2.isConnected(), false); - - QmlDebugClient client3("tst_QmlDebugClient::isConnected() C", 0); - QCOMPARE(client3.isConnected(), false); - - // duplicate plugin name - QTest::ignoreMessage(QtWarningMsg, "QmlDebugClient: Conflicting plugin name \"tst_QmlDebugClient::isConnected() A\" "); - QmlDebugClient client4("tst_QmlDebugClient::isConnected() A", m_conn); - QCOMPARE(client4.isConnected(), false); -} - -void tst_QmlDebugClient::sendMessage() -{ - QmlDebugTestService service("tst_QmlDebugClient::sendMessage()"); - QmlDebugTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); -} - - -class tst_QmlDebugClient_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugClient(data); } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QmlDebugClient_Factory factory; - return QmlDebugTest::runTests(&factory); -} - -#include "tst_qmldebugclient.moc" diff --git a/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro b/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro deleted file mode 100644 index cce277a..0000000 --- a/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebugservice.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp deleted file mode 100644 index 0c02929..0000000 --- a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -#include "../debugutil_p.h" - -class tst_QmlDebugService : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebugService(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - } - - QmlDebugConnection *m_conn; - QmlEngine *m_engine; - -private slots: - void name(); - void isEnabled(); - void enabledChanged(); - void sendMessage(); - void idForObject(); - void objectForId(); - void objectToString(); -}; - -void tst_QmlDebugService::name() -{ - QString name = "tst_QmlDebugService::name()"; - - QmlDebugService service(name); - QCOMPARE(service.name(), name); -} - -void tst_QmlDebugService::isEnabled() -{ - QmlDebugTestService service("tst_QmlDebugService::isEnabled()", m_conn); - QCOMPARE(service.isEnabled(), false); - - QmlDebugTestClient client("tst_QmlDebugService::isEnabled()", m_conn); - client.setEnabled(true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), true); - - QTest::ignoreMessage(QtWarningMsg, "QmlDebugService: Conflicting plugin name \"tst_QmlDebugService::isEnabled()\" "); - QmlDebugService duplicate("tst_QmlDebugService::isEnabled()", m_conn); - QCOMPARE(duplicate.isEnabled(), false); -} - -void tst_QmlDebugService::enabledChanged() -{ - QmlDebugTestService service("tst_QmlDebugService::enabledChanged()"); - QmlDebugTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); - - QCOMPARE(service.enabled, false); - - client.setEnabled(true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.enabled, true); -} - -void tst_QmlDebugService::sendMessage() -{ - QmlDebugTestService service("tst_QmlDebugService::sendMessage()"); - QmlDebugTestClient client("tst_QmlDebugService::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); -} - -void tst_QmlDebugService::idForObject() -{ - QCOMPARE(QmlDebugService::idForObject(0), -1); - - QObject *objA = new QObject; - - int idA = QmlDebugService::idForObject(objA); - QVERIFY(idA >= 0); - QCOMPARE(QmlDebugService::objectForId(idA), objA); - - int idAA = QmlDebugService::idForObject(objA); - QCOMPARE(idAA, idA); - - QObject *objB = new QObject; - int idB = QmlDebugService::idForObject(objB); - QVERIFY(idB != idA); - QCOMPARE(QmlDebugService::objectForId(idB), objB); - - delete objA; - delete objB; -} - -void tst_QmlDebugService::objectForId() -{ - QCOMPARE(QmlDebugService::objectForId(-1), static_cast(0)); - QCOMPARE(QmlDebugService::objectForId(1), static_cast(0)); - - QObject *obj = new QObject; - int id = QmlDebugService::idForObject(obj); - QCOMPARE(QmlDebugService::objectForId(id), obj); - - delete obj; - QCOMPARE(QmlDebugService::objectForId(id), static_cast(0)); -} - -void tst_QmlDebugService::objectToString() -{ - QCOMPARE(QmlDebugService::objectToString(0), QString("NULL")); - - QObject *obj = new QObject; - QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: ")); - - obj->setObjectName("Hello"); - QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: Hello")); -} - - -class tst_QmlDebugService_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugService(data); } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QmlDebugService_Factory factory; - return QmlDebugTest::runTests(&factory); -} - -#include "tst_qmldebugservice.moc" diff --git a/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro deleted file mode 100644 index 800e5e0..0000000 --- a/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qpacketprotocol.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp deleted file mode 100644 index 36b6317..0000000 --- a/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** -** -** 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 "../debugutil_p.h" - -class tst_QPacketProtocol : public QObject -{ - Q_OBJECT - -private: - QTcpServer *m_server; - QTcpSocket *m_client; - QTcpSocket *m_serverConn; - -private slots: - void init(); - void cleanup(); - - void maximumPacketSize(); - void setMaximumPacketSize(); - void setMaximumPacketSize_data(); - void send(); - void send_data(); - void packetsAvailable(); - void packetsAvailable_data(); - void clear(); - void read(); - void device(); - - void tst_QPacket_clear(); -}; - -void tst_QPacketProtocol::init() -{ - m_server = new QTcpServer(this); - QVERIFY(m_server->listen()); - - m_client = new QTcpSocket(this); - m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); - - QVERIFY(m_client->waitForConnected()); - QVERIFY(m_server->waitForNewConnection()); - m_serverConn = m_server->nextPendingConnection(); -} - -void tst_QPacketProtocol::cleanup() -{ - delete m_client; - delete m_serverConn; - delete m_server; -} - -void tst_QPacketProtocol::maximumPacketSize() -{ - QPacketProtocol p(m_client); - QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); -} - -void tst_QPacketProtocol::setMaximumPacketSize() -{ - QFETCH(qint32, size); - QFETCH(qint32, expected); - - QPacketProtocol out(m_serverConn); - QCOMPARE(out.setMaximumPacketSize(size), expected); - - if (size == expected) { - QPacketProtocol in(m_client); - QByteArray b; - b.fill('a', size + 1); - out.send() << b.constData(); - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(invalidPacket()))); - } -} - -void tst_QPacketProtocol::setMaximumPacketSize_data() -{ - QTest::addColumn("size"); - QTest::addColumn("expected"); - - QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); - QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); - QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); -} - -void tst_QPacketProtocol::send() -{ - QFETCH(bool, useAutoSend); - - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QByteArray ba; - int num; - - if (useAutoSend) { - out.send() << "Hello world" << 123; - } else { - QPacket packet; - packet << "Hello world" << 123; - out.send(packet); - } - - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p = in.read(); - p >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world") + '\0'); - QCOMPARE(num, 123); -} - -void tst_QPacketProtocol::send_data() -{ - QTest::addColumn("useAutoSend"); - - QTest::newRow("auto send") << true; - QTest::newRow("no auto send") << false; -} - -void tst_QPacketProtocol::packetsAvailable() -{ - QFETCH(int, packetCount); - - QPacketProtocol out(m_client); - QPacketProtocol in(m_serverConn); - - QCOMPARE(out.packetsAvailable(), qint64(0)); - QCOMPARE(in.packetsAvailable(), qint64(0)); - - for (int i=0; i("packetCount"); - - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("10") << 10; -} - -void tst_QPacketProtocol::clear() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - out.send() << 123; - out.send() << 456; - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - in.clear(); - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::read() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QVERIFY(in.read().isEmpty()); - - out.send() << 123; - out.send() << 456; - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - int num; - - QPacket p1 = in.read(); - QVERIFY(!p1.isEmpty()); - p1 >> num; - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - QVERIFY(!p2.isEmpty()); - p2 >> num; - QCOMPARE(num, 456); - - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::device() -{ - QPacketProtocol p(m_client); - QCOMPARE(p.device(), m_client); -} - -void tst_QPacketProtocol::tst_QPacket_clear() -{ - QPacketProtocol protocol(m_client); - - QPacket packet; - - packet << "Hello world!" << 123; - protocol.send(packet); - - packet.clear(); - QVERIFY(packet.isEmpty()); - packet << "Goodbyte world!" << 789; - protocol.send(packet); - - QByteArray ba; - int num; - QPacketProtocol in(m_serverConn); - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p1 = in.read(); - p1 >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world!") + '\0'); - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - p2 >> ba >> num; - QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); - QCOMPARE(num, 789); -} - -QTEST_MAIN(tst_QPacketProtocol) - -#include "tst_qpacketprotocol.moc" diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index ec2c7d0..c45a05e 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -2,10 +2,7 @@ TEMPLATE = subdirs SUBDIRS += \ anchors \ # Cover animatedimage \ # Cover - animations \ # Cover - behaviors \ # Cover datetimeformatter \ # Cover - debugger \ # Cover examples \ layouts \ # Cover numberformatter \ # Cover @@ -15,6 +12,9 @@ SUBDIRS += \ qmlbinding \ # Cover qmlconnection \ # Cover qmlcontext \ # Cover + qmldebug \ # Cover + qmldebugclient \ # Cover + qmldebugservice \ # Cover qmldom \ # Cover qmleasefollow \ # Cover qmlecmascript \ # Cover @@ -49,6 +49,7 @@ SUBDIRS += \ qmlsystempalette \ # Cover qmltimer \ # Cover qmlxmllistmodel \ # Cover + qpacketprotocol \ # Cover repeater \ # Cover sql \ # Cover states \ # Cover diff --git a/tests/auto/declarative/qmldebug/qmldebug.pro b/tests/auto/declarative/qmldebug/qmldebug.pro new file mode 100644 index 0000000..f79829d --- /dev/null +++ b/tests/auto/declarative/qmldebug/qmldebug.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebug.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp new file mode 100644 index 0000000..6916cc9 --- /dev/null +++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp @@ -0,0 +1,831 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "../shared/debugutil_p.h" + +Q_DECLARE_METATYPE(QmlDebugWatch::State) + + +class tst_QmlDebug : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebug(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + m_rootItem = data->items[0]; + } + +private: + QmlDebugObjectReference findRootObject(); + QmlDebugPropertyReference findProperty(const QList &props, const QString &name) 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; + +private slots: + void initTestCase(); + + void watch_property(); + void watch_object(); + void watch_expression(); + void watch_expression_data(); + void watch_context(); + void watch_file(); + + 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 &props, const QString &name) const +{ + foreach(const QmlDebugPropertyReference &p, props) { + if (p.name() == name) + return p; + } + return QmlDebugPropertyReference(); +} + +void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) +{ + QVERIFY(query); + QCOMPARE(query->parent(), this); + QVERIFY(query->state() == QmlDebugQuery::Waiting); + if (!QmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) + 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))); + + const QObjectList &children = o->children(); + for (int i=0; i= 0); + + QmlDebugObjectReference cref; + foreach (const QmlDebugObjectReference &ref, oref.children()) { + if (ref.debugId() == debugId) { + cref = ref; + break; + } + } + QVERIFY(cref.debugId() >= 0); + + if (recursive) + recursiveObjectTest(child, cref, true); + } + + foreach (const QmlDebugPropertyReference &p, oref.properties()) { + QCOMPARE(p.objectDebugId(), QmlDebugService::idForObject(o)); + + // signal properties are fake - they are generated from QmlBoundSignal children + if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { + QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); + QVERIFY(p.valueTypeName().isEmpty()); + QVERIFY(p.binding().isEmpty()); + QVERIFY(!p.hasNotifySignal()); + continue; + } + + QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); + + 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()); + + QVERIFY(pmeta.isValid()); + } +} + +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 aprops = a.properties(); + QList bprops = b.properties(); + + for (int i=0; i(); +} + +void tst_QmlDebug::watch_property() +{ + QmlDebugObjectReference obj = findRootObject(); + QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); + + QmlDebugPropertyWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(prop, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugPropertyReference(), this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + 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))); + + int origWidth = m_rootItem->property("width").toInt(); + m_rootItem->setProperty("width", origWidth*2); + + // stateChanged() is received before valueChanged() + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + QCOMPARE(spy.count(), 1); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get additional 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(), prop.name().toUtf8()); + QCOMPARE(spy.at(0).at(1).value(), 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; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugObjectReference(), this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(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); + + // stateChanged() is received before any valueChanged() signals + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + QVERIFY(spy.count() > 0); + + int newWidth = -1; + int newHeight = -1; + for (int i=0; i() == "width") + newWidth = values[1].value().toInt(); + else if (values[0].value() == "height") + newHeight = values[1].value().toInt(); + + } + + m_dbg->removeWatch(watch); + delete watch; + + // since watch has been removed, restoring the original values should not trigger a valueChanged() + spy.clear(); + m_rootItem->setProperty("width", origWidth); + m_rootItem->setProperty("height", origHeight); + QTest::qWait(100); + QCOMPARE(spy.count(), 0); + + QCOMPARE(newWidth, origWidth * 2); + QCOMPARE(newHeight, 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; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugObjectReference(), expr, this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->expression(), expr); + + QSignalSpy spyState(watch, SIGNAL(stateChanged(QmlDebugWatch::State))); + + 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 0) { + width += increment; + m_rootItem->setProperty("width", width); + } + if (!QmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) + QFAIL("Did not receive valueChanged() for expression"); + } + + if (spyState.count() == 0) + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(spyState.count(), 1); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + + 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().toInt(), width); + width += increment; + } +} + +void tst_QmlDebug::watch_expression_data() +{ + QTest::addColumn("expr"); + QTest::addColumn("increment"); + QTest::addColumn("incrementCount"); + + QTest::newRow("width") << "width" << 0 << 0; + QTest::newRow("width+10") << "width + 10" << 10 << 5; +} + +void tst_QmlDebug::watch_context() +{ + QmlDebugContextReference c; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(c, QString(), this)); +} + +void tst_QmlDebug::watch_file() +{ + QmlDebugFileReference f; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(f, this)); +} + +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 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 qml component objects created for context 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); + + QCOMPARE(context.contexts().count(), 1); + QVERIFY(context.contexts()[0].debugId() >= 0); + QCOMPARE(context.contexts()[0].name(), QString("tst_QmlDebug_childContext")); + + 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("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); // check immediate deletion is ok + + 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("expr"); + QTest::addColumn("result"); + + QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); + QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); + QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); +} + +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() << 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() << 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() << 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() << 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; + + QmlDebugPropertyReference ref = findProperty(obj.properties(), "scale"); + QVERIFY(ref.objectDebugId() > 0); + QVERIFY(!ref.name().isEmpty()); + QVERIFY(!ref.value().isNull()); + QVERIFY(!ref.valueTypeName().isEmpty()); + QVERIFY(!ref.binding().isEmpty()); + QVERIFY(ref.hasNotifySignal()); + + QmlDebugPropertyReference copy(ref); + QmlDebugPropertyReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugPropertyReference &r, (QList() << copy << copyAssign)) + compareProperties(r, ref); +} + + +class tst_QmlDebug_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) + { + QmlContext *c = new QmlContext(data->engine->rootContext()); + c->setObjectName("tst_QmlDebug_childContext"); + return new tst_QmlDebug(data); + } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QList qml; + qml << "import Qt 4.6\n" + "Item {" + "width: 10; height: 20; scale: blueRect.scale;" + "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" + "Text { color: blueRect.color; }" + "MouseRegion {" + "onEntered: { print('hello') }" + "}" + "}"; + // add second component to test multiple root contexts + qml << "import Qt 4.6\n" + "Item {}"; + tst_QmlDebug_Factory factory; + return QmlDebugTest::runTests(&factory, qml); +} + +//QTEST_MAIN(tst_QmlDebug) + +#include "tst_qmldebug.moc" diff --git a/tests/auto/declarative/qmldebugclient/qmldebugclient.pro b/tests/auto/declarative/qmldebugclient/qmldebugclient.pro new file mode 100644 index 0000000..36aa818 --- /dev/null +++ b/tests/auto/declarative/qmldebugclient/qmldebugclient.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebugclient.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp new file mode 100644 index 0000000..8325731 --- /dev/null +++ b/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** 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 +#include + +#include "../shared/debugutil_p.h" + +class tst_QmlDebugClient : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebugClient(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } + + QmlDebugConnection *m_conn; + QmlEngine *m_engine; + +private slots: + void name(); + void isEnabled(); + void setEnabled(); + void isConnected(); + void sendMessage(); +}; + +void tst_QmlDebugClient::name() +{ + QString name = "tst_QmlDebugClient::name()"; + + QmlDebugClient client(name, m_conn); + QCOMPARE(client.name(), name); +} + +void tst_QmlDebugClient::isEnabled() +{ + QmlDebugClient client("tst_QmlDebugClient::isEnabled()", m_conn); + QCOMPARE(client.isEnabled(), false); +} + +void tst_QmlDebugClient::setEnabled() +{ + QmlDebugTestService service("tst_QmlDebugClient::setEnabled()"); + QmlDebugTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); + + QCOMPARE(service.isEnabled(), false); + + client.setEnabled(true); + QCOMPARE(client.isEnabled(), true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), true); + + client.setEnabled(false); + QCOMPARE(client.isEnabled(), false); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), false); +} + +void tst_QmlDebugClient::isConnected() +{ + QmlDebugClient client1("tst_QmlDebugClient::isConnected() A", m_conn); + QCOMPARE(client1.isConnected(), true); + + QmlDebugConnection conn; + QmlDebugClient client2("tst_QmlDebugClient::isConnected() B", &conn); + QCOMPARE(client2.isConnected(), false); + + QmlDebugClient client3("tst_QmlDebugClient::isConnected() C", 0); + QCOMPARE(client3.isConnected(), false); + + // duplicate plugin name + QTest::ignoreMessage(QtWarningMsg, "QmlDebugClient: Conflicting plugin name \"tst_QmlDebugClient::isConnected() A\" "); + QmlDebugClient client4("tst_QmlDebugClient::isConnected() A", m_conn); + QCOMPARE(client4.isConnected(), false); +} + +void tst_QmlDebugClient::sendMessage() +{ + QmlDebugTestService service("tst_QmlDebugClient::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + + +class tst_QmlDebugClient_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugClient(data); } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + tst_QmlDebugClient_Factory factory; + return QmlDebugTest::runTests(&factory); +} + +#include "tst_qmldebugclient.moc" diff --git a/tests/auto/declarative/qmldebugservice/qmldebugservice.pro b/tests/auto/declarative/qmldebugservice/qmldebugservice.pro new file mode 100644 index 0000000..9995f1f --- /dev/null +++ b/tests/auto/declarative/qmldebugservice/qmldebugservice.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebugservice.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp new file mode 100644 index 0000000..625d1f5 --- /dev/null +++ b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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 +#include + +#include "../shared/debugutil_p.h" + +class tst_QmlDebugService : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebugService(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } + + QmlDebugConnection *m_conn; + QmlEngine *m_engine; + +private slots: + void name(); + void isEnabled(); + void enabledChanged(); + void sendMessage(); + void idForObject(); + void objectForId(); + void objectToString(); +}; + +void tst_QmlDebugService::name() +{ + QString name = "tst_QmlDebugService::name()"; + + QmlDebugService service(name); + QCOMPARE(service.name(), name); +} + +void tst_QmlDebugService::isEnabled() +{ + QmlDebugTestService service("tst_QmlDebugService::isEnabled()", m_conn); + QCOMPARE(service.isEnabled(), false); + + QmlDebugTestClient client("tst_QmlDebugService::isEnabled()", m_conn); + client.setEnabled(true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), true); + + QTest::ignoreMessage(QtWarningMsg, "QmlDebugService: Conflicting plugin name \"tst_QmlDebugService::isEnabled()\" "); + QmlDebugService duplicate("tst_QmlDebugService::isEnabled()", m_conn); + QCOMPARE(duplicate.isEnabled(), false); +} + +void tst_QmlDebugService::enabledChanged() +{ + QmlDebugTestService service("tst_QmlDebugService::enabledChanged()"); + QmlDebugTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); + + QCOMPARE(service.enabled, false); + + client.setEnabled(true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.enabled, true); +} + +void tst_QmlDebugService::sendMessage() +{ + QmlDebugTestService service("tst_QmlDebugService::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugService::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + +void tst_QmlDebugService::idForObject() +{ + QCOMPARE(QmlDebugService::idForObject(0), -1); + + QObject *objA = new QObject; + + int idA = QmlDebugService::idForObject(objA); + QVERIFY(idA >= 0); + QCOMPARE(QmlDebugService::objectForId(idA), objA); + + int idAA = QmlDebugService::idForObject(objA); + QCOMPARE(idAA, idA); + + QObject *objB = new QObject; + int idB = QmlDebugService::idForObject(objB); + QVERIFY(idB != idA); + QCOMPARE(QmlDebugService::objectForId(idB), objB); + + delete objA; + delete objB; +} + +void tst_QmlDebugService::objectForId() +{ + QCOMPARE(QmlDebugService::objectForId(-1), static_cast(0)); + QCOMPARE(QmlDebugService::objectForId(1), static_cast(0)); + + QObject *obj = new QObject; + int id = QmlDebugService::idForObject(obj); + QCOMPARE(QmlDebugService::objectForId(id), obj); + + delete obj; + QCOMPARE(QmlDebugService::objectForId(id), static_cast(0)); +} + +void tst_QmlDebugService::objectToString() +{ + QCOMPARE(QmlDebugService::objectToString(0), QString("NULL")); + + QObject *obj = new QObject; + QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: ")); + + obj->setObjectName("Hello"); + QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: Hello")); +} + + +class tst_QmlDebugService_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugService(data); } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + tst_QmlDebugService_Factory factory; + return QmlDebugTest::runTests(&factory); +} + +#include "tst_qmldebugservice.moc" diff --git a/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro new file mode 100644 index 0000000..f42cecc --- /dev/null +++ b/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qpacketprotocol.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp new file mode 100644 index 0000000..b54f133 --- /dev/null +++ b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp @@ -0,0 +1,270 @@ +/**************************************************************************** +** +** 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 "../shared/debugutil_p.h" + +class tst_QPacketProtocol : public QObject +{ + Q_OBJECT + +private: + QTcpServer *m_server; + QTcpSocket *m_client; + QTcpSocket *m_serverConn; + +private slots: + void init(); + void cleanup(); + + void maximumPacketSize(); + void setMaximumPacketSize(); + void setMaximumPacketSize_data(); + void send(); + void send_data(); + void packetsAvailable(); + void packetsAvailable_data(); + void clear(); + void read(); + void device(); + + void tst_QPacket_clear(); +}; + +void tst_QPacketProtocol::init() +{ + m_server = new QTcpServer(this); + QVERIFY(m_server->listen()); + + m_client = new QTcpSocket(this); + m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); + + QVERIFY(m_client->waitForConnected()); + QVERIFY(m_server->waitForNewConnection()); + m_serverConn = m_server->nextPendingConnection(); +} + +void tst_QPacketProtocol::cleanup() +{ + delete m_client; + delete m_serverConn; + delete m_server; +} + +void tst_QPacketProtocol::maximumPacketSize() +{ + QPacketProtocol p(m_client); + QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); +} + +void tst_QPacketProtocol::setMaximumPacketSize() +{ + QFETCH(qint32, size); + QFETCH(qint32, expected); + + QPacketProtocol out(m_serverConn); + QCOMPARE(out.setMaximumPacketSize(size), expected); + + if (size == expected) { + QPacketProtocol in(m_client); + QByteArray b; + b.fill('a', size + 1); + out.send() << b.constData(); + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(invalidPacket()))); + } +} + +void tst_QPacketProtocol::setMaximumPacketSize_data() +{ + QTest::addColumn("size"); + QTest::addColumn("expected"); + + QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); + QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); + QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); +} + +void tst_QPacketProtocol::send() +{ + QFETCH(bool, useAutoSend); + + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QByteArray ba; + int num; + + if (useAutoSend) { + out.send() << "Hello world" << 123; + } else { + QPacket packet; + packet << "Hello world" << 123; + out.send(packet); + } + + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p = in.read(); + p >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world") + '\0'); + QCOMPARE(num, 123); +} + +void tst_QPacketProtocol::send_data() +{ + QTest::addColumn("useAutoSend"); + + QTest::newRow("auto send") << true; + QTest::newRow("no auto send") << false; +} + +void tst_QPacketProtocol::packetsAvailable() +{ + QFETCH(int, packetCount); + + QPacketProtocol out(m_client); + QPacketProtocol in(m_serverConn); + + QCOMPARE(out.packetsAvailable(), qint64(0)); + QCOMPARE(in.packetsAvailable(), qint64(0)); + + for (int i=0; i("packetCount"); + + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("10") << 10; +} + +void tst_QPacketProtocol::clear() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + out.send() << 123; + out.send() << 456; + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + in.clear(); + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::read() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QVERIFY(in.read().isEmpty()); + + out.send() << 123; + out.send() << 456; + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + int num; + + QPacket p1 = in.read(); + QVERIFY(!p1.isEmpty()); + p1 >> num; + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + QVERIFY(!p2.isEmpty()); + p2 >> num; + QCOMPARE(num, 456); + + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::device() +{ + QPacketProtocol p(m_client); + QCOMPARE(p.device(), m_client); +} + +void tst_QPacketProtocol::tst_QPacket_clear() +{ + QPacketProtocol protocol(m_client); + + QPacket packet; + + packet << "Hello world!" << 123; + protocol.send(packet); + + packet.clear(); + QVERIFY(packet.isEmpty()); + packet << "Goodbyte world!" << 789; + protocol.send(packet); + + QByteArray ba; + int num; + QPacketProtocol in(m_serverConn); + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p1 = in.read(); + p1 >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world!") + '\0'); + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + p2 >> ba >> num; + QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); + QCOMPARE(num, 789); +} + +QTEST_MAIN(tst_QPacketProtocol) + +#include "tst_qpacketprotocol.moc" -- cgit v0.12 From f1efdb342224cfb1e22b55ae4c704635edbbf46a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 17 Nov 2009 13:54:56 +1000 Subject: Fix binding (it should be resulted to arrays, since SQL and JS are not) --- src/declarative/qml/qmlsqldatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp index 330d904..6e32fb7 100644 --- a/src/declarative/qml/qmlsqldatabase.cpp +++ b/src/declarative/qml/qmlsqldatabase.cpp @@ -248,10 +248,10 @@ static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEn QSqlQuery query(db); bool err = false; if (query.prepare(sql)) { - if (values.isArray()) { + if (values.isObject()) { for (QScriptValueIterator it(values); it.hasNext();) { it.next(); - query.addBindValue(it.value().toVariant()); + query.bindValue(it.name(),it.value().toVariant()); } } else { query.bindValue(0,values.toVariant()); -- cgit v0.12 From f7a1e0a2ca7eec54966fb4c0d14ffa5e93731194 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 17 Nov 2009 13:55:35 +1000 Subject: test more --- .../declarative/sql/data/2-selection-bindnames.js | 24 ++++++++++++++++++++++ .../declarative/sql/data/6-iteration-efficient.js | 6 +++++- tests/auto/declarative/sql/tst_sql.cpp | 7 ++++--- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/sql/data/2-selection-bindnames.js diff --git a/tests/auto/declarative/sql/data/2-selection-bindnames.js b/tests/auto/declarative/sql/data/2-selection-bindnames.js new file mode 100644 index 0000000..c00acc14 --- /dev/null +++ b/tests/auto/declarative/sql/data/2-selection-bindnames.js @@ -0,0 +1,24 @@ +var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000); +var r=0; + +db.transaction( + function(tx) { + tx.executeSql('SELECT * FROM Greeting WHERE salutation=:p2 AND salutee=:p1', {':p1':'world', ':p2':'hello'}, + function(tx, rs) { + if ( rs.rows.length != 4 ) { + if (r==0) r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1) + } + }, + function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message } + ); + }, + function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message }, + function(tx, result) { if (r==0) r="passed" } +); + + +function test() +{ + if (r == 0) r = "transaction_not_finished"; + return r; +} diff --git a/tests/auto/declarative/sql/data/6-iteration-efficient.js b/tests/auto/declarative/sql/data/6-iteration-efficient.js index 2222b8a..6711fb0 100644 --- a/tests/auto/declarative/sql/data/6-iteration-efficient.js +++ b/tests/auto/declarative/sql/data/6-iteration-efficient.js @@ -1,12 +1,16 @@ var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000); var r=0; +var fbefore="FORWARD WRONG" +var fafter="FORWARD WRONG" db.transaction( function(tx) { tx.executeSql('SELECT * FROM Greeting', [], function(tx, rs) { var r1="" + if (!rs.rows.forwardOnly) fbefore="" rs.rows.forwardOnly = true; + if (rs.rows.forwardOnly) fafter=""; for(var i=0; rs.rows[i]; ++i) { r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";" } @@ -17,7 +21,7 @@ db.transaction( ); }, function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message }, - function(tx, result) { if (r==0) r="passed" } + function(tx, result) { if (r==0) r=fbefore+"passed"+fafter } ); diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index e4f497c..973d7b1 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -139,10 +139,11 @@ void tst_sql::testQml_data() QTest::newRow("creation") << "data/1-creation.js" << "passed" << 1 << false; QTest::newRow("selection") << "data/2-selection.js" << "passed" << 1 << false; + QTest::newRow("selection-bindnames") << "data/2-selection-bindnames.js" << "passed" << 1 << true; // WebKit somehow breaks named parameters QTest::newRow("iteration-item-function") << "data/3-iteration-item-function.js" << "passed" << 1 << false; - QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 1 << true; - QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 1 << true; - QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 1 << true; + QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 1 << true; // Some HTML5 documents say to use rows by index, others by item() function + QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 1 << true; // As with previous, WebKit doesn't give an array + QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 1 << true; // It's very inefficient to find the total number of results, here is a solution } void tst_sql::validateAgainstWebkit_data() -- cgit v0.12 From 4d5d94b7cf41fbfefd37812ae3b311dd619a6731 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 17 Nov 2009 14:04:21 +1000 Subject: graphicswidgets basic autotest --- tests/auto/declarative/declarative.pro | 1 + .../graphicswidgets/data/graphicswidgets.qml | 57 ++++++++++++++++ .../graphicswidgets/graphicswidgets.pro | 8 +++ .../graphicswidgets/tst_graphicswidgets.cpp | 77 ++++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml create mode 100644 tests/auto/declarative/graphicswidgets/graphicswidgets.pro create mode 100644 tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index ec2c7d0..5ab272c 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -7,6 +7,7 @@ SUBDIRS += \ datetimeformatter \ # Cover debugger \ # Cover examples \ + graphicswidgets \ # Cover layouts \ # Cover numberformatter \ # Cover parserstress \ # Cover diff --git a/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml b/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml new file mode 100644 index 0000000..70fafd6 --- /dev/null +++ b/tests/auto/declarative/graphicswidgets/data/graphicswidgets.qml @@ -0,0 +1,57 @@ +import Qt 4.6 + +QGraphicsView { + objectName: "GView" + size: "800x600" + + QGraphicsScene { + objectName: "GScene" + sceneRect: "0,0,500x300" + + QGraphicsWidget { + layout: QGraphicsLinearLayout { + orientation: Qt.Horizontal + QGraphicsWidget { + layout: QGraphicsLinearLayout { + spacing: 10; orientation: Qt.Vertical + LayoutItem { + QGraphicsLinearLayout.stretchFactor: 1 + objectName: "left" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { objectName: "yellowRect"; color: "yellow"; anchors.fill: parent } + } + LayoutItem { + QGraphicsLinearLayout.stretchFactor: 10 + objectName: "left" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { objectName: "yellowRect"; color: "blue"; anchors.fill: parent } + } + } + } + QGraphicsWidget { + layout: QGraphicsLinearLayout { + spacing: 10; orientation: Qt.Vertical + LayoutItem { + objectName: "left" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { objectName: "yellowRect"; color: "red"; anchors.fill: parent } + } + LayoutItem { + objectName: "left" + minimumSize: "100x100" + maximumSize: "300x300" + preferredSize: "100x100" + Rectangle { objectName: "yellowRect"; color: "green"; anchors.fill: parent } + } + } + } + } + } + } +} diff --git a/tests/auto/declarative/graphicswidgets/graphicswidgets.pro b/tests/auto/declarative/graphicswidgets/graphicswidgets.pro new file mode 100644 index 0000000..712c34c --- /dev/null +++ b/tests/auto/declarative/graphicswidgets/graphicswidgets.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_graphicswidgets.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp b/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp new file mode 100644 index 0000000..783094b --- /dev/null +++ b/tests/auto/declarative/graphicswidgets/tst_graphicswidgets.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 + +class tst_graphicswidgets : public QObject + +{ + Q_OBJECT +public: + tst_graphicswidgets(); + +private slots: + void widgets(); +}; + +tst_graphicswidgets::tst_graphicswidgets() +{ +} + +void tst_graphicswidgets::widgets() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/graphicswidgets.qml")); + QGraphicsView *obj = qobject_cast(c.create()); + + QVERIFY(obj != 0); + QVERIFY(obj->scene() != 0); + QList list; + QVERIFY(obj->scene()->children() != list); + delete obj; +} + +QTEST_MAIN(tst_graphicswidgets) + +#include "tst_graphicswidgets.moc" -- cgit v0.12 From a2511fc8cc122412ddf3955aec73a6b42c601d92 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 17 Nov 2009 14:30:59 +1000 Subject: Distinguish between reversing and rewinding a state change. Task-number: QTBUG-5769 --- src/declarative/util/qmlpropertychanges.cpp | 14 ++- src/declarative/util/qmlstate.cpp | 4 + src/declarative/util/qmlstate_p.h | 5 +- src/declarative/util/qmlstateoperations.cpp | 147 ++++++++++++++++++-------- src/declarative/util/qmlstateoperations_p.h | 4 + src/declarative/util/qmltransitionmanager.cpp | 4 +- 6 files changed, 131 insertions(+), 47 deletions(-) diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index a1e92b5..28c8e4f 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -83,7 +83,8 @@ QT_BEGIN_NAMESPACE class QmlReplaceSignalHandler : public ActionEvent { public: - QmlReplaceSignalHandler() : expression(0), reverseExpression(0), ownedExpression(0) {} + QmlReplaceSignalHandler() : expression(0), reverseExpression(0), + rewindExpression(0), ownedExpression(0) {} ~QmlReplaceSignalHandler() { delete ownedExpression; } @@ -93,6 +94,7 @@ public: QmlMetaProperty property; QmlExpression *expression; QmlExpression *reverseExpression; + QmlExpression *rewindExpression; QGuard ownedExpression; virtual void execute() { @@ -104,7 +106,15 @@ public: ownedExpression = property.setSignalExpression(reverseExpression); } - virtual void saveOriginals() { reverseExpression = property.signalExpression(); } + virtual void saveOriginals() { + saveCurrentValues(); + reverseExpression = rewindExpression; + } + + virtual void rewind() { + ownedExpression = property.setSignalExpression(rewindExpression); + } + virtual void saveCurrentValues() { rewindExpression = property.signalExpression(); } virtual bool override(ActionEvent*other) { if (other == this) diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 1f5dbad..c05c539 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -362,6 +362,8 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever } if (!found || action.event != d->revertList.at(jj).event) action.event->saveOriginals(); + else if (action.event->isRewindable()) + action.event->saveCurrentValues(); } else { action.fromBinding = action.property.binding(); @@ -422,6 +424,8 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever a.specifiedProperty = d->revertList.at(ii).specifiedProperty; a.event = d->revertList.at(ii).event; a.reverseEvent = d->revertList.at(ii).reverseEvent; + if (a.event && a.event->isRewindable()) + a.event->saveCurrentValues(); applyList << a; // Store these special reverts in the reverting list d->reverting << d->revertList.at(ii).property; diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 50c5401..856af8a 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -43,7 +43,6 @@ #define QMLSTATE_H #include -#include #include QT_BEGIN_HEADER @@ -91,6 +90,10 @@ public: virtual void reverse(); virtual void saveOriginals() {} + virtual bool isRewindable() { return isReversable(); } + virtual void rewind() {} + virtual void saveCurrentValues() {} + //virtual bool hasExtraActions(); virtual QList extraActions(); diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 2d32fdb..0d977de 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -57,12 +57,15 @@ class QmlParentChangePrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlParentChange) public: - QmlParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0) {} + QmlParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0), + rewindParent(0), rewindStackBefore(0) {} QmlGraphicsItem *target; QmlGraphicsItem *parent; QGuard origParent; QGuard origStackBefore; + QmlGraphicsItem *rewindParent; + QmlGraphicsItem *rewindStackBefore; void doChange(QmlGraphicsItem *targetParent, QmlGraphicsItem *stackBefore = 0); }; @@ -222,31 +225,9 @@ public: void QmlParentChange::saveOriginals() { Q_D(QmlParentChange); - if (!d->target) { - d->origParent = 0; - d->origStackBefore = 0; - return; - } - - d->origParent = d->target->parentItem(); - - if (!d->origParent) { - d->origStackBefore = 0; - return; - } - - //try to determine the item's original stack position so we can restore it - int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1; - QList children = d->origParent->childItems(); - for (int i = 0; i < children.count(); ++i) { - QmlGraphicsItem *child = qobject_cast(children.at(i)); - if (!child) - continue; - if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) { - d->origStackBefore = child; - break; - } - } + saveCurrentValues(); + d->origParent = d->rewindParent; + d->origStackBefore = d->rewindStackBefore; } void QmlParentChange::execute() @@ -281,6 +262,42 @@ bool QmlParentChange::override(ActionEvent*other) return false; } +void QmlParentChange::saveCurrentValues() +{ + Q_D(QmlParentChange); + if (!d->target) { + d->rewindParent = 0; + d->rewindStackBefore = 0; + return; + } + + d->rewindParent = d->target->parentItem(); + + if (!d->rewindParent) { + d->rewindStackBefore = 0; + return; + } + + //try to determine the item's original stack position so we can restore it + int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1; + QList children = d->rewindParent->childItems(); + for (int i = 0; i < children.count(); ++i) { + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if (!child) + continue; + if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) { + d->rewindStackBefore = child; + break; + } + } +} + +void QmlParentChange::rewind() +{ + Q_D(QmlParentChange); + d->doChange(d->rewindParent, d->rewindStackBefore); +} + class QmlStateChangeScriptPrivate : public QObjectPrivate { public: @@ -399,10 +416,19 @@ public: QmlGraphicsAnchorLine origBottom; QmlGraphicsAnchorLine origVCenter; QmlGraphicsAnchorLine origBaseline; - qreal origX; - qreal origY; - qreal origWidth; - qreal origHeight; + + QmlGraphicsAnchorLine rewindLeft; + QmlGraphicsAnchorLine rewindRight; + QmlGraphicsAnchorLine rewindHCenter; + QmlGraphicsAnchorLine rewindTop; + QmlGraphicsAnchorLine rewindBottom; + QmlGraphicsAnchorLine rewindVCenter; + QmlGraphicsAnchorLine rewindBaseline; + + qreal fromX; + qreal fromY; + qreal fromWidth; + qreal fromHeight; }; /*! @@ -613,19 +639,19 @@ QList QmlAnchorChanges::extraActions() // we shouldn't set explicit width if there wasn't one before. if (d->target) { Action a; - a.fromValue = d->origX; + a.fromValue = d->fromX; a.property = QmlMetaProperty(d->target, QLatin1String("x")); extra << a; - a.fromValue = d->origY; + a.fromValue = d->fromY; a.property = QmlMetaProperty(d->target, QLatin1String("y")); extra << a; - a.fromValue = d->origWidth; + a.fromValue = d->fromWidth; a.property = QmlMetaProperty(d->target, QLatin1String("width")); extra << a; - a.fromValue = d->origHeight; + a.fromValue = d->fromHeight; a.property = QmlMetaProperty(d->target, QLatin1String("height")); extra << a; } @@ -648,15 +674,17 @@ void QmlAnchorChanges::saveOriginals() d->origBottom = d->target->anchors()->bottom(); d->origVCenter = d->target->anchors()->verticalCenter(); d->origBaseline = d->target->anchors()->baseline(); + + saveCurrentValues(); } void QmlAnchorChanges::clearForwardBindings() { Q_D(QmlAnchorChanges); - d->origX = d->target->x(); - d->origY = d->target->y(); - d->origWidth = d->target->width(); - d->origHeight = d->target->height(); + d->fromX = d->target->x(); + d->fromY = d->target->y(); + d->fromWidth = d->target->width(); + d->fromHeight = d->target->height(); //reset any anchors that have been specified if (d->resetList.contains(QLatin1String("left"))) @@ -694,10 +722,10 @@ void QmlAnchorChanges::clearForwardBindings() void QmlAnchorChanges::clearReverseBindings() { Q_D(QmlAnchorChanges); - d->origX = d->target->x(); - d->origY = d->target->y(); - d->origWidth = d->target->width(); - d->origHeight = d->target->height(); + d->fromX = d->target->x(); + d->fromY = d->target->y(); + d->fromWidth = d->target->width(); + d->fromHeight = d->target->height(); //reset any anchors that were set in the state if (d->left.anchorLine != QmlGraphicsAnchorLine::Invalid) @@ -743,6 +771,41 @@ bool QmlAnchorChanges::override(ActionEvent*other) return false; } +void QmlAnchorChanges::rewind() +{ + Q_D(QmlAnchorChanges); + if (!d->target) + return; + + //restore previous anchors + if (d->rewindLeft.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setLeft(d->rewindLeft); + if (d->rewindRight.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setRight(d->rewindRight); + if (d->rewindHCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setHorizontalCenter(d->rewindHCenter); + if (d->rewindTop.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setTop(d->rewindTop); + if (d->rewindBottom.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setBottom(d->rewindBottom); + if (d->rewindVCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setVerticalCenter(d->rewindVCenter); + if (d->rewindBaseline.anchorLine != QmlGraphicsAnchorLine::Invalid) + d->target->anchors()->setBaseline(d->rewindBaseline); +} + +void QmlAnchorChanges::saveCurrentValues() +{ + Q_D(QmlAnchorChanges); + d->rewindLeft = d->target->anchors()->left(); + d->rewindRight = d->target->anchors()->right(); + d->rewindHCenter = d->target->anchors()->horizontalCenter(); + d->rewindTop = d->target->anchors()->top(); + d->rewindBottom = d->target->anchors()->bottom(); + d->rewindVCenter = d->target->anchors()->verticalCenter(); + d->rewindBaseline = d->target->anchors()->baseline(); +} + #include "qmlstateoperations.moc" #include "moc_qmlstateoperations_p.cpp" diff --git a/src/declarative/util/qmlstateoperations_p.h b/src/declarative/util/qmlstateoperations_p.h index a9488dc..589fe20 100644 --- a/src/declarative/util/qmlstateoperations_p.h +++ b/src/declarative/util/qmlstateoperations_p.h @@ -79,6 +79,8 @@ public: virtual void reverse(); virtual QString typeName() const; virtual bool override(ActionEvent*other); + virtual void rewind(); + virtual void saveCurrentValues(); }; class QmlStateChangeScriptPrivate; @@ -166,6 +168,8 @@ public: virtual void saveOriginals(); virtual void clearForwardBindings(); virtual void clearReverseBindings(); + virtual void rewind(); + virtual void saveCurrentValues(); }; QT_END_NAMESPACE diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index bae7e81..d1db9ec 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -173,11 +173,11 @@ void QmlTransitionManager::transition(const QList &list, if (action.event->isReversable()) { if (action.reverseEvent) { //reverse the reverse action.event->clearForwardBindings(); - action.event->execute(); + action.event->rewind(); action.event->clearReverseBindings(); } else { action.event->clearReverseBindings(); - action.event->reverse(); + action.event->rewind(); action.event->clearForwardBindings(); } } -- cgit v0.12 From 5b7957fa3b728ff8a949ab35e332013bbcbfeeba Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 17 Nov 2009 14:54:37 +1000 Subject: QMetaObjectBuilder tests --- src/declarative/qml/qmetaobjectbuilder.cpp | 5 +- .../qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp | 286 ++++++++++++++++----- 2 files changed, 230 insertions(+), 61 deletions(-) diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp index c2f5659..c421c76 100644 --- a/src/declarative/qml/qmetaobjectbuilder.cpp +++ b/src/declarative/qml/qmetaobjectbuilder.cpp @@ -921,9 +921,10 @@ void QMetaObjectBuilder::removeMethod(int index) d->methods.removeAt(index); for (int prop = 0; prop < d->properties.size(); ++prop) { // Adjust the indices of property notify signal references. - if (d->properties[prop].notifySignal == index) + if (d->properties[prop].notifySignal == index) { d->properties[prop].notifySignal = -1; - else if (d->properties[prop].notifySignal > index) + d->properties[prop].setFlag(Notify, false); + } else if (d->properties[prop].notifySignal > index) (d->properties[prop].notifySignal)--; } } diff --git a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index 9beec17..71eefdd 100644 --- a/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/declarative/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -25,6 +25,7 @@ private slots: void create(); void className(); void superClass(); + void flags(); void method(); void slot(); void signal(); @@ -37,6 +38,7 @@ private slots: void staticMetacall(); void copyMetaObject(); void serialize(); + void removeNotifySignal(); private: static bool checkForSideEffects @@ -46,6 +48,61 @@ private: (const QMetaObject *meta1, const QMetaObject *meta2); }; +// Dummy class that has something of every type of thing moc can generate. +class SomethingOfEverything : public QObject +{ + Q_OBJECT + Q_CLASSINFO("ci_foo", "ABC") + Q_CLASSINFO("ci_bar", "DEF") + Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) + Q_PROPERTY(QString prop2 READ prop WRITE setProp) + Q_PROPERTY(SomethingEnum eprop READ eprop) + Q_PROPERTY(SomethingFlagEnum fprop READ fprop) + Q_PROPERTY(QLocale::Language language READ language) + Q_ENUMS(SomethingEnum) + Q_FLAGS(SomethingFlagEnum) +public: + Q_INVOKABLE SomethingOfEverything() {} + ~SomethingOfEverything() {} + + enum SomethingEnum + { + GHI, + JKL = 10 + }; + + enum SomethingFlagEnum + { + XYZ = 1, + UVW = 8 + }; + + Q_INVOKABLE Q_SCRIPTABLE void method1() {} + + QString prop() const { return QString(); } + void setProp(const QString& v) { Q_UNUSED(v); } + + SomethingOfEverything::SomethingEnum eprop() const { return GHI; } + SomethingOfEverything::SomethingFlagEnum fprop() const { return XYZ; } + QLocale::Language language() const { return QLocale::English; } + +public slots: + void slot1(const QString&) {} + void slot2(int, const QString&) {} + +private slots: + void slot3() {} + +protected slots: + Q_SCRIPTABLE void slot4(int) {} + void slot5(int a, const QString& b) { Q_UNUSED(a); Q_UNUSED(b); } + +signals: + void sig1(); + void sig2(int x, const QString& y); + void propChanged(const QString&); +}; + void tst_QMetaObjectBuilder::mocVersionCheck() { // This test will fail when the moc version number is changed. @@ -112,10 +169,33 @@ void tst_QMetaObjectBuilder::superClass() QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::SuperClass)); } +void tst_QMetaObjectBuilder::flags() +{ + QMetaObjectBuilder builder; + + // Check default + QVERIFY(builder.flags() == 0); + + // Set flags + builder.setFlags(QMetaObjectBuilder::DynamicMetaObject); + QVERIFY(builder.flags() == QMetaObjectBuilder::DynamicMetaObject); +} + void tst_QMetaObjectBuilder::method() { QMetaObjectBuilder builder; + // Check null method + QMetaMethodBuilder nullMethod; + QCOMPARE(nullMethod.signature(), QByteArray()); + QVERIFY(nullMethod.methodType() == QMetaMethod::Method); + QVERIFY(nullMethod.returnType().isEmpty()); + QVERIFY(nullMethod.parameterNames().isEmpty()); + QVERIFY(nullMethod.tag().isEmpty()); + QVERIFY(nullMethod.access() == QMetaMethod::Public); + QCOMPARE(nullMethod.attributes(), 0); + QCOMPARE(nullMethod.index(), 0); + // Add a method and check its attributes. QMetaMethodBuilder method1 = builder.addMethod("foo(const QString&, int)"); QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); @@ -129,10 +209,10 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(builder.methodCount(), 1); // Add another method and check again. - QMetaMethodBuilder method2 = builder.addMethod("bar(QString)"); + QMetaMethodBuilder method2 = builder.addMethod("bar(QString)", "int"); QCOMPARE(method2.signature(), QByteArray("bar(QString)")); QVERIFY(method2.methodType() == QMetaMethod::Method); - QVERIFY(method2.returnType().isEmpty()); + QCOMPARE(method2.returnType(), QByteArray("int")); QVERIFY(method2.parameterNames().isEmpty()); QVERIFY(method2.tag().isEmpty()); QVERIFY(method2.access() == QMetaMethod::Public); @@ -163,7 +243,7 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(method1.index(), 0); QCOMPARE(method2.signature(), QByteArray("bar(QString)")); QVERIFY(method2.methodType() == QMetaMethod::Method); - QVERIFY(method2.returnType().isEmpty()); + QCOMPARE(method2.returnType(), QByteArray("int")); QVERIFY(method2.parameterNames().isEmpty()); QVERIFY(method2.tag().isEmpty()); QVERIFY(method2.access() == QMetaMethod::Public); @@ -214,6 +294,8 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(builder.indexOfMethod("foo(const QString&, int)"), -1); QCOMPARE(builder.indexOfMethod("bar(QString)"), 0); QCOMPARE(builder.indexOfMethod("baz()"), -1); + QCOMPARE(builder.method(0).signature(), QByteArray("bar(QString)")); + QCOMPARE(builder.method(9).signature(), QByteArray()); // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); @@ -247,6 +329,11 @@ void tst_QMetaObjectBuilder::slot() QCOMPARE(method2.index(), 1); QCOMPARE(builder.methodCount(), 2); + // Perform index-based lookup + QCOMPARE(builder.indexOfSlot("foo(const QString &, int)"), 0); + QCOMPARE(builder.indexOfSlot("bar(QString)"), 1); + QCOMPARE(builder.indexOfSlot("baz()"), -1); + // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); } @@ -279,6 +366,11 @@ void tst_QMetaObjectBuilder::signal() QCOMPARE(method2.index(), 1); QCOMPARE(builder.methodCount(), 2); + // Perform index-based lookup + QCOMPARE(builder.indexOfSignal("foo(const QString &, int)"), 0); + QCOMPARE(builder.indexOfSignal("bar(QString)"), 1); + QCOMPARE(builder.indexOfSignal("baz()"), -1); + // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Methods)); } @@ -315,6 +407,8 @@ void tst_QMetaObjectBuilder::constructor() QCOMPARE(builder.indexOfConstructor("foo(const QString&, int)"), 0); QCOMPARE(builder.indexOfConstructor("bar(QString)"), 1); QCOMPARE(builder.indexOfConstructor("baz()"), -1); + QCOMPARE(builder.constructor(1).signature(), QByteArray("bar(QString)")); + QCOMPARE(builder.constructor(9).signature(), QByteArray()); // Modify the attributes on ctor1. ctor1.setReturnType("int"); @@ -386,6 +480,17 @@ void tst_QMetaObjectBuilder::constructor() QCOMPARE(builder.indexOfConstructor("bar(QString)"), 0); QCOMPARE(builder.indexOfConstructor("baz()"), -1); + // Add constructor from prototype + QMetaMethod prototype = SomethingOfEverything::staticMetaObject.constructor(0); + QMetaMethodBuilder prototypeConstructor = builder.addMethod(prototype); + QCOMPARE(builder.constructorCount(), 2); + + QCOMPARE(prototypeConstructor.signature(), QByteArray("SomethingOfEverything()")); + QVERIFY(prototypeConstructor.methodType() == QMetaMethod::Constructor); + QCOMPARE(prototypeConstructor.returnType(), QByteArray()); + QVERIFY(prototypeConstructor.access() == QMetaMethod::Public); + QCOMPARE(prototypeConstructor.index(), 1); + // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Constructors)); } @@ -394,6 +499,24 @@ void tst_QMetaObjectBuilder::property() { QMetaObjectBuilder builder; + // Null property builder + QMetaPropertyBuilder nullProp; + QCOMPARE(nullProp.name(), QByteArray()); + QCOMPARE(nullProp.type(), QByteArray()); + QVERIFY(!nullProp.hasNotifySignal()); + QVERIFY(!nullProp.isReadable()); + QVERIFY(!nullProp.isWritable()); + QVERIFY(!nullProp.isResettable()); + QVERIFY(!nullProp.isDesignable()); + QVERIFY(!nullProp.isScriptable()); + QVERIFY(!nullProp.isStored()); + QVERIFY(!nullProp.isEditable()); + QVERIFY(!nullProp.isUser()); + QVERIFY(!nullProp.hasStdCppSet()); + QVERIFY(!nullProp.isEnumOrFlag()); + QVERIFY(!nullProp.isDynamic()); + QCOMPARE(nullProp.index(), 0); + // Add a property and check its attributes. QMetaPropertyBuilder prop1 = builder.addProperty("foo", "const QString &"); QCOMPARE(prop1.name(), QByteArray("foo")); @@ -409,6 +532,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop1.isUser()); QVERIFY(!prop1.hasStdCppSet()); QVERIFY(!prop1.isEnumOrFlag()); + QVERIFY(!prop1.isDynamic()); QCOMPARE(prop1.index(), 0); QCOMPARE(builder.propertyCount(), 1); @@ -427,6 +551,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isDynamic()); QCOMPARE(prop2.index(), 1); QCOMPARE(builder.propertyCount(), 2); @@ -434,6 +559,8 @@ void tst_QMetaObjectBuilder::property() QCOMPARE(builder.indexOfProperty("foo"), 0); QCOMPARE(builder.indexOfProperty("bar"), 1); QCOMPARE(builder.indexOfProperty("baz"), -1); + QCOMPARE(builder.property(1).name(), QByteArray("bar")); + QCOMPARE(builder.property(9).name(), QByteArray()); // Modify the attributes on prop1. prop1.setReadable(false); @@ -446,6 +573,7 @@ void tst_QMetaObjectBuilder::property() prop1.setUser(true); prop1.setStdCppSet(true); prop1.setEnumOrFlag(true); + prop1.setDynamic(true); // Check that prop1 is changed, but prop2 is not. QCOMPARE(prop1.name(), QByteArray("foo")); @@ -460,6 +588,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(prop1.isUser()); QVERIFY(prop1.hasStdCppSet()); QVERIFY(prop1.isEnumOrFlag()); + QVERIFY(prop1.isDynamic()); QVERIFY(prop2.isReadable()); QVERIFY(prop2.isWritable()); QCOMPARE(prop2.name(), QByteArray("bar")); @@ -472,6 +601,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isDynamic()); // Remove prop1 and check that prop2 becomes index 0. builder.removeProperty(0); @@ -487,6 +617,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isUser()); QVERIFY(!prop2.hasStdCppSet()); QVERIFY(!prop2.isEnumOrFlag()); + QVERIFY(!prop2.isDynamic()); QCOMPARE(prop2.index(), 0); // Perform index-based lookup again. @@ -510,6 +641,7 @@ void tst_QMetaObjectBuilder::property() prop2.setUser(false); \ prop2.setStdCppSet(false); \ prop2.setEnumOrFlag(false); \ + prop2.setDynamic(false); \ } while (0) #define COUNT_FLAGS() \ ((prop2.isReadable() ? 1 : 0) + \ @@ -521,7 +653,8 @@ void tst_QMetaObjectBuilder::property() (prop2.isEditable() ? 1 : 0) + \ (prop2.isUser() ? 1 : 0) + \ (prop2.hasStdCppSet() ? 1 : 0) + \ - (prop2.isEnumOrFlag() ? 1 : 0)) + (prop2.isEnumOrFlag() ? 1 : 0) + \ + (prop2.isDynamic() ? 1 : 0)) #define CHECK_FLAG(setFunc,isFunc) \ do { \ CLEAR_FLAGS(); \ @@ -540,9 +673,20 @@ void tst_QMetaObjectBuilder::property() CHECK_FLAG(setUser, isUser); CHECK_FLAG(setStdCppSet, hasStdCppSet); CHECK_FLAG(setEnumOrFlag, isEnumOrFlag); + CHECK_FLAG(setDynamic, isDynamic); // Check that nothing else changed. QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::Properties)); + + // Add property from prototype + QMetaProperty prototype = SomethingOfEverything::staticMetaObject.property(1); + QVERIFY(prototype.name() == QByteArray("prop")); + QMetaPropertyBuilder prototypeProp = builder.addProperty(prototype); + QCOMPARE(prototypeProp.name(), QByteArray("prop")); + QVERIFY(prototypeProp.hasNotifySignal()); + QCOMPARE(prototypeProp.notifySignal().signature(), QByteArray("propChanged(QString)")); + QCOMPARE(builder.methodCount(), 1); + QCOMPARE(builder.method(0).signature(), QByteArray("propChanged(QString)")); } void tst_QMetaObjectBuilder::notifySignal() @@ -601,6 +745,8 @@ void tst_QMetaObjectBuilder::enumerator() QCOMPARE(builder.indexOfEnumerator("foo"), 0); QCOMPARE(builder.indexOfEnumerator("bar"), 1); QCOMPARE(builder.indexOfEnumerator("baz"), -1); + QCOMPARE(builder.enumerator(1).name(), QByteArray("bar")); + QCOMPARE(builder.enumerator(9).name(), QByteArray()); // Modify the attributes on enum1. enum1.setIsFlag(true); @@ -616,6 +762,7 @@ void tst_QMetaObjectBuilder::enumerator() QCOMPARE(enum1.key(0), QByteArray("ABC")); QCOMPARE(enum1.key(1), QByteArray("DEF")); QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.key(3), QByteArray()); QCOMPARE(enum1.value(0), 0); QCOMPARE(enum1.value(1), 1); QCOMPARE(enum1.value(2), -1); @@ -637,6 +784,7 @@ void tst_QMetaObjectBuilder::enumerator() QCOMPARE(enum1.key(0), QByteArray("ABC")); QCOMPARE(enum1.key(1), QByteArray("DEF")); QCOMPARE(enum1.key(2), QByteArray("GHI")); + QCOMPARE(enum1.key(3), QByteArray()); QCOMPARE(enum1.value(0), 0); QCOMPARE(enum1.value(1), 1); QCOMPARE(enum1.value(2), -1); @@ -646,6 +794,29 @@ void tst_QMetaObjectBuilder::enumerator() QCOMPARE(enum2.index(), 1); QCOMPARE(enum2.key(0), QByteArray("XYZ")); QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.key(2), QByteArray()); + QCOMPARE(enum2.value(0), 10); + QCOMPARE(enum2.value(1), 19); + + // Remove enum1 key + enum1.removeKey(2); + QCOMPARE(enum1.name(), QByteArray("foo")); + QVERIFY(enum1.isFlag()); + QCOMPARE(enum1.keyCount(), 2); + QCOMPARE(enum1.index(), 0); + QCOMPARE(enum1.key(0), QByteArray("ABC")); + QCOMPARE(enum1.key(1), QByteArray("DEF")); + QCOMPARE(enum1.key(2), QByteArray()); + QCOMPARE(enum1.value(0), 0); + QCOMPARE(enum1.value(1), 1); + QCOMPARE(enum1.value(2), -1); + QCOMPARE(enum2.name(), QByteArray("bar")); + QVERIFY(enum2.isFlag()); + QCOMPARE(enum2.keyCount(), 2); + QCOMPARE(enum2.index(), 1); + QCOMPARE(enum2.key(0), QByteArray("XYZ")); + QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.key(2), QByteArray()); QCOMPARE(enum2.value(0), 10); QCOMPARE(enum2.value(1), 19); @@ -659,6 +830,7 @@ void tst_QMetaObjectBuilder::enumerator() QCOMPARE(enum2.index(), 0); QCOMPARE(enum2.key(0), QByteArray("XYZ")); QCOMPARE(enum2.key(1), QByteArray("UVW")); + QCOMPARE(enum2.key(2), QByteArray()); QCOMPARE(enum2.value(0), 10); QCOMPARE(enum2.value(1), 19); @@ -682,6 +854,8 @@ void tst_QMetaObjectBuilder::classInfo() QCOMPARE(builder.classInfoValue(0), QByteArray("value1")); QCOMPARE(builder.classInfoName(1), QByteArray("bar")); QCOMPARE(builder.classInfoValue(1), QByteArray("value2")); + QCOMPARE(builder.classInfoName(9), QByteArray()); + QCOMPARE(builder.classInfoValue(9), QByteArray()); QCOMPARE(builder.classInfoCount(), 2); // Perform index-based lookup. @@ -738,61 +912,6 @@ void tst_QMetaObjectBuilder::staticMetacall() QVERIFY(checkForSideEffects(builder, QMetaObjectBuilder::StaticMetacall)); } -// Dummy class that has something of every type of thing moc can generate. -class SomethingOfEverything : public QObject -{ - Q_OBJECT - Q_CLASSINFO("ci_foo", "ABC") - Q_CLASSINFO("ci_bar", "DEF") - Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) - Q_PROPERTY(QString prop2 READ prop WRITE setProp) - Q_PROPERTY(SomethingEnum eprop READ eprop) - Q_PROPERTY(SomethingFlagEnum fprop READ fprop) - Q_PROPERTY(QLocale::Language language READ language) - Q_ENUMS(SomethingEnum) - Q_FLAGS(SomethingFlagEnum) -public: - Q_INVOKABLE SomethingOfEverything() {} - ~SomethingOfEverything() {} - - enum SomethingEnum - { - GHI, - JKL = 10 - }; - - enum SomethingFlagEnum - { - XYZ = 1, - UVW = 8 - }; - - Q_INVOKABLE Q_SCRIPTABLE void method1() {} - - QString prop() const { return QString(); } - void setProp(const QString& v) { Q_UNUSED(v); } - - SomethingOfEverything::SomethingEnum eprop() const { return GHI; } - SomethingOfEverything::SomethingFlagEnum fprop() const { return XYZ; } - QLocale::Language language() const { return QLocale::English; } - -public slots: - void slot1(const QString&) {} - void slot2(int, const QString&) {} - -private slots: - void slot3() {} - -protected slots: - Q_SCRIPTABLE void slot4(int) {} - void slot5(int a, const QString& b) { Q_UNUSED(a); Q_UNUSED(b); } - -signals: - void sig1(); - void sig2(int x, const QString& y); - void propChanged(const QString&); -}; - // Copy the entire contents of a static QMetaObject and then check // that QMetaObjectBuilder will produce an exact copy as output. void tst_QMetaObjectBuilder::copyMetaObject() @@ -817,6 +936,8 @@ void tst_QMetaObjectBuilder::copyMetaObject() // it round-trips to the exact same value. void tst_QMetaObjectBuilder::serialize() { + // Full QMetaObjectBuilder + { QMetaObjectBuilder builder(&SomethingOfEverything::staticMetaObject); QMetaObject *meta = builder.toMetaObject(); @@ -835,6 +956,53 @@ void tst_QMetaObjectBuilder::serialize() QVERIFY(sameMetaObject(meta, meta2)); qFree(meta); qFree(meta2); + } + + // Partial QMetaObjectBuilder + { + QMetaObjectBuilder builder; + builder.setClassName("Test"); + builder.addProperty("foo", "int"); + builder.setSuperClass(0); + + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append); + builder.serialize(stream); + + QMetaObjectBuilder builder2; + QDataStream stream2(data); + builder2.deserialize(stream2, QMap()); + + QCOMPARE(builder.superClass(), builder2.superClass()); + QCOMPARE(builder.className(), builder2.className()); + QCOMPARE(builder.propertyCount(), builder2.propertyCount()); + QCOMPARE(builder.property(0).name(), builder2.property(0).name()); + QCOMPARE(builder.property(0).type(), builder2.property(0).type()); + } +} + +// Check that removing a method updates notify signals appropriately +void tst_QMetaObjectBuilder::removeNotifySignal() +{ + QMetaObjectBuilder builder; + + QMetaMethodBuilder method1 = builder.addSignal("foo(const QString&, int)"); + QMetaMethodBuilder method2 = builder.addSignal("bar(QString)"); + + // Setup property + QMetaPropertyBuilder prop = builder.addProperty("prop", "const QString &"); + prop.setNotifySignal(method2); + QVERIFY(prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 1); + + // Remove non-notify signal + builder.removeMethod(0); + QVERIFY(prop.hasNotifySignal()); + QCOMPARE(prop.notifySignal().index(), 0); + + // Remove notify signal + builder.removeMethod(0); + QVERIFY(!prop.hasNotifySignal()); } // Check that the only changes to a "builder" relative to the default -- cgit v0.12