diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2019-08-06 14:17:47 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2019-08-08 10:40:48 +0200 |
commit | b76aeb87cddc4eb0fb4040787e6855dc18cf0408 (patch) | |
tree | 2b045bc4dff84c46fe636644f9cdd446df154836 /tests | |
parent | 8596715ffc5036d380217fc55418c82449504fe3 (diff) | |
download | qtconnectivity-b76aeb87cddc4eb0fb4040787e6855dc18cf0408.tar.gz |
Add ability to have multiple manufacturer data per manufacturer ID
The current QBluetoothDeviceInfo API is somewhat limited as it cannot
clearly express the nature of multiple data sets per manufacturerId.
The API should really offer:
QMultiHash<quint16, QByteArray> QBluetoothDeviceInfo::manufacturerData() const
QVector<QByteArray> QBluetoothDeviceInfo::manufacturerData(quint16 manufacturerId) const
Adding overloads and usual deprecation warnings cannot be done during
Qt 5.x time though as the required overloads merely change the return types.
Overloads which only offer different return types are not permitted
by C++. The plan is to replace w/o deprecation in the Qt 6 branch.
To avoid the API change during Qt 5.x, this patch leverages QHash::insertMulti().
There is a minor API behavior change that comes along with this approach.
Previously, old manufacturer data for a given manufacturerId was replaced
by the new value. Now, the data is added. The fact that multi inserts are permitted
are a minor behavioral change too but actually desired by the nature of
the bug this patch addresses.
Note that there is some talk that QHash's insertMulti() capability may
disappear in Qt 6.
Task-number: QTBUG-76615
Change-Id: I35b737cb48d6ed83112ebe0b22853ca307f20115
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp index d8c80291..45b429db 100644 --- a/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp +++ b/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp @@ -64,6 +64,8 @@ private slots: void tst_cached(); void tst_flags(); + + void tst_manufacturerData(); }; tst_QBluetoothDeviceInfo::tst_QBluetoothDeviceInfo() @@ -514,6 +516,38 @@ void tst_QBluetoothDeviceInfo::tst_flags() QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::CapturingService)); } +void tst_QBluetoothDeviceInfo::tst_manufacturerData() +{ + const int manufacturerAVM = 0x1F; + + QBluetoothDeviceInfo info; + QVERIFY(info.manufacturerIds().isEmpty()); + QVERIFY(info.manufacturerData(manufacturerAVM).isNull()); + + QVERIFY(info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD"))); + QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD"))); + QCOMPARE(info.manufacturerData(manufacturerAVM), QByteArray::fromHex("ABCD")); + auto temp = info.manufacturerData(); + QCOMPARE(temp.keys().count(), 1); + QCOMPARE(temp.values().count(), 1); + QCOMPARE(temp.values(), QList<QByteArray>() << QByteArray::fromHex("ABCD")); + + QVERIFY(info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("CDEF"))); + QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD"))); + QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("CDEF"))); + + temp = info.manufacturerData(); + QCOMPARE(temp.keys().count(), 2); + QCOMPARE(temp.values().count(), 2); + auto list = temp.values(); + + QCOMPARE(QSet<QByteArray> (list.begin(), list.end()), + QSet<QByteArray>() << QByteArray::fromHex("ABCD") << QByteArray::fromHex("CDEF")); + + // return latest entry + QCOMPARE(info.manufacturerData(manufacturerAVM), QByteArray::fromHex("CDEF")); +} + QTEST_MAIN(tst_QBluetoothDeviceInfo) #include "tst_qbluetoothdeviceinfo.moc" |