summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-21 12:03:41 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-23 15:28:44 +0200
commitf1b1896889dd32d4e304e369844c9764ec49364d (patch)
tree459b417e42ca2369092a6ac171690010e20dc824 /tests
parent45536c645baa22e51be4871308ff872c1ba43dce (diff)
Remove QBluetoothServiceDiscoveryAgent dependency from QLE unit tests
Services cannot always discovered via SDP. Therefore we can only run a device discovery and let QLEController do the service discovery. In addition we add the missing Connection Control service to the QLEController unit test. This service was introduced by a firmware update on the TI SensorTag. Change-Id: I52f172c0c4968c393779cd42275c548998dde8ce Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp26
-rw-r--r--tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp193
-rw-r--r--tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp24
3 files changed, 145 insertions, 98 deletions
diff --git a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
index 0a35b173..9ecddbd5 100644
--- a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
+++ b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
@@ -1,6 +1,7 @@
/***************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -44,9 +45,8 @@
#include <QDebug>
-#include <QBluetoothServiceDiscoveryAgent>
+#include <QBluetoothDeviceDiscoveryAgent>
#include <QLowEnergyCharacteristic>
-#include <QLowEnergyServiceInfo>
#include <QLowEnergyController>
#include <QBluetoothLocalDevice>
@@ -61,7 +61,7 @@ public:
~tst_QLowEnergyCharacteristic();
protected slots:
- void serviceDiscovered(const QLowEnergyServiceInfo &info);
+ void deviceDiscovered(const QBluetoothDeviceInfo &info);
private slots:
void initTestCase();
@@ -70,7 +70,6 @@ private slots:
void tst_assignCompare();
private:
- QBluetoothServiceDiscoveryAgent *agent;
QSet<QString> remoteLeDevices;
QLowEnergyController *globalControl;
QLowEnergyService *globalService;
@@ -99,17 +98,19 @@ void tst_QLowEnergyCharacteristic::initTestCase()
// find an arbitrary low energy device in vincinity
// find an arbitrary service with characteristic
+ QBluetoothDeviceDiscoveryAgent *devAgent = new QBluetoothDeviceDiscoveryAgent(this);
+ connect(devAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
+ this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
- QBluetoothServiceDiscoveryAgent * agent = new QBluetoothServiceDiscoveryAgent(this);
- connect(agent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)),
- SLOT(serviceDiscovered(QLowEnergyServiceInfo)));
+ QSignalSpy errorSpy(devAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy.isEmpty());
- QSignalSpy spy(agent, SIGNAL(finished()));
- // there should be no changes yet
+ QSignalSpy spy(devAgent, SIGNAL(finished()));
QVERIFY(spy.isValid());
QVERIFY(spy.isEmpty());
- agent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
+ devAgent->start();
QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 50000);
// find first service with descriptor
@@ -174,9 +175,10 @@ void tst_QLowEnergyCharacteristic::cleanupTestCase()
globalControl->disconnectFromDevice();
}
-void tst_QLowEnergyCharacteristic::serviceDiscovered(const QLowEnergyServiceInfo &info)
+void tst_QLowEnergyCharacteristic::deviceDiscovered(const QBluetoothDeviceInfo &info)
{
- remoteLeDevices.insert(info.device().address().toString());
+ if (info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
+ remoteLeDevices.insert(info.address().toString());
}
void tst_QLowEnergyCharacteristic::tst_constructionDefault()
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
index 810a8d6a..6b682d8d 100644
--- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
+++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QBluetoothLocalDevice>
-#include <QBluetoothServiceDiscoveryAgent>
+#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothUuid>
#include <QLowEnergyController>
-#include <QLowEnergyServiceInfo>
#include <QLowEnergyCharacteristic>
#include <QDebug>
@@ -69,14 +68,9 @@ public:
tst_QLowEnergyController();
~tst_QLowEnergyController();
-protected slots:
- void discoveryError(QBluetoothServiceDiscoveryAgent::Error error);
- void serviceDiscovered(const QLowEnergyServiceInfo &info);
-
private slots:
void initTestCase();
void cleanupTestCase();
- void tst_verifyAllServices();
void tst_connect();
void tst_concurrentDiscovery();
void tst_defaultBehavior();
@@ -86,20 +80,17 @@ private slots:
private:
void verifyServiceProperties(const QLowEnergyService *info);
- QBluetoothServiceDiscoveryAgent *agent;
+ QBluetoothDeviceDiscoveryAgent *devAgent;
QBluetoothAddress remoteDevice;
- QList<QLowEnergyServiceInfo> foundServices;
+ QList<QBluetoothUuid> foundServices;
};
Q_DECLARE_METATYPE(QLowEnergyCharacteristic)
Q_DECLARE_METATYPE(QLowEnergyDescriptor)
Q_DECLARE_METATYPE(QLowEnergyService::ServiceError)
-Q_DECLARE_METATYPE(QLowEnergyServiceInfo)
-
tst_QLowEnergyController::tst_QLowEnergyController()
{
- qRegisterMetaType<QLowEnergyServiceInfo>();
qRegisterMetaType<QLowEnergyCharacteristic>();
qRegisterMetaType<QLowEnergyDescriptor>();
@@ -118,40 +109,47 @@ tst_QLowEnergyController::~tst_QLowEnergyController()
}
-void tst_QLowEnergyController::discoveryError(QBluetoothServiceDiscoveryAgent::Error /*error*/)
-{
-}
-
-void tst_QLowEnergyController::serviceDiscovered(const QLowEnergyServiceInfo &info)
-{
- foundServices.append(info);
-}
-
void tst_QLowEnergyController::initTestCase()
{
if (remoteDevice.isNull()
|| QBluetoothLocalDevice::allDevices().isEmpty()) {
- qWarning("No remote device found");
+ qWarning("No remote device or local adapter found.");
return;
}
- agent = new QBluetoothServiceDiscoveryAgent(this);
- connect(agent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)),
- SLOT(serviceDiscovered(QLowEnergyServiceInfo)));
- connect(agent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
- SLOT(discoveryError(QBluetoothServiceDiscoveryAgent::Error)));
- agent->setRemoteAddress(remoteDevice);
+ devAgent = new QBluetoothDeviceDiscoveryAgent(this);
- QSignalSpy spy(agent, SIGNAL(finished()));
+ QSignalSpy finishedSpy(devAgent, SIGNAL(finished()));
// there should be no changes yet
- QVERIFY(spy.isValid());
- QVERIFY(spy.isEmpty());
-
-
- agent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
+ QVERIFY(finishedSpy.isValid());
+ QVERIFY(finishedSpy.isEmpty());
+
+ bool deviceFound = false;
+ devAgent->start();
+ QTRY_VERIFY_WITH_TIMEOUT(finishedSpy.count() > 0, 30000);
+ foreach (const QBluetoothDeviceInfo &info, devAgent->discoveredDevices()) {
+ if (info.address() == remoteDevice) {
+ deviceFound = true;
+ break;
+ }
+ }
- QTRY_VERIFY(spy.count() > 0);
- QCOMPARE(12, foundServices.count());
+ QVERIFY2(deviceFound, "Cannot find remote device.");
+
+ // These are the services exported by the TI SensorTag
+ foundServices << QBluetoothUuid(QString("00001800-0000-1000-8000-00805f9b34fb"));
+ foundServices << QBluetoothUuid(QString("00001801-0000-1000-8000-00805f9b34fb"));
+ foundServices << QBluetoothUuid(QString("0000180a-0000-1000-8000-00805f9b34fb"));
+ foundServices << QBluetoothUuid(QString("0000ffe0-0000-1000-8000-00805f9b34fb"));
+ foundServices << QBluetoothUuid(QString("f000aa00-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa10-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa20-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa30-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa40-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa50-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000aa60-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000ccc0-0451-4000-b000-000000000000"));
+ foundServices << QBluetoothUuid(QString("f000ffc0-0451-4000-b000-000000000000"));
}
void tst_QLowEnergyController::cleanupTestCase()
@@ -159,41 +157,6 @@ void tst_QLowEnergyController::cleanupTestCase()
}
-void tst_QLowEnergyController::tst_verifyAllServices()
-{
- QList<QBluetoothUuid> uuids;
- uuids << QBluetoothUuid(QString("00001800-0000-1000-8000-00805f9b34fb"));
- uuids << QBluetoothUuid(QString("00001801-0000-1000-8000-00805f9b34fb"));
- uuids << QBluetoothUuid(QString("0000180a-0000-1000-8000-00805f9b34fb"));
- uuids << QBluetoothUuid(QString("0000ffe0-0000-1000-8000-00805f9b34fb"));
- uuids << QBluetoothUuid(QString("f000aa00-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa10-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa20-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa30-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa40-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa50-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000aa60-0451-4000-b000-000000000000"));
- uuids << QBluetoothUuid(QString("f000ffc0-0451-4000-b000-000000000000"));
-
- foreach (const QLowEnergyServiceInfo &info, foundServices) {
- QVERIFY(uuids.contains(info.serviceUuid()));
- //QVERIFY(!info.isConnected());
- QVERIFY(info.isValid());
- QBluetoothUuid u = info.serviceUuid();
- bool ok = false;
- quint16 clsId = u.toUInt16(&ok);
- if (ok && (clsId & 0x1800) == 0x1800 && clsId < 0x1900) {
- QVERIFY(!info.serviceName().isEmpty());
- } else {
- const QString unknown = info.serviceName();
- QVERIFY2(unknown.isEmpty() || unknown == QStringLiteral("Unknown Service"),
- info.serviceUuid().toString().toLatin1());
- }
-
- QCOMPARE(remoteDevice, info.device().address());
- }
-}
-
void tst_QLowEnergyController::tst_connect()
{
QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices();
@@ -260,12 +223,12 @@ void tst_QLowEnergyController::tst_connect()
listing.append(v.value<QBluetoothUuid>());
}
- foreach (const QLowEnergyServiceInfo &info, foundServices) {
- QVERIFY2(listing.contains(info.serviceUuid()),
- info.serviceUuid().toString().toLatin1());
+ foreach (const QBluetoothUuid &uuid, foundServices) {
+ QVERIFY2(listing.contains(uuid),
+ uuid.toString().toLatin1());
- QLowEnergyService *service = control.createServiceObject(info.serviceUuid());
- QVERIFY2(service, info.serviceUuid().toString().toLatin1());
+ QLowEnergyService *service = control.createServiceObject(uuid);
+ QVERIFY2(service, uuid.toString().toLatin1());
savedReferences.append(service);
QCOMPARE(service->type(), QLowEnergyService::PrimaryService);
QCOMPARE(service->state(), QLowEnergyService::DiscoveryRequired);
@@ -1338,6 +1301,84 @@ void tst_QLowEnergyController::verifyServiceProperties(
QByteArray("5465737420436f6e666967"));
QVERIFY(info->contains(chars[1].descriptors().at(0)));
} else if (info->serviceUuid() ==
+ QBluetoothUuid(QString("f000ccc0-0451-4000-b000-000000000000"))) {
+ qDebug() << "Connection Control Service";
+ QList<QLowEnergyCharacteristic> chars = info->characteristics();
+ QCOMPARE(chars.count(), 3);
+
+ //first characteristic
+ QString temp("f000ccc1-0451-4000-b000-000000000000");
+ QCOMPARE(chars[0].uuid(), QBluetoothUuid(temp));
+ QCOMPARE(chars[0].handle(), QLowEnergyHandle(0x77));
+ QCOMPARE(chars[0].properties(),
+ (QLowEnergyCharacteristic::Notify|QLowEnergyCharacteristic::Read));
+ QCOMPARE(chars[0].value(), QByteArray("000000000000"));
+ QVERIFY(chars[0].isValid());
+ QVERIFY(info->contains(chars[0]));
+
+ QCOMPARE(chars[0].descriptors().count(), 2);
+ //descriptor checks
+ QCOMPARE(chars[0].descriptors().at(0).isValid(), true);
+ QCOMPARE(chars[0].descriptors().at(0).handle(), QLowEnergyHandle(0x78));
+ QCOMPARE(chars[0].descriptors().at(0).uuid(),
+ QBluetoothUuid(QBluetoothUuid::ClientCharacteristicConfiguration));
+ QCOMPARE(chars[0].descriptors().at(0).type(),
+ QBluetoothUuid::ClientCharacteristicConfiguration);
+ // value different in other revisions and test may fail
+ QCOMPARE(chars[0].descriptors().at(0).value(), QByteArray("0100"));
+ QVERIFY(info->contains(chars[0].descriptors().at(0)));
+
+ QCOMPARE(chars[0].descriptors().at(1).isValid(), true);
+ // value different in other revisions and test may fail
+ QCOMPARE(chars[0].descriptors().at(1).handle(), QLowEnergyHandle(0x79));
+ QCOMPARE(chars[0].descriptors().at(1).uuid(),
+ QBluetoothUuid(QBluetoothUuid::CharacteristicUserDescription));
+ QCOMPARE(chars[0].descriptors().at(1).type(),
+ QBluetoothUuid::CharacteristicUserDescription);
+ QCOMPARE(chars[0].descriptors().at(1).value(),
+ QByteArray("436f6e6e2e20506172616d73"));
+ QVERIFY(info->contains(chars[0].descriptors().at(1)));
+
+ //second characteristic
+ temp = QString("f000ccc2-0451-4000-b000-000000000000");
+ QCOMPARE(chars[1].uuid(), QBluetoothUuid(temp));
+ QCOMPARE(chars[1].handle(), QLowEnergyHandle(0x7b));
+ QCOMPARE(chars[1].properties(), QLowEnergyCharacteristic::Write);
+ QCOMPARE(chars[1].value(), QByteArray());
+ QVERIFY(chars[1].isValid());
+ QVERIFY(info->contains(chars[1]));
+
+ QCOMPARE(chars[1].descriptors().count(), 1);
+ QCOMPARE(chars[1].descriptors().at(0).isValid(), true);
+ QCOMPARE(chars[1].descriptors().at(0).handle(), QLowEnergyHandle(0x7c));
+ QCOMPARE(chars[1].descriptors().at(0).uuid(),
+ QBluetoothUuid(QBluetoothUuid::CharacteristicUserDescription));
+ QCOMPARE(chars[1].descriptors().at(0).type(),
+ QBluetoothUuid::CharacteristicUserDescription);
+ QCOMPARE(chars[1].descriptors().at(0).value(),
+ QByteArray("436f6e6e2e20506172616d7320526571"));
+ QVERIFY(info->contains(chars[1].descriptors().at(0)));
+
+ //third characteristic
+ temp = QString("f000ccc3-0451-4000-b000-000000000000");
+ QCOMPARE(chars[2].uuid(), QBluetoothUuid(temp));
+ QCOMPARE(chars[2].handle(), QLowEnergyHandle(0x7e));
+ QCOMPARE(chars[2].properties(), QLowEnergyCharacteristic::Write);
+ QCOMPARE(chars[2].value(), QByteArray());
+ QVERIFY(chars[2].isValid());
+ QVERIFY(info->contains(chars[2]));
+
+ QCOMPARE(chars[2].descriptors().count(), 1);
+ QCOMPARE(chars[2].descriptors().at(0).isValid(), true);
+ QCOMPARE(chars[2].descriptors().at(0).handle(), QLowEnergyHandle(0x7f));
+ QCOMPARE(chars[2].descriptors().at(0).uuid(),
+ QBluetoothUuid(QBluetoothUuid::CharacteristicUserDescription));
+ QCOMPARE(chars[2].descriptors().at(0).type(),
+ QBluetoothUuid::CharacteristicUserDescription);
+ QCOMPARE(chars[2].descriptors().at(0).value(),
+ QByteArray("446973636f6e6e65637420526571"));
+ QVERIFY(info->contains(chars[2].descriptors().at(0)));
+ } else if (info->serviceUuid() ==
QBluetoothUuid(QString("f000ffc0-0451-4000-b000-000000000000"))) {
qDebug() << "Verifying OID Service";
QList<QLowEnergyCharacteristic> chars = info->characteristics();
diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
index 6156f0cf..6de47458 100644
--- a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
+++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
@@ -45,7 +45,7 @@
#include <QDebug>
-#include <QBluetoothServiceDiscoveryAgent>
+#include <QBluetoothDeviceDiscoveryAgent>
#include <QLowEnergyDescriptor>
#include <QLowEnergyController>
#include <QBluetoothLocalDevice>
@@ -61,7 +61,7 @@ public:
~tst_QLowEnergyDescriptor();
protected slots:
- void serviceDiscovered(const QLowEnergyServiceInfo &info);
+ void deviceDiscovered(const QBluetoothDeviceInfo &info);
private slots:
void initTestCase();
@@ -70,7 +70,6 @@ private slots:
void tst_assignCompare();
private:
- QBluetoothServiceDiscoveryAgent *agent;
QSet<QString> remoteLeDevices;
QLowEnergyController *globalControl;
QLowEnergyService *globalService;
@@ -101,16 +100,20 @@ void tst_QLowEnergyDescriptor::initTestCase()
// find an arbitrary low energy device in vincinity
// find an arbitrary service with descriptor
- QBluetoothServiceDiscoveryAgent * agent = new QBluetoothServiceDiscoveryAgent(this);
- connect(agent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)),
- SLOT(serviceDiscovered(QLowEnergyServiceInfo)));
+ QBluetoothDeviceDiscoveryAgent *devAgent = new QBluetoothDeviceDiscoveryAgent(this);
+ connect(devAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
+ this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
- QSignalSpy spy(agent, SIGNAL(finished()));
+ QSignalSpy errorSpy(devAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy.isEmpty());
+
+ QSignalSpy spy(devAgent, SIGNAL(finished()));
// there should be no changes yet
QVERIFY(spy.isValid());
QVERIFY(spy.isEmpty());
- agent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
+ devAgent->start();
QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 50000);
// find first service with descriptor
@@ -175,9 +178,10 @@ void tst_QLowEnergyDescriptor::cleanupTestCase()
globalControl->disconnectFromDevice();
}
-void tst_QLowEnergyDescriptor::serviceDiscovered(const QLowEnergyServiceInfo &info)
+void tst_QLowEnergyDescriptor::deviceDiscovered(const QBluetoothDeviceInfo &info)
{
- remoteLeDevices.insert(info.device().address().toString());
+ if (info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
+ remoteLeDevices.insert(info.address().toString());
}
void tst_QLowEnergyDescriptor::tst_constructionDefault()