summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2016-06-30 09:32:39 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2016-06-30 15:10:18 +0000
commita713565d119c39bd31ec25926ded881d1f0b78b7 (patch)
tree9bcd50238ea6ecadf62abe797a339b1777095cfc /tests
parent9df15226d3e7cbf8e601432d706c199f6ec3d112 (diff)
downloadqtserialport-a713565d119c39bd31ec25926ded881d1f0b78b7.tar.gz
Add tests for RTS and DTR signals
Change-Id: I148339d731b77975ce56fa79a3ead485bbf02a87 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.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp
index 24c0134..33a48fe 100644
--- a/tests/auto/qserialport/tst_qserialport.cpp
+++ b/tests/auto/qserialport/tst_qserialport.cpp
@@ -96,6 +96,9 @@ private slots:
void flowControl_data();
void flowControl();
+ void rts();
+ void dtr();
+
void flush();
void doubleFlush();
@@ -149,6 +152,7 @@ const QByteArray tst_QSerialPort::newlineArray("\n\r");
tst_QSerialPort::tst_QSerialPort()
{
+ qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
}
void tst_QSerialPort::initTestCase()
@@ -468,6 +472,83 @@ void tst_QSerialPort::flowControl()
}
}
+void tst_QSerialPort::rts()
+{
+ QSerialPort serialPort(m_senderPortName);
+
+ QSignalSpy errorSpy(&serialPort, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error));
+ QVERIFY(errorSpy.isValid());
+ QSignalSpy rtsSpy(&serialPort, &QSerialPort::requestToSendChanged);
+ QVERIFY(rtsSpy.isValid());
+
+ QVERIFY(serialPort.open(QIODevice::ReadWrite));
+
+ // no flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::NoFlowControl));
+ const bool toggle1 = !serialPort.isRequestToSend();
+ QVERIFY(serialPort.setRequestToSend(toggle1));
+ QCOMPARE(serialPort.isRequestToSend(), toggle1);
+
+ // software flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::SoftwareControl));
+ const bool toggle2 = !serialPort.isRequestToSend();
+ QVERIFY(serialPort.setRequestToSend(toggle2));
+ QCOMPARE(serialPort.isRequestToSend(), toggle2);
+
+ // hardware flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::HardwareControl));
+ const bool toggle3 = !serialPort.isRequestToSend();
+ QVERIFY(!serialPort.setRequestToSend(toggle3)); // not allowed
+ QCOMPARE(serialPort.isRequestToSend(), !toggle3); // same as before
+ QCOMPARE(serialPort.error(), QSerialPort::UnsupportedOperationError);
+
+ QCOMPARE(errorSpy.count(), 2);
+ QCOMPARE(qvariant_cast<QSerialPort::SerialPortError>(errorSpy.at(0).at(0)), QSerialPort::NoError);
+ QCOMPARE(qvariant_cast<QSerialPort::SerialPortError>(errorSpy.at(1).at(0)), QSerialPort::UnsupportedOperationError);
+
+ QCOMPARE(rtsSpy.count(), 2);
+ QCOMPARE(qvariant_cast<bool>(rtsSpy.at(0).at(0)), toggle1);
+ QCOMPARE(qvariant_cast<bool>(rtsSpy.at(1).at(0)), toggle2);
+}
+
+void tst_QSerialPort::dtr()
+{
+ QSerialPort serialPort(m_senderPortName);
+
+ QSignalSpy errorSpy(&serialPort, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error));
+ QVERIFY(errorSpy.isValid());
+ QSignalSpy dtrSpy(&serialPort, &QSerialPort::dataTerminalReadyChanged);
+ QVERIFY(dtrSpy.isValid());
+
+ QVERIFY(serialPort.open(QIODevice::ReadWrite));
+
+ // no flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::NoFlowControl));
+ const bool toggle1 = !serialPort.isDataTerminalReady();
+ QVERIFY(serialPort.setDataTerminalReady(toggle1));
+ QCOMPARE(serialPort.isDataTerminalReady(), toggle1);
+
+ // software flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::SoftwareControl));
+ const bool toggle2 = !serialPort.isDataTerminalReady();
+ QVERIFY(serialPort.setDataTerminalReady(toggle2));
+ QCOMPARE(serialPort.isDataTerminalReady(), toggle2);
+
+ // hardware flow control
+ QVERIFY(serialPort.setFlowControl(QSerialPort::HardwareControl));
+ const bool toggle3 = !serialPort.isDataTerminalReady();
+ QVERIFY(serialPort.setDataTerminalReady(toggle3));
+ QCOMPARE(serialPort.isDataTerminalReady(), toggle3);
+
+ QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(qvariant_cast<QSerialPort::SerialPortError>(errorSpy.at(0).at(0)), QSerialPort::NoError);
+
+ QCOMPARE(dtrSpy.count(), 3);
+ QCOMPARE(qvariant_cast<bool>(dtrSpy.at(0).at(0)), toggle1);
+ QCOMPARE(qvariant_cast<bool>(dtrSpy.at(1).at(0)), toggle2);
+ QCOMPARE(qvariant_cast<bool>(dtrSpy.at(2).at(0)), toggle3);
+}
+
void tst_QSerialPort::handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten)
{
QCOMPARE(bytesWritten, qint64(alphabetArray.size() + newlineArray.size()));