Implemented parsing of bulk replies and added test for data storage.

This commit is contained in:
Nathan Osman 2013-07-04 09:43:29 -07:00
parent e049215a70
commit 45e7ada7dc
3 changed files with 32 additions and 0 deletions

View File

@ -54,6 +54,20 @@ bool ClientPrivate::readInteger()
bool ClientPrivate::readBulk()
{
/* Check if the reply contains \r\n. */
int pos = buffer.indexOf("\r\n");
if(pos != -1)
{
int length = buffer.mid(1, pos -1).toInt();
if(buffer.size() >= pos + length + 4)
{
emit queue.dequeue()->bulk(buffer.mid(pos + 2, length));
buffer.remove(0, pos + length + 4);
return true;
}
}
return false;
}

View File

@ -27,3 +27,20 @@ void TestClient::testPing()
QCOMPARE(spy.count(), 1);
QCOMPARE(spy[0][0].toString(), QString("PONG"));
}
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"));
}

View File

@ -15,6 +15,7 @@ class TestClient : public QObject
void cleanupTestCase();
void testPing();
void testStorage();
private: