Debugger: Clearing the ObjectReferenceHash
authorSimjees Abraham <simjees.abraham@nokia.com>
Fri, 25 May 2012 07:02:44 +0000 (09:02 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 30 May 2012 10:07:19 +0000 (12:07 +0200)
ObjectReferenceHash is cleared when the Qml file is reloaded.

Change-Id: I78da1d88cce2f04fe820f3af14b047cd562e90ed
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>

16 files changed:
src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp
src/qml/debugger/qqmldebugservice.cpp
src/qml/debugger/qqmldebugservice_p.h
tests/auto/qml/debugger/debugger.pro
tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml [new file with mode: 0644]
tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro [new file with mode: 0644]
tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp [new file with mode: 0644]
tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugservice.pro
tests/auto/qml/debugger/qqmlinspector/qqmlinspector.pro
tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp
tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp [moved from tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.cpp with 100% similarity]
tests/auto/qml/debugger/shared/qqmlenginedebugclient.h [moved from tests/auto/qml/debugger/qqmlenginedebugservice/qqmlenginedebugclient.h with 100% similarity]
tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri [new file with mode: 0644]
tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp [new file with mode: 0644]
tests/auto/qml/debugger/shared/qqmlinspectorclient.h [new file with mode: 0644]
tests/auto/qml/debugger/shared/qqmlinspectorclient.pri [new file with mode: 0644]

index dbe5119..a42663e 100644 (file)
@@ -45,6 +45,7 @@
 #include "inspecttool.h"
 
 #include <QtQml/private/qqmlengine_p.h>
+#include <QtQml/private/qqmldebugservice_p.h>
 #include <QtQuick/private/qquickitem_p.h>
 
 #include <QtQuick/QQuickView>
@@ -321,6 +322,8 @@ void QQuickViewInspector::reloadQmlFile(const QHash<QString, QByteArray> &change
     // Reset the selection since we are reloading the main qml
     setSelectedItems(QList<QQuickItem *>());
 
+    QQmlDebugService::clearObjectsFromHash();
+
     QHash<QUrl, QByteArray> debugCache;
 
     foreach (const QString &str, changesHash.keys())
index 511c854..d3d4df7 100644 (file)
@@ -257,6 +257,13 @@ void QQmlDebugService::removeInvalidObjectsFromHash()
     }
 }
 
+void QQmlDebugService::clearObjectsFromHash()
+{
+    ObjectReferenceHash *hash = objectReferenceHash();
+    hash->ids.clear();
+    hash->objects.clear();
+}
+
 bool QQmlDebugService::isDebuggingEnabled()
 {
     return QQmlDebugServer::instance() != 0;
index 4a0b52e..4fc37e6 100644 (file)
@@ -88,6 +88,7 @@ public:
     static QList<QObject*> objectForLocationInfo(const QString &filename,
                                           int lineNumber, int columnNumber);
     static void removeInvalidObjectsFromHash();
+    static void clearObjectsFromHash();
 
     static QString objectToString(QObject *obj);
 
index 81ca29a..8f90e4b 100644 (file)
@@ -7,7 +7,8 @@ PUBLICTESTS += \
     qqmlprofilerservice \
     qpacketprotocol \
     qv8profilerservice \
-    qdebugmessageservice
+    qdebugmessageservice \
+    qqmlenginedebuginspectorintegrationtest
 
 PRIVATETESTS += \
     qqmldebugclient \
diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/data/qtquick2.qml
new file mode 100644 (file)
index 0000000..9c36e13
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+
+}
diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/qqmlenginedebuginspectorintegrationtest.pro
new file mode 100644 (file)
index 0000000..0ecb966
--- /dev/null
@@ -0,0 +1,15 @@
+CONFIG += testcase
+TARGET = tst_qqmlenginedebuginspectorintegration
+
+QT += qml testlib
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qqmlenginedebuginspectorintegration.cpp
+
+INCLUDEPATH += ../shared
+include(../../../shared/util.pri)
+include(../shared/qqmlinspectorclient.pri)
+include(../shared/qqmlenginedebugclient.pri)
+include(../shared/debugutil.pri)
+
+TESTDATA = data/*
diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp
new file mode 100644 (file)
index 0000000..de34ba9
--- /dev/null
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** 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.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QSignalSpy>
+#include <QTimer>
+#include <QHostAddress>
+#include <QDebug>
+#include <QThread>
+#include <QtCore/QLibraryInfo>
+
+#include "../shared/debugutil_p.h"
+#include "../../../shared/util.h"
+#include "qqmlinspectorclient.h"
+#include "qqmlenginedebugclient.h"
+
+#define PORT 3776
+#define STR_PORT "3776"
+
+class tst_QQmlEngineDebugInspectorIntegration : public QQmlDataTest
+{
+    Q_OBJECT
+
+public:
+    tst_QQmlEngineDebugInspectorIntegration()
+        : m_process(0)
+        , m_connection(0)
+        , m_inspectorClient(0)
+        , m_engineDebugClient(0)
+    {
+    }
+
+
+private:
+    QmlDebugObjectReference findRootObject();
+
+    QQmlDebugProcess *m_process;
+    QQmlDebugConnection *m_connection;
+    QQmlInspectorClient *m_inspectorClient;
+    QQmlEngineDebugClient *m_engineDebugClient;
+
+private slots:
+    void init();
+    void cleanup();
+
+    void connect();
+    void clearObjectReferenceHashonReloadQml();
+};
+
+
+QmlDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRootObject()
+{
+    bool success = false;
+    m_engineDebugClient->queryAvailableEngines(&success);
+
+    QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
+
+    m_engineDebugClient->queryRootContexts(m_engineDebugClient->engines()[0].debugId, &success);
+    QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
+    int count = m_engineDebugClient->rootContext().contexts.count();
+    m_engineDebugClient->queryObject(
+                m_engineDebugClient->rootContext().contexts[count - 1].objects[0], &success);
+    QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
+    return m_engineDebugClient->object();
+}
+
+
+void tst_QQmlEngineDebugInspectorIntegration::init()
+{
+    const QString argument = "-qmljsdebugger=port:"STR_PORT",block";
+
+    m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath)
+                                     + "/qmlscene");
+    m_process->start(QStringList() << argument << testFile("qtquick2.qml"));
+    QVERIFY2(m_process->waitForSessionStart(),
+             "Could not launch application, or did not get 'Waiting for connection'.");
+
+    QQmlDebugConnection *m_connection = new QQmlDebugConnection(this);
+    m_inspectorClient = new QQmlInspectorClient(m_connection);
+    m_engineDebugClient = new QQmlEngineDebugClient(m_connection);
+
+    m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT);
+    bool ok = m_connection->waitForConnected();
+    QVERIFY(ok);
+}
+
+void tst_QQmlEngineDebugInspectorIntegration::cleanup()
+{
+    if (QTest::currentTestFailed()) {
+        qDebug() << "Process State:" << m_process->state();
+        qDebug() << "Application Output:" << m_process->output();
+    }
+    delete m_process;
+    delete m_engineDebugClient;
+    delete m_inspectorClient;
+}
+
+void tst_QQmlEngineDebugInspectorIntegration::connect()
+{
+    QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
+    QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
+}
+
+void tst_QQmlEngineDebugInspectorIntegration::clearObjectReferenceHashonReloadQml()
+{
+    QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
+    bool success = false;
+    QmlDebugObjectReference rootObject = findRootObject();
+    const QString fileName = QFileInfo(rootObject.source.url.toString()).fileName();
+    int lineNumber = rootObject.source.lineNumber;
+    int columnNumber = rootObject.source.columnNumber;
+    m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
+                                        columnNumber, &success);
+    QVERIFY(success);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
+
+    foreach (QmlDebugObjectReference child, rootObject.children) {
+        success = false;
+        lineNumber = child.source.lineNumber;
+        columnNumber = child.source.columnNumber;
+        m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
+                                       columnNumber, &success);
+        QVERIFY(success);
+        QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
+    }
+
+    QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
+
+    QByteArray contents;
+    contents.append("import QtQuick 2.0\n"
+               "Text {"
+               "y: 10\n"
+               "text: \"test\"\n"
+               "}");
+
+    QHash<QString, QByteArray> changesHash;
+    changesHash.insert("test.qml", contents);
+    m_inspectorClient->reloadQml(changesHash);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_inspectorClient, SIGNAL(responseReceived())));
+
+    lineNumber = rootObject.source.lineNumber;
+    columnNumber = rootObject.source.columnNumber;
+    success = false;
+    m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
+                                   columnNumber, &success);
+    QVERIFY(success);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
+
+    foreach (QmlDebugObjectReference child, rootObject.children) {
+        success = false;
+        lineNumber = child.source.lineNumber;
+        columnNumber = child.source.columnNumber;
+        m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
+                                       columnNumber, &success);
+        QVERIFY(success);
+        QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
+    }
+}
+
+QTEST_MAIN(tst_QQmlEngineDebugInspectorIntegration)
+
+#include "tst_qqmlenginedebuginspectorintegration.moc"
index 983fdb3..26dba8b 100644 (file)
@@ -2,15 +2,12 @@ CONFIG += testcase
 TARGET = tst_qqmlenginedebugservice
 macx:CONFIG -= app_bundle
 
-HEADERS += \
-    qqmlenginedebugclient.h
-
 SOURCES += \
-    tst_qqmlenginedebugservice.cpp \
-    qqmlenginedebugclient.cpp
+    tst_qqmlenginedebugservice.cpp
 
 INCLUDEPATH += ../shared
 include(../../../shared/util.pri)
+include(../shared/qqmlenginedebugclient.pri)
 include(../shared/debugutil.pri)
 
 DEFINES += QT_QML_DEBUG_NO_WARNING
index 1d42dde..5849d60 100644 (file)
@@ -8,6 +8,7 @@ SOURCES += tst_qqmlinspector.cpp
 
 INCLUDEPATH += ../shared
 include(../../../shared/util.pri)
+include(../shared/qqmlinspectorclient.pri)
 include(../shared/debugutil.pri)
 
 TESTDATA = data/*
index 5326a05..291939d 100644 (file)
 
 #include "../shared/debugutil_p.h"
 #include "../../../shared/util.h"
+#include "qqmlinspectorclient.h"
 
 #define PORT 3772
 #define STR_PORT "3772"
 
-class QQmlInspectorClient : public QQmlDebugClient
-{
-    Q_OBJECT
-
-public:
-    QQmlInspectorClient(QQmlDebugConnection *connection)
-        : QQmlDebugClient(QLatin1String("QmlInspector"), connection)
-        , m_showAppOnTop(false)
-        , m_requestId(0)
-        , m_requestResult(false)
-        , m_responseId(-1)
-    {
-    }
-
-    void setShowAppOnTop(bool showOnTop);
-    void reloadQml(const QHash<QString, QByteArray> &changesHash);
-
-signals:
-    void responseReceived();
 
-protected:
-    void messageReceived(const QByteArray &message);
-
-private:
-    bool m_showAppOnTop;
-    int m_requestId;
-
-public:
-    bool m_requestResult;
-    int m_responseId;
-    int m_reloadRequestId;
-};
 
 class tst_QQmlInspector : public QQmlDataTest
 {
@@ -112,45 +82,6 @@ private slots:
     void reloadQml();
 };
 
-
-void QQmlInspectorClient::setShowAppOnTop(bool showOnTop)
-{
-    QByteArray message;
-    QDataStream ds(&message, QIODevice::WriteOnly);
-    ds << QByteArray("request") << m_requestId++
-       << QByteArray("showAppOnTop") << showOnTop;
-
-    sendMessage(message);
-}
-
-void QQmlInspectorClient::reloadQml(const QHash<QString, QByteArray> &changesHash)
-{
-    QByteArray message;
-    QDataStream ds(&message, QIODevice::WriteOnly);
-    m_reloadRequestId = m_requestId;
-
-    ds << QByteArray("request") << m_requestId++
-       << QByteArray("reload") << changesHash;
-
-    sendMessage(message);
-}
-
-void QQmlInspectorClient::messageReceived(const QByteArray &message)
-{
-    QDataStream ds(message);
-    QByteArray type;
-    ds >> type;
-
-    if (type != QByteArray("response")) {
-        qDebug() << "Unhandled message of type" << type;
-        return;
-    }
-
-    m_requestResult = false;
-    ds >> m_responseId >> m_requestResult;
-    emit responseReceived();
-}
-
 void tst_QQmlInspector::init()
 {
     const QString argument = "-qmljsdebugger=port:"STR_PORT",block";
diff --git a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.pri
new file mode 100644 (file)
index 0000000..a969b4f
--- /dev/null
@@ -0,0 +1,3 @@
+HEADERS += $$PWD/qqmlenginedebugclient.h
+
+SOURCES += $$PWD/qqmlenginedebugclient.cpp
diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp b/tests/auto/qml/debugger/shared/qqmlinspectorclient.cpp
new file mode 100644 (file)
index 0000000..604e970
--- /dev/null
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** 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.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qqmlinspectorclient.h"
+
+void QQmlInspectorClient::setShowAppOnTop(bool showOnTop)
+{
+    QByteArray message;
+    QDataStream ds(&message, QIODevice::WriteOnly);
+    ds << QByteArray("request") << m_requestId++
+       << QByteArray("showAppOnTop") << showOnTop;
+
+    sendMessage(message);
+}
+
+void QQmlInspectorClient::reloadQml(const QHash<QString, QByteArray> &changesHash)
+{
+    QByteArray message;
+    QDataStream ds(&message, QIODevice::WriteOnly);
+    m_reloadRequestId = m_requestId;
+
+    ds << QByteArray("request") << m_requestId++
+       << QByteArray("reload") << changesHash;
+
+    sendMessage(message);
+}
+
+void QQmlInspectorClient::messageReceived(const QByteArray &message)
+{
+    QDataStream ds(message);
+    QByteArray type;
+    ds >> type;
+
+    if (type != QByteArray("response")) {
+        qDebug() << "Unhandled message of type" << type;
+        return;
+    }
+
+    m_requestResult = false;
+    ds >> m_responseId >> m_requestResult;
+    emit responseReceived();
+}
diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.h b/tests/auto/qml/debugger/shared/qqmlinspectorclient.h
new file mode 100644 (file)
index 0000000..5eb543e
--- /dev/null
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** 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.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQMLINSPECTORCLIENT_H
+#define QQMLINSPECTORCLIENT_H
+
+#include "qqmldebugclient.h"
+
+class QQmlInspectorClient : public QQmlDebugClient
+{
+    Q_OBJECT
+
+public:
+    QQmlInspectorClient(QQmlDebugConnection *connection)
+        : QQmlDebugClient(QLatin1String("QmlInspector"), connection)
+        , m_showAppOnTop(false)
+        , m_requestId(0)
+        , m_requestResult(false)
+        , m_responseId(-1)
+    {
+    }
+
+    void setShowAppOnTop(bool showOnTop);
+    void reloadQml(const QHash<QString, QByteArray> &changesHash);
+
+signals:
+    void responseReceived();
+
+protected:
+    void messageReceived(const QByteArray &message);
+
+private:
+    bool m_showAppOnTop;
+    int m_requestId;
+
+public:
+    bool m_requestResult;
+    int m_responseId;
+    int m_reloadRequestId;
+};
+
+#endif // QQMLINSPECTORCLIENT_H
diff --git a/tests/auto/qml/debugger/shared/qqmlinspectorclient.pri b/tests/auto/qml/debugger/shared/qqmlinspectorclient.pri
new file mode 100644 (file)
index 0000000..c136e13
--- /dev/null
@@ -0,0 +1,3 @@
+HEADERS += $$PWD/qqmlinspectorclient.h
+
+SOURCES += $$PWD/qqmlinspectorclient.cpp