2013-07-03 06:26:19 +08:00
|
|
|
#include <QSignalSpy>
|
2013-07-02 12:45:04 +08:00
|
|
|
#include <QTest>
|
|
|
|
|
|
2013-07-03 06:26:19 +08:00
|
|
|
#include <qredis/request.h>
|
2013-07-02 12:45:04 +08:00
|
|
|
#include "testclient.h"
|
|
|
|
|
|
|
|
|
|
void TestClient::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
client.connectToHost("localhost");
|
|
|
|
|
QVERIFY(client.waitForConnected());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestClient::cleanupTestCase()
|
|
|
|
|
{
|
|
|
|
|
client.disconnectFromHost();
|
2013-07-02 12:51:48 +08:00
|
|
|
|
|
|
|
|
if(client.isConnected())
|
|
|
|
|
QVERIFY(client.waitForDisconnected());
|
2013-07-02 12:45:04 +08:00
|
|
|
}
|
2013-07-03 06:26:19 +08:00
|
|
|
|
|
|
|
|
void TestClient::testPing()
|
|
|
|
|
{
|
|
|
|
|
QRedis::Request * request = client.sendCommand("PING");
|
2013-07-05 00:25:46 +08:00
|
|
|
QSignalSpy spy(request, SIGNAL(status(QString)));
|
2013-07-04 01:55:41 +08:00
|
|
|
|
2013-07-03 06:26:19 +08:00
|
|
|
QVERIFY(request->waitForReply());
|
2013-07-04 01:55:41 +08:00
|
|
|
QCOMPARE(spy.count(), 1);
|
2013-07-05 00:25:46 +08:00
|
|
|
QCOMPARE(spy[0][0].toString(), QString("PONG"));
|
2013-07-03 06:26:19 +08:00
|
|
|
}
|
2013-07-05 00:43:29 +08:00
|
|
|
|
|
|
|
|
void TestClient::testStorage()
|
|
|
|
|
{
|
|
|
|
|
QRedis::Request * request1 = client.sendCommand("SET value 10");
|
|
|
|
|
QSignalSpy spy1(request1, SIGNAL(status(QString)));
|
|
|
|
|
|
|
|
|
|
QVERIFY(request1->waitForReply());
|
|
|
|
|
QCOMPARE(spy1.count(), 1);
|
|
|
|
|
QCOMPARE(spy1[0][0].toString(), QString("OK"));
|
|
|
|
|
|
|
|
|
|
QRedis::Request * request2 = client.sendCommand("GET value");
|
|
|
|
|
QSignalSpy spy2(request2, SIGNAL(bulk(QByteArray)));
|
|
|
|
|
|
|
|
|
|
QVERIFY(request2->waitForReply());
|
|
|
|
|
QCOMPARE(spy2.count(), 1);
|
|
|
|
|
QCOMPARE(spy2[0][0].toByteArray(), QByteArray("10"));
|
|
|
|
|
}
|