diff options
Diffstat (limited to 'tests/auto/corelib')
11 files changed, 454 insertions, 82 deletions
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 <QtTest/QtTest> #include <QtCore/QCoreApplication> -#include <QtCore/QMimeDatabase> 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); 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 <QStandardItemModel> #include <QStringListModel> #include <QTest> +#include <QTransposeProxyModel> #include <QLoggingCategory> #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<int>() << 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<int>() << 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<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value<QModelIndex>())); QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1)); @@ -289,9 +268,62 @@ void tst_QIdentityProxyModel::moveRows() QCOMPARE(modelAfterSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value<QModelIndex>())); 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<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().first().value<QModelIndex>())); + QCOMPARE(modelBeforeSpy.first().at(1), proxyBeforeSpy.first().at(1)); + QCOMPARE(modelBeforeSpy.first().at(2), proxyBeforeSpy.first().at(2)); + QCOMPARE(modelBeforeSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyBeforeSpy.first().at(3).value<QModelIndex>())); + QCOMPARE(modelBeforeSpy.first().at(4), proxyBeforeSpy.first().at(4)); + + QCOMPARE(modelAfterSpy.first().first().value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().first().value<QModelIndex>())); + QCOMPARE(modelAfterSpy.first().at(1), proxyAfterSpy.first().at(1)); + QCOMPARE(modelAfterSpy.first().at(2), proxyAfterSpy.first().at(2)); + QCOMPARE(modelAfterSpy.first().at(3).value<QModelIndex>(), m_proxy->mapToSource(proxyAfterSpy.first().at(3).value<QModelIndex>())); + 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() diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index ccb6a457a6..6b59a6f1af 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() 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<QModelIndex>("destinationParent"); QTest::addColumn<int>("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"}; } diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 8db28c7c71..ead5b685f2 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -31,6 +31,7 @@ #include <QtTest/QtTest> #include <qvariant.h> +#include <QtCore/private/qvariant_p.h> #include <qbitarray.h> #include <qbytearraylist.h> #include <qdatetime.h> @@ -271,7 +272,8 @@ private slots: void nullConvert(); void accessSequentialContainerKey(); - + void shouldDeleteVariantDataWorksForSequential(); + void shouldDeleteVariantDataWorksForAssociative(); void fromStdVariant(); void qt4UuidDataStream(); @@ -4566,6 +4568,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<MyType>(); + 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>(), &mytype); + }; + iterator._get = [](void * const *, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {2, "zwei"}; + return {qMetaTypeId<MyType>(), QMetaType::create(qMetaTypeId<MyType>(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + QSequentialIterable iterable {iterator}; + QVariant value1 = iterable.at(0); + QVERIFY(value1.canConvert<MyType>()); + QCOMPARE(value1.value<MyType>().number, 1); + QVariant value2 = *iterable.begin(); + QVERIFY(value2.canConvert<MyType>()); + QCOMPARE(value2.value<MyType>().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<MyType>(); + iterator._metaType_id_key = qMetaTypeId<MyType>(); + 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<void *>(quintptr(42)); + }; + iterator._getKey = [](void * const *iterator, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {1, "key"}; + if (reinterpret_cast<quintptr>(*iterator) == 42) { + mytype.number = 42; + mytype.text = "find_key"; + } + return {qMetaTypeId<MyType>(), QMetaType::create(qMetaTypeId<MyType>(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + iterator._getValue = [](void * const *iterator, int, uint) -> QtMetaTypePrivate::VariantData { + MyType mytype {2, "value"}; + if (reinterpret_cast<quintptr>(*iterator) == 42) { + mytype.number = 42; + mytype.text = "find_value"; + } + return {qMetaTypeId<MyType>(), QMetaType::create(qMetaTypeId<MyType>(), &mytype), QVariantConstructionFlags::ShouldDeleteVariantData}; + }; + QAssociativeIterable iterable {iterator}; + auto it = iterable.begin(); + QVariant value1 = it.key(); + QVERIFY(value1.canConvert<MyType>()); + QCOMPARE(value1.value<MyType>().number, 1); + QCOMPARE(value1.value<MyType>().text, "key"); + QVariant value2 = it.value(); + QVERIFY(value2.canConvert<MyType>()); + QCOMPARE(value2.value<MyType>().number, 2); + auto findIt = iterable.find(QVariant::fromValue(MyType {})); + value1 = findIt.key(); + QCOMPARE(value1.value<MyType>().number, 42); + QCOMPARE(value1.value<MyType>().text, "find_key"); + value2 = findIt.value(); + QCOMPARE(value2.value<MyType>().number, 42); + QCOMPARE(value2.value<MyType>().text, "find_value"); + } + QCOMPARE(instanceCount, 0); +} + void tst_QVariant::fromStdVariant() { #if __has_include(<variant>) && __cplusplus >= 201703L diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 50d3ab1f6b..4c85482c6a 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -587,6 +587,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() diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 0b2d33dc09..7b2d92f9cb 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" diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index cd074ce944..84e12cd46b 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(); }; @@ -7002,6 +7004,52 @@ void tst_QString::isRightToLeft() QCOMPARE(unicode.isRightToLeft(), rtl); } +void tst_QString::isValidUtf16_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<bool>("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" diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 7778542736..6aae91f62f 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2213,8 +2213,50 @@ 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 +#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") + << 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") @@ -2294,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!") 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); diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 85733639b8..1638ebc992 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -70,6 +70,7 @@ private slots: void equal_range(); void insert(); + void insertMap(); void checkMostLeftNode(); void initializerList(); void testInsertWithHint(); @@ -1202,6 +1203,101 @@ void tst_QMap::insert() } } +void tst_QMap::insertMap() +{ + { + QMap<int, int> map; + map.insert(1, 1); + map.insert(2, 2); + map.insert(0, -1); + + QMap<int, int> 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<int, int> map; + for (int i = 0; i < 10; ++i) + map.insert(i * 3, i); + + QMap<int, int> 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<int, int> map; + map.insert(1, 1); + + QMap<int, int> map2; + + map.insert(map2); + QCOMPARE(map.count(), 1); + QCOMPARE(map[1], 1); + } + { + QMap<int, int> map; + QMap<int, int> map2; + map2.insert(1, 1); + + map.insert(map2); + QCOMPARE(map.count(), 1); + QCOMPARE(map[1], 1); + } + { + QMap<int, int> 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<int, int> map; + QMultiMap<int, int> 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<int, int> map; |