-// ----------------------------------------------------------------------------
-// wxDir
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_DIR
-
-#include <wx/dir.h>
-
-static void TestDirEnumHelper(wxDir& dir,
- int flags = wxDIR_DEFAULT,
- const wxString& filespec = wxEmptyString)
-{
- wxString filename;
-
- if ( !dir.IsOpened() )
- return;
-
- bool cont = dir.GetFirst(&filename, filespec, flags);
- while ( cont )
- {
- printf("\t%s\n", filename.c_str());
-
- cont = dir.GetNext(&filename);
- }
-
- puts("");
-}
-
-static void TestDirEnum()
-{
- wxDir dir(wxGetCwd());
-
- puts("Enumerating everything in current directory:");
- TestDirEnumHelper(dir);
-
- puts("Enumerating really everything in current directory:");
- TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
-
- puts("Enumerating object files in current directory:");
- TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o");
-
- puts("Enumerating directories in current directory:");
- TestDirEnumHelper(dir, wxDIR_DIRS);
-
- puts("Enumerating files in current directory:");
- TestDirEnumHelper(dir, wxDIR_FILES);
-
- puts("Enumerating files including hidden in current directory:");
- TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
-
-#ifdef __UNIX__
- dir.Open("/");
-#elif defined(__WXMSW__)
- dir.Open("c:\\");
-#else
- #error "don't know where the root directory is"
-#endif
-
- puts("Enumerating everything in root directory:");
- TestDirEnumHelper(dir, wxDIR_DEFAULT);
-
- puts("Enumerating directories in root directory:");
- TestDirEnumHelper(dir, wxDIR_DIRS);
-
- puts("Enumerating files in root directory:");
- TestDirEnumHelper(dir, wxDIR_FILES);
-
- puts("Enumerating files including hidden in root directory:");
- TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
-
- puts("Enumerating files in non existing directory:");
- wxDir dirNo("nosuchdir");
- TestDirEnumHelper(dirNo);
-}
-
-#endif // TEST_DIR
-
-// ----------------------------------------------------------------------------
-// MIME types
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_MIME
-
-#include <wx/mimetype.h>
-
-static void TestMimeEnum()
-{
- wxMimeTypesManager mimeTM;
- wxArrayString mimetypes;
-
- size_t count = mimeTM.EnumAllFileTypes(mimetypes);
-
- printf("*** All %u known filetypes: ***\n", count);
-
- wxArrayString exts;
- wxString desc;
-
- for ( size_t n = 0; n < count; n++ )
- {
- wxFileType *filetype = mimeTM.GetFileTypeFromMimeType(mimetypes[n]);
- if ( !filetype )
- {
- printf("nothing known about the filetype '%s'!\n",
- mimetypes[n].c_str());
- continue;
- }
-
- filetype->GetDescription(&desc);
- filetype->GetExtensions(exts);
-
- wxString extsAll;
- for ( size_t e = 0; e < exts.GetCount(); e++ )
- {
- if ( e > 0 )
- extsAll << _T(", ");
- extsAll += exts[e];
- }
-
- printf("\t%s: %s (%s)\n",
- mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
- }
-}
-
-#endif // TEST_MIME
-
-// ----------------------------------------------------------------------------
-// long long
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_LONGLONG
-
-#include <wx/longlong.h>
-#include <wx/timer.h>
-
-static void TestSpeed()
-{
- static const long max = 100000000;
- long n;
-
- {
- wxStopWatch sw;
-
- long l = 0;
- for ( n = 0; n < max; n++ )
- {
- l += n;
- }
-
- printf("Summing longs took %ld milliseconds.\n", sw.Time());
- }
-
- {
- wxStopWatch sw;
-
- __int64 l = 0;
- for ( n = 0; n < max; n++ )
- {
- l += n;
- }
-
- printf("Summing __int64s took %ld milliseconds.\n", sw.Time());
- }
-
- {
- wxStopWatch sw;
-
- wxLongLong l;
- for ( n = 0; n < max; n++ )
- {
- l += n;
- }
-
- printf("Summing wxLongLongs took %ld milliseconds.\n", sw.Time());
- }
-}
-
-static void TestDivision()
-{
- #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
-
- // seed pseudo random generator
- //srand((unsigned)time(NULL));
-
- size_t nTested = 0;
- for ( size_t n = 0; n < 10000; n++ )
- {
- // get a random wxLongLong (shifting by 12 the MSB ensures that the
- // multiplication will not overflow)
- wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
-
- wxASSERT( (ll * 1000l)/1000l == ll );
-
- nTested++;
- }
-
- printf("\n*** Tested %u divisions/multiplications: ok\n", nTested);
-
- #undef MAKE_LL
-}
-
-#endif // TEST_LONGLONG
-
-// ----------------------------------------------------------------------------
-// date time
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_TIME
-
-#include <wx/datetime.h>
-
-// this test miscellaneous static wxDateTime functions
-static void TestTimeStatic()
-{
- puts("\n*** wxDateTime static methods test ***");
-
- // some info about the current date
- int year = wxDateTime::GetCurrentYear();
- printf("Current year %d is %sa leap one and has %d days.\n",
- year,
- wxDateTime::IsLeapYear(year) ? "" : "not ",
- wxDateTime::GetNumberOfDays(year));
-
- 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).c_str(),
- wxDateTime::GetNumberOfDays(month));
-
- // leap year logic
- static const size_t nYears = 5;
- static const size_t years[2][nYears] =
- {
- // first line: the years to test
- { 1990, 1976, 2000, 2030, 1984, },
-
- // second line: TRUE if leap, FALSE otherwise
- { FALSE, TRUE, TRUE, FALSE, TRUE }
- };
-
- for ( size_t n = 0; n < nYears; n++ )
- {
- int year = years[0][n];
- bool should = years[1][n] != 0;
-
- printf("Year %d is %sa leap year (should be: %s)\n",
- year,
- wxDateTime::IsLeapYear(year) ? "" : "not ",
- should ? "yes" : "no");
-
- wxASSERT( should == wxDateTime::IsLeapYear(year) );
- }
-}
-
-// test constructing wxDateTime objects
-static void TestTimeSet()
-{
- puts("\n*** wxDateTime construction test ***");
-
- printf("Current time:\t%s\n", wxDateTime::Now().Format().c_str());
- printf("Unix epoch:\t%s\n", wxDateTime((time_t)0).Format().c_str());
- printf("Today noon:\t%s\n", wxDateTime(12, 0).Format().c_str());
- printf("May 29, 1976:\t%s\n", wxDateTime(29, wxDateTime::May, 1976).Format().c_str());
-}
-
-// test time zones stuff
-static void TestTimeZones()
-{
- puts("\n*** wxDateTime timezone test ***");
-
- wxDateTime now = wxDateTime::Now();
-
- printf("Current GMT time:\t%s\n", now.ToGMT().Format().c_str());
- printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).MakeGMT().Format().c_str());
- printf("Current time in Paris:\t%s\n", now.ToTimezone(wxDateTime::CET).Format().c_str());
- printf(" Moscow:\t%s\n", now.ToTimezone(wxDateTime::MSK).Format().c_str());
- printf(" New York:\t%s\n", now.ToTimezone(wxDateTime::EST).Format().c_str());
-}
-
-// test some minimal support for the dates outside the standard range
-static void TestTimeRange()
-{
- puts("\n*** wxDateTime out-of-standard-range dates test ***");
-
- printf("Unix epoch:\t%s\n",
- wxDateTime(2440587.5).Format().c_str());
- printf("Feb 29, 0: \t%s\n",
- wxDateTime(29, wxDateTime::Feb, 0).Format().c_str());
- printf("JDN 0: \t%s\n",
- wxDateTime(0.0).Format().c_str());
- printf("Jan 1, 1AD:\t%s\n",
- wxDateTime(1, wxDateTime::Jan, 1).Format().c_str());
- printf("May 29, 2099:\t%s\n",
- wxDateTime(29, wxDateTime::May, 2099).Format().c_str());
-}
-
-// test conversions to JDN &c
-static void TestTimeJDN()
-{
- puts("\n*** wxDateTime to JDN test ***");
-
- struct Date
- {
- wxDateTime::wxDateTime_t day;
- wxDateTime::Month month;
- int year;
- double jdn;
- };
-
- static const Date testDates[] =
- {
- { 21, wxDateTime::Jan, 2222, 2532648.5 },
- { 29, wxDateTime::May, 1976, 2442927.5 },
- { 1, wxDateTime::Jan, 1970, 2440587.5 },
- { 1, wxDateTime::Jan, 1900, 2415020.5 },
- { 15, wxDateTime::Oct, 1582, 2299160.5 },
- { 4, wxDateTime::Oct, 1582, 2299149.5 },
- { 1, wxDateTime::Mar, 1, 1721484.5 },
- { 1, wxDateTime::Jan, 1, 1721425.5 },
- { 31, wxDateTime::Dec, 0, 1721424.5 },
- { 1, wxDateTime::Jan, 0, 1721059.5 },
- { 12, wxDateTime::Aug, -1234, 1270573.5 },
- { 12, wxDateTime::Aug, -4000, 260313.5 },
- { 24, wxDateTime::Nov, -4713, -0.5 },
- };
-
- for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
- {
- const Date& d = testDates[n];
- wxDateTime dt(d.day, d.month, d.year);
- double jdn = dt.GetJulianDayNumber();
-
- printf("JDN of %s %02d, %4d%s is:\t%f",
- wxDateTime::GetMonthName(d.month).c_str(),
- d.day,
- wxDateTime::ConvertYearToBC(d.year),
- d.year > 0 ? "AD" : "BC",
- jdn);
- if ( jdn == d.jdn )
- {
- puts(" (ok)");
- }
- else
- {
- printf(" (ERROR: should be %f, delta = %f)\n",
- d.jdn, jdn - d.jdn);
- }
- }
-}
-
-#endif // TEST_TIME
-
-// ----------------------------------------------------------------------------
-// threads
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_THREADS
-
-#include <wx/thread.h>
-
-static size_t gs_counter = (size_t)-1;
-static wxCriticalSection gs_critsect;
-static wxCondition gs_cond;
-
-class MyJoinableThread : public wxThread