From 330efe20f7e97caf0162ae29b940508f95c0e3c5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 7 Apr 2022 13:16:42 +0200 Subject: Replace count() comparisons against 0 with isEmpty() Pick-to: 6.3 Change-Id: I0a14c1737cda87fa30d207bdf5b2a697214b7e70 Reviewed-by: Alex Blasche Reviewed-by: Qt CI Bot --- .../tst_qbluetoothdevicediscoveryagent.cpp | 20 ++++++++++---------- .../tst_qbluetoothdeviceinfo.cpp | 4 ++-- .../tst_qbluetoothlocaldevice.cpp | 12 ++++++------ .../auto/qbluetoothserver/tst_qbluetoothserver.cpp | 6 +++--- .../tst_qbluetoothservicediscoveryagent.cpp | 14 +++++++------- .../tst_qbluetoothserviceinfo.cpp | 2 +- .../auto/qbluetoothsocket/tst_qbluetoothsocket.cpp | 22 +++++++++++----------- .../tst_qlowenergycharacteristic.cpp | 6 +++--- .../test/tst_qlowenergycontroller-gattserver.cpp | 2 +- .../tst_qlowenergycontroller.cpp | 2 +- .../tst_qlowenergycontroller_device.cpp | 2 +- 11 files changed, 46 insertions(+), 46 deletions(-) (limited to 'tests') diff --git a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp index adea75bd..80dd1e6f 100644 --- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp +++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp @@ -109,11 +109,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 @@ -134,7 +134,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_invalidBtAddress() discoveryAgent = new QBluetoothDeviceDiscoveryAgent(QBluetoothAddress()); QCOMPARE(discoveryAgent->error(), QBluetoothDeviceDiscoveryAgent::NoError); - if (QBluetoothLocalDevice::allDevices().count() > 0) { + if (!QBluetoothLocalDevice::allDevices().isEmpty()) { discoveryAgent->start(); QCOMPARE(discoveryAgent->isActive(), true); } @@ -182,7 +182,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() // Wait for up to MaxWaitForCancelTime for the cancel to finish int waitTime = MaxWaitForCancelTime; - while (cancelSpy.count() == 0 && waitTime > 0) { + while (cancelSpy.isEmpty() && waitTime > 0) { QTest::qWait(100); waitTime-=100; } @@ -206,7 +206,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() // Wait for up to MaxWaitForCancelTime for the cancel to finish waitTime = MaxWaitForCancelTime; - while (cancelSpy.count() == 0 && waitTime > 0) { + while (cancelSpy.isEmpty() && waitTime > 0) { QTest::qWait(100); waitTime-=100; } @@ -223,7 +223,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()); @@ -260,7 +260,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() // Wait for up to MaxWaitForCancelTime for the cancel to finish waitTime = MaxWaitForCancelTime; - while (cancelSpy.count() == 0 && waitTime > 0) { + while (cancelSpy.isEmpty() && waitTime > 0) { QTest::qWait(100); waitTime-=100; } @@ -289,7 +289,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() // Wait for up to MaxScanTime for the cancel to finish waitTime = MaxScanTime; - while (finishedSpy.count() == 0 && waitTime > 0) { + while (finishedSpy.isEmpty() && waitTime > 0) { QTest::qWait(1000); waitTime-=1000; } @@ -344,7 +344,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; } @@ -378,7 +378,7 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_deviceDiscovery() } if (!remoteDevice.isNull()) - QVERIFY(discoveredSpy.count() > 0); + QVERIFY(!discoveredSpy.isEmpty()); // All returned QBluetoothDeviceInfo should be valid. while (!discoveredSpy.isEmpty()) { const QBluetoothDeviceInfo info = diff --git a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp index 689d1052..25c6218f 100644 --- a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp +++ b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp @@ -452,10 +452,10 @@ void tst_QBluetoothDeviceInfo::tst_serviceUuids() QList servicesList; servicesList.append(QBluetoothUuid::ProtocolUuid::L2cap); servicesList.append(QBluetoothUuid::ProtocolUuid::Rfcomm); - QVERIFY(servicesList.count() > 0); + QVERIFY(!servicesList.isEmpty()); deviceInfo.setServiceUuids(servicesList); - QVERIFY(deviceInfo.serviceUuids().count() > 0); + QVERIFY(!deviceInfo.serviceUuids().isEmpty()); deviceInfo.setServiceUuids(QList()); QCOMPARE(deviceInfo.serviceUuids().count(), 0); } diff --git a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp index 269dc0fe..32e272af 100644 --- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp +++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp @@ -130,7 +130,7 @@ void tst_QBluetoothLocalDevice::tst_powerOn() localDevice.powerOn(); // async, wait for it - QTRY_VERIFY(hostModeSpy.count() > 0); + QTRY_VERIFY(!hostModeSpy.isEmpty()); QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode(); // we should not be powered off QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable @@ -164,7 +164,7 @@ void tst_QBluetoothLocalDevice::tst_powerOff() localDevice.setHostMode(QBluetoothLocalDevice::HostPoweredOff); // async, wait for it - QTRY_VERIFY(hostModeSpy.count() > 0); + QTRY_VERIFY(!hostModeSpy.isEmpty()); // we should not be powered off QVERIFY(localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff); @@ -214,13 +214,13 @@ void tst_QBluetoothLocalDevice::tst_hostModes() // wait for the device to switch bluetooth mode. QTest::qWait(1000); if (hostModeExpected != localDevice.hostMode()) { - QTRY_VERIFY(hostModeSpy.count() > 0); + QTRY_VERIFY(!hostModeSpy.isEmpty()); } // test the actual signal values. if (expectSignal) - QVERIFY(hostModeSpy.count() > 0); + QVERIFY(!hostModeSpy.isEmpty()); else - QVERIFY(hostModeSpy.count() == 0); + QVERIFY(hostModeSpy.isEmpty()); if (expectSignal) { QList arguments = hostModeSpy.takeLast(); @@ -262,7 +262,7 @@ void tst_QBluetoothLocalDevice::tst_isValid() QBluetoothAddress invalidAddress("FF:FF:FF:FF:FF:FF"); const QList devices = QBluetoothLocalDevice::allDevices(); - if (devices.count()) { + if (!devices.isEmpty()) { QVERIFY(localDevice.isValid()); bool defaultFound = false; for (int i = 0; i 0) { + while (hostModeSpy.isEmpty() && connectTime > 0) { QTest::qWait(500); connectTime -= 500; } @@ -204,7 +204,7 @@ void tst_QBluetoothServer::tst_receive() 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); @@ -218,7 +218,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); diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp index 3a58de2a..e1ef9591 100644 --- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp +++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp @@ -127,7 +127,7 @@ void tst_QBluetoothServiceDiscoveryAgent::initTestCase() // 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(1000); scanTime -= 1000; } @@ -177,7 +177,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_invalidBtAddress() discoveryAgent = new QBluetoothServiceDiscoveryAgent(QBluetoothAddress()); QCOMPARE(discoveryAgent->error(), QBluetoothServiceDiscoveryAgent::NoError); - if (QBluetoothLocalDevice::allDevices().count() > 0) { + if (!QBluetoothLocalDevice::allDevices().isEmpty()) { discoveryAgent->start(); QCOMPARE(discoveryAgent->isActive(), true); } @@ -352,7 +352,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscoveryAdapters() discoveryAgent.start(); int scanTime = MaxScanTime; - while (finishedSpy.count() == 0 && scanTime > 0) { + while (finishedSpy.isEmpty() && scanTime > 0) { QTest::qWait(1000); scanTime -= 1000; } @@ -416,7 +416,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery() // Wait for up to MaxScanTime for the scan to finish int scanTime = 20000; - while (finishedSpy.count() == 0 && scanTime > 0) { + while (finishedSpy.isEmpty() && scanTime > 0) { QTest::qWait(1000); scanTime -= 1000; } @@ -435,7 +435,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery() QVERIFY(errorSpy.isEmpty()); - //if (discoveryAgent.discoveredServices().count() && expected_failures++ <2){ + //if (!discoveryAgent.discoveredServices().isEmpty() && expected_failures++ <2){ if (discoveredSpy.isEmpty()) { qDebug() << "Device failed to return any results, skipping device" << discoveryAgent.discoveredServices().count(); return; @@ -472,9 +472,9 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery() } if (servicesFound) - QVERIFY(discoveryAgent.discoveredServices().count() != 0); + QVERIFY(!discoveryAgent.discoveredServices().isEmpty()); discoveryAgent.clear(); - QVERIFY(discoveryAgent.discoveredServices().count() == 0); + QVERIFY(discoveryAgent.discoveredServices().isEmpty()); discoveryAgent.stop(); QVERIFY(!discoveryAgent.isActive()); diff --git a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp index 4317c8cb..65194909 100644 --- a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp +++ b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp @@ -282,7 +282,7 @@ void tst_QBluetoothServiceInfo::tst_assignment() copyInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, QBluetoothUuid(uuid)); QVERIFY(copyInfo.contains(QBluetoothServiceInfo::ProtocolDescriptorList)); QVERIFY(copyInfo.isComplete()); - QVERIFY(copyInfo.attributes().count() > 0); + QVERIFY(!copyInfo.attributes().isEmpty()); copyInfo.removeAttribute(QBluetoothServiceInfo::ProtocolDescriptorList); QVERIFY(!copyInfo.contains(QBluetoothServiceInfo::ProtocolDescriptorList)); diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp index 7fdae313..24f3ae4c 100644 --- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp +++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp @@ -118,7 +118,7 @@ void tst_QBluetoothSocket::initTestCase() { // setup Bluetooth env const QList foundDevices = QBluetoothLocalDevice::allDevices(); - if (!foundDevices.count()) { + if (foundDevices.isEmpty()) { qWarning() << "Missing local device"; return; } else { @@ -264,12 +264,12 @@ void tst_QBluetoothSocket::tst_serviceConnection() 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"); } @@ -305,11 +305,11 @@ void tst_QBluetoothSocket::tst_serviceConnection() QCOMPARE(socket.isOpen(), false); QCOMPARE(socket.openMode(), QIODevice::NotOpen); - QVERIFY(stateSpy.count() >= 1); + QVERIFY(!stateSpy.isEmpty()); QCOMPARE(stateSpy.takeFirst().at(0).value(), QBluetoothSocket::SocketState::ClosingState); int disconnectTime = MaxConnectTime; - while (disconnectedSpy.count() == 0 && disconnectTime > 0) { + while (disconnectedSpy.isEmpty() && disconnectTime > 0) { QTest::qWait(1000); disconnectTime -= 1000; } @@ -365,7 +365,7 @@ void tst_QBluetoothSocket::tst_clientCommunication() stateSpy.clear(); int connectTime = MaxConnectTime; - while (connectedSpy.count() == 0 && connectTime > 0) { + while (connectedSpy.isEmpty() && connectTime > 0) { QTest::qWait(1000); connectTime -= 1000; } @@ -401,7 +401,7 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(dataWritten, qint64(line.length())); int readWriteTime = MaxReadWriteTime; - while ((bytesWrittenSpy.count() == 0 || readyReadSpy.count() == 0) && readWriteTime > 0) { + while ((bytesWrittenSpy.isEmpty() || readyReadSpy.isEmpty()) && readWriteTime > 0) { QTest::qWait(1000); readWriteTime -= 1000; } @@ -410,7 +410,7 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(line.length())); readWriteTime = MaxReadWriteTime; - while ((readyReadSpy.count() == 0) && readWriteTime > 0) { + while (readyReadSpy.isEmpty() && readWriteTime > 0) { QTest::qWait(1000); readWriteTime -= 1000; } @@ -450,14 +450,14 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(dataWritten, qint64(joined.length())); 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); + QVERIFY(!readyReadSpy.isEmpty()); if (socket.openMode() & QIODevice::Unbuffered) QVERIFY(socket.bytesAvailable() <= qint64(joined.length())); @@ -482,7 +482,7 @@ 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; } diff --git a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp index 27a89dd6..125aa3dd 100644 --- a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp +++ b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp @@ -113,7 +113,7 @@ void tst_QLowEnergyCharacteristic::initTestCase() QVERIFY(spy.isEmpty()); devAgent->start(); - QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 100000); + QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty(), 100000); // find first service with descriptor QLowEnergyController *controller = 0; @@ -263,7 +263,7 @@ void tst_QLowEnergyCharacteristic::tst_assignCompare() globalService->characteristic(chars[i].uuid()); QVERIFY(specific.isValid()); QCOMPARE(specific, chars[i]); - if (chars[i].descriptors().count() > 0) { + if (!chars[i].descriptors().isEmpty()) { indexWithDescriptor = i; break; } @@ -285,7 +285,7 @@ void tst_QLowEnergyCharacteristic::tst_assignCompare() if (target.properties() & QLowEnergyCharacteristic::Read) QVERIFY(!target.value().isEmpty()); if (!noDescriptors) - QVERIFY(target.descriptors().count() > 0); + QVERIFY(!target.descriptors().isEmpty()); QVERIFY(target == chars[indexWithDescriptor]); QVERIFY(chars[indexWithDescriptor] == target); diff --git a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp index 6a949d86..9b0249d9 100644 --- a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp +++ b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp @@ -448,7 +448,7 @@ void TestQLowEnergyControllerGattServer::serverCommunication() customService->writeCharacteristic(customChar5, "1", QLowEnergyService::WriteSigned); // error might happen immediately or once event loop comes back - bool wasError = ((spy->count() > 0) || spy->wait(3000)); // + bool wasError = (!spy->isEmpty() || spy->wait(3000)); // if (!wasError) { // Signed write is done twice to test the sign counter stuff. diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 3afb78b3..5b7e1c9e 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -144,7 +144,7 @@ void tst_QLowEnergyController::initTestCase() bool deviceFound = false; devAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); - QTRY_VERIFY_WITH_TIMEOUT(finishedSpy.count() > 0, 30000); + QTRY_VERIFY_WITH_TIMEOUT(!finishedSpy.isEmpty(), 30000); const QList infos = devAgent->discoveredDevices(); for (const QBluetoothDeviceInfo &info : infos) { #ifndef Q_OS_MAC diff --git a/tests/manual/qlowenergycontroller/tst_qlowenergycontroller_device.cpp b/tests/manual/qlowenergycontroller/tst_qlowenergycontroller_device.cpp index d24ceffc..7c8b67ec 100644 --- a/tests/manual/qlowenergycontroller/tst_qlowenergycontroller_device.cpp +++ b/tests/manual/qlowenergycontroller/tst_qlowenergycontroller_device.cpp @@ -164,7 +164,7 @@ void tst_qlowenergycontroller_device::discoverTestServer() // Start device discovery mDevAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); - QTRY_VERIFY_WITH_TIMEOUT(finishedSpy.count() > 0 || canceledSpy.count() > 0, 80000); + QTRY_VERIFY_WITH_TIMEOUT(!finishedSpy.isEmpty() || !canceledSpy.isEmpty(), 80000); // Verify that we have found a matching server device bool deviceFound = false; -- cgit v1.2.3