From bf65c277892f6f322fa689c06d81ba9b1d9a8038 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 2 Dec 2019 16:15:14 +0100 Subject: Fix more mis-handling of spaces in ISO date format strings ISO date format doesn't allow spaces within a date, although 3339 does allow a space to replace the T between date and time. Sixteen tests added to check this all failed. So clean up the handling of spaces in the parsing of ISO date-time strings. [ChangeLog][QtCore][QDateTime] ISO 8601: parsing of dates now requires a punctuator as separator (it previously allowed any non-digit; officially only a dash should be allowed) and parsing of date-times no longer tolerates spaces in the numeric fields: an internal space is only allowed in an ISO 8601 date-time as replacement for the T between date and time. Change-Id: I24d110e71d416ecef74e196d5ee270b59d1bd813 Reviewed-by: Thiago Macieira --- .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 7778542736..c03d112560 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2213,8 +2213,46 @@ void tst_QDateTime::fromStringDateFormat_data() QTest::newRow("trailing space") // QTBUG-80445 << QString("2000-01-02 03:04:05.678 ") << Qt::ISODate << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5, 678)); + + // Invalid spaces (but keeping field widths correct): QTest::newRow("space before millis") << QString("2000-01-02 03:04:05. 678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after seconds") + << QString("2000-01-02 03:04:5 .678") << Qt::ISODate << QDateTime(); + QTest::newRow("space before seconds") + << QString("2000-01-02 03:04: 5.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after minutes") + << QString("2000-01-02 03:4 :05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space before minutes") + << QString("2000-01-02 03: 4:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after hour") + << QString("2000-01-02 3 :04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space before hour") + << QString("2000-01-02 3:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after day") + << QString("2000-01-2 03:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space before day") + << QString("2000-01- 2 03:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after month") + << QString("2000-1 -02 03:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space before month") + << QString("2000- 1-02 03:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("space after year") + << QString("200 -01-02 03:04:05.678") << Qt::ISODate << QDateTime(); + + // Spaces as separators: + QTest::newRow("sec-milli space") + << QString("2000-01-02 03:04:05 678") << Qt::ISODate + // Should be invalid, but we ignore trailing cruft (in some cases) + << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5)); + QTest::newRow("min-sec space") + << QString("2000-01-02 03:04 05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("hour-min space") + << QString("2000-01-02 03 04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("mon-day space") + << QString("2000-01 02 03:04:05.678") << Qt::ISODate << QDateTime(); + QTest::newRow("year-mon space") + << QString("2000 01-02 03:04:05.678") << Qt::ISODate << QDateTime(); // Normal usage: QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00") -- cgit v1.2.3 From 0d4dea728ff3b7f15a7ddb22d94c54087e98f53d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 31 May 2019 15:52:52 -0700 Subject: MIME: Make the internal database direct content, not a Qt resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This saves us from having to bootstrap rcc in regular (non-cross) compilations, as it can now link to QtCore. Actually un-bootstrapping rcc is left as an exercise for the reader. This commit discovered that MSVC cannot handle constexpr arrays bigger than 256 kB, at which point it simply starts claiming that the constant expressions using it are not constexpr. ICC has a similar problem at 64 kB, but it tells you why ("note: type "const unsigned char [65537]" too large for constant-expression evaluation"). Note also that this requires gzip or zstd to be in PATH for compression to happen. RCC linked to zlib, which is always present due to the bundled copy. gzip's presence is not likely to be a problem on Unix systems, but could be for Windows users, especially MSVC ones. If gzip is not present, QtCore's size will increase by about 1910 kB of read-only (sharable) data. Change-Id: I2b1955a995ad40f3b89afffd15a3e65a94670242 Reviewed-by: Edward Welbourne --- .../io/qresourceengine/tst_qresourceengine.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 44c8c4b681..bdbc1c6928 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -30,7 +30,6 @@ #include #include -#include class tst_QResourceEngine: public QObject { @@ -119,24 +118,20 @@ void tst_QResourceEngine::checkStructure_data() QStringList rootContents; rootContents << QLatin1String("aliasdir") +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + << QLatin1String("android_testdata") +#endif << QLatin1String("otherdir") - << QLatin1String("qt-project.org") << QLatin1String("runtime_resource") << QLatin1String("searchpath1") << QLatin1String("searchpath2") << QLatin1String("secondary_root") << QLatin1String("staticplugin") << QLatin1String("test") - << QLatin1String("withoutslashes"); - -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) - rootContents.insert(1, QLatin1String("android_testdata")); -#endif - #if defined(BUILTIN_TESTDATA) - rootContents.insert(9, QLatin1String("testqrc")); + << QLatin1String("testqrc") #endif - + << QLatin1String("withoutslashes"); QTest::newRow("root dir") << QString(":/") << QByteArray() @@ -352,11 +347,6 @@ void tst_QResourceEngine::checkStructure() QFETCH(QLocale, locale); QFETCH(qlonglong, contentsSize); - // We rely on the existence of the root "qt-project.org" in resources. For - // static builds on MSVC these resources are only added if they are used. - QMimeDatabase db; - Q_UNUSED(db); - bool directory = (containedDirs.size() + containedFiles.size() > 0); QLocale::setDefault(locale); -- cgit v1.2.3 From c15d6a155c6121bad68a3ec60be62181fb92d0f8 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 10 Dec 2019 14:55:14 +0100 Subject: QVariant: introduce ShouldDeleteVariantData flag This flag is used in QSequentialIterable and QAssociativeIterable to indicate that the data pointer in VariantData should be deleted after the variant has been constructed. The use case for this is https://codereview.qt-project.org/c/qt/qtdeclarative/+/284151, where we have a proxy iterator and cannot easily return a pointer to already owned data, as it is hard to manage its lifetime in the iterator. In contrast, it is clear that we can release the memory in the QSequentialIterable functions, as it has already been copied into the QVariant there. Change-Id: I2b33497d991cd4f752153e0ebda767b82e4bb851 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 97 +++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index edb15a8db2..e719871128 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -276,7 +277,8 @@ private slots: void nullConvert(); void accessSequentialContainerKey(); - + void shouldDeleteVariantDataWorksForSequential(); + void shouldDeleteVariantDataWorksForAssociative(); void fromStdVariant(); void qt4UuidDataStream(); @@ -4990,6 +4992,99 @@ void tst_QVariant::accessSequentialContainerKey() QCOMPARE(nameResult, QStringLiteral("Seven")); } +void tst_QVariant::shouldDeleteVariantDataWorksForSequential() +{ + QCOMPARE(instanceCount, 0); + { + QtMetaTypePrivate::QSequentialIterableImpl iterator {}; + iterator._iteratorCapabilities = QtMetaTypePrivate::RandomAccessCapability | + QtMetaTypePrivate::BiDirectionalCapability | + QtMetaTypePrivate::ForwardCapability; + iterator._metaType_flags = QVariantConstructionFlags::ShouldDeleteVariantData; + + iterator._size = [](const void *) {return 1;}; + iterator._metaType_id = qMetaTypeId(); + iterator._moveToBegin = [](const void *, void **) {}; + iterator._moveToEnd = [](const void *, void **) {}; + iterator._advance = [](void **, int) {}; + iterator._destroyIter = [](void **){}; + iterator._equalIter = [](void * const *, void * const *){return true; /*all iterators are nullptr*/}; + iterator._destroyIter = [](void **){}; + iterator._at = [](const void *, int ) -> void const * { + MyType mytype {1, "eins"}; + return QMetaType::create(qMetaTypeId(), &mytype); + }; + iterator._get = [](void * const *, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {2, "zwei"}; + return {qMetaTypeId(), QMetaType::create(qMetaTypeId(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + QSequentialIterable iterable {iterator}; + QVariant value1 = iterable.at(0); + QVERIFY(value1.canConvert()); + QCOMPARE(value1.value().number, 1); + QVariant value2 = *iterable.begin(); + QVERIFY(value2.canConvert()); + QCOMPARE(value2.value().number, 2); + } + QCOMPARE(instanceCount, 0); +} + +void tst_QVariant::shouldDeleteVariantDataWorksForAssociative() +{ + QCOMPARE(instanceCount, 0); + { + QtMetaTypePrivate::QAssociativeIterableImpl iterator {}; + iterator._metaType_flags_key = QVariantConstructionFlags::ShouldDeleteVariantData; + iterator._metaType_flags_value = QVariantConstructionFlags::ShouldDeleteVariantData; + + iterator._size = [](const void *) {return 1;}; + iterator._metaType_id_value = qMetaTypeId(); + iterator._metaType_id_key = qMetaTypeId(); + iterator._begin = [](const void *, void **) {}; + iterator._end = [](const void *, void **) {}; + iterator._advance = [](void **, int) {}; + iterator._destroyIter = [](void **){}; + iterator._equalIter = [](void * const *, void * const *){return true; /*all iterators are nullptr*/}; + iterator._destroyIter = [](void **){}; + iterator._find = [](const void *, const void *, void **iterator ) -> void { + (*iterator) = reinterpret_cast(quintptr(42)); + }; + iterator._getKey = [](void * const *iterator, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {1, "key"}; + if (reinterpret_cast(*iterator) == 42) { + mytype.number = 42; + mytype.text = "find_key"; + } + return {qMetaTypeId(), QMetaType::create(qMetaTypeId(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + iterator._getValue = [](void * const *iterator, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {2, "value"}; + if (reinterpret_cast(*iterator) == 42) { + mytype.number = 42; + mytype.text = "find_value"; + } + return {qMetaTypeId(), QMetaType::create(qMetaTypeId(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + QAssociativeIterable iterable {iterator}; + auto it = iterable.begin(); + QVariant value1 = it.key(); + QVERIFY(value1.canConvert()); + QCOMPARE(value1.value().number, 1); + QCOMPARE(value1.value().text, "key"); + QVariant value2 = it.value(); + QVERIFY(value2.canConvert()); + QCOMPARE(value2.value().number, 2); + auto findIt = iterable.find(QVariant::fromValue(MyType {})); + value1 = findIt.key(); + QCOMPARE(value1.value().number, 42); + QCOMPARE(value1.value().text, "find_key"); + value2 = findIt.value(); + QCOMPARE(value2.value().number, 42); + QCOMPARE(value2.value().text, "find_value"); + } + QCOMPARE(instanceCount, 0); +} + void tst_QVariant::fromStdVariant() { #if __has_include() && __cplusplus >= 201703L -- cgit v1.2.3 From d98a1ef902527ca2351ec6bf18872a4226953487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 6 Nov 2019 18:04:45 +0100 Subject: Add QMap::insert(const QMap &map) As opposed to unite(), this inserts one map into the other without duplicating elements. Task-number: QTBUG-35544 Change-Id: Ie8ab350b29148851a3176cef1007e8a4ca82c273 Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qmap/tst_qmap.cpp | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index d66fd28779..c3a8a88f0c 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -71,6 +71,7 @@ private slots: void setSharable(); void insert(); + void insertMap(); void checkMostLeftNode(); void initializerList(); void testInsertWithHint(); @@ -1265,6 +1266,101 @@ void tst_QMap::insert() } } +void tst_QMap::insertMap() +{ + { + QMap map; + map.insert(1, 1); + map.insert(2, 2); + map.insert(0, -1); + + QMap map2; + map2.insert(0, 0); + map2.insert(3, 3); + map2.insert(4, 4); + + map.insert(map2); + + QCOMPARE(map.count(), 5); + for (int i = 0; i < 5; ++i) + QCOMPARE(map[i], i); + } + { + QMap map; + for (int i = 0; i < 10; ++i) + map.insert(i * 3, i); + + QMap map2; + for (int i = 0; i < 10; ++i) + map2.insert(i * 4, i); + + map.insert(map2); + + QCOMPARE(map.count(), 17); + for (int i = 0; i < 10; ++i) { + // i * 3 == i except for i = 4, 8 + QCOMPARE(map[i * 3], (i && i % 4 == 0) ? i - (i / 4) : i); + QCOMPARE(map[i * 4], i); + } + + auto it = map.cbegin(); + int prev = it.key(); + ++it; + for (auto end = map.cend(); it != end; ++it) { + QVERIFY(prev < it.key()); + prev = it.key(); + } + } + { + QMap map; + map.insert(1, 1); + + QMap map2; + + map.insert(map2); + QCOMPARE(map.count(), 1); + QCOMPARE(map[1], 1); + } + { + QMap map; + QMap map2; + map2.insert(1, 1); + + map.insert(map2); + QCOMPARE(map.count(), 1); + QCOMPARE(map[1], 1); + } + { + QMap map; + map.insert(0, 0); + map.insert(1, 1); + map.insert(2, 2); + + // Test inserting into self, nothing should happen + map.insert(map); + + QCOMPARE(map.count(), 3); + for (int i = 0; i < 3; ++i) + QCOMPARE(map[i], i); + } + { + // Here we use a QMultiMap and insert that into QMap, + // since it has multiple values with the same key the + // ordering is undefined so we won't test that, but + // make sure this isn't adding multiple entries with the + // same key to the QMap. + QMap map; + QMultiMap map2; + map2.insert(0, 0); + map2.insert(0, 1); + map2.insert(0, 2); + + map.insert(map2); + + QCOMPARE(map.count(), 1); + } +} + void tst_QMap::checkMostLeftNode() { QMap map; -- cgit v1.2.3 From 0edd2e39ad7f959c3d0c56e79abd3c60d9950538 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 11 Dec 2019 19:48:53 +0100 Subject: Let QItemSelectionModel::columnIntersectsSelection honor the parent QItemSelectionModel::columnIntersectsSelection() should honor the parent according to the docs. For rowIntersectsSelection() this was fixed a long time ago but columnIntersectsSelection() was forgotten. Sync the both functions and use range-based for loops as a drive-by. Fixes: QTBUG-80644 Change-Id: Iaf08f85e2225204d1e6564fa4bb0bc826352ed53 Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- .../itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index c74101928a..80e5456306 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -2037,12 +2037,16 @@ void tst_QItemSelectionModel::rowIntersectsSelection3() QModelIndex parent; QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); } void tst_QItemSelectionModel::unselectable() -- cgit v1.2.3 From 4e04132264a1259d28dc55e1ad01f848562c4c6d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 2 Dec 2019 21:04:09 +0100 Subject: QStringListModel: fix moveRows() QStringListMode::moveRows() had an issue when the destination was before the source row. Change-Id: Icf64e5b4cdd6a39faf3ba4ccc3883196b247ccbd Reviewed-by: Luca Beldi Reviewed-by: David Faure --- .../qstringlistmodel/tst_qstringlistmodel.cpp | 53 ++++++++++------------ 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp index 3919472b96..7182553f27 100644 --- a/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp +++ b/tests/auto/corelib/itemmodels/qstringlistmodel/tst_qstringlistmodel.cpp @@ -103,28 +103,25 @@ void tst_QStringListModel::moveRowsInvalid_data() QTest::addColumn("destinationParent"); QTest::addColumn("destination"); - QStringListModel* tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("destination_equal_source") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << 1; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("count_equal_0") << tempModel << QModelIndex() << 0 << 0 << QModelIndex() << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); + const auto createModel = [this]() { + return new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); + }; + constexpr int rowCount = 6; + + QTest::addRow("destination_equal_source") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << 0; + QTest::addRow("count_equal_0") << createModel() << QModelIndex() << 0 << 0 << QModelIndex() << 2; + QStringListModel *tempModel = createModel(); QTest::addRow("move_child") << tempModel << tempModel->index(0, 0) << 0 << 1 << QModelIndex() << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); + tempModel = createModel(); QTest::addRow("move_to_child") << tempModel << QModelIndex() << 0 << 1 << tempModel->index(0, 0) << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("negative_count") << tempModel << QModelIndex() << 0 << -1 << QModelIndex() << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("negative_source_row") << tempModel << QModelIndex() << -1 << 1 << QModelIndex() << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("negative_destination_row") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << -1; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("source_row_equal_rowCount") << tempModel << QModelIndex() << tempModel->rowCount() << 1 << QModelIndex() << 1; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("destination_row_greater_rowCount") << tempModel << QModelIndex() << 0 << 1 << QModelIndex() << tempModel->rowCount() + 1; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("move_row_within_source_range") << tempModel << QModelIndex() << 0 << 3 << QModelIndex() << 2; - tempModel = new QStringListModel(QStringList{"A", "B", "C", "D", "E", "F"}, this); - QTest::addRow("destination_row_before_0") << tempModel << QModelIndex() << 1 << 1 << QModelIndex() << 0; + QTest::addRow("negative_count") << createModel() << QModelIndex() << 0 << -1 << QModelIndex() << 2; + QTest::addRow("negative_source_row") << createModel() << QModelIndex() << -1 << 1 << QModelIndex() << 2; + QTest::addRow("negative_destination_row") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << -1; + QTest::addRow("source_row_equal_rowCount") << createModel() << QModelIndex() << rowCount << 1 << QModelIndex() << 1; + QTest::addRow("source_row_equal_destination_row") << createModel() << QModelIndex() << 2 << 1 << QModelIndex() << 2; + QTest::addRow("source_row_equal_destination_row_plus_1") << createModel() << QModelIndex() << 2 << 1 << QModelIndex() << 3; + QTest::addRow("destination_row_greater_rowCount") << createModel() << QModelIndex() << 0 << 1 << QModelIndex() << rowCount + 1; + QTest::addRow("move_row_within_source_range") << createModel() << QModelIndex() << 0 << 3 << QModelIndex() << 2; } void tst_QStringListModel::moveRowsInvalid() @@ -155,20 +152,20 @@ void tst_QStringListModel::moveRows_data() QTest::newRow("1_Item_from_top_to_middle") << 0 << 1 << 3 << QStringList{"B", "C", "A", "D", "E", "F"}; QTest::newRow("1_Item_from_top_to_bottom") << 0 << 1 << 6 << QStringList{"B", "C", "D", "E", "F", "A"}; - QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"}; - QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 3 << QStringList{"A", "B", "F", "C", "D", "E"}; - QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 1 << QStringList{"F", "A", "B", "C", "D", "E"}; + QTest::newRow("1_Item_from_middle_to_top") << 2 << 1 << 0 << QStringList{"C", "A", "B", "D", "E", "F"}; + QTest::newRow("1_Item_from_bottom_to_middle") << 5 << 1 << 2 << QStringList{"A", "B", "F", "C", "D", "E"}; + QTest::newRow("1_Item_from_bottom to_top") << 5 << 1 << 0 << QStringList{"F", "A", "B", "C", "D", "E"}; QTest::newRow("1_Item_from_middle_to_bottom") << 2 << 1 << 6 << QStringList{"A", "B", "D", "E", "F", "C"}; - QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"C", "A", "B", "D", "E", "F"}; + QTest::newRow("1_Item_from_middle_to_middle_before") << 2 << 1 << 1 << QStringList{"A", "C", "B", "D", "E", "F"}; QTest::newRow("1_Item_from_middle_to_middle_after") << 2 << 1 << 4 << QStringList{"A", "B", "D", "C", "E", "F"}; QTest::newRow("2_Items_from_top_to_middle") << 0 << 2 << 3 << QStringList{"C", "A", "B", "D", "E", "F"}; QTest::newRow("2_Items_from_top_to_bottom") << 0 << 2 << 6 << QStringList{"C", "D", "E", "F", "A", "B"}; - QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 1 << QStringList{"C", "D", "A", "B", "E", "F"}; - QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 3 << QStringList{"A", "B", "E", "F", "C", "D"}; - QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 1 << QStringList{"E", "F", "A", "B", "C", "D"}; + QTest::newRow("2_Items_from_middle_to_top") << 2 << 2 << 0 << QStringList{"C", "D", "A", "B", "E", "F"}; + QTest::newRow("2_Items_from_bottom_to_middle") << 4 << 2 << 2 << QStringList{"A", "B", "E", "F", "C", "D"}; + QTest::newRow("2_Items_from_bottom_to_top") << 4 << 2 << 0 << QStringList{"E", "F", "A", "B", "C", "D"}; QTest::newRow("2_Items_from_middle_to_bottom") << 2 << 2 << 6 << QStringList{"A", "B", "E", "F", "C", "D"}; - QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 2 << QStringList{"A", "D", "E", "B", "C", "F"}; + QTest::newRow("2_Items_from_middle_to_middle_before") << 3 << 2 << 1 << QStringList{"A", "D", "E", "B", "C", "F"}; QTest::newRow("2_Items_from_middle_to_middle_after") << 1 << 2 << 5 << QStringList{"A", "D", "E", "B", "C", "F"}; } -- cgit v1.2.3 From a2ddd96ac8b7657c2ef64f2a8f51db5cd8a8d96a Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 18 Dec 2019 20:23:11 +0100 Subject: Introduce QString(View)::isValidUtf16 QString(View)s can be built or manipulated in ways that make them contain/refer to improperly encoded UTF-16 data. Problem is, we don't have public APIs to check whether a string contains valid UTF-16. This knowledge is precious if the string is to be fed in algorithms, regular expressions, etc. that expect validated input (e.g. QRegularExpression can be faster if it can assume valid UTF-16, otherwise it has to employ extra checks). Add a function that does the validation. [ChangeLog][QtCore][QStringView] Added QStringView::isValidUtf16. [ChangeLog][QtCore][QString] Added QString::isValidUtf16. Change-Id: Idd699183f6ec08013046c76c6a5a7c524b6c6fbc Reviewed-by: Thiago Macieira --- tests/auto/corelib/text/qstring/tst_qstring.cpp | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 2108e99f20..f86fbc5988 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -596,6 +596,8 @@ private slots: void assignQChar(); void isRightToLeft_data(); void isRightToLeft(); + void isValidUtf16_data(); + void isValidUtf16(); void unicodeStrings(); }; @@ -7025,6 +7027,52 @@ void tst_QString::isRightToLeft() QCOMPARE(unicode.isRightToLeft(), rtl); } +void tst_QString::isValidUtf16_data() +{ + QTest::addColumn("string"); + QTest::addColumn("valid"); + + int row = 0; + QTest::addRow("valid-%02d", row++) << QString() << true; + QTest::addRow("valid-%02d", row++) << QString("") << true; + QTest::addRow("valid-%02d", row++) << QString("abc def") << true; + QTest::addRow("valid-%02d", row++) << QString("àbç") << true; + QTest::addRow("valid-%02d", row++) << QString("ßẞ") << true; + QTest::addRow("valid-%02d", row++) << QString("𝐀𝐁𝐂abc𝐃𝐄𝐅def") << true; + QTest::addRow("valid-%02d", row++) << QString("abc𝐀𝐁𝐂def𝐃𝐄𝐅") << true; + QTest::addRow("valid-%02d", row++) << (QString("abc") + QChar(0x0000) + QString("def")) << true; + QTest::addRow("valid-%02d", row++) << (QString("abc") + QChar(0xFFFF) + QString("def")) << true; + // check that BOM presence doesn't make any difference + QTest::addRow("valid-%02d", row++) << (QString() + QChar(0xFEFF) + QString("abc𝐀𝐁𝐂def𝐃𝐄𝐅")) << true; + QTest::addRow("valid-%02d", row++) << (QString() + QChar(0xFFFE) + QString("abc𝐀𝐁𝐂def𝐃𝐄𝐅")) << true; + + row = 0; + QTest::addRow("stray-high-%02d", row++) << (QString() + QChar(0xD800)) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QString("abc") + QChar(0xD800)) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QChar(0xD800) + QString("def")) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QString("abc") + QChar(0xD800) + QString("def")) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QChar(0xD800) + QChar(0xD800)) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QString("abc") + QChar(0xD800) + QChar(0xD800)) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QChar(0xD800) + QChar(0xD800) + QString("def")) << false; + QTest::addRow("stray-high-%02d", row++) << (QString() + QString("abc") + QChar(0xD800) + QChar(0xD800) + QString("def")) << false; + + row = 0; + QTest::addRow("stray-low-%02d", row++) << (QString() + QChar(0xDC00)) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QString("abc") + QChar(0xDC00)) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QChar(0xDC00) + QString("def")) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QString("abc") + QChar(0xDC00) + QString("def")) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QChar(0xDC00) + QChar(0xDC00)) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QString("abc") + QChar(0xDC00) + QChar(0xDC00)) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QChar(0xDC00) + QChar(0xDC00) + QString("def")) << false; + QTest::addRow("stray-low-%02d", row++) << (QString() + QString("abc") + QChar(0xDC00) + QChar(0xDC00) + QString("def")) << false; +} + +void tst_QString::isValidUtf16() +{ + QFETCH(QString, string); + QTEST(string.isValidUtf16(), "valid"); +} + QTEST_APPLESS_MAIN(tst_QString) #include "tst_qstring.moc" -- cgit v1.2.3 From 27d139128013c969a939779536485c1a80be977e Mon Sep 17 00:00:00 2001 From: Tuomas Heimonen Date: Fri, 29 Nov 2019 09:27:35 +0200 Subject: QLocale: Support Indian number formatting When QLocale::Country is set to QLocale::India numbers are written so that after first three from the right and then after every second will be comma. E.g. 10000000 is written as 1,00,00,000 Task-number: QTBUG-24301 Change-Id: Ic06241c127b0af1824104f94f7e2ce6e2058a070 Reviewed-by: Venugopal Shivashankar Reviewed-by: Teemu Holappa --- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 20ed7500b5..8f434acb29 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -147,6 +147,8 @@ private slots: void systemLocale_data(); void systemLocale(); + void IndianNumberGrouping(); + // *** ORDER-DEPENDENCY *** (This Is Bad.) // Test order is determined by order of declaration here: *all* tests that // QLocale::setDefault() *must* appear *after* all other tests ! @@ -2991,5 +2993,56 @@ void tst_QLocale::systemLocale() QCOMPARE(QLocale::system(), originalSystemLocale); } +void tst_QLocale::IndianNumberGrouping() +{ + QLocale indian(QLocale::Hindi, QLocale::India); + + qint8 int8 = 100; + QString strResult8("100"); + QCOMPARE(indian.toString(int8), strResult8); + QCOMPARE(indian.toShort(strResult8), short(int8)); + + quint8 uint8 = 100; + QCOMPARE(indian.toString(uint8), strResult8); + QCOMPARE(indian.toShort(strResult8), short(uint8)); + + // Boundary case 1000 for short and ushort + short shortInt = 1000; + QString strResult16("1,000"); + QCOMPARE(indian.toString(shortInt), strResult16); + QCOMPARE(indian.toShort(strResult16), shortInt); + + ushort uShortInt = 1000; + QCOMPARE(indian.toString(uShortInt), strResult16); + QCOMPARE(indian.toUShort(strResult16), uShortInt); + + shortInt = 10000; + strResult16 = "10,000"; + QCOMPARE(indian.toString(shortInt), strResult16); + QCOMPARE(indian.toShort(strResult16), shortInt); + + uShortInt = 10000; + QCOMPARE(indian.toString(uShortInt), strResult16); + QCOMPARE(indian.toUShort(strResult16), uShortInt); + + int intInt = 1000000000; + QString strResult32("1,00,00,00,000"); + QCOMPARE(indian.toString(intInt), strResult32); + QCOMPARE(indian.toInt(strResult32), intInt); + + uint uIntInt = 1000000000; + QCOMPARE(indian.toString(uIntInt), strResult32); + QCOMPARE(indian.toUInt(strResult32), uIntInt); + + QString strResult64("10,00,00,00,00,00,00,00,000"); + qint64 int64 = Q_INT64_C(1000000000000000000); + QCOMPARE(indian.toString(int64), strResult64); + QCOMPARE(indian.toLongLong(strResult64), int64); + + quint64 uint64 = Q_UINT64_C(1000000000000000000); + QCOMPARE(indian.toString(uint64), strResult64); + QCOMPARE(indian.toULongLong(strResult64), uint64); +} + QTEST_MAIN(tst_QLocale) #include "tst_qlocale.moc" -- cgit v1.2.3 From cf033b32b56f82cbace1525394f32199cd3a32f7 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 30 Dec 2019 22:24:25 +0100 Subject: QDateTime: fix tests with Qt6 In Qt6 there is a behavior change with extra stuff after the seconds - it's no longer allowed and will result in an invalid QDateTime. This was introduced with bf65c277892f6f322fa689c06d81ba9b1d9a8038 but the autotests were not adjusted for it. Change-Id: Iee6a9a7ac6cbb2754a68e082bb7074d17fac9d9c Reviewed-by: Lars Knoll --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index c03d112560..6aae91f62f 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2243,8 +2243,12 @@ void tst_QDateTime::fromStringDateFormat_data() // Spaces as separators: QTest::newRow("sec-milli space") << QString("2000-01-02 03:04:05 678") << Qt::ISODate +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + << invalidDateTime(); +#else // Should be invalid, but we ignore trailing cruft (in some cases) << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5)); +#endif QTest::newRow("min-sec space") << QString("2000-01-02 03:04 05.678") << Qt::ISODate << QDateTime(); QTest::newRow("hour-min space") @@ -2332,7 +2336,11 @@ void tst_QDateTime::fromStringDateFormat_data() << Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime); // Test invalid characters (should ignore invalid characters at end of string). QTest::newRow("ISO invalid character at end") << QString::fromLatin1("2012-01-01T08:00:00!") +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + << Qt::ISODate << invalidDateTime(); +#else << Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime); +#endif QTest::newRow("ISO invalid character at front") << QString::fromLatin1("!2012-01-01T08:00:00") << Qt::ISODate << invalidDateTime(); QTest::newRow("ISO invalid character both ends") << QString::fromLatin1("!2012-01-01T08:00:00!") -- cgit v1.2.3 From 2ced01cbdd10a9959db03406f74529cdcce544ca Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 4 Dec 2015 12:44:45 +0100 Subject: QIdentityProxyModel: implement moveRows / moveColumns It makes sense for it (instead of triggering the QAbstractItemModel base class implementation, which doesn't do anything). Safe to override virtuals in this case -- code calling the old version could not do anything useful, so at least new code gets those functions properly implemented for free. Change-Id: Iefe1ff25e15d877435e93ab28289ad2579616f72 Task-number: QTBUG-48076 Reviewed-by: Luca Beldi Reviewed-by: David Faure --- .../tst_qidentityproxymodel.cpp | 102 ++++++++++++++------- 1 file changed, 67 insertions(+), 35 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp index c76052a38b..149d272594 100644 --- a/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "dynamictreemodel.h" @@ -69,6 +70,7 @@ private slots: void insertRows(); void removeRows(); void moveRows(); + void moveColumns(); void reset(); void dataChanged(); @@ -235,47 +237,24 @@ void tst_QIdentityProxyModel::removeRows() void tst_QIdentityProxyModel::moveRows() { - DynamicTreeModel model; - - { - ModelInsertCommand insertCommand(&model); - insertCommand.setStartRow(0); - insertCommand.setEndRow(9); - insertCommand.doCommand(); - } - { - ModelInsertCommand insertCommand(&model); - insertCommand.setAncestorRowNumbers(QList() << 5); - insertCommand.setStartRow(0); - insertCommand.setEndRow(9); - insertCommand.doCommand(); - } + QStringListModel model({"A", "B", "C", "D", "E", "F"}); m_proxy->setSourceModel(&model); verifyIdentity(&model); - QSignalSpy modelBeforeSpy(&model, &DynamicTreeModel::rowsAboutToBeMoved); - QSignalSpy modelAfterSpy(&model, &DynamicTreeModel::rowsMoved); - QSignalSpy proxyBeforeSpy(m_proxy, &QIdentityProxyModel::rowsAboutToBeMoved); - QSignalSpy proxyAfterSpy(m_proxy, &QIdentityProxyModel::rowsMoved); - - QVERIFY(modelBeforeSpy.isValid()); - QVERIFY(modelAfterSpy.isValid()); - QVERIFY(proxyBeforeSpy.isValid()); - QVERIFY(proxyAfterSpy.isValid()); + QSignalSpy modelBeforeSpy(&model, &QAbstractItemModel::rowsAboutToBeMoved); + QSignalSpy modelAfterSpy(&model, &QAbstractItemModel::rowsMoved); + QSignalSpy proxyBeforeSpy(m_proxy, &QAbstractItemModel::rowsAboutToBeMoved); + QSignalSpy proxyAfterSpy(m_proxy, &QAbstractItemModel::rowsMoved); - { - ModelMoveCommand moveCommand(&model, 0); - moveCommand.setAncestorRowNumbers(QList() << 5); - moveCommand.setStartRow(3); - moveCommand.setEndRow(4); - moveCommand.setDestRow(1); - moveCommand.doCommand(); - } + QVERIFY(m_proxy->moveRows(QModelIndex(), 1, 2, QModelIndex(), 5)); + QCOMPARE(model.stringList(), QStringList({"A", "D", "E", "B", "C", "F"})); - QVERIFY(modelBeforeSpy.size() == 1 && 1 == proxyBeforeSpy.size()); - QVERIFY(modelAfterSpy.size() == 1 && 1 == proxyAfterSpy.size()); + QCOMPARE(modelBeforeSpy.size(), 1); + QCOMPARE(proxyBeforeSpy.size(), 1); + QCOMPARE(modelAfterSpy.size(), 1); + QCOMPARE(proxyAfterSpy.size(), 1); QCOMPARE(modelBeforeSpy.first().first().value(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value())); QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1)); @@ -289,9 +268,62 @@ void tst_QIdentityProxyModel::moveRows() QCOMPARE(modelAfterSpy.first().at(3).value(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value())); QCOMPARE(modelAfterSpy.first().at(4), proxyAfterSpy.first().at(4)); + QVERIFY(m_proxy->moveRows(QModelIndex(), 3, 2, QModelIndex(), 1)); + QCOMPARE(model.stringList(), QStringList({"A", "B", "C", "D", "E", "F"})); + QVERIFY(m_proxy->moveRows(QModelIndex(), 0, 3, QModelIndex(), 6)); + QCOMPARE(model.stringList(), QStringList({"D", "E", "F", "A", "B", "C"})); + verifyIdentity(&model); - m_proxy->setSourceModel(0); + m_proxy->setSourceModel(nullptr); +} + +void tst_QIdentityProxyModel::moveColumns() +{ + // QStringListModel implements moveRows but not moveColumns + // so we have to use a QTransposeProxyModel inbetween to check if + // QIdentityProxyModel::moveColumns works as expected + QStringListModel model({"A", "B", "C", "D", "E", "F"}); + QTransposeProxyModel tpm; + tpm.setSourceModel(&model); + + m_proxy->setSourceModel(&tpm); + + verifyIdentity(&tpm); + + QSignalSpy modelBeforeSpy(&tpm, &QAbstractItemModel::columnsAboutToBeMoved); + QSignalSpy modelAfterSpy(&tpm, &QAbstractItemModel::columnsMoved); + QSignalSpy proxyBeforeSpy(m_proxy, &QAbstractItemModel::columnsAboutToBeMoved); + QSignalSpy proxyAfterSpy(m_proxy, &QAbstractItemModel::columnsMoved); + + QVERIFY(m_proxy->moveColumns(QModelIndex(), 1, 2, QModelIndex(), 5)); + QCOMPARE(model.stringList(), QStringList({"A", "D", "E", "B", "C", "F"})); + + QCOMPARE(proxyBeforeSpy.size(), 1); + QCOMPARE(modelBeforeSpy.size(), 1); + QCOMPARE(modelAfterSpy.size(), 1); + QCOMPARE(proxyAfterSpy.size(), 1); + + QCOMPARE(modelBeforeSpy.first().first().value(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value())); + QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1)); + QCOMPARE(modelBeforeSpy.first().at(2), proxyBeforeSpy.first().at(2)); + QCOMPARE(modelBeforeSpy.first().at(3).value(), m_proxy->mapToSource(proxyBeforeSpy.first().at(3).value())); + QCOMPARE(modelBeforeSpy.first().at(4), proxyBeforeSpy.first().at(4)); + + QCOMPARE(modelAfterSpy.first().first().value(), m_proxy->mapToSource(proxyAfterSpy.first().first().value())); + QCOMPARE(modelAfterSpy.first().at(1), proxyAfterSpy.first().at(1)); + QCOMPARE(modelAfterSpy.first().at(2), proxyAfterSpy.first().at(2)); + QCOMPARE(modelAfterSpy.first().at(3).value(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value())); + QCOMPARE(modelAfterSpy.first().at(4), proxyAfterSpy.first().at(4)); + + QVERIFY(m_proxy->moveColumns(QModelIndex(), 3, 2, QModelIndex(), 1)); + QCOMPARE(model.stringList(), QStringList({"A", "B", "C", "D", "E", "F"})); + QVERIFY(m_proxy->moveColumns(QModelIndex(), 0, 3, QModelIndex(), 6)); + QCOMPARE(model.stringList(), QStringList({"D", "E", "F", "A", "B", "C"})); + + verifyIdentity(&tpm); + + m_proxy->setSourceModel(nullptr); } void tst_QIdentityProxyModel::reset() -- cgit v1.2.3 From 21987679de013a4b1b655a6a06638f9fa293fdfc Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 3 Jan 2020 12:20:35 +0100 Subject: QTime: fix tests with Qt6 In Qt6 there is a behavior change with extra stuff after the seconds - it's no longer allowed and will result in an invalid QTime. This was introduced with bf65c277892f6f322fa689c06d81ba9b1d9a8038 but the autotests were not adjusted for it. Change-Id: Ia78f4f2a8019e46d9d0e8e8b8918a3ab2d4638e2 Reviewed-by: Liang Qi --- tests/auto/corelib/time/qtime/tst_qtime.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index d8de6e585d..f85e0ea74e 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -590,7 +590,12 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime(); QTest::newRow("TextDate - invalid, minute fraction") << QString::fromLatin1("23:00.123456") << Qt::TextDate << invalidTime(); QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime(); - QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate << QTime(23, 1, 1, 0); + QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + << invalidTime(); +#else + << QTime(23, 1, 1, 0); +#endif QTest::newRow("TextDate - midnight 24") << QString("24:00:00") << Qt::TextDate << QTime(); QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0); @@ -607,8 +612,12 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("IsoDate - invalid, not enough minutes") << QString::fromLatin1("23:0") << Qt::ISODate << invalidTime(); QTest::newRow("IsoDate - invalid, minute fraction") << QString::fromLatin1("23:00,XX") << Qt::ISODate << invalidTime(); QTest::newRow("IsoDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::ISODate << invalidTime(); - QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate << QTime(23, 1, 1, 0); - + QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + << invalidTime(); +#else + << QTime(23, 1, 1, 0); +#endif QTest::newRow("IsoDate - data0") << QString("00:00:00") << Qt::ISODate << QTime(0,0,0,0); QTest::newRow("IsoDate - data1") << QString("10:12:34") << Qt::ISODate << QTime(10,12,34,0); QTest::newRow("IsoDate - data2") << QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999); -- cgit v1.2.3 From 3a9251e8691f77c849c93f8d40784fae77f0a923 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 2 Jan 2020 13:08:21 +0100 Subject: Fix parameter of QJsonObject::const_iterator operator-(const_iterator) It used to be "iterator", causing a qdoc warning: src/corelib/serialization/qjsonobject.cpp:1405: (qdoc) warning: clang found diagnostics parsing \fn int QJsonObject::const_iterator::operator-(const_iterator other) const error: out-of-line definition of 'operator-' does not match any declaration in 'QJsonObject::const_iterator' Add a small test. Change-Id: Id65effffa720ed1e0fb0ee6937dcc4298f3ef363 Reviewed-by: Lars Knoll --- tests/auto/corelib/serialization/json/tst_qtjson.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 57aa67c142..45f815f810 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -527,6 +527,8 @@ void tst_QtJson::testObjectSmallKeys() QVERIFY(data1.contains(QStringLiteral("123"))); QCOMPARE(data1.value(QStringLiteral("123")).type(), QJsonValue::Double); QCOMPARE(data1.value(QStringLiteral("123")).toDouble(), (double)323); + QCOMPARE(data1.constEnd() - data1.constBegin(), 3); + QCOMPARE(data1.end() - data1.begin(), 3); } void tst_QtJson::testArraySimple() -- cgit v1.2.3