diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-07-18 17:21:01 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2023-08-03 22:23:08 +0200 |
commit | 5d90296f312f72ffa6a5322df7b565c3e5521684 (patch) | |
tree | dbe22479bb1704518cf3ab4e8be6499bff41233a /tests | |
parent | d4d43974fce2c56c718157a1a46e23e2fb39aba9 (diff) |
QBluetoothUuid: keep custom quint128 and related methods when 128-bit ints are not supported
... to retain SC with prior Qt versions.
For QBluetoothUuid::toUInt128() this is done by introducing
an extra condition to the method declaration and definition.
If the 128-bit ints are not supported, we shouldn't hide the
method under QT_BLUETOOTH_REMOVED_SINCE.
The QBluetoothUuid(quint128) c-tor is a bit more tricky,
because we need to provide a forwarding c-tor to be able to
use QUuid(quint128) c-tor. And at the same time, we need
to keep BC by keeping the constructor that takes custom
struct quint128.
This is achieved by having an unconstrained c-tor declaration
and two implementations:
* an implementation in qbluetoothuuid.cpp is only available
when Qt supports 128-bit ints. It just forwards to the
QUuid c-tor.
* an implementation in removed_api.cpp serves as a backup
implementation to keep BC for the case when Qt supports
128-bit ints. And at the same time it serves as a main
implementation when 128-bit ints are not supported.
Also extend the unit-tests to explicitly check that both
APIs are available on all platforms.
The test additionally makes sure that QUuid::toUInt128() and
QBluetoothUuid::toUInt128() provide the result which is similar to
QUuid::toBytes(). This guarantees compatibility between platforms.
This commit amends 1e903be81f43da4e31385bb7866bb4d3f07e5eba.
Pick-to: 6.6
Change-Id: I6ba3ff6278e6db11a372b46f001429f4466520a0
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp index e31b0667..7a31300c 100644 --- a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp +++ b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp @@ -359,6 +359,23 @@ void tst_QBluetoothUuid::tst_comparison() for (int var = 0; var < 16; ++var) { QVERIFY(quuid128.toBytes().data[var] == uuid128.data[var]); } + + // check that toUInt128() call returns the value in the same format as + // QUuid::Id128Bytes, no matter what version we use (it can be + // QUuid::toUint128() on platforms that define __SIZEOF_INT128__ or + // QBluetoothUuid::toUint128() on other platforms). + const quint128 i128 = quuid128.toUInt128(); + static_assert(sizeof(i128) == 16); // uint128 or QUuid::Id128Bytes + uchar dst[16]; + memcpy(dst, &i128, sizeof(i128)); + for (int var = 0; var < 16; ++var) + QCOMPARE_EQ(dst[var], uuid128.data[var]); + + // check that we always have a c-tor taking quint128 + QBluetoothUuid other{i128}; + const auto bytes = other.toBytes(); + for (int var = 0; var < 16; ++var) + QCOMPARE_EQ(bytes.data[var], uuid128.data[var]); } } |