diff options
Diffstat (limited to 'tests/auto/qml/qqmlqt/tst_qqmlqt.cpp')
-rw-r--r-- | tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 264 |
1 files changed, 147 insertions, 117 deletions
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index ba21320bf4..710bbce17a 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -1,62 +1,40 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #include <private/qqmlengine_p.h> #include <qtest.h> -#include <QDebug> + #include <QQmlEngine> -#include <QFontDatabase> -#include <QFileInfo> #include <QQmlComponent> +#include <QtQuick/QQuickItem> + +#include <QCryptographicHash> +#include <QDateTime> +#include <QDebug> +#include <QDateTime> #include <QDesktopServices> #include <QDir> -#include <QCryptographicHash> -#include <QtQuick/QQuickItem> +#include <QFileInfo> +#include <QFont> +#include <QFontDatabase> +#include <QMatrix4x4> +#include <QQuaternion> #include <QSignalSpy> #include <QVector2D> #include <QVector3D> #include <QVector4D> -#include <QQuaternion> -#include <QMatrix4x4> -#include <QFont> -#include "../../shared/util.h" +#include <QTimeZone> -// Copied from tst_qdatetime.cpp -#ifdef Q_OS_WIN -# include <qt_windows.h> -# include <time.h> -#endif +#include <QtQuickTestUtils/private/qmlutils_p.h> +#include <private/qtenvironmentvariables_p.h> // for qTzSet() +#include <private/qqmlengine_p.h> class tst_qqmlqt : public QQmlDataTest { Q_OBJECT public: - tst_qqmlqt() {} + tst_qqmlqt() : QQmlDataTest(QT_QMLTEST_DATADIR) {} private slots: void initTestCase() override; @@ -189,8 +167,8 @@ void tst_qqmlqt::rgba() QVERIFY(object != nullptr); - QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0, 0, 0.8)); - QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromRgbF(1, 0.5, 0.3, 1)); + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0, 0, 0.8f)); + QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromRgbF(1, 0.5f, 0.3f, 1)); QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor::fromRgbF(1, 1, 1, 1)); @@ -209,8 +187,8 @@ void tst_qqmlqt::hsla() QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromHslF(1, 0, 0, 0.8)); - QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromHslF(1, 0.5, 0.3, 1)); + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromHslF(1, 0, 0, 0.8f)); + QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromHslF(1, 0.5f, 0.3f, 1)); QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor::fromHslF(1, 1, 1, 1)); @@ -229,8 +207,8 @@ void tst_qqmlqt::hsva() QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromHsvF(1, 0, 0, 0.8)); - QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromHsvF(1, 0.5, 0.3, 1)); + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromHsvF(1, 0, 0, 0.8f)); + QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromHsvF(1, 0.5f, 0.3f, 1)); QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor::fromHsvF(1, 1, 1, 1)); @@ -503,13 +481,13 @@ void tst_qqmlqt::lighter() QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).lighter()); + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8f, 0.3f).lighter()); QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")), - QColor::fromRgbF(1, 0.8, 0.3).lighter()); + QColor::fromRgbF(1, 0.8f, 0.3f).lighter()); QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor()); - QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).lighter(180)); + QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8f, 0.3f).lighter(180)); QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")), - QColor::fromRgbF(1, 0.8, 0.3).lighter(180)); + QColor::fromRgbF(1, 0.8f, 0.3f).lighter(180)); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").lighter()); QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), QColor("red").lighter()); QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor()); @@ -528,13 +506,13 @@ void tst_qqmlqt::darker() QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).darker()); + QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8f, 0.3f).darker()); QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")), - QColor::fromRgbF(1, 0.8, 0.3).darker()); + QColor::fromRgbF(1, 0.8f, 0.3f).darker()); QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor()); - QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).darker(280)); + QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8f, 0.3f).darker(280)); QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")), - QColor::fromRgbF(1, 0.8, 0.3).darker(280)); + QColor::fromRgbF(1, 0.8f, 0.3f).darker(280)); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").darker()); QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), QColor("red").darker()); QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor()); @@ -554,17 +532,17 @@ void tst_qqmlqt::alpha() QVERIFY(object != nullptr); QCOMPARE(qvariant_cast<QColor>(object->property("test1")), - QColor::fromRgbF(1.0, 0.8, 0.3, 0.5)); + QColor::fromRgbF(1.0f, 0.8f, 0.3f, 0.5f)); QCOMPARE(qvariant_cast<QColor>(object->property("testColor1")), - QColor::fromRgbF(1, 0.8, 0.3, 0.5)); + QColor::fromRgbF(1, 0.8f, 0.3f, 0.5)); QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor()); QCOMPARE(qvariant_cast<QColor>(object->property("test3")), - QColor::fromRgbF(1.0, 0.8, 0.3, 0.7)); + QColor::fromRgbF(1.0f, 0.8f, 0.3f, 0.7f)); QCOMPARE(qvariant_cast<QColor>(object->property("testColor3")), - QColor::fromRgbF(1, 0.8, 0.3, 0.7)); + QColor::fromRgbF(1, 0.8f, 0.3f, 0.7f)); QColor alphaRed = QColor("red"); - alphaRed.setAlphaF(0.5); + alphaRed.setAlphaF(0.5f); QCOMPARE(qvariant_cast<QColor>(object->property("test4")), alphaRed); QCOMPARE(qvariant_cast<QColor>(object->property("testColor4")), alphaRed); @@ -639,9 +617,13 @@ void tst_qqmlqt::openUrlExternally() { MyUrlHandler handler; + const QUrl htmlTestFile = testFileUrl("test.html"); QDesktopServices::setUrlHandler("test", &handler, "noteCall"); - QDesktopServices::setUrlHandler("file", &handler, "noteCall"); - + QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall"); + const auto unset = qScopeGuard([&] { + QDesktopServices::unsetUrlHandler(htmlTestFile.scheme()); + QDesktopServices::unsetUrlHandler("test"); + }); QQmlComponent component(&engine, testFileUrl("openUrlExternally.qml")); QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); @@ -651,18 +633,20 @@ void tst_qqmlqt::openUrlExternally() object->setProperty("testFile", true); QCOMPARE(handler.called,2); - QCOMPARE(handler.last, testFileUrl("test.html")); - - QDesktopServices::unsetUrlHandler("test"); - QDesktopServices::unsetUrlHandler("file"); + QCOMPARE(handler.last, htmlTestFile); } void tst_qqmlqt::openUrlExternally_pragmaLibrary() { MyUrlHandler handler; + const QUrl htmlTestFile = testFileUrl("test.html"); QDesktopServices::setUrlHandler("test", &handler, "noteCall"); - QDesktopServices::setUrlHandler("file", &handler, "noteCall"); + QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall"); + const auto unset = qScopeGuard([&] { + QDesktopServices::unsetUrlHandler(htmlTestFile.scheme()); + QDesktopServices::unsetUrlHandler("test"); + }); QQmlComponent component(&engine, testFileUrl("openUrlExternally_lib.qml")); QScopedPointer<QObject> object(component.create()); @@ -673,10 +657,7 @@ void tst_qqmlqt::openUrlExternally_pragmaLibrary() object->setProperty("testFile", true); QCOMPARE(handler.called,2); - QCOMPARE(handler.last, testFileUrl("test.html")); - - QDesktopServices::unsetUrlHandler("test"); - QDesktopServices::unsetUrlHandler("file"); + QCOMPARE(handler.last, htmlTestFile); } void tst_qqmlqt::md5() @@ -759,7 +740,7 @@ void tst_qqmlqt::createQmlObject() QQuickItem *item = qobject_cast<QQuickItem *>(object.data()); QVERIFY(item != nullptr); - QCOMPARE(item->childItems().count(), 1); + QCOMPARE(item->childItems().size(), 1); } @@ -768,25 +749,32 @@ void tst_qqmlqt::dateTimeConversion() QDate date(2008,12,24); QTime time(14,15,38,200); QDateTime dateTime(date, time); - //Note that when converting Date to QDateTime they can argue over historical DST data when converting to local time. - //Tests should use UTC or recent dates. + QDateTime dateTime0(QDate(2021, 7, 1).startOfDay()); + QDateTime dateTime0utc(QDate(2021, 7, 1).startOfDay(QTimeZone::UTC)); + QDateTime dateTime1(QDate(2021, 7, 31).startOfDay()); + QDateTime dateTime1utc(QDate(2021, 7, 31).startOfDay(QTimeZone::UTC)); QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500)); QDateTime dateTime3(QDate(2000,1,1), QTime(0,0,0,0)); QDateTime dateTime4(QDate(2001,2,2), QTime(0,0,0,0)); QDateTime dateTime5(QDate(1999,1,1), QTime(2,3,4,0)); QDateTime dateTime6(QDate(2008,2,24), QTime(14,15,38,200)); - QDateTime dateTime7(QDate(1970,1,1), QTime(0,0,0,0), Qt::UTC); - QDateTime dateTime8(QDate(1586,2,2), QTime(0,0,0,0), Qt::UTC); - QDateTime dateTime9(QDate(955,1,1), QTime(0,0,0,0), Qt::UTC); - QDateTime dateTime10(QDate(113,2,24), QTime(14,15,38,200), Qt::UTC); + QDateTime dateTime7(QDate(1970, 1, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime dateTime8(QDate(1586, 2, 2), QTime(0, 0), QTimeZone::UTC); + QDateTime dateTime9(QDate(955, 1, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime dateTime10(QDate(113, 2, 24), QTime(14, 15, 38, 200), QTimeZone::UTC); QQmlEngine eng; QQmlComponent component(&eng, testFileUrl("dateTimeConversion.qml")); QScopedPointer<QObject> obj(component.create()); + QVERIFY2(obj != nullptr, qPrintable(component.errorString())); QCOMPARE(obj->property("qdate").toDate(), date); QCOMPARE(obj->property("qtime").toTime(), time); QCOMPARE(obj->property("qdatetime").toDateTime(), dateTime); + QCOMPARE(obj->property("qdatetime0").toDateTime(), dateTime0); + QCOMPARE(obj->property("qdatetime0utc").toDateTime(), dateTime0utc); + QCOMPARE(obj->property("qdatetime1").toDateTime(), dateTime1); + QCOMPARE(obj->property("qdatetime1utc").toDateTime(), dateTime1utc); QCOMPARE(obj->property("qdatetime2").toDateTime(), dateTime2); QCOMPARE(obj->property("qdatetime3").toDateTime(), dateTime3); QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4); @@ -818,7 +806,7 @@ void tst_qqmlqt::dateTimeFormatting() << component.url().toString() + ":40: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed." << component.url().toString() + ":43: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed."; - foreach (const QString &warning, warnings) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); warnings.clear(); @@ -833,7 +821,7 @@ void tst_qqmlqt::dateTimeFormatting() << "Could not convert argument 1 at" << "expression for err_dateTime2@"; - foreach (const QString &warning, warnings) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, QRegularExpression(warning)); QScopedPointer<QObject> object(component.createWithInitialProperties({ @@ -844,15 +832,15 @@ void tst_qqmlqt::dateTimeFormatting() QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString())); QVERIFY(object != nullptr); - QVERIFY(inputProperties.count() > 0); + QVERIFY(inputProperties.size() > 0); QVariant result; - foreach(const QString &prop, inputProperties) { + for (const QString &prop : std::as_const(inputProperties)) { QVERIFY(QMetaObject::invokeMethod(object.data(), method.toUtf8().constData(), Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, prop))); QStringList output = result.toStringList(); QCOMPARE(output.size(), expectedResults.size()); - for (int i=0; i<output.count(); i++) + for (int i=0; i<output.size(); i++) QCOMPARE(output[i], expectedResults[i]); } } @@ -904,7 +892,7 @@ void tst_qqmlqt::dateTimeFormattingVariants() << component.url().toString() + ":40: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed." << component.url().toString() + ":43: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed."; - for (const QString &warning : qAsConst(warnings)) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); warnings.clear(); @@ -918,11 +906,14 @@ void tst_qqmlqt::dateTimeFormattingVariants() << "Could not convert argument 1 at" << "expression for err_dateTime2@"; - for (const QString &warning : qAsConst(warnings)) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, QRegularExpression(warning)); warnings.clear(); - if (method == QStringLiteral("formatTime") && variant.typeId() == QMetaType::QString) { + + if (method == QStringLiteral("formatTime") + && variant.typeId() == QMetaType::QString + && QByteArrayView(QTest::currentDataTag()).endsWith("ISO")) { for (int i = 0; i < 4; ++i) { QTest::ignoreMessage(QtWarningMsg, "\"2011/05/31 11:16:39.755\" is a " @@ -934,16 +925,22 @@ void tst_qqmlqt::dateTimeFormattingVariants() if (variant.typeId() == QMetaType::QColor || variant.typeId() == QMetaType::Int) { if (method == "formatTime") { // formatTime has special error handling as it parses the strings itself. - QTest::ignoreMessage(QtWarningMsg, QRegularExpression( - "formatting.qml:18: Error: Invalid argument passed to " - "formatTime")); - } else { - QTest::ignoreMessage(QtWarningMsg, - QRegularExpression("Could not convert argument 0 at")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(method + "@")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression( - "TypeError: Passing incompatible arguments to " - "C.. functions from JavaScript is not allowed.")); + QTest::ignoreMessage( + QtWarningMsg, + QRegularExpression("formatting.qml:19: Error: Invalid argument passed to " + "formatTime")); + } else if (method == "formatDate") { + // formatDate has special error handling as it parses the strings itself. + QTest::ignoreMessage( + QtWarningMsg, + QRegularExpression("formatting.qml:10: Error: Invalid argument passed to " + "formatDate")); + } else if (method == "formatDateTime") { + // formatDateTime has special error handling as it parses the strings itself. + QTest::ignoreMessage( + QtWarningMsg, + QRegularExpression("formatting.qml:29: Error: Invalid argument passed to " + "formatDateTime")); } } @@ -979,7 +976,7 @@ void tst_qqmlqt::dateTimeFormattingVariants_data() QDate date(2011,5,31); // V4 reads the date in UTC but DateObject::toQDateTime() gives it back in local time: - temporary = QDateTime(date, QTime(0, 0, 0), Qt::UTC).toLocalTime(); + temporary = date.startOfDay(QTimeZone::UTC).toLocalTime(); QTest::newRow("formatDate, qdate") << "formatDate" << QVariant::fromValue(date) << (QStringList() @@ -1022,27 +1019,47 @@ void tst_qqmlqt::dateTimeFormattingVariants_data() << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); - QString string(QLatin1String("2011/05/31 11:16:39.755")); - temporary = QDateTime::fromString(string, "yyyy/MM/dd HH:mm:ss.zzz"); - QTest::newRow("formatDate, qstring") - << "formatDate" << QVariant::fromValue(string) + const QString isoString(QLatin1String("2011/05/31 11:16:39.755")); + temporary = QDateTime::fromString(isoString, "yyyy/MM/dd HH:mm:ss.zzz"); + const QString jsString = engine.coerceValue<QDateTime, QString>(temporary); + QTest::newRow("formatDate, qstring, ISO") + << "formatDate" << QVariant::fromValue(isoString) + << (QStringList() + << QLocale().toString(temporary.date(), QLocale::ShortFormat) + << QLocale().toString(temporary.date(), QLocale::LongFormat) + << temporary.date().toString("ddd MMMM d yy")); + QTest::newRow("formatDate, qstring, JS") + << "formatDate" << QVariant::fromValue(jsString) << (QStringList() << QLocale().toString(temporary.date(), QLocale::ShortFormat) << QLocale().toString(temporary.date(), QLocale::LongFormat) << temporary.date().toString("ddd MMMM d yy")); - QTest::newRow("formatDateTime, qstring") - << "formatDateTime" << QVariant::fromValue(string) + QTest::newRow("formatDateTime, qstring, ISO") + << "formatDateTime" << QVariant::fromValue(isoString) + << (QStringList() + << QLocale().toString(temporary, QLocale::ShortFormat) + << QLocale().toString(temporary, QLocale::LongFormat) + << temporary.toString("M/d/yy H:m:s a")); + QTest::newRow("formatDateTime, qstring, JS") + << "formatDateTime" << QVariant::fromValue(jsString) << (QStringList() << QLocale().toString(temporary, QLocale::ShortFormat) << QLocale().toString(temporary, QLocale::LongFormat) << temporary.toString("M/d/yy H:m:s a")); - QTest::newRow("formatTime, qstring") - << "formatTime" << QVariant::fromValue(string) + QTest::newRow("formatTime, qstring, ISO") + << "formatTime" << QVariant::fromValue(isoString) << (QStringList() << QLocale().toString(temporary.time(), QLocale::ShortFormat) << QLocale().toString(temporary.time(), QLocale::LongFormat) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz")); + QTest::newRow("formatTime, qstring, JS") + << "formatTime" << QVariant::fromValue(jsString) + << (QStringList() + << QLocale().toString(temporary.time(), QLocale::ShortFormat) + << QLocale().toString(temporary.time(), QLocale::LongFormat) + << temporary.time().toString("H:m:s a") + << temporary.time().toString("hh:mm:ss.000")); // JS Date to string coercion drops milliseconds QColor color(Qt::red); temporary = QVariant::fromValue(color).toDateTime(); @@ -1154,7 +1171,7 @@ void tst_qqmlqt::quit() QSignalSpy spy(&engine, SIGNAL(quit())); QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_qqmlqt::exit() @@ -1164,13 +1181,15 @@ void tst_qqmlqt::exit() QSignalSpy spy(&engine, &QQmlEngine::exit); QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> arguments = spy.takeFirst(); QVERIFY(arguments.at(0).toInt() == object->property("returnCode").toInt()); } void tst_qqmlqt::resolvedUrl() { + QQmlEngine engine; + engine.addImportPath(dataDirectory()); QQmlComponent component(&engine, testFileUrl("resolvedUrl.qml")); QScopedPointer<QObject> object(component.create()); @@ -1179,6 +1198,15 @@ void tst_qqmlqt::resolvedUrl() QCOMPARE(object->property("result").toString(), component.url().toString()); QCOMPARE(object->property("isString").toBool(), false); QCOMPARE(object->property("isObject").toBool(), true); + + QCOMPARE(qvariant_cast<QUrl>(object->property("resolvedHere")), + dataDirectoryUrl().resolved(QStringLiteral("somewhere.qml"))); + QCOMPARE(qvariant_cast<QUrl>(object->property("resolvedThere")), + dataDirectoryUrl().resolved(QStringLiteral("Other/somewhere.qml"))); + + QVariant unresolved = object->property("unresolvedUrl"); + QCOMPARE(unresolved.metaType(), QMetaType::fromType<QUrl>()); + QCOMPARE(qvariant_cast<QUrl>(unresolved), QUrl(QStringLiteral("nowhere/else.js"))); } void tst_qqmlqt::later_data() @@ -1253,12 +1281,13 @@ void tst_qqmlqt::later_data() void tst_qqmlqt::later() { + QQmlEngine engine; QFETCH(QString, function); QFETCH(QStringList, expectedWarnings); QFETCH(QStringList, propNames); QFETCH(QVariantList, values); - foreach (const QString &w, expectedWarnings) + for (const QString &w : std::as_const(expectedWarnings)) QTest::ignoreMessage(QtWarningMsg, qPrintable(w)); QQmlComponent component(&engine, testFileUrl("later.qml")); @@ -1273,7 +1302,7 @@ void tst_qqmlqt::later() QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QCoreApplication::processEvents(); } else if (propNames.at(i) == QLatin1String("collectGarbage")) { - engine.collectGarbage(); + gc(engine, GCFlags::DontSendPostedEvents); } else { QCOMPARE(root->property(qPrintable(propNames.at(i))), values.at(i)); } @@ -1338,6 +1367,7 @@ class TimeProvider: public QObject { Q_OBJECT QML_NAMED_ELEMENT(TimeProvider) + QML_UNCREATABLE("") Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged) public: @@ -1359,7 +1389,7 @@ class TimeZoneSwitch { public: TimeZoneSwitch(const char *newZone) - : doChangeZone(qstrcmp(newZone, "localtime") == 0) + : doChangeZone(qstrcmp(newZone, "localtime") != 0) { if (!doChangeZone) return; @@ -1369,7 +1399,7 @@ public: oldZone = qgetenv("TZ"); } qputenv("TZ", newZone); - tzset(); + qTzSet(); } ~TimeZoneSwitch() @@ -1381,7 +1411,7 @@ public: qputenv("TZ", oldZone); else qunsetenv("TZ"); - tzset(); + qTzSet(); } private: @@ -1397,6 +1427,9 @@ void tst_qqmlqt::timeRoundtrip_data() // Local timezone: QTest::newRow("localtime") << QTime(0, 0, 0); +#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID) + qInfo("Omitting the tests that depend on setting local time's zone"); +#else // No DST: QTest::newRow("UTC") << QTime(0, 0, 0); QTest::newRow("Europe/Amsterdam") << QTime(1, 0, 0); @@ -1408,14 +1441,11 @@ void tst_qqmlqt::timeRoundtrip_data() QTest::newRow("Australia/Hobart") << QTime(10, 0, 0); QTest::newRow("Pacific/Auckland") << QTime(12, 0, 0); QTest::newRow("Pacific/Samoa") << QTime(13, 0, 0); +#endif } void tst_qqmlqt::timeRoundtrip() { -#ifdef Q_OS_WIN - QSKIP("On Windows, the DateObject doesn't handle DST transitions correctly when the timezone is not localtime."); // I.e.: for this test. -#endif - TimeZoneSwitch tzs(QTest::currentDataTag()); QFETCH(QTime, time); qmlRegisterTypesAndRevisions<TimeProvider>("Test", 1); |