From 073963d9e45d9923cfafd5a3b43ef0dda8fe6d6f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 12 Nov 2009 16:41:22 +1000 Subject: Move engine/test set up code to debugutil.cpp --- tests/auto/declarative/debugger/debuggerutil.cpp | 103 ------------- tests/auto/declarative/debugger/debuggerutil_p.h | 84 ---------- tests/auto/declarative/debugger/debugutil.cpp | 170 +++++++++++++++++++++ tests/auto/declarative/debugger/debugutil_p.h | 142 +++++++++++++++++ .../declarative/debugger/qmldebug/qmldebug.pro | 4 +- .../declarative/debugger/qmldebug/tst_qmldebug.cpp | 96 ++++-------- .../debugger/qmldebugclient/qmldebugclient.pro | 4 +- .../debugger/qmldebugclient/tst_qmldebugclient.cpp | 66 ++------ .../debugger/qmldebugservice/qmldebugservice.pro | 4 +- .../qmldebugservice/tst_qmldebugservice.cpp | 69 +++------ 10 files changed, 382 insertions(+), 360 deletions(-) delete mode 100644 tests/auto/declarative/debugger/debuggerutil.cpp delete mode 100644 tests/auto/declarative/debugger/debuggerutil_p.h create mode 100644 tests/auto/declarative/debugger/debugutil.cpp create mode 100644 tests/auto/declarative/debugger/debugutil_p.h 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 -#include -#include - -#include -#include - -#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(); -} - -void QmlDebuggerTestClient::messageReceived(const QByteArray &ba) -{ - emit serverMessage(ba); -} - - diff --git a/tests/auto/declarative/debugger/debuggerutil_p.h b/tests/auto/declarative/debugger/debuggerutil_p.h deleted file mode 100644 index 5e27a7a..0000000 --- a/tests/auto/declarative/debugger/debuggerutil_p.h +++ /dev/null @@ -1,84 +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 - -namespace QmlDebuggerTest { - - bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); -} - -class QmlDebuggerTestService : public QmlDebugService -{ - Q_OBJECT -public: - QmlDebuggerTestService(const QString &s, QObject *parent = 0); - bool enabled; - -signals: - void enabledStateChanged(); - -protected: - virtual void messageReceived(const QByteArray &ba); - - virtual void enabledChanged(bool e); -}; - -class QmlDebuggerTestClient : public QmlDebugClient -{ - Q_OBJECT -public: - QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c); - - QByteArray waitForResponse(); - -signals: - void serverMessage(const QByteArray &); - -protected: - virtual void messageReceived(const QByteArray &ba); -}; - - diff --git a/tests/auto/declarative/debugger/debugutil.cpp b/tests/auto/declarative/debugger/debugutil.cpp new file mode 100644 index 0000000..cc58fe9 --- /dev/null +++ b/tests/auto/declarative/debugger/debugutil.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** 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; + QObject *test = m_factory->createTest(m_data); + 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 new file mode 100644 index 0000000..665aeda --- /dev/null +++ b/tests/auto/declarative/debugger/debugutil_p.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 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..21e7962 100644 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp @@ -59,7 +59,7 @@ #include #include -#include "../debuggerutil_p.h" +#include "../debugutil_p.h" Q_DECLARE_METATYPE(QmlDebugWatch::State) @@ -69,8 +69,12 @@ 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(); @@ -160,7 +164,7 @@ 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"); } @@ -289,7 +293,7 @@ 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(spy.count(), 1); m_dbg->removeWatch(watch); @@ -340,7 +344,7 @@ 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)))); QVERIFY(spy.count() > 0); int newWidth = -1; @@ -401,12 +405,12 @@ 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); m_dbg->removeWatch(watch); @@ -759,72 +763,32 @@ 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 m_engine; - QPointer m_item; - -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 && !m_item) - QTest::qWait(50); - - tst_QmlDebug test(&conn, m_engine, m_item); - QTest::qExec(&test); - emit testsFinished(); - } + QObject *createTest(QmlDebugTestData *data) { 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(o); - - return app.exec(); + 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; }" + "}" + << "import Qt 4.6\n" + "Item {" + "MouseRegion {" + "onEntered: { print('hello') }" + "}" + "}"; + 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 #include -#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 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 #include -#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 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" -- cgit v0.12 From 40f78db14b38b549c1afa588c0c8b48d8a849999 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 13 Nov 2009 11:25:17 +1000 Subject: Fix bug in WATCH_OBJECT_R message and add more tests. --- src/declarative/qml/qmlenginedebug.cpp | 2 +- tests/auto/declarative/debugger/debugutil.cpp | 3 + .../declarative/debugger/qmldebug/tst_qmldebug.cpp | 87 +++++++++++++++------- 3 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 3813d20..7e09fe6 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -358,7 +358,7 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message) QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); - rs << QByteArray("WATCH_OBJECT_R") << queryId << objectId << ok; + rs << QByteArray("WATCH_OBJECT_R") << queryId << ok; sendMessage(reply); } else if (type == "WATCH_PROPERTY") { diff --git a/tests/auto/declarative/debugger/debugutil.cpp b/tests/auto/declarative/debugger/debugutil.cpp index cc58fe9..7008529 100644 --- a/tests/auto/declarative/debugger/debugutil.cpp +++ b/tests/auto/declarative/debugger/debugutil.cpp @@ -133,7 +133,10 @@ void tst_QmlDebug_Thread::run() 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); } diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp index 21e7962..70404f6 100644 --- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp +++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp @@ -79,7 +79,6 @@ public: private: QmlDebugObjectReference findRootObject(); QmlDebugPropertyReference findProperty(const QList &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; @@ -150,15 +149,6 @@ QmlDebugPropertyReference tst_QmlDebug::findProperty(const QListchildren(); + for (int i=0; ichildren(), 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())); @@ -212,6 +221,8 @@ void tst_QmlDebug::recursiveObjectTest(QObject *o, const QmlDebugObjectReference QCOMPARE(binding->expression(), p.binding()); QCOMPARE(p.hasNotifySignal(), pmeta.hasNotifySignal()); + + QVERIFY(pmeta.isValid()); } } @@ -281,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); @@ -294,6 +310,7 @@ void tst_QmlDebug::watch_property() // 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); @@ -332,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()); @@ -345,6 +367,7 @@ void tst_QmlDebug::watch_object() // 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; @@ -389,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()); @@ -412,6 +440,7 @@ void tst_QmlDebug::watch_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; @@ -504,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; @@ -597,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); @@ -767,7 +797,12 @@ void tst_QmlDebug::tst_QmlDebugPropertyReference() class tst_QmlDebug_Factory : public QmlTestFactory { public: - QObject *createTest(QmlDebugTestData *data) { return new tst_QmlDebug(data); } + 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[]) @@ -780,13 +815,13 @@ int main(int argc, char *argv[]) "width: 10; height: 20; scale: blueRect.scale;" "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" "Text { color: blueRect.color; }" - "}" - << "import Qt 4.6\n" - "Item {" "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); } -- cgit v0.12 From ec7590bf1b7120dd6948766280917a3db555d97f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 13 Nov 2009 16:19:23 +1000 Subject: QPacketProtocol tests --- tests/auto/declarative/debugger/debugger.pro | 3 +- .../debugger/qpacketprotocol/qpacketprotocol.pro | 7 + .../qpacketprotocol/tst_qpacketprotocol.cpp | 270 +++++++++++++++++++++ 3 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/debugger/qpacketprotocol/qpacketprotocol.pro create mode 100644 tests/auto/declarative/debugger/qpacketprotocol/tst_qpacketprotocol.cpp 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/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 +#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" -- cgit v0.12 From ba6180ee3fa07590f0de419ae7f41e20b4a7504e Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 13 Nov 2009 16:43:14 +1000 Subject: more Connection autotests --- .../qmlconnection/data/test-connection2.qml | 3 ++ .../qmlconnection/data/test-connection3.qml | 3 ++ .../qmlconnection/tst_qmlconnection.cpp | 33 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/auto/declarative/qmlconnection/data/test-connection2.qml create mode 100644 tests/auto/declarative/qmlconnection/data/test-connection3.qml diff --git a/tests/auto/declarative/qmlconnection/data/test-connection2.qml b/tests/auto/declarative/qmlconnection/data/test-connection2.qml new file mode 100644 index 0000000..65fe23a --- /dev/null +++ b/tests/auto/declarative/qmlconnection/data/test-connection2.qml @@ -0,0 +1,3 @@ +import Qt 4.6 + +Connection { id: connection; sender: connection; signal: "widthChanged()"; script: 1 == 1 } diff --git a/tests/auto/declarative/qmlconnection/data/test-connection3.qml b/tests/auto/declarative/qmlconnection/data/test-connection3.qml new file mode 100644 index 0000000..32133f9 --- /dev/null +++ b/tests/auto/declarative/qmlconnection/data/test-connection3.qml @@ -0,0 +1,3 @@ +import Qt 4.6 + +Connection {} diff --git a/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp b/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp index c6d2cc4..b21da48 100644 --- a/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp +++ b/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp @@ -44,6 +44,7 @@ #include #include #include "../../../shared/util.h" +#include class tst_qmlconnection : public QObject @@ -53,6 +54,8 @@ public: tst_qmlconnection(); private slots: + void defaultValues(); + void properties(); void connection(); private: @@ -63,6 +66,36 @@ tst_qmlconnection::tst_qmlconnection() { } +void tst_qmlconnection::defaultValues() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/test-connection3.qml")); + QmlConnection *item = qobject_cast(c.create()); + + QVERIFY(item != 0); + QVERIFY(item->signalSender() == 0); + QCOMPARE(item->script().script(), QString()); + QCOMPARE(item->signal(), QString()); + + delete item; +} + +void tst_qmlconnection::properties() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/test-connection2.qml")); + QmlConnection *item = qobject_cast(c.create()); + + QVERIFY(item != 0); + + QVERIFY(item != 0); + QVERIFY(item->signalSender() == item); + QCOMPARE(item->script().script(), QString("1 == 1")); + QCOMPARE(item->signal(), QString("widthChanged()")); + + delete item; +} + void tst_qmlconnection::connection() { QmlEngine engine; -- cgit v0.12