diff options
Diffstat (limited to 'tests/auto/qbluetoothsocket')
-rw-r--r-- | tests/auto/qbluetoothsocket/CMakeLists.txt | 39 | ||||
-rw-r--r-- | tests/auto/qbluetoothsocket/qbluetoothsocket.pro | 16 | ||||
-rw-r--r-- | tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp | 200 |
3 files changed, 140 insertions, 115 deletions
diff --git a/tests/auto/qbluetoothsocket/CMakeLists.txt b/tests/auto/qbluetoothsocket/CMakeLists.txt new file mode 100644 index 00000000..59b6a8f2 --- /dev/null +++ b/tests/auto/qbluetoothsocket/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qbluetoothsocket Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qbluetoothsocket LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qbluetoothsocket + SOURCES + tst_qbluetoothsocket.cpp + LIBRARIES + Qt::BluetoothPrivate + Qt::Network +) + +#### Keys ignored in scope 1:.:.:qbluetoothsocket.pro:<TRUE>: +# OTHER_FILES = "README.txt" +# testcase.timeout = "250" + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_qbluetoothsocket CONDITION MACOS + DEFINES + QT_OSX_BLUETOOTH + LIBRARIES + Qt::Widgets +) + +qt_internal_extend_target(tst_qbluetoothsocket CONDITION ANDROID AND NOT ANDROID_EMBEDDED + DEFINES + QT_ANDROID_BLUETOOTH +) diff --git a/tests/auto/qbluetoothsocket/qbluetoothsocket.pro b/tests/auto/qbluetoothsocket/qbluetoothsocket.pro deleted file mode 100644 index 83bc417c..00000000 --- a/tests/auto/qbluetoothsocket/qbluetoothsocket.pro +++ /dev/null @@ -1,16 +0,0 @@ -SOURCES += tst_qbluetoothsocket.cpp -TARGET = tst_qbluetoothsocket -CONFIG += testcase -testcase.timeout = 250 # this test is slow - -QT = core concurrent network bluetooth-private testlib -osx:QT += widgets - -OTHER_FILES += \ - README.txt - -osx { - DEFINES += QT_OSX_BLUETOOTH -} else:android:!android-embedded { - DEFINES += QT_ANDROID_BLUETOOTH -} diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp index 05bc1a0f..d88e64e7 100644 --- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp +++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtBluetooth module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> @@ -35,6 +10,9 @@ #include <qbluetoothserviceinfo.h> #include <qbluetoothservicediscoveryagent.h> #include <qbluetoothlocaldevice.h> +#if QT_CONFIG(bluez) +#include <QtBluetooth/private/bluez5_helper_p.h> +#endif QT_USE_NAMESPACE @@ -115,7 +93,7 @@ void tst_QBluetoothSocket::initTestCase() { // setup Bluetooth env const QList<QBluetoothHostInfo> foundDevices = QBluetoothLocalDevice::allDevices(); - if (!foundDevices.count()) { + if (foundDevices.isEmpty()) { qWarning() << "Missing local device"; return; } else { @@ -136,13 +114,14 @@ void tst_QBluetoothSocket::initTestCase() // Go find the server QBluetoothServiceDiscoveryAgent *sda = new QBluetoothServiceDiscoveryAgent(this); connect(sda, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); - connect(sda, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this, SLOT(error(QBluetoothServiceDiscoveryAgent::Error))); + connect(sda, SIGNAL(errorOccurred(QBluetoothServiceDiscoveryAgent::Error)), this, + SLOT(error(QBluetoothServiceDiscoveryAgent::Error))); connect(sda, SIGNAL(finished()), this, SLOT(finished())); qDebug() << "Starting discovery"; sda->setUuidFilter(QBluetoothUuid(QString(TEST_SERVICE_UUID))); - sda->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery); + sda->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); for (int connectTime = MaxConnectTime; !done_discovery && connectTime > 0; connectTime -= 1000) QTest::qWait(1000); @@ -196,12 +175,12 @@ void tst_QBluetoothSocket::tst_construction() QBluetoothSocket socket; QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol); - QCOMPARE(socket.error(), QBluetoothSocket::NoSocketError); + QCOMPARE(socket.error(), QBluetoothSocket::SocketError::NoSocketError); QCOMPARE(socket.errorString(), QString()); QCOMPARE(socket.peerAddress(), QBluetoothAddress()); QCOMPARE(socket.peerName(), QString()); QCOMPARE(socket.peerPort(), quint16(0)); - QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); QCOMPARE(socket.socketDescriptor(), -1); QCOMPARE(socket.bytesAvailable(), 0); QCOMPARE(socket.bytesToWrite(), 0); @@ -240,11 +219,11 @@ void tst_QBluetoothSocket::tst_serviceConnection() QSignalSpy stateSpy(&socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState))); QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol); - QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); /* Connection */ QSignalSpy connectedSpy(&socket, SIGNAL(connected())); - QSignalSpy errorSpy(&socket, SIGNAL(error(QBluetoothSocket::SocketError))); + QSignalSpy errorSpy(&socket, SIGNAL(errorOccurred(QBluetoothSocket::SocketError))); QCOMPARE(socket.openMode(), QIODevice::NotOpen); QCOMPARE(socket.isWritable(), false); @@ -253,26 +232,26 @@ void tst_QBluetoothSocket::tst_serviceConnection() socket.connectToService(remoteServiceInfo); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ConnectingState); - QCOMPARE(socket.state(), QBluetoothSocket::ConnectingState); + QCOMPARE(stateSpy.size(), 1); + QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ConnectingState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectingState); stateSpy.clear(); int connectTime = MaxConnectTime; - while (connectedSpy.count() == 0 && errorSpy.count() == 0 && connectTime > 0) { + while (connectedSpy.isEmpty() && errorSpy.isEmpty() && connectTime > 0) { QTest::qWait(1000); connectTime -= 1000; } - if (errorSpy.count() != 0) { + if (!errorSpy.isEmpty()) { qDebug() << errorSpy.takeFirst().at(0).toInt(); QSKIP("Connection error"); } - QCOMPARE(connectedSpy.count(), 1); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ConnectedState); - QCOMPARE(socket.state(), QBluetoothSocket::ConnectedState); + QCOMPARE(connectedSpy.size(), 1); + QCOMPARE(stateSpy.size(), 1); + QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ConnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectedState); QCOMPARE(socket.isWritable(), true); QCOMPARE(socket.isReadable(), true); @@ -283,7 +262,13 @@ void tst_QBluetoothSocket::tst_serviceConnection() //check the peer & local info QCOMPARE(socket.localAddress(), localDevice.address()); QCOMPARE(socket.localName(), localDevice.name()); +#ifdef Q_OS_WIN + // On Windows the socket peer name (aka remotehost display name) seems to be + // formed from the BT address and not necessarily the remoteDevice name + QVERIFY(!socket.peerName().isEmpty()); +#else QCOMPARE(socket.peerName(), remoteDevice.name()); +#endif QCOMPARE(socket.peerAddress(), remoteDevice.address()); /* Disconnection */ @@ -295,18 +280,18 @@ void tst_QBluetoothSocket::tst_serviceConnection() QCOMPARE(socket.isOpen(), false); QCOMPARE(socket.openMode(), QIODevice::NotOpen); - QVERIFY(stateSpy.count() >= 1); - QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ClosingState); + QVERIFY(!stateSpy.isEmpty()); + QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ClosingState); int disconnectTime = MaxConnectTime; - while (disconnectedSpy.count() == 0 && disconnectTime > 0) { + while (disconnectedSpy.isEmpty() && disconnectTime > 0) { QTest::qWait(1000); disconnectTime -= 1000; } - QCOMPARE(disconnectedSpy.count(), 1); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::UnconnectedState); + QCOMPARE(disconnectedSpy.size(), 1); + QCOMPARE(stateSpy.size(), 1); + QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::UnconnectedState); // The remote service needs time to close the connection and resume listening QTest::qSleep(100); @@ -337,7 +322,7 @@ void tst_QBluetoothSocket::tst_clientCommunication() QSignalSpy stateSpy(&socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState))); QCOMPARE(socket.socketType(), QBluetoothServiceInfo::RfcommProtocol); - QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); /* Connection */ QSignalSpy connectedSpy(&socket, SIGNAL(connected())); @@ -348,14 +333,14 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(socket.openMode(), QIODevice::NotOpen); socket.connectToService(remoteServiceInfo); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ConnectingState); - QCOMPARE(socket.state(), QBluetoothSocket::ConnectingState); + QCOMPARE(stateSpy.size(), 1); + QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ConnectingState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectingState); stateSpy.clear(); int connectTime = MaxConnectTime; - while (connectedSpy.count() == 0 && connectTime > 0) { + while (connectedSpy.isEmpty() && connectTime > 0) { QTest::qWait(1000); connectTime -= 1000; } @@ -364,10 +349,10 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(socket.isReadable(), true); QCOMPARE(socket.isOpen(), true); - QCOMPARE(connectedSpy.count(), 1); - QCOMPARE(stateSpy.count(), 1); - QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ConnectedState); - QCOMPARE(socket.state(), QBluetoothSocket::ConnectedState); + QCOMPARE(connectedSpy.size(), 1); + QCOMPARE(stateSpy.size(), 1); + QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ConnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectedState); stateSpy.clear(); @@ -377,7 +362,7 @@ void tst_QBluetoothSocket::tst_clientCommunication() { /* Send line by line with event loop */ - for (const QString &line : qAsConst(data)) { + for (const QString &line : std::as_const(data)) { QSignalSpy readyReadSpy(&socket, SIGNAL(readyRead())); QSignalSpy bytesWrittenSpy(&socket, SIGNAL(bytesWritten(qint64))); @@ -386,31 +371,31 @@ void tst_QBluetoothSocket::tst_clientCommunication() if (socket.openMode() & QIODevice::Unbuffered) QCOMPARE(socket.bytesToWrite(), qint64(0)); else - QCOMPARE(socket.bytesToWrite(), qint64(line.length())); + QCOMPARE(socket.bytesToWrite(), qint64(line.size())); - QCOMPARE(dataWritten, qint64(line.length())); + QCOMPARE(dataWritten, qint64(line.size())); int readWriteTime = MaxReadWriteTime; - while ((bytesWrittenSpy.count() == 0 || readyReadSpy.count() == 0) && readWriteTime > 0) { + while ((bytesWrittenSpy.isEmpty() || readyReadSpy.isEmpty()) && readWriteTime > 0) { QTest::qWait(1000); readWriteTime -= 1000; } - QCOMPARE(bytesWrittenSpy.count(), 1); - QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(line.length())); + QCOMPARE(bytesWrittenSpy.size(), 1); + QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(line.size())); readWriteTime = MaxReadWriteTime; - while ((readyReadSpy.count() == 0) && readWriteTime > 0) { + while (readyReadSpy.isEmpty() && readWriteTime > 0) { QTest::qWait(1000); readWriteTime -= 1000; } - QCOMPARE(readyReadSpy.count(), 1); + QCOMPARE(readyReadSpy.size(), 1); if (socket.openMode() & QIODevice::Unbuffered) - QVERIFY(socket.bytesAvailable() <= qint64(line.length())); + QVERIFY(socket.bytesAvailable() <= qint64(line.size())); else - QCOMPARE(socket.bytesAvailable(), qint64(line.length())); + QCOMPARE(socket.bytesAvailable(), qint64(line.size())); QVERIFY(socket.canReadLine()); @@ -435,24 +420,24 @@ void tst_QBluetoothSocket::tst_clientCommunication() if (socket.openMode() & QIODevice::Unbuffered) QCOMPARE(socket.bytesToWrite(), qint64(0)); else - QCOMPARE(socket.bytesToWrite(), qint64(joined.length())); + QCOMPARE(socket.bytesToWrite(), qint64(joined.size())); - QCOMPARE(dataWritten, qint64(joined.length())); + QCOMPARE(dataWritten, qint64(joined.size())); int readWriteTime = MaxReadWriteTime; - while ((bytesWrittenSpy.count() == 0 || readyReadSpy.count() == 0) && readWriteTime > 0) { + while ((bytesWrittenSpy.isEmpty() || readyReadSpy.isEmpty()) && readWriteTime > 0) { QTest::qWait(1000); readWriteTime -= 1000; } - QCOMPARE(bytesWrittenSpy.count(), 1); - QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(joined.length())); - QVERIFY(readyReadSpy.count() > 0); + QCOMPARE(bytesWrittenSpy.size(), 1); + QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(joined.size())); + QVERIFY(!readyReadSpy.isEmpty()); if (socket.openMode() & QIODevice::Unbuffered) - QVERIFY(socket.bytesAvailable() <= qint64(joined.length())); + QVERIFY(socket.bytesAvailable() <= qint64(joined.size())); else - QCOMPARE(socket.bytesAvailable(), qint64(joined.length())); + QCOMPARE(socket.bytesAvailable(), qint64(joined.size())); QVERIFY(socket.canReadLine()); @@ -472,15 +457,15 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(socket.openMode(), QIODevice::NotOpen); int disconnectTime = MaxConnectTime; - while (disconnectedSpy.count() == 0 && disconnectTime > 0) { + while (disconnectedSpy.isEmpty() && disconnectTime > 0) { QTest::qWait(1000); disconnectTime -= 1000; } - QCOMPARE(disconnectedSpy.count(), 1); - QCOMPARE(stateSpy.count(), 2); - QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ClosingState); - QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::UnconnectedState); + QCOMPARE(disconnectedSpy.size(), 1); + QCOMPARE(stateSpy.size(), 2); + QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ClosingState); + QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::UnconnectedState); // The remote service needs time to close the connection and resume listening QTest::qSleep(100); @@ -489,11 +474,11 @@ void tst_QBluetoothSocket::tst_clientCommunication() void tst_QBluetoothSocket::tst_error() { QBluetoothSocket socket; - QSignalSpy errorSpy(&socket, SIGNAL(error(QBluetoothSocket::SocketError))); - QCOMPARE(errorSpy.count(), 0); + QSignalSpy errorSpy(&socket, SIGNAL(errorOccurred(QBluetoothSocket::SocketError))); + QCOMPARE(errorSpy.size(), 0); const QBluetoothSocket::SocketError e = socket.error(); - QVERIFY(e == QBluetoothSocket::NoSocketError); + QVERIFY(e == QBluetoothSocket::SocketError::NoSocketError); QVERIFY(socket.errorString() == QString()); } @@ -503,21 +488,27 @@ void tst_QBluetoothSocket::tst_preferredSecurityFlags() QBluetoothSocket socket; //test default values -#if defined(QT_ANDROID_BLUETOOTH) | defined(QT_OSX_BLUETOOTH) - QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Secure); +#if defined(QT_ANDROID_BLUETOOTH) || defined(QT_OSX_BLUETOOTH) + QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Security::Secure); #elif QT_CONFIG(bluez) - QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Authorization); + // The bluezdbus socket uses "NoSecurity" by default, whereas the non-dbus bluez + // socket uses "Authorization" by default + if (bluetoothdVersion() >= QVersionNumber(5, 46)) + QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Security::NoSecurity); + else + QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Security::Authorization); #else - QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::NoSecurity); + QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Security::NoSecurity); #endif - socket.setPreferredSecurityFlags(QBluetooth::Authentication|QBluetooth::Encryption); + socket.setPreferredSecurityFlags(QBluetooth::Security::Authentication + | QBluetooth::Security::Encryption); #if defined(QT_OSX_BLUETOOTH) - QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Secure); + QCOMPARE(socket.preferredSecurityFlags(), QBluetooth::Security::Secure); #else QCOMPARE(socket.preferredSecurityFlags(), - QBluetooth::Encryption|QBluetooth::Authentication); + QBluetooth::Security::Encryption | QBluetooth::Security::Authentication); #endif } @@ -531,19 +522,19 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError() // UnsupportedProtocolError. QBluetoothSocket socket; QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol); - QVERIFY(socket.error() == QBluetoothSocket::NoSocketError); + QVERIFY(socket.error() == QBluetoothSocket::SocketError::NoSocketError); QVERIFY(socket.errorString() == QString()); - QSignalSpy errorSpy(&socket, SIGNAL(error(QBluetoothSocket::SocketError))); + QSignalSpy errorSpy(&socket, SIGNAL(errorOccurred(QBluetoothSocket::SocketError))); // 1. Stop early with 'UnsupportedProtocolError'. QBluetoothServiceInfo dummyServiceInfo; socket.connectToService(dummyServiceInfo, QIODevice::ReadWrite); QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000); QCOMPARE(errorSpy.size(), 1); - QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError)); + QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError)); QVERIFY(socket.errorString().size() != 0); - QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); errorSpy.clear(); @@ -551,9 +542,20 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError() socket.connectToService(QBluetoothAddress(), 1, QIODevice::ReadWrite); QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000); QCOMPARE(errorSpy.size(), 1); - QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError)); +#if QT_CONFIG(bluez) + // Bluez dbus socket does not support connecting to port and gives different error code + if (bluetoothdVersion() >= QVersionNumber(5, 46)) { + 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::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); errorSpy.clear(); @@ -561,9 +563,9 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError() socket.connectToService(QBluetoothAddress(), QBluetoothUuid(), QIODevice::ReadWrite); QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000); QCOMPARE(errorSpy.size(), 1); - QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError)); + QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError)); QVERIFY(socket.errorString().size() != 0); - QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState); + QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState); } QTEST_MAIN(tst_QBluetoothSocket) |