From 0110e3a8eb3a387fbe7e02a835ae1420e014e496 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 5 May 2014 00:35:06 +0200 Subject: [PATCH] test the handshake message --- server/jsonrpc/jsonrpcserver.cpp | 2 +- tests/auto/jsonrpc/testjsonrpc.cpp | 16 ++++++++++++++++ tests/auto/mocktcpserver.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/jsonrpc/jsonrpcserver.cpp b/server/jsonrpc/jsonrpcserver.cpp index 2e00291c..5aa2a0ba 100644 --- a/server/jsonrpc/jsonrpcserver.cpp +++ b/server/jsonrpc/jsonrpcserver.cpp @@ -248,7 +248,7 @@ void JsonRPCServer::clientConnected(const QUuid &clientId) QVariantMap handshake; handshake.insert("id", 0); handshake.insert("server", "guh JSONRPC interface"); - handshake.insert("version", "0.0.0"); + handshake.insert("version", GUH_VERSION_STRING); QJsonDocument jsonDoc = QJsonDocument::fromVariant(handshake); m_tcpServer->sendData(clientId, jsonDoc.toJson()); } diff --git a/tests/auto/jsonrpc/testjsonrpc.cpp b/tests/auto/jsonrpc/testjsonrpc.cpp index 17490a98..bd2eb376 100644 --- a/tests/auto/jsonrpc/testjsonrpc.cpp +++ b/tests/auto/jsonrpc/testjsonrpc.cpp @@ -35,6 +35,8 @@ class TestJSONRPC: public GuhTestBase Q_OBJECT private slots: + void testHandshake(); + void testBasicCall_data(); void testBasicCall(); @@ -76,6 +78,20 @@ QStringList TestJSONRPC::extractRefs(const QVariant &variant) return QStringList(); } +void TestJSONRPC::testHandshake() +{ + QSignalSpy spy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); + + QUuid newClientId = QUuid::createUuid(); + m_mockTcpServer->clientConnected(newClientId); + QVERIFY2(spy.count() > 0, "Did not get the handshake message upon connect."); + QVERIFY2(spy.first().first() == newClientId, "Handshake message addressed at the wrong client."); + + QJsonDocument jsonDoc = QJsonDocument::fromJson(spy.first().at(1).toByteArray()); + QVariantMap handShake = jsonDoc.toVariant().toMap(); + QVERIFY2(handShake.value("version").toString() == GUH_VERSION_STRING, "Handshake version doesn't match Guh version."); +} + void TestJSONRPC::testBasicCall_data() { QTest::addColumn("call"); diff --git a/tests/auto/mocktcpserver.h b/tests/auto/mocktcpserver.h index 28193001..c159b3b3 100644 --- a/tests/auto/mocktcpserver.h +++ b/tests/auto/mocktcpserver.h @@ -41,6 +41,8 @@ signals: /************** Used for testing **************************/ signals: + void clientConnected(const QUuid &clientId); + void clientDisconnected(const QUuid &clientId); void dataAvailable(const QUuid &clientId, const QByteArray &data); public slots: