Make QRingBuffer a 64-bit safe
According to I/O API, QIODevice and its inherited classes should be able to process a full 64-bit offsets and lengths. This requires 64-bit parameters in operations with internal buffers. Rework QRingBuffer to avoid implicit truncation of numbers and fix some 64-bit issues in code. Change-Id: Iadd6fd5fefd2d64e6c084e2feebb4dc2d6df66de Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
2d5210a684
commit
9dd0bb851b
@ -481,7 +481,7 @@ bool QFileDevicePrivate::putCharHelper(char c)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// Cutoff for code that doesn't only touch the buffer.
|
// Cutoff for code that doesn't only touch the buffer.
|
||||||
int writeBufferSize = writeBuffer.size();
|
qint64 writeBufferSize = writeBuffer.size();
|
||||||
if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE
|
if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|| ((openMode & QIODevice::Text) && c == '\n' && writeBufferSize + 2 >= QFILE_WRITEBUFFER_SIZE)
|
|| ((openMode & QIODevice::Text) && c == '\n' && writeBufferSize + 2 >= QFILE_WRITEBUFFER_SIZE)
|
||||||
|
@ -1912,11 +1912,11 @@ qint64 QProcess::readData(char *data, qint64 maxlen)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 bytesToRead = qint64(qMin(readBuffer->size(), (int)maxlen));
|
qint64 bytesToRead = qMin(readBuffer->size(), maxlen);
|
||||||
qint64 readSoFar = 0;
|
qint64 readSoFar = 0;
|
||||||
while (readSoFar < bytesToRead) {
|
while (readSoFar < bytesToRead) {
|
||||||
const char *ptr = readBuffer->readPointer();
|
const char *ptr = readBuffer->readPointer();
|
||||||
int bytesToReadFromThisBlock = qMin<qint64>(bytesToRead - readSoFar,
|
qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
|
||||||
readBuffer->nextDataBlockSize());
|
readBuffer->nextDataBlockSize());
|
||||||
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
|
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
|
||||||
readSoFar += bytesToReadFromThisBlock;
|
readSoFar += bytesToReadFromThisBlock;
|
||||||
|
@ -45,8 +45,8 @@ QWindowsPipeReader::QWindowsPipeReader(QObject *parent)
|
|||||||
handle(INVALID_HANDLE_VALUE),
|
handle(INVALID_HANDLE_VALUE),
|
||||||
readBufferMaxSize(0),
|
readBufferMaxSize(0),
|
||||||
actualReadBufferSize(0),
|
actualReadBufferSize(0),
|
||||||
readSequenceStarted(false),
|
|
||||||
emitReadyReadTimer(new QTimer(this)),
|
emitReadyReadTimer(new QTimer(this)),
|
||||||
|
readSequenceStarted(false),
|
||||||
pipeBroken(false),
|
pipeBroken(false),
|
||||||
readyReadEmitted(false)
|
readyReadEmitted(false)
|
||||||
{
|
{
|
||||||
@ -133,12 +133,12 @@ qint64 QWindowsPipeReader::read(char *data, qint64 maxlen)
|
|||||||
actualReadBufferSize--;
|
actualReadBufferSize--;
|
||||||
readSoFar = 1;
|
readSoFar = 1;
|
||||||
} else {
|
} else {
|
||||||
qint64 bytesToRead = qMin(qint64(actualReadBufferSize), maxlen);
|
qint64 bytesToRead = qMin(actualReadBufferSize, maxlen);
|
||||||
readSoFar = 0;
|
readSoFar = 0;
|
||||||
while (readSoFar < bytesToRead) {
|
while (readSoFar < bytesToRead) {
|
||||||
const char *ptr = readBuffer.readPointer();
|
const char *ptr = readBuffer.readPointer();
|
||||||
int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
|
qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
|
||||||
qint64(readBuffer.nextDataBlockSize()));
|
readBuffer.nextDataBlockSize());
|
||||||
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
|
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
|
||||||
readSoFar += bytesToReadFromThisBlock;
|
readSoFar += bytesToReadFromThisBlock;
|
||||||
readBuffer.free(bytesToReadFromThisBlock);
|
readBuffer.free(bytesToReadFromThisBlock);
|
||||||
|
@ -98,9 +98,9 @@ private:
|
|||||||
QWinOverlappedIoNotifier *dataReadNotifier;
|
QWinOverlappedIoNotifier *dataReadNotifier;
|
||||||
qint64 readBufferMaxSize;
|
qint64 readBufferMaxSize;
|
||||||
QRingBuffer readBuffer;
|
QRingBuffer readBuffer;
|
||||||
int actualReadBufferSize;
|
qint64 actualReadBufferSize;
|
||||||
bool readSequenceStarted;
|
|
||||||
QTimer *emitReadyReadTimer;
|
QTimer *emitReadyReadTimer;
|
||||||
|
bool readSequenceStarted;
|
||||||
bool pipeBroken;
|
bool pipeBroken;
|
||||||
bool readyReadEmitted;
|
bool readyReadEmitted;
|
||||||
};
|
};
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
buffers.append(QByteArray());
|
buffers.append(QByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int nextDataBlockSize() const {
|
inline qint64 nextDataBlockSize() const {
|
||||||
return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
|
return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,9 +86,9 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void free(int bytes) {
|
inline void free(qint64 bytes) {
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
int blockSize = buffers.first().size() - head;
|
const qint64 blockSize = buffers.first().size() - head;
|
||||||
|
|
||||||
if (tailBuffer == 0 || blockSize > bytes) {
|
if (tailBuffer == 0 || blockSize > bytes) {
|
||||||
// keep a single block around if it does not exceed
|
// keep a single block around if it does not exceed
|
||||||
@ -102,7 +102,8 @@ public:
|
|||||||
clear(); // try to minify/squeeze us
|
clear(); // try to minify/squeeze us
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
head += bytes;
|
Q_ASSERT(quint64(bytes) < QByteArray::MaxSize);
|
||||||
|
head += int(bytes);
|
||||||
bufferSize -= bytes;
|
bufferSize -= bytes;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -116,13 +117,15 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char *reserve(int bytes) {
|
inline char *reserve(qint64 bytes) {
|
||||||
if (bytes <= 0)
|
if (bytes <= 0 || quint64(bytes) >= QByteArray::MaxSize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
const qint64 newSize = bytes + tail;
|
||||||
// if need buffer reallocation
|
// if need buffer reallocation
|
||||||
if (tail + bytes > buffers.last().size()) {
|
if (newSize > buffers.last().size()) {
|
||||||
if (tail + bytes > buffers.last().capacity() && tail >= basicBlockSize) {
|
if (newSize > buffers.last().capacity() && (tail >= basicBlockSize
|
||||||
|
|| quint64(newSize) >= QByteArray::MaxSize)) {
|
||||||
// shrink this buffer to its current size
|
// shrink this buffer to its current size
|
||||||
buffers.last().resize(tail);
|
buffers.last().resize(tail);
|
||||||
|
|
||||||
@ -131,21 +134,22 @@ public:
|
|||||||
++tailBuffer;
|
++tailBuffer;
|
||||||
tail = 0;
|
tail = 0;
|
||||||
}
|
}
|
||||||
buffers.last().resize(qMax(basicBlockSize, tail + bytes));
|
buffers.last().resize(qMax(basicBlockSize, tail + int(bytes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
char *writePtr = buffers.last().data() + tail;
|
char *writePtr = buffers.last().data() + tail;
|
||||||
bufferSize += bytes;
|
bufferSize += bytes;
|
||||||
tail += bytes;
|
Q_ASSERT(quint64(bytes) < QByteArray::MaxSize);
|
||||||
|
tail += int(bytes);
|
||||||
return writePtr;
|
return writePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void truncate(int pos) {
|
inline void truncate(qint64 pos) {
|
||||||
if (pos < size())
|
if (pos < size())
|
||||||
chop(size() - pos);
|
chop(size() - pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void chop(int bytes) {
|
inline void chop(qint64 bytes) {
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
if (tailBuffer == 0 || tail > bytes) {
|
if (tailBuffer == 0 || tail > bytes) {
|
||||||
// keep a single block around if it does not exceed
|
// keep a single block around if it does not exceed
|
||||||
@ -159,7 +163,8 @@ public:
|
|||||||
clear(); // try to minify/squeeze us
|
clear(); // try to minify/squeeze us
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tail -= bytes;
|
Q_ASSERT(quint64(bytes) < QByteArray::MaxSize);
|
||||||
|
tail -= int(bytes);
|
||||||
bufferSize -= bytes;
|
bufferSize -= bytes;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -206,7 +211,7 @@ public:
|
|||||||
++bufferSize;
|
++bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int size() const {
|
inline qint64 size() const {
|
||||||
return bufferSize;
|
return bufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,9 +224,9 @@ public:
|
|||||||
bufferSize = 0;
|
bufferSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int indexOf(char c) const {
|
inline qint64 indexOf(char c) const {
|
||||||
int index = 0;
|
qint64 index = 0;
|
||||||
int j = head;
|
qint64 j = head;
|
||||||
for (int i = 0; i < buffers.size(); ++i) {
|
for (int i = 0; i < buffers.size(); ++i) {
|
||||||
const char *ptr = buffers[i].constData() + j;
|
const char *ptr = buffers[i].constData() + j;
|
||||||
j = index + (i == tailBuffer ? tail : buffers[i].size()) - j;
|
j = index + (i == tailBuffer ? tail : buffers[i].size()) - j;
|
||||||
@ -236,9 +241,9 @@ public:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int indexOf(char c, int maxLength) const {
|
inline qint64 indexOf(char c, qint64 maxLength) const {
|
||||||
int index = 0;
|
qint64 index = 0;
|
||||||
int j = head;
|
qint64 j = head;
|
||||||
for (int i = 0; index < maxLength && i < buffers.size(); ++i) {
|
for (int i = 0; index < maxLength && i < buffers.size(); ++i) {
|
||||||
const char *ptr = buffers[i].constData() + j;
|
const char *ptr = buffers[i].constData() + j;
|
||||||
j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength);
|
j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength);
|
||||||
@ -253,11 +258,12 @@ public:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int read(char *data, int maxLength) {
|
inline qint64 read(char *data, qint64 maxLength) {
|
||||||
int bytesToRead = qMin(size(), maxLength);
|
const qint64 bytesToRead = qMin(size(), maxLength);
|
||||||
int readSoFar = 0;
|
qint64 readSoFar = 0;
|
||||||
while (readSoFar < bytesToRead) {
|
while (readSoFar < bytesToRead) {
|
||||||
int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, nextDataBlockSize());
|
const qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
|
||||||
|
nextDataBlockSize());
|
||||||
if (data)
|
if (data)
|
||||||
memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock);
|
memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock);
|
||||||
readSoFar += bytesToReadFromThisBlock;
|
readSoFar += bytesToReadFromThisBlock;
|
||||||
@ -300,15 +306,15 @@ public:
|
|||||||
bufferSize += tail;
|
bufferSize += tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int skip(int length) {
|
inline qint64 skip(qint64 length) {
|
||||||
return read(0, length);
|
return read(0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int readLine(char *data, int maxLength) {
|
inline qint64 readLine(char *data, qint64 maxLength) {
|
||||||
if (!data || --maxLength <= 0)
|
if (!data || --maxLength <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int i = indexOf('\n', maxLength);
|
qint64 i = indexOf('\n', maxLength);
|
||||||
i = read(data, i >= 0 ? (i + 1) : maxLength);
|
i = read(data, i >= 0 ? (i + 1) : maxLength);
|
||||||
|
|
||||||
// Terminate it.
|
// Terminate it.
|
||||||
@ -325,7 +331,7 @@ private:
|
|||||||
int head, tail;
|
int head, tail;
|
||||||
int tailBuffer; // always buffers.size() - 1
|
int tailBuffer; // always buffers.size() - 1
|
||||||
const int basicBlockSize;
|
const int basicBlockSize;
|
||||||
int bufferSize;
|
qint64 bufferSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -812,7 +812,7 @@ bool QAbstractSocketPrivate::canWriteNotification()
|
|||||||
#if defined (QABSTRACTSOCKET_DEBUG)
|
#if defined (QABSTRACTSOCKET_DEBUG)
|
||||||
qDebug("QAbstractSocketPrivate::canWriteNotification() flushing");
|
qDebug("QAbstractSocketPrivate::canWriteNotification() flushing");
|
||||||
#endif
|
#endif
|
||||||
int tmp = writeBuffer.size();
|
qint64 tmp = writeBuffer.size();
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
if (socketEngine) {
|
if (socketEngine) {
|
||||||
@ -872,7 +872,7 @@ bool QAbstractSocketPrivate::flush()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextSize = writeBuffer.nextDataBlockSize();
|
qint64 nextSize = writeBuffer.nextDataBlockSize();
|
||||||
const char *ptr = writeBuffer.readPointer();
|
const char *ptr = writeBuffer.readPointer();
|
||||||
|
|
||||||
// Attempt to write it all in one chunk.
|
// Attempt to write it all in one chunk.
|
||||||
@ -1707,9 +1707,9 @@ qint64 QAbstractSocket::bytesToWrite() const
|
|||||||
{
|
{
|
||||||
Q_D(const QAbstractSocket);
|
Q_D(const QAbstractSocket);
|
||||||
#if defined(QABSTRACTSOCKET_DEBUG)
|
#if defined(QABSTRACTSOCKET_DEBUG)
|
||||||
qDebug("QAbstractSocket::bytesToWrite() == %i", d->writeBuffer.size());
|
qDebug("QAbstractSocket::bytesToWrite() == %lld", d->writeBuffer.size());
|
||||||
#endif
|
#endif
|
||||||
return (qint64)d->writeBuffer.size();
|
return d->writeBuffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -60,7 +60,7 @@ void tst_QRingBuffer::sizeWhenReserved()
|
|||||||
QRingBuffer ringBuffer;
|
QRingBuffer ringBuffer;
|
||||||
ringBuffer.reserve(5);
|
ringBuffer.reserve(5);
|
||||||
|
|
||||||
QCOMPARE(ringBuffer.size(), 5);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRingBuffer::sizeWhenReservedAndChopped()
|
void tst_QRingBuffer::sizeWhenReservedAndChopped()
|
||||||
@ -69,14 +69,14 @@ void tst_QRingBuffer::sizeWhenReservedAndChopped()
|
|||||||
ringBuffer.reserve(31337);
|
ringBuffer.reserve(31337);
|
||||||
ringBuffer.chop(31337);
|
ringBuffer.chop(31337);
|
||||||
|
|
||||||
QCOMPARE(ringBuffer.size(), 0);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRingBuffer::sizeWhenEmpty()
|
void tst_QRingBuffer::sizeWhenEmpty()
|
||||||
{
|
{
|
||||||
QRingBuffer ringBuffer;
|
QRingBuffer ringBuffer;
|
||||||
|
|
||||||
QCOMPARE(ringBuffer.size(), 0);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRingBuffer::readPointerAtPositionReadTooMuch()
|
void tst_QRingBuffer::readPointerAtPositionReadTooMuch()
|
||||||
@ -101,22 +101,22 @@ void tst_QRingBuffer::readPointerAtPositionWithHead()
|
|||||||
qint64 length;
|
qint64 length;
|
||||||
const char* buf2 = ringBuffer.readPointerAtPosition(0, length);
|
const char* buf2 = ringBuffer.readPointerAtPosition(0, length);
|
||||||
|
|
||||||
QCOMPARE(length, qint64(2));
|
QCOMPARE(length, Q_INT64_C(2));
|
||||||
QVERIFY(*buf2 == '2');
|
QVERIFY(*buf2 == '2');
|
||||||
QVERIFY(*(buf2+1) == '3');
|
QVERIFY(*(buf2+1) == '3');
|
||||||
|
|
||||||
// advance 2 more, ringBuffer should be empty then
|
// advance 2 more, ringBuffer should be empty then
|
||||||
ringBuffer.free(2);
|
ringBuffer.free(2);
|
||||||
buf2 = ringBuffer.readPointerAtPosition(0, length);
|
buf2 = ringBuffer.readPointerAtPosition(0, length);
|
||||||
QCOMPARE(length, qint64(0));
|
QCOMPARE(length, Q_INT64_C(0));
|
||||||
QVERIFY(buf2 == 0);
|
QVERIFY(buf2 == 0);
|
||||||
|
|
||||||
// check buffer with 2 blocks
|
// check buffer with 2 blocks
|
||||||
memcpy(ringBuffer.reserve(4), "0123", 4);
|
memcpy(ringBuffer.reserve(4), "0123", 4);
|
||||||
ringBuffer.append(QByteArray("45678", 5));
|
ringBuffer.append(QByteArray("45678", 5));
|
||||||
ringBuffer.free(3);
|
ringBuffer.free(3);
|
||||||
buf2 = ringBuffer.readPointerAtPosition(1, length);
|
buf2 = ringBuffer.readPointerAtPosition(Q_INT64_C(1), length);
|
||||||
QCOMPARE(length, qint64(5));
|
QCOMPARE(length, Q_INT64_C(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRingBuffer::readPointerAtPositionEmptyRead()
|
void tst_QRingBuffer::readPointerAtPositionEmptyRead()
|
||||||
@ -149,14 +149,14 @@ void tst_QRingBuffer::readPointerAtPositionWriteRead()
|
|||||||
// write in chunks of 50 bytes
|
// write in chunks of 50 bytes
|
||||||
// this ensures there will be multiple QByteArrays inside the QRingBuffer
|
// this ensures there will be multiple QByteArrays inside the QRingBuffer
|
||||||
// since QRingBuffer is then only using individual arrays of around 4000 bytes
|
// since QRingBuffer is then only using individual arrays of around 4000 bytes
|
||||||
qint64 thisWrite = qMin(remaining, qint64(50));
|
qint64 thisWrite = qMin(remaining, Q_INT64_C(50));
|
||||||
char *pos = ringBuffer.reserve(thisWrite);
|
char *pos = ringBuffer.reserve(thisWrite);
|
||||||
inData.read(pos, thisWrite);
|
inData.read(pos, thisWrite);
|
||||||
remaining -= thisWrite;
|
remaining -= thisWrite;
|
||||||
}
|
}
|
||||||
// was data put into it?
|
// was data put into it?
|
||||||
QVERIFY(ringBuffer.size() > 0);
|
QVERIFY(ringBuffer.size() > 0);
|
||||||
QCOMPARE(qint64(ringBuffer.size()), inData.size());
|
QCOMPARE(ringBuffer.size(), inData.size());
|
||||||
|
|
||||||
//read from the QRingBuffer in loop, put back into another QBuffer
|
//read from the QRingBuffer in loop, put back into another QBuffer
|
||||||
QBuffer outData;
|
QBuffer outData;
|
||||||
@ -187,12 +187,12 @@ void tst_QRingBuffer::free()
|
|||||||
ringBuffer.append(QByteArray("01234", 5));
|
ringBuffer.append(QByteArray("01234", 5));
|
||||||
|
|
||||||
ringBuffer.free(1);
|
ringBuffer.free(1);
|
||||||
QCOMPARE(ringBuffer.size(), 4095 + 2048 + 5);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(4095 + 2048 + 5));
|
||||||
ringBuffer.free(4096);
|
ringBuffer.free(4096);
|
||||||
QCOMPARE(ringBuffer.size(), 2047 + 5);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(2047 + 5));
|
||||||
ringBuffer.free(48);
|
ringBuffer.free(48);
|
||||||
ringBuffer.free(2000);
|
ringBuffer.free(2000);
|
||||||
QCOMPARE(ringBuffer.size(), 4);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(4));
|
||||||
QVERIFY(memcmp(ringBuffer.readPointer(), "1234", 4) == 0);
|
QVERIFY(memcmp(ringBuffer.readPointer(), "1234", 4) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,8 +211,8 @@ void tst_QRingBuffer::reserveAndRead()
|
|||||||
for (int i = 1; i < 256; ++i) {
|
for (int i = 1; i < 256; ++i) {
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
ba.resize(i);
|
ba.resize(i);
|
||||||
int thisRead = ringBuffer.read(ba.data(), i);
|
qint64 thisRead = ringBuffer.read(ba.data(), i);
|
||||||
QCOMPARE(thisRead, i);
|
QCOMPARE(thisRead, qint64(i));
|
||||||
QVERIFY(ba.count(char(i)) == i);
|
QVERIFY(ba.count(char(i)) == i);
|
||||||
}
|
}
|
||||||
QVERIFY(ringBuffer.size() == 0);
|
QVERIFY(ringBuffer.size() == 0);
|
||||||
@ -227,12 +227,12 @@ void tst_QRingBuffer::chop()
|
|||||||
ringBuffer.reserve(4096);
|
ringBuffer.reserve(4096);
|
||||||
|
|
||||||
ringBuffer.chop(1);
|
ringBuffer.chop(1);
|
||||||
QCOMPARE(ringBuffer.size(), 5 + 2048 + 4095);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2048 + 4095));
|
||||||
ringBuffer.chop(4096);
|
ringBuffer.chop(4096);
|
||||||
QCOMPARE(ringBuffer.size(), 5 + 2047);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(5 + 2047));
|
||||||
ringBuffer.chop(48);
|
ringBuffer.chop(48);
|
||||||
ringBuffer.chop(2000);
|
ringBuffer.chop(2000);
|
||||||
QCOMPARE(ringBuffer.size(), 4);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(4));
|
||||||
QVERIFY(memcmp(ringBuffer.readPointer(), "0123", 4) == 0);
|
QVERIFY(memcmp(ringBuffer.readPointer(), "0123", 4) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ void tst_QRingBuffer::ungetChar()
|
|||||||
ringBuffer.getChar();
|
ringBuffer.getChar();
|
||||||
ringBuffer.ungetChar(char(c)); // unget first char
|
ringBuffer.ungetChar(char(c)); // unget first char
|
||||||
}
|
}
|
||||||
QCOMPARE(ringBuffer.size(), 1);
|
QCOMPARE(ringBuffer.size(), Q_INT64_C(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRingBuffer::indexOf()
|
void tst_QRingBuffer::indexOf()
|
||||||
@ -258,8 +258,8 @@ void tst_QRingBuffer::indexOf()
|
|||||||
ringBuffer.putChar(char(i));
|
ringBuffer.putChar(char(i));
|
||||||
|
|
||||||
for (int i = 1; i < 256; ++i) {
|
for (int i = 1; i < 256; ++i) {
|
||||||
int index = ringBuffer.indexOf(char(i));
|
qint64 index = ringBuffer.indexOf(char(i));
|
||||||
QCOMPARE(i - 1, index);
|
QCOMPARE(qint64(i - 1), index);
|
||||||
QCOMPARE(index, ringBuffer.indexOf(char(i), i));
|
QCOMPARE(index, ringBuffer.indexOf(char(i), i));
|
||||||
QVERIFY(ringBuffer.indexOf(char(i), i - 1) == -1); // test for absent char
|
QVERIFY(ringBuffer.indexOf(char(i), i - 1) == -1); // test for absent char
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ void tst_QRingBuffer::readLine()
|
|||||||
|
|
||||||
// check first empty string reading
|
// check first empty string reading
|
||||||
stringBuf[0] = char(0xFF);
|
stringBuf[0] = char(0xFF);
|
||||||
QCOMPARE(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2), ba2.size());
|
QCOMPARE(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2), qint64(ba2.size()));
|
||||||
QVERIFY(stringBuf[0] == ba2[0]);
|
QVERIFY(stringBuf[0] == ba2[0]);
|
||||||
|
|
||||||
QVERIFY(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2) == (ba3.size() + ba4.size()
|
QVERIFY(ringBuffer.readLine(stringBuf, int(sizeof(stringBuf)) - 2) == (ba3.size() + ba4.size()
|
||||||
|
@ -48,10 +48,10 @@ void tst_qringbuffer::reserveAndRead()
|
|||||||
{
|
{
|
||||||
QRingBuffer ringBuffer;
|
QRingBuffer ringBuffer;
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
for (int i = 1; i < 256; ++i)
|
for (qint64 i = 1; i < 256; ++i)
|
||||||
ringBuffer.reserve(i);
|
ringBuffer.reserve(i);
|
||||||
|
|
||||||
for (int i = 1; i < 256; ++i)
|
for (qint64 i = 1; i < 256; ++i)
|
||||||
ringBuffer.read(0, i);
|
ringBuffer.read(0, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user