diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-12-11 11:04:47 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-12-11 17:46:32 +0000 |
commit | 7a829eaf51853e0852db28b8b8223e1a62a3db0c (patch) | |
tree | c26b6d7de66702aba2d32deeaa58c79c634a14e7 | |
parent | d557718d68184f6b56b17a3b5b54d1d5511a5294 (diff) |
Fix return value of qbswap(qint128)
Should be qint128, not quint128.
[ChangeLog][QtCore][QtEndian] Fixed return type of qbswap(qint128)
(was: quint128).
No tests for this exist, so no wonder it fell through. Added them.
Amends befda1accab417ce5f55cb11816e6ded51af55e3.
Pick-to: 6.7 6.6
Change-Id: Ibf87724b1d500081caca46af1c598975964e04c0
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r-- | src/corelib/global/qendian.h | 2 | ||||
-rw-r--r-- | tests/auto/corelib/global/qtendian/tst_qtendian.cpp | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 60c4a7b174..8c3b5e4374 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -116,7 +116,7 @@ inline constexpr quint128 qbswap(quint128 source) return result; } -inline constexpr quint128 qbswap(qint128 source) +inline constexpr qint128 qbswap(qint128 source) { return qint128(qbswap(quint128(source))); } diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index 885e693c8d..441256abc1 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -7,6 +7,12 @@ #include <QtCore/private/qendian_p.h> #include <QtCore/qsysinfo.h> +#if QT_SUPPORTS_INT128 +#define ONLY_INT128(...) __VA_ARGS__ +#else +#define ONLY_INT128(...) +#endif + class tst_QtEndian: public QObject { Q_OBJECT @@ -41,6 +47,9 @@ private slots: struct TestData { + ONLY_INT128( + quint128 data128; + ) quint64 data64; quint32 data32; quint16 data16; @@ -57,6 +66,9 @@ template <> quint8 getData(const TestData &d) { return d.data8; } template <> quint16 getData(const TestData &d) { return d.data16; } template <> quint32 getData(const TestData &d) { return d.data32; } template <> quint64 getData(const TestData &d) { return d.data64; } +ONLY_INT128( +template <> quint128 getData(const TestData &d) { return d.data128; } +) template <> float getData(const TestData &d) { return d.dataFloat; } union RawTestData @@ -74,6 +86,9 @@ Float int2Float(typename QIntegerForSizeof<Float>::Unsigned i) } static const TestData inNativeEndian = { + ONLY_INT128( + Q_UINT128_C(0x0123'4567'89ab'cdef'18ba'df00'd1da'cafe), + ) Q_UINT64_C(0x0123456789abcdef), 0x00c0ffee, 0xcafe, @@ -83,6 +98,9 @@ static const TestData inNativeEndian = { '\0' }; static const RawTestData inBigEndian = { + ONLY_INT128( + "\x01\x23\x45\x67\x89\xab\xcd\xef\x18\xba\xdf\x00\xd1\xda\xca\xfe" + ) "\x01\x23\x45\x67\x89\xab\xcd\xef" "\x00\xc0\xff\xee" "\xca\xfe" @@ -91,6 +109,9 @@ static const RawTestData inBigEndian = { "\x01\x23\x45\x67\x89\xab\xcd\xef" }; static const RawTestData inLittleEndian = { + ONLY_INT128( + "\xfe\xca\xda\xd1\x00\xdf\xba\x18\xef\xcd\xab\x89\x67\x45\x23\x01" + ) "\xef\xcd\xab\x89\x67\x45\x23\x01" "\xee\xff\xc0\x00" "\xfe\xca" @@ -102,12 +123,18 @@ static const RawTestData inLittleEndian = { #define EXPAND_ENDIAN_TEST(endian) \ do { \ /* Unsigned tests */ \ + ONLY_INT128( \ + ENDIAN_TEST(endian, quint, 128); \ + ) \ ENDIAN_TEST(endian, quint, 64); \ ENDIAN_TEST(endian, quint, 32); \ ENDIAN_TEST(endian, quint, 16); \ ENDIAN_TEST(endian, quint, 8); \ \ /* Signed tests */ \ + ONLY_INT128( \ + ENDIAN_TEST(endian, qint, 128); \ + ) \ ENDIAN_TEST(endian, qint, 64); \ ENDIAN_TEST(endian, qint, 32); \ ENDIAN_TEST(endian, qint, 16); \ @@ -117,6 +144,8 @@ static const RawTestData inLittleEndian = { #define ENDIAN_TEST(endian, type, size) \ do { \ + static_assert(std::is_same_v<decltype(qbswap(std::declval<type ## size>())), \ + type ## size>); \ QCOMPARE(qFrom ## endian ## Endian( \ (type ## size)(in ## endian ## Endian.data.data ## size)), \ (type ## size)(inNativeEndian.data ## size)); \ |