From c86cf385d6d66d8fd3de1666205aaf4b8fcec747 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 15 Aug 2023 13:22:04 +0200 Subject: [PATCH] tst_QHashFunctions: extend the consistency() test with int/FP types It's ... broken. Found and filed lots of bugs. Add #ifdef'ery and QEXPECTED_FAIL() to document the state of affairs, hopefully reminding us to fix these things come Qt 7. Task-number: QTBUG-116064 Task-number: QTBUG-116076 Task-number: QTBUG-116077 Task-number: QTBUG-116079 Task-number: QTBUG-116080 Pick-to: 6.6 6.5 Change-Id: I29e89fdf995ddf60ef1e03c7af009e80980c9817 Reviewed-by: Thiago Macieira --- .../qhashfunctions/tst_qhashfunctions.cpp | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 6b8c5a76beb..700102f834b 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -65,6 +66,60 @@ void tst_QHashFunctions::consistent() // QString-like const QString s = QStringLiteral("abcdefghijklmnopqrstuvxyz").repeated(16); QCOMPARE(qHash(s, seed), qHash(QStringView(s), seed)); + + // unsigned integers + { + constexpr unsigned char ae = 0xE4; // LATIN SMALL LETTER A WITH DIAERESIS + const auto h8 = qHash(quint8(ae), seed); + const auto h16 = qHash(quint16(ae), seed); + const auto h32 = qHash(quint32(ae), seed); + const auto h64 = qHash(quint64(ae), seed); + QCOMPARE(h8, h16); + QCOMPARE(h16, h32); + QCOMPARE(h32, h64); + // there are a few more unsigned types: +#ifdef __cpp_char8_t + const auto hc8 = qHash(char8_t(ae), seed); +#endif + const auto hc16 = qHash(char16_t(ae), seed); + const auto hc32 = qHash(char32_t(ae), seed); +#ifdef __cpp_char8_t + QCOMPARE(hc8, h8); +#endif + QCOMPARE(hc16, h16); + QCOMPARE(hc32, h32); + } + + // signed integers + { + constexpr signed char ae = 0xE4; // LATIN SMALL LETTER A WITH DIAERESIS + const auto h8 = qHash(qint8(ae), seed); + const auto h16 = qHash(qint16(ae), seed); + const auto h32 = qHash(qint32(ae), seed); + const auto h64 = qHash(qint64(ae), seed); + QCOMPARE(h8, h16); + QCOMPARE(h16, h32); + if constexpr (sizeof(size_t) == sizeof(int)) // 32-bit + QEXPECT_FAIL("", "QTBUG-116080", Continue); + QCOMPARE(h32, h64); + } + + // floats + { + const/*expr broken: QTBUG-116079*/ qfloat16 f16 = -42.f; +#if !QFLOAT16_IS_NATIVE // QTBUG-116064 + const auto h16 = qHash(f16, seed); +#endif + const auto h32 = qHash(float(f16), seed); + const auto h64 = qHash(double(f16), seed); +#if !QFLOAT16_IS_NATIVE // QTBUG-116064 + if (seed != 0) + QEXPECT_FAIL("", "QTBUG-116076", Continue); + QCOMPARE(h16, h32); +#endif + QEXPECT_FAIL("", "QTBUG-116077", Continue); + QCOMPARE(h32, h64); + } } void tst_QHashFunctions::initTestCase()