// what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
// test, define it to 1 to do all tests.
-#define TEST_ALL 1
+#define TEST_ALL 0
#if TEST_ALL
#define TEST_STACKWALKER
#define TEST_STDPATHS
#define TEST_STREAMS
- #define TEST_TEXTSTREAM
#define TEST_TIMER
// #define TEST_VOLUME --FIXME! (RN)
- #define TEST_WCHAR
- #define TEST_ZIP
#else // #if TEST_ALL
- #define TEST_FTP
+ #define TEST_DATETIME
#endif
// some tests are interactive, define this to run them
#define TEST_INTERACTIVE 1
#else
- #define TEST_INTERACTIVE 0
+ #define TEST_INTERACTIVE 1
#endif
// ============================================================================
#endif // TEST_VOLUME
-// ----------------------------------------------------------------------------
-// wide char and Unicode support
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_WCHAR
-
-#include "wx/strconv.h"
-#include "wx/fontenc.h"
-#include "wx/encconv.h"
-#include "wx/buffer.h"
-
-static const unsigned char utf8koi8r[] =
-{
- 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
- 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
- 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
- 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
- 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
- 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
- 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
-};
-
-static const unsigned char utf8iso8859_1[] =
-{
- 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
- 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
- 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
- 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
- 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
-};
-
-static const unsigned char utf8Invalid[] =
-{
- 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
- 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
- 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
- 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
- 0x6c, 0x61, 0x79, 0
-};
-
-static const struct Utf8Data
-{
- const unsigned char *text;
- size_t len;
- const wxChar *charset;
- wxFontEncoding encoding;
-} utf8data[] =
-{
- { utf8Invalid, WXSIZEOF(utf8Invalid), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1 },
- { utf8koi8r, WXSIZEOF(utf8koi8r), wxT("koi8-r"), wxFONTENCODING_KOI8 },
- { utf8iso8859_1, WXSIZEOF(utf8iso8859_1), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1 },
-};
-
-static void TestUtf8()
-{
- wxPuts(wxT("*** Testing UTF8 support ***\n"));
-
- char buf[1024];
- wchar_t wbuf[1024];
-
- for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
- {
- const Utf8Data& u8d = utf8data[n];
- if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text,
- WXSIZEOF(wbuf)) == (size_t)-1 )
- {
- wxPuts(wxT("ERROR: UTF-8 decoding failed."));
- }
- else
- {
- wxCSConv conv(u8d.charset);
- if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 )
- {
- wxPrintf(wxT("ERROR: conversion to %s failed.\n"), u8d.charset);
- }
- else
- {
- wxPrintf(wxT("String in %s: %s\n"), u8d.charset, buf);
- }
- }
-
- wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
- if ( s.empty() )
- s = wxT("<< conversion failed >>");
- wxPrintf(wxT("String in current cset: %s\n"), s.c_str());
-
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestEncodingConverter()
-{
- wxPuts(wxT("*** Testing wxEncodingConverter ***\n"));
-
- // using wxEncodingConverter should give the same result as above
- char buf[1024];
- wchar_t wbuf[1024];
- if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r,
- WXSIZEOF(utf8koi8r)) == (size_t)-1 )
- {
- wxPuts(wxT("ERROR: UTF-8 decoding failed."));
- }
- else
- {
- wxEncodingConverter ec;
- ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
- ec.Convert(wbuf, buf);
- wxPrintf(wxT("The same KOI8-R string using wxEC: %s\n"), buf);
- }
-
- wxPuts(wxEmptyString);
-}
-
-#endif // TEST_WCHAR
-
-// ----------------------------------------------------------------------------
-// ZIP stream
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_ZIP
-
-#include "wx/filesys.h"
-#include "wx/fs_zip.h"
-#include "wx/zipstrm.h"
-
-static const wxChar *TESTFILE_ZIP = wxT("testdata.zip");
-
-static void TestZipStreamRead()
-{
- wxPuts(wxT("*** Testing ZIP reading ***\n"));
-
- static const wxString filename = wxT("foo");
- wxFFileInputStream in(TESTFILE_ZIP);
- wxZipInputStream istr(in);
- wxZipEntry entry(filename);
- istr.OpenEntry(entry);
-
- wxPrintf(wxT("Archive size: %u\n"), istr.GetSize());
-
- wxPrintf(wxT("Dumping the file '%s':\n"), filename.c_str());
- int c;
- while ( (c=istr.GetC()) != wxEOF )
- {
- wxPutchar(c);
- fflush(stdout);
- }
-
- wxPuts(wxT("\n----- done ------"));
-}
-
-static void DumpZipDirectory(wxFileSystem& fs,
- const wxString& dir,
- const wxString& indent)
-{
- wxString prefix = wxString::Format(wxT("%s#zip:%s"),
- TESTFILE_ZIP, dir.c_str());
- wxString wildcard = prefix + wxT("/*");
-
- wxString dirname = fs.FindFirst(wildcard, wxDIR);
- while ( !dirname.empty() )
- {
- if ( !dirname.StartsWith(prefix + wxT('/'), &dirname) )
- {
- wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
-
- break;
- }
-
- wxPrintf(wxT("%s%s\n"), indent.c_str(), dirname.c_str());
-
- DumpZipDirectory(fs, dirname,
- indent + wxString(wxT(' '), 4));
-
- dirname = fs.FindNext();
- }
-
- wxString filename = fs.FindFirst(wildcard, wxFILE);
- while ( !filename.empty() )
- {
- if ( !filename.StartsWith(prefix, &filename) )
- {
- wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
-
- break;
- }
-
- wxPrintf(wxT("%s%s\n"), indent.c_str(), filename.c_str());
-
- filename = fs.FindNext();
- }
-}
-
-static void TestZipFileSystem()
-{
- wxPuts(wxT("*** Testing ZIP file system ***\n"));
-
- wxFileSystem::AddHandler(new wxZipFSHandler);
- wxFileSystem fs;
- wxPrintf(wxT("Dumping all files in the archive %s:\n"), TESTFILE_ZIP);
-
- DumpZipDirectory(fs, wxT(""), wxString(wxT(' '), 4));
-}
-
-#endif // TEST_ZIP
-
// ----------------------------------------------------------------------------
// date time
// ----------------------------------------------------------------------------
#include "wx/math.h"
#include "wx/datetime.h"
-// this test miscellaneous static wxDateTime functions
-
-#if TEST_ALL
-
-static void TestTimeStatic()
-{
- wxPuts(wxT("\n*** wxDateTime static methods test ***"));
-
- // some info about the current date
- int year = wxDateTime::GetCurrentYear();
- wxPrintf(wxT("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();
- wxPrintf(wxT("Current month is '%s' ('%s') and it has %d days\n"),
- wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
- wxDateTime::GetMonthName(month).c_str(),
- wxDateTime::GetNumberOfDays(month));
-}
-
-// test time zones stuff
-static void TestTimeZones()
-{
- wxPuts(wxT("\n*** wxDateTime timezone test ***"));
-
- wxDateTime now = wxDateTime::Now();
-
- wxPrintf(wxT("Current GMT time:\t%s\n"), now.Format(wxT("%c"), wxDateTime::GMT0).c_str());
- wxPrintf(wxT("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime::GMT0).c_str());
- wxPrintf(wxT("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime::EST).c_str());
- wxPrintf(wxT("Current time in Paris:\t%s\n"), now.Format(wxT("%c"), wxDateTime::CET).c_str());
- wxPrintf(wxT(" Moscow:\t%s\n"), now.Format(wxT("%c"), wxDateTime::MSK).c_str());
- wxPrintf(wxT(" New York:\t%s\n"), now.Format(wxT("%c"), wxDateTime::EST).c_str());
-
- wxPrintf(wxT("%s\n"), wxDateTime::Now().Format(wxT("Our timezone is %Z")).c_str());
-
- wxDateTime::Tm tm = now.GetTm();
- if ( wxDateTime(tm) != now )
- {
- wxPrintf(wxT("ERROR: got %s instead of %s\n"),
- wxDateTime(tm).Format().c_str(), now.Format().c_str());
- }
-}
-
-// test some minimal support for the dates outside the standard range
-static void TestTimeRange()
-{
- wxPuts(wxT("\n*** wxDateTime out-of-standard-range dates test ***"));
-
- static const wxChar *fmt = wxT("%d-%b-%Y %H:%M:%S");
-
- wxPrintf(wxT("Unix epoch:\t%s\n"),
- wxDateTime(2440587.5).Format(fmt).c_str());
- wxPrintf(wxT("Feb 29, 0: \t%s\n"),
- wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str());
- wxPrintf(wxT("JDN 0: \t%s\n"),
- wxDateTime(0.0).Format(fmt).c_str());
- wxPrintf(wxT("Jan 1, 1AD:\t%s\n"),
- wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str());
- wxPrintf(wxT("May 29, 2099:\t%s\n"),
- wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str());
-}
-
-// test DST calculations
-static void TestTimeDST()
-{
- wxPuts(wxT("\n*** wxDateTime DST test ***"));
-
- wxPrintf(wxT("DST is%s in effect now.\n\n"),
- wxDateTime::Now().IsDST() ? wxEmptyString : wxT(" not"));
-
- for ( int year = 1990; year < 2005; year++ )
- {
- wxPrintf(wxT("DST period in Europe for year %d: from %s to %s\n"),
- year,
- wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
- wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
- }
-}
-
-#endif // TEST_ALL
-
#if TEST_INTERACTIVE
static void TestDateTimeInteractive()
}
#endif // TEST_INTERACTIVE
-
-#if TEST_ALL
-
-static void TestTimeMS()
-{
- wxPuts(wxT("*** testing millisecond-resolution support in wxDateTime ***"));
-
- wxDateTime dt1 = wxDateTime::Now(),
- dt2 = wxDateTime::UNow();
-
- wxPrintf(wxT("Now = %s\n"), dt1.Format(wxT("%H:%M:%S:%l")).c_str());
- wxPrintf(wxT("UNow = %s\n"), dt2.Format(wxT("%H:%M:%S:%l")).c_str());
- wxPrintf(wxT("Dummy loop: "));
- for ( int i = 0; i < 6000; i++ )
- {
- //for ( int j = 0; j < 10; j++ )
- {
- wxString s;
- s.Printf(wxT("%g"), sqrt((float)i));
- }
-
- if ( !(i % 100) )
- wxPutchar('.');
- }
- wxPuts(wxT(", done"));
-
- dt1 = dt2;
- dt2 = wxDateTime::UNow();
- wxPrintf(wxT("UNow = %s\n"), dt2.Format(wxT("%H:%M:%S:%l")).c_str());
-
- wxPrintf(wxT("Loop executed in %s ms\n"), (dt2 - dt1).Format(wxT("%l")).c_str());
-
- wxPuts(wxT("\n*** done ***"));
-}
-
-static void TestTimeHolidays()
-{
- wxPuts(wxT("\n*** testing wxDateTimeHolidayAuthority ***\n"));
-
- wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
- wxDateTime dtStart(1, tm.mon, tm.year),
- dtEnd = dtStart.GetLastMonthDay();
-
- wxDateTimeArray hol;
- wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
-
- const wxChar *format = wxT("%d-%b-%Y (%a)");
-
- wxPrintf(wxT("All holidays between %s and %s:\n"),
- dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
-
- size_t count = hol.GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- wxPrintf(wxT("\t%s\n"), hol[n].Format(format).c_str());
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestTimeZoneBug()
-{
- wxPuts(wxT("\n*** testing for DST/timezone bug ***\n"));
-
- wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000);
- for ( int i = 0; i < 31; i++ )
- {
- wxPrintf(wxT("Date %s: week day %s.\n"),
- date.Format(wxT("%d-%m-%Y")).c_str(),
- date.GetWeekDayName(date.GetWeekDay()).c_str());
-
- date += wxDateSpan::Day();
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestTimeSpanFormat()
-{
- wxPuts(wxT("\n*** wxTimeSpan tests ***"));
-
- static const wxChar *formats[] =
- {
- wxT("(default) %H:%M:%S"),
- wxT("%E weeks and %D days"),
- wxT("%l milliseconds"),
- wxT("(with ms) %H:%M:%S:%l"),
- wxT("100%% of minutes is %M"), // test "%%"
- wxT("%D days and %H hours"),
- wxT("or also %S seconds"),
- };
-
- wxTimeSpan ts1(1, 2, 3, 4),
- ts2(111, 222, 333);
- for ( size_t n = 0; n < WXSIZEOF(formats); n++ )
- {
- wxPrintf(wxT("ts1 = %s\tts2 = %s\n"),
- ts1.Format(formats[n]).c_str(),
- ts2.Format(formats[n]).c_str());
- }
-
- wxPuts(wxEmptyString);
-}
-
-#endif // TEST_ALL
-
#endif // TEST_DATETIME
-// ----------------------------------------------------------------------------
-// wxTextInput/OutputStream
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_TEXTSTREAM
-
-#include "wx/txtstrm.h"
-#include "wx/wfstream.h"
-
-static void TestTextInputStream()
-{
- wxPuts(wxT("\n*** wxTextInputStream test ***"));
-
- wxString filename = wxT("testdata.fc");
- wxFileInputStream fsIn(filename);
- if ( !fsIn.Ok() )
- {
- wxPuts(wxT("ERROR: couldn't open file."));
- }
- else
- {
- wxTextInputStream tis(fsIn);
-
- size_t line = 1;
- for ( ;; )
- {
- const wxString s = tis.ReadLine();
-
- // line could be non empty if the last line of the file isn't
- // terminated with EOL
- if ( fsIn.Eof() && s.empty() )
- break;
-
- wxPrintf(wxT("Line %d: %s\n"), line++, s.c_str());
- }
- }
-}
-
-#endif // TEST_TEXTSTREAM
-
// ----------------------------------------------------------------------------
// entry point
// ----------------------------------------------------------------------------
TestMemoryStream();
#endif // TEST_STREAMS
-#ifdef TEST_TEXTSTREAM
- TestTextInputStream();
-#endif // TEST_TEXTSTREAM
-
#ifdef TEST_TIMER
TestStopWatch();
TestTimer();
#endif // TEST_TIMER
#ifdef TEST_DATETIME
- #if TEST_ALL
- TestTimeStatic();
- TestTimeRange();
- TestTimeZones();
- TestTimeDST();
- TestTimeHolidays();
- TestTimeSpanFormat();
- TestTimeMS();
-
- TestTimeZoneBug();
- #endif
-
#if TEST_INTERACTIVE
TestDateTimeInteractive();
#endif
TestFSVolume();
#endif // TEST_VOLUME
-#ifdef TEST_WCHAR
- TestUtf8();
- TestEncodingConverter();
-#endif // TEST_WCHAR
-
-#ifdef TEST_ZIP
- TestZipStreamRead();
- TestZipFileSystem();
-#endif // TEST_ZIP
-
#if wxUSE_UNICODE
{
for ( int n = 0; n < argc; n++ )