correct DateTimeTestCase::TestTimeTicks() [backport of r53902 from trunk]
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53917 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -87,6 +87,10 @@
|
|||||||
// Use this macro to compare a size_t with a literal integer
|
// Use this macro to compare a size_t with a literal integer
|
||||||
#define WX_ASSERT_SIZET_EQUAL(n, m) CPPUNIT_ASSERT_EQUAL(((size_t)n), m)
|
#define WX_ASSERT_SIZET_EQUAL(n, m) CPPUNIT_ASSERT_EQUAL(((size_t)n), m)
|
||||||
|
|
||||||
|
// Use this macro to compare the expected time_t value with the result of not
|
||||||
|
// necessarily time_t type
|
||||||
|
#define WX_ASSERT_TIME_T_EQUAL(t, n) CPPUNIT_ASSERT_EQUAL((t), (time_t)(n))
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// stream inserter for wxString
|
// stream inserter for wxString
|
||||||
|
@@ -718,23 +718,31 @@ void DateTimeTestCase::TestTimeSpanFormat()
|
|||||||
|
|
||||||
void DateTimeTestCase::TestTimeTicks()
|
void DateTimeTestCase::TestTimeTicks()
|
||||||
{
|
{
|
||||||
|
static const wxDateTime::TimeZone TZ_LOCAL(wxDateTime::Local);
|
||||||
|
static const wxDateTime::TimeZone TZ_TEST(wxDateTime::NZST);
|
||||||
|
|
||||||
|
// this offset is needed to make the test work in any time zone when we
|
||||||
|
// only have expected test results in UTC in testDates
|
||||||
|
static const long tzOffset = TZ_LOCAL.GetOffset() - TZ_TEST.GetOffset();
|
||||||
|
|
||||||
for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
|
for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
|
||||||
{
|
{
|
||||||
const Date& d = testDates[n];
|
const Date& d = testDates[n];
|
||||||
if ( d.ticks == -1 )
|
if ( d.gmticks == -1 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
wxDateTime dt = d.DT();
|
wxDateTime dt = d.DT().MakeTimezone(TZ_TEST, true /* no DST */);
|
||||||
//RN: Translate according to test's time zone
|
|
||||||
//2nd param is to ignore DST - it's already factored
|
|
||||||
//into Vadim's tests
|
|
||||||
dt.MakeTimezone(wxDateTime::WEST, true);
|
|
||||||
long ticks = (dt.GetValue() / 1000).ToLong();
|
|
||||||
CPPUNIT_ASSERT( ticks == d.ticks );
|
|
||||||
|
|
||||||
dt = d.DT().FromTimezone(wxDateTime::GMT0);
|
// GetValue() returns internal UTC-based representation, we need to
|
||||||
|
// convert it to local TZ before comparing
|
||||||
|
long ticks = (dt.GetValue() / 1000).ToLong() + TZ_LOCAL.GetOffset();
|
||||||
|
if ( dt.IsDST() )
|
||||||
|
ticks += 3600;
|
||||||
|
WX_ASSERT_TIME_T_EQUAL( d.gmticks, ticks + tzOffset );
|
||||||
|
|
||||||
|
dt = d.DT().FromTimezone(wxDateTime::UTC);
|
||||||
ticks = (dt.GetValue() / 1000).ToLong();
|
ticks = (dt.GetValue() / 1000).ToLong();
|
||||||
CPPUNIT_ASSERT( ticks == d.gmticks );
|
WX_ASSERT_TIME_T_EQUAL( d.gmticks, ticks );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user