#endif // CHANGE_SYSTEM_DATE
-// helper class setting the locale to "C" for its lifetime
-class CLocaleSetter
-{
-public:
- CLocaleSetter() : m_locOld(setlocale(LC_ALL, "C")) { }
- ~CLocaleSetter() { setlocale(LC_ALL, m_locOld); }
-
-private:
- const char * const m_locOld;
- wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
-};
-
// helper function translating week day/month names from English to the current
// locale
static wxString TranslateDate(const wxString& str)
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase );
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase, "DateTimeTestCase" );
// ============================================================================
{ { 16, wxDateTime::Oct, 1942, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 }, 42, 3, 3, 289 },
{ { 30, wxDateTime::Dec, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 }, 1, 5, 5, 364 },
{ { 2, wxDateTime::Jan, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 }, 1, 1, 1, 2 },
+ { { 5, wxDateTime::Jan, 2010, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 }, 1, 2, 2, 5 },
+ { { 3, wxDateTime::Jan, 2011, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 }, 1, 2, 2, 3 },
};
for ( size_t n = 0; n < WXSIZEOF(weekNumberTestDates); n++ )
wmon2 = dt.GetWeekOfMonth(wxDateTime::Sunday_First),
dnum = dt.GetDayOfYear();
- CPPUNIT_ASSERT_EQUAL( wn.dnum, dnum );
- CPPUNIT_ASSERT_EQUAL( wn.wmon, wmon );
- CPPUNIT_ASSERT_EQUAL( wn.wmon2, wmon2 );
- CPPUNIT_ASSERT_EQUAL( wn.week, week );
+ WX_ASSERT_EQUAL_MESSAGE( ("day of year for %s", d.Format()),
+ wn.dnum, dnum );
+ WX_ASSERT_EQUAL_MESSAGE( ("week of month (Monday) for %s", d.Format()),
+ wn.wmon, wmon );
+ WX_ASSERT_EQUAL_MESSAGE( ("week of month (Sunday) for %s", d.Format()),
+ wn.wmon2, wmon2 );
+ WX_ASSERT_EQUAL_MESSAGE( ("week of year for %s", d.Format()),
+ wn.week, week );
int year = d.year;
if ( week == 1 && d.month != wxDateTime::Jan )
{
// conversion failed - should it have?
WX_ASSERT_MESSAGE(
- ("Test #%lu failed: failed to parse \"%s\"", n, s),
+ ("Test #%u failed: failed to parse \"%s\"", n, s),
kind == CompareNone
);
}
result++;
WX_ASSERT_MESSAGE(
- ("Test #%lu failed: \"%s\" was left unparsed in \"%s\"",
+ ("Test #%u failed: \"%s\" was left unparsed in \"%s\"",
n, result, s),
!*result
);
{ "29 Feb 2006" },
{ "31/04/06" },
{ "bloordyblop" },
+ { "2 . . " },
};
// special cases
bool good;
} parseTestDates[] =
{
- { "Thu 22 Nov 2007 07:40:00 PM",
- { 22, wxDateTime::Nov, 2007, 19, 40, 0}, true },
+ {
+ "Thu 22 Nov 2007 07:40:00 PM",
+ { 22, wxDateTime::Nov, 2007, 19, 40, 0 },
+ true
+ },
+
+ {
+ "2010-01-04 14:30",
+ { 4, wxDateTime::Jan, 2010, 14, 30, 0 },
+ true
+ },
+
+ {
+ "bloordyblop",
+ { 1, wxDateTime::Jan, 9999, 0, 0, 0},
+ false
+ },
};
// the test strings here use "PM" which is not available in all locales so