diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-09-10 12:10:25 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-09-16 08:59:10 +0200 |
commit | 27abf796987c137d2660efd8e73b0e0fc8ffad0c (patch) | |
tree | 0bc4d4715b83f11cf4845e38e3074a6e039f9ffd /tests | |
parent | 3d87d02970237c9e7a8ef8d921702bcc755130c0 (diff) |
Upgrade ATT reads requests to encrypted links when indicated
This is triggered if the GATT
server complains about missing authorization/encryption
when reading an attribute.
The same mechanism has to be applied to all remaining
read and write types
Change-Id: Ia8330951ffdc61afb98424557bbeffe444e9a812
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index b5e9dd31..4af96f3c 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -69,7 +69,7 @@ private slots: void tst_writeCharacteristic(); void tst_writeCharacteristicNoResponse(); void tst_writeDescriptor(); - + void tst_encryption(); private: void verifyServiceProperties(const QLowEnergyService *info); @@ -1844,6 +1844,70 @@ void tst_QLowEnergyController::tst_writeDescriptor() } /* + * Tests encrypted read/write. + * This test is semi manual as the test device environment is very specific. + * Adjust the various uuids and addresses at the top to cater for the current + * situation. By default this test is skipped. + */ +void tst_QLowEnergyController::tst_encryption() +{ + QSKIP("Skipping encryption"); + + //Adjust the uuids and device address as see fit to match + //values that match the current test environment + //The target characteristic must be readble and writable + //under encryption to test dynamic switching of security level + QBluetoothAddress encryptedDevice(QString("00:02:5B:00:15:10")); + QBluetoothUuid serviceUuid(QBluetoothUuid::GenericAccess); + QBluetoothUuid characterristicUuid(QBluetoothUuid::DeviceName); + + QLowEnergyController control(encryptedDevice); + QCOMPARE(control.error(), QLowEnergyController::NoError); + + control.connectToDevice(); + { + QTRY_IMPL(control.state() != QLowEnergyController::ConnectingState, + 30000); + } + + if (control.state() == QLowEnergyController::ConnectingState + || control.error() != QLowEnergyController::NoError) { + // default BTLE backend forever hangs in ConnectingState + QSKIP("Cannot connect to remote device"); + } + + QCOMPARE(control.state(), QLowEnergyController::ConnectedState); + QSignalSpy discoveryFinishedSpy(&control, SIGNAL(discoveryFinished())); + QSignalSpy stateSpy(&control, SIGNAL(stateChanged(QLowEnergyController::ControllerState))); + control.discoverServices(); + QTRY_VERIFY_WITH_TIMEOUT(discoveryFinishedSpy.count() == 1, 10000); + QCOMPARE(stateSpy.count(), 2); + QCOMPARE(stateSpy.at(0).at(0).value<QLowEnergyController::ControllerState>(), + QLowEnergyController::DiscoveringState); + QCOMPARE(stateSpy.at(1).at(0).value<QLowEnergyController::ControllerState>(), + QLowEnergyController::DiscoveredState); + + QList<QBluetoothUuid> uuids = control.services(); + QVERIFY(uuids.contains(serviceUuid)); + + QLowEnergyService *service = control.createServiceObject(serviceUuid, this); + QVERIFY(service); + service->discoverDetails(); + QTRY_VERIFY_WITH_TIMEOUT( + service->state() == QLowEnergyService::ServiceDiscovered, 30000); + + QLowEnergyCharacteristic characteristic = service->characteristic( + characterristicUuid); + + QVERIFY(characteristic.isValid()); + qDebug() << "Encrypted char value:" << characteristic.value().toHex() << characteristic.value(); + QVERIFY(!characteristic.value().isEmpty()); + + delete service; + control.disconnectFromDevice(); +} + +/* Tests write without responses. We utilize the Over-The-Air image update service of the SensorTag. */ |