summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2010-09-22 19:03:57 (GMT)
committerKai Koehne <kai.koehne@nokia.com>2010-09-28 05:55:32 (GMT)
commitfd9771c29d401d88779ab7c5d7715c9ca41dd723 (patch)
tree0e96e0871e8914f5747bfc1a1314d76a78620b6d /tests/auto
parent7b796b4dcdebfba55c4754d241edb334217fc550 (diff)
downloadQt-fd9771c29d401d88779ab7c5d7715c9ca41dd723.zip
Qt-fd9771c29d401d88779ab7c5d7715c9ca41dd723.tar.gz
Qt-fd9771c29d401d88779ab7c5d7715c9ca41dd723.tar.bz2
Make QmlDebug protocol more robust
The protocol so far was client->server only. That is, there was no sane way for a client to check whether a plugin on the server (service) was available or not. E.g. calling Client::setEnabled(true) 'succeeded', without a check whether there is actually a service to talk to. The new protocol replaces this shortcoming by a service discovery mechanism: Both client & service announce their available plugins at handshake time, and later on if there are changes. The status is reflected in Client::status() and Service::Status() , which are either NotConnected - no network connection, or not registered properly Unavailable - TCP/IP connection works, but no plugin with the same name on the other side Enabled - You can connect to plugin on other side The status changes happen automatically (no setEnabled() anymore). Furthermore a version ID was added to the handshake, so that we can extend the protocol further in the future :)
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp5
-rw-r--r--tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp60
-rw-r--r--tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp41
-rw-r--r--tests/auto/declarative/shared/debugutil.cpp13
-rw-r--r--tests/auto/declarative/shared/debugutil_p.h8
5 files changed, 58 insertions, 69 deletions
diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
index adba190..dd58baf 100644
--- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
+++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
@@ -324,13 +324,16 @@ void tst_QDeclarativeDebug::initTestCase()
bool ok = m_conn->waitForConnected();
Q_ASSERT(ok);
QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
-
m_dbg = new QDeclarativeEngineDebug(m_conn, this);
+ QTRY_VERIFY(m_dbg->status() == QDeclarativeEngineDebug::Enabled);
}
void tst_QDeclarativeDebug::cleanupTestCase()
{
+ delete m_dbg;
+ delete m_conn;
qDeleteAll(m_components);
+ delete m_engine;
}
void tst_QDeclarativeDebug::setMethodBody()
diff --git a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
index 7db0e60..72af3eb 100644
--- a/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
+++ b/tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
@@ -66,9 +66,7 @@ private slots:
void initTestCase();
void name();
- void isEnabled();
- void setEnabled();
- void isConnected();
+ void status();
void sendMessage();
};
@@ -96,46 +94,33 @@ void tst_QDeclarativeDebugClient::name()
QCOMPARE(client.name(), name);
}
-void tst_QDeclarativeDebugClient::isEnabled()
+void tst_QDeclarativeDebugClient::status()
{
- QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::isEnabled()", m_conn);
- QCOMPARE(client.isEnabled(), false);
-}
+ {
+ QDeclarativeDebugConnection dummyConn;
+ QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::status()", &dummyConn);
+ QCOMPARE(client.status(), QDeclarativeDebugClient::NotConnected);
+ }
-void tst_QDeclarativeDebugClient::setEnabled()
-{
- QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::setEnabled()");
- QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::setEnabled()", m_conn);
+ QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::status()", m_conn);
+ QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
- QCOMPARE(service.isEnabled(), false);
+ {
+ QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()");
+ QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()));
+ QCOMPARE(client.status(), QDeclarativeDebugClient::Enabled);
+ }
+ QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()));
- client.setEnabled(true);
- QCOMPARE(client.isEnabled(), true);
- QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
- QCOMPARE(service.isEnabled(), true);
-
- client.setEnabled(false);
- QCOMPARE(client.isEnabled(), false);
- QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
- QCOMPARE(service.isEnabled(), false);
-}
-
-void tst_QDeclarativeDebugClient::isConnected()
-{
- QDeclarativeDebugClient client1("tst_QDeclarativeDebugClient::isConnected() A", m_conn);
- QCOMPARE(client1.isConnected(), true);
-
- QDeclarativeDebugConnection conn;
- QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::isConnected() B", &conn);
- QCOMPARE(client2.isConnected(), false);
-
- QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::isConnected() C", 0);
- QCOMPARE(client3.isConnected(), false);
+ QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
// duplicate plugin name
- QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::isConnected() A\" ");
- QDeclarativeDebugClient client4("tst_QDeclarativeDebugClient::isConnected() A", m_conn);
- QCOMPARE(client4.isConnected(), false);
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::status()\" ");
+ QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::status()", m_conn);
+ QCOMPARE(client2.status(), QDeclarativeDebugClient::NotConnected);
+
+ QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::status3()", 0);
+ QCOMPARE(client3.status(), QDeclarativeDebugClient::NotConnected);
}
void tst_QDeclarativeDebugClient::sendMessage()
@@ -145,6 +130,7 @@ void tst_QDeclarativeDebugClient::sendMessage()
QByteArray msg = "hello!";
+ QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()));
client.sendMessage(msg);
QByteArray resp = client.waitForResponse();
QCOMPARE(resp, msg);
diff --git a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
index 4683199..bce4713 100644
--- a/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
+++ b/tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
@@ -66,8 +66,7 @@ private slots:
void initTestCase();
void name();
- void isEnabled();
- void enabledChanged();
+ void status();
void sendMessage();
void idForObject();
void objectForId();
@@ -97,31 +96,24 @@ void tst_QDeclarativeDebugService::name()
QCOMPARE(service.name(), name);
}
-void tst_QDeclarativeDebugService::isEnabled()
+void tst_QDeclarativeDebugService::status()
{
- QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::isEnabled()", m_conn);
- QCOMPARE(service.isEnabled(), false);
+ QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::status()");
+ QCOMPARE(service.status(), QDeclarativeDebugService::Unavailable);
- QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::isEnabled()", m_conn);
- client.setEnabled(true);
- QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
- QCOMPARE(service.isEnabled(), true);
+ {
+ QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::status()", m_conn);
+ QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(statusHasChanged()));
+ QCOMPARE(service.status(), QDeclarativeDebugService::Enabled);
+ }
- QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::isEnabled()\" ");
- QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::isEnabled()", m_conn);
- QCOMPARE(duplicate.isEnabled(), false);
-}
-
-void tst_QDeclarativeDebugService::enabledChanged()
-{
- QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::enabledChanged()");
- QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::enabledChanged()", m_conn);
+ QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(statusHasChanged()));
+ QCOMPARE(service.status(), QDeclarativeDebugService::Unavailable);
- QCOMPARE(service.enabled, false);
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::status()\" ");
- client.setEnabled(true);
- QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
- QCOMPARE(service.enabled, true);
+ QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::status()");
+ QCOMPARE(duplicate.status(), QDeclarativeDebugService::NotConnected);
}
void tst_QDeclarativeDebugService::sendMessage()
@@ -131,6 +123,11 @@ void tst_QDeclarativeDebugService::sendMessage()
QByteArray msg = "hello!";
+ if (service.status() != QDeclarativeDebugService::Enabled)
+ QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(statusHasChanged()));
+ if (client.status() != QDeclarativeDebugClient::Enabled)
+ QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()));
+
client.sendMessage(msg);
QByteArray resp = client.waitForResponse();
QCOMPARE(resp, msg);
diff --git a/tests/auto/declarative/shared/debugutil.cpp b/tests/auto/declarative/shared/debugutil.cpp
index c0c3eca..5f68e44 100644
--- a/tests/auto/declarative/shared/debugutil.cpp
+++ b/tests/auto/declarative/shared/debugutil.cpp
@@ -60,7 +60,7 @@ bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member,
}
QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent)
- : QDeclarativeDebugService(s, parent), enabled(false)
+ : QDeclarativeDebugService(s, parent)
{
}
@@ -69,10 +69,9 @@ void QDeclarativeDebugTestService::messageReceived(const QByteArray &ba)
sendMessage(ba);
}
-void QDeclarativeDebugTestService::enabledChanged(bool e)
+void QDeclarativeDebugTestService::statusChanged(Status)
{
- enabled = e;
- emit enabledStateChanged();
+ emit statusHasChanged();
}
@@ -92,9 +91,13 @@ QByteArray QDeclarativeDebugTestClient::waitForResponse()
return lastMsg;
}
+void QDeclarativeDebugTestClient::statusChanged(Status status)
+{
+ emit statusHasChanged();
+}
+
void QDeclarativeDebugTestClient::messageReceived(const QByteArray &ba)
{
lastMsg = ba;
emit serverMessage(ba);
}
-
diff --git a/tests/auto/declarative/shared/debugutil_p.h b/tests/auto/declarative/shared/debugutil_p.h
index e6bb7ad..434e053 100644
--- a/tests/auto/declarative/shared/debugutil_p.h
+++ b/tests/auto/declarative/shared/debugutil_p.h
@@ -62,15 +62,13 @@ class QDeclarativeDebugTestService : public QDeclarativeDebugService
Q_OBJECT
public:
QDeclarativeDebugTestService(const QString &s, QObject *parent = 0);
- bool enabled;
signals:
- void enabledStateChanged();
+ void statusHasChanged();
protected:
virtual void messageReceived(const QByteArray &ba);
-
- virtual void enabledChanged(bool e);
+ virtual void statusChanged(Status status);
};
class QDeclarativeDebugTestClient : public QDeclarativeDebugClient
@@ -82,9 +80,11 @@ public:
QByteArray waitForResponse();
signals:
+ void statusHasChanged();
void serverMessage(const QByteArray &);
protected:
+ virtual void statusChanged(Status status);
virtual void messageReceived(const QByteArray &ba);
private: