summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-12-30 13:38:05 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-01-16 10:00:38 +0100
commit601f43c5b60743f9fb12a3ff3ef0715d51777baa (patch)
tree7de9b7de7b07369e3e18a977f758a6e16e3b235c /tests
parent203e0ec5292589592ab7819beaf246a33a218c9f (diff)
downloadqtserialport-601f43c5b60743f9fb12a3ff3ef0715d51777baa.tar.gz
Improve usage of the break state for the Tx line
1. Now the sendBreak() method is deprecated since it is blocking and impossible to implement same behavior on different platforms using their API's. Besides, this method can be implemented via setBreakEnabled() and QTimer. 2. Introduced the new property named as "breakEnabled" which consist of setBreakEnabled() and isBreakEnabled() methods and the signal breakEnabledChanged(). Note: After opening, the port always is in non-break state. Task-number: QTBUG-36571 Change-Id: Ib808dab7eaed8cc5449c66d8186a29a7b7e45afc Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qserialport/tst_qserialport.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp
index b05d7d0..0ebeb0a 100644
--- a/tests/auto/qserialport/tst_qserialport.cpp
+++ b/tests/auto/qserialport/tst_qserialport.cpp
@@ -112,6 +112,8 @@ private slots:
void readAfterInputClear();
#endif
+ void controlBreak();
+
protected slots:
void handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten);
void handleBytesWrittenAndExitLoopSlot2(qint64 bytesWritten);
@@ -750,5 +752,62 @@ void tst_QSerialPort::readAfterInputClear()
}
#endif
+class BreakReader : public QObject
+{
+ Q_OBJECT
+public:
+ explicit BreakReader(QSerialPort &port)
+ : serialPort(port)
+ {
+ connect(&serialPort, SIGNAL(readyRead()), this, SLOT(receive()));
+ }
+
+private slots:
+ void receive()
+ {
+ tst_QSerialPort::exitLoop();
+ }
+
+private:
+ QSerialPort &serialPort;
+};
+
+void tst_QSerialPort::controlBreak()
+{
+#ifdef Q_OS_WIN
+ clearReceiver();
+#endif
+
+ QSerialPort senderPort(m_senderPortName);
+ QVERIFY(senderPort.open(QSerialPort::WriteOnly));
+ QCOMPARE(senderPort.isBreakEnabled(), false);
+
+ QSignalSpy breakSpy(&senderPort, SIGNAL(breakEnabledChanged(bool)));
+ QVERIFY(breakSpy.isValid());
+
+ QSerialPort receiverPort(m_receiverPortName);
+ QVERIFY(receiverPort.open(QSerialPort::ReadOnly));
+
+ BreakReader reader(receiverPort);
+
+ QVERIFY(senderPort.setBreakEnabled(true));
+ QCOMPARE(senderPort.isBreakEnabled(), true);
+
+ enterLoop(1);
+ QVERIFY2(!timeout(), "Timed out when waiting for the read of break state.");
+ QVERIFY(receiverPort.bytesAvailable() > 0);
+
+ foreach (const char c, receiverPort.readAll()) {
+ QCOMPARE(c, char(0));
+ }
+
+ QVERIFY(senderPort.setBreakEnabled(false));
+ QCOMPARE(senderPort.isBreakEnabled(), false);
+
+ QCOMPARE(breakSpy.count(), 2);
+ QCOMPARE(qvariant_cast<bool>(breakSpy.at(0).at(0)), true);
+ QCOMPARE(qvariant_cast<bool>(breakSpy.at(1).at(0)), false);
+}
+
QTEST_MAIN(tst_QSerialPort)
#include "tst_qserialport.moc"