diff options
Diffstat (limited to 'tests')
12 files changed, 871 insertions, 32 deletions
diff --git a/tests/auto/qbluetoothdeviceinfo/qbluetoothdeviceinfo.pro b/tests/auto/qbluetoothdeviceinfo/qbluetoothdeviceinfo.pro index 43ca52ed..408628ea 100644 --- a/tests/auto/qbluetoothdeviceinfo/qbluetoothdeviceinfo.pro +++ b/tests/auto/qbluetoothdeviceinfo/qbluetoothdeviceinfo.pro @@ -4,3 +4,6 @@ CONFIG += testcase QT = core concurrent bluetooth testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +qnx { + LIBS += -lbtapi +} diff --git a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp index adc61199..6b99639e 100644 --- a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp +++ b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp @@ -52,6 +52,7 @@ QT_USE_NAMESPACE Q_DECLARE_METATYPE(QBluetoothDeviceInfo::ServiceClasses) Q_DECLARE_METATYPE(QBluetoothDeviceInfo::MajorDeviceClass) +Q_DECLARE_METATYPE(QBluetoothDeviceInfo::CoreConfiguration) class tst_QBluetoothDeviceInfo : public QObject { @@ -101,6 +102,7 @@ void tst_QBluetoothDeviceInfo::tst_construction_data() QTest::addColumn<QBluetoothDeviceInfo::ServiceClasses>("serviceClasses"); QTest::addColumn<QBluetoothDeviceInfo::MajorDeviceClass>("majorDeviceClass"); QTest::addColumn<quint8>("minorDeviceClass"); + QTest::addColumn<QBluetoothDeviceInfo::CoreConfiguration>("coreConfiguration"); // bits 12-8 Major // bits 7-2 Minor @@ -110,120 +112,144 @@ void tst_QBluetoothDeviceInfo::tst_construction_data() << quint32(0x000000) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::MiscellaneousDevice - << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous); + << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous) + << QBluetoothDeviceInfo::BaseRateCoreConfiguration; QTest::newRow("0x000100 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000100) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ComputerDevice - << quint8(QBluetoothDeviceInfo::UncategorizedComputer); + << quint8(QBluetoothDeviceInfo::UncategorizedComputer) + << QBluetoothDeviceInfo::BaseRateCoreConfiguration; QTest::newRow("0x000104 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000104) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ComputerDevice - << quint8(QBluetoothDeviceInfo::DesktopComputer); + << quint8(QBluetoothDeviceInfo::DesktopComputer) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000118 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000118) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ComputerDevice - << quint8(QBluetoothDeviceInfo::WearableComputer); + << quint8(QBluetoothDeviceInfo::WearableComputer) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000200 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000200) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::PhoneDevice - << quint8(QBluetoothDeviceInfo::UncategorizedPhone); + << quint8(QBluetoothDeviceInfo::UncategorizedPhone) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000204 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000204) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::PhoneDevice - << quint8(QBluetoothDeviceInfo::CellularPhone); + << quint8(QBluetoothDeviceInfo::CellularPhone) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000214 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000214) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::PhoneDevice - << quint8(QBluetoothDeviceInfo::CommonIsdnAccessPhone); + << quint8(QBluetoothDeviceInfo::CommonIsdnAccessPhone) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000300 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000300) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::LANAccessDevice - << quint8(QBluetoothDeviceInfo::NetworkFullService); + << quint8(QBluetoothDeviceInfo::NetworkFullService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000320 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000320) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::LANAccessDevice - << quint8(QBluetoothDeviceInfo::NetworkLoadFactorOne); + << quint8(QBluetoothDeviceInfo::NetworkLoadFactorOne) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x0003E0 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x0003E0) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::LANAccessDevice - << quint8(QBluetoothDeviceInfo::NetworkNoService); + << quint8(QBluetoothDeviceInfo::NetworkNoService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000400 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000400) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::AudioVideoDevice - << quint8(QBluetoothDeviceInfo::UncategorizedAudioVideoDevice); + << quint8(QBluetoothDeviceInfo::UncategorizedAudioVideoDevice) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000448 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000448) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::AudioVideoDevice - << quint8(QBluetoothDeviceInfo::GamingDevice); + << quint8(QBluetoothDeviceInfo::GamingDevice) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000500 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000500) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::PeripheralDevice - << quint8(QBluetoothDeviceInfo::UncategorizedPeripheral); + << quint8(QBluetoothDeviceInfo::UncategorizedPeripheral) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x0005D8 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x0005D8) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::PeripheralDevice - << quint8(QBluetoothDeviceInfo::KeyboardWithPointingDevicePeripheral | QBluetoothDeviceInfo::CardReaderPeripheral); + << quint8(QBluetoothDeviceInfo::KeyboardWithPointingDevicePeripheral | QBluetoothDeviceInfo::CardReaderPeripheral) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000600 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000600) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ImagingDevice - << quint8(QBluetoothDeviceInfo::UncategorizedImagingDevice); + << quint8(QBluetoothDeviceInfo::UncategorizedImagingDevice) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; QTest::newRow("0x000680 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000680) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ImagingDevice - << quint8(QBluetoothDeviceInfo::ImagePrinter); + << quint8(QBluetoothDeviceInfo::ImagePrinter) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x000700 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000700) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::WearableDevice - << quint8(QBluetoothDeviceInfo::UncategorizedWearableDevice); + << quint8(QBluetoothDeviceInfo::UncategorizedWearableDevice) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x000714 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000714) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::WearableDevice - << quint8(QBluetoothDeviceInfo::WearableGlasses); + << quint8(QBluetoothDeviceInfo::WearableGlasses) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x000800 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000800) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ToyDevice - << quint8(QBluetoothDeviceInfo::UncategorizedToy); + << quint8(QBluetoothDeviceInfo::UncategorizedToy) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x000814 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000814) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::ToyDevice - << quint8(QBluetoothDeviceInfo::ToyGame); + << quint8(QBluetoothDeviceInfo::ToyGame) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x001f00 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x001f00) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService) << QBluetoothDeviceInfo::UncategorizedDevice - << quint8(0); + << quint8(0) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x002000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x002000) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::PositioningService) << QBluetoothDeviceInfo::MiscellaneousDevice - << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous); + << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0x100000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x100000) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::InformationService) << QBluetoothDeviceInfo::MiscellaneousDevice - << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous); + << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; QTest::newRow("0xFFE000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0xFFE000) << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::AllServices) << QBluetoothDeviceInfo::MiscellaneousDevice - << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous); + << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; } void tst_QBluetoothDeviceInfo::tst_construction() @@ -241,6 +267,7 @@ void tst_QBluetoothDeviceInfo::tst_construction() QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses); QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass); QFETCH(quint8, minorDeviceClass); + QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration); QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice); @@ -251,9 +278,12 @@ void tst_QBluetoothDeviceInfo::tst_construction() QCOMPARE(deviceInfo.serviceClasses(), serviceClasses); QCOMPARE(deviceInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(deviceInfo.minorDeviceClass(), minorDeviceClass); + QCOMPARE(deviceInfo.coreConfiguration(), QBluetoothDeviceInfo::BaseRateCoreConfiguration); - QBluetoothDeviceInfo copyInfo(deviceInfo); + deviceInfo.setCoreConfiguration(coreConfiguration); + QCOMPARE(deviceInfo.coreConfiguration(), coreConfiguration); + QBluetoothDeviceInfo copyInfo(deviceInfo); QVERIFY(copyInfo.isValid()); QCOMPARE(copyInfo.address(), address); @@ -261,6 +291,7 @@ void tst_QBluetoothDeviceInfo::tst_construction() QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); + QCOMPARE(copyInfo.coreConfiguration(), coreConfiguration); } } @@ -277,8 +308,10 @@ void tst_QBluetoothDeviceInfo::tst_assignment() QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses); QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass); QFETCH(quint8, minorDeviceClass); + QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration); QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice); + deviceInfo.setCoreConfiguration(coreConfiguration); QVERIFY(deviceInfo.isValid()); @@ -292,6 +325,7 @@ void tst_QBluetoothDeviceInfo::tst_assignment() QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); + QCOMPARE(copyInfo.coreConfiguration(), coreConfiguration); } { @@ -308,6 +342,7 @@ void tst_QBluetoothDeviceInfo::tst_assignment() QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); + QCOMPARE(copyInfo.coreConfiguration(), coreConfiguration); } { @@ -333,6 +368,8 @@ void tst_QBluetoothDeviceInfo::tst_assignment() QCOMPARE(copyInfo2.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo1.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo2.minorDeviceClass(), minorDeviceClass); + QCOMPARE(copyInfo1.coreConfiguration(), coreConfiguration); + QCOMPARE(copyInfo2.coreConfiguration(), coreConfiguration); } { diff --git a/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro b/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro index 7b8ee74a..e678aa12 100644 --- a/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro +++ b/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro @@ -3,5 +3,8 @@ TARGET = tst_qbluetoothservicediscoveryagent CONFIG += testcase QT = core concurrent bluetooth testlib +qnx { + LIBS += -lbtapi +} DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp index 791bff8d..d7a6a6ef 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: @@ -100,6 +105,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"); @@ -180,6 +186,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.serviceName(); + qDebug() << "\tUUID:" << info.serviceUuid(); +} + static void dumpAttributeVariant(const QVariant &var, const QString indent) { if (!var.isValid()) { @@ -316,7 +330,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]); @@ -362,9 +376,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()); @@ -384,11 +398,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()); @@ -446,6 +465,79 @@ 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(leController.errorString(), QString()); + QVERIFY((info.characteristics().size() > 0)); + qDebug() << "LE Service Connected: " << info.serviceName() << info.serviceUuid(); + 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()); + qDebug() << "LE Service Disconnected: " << info.serviceName() << info.serviceUuid(); + } else { + QFAIL("Unknown type returned by service discovery"); + } + + } + } QVERIFY(discoveryAgent.discoveredServices().count() != 0); discoveryAgent.clear(); diff --git a/tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro b/tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro new file mode 100644 index 00000000..aa4d5842 --- /dev/null +++ b/tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro @@ -0,0 +1,9 @@ +SOURCES += tst_qlowenergycharacteristicinfo.cpp +TARGET = tst_qlowenergycharacteristicinfo +CONFIG += testcase + +QT = core bluetooth testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +qnx { + LIBS += -lbtapi +} diff --git a/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp b/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp new file mode 100644 index 00000000..fc8095bf --- /dev/null +++ b/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp @@ -0,0 +1,215 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited all rights reserved +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QUuid> + +#include <QDebug> + +#include <qbluetoothdeviceinfo.h> +#include <qlowenergycharacteristicinfo.h> +#include <qbluetoothaddress.h> +#include <qbluetoothlocaldevice.h> +#include <qbluetoothuuid.h> + +QT_USE_NAMESPACE + +Q_DECLARE_METATYPE(QUuid) +Q_DECLARE_METATYPE(QLowEnergyCharacteristicInfo) +Q_DECLARE_METATYPE(QBluetoothUuid::CharacteristicId) + +class tst_QLowEnergyCharacteristicInfo : public QObject +{ + Q_OBJECT + +public: + tst_QLowEnergyCharacteristicInfo(); + ~tst_QLowEnergyCharacteristicInfo(); + +private slots: + void initTestCase(); + void tst_construction(); + void tst_assignment_data(); + void tst_assignment(); +}; + +tst_QLowEnergyCharacteristicInfo::tst_QLowEnergyCharacteristicInfo() +{ +} + +tst_QLowEnergyCharacteristicInfo::~tst_QLowEnergyCharacteristicInfo() +{ +} + +void tst_QLowEnergyCharacteristicInfo::initTestCase() +{ + // start Bluetooth if not started + QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); + device->powerOn(); + delete device; +} + +void tst_QLowEnergyCharacteristicInfo::tst_construction() +{ + const QBluetoothUuid characteristicUuid(QBluetoothUuid::HIDControlPoint); + const QBluetoothUuid alternateCharacteristicUuid(QBluetoothUuid::TemperatureMeasurement); + + { + QLowEnergyCharacteristicInfo characteristicInfo; + + QVERIFY(!characteristicInfo.isValid()); + QCOMPARE(characteristicInfo.uuid().toString(), QBluetoothUuid().toString()); + QCOMPARE(characteristicInfo.value(), QByteArray()); + QCOMPARE(characteristicInfo.permissions(), 0); + QCOMPARE(characteristicInfo.handle(), QString("0x0000")); + QCOMPARE(characteristicInfo.name(), QString("")); + QCOMPARE(characteristicInfo.isNotificationCharacteristic(), false); + QCOMPARE(characteristicInfo.descriptors().count(), 0); + } + + { + QLowEnergyCharacteristicInfo characteristicInfo(characteristicUuid); + + QVERIFY(!characteristicInfo.isValid()); + + QCOMPARE(characteristicInfo.uuid().toString(), characteristicUuid.toString()); + QCOMPARE(characteristicInfo.value(), QByteArray()); + QCOMPARE(characteristicInfo.permissions(), 0); + QCOMPARE(characteristicInfo.handle(), QString("0x0000")); + QCOMPARE(characteristicInfo.name(), QString("")); + QCOMPARE(characteristicInfo.isNotificationCharacteristic(), false); + QCOMPARE(characteristicInfo.descriptors().count(), 0); + + QLowEnergyCharacteristicInfo copyInfo(characteristicInfo); + + QVERIFY(!copyInfo.isValid()); + + QCOMPARE(copyInfo.uuid().toString(), characteristicUuid.toString()); + + copyInfo = QLowEnergyCharacteristicInfo(alternateCharacteristicUuid); + QCOMPARE(copyInfo.uuid().toString(), alternateCharacteristicUuid.toString()); + + QCOMPARE(copyInfo.handle(), QString("0x0000")); + QCOMPARE(copyInfo.value(), QByteArray()); + QCOMPARE(copyInfo.permissions(), 0); + QCOMPARE(copyInfo.handle(), QString("0x0000")); + QCOMPARE(copyInfo.name(), QString("")); + QCOMPARE(copyInfo.isNotificationCharacteristic(), false); + QCOMPARE(copyInfo.descriptors().count(), 0); + copyInfo.writeValue("test"); + } +} + +void tst_QLowEnergyCharacteristicInfo::tst_assignment_data() +{ + QTest::addColumn<QBluetoothUuid>("characteristicClassUuid"); + + QTest::newRow("0x000000 COD") << QBluetoothUuid(QBluetoothUuid::AlertCategoryID); + QTest::newRow("0x001000 COD") << QBluetoothUuid(QBluetoothUuid::AlertCategoryIDBitMask); + QTest::newRow("0x002000 COD") << QBluetoothUuid(QBluetoothUuid::AlertLevel); + QTest::newRow("0x003000 COD") << QBluetoothUuid(QBluetoothUuid::AlertNotificationControlPoint); + QTest::newRow("0x004000 COD") << QBluetoothUuid(QBluetoothUuid::AlertStatus); + QTest::newRow("0x005000 COD") << QBluetoothUuid(QBluetoothUuid::Appearance); + QTest::newRow("0x006000 COD") << QBluetoothUuid(QBluetoothUuid::CSCFeature); + QTest::newRow("0x007000 COD") << QBluetoothUuid(QBluetoothUuid::CSCMeasurement); + QTest::newRow("0x008000 COD") << QBluetoothUuid(QBluetoothUuid::CurrentTime); + QTest::newRow("0x009000 COD") << QBluetoothUuid(QBluetoothUuid::DateTime); + QTest::newRow("0x010000 COD") << QBluetoothUuid(QBluetoothUuid::DayOfWeek); + QTest::newRow("0x011000 COD") << QBluetoothUuid(QBluetoothUuid::DeviceName); + QTest::newRow("0x012000 COD") << QBluetoothUuid(QBluetoothUuid::DSTOffset); + QTest::newRow("0x013000 COD") << QBluetoothUuid(QBluetoothUuid::ExactTime256); + QTest::newRow("0x014000 COD") << QBluetoothUuid(QBluetoothUuid::HeartRateControlPoint); + QTest::newRow("0x015000 COD") << QBluetoothUuid(QBluetoothUuid::IntermediateCuffPressure); + QTest::newRow("0x016000 COD") << QBluetoothUuid(QBluetoothUuid::Navigation); + QTest::newRow("0x017000 COD") << QBluetoothUuid(QBluetoothUuid::NewAlert); + QTest::newRow("0x018000 COD") << QBluetoothUuid(QBluetoothUuid::PeripheralPreferredConnectionParameters); +} + +void tst_QLowEnergyCharacteristicInfo::tst_assignment() +{ + QFETCH(QBluetoothUuid, characteristicClassUuid); + + QLowEnergyCharacteristicInfo characteristicInfo(characteristicClassUuid); + + QVERIFY(!characteristicInfo.isValid()); + + { + QLowEnergyCharacteristicInfo copyInfo = characteristicInfo; + + QVERIFY(!copyInfo.isValid()); + + QCOMPARE(copyInfo.uuid(), characteristicClassUuid); + QCOMPARE(copyInfo.value(), QByteArray()); + } + + { + QLowEnergyCharacteristicInfo copyInfo; + + QVERIFY(!copyInfo.isValid()); + + copyInfo = characteristicInfo; + + QVERIFY(!copyInfo.isValid()); + + QCOMPARE(copyInfo.uuid(), characteristicClassUuid); + } + + { + QLowEnergyCharacteristicInfo copyInfo1; + QLowEnergyCharacteristicInfo copyInfo2; + + QVERIFY(!copyInfo1.isValid()); + QVERIFY(!copyInfo2.isValid()); + + copyInfo1 = copyInfo2 = characteristicInfo; + + QVERIFY(!copyInfo1.isValid()); + QVERIFY(!copyInfo2.isValid()); + //QVERIFY(QLowEnergyCharacteristicInfo() != copyInfo1); + + QCOMPARE(copyInfo1.uuid(), characteristicClassUuid); + QCOMPARE(copyInfo2.uuid(), characteristicClassUuid); + } +} + +QTEST_MAIN(tst_QLowEnergyCharacteristicInfo) + +#include "tst_qlowenergycharacteristicinfo.moc" diff --git a/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro b/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro new file mode 100644 index 00000000..f25272a7 --- /dev/null +++ b/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro @@ -0,0 +1,9 @@ +SOURCES += tst_qlowenergydescriptorinfo.cpp +TARGET = tst_qlowenergydescriptorinfo +CONFIG += testcase + +QT = core bluetooth testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +qnx { + LIBS += -lbtapi +} diff --git a/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp b/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp new file mode 100644 index 00000000..d3abcedf --- /dev/null +++ b/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp @@ -0,0 +1,176 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited all rights reserved +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QUuid> + +#include <QDebug> + +#include <qbluetoothdeviceinfo.h> +#include <qlowenergydescriptorinfo.h> +#include <qbluetoothlocaldevice.h> +#include "qbluetoothuuid.h" + +QT_USE_NAMESPACE + +Q_DECLARE_METATYPE(QUuid) +Q_DECLARE_METATYPE(QBluetoothUuid::DescriptorID) + +class tst_QLowEnergyDescriptorInfo : public QObject +{ + Q_OBJECT + +public: + tst_QLowEnergyDescriptorInfo(); + ~tst_QLowEnergyDescriptorInfo(); + +private slots: + void initTestCase(); + void tst_construction(); + void tst_assignment_data(); + void tst_assignment(); +}; + +tst_QLowEnergyDescriptorInfo::tst_QLowEnergyDescriptorInfo() +{ +} + +tst_QLowEnergyDescriptorInfo::~tst_QLowEnergyDescriptorInfo() +{ +} + +void tst_QLowEnergyDescriptorInfo::initTestCase() +{ + // start Bluetooth if not started + QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); + device->powerOn(); + delete device; +} + +void tst_QLowEnergyDescriptorInfo::tst_construction() +{ + const QBluetoothUuid descriptorUuid(QString("0x2902").toUShort(0,0)); + const QBluetoothUuid alternateDescriptorUuid(QString("0x2906").toUShort(0,0)); + + { + QLowEnergyDescriptorInfo descriptorInfo = QLowEnergyDescriptorInfo(QBluetoothUuid()); + + QCOMPARE(descriptorInfo.uuid(), QBluetoothUuid()); + QCOMPARE(descriptorInfo.value(), QByteArray()); + QCOMPARE(descriptorInfo.properties(), QVariantMap()); + QCOMPARE(descriptorInfo.handle(), QString("0x0000")); + QCOMPARE(descriptorInfo.name(), QString("")); + } + + { + QLowEnergyDescriptorInfo descriptorInfo(descriptorUuid); + + QCOMPARE(descriptorInfo.uuid().toString(), descriptorUuid.toString()); + + QLowEnergyDescriptorInfo copyInfo = descriptorInfo; + + QCOMPARE(copyInfo.uuid().toString(), descriptorUuid.toString()); + + copyInfo = QLowEnergyDescriptorInfo(alternateDescriptorUuid); + QCOMPARE(copyInfo.uuid().toString(), alternateDescriptorUuid.toString()); + + QCOMPARE(copyInfo.uuid(), QBluetoothUuid()); + QCOMPARE(copyInfo.value(), QByteArray()); + QCOMPARE(copyInfo.properties(), QVariantMap()); + QCOMPARE(copyInfo.handle(), QString("0x0000")); + QCOMPARE(copyInfo.name(), QString("")); + + } +} + +void tst_QLowEnergyDescriptorInfo::tst_assignment_data() +{ + QTest::addColumn<QBluetoothUuid>("descriptorClassUuid"); + + QTest::newRow("0x000000 COD") << QBluetoothUuid(QString("0x2901").toUShort(0,0)); + QTest::newRow("0x001000 COD") << QBluetoothUuid(QString("0x2902").toUShort(0,0)); + QTest::newRow("0x002000 COD") << QBluetoothUuid(QString("0x2903").toUShort(0,0)); + QTest::newRow("0x003000 COD") << QBluetoothUuid(QString("0x2904").toUShort(0,0)); + QTest::newRow("0x004000 COD") << QBluetoothUuid(QString("0x2905").toUShort(0,0)); + QTest::newRow("0x005000 COD") << QBluetoothUuid(QString("0x2906").toUShort(0,0)); + QTest::newRow("0x006000 COD") << QBluetoothUuid(QString("0x2907").toUShort(0,0)); + QTest::newRow("0x007000 COD") << QBluetoothUuid(QString("0x2908").toUShort(0,0)); + QTest::newRow("0x008000 COD") << QBluetoothUuid(QString("0x2900").toUShort(0,0)); +} + +void tst_QLowEnergyDescriptorInfo::tst_assignment() +{ + QFETCH(QBluetoothUuid, descriptorClassUuid); + + QLowEnergyDescriptorInfo descriptorInfo(descriptorClassUuid); + + + { + QLowEnergyDescriptorInfo copyInfo = descriptorInfo; + + QCOMPARE(copyInfo.uuid(), descriptorClassUuid); + QCOMPARE(copyInfo.value(), QByteArray()); + } + + { + QLowEnergyDescriptorInfo copyInfo = QLowEnergyDescriptorInfo(QBluetoothUuid()); + + copyInfo = descriptorInfo; + + QCOMPARE(copyInfo.uuid(), descriptorClassUuid); + } + + { + QLowEnergyDescriptorInfo copyInfo1 = QLowEnergyDescriptorInfo(QBluetoothUuid()); + QLowEnergyDescriptorInfo copyInfo2 = QLowEnergyDescriptorInfo(QBluetoothUuid()); + + copyInfo1 = copyInfo2 = descriptorInfo; + + QCOMPARE(copyInfo1.uuid(), descriptorClassUuid); + QCOMPARE(copyInfo2.uuid(), descriptorClassUuid); + } + +} + +QTEST_MAIN(tst_QLowEnergyDescriptorInfo) + +#include "tst_qlowenergydescriptorinfo.moc" + diff --git a/tests/auto/qlowenergyserviceinfo/qlowenergyserviceinfo.pro b/tests/auto/qlowenergyserviceinfo/qlowenergyserviceinfo.pro new file mode 100644 index 00000000..3fa99d76 --- /dev/null +++ b/tests/auto/qlowenergyserviceinfo/qlowenergyserviceinfo.pro @@ -0,0 +1,9 @@ +SOURCES += tst_qlowenergyserviceinfo.cpp +TARGET = tst_qlowenergyserviceinfo +CONFIG += testcase + +QT = core bluetooth testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +qnx { + LIBS += -lbtapi +} diff --git a/tests/auto/qlowenergyserviceinfo/tst_qlowenergyserviceinfo.cpp b/tests/auto/qlowenergyserviceinfo/tst_qlowenergyserviceinfo.cpp new file mode 100644 index 00000000..fc3ba25d --- /dev/null +++ b/tests/auto/qlowenergyserviceinfo/tst_qlowenergyserviceinfo.cpp @@ -0,0 +1,277 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited all rights reserved +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QUuid> + +#include <QDebug> + +#include <qbluetoothdeviceinfo.h> +#include <qlowenergyserviceinfo.h> +#include <qbluetoothaddress.h> +#include <qbluetoothlocaldevice.h> +#include <qbluetoothuuid.h> + +QT_USE_NAMESPACE + +Q_DECLARE_METATYPE(QUuid) +Q_DECLARE_METATYPE(QLowEnergyServiceInfo::ServiceType) +Q_DECLARE_METATYPE(QBluetoothDeviceInfo::CoreConfiguration) +Q_DECLARE_METATYPE(QLowEnergyServiceInfo) +Q_DECLARE_METATYPE(QBluetoothUuid::ServiceClassUuid) + +class tst_QLowEnergyServiceInfo : public QObject +{ + Q_OBJECT + +public: + tst_QLowEnergyServiceInfo(); + ~tst_QLowEnergyServiceInfo(); + +private slots: + void initTestCase(); + void tst_construction(); + void tst_assignment_data(); + void tst_assignment(); +}; + +tst_QLowEnergyServiceInfo::tst_QLowEnergyServiceInfo() +{ +} + +tst_QLowEnergyServiceInfo::~tst_QLowEnergyServiceInfo() +{ +} + +void tst_QLowEnergyServiceInfo::initTestCase() +{ + // start Bluetooth if not started + QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); + device->powerOn(); + delete device; +} + +void tst_QLowEnergyServiceInfo::tst_construction() +{ + const QBluetoothUuid serviceUuid(QBluetoothUuid::HeartRate); + const QBluetoothUuid alternateServiceUuid(QBluetoothUuid::BatteryService); + const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0); + const QBluetoothDeviceInfo alternatedeviceInfo(QBluetoothAddress("554433221100"), "Test Device2", 0); + + { + QLowEnergyServiceInfo serviceInfo; + + QVERIFY(!serviceInfo.isValid()); + QCOMPARE(serviceInfo.serviceName(), QString()); + QCOMPARE(serviceInfo.serviceUuid().toString(), QBluetoothUuid().toString()); + QCOMPARE(serviceInfo.serviceType(), QLowEnergyServiceInfo::PrimaryService); + QCOMPARE(serviceInfo.isConnected(), false); + QCOMPARE(serviceInfo.characteristics().size(), 0); + QCOMPARE(serviceInfo.device(), QBluetoothDeviceInfo()); + } + + { + QLowEnergyServiceInfo serviceInfo(serviceUuid); + serviceInfo.setDevice(deviceInfo); + + QVERIFY(serviceInfo.isValid()); + + QCOMPARE(serviceInfo.serviceUuid().toString(), serviceUuid.toString()); + QCOMPARE(serviceInfo.device().address(), deviceInfo.address()); + + QLowEnergyServiceInfo copyInfo(serviceInfo); + + QVERIFY(copyInfo.isValid()); + + QCOMPARE(copyInfo.serviceUuid().toString(), serviceUuid.toString()); + QCOMPARE(copyInfo.device().address(), deviceInfo.address()); + + + copyInfo = QLowEnergyServiceInfo(alternateServiceUuid); + copyInfo.setDevice(alternatedeviceInfo); + QCOMPARE(copyInfo.serviceUuid(), alternateServiceUuid); + + QCOMPARE(copyInfo.device().address(), alternatedeviceInfo.address()); + + } +} + +void tst_QLowEnergyServiceInfo::tst_assignment_data() +{ + QTest::addColumn<QBluetoothAddress>("address"); + QTest::addColumn<QString>("name"); + QTest::addColumn<quint32>("classOfDevice"); + QTest::addColumn<QBluetoothUuid>("serviceClassUuid"); + QTest::addColumn<QLowEnergyServiceInfo::ServiceType>("serviceType"); + QTest::addColumn<QBluetoothDeviceInfo::CoreConfiguration>("coreConfiguration"); + + // bits 12-8 Major + // bits 7-2 Minor + // bits 1-0 0 + + QTest::newRow("0x000000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000000) + << QBluetoothUuid(QBluetoothUuid::GenericAccess) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; + QTest::newRow("0x000100 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000100) + << QBluetoothUuid(QBluetoothUuid::GenericAttribute) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; + QTest::newRow("0x000104 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000104) + << QBluetoothUuid(QBluetoothUuid::HeartRate) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; + QTest::newRow("0x000118 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000118) + << QBluetoothUuid(QBluetoothUuid::CyclingSpeedAndCadence) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration; + QTest::newRow("0x000200 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000200) + << QBluetoothUuid(QBluetoothUuid::CyclingPower) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; + QTest::newRow("0x000204 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000204) + << QBluetoothUuid(QBluetoothUuid::ScanParameters) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; + QTest::newRow("0x000214 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000214) + << QBluetoothUuid(QBluetoothUuid::DeviceInformation) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; + QTest::newRow("0x000300 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000300) + << QBluetoothUuid(QBluetoothUuid::CurrentTimeService) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; + QTest::newRow("0x000320 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" + << quint32(0x000320) + << QBluetoothUuid(QBluetoothUuid::LocationAndNavigation) + << QLowEnergyServiceInfo::ServiceType(QLowEnergyServiceInfo::PrimaryService) + << QBluetoothDeviceInfo::LowEnergyCoreConfiguration; +} + +void tst_QLowEnergyServiceInfo::tst_assignment() +{ + QFETCH(QBluetoothAddress, address); + QFETCH(QString, name); + QFETCH(quint32, classOfDevice); + QFETCH(QBluetoothUuid, serviceClassUuid); + QFETCH(QLowEnergyServiceInfo::ServiceType, serviceType); + QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration); + + QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice); + deviceInfo.setCoreConfiguration(coreConfiguration); + QCOMPARE(deviceInfo.coreConfiguration(), coreConfiguration); + + QLowEnergyServiceInfo serviceInfo(serviceClassUuid); + serviceInfo.setDevice(deviceInfo); + QCOMPARE(serviceInfo.device(), deviceInfo); + + QVERIFY(serviceInfo.isValid()); + + { + QLowEnergyServiceInfo copyInfo = serviceInfo; + + QVERIFY(copyInfo.isValid()); + + QCOMPARE(copyInfo.device().address(), address); + QCOMPARE(copyInfo.serviceUuid(), serviceClassUuid); + QCOMPARE(copyInfo.device().coreConfiguration(), coreConfiguration); + QCOMPARE(copyInfo.serviceType(), serviceType); + QCOMPARE(copyInfo.isConnected(), false); + QCOMPARE(copyInfo.characteristics().size(), 0); + QCOMPARE(copyInfo.device(), deviceInfo); + } + + { + QLowEnergyServiceInfo copyInfo; + + QVERIFY(!copyInfo.isValid()); + + copyInfo = serviceInfo; + + QVERIFY(copyInfo.isValid()); + + QCOMPARE(copyInfo.device().address(), address); + QCOMPARE(copyInfo.serviceUuid(), serviceClassUuid); + QCOMPARE(copyInfo.device().coreConfiguration(), coreConfiguration); + QCOMPARE(copyInfo.serviceType(), serviceType); + } + + { + QLowEnergyServiceInfo copyInfo1; + QLowEnergyServiceInfo copyInfo2; + + QVERIFY(!copyInfo1.isValid()); + QVERIFY(!copyInfo2.isValid()); + + copyInfo1 = copyInfo2 = serviceInfo; + + QVERIFY(copyInfo1.isValid()); + QVERIFY(copyInfo2.isValid()); + //QVERIFY(QLowEnergyServiceInfo() != copyInfo1); + + QCOMPARE(copyInfo1.device().address(), address); + QCOMPARE(copyInfo2.device().address(), address); + QCOMPARE(copyInfo1.serviceUuid(), serviceClassUuid); + QCOMPARE(copyInfo2.serviceUuid(), serviceClassUuid); + QCOMPARE(copyInfo1.serviceType(), serviceType); + QCOMPARE(copyInfo2.serviceType(), serviceType); + QCOMPARE(copyInfo1.device().coreConfiguration(), coreConfiguration); + QCOMPARE(copyInfo2.device().coreConfiguration(), coreConfiguration); + QCOMPARE(copyInfo1.isConnected(), false); + QCOMPARE(copyInfo2.isConnected(), false); + QCOMPARE(copyInfo1.characteristics().size(), 0); + QCOMPARE(copyInfo2.characteristics().size(), 0); + QCOMPARE(copyInfo1.device(), deviceInfo); + QCOMPARE(copyInfo2.device(), deviceInfo); + } +} + +QTEST_MAIN(tst_QLowEnergyServiceInfo) + +#include "tst_qlowenergyserviceinfo.moc" diff --git a/tests/bttestui/btlocaldevice.cpp b/tests/bttestui/btlocaldevice.cpp index 3a9b52b5..148ba1aa 100644 --- a/tests/bttestui/btlocaldevice.cpp +++ b/tests/bttestui/btlocaldevice.cpp @@ -80,6 +80,8 @@ BtLocalDevice::BtLocalDevice(QObject *parent) : serviceAgent = new QBluetoothServiceDiscoveryAgent(this); connect(serviceAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); + connect(serviceAgent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)), + this, SLOT(leServiceDiscovered(QLowEnergyServiceInfo))); connect(serviceAgent, SIGNAL(finished()), this, SLOT(serviceDiscoveryFinished())); connect(serviceAgent, SIGNAL(canceled()), @@ -271,11 +273,11 @@ void BtLocalDevice::stopServiceDiscovery() void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info) { - QString classIds; - foreach (const QBluetoothUuid uuid, info.serviceClassUuids()) - classIds += uuid.toString() + QLatin1Char(' '); + QStringList classIds; + foreach (const QBluetoothUuid &uuid, info.serviceClassUuids()) + classIds.append(uuid.toString()); qDebug() << "$$ Found new service" << info.device().address().toString() - << info.serviceUuid() << info.serviceName() << classIds; + << info.serviceUuid() << info.serviceName() << info.serviceDescription() << classIds; if (info.serviceUuid() == QBluetoothUuid(QString(TEST_SERVICE_UUID)) || info.serviceClassUuids().contains(QBluetoothUuid(QString(TEST_SERVICE_UUID)))) @@ -296,6 +298,12 @@ void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info) } } +void BtLocalDevice::leServiceDiscovered(const QLowEnergyServiceInfo &info) +{ + qDebug() << "$$ Found new BTLE service" << info.device().address().toString() + << info.serviceUuid() << info.serviceName(); +} + void BtLocalDevice::serviceDiscoveryFinished() { qDebug() << "###### Service Discovery Finished"; diff --git a/tests/bttestui/btlocaldevice.h b/tests/bttestui/btlocaldevice.h index 759599b7..a9571ecc 100644 --- a/tests/bttestui/btlocaldevice.h +++ b/tests/bttestui/btlocaldevice.h @@ -89,6 +89,7 @@ public slots: void startServiceDiscovery(bool isMinimalDiscovery); void stopServiceDiscovery(); void serviceDiscovered(const QBluetoothServiceInfo &info); + void leServiceDiscovered(const QLowEnergyServiceInfo &leInfo); void serviceDiscoveryFinished(); void serviceDiscoveryCanceled(); void serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error error); |