summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qringbuffer
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-07-12 16:14:11 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2016-07-23 09:05:13 +0000
commit3c6a7a96ef17d5bd1fbea1d9e06617d281c6ca20 (patch)
treefa9927bdf77e682b2efed3098d6fb663915cc48d /tests/auto/corelib/tools/qringbuffer
parent3605fc653b3f54c9cda59fb3bf29b97d85ae0737 (diff)
QRingBuffer: add packet mode
As a special case, setting the value of chunk size to zero forces QRingBuffer to produce a separate QByteArray on each call which appends the data. So, this enables a packet mode where portions of data are stored independently from each other. Change-Id: I2d0b331211901a289da7d4533e974f06830b5590 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qringbuffer')
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index 4e14fd7a9b..145ba7ff72 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -45,6 +45,7 @@ private slots:
void sizeWhenReserved();
void free();
void reserveAndRead();
+ void reserveAndReadInPacketMode();
void reserveFrontAndRead();
void chop();
void ungetChar();
@@ -243,6 +244,25 @@ void tst_QRingBuffer::reserveAndRead()
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
}
+void tst_QRingBuffer::reserveAndReadInPacketMode()
+{
+ QRingBuffer ringBuffer(0);
+ // try to allocate 255 buffers
+ for (int i = 1; i < 256; ++i) {
+ char *ringPos = ringBuffer.reserve(i);
+ QVERIFY(ringPos);
+ }
+
+ // count and check the size of stored buffers
+ int buffersCount = 0;
+ while (!ringBuffer.isEmpty()) {
+ QByteArray ba = ringBuffer.read();
+ ++buffersCount;
+ QCOMPARE(ba.size(), buffersCount);
+ }
+ QCOMPARE(buffersCount, 255);
+}
+
void tst_QRingBuffer::reserveFrontAndRead()
{
QRingBuffer ringBuffer;