Add tests for wxDateTime setters around DST end time

Check that setting the other date components doesn't change its hour.

See https://github.com/wxWidgets/wxWidgets/pull/367
This commit is contained in:
Vadim Zeitlin
2017-11-28 23:05:45 +01:00
parent 8415d12c61
commit e23ff6fded

View File

@@ -1586,4 +1586,54 @@ void DateTimeTestCase::TestConvToFromLocalTZ()
CPPUNIT_ASSERT_EQUAL( dt.ToTimezone(wxDateTime::Local), dt );
}
static void DoTestSetFunctionsOnDST(const wxDateTime &orig)
{
#define DST_TEST_FUN(func) \
{ \
wxDateTime copy = orig; \
copy.func; \
CHECK(orig.IsDST() == copy.IsDST()); \
CHECK(orig.GetHour() == copy.GetHour()); \
}
// Test the functions by just calling them with their existing values
// This is primarily just ensuring that we're not converting to a Tm and back
// but also if we do that we're handling it properly
DST_TEST_FUN(SetMinute(orig.GetMinute()));
DST_TEST_FUN(SetSecond(orig.GetSecond()));
DST_TEST_FUN(SetMillisecond(orig.GetMillisecond()));
DST_TEST_FUN(SetDay(orig.GetDay()));
DST_TEST_FUN(SetMonth(orig.GetMonth()));
DST_TEST_FUN(SetYear(orig.GetYear()));
// Test again by actually changing the time (this shouldn't affect DST)
// Can't test changing the date because that WILL affect DST
DST_TEST_FUN(SetMinute((orig.GetMinute() + 1) % 60));
DST_TEST_FUN(SetSecond((orig.GetSecond() + 1) % 60));
DST_TEST_FUN(SetMillisecond((orig.GetMillisecond() + 1) % 1000));
{
// Special case for set hour since it's ambiguous at DST we don't care if IsDST matches
wxDateTime copy = orig;
copy.SetHour(orig.GetHour());
CHECK(orig.GetHour() == copy.GetHour());
}
#undef DST_TEST_FUN
}
TEST_CASE("wxDateTime::SetOnDST", "[datetime][dst]")
{
wxDateTime dst = wxDateTime::GetEndDST();
if ( !dst.IsValid() )
{
WARN("Skipping test as DST period couldn't be determined.");
return;
}
// End DST is the 2nd 1am after DST ends so go back an hour to the first 1am
DoTestSetFunctionsOnDST(dst - wxTimeSpan::Hour());
DoTestSetFunctionsOnDST(dst);
}
#endif // wxUSE_DATETIME