summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-08-15 13:25:33 +0200
committerThiago Macieira <thiago.macieira@intel.com>2024-02-12 17:01:33 -0800
commit1d7950c9467ba4db75ac065bd54ffe08e4a29710 (patch)
treedf21f716b87fae1b555a67c008fde31848d9b639 /tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
parent1845d433277348542e496d3c38175ad0c5cbddde (diff)
Add missing qHash(qu/int128) overloads
If we add the typedefs, we also need to add the qHash() overloads. See code comments for the explanation of how it works. I chose to use an addition to merge the upper and lower parts because of the comment in QHashCombineCommutative's operator(), introduced by commit 91b44afdcba3f4cb2ddc7a80c0cff723b408b447. Found in 6.6 API-review, but didn't make the cut and then was forgotten. Drive-by fix long line nearby. [ChangeLog][QtCore] Added qHash() overloads for quint128 and qint128. Fixes: QTBUG-116054 Task-number: QTBUG-116080 Change-Id: If484aed08ba476e0eace800b719f435203100f3e Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp')
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index 424e869d98..aebc0422ad 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -35,6 +35,7 @@ private Q_SLOTS:
void unsignedIntegerConsistency();
void signedIntegerConsistency_data();
void signedIntegerConsistency();
+ void extendedIntegerConsistency();
void floatingPointConsistency_data();
void floatingPointConsistency();
void stringConsistency_data();
@@ -151,6 +152,11 @@ static void unsignedIntegerConsistency(quint64 value, size_t seed)
if (v32 == value)
QCOMPARE(hu64, hu32);
+#if QT_SUPPORTS_INT128
+ const auto hu128 = qHash(quint128(value), seed);
+ QCOMPARE(hu128, hu64);
+#endif
+
// there are a few more unsigned types:
#ifdef __cpp_char8_t
const auto hc8 = qHash(char8_t(value), seed);
@@ -193,6 +199,11 @@ void tst_QHashFunctions::signedIntegerConsistency()
QCOMPARE(hs64, hs32);
}
+#if QT_SUPPORTS_INT128
+ const auto hs128 = qHash(qint128(value), seed);
+ QCOMPARE(hs128, hs64);
+#endif
+
if (value > 0) {
quint64 u64 = quint64(value);
const auto hu64 = qHash(u64, seed);
@@ -202,6 +213,20 @@ void tst_QHashFunctions::signedIntegerConsistency()
}
}
+void tst_QHashFunctions::extendedIntegerConsistency()
+{
+#ifdef QT_SUPPORTS_INT128
+ // We only need to check qint128 and quint128 consistency here.
+ qint128 v65bit = Q_INT128_C(0x1'abea'06b7'dcf5'106a);
+ qint128 v127bit = Q_INT128_C(0x387c'ac7a'22a0'5242'9ee9'bcaa'6a53'13af);
+
+ QCOMPARE(qHash(quint128(v65bit), seed), qHash(v65bit, seed));
+ QCOMPARE(qHash(quint128(v127bit), seed), qHash(v127bit, seed));
+#else
+ QSKIP("This platform does not support extended integer types.");
+#endif
+}
+
void tst_QHashFunctions::floatingPointConsistency_data()
{
QTest::addColumn<double>("value");