QDateTime - Fix tests to correctly restore time zone
The unit tests were caching the original TZ value to restore later after testing with different TZ values. The problem is reading TZ will return a null value if no override TZ value is set, and if you then set the TZ to null the system assumes UTC and not the system time zone. Instead we need to unset TZ if it was null to start with. Change-Id: Ib0625b1712e565f9fdfa99e2ffe1e5d74f059354 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1696f45d92
commit
2f2a799f3d
@ -1430,8 +1430,9 @@ void tst_QDateTime::operator_insert_extract()
|
|||||||
QFETCH(QString, deserialiseAs);
|
QFETCH(QString, deserialiseAs);
|
||||||
QFETCH(QDataStream::Version, dataStreamVersion);
|
QFETCH(QDataStream::Version, dataStreamVersion);
|
||||||
|
|
||||||
// Save the previous timezone so we can restore it afterwards, just in case.
|
// Save the previous timezone so we can restore it afterwards, otherwise later tests will break
|
||||||
QString previousTimeZone = qgetenv("TZ");
|
QByteArray previousTimeZone = qgetenv("TZ");
|
||||||
|
|
||||||
// Start off in a certain timezone.
|
// Start off in a certain timezone.
|
||||||
qputenv("TZ", serialiseAs.toLocal8Bit().constData());
|
qputenv("TZ", serialiseAs.toLocal8Bit().constData());
|
||||||
tzset();
|
tzset();
|
||||||
@ -1512,7 +1513,10 @@ void tst_QDateTime::operator_insert_extract()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qputenv("TZ", previousTimeZone.toLocal8Bit().constData());
|
if (previousTimeZone.isNull())
|
||||||
|
qunsetenv("TZ");
|
||||||
|
else
|
||||||
|
qputenv("TZ", previousTimeZone.constData());
|
||||||
tzset();
|
tzset();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user