summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-12-02 15:02:47 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-12-04 14:17:33 +0000
commit38b765206c352cc88123a03025024b3e5e368a4a (patch)
tree189a37106251c87d499b1122bafa1b06ca3a4753 /tests
parentb0a0b2572a5060c268f96a77716e7ea4e3065da4 (diff)
Bluetooth LE: Implement ATT access permissions.
Change-Id: I456d083d45569ea8d61f0a659f72646d653143d1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp8
-rw-r--r--tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp30
2 files changed, 35 insertions, 3 deletions
diff --git a/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp
index ddba0ddb..b1fc7256 100644
--- a/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp
+++ b/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp
@@ -100,7 +100,7 @@ void addGenericAccessService()
charData.setUuid(QBluetoothUuid::Appearance);
charData.setProperties(QLowEnergyCharacteristic::Read);
QByteArray value(2, 0);
- value[0] = -1; // 128 => Generic computer.
+ value[0] = 64; // Generic Phone
charData.setValue(value);
serviceData.addCharacteristic(charData);
@@ -120,6 +120,12 @@ void addCustomService()
charData.setValue(QByteArray(1024, 'x')); // Long value to test "Read Blob".
serviceData.addCharacteristic(charData);
+ charData.setUuid(QBluetoothUuid(quint16(0x5001))); // Made up.
+ charData.setProperties(QLowEnergyCharacteristic::Read);
+ charData.setReadConstraints(QBluetooth::AttAuthorizationRequired); // To test read failure.
+ serviceData.addCharacteristic(charData);
+ charData.setValue("something");
+
addService(serviceData);
}
diff --git a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
index 12d0db17..25098273 100644
--- a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
+++ b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
@@ -46,6 +46,8 @@
#include <algorithm>
+using namespace QBluetooth;
+
class TestQLowEnergyControllerGattServer : public QObject
{
Q_OBJECT
@@ -213,7 +215,7 @@ void TestQLowEnergyControllerGattServer::initialServices()
QCOMPARE(appearanceChar.descriptors().count(), 0);
QCOMPARE(appearanceChar.properties(), QLowEnergyCharacteristic::Read);
QByteArray appearanceValue(2, 0);
- appearanceValue[0] = -1;
+ appearanceValue[0] = 64;
QCOMPARE(appearanceChar.value(), appearanceValue);
const QScopedPointer<QLowEnergyService> runningSpeedService(
@@ -254,12 +256,24 @@ void TestQLowEnergyControllerGattServer::initialServices()
QVERIFY(spy->wait(3000));
}
QCOMPARE(customService->includedServices().count(), 0);
- QCOMPARE(customService->characteristics().count(), 1);
+ QCOMPARE(customService->characteristics().count(), 2);
QLowEnergyCharacteristic customChar
= customService->characteristic(QBluetoothUuid(quint16(0x5000)));
QVERIFY(customChar.isValid());
QCOMPARE(customChar.descriptors().count(), 0);
QCOMPARE(customChar.value(), QByteArray(1024, 'x'));
+
+ QLowEnergyCharacteristic customChar2
+ = customService->characteristic(QBluetoothUuid(quint16(0x5001)));
+ QVERIFY(customChar2.isValid());
+ QCOMPARE(customChar2.descriptors().count(), 0);
+ QCOMPARE(customChar2.value(), QByteArray()); // Was not readable due to authorization requirement.
+
+ customService->writeCharacteristic(customChar, "whatever");
+ spy.reset(new QSignalSpy(customService.data(), static_cast<void (QLowEnergyService::*)
+ (QLowEnergyService::ServiceError)>(&QLowEnergyService::error)));
+ QVERIFY(spy->wait(3000));
+ QCOMPARE(customService->error(), QLowEnergyService::CharacteristicWriteError);
}
void TestQLowEnergyControllerGattServer::controllerType()
@@ -282,6 +296,13 @@ void TestQLowEnergyControllerGattServer::serviceData()
descData.setValue("xyz");
QCOMPARE(descData.value().constData(), "xyz");
+ descData.setReadPermissions(true, AttAuthenticationRequired);
+ QCOMPARE(descData.isReadable(), true);
+ QCOMPARE(descData.readConstraints(), AttAuthenticationRequired);
+
+ descData.setWritePermissions(false);
+ QCOMPARE(descData.isWritable(), false);
+
QLowEnergyDescriptorData descData2(QBluetoothUuid::ReportReference, "abc");
QVERIFY(descData2 != QLowEnergyDescriptorData());
QVERIFY(descData2.isValid());
@@ -304,6 +325,11 @@ void TestQLowEnergyControllerGattServer::serviceData()
charData.setProperties(props);
QCOMPARE(charData.properties(), props);
+ charData.setReadConstraints(AttEncryptionRequired);
+ QCOMPARE(charData.readConstraints(), AttEncryptionRequired);
+ charData.setWriteConstraints(AttAuthenticationRequired | AttAuthorizationRequired);
+ QCOMPARE(charData.writeConstraints(), AttAuthenticationRequired | AttAuthorizationRequired);
+
charData.setDescriptors(QList<QLowEnergyDescriptorData>() << descData << descData2);
QLowEnergyDescriptorData descData3(QBluetoothUuid::ExternalReportReference, "someval");
charData.addDescriptor(descData3);