summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-10-01 15:53:09 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-10-01 13:20:36 +0000
commit23c89518d1404a4db570fe41f3cc04451703e16f (patch)
treed5b8c0bc5543f5a9683f46f416c8cd90e342bfb2 /tests
parenta1655d6ccf3f82508286b471819cc5e5cb64ff44 (diff)
downloadqtserialport-23c89518d1404a4db570fe41f3cc04451703e16f.tar.gz
Fix stalling of reading with the limited buffer size on *nix
When the read buffer with a limited size is used, the read notifier becomes disabled when the buffer completely is filled. The notifier should be enabled again when several bytes were read from the read buffer. Change-Id: I723253fb153a1144009579141fa0ce1aca93b648 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qserialport/tst_qserialport.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp
index d50afe9..3a62bfa 100644
--- a/tests/auto/qserialport/tst_qserialport.cpp
+++ b/tests/auto/qserialport/tst_qserialport.cpp
@@ -120,6 +120,8 @@ private slots:
void asynchronousWriteByTimer_data();
void asynchronousWriteByTimer();
+ void asyncReadWithLimitedReadBufferSize();
+
void readBufferOverflow();
void readAfterInputClear();
void synchronousReadWriteAfterAsynchronousReadWrite();
@@ -808,6 +810,49 @@ void tst_QSerialPort::asynchronousWriteByTimer()
QCOMPARE(receiverPort.readAll(), alphabetArray);
}
+class AsyncReader2 : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AsyncReader2(QSerialPort &port, const QByteArray &expectedData)
+ : serialPort(port), expectedData(expectedData)
+ {
+ connect(&serialPort, &QSerialPort::readyRead, this, &AsyncReader2::receive);
+ }
+
+private slots:
+ void receive()
+ {
+ receivedData.append(serialPort.readAll());
+ if (receivedData == expectedData)
+ tst_QSerialPort::exitLoop();
+ }
+
+private:
+ QSerialPort &serialPort;
+ const QByteArray expectedData;
+ QByteArray receivedData;
+};
+
+void tst_QSerialPort::asyncReadWithLimitedReadBufferSize()
+{
+ QSerialPort senderPort(m_senderPortName);
+ QVERIFY(senderPort.open(QSerialPort::WriteOnly));
+
+ QSerialPort receiverPort(m_receiverPortName);
+ QVERIFY(receiverPort.open(QSerialPort::ReadOnly));
+
+ receiverPort.setReadBufferSize(1);
+ QCOMPARE(receiverPort.readBufferSize(), qint64(1));
+
+ AsyncReader2 reader(receiverPort, alphabetArray);
+
+ QCOMPARE(senderPort.write(alphabetArray), qint64(alphabetArray.size()));
+
+ enterLoop(1);
+ QVERIFY2(!timeout(), "Timed out when waiting for the read or write.");
+}
+
void tst_QSerialPort::readBufferOverflow()
{
QSerialPort senderPort(m_senderPortName);