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 // ---------------------------------------------------------------------------- 
  23     #error "This sample can't be compiled in GUI mode." 
  28 #include "wx/string.h" 
  33 // without this pragma, the stupid compiler precompiles #defines below so that 
  34 // changing them doesn't "take place" later! 
  39 // ---------------------------------------------------------------------------- 
  40 // conditional compilation 
  41 // ---------------------------------------------------------------------------- 
  44    A note about all these conditional compilation macros: this file is used 
  45    both as a test suite for various non-GUI wxWindows classes and as a 
  46    scratchpad for quick tests. So there are two compilation modes: if you 
  47    define TEST_ALL all tests are run, otherwise you may enable the individual 
  48    tests individually in the "#else" branch below. 
  51 // what to test (in alphabetic order)? uncomment the line below to do all tests 
  59     #define TEST_DLLLOADER 
  70     #define TEST_INFO_FUNCTIONS 
  82     #define TEST_SCOPEGUARD 
  87     #define TEST_TEXTSTREAM 
  91     // #define TEST_VCARD            -- don't enable this (VZ) 
  98     static const bool TEST_ALL 
= true; 
 102     static const bool TEST_ALL 
= false; 
 105 // some tests are interactive, define this to run them 
 106 #ifdef TEST_INTERACTIVE 
 107     #undef TEST_INTERACTIVE 
 109     static const bool TEST_INTERACTIVE 
= true; 
 111     static const bool TEST_INTERACTIVE 
= false; 
 114 // ---------------------------------------------------------------------------- 
 115 // test class for container objects 
 116 // ---------------------------------------------------------------------------- 
 118 #if defined(TEST_ARRAYS) || defined(TEST_LIST) 
 120 class Bar 
// Foo is already taken in the hash test 
 123     Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; } 
 124     Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; } 
 125    ~Bar() { ms_bars
--; } 
 127    static size_t GetNumber() { return ms_bars
; } 
 129    const wxChar 
*GetName() const { return m_name
; } 
 134    static size_t ms_bars
; 
 137 size_t Bar::ms_bars 
= 0; 
 139 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST) 
 141 // ============================================================================ 
 143 // ============================================================================ 
 145 // ---------------------------------------------------------------------------- 
 147 // ---------------------------------------------------------------------------- 
 149 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS) 
 151 // replace TABs with \t and CRs with \n 
 152 static wxString 
MakePrintable(const wxChar 
*s
) 
 155     (void)str
.Replace(_T("\t"), _T("\\t")); 
 156     (void)str
.Replace(_T("\n"), _T("\\n")); 
 157     (void)str
.Replace(_T("\r"), _T("\\r")); 
 162 #endif // MakePrintable() is used 
 164 // ---------------------------------------------------------------------------- 
 165 // wxFontMapper::CharsetToEncoding 
 166 // ---------------------------------------------------------------------------- 
 170 #include "wx/fontmap.h" 
 172 static void TestCharset() 
 174     static const wxChar 
*charsets
[] = 
 176         // some vali charsets 
 185         // and now some bogus ones 
 192     for ( size_t n 
= 0; n 
< WXSIZEOF(charsets
); n
++ ) 
 194         wxFontEncoding enc 
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]); 
 195         wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"), 
 197                  wxFontMapper::Get()->GetEncodingName(enc
).c_str(), 
 198                  wxFontMapper::Get()->GetEncodingDescription(enc
).c_str()); 
 202 #endif // TEST_CHARSET 
 204 // ---------------------------------------------------------------------------- 
 206 // ---------------------------------------------------------------------------- 
 210 #include "wx/cmdline.h" 
 211 #include "wx/datetime.h" 
 213 #if wxUSE_CMDLINE_PARSER 
 215 static void ShowCmdLine(const wxCmdLineParser
& parser
) 
 217     wxString s 
= _T("Input files: "); 
 219     size_t count 
= parser
.GetParamCount(); 
 220     for ( size_t param 
= 0; param 
< count
; param
++ ) 
 222         s 
<< parser
.GetParam(param
) << ' '; 
 226       << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n' 
 227       << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n'; 
 232     if ( parser
.Found(_T("o"), &strVal
) ) 
 233         s 
<< _T("Output file:\t") << strVal 
<< '\n'; 
 234     if ( parser
.Found(_T("i"), &strVal
) ) 
 235         s 
<< _T("Input dir:\t") << strVal 
<< '\n'; 
 236     if ( parser
.Found(_T("s"), &lVal
) ) 
 237         s 
<< _T("Size:\t") << lVal 
<< '\n'; 
 238     if ( parser
.Found(_T("d"), &dt
) ) 
 239         s 
<< _T("Date:\t") << dt
.FormatISODate() << '\n'; 
 240     if ( parser
.Found(_T("project_name"), &strVal
) ) 
 241         s 
<< _T("Project:\t") << strVal 
<< '\n'; 
 246 #endif // wxUSE_CMDLINE_PARSER 
 248 static void TestCmdLineConvert() 
 250     static const wxChar 
*cmdlines
[] = 
 253         _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""), 
 254         _T("literal \\\" and \"\""), 
 257     for ( size_t n 
= 0; n 
< WXSIZEOF(cmdlines
); n
++ ) 
 259         const wxChar 
*cmdline 
= cmdlines
[n
]; 
 260         wxPrintf(_T("Parsing: %s\n"), cmdline
); 
 261         wxArrayString args 
= wxCmdLineParser::ConvertStringToArgs(cmdline
); 
 263         size_t count 
= args
.GetCount(); 
 264         wxPrintf(_T("\targc = %u\n"), count
); 
 265         for ( size_t arg 
= 0; arg 
< count
; arg
++ ) 
 267             wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str()); 
 272 #endif // TEST_CMDLINE 
 274 // ---------------------------------------------------------------------------- 
 276 // ---------------------------------------------------------------------------- 
 283     static const wxChar 
*ROOTDIR 
= _T("/"); 
 284     static const wxChar 
*TESTDIR 
= _T("/usr/local/share"); 
 285 #elif defined(__WXMSW__) 
 286     static const wxChar 
*ROOTDIR 
= _T("c:\\"); 
 287     static const wxChar 
*TESTDIR 
= _T("d:\\"); 
 289     #error "don't know where the root directory is" 
 292 static void TestDirEnumHelper(wxDir
& dir
, 
 293                               int flags 
= wxDIR_DEFAULT
, 
 294                               const wxString
& filespec 
= wxEmptyString
) 
 298     if ( !dir
.IsOpened() ) 
 301     bool cont 
= dir
.GetFirst(&filename
, filespec
, flags
); 
 304         wxPrintf(_T("\t%s\n"), filename
.c_str()); 
 306         cont 
= dir
.GetNext(&filename
); 
 312 static void TestDirEnum() 
 314     wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***")); 
 316     wxString cwd 
= wxGetCwd(); 
 317     if ( !wxDir::Exists(cwd
) ) 
 319         wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str()); 
 324     if ( !dir
.IsOpened() ) 
 326         wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str()); 
 330     wxPuts(_T("Enumerating everything in current directory:")); 
 331     TestDirEnumHelper(dir
); 
 333     wxPuts(_T("Enumerating really everything in current directory:")); 
 334     TestDirEnumHelper(dir
, wxDIR_DEFAULT 
| wxDIR_DOTDOT
); 
 336     wxPuts(_T("Enumerating object files in current directory:")); 
 337     TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o*"); 
 339     wxPuts(_T("Enumerating directories in current directory:")); 
 340     TestDirEnumHelper(dir
, wxDIR_DIRS
); 
 342     wxPuts(_T("Enumerating files in current directory:")); 
 343     TestDirEnumHelper(dir
, wxDIR_FILES
); 
 345     wxPuts(_T("Enumerating files including hidden in current directory:")); 
 346     TestDirEnumHelper(dir
, wxDIR_FILES 
| wxDIR_HIDDEN
); 
 350     wxPuts(_T("Enumerating everything in root directory:")); 
 351     TestDirEnumHelper(dir
, wxDIR_DEFAULT
); 
 353     wxPuts(_T("Enumerating directories in root directory:")); 
 354     TestDirEnumHelper(dir
, wxDIR_DIRS
); 
 356     wxPuts(_T("Enumerating files in root directory:")); 
 357     TestDirEnumHelper(dir
, wxDIR_FILES
); 
 359     wxPuts(_T("Enumerating files including hidden in root directory:")); 
 360     TestDirEnumHelper(dir
, wxDIR_FILES 
| wxDIR_HIDDEN
); 
 362     wxPuts(_T("Enumerating files in non existing directory:")); 
 363     wxDir 
dirNo("nosuchdir"); 
 364     TestDirEnumHelper(dirNo
); 
 367 class DirPrintTraverser 
: public wxDirTraverser
 
 370     virtual wxDirTraverseResult 
OnFile(const wxString
& filename
) 
 372         return wxDIR_CONTINUE
; 
 375     virtual wxDirTraverseResult 
OnDir(const wxString
& dirname
) 
 377         wxString path
, name
, ext
; 
 378         wxSplitPath(dirname
, &path
, &name
, &ext
); 
 381             name 
<< _T('.') << ext
; 
 384         for ( const wxChar 
*p 
= path
.c_str(); *p
; p
++ ) 
 386             if ( wxIsPathSeparator(*p
) ) 
 390         wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str()); 
 392         return wxDIR_CONTINUE
; 
 396 static void TestDirTraverse() 
 398     wxPuts(_T("*** Testing wxDir::Traverse() ***")); 
 402     size_t n 
= wxDir::GetAllFiles(TESTDIR
, &files
); 
 403     wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
); 
 406         wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str()); 
 407         wxPrintf(_T(" last one is '%s'\n"), files
[n 
- 1].c_str()); 
 410     // enum again with custom traverser 
 411     wxPuts(_T("Now enumerating directories:")); 
 413     DirPrintTraverser traverser
; 
 414     dir
.Traverse(traverser
, _T(""), wxDIR_DIRS 
| wxDIR_HIDDEN
); 
 417 static void TestDirExists() 
 419     wxPuts(_T("*** Testing wxDir::Exists() ***")); 
 421     static const wxChar 
*dirnames
[] = 
 424 #if defined(__WXMSW__) 
 427         _T("\\\\share\\file"), 
 431         _T("c:\\autoexec.bat"), 
 432 #elif defined(__UNIX__) 
 441     for ( size_t n 
= 0; n 
< WXSIZEOF(dirnames
); n
++ ) 
 443         wxPrintf(_T("%-40s: %s\n"), 
 445                  wxDir::Exists(dirnames
[n
]) ? _T("exists") 
 446                                             : _T("doesn't exist")); 
 452 // ---------------------------------------------------------------------------- 
 454 // ---------------------------------------------------------------------------- 
 456 #ifdef TEST_DLLLOADER 
 458 #include "wx/dynlib.h" 
 460 static void TestDllLoad() 
 462 #if defined(__WXMSW__) 
 463     static const wxChar 
*LIB_NAME 
= _T("kernel32.dll"); 
 464     static const wxChar 
*FUNC_NAME 
= _T("lstrlenA"); 
 465 #elif defined(__UNIX__) 
 466     // weird: using just libc.so does *not* work! 
 467     static const wxChar 
*LIB_NAME 
= _T("/lib/libc-2.0.7.so"); 
 468     static const wxChar 
*FUNC_NAME 
= _T("strlen"); 
 470     #error "don't know how to test wxDllLoader on this platform" 
 473     wxPuts(_T("*** testing wxDllLoader ***\n")); 
 475     wxDynamicLibrary 
lib(LIB_NAME
); 
 476     if ( !lib
.IsLoaded() ) 
 478         wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
); 
 482         typedef int (*wxStrlenType
)(const char *); 
 483         wxStrlenType pfnStrlen 
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
); 
 486             wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"), 
 487                      FUNC_NAME
, LIB_NAME
); 
 491             if ( pfnStrlen("foo") != 3 ) 
 493                 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n")); 
 497                 wxPuts(_T("... ok")); 
 503 #endif // TEST_DLLLOADER 
 505 // ---------------------------------------------------------------------------- 
 507 // ---------------------------------------------------------------------------- 
 511 #include "wx/utils.h" 
 513 static wxString 
MyGetEnv(const wxString
& var
) 
 516     if ( !wxGetEnv(var
, &val
) ) 
 519         val 
= wxString(_T('\'')) + val 
+ _T('\''); 
 524 static void TestEnvironment() 
 526     const wxChar 
*var 
= _T("wxTestVar"); 
 528     wxPuts(_T("*** testing environment access functions ***")); 
 530     wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str()); 
 531     wxSetEnv(var
, _T("value for wxTestVar")); 
 532     wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 533     wxSetEnv(var
, _T("another value")); 
 534     wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 536     wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"),  var
, MyGetEnv(var
).c_str()); 
 537     wxPrintf(_T("PATH = %s\n"),  MyGetEnv(_T("PATH")).c_str()); 
 540 #endif // TEST_ENVIRON 
 542 // ---------------------------------------------------------------------------- 
 544 // ---------------------------------------------------------------------------- 
 548 #include "wx/utils.h" 
 550 static void TestExecute() 
 552     wxPuts(_T("*** testing wxExecute ***")); 
 555     #define COMMAND "cat -n ../../Makefile" // "echo hi" 
 556     #define SHELL_COMMAND "echo hi from shell" 
 557     #define REDIRECT_COMMAND COMMAND // "date" 
 558 #elif defined(__WXMSW__) 
 559     #define COMMAND "command.com /c echo hi" 
 560     #define SHELL_COMMAND "echo hi" 
 561     #define REDIRECT_COMMAND COMMAND 
 563     #error "no command to exec" 
 566     wxPrintf(_T("Testing wxShell: ")); 
 568     if ( wxShell(SHELL_COMMAND
) ) 
 571         wxPuts(_T("ERROR.")); 
 573     wxPrintf(_T("Testing wxExecute: ")); 
 575     if ( wxExecute(COMMAND
, true /* sync */) == 0 ) 
 578         wxPuts(_T("ERROR.")); 
 580 #if 0 // no, it doesn't work (yet?) 
 581     wxPrintf(_T("Testing async wxExecute: ")); 
 583     if ( wxExecute(COMMAND
) != 0 ) 
 584         wxPuts(_T("Ok (command launched).")); 
 586         wxPuts(_T("ERROR.")); 
 589     wxPrintf(_T("Testing wxExecute with redirection:\n")); 
 590     wxArrayString output
; 
 591     if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 ) 
 593         wxPuts(_T("ERROR.")); 
 597         size_t count 
= output
.GetCount(); 
 598         for ( size_t n 
= 0; n 
< count
; n
++ ) 
 600             wxPrintf(_T("\t%s\n"), output
[n
].c_str()); 
 607 #endif // TEST_EXECUTE 
 609 // ---------------------------------------------------------------------------- 
 611 // ---------------------------------------------------------------------------- 
 616 #include "wx/ffile.h" 
 617 #include "wx/textfile.h" 
 619 static void TestFileRead() 
 621     wxPuts(_T("*** wxFile read test ***")); 
 623     wxFile 
file(_T("testdata.fc")); 
 624     if ( file
.IsOpened() ) 
 626         wxPrintf(_T("File length: %lu\n"), file
.Length()); 
 628         wxPuts(_T("File dump:\n----------")); 
 630         static const off_t len 
= 1024; 
 634             off_t nRead 
= file
.Read(buf
, len
); 
 635             if ( nRead 
== wxInvalidOffset 
) 
 637                 wxPrintf(_T("Failed to read the file.")); 
 641             fwrite(buf
, nRead
, 1, stdout
); 
 647         wxPuts(_T("----------")); 
 651         wxPrintf(_T("ERROR: can't open test file.\n")); 
 657 static void TestTextFileRead() 
 659     wxPuts(_T("*** wxTextFile read test ***")); 
 661     wxTextFile 
file(_T("testdata.fc")); 
 664         wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount()); 
 665         wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str()); 
 669         wxPuts(_T("\nDumping the entire file:")); 
 670         for ( s 
= file
.GetFirstLine(); !file
.Eof(); s 
= file
.GetNextLine() ) 
 672             wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 674         wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 676         wxPuts(_T("\nAnd now backwards:")); 
 677         for ( s 
= file
.GetLastLine(); 
 678               file
.GetCurrentLine() != 0; 
 679               s 
= file
.GetPrevLine() ) 
 681             wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 683         wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str()); 
 687         wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName()); 
 693 static void TestFileCopy() 
 695     wxPuts(_T("*** Testing wxCopyFile ***")); 
 697     static const wxChar 
*filename1 
= _T("testdata.fc"); 
 698     static const wxChar 
*filename2 
= _T("test2"); 
 699     if ( !wxCopyFile(filename1
, filename2
) ) 
 701         wxPuts(_T("ERROR: failed to copy file")); 
 705         wxFFile 
f1(filename1
, "rb"), 
 708         if ( !f1
.IsOpened() || !f2
.IsOpened() ) 
 710             wxPuts(_T("ERROR: failed to open file(s)")); 
 715             if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) ) 
 717                 wxPuts(_T("ERROR: failed to read file(s)")); 
 721                 if ( (s1
.length() != s2
.length()) || 
 722                      (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) ) 
 724                     wxPuts(_T("ERROR: copy error!")); 
 728                     wxPuts(_T("File was copied ok.")); 
 734     if ( !wxRemoveFile(filename2
) ) 
 736         wxPuts(_T("ERROR: failed to remove the file")); 
 744 // ---------------------------------------------------------------------------- 
 746 // ---------------------------------------------------------------------------- 
 750 #include "wx/confbase.h" 
 751 #include "wx/fileconf.h" 
 753 static const struct FileConfTestData
 
 755     const wxChar 
*name
;      // value name 
 756     const wxChar 
*value
;     // the value from the file 
 759     { _T("value1"),                       _T("one") }, 
 760     { _T("value2"),                       _T("two") }, 
 761     { _T("novalue"),                      _T("default") }, 
 764 static void TestFileConfRead() 
 766     wxPuts(_T("*** testing wxFileConfig loading/reading ***")); 
 768     wxFileConfig 
fileconf(_T("test"), wxEmptyString
, 
 769                           _T("testdata.fc"), wxEmptyString
, 
 770                           wxCONFIG_USE_RELATIVE_PATH
); 
 772     // test simple reading 
 773     wxPuts(_T("\nReading config file:")); 
 774     wxString 
defValue(_T("default")), value
; 
 775     for ( size_t n 
= 0; n 
< WXSIZEOF(fcTestData
); n
++ ) 
 777         const FileConfTestData
& data 
= fcTestData
[n
]; 
 778         value 
= fileconf
.Read(data
.name
, defValue
); 
 779         wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str()); 
 780         if ( value 
== data
.value 
) 
 786             wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
); 
 790     // test enumerating the entries 
 791     wxPuts(_T("\nEnumerating all root entries:")); 
 794     bool cont 
= fileconf
.GetFirstEntry(name
, dummy
); 
 797         wxPrintf(_T("\t%s = %s\n"), 
 799                fileconf
.Read(name
.c_str(), _T("ERROR")).c_str()); 
 801         cont 
= fileconf
.GetNextEntry(name
, dummy
); 
 804     static const wxChar 
*testEntry 
= _T("TestEntry"); 
 805     wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: ")); 
 806     fileconf
.Write(testEntry
, _T("A value")); 
 807     fileconf
.DeleteEntry(testEntry
); 
 808     wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n")); 
 811 #endif // TEST_FILECONF 
 813 // ---------------------------------------------------------------------------- 
 815 // ---------------------------------------------------------------------------- 
 819 #include "wx/filename.h" 
 821 static void DumpFileName(const wxFileName
& fn
) 
 823     wxString full 
= fn
.GetFullPath(); 
 825     wxString vol
, path
, name
, ext
; 
 826     wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
); 
 828     wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"), 
 829              full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str()); 
 831     wxFileName::SplitPath(full
, &path
, &name
, &ext
); 
 832     wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"), 
 833              path
.c_str(), name
.c_str(), ext
.c_str()); 
 835     wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str()); 
 836     wxPrintf(_T("with volume: \t'%s'\n"), 
 837              fn
.GetPath(wxPATH_GET_VOLUME
).c_str()); 
 838     wxPrintf(_T("with separator:\t'%s'\n"), 
 839              fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str()); 
 840     wxPrintf(_T("with both:   \t'%s'\n"), 
 841              fn
.GetPath(wxPATH_GET_SEPARATOR 
| wxPATH_GET_VOLUME
).c_str()); 
 843     wxPuts(_T("The directories in the path are:")); 
 844     wxArrayString dirs 
= fn
.GetDirs(); 
 845     size_t count 
= dirs
.GetCount(); 
 846     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 848         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
, _T(""), fni
.format
) ) 
 923             wxPuts(_T("ERROR (couldn't be normalized)")); 
 927             wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str()); 
 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
); 
 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 
) 
1024                 // TODO: I don't know how this is supposed to work there 
1027             case wxPATH_NATIVE
: // make gcc happy 
1029                 wxFAIL_MSG( "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()); 
1064 static void TestFileNameComparison() 
1069 static void TestFileNameOperations() 
1074 static void TestFileNameCwd() 
1079 #endif // TEST_FILENAME 
1081 // ---------------------------------------------------------------------------- 
1082 // wxFileName time functions 
1083 // ---------------------------------------------------------------------------- 
1085 #ifdef TEST_FILETIME 
1087 #include <wx/filename.h> 
1088 #include <wx/datetime.h> 
1090 static void TestFileGetTimes() 
1092     wxFileName 
fn(_T("testdata.fc")); 
1094     wxDateTime dtAccess
, dtMod
, dtCreate
; 
1095     if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) ) 
1097         wxPrintf(_T("ERROR: GetTimes() failed.\n")); 
1101         static const wxChar 
*fmt 
= _T("%Y-%b-%d %H:%M:%S"); 
1103         wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str()); 
1104         wxPrintf(_T("Creation:    \t%s\n"), dtCreate
.Format(fmt
).c_str()); 
1105         wxPrintf(_T("Last read:   \t%s\n"), dtAccess
.Format(fmt
).c_str()); 
1106         wxPrintf(_T("Last write:  \t%s\n"), dtMod
.Format(fmt
).c_str()); 
1110 static void TestFileSetTimes() 
1112     wxFileName 
fn(_T("testdata.fc")); 
1116         wxPrintf(_T("ERROR: Touch() failed.\n")); 
1120 #endif // TEST_FILETIME 
1122 // ---------------------------------------------------------------------------- 
1124 // ---------------------------------------------------------------------------- 
1128 #include "wx/hash.h" 
1132     Foo(int n_
) { n 
= n_
; count
++; } 
1137     static size_t count
; 
1140 size_t Foo::count 
= 0; 
1142 WX_DECLARE_LIST(Foo
, wxListFoos
); 
1143 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
); 
1145 #include "wx/listimpl.cpp" 
1147 WX_DEFINE_LIST(wxListFoos
); 
1149 static void TestHash() 
1151     wxPuts(_T("*** Testing wxHashTable ***\n")); 
1154         wxHashTable 
hash(wxKEY_INTEGER
), hash2(wxKEY_STRING
); 
1157         for ( i 
= 0; i 
< 100; ++i 
) 
1158             hash
.Put(i
, (wxObject
*)&i 
+ i
); 
1161         wxHashTable::compatibility_iterator it 
= hash
.Next(); 
1171             wxPuts(_T("Error in wxHashTable::compatibility_iterator\n")); 
1173         for ( i 
= 99; i 
>= 0; --i 
) 
1174             if( hash
.Get(i
) != (wxObject
*)&i 
+ i 
) 
1175                 wxPuts(_T("Error in wxHashTable::Get/Put\n")); 
1177         hash2
.Put("foo", (wxObject
*)&i 
+ 1); 
1178         hash2
.Put("bar", (wxObject
*)&i 
+ 2); 
1179         hash2
.Put("baz", (wxObject
*)&i 
+ 3); 
1181         if (hash2
.Get("moo") != NULL
) 
1182             wxPuts(_T("Error in wxHashTable::Get\n")); 
1184         if (hash2
.Get("bar") != (wxObject
*)&i 
+ 2) 
1185             wxPuts(_T("Error in wxHashTable::Get/Put\n")); 
1190         hash
.DeleteContents(true); 
1192         wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"), 
1193                hash
.GetCount(), Foo::count
); 
1195         static const int hashTestData
[] = 
1197             0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1, 
1201         for ( n 
= 0; n 
< WXSIZEOF(hashTestData
); n
++ ) 
1203             hash
.Put(hashTestData
[n
], n
, new Foo(n
)); 
1206         wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"), 
1207                hash
.GetCount(), Foo::count
); 
1209         wxPuts(_T("Hash access test:")); 
1210         for ( n 
= 0; n 
< WXSIZEOF(hashTestData
); n
++ ) 
1212             wxPrintf(_T("\tGetting element with key %d, value %d: "), 
1213                    hashTestData
[n
], n
); 
1214             Foo 
*foo 
= hash
.Get(hashTestData
[n
], n
); 
1217                 wxPrintf(_T("ERROR, not found.\n")); 
1221                 wxPrintf(_T("%d (%s)\n"), foo
->n
, 
1222                        (size_t)foo
->n 
== n 
? "ok" : "ERROR"); 
1226         wxPrintf(_T("\nTrying to get an element not in hash: ")); 
1228         if ( hash
.Get(1234) || hash
.Get(1, 0) ) 
1230             wxPuts(_T("ERROR: found!")); 
1234             wxPuts(_T("ok (not found)")); 
1239     wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
); 
1240     wxPuts(_T("*** Testing wxHashTable finished ***\n")); 
1245 // ---------------------------------------------------------------------------- 
1247 // ---------------------------------------------------------------------------- 
1251 #include "wx/hashmap.h" 
1253 // test compilation of basic map types 
1254 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap 
); 
1255 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap 
); 
1256 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1257                      myUnsignedHashMap 
); 
1258 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1260 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1262 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1264 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
, 
1268 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual, 
1269 //                      myStringHashMap ); 
1270 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
); 
1272 typedef myStringHashMap::iterator Itor
; 
1274 static void TestHashMap() 
1276     wxPuts(_T("*** Testing wxHashMap ***\n")); 
1277     myStringHashMap 
sh(0); // as small as possible 
1280     const size_t count 
= 10000; 
1282     // init with some data 
1283     for( i 
= 0; i 
< count
; ++i 
) 
1285         buf
.Printf(wxT("%d"), i 
); 
1286         sh
[buf
] = wxT("A") + buf 
+ wxT("C"); 
1289     // test that insertion worked 
1290     if( sh
.size() != count 
) 
1292         wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
); 
1295     for( i 
= 0; i 
< count
; ++i 
) 
1297         buf
.Printf(wxT("%d"), i 
); 
1298         if( sh
[buf
] != wxT("A") + buf 
+ wxT("C") ) 
1300             wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n")); 
1305     // check that iterators work 
1307     for( i 
= 0, it 
= sh
.begin(); it 
!= sh
.end(); ++it
, ++i 
) 
1311             wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n")); 
1315         if( it
->second 
!= sh
[it
->first
] ) 
1317             wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n")); 
1322     if( sh
.size() != i 
) 
1324         wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
); 
1327     // test copy ctor, assignment operator 
1328     myStringHashMap 
h1( sh 
), h2( 0 ); 
1331     for( i 
= 0, it 
= sh
.begin(); it 
!= sh
.end(); ++it
, ++i 
) 
1333         if( h1
[it
->first
] != it
->second 
) 
1335             wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str()); 
1338         if( h2
[it
->first
] != it
->second 
) 
1340             wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str()); 
1345     for( i 
= 0; i 
< count
; ++i 
) 
1347         buf
.Printf(wxT("%d"), i 
); 
1348         size_t sz 
= sh
.size(); 
1350         // test find() and erase(it) 
1353             it 
= sh
.find( buf 
); 
1354             if( it 
!= sh
.end() ) 
1358                 if( sh
.find( buf 
) != sh
.end() ) 
1360                     wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
); 
1364                 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
); 
1369             size_t c 
= sh
.erase( buf 
); 
1371                 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n")); 
1373             if( sh
.find( buf 
) != sh
.end() ) 
1375                 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
); 
1379         // count should decrease 
1380         if( sh
.size() != sz 
- 1 ) 
1382             wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n")); 
1386     wxPrintf(_T("*** Finished testing wxHashMap ***\n")); 
1389 #endif // TEST_HASHMAP 
1391 // ---------------------------------------------------------------------------- 
1393 // ---------------------------------------------------------------------------- 
1397 #include "wx/hashset.h" 
1399 // test compilation of basic map types 
1400 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet 
); 
1401 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet 
); 
1402 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
, 
1403                      myUnsignedHashSet 
); 
1404 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
, 
1406 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
, 
1408 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
, 
1410 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
, 
1412 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
, 
1424     unsigned long operator()(const MyStruct
& s
) const 
1425         { return m_dummy(s
.ptr
); } 
1426     MyHash
& operator=(const MyHash
&) { return *this; } 
1428     wxPointerHash m_dummy
; 
1434     bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const 
1435         { return s1
.ptr 
== s2
.ptr
; } 
1436     MyEqual
& operator=(const MyEqual
&) { return *this; } 
1439 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet 
); 
1441 typedef myTestHashSet5 wxStringHashSet
; 
1443 static void TestHashSet() 
1445     wxPrintf(_T("*** Testing wxHashSet ***\n")); 
1447     wxStringHashSet set1
; 
1449     set1
.insert( _T("abc") ); 
1450     set1
.insert( _T("bbc") ); 
1451     set1
.insert( _T("cbc") ); 
1452     set1
.insert( _T("abc") ); 
1454     if( set1
.size() != 3 ) 
1455         wxPrintf(_T("*** ERROR IN INSERT ***\n")); 
1461     tmp
.ptr 
= &dummy
; tmp
.str 
= _T("ABC"); 
1463     tmp
.ptr 
= &dummy 
+ 1; 
1465     tmp
.ptr 
= &dummy
; tmp
.str 
= _T("CDE"); 
1468     if( set2
.size() != 2 ) 
1469         wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n")); 
1471     mySet::iterator it 
= set2
.find( tmp 
); 
1473     if( it 
== set2
.end() ) 
1474         wxPrintf(_T("*** ERROR IN FIND - 1 ***\n")); 
1475     if( it
->ptr 
!= &dummy 
) 
1476         wxPrintf(_T("*** ERROR IN FIND - 2 ***\n")); 
1477     if( it
->str 
!= _T("ABC") ) 
1478         wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n")); 
1480     wxPrintf(_T("*** Finished testing wxHashSet ***\n")); 
1483 #endif // TEST_HASHSET 
1485 // ---------------------------------------------------------------------------- 
1487 // ---------------------------------------------------------------------------- 
1491 #include "wx/list.h" 
1493 WX_DECLARE_LIST(Bar
, wxListBars
); 
1494 #include "wx/listimpl.cpp" 
1495 WX_DEFINE_LIST(wxListBars
); 
1497 WX_DECLARE_LIST(int, wxListInt
); 
1498 WX_DEFINE_LIST(wxListInt
); 
1500 static void TestList() 
1502     wxPuts(_T("*** Testing wxList operations ***\n")); 
1508         for ( i 
= 0; i 
< 5; ++i 
) 
1509             list1
.Append(dummy 
+ i
); 
1511         if ( list1
.GetCount() != 5 ) 
1512             wxPuts(_T("Wrong number of items in list\n")); 
1514         if ( list1
.Item(3)->GetData() != dummy 
+ 3 ) 
1515             wxPuts(_T("Error in Item()\n")); 
1517         if ( !list1
.Find(dummy 
+ 4) ) 
1518             wxPuts(_T("Error in Find()\n")); 
1520         wxListInt::compatibility_iterator node 
= list1
.GetFirst(); 
1525             if ( node
->GetData() != dummy 
+ i 
) 
1526                 wxPuts(_T("Error in compatibility_iterator\n")); 
1527             node 
= node
->GetNext(); 
1531         if ( size_t(i
) != list1
.GetCount() ) 
1532             wxPuts(_T("Error in compatibility_iterator\n")); 
1534         list1
.Insert(dummy 
+ 0); 
1535         list1
.Insert(1, dummy 
+ 1); 
1536         list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy 
+ 2); 
1538         node 
= list1
.GetFirst(); 
1543             int* t 
= node
->GetData(); 
1544             if ( t 
!= dummy 
+ i 
) 
1545                 wxPuts(_T("Error in Insert\n")); 
1546             node 
= node
->GetNext(); 
1551     wxPuts(_T("*** Testing wxList operations finished ***\n")); 
1553     wxPuts(_T("*** Testing std::list operations ***\n")); 
1557         wxListInt::iterator it
, en
; 
1558         wxListInt::reverse_iterator rit
, ren
; 
1560         for ( i 
= 0; i 
< 5; ++i 
) 
1561             list1
.push_back(i 
+ &i
); 
1563         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 0; 
1564               it 
!= en
; ++it
, ++i 
) 
1565             if ( *it 
!= i 
+ &i 
) 
1566                 wxPuts(_T("Error in iterator\n")); 
1568         for ( rit 
= list1
.rbegin(), ren 
= list1
.rend(), i 
= 4; 
1569               rit 
!= ren
; ++rit
, --i 
) 
1570             if ( *rit 
!= i 
+ &i 
) 
1571                 wxPuts(_T("Error in reverse_iterator\n")); 
1573         if ( *list1
.rbegin() != *--list1
.end() || 
1574              *list1
.begin() != *--list1
.rend() ) 
1575             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
1576         if ( *list1
.begin() != *--++list1
.begin() || 
1577              *list1
.rbegin() != *--++list1
.rbegin() ) 
1578             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
1580         if ( list1
.front() != &i 
|| list1
.back() != &i 
+ 4 ) 
1581             wxPuts(_T("Error in front()/back()\n")); 
1583         list1
.erase(list1
.begin()); 
1584         list1
.erase(--list1
.end()); 
1586         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 1; 
1587               it 
!= en
; ++it
, ++i 
) 
1588             if ( *it 
!= i 
+ &i 
) 
1589                 wxPuts(_T("Error in erase()\n")); 
1592     wxPuts(_T("*** Testing std::list operations finished ***\n")); 
1595 static void TestListCtor() 
1597     wxPuts(_T("*** Testing wxList construction ***\n")); 
1601         list1
.Append(new Bar(_T("first"))); 
1602         list1
.Append(new Bar(_T("second"))); 
1604         wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"), 
1605                list1
.GetCount(), Bar::GetNumber()); 
1610         wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"), 
1611                list1
.GetCount(), list2
.GetCount(), Bar::GetNumber()); 
1614         list1
.DeleteContents(true); 
1616         WX_CLEAR_LIST(wxListBars
, list1
); 
1620     wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber()); 
1625 // ---------------------------------------------------------------------------- 
1627 // ---------------------------------------------------------------------------- 
1631 #include "wx/intl.h" 
1632 #include "wx/utils.h"   // for wxSetEnv 
1634 static wxLocale 
gs_localeDefault(wxLANGUAGE_ENGLISH
); 
1636 // find the name of the language from its value 
1637 static const wxChar 
*GetLangName(int lang
) 
1639     static const wxChar 
*languageNames
[] = 
1649         _T("ARABIC_ALGERIA"), 
1650         _T("ARABIC_BAHRAIN"), 
1653         _T("ARABIC_JORDAN"), 
1654         _T("ARABIC_KUWAIT"), 
1655         _T("ARABIC_LEBANON"), 
1657         _T("ARABIC_MOROCCO"), 
1660         _T("ARABIC_SAUDI_ARABIA"), 
1663         _T("ARABIC_TUNISIA"), 
1670         _T("AZERI_CYRILLIC"), 
1685         _T("CHINESE_SIMPLIFIED"), 
1686         _T("CHINESE_TRADITIONAL"), 
1687         _T("CHINESE_HONGKONG"), 
1688         _T("CHINESE_MACAU"), 
1689         _T("CHINESE_SINGAPORE"), 
1690         _T("CHINESE_TAIWAN"), 
1696         _T("DUTCH_BELGIAN"), 
1700         _T("ENGLISH_AUSTRALIA"), 
1701         _T("ENGLISH_BELIZE"), 
1702         _T("ENGLISH_BOTSWANA"), 
1703         _T("ENGLISH_CANADA"), 
1704         _T("ENGLISH_CARIBBEAN"), 
1705         _T("ENGLISH_DENMARK"), 
1707         _T("ENGLISH_JAMAICA"), 
1708         _T("ENGLISH_NEW_ZEALAND"), 
1709         _T("ENGLISH_PHILIPPINES"), 
1710         _T("ENGLISH_SOUTH_AFRICA"), 
1711         _T("ENGLISH_TRINIDAD"), 
1712         _T("ENGLISH_ZIMBABWE"), 
1720         _T("FRENCH_BELGIAN"), 
1721         _T("FRENCH_CANADIAN"), 
1722         _T("FRENCH_LUXEMBOURG"), 
1723         _T("FRENCH_MONACO"), 
1729         _T("GERMAN_AUSTRIAN"), 
1730         _T("GERMAN_BELGIUM"), 
1731         _T("GERMAN_LIECHTENSTEIN"), 
1732         _T("GERMAN_LUXEMBOURG"), 
1750         _T("ITALIAN_SWISS"), 
1755         _T("KASHMIRI_INDIA"), 
1773         _T("MALAY_BRUNEI_DARUSSALAM"), 
1774         _T("MALAY_MALAYSIA"), 
1784         _T("NORWEGIAN_BOKMAL"), 
1785         _T("NORWEGIAN_NYNORSK"), 
1792         _T("PORTUGUESE_BRAZILIAN"), 
1795         _T("RHAETO_ROMANCE"), 
1798         _T("RUSSIAN_UKRAINE"), 
1804         _T("SERBIAN_CYRILLIC"), 
1805         _T("SERBIAN_LATIN"), 
1806         _T("SERBO_CROATIAN"), 
1817         _T("SPANISH_ARGENTINA"), 
1818         _T("SPANISH_BOLIVIA"), 
1819         _T("SPANISH_CHILE"), 
1820         _T("SPANISH_COLOMBIA"), 
1821         _T("SPANISH_COSTA_RICA"), 
1822         _T("SPANISH_DOMINICAN_REPUBLIC"), 
1823         _T("SPANISH_ECUADOR"), 
1824         _T("SPANISH_EL_SALVADOR"), 
1825         _T("SPANISH_GUATEMALA"), 
1826         _T("SPANISH_HONDURAS"), 
1827         _T("SPANISH_MEXICAN"), 
1828         _T("SPANISH_MODERN"), 
1829         _T("SPANISH_NICARAGUA"), 
1830         _T("SPANISH_PANAMA"), 
1831         _T("SPANISH_PARAGUAY"), 
1833         _T("SPANISH_PUERTO_RICO"), 
1834         _T("SPANISH_URUGUAY"), 
1836         _T("SPANISH_VENEZUELA"), 
1840         _T("SWEDISH_FINLAND"), 
1858         _T("URDU_PAKISTAN"), 
1860         _T("UZBEK_CYRILLIC"), 
1873     if ( (size_t)lang 
< WXSIZEOF(languageNames
) ) 
1874         return languageNames
[lang
]; 
1876         return _T("INVALID"); 
1879 static void TestDefaultLang() 
1881     wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***")); 
1883     static const wxChar 
*langStrings
[] = 
1885         NULL
,               // system default 
1892         _T("de_DE.iso88591"), 
1894         _T("?"),            // invalid lang spec 
1895         _T("klingonese"),   // I bet on some systems it does exist... 
1898     wxPrintf(_T("The default system encoding is %s (%d)\n"), 
1899              wxLocale::GetSystemEncodingName().c_str(), 
1900              wxLocale::GetSystemEncoding()); 
1902     for ( size_t n 
= 0; n 
< WXSIZEOF(langStrings
); n
++ ) 
1904         const wxChar 
*langStr 
= langStrings
[n
]; 
1907             // FIXME: this doesn't do anything at all under Windows, we need 
1908             //        to create a new wxLocale! 
1909             wxSetEnv(_T("LC_ALL"), langStr
); 
1912         int lang 
= gs_localeDefault
.GetSystemLanguage(); 
1913         wxPrintf(_T("Locale for '%s' is %s.\n"), 
1914                  langStr 
? langStr 
: _T("system default"), GetLangName(lang
)); 
1918 #endif // TEST_LOCALE 
1920 // ---------------------------------------------------------------------------- 
1922 // ---------------------------------------------------------------------------- 
1926 #include "wx/mimetype.h" 
1928 static void TestMimeEnum() 
1930     wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n")); 
1932     wxArrayString mimetypes
; 
1934     size_t count 
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
); 
1936     wxPrintf(_T("*** All %u known filetypes: ***\n"), count
); 
1941     for ( size_t n 
= 0; n 
< count
; n
++ ) 
1943         wxFileType 
*filetype 
= 
1944             wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]); 
1947             wxPrintf(_T("nothing known about the filetype '%s'!\n"), 
1948                    mimetypes
[n
].c_str()); 
1952         filetype
->GetDescription(&desc
); 
1953         filetype
->GetExtensions(exts
); 
1955         filetype
->GetIcon(NULL
); 
1958         for ( size_t e 
= 0; e 
< exts
.GetCount(); e
++ ) 
1961                 extsAll 
<< _T(", "); 
1965         wxPrintf(_T("\t%s: %s (%s)\n"), 
1966                mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str()); 
1972 static void TestMimeOverride() 
1974     wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n")); 
1976     static const wxChar 
*mailcap 
= _T("/tmp/mailcap"); 
1977     static const wxChar 
*mimetypes 
= _T("/tmp/mime.types"); 
1979     if ( wxFile::Exists(mailcap
) ) 
1980         wxPrintf(_T("Loading mailcap from '%s': %s\n"), 
1982                  wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR")); 
1984         wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), 
1987     if ( wxFile::Exists(mimetypes
) ) 
1988         wxPrintf(_T("Loading mime.types from '%s': %s\n"), 
1990                  wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR")); 
1992         wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), 
1998 static void TestMimeFilename() 
2000     wxPuts(_T("*** Testing MIME type from filename query ***\n")); 
2002     static const wxChar 
*filenames
[] = 
2010     for ( size_t n 
= 0; n 
< WXSIZEOF(filenames
); n
++ ) 
2012         const wxString fname 
= filenames
[n
]; 
2013         wxString ext 
= fname
.AfterLast(_T('.')); 
2014         wxFileType 
*ft 
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
); 
2017             wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str()); 
2022             if ( !ft
->GetDescription(&desc
) ) 
2023                 desc 
= _T("<no description>"); 
2026             if ( !ft
->GetOpenCommand(&cmd
, 
2027                                      wxFileType::MessageParameters(fname
, _T(""))) ) 
2028                 cmd 
= _T("<no command available>"); 
2030                 cmd 
= wxString(_T('"')) + cmd 
+ _T('"'); 
2032             wxPrintf(_T("To open %s (%s) do %s.\n"), 
2033                      fname
.c_str(), desc
.c_str(), cmd
.c_str()); 
2042 static void TestMimeAssociate() 
2044     wxPuts(_T("*** Testing creation of filetype association ***\n")); 
2046     wxFileTypeInfo 
ftInfo( 
2047                             _T("application/x-xyz"), 
2048                             _T("xyzview '%s'"), // open cmd 
2049                             _T(""),             // print cmd 
2050                             _T("XYZ File"),     // description 
2051                             _T(".xyz"),         // extensions 
2052                             NULL                
// end of extensions 
2054     ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only 
2056     wxFileType 
*ft 
= wxTheMimeTypesManager
->Associate(ftInfo
); 
2059         wxPuts(_T("ERROR: failed to create association!")); 
2063         // TODO: read it back 
2072 // ---------------------------------------------------------------------------- 
2073 // misc information functions 
2074 // ---------------------------------------------------------------------------- 
2076 #ifdef TEST_INFO_FUNCTIONS 
2078 #include "wx/utils.h" 
2080 static void TestDiskInfo() 
2082     wxPuts(_T("*** Testing wxGetDiskSpace() ***")); 
2086         wxChar pathname
[128]; 
2087         wxPrintf(_T("\nEnter a directory name: ")); 
2088         if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) ) 
2091         // kill the last '\n' 
2092         pathname
[wxStrlen(pathname
) - 1] = 0; 
2094         wxLongLong total
, free
; 
2095         if ( !wxGetDiskSpace(pathname
, &total
, &free
) ) 
2097             wxPuts(_T("ERROR: wxGetDiskSpace failed.")); 
2101             wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"), 
2102                     (total 
/ 1024).ToString().c_str(), 
2103                     (free 
/ 1024).ToString().c_str(), 
2109 static void TestOsInfo() 
2111     wxPuts(_T("*** Testing OS info functions ***\n")); 
2114     wxGetOsVersion(&major
, &minor
); 
2115     wxPrintf(_T("Running under: %s, version %d.%d\n"), 
2116             wxGetOsDescription().c_str(), major
, minor
); 
2118     wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory()); 
2120     wxPrintf(_T("Host name is %s (%s).\n"), 
2121            wxGetHostName().c_str(), wxGetFullHostName().c_str()); 
2126 static void TestUserInfo() 
2128     wxPuts(_T("*** Testing user info functions ***\n")); 
2130     wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str()); 
2131     wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str()); 
2132     wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); 
2133     wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str()); 
2138 #endif // TEST_INFO_FUNCTIONS 
2140 // ---------------------------------------------------------------------------- 
2142 // ---------------------------------------------------------------------------- 
2144 #ifdef TEST_LONGLONG 
2146 #include "wx/longlong.h" 
2147 #include "wx/timer.h" 
2149 // make a 64 bit number from 4 16 bit ones 
2150 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3) 
2152 // get a random 64 bit number 
2153 #define RAND_LL()   MAKE_LL(rand(), rand(), rand(), rand()) 
2155 static const long testLongs
[] = 
2166 #if wxUSE_LONGLONG_WX 
2167 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
) 
2168     { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); } 
2169 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
) 
2170     { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); } 
2171 #endif // wxUSE_LONGLONG_WX 
2173 static void TestSpeed() 
2175     static const long max 
= 100000000; 
2182         for ( n 
= 0; n 
< max
; n
++ ) 
2187         wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw
.Time()); 
2190 #if wxUSE_LONGLONG_NATIVE 
2195         for ( n 
= 0; n 
< max
; n
++ ) 
2200         wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw
.Time()); 
2202 #endif // wxUSE_LONGLONG_NATIVE 
2208         for ( n 
= 0; n 
< max
; n
++ ) 
2213         wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw
.Time()); 
2217 static void TestLongLongConversion() 
2219     wxPuts(_T("*** Testing wxLongLong conversions ***\n")); 
2223     for ( size_t n 
= 0; n 
< 100000; n
++ ) 
2227 #if wxUSE_LONGLONG_NATIVE 
2228         wxLongLongNative 
b(a
.GetHi(), a
.GetLo()); 
2230         wxASSERT_MSG( a 
== b
, "conversions failure" ); 
2232         wxPuts(_T("Can't do it without native long long type, test skipped.")); 
2235 #endif // wxUSE_LONGLONG_NATIVE 
2237         if ( !(nTested 
% 1000) ) 
2246     wxPuts(_T(" done!")); 
2249 static void TestMultiplication() 
2251     wxPuts(_T("*** Testing wxLongLong multiplication ***\n")); 
2255     for ( size_t n 
= 0; n 
< 100000; n
++ ) 
2260 #if wxUSE_LONGLONG_NATIVE 
2261         wxLongLongNative 
aa(a
.GetHi(), a
.GetLo()); 
2262         wxLongLongNative 
bb(b
.GetHi(), b
.GetLo()); 
2264         wxASSERT_MSG( a
*b 
== aa
*bb
, "multiplication failure" ); 
2265 #else // !wxUSE_LONGLONG_NATIVE 
2266         wxPuts(_T("Can't do it without native long long type, test skipped.")); 
2269 #endif // wxUSE_LONGLONG_NATIVE 
2271         if ( !(nTested 
% 1000) ) 
2280     wxPuts(_T(" done!")); 
2283 static void TestDivision() 
2285     wxPuts(_T("*** Testing wxLongLong division ***\n")); 
2289     for ( size_t n 
= 0; n 
< 100000; n
++ ) 
2291         // get a random wxLongLong (shifting by 12 the MSB ensures that the 
2292         // multiplication will not overflow) 
2293         wxLongLong ll 
= MAKE_LL((rand() >> 12), rand(), rand(), rand()); 
2295         // get a random (but non null) long (not wxLongLong for now) to divide 
2307 #if wxUSE_LONGLONG_NATIVE 
2308         wxLongLongNative 
m(ll
.GetHi(), ll
.GetLo()); 
2310         wxLongLongNative p 
= m 
/ l
, s 
= m 
% l
; 
2311         wxASSERT_MSG( q 
== p 
&& r 
== s
, "division failure" ); 
2312 #else // !wxUSE_LONGLONG_NATIVE 
2313         // verify the result 
2314         wxASSERT_MSG( ll 
== q
*l 
+ r
, "division failure" ); 
2315 #endif // wxUSE_LONGLONG_NATIVE 
2317         if ( !(nTested 
% 1000) ) 
2326     wxPuts(_T(" done!")); 
2329 static void TestAddition() 
2331     wxPuts(_T("*** Testing wxLongLong addition ***\n")); 
2335     for ( size_t n 
= 0; n 
< 100000; n
++ ) 
2341 #if wxUSE_LONGLONG_NATIVE 
2342         wxASSERT_MSG( c 
== wxLongLongNative(a
.GetHi(), a
.GetLo()) + 
2343                            wxLongLongNative(b
.GetHi(), b
.GetLo()), 
2344                       "addition failure" ); 
2345 #else // !wxUSE_LONGLONG_NATIVE 
2346         wxASSERT_MSG( c 
- b 
== a
, "addition failure" ); 
2347 #endif // wxUSE_LONGLONG_NATIVE 
2349         if ( !(nTested 
% 1000) ) 
2358     wxPuts(_T(" done!")); 
2361 static void TestBitOperations() 
2363     wxPuts(_T("*** Testing wxLongLong bit operation ***\n")); 
2367     for ( size_t n 
= 0; n 
< 100000; n
++ ) 
2371 #if wxUSE_LONGLONG_NATIVE 
2372         for ( size_t n 
= 0; n 
< 33; n
++ ) 
2375 #else // !wxUSE_LONGLONG_NATIVE 
2376         wxPuts(_T("Can't do it without native long long type, test skipped.")); 
2379 #endif // wxUSE_LONGLONG_NATIVE 
2381         if ( !(nTested 
% 1000) ) 
2390     wxPuts(_T(" done!")); 
2393 static void TestLongLongComparison() 
2395 #if wxUSE_LONGLONG_WX 
2396     wxPuts(_T("*** Testing wxLongLong comparison ***\n")); 
2398     static const long ls
[2] = 
2404     wxLongLongWx lls
[2]; 
2408     for ( size_t n 
= 0; n 
< WXSIZEOF(testLongs
); n
++ ) 
2412         for ( size_t m 
= 0; m 
< WXSIZEOF(lls
); m
++ ) 
2414             res 
= lls
[m
] > testLongs
[n
]; 
2415             wxPrintf(_T("0x%lx > 0x%lx is %s (%s)\n"), 
2416                    ls
[m
], testLongs
[n
], res 
? "true" : "false", 
2417                    res 
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR"); 
2419             res 
= lls
[m
] < testLongs
[n
]; 
2420             wxPrintf(_T("0x%lx < 0x%lx is %s (%s)\n"), 
2421                    ls
[m
], testLongs
[n
], res 
? "true" : "false", 
2422                    res 
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR"); 
2424             res 
= lls
[m
] == testLongs
[n
]; 
2425             wxPrintf(_T("0x%lx == 0x%lx is %s (%s)\n"), 
2426                    ls
[m
], testLongs
[n
], res 
? "true" : "false", 
2427                    res 
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR"); 
2430 #endif // wxUSE_LONGLONG_WX 
2433 static void TestLongLongToString() 
2435     wxPuts(_T("*** Testing wxLongLong::ToString() ***\n")); 
2437     for ( size_t n 
= 0; n 
< WXSIZEOF(testLongs
); n
++ ) 
2439         wxLongLong ll 
= testLongs
[n
]; 
2440         wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str()); 
2443     wxLongLong 
ll(0x12345678, 0x87654321); 
2444     wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str()); 
2447     wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str()); 
2450 static void TestLongLongPrintf() 
2452     wxPuts(_T("*** Testing wxLongLong printing ***\n")); 
2454 #ifdef wxLongLongFmtSpec 
2455     wxLongLong ll 
= wxLL(0x1234567890abcdef); 
2456     wxString s 
= wxString::Format(_T("%") wxLongLongFmtSpec 
_T("x"), ll
); 
2457     wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"), 
2458              s
.c_str(), s 
== _T("1234567890abcdef") ? _T("ok") : _T("ERROR")); 
2459 #else // !wxLongLongFmtSpec 
2460     #error "wxLongLongFmtSpec not defined for this compiler/platform" 
2467 #endif // TEST_LONGLONG 
2469 // ---------------------------------------------------------------------------- 
2471 // ---------------------------------------------------------------------------- 
2473 #ifdef TEST_PATHLIST 
2476     #define CMD_IN_PATH _T("ls") 
2478     #define CMD_IN_PATH _T("command.com") 
2481 static void TestPathList() 
2483     wxPuts(_T("*** Testing wxPathList ***\n")); 
2485     wxPathList pathlist
; 
2486     pathlist
.AddEnvList(_T("PATH")); 
2487     wxString path 
= pathlist
.FindValidPath(CMD_IN_PATH
); 
2490         wxPrintf(_T("ERROR: command not found in the path.\n")); 
2494         wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str()); 
2498 #endif // TEST_PATHLIST 
2500 // ---------------------------------------------------------------------------- 
2501 // regular expressions 
2502 // ---------------------------------------------------------------------------- 
2506 #include "wx/regex.h" 
2508 static void TestRegExCompile() 
2510     wxPuts(_T("*** Testing RE compilation ***\n")); 
2512     static struct RegExCompTestData
 
2514         const wxChar 
*pattern
; 
2516     } regExCompTestData
[] = 
2518         { _T("foo"), true }, 
2519         { _T("foo("), false }, 
2520         { _T("foo(bar"), false }, 
2521         { _T("foo(bar)"), true }, 
2522         { _T("foo["), false }, 
2523         { _T("foo[bar"), false }, 
2524         { _T("foo[bar]"), true }, 
2525         { _T("foo{"), true }, 
2526         { _T("foo{1"), false }, 
2527         { _T("foo{bar"), true }, 
2528         { _T("foo{1}"), true }, 
2529         { _T("foo{1,2}"), true }, 
2530         { _T("foo{bar}"), true }, 
2531         { _T("foo*"), true }, 
2532         { _T("foo**"), false }, 
2533         { _T("foo+"), true }, 
2534         { _T("foo++"), false }, 
2535         { _T("foo?"), true }, 
2536         { _T("foo??"), false }, 
2537         { _T("foo?+"), false }, 
2541     for ( size_t n 
= 0; n 
< WXSIZEOF(regExCompTestData
); n
++ ) 
2543         const RegExCompTestData
& data 
= regExCompTestData
[n
]; 
2544         bool ok 
= re
.Compile(data
.pattern
); 
2546         wxPrintf(_T("'%s' is %sa valid RE (%s)\n"), 
2548                  ok 
? _T("") : _T("not "), 
2549                  ok 
== data
.correct 
? _T("ok") : _T("ERROR")); 
2553 static void TestRegExMatch() 
2555     wxPuts(_T("*** Testing RE matching ***\n")); 
2557     static struct RegExMatchTestData
 
2559         const wxChar 
*pattern
; 
2562     } regExMatchTestData
[] = 
2564         { _T("foo"), _T("bar"), false }, 
2565         { _T("foo"), _T("foobar"), true }, 
2566         { _T("^foo"), _T("foobar"), true }, 
2567         { _T("^foo"), _T("barfoo"), false }, 
2568         { _T("bar$"), _T("barbar"), true }, 
2569         { _T("bar$"), _T("barbar "), false }, 
2572     for ( size_t n 
= 0; n 
< WXSIZEOF(regExMatchTestData
); n
++ ) 
2574         const RegExMatchTestData
& data 
= regExMatchTestData
[n
]; 
2576         wxRegEx 
re(data
.pattern
); 
2577         bool ok 
= re
.Matches(data
.text
); 
2579         wxPrintf(_T("'%s' %s %s (%s)\n"), 
2581                  ok 
? _T("matches") : _T("doesn't match"), 
2583                  ok 
== data
.correct 
? _T("ok") : _T("ERROR")); 
2587 static void TestRegExSubmatch() 
2589     wxPuts(_T("*** Testing RE subexpressions ***\n")); 
2591     wxRegEx 
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$")); 
2592     if ( !re
.IsValid() ) 
2594         wxPuts(_T("ERROR: compilation failed.")); 
2598     wxString text 
= _T("Fri Jul 13 18:37:52 CEST 2001"); 
2600     if ( !re
.Matches(text
) ) 
2602         wxPuts(_T("ERROR: match expected.")); 
2606         wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str()); 
2608         wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"), 
2609                  re
.GetMatch(text
, 3).c_str(), 
2610                  re
.GetMatch(text
, 2).c_str(), 
2611                  re
.GetMatch(text
, 4).c_str(), 
2612                  re
.GetMatch(text
, 1).c_str()); 
2616 static void TestRegExReplacement() 
2618     wxPuts(_T("*** Testing RE replacement ***")); 
2620     static struct RegExReplTestData
 
2624         const wxChar 
*result
; 
2626     } regExReplTestData
[] = 
2628         { _T("foo123"), _T("bar"), _T("bar"), 1 }, 
2629         { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 }, 
2630         { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 }, 
2631         { _T("123foo"), _T("bar"), _T("123foo"), 0 }, 
2632         { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 }, 
2633         { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 }, 
2634         { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 }, 
2637     const wxChar 
*pattern 
= _T("([a-z]+)[^0-9]*([0-9]+)"); 
2638     wxRegEx 
re(pattern
); 
2640     wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
); 
2642     for ( size_t n 
= 0; n 
< WXSIZEOF(regExReplTestData
); n
++ ) 
2644         const RegExReplTestData
& data 
= regExReplTestData
[n
]; 
2646         wxString text 
= data
.text
; 
2647         size_t nRepl 
= re
.Replace(&text
, data
.repl
); 
2649         wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("), 
2650                  data
.text
, data
.repl
, 
2651                  nRepl
, nRepl 
== 1 ? _T("") : _T("es"), 
2653         if ( text 
== data
.result 
&& nRepl 
== data
.count 
) 
2659             wxPrintf(_T("ERROR: should be %u and '%s')\n"), 
2660                      data
.count
, data
.result
); 
2665 static void TestRegExInteractive() 
2667     wxPuts(_T("*** Testing RE interactively ***")); 
2671         wxChar pattern
[128]; 
2672         wxPrintf(_T("\nEnter a pattern: ")); 
2673         if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) ) 
2676         // kill the last '\n' 
2677         pattern
[wxStrlen(pattern
) - 1] = 0; 
2680         if ( !re
.Compile(pattern
) ) 
2688             wxPrintf(_T("Enter text to match: ")); 
2689             if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) ) 
2692             // kill the last '\n' 
2693             text
[wxStrlen(text
) - 1] = 0; 
2695             if ( !re
.Matches(text
) ) 
2697                 wxPrintf(_T("No match.\n")); 
2701                 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str()); 
2704                 for ( size_t n 
= 1; ; n
++ ) 
2706                     if ( !re
.GetMatch(&start
, &len
, n
) ) 
2711                     wxPrintf(_T("Subexpr %u matched '%s'\n"), 
2712                              n
, wxString(text 
+ start
, len
).c_str()); 
2719 #endif // TEST_REGEX 
2721 // ---------------------------------------------------------------------------- 
2723 // ---------------------------------------------------------------------------- 
2733 static void TestDbOpen() 
2741 // ---------------------------------------------------------------------------- 
2743 // ---------------------------------------------------------------------------- 
2746    NB: this stuff was taken from the glibc test suite and modified to build 
2747        in wxWindows: if I read the copyright below properly, this shouldn't 
2753 #ifdef wxTEST_PRINTF 
2754     // use our functions from wxchar.cpp 
2758     // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats 
2759     //     in the tests below 
2760     int wxPrintf( const wxChar 
*format
, ... ); 
2761     int wxSprintf( wxChar 
*str
, const wxChar 
*format
, ... ); 
2764 #include "wx/longlong.h" 
2768 static void rfg1 (void); 
2769 static void rfg2 (void); 
2773 fmtchk (const wxChar 
*fmt
) 
2775   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2776   (void) wxPrintf(fmt
, 0x12); 
2777   (void) wxPrintf(_T("'\n")); 
2781 fmtst1chk (const wxChar 
*fmt
) 
2783   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2784   (void) wxPrintf(fmt
, 4, 0x12); 
2785   (void) wxPrintf(_T("'\n")); 
2789 fmtst2chk (const wxChar 
*fmt
) 
2791   (void) wxPrintf(_T("%s:\t`"), fmt
); 
2792   (void) wxPrintf(fmt
, 4, 4, 0x12); 
2793   (void) wxPrintf(_T("'\n")); 
2796 /* This page is covered by the following copyright: */ 
2798 /* (C) Copyright C E Chew 
2800  * Feel free to copy, use and distribute this software provided: 
2802  *        1. you do not pretend that you wrote it 
2803  *        2. you leave this copyright notice intact. 
2807  * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. 
2814 /* Formatted Output Test 
2816  * This exercises the output formatting code. 
2824   wxChar 
*prefix 
= buf
; 
2827   wxPuts(_T("\nFormatted output test")); 
2828   wxPrintf(_T("prefix  6d      6o      6x      6X      6u\n")); 
2829   wxStrcpy(prefix
, _T("%")); 
2830   for (i 
= 0; i 
< 2; i
++) { 
2831     for (j 
= 0; j 
< 2; j
++) { 
2832       for (k 
= 0; k 
< 2; k
++) { 
2833         for (l 
= 0; l 
< 2; l
++) { 
2834           wxStrcpy(prefix
, _T("%")); 
2835           if (i 
== 0) wxStrcat(prefix
, _T("-")); 
2836           if (j 
== 0) wxStrcat(prefix
, _T("+")); 
2837           if (k 
== 0) wxStrcat(prefix
, _T("#")); 
2838           if (l 
== 0) wxStrcat(prefix
, _T("0")); 
2839           wxPrintf(_T("%5s |"), prefix
); 
2840           wxStrcpy(tp
, prefix
); 
2841           wxStrcat(tp
, _T("6d |")); 
2843           wxStrcpy(tp
, prefix
); 
2844           wxStrcat(tp
, _T("6o |")); 
2846           wxStrcpy(tp
, prefix
); 
2847           wxStrcat(tp
, _T("6x |")); 
2849           wxStrcpy(tp
, prefix
); 
2850           wxStrcat(tp
, _T("6X |")); 
2852           wxStrcpy(tp
, prefix
); 
2853           wxStrcat(tp
, _T("6u |")); 
2860   wxPrintf(_T("%10s\n"), (wxChar 
*) NULL
); 
2861   wxPrintf(_T("%-10s\n"), (wxChar 
*) NULL
); 
2864 static void TestPrintf() 
2866   static wxChar shortstr
[] = _T("Hi, Z."); 
2867   static wxChar longstr
[] = _T("Good morning, Doctor Chandra.  This is Hal.  \ 
2868 I am ready for my first lesson today."); 
2873   fmtchk(_T("%4.4x")); 
2874   fmtchk(_T("%04.4x")); 
2875   fmtchk(_T("%4.3x")); 
2876   fmtchk(_T("%04.3x")); 
2878   fmtst1chk(_T("%.*x")); 
2879   fmtst1chk(_T("%0*x")); 
2880   fmtst2chk(_T("%*.*x")); 
2881   fmtst2chk(_T("%0*.*x")); 
2883   wxPrintf(_T("bad format:\t\"%b\"\n")); 
2884   wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
); 
2886   wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345); 
2887   wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345); 
2888   wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345); 
2889   wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L); 
2890   wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L); 
2891   wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L); 
2892   wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L); 
2893   wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456); 
2894   wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L); 
2895   wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); 
2897   wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr
); 
2898   wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr
); 
2899   wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
); 
2900   wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
); 
2901   wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar 
*)NULL
); 
2902   wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
); 
2904   wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34); 
2905   wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234); 
2906   wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234); 
2907   wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
); 
2908   wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1); 
2909   wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34); 
2910   wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234); 
2911   wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234); 
2912   wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34); 
2913   wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234); 
2914   wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234); 
2915   wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
); 
2917   wxPrintf (_T(" %6.5f\n"), .099999999860301614); 
2918   wxPrintf (_T(" %6.5f\n"), .1); 
2919   wxPrintf (_T("x%5.4fx\n"), .5); 
2921   wxPrintf (_T("%#03x\n"), 1); 
2923   //wxPrintf (_T("something really insane: %.10000f\n"), 1.0); 
2929     while (niter
-- != 0) 
2930       wxPrintf (_T("%.17e\n"), d 
/ 2); 
2934   wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324); 
2936 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n") 
2937   wxPrintf (FORMAT
, 0.0, 0.0, 0.0); 
2938   wxPrintf (FORMAT
, 1.0, 1.0, 1.0); 
2939   wxPrintf (FORMAT
, -1.0, -1.0, -1.0); 
2940   wxPrintf (FORMAT
, 100.0, 100.0, 100.0); 
2941   wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0); 
2942   wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0); 
2943   wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0); 
2944   wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0); 
2945   wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0); 
2950     int rc 
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo")); 
2952     wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"), 
2953              rc
, WXSIZEOF(buf
), buf
); 
2956     wxPrintf ("snprintf (\"%%.999999u\", 10)\n", 
2957             wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10)); 
2963   wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8); 
2964   wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8); 
2965   wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8); 
2966   wxPrintf (_T("%g should be 123.456\n"), 123.456); 
2967   wxPrintf (_T("%g should be 1e+06\n"), 1000000.0); 
2968   wxPrintf (_T("%g should be 10\n"), 10.0); 
2969   wxPrintf (_T("%g should be 0.02\n"), 0.02); 
2973     wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
); 
2979     wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three")); 
2981     result 
|= wxStrcmp (buf
, 
2982                       _T("onetwo                 three                         ")); 
2984     wxPuts (result 
!= 0 ? _T("Test failed!") : _T("Test ok.")); 
2991       wxSprintf(buf
, _T("%07") wxLongLongFmtSpec 
_T("o"), wxLL(040000000000)); 
2992       wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
); 
2994       if (wxStrcmp (buf
, _T("40000000000")) != 0) 
2997           wxPuts (_T("\tFAILED")); 
3001 #endif // wxLongLong_t 
3003   wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX 
+ 2, UCHAR_MAX 
+ 2); 
3004   wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX 
+ 2, USHRT_MAX 
+ 2); 
3006   wxPuts (_T("--- Should be no further output. ---")); 
3015     memset (bytes
, '\xff', sizeof bytes
); 
3016     wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]); 
3017     if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff' 
3018         || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff') 
3020         wxPuts (_T("%hhn overwrite more bytes")); 
3025         wxPuts (_T("%hhn wrote incorrect value")); 
3037   wxSprintf (buf
, _T("%5.s"), _T("xyz")); 
3038   if (wxStrcmp (buf
, _T("     ")) != 0) 
3039     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("     ")); 
3040   wxSprintf (buf
, _T("%5.f"), 33.3); 
3041   if (wxStrcmp (buf
, _T("   33")) != 0) 
3042     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   33")); 
3043   wxSprintf (buf
, _T("%8.e"), 33.3e7
); 
3044   if (wxStrcmp (buf
, _T("   3e+08")) != 0) 
3045     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   3e+08")); 
3046   wxSprintf (buf
, _T("%8.E"), 33.3e7
); 
3047   if (wxStrcmp (buf
, _T("   3E+08")) != 0) 
3048     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("   3E+08")); 
3049   wxSprintf (buf
, _T("%.g"), 33.3); 
3050   if (wxStrcmp (buf
, _T("3e+01")) != 0) 
3051     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01")); 
3052   wxSprintf (buf
, _T("%.G"), 33.3); 
3053   if (wxStrcmp (buf
, _T("3E+01")) != 0) 
3054     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01")); 
3064   wxSprintf (buf
, _T("%.*g"), prec
, 3.3); 
3065   if (wxStrcmp (buf
, _T("3")) != 0) 
3066     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3")); 
3068   wxSprintf (buf
, _T("%.*G"), prec
, 3.3); 
3069   if (wxStrcmp (buf
, _T("3")) != 0) 
3070     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3")); 
3072   wxSprintf (buf
, _T("%7.*G"), prec
, 3.33); 
3073   if (wxStrcmp (buf
, _T("      3")) != 0) 
3074     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("      3")); 
3076   wxSprintf (buf
, _T("%04.*o"), prec
, 33); 
3077   if (wxStrcmp (buf
, _T(" 041")) != 0) 
3078     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041")); 
3080   wxSprintf (buf
, _T("%09.*u"), prec
, 33); 
3081   if (wxStrcmp (buf
, _T("  0000033")) != 0) 
3082     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("  0000033")); 
3084   wxSprintf (buf
, _T("%04.*x"), prec
, 33); 
3085   if (wxStrcmp (buf
, _T(" 021")) != 0) 
3086     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021")); 
3088   wxSprintf (buf
, _T("%04.*X"), prec
, 33); 
3089   if (wxStrcmp (buf
, _T(" 021")) != 0) 
3090     wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021")); 
3093 #endif // TEST_PRINTF 
3095 // ---------------------------------------------------------------------------- 
3096 // registry and related stuff 
3097 // ---------------------------------------------------------------------------- 
3099 // this is for MSW only 
3102     #undef TEST_REGISTRY 
3107 #include "wx/confbase.h" 
3108 #include "wx/msw/regconf.h" 
3110 static void TestRegConfWrite() 
3112     wxRegConfig 
regconf(_T("console"), _T("wxwindows")); 
3113     regconf
.Write(_T("Hello"), wxString(_T("world"))); 
3116 #endif // TEST_REGCONF 
3118 #ifdef TEST_REGISTRY 
3120 #include "wx/msw/registry.h" 
3122 // I chose this one because I liked its name, but it probably only exists under 
3124 static const wxChar 
*TESTKEY 
= 
3125     _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl"); 
3127 static void TestRegistryRead() 
3129     wxPuts(_T("*** testing registry reading ***")); 
3131     wxRegKey 
key(TESTKEY
); 
3132     wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str()); 
3135         wxPuts(_T("ERROR: test key can't be opened, aborting test.")); 
3140     size_t nSubKeys
, nValues
; 
3141     if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) ) 
3143         wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
); 
3146     wxPrintf(_T("Enumerating values:\n")); 
3150     bool cont 
= key
.GetFirstValue(value
, dummy
); 
3153         wxPrintf(_T("Value '%s': type "), value
.c_str()); 
3154         switch ( key
.GetValueType(value
) ) 
3156             case wxRegKey::Type_None
:   wxPrintf(_T("ERROR (none)")); break; 
3157             case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break; 
3158             case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break; 
3159             case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break; 
3160             case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break; 
3161             case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break; 
3162             default: wxPrintf(_T("other (unknown)")); break; 
3165         wxPrintf(_T(", value = ")); 
3166         if ( key
.IsNumericValue(value
) ) 
3169             key
.QueryValue(value
, &val
); 
3170             wxPrintf(_T("%ld"), val
); 
3175             key
.QueryValue(value
, val
); 
3176             wxPrintf(_T("'%s'"), val
.c_str()); 
3178             key
.QueryRawValue(value
, val
); 
3179             wxPrintf(_T(" (raw value '%s')"), val
.c_str()); 
3184         cont 
= key
.GetNextValue(value
, dummy
); 
3188 static void TestRegistryAssociation() 
3191        The second call to deleteself genertaes an error message, with a 
3192        messagebox saying .flo is crucial to system operation, while the .ddf 
3193        call also fails, but with no error message 
3198     key
.SetName("HKEY_CLASSES_ROOT\\.ddf" ); 
3200     key 
= "ddxf_auto_file" ; 
3201     key
.SetName("HKEY_CLASSES_ROOT\\.flo" ); 
3203     key 
= "ddxf_auto_file" ; 
3204     key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"); 
3207     key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"); 
3209     key 
= "program \"%1\"" ; 
3211     key
.SetName("HKEY_CLASSES_ROOT\\.ddf" ); 
3213     key
.SetName("HKEY_CLASSES_ROOT\\.flo" ); 
3215     key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"); 
3217     key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"); 
3221 #endif // TEST_REGISTRY 
3223 // ---------------------------------------------------------------------------- 
3225 // ---------------------------------------------------------------------------- 
3227 #ifdef TEST_SCOPEGUARD 
3229 #include "wx/scopeguard.h" 
3231 static void function0() { puts("function0()"); } 
3232 static void function1(int n
) { printf("function1(%d)\n", n
); } 
3233 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); } 
3237     void method0() { printf("method0()\n"); } 
3238     void method1(int n
) { printf("method1(%d)\n", n
); } 
3239     void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); } 
3242 static void TestScopeGuard() 
3244     ON_BLOCK_EXIT0(function0
); 
3245     ON_BLOCK_EXIT1(function1
, 17); 
3246     ON_BLOCK_EXIT2(function2
, 3.14, 'p'); 
3249     ON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
); 
3250     ON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7); 
3251     ON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e'); 
3253     wxScopeGuard dismissed 
= wxMakeGuard(function0
); 
3254     dismissed
.Dismiss(); 
3259 // ---------------------------------------------------------------------------- 
3261 // ---------------------------------------------------------------------------- 
3265 #include "wx/socket.h" 
3266 #include "wx/protocol/protocol.h" 
3267 #include "wx/protocol/http.h" 
3269 static void TestSocketServer() 
3271     wxPuts(_T("*** Testing wxSocketServer ***\n")); 
3273     static const int PORT 
= 3000; 
3278     wxSocketServer 
*server 
= new wxSocketServer(addr
); 
3279     if ( !server
->Ok() ) 
3281         wxPuts(_T("ERROR: failed to bind")); 
3289         wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
); 
3291         wxSocketBase 
*socket 
= server
->Accept(); 
3294             wxPuts(_T("ERROR: wxSocketServer::Accept() failed.")); 
3298         wxPuts(_T("Server: got a client.")); 
3300         server
->SetTimeout(60); // 1 min 
3303         while ( !close 
&& socket
->IsConnected() ) 
3306             wxChar ch 
= _T('\0'); 
3309                 if ( socket
->Read(&ch
, sizeof(ch
)).Error() ) 
3311                     // don't log error if the client just close the connection 
3312                     if ( socket
->IsConnected() ) 
3314                         wxPuts(_T("ERROR: in wxSocket::Read.")); 
3334             wxPrintf(_T("Server: got '%s'.\n"), s
.c_str()); 
3335             if ( s 
== _T("close") ) 
3337                 wxPuts(_T("Closing connection")); 
3341             else if ( s 
== _T("quit") ) 
3346                 wxPuts(_T("Shutting down the server")); 
3348             else // not a special command 
3350                 socket
->Write(s
.MakeUpper().c_str(), s
.length()); 
3351                 socket
->Write("\r\n", 2); 
3352                 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str()); 
3358             wxPuts(_T("Server: lost a client unexpectedly.")); 
3364     // same as "delete server" but is consistent with GUI programs 
3368 static void TestSocketClient() 
3370     wxPuts(_T("*** Testing wxSocketClient ***\n")); 
3372     static const wxChar 
*hostname 
= _T("www.wxwindows.org"); 
3375     addr
.Hostname(hostname
); 
3378     wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
); 
3380     wxSocketClient client
; 
3381     if ( !client
.Connect(addr
) ) 
3383         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3387         wxPrintf(_T("--- Connected to %s:%u...\n"), 
3388                addr
.Hostname().c_str(), addr
.Service()); 
3392         // could use simply "GET" here I suppose 
3394             wxString::Format(_T("GET http://%s/\r\n"), hostname
); 
3395         client
.Write(cmdGet
, cmdGet
.length()); 
3396         wxPrintf(_T("--- Sent command '%s' to the server\n"), 
3397                MakePrintable(cmdGet
).c_str()); 
3398         client
.Read(buf
, WXSIZEOF(buf
)); 
3399         wxPrintf(_T("--- Server replied:\n%s"), buf
); 
3403 #endif // TEST_SOCKETS 
3405 // ---------------------------------------------------------------------------- 
3407 // ---------------------------------------------------------------------------- 
3411 #include "wx/protocol/ftp.h" 
3415 #define FTP_ANONYMOUS 
3417 #ifdef FTP_ANONYMOUS 
3418     static const wxChar 
*directory 
= _T("/pub"); 
3419     static const wxChar 
*filename 
= _T("welcome.msg"); 
3421     static const wxChar 
*directory 
= _T("/etc"); 
3422     static const wxChar 
*filename 
= _T("issue"); 
3425 static bool TestFtpConnect() 
3427     wxPuts(_T("*** Testing FTP connect ***")); 
3429 #ifdef FTP_ANONYMOUS 
3430     static const wxChar 
*hostname 
= _T("ftp.wxwindows.org"); 
3432     wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
); 
3433 #else // !FTP_ANONYMOUS 
3434     static const wxChar 
*hostname 
= "localhost"; 
3437     wxFgets(user
, WXSIZEOF(user
), stdin
); 
3438     user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n' 
3441     wxChar password
[256]; 
3442     wxPrintf(_T("Password for %s: "), password
); 
3443     wxFgets(password
, WXSIZEOF(password
), stdin
); 
3444     password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n' 
3445     ftp
.SetPassword(password
); 
3447     wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
); 
3448 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS 
3450     if ( !ftp
.Connect(hostname
) ) 
3452         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3458         wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"), 
3459                hostname
, ftp
.Pwd().c_str()); 
3465 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0? 
3466 static void TestFtpWuFtpd() 
3469     static const wxChar 
*hostname 
= _T("ftp.eudora.com"); 
3470     if ( !ftp
.Connect(hostname
) ) 
3472         wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
); 
3476         static const wxChar 
*filename 
= _T("eudora/pubs/draft-gellens-submit-09.txt"); 
3477         wxInputStream 
*in 
= ftp
.GetInputStream(filename
); 
3480             wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
); 
3484             size_t size 
= in
->GetSize(); 
3485             wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
); 
3487             wxChar 
*data 
= new wxChar
[size
]; 
3488             if ( !in
->Read(data
, size
) ) 
3490                 wxPuts(_T("ERROR: read error")); 
3494                 wxPrintf(_T("Successfully retrieved the file.\n")); 
3503 static void TestFtpList() 
3505     wxPuts(_T("*** Testing wxFTP file listing ***\n")); 
3508     if ( !ftp
.ChDir(directory
) ) 
3510         wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
); 
3513     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3515     // test NLIST and LIST 
3516     wxArrayString files
; 
3517     if ( !ftp
.GetFilesList(files
) ) 
3519         wxPuts(_T("ERROR: failed to get NLIST of files")); 
3523         wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str()); 
3524         size_t count 
= files
.GetCount(); 
3525         for ( size_t n 
= 0; n 
< count
; n
++ ) 
3527             wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3529         wxPuts(_T("End of the file list")); 
3532     if ( !ftp
.GetDirList(files
) ) 
3534         wxPuts(_T("ERROR: failed to get LIST of files")); 
3538         wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str()); 
3539         size_t count 
= files
.GetCount(); 
3540         for ( size_t n 
= 0; n 
< count
; n
++ ) 
3542             wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3544         wxPuts(_T("End of the file list")); 
3547     if ( !ftp
.ChDir(_T("..")) ) 
3549         wxPuts(_T("ERROR: failed to cd to ..")); 
3552     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3555 static void TestFtpDownload() 
3557     wxPuts(_T("*** Testing wxFTP download ***\n")); 
3560     wxInputStream 
*in 
= ftp
.GetInputStream(filename
); 
3563         wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
); 
3567         size_t size 
= in
->GetSize(); 
3568         wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
); 
3571         wxChar 
*data 
= new wxChar
[size
]; 
3572         if ( !in
->Read(data
, size
) ) 
3574             wxPuts(_T("ERROR: read error")); 
3578             wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
); 
3586 static void TestFtpFileSize() 
3588     wxPuts(_T("*** Testing FTP SIZE command ***")); 
3590     if ( !ftp
.ChDir(directory
) ) 
3592         wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
); 
3595     wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str()); 
3597     if ( ftp
.FileExists(filename
) ) 
3599         int size 
= ftp
.GetFileSize(filename
); 
3601             wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
); 
3603             wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
); 
3607         wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
); 
3611 static void TestFtpMisc() 
3613     wxPuts(_T("*** Testing miscellaneous wxFTP functions ***")); 
3615     if ( ftp
.SendCommand("STAT") != '2' ) 
3617         wxPuts(_T("ERROR: STAT failed")); 
3621         wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str()); 
3624     if ( ftp
.SendCommand("HELP SITE") != '2' ) 
3626         wxPuts(_T("ERROR: HELP SITE failed")); 
3630         wxPrintf(_T("The list of site-specific commands:\n\n%s\n"), 
3631                ftp
.GetLastResult().c_str()); 
3635 static void TestFtpInteractive() 
3637     wxPuts(_T("\n*** Interactive wxFTP test ***")); 
3643         wxPrintf(_T("Enter FTP command: ")); 
3644         if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) ) 
3647         // kill the last '\n' 
3648         buf
[wxStrlen(buf
) - 1] = 0; 
3650         // special handling of LIST and NLST as they require data connection 
3651         wxString 
start(buf
, 4); 
3653         if ( start 
== "LIST" || start 
== "NLST" ) 
3656             if ( wxStrlen(buf
) > 4 ) 
3659             wxArrayString files
; 
3660             if ( !ftp
.GetList(files
, wildcard
, start 
== "LIST") ) 
3662                 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str()); 
3666                 wxPrintf(_T("--- %s of '%s' under '%s':\n"), 
3667                        start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str()); 
3668                 size_t count 
= files
.GetCount(); 
3669                 for ( size_t n 
= 0; n 
< count
; n
++ ) 
3671                     wxPrintf(_T("\t%s\n"), files
[n
].c_str()); 
3673                 wxPuts(_T("--- End of the file list")); 
3678             wxChar ch 
= ftp
.SendCommand(buf
); 
3679             wxPrintf(_T("Command %s"), ch 
? _T("succeeded") : _T("failed")); 
3682                 wxPrintf(_T(" (return code %c)"), ch
); 
3685             wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str()); 
3689     wxPuts(_T("\n*** done ***")); 
3692 static void TestFtpUpload() 
3694     wxPuts(_T("*** Testing wxFTP uploading ***\n")); 
3697     static const wxChar 
*file1 
= _T("test1"); 
3698     static const wxChar 
*file2 
= _T("test2"); 
3699     wxOutputStream 
*out 
= ftp
.GetOutputStream(file1
); 
3702         wxPrintf(_T("--- Uploading to %s ---\n"), file1
); 
3703         out
->Write("First hello", 11); 
3707     // send a command to check the remote file 
3708     if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' ) 
3710         wxPrintf(_T("ERROR: STAT %s failed\n"), file1
); 
3714         wxPrintf(_T("STAT %s returned:\n\n%s\n"), 
3715                file1
, ftp
.GetLastResult().c_str()); 
3718     out 
= ftp
.GetOutputStream(file2
); 
3721         wxPrintf(_T("--- Uploading to %s ---\n"), file1
); 
3722         out
->Write("Second hello", 12); 
3729 // ---------------------------------------------------------------------------- 
3731 // ---------------------------------------------------------------------------- 
3735 #include "wx/wfstream.h" 
3736 #include "wx/mstream.h" 
3738 static void TestFileStream() 
3740     wxPuts(_T("*** Testing wxFileInputStream ***")); 
3742     static const wxChar 
*filename 
= _T("testdata.fs"); 
3744         wxFileOutputStream 
fsOut(filename
); 
3745         fsOut
.Write("foo", 3); 
3748     wxFileInputStream 
fsIn(filename
); 
3749     wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize()); 
3750     while ( !fsIn
.Eof() ) 
3752         putchar(fsIn
.GetC()); 
3755     if ( !wxRemoveFile(filename
) ) 
3757         wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
); 
3760     wxPuts(_T("\n*** wxFileInputStream test done ***")); 
3763 static void TestMemoryStream() 
3765     wxPuts(_T("*** Testing wxMemoryOutputStream ***")); 
3767     wxMemoryOutputStream memOutStream
; 
3768     wxPrintf(_T("Initially out stream offset: %lu\n"), 
3769              (unsigned long)memOutStream
.TellO()); 
3771     for ( const wxChar 
*p 
= _T("Hello, stream!"); *p
; p
++ ) 
3773         memOutStream
.PutC(*p
); 
3776     wxPrintf(_T("Final out stream offset: %lu\n"), 
3777              (unsigned long)memOutStream
.TellO()); 
3779     wxPuts(_T("*** Testing wxMemoryInputStream ***")); 
3782     size_t len 
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
)); 
3784     wxMemoryInputStream 
memInpStream(buf
, len
); 
3785     wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize()); 
3786     while ( !memInpStream
.Eof() ) 
3788         putchar(memInpStream
.GetC()); 
3791     wxPuts(_T("\n*** wxMemoryInputStream test done ***")); 
3794 #endif // TEST_STREAMS 
3796 // ---------------------------------------------------------------------------- 
3798 // ---------------------------------------------------------------------------- 
3802 #include "wx/timer.h" 
3803 #include "wx/utils.h" 
3805 static void TestStopWatch() 
3807     wxPuts(_T("*** Testing wxStopWatch ***\n")); 
3811     wxPrintf(_T("Initially paused, after 2 seconds time is...")); 
3814     wxPrintf(_T("\t%ldms\n"), sw
.Time()); 
3816     wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds...")); 
3820     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3823     wxPrintf(_T("Pausing agan and sleeping 2 more seconds...")); 
3826     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3829     wxPrintf(_T("Finally resuming and sleeping 2 more seconds...")); 
3832     wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time()); 
3835     wxPuts(_T("\nChecking for 'backwards clock' bug...")); 
3836     for ( size_t n 
= 0; n 
< 70; n
++ ) 
3840         for ( size_t m 
= 0; m 
< 100000; m
++ ) 
3842             if ( sw
.Time() < 0 || sw2
.Time() < 0 ) 
3844                 wxPuts(_T("\ntime is negative - ERROR!")); 
3852     wxPuts(_T(", ok.")); 
3855 #endif // TEST_TIMER 
3857 // ---------------------------------------------------------------------------- 
3859 // ---------------------------------------------------------------------------- 
3863 #include "wx/vcard.h" 
3865 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
) 
3868     wxVCardObject 
*vcObj 
= vcard
.GetFirstProp(&cookie
); 
3871         wxPrintf(_T("%s%s"), 
3872                wxString(_T('\t'), level
).c_str(), 
3873                vcObj
->GetName().c_str()); 
3876         switch ( vcObj
->GetType() ) 
3878             case wxVCardObject::String
: 
3879             case wxVCardObject::UString
: 
3882                     vcObj
->GetValue(&val
); 
3883                     value 
<< _T('"') << val 
<< _T('"'); 
3887             case wxVCardObject::Int
: 
3890                     vcObj
->GetValue(&i
); 
3891                     value
.Printf(_T("%u"), i
); 
3895             case wxVCardObject::Long
: 
3898                     vcObj
->GetValue(&l
); 
3899                     value
.Printf(_T("%lu"), l
); 
3903             case wxVCardObject::None
: 
3906             case wxVCardObject::Object
: 
3907                 value 
= _T("<node>"); 
3911                 value 
= _T("<unknown value type>"); 
3915             wxPrintf(_T(" = %s"), value
.c_str()); 
3918         DumpVObject(level 
+ 1, *vcObj
); 
3921         vcObj 
= vcard
.GetNextProp(&cookie
); 
3925 static void DumpVCardAddresses(const wxVCard
& vcard
) 
3927     wxPuts(_T("\nShowing all addresses from vCard:\n")); 
3931     wxVCardAddress 
*addr 
= vcard
.GetFirstAddress(&cookie
); 
3935         int flags 
= addr
->GetFlags(); 
3936         if ( flags 
& wxVCardAddress::Domestic 
) 
3938             flagsStr 
<< _T("domestic "); 
3940         if ( flags 
& wxVCardAddress::Intl 
) 
3942             flagsStr 
<< _T("international "); 
3944         if ( flags 
& wxVCardAddress::Postal 
) 
3946             flagsStr 
<< _T("postal "); 
3948         if ( flags 
& wxVCardAddress::Parcel 
) 
3950             flagsStr 
<< _T("parcel "); 
3952         if ( flags 
& wxVCardAddress::Home 
) 
3954             flagsStr 
<< _T("home "); 
3956         if ( flags 
& wxVCardAddress::Work 
) 
3958             flagsStr 
<< _T("work "); 
3961         wxPrintf(_T("Address %u:\n") 
3963                "\tvalue = %s;%s;%s;%s;%s;%s;%s\n", 
3966                addr
->GetPostOffice().c_str(), 
3967                addr
->GetExtAddress().c_str(), 
3968                addr
->GetStreet().c_str(), 
3969                addr
->GetLocality().c_str(), 
3970                addr
->GetRegion().c_str(), 
3971                addr
->GetPostalCode().c_str(), 
3972                addr
->GetCountry().c_str() 
3976         addr 
= vcard
.GetNextAddress(&cookie
); 
3980 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
) 
3982     wxPuts(_T("\nShowing all phone numbers from vCard:\n")); 
3986     wxVCardPhoneNumber 
*phone 
= vcard
.GetFirstPhoneNumber(&cookie
); 
3990         int flags 
= phone
->GetFlags(); 
3991         if ( flags 
& wxVCardPhoneNumber::Voice 
) 
3993             flagsStr 
<< _T("voice "); 
3995         if ( flags 
& wxVCardPhoneNumber::Fax 
) 
3997             flagsStr 
<< _T("fax "); 
3999         if ( flags 
& wxVCardPhoneNumber::Cellular 
) 
4001             flagsStr 
<< _T("cellular "); 
4003         if ( flags 
& wxVCardPhoneNumber::Modem 
) 
4005             flagsStr 
<< _T("modem "); 
4007         if ( flags 
& wxVCardPhoneNumber::Home 
) 
4009             flagsStr 
<< _T("home "); 
4011         if ( flags 
& wxVCardPhoneNumber::Work 
) 
4013             flagsStr 
<< _T("work "); 
4016         wxPrintf(_T("Phone number %u:\n") 
4021                phone
->GetNumber().c_str() 
4025         phone 
= vcard
.GetNextPhoneNumber(&cookie
); 
4029 static void TestVCardRead() 
4031     wxPuts(_T("*** Testing wxVCard reading ***\n")); 
4033     wxVCard 
vcard(_T("vcard.vcf")); 
4034     if ( !vcard
.IsOk() ) 
4036         wxPuts(_T("ERROR: couldn't load vCard.")); 
4040         // read individual vCard properties 
4041         wxVCardObject 
*vcObj 
= vcard
.GetProperty("FN"); 
4045             vcObj
->GetValue(&value
); 
4050             value 
= _T("<none>"); 
4053         wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str()); 
4056         if ( !vcard
.GetFullName(&value
) ) 
4058             value 
= _T("<none>"); 
4061         wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str()); 
4063         // now show how to deal with multiply occuring properties 
4064         DumpVCardAddresses(vcard
); 
4065         DumpVCardPhoneNumbers(vcard
); 
4067         // and finally show all 
4068         wxPuts(_T("\nNow dumping the entire vCard:\n") 
4069              "-----------------------------\n"); 
4071         DumpVObject(0, vcard
); 
4075 static void TestVCardWrite() 
4077     wxPuts(_T("*** Testing wxVCard writing ***\n")); 
4080     if ( !vcard
.IsOk() ) 
4082         wxPuts(_T("ERROR: couldn't create vCard.")); 
4087         vcard
.SetName("Zeitlin", "Vadim"); 
4088         vcard
.SetFullName("Vadim Zeitlin"); 
4089         vcard
.SetOrganization("wxWindows", "R&D"); 
4091         // just dump the vCard back 
4092         wxPuts(_T("Entire vCard follows:\n")); 
4093         wxPuts(vcard
.Write()); 
4097 #endif // TEST_VCARD 
4099 // ---------------------------------------------------------------------------- 
4101 // ---------------------------------------------------------------------------- 
4103 #if !defined(__WIN32__) || !wxUSE_FSVOLUME 
4109 #include "wx/volume.h" 
4111 static const wxChar 
*volumeKinds
[] = 
4117     _T("network volume"), 
4121 static void TestFSVolume() 
4123     wxPuts(_T("*** Testing wxFSVolume class ***")); 
4125     wxArrayString volumes 
= wxFSVolume::GetVolumes(); 
4126     size_t count 
= volumes
.GetCount(); 
4130         wxPuts(_T("ERROR: no mounted volumes?")); 
4134     wxPrintf(_T("%u mounted volumes found:\n"), count
); 
4136     for ( size_t n 
= 0; n 
< count
; n
++ ) 
4138         wxFSVolume 
vol(volumes
[n
]); 
4141             wxPuts(_T("ERROR: couldn't create volume")); 
4145         wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"), 
4147                  vol
.GetDisplayName().c_str(), 
4148                  vol
.GetName().c_str(), 
4149                  volumeKinds
[vol
.GetKind()], 
4150                  vol
.IsWritable() ? _T("rw") : _T("ro"), 
4151                  vol
.GetFlags() & wxFS_VOL_REMOVABLE 
? _T("removable") 
4156 #endif // TEST_VOLUME 
4158 // ---------------------------------------------------------------------------- 
4159 // wide char and Unicode support 
4160 // ---------------------------------------------------------------------------- 
4164 static void TestUnicodeToFromAscii() 
4166     wxPuts(_T("Testing wxString::To/FromAscii()\n")); 
4168     static const char *msg 
= "Hello, world!"; 
4169     wxString s 
= wxString::FromAscii(msg
); 
4171     wxPrintf(_T("Message in Unicode: %s\n"), s
.c_str()); 
4172     printf("Message in ASCII: %s\n", (const char *)s
.ToAscii()); 
4174     wxPutchar(_T('\n')); 
4177 #endif // TEST_UNICODE 
4181 #include "wx/strconv.h" 
4182 #include "wx/fontenc.h" 
4183 #include "wx/encconv.h" 
4184 #include "wx/buffer.h" 
4186 static const unsigned char utf8koi8r
[] = 
4188     208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176, 
4189     208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208, 
4190     176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188, 
4191     208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208, 
4192     181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181, 
4193     208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208, 
4194     178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0 
4197 static const unsigned char utf8iso8859_1
[] = 
4199     0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e, 
4200     0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65, 
4201     0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65, 
4202     0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65, 
4203     0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0 
4206 static const unsigned char utf8Invalid
[] = 
4208     0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30, 
4209     0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6, 
4210     0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88, 
4211     0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70, 
4215 static const struct Utf8Data
 
4217     const unsigned char *text
; 
4219     const wxChar 
*charset
; 
4220     wxFontEncoding encoding
; 
4223     { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 
}, 
4224     { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8 
}, 
4225     { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 
}, 
4228 static void TestUtf8() 
4230     wxPuts(_T("*** Testing UTF8 support ***\n")); 
4235     for ( size_t n 
= 0; n 
< WXSIZEOF(utf8data
); n
++ ) 
4237         const Utf8Data
& u8d 
= utf8data
[n
]; 
4238         if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
, 
4239                               WXSIZEOF(wbuf
)) == (size_t)-1 ) 
4241             wxPuts(_T("ERROR: UTF-8 decoding failed.")); 
4245             wxCSConv 
conv(u8d
.charset
); 
4246             if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 ) 
4248                 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
); 
4252                 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
); 
4256         wxString 
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
), *wxConvCurrent
); 
4258             s 
= _T("<< conversion failed >>"); 
4259         wxPrintf(_T("String in current cset: %s\n"), s
.c_str()); 
4266 static void TestEncodingConverter() 
4268     wxPuts(_T("*** Testing wxEncodingConverter ***\n")); 
4270     // using wxEncodingConverter should give the same result as above 
4273     if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
, 
4274                           WXSIZEOF(utf8koi8r
)) == (size_t)-1 ) 
4276         wxPuts(_T("ERROR: UTF-8 decoding failed.")); 
4280         wxEncodingConverter ec
; 
4281         ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
); 
4282         ec
.Convert(wbuf
, buf
); 
4283         wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
); 
4289 #endif // TEST_WCHAR 
4291 // ---------------------------------------------------------------------------- 
4293 // ---------------------------------------------------------------------------- 
4297 #include "wx/filesys.h" 
4298 #include "wx/fs_zip.h" 
4299 #include "wx/zipstrm.h" 
4301 static const wxChar 
*TESTFILE_ZIP 
= _T("testdata.zip"); 
4303 static void TestZipStreamRead() 
4305     wxPuts(_T("*** Testing ZIP reading ***\n")); 
4307     static const wxChar 
*filename 
= _T("foo"); 
4308     wxZipInputStream 
istr(TESTFILE_ZIP
, filename
); 
4309     wxPrintf(_T("Archive size: %u\n"), istr
.GetSize()); 
4311     wxPrintf(_T("Dumping the file '%s':\n"), filename
); 
4312     while ( !istr
.Eof() ) 
4314         putchar(istr
.GetC()); 
4318     wxPuts(_T("\n----- done ------")); 
4321 static void DumpZipDirectory(wxFileSystem
& fs
, 
4322                              const wxString
& dir
, 
4323                              const wxString
& indent
) 
4325     wxString prefix 
= wxString::Format(_T("%s#zip:%s"), 
4326                                          TESTFILE_ZIP
, dir
.c_str()); 
4327     wxString wildcard 
= prefix 
+ _T("/*"); 
4329     wxString dirname 
= fs
.FindFirst(wildcard
, wxDIR
); 
4330     while ( !dirname
.empty() ) 
4332         if ( !dirname
.StartsWith(prefix 
+ _T('/'), &dirname
) ) 
4334             wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); 
4339         wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str()); 
4341         DumpZipDirectory(fs
, dirname
, 
4342                          indent 
+ wxString(_T(' '), 4)); 
4344         dirname 
= fs
.FindNext(); 
4347     wxString filename 
= fs
.FindFirst(wildcard
, wxFILE
); 
4348     while ( !filename
.empty() ) 
4350         if ( !filename
.StartsWith(prefix
, &filename
) ) 
4352             wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); 
4357         wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str()); 
4359         filename 
= fs
.FindNext(); 
4363 static void TestZipFileSystem() 
4365     wxPuts(_T("*** Testing ZIP file system ***\n")); 
4367     wxFileSystem::AddHandler(new wxZipFSHandler
); 
4369     wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
); 
4371     DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4)); 
4376 // ---------------------------------------------------------------------------- 
4378 // ---------------------------------------------------------------------------- 
4382 #include "wx/zstream.h" 
4383 #include "wx/wfstream.h" 
4385 static const wxChar 
*FILENAME_GZ 
= _T("test.gz"); 
4386 static const wxChar 
*TEST_DATA 
= _T("hello and hello and hello and hello and hello"); 
4388 static void TestZlibStreamWrite() 
4390     wxPuts(_T("*** Testing Zlib stream reading ***\n")); 
4392     wxFileOutputStream 
fileOutStream(FILENAME_GZ
); 
4393     wxZlibOutputStream 
ostr(fileOutStream
); 
4394     wxPrintf(_T("Compressing the test string... ")); 
4395     ostr
.Write(TEST_DATA
, wxStrlen(TEST_DATA
) + 1); 
4398         wxPuts(_T("(ERROR: failed)")); 
4405     wxPuts(_T("\n----- done ------")); 
4408 static void TestZlibStreamRead() 
4410     wxPuts(_T("*** Testing Zlib stream reading ***\n")); 
4412     wxFileInputStream 
fileInStream(FILENAME_GZ
); 
4413     wxZlibInputStream 
istr(fileInStream
); 
4414     wxPrintf(_T("Archive size: %u\n"), istr
.GetSize()); 
4416     wxPuts(_T("Dumping the file:")); 
4417     while ( !istr
.Eof() ) 
4419         putchar(istr
.GetC()); 
4423     wxPuts(_T("\n----- done ------")); 
4428 // ---------------------------------------------------------------------------- 
4430 // ---------------------------------------------------------------------------- 
4432 #ifdef TEST_DATETIME 
4436 #include "wx/datetime.h" 
4441     wxDateTime::wxDateTime_t day
; 
4442     wxDateTime::Month month
; 
4444     wxDateTime::wxDateTime_t hour
, min
, sec
; 
4446     wxDateTime::WeekDay wday
; 
4447     time_t gmticks
, ticks
; 
4449     void Init(const wxDateTime::Tm
& tm
) 
4458         gmticks 
= ticks 
= -1; 
4461     wxDateTime 
DT() const 
4462         { return wxDateTime(day
, month
, year
, hour
, min
, sec
); } 
4464     bool SameDay(const wxDateTime::Tm
& tm
) const 
4466         return day 
== tm
.mday 
&& month 
== tm
.mon 
&& year 
== tm
.year
; 
4469     wxString 
Format() const 
4472         s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"), 
4474                  wxDateTime::GetMonthName(month
).c_str(), 
4476                  abs(wxDateTime::ConvertYearToBC(year
)), 
4477                  year 
> 0 ? _T("AD") : _T("BC")); 
4481     wxString 
FormatDate() const 
4484         s
.Printf(_T("%02d-%s-%4d%s"), 
4486                  wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(), 
4487                  abs(wxDateTime::ConvertYearToBC(year
)), 
4488                  year 
> 0 ? _T("AD") : _T("BC")); 
4493 static const Date testDates
[] = 
4495     {  1, wxDateTime::Jan
,  1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
,         0,     -3600 }, 
4496     {  7, wxDateTime::Feb
,  2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
,        -1,        -1 }, 
4497     {  8, wxDateTime::Feb
,  2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
,        -1,        -1 }, 
4498     {  1, wxDateTime::Jan
,  2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
,        -1,        -1 }, 
4499     {  1, wxDateTime::Jan
,  2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
,        -1,        -1 }, 
4500     { 21, wxDateTime::Jan
,  2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
,        -1,        -1 }, 
4501     { 29, wxDateTime::May
,  1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 }, 
4502     { 29, wxDateTime::Feb
,  1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 }, 
4503     {  1, wxDateTime::Jan
,  1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
,        -1,        -1 }, 
4504     {  1, wxDateTime::Jan
,  1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
,        -1,        -1 }, 
4505     { 15, wxDateTime::Oct
,  1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
,        -1,        -1 }, 
4506     {  4, wxDateTime::Oct
,  1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
,        -1,        -1 }, 
4507     {  1, wxDateTime::Mar
,     1, 00, 00, 00, 1721484.5, wxDateTime::Thu
,        -1,        -1 }, 
4508     {  1, wxDateTime::Jan
,     1, 00, 00, 00, 1721425.5, wxDateTime::Mon
,        -1,        -1 }, 
4509     { 31, wxDateTime::Dec
,     0, 00, 00, 00, 1721424.5, wxDateTime::Sun
,        -1,        -1 }, 
4510     {  1, wxDateTime::Jan
,     0, 00, 00, 00, 1721059.5, wxDateTime::Sat
,        -1,        -1 }, 
4511     { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
,        -1,        -1 }, 
4512     { 12, wxDateTime::Aug
, -4000, 00, 00, 00,  260313.5, wxDateTime::Sat
,        -1,        -1 }, 
4513     { 24, wxDateTime::Nov
, -4713, 00, 00, 00,      -0.5, wxDateTime::Mon
,        -1,        -1 }, 
4516 // this test miscellaneous static wxDateTime functions 
4517 static void TestTimeStatic() 
4519     wxPuts(_T("\n*** wxDateTime static methods test ***")); 
4521     // some info about the current date 
4522     int year 
= wxDateTime::GetCurrentYear(); 
4523     wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"), 
4525            wxDateTime::IsLeapYear(year
) ? "" : "not ", 
4526            wxDateTime::GetNumberOfDays(year
)); 
4528     wxDateTime::Month month 
= wxDateTime::GetCurrentMonth(); 
4529     wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"), 
4530            wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(), 
4531            wxDateTime::GetMonthName(month
).c_str(), 
4532            wxDateTime::GetNumberOfDays(month
)); 
4535     static const size_t nYears 
= 5; 
4536     static const size_t years
[2][nYears
] = 
4538         // first line: the years to test 
4539         { 1990, 1976, 2000, 2030, 1984, }, 
4541         // second line: true if leap, false otherwise 
4542         { false, true, true, false, true } 
4545     for ( size_t n 
= 0; n 
< nYears
; n
++ ) 
4547         int year 
= years
[0][n
]; 
4548         bool should 
= years
[1][n
] != 0, 
4549              is 
= wxDateTime::IsLeapYear(year
); 
4551         wxPrintf(_T("Year %d is %sa leap year (%s)\n"), 
4554                should 
== is 
? "ok" : "ERROR"); 
4556         wxASSERT( should 
== wxDateTime::IsLeapYear(year
) ); 
4560 // test constructing wxDateTime objects 
4561 static void TestTimeSet() 
4563     wxPuts(_T("\n*** wxDateTime construction test ***")); 
4565     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4567         const Date
& d1 
= testDates
[n
]; 
4568         wxDateTime dt 
= d1
.DT(); 
4571         d2
.Init(dt
.GetTm()); 
4573         wxString s1 
= d1
.Format(), 
4576         wxPrintf(_T("Date: %s == %s (%s)\n"), 
4577                  s1
.c_str(), s2
.c_str(), 
4578                  s1 
== s2 
? _T("ok") : _T("ERROR")); 
4582 // test time zones stuff 
4583 static void TestTimeZones() 
4585     wxPuts(_T("\n*** wxDateTime timezone test ***")); 
4587     wxDateTime now 
= wxDateTime::Now(); 
4589     wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str()); 
4590     wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str()); 
4591     wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str()); 
4592     wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str()); 
4593     wxPrintf(_T("               Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str()); 
4594     wxPrintf(_T("             New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str()); 
4596     wxDateTime::Tm tm 
= now
.GetTm(); 
4597     if ( wxDateTime(tm
) != now 
) 
4599         wxPrintf(_T("ERROR: got %s instead of %s\n"), 
4600                  wxDateTime(tm
).Format().c_str(), now
.Format().c_str()); 
4604 // test some minimal support for the dates outside the standard range 
4605 static void TestTimeRange() 
4607     wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***")); 
4609     static const wxChar 
*fmt 
= _T("%d-%b-%Y %H:%M:%S"); 
4611     wxPrintf(_T("Unix epoch:\t%s\n"), 
4612              wxDateTime(2440587.5).Format(fmt
).c_str()); 
4613     wxPrintf(_T("Feb 29, 0: \t%s\n"), 
4614              wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str()); 
4615     wxPrintf(_T("JDN 0:     \t%s\n"), 
4616              wxDateTime(0.0).Format(fmt
).c_str()); 
4617     wxPrintf(_T("Jan 1, 1AD:\t%s\n"), 
4618              wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str()); 
4619     wxPrintf(_T("May 29, 2099:\t%s\n"), 
4620              wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str()); 
4623 static void TestTimeTicks() 
4625     wxPuts(_T("\n*** wxDateTime ticks test ***")); 
4627     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4629         const Date
& d 
= testDates
[n
]; 
4630         if ( d
.ticks 
== -1 ) 
4633         wxDateTime dt 
= d
.DT(); 
4634         long ticks 
= (dt
.GetValue() / 1000).ToLong(); 
4635         wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
); 
4636         if ( ticks 
== d
.ticks 
) 
4638             wxPuts(_T(" (ok)")); 
4642             wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"), 
4643                      (long)d
.ticks
, (long)(ticks 
- d
.ticks
)); 
4646         dt 
= d
.DT().ToTimezone(wxDateTime::GMT0
); 
4647         ticks 
= (dt
.GetValue() / 1000).ToLong(); 
4648         wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
); 
4649         if ( ticks 
== d
.gmticks 
) 
4651             wxPuts(_T(" (ok)")); 
4655             wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"), 
4656                      (long)d
.gmticks
, (long)(ticks 
- d
.gmticks
)); 
4663 // test conversions to JDN &c 
4664 static void TestTimeJDN() 
4666     wxPuts(_T("\n*** wxDateTime to JDN test ***")); 
4668     for ( size_t n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4670         const Date
& d 
= testDates
[n
]; 
4671         wxDateTime 
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
); 
4672         double jdn 
= dt
.GetJulianDayNumber(); 
4674         wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
); 
4677             wxPuts(_T(" (ok)")); 
4681             wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"), 
4682                      d
.jdn
, jdn 
- d
.jdn
); 
4687 // test week days computation 
4688 static void TestTimeWDays() 
4690     wxPuts(_T("\n*** wxDateTime weekday test ***")); 
4692     // test GetWeekDay() 
4694     for ( n 
= 0; n 
< WXSIZEOF(testDates
); n
++ ) 
4696         const Date
& d 
= testDates
[n
]; 
4697         wxDateTime 
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
); 
4699         wxDateTime::WeekDay wday 
= dt
.GetWeekDay(); 
4700         wxPrintf(_T("%s is: %s"), 
4702                  wxDateTime::GetWeekDayName(wday
).c_str()); 
4703         if ( wday 
== d
.wday 
) 
4705             wxPuts(_T(" (ok)")); 
4709             wxPrintf(_T(" (ERROR: should be %s)\n"), 
4710                      wxDateTime::GetWeekDayName(d
.wday
).c_str()); 
4716     // test SetToWeekDay() 
4717     struct WeekDateTestData
 
4719         Date date
;                  // the real date (precomputed) 
4720         int nWeek
;                  // its week index in the month 
4721         wxDateTime::WeekDay wday
;   // the weekday 
4722         wxDateTime::Month month
;    // the month 
4723         int year
;                   // and the year 
4725         wxString 
Format() const 
4728             switch ( nWeek 
< -1 ? -nWeek 
: nWeek 
) 
4730                 case 1: which 
= _T("first"); break; 
4731                 case 2: which 
= _T("second"); break; 
4732                 case 3: which 
= _T("third"); break; 
4733                 case 4: which 
= _T("fourth"); break; 
4734                 case 5: which 
= _T("fifth"); break; 
4736                 case -1: which 
= _T("last"); break; 
4741                 which 
+= _T(" from end"); 
4744             s
.Printf(_T("The %s %s of %s in %d"), 
4746                      wxDateTime::GetWeekDayName(wday
).c_str(), 
4747                      wxDateTime::GetMonthName(month
).c_str(), 
4754     // the array data was generated by the following python program 
4756 from DateTime import * 
4757 from whrandom import * 
4758 from string import * 
4760 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] 
4761 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ] 
4763 week = DateTimeDelta(7) 
4766     year = randint(1900, 2100) 
4767     month = randint(1, 12) 
4768     day = randint(1, 28) 
4769     dt = DateTime(year, month, day) 
4770     wday = dt.day_of_week 
4772     countFromEnd = choice([-1, 1]) 
4775     while dt.month is month: 
4776         dt = dt - countFromEnd * week 
4777         weekNum = weekNum + countFromEnd 
4779     data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] } 
4781     print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\ 
4782           "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data 
4785     static const WeekDateTestData weekDatesTestData
[] = 
4787         { { 20, wxDateTime::Mar
, 2045 },  3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 }, 
4788         { {  5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 }, 
4789         { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 }, 
4790         { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 }, 
4791         { {  4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 }, 
4792         { {  2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 }, 
4793         { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 }, 
4794         { {  5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 }, 
4795         { { 11, wxDateTime::Aug
, 1900 },  2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 }, 
4796         { { 14, wxDateTime::Feb
, 1945 },  2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 }, 
4797         { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 }, 
4798         { {  9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 }, 
4799         { { 20, wxDateTime::Jun
, 1927 },  3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 }, 
4800         { {  2, wxDateTime::Aug
, 2000 },  1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 }, 
4801         { { 20, wxDateTime::Apr
, 2044 },  3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 }, 
4802         { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 }, 
4803         { { 25, wxDateTime::Jul
, 2069 },  4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 }, 
4804         { {  3, wxDateTime::Apr
, 1925 },  1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 }, 
4805         { { 21, wxDateTime::Mar
, 2093 },  3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 }, 
4806         { {  3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 }, 
4809     static const wxChar 
*fmt 
= _T("%d-%b-%Y"); 
4812     for ( n 
= 0; n 
< WXSIZEOF(weekDatesTestData
); n
++ ) 
4814         const WeekDateTestData
& wd 
= weekDatesTestData
[n
]; 
4816         dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
); 
4818         wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str()); 
4820         const Date
& d 
= wd
.date
; 
4821         if ( d
.SameDay(dt
.GetTm()) ) 
4823             wxPuts(_T(" (ok)")); 
4827             dt
.Set(d
.day
, d
.month
, d
.year
); 
4829             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str()); 
4834 // test the computation of (ISO) week numbers 
4835 static void TestTimeWNumber() 
4837     wxPuts(_T("\n*** wxDateTime week number test ***")); 
4839     struct WeekNumberTestData
 
4841         Date date
;                          // the date 
4842         wxDateTime::wxDateTime_t week
;      // the week number in the year 
4843         wxDateTime::wxDateTime_t wmon
;      // the week number in the month 
4844         wxDateTime::wxDateTime_t wmon2
;     // same but week starts with Sun 
4845         wxDateTime::wxDateTime_t dnum
;      // day number in the year 
4848     // data generated with the following python script: 
4850 from DateTime import * 
4851 from whrandom import * 
4852 from string import * 
4854 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] 
4855 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ] 
4857 def GetMonthWeek(dt): 
4858     weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1 
4859     if weekNumMonth < 0: 
4860         weekNumMonth = weekNumMonth + 53 
4863 def GetLastSundayBefore(dt): 
4864     if dt.iso_week[2] == 7: 
4867         return dt - DateTimeDelta(dt.iso_week[2]) 
4870     year = randint(1900, 2100) 
4871     month = randint(1, 12) 
4872     day = randint(1, 28) 
4873     dt = DateTime(year, month, day) 
4874     dayNum = dt.day_of_year 
4875     weekNum = dt.iso_week[1] 
4876     weekNumMonth = GetMonthWeek(dt) 
4879     dtSunday = GetLastSundayBefore(dt) 
4881     while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)): 
4882         weekNumMonth2 = weekNumMonth2 + 1 
4883         dtSunday = dtSunday - DateTimeDelta(7) 
4885     data = { 'day': rjust(`day`, 2), \ 
4886              'month': monthNames[month - 1], \ 
4888              'weekNum': rjust(`weekNum`, 2), \ 
4889              'weekNumMonth': weekNumMonth, \ 
4890              'weekNumMonth2': weekNumMonth2, \ 
4891              'dayNum': rjust(`dayNum`, 3) } 
4893     print "        { { %(day)s, "\ 
4894           "wxDateTime::%(month)s, "\ 
4897           "%(weekNumMonth)s, "\ 
4898           "%(weekNumMonth2)s, "\ 
4899           "%(dayNum)s }," % data 
4902     static const WeekNumberTestData weekNumberTestDates
[] = 
4904         { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 }, 
4905         { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 }, 
4906         { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 }, 
4907         { {  1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 }, 
4908         { {  8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 }, 
4909         { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4,  81 }, 
4910         { {  7, wxDateTime::Jan
, 1965 },  1, 2, 2,   7 }, 
4911         { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 }, 
4912         { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 }, 
4913         { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 }, 
4914         { {  2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 }, 
4915         { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 }, 
4916         { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 }, 
4917         { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 }, 
4918         { {  3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 }, 
4919         { { 23, wxDateTime::Feb
, 1940 },  8, 4, 4,  54 }, 
4920         { {  2, wxDateTime::Jan
, 1987 },  1, 1, 1,   2 }, 
4921         { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 }, 
4922         { {  2, wxDateTime::Feb
, 2063 },  5, 1, 1,  33 }, 
4923         { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 }, 
4926     for ( size_t n 
= 0; n 
< WXSIZEOF(weekNumberTestDates
); n
++ ) 
4928         const WeekNumberTestData
& wn 
= weekNumberTestDates
[n
]; 
4929         const Date
& d 
= wn
.date
; 
4931         wxDateTime dt 
= d
.DT(); 
4933         wxDateTime::wxDateTime_t
 
4934             week 
= dt
.GetWeekOfYear(wxDateTime::Monday_First
), 
4935             wmon 
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
), 
4936             wmon2 
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
), 
4937             dnum 
= dt
.GetDayOfYear(); 
4939         wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
); 
4940         if ( dnum 
== wn
.dnum 
) 
4942             wxPrintf(_T(" (ok)")); 
4946             wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
); 
4949         wxPrintf(_T(", week in month = %d"), wmon
); 
4950         if ( wmon 
!= wn
.wmon 
) 
4952             wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
); 
4955         wxPrintf(_T(" or %d"), wmon2
); 
4956         if ( wmon2 
== wn
.wmon2 
) 
4958             wxPrintf(_T(" (ok)")); 
4962             wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
); 
4965         wxPrintf(_T(", week in year = %d"), week
); 
4966         if ( week 
!= wn
.week 
) 
4968             wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
); 
4971         wxPutchar(_T('\n')); 
4973         wxDateTime 
dt2(1, wxDateTime::Jan
, d
.year
); 
4974         dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay()); 
4978             d2
.Init(dt2
.GetTm()); 
4979             wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"), 
4980                      d2
.FormatDate().c_str()); 
4985 // test DST calculations 
4986 static void TestTimeDST() 
4988     wxPuts(_T("\n*** wxDateTime DST test ***")); 
4990     wxPrintf(_T("DST is%s in effect now.\n\n"), 
4991              wxDateTime::Now().IsDST() ? _T("") : _T(" not")); 
4993     // taken from http://www.energy.ca.gov/daylightsaving.html 
4994     static const Date datesDST
[2][2004 - 1900 + 1] = 
4997             { 1, wxDateTime::Apr
, 1990 }, 
4998             { 7, wxDateTime::Apr
, 1991 }, 
4999             { 5, wxDateTime::Apr
, 1992 }, 
5000             { 4, wxDateTime::Apr
, 1993 }, 
5001             { 3, wxDateTime::Apr
, 1994 }, 
5002             { 2, wxDateTime::Apr
, 1995 }, 
5003             { 7, wxDateTime::Apr
, 1996 }, 
5004             { 6, wxDateTime::Apr
, 1997 }, 
5005             { 5, wxDateTime::Apr
, 1998 }, 
5006             { 4, wxDateTime::Apr
, 1999 }, 
5007             { 2, wxDateTime::Apr
, 2000 }, 
5008             { 1, wxDateTime::Apr
, 2001 }, 
5009             { 7, wxDateTime::Apr
, 2002 }, 
5010             { 6, wxDateTime::Apr
, 2003 }, 
5011             { 4, wxDateTime::Apr
, 2004 }, 
5014             { 28, wxDateTime::Oct
, 1990 }, 
5015             { 27, wxDateTime::Oct
, 1991 }, 
5016             { 25, wxDateTime::Oct
, 1992 }, 
5017             { 31, wxDateTime::Oct
, 1993 }, 
5018             { 30, wxDateTime::Oct
, 1994 }, 
5019             { 29, wxDateTime::Oct
, 1995 }, 
5020             { 27, wxDateTime::Oct
, 1996 }, 
5021             { 26, wxDateTime::Oct
, 1997 }, 
5022             { 25, wxDateTime::Oct
, 1998 }, 
5023             { 31, wxDateTime::Oct
, 1999 }, 
5024             { 29, wxDateTime::Oct
, 2000 }, 
5025             { 28, wxDateTime::Oct
, 2001 }, 
5026             { 27, wxDateTime::Oct
, 2002 }, 
5027             { 26, wxDateTime::Oct
, 2003 }, 
5028             { 31, wxDateTime::Oct
, 2004 }, 
5033     for ( year 
= 1990; year 
< 2005; year
++ ) 
5035         wxDateTime dtBegin 
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
), 
5036                    dtEnd 
= wxDateTime::GetEndDST(year
, wxDateTime::USA
); 
5038         wxPrintf(_T("DST period in the US for year %d: from %s to %s"), 
5039                  year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str()); 
5041         size_t n 
= year 
- 1990; 
5042         const Date
& dBegin 
= datesDST
[0][n
]; 
5043         const Date
& dEnd 
= datesDST
[1][n
]; 
5045         if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) ) 
5047             wxPuts(_T(" (ok)")); 
5051             wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"), 
5052                      wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
, 
5053                      wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
); 
5059     for ( year 
= 1990; year 
< 2005; year
++ ) 
5061         wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"), 
5063                  wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(), 
5064                  wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str()); 
5068 // test wxDateTime -> text conversion 
5069 static void TestTimeFormat() 
5071     wxPuts(_T("\n*** wxDateTime formatting test ***")); 
5073     // some information may be lost during conversion, so store what kind 
5074     // of info should we recover after a round trip 
5077         CompareNone
,        // don't try comparing 
5078         CompareBoth
,        // dates and times should be identical 
5079         CompareDate
,        // dates only 
5080         CompareTime         
// time only 
5085         CompareKind compareKind
; 
5086         const wxChar 
*format
; 
5087     } formatTestFormats
[] = 
5089        { CompareBoth
, _T("---> %c") }, 
5090        { CompareDate
, _T("Date is %A, %d of %B, in year %Y") }, 
5091        { CompareBoth
, _T("Date is %x, time is %X") }, 
5092        { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") }, 
5093        { CompareNone
, _T("The day of year: %j, the week of year: %W") }, 
5094        { CompareDate
, _T("ISO date without separators: %Y%m%d") }, 
5097     static const Date formatTestDates
[] = 
5099         { 29, wxDateTime::May
, 1976, 18, 30, 00 }, 
5100         { 31, wxDateTime::Dec
, 1999, 23, 30, 00 }, 
5102         // this test can't work for other centuries because it uses two digit 
5103         // years in formats, so don't even try it 
5104         { 29, wxDateTime::May
, 2076, 18, 30, 00 }, 
5105         { 29, wxDateTime::Feb
, 2400, 02, 15, 25 }, 
5106         { 01, wxDateTime::Jan
,  -52, 03, 16, 47 }, 
5110     // an extra test (as it doesn't depend on date, don't do it in the loop) 
5111     wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str()); 
5113     for ( size_t d 
= 0; d 
< WXSIZEOF(formatTestDates
) + 1; d
++ ) 
5117         wxDateTime dt 
= d 
== 0 ? wxDateTime::Now() : formatTestDates
[d 
- 1].DT(); 
5118         for ( size_t n 
= 0; n 
< WXSIZEOF(formatTestFormats
); n
++ ) 
5120             wxString s 
= dt
.Format(formatTestFormats
[n
].format
); 
5121             wxPrintf(_T("%s"), s
.c_str()); 
5123             // what can we recover? 
5124             int kind 
= formatTestFormats
[n
].compareKind
; 
5128             const wxChar 
*result 
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
); 
5131                 // converion failed - should it have? 
5132                 if ( kind 
== CompareNone 
) 
5133                     wxPuts(_T(" (ok)")); 
5135                     wxPuts(_T(" (ERROR: conversion back failed)")); 
5139                 // should have parsed the entire string 
5140                 wxPuts(_T(" (ERROR: conversion back stopped too soon)")); 
5144                 bool equal 
= false; // suppress compilaer warning 
5152                         equal 
= dt
.IsSameDate(dt2
); 
5156                         equal 
= dt
.IsSameTime(dt2
); 
5162                     wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"), 
5163                            dt2
.Format().c_str(), dt
.Format().c_str()); 
5167                     wxPuts(_T(" (ok)")); 
5174 // test text -> wxDateTime conversion 
5175 static void TestTimeParse() 
5177     wxPuts(_T("\n*** wxDateTime parse test ***")); 
5179     struct ParseTestData
 
5181         const wxChar 
*format
; 
5186     static const ParseTestData parseTestDates
[] = 
5188         { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true }, 
5189         { _T("Wed, 1 Dec 1999 05:17:20 +0300"),  {  1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true }, 
5192     for ( size_t n 
= 0; n 
< WXSIZEOF(parseTestDates
); n
++ ) 
5194         const wxChar 
*format 
= parseTestDates
[n
].format
; 
5196         wxPrintf(_T("%s => "), format
); 
5199         if ( dt
.ParseRfc822Date(format
) ) 
5201             wxPrintf(_T("%s "), dt
.Format().c_str()); 
5203             if ( parseTestDates
[n
].good 
) 
5205                 wxDateTime dtReal 
= parseTestDates
[n
].date
.DT(); 
5212                     wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str()); 
5217                 wxPuts(_T("(ERROR: bad format)")); 
5222             wxPrintf(_T("bad format (%s)\n"), 
5223                    parseTestDates
[n
].good 
? "ERROR" : "ok"); 
5228 static void TestDateTimeInteractive() 
5230     wxPuts(_T("\n*** interactive wxDateTime tests ***")); 
5236         wxPrintf(_T("Enter a date: ")); 
5237         if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) ) 
5240         // kill the last '\n' 
5241         buf
[wxStrlen(buf
) - 1] = 0; 
5244         const wxChar 
*p 
= dt
.ParseDate(buf
); 
5247             wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
); 
5253             wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p 
- buf
); 
5256         wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"), 
5257                  dt
.Format(_T("%b %d, %Y")).c_str(), 
5259                  dt
.GetWeekOfMonth(wxDateTime::Monday_First
), 
5260                  dt
.GetWeekOfMonth(wxDateTime::Sunday_First
), 
5261                  dt
.GetWeekOfYear(wxDateTime::Monday_First
)); 
5264     wxPuts(_T("\n*** done ***")); 
5267 static void TestTimeMS() 
5269     wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***")); 
5271     wxDateTime dt1 
= wxDateTime::Now(), 
5272                dt2 
= wxDateTime::UNow(); 
5274     wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str()); 
5275     wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str()); 
5276     wxPrintf(_T("Dummy loop: ")); 
5277     for ( int i 
= 0; i 
< 6000; i
++ ) 
5279         //for ( int j = 0; j < 10; j++ ) 
5282             s
.Printf(_T("%g"), sqrt(i
)); 
5288     wxPuts(_T(", done")); 
5291     dt2 
= wxDateTime::UNow(); 
5292     wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str()); 
5294     wxPrintf(_T("Loop executed in %s ms\n"), (dt2 
- dt1
).Format(_T("%l")).c_str()); 
5296     wxPuts(_T("\n*** done ***")); 
5299 static void TestTimeArithmetics() 
5301     wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***")); 
5303     static const struct ArithmData
 
5305         ArithmData(const wxDateSpan
& sp
, const wxChar 
*nam
) 
5306             : span(sp
), name(nam
) { } 
5310     } testArithmData
[] = 
5312         ArithmData(wxDateSpan::Day(), _T("day")), 
5313         ArithmData(wxDateSpan::Week(), _T("week")), 
5314         ArithmData(wxDateSpan::Month(), _T("month")), 
5315         ArithmData(wxDateSpan::Year(), _T("year")), 
5316         ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")), 
5319     wxDateTime 
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
; 
5321     for ( size_t n 
= 0; n 
< WXSIZEOF(testArithmData
); n
++ ) 
5323         wxDateSpan span 
= testArithmData
[n
].span
; 
5327         const wxChar 
*name 
= testArithmData
[n
].name
; 
5328         wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"), 
5329                dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(), 
5330                dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str()); 
5332         wxPrintf(_T("Going back: %s"), (dt1 
- span
).FormatISODate().c_str()); 
5333         if ( dt1 
- span 
== dt 
) 
5335             wxPuts(_T(" (ok)")); 
5339             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str()); 
5342         wxPrintf(_T("Going forward: %s"), (dt2 
+ span
).FormatISODate().c_str()); 
5343         if ( dt2 
+ span 
== dt 
) 
5345             wxPuts(_T(" (ok)")); 
5349             wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str()); 
5352         wxPrintf(_T("Double increment: %s"), (dt2 
+ 2*span
).FormatISODate().c_str()); 
5353         if ( dt2 
+ 2*span 
== dt1 
) 
5355             wxPuts(_T(" (ok)")); 
5359             wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str()); 
5366 static void TestTimeHolidays() 
5368     wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n")); 
5370     wxDateTime::Tm tm 
= wxDateTime(29, wxDateTime::May
, 2000).GetTm(); 
5371     wxDateTime 
dtStart(1, tm
.mon
, tm
.year
), 
5372                dtEnd 
= dtStart
.GetLastMonthDay(); 
5374     wxDateTimeArray hol
; 
5375     wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
); 
5377     const wxChar 
*format 
= _T("%d-%b-%Y (%a)"); 
5379     wxPrintf(_T("All holidays between %s and %s:\n"), 
5380            dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str()); 
5382     size_t count 
= hol
.GetCount(); 
5383     for ( size_t n 
= 0; n 
< count
; n
++ ) 
5385         wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str()); 
5391 static void TestTimeZoneBug() 
5393     wxPuts(_T("\n*** testing for DST/timezone bug ***\n")); 
5395     wxDateTime date 
= wxDateTime(1, wxDateTime::Mar
, 2000); 
5396     for ( int i 
= 0; i 
< 31; i
++ ) 
5398         wxPrintf(_T("Date %s: week day %s.\n"), 
5399                date
.Format(_T("%d-%m-%Y")).c_str(), 
5400                date
.GetWeekDayName(date
.GetWeekDay()).c_str()); 
5402         date 
+= wxDateSpan::Day(); 
5408 static void TestTimeSpanFormat() 
5410     wxPuts(_T("\n*** wxTimeSpan tests ***")); 
5412     static const wxChar 
*formats
[] = 
5414         _T("(default) %H:%M:%S"), 
5415         _T("%E weeks and %D days"), 
5416         _T("%l milliseconds"), 
5417         _T("(with ms) %H:%M:%S:%l"), 
5418         _T("100%% of minutes is %M"),       // test "%%" 
5419         _T("%D days and %H hours"), 
5420         _T("or also %S seconds"), 
5423     wxTimeSpan 
ts1(1, 2, 3, 4), 
5425     for ( size_t n 
= 0; n 
< WXSIZEOF(formats
); n
++ ) 
5427         wxPrintf(_T("ts1 = %s\tts2 = %s\n"), 
5428                ts1
.Format(formats
[n
]).c_str(), 
5429                ts2
.Format(formats
[n
]).c_str()); 
5435 #endif // TEST_DATETIME 
5437 // ---------------------------------------------------------------------------- 
5438 // wxTextInput/OutputStream 
5439 // ---------------------------------------------------------------------------- 
5441 #ifdef TEST_TEXTSTREAM 
5443 #include "wx/txtstrm.h" 
5444 #include "wx/wfstream.h" 
5446 static void TestTextInputStream() 
5448     wxPuts(_T("\n*** wxTextInputStream test ***")); 
5450     wxFileInputStream 
fsIn(_T("testdata.fc")); 
5453         wxPuts(_T("ERROR: couldn't open file.")); 
5457         wxTextInputStream 
tis(fsIn
); 
5462             const wxString s 
= tis
.ReadLine(); 
5464             // line could be non empty if the last line of the file isn't 
5465             // terminated with EOL 
5466             if ( fsIn
.Eof() && s
.empty() ) 
5469             wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str()); 
5474 #endif // TEST_TEXTSTREAM 
5476 // ---------------------------------------------------------------------------- 
5478 // ---------------------------------------------------------------------------- 
5482 #include "wx/thread.h" 
5484 static size_t gs_counter 
= (size_t)-1; 
5485 static wxCriticalSection gs_critsect
; 
5486 static wxSemaphore gs_cond
; 
5488 class MyJoinableThread 
: public wxThread
 
5491     MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
) 
5492         { m_n 
= n
; Create(); } 
5494     // thread execution starts here 
5495     virtual ExitCode 
Entry(); 
5501 wxThread::ExitCode 
MyJoinableThread::Entry() 
5503     unsigned long res 
= 1; 
5504     for ( size_t n 
= 1; n 
< m_n
; n
++ ) 
5508         // it's a loooong calculation :-) 
5512     return (ExitCode
)res
; 
5515 class MyDetachedThread 
: public wxThread
 
5518     MyDetachedThread(size_t n
, wxChar ch
) 
5522         m_cancelled 
= false; 
5527     // thread execution starts here 
5528     virtual ExitCode 
Entry(); 
5531     virtual void OnExit(); 
5534     size_t m_n
; // number of characters to write 
5535     wxChar m_ch
;  // character to write 
5537     bool m_cancelled
;   // false if we exit normally 
5540 wxThread::ExitCode 
MyDetachedThread::Entry() 
5543         wxCriticalSectionLocker 
lock(gs_critsect
); 
5544         if ( gs_counter 
== (size_t)-1 ) 
5550     for ( size_t n 
= 0; n 
< m_n
; n
++ ) 
5552         if ( TestDestroy() ) 
5562         wxThread::Sleep(100); 
5568 void MyDetachedThread::OnExit() 
5570     wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId()); 
5572     wxCriticalSectionLocker 
lock(gs_critsect
); 
5573     if ( !--gs_counter 
&& !m_cancelled 
) 
5577 static void TestDetachedThreads() 
5579     wxPuts(_T("\n*** Testing detached threads ***")); 
5581     static const size_t nThreads 
= 3; 
5582     MyDetachedThread 
*threads
[nThreads
]; 
5584     for ( n 
= 0; n 
< nThreads
; n
++ ) 
5586         threads
[n
] = new MyDetachedThread(10, 'A' + n
); 
5589     threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
); 
5590     threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
); 
5592     for ( n 
= 0; n 
< nThreads
; n
++ ) 
5597     // wait until all threads terminate 
5603 static void TestJoinableThreads() 
5605     wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***")); 
5607     // calc 10! in the background 
5608     MyJoinableThread 
thread(10); 
5611     wxPrintf(_T("\nThread terminated with exit code %lu.\n"), 
5612            (unsigned long)thread
.Wait()); 
5615 static void TestThreadSuspend() 
5617     wxPuts(_T("\n*** Testing thread suspend/resume functions ***")); 
5619     MyDetachedThread 
*thread 
= new MyDetachedThread(15, 'X'); 
5623     // this is for this demo only, in a real life program we'd use another 
5624     // condition variable which would be signaled from wxThread::Entry() to 
5625     // tell us that the thread really started running - but here just wait a 
5626     // bit and hope that it will be enough (the problem is, of course, that 
5627     // the thread might still not run when we call Pause() which will result 
5629     wxThread::Sleep(300); 
5631     for ( size_t n 
= 0; n 
< 3; n
++ ) 
5635         wxPuts(_T("\nThread suspended")); 
5638             // don't sleep but resume immediately the first time 
5639             wxThread::Sleep(300); 
5641         wxPuts(_T("Going to resume the thread")); 
5646     wxPuts(_T("Waiting until it terminates now")); 
5648     // wait until the thread terminates 
5654 static void TestThreadDelete() 
5656     // As above, using Sleep() is only for testing here - we must use some 
5657     // synchronisation object instead to ensure that the thread is still 
5658     // running when we delete it - deleting a detached thread which already 
5659     // terminated will lead to a crash! 
5661     wxPuts(_T("\n*** Testing thread delete function ***")); 
5663     MyDetachedThread 
*thread0 
= new MyDetachedThread(30, 'W'); 
5667     wxPuts(_T("\nDeleted a thread which didn't start to run yet.")); 
5669     MyDetachedThread 
*thread1 
= new MyDetachedThread(30, 'Y'); 
5673     wxThread::Sleep(300); 
5677     wxPuts(_T("\nDeleted a running thread.")); 
5679     MyDetachedThread 
*thread2 
= new MyDetachedThread(30, 'Z'); 
5683     wxThread::Sleep(300); 
5689     wxPuts(_T("\nDeleted a sleeping thread.")); 
5691     MyJoinableThread 
thread3(20); 
5696     wxPuts(_T("\nDeleted a joinable thread.")); 
5698     MyJoinableThread 
thread4(2); 
5701     wxThread::Sleep(300); 
5705     wxPuts(_T("\nDeleted a joinable thread which already terminated.")); 
5710 class MyWaitingThread 
: public wxThread
 
5713     MyWaitingThread( wxMutex 
*mutex
, wxCondition 
*condition 
) 
5716         m_condition 
= condition
; 
5721     virtual ExitCode 
Entry() 
5723         wxPrintf(_T("Thread %lu has started running.\n"), GetId()); 
5728         wxPrintf(_T("Thread %lu starts to wait...\n"), GetId()); 
5732         m_condition
->Wait(); 
5735         wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId()); 
5743     wxCondition 
*m_condition
; 
5746 static void TestThreadConditions() 
5749     wxCondition 
condition(mutex
); 
5751     // otherwise its difficult to understand which log messages pertain to 
5753     //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"), 
5754     //           condition.GetId(), gs_cond.GetId()); 
5756     // create and launch threads 
5757     MyWaitingThread 
*threads
[10]; 
5760     for ( n 
= 0; n 
< WXSIZEOF(threads
); n
++ ) 
5762         threads
[n
] = new MyWaitingThread( &mutex
, &condition 
); 
5765     for ( n 
= 0; n 
< WXSIZEOF(threads
); n
++ ) 
5770     // wait until all threads run 
5771     wxPuts(_T("Main thread is waiting for the other threads to start")); 
5774     size_t nRunning 
= 0; 
5775     while ( nRunning 
< WXSIZEOF(threads
) ) 
5781         wxPrintf(_T("Main thread: %u already running\n"), nRunning
); 
5785     wxPuts(_T("Main thread: all threads started up.")); 
5788     wxThread::Sleep(500); 
5791     // now wake one of them up 
5792     wxPrintf(_T("Main thread: about to signal the condition.\n")); 
5797     wxThread::Sleep(200); 
5799     // wake all the (remaining) threads up, so that they can exit 
5800     wxPrintf(_T("Main thread: about to broadcast the condition.\n")); 
5802     condition
.Broadcast(); 
5804     // give them time to terminate (dirty!) 
5805     wxThread::Sleep(500); 
5808 #include "wx/utils.h" 
5810 class MyExecThread 
: public wxThread
 
5813     MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
), 
5819     virtual ExitCode 
Entry() 
5821         return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
); 
5828 static void TestThreadExec() 
5830     wxPuts(_T("*** Testing wxExecute interaction with threads ***\n")); 
5832     MyExecThread 
thread(_T("true")); 
5835     wxPrintf(_T("Main program exit code: %ld.\n"), 
5836              wxExecute(_T("false"), wxEXEC_SYNC
)); 
5838     wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait()); 
5842 #include "wx/datetime.h" 
5844 class MySemaphoreThread 
: public wxThread
 
5847     MySemaphoreThread(int i
, wxSemaphore 
*sem
) 
5848         : wxThread(wxTHREAD_JOINABLE
), 
5855     virtual ExitCode 
Entry() 
5857         wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"), 
5858                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5862         wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"), 
5863                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5867         wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"), 
5868                  wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId()); 
5880 WX_DEFINE_ARRAY(wxThread 
*, ArrayThreads
); 
5882 static void TestSemaphore() 
5884     wxPuts(_T("*** Testing wxSemaphore class. ***")); 
5886     static const int SEM_LIMIT 
= 3; 
5888     wxSemaphore 
sem(SEM_LIMIT
, SEM_LIMIT
); 
5889     ArrayThreads threads
; 
5891     for ( int i 
= 0; i 
< 3*SEM_LIMIT
; i
++ ) 
5893         threads
.Add(new MySemaphoreThread(i
, &sem
)); 
5894         threads
.Last()->Run(); 
5897     for ( size_t n 
= 0; n 
< threads
.GetCount(); n
++ ) 
5904 #endif // TEST_THREADS 
5906 // ---------------------------------------------------------------------------- 
5908 // ---------------------------------------------------------------------------- 
5912 #include "wx/dynarray.h" 
5914 typedef unsigned short ushort
; 
5916 #define DefineCompare(name, T)                                                \ 
5918 int wxCMPFUNC_CONV name ## CompareValues(T first, T second)                   \ 
5920     return first - second;                                                    \ 
5923 int wxCMPFUNC_CONV name ## Compare(T* first, T* second)                       \ 
5925     return *first - *second;                                                  \ 
5928 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second)                    \ 
5930     return *second - *first;                                                  \ 
5933 DefineCompare(UShort, ushort); 
5934 DefineCompare(Int
, int); 
5936 // test compilation of all macros 
5937 WX_DEFINE_ARRAY_SHORT(ushort
, wxArrayUShort
); 
5938 WX_DEFINE_SORTED_ARRAY_SHORT(ushort
, wxSortedArrayUShortNoCmp
); 
5939 WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort
, UShortCompareValues
, wxSortedArrayUShort
); 
5940 WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues
, wxSortedArrayInt
); 
5942 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
); 
5943 #include "wx/arrimpl.cpp" 
5944 WX_DEFINE_OBJARRAY(ArrayBars
); 
5946 static void PrintArray(const wxChar
* name
, const wxArrayString
& array
) 
5948     wxPrintf(_T("Dump of the array '%s'\n"), name
); 
5950     size_t nCount 
= array
.GetCount(); 
5951     for ( size_t n 
= 0; n 
< nCount
; n
++ ) 
5953         wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str()); 
5957 static void PrintArray(const wxChar
* name
, const wxSortedArrayString
& array
) 
5959     wxPrintf(_T("Dump of the array '%s'\n"), name
); 
5961     size_t nCount 
= array
.GetCount(); 
5962     for ( size_t n 
= 0; n 
< nCount
; n
++ ) 
5964         wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str()); 
5968 int wxCMPFUNC_CONV 
StringLenCompare(const wxString
& first
, 
5969                                     const wxString
& second
) 
5971     return first
.length() - second
.length(); 
5974 #define TestArrayOf(name)                                                     \ 
5976 static void PrintArray(const wxChar* name, const wxSortedArray##name & array) \ 
5978     wxPrintf(_T("Dump of the array '%s'\n"), name);                           \ 
5980     size_t nCount = array.GetCount();                                         \ 
5981     for ( size_t n = 0; n < nCount; n++ )                                     \ 
5983         wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]);                   \ 
5987 static void PrintArray(const wxChar* name, const wxArray##name & array)       \ 
5989     wxPrintf(_T("Dump of the array '%s'\n"), name);                           \ 
5991     size_t nCount = array.GetCount();                                         \ 
5992     for ( size_t n = 0; n < nCount; n++ )                                     \ 
5994         wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]);                   \ 
5998 static void TestArrayOf ## name ## s()                                        \ 
6000     wxPrintf(_T("*** Testing wxArray%s ***\n"), #name);                       \ 
6008     wxPuts(_T("Initially:"));                                                 \ 
6009     PrintArray(_T("a"), a);                                                   \ 
6011     wxPuts(_T("After sort:"));                                                \ 
6012     a.Sort(name ## Compare);                                                  \ 
6013     PrintArray(_T("a"), a);                                                   \ 
6015     wxPuts(_T("After reverse sort:"));                                        \ 
6016     a.Sort(name ## RevCompare);                                               \ 
6017     PrintArray(_T("a"), a);                                                   \ 
6019     wxSortedArray##name b;                                                    \ 
6025     wxPuts(_T("Sorted array initially:"));                                    \ 
6026     PrintArray(_T("b"), b);                                                       \ 
6029 TestArrayOf(UShort
); 
6032 static void TestStlArray() 
6034     wxPuts(_T("*** Testing std::vector operations ***\n")); 
6038         wxArrayInt::iterator it
, en
; 
6039         wxArrayInt::reverse_iterator rit
, ren
; 
6041         for ( i 
= 0; i 
< 5; ++i 
) 
6044         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 0; 
6045               it 
!= en
; ++it
, ++i 
) 
6047                 wxPuts(_T("Error in iterator\n")); 
6049         for ( rit 
= list1
.rbegin(), ren 
= list1
.rend(), i 
= 4; 
6050               rit 
!= ren
; ++rit
, --i 
) 
6052                 wxPuts(_T("Error in reverse_iterator\n")); 
6054         if ( *list1
.rbegin() != *(list1
.end()-1) || 
6055              *list1
.begin() != *(list1
.rend()-1) ) 
6056             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
6058         it 
= list1
.begin()+1; 
6059         rit 
= list1
.rbegin()+1; 
6060         if ( *list1
.begin() != *(it
-1) || 
6061              *list1
.rbegin() != *(rit
-1) ) 
6062             wxPuts(_T("Error in iterator/reverse_iterator\n")); 
6064         if ( list1
.front() != 0 || list1
.back() != 4 ) 
6065             wxPuts(_T("Error in front()/back()\n")); 
6067         list1
.erase(list1
.begin()); 
6068         list1
.erase(list1
.end()-1); 
6070         for ( it 
= list1
.begin(), en 
= list1
.end(), i 
= 1; 
6071               it 
!= en
; ++it
, ++i 
) 
6073                 wxPuts(_T("Error in erase()\n")); 
6076     wxPuts(_T("*** Testing std::vector operations finished ***\n")); 
6079 static void TestArrayOfObjects() 
6081     wxPuts(_T("*** Testing wxObjArray ***\n")); 
6085         Bar 
bar("second bar (two copies!)"); 
6087         wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"), 
6088                bars
.GetCount(), Bar::GetNumber()); 
6090         bars
.Add(new Bar("first bar")); 
6093         wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"), 
6094                bars
.GetCount(), Bar::GetNumber()); 
6096         bars
.RemoveAt(1, bars
.GetCount() - 1); 
6098         wxPrintf(_T("After removing all but first element: %u objects in the ") 
6099                  _T("array, %u objects total.\n"), 
6100                bars
.GetCount(), Bar::GetNumber()); 
6104         wxPrintf(_T("After Empty(): %u objects in the array, %u objects total.\n"), 
6105                bars
.GetCount(), Bar::GetNumber()); 
6108     wxPrintf(_T("Finally: no more objects in the array, %u objects total.\n"), 
6112 #endif // TEST_ARRAYS 
6114 // ---------------------------------------------------------------------------- 
6116 // ---------------------------------------------------------------------------- 
6120 #include "wx/timer.h" 
6121 #include "wx/tokenzr.h" 
6123 static void TestStringConstruction() 
6125     wxPuts(_T("*** Testing wxString constructores ***")); 
6127     #define TEST_CTOR(args, res)                                               \ 
6130             wxPrintf(_T("wxString%s = %s "), #args, s.c_str());                      \ 
6133                 wxPuts(_T("(ok)"));                                                  \ 
6137                 wxPrintf(_T("(ERROR: should be %s)\n"), res);                        \ 
6141     TEST_CTOR((_T('Z'), 4), _T("ZZZZ")); 
6142     TEST_CTOR((_T("Hello"), 4), _T("Hell")); 
6143     TEST_CTOR((_T("Hello"), 5), _T("Hello")); 
6144     // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure 
6146     static const wxChar 
*s 
= _T("?really!"); 
6147     const wxChar 
*start 
= wxStrchr(s
, _T('r')); 
6148     const wxChar 
*end 
= wxStrchr(s
, _T('!')); 
6149     TEST_CTOR((start
, end
), _T("really")); 
6154 static void TestString() 
6164     for (int i 
= 0; i 
< 1000000; ++i
) 
6168         c 
= _T("! How'ya doin'?"); 
6171         c 
= _T("Hello world! What's up?"); 
6176     wxPrintf(_T("TestString elapsed time: %ld\n"), sw
.Time()); 
6179 static void TestPChar() 
6187     for (int i 
= 0; i 
< 1000000; ++i
) 
6189         wxStrcpy (a
, _T("Hello")); 
6190         wxStrcpy (b
, _T(" world")); 
6191         wxStrcpy (c
, _T("! How'ya doin'?")); 
6194         wxStrcpy (c
, _T("Hello world! What's up?")); 
6195         if (wxStrcmp (c
, a
) == 0) 
6196             wxStrcpy (c
, _T("Doh!")); 
6199     wxPrintf(_T("TestPChar elapsed time: %ld\n"), sw
.Time()); 
6202 static void TestStringSub() 
6204     wxString 
s(_T("Hello, world!")); 
6206     wxPuts(_T("*** Testing wxString substring extraction ***")); 
6208     wxPrintf(_T("String = '%s'\n"), s
.c_str()); 
6209     wxPrintf(_T("Left(5) = '%s'\n"), s
.Left(5).c_str()); 
6210     wxPrintf(_T("Right(6) = '%s'\n"), s
.Right(6).c_str()); 
6211     wxPrintf(_T("Mid(3, 5) = '%s'\n"), s(3, 5).c_str()); 
6212     wxPrintf(_T("Mid(3) = '%s'\n"), s
.Mid(3).c_str()); 
6213     wxPrintf(_T("substr(3, 5) = '%s'\n"), s
.substr(3, 5).c_str()); 
6214     wxPrintf(_T("substr(3) = '%s'\n"), s
.substr(3).c_str()); 
6216     static const wxChar 
*prefixes
[] = 
6220         _T("Hello, world!"), 
6221         _T("Hello, world!!!"), 
6227     for ( size_t n 
= 0; n 
< WXSIZEOF(prefixes
); n
++ ) 
6229         wxString prefix 
= prefixes
[n
], rest
; 
6230         bool rc 
= s
.StartsWith(prefix
, &rest
); 
6231         wxPrintf(_T("StartsWith('%s') = %s"), prefix
.c_str(), rc 
? _T("true") : _T("false")); 
6234             wxPrintf(_T(" (the rest is '%s')\n"), rest
.c_str()); 
6245 static void TestStringFormat() 
6247     wxPuts(_T("*** Testing wxString formatting ***")); 
6250     s
.Printf(_T("%03d"), 18); 
6252     wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str()); 
6253     wxPrintf(_T("Number 18: %s\n"), s
.c_str()); 
6258 // returns "not found" for npos, value for all others 
6259 static wxString 
PosToString(size_t res
) 
6261     wxString s 
= res 
== wxString::npos 
? wxString(_T("not found")) 
6262                                        : wxString::Format(_T("%u"), res
); 
6266 static void TestStringFind() 
6268     wxPuts(_T("*** Testing wxString find() functions ***")); 
6270     static const wxChar 
*strToFind 
= _T("ell"); 
6271     static const struct StringFindTest
 
6275                       result
;   // of searching "ell" in str 
6278         { _T("Well, hello world"),  0, 1 }, 
6279         { _T("Well, hello world"),  6, 7 }, 
6280         { _T("Well, hello world"),  9, wxString::npos 
}, 
6283     for ( size_t n 
= 0; n 
< WXSIZEOF(findTestData
); n
++ ) 
6285         const StringFindTest
& ft 
= findTestData
[n
]; 
6286         size_t res 
= wxString(ft
.str
).find(strToFind
, ft
.start
); 
6288         wxPrintf(_T("Index of '%s' in '%s' starting from %u is %s "), 
6289                strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str()); 
6291         size_t resTrue 
= ft
.result
; 
6292         if ( res 
== resTrue 
) 
6298             wxPrintf(_T("(ERROR: should be %s)\n"), 
6299                    PosToString(resTrue
).c_str()); 
6306 static void TestStringTokenizer() 
6308     wxPuts(_T("*** Testing wxStringTokenizer ***")); 
6310     static const wxChar 
*modeNames
[] = 
6314         _T("return all empty"), 
6319     static const struct StringTokenizerTest
 
6321         const wxChar 
*str
;              // string to tokenize 
6322         const wxChar 
*delims
;           // delimiters to use 
6323         size_t        count
;            // count of token 
6324         wxStringTokenizerMode mode
;     // how should we tokenize it 
6325     } tokenizerTestData
[] = 
6327         { _T(""), _T(" "), 0 }, 
6328         { _T("Hello, world"), _T(" "), 2 }, 
6329         { _T("Hello,   world  "), _T(" "), 2 }, 
6330         { _T("Hello, world"), _T(","), 2 }, 
6331         { _T("Hello, world!"), _T(",!"), 2 }, 
6332         { _T("Hello,, world!"), _T(",!"), 3 }, 
6333         { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL 
}, 
6334         { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 }, 
6335         { _T("1 \t3\t4  6   "), wxDEFAULT_DELIMITERS
, 4 }, 
6336         { _T("1 \t3\t4  6   "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY 
}, 
6337         { _T("1 \t3\t4  6   "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL 
}, 
6338         { _T("01/02/99"), _T("/-"), 3 }, 
6339         { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS 
}, 
6342     for ( size_t n 
= 0; n 
< WXSIZEOF(tokenizerTestData
); n
++ ) 
6344         const StringTokenizerTest
& tt 
= tokenizerTestData
[n
]; 
6345         wxStringTokenizer 
tkz(tt
.str
, tt
.delims
, tt
.mode
); 
6347         size_t count 
= tkz
.CountTokens(); 
6348         wxPrintf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "), 
6349                MakePrintable(tt
.str
).c_str(), 
6351                MakePrintable(tt
.delims
).c_str(), 
6352                modeNames
[tkz
.GetMode()]); 
6353         if ( count 
== tt
.count 
) 
6359             wxPrintf(_T("(ERROR: should be %u)\n"), tt
.count
); 
6364         // if we emulate strtok(), check that we do it correctly 
6365         wxChar 
*buf
, *s 
= NULL
, *last
; 
6367         if ( tkz
.GetMode() == wxTOKEN_STRTOK 
) 
6369             buf 
= new wxChar
[wxStrlen(tt
.str
) + 1]; 
6370             wxStrcpy(buf
, tt
.str
); 
6372             s 
= wxStrtok(buf
, tt
.delims
, &last
); 
6379         // now show the tokens themselves 
6381         while ( tkz
.HasMoreTokens() ) 
6383             wxString token 
= tkz
.GetNextToken(); 
6385             wxPrintf(_T("\ttoken %u: '%s'"), 
6387                    MakePrintable(token
).c_str()); 
6393                     wxPuts(_T(" (ok)")); 
6397                     wxPrintf(_T(" (ERROR: should be %s)\n"), s
); 
6400                 s 
= wxStrtok(NULL
, tt
.delims
, &last
); 
6404                 // nothing to compare with 
6409         if ( count2 
!= count 
) 
6411             wxPuts(_T("\tERROR: token count mismatch")); 
6420 static void TestStringReplace() 
6422     wxPuts(_T("*** Testing wxString::replace ***")); 
6424     static const struct StringReplaceTestData
 
6426         const wxChar 
*original
;     // original test string 
6427         size_t start
, len
;          // the part to replace 
6428         const wxChar 
*replacement
;  // the replacement string 
6429         const wxChar 
*result
;       // and the expected result 
6430     } stringReplaceTestData
[] = 
6432         { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") }, 
6433         { _T("increase"), 0, 2, _T("de"), _T("decrease") }, 
6434         { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") }, 
6435         { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") }, 
6436         { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") }, 
6439     for ( size_t n 
= 0; n 
< WXSIZEOF(stringReplaceTestData
); n
++ ) 
6441         const StringReplaceTestData data 
= stringReplaceTestData
[n
]; 
6443         wxString original 
= data
.original
; 
6444         original
.replace(data
.start
, data
.len
, data
.replacement
); 
6446         wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "), 
6447                  data
.original
, data
.start
, data
.len
, data
.replacement
, 
6450         if ( original 
== data
.result 
) 
6456             wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
); 
6463 static void TestStringMatch() 
6465     wxPuts(_T("*** Testing wxString::Matches() ***")); 
6467     static const struct StringMatchTestData
 
6470         const wxChar 
*wildcard
; 
6472     } stringMatchTestData
[] = 
6474         { _T("foobar"), _T("foo*"), 1 }, 
6475         { _T("foobar"), _T("*oo*"), 1 }, 
6476         { _T("foobar"), _T("*bar"), 1 }, 
6477         { _T("foobar"), _T("??????"), 1 }, 
6478         { _T("foobar"), _T("f??b*"), 1 }, 
6479         { _T("foobar"), _T("f?b*"), 0 }, 
6480         { _T("foobar"), _T("*goo*"), 0 }, 
6481         { _T("foobar"), _T("*foo"), 0 }, 
6482         { _T("foobarfoo"), _T("*foo"), 1 }, 
6483         { _T(""), _T("*"), 1 }, 
6484         { _T(""), _T("?"), 0 }, 
6487     for ( size_t n 
= 0; n 
< WXSIZEOF(stringMatchTestData
); n
++ ) 
6489         const StringMatchTestData
& data 
= stringMatchTestData
[n
]; 
6490         bool matches 
= wxString(data
.text
).Matches(data
.wildcard
); 
6491         wxPrintf(_T("'%s' %s '%s' (%s)\n"), 
6493                  matches 
? _T("matches") : _T("doesn't match"), 
6495                  matches 
== data
.matches 
? _T("ok") : _T("ERROR")); 
6501 // Sigh, I want Test::Simple, Test::More and Test::Harness... 
6502 void ok(int line
, bool ok
, const wxString
& msg 
= wxEmptyString
) 
6505         wxPuts(_T("NOT OK: (") + wxString::Format(_T("%d"), line
) + 
6509 void is(int line
, const wxString
& got
, const wxString
& expected
, 
6510         const wxString
& msg 
= wxEmptyString
) 
6512     bool isOk 
= got 
== expected
; 
6513     ok(line
, isOk
, msg
); 
6516         wxPuts(_T("Got: ") + got
); 
6517         wxPuts(_T("Expected: ") + expected
); 
6521 void is(int line
, const wxChar
& got
, const wxChar
& expected
, 
6522         const wxString
& msg 
= wxEmptyString
) 
6524     bool isOk 
= got 
== expected
; 
6525     ok(line
, isOk
, msg
); 
6528         wxPuts("Got: " + got
); 
6529         wxPuts("Expected: " + expected
); 
6533 void TestStdString() 
6535     wxPuts(_T("*** Testing std::string operations ***\n")); 
6538     wxString 
s1(_T("abcdefgh")), 
6539              s2(_T("abcdefghijklm"), 8), 
6540              s3(_T("abcdefghijklm")), 
6544              s7(s3
.begin(), s3
.begin() + 8); 
6545     wxString 
s8(s1
, 4, 8), s9
, s10
, s11
; 
6547     is( __LINE__
, s1
, _T("abcdefgh") ); 
6548     is( __LINE__
, s2
, s1 
); 
6549     is( __LINE__
, s4
, _T("aaaaaaaa") ); 
6550     is( __LINE__
, s5
, _T("abcdefgh") ); 
6551     is( __LINE__
, s6
, s1 
); 
6552     is( __LINE__
, s7
, s1 
); 
6553     is( __LINE__
, s8
, _T("efgh") ); 
6556     s1 
= s2 
= s3 
= s4 
= s5 
= s6 
= s7 
= s8 
= _T("abc"); 
6557     s1
.append(_T("def")); 
6558     s2
.append(_T("defgh"), 3); 
6559     s3
.append(wxString(_T("abcdef")), 3, 6); 
6561     s5
.append(3, _T('a')); 
6562     s6
.append(s1
.begin() + 3, s1
.end()); 
6564     is( __LINE__
, s1
, _T("abcdef") ); 
6565     is( __LINE__
, s2
, _T("abcdef") ); 
6566     is( __LINE__
, s3
, _T("abcdef") ); 
6567     is( __LINE__
, s4
, _T("abcabcdef") ); 
6568     is( __LINE__
, s5
, _T("abcaaa") ); 
6569     is( __LINE__
, s6
, _T("abcdef") ); 
6572     s1 
= s2 
= s3 
= s4 
= s5 
= s6 
= s7 
= s8 
= _T("abc"); 
6573     s1
.assign(_T("def")); 
6574     s2
.assign(_T("defgh"), 3); 
6575     s3
.assign(wxString(_T("abcdef")), 3, 6); 
6577     s5
.assign(3, _T('a')); 
6578     s6
.assign(s1
.begin() + 1, s1
.end()); 
6580     is( __LINE__
, s1
, _T("def") ); 
6581     is( __LINE__
, s2
, _T("def") ); 
6582     is( __LINE__
, s3
, _T("def") ); 
6583     is( __LINE__
, s4
, _T("def") ); 
6584     is( __LINE__
, s5
, _T("aaa") ); 
6585     is( __LINE__
, s6
, _T("ef") ); 
6588     s1 
= _T("abcdefgh"); 
6589     s2 
= _T("abcdefgh"); 
6591     s4 
= _T("abcdefghi"); 
6594     s7 
= _T("zabcdefg"); 
6596     ok( __LINE__
, s1
.compare(s2
) == 0 ); 
6597     ok( __LINE__
, s1
.compare(s3
) > 0 ); 
6598     ok( __LINE__
, s1
.compare(s4
) < 0 ); 
6599     ok( __LINE__
, s1
.compare(s5
) > 0 ); 
6600     ok( __LINE__
, s1
.compare(s6
) < 0 ); 
6601     ok( __LINE__
, s1
.compare(1, 12, s1
) > 0); 
6602     ok( __LINE__
, s1
.compare(_T("abcdefgh")) == 0); 
6603     ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh")) == 0); 
6604     ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh"), 7) == 0); 
6609     wxString::iterator it 
= s3
.erase(s3
.begin() + 1); 
6610     wxString::iterator it2 
= s4
.erase(s4
.begin() + 4, s4
.begin() + 6); 
6611     wxString::iterator it3 
= s7
.erase(s7
.begin() + 4, s7
.begin() + 8); 
6613     is( __LINE__
, s1
, _T("acdefgh") ); 
6614     is( __LINE__
, s2
, _T("abcd") ); 
6615     is( __LINE__
, s3
, _T("ac") ); 
6616     is( __LINE__
, s4
, _T("abcdghi") ); 
6617     is( __LINE__
, s7
, _T("zabc") ); 
6618     is( __LINE__
, *it
, _T('c') ); 
6619     is( __LINE__
, *it2
, _T('g') ); 
6620     ok( __LINE__
, it3 
== s7
.end() ); 
6623     s1 
= s2 
= s3 
= s4 
= s5 
= s6 
= s7 
= s8 
= _T("aaaa"); 
6624     s9 
= s10 
= _T("cdefg"); 
6626     s1
.insert(1, _T("cc") ); 
6627     s2
.insert(2, _T("cdef"), 3); 
6629     s4
.insert(2, s10
, 3, 7); 
6630     s5
.insert(1, 2, _T('c')); 
6631     it 
= s6
.insert(s6
.begin() + 3, _T('X')); 
6632     s7
.insert(s7
.begin(), s9
.begin(), s9
.end() - 1); 
6633     s8
.insert(s8
.begin(), 2, _T('c')); 
6635     is( __LINE__
, s1
, _T("accaaa") ); 
6636     is( __LINE__
, s2
, _T("aacdeaa") ); 
6637     is( __LINE__
, s3
, _T("aacdefgaa") ); 
6638     is( __LINE__
, s4
, _T("aafgaa") ); 
6639     is( __LINE__
, s5
, _T("accaaa") ); 
6640     is( __LINE__
, s6
, _T("aaaXa") ); 
6641     is( __LINE__
, s7
, _T("cdefaaaa") ); 
6642     is( __LINE__
, s8
, _T("ccaaaa") ); 
6644     s1 
= s2 
= s3 
= _T("aaaa"); 
6645     s1
.insert(0, _T("ccc"), 2); 
6646     s2
.insert(4, _T("ccc"), 2); 
6648     is( __LINE__
, s1
, _T("ccaaaa") ); 
6649     is( __LINE__
, s2
, _T("aaaacc") ); 
6652     s1 
= s2 
= s3 
= s4 
= s5 
= s6 
= s7 
= s8 
= _T("QWERTYUIOP"); 
6653     s9 
= s10 
= _T("werty"); 
6655     s1
.replace(3, 4, _T("rtyu")); 
6656     s1
.replace(8, 7, _T("opopop")); 
6657     s2
.replace(10, 12, _T("WWWW")); 
6658     s3
.replace(1, 5, s9
); 
6659     s4
.replace(1, 4, s9
, 0, 4); 
6660     s5
.replace(1, 2, s9
, 1, 12); 
6661     s6
.replace(0, 123, s9
, 0, 123); 
6662     s7
.replace(2, 7, s9
); 
6664     is( __LINE__
, s1
, _T("QWErtyuIopopop") ); 
6665     is( __LINE__
, s2
, _T("QWERTYUIOPWWWW") ); 
6666     is( __LINE__
, s3
, _T("QwertyUIOP") ); 
6667     is( __LINE__
, s4
, _T("QwertYUIOP") ); 
6668     is( __LINE__
, s5
, _T("QertyRTYUIOP") ); 
6669     is( __LINE__
, s6
, s9
); 
6670     is( __LINE__
, s7
, _T("QWwertyP") ); 
6672     wxPuts(_T("*** Testing std::string operations finished ***\n")); 
6675 #endif // TEST_STRINGS 
6677 // ---------------------------------------------------------------------------- 
6679 // ---------------------------------------------------------------------------- 
6681 #ifdef TEST_SNGLINST 
6682     #include "wx/snglinst.h" 
6683 #endif // TEST_SNGLINST 
6685 int main(int argc
, char **argv
) 
6687     wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program"); 
6689     wxInitializer initializer
; 
6692         fprintf(stderr
, "Failed to initialize the wxWindows library, aborting."); 
6697 #ifdef TEST_SNGLINST 
6698     wxSingleInstanceChecker checker
; 
6699     if ( checker
.Create(_T(".wxconsole.lock")) ) 
6701         if ( checker
.IsAnotherRunning() ) 
6703             wxPrintf(_T("Another instance of the program is running, exiting.\n")); 
6708         // wait some time to give time to launch another instance 
6709         wxPrintf(_T("Press \"Enter\" to continue...")); 
6712     else // failed to create 
6714         wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n")); 
6716 #endif // TEST_SNGLINST 
6720 #endif // TEST_CHARSET 
6723     TestCmdLineConvert(); 
6725 #if wxUSE_CMDLINE_PARSER 
6726     static const wxCmdLineEntryDesc cmdLineDesc
[] = 
6728         { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"), 
6729             wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP 
}, 
6730         { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") }, 
6731         { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"),   _T("be quiet") }, 
6733         { wxCMD_LINE_OPTION
, _T("o"), _T("output"),  _T("output file") }, 
6734         { wxCMD_LINE_OPTION
, _T("i"), _T("input"),   _T("input dir") }, 
6735         { wxCMD_LINE_OPTION
, _T("s"), _T("size"),    _T("output block size"), 
6736             wxCMD_LINE_VAL_NUMBER 
}, 
6737         { wxCMD_LINE_OPTION
, _T("d"), _T("date"),    _T("output file date"), 
6738             wxCMD_LINE_VAL_DATE 
}, 
6740         { wxCMD_LINE_PARAM
,  NULL
, NULL
, _T("input file"), 
6741             wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE 
}, 
6747     wxChar 
**wargv 
= new wxChar 
*[argc 
+ 1]; 
6750         for ( int n 
= 0; n 
< argc
; n
++ ) 
6752             wxMB2WXbuf warg 
= wxConvertMB2WX(argv
[n
]); 
6753             wargv
[n
] = wxStrdup(warg
); 
6760 #endif // wxUSE_UNICODE 
6762     wxCmdLineParser 
parser(cmdLineDesc
, argc
, argv
); 
6766         for ( int n 
= 0; n 
< argc
; n
++ ) 
6771 #endif // wxUSE_UNICODE 
6773     parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"), 
6774                      wxCMD_LINE_VAL_STRING
, 
6775                      wxCMD_LINE_OPTION_MANDATORY 
| wxCMD_LINE_NEEDS_SEPARATOR
); 
6777     switch ( parser
.Parse() ) 
6780             wxLogMessage(_T("Help was given, terminating.")); 
6784             ShowCmdLine(parser
); 
6788             wxLogMessage(_T("Syntax error detected, aborting.")); 
6791 #endif // wxUSE_CMDLINE_PARSER 
6793 #endif // TEST_CMDLINE 
6801         TestStringConstruction(); 
6804         TestStringTokenizer(); 
6805         TestStringReplace(); 
6813 #endif // TEST_STRINGS 
6816     if ( 1 || TEST_ALL 
) 
6819         a1
.Add(_T("tiger")); 
6821         a1
.Add(_T("lion"), 3); 
6823         a1
.Add(_T("human")); 
6826         wxPuts(_T("*** Initially:")); 
6828         PrintArray(_T("a1"), a1
); 
6830         wxArrayString 
a2(a1
); 
6831         PrintArray(_T("a2"), a2
); 
6834         wxSortedArrayString 
a3(a1
); 
6836         wxSortedArrayString a3
; 
6837         for (wxArrayString::iterator it 
= a1
.begin(), en 
= a1
.end(); 
6841         PrintArray(_T("a3"), a3
); 
6843         wxPuts(_T("*** After deleting three strings from a1")); 
6846         PrintArray(_T("a1"), a1
); 
6847         PrintArray(_T("a2"), a2
); 
6848         PrintArray(_T("a3"), a3
); 
6851         wxPuts(_T("*** After reassigning a1 to a2 and a3")); 
6853         PrintArray(_T("a2"), a2
); 
6854         PrintArray(_T("a3"), a3
); 
6857         wxPuts(_T("*** After sorting a1")); 
6858         a1
.Sort(wxStringCompareAscending
); 
6859         PrintArray(_T("a1"), a1
); 
6861         wxPuts(_T("*** After sorting a1 in reverse order")); 
6862         a1
.Sort(wxStringCompareDescending
); 
6863         PrintArray(_T("a1"), a1
); 
6866         wxPuts(_T("*** After sorting a1 by the string length")); 
6867         a1
.Sort(&StringLenCompare
); 
6868         PrintArray(_T("a1"), a1
); 
6871         TestArrayOfObjects(); 
6872         TestArrayOfUShorts(); 
6877 #endif // TEST_ARRAYS 
6888 #ifdef TEST_DLLLOADER 
6890 #endif // TEST_DLLLOADER 
6894 #endif // TEST_ENVIRON 
6898 #endif // TEST_EXECUTE 
6900 #ifdef TEST_FILECONF 
6902 #endif // TEST_FILECONF 
6911 #endif // TEST_LOCALE 
6914     wxPuts(_T("*** Testing wxLog ***")); 
6917     for ( size_t n 
= 0; n 
< 8000; n
++ ) 
6919         s 
<< (wxChar
)(_T('A') + (n 
% 26)); 
6922     wxLogWarning(_T("The length of the string is %lu"), 
6923                  (unsigned long)s
.length()); 
6926     msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str()); 
6928     // this one shouldn't be truncated 
6931     // but this one will because log functions use fixed size buffer 
6932     // (note that it doesn't need '\n' at the end neither - will be added 
6934     wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str()); 
6946 #ifdef TEST_FILENAME 
6950         fn
.Assign(_T("c:\\foo"), _T("bar.baz")); 
6951         fn
.Assign(_T("/u/os9-port/Viewer/tvision/WEI2HZ-3B3-14_05-04-00MSC1.asc")); 
6956     TestFileNameConstruction(); 
6959         TestFileNameConstruction(); 
6960         TestFileNameMakeRelative(); 
6961         TestFileNameMakeAbsolute(); 
6962         TestFileNameSplit(); 
6965         TestFileNameComparison(); 
6966         TestFileNameOperations(); 
6968 #endif // TEST_FILENAME 
6970 #ifdef TEST_FILETIME 
6974 #endif // TEST_FILETIME 
6977     wxLog::AddTraceMask(FTP_TRACE_MASK
); 
6978     if ( TestFtpConnect() ) 
6989         if ( TEST_INTERACTIVE 
) 
6990             TestFtpInteractive(); 
6992     //else: connecting to the FTP server failed 
6998 #ifdef TEST_LONGLONG 
6999     // seed pseudo random generator 
7000     srand((unsigned)time(NULL
)); 
7009         TestMultiplication(); 
7012         TestLongLongConversion(); 
7013         TestBitOperations(); 
7014         TestLongLongComparison(); 
7015         TestLongLongToString(); 
7016         TestLongLongPrintf(); 
7018 #endif // TEST_LONGLONG 
7026 #endif // TEST_HASHMAP 
7030 #endif // TEST_HASHSET 
7033     wxLog::AddTraceMask(_T("mime")); 
7038         TestMimeAssociate(); 
7043 #ifdef TEST_INFO_FUNCTIONS 
7049         if ( TEST_INTERACTIVE 
) 
7052 #endif // TEST_INFO_FUNCTIONS 
7054 #ifdef TEST_PATHLIST 
7056 #endif // TEST_PATHLIST 
7064 #endif // TEST_PRINTF 
7068 #endif // TEST_REGCONF 
7071     // TODO: write a real test using src/regex/tests file 
7076         TestRegExSubmatch(); 
7077         TestRegExReplacement(); 
7079         if ( TEST_INTERACTIVE 
) 
7080             TestRegExInteractive(); 
7082 #endif // TEST_REGEX 
7084 #ifdef TEST_REGISTRY 
7086     TestRegistryAssociation(); 
7087 #endif // TEST_REGISTRY 
7092 #endif // TEST_SOCKETS 
7100 #endif // TEST_STREAMS 
7102 #ifdef TEST_TEXTSTREAM 
7103     TestTextInputStream(); 
7104 #endif // TEST_TEXTSTREAM 
7107     int nCPUs 
= wxThread::GetCPUCount(); 
7108     wxPrintf(_T("This system has %d CPUs\n"), nCPUs
); 
7110         wxThread::SetConcurrency(nCPUs
); 
7112         TestDetachedThreads(); 
7115         TestJoinableThreads(); 
7116         TestThreadSuspend(); 
7118         TestThreadConditions(); 
7122 #endif // TEST_THREADS 
7126 #endif // TEST_TIMER 
7128 #ifdef TEST_DATETIME 
7141         TestTimeArithmetics(); 
7144         TestTimeSpanFormat(); 
7152     if ( TEST_INTERACTIVE 
) 
7153         TestDateTimeInteractive(); 
7154 #endif // TEST_DATETIME 
7156 #ifdef TEST_SCOPEGUARD 
7161     wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z...")); 
7163 #endif // TEST_USLEEP 
7168 #endif // TEST_VCARD 
7172 #endif // TEST_VOLUME 
7175     TestUnicodeToFromAscii(); 
7176 #endif // TEST_UNICODE 
7180     TestEncodingConverter(); 
7181 #endif // TEST_WCHAR 
7184     TestZipStreamRead(); 
7185     TestZipFileSystem(); 
7189     TestZlibStreamWrite(); 
7190     TestZlibStreamRead();