Skip to content

Commit

Permalink
Optimise some QSKIP macros in unit tests
Browse files Browse the repository at this point in the history
Specially:

1. move QSKIP macros from test functions into their respective data
   functions, where appropriate (resulting is less output noise,
   ever-so-slightly faster test runs).

2. replace some QSKIP macros with QEXPECT_FAILURE macros instead.
   This not only provides slightly better semantics, but also allows
   slightly better test coverage for the affected corner cases.

Squashed commit of the following:

commit 5625c06
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 09:01:57 2025 +1100

    It's device UUID tracking that (unexpectedly) passes on macOS 13

commit 1613170
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 08:57:46 2025 +1100

    Only expect failure on macOS 14+

commit b20d4e6
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 08:52:53 2025 +1100

    Dont' expect a warning when expecting errors

    The error/s will trump (prevent) the warning.

commit 493229d
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 08:48:28 2025 +1100

    Fix compile-time errors for Qt <= 5.12

commit 4be8cd6
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 08:34:23 2025 +1100

    Replace QSKIPs with QEXPECT_FAIL

    Where appropriate.

commit 8369b35
Author: Paul Colby <git@colby.id.au>
Date:   Fri Jan 10 08:33:23 2025 +1100

    Move QSKIPs to data providers

    Where appropriate.
  • Loading branch information
pcolby committed Jan 10, 2025
1 parent 805eed9 commit f68e51d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 59 deletions.
12 changes: 4 additions & 8 deletions test/unit/cli/testabstractcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,13 @@ void TestAbstractCommand::processOptions_timeout()

MockCommand mock;
const int defaultTimeout = mock.discoveryAgent->lowEnergyDiscoveryTimeout(); // eg 20s on Linux.
if (defaultTimeout == -1) {
QSKIP("This platform does not support timeout for BLE device searches.");
// See https://doc.qt.io/qt-5/qbluetoothdevicediscoveryagent.html#lowEnergyDiscoveryTimeout
if ((!expectErrors) && (defaultTimeout == -1)) {
QTest::ignoreMessage(QtWarningMsg, "Platform does not support Bluetooth scan timeout");
}
const QStringList errors = mock.processOptions(parser);
QCOMPARE(!errors.isEmpty(), expectErrors);
if (expectErrors) {
QCOMPARE(mock.discoveryAgent->lowEnergyDiscoveryTimeout(), defaultTimeout);
} else {
QCOMPARE(mock.discoveryAgent->lowEnergyDiscoveryTimeout(), expected);
}
QCOMPARE(mock.discoveryAgent->lowEnergyDiscoveryTimeout(),
((expectErrors || defaultTimeout == -1)) ? defaultTimeout : expected);
}

void TestAbstractCommand::tr()
Expand Down
16 changes: 8 additions & 8 deletions test/unit/cli/testdsocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void TestDsoCommand::supportedOptions()

void TestDsoCommand::processOptions_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<QStringList>("arguments");
QTest::addColumn<DsoService::Settings>("expectedSettings");
QTest::addColumn<minRangeFunc>("expectedMinRangeFunc");
Expand Down Expand Up @@ -368,10 +372,6 @@ void TestDsoCommand::processOptions_data()

void TestDsoCommand::processOptions()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(QStringList, arguments);
QFETCH(DsoService::Settings, expectedSettings);
QFETCH(minRangeFunc, expectedMinRangeFunc);
Expand Down Expand Up @@ -447,6 +447,10 @@ void TestDsoCommand::metadataRead()

void TestDsoCommand::outputSamples_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<DsoService::Metadata>("metadata");
QTest::addColumn<QList<DsoService::Samples>>("samplesList");
QTest::addColumn<AbstractCommand::OutputFormat>("format");
Expand Down Expand Up @@ -492,10 +496,6 @@ void TestDsoCommand::outputSamples_data()

void TestDsoCommand::outputSamples()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(DsoService::Metadata, metadata);
QFETCH(QList<DsoService::Samples>, samplesList);
QFETCH(AbstractCommand::OutputFormat, format);
Expand Down
33 changes: 18 additions & 15 deletions test/unit/cli/testinfocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <qtpokit/pokitdevice.h>

#include <QOperatingSystemVersion>

Q_DECLARE_METATYPE(AbstractCommand::OutputFormat)

class MockDeviceCommand : public DeviceCommand
Expand Down Expand Up @@ -58,6 +60,10 @@ void TestInfoCommand::getService()

void TestInfoCommand::serviceDetailsDiscovered_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<QBluetoothDeviceInfo>("info");
QTest::addColumn<AbstractCommand::OutputFormat>("format");

Expand Down Expand Up @@ -88,32 +94,29 @@ void TestInfoCommand::serviceDetailsDiscovered_data()

void TestInfoCommand::serviceDetailsDiscovered()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(QBluetoothDeviceInfo, info);
QFETCH(AbstractCommand::OutputFormat, format);
LOADTESTDATA(expected);

const OutputStreamCapture capture(&std::cout);
InfoCommand command(this);
command.device = new PokitDevice(info, &command);
command.service = command.device->deviceInformation();
command.format = format;
command.serviceDetailsDiscovered();

#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
if (!info.deviceUuid().isNull()) {
if ((!info.deviceUuid().isNull()) &&
(!(QOperatingSystemVersion::current() <= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 13)))) {
// Fixed (though not called out) by https://bugreports.qt.io/browse/QTBUG-75348
QSKIP("QLowEnergyController fails to track device UUIDs prior to Qt 5.14.");
QEXPECT_FAIL("", "QLowEnergyController fails to track device UUIDs prior to Qt 5.14, except on macOS 13-", Continue);
}
#if defined(Q_OS_MACOS)
if (!info.address().isNull()) {
QSKIP("On macOS, QLowEnergyController fails to track device addresses prior to Qt 5.14.");
else if (!info.address().isNull()) {
QEXPECT_FAIL("", "On macOS, QLowEnergyController fails to track device addresses prior to Qt 5.14.", Continue);
}
#endif // macOS
#endif // < Qt 5.14

const OutputStreamCapture capture(&std::cout);
InfoCommand command(this);
command.device = new PokitDevice(info, &command);
command.service = command.device->deviceInformation();
command.format = format;
command.serviceDetailsDiscovered();
QCOMPARE(QByteArray::fromStdString(capture.data()), expected);
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/cli/testloggerfetchcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void TestLoggerFetchCommand::metadataRead()

void TestLoggerFetchCommand::outputSamples_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<DataLoggerService::Metadata>("metadata");
QTest::addColumn<QList<DataLoggerService::Samples>>("samplesList");
QTest::addColumn<AbstractCommand::OutputFormat>("format");
Expand Down Expand Up @@ -98,10 +102,6 @@ void TestLoggerFetchCommand::outputSamples_data()

void TestLoggerFetchCommand::outputSamples()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(DataLoggerService::Metadata, metadata);
QFETCH(QList<DataLoggerService::Samples>, samplesList);
QFETCH(AbstractCommand::OutputFormat, format);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/cli/testmetercommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ void TestMeterCommand::settingsWritten()

void TestMeterCommand::outputReading_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<QList<MultimeterService::Reading>>("readings");
QTest::addColumn<AbstractCommand::OutputFormat>("format");

Expand Down Expand Up @@ -407,10 +411,6 @@ void TestMeterCommand::outputReading_data()

void TestMeterCommand::outputReading()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(QList<MultimeterService::Reading>, readings);
QFETCH(AbstractCommand::OutputFormat, format);
LOADTESTDATA(expected);
Expand Down
9 changes: 5 additions & 4 deletions test/unit/cli/testscancommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ void TestScanCommand::deviceDiscovered()

void TestScanCommand::deviceUpdated_data()
{
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
QSKIP("Not applicable before Qt version 5.12.");
#endif
deviceDiscovered_data();
}

void TestScanCommand::deviceUpdated()
{
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
QSKIP("Not applicable before Qt version 5.12.");
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
QFETCH(QList<QBluetoothDeviceInfo>, infos);
QFETCH(AbstractCommand::OutputFormat, format);
LOADTESTDATA(expected);
Expand All @@ -150,7 +151,7 @@ void TestScanCommand::deviceUpdated()
command.deviceUpdated(info, QBluetoothDeviceInfo::Fields());
}
QCOMPARE(QByteArray::fromStdString(capture.data()), expected);
#endif
#endif
}

void TestScanCommand::deviceDiscoveryFinished()
Expand Down
8 changes: 4 additions & 4 deletions test/unit/cli/teststatuscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ void TestStatusCommand::serviceDetailsDiscovered()

void TestStatusCommand::outputDeviceStatus_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QTest::addColumn<StatusService::DeviceCharacteristics>("chrs");
QTest::addColumn<AbstractCommand::OutputFormat>("format");

Expand Down Expand Up @@ -103,10 +107,6 @@ void TestStatusCommand::outputDeviceStatus_data()

void TestStatusCommand::outputDeviceStatus()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(StatusService::DeviceCharacteristics, chrs);
QFETCH(AbstractCommand::OutputFormat, format);
LOADTESTDATA(expected);
Expand Down
7 changes: 3 additions & 4 deletions test/unit/lib/testpokitdiscoveryagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ void TestPokitDiscoveryAgent::deviceDiscovered()

void TestPokitDiscoveryAgent::deviceUpdated_data()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
deviceDiscovered_data();
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) // Required signal, and Fields, added in Qt 5.12.
QSKIP("Not applicable before Qt version 5.12.");
#endif
deviceDiscovered_data();
}

void TestPokitDiscoveryAgent::deviceUpdated()
Expand All @@ -80,8 +81,6 @@ void TestPokitDiscoveryAgent::deviceUpdated()
info.setServiceUuids({ uuid } DATA_COMPLETENESS);
service.d_func()->deviceUpdated(info, QBluetoothDeviceInfo::Fields());
QCOMPARE(spy.count(), (expected) ? 1 : 0);
#else
QSKIP("Not applicable before Qt version 5.12.");
#endif
}

Expand Down
14 changes: 6 additions & 8 deletions test/unit/lib/testpokitproducts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ void TestPokitProducts::isPokitProduct_Uuids()

void TestPokitProducts::isPokitProduct_Controller_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}
isPokitProduct_data();
}

void TestPokitProducts::isPokitProduct_Controller()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(QBluetoothUuid, uuid);
QFETCH(bool, expected);

Expand Down Expand Up @@ -160,15 +159,14 @@ void TestPokitProducts::pokitProduct_Uuids()

void TestPokitProducts::pokitProduct_Controller_data()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}
pokitProduct_data();
}

void TestPokitProducts::pokitProduct_Controller()
{
if (gitHubActionsRunnerOsVersion() >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 14)) {
QSKIP("BLE controller operations hang on GitHub Actions's macOS 14 runners");
}

QFETCH(QBluetoothUuid, uuid);
QFETCH(PokitProduct, expected);

Expand Down

0 comments on commit f68e51d

Please sign in to comment.