test the handshake message

This commit is contained in:
Michael Zanetti 2014-05-05 00:35:06 +02:00
parent 21c14cd6db
commit 0110e3a8eb
3 changed files with 19 additions and 1 deletions

View File

@ -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());
}

View File

@ -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<QByteArray>("call");

View File

@ -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: