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/qdeclarativedebug | |
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/qdeclarativedebug')
-rw-r--r-- | tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp | 91 |
1 files changed, 47 insertions, 44 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" |