test the handshake message
This commit is contained in:
parent
21c14cd6db
commit
0110e3a8eb
@ -248,7 +248,7 @@ void JsonRPCServer::clientConnected(const QUuid &clientId)
|
|||||||
QVariantMap handshake;
|
QVariantMap handshake;
|
||||||
handshake.insert("id", 0);
|
handshake.insert("id", 0);
|
||||||
handshake.insert("server", "guh JSONRPC interface");
|
handshake.insert("server", "guh JSONRPC interface");
|
||||||
handshake.insert("version", "0.0.0");
|
handshake.insert("version", GUH_VERSION_STRING);
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(handshake);
|
QJsonDocument jsonDoc = QJsonDocument::fromVariant(handshake);
|
||||||
m_tcpServer->sendData(clientId, jsonDoc.toJson());
|
m_tcpServer->sendData(clientId, jsonDoc.toJson());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,8 @@ class TestJSONRPC: public GuhTestBase
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void testHandshake();
|
||||||
|
|
||||||
void testBasicCall_data();
|
void testBasicCall_data();
|
||||||
void testBasicCall();
|
void testBasicCall();
|
||||||
|
|
||||||
@ -76,6 +78,20 @@ QStringList TestJSONRPC::extractRefs(const QVariant &variant)
|
|||||||
return QStringList();
|
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()
|
void TestJSONRPC::testBasicCall_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QByteArray>("call");
|
QTest::addColumn<QByteArray>("call");
|
||||||
|
|||||||
@ -41,6 +41,8 @@ signals:
|
|||||||
/************** Used for testing **************************/
|
/************** Used for testing **************************/
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void clientConnected(const QUuid &clientId);
|
||||||
|
void clientDisconnected(const QUuid &clientId);
|
||||||
void dataAvailable(const QUuid &clientId, const QByteArray &data);
|
void dataAvailable(const QUuid &clientId, const QByteArray &data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user