diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-13 07:11:22 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-13 07:11:22 (GMT) |
commit | 98d06d8d10919e0a83d29bd88f0b572b9b4a753c (patch) | |
tree | b8d7590169fbee35d0ecc149845dab9aaac6ee76 /tests/auto/declarative/debugger | |
parent | 9f24db4d0e9ce08f01083d9999fdc9dc69f54b80 (diff) | |
parent | 543c9ab8f423297601def9344b2847f283d87169 (diff) | |
download | Qt-98d06d8d10919e0a83d29bd88f0b572b9b4a753c.zip Qt-98d06d8d10919e0a83d29bd88f0b572b9b4a753c.tar.gz Qt-98d06d8d10919e0a83d29bd88f0b572b9b4a753c.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests/auto/declarative/debugger')
-rw-r--r-- | tests/auto/declarative/debugger/debugger.pro | 3 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/debuggerutil.cpp | 103 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/debugutil.cpp | 173 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/debugutil_p.h (renamed from tests/auto/declarative/debugger/debuggerutil_p.h) | 68 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebug/qmldebug.pro | 4 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp | 171 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro | 4 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp | 66 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro | 4 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp | 69 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro | 7 | ||||
-rw-r--r-- | tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp | 270 |
12 files changed, 640 insertions, 302 deletions
diff --git a/tests/auto/declarative/debugger/debugger.pro b/tests/auto/declarative/debugger/debugger.pro index f4a4476..a341ca9 100644 --- a/tests/auto/declarative/debugger/debugger.pro +++ b/tests/auto/declarative/debugger/debugger.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += qmldebug \ qmldebugclient \ - qmldebugservice + qmldebugservice \ + qpacketprotocol diff --git a/tests/auto/declarative/debugger/debuggerutil.cpp b/tests/auto/declarative/debugger/debuggerutil.cpp deleted file mode 100644 index 761105e..0000000 --- a/tests/auto/declarative/debugger/debuggerutil.cpp +++ /dev/null @@ -1,103 +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 <QSignalSpy> -#include <QEventLoop> -#include <QTimer> - -#include <private/qmldebugclient_p.h> -#include <private/qmldebugservice_p.h> - -#include "debuggerutil_p.h" - -namespace QmlDebuggerTest { - - bool 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(); - } - -} - - -QmlDebuggerTestService::QmlDebuggerTestService(const QString &s, QObject *parent) - : QmlDebugService(s, parent), enabled(false) -{ -} - -void QmlDebuggerTestService::messageReceived(const QByteArray &ba) -{ - sendMessage(ba); -} - -void QmlDebuggerTestService::enabledChanged(bool e) -{ - emit enabledStateChanged(); - enabled = e; -} - - -QmlDebuggerTestClient::QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c) - : QmlDebugClient(s, c) -{ -} - -QByteArray QmlDebuggerTestClient::waitForResponse() -{ - QSignalSpy spy(this, SIGNAL(serverMessage(QByteArray))); - QmlDebuggerTest::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<QByteArray>(); -} - -void QmlDebuggerTestClient::messageReceived(const QByteArray &ba) -{ - emit serverMessage(ba); -} - - diff --git a/tests/auto/declarative/debugger/debugutil.cpp b/tests/auto/declarative/debugger/debugutil.cpp new file mode 100644 index 0000000..7008529 --- /dev/null +++ b/tests/auto/declarative/debugger/debugutil.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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 <QSignalSpy> +#include <QEventLoop> +#include <QTimer> + +#include <private/qmldebugclient_p.h> +#include <private/qmldebugservice_p.h> + +#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<QByteArray>(); +} + +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<QByteArray> &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<QmlGraphicsItem*>(c.create()); + } + + // start the test + data.engine = &engine; + thread.m_ready = true; + + loop.exec(); + + return data.exitCode; +} + + diff --git a/tests/auto/declarative/debugger/debuggerutil_p.h b/tests/auto/declarative/debugger/debugutil_p.h index 5e27a7a..665aeda 100644 --- a/tests/auto/declarative/debugger/debuggerutil_p.h +++ b/tests/auto/declarative/debugger/debugutil_p.h @@ -40,21 +40,61 @@ ****************************************************************************/ #include <QSignalSpy> #include <QEventLoop> +#include <QPointer> #include <QTimer> +#include <QThread> +#include <QTest> + +#include <QtDeclarative/qmlengine.h> #include <private/qmldebugclient_p.h> #include <private/qmldebugservice_p.h> +#include <private/qmlgraphicsitem_p.h> + + +class QmlDebugTestData : public QObject +{ + Q_OBJECT +public: + QmlDebugTestData(QEventLoop *el); + + ~QmlDebugTestData(); + + QmlEngine *engine; + QmlDebugConnection *conn; + + int exitCode; + QEventLoop *loop; + + QList<QmlGraphicsItem *> items; + +public slots: + void testsFinished(int code); +}; + + +class QmlTestFactory +{ +public: + QmlTestFactory() {} + virtual ~QmlTestFactory() {} + + virtual QObject *createTest(QmlDebugTestData *data) = 0; +}; + -namespace QmlDebuggerTest { +namespace QmlDebugTest { bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); + + int runTests(QmlTestFactory *factory, const QList<QByteArray> &qml = QList<QByteArray>()); } -class QmlDebuggerTestService : public QmlDebugService +class QmlDebugTestService : public QmlDebugService { Q_OBJECT public: - QmlDebuggerTestService(const QString &s, QObject *parent = 0); + QmlDebugTestService(const QString &s, QObject *parent = 0); bool enabled; signals: @@ -66,11 +106,11 @@ protected: virtual void enabledChanged(bool e); }; -class QmlDebuggerTestClient : public QmlDebugClient +class QmlDebugTestClient : public QmlDebugClient { Q_OBJECT public: - QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c); + QmlDebugTestClient(const QString &s, QmlDebugConnection *c); QByteArray waitForResponse(); @@ -81,4 +121,22 @@ 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 index c1ac125..0af30e1 100644 --- a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro +++ b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += network declarative macx:CONFIG -= app_bundle -HEADERS += ../debuggerutil_p.h +HEADERS += ../debugutil_p.h SOURCES += tst_qmldebug.cpp \ - ../debuggerutil.cpp + ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp index bfb8aee..70404f6 100644 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp @@ -59,7 +59,7 @@ #include <private/qmldebugservice_p.h> #include <private/qmlgraphicsrectangle_p.h> -#include "../debuggerutil_p.h" +#include "../debugutil_p.h" Q_DECLARE_METATYPE(QmlDebugWatch::State) @@ -69,13 +69,16 @@ class tst_QmlDebug : public QObject Q_OBJECT public: - tst_QmlDebug(QmlDebugConnection *conn, QmlEngine *engine, QmlGraphicsItem *rootItem) - : m_conn(conn), m_dbg(0), m_engine(engine), m_rootItem(rootItem) {} + tst_QmlDebug(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + m_rootItem = data->items[0]; + } private: QmlDebugObjectReference findRootObject(); QmlDebugPropertyReference findProperty(const QList<QmlDebugPropertyReference> &props, const QString &name) const; - QObject *findObjectWithId(const QObjectList &objects, int id) const; void waitForQuery(QmlDebugQuery *query); void recursiveObjectTest(QObject *o, const QmlDebugObjectReference &oref, bool recursive) const; @@ -146,21 +149,12 @@ QmlDebugPropertyReference tst_QmlDebug::findProperty(const QList<QmlDebugPropert return QmlDebugPropertyReference(); } -QObject *tst_QmlDebug::findObjectWithId(const QObjectList &objects, int id) const -{ - foreach (QObject *o, objects) { - if (id == QmlDebugService::idForObject(o)) - return o; - } - return 0; -} - void tst_QmlDebug::waitForQuery(QmlDebugQuery *query) { QVERIFY(query); QCOMPARE(query->parent(), this); QVERIFY(query->state() == QmlDebugQuery::Waiting); - if (!QmlDebuggerTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) + if (!QmlDebugTest::waitForSignal(query, SIGNAL(stateChanged(QmlDebugQuery::State)))) QFAIL("query timed out"); } @@ -177,21 +171,40 @@ void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference QCOMPARE(oref.className(), className); QCOMPARE(oref.contextDebugId(), QmlDebugService::idForObject(qmlContext(o))); - foreach (const QmlDebugObjectReference &cref, oref.children()) { - // ignore children with no context - if (cref.contextDebugId() < 0) + const QObjectList &children = o->children(); + for (int i=0; i<children.count(); i++) { + QObject *child = children[i]; + if (!qmlContext(child)) continue; - - QObject *childObject = findObjectWithId(o->children(), cref.debugId()); - QVERIFY2(childObject, qPrintable(QString("Can't find QObject* for %1").arg(cref.className()))); + int debugId = QmlDebugService::idForObject(child); + QVERIFY(debugId >= 0); + + QmlDebugObjectReference cref; + foreach (const QmlDebugObjectReference &ref, oref.children()) { + if (ref.debugId() == debugId) { + cref = ref; + break; + } + } + QVERIFY(cref.debugId() >= 0); if (recursive) - recursiveObjectTest(childObject, cref, true); + 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())); - QVERIFY(pmeta.isValid()); QCOMPARE(p.name(), QString::fromUtf8(pmeta.name())); @@ -208,6 +221,8 @@ void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference QCOMPARE(binding->expression(), p.binding()); QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + + QVERIFY(pmeta.isValid()); } } @@ -277,6 +292,11 @@ void tst_QmlDebug::watch_property() 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); @@ -289,7 +309,8 @@ void tst_QmlDebug::watch_property() m_rootItem->setProperty("width", origWidth*2); // stateChanged() is received before valueChanged() - QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); QCOMPARE(spy.count(), 1); m_dbg->removeWatch(watch); @@ -328,6 +349,11 @@ void tst_QmlDebug::watch_object() 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()); @@ -340,7 +366,8 @@ void tst_QmlDebug::watch_object() m_rootItem->setProperty("height", origHeight*2); // stateChanged() is received before any valueChanged() signals - QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QCOMPARE(watch->state(), QmlDebugWatch::Active); QVERIFY(spy.count() > 0); int newWidth = -1; @@ -385,6 +412,11 @@ void tst_QmlDebug::watch_expression() 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()); @@ -401,13 +433,14 @@ void tst_QmlDebug::watch_expression() width += increment; m_rootItem->setProperty("width", width); } - if (!QmlDebuggerTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) + if (!QmlDebugTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant)))) QFAIL("Did not receive valueChanged() for expression"); } if (spyState.count() == 0) - QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); + QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State)))); QCOMPARE(spyState.count(), 1); + QCOMPARE(watch->state(), QmlDebugWatch::Active); m_dbg->removeWatch(watch); delete watch; @@ -500,15 +533,16 @@ void tst_QmlDebug::queryRootContexts() QCOMPARE(context.debugId(), QmlDebugService::idForObject(actualContext)); QCOMPARE(context.name(), actualContext->objectName()); - QCOMPARE(context.objects().count(), 2); // 2 objects created for engine in main() + 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); - // TODO have multiple contexts - QCOMPARE(context.contexts().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; @@ -593,7 +627,7 @@ void tst_QmlDebug::queryExpressionResult() QFETCH(QVariant, result); QmlDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this); - waitForQuery(q_engines); + waitForQuery(q_engines); // check immediate deletion is ok QmlDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this); waitForQuery(q_context); @@ -759,72 +793,37 @@ void tst_QmlDebug::tst_QmlDebugPropertyReference() compareProperties(r, ref); } -class TestRunnerThread : public QThread + +class tst_QmlDebug_Factory : public QmlTestFactory { - Q_OBJECT public: - void run() { - QTest::qWait(1000); - connectToEngine(); - } - - QPointer<QmlEngine> m_engine; - QPointer<QmlGraphicsItem> m_item; - -signals: - void testsFinished(); - -public slots: - - void connectToEngine() + QObject *createTest(QmlDebugTestData *data) { - QmlDebugConnection conn; - conn.connectToHost("127.0.0.1", 3768); - bool ok = conn.waitForConnected(5000); - Q_ASSERT(ok); - while (!m_engine && !m_item) - QTest::qWait(50); - - tst_QmlDebug test(&conn, m_engine, m_item); - QTest::qExec(&test); - emit testsFinished(); + 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); - qputenv("QML_DEBUG_SERVER_PORT", "3768"); - - TestRunnerThread thread; - QObject::connect(&thread, SIGNAL(testsFinished()), qApp, SLOT(quit())); - thread.start(); - - QmlEngine engine; // blocks until client connects - - QmlComponent component(&engine, - "import Qt 4.6\n" - "Item {\n" - "width: 10; height: 20; scale: blueRect.scale;\n" - "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" - "Text { color: blueRect.color; }" - "}\n", - QUrl("file://")); - Q_ASSERT(component.isReady()); - QObject *o = component.create(); - QObject::connect(&thread, SIGNAL(testsFinished()), o, SLOT(deleteLater())); - - // allows us to test that multiple contexts can be detected - QObject *o2 = component.create(); - QObject::connect(&thread, SIGNAL(testsFinished()), o2, SLOT(deleteLater())); - - // start the test - thread.m_engine = &engine; - thread.m_item = qobject_cast<QmlGraphicsItem*>(o); - - return app.exec(); + QList<QByteArray> 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) diff --git a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro b/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro index 6e68cd5..c0aa7b2 100644 --- a/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro +++ b/tests/auto/declarative/debugger/qmldebugclient/qmldebugclient.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += network declarative macx:CONFIG -= app_bundle -HEADERS += ../debuggerutil_p.h +HEADERS += ../debugutil_p.h SOURCES += tst_qmldebugclient.cpp \ - ../debuggerutil.cpp + ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp index 0a768a5..6c4a1a3 100644 --- a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp +++ b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp @@ -52,15 +52,18 @@ #include <private/qmldebugclient_p.h> #include <private/qmldebugservice_p.h> -#include "../debuggerutil_p.h" +#include "../debugutil_p.h" class tst_QmlDebugClient : public QObject { Q_OBJECT public: - tst_QmlDebugClient(QmlDebugConnection *conn, QmlEngine *engine) - : m_conn(conn), m_engine(engine) {} + tst_QmlDebugClient(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } QmlDebugConnection *m_conn; QmlEngine *m_engine; @@ -89,19 +92,19 @@ void tst_QmlDebugClient::isEnabled() void tst_QmlDebugClient::setEnabled() { - QmlDebuggerTestService service("tst_QmlDebugClient::setEnabled()"); - QmlDebuggerTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); + QmlDebugTestService service("tst_QmlDebugClient::setEnabled()"); + QmlDebugTestClient client("tst_QmlDebugClient::setEnabled()", m_conn); QCOMPARE(service.isEnabled(), false); client.setEnabled(true); QCOMPARE(client.isEnabled(), true); - QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); QCOMPARE(service.isEnabled(), true); client.setEnabled(false); QCOMPARE(client.isEnabled(), false); - QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); QCOMPARE(service.isEnabled(), false); } @@ -125,8 +128,8 @@ void tst_QmlDebugClient::isConnected() void tst_QmlDebugClient::sendMessage() { - QmlDebuggerTestService service("tst_QmlDebugClient::sendMessage()"); - QmlDebuggerTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); + QmlDebugTestService service("tst_QmlDebugClient::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugClient::sendMessage()", m_conn); QByteArray msg = "hello!"; @@ -136,55 +139,18 @@ void tst_QmlDebugClient::sendMessage() } - -class tst_QmlDebugClient_Thread : public QThread +class tst_QmlDebugClient_Factory : public QmlTestFactory { - Q_OBJECT public: - void run() { - QTest::qWait(1000); - connectToEngine(); - } - - QPointer<QmlEngine> m_engine; - -signals: - void testsFinished(); - -public slots: - - void connectToEngine() - { - QmlDebugConnection conn; - conn.connectToHost("127.0.0.1", 3768); - bool ok = conn.waitForConnected(5000); - Q_ASSERT(ok); - while (!m_engine) - QTest::qWait(50); - - tst_QmlDebugClient test(&conn, m_engine); - QTest::qExec(&test); - emit testsFinished(); - } + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugClient(data); } }; - int main(int argc, char *argv[]) { QApplication app(argc, argv); - qputenv("QML_DEBUG_SERVER_PORT", "3768"); - - tst_QmlDebugClient_Thread thread; - QObject::connect(&thread, SIGNAL(testsFinished()), qApp, SLOT(quit())); - thread.start(); - - QmlEngine engine; // blocks until client connects - - // start the test - thread.m_engine = &engine; - - return app.exec(); + 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 index 1b6762c..cce277a 100644 --- a/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro +++ b/tests/auto/declarative/debugger/qmldebugservice/qmldebugservice.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += network declarative macx:CONFIG -= app_bundle -HEADERS += ../debuggerutil_p.h +HEADERS += ../debugutil_p.h SOURCES += tst_qmldebugservice.cpp \ - ../debuggerutil.cpp + ../debugutil.cpp diff --git a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp index 2cd8607..0c02929 100644 --- a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp +++ b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp @@ -52,15 +52,18 @@ #include <private/qmldebugclient_p.h> #include <private/qmldebugservice_p.h> -#include "../debuggerutil_p.h" +#include "../debugutil_p.h" class tst_QmlDebugService : public QObject { Q_OBJECT public: - tst_QmlDebugService(QmlDebugConnection *conn, QmlEngine *engine) - : m_conn(conn), m_engine(engine) {} + tst_QmlDebugService(QmlDebugTestData *data) + { + m_conn = data->conn; + m_engine = data->engine; + } QmlDebugConnection *m_conn; QmlEngine *m_engine; @@ -85,12 +88,12 @@ void tst_QmlDebugService::name() void tst_QmlDebugService::isEnabled() { - QmlDebuggerTestService service("tst_QmlDebugService::isEnabled()", m_conn); + QmlDebugTestService service("tst_QmlDebugService::isEnabled()", m_conn); QCOMPARE(service.isEnabled(), false); - QmlDebuggerTestClient client("tst_QmlDebugService::isEnabled()", m_conn); + QmlDebugTestClient client("tst_QmlDebugService::isEnabled()", m_conn); client.setEnabled(true); - QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); QCOMPARE(service.isEnabled(), true); QTest::ignoreMessage(QtWarningMsg, "QmlDebugService: Conflicting plugin name \"tst_QmlDebugService::isEnabled()\" "); @@ -100,20 +103,20 @@ void tst_QmlDebugService::isEnabled() void tst_QmlDebugService::enabledChanged() { - QmlDebuggerTestService service("tst_QmlDebugService::enabledChanged()"); - QmlDebuggerTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); + QmlDebugTestService service("tst_QmlDebugService::enabledChanged()"); + QmlDebugTestClient client("tst_QmlDebugService::enabledChanged()", m_conn); QCOMPARE(service.enabled, false); client.setEnabled(true); - QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); + QmlDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); QCOMPARE(service.enabled, true); } void tst_QmlDebugService::sendMessage() { - QmlDebuggerTestService service("tst_QmlDebugService::sendMessage()"); - QmlDebuggerTestClient client("tst_QmlDebugService::sendMessage()", m_conn); + QmlDebugTestService service("tst_QmlDebugService::sendMessage()"); + QmlDebugTestClient client("tst_QmlDebugService::sendMessage()", m_conn); QByteArray msg = "hello!"; @@ -169,54 +172,18 @@ void tst_QmlDebugService::objectToString() } -class tst_QmlDebugService_Thread : public QThread +class tst_QmlDebugService_Factory : public QmlTestFactory { - Q_OBJECT public: - void run() { - QTest::qWait(1000); - connectToEngine(); - } - - QPointer<QmlEngine> m_engine; - -signals: - void testsFinished(); - -public slots: - - void connectToEngine() - { - QmlDebugConnection conn; - conn.connectToHost("127.0.0.1", 3768); - bool ok = conn.waitForConnected(5000); - Q_ASSERT(ok); - while (!m_engine) - QTest::qWait(50); - - tst_QmlDebugService test(&conn, m_engine); - QTest::qExec(&test); - emit testsFinished(); - } + QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebugService(data); } }; - int main(int argc, char *argv[]) { QApplication app(argc, argv); - qputenv("QML_DEBUG_SERVER_PORT", "3768"); - - tst_QmlDebugService_Thread thread; - QObject::connect(&thread, SIGNAL(testsFinished()), qApp, SLOT(quit())); - thread.start(); - - QmlEngine engine; // blocks until client connects - - // start the test - thread.m_engine = &engine; - - return app.exec(); + 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 new file mode 100644 index 0000000..800e5e0 --- /dev/null +++ b/tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000..36b6317 --- /dev/null +++ b/tests/auto/declarative/debugger/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 <qtest.h> +#include <QSignalSpy> +#include <QTimer> +#include <QTcpSocket> +#include <QTcpServer> +#include <QDebug> +#include <QBuffer> + +#include <private/qpacketprotocol_p.h> + +#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<int>("size"); + QTest::addColumn<int>("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<bool>("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; i++) + out.send() << "Hello"; + + QVERIFY(QmlDebugTest::waitForSignal(&in, SIGNAL(readyRead()))); + QCOMPARE(in.packetsAvailable(), qint64(packetCount)); +} + +void tst_QPacketProtocol::packetsAvailable_data() +{ + QTest::addColumn<int>("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" |