summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Buhr <andreas@andreasbuhr.de>2021-02-24 20:38:36 +0100
committerAndreas Buhr <andreas@andreasbuhr.de>2021-02-26 09:32:39 +0100
commit51c341ce5fd9682cd38f1a76ddc72d9e14144392 (patch)
tree3a4f791ac480439e9277385fa26d0b0df05aea19
parent4789deec2db226a41f60061666c1e5b36a16abd9 (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>
-rw-r--r--src/bluetooth/qlowenergycontroller_bluezdbus.cpp5
-rw-r--r--src/bluetooth/qlowenergycontrollerbase.cpp1
-rw-r--r--tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp26
3 files changed, 30 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
index 8720c549..9849e3f8 100644
--- a/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
@@ -60,6 +60,9 @@ QLowEnergyControllerPrivateBluezDBus::QLowEnergyControllerPrivateBluezDBus()
QLowEnergyControllerPrivateBluezDBus::~QLowEnergyControllerPrivateBluezDBus()
{
+ if (state != QLowEnergyController::UnconnectedState) {
+ qCWarning(QT_BT_BLUEZ) << "Low Energy Controller deleted while connected.";
+ }
}
void QLowEnergyControllerPrivateBluezDBus::init()
@@ -390,6 +393,8 @@ void QLowEnergyControllerPrivateBluezDBus::disconnectFromDevice()
qCDebug(QT_BT_BLUEZ) << "BTLE_DBUS::disconnect() failed"
<< reply.reply().errorName()
<< reply.reply().errorMessage();
+ executeClose(QLowEnergyController::UnknownError);
+ } else {
executeClose(QLowEnergyController::NoError);
}
call->deleteLater();
diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp
index 841de3e3..07c3b44b 100644
--- a/src/bluetooth/qlowenergycontrollerbase.cpp
+++ b/src/bluetooth/qlowenergycontrollerbase.cpp
@@ -123,6 +123,7 @@ void QLowEnergyControllerPrivate::setError(
void QLowEnergyControllerPrivate::setState(
QLowEnergyController::ControllerState newState)
{
+ qCDebug(QT_BT) << "QLowEnergyControllerPrivate setting state to" << newState;
Q_Q(QLowEnergyController);
if (state == newState)
return;
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)