diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-06-18 12:24:09 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-06-19 11:11:24 +0200 |
commit | 243db8a80ff4cfeba5eda13f900fd11e1144e367 (patch) | |
tree | 754db9ebff4ae081b3f5b47ebee301cc352dcfb6 /tests | |
parent | 6014943db4b72962731a90c09a1b476af8385c29 (diff) |
Connect QLowEnergyService and QLowEnergyControllerNew classes
Ensures that the two classes have sufficient references to each other.
When the controller disconnects the related QLES classes should become
invalid.
Introduces an error flag for QLowEnergyService.
Change-Id: I28aee49e45f93c68c4ac69a5e489c0a3cc33dbf5
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 5792d6d2..6d45bfda 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -794,28 +794,33 @@ void tst_QLowEnergyController::tst_connectNew() QVERIFY(control.services().isEmpty()); - QSignalSpy discoveryFinishedSpy(&control, SIGNAL(discoveryFinished())); - QSignalSpy serviceFoundSpy(&control, SIGNAL(serviceDiscovered(QBluetoothUuid))); - control.discoverServices(); - QTRY_VERIFY_WITH_TIMEOUT(discoveryFinishedSpy.count() == 1, 10000); - - QCOMPARE(serviceFoundSpy.count(), foundServices.count()); - QList<QBluetoothUuid> listing; - for (int i = 0; i < serviceFoundSpy.count(); i++) { - const QVariant v = serviceFoundSpy[i].at(0); - listing.append(v.value<QBluetoothUuid>()); - } + QList<QSharedPointer<QLowEnergyService> > savedReferences; + + if (!wasError) { + QSignalSpy discoveryFinishedSpy(&control, SIGNAL(discoveryFinished())); + QSignalSpy serviceFoundSpy(&control, SIGNAL(serviceDiscovered(QBluetoothUuid))); + control.discoverServices(); + QTRY_VERIFY_WITH_TIMEOUT(discoveryFinishedSpy.count() == 1, 10000); + + QCOMPARE(serviceFoundSpy.count(), foundServices.count()); + QList<QBluetoothUuid> listing; + for (int i = 0; i < serviceFoundSpy.count(); i++) { + const QVariant v = serviceFoundSpy[i].at(0); + listing.append(v.value<QBluetoothUuid>()); + } - foreach (const QLowEnergyServiceInfo &info, foundServices) { - QVERIFY2(listing.contains(info.serviceUuid()), - info.serviceUuid().toString().toLatin1()); - } + foreach (const QLowEnergyServiceInfo &info, foundServices) { + QVERIFY2(listing.contains(info.serviceUuid()), + info.serviceUuid().toString().toLatin1()); + } - foreach (const QSharedPointer<QLowEnergyService> &entry, control.services()) { - const QBluetoothUuid &uuid = entry.data()->serviceUuid(); - QVERIFY2(listing.contains(uuid), uuid.toString().toLatin1()); - QCOMPARE(entry.data()->type(), QLowEnergyService::PrimaryService); - QCOMPARE(entry.data()->state(), QLowEnergyService::DiscoveryRequired); + savedReferences = control.services(); + foreach (const QSharedPointer<QLowEnergyService> &entry, savedReferences) { + const QBluetoothUuid &uuid = entry.data()->serviceUuid(); + QVERIFY2(listing.contains(uuid), uuid.toString().toLatin1()); + QCOMPARE(entry.data()->type(), QLowEnergyService::PrimaryService); + QCOMPARE(entry.data()->state(), QLowEnergyService::DiscoveryRequired); + } } // Finish off @@ -824,10 +829,18 @@ void tst_QLowEnergyController::tst_connectNew() control.state() == QLowEnergyControllerNew::UnconnectedState, 10000); - if (wasError) + if (wasError) { QCOMPARE(disconnectedSpy.count(), 0); - else + } else { QCOMPARE(disconnectedSpy.count(), 1); + + // after disconnect all service references must be invalid + foreach (const QSharedPointer<QLowEnergyService> &entry, savedReferences) { + const QBluetoothUuid &uuid = entry.data()->serviceUuid(); + QVERIFY2(entry.data()->state() == QLowEnergyService::InvalidService, + uuid.toString().toLatin1()); + } + } } void tst_QLowEnergyController::tst_defaultBehavior() |