//#define TEST_ARRAYS
//#define TEST_DIR
//#define TEST_LOG
+#define TEST_LONGLONG
//#define TEST_MIME
//#define TEST_STRINGS
//#define TEST_THREADS
-#define TEST_TIME
-//#define TEST_LONGLONG
+//#define TEST_TIME
// ============================================================================
// implementation
printf("Summing longs took %ld milliseconds.\n", sw.Time());
}
+#if wxUSE_LONGLONG_NATIVE
{
wxStopWatch sw;
- __int64 l = 0;
+ wxLongLong_t l = 0;
for ( n = 0; n < max; n++ )
{
l += n;
}
- printf("Summing __int64s took %ld milliseconds.\n", sw.Time());
+ printf("Summing wxLongLong_t took %ld milliseconds.\n", sw.Time());
}
+#endif // wxUSE_LONGLONG_NATIVE
{
wxStopWatch sw;
// seed pseudo random generator
//srand((unsigned)time(NULL));
+ wxLongLong q, r;
size_t nTested = 0;
for ( size_t n = 0; n < 10000; n++ )
{
// multiplication will not overflow)
wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
- wxASSERT( (ll * 1000l)/1000l == ll );
+ // get a random long (not wxLongLong for now) to divide it with
+ long l = rand();
+ q = ll / l;
+ r = ll % l;
+
+ wxASSERT_MSG( ll == q*l + r, "division failure" );
nTested++;
}
wxString s;
s.Printf("%02d-%s-%4d%s",
day,
- wxDateTime::GetMonthName(month, TRUE).c_str(),
+ wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
abs(wxDateTime::ConvertYearToBC(year)),
year > 0 ? "AD" : "BC");
return s;
wxDateTime::Month month = wxDateTime::GetCurrentMonth();
printf("Current month is '%s' ('%s') and it has %d days\n",
- wxDateTime::GetMonthName(month, TRUE).c_str(),
+ wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
wxDateTime::GetMonthName(month).c_str(),
wxDateTime::GetNumberOfDays(month));
{
puts("\n*** wxDateTime formatting test ***");
- static const char *formatTestFormats[] =
+ // some information may be lost during conversion, so store what kind
+ // of info should we recover after a round trip
+ enum CompareKind
+ {
+ CompareNone, // don't try comparing
+ CompareBoth, // dates and times should be identical
+ CompareDate, // dates only
+ CompareTime // time only
+ };
+
+ static const struct
+ {
+ CompareKind compareKind;
+ const char *format;
+ } formatTestFormats[] =
{
- "%c",
- "Date is %A, %d of %B, in year %Y",
- "Date is %x, time is %X",
- "Time is %H:%M:%S or %I:%M:%S %p",
- "The day of year: %j, the week of year: %W",
+ { CompareBoth, "---> %c" },
+ { CompareDate, "Date is %A, %d of %B, in year %Y" },
+ { CompareBoth, "Date is %x, time is %X" },
+ { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
+ { CompareNone, "The day of year: %j, the week of year: %W" },
};
static const Date formatTestDates[] =
{
- { }, // unused
{ 29, wxDateTime::May, 1976, 18, 30, 00 },
{ 31, wxDateTime::Dec, 1999, 23, 30, 00 },
+#if 0
+ // this test can't work for other centuries because it uses two digit
+ // years in formats, so don't even try it
{ 29, wxDateTime::May, 2076, 18, 30, 00 },
{ 29, wxDateTime::Feb, 2400, 02, 15, 25 },
{ 01, wxDateTime::Jan, -52, 03, 16, 47 },
+#endif
};
// an extra test (as it doesn't depend on date, don't do it in the loop)
printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
- for ( size_t d = 0; d < WXSIZEOF(formatTestDates); d++ )
+ for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ )
{
puts("");
- wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d].DT();
+ wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT();
for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
{
- printf("%s\n", dt.Format(formatTestFormats[n]).c_str());
+ wxString s = dt.Format(formatTestFormats[n].format);
+ printf("%s", s.c_str());
+
+ // what can we recover?
+ int kind = formatTestFormats[n].compareKind;
+
+ // convert back
+ wxDateTime dt2;
+ const wxChar *result = dt2.ParseFormat(s, formatTestFormats[n].format);
+ if ( !result )
+ {
+ // converion failed - should it have?
+ if ( kind == CompareNone )
+ puts(" (ok)");
+ else
+ puts(" (ERROR: conversion back failed)");
+ }
+ else if ( *result )
+ {
+ // should have parsed the entire string
+ puts(" (ERROR: conversion back stopped too soon)");
+ }
+ else
+ {
+ bool equal = FALSE; // suppress compilaer warning
+ switch ( kind )
+ {
+ case CompareBoth:
+ equal = dt2 == dt;
+ break;
+
+ case CompareDate:
+ equal = dt.IsSameDate(dt2);
+ break;
+
+ case CompareTime:
+ equal = dt.IsSameTime(dt2);
+ break;
+ }
+
+ if ( !equal )
+ {
+ printf(" (ERROR: got back '%s' instead of '%s')\n",
+ dt2.Format().c_str(), dt.Format().c_str());
+ }
+ else
+ {
+ puts(" (ok)");
+ }
+ }
}
}
}
puts("");
}
+static void TestStringFormat()
+{
+ puts("*** Testing wxString formatting ***");
+
+ wxString s;
+ s.Printf("%03d", 18);
+
+ printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
+ printf("Number 18: %s\n", s.c_str());
+
+ puts("");
+}
+
#endif // TEST_STRINGS
// ----------------------------------------------------------------------------
TestPChar();
TestString();
}
- TestStringSub();
+ if ( 0 )
+ {
+ TestStringSub();
+ }
+ TestStringFormat();
#endif // TEST_STRINGS
#ifdef TEST_ARRAYS