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
Change-Id: I29e89fdf995ddf60ef1e03c7af009e80980c9817
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit c86cf385d6d66d8fd3de1666205aaf4b8fcec747)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-08-15 13:22:04 +02:00 committed by Qt Cherry-pick Bot
parent 3e09f3abbb
commit 3a9bbf235d

View File

@ -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()