diff options
author | Andreas Buhr <andreas@andreasbuhr.de> | 2021-02-24 20:38:36 +0100 |
---|---|---|
committer | Andreas Buhr <andreas@andreasbuhr.de> | 2021-02-26 09:32:39 +0100 |
commit | 51c341ce5fd9682cd38f1a76ddc72d9e14144392 (patch) | |
tree | 3a4f791ac480439e9277385fa26d0b0df05aea19 /tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | |
parent | 4789deec2db226a41f60061666c1e5b36a16abd9 (diff) |
Change tst_qlowenergycontroller to wait for disconnects
Many occurrences in tst_qlowenergycontroller exist where
disconnectFromDevice() is called but the code did not wait for the
disconnect to happen. This patch changes this.
Change-Id: I1df4e68136b8a83640af1fc50298e559d983cc9a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
(cherry picked from commit 180f895023f136a694738667a73674968964bafc)
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Diffstat (limited to 'tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp')
-rw-r--r-- | tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index ab393210..bc74c693 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -148,6 +148,8 @@ void tst_QLowEnergyController::initTestCase() } #endif + // QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); + devAgent = new QBluetoothDeviceDiscoveryAgent(this); devAgent->setLowEnergyDiscoveryTimeout(5000); @@ -489,10 +491,12 @@ void tst_QLowEnergyController::tst_concurrentDiscovery() } else { QCOMPARE(control.state(), QLowEnergyController::ConnectedState); QCOMPARE(control2.state(), QLowEnergyController::ConnectedState); + QTRY_COMPARE(control2.error(), QLowEnergyController::NoError); control2.disconnectFromDevice(); QTRY_COMPARE(control2.state(), QLowEnergyController::UnconnectedState); QTRY_COMPARE(control2.error(), QLowEnergyController::NoError); QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QTRY_COMPARE(control.error(), QLowEnergyController::NoError); // reconnect control control.connectToDevice(); @@ -627,6 +631,8 @@ void tst_QLowEnergyController::tst_concurrentDiscovery() } control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); } void tst_QLowEnergyController::verifyServiceProperties( @@ -1738,7 +1744,7 @@ void tst_QLowEnergyController::tst_writeCharacteristic() QSKIP("Cannot connect to remote device"); } - QCOMPARE(control.state(), QLowEnergyController::ConnectedState); + QTRY_VERIFY_WITH_TIMEOUT(control.state() == QLowEnergyController::ConnectedState, 20000); QSignalSpy discoveryFinishedSpy(&control, SIGNAL(discoveryFinished())); QSignalSpy stateSpy(&control, SIGNAL(stateChanged(QLowEnergyController::ControllerState))); control.discoverServices(); @@ -1866,6 +1872,8 @@ void tst_QLowEnergyController::tst_writeCharacteristic() control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); // ******************************************* // write value while disconnected -> error errorSpy.clear(); @@ -1945,6 +1953,8 @@ void tst_QLowEnergyController::tst_readWriteDescriptor() if (!tempData.isValid()) { delete service; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); QSKIP("Cannot find temperature data characteristic of TI Sensor"); } @@ -1955,6 +1965,8 @@ void tst_QLowEnergyController::tst_readWriteDescriptor() if (!notification.isValid()) { delete service; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); QSKIP("Cannot find temperature data notification of TI Sensor"); } @@ -2131,6 +2143,8 @@ void tst_QLowEnergyController::tst_readWriteDescriptor() QCOMPARE(notification.value(), QByteArray::fromHex("0000")); control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); // ******************************************* // write value while disconnected -> error @@ -2319,6 +2333,8 @@ void tst_QLowEnergyController::tst_customProgrammableDevice() delete service; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); } @@ -2544,6 +2560,8 @@ void tst_QLowEnergyController::tst_errorCases() delete irService; delete oadService; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); } /* @@ -2576,7 +2594,7 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() QSKIP("Cannot connect to remote device"); } - QCOMPARE(control.state(), QLowEnergyController::ConnectedState); + QTRY_VERIFY_WITH_TIMEOUT(control.state() == QLowEnergyController::ConnectedState, 20000); QSignalSpy discoveryFinishedSpy(&control, SIGNAL(discoveryFinished())); QSignalSpy stateSpy(&control, SIGNAL(stateChanged(QLowEnergyController::ControllerState))); control.discoverServices(); @@ -2620,6 +2638,8 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() || !imageIdentityChar.isValid()) { delete service; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); QSKIP("Cannot find OAD char/notification"); } @@ -2829,6 +2849,8 @@ void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() delete service; control.disconnectFromDevice(); + QTRY_COMPARE(control.state(), QLowEnergyController::UnconnectedState); + QCOMPARE(control.error(), QLowEnergyController::NoError); } QTEST_MAIN(tst_QLowEnergyController) |