diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-02-21 13:59:18 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-22 15:35:52 +0000 |
commit | 1834a38279d2d20c068ee4553d340157be3adef7 (patch) | |
tree | d5116ec3d607ff16cc34c4a63cabaf83dc8f8c1e | |
parent | b63072988b158588921c29ca0dabe99edb8b4776 (diff) | |
download | qtconnectivity-1834a38279d2d20c068ee4553d340157be3adef7.tar.gz |
Align the bluez dbus socket error codes with other platforms
The qbluetoothsocket::connectToService methods generally
speaking fail with "UnsupportedProtocolError" if the provided data
for the methods are not correct. In some cases the bluez dbus socket
implementation fails with "OperationError" error code causing the
tst_qbluetoothsocket::tst_unsupportedProtocolError autotest to fail.
This commit adjusts these error codes to be aligned with other
platforms. The one exception is the connectToService overload which
takes a port number as a parameter; there the bluez dbus socket error
code can be considered to differ because it does not support it.
Android backend doesn't support it either and provides also the
(same) differing error code. That test is skipped on Android
due to other reasons and doesn't need its own #ifdeffery.
Fixes: QTBUG-101071
Change-Id: Id07c3a27f8bda6cb75fda7b45854943a9800bce0
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit a73e02ebc90971ecc359ff22d8884fe8efbebbed)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp index 58510036..3e74a55c 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp +++ b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp @@ -280,7 +280,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService( qCWarning(QT_BT_BLUEZ) << "Cannot find appropriate serviceUuid" << "or SerialPort service class uuid"; errorString = QBluetoothSocket::tr("Missing serviceUuid or Serial Port service class uuid"); - q->setSocketError(QBluetoothSocket::SocketError::OperationError); + q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError); return; } @@ -299,7 +299,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService( if (address.isNull()) { qCWarning(QT_BT_BLUEZ) << "Invalid address to remote address passed."; errorString = QBluetoothSocket::tr("Invalid Bluetooth address passed to connectToService()"); - q->setSocketError(QBluetoothSocket::SocketError::OperationError); + q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError); return; } @@ -307,7 +307,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService( qCWarning(QT_BT_BLUEZ) << "Cannot find appropriate serviceUuid" << "or SerialPort service class uuid"; errorString = QBluetoothSocket::tr("Missing serviceUuid or Serial Port service class uuid"); - q->setSocketError(QBluetoothSocket::SocketError::OperationError); + q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError); return; } diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp index 75dd814a..653dde4a 100644 --- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp +++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp @@ -561,7 +561,18 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError() socket.connectToService(QBluetoothAddress(), 1, QIODevice::ReadWrite); QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000); QCOMPARE(errorSpy.size(), 1); +#if QT_CONFIG(bluez) + // Bluez dbus socket does not support connecting to port and gives different error code + if (bluetoothdVersion() >= QVersionNumber(5, 42)) { + QCOMPARE(errorSpy.takeFirst().at(0).toInt(), + int(QBluetoothSocket::SocketError::ServiceNotFoundError)); + } else { + QCOMPARE(errorSpy.takeFirst().at(0).toInt(), + int(QBluetoothSocket::SocketError::UnsupportedProtocolError)); + } +#else QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError)); +#endif QVERIFY(socket.errorString().size() != 0); QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); |