diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-08-15 13:22:04 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-08-16 12:56:50 +0000 |
commit | c86cf385d6d66d8fd3de1666205aaf4b8fcec747 (patch) | |
tree | c0010369e354ca9eeff4e9efc82714cf18347d7f /tests/auto/corelib/tools | |
parent | f7953cdee6eed997f1b5f3e5085dac405f3d5e31 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 6b8c5a76be..700102f834 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -5,6 +5,7 @@ #include <QVarLengthArray> #include <qhash.h> +#include <qfloat16.h> #include <iterator> #include <sstream> @@ -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() |