mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-13 09:10:45 +00:00
Fix boundary condition bugs in RawDataDevice.
bytesAvailable gets automatically calculated by QIODevice, so it doesn't need to be reimplemented. QIODevice doesn't necessarily buffer after a seek, and the underlying device is unaware of peek/ungetChar, so canReadLine needs to check both QIODevice and the device.
This commit is contained in:
parent
0737ad9b10
commit
c64376033d
@ -138,14 +138,9 @@ bool RawDataDevice::isSequential() const
|
|||||||
return is_sequential;
|
return is_sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 RawDataDevice::bytesAvailable() const
|
|
||||||
{
|
|
||||||
return m_device.bytesAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RawDataDevice::canReadLine() const
|
bool RawDataDevice::canReadLine() const
|
||||||
{
|
{
|
||||||
return m_device.canReadLine();
|
return m_device.canReadLine() || QIODevice::canReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 RawDataDevice::size() const
|
qint64 RawDataDevice::size() const
|
||||||
|
@ -30,8 +30,6 @@ class RawDataDevice : public QIODevice
|
|||||||
virtual qint64 size() const;
|
virtual qint64 size() const;
|
||||||
virtual bool seek(qint64 pos);
|
virtual bool seek(qint64 pos);
|
||||||
|
|
||||||
virtual qint64 bytesAvailable() const;
|
|
||||||
|
|
||||||
virtual bool canReadLine() const;
|
virtual bool canReadLine() const;
|
||||||
|
|
||||||
virtual bool waitForReadyRead(int msecs);
|
virtual bool waitForReadyRead(int msecs);
|
||||||
|
@ -95,12 +95,24 @@ void RawDataTests::testQIODeviceInterface()
|
|||||||
Q_ASSERT(ch == data[0]);
|
Q_ASSERT(ch == data[0]);
|
||||||
|
|
||||||
Q_ASSERT(raw.size() == qio.size());
|
Q_ASSERT(raw.size() == qio.size());
|
||||||
Q_ASSERT(raw.atEnd() == qio.atEnd());
|
|
||||||
Q_ASSERT(raw.bytesAvailable() == qio.bytesAvailable());
|
|
||||||
|
|
||||||
Q_ASSERT(raw.seek(16) == true);
|
Q_ASSERT(raw.seek(16) == true);
|
||||||
Q_ASSERT(raw.pos() == 16);
|
Q_ASSERT(raw.pos() == 16);
|
||||||
Q_ASSERT(raw.pos() == qio.pos());
|
Q_ASSERT(raw.pos() == qio.pos());
|
||||||
|
Q_ASSERT(raw.atEnd() == qio.atEnd());
|
||||||
|
|
||||||
|
|
||||||
|
// Check boundary conditions at end of device.
|
||||||
|
Q_ASSERT(raw.seek(255) == true);
|
||||||
|
Q_ASSERT(raw.getChar(&ch) == true);
|
||||||
|
Q_ASSERT(raw.pos() == qio.pos());
|
||||||
|
Q_ASSERT(raw.atEnd() == true);
|
||||||
|
Q_ASSERT(raw.atEnd() == qio.atEnd());
|
||||||
|
Q_ASSERT(raw.bytesAvailable() == qio.bytesAvailable());
|
||||||
|
raw.ungetChar(ch);
|
||||||
|
Q_ASSERT(raw.atEnd() == false);
|
||||||
|
Q_ASSERT(raw.atEnd() != qio.atEnd());
|
||||||
|
Q_ASSERT(raw.bytesAvailable() == qio.bytesAvailable() + 1);
|
||||||
|
|
||||||
Q_ASSERT(raw.reset() == true);
|
Q_ASSERT(raw.reset() == true);
|
||||||
Q_ASSERT(raw.pos() == 0);
|
Q_ASSERT(raw.pos() == 0);
|
||||||
@ -111,6 +123,20 @@ void RawDataTests::testQIODeviceInterface()
|
|||||||
Q_ASSERT(raw.bytesAvailable() == qio.bytesAvailable());
|
Q_ASSERT(raw.bytesAvailable() == qio.bytesAvailable());
|
||||||
|
|
||||||
|
|
||||||
|
// canReadLine
|
||||||
|
Q_ASSERT(raw.canReadLine() == qio.canReadLine());
|
||||||
|
raw.seek(255 - 0x0A);
|
||||||
|
Q_ASSERT(raw.canReadLine() == true);
|
||||||
|
Q_ASSERT(raw.canReadLine() == qio.canReadLine());
|
||||||
|
Q_ASSERT(raw.getChar(&ch) == true);
|
||||||
|
Q_ASSERT(ch == 0x0A);
|
||||||
|
Q_ASSERT(raw.canReadLine() == false);
|
||||||
|
Q_ASSERT(raw.canReadLine() == qio.canReadLine());
|
||||||
|
raw.ungetChar(ch);
|
||||||
|
Q_ASSERT(raw.canReadLine() == true);
|
||||||
|
Q_ASSERT(raw.canReadLine() != qio.canReadLine());
|
||||||
|
|
||||||
|
|
||||||
// readLine x2
|
// readLine x2
|
||||||
Q_ASSERT(raw.reset() == true);
|
Q_ASSERT(raw.reset() == true);
|
||||||
Q_ASSERT(raw.canReadLine() == qio.canReadLine());
|
Q_ASSERT(raw.canReadLine() == qio.canReadLine());
|
||||||
|
Loading…
Reference in New Issue
Block a user