diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-05-07 15:12:02 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-05-11 16:20:55 +0200 |
commit | cdf85cf884435a4fc559c98bec192552e90e105a (patch) | |
tree | 5b6afff55882846fb101fbaa97983b776af979b6 /tests | |
parent | 0e7dcfb64100ed3b78c2748bbd665ecace8c2a45 (diff) |
Make tst_qqmlecmascript::dateParse() more thorough
Expand the test to pass a local-time QDateTime in (to check it arrives
in the form expected) and, parallel to the UTC time test, that the
various ways of constructing a local-time Date in JS do actually
produce the expected results.
Change-Id: I5ee8b4d3c0c15a5aa1168c7fb20646f3b55a7488
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/date.qml | 62 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 5 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/date.qml b/tests/auto/qml/qqmlecmascript/data/date.qml index 41dcaafa33..8e190b1f8f 100644 --- a/tests/auto/qml/qqmlecmascript/data/date.qml +++ b/tests/auto/qml/qqmlecmascript/data/date.qml @@ -23,4 +23,66 @@ Item { var dt = new Date("Wed, 18 Sep 2013 07:00:51 -0700"); return dt.getTime(); } + + function check_value(date, tag, qdt) { + var result = true; + if (date.getFullYear() != 2014) { + console.warn("Wrong year (" + tag + "):", date.getFullYear(), "!= 2014") + result = false; + } + // July; JS's months are Jan 0 to 11 Dec, vs. Qt's 1 to 12. + if (date.getMonth() != 6) { + console.warn("Wrong month (" + tag + "):", date.getMonth(), "!= 6"); + result = false; + } + if (date.getDate() != 16) { + console.warn("Wrong day (" + tag + "):", date.getDate(), "!= 16"); + result = false; + } + if (date.getHours() != 23) { + console.warn("Wrong hour (" + tag + "):", date.getHours(), "!= 23"); + result = false; + } + if (date.getMinutes() != 30) { + console.warn("Wrong minute (" + tag + "):", date.getMinutes(), "!= 30"); + result = false; + } + if (date.getSeconds() != 31) { + console.warn("Wrong second (" + tag + "):", date.getSecondss(), "!= 31"); + result = false; + } + + if (qdt != undefined) { + if (date.toISOString() != qdt.toISOString()) { + console.warn("Different ISO strings (" + tag + "):", + date.toISOString(), "!=", qdt.toISOString); + result = false; + } + if (date.getTime() != qdt.getTime()) { + console.warn("Different epoch times (" + tag + "):", + date.getTime(), "!=", qdt.getTime()); + } + } + return result; + } + + function check_date(qdt) { + var result = check_value(qdt, "passed"); + if (!check_value(new Date(2014, 6, 16, 23, 30, 31), "construct", qdt)) + result = false; + if (!check_value(new Date(Date.parse("2014-07-16T23:30:31")), "parsed", qdt)) + result = false; + + var date = new Date(0); + date.setFullYear(2014); + date.setMonth(6); + date.setDate(16); + date.setHours(23); + date.setMinutes(30); + date.setSeconds(31); + if (!check_value(date, "by field", qdt)) + result = false; + + return result; + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index fd84691e3d..cb14333e6d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -7948,6 +7948,11 @@ void tst_qqmlecmascript::dateParse() QMetaObject::invokeMethod(object.get(), "test_rfc2822_date", Q_RETURN_ARG(QVariant, q)); QCOMPARE(q.toLongLong(), 1379512851000LL); + + QDateTime val(QDate(2014, 7, 16), QTime(23, 30, 31), Qt::LocalTime); + QMetaObject::invokeMethod(object.get(), "check_date", + Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, val)); + QVERIFY(q.toBool()); } void tst_qqmlecmascript::utcDate() |