summaryrefslogtreecommitdiffstats
path: root/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
diff options
context:
space:
mode:
authorNedim Hadzic <nhadzic@blackberry.com>2013-10-29 18:10:08 +0100
committerNedim Hadzic <nhadzic@blackberry.com>2013-11-28 16:32:28 +0100
commit8bc9b6f66a67a7b12b2ef8d927fdec83a4c17f58 (patch)
tree7e4d7b809590685c53bb7f96397fac4976fc2afb /tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
parent12ac88fa8d87d8fd86aa86bc009c7a78503648ee (diff)
Implemented Bluetooth Low Energy: autotests
Autotests added for new Bluetooth LE classes. Change-Id: I31742786104df2aa9ec68ec9a82606f1e227c198 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp')
-rw-r--r--tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp99
1 files changed, 96 insertions, 3 deletions
diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
index 1550642b..dc065096 100644
--- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
@@ -51,11 +51,15 @@
#include <qbluetoothlocaldevice.h>
#include <qbluetoothserver.h>
#include <qbluetoothserviceinfo.h>
+#include <qlowenergyserviceinfo.h>
+#include <qlowenergycontroller.h>
+#include <qlowenergycharacteristicinfo.h>
QT_USE_NAMESPACE
Q_DECLARE_METATYPE(QBluetoothDeviceInfo)
Q_DECLARE_METATYPE(QBluetoothServiceDiscoveryAgent::Error)
+Q_DECLARE_METATYPE(QLowEnergyServiceInfo)
// Maximum time to for bluetooth device scan
const int MaxScanTime = 5 * 60 * 1000; // 5 minutes in ms
@@ -71,6 +75,7 @@ public:
public slots:
void deviceDiscoveryDebug(const QBluetoothDeviceInfo &info);
void serviceDiscoveryDebug(const QBluetoothServiceInfo &info);
+ void leServiceDiscoveryDebug(const QLowEnergyServiceInfo &info);
void serviceError(const QBluetoothServiceDiscoveryAgent::Error err);
private slots:
@@ -99,6 +104,7 @@ tst_QBluetoothServiceDiscoveryAgent::tst_QBluetoothServiceDiscoveryAgent()
qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo");
qRegisterMetaType<QBluetoothServiceInfo>("QBluetoothServiceInfo");
+ qRegisterMetaType<QLowEnergyServiceInfo>("QLowEnergyServiceInfo");
qRegisterMetaType<QList<QBluetoothUuid> >("QList<QBluetoothUuid>");
qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>("QBluetoothServiceDiscoveryAgent::Error");
qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::Error>("QBluetoothDeviceDiscoveryAgent::Error");
@@ -161,6 +167,14 @@ void tst_QBluetoothServiceDiscoveryAgent::serviceDiscoveryDebug(const QBluetooth
qDebug() << "\tRFCOMM server channel:" << info.serverChannel();
}
+void tst_QBluetoothServiceDiscoveryAgent::leServiceDiscoveryDebug(const QLowEnergyServiceInfo &info)
+{
+ qDebug() << "Discovered LE service on"
+ << info.device().name() << info.device().address().toString();
+ qDebug() << "\tService name:" << info.name();
+ qDebug() << "\tUUID:" << info.uuid();
+}
+
static void dumpAttributeVariant(const QVariant &var, const QString indent)
{
if (!var.isValid()) {
@@ -297,7 +311,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscoveryAdapters()
QVERIFY(serviceInfo.registerService());
QVERIFY(server.isListening());
- qDebug() << "Scanning address" << addresses[0].toString();
+ qDebug() << "Scanning address " << addresses[0].toString();
QBluetoothServiceDiscoveryAgent discoveryAgent(addresses[1]);
bool setAddress = discoveryAgent.setRemoteAddress(addresses[0]);
@@ -343,9 +357,9 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
QFETCH(QBluetoothDeviceInfo, deviceInfo);
QFETCH(QList<QBluetoothUuid>, uuidFilter);
QFETCH(QBluetoothServiceDiscoveryAgent::Error, serviceDiscoveryError);
-
+ QLowEnergyController leController;
+ bool leDevice = false;
QBluetoothLocalDevice localDevice;
-
qDebug() << "Scanning address" << deviceInfo.address().toString();
QBluetoothServiceDiscoveryAgent discoveryAgent(localDevice.address());
bool setAddress = discoveryAgent.setRemoteAddress(deviceInfo.address());
@@ -365,11 +379,16 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)));
QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)));
+ QSignalSpy leDiscoveredSpy(&discoveryAgent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)));
// connect(&discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
// this, SLOT(serviceDiscoveryDebug(QBluetoothServiceInfo)));
+// connect(&discoveryAgent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)),
+// this, SLOT(leServiceDiscoveryDebug(QLowEnergyServiceInfo)));
connect(&discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
this, SLOT(serviceError(QBluetoothServiceDiscoveryAgent::Error)));
+ QSignalSpy leConnectedSpy(&leController, SIGNAL(connected(QLowEnergyServiceInfo)));
+
discoveryAgent.start();
QVERIFY(discoveryAgent.isActive());
@@ -427,6 +446,80 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
}
}
+ int leCounter = 0;
+ while (!leDiscoveredSpy.isEmpty()) {
+ const QVariant v = leDiscoveredSpy.takeFirst().at(0);
+ if (v.userType() == qMetaTypeId<QLowEnergyServiceInfo>())
+ {
+ const QLowEnergyServiceInfo info =
+ *reinterpret_cast<const QLowEnergyServiceInfo*>(v.constData());
+
+ QVERIFY(info.isValid());
+ if (info.device().coreConfiguration() == QBluetoothDeviceInfo::LowEnergyCoreConfiguration || info.device().coreConfiguration() == QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration) {
+ leDevice = true;
+ leController.connectToService(info);
+ leCounter ++;
+ }
+
+ } else {
+ QFAIL("Unknown type returned by service discovery");
+ }
+
+ }
+
+ // In case it is not LE device next steps will be skipped.
+ // In case of regular Bluetooth devices there is no need to go in to the loop below.
+ if (leDevice) {
+ scanTime = MaxScanTime;
+ while (leConnectedSpy.count() != leCounter && scanTime > 0) {
+ QTest::qWait(1000);
+ scanTime -= 1000;
+ }
+ int leTestCounter = 0;
+ QSignalSpy leDisonnectedSpy(&leController, SIGNAL(disconnected(QLowEnergyServiceInfo)));
+ while (!leConnectedSpy.isEmpty()) {
+ const QVariant v = leConnectedSpy.takeFirst().at(0);
+ if (v.userType() == qMetaTypeId<QLowEnergyServiceInfo>())
+ {
+ const QLowEnergyServiceInfo info =
+ *reinterpret_cast<const QLowEnergyServiceInfo*>(v.constData());
+
+ QVERIFY(info.isValid());
+ QCOMPARE(info.errorString(), QString());
+ QVERIFY((info.characteristics().size() > 0));
+ qDebug() << "LE Service Connected: " << info.name() << info.uuid();
+ leTestCounter++;
+ for (int i = 0; i < info.characteristics().size(); i++)
+ QVERIFY(info.characteristics().at(i).isValid());
+ leController.disconnectFromService(info);
+ } else {
+ QFAIL("Unknown type returned by service discovery");
+ }
+
+ }
+ QCOMPARE(leCounter, leTestCounter);
+ scanTime = MaxScanTime;
+ while (leDisonnectedSpy.count() != leTestCounter && scanTime > 0) {
+ QTest::qWait(1000);
+ scanTime -= 1000;
+ }
+
+ while (!leDisonnectedSpy.isEmpty()) {
+ const QVariant v = leDisonnectedSpy.takeFirst().at(0);
+ if (v.userType() == qMetaTypeId<QLowEnergyServiceInfo>())
+ {
+ const QLowEnergyServiceInfo info =
+ *reinterpret_cast<const QLowEnergyServiceInfo*>(v.constData());
+
+ QVERIFY(info.isValid());
+ QCOMPARE(info.errorString(), QString());
+ qDebug() << "LE Service Disconnected: " << info.name() << info.uuid();
+ } else {
+ QFAIL("Unknown type returned by service discovery");
+ }
+
+ }
+ }
QVERIFY(discoveryAgent.discoveredServices().count() != 0);
discoveryAgent.clear();