From b1005907d26a3e2f5dffaec93d656a0c1210961f Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Tue, 30 Dec 2014 13:38:05 +0300 Subject: 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: Sergey Belyashov Reviewed-by: Denis Shienkov --- tests/auto/qserialport/tst_qserialport.cpp | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'tests') diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index 357cef8..24f6224 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); @@ -736,5 +738,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(breakSpy.at(0).at(0)), true); + QCOMPARE(qvariant_cast(breakSpy.at(1).at(0)), false); +} + QTEST_MAIN(tst_QSerialPort) #include "tst_qserialport.moc" -- cgit v1.2.1