From 3a3515b5a7f5d41fe79a53f162b69f58aca9731d Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Tue, 6 Mar 2012 17:25:58 +0100 Subject: [PATCH] QmlEngineDebug: Simplify the utility classes Change-Id: Ie0e1b6e9edd6a09fef565635cc793f8bdb6c42e7 Reviewed-by: Kai Koehne --- .../qqmlenginedebugclient.cpp | 1077 ++++------------- .../qqmlenginedebugclient.h | 463 +++---- .../qqmlenginedebugservice.pro | 4 +- .../tst_qqmlenginedebugservice.cpp | 979 ++++++--------- 4 files changed, 776 insertions(+), 1747 deletions(-) diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp index db3ab192d0..9639a36065 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp @@ -78,968 +78,383 @@ QDataStream &operator>>(QDataStream &ds, QmlObjectProperty &data) return ds; } -class QQmlEngineDebugClientPrivate +QQmlEngineDebugClient::QQmlEngineDebugClient( + QQmlDebugConnection *connection) + : QQmlDebugClient(QLatin1String("QmlDebugger"), connection), + m_nextId(0), + m_valid(false) { -public: - QQmlEngineDebugClientPrivate(QQmlEngineDebugClient *); - ~QQmlEngineDebugClientPrivate(); - - void message(const QByteArray &); - - QQmlEngineDebugClient *q; - int nextId; - int getId(); - - void decode(QDataStream &, QQmlDebugContextReference &); - void decode(QDataStream &, QQmlDebugObjectReference &, bool simple); - - static void remove(QQmlEngineDebugClient *, QQmlDebugEnginesQuery *); - static void remove(QQmlEngineDebugClient *, QQmlDebugRootContextQuery *); - static void remove(QQmlEngineDebugClient *, QQmlDebugObjectQuery *); - static void remove(QQmlEngineDebugClient *, QQmlDebugExpressionQuery *); - static void remove(QQmlEngineDebugClient *, QQmlDebugWatch *); - - QHash enginesQuery; - QHash rootContextQuery; - QHash objectQuery; - QHash expressionQuery; - - QHash watched; -}; - -void QQmlEngineDebugClient::stateChanged(State status) -{ - emit newState(status); -} - -void QQmlEngineDebugClient::messageReceived(const QByteArray &data) -{ - d->message(data); -} - -QQmlEngineDebugClientPrivate::QQmlEngineDebugClientPrivate(QQmlEngineDebugClient *p) - : q(p), - nextId(0) -{ -} - -QQmlEngineDebugClientPrivate::~QQmlEngineDebugClientPrivate() -{ - QHash::iterator enginesIter = enginesQuery.begin(); - for (; enginesIter != enginesQuery.end(); ++enginesIter) { - enginesIter.value()->m_client = 0; - if (enginesIter.value()->state() == QQmlDebugQuery::Waiting) - enginesIter.value()->setState(QQmlDebugQuery::Error); - } - - QHash::iterator rootContextIter = rootContextQuery.begin(); - for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) { - rootContextIter.value()->m_client = 0; - if (rootContextIter.value()->state() == QQmlDebugQuery::Waiting) - rootContextIter.value()->setState(QQmlDebugQuery::Error); - } - - QHash::iterator objectIter = objectQuery.begin(); - for (; objectIter != objectQuery.end(); ++objectIter) { - objectIter.value()->m_client = 0; - if (objectIter.value()->state() == QQmlDebugQuery::Waiting) - objectIter.value()->setState(QQmlDebugQuery::Error); - } - - QHash::iterator exprIter = expressionQuery.begin(); - for (; exprIter != expressionQuery.end(); ++exprIter) { - exprIter.value()->m_client = 0; - if (exprIter.value()->state() == QQmlDebugQuery::Waiting) - exprIter.value()->setState(QQmlDebugQuery::Error); - } - - QHash::iterator watchIter = watched.begin(); - for (; watchIter != watched.end(); ++watchIter) { - watchIter.value()->m_client = 0; - watchIter.value()->setState(QQmlDebugWatch::Dead); - } -} - -int QQmlEngineDebugClientPrivate::getId() -{ - return nextId++; -} - -void QQmlEngineDebugClientPrivate::remove(QQmlEngineDebugClient *c, QQmlDebugEnginesQuery *q) -{ - if (c && q) { - QQmlEngineDebugClientPrivate *p = c->getPrivate(); - p->enginesQuery.remove(q->m_queryId); - } -} - -void QQmlEngineDebugClientPrivate::remove(QQmlEngineDebugClient *c, - QQmlDebugRootContextQuery *q) -{ - if (c && q) { - QQmlEngineDebugClientPrivate *p = c->getPrivate(); - p->rootContextQuery.remove(q->m_queryId); - } -} - -void QQmlEngineDebugClientPrivate::remove(QQmlEngineDebugClient *c, QQmlDebugObjectQuery *q) -{ - if (c && q) { - QQmlEngineDebugClientPrivate *p = c->getPrivate(); - p->objectQuery.remove(q->m_queryId); - } -} - -void QQmlEngineDebugClientPrivate::remove(QQmlEngineDebugClient *c, QQmlDebugExpressionQuery *q) -{ - if (c && q) { - QQmlEngineDebugClientPrivate *p = c->getPrivate(); - p->expressionQuery.remove(q->m_queryId); - } -} - -void QQmlEngineDebugClientPrivate::remove(QQmlEngineDebugClient *c, QQmlDebugWatch *w) -{ - if (c && w) { - QQmlEngineDebugClientPrivate *p = c->getPrivate(); - p->watched.remove(w->m_queryId); - } -} - -void QQmlEngineDebugClientPrivate::decode(QDataStream &ds, QQmlDebugObjectReference &o, - bool simple) -{ - QmlObjectData data; - ds >> data; - o.m_debugId = data.objectId; - o.m_class = data.objectType; - o.m_idString = data.idString; - o.m_name = data.objectName; - o.m_source.m_url = data.url; - o.m_source.m_lineNumber = data.lineNumber; - o.m_source.m_columnNumber = data.columnNumber; - o.m_contextDebugId = data.contextId; - - if (simple) - return; - - int childCount; - bool recur; - ds >> childCount >> recur; - - for (int ii = 0; ii < childCount; ++ii) { - o.m_children.append(QQmlDebugObjectReference()); - decode(ds, o.m_children.last(), !recur); - } - - int propCount; - ds >> propCount; - - for (int ii = 0; ii < propCount; ++ii) { - QmlObjectProperty data; - ds >> data; - QQmlDebugPropertyReference prop; - prop.m_objectDebugId = o.m_debugId; - prop.m_name = data.name; - prop.m_binding = data.binding; - prop.m_hasNotifySignal = data.hasNotifySignal; - prop.m_valueTypeName = data.valueTypeName; - switch (data.type) { - case QmlObjectProperty::Basic: - case QmlObjectProperty::List: - case QmlObjectProperty::SignalProperty: - { - prop.m_value = data.value; - break; - } - case QmlObjectProperty::Object: - { - QQmlDebugObjectReference obj; - obj.m_debugId = prop.m_value.toInt(); - prop.m_value = QVariant::fromValue(obj); - break; - } - case QmlObjectProperty::Unknown: - break; - } - o.m_properties << prop; - } -} - -void QQmlEngineDebugClientPrivate::decode(QDataStream &ds, QQmlDebugContextReference &c) -{ - ds >> c.m_name >> c.m_debugId; - - int contextCount; - ds >> contextCount; - - for (int ii = 0; ii < contextCount; ++ii) { - c.m_contexts.append(QQmlDebugContextReference()); - decode(ds, c.m_contexts.last()); - } - - int objectCount; - ds >> objectCount; - - for (int ii = 0; ii < objectCount; ++ii) { - QQmlDebugObjectReference obj; - decode(ds, obj, true); - - obj.m_contextDebugId = c.m_debugId; - c.m_objects << obj; - } } -void QQmlEngineDebugClientPrivate::message(const QByteArray &data) +quint32 QQmlEngineDebugClient::addWatch( + const QmlDebugPropertyReference &property, bool *success) { - QDataStream ds(data); - - QByteArray type; - ds >> type; - - //qDebug() << "QQmlEngineDebugPrivate::message()" << type; - - if (type == "LIST_ENGINES_R") { - int queryId; - ds >> queryId; - - QQmlDebugEnginesQuery *query = enginesQuery.value(queryId); - if (!query) - return; - enginesQuery.remove(queryId); - - int count; - ds >> count; - - for (int ii = 0; ii < count; ++ii) { - QQmlDebugEngineReference ref; - ds >> ref.m_name; - ds >> ref.m_debugId; - query->m_engines << ref; - } - - query->m_client = 0; - query->setState(QQmlDebugQuery::Completed); - } else if (type == "LIST_OBJECTS_R") { - int queryId; - ds >> queryId; - - QQmlDebugRootContextQuery *query = rootContextQuery.value(queryId); - if (!query) - return; - rootContextQuery.remove(queryId); - - if (!ds.atEnd()) - decode(ds, query->m_context); - - query->m_client = 0; - query->setState(QQmlDebugQuery::Completed); - } else if (type == "FETCH_OBJECT_R") { - int queryId; - ds >> queryId; - - QQmlDebugObjectQuery *query = objectQuery.value(queryId); - if (!query) - return; - objectQuery.remove(queryId); - - if (!ds.atEnd()) - decode(ds, query->m_object, false); - - query->m_client = 0; - query->setState(QQmlDebugQuery::Completed); - } else if (type == "EVAL_EXPRESSION_R") { - int queryId; - QVariant result; - ds >> queryId >> result; - - QQmlDebugExpressionQuery *query = expressionQuery.value(queryId); - if (!query) - return; - expressionQuery.remove(queryId); - - query->m_result = result; - query->m_client = 0; - query->setState(QQmlDebugQuery::Completed); - } else if (type == "WATCH_PROPERTY_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QQmlDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive); - } else if (type == "WATCH_OBJECT_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QQmlDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive); - } else if (type == "WATCH_EXPR_OBJECT_R") { - int queryId; - bool ok; - ds >> queryId >> ok; - - QQmlDebugWatch *watch = watched.value(queryId); - if (!watch) - return; - - watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive); - } else if (type == "UPDATE_WATCH") { - int queryId; - int debugId; - QByteArray name; - QVariant value; - ds >> queryId >> debugId >> name >> value; - - QQmlDebugWatch *watch = watched.value(queryId, 0); - if (!watch) - return; - emit watch->valueChanged(name, value); - } else if (type == "OBJECT_CREATED") { - emit q->newObjects(); - } else if (type == "SET_BINDING_R" || - type == "RESET_BINDING_R" || - type == "SET_METHOD_BODY_R" || - type == "NO_WATCH_R") { - bool valid; - ds >> valid; - } -} - -QQmlEngineDebugClient::QQmlEngineDebugClient(QQmlDebugConnection *client) - : QQmlDebugClient(QLatin1String("QmlDebugger"), client), - d(new QQmlEngineDebugClientPrivate(this)) -{ -} - -QQmlEngineDebugClient::~QQmlEngineDebugClient() -{ - delete d; -} - -QQmlDebugPropertyWatch *QQmlEngineDebugClient::addWatch(const QQmlDebugPropertyReference &property, QObject *parent) -{ - QQmlDebugPropertyWatch *watch = new QQmlDebugPropertyWatch(parent); + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = property.objectDebugId(); - watch->m_name = property.name(); - d->watched.insert(queryId, watch); - + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8(); + ds << QByteArray("WATCH_PROPERTY") << id << property.objectDebugId + << property.name.toUtf8(); sendMessage(message); - } else { - watch->m_state = QQmlDebugWatch::Dead; + *success = true; } - - return watch; + return id; } -QQmlDebugWatch *QQmlEngineDebugClient::addWatch(const QQmlDebugContextReference &, const QString &, QObject *) +quint32 QQmlEngineDebugClient::addWatch( + const QmlDebugContextReference &, const QString &, bool *success) { - qWarning("QQmlEngineDebug::addWatch(): Not implemented"); + *success = false; + qWarning("QQmlEngineDebugClient::addWatch(): Not implemented"); return 0; } -QQmlDebugObjectExpressionWatch *QQmlEngineDebugClient::addWatch(const QQmlDebugObjectReference &object, const QString &expr, QObject *parent) +quint32 QQmlEngineDebugClient::addWatch( + const QmlDebugObjectReference &object, const QString &expr, + bool *success) { - QQmlDebugObjectExpressionWatch *watch = new QQmlDebugObjectExpressionWatch(parent); + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = object.debugId(); - watch->m_expr = expr; - d->watched.insert(queryId, watch); - + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr; + ds << QByteArray("WATCH_EXPR_OBJECT") << id << object.debugId << expr; sendMessage(message); - } else { - watch->m_state = QQmlDebugWatch::Dead; + *success = true; } - return watch; + return id; } -QQmlDebugWatch *QQmlEngineDebugClient::addWatch(const QQmlDebugObjectReference &object, QObject *parent) +quint32 QQmlEngineDebugClient::addWatch( + const QmlDebugObjectReference &object, bool *success) { - QQmlDebugWatch *watch = new QQmlDebugWatch(parent); + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled) { - int queryId = d->getId(); - watch->m_queryId = queryId; - watch->m_client = this; - watch->m_objectDebugId = object.debugId(); - d->watched.insert(queryId, watch); - + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId(); + ds << QByteArray("WATCH_OBJECT") << id << object.debugId; sendMessage(message); - } else { - watch->m_state = QQmlDebugWatch::Dead; + *success = true; } - - return watch; + return id; } -QQmlDebugWatch *QQmlEngineDebugClient::addWatch(const QQmlDebugFileReference &, QObject *) +quint32 QQmlEngineDebugClient::addWatch( + const QmlDebugFileReference &, bool *success) { - qWarning("QQmlEngineDebug::addWatch(): Not implemented"); + *success = false; + qWarning("QQmlEngineDebugClient::addWatch(): Not implemented"); return 0; } -void QQmlEngineDebugClient::removeWatch(QQmlDebugWatch *watch) +void QQmlEngineDebugClient::removeWatch(quint32 id, bool *success) { - if (!watch || !watch->m_client) - return; - - watch->m_client = 0; - watch->setState(QQmlDebugWatch::Inactive); - - d->watched.remove(watch->queryId()); - + *success = false; if (state() == QQmlDebugClient::Enabled) { QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("NO_WATCH") << watch->queryId(); + ds << QByteArray("NO_WATCH") << id; sendMessage(message); + *success = true; } } -QQmlDebugEnginesQuery *QQmlEngineDebugClient::queryAvailableEngines(QObject *parent) +quint32 QQmlEngineDebugClient::queryAvailableEngines(bool *success) { - QQmlDebugEnginesQuery *query = new QQmlDebugEnginesQuery(parent); + m_engines.clear(); + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->enginesQuery.insert(queryId, query); - + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("LIST_ENGINES") << queryId; + ds << QByteArray("LIST_ENGINES") << id; sendMessage(message); - } else { - query->m_state = QQmlDebugQuery::Error; + *success = true; } - - return query; + return id; } -QQmlDebugRootContextQuery *QQmlEngineDebugClient::queryRootContexts(const QQmlDebugEngineReference &engine, QObject *parent) +quint32 QQmlEngineDebugClient::queryRootContexts( + const QmlDebugEngineReference &engine, bool *success) { - QQmlDebugRootContextQuery *query = new QQmlDebugRootContextQuery(parent); - if (state() == QQmlDebugClient::Enabled && engine.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->rootContextQuery.insert(queryId, query); - + m_rootContext = QmlDebugContextReference(); + quint32 id; + *success = false; + if (state() == QQmlDebugClient::Enabled && engine.debugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId(); + ds << QByteArray("LIST_OBJECTS") << id << engine.debugId; sendMessage(message); - } else { - query->m_state = QQmlDebugQuery::Error; + *success = true; } - - return query; + return id; } -QQmlDebugObjectQuery *QQmlEngineDebugClient::queryObject(const QQmlDebugObjectReference &object, QObject *parent) +quint32 QQmlEngineDebugClient::queryObject( + const QmlDebugObjectReference &object, bool *success) { - QQmlDebugObjectQuery *query = new QQmlDebugObjectQuery(parent); - if (state() == QQmlDebugClient::Enabled && object.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->objectQuery.insert(queryId, query); - + m_object = QmlDebugObjectReference(); + quint32 id; + *success = false; + if (state() == QQmlDebugClient::Enabled && object.debugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() - << false << true; + ds << QByteArray("FETCH_OBJECT") << id << object.debugId << false << + true; sendMessage(message); - } else { - query->m_state = QQmlDebugQuery::Error; + *success = true; } - - return query; + return id; } -QQmlDebugObjectQuery *QQmlEngineDebugClient::queryObjectRecursive(const QQmlDebugObjectReference &object, QObject *parent) +quint32 QQmlEngineDebugClient::queryObjectRecursive( + const QmlDebugObjectReference &object, bool *success) { - QQmlDebugObjectQuery *query = new QQmlDebugObjectQuery(parent); - if (state() == QQmlDebugClient::Enabled && object.debugId() != -1) { - query->m_client = this; - int queryId = d->getId(); - query->m_queryId = queryId; - d->objectQuery.insert(queryId, query); - + m_object = QmlDebugObjectReference(); + quint32 id; + *success = false; + if (state() == QQmlDebugClient::Enabled && object.debugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() - << true << true; + ds << QByteArray("FETCH_OBJECT") << id << object.debugId << true << + true; sendMessage(message); - } else { - query->m_state = QQmlDebugQuery::Error; + *success = true; } - - return query; + return id; } -QQmlDebugExpressionQuery *QQmlEngineDebugClient::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent) +quint32 QQmlEngineDebugClient::queryExpressionResult( + int objectDebugId, const QString &expr, bool *success) { - QQmlDebugExpressionQuery *query = new QQmlDebugExpressionQuery(parent); + m_exprResult = QVariant(); + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) { - query->m_client = this; - query->m_expr = expr; - int queryId = d->getId(); - query->m_queryId = queryId; - d->expressionQuery.insert(queryId, query); - + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr; + ds << QByteArray("EVAL_EXPRESSION") << id << objectDebugId << expr; sendMessage(message); - } else { - query->m_state = QQmlDebugQuery::Error; + *success = true; } - - return query; + return id; } -bool QQmlEngineDebugClient::setBindingForObject(int objectDebugId, const QString &propertyName, - const QVariant &bindingExpression, - bool isLiteralValue, - QString source, int line) +quint32 QQmlEngineDebugClient::setBindingForObject( + int objectDebugId, + const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QString source, int line, + bool *success) { + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("SET_BINDING") << d->getId() << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line; + ds << QByteArray("SET_BINDING") << id << objectDebugId << propertyName + << bindingExpression << isLiteralValue << source << line; sendMessage(message); - return true; - } else { - return false; + *success = true; } + return id; } -bool QQmlEngineDebugClient::resetBindingForObject(int objectDebugId, const QString &propertyName) +quint32 QQmlEngineDebugClient::resetBindingForObject( + int objectDebugId, + const QString &propertyName, + bool *success) { + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("RESET_BINDING") << d->getId() << objectDebugId << propertyName; + ds << QByteArray("RESET_BINDING") << id << objectDebugId << propertyName; sendMessage(message); - return true; - } else { - return false; + *success = true; } + return id; } -bool QQmlEngineDebugClient::setMethodBody(int objectDebugId, const QString &methodName, - const QString &methodBody) +quint32 QQmlEngineDebugClient::setMethodBody( + int objectDebugId, const QString &methodName, + const QString &methodBody, bool *success) { + quint32 id; + *success = false; if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) { + id = getId(); QByteArray message; QDataStream ds(&message, QIODevice::WriteOnly); - ds << QByteArray("SET_METHOD_BODY") << d->getId() << objectDebugId << methodName << methodBody; + ds << QByteArray("SET_METHOD_BODY") << id << objectDebugId + << methodName << methodBody; sendMessage(message); - return true; - } else { - return false; + *success = true; } + return id; } -QQmlDebugWatch::QQmlDebugWatch(QObject *parent) - : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) -{ -} - -QQmlDebugWatch::~QQmlDebugWatch() -{ - if (m_client && m_queryId != -1) - QQmlEngineDebugClientPrivate::remove(m_client, this); -} - -int QQmlDebugWatch::queryId() const -{ - return m_queryId; -} - -int QQmlDebugWatch::objectDebugId() const -{ - return m_objectDebugId; -} - -QQmlDebugWatch::State QQmlDebugWatch::state() const -{ - return m_state; -} - -void QQmlDebugWatch::setState(State s) -{ - if (m_state == s) - return; - m_state = s; - emit stateChanged(m_state); -} - -QQmlDebugPropertyWatch::QQmlDebugPropertyWatch(QObject *parent) - : QQmlDebugWatch(parent) -{ -} - -QString QQmlDebugPropertyWatch::name() const -{ - return m_name; -} - - -QQmlDebugObjectExpressionWatch::QQmlDebugObjectExpressionWatch(QObject *parent) - : QQmlDebugWatch(parent) -{ -} - -QString QQmlDebugObjectExpressionWatch::expression() const -{ - return m_expr; -} - - -QQmlDebugQuery::QQmlDebugQuery(QObject *parent) - : QObject(parent), m_state(Waiting) -{ -} - -QQmlDebugQuery::State QQmlDebugQuery::state() const -{ - return m_state; -} - -bool QQmlDebugQuery::isWaiting() const +void QQmlEngineDebugClient::decode(QDataStream &ds, + QmlDebugObjectReference &o, + bool simple) { - return m_state == Waiting; -} + QmlObjectData data; + ds >> data; + o.debugId = data.objectId; + o.className = data.objectType; + o.idString = data.idString; + o.name = data.objectName; + o.source.url = data.url; + o.source.lineNumber = data.lineNumber; + o.source.columnNumber = data.columnNumber; + o.contextDebugId = data.contextId; -void QQmlDebugQuery::setState(State s) -{ - if (m_state == s) + if (simple) return; - m_state = s; - emit stateChanged(m_state); -} - -QQmlDebugEnginesQuery::QQmlDebugEnginesQuery(QObject *parent) - : QQmlDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QQmlDebugEnginesQuery::~QQmlDebugEnginesQuery() -{ - if (m_client && m_queryId != -1) - QQmlEngineDebugClientPrivate::remove(m_client, this); -} - -QList QQmlDebugEnginesQuery::engines() const -{ - return m_engines; -} - -QQmlDebugRootContextQuery::QQmlDebugRootContextQuery(QObject *parent) - : QQmlDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QQmlDebugRootContextQuery::~QQmlDebugRootContextQuery() -{ - if (m_client && m_queryId != -1) - QQmlEngineDebugClientPrivate::remove(m_client, this); -} - -QQmlDebugContextReference QQmlDebugRootContextQuery::rootContext() const -{ - return m_context; -} - -QQmlDebugObjectQuery::QQmlDebugObjectQuery(QObject *parent) - : QQmlDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QQmlDebugObjectQuery::~QQmlDebugObjectQuery() -{ - if (m_client && m_queryId != -1) - QQmlEngineDebugClientPrivate::remove(m_client, this); -} - -QQmlDebugObjectReference QQmlDebugObjectQuery::object() const -{ - return m_object; -} - -QQmlDebugExpressionQuery::QQmlDebugExpressionQuery(QObject *parent) - : QQmlDebugQuery(parent), m_client(0), m_queryId(-1) -{ -} - -QQmlDebugExpressionQuery::~QQmlDebugExpressionQuery() -{ - if (m_client && m_queryId != -1) - QQmlEngineDebugClientPrivate::remove(m_client, this); -} - -QVariant QQmlDebugExpressionQuery::expression() const -{ - return m_expr; -} - -QVariant QQmlDebugExpressionQuery::result() const -{ - return m_result; -} - -QQmlDebugEngineReference::QQmlDebugEngineReference() - : m_debugId(-1) -{ -} - -QQmlDebugEngineReference::QQmlDebugEngineReference(int debugId) - : m_debugId(debugId) -{ -} - -QQmlDebugEngineReference::QQmlDebugEngineReference(const QQmlDebugEngineReference &o) - : m_debugId(o.m_debugId), m_name(o.m_name) -{ -} - -QQmlDebugEngineReference & -QQmlDebugEngineReference::operator=(const QQmlDebugEngineReference &o) -{ - m_debugId = o.m_debugId; m_name = o.m_name; - return *this; -} - -int QQmlDebugEngineReference::debugId() const -{ - return m_debugId; -} - -QString QQmlDebugEngineReference::name() const -{ - return m_name; -} - -QQmlDebugObjectReference::QQmlDebugObjectReference() - : m_debugId(-1), m_contextDebugId(-1) -{ -} - -QQmlDebugObjectReference::QQmlDebugObjectReference(int debugId) - : m_debugId(debugId), m_contextDebugId(-1) -{ -} - -QQmlDebugObjectReference::QQmlDebugObjectReference(const QQmlDebugObjectReference &o) - : m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString), - m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId), - m_properties(o.m_properties), m_children(o.m_children) -{ -} - -QQmlDebugObjectReference & -QQmlDebugObjectReference::operator=(const QQmlDebugObjectReference &o) -{ - m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString; - m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId; - m_properties = o.m_properties; m_children = o.m_children; - return *this; -} - -int QQmlDebugObjectReference::debugId() const -{ - return m_debugId; -} - -QString QQmlDebugObjectReference::className() const -{ - return m_class; -} - -QString QQmlDebugObjectReference::idString() const -{ - return m_idString; -} - -QString QQmlDebugObjectReference::name() const -{ - return m_name; -} - -QQmlDebugFileReference QQmlDebugObjectReference::source() const -{ - return m_source; -} - -int QQmlDebugObjectReference::contextDebugId() const -{ - return m_contextDebugId; -} - -QList QQmlDebugObjectReference::properties() const -{ - return m_properties; -} - -QList QQmlDebugObjectReference::children() const -{ - return m_children; -} - -QQmlDebugContextReference::QQmlDebugContextReference() - : m_debugId(-1) -{ -} - -QQmlDebugContextReference::QQmlDebugContextReference(const QQmlDebugContextReference &o) - : m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts) -{ -} - -QQmlDebugContextReference &QQmlDebugContextReference::operator=(const QQmlDebugContextReference &o) -{ - m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; - m_contexts = o.m_contexts; - return *this; -} -int QQmlDebugContextReference::debugId() const -{ - return m_debugId; -} - -QString QQmlDebugContextReference::name() const -{ - return m_name; -} + int childCount; + bool recur; + ds >> childCount >> recur; -QList QQmlDebugContextReference::objects() const -{ - return m_objects; -} + for (int ii = 0; ii < childCount; ++ii) { + o.children.append(QmlDebugObjectReference()); + decode(ds, o.children.last(), !recur); + } -QList QQmlDebugContextReference::contexts() const -{ - return m_contexts; -} + int propCount; + ds >> propCount; -QQmlDebugFileReference::QQmlDebugFileReference() - : m_lineNumber(-1), m_columnNumber(-1) -{ + for (int ii = 0; ii < propCount; ++ii) { + QmlObjectProperty data; + ds >> data; + QmlDebugPropertyReference prop; + prop.objectDebugId = o.debugId; + prop.name = data.name; + prop.binding = data.binding; + prop.hasNotifySignal = data.hasNotifySignal; + prop.valueTypeName = data.valueTypeName; + switch (data.type) { + case QmlObjectProperty::Basic: + case QmlObjectProperty::List: + case QmlObjectProperty::SignalProperty: + { + prop.value = data.value; + break; + } + case QmlObjectProperty::Object: + { + QmlDebugObjectReference obj; + obj.debugId = prop.value.toInt(); + prop.value = qVariantFromValue(obj); + break; + } + case QmlObjectProperty::Unknown: + break; + } + o.properties << prop; + } } -QQmlDebugFileReference::QQmlDebugFileReference(const QQmlDebugFileReference &o) - : m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber) +void QQmlEngineDebugClient::decode(QDataStream &ds, + QmlDebugContextReference &c) { -} + ds >> c.name >> c.debugId; -QQmlDebugFileReference &QQmlDebugFileReference::operator=(const QQmlDebugFileReference &o) -{ - m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber; - return *this; -} + int contextCount; + ds >> contextCount; -QUrl QQmlDebugFileReference::url() const -{ - return m_url; -} + for (int ii = 0; ii < contextCount; ++ii) { + c.contexts.append(QmlDebugContextReference()); + decode(ds, c.contexts.last()); + } -void QQmlDebugFileReference::setUrl(const QUrl &u) -{ - m_url = u; -} + int objectCount; + ds >> objectCount; -int QQmlDebugFileReference::lineNumber() const -{ - return m_lineNumber; -} + for (int ii = 0; ii < objectCount; ++ii) { + QmlDebugObjectReference obj; + decode(ds, obj, true); -void QQmlDebugFileReference::setLineNumber(int l) -{ - m_lineNumber = l; + obj.contextDebugId = c.debugId; + c.objects << obj; + } } -int QQmlDebugFileReference::columnNumber() const +void QQmlEngineDebugClient::messageReceived(const QByteArray &data) { - return m_columnNumber; -} + m_valid = false; + QDataStream ds(data); + int queryId; + QByteArray type; + ds >> type >> queryId; -void QQmlDebugFileReference::setColumnNumber(int c) -{ - m_columnNumber = c; -} + //qDebug() << "QQmlEngineDebugPrivate::message()" << type; -QQmlDebugPropertyReference::QQmlDebugPropertyReference() - : m_objectDebugId(-1), m_hasNotifySignal(false) -{ -} + if (type == "LIST_ENGINES_R") { + int count; + ds >> count; -QQmlDebugPropertyReference::QQmlDebugPropertyReference(const QQmlDebugPropertyReference &o) - : m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value), - m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding), - m_hasNotifySignal(o.m_hasNotifySignal) -{ -} + m_engines.clear(); + for (int ii = 0; ii < count; ++ii) { + QmlDebugEngineReference eng; + ds >> eng.name; + ds >> eng.debugId; + m_engines << eng; + } + } else if (type == "LIST_OBJECTS_R") { + if (!ds.atEnd()) + decode(ds, m_rootContext); -QQmlDebugPropertyReference &QQmlDebugPropertyReference::operator=(const QQmlDebugPropertyReference &o) -{ - m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value; - m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding; - m_hasNotifySignal = o.m_hasNotifySignal; - return *this; -} + } else if (type == "FETCH_OBJECT_R") { + if (!ds.atEnd()) + decode(ds, m_object, false); -int QQmlDebugPropertyReference::objectDebugId() const -{ - return m_objectDebugId; -} + } else if (type == "EVAL_EXPRESSION_R") {; + ds >> m_exprResult; -QString QQmlDebugPropertyReference::name() const -{ - return m_name; -} + } else if (type == "WATCH_PROPERTY_R") { + ds >> m_valid; -QString QQmlDebugPropertyReference::valueTypeName() const -{ - return m_valueTypeName; -} + } else if (type == "WATCH_OBJECT_R") { + ds >> m_valid; -QVariant QQmlDebugPropertyReference::value() const -{ - return m_value; -} + } else if (type == "WATCH_EXPR_OBJECT_R") { + ds >> m_valid; -QString QQmlDebugPropertyReference::binding() const -{ - return m_binding; -} + } else if (type == "UPDATE_WATCH") { + int debugId; + QByteArray name; + QVariant value; + ds >> debugId >> name >> value; + emit valueChanged(name, value); + return; -bool QQmlDebugPropertyReference::hasNotifySignal() const -{ - return m_hasNotifySignal; + } else if (type == "OBJECT_CREATED") { + emit newObjects(); + return; + } else if (type == "SET_BINDING_R") { + ds >> m_valid; + } else if (type == "RESET_BINDING_R") { + ds >> m_valid; + } else if (type == "SET_METHOD_BODY_R") { + ds >> m_valid; + } else if (type == "NO_WATCH_R") { + ds >> m_valid; + } + emit result(); } diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h index bf610af09d..62f9b15824 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h @@ -48,331 +48,190 @@ #include class QQmlDebugConnection; -class QQmlDebugWatch; -class QQmlDebugPropertyWatch; -class QQmlDebugObjectExpressionWatch; -class QQmlDebugEnginesQuery; -class QQmlDebugRootContextQuery; -class QQmlDebugObjectQuery; -class QQmlDebugExpressionQuery; -class QQmlDebugPropertyReference; -class QQmlDebugContextReference; -class QQmlDebugObjectReference; -class QQmlDebugFileReference; -class QQmlDebugEngineReference; -class QQmlEngineDebugClientPrivate; -class QQmlEngineDebugClient : public QQmlDebugClient -{ - Q_OBJECT -public: - explicit QQmlEngineDebugClient(QQmlDebugConnection *); - ~QQmlEngineDebugClient(); - - QQmlDebugPropertyWatch *addWatch(const QQmlDebugPropertyReference &, - QObject *parent = 0); - QQmlDebugWatch *addWatch(const QQmlDebugContextReference &, const QString &, - QObject *parent = 0); - QQmlDebugObjectExpressionWatch *addWatch(const QQmlDebugObjectReference &, const QString &, - QObject *parent = 0); - QQmlDebugWatch *addWatch(const QQmlDebugObjectReference &, - QObject *parent = 0); - QQmlDebugWatch *addWatch(const QQmlDebugFileReference &, - QObject *parent = 0); - - void removeWatch(QQmlDebugWatch *watch); - - QQmlDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); - QQmlDebugRootContextQuery *queryRootContexts(const QQmlDebugEngineReference &, - QObject *parent = 0); - QQmlDebugObjectQuery *queryObject(const QQmlDebugObjectReference &, - QObject *parent = 0); - QQmlDebugObjectQuery *queryObjectRecursive(const QQmlDebugObjectReference &, - QObject *parent = 0); - QQmlDebugExpressionQuery *queryExpressionResult(int objectDebugId, - const QString &expr, - QObject *parent = 0); - bool setBindingForObject(int objectDebugId, const QString &propertyName, - const QVariant &bindingExpression, bool isLiteralValue, - QString source = QString(), int line = -1); - bool resetBindingForObject(int objectDebugId, const QString &propertyName); - bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); - - QQmlEngineDebugClientPrivate *getPrivate() const { return d; } - -Q_SIGNALS: - void newObjects(); - void newState(State state); - -protected: - void stateChanged(State status); - void messageReceived(const QByteArray &data); - -private: - QQmlEngineDebugClientPrivate *d; -}; -class QQmlDebugWatch : public QObject +struct QmlDebugPropertyReference { - Q_OBJECT -public: - enum State { Waiting, Active, Inactive, Dead }; - - QQmlDebugWatch(QObject *); - ~QQmlDebugWatch(); - - int queryId() const; - int objectDebugId() const; - State state() const; - -Q_SIGNALS: - void stateChanged(QQmlDebugWatch::State); - //void objectChanged(int, const QQmlDebugObjectReference &); - //void valueChanged(int, const QVariant &); - - // Server sends value as string if it is a user-type variant - void valueChanged(const QByteArray &name, const QVariant &value); - -private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - void setState(State); - State m_state; - int m_queryId; - QQmlEngineDebugClient *m_client; - int m_objectDebugId; + QmlDebugPropertyReference() + : objectDebugId(-1), hasNotifySignal(false) + { + } + + QmlDebugPropertyReference &operator=( + const QmlDebugPropertyReference &o) + { + objectDebugId = o.objectDebugId; name = o.name; value = o.value; + valueTypeName = o.valueTypeName; binding = o.binding; + hasNotifySignal = o.hasNotifySignal; + return *this; + } + + int objectDebugId; + QString name; + QVariant value; + QString valueTypeName; + QString binding; + bool hasNotifySignal; }; -class QQmlDebugPropertyWatch : public QQmlDebugWatch +struct QmlDebugFileReference { - Q_OBJECT -public: - QQmlDebugPropertyWatch(QObject *parent); - - QString name() const; - -private: - friend class QQmlEngineDebugClient; - QString m_name; + QmlDebugFileReference() + : lineNumber(-1), columnNumber(-1) + { + } + + QmlDebugFileReference &operator=( + const QmlDebugFileReference &o) + { + url = o.url; lineNumber = o.lineNumber; columnNumber = o.columnNumber; + return *this; + } + + QUrl url; + int lineNumber; + int columnNumber; }; -class QQmlDebugObjectExpressionWatch : public QQmlDebugWatch +struct QmlDebugObjectReference { - Q_OBJECT -public: - QQmlDebugObjectExpressionWatch(QObject *parent); - - QString expression() const; - -private: - friend class QQmlEngineDebugClient; - QString m_expr; - int m_debugId; + QmlDebugObjectReference() + : debugId(-1), contextDebugId(-1) + { + } + + QmlDebugObjectReference(int id) + : debugId(id), contextDebugId(-1) + { + } + + QmlDebugObjectReference &operator=( + const QmlDebugObjectReference &o) + { + debugId = o.debugId; className = o.className; idString = o.idString; + name = o.name; source = o.source; contextDebugId = o.contextDebugId; + properties = o.properties; children = o.children; + return *this; + } + int debugId; + QString className; + QString idString; + QString name; + QmlDebugFileReference source; + int contextDebugId; + QList properties; + QList children; }; +Q_DECLARE_METATYPE(QmlDebugObjectReference) -class QQmlDebugQuery : public QObject +struct QmlDebugContextReference { - Q_OBJECT -public: - enum State { Waiting, Error, Completed }; - - State state() const; - bool isWaiting() const; - -Q_SIGNALS: - void stateChanged(QQmlDebugQuery::State); - -protected: - QQmlDebugQuery(QObject *); - -private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - void setState(State); - State m_state; + QmlDebugContextReference() + : debugId(-1) + { + } + + QmlDebugContextReference &operator=( + const QmlDebugContextReference &o) + { + debugId = o.debugId; name = o.name; objects = o.objects; + contexts = o.contexts; + return *this; + } + + int debugId; + QString name; + QList objects; + QList contexts; }; -class QQmlDebugFileReference +struct QmlDebugEngineReference { -public: - QQmlDebugFileReference(); - QQmlDebugFileReference(const QQmlDebugFileReference &); - QQmlDebugFileReference &operator=(const QQmlDebugFileReference &); - - QUrl url() const; - void setUrl(const QUrl &); - int lineNumber() const; - void setLineNumber(int); - int columnNumber() const; - void setColumnNumber(int); - -private: - friend class QQmlEngineDebugClientPrivate; - QUrl m_url; - int m_lineNumber; - int m_columnNumber; -}; - -class QQmlDebugEngineReference -{ -public: - QQmlDebugEngineReference(); - QQmlDebugEngineReference(int); - QQmlDebugEngineReference(const QQmlDebugEngineReference &); - QQmlDebugEngineReference &operator=(const QQmlDebugEngineReference &); - - int debugId() const; - QString name() const; - -private: - friend class QQmlEngineDebugClientPrivate; - int m_debugId; - QString m_name; + QmlDebugEngineReference() + : debugId(-1) + { + } + + QmlDebugEngineReference(int id) + : debugId(id) + { + } + + QmlDebugEngineReference &operator=( + const QmlDebugEngineReference &o) + { + debugId = o.debugId; name = o.name; + return *this; + } + + int debugId; + QString name; }; -class QQmlDebugObjectReference -{ -public: - QQmlDebugObjectReference(); - QQmlDebugObjectReference(int); - QQmlDebugObjectReference(const QQmlDebugObjectReference &); - QQmlDebugObjectReference &operator=(const QQmlDebugObjectReference &); - - int debugId() const; - QString className() const; - QString idString() const; - QString name() const; - - QQmlDebugFileReference source() const; - int contextDebugId() const; - - QList properties() const; - QList children() const; - -private: - friend class QQmlEngineDebugClientPrivate; - int m_debugId; - QString m_class; - QString m_idString; - QString m_name; - QQmlDebugFileReference m_source; - int m_contextDebugId; - QList m_properties; - QList m_children; -}; - -class QQmlDebugContextReference -{ -public: - QQmlDebugContextReference(); - QQmlDebugContextReference(const QQmlDebugContextReference &); - QQmlDebugContextReference &operator=(const QQmlDebugContextReference &); - - int debugId() const; - QString name() const; - - QList objects() const; - QList contexts() const; - -private: - friend class QQmlEngineDebugClientPrivate; - int m_debugId; - QString m_name; - QList m_objects; - QList m_contexts; -}; - -class QQmlDebugPropertyReference -{ -public: - QQmlDebugPropertyReference(); - QQmlDebugPropertyReference(const QQmlDebugPropertyReference &); - QQmlDebugPropertyReference &operator=(const QQmlDebugPropertyReference &); - - int objectDebugId() const; - QString name() const; - QVariant value() const; - QString valueTypeName() const; - QString binding() const; - bool hasNotifySignal() const; - -private: - friend class QQmlEngineDebugClientPrivate; - int m_objectDebugId; - QString m_name; - QVariant m_value; - QString m_valueTypeName; - QString m_binding; - bool m_hasNotifySignal; -}; - - -class QQmlDebugEnginesQuery : public QQmlDebugQuery -{ - Q_OBJECT -public: - virtual ~QQmlDebugEnginesQuery(); - QList engines() const; -private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - QQmlDebugEnginesQuery(QObject *); - QQmlEngineDebugClient *m_client; - int m_queryId; - QList m_engines; -}; - -class QQmlDebugRootContextQuery : public QQmlDebugQuery -{ - Q_OBJECT -public: - virtual ~QQmlDebugRootContextQuery(); - QQmlDebugContextReference rootContext() const; -private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - QQmlDebugRootContextQuery(QObject *); - QQmlEngineDebugClient *m_client; - int m_queryId; - QQmlDebugContextReference m_context; -}; - -class QQmlDebugObjectQuery : public QQmlDebugQuery +class QQmlEngineDebugClient : public QQmlDebugClient { Q_OBJECT public: - virtual ~QQmlDebugObjectQuery(); - QQmlDebugObjectReference object() const; -private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - QQmlDebugObjectQuery(QObject *); - QQmlEngineDebugClient *m_client; - int m_queryId; - QQmlDebugObjectReference m_object; + explicit QQmlEngineDebugClient(QQmlDebugConnection *conn); + + quint32 addWatch(const QmlDebugPropertyReference &, + bool *success); + quint32 addWatch(const QmlDebugContextReference &, const QString &, + bool *success); + quint32 addWatch(const QmlDebugObjectReference &, const QString &, + bool *success); + quint32 addWatch(const QmlDebugObjectReference &, + bool *success); + quint32 addWatch(const QmlDebugFileReference &, + bool *success); + + void removeWatch(quint32 watch, bool *success); + + quint32 queryAvailableEngines(bool *success); + quint32 queryRootContexts(const QmlDebugEngineReference &, + bool *success); + quint32 queryObject(const QmlDebugObjectReference &, + bool *success); + quint32 queryObjectRecursive(const QmlDebugObjectReference &, + bool *success); + quint32 queryExpressionResult(int objectDebugId, + const QString &expr, + bool *success); + quint32 setBindingForObject(int objectDebugId, const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QString source, int line, bool *success); + quint32 resetBindingForObject(int objectDebugId, + const QString &propertyName, bool *success); + quint32 setMethodBody(int objectDebugId, const QString &methodName, + const QString &methodBody, bool *success); + + quint32 getId() { return m_nextId++; } + + void decode(QDataStream &, QmlDebugContextReference &); + void decode(QDataStream &, QmlDebugObjectReference &, bool simple); + + QList engines() { return m_engines; } + QmlDebugContextReference rootContext() { return m_rootContext; } + QmlDebugObjectReference object() { return m_object; } + QVariant resultExpr() { return m_exprResult; } + bool valid() { return m_valid; } + +signals: + void newObjects(); + void valueChanged(QByteArray,QVariant); + void result(); -}; +protected: + void messageReceived(const QByteArray &); -class QQmlDebugExpressionQuery : public QQmlDebugQuery -{ - Q_OBJECT -public: - virtual ~QQmlDebugExpressionQuery(); - QVariant expression() const; - QVariant result() const; private: - friend class QQmlEngineDebugClient; - friend class QQmlEngineDebugClientPrivate; - QQmlDebugExpressionQuery(QObject *); - QQmlEngineDebugClient *m_client; - int m_queryId; - QVariant m_expr; - QVariant m_result; + quint32 m_nextId; + bool m_valid; + QList m_engines; + QmlDebugContextReference m_rootContext; + QmlDebugObjectReference m_object; + QVariant m_exprResult; }; -Q_DECLARE_METATYPE(QQmlDebugEngineReference) -Q_DECLARE_METATYPE(QQmlDebugObjectReference) -Q_DECLARE_METATYPE(QQmlDebugContextReference) -Q_DECLARE_METATYPE(QQmlDebugPropertyReference) - #endif // QQMLENGINEDEBUGCLIENT_H diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro index 20fcd6d04c..0212d11cd1 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro @@ -5,10 +5,12 @@ macx:CONFIG -= app_bundle HEADERS += \ qqmlenginedebugclient.h -SOURCES += tst_qqmlenginedebugservice.cpp \ +SOURCES += \ + tst_qqmlenginedebugservice.cpp \ qqmlenginedebugclient.cpp INCLUDEPATH += ../shared +include(../../../shared/util.pri) include(../shared/debugutil.pri) CONFIG += parallel_test declarative_debug diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index cbb7e0f203..e84e6623c1 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -61,22 +61,40 @@ #include "debugutil_p.h" #include "qqmlenginedebugclient.h" -Q_DECLARE_METATYPE(QQmlDebugWatch::State) +#include "../../../shared/util.h" + +#define QVERIFYOBJECT(statement) \ + do {\ + if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) {\ + return QmlDebugObjectReference();\ + }\ + } while (0) + +class NonScriptProperty : public QObject { + Q_OBJECT + Q_PROPERTY(int nonScriptProp READ nonScriptProp WRITE setNonScriptProp NOTIFY nonScriptPropChanged SCRIPTABLE false) +public: + int nonScriptProp() const { return 0; } + void setNonScriptProp(int) {} +signals: + void nonScriptPropChanged(); +}; +QML_DECLARE_TYPE(NonScriptProperty) class tst_QQmlEngineDebugService : public QObject { Q_OBJECT private: - QQmlDebugObjectReference findRootObject(int context = 0, bool recursive = false); - QQmlDebugPropertyReference findProperty(const QList &props, const QString &name) const; - void waitForQuery(QQmlDebugQuery *query); - - void recursiveObjectTest(QObject *o, const QQmlDebugObjectReference &oref, bool recursive) const; + QmlDebugObjectReference findRootObject(int context = 0, + bool recursive = false); + QmlDebugPropertyReference findProperty( + const QList &props, + const QString &name) const; - void recursiveCompareObjects(const QQmlDebugObjectReference &a, const QQmlDebugObjectReference &b) const; - void recursiveCompareContexts(const QQmlDebugContextReference &a, const QQmlDebugContextReference &b) const; - void compareProperties(const QQmlDebugPropertyReference &a, const QQmlDebugPropertyReference &b) const; + void recursiveObjectTest(QObject *o, + const QmlDebugObjectReference &oref, + bool recursive) const; QQmlDebugConnection *m_conn; QQmlEngineDebugClient *m_dbg; @@ -103,90 +121,62 @@ private slots: void queryExpressionResult(); void queryExpressionResult_data(); - void tst_QQmlDebugFileReference(); - void tst_QQmlDebugEngineReference(); - void tst_QQmlDebugObjectReference(); - void tst_QQmlDebugContextReference(); - void tst_QQmlDebugPropertyReference(); - void setBindingForObject(); void setMethodBody(); void queryObjectTree(); void setBindingInStates(); }; -class NonScriptProperty : public QObject { - Q_OBJECT - Q_PROPERTY(int nonScriptProp READ nonScriptProp WRITE setNonScriptProp NOTIFY nonScriptPropChanged SCRIPTABLE false) -public: - int nonScriptProp() const { return 0; } - void setNonScriptProp(int) {} -signals: - void nonScriptPropChanged(); -}; -QML_DECLARE_TYPE(NonScriptProperty) - - -QQmlDebugObjectReference tst_QQmlEngineDebugService::findRootObject(int context, bool recursive) -{ - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - if (q_engines->engines().count() == 0) - return QQmlDebugObjectReference(); - QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - if (q_context->rootContext().contexts().count() == 0 || - q_context->rootContext().contexts().last().objects().count() == 0) - return QQmlDebugObjectReference(); - - //Contexts are in a stack - int count = q_context->rootContext().contexts().count(); - QQmlDebugObjectQuery *q_obj = recursive ? - m_dbg->queryObjectRecursive(q_context->rootContext().contexts()[count - context - 1].objects()[0], this) : - m_dbg->queryObject(q_context->rootContext().contexts()[count - context - 1].objects()[0], this); - waitForQuery(q_obj); - - QQmlDebugObjectReference result = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - return result; +QmlDebugObjectReference tst_QQmlEngineDebugService::findRootObject( + int context, bool recursive) +{ + bool success = false; + m_dbg->queryAvailableEngines(&success); + QVERIFYOBJECT(success); + QVERIFYOBJECT(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + + QVERIFYOBJECT(m_dbg->engines().count()); + m_dbg->queryRootContexts(m_dbg->engines()[0].debugId, &success); + QVERIFYOBJECT(success); + QVERIFYOBJECT(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + + QVERIFYOBJECT(m_dbg->rootContext().contexts.count()); + QVERIFYOBJECT(m_dbg->rootContext().contexts.last().objects.count()); + int count = m_dbg->rootContext().contexts.count(); + recursive ? m_dbg->queryObjectRecursive(m_dbg->rootContext().contexts[count - context - 1].objects[0], + &success) : + m_dbg->queryObject(m_dbg->rootContext().contexts[count - context - 1].objects[0], &success); + QVERIFYOBJECT(success); + QVERIFYOBJECT(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + + return m_dbg->object(); } -QQmlDebugPropertyReference tst_QQmlEngineDebugService::findProperty(const QList &props, const QString &name) const +QmlDebugPropertyReference tst_QQmlEngineDebugService::findProperty( + const QList &props, const QString &name) const { - foreach(const QQmlDebugPropertyReference &p, props) { - if (p.name() == name) + foreach (const QmlDebugPropertyReference &p, props) { + if (p.name == name) return p; } - return QQmlDebugPropertyReference(); + return QmlDebugPropertyReference(); } -void tst_QQmlEngineDebugService::waitForQuery(QQmlDebugQuery *query) -{ - QVERIFY(query); - QCOMPARE(query->parent(), qobject_cast(this)); - QVERIFY(query->state() == QQmlDebugQuery::Waiting); - if (!QQmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QQmlDebugQuery::State)))) - QFAIL("query timed out"); -} - -void tst_QQmlEngineDebugService::recursiveObjectTest(QObject *o, const QQmlDebugObjectReference &oref, bool recursive) const +void tst_QQmlEngineDebugService::recursiveObjectTest( + QObject *o, const QmlDebugObjectReference &oref, bool recursive) const { const QMetaObject *meta = o->metaObject(); QQmlType *type = QQmlMetaType::qmlType(meta); - QString className = type ? QString(type->qmlTypeName()) : QString(meta->className()); + QString className = type ? QString(type->qmlTypeName()) + : QString(meta->className()); className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); - QCOMPARE(oref.debugId(), QQmlDebugService::idForObject(o)); - QCOMPARE(oref.name(), o->objectName()); - QCOMPARE(oref.className(), className); - QCOMPARE(oref.contextDebugId(), QQmlDebugService::idForObject(qmlContext(o))); + QCOMPARE(oref.debugId, QQmlDebugService::idForObject(o)); + QCOMPARE(oref.name, o->objectName()); + QCOMPARE(oref.className, className); + QCOMPARE(oref.contextDebugId, QQmlDebugService::idForObject( + qmlContext(o))); const QObjectList &children = o->children(); for (int i=0; i= 0); - QQmlDebugObjectReference cref; - foreach (const QQmlDebugObjectReference &ref, oref.children()) { - if (ref.debugId() == debugId) { + QmlDebugObjectReference cref; + foreach (const QmlDebugObjectReference &ref, oref.children) { + if (ref.debugId == debugId) { cref = ref; break; } } - QVERIFY(cref.debugId() >= 0); + QVERIFY(cref.debugId >= 0); if (recursive) recursiveObjectTest(child, cref, true); } - foreach (const QQmlDebugPropertyReference &p, oref.properties()) { - QCOMPARE(p.objectDebugId(), QQmlDebugService::idForObject(o)); + foreach (const QmlDebugPropertyReference &p, oref.properties) { + QCOMPARE(p.objectDebugId, QQmlDebugService::idForObject(o)); // signal properties are fake - they are generated from QQmlBoundSignal children - if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { - QList signalHandlers = o->findChildren(); - QString signal = p.value().toString(); + if (p.name.startsWith("on") && p.name.length() > 2 && p.name[2].isUpper()) { + QList signalHandlers = + o->findChildren(); + QString signal = p.value.toString(); bool found = false; for (int i = 0; i < signalHandlers.count(); ++i) if (signalHandlers.at(i)->expression()->expression() == signal) { @@ -223,86 +214,40 @@ void tst_QQmlEngineDebugService::recursiveObjectTest(QObject *o, const QQmlDebug break; } QVERIFY(found); - QVERIFY(p.valueTypeName().isEmpty()); - QVERIFY(p.binding().isEmpty()); - QVERIFY(!p.hasNotifySignal()); + QVERIFY(p.valueTypeName.isEmpty()); + QVERIFY(p.binding.isEmpty()); + QVERIFY(!p.hasNotifySignal); continue; } - QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); + QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name.toUtf8().constData())); - QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); + QCOMPARE(p.name, QString::fromUtf8(pmeta.name())); - if (pmeta.type() < QVariant::UserType && pmeta.userType() != QMetaType::QVariant) // TODO test complex types - QCOMPARE(p.value(), pmeta.read(o)); + if (pmeta.type() < QVariant::UserType && pmeta.userType() != + QMetaType::QVariant) // TODO test complex types + QCOMPARE(p.value , pmeta.read(o)); - if (p.name() == "parent") - QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QQuickItem*"); + if (p.name == "parent") + QVERIFY(p.valueTypeName == "QGraphicsObject*" || + p.valueTypeName == "QQuickItem*"); else - QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); + QCOMPARE(p.valueTypeName, QString::fromUtf8(pmeta.typeName())); - QQmlAbstractBinding *binding = - QQmlPropertyPrivate::binding(QQmlProperty(o, p.name())); + QQmlAbstractBinding *binding = + QQmlPropertyPrivate::binding( + QQmlProperty(o, p.name)); if (binding) - QCOMPARE(binding->expression(), p.binding()); + QCOMPARE(binding->expression(), p.binding); - QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + QCOMPARE(p.hasNotifySignal, pmeta.hasNotifySignal()); QVERIFY(pmeta.isValid()); } } -void tst_QQmlEngineDebugService::recursiveCompareObjects(const QQmlDebugObjectReference &a, const QQmlDebugObjectReference &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(); qmlRegisterType("Test", 1, 0, "NonScriptPropertyElement"); QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Waiting for connection on port 3768..."); @@ -407,7 +352,8 @@ void tst_QQmlEngineDebugService::cleanupTestCase() void tst_QQmlEngineDebugService::setMethodBody() { - QQmlDebugObjectReference obj = findRootObject(2); + bool success; + QmlDebugObjectReference obj = findRootObject(2); QObject *root = m_components.at(2); // Without args @@ -418,8 +364,10 @@ void tst_QQmlEngineDebugService::setMethodBody() QVERIFY(rv == QVariant(qreal(3))); - QVERIFY(m_dbg->setMethodBody(obj.debugId(), "myMethodNoArgs", "return 7")); - QTest::qWait(100); + QVERIFY(m_dbg->setMethodBody(obj.debugId, "myMethodNoArgs", "return 7", + &success)); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); QVERIFY(QMetaObject::invokeMethod(root, "myMethodNoArgs", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv))); @@ -433,8 +381,10 @@ void tst_QQmlEngineDebugService::setMethodBody() Q_RETURN_ARG(QVariant, rv), Q_ARG(QVariant, QVariant(19)))); QVERIFY(rv == QVariant(qreal(28))); - QVERIFY(m_dbg->setMethodBody(obj.debugId(), "myMethod", "return a + 7")); - QTest::qWait(100); + QVERIFY(m_dbg->setMethodBody(obj.debugId, "myMethod", "return a + 7", + &success)); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); QVERIFY(QMetaObject::invokeMethod(root, "myMethod", Qt::DirectConnection, Q_RETURN_ARG(QVariant, rv), Q_ARG(QVariant, QVariant(19)))); @@ -444,96 +394,78 @@ void tst_QQmlEngineDebugService::setMethodBody() void tst_QQmlEngineDebugService::watch_property() { - QQmlDebugObjectReference obj = findRootObject(); - QQmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); + QmlDebugObjectReference obj = findRootObject(); + QmlDebugPropertyReference prop = findProperty(obj.properties, "width"); - QQmlDebugPropertyWatch *watch; + bool success; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - watch = unconnected->addWatch(prop, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Dead); - delete watch; + unconnected->addWatch(prop, &success); + QVERIFY(!success); delete unconnected; - watch = m_dbg->addWatch(QQmlDebugPropertyReference(), this); - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(watch->state(), QQmlDebugWatch::Inactive); - delete watch; + m_dbg->addWatch(QmlDebugPropertyReference(), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), false); - watch = m_dbg->addWatch(prop, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->name(), prop.name()); + quint32 id = m_dbg->addWatch(prop, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + QSignalSpy spy(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant))); int origWidth = m_rootItem->property("width").toInt(); m_rootItem->setProperty("width", origWidth*2); - // stateChanged() is received before valueChanged() - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(watch->state(), QQmlDebugWatch::Active); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); QCOMPARE(spy.count(), 1); - m_dbg->removeWatch(watch); - delete watch; + m_dbg->removeWatch(id, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); // 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(0).value(), prop.name.toUtf8()); QCOMPARE(spy.at(0).at(1).value(), qVariantFromValue(origWidth*2)); } void tst_QQmlEngineDebugService::watch_object() { - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QVERIFY(q_engines->engines().count() > 0); - QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - QVERIFY(q_context->rootContext().contexts().count()); - QVERIFY(q_context->rootContext().contexts().last().objects().count() > 0); - QQmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().contexts().last().objects()[0], this); - waitForQuery(q_obj); + QmlDebugObjectReference obj = findRootObject(); - QQmlDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - QQmlDebugWatch *watch; + bool success; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - watch = unconnected->addWatch(obj, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Dead); - delete watch; + unconnected->addWatch(obj, &success); + QVERIFY(!success); delete unconnected; - watch = m_dbg->addWatch(QQmlDebugObjectReference(), this); - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(watch->state(), QQmlDebugWatch::Inactive); - delete watch; + m_dbg->addWatch(QmlDebugObjectReference(), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), false); - watch = m_dbg->addWatch(obj, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); + quint32 id = m_dbg->addWatch(obj, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + QSignalSpy spy(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant))); int origWidth = m_rootItem->property("width").toInt(); int origHeight = m_rootItem->property("height").toInt(); m_rootItem->setProperty("width", origWidth*2); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); m_rootItem->setProperty("height", origHeight*2); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); - // stateChanged() is received before any valueChanged() signals - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(watch->state(), QQmlDebugWatch::Active); QVERIFY(spy.count() > 0); int newWidth = -1; @@ -547,8 +479,10 @@ void tst_QQmlEngineDebugService::watch_object() } - m_dbg->removeWatch(watch); - delete watch; + m_dbg->removeWatch(id, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); // since watch has been removed, restoring the original values should not trigger a valueChanged() spy.clear(); @@ -569,58 +503,50 @@ void tst_QQmlEngineDebugService::watch_expression() int origWidth = m_rootItem->property("width").toInt(); - QQmlDebugObjectReference obj = findRootObject(); + QmlDebugObjectReference obj = findRootObject(); - QQmlDebugObjectExpressionWatch *watch; + bool success; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - watch = unconnected->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Dead); - delete watch; + unconnected->addWatch(obj, expr, &success); + QVERIFY(!success); delete unconnected; - watch = m_dbg->addWatch(QQmlDebugObjectReference(), expr, this); - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(watch->state(), QQmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QQmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->expression(), expr); + m_dbg->addWatch(QmlDebugObjectReference(), expr, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), false); - QSignalSpy spyState(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))); + quint32 id = m_dbg->addWatch(obj, expr, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value + QSignalSpy spy(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant))); int width = origWidth; for (int i=0; i 0) { width += increment; m_rootItem->setProperty("width", width); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); } - if (!QQmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) - QFAIL("Did not receive valueChanged() for expression"); } - if (spyState.count() == 0) - QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)))); - QCOMPARE(spyState.count(), 1); - QCOMPARE(watch->state(), QQmlDebugWatch::Active); - - m_dbg->removeWatch(watch); - delete watch; + m_dbg->removeWatch(id, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); // 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); + QCOMPARE(spy.count(), incrementCount); width = origWidth + increment; for (int i=0; i().toInt(), width); width += increment; + QCOMPARE(spy.at(i).at(1).value().toInt(), width); } } @@ -636,165 +562,126 @@ void tst_QQmlEngineDebugService::watch_expression_data() void tst_QQmlEngineDebugService::watch_context() { - QQmlDebugContextReference c; - QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(c, QString(), this)); + QmlDebugContextReference c; + QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebugClient::addWatch(): Not implemented"); + bool success; + m_dbg->addWatch(c, QString(), &success); + QVERIFY(!success); } void tst_QQmlEngineDebugService::watch_file() { - QQmlDebugFileReference f; - QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(f, this)); + QmlDebugFileReference f; + QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebugClient::addWatch(): Not implemented"); + bool success; + m_dbg->addWatch(f, &success); + QVERIFY(!success); } void tst_QQmlEngineDebugService::queryAvailableEngines() { - QQmlDebugEnginesQuery *q_engines; + bool success; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - q_engines = unconnected->queryAvailableEngines(0); - QCOMPARE(q_engines->state(), QQmlDebugQuery::Error); - delete q_engines; + unconnected->queryAvailableEngines(&success); + QVERIFY(!success); delete unconnected; - q_engines = m_dbg->queryAvailableEngines(this); - delete q_engines; - - q_engines = m_dbg->queryAvailableEngines(this); - QVERIFY(q_engines->engines().isEmpty()); - waitForQuery(q_engines); + m_dbg->queryAvailableEngines(&success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); // TODO test multiple engines - QList engines = q_engines->engines(); + QList engines = m_dbg->engines(); QCOMPARE(engines.count(), 1); - foreach(const QQmlDebugEngineReference &e, engines) { - QCOMPARE(e.debugId(), QQmlDebugService::idForObject(m_engine)); - QCOMPARE(e.name(), m_engine->objectName()); + foreach (const QmlDebugEngineReference &e, engines) { + QCOMPARE(e.debugId, QQmlDebugService::idForObject(m_engine)); + QCOMPARE(e.name, m_engine->objectName()); } - - // Make query invalid by deleting client - q_engines = m_dbg->queryAvailableEngines(this); - QCOMPARE(q_engines->state(), QQmlDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_engines->state(), QQmlDebugQuery::Error); - delete q_engines; - m_dbg = new QQmlEngineDebugClient(m_conn); } void tst_QQmlEngineDebugService::queryRootContexts() { - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - int engineId = q_engines->engines()[0].debugId(); - delete q_engines; - - QQmlDebugRootContextQuery *q_context; + bool success; + m_dbg->queryAvailableEngines(&success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QVERIFY(m_dbg->engines().count()); + int engineId = m_dbg->engines()[0].debugId; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - q_context = unconnected->queryRootContexts(engineId, this); - QCOMPARE(q_context->state(), QQmlDebugQuery::Error); - delete q_context; + unconnected->queryRootContexts(engineId, &success); + QVERIFY(!success); delete unconnected; - q_context = m_dbg->queryRootContexts(engineId, this); - delete q_context; - - q_context = m_dbg->queryRootContexts(engineId, this); - waitForQuery(q_context); + m_dbg->queryRootContexts(engineId, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); QQmlContext *actualContext = m_engine->rootContext(); - QQmlDebugContextReference context = q_context->rootContext(); - QCOMPARE(context.debugId(), QQmlDebugService::idForObject(actualContext)); - QCOMPARE(context.name(), actualContext->objectName()); + QmlDebugContextReference context = m_dbg->rootContext(); + QCOMPARE(context.debugId, QQmlDebugService::idForObject(actualContext)); + QCOMPARE(context.name, actualContext->objectName()); // root context query sends only root object data - it doesn't fill in // the children or property info - QCOMPARE(context.objects().count(), 0); - - QCOMPARE(context.contexts().count(), 5); - QVERIFY(context.contexts()[0].debugId() >= 0); - QCOMPARE(context.contexts()[0].name(), QString("tst_QQmlDebug_childContext")); - - // Make query invalid by deleting client - q_context = m_dbg->queryRootContexts(engineId, this); - QCOMPARE(q_context->state(), QQmlDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_context->state(), QQmlDebugQuery::Error); - delete q_context; - m_dbg = new QQmlEngineDebugClient(m_conn); + QCOMPARE(context.objects.count(), 0); + QCOMPARE(context.contexts.count(), 5); + QVERIFY(context.contexts[0].debugId >= 0); + QCOMPARE(context.contexts[0].name, QString("tst_QQmlDebug_childContext")); } void tst_QQmlEngineDebugService::queryObject() { QFETCH(bool, recursive); - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - QQmlDebugObjectReference rootObject = q_context->rootContext().contexts().last().objects()[0]; + bool success; - QQmlDebugObjectQuery *q_obj = 0; + QmlDebugObjectReference rootObject = findRootObject(); QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - q_obj = recursive ? unconnected->queryObjectRecursive(rootObject, this) : unconnected->queryObject(rootObject, this); - QCOMPARE(q_obj->state(), QQmlDebugQuery::Error); - delete q_obj; + recursive ? unconnected->queryObjectRecursive(rootObject, &success) : unconnected->queryObject(rootObject, &success); + QVERIFY(!success); delete unconnected; - q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); - delete q_obj; + recursive ? m_dbg->queryObjectRecursive(rootObject, &success) : m_dbg->queryObject(rootObject, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); - waitForQuery(q_obj); - - QQmlDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - - // Make query invalid by deleting client - q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); - QCOMPARE(q_obj->state(), QQmlDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_obj->state(), QQmlDebugQuery::Error); - delete q_obj; - m_dbg = new QQmlEngineDebugClient(m_conn); + QmlDebugObjectReference obj = m_dbg->object(); // check source as defined in main() - QQmlDebugFileReference source = obj.source(); - QCOMPARE(source.url(), QUrl::fromLocalFile("")); - QCOMPARE(source.lineNumber(), 3); - QCOMPARE(source.columnNumber(), 1); + QmlDebugFileReference source = obj.source; + QCOMPARE(source.url, QUrl::fromLocalFile("")); + QCOMPARE(source.lineNumber, 3); + QCOMPARE(source.columnNumber, 1); // generically test all properties, children and childrens' properties recursiveObjectTest(m_rootItem, obj, recursive); if (recursive) { - foreach(const QQmlDebugObjectReference &child, obj.children()) - QVERIFY(child.properties().count() > 0); + foreach (const QmlDebugObjectReference &child, obj.children) + QVERIFY(child.properties.count() > 0); - QQmlDebugObjectReference rect; - QQmlDebugObjectReference text; - foreach (const QQmlDebugObjectReference &child, obj.children()) { - if (child.className() == "Rectangle") + QmlDebugObjectReference rect; + QmlDebugObjectReference text; + foreach (const QmlDebugObjectReference &child, obj.children) { + if (child.className == "Rectangle") rect = child; - else if (child.className() == "Text") + 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(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"))); + QCOMPARE(findProperty(text.properties, "color").value, qVariantFromValue(QColor("blue"))); } else { - foreach(const QQmlDebugObjectReference &child, obj.children()) - QCOMPARE(child.properties().count(), 0); + foreach (const QmlDebugObjectReference &child, obj.children) + QCOMPARE(child.properties.count(), 0); } } @@ -811,40 +698,20 @@ void tst_QQmlEngineDebugService::queryExpressionResult() QFETCH(QString, expr); QFETCH(QVariant, result); - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); // check immediate deletion is ok - - QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - int objectId = q_context->rootContext().contexts().last().objects()[0].debugId(); + int objectId = findRootObject().debugId; - QQmlDebugExpressionQuery *q_expr; + bool success; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0); - q_expr = unconnected->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->state(), QQmlDebugQuery::Error); - delete q_expr; + unconnected->queryExpressionResult(objectId, expr, &success); + QVERIFY(!success); delete unconnected; - q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - delete q_expr; - - q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->expression().toString(), expr); - waitForQuery(q_expr); + m_dbg->queryExpressionResult(objectId, expr, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QCOMPARE(q_expr->result(), result); - - delete q_engines; - delete q_context; - - // Make query invalid by deleting client - q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->state(), QQmlDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_expr->state(), QQmlDebugQuery::Error); - delete q_expr; - m_dbg = new QQmlEngineDebugClient(m_conn); + QCOMPARE(m_dbg->resultExpr(), result); } void tst_QQmlEngineDebugService::queryExpressionResult_data() @@ -862,204 +729,94 @@ void tst_QQmlEngineDebugService::queryExpressionResult_data() QTest::newRow("varObjMap") << "varObjMap" << qVariantFromValue(map); } -void tst_QQmlEngineDebugService::tst_QQmlDebugFileReference() -{ - QQmlDebugFileReference 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); - - QQmlDebugFileReference copy(ref); - QQmlDebugFileReference copyAssign; - copyAssign = ref; - foreach (const QQmlDebugFileReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.url(), ref.url()); - QCOMPARE(r.lineNumber(), ref.lineNumber()); - QCOMPARE(r.columnNumber(), ref.columnNumber()); - } -} - -void tst_QQmlEngineDebugService::tst_QQmlDebugEngineReference() -{ - QQmlDebugEngineReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - - ref = QQmlDebugEngineReference(1); - QCOMPARE(ref.debugId(), 1); - QVERIFY(ref.name().isEmpty()); - - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - ref = q_engines->engines()[0]; - delete q_engines; - - QQmlDebugEngineReference copy(ref); - QQmlDebugEngineReference copyAssign; - copyAssign = ref; - foreach (const QQmlDebugEngineReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.debugId(), ref.debugId()); - QCOMPARE(r.name(), ref.name()); - } -} - -void tst_QQmlEngineDebugService::tst_QQmlDebugObjectReference() -{ - QQmlDebugObjectReference 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()); - - QQmlDebugFileReference source = ref.source(); - QVERIFY(source.url().isEmpty()); - QVERIFY(source.lineNumber() < 0); - QVERIFY(source.columnNumber() < 0); - - ref = QQmlDebugObjectReference(1); - QCOMPARE(ref.debugId(), 1); - - QQmlDebugObjectReference rootObject = findRootObject(); - QQmlDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); - waitForQuery(query); - ref = query->object(); - delete query; - - QVERIFY(ref.debugId() >= 0); - - QQmlDebugObjectReference copy(ref); - QQmlDebugObjectReference copyAssign; - copyAssign = ref; - foreach (const QQmlDebugObjectReference &r, (QList() << copy << copyAssign)) - recursiveCompareObjects(r, ref); -} - -void tst_QQmlEngineDebugService::tst_QQmlDebugContextReference() -{ - QQmlDebugContextReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - QVERIFY(ref.objects().isEmpty()); - QVERIFY(ref.contexts().isEmpty()); - - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - QQmlDebugRootContextQuery *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); - - QQmlDebugContextReference copy(ref); - QQmlDebugContextReference copyAssign; - copyAssign = ref; - foreach (const QQmlDebugContextReference &r, (QList() << copy << copyAssign)) - recursiveCompareContexts(r, ref); -} - -void tst_QQmlEngineDebugService::tst_QQmlDebugPropertyReference() -{ - QQmlDebugObjectReference rootObject = findRootObject(); - QQmlDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); - waitForQuery(query); - QQmlDebugObjectReference obj = query->object(); - delete query; - - QQmlDebugPropertyReference 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()); - - QQmlDebugPropertyReference copy(ref); - QQmlDebugPropertyReference copyAssign; - copyAssign = ref; - foreach (const QQmlDebugPropertyReference &r, (QList() << copy << copyAssign)) - compareProperties(r, ref); -} - void tst_QQmlEngineDebugService::setBindingForObject() { - QQmlDebugObjectReference rootObject = findRootObject(); - QVERIFY(rootObject.debugId() != -1); - QQmlDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties(), "width"); + QmlDebugObjectReference rootObject = findRootObject(); + QVERIFY(rootObject.debugId != -1); + QmlDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties, "width"); - QCOMPARE(widthPropertyRef.value(), QVariant(10)); - QCOMPARE(widthPropertyRef.binding(), QString()); + QCOMPARE(widthPropertyRef.value, QVariant(10)); + QCOMPARE(widthPropertyRef.binding, QString()); + bool success; // // set literal // - m_dbg->setBindingForObject(rootObject.debugId(), "width", "15", true); + m_dbg->setBindingForObject(rootObject.debugId, "width", "15", true, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); rootObject = findRootObject(); - widthPropertyRef = findProperty(rootObject.properties(), "width"); + widthPropertyRef = findProperty(rootObject.properties, "width"); - QCOMPARE(widthPropertyRef.value(), QVariant(15)); - QCOMPARE(widthPropertyRef.binding(), QString()); + QCOMPARE(widthPropertyRef.value, QVariant(15)); + QCOMPARE(widthPropertyRef.binding, QString()); // // set expression // - m_dbg->setBindingForObject(rootObject.debugId(), "width", "height", false); + m_dbg->setBindingForObject(rootObject.debugId, "width", "height", false, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); rootObject = findRootObject(); - widthPropertyRef = findProperty(rootObject.properties(), "width"); + widthPropertyRef = findProperty(rootObject.properties, "width"); - QCOMPARE(widthPropertyRef.value(), QVariant(20)); - QCOMPARE(widthPropertyRef.binding(), QString("height")); + QCOMPARE(widthPropertyRef.value, QVariant(20)); + QCOMPARE(widthPropertyRef.binding, QString("height")); // // reset // - m_dbg->resetBindingForObject(rootObject.debugId(), "width"); + m_dbg->resetBindingForObject(rootObject.debugId, "width", &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); rootObject = findRootObject(); - widthPropertyRef = findProperty(rootObject.properties(), "width"); + widthPropertyRef = findProperty(rootObject.properties, "width"); // QCOMPARE(widthPropertyRef.value(), QVariant(0)); // TODO: Shouldn't this work? - QCOMPARE(widthPropertyRef.binding(), QString()); + QCOMPARE(widthPropertyRef.binding, QString()); // // set handler // rootObject = findRootObject(); - QCOMPARE(rootObject.children().size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement - QQmlDebugObjectReference mouseAreaObject = rootObject.children().at(2); - QQmlDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); - waitForQuery(q_obj); - mouseAreaObject = q_obj->object(); + QCOMPARE(rootObject.children.size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement + QmlDebugObjectReference mouseAreaObject = rootObject.children.at(2); + m_dbg->queryObjectRecursive(mouseAreaObject, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + mouseAreaObject = m_dbg->object(); - QCOMPARE(mouseAreaObject.className(), QString("MouseArea")); + QCOMPARE(mouseAreaObject.className, QString("MouseArea")); - QQmlDebugPropertyReference onEnteredRef = findProperty(mouseAreaObject.properties(), "onEntered"); + QmlDebugPropertyReference onEnteredRef = findProperty(mouseAreaObject.properties, "onEntered"); - QCOMPARE(onEnteredRef.name(), QString("onEntered")); - QCOMPARE(onEnteredRef.value(), QVariant("(function onEntered() { { console.log('hello') } })")); + QCOMPARE(onEnteredRef.name, QString("onEntered")); + QCOMPARE(onEnteredRef.value, QVariant("(function onEntered() { { console.log('hello') } })")); - m_dbg->setBindingForObject(mouseAreaObject.debugId(), "onEntered", "{console.log('hello, world') }", false) ; + m_dbg->setBindingForObject(mouseAreaObject.debugId, "onEntered", + "{console.log('hello, world') }", false, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); rootObject = findRootObject(); - mouseAreaObject = rootObject.children().at(2); - q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); - waitForQuery(q_obj); - mouseAreaObject = q_obj->object(); - onEnteredRef = findProperty(mouseAreaObject.properties(), "onEntered"); - QCOMPARE(onEnteredRef.name(), QString("onEntered")); - QCOMPARE(onEnteredRef.value(), QVariant("{console.log('hello, world') }")); + mouseAreaObject = rootObject.children.at(2); + m_dbg->queryObjectRecursive(mouseAreaObject, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + mouseAreaObject = m_dbg->object(); + onEnteredRef = findProperty(mouseAreaObject.properties, "onEntered"); + QCOMPARE(onEnteredRef.name, QString("onEntered")); + QCOMPARE(onEnteredRef.value, QVariant("{console.log('hello, world') }")); } void tst_QQmlEngineDebugService::setBindingInStates() @@ -1068,155 +825,151 @@ void tst_QQmlEngineDebugService::setBindingInStates() const int sourceIndex = 3; - QQmlDebugObjectReference obj = findRootObject(sourceIndex); - - QVERIFY(obj.debugId() != -1); - QVERIFY(obj.children().count() >= 2); + QmlDebugObjectReference obj = findRootObject(sourceIndex); + QVERIFY(obj.debugId != -1); + QVERIFY(obj.children.count() >= 2); + bool success; // We are going to switch state a couple of times, we need to get rid of the transition before - QQmlDebugExpressionQuery *q_deleteTransition = m_dbg->queryExpressionResult(obj.debugId(),QString("transitions = []"),this); - waitForQuery(q_deleteTransition); - delete q_deleteTransition; + m_dbg->queryExpressionResult(obj.debugId,QString("transitions = []"), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); // check initial value of the property that is changing - QQmlDebugExpressionQuery *q_setState; - q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this); - waitForQuery(q_setState); - delete q_setState; + m_dbg->queryExpressionResult(obj.debugId,QString("state=\"state1\""), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),200); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(),200); - q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this); - waitForQuery(q_setState); - delete q_setState; + m_dbg->queryExpressionResult(obj.debugId,QString("state=\"\""), + &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex, true); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),100); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(),100); // change the binding - QQmlDebugObjectReference state = obj.children()[1]; - QCOMPARE(state.className(), QString("State")); - QVERIFY(state.children().count() > 0); + QmlDebugObjectReference state = obj.children[1]; + QCOMPARE(state.className, QString("State")); + QVERIFY(state.children.count() > 0); - QQmlDebugObjectReference propertyChange = state.children()[0]; - QVERIFY(propertyChange.debugId() != -1); + QmlDebugObjectReference propertyChange = state.children[0]; + QVERIFY(propertyChange.debugId != -1); - QVERIFY( m_dbg->setBindingForObject(propertyChange.debugId(), "width",QVariant(300),true) ); + m_dbg->setBindingForObject(propertyChange.debugId, "width",QVariant(300),true, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); // check properties changed in state obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),100); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(),100); - q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this); - waitForQuery(q_setState); - delete q_setState; + m_dbg->queryExpressionResult(obj.debugId,QString("state=\"state1\""), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),300); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(),300); // check changing properties of base state from within a state - QVERIFY(m_dbg->setBindingForObject(obj.debugId(),"width","height*2",false)); - QVERIFY(m_dbg->setBindingForObject(obj.debugId(),"height","200",true)); + m_dbg->setBindingForObject(obj.debugId,"width","height*2",false, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + m_dbg->setBindingForObject(obj.debugId,"height","200",true, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),300); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(),300); - q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this); - waitForQuery(q_setState); - delete q_setState; + m_dbg->queryExpressionResult(obj.debugId,QString("state=\"\""), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 400); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(), 400); // reset binding while in a state - q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this); - waitForQuery(q_setState); - delete q_setState; + m_dbg->queryExpressionResult(obj.debugId,QString("state=\"state1\""), &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(), 300); - m_dbg->resetBindingForObject(propertyChange.debugId(), "width"); + m_dbg->resetBindingForObject(propertyChange.debugId, "width", &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 400); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(), 400); // re-add binding - m_dbg->setBindingForObject(propertyChange.debugId(), "width", "300", true); + m_dbg->setBindingForObject(propertyChange.debugId, "width", "300", true, + QString(), -1, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QCOMPARE(m_dbg->valid(), true); obj = findRootObject(sourceIndex); - QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300); + QCOMPARE(findProperty(obj.properties,"width").value.toInt(), 300); } void tst_QQmlEngineDebugService::queryObjectTree() { const int sourceIndex = 3; - // Check if states/transitions are initialized when fetching root item - QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - QVERIFY(q_context->rootContext().contexts().count() >= sourceIndex); - int count = q_context->rootContext().contexts().count(); - QQmlDebugObjectReference rootObject = q_context->rootContext().contexts()[count - sourceIndex - 1].objects()[0]; - - QQmlDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this); - waitForQuery(q_obj); - - QQmlDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - QVERIFY(obj.debugId() != -1); - QVERIFY(obj.children().count() >= 2); - + QmlDebugObjectReference obj = findRootObject(sourceIndex, true); + QVERIFY(obj.debugId != -1); + QVERIFY(obj.children.count() >= 2); // check state - QQmlDebugObjectReference state = obj.children()[1]; - QCOMPARE(state.className(), QString("State")); - QVERIFY(state.children().count() > 0); + QmlDebugObjectReference state = obj.children[1]; + QCOMPARE(state.className, QString("State")); + QVERIFY(state.children.count() > 0); - QQmlDebugObjectReference propertyChange = state.children()[0]; - QVERIFY(propertyChange.debugId() != -1); + QmlDebugObjectReference propertyChange = state.children[0]; + QVERIFY(propertyChange.debugId != -1); - QQmlDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties(),"target"); - QCOMPARE(propertyChangeTarget.objectDebugId(), propertyChange.debugId()); + QmlDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties,"target"); + QCOMPARE(propertyChangeTarget.objectDebugId, propertyChange.debugId); - QQmlDebugObjectReference targetReference = qvariant_cast(propertyChangeTarget.value()); - QVERIFY(targetReference.debugId() != -1); + QmlDebugObjectReference targetReference = qvariant_cast(propertyChangeTarget.value); + QVERIFY(targetReference.debugId != -1); // check transition - QQmlDebugObjectReference transition = obj.children()[0]; - QCOMPARE(transition.className(), QString("Transition")); - QCOMPARE(findProperty(transition.properties(),"from").value().toString(), QString("*")); - QCOMPARE(findProperty(transition.properties(),"to").value(), findProperty(state.properties(),"name").value()); - QVERIFY(transition.children().count() > 0); + QmlDebugObjectReference transition = obj.children[0]; + QCOMPARE(transition.className, QString("Transition")); + QCOMPARE(findProperty(transition.properties,"from").value.toString(), QString("*")); + QCOMPARE(findProperty(transition.properties,"to").value, findProperty(state.properties,"name").value); + QVERIFY(transition.children.count() > 0); - QQmlDebugObjectReference animation = transition.children()[0]; - QVERIFY(animation.debugId() != -1); + QmlDebugObjectReference animation = transition.children[0]; + QVERIFY(animation.debugId != -1); - QQmlDebugPropertyReference animationTarget = findProperty(animation.properties(),"target"); - QCOMPARE(animationTarget.objectDebugId(), animation.debugId()); + QmlDebugPropertyReference animationTarget = findProperty(animation.properties,"target"); + QCOMPARE(animationTarget.objectDebugId, animation.debugId); - targetReference = qvariant_cast(animationTarget.value()); - QVERIFY(targetReference.debugId() != -1); + targetReference = qvariant_cast(animationTarget.value); + QVERIFY(targetReference.debugId != -1); - QCOMPARE(findProperty(animation.properties(),"property").value().toString(), QString("width")); - QCOMPARE(findProperty(animation.properties(),"duration").value().toInt(), 100); + QCOMPARE(findProperty(animation.properties,"property").value.toString(), QString("width")); + QCOMPARE(findProperty(animation.properties,"duration").value.toInt(), 100); } int main(int argc, char *argv[])