Give symbolic names to some constants used in time-zone tests

Where std::numeric_limits<...>::min() is used used as invalid value
for an API return, save it as a named constant so that the comparisons
are against an informative name, rather than leaving the reader to
guess the significance of the min-value.

Change-Id: Ia99c75e21856f65cb4494120d05eed36f5fc2d50
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-11-03 16:42:51 +01:00
parent 2b26dea51b
commit f4b19f8bba

View File

@ -300,24 +300,25 @@ void tst_QTimeZone::nullTest()
QCOMPARE(nullTz1.isDaylightTime(jun), false);
QTimeZone::OffsetData data = nullTz1.offsetData(jan);
constexpr auto invalidOffset = std::numeric_limits<int>::min();
QCOMPARE(data.atUtc, QDateTime());
QCOMPARE(data.offsetFromUtc, std::numeric_limits<int>::min());
QCOMPARE(data.standardTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.daylightTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.offsetFromUtc, invalidOffset);
QCOMPARE(data.standardTimeOffset, invalidOffset);
QCOMPARE(data.daylightTimeOffset, invalidOffset);
QCOMPARE(nullTz1.hasTransitions(), false);
data = nullTz1.nextTransition(jan);
QCOMPARE(data.atUtc, QDateTime());
QCOMPARE(data.offsetFromUtc, std::numeric_limits<int>::min());
QCOMPARE(data.standardTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.daylightTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.offsetFromUtc, invalidOffset);
QCOMPARE(data.standardTimeOffset, invalidOffset);
QCOMPARE(data.daylightTimeOffset, invalidOffset);
data = nullTz1.previousTransition(jan);
QCOMPARE(data.atUtc, QDateTime());
QCOMPARE(data.offsetFromUtc, std::numeric_limits<int>::min());
QCOMPARE(data.standardTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.daylightTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(data.offsetFromUtc, invalidOffset);
QCOMPARE(data.standardTimeOffset, invalidOffset);
QCOMPARE(data.daylightTimeOffset, invalidOffset);
}
void tst_QTimeZone::systemZone()
@ -1232,11 +1233,13 @@ void tst_QTimeZone::tzTest()
} else {
QCOMPARE(dat.standardTimeOffset, 3600);
constexpr qint64 invalidTime = std::numeric_limits<qint64>::min();
constexpr int invalidOffset = std::numeric_limits<int>::min();
// Test previous to low value is invalid
dat = tzp.previousTransition(-9999999999999);
QCOMPARE(dat.atMSecsSinceEpoch, std::numeric_limits<qint64>::min());
QCOMPARE(dat.standardTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(dat.daylightTimeOffset, std::numeric_limits<int>::min());
QCOMPARE(dat.atMSecsSinceEpoch, invalidTime);
QCOMPARE(dat.standardTimeOffset, invalidOffset);
QCOMPARE(dat.daylightTimeOffset, invalidOffset);
}
dat = tzp.nextTransition(-9999999999999);