summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-04-29 18:23:36 +0200
committerIvan Solovev <ivan.solovev@qt.io>2022-05-12 09:39:47 +0200
commit999236015967641a6a53bd0633a4bb9b798bb95f (patch)
treed7251918c789ffb816352dcf4476351b78c9554a /tests
parente1822d61d5be5c9d35872a7994d1d0b9da0767bd (diff)
downloadqtconnectivity-999236015967641a6a53bd0633a4bb9b798bb95f.tar.gz
Windows: implement the missing APIs for QBluetoothLocalDevice
[ChangeLog][QBluetoothLocalDevice][Windows] Add support for correctly emitting deviceConnected() and deviceDisconnected() signals, as well as return a valid list of connectedDevices(). The implementation has one assumption - it considers that Windows always has only one local adapter available. This is correct for now, and is unlikely to change, but we need to keep it in mind. Fixes: QTBUG-98942 Change-Id: If7c5ce2237a60754965f485d8fe54159f071a3f0 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp
index c042f60b..7e63007f 100644
--- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp
+++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp
@@ -67,6 +67,7 @@ private slots:
void tst_pairingStatus();
void tst_pairDevice_data();
void tst_pairDevice();
+ void tst_connectedDevices();
private:
QBluetoothAddress remoteDevice;
@@ -429,6 +430,61 @@ void tst_QBluetoothLocalDevice::tst_pairDevice()
}
}
+void tst_QBluetoothLocalDevice::tst_connectedDevices()
+{
+#if defined(Q_OS_MACOS)
+ QSKIP("The connectedDevices test fails on macOS");
+#endif
+ if (numDevices == 0)
+ QSKIP("Skipping test due to missing Bluetooth device");
+ if (remoteDevice.isNull())
+ QSKIP("This test only makes sense with remote device");
+
+ QBluetoothLocalDevice localDevice;
+ // powerOn if not already
+ if (localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff) {
+ localDevice.powerOn();
+ QTRY_VERIFY(localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff);
+ }
+
+ QSignalSpy pairingSpy(&localDevice, &QBluetoothLocalDevice::pairingFinished);
+
+ // Make sure that the remote device is not paired
+ localDevice.requestPairing(remoteDevice, QBluetoothLocalDevice::Unpaired);
+ QTRY_VERIFY(!pairingSpy.isEmpty());
+
+ QList<QBluetoothAddress> connectedDevices = localDevice.connectedDevices();
+ QVERIFY(!connectedDevices.contains(remoteDevice));
+
+ QSignalSpy deviceConnectedSpy(&localDevice, &QBluetoothLocalDevice::deviceConnected);
+ QSignalSpy deviceDisconnectedSpy(&localDevice, &QBluetoothLocalDevice::deviceDisconnected);
+
+ // Now pair with the device. We should have a deviceConnected signal.
+ pairingSpy.clear();
+ localDevice.requestPairing(remoteDevice, QBluetoothLocalDevice::Paired);
+ // Manual confirmation for pairing might be required
+ QTRY_VERIFY_WITH_TIMEOUT(!pairingSpy.isEmpty(), 30000);
+ QTRY_VERIFY(!deviceConnectedSpy.isEmpty());
+ QList<QVariant> arguments = deviceConnectedSpy.takeFirst();
+ auto address = arguments.at(0).value<QBluetoothAddress>();
+ QCOMPARE(address, remoteDevice);
+
+ connectedDevices = localDevice.connectedDevices();
+ QVERIFY(connectedDevices.contains(remoteDevice));
+
+ // Unpair again. We should have a deviceDisconnected signal.
+ pairingSpy.clear();
+ localDevice.requestPairing(remoteDevice, QBluetoothLocalDevice::Unpaired);
+ QTRY_VERIFY(!pairingSpy.isEmpty());
+ QTRY_VERIFY(!deviceDisconnectedSpy.isEmpty());
+ arguments = deviceDisconnectedSpy.takeFirst();
+ address = arguments.at(0).value<QBluetoothAddress>();
+ QCOMPARE(address, remoteDevice);
+
+ connectedDevices = localDevice.connectedDevices();
+ QVERIFY(!connectedDevices.contains(remoteDevice));
+}
+
void tst_QBluetoothLocalDevice::tst_pairingStatus_data()
{
QTest::addColumn<QBluetoothAddress>("deviceAddress");