summaryrefslogtreecommitdiffstats
path: root/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp')
-rw-r--r--tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp329
1 files changed, 134 insertions, 195 deletions
diff --git a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp
index cbce5042..d866ec57 100644
--- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.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>
@@ -33,11 +8,20 @@
#include <QList>
#include <QLoggingCategory>
+#include "../../shared/bttestutil_p.h"
#include <private/qtbluetoothglobal_p.h>
#include <qbluetoothaddress.h>
#include <qbluetoothdevicediscoveryagent.h>
#include <qbluetoothlocaldevice.h>
+#if QT_CONFIG(permissions)
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#include <QtCore/qnamespace.h>
+#endif // permissions
+
+#include <memory>
+
QT_USE_NAMESPACE
/*
@@ -55,6 +39,11 @@ const int MaxScanTime = 5 * 60 * 1000; // 5 minutes in ms
//Bluez needs at least 10s for a device discovery to be cancelled
const int MaxWaitForCancelTime = 15 * 1000; // 15 seconds in ms
+#ifdef Q_OS_ANDROID
+// Android is sometimes unable to cancel immediately
+const int WaitBeforeStopTime = 200;
+#endif
+
class tst_QBluetoothDeviceDiscoveryAgent : public QObject
{
Q_OBJECT
@@ -70,85 +59,52 @@ public slots:
private slots:
void initTestCase();
- void tst_properties();
-
void tst_invalidBtAddress();
void tst_startStopDeviceDiscoveries();
- void tst_deviceDiscovery_data();
void tst_deviceDiscovery();
void tst_discoveryTimeout();
void tst_discoveryMethods();
private:
- int noOfLocalDevices;
- bool isBluez5Runtime = false;
+ qsizetype noOfLocalDevices;
+ using DiscoveryAgentPtr = std::unique_ptr<QBluetoothDeviceDiscoveryAgent>;
+#if QT_CONFIG(permissions)
+ Qt::PermissionStatus permissionStatus = Qt::PermissionStatus::Undetermined;
+#endif
};
tst_QBluetoothDeviceDiscoveryAgent::tst_QBluetoothDeviceDiscoveryAgent()
{
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::Error>();
-}
-
-tst_QBluetoothDeviceDiscoveryAgent::~tst_QBluetoothDeviceDiscoveryAgent()
-{
-}
-
-#if QT_CONFIG(bluez)
-// This section was adopted from tst_qloggingcategory.cpp
-QString logMessage;
-
-QByteArray qMyMessageFormatString(QtMsgType type, const QMessageLogContext &context,
- const QString &str)
-{
- QByteArray message;
- message.append(context.category);
- switch (type) {
- case QtDebugMsg: message.append(".debug"); break;
- case QtInfoMsg: message.append(".info"); break;
- case QtWarningMsg: message.append(".warning"); break;
- case QtCriticalMsg:message.append(".critical"); break;
- case QtFatalMsg: message.append(".fatal"); break;
+#if QT_CONFIG(permissions)
+ permissionStatus = qApp->checkPermission(QBluetoothPermission{});
+
+ const bool ciRun = qEnvironmentVariable("QTEST_ENVIRONMENT").split(' ').contains("ci");
+ if (!ciRun && permissionStatus == Qt::PermissionStatus::Undetermined) {
+ QTestEventLoop loop;
+ qApp->requestPermission(QBluetoothPermission{}, [this, &loop](const QPermission &permission){
+ permissionStatus = permission.status();
+ loop.exitLoop();
+ });
+ if (permissionStatus == Qt::PermissionStatus::Undetermined)
+ loop.enterLoopMSecs(30000);
}
- message.append(": ");
- message.append(qPrintable(str));
-
- return message.simplified();
+#endif // QT_CONFIG(permissions)
}
-static void myCustomMessageHandler(QtMsgType type,
- const QMessageLogContext &context,
- const QString &msg)
+tst_QBluetoothDeviceDiscoveryAgent::~tst_QBluetoothDeviceDiscoveryAgent()
{
- logMessage = qMyMessageFormatString(type, context, msg);
}
-#endif
-
-
void tst_QBluetoothDeviceDiscoveryAgent::initTestCase()
{
qRegisterMetaType<QBluetoothDeviceInfo>();
- qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::InquiryType>();
-
-#if QT_CONFIG(bluez)
- // To distinguish Bluez 4 and 5 we peek into the debug output
- // of first Bluetooth ctor. It executes a runtime test and prints the result
- // as logging output. This avoids more complex runtime detection logic within this unit test.
- QtMessageHandler oldMessageHandler;
- oldMessageHandler = qInstallMessageHandler(myCustomMessageHandler);
-
- noOfLocalDevices = QBluetoothLocalDevice::allDevices().count();
- qInstallMessageHandler(oldMessageHandler);
- isBluez5Runtime = logMessage.contains(QStringLiteral("Bluez 5"));
- if (isBluez5Runtime)
- qDebug() << "BlueZ 5 runtime detected.";
-#else
- noOfLocalDevices = QBluetoothLocalDevice::allDevices().count();
-#endif
+
+ noOfLocalDevices = QBluetoothLocalDevice::allDevices().size();
if (!noOfLocalDevices)
return;
@@ -160,11 +116,11 @@ void tst_QBluetoothDeviceDiscoveryAgent::initTestCase()
QVERIFY(hostModeSpy.isEmpty());
device->powerOn();
int connectTime = 5000; // ms
- while (hostModeSpy.count() < 1 && connectTime > 0) {
+ while (hostModeSpy.isEmpty() && connectTime > 0) {
QTest::qWait(500);
connectTime -= 500;
}
- QVERIFY(hostModeSpy.count() > 0);
+ QVERIFY(!hostModeSpy.isEmpty());
}
QBluetoothLocalDevice::HostMode hostMode= device->hostMode();
QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable
@@ -173,33 +129,26 @@ void tst_QBluetoothDeviceDiscoveryAgent::initTestCase()
delete device;
}
-void tst_QBluetoothDeviceDiscoveryAgent::tst_properties()
-{
- QBluetoothDeviceDiscoveryAgent discoveryAgent;
-
- QCOMPARE(discoveryAgent.inquiryType(), QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry);
- discoveryAgent.setInquiryType(QBluetoothDeviceDiscoveryAgent::LimitedInquiry);
- QCOMPARE(discoveryAgent.inquiryType(), QBluetoothDeviceDiscoveryAgent::LimitedInquiry);
- discoveryAgent.setInquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry);
- QCOMPARE(discoveryAgent.inquiryType(), QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry);
-}
-
void tst_QBluetoothDeviceDiscoveryAgent::tst_invalidBtAddress()
{
- QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(QBluetoothAddress("11:11:11:11:11:11"));
+ DiscoveryAgentPtr discoveryAgent(new QBluetoothDeviceDiscoveryAgent(
+ QBluetoothAddress(QStringLiteral("11:11:11:11:11:11"))));
QCOMPARE(discoveryAgent->error(), QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError);
discoveryAgent->start();
QCOMPARE(discoveryAgent->isActive(), false);
- delete discoveryAgent;
- discoveryAgent = new QBluetoothDeviceDiscoveryAgent(QBluetoothAddress());
+#if QT_CONFIG(permissions)
+ if (permissionStatus != Qt::PermissionStatus::Granted)
+ return;
+#endif
+
+ discoveryAgent.reset(new QBluetoothDeviceDiscoveryAgent(QBluetoothAddress()));
QCOMPARE(discoveryAgent->error(), QBluetoothDeviceDiscoveryAgent::NoError);
- if (QBluetoothLocalDevice::allDevices().count() > 0) {
+ if (!QBluetoothLocalDevice::allDevices().isEmpty()) {
discoveryAgent->start();
QCOMPARE(discoveryAgent->isActive(), true);
}
- delete discoveryAgent;
}
void tst_QBluetoothDeviceDiscoveryAgent::deviceDiscoveryDebug(const QBluetoothDeviceInfo &info)
@@ -209,7 +158,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::deviceDiscoveryDebug(const QBluetoothDe
void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
{
- QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
+ if (androidBluetoothEmulator())
+ QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input");
+
QBluetoothDeviceDiscoveryAgent discoveryAgent;
QVERIFY(discoveryAgent.error() == discoveryAgent.NoError);
@@ -219,14 +170,22 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
QSignalSpy cancelSpy(&discoveryAgent, SIGNAL(canceled()));
- QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QSignalSpy errorSpy(&discoveryAgent,
+ SIGNAL(errorOccurred(QBluetoothDeviceDiscoveryAgent::Error)));
// Starting case 1: start-stop, expecting cancel signal
- discoveryAgent.setInquiryType(inquiryType);
// we should have no errors at this point.
QVERIFY(errorSpy.isEmpty());
discoveryAgent.start();
+#if QT_CONFIG(permissions)
+ if (permissionStatus != Qt::PermissionStatus::Granted) {
+ // If bluetooth is OFF, the permission does not get checked (e.g. on Darwin),
+ // but not to depend on the order in which errors generated, we
+ // do not compare error value with MissionPermissionsError here.
+ return;
+ }
+#endif
if (errorSpy.isEmpty()) {
QVERIFY(discoveryAgent.isActive());
@@ -240,19 +199,27 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QSKIP("No local Bluetooth device available. Skipping remaining part of test.");
}
// cancel current request.
+#ifdef Q_OS_ANDROID
+ // Android sometimes can't cancel immediately (~on the same millisecond),
+ // but instead a "pending cancel" happens, which means the discovery will be
+ // canceled at a later point in time. When this happens the Android backend
+ // also emits an immediate errorOccurred(). While this seems to be as intended,
+ // as a result many parts of this test function may fail (not always).
+ //
+ // In this test function we wait some milliseconds between start() and stop() to
+ // bypass this behavior difference. This is to avoid complex iffery (Android itself
+ // can behave differently every time) and ifdeffery (Q_OS_ANDROID) in the test
+ QTest::qWait(WaitBeforeStopTime);
+#endif
discoveryAgent.stop();
// Wait for up to MaxWaitForCancelTime for the cancel to finish
- int waitTime = MaxWaitForCancelTime;
- while (cancelSpy.count() == 0 && waitTime > 0) {
- QTest::qWait(100);
- waitTime-=100;
- }
+ QTRY_VERIFY_WITH_TIMEOUT(!cancelSpy.isEmpty(), MaxWaitForCancelTime);
// we should not be active anymore
QVERIFY(!discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
- QCOMPARE(cancelSpy.count(), 1);
+ QCOMPARE(cancelSpy.size(), 1);
cancelSpy.clear();
// Starting case 2: start-start-stop, expecting cancel signal
discoveryAgent.start();
@@ -264,19 +231,19 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
// stop
+#ifdef Q_OS_ANDROID
+ QTest::qWait(WaitBeforeStopTime);
+#endif
discoveryAgent.stop();
// Wait for up to MaxWaitForCancelTime for the cancel to finish
- waitTime = MaxWaitForCancelTime;
- while (cancelSpy.count() == 0 && waitTime > 0) {
- QTest::qWait(100);
- waitTime-=100;
- }
+ QTRY_VERIFY_WITH_TIMEOUT(!cancelSpy.isEmpty(), MaxWaitForCancelTime);
// we should not be active anymore
QVERIFY(!discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
- QVERIFY(cancelSpy.count() == 1);
+
+ QCOMPARE(cancelSpy.size(), 1);
cancelSpy.clear();
// Starting case 3: stop
@@ -285,7 +252,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(errorSpy.isEmpty());
// Don't expect finished signal and no error
- QVERIFY(finishedSpy.count() == 0);
+ QVERIFY(finishedSpy.isEmpty());
QVERIFY(discoveryAgent.error() == discoveryAgent.NoError);
QVERIFY(discoveryAgent.errorString().isEmpty());
@@ -306,9 +273,12 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
// cancel current request.
+#ifdef Q_OS_ANDROID
+ QTest::qWait(WaitBeforeStopTime);
+#endif
discoveryAgent.stop();
//should only have triggered cancel() if stop didn't involve the event loop
- if (cancelSpy.count() == 1) immediateSignal = true;
+ if (cancelSpy.size() == 1) immediateSignal = true;
// start a new one
discoveryAgent.start();
@@ -316,25 +286,25 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
// stop
+#ifdef Q_OS_ANDROID
+ QTest::qWait(WaitBeforeStopTime);
+#endif
discoveryAgent.stop();
if (immediateSignal)
- QVERIFY(cancelSpy.count() == 2);
+ QCOMPARE(cancelSpy.size(), 2);
// Wait for up to MaxWaitForCancelTime for the cancel to finish
- waitTime = MaxWaitForCancelTime;
- while (cancelSpy.count() == 0 && waitTime > 0) {
- QTest::qWait(100);
- waitTime-=100;
- }
+ QTRY_VERIFY_WITH_TIMEOUT(!cancelSpy.isEmpty(), MaxWaitForCancelTime);
+
// we should not be active anymore
QVERIFY(!discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
- // should only have 1 cancel
+ // should only have 1 cancel
if (immediateSignal)
- QVERIFY(cancelSpy.count() == 2);
+ QCOMPARE(cancelSpy.size(), 2);
else
- QVERIFY(cancelSpy.count() == 1);
+ QCOMPARE(cancelSpy.size(), 1);
cancelSpy.clear();
// Starting case 5: start-stop-start: expecting finished signal & no cancel
@@ -342,6 +312,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
// cancel current request.
+#ifdef Q_OS_ANDROID
+ QTest::qWait(WaitBeforeStopTime);
+#endif
discoveryAgent.stop();
// start a new one
discoveryAgent.start();
@@ -349,18 +322,14 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries()
QVERIFY(discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
- // Wait for up to MaxScanTime for the cancel to finish
- waitTime = MaxScanTime;
- while (finishedSpy.count() == 0 && waitTime > 0) {
- QTest::qWait(1000);
- waitTime-=1000;
- }
+ // Wait for up to MaxScanTime for the scan to finish
+ QTRY_VERIFY_WITH_TIMEOUT(!finishedSpy.isEmpty(), MaxScanTime);
// we should not be active anymore
QVERIFY(!discoveryAgent.isActive());
QVERIFY(errorSpy.isEmpty());
// should only have 1 cancel
- QVERIFY(finishedSpy.count() == 1);
+ QCOMPARE(finishedSpy.size(), 1);
// On OS X, stop is synchronous (signal will be emitted immediately).
if (!immediateSignal)
@@ -372,32 +341,13 @@ void tst_QBluetoothDeviceDiscoveryAgent::finished()
qDebug() << "Finished called";
}
-void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery_data()
-{
- QTest::addColumn<QBluetoothDeviceDiscoveryAgent::InquiryType>("inquiryType");
-
- QTest::newRow("general unlimited inquiry") << QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
- QTest::newRow("limited inquiry") << QBluetoothDeviceDiscoveryAgent::LimitedInquiry;
-}
-
void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery()
{
{
- QFETCH(QBluetoothDeviceDiscoveryAgent::InquiryType, inquiryType);
-
//Run test in case of multiple Bluetooth adapters
QBluetoothLocalDevice localDevice;
//We will use default adapter if there is no other adapter
QBluetoothAddress address = localDevice.address();
- int numberOfAdapters = (localDevice.allDevices()).size();
- QList<QBluetoothAddress> addresses;
- if (numberOfAdapters > 1) {
-
- for (int i=0; i < numberOfAdapters; i++) {
- addresses.append(((QBluetoothHostInfo)localDevice.allDevices().at(i)).address());
- }
- address = (QBluetoothAddress)addresses.at(0);
- }
QBluetoothDeviceDiscoveryAgent discoveryAgent(address);
QVERIFY(discoveryAgent.error() == discoveryAgent.NoError);
@@ -407,15 +357,20 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery()
QVERIFY(discoveryAgent.discoveredDevices().isEmpty());
QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
- QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QSignalSpy errorSpy(&discoveryAgent,
+ SIGNAL(errorOccurred(QBluetoothDeviceDiscoveryAgent::Error)));
QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)));
// connect(&discoveryAgent, SIGNAL(finished()), this, SLOT(finished()));
// connect(&discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
// this, SLOT(deviceDiscoveryDebug(QBluetoothDeviceInfo)));
- discoveryAgent.setInquiryType(inquiryType);
discoveryAgent.start();
+
if (!errorSpy.isEmpty()) {
+#if QT_CONFIG(permissions)
+ if (permissionStatus == Qt::PermissionStatus::Granted)
+#endif
+
QCOMPARE(noOfLocalDevices, 0);
QVERIFY(!discoveryAgent.isActive());
QSKIP("No local Bluetooth device available. Skipping remaining part of test.");
@@ -425,7 +380,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery()
// Wait for up to MaxScanTime for the scan to finish
int scanTime = MaxScanTime;
- while (finishedSpy.count() == 0 && scanTime > 0) {
+ while (finishedSpy.isEmpty() && scanTime > 0) {
QTest::qWait(15000);
scanTime -= 15000;
}
@@ -437,16 +392,19 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery()
QVERIFY(!discoveryAgent.isActive());
qDebug() << "Scan time left:" << scanTime;
// Expect finished signal with no error
- QVERIFY(finishedSpy.count() == 1);
+ QVERIFY(finishedSpy.size() == 1);
QVERIFY(errorSpy.isEmpty());
QVERIFY(discoveryAgent.error() == discoveryAgent.NoError);
QVERIFY(discoveryAgent.errorString().isEmpty());
// verify that the list is as big as the signals received.
- QVERIFY(discoveredSpy.count() == discoveryAgent.discoveredDevices().length());
+ // discoveredSpy might have more events as some devices are found multiple times,
+ // leading to messages like
+ // "Almost Duplicate "88:C6:26:F5:3E:E2" "88-C6-26-F5-3E-E2" - replacing in place"
+ QVERIFY(discoveredSpy.size() >= discoveryAgent.discoveredDevices().size());
// verify that there really was some devices in the array
- const QString remote = qgetenv("BT_TEST_DEVICE");
+ const QString remote = qEnvironmentVariable("BT_TEST_DEVICE");
QBluetoothAddress remoteDevice;
if (!remote.isEmpty()) {
remoteDevice = QBluetoothAddress(remote);
@@ -456,31 +414,13 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery()
}
if (!remoteDevice.isNull())
- QVERIFY(discoveredSpy.count() > 0);
- int counter = 0;
+ QVERIFY(!discoveredSpy.isEmpty());
// All returned QBluetoothDeviceInfo should be valid.
while (!discoveredSpy.isEmpty()) {
const QBluetoothDeviceInfo info =
qvariant_cast<QBluetoothDeviceInfo>(discoveredSpy.takeFirst().at(0));
QVERIFY(info.isValid());
- qDebug() << "Discovered device:" << info.address().toString() << info.name();
-
- if (numberOfAdapters > 1) {
- for (int i= 1; i < numberOfAdapters; i++) {
- if (info.address().toString() == addresses[i].toString())
- counter++;
- }
- }
}
-#if defined(Q_OS_IOS) || defined(Q_OS_TVOS) || QT_CONFIG(winrt_bt)
- //On iOS/WinRT, we do not have access to the local device/adapter, numberOfAdapters is 0,
- //so we skip this test at all.
- QSKIP("iOS/WinRT: no local Bluetooth device available. Skipping remaining part of test.");
-#endif
-
- //For multiple Bluetooth adapter do the check only for GeneralUnlimitedInquiry.
- if (!(inquiryType == QBluetoothDeviceDiscoveryAgent::LimitedInquiry))
- QVERIFY((numberOfAdapters-1) == counter);
}
}
@@ -490,24 +430,13 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryTimeout()
QBluetoothDeviceDiscoveryAgent agent;
// check default values
-#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || QT_CONFIG(winrt_bt)
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 25000);
+#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || QT_CONFIG(winrt_bt) \
+ || QT_CONFIG(bluez)
+ QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 40000);
agent.setLowEnergyDiscoveryTimeout(-1); // negative ignored
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 25000);
+ QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 40000);
agent.setLowEnergyDiscoveryTimeout(20000);
QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 20000);
-#elif QT_CONFIG(bluez)
- if (isBluez5Runtime) {
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 20000);
- agent.setLowEnergyDiscoveryTimeout(-1); // negative ignored
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 20000);
- agent.setLowEnergyDiscoveryTimeout(25000);
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), 25000);
- } else {
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), -1);
- agent.setLowEnergyDiscoveryTimeout(20000); // feature not supported -> ignored
- QCOMPARE(agent.lowEnergyDiscoveryTimeout(), -1);
- }
#else
QCOMPARE(agent.lowEnergyDiscoveryTimeout(), -1);
agent.setLowEnergyDiscoveryTimeout(20000); // feature not supported -> ignored
@@ -517,6 +446,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryTimeout()
void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods()
{
+ if (androidBluetoothEmulator())
+ QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input");
+
const QBluetoothLocalDevice localDevice;
if (localDevice.allDevices().size() != 1) {
// On iOS it returns 0 but we still have working BT.
@@ -545,7 +477,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods()
QBluetoothDeviceDiscoveryAgent agent;
QSignalSpy finishedSpy(&agent, SIGNAL(finished()));
- QSignalSpy errorSpy(&agent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QSignalSpy errorSpy(&agent, SIGNAL(errorOccurred(QBluetoothDeviceDiscoveryAgent::Error)));
QSignalSpy discoveredSpy(&agent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)));
// NoMethod - should just immediately return:
@@ -568,10 +500,15 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods()
// Start discovery, probably both Classic and LE methods:
agent.start(supportedMethods);
+#if QT_CONFIG(permissions)
+ if (permissionStatus != Qt::PermissionStatus::Granted) {
+ QCOMPARE(agent.error(), QBluetoothDeviceDiscoveryAgent::MissingPermissionsError);
+ QSKIP("The remaining test requires the Bluetooth permission granted");
+ }
+#endif
QVERIFY(agent.isActive());
QVERIFY(errorSpy.isEmpty());
-
#define RUN_DISCOVERY(maxTimeout, step, condition) \
for (int scanTime = maxTimeout; (condition) && scanTime > 0; scanTime -= step) \
QTest::qWait(step);
@@ -589,7 +526,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods()
QVERIFY(supportedMethods == QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
QCOMPARE(agent.error(), QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod);
} else {
- QVERIFY(finishedSpy.count() == 1);
+ QVERIFY(finishedSpy.size() == 1);
QVERIFY(agent.error() == QBluetoothDeviceDiscoveryAgent::NoError);
QVERIFY(agent.errorString().isEmpty());
@@ -597,7 +534,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods()
const QBluetoothDeviceInfo info =
qvariant_cast<QBluetoothDeviceInfo>(discoveredSpy.takeFirst().at(0));
QVERIFY(info.isValid());
- QVERIFY(info.coreConfigurations() & expectedConfiguration);
+ // on Android we do find devices with unknown configuration
+ if (info.coreConfigurations() != QBluetoothDeviceInfo::UnknownCoreConfiguration)
+ QVERIFY(info.coreConfigurations() & expectedConfiguration);
}
}