summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-09-08 11:57:06 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-09-08 17:26:57 +0000
commite07a665edef5a238e3f1b948bc3f5e3e244f2ab2 (patch)
tree1e56ed14d537f564204ff9405ae09d7bf92a6483 /tests
parentdb27ac4672a0aa28abec2a301758ee14c385f350 (diff)
downloadqtserialport-e07a665edef5a238e3f1b948bc3f5e3e244f2ab2.tar.gz
Refactor functionality of the loopBack test
Testing of a single port with connected Tx and Rx pins doesn't make sense since: * It is necessary existence of a real physical port. * It is impossible to set different speed for transmission and reception (in common case). Now the new test is deprived of these problems, it can reveal real mismatch of speeds. Change-Id: I1c60a373b60198d9aa9cefc329c0817981232de8 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.cpp82
1 files changed, 59 insertions, 23 deletions
diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp
index 469586b..1a2813d 100644
--- a/tests/auto/qserialport/tst_qserialport.cpp
+++ b/tests/auto/qserialport/tst_qserialport.cpp
@@ -128,8 +128,8 @@ private slots:
void clearAfterOpen();
- void loopBack_data();
- void loopBack();
+ void readWriteWithDifferentBaudRate_data();
+ void readWriteWithDifferentBaudRate();
protected slots:
void handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten);
@@ -1090,34 +1090,70 @@ void tst_QSerialPort::clearAfterOpen()
QCOMPARE(senderPort.error(), QSerialPort::NoError);
}
-void tst_QSerialPort::loopBack_data()
+void tst_QSerialPort::readWriteWithDifferentBaudRate_data()
{
- QTest::addColumn<int>("baudRate");
+ QTest::addColumn<int>("senderBaudRate");
+ QTest::addColumn<int>("receiverBaudRate");
+ QTest::addColumn<bool>("expectedResult");
- QTest::newRow("9600 N 1 None") << 9600;
- QTest::newRow("115200 N 1 None") << 115200;
- QTest::newRow("14400 N 1 None") << 14400;
+ QTest::newRow("9600, 9600") << 9600 << 9600 << true;
+ QTest::newRow("115200, 115200") << 115200 << 115200 << true;
+ QTest::newRow("9600, 115200") << 9600 << 115200 << false;
}
-// This test works with the connected Rx and Tx pins.
-void tst_QSerialPort::loopBack()
+void tst_QSerialPort::readWriteWithDifferentBaudRate()
{
- QFETCH(int, baudRate);
+ QFETCH(int, senderBaudRate);
+ QFETCH(int, receiverBaudRate);
+ QFETCH(bool, expectedResult);
- 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());
+ {
+ // setup before opening
+ QSerialPort senderSerialPort(m_senderPortName);
+ QVERIFY(senderSerialPort.setBaudRate(senderBaudRate));
+ QCOMPARE(senderSerialPort.baudRate(), senderBaudRate);
+ QVERIFY(senderSerialPort.open(QSerialPort::ReadWrite));
+ QSerialPort receiverSerialPort(m_receiverPortName);
+ QVERIFY(receiverSerialPort.setBaudRate(receiverBaudRate));
+ QCOMPARE(receiverSerialPort.baudRate(), receiverBaudRate);
+ QVERIFY(receiverSerialPort.open(QSerialPort::ReadWrite));
+
+ QCOMPARE(senderSerialPort.write(alphabetArray), qint64(alphabetArray.size()));
+ QVERIFY(senderSerialPort.waitForBytesWritten(500));
+
+ do {
+ QVERIFY(receiverSerialPort.waitForReadyRead(500));
+ } while (receiverSerialPort.bytesAvailable() < alphabetArray.size());
+
+ if (expectedResult)
+ QVERIFY(receiverSerialPort.readAll() == alphabetArray);
+ else
+ QVERIFY(receiverSerialPort.readAll() != alphabetArray);
+ }
- QCOMPARE(serialPort.readAll(), alphabetArray);
+ {
+ // setup after opening
+ QSerialPort senderSerialPort(m_senderPortName);
+ QVERIFY(senderSerialPort.open(QSerialPort::ReadWrite));
+ QVERIFY(senderSerialPort.setBaudRate(senderBaudRate));
+ QCOMPARE(senderSerialPort.baudRate(), senderBaudRate);
+ QSerialPort receiverSerialPort(m_receiverPortName);
+ QVERIFY(receiverSerialPort.open(QSerialPort::ReadWrite));
+ QVERIFY(receiverSerialPort.setBaudRate(receiverBaudRate));
+ QCOMPARE(receiverSerialPort.baudRate(), receiverBaudRate);
+
+ QCOMPARE(senderSerialPort.write(alphabetArray), qint64(alphabetArray.size()));
+ QVERIFY(senderSerialPort.waitForBytesWritten(500));
+
+ do {
+ QVERIFY(receiverSerialPort.waitForReadyRead(500));
+ } while (receiverSerialPort.bytesAvailable() < alphabetArray.size());
+
+ if (expectedResult)
+ QVERIFY(receiverSerialPort.readAll() == alphabetArray);
+ else
+ QVERIFY(receiverSerialPort.readAll() != alphabetArray);
+ }
}
QTEST_MAIN(tst_QSerialPort)