summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2016-02-04 16:07:43 +0100
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2016-02-09 16:25:40 +0000
commit547c931904e5251fe79413ba933506a88df0fbbb (patch)
tree896896dc03feb6ede09ce7ea3eab5fdfe0fae209
parenta56a776d4199568657f10248d387c87e40c508fc (diff)
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 <alexander.blasche@theqtcompany.com>
-rw-r--r--src/bluetooth/qlowenergycharacteristicdata.cpp1
-rw-r--r--src/bluetooth/qlowenergyservicedata.cpp1
-rw-r--r--tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp8
3 files changed, 10 insertions, 0 deletions
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<QLowEnergyDescriptorData> QLowEnergyCharacteristicData::descriptors() cons
*/
void QLowEnergyCharacteristicData::setDescriptors(const QList<QLowEnergyDescriptorData> &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<QLowEnergyCharacteristicData> QLowEnergyServiceData::characteristics() con
*/
void QLowEnergyServiceData::setCharacteristics(const QList<QLowEnergyCharacteristicData> &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<QLowEnergyDescriptorData>());
+ QCOMPARE(charData.descriptors().count(), 0);
charData.setDescriptors(QList<QLowEnergyDescriptorData>() << 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<QLowEnergyCharacteristicData>());
+ QCOMPARE(secondaryData.characteristics().count(), 0);
secondaryData.setCharacteristics(QList<QLowEnergyCharacteristicData>()
<< charData << QLowEnergyCharacteristicData());
QCOMPARE(secondaryData.characteristics(), QList<QLowEnergyCharacteristicData>() << charData);