summaryrefslogtreecommitdiffstats
path: root/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp')
-rw-r--r--tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp70
1 files changed, 24 insertions, 46 deletions
diff --git a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
index 4564cf4d..ed56d49a 100644
--- a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
+++ b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
@@ -1,35 +1,11 @@
-/****************************************************************************
-**
-** 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>
#include <QDebug>
+#include "../../shared/bttestutil_p.h"
#include <private/qtbluetoothglobal_p.h>
#include <qbluetoothserver.h>
#include <qbluetoothsocket.h>
@@ -37,14 +13,8 @@
QT_USE_NAMESPACE
-//same uuid as tests/bttestui
-#define TEST_SERVICE_UUID "e8e10f95-1a70-4b27-9ccf-02010264e9c8"
-
Q_DECLARE_METATYPE(QBluetooth::SecurityFlags)
-// Max time to wait for connection
-static const int MaxConnectTime = 60 * 1000; // 1 minute in ms
-
class tst_QBluetoothServer : public QObject
{
Q_OBJECT
@@ -65,7 +35,7 @@ private slots:
void setHostMode(const QBluetoothAddress &localAdapter, QBluetoothLocalDevice::HostMode newHostMode);
private:
- QBluetoothLocalDevice localDevice;
+ QBluetoothLocalDevice *localDevice = nullptr;
QBluetoothLocalDevice::HostMode initialHostMode;
};
@@ -105,7 +75,7 @@ void tst_QBluetoothServer::setHostMode(const QBluetoothAddress &localAdapter,
}
int connectTime = 5000; // ms
- while (hostModeSpy.count() < 1 && connectTime > 0) {
+ while (hostModeSpy.isEmpty() && connectTime > 0) {
QTest::qWait(500);
connectTime -= 500;
}
@@ -113,30 +83,34 @@ void tst_QBluetoothServer::setHostMode(const QBluetoothAddress &localAdapter,
void tst_QBluetoothServer::initTestCase()
{
+ if (androidBluetoothEmulator())
+ QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input");
qRegisterMetaType<QBluetooth::SecurityFlags>();
qRegisterMetaType<QBluetoothServer::Error>();
+ localDevice = new QBluetoothLocalDevice(this);
+
QBluetoothLocalDevice device;
if (!device.isValid())
return;
initialHostMode = device.hostMode();
-#ifdef Q_OS_OSX
+#ifdef Q_OS_MACOS
if (initialHostMode == QBluetoothLocalDevice::HostPoweredOff)
return;
#endif
setHostMode(device.address(), QBluetoothLocalDevice::HostConnectable);
- QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode();
+ QBluetoothLocalDevice::HostMode hostMode= localDevice->hostMode();
QVERIFY(hostMode != QBluetoothLocalDevice::HostPoweredOff);
}
void tst_QBluetoothServer::cleanupTestCase()
{
- QBluetoothLocalDevice device;
- setHostMode(device.address(), initialHostMode);
+ if (localDevice)
+ setHostMode(localDevice->address(), initialHostMode);
}
void tst_QBluetoothServer::tst_construction()
@@ -176,7 +150,7 @@ void tst_QBluetoothServer::tst_receive()
QFETCH(QBluetoothLocalDevice::HostMode, hostmode);
QBluetoothLocalDevice localDev;
-#ifdef Q_OS_OSX
+#ifdef Q_OS_MACOS
if (localDev.hostMode() == QBluetoothLocalDevice::HostPoweredOff)
QSKIP("On OS X this test requires Bluetooth adapter ON");
#endif
@@ -189,23 +163,27 @@ void tst_QBluetoothServer::tst_receive()
setHostMode(address, hostmode);
if (hostmode == QBluetoothLocalDevice::HostPoweredOff) {
-#if !defined(Q_OS_OSX) && !QT_CONFIG(winrt_bt)
- QCOMPARE(localDevice.hostMode(), hostmode);
+#if !defined(Q_OS_MACOS) && !QT_CONFIG(winrt_bt)
+ QCOMPARE(localDevice->hostMode(), hostmode);
#endif
} else {
- QVERIFY(localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff);
+ QVERIFY(localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff);
}
}
QBluetoothServer server(QBluetoothServiceInfo::RfcommProtocol);
- QSignalSpy errorSpy(&server, SIGNAL(error(QBluetoothServer::Error)));
+ QSignalSpy errorSpy(&server, SIGNAL(errorOccurred(QBluetoothServer::Error)));
bool result = server.listen(address, 20); // port == 20
QTest::qWait(1000);
if (!result) {
+#ifndef Q_OS_ANDROID
+ // Disable address check on Android as an actual device always returns
+ // a valid address, while the emulator doesn't
QCOMPARE(server.serverAddress(), QBluetoothAddress());
+#endif
QCOMPARE(server.serverPort(), quint16(0));
- QVERIFY(errorSpy.count() > 0);
+ QVERIFY(!errorSpy.isEmpty());
QVERIFY(!server.isListening());
if (!localDeviceAvailable) {
QVERIFY(server.error() != QBluetoothServer::NoError);
@@ -219,7 +197,7 @@ void tst_QBluetoothServer::tst_receive()
QVERIFY(result);
#if !QT_CONFIG(winrt_bt)
- QVERIFY(QBluetoothLocalDevice::allDevices().count());
+ QVERIFY(!QBluetoothLocalDevice::allDevices().isEmpty());
#endif
QCOMPARE(server.error(), QBluetoothServer::NoError);
QCOMPARE(server.serverAddress(), address);