From 547c931904e5251fe79413ba933506a88df0fbbb Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 4 Feb 2016 16:07:43 +0100 Subject: Bluetooth LE: Fix two list setter functions. Adding the new list elements is all well and nice, but we have to clear the existing ones first. Change-Id: I1b044f2ea86a4a300bde93535a944c18328aa805 Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycharacteristicdata.cpp | 1 + src/bluetooth/qlowenergyservicedata.cpp | 1 + .../test/tst_qlowenergycontroller-gattserver.cpp | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/src/bluetooth/qlowenergycharacteristicdata.cpp b/src/bluetooth/qlowenergycharacteristicdata.cpp index 03f61762..9e0d69ad 100644 --- a/src/bluetooth/qlowenergycharacteristicdata.cpp +++ b/src/bluetooth/qlowenergycharacteristicdata.cpp @@ -156,6 +156,7 @@ QList QLowEnergyCharacteristicData::descriptors() cons */ void QLowEnergyCharacteristicData::setDescriptors(const QList &descriptors) { + d->descriptors.clear(); foreach (const QLowEnergyDescriptorData &desc, descriptors) addDescriptor(desc); } diff --git a/src/bluetooth/qlowenergyservicedata.cpp b/src/bluetooth/qlowenergyservicedata.cpp index 94be1237..17f984a6 100644 --- a/src/bluetooth/qlowenergyservicedata.cpp +++ b/src/bluetooth/qlowenergyservicedata.cpp @@ -167,6 +167,7 @@ QList QLowEnergyServiceData::characteristics() con */ void QLowEnergyServiceData::setCharacteristics(const QList &characteristics) { + d->characteristics.clear(); foreach (const QLowEnergyCharacteristicData &cd, characteristics) addCharacteristic(cd); } diff --git a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp index 5acffcab..8b11e5a7 100644 --- a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp +++ b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp @@ -500,6 +500,10 @@ void TestQLowEnergyControllerGattServer::serviceData() charData.setWriteConstraints(AttAuthenticationRequired | AttAuthorizationRequired); QCOMPARE(charData.writeConstraints(), AttAuthenticationRequired | AttAuthorizationRequired); + charData.addDescriptor(descData); + QCOMPARE(charData.descriptors().count(), 1); + charData.setDescriptors(QList()); + QCOMPARE(charData.descriptors().count(), 0); charData.setDescriptors(QList() << descData << descData2); QLowEnergyDescriptorData descData3(QBluetoothUuid::ExternalReportReference, "someval"); charData.addDescriptor(descData3); @@ -518,6 +522,10 @@ void TestQLowEnergyControllerGattServer::serviceData() secondaryData.setType(QLowEnergyServiceData::ServiceTypeSecondary); QCOMPARE(secondaryData.type(), QLowEnergyServiceData::ServiceTypeSecondary); + secondaryData.addCharacteristic(charData); + QCOMPARE(secondaryData.characteristics().count(), 1); + secondaryData.setCharacteristics(QList()); + QCOMPARE(secondaryData.characteristics().count(), 0); secondaryData.setCharacteristics(QList() << charData << QLowEnergyCharacteristicData()); QCOMPARE(secondaryData.characteristics(), QList() << charData); -- cgit v1.2.3