Correct string comparison in Android's IANA ID matching code

It used QString.compare() and assumed it was returning a bool true on
equality, when it actually returns an int that compares to 0 as the
given strings compare. So it should use compare() == 0.

This fixes several of QTimeZone's blacklisted tests on Android and a
crasher, which we dodged with a QSKIP. Added an id-comparison to a
test. Gave two local variables more informative names, made an early
return into a QSKIP so it explains itself.

Fixes: QTBUG-89905
Fixes: QTBUG-69122
Fixes: QTBUG-69132
Fixes: QTBUG-87435
Change-Id: Icf18ed5a810143d6e65d36e34a70e82faac10b8e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 6ee13db700eecd8dfed54a9ec2d1081b39511562)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2021-01-08 13:48:51 +01:00 committed by Qt Cherry-pick Bot
parent f1efd15d43
commit 8b1194edea
3 changed files with 12 additions and 32 deletions

View File

@ -113,7 +113,7 @@ void QAndroidTimeZonePrivate::init(const QByteArray &ianaId)
// The ID or display name of the zone we've got, if it looks like what we asked for: // The ID or display name of the zone we've got, if it looks like what we asked for:
const auto match = [iana](const QJNIObjectPrivate &jname) -> QByteArray { const auto match = [iana](const QJNIObjectPrivate &jname) -> QByteArray {
const QString name = jname.toString(); const QString name = jname.toString();
if (iana.compare(name, Qt::CaseInsensitive)) if (iana.compare(name, Qt::CaseInsensitive) == 0)
return name.toUtf8(); return name.toUtf8();
return QByteArray(); return QByteArray();

View File

@ -1,7 +1,3 @@
# QTBUG-69122
[dataStreamTest]
android
# QTBUG-69129 # QTBUG-69129
[specificTransition] [specificTransition]
android android
@ -173,14 +169,3 @@ android
android android
[transitionEachZone:America/Danmarkshavn@1970] [transitionEachZone:America/Danmarkshavn@1970]
android android
# QTBUG-87435
[createTest]
android
[systemZone]
android
[utcOffsetId]
android
[stressTest]
android
[serialize]
android

View File

@ -155,25 +155,23 @@ void tst_QTimeZone::printTimeZone(const QTimeZone &tz)
void tst_QTimeZone::createTest() void tst_QTimeZone::createTest()
{ {
QTimeZone tz("Pacific/Auckland"); const QTimeZone tz("Pacific/Auckland");
if (debug) if (debug)
printTimeZone(tz); printTimeZone(tz);
// If the tz is not valid then skip as is probably using the UTC backend which is tested later // If the tz is not valid then skip as is probably using the UTC backend which is tested later
if (!tz.isValid()) if (!tz.isValid())
return; QSKIP("System lacks zone used for test"); // This returns.
// Validity tests QCOMPARE(tz.id(), "Pacific/Auckland");
QCOMPARE(tz.isValid(), true); // Comparison tests:
const QTimeZone same("Pacific/Auckland");
// Comparison tests QCOMPARE((tz == same), true);
QTimeZone tz2("Pacific/Auckland"); QCOMPARE((tz != same), false);
QTimeZone tz3("Australia/Sydney"); const QTimeZone other("Australia/Sydney");
QCOMPARE((tz == tz2), true); QCOMPARE((tz == other), false);
QCOMPARE((tz != tz2), false); QCOMPARE((tz != other), true);
QCOMPARE((tz == tz3), false);
QCOMPARE((tz != tz3), true);
QCOMPARE(tz.country(), QLocale::NewZealand); QCOMPARE(tz.country(), QLocale::NewZealand);
@ -447,6 +445,7 @@ void tst_QTimeZone::utcOffsetId_data()
ROW("UTC+12:00", true, 43200); ROW("UTC+12:00", true, 43200);
ROW("UTC+13:00", true, 46800); ROW("UTC+13:00", true, 46800);
ROW("UTC+14:00", true, 50400); ROW("UTC+14:00", true, 50400);
// Windows IDs known to CLDR v35.1: // Windows IDs known to CLDR v35.1:
ROW("UTC-11", true, -39600); ROW("UTC-11", true, -39600);
ROW("UTC-09", true, -32400); ROW("UTC-09", true, -32400);
@ -609,10 +608,6 @@ void tst_QTimeZone::transitionEachZone()
if (zone == "Europe/Samara" && i == -3) { if (zone == "Europe/Samara" && i == -3) {
continue; continue;
} }
#endif
#ifdef Q_OS_ANDROID
if (zone == "America/Mazatlan" || zone == "Mexico/BajaSur")
QSKIP("Crashes on Android, see QTBUG-69132");
#endif #endif
qint64 here = secs + i * 3600; qint64 here = secs + i * 3600;
QDateTime when = QDateTime::fromMSecsSinceEpoch(here * 1000, named); QDateTime when = QDateTime::fromMSecsSinceEpoch(here * 1000, named);