diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-09-26 08:28:40 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-09-26 08:29:12 +0200 |
commit | c1aabdba2e839ba525a4918eebfbf6fbbe96d34d (patch) | |
tree | d154275f00d6a8cbcf792f298654fb6ab12f6044 /tests/auto | |
parent | dc34c7aae7d4d641f4d06990141c7915542363ee (diff) | |
parent | b7f4825cbf24c357d2f562ecdd81bc5109f4439f (diff) |
Merge branch '5.4' into btle
Change-Id: Ic5f6b510e43afbebc9bb76aa7bcd68a27d4a4a9b
Diffstat (limited to 'tests/auto')
4 files changed, 77 insertions, 9 deletions
diff --git a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp index 89c70854..b2c55da5 100644 --- a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp +++ b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp @@ -235,6 +235,7 @@ void tst_QBluetoothTransferManager::tst_sendFile() QBluetoothTransferReply* reply = manager.put(request, &f); QSignalSpy finishedSpy(reply, SIGNAL(finished(QBluetoothTransferReply*))); QSignalSpy progressSpy(reply, SIGNAL(transferProgress(qint64,qint64))); + QSignalSpy errorSpy(reply, SIGNAL(error(QBluetoothTransferReply::TransferError))); QCOMPARE(reply->request(), request); QVERIFY(reply->manager() == &manager); @@ -253,6 +254,7 @@ void tst_QBluetoothTransferManager::tst_sendFile() QVERIFY(progressSpy.count()>0); QCOMPARE(reply->error(), QBluetoothTransferReply::NoError); QCOMPARE(reply->errorString(), QString()); + QVERIFY(errorSpy.isEmpty()); } else { QVERIFY(progressSpy.count() == 0); if (isInvalidFile) @@ -260,6 +262,7 @@ void tst_QBluetoothTransferManager::tst_sendFile() else QVERIFY(reply->error() != QBluetoothTransferReply::NoError); QVERIFY(!reply->errorString().isEmpty()); + QCOMPARE(errorSpy.count(), 1); } QVERIFY(reply->isFinished()); @@ -274,7 +277,7 @@ void tst_QBluetoothTransferManager::tst_sendBuffer_data() QTest::addColumn<QByteArray>("data"); QTest::newRow("Push to remote test device") << remoteAddress << true << - QByteArray("This is a very long byte arry which we are going to access via a QBuffer"); ; + QByteArray("This is a very long byte array which we are going to access via a QBuffer"); ; QTest::newRow("Push to invalid address") << QBluetoothAddress() << false << QByteArray("test"); QTest::newRow("Push to non-existend device") << QBluetoothAddress("11:22:33:44:55:66") << false << QByteArray("test"); } @@ -310,6 +313,7 @@ void tst_QBluetoothTransferManager::tst_sendBuffer() QBluetoothTransferReply* reply = manager.put(request, &buffer); QSignalSpy finishedSpy(reply, SIGNAL(finished(QBluetoothTransferReply*))); QSignalSpy progressSpy(reply, SIGNAL(transferProgress(qint64,qint64))); + QSignalSpy errorSpy(reply, SIGNAL(error(QBluetoothTransferReply::TransferError))); QCOMPARE(reply->request(), request); QVERIFY(reply->manager() == &manager); @@ -326,12 +330,14 @@ void tst_QBluetoothTransferManager::tst_sendBuffer() QVERIFY(finishedSpy.count()>0); if (expectSuccess) { QVERIFY(progressSpy.count()>0); + QVERIFY(errorSpy.isEmpty()); QCOMPARE(reply->error(), QBluetoothTransferReply::NoError); QCOMPARE(reply->errorString(), QString()); } else { QVERIFY(progressSpy.count() == 0); QVERIFY(reply->error() != QBluetoothTransferReply::NoError); QVERIFY(!reply->errorString().isEmpty()); + QCOMPARE(errorSpy.count(), 1); } QVERIFY(reply->isFinished()); diff --git a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp index 23189f51..e65b573c 100644 --- a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp +++ b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp @@ -116,7 +116,7 @@ void tst_QLowEnergyCharacteristic::initTestCase() qDebug() << "Connecting to" << remoteDevice; controller->connectToDevice(); QTRY_IMPL(controller->state() != QLowEnergyController::ConnectingState, - 10000); + 20000); if (controller->state() != QLowEnergyController::ConnectedState) { // any error and we skip delete controller; diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 84223c91..4af96f3c 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -67,10 +67,9 @@ private slots: void tst_concurrentDiscovery(); void tst_defaultBehavior(); void tst_writeCharacteristic(); + void tst_writeCharacteristicNoResponse(); void tst_writeDescriptor(); - void tst_writeDescriptorNoResponse(); - - + void tst_encryption(); private: void verifyServiceProperties(const QLowEnergyService *info); @@ -113,6 +112,7 @@ void tst_QLowEnergyController::initTestCase() return; } + devAgent = new QBluetoothDeviceDiscoveryAgent(this); QSignalSpy finishedSpy(devAgent, SIGNAL(finished())); @@ -1844,10 +1844,74 @@ 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. */ -void tst_QLowEnergyController::tst_writeDescriptorNoResponse() +void tst_QLowEnergyController::tst_writeCharacteristicNoResponse() { QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices(); if (localAdapters.isEmpty() || remoteDevice.isNull()) @@ -1932,8 +1996,6 @@ void tst_QLowEnergyController::tst_writeDescriptorNoResponse() } // 4. Trigger image identity announcement (using traditional write) - - QByteArray imageAValue, imageBValue; QList<QVariant> entry; bool foundOneImage = false; diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp index e276b2ea..ff958cc6 100644 --- a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp +++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp @@ -119,7 +119,7 @@ void tst_QLowEnergyDescriptor::initTestCase() qDebug() << "Connecting to" << remoteDevice; controller->connectToDevice(); QTRY_IMPL(controller->state() != QLowEnergyController::ConnectingState, - 10000); + 20000); if (controller->state() != QLowEnergyController::ConnectedState) { // any error and we skip delete controller; |