From 3abd3ed07d2b30ecb2f8b9772ed5b3811bb9194b Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sat, 5 Sep 2015 12:43:05 +0300 Subject: Refactor the speed configuration for *nix The internal implementation of this is a little tangled. It is reasonable to simplify it: 1. Remove the setBaudRate_helper() method, as it is equivalent to setStandardBaudRate() method. 2. Now the setStandardBaudRate() and the setCustomBaudRate() are self-sufficient methods (can setup a speed and an error codes internally) and return a boolean values. Also added the "loopback" test for check of different speeds. Tested with the on-board and the USB serial ports. Change-Id: I4320c2e29ad42a394e07753cbaea804d0faf6b78 Reviewed-by: Sergey Belyashov Reviewed-by: Denis Shienkov --- tests/auto/qserialport/tst_qserialport.cpp | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 947047a..22f3b65 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -112,6 +112,9 @@ private slots: void clearAfterOpen(); + void loopBack_data(); + void loopBack(); + protected slots: void handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten); void handleBytesWrittenAndExitLoopSlot2(qint64 bytesWritten); @@ -916,5 +919,35 @@ void tst_QSerialPort::clearAfterOpen() QCOMPARE(senderPort.error(), QSerialPort::NoError); } +void tst_QSerialPort::loopBack_data() +{ + QTest::addColumn("baudRate"); + + QTest::newRow("9600 N 1 None") << 9600; + QTest::newRow("115200 N 1 None") << 115200; + QTest::newRow("14400 N 1 None") << 14400; +} + +// This test works with the connected Rx and Tx pins. +void tst_QSerialPort::loopBack() +{ + QFETCH(int, baudRate); + + QSerialPort serialPort(m_senderPortName); + QVERIFY(serialPort.open(QSerialPort::ReadWrite)); + + QVERIFY(serialPort.setBaudRate(baudRate)); + QCOMPARE(serialPort.baudRate(), baudRate); + + QCOMPARE(serialPort.write(alphabetArray), qint64(alphabetArray.size())); + QVERIFY(serialPort.waitForBytesWritten(500)); + + do { + QVERIFY(serialPort.waitForReadyRead(500)); + } while (serialPort.bytesAvailable() < alphabetArray.size()); + + QCOMPARE(serialPort.readAll(), alphabetArray); +} + QTEST_MAIN(tst_QSerialPort) #include "tst_qserialport.moc" -- cgit v1.2.1