From 477d9f450a1e9767dbf10f4c040e994231674a1f Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 6 Feb 2014 13:03:58 +0100 Subject: Fix broken QBluetoothServiceInfo::serviceClassUuids() call It never returned a valid entry due to wrong QVariant conversion. The patch changes the public header with a potential to break BC. A formerly inline function was reimplemented and is no longer inline. This should be safe though as older header versions can still use the previous implementation. Change-Id: If786a366e625a56810b8d4cc682b25d07f72f4e5 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserviceinfo.cpp | 36 ++++++++++++++-------- src/bluetooth/qbluetoothserviceinfo.h | 8 +---- .../tst_qbluetoothserviceinfo.cpp | 23 ++++++++++++++ 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp index 3a864b3c..84655b77 100644 --- a/src/bluetooth/qbluetoothserviceinfo.cpp +++ b/src/bluetooth/qbluetoothserviceinfo.cpp @@ -331,18 +331,6 @@ bool QBluetoothServiceInfo::unregisterService() \sa setServiceUuid(), attribute() */ -/*! - \fn QList QBluetoothServiceInfo::serviceClassUuids() const - - This is a convenience function. It is equivalent to calling - attribute(QBluetoothServiceInfo::ServiceClassIds).value >(). - - Returns a list of UUIDs describing the service classes that this service conforms to. - - \sa attribute() -*/ - - /*! Construct a new invalid QBluetoothServiceInfo; */ @@ -513,6 +501,30 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfo::protocolDescriptor(QBluet return d_ptr->protocolDescriptor(protocol); } +/*! + Returns a list of UUIDs describing the service classes that this service conforms to. + + This is a convenience function. It is equivalent to calling + attribute(QBluetoothServiceInfo::ServiceClassIds).value() + and subsequently iterating over its QBluetoothUuid entries. + + \sa attribute() +*/ +QList QBluetoothServiceInfo::serviceClassUuids() const +{ + QList results; + + const QVariant var = attribute(QBluetoothServiceInfo::ServiceClassIds); + if (!var.isValid()) + return results; + + const QBluetoothServiceInfo::Sequence seq = var.value(); + for (int i = 0; i < seq.count(); i++) + results.append(seq.at(i).value()); + + return results; +} + /*! Makes a copy of the \a other and assigns it to this QBluetoothServiceInfo object. The two copies continue to share the same service and registration details. diff --git a/src/bluetooth/qbluetoothserviceinfo.h b/src/bluetooth/qbluetoothserviceinfo.h index 0e6555c0..4d3b8612 100644 --- a/src/bluetooth/qbluetoothserviceinfo.h +++ b/src/bluetooth/qbluetoothserviceinfo.h @@ -141,7 +141,7 @@ public: inline void setServiceUuid(const QBluetoothUuid &uuid); inline QBluetoothUuid serviceUuid() const; - inline QList serviceClassUuids() const; + QList serviceClassUuids() const; QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other); @@ -228,12 +228,6 @@ inline QBluetoothUuid QBluetoothServiceInfo::serviceUuid() const { return attribute(ServiceId).value(); } - -inline QList QBluetoothServiceInfo::serviceClassUuids() const -{ - return attribute(ServiceClassIds).value >(); -} - QT_END_NAMESPACE #endif diff --git a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp index 62550622..2195bc0e 100644 --- a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp +++ b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp @@ -71,6 +71,8 @@ private slots: void tst_assignment_data(); void tst_assignment(); + + void tst_serviceClassUuids(); }; tst_QBluetoothServiceInfo::tst_QBluetoothServiceInfo() @@ -329,6 +331,27 @@ void tst_QBluetoothServiceInfo::tst_assignment() } } +void tst_QBluetoothServiceInfo::tst_serviceClassUuids() +{ + QBluetoothServiceInfo info; + QCOMPARE(info.serviceClassUuids().count(), 0); + + QBluetoothServiceInfo::Sequence classIds; + classIds << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); + QCOMPARE(classIds.count(), 1); + + QBluetoothUuid uuid(QString("e8e10f95-1a70-4b27-9ccf-02010264e9c8")); + classIds.prepend(QVariant::fromValue(uuid)); + QCOMPARE(classIds.count(), 2); + QCOMPARE(classIds.at(0).value(), uuid); + + info.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classIds); + QList svclids = info.serviceClassUuids(); + QCOMPARE(svclids.count(), 2); + QCOMPARE(svclids.at(0), uuid); + QCOMPARE(svclids.at(1), QBluetoothUuid(QBluetoothUuid::SerialPort)); +} + QTEST_MAIN(tst_QBluetoothServiceInfo) #include "tst_qbluetoothserviceinfo.moc" -- cgit v1.2.3