summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-11-11 00:30:48 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-11-11 00:30:48 (GMT)
commit9c19362c726d1d80bc38bb07b43eb3439ed05a8b (patch)
tree65c87281508e94fc86e63c3d47c6bc59c92e66b8 /tests
parent18a785eefdfbc5f83d7a0e78cbd8430f9d79c13f (diff)
downloadQt-9c19362c726d1d80bc38bb07b43eb3439ed05a8b.zip
Qt-9c19362c726d1d80bc38bb07b43eb3439ed05a8b.tar.gz
Qt-9c19362c726d1d80bc38bb07b43eb3439ed05a8b.tar.bz2
Clean up, and check stateChanged() is emitted for watches.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/debugger/debuggerutil.cpp17
-rw-r--r--tests/auto/declarative/debugger/debuggerutil_p.h10
-rw-r--r--tests/auto/declarative/debugger/qmldebug/qmldebug.pro4
-rw-r--r--tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp80
-rw-r--r--tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp8
-rw-r--r--tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp12
6 files changed, 54 insertions, 77 deletions
diff --git a/tests/auto/declarative/debugger/debuggerutil.cpp b/tests/auto/declarative/debugger/debuggerutil.cpp
index 8e93407..761105e 100644
--- a/tests/auto/declarative/debugger/debuggerutil.cpp
+++ b/tests/auto/declarative/debugger/debuggerutil.cpp
@@ -49,41 +49,42 @@
namespace QmlDebuggerTest {
- void waitForSignal(QObject *receiver, const char *member) {
+ 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(5000);
+ timer.start(timeout);
loop.exec();
+ return timer.isActive();
}
}
-EchoService::EchoService(const QString &s, QObject *parent)
+QmlDebuggerTestService::QmlDebuggerTestService(const QString &s, QObject *parent)
: QmlDebugService(s, parent), enabled(false)
{
}
-void EchoService::messageReceived(const QByteArray &ba)
+void QmlDebuggerTestService::messageReceived(const QByteArray &ba)
{
sendMessage(ba);
}
-void EchoService::enabledChanged(bool e)
+void QmlDebuggerTestService::enabledChanged(bool e)
{
emit enabledStateChanged();
enabled = e;
}
-MyQmlDebugClient::MyQmlDebugClient(const QString &s, QmlDebugConnection *c)
+QmlDebuggerTestClient::QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c)
: QmlDebugClient(s, c)
{
}
-QByteArray MyQmlDebugClient::waitForResponse()
+QByteArray QmlDebuggerTestClient::waitForResponse()
{
QSignalSpy spy(this, SIGNAL(serverMessage(QByteArray)));
QmlDebuggerTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray)));
@@ -94,7 +95,7 @@ QByteArray MyQmlDebugClient::waitForResponse()
return spy.at(0).at(0).value<QByteArray>();
}
-void MyQmlDebugClient::messageReceived(const QByteArray &ba)
+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
index 155d550..5e27a7a 100644
--- a/tests/auto/declarative/debugger/debuggerutil_p.h
+++ b/tests/auto/declarative/debugger/debuggerutil_p.h
@@ -47,14 +47,14 @@
namespace QmlDebuggerTest {
- void waitForSignal(QObject *receiver, const char *member);
+ bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000);
}
-class EchoService : public QmlDebugService
+class QmlDebuggerTestService : public QmlDebugService
{
Q_OBJECT
public:
- EchoService(const QString &s, QObject *parent = 0);
+ QmlDebuggerTestService(const QString &s, QObject *parent = 0);
bool enabled;
signals:
@@ -66,11 +66,11 @@ protected:
virtual void enabledChanged(bool e);
};
-class MyQmlDebugClient : public QmlDebugClient
+class QmlDebuggerTestClient : public QmlDebugClient
{
Q_OBJECT
public:
- MyQmlDebugClient(const QString &s, QmlDebugConnection *c);
+ QmlDebuggerTestClient(const QString &s, QmlDebugConnection *c);
QByteArray waitForResponse();
diff --git a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro
index 61f821e..c1ac125 100644
--- a/tests/auto/declarative/debugger/qmldebug/qmldebug.pro
+++ b/tests/auto/declarative/debugger/qmldebug/qmldebug.pro
@@ -2,4 +2,6 @@ load(qttest_p4)
contains(QT_CONFIG,declarative): QT += network declarative
macx:CONFIG -= app_bundle
-SOURCES += tst_qmldebug.cpp
+HEADERS += ../debuggerutil_p.h
+SOURCES += tst_qmldebug.cpp \
+ ../debuggerutil.cpp
diff --git a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp
index 7c52a19..d2305f8 100644
--- a/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp
+++ b/tests/auto/declarative/debugger/qmldebug/tst_qmldebug.cpp
@@ -59,6 +59,8 @@
#include <private/qmldebugservice_p.h>
#include <private/qmlgraphicsrectangle_p.h>
+#include "../debuggerutil_p.h"
+
class tst_QmlDebug : public QObject
{
@@ -68,12 +70,6 @@ public:
tst_QmlDebug(QmlDebugConnection *conn, QmlEngine *engine, QmlGraphicsItem *rootItem)
: m_conn(conn), m_dbg(0), m_engine(engine), m_rootItem(rootItem) {}
-protected slots:
- void saveValueChange(const QByteArray &ba, const QVariant &v)
- {
- m_savedValueChanges[ba] = v;
- }
-
private:
QmlDebugObjectReference findRootObject();
QmlDebugPropertyReference findProperty(const QList<QmlDebugPropertyReference> &props, const QString &name) const;
@@ -90,7 +86,6 @@ private:
QmlEngineDebug *m_dbg;
QmlEngine *m_engine;
QmlGraphicsItem *m_rootItem;
- QHash<QByteArray, QVariant> m_savedValueChanges;
private slots:
void initTestCase();
@@ -160,14 +155,8 @@ void tst_QmlDebug::waitForQuery(QmlDebugQuery *query)
{
QVERIFY(query);
QCOMPARE(query->parent(), this);
- QEventLoop loop;
- QTimer timer;
QVERIFY(query->state() == QmlDebugQuery::Waiting);
- connect(query, SIGNAL(stateChanged(State)), &loop, SLOT(quit()));
- connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- timer.start(5000);
- loop.exec();
- if (!timer.isActive())
+ if (!QmlDebuggerTest::waitForSignal(query, SIGNAL(stateChanged(State))))
QFAIL("query timed out");
}
@@ -282,23 +271,18 @@ void tst_QmlDebug::watch_property()
QCOMPARE(watch->name(), prop.name());
QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant)));
- QEventLoop loop;
- QTimer timer;
- connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit()));
- connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
int origWidth = m_rootItem->property("width").toInt();
- timer.start(5000);
m_rootItem->setProperty("width", origWidth*2);
- loop.exec();
- if (!timer.isActive())
- QFAIL("Did not receive valueChanged() for property");
+ // stateChanged() is received before valueChanged()
+ QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(State))));
+ QCOMPARE(spy.count(), 1);
m_dbg->removeWatch(watch);
delete watch;
- // restore original value and verify spy doesn't get a signal since watch has been removed
+ // restore original value and verify spy doesn't get additional signal since watch has been removed
m_rootItem->setProperty("width", origWidth);
QTest::qWait(100);
QCOMPARE(spy.count(), 1);
@@ -328,44 +312,40 @@ void tst_QmlDebug::watch_object()
QCOMPARE(watch->state(), QmlDebugWatch::Waiting);
QCOMPARE(watch->objectDebugId(), obj.debugId());
- m_savedValueChanges.clear();
- connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)),
- SLOT(saveValueChange(QByteArray,QVariant)));
+ QSignalSpy spy(watch, SIGNAL(valueChanged(QByteArray,QVariant)));
int origWidth = m_rootItem->property("width").toInt();
int origHeight = m_rootItem->property("height").toInt();
m_rootItem->setProperty("width", origWidth*2);
m_rootItem->setProperty("height", origHeight*2);
- QEventLoop loop;
- QTimer timer;
- timer.start(5000);
- while (timer.isActive() &&
- (!m_savedValueChanges.contains("width") || !m_savedValueChanges.contains("height"))) {
- loop.processEvents(QEventLoop::AllEvents, 50);
- }
+ // stateChanged() is received before any valueChanged() signals
+ QVERIFY(QmlDebuggerTest::waitForSignal(watch, SIGNAL(stateChanged(State))));
+ QVERIFY(spy.count() > 0);
+
+ int newWidth = -1;
+ int newHeight = -1;
+ for (int i=0; i<spy.count(); i++) {
+ const QVariantList &values = spy[i];
+ if (values[0].value<QByteArray>() == "width")
+ newWidth = values[1].value<QVariant>().toInt();
+ else if (values[0].value<QByteArray>() == "height")
+ newHeight = values[1].value<QVariant>().toInt();
- QVariant newWidth = m_savedValueChanges["width"];
- QVariant newHeight = m_savedValueChanges["height"];
+ }
m_dbg->removeWatch(watch);
delete watch;
// since watch has been removed, restoring the original values should not trigger a valueChanged()
- m_savedValueChanges.clear();
+ spy.clear();
m_rootItem->setProperty("width", origWidth);
m_rootItem->setProperty("height", origHeight);
QTest::qWait(100);
- QCOMPARE(m_savedValueChanges.count(), 0);
-
- if (newWidth.isNull() || newHeight.isNull()) {
- QString s = QString("Did not receive both width and height changes (width=%1, height=%2)")
- .arg(newWidth.toString()).arg(newHeight.toString());
- QFAIL(qPrintable(s));
- }
+ QCOMPARE(spy.count(), 0);
- QCOMPARE(newWidth, qVariantFromValue(origWidth*2));
- QCOMPARE(newHeight, qVariantFromValue(origHeight*2));
+ QCOMPARE(newWidth, origWidth * 2);
+ QCOMPARE(newHeight, origHeight * 2);
}
void tst_QmlDebug::watch_expression()
@@ -388,18 +368,12 @@ void tst_QmlDebug::watch_expression()
int width = origWidth;
for (int i=0; i<incrementCount+1; i++) {
- QTimer timer;
- timer.start(5000);
if (i > 0) {
width += increment;
m_rootItem->setProperty("width", width);
}
- QEventLoop loop;
- connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- connect(watch, SIGNAL(valueChanged(QByteArray,QVariant)), &loop, SLOT(quit()));
- loop.exec();
- if (!timer.isActive())
- QFAIL("Did not receive valueChanged() signal for expression");
+ if (!QmlDebuggerTest::waitForSignal(watch, SIGNAL(valueChanged(QByteArray,QVariant))))
+ QFAIL("Did not receive valueChanged() for expression");
}
m_dbg->removeWatch(watch);
diff --git a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp
index db33061..0a768a5 100644
--- a/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp
+++ b/tests/auto/declarative/debugger/qmldebugclient/tst_qmldebugclient.cpp
@@ -89,8 +89,8 @@ void tst_QmlDebugClient::isEnabled()
void tst_QmlDebugClient::setEnabled()
{
- EchoService service("tst_QmlDebugClient::setEnabled()");
- MyQmlDebugClient client("tst_QmlDebugClient::setEnabled()", m_conn);
+ QmlDebuggerTestService service("tst_QmlDebugClient::setEnabled()");
+ QmlDebuggerTestClient client("tst_QmlDebugClient::setEnabled()", m_conn);
QCOMPARE(service.isEnabled(), false);
@@ -125,8 +125,8 @@ void tst_QmlDebugClient::isConnected()
void tst_QmlDebugClient::sendMessage()
{
- EchoService service("tst_QmlDebugClient::sendMessage()");
- MyQmlDebugClient client("tst_QmlDebugClient::sendMessage()", m_conn);
+ QmlDebuggerTestService service("tst_QmlDebugClient::sendMessage()");
+ QmlDebuggerTestClient client("tst_QmlDebugClient::sendMessage()", m_conn);
QByteArray msg = "hello!";
diff --git a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp
index 224e7e1..2cd8607 100644
--- a/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp
+++ b/tests/auto/declarative/debugger/qmldebugservice/tst_qmldebugservice.cpp
@@ -85,10 +85,10 @@ void tst_QmlDebugService::name()
void tst_QmlDebugService::isEnabled()
{
- EchoService service("tst_QmlDebugService::isEnabled()", m_conn);
+ QmlDebuggerTestService service("tst_QmlDebugService::isEnabled()", m_conn);
QCOMPARE(service.isEnabled(), false);
- MyQmlDebugClient client("tst_QmlDebugService::isEnabled()", m_conn);
+ QmlDebuggerTestClient client("tst_QmlDebugService::isEnabled()", m_conn);
client.setEnabled(true);
QmlDebuggerTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
QCOMPARE(service.isEnabled(), true);
@@ -100,8 +100,8 @@ void tst_QmlDebugService::isEnabled()
void tst_QmlDebugService::enabledChanged()
{
- EchoService service("tst_QmlDebugService::enabledChanged()");
- MyQmlDebugClient client("tst_QmlDebugService::enabledChanged()", m_conn);
+ QmlDebuggerTestService service("tst_QmlDebugService::enabledChanged()");
+ QmlDebuggerTestClient client("tst_QmlDebugService::enabledChanged()", m_conn);
QCOMPARE(service.enabled, false);
@@ -112,8 +112,8 @@ void tst_QmlDebugService::enabledChanged()
void tst_QmlDebugService::sendMessage()
{
- EchoService service("tst_QmlDebugService::sendMessage()");
- MyQmlDebugClient client("tst_QmlDebugService::sendMessage()", m_conn);
+ QmlDebuggerTestService service("tst_QmlDebugService::sendMessage()");
+ QmlDebuggerTestClient client("tst_QmlDebugService::sendMessage()", m_conn);
QByteArray msg = "hello!";