diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2015-03-23 14:36:19 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2015-04-10 05:37:11 +0000 |
commit | 853cba729bc2bbac254ee36be6d42241eb92fd21 (patch) | |
tree | edd86f3f1e1b34bf1247ec598a55ddd3eb2c482a /tests/auto/corelib/tools/qringbuffer | |
parent | 921b22e5cee1be54b96dcd1eebbb3db48301bc9a (diff) |
QRingBuffer: allow to peek bytes from any position
Add an ordinary peek() function which also allows retrieving data from
a specified position. We need this functionality in several places.
Change-Id: Ia4a1b6fe1d7f76cb8f6f1ea34b3e4b89e05a2a68
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.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp index 33e143fa7d..044fdbdee5 100644 --- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp +++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp @@ -52,6 +52,7 @@ private slots: void ungetChar(); void indexOf(); void appendAndRead(); + void peek(); void readLine(); }; @@ -280,6 +281,31 @@ void tst_QRingBuffer::appendAndRead() QVERIFY(ringBuffer.read() == ba3); } +void tst_QRingBuffer::peek() +{ + QRingBuffer ringBuffer; + QByteArray testBuffer; + // fill buffer with an arithmetic progression + for (int i = 1; i < 256; ++i) { + char *ringPos = ringBuffer.reserve(i); + QVERIFY(ringPos); + memset(ringPos, i, i); + testBuffer.append(ringPos, i); + } + + // check stored data + QByteArray resultBuffer; + int peekPosition = testBuffer.size(); + for (int i = 1; i < 256; ++i) { + QByteArray ba(i, 0); + peekPosition -= i; + qint64 thisPeek = ringBuffer.peek(ba.data(), i, peekPosition); + QCOMPARE(thisPeek, qint64(i)); + resultBuffer.prepend(ba); + } + QCOMPARE(testBuffer, resultBuffer); +} + void tst_QRingBuffer::readLine() { QRingBuffer ringBuffer; |