From 13caa7c6c585545f5eeec9d529c675d8dc2ef0fa Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Wed, 16 Apr 2014 16:30:15 +0400 Subject: Add test for the waitForBytesWritten() method Change-Id: I4a6767196d205cf1f0715edfb9ea117a2d7fa5c9 Reviewed-by: Sergey Belyashov Reviewed-by: Denis Shienkov --- tests/auto/qserialport/tst_qserialport.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 245c7f2..96d3788 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -86,6 +86,8 @@ private slots: void flush(); void doubleFlush(); + void waitForBytesWritten(); + protected slots: void handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten); void handleBytesWrittenAndExitLoopSlot2(qint64 bytesWritten); @@ -319,5 +321,19 @@ void tst_QSerialPort::doubleFlush() QCOMPARE(bytesWrittenSpy.count(), 2); } +void tst_QSerialPort::waitForBytesWritten() +{ + // the dummy device on other side also has to be open + QSerialPort dummySerialPort(m_receiverPortName); + QVERIFY(dummySerialPort.open(QIODevice::ReadOnly)); + + QSerialPort serialPort(m_senderPortName); + QVERIFY(serialPort.open(QIODevice::WriteOnly)); + serialPort.write(alphabetArray); + const qint64 toWrite = serialPort.bytesToWrite(); + QVERIFY(serialPort.waitForBytesWritten(1000)); + QVERIFY(toWrite > serialPort.bytesToWrite()); +} + QTEST_MAIN(tst_QSerialPort) #include "tst_qserialport.moc" -- cgit v1.2.1