summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-02-15 07:22:29 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-02-15 07:22:29 (GMT)
commitaf36be2c7257870e1ad094ec7b2cc37ae4ca2176 (patch)
tree5e69a670cad06f62f8a5b539105995cea00ae0aa /tests
parentb258be1d39889e65411324fe5cda47a34f814033 (diff)
downloadQt-af36be2c7257870e1ad094ec7b2cc37ae4ca2176.zip
Qt-af36be2c7257870e1ad094ec7b2cc37ae4ca2176.tar.gz
Qt-af36be2c7257870e1ad094ec7b2cc37ae4ca2176.tar.bz2
For qmldebug* tests, make sure engine is running before the test thread
is started. Also fix some memory leaks.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qmldebug/tst_qmldebug.cpp40
-rw-r--r--tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp1
-rw-r--r--tests/auto/declarative/shared/debugutil.cpp21
-rw-r--r--tests/auto/declarative/shared/debugutil_p.h25
4 files changed, 52 insertions, 35 deletions
diff --git a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp
index 82e74ce..a51fd29 100644
--- a/tests/auto/declarative/qmldebug/tst_qmldebug.cpp
+++ b/tests/auto/declarative/qmldebug/tst_qmldebug.cpp
@@ -288,10 +288,11 @@ void tst_QmlDebug::watch_property()
QmlDebugPropertyWatch *watch;
- QmlEngineDebug unconnected(0);
- watch = unconnected.addWatch(prop, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ watch = unconnected->addWatch(prop, this);
QCOMPARE(watch->state(), QmlDebugWatch::Dead);
delete watch;
+ delete unconnected;
watch = m_dbg->addWatch(QmlDebugPropertyReference(), this);
QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State))));
@@ -346,10 +347,11 @@ void tst_QmlDebug::watch_object()
QmlDebugWatch *watch;
- QmlEngineDebug unconnected(0);
- watch = unconnected.addWatch(obj, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ watch = unconnected->addWatch(obj, this);
QCOMPARE(watch->state(), QmlDebugWatch::Dead);
delete watch;
+ delete unconnected;
watch = m_dbg->addWatch(QmlDebugObjectReference(), this);
QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State))));
@@ -409,10 +411,11 @@ void tst_QmlDebug::watch_expression()
QmlDebugObjectExpressionWatch *watch;
- QmlEngineDebug unconnected(0);
- watch = unconnected.addWatch(obj, expr, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ watch = unconnected->addWatch(obj, expr, this);
QCOMPARE(watch->state(), QmlDebugWatch::Dead);
delete watch;
+ delete unconnected;
watch = m_dbg->addWatch(QmlDebugObjectReference(), expr, this);
QVERIFY(QmlDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QmlDebugWatch::State))));
@@ -487,10 +490,11 @@ void tst_QmlDebug::queryAvailableEngines()
{
QmlDebugEnginesQuery *q_engines;
- QmlEngineDebug unconnected(0);
- q_engines = unconnected.queryAvailableEngines(0);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ q_engines = unconnected->queryAvailableEngines(0);
QCOMPARE(q_engines->state(), QmlDebugQuery::Error);
delete q_engines;
+ delete unconnected;
q_engines = m_dbg->queryAvailableEngines(this);
delete q_engines;
@@ -519,10 +523,11 @@ void tst_QmlDebug::queryRootContexts()
QmlDebugRootContextQuery *q_context;
- QmlEngineDebug unconnected(0);
- q_context = unconnected.queryRootContexts(engineId, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ q_context = unconnected->queryRootContexts(engineId, this);
QCOMPARE(q_context->state(), QmlDebugQuery::Error);
delete q_context;
+ delete unconnected;
q_context = m_dbg->queryRootContexts(engineId, this);
delete q_context;
@@ -563,10 +568,11 @@ void tst_QmlDebug::queryObject()
QmlDebugObjectQuery *q_obj = 0;
- QmlEngineDebug unconnected(0);
- q_obj = recursive ? unconnected.queryObjectRecursive(rootObject, this) : unconnected.queryObject(rootObject, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ q_obj = recursive ? unconnected->queryObjectRecursive(rootObject, this) : unconnected->queryObject(rootObject, this);
QCOMPARE(q_obj->state(), QmlDebugQuery::Error);
delete q_obj;
+ delete unconnected;
q_obj = recursive ? m_dbg->queryObjectRecursive(rootObject, this) : m_dbg->queryObject(rootObject, this);
delete q_obj;
@@ -637,10 +643,11 @@ void tst_QmlDebug::queryExpressionResult()
QmlDebugExpressionQuery *q_expr;
- QmlEngineDebug unconnected(0);
- q_expr = unconnected.queryExpressionResult(objectId, expr, this);
+ QmlEngineDebug *unconnected = new QmlEngineDebug(0);
+ q_expr = unconnected->queryExpressionResult(objectId, expr, this);
QCOMPARE(q_expr->state(), QmlDebugQuery::Error);
delete q_expr;
+ delete unconnected;
q_expr = m_dbg->queryExpressionResult(objectId, expr, this);
delete q_expr;
@@ -801,9 +808,10 @@ class tst_QmlDebug_Factory : public QmlTestFactory
public:
QObject *createTest(QmlDebugTestData *data)
{
- QmlContext *c = new QmlContext(data->engine->rootContext());
+ tst_QmlDebug *test = new tst_QmlDebug(data);
+ QmlContext *c = new QmlContext(data->engine->rootContext(), test);
c->setObjectName("tst_QmlDebug_childContext");
- return new tst_QmlDebug(data);
+ return test;
}
};
diff --git a/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp
index 4e7bc27..9abc5a5 100644
--- a/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp
+++ b/tests/auto/declarative/qmldebugservice/tst_qmldebugservice.cpp
@@ -167,6 +167,7 @@ void tst_QmlDebugService::objectToString()
obj->setObjectName("Hello");
QCOMPARE(QmlDebugService::objectToString(obj), QString("QObject: Hello"));
+ delete obj;
}
diff --git a/tests/auto/declarative/shared/debugutil.cpp b/tests/auto/declarative/shared/debugutil.cpp
index aa0cd31..0010508 100644
--- a/tests/auto/declarative/shared/debugutil.cpp
+++ b/tests/auto/declarative/shared/debugutil.cpp
@@ -47,6 +47,8 @@
#include "debugutil_p.h"
+#include <iostream>
+
bool QmlDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) {
QEventLoop loop;
QTimer timer;
@@ -117,21 +119,22 @@ void QmlDebugTestClient::messageReceived(const QByteArray &ba)
tst_QmlDebug_Thread::tst_QmlDebug_Thread(QmlDebugTestData *data, QmlTestFactory *factory)
- : m_ready(false), m_data(data), m_factory(factory)
+ : m_data(data), m_factory(factory)
{
}
void tst_QmlDebug_Thread::run()
{
- QTest::qWait(1000);
+ bool ok = false;
QmlDebugConnection conn;
conn.connectToHost("127.0.0.1", 3768);
- bool ok = conn.waitForConnected(5000);
+ ok = conn.waitForConnected();
Q_ASSERT(ok);
- while (!m_ready)
- QTest::qWait(100);
+ QEventLoop loop;
+ connect(m_data, SIGNAL(engineCreated()), &loop, SLOT(quit()));
+ loop.exec();
m_data->conn = &conn;
@@ -139,10 +142,10 @@ void tst_QmlDebug_Thread::run()
QObject *test = m_factory->createTest(m_data);
Q_ASSERT(test);
int code = QTest::qExec(test, QCoreApplication::arguments());
+ delete test;
emit testsFinished(code);
}
-
int QmlDebugTest::runTests(QmlTestFactory *factory, const QList<QByteArray> &qml)
{
qputenv("QML_DEBUG_SERVER_PORT", "3768");
@@ -152,7 +155,8 @@ int QmlDebugTest::runTests(QmlTestFactory *factory, const QList<QByteArray> &qml
tst_QmlDebug_Thread thread(&data, factory);
QObject::connect(&thread, SIGNAL(testsFinished(int)), &data, SLOT(testsFinished(int)));
- thread.start();
+
+ QmlDebugService::notifyOnServerStart(&thread, "start");
QmlEngine engine; // blocks until client connects
@@ -165,7 +169,7 @@ int QmlDebugTest::runTests(QmlTestFactory *factory, const QList<QByteArray> &qml
// start the test
data.engine = &engine;
- thread.m_ready = true;
+ emit data.engineCreated();
loop.exec();
thread.wait();
@@ -173,4 +177,3 @@ int QmlDebugTest::runTests(QmlTestFactory *factory, const QList<QByteArray> &qml
return data.exitCode;
}
-
diff --git a/tests/auto/declarative/shared/debugutil_p.h b/tests/auto/declarative/shared/debugutil_p.h
index 313d16c..6f23899 100644
--- a/tests/auto/declarative/shared/debugutil_p.h
+++ b/tests/auto/declarative/shared/debugutil_p.h
@@ -51,6 +51,15 @@
#include <private/qmldebugservice_p.h>
#include <private/qmlgraphicsitem_p.h>
+class QmlTestFactory;
+
+class QmlDebugTest
+{
+public:
+ static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000);
+
+ static int runTests(QmlTestFactory *factory, const QList<QByteArray> &qml = QList<QByteArray>());
+};
class QmlDebugTestData : public QObject
{
@@ -68,8 +77,14 @@ public:
QList<QmlGraphicsItem *> items;
+signals:
+ void engineCreated();
+
public slots:
void testsFinished(int code);
+
+private:
+ friend class QmlDebugTest;
};
@@ -82,14 +97,6 @@ public:
virtual QObject *createTest(QmlDebugTestData *data) = 0;
};
-
-namespace QmlDebugTest {
-
- bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000);
-
- int runTests(QmlTestFactory *factory, const QList<QByteArray> &qml = QList<QByteArray>());
-}
-
class QmlDebugTestService : public QmlDebugService
{
Q_OBJECT
@@ -132,8 +139,6 @@ public:
void run();
- bool m_ready;
-
signals:
void testsFinished(int);