1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        samples/console/console.cpp 
   3 // Purpose:     a sample console (as opposed to GUI) progam using wxWindows 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  24 #include "wx/string.h" 
  29 // without this pragma, the stupid compiler precompiles #defines below so that 
  30 // changing them doesn't "take place" later! 
  35 // ---------------------------------------------------------------------------- 
  36 // conditional compilation 
  37 // ---------------------------------------------------------------------------- 
  40    A note about all these conditional compilation macros: this file is used 
  41    both as a test suite for various non-GUI wxWindows classes and as a 
  42    scratchpad for quick tests. So there are two compilation modes: if you 
  43    define TEST_ALL all tests are run, otherwise you may enable the individual 
  44    tests individually in the "#else" branch below. 
  47 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single 
  48 // test, define it to 1 to do all tests. 
  58     #define TEST_DLLLOADER 
  65  //   #define TEST_FTP  --FIXME! (RN) 
  69     #define TEST_INFO_FUNCTIONS 
  80     #define TEST_SCOPEGUARD 
  82 //    #define TEST_SOCKETS  --FIXME! (RN) 
  84     #define TEST_TEXTSTREAM 
  88     // #define TEST_VCARD            -- don't enable this (VZ) 
  89 //    #define TEST_VOLUME   --FIXME! (RN) 
 101 // some tests are interactive, define this to run them 
 102 #ifdef TEST_INTERACTIVE 
 103     #undef TEST_INTERACTIVE 
 105     #define TEST_INTERACTIVE 1 
 107     #define TEST_INTERACTIVE 0 
 110 // ---------------------------------------------------------------------------- 
 111 // test class for container objects 
 112 // ---------------------------------------------------------------------------- 
 114 #if defined(TEST_LIST) 
 116 class Bar 
// Foo is already taken in the hash test 
 119     Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; } 
 120     Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; } 
 121    ~Bar() { ms_bars
--; } 
 123    static size_t GetNumber() { return ms_bars
; } 
 125    const wxChar 
*GetName() const { return m_name
; } 
 130    static size_t ms_bars
; 
 133 size_t Bar::ms_bars 
= 0; 
 135 #endif // defined(TEST_LIST) 
 137 // ============================================================================ 
 139 // ============================================================================ 
 141 // ---------------------------------------------------------------------------- 
 143 // ---------------------------------------------------------------------------- 
 145 #if defined(TEST_SOCKETS) 
 147 // replace TABs with \t and CRs with \n 
 148 static wxString 
MakePrintable(const wxChar 
*s
) 
 151     (void)str
.Replace(_T("\t"), _T("\\t")); 
 152     (void)str
.Replace(_T("\n"), _T("\\n")); 
 153     (void)str
.Replace(_T("\r"), _T("\\r")); 
 158 #endif // MakePrintable() is used 
 160 // ---------------------------------------------------------------------------- 
 161 // wxFontMapper::CharsetToEncoding 
 162 // ---------------------------------------------------------------------------- 
 166 #include "wx/fontmap.h" 
 168 static void TestCharset() 
 170     static const wxChar 
*charsets
[] = 
 172         // some vali charsets 
 181         // and now some bogus ones 
 188     for ( size_t n 
= 0; n 
< WXSIZEOF(charsets
); n
++ ) 
 190         wxFontEncoding enc 
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]); 
 191         wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"), 
 193                  wxFontMapper::Get()->GetEncodingName(enc
).c_str(), 
 194                  wxFontMapper::Get()->GetEncodingDescription(enc
).c_str()); 
 198 #endif // TEST_CHARSET 
 200 // ---------------------------------------------------------------------------- 
 202 // ---------------------------------------------------------------------------- 
 206 #include "wx/cmdline.h" 
 207 #include "wx/datetime.h" 
 209 #if wxUSE_CMDLINE_PARSER 
 211 static void ShowCmdLine(const wxCmdLineParser
& parser
) 
 213     wxString s 
= _T("Input files: "); 
 215     size_t count 
= parser
.GetParamCount(); 
 216     for ( size_t param 
= 0; param 
< count
; param
++ ) 
 218         s 
<< parser
.GetParam(param
) << ' '; 
 222       << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n' 
 223       << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n'; 
 228     if ( parser
.Found(_T("o"), &strVal
) ) 
 229         s 
<< _T("Output file:\t") << strVal 
<< '\n'; 
 230     if ( parser
.Found(_T("i"), &strVal
) ) 
 231         s 
<< _T("Input dir:\t") << strVal 
<< '\n'; 
 232     if ( parser
.Found(_T("s"), &lVal
) ) 
 233         s 
<< _T("Size:\t") << lVal 
<< '\n'; 
 234     if ( parser
.Found(_T("d"), &dt
) ) 
 235         s 
<< _T("Date:\t") << dt
.FormatISODate() << '\n'; 
 236     if ( parser
.Found(_T("project_name"), &strVal
) ) 
 237         s 
<< _T("Project:\t") << strVal 
<< '\n'; 
 242 #endif // wxUSE_CMDLINE_PARSER 
 244 static void TestCmdLineConvert() 
 246     static const wxChar 
*cmdlines
[] = 
 249         _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""), 
 250         _T("literal \\\" and \"\""), 
 253     for ( size_t n 
= 0; n 
< WXSIZEOF(cmdlines
); n
++ ) 
 255         const wxChar 
*cmdline 
= cmdlines
[n
]; 
 256         wxPrintf(_T("Parsing: %s\n"), cmdline
); 
 257         wxArrayString args 
= wxCmdLineParser::ConvertStringToArgs(cmdline
); 
 259         size_t count 
= args
.GetCount(); 
 260         wxPrintf(_T("\targc = %u\n"), count
); 
 261         for ( size_t arg 
= 0; arg 
< count
; arg
++ ) 
 263             wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str()); 
 268 #endif // TEST_CMDLINE 
 270 // ---------------------------------------------------------------------------- 
 272 // ---------------------------------------------------------------------------- 
 279     static const wxChar 
*ROOTDIR 
= _T("/"); 
 280     static const wxChar 
*TESTDIR 
= _T("/usr/local/share"); 
 281 #elif defined(__WXMSW__) 
 282     static const wxChar 
*ROOTDIR 
= _T("c:\\"); 
 283     static const wxChar 
*TESTDIR 
= _T("d:\\"); 
 285     #error "don't know where the root directory is" 
 288 static void TestDirEnumHelper(wxDir
& dir
, 
 289                               int flags 
= wxDIR_DEFAULT
, 
 290                               const wxString
& filespec 
= wxEmptyString
) 
 294     if ( !dir
.IsOpened() ) 
 297     bool cont 
= dir
.GetFirst(&filename
, filespec
, flags
); 
 300         wxPrintf(_T("\t%s\n"), filename
.c_str()); 
 302         cont 
= dir
.GetNext(&filename
); 
 305     wxPuts(wxEmptyString
); 
 308 static void TestDirEnum() 
 310     wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***")); 
 312     wxString cwd 
= wxGetCwd(); 
 313     if ( !wxDir::Exists(cwd
) ) 
 315         wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str()); 
 320     if ( !dir
.IsOpened() ) 
 322         wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str()); 
 326     wxPuts(_T("Enumerating everything in current directory:")); 
 327     TestDirEnumHelper(dir
); 
 329     wxPuts(_T("Enumerating really everything in current directory:")); 
 330     TestDirEnumHelper(dir
, wxDIR_DEFAULT 
| wxDIR_DOTDOT
); 
 332     wxPuts(_T("Enumerating object files in current directory:")); 
 333     TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*")); 
 335     wxPuts(_T("Enumerating directories in current directory:")); 
 336     TestDirEnumHelper(dir
, wxDIR_DIRS
); 
 338     wxPuts(_T("Enumerating files in current directory:")); 
 339     TestDirEnumHelper(dir
, wxDIR_FILES
); 
 341     wxPuts(_T("Enumerating files including hidden in current directory:")); 
 342     TestDirEnumHelper(dir
, wxDIR_FILES 
| wxDIR_HIDDEN
); 
 346     wxPuts(_T("Enumerating everything in root directory:")); 
 347     TestDirEnumHelper(dir
, wxDIR_DEFAULT
); 
 349     wxPuts(_T("Enumerating directories in root directory:")); 
 350     TestDirEnumHelper(dir
, wxDIR_DIRS
); 
 352     wxPuts(_T("Enumerating files in root directory:")); 
 353     TestDirEnumHelper(dir
, wxDIR_FILES
); 
 355     wxPuts(_T("Enumerating files including hidden in root directory:")); 
 356     TestDirEnumHelper(dir
, wxDIR_FILES 
| wxDIR_HIDDEN
); 
 358     wxPuts(_T("Enumerating files in non existing directory:")); 
 359     wxDir 
dirNo(_T("nosuchdir")); 
 360     TestDirEnumHelper(dirNo
); 
 363 class DirPrintTraverser 
: public wxDirTraverser
 
 366     virtual wxDirTraverseResult 
OnFile(const wxString
& WXUNUSED(filename
)) 
 368         return wxDIR_CONTINUE
; 
 371     virtual wxDirTraverseResult 
OnDir(const wxString
& dirname
) 
 373         wxString path
, name
, ext
; 
 374         wxSplitPath(dirname
, &path
, &name
, &ext
); 
 377             name 
<< _T('.') << ext
; 
 380         for ( const wxChar 
*p 
= path
.c_str(); *p
; p
++ ) 
 382             if ( wxIsPathSeparator(*p
) ) 
 386         wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str()); 
 388         return wxDIR_CONTINUE
; 
 392 static void TestDirTraverse() 
 394     wxPuts(_T("*** Testing wxDir::Traverse() ***")); 
 398     size_t n 
= wxDir::GetAllFiles(TESTDIR
, &files
); 
 399     wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
); 
 402         wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str()); 
 403         wxPrintf(_T(" last one is '%s'\n"), files
[n 
- 1].c_str()); 
 406     // enum again with custom traverser 
 407     wxPuts(_T("Now enumerating directories:")); 
 409     DirPrintTraverser traverser
; 
 410     dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS 
| wxDIR_HIDDEN
); 
 413 static void TestDirExists() 
 415     wxPuts(_T("*** Testing wxDir::Exists() ***")); 
 417     static const wxChar 
*dirnames
[] = 
 420 #if defined(__WXMSW__) 
 423         _T("\\\\share\\file"), 
 427         _T("c:\\autoexec.bat"), 
 428 #elif defined(__UNIX__) 
 437     for ( size_t n 
= 0; n 
< WXSIZEOF(dirnames
); n
++ ) 
 439         wxPrintf(_T("%-40s: %s\n"), 
 441                  wxDir::Exists(dirnames
[n
]) ? _T("exists") 
 442                                             : _T("doesn't exist")); 
 448 // ---------------------------------------------------------------------------- 
 450 // ---------------------------------------------------------------------------- 
 452 #ifdef TEST_DLLLOADER 
 454 #include "wx/dynlib.h" 
 456 static void TestDllLoad() 
 458 #if defined(__WXMSW__) 
 459     static const wxChar 
*LIB_NAME 
= _T("kernel32.dll"); 
 460     static const wxChar 
*FUNC_NAME 
= _T("lstrlenA"); 
 461 #elif defined(__UNIX__) 
 462     // weird: using just libc.so does *not* work! 
 463     static const wxChar 
*LIB_NAME 
= _T("/lib/libc-2.0.7.so"); 
 464     static const wxChar 
*FUNC_NAME 
= _T("strlen"); 
 466     #error "don't know how to test wxDllLoader on this platform" 
 469     wxPuts(_T("*** testing wxDllLoader ***\n")); 
 471     wxDynamicLibrary 
lib(LIB_NAME
); 
 472     if ( !lib
.IsLoaded() ) 
 474         wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
); 
 478         typedef int (*wxStrlenType
)(const char *); 
 479         wxStrlenType pfnStrlen 
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
); 
 482             wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"), 
 483                      FUNC_NAME
, LIB_NAME
); 
 487             if ( pfnStrlen("foo") != 3 ) 
 489                 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n")); 
 493                 wxPuts(_T("... ok")); 
 499 #endif // TEST_DLLLOADER 
 501 // ---------------------------------------------------------------------------- 
 503 // ---------------------------------------------------------------------------- 
 507 #include "wx/utils.h" 
 509 static wxString 
MyGetEnv(const wxString
& var
) 
 512     if ( !wxGetEnv(var
, &val
) ) 
 515         val 
= wxString(_T('\'')) + val 
+ _T('\''); 
 520 static void TestEnvironment() 
 522     const wxChar 
*var 
= _T("wxTestVar"); 
 524     wxPuts(_T("*** testing environment access functions ***")); 
 526     wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str()); 
 527     wxSetEnv(var
, _T("value for wxTestVar")); 
 528     wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 529     wxSetEnv(var
, _T("another value")); 
 530     wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 532     wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 533     wxPrintf(_T("PATH = %s\n"),  MyGetEnv(_T("PATH")).c_str()); 
 536 #endif // TEST_ENVIRON 
 538 // ---------------------------------------------------------------------------- 
 540 // ---------------------------------------------------------------------------- 
 544 #include "wx/utils.h" 
 546 static void TestExecute() 
 548     wxPuts(_T("*** testing wxExecute ***")); 
 551     #define COMMAND "cat -n ../../Makefile" // "echo hi" 
 552     #define SHELL_COMMAND "echo hi from shell" 
 553     #define REDIRECT_COMMAND COMMAND // "date" 
 554 #elif defined(__WXMSW__) 
 555     #define COMMAND "command.com /c echo hi" 
 556     #define SHELL_COMMAND "echo hi" 
 557     #define REDIRECT_COMMAND COMMAND 
 559     #error "no command to exec" 
 562     wxPrintf(_T("Testing wxShell: ")); 
 564     if ( wxShell(_T(SHELL_COMMAND
)) ) 
 567         wxPuts(_T("ERROR.")); 
 569     wxPrintf(_T("Testing wxExecute: ")); 
 571     if ( wxExecute(_T(COMMAND
), true /* sync */) == 0 ) 
 574         wxPuts(_T("ERROR.")); 
 576 #if 0 // no, it doesn't work (yet?) 
 577     wxPrintf(_T("Testing async wxExecute: ")); 
 579     if ( wxExecute(COMMAND
) != 0 ) 
 580         wxPuts(_T("Ok (command launched).")); 
 582         wxPuts(_T("ERROR.")); 
 585     wxPrintf(_T("Testing wxExecute with redirection:\n")); 
 586     wxArrayString output
; 
 587     if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 ) 
 589         wxPuts(_T("ERROR.")); 
 593         size_t count 
= output
.GetCount(); 
 594         for ( size_t n 
= 0; n 
< count
; n
++ ) 
 596             wxPrintf(_T("\t%s\n"), output
[n
].c_str()); 
 603 #endif // TEST_EXECUTE 
 605 // ---------------------------------------------------------------------------- 
 607 // ---------------------------------------------------------------------------- 
 612 #include "wx/ffile.h" 
 613 #include "wx/textfile.h" 
 615 static void TestFileRead() 
 617     wxPuts(_T("*** wxFile read test ***")); 
 619     wxFile 
file(_T("testdata.fc")); 
 620     if ( file
.IsOpened() ) 
 622         wxPrintf(_T("File length: %lu\n"), file
.Length()); 
 624         wxPuts(_T("File dump:\n----------")); 
 626         static const off_t len 
= 1024; 
 630             off_t nRead 
= file
.Read(buf
, len
); 
 631             if ( nRead 
== wxInvalidOffset 
) 
 633                 wxPrintf(_T("Failed to read the file.")); 
 637             fwrite(buf
, nRead
, 1, stdout
); 
 643         wxPuts(_T("----------")); 
 647         wxPrintf(_T("ERROR: can't open test file.\n")); 
 650     wxPuts(wxEmptyString
); 
 653 static void TestTextFileRead() 
 655     wxPuts(_T("*** wxTextFile read test ***")); 
 657     wxTextFile 
file(_T("testdata.fc")); 
 660         wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount()); 
 661         wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str()); 
 665         wxPuts(_T("\nDumping the entire file:")); 
 666         for ( s 
= file
.GetFirstLine(); !file
.Eof(); s 
= file
.GetNextLine() ) 
 668             wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 670         wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 672         wxPuts(_T("\nAnd now backwards:")); 
 673         for ( s 
= file
.GetLastLine(); 
 674               file
.GetCurrentLine() != 0; 
 675               s 
= file
.GetPrevLine() ) 
 677             wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 679         wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 683         wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName()); 
 686     wxPuts(wxEmptyString
); 
 689 static void TestFileCopy() 
 691     wxPuts(_T("*** Testing wxCopyFile ***")); 
 693     static const wxChar 
*filename1 
= _T("testdata.fc"); 
 694     static const wxChar 
*filename2 
= _T("test2"); 
 695     if ( !wxCopyFile(filename1
, filename2
) ) 
 697         wxPuts(_T("ERROR: failed to copy file")); 
 701         wxFFile 
f1(filename1
, _T("rb")), 
 702                 f2(filename2
, _T("rb")); 
 704         if ( !f1
.IsOpened() || !f2
.IsOpened() ) 
 706             wxPuts(_T("ERROR: failed to open file(s)")); 
 711             if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) ) 
 713                 wxPuts(_T("ERROR: failed to read file(s)")); 
 717                 if ( (s1
.length() != s2
.length()) || 
 718                      (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) ) 
 720                     wxPuts(_T("ERROR: copy error!")); 
 724                     wxPuts(_T("File was copied ok.")); 
 730     if ( !wxRemoveFile(filename2
) ) 
 732         wxPuts(_T("ERROR: failed to remove the file")); 
 735     wxPuts(wxEmptyString
); 
 740 // ---------------------------------------------------------------------------- 
 742 // ---------------------------------------------------------------------------- 
 746 #include "wx/confbase.h" 
 747 #include "wx/fileconf.h" 
 749 static const struct FileConfTestData
 
 751     const wxChar 
*name
;      // value name 
 752     const wxChar 
*value
;     // the value from the file 
 755     { _T("value1"),                       _T("one") }, 
 756     { _T("value2"),                       _T("two") }, 
 757     { _T("novalue"),                      _T("default") }, 
 760 static void TestFileConfRead() 
 762     wxPuts(_T("*** testing wxFileConfig loading/reading ***")); 
 764     wxFileConfig 
fileconf(_T("test"), wxEmptyString
, 
 765                           _T("testdata.fc"), wxEmptyString
, 
 766                           wxCONFIG_USE_RELATIVE_PATH
); 
 768     // test simple reading 
 769     wxPuts(_T("\nReading config file:")); 
 770     wxString 
defValue(_T("default")), value
; 
 771     for ( size_t n 
= 0; n 
< WXSIZEOF(fcTestData
); n
++ ) 
 773         const FileConfTestData
& data 
= fcTestData
[n
]; 
 774         value 
= fileconf
.Read(data
.name
, defValue
); 
 775         wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str()); 
 776         if ( value 
== data
.value 
) 
 782             wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
); 
 786     // test enumerating the entries 
 787     wxPuts(_T("\nEnumerating all root entries:")); 
 790     bool cont 
= fileconf
.GetFirstEntry(name
, dummy
); 
 793         wxPrintf(_T("\t%s = %s\n"), 
 795                fileconf
.Read(name
.c_str(), _T("ERROR")).c_str()); 
 797         cont 
= fileconf
.GetNextEntry(name
, dummy
); 
 800     static const wxChar 
*testEntry 
= _T("TestEntry"); 
 801     wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: ")); 
 802     fileconf
.Write(testEntry
, _T("A value")); 
 803     fileconf
.DeleteEntry(testEntry
); 
 804     wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n")); 
 807 #endif // TEST_FILECONF 
 809 // ---------------------------------------------------------------------------- 
 811 // ---------------------------------------------------------------------------- 
 815 #include "wx/filename.h" 
 818 static void DumpFileName(const wxChar 
*desc
, const wxFileName
& fn
) 
 822     wxString full 
= fn
.GetFullPath(); 
 824     wxString vol
, path
, name
, ext
; 
 825     wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
); 
 827     wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"), 
 828              full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str()); 
 830     wxFileName::SplitPath(full
, &path
, &name
, &ext
); 
 831     wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"), 
 832              path
.c_str(), name
.c_str(), ext
.c_str()); 
 834     wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str()); 
 835     wxPrintf(_T("with volume: \t'%s'\n"), 
 836              fn
.GetPath(wxPATH_GET_VOLUME
).c_str()); 
 837     wxPrintf(_T("with separator:\t'%s'\n"), 
 838              fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str()); 
 839     wxPrintf(_T("with both:   \t'%s'\n"), 
 840              fn
.GetPath(wxPATH_GET_SEPARATOR 
| wxPATH_GET_VOLUME
).c_str()); 
 842     wxPuts(_T("The directories in the path are:")); 
 843     wxArrayString dirs 
= fn
.GetDirs(); 
 844     size_t count 
= dirs
.GetCount(); 
 845     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 847         wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str()); 
 852 static struct FileNameInfo
 
 854     const wxChar 
*fullname
; 
 855     const wxChar 
*volume
; 
 864     { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX 
}, 
 865     { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX 
}, 
 866     { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX 
}, 
 867     { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX 
}, 
 868     { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX 
}, 
 869     { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX 
}, 
 870     { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX 
}, 
 871     { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX 
}, 
 872     { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX 
}, 
 874     // Windows file names 
 875     { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS 
}, 
 876     { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS 
}, 
 877     { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS 
}, 
 878     { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS 
}, 
 879     { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS 
}, 
 880     { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS 
}, 
 881     { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS 
}, 
 883     // wxFileName support for Mac file names is broken currently 
 886     { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC 
}, 
 887     { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC 
}, 
 888     { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC 
}, 
 889     { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC 
}, 
 890     { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC 
}, 
 891     { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC 
}, 
 895     { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS 
}, 
 896     { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS 
}, 
 899 static void TestFileNameConstruction() 
 901     wxPuts(_T("*** testing wxFileName construction ***")); 
 903     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
 905         const FileNameInfo
& fni 
= filenames
[n
]; 
 907         wxFileName 
fn(fni
.fullname
, fni
.format
); 
 909         wxString fullname 
= fn
.GetFullPath(fni
.format
); 
 910         if ( fullname 
!= fni
.fullname 
) 
 912             wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni
.fullname
); 
 915         bool isAbsolute 
= fn
.IsAbsolute(fni
.format
); 
 916         wxPrintf(_T("'%s' is %s (%s)\n\t"), 
 918                isAbsolute 
? "absolute" : "relative", 
 919                isAbsolute 
== fni
.isAbsolute 
? "ok" : "ERROR"); 
 921         if ( !fn
.Normalize(wxPATH_NORM_ALL
, wxEmptyString
, fni
.format
) ) 
 923             wxPuts(_T("ERROR (couldn't be normalized)")); 
 927             wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str()); 
 931     wxPuts(wxEmptyString
); 
 934 static void TestFileNameSplit() 
 936     wxPuts(_T("*** testing wxFileName splitting ***")); 
 938     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
 940         const FileNameInfo
& fni 
= filenames
[n
]; 
 941         wxString volume
, path
, name
, ext
; 
 942         wxFileName::SplitPath(fni
.fullname
, 
 943                               &volume
, &path
, &name
, &ext
, fni
.format
); 
 945         wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"), 
 947                volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str()); 
 949         if ( volume 
!= fni
.volume 
) 
 950             wxPrintf(_T(" (ERROR: volume = '%s')"), fni
.volume
); 
 951         if ( path 
!= fni
.path 
) 
 952             wxPrintf(_T(" (ERROR: path = '%s')"), fni
.path
); 
 953         if ( name 
!= fni
.name 
) 
 954             wxPrintf(_T(" (ERROR: name = '%s')"), fni
.name
); 
 955         if ( ext 
!= fni
.ext 
) 
 956             wxPrintf(_T(" (ERROR: ext = '%s')"), fni
.ext
); 
 958         wxPuts(wxEmptyString
); 
 962 static void TestFileNameTemp() 
 964     wxPuts(_T("*** testing wxFileName temp file creation ***")); 
 966     static const wxChar 
*tmpprefixes
[] = 
 974         _T("/tmp/foo/bar"), // this one must be an error 
 978     for ( size_t n 
= 0; n 
< WXSIZEOF(tmpprefixes
); n
++ ) 
 980         wxString path 
= wxFileName::CreateTempFileName(tmpprefixes
[n
]); 
 983             // "error" is not in upper case because it may be ok 
 984             wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]); 
 988             wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"), 
 989                    tmpprefixes
[n
], path
.c_str()); 
 991             if ( !wxRemoveFile(path
) ) 
 993                 wxLogWarning(_T("Failed to remove temp file '%s'"), 
1000 static void TestFileNameMakeRelative() 
1002     wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***")); 
1004     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
1006         const FileNameInfo
& fni 
= filenames
[n
]; 
1008         wxFileName 
fn(fni
.fullname
, fni
.format
); 
1010         // choose the base dir of the same format 
1012         switch ( fni
.format 
) 
1015                 base 
= _T("/usr/bin/"); 
1024                 // TODO: I don't know how this is supposed to work there 
1027             case wxPATH_NATIVE
: // make gcc happy 
1029                 wxFAIL_MSG( _T("unexpected path format") ); 
1032         wxPrintf(_T("'%s' relative to '%s': "), 
1033                fn
.GetFullPath(fni
.format
).c_str(), base
.c_str()); 
1035         if ( !fn
.MakeRelativeTo(base
, fni
.format
) ) 
1037             wxPuts(_T("unchanged")); 
1041             wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str()); 
1046 static void TestFileNameMakeAbsolute() 
1048     wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***")); 
1050     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
1052         const FileNameInfo
& fni 
= filenames
[n
]; 
1053         wxFileName 
fn(fni
.fullname
, fni
.format
); 
1055         wxPrintf(_T("'%s' absolutized: "), 
1056                fn
.GetFullPath(fni
.format
).c_str()); 
1058         wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str()); 
1061     wxPuts(wxEmptyString
); 
1064 static void TestFileNameDirManip() 
1066     // TODO: test AppendDir(), RemoveDir(), ... 
1069 static void TestFileNameComparison() 
1074 static void TestFileNameOperations() 
1079 static void TestFileNameCwd() 
1084 #endif // TEST_FILENAME 
1086 // ---------------------------------------------------------------------------- 
1087 // wxFileName time functions 
1088 // ---------------------------------------------------------------------------- 
1090 #ifdef TEST_FILETIME 
1092 #include <wx/filename.h> 
1093 #include <wx/datetime.h> 
1095 static void TestFileGetTimes() 
1097     wxFileName 
fn(_T("testdata.fc")); 
1099     wxDateTime dtAccess
, dtMod
, dtCreate
; 
1100     if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) ) 
1102         wxPrintf(_T("ERROR: GetTimes() failed.\n")); 
1106         static const wxChar 
*fmt 
= _T("%Y-%b-%d %H:%M:%S"); 
1108         wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str()); 
1109         wxPrintf(_T("Creation:    \t%s\n"), dtCreate
.Format(fmt
).c_str()); 
1110         wxPrintf(_T("Last read:   \t%s\n"), dtAccess
.Format(fmt
).c_str()); 
1111         wxPrintf(_T("Last write:  \t%s\n"), dtMod
.Format(fmt
).c_str()); 
1116 static void TestFileSetTimes() 
1118     wxFileName 
fn(_T("testdata.fc")); 
1122         wxPrintf(_T("ERROR: Touch() failed.\n")); 
1127 #endif // TEST_FILETIME 
1129 // ---------------------------------------------------------------------------- 
1131 // ---------------------------------------------------------------------------- 
1135 #include "wx/hash.h" 
1139     Foo(int n_
) { n 
= n_
; count
++; } 
1144     static size_t count
; 
1147 size_t Foo::count 
= 0; 
1149 WX_DECLARE_LIST(Foo
, wxListFoos
); 
1150 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
); 
1152 #include "wx/listimpl.cpp" 
1154 WX_DEFINE_LIST(wxListFoos
); 
1156 #include "wx/timer.h" 
1158 static void TestHash() 
1160     wxPuts(_T("*** Testing wxHashTable ***\n")); 
1161     const int COUNT 
= 100; 
1168         wxHashTable 
hash(wxKEY_INTEGER
, 10), hash2(wxKEY_STRING
); 
1172         for ( i 
= 0; i 
< COUNT
; ++i 
) 
1173             hash
.Put(i
, &o 
+ i
); 
1176         wxHashTable::compatibility_iterator it 
= hash
.Next(); 
1186             wxPuts(_T("Error in wxHashTable::compatibility_iterator\n")); 
1188         for ( i 
= 99; i 
>= 0; --i 
) 
1189             if( hash
.Get(i
) != &o 
+ i 
) 
1190                 wxPuts(_T("Error in wxHashTable::Get/Put\n")); 
1192         for ( i 
= 0; i 
< COUNT
; ++i 
) 
1193             hash
.Put(i
, &o 
+ i 
+ 20); 
1195         for ( i 
= 99; i 
>= 0; --i 
) 
1196             if( hash
.Get(i
) != &o 
+ i
) 
1197                 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n")); 
1199         for ( i 
= 0; i 
< COUNT
/2; ++i 
) 
1200             if( hash
.Delete(i
) != &o 
+ i
) 
1201                 wxPuts(_T("Error in wxHashTable::Delete\n")); 
1203         for ( i 
= COUNT
/2; i 
< COUNT
; ++i 
) 
1204             if( hash
.Get(i
) != &o 
+ i
) 
1205                 wxPuts(_T("Error (3) in wxHashTable::Get/Put\n")); 
1207         for ( i 
= 0; i 
< COUNT
/2; ++i 
) 
1208             if( hash
.Get(i
) != &o 
+ i 
+ 20) 
1209                 wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n")); 
1211         for ( i 
= 0; i 
< COUNT
/2; ++i 
) 
1212             if( hash
.Delete(i
) != &o 
+ i 
+ 20) 
1213                 wxPuts(_T("Error (2) in wxHashTable::Delete\n")); 
1215         for ( i 
= 0; i 
< COUNT
/2; ++i 
) 
1216             if( hash
.Get(i
) != NULL
) 
1217                 wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n")); 
1219         hash2
.Put(_T("foo"), &o 
+ 1); 
1220         hash2
.Put(_T("bar"), &o 
+ 2); 
1221         hash2
.Put(_T("baz"), &o 
+ 3); 
1223         if (hash2
.Get(_T("moo")) != NULL
) 
1224             wxPuts(_T("Error in wxHashTable::Get\n")); 
1226         if (hash2
.Get(_T("bar")) != &o 
+ 2) 
1227             wxPuts(_T("Error in wxHashTable::Get/Put\n")); 
1229         hash2
.Put(_T("bar"), &o 
+ 0); 
1231         if (hash2
.Get(_T("bar")) != &o 
+ 2) 
1232             wxPuts(_T("Error (2) in wxHashTable::Get/Put\n")); 
1235     // and now some corner-case testing; 3 and 13 hash to the same bucket 
1237         wxHashTable 
hash(wxKEY_INTEGER
, 10); 
1240         hash
.Put(3, &dummy
); 
1243         if (hash
.Get(3) != NULL
) 
1244             wxPuts(_T("Corner case 1 failure\n")); 
1246         hash
.Put(3, &dummy
); 
1247         hash
.Put(13, &dummy
); 
1250         if (hash
.Get(3) != NULL
) 
1251             wxPuts(_T("Corner case 2 failure\n")); 
1255         if (hash
.Get(13) != NULL
) 
1256             wxPuts(_T("Corner case 3 failure\n")); 
1258         hash
.Put(3, &dummy
); 
1259         hash
.Put(13, &dummy
); 
1262         if (hash
.Get(13) != NULL
) 
1263             wxPuts(_T("Corner case 4 failure\n")); 
1267         if (hash
.Get(3) != NULL
) 
1268             wxPuts(_T("Corner case 5 failure\n")); 
1272         wxHashTable 
hash(wxKEY_INTEGER
, 10); 
1275         hash
.Put(3, 7, &dummy 
+ 7); 
1276         hash
.Put(4, 8, &dummy 
+ 8); 
1278         if (hash
.Get(7) != NULL
) wxPuts(_T("Key/Hash 1 failure\n")); 
1279         if (hash
.Get(3, 7) != &dummy 
+ 7) wxPuts(_T("Key/Hash 2 failure\n")); 
1280         if (hash
.Get(4) != NULL
) wxPuts(_T("Key/Hash 3 failure\n")); 
1281         if (hash
.Get(3) != NULL
) wxPuts(_T("Key/Hash 4 failure\n")); 
1282         if (hash
.Get(8) != NULL
) wxPuts(_T("Key/Hash 5 failure\n")); 
1283         if (hash
.Get(8, 4) != NULL
) wxPuts(_T("Key/Hash 6 failure\n")); 
1285         if (hash
.Delete(7) != NULL
) wxPuts(_T("Key/Hash 7 failure\n")); 
1286         if (hash
.Delete(3) != NULL
) wxPuts(_T("Key/Hash 8 failure\n")); 
1287         if (hash
.Delete(3, 7) != &dummy 
+ 7) wxPuts(_T("Key/Hash 8 failure\n")); 
1292         hash
.DeleteContents(true); 
1294         wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"), 
1295                hash
.GetCount(), Foo::count
); 
1297         static const int hashTestData
[] = 
1299             0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1, 
1303         for ( n 
= 0; n 
< WXSIZEOF(hashTestData
); n
++ ) 
1305             hash
.Put(hashTestData
[n
], n
, new Foo(n
)); 
1308         wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"), 
1309                hash
.GetCount(), Foo::count
); 
1311         wxPuts(_T("Hash access test:")); 
1312         for ( n 
= 0; n 
< WXSIZEOF(hashTestData
); n
++ ) 
1314             wxPrintf(_T("\tGetting element with key %d, value %d: "), 
1315                    hashTestData
[n
], n
); 
1316             Foo 
*foo 
= hash
.Get(hashTestData
[n
], n
); 
1319                 wxPrintf(_T("ERROR, not found.\n")); 
1323                 wxPrintf(_T("%d (%s)\n"), foo
->n
, 
1324                        (size_t)foo
->n 
== n 
? "ok" : "ERROR"); 
1328         wxPrintf(_T("\nTrying to get an element not in hash: ")); 
1330         if ( hash
.Get(1234) || hash
.Get(1, 0) ) 
1332             wxPuts(_T("ERROR: found!")); 
1336             wxPuts(_T("ok (not found)")); 
1339         Foo
* foo 
= hash
.Delete(0); 
1341         wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count
); 
1345         wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count
); 
1348     wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
); 
1349     wxPuts(_T("*** Testing wxHashTable finished ***\n")); 
1351     wxPrintf(_T("Time: %ld\n"), sw
.Time()); 
1356 // ---------------------------------------------------------------------------- 
1358 // ---------------------------------------------------------------------------- 
1362 #include "wx/hashmap.h" 
1364 // test compilation of basic map types 
1365 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap 
); 
1366 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap 
); 
1367 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1368                      myUnsignedHashMap 
); 
1369 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1371 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1373 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1375 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1379 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual, 
1380 //                      myStringHashMap ); 
1381 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
); 
1383 typedef myStringHashMap::iterator Itor
; 
1385 static void TestHashMap() 
1387     wxPuts(_T("*** Testing wxHashMap ***\n")); 
1388     myStringHashMap 
sh(0); // as small as possible 
1391     const size_t count 
= 10000; 
1393     // init with some data 
1394     for( i 
= 0; i 
< count
; ++i 
) 
1396         buf
.Printf(wxT("%d"), i 
); 
1397         sh
[buf
] = wxT("A") + buf 
+ wxT("C"); 
1400     // test that insertion worked 
1401     if( sh
.size() != count 
) 
1403         wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
); 
1406     for( i 
= 0; i 
< count
; ++i 
) 
1408         buf
.Printf(wxT("%d"), i 
); 
1409         if( sh
[buf
] != wxT("A") + buf 
+ wxT("C") ) 
1411             wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n")); 
1416     // check that iterators work 
1418     for( i 
= 0, it 
= sh
.begin(); it 
!= sh
.end(); ++it
, ++i 
) 
1422             wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n")); 
1426         if( it
->second 
!= sh
[it
->first
] ) 
1428             wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n")); 
1433     if( sh
.size() != i 
) 
1435         wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
); 
1438     // test copy ctor, assignment operator 
1439     myStringHashMap 
h1( sh 
), h2( 0 ); 
1442     for( i 
= 0, it 
= sh
.begin(); it 
!= sh
.end(); ++it
, ++i 
) 
1444         if( h1
[it
->first
] != it
->second 
) 
1446             wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str()); 
1449         if( h2
[it
->first
] != it
->second 
) 
1451             wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str()); 
1456     for( i 
= 0; i 
< count
; ++i 
) 
1458         buf
.Printf(wxT("%d"), i 
); 
1459         size_t sz 
= sh
.size(); 
1461         // test find() and erase(it) 
1464             it 
= sh
.find( buf 
); 
1465             if( it 
!= sh
.end() ) 
1469                 if( sh
.find( buf 
) != sh
.end() ) 
1471                     wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
); 
1475                 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
); 
1480             size_t c 
= sh
.erase( buf 
); 
1482                 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n")); 
1484             if( sh
.find( buf 
) != sh
.end() ) 
1486                 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
); 
1490         // count should decrease 
1491         if( sh
.size() != sz 
- 1 ) 
1493             wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n")); 
1497     wxPrintf(_T("*** Finished testing wxHashMap ***\n")); 
1500 #endif // TEST_HASHMAP 
1502 // ---------------------------------------------------------------------------- 
1504 // ---------------------------------------------------------------------------- 
1508 #include "wx/hashset.h" 
1510 // test compilation of basic map types 
1511 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet 
); 
1512 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet 
); 
1513 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
, 
1514                      myUnsignedHashSet 
); 
1515 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
, 
1517 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
, 
1519 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
, 
1521 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
, 
1523 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
, 
1535     unsigned long operator()(const MyStruct
& s
) const 
1536         { return m_dummy(s
.ptr
); } 
1537     MyHash
& operator=(const MyHash
&) { return *this; } 
1539     wxPointerHash m_dummy
; 
1545     bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const 
1546         { return s1
.ptr 
== s2
.ptr
; } 
1547     MyEqual
& operator=(const MyEqual
&) { return *this; } 
1550 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet 
); 
1552 typedef myTestHashSet5 wxStringHashSet
; 
1554 static void TestHashSet() 
1556     wxPrintf(_T("*** Testing wxHashSet ***\n")); 
1558     wxStringHashSet set1
; 
1560     set1
.insert( _T("abc") ); 
1561     set1
.insert( _T("bbc") ); 
1562     set1
.insert( _T("cbc") ); 
1563     set1
.insert( _T("abc") ); 
1565     if( set1
.size() != 3 ) 
1566         wxPrintf(_T("*** ERROR IN INSERT ***\n")); 
1572     tmp
.ptr 
= &dummy
; tmp
.str 
= _T("ABC"); 
1574     tmp
.ptr 
= &dummy 
+ 1; 
1576     tmp
.ptr 
= &dummy
; tmp
.str 
= _T("CDE"); 
1579     if( set2
.size() != 2 ) 
1580         wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n")); 
1582     mySet::iterator it 
= set2
.find( tmp 
); 
1584     if( it 
== set2
.end() ) 
1585         wxPrintf(_T("*** ERROR IN FIND - 1 ***\n")); 
1586     if( it
->ptr 
!= &dummy 
) 
1587         wxPrintf(_T("*** ERROR IN FIND - 2 ***\n")); 
1588     if( it
->str 
!= _T("ABC") ) 
1589         wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n")); 
1591     wxPrintf(_T("*** Finished testing wxHashSet ***\n")); 
1594 #endif // TEST_HASHSET 
1596 // ---------------------------------------------------------------------------- 
1598 // ---------------------------------------------------------------------------- 
1602 #include "wx/list.h" 
1604 WX_DECLARE_LIST(Bar
, wxListBars
); 
1605 #include "wx/listimpl.cpp" 
1606 WX_DEFINE_LIST(wxListBars
); 
1608 WX_DECLARE_LIST(int, wxListInt
); 
1609 WX_DEFINE_LIST(wxListInt
); 
1611 static void TestList() 
1613     wxPuts(_T("*** Testing wxList operations ***\n")); 
1619         for ( i 
= 0; i 
< 5; ++i 
) 
1620             list1
.Append(dummy 
+ i
); 
1622         if ( list1
.GetCount() != 5 ) 
1623             wxPuts(_T("Wrong number of items in list\n")); 
1625         if ( list1
.Item(3)->GetData() != dummy 
+ 3 ) 
1626             wxPuts(_T("Error in Item()\n")); 
1628         if ( !list1
.Find(dummy 
+ 4) ) 
1629             wxPuts(_T("Error in Find()\n")); 
1631         wxListInt::compatibility_iterator node 
= list1
.GetFirst(); 
1636             if ( node
->GetData() != dummy 
+ i 
) 
1637                 wxPuts(_T("Error in compatibility_iterator\n")); 
1638             node 
= node
->GetNext(); 
1642         if ( size_t(i
) != list1
.GetCount() ) 
1643             wxPuts(_T("Error in compatibility_iterator\n")); 
1645         list1
.Insert(dummy 
+ 0); 
1646         list1
.Insert(1, dummy 
+ 1); 
1647         list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy 
+ 2); 
1649         node 
= list1
.GetFirst(); 
1654             int* t 
= node
->GetData(); 
1655             if ( t 
!= dummy 
+ i 
) 
1656                 wxPuts(_T("Error in Insert\n")); 
1657             node 
= node
->GetNext(); 
1662     wxPuts(_T("*** Testing wxList operations finished ***\n")); 
1664     wxPuts(_T("*** Testing std::list operations ***\n")); 
1668         wxListInt::iterator it
, en
; 
1669         wxListInt::reverse_iterator rit
, ren
; 
1671         for ( i 
= 0; i 
< 5; ++i 
) 
1672             list1
.push_back(i 
+ &i
); 
1674         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 0; 
1675               it 
!= en
; ++it
, ++i 
) 
1676             if ( *it 
!= i 
+ &i 
) 
1677                 wxPuts(_T("Error in iterator\n")); 
1679         for ( rit 
= list1
.rbegin(), ren 
= list1
.rend(), i 
= 4; 
1680               rit 
!= ren
; ++rit
, --i 
) 
1681             if ( *rit 
!= i 
+ &i 
) 
1682                 wxPuts(_T("Error in reverse_iterator\n")); 
1684         if ( *list1
.rbegin() != *--list1
.end() || 
1685              *list1
.begin() != *--list1
.rend() ) 
1686             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
1687         if ( *list1
.begin() != *--++list1
.begin() || 
1688              *list1
.rbegin() != *--++list1
.rbegin() ) 
1689             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
1691         if ( list1
.front() != &i 
|| list1
.back() != &i 
+ 4 ) 
1692             wxPuts(_T("Error in front()/back()\n")); 
1694         list1
.erase(list1
.begin()); 
1695         list1
.erase(--list1
.end()); 
1697         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 1; 
1698               it 
!= en
; ++it
, ++i 
) 
1699             if ( *it 
!= i 
+ &i 
) 
1700                 wxPuts(_T("Error in erase()\n")); 
1703     wxPuts(_T("*** Testing std::list operations finished ***\n")); 
1706 static void TestListCtor() 
1708     wxPuts(_T("*** Testing wxList construction ***\n")); 
1712         list1
.Append(new Bar(_T("first"))); 
1713         list1
.Append(new Bar(_T("second"))); 
1715         wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"), 
1716                list1
.GetCount(), Bar::GetNumber()); 
1721         wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"), 
1722                list1
.GetCount(), list2
.GetCount(), Bar::GetNumber()); 
1725         list1
.DeleteContents(true); 
1727         WX_CLEAR_LIST(wxListBars
, list1
); 
1731     wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber()); 
1736 // ---------------------------------------------------------------------------- 
1738 // ---------------------------------------------------------------------------- 
1742 #include "wx/intl.h" 
1743 #include "wx/utils.h"   // for wxSetEnv 
1745 static wxLocale 
gs_localeDefault(wxLANGUAGE_ENGLISH
); 
1747 // find the name of the language from its value 
1748 static const wxChar 
*GetLangName(int lang
) 
1750     static const wxChar 
*languageNames
[] = 
1760         _T("ARABIC_ALGERIA"), 
1761         _T("ARABIC_BAHRAIN"), 
1764         _T("ARABIC_JORDAN"), 
1765         _T("ARABIC_KUWAIT"), 
1766         _T("ARABIC_LEBANON"), 
1768         _T("ARABIC_MOROCCO"), 
1771         _T("ARABIC_SAUDI_ARABIA"), 
1774         _T("ARABIC_TUNISIA"), 
1781         _T("AZERI_CYRILLIC"), 
1796         _T("CHINESE_SIMPLIFIED"), 
1797         _T("CHINESE_TRADITIONAL"), 
1798         _T("CHINESE_HONGKONG"), 
1799         _T("CHINESE_MACAU"), 
1800         _T("CHINESE_SINGAPORE"), 
1801         _T("CHINESE_TAIWAN"), 
1807         _T("DUTCH_BELGIAN"), 
1811         _T("ENGLISH_AUSTRALIA"), 
1812         _T("ENGLISH_BELIZE"), 
1813         _T("ENGLISH_BOTSWANA"), 
1814         _T("ENGLISH_CANADA"), 
1815         _T("ENGLISH_CARIBBEAN"), 
1816         _T("ENGLISH_DENMARK"), 
1818         _T("ENGLISH_JAMAICA"), 
1819         _T("ENGLISH_NEW_ZEALAND"), 
1820         _T("ENGLISH_PHILIPPINES"), 
1821         _T("ENGLISH_SOUTH_AFRICA"), 
1822         _T("ENGLISH_TRINIDAD"), 
1823         _T("ENGLISH_ZIMBABWE"), 
1831         _T("FRENCH_BELGIAN"), 
1832         _T("FRENCH_CANADIAN"), 
1833         _T("FRENCH_LUXEMBOURG"), 
1834         _T("FRENCH_MONACO"), 
1840         _T("GERMAN_AUSTRIAN"), 
1841         _T("GERMAN_BELGIUM"), 
1842         _T("GERMAN_LIECHTENSTEIN"), 
1843         _T("GERMAN_LUXEMBOURG"), 
1861         _T("ITALIAN_SWISS"), 
1866         _T("KASHMIRI_INDIA"), 
1884         _T("MALAY_BRUNEI_DARUSSALAM"), 
1885         _T("MALAY_MALAYSIA"), 
1895         _T("NORWEGIAN_BOKMAL"), 
1896         _T("NORWEGIAN_NYNORSK"), 
1903         _T("PORTUGUESE_BRAZILIAN"), 
1906         _T("RHAETO_ROMANCE"), 
1909         _T("RUSSIAN_UKRAINE"), 
1915         _T("SERBIAN_CYRILLIC"), 
1916         _T("SERBIAN_LATIN"), 
1917         _T("SERBO_CROATIAN"), 
1928         _T("SPANISH_ARGENTINA"), 
1929         _T("SPANISH_BOLIVIA"), 
1930         _T("SPANISH_CHILE"), 
1931         _T("SPANISH_COLOMBIA"), 
1932         _T("SPANISH_COSTA_RICA"), 
1933         _T("SPANISH_DOMINICAN_REPUBLIC"), 
1934         _T("SPANISH_ECUADOR"), 
1935         _T("SPANISH_EL_SALVADOR"), 
1936         _T("SPANISH_GUATEMALA"), 
1937         _T("SPANISH_HONDURAS"), 
1938         _T("SPANISH_MEXICAN"), 
1939         _T("SPANISH_MODERN"), 
1940         _T("SPANISH_NICARAGUA"), 
1941         _T("SPANISH_PANAMA"), 
1942         _T("SPANISH_PARAGUAY"), 
1944         _T("SPANISH_PUERTO_RICO"), 
1945         _T("SPANISH_URUGUAY"), 
1947         _T("SPANISH_VENEZUELA"), 
1951         _T("SWEDISH_FINLAND"), 
1969         _T("URDU_PAKISTAN"), 
1971         _T("UZBEK_CYRILLIC"), 
1984     if ( (size_t)lang 
< WXSIZEOF(languageNames
) ) 
1985         return languageNames
[lang
]; 
1987         return _T("INVALID"); 
1990 static void TestDefaultLang() 
1992     wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***")); 
1994     static const wxChar 
*langStrings
[] = 
1996         NULL
,               // system default 
2003         _T("de_DE.iso88591"), 
2005         _T("?"),            // invalid lang spec 
2006         _T("klingonese"),   // I bet on some systems it does exist... 
2009     wxPrintf(_T("The default system encoding is %s (%d)\n"), 
2010              wxLocale::GetSystemEncodingName().c_str(), 
2011              wxLocale::GetSystemEncoding()); 
2013     for ( size_t n 
= 0; n 
< WXSIZEOF(langStrings
); n
++ ) 
2015         const wxChar 
*langStr 
= langStrings
[n
]; 
2018             // FIXME: this doesn't do anything at all under Windows, we need 
2019             //        to create a new wxLocale! 
2020             wxSetEnv(_T("LC_ALL"), langStr
); 
2023         int lang 
= gs_localeDefault
.GetSystemLanguage(); 
2024         wxPrintf(_T("Locale for '%s' is %s.\n"), 
2025                  langStr 
? langStr 
: _T("system default"), GetLangName(lang
)); 
2029 #endif // TEST_LOCALE 
2031 // ---------------------------------------------------------------------------- 
2033 // ---------------------------------------------------------------------------- 
2037 #include "wx/mimetype.h" 
2039 static void TestMimeEnum() 
2041     wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n")); 
2043     wxArrayString mimetypes
; 
2045     size_t count 
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
); 
2047     wxPrintf(_T("*** All %u known filetypes: ***\n"), count
); 
2052     for ( size_t n 
= 0; n 
< count
; n
++ ) 
2054         wxFileType 
*filetype 
= 
2055             wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]); 
2058             wxPrintf(_T("nothing known about the filetype '%s'!\n"), 
2059                    mimetypes
[n
].c_str()); 
2063         filetype
->GetDescription(&desc
); 
2064         filetype
->GetExtensions(exts
); 
2066         filetype
->GetIcon(NULL
); 
2069         for ( size_t e 
= 0; e 
< exts
.GetCount(); e
++ ) 
2072                 extsAll 
<< _T(", "); 
2076         wxPrintf(_T("\t%s: %s (%s)\n"), 
2077                mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str()); 
2080     wxPuts(wxEmptyString
); 
2083 static void TestMimeOverride() 
2085     wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n")); 
2087     static const wxChar 
*mailcap 
= _T("/tmp/mailcap"); 
2088     static const wxChar 
*mimetypes 
= _T("/tmp/mime.types"); 
2090     if ( wxFile::Exists(mailcap
) ) 
2091         wxPrintf(_T("Loading mailcap from '%s': %s\n"), 
2093                  wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR")); 
2095         wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), 
2098     if ( wxFile::Exists(mimetypes
) ) 
2099         wxPrintf(_T("Loading mime.types from '%s': %s\n"), 
2101                  wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR")); 
2103         wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), 
2106     wxPuts(wxEmptyString
); 
2109 static void TestMimeFilename() 
2111     wxPuts(_T("*** Testing MIME type from filename query ***\n")); 
2113     static const wxChar 
*filenames
[] = 
2121     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
2123         const wxString fname 
= filenames
[n
]; 
2124         wxString ext 
= fname
.AfterLast(_T('.')); 
2125         wxFileType 
*ft 
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
); 
2128             wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str()); 
2133             if ( !ft
->GetDescription(&desc
) ) 
2134                 desc 
= _T("<no description>"); 
2137             if ( !ft
->GetOpenCommand(&cmd
, 
2138                                      wxFileType::MessageParameters(fname
, wxEmptyString
)) ) 
2139                 cmd 
= _T("<no command available>"); 
2141                 cmd 
= wxString(_T('"')) + cmd 
+ _T('"'); 
2143             wxPrintf(_T("To open %s (%s) do %s.\n"), 
2144                      fname
.c_str(), desc
.c_str(), cmd
.c_str()); 
2150     wxPuts(wxEmptyString
); 
2153 static void TestMimeAssociate() 
2155     wxPuts(_T("*** Testing creation of filetype association ***\n")); 
2157     wxFileTypeInfo 
ftInfo( 
2158                             _T("application/x-xyz"), 
2159                             _T("xyzview '%s'"), // open cmd 
2160                             _T(""),             // print cmd 
2161                             _T("XYZ File"),     // description 
2162                             _T(".xyz"),         // extensions 
2163                             NULL                
// end of extensions 
2165     ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only 
2167     wxFileType 
*ft 
= wxTheMimeTypesManager
->Associate(ftInfo
); 
2170         wxPuts(_T("ERROR: failed to create association!")); 
2174         // TODO: read it back 
2178     wxPuts(wxEmptyString
); 
2183 // ---------------------------------------------------------------------------- 
2184 // misc information functions 
2185 // ---------------------------------------------------------------------------- 
2187 #ifdef TEST_INFO_FUNCTIONS 
2189 #include "wx/utils.h" 
2191 static void TestDiskInfo() 
2193     wxPuts(_T("*** Testing wxGetDiskSpace() ***")); 
2197         wxChar pathname
[128]; 
2198         wxPrintf(_T("\nEnter a directory name: ")); 
2199         if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) ) 
2202         // kill the last '\n' 
2203         pathname
[wxStrlen(pathname
) - 1] = 0; 
2205         wxLongLong total
, free
; 
2206         if ( !wxGetDiskSpace(pathname
, &total
, &free
) ) 
2208             wxPuts(_T("ERROR: wxGetDiskSpace failed.")); 
2212             wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"), 
2213                     (total 
/ 1024).ToString().c_str(), 
2214                     (free 
/ 1024).ToString().c_str(), 
2220 static void TestOsInfo() 
2222     wxPuts(_T("*** Testing OS info functions ***\n")); 
2225     wxGetOsVersion(&major
, &minor
); 
2226     wxPrintf(_T("Running under: %s, version %d.%d\n"), 
2227             wxGetOsDescription().c_str(), major
, minor
); 
2229     wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory()); 
2231     wxPrintf(_T("Host name is %s (%s).\n"), 
2232            wxGetHostName().c_str(), wxGetFullHostName().c_str()); 
2234     wxPuts(wxEmptyString
); 
2237 static void TestUserInfo() 
2239     wxPuts(_T("*** Testing user info functions ***\n")); 
2241     wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str()); 
2242     wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str()); 
2243     wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); 
2244     wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str()); 
2246     wxPuts(wxEmptyString
); 
2249 #endif // TEST_INFO_FUNCTIONS 
2251 // ---------------------------------------------------------------------------- 
2253 // ---------------------------------------------------------------------------- 
2255 #ifdef TEST_PATHLIST 
2258     #define CMD_IN_PATH _T("ls") 
2260     #define CMD_IN_PATH _T("command.com") 
2263 static void TestPathList() 
2265     wxPuts(_T("*** Testing wxPathList ***\n")); 
2267     wxPathList pathlist
; 
2268     pathlist
.AddEnvList(_T("PATH")); 
2269     wxString path 
= pathlist
.FindValidPath(CMD_IN_PATH
); 
2272         wxPrintf(_T("ERROR: command not found in the path.\n")); 
2276         wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str()); 
2280 #endif // TEST_PATHLIST 
2282 // ---------------------------------------------------------------------------- 
2283 // regular expressions 
2284 // ---------------------------------------------------------------------------- 
2288 #include "wx/regex.h" 
2290 static void TestRegExInteractive() 
2292     wxPuts(_T("*** Testing RE interactively ***")); 
2296         wxChar pattern
[128]; 
2297         wxPrintf(_T("\nEnter a pattern: ")); 
2298         if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) ) 
2301         // kill the last '\n' 
2302         pattern
[wxStrlen(pattern
) - 1] = 0; 
2305         if ( !re
.Compile(pattern
) ) 
2313             wxPrintf(_T("Enter text to match: ")); 
2314             if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) ) 
2317             // kill the last '\n' 
2318             text
[wxStrlen(text
) - 1] = 0; 
2320             if ( !re
.Matches(text
) ) 
2322                 wxPrintf(_T("No match.\n")); 
2326                 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str()); 
2329                 for ( size_t n 
= 1; ; n
++ ) 
2331                     if ( !re
.GetMatch(&start
, &len
, n
) ) 
2336                     wxPrintf(_T("Subexpr %u matched '%s'\n"), 
2337                              n
, wxString(text 
+ start
, len
).c_str()); 
2344 #endif // TEST_REGEX 
2346 // ---------------------------------------------------------------------------- 
2348 // ---------------------------------------------------------------------------- 
2358 static void TestDbOpen() 
2366 // ---------------------------------------------------------------------------- 
2368 // ---------------------------------------------------------------------------- 
2371    NB: this stuff was taken from the glibc test suite and modified to build 
2372        in wxWindows: if I read the copyright below properly, this shouldn't 
2378 #ifdef wxTEST_PRINTF 
2379     // use our functions from wxchar.cpp 
2383     // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats 
2384     //     in the tests below 
2385     int wxPrintf( const wxChar 
*format
, ... ); 
2386     int wxSprintf( wxChar 
*str
, const wxChar 
*format
, ... ); 
2389 #include "wx/longlong.h" 
2393 static void rfg1 (void); 
2394 static void rfg2 (void); 
2398 fmtchk (const wxChar 
*fmt
) 
2400   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2401   (void) wxPrintf(fmt
, 0x12); 
2402   (void) wxPrintf(_T("'\n")); 
2406 fmtst1chk (const wxChar 
*fmt
) 
2408   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2409   (void) wxPrintf(fmt
, 4, 0x12); 
2410   (void) wxPrintf(_T("'\n")); 
2414 fmtst2chk (const wxChar 
*fmt
) 
2416   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2417   (void) wxPrintf(fmt
, 4, 4, 0x12); 
2418   (void) wxPrintf(_T("'\n")); 
2421 /* This page is covered by the following copyright: */ 
2423 /* (C) Copyright C E Chew 
2425  * Feel free to copy, use and distribute this software provided: 
2427  *        1. you do not pretend that you wrote it 
2428  *        2. you leave this copyright notice intact. 
2432  * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. 
2439 /* Formatted Output Test 
2441  * This exercises the output formatting code. 
2444 wxChar 
*PointerNull 
= NULL
; 
2451   wxChar 
*prefix 
= buf
; 
2454   wxPuts(_T("\nFormatted output test")); 
2455   wxPrintf(_T("prefix  6d      6o      6x      6X      6u\n")); 
2456   wxStrcpy(prefix
, _T("%")); 
2457   for (i 
= 0; i 
< 2; i
++) { 
2458     for (j 
= 0; j 
< 2; j
++) { 
2459       for (k 
= 0; k 
< 2; k
++) { 
2460         for (l 
= 0; l 
< 2; l
++) { 
2461           wxStrcpy(prefix
, _T("%")); 
2462           if (i 
== 0) wxStrcat(prefix
, _T("-")); 
2463           if (j 
== 0) wxStrcat(prefix
, _T("+")); 
2464           if (k 
== 0) wxStrcat(prefix
, _T("#")); 
2465           if (l 
== 0) wxStrcat(prefix
, _T("0")); 
2466           wxPrintf(_T("%5s |"), prefix
); 
2467           wxStrcpy(tp
, prefix
); 
2468           wxStrcat(tp
, _T("6d |")); 
2470           wxStrcpy(tp
, prefix
); 
2471           wxStrcat(tp
, _T("6o |")); 
2473           wxStrcpy(tp
, prefix
); 
2474           wxStrcat(tp
, _T("6x |")); 
2476           wxStrcpy(tp
, prefix
); 
2477           wxStrcat(tp
, _T("6X |")); 
2479           wxStrcpy(tp
, prefix
); 
2480           wxStrcat(tp
, _T("6u |")); 
2487   wxPrintf(_T("%10s\n"), PointerNull
); 
2488   wxPrintf(_T("%-10s\n"), PointerNull
); 
2491 static void TestPrintf() 
2493   static wxChar shortstr
[] = _T("Hi, Z."); 
2494   static wxChar longstr
[] = _T("Good morning, Doctor Chandra.  This is Hal.  \ 
2495 I am ready for my first lesson today."); 
2497   wxString test_format
; 
2501   fmtchk(_T("%4.4x")); 
2502   fmtchk(_T("%04.4x")); 
2503   fmtchk(_T("%4.3x")); 
2504   fmtchk(_T("%04.3x")); 
2506   fmtst1chk(_T("%.*x")); 
2507   fmtst1chk(_T("%0*x")); 
2508   fmtst2chk(_T("%*.*x")); 
2509   fmtst2chk(_T("%0*.*x")); 
2511   wxString bad_format 
= _T("bad format:\t\"%b\"\n"); 
2512   wxPrintf(bad_format
.c_str()); 
2513   wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
); 
2515   wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345); 
2516   wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345); 
2517   wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345); 
2518   wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L); 
2519   wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L); 
2520   wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L); 
2521   wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L); 
2522   test_format 
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n"); 
2523   wxPrintf(test_format
.c_str(), -123456); 
2524   wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L); 
2525   wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); 
2527   test_format 
= _T("zero-padded string:\t\"%010s\"\n"); 
2528   wxPrintf(test_format
.c_str(), shortstr
); 
2529   test_format 
= _T("left-adjusted Z string:\t\"%-010s\"\n"); 
2530   wxPrintf(test_format
.c_str(), shortstr
); 
2531   wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
); 
2532   wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
); 
2533   wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
); 
2534   wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
); 
2536   wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34); 
2537   wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234); 
2538   wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234); 
2539   wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
); 
2540   wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1); 
2541   wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34); 
2542   wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234); 
2543   wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234); 
2544   wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34); 
2545   wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234); 
2546   wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234); 
2547   wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
); 
2549   wxPrintf (_T(" %6.5f\n"), .099999999860301614); 
2550   wxPrintf (_T(" %6.5f\n"), .1); 
2551   wxPrintf (_T("x%5.4fx\n"), .5); 
2553   wxPrintf (_T("%#03x\n"), 1); 
2555   //wxPrintf (_T("something really insane: %.10000f\n"), 1.0); 
2561     while (niter
-- != 0) 
2562       wxPrintf (_T("%.17e\n"), d 
/ 2); 
2567   // Open Watcom cause compiler error here 
2568   // Error! E173: col(24) floating-point constant too small to represent 
2569   wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324); 
2572 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n") 
2573   wxPrintf (FORMAT
, 0.0, 0.0, 0.0); 
2574   wxPrintf (FORMAT
, 1.0, 1.0, 1.0); 
2575   wxPrintf (FORMAT
, -1.0, -1.0, -1.0); 
2576   wxPrintf (FORMAT
, 100.0, 100.0, 100.0); 
2577   wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0); 
2578   wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0); 
2579   wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0); 
2580   wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0); 
2581   wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0); 
2586     int rc 
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo")); 
2588     wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"), 
2589              rc
, WXSIZEOF(buf
), buf
); 
2592     wxPrintf ("snprintf (\"%%.999999u\", 10)\n", 
2593             wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10)); 
2599   wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8); 
2600   wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8); 
2601   wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8); 
2602   wxPrintf (_T("%g should be 123.456\n"), 123.456); 
2603   wxPrintf (_T("%g should be 1e+06\n"), 1000000.0); 
2604   wxPrintf (_T("%g should be 10\n"), 10.0); 
2605   wxPrintf (_T("%g should be 0.02\n"), 0.02); 
2609     wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
); 
2615     wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three")); 
2617     result 
|= wxStrcmp (buf
, 
2618                       _T("onetwo                 three                         ")); 
2620     wxPuts (result 
!= 0 ? _T("Test failed!") : _T("Test ok.")); 
2627       wxSprintf(buf
, _T("%07") wxLongLongFmtSpec 
_T("o"), wxLL(040000000000)); 
2629         // for some reason below line fails under Borland 
2630       wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
); 
2633       if (wxStrcmp (buf
, _T("40000000000")) != 0) 
2636           wxPuts (_T("\tFAILED")); 
2638       wxUnusedVar(result
); 
2639       wxPuts (wxEmptyString
); 
2641 #endif // wxLongLong_t 
2643   wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX 
+ 2, UCHAR_MAX 
+ 2); 
2644   wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX 
+ 2, USHRT_MAX 
+ 2); 
2646   wxPuts (_T("--- Should be no further output. ---")); 
2655     memset (bytes
, '\xff', sizeof bytes
); 
2656     wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]); 
2657     if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff' 
2658         || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff') 
2660         wxPuts (_T("%hhn overwrite more bytes")); 
2665         wxPuts (_T("%hhn wrote incorrect value")); 
2677   wxSprintf (buf
, _T("%5.s"), _T("xyz")); 
2678   if (wxStrcmp (buf
, _T("     ")) != 0) 
2679     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("     ")); 
2680   wxSprintf (buf
, _T("%5.f"), 33.3); 
2681   if (wxStrcmp (buf
, _T("   33")) != 0) 
2682     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   33")); 
2683   wxSprintf (buf
, _T("%8.e"), 33.3e7
); 
2684   if (wxStrcmp (buf
, _T("   3e+08")) != 0) 
2685     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   3e+08")); 
2686   wxSprintf (buf
, _T("%8.E"), 33.3e7
); 
2687   if (wxStrcmp (buf
, _T("   3E+08")) != 0) 
2688     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   3E+08")); 
2689   wxSprintf (buf
, _T("%.g"), 33.3); 
2690   if (wxStrcmp (buf
, _T("3e+01")) != 0) 
2691     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01")); 
2692   wxSprintf (buf
, _T("%.G"), 33.3); 
2693   if (wxStrcmp (buf
, _T("3E+01")) != 0) 
2694     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01")); 
2702   wxString test_format
; 
2705   wxSprintf (buf
, _T("%.*g"), prec
, 3.3); 
2706   if (wxStrcmp (buf
, _T("3")) != 0) 
2707     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3")); 
2709   wxSprintf (buf
, _T("%.*G"), prec
, 3.3); 
2710   if (wxStrcmp (buf
, _T("3")) != 0) 
2711     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3")); 
2713   wxSprintf (buf
, _T("%7.*G"), prec
, 3.33); 
2714   if (wxStrcmp (buf
, _T("      3")) != 0) 
2715     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("      3")); 
2717   test_format 
= _T("%04.*o"); 
2718   wxSprintf (buf
, test_format
.c_str(), prec
, 33); 
2719   if (wxStrcmp (buf
, _T(" 041")) != 0) 
2720     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041")); 
2722   test_format 
= _T("%09.*u"); 
2723   wxSprintf (buf
, test_format
.c_str(), prec
, 33); 
2724   if (wxStrcmp (buf
, _T("  0000033")) != 0) 
2725     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("  0000033")); 
2727   test_format 
= _T("%04.*x"); 
2728   wxSprintf (buf
, test_format
.c_str(), prec
, 33); 
2729   if (wxStrcmp (buf
, _T(" 021")) != 0) 
2730     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021")); 
2732   test_format 
= _T("%04.*X"); 
2733   wxSprintf (buf
, test_format
.c_str(), prec
, 33); 
2734   if (wxStrcmp (buf
, _T(" 021")) != 0) 
2735     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021")); 
2738 #endif // TEST_PRINTF 
2740 // ---------------------------------------------------------------------------- 
2741 // registry and related stuff 
2742 // ---------------------------------------------------------------------------- 
2744 // this is for MSW only 
2747     #undef TEST_REGISTRY 
2752 #include "wx/confbase.h" 
2753 #include "wx/msw/regconf.h" 
2756 static void TestRegConfWrite() 
2758     wxConfig 
*config 
= new wxConfig(_T("myapp")); 
2759     config
->SetPath(_T("/group1")); 
2760     config
->Write(_T("entry1"), _T("foo")); 
2761     config
->SetPath(_T("/group2")); 
2762     config
->Write(_T("entry1"), _T("bar")); 
2766 static void TestRegConfRead() 
2768     wxConfig 
*config 
= new wxConfig(_T("myapp")); 
2772     config
->SetPath(_T("/")); 
2773     wxPuts(_T("Enumerating / subgroups:")); 
2774     bool bCont 
= config
->GetFirstGroup(str
, dummy
); 
2778         bCont 
= config
->GetNextGroup(str
, dummy
); 
2782 #endif // TEST_REGCONF 
2784 #ifdef TEST_REGISTRY 
2786 #include "wx/msw/registry.h" 
2788 // I chose this one because I liked its name, but it probably only exists under 
2790 static const wxChar 
*TESTKEY 
= 
2791     _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl"); 
2793 static void TestRegistryRead() 
2795     wxPuts(_T("*** testing registry reading ***")); 
2797     wxRegKey 
key(TESTKEY
); 
2798     wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str()); 
2801         wxPuts(_T("ERROR: test key can't be opened, aborting test.")); 
2806     size_t nSubKeys
, nValues
; 
2807     if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) ) 
2809         wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
); 
2812     wxPrintf(_T("Enumerating values:\n")); 
2816     bool cont 
= key
.GetFirstValue(value
, dummy
); 
2819         wxPrintf(_T("Value '%s': type "), value
.c_str()); 
2820         switch ( key
.GetValueType(value
) ) 
2822             case wxRegKey::Type_None
:   wxPrintf(_T("ERROR (none)")); break; 
2823             case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break; 
2824             case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break; 
2825             case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break; 
2826             case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break; 
2827             case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break; 
2828             default: wxPrintf(_T("other (unknown)")); break; 
2831         wxPrintf(_T(", value = ")); 
2832         if ( key
.IsNumericValue(value
) ) 
2835             key
.QueryValue(value
, &val
); 
2836             wxPrintf(_T("%ld"), val
); 
2841             key
.QueryValue(value
, val
); 
2842             wxPrintf(_T("'%s'"), val
.c_str()); 
2844             key
.QueryRawValue(value
, val
); 
2845             wxPrintf(_T(" (raw value '%s')"), val
.c_str()); 
2850         cont 
= key
.GetNextValue(value
, dummy
); 
2854 static void TestRegistryAssociation() 
2857        The second call to deleteself genertaes an error message, with a 
2858        messagebox saying .flo is crucial to system operation, while the .ddf 
2859        call also fails, but with no error message 
2864     key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); 
2866     key 
= _T("ddxf_auto_file") ; 
2867     key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); 
2869     key 
= _T("ddxf_auto_file") ; 
2870     key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); 
2872     key 
= _T("program,0") ; 
2873     key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); 
2875     key 
= _T("program \"%1\"") ; 
2877     key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); 
2879     key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); 
2881     key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); 
2883     key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); 
2887 #endif // TEST_REGISTRY 
2889 // ---------------------------------------------------------------------------- 
2891 // ---------------------------------------------------------------------------- 
2893 #ifdef TEST_SCOPEGUARD 
2895 #include "wx/scopeguard.h" 
2897 static void function0() { puts("function0()"); } 
2898 static void function1(int n
) { printf("function1(%d)\n", n
); } 
2899 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); } 
2903     void method0() { printf("method0()\n"); } 
2904     void method1(int n
) { printf("method1(%d)\n", n
); } 
2905     void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); } 
2908 static void TestScopeGuard() 
2910     wxON_BLOCK_EXIT0(function0
); 
2911     wxON_BLOCK_EXIT1(function1
, 17); 
2912     wxON_BLOCK_EXIT2(function2
, 3.14, 'p'); 
2915     wxON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
); 
2916     wxON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7); 
2917     wxON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e'); 
2919     wxScopeGuard dismissed 
= wxMakeGuard(function0
); 
2920     dismissed
.Dismiss(); 
2925 // ---------------------------------------------------------------------------- 
2927 // ---------------------------------------------------------------------------- 
2931 #include "wx/socket.h" 
2932 #include "wx/protocol/protocol.h" 
2933 #include "wx/protocol/http.h" 
2935 static void TestSocketServer() 
2937     wxPuts(_T("*** Testing wxSocketServer ***\n")); 
2939     static const int PORT 
= 3000; 
2944     wxSocketServer 
*server 
= new wxSocketServer(addr
); 
2945     if ( !server
->Ok() ) 
2947         wxPuts(_T("ERROR: failed to bind")); 
2955         wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
); 
2957         wxSocketBase 
*socket 
= server
->Accept(); 
2960             wxPuts(_T("ERROR: wxSocketServer::Accept() failed.")); 
2964         wxPuts(_T("Server: got a client.")); 
2966         server
->SetTimeout(60); // 1 min 
2969         while ( !close 
&& socket
->IsConnected() ) 
2972             wxChar ch 
= _T('\0'); 
2975                 if ( socket
->Read(&ch
, sizeof(ch
)).Error() ) 
2977                     // don't log error if the client just close the connection 
2978                     if ( socket
->IsConnected() ) 
2980                         wxPuts(_T("ERROR: in wxSocket::Read.")); 
3000             wxPrintf(_T("Server: got '%s'.\n"), s
.c_str()); 
3001             if ( s 
== _T("close") ) 
3003                 wxPuts(_T("Closing connection")); 
3007             else if ( s 
== _T("quit") ) 
3012                 wxPuts(_T("Shutting down the server")); 
3014             else // not a special command 
3016                 socket
->Write(s
.MakeUpper().c_str(), s
.length()); 
3017                 socket
->Write("\r\n", 2); 
3018                 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str()); 
3024             wxPuts(_T("Server: lost a client unexpectedly.")); 
3030     // same as "delete server" but is consistent with GUI programs 
3034 static void TestSocketClient() 
3036     wxPuts(_T("*** Testing wxSocketClient ***\n")); 
3038     static const wxChar 
*hostname 
= _T("www.wxwindows.org"); 
3041     addr
.Hostname(hostname
); 
3044     wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
); 
3046     wxSocketClient client
; 
3047     if ( !client
.Connect(addr
) ) 
3049         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3053         wxPrintf(_T("--- Connected to %s:%u...\n"), 
3054                addr
.Hostname().c_str(), addr
.Service()); 
3058         // could use simply "GET" here I suppose 
3060             wxString::Format(_T("GET http://%s/\r\n"), hostname
); 
3061         client
.Write(cmdGet
, cmdGet
.length()); 
3062         wxPrintf(_T("--- Sent command '%s' to the server\n"), 
3063                MakePrintable(cmdGet
).c_str()); 
3064         client
.Read(buf
, WXSIZEOF(buf
)); 
3065         wxPrintf(_T("--- Server replied:\n%s"), buf
); 
3069 #endif // TEST_SOCKETS 
3071 // ---------------------------------------------------------------------------- 
3073 // ---------------------------------------------------------------------------- 
3077 #include "wx/protocol/ftp.h" 
3081 #define FTP_ANONYMOUS 
3083 #ifdef FTP_ANONYMOUS 
3084     static const wxChar 
*directory 
= _T("/pub"); 
3085     static const wxChar 
*filename 
= _T("welcome.msg"); 
3087     static const wxChar 
*directory 
= _T("/etc"); 
3088     static const wxChar 
*filename 
= _T("issue"); 
3091 static bool TestFtpConnect() 
3093     wxPuts(_T("*** Testing FTP connect ***")); 
3095 #ifdef FTP_ANONYMOUS 
3096     static const wxChar 
*hostname 
= _T("ftp.wxwindows.org"); 
3098     wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
); 
3099 #else // !FTP_ANONYMOUS 
3100     static const wxChar 
*hostname 
= "localhost"; 
3103     wxFgets(user
, WXSIZEOF(user
), stdin
); 
3104     user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n' 
3107     wxChar password
[256]; 
3108     wxPrintf(_T("Password for %s: "), password
); 
3109     wxFgets(password
, WXSIZEOF(password
), stdin
); 
3110     password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n' 
3111     ftp
.SetPassword(password
); 
3113     wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
); 
3114 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS 
3116     if ( !ftp
.Connect(hostname
) ) 
3118         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3124         wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"), 
3125                hostname
, ftp
.Pwd().c_str()); 
3131 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0? 
3132 static void TestFtpWuFtpd() 
3135     static const wxChar 
*hostname 
= _T("ftp.eudora.com"); 
3136     if ( !ftp
.Connect(hostname
) ) 
3138         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3142         static const wxChar 
*filename 
= _T("eudora/pubs/draft-gellens-submit-09.txt"); 
3143         wxInputStream 
*in 
= ftp
.GetInputStream(filename
); 
3146             wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
); 
3150             size_t size 
= in
->GetSize(); 
3151             wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
); 
3153             wxChar 
*data 
= new wxChar
[size
]; 
3154             if ( !in
->Read(data
, size
) ) 
3156                 wxPuts(_T("ERROR: read error")); 
3160                 wxPrintf(_T("Successfully retrieved the file.\n")); 
3169 static void TestFtpList() 
3171     wxPuts(_T("*** Testing wxFTP file listing ***\n")); 
3174     if ( !ftp
.ChDir(directory
) ) 
3176         wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
); 
3179     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3181     // test NLIST and LIST 
3182     wxArrayString files
; 
3183     if ( !ftp
.GetFilesList(files
) ) 
3185         wxPuts(_T("ERROR: failed to get NLIST of files")); 
3189         wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str()); 
3190         size_t count 
= files
.GetCount(); 
3191         for ( size_t n 
= 0; n 
< count
; n
++ ) 
3193             wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3195         wxPuts(_T("End of the file list")); 
3198     if ( !ftp
.GetDirList(files
) ) 
3200         wxPuts(_T("ERROR: failed to get LIST of files")); 
3204         wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str()); 
3205         size_t count 
= files
.GetCount(); 
3206         for ( size_t n 
= 0; n 
< count
; n
++ ) 
3208             wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3210         wxPuts(_T("End of the file list")); 
3213     if ( !ftp
.ChDir(_T("..")) ) 
3215         wxPuts(_T("ERROR: failed to cd to ..")); 
3218     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3221 static void TestFtpDownload() 
3223     wxPuts(_T("*** Testing wxFTP download ***\n")); 
3226     wxInputStream 
*in 
= ftp
.GetInputStream(filename
); 
3229         wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
); 
3233         size_t size 
= in
->GetSize(); 
3234         wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
); 
3237         wxChar 
*data 
= new wxChar
[size
]; 
3238         if ( !in
->Read(data
, size
) ) 
3240             wxPuts(_T("ERROR: read error")); 
3244             wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
); 
3252 static void TestFtpFileSize() 
3254     wxPuts(_T("*** Testing FTP SIZE command ***")); 
3256     if ( !ftp
.ChDir(directory
) ) 
3258         wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
); 
3261     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3263     if ( ftp
.FileExists(filename
) ) 
3265         int size 
= ftp
.GetFileSize(filename
); 
3267             wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
); 
3269             wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
); 
3273         wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
); 
3277 static void TestFtpMisc() 
3279     wxPuts(_T("*** Testing miscellaneous wxFTP functions ***")); 
3281     if ( ftp
.SendCommand(_T("STAT")) != '2' ) 
3283         wxPuts(_T("ERROR: STAT failed")); 
3287         wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str()); 
3290     if ( ftp
.SendCommand(_T("HELP SITE")) != '2' ) 
3292         wxPuts(_T("ERROR: HELP SITE failed")); 
3296         wxPrintf(_T("The list of site-specific commands:\n\n%s\n"), 
3297                ftp
.GetLastResult().c_str()); 
3301 static void TestFtpInteractive() 
3303     wxPuts(_T("\n*** Interactive wxFTP test ***")); 
3309         wxPrintf(_T("Enter FTP command: ")); 
3310         if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) ) 
3313         // kill the last '\n' 
3314         buf
[wxStrlen(buf
) - 1] = 0; 
3316         // special handling of LIST and NLST as they require data connection 
3317         wxString 
start(buf
, 4); 
3319         if ( start 
== _T("LIST") || start 
== _T("NLST") ) 
3322             if ( wxStrlen(buf
) > 4 ) 
3325             wxArrayString files
; 
3326             if ( !ftp
.GetList(files
, wildcard
, start 
== _T("LIST")) ) 
3328                 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str()); 
3332                 wxPrintf(_T("--- %s of '%s' under '%s':\n"), 
3333                        start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str()); 
3334                 size_t count 
= files
.GetCount(); 
3335                 for ( size_t n 
= 0; n 
< count
; n
++ ) 
3337                     wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3339                 wxPuts(_T("--- End of the file list")); 
3344             wxChar ch 
= ftp
.SendCommand(buf
); 
3345             wxPrintf(_T("Command %s"), ch 
? _T("succeeded") : _T("failed")); 
3348                 wxPrintf(_T(" (return code %c)"), ch
); 
3351             wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str()); 
3355     wxPuts(_T("\n*** done ***")); 
3358 static void TestFtpUpload() 
3360     wxPuts(_T("*** Testing wxFTP uploading ***\n")); 
3363     static const wxChar 
*file1 
= _T("test1"); 
3364     static const wxChar 
*file2 
= _T("test2"); 
3365     wxOutputStream 
*out 
= ftp
.GetOutputStream(file1
); 
3368         wxPrintf(_T("--- Uploading to %s ---\n"), file1
); 
3369         out
->Write("First hello", 11); 
3373     // send a command to check the remote file 
3374     if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' ) 
3376         wxPrintf(_T("ERROR: STAT %s failed\n"), file1
); 
3380         wxPrintf(_T("STAT %s returned:\n\n%s\n"), 
3381                file1
, ftp
.GetLastResult().c_str()); 
3384     out 
= ftp
.GetOutputStream(file2
); 
3387         wxPrintf(_T("--- Uploading to %s ---\n"), file1
); 
3388         out
->Write("Second hello", 12); 
3395 // ---------------------------------------------------------------------------- 
3397 // ---------------------------------------------------------------------------- 
3401 #include "wx/wfstream.h" 
3402 #include "wx/mstream.h" 
3404 static void TestFileStream() 
3406     wxPuts(_T("*** Testing wxFileInputStream ***")); 
3408     static const wxString filename 
= _T("testdata.fs"); 
3410         wxFileOutputStream 
fsOut(filename
); 
3411         fsOut
.Write("foo", 3); 
3414     wxFileInputStream 
fsIn(filename
); 
3415     wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize()); 
3416     while ( !fsIn
.Eof() ) 
3418         wxPutchar(fsIn
.GetC()); 
3421     if ( !wxRemoveFile(filename
) ) 
3423         wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str()); 
3426     wxPuts(_T("\n*** wxFileInputStream test done ***")); 
3429 static void TestMemoryStream() 
3431     wxPuts(_T("*** Testing wxMemoryOutputStream ***")); 
3433     wxMemoryOutputStream memOutStream
; 
3434     wxPrintf(_T("Initially out stream offset: %lu\n"), 
3435              (unsigned long)memOutStream
.TellO()); 
3437     for ( const wxChar 
*p 
= _T("Hello, stream!"); *p
; p
++ ) 
3439         memOutStream
.PutC(*p
); 
3442     wxPrintf(_T("Final out stream offset: %lu\n"), 
3443              (unsigned long)memOutStream
.TellO()); 
3445     wxPuts(_T("*** Testing wxMemoryInputStream ***")); 
3448     size_t len 
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
)); 
3450     wxMemoryInputStream 
memInpStream(buf
, len
); 
3451     wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize()); 
3452     while ( !memInpStream
.Eof() ) 
3454         wxPutchar(memInpStream
.GetC()); 
3457     wxPuts(_T("\n*** wxMemoryInputStream test done ***")); 
3460 #endif // TEST_STREAMS 
3462 // ---------------------------------------------------------------------------- 
3464 // ---------------------------------------------------------------------------- 
3468 #include "wx/timer.h" 
3469 #include "wx/utils.h" 
3471 static void TestStopWatch() 
3473     wxPuts(_T("*** Testing wxStopWatch ***\n")); 
3477     wxPrintf(_T("Initially paused, after 2 seconds time is...")); 
3480     wxPrintf(_T("\t%ldms\n"), sw
.Time()); 
3482     wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds...")); 
3486     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3489     wxPrintf(_T("Pausing agan and sleeping 2 more seconds...")); 
3492     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3495     wxPrintf(_T("Finally resuming and sleeping 2 more seconds...")); 
3498     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3501     wxPuts(_T("\nChecking for 'backwards clock' bug...")); 
3502     for ( size_t n 
= 0; n 
< 70; n
++ ) 
3506         for ( size_t m 
= 0; m 
< 100000; m
++ ) 
3508             if ( sw
.Time() < 0 || sw2
.Time() < 0 ) 
3510                 wxPuts(_T("\ntime is negative - ERROR!")); 
3518     wxPuts(_T(", ok.")); 
3521 #endif // TEST_TIMER 
3523 // ---------------------------------------------------------------------------- 
3525 // ---------------------------------------------------------------------------- 
3529 #include "wx/vcard.h" 
3531 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
) 
3534     wxVCardObject 
*vcObj 
= vcard
.GetFirstProp(&cookie
); 
3537         wxPrintf(_T("%s%s"), 
3538                wxString(_T('\t'), level
).c_str(), 
3539                vcObj
->GetName().c_str()); 
3542         switch ( vcObj
->GetType() ) 
3544             case wxVCardObject::String
: 
3545             case wxVCardObject::UString
: 
3548                     vcObj
->GetValue(&val
); 
3549                     value 
<< _T('"') << val 
<< _T('"'); 
3553             case wxVCardObject::Int
: 
3556                     vcObj
->GetValue(&i
); 
3557                     value
.Printf(_T("%u"), i
); 
3561             case wxVCardObject::Long
: 
3564                     vcObj
->GetValue(&l
); 
3565                     value
.Printf(_T("%lu"), l
); 
3569             case wxVCardObject::None
: 
3572             case wxVCardObject::Object
: 
3573                 value 
= _T("<node>"); 
3577                 value 
= _T("<unknown value type>"); 
3581             wxPrintf(_T(" = %s"), value
.c_str()); 
3584         DumpVObject(level 
+ 1, *vcObj
); 
3587         vcObj 
= vcard
.GetNextProp(&cookie
); 
3591 static void DumpVCardAddresses(const wxVCard
& vcard
) 
3593     wxPuts(_T("\nShowing all addresses from vCard:\n")); 
3597     wxVCardAddress 
*addr 
= vcard
.GetFirstAddress(&cookie
); 
3601         int flags 
= addr
->GetFlags(); 
3602         if ( flags 
& wxVCardAddress::Domestic 
) 
3604             flagsStr 
<< _T("domestic "); 
3606         if ( flags 
& wxVCardAddress::Intl 
) 
3608             flagsStr 
<< _T("international "); 
3610         if ( flags 
& wxVCardAddress::Postal 
) 
3612             flagsStr 
<< _T("postal "); 
3614         if ( flags 
& wxVCardAddress::Parcel 
) 
3616             flagsStr 
<< _T("parcel "); 
3618         if ( flags 
& wxVCardAddress::Home 
) 
3620             flagsStr 
<< _T("home "); 
3622         if ( flags 
& wxVCardAddress::Work 
) 
3624             flagsStr 
<< _T("work "); 
3627         wxPrintf(_T("Address %u:\n") 
3629                "\tvalue = %s;%s;%s;%s;%s;%s;%s\n", 
3632                addr
->GetPostOffice().c_str(), 
3633                addr
->GetExtAddress().c_str(), 
3634                addr
->GetStreet().c_str(), 
3635                addr
->GetLocality().c_str(), 
3636                addr
->GetRegion().c_str(), 
3637                addr
->GetPostalCode().c_str(), 
3638                addr
->GetCountry().c_str() 
3642         addr 
= vcard
.GetNextAddress(&cookie
); 
3646 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
) 
3648     wxPuts(_T("\nShowing all phone numbers from vCard:\n")); 
3652     wxVCardPhoneNumber 
*phone 
= vcard
.GetFirstPhoneNumber(&cookie
); 
3656         int flags 
= phone
->GetFlags(); 
3657         if ( flags 
& wxVCardPhoneNumber::Voice 
) 
3659             flagsStr 
<< _T("voice "); 
3661         if ( flags 
& wxVCardPhoneNumber::Fax 
) 
3663             flagsStr 
<< _T("fax "); 
3665         if ( flags 
& wxVCardPhoneNumber::Cellular 
) 
3667             flagsStr 
<< _T("cellular "); 
3669         if ( flags 
& wxVCardPhoneNumber::Modem 
) 
3671             flagsStr 
<< _T("modem "); 
3673         if ( flags 
& wxVCardPhoneNumber::Home 
) 
3675             flagsStr 
<< _T("home "); 
3677         if ( flags 
& wxVCardPhoneNumber::Work 
) 
3679             flagsStr 
<< _T("work "); 
3682         wxPrintf(_T("Phone number %u:\n") 
3687                phone
->GetNumber().c_str() 
3691         phone 
= vcard
.GetNextPhoneNumber(&cookie
); 
3695 static void TestVCardRead() 
3697     wxPuts(_T("*** Testing wxVCard reading ***\n")); 
3699     wxVCard 
vcard(_T("vcard.vcf")); 
3700     if ( !vcard
.IsOk() ) 
3702         wxPuts(_T("ERROR: couldn't load vCard.")); 
3706         // read individual vCard properties 
3707         wxVCardObject 
*vcObj 
= vcard
.GetProperty("FN"); 
3711             vcObj
->GetValue(&value
); 
3716             value 
= _T("<none>"); 
3719         wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str()); 
3722         if ( !vcard
.GetFullName(&value
) ) 
3724             value 
= _T("<none>"); 
3727         wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str()); 
3729         // now show how to deal with multiply occuring properties 
3730         DumpVCardAddresses(vcard
); 
3731         DumpVCardPhoneNumbers(vcard
); 
3733         // and finally show all 
3734         wxPuts(_T("\nNow dumping the entire vCard:\n") 
3735              "-----------------------------\n"); 
3737         DumpVObject(0, vcard
); 
3741 static void TestVCardWrite() 
3743     wxPuts(_T("*** Testing wxVCard writing ***\n")); 
3746     if ( !vcard
.IsOk() ) 
3748         wxPuts(_T("ERROR: couldn't create vCard.")); 
3753         vcard
.SetName("Zeitlin", "Vadim"); 
3754         vcard
.SetFullName("Vadim Zeitlin"); 
3755         vcard
.SetOrganization("wxWindows", "R&D"); 
3757         // just dump the vCard back 
3758         wxPuts(_T("Entire vCard follows:\n")); 
3759         wxPuts(vcard
.Write()); 
3763 #endif // TEST_VCARD 
3765 // ---------------------------------------------------------------------------- 
3767 // ---------------------------------------------------------------------------- 
3769 #if !defined(__WIN32__) || !wxUSE_FSVOLUME 
3775 #include "wx/volume.h" 
3777 static const wxChar 
*volumeKinds
[] = 
3783     _T("network volume"), 
3787 static void TestFSVolume() 
3789     wxPuts(_T("*** Testing wxFSVolume class ***")); 
3791     wxArrayString volumes 
= wxFSVolume::GetVolumes(); 
3792     size_t count 
= volumes
.GetCount(); 
3796         wxPuts(_T("ERROR: no mounted volumes?")); 
3800     wxPrintf(_T("%u mounted volumes found:\n"), count
); 
3802     for ( size_t n 
= 0; n 
< count
; n
++ ) 
3804         wxFSVolume 
vol(volumes
[n
]); 
3807             wxPuts(_T("ERROR: couldn't create volume")); 
3811         wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"), 
3813                  vol
.GetDisplayName().c_str(), 
3814                  vol
.GetName().c_str(), 
3815                  volumeKinds
[vol
.GetKind()], 
3816                  vol
.IsWritable() ? _T("rw") : _T("ro"), 
3817                  vol
.GetFlags() & wxFS_VOL_REMOVABLE 
? _T("removable") 
3822 #endif // TEST_VOLUME 
3824 // ---------------------------------------------------------------------------- 
3825 // wide char and Unicode support 
3826 // ---------------------------------------------------------------------------- 
3830 static void TestUnicodeToFromAscii() 
3832     wxPuts(_T("Testing wxString::To/FromAscii()\n")); 
3834     static const char *msg 
= "Hello, world!"; 
3835     wxString s 
= wxString::FromAscii(msg
); 
3837     wxPrintf(_T("Message in Unicode: %s\n"), s
.c_str()); 
3838     printf("Message in ASCII: %s\n", (const char *)s
.ToAscii()); 
3840     wxPutchar(_T('\n')); 
3843 #include "wx/textfile.h" 
3845 static void TestUnicodeTextFileRead() 
3847     wxPuts(_T("Testing wxTextFile in Unicode build\n")); 
3850     if ( file
.Open(_T("testdata.fc"), wxConvLocal
) ) 
3852         const size_t count 
= file
.GetLineCount(); 
3853         for ( size_t n 
= 0; n 
< count
; n
++ ) 
3855             const wxString
& s 
= file
[n
]; 
3857             wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"), 
3858                      (unsigned)n
, s
.c_str(), (unsigned)s
.length(), s
.Last()); 
3863 #endif // TEST_UNICODE 
3867 #include "wx/strconv.h" 
3868 #include "wx/fontenc.h" 
3869 #include "wx/encconv.h" 
3870 #include "wx/buffer.h" 
3872 static const unsigned char utf8koi8r
[] = 
3874     208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176, 
3875     208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208, 
3876     176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188, 
3877     208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208, 
3878     181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181, 
3879     208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208, 
3880     178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0 
3883 static const unsigned char utf8iso8859_1
[] = 
3885     0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e, 
3886     0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65, 
3887     0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65, 
3888     0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65, 
3889     0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0 
3892 static const unsigned char utf8Invalid
[] = 
3894     0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30, 
3895     0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6, 
3896     0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88, 
3897     0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70, 
3901 static const struct Utf8Data
 
3903     const unsigned char *text
; 
3905     const wxChar 
*charset
; 
3906     wxFontEncoding encoding
; 
3909     { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 
}, 
3910     { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8 
}, 
3911     { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 
}, 
3914 static void TestUtf8() 
3916     wxPuts(_T("*** Testing UTF8 support ***\n")); 
3921     for ( size_t n 
= 0; n 
< WXSIZEOF(utf8data
); n
++ ) 
3923         const Utf8Data
& u8d 
= utf8data
[n
]; 
3924         if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
, 
3925                               WXSIZEOF(wbuf
)) == (size_t)-1 ) 
3927             wxPuts(_T("ERROR: UTF-8 decoding failed.")); 
3931             wxCSConv 
conv(u8d
.charset
); 
3932             if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 ) 
3934                 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
); 
3938                 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
); 
3942         wxString 
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
)); 
3944             s 
= _T("<< conversion failed >>"); 
3945         wxPrintf(_T("String in current cset: %s\n"), s
.c_str()); 
3949     wxPuts(wxEmptyString
); 
3952 static void TestEncodingConverter() 
3954     wxPuts(_T("*** Testing wxEncodingConverter ***\n")); 
3956     // using wxEncodingConverter should give the same result as above 
3959     if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
, 
3960                           WXSIZEOF(utf8koi8r
)) == (size_t)-1 ) 
3962         wxPuts(_T("ERROR: UTF-8 decoding failed.")); 
3966         wxEncodingConverter ec
; 
3967         ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
); 
3968         ec
.Convert(wbuf
, buf
); 
3969         wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
); 
3972     wxPuts(wxEmptyString
); 
3975 #endif // TEST_WCHAR 
3977 // ---------------------------------------------------------------------------- 
3979 // ---------------------------------------------------------------------------- 
3983 #include "wx/filesys.h" 
3984 #include "wx/fs_zip.h" 
3985 #include "wx/zipstrm.h" 
3987 static const wxChar 
*TESTFILE_ZIP 
= _T("testdata.zip"); 
3989 static void TestZipStreamRead() 
3991     wxPuts(_T("*** Testing ZIP reading ***\n")); 
3993     static const wxString filename 
= _T("foo"); 
3994     wxZipInputStream 
istr(TESTFILE_ZIP
, filename
); 
3995     wxPrintf(_T("Archive size: %u\n"), istr
.GetSize()); 
3997     wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str()); 
3998     while ( !istr
.Eof() ) 
4000         wxPutchar(istr
.GetC()); 
4004     wxPuts(_T("\n----- done ------")); 
4007 static void DumpZipDirectory(wxFileSystem
& fs
, 
4008                              const wxString
& dir
, 
4009                              const wxString
& indent
) 
4011     wxString prefix 
= wxString::Format(_T("%s#zip:%s"), 
4012                                          TESTFILE_ZIP
, dir
.c_str()); 
4013     wxString wildcard 
= prefix 
+ _T("/*"); 
4015     wxString dirname 
= fs
.FindFirst(wildcard
, wxDIR
); 
4016     while ( !dirname
.empty() ) 
4018         if ( !dirname
.StartsWith(prefix 
+ _T('/'), &dirname
) ) 
4020             wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); 
4025         wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str()); 
4027         DumpZipDirectory(fs
, dirname
, 
4028                          indent 
+ wxString(_T(' '), 4)); 
4030         dirname 
= fs
.FindNext(); 
4033     wxString filename 
= fs
.FindFirst(wildcard
, wxFILE
); 
4034     while ( !filename
.empty() ) 
4036         if ( !filename
.StartsWith(prefix
, &filename
) ) 
4038             wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); 
4043         wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str()); 
4045         filename 
= fs
.FindNext(); 
4049 static void TestZipFileSystem() 
4051     wxPuts(_T("*** Testing ZIP file system ***\n")); 
4053     wxFileSystem::AddHandler(new wxZipFSHandler
); 
4055     wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
); 
4057     DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4)); 
4062 // ---------------------------------------------------------------------------- 
4064 // ---------------------------------------------------------------------------- 
4068 #include "wx/zstream.h" 
4069 #include "wx/wfstream.h" 
4071 static const wxString FILENAME_GZ 
= _T("test.gz"); 
4072 static const wxChar 
*TEST_DATA 
= _T("hello and hello and hello and hello and hello"); 
4074 static void TestZlibStreamWrite() 
4076     wxPuts(_T("*** Testing Zlib stream reading ***\n")); 
4078     wxFileOutputStream 
fileOutStream(FILENAME_GZ
); 
4079     wxZlibOutputStream 
ostr(fileOutStream
); 
4080     wxPrintf(_T("Compressing the test string... ")); 
4081     ostr
.Write(TEST_DATA
, wxStrlen(TEST_DATA
) + 1); 
4084         wxPuts(_T("(ERROR: failed)")); 
4091     wxPuts(_T("\n----- done ------")); 
4094 static void TestZlibStreamRead() 
4096     wxPuts(_T("*** Testing Zlib stream reading ***\n")); 
4098     wxFileInputStream 
fileInStream(FILENAME_GZ
); 
4099     wxZlibInputStream 
istr(fileInStream
); 
4100     wxPrintf(_T("Archive size: %u\n"), istr
.GetSize()); 
4102     wxPuts(_T("Dumping the file:")); 
4103     while ( !istr
.Eof() ) 
4105         wxPutchar(istr
.GetC()); 
4109     wxPuts(_T("\n----- done ------")); 
4114 // ---------------------------------------------------------------------------- 
4116 // ---------------------------------------------------------------------------- 
4120 #include "wx/wfstream.h" 
4121 #include "wx/gzstream.h" 
4122 #include "wx/filename.h" 
4123 #include "wx/txtstrm.h" 
4125 // Reads two input streams and verifies that they are the same (and non-emtpy) 
4127 void GzipVerify(wxInputStream 
&in1
, wxInputStream 
&in2
) 
4130         wxPuts(_T("    Can't verify")); 
4134     const int BUFSIZE 
= 8192; 
4135     wxCharBuffer 
buf1(BUFSIZE
); 
4136     wxCharBuffer 
buf2(BUFSIZE
); 
4141         int n1 
= in1
.Read(buf1
.data(), BUFSIZE
).LastRead(); 
4142         int n2 
= in2
.Read(buf2
.data(), BUFSIZE
).LastRead(); 
4144         if (n1 
!= n2 
|| (n1 
&& memcmp(buf1
, buf2
, n1
) != 0) || (!n1 
&& none
)) { 
4145             wxPuts(_T("    Failure")); 
4150             wxPuts(_T("    Success")); 
4158         in1
.Read(buf1
.data(), BUFSIZE
); 
4160         in2
.Read(buf2
.data(), BUFSIZE
); 
4163 // Write a gzip file and read it back. 
4167     wxPuts(_T("*** Testing gzip streams ***\n")); 
4169     const wxString testname 
= _T("gziptest"); 
4170     const wxString gzipname 
= testname 
+ _T(".gz"); 
4172     // write some random test data to a testfile 
4173     wxPuts(_T("Writing random test data to ") + testname 
+ _T("...")); 
4175         wxFFileOutputStream 
outstream(testname
); 
4176         wxTextOutputStream 
textout(outstream
); 
4178         for (int i 
= 0; i 
< 1000 && outstream
.Ok(); i
++) 
4179             textout 
<< rand() << rand() << rand() << rand() << endl
; 
4181         wxPuts(_T("    Done")); 
4184     wxFileName 
fn(testname
); 
4185     wxDateTime dt 
= fn
.GetModificationTime(); 
4186     wxFFileInputStream 
instream(testname
); 
4188     // try writing a gzip file 
4189     wxPuts(_T("Writing ") + gzipname 
+ _T(" using wxGzipOutputStream...")); 
4191         wxFFileOutputStream 
outstream(gzipname
); 
4192         wxGzipOutputStream 
gzip(outstream
, testname
, dt
); 
4194         if (!gzip
.Write(instream
)) 
4195             wxPuts(_T("    Failure")); 
4197             wxPuts(_T("    Success")); 
4200     // try reading the gzip file 
4201     wxPuts(_T("Reading ") + gzipname 
+ _T(" using wxGzipInputStream...")); 
4204         wxFFileInputStream 
instream2(gzipname
); 
4205         wxGzipInputStream 
gzip(instream2
); 
4206         GzipVerify(instream
, gzip
); 
4208         if (gzip
.GetName() != fn
.GetFullName()) 
4209             wxPuts(gzipname 
+ _T(" contains incorrect filename: ") 
4211         if (dt
.IsValid() && gzip
.GetDateTime() != dt
) 
4212             wxPuts(gzipname 
+ _T(" contains incorrect timestamp: ") 
4213                     + gzip
.GetDateTime().Format()); 
4217     // then verify it using gzip program if it is in the path 
4218     wxPuts(_T("Reading ") + gzipname 
+ _T(" using gzip program...")); 
4219     wxFFile 
file(popen((_T("gzip -d -c ") + gzipname
).mb_str(), "r")); 
4221         wxFFileInputStream 
instream2(file
); 
4223         GzipVerify(instream
, instream2
); 
4228     // try reading a gzip created by gzip program 
4229     wxPuts(_T("Reading output of gzip program using wxGzipInputStream...")); 
4230     file
.Attach(popen((_T("gzip -c ") + testname
).mb_str(), "r")); 
4232         wxFFileInputStream 
instream2(file
); 
4233         wxGzipInputStream 
gzip(instream2
); 
4235         GzipVerify(instream
, gzip
); 
4241     wxPuts(_T("\n--- Done gzip streams ---")); 
4246 // ---------------------------------------------------------------------------- 
4248 // ---------------------------------------------------------------------------- 
4250 #ifdef TEST_DATETIME 
4254 #include "wx/datetime.h" 
4259     wxDateTime::wxDateTime_t day
; 
4260     wxDateTime::Month month
; 
4262     wxDateTime::wxDateTime_t hour
, min
, sec
; 
4264     wxDateTime::WeekDay wday
; 
4265     time_t gmticks
, ticks
; 
4267     void Init(const wxDateTime::Tm
& tm
) 
4276         gmticks 
= ticks 
= -1; 
4279     wxDateTime 
DT() const 
4280         { return wxDateTime(day
, month
, year
, hour
, min
, sec
); } 
4282     bool SameDay(const wxDateTime::Tm
& tm
) const 
4284         return day 
== tm
.mday 
&& month 
== tm
.mon 
&& year 
== tm
.year
; 
4287     wxString 
Format() const 
4290         s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"), 
4292                  wxDateTime::GetMonthName(month
).c_str(), 
4294                  abs(wxDateTime::ConvertYearToBC(year
)), 
4295                  year 
> 0 ? _T("AD") : _T("BC")); 
4299     wxString 
FormatDate() const 
4302         s
.Printf(_T("%02d-%s-%4d%s"), 
4304                  wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(), 
4305                  abs(wxDateTime::ConvertYearToBC(year
)), 
4306                  year 
> 0 ? _T("AD") : _T("BC")); 
4311 static const Date testDates
[] = 
4313     {  1, wxDateTime::Jan
,  1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
,         0,     -3600 }, 
4314     {  7, wxDateTime::Feb
,  2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
,        -1,        -1 }, 
4315     {  8, wxDateTime::Feb
,  2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
,        -1,        -1 }, 
4316     {  1, wxDateTime::Jan
,  2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
,        -1,        -1 }, 
4317     {  1, wxDateTime::Jan
,  2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
,        -1,        -1 }, 
4318     { 21, wxDateTime::Jan
,  2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
,        -1,        -1 }, 
4319     { 29, wxDateTime::May
,  1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 }, 
4320     { 29, wxDateTime::Feb
,  1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 }, 
4321     {  1, wxDateTime::Jan
,  1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
,        -1,        -1 }, 
4322     {  1, wxDateTime::Jan
,  1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
,        -1,        -1 }, 
4323     { 15, wxDateTime::Oct
,  1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
,        -1,        -1 }, 
4324     {  4, wxDateTime::Oct
,  1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
,        -1,        -1 }, 
4325     {  1, wxDateTime::Mar
,     1, 00, 00, 00, 1721484.5, wxDateTime::Thu
,        -1,        -1 }, 
4326     {  1, wxDateTime::Jan
,     1, 00, 00, 00, 1721425.5, wxDateTime::Mon
,        -1,        -1 }, 
4327     { 31, wxDateTime::Dec
,     0, 00, 00, 00, 1721424.5, wxDateTime::Sun
,        -1,        -1 }, 
4328     {  1, wxDateTime::Jan
,     0, 00, 00, 00, 1721059.5, wxDateTime::Sat
,        -1,        -1 }, 
4329     { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
,        -1,        -1 }, 
4330     { 12, wxDateTime::Aug
, -4000, 00, 00, 00,  260313.5, wxDateTime::Sat
,        -1,        -1 }, 
4331     { 24, wxDateTime::Nov
, -4713, 00, 00, 00,      -0.5, wxDateTime::Mon
,        -1,        -1 }, 
4334 // this test miscellaneous static wxDateTime functions 
4335 static void TestTimeStatic() 
4337     wxPuts(_T("\n*** wxDateTime static methods test ***")); 
4339     // some info about the current date 
4340     int year 
= wxDateTime::GetCurrentYear(); 
4341     wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"), 
4343            wxDateTime::IsLeapYear(year
) ? "" : "not ", 
4344            wxDateTime::GetNumberOfDays(year
)); 
4346     wxDateTime::Month month 
= wxDateTime::GetCurrentMonth(); 
4347     wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"), 
4348            wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(), 
4349            wxDateTime::GetMonthName(month
).c_str(), 
4350            wxDateTime::GetNumberOfDays(month
)); 
4353     static const size_t nYears 
= 5; 
4354     static const size_t years
[2][nYears
] = 
4356         // first line: the years to test 
4357         { 1990, 1976, 2000, 2030, 1984, }, 
4359         // second line: true if leap, false otherwise 
4360         { false, true, true, false, true } 
4363     for ( size_t n 
= 0; n 
< nYears
; n
++ ) 
4365         int year 
= years
[0][n
]; 
4366         bool should 
= years
[1][n
] != 0, 
4367              is 
= wxDateTime::IsLeapYear(year
); 
4369         wxPrintf(_T("Year %d is %sa leap year (%s)\n"), 
4372                should 
== is 
? "ok" : "ERROR"); 
4374         wxASSERT( should 
== wxDateTime::IsLeapYear(year
) ); 
4378 // test constructing wxDateTime objects 
4379 static void TestTimeSet() 
4381     wxPuts(_T("\n*** wxDateTime construction test ***")); 
4383     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4385         const Date
& d1 
= testDates
[n
]; 
4386         wxDateTime dt 
= d1
.DT(); 
4389         d2
.Init(dt
.GetTm()); 
4391         wxString s1 
= d1
.Format(), 
4394         wxPrintf(_T("Date: %s == %s (%s)\n"), 
4395                  s1
.c_str(), s2
.c_str(), 
4396                  s1 
== s2 
? _T("ok") : _T("ERROR")); 
4400 // test time zones stuff 
4401 static void TestTimeZones() 
4403     wxPuts(_T("\n*** wxDateTime timezone test ***")); 
4405     wxDateTime now 
= wxDateTime::Now(); 
4407     wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str()); 
4408     wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str()); 
4409     wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str()); 
4410     wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str()); 
4411     wxPrintf(_T("               Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str()); 
4412     wxPrintf(_T("             New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str()); 
4414     wxDateTime::Tm tm 
= now
.GetTm(); 
4415     if ( wxDateTime(tm
) != now 
) 
4417         wxPrintf(_T("ERROR: got %s instead of %s\n"), 
4418                  wxDateTime(tm
).Format().c_str(), now
.Format().c_str()); 
4422 // test some minimal support for the dates outside the standard range 
4423 static void TestTimeRange() 
4425     wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***")); 
4427     static const wxChar 
*fmt 
= _T("%d-%b-%Y %H:%M:%S"); 
4429     wxPrintf(_T("Unix epoch:\t%s\n"), 
4430              wxDateTime(2440587.5).Format(fmt
).c_str()); 
4431     wxPrintf(_T("Feb 29, 0: \t%s\n"), 
4432              wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str()); 
4433     wxPrintf(_T("JDN 0:     \t%s\n"), 
4434              wxDateTime(0.0).Format(fmt
).c_str()); 
4435     wxPrintf(_T("Jan 1, 1AD:\t%s\n"), 
4436              wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str()); 
4437     wxPrintf(_T("May 29, 2099:\t%s\n"), 
4438              wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str()); 
4441 static void TestTimeTicks() 
4443     wxPuts(_T("\n*** wxDateTime ticks test ***")); 
4445     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4447         const Date
& d 
= testDates
[n
]; 
4448         if ( d
.ticks 
== -1 ) 
4451         wxDateTime dt 
= d
.DT(); 
4452         long ticks 
= (dt
.GetValue() / 1000).ToLong(); 
4453         wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
); 
4454         if ( ticks 
== d
.ticks 
) 
4456             wxPuts(_T(" (ok)")); 
4460             wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"), 
4461                      (long)d
.ticks
, (long)(ticks 
- d
.ticks
)); 
4464         dt 
= d
.DT().ToTimezone(wxDateTime::GMT0
); 
4465         ticks 
= (dt
.GetValue() / 1000).ToLong(); 
4466         wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
); 
4467         if ( ticks 
== d
.gmticks 
) 
4469             wxPuts(_T(" (ok)")); 
4473             wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"), 
4474                      (long)d
.gmticks
, (long)(ticks 
- d
.gmticks
)); 
4478     wxPuts(wxEmptyString
); 
4481 // test conversions to JDN &c 
4482 static void TestTimeJDN() 
4484     wxPuts(_T("\n*** wxDateTime to JDN test ***")); 
4486     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4488         const Date
& d 
= testDates
[n
]; 
4489         wxDateTime 
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
); 
4490         double jdn 
= dt
.GetJulianDayNumber(); 
4492         wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
); 
4495             wxPuts(_T(" (ok)")); 
4499             wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"), 
4500                      d
.jdn
, jdn 
- d
.jdn
); 
4505 // test week days computation 
4506 static void TestTimeWDays() 
4508     wxPuts(_T("\n*** wxDateTime weekday test ***")); 
4510     // test GetWeekDay() 
4512     for ( n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4514         const Date
& d 
= testDates
[n
]; 
4515         wxDateTime 
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
); 
4517         wxDateTime::WeekDay wday 
= dt
.GetWeekDay(); 
4518         wxPrintf(_T("%s is: %s"), 
4520                  wxDateTime::GetWeekDayName(wday
).c_str()); 
4521         if ( wday 
== d
.wday 
) 
4523             wxPuts(_T(" (ok)")); 
4527             wxPrintf(_T(" (ERROR: should be %s)\n"), 
4528                      wxDateTime::GetWeekDayName(d
.wday
).c_str()); 
4532     wxPuts(wxEmptyString
); 
4534     // test SetToWeekDay() 
4535     struct WeekDateTestData
 
4537         Date date
;                  // the real date (precomputed) 
4538         int nWeek
;                  // its week index in the month 
4539         wxDateTime::WeekDay wday
;   // the weekday 
4540         wxDateTime::Month month
;    // the month 
4541         int year
;                   // and the year 
4543         wxString 
Format() const 
4546             switch ( nWeek 
< -1 ? -nWeek 
: nWeek 
) 
4548                 case 1: which 
= _T("first"); break; 
4549                 case 2: which 
= _T("second"); break; 
4550                 case 3: which 
= _T("third"); break; 
4551                 case 4: which 
= _T("fourth"); break; 
4552                 case 5: which 
= _T("fifth"); break; 
4554                 case -1: which 
= _T("last"); break; 
4559                 which 
+= _T(" from end"); 
4562             s
.Printf(_T("The %s %s of %s in %d"), 
4564                      wxDateTime::GetWeekDayName(wday
).c_str(), 
4565                      wxDateTime::GetMonthName(month
).c_str(), 
4572     // the array data was generated by the following python program 
4574 from DateTime import * 
4575 from whrandom import * 
4576 from string import * 
4578 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] 
4579 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ] 
4581 week = DateTimeDelta(7) 
4584     year = randint(1900, 2100) 
4585     month = randint(1, 12) 
4586     day = randint(1, 28) 
4587     dt = DateTime(year, month, day) 
4588     wday = dt.day_of_week 
4590     countFromEnd = choice([-1, 1]) 
4593     while dt.month is month: 
4594         dt = dt - countFromEnd * week 
4595         weekNum = weekNum + countFromEnd 
4597     data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] } 
4599     print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\ 
4600           "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data 
4603     static const WeekDateTestData weekDatesTestData
[] = 
4605         { { 20, wxDateTime::Mar
, 2045 },  3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 }, 
4606         { {  5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 }, 
4607         { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 }, 
4608         { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 }, 
4609         { {  4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 }, 
4610         { {  2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 }, 
4611         { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 }, 
4612         { {  5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 }, 
4613         { { 11, wxDateTime::Aug
, 1900 },  2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 }, 
4614         { { 14, wxDateTime::Feb
, 1945 },  2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 }, 
4615         { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 }, 
4616         { {  9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 }, 
4617         { { 20, wxDateTime::Jun
, 1927 },  3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 }, 
4618         { {  2, wxDateTime::Aug
, 2000 },  1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 }, 
4619         { { 20, wxDateTime::Apr
, 2044 },  3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 }, 
4620         { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 }, 
4621         { { 25, wxDateTime::Jul
, 2069 },  4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 }, 
4622         { {  3, wxDateTime::Apr
, 1925 },  1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 }, 
4623         { { 21, wxDateTime::Mar
, 2093 },  3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 }, 
4624         { {  3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 }, 
4627     static const wxChar 
*fmt 
= _T("%d-%b-%Y"); 
4630     for ( n 
= 0; n 
< WXSIZEOF(weekDatesTestData
); n
++ ) 
4632         const WeekDateTestData
& wd 
= weekDatesTestData
[n
]; 
4634         dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
); 
4636         wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str()); 
4638         const Date
& d 
= wd
.date
; 
4639         if ( d
.SameDay(dt
.GetTm()) ) 
4641             wxPuts(_T(" (ok)")); 
4645             dt
.Set(d
.day
, d
.month
, d
.year
); 
4647             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str()); 
4652 // test the computation of (ISO) week numbers 
4653 static void TestTimeWNumber() 
4655     wxPuts(_T("\n*** wxDateTime week number test ***")); 
4657     struct WeekNumberTestData
 
4659         Date date
;                          // the date 
4660         wxDateTime::wxDateTime_t week
;      // the week number in the year 
4661         wxDateTime::wxDateTime_t wmon
;      // the week number in the month 
4662         wxDateTime::wxDateTime_t wmon2
;     // same but week starts with Sun 
4663         wxDateTime::wxDateTime_t dnum
;      // day number in the year 
4666     // data generated with the following python script: 
4668 from DateTime import * 
4669 from whrandom import * 
4670 from string import * 
4672 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] 
4673 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ] 
4675 def GetMonthWeek(dt): 
4676     weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1 
4677     if weekNumMonth < 0: 
4678         weekNumMonth = weekNumMonth + 53 
4681 def GetLastSundayBefore(dt): 
4682     if dt.iso_week[2] == 7: 
4685         return dt - DateTimeDelta(dt.iso_week[2]) 
4688     year = randint(1900, 2100) 
4689     month = randint(1, 12) 
4690     day = randint(1, 28) 
4691     dt = DateTime(year, month, day) 
4692     dayNum = dt.day_of_year 
4693     weekNum = dt.iso_week[1] 
4694     weekNumMonth = GetMonthWeek(dt) 
4697     dtSunday = GetLastSundayBefore(dt) 
4699     while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)): 
4700         weekNumMonth2 = weekNumMonth2 + 1 
4701         dtSunday = dtSunday - DateTimeDelta(7) 
4703     data = { 'day': rjust(`day`, 2), \ 
4704              'month': monthNames[month - 1], \ 
4706              'weekNum': rjust(`weekNum`, 2), \ 
4707              'weekNumMonth': weekNumMonth, \ 
4708              'weekNumMonth2': weekNumMonth2, \ 
4709              'dayNum': rjust(`dayNum`, 3) } 
4711     print "        { { %(day)s, "\ 
4712           "wxDateTime::%(month)s, "\ 
4715           "%(weekNumMonth)s, "\ 
4716           "%(weekNumMonth2)s, "\ 
4717           "%(dayNum)s }," % data 
4720     static const WeekNumberTestData weekNumberTestDates
[] = 
4722         { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 }, 
4723         { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 }, 
4724         { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 }, 
4725         { {  1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 }, 
4726         { {  8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 }, 
4727         { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4,  81 }, 
4728         { {  7, wxDateTime::Jan
, 1965 },  1, 2, 2,   7 }, 
4729         { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 }, 
4730         { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 }, 
4731         { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 }, 
4732         { {  2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 }, 
4733         { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 }, 
4734         { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 }, 
4735         { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 }, 
4736         { {  3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 }, 
4737         { { 23, wxDateTime::Feb
, 1940 },  8, 4, 4,  54 }, 
4738         { {  2, wxDateTime::Jan
, 1987 },  1, 1, 1,   2 }, 
4739         { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 }, 
4740         { {  2, wxDateTime::Feb
, 2063 },  5, 1, 1,  33 }, 
4741         { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 }, 
4744     for ( size_t n 
= 0; n 
< WXSIZEOF(weekNumberTestDates
); n
++ ) 
4746         const WeekNumberTestData
& wn 
= weekNumberTestDates
[n
]; 
4747         const Date
& d 
= wn
.date
; 
4749         wxDateTime dt 
= d
.DT(); 
4751         wxDateTime::wxDateTime_t
 
4752             week 
= dt
.GetWeekOfYear(wxDateTime::Monday_First
), 
4753             wmon 
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
), 
4754             wmon2 
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
), 
4755             dnum 
= dt
.GetDayOfYear(); 
4757         wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
); 
4758         if ( dnum 
== wn
.dnum 
) 
4760             wxPrintf(_T(" (ok)")); 
4764             wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
); 
4767         wxPrintf(_T(", week in month = %d"), wmon
); 
4768         if ( wmon 
!= wn
.wmon 
) 
4770             wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
); 
4773         wxPrintf(_T(" or %d"), wmon2
); 
4774         if ( wmon2 
== wn
.wmon2 
) 
4776             wxPrintf(_T(" (ok)")); 
4780             wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
); 
4783         wxPrintf(_T(", week in year = %d"), week
); 
4784         if ( week 
!= wn
.week 
) 
4786             wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
); 
4789         wxPutchar(_T('\n')); 
4791         wxDateTime 
dt2(1, wxDateTime::Jan
, d
.year
); 
4792         dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay()); 
4796             d2
.Init(dt2
.GetTm()); 
4797             wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"), 
4798                      d2
.FormatDate().c_str()); 
4803 // test DST calculations 
4804 static void TestTimeDST() 
4806     wxPuts(_T("\n*** wxDateTime DST test ***")); 
4808     wxPrintf(_T("DST is%s in effect now.\n\n"), 
4809              wxDateTime::Now().IsDST() ? wxEmptyString 
: _T(" not")); 
4811     // taken from http://www.energy.ca.gov/daylightsaving.html 
4812     static const Date datesDST
[2][2004 - 1900 + 1] = 
4815             { 1, wxDateTime::Apr
, 1990 }, 
4816             { 7, wxDateTime::Apr
, 1991 }, 
4817             { 5, wxDateTime::Apr
, 1992 }, 
4818             { 4, wxDateTime::Apr
, 1993 }, 
4819             { 3, wxDateTime::Apr
, 1994 }, 
4820             { 2, wxDateTime::Apr
, 1995 }, 
4821             { 7, wxDateTime::Apr
, 1996 }, 
4822             { 6, wxDateTime::Apr
, 1997 }, 
4823             { 5, wxDateTime::Apr
, 1998 }, 
4824             { 4, wxDateTime::Apr
, 1999 }, 
4825             { 2, wxDateTime::Apr
, 2000 }, 
4826             { 1, wxDateTime::Apr
, 2001 }, 
4827             { 7, wxDateTime::Apr
, 2002 }, 
4828             { 6, wxDateTime::Apr
, 2003 }, 
4829             { 4, wxDateTime::Apr
, 2004 }, 
4832             { 28, wxDateTime::Oct
, 1990 }, 
4833             { 27, wxDateTime::Oct
, 1991 }, 
4834             { 25, wxDateTime::Oct
, 1992 }, 
4835             { 31, wxDateTime::Oct
, 1993 }, 
4836             { 30, wxDateTime::Oct
, 1994 }, 
4837             { 29, wxDateTime::Oct
, 1995 }, 
4838             { 27, wxDateTime::Oct
, 1996 }, 
4839             { 26, wxDateTime::Oct
, 1997 }, 
4840             { 25, wxDateTime::Oct
, 1998 }, 
4841             { 31, wxDateTime::Oct
, 1999 }, 
4842             { 29, wxDateTime::Oct
, 2000 }, 
4843             { 28, wxDateTime::Oct
, 2001 }, 
4844             { 27, wxDateTime::Oct
, 2002 }, 
4845             { 26, wxDateTime::Oct
, 2003 }, 
4846             { 31, wxDateTime::Oct
, 2004 }, 
4851     for ( year 
= 1990; year 
< 2005; year
++ ) 
4853         wxDateTime dtBegin 
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
), 
4854                    dtEnd 
= wxDateTime::GetEndDST(year
, wxDateTime::USA
); 
4856         wxPrintf(_T("DST period in the US for year %d: from %s to %s"), 
4857                  year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str()); 
4859         size_t n 
= year 
- 1990; 
4860         const Date
& dBegin 
= datesDST
[0][n
]; 
4861         const Date
& dEnd 
= datesDST
[1][n
]; 
4863         if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) ) 
4865             wxPuts(_T(" (ok)")); 
4869             wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"), 
4870                      wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
, 
4871                      wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
); 
4875     wxPuts(wxEmptyString
); 
4877     for ( year 
= 1990; year 
< 2005; year
++ ) 
4879         wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"), 
4881                  wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(), 
4882                  wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str()); 
4886 // test wxDateTime -> text conversion 
4887 static void TestTimeFormat() 
4889     wxPuts(_T("\n*** wxDateTime formatting test ***")); 
4891     // some information may be lost during conversion, so store what kind 
4892     // of info should we recover after a round trip 
4895         CompareNone
,        // don't try comparing 
4896         CompareBoth
,        // dates and times should be identical 
4897         CompareDate
,        // dates only 
4898         CompareTime         
// time only 
4903         CompareKind compareKind
; 
4904         const wxChar 
*format
; 
4905     } formatTestFormats
[] = 
4907        { CompareBoth
, _T("---> %c") }, 
4908        { CompareDate
, _T("Date is %A, %d of %B, in year %Y") }, 
4909        { CompareBoth
, _T("Date is %x, time is %X") }, 
4910        { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") }, 
4911        { CompareNone
, _T("The day of year: %j, the week of year: %W") }, 
4912        { CompareDate
, _T("ISO date without separators: %Y%m%d") }, 
4915     static const Date formatTestDates
[] = 
4917         { 29, wxDateTime::May
, 1976, 18, 30, 00 }, 
4918         { 31, wxDateTime::Dec
, 1999, 23, 30, 00 }, 
4920         // this test can't work for other centuries because it uses two digit 
4921         // years in formats, so don't even try it 
4922         { 29, wxDateTime::May
, 2076, 18, 30, 00 }, 
4923         { 29, wxDateTime::Feb
, 2400, 02, 15, 25 }, 
4924         { 01, wxDateTime::Jan
,  -52, 03, 16, 47 }, 
4928     // an extra test (as it doesn't depend on date, don't do it in the loop) 
4929     wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str()); 
4931     for ( size_t d 
= 0; d 
< WXSIZEOF(formatTestDates
) + 1; d
++ ) 
4933         wxPuts(wxEmptyString
); 
4935         wxDateTime dt 
= d 
== 0 ? wxDateTime::Now() : formatTestDates
[d 
- 1].DT(); 
4936         for ( size_t n 
= 0; n 
< WXSIZEOF(formatTestFormats
); n
++ ) 
4938             wxString s 
= dt
.Format(formatTestFormats
[n
].format
); 
4939             wxPrintf(_T("%s"), s
.c_str()); 
4941             // what can we recover? 
4942             int kind 
= formatTestFormats
[n
].compareKind
; 
4946             const wxChar 
*result 
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
); 
4949                 // converion failed - should it have? 
4950                 if ( kind 
== CompareNone 
) 
4951                     wxPuts(_T(" (ok)")); 
4953                     wxPuts(_T(" (ERROR: conversion back failed)")); 
4957                 // should have parsed the entire string 
4958                 wxPuts(_T(" (ERROR: conversion back stopped too soon)")); 
4962                 bool equal 
= false; // suppress compilaer warning 
4970                         equal 
= dt
.IsSameDate(dt2
); 
4974                         equal 
= dt
.IsSameTime(dt2
); 
4980                     wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"), 
4981                            dt2
.Format().c_str(), dt
.Format().c_str()); 
4985                     wxPuts(_T(" (ok)")); 
4992 // test text -> wxDateTime conversion 
4993 static void TestTimeParse() 
4995     wxPuts(_T("\n*** wxDateTime parse test ***")); 
4997     struct ParseTestData
 
4999         const wxChar 
*format
; 
5004     static const ParseTestData parseTestDates
[] = 
5006         { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true }, 
5007         { _T("Wed, 1 Dec 1999 05:17:20 +0300"),  {  1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true }, 
5010     for ( size_t n 
= 0; n 
< WXSIZEOF(parseTestDates
); n
++ ) 
5012         const wxChar 
*format 
= parseTestDates
[n
].format
; 
5014         wxPrintf(_T("%s => "), format
); 
5017         if ( dt
.ParseRfc822Date(format
) ) 
5019             wxPrintf(_T("%s "), dt
.Format().c_str()); 
5021             if ( parseTestDates
[n
].good 
) 
5023                 wxDateTime dtReal 
= parseTestDates
[n
].date
.DT(); 
5030                     wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str()); 
5035                 wxPuts(_T("(ERROR: bad format)")); 
5040             wxPrintf(_T("bad format (%s)\n"), 
5041                    parseTestDates
[n
].good 
? "ERROR" : "ok"); 
5046 static void TestDateTimeInteractive() 
5048     wxPuts(_T("\n*** interactive wxDateTime tests ***")); 
5054         wxPrintf(_T("Enter a date: ")); 
5055         if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) ) 
5058         // kill the last '\n' 
5059         buf
[wxStrlen(buf
) - 1] = 0; 
5062         const wxChar 
*p 
= dt
.ParseDate(buf
); 
5065             wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
); 
5071             wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p 
- buf
); 
5074         wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"), 
5075                  dt
.Format(_T("%b %d, %Y")).c_str(), 
5077                  dt
.GetWeekOfMonth(wxDateTime::Monday_First
), 
5078                  dt
.GetWeekOfMonth(wxDateTime::Sunday_First
), 
5079                  dt
.GetWeekOfYear(wxDateTime::Monday_First
)); 
5082     wxPuts(_T("\n*** done ***")); 
5085 static void TestTimeMS() 
5087     wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***")); 
5089     wxDateTime dt1 
= wxDateTime::Now(), 
5090                dt2 
= wxDateTime::UNow(); 
5092     wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str()); 
5093     wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str()); 
5094     wxPrintf(_T("Dummy loop: ")); 
5095     for ( int i 
= 0; i 
< 6000; i
++ ) 
5097         //for ( int j = 0; j < 10; j++ ) 
5100             s
.Printf(_T("%g"), sqrt(i
)); 
5106     wxPuts(_T(", done")); 
5109     dt2 
= wxDateTime::UNow(); 
5110     wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str()); 
5112     wxPrintf(_T("Loop executed in %s ms\n"), (dt2 
- dt1
).Format(_T("%l")).c_str()); 
5114     wxPuts(_T("\n*** done ***")); 
5117 static void TestTimeArithmetics() 
5119     wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***")); 
5121     static const struct ArithmData
 
5123         ArithmData(const wxDateSpan
& sp
, const wxChar 
*nam
) 
5124             : span(sp
), name(nam
) { } 
5128     } testArithmData
[] = 
5130         ArithmData(wxDateSpan::Day(), _T("day")), 
5131         ArithmData(wxDateSpan::Week(), _T("week")), 
5132         ArithmData(wxDateSpan::Month(), _T("month")), 
5133         ArithmData(wxDateSpan::Year(), _T("year")), 
5134         ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")), 
5137     wxDateTime 
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
; 
5139     for ( size_t n 
= 0; n 
< WXSIZEOF(testArithmData
); n
++ ) 
5141         wxDateSpan span 
= testArithmData
[n
].span
; 
5145         const wxChar 
*name 
= testArithmData
[n
].name
; 
5146         wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"), 
5147                dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(), 
5148                dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str()); 
5150         wxPrintf(_T("Going back: %s"), (dt1 
- span
).FormatISODate().c_str()); 
5151         if ( dt1 
- span 
== dt 
) 
5153             wxPuts(_T(" (ok)")); 
5157             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str()); 
5160         wxPrintf(_T("Going forward: %s"), (dt2 
+ span
).FormatISODate().c_str()); 
5161         if ( dt2 
+ span 
== dt 
) 
5163             wxPuts(_T(" (ok)")); 
5167             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str()); 
5170         wxPrintf(_T("Double increment: %s"), (dt2 
+ 2*span
).FormatISODate().c_str()); 
5171         if ( dt2 
+ 2*span 
== dt1 
) 
5173             wxPuts(_T(" (ok)")); 
5177             wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str()); 
5180         wxPuts(wxEmptyString
); 
5184 static void TestTimeHolidays() 
5186     wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n")); 
5188     wxDateTime::Tm tm 
= wxDateTime(29, wxDateTime::May
, 2000).GetTm(); 
5189     wxDateTime 
dtStart(1, tm
.mon
, tm
.year
), 
5190                dtEnd 
= dtStart
.GetLastMonthDay(); 
5192     wxDateTimeArray hol
; 
5193     wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
); 
5195     const wxChar 
*format 
= _T("%d-%b-%Y (%a)"); 
5197     wxPrintf(_T("All holidays between %s and %s:\n"), 
5198            dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str()); 
5200     size_t count 
= hol
.GetCount(); 
5201     for ( size_t n 
= 0; n 
< count
; n
++ ) 
5203         wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str()); 
5206     wxPuts(wxEmptyString
); 
5209 static void TestTimeZoneBug() 
5211     wxPuts(_T("\n*** testing for DST/timezone bug ***\n")); 
5213     wxDateTime date 
= wxDateTime(1, wxDateTime::Mar
, 2000); 
5214     for ( int i 
= 0; i 
< 31; i
++ ) 
5216         wxPrintf(_T("Date %s: week day %s.\n"), 
5217                date
.Format(_T("%d-%m-%Y")).c_str(), 
5218                date
.GetWeekDayName(date
.GetWeekDay()).c_str()); 
5220         date 
+= wxDateSpan::Day(); 
5223     wxPuts(wxEmptyString
); 
5226 static void TestTimeSpanFormat() 
5228     wxPuts(_T("\n*** wxTimeSpan tests ***")); 
5230     static const wxChar 
*formats
[] = 
5232         _T("(default) %H:%M:%S"), 
5233         _T("%E weeks and %D days"), 
5234         _T("%l milliseconds"), 
5235         _T("(with ms) %H:%M:%S:%l"), 
5236         _T("100%% of minutes is %M"),       // test "%%" 
5237         _T("%D days and %H hours"), 
5238         _T("or also %S seconds"), 
5241     wxTimeSpan 
ts1(1, 2, 3, 4), 
5243     for ( size_t n 
= 0; n 
< WXSIZEOF(formats
); n
++ ) 
5245         wxPrintf(_T("ts1 = %s\tts2 = %s\n"), 
5246                ts1
.Format(formats
[n
]).c_str(), 
5247                ts2
.Format(formats
[n
]).c_str()); 
5250     wxPuts(wxEmptyString
); 
5253 #endif // TEST_DATETIME 
5255 // ---------------------------------------------------------------------------- 
5256 // wxTextInput/OutputStream 
5257 // ---------------------------------------------------------------------------- 
5259 #ifdef TEST_TEXTSTREAM 
5261 #include "wx/txtstrm.h" 
5262 #include "wx/wfstream.h" 
5264 static void TestTextInputStream() 
5266     wxPuts(_T("\n*** wxTextInputStream test ***")); 
5268     wxString filename 
= _T("testdata.fc"); 
5269     wxFileInputStream 
fsIn(filename
); 
5272         wxPuts(_T("ERROR: couldn't open file.")); 
5276         wxTextInputStream 
tis(fsIn
); 
5281             const wxString s 
= tis
.ReadLine(); 
5283             // line could be non empty if the last line of the file isn't 
5284             // terminated with EOL 
5285             if ( fsIn
.Eof() && s
.empty() ) 
5288             wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str()); 
5293 #endif // TEST_TEXTSTREAM 
5295 // ---------------------------------------------------------------------------- 
5297 // ---------------------------------------------------------------------------- 
5301 #include "wx/thread.h" 
5303 static size_t gs_counter 
= (size_t)-1; 
5304 static wxCriticalSection gs_critsect
; 
5305 static wxSemaphore gs_cond
; 
5307 class MyJoinableThread 
: public wxThread
 
5310     MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
) 
5311         { m_n 
= n
; Create(); } 
5313     // thread execution starts here 
5314     virtual ExitCode 
Entry(); 
5320 wxThread::ExitCode 
MyJoinableThread::Entry() 
5322     unsigned long res 
= 1; 
5323     for ( size_t n 
= 1; n 
< m_n
; n
++ ) 
5327         // it's a loooong calculation :-) 
5331     return (ExitCode
)res
; 
5334 class MyDetachedThread 
: public wxThread
 
5337     MyDetachedThread(size_t n
, wxChar ch
) 
5341         m_cancelled 
= false; 
5346     // thread execution starts here 
5347     virtual ExitCode 
Entry(); 
5350     virtual void OnExit(); 
5353     size_t m_n
; // number of characters to write 
5354     wxChar m_ch
;  // character to write 
5356     bool m_cancelled
;   // false if we exit normally 
5359 wxThread::ExitCode 
MyDetachedThread::Entry() 
5362         wxCriticalSectionLocker 
lock(gs_critsect
); 
5363         if ( gs_counter 
== (size_t)-1 ) 
5369     for ( size_t n 
= 0; n 
< m_n
; n
++ ) 
5371         if ( TestDestroy() ) 
5381         wxThread::Sleep(100); 
5387 void MyDetachedThread::OnExit() 
5389     wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId()); 
5391     wxCriticalSectionLocker 
lock(gs_critsect
); 
5392     if ( !--gs_counter 
&& !m_cancelled 
) 
5396 static void TestDetachedThreads() 
5398     wxPuts(_T("\n*** Testing detached threads ***")); 
5400     static const size_t nThreads 
= 3; 
5401     MyDetachedThread 
*threads
[nThreads
]; 
5403     for ( n 
= 0; n 
< nThreads
; n
++ ) 
5405         threads
[n
] = new MyDetachedThread(10, 'A' + n
); 
5408     threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
); 
5409     threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
); 
5411     for ( n 
= 0; n 
< nThreads
; n
++ ) 
5416     // wait until all threads terminate 
5419     wxPuts(wxEmptyString
); 
5422 static void TestJoinableThreads() 
5424     wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***")); 
5426     // calc 10! in the background 
5427     MyJoinableThread 
thread(10); 
5430     wxPrintf(_T("\nThread terminated with exit code %lu.\n"), 
5431              (unsigned long)thread
.Wait()); 
5434 static void TestThreadSuspend() 
5436     wxPuts(_T("\n*** Testing thread suspend/resume functions ***")); 
5438     MyDetachedThread 
*thread 
= new MyDetachedThread(15, 'X'); 
5442     // this is for this demo only, in a real life program we'd use another 
5443     // condition variable which would be signaled from wxThread::Entry() to 
5444     // tell us that the thread really started running - but here just wait a 
5445     // bit and hope that it will be enough (the problem is, of course, that 
5446     // the thread might still not run when we call Pause() which will result 
5448     wxThread::Sleep(300); 
5450     for ( size_t n 
= 0; n 
< 3; n
++ ) 
5454         wxPuts(_T("\nThread suspended")); 
5457             // don't sleep but resume immediately the first time 
5458             wxThread::Sleep(300); 
5460         wxPuts(_T("Going to resume the thread")); 
5465     wxPuts(_T("Waiting until it terminates now")); 
5467     // wait until the thread terminates 
5470     wxPuts(wxEmptyString
); 
5473 static void TestThreadDelete() 
5475     // As above, using Sleep() is only for testing here - we must use some 
5476     // synchronisation object instead to ensure that the thread is still 
5477     // running when we delete it - deleting a detached thread which already 
5478     // terminated will lead to a crash! 
5480     wxPuts(_T("\n*** Testing thread delete function ***")); 
5482     MyDetachedThread 
*thread0 
= new MyDetachedThread(30, 'W'); 
5486     wxPuts(_T("\nDeleted a thread which didn't start to run yet.")); 
5488     MyDetachedThread 
*thread1 
= new MyDetachedThread(30, 'Y'); 
5492     wxThread::Sleep(300); 
5496     wxPuts(_T("\nDeleted a running thread.")); 
5498     MyDetachedThread 
*thread2 
= new MyDetachedThread(30, 'Z'); 
5502     wxThread::Sleep(300); 
5508     wxPuts(_T("\nDeleted a sleeping thread.")); 
5510     MyJoinableThread 
thread3(20); 
5515     wxPuts(_T("\nDeleted a joinable thread.")); 
5517     MyJoinableThread 
thread4(2); 
5520     wxThread::Sleep(300); 
5524     wxPuts(_T("\nDeleted a joinable thread which already terminated.")); 
5526     wxPuts(wxEmptyString
); 
5529 class MyWaitingThread 
: public wxThread
 
5532     MyWaitingThread( wxMutex 
*mutex
, wxCondition 
*condition 
) 
5535         m_condition 
= condition
; 
5540     virtual ExitCode 
Entry() 
5542         wxPrintf(_T("Thread %lu has started running.\n"), GetId()); 
5547         wxPrintf(_T("Thread %lu starts to wait...\n"), GetId()); 
5551         m_condition
->Wait(); 
5554         wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId()); 
5562     wxCondition 
*m_condition
; 
5565 static void TestThreadConditions() 
5568     wxCondition 
condition(mutex
); 
5570     // otherwise its difficult to understand which log messages pertain to 
5572     //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"), 
5573     //           condition.GetId(), gs_cond.GetId()); 
5575     // create and launch threads 
5576     MyWaitingThread 
*threads
[10]; 
5579     for ( n 
= 0; n 
< WXSIZEOF(threads
); n
++ ) 
5581         threads
[n
] = new MyWaitingThread( &mutex
, &condition 
); 
5584     for ( n 
= 0; n 
< WXSIZEOF(threads
); n
++ ) 
5589     // wait until all threads run 
5590     wxPuts(_T("Main thread is waiting for the other threads to start")); 
5593     size_t nRunning 
= 0; 
5594     while ( nRunning 
< WXSIZEOF(threads
) ) 
5600         wxPrintf(_T("Main thread: %u already running\n"), nRunning
); 
5604     wxPuts(_T("Main thread: all threads started up.")); 
5607     wxThread::Sleep(500); 
5610     // now wake one of them up 
5611     wxPrintf(_T("Main thread: about to signal the condition.\n")); 
5616     wxThread::Sleep(200); 
5618     // wake all the (remaining) threads up, so that they can exit 
5619     wxPrintf(_T("Main thread: about to broadcast the condition.\n")); 
5621     condition
.Broadcast(); 
5623     // give them time to terminate (dirty!) 
5624     wxThread::Sleep(500); 
5627 #include "wx/utils.h" 
5629 class MyExecThread 
: public wxThread
 
5632     MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
), 
5638     virtual ExitCode 
Entry() 
5640         return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
); 
5647 static void TestThreadExec() 
5649     wxPuts(_T("*** Testing wxExecute interaction with threads ***\n")); 
5651     MyExecThread 
thread(_T("true")); 
5654     wxPrintf(_T("Main program exit code: %ld.\n"), 
5655              wxExecute(_T("false"), wxEXEC_SYNC
)); 
5657     wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait()); 
5661 #include "wx/datetime.h" 
5663 class MySemaphoreThread 
: public wxThread
 
5666     MySemaphoreThread(int i
, wxSemaphore 
*sem
) 
5667         : wxThread(wxTHREAD_JOINABLE
), 
5674     virtual ExitCode 
Entry() 
5676         wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"), 
5677                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5681         wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"), 
5682                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5686         wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"), 
5687                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5699 WX_DEFINE_ARRAY_PTR(wxThread 
*, ArrayThreads
); 
5701 static void TestSemaphore() 
5703     wxPuts(_T("*** Testing wxSemaphore class. ***")); 
5705     static const int SEM_LIMIT 
= 3; 
5707     wxSemaphore 
sem(SEM_LIMIT
, SEM_LIMIT
); 
5708     ArrayThreads threads
; 
5710     for ( int i 
= 0; i 
< 3*SEM_LIMIT
; i
++ ) 
5712         threads
.Add(new MySemaphoreThread(i
, &sem
)); 
5713         threads
.Last()->Run(); 
5716     for ( size_t n 
= 0; n 
< threads
.GetCount(); n
++ ) 
5723 #endif // TEST_THREADS 
5725 // ---------------------------------------------------------------------------- 
5727 // ---------------------------------------------------------------------------- 
5729 #ifdef TEST_SNGLINST 
5730     #include "wx/snglinst.h" 
5731 #endif // TEST_SNGLINST 
5733 int main(int argc
, char **argv
) 
5735     wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program"); 
5737     wxInitializer initializer
; 
5740         fprintf(stderr
, "Failed to initialize the wxWindows library, aborting."); 
5745 #ifdef TEST_SNGLINST 
5746     wxSingleInstanceChecker checker
; 
5747     if ( checker
.Create(_T(".wxconsole.lock")) ) 
5749         if ( checker
.IsAnotherRunning() ) 
5751             wxPrintf(_T("Another instance of the program is running, exiting.\n")); 
5756         // wait some time to give time to launch another instance 
5757         wxPrintf(_T("Press \"Enter\" to continue...")); 
5760     else // failed to create 
5762         wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n")); 
5764 #endif // TEST_SNGLINST 
5768 #endif // TEST_CHARSET 
5771     TestCmdLineConvert(); 
5773 #if wxUSE_CMDLINE_PARSER 
5774     static const wxCmdLineEntryDesc cmdLineDesc
[] = 
5776         { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"), 
5777             wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP 
}, 
5778         { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") }, 
5779         { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"),   _T("be quiet") }, 
5781         { wxCMD_LINE_OPTION
, _T("o"), _T("output"),  _T("output file") }, 
5782         { wxCMD_LINE_OPTION
, _T("i"), _T("input"),   _T("input dir") }, 
5783         { wxCMD_LINE_OPTION
, _T("s"), _T("size"),    _T("output block size"), 
5784             wxCMD_LINE_VAL_NUMBER 
}, 
5785         { wxCMD_LINE_OPTION
, _T("d"), _T("date"),    _T("output file date"), 
5786             wxCMD_LINE_VAL_DATE 
}, 
5788         { wxCMD_LINE_PARAM
,  NULL
, NULL
, _T("input file"), 
5789             wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE 
}, 
5795     wxChar 
**wargv 
= new wxChar 
*[argc 
+ 1]; 
5800         for (n 
= 0; n 
< argc
; n
++ ) 
5802             wxMB2WXbuf warg 
= wxConvertMB2WX(argv
[n
]); 
5803             wargv
[n
] = wxStrdup(warg
); 
5810 #endif // wxUSE_UNICODE 
5812     wxCmdLineParser 
parser(cmdLineDesc
, argc
, argv
); 
5816         for ( int n 
= 0; n 
< argc
; n
++ ) 
5821 #endif // wxUSE_UNICODE 
5823     parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"), 
5824                      wxCMD_LINE_VAL_STRING
, 
5825                      wxCMD_LINE_OPTION_MANDATORY 
| wxCMD_LINE_NEEDS_SEPARATOR
); 
5827     switch ( parser
.Parse() ) 
5830             wxLogMessage(_T("Help was given, terminating.")); 
5834             ShowCmdLine(parser
); 
5838             wxLogMessage(_T("Syntax error detected, aborting.")); 
5841 #endif // wxUSE_CMDLINE_PARSER 
5843 #endif // TEST_CMDLINE 
5853 #ifdef TEST_DLLLOADER 
5855 #endif // TEST_DLLLOADER 
5859 #endif // TEST_ENVIRON 
5863 #endif // TEST_EXECUTE 
5865 #ifdef TEST_FILECONF 
5867 #endif // TEST_FILECONF 
5876 #endif // TEST_LOCALE 
5879     wxPuts(_T("*** Testing wxLog ***")); 
5882     for ( size_t n 
= 0; n 
< 8000; n
++ ) 
5884         s 
<< (wxChar
)(_T('A') + (n 
% 26)); 
5887     wxLogWarning(_T("The length of the string is %lu"), 
5888                  (unsigned long)s
.length()); 
5891     msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str()); 
5893     // this one shouldn't be truncated 
5896     // but this one will because log functions use fixed size buffer 
5897     // (note that it doesn't need '\n' at the end neither - will be added 
5899     wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str()); 
5908 #ifdef TEST_FILENAME 
5909     TestFileNameConstruction(); 
5910     TestFileNameMakeRelative(); 
5911     TestFileNameMakeAbsolute(); 
5912     TestFileNameSplit(); 
5915     TestFileNameDirManip(); 
5916     TestFileNameComparison(); 
5917     TestFileNameOperations(); 
5918 #endif // TEST_FILENAME 
5920 #ifdef TEST_FILETIME 
5925 #endif // TEST_FILETIME 
5928     wxLog::AddTraceMask(FTP_TRACE_MASK
); 
5929     if ( TestFtpConnect() ) 
5939         #if TEST_INTERACTIVE 
5940             TestFtpInteractive(); 
5943     //else: connecting to the FTP server failed 
5956 #endif // TEST_HASHMAP 
5960 #endif // TEST_HASHSET 
5963     wxLog::AddTraceMask(_T("mime")); 
5967         TestMimeAssociate(); 
5972 #ifdef TEST_INFO_FUNCTIONS 
5977         #if TEST_INTERACTIVE 
5981 #endif // TEST_INFO_FUNCTIONS 
5983 #ifdef TEST_PATHLIST 
5985 #endif // TEST_PATHLIST 
5993 #endif // TEST_PRINTF 
6000 #endif // TEST_REGCONF 
6002 #if defined TEST_REGEX && TEST_INTERACTIVE 
6003     TestRegExInteractive(); 
6004 #endif // defined TEST_REGEX && TEST_INTERACTIVE 
6006 #ifdef TEST_REGISTRY 
6008     TestRegistryAssociation(); 
6009 #endif // TEST_REGISTRY 
6014 #endif // TEST_SOCKETS 
6021 #endif // TEST_STREAMS 
6023 #ifdef TEST_TEXTSTREAM 
6024     TestTextInputStream(); 
6025 #endif // TEST_TEXTSTREAM 
6028     int nCPUs 
= wxThread::GetCPUCount(); 
6029     wxPrintf(_T("This system has %d CPUs\n"), nCPUs
); 
6031         wxThread::SetConcurrency(nCPUs
); 
6033         TestJoinableThreads(); 
6036         TestJoinableThreads(); 
6037         TestDetachedThreads(); 
6038         TestThreadSuspend(); 
6040         TestThreadConditions(); 
6044 #endif // TEST_THREADS 
6048 #endif // TEST_TIMER 
6050 #ifdef TEST_DATETIME 
6062         TestTimeArithmetics(); 
6065         TestTimeSpanFormat(); 
6071     #if TEST_INTERACTIVE 
6072         TestDateTimeInteractive(); 
6074 #endif // TEST_DATETIME 
6076 #ifdef TEST_SCOPEGUARD 
6081     wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z...")); 
6083 #endif // TEST_USLEEP 
6088 #endif // TEST_VCARD 
6092 #endif // TEST_VOLUME 
6095     TestUnicodeTextFileRead(); 
6097         TestUnicodeToFromAscii(); 
6099 #endif // TEST_UNICODE 
6103     TestEncodingConverter(); 
6104 #endif // TEST_WCHAR 
6107     TestZipStreamRead(); 
6108     TestZipFileSystem(); 
6112     TestZlibStreamWrite(); 
6113     TestZlibStreamRead();