diff options
Diffstat (limited to 'tests/auto/corelib')
13 files changed, 217 insertions, 17 deletions
diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index 2345bb39c1..b70dcd4a3b 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -30,11 +30,17 @@ #include <QtTest/QtTest> #include <QtCore/qendian.h> #include <QtCore/private/qendian_p.h> - +#include <QtCore/qsysinfo.h> class tst_QtEndian: public QObject { Q_OBJECT +public: + enum Signedness { + Unsigned, + Signed + }; + Q_ENUM(Signedness); private slots: void fromBigEndian(); @@ -55,6 +61,9 @@ private slots: void endianIntegers(); void endianBitfields(); + + void endianBitfieldUnions_data(); + void endianBitfieldUnions(); }; struct TestData @@ -383,5 +392,103 @@ void tst_QtEndian::endianBitfields() QCOMPARE(u.bottom, -8); } +template<template<typename... Accessors> class Union, template<int, int, typename> class Member> +void testBitfieldUnion() +{ + using upper = Member<21, 11, uint>; + using lower = Member<10, 11, uint>; + using bottom = Member<0, 10, int>; + + using UnionType = Union<upper, lower, bottom>; + UnionType u; + + u.template set<upper>(200); + QCOMPARE(u.template get<upper>(), 200U); + u.template set<lower>(1000); + u.template set<bottom>(-8); + QCOMPARE(u.template get<lower>(), 1000U); + QCOMPARE(u.template get<upper>(), 200U); + + u.template set<lower>(u.template get<lower>() + u.template get<upper>()); + QCOMPARE(u.template get<upper>(), 200U); + QCOMPARE(u.template get<lower>(), 1200U); + + u.template set<upper>(65536 + 7); + u.template set<lower>(65535); + QCOMPARE(u.template get<lower>(), 65535U & ((1<<11) - 1)); + QCOMPARE(u.template get<upper>(), 7U); + + QCOMPARE(u.template get<bottom>(), -8); + + UnionType u2(QSpecialIntegerBitfieldZero); + QCOMPARE(u2.data(), 0U); + + UnionType u3(42U); + QCOMPARE(u3.data(), 42U); + +// We'd need if constexpr to test this: +// +// using BEUintAccessor = QSpecialIntegerAccessor<QBigEndianStorageType<uint>, 21, 11>; +// using LEUintAccessor = QSpecialIntegerAccessor<QLittleEndianStorageType<uint>, 21, 11>; +// using BEIntAccessor = QSpecialIntegerAccessor<QBigEndianStorageType<int>, 0, 10>; +// using LEIntAccessor = QSpecialIntegerAccessor<QLittleEndianStorageType<int>, 0, 10>; + +// if constexpr (std::is_same<BEUintAccessor, upper>::value) { +// QCOMPARE(u.template get<BEUintAccessor>(), 7U); +// } else if constexpr (std::is_same<LEUintAccessor, upper>::value) { +// QCOMPARE(u.template get<LEUintAccessor>(), 7U); +// } else if constexpr (std::is_same<BEIntAccessor, bottom>::value) { +// QCOMPARE(u.template get<BEIntAccessor>(), -8); +// } else if constexpr (std::is_same<LEIntAccessor, bottom>::value) { +// QCOMPARE(u.template get<LEIntAccessor>(), -8); +// } else { +// QFAIL("none of the manually defined accessors match"); +// } +} + +Q_DECLARE_METATYPE(QSysInfo::Endian) +void tst_QtEndian::endianBitfieldUnions_data() +{ + QTest::addColumn<QSysInfo::Endian>("byteOrder"); + QTest::addColumn<Signedness>("signedness"); + + QTest::addRow("little endian unsigned") << QSysInfo::LittleEndian << Unsigned; + QTest::addRow("little endian signed") << QSysInfo::LittleEndian << Signed; + QTest::addRow("big endian unsigned") << QSysInfo::BigEndian << Unsigned; + QTest::addRow("big endian signed") << QSysInfo::BigEndian << Signed; +} + +void tst_QtEndian::endianBitfieldUnions() +{ + QFETCH(QSysInfo::Endian, byteOrder); + QFETCH(Signedness, signedness); + + switch (byteOrder) { + case QSysInfo::LittleEndian: + switch (signedness) { + case Unsigned: + testBitfieldUnion<quint32_le_bitfield_union, quint32_le_bitfield_member>(); + return; + case Signed: + testBitfieldUnion<qint32_le_bitfield_union, qint32_le_bitfield_member>(); + return; + } + Q_UNREACHABLE(); + return; + case QSysInfo::BigEndian: + switch (signedness) { + case Unsigned: + testBitfieldUnion<quint32_be_bitfield_union, quint32_be_bitfield_member>(); + return; + case Signed: + testBitfieldUnion<qint32_be_bitfield_union, qint32_be_bitfield_member>(); + return; + } + Q_UNREACHABLE(); + return; + } +} + + QTEST_MAIN(tst_QtEndian) #include "tst_qtendian.moc" diff --git a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp index 4968742110..6f37f85230 100644 --- a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp @@ -42,6 +42,7 @@ private slots: void writeBlock_data(); void writeBlock(); void seek(); + void invalidSeeks(); void seekTest_data(); void seekTest(); void read_rawdata(); @@ -286,6 +287,29 @@ void tst_QBuffer::seek() QCOMPARE(buffer.size(), pos); } +void tst_QBuffer::invalidSeeks() +{ + if (sizeof(qsizetype) == sizeof(qint64)) { + // sizeof(qsizetype) == sizeof(qint64), so +1 would overflow + QSKIP("This is a 32-bit-only test."); + } else { + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + QCOMPARE(buffer.buffer().size(), qsizetype(0)); + QCOMPARE(buffer.pos(), qint64(0)); + constexpr qint64 MaxQByteArrayCapacity = (std::numeric_limits<qsizetype>::max)(); + // this should fail fast, not after trying to allocate nearly 2 GiB of data, + // potentially crashing in the process: + QVERIFY(!buffer.seek(2 * MaxQByteArrayCapacity - 1)); + QCOMPARE(buffer.buffer().size(), qsizetype(0)); + QCOMPARE(buffer.pos(), qint64(0)); + // ditto: + QVERIFY(!buffer.seek(MaxQByteArrayCapacity + 1)); + QCOMPARE(buffer.buffer().size(), qsizetype(0)); + QCOMPARE(buffer.pos(), qint64(0)); + } +} + void tst_QBuffer::seekTest_data() { writeBlock_data(); diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 19b3289390..2e2209ac5d 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -369,7 +369,7 @@ protected: const char *nm = name.constData(); int tp = qRegisterMetaType<Bar>(nm); #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) - pthread_yield(); + sched_yield(); #endif QMetaType info(tp); if (!info.isValid()) { diff --git a/tests/auto/corelib/serialization/qxmlstream/data/019.ref b/tests/auto/corelib/serialization/qxmlstream/data/019.ref index 314efb2b04..9ae28f42e5 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/019.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/019.ref @@ -3,5 +3,5 @@ Comment( text=" Simple legal case: prefixed element " ) StartElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a" NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/namespace" ) ) -EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" ) +EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a" ) EndDocument( ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/024.ref b/tests/auto/corelib/serialization/qxmlstream/data/024.ref index 83c3ac5315..43cf2b1faf 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/024.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/024.ref @@ -8,8 +8,8 @@ Characters( whitespace text=" StartElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a" NamespaceDeclaration( prefix="a" namespaceUri="http://example.org/other-namespace" ) ) -EndElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" ) +EndElement( name="foo" namespaceUri="http://example.org/other-namespace" qualifiedName="a:foo" prefix="a" ) Characters( whitespace text=" " ) -EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" ) +EndElement( name="foo" namespaceUri="http://example.org/namespace" qualifiedName="a:foo" prefix="a" ) EndDocument( ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/039.ref b/tests/auto/corelib/serialization/qxmlstream/data/039.ref index 63ee6b4def..f7413e5436 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/039.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/039.ref @@ -16,7 +16,7 @@ StartElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName Attribute( name="attr" qualifiedName="attr" value="2" ) ) -EndElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName="b:bar" ) +EndElement( name="bar" namespaceUri="http://example.org/~kipper" qualifiedName="b:bar" prefix="b" ) Characters( whitespace text=" " ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/041.ref b/tests/auto/corelib/serialization/qxmlstream/data/041.ref index 3e7ca64208..50328feb4a 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/041.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/041.ref @@ -12,7 +12,7 @@ StartElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName Attribute( name="attr" qualifiedName="attr" value="2" ) ) -EndElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName="a:bar" ) +EndElement( name="bar" namespaceUri="http://example.org/~wilbur" qualifiedName="a:bar" prefix="a" ) Characters( whitespace text=" " ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/1.ref b/tests/auto/corelib/serialization/qxmlstream/data/1.ref index 0288cf0e11..41a9febd8e 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/1.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/1.ref @@ -4,5 +4,5 @@ StartElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" pref NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" ) ) -EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" ) +EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" prefix="ns" ) EndDocument( ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/2.ref b/tests/auto/corelib/serialization/qxmlstream/data/2.ref index 95d68efbd6..2fad9844ce 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/2.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/2.ref @@ -5,5 +5,5 @@ StartElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" pref NamespaceDeclaration( prefix="ns" namespaceUri="namespaceUri" ) ) Characters( text="The world goes round and round" ) -EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" ) +EndElement( name="doc" namespaceUri="namespaceUri" qualifiedName="ns:doc" prefix="ns" ) EndDocument( ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/21.ref b/tests/auto/corelib/serialization/qxmlstream/data/21.ref index 1098c6800f..d0e4982eec 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/21.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/21.ref @@ -33,10 +33,10 @@ Characters( whitespace text=" " ) StartElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" prefix="html" ) Characters( text="test file" ) -EndElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" ) +EndElement( name="title" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:title" prefix="html" ) Characters( whitespace text=" " ) -EndElement( name="head" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:head" ) +EndElement( name="head" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:head" prefix="html" ) Characters( whitespace text=" " ) StartElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" prefix="html" ) @@ -46,11 +46,11 @@ StartElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName Attribute( name="class" qualifiedName="class" value="visible:false" ) ) Characters( text="bar" ) -EndElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:p" ) +EndElement( name="p" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:p" prefix="html" ) Characters( whitespace text=" " ) -EndElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" ) +EndElement( name="body" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:body" prefix="html" ) Characters( whitespace text=" " ) -EndElement( name="html" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:html" ) +EndElement( name="html" namespaceUri="http://www.w3.org/1999/xhtml" qualifiedName="html:html" prefix="html" ) EndDocument( ) diff --git a/tests/auto/corelib/serialization/qxmlstream/data/namespaceCDATA.ref b/tests/auto/corelib/serialization/qxmlstream/data/namespaceCDATA.ref index 132875f4bb..84538b0230 100644 --- a/tests/auto/corelib/serialization/qxmlstream/data/namespaceCDATA.ref +++ b/tests/auto/corelib/serialization/qxmlstream/data/namespaceCDATA.ref @@ -15,7 +15,7 @@ Characters( whitespace text=" StartElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" prefix="pre" NamespaceDeclaration( prefix="pre" namespaceUri="http://qt-project.org" ) ) -EndElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" ) +EndElement( name="bar" namespaceUri="http://qt-project.org" qualifiedName="pre:bar" prefix="pre" ) Characters( whitespace text=" " ) EndElement( name="body" qualifiedName="body" ) diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 33fcb156b6..84901f8f75 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -1778,7 +1778,8 @@ void tst_QLocale::toDateTime_data() QTest::addColumn<QDateTime>("result"); QTest::addColumn<QString>("format"); QTest::addColumn<QString>("string"); - QTest::addColumn<bool>("clean"); // No non-format letters in format string + // No non-format letters in format string, no time-zone (t format): + QTest::addColumn<bool>("clean"); QTest::newRow("1C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 0)) << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14" << true; @@ -1832,6 +1833,21 @@ void tst_QLocale::toDateTime_data() QTest::newRow("12no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0)) << "d'd'dd/M/yyh" << "1d01/12/7415" << false; + QTest::newRow("short-ss") // QTBUG-102199: trips over an assert in CET + << "C" << QDateTime() // Single-digit seconds does not match ss format. + << QStringLiteral("ddd, d MMM yyyy HH:mm:ss") + << QStringLiteral("Sun, 29 Mar 2020 02:26:3") << true; + + QTest::newRow("short-ss-Z") // Same, but with a valid date-time: + << "C" << QDateTime() + << QStringLiteral("ddd, d MMM yyyy HH:mm:ss t") + << QStringLiteral("Sun, 29 Mar 2020 02:26:3 Z") << false; + + QTest::newRow("s-Z") // Same, but with a format that accepts the single digit: + << "C" << QDateTime(QDate(2020, 3, 29), QTime(2, 26, 3), Qt::UTC) + << QStringLiteral("ddd, d MMM yyyy HH:mm:s t") + << QStringLiteral("Sun, 29 Mar 2020 02:26:3 Z") << false; + QTest::newRow("RFC-1123") << "C" << QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30)) << "ddd, dd MMM yyyy hh:mm:ss 'GMT'" << "Thu, 01 Nov 2007 18:08:30 GMT" << false; diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index a59b58d57f..412f092377 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -31,6 +31,8 @@ #include <private/qtimezoneprivate_p.h> #include <qlocale.h> +Q_DECLARE_METATYPE(QTimeZone::TimeType) + #if defined(Q_OS_WIN) && !QT_CONFIG(icu) # define USING_WIN_TZ #endif @@ -70,6 +72,8 @@ private slots: void macTest(); void darwinTypes(); void winTest(); + void localeSpecificDisplayName_data(); + void localeSpecificDisplayName(); private: void printTimeZone(const QTimeZone &tz); @@ -1366,6 +1370,55 @@ void tst_QTimeZone::winTest() #endif // QT_BUILD_INTERNAL && USING_WIN_TZ } +void tst_QTimeZone::localeSpecificDisplayName_data() +{ +#ifdef USING_WIN_TZ + QSKIP("MS backend does not use locale parameter"); +#endif + QTest::addColumn<QByteArray>("zoneName"); + QTest::addColumn<QLocale>("locale"); + QTest::addColumn<QTimeZone::TimeType>("timeType"); + QTest::addColumn<QString>("expectedName"); + + QStringList names; + QLocale locale; + // Pick a non-system locale; German or French + if (QLocale::system().language() != QLocale::German) { + locale = QLocale(QLocale::German); + names << QString("Mitteleurop\u00e4ische Normalzeit") + << QString("Mitteleurop\u00e4ische Sommerzeit"); + } else { + locale = QLocale(QLocale::French); + names << QString("heure normale d\u2019Europe centrale") + << QString("heure d\u2019\u00E9t\u00E9 d\u2019Europe centrale"); + } + + qsizetype index = 0; + QTest::newRow("Berlin, standard time") + << QByteArray("Europe/Berlin") << locale << QTimeZone::StandardTime + << names.at(index++); + + QTest::newRow("Berlin, summer time") + << QByteArray("Europe/Berlin") << locale << QTimeZone::DaylightTime + << names.at(index++); +} + +void tst_QTimeZone::localeSpecificDisplayName() +{ + // This test checks that QTimeZone::displayName() correctly uses the + // specified locale, NOT the system locale (see QTBUG-101460). + QFETCH(QByteArray, zoneName); + QFETCH(QLocale, locale); + QFETCH(QTimeZone::TimeType, timeType); + QFETCH(QString, expectedName); + + QTimeZone zone(zoneName); + QVERIFY(zone.isValid()); + + const QString localeName = zone.displayName(timeType, QTimeZone::LongName, locale); + QCOMPARE(localeName, expectedName); +} + #ifdef QT_BUILD_INTERNAL // Test each private produces the same basic results for CET void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp) |