2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#include <qtest.h>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QThread>
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqmlengine.h>
|
|
|
|
#include <QtQml/qqmlcontext.h>
|
|
|
|
#include <QtQml/qqmlcomponent.h>
|
|
|
|
#include <QtQml/qqmlexpression.h>
|
|
|
|
#include <QtQml/qqmlproperty.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/qquickitem.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <private/qqmlbinding_p.h>
|
|
|
|
#include <private/qqmlboundsignal_p.h>
|
|
|
|
#include <private/qqmldebugservice_p.h>
|
|
|
|
#include <private/qqmlmetatype_p.h>
|
|
|
|
#include <private/qqmlproperty_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
#include "debugutil_p.h"
|
2012-03-13 16:16:16 +00:00
|
|
|
#include "qqmlenginedebugclient.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_DECLARE_METATYPE(QQmlDebugWatch::State)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
class tst_QQmlEngineDebugService : public QObject
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference findRootObject(int context = 0, bool recursive = false);
|
|
|
|
QQmlDebugPropertyReference findProperty(const QList<QQmlDebugPropertyReference> &props, const QString &name) const;
|
|
|
|
void waitForQuery(QQmlDebugQuery *query);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void recursiveObjectTest(QObject *o, const QQmlDebugObjectReference &oref, bool recursive) const;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
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;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection *m_conn;
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *m_dbg;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine *m_engine;
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *m_rootItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QObjectList m_components;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
void watch_property();
|
|
|
|
void watch_object();
|
|
|
|
void watch_expression();
|
|
|
|
void watch_expression_data();
|
|
|
|
void watch_context();
|
|
|
|
void watch_file();
|
|
|
|
|
|
|
|
void queryAvailableEngines();
|
|
|
|
void queryRootContexts();
|
|
|
|
void queryObject();
|
|
|
|
void queryObject_data();
|
|
|
|
void queryExpressionResult();
|
|
|
|
void queryExpressionResult_data();
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugFileReference();
|
|
|
|
void tst_QQmlDebugEngineReference();
|
|
|
|
void tst_QQmlDebugObjectReference();
|
|
|
|
void tst_QQmlDebugContextReference();
|
|
|
|
void tst_QQmlDebugPropertyReference();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
QQmlDebugObjectReference tst_QQmlEngineDebugService::findRootObject(int context, bool recursive)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (q_engines->engines().count() == 0)
|
2012-02-16 04:43:03 +00:00
|
|
|
return QQmlDebugObjectReference();
|
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
|
|
|
|
2012-03-12 13:08:56 +00:00
|
|
|
if (q_context->rootContext().contexts().count() == 0 ||
|
|
|
|
q_context->rootContext().contexts().last().objects().count() == 0)
|
2012-02-16 04:43:03 +00:00
|
|
|
return QQmlDebugObjectReference();
|
2012-03-12 13:08:56 +00:00
|
|
|
|
|
|
|
//Contexts are in a stack
|
|
|
|
int count = q_context->rootContext().contexts().count();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectQuery *q_obj = recursive ?
|
2012-03-12 13:08:56 +00:00
|
|
|
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);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_obj);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference result = q_obj->object();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
|
|
|
delete q_obj;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
QQmlDebugPropertyReference tst_QQmlEngineDebugService::findProperty(const QList<QQmlDebugPropertyReference> &props, const QString &name) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach(const QQmlDebugPropertyReference &p, props) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (p.name() == name)
|
|
|
|
return p;
|
|
|
|
}
|
2012-02-16 04:43:03 +00:00
|
|
|
return QQmlDebugPropertyReference();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::waitForQuery(QQmlDebugQuery *query)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QVERIFY(query);
|
|
|
|
QCOMPARE(query->parent(), qobject_cast<QObject*>(this));
|
2012-02-16 04:43:03 +00:00
|
|
|
QVERIFY(query->state() == QQmlDebugQuery::Waiting);
|
|
|
|
if (!QQmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QQmlDebugQuery::State))))
|
2011-04-27 10:05:43 +00:00
|
|
|
QFAIL("query timed out");
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::recursiveObjectTest(QObject *o, const QQmlDebugObjectReference &oref, bool recursive) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
const QMetaObject *meta = o->metaObject();
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlType *type = QQmlMetaType::qmlType(meta);
|
2011-04-27 10:05:43 +00:00
|
|
|
QString className = type ? QString(type->qmlTypeName()) : QString(meta->className());
|
|
|
|
className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(oref.debugId(), QQmlDebugService::idForObject(o));
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(oref.name(), o->objectName());
|
|
|
|
QCOMPARE(oref.className(), className);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(oref.contextDebugId(), QQmlDebugService::idForObject(qmlContext(o)));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
const QObjectList &children = o->children();
|
|
|
|
for (int i=0; i<children.count(); i++) {
|
|
|
|
QObject *child = children[i];
|
|
|
|
if (!qmlContext(child))
|
|
|
|
continue;
|
2012-02-16 04:43:03 +00:00
|
|
|
int debugId = QQmlDebugService::idForObject(child);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(debugId >= 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference cref;
|
|
|
|
foreach (const QQmlDebugObjectReference &ref, oref.children()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (ref.debugId() == debugId) {
|
|
|
|
cref = ref;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(cref.debugId() >= 0);
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
recursiveObjectTest(child, cref, true);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugPropertyReference &p, oref.properties()) {
|
|
|
|
QCOMPARE(p.objectDebugId(), QQmlDebugService::idForObject(o));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
// signal properties are fake - they are generated from QQmlBoundSignal children
|
2011-04-27 10:05:43 +00:00
|
|
|
if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlBoundSignal*> signalHandlers = o->findChildren<QQmlBoundSignal*>();
|
2011-11-17 02:53:26 +00:00
|
|
|
QString signal = p.value().toString();
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < signalHandlers.count(); ++i)
|
|
|
|
if (signalHandlers.at(i)->expression()->expression() == signal) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QVERIFY(found);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(p.valueTypeName().isEmpty());
|
|
|
|
QVERIFY(p.binding().isEmpty());
|
|
|
|
QVERIFY(!p.hasNotifySignal());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData()));
|
|
|
|
|
|
|
|
QCOMPARE(p.name(), QString::fromUtf8(pmeta.name()));
|
|
|
|
|
2012-01-26 14:04:51 +00:00
|
|
|
if (pmeta.type() < QVariant::UserType && pmeta.userType() != QMetaType::QVariant) // TODO test complex types
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(p.value(), pmeta.read(o));
|
|
|
|
|
|
|
|
if (p.name() == "parent")
|
2011-10-14 08:51:42 +00:00
|
|
|
QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QQuickItem*");
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
|
|
|
QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName()));
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlAbstractBinding *binding =
|
|
|
|
QQmlPropertyPrivate::binding(QQmlProperty(o, p.name()));
|
2011-04-27 10:05:43 +00:00
|
|
|
if (binding)
|
|
|
|
QCOMPARE(binding->expression(), p.binding());
|
|
|
|
|
|
|
|
QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal());
|
|
|
|
|
|
|
|
QVERIFY(pmeta.isValid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::recursiveCompareObjects(const QQmlDebugObjectReference &a, const QQmlDebugObjectReference &b) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlDebugPropertyReference> aprops = a.properties();
|
|
|
|
QList<QQmlDebugPropertyReference> bprops = b.properties();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
for (int i=0; i<aprops.count(); i++)
|
|
|
|
compareProperties(aprops[i], bprops[i]);
|
|
|
|
|
|
|
|
for (int i=0; i<a.children().count(); i++)
|
|
|
|
recursiveCompareObjects(a.children()[i], b.children()[i]);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::recursiveCompareContexts(const QQmlDebugContextReference &a, const QQmlDebugContextReference &b) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QCOMPARE(a.debugId(), b.debugId());
|
|
|
|
QCOMPARE(a.name(), b.name());
|
|
|
|
QCOMPARE(a.objects().count(), b.objects().count());
|
|
|
|
QCOMPARE(a.contexts().count(), b.contexts().count());
|
|
|
|
|
|
|
|
for (int i=0; i<a.objects().count(); i++)
|
|
|
|
recursiveCompareObjects(a.objects()[i], b.objects()[i]);
|
|
|
|
|
|
|
|
for (int i=0; i<a.contexts().count(); i++)
|
|
|
|
recursiveCompareContexts(a.contexts()[i], b.contexts()[i]);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::compareProperties(const QQmlDebugPropertyReference &a, const QQmlDebugPropertyReference &b) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QCOMPARE(a.objectDebugId(), b.objectDebugId());
|
|
|
|
QCOMPARE(a.name(), b.name());
|
|
|
|
QCOMPARE(a.value(), b.value());
|
|
|
|
QCOMPARE(a.valueTypeName(), b.valueTypeName());
|
|
|
|
QCOMPARE(a.binding(), b.binding());
|
|
|
|
QCOMPARE(a.hasNotifySignal(), b.hasNotifySignal());
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::initTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
qRegisterMetaType<QQmlDebugWatch::State>();
|
2011-04-27 10:05:43 +00:00
|
|
|
qmlRegisterType<NonScriptProperty>("Test", 1, 0, "NonScriptPropertyElement");
|
|
|
|
|
2012-03-08 14:15:10 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Waiting for connection on port 3768...");
|
2012-02-16 04:43:03 +00:00
|
|
|
m_engine = new QQmlEngine(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QList<QByteArray> qml;
|
2011-07-11 03:47:51 +00:00
|
|
|
qml << "import QtQuick 2.0\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"import Test 1.0\n"
|
|
|
|
"Item {"
|
|
|
|
"id: root\n"
|
|
|
|
"width: 10; height: 20; scale: blueRect.scale;"
|
|
|
|
"Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
|
|
|
|
"Text { color: blueRect.color; }"
|
|
|
|
"MouseArea {"
|
|
|
|
"onEntered: { console.log('hello') }"
|
|
|
|
"}"
|
|
|
|
"property variant varObj\n"
|
|
|
|
"property variant varObjList: []\n"
|
2012-02-17 10:09:31 +00:00
|
|
|
"property variant varObjMap\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"Component.onCompleted: {\n"
|
|
|
|
"varObj = blueRect;\n"
|
|
|
|
"var list = varObjList;\n"
|
|
|
|
"list[0] = blueRect;\n"
|
|
|
|
"varObjList = list;\n"
|
2012-02-17 10:09:31 +00:00
|
|
|
"var map = new Object;\n"
|
|
|
|
"map.rect = blueRect;\n"
|
|
|
|
"varObjMap = map;\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"}\n"
|
|
|
|
"NonScriptPropertyElement {\n"
|
|
|
|
"}\n"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
// add second component to test multiple root contexts
|
2011-07-11 03:47:51 +00:00
|
|
|
qml << "import QtQuick 2.0\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"Item {}";
|
|
|
|
|
|
|
|
// and a third to test methods
|
2011-07-11 03:47:51 +00:00
|
|
|
qml << "import QtQuick 2.0\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"Item {"
|
|
|
|
"function myMethodNoArgs() { return 3; }\n"
|
|
|
|
"function myMethod(a) { return a + 9; }\n"
|
|
|
|
"function myMethodIndirect() { myMethod(3); }\n"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
// and a fourth to test states
|
2011-07-11 03:47:51 +00:00
|
|
|
qml << "import QtQuick 2.0\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
"Rectangle {\n"
|
|
|
|
"id:rootRect\n"
|
|
|
|
"width:100\n"
|
|
|
|
"states: [\n"
|
|
|
|
"State {\n"
|
|
|
|
"name:\"state1\"\n"
|
|
|
|
"PropertyChanges {\n"
|
|
|
|
"target:rootRect\n"
|
|
|
|
"width:200\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"]\n"
|
|
|
|
"transitions: [\n"
|
|
|
|
"Transition {\n"
|
|
|
|
"from:\"*\"\n"
|
|
|
|
"to:\"state1\"\n"
|
|
|
|
"PropertyAnimation {\n"
|
|
|
|
"target:rootRect\n"
|
|
|
|
"property:\"width\"\n"
|
|
|
|
"duration:100\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
"]\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
|
|
|
|
for (int i=0; i<qml.count(); i++) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent component(m_engine);
|
2011-04-27 10:05:43 +00:00
|
|
|
component.setData(qml[i], QUrl::fromLocalFile(""));
|
2011-05-18 00:45:16 +00:00
|
|
|
QVERIFY(component.isReady()); // fails if bad syntax
|
2011-10-14 08:51:42 +00:00
|
|
|
m_components << qobject_cast<QQuickItem*>(component.create());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-10-14 08:51:42 +00:00
|
|
|
m_rootItem = qobject_cast<QQuickItem*>(m_components.first());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// add an extra context to test for multiple contexts
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *context = new QQmlContext(m_engine->rootContext(), this);
|
|
|
|
context->setObjectName("tst_QQmlDebug_childContext");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
m_conn = new QQmlDebugConnection(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
m_conn->connectToHost("127.0.0.1", 3768);
|
|
|
|
|
2012-03-08 14:15:10 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established.");
|
2011-04-27 10:05:43 +00:00
|
|
|
bool ok = m_conn->waitForConnected();
|
2011-05-18 00:45:16 +00:00
|
|
|
QVERIFY(ok);
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_VERIFY(QQmlDebugService::hasDebuggingClient());
|
2012-03-13 16:16:16 +00:00
|
|
|
m_dbg = new QQmlEngineDebugClient(m_conn);
|
|
|
|
QTRY_VERIFY(m_dbg->state() == QQmlEngineDebugClient::Enabled);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::cleanupTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
delete m_conn;
|
|
|
|
qDeleteAll(m_components);
|
|
|
|
delete m_engine;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::setMethodBody()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = findRootObject(2);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QObject *root = m_components.at(2);
|
|
|
|
// Without args
|
|
|
|
{
|
|
|
|
QVariant rv;
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(root, "myMethodNoArgs", Qt::DirectConnection,
|
|
|
|
Q_RETURN_ARG(QVariant, rv)));
|
|
|
|
QVERIFY(rv == QVariant(qreal(3)));
|
|
|
|
|
|
|
|
|
|
|
|
QVERIFY(m_dbg->setMethodBody(obj.debugId(), "myMethodNoArgs", "return 7"));
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(root, "myMethodNoArgs", Qt::DirectConnection,
|
|
|
|
Q_RETURN_ARG(QVariant, rv)));
|
|
|
|
QVERIFY(rv == QVariant(qreal(7)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// With args
|
|
|
|
{
|
|
|
|
QVariant rv;
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(root, "myMethod", Qt::DirectConnection,
|
|
|
|
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(QMetaObject::invokeMethod(root, "myMethod", Qt::DirectConnection,
|
|
|
|
Q_RETURN_ARG(QVariant, rv), Q_ARG(QVariant, QVariant(19))));
|
|
|
|
QVERIFY(rv == QVariant(qreal(26)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_property()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = findRootObject();
|
|
|
|
QQmlDebugPropertyReference prop = findProperty(obj.properties(), "width");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyWatch *watch;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
watch = unconnected->addWatch(prop, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Dead);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
|
|
|
delete unconnected;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
watch = m_dbg->addWatch(QQmlDebugPropertyReference(), this);
|
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
watch = m_dbg->addWatch(prop, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Waiting);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(watch->objectDebugId(), obj.debugId());
|
|
|
|
QCOMPARE(watch->name(), prop.name());
|
|
|
|
|
|
|
|
QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant)));
|
|
|
|
|
|
|
|
int origWidth = m_rootItem->property("width").toInt();
|
|
|
|
m_rootItem->setProperty("width", origWidth*2);
|
|
|
|
|
|
|
|
// stateChanged() is received before valueChanged()
|
2012-02-16 04:43:03 +00:00
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Active);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
m_dbg->removeWatch(watch);
|
|
|
|
delete watch;
|
|
|
|
|
|
|
|
// restore original value and verify spy doesn't get additional signal since watch has been removed
|
|
|
|
m_rootItem->setProperty("width", origWidth);
|
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(spy.at(0).at(0).value<QByteArray>(), prop.name().toUtf8());
|
|
|
|
QCOMPARE(spy.at(0).at(1).value<QVariant>(), qVariantFromValue(origWidth*2));
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_object()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
2011-05-18 00:45:16 +00:00
|
|
|
|
|
|
|
QVERIFY(q_engines->engines().count() > 0);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
|
|
|
|
2012-03-12 13:08:56 +00:00
|
|
|
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);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_obj);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = q_obj->object();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
|
|
|
delete q_obj;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugWatch *watch;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
watch = unconnected->addWatch(obj, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Dead);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
|
|
|
delete unconnected;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
watch = m_dbg->addWatch(QQmlDebugObjectReference(), this);
|
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
|
|
|
|
|
|
|
watch = m_dbg->addWatch(obj, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Waiting);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(watch->objectDebugId(), obj.debugId());
|
|
|
|
|
|
|
|
QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant)));
|
|
|
|
|
|
|
|
int origWidth = m_rootItem->property("width").toInt();
|
|
|
|
int origHeight = m_rootItem->property("height").toInt();
|
|
|
|
m_rootItem->setProperty("width", origWidth*2);
|
|
|
|
m_rootItem->setProperty("height", origHeight*2);
|
|
|
|
|
|
|
|
// stateChanged() is received before any valueChanged() signals
|
2012-02-16 04:43:03 +00:00
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Active);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(spy.count() > 0);
|
|
|
|
|
|
|
|
int newWidth = -1;
|
|
|
|
int newHeight = -1;
|
|
|
|
for (int i=0; i<spy.count(); i++) {
|
|
|
|
const QVariantList &values = spy[i];
|
|
|
|
if (values[0].value<QByteArray>() == "width")
|
|
|
|
newWidth = values[1].value<QVariant>().toInt();
|
|
|
|
else if (values[0].value<QByteArray>() == "height")
|
|
|
|
newHeight = values[1].value<QVariant>().toInt();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dbg->removeWatch(watch);
|
|
|
|
delete watch;
|
|
|
|
|
|
|
|
// since watch has been removed, restoring the original values should not trigger a valueChanged()
|
|
|
|
spy.clear();
|
|
|
|
m_rootItem->setProperty("width", origWidth);
|
|
|
|
m_rootItem->setProperty("height", origHeight);
|
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
|
|
|
|
QCOMPARE(newWidth, origWidth * 2);
|
|
|
|
QCOMPARE(newHeight, origHeight * 2);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_expression()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QFETCH(QString, expr);
|
|
|
|
QFETCH(int, increment);
|
|
|
|
QFETCH(int, incrementCount);
|
|
|
|
|
|
|
|
int origWidth = m_rootItem->property("width").toInt();
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = findRootObject();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectExpressionWatch *watch;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
watch = unconnected->addWatch(obj, expr, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Dead);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
|
|
|
delete unconnected;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
watch = m_dbg->addWatch(QQmlDebugObjectReference(), expr, this);
|
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete watch;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
watch = m_dbg->addWatch(obj, expr, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Waiting);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(watch->objectDebugId(), obj.debugId());
|
|
|
|
QCOMPARE(watch->expression(), expr);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QSignalSpy spyState(watch, SIGNAL(stateChanged(QQmlDebugWatch::State)));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant)));
|
|
|
|
int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value
|
|
|
|
|
|
|
|
int width = origWidth;
|
|
|
|
for (int i=0; i<incrementCount+1; i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
width += increment;
|
|
|
|
m_rootItem->setProperty("width", width);
|
|
|
|
}
|
2012-02-16 04:43:03 +00:00
|
|
|
if (!QQmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant))))
|
2011-04-27 10:05:43 +00:00
|
|
|
QFAIL("Did not receive valueChanged() for expression");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spyState.count() == 0)
|
2012-02-16 04:43:03 +00:00
|
|
|
QVERIFY(QQmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QQmlDebugWatch::State))));
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spyState.count(), 1);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(watch->state(), QQmlDebugWatch::Active);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
m_dbg->removeWatch(watch);
|
|
|
|
delete watch;
|
|
|
|
|
|
|
|
// restore original value and verify spy doesn't get a signal since watch has been removed
|
2011-05-18 00:45:16 +00:00
|
|
|
m_rootItem->setProperty("width", origWidth);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(spy.count(), expectedSpyCount);
|
|
|
|
|
|
|
|
width = origWidth + increment;
|
|
|
|
for (int i=0; i<spy.count(); i++) {
|
|
|
|
QCOMPARE(spy.at(i).at(1).value<QVariant>().toInt(), width);
|
|
|
|
width += increment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_expression_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("expr");
|
|
|
|
QTest::addColumn<int>("increment");
|
|
|
|
QTest::addColumn<int>("incrementCount");
|
|
|
|
|
|
|
|
QTest::newRow("width") << "width" << 0 << 0;
|
|
|
|
QTest::newRow("width+10") << "width + 10" << 10 << 5;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_context()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugContextReference c;
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebug::addWatch(): Not implemented");
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!m_dbg->addWatch(c, QString(), this));
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::watch_file()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugFileReference f;
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QQmlEngineDebug::addWatch(): Not implemented");
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!m_dbg->addWatch(f, this));
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryAvailableEngines()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
q_engines = unconnected->queryAvailableEngines(0);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_engines->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_engines;
|
|
|
|
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);
|
|
|
|
|
|
|
|
// TODO test multiple engines
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlDebugEngineReference> engines = q_engines->engines();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(engines.count(), 1);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach(const QQmlDebugEngineReference &e, engines) {
|
|
|
|
QCOMPARE(e.debugId(), QQmlDebugService::idForObject(m_engine));
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(e.name(), m_engine->objectName());
|
|
|
|
}
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
// Make query invalid by deleting client
|
|
|
|
q_engines = m_dbg->queryAvailableEngines(this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_engines->state(), QQmlDebugQuery::Waiting);
|
2011-04-27 12:13:26 +00:00
|
|
|
delete m_dbg;
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_engines->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_engines;
|
2012-03-13 16:16:16 +00:00
|
|
|
m_dbg = new QQmlEngineDebugClient(m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryRootContexts()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
|
|
|
int engineId = q_engines->engines()[0].debugId();
|
2011-04-27 12:13:26 +00:00
|
|
|
delete q_engines;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
q_context = unconnected->queryRootContexts(engineId, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_context->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_context;
|
|
|
|
delete unconnected;
|
|
|
|
|
|
|
|
q_context = m_dbg->queryRootContexts(engineId, this);
|
|
|
|
delete q_context;
|
|
|
|
|
|
|
|
q_context = m_dbg->queryRootContexts(engineId, this);
|
|
|
|
waitForQuery(q_context);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *actualContext = m_engine->rootContext();
|
|
|
|
QQmlDebugContextReference context = q_context->rootContext();
|
|
|
|
QCOMPARE(context.debugId(), QQmlDebugService::idForObject(actualContext));
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(context.name(), actualContext->objectName());
|
|
|
|
|
|
|
|
// root context query sends only root object data - it doesn't fill in
|
|
|
|
// the children or property info
|
2012-03-12 13:08:56 +00:00
|
|
|
QCOMPARE(context.objects().count(), 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(context.contexts().count(), 5);
|
|
|
|
QVERIFY(context.contexts()[0].debugId() >= 0);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(context.contexts()[0].name(), QString("tst_QQmlDebug_childContext"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
// Make query invalid by deleting client
|
|
|
|
q_context = m_dbg->queryRootContexts(engineId, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_context->state(), QQmlDebugQuery::Waiting);
|
2011-04-27 12:13:26 +00:00
|
|
|
delete m_dbg;
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_context->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_context;
|
2012-03-13 16:16:16 +00:00
|
|
|
m_dbg = new QQmlEngineDebugClient(m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryObject()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QFETCH(bool, recursive);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
2012-03-12 13:08:56 +00:00
|
|
|
QQmlDebugObjectReference rootObject = q_context->rootContext().contexts().last().objects()[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectQuery *q_obj = 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
q_obj = recursive ? unconnected->queryObjectRecursive(rootObject, this) : unconnected->queryObject(rootObject, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_obj->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_obj;
|
|
|
|
delete unconnected;
|
|
|
|
|
|
|
|
q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this);
|
|
|
|
delete q_obj;
|
|
|
|
|
|
|
|
q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this);
|
|
|
|
waitForQuery(q_obj);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = q_obj->object();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// Make query invalid by deleting client
|
|
|
|
q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_obj->state(), QQmlDebugQuery::Waiting);
|
2011-04-27 12:13:26 +00:00
|
|
|
delete m_dbg;
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_obj->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_obj;
|
2012-03-13 16:16:16 +00:00
|
|
|
m_dbg = new QQmlEngineDebugClient(m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// check source as defined in main()
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugFileReference source = obj.source();
|
2011-04-27 10:05:43 +00:00
|
|
|
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) {
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach(const QQmlDebugObjectReference &child, obj.children())
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(child.properties().count() > 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference rect;
|
|
|
|
QQmlDebugObjectReference text;
|
|
|
|
foreach (const QQmlDebugObjectReference &child, obj.children()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (child.className() == "Rectangle")
|
|
|
|
rect = child;
|
|
|
|
else if (child.className() == "Text")
|
|
|
|
text = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
// test specific property values
|
|
|
|
QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500));
|
|
|
|
QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600));
|
|
|
|
QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue")));
|
|
|
|
|
|
|
|
QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue")));
|
|
|
|
} else {
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach(const QQmlDebugObjectReference &child, obj.children())
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(child.properties().count(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryObject_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("recursive");
|
|
|
|
|
|
|
|
QTest::newRow("non-recursive") << false;
|
|
|
|
QTest::newRow("recursive") << true;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryExpressionResult()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QFETCH(QString, expr);
|
|
|
|
QFETCH(QVariant, result);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines); // check immediate deletion is ok
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
2012-03-12 13:08:56 +00:00
|
|
|
int objectId = q_context->rootContext().contexts().last().objects()[0].debugId();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugExpressionQuery *q_expr;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-13 16:16:16 +00:00
|
|
|
QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
q_expr = unconnected->queryExpressionResult(objectId, expr, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_expr->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_expr;
|
|
|
|
delete unconnected;
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
QCOMPARE(q_expr->result(), result);
|
|
|
|
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// Make query invalid by deleting client
|
|
|
|
q_expr = m_dbg->queryExpressionResult(objectId, expr, this);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_expr->state(), QQmlDebugQuery::Waiting);
|
2011-04-27 12:13:26 +00:00
|
|
|
delete m_dbg;
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(q_expr->state(), QQmlDebugQuery::Error);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete q_expr;
|
2012-03-13 16:16:16 +00:00
|
|
|
m_dbg = new QQmlEngineDebugClient(m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryExpressionResult_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("expr");
|
|
|
|
QTest::addColumn<QVariant>("result");
|
|
|
|
|
|
|
|
QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60);
|
|
|
|
QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500);
|
|
|
|
QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("<undefined>"));
|
|
|
|
QTest::newRow("QObject*") << "varObj" << qVariantFromValue(QString("<unnamed object>"));
|
|
|
|
QTest::newRow("list of QObject*") << "varObjList" << qVariantFromValue(QString("<unknown value>"));
|
2012-02-17 10:09:31 +00:00
|
|
|
QVariantMap map;
|
|
|
|
map.insert(QLatin1String("rect"), QVariant(QLatin1String("<unnamed object>")));
|
|
|
|
QTest::newRow("varObjMap") << "varObjMap" << qVariantFromValue(map);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::tst_QQmlDebugFileReference()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugFileReference ref;
|
2011-04-27 10:05:43 +00:00
|
|
|
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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugFileReference copy(ref);
|
|
|
|
QQmlDebugFileReference copyAssign;
|
2011-04-27 10:05:43 +00:00
|
|
|
copyAssign = ref;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugFileReference &r, (QList<QQmlDebugFileReference>() << copy << copyAssign)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(r.url(), ref.url());
|
|
|
|
QCOMPARE(r.lineNumber(), ref.lineNumber());
|
|
|
|
QCOMPARE(r.columnNumber(), ref.columnNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::tst_QQmlDebugEngineReference()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEngineReference ref;
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ref.debugId(), -1);
|
|
|
|
QVERIFY(ref.name().isEmpty());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
ref = QQmlDebugEngineReference(1);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ref.debugId(), 1);
|
|
|
|
QVERIFY(ref.name().isEmpty());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
|
|
|
ref = q_engines->engines()[0];
|
|
|
|
delete q_engines;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEngineReference copy(ref);
|
|
|
|
QQmlDebugEngineReference copyAssign;
|
2011-04-27 10:05:43 +00:00
|
|
|
copyAssign = ref;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugEngineReference &r, (QList<QQmlDebugEngineReference>() << copy << copyAssign)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(r.debugId(), ref.debugId());
|
|
|
|
QCOMPARE(r.name(), ref.name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::tst_QQmlDebugObjectReference()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference ref;
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ref.debugId(), -1);
|
|
|
|
QCOMPARE(ref.className(), QString());
|
|
|
|
QCOMPARE(ref.name(), QString());
|
|
|
|
QCOMPARE(ref.contextDebugId(), -1);
|
|
|
|
QVERIFY(ref.properties().isEmpty());
|
|
|
|
QVERIFY(ref.children().isEmpty());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugFileReference source = ref.source();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(source.url().isEmpty());
|
|
|
|
QVERIFY(source.lineNumber() < 0);
|
|
|
|
QVERIFY(source.columnNumber() < 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
ref = QQmlDebugObjectReference(1);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ref.debugId(), 1);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference rootObject = findRootObject();
|
|
|
|
QQmlDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(query);
|
|
|
|
ref = query->object();
|
|
|
|
delete query;
|
|
|
|
|
|
|
|
QVERIFY(ref.debugId() >= 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference copy(ref);
|
|
|
|
QQmlDebugObjectReference copyAssign;
|
2011-04-27 10:05:43 +00:00
|
|
|
copyAssign = ref;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugObjectReference &r, (QList<QQmlDebugObjectReference>() << copy << copyAssign))
|
2011-04-27 10:05:43 +00:00
|
|
|
recursiveCompareObjects(r, ref);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::tst_QQmlDebugContextReference()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugContextReference ref;
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ref.debugId(), -1);
|
|
|
|
QVERIFY(ref.name().isEmpty());
|
|
|
|
QVERIFY(ref.objects().isEmpty());
|
|
|
|
QVERIFY(ref.contexts().isEmpty());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
|
|
|
|
|
|
|
ref = q_context->rootContext();
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
|
|
|
QVERIFY(ref.debugId() >= 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugContextReference copy(ref);
|
|
|
|
QQmlDebugContextReference copyAssign;
|
2011-04-27 10:05:43 +00:00
|
|
|
copyAssign = ref;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugContextReference &r, (QList<QQmlDebugContextReference>() << copy << copyAssign))
|
2011-04-27 10:05:43 +00:00
|
|
|
recursiveCompareContexts(r, ref);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::tst_QQmlDebugPropertyReference()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference rootObject = findRootObject();
|
|
|
|
QQmlDebugObjectQuery *query = m_dbg->queryObject(rootObject, this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(query);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = query->object();
|
2011-05-18 00:45:16 +00:00
|
|
|
delete query;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference ref = findProperty(obj.properties(), "scale");
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(ref.objectDebugId() > 0);
|
|
|
|
QVERIFY(!ref.name().isEmpty());
|
|
|
|
QVERIFY(!ref.value().isNull());
|
|
|
|
QVERIFY(!ref.valueTypeName().isEmpty());
|
|
|
|
QVERIFY(!ref.binding().isEmpty());
|
|
|
|
QVERIFY(ref.hasNotifySignal());
|
2011-05-18 00:45:16 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference copy(ref);
|
|
|
|
QQmlDebugPropertyReference copyAssign;
|
2011-04-27 10:05:43 +00:00
|
|
|
copyAssign = ref;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (const QQmlDebugPropertyReference &r, (QList<QQmlDebugPropertyReference>() << copy << copyAssign))
|
2011-04-27 10:05:43 +00:00
|
|
|
compareProperties(r, ref);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::setBindingForObject()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference rootObject = findRootObject();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(rootObject.debugId() != -1);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties(), "width");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(widthPropertyRef.value(), QVariant(10));
|
|
|
|
QCOMPARE(widthPropertyRef.binding(), QString());
|
|
|
|
|
|
|
|
//
|
|
|
|
// set literal
|
|
|
|
//
|
|
|
|
m_dbg->setBindingForObject(rootObject.debugId(), "width", "15", true);
|
|
|
|
|
|
|
|
rootObject = findRootObject();
|
|
|
|
widthPropertyRef = findProperty(rootObject.properties(), "width");
|
|
|
|
|
|
|
|
QCOMPARE(widthPropertyRef.value(), QVariant(15));
|
|
|
|
QCOMPARE(widthPropertyRef.binding(), QString());
|
|
|
|
|
|
|
|
//
|
|
|
|
// set expression
|
|
|
|
//
|
|
|
|
m_dbg->setBindingForObject(rootObject.debugId(), "width", "height", false);
|
|
|
|
|
|
|
|
rootObject = findRootObject();
|
|
|
|
widthPropertyRef = findProperty(rootObject.properties(), "width");
|
|
|
|
|
|
|
|
QCOMPARE(widthPropertyRef.value(), QVariant(20));
|
|
|
|
QCOMPARE(widthPropertyRef.binding(), QString("height"));
|
|
|
|
|
|
|
|
//
|
|
|
|
// reset
|
|
|
|
//
|
|
|
|
m_dbg->resetBindingForObject(rootObject.debugId(), "width");
|
|
|
|
|
|
|
|
rootObject = findRootObject();
|
|
|
|
widthPropertyRef = findProperty(rootObject.properties(), "width");
|
|
|
|
|
|
|
|
// QCOMPARE(widthPropertyRef.value(), QVariant(0)); // TODO: Shouldn't this work?
|
|
|
|
QCOMPARE(widthPropertyRef.binding(), QString());
|
|
|
|
|
|
|
|
//
|
|
|
|
// set handler
|
|
|
|
//
|
|
|
|
rootObject = findRootObject();
|
2011-05-20 12:25:24 +00:00
|
|
|
QCOMPARE(rootObject.children().size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference mouseAreaObject = rootObject.children().at(2);
|
|
|
|
QQmlDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_obj);
|
|
|
|
mouseAreaObject = q_obj->object();
|
|
|
|
|
|
|
|
QCOMPARE(mouseAreaObject.className(), QString("MouseArea"));
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference onEnteredRef = findProperty(mouseAreaObject.properties(), "onEntered");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(onEnteredRef.name(), QString("onEntered"));
|
2011-11-17 02:53:26 +00:00
|
|
|
QCOMPARE(onEnteredRef.value(), QVariant("(function onEntered() { { console.log('hello') } })"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
m_dbg->setBindingForObject(mouseAreaObject.debugId(), "onEntered", "{console.log('hello, world') }", false) ;
|
|
|
|
|
|
|
|
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') }"));
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::setBindingInStates()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
// Check if changing bindings of propertychanges works
|
|
|
|
|
|
|
|
const int sourceIndex = 3;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = findRootObject(sourceIndex);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(obj.debugId() != -1);
|
|
|
|
QVERIFY(obj.children().count() >= 2);
|
|
|
|
|
|
|
|
// We are going to switch state a couple of times, we need to get rid of the transition before
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugExpressionQuery *q_deleteTransition = m_dbg->queryExpressionResult(obj.debugId(),QString("transitions = []"),this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_deleteTransition);
|
|
|
|
delete q_deleteTransition;
|
|
|
|
|
|
|
|
|
|
|
|
// check initial value of the property that is changing
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugExpressionQuery *q_setState;
|
2011-04-27 10:05:43 +00:00
|
|
|
q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"state1\""),this);
|
|
|
|
waitForQuery(q_setState);
|
|
|
|
delete q_setState;
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),200);
|
|
|
|
|
|
|
|
|
|
|
|
q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this);
|
|
|
|
waitForQuery(q_setState);
|
|
|
|
delete q_setState;
|
|
|
|
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex, true);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),100);
|
|
|
|
|
|
|
|
|
|
|
|
// change the binding
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference state = obj.children()[1];
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(state.className(), QString("State"));
|
|
|
|
QVERIFY(state.children().count() > 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference propertyChange = state.children()[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(propertyChange.debugId() != -1);
|
|
|
|
|
|
|
|
QVERIFY( m_dbg->setBindingForObject(propertyChange.debugId(), "width",QVariant(300),true) );
|
|
|
|
|
|
|
|
// check properties changed in state
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
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;
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
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));
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(),300);
|
|
|
|
|
|
|
|
q_setState = m_dbg->queryExpressionResult(obj.debugId(),QString("state=\"\""),this);
|
|
|
|
waitForQuery(q_setState);
|
|
|
|
delete q_setState;
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
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;
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300);
|
|
|
|
|
|
|
|
m_dbg->resetBindingForObject(propertyChange.debugId(), "width");
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 400);
|
|
|
|
|
|
|
|
// re-add binding
|
|
|
|
m_dbg->setBindingForObject(propertyChange.debugId(), "width", "300", true);
|
|
|
|
|
|
|
|
obj = findRootObject(sourceIndex);
|
|
|
|
QCOMPARE(findProperty(obj.properties(),"width").value().toInt(), 300);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
void tst_QQmlEngineDebugService::queryObjectTree()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
const int sourceIndex = 3;
|
|
|
|
|
|
|
|
// Check if states/transitions are initialized when fetching root item
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_engines);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_context);
|
|
|
|
|
2012-03-12 13:08:56 +00:00
|
|
|
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];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this);
|
2011-04-27 10:05:43 +00:00
|
|
|
waitForQuery(q_obj);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference obj = q_obj->object();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
delete q_engines;
|
|
|
|
delete q_context;
|
|
|
|
delete q_obj;
|
|
|
|
|
|
|
|
QVERIFY(obj.debugId() != -1);
|
|
|
|
QVERIFY(obj.children().count() >= 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check state
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference state = obj.children()[1];
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(state.className(), QString("State"));
|
|
|
|
QVERIFY(state.children().count() > 0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference propertyChange = state.children()[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(propertyChange.debugId() != -1);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties(),"target");
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(propertyChangeTarget.objectDebugId(), propertyChange.debugId());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference targetReference = qvariant_cast<QQmlDebugObjectReference>(propertyChangeTarget.value());
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(targetReference.debugId() != -1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check transition
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference transition = obj.children()[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugObjectReference animation = transition.children()[0];
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(animation.debugId() != -1);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugPropertyReference animationTarget = findProperty(animation.properties(),"target");
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(animationTarget.objectDebugId(), animation.debugId());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
targetReference = qvariant_cast<QQmlDebugObjectReference>(animationTarget.value());
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(targetReference.debugId() != -1);
|
|
|
|
|
|
|
|
QCOMPARE(findProperty(animation.properties(),"property").value().toString(), QString("width"));
|
|
|
|
QCOMPARE(findProperty(animation.properties(),"duration").value().toInt(), 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int _argc = argc + 1;
|
|
|
|
char **_argv = new char*[_argc];
|
|
|
|
for (int i = 0; i < argc; ++i)
|
|
|
|
_argv[i] = argv[i];
|
2011-08-31 07:05:00 +00:00
|
|
|
char arg[] = "-qmljsdebugger=port:3768";
|
|
|
|
_argv[_argc - 1] = arg;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-16 10:07:14 +00:00
|
|
|
QGuiApplication app(_argc, _argv);
|
2012-03-06 13:59:29 +00:00
|
|
|
tst_QQmlEngineDebugService tc;
|
2011-04-27 10:05:43 +00:00
|
|
|
return QTest::qExec(&tc, _argc, _argv);
|
|
|
|
delete _argv;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
#include "tst_qqmlenginedebugservice.moc"
|