From 751c10d1471a8c3ccc81ce47adc642c1f6f0c2f7 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Sat, 15 Oct 2011 17:43:55 +0200 Subject: [PATCH] Debugger: Move debugging autotests into own folder This mirrors the source tree structure and makes it easier to run them all in one go. Change-Id: Ia191790eaec2c409857c41aff479d2ebd144aaf8 Reviewed-by: Kai Koehne --- tests/auto/declarative/debugger/debugger.pro | 12 + .../qdeclarativedebugclient.pro | 12 + .../tst_qdeclarativedebugclient.cpp | 191 +++ .../debugger/qdeclarativedebugjs/data/test.js | 53 + .../debugger/qdeclarativedebugjs/data/test.qml | 86 + .../qdeclarativedebugjs/qdeclarativedebugjs.pro | 20 + .../tst_qdeclarativedebugjs.cpp | 1707 +++++++++++++++++++ .../qdeclarativedebugservice.pro | 11 + .../tst_qdeclarativedebugservice.cpp | 200 +++ .../qdeclarativeenginedebug.pro | 11 + .../tst_qdeclarativeenginedebug.cpp | 1220 ++++++++++++++ .../debugger/qpacketprotocol/qpacketprotocol.pro | 10 + .../qpacketprotocol/tst_qpacketprotocol.cpp | 263 +++ .../auto/declarative/debugger/shared/debugutil.cpp | 104 ++ .../auto/declarative/debugger/shared/debugutil_p.h | 93 ++ tests/auto/declarative/declarative.pro | 7 +- .../qdeclarativedebugclient.pro | 12 - .../tst_qdeclarativedebugclient.cpp | 191 --- .../declarative/qdeclarativedebugjs/data/test.js | 53 - .../declarative/qdeclarativedebugjs/data/test.qml | 86 - .../qdeclarativedebugjs/qdeclarativedebugjs.pro | 20 - .../tst_qdeclarativedebugjs.cpp | 1708 -------------------- .../qdeclarativedebugservice.pro | 11 - .../tst_qdeclarativedebugservice.cpp | 199 --- .../qdeclarativeenginedebug.pro | 11 - .../tst_qdeclarativeenginedebug.cpp | 1220 -------------- .../qpacketprotocol/qpacketprotocol.pro | 10 - .../qpacketprotocol/tst_qpacketprotocol.cpp | 263 --- tests/auto/declarative/shared/debugutil.cpp | 104 -- tests/auto/declarative/shared/debugutil_p.h | 93 -- 30 files changed, 3994 insertions(+), 3987 deletions(-) create mode 100644 tests/auto/declarative/debugger/debugger.pro create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugclient/qdeclarativedebugclient.pro create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.js create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugservice/qdeclarativedebugservice.pro create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp create mode 100644 tests/auto/declarative/debugger/qdeclarativeenginedebug/qdeclarativeenginedebug.pro create mode 100644 tests/auto/declarative/debugger/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp create mode 100644 tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro create mode 100644 tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp create mode 100644 tests/auto/declarative/debugger/shared/debugutil.cpp create mode 100644 tests/auto/declarative/debugger/shared/debugutil_p.h delete mode 100644 tests/auto/declarative/qdeclarativedebugclient/qdeclarativedebugclient.pro delete mode 100644 tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp delete mode 100644 tests/auto/declarative/qdeclarativedebugjs/data/test.js delete mode 100644 tests/auto/declarative/qdeclarativedebugjs/data/test.qml delete mode 100644 tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro delete mode 100644 tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp delete mode 100644 tests/auto/declarative/qdeclarativedebugservice/qdeclarativedebugservice.pro delete mode 100644 tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp delete mode 100644 tests/auto/declarative/qdeclarativeenginedebug/qdeclarativeenginedebug.pro delete mode 100644 tests/auto/declarative/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp delete mode 100644 tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro delete mode 100644 tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp delete mode 100644 tests/auto/declarative/shared/debugutil.cpp delete mode 100644 tests/auto/declarative/shared/debugutil_p.h diff --git a/tests/auto/declarative/debugger/debugger.pro b/tests/auto/declarative/debugger/debugger.pro new file mode 100644 index 0000000..3ea5c41 --- /dev/null +++ b/tests/auto/declarative/debugger/debugger.pro @@ -0,0 +1,12 @@ +TEMPLATE = subdirs + +PRIVATETESTS += \ + qdeclarativeenginedebug \ + qdeclarativedebugclient \ + qdeclarativedebugservice \ +# qdeclarativedebugjs \ + qpacketprotocol + +contains(QT_CONFIG, private_tests) { + SUBDIRS += $$PRIVATETESTS +} diff --git a/tests/auto/declarative/debugger/qdeclarativedebugclient/qdeclarativedebugclient.pro b/tests/auto/declarative/debugger/qdeclarativedebugclient/qdeclarativedebugclient.pro new file mode 100644 index 0000000..850a0d4 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugclient/qdeclarativedebugclient.pro @@ -0,0 +1,12 @@ +CONFIG += testcase +TARGET = tst_qdeclarativedebugclient +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qdeclarativedebugclient.cpp \ + ../shared/debugutil.cpp + +CONFIG += declarative_debug + +QT += core-private gui-private declarative-private network testlib + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp b/tests/auto/declarative/debugger/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp new file mode 100644 index 0000000..55a49c7 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include + +#include + +#include "../../../../shared/util.h" +#include "../shared/debugutil_p.h" + +#define PORT 13770 +#define STR_PORT "13770" + +class tst_QDeclarativeDebugClient : public QObject +{ + Q_OBJECT + +private: + QDeclarativeDebugConnection *m_conn; + +private slots: + void initTestCase(); + + void name(); + void status(); + void sendMessage(); + void parallelConnect(); + void sequentialConnect(); +}; + +void tst_QDeclarativeDebugClient::initTestCase() +{ + const QString waitingMsg = QString("QDeclarativeDebugServer: Waiting for connection on port %1...").arg(PORT); + QTest::ignoreMessage(QtWarningMsg, waitingMsg.toAscii().constData()); + new QDeclarativeEngine(this); + + m_conn = new QDeclarativeDebugConnection(this); + + QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::handshake()", m_conn); + QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::handshake()"); + + m_conn->connectToHost("127.0.0.1", PORT); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); + bool ok = m_conn->waitForConnected(); + QVERIFY(ok); + + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); +} + +void tst_QDeclarativeDebugClient::name() +{ + QString name = "tst_QDeclarativeDebugClient::name()"; + + QDeclarativeDebugClient client(name, m_conn); + QCOMPARE(client.name(), name); +} + +void tst_QDeclarativeDebugClient::status() +{ + { + QDeclarativeDebugConnection dummyConn; + QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::status()", &dummyConn); + QCOMPARE(client.status(), QDeclarativeDebugClient::NotConnected); + } + + QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::status()", m_conn); + QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable); + + { + QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()"); + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); + } + + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Unavailable); + + // duplicate plugin name + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::status()\" "); + QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::status()", m_conn); + QCOMPARE(client2.status(), QDeclarativeDebugClient::NotConnected); + + QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::status3()", 0); + QCOMPARE(client3.status(), QDeclarativeDebugClient::NotConnected); +} + +void tst_QDeclarativeDebugClient::sendMessage() +{ + QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::sendMessage()"); + QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + +void tst_QDeclarativeDebugClient::parallelConnect() +{ + QDeclarativeDebugConnection connection2; + + connection2.connectToHost("127.0.0.1", PORT); + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Another client is already connected"); + // will connect & immediately disconnect + QVERIFY(connection2.waitForConnected()); + QTRY_COMPARE(connection2.state(), QAbstractSocket::UnconnectedState); + QVERIFY(m_conn->isConnected()); +} + +void tst_QDeclarativeDebugClient::sequentialConnect() +{ + QDeclarativeDebugConnection connection2; + QDeclarativeDebugTestClient client2("tst_QDeclarativeDebugClient::handshake()", &connection2); + QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::handshake()"); + + m_conn->close(); + QVERIFY(!m_conn->isConnected()); + QCOMPARE(m_conn->state(), QAbstractSocket::UnconnectedState); + + // Make sure that the disconnect is actually delivered to the server + QGuiApplication::processEvents(); + + connection2.connectToHost("127.0.0.1", PORT); + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); + QVERIFY(connection2.waitForConnected()); + QVERIFY(connection2.isConnected()); + QTRY_VERIFY(client2.status() == QDeclarativeDebugClient::Enabled); +} + +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]; + + _argv[_argc - 1] = "-qmljsdebugger=port:" STR_PORT; + + QGuiApplication app(_argc, _argv); + tst_QDeclarativeDebugClient tc; + return QTest::qExec(&tc, _argc, _argv); + delete _argv; +} + +#include "tst_qdeclarativedebugclient.moc" + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.js b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.js new file mode 100644 index 0000000..230a4ea --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.js @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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$ +** +****************************************************************************/ + +function printMessage(msg) +{ + print(msg); +} + +function add(a,b) +{ + //This is a comment and below is an empty line + + var out = a + b; + return out; +} diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml new file mode 100644 index 0000000..386b366 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "test.js" as Script + +//DO NOT CHANGE + +Rectangle { + id: root + width: 10; height: 10; + Component.onCompleted: print("onCompleted") + + property int result:0 + + property int someValue: 10 + + function doSomething() { + var a = root.result; + var b = commonFunction(); + var c = [1,2,3]; + var d = Script.add(a,c[2]); + result += d; + doSomethingElse(); + } + + Timer { + interval: 4000; running: true; repeat: true + onTriggered: { + doSomething(); + Script.printMessage("onTriggered"); + } + } + + function commonFunction() { + console.log("commonFunction"); + return 5; + } + + function doSomethingElse() { + result = Script.add(result,8); + eval("print(root.result)"); + if (root.result > 15) + dummy(); + } + +} + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro b/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro new file mode 100644 index 0000000..a6f005e --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro @@ -0,0 +1,20 @@ +CONFIG += testcase +TARGET = tst_qdeclarativedebugjs +QT += network script declarative-private testlib +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h + +SOURCES += tst_qdeclarativedebugjs.cpp \ + ../shared/debugutil.cpp + +INCLUDEPATH += ../shared + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + + +CONFIG += parallel_test +#temporary +CONFIG += insignificant_test diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp new file mode 100644 index 0000000..ee40056 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -0,0 +1,1707 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include +#include +#include +#include + +//QDeclarativeDebugTest +#include "../shared/debugutil_p.h" +#include "../../shared/util.h" + +const char *SEQ = "seq"; +const char *TYPE = "type"; +const char *COMMAND = "command"; +const char *ARGUMENTS = "arguments"; +const char *STEPACTION = "stepaction"; +const char *STEPCOUNT = "stepcount"; +const char *EXPRESSION = "expression"; +const char *FRAME = "frame"; +const char *GLOBAL = "global"; +const char *DISABLEBREAK = "disable_break"; +const char *HANDLES = "handles"; +const char *INCLUDESOURCE = "includeSource"; +const char *FROMFRAME = "fromFrame"; +const char *TOFRAME = "toFrame"; +const char *BOTTOM = "bottom"; +const char *NUMBER = "number"; +const char *FRAMENUMBER = "frameNumber"; +const char *TYPES = "types"; +const char *IDS = "ids"; +const char *FILTER = "filter"; +const char *FROMLINE = "fromLine"; +const char *TOLINE = "toLine"; +const char *TARGET = "target"; +const char *LINE = "line"; +const char *COLUMN = "column"; +const char *ENABLED = "enabled"; +const char *CONDITION = "condition"; +const char *IGNORECOUNT = "ignoreCount"; +const char *BREAKPOINT = "breakpoint"; +const char *FLAGS = "flags"; + +const char *CONTINEDEBUGGING = "continue"; +const char *EVALUATE = "evaluate"; +const char *LOOKUP = "lookup"; +const char *BACKTRACE = "backtrace"; +const char *SCOPE = "scope"; +const char *SCOPES = "scopes"; +const char *SCRIPTS = "scripts"; +const char *SOURCE = "source"; +const char *SETBREAKPOINT = "setbreakpoint"; +const char *CHANGEBREAKPOINT = "changebreakpoint"; +const char *CLEARBREAKPOINT = "clearbreakpoint"; +const char *SETEXCEPTIONBREAK = "setexceptionbreak"; +const char *V8FLAGS = "v8flags"; +const char *VERSION = "version"; +const char *DISCONNECT = "disconnect"; +const char *LISTBREAKPOINTS = "listbreakpoints"; +const char *GARBAGECOLLECTOR = "gc"; +//const char *PROFILE = "profile"; + +const char *CONNECT = "connect"; +const char *INTERRUPT = "interrupt"; + +const char *REQUEST = "request"; +const char *IN = "in"; +const char *NEXT = "next"; +const char *OUT = "out"; + +const char *FUNCTION = "function"; +const char *SCRIPT = "script"; + +const char *ALL = "all"; +const char *UNCAUGHT = "uncaught"; + +//const char *PAUSE = "pause"; +//const char *RESUME = "resume"; + +const char *BLOCKMODE = "-qmljsdebugger=port:3771,block"; +const char *NORMALMODE = "-qmljsdebugger=port:3771"; +const char *QMLFILE = "test.qml"; +const char *JSFILE = "test.js"; + +#define VARIANTMAPINIT \ + QString obj("{}"); \ + QJSValue jsonVal = parser.call(QJSValue(), QJSValueList() << obj); \ + jsonVal.setProperty(SEQ,QJSValue(seq++)); \ + jsonVal.setProperty(TYPE,REQUEST); + +class QJSDebugProcess; +class QJSDebugClient; + +class tst_QDeclarativeDebugJS : public QObject +{ + Q_OBJECT + +private slots: + + void initTestCase(); + void cleanupTestCase(); + + void init(); + void cleanup(); + + void getVersion(); + + void applyV8Flags(); + + void disconnect(); + + void gc(); + + void listBreakpoints(); + + void setBreakpointInScriptOnCompleted(); + void setBreakpointInScriptOnTimerCallback(); + void setBreakpointInScriptInDifferentFile(); + void setBreakpointInScriptOnComment(); + void setBreakpointInScriptOnEmptyLine(); + void setBreakpointInScriptWithCondition(); + //void setBreakpointInFunction(); //NOT SUPPORTED + + void changeBreakpoint(); + void changeBreakpointOnCondition(); + + void clearBreakpoint(); + + void setExceptionBreak(); + + void stepNext(); + void stepNextWithCount(); + void stepIn(); + void stepOut(); + void continueDebugging(); + + void backtrace(); + + void getFrameDetails(); + + void getScopeDetails(); + + void evaluateInGlobalScope(); + void evaluateInLocalScope(); + + void getScopes(); + + void getScripts(); + + void getSource(); + + // void profile(); //NOT SUPPORTED + + // void verifyQMLOptimizerDisabled(); + +private: + QJSDebugProcess *process; + QJSDebugClient *client; + QDeclarativeDebugConnection *connection; +}; + +class QJSDebugProcess : public QObject +{ + Q_OBJECT +public: + QJSDebugProcess(); + ~QJSDebugProcess(); + + void start(const QStringList &arguments); + bool waitForSessionStart(); + +private slots: + void processAppOutput(); + +private: + void stop(); + +private: + QProcess m_process; + QTimer m_timer; + QEventLoop m_eventLoop; + QMutex m_mutex; + bool m_started; +}; + +QJSDebugProcess::QJSDebugProcess() + : m_started(false) +{ + m_process.setProcessChannelMode(QProcess::MergedChannels); + m_timer.setSingleShot(true); + m_timer.setInterval(5000); + connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput())); + connect(&m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit())); + +// QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); +// env.insert("QML_DISABLE_OPTIMIZER", "1"); // Add an environment variable +// m_process.setProcessEnvironment(env); + +} + +QJSDebugProcess::~QJSDebugProcess() +{ + stop(); +} + +void QJSDebugProcess::start(const QStringList &arguments) +{ + m_mutex.lock(); + m_process.start(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", arguments); + m_process.waitForStarted(); + m_timer.start(); + m_mutex.unlock(); +} + +void QJSDebugProcess::stop() +{ + if (m_process.state() != QProcess::NotRunning) { + m_process.terminate(); + m_process.waitForFinished(5000); + } +} + +bool QJSDebugProcess::waitForSessionStart() +{ + m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents); + + return m_started; +} + +void QJSDebugProcess::processAppOutput() +{ + m_mutex.lock(); + const QString appOutput = m_process.readAll(); + static QRegExp newline("[\n\r]{1,2}"); + QStringList lines = appOutput.split(newline); + foreach (const QString &line, lines) { + if (line.isEmpty()) + continue; + if (line.startsWith("Qml debugging is enabled")) // ignore + continue; + if (line.startsWith("QDeclarativeDebugServer:")) { + if (line.contains("Waiting for connection ")) { + m_started = true; + m_eventLoop.quit(); + continue; + } + if (line.contains("Connection established")) { + continue; + } + } +// qWarning() << line; + } + m_mutex.unlock(); +} + +class QJSDebugClient : public QDeclarativeDebugClient +{ + Q_OBJECT +public: + enum StepAction + { + Continue, + In, + Out, + Next + }; + + enum Exception + { + All, + Uncaught + }; + +// enum ProfileCommand +// { +// Pause, +// Resume +// }; + + QJSDebugClient(QDeclarativeDebugConnection *connection) + : QDeclarativeDebugClient(QLatin1String("V8Debugger"), connection), + seq(0) + { + parser = jsEngine.evaluate(QLatin1String("JSON.parse")); + stringify = jsEngine.evaluate(QLatin1String("JSON.stringify")); + } + + void startDebugging(); + void interrupt(); + + void continueDebugging(StepAction stepAction, int stepCount = 1); + void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); + void lookup(QList handles, bool includeSource = false); + void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); + void frame(int number = -1); + void scope(int number = -1, int frameNumber = -1); + void scopes(int frameNumber = -1); + void scripts(int types = 4, QList ids = QList(), bool includeSource = false, QVariant filter = QVariant()); + void source(int frame = -1, int fromLine = -1, int toLine = -1); + void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = true, QString condition = QString(), int ignoreCount = -1); + void changeBreakpoint(int breakpoint, bool enabled = true, QString condition = QString(), int ignoreCount = -1); + void clearBreakpoint(int breakpoint); + void setExceptionBreak(Exception type, bool enabled = false); + void v8flags(QString flags); + void version(); + //void profile(ProfileCommand command); //NOT SUPPORTED + void disconnect(); + void gc(); + void listBreakpoints(); + +protected: + //inherited from QDeclarativeDebugClient + void statusChanged(Status status); + void messageReceived(const QByteArray &data); + +signals: + void enabled(); + void breakpointSet(); + void result(); + void stopped(); + +private: + void sendMessage(const QByteArray &); + void flushSendBuffer(); + QByteArray packMessage(QByteArray message); + +private: + QJSEngine jsEngine; + int seq; + + QList sendBuffer; + +public: + QJSValue parser; + QJSValue stringify; + QByteArray response; + +}; + +void QJSDebugClient::startDebugging() +{ + // { "seq" : , + // "type" : "request", + // "command" : "connect", + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONNECT))); + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::interrupt() +{ + // { "seq" : , + // "type" : "request", + // "command" : "interrupt", + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(INTERRUPT))); + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::continueDebugging(StepAction action, int count) +{ + // { "seq" : , + // "type" : "request", + // "command" : "continue", + // "arguments" : { "stepaction" : <"in", "next" or "out">, + // "stepcount" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONTINEDEBUGGING))); + + if (action != Continue) { + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + switch (action) { + case In: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(IN))); + break; + case Out: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(OUT))); + break; + case Next: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(NEXT))); + break; + default:break; + } + if (args.isValid()) { + if (count != 1) + args.setProperty(QLatin1String(STEPCOUNT),QJSValue(count)); + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + } + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::evaluate(QString expr, bool global, bool disableBreak, int frame, const QVariantMap &/*addContext*/) +{ + // { "seq" : , + // "type" : "request", + // "command" : "evaluate", + // "arguments" : { "expression" : , + // "frame" : , + // "global" : , + // "disable_break" : , + // "additional_context" : [ + // { "name" : , "handle" : }, + // { "name" : , "handle" : }, + // ... + // ] + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(EVALUATE))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + args.setProperty(QLatin1String(EXPRESSION),QJSValue(expr)); + + if (frame != -1) + args.setProperty(QLatin1String(FRAME),QJSValue(frame)); + + if (global) + args.setProperty(QLatin1String(GLOBAL),QJSValue(global)); + + if (disableBreak) + args.setProperty(QLatin1String(DISABLEBREAK),QJSValue(disableBreak)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::lookup(QList handles, bool includeSource) +{ + // { "seq" : , + // "type" : "request", + // "command" : "lookup", + // "arguments" : { "handles" : , + // "includeSource" : , + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LOOKUP))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + QString arr("[]"); + QJSValue array = parser.call(QJSValue(), QJSValueList() << arr); + int index = 0; + foreach (int handle, handles) { + array.setProperty(index++,QJSValue(handle)); + } + args.setProperty(QLatin1String(HANDLES),array); + + if (includeSource) + args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::backtrace(int fromFrame, int toFrame, bool bottom) +{ + // { "seq" : , + // "type" : "request", + // "command" : "backtrace", + // "arguments" : { "fromFrame" : + // "toFrame" : + // "bottom" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(BACKTRACE))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + if (fromFrame != -1) + args.setProperty(QLatin1String(FROMFRAME),QJSValue(fromFrame)); + + if (toFrame != -1) + args.setProperty(QLatin1String(TOFRAME),QJSValue(toFrame)); + + if (bottom) + args.setProperty(QLatin1String(BOTTOM),QJSValue(bottom)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::frame(int number) +{ + // { "seq" : , + // "type" : "request", + // "command" : "frame", + // "arguments" : { "number" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(FRAME))); + + if (number != -1) { + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + args.setProperty(QLatin1String(NUMBER),QJSValue(number)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::scope(int number, int frameNumber) +{ + // { "seq" : , + // "type" : "request", + // "command" : "scope", + // "arguments" : { "number" : + // "frameNumber" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPE))); + + if (number != -1) { + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + args.setProperty(QLatin1String(NUMBER),QJSValue(number)); + + if (frameNumber != -1) + args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::scopes(int frameNumber) +{ + // { "seq" : , + // "type" : "request", + // "command" : "scopes", + // "arguments" : { "frameNumber" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPES))); + + if (frameNumber != -1) { + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::scripts(int types, QList ids, bool includeSource, QVariant /*filter*/) +{ + // { "seq" : , + // "type" : "request", + // "command" : "scripts", + // "arguments" : { "types" : + // "ids" : + // "includeSource" : + // "filter" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCRIPTS))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + args.setProperty(QLatin1String(TYPES),QJSValue(types)); + + if (ids.count()) { + QString arr("[]"); + QJSValue array = parser.call(QJSValue(), QJSValueList() << arr); + int index = 0; + foreach (int id, ids) { + array.setProperty(index++,QJSValue(id)); + } + args.setProperty(QLatin1String(IDS),array); + } + + if (includeSource) + args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::source(int frame, int fromLine, int toLine) +{ + // { "seq" : , + // "type" : "request", + // "command" : "source", + // "arguments" : { "frame" : + // "fromLine" : + // "toLine" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SOURCE))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + if (frame != -1) + args.setProperty(QLatin1String(FRAME),QJSValue(frame)); + + if (fromLine != -1) + args.setProperty(QLatin1String(FROMLINE),QJSValue(fromLine)); + + if (toLine != -1) + args.setProperty(QLatin1String(TOLINE),QJSValue(toLine)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::setBreakpoint(QString type, QString target, int line, int column, bool enabled, QString condition, int ignoreCount) +{ + // { "seq" : , + // "type" : "request", + // "command" : "setbreakpoint", + // "arguments" : { "type" : <"function" or "script" or "scriptId" or "scriptRegExp"> + // "target" : + // "line" : + // "column" : + // "enabled" : + // "condition" : + // "ignoreCount" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETBREAKPOINT))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + args.setProperty(QLatin1String(TYPE),QJSValue(type)); + args.setProperty(QLatin1String(TARGET),QJSValue(target)); + + if (line != -1) + args.setProperty(QLatin1String(LINE),QJSValue(line)); + + if (column != -1) + args.setProperty(QLatin1String(COLUMN),QJSValue(column)); + + args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); + + if (!condition.isEmpty()) + args.setProperty(QLatin1String(CONDITION),QJSValue(condition)); + + if (ignoreCount != -1) + args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::changeBreakpoint(int breakpoint, bool enabled, QString condition, int ignoreCount) +{ + // { "seq" : , + // "type" : "request", + // "command" : "changebreakpoint", + // "arguments" : { "breakpoint" : + // "enabled" : + // "condition" : + // "ignoreCount" : , + // "type" : "request", + // "command" : "clearbreakpoint", + // "arguments" : { "breakpoint" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CLEARBREAKPOINT))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + args.setProperty(QLatin1String(BREAKPOINT),QJSValue(breakpoint)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::setExceptionBreak(Exception type, bool enabled) +{ + // { "seq" : , + // "type" : "request", + // "command" : "setexceptionbreak", + // "arguments" : { "type" : , + // "enabled" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETEXCEPTIONBREAK))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + if (type == All) + args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(ALL))); + else if (type == Uncaught) + args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(UNCAUGHT))); + + if (enabled) + args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::v8flags(QString flags) +{ + // { "seq" : , + // "type" : "request", + // "command" : "v8flags", + // "arguments" : { "flags" : + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(V8FLAGS))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + args.setProperty(QLatin1String(FLAGS),QJSValue(flags)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::version() +{ + // { "seq" : , + // "type" : "request", + // "command" : "version", + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(VERSION))); + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +//void QJSDebugClient::profile(ProfileCommand command) +//{ +//// { "seq" : , +//// "type" : "request", +//// "command" : "profile", +//// "arguments" : { "command" : "resume" or "pause" } +//// } +// VARIANTMAPINIT; +// jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PROFILE))); + +// QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + +// if (command == Resume) +// args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(RESUME))); +// else +// args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PAUSE))); + +// args.setProperty(QLatin1String("modules"),QJSValue(1)); +// if (args.isValid()) { +// jsonVal.setProperty(QLatin1String(ARGUMENTS),args); +// } + +// QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); +// sendMessage(packMessage(json.toString().toUtf8())); +//} + +void QJSDebugClient::disconnect() +{ + // { "seq" : , + // "type" : "request", + // "command" : "disconnect", + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(DISCONNECT))); + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::gc() +{ + // { "seq" : , + // "type" : "request", + // "command" : "gc", + // "arguments" : { "type" : , + // } + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(GARBAGECOLLECTOR))); + + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + + args.setProperty(QLatin1String(FLAGS),QJSValue(QLatin1String(ALL))); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::listBreakpoints() +{ + // { "seq" : , + // "type" : "request", + // "command" : "listbreakpoints", + // } + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LISTBREAKPOINTS))); + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(json.toString().toUtf8())); +} + +void QJSDebugClient::statusChanged(Status status) +{ + if (status == Enabled) { + flushSendBuffer(); + emit enabled(); + } +} + +void QJSDebugClient::messageReceived(const QByteArray &data) +{ + QDataStream ds(data); + QByteArray command; + ds >> command; + + if (command == "V8DEBUG") { + ds >> response; + QString jsonString(response); + QVariantMap value = parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString type = value.value("type").toString(); + + if (type == "response") { + + if (!value.value("success").toBool()) { + qDebug() << "Error: The test case will fail since no signal is emitted"; + return; + } + + QString debugCommand(value.value("command").toString()); + if (debugCommand == "backtrace" || + debugCommand == "lookup" || + debugCommand == "setbreakpoint" || + debugCommand == "evaluate" || + debugCommand == "listbreakpoints" || + debugCommand == "version" || + debugCommand == "v8flags" || + debugCommand == "disconnect" || + debugCommand == "gc" || + debugCommand == "changebreakpoint" || + debugCommand == "clearbreakpoint" || + debugCommand == "frame" || + debugCommand == "scope" || + debugCommand == "scopes" || + debugCommand == "scripts" || + debugCommand == "source" || + debugCommand == "setexceptionbreak" /*|| + debugCommand == "profile"*/) { + emit result(); + + } else { + // DO NOTHING + } + + } else if (type == "event") { + QString event(value.value("event").toString()); + + if (event == "break" || + event == "exception") { + emit stopped(); + } + } + } +} + +void QJSDebugClient::sendMessage(const QByteArray &msg) +{ + if (status() == Enabled) { + QDeclarativeDebugClient::sendMessage(msg); + } else { + sendBuffer.append(msg); + } +} + +void QJSDebugClient::flushSendBuffer() +{ + foreach (const QByteArray &msg, sendBuffer) + QDeclarativeDebugClient::sendMessage(msg); + sendBuffer.clear(); +} + +QByteArray QJSDebugClient::packMessage(QByteArray message) +{ + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + QByteArray cmd = "V8DEBUG"; + rs << cmd << message; + return reply; +} + +void tst_QDeclarativeDebugJS::initTestCase() +{ + process = 0; + client = 0; + connection = 0; +} + +void tst_QDeclarativeDebugJS::cleanupTestCase() +{ + if (process) + delete process; + + if (client) + delete client; + + if (connection) + delete connection; +} + +void tst_QDeclarativeDebugJS::init() +{ + connection = new QDeclarativeDebugConnection(); + process = new QJSDebugProcess(); + client = new QJSDebugClient(connection); + + process->start(QStringList() << QLatin1String(BLOCKMODE) << TESTDATA(QLatin1String(QMLFILE))); + QVERIFY(process->waitForSessionStart()); + + connection->connectToHost("127.0.0.1", 3771); + QVERIFY(connection->waitForConnected()); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(enabled()))); +} + +void tst_QDeclarativeDebugJS::cleanup() +{ + if (process) + delete process; + + if (client) + delete client; + + if (connection) + delete connection; + + process = 0; + client = 0; + connection = 0; +} + +void tst_QDeclarativeDebugJS::getVersion() +{ + //void version() + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->version(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::applyV8Flags() +{ + //void v8flags(QString flags) + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->v8flags(QString()); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::disconnect() +{ + //void disconnect() + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->disconnect(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::gc() +{ + //void gc() + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), 2, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->gc(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::listBreakpoints() +{ + //void listBreakpoints() + + int sourceLine1 = 57; + int sourceLine2 = 60; + int sourceLine3 = 67; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine3, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->listBreakpoints(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QList breakpoints = value.value("body").toMap().value("breakpoints").toList(); + + QCOMPARE(breakpoints.count(), 3); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine = 49; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine = 67; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine = 43; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine = 48; + int actualLine = 50; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), actualLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine = 49; + int actualLine = 50; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), actualLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); +} + +void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int out = 10; + int sourceLine = 51; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true, QLatin1String("out > 10")); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + //Get the frame index + QString jsonString = client->response; + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + int frameIndex = body.value("index").toInt(); + + //Verify the value of 'result' + client->evaluate(QLatin1String("out"),frameIndex); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QVERIFY(body.value("value").toInt() > out); +} + +//void tst_QDeclarativeDebugJS::setBreakpointInFunction() +//{ +// //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + +// int actualLine = 31; + +// client->startDebugging(); +// client->setBreakpoint(QLatin1String(FUNCTION), QLatin1String("doSomethingElse"), -1, -1, true); + +// QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + +// QString jsonString(client->response); +// QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + +// QVariantMap body = value.value("body").toMap(); + +// QCOMPARE(body.value("sourceLine").toInt(), actualLine); +// QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +//} + +void tst_QDeclarativeDebugJS::changeBreakpoint() +{ + //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine1 = 77; + int sourceLine2 = 78; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + //Will hit 1st brakpoint, change this breakpoint enable = false + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + QList breakpointsHit = body.value("breakpoints").toList(); + + int breakpoint = breakpointsHit.at(0).toInt(); + client->changeBreakpoint(breakpoint,false); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Hit 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Should stop at 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); +} + +void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() +{ + //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + int sourceLine1 = 56; + int sourceLine2 = 60; + int result = 0; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + //Will hit 1st brakpoint, change this breakpoint enable = false + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + QList breakpointsHit = body.value("breakpoints").toList(); + + int breakpoint = breakpointsHit.at(0).toInt(); + client->changeBreakpoint(breakpoint,false,QLatin1String("a = 0")); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Hit 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Should stop at 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); + + client->frame(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Get the frame index + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + int frameIndex = body.value("index").toInt(); + + //Verify the value of 'result' + client->evaluate(QLatin1String("root.result"),frameIndex); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QVERIFY(body.value("value").toInt() > result); +} + +void tst_QDeclarativeDebugJS::clearBreakpoint() +{ + //void clearBreakpoint(int breakpoint); + + int sourceLine1 = 77; + int sourceLine2 = 78; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + //Will hit 1st brakpoint, change this breakpoint enable = false + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + QList breakpointsHit = body.value("breakpoints").toList(); + + int breakpoint = breakpointsHit.at(0).toInt(); + client->changeBreakpoint(breakpoint,false,QLatin1String("result > 5")); + + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Hit 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + //Continue with debugging + client->continueDebugging(QJSDebugClient::Continue); + //Should stop at 2nd breakpoint + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); +} + +void tst_QDeclarativeDebugJS::setExceptionBreak() +{ + //void setExceptionBreak(QString type, bool enabled = false); + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->setExceptionBreak(QJSDebugClient::All,true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + client->continueDebugging(QJSDebugClient::Continue); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); +} + +void tst_QDeclarativeDebugJS::stepNext() +{ + //void continueDebugging(StepAction stepAction, int stepCount = 1); + + int sourceLine = 57; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->continueDebugging(QJSDebugClient::Next); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 1); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::stepNextWithCount() +{ + //void continueDebugging(StepAction stepAction, int stepCount = 1); + + int sourceLine = 59; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->continueDebugging(QJSDebugClient::Next,2); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 2); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::stepIn() +{ + //void continueDebugging(StepAction stepAction, int stepCount = 1); + + int sourceLine = 67; + int actualLine = 56; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->continueDebugging(QJSDebugClient::In); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), actualLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::stepOut() +{ + //void continueDebugging(StepAction stepAction, int stepCount = 1); + + int sourceLine = 56; + int actualLine = 68; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->continueDebugging(QJSDebugClient::Out); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), actualLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::continueDebugging() +{ + //void continueDebugging(StepAction stepAction, int stepCount = 1); + + int sourceLine1 = 56; + int sourceLine2 = 60; + + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->continueDebugging(QJSDebugClient::Continue); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); +} + +void tst_QDeclarativeDebugJS::backtrace() +{ + //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); + + int sourceLine = 60; + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->backtrace(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::getFrameDetails() +{ + //void frame(int number = -1); + + int sourceLine = 60; + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->frame(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::getScopeDetails() +{ + //void scope(int number = -1, int frameNumber = -1); + + int sourceLine = 60; + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->scope(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::evaluateInGlobalScope() +{ + //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); + + int sourceLine = 49; + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->evaluate(QLatin1String("print('Hello World')"),true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Verify the value of 'print' + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("text").toString(),QLatin1String("undefined")); +} + +void tst_QDeclarativeDebugJS::evaluateInLocalScope() +{ + //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); + + int sourceLine = 60; + client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->frame(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Get the frame index + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + int frameIndex = body.value("index").toInt(); + + client->evaluate(QLatin1String("root.someValue"),frameIndex); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + + //Verify the value of 'root.someValue' + jsonString = client->response; + value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + body = value.value("body").toMap(); + + QCOMPARE(body.value("value").toInt(),10); +} + +void tst_QDeclarativeDebugJS::getScopes() +{ + //void scopes(int frameNumber = -1); + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->scopes(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::getScripts() +{ + //void scripts(int types = -1, QList ids = QList(), bool includeSource = false, QVariant filter = QVariant()); + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->scripts(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +void tst_QDeclarativeDebugJS::getSource() +{ + //void source(int frame = -1, int fromLine = -1, int toLine = -1); + + client->interrupt(); + client->startDebugging(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + client->source(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); +} + +QTEST_MAIN(tst_QDeclarativeDebugJS) + +#include "tst_qdeclarativedebugjs.moc" + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugservice/qdeclarativedebugservice.pro b/tests/auto/declarative/debugger/qdeclarativedebugservice/qdeclarativedebugservice.pro new file mode 100644 index 0000000..c23e920 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugservice/qdeclarativedebugservice.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qdeclarativedebugservice +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qdeclarativedebugservice.cpp \ + ../shared/debugutil.cpp + +CONFIG += parallel_test declarative_debug + +QT += core-private gui-private declarative-private network testlib diff --git a/tests/auto/declarative/debugger/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp b/tests/auto/declarative/debugger/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp new file mode 100644 index 0000000..91e06ce --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "../../../../shared/util.h" +#include "../../shared/util.h" +#include "../shared/debugutil_p.h" + + +class tst_QDeclarativeDebugService : public QObject +{ + Q_OBJECT +private: + QDeclarativeDebugConnection *m_conn; + +private slots: + void initTestCase(); + + void name(); + void status(); + void sendMessage(); + void idForObject(); + void objectForId(); + void objectToString(); +}; + +void tst_QDeclarativeDebugService::initTestCase() +{ + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 13769..."); + new QDeclarativeEngine(this); + + m_conn = new QDeclarativeDebugConnection(this); + m_conn->connectToHost("127.0.0.1", 13769); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); + bool ok = m_conn->waitForConnected(); + QVERIFY(ok); + + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); +} + +void tst_QDeclarativeDebugService::name() +{ + QString name = "tst_QDeclarativeDebugService::name()"; + + QDeclarativeDebugService service(name); + QCOMPARE(service.name(), name); +} + +void tst_QDeclarativeDebugService::status() +{ + QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::status()"); + QCOMPARE(service.status(), QDeclarativeDebugService::Unavailable); + + { + QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::status()", m_conn); + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); + QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled); + } + + + QTRY_COMPARE(service.status(), QDeclarativeDebugService::Unavailable); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::status()\" "); + + QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::status()"); + QCOMPARE(duplicate.status(), QDeclarativeDebugService::NotConnected); +} + +void tst_QDeclarativeDebugService::sendMessage() +{ + QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::sendMessage()"); + QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); + QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled); + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::sendMessage()\" "); + QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::sendMessage()"); + duplicate.sendMessage("msg"); +} + +void tst_QDeclarativeDebugService::idForObject() +{ + QCOMPARE(QDeclarativeDebugService::idForObject(0), -1); + + QObject *objA = new QObject; + + int idA = QDeclarativeDebugService::idForObject(objA); + QVERIFY(idA >= 0); + QCOMPARE(QDeclarativeDebugService::objectForId(idA), objA); + + int idAA = QDeclarativeDebugService::idForObject(objA); + QCOMPARE(idAA, idA); + + QObject *objB = new QObject; + int idB = QDeclarativeDebugService::idForObject(objB); + QVERIFY(idB != idA); + QCOMPARE(QDeclarativeDebugService::objectForId(idB), objB); + + delete objA; + delete objB; +} + +void tst_QDeclarativeDebugService::objectForId() +{ + QCOMPARE(QDeclarativeDebugService::objectForId(-1), static_cast(0)); + QCOMPARE(QDeclarativeDebugService::objectForId(1), static_cast(0)); + + QObject *obj = new QObject; + int id = QDeclarativeDebugService::idForObject(obj); + QCOMPARE(QDeclarativeDebugService::objectForId(id), obj); + + delete obj; + QCOMPARE(QDeclarativeDebugService::objectForId(id), static_cast(0)); +} + +void tst_QDeclarativeDebugService::objectToString() +{ + QCOMPARE(QDeclarativeDebugService::objectToString(0), QString("NULL")); + + QObject *obj = new QObject; + QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: ")); + + obj->setObjectName("Hello"); + QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: Hello")); + delete obj; +} + + +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]; + char arg[] = "-qmljsdebugger=port:13769"; + _argv[_argc - 1] = arg; + + QGuiApplication app(_argc, _argv); + tst_QDeclarativeDebugService tc; + return QTest::qExec(&tc, _argc, _argv); + delete _argv; +} + +#include "tst_qdeclarativedebugservice.moc" diff --git a/tests/auto/declarative/debugger/qdeclarativeenginedebug/qdeclarativeenginedebug.pro b/tests/auto/declarative/debugger/qdeclarativeenginedebug/qdeclarativeenginedebug.pro new file mode 100644 index 0000000..98736c6 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativeenginedebug/qdeclarativeenginedebug.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qdeclarativeenginedebug +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qdeclarativeenginedebug.cpp \ + ../shared/debugutil.cpp + +CONFIG += parallel_test declarative_debug + +QT += core-private gui-private v8-private declarative-private network testlib diff --git a/tests/auto/declarative/debugger/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp b/tests/auto/declarative/debugger/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp new file mode 100644 index 0000000..7ef2ee1 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp @@ -0,0 +1,1220 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "../../../../shared/util.h" +#include "../shared/debugutil_p.h" + +Q_DECLARE_METATYPE(QDeclarativeDebugWatch::State) + +class tst_QDeclarativeEngineDebug : public QObject +{ + Q_OBJECT + +private: + QDeclarativeDebugObjectReference findRootObject(int context = 0, bool recursive = false); + QDeclarativeDebugPropertyReference findProperty(const QList &props, const QString &name) const; + void waitForQuery(QDeclarativeDebugQuery *query); + + void recursiveObjectTest(QObject *o, const QDeclarativeDebugObjectReference &oref, bool recursive) const; + + void recursiveCompareObjects(const QDeclarativeDebugObjectReference &a, const QDeclarativeDebugObjectReference &b) const; + void recursiveCompareContexts(const QDeclarativeDebugContextReference &a, const QDeclarativeDebugContextReference &b) const; + void compareProperties(const QDeclarativeDebugPropertyReference &a, const QDeclarativeDebugPropertyReference &b) const; + + QDeclarativeDebugConnection *m_conn; + QDeclarativeEngineDebug *m_dbg; + QDeclarativeEngine *m_engine; + QSGItem *m_rootItem; + + 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(); + + void tst_QDeclarativeDebugFileReference(); + void tst_QDeclarativeDebugEngineReference(); + void tst_QDeclarativeDebugObjectReference(); + void tst_QDeclarativeDebugContextReference(); + void tst_QDeclarativeDebugPropertyReference(); + + 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) + + +QDeclarativeDebugObjectReference tst_QDeclarativeEngineDebug::findRootObject(int context, bool recursive) +{ + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + if (q_engines->engines().count() == 0) + return QDeclarativeDebugObjectReference(); + QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + if (q_context->rootContext().objects().count() == 0) + return QDeclarativeDebugObjectReference(); + QDeclarativeDebugObjectQuery *q_obj = recursive ? + m_dbg->queryObjectRecursive(q_context->rootContext().objects()[context], this) : + m_dbg->queryObject(q_context->rootContext().objects()[context], this); + waitForQuery(q_obj); + + QDeclarativeDebugObjectReference result = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + return result; +} + +QDeclarativeDebugPropertyReference tst_QDeclarativeEngineDebug::findProperty(const QList &props, const QString &name) const +{ + foreach(const QDeclarativeDebugPropertyReference &p, props) { + if (p.name() == name) + return p; + } + return QDeclarativeDebugPropertyReference(); +} + +void tst_QDeclarativeEngineDebug::waitForQuery(QDeclarativeDebugQuery *query) +{ + QVERIFY(query); + QCOMPARE(query->parent(), qobject_cast(this)); + QVERIFY(query->state() == QDeclarativeDebugQuery::Waiting); + if (!QDeclarativeDebugTest::waitForSignal(query, SIGNAL(stateChanged(QDeclarativeDebugQuery::State)))) + QFAIL("query timed out"); +} + +void tst_QDeclarativeEngineDebug::recursiveObjectTest(QObject *o, const QDeclarativeDebugObjectReference &oref, bool recursive) const +{ + const QMetaObject *meta = o->metaObject(); + + QDeclarativeType *type = QDeclarativeMetaType::qmlType(meta); + QString className = type ? QString(type->qmlTypeName()) : QString(meta->className()); + className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); + + QCOMPARE(oref.debugId(), QDeclarativeDebugService::idForObject(o)); + QCOMPARE(oref.name(), o->objectName()); + QCOMPARE(oref.className(), className); + QCOMPARE(oref.contextDebugId(), QDeclarativeDebugService::idForObject(qmlContext(o))); + + const QObjectList &children = o->children(); + for (int i=0; i= 0); + + QDeclarativeDebugObjectReference cref; + foreach (const QDeclarativeDebugObjectReference &ref, oref.children()) { + if (ref.debugId() == debugId) { + cref = ref; + break; + } + } + QVERIFY(cref.debugId() >= 0); + + if (recursive) + recursiveObjectTest(child, cref, true); + } + + foreach (const QDeclarativeDebugPropertyReference &p, oref.properties()) { + QCOMPARE(p.objectDebugId(), QDeclarativeDebugService::idForObject(o)); + + // signal properties are fake - they are generated from QDeclarativeBoundSignal children + if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { + QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); + QVERIFY(p.valueTypeName().isEmpty()); + QVERIFY(p.binding().isEmpty()); + QVERIFY(!p.hasNotifySignal()); + continue; + } + + QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); + + QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); + + if (pmeta.type() < QVariant::UserType) // TODO test complex types + QCOMPARE(p.value(), pmeta.read(o)); + + if (p.name() == "parent") + QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QSGItem*"); + else + QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); + + QDeclarativeAbstractBinding *binding = + QDeclarativePropertyPrivate::binding(QDeclarativeProperty(o, p.name())); + if (binding) + QCOMPARE(binding->expression(), p.binding()); + + QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + + QVERIFY(pmeta.isValid()); + } +} + +void tst_QDeclarativeEngineDebug::recursiveCompareObjects(const QDeclarativeDebugObjectReference &a, const QDeclarativeDebugObjectReference &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(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768..."); + m_engine = new QDeclarativeEngine(this); + + QList qml; + qml << "import QtQuick 2.0\n" + "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" + "Component.onCompleted: {\n" + "varObj = blueRect;\n" + "var list = varObjList;\n" + "list[0] = blueRect;\n" + "varObjList = list;\n" + "}\n" + "NonScriptPropertyElement {\n" + "}\n" + "}"; + + // add second component to test multiple root contexts + qml << "import QtQuick 2.0\n" + "Item {}"; + + // and a third to test methods + qml << "import QtQuick 2.0\n" + "Item {" + "function myMethodNoArgs() { return 3; }\n" + "function myMethod(a) { return a + 9; }\n" + "function myMethodIndirect() { myMethod(3); }\n" + "}"; + + // and a fourth to test states + qml << "import QtQuick 2.0\n" + "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(component.create()); + } + m_rootItem = qobject_cast(m_components.first()); + + // add an extra context to test for multiple contexts + QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this); + context->setObjectName("tst_QDeclarativeDebug_childContext"); + + m_conn = new QDeclarativeDebugConnection(this); + m_conn->connectToHost("127.0.0.1", 3768); + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); + bool ok = m_conn->waitForConnected(); + QVERIFY(ok); + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); + m_dbg = new QDeclarativeEngineDebug(m_conn, this); + QTRY_VERIFY(m_dbg->status() == QDeclarativeEngineDebug::Enabled); +} + +void tst_QDeclarativeEngineDebug::cleanupTestCase() +{ + delete m_dbg; + delete m_conn; + qDeleteAll(m_components); + delete m_engine; +} + +void tst_QDeclarativeEngineDebug::setMethodBody() +{ + QDeclarativeDebugObjectReference obj = findRootObject(2); + + 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))); + } +} + +void tst_QDeclarativeEngineDebug::watch_property() +{ + QDeclarativeDebugObjectReference obj = findRootObject(); + QDeclarativeDebugPropertyReference prop = findProperty(obj.properties(), "width"); + + QDeclarativeDebugPropertyWatch *watch; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + watch = unconnected->addWatch(prop, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); + delete watch; + delete unconnected; + + watch = m_dbg->addWatch(QDeclarativeDebugPropertyReference(), this); + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(prop, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->name(), prop.name()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + + int origWidth = m_rootItem->property("width").toInt(); + m_rootItem->setProperty("width", origWidth*2); + + // stateChanged() is received before valueChanged() + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); + QCOMPARE(spy.count(), 1); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get additional signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.at(0).at(0).value(), prop.name().toUtf8()); + QCOMPARE(spy.at(0).at(1).value(), qVariantFromValue(origWidth*2)); +} + +void tst_QDeclarativeEngineDebug::watch_object() +{ + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QVERIFY(q_engines->engines().count() > 0); + QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + QVERIFY(q_context->rootContext().objects().count() > 0); + QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); + waitForQuery(q_obj); + + QDeclarativeDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + QDeclarativeDebugWatch *watch; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + watch = unconnected->addWatch(obj, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); + delete watch; + delete unconnected; + + watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), this); + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + + int origWidth = m_rootItem->property("width").toInt(); + int origHeight = m_rootItem->property("height").toInt(); + m_rootItem->setProperty("width", origWidth*2); + m_rootItem->setProperty("height", origHeight*2); + + // stateChanged() is received before any valueChanged() signals + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); + QVERIFY(spy.count() > 0); + + int newWidth = -1; + int newHeight = -1; + for (int i=0; i() == "width") + newWidth = values[1].value().toInt(); + else if (values[0].value() == "height") + newHeight = values[1].value().toInt(); + + } + + m_dbg->removeWatch(watch); + delete watch; + + // since watch has been removed, restoring the original values should not trigger a valueChanged() + spy.clear(); + m_rootItem->setProperty("width", origWidth); + m_rootItem->setProperty("height", origHeight); + QTest::qWait(100); + QCOMPARE(spy.count(), 0); + + QCOMPARE(newWidth, origWidth * 2); + QCOMPARE(newHeight, origHeight * 2); +} + +void tst_QDeclarativeEngineDebug::watch_expression() +{ + QFETCH(QString, expr); + QFETCH(int, increment); + QFETCH(int, incrementCount); + + int origWidth = m_rootItem->property("width").toInt(); + + QDeclarativeDebugObjectReference obj = findRootObject(); + + QDeclarativeDebugObjectExpressionWatch *watch; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + watch = unconnected->addWatch(obj, expr, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); + delete watch; + delete unconnected; + + watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), expr, this); + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, expr, this); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->expression(), expr); + + QSignalSpy spyState(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State))); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value + + int width = origWidth; + for (int i=0; i 0) { + width += increment; + m_rootItem->setProperty("width", width); + } + if (!QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) + QFAIL("Did not receive valueChanged() for expression"); + } + + if (spyState.count() == 0) + QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); + QCOMPARE(spyState.count(), 1); + QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get a signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), expectedSpyCount); + + width = origWidth + increment; + for (int i=0; i().toInt(), width); + width += increment; + } +} + +void tst_QDeclarativeEngineDebug::watch_expression_data() +{ + QTest::addColumn("expr"); + QTest::addColumn("increment"); + QTest::addColumn("incrementCount"); + + QTest::newRow("width") << "width" << 0 << 0; + QTest::newRow("width+10") << "width + 10" << 10 << 5; +} + +void tst_QDeclarativeEngineDebug::watch_context() +{ + QDeclarativeDebugContextReference c; + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(c, QString(), this)); +} + +void tst_QDeclarativeEngineDebug::watch_file() +{ + QDeclarativeDebugFileReference f; + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(f, this)); +} + +void tst_QDeclarativeEngineDebug::queryAvailableEngines() +{ + QDeclarativeDebugEnginesQuery *q_engines; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + q_engines = unconnected->queryAvailableEngines(0); + QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Error); + 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 + QList engines = q_engines->engines(); + QCOMPARE(engines.count(), 1); + + foreach(const QDeclarativeDebugEngineReference &e, engines) { + QCOMPARE(e.debugId(), QDeclarativeDebugService::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(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Error); + delete q_engines; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); +} + +void tst_QDeclarativeEngineDebug::queryRootContexts() +{ + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + int engineId = q_engines->engines()[0].debugId(); + delete q_engines; + + QDeclarativeDebugRootContextQuery *q_context; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + q_context = unconnected->queryRootContexts(engineId, this); + QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error); + 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); + + QDeclarativeContext *actualContext = m_engine->rootContext(); + QDeclarativeDebugContextReference context = q_context->rootContext(); + QCOMPARE(context.debugId(), QDeclarativeDebugService::idForObject(actualContext)); + QCOMPARE(context.name(), actualContext->objectName()); + + QCOMPARE(context.objects().count(), 4); // 4 qml component objects created for context in main() + + // root context query sends only root object data - it doesn't fill in + // the children or property info + QCOMPARE(context.objects()[0].properties().count(), 0); + QCOMPARE(context.objects()[0].children().count(), 0); + + QCOMPARE(context.contexts().count(), 5); + QVERIFY(context.contexts()[0].debugId() >= 0); + QCOMPARE(context.contexts()[0].name(), QString("tst_QDeclarativeDebug_childContext")); + + // Make query invalid by deleting client + q_context = m_dbg->queryRootContexts(engineId, this); + QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error); + delete q_context; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); +} + +void tst_QDeclarativeEngineDebug::queryObject() +{ + QFETCH(bool, recursive); + + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[0]; + + QDeclarativeDebugObjectQuery *q_obj = 0; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + q_obj = recursive ? unconnected->queryObjectRecursive(rootObject, this) : unconnected->queryObject(rootObject, this); + QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Error); + 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); + + QDeclarativeDebugObjectReference 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(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Error); + delete q_obj; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); + + // check source as defined in main() + QDeclarativeDebugFileReference 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 QDeclarativeDebugObjectReference &child, obj.children()) + QVERIFY(child.properties().count() > 0); + + QDeclarativeDebugObjectReference rect; + QDeclarativeDebugObjectReference text; + foreach (const QDeclarativeDebugObjectReference &child, obj.children()) { + if (child.className() == "Rectangle") + rect = child; + else if (child.className() == "Text") + text = child; + } + + // test specific property values + QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500)); + QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600)); + QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + + QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + } else { + foreach(const QDeclarativeDebugObjectReference &child, obj.children()) + QCOMPARE(child.properties().count(), 0); + } +} + +void tst_QDeclarativeEngineDebug::queryObject_data() +{ + QTest::addColumn("recursive"); + + QTest::newRow("non-recursive") << false; + QTest::newRow("recursive") << true; +} + +void tst_QDeclarativeEngineDebug::queryExpressionResult() +{ + QFETCH(QString, expr); + QFETCH(QVariant, result); + + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); // check immediate deletion is ok + + QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + int objectId = q_context->rootContext().objects()[0].debugId(); + + QDeclarativeDebugExpressionQuery *q_expr; + + QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); + q_expr = unconnected->queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error); + delete q_expr; + 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); + + 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(), QDeclarativeDebugQuery::Waiting); + delete m_dbg; + QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error); + delete q_expr; + m_dbg = new QDeclarativeEngineDebug(m_conn, this); +} + +void tst_QDeclarativeEngineDebug::queryExpressionResult_data() +{ + QTest::addColumn("expr"); + QTest::addColumn("result"); + + QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); + QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); + QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); + QTest::newRow("QObject*") << "varObj" << qVariantFromValue(QString("")); + QTest::newRow("list of QObject*") << "varObjList" << qVariantFromValue(QString("")); +} + +void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugFileReference() +{ + QDeclarativeDebugFileReference 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); + + QDeclarativeDebugFileReference copy(ref); + QDeclarativeDebugFileReference copyAssign; + copyAssign = ref; + foreach (const QDeclarativeDebugFileReference &r, (QList() << copy << copyAssign)) { + QCOMPARE(r.url(), ref.url()); + QCOMPARE(r.lineNumber(), ref.lineNumber()); + QCOMPARE(r.columnNumber(), ref.columnNumber()); + } +} + +void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugEngineReference() +{ + QDeclarativeDebugEngineReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + + ref = QDeclarativeDebugEngineReference(1); + QCOMPARE(ref.debugId(), 1); + QVERIFY(ref.name().isEmpty()); + + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + ref = q_engines->engines()[0]; + delete q_engines; + + QDeclarativeDebugEngineReference copy(ref); + QDeclarativeDebugEngineReference copyAssign; + copyAssign = ref; + foreach (const QDeclarativeDebugEngineReference &r, (QList() << copy << copyAssign)) { + QCOMPARE(r.debugId(), ref.debugId()); + QCOMPARE(r.name(), ref.name()); + } +} + +void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugObjectReference() +{ + QDeclarativeDebugObjectReference 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()); + + QDeclarativeDebugFileReference source = ref.source(); + QVERIFY(source.url().isEmpty()); + QVERIFY(source.lineNumber() < 0); + QVERIFY(source.columnNumber() < 0); + + ref = QDeclarativeDebugObjectReference(1); + QCOMPARE(ref.debugId(), 1); + + QDeclarativeDebugObjectReference rootObject = findRootObject(); + QDeclarativeDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); + waitForQuery(query); + ref = query->object(); + delete query; + + QVERIFY(ref.debugId() >= 0); + + QDeclarativeDebugObjectReference copy(ref); + QDeclarativeDebugObjectReference copyAssign; + copyAssign = ref; + foreach (const QDeclarativeDebugObjectReference &r, (QList() << copy << copyAssign)) + recursiveCompareObjects(r, ref); +} + +void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugContextReference() +{ + QDeclarativeDebugContextReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + QVERIFY(ref.objects().isEmpty()); + QVERIFY(ref.contexts().isEmpty()); + + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + QDeclarativeDebugRootContextQuery *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); + + QDeclarativeDebugContextReference copy(ref); + QDeclarativeDebugContextReference copyAssign; + copyAssign = ref; + foreach (const QDeclarativeDebugContextReference &r, (QList() << copy << copyAssign)) + recursiveCompareContexts(r, ref); +} + +void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugPropertyReference() +{ + QDeclarativeDebugObjectReference rootObject = findRootObject(); + QDeclarativeDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); + waitForQuery(query); + QDeclarativeDebugObjectReference obj = query->object(); + delete query; + + QDeclarativeDebugPropertyReference 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()); + + QDeclarativeDebugPropertyReference copy(ref); + QDeclarativeDebugPropertyReference copyAssign; + copyAssign = ref; + foreach (const QDeclarativeDebugPropertyReference &r, (QList() << copy << copyAssign)) + compareProperties(r, ref); +} + +void tst_QDeclarativeEngineDebug::setBindingForObject() +{ + QDeclarativeDebugObjectReference rootObject = findRootObject(); + QVERIFY(rootObject.debugId() != -1); + QDeclarativeDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties(), "width"); + + 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(); + QCOMPARE(rootObject.children().size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement + QDeclarativeDebugObjectReference mouseAreaObject = rootObject.children().at(2); + QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); + waitForQuery(q_obj); + mouseAreaObject = q_obj->object(); + + QCOMPARE(mouseAreaObject.className(), QString("MouseArea")); + + QDeclarativeDebugPropertyReference onEnteredRef = findProperty(mouseAreaObject.properties(), "onEntered"); + + QCOMPARE(onEnteredRef.name(), QString("onEntered")); + QCOMPARE(onEnteredRef.value(), QVariant("{ console.log('hello') }")); + + 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') }")); +} + +void tst_QDeclarativeEngineDebug::setBindingInStates() +{ + // Check if changing bindings of propertychanges works + + const int sourceIndex = 3; + + QDeclarativeDebugObjectReference obj = findRootObject(sourceIndex); + + 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 + QDeclarativeDebugExpressionQuery *q_deleteTransition = m_dbg->queryExpressionResult(obj.debugId(),QString("transitions = []"),this); + waitForQuery(q_deleteTransition); + delete q_deleteTransition; + + + // check initial value of the property that is changing + QDeclarativeDebugExpressionQuery *q_setState; + 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 + QDeclarativeDebugObjectReference state = obj.children()[1]; + QCOMPARE(state.className(), QString("State")); + QVERIFY(state.children().count() > 0); + + QDeclarativeDebugObjectReference propertyChange = state.children()[0]; + 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); +} + +void tst_QDeclarativeEngineDebug::queryObjectTree() +{ + const int sourceIndex = 3; + + // Check if states/transitions are initialized when fetching root item + QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + QVERIFY(q_context->rootContext().objects().count() > sourceIndex); + QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[sourceIndex]; + + QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this); + waitForQuery(q_obj); + + QDeclarativeDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + QVERIFY(obj.debugId() != -1); + QVERIFY(obj.children().count() >= 2); + + + + // check state + QDeclarativeDebugObjectReference state = obj.children()[1]; + QCOMPARE(state.className(), QString("State")); + QVERIFY(state.children().count() > 0); + + QDeclarativeDebugObjectReference propertyChange = state.children()[0]; + QVERIFY(propertyChange.debugId() != -1); + + QDeclarativeDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties(),"target"); + QCOMPARE(propertyChangeTarget.objectDebugId(), propertyChange.debugId()); + + QDeclarativeDebugObjectReference targetReference = qvariant_cast(propertyChangeTarget.value()); + QVERIFY(targetReference.debugId() != -1); + + + + // check transition + QDeclarativeDebugObjectReference 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); + + QDeclarativeDebugObjectReference animation = transition.children()[0]; + QVERIFY(animation.debugId() != -1); + + QDeclarativeDebugPropertyReference animationTarget = findProperty(animation.properties(),"target"); + QCOMPARE(animationTarget.objectDebugId(), animation.debugId()); + + 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); +} + +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]; + char arg[] = "-qmljsdebugger=port:3768"; + _argv[_argc - 1] = arg; + + QGuiApplication app(_argc, _argv); + tst_QDeclarativeEngineDebug tc; + return QTest::qExec(&tc, _argc, _argv); + delete _argv; +} + +#include "tst_qdeclarativeenginedebug.moc" diff --git a/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro new file mode 100644 index 0000000..076ab98 --- /dev/null +++ b/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qpacketprotocol +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qpacketprotocol.cpp \ + ../shared/debugutil.cpp + +CONFIG += parallel_test +QT += core-private gui-private v8-private declarative-private network testlib diff --git a/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp new file mode 100644 index 0000000..87fa12f --- /dev/null +++ b/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp @@ -0,0 +1,263 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include +#include + +#include + +#include "../shared/debugutil_p.h" + +class tst_QPacketProtocol : public QObject +{ + Q_OBJECT + +private: + QTcpServer *m_server; + QTcpSocket *m_client; + QTcpSocket *m_serverConn; + +private slots: + void init(); + void cleanup(); + + void maximumPacketSize(); + void setMaximumPacketSize(); + void setMaximumPacketSize_data(); + void send(); + void send_data(); + void packetsAvailable(); + void packetsAvailable_data(); + void clear(); + void read(); + void device(); + + void tst_QPacket_clear(); +}; + +void tst_QPacketProtocol::init() +{ + m_server = new QTcpServer(this); + m_serverConn = 0; + QVERIFY(m_server->listen(QHostAddress("127.0.0.1"))); + + m_client = new QTcpSocket(this); + m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); + + QVERIFY(m_client->waitForConnected()); + QVERIFY(m_server->waitForNewConnection()); + m_serverConn = m_server->nextPendingConnection(); +} + +void tst_QPacketProtocol::cleanup() +{ + delete m_client; + delete m_serverConn; + delete m_server; +} + +void tst_QPacketProtocol::maximumPacketSize() +{ + QPacketProtocol p(m_client); + QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); +} + +void tst_QPacketProtocol::setMaximumPacketSize() +{ + QFETCH(qint32, size); + QFETCH(qint32, expected); + + QPacketProtocol out(m_serverConn); + QCOMPARE(out.setMaximumPacketSize(size), expected); +} + +void tst_QPacketProtocol::setMaximumPacketSize_data() +{ + QTest::addColumn("size"); + QTest::addColumn("expected"); + + QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); + QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); + QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); +} + +void tst_QPacketProtocol::send() +{ + QFETCH(bool, useAutoSend); + + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QByteArray ba; + int num; + + if (useAutoSend) { + out.send() << "Hello world" << 123; + } else { + QPacket packet; + packet << "Hello world" << 123; + out.send(packet); + } + + QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p = in.read(); + p >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world") + '\0'); + QCOMPARE(num, 123); +} + +void tst_QPacketProtocol::send_data() +{ + QTest::addColumn("useAutoSend"); + + QTest::newRow("auto send") << true; + QTest::newRow("no auto send") << false; +} + +void tst_QPacketProtocol::packetsAvailable() +{ + QFETCH(int, packetCount); + + QPacketProtocol out(m_client); + QPacketProtocol in(m_serverConn); + + QCOMPARE(out.packetsAvailable(), qint64(0)); + QCOMPARE(in.packetsAvailable(), qint64(0)); + + for (int i=0; i("packetCount"); + + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("10") << 10; +} + +void tst_QPacketProtocol::clear() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + out.send() << 123; + out.send() << 456; + QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + in.clear(); + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::read() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QVERIFY(in.read().isEmpty()); + + out.send() << 123; + out.send() << 456; + QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + int num; + + QPacket p1 = in.read(); + QVERIFY(!p1.isEmpty()); + p1 >> num; + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + QVERIFY(!p2.isEmpty()); + p2 >> num; + QCOMPARE(num, 456); + + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::device() +{ + QPacketProtocol p(m_client); + QVERIFY(p.device() == m_client); +} + +void tst_QPacketProtocol::tst_QPacket_clear() +{ + QPacketProtocol protocol(m_client); + + QPacket packet; + + packet << "Hello world!" << 123; + protocol.send(packet); + + packet.clear(); + QVERIFY(packet.isEmpty()); + packet << "Goodbyte world!" << 789; + protocol.send(packet); + + QByteArray ba; + int num; + QPacketProtocol in(m_serverConn); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p1 = in.read(); + p1 >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world!") + '\0'); + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + p2 >> ba >> num; + QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); + QCOMPARE(num, 789); +} + +QTEST_MAIN(tst_QPacketProtocol) + +#include "tst_qpacketprotocol.moc" diff --git a/tests/auto/declarative/debugger/shared/debugutil.cpp b/tests/auto/declarative/debugger/shared/debugutil.cpp new file mode 100644 index 0000000..99f8dcc --- /dev/null +++ b/tests/auto/declarative/debugger/shared/debugutil.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include + +#include +#include + +#include "debugutil_p.h" + + +bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { + QEventLoop loop; + QTimer timer; + timer.setSingleShot(true); + QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + QObject::connect(receiver, member, &loop, SLOT(quit())); + timer.start(timeout); + loop.exec(); + return timer.isActive(); +} + +QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent) + : QDeclarativeDebugService(s, parent) +{ +} + +void QDeclarativeDebugTestService::messageReceived(const QByteArray &ba) +{ + sendMessage(ba); +} + +void QDeclarativeDebugTestService::statusChanged(Status) +{ + emit statusHasChanged(); +} + + +QDeclarativeDebugTestClient::QDeclarativeDebugTestClient(const QString &s, QDeclarativeDebugConnection *c) + : QDeclarativeDebugClient(s, c) +{ +} + +QByteArray QDeclarativeDebugTestClient::waitForResponse() +{ + lastMsg.clear(); + QDeclarativeDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); + if (lastMsg.isEmpty()) { + qWarning() << "tst_QDeclarativeDebugClient: no response from server!"; + return QByteArray(); + } + return lastMsg; +} + +void QDeclarativeDebugTestClient::statusChanged(Status stat) +{ + QCOMPARE(stat, status()); + emit statusHasChanged(); +} + +void QDeclarativeDebugTestClient::messageReceived(const QByteArray &ba) +{ + lastMsg = ba; + emit serverMessage(ba); +} diff --git a/tests/auto/declarative/debugger/shared/debugutil_p.h b/tests/auto/declarative/debugger/shared/debugutil_p.h new file mode 100644 index 0000000..be8df86 --- /dev/null +++ b/tests/auto/declarative/debugger/shared/debugutil_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +class QDeclarativeDebugTest +{ +public: + static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); +}; + +class QDeclarativeDebugTestService : public QDeclarativeDebugService +{ + Q_OBJECT +public: + QDeclarativeDebugTestService(const QString &s, QObject *parent = 0); + +signals: + void statusHasChanged(); + +protected: + virtual void messageReceived(const QByteArray &ba); + virtual void statusChanged(Status status); +}; + +class QDeclarativeDebugTestClient : public QDeclarativeDebugClient +{ + Q_OBJECT +public: + QDeclarativeDebugTestClient(const QString &s, QDeclarativeDebugConnection *c); + + QByteArray waitForResponse(); + +signals: + void statusHasChanged(); + void serverMessage(const QByteArray &); + +protected: + virtual void statusChanged(Status status); + virtual void messageReceived(const QByteArray &ba); + +private: + QByteArray lastMsg; +}; + + diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 7193182..831061d 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -35,10 +35,6 @@ PRIVATETESTS += \ qdeclarativebinding \ qdeclarativechangeset \ qdeclarativeconnection \ - qdeclarativeenginedebug \ - qdeclarativedebugclient \ - qdeclarativedebugservice \ -# qdeclarativedebugjs \ qdeclarativeecmascript \ qdeclarativeexpression \ qdeclarativefontloader \ @@ -61,7 +57,6 @@ PRIVATETESTS += \ qdeclarativevaluetypes \ qdeclarativeworkerscript \ qdeclarativexmllistmodel \ - qpacketprotocol \ v4 # This test requires the xmlpatterns module @@ -96,8 +91,8 @@ SGTESTS = \ SUBDIRS += $$PUBLICTESTS - SUBDIRS += $$METATYPETESTS +SUBDIRS += debugger contains(QT_CONFIG, private_tests) { SUBDIRS += $$PRIVATETESTS diff --git a/tests/auto/declarative/qdeclarativedebugclient/qdeclarativedebugclient.pro b/tests/auto/declarative/qdeclarativedebugclient/qdeclarativedebugclient.pro deleted file mode 100644 index 850a0d4..0000000 --- a/tests/auto/declarative/qdeclarativedebugclient/qdeclarativedebugclient.pro +++ /dev/null @@ -1,12 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativedebugclient -macx:CONFIG -= app_bundle - -HEADERS += ../shared/debugutil_p.h -SOURCES += tst_qdeclarativedebugclient.cpp \ - ../shared/debugutil.cpp - -CONFIG += declarative_debug - -QT += core-private gui-private declarative-private network testlib - diff --git a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp deleted file mode 100644 index 220669a..0000000 --- a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include - -#include - -#include "../../../shared/util.h" -#include "../shared/debugutil_p.h" - -#define PORT 13770 -#define STR_PORT "13770" - -class tst_QDeclarativeDebugClient : public QObject -{ - Q_OBJECT - -private: - QDeclarativeDebugConnection *m_conn; - -private slots: - void initTestCase(); - - void name(); - void status(); - void sendMessage(); - void parallelConnect(); - void sequentialConnect(); -}; - -void tst_QDeclarativeDebugClient::initTestCase() -{ - const QString waitingMsg = QString("QDeclarativeDebugServer: Waiting for connection on port %1...").arg(PORT); - QTest::ignoreMessage(QtWarningMsg, waitingMsg.toAscii().constData()); - new QDeclarativeEngine(this); - - m_conn = new QDeclarativeDebugConnection(this); - - QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::handshake()", m_conn); - QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::handshake()"); - - m_conn->connectToHost("127.0.0.1", PORT); - - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); - bool ok = m_conn->waitForConnected(); - QVERIFY(ok); - - QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); -} - -void tst_QDeclarativeDebugClient::name() -{ - QString name = "tst_QDeclarativeDebugClient::name()"; - - QDeclarativeDebugClient client(name, m_conn); - QCOMPARE(client.name(), name); -} - -void tst_QDeclarativeDebugClient::status() -{ - { - QDeclarativeDebugConnection dummyConn; - QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::status()", &dummyConn); - QCOMPARE(client.status(), QDeclarativeDebugClient::NotConnected); - } - - QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::status()", m_conn); - QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable); - - { - QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()"); - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); - } - - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Unavailable); - - // duplicate plugin name - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::status()\" "); - QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::status()", m_conn); - QCOMPARE(client2.status(), QDeclarativeDebugClient::NotConnected); - - QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::status3()", 0); - QCOMPARE(client3.status(), QDeclarativeDebugClient::NotConnected); -} - -void tst_QDeclarativeDebugClient::sendMessage() -{ - QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::sendMessage()"); - QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); -} - -void tst_QDeclarativeDebugClient::parallelConnect() -{ - QDeclarativeDebugConnection connection2; - - connection2.connectToHost("127.0.0.1", PORT); - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Another client is already connected"); - // will connect & immediately disconnect - QVERIFY(connection2.waitForConnected()); - QTRY_COMPARE(connection2.state(), QAbstractSocket::UnconnectedState); - QVERIFY(m_conn->isConnected()); -} - -void tst_QDeclarativeDebugClient::sequentialConnect() -{ - QDeclarativeDebugConnection connection2; - QDeclarativeDebugTestClient client2("tst_QDeclarativeDebugClient::handshake()", &connection2); - QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::handshake()"); - - m_conn->close(); - QVERIFY(!m_conn->isConnected()); - QCOMPARE(m_conn->state(), QAbstractSocket::UnconnectedState); - - // Make sure that the disconnect is actually delivered to the server - QGuiApplication::processEvents(); - - connection2.connectToHost("127.0.0.1", PORT); - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); - QVERIFY(connection2.waitForConnected()); - QVERIFY(connection2.isConnected()); - QTRY_VERIFY(client2.status() == QDeclarativeDebugClient::Enabled); -} - -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]; - - _argv[_argc - 1] = "-qmljsdebugger=port:" STR_PORT; - - QGuiApplication app(_argc, _argv); - tst_QDeclarativeDebugClient tc; - return QTest::qExec(&tc, _argc, _argv); - delete _argv; -} - -#include "tst_qdeclarativedebugclient.moc" - diff --git a/tests/auto/declarative/qdeclarativedebugjs/data/test.js b/tests/auto/declarative/qdeclarativedebugjs/data/test.js deleted file mode 100644 index 230a4ea..0000000 --- a/tests/auto/declarative/qdeclarativedebugjs/data/test.js +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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$ -** -****************************************************************************/ - -function printMessage(msg) -{ - print(msg); -} - -function add(a,b) -{ - //This is a comment and below is an empty line - - var out = a + b; - return out; -} diff --git a/tests/auto/declarative/qdeclarativedebugjs/data/test.qml b/tests/auto/declarative/qdeclarativedebugjs/data/test.qml deleted file mode 100644 index 386b366..0000000 --- a/tests/auto/declarative/qdeclarativedebugjs/data/test.qml +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import "test.js" as Script - -//DO NOT CHANGE - -Rectangle { - id: root - width: 10; height: 10; - Component.onCompleted: print("onCompleted") - - property int result:0 - - property int someValue: 10 - - function doSomething() { - var a = root.result; - var b = commonFunction(); - var c = [1,2,3]; - var d = Script.add(a,c[2]); - result += d; - doSomethingElse(); - } - - Timer { - interval: 4000; running: true; repeat: true - onTriggered: { - doSomething(); - Script.printMessage("onTriggered"); - } - } - - function commonFunction() { - console.log("commonFunction"); - return 5; - } - - function doSomethingElse() { - result = Script.add(result,8); - eval("print(root.result)"); - if (root.result > 15) - dummy(); - } - -} - diff --git a/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro b/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro deleted file mode 100644 index a6f005e..0000000 --- a/tests/auto/declarative/qdeclarativedebugjs/qdeclarativedebugjs.pro +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativedebugjs -QT += network script declarative-private testlib -macx:CONFIG -= app_bundle - -HEADERS += ../shared/debugutil_p.h - -SOURCES += tst_qdeclarativedebugjs.cpp \ - ../shared/debugutil.cpp - -INCLUDEPATH += ../shared - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - - -CONFIG += parallel_test -#temporary -CONFIG += insignificant_test diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp deleted file mode 100644 index fbc1ff6..0000000 --- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ /dev/null @@ -1,1708 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include -#include -#include -#include - -//QDeclarativeDebugTest -#include "../../../shared/util.h" -#include "../shared/debugutil_p.h" -#include "../shared/util.h" - -const char *SEQ = "seq"; -const char *TYPE = "type"; -const char *COMMAND = "command"; -const char *ARGUMENTS = "arguments"; -const char *STEPACTION = "stepaction"; -const char *STEPCOUNT = "stepcount"; -const char *EXPRESSION = "expression"; -const char *FRAME = "frame"; -const char *GLOBAL = "global"; -const char *DISABLEBREAK = "disable_break"; -const char *HANDLES = "handles"; -const char *INCLUDESOURCE = "includeSource"; -const char *FROMFRAME = "fromFrame"; -const char *TOFRAME = "toFrame"; -const char *BOTTOM = "bottom"; -const char *NUMBER = "number"; -const char *FRAMENUMBER = "frameNumber"; -const char *TYPES = "types"; -const char *IDS = "ids"; -const char *FILTER = "filter"; -const char *FROMLINE = "fromLine"; -const char *TOLINE = "toLine"; -const char *TARGET = "target"; -const char *LINE = "line"; -const char *COLUMN = "column"; -const char *ENABLED = "enabled"; -const char *CONDITION = "condition"; -const char *IGNORECOUNT = "ignoreCount"; -const char *BREAKPOINT = "breakpoint"; -const char *FLAGS = "flags"; - -const char *CONTINEDEBUGGING = "continue"; -const char *EVALUATE = "evaluate"; -const char *LOOKUP = "lookup"; -const char *BACKTRACE = "backtrace"; -const char *SCOPE = "scope"; -const char *SCOPES = "scopes"; -const char *SCRIPTS = "scripts"; -const char *SOURCE = "source"; -const char *SETBREAKPOINT = "setbreakpoint"; -const char *CHANGEBREAKPOINT = "changebreakpoint"; -const char *CLEARBREAKPOINT = "clearbreakpoint"; -const char *SETEXCEPTIONBREAK = "setexceptionbreak"; -const char *V8FLAGS = "v8flags"; -const char *VERSION = "version"; -const char *DISCONNECT = "disconnect"; -const char *LISTBREAKPOINTS = "listbreakpoints"; -const char *GARBAGECOLLECTOR = "gc"; -//const char *PROFILE = "profile"; - -const char *CONNECT = "connect"; -const char *INTERRUPT = "interrupt"; - -const char *REQUEST = "request"; -const char *IN = "in"; -const char *NEXT = "next"; -const char *OUT = "out"; - -const char *FUNCTION = "function"; -const char *SCRIPT = "script"; - -const char *ALL = "all"; -const char *UNCAUGHT = "uncaught"; - -//const char *PAUSE = "pause"; -//const char *RESUME = "resume"; - -const char *BLOCKMODE = "-qmljsdebugger=port:3771,block"; -const char *NORMALMODE = "-qmljsdebugger=port:3771"; -const char *QMLFILE = "test.qml"; -const char *JSFILE = "test.js"; - -#define VARIANTMAPINIT \ - QString obj("{}"); \ - QJSValue jsonVal = parser.call(QJSValue(), QJSValueList() << obj); \ - jsonVal.setProperty(SEQ,QJSValue(seq++)); \ - jsonVal.setProperty(TYPE,REQUEST); - -class QJSDebugProcess; -class QJSDebugClient; - -class tst_QDeclarativeDebugJS : public QObject -{ - Q_OBJECT - -private slots: - - void initTestCase(); - void cleanupTestCase(); - - void init(); - void cleanup(); - - void getVersion(); - - void applyV8Flags(); - - void disconnect(); - - void gc(); - - void listBreakpoints(); - - void setBreakpointInScriptOnCompleted(); - void setBreakpointInScriptOnTimerCallback(); - void setBreakpointInScriptInDifferentFile(); - void setBreakpointInScriptOnComment(); - void setBreakpointInScriptOnEmptyLine(); - void setBreakpointInScriptWithCondition(); - //void setBreakpointInFunction(); //NOT SUPPORTED - - void changeBreakpoint(); - void changeBreakpointOnCondition(); - - void clearBreakpoint(); - - void setExceptionBreak(); - - void stepNext(); - void stepNextWithCount(); - void stepIn(); - void stepOut(); - void continueDebugging(); - - void backtrace(); - - void getFrameDetails(); - - void getScopeDetails(); - - void evaluateInGlobalScope(); - void evaluateInLocalScope(); - - void getScopes(); - - void getScripts(); - - void getSource(); - - // void profile(); //NOT SUPPORTED - - // void verifyQMLOptimizerDisabled(); - -private: - QJSDebugProcess *process; - QJSDebugClient *client; - QDeclarativeDebugConnection *connection; -}; - -class QJSDebugProcess : public QObject -{ - Q_OBJECT -public: - QJSDebugProcess(); - ~QJSDebugProcess(); - - void start(const QStringList &arguments); - bool waitForSessionStart(); - -private slots: - void processAppOutput(); - -private: - void stop(); - -private: - QProcess m_process; - QTimer m_timer; - QEventLoop m_eventLoop; - QMutex m_mutex; - bool m_started; -}; - -QJSDebugProcess::QJSDebugProcess() - : m_started(false) -{ - m_process.setProcessChannelMode(QProcess::MergedChannels); - m_timer.setSingleShot(true); - m_timer.setInterval(5000); - connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput())); - connect(&m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit())); - -// QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); -// env.insert("QML_DISABLE_OPTIMIZER", "1"); // Add an environment variable -// m_process.setProcessEnvironment(env); - -} - -QJSDebugProcess::~QJSDebugProcess() -{ - stop(); -} - -void QJSDebugProcess::start(const QStringList &arguments) -{ - m_mutex.lock(); - m_process.start(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", arguments); - m_process.waitForStarted(); - m_timer.start(); - m_mutex.unlock(); -} - -void QJSDebugProcess::stop() -{ - if (m_process.state() != QProcess::NotRunning) { - m_process.terminate(); - m_process.waitForFinished(5000); - } -} - -bool QJSDebugProcess::waitForSessionStart() -{ - m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents); - - return m_started; -} - -void QJSDebugProcess::processAppOutput() -{ - m_mutex.lock(); - const QString appOutput = m_process.readAll(); - static QRegExp newline("[\n\r]{1,2}"); - QStringList lines = appOutput.split(newline); - foreach (const QString &line, lines) { - if (line.isEmpty()) - continue; - if (line.startsWith("Qml debugging is enabled")) // ignore - continue; - if (line.startsWith("QDeclarativeDebugServer:")) { - if (line.contains("Waiting for connection ")) { - m_started = true; - m_eventLoop.quit(); - continue; - } - if (line.contains("Connection established")) { - continue; - } - } -// qWarning() << line; - } - m_mutex.unlock(); -} - -class QJSDebugClient : public QDeclarativeDebugClient -{ - Q_OBJECT -public: - enum StepAction - { - Continue, - In, - Out, - Next - }; - - enum Exception - { - All, - Uncaught - }; - -// enum ProfileCommand -// { -// Pause, -// Resume -// }; - - QJSDebugClient(QDeclarativeDebugConnection *connection) - : QDeclarativeDebugClient(QLatin1String("V8Debugger"), connection), - seq(0) - { - parser = jsEngine.evaluate(QLatin1String("JSON.parse")); - stringify = jsEngine.evaluate(QLatin1String("JSON.stringify")); - } - - void startDebugging(); - void interrupt(); - - void continueDebugging(StepAction stepAction, int stepCount = 1); - void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - void lookup(QList handles, bool includeSource = false); - void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); - void frame(int number = -1); - void scope(int number = -1, int frameNumber = -1); - void scopes(int frameNumber = -1); - void scripts(int types = 4, QList ids = QList(), bool includeSource = false, QVariant filter = QVariant()); - void source(int frame = -1, int fromLine = -1, int toLine = -1); - void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = true, QString condition = QString(), int ignoreCount = -1); - void changeBreakpoint(int breakpoint, bool enabled = true, QString condition = QString(), int ignoreCount = -1); - void clearBreakpoint(int breakpoint); - void setExceptionBreak(Exception type, bool enabled = false); - void v8flags(QString flags); - void version(); - //void profile(ProfileCommand command); //NOT SUPPORTED - void disconnect(); - void gc(); - void listBreakpoints(); - -protected: - //inherited from QDeclarativeDebugClient - void statusChanged(Status status); - void messageReceived(const QByteArray &data); - -signals: - void enabled(); - void breakpointSet(); - void result(); - void stopped(); - -private: - void sendMessage(const QByteArray &); - void flushSendBuffer(); - QByteArray packMessage(QByteArray message); - -private: - QJSEngine jsEngine; - int seq; - - QList sendBuffer; - -public: - QJSValue parser; - QJSValue stringify; - QByteArray response; - -}; - -void QJSDebugClient::startDebugging() -{ - // { "seq" : , - // "type" : "request", - // "command" : "connect", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONNECT))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::interrupt() -{ - // { "seq" : , - // "type" : "request", - // "command" : "interrupt", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(INTERRUPT))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::continueDebugging(StepAction action, int count) -{ - // { "seq" : , - // "type" : "request", - // "command" : "continue", - // "arguments" : { "stepaction" : <"in", "next" or "out">, - // "stepcount" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONTINEDEBUGGING))); - - if (action != Continue) { - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - switch (action) { - case In: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(IN))); - break; - case Out: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(OUT))); - break; - case Next: args.setProperty(QLatin1String(STEPACTION),QJSValue(QLatin1String(NEXT))); - break; - default:break; - } - if (args.isValid()) { - if (count != 1) - args.setProperty(QLatin1String(STEPCOUNT),QJSValue(count)); - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - } - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::evaluate(QString expr, bool global, bool disableBreak, int frame, const QVariantMap &/*addContext*/) -{ - // { "seq" : , - // "type" : "request", - // "command" : "evaluate", - // "arguments" : { "expression" : , - // "frame" : , - // "global" : , - // "disable_break" : , - // "additional_context" : [ - // { "name" : , "handle" : }, - // { "name" : , "handle" : }, - // ... - // ] - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(EVALUATE))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - args.setProperty(QLatin1String(EXPRESSION),QJSValue(expr)); - - if (frame != -1) - args.setProperty(QLatin1String(FRAME),QJSValue(frame)); - - if (global) - args.setProperty(QLatin1String(GLOBAL),QJSValue(global)); - - if (disableBreak) - args.setProperty(QLatin1String(DISABLEBREAK),QJSValue(disableBreak)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::lookup(QList handles, bool includeSource) -{ - // { "seq" : , - // "type" : "request", - // "command" : "lookup", - // "arguments" : { "handles" : , - // "includeSource" : , - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LOOKUP))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - QString arr("[]"); - QJSValue array = parser.call(QJSValue(), QJSValueList() << arr); - int index = 0; - foreach (int handle, handles) { - array.setProperty(index++,QJSValue(handle)); - } - args.setProperty(QLatin1String(HANDLES),array); - - if (includeSource) - args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::backtrace(int fromFrame, int toFrame, bool bottom) -{ - // { "seq" : , - // "type" : "request", - // "command" : "backtrace", - // "arguments" : { "fromFrame" : - // "toFrame" : - // "bottom" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(BACKTRACE))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - if (fromFrame != -1) - args.setProperty(QLatin1String(FROMFRAME),QJSValue(fromFrame)); - - if (toFrame != -1) - args.setProperty(QLatin1String(TOFRAME),QJSValue(toFrame)); - - if (bottom) - args.setProperty(QLatin1String(BOTTOM),QJSValue(bottom)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::frame(int number) -{ - // { "seq" : , - // "type" : "request", - // "command" : "frame", - // "arguments" : { "number" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(FRAME))); - - if (number != -1) { - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - args.setProperty(QLatin1String(NUMBER),QJSValue(number)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::scope(int number, int frameNumber) -{ - // { "seq" : , - // "type" : "request", - // "command" : "scope", - // "arguments" : { "number" : - // "frameNumber" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPE))); - - if (number != -1) { - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - args.setProperty(QLatin1String(NUMBER),QJSValue(number)); - - if (frameNumber != -1) - args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::scopes(int frameNumber) -{ - // { "seq" : , - // "type" : "request", - // "command" : "scopes", - // "arguments" : { "frameNumber" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCOPES))); - - if (frameNumber != -1) { - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - args.setProperty(QLatin1String(FRAMENUMBER),QJSValue(frameNumber)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::scripts(int types, QList ids, bool includeSource, QVariant /*filter*/) -{ - // { "seq" : , - // "type" : "request", - // "command" : "scripts", - // "arguments" : { "types" : - // "ids" : - // "includeSource" : - // "filter" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SCRIPTS))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - args.setProperty(QLatin1String(TYPES),QJSValue(types)); - - if (ids.count()) { - QString arr("[]"); - QJSValue array = parser.call(QJSValue(), QJSValueList() << arr); - int index = 0; - foreach (int id, ids) { - array.setProperty(index++,QJSValue(id)); - } - args.setProperty(QLatin1String(IDS),array); - } - - if (includeSource) - args.setProperty(QLatin1String(INCLUDESOURCE),QJSValue(includeSource)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::source(int frame, int fromLine, int toLine) -{ - // { "seq" : , - // "type" : "request", - // "command" : "source", - // "arguments" : { "frame" : - // "fromLine" : - // "toLine" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SOURCE))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - if (frame != -1) - args.setProperty(QLatin1String(FRAME),QJSValue(frame)); - - if (fromLine != -1) - args.setProperty(QLatin1String(FROMLINE),QJSValue(fromLine)); - - if (toLine != -1) - args.setProperty(QLatin1String(TOLINE),QJSValue(toLine)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::setBreakpoint(QString type, QString target, int line, int column, bool enabled, QString condition, int ignoreCount) -{ - // { "seq" : , - // "type" : "request", - // "command" : "setbreakpoint", - // "arguments" : { "type" : <"function" or "script" or "scriptId" or "scriptRegExp"> - // "target" : - // "line" : - // "column" : - // "enabled" : - // "condition" : - // "ignoreCount" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETBREAKPOINT))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - args.setProperty(QLatin1String(TYPE),QJSValue(type)); - args.setProperty(QLatin1String(TARGET),QJSValue(target)); - - if (line != -1) - args.setProperty(QLatin1String(LINE),QJSValue(line)); - - if (column != -1) - args.setProperty(QLatin1String(COLUMN),QJSValue(column)); - - args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); - - if (!condition.isEmpty()) - args.setProperty(QLatin1String(CONDITION),QJSValue(condition)); - - if (ignoreCount != -1) - args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::changeBreakpoint(int breakpoint, bool enabled, QString condition, int ignoreCount) -{ - // { "seq" : , - // "type" : "request", - // "command" : "changebreakpoint", - // "arguments" : { "breakpoint" : - // "enabled" : - // "condition" : - // "ignoreCount" : , - // "type" : "request", - // "command" : "clearbreakpoint", - // "arguments" : { "breakpoint" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CLEARBREAKPOINT))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - args.setProperty(QLatin1String(BREAKPOINT),QJSValue(breakpoint)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::setExceptionBreak(Exception type, bool enabled) -{ - // { "seq" : , - // "type" : "request", - // "command" : "setexceptionbreak", - // "arguments" : { "type" : , - // "enabled" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETEXCEPTIONBREAK))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - if (type == All) - args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(ALL))); - else if (type == Uncaught) - args.setProperty(QLatin1String(TYPE),QJSValue(QLatin1String(UNCAUGHT))); - - if (enabled) - args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::v8flags(QString flags) -{ - // { "seq" : , - // "type" : "request", - // "command" : "v8flags", - // "arguments" : { "flags" : - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(V8FLAGS))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - args.setProperty(QLatin1String(FLAGS),QJSValue(flags)); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::version() -{ - // { "seq" : , - // "type" : "request", - // "command" : "version", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(VERSION))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -//void QJSDebugClient::profile(ProfileCommand command) -//{ -//// { "seq" : , -//// "type" : "request", -//// "command" : "profile", -//// "arguments" : { "command" : "resume" or "pause" } -//// } -// VARIANTMAPINIT; -// jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PROFILE))); - -// QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - -// if (command == Resume) -// args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(RESUME))); -// else -// args.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(PAUSE))); - -// args.setProperty(QLatin1String("modules"),QJSValue(1)); -// if (args.isValid()) { -// jsonVal.setProperty(QLatin1String(ARGUMENTS),args); -// } - -// QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); -// sendMessage(packMessage(json.toString().toUtf8())); -//} - -void QJSDebugClient::disconnect() -{ - // { "seq" : , - // "type" : "request", - // "command" : "disconnect", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(DISCONNECT))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::gc() -{ - // { "seq" : , - // "type" : "request", - // "command" : "gc", - // "arguments" : { "type" : , - // } - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(GARBAGECOLLECTOR))); - - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - - args.setProperty(QLatin1String(FLAGS),QJSValue(QLatin1String(ALL))); - - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::listBreakpoints() -{ - // { "seq" : , - // "type" : "request", - // "command" : "listbreakpoints", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LISTBREAKPOINTS))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); -} - -void QJSDebugClient::statusChanged(Status status) -{ - if (status == Enabled) { - flushSendBuffer(); - emit enabled(); - } -} - -void QJSDebugClient::messageReceived(const QByteArray &data) -{ - QDataStream ds(data); - QByteArray command; - ds >> command; - - if (command == "V8DEBUG") { - ds >> response; - QString jsonString(response); - QVariantMap value = parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - QString type = value.value("type").toString(); - - if (type == "response") { - - if (!value.value("success").toBool()) { - qDebug() << "Error: The test case will fail since no signal is emitted"; - return; - } - - QString debugCommand(value.value("command").toString()); - if (debugCommand == "backtrace" || - debugCommand == "lookup" || - debugCommand == "setbreakpoint" || - debugCommand == "evaluate" || - debugCommand == "listbreakpoints" || - debugCommand == "version" || - debugCommand == "v8flags" || - debugCommand == "disconnect" || - debugCommand == "gc" || - debugCommand == "changebreakpoint" || - debugCommand == "clearbreakpoint" || - debugCommand == "frame" || - debugCommand == "scope" || - debugCommand == "scopes" || - debugCommand == "scripts" || - debugCommand == "source" || - debugCommand == "setexceptionbreak" /*|| - debugCommand == "profile"*/) { - emit result(); - - } else { - // DO NOTHING - } - - } else if (type == "event") { - QString event(value.value("event").toString()); - - if (event == "break" || - event == "exception") { - emit stopped(); - } - } - } -} - -void QJSDebugClient::sendMessage(const QByteArray &msg) -{ - if (status() == Enabled) { - QDeclarativeDebugClient::sendMessage(msg); - } else { - sendBuffer.append(msg); - } -} - -void QJSDebugClient::flushSendBuffer() -{ - foreach (const QByteArray &msg, sendBuffer) - QDeclarativeDebugClient::sendMessage(msg); - sendBuffer.clear(); -} - -QByteArray QJSDebugClient::packMessage(QByteArray message) -{ - QByteArray reply; - QDataStream rs(&reply, QIODevice::WriteOnly); - QByteArray cmd = "V8DEBUG"; - rs << cmd << message; - return reply; -} - -void tst_QDeclarativeDebugJS::initTestCase() -{ - process = 0; - client = 0; - connection = 0; -} - -void tst_QDeclarativeDebugJS::cleanupTestCase() -{ - if (process) - delete process; - - if (client) - delete client; - - if (connection) - delete connection; -} - -void tst_QDeclarativeDebugJS::init() -{ - connection = new QDeclarativeDebugConnection(); - process = new QJSDebugProcess(); - client = new QJSDebugClient(connection); - - process->start(QStringList() << QLatin1String(BLOCKMODE) << TESTDATA(QLatin1String(QMLFILE))); - QVERIFY(process->waitForSessionStart()); - - connection->connectToHost("127.0.0.1", 3771); - QVERIFY(connection->waitForConnected()); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(enabled()))); -} - -void tst_QDeclarativeDebugJS::cleanup() -{ - if (process) - delete process; - - if (client) - delete client; - - if (connection) - delete connection; - - process = 0; - client = 0; - connection = 0; -} - -void tst_QDeclarativeDebugJS::getVersion() -{ - //void version() - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->version(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::applyV8Flags() -{ - //void v8flags(QString flags) - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->v8flags(QString()); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::disconnect() -{ - //void disconnect() - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->disconnect(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::gc() -{ - //void gc() - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), 2, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->gc(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::listBreakpoints() -{ - //void listBreakpoints() - - int sourceLine1 = 57; - int sourceLine2 = 60; - int sourceLine3 = 67; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine3, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->listBreakpoints(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QList breakpoints = value.value("body").toMap().value("breakpoints").toList(); - - QCOMPARE(breakpoints.count(), 3); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine = 49; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine = 67; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine = 43; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine = 48; - int actualLine = 50; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine = 49; - int actualLine = 50; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(JSFILE)); -} - -void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition() -{ - //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int out = 10; - int sourceLine = 51; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(JSFILE), sourceLine, -1, true, QLatin1String("out > 10")); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - //Get the frame index - QString jsonString = client->response; - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - int frameIndex = body.value("index").toInt(); - - //Verify the value of 'result' - client->evaluate(QLatin1String("out"),frameIndex); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QVERIFY(body.value("value").toInt() > out); -} - -//void tst_QDeclarativeDebugJS::setBreakpointInFunction() -//{ -// //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - -// int actualLine = 31; - -// client->startDebugging(); -// client->setBreakpoint(QLatin1String(FUNCTION), QLatin1String("doSomethingElse"), -1, -1, true); - -// QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - -// QString jsonString(client->response); -// QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - -// QVariantMap body = value.value("body").toMap(); - -// QCOMPARE(body.value("sourceLine").toInt(), actualLine); -// QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -//} - -void tst_QDeclarativeDebugJS::changeBreakpoint() -{ - //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine1 = 77; - int sourceLine2 = 78; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - //Will hit 1st brakpoint, change this breakpoint enable = false - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - QList breakpointsHit = body.value("breakpoints").toList(); - - int breakpoint = breakpointsHit.at(0).toInt(); - client->changeBreakpoint(breakpoint,false); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Hit 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Should stop at 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); -} - -void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() -{ - //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - - int sourceLine1 = 56; - int sourceLine2 = 60; - int result = 0; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - //Will hit 1st brakpoint, change this breakpoint enable = false - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - QList breakpointsHit = body.value("breakpoints").toList(); - - int breakpoint = breakpointsHit.at(0).toInt(); - client->changeBreakpoint(breakpoint,false,QLatin1String("a = 0")); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Hit 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Should stop at 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); - - client->frame(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Get the frame index - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - int frameIndex = body.value("index").toInt(); - - //Verify the value of 'result' - client->evaluate(QLatin1String("root.result"),frameIndex); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QVERIFY(body.value("value").toInt() > result); -} - -void tst_QDeclarativeDebugJS::clearBreakpoint() -{ - //void clearBreakpoint(int breakpoint); - - int sourceLine1 = 77; - int sourceLine2 = 78; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - //Will hit 1st brakpoint, change this breakpoint enable = false - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - QList breakpointsHit = body.value("breakpoints").toList(); - - int breakpoint = breakpointsHit.at(0).toInt(); - client->changeBreakpoint(breakpoint,false,QLatin1String("result > 5")); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Hit 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); - //Should stop at 2nd breakpoint - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); -} - -void tst_QDeclarativeDebugJS::setExceptionBreak() -{ - //void setExceptionBreak(QString type, bool enabled = false); - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->setExceptionBreak(QJSDebugClient::All,true); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); -} - -void tst_QDeclarativeDebugJS::stepNext() -{ - //void continueDebugging(StepAction stepAction, int stepCount = 1); - - int sourceLine = 57; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->continueDebugging(QJSDebugClient::Next); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 1); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::stepNextWithCount() -{ - //void continueDebugging(StepAction stepAction, int stepCount = 1); - - int sourceLine = 59; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->continueDebugging(QJSDebugClient::Next,2); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 2); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::stepIn() -{ - //void continueDebugging(StepAction stepAction, int stepCount = 1); - - int sourceLine = 67; - int actualLine = 56; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->continueDebugging(QJSDebugClient::In); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::stepOut() -{ - //void continueDebugging(StepAction stepAction, int stepCount = 1); - - int sourceLine = 56; - int actualLine = 68; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->continueDebugging(QJSDebugClient::Out); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::continueDebugging() -{ - //void continueDebugging(StepAction stepAction, int stepCount = 1); - - int sourceLine1 = 56; - int sourceLine2 = 60; - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine2, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); - - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); -} - -void tst_QDeclarativeDebugJS::backtrace() -{ - //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); - - int sourceLine = 60; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->backtrace(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::getFrameDetails() -{ - //void frame(int number = -1); - - int sourceLine = 60; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->frame(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::getScopeDetails() -{ - //void scope(int number = -1, int frameNumber = -1); - - int sourceLine = 60; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->scope(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::evaluateInGlobalScope() -{ - //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - - int sourceLine = 49; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->evaluate(QLatin1String("print('Hello World')"),true); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Verify the value of 'print' - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - QCOMPARE(body.value("text").toString(),QLatin1String("undefined")); -} - -void tst_QDeclarativeDebugJS::evaluateInLocalScope() -{ - //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - - int sourceLine = 60; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->frame(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Get the frame index - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - QVariantMap body = value.value("body").toMap(); - - int frameIndex = body.value("index").toInt(); - - client->evaluate(QLatin1String("root.someValue"),frameIndex); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Verify the value of 'root.someValue' - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QCOMPARE(body.value("value").toInt(),10); -} - -void tst_QDeclarativeDebugJS::getScopes() -{ - //void scopes(int frameNumber = -1); - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->scopes(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::getScripts() -{ - //void scripts(int types = -1, QList ids = QList(), bool includeSource = false, QVariant filter = QVariant()); - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->scripts(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -void tst_QDeclarativeDebugJS::getSource() -{ - //void source(int frame = -1, int fromLine = -1, int toLine = -1); - - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->source(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); -} - -QTEST_MAIN(tst_QDeclarativeDebugJS) - -#include "tst_qdeclarativedebugjs.moc" - diff --git a/tests/auto/declarative/qdeclarativedebugservice/qdeclarativedebugservice.pro b/tests/auto/declarative/qdeclarativedebugservice/qdeclarativedebugservice.pro deleted file mode 100644 index c23e920..0000000 --- a/tests/auto/declarative/qdeclarativedebugservice/qdeclarativedebugservice.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativedebugservice -macx:CONFIG -= app_bundle - -HEADERS += ../shared/debugutil_p.h -SOURCES += tst_qdeclarativedebugservice.cpp \ - ../shared/debugutil.cpp - -CONFIG += parallel_test declarative_debug - -QT += core-private gui-private declarative-private network testlib diff --git a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp deleted file mode 100644 index 011bd40..0000000 --- a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "../../../shared/util.h" -#include "../shared/debugutil_p.h" - - -class tst_QDeclarativeDebugService : public QObject -{ - Q_OBJECT -private: - QDeclarativeDebugConnection *m_conn; - -private slots: - void initTestCase(); - - void name(); - void status(); - void sendMessage(); - void idForObject(); - void objectForId(); - void objectToString(); -}; - -void tst_QDeclarativeDebugService::initTestCase() -{ - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 13769..."); - new QDeclarativeEngine(this); - - m_conn = new QDeclarativeDebugConnection(this); - m_conn->connectToHost("127.0.0.1", 13769); - - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); - bool ok = m_conn->waitForConnected(); - QVERIFY(ok); - - QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); -} - -void tst_QDeclarativeDebugService::name() -{ - QString name = "tst_QDeclarativeDebugService::name()"; - - QDeclarativeDebugService service(name); - QCOMPARE(service.name(), name); -} - -void tst_QDeclarativeDebugService::status() -{ - QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::status()"); - QCOMPARE(service.status(), QDeclarativeDebugService::Unavailable); - - { - QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::status()", m_conn); - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); - QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled); - } - - - QTRY_COMPARE(service.status(), QDeclarativeDebugService::Unavailable); - - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::status()\" "); - - QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::status()"); - QCOMPARE(duplicate.status(), QDeclarativeDebugService::NotConnected); -} - -void tst_QDeclarativeDebugService::sendMessage() -{ - QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::sendMessage()"); - QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled); - QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled); - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); - - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::sendMessage()\" "); - QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::sendMessage()"); - duplicate.sendMessage("msg"); -} - -void tst_QDeclarativeDebugService::idForObject() -{ - QCOMPARE(QDeclarativeDebugService::idForObject(0), -1); - - QObject *objA = new QObject; - - int idA = QDeclarativeDebugService::idForObject(objA); - QVERIFY(idA >= 0); - QCOMPARE(QDeclarativeDebugService::objectForId(idA), objA); - - int idAA = QDeclarativeDebugService::idForObject(objA); - QCOMPARE(idAA, idA); - - QObject *objB = new QObject; - int idB = QDeclarativeDebugService::idForObject(objB); - QVERIFY(idB != idA); - QCOMPARE(QDeclarativeDebugService::objectForId(idB), objB); - - delete objA; - delete objB; -} - -void tst_QDeclarativeDebugService::objectForId() -{ - QCOMPARE(QDeclarativeDebugService::objectForId(-1), static_cast(0)); - QCOMPARE(QDeclarativeDebugService::objectForId(1), static_cast(0)); - - QObject *obj = new QObject; - int id = QDeclarativeDebugService::idForObject(obj); - QCOMPARE(QDeclarativeDebugService::objectForId(id), obj); - - delete obj; - QCOMPARE(QDeclarativeDebugService::objectForId(id), static_cast(0)); -} - -void tst_QDeclarativeDebugService::objectToString() -{ - QCOMPARE(QDeclarativeDebugService::objectToString(0), QString("NULL")); - - QObject *obj = new QObject; - QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: ")); - - obj->setObjectName("Hello"); - QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: Hello")); - delete obj; -} - - -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]; - char arg[] = "-qmljsdebugger=port:13769"; - _argv[_argc - 1] = arg; - - QGuiApplication app(_argc, _argv); - tst_QDeclarativeDebugService tc; - return QTest::qExec(&tc, _argc, _argv); - delete _argv; -} - -#include "tst_qdeclarativedebugservice.moc" diff --git a/tests/auto/declarative/qdeclarativeenginedebug/qdeclarativeenginedebug.pro b/tests/auto/declarative/qdeclarativeenginedebug/qdeclarativeenginedebug.pro deleted file mode 100644 index 98736c6..0000000 --- a/tests/auto/declarative/qdeclarativeenginedebug/qdeclarativeenginedebug.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativeenginedebug -macx:CONFIG -= app_bundle - -HEADERS += ../shared/debugutil_p.h -SOURCES += tst_qdeclarativeenginedebug.cpp \ - ../shared/debugutil.cpp - -CONFIG += parallel_test declarative_debug - -QT += core-private gui-private v8-private declarative-private network testlib diff --git a/tests/auto/declarative/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp b/tests/auto/declarative/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp deleted file mode 100644 index 0e4eebb..0000000 --- a/tests/auto/declarative/qdeclarativeenginedebug/tst_qdeclarativeenginedebug.cpp +++ /dev/null @@ -1,1220 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "../../../shared/util.h" -#include "../shared/debugutil_p.h" - -Q_DECLARE_METATYPE(QDeclarativeDebugWatch::State) - -class tst_QDeclarativeEngineDebug : public QObject -{ - Q_OBJECT - -private: - QDeclarativeDebugObjectReference findRootObject(int context = 0, bool recursive = false); - QDeclarativeDebugPropertyReference findProperty(const QList &props, const QString &name) const; - void waitForQuery(QDeclarativeDebugQuery *query); - - void recursiveObjectTest(QObject *o, const QDeclarativeDebugObjectReference &oref, bool recursive) const; - - void recursiveCompareObjects(const QDeclarativeDebugObjectReference &a, const QDeclarativeDebugObjectReference &b) const; - void recursiveCompareContexts(const QDeclarativeDebugContextReference &a, const QDeclarativeDebugContextReference &b) const; - void compareProperties(const QDeclarativeDebugPropertyReference &a, const QDeclarativeDebugPropertyReference &b) const; - - QDeclarativeDebugConnection *m_conn; - QDeclarativeEngineDebug *m_dbg; - QDeclarativeEngine *m_engine; - QSGItem *m_rootItem; - - 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(); - - void tst_QDeclarativeDebugFileReference(); - void tst_QDeclarativeDebugEngineReference(); - void tst_QDeclarativeDebugObjectReference(); - void tst_QDeclarativeDebugContextReference(); - void tst_QDeclarativeDebugPropertyReference(); - - 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) - - -QDeclarativeDebugObjectReference tst_QDeclarativeEngineDebug::findRootObject(int context, bool recursive) -{ - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - if (q_engines->engines().count() == 0) - return QDeclarativeDebugObjectReference(); - QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - if (q_context->rootContext().objects().count() == 0) - return QDeclarativeDebugObjectReference(); - QDeclarativeDebugObjectQuery *q_obj = recursive ? - m_dbg->queryObjectRecursive(q_context->rootContext().objects()[context], this) : - m_dbg->queryObject(q_context->rootContext().objects()[context], this); - waitForQuery(q_obj); - - QDeclarativeDebugObjectReference result = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - return result; -} - -QDeclarativeDebugPropertyReference tst_QDeclarativeEngineDebug::findProperty(const QList &props, const QString &name) const -{ - foreach(const QDeclarativeDebugPropertyReference &p, props) { - if (p.name() == name) - return p; - } - return QDeclarativeDebugPropertyReference(); -} - -void tst_QDeclarativeEngineDebug::waitForQuery(QDeclarativeDebugQuery *query) -{ - QVERIFY(query); - QCOMPARE(query->parent(), qobject_cast(this)); - QVERIFY(query->state() == QDeclarativeDebugQuery::Waiting); - if (!QDeclarativeDebugTest::waitForSignal(query, SIGNAL(stateChanged(QDeclarativeDebugQuery::State)))) - QFAIL("query timed out"); -} - -void tst_QDeclarativeEngineDebug::recursiveObjectTest(QObject *o, const QDeclarativeDebugObjectReference &oref, bool recursive) const -{ - const QMetaObject *meta = o->metaObject(); - - QDeclarativeType *type = QDeclarativeMetaType::qmlType(meta); - QString className = type ? QString(type->qmlTypeName()) : QString(meta->className()); - className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); - - QCOMPARE(oref.debugId(), QDeclarativeDebugService::idForObject(o)); - QCOMPARE(oref.name(), o->objectName()); - QCOMPARE(oref.className(), className); - QCOMPARE(oref.contextDebugId(), QDeclarativeDebugService::idForObject(qmlContext(o))); - - const QObjectList &children = o->children(); - for (int i=0; i= 0); - - QDeclarativeDebugObjectReference cref; - foreach (const QDeclarativeDebugObjectReference &ref, oref.children()) { - if (ref.debugId() == debugId) { - cref = ref; - break; - } - } - QVERIFY(cref.debugId() >= 0); - - if (recursive) - recursiveObjectTest(child, cref, true); - } - - foreach (const QDeclarativeDebugPropertyReference &p, oref.properties()) { - QCOMPARE(p.objectDebugId(), QDeclarativeDebugService::idForObject(o)); - - // signal properties are fake - they are generated from QDeclarativeBoundSignal children - if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { - QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); - QVERIFY(p.valueTypeName().isEmpty()); - QVERIFY(p.binding().isEmpty()); - QVERIFY(!p.hasNotifySignal()); - continue; - } - - QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); - - QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); - - if (pmeta.type() < QVariant::UserType) // TODO test complex types - QCOMPARE(p.value(), pmeta.read(o)); - - if (p.name() == "parent") - QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QSGItem*"); - else - QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); - - QDeclarativeAbstractBinding *binding = - QDeclarativePropertyPrivate::binding(QDeclarativeProperty(o, p.name())); - if (binding) - QCOMPARE(binding->expression(), p.binding()); - - QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); - - QVERIFY(pmeta.isValid()); - } -} - -void tst_QDeclarativeEngineDebug::recursiveCompareObjects(const QDeclarativeDebugObjectReference &a, const QDeclarativeDebugObjectReference &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(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3768..."); - m_engine = new QDeclarativeEngine(this); - - QList qml; - qml << "import QtQuick 2.0\n" - "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" - "Component.onCompleted: {\n" - "varObj = blueRect;\n" - "var list = varObjList;\n" - "list[0] = blueRect;\n" - "varObjList = list;\n" - "}\n" - "NonScriptPropertyElement {\n" - "}\n" - "}"; - - // add second component to test multiple root contexts - qml << "import QtQuick 2.0\n" - "Item {}"; - - // and a third to test methods - qml << "import QtQuick 2.0\n" - "Item {" - "function myMethodNoArgs() { return 3; }\n" - "function myMethod(a) { return a + 9; }\n" - "function myMethodIndirect() { myMethod(3); }\n" - "}"; - - // and a fourth to test states - qml << "import QtQuick 2.0\n" - "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(component.create()); - } - m_rootItem = qobject_cast(m_components.first()); - - // add an extra context to test for multiple contexts - QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this); - context->setObjectName("tst_QDeclarativeDebug_childContext"); - - m_conn = new QDeclarativeDebugConnection(this); - m_conn->connectToHost("127.0.0.1", 3768); - - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); - bool ok = m_conn->waitForConnected(); - QVERIFY(ok); - QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); - m_dbg = new QDeclarativeEngineDebug(m_conn, this); - QTRY_VERIFY(m_dbg->status() == QDeclarativeEngineDebug::Enabled); -} - -void tst_QDeclarativeEngineDebug::cleanupTestCase() -{ - delete m_dbg; - delete m_conn; - qDeleteAll(m_components); - delete m_engine; -} - -void tst_QDeclarativeEngineDebug::setMethodBody() -{ - QDeclarativeDebugObjectReference obj = findRootObject(2); - - 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))); - } -} - -void tst_QDeclarativeEngineDebug::watch_property() -{ - QDeclarativeDebugObjectReference obj = findRootObject(); - QDeclarativeDebugPropertyReference prop = findProperty(obj.properties(), "width"); - - QDeclarativeDebugPropertyWatch *watch; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - watch = unconnected->addWatch(prop, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); - delete watch; - delete unconnected; - - watch = m_dbg->addWatch(QDeclarativeDebugPropertyReference(), this); - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(prop, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->name(), prop.name()); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - - int origWidth = m_rootItem->property("width").toInt(); - m_rootItem->setProperty("width", origWidth*2); - - // stateChanged() is received before valueChanged() - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); - QCOMPARE(spy.count(), 1); - - m_dbg->removeWatch(watch); - delete watch; - - // restore original value and verify spy doesn't get additional signal since watch has been removed - m_rootItem->setProperty("width", origWidth); - QTest::qWait(100); - QCOMPARE(spy.count(), 1); - - QCOMPARE(spy.at(0).at(0).value(), prop.name().toUtf8()); - QCOMPARE(spy.at(0).at(1).value(), qVariantFromValue(origWidth*2)); -} - -void tst_QDeclarativeEngineDebug::watch_object() -{ - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QVERIFY(q_engines->engines().count() > 0); - QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - QVERIFY(q_context->rootContext().objects().count() > 0); - QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); - waitForQuery(q_obj); - - QDeclarativeDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - QDeclarativeDebugWatch *watch; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - watch = unconnected->addWatch(obj, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); - delete watch; - delete unconnected; - - watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), this); - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - - int origWidth = m_rootItem->property("width").toInt(); - int origHeight = m_rootItem->property("height").toInt(); - m_rootItem->setProperty("width", origWidth*2); - m_rootItem->setProperty("height", origHeight*2); - - // stateChanged() is received before any valueChanged() signals - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); - QVERIFY(spy.count() > 0); - - int newWidth = -1; - int newHeight = -1; - for (int i=0; i() == "width") - newWidth = values[1].value().toInt(); - else if (values[0].value() == "height") - newHeight = values[1].value().toInt(); - - } - - m_dbg->removeWatch(watch); - delete watch; - - // since watch has been removed, restoring the original values should not trigger a valueChanged() - spy.clear(); - m_rootItem->setProperty("width", origWidth); - m_rootItem->setProperty("height", origHeight); - QTest::qWait(100); - QCOMPARE(spy.count(), 0); - - QCOMPARE(newWidth, origWidth * 2); - QCOMPARE(newHeight, origHeight * 2); -} - -void tst_QDeclarativeEngineDebug::watch_expression() -{ - QFETCH(QString, expr); - QFETCH(int, increment); - QFETCH(int, incrementCount); - - int origWidth = m_rootItem->property("width").toInt(); - - QDeclarativeDebugObjectReference obj = findRootObject(); - - QDeclarativeDebugObjectExpressionWatch *watch; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - watch = unconnected->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead); - delete watch; - delete unconnected; - - watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), expr, this); - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->expression(), expr); - - QSignalSpy spyState(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State))); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value - - int width = origWidth; - for (int i=0; i 0) { - width += increment; - m_rootItem->setProperty("width", width); - } - if (!QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) - QFAIL("Did not receive valueChanged() for expression"); - } - - if (spyState.count() == 0) - QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State)))); - QCOMPARE(spyState.count(), 1); - QCOMPARE(watch->state(), QDeclarativeDebugWatch::Active); - - m_dbg->removeWatch(watch); - delete watch; - - // restore original value and verify spy doesn't get a signal since watch has been removed - m_rootItem->setProperty("width", origWidth); - QTest::qWait(100); - QCOMPARE(spy.count(), expectedSpyCount); - - width = origWidth + increment; - for (int i=0; i().toInt(), width); - width += increment; - } -} - -void tst_QDeclarativeEngineDebug::watch_expression_data() -{ - QTest::addColumn("expr"); - QTest::addColumn("increment"); - QTest::addColumn("incrementCount"); - - QTest::newRow("width") << "width" << 0 << 0; - QTest::newRow("width+10") << "width + 10" << 10 << 5; -} - -void tst_QDeclarativeEngineDebug::watch_context() -{ - QDeclarativeDebugContextReference c; - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(c, QString(), this)); -} - -void tst_QDeclarativeEngineDebug::watch_file() -{ - QDeclarativeDebugFileReference f; - QTest::ignoreMessage(QtWarningMsg, "QDeclarativeEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(f, this)); -} - -void tst_QDeclarativeEngineDebug::queryAvailableEngines() -{ - QDeclarativeDebugEnginesQuery *q_engines; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - q_engines = unconnected->queryAvailableEngines(0); - QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Error); - 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 - QList engines = q_engines->engines(); - QCOMPARE(engines.count(), 1); - - foreach(const QDeclarativeDebugEngineReference &e, engines) { - QCOMPARE(e.debugId(), QDeclarativeDebugService::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(), QDeclarativeDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_engines->state(), QDeclarativeDebugQuery::Error); - delete q_engines; - m_dbg = new QDeclarativeEngineDebug(m_conn, this); -} - -void tst_QDeclarativeEngineDebug::queryRootContexts() -{ - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - int engineId = q_engines->engines()[0].debugId(); - delete q_engines; - - QDeclarativeDebugRootContextQuery *q_context; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - q_context = unconnected->queryRootContexts(engineId, this); - QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error); - 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); - - QDeclarativeContext *actualContext = m_engine->rootContext(); - QDeclarativeDebugContextReference context = q_context->rootContext(); - QCOMPARE(context.debugId(), QDeclarativeDebugService::idForObject(actualContext)); - QCOMPARE(context.name(), actualContext->objectName()); - - QCOMPARE(context.objects().count(), 4); // 4 qml component objects created for context in main() - - // root context query sends only root object data - it doesn't fill in - // the children or property info - QCOMPARE(context.objects()[0].properties().count(), 0); - QCOMPARE(context.objects()[0].children().count(), 0); - - QCOMPARE(context.contexts().count(), 5); - QVERIFY(context.contexts()[0].debugId() >= 0); - QCOMPARE(context.contexts()[0].name(), QString("tst_QDeclarativeDebug_childContext")); - - // Make query invalid by deleting client - q_context = m_dbg->queryRootContexts(engineId, this); - QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error); - delete q_context; - m_dbg = new QDeclarativeEngineDebug(m_conn, this); -} - -void tst_QDeclarativeEngineDebug::queryObject() -{ - QFETCH(bool, recursive); - - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[0]; - - QDeclarativeDebugObjectQuery *q_obj = 0; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - q_obj = recursive ? unconnected->queryObjectRecursive(rootObject, this) : unconnected->queryObject(rootObject, this); - QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Error); - 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); - - QDeclarativeDebugObjectReference 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(), QDeclarativeDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_obj->state(), QDeclarativeDebugQuery::Error); - delete q_obj; - m_dbg = new QDeclarativeEngineDebug(m_conn, this); - - // check source as defined in main() - QDeclarativeDebugFileReference 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 QDeclarativeDebugObjectReference &child, obj.children()) - QVERIFY(child.properties().count() > 0); - - QDeclarativeDebugObjectReference rect; - QDeclarativeDebugObjectReference text; - foreach (const QDeclarativeDebugObjectReference &child, obj.children()) { - if (child.className() == "Rectangle") - rect = child; - else if (child.className() == "Text") - text = child; - } - - // test specific property values - QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500)); - QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600)); - QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue"))); - - QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue"))); - } else { - foreach(const QDeclarativeDebugObjectReference &child, obj.children()) - QCOMPARE(child.properties().count(), 0); - } -} - -void tst_QDeclarativeEngineDebug::queryObject_data() -{ - QTest::addColumn("recursive"); - - QTest::newRow("non-recursive") << false; - QTest::newRow("recursive") << true; -} - -void tst_QDeclarativeEngineDebug::queryExpressionResult() -{ - QFETCH(QString, expr); - QFETCH(QVariant, result); - - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); // check immediate deletion is ok - - QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - int objectId = q_context->rootContext().objects()[0].debugId(); - - QDeclarativeDebugExpressionQuery *q_expr; - - QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0); - q_expr = unconnected->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error); - delete q_expr; - 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); - - 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(), QDeclarativeDebugQuery::Waiting); - delete m_dbg; - QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error); - delete q_expr; - m_dbg = new QDeclarativeEngineDebug(m_conn, this); -} - -void tst_QDeclarativeEngineDebug::queryExpressionResult_data() -{ - QTest::addColumn("expr"); - QTest::addColumn("result"); - - QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); - QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); - QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); - QTest::newRow("QObject*") << "varObj" << qVariantFromValue(QString("")); - QTest::newRow("list of QObject*") << "varObjList" << qVariantFromValue(QString("")); -} - -void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugFileReference() -{ - QDeclarativeDebugFileReference 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); - - QDeclarativeDebugFileReference copy(ref); - QDeclarativeDebugFileReference copyAssign; - copyAssign = ref; - foreach (const QDeclarativeDebugFileReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.url(), ref.url()); - QCOMPARE(r.lineNumber(), ref.lineNumber()); - QCOMPARE(r.columnNumber(), ref.columnNumber()); - } -} - -void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugEngineReference() -{ - QDeclarativeDebugEngineReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - - ref = QDeclarativeDebugEngineReference(1); - QCOMPARE(ref.debugId(), 1); - QVERIFY(ref.name().isEmpty()); - - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - ref = q_engines->engines()[0]; - delete q_engines; - - QDeclarativeDebugEngineReference copy(ref); - QDeclarativeDebugEngineReference copyAssign; - copyAssign = ref; - foreach (const QDeclarativeDebugEngineReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.debugId(), ref.debugId()); - QCOMPARE(r.name(), ref.name()); - } -} - -void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugObjectReference() -{ - QDeclarativeDebugObjectReference 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()); - - QDeclarativeDebugFileReference source = ref.source(); - QVERIFY(source.url().isEmpty()); - QVERIFY(source.lineNumber() < 0); - QVERIFY(source.columnNumber() < 0); - - ref = QDeclarativeDebugObjectReference(1); - QCOMPARE(ref.debugId(), 1); - - QDeclarativeDebugObjectReference rootObject = findRootObject(); - QDeclarativeDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); - waitForQuery(query); - ref = query->object(); - delete query; - - QVERIFY(ref.debugId() >= 0); - - QDeclarativeDebugObjectReference copy(ref); - QDeclarativeDebugObjectReference copyAssign; - copyAssign = ref; - foreach (const QDeclarativeDebugObjectReference &r, (QList() << copy << copyAssign)) - recursiveCompareObjects(r, ref); -} - -void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugContextReference() -{ - QDeclarativeDebugContextReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - QVERIFY(ref.objects().isEmpty()); - QVERIFY(ref.contexts().isEmpty()); - - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - QDeclarativeDebugRootContextQuery *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); - - QDeclarativeDebugContextReference copy(ref); - QDeclarativeDebugContextReference copyAssign; - copyAssign = ref; - foreach (const QDeclarativeDebugContextReference &r, (QList() << copy << copyAssign)) - recursiveCompareContexts(r, ref); -} - -void tst_QDeclarativeEngineDebug::tst_QDeclarativeDebugPropertyReference() -{ - QDeclarativeDebugObjectReference rootObject = findRootObject(); - QDeclarativeDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); - waitForQuery(query); - QDeclarativeDebugObjectReference obj = query->object(); - delete query; - - QDeclarativeDebugPropertyReference 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()); - - QDeclarativeDebugPropertyReference copy(ref); - QDeclarativeDebugPropertyReference copyAssign; - copyAssign = ref; - foreach (const QDeclarativeDebugPropertyReference &r, (QList() << copy << copyAssign)) - compareProperties(r, ref); -} - -void tst_QDeclarativeEngineDebug::setBindingForObject() -{ - QDeclarativeDebugObjectReference rootObject = findRootObject(); - QVERIFY(rootObject.debugId() != -1); - QDeclarativeDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties(), "width"); - - 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(); - QCOMPARE(rootObject.children().size(), 5); // Rectangle, Text, MouseArea, Component.onCompleted, NonScriptPropertyElement - QDeclarativeDebugObjectReference mouseAreaObject = rootObject.children().at(2); - QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(mouseAreaObject, this); - waitForQuery(q_obj); - mouseAreaObject = q_obj->object(); - - QCOMPARE(mouseAreaObject.className(), QString("MouseArea")); - - QDeclarativeDebugPropertyReference onEnteredRef = findProperty(mouseAreaObject.properties(), "onEntered"); - - QCOMPARE(onEnteredRef.name(), QString("onEntered")); - QCOMPARE(onEnteredRef.value(), QVariant("{ console.log('hello') }")); - - 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') }")); -} - -void tst_QDeclarativeEngineDebug::setBindingInStates() -{ - // Check if changing bindings of propertychanges works - - const int sourceIndex = 3; - - QDeclarativeDebugObjectReference obj = findRootObject(sourceIndex); - - 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 - QDeclarativeDebugExpressionQuery *q_deleteTransition = m_dbg->queryExpressionResult(obj.debugId(),QString("transitions = []"),this); - waitForQuery(q_deleteTransition); - delete q_deleteTransition; - - - // check initial value of the property that is changing - QDeclarativeDebugExpressionQuery *q_setState; - 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 - QDeclarativeDebugObjectReference state = obj.children()[1]; - QCOMPARE(state.className(), QString("State")); - QVERIFY(state.children().count() > 0); - - QDeclarativeDebugObjectReference propertyChange = state.children()[0]; - 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); -} - -void tst_QDeclarativeEngineDebug::queryObjectTree() -{ - const int sourceIndex = 3; - - // Check if states/transitions are initialized when fetching root item - QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - QVERIFY(q_context->rootContext().objects().count() > sourceIndex); - QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[sourceIndex]; - - QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObjectRecursive(rootObject, this); - waitForQuery(q_obj); - - QDeclarativeDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - QVERIFY(obj.debugId() != -1); - QVERIFY(obj.children().count() >= 2); - - - - // check state - QDeclarativeDebugObjectReference state = obj.children()[1]; - QCOMPARE(state.className(), QString("State")); - QVERIFY(state.children().count() > 0); - - QDeclarativeDebugObjectReference propertyChange = state.children()[0]; - QVERIFY(propertyChange.debugId() != -1); - - QDeclarativeDebugPropertyReference propertyChangeTarget = findProperty(propertyChange.properties(),"target"); - QCOMPARE(propertyChangeTarget.objectDebugId(), propertyChange.debugId()); - - QDeclarativeDebugObjectReference targetReference = qvariant_cast(propertyChangeTarget.value()); - QVERIFY(targetReference.debugId() != -1); - - - - // check transition - QDeclarativeDebugObjectReference 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); - - QDeclarativeDebugObjectReference animation = transition.children()[0]; - QVERIFY(animation.debugId() != -1); - - QDeclarativeDebugPropertyReference animationTarget = findProperty(animation.properties(),"target"); - QCOMPARE(animationTarget.objectDebugId(), animation.debugId()); - - 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); -} - -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]; - char arg[] = "-qmljsdebugger=port:3768"; - _argv[_argc - 1] = arg; - - QGuiApplication app(_argc, _argv); - tst_QDeclarativeEngineDebug tc; - return QTest::qExec(&tc, _argc, _argv); - delete _argv; -} - -#include "tst_qdeclarativeenginedebug.moc" diff --git a/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro deleted file mode 100644 index 076ab98..0000000 --- a/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG += testcase -TARGET = tst_qpacketprotocol -macx:CONFIG -= app_bundle - -HEADERS += ../shared/debugutil_p.h -SOURCES += tst_qpacketprotocol.cpp \ - ../shared/debugutil.cpp - -CONFIG += parallel_test -QT += core-private gui-private v8-private declarative-private network testlib diff --git a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp deleted file mode 100644 index 87fa12f..0000000 --- a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include -#include - -#include - -#include "../shared/debugutil_p.h" - -class tst_QPacketProtocol : public QObject -{ - Q_OBJECT - -private: - QTcpServer *m_server; - QTcpSocket *m_client; - QTcpSocket *m_serverConn; - -private slots: - void init(); - void cleanup(); - - void maximumPacketSize(); - void setMaximumPacketSize(); - void setMaximumPacketSize_data(); - void send(); - void send_data(); - void packetsAvailable(); - void packetsAvailable_data(); - void clear(); - void read(); - void device(); - - void tst_QPacket_clear(); -}; - -void tst_QPacketProtocol::init() -{ - m_server = new QTcpServer(this); - m_serverConn = 0; - QVERIFY(m_server->listen(QHostAddress("127.0.0.1"))); - - m_client = new QTcpSocket(this); - m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); - - QVERIFY(m_client->waitForConnected()); - QVERIFY(m_server->waitForNewConnection()); - m_serverConn = m_server->nextPendingConnection(); -} - -void tst_QPacketProtocol::cleanup() -{ - delete m_client; - delete m_serverConn; - delete m_server; -} - -void tst_QPacketProtocol::maximumPacketSize() -{ - QPacketProtocol p(m_client); - QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); -} - -void tst_QPacketProtocol::setMaximumPacketSize() -{ - QFETCH(qint32, size); - QFETCH(qint32, expected); - - QPacketProtocol out(m_serverConn); - QCOMPARE(out.setMaximumPacketSize(size), expected); -} - -void tst_QPacketProtocol::setMaximumPacketSize_data() -{ - QTest::addColumn("size"); - QTest::addColumn("expected"); - - QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); - QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); - QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); -} - -void tst_QPacketProtocol::send() -{ - QFETCH(bool, useAutoSend); - - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QByteArray ba; - int num; - - if (useAutoSend) { - out.send() << "Hello world" << 123; - } else { - QPacket packet; - packet << "Hello world" << 123; - out.send(packet); - } - - QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p = in.read(); - p >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world") + '\0'); - QCOMPARE(num, 123); -} - -void tst_QPacketProtocol::send_data() -{ - QTest::addColumn("useAutoSend"); - - QTest::newRow("auto send") << true; - QTest::newRow("no auto send") << false; -} - -void tst_QPacketProtocol::packetsAvailable() -{ - QFETCH(int, packetCount); - - QPacketProtocol out(m_client); - QPacketProtocol in(m_serverConn); - - QCOMPARE(out.packetsAvailable(), qint64(0)); - QCOMPARE(in.packetsAvailable(), qint64(0)); - - for (int i=0; i("packetCount"); - - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("10") << 10; -} - -void tst_QPacketProtocol::clear() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - out.send() << 123; - out.send() << 456; - QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - in.clear(); - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::read() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QVERIFY(in.read().isEmpty()); - - out.send() << 123; - out.send() << 456; - QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - int num; - - QPacket p1 = in.read(); - QVERIFY(!p1.isEmpty()); - p1 >> num; - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - QVERIFY(!p2.isEmpty()); - p2 >> num; - QCOMPARE(num, 456); - - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::device() -{ - QPacketProtocol p(m_client); - QVERIFY(p.device() == m_client); -} - -void tst_QPacketProtocol::tst_QPacket_clear() -{ - QPacketProtocol protocol(m_client); - - QPacket packet; - - packet << "Hello world!" << 123; - protocol.send(packet); - - packet.clear(); - QVERIFY(packet.isEmpty()); - packet << "Goodbyte world!" << 789; - protocol.send(packet); - - QByteArray ba; - int num; - QPacketProtocol in(m_serverConn); - QVERIFY(QDeclarativeDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p1 = in.read(); - p1 >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world!") + '\0'); - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - p2 >> ba >> num; - QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); - QCOMPARE(num, 789); -} - -QTEST_MAIN(tst_QPacketProtocol) - -#include "tst_qpacketprotocol.moc" diff --git a/tests/auto/declarative/shared/debugutil.cpp b/tests/auto/declarative/shared/debugutil.cpp deleted file mode 100644 index 99f8dcc..0000000 --- a/tests/auto/declarative/shared/debugutil.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include - -#include -#include - -#include "debugutil_p.h" - - -bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { - QEventLoop loop; - QTimer timer; - timer.setSingleShot(true); - QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - QObject::connect(receiver, member, &loop, SLOT(quit())); - timer.start(timeout); - loop.exec(); - return timer.isActive(); -} - -QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent) - : QDeclarativeDebugService(s, parent) -{ -} - -void QDeclarativeDebugTestService::messageReceived(const QByteArray &ba) -{ - sendMessage(ba); -} - -void QDeclarativeDebugTestService::statusChanged(Status) -{ - emit statusHasChanged(); -} - - -QDeclarativeDebugTestClient::QDeclarativeDebugTestClient(const QString &s, QDeclarativeDebugConnection *c) - : QDeclarativeDebugClient(s, c) -{ -} - -QByteArray QDeclarativeDebugTestClient::waitForResponse() -{ - lastMsg.clear(); - QDeclarativeDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); - if (lastMsg.isEmpty()) { - qWarning() << "tst_QDeclarativeDebugClient: no response from server!"; - return QByteArray(); - } - return lastMsg; -} - -void QDeclarativeDebugTestClient::statusChanged(Status stat) -{ - QCOMPARE(stat, status()); - emit statusHasChanged(); -} - -void QDeclarativeDebugTestClient::messageReceived(const QByteArray &ba) -{ - lastMsg = ba; - emit serverMessage(ba); -} diff --git a/tests/auto/declarative/shared/debugutil_p.h b/tests/auto/declarative/shared/debugutil_p.h deleted file mode 100644 index be8df86..0000000 --- a/tests/auto/declarative/shared/debugutil_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 -#include -#include -#include -#include -#include - -#include - -#include -#include - -class QDeclarativeDebugTest -{ -public: - static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); -}; - -class QDeclarativeDebugTestService : public QDeclarativeDebugService -{ - Q_OBJECT -public: - QDeclarativeDebugTestService(const QString &s, QObject *parent = 0); - -signals: - void statusHasChanged(); - -protected: - virtual void messageReceived(const QByteArray &ba); - virtual void statusChanged(Status status); -}; - -class QDeclarativeDebugTestClient : public QDeclarativeDebugClient -{ - Q_OBJECT -public: - QDeclarativeDebugTestClient(const QString &s, QDeclarativeDebugConnection *c); - - QByteArray waitForResponse(); - -signals: - void statusHasChanged(); - void serverMessage(const QByteArray &); - -protected: - virtual void statusChanged(Status status); - virtual void messageReceived(const QByteArray &ba); - -private: - QByteArray lastMsg; -}; - - -- 1.7.2.5