diff options
author | Nedim Hadzic <nhadzic@blackberry.com> | 2013-08-29 12:46:56 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-05 10:23:47 +0200 |
commit | ecb93e0f63f317039c0bba2c6c754c67b80a9d5e (patch) | |
tree | b98cc16f8d5416e4dabc9dce101ab068136cecf5 /tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp | |
parent | fcb5d4d992b660305c764d54ee70d977c0833602 (diff) |
Make Bluetooth adapter choosable for device and service search
In case there are more Bluetooth adapter, device and service search
might give different results.
Addition to Change-Id: Ideddb39460985c18547baec986b15e43946c85de - added option
for setting the device adapter for service search. QBluetoothLocalDevice was used
in both classes (device and service search) for passing an argument for setting
adapter. The reason for this to keep the same approach, because in
QBluetoothServiceDiscoveryAgent class there is already a constructor
with QBluetoothAddress argument.
Auto tests and examples updated.
Change-Id: Ib5d7ff23e4846d9d42dae68d8d424031748811e5
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.cpp | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp index 2ab0326c..ec5ff840 100644 --- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp +++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp @@ -43,12 +43,14 @@ #include <QDebug> #include <QVariant> -#include <QStringList> +#include <QList> #include <qbluetoothaddress.h> #include <qbluetoothdevicediscoveryagent.h> #include <qbluetoothservicediscoveryagent.h> #include <qbluetoothlocaldevice.h> +#include <qbluetoothserver.h> +#include <qbluetoothserviceinfo.h> QT_USE_NAMESPACE_BLUETOOTH @@ -76,6 +78,7 @@ private slots: void tst_serviceDiscovery_data(); void tst_serviceDiscovery(); + void tst_serviceDiscoveryAdapters(); private: QList<QBluetoothDeviceInfo> devices; @@ -250,6 +253,84 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery_data() << QBluetoothServiceDiscoveryAgent::NoError; } +void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscoveryAdapters() +{ + QBluetoothLocalDevice localDevice; + int numberOfAdapters = (localDevice.allDevices()).size(); + if (numberOfAdapters>1) { + if (devices.isEmpty()) + QSKIP("This test requires an in-range bluetooth device"); + + QList<QBluetoothAddress> addresses; + + for (int i=0; i<numberOfAdapters; i++) { + addresses.append(((QBluetoothHostInfo)localDevice.allDevices().at(i)).address()); + } + QBluetoothServer server(QBluetoothServer::RfcommServer); + QBluetoothUuid uuid(QBluetoothUuid::Ftp); + server.listen(addresses[0]); + QBluetoothServiceInfo serviceInfo; + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, "serviceName"); + serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, + QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); + + QBluetoothServiceInfo::Sequence classId; + classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); + serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, + classId); + + serviceInfo.setServiceUuid(uuid); + + QBluetoothServiceInfo::Sequence protocolDescriptorList; + QBluetoothServiceInfo::Sequence protocol; + protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + protocolDescriptorList.append(QVariant::fromValue(protocol)); + protocol.clear(); + + protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) + << QVariant::fromValue(quint8(server.serverPort())); + + protocolDescriptorList.append(QVariant::fromValue(protocol)); + serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, + protocolDescriptorList); + QVERIFY(serviceInfo.registerService()); + + QVERIFY(server.isListening()); + qDebug() << "Scanning address" << addresses[0].toString(); + QBluetoothServiceDiscoveryAgent discoveryAgent(addresses[1]); + bool setAddress = discoveryAgent.setRemoteAddress(addresses[0]); + + QVERIFY(setAddress); + + QVERIFY(!discoveryAgent.isActive()); + + QVERIFY(discoveryAgent.discoveredServices().isEmpty()); + + QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished())); + + discoveryAgent.start(); + int scanTime = MaxScanTime; + while (finishedSpy.count() == 0 && scanTime > 0) { + QTest::qWait(1000); + scanTime -= 1000; + } + + QList<QBluetoothServiceInfo> discServices = discoveryAgent.discoveredServices(); + QVERIFY(!discServices.empty()); + + int counter = 0; + for (int i = 0; i<discServices.size(); i++) + { + QBluetoothServiceInfo service((QBluetoothServiceInfo)discServices.at(i)); + if (uuid == service.serviceUuid()) + counter++; + } + QVERIFY(counter == 1); + } + +} + void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery() { @@ -263,8 +344,13 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery() QFETCH(QList<QBluetoothUuid>, uuidFilter); QFETCH(QBluetoothServiceDiscoveryAgent::Error, serviceDiscoveryError); + QBluetoothLocalDevice localDevice; + qDebug() << "Scanning address" << deviceInfo.address().toString(); - QBluetoothServiceDiscoveryAgent discoveryAgent(deviceInfo.address()); + QBluetoothServiceDiscoveryAgent discoveryAgent(localDevice.address()); + bool setAddress = discoveryAgent.setRemoteAddress(deviceInfo.address()); + + QVERIFY(setAddress); QVERIFY(!discoveryAgent.isActive()); |