Clean up tst_QDateTime's conditions on zoneIsCET
In setMSecsSinceEpoch(), the CET end-of-time is invalid anyway, so a whole block (rather than just one sub-test of it) was irrelevant for the max-qint64 test case (aside from verifying cet *is* invalid). Split out to a separate test the part of a data-driven test that was the same for all data rows. Reworked several ill-advised ways to use QSKIP(). Change-Id: If757d3e722c81fc42a87256125ceef605b6bfb64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
74eddd5bf0
commit
e069f06da7
@ -98,6 +98,7 @@ private Q_SLOTS:
|
||||
void toLocalTime();
|
||||
void toUTC_data();
|
||||
void toUTC();
|
||||
void toUTC_extra();
|
||||
void daysTo();
|
||||
void secsTo_data();
|
||||
void secsTo();
|
||||
@ -685,7 +686,13 @@ void tst_QDateTime::setMSecsSinceEpoch()
|
||||
QCOMPARE(dt1.timeSpec(), Qt::UTC);
|
||||
}
|
||||
|
||||
if (zoneIsCET) {
|
||||
if (zoneIsCET && (msecs == std::numeric_limits<qint64>::max()
|
||||
// LocalTime will also overflow for min in a CET zone west
|
||||
// of Greenwich (Europe/Madrid):
|
||||
|| (preZoneFix < -3600 && msecs == std::numeric_limits<qint64>::min()))) {
|
||||
QVERIFY(!cet.isValid()); // overflows
|
||||
} else if (zoneIsCET) {
|
||||
QVERIFY(cet.isValid());
|
||||
QCOMPARE(dt.toLocalTime(), cet);
|
||||
|
||||
// Test converting from LocalTime to UTC back to LocalTime.
|
||||
@ -693,12 +700,7 @@ void tst_QDateTime::setMSecsSinceEpoch()
|
||||
localDt.setTimeSpec(Qt::LocalTime);
|
||||
localDt.setMSecsSinceEpoch(msecs);
|
||||
|
||||
// LocalTime will overflow for max
|
||||
if (msecs != std::numeric_limits<qint64>::max()
|
||||
//... or for min, if this CET zone is west of Greenwich (Europe/Madrid)
|
||||
&& (preZoneFix >= -3600 || msecs != std::numeric_limits<qint64>::min())) {
|
||||
QCOMPARE(localDt, utc);
|
||||
}
|
||||
QCOMPARE(localDt.timeSpec(), Qt::LocalTime);
|
||||
|
||||
// Compare result for LocalTime to TimeZone
|
||||
@ -1459,6 +1461,9 @@ void tst_QDateTime::addMSecs()
|
||||
|
||||
void tst_QDateTime::toTimeSpec_data()
|
||||
{
|
||||
if (!zoneIsCET)
|
||||
QSKIP("Not tested with timezone other than Central European (CET/CEST)");
|
||||
|
||||
QTest::addColumn<QDateTime>("fromUtc");
|
||||
QTest::addColumn<QDateTime>("fromLocal");
|
||||
|
||||
@ -1515,7 +1520,6 @@ void tst_QDateTime::toTimeSpec_data()
|
||||
|
||||
void tst_QDateTime::toTimeSpec()
|
||||
{
|
||||
if (zoneIsCET) {
|
||||
QFETCH(QDateTime, fromUtc);
|
||||
QFETCH(QDateTime, fromLocal);
|
||||
|
||||
@ -1570,9 +1574,6 @@ void tst_QDateTime::toTimeSpec()
|
||||
QCOMPARE(localToOffset.time(), fromUtc.time());
|
||||
QCOMPARE(localToOffset.timeSpec(), Qt::UTC);
|
||||
QCOMPARE(localToOffset.toTimeSpec(Qt::LocalTime), fromLocal);
|
||||
} else {
|
||||
QSKIP("Not tested with timezone other than Central European (CET/CEST)");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toLocalTime_data()
|
||||
@ -1582,16 +1583,12 @@ void tst_QDateTime::toLocalTime_data()
|
||||
|
||||
void tst_QDateTime::toLocalTime()
|
||||
{
|
||||
if (zoneIsCET) {
|
||||
QFETCH(QDateTime, fromUtc);
|
||||
QFETCH(QDateTime, fromLocal);
|
||||
|
||||
QCOMPARE(fromLocal.toLocalTime(), fromLocal);
|
||||
QCOMPARE(fromUtc.toLocalTime(), fromLocal);
|
||||
QCOMPARE(fromUtc.toLocalTime(), fromLocal.toLocalTime());
|
||||
} else {
|
||||
QSKIP("Not tested with timezone other than Central European (CET/CEST)");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toUTC_data()
|
||||
@ -1601,21 +1598,19 @@ void tst_QDateTime::toUTC_data()
|
||||
|
||||
void tst_QDateTime::toUTC()
|
||||
{
|
||||
if (zoneIsCET) {
|
||||
QFETCH(QDateTime, fromUtc);
|
||||
QFETCH(QDateTime, fromLocal);
|
||||
|
||||
QCOMPARE(fromUtc.toUTC(), fromUtc);
|
||||
QCOMPARE(fromLocal.toUTC(), fromUtc);
|
||||
QCOMPARE(fromUtc.toUTC(), fromLocal.toUTC());
|
||||
} else {
|
||||
QSKIP("Not tested with timezone other than Central European (CET/CEST)");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toUTC_extra()
|
||||
{
|
||||
QDateTime dt = QDateTime::currentDateTime();
|
||||
if(dt.time().msec() == 0){
|
||||
if (dt.time().msec() == 0)
|
||||
dt.setTime(dt.time().addMSecs(1));
|
||||
}
|
||||
QString s = dt.toString("zzz");
|
||||
QString t = dt.toUTC().toString("zzz");
|
||||
QCOMPARE(s, t);
|
||||
@ -2956,7 +2951,8 @@ void tst_QDateTime::offsetFromUtc()
|
||||
QDateTime dt4(QDate(2013, 6, 1), QTime(0, 0), Qt::LocalTime);
|
||||
QCOMPARE(dt4.offsetFromUtc(), 2 * 60 * 60);
|
||||
} else {
|
||||
QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo");
|
||||
qDebug("Skipped some tests specific to Central European Time "
|
||||
"(CET/CEST), e.g. TZ=Europe/Oslo");
|
||||
}
|
||||
|
||||
#if QT_CONFIG(timezone)
|
||||
@ -3279,13 +3275,16 @@ void tst_QDateTime::isDaylightTime() const
|
||||
QDateTime cet2(QDate(2012, 6, 1), QTime(0, 0));
|
||||
QVERIFY(cet2.isDaylightTime());
|
||||
} else {
|
||||
QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo");
|
||||
qDebug("Skipped some tests specific to Central European Time "
|
||||
"(CET/CEST), e.g. TZ=Europe/Oslo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::daylightTransitions() const
|
||||
{
|
||||
if (zoneIsCET) {
|
||||
if (!zoneIsCET)
|
||||
QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo");
|
||||
|
||||
// CET transitions occur at 01:00:00 UTC on last Sunday in March and October
|
||||
// 2011-03-27 02:00:00 CET became 03:00:00 CEST at msecs = 1301187600000
|
||||
// 2011-10-30 03:00:00 CEST became 02:00:00 CET at msecs = 1319936400000
|
||||
@ -3641,10 +3640,6 @@ void tst_QDateTime::daylightTransitions() const
|
||||
QEXPECT_FAIL("", "QDateTime doesn't properly support Daylight Transitions", Continue);
|
||||
#endif // Q_OS_WIN
|
||||
QCOMPARE(test.toMSecsSinceEpoch(), standard2012 + msecsOneHour);
|
||||
|
||||
} else {
|
||||
QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::timeZones() const
|
||||
|
Loading…
Reference in New Issue
Block a user