From a493a5e104579c0a7908fc600be1fd622d6447ae Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 17 Nov 2009 13:47:16 +1000 Subject: Move debugger tests out of debugger/ subdir --- tests/auto/declarative/debugger/debugger.pro | 5 - tests/auto/declarative/debugger/debugutil.cpp | 173 ----- tests/auto/declarative/debugger/debugutil_p.h | 142 ---- .../declarative/debugger/qmldebug/qmldebug.pro | 7 - .../declarative/debugger/qmldebug/tst_qmldebug.cpp | 831 --------------------- .../debugger/qmldebugclient/qmldebugclient.pro | 7 - .../debugger/qmldebugclient/tst_qmldebugclient.cpp | 156 ---- .../debugger/qmldebugservice/qmldebugservice.pro | 7 - .../qmldebugservice/tst_qmldebugservice.cpp | 189 ----- .../debugger/qpacketprotocol/qpacketprotocol.pro | 7 - .../qpacketprotocol/tst_qpacketprotocol.cpp | 270 ------- tests/auto/declarative/declarative.pro | 7 +- tests/auto/declarative/qmldebug/qmldebug.pro | 7 + tests/auto/declarative/qmldebug/tst_qmldebug.cpp | 831 +++++++++++++++++++++ .../declarative/qmldebugclient/qmldebugclient.pro | 7 + .../qmldebugclient/tst_qmldebugclient.cpp | 156 ++++ .../qmldebugservice/qmldebugservice.pro | 7 + .../qmldebugservice/tst_qmldebugservice.cpp | 189 +++++ .../qpacketprotocol/qpacketprotocol.pro | 7 + .../qpacketprotocol/tst_qpacketprotocol.cpp | 270 +++++++ 20 files changed, 1478 insertions(+), 1797 deletions(-) delete mode 100644 tests/auto/declarative/debugger/debugger.pro delete mode 100644 tests/auto/declarative/debugger/debugutil.cpp delete mode 100644 tests/auto/declarative/debugger/debugutil_p.h delete mode 100644 tests/auto/declarative/debugger/qmldebug/qmldebug.pro delete mode 100644 tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp delete mode 100644 tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro delete mode 100644 tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp delete mode 100644 tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro delete mode 100644 tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp delete mode 100644 tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro delete mode 100644 tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp create mode 100644 tests/auto/declarative/qmldebug/qmldebug.pro create mode 100644 tests/auto/declarative/qmldebug/tst_qmldebug.cpp create mode 100644 tests/auto/declarative/qmldebugclient/qmldebugclient.pro create mode 100644 tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp create mode 100644 tests/auto/declarative/qmldebugservice/qmldebugservice.pro create mode 100644 tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp create mode 100644 tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro create mode 100644 tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp diff --git a/tests/auto/declarative/debugger/debugger.pro b/tests/auto/declarative/debugger/debugger.pro deleted file mode 100644 index a341ca9..0000000 --- a/tests/auto/declarative/debugger/debugger.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS += qmldebug \ - qmldebugclient \ - qmldebugservice \ - qpacketprotocol diff --git a/tests/auto/declarative/debugger/debugutil.cpp b/tests/auto/declarative/debugger/debugutil.cpp deleted file mode 100644 index 7008529..0000000 --- a/tests/auto/declarative/debugger/debugutil.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include - -#include -#include - -#include "debugutil_p.h" - -bool QmlDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { - QEventLoop loop; - QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - QObject::connect(receiver, member, &loop, SLOT(quit())); - timer.start(timeout); - loop.exec(); - return timer.isActive(); -} - - -QmlDebugTestData::QmlDebugTestData(QEventLoop *el) - : exitCode(-1), loop(el) -{ -} - -QmlDebugTestData::~QmlDebugTestData() -{ - qDeleteAll(items); -} - -void QmlDebugTestData::testsFinished(int code) -{ - exitCode = code; - loop->quit(); -} - - - -QmlDebugTestService::QmlDebugTestService(const QString &s, QObject *parent) - : QmlDebugService(s, parent), enabled(false) -{ -} - -void QmlDebugTestService::messageReceived(const QByteArray &ba) -{ - sendMessage(ba); -} - -void QmlDebugTestService::enabledChanged(bool e) -{ - emit enabledStateChanged(); - enabled = e; -} - - -QmlDebugTestClient::QmlDebugTestClient(const QString &s, QmlDebugConnection *c) - : QmlDebugClient(s, c) -{ -} - -QByteArray QmlDebugTestClient::waitForResponse() -{ - QSignalSpy spy(this, SIGNAL(serverMessage(QByteArray))); - QmlDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); - if (spy.count() == 0) { - qWarning() << "tst_QmlDebugClient: no response from server!"; - return QByteArray(); - } - return spy.at(0).at(0).value(); -} - -void QmlDebugTestClient::messageReceived(const QByteArray &ba) -{ - emit serverMessage(ba); -} - - -tst_QmlDebug_Thread::tst_QmlDebug_Thread(QmlDebugTestData *data, QmlTestFactory *factory) - : m_ready(false), m_data(data), m_factory(factory) -{ -} - -void tst_QmlDebug_Thread::run() -{ - QTest::qWait(1000); - - QmlDebugConnection conn; - conn.connectToHost("127.0.0.1", 3768); - bool ok = conn.waitForConnected(5000); - Q_ASSERT(ok); - - while (!m_ready) - QTest::qWait(100); - - m_data->conn = &conn; - - Q_ASSERT(m_factory); - QObject *test = m_factory->createTest(m_data); - Q_ASSERT(test); - int code = QTest::qExec(test); - emit testsFinished(code); -} - - -int QmlDebugTest::runTests(QmlTestFactory *factory, const QList &qml) -{ - qputenv("QML_DEBUG_SERVER_PORT", "3768"); - - QEventLoop loop; - QmlDebugTestData data(&loop); - - tst_QmlDebug_Thread thread(&data, factory); - QObject::connect(&thread, SIGNAL(testsFinished(int)), &data, SLOT(testsFinished(int))); - thread.start(); - - QmlEngine engine; // blocks until client connects - - foreach (const QByteArray &code, qml) { - QmlComponent c(&engine, code, QUrl("file://")); - Q_ASSERT(c.isReady()); // fails if bad syntax - data.items << qobject_cast(c.create()); - } - - // start the test - data.engine = &engine; - thread.m_ready = true; - - loop.exec(); - - return data.exitCode; -} - - diff --git a/tests/auto/declarative/debugger/debugutil_p.h b/tests/auto/declarative/debugger/debugutil_p.h deleted file mode 100644 index 665aeda..0000000 --- a/tests/auto/declarative/debugger/debugutil_p.h +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - - -class QmlDebugTestData : public QObject -{ - Q_OBJECT -public: - QmlDebugTestData(QEventLoop *el); - - ~QmlDebugTestData(); - - QmlEngine *engine; - QmlDebugConnection *conn; - - int exitCode; - QEventLoop *loop; - - QList items; - -public slots: - void testsFinished(int code); -}; - - -class QmlTestFactory -{ -public: - QmlTestFactory() {} - virtual ~QmlTestFactory() {} - - virtual QObject *createTest(QmlDebugTestData *data) = 0; -}; - - -namespace QmlDebugTest { - - bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); - - int runTests(QmlTestFactory *factory, const QList &qml = QList()); -} - -class QmlDebugTestService : public QmlDebugService -{ - Q_OBJECT -public: - QmlDebugTestService(const QString &s, QObject *parent = 0); - bool enabled; - -signals: - void enabledStateChanged(); - -protected: - virtual void messageReceived(const QByteArray &ba); - - virtual void enabledChanged(bool e); -}; - -class QmlDebugTestClient : public QmlDebugClient -{ - Q_OBJECT -public: - QmlDebugTestClient(const QString &s, QmlDebugConnection *c); - - QByteArray waitForResponse(); - -signals: - void serverMessage(const QByteArray &); - -protected: - virtual void messageReceived(const QByteArray &ba); -}; - -class tst_QmlDebug_Thread : public QThread -{ - Q_OBJECT -public: - tst_QmlDebug_Thread(QmlDebugTestData *data, QmlTestFactory *factory); - - void run(); - - bool m_ready; - -signals: - void testsFinished(int); - -private: - QmlDebugTestData *m_data; - QmlTestFactory *m_factory; -}; - - diff --git a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro deleted file mode 100644 index 0af30e1..0000000 --- a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebug.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp deleted file mode 100644 index 70404f6..0000000 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ /dev/null @@ -1,831 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "../debugutil_p.h" - -Q_DECLARE_METATYPE(QmlDebugWatch::State) - - -class tst_QmlDebug : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebug(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - m_rootItem = data->items[0]; - } - -private: - QmlDebugObjectReference findRootObject(); - QmlDebugPropertyReference findProperty(const QList &props, const QString &name) const; - void waitForQuery(QmlDebugQuery *query); - - void recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const; - - void recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const; - void recursiveCompareContexts(const QmlDebugContextReference &a, const QmlDebugContextReference &b) const; - void compareProperties(const QmlDebugPropertyReference &a, const QmlDebugPropertyReference &b) const; - - QmlDebugConnection *m_conn; - QmlEngineDebug *m_dbg; - QmlEngine *m_engine; - QmlGraphicsItem *m_rootItem; - -private slots: - void initTestCase(); - - void watch_property(); - void watch_object(); - void watch_expression(); - void watch_expression_data(); - void watch_context(); - void watch_file(); - - void queryAvailableEngines(); - void queryRootContexts(); - void queryObject(); - void queryObject_data(); - void queryExpressionResult(); - void queryExpressionResult_data(); - - void tst_QmlDebugFileReference(); - void tst_QmlDebugEngineReference(); - void tst_QmlDebugObjectReference(); - void tst_QmlDebugContextReference(); - void tst_QmlDebugPropertyReference(); -}; - -QmlDebugObjectReference tst_QmlDebug::findRootObject() -{ - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - if (q_engines->engines().count() == 0) - return QmlDebugObjectReference(); - QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - if (q_context->rootContext().objects().count() == 0) - return QmlDebugObjectReference(); - QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); - waitForQuery(q_obj); - - QmlDebugObjectReference result = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - return result; -} - -QmlDebugPropertyReference tst_QmlDebug::findProperty(const QList &props, const QString &name) const -{ - foreach(const QmlDebugPropertyReference &p, props) { - if (p.name() == name) - return p; - } - return QmlDebugPropertyReference(); -} - -void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) -{ - QVERIFY(query); - QCOMPARE(query->parent(), this); - QVERIFY(query->state() == QmlDebugQuery::Waiting); - if (!QmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) - QFAIL("query timed out"); -} - -void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const -{ - const QMetaObject *meta = o->metaObject(); - - QmlType *type = QmlMetaType::qmlType(o->metaObject()); - QString className = type ? type->qmlTypeName() : QString(); - className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); - - QCOMPARE(oref.debugId(), QmlDebugService::idForObject(o)); - QCOMPARE(oref.name(), o->objectName()); - QCOMPARE(oref.className(), className); - QCOMPARE(oref.contextDebugId(), QmlDebugService::idForObject(qmlContext(o))); - - const QObjectList &children = o->children(); - for (int i=0; i= 0); - - QmlDebugObjectReference cref; - foreach (const QmlDebugObjectReference &ref, oref.children()) { - if (ref.debugId() == debugId) { - cref = ref; - break; - } - } - QVERIFY(cref.debugId() >= 0); - - if (recursive) - recursiveObjectTest(child, cref, true); - } - - foreach (const QmlDebugPropertyReference &p, oref.properties()) { - QCOMPARE(p.objectDebugId(), QmlDebugService::idForObject(o)); - - // signal properties are fake - they are generated from QmlBoundSignal children - if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { - QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); - QVERIFY(p.valueTypeName().isEmpty()); - QVERIFY(p.binding().isEmpty()); - QVERIFY(!p.hasNotifySignal()); - continue; - } - - QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); - - QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); - - if (pmeta.type() < QVariant::UserType) // TODO test complex types - QCOMPARE(p.value(), pmeta.read(o)); - - if (p.name() == "parent") - QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QmlGraphicsItem*"); - else - QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); - - QmlAbstractBinding *binding = QmlMetaProperty(o, p.name()).binding(); - if (binding) - QCOMPARE(binding->expression(), p.binding()); - - QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); - - QVERIFY(pmeta.isValid()); - } -} - -void tst_QmlDebug::recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const -{ - QCOMPARE(a.debugId(), b.debugId()); - QCOMPARE(a.className(), b.className()); - QCOMPARE(a.name(), b.name()); - QCOMPARE(a.contextDebugId(), b.contextDebugId()); - - QCOMPARE(a.source().url(), b.source().url()); - QCOMPARE(a.source().lineNumber(), b.source().lineNumber()); - QCOMPARE(a.source().columnNumber(), b.source().columnNumber()); - - QCOMPARE(a.properties().count(), b.properties().count()); - QCOMPARE(a.children().count(), b.children().count()); - - QList aprops = a.properties(); - QList bprops = b.properties(); - - for (int i=0; i(); -} - -void tst_QmlDebug::watch_property() -{ - QmlDebugObjectReference obj = findRootObject(); - QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); - - QmlDebugPropertyWatch *watch; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(prop, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugPropertyReference(), this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(prop, this); - QCOMPARE(watch->state(), QmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->name(), prop.name()); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - - int origWidth = m_rootItem->property("width").toInt(); - m_rootItem->setProperty("width", origWidth*2); - - // stateChanged() is received before valueChanged() - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - QCOMPARE(spy.count(), 1); - - m_dbg->removeWatch(watch); - delete watch; - - // restore original value and verify spy doesn't get additional signal since watch has been removed - m_rootItem->setProperty("width", origWidth); - QTest::qWait(100); - QCOMPARE(spy.count(), 1); - - QCOMPARE(spy.at(0).at(0).value(), prop.name().toUtf8()); - QCOMPARE(spy.at(0).at(1).value(), qVariantFromValue(origWidth*2)); -} - -void tst_QmlDebug::watch_object() -{ - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); - waitForQuery(q_obj); - - QmlDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - QmlDebugWatch *watch; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(obj, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugObjectReference(), this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, this); - QCOMPARE(watch->state(), QmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - - int origWidth = m_rootItem->property("width").toInt(); - int origHeight = m_rootItem->property("height").toInt(); - m_rootItem->setProperty("width", origWidth*2); - m_rootItem->setProperty("height", origHeight*2); - - // stateChanged() is received before any valueChanged() signals - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - QVERIFY(spy.count() > 0); - - int newWidth = -1; - int newHeight = -1; - for (int i=0; i() == "width") - newWidth = values[1].value().toInt(); - else if (values[0].value() == "height") - newHeight = values[1].value().toInt(); - - } - - m_dbg->removeWatch(watch); - delete watch; - - // since watch has been removed, restoring the original values should not trigger a valueChanged() - spy.clear(); - m_rootItem->setProperty("width", origWidth); - m_rootItem->setProperty("height", origHeight); - QTest::qWait(100); - QCOMPARE(spy.count(), 0); - - QCOMPARE(newWidth, origWidth * 2); - QCOMPARE(newHeight, origHeight * 2); -} - -void tst_QmlDebug::watch_expression() -{ - QFETCH(QString, expr); - QFETCH(int, increment); - QFETCH(int, incrementCount); - - int origWidth = m_rootItem->property("width").toInt(); - - QmlDebugObjectReference obj = findRootObject(); - - QmlDebugObjectExpressionWatch *watch; - - QmlEngineDebug unconnected(0); - watch = unconnected.addWatch(obj, expr, this); - QCOMPARE(watch->state(), QmlDebugWatch::Dead); - delete watch; - - watch = m_dbg->addWatch(QmlDebugObjectReference(), expr, this); - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(watch->state(), QmlDebugWatch::Inactive); - delete watch; - - watch = m_dbg->addWatch(obj, expr, this); - QCOMPARE(watch->state(), QmlDebugWatch::Waiting); - QCOMPARE(watch->objectDebugId(), obj.debugId()); - QCOMPARE(watch->expression(), expr); - - QSignalSpy spyState(watch, SIGNAL(stateChanged(QmlDebugWatch::State))); - - QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); - int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value - - int width = origWidth; - for (int i=0; i 0) { - width += increment; - m_rootItem->setProperty("width", width); - } - if (!QmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) - QFAIL("Did not receive valueChanged() for expression"); - } - - if (spyState.count() == 0) - QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); - QCOMPARE(spyState.count(), 1); - QCOMPARE(watch->state(), QmlDebugWatch::Active); - - m_dbg->removeWatch(watch); - delete watch; - - // restore original value and verify spy doesn't get a signal since watch has been removed - m_rootItem->setProperty("width", origWidth); - QTest::qWait(100); - QCOMPARE(spy.count(), expectedSpyCount); - - width = origWidth + increment; - for (int i=0; i().toInt(), width); - width += increment; - } -} - -void tst_QmlDebug::watch_expression_data() -{ - QTest::addColumn("expr"); - QTest::addColumn("increment"); - QTest::addColumn("incrementCount"); - - QTest::newRow("width") << "width" << 0 << 0; - QTest::newRow("width+10") << "width + 10" << 10 << 5; -} - -void tst_QmlDebug::watch_context() -{ - QmlDebugContextReference c; - QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(c, QString(), this)); -} - -void tst_QmlDebug::watch_file() -{ - QmlDebugFileReference f; - QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); - QVERIFY(!m_dbg->addWatch(f, this)); -} - -void tst_QmlDebug::queryAvailableEngines() -{ - QmlDebugEnginesQuery *q_engines; - - QmlEngineDebug unconnected(0); - q_engines = unconnected.queryAvailableEngines(0); - QCOMPARE(q_engines->state(), QmlDebugQuery::Error); - delete q_engines; - - q_engines = m_dbg->queryAvailableEngines(this); - delete q_engines; - - q_engines = m_dbg->queryAvailableEngines(this); - QVERIFY(q_engines->engines().isEmpty()); - waitForQuery(q_engines); - - // TODO test multiple engines - QList engines = q_engines->engines(); - QCOMPARE(engines.count(), 1); - - foreach(const QmlDebugEngineReference &e, engines) { - QCOMPARE(e.debugId(), QmlDebugService::idForObject(m_engine)); - QCOMPARE(e.name(), m_engine->objectName()); - } - - delete q_engines; -} - -void tst_QmlDebug::queryRootContexts() -{ - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - int engineId = q_engines->engines()[0].debugId(); - - QmlDebugRootContextQuery *q_context; - - QmlEngineDebug unconnected(0); - q_context = unconnected.queryRootContexts(engineId, this); - QCOMPARE(q_context->state(), QmlDebugQuery::Error); - delete q_context; - - q_context = m_dbg->queryRootContexts(engineId, this); - delete q_context; - - q_context = m_dbg->queryRootContexts(engineId, this); - waitForQuery(q_context); - - QmlContext *actualContext = m_engine->rootContext(); - QmlDebugContextReference context = q_context->rootContext(); - QCOMPARE(context.debugId(), QmlDebugService::idForObject(actualContext)); - QCOMPARE(context.name(), actualContext->objectName()); - - QCOMPARE(context.objects().count(), 2); // 2 qml component objects created for context in main() - - // root context query sends only root object data - it doesn't fill in - // the children or property info - QCOMPARE(context.objects()[0].properties().count(), 0); - QCOMPARE(context.objects()[0].children().count(), 0); - - QCOMPARE(context.contexts().count(), 1); - QVERIFY(context.contexts()[0].debugId() >= 0); - QCOMPARE(context.contexts()[0].name(), QString("tst_QmlDebug_childContext")); - - delete q_engines; - delete q_context; -} - -void tst_QmlDebug::queryObject() -{ - QFETCH(bool, recursive); - - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - - QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - QmlDebugObjectReference rootObject = q_context->rootContext().objects()[0]; - - QmlDebugObjectQuery *q_obj = 0; - - QmlEngineDebug unconnected(0); - q_obj = recursive ? unconnected.queryObjectRecursive(rootObject, this) : unconnected.queryObject(rootObject, this); - QCOMPARE(q_obj->state(), QmlDebugQuery::Error); - delete q_obj; - - q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); - delete q_obj; - - q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); - waitForQuery(q_obj); - - QmlDebugObjectReference obj = q_obj->object(); - - delete q_engines; - delete q_context; - delete q_obj; - - // check source as defined in main() - QmlDebugFileReference source = obj.source(); - QCOMPARE(source.url(), QUrl("file://")); - QCOMPARE(source.lineNumber(), 2); - QCOMPARE(source.columnNumber(), 1); - - // generically test all properties, children and childrens' properties - recursiveObjectTest(m_rootItem, obj, recursive); - - if (recursive) { - foreach(const QmlDebugObjectReference &child, obj.children()) - QVERIFY(child.properties().count() > 0); - - QmlDebugObjectReference rect; - QmlDebugObjectReference text; - foreach (const QmlDebugObjectReference &child, obj.children()) { - if (child.className() == "Rectangle") - rect = child; - else if (child.className() == "Text") - text = child; - } - - // test specific property values - QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500)); - QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600)); - QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue"))); - - QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue"))); - - } else { - foreach(const QmlDebugObjectReference &child, obj.children()) - QCOMPARE(child.properties().count(), 0); - } -} - -void tst_QmlDebug::queryObject_data() -{ - QTest::addColumn("recursive"); - - QTest::newRow("non-recursive") << false; - QTest::newRow("recursive") << true; -} - -void tst_QmlDebug::queryExpressionResult() -{ - QFETCH(QString, expr); - QFETCH(QVariant, result); - - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); // check immediate deletion is ok - - QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - int objectId = q_context->rootContext().objects()[0].debugId(); - - QmlDebugExpressionQuery *q_expr; - - QmlEngineDebug unconnected(0); - q_expr = unconnected.queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->state(), QmlDebugQuery::Error); - delete q_expr; - - q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - delete q_expr; - - q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->expression(), expr); - waitForQuery(q_expr); - - QCOMPARE(q_expr->result(), result); - - delete q_engines; - delete q_context; - delete q_expr; -} - -void tst_QmlDebug::queryExpressionResult_data() -{ - QTest::addColumn("expr"); - QTest::addColumn("result"); - - QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); - QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); - QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); -} - -void tst_QmlDebug::tst_QmlDebugFileReference() -{ - QmlDebugFileReference ref; - QVERIFY(ref.url().isEmpty()); - QCOMPARE(ref.lineNumber(), -1); - QCOMPARE(ref.columnNumber(), -1); - - ref.setUrl(QUrl("http://test")); - QCOMPARE(ref.url(), QUrl("http://test")); - ref.setLineNumber(1); - QCOMPARE(ref.lineNumber(), 1); - ref.setColumnNumber(1); - QCOMPARE(ref.columnNumber(), 1); - - QmlDebugFileReference copy(ref); - QmlDebugFileReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugFileReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.url(), ref.url()); - QCOMPARE(r.lineNumber(), ref.lineNumber()); - QCOMPARE(r.columnNumber(), ref.columnNumber()); - } -} - -void tst_QmlDebug::tst_QmlDebugEngineReference() -{ - QmlDebugEngineReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - - ref = QmlDebugEngineReference(1); - QCOMPARE(ref.debugId(), 1); - QVERIFY(ref.name().isEmpty()); - - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - ref = q_engines->engines()[0]; - delete q_engines; - - QmlDebugEngineReference copy(ref); - QmlDebugEngineReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugEngineReference &r, (QList() << copy << copyAssign)) { - QCOMPARE(r.debugId(), ref.debugId()); - QCOMPARE(r.name(), ref.name()); - } -} - -void tst_QmlDebug::tst_QmlDebugObjectReference() -{ - QmlDebugObjectReference ref; - QCOMPARE(ref.debugId(), -1); - QCOMPARE(ref.className(), QString()); - QCOMPARE(ref.name(), QString()); - QCOMPARE(ref.contextDebugId(), -1); - QVERIFY(ref.properties().isEmpty()); - QVERIFY(ref.children().isEmpty()); - - QmlDebugFileReference source = ref.source(); - QVERIFY(source.url().isEmpty()); - QVERIFY(source.lineNumber() < 0); - QVERIFY(source.columnNumber() < 0); - - ref = QmlDebugObjectReference(1); - QCOMPARE(ref.debugId(), 1); - - QmlDebugObjectReference rootObject = findRootObject(); - QmlDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); - waitForQuery(query); - ref = query->object(); - delete query; - - QVERIFY(ref.debugId() >= 0); - - QmlDebugObjectReference copy(ref); - QmlDebugObjectReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugObjectReference &r, (QList() << copy << copyAssign)) - recursiveCompareObjects(r, ref); -} - -void tst_QmlDebug::tst_QmlDebugContextReference() -{ - QmlDebugContextReference ref; - QCOMPARE(ref.debugId(), -1); - QVERIFY(ref.name().isEmpty()); - QVERIFY(ref.objects().isEmpty()); - QVERIFY(ref.contexts().isEmpty()); - - QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); - QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); - waitForQuery(q_context); - - ref = q_context->rootContext(); - delete q_engines; - delete q_context; - QVERIFY(ref.debugId() >= 0); - - QmlDebugContextReference copy(ref); - QmlDebugContextReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugContextReference &r, (QList() << copy << copyAssign)) - recursiveCompareContexts(r, ref); -} - -void tst_QmlDebug::tst_QmlDebugPropertyReference() -{ - QmlDebugObjectReference rootObject = findRootObject(); - QmlDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); - waitForQuery(query); - QmlDebugObjectReference obj = query->object(); - delete query; - - QmlDebugPropertyReference ref = findProperty(obj.properties(), "scale"); - QVERIFY(ref.objectDebugId() > 0); - QVERIFY(!ref.name().isEmpty()); - QVERIFY(!ref.value().isNull()); - QVERIFY(!ref.valueTypeName().isEmpty()); - QVERIFY(!ref.binding().isEmpty()); - QVERIFY(ref.hasNotifySignal()); - - QmlDebugPropertyReference copy(ref); - QmlDebugPropertyReference copyAssign; - copyAssign = ref; - foreach (const QmlDebugPropertyReference &r, (QList() << copy << copyAssign)) - compareProperties(r, ref); -} - - -class tst_QmlDebug_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) - { - QmlContext *c = new QmlContext(data->engine->rootContext()); - c->setObjectName("tst_QmlDebug_childContext"); - return new tst_QmlDebug(data); - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QList qml; - qml << "import Qt 4.6\n" - "Item {" - "width: 10; height: 20; scale: blueRect.scale;" - "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" - "Text { color: blueRect.color; }" - "MouseRegion {" - "onEntered: { print('hello') }" - "}" - "}"; - // add second component to test multiple root contexts - qml << "import Qt 4.6\n" - "Item {}"; - tst_QmlDebug_Factory factory; - return QmlDebugTest::runTests(&factory, qml); -} - -//QTEST_MAIN(tst_QmlDebug) - -#include "tst_qmldebug.moc" diff --git a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro b/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro deleted file mode 100644 index c0aa7b2..0000000 --- a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebugclient.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp deleted file mode 100644 index 6c4a1a3..0000000 --- a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include "../debugutil_p.h" - -class tst_QmlDebugClient : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebugClient(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - } - - QmlDebugConnection *m_conn; - QmlEngine *m_engine; - -private slots: - void name(); - void isEnabled(); - void setEnabled(); - void isConnected(); - void sendMessage(); -}; - -void tst_QmlDebugClient::name() -{ - QString name = "tst_QmlDebugClient::name()"; - - QmlDebugClient client(name, m_conn); - QCOMPARE(client.name(), name); -} - -void tst_QmlDebugClient::isEnabled() -{ - QmlDebugClient client("tst_QmlDebugClient::isEnabled()", m_conn); - QCOMPARE(client.isEnabled(), false); -} - -void tst_QmlDebugClient::setEnabled() -{ - QmlDebugTestService service("tst_QmlDebugClient::setEnabled()"); - QmlDebugTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); - - QCOMPARE(service.isEnabled(), false); - - client.setEnabled(true); - QCOMPARE(client.isEnabled(), true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), true); - - client.setEnabled(false); - QCOMPARE(client.isEnabled(), false); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), false); -} - -void tst_QmlDebugClient::isConnected() -{ - QmlDebugClient client1("tst_QmlDebugClient::isConnected() A", m_conn); - QCOMPARE(client1.isConnected(), true); - - QmlDebugConnection conn; - QmlDebugClient client2("tst_QmlDebugClient::isConnected() B", &conn); - QCOMPARE(client2.isConnected(), false); - - QmlDebugClient client3("tst_QmlDebugClient::isConnected() C", 0); - QCOMPARE(client3.isConnected(), false); - - // duplicate plugin name - QTest::ignoreMessage(QtWarningMsg, "QmlDebugClient: Conflicting plugin name \"tst_QmlDebugClient::isConnected() A\" "); - QmlDebugClient client4("tst_QmlDebugClient::isConnected() A", m_conn); - QCOMPARE(client4.isConnected(), false); -} - -void tst_QmlDebugClient::sendMessage() -{ - QmlDebugTestService service("tst_QmlDebugClient::sendMessage()"); - QmlDebugTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); -} - - -class tst_QmlDebugClient_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugClient(data); } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QmlDebugClient_Factory factory; - return QmlDebugTest::runTests(&factory); -} - -#include "tst_qmldebugclient.moc" diff --git a/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro b/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro deleted file mode 100644 index cce277a..0000000 --- a/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qmldebugservice.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp deleted file mode 100644 index 0c02929..0000000 --- a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include "../debugutil_p.h" - -class tst_QmlDebugService : public QObject -{ - Q_OBJECT - -public: - tst_QmlDebugService(QmlDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - } - - QmlDebugConnection *m_conn; - QmlEngine *m_engine; - -private slots: - void name(); - void isEnabled(); - void enabledChanged(); - void sendMessage(); - void idForObject(); - void objectForId(); - void objectToString(); -}; - -void tst_QmlDebugService::name() -{ - QString name = "tst_QmlDebugService::name()"; - - QmlDebugService service(name); - QCOMPARE(service.name(), name); -} - -void tst_QmlDebugService::isEnabled() -{ - QmlDebugTestService service("tst_QmlDebugService::isEnabled()", m_conn); - QCOMPARE(service.isEnabled(), false); - - QmlDebugTestClient client("tst_QmlDebugService::isEnabled()", m_conn); - client.setEnabled(true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.isEnabled(), true); - - QTest::ignoreMessage(QtWarningMsg, "QmlDebugService: Conflicting plugin name \"tst_QmlDebugService::isEnabled()\" "); - QmlDebugService duplicate("tst_QmlDebugService::isEnabled()", m_conn); - QCOMPARE(duplicate.isEnabled(), false); -} - -void tst_QmlDebugService::enabledChanged() -{ - QmlDebugTestService service("tst_QmlDebugService::enabledChanged()"); - QmlDebugTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); - - QCOMPARE(service.enabled, false); - - client.setEnabled(true); - QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); - QCOMPARE(service.enabled, true); -} - -void tst_QmlDebugService::sendMessage() -{ - QmlDebugTestService service("tst_QmlDebugService::sendMessage()"); - QmlDebugTestClient client("tst_QmlDebugService::sendMessage()", m_conn); - - QByteArray msg = "hello!"; - - client.sendMessage(msg); - QByteArray resp = client.waitForResponse(); - QCOMPARE(resp, msg); -} - -void tst_QmlDebugService::idForObject() -{ - QCOMPARE(QmlDebugService::idForObject(0), -1); - - QObject *objA = new QObject; - - int idA = QmlDebugService::idForObject(objA); - QVERIFY(idA >= 0); - QCOMPARE(QmlDebugService::objectForId(idA), objA); - - int idAA = QmlDebugService::idForObject(objA); - QCOMPARE(idAA, idA); - - QObject *objB = new QObject; - int idB = QmlDebugService::idForObject(objB); - QVERIFY(idB != idA); - QCOMPARE(QmlDebugService::objectForId(idB), objB); - - delete objA; - delete objB; -} - -void tst_QmlDebugService::objectForId() -{ - QCOMPARE(QmlDebugService::objectForId(-1), static_cast(0)); - QCOMPARE(QmlDebugService::objectForId(1), static_cast(0)); - - QObject *obj = new QObject; - int id = QmlDebugService::idForObject(obj); - QCOMPARE(QmlDebugService::objectForId(id), obj); - - delete obj; - QCOMPARE(QmlDebugService::objectForId(id), static_cast(0)); -} - -void tst_QmlDebugService::objectToString() -{ - QCOMPARE(QmlDebugService::objectToString(0), QString("NULL")); - - QObject *obj = new QObject; - QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: ")); - - obj->setObjectName("Hello"); - QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: Hello")); -} - - -class tst_QmlDebugService_Factory : public QmlTestFactory -{ -public: - QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugService(data); } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QmlDebugService_Factory factory; - return QmlDebugTest::runTests(&factory); -} - -#include "tst_qmldebugservice.moc" diff --git a/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro deleted file mode 100644 index 800e5e0..0000000 --- a/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += network declarative -macx:CONFIG -= app_bundle - -HEADERS += ../debugutil_p.h -SOURCES += tst_qpacketprotocol.cpp \ - ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp deleted file mode 100644 index 36b6317..0000000 --- a/tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "../debugutil_p.h" - -class tst_QPacketProtocol : public QObject -{ - Q_OBJECT - -private: - QTcpServer *m_server; - QTcpSocket *m_client; - QTcpSocket *m_serverConn; - -private slots: - void init(); - void cleanup(); - - void maximumPacketSize(); - void setMaximumPacketSize(); - void setMaximumPacketSize_data(); - void send(); - void send_data(); - void packetsAvailable(); - void packetsAvailable_data(); - void clear(); - void read(); - void device(); - - void tst_QPacket_clear(); -}; - -void tst_QPacketProtocol::init() -{ - m_server = new QTcpServer(this); - QVERIFY(m_server->listen()); - - m_client = new QTcpSocket(this); - m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); - - QVERIFY(m_client->waitForConnected()); - QVERIFY(m_server->waitForNewConnection()); - m_serverConn = m_server->nextPendingConnection(); -} - -void tst_QPacketProtocol::cleanup() -{ - delete m_client; - delete m_serverConn; - delete m_server; -} - -void tst_QPacketProtocol::maximumPacketSize() -{ - QPacketProtocol p(m_client); - QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); -} - -void tst_QPacketProtocol::setMaximumPacketSize() -{ - QFETCH(qint32, size); - QFETCH(qint32, expected); - - QPacketProtocol out(m_serverConn); - QCOMPARE(out.setMaximumPacketSize(size), expected); - - if (size == expected) { - QPacketProtocol in(m_client); - QByteArray b; - b.fill('a', size + 1); - out.send() << b.constData(); - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(invalidPacket()))); - } -} - -void tst_QPacketProtocol::setMaximumPacketSize_data() -{ - QTest::addColumn("size"); - QTest::addColumn("expected"); - - QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); - QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); - QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); -} - -void tst_QPacketProtocol::send() -{ - QFETCH(bool, useAutoSend); - - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QByteArray ba; - int num; - - if (useAutoSend) { - out.send() << "Hello world" << 123; - } else { - QPacket packet; - packet << "Hello world" << 123; - out.send(packet); - } - - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p = in.read(); - p >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world") + '\0'); - QCOMPARE(num, 123); -} - -void tst_QPacketProtocol::send_data() -{ - QTest::addColumn("useAutoSend"); - - QTest::newRow("auto send") << true; - QTest::newRow("no auto send") << false; -} - -void tst_QPacketProtocol::packetsAvailable() -{ - QFETCH(int, packetCount); - - QPacketProtocol out(m_client); - QPacketProtocol in(m_serverConn); - - QCOMPARE(out.packetsAvailable(), qint64(0)); - QCOMPARE(in.packetsAvailable(), qint64(0)); - - for (int i=0; i("packetCount"); - - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("10") << 10; -} - -void tst_QPacketProtocol::clear() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - out.send() << 123; - out.send() << 456; - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - in.clear(); - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::read() -{ - QPacketProtocol in(m_client); - QPacketProtocol out(m_serverConn); - - QVERIFY(in.read().isEmpty()); - - out.send() << 123; - out.send() << 456; - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - int num; - - QPacket p1 = in.read(); - QVERIFY(!p1.isEmpty()); - p1 >> num; - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - QVERIFY(!p2.isEmpty()); - p2 >> num; - QCOMPARE(num, 456); - - QVERIFY(in.read().isEmpty()); -} - -void tst_QPacketProtocol::device() -{ - QPacketProtocol p(m_client); - QCOMPARE(p.device(), m_client); -} - -void tst_QPacketProtocol::tst_QPacket_clear() -{ - QPacketProtocol protocol(m_client); - - QPacket packet; - - packet << "Hello world!" << 123; - protocol.send(packet); - - packet.clear(); - QVERIFY(packet.isEmpty()); - packet << "Goodbyte world!" << 789; - protocol.send(packet); - - QByteArray ba; - int num; - QPacketProtocol in(m_serverConn); - QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); - - QPacket p1 = in.read(); - p1 >> ba >> num; - QCOMPARE(ba, QByteArray("Hello world!") + '\0'); - QCOMPARE(num, 123); - - QPacket p2 = in.read(); - p2 >> ba >> num; - QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); - QCOMPARE(num, 789); -} - -QTEST_MAIN(tst_QPacketProtocol) - -#include "tst_qpacketprotocol.moc" diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index ec2c7d0..c45a05e 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -2,10 +2,7 @@ TEMPLATE = subdirs SUBDIRS += \ anchors \ # Cover animatedimage \ # Cover - animations \ # Cover - behaviors \ # Cover datetimeformatter \ # Cover - debugger \ # Cover examples \ layouts \ # Cover numberformatter \ # Cover @@ -15,6 +12,9 @@ SUBDIRS += \ qmlbinding \ # Cover qmlconnection \ # Cover qmlcontext \ # Cover + qmldebug \ # Cover + qmldebugclient \ # Cover + qmldebugservice \ # Cover qmldom \ # Cover qmleasefollow \ # Cover qmlecmascript \ # Cover @@ -49,6 +49,7 @@ SUBDIRS += \ qmlsystempalette \ # Cover qmltimer \ # Cover qmlxmllistmodel \ # Cover + qpacketprotocol \ # Cover repeater \ # Cover sql \ # Cover states \ # Cover diff --git a/tests/auto/declarative/qmldebug/qmldebug.pro b/tests/auto/declarative/qmldebug/qmldebug.pro new file mode 100644 index 0000000..f79829d --- /dev/null +++ b/tests/auto/declarative/qmldebug/qmldebug.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebug.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp new file mode 100644 index 0000000..6916cc9 --- /dev/null +++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp @@ -0,0 +1,831 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "../shared/debugutil_p.h" + +Q_DECLARE_METATYPE(QmlDebugWatch::State) + + +class tst_QmlDebug : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebug(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + m_rootItem = data->items[0]; + } + +private: + QmlDebugObjectReference findRootObject(); + QmlDebugPropertyReference findProperty(const QList &props, const QString &name) const; + void waitForQuery(QmlDebugQuery *query); + + void recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const; + + void recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const; + void recursiveCompareContexts(const QmlDebugContextReference &a, const QmlDebugContextReference &b) const; + void compareProperties(const QmlDebugPropertyReference &a, const QmlDebugPropertyReference &b) const; + + QmlDebugConnection *m_conn; + QmlEngineDebug *m_dbg; + QmlEngine *m_engine; + QmlGraphicsItem *m_rootItem; + +private slots: + void initTestCase(); + + void watch_property(); + void watch_object(); + void watch_expression(); + void watch_expression_data(); + void watch_context(); + void watch_file(); + + void queryAvailableEngines(); + void queryRootContexts(); + void queryObject(); + void queryObject_data(); + void queryExpressionResult(); + void queryExpressionResult_data(); + + void tst_QmlDebugFileReference(); + void tst_QmlDebugEngineReference(); + void tst_QmlDebugObjectReference(); + void tst_QmlDebugContextReference(); + void tst_QmlDebugPropertyReference(); +}; + +QmlDebugObjectReference tst_QmlDebug::findRootObject() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + if (q_engines->engines().count() == 0) + return QmlDebugObjectReference(); + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + if (q_context->rootContext().objects().count() == 0) + return QmlDebugObjectReference(); + QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); + waitForQuery(q_obj); + + QmlDebugObjectReference result = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + return result; +} + +QmlDebugPropertyReference tst_QmlDebug::findProperty(const QList &props, const QString &name) const +{ + foreach(const QmlDebugPropertyReference &p, props) { + if (p.name() == name) + return p; + } + return QmlDebugPropertyReference(); +} + +void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) +{ + QVERIFY(query); + QCOMPARE(query->parent(), this); + QVERIFY(query->state() == QmlDebugQuery::Waiting); + if (!QmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) + QFAIL("query timed out"); +} + +void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const +{ + const QMetaObject *meta = o->metaObject(); + + QmlType *type = QmlMetaType::qmlType(o->metaObject()); + QString className = type ? type->qmlTypeName() : QString(); + className = className.mid(className.lastIndexOf(QLatin1Char('/'))+1); + + QCOMPARE(oref.debugId(), QmlDebugService::idForObject(o)); + QCOMPARE(oref.name(), o->objectName()); + QCOMPARE(oref.className(), className); + QCOMPARE(oref.contextDebugId(), QmlDebugService::idForObject(qmlContext(o))); + + const QObjectList &children = o->children(); + for (int i=0; i= 0); + + QmlDebugObjectReference cref; + foreach (const QmlDebugObjectReference &ref, oref.children()) { + if (ref.debugId() == debugId) { + cref = ref; + break; + } + } + QVERIFY(cref.debugId() >= 0); + + if (recursive) + recursiveObjectTest(child, cref, true); + } + + foreach (const QmlDebugPropertyReference &p, oref.properties()) { + QCOMPARE(p.objectDebugId(), QmlDebugService::idForObject(o)); + + // signal properties are fake - they are generated from QmlBoundSignal children + if (p.name().startsWith("on") && p.name().length() > 2 && p.name()[2].isUpper()) { + QVERIFY(p.value().toString().startsWith('{') && p.value().toString().endsWith('}')); + QVERIFY(p.valueTypeName().isEmpty()); + QVERIFY(p.binding().isEmpty()); + QVERIFY(!p.hasNotifySignal()); + continue; + } + + QMetaProperty pmeta = meta->property(meta->indexOfProperty(p.name().toUtf8().constData())); + + QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); + + if (pmeta.type() < QVariant::UserType) // TODO test complex types + QCOMPARE(p.value(), pmeta.read(o)); + + if (p.name() == "parent") + QVERIFY(p.valueTypeName() == "QGraphicsObject*" || p.valueTypeName() == "QmlGraphicsItem*"); + else + QCOMPARE(p.valueTypeName(), QString::fromUtf8(pmeta.typeName())); + + QmlAbstractBinding *binding = QmlMetaProperty(o, p.name()).binding(); + if (binding) + QCOMPARE(binding->expression(), p.binding()); + + QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + + QVERIFY(pmeta.isValid()); + } +} + +void tst_QmlDebug::recursiveCompareObjects(const QmlDebugObjectReference &a, const QmlDebugObjectReference &b) const +{ + QCOMPARE(a.debugId(), b.debugId()); + QCOMPARE(a.className(), b.className()); + QCOMPARE(a.name(), b.name()); + QCOMPARE(a.contextDebugId(), b.contextDebugId()); + + QCOMPARE(a.source().url(), b.source().url()); + QCOMPARE(a.source().lineNumber(), b.source().lineNumber()); + QCOMPARE(a.source().columnNumber(), b.source().columnNumber()); + + QCOMPARE(a.properties().count(), b.properties().count()); + QCOMPARE(a.children().count(), b.children().count()); + + QList aprops = a.properties(); + QList bprops = b.properties(); + + for (int i=0; i(); +} + +void tst_QmlDebug::watch_property() +{ + QmlDebugObjectReference obj = findRootObject(); + QmlDebugPropertyReference prop = findProperty(obj.properties(), "width"); + + QmlDebugPropertyWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(prop, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugPropertyReference(), this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(prop, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->name(), prop.name()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + + int origWidth = m_rootItem->property("width").toInt(); + m_rootItem->setProperty("width", origWidth*2); + + // stateChanged() is received before valueChanged() + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + QCOMPARE(spy.count(), 1); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get additional signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.at(0).at(0).value(), prop.name().toUtf8()); + QCOMPARE(spy.at(0).at(1).value(), qVariantFromValue(origWidth*2)); +} + +void tst_QmlDebug::watch_object() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + QmlDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this); + waitForQuery(q_obj); + + QmlDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + QmlDebugWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugObjectReference(), this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + + int origWidth = m_rootItem->property("width").toInt(); + int origHeight = m_rootItem->property("height").toInt(); + m_rootItem->setProperty("width", origWidth*2); + m_rootItem->setProperty("height", origHeight*2); + + // stateChanged() is received before any valueChanged() signals + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + QVERIFY(spy.count() > 0); + + int newWidth = -1; + int newHeight = -1; + for (int i=0; i() == "width") + newWidth = values[1].value().toInt(); + else if (values[0].value() == "height") + newHeight = values[1].value().toInt(); + + } + + m_dbg->removeWatch(watch); + delete watch; + + // since watch has been removed, restoring the original values should not trigger a valueChanged() + spy.clear(); + m_rootItem->setProperty("width", origWidth); + m_rootItem->setProperty("height", origHeight); + QTest::qWait(100); + QCOMPARE(spy.count(), 0); + + QCOMPARE(newWidth, origWidth * 2); + QCOMPARE(newHeight, origHeight * 2); +} + +void tst_QmlDebug::watch_expression() +{ + QFETCH(QString, expr); + QFETCH(int, increment); + QFETCH(int, incrementCount); + + int origWidth = m_rootItem->property("width").toInt(); + + QmlDebugObjectReference obj = findRootObject(); + + QmlDebugObjectExpressionWatch *watch; + + QmlEngineDebug unconnected(0); + watch = unconnected.addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Dead); + delete watch; + + watch = m_dbg->addWatch(QmlDebugObjectReference(), expr, this); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Inactive); + delete watch; + + watch = m_dbg->addWatch(obj, expr, this); + QCOMPARE(watch->state(), QmlDebugWatch::Waiting); + QCOMPARE(watch->objectDebugId(), obj.debugId()); + QCOMPARE(watch->expression(), expr); + + QSignalSpy spyState(watch, SIGNAL(stateChanged(QmlDebugWatch::State))); + + QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant))); + int expectedSpyCount = incrementCount + 1; // should also get signal with expression's initial value + + int width = origWidth; + for (int i=0; i 0) { + width += increment; + m_rootItem->setProperty("width", width); + } + if (!QmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) + QFAIL("Did not receive valueChanged() for expression"); + } + + if (spyState.count() == 0) + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(spyState.count(), 1); + QCOMPARE(watch->state(), QmlDebugWatch::Active); + + m_dbg->removeWatch(watch); + delete watch; + + // restore original value and verify spy doesn't get a signal since watch has been removed + m_rootItem->setProperty("width", origWidth); + QTest::qWait(100); + QCOMPARE(spy.count(), expectedSpyCount); + + width = origWidth + increment; + for (int i=0; i().toInt(), width); + width += increment; + } +} + +void tst_QmlDebug::watch_expression_data() +{ + QTest::addColumn("expr"); + QTest::addColumn("increment"); + QTest::addColumn("incrementCount"); + + QTest::newRow("width") << "width" << 0 << 0; + QTest::newRow("width+10") << "width + 10" << 10 << 5; +} + +void tst_QmlDebug::watch_context() +{ + QmlDebugContextReference c; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(c, QString(), this)); +} + +void tst_QmlDebug::watch_file() +{ + QmlDebugFileReference f; + QTest::ignoreMessage(QtWarningMsg, "QmlEngineDebug::addWatch(): Not implemented"); + QVERIFY(!m_dbg->addWatch(f, this)); +} + +void tst_QmlDebug::queryAvailableEngines() +{ + QmlDebugEnginesQuery *q_engines; + + QmlEngineDebug unconnected(0); + q_engines = unconnected.queryAvailableEngines(0); + QCOMPARE(q_engines->state(), QmlDebugQuery::Error); + delete q_engines; + + q_engines = m_dbg->queryAvailableEngines(this); + delete q_engines; + + q_engines = m_dbg->queryAvailableEngines(this); + QVERIFY(q_engines->engines().isEmpty()); + waitForQuery(q_engines); + + // TODO test multiple engines + QList engines = q_engines->engines(); + QCOMPARE(engines.count(), 1); + + foreach(const QmlDebugEngineReference &e, engines) { + QCOMPARE(e.debugId(), QmlDebugService::idForObject(m_engine)); + QCOMPARE(e.name(), m_engine->objectName()); + } + + delete q_engines; +} + +void tst_QmlDebug::queryRootContexts() +{ + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + int engineId = q_engines->engines()[0].debugId(); + + QmlDebugRootContextQuery *q_context; + + QmlEngineDebug unconnected(0); + q_context = unconnected.queryRootContexts(engineId, this); + QCOMPARE(q_context->state(), QmlDebugQuery::Error); + delete q_context; + + q_context = m_dbg->queryRootContexts(engineId, this); + delete q_context; + + q_context = m_dbg->queryRootContexts(engineId, this); + waitForQuery(q_context); + + QmlContext *actualContext = m_engine->rootContext(); + QmlDebugContextReference context = q_context->rootContext(); + QCOMPARE(context.debugId(), QmlDebugService::idForObject(actualContext)); + QCOMPARE(context.name(), actualContext->objectName()); + + QCOMPARE(context.objects().count(), 2); // 2 qml component objects created for context in main() + + // root context query sends only root object data - it doesn't fill in + // the children or property info + QCOMPARE(context.objects()[0].properties().count(), 0); + QCOMPARE(context.objects()[0].children().count(), 0); + + QCOMPARE(context.contexts().count(), 1); + QVERIFY(context.contexts()[0].debugId() >= 0); + QCOMPARE(context.contexts()[0].name(), QString("tst_QmlDebug_childContext")); + + delete q_engines; + delete q_context; +} + +void tst_QmlDebug::queryObject() +{ + QFETCH(bool, recursive); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + QmlDebugObjectReference rootObject = q_context->rootContext().objects()[0]; + + QmlDebugObjectQuery *q_obj = 0; + + QmlEngineDebug unconnected(0); + q_obj = recursive ? unconnected.queryObjectRecursive(rootObject, this) : unconnected.queryObject(rootObject, this); + QCOMPARE(q_obj->state(), QmlDebugQuery::Error); + delete q_obj; + + q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); + delete q_obj; + + q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this); + waitForQuery(q_obj); + + QmlDebugObjectReference obj = q_obj->object(); + + delete q_engines; + delete q_context; + delete q_obj; + + // check source as defined in main() + QmlDebugFileReference source = obj.source(); + QCOMPARE(source.url(), QUrl("file://")); + QCOMPARE(source.lineNumber(), 2); + QCOMPARE(source.columnNumber(), 1); + + // generically test all properties, children and childrens' properties + recursiveObjectTest(m_rootItem, obj, recursive); + + if (recursive) { + foreach(const QmlDebugObjectReference &child, obj.children()) + QVERIFY(child.properties().count() > 0); + + QmlDebugObjectReference rect; + QmlDebugObjectReference text; + foreach (const QmlDebugObjectReference &child, obj.children()) { + if (child.className() == "Rectangle") + rect = child; + else if (child.className() == "Text") + text = child; + } + + // test specific property values + QCOMPARE(findProperty(rect.properties(), "width").value(), qVariantFromValue(500)); + QCOMPARE(findProperty(rect.properties(), "height").value(), qVariantFromValue(600)); + QCOMPARE(findProperty(rect.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + + QCOMPARE(findProperty(text.properties(), "color").value(), qVariantFromValue(QColor("blue"))); + + } else { + foreach(const QmlDebugObjectReference &child, obj.children()) + QCOMPARE(child.properties().count(), 0); + } +} + +void tst_QmlDebug::queryObject_data() +{ + QTest::addColumn("recursive"); + + QTest::newRow("non-recursive") << false; + QTest::newRow("recursive") << true; +} + +void tst_QmlDebug::queryExpressionResult() +{ + QFETCH(QString, expr); + QFETCH(QVariant, result); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); // check immediate deletion is ok + + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + int objectId = q_context->rootContext().objects()[0].debugId(); + + QmlDebugExpressionQuery *q_expr; + + QmlEngineDebug unconnected(0); + q_expr = unconnected.queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->state(), QmlDebugQuery::Error); + delete q_expr; + + q_expr = m_dbg->queryExpressionResult(objectId, expr, this); + delete q_expr; + + q_expr = m_dbg->queryExpressionResult(objectId, expr, this); + QCOMPARE(q_expr->expression(), expr); + waitForQuery(q_expr); + + QCOMPARE(q_expr->result(), result); + + delete q_engines; + delete q_context; + delete q_expr; +} + +void tst_QmlDebug::queryExpressionResult_data() +{ + QTest::addColumn("expr"); + QTest::addColumn("result"); + + QTest::newRow("width + 50") << "width + 50" << qVariantFromValue(60); + QTest::newRow("blueRect.width") << "blueRect.width" << qVariantFromValue(500); + QTest::newRow("bad expr") << "aeaef" << qVariantFromValue(QString("")); +} + +void tst_QmlDebug::tst_QmlDebugFileReference() +{ + QmlDebugFileReference ref; + QVERIFY(ref.url().isEmpty()); + QCOMPARE(ref.lineNumber(), -1); + QCOMPARE(ref.columnNumber(), -1); + + ref.setUrl(QUrl("http://test")); + QCOMPARE(ref.url(), QUrl("http://test")); + ref.setLineNumber(1); + QCOMPARE(ref.lineNumber(), 1); + ref.setColumnNumber(1); + QCOMPARE(ref.columnNumber(), 1); + + QmlDebugFileReference copy(ref); + QmlDebugFileReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugFileReference &r, (QList() << copy << copyAssign)) { + QCOMPARE(r.url(), ref.url()); + QCOMPARE(r.lineNumber(), ref.lineNumber()); + QCOMPARE(r.columnNumber(), ref.columnNumber()); + } +} + +void tst_QmlDebug::tst_QmlDebugEngineReference() +{ + QmlDebugEngineReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + + ref = QmlDebugEngineReference(1); + QCOMPARE(ref.debugId(), 1); + QVERIFY(ref.name().isEmpty()); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + ref = q_engines->engines()[0]; + delete q_engines; + + QmlDebugEngineReference copy(ref); + QmlDebugEngineReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugEngineReference &r, (QList() << copy << copyAssign)) { + QCOMPARE(r.debugId(), ref.debugId()); + QCOMPARE(r.name(), ref.name()); + } +} + +void tst_QmlDebug::tst_QmlDebugObjectReference() +{ + QmlDebugObjectReference ref; + QCOMPARE(ref.debugId(), -1); + QCOMPARE(ref.className(), QString()); + QCOMPARE(ref.name(), QString()); + QCOMPARE(ref.contextDebugId(), -1); + QVERIFY(ref.properties().isEmpty()); + QVERIFY(ref.children().isEmpty()); + + QmlDebugFileReference source = ref.source(); + QVERIFY(source.url().isEmpty()); + QVERIFY(source.lineNumber() < 0); + QVERIFY(source.columnNumber() < 0); + + ref = QmlDebugObjectReference(1); + QCOMPARE(ref.debugId(), 1); + + QmlDebugObjectReference rootObject = findRootObject(); + QmlDebugObjectQuery *query = m_dbg->queryObjectRecursive(rootObject, this); + waitForQuery(query); + ref = query->object(); + delete query; + + QVERIFY(ref.debugId() >= 0); + + QmlDebugObjectReference copy(ref); + QmlDebugObjectReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugObjectReference &r, (QList() << copy << copyAssign)) + recursiveCompareObjects(r, ref); +} + +void tst_QmlDebug::tst_QmlDebugContextReference() +{ + QmlDebugContextReference ref; + QCOMPARE(ref.debugId(), -1); + QVERIFY(ref.name().isEmpty()); + QVERIFY(ref.objects().isEmpty()); + QVERIFY(ref.contexts().isEmpty()); + + QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); + waitForQuery(q_engines); + QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); + waitForQuery(q_context); + + ref = q_context->rootContext(); + delete q_engines; + delete q_context; + QVERIFY(ref.debugId() >= 0); + + QmlDebugContextReference copy(ref); + QmlDebugContextReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugContextReference &r, (QList() << copy << copyAssign)) + recursiveCompareContexts(r, ref); +} + +void tst_QmlDebug::tst_QmlDebugPropertyReference() +{ + QmlDebugObjectReference rootObject = findRootObject(); + QmlDebugObjectQuery *query = m_dbg->queryObject(rootObject, this); + waitForQuery(query); + QmlDebugObjectReference obj = query->object(); + delete query; + + QmlDebugPropertyReference ref = findProperty(obj.properties(), "scale"); + QVERIFY(ref.objectDebugId() > 0); + QVERIFY(!ref.name().isEmpty()); + QVERIFY(!ref.value().isNull()); + QVERIFY(!ref.valueTypeName().isEmpty()); + QVERIFY(!ref.binding().isEmpty()); + QVERIFY(ref.hasNotifySignal()); + + QmlDebugPropertyReference copy(ref); + QmlDebugPropertyReference copyAssign; + copyAssign = ref; + foreach (const QmlDebugPropertyReference &r, (QList() << copy << copyAssign)) + compareProperties(r, ref); +} + + +class tst_QmlDebug_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) + { + QmlContext *c = new QmlContext(data->engine->rootContext()); + c->setObjectName("tst_QmlDebug_childContext"); + return new tst_QmlDebug(data); + } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QList qml; + qml << "import Qt 4.6\n" + "Item {" + "width: 10; height: 20; scale: blueRect.scale;" + "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" + "Text { color: blueRect.color; }" + "MouseRegion {" + "onEntered: { print('hello') }" + "}" + "}"; + // add second component to test multiple root contexts + qml << "import Qt 4.6\n" + "Item {}"; + tst_QmlDebug_Factory factory; + return QmlDebugTest::runTests(&factory, qml); +} + +//QTEST_MAIN(tst_QmlDebug) + +#include "tst_qmldebug.moc" diff --git a/tests/auto/declarative/qmldebugclient/qmldebugclient.pro b/tests/auto/declarative/qmldebugclient/qmldebugclient.pro new file mode 100644 index 0000000..36aa818 --- /dev/null +++ b/tests/auto/declarative/qmldebugclient/qmldebugclient.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebugclient.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp new file mode 100644 index 0000000..8325731 --- /dev/null +++ b/tests/auto/declarative/qmldebugclient/tst_qmldebugclient.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "../shared/debugutil_p.h" + +class tst_QmlDebugClient : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebugClient(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } + + QmlDebugConnection *m_conn; + QmlEngine *m_engine; + +private slots: + void name(); + void isEnabled(); + void setEnabled(); + void isConnected(); + void sendMessage(); +}; + +void tst_QmlDebugClient::name() +{ + QString name = "tst_QmlDebugClient::name()"; + + QmlDebugClient client(name, m_conn); + QCOMPARE(client.name(), name); +} + +void tst_QmlDebugClient::isEnabled() +{ + QmlDebugClient client("tst_QmlDebugClient::isEnabled()", m_conn); + QCOMPARE(client.isEnabled(), false); +} + +void tst_QmlDebugClient::setEnabled() +{ + QmlDebugTestService service("tst_QmlDebugClient::setEnabled()"); + QmlDebugTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); + + QCOMPARE(service.isEnabled(), false); + + client.setEnabled(true); + QCOMPARE(client.isEnabled(), true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), true); + + client.setEnabled(false); + QCOMPARE(client.isEnabled(), false); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), false); +} + +void tst_QmlDebugClient::isConnected() +{ + QmlDebugClient client1("tst_QmlDebugClient::isConnected() A", m_conn); + QCOMPARE(client1.isConnected(), true); + + QmlDebugConnection conn; + QmlDebugClient client2("tst_QmlDebugClient::isConnected() B", &conn); + QCOMPARE(client2.isConnected(), false); + + QmlDebugClient client3("tst_QmlDebugClient::isConnected() C", 0); + QCOMPARE(client3.isConnected(), false); + + // duplicate plugin name + QTest::ignoreMessage(QtWarningMsg, "QmlDebugClient: Conflicting plugin name \"tst_QmlDebugClient::isConnected() A\" "); + QmlDebugClient client4("tst_QmlDebugClient::isConnected() A", m_conn); + QCOMPARE(client4.isConnected(), false); +} + +void tst_QmlDebugClient::sendMessage() +{ + QmlDebugTestService service("tst_QmlDebugClient::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + + +class tst_QmlDebugClient_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugClient(data); } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + tst_QmlDebugClient_Factory factory; + return QmlDebugTest::runTests(&factory); +} + +#include "tst_qmldebugclient.moc" diff --git a/tests/auto/declarative/qmldebugservice/qmldebugservice.pro b/tests/auto/declarative/qmldebugservice/qmldebugservice.pro new file mode 100644 index 0000000..9995f1f --- /dev/null +++ b/tests/auto/declarative/qmldebugservice/qmldebugservice.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qmldebugservice.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp new file mode 100644 index 0000000..625d1f5 --- /dev/null +++ b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "../shared/debugutil_p.h" + +class tst_QmlDebugService : public QObject +{ + Q_OBJECT + +public: + tst_QmlDebugService(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } + + QmlDebugConnection *m_conn; + QmlEngine *m_engine; + +private slots: + void name(); + void isEnabled(); + void enabledChanged(); + void sendMessage(); + void idForObject(); + void objectForId(); + void objectToString(); +}; + +void tst_QmlDebugService::name() +{ + QString name = "tst_QmlDebugService::name()"; + + QmlDebugService service(name); + QCOMPARE(service.name(), name); +} + +void tst_QmlDebugService::isEnabled() +{ + QmlDebugTestService service("tst_QmlDebugService::isEnabled()", m_conn); + QCOMPARE(service.isEnabled(), false); + + QmlDebugTestClient client("tst_QmlDebugService::isEnabled()", m_conn); + client.setEnabled(true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.isEnabled(), true); + + QTest::ignoreMessage(QtWarningMsg, "QmlDebugService: Conflicting plugin name \"tst_QmlDebugService::isEnabled()\" "); + QmlDebugService duplicate("tst_QmlDebugService::isEnabled()", m_conn); + QCOMPARE(duplicate.isEnabled(), false); +} + +void tst_QmlDebugService::enabledChanged() +{ + QmlDebugTestService service("tst_QmlDebugService::enabledChanged()"); + QmlDebugTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); + + QCOMPARE(service.enabled, false); + + client.setEnabled(true); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QCOMPARE(service.enabled, true); +} + +void tst_QmlDebugService::sendMessage() +{ + QmlDebugTestService service("tst_QmlDebugService::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugService::sendMessage()", m_conn); + + QByteArray msg = "hello!"; + + client.sendMessage(msg); + QByteArray resp = client.waitForResponse(); + QCOMPARE(resp, msg); +} + +void tst_QmlDebugService::idForObject() +{ + QCOMPARE(QmlDebugService::idForObject(0), -1); + + QObject *objA = new QObject; + + int idA = QmlDebugService::idForObject(objA); + QVERIFY(idA >= 0); + QCOMPARE(QmlDebugService::objectForId(idA), objA); + + int idAA = QmlDebugService::idForObject(objA); + QCOMPARE(idAA, idA); + + QObject *objB = new QObject; + int idB = QmlDebugService::idForObject(objB); + QVERIFY(idB != idA); + QCOMPARE(QmlDebugService::objectForId(idB), objB); + + delete objA; + delete objB; +} + +void tst_QmlDebugService::objectForId() +{ + QCOMPARE(QmlDebugService::objectForId(-1), static_cast(0)); + QCOMPARE(QmlDebugService::objectForId(1), static_cast(0)); + + QObject *obj = new QObject; + int id = QmlDebugService::idForObject(obj); + QCOMPARE(QmlDebugService::objectForId(id), obj); + + delete obj; + QCOMPARE(QmlDebugService::objectForId(id), static_cast(0)); +} + +void tst_QmlDebugService::objectToString() +{ + QCOMPARE(QmlDebugService::objectToString(0), QString("NULL")); + + QObject *obj = new QObject; + QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: ")); + + obj->setObjectName("Hello"); + QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: Hello")); +} + + +class tst_QmlDebugService_Factory : public QmlTestFactory +{ +public: + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugService(data); } +}; + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + tst_QmlDebugService_Factory factory; + return QmlDebugTest::runTests(&factory); +} + +#include "tst_qmldebugservice.moc" diff --git a/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro b/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro new file mode 100644 index 0000000..f42cecc --- /dev/null +++ b/tests/auto/declarative/qpacketprotocol/qpacketprotocol.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += network declarative +macx:CONFIG -= app_bundle + +HEADERS += ../shared/debugutil_p.h +SOURCES += tst_qpacketprotocol.cpp \ + ../shared/debugutil.cpp diff --git a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp new file mode 100644 index 0000000..b54f133 --- /dev/null +++ b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp @@ -0,0 +1,270 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../shared/debugutil_p.h" + +class tst_QPacketProtocol : public QObject +{ + Q_OBJECT + +private: + QTcpServer *m_server; + QTcpSocket *m_client; + QTcpSocket *m_serverConn; + +private slots: + void init(); + void cleanup(); + + void maximumPacketSize(); + void setMaximumPacketSize(); + void setMaximumPacketSize_data(); + void send(); + void send_data(); + void packetsAvailable(); + void packetsAvailable_data(); + void clear(); + void read(); + void device(); + + void tst_QPacket_clear(); +}; + +void tst_QPacketProtocol::init() +{ + m_server = new QTcpServer(this); + QVERIFY(m_server->listen()); + + m_client = new QTcpSocket(this); + m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); + + QVERIFY(m_client->waitForConnected()); + QVERIFY(m_server->waitForNewConnection()); + m_serverConn = m_server->nextPendingConnection(); +} + +void tst_QPacketProtocol::cleanup() +{ + delete m_client; + delete m_serverConn; + delete m_server; +} + +void tst_QPacketProtocol::maximumPacketSize() +{ + QPacketProtocol p(m_client); + QCOMPARE(p.maximumPacketSize(), 0x7FFFFFFF); +} + +void tst_QPacketProtocol::setMaximumPacketSize() +{ + QFETCH(qint32, size); + QFETCH(qint32, expected); + + QPacketProtocol out(m_serverConn); + QCOMPARE(out.setMaximumPacketSize(size), expected); + + if (size == expected) { + QPacketProtocol in(m_client); + QByteArray b; + b.fill('a', size + 1); + out.send() << b.constData(); + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(invalidPacket()))); + } +} + +void tst_QPacketProtocol::setMaximumPacketSize_data() +{ + QTest::addColumn("size"); + QTest::addColumn("expected"); + + QTest::newRow("invalid") << qint32(sizeof(qint32) - 1) << qint32(0x7FFFFFFF); + QTest::newRow("still invalid") << qint32(sizeof(qint32)) << qint32(0x7FFFFFFF); + QTest::newRow("valid") << qint32(sizeof(qint32) + 1) << qint32(sizeof(qint32) + 1); +} + +void tst_QPacketProtocol::send() +{ + QFETCH(bool, useAutoSend); + + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QByteArray ba; + int num; + + if (useAutoSend) { + out.send() << "Hello world" << 123; + } else { + QPacket packet; + packet << "Hello world" << 123; + out.send(packet); + } + + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p = in.read(); + p >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world") + '\0'); + QCOMPARE(num, 123); +} + +void tst_QPacketProtocol::send_data() +{ + QTest::addColumn("useAutoSend"); + + QTest::newRow("auto send") << true; + QTest::newRow("no auto send") << false; +} + +void tst_QPacketProtocol::packetsAvailable() +{ + QFETCH(int, packetCount); + + QPacketProtocol out(m_client); + QPacketProtocol in(m_serverConn); + + QCOMPARE(out.packetsAvailable(), qint64(0)); + QCOMPARE(in.packetsAvailable(), qint64(0)); + + for (int i=0; i("packetCount"); + + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("10") << 10; +} + +void tst_QPacketProtocol::clear() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + out.send() << 123; + out.send() << 456; + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + in.clear(); + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::read() +{ + QPacketProtocol in(m_client); + QPacketProtocol out(m_serverConn); + + QVERIFY(in.read().isEmpty()); + + out.send() << 123; + out.send() << 456; + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + int num; + + QPacket p1 = in.read(); + QVERIFY(!p1.isEmpty()); + p1 >> num; + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + QVERIFY(!p2.isEmpty()); + p2 >> num; + QCOMPARE(num, 456); + + QVERIFY(in.read().isEmpty()); +} + +void tst_QPacketProtocol::device() +{ + QPacketProtocol p(m_client); + QCOMPARE(p.device(), m_client); +} + +void tst_QPacketProtocol::tst_QPacket_clear() +{ + QPacketProtocol protocol(m_client); + + QPacket packet; + + packet << "Hello world!" << 123; + protocol.send(packet); + + packet.clear(); + QVERIFY(packet.isEmpty()); + packet << "Goodbyte world!" << 789; + protocol.send(packet); + + QByteArray ba; + int num; + QPacketProtocol in(m_serverConn); + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + + QPacket p1 = in.read(); + p1 >> ba >> num; + QCOMPARE(ba, QByteArray("Hello world!") + '\0'); + QCOMPARE(num, 123); + + QPacket p2 = in.read(); + p2 >> ba >> num; + QCOMPARE(ba, QByteArray("Goodbyte world!") + '\0'); + QCOMPARE(num, 789); +} + +QTEST_MAIN(tst_QPacketProtocol) + +#include "tst_qpacketprotocol.moc" -- cgit v0.12