diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-04-16 05:33:41 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-04-16 05:38:23 (GMT) |
commit | 34a1a6b5d6399e7bcad136fdaa9a050a0f8bb2dc (patch) | |
tree | 9d7585945744454937ac495d7f729a9386f755bb /tests/auto/declarative | |
parent | b458d672dbec892f00019edc1fe06156190401c7 (diff) | |
download | Qt-34a1a6b5d6399e7bcad136fdaa9a050a0f8bb2dc.zip Qt-34a1a6b5d6399e7bcad136fdaa9a050a0f8bb2dc.tar.gz Qt-34a1a6b5d6399e7bcad136fdaa9a050a0f8bb2dc.tar.bz2 |
Wait for debug clients asynchronously instead of blocking creation of
the engine until a debug client has connected. This makes for easier
debugging from Qt Creator when debugging C++ and QML together and when
debugging an application that has multiple engines.
Diffstat (limited to 'tests/auto/declarative')
5 files changed, 86 insertions, 226 deletions
diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index 133dcb8..49d430e 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -60,6 +60,7 @@ #include <private/qdeclarativemetatype_p.h> #include <private/qdeclarativeproperty_p.h> +#include "../../../shared/util.h" #include "../shared/debugutil_p.h" Q_DECLARE_METATYPE(QDeclarativeDebugWatch::State) @@ -69,14 +70,6 @@ class tst_QDeclarativeDebug : public QObject { Q_OBJECT -public: - tst_QDeclarativeDebug(QDeclarativeDebugTestData *data) - { - m_conn = data->conn; - m_engine = data->engine; - m_rootItem = data->items[0]; - } - private: QDeclarativeDebugObjectReference findRootObject(); QDeclarativeDebugPropertyReference findProperty(const QList<QDeclarativeDebugPropertyReference> &props, const QString &name) const; @@ -93,8 +86,11 @@ private: QDeclarativeEngine *m_engine; QDeclarativeItem *m_rootItem; + QObjectList m_components; + private slots: void initTestCase(); + void cleanupTestCase(); void watch_property(); void watch_object(); @@ -278,9 +274,50 @@ void tst_QDeclarativeDebug::compareProperties(const QDeclarativeDebugPropertyRef void tst_QDeclarativeDebug::initTestCase() { + qRegisterMetaType<QDeclarativeDebugWatch::State>(); + + qputenv("QML_DEBUG_SERVER_PORT", "3768"); + m_engine = new QDeclarativeEngine(this); + + QList<QByteArray> qml; + qml << "import Qt 4.7\n" + "Item {" + "width: 10; height: 20; scale: blueRect.scale;" + "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" + "Text { color: blueRect.color; }" + "MouseArea {" + "onEntered: { console.log('hello') }" + "}" + "}"; + // add second component to test multiple root contexts + qml << "import Qt 4.7\n" + "Item {}"; + + for (int i=0; i<qml.count(); i++) { + QDeclarativeComponent component(m_engine); + component.setData(qml[i], QUrl::fromLocalFile("")); + Q_ASSERT(component.isReady()); // fails if bad syntax + m_components << qobject_cast<QDeclarativeItem*>(component.create()); + } + m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first()); + + + // add an extra context to test for multiple contexts + QDeclarativeContext *context = new QDeclarativeContext(m_engine->rootContext(), this); + context->setObjectName("tst_QDeclarativeDebug_childContext"); + + m_conn = new QDeclarativeDebugConnection(this); + m_conn->connectToHost("127.0.0.1", 3768); + bool ok = m_conn->waitForConnected(); + Q_ASSERT(ok); + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); + m_dbg = new QDeclarativeEngineDebug(m_conn, this); +} - qRegisterMetaType<QDeclarativeDebugWatch::State>(); +void tst_QDeclarativeDebug::cleanupTestCase() +{ + qDeleteAll(m_components); } void tst_QDeclarativeDebug::watch_property() @@ -804,40 +841,6 @@ void tst_QDeclarativeDebug::tst_QDeclarativeDebugPropertyReference() compareProperties(r, ref); } - -class tst_QDeclarativeDebug_Factory : public QDeclarativeTestFactory -{ -public: - QObject *createTest(QDeclarativeDebugTestData *data) - { - tst_QDeclarativeDebug *test = new tst_QDeclarativeDebug(data); - QDeclarativeContext *c = new QDeclarativeContext(data->engine->rootContext(), test); - c->setObjectName("tst_QDeclarativeDebug_childContext"); - return test; - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - QList<QByteArray> qml; - qml << "import Qt 4.7\n" - "Item {" - "width: 10; height: 20; scale: blueRect.scale;" - "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }" - "Text { color: blueRect.color; }" - "MouseArea {" - "onEntered: { console.log('hello') }" - "}" - "}"; - // add second component to test multiple root contexts - qml << "import Qt 4.7\n" - "Item {}"; - tst_QDeclarativeDebug_Factory factory; - return QDeclarativeDebugTest::runTests(&factory, qml); -} - -//QTEST_MAIN(tst_QDeclarativeDebug) +QTEST_MAIN(tst_QDeclarativeDebug) #include "tst_qdeclarativedebug.moc" diff --git a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp index d3679a7..fb17f90 100644 --- a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp +++ b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp @@ -52,21 +52,19 @@ #include <private/qdeclarativedebugclient_p.h> #include <private/qdeclarativedebugservice_p.h> +#include "../../../shared/util.h" #include "../shared/debugutil_p.h" class tst_QDeclarativeDebugClient : public QObject { Q_OBJECT -public: - tst_QDeclarativeDebugClient(QDeclarativeDebugTestData *data) - { - m_conn = data->conn; - } - +private: QDeclarativeDebugConnection *m_conn; private slots: + void initTestCase(); + void name(); void isEnabled(); void setEnabled(); @@ -74,6 +72,19 @@ private slots: void sendMessage(); }; +void tst_QDeclarativeDebugClient::initTestCase() +{ + qputenv("QML_DEBUG_SERVER_PORT", "3768"); + new QDeclarativeEngine(this); + + m_conn = new QDeclarativeDebugConnection(this); + m_conn->connectToHost("127.0.0.1", 3768); + bool ok = m_conn->waitForConnected(); + Q_ASSERT(ok); + + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); +} + void tst_QDeclarativeDebugClient::name() { QString name = "tst_QDeclarativeDebugClient::name()"; @@ -136,22 +147,7 @@ void tst_QDeclarativeDebugClient::sendMessage() QCOMPARE(resp, msg); } - -class tst_QDeclarativeDebugClient_Factory : public QDeclarativeTestFactory -{ -public: - QObject *createTest(QDeclarativeDebugTestData *data) { return new tst_QDeclarativeDebugClient(data); } -}; - - -// This does not use QTEST_MAIN because the test has to be created and run -// in a separate thread. -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QDeclarativeDebugClient_Factory factory; - return QDeclarativeDebugTest::runTests(&factory); -} +QTEST_MAIN(tst_QDeclarativeDebugClient) #include "tst_qdeclarativedebugclient.moc" + diff --git a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp index c8fc001..80d7f76 100644 --- a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp +++ b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp @@ -52,21 +52,19 @@ #include <private/qdeclarativedebugclient_p.h> #include <private/qdeclarativedebugservice_p.h> +#include "../../../shared/util.h" #include "../shared/debugutil_p.h" + class tst_QDeclarativeDebugService : public QObject { Q_OBJECT - -public: - tst_QDeclarativeDebugService(QDeclarativeDebugTestData *data) - { - m_conn = data->conn; - } - +private: QDeclarativeDebugConnection *m_conn; private slots: + void initTestCase(); + void name(); void isEnabled(); void enabledChanged(); @@ -76,6 +74,19 @@ private slots: void objectToString(); }; +void tst_QDeclarativeDebugService::initTestCase() +{ + qputenv("QML_DEBUG_SERVER_PORT", "3768"); + new QDeclarativeEngine(this); + + m_conn = new QDeclarativeDebugConnection(this); + m_conn->connectToHost("127.0.0.1", 3768); + bool ok = m_conn->waitForConnected(); + Q_ASSERT(ok); + + QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); +} + void tst_QDeclarativeDebugService::name() { QString name = "tst_QDeclarativeDebugService::name()"; @@ -170,21 +181,6 @@ void tst_QDeclarativeDebugService::objectToString() delete obj; } - -class tst_QDeclarativeDebugService_Factory : public QDeclarativeTestFactory -{ -public: - QObject *createTest(QDeclarativeDebugTestData *data) { return new tst_QDeclarativeDebugService(data); } -}; - -// This does not use QTEST_MAIN because the test has to be created and run -// in a separate thread. -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - tst_QDeclarativeDebugService_Factory factory; - return QDeclarativeDebugTest::runTests(&factory); -} +QTEST_MAIN(tst_QDeclarativeDebugService) #include "tst_qdeclarativedebugservice.moc" diff --git a/tests/auto/declarative/shared/debugutil.cpp b/tests/auto/declarative/shared/debugutil.cpp index 66f04e5..c0c3eca 100644 --- a/tests/auto/declarative/shared/debugutil.cpp +++ b/tests/auto/declarative/shared/debugutil.cpp @@ -47,11 +47,11 @@ #include "debugutil_p.h" -#include <iostream> bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) { QEventLoop loop; QTimer timer; + timer.setSingleShot(true); QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); QObject::connect(receiver, member, &loop, SLOT(quit())); timer.start(timeout); @@ -59,25 +59,6 @@ bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member, return timer.isActive(); } - -QDeclarativeDebugTestData::QDeclarativeDebugTestData(QEventLoop *el) - : exitCode(-1), loop(el) -{ -} - -QDeclarativeDebugTestData::~QDeclarativeDebugTestData() -{ - qDeleteAll(items); -} - -void QDeclarativeDebugTestData::testsFinished(int code) -{ - exitCode = code; - loop->quit(); -} - - - QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent) : QDeclarativeDebugService(s, parent), enabled(false) { @@ -117,63 +98,3 @@ void QDeclarativeDebugTestClient::messageReceived(const QByteArray &ba) emit serverMessage(ba); } - -tst_QDeclarativeDebug_Thread::tst_QDeclarativeDebug_Thread(QDeclarativeDebugTestData *data, QDeclarativeTestFactory *factory) - : m_data(data), m_factory(factory) -{ -} - -void tst_QDeclarativeDebug_Thread::run() -{ - bool ok = false; - - QDeclarativeDebugConnection conn; - conn.connectToHost("127.0.0.1", 3768); - ok = conn.waitForConnected(); - Q_ASSERT(ok); - - QEventLoop loop; - connect(m_data, SIGNAL(engineCreated()), &loop, SLOT(quit())); - loop.exec(); - - m_data->conn = &conn; - - Q_ASSERT(m_factory); - QObject *test = m_factory->createTest(m_data); - Q_ASSERT(test); - int code = QTest::qExec(test, QCoreApplication::arguments()); - delete test; - emit testsFinished(code); -} - -int QDeclarativeDebugTest::runTests(QDeclarativeTestFactory *factory, const QList<QByteArray> &qml) -{ - qputenv("QML_DEBUG_SERVER_PORT", "3768"); - - QEventLoop loop; - QDeclarativeDebugTestData data(&loop); - - tst_QDeclarativeDebug_Thread thread(&data, factory); - QObject::connect(&thread, SIGNAL(testsFinished(int)), &data, SLOT(testsFinished(int))); - - QDeclarativeDebugService::notifyOnServerStart(&thread, "start"); - - QDeclarativeEngine engine; // blocks until client connects - - foreach (const QByteArray &code, qml) { - QDeclarativeComponent c(&engine); - c.setData(code, QUrl::fromLocalFile("")); - Q_ASSERT(c.isReady()); // fails if bad syntax - data.items << qobject_cast<QDeclarativeItem*>(c.create()); - } - - // start the test - data.engine = &engine; - emit data.engineCreated(); - - loop.exec(); - thread.wait(); - - return data.exitCode; -} - diff --git a/tests/auto/declarative/shared/debugutil_p.h b/tests/auto/declarative/shared/debugutil_p.h index c152b5a..e6bb7ad 100644 --- a/tests/auto/declarative/shared/debugutil_p.h +++ b/tests/auto/declarative/shared/debugutil_p.h @@ -51,50 +51,10 @@ #include <private/qdeclarativedebugservice_p.h> #include <private/qdeclarativeitem_p.h> -class QDeclarativeTestFactory; - class QDeclarativeDebugTest { public: static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); - - static int runTests(QDeclarativeTestFactory *factory, const QList<QByteArray> &qml = QList<QByteArray>()); -}; - -class QDeclarativeDebugTestData : public QObject -{ - Q_OBJECT -public: - QDeclarativeDebugTestData(QEventLoop *el); - - ~QDeclarativeDebugTestData(); - - QDeclarativeDebugConnection *conn; - QDeclarativeEngine *engine; - - int exitCode; - QEventLoop *loop; - - QList<QDeclarativeItem *> items; - -signals: - void engineCreated(); - -public slots: - void testsFinished(int code); - -private: - friend class QDeclarativeDebugTest; -}; - - -class QDeclarativeTestFactory -{ -public: - QDeclarativeTestFactory() {} - virtual ~QDeclarativeTestFactory() {} - - virtual QObject *createTest(QDeclarativeDebugTestData *data) = 0; }; class QDeclarativeDebugTestService : public QDeclarativeDebugService @@ -131,20 +91,4 @@ private: QByteArray lastMsg; }; -class tst_QDeclarativeDebug_Thread : public QThread -{ - Q_OBJECT -public: - tst_QDeclarativeDebug_Thread(QDeclarativeDebugTestData *data, QDeclarativeTestFactory *factory); - - void run(); - -signals: - void testsFinished(int); - -private: - QDeclarativeDebugTestData *m_data; - QDeclarativeTestFactory *m_factory; -}; - |