From 8027fb60dd1c1e4349eb1ac782d1197e784d6081 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 18 Nov 2019 13:26:13 +0100 Subject: Fix QCborValue::toCbor with non-ASCII URLs Found while fixing QTBUG-79196. Change-Id: Ia2aa807ffa8a4c798425fffd15d841657def99af Reviewed-by: Ulf Hermann --- tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index c6733205e5..ffc22bc9a3 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -1391,6 +1391,9 @@ static void addCommonCborData() QTest::newRow("Url") << QCborValue(QUrl("HTTPS://example.com/{%30%31}?q=%3Ca+b%20%C2%A9%3E&%26")) << raw("\xd8\x20\x78\x27" "https://example.com/{01}?q=&%26") << noxfrm; + QTest::newRow("Url:NonAscii") << QCborValue(QUrl("https://example.com/\xc2\xa0")) + << raw("\xd8\x20\x76" "https://example.com/\xc2\xa0") + << noxfrm; QTest::newRow("Regex:Empty") << QCborValue(QRegularExpression()) << raw("\xd8\x23\x60") << noxfrm; QTest::newRow("Regex") << QCborValue(QRegularExpression("^.*$")) << raw("\xd8\x23\x64" "^.*$") << noxfrm; -- cgit v1.2.3 From bcbefcd6457adac9d92a410b1f7250ed5b0e8955 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 15 Oct 2019 16:37:52 -0700 Subject: QCborValue: Extend the constructor to also create extended types We already did that when parsing from CBOR binary data, so the code was already present. [ChangeLog][QtCore][QCborValue] The constructor taking a CBOR tag and a value to be tagged now attempts to convert to a QCborValue extended type. For example, if the tag is 0 (UnixTime_t) and the payload is a number, the resulting object will become tag 1 (DateTime) and the payload will be the the ISO-8601 date/time string. Fixes: QTBUG-79196 Change-Id: I6edce5101800424a8093fffd15cdf650fb2fc45c Reviewed-by: Ulf Hermann --- .../serialization/qcborvalue/tst_qcborvalue.cpp | 71 ++++++++++++++++++---- 1 file changed, 59 insertions(+), 12 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index ffc22bc9a3..47ad328d64 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -40,6 +40,7 @@ #include #include +Q_DECLARE_METATYPE(QCborKnownTags) Q_DECLARE_METATYPE(QCborValue) Q_DECLARE_METATYPE(QCborValue::EncodingOptions) @@ -294,34 +295,77 @@ void tst_QCborValue::tagged() void tst_QCborValue::extendedTypes_data() { QTest::addColumn("extended"); - QTest::addColumn("tagged"); + QTest::addColumn("tag"); + QTest::addColumn("taggedValue"); + QTest::addColumn("correctedTaggedValue"); + QCborValue v(QCborValue::Invalid); QDateTime dt = QDateTime::currentDateTimeUtc(); + QDateTime dtTzOffset(dt.date(), dt.time(), Qt::OffsetFromUTC, dt.offsetFromUtc()); QUuid uuid = QUuid::createUuid(); + // non-correcting extended types (tagged value remains unchanged) QTest::newRow("DateTime") << QCborValue(dt) - << QCborValue(QCborKnownTags::DateTimeString, dt.toString(Qt::ISODateWithMs)); + << QCborKnownTags::DateTimeString << QCborValue(dt.toString(Qt::ISODateWithMs)) << v; + QTest::newRow("DateTime:TzOffset") << QCborValue(dtTzOffset) + << QCborKnownTags::DateTimeString << QCborValue(dtTzOffset.toString(Qt::ISODateWithMs)) << v; QTest::newRow("Url:Empty") << QCborValue(QUrl()) - << QCborValue(QCborKnownTags::Url, QString()); + << QCborKnownTags::Url << QCborValue(QString()) << v; QTest::newRow("Url:Authority") << QCborValue(QUrl("https://example.com")) - << QCborValue(QCborKnownTags::Url, "https://example.com"); + << QCborKnownTags::Url << QCborValue("https://example.com") << v; QTest::newRow("Url:Path") << QCborValue(QUrl("file:///tmp/none")) - << QCborValue(QCborKnownTags::Url, "file:///tmp/none"); + << QCborKnownTags::Url << QCborValue("file:///tmp/none") << v; QTest::newRow("Url:QueryFragment") << QCborValue(QUrl("whatever:?a=b&c=d#e")) - << QCborValue(QCborKnownTags::Url, "whatever:?a=b&c=d#e"); + << QCborKnownTags::Url << QCborValue("whatever:?a=b&c=d#e") << v; QTest::newRow("Regex:Empty") << QCborValue(QRegularExpression()) - << QCborValue(QCborKnownTags::RegularExpression, QString()); + << QCborKnownTags::RegularExpression << QCborValue(QString()) << v; QTest::newRow("Regex") << QCborValue(QRegularExpression("^.*$")) - << QCborValue(QCborKnownTags::RegularExpression, QString("^.*$")); + << QCborKnownTags::RegularExpression << QCborValue(QString("^.*$")) << v; QTest::newRow("Uuid") << QCborValue(uuid) - << QCborValue(QCborKnownTags::Uuid, uuid.toRfc4122()); + << QCborKnownTags::Uuid << QCborValue(uuid.toRfc4122()) << v; + + // correcting extended types + QDateTime dtNoMsecs = dt.fromSecsSinceEpoch(dt.toSecsSinceEpoch(), Qt::UTC); + QUrl url("https://example.com/\xc2\xa9 "); + QTest::newRow("UnixTime_t:Integer") << QCborValue(dtNoMsecs) << QCborKnownTags::UnixTime_t + << QCborValue(dtNoMsecs.toSecsSinceEpoch()) + << QCborValue(dtNoMsecs.toString(Qt::ISODateWithMs)); + QTest::newRow("UnixTime_t:Double") << QCborValue(dt) << QCborKnownTags::UnixTime_t + << QCborValue(dt.toMSecsSinceEpoch() / 1000.) + << QCborValue(dt.toString(Qt::ISODateWithMs)); + QTest::newRow("DateTime::JustDate") << QCborValue(QDateTime({2018, 1, 1}, {})) + << QCborKnownTags::DateTimeString + << QCborValue("2018-01-01") << QCborValue("2018-01-01T00:00:00.000"); + QTest::newRow("DateTime::TzOffset") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::UTC)) + << QCborKnownTags::DateTimeString + << QCborValue("2018-01-01T09:00:00.000+00:00") + << QCborValue("2018-01-01T09:00:00.000Z"); + QTest::newRow("Url:NotNormalized") << QCborValue(url) << QCborKnownTags::Url + << QCborValue("HTTPS://EXAMPLE.COM/%c2%a9%20") + << QCborValue(url.toString()); + QTest::newRow("Uuid:Zero") << QCborValue(QUuid()) << QCborKnownTags::Uuid + << QCborValue(QByteArray()) + << QCborValue(QByteArray(sizeof(QUuid), 0)); + QTest::newRow("Uuid:TooShort") << QCborValue(QUuid(0x12345678, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) + << QCborKnownTags::Uuid + << QCborValue(raw("\x12\x34\x56\x78")) + << QCborValue(raw("\x12\x34\x56\x78" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0")); + QTest::newRow("Uuid:TooLong") << QCborValue(uuid) << QCborKnownTags::Uuid + << QCborValue(uuid.toRfc4122() + "\1\2\3\4") << QCborValue(uuid.toRfc4122()); } void tst_QCborValue::extendedTypes() { QFETCH(QCborValue, extended); - QFETCH(QCborValue, tagged); + QFETCH(QCborKnownTags, tag); + QFETCH(QCborValue, taggedValue); + QFETCH(QCborValue, correctedTaggedValue); + if (correctedTaggedValue.isInvalid()) + correctedTaggedValue = taggedValue; + + QCborValue tagged(tag, taggedValue); QVERIFY(extended.isTag()); QVERIFY(tagged.isTag()); + QCOMPARE(tagged.taggedValue(), correctedTaggedValue); QVERIFY(extended == tagged); QVERIFY(tagged == extended); @@ -1224,8 +1268,11 @@ void tst_QCborValue::sorting() QCborValue va1(QCborValue::Array), va2(QCborArray{1}), va3(QCborArray{0, 0}); QCborValue vm1(QCborValue::Map), vm2(QCborMap{{1, 0}}), vm3(QCborMap{{0, 0}, {1, 0}}); QCborValue vdt1(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)), vdt2(QDateTime::currentDateTimeUtc()); - QCborValue vtagged1(QCborKnownTags::UnixTime_t, 0), vtagged2(QCborKnownTags::UnixTime_t, 0.0), - vtagged3(QCborKnownTags::Signature, 0), vtagged4(QCborTag(-2), 0), vtagged5(QCborTag(-1), 0); + QCborValue vtagged1(QCborKnownTags::PositiveBignum, QByteArray()), + vtagged2(QCborKnownTags::PositiveBignum, 0.0), // bignums are supposed to have byte arrays... + vtagged3(QCborKnownTags::Signature, 0), + vtagged4(QCborTag(-2), 0), + vtagged5(QCborTag(-1), 0); QCborValue vurl1(QUrl("https://example.net")), vurl2(QUrl("https://example.com/")); QCborValue vuuid1{QUuid()}, vuuid2(QUuid::createUuid()); QCborValue vsimple1(QCborSimpleType(1)), vsimple32(QCborSimpleType(32)), vsimple255(QCborSimpleType(255)); -- cgit v1.2.3 From 6566157df3c5a1352231be87c7b7d2705a46efe3 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 13 Nov 2019 18:42:00 +0100 Subject: Make Qt::RFC2822Date's doc match up with its implementation The qdatetime implementation's rfcDateImpl() uses regexes which did not match its comments; nor did either the regexes or the comments match what was documented. A review of relevant RFCs suggests we should revise this in future, probably at Qt 6. The documentation also only addressed the formats recognized when parsing a date-time, without indicating how they are serialised or how dates and times are handled separately. Added a note to the tests for the read-only formats, to remind the reader that the RFCs merely recommend recognising these - be permissive in what you expect and strict in what you deliver. Change-Id: I0f0bec752e7a50bde98cceceb7e0d11be15c6a6f Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 2 +- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 2 +- tests/auto/corelib/time/qtime/tst_qtime.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 73384c35f4..0f2f55ef2e 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -1165,7 +1165,7 @@ void tst_QDate::fromStringDateFormat_data() QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") << Qt::RFC2822Date << QDate(); - // Test Qt::RFC2822Date format (RFC 850 and 1036). + // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QDate(1987, 2, 13); // No timezone diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 216ae1f79e..a5482657aa 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2351,7 +2351,7 @@ void tst_QDateTime::fromStringDateFormat_data() QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") << Qt::RFC2822Date << invalidDateTime(); - // Test Qt::RFC2822Date format (RFC 850 and 1036). + // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100") diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index 3403c5bf7f..b2bb5dbb24 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -648,7 +648,7 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") << Qt::RFC2822Date << invalidTime(); - // Test Qt::RFC2822Date format (RFC 850 and 1036). + // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QTime(13, 24, 51); // No timezone -- cgit v1.2.3 From 0debb205b23a39b79650861de0e61cf4cf00286c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 14 Nov 2019 16:40:21 +0100 Subject: Permit leading space at start of RFC 2822 Date format Relevant RFCs explicitly permit such space. Change-Id: I8eb444e96287368cbbf973c77513b43d1d36f972 Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 9 +++++++++ tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 14 ++++++++++++++ tests/auto/corelib/time/qtime/tst_qtime.cpp | 9 +++++++++ 3 files changed, 32 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 0f2f55ef2e..63fdbbbe92 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -1136,8 +1136,14 @@ void tst_QDate::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 2822). QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100") << Qt::RFC2822Date << QDate(1987, 2, 13); + QTest::newRow("RFC 2822 after space") + << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100") + << Qt::RFC2822Date << QDate(1987, 2, 13); QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000") << Qt::RFC2822Date << QDate(1970, 1, 1); + QTest::newRow("RFC 2822 with day after space") + << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000") + << Qt::RFC2822Date << QDate(1970, 1, 1); // No timezone QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34") << Qt::RFC2822Date << QDate(1970, 1, 1); @@ -1168,6 +1174,9 @@ void tst_QDate::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QDate(1987, 2, 13); + QTest::newRow("RFC 850 and 1036 after space") + << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100") + << Qt::RFC2822Date << QDate(1987, 2, 13); // No timezone QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970") << Qt::RFC2822Date << QDate(1970, 1, 1); diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index a5482657aa..2bb5d0a75d 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2310,8 +2310,14 @@ void tst_QDateTime::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 2822). QTest::newRow("RFC 2822 +0100") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + QTest::newRow("RFC 2822 after space +0100") + << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100") + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); QTest::newRow("RFC 2822 with day +0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 +0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + QTest::newRow("RFC 2822 with day after space +0100") + << QString::fromLatin1(" Fri, 13 Feb 1987 13:24:51 +0100") + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); QTest::newRow("RFC 2822 -0100") << QString::fromLatin1("13 Feb 1987 13:24:51 -0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); QTest::newRow("RFC 2822 with day -0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 -0100") @@ -2324,6 +2330,11 @@ void tst_QDateTime::fromStringDateFormat_data() << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000") << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + // Should be invalid, but current implementation would just ignore the + // offset as trailing junk if we insist on the space: + QTest::newRow("RFC 2822 missing space before +0100") + << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date + << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::OffsetFromUTC, 3600); // No timezone assume UTC QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34") << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); @@ -2354,6 +2365,9 @@ void tst_QDateTime::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + QTest::newRow("RFC 1036 after space +0100") + << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100") + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100") << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000") diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index b2bb5dbb24..ed8700d93f 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -619,8 +619,14 @@ void tst_QTime::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 2822). QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100") << Qt::RFC2822Date << QTime(13, 24, 51); + QTest::newRow("RFC 2822 after space") + << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100") + << Qt::RFC2822Date << QTime(13, 24, 51); QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000") << Qt::RFC2822Date << QTime(0, 12, 34); + QTest::newRow("RFC 2822 with day after space") + << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000") + << Qt::RFC2822Date << QTime(0, 12, 34); // No timezone QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34") << Qt::RFC2822Date << QTime(0, 12, 34); @@ -651,6 +657,9 @@ void tst_QTime::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") << Qt::RFC2822Date << QTime(13, 24, 51); + QTest::newRow("RFC 850 and 1036 after space") + << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100") + << Qt::RFC2822Date << QTime(13, 24, 51); // No timezone QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970") << Qt::RFC2822Date << QTime(0, 12, 34); -- cgit v1.2.3 From 52affd322cad474efc9235e09f9f5e85f558b7a4 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 18 Nov 2019 12:06:19 +0100 Subject: Be consistent in the RFC2822Date invalid character tests The ones we reject used a zero offset while the one that does parse (though it shouldn't - revised comment) has a one hour offset. Made them all use that offset and added a partner test that has no invalid characters, so ensure the success of the invalid character tests isn't due to falsely rejecting the valid date/time text to which the invalid characters are added. Task-number: QTBUG-80038 Change-Id: I6e3dd79b981af6803e60877229c56599cfd719cb Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 47 ++++++++++++++------- .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 49 +++++++++++++++------- tests/auto/corelib/time/qtime/tst_qtime.cpp | 41 +++++++++++++----- 3 files changed, 96 insertions(+), 41 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 63fdbbbe92..dd2cb3eea8 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -1159,17 +1159,23 @@ void tst_QDate::fromStringDateFormat_data() << Qt::RFC2822Date << QDate(); QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100") << Qt::RFC2822Date << QDate(); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 2822 invalid character at end") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") + << Qt::RFC2822Date << QDate(2012, 1, 1); + QTest::newRow("RFC 2822 invalid character at front") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate(); + QTest::newRow("RFC 2822 invalid character both ends") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDate(); + QTest::newRow("RFC 2822 invalid character at front, 2 at back") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << QDate(); + QTest::newRow("RFC 2822 invalid character 2 at front") + << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate(); + // The common date text used by the "invalid character" tests, just to be + // sure *it's* not what's invalid: + QTest::newRow("RFC 2822 (not invalid)") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate(2012, 1, 1); - QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000") - << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!") - << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..") - << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") - << Qt::RFC2822Date << QDate(); // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") @@ -1183,17 +1189,26 @@ void tst_QDate::fromStringDateFormat_data() // No time specified QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002") << Qt::RFC2822Date << QDate(2002, 11, 1); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 850 and 1036 invalid character at end") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << QDate(2012, 1, 1); - QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000") + QTest::newRow("RFC 850 and 1036 invalid character at front") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!") + QTest::newRow("RFC 850 and 1036 invalid character both ends") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..") + QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..") << Qt::RFC2822Date << QDate(); - QTest::newRow("RFC 850 and 1036 invalid character 2 at front") << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0000") + QTest::newRow("RFC 850 and 1036 invalid character 2 at front") + << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << QDate(); + // Again, check the text in the "invalid character" tests isn't the source of invalidity: + QTest::newRow("RFC 850 and 1036 (not invalid)") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100") + << Qt::RFC2822Date << QDate(2012, 1, 1); QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDate(); } diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 2bb5d0a75d..7f13fd0aa5 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -1003,8 +1003,9 @@ void tst_QDateTime::toString_rfcDate() // Set to non-English locale to confirm still uses English QLocale oldLocale; QLocale::setDefault(QLocale("de_DE")); - QCOMPARE(dt.toString(Qt::RFC2822Date), formatted); + QString actual(dt.toString(Qt::RFC2822Date)); QLocale::setDefault(oldLocale); + QCOMPARE(actual, formatted); } void tst_QDateTime::toString_enumformat() @@ -2350,17 +2351,27 @@ void tst_QDateTime::fromStringDateFormat_data() << Qt::RFC2822Date << invalidDateTime(); QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100") << Qt::RFC2822Date << invalidDateTime(); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 2822 invalid character at end") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC); - QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000") + QTest::newRow("RFC 2822 invalid character at front") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!") + QTest::newRow("RFC 2822 invalid character both ends") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..") + QTest::newRow("RFC 2822 invalid character at front, 2 at back") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") + QTest::newRow("RFC 2822 invalid character 2 at front") + << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << invalidDateTime(); + // The common date text used by the "invalid character" tests, just to be + // sure *it's* not what's invalid: + QTest::newRow("RFC 2822 (not invalid)") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100") + << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC); // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") @@ -2378,19 +2389,29 @@ void tst_QDateTime::fromStringDateFormat_data() QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970") << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); // No time specified - QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002") + QTest::newRow("RFC 850 and 1036 date only") + << QString::fromLatin1("Fri Nov 01 2002") << Qt::RFC2822Date << invalidDateTime(); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 850 and 1036 invalid character at end") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC); - QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000") + QTest::newRow("RFC 850 and 1036 invalid character at front") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!") + QTest::newRow("RFC 850 and 1036 invalid character both ends") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..") + QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..") << Qt::RFC2822Date << invalidDateTime(); - QTest::newRow("RFC 850 and 1036 invalid character 2 at front") << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0000") + QTest::newRow("RFC 850 and 1036 invalid character 2 at front") + << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << invalidDateTime(); + // Again, check the text in the "invalid character" tests isn't the source of invalidity: + QTest::newRow("RFC 850 and 1036 (not invalid)") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100") + << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC); QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidDateTime(); } diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index ed8700d93f..d8de6e585d 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -642,17 +642,27 @@ void tst_QTime::fromStringDateFormat_data() << Qt::RFC2822Date << QTime(13, 24, 51); QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100") << Qt::RFC2822Date << QTime(13, 24, 51); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 2822 invalid character at end") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QTime(8, 0, 0); - QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000") + QTest::newRow("RFC 2822 invalid character at front") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << invalidTime(); - QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!") + QTest::newRow("RFC 2822 invalid character both ends") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << invalidTime(); - QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..") + QTest::newRow("RFC 2822 invalid character at front, 2 at back") + << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << invalidTime(); - QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000") + QTest::newRow("RFC 2822 invalid character 2 at front") + << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << invalidTime(); + // The common date text used by the "invalid character" tests, just to be + // sure *it's* not what's invalid: + QTest::newRow("RFC 2822 invalid character at end") + << QString::fromLatin1("01 Jan 2012 08:00:00 +0100") + << Qt::RFC2822Date << QTime(8, 0, 0); // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") @@ -666,15 +676,24 @@ void tst_QTime::fromStringDateFormat_data() // No time specified QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002") << Qt::RFC2822Date << invalidTime(); - // Test invalid characters (should ignore invalid characters at end of string). - QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") + // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038). + QTest::newRow("RFC 850 and 1036 invalid character at end") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << QTime(8, 0, 0); - QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000") + QTest::newRow("RFC 850 and 1036 invalid character at front") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << invalidTime(); - QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!") + QTest::newRow("RFC 850 and 1036 invalid character both ends") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!") << Qt::RFC2822Date << invalidTime(); - QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..") + QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") + << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..") << Qt::RFC2822Date << invalidTime(); + // The common date text used by the "invalid character" tests, just to be + // sure *it's* not what's invalid: + QTest::newRow("RFC 850 and 1036 invalid character at end") + << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100") + << Qt::RFC2822Date << QTime(8, 0, 0); QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidTime(); } -- cgit v1.2.3 From cfd2f3c46eaefcaa8795a777d5e01fa85dd850a8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 26 Nov 2019 13:44:30 +0100 Subject: Work around macOS's inconsistency in naming of India's time-zone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS fails to create a zone for the name its own systemTimeZone claims to have (see new comment). So make sure we do consistently recognize the name systemTimeZoneId() returns, using systemTimeZone from which we got its name. Add minimal testing of system time-zone. Fixes: QTBUG-80173 Change-Id: I42f21efbd7c439158fee954d555414bb180e7f8f Reviewed-by: Tor Arne Vestbø --- tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index f425691d9c..4fdcbc7809 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -46,6 +46,7 @@ private slots: // Public class default system tests void createTest(); void nullTest(); + void systemZone(); void dataStreamTest(); void isTimeZoneIdAvailable(); void availableTimeZoneIds(); @@ -315,6 +316,14 @@ void tst_QTimeZone::nullTest() QCOMPARE(data.daylightTimeOffset, std::numeric_limits::min()); } +void tst_QTimeZone::systemZone() +{ + const QTimeZone zone = QTimeZone::systemTimeZone(); + QVERIFY(zone.isValid()); + QCOMPARE(zone.id(), QTimeZone::systemTimeZoneId()); + QCOMPARE(zone, QTimeZone(QTimeZone::systemTimeZoneId())); +} + void tst_QTimeZone::dataStreamTest() { // Test the OffsetFromUtc backend serialization. First with a custom timezone: -- cgit v1.2.3