summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-09-05 12:43:05 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-09-07 13:06:40 +0000
commit3abd3ed07d2b30ecb2f8b9772ed5b3811bb9194b (patch)
tree48b84bfa7f3cebf5707e58a94d2b8f03773d7fd7 /tests
parent45bf94455c065b64dec65f354e62999b1c16cc7e (diff)
downloadqtserialport-3abd3ed07d2b30ecb2f8b9772ed5b3811bb9194b.tar.gz
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 <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qserialport/tst_qserialport.cpp33
1 files changed, 33 insertions, 0 deletions
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<int>("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"