diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-04-02 09:14:06 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-04-15 05:44:38 +0000 |
commit | 5c13863d16ed1d54e4d4dfe25b9684425c8c03d5 (patch) | |
tree | 72580fd4f3fd30a39c7705b5a6bf187338900bf6 | |
parent | e2e00f89b1ef52fcd18cf89e1205c761ec538393 (diff) |
Add tests for QLEService::readDescriptor()
Change-Id: I84f6d76e89036d29f14f8ca326f3fa26e626ff63
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
-rw-r--r-- | tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 495af83c..8ef475a2 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -84,7 +84,7 @@ private slots: void tst_defaultBehavior(); void tst_writeCharacteristic(); void tst_writeCharacteristicNoResponse(); - void tst_writeDescriptor(); + void tst_readWriteDescriptor(); void tst_customProgrammableDevice(); void tst_errorCases(); private: @@ -1831,7 +1831,7 @@ void tst_QLowEnergyController::tst_writeCharacteristic() delete service; } -void tst_QLowEnergyController::tst_writeDescriptor() +void tst_QLowEnergyController::tst_readWriteDescriptor() { #ifndef Q_OS_MAC QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices(); @@ -1910,9 +1910,11 @@ void tst_QLowEnergyController::tst_writeDescriptor() QCOMPARE(tempConfig.value(), QByteArray::fromHex("00")); } - // 3. Test writing to descriptor -> activate notifications + // 3. Test reading and writing to descriptor -> activate notifications QSignalSpy descWrittenSpy(service, SIGNAL(descriptorWritten(QLowEnergyDescriptor,QByteArray))); + QSignalSpy descReadSpy(service, + SIGNAL(descriptorRead(QLowEnergyDescriptor,QByteArray))); QSignalSpy charWrittenSpy(service, SIGNAL(characteristicWritten(QLowEnergyCharacteristic,QByteArray))); QSignalSpy charChangedSpy(service, @@ -1971,7 +1973,19 @@ void tst_QLowEnergyController::tst_writeDescriptor() service->writeCharacteristic(tempConfig, QByteArray::fromHex("00")); } - // 5. Test writing to descriptor -> deactivate notifications + // 5. Test reading and writing of/to descriptor -> deactivate notifications + + service->readDescriptor(notification); + QTRY_VERIFY_WITH_TIMEOUT(!descReadSpy.isEmpty(), 3000); + QCOMPARE(descReadSpy.count(), 1); + firstSignalData = descReadSpy.first(); + signalDesc = firstSignalData[0].value<QLowEnergyDescriptor>(); + signalValue = firstSignalData[1].toByteArray(); + QCOMPARE(signalValue, notification.value()); + QCOMPARE(notification.value(), QByteArray::fromHex("0100")); + descReadSpy.clear(); + + service->writeDescriptor(notification, QByteArray::fromHex("0000")); // verify QTRY_VERIFY_WITH_TIMEOUT(!descWrittenSpy.isEmpty(), 3000); @@ -2003,6 +2017,19 @@ void tst_QLowEnergyController::tst_writeDescriptor() QVERIFY(notification == signalDesc); } + + // 5. Test reading and writing of/to descriptor -> deactivate notifications + + service->readDescriptor(notification); + QTRY_VERIFY_WITH_TIMEOUT(!descReadSpy.isEmpty(), 3000); + QCOMPARE(descReadSpy.count(), 1); + firstSignalData = descReadSpy.first(); + signalDesc = firstSignalData[0].value<QLowEnergyDescriptor>(); + signalValue = firstSignalData[1].toByteArray(); + QCOMPARE(signalValue, notification.value()); + QCOMPARE(notification.value(), QByteArray::fromHex("0000")); + descReadSpy.clear(); + descWrittenSpy.clear(); // ******************************************* |