diff options
Diffstat (limited to 'tests/auto')
5 files changed, 39 insertions, 49 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 672a550e..96222438 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -1,9 +1,4 @@ if(TARGET Qt::Bluetooth) - if(ANDROID) - if("$ENV{QTEST_ENVIRONMENT}" STREQUAL "ci") - add_compile_definitions(ANDROID_CI_TEST_ENVIRONMENT) - endif() - endif() add_subdirectory(qbluetoothaddress) add_subdirectory(qbluetoothdevicediscoveryagent) add_subdirectory(qbluetoothdeviceinfo) diff --git a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp index e16e2405..af2e1c8e 100644 --- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp +++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp @@ -33,6 +33,7 @@ #include <QList> #include <QLoggingCategory> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothaddress.h> #include <qbluetoothdevicediscoveryagent.h> @@ -153,10 +154,8 @@ void tst_QBluetoothDeviceDiscoveryAgent::deviceDiscoveryDebug(const QBluetoothDe void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); QBluetoothDeviceDiscoveryAgent discoveryAgent; QVERIFY(discoveryAgent.error() == discoveryAgent.NoError); @@ -429,10 +428,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryTimeout() void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + 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. diff --git a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp index 153d515d..32f8448d 100644 --- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp +++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp @@ -30,6 +30,7 @@ #include <QDebug> #include <QVariant> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothaddress.h> @@ -70,14 +71,15 @@ private slots: private: QBluetoothAddress remoteDevice; - qsizetype numDevices; - bool expectRemoteDevice; + qsizetype numDevices = 0; + bool expectRemoteDevice = false; }; tst_QBluetoothLocalDevice::tst_QBluetoothLocalDevice() - : numDevices(QBluetoothLocalDevice::allDevices().size()), - expectRemoteDevice(false) { + if (androidBluetoothEmulator()) + return; + numDevices = QBluetoothLocalDevice::allDevices().size(); const QString remote = qgetenv("BT_TEST_DEVICE"); if (!remote.isEmpty()) { remoteDevice = QBluetoothAddress(remote); @@ -102,10 +104,8 @@ void tst_QBluetoothLocalDevice::initTestCase() void tst_QBluetoothLocalDevice::tst_powerOn() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -138,10 +138,8 @@ void tst_QBluetoothLocalDevice::tst_powerOn() void tst_QBluetoothLocalDevice::tst_powerOff() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -200,10 +198,8 @@ void tst_QBluetoothLocalDevice::tst_hostModes_data() void tst_QBluetoothLocalDevice::tst_hostModes() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -282,6 +278,8 @@ void tst_QBluetoothLocalDevice::tst_name() } void tst_QBluetoothLocalDevice::tst_isValid() { + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #if defined(Q_OS_MACOS) || QT_CONFIG(winrt_bt) // On OS X we can have a valid device (device.isValid() == true), // that has neither a name nor a valid address - this happens @@ -383,10 +381,8 @@ void tst_QBluetoothLocalDevice::tst_pairDevice_data() void tst_QBluetoothLocalDevice::tst_pairDevice() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #if defined(Q_OS_MACOS) QSKIP("The pair device test fails on macOS"); #endif diff --git a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp index d265bccc..9015345b 100644 --- a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp +++ b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp @@ -30,6 +30,7 @@ #include <QDebug> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothserver.h> #include <qbluetoothsocket.h> @@ -59,7 +60,7 @@ private slots: void setHostMode(const QBluetoothAddress &localAdapter, QBluetoothLocalDevice::HostMode newHostMode); private: - QBluetoothLocalDevice localDevice; + QBluetoothLocalDevice *localDevice = nullptr; QBluetoothLocalDevice::HostMode initialHostMode; }; @@ -107,9 +108,13 @@ 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; @@ -122,15 +127,15 @@ void tst_QBluetoothServer::initTestCase() 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() @@ -169,11 +174,6 @@ void tst_QBluetoothServer::tst_receive() { QFETCH(QBluetoothLocalDevice::HostMode, hostmode); -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif - QBluetoothLocalDevice localDev; #ifdef Q_OS_OSX if (localDev.hostMode() == QBluetoothLocalDevice::HostPoweredOff) @@ -189,10 +189,10 @@ void tst_QBluetoothServer::tst_receive() if (hostmode == QBluetoothLocalDevice::HostPoweredOff) { #if !defined(Q_OS_OSX) && !QT_CONFIG(winrt_bt) - QCOMPARE(localDevice.hostMode(), hostmode); + QCOMPARE(localDevice->hostMode(), hostmode); #endif } else { - QVERIFY(localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff); + QVERIFY(localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff); } } QBluetoothServer server(QBluetoothServiceInfo::RfcommProtocol); diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp index 8d790357..27827da3 100644 --- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp +++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp @@ -32,6 +32,7 @@ #include <QLoggingCategory> #include <QVariant> #include <QList> +#include "../../shared/bttestutil_p.h" #include <qbluetoothaddress.h> #include <qbluetoothdevicediscoveryagent.h> @@ -75,7 +76,8 @@ private: tst_QBluetoothServiceDiscoveryAgent::tst_QBluetoothServiceDiscoveryAgent() { QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); - + if (androidBluetoothEmulator()) + return; // start Bluetooth if not started #ifndef Q_OS_OSX QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); @@ -115,10 +117,9 @@ void tst_QBluetoothServiceDiscoveryAgent::serviceError(const QBluetoothServiceDi void tst_QBluetoothServiceDiscoveryAgent::initTestCase() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); + if (localDeviceAvailable) { QBluetoothDeviceDiscoveryAgent discoveryAgent; |