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"
32 // without this pragma, the stupid compiler precompiles #defines below so that
33 // changing them doesn't "take place" later!
38 // ----------------------------------------------------------------------------
39 // conditional compilation
40 // ----------------------------------------------------------------------------
43 A note about all these conditional compilation macros: this file is used
44 both as a test suite for various non-GUI wxWindows classes and as a
45 scratchpad for quick tests. So there are two compilation modes: if you
46 define TEST_ALL all tests are run, otherwise you may enable the individual
47 tests individually in the "#else" branch below.
50 // what to test (in alphabetic order)? uncomment the line below to do all tests
58 #define TEST_DLLLOADER
68 #define TEST_INFO_FUNCTIONS
85 // #define TEST_VCARD -- don't enable this (VZ)
91 static const bool TEST_ALL
= TRUE
;
95 static const bool TEST_ALL
= FALSE
;
98 // some tests are interactive, define this to run them
99 #ifdef TEST_INTERACTIVE
100 #undef TEST_INTERACTIVE
102 static const bool TEST_INTERACTIVE
= TRUE
;
104 static const bool TEST_INTERACTIVE
= FALSE
;
107 // ----------------------------------------------------------------------------
108 // test class for container objects
109 // ----------------------------------------------------------------------------
111 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
113 class Bar
// Foo is already taken in the hash test
116 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
117 ~Bar() { ms_bars
--; }
119 static size_t GetNumber() { return ms_bars
; }
121 const char *GetName() const { return m_name
; }
126 static size_t ms_bars
;
129 size_t Bar::ms_bars
= 0;
131 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
133 // ============================================================================
135 // ============================================================================
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
143 // replace TABs with \t and CRs with \n
144 static wxString
MakePrintable(const wxChar
*s
)
147 (void)str
.Replace(_T("\t"), _T("\\t"));
148 (void)str
.Replace(_T("\n"), _T("\\n"));
149 (void)str
.Replace(_T("\r"), _T("\\r"));
154 #endif // MakePrintable() is used
156 // ----------------------------------------------------------------------------
157 // wxFontMapper::CharsetToEncoding
158 // ----------------------------------------------------------------------------
162 #include "wx/fontmap.h"
164 static void TestCharset()
166 static const wxChar
*charsets
[] =
168 // some vali charsets
177 // and now some bogus ones
184 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
186 wxFontEncoding enc
= wxTheFontMapper
->CharsetToEncoding(charsets
[n
]);
187 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
189 wxTheFontMapper
->GetEncodingName(enc
).c_str(),
190 wxTheFontMapper
->GetEncodingDescription(enc
).c_str());
194 #endif // TEST_CHARSET
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
202 #include "wx/cmdline.h"
203 #include "wx/datetime.h"
205 #if wxUSE_CMDLINE_PARSER
207 static void ShowCmdLine(const wxCmdLineParser
& parser
)
209 wxString s
= "Input files: ";
211 size_t count
= parser
.GetParamCount();
212 for ( size_t param
= 0; param
< count
; param
++ )
214 s
<< parser
.GetParam(param
) << ' ';
218 << "Verbose:\t" << (parser
.Found("v") ? "yes" : "no") << '\n'
219 << "Quiet:\t" << (parser
.Found("q") ? "yes" : "no") << '\n';
224 if ( parser
.Found("o", &strVal
) )
225 s
<< "Output file:\t" << strVal
<< '\n';
226 if ( parser
.Found("i", &strVal
) )
227 s
<< "Input dir:\t" << strVal
<< '\n';
228 if ( parser
.Found("s", &lVal
) )
229 s
<< "Size:\t" << lVal
<< '\n';
230 if ( parser
.Found("d", &dt
) )
231 s
<< "Date:\t" << dt
.FormatISODate() << '\n';
232 if ( parser
.Found("project_name", &strVal
) )
233 s
<< "Project:\t" << strVal
<< '\n';
238 #endif // wxUSE_CMDLINE_PARSER
240 static void TestCmdLineConvert()
242 static const char *cmdlines
[] =
245 "-a \"-bstring 1\" -c\"string 2\" \"string 3\"",
246 "literal \\\" and \"\"",
249 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
251 const char *cmdline
= cmdlines
[n
];
252 printf("Parsing: %s\n", cmdline
);
253 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
255 size_t count
= args
.GetCount();
256 printf("\targc = %u\n", count
);
257 for ( size_t arg
= 0; arg
< count
; arg
++ )
259 printf("\targv[%u] = %s\n", arg
, args
[arg
].c_str());
264 #endif // TEST_CMDLINE
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
275 static const wxChar
*ROOTDIR
= _T("/");
276 static const wxChar
*TESTDIR
= _T("/usr");
277 #elif defined(__WXMSW__)
278 static const wxChar
*ROOTDIR
= _T("c:\\");
279 static const wxChar
*TESTDIR
= _T("d:\\");
281 #error "don't know where the root directory is"
284 static void TestDirEnumHelper(wxDir
& dir
,
285 int flags
= wxDIR_DEFAULT
,
286 const wxString
& filespec
= wxEmptyString
)
290 if ( !dir
.IsOpened() )
293 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
296 printf("\t%s\n", filename
.c_str());
298 cont
= dir
.GetNext(&filename
);
304 static void TestDirEnum()
306 puts("*** Testing wxDir::GetFirst/GetNext ***");
308 wxDir
dir(wxGetCwd());
310 puts("Enumerating everything in current directory:");
311 TestDirEnumHelper(dir
);
313 puts("Enumerating really everything in current directory:");
314 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
316 puts("Enumerating object files in current directory:");
317 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o");
319 puts("Enumerating directories in current directory:");
320 TestDirEnumHelper(dir
, wxDIR_DIRS
);
322 puts("Enumerating files in current directory:");
323 TestDirEnumHelper(dir
, wxDIR_FILES
);
325 puts("Enumerating files including hidden in current directory:");
326 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
330 puts("Enumerating everything in root directory:");
331 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
333 puts("Enumerating directories in root directory:");
334 TestDirEnumHelper(dir
, wxDIR_DIRS
);
336 puts("Enumerating files in root directory:");
337 TestDirEnumHelper(dir
, wxDIR_FILES
);
339 puts("Enumerating files including hidden in root directory:");
340 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
342 puts("Enumerating files in non existing directory:");
343 wxDir
dirNo("nosuchdir");
344 TestDirEnumHelper(dirNo
);
347 class DirPrintTraverser
: public wxDirTraverser
350 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
352 return wxDIR_CONTINUE
;
355 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
357 wxString path
, name
, ext
;
358 wxSplitPath(dirname
, &path
, &name
, &ext
);
361 name
<< _T('.') << ext
;
364 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
366 if ( wxIsPathSeparator(*p
) )
370 printf("%s%s\n", indent
.c_str(), name
.c_str());
372 return wxDIR_CONTINUE
;
376 static void TestDirTraverse()
378 puts("*** Testing wxDir::Traverse() ***");
382 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
383 printf("There are %u files under '%s'\n", n
, TESTDIR
);
386 printf("First one is '%s'\n", files
[0u].c_str());
387 printf(" last one is '%s'\n", files
[n
- 1].c_str());
390 // enum again with custom traverser
392 DirPrintTraverser traverser
;
393 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
398 // ----------------------------------------------------------------------------
400 // ----------------------------------------------------------------------------
402 #ifdef TEST_DLLLOADER
404 #include "wx/dynlib.h"
406 static void TestDllLoad()
408 #if defined(__WXMSW__)
409 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
410 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
411 #elif defined(__UNIX__)
412 // weird: using just libc.so does *not* work!
413 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
414 static const wxChar
*FUNC_NAME
= _T("strlen");
416 #error "don't know how to test wxDllLoader on this platform"
419 puts("*** testing wxDllLoader ***\n");
421 wxDllType dllHandle
= wxDllLoader::LoadLibrary(LIB_NAME
);
424 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
428 typedef int (*strlenType
)(const char *);
429 strlenType pfnStrlen
= (strlenType
)wxDllLoader::GetSymbol(dllHandle
, FUNC_NAME
);
432 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
433 FUNC_NAME
, LIB_NAME
);
437 if ( pfnStrlen("foo") != 3 )
439 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
447 wxDllLoader::UnloadLibrary(dllHandle
);
451 #endif // TEST_DLLLOADER
453 // ----------------------------------------------------------------------------
455 // ----------------------------------------------------------------------------
459 #include "wx/utils.h"
461 static wxString
MyGetEnv(const wxString
& var
)
464 if ( !wxGetEnv(var
, &val
) )
467 val
= wxString(_T('\'')) + val
+ _T('\'');
472 static void TestEnvironment()
474 const wxChar
*var
= _T("wxTestVar");
476 puts("*** testing environment access functions ***");
478 printf("Initially getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
479 wxSetEnv(var
, _T("value for wxTestVar"));
480 printf("After wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
481 wxSetEnv(var
, _T("another value"));
482 printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
484 printf("After wxUnsetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
485 printf("PATH = %s\n", MyGetEnv(_T("PATH")).c_str());
488 #endif // TEST_ENVIRON
490 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
496 #include "wx/utils.h"
498 static void TestExecute()
500 puts("*** testing wxExecute ***");
503 #define COMMAND "cat -n ../../Makefile" // "echo hi"
504 #define SHELL_COMMAND "echo hi from shell"
505 #define REDIRECT_COMMAND COMMAND // "date"
506 #elif defined(__WXMSW__)
507 #define COMMAND "command.com -c 'echo hi'"
508 #define SHELL_COMMAND "echo hi"
509 #define REDIRECT_COMMAND COMMAND
511 #error "no command to exec"
514 printf("Testing wxShell: ");
516 if ( wxShell(SHELL_COMMAND
) )
521 printf("Testing wxExecute: ");
523 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
528 #if 0 // no, it doesn't work (yet?)
529 printf("Testing async wxExecute: ");
531 if ( wxExecute(COMMAND
) != 0 )
532 puts("Ok (command launched).");
537 printf("Testing wxExecute with redirection:\n");
538 wxArrayString output
;
539 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
545 size_t count
= output
.GetCount();
546 for ( size_t n
= 0; n
< count
; n
++ )
548 printf("\t%s\n", output
[n
].c_str());
555 #endif // TEST_EXECUTE
557 // ----------------------------------------------------------------------------
559 // ----------------------------------------------------------------------------
564 #include "wx/ffile.h"
565 #include "wx/textfile.h"
567 static void TestFileRead()
569 puts("*** wxFile read test ***");
571 wxFile
file(_T("testdata.fc"));
572 if ( file
.IsOpened() )
574 printf("File length: %lu\n", file
.Length());
576 puts("File dump:\n----------");
578 static const off_t len
= 1024;
582 off_t nRead
= file
.Read(buf
, len
);
583 if ( nRead
== wxInvalidOffset
)
585 printf("Failed to read the file.");
589 fwrite(buf
, nRead
, 1, stdout
);
599 printf("ERROR: can't open test file.\n");
605 static void TestTextFileRead()
607 puts("*** wxTextFile read test ***");
609 wxTextFile
file(_T("testdata.fc"));
612 printf("Number of lines: %u\n", file
.GetLineCount());
613 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
617 puts("\nDumping the entire file:");
618 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
620 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
622 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
624 puts("\nAnd now backwards:");
625 for ( s
= file
.GetLastLine();
626 file
.GetCurrentLine() != 0;
627 s
= file
.GetPrevLine() )
629 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
631 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
635 printf("ERROR: can't open '%s'\n", file
.GetName());
641 static void TestFileCopy()
643 puts("*** Testing wxCopyFile ***");
645 static const wxChar
*filename1
= _T("testdata.fc");
646 static const wxChar
*filename2
= _T("test2");
647 if ( !wxCopyFile(filename1
, filename2
) )
649 puts("ERROR: failed to copy file");
653 wxFFile
f1(filename1
, "rb"),
656 if ( !f1
.IsOpened() || !f2
.IsOpened() )
658 puts("ERROR: failed to open file(s)");
663 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
665 puts("ERROR: failed to read file(s)");
669 if ( (s1
.length() != s2
.length()) ||
670 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
672 puts("ERROR: copy error!");
676 puts("File was copied ok.");
682 if ( !wxRemoveFile(filename2
) )
684 puts("ERROR: failed to remove the file");
692 // ----------------------------------------------------------------------------
694 // ----------------------------------------------------------------------------
698 #include "wx/confbase.h"
699 #include "wx/fileconf.h"
701 static const struct FileConfTestData
703 const wxChar
*name
; // value name
704 const wxChar
*value
; // the value from the file
707 { _T("value1"), _T("one") },
708 { _T("value2"), _T("two") },
709 { _T("novalue"), _T("default") },
712 static void TestFileConfRead()
714 puts("*** testing wxFileConfig loading/reading ***");
716 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
717 _T("testdata.fc"), wxEmptyString
,
718 wxCONFIG_USE_RELATIVE_PATH
);
720 // test simple reading
721 puts("\nReading config file:");
722 wxString
defValue(_T("default")), value
;
723 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
725 const FileConfTestData
& data
= fcTestData
[n
];
726 value
= fileconf
.Read(data
.name
, defValue
);
727 printf("\t%s = %s ", data
.name
, value
.c_str());
728 if ( value
== data
.value
)
734 printf("(ERROR: should be %s)\n", data
.value
);
738 // test enumerating the entries
739 puts("\nEnumerating all root entries:");
742 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
745 printf("\t%s = %s\n",
747 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
749 cont
= fileconf
.GetNextEntry(name
, dummy
);
753 #endif // TEST_FILECONF
755 // ----------------------------------------------------------------------------
757 // ----------------------------------------------------------------------------
761 #include "wx/filename.h"
763 static void DumpFileName(const wxFileName
& fn
)
765 wxString full
= fn
.GetFullPath();
767 wxString vol
, path
, name
, ext
;
768 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
770 wxPrintf(_T("Filename '%s' -> vol '%s', path '%s', name '%s', ext '%s'\n"),
771 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
774 static struct FileNameInfo
776 const wxChar
*fullname
;
777 const wxChar
*volume
;
786 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), TRUE
, wxPATH_UNIX
},
787 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), TRUE
, wxPATH_UNIX
},
788 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), TRUE
, wxPATH_UNIX
},
789 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), FALSE
, wxPATH_UNIX
},
790 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_UNIX
},
791 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), TRUE
, wxPATH_UNIX
},
792 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), TRUE
, wxPATH_UNIX
},
793 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), FALSE
, wxPATH_UNIX
},
794 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), TRUE
, wxPATH_UNIX
},
796 // Windows file names
797 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
798 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
799 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
800 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), TRUE
, wxPATH_DOS
},
801 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), TRUE
, wxPATH_DOS
},
802 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), TRUE
, wxPATH_DOS
},
805 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
806 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
807 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), TRUE
, wxPATH_MAC
},
808 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), FALSE
, wxPATH_MAC
},
809 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
810 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
813 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), TRUE
, wxPATH_VMS
},
814 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), FALSE
, wxPATH_VMS
},
817 static void TestFileNameConstruction()
819 puts("*** testing wxFileName construction ***");
821 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
823 const FileNameInfo
& fni
= filenames
[n
];
825 wxFileName
fn(fni
.fullname
, fni
.format
);
827 wxString fullname
= fn
.GetFullPath(fni
.format
);
828 if ( fullname
!= fni
.fullname
)
830 printf("ERROR: fullname should be '%s'\n", fni
.fullname
);
833 bool isAbsolute
= fn
.IsAbsolute();
834 printf("'%s' is %s (%s)\n\t",
836 isAbsolute
? "absolute" : "relative",
837 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
839 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
841 puts("ERROR (couldn't be normalized)");
845 printf("normalized: '%s'\n", fn
.GetFullPath(fni
.format
).c_str());
852 static void TestFileNameSplit()
854 puts("*** testing wxFileName splitting ***");
856 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
858 const FileNameInfo
& fni
= filenames
[n
];
859 wxString volume
, path
, name
, ext
;
860 wxFileName::SplitPath(fni
.fullname
,
861 &volume
, &path
, &name
, &ext
, fni
.format
);
863 printf("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'",
865 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
867 if ( volume
!= fni
.volume
)
868 printf(" (ERROR: volume = '%s')", fni
.volume
);
869 if ( path
!= fni
.path
)
870 printf(" (ERROR: path = '%s')", fni
.path
);
871 if ( name
!= fni
.name
)
872 printf(" (ERROR: name = '%s')", fni
.name
);
873 if ( ext
!= fni
.ext
)
874 printf(" (ERROR: ext = '%s')", fni
.ext
);
880 static void TestFileNameTemp()
882 puts("*** testing wxFileName temp file creation ***");
884 static const char *tmpprefixes
[] =
890 "/tmp/foo/bar", // this one must be an error
893 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
895 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
898 printf("Prefix '%s'\t-> temp file '%s'\n",
899 tmpprefixes
[n
], path
.c_str());
901 if ( !wxRemoveFile(path
) )
903 wxLogWarning("Failed to remove temp file '%s'", path
.c_str());
909 static void TestFileNameMakeRelative()
911 puts("*** testing wxFileName::MakeRelativeTo() ***");
913 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
915 const FileNameInfo
& fni
= filenames
[n
];
917 wxFileName
fn(fni
.fullname
, fni
.format
);
919 // choose the base dir of the same format
921 switch ( fni
.format
)
933 // TODO: I don't know how this is supposed to work there
936 case wxPATH_NATIVE
: // make gcc happy
938 wxFAIL_MSG( "unexpected path format" );
941 printf("'%s' relative to '%s': ",
942 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
944 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
950 printf("'%s'\n", fn
.GetFullPath(fni
.format
).c_str());
955 static void TestFileNameComparison()
960 static void TestFileNameOperations()
965 static void TestFileNameCwd()
970 #endif // TEST_FILENAME
972 // ----------------------------------------------------------------------------
973 // wxFileName time functions
974 // ----------------------------------------------------------------------------
978 #include <wx/filename.h>
979 #include <wx/datetime.h>
981 static void TestFileGetTimes()
983 wxFileName
fn(_T("testdata.fc"));
985 wxDateTime dtAccess
, dtMod
, dtChange
;
986 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtChange
) )
988 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
992 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
994 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
995 wxPrintf(_T("Access: \t%s\n"), dtAccess
.Format(fmt
).c_str());
996 wxPrintf(_T("Mod/creation:\t%s\n"), dtMod
.Format(fmt
).c_str());
997 wxPrintf(_T("Change: \t%s\n"), dtChange
.Format(fmt
).c_str());
1001 static void TestFileSetTimes()
1003 wxFileName
fn(_T("testdata.fc"));
1007 wxPrintf(_T("ERROR: Touch() failed.\n"));
1011 #endif // TEST_FILETIME
1013 // ----------------------------------------------------------------------------
1015 // ----------------------------------------------------------------------------
1019 #include "wx/hash.h"
1023 Foo(int n_
) { n
= n_
; count
++; }
1028 static size_t count
;
1031 size_t Foo::count
= 0;
1033 WX_DECLARE_LIST(Foo
, wxListFoos
);
1034 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1036 #include "wx/listimpl.cpp"
1038 WX_DEFINE_LIST(wxListFoos
);
1040 static void TestHash()
1042 puts("*** Testing wxHashTable ***\n");
1046 hash
.DeleteContents(TRUE
);
1048 printf("Hash created: %u foos in hash, %u foos totally\n",
1049 hash
.GetCount(), Foo::count
);
1051 static const int hashTestData
[] =
1053 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1057 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1059 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1062 printf("Hash filled: %u foos in hash, %u foos totally\n",
1063 hash
.GetCount(), Foo::count
);
1065 puts("Hash access test:");
1066 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1068 printf("\tGetting element with key %d, value %d: ",
1069 hashTestData
[n
], n
);
1070 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1073 printf("ERROR, not found.\n");
1077 printf("%d (%s)\n", foo
->n
,
1078 (size_t)foo
->n
== n
? "ok" : "ERROR");
1082 printf("\nTrying to get an element not in hash: ");
1084 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1086 puts("ERROR: found!");
1090 puts("ok (not found)");
1094 printf("Hash destroyed: %u foos left\n", Foo::count
);
1099 // ----------------------------------------------------------------------------
1101 // ----------------------------------------------------------------------------
1105 #include "wx/hashmap.h"
1107 // test compilation of basic map types
1108 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1109 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1110 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1111 myUnsignedHashMap
);
1112 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1114 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1116 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1118 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1122 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1123 // myStringHashMap );
1124 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1126 typedef myStringHashMap::iterator Itor
;
1128 static void TestHashMap()
1130 puts("*** Testing wxHashMap ***\n");
1131 myStringHashMap
sh(0); // as small as possible
1134 const size_t count
= 10000;
1136 // init with some data
1137 for( i
= 0; i
< count
; ++i
)
1139 buf
.Printf(wxT("%d"), i
);
1140 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1143 // test that insertion worked
1144 if( sh
.size() != count
)
1146 printf("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n", sh
.size(), count
);
1149 for( i
= 0; i
< count
; ++i
)
1151 buf
.Printf(wxT("%d"), i
);
1152 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1154 printf("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n");
1159 // check that iterators work
1161 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1165 printf("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n");
1169 if( it
->second
!= sh
[it
->first
] )
1171 printf("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n");
1176 if( sh
.size() != i
)
1178 printf("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n", i
, count
);
1181 // test copy ctor, assignment operator
1182 myStringHashMap
h1( sh
), h2( 0 );
1185 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1187 if( h1
[it
->first
] != it
->second
)
1189 printf("*** ERROR: COPY CTOR BROKEN %s ***\n", it
->first
.c_str());
1192 if( h2
[it
->first
] != it
->second
)
1194 printf("*** ERROR: OPERATOR= BROKEN %s ***\n", it
->first
.c_str());
1199 for( i
= 0; i
< count
; ++i
)
1201 buf
.Printf(wxT("%d"), i
);
1202 size_t sz
= sh
.size();
1204 // test find() and erase(it)
1207 it
= sh
.find( buf
);
1208 if( it
!= sh
.end() )
1212 if( sh
.find( buf
) != sh
.end() )
1214 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1218 printf("*** ERROR: CANT FIND ELEMENT %u ***\n", i
);
1223 size_t c
= sh
.erase( buf
);
1225 printf("*** ERROR: SHOULD RETURN 1 ***\n");
1227 if( sh
.find( buf
) != sh
.end() )
1229 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1233 // count should decrease
1234 if( sh
.size() != sz
- 1 )
1236 printf("*** ERROR: COUNT DID NOT DECREASE ***\n");
1240 printf("*** Finished testing wxHashMap ***\n");
1243 #endif // TEST_HASHMAP
1245 // ----------------------------------------------------------------------------
1247 // ----------------------------------------------------------------------------
1251 #include "wx/list.h"
1253 WX_DECLARE_LIST(Bar
, wxListBars
);
1254 #include "wx/listimpl.cpp"
1255 WX_DEFINE_LIST(wxListBars
);
1257 static void TestListCtor()
1259 puts("*** Testing wxList construction ***\n");
1263 list1
.Append(new Bar(_T("first")));
1264 list1
.Append(new Bar(_T("second")));
1266 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
1267 list1
.GetCount(), Bar::GetNumber());
1272 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
1273 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1275 list1
.DeleteContents(TRUE
);
1278 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
1283 // ----------------------------------------------------------------------------
1285 // ----------------------------------------------------------------------------
1289 #include "wx/intl.h"
1290 #include "wx/utils.h" // for wxSetEnv
1292 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1294 // find the name of the language from its value
1295 static const char *GetLangName(int lang
)
1297 static const char *languageNames
[] =
1318 "ARABIC_SAUDI_ARABIA",
1343 "CHINESE_SIMPLIFIED",
1344 "CHINESE_TRADITIONAL",
1347 "CHINESE_SINGAPORE",
1358 "ENGLISH_AUSTRALIA",
1362 "ENGLISH_CARIBBEAN",
1366 "ENGLISH_NEW_ZEALAND",
1367 "ENGLISH_PHILIPPINES",
1368 "ENGLISH_SOUTH_AFRICA",
1380 "FRENCH_LUXEMBOURG",
1389 "GERMAN_LIECHTENSTEIN",
1390 "GERMAN_LUXEMBOURG",
1431 "MALAY_BRUNEI_DARUSSALAM",
1443 "NORWEGIAN_NYNORSK",
1450 "PORTUGUESE_BRAZILIAN",
1475 "SPANISH_ARGENTINA",
1479 "SPANISH_COSTA_RICA",
1480 "SPANISH_DOMINICAN_REPUBLIC",
1482 "SPANISH_EL_SALVADOR",
1483 "SPANISH_GUATEMALA",
1487 "SPANISH_NICARAGUA",
1491 "SPANISH_PUERTO_RICO",
1494 "SPANISH_VENEZUELA",
1531 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1532 return languageNames
[lang
];
1537 static void TestDefaultLang()
1539 puts("*** Testing wxLocale::GetSystemLanguage ***");
1541 static const wxChar
*langStrings
[] =
1543 NULL
, // system default
1550 _T("de_DE.iso88591"),
1552 _T("?"), // invalid lang spec
1553 _T("klingonese"), // I bet on some systems it does exist...
1556 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1557 wxLocale::GetSystemEncodingName().c_str(),
1558 wxLocale::GetSystemEncoding());
1560 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1562 const char *langStr
= langStrings
[n
];
1565 // FIXME: this doesn't do anything at all under Windows, we need
1566 // to create a new wxLocale!
1567 wxSetEnv(_T("LC_ALL"), langStr
);
1570 int lang
= gs_localeDefault
.GetSystemLanguage();
1571 printf("Locale for '%s' is %s.\n",
1572 langStr
? langStr
: "system default", GetLangName(lang
));
1576 #endif // TEST_LOCALE
1578 // ----------------------------------------------------------------------------
1580 // ----------------------------------------------------------------------------
1584 #include "wx/mimetype.h"
1586 static void TestMimeEnum()
1588 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1590 wxArrayString mimetypes
;
1592 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1594 printf("*** All %u known filetypes: ***\n", count
);
1599 for ( size_t n
= 0; n
< count
; n
++ )
1601 wxFileType
*filetype
=
1602 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1605 printf("nothing known about the filetype '%s'!\n",
1606 mimetypes
[n
].c_str());
1610 filetype
->GetDescription(&desc
);
1611 filetype
->GetExtensions(exts
);
1613 filetype
->GetIcon(NULL
);
1616 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1619 extsAll
<< _T(", ");
1623 printf("\t%s: %s (%s)\n",
1624 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1630 static void TestMimeOverride()
1632 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1634 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1635 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1637 if ( wxFile::Exists(mailcap
) )
1638 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1640 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1642 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1645 if ( wxFile::Exists(mimetypes
) )
1646 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1648 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1650 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1656 static void TestMimeFilename()
1658 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1660 static const wxChar
*filenames
[] =
1667 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1669 const wxString fname
= filenames
[n
];
1670 wxString ext
= fname
.AfterLast(_T('.'));
1671 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1674 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1679 if ( !ft
->GetDescription(&desc
) )
1680 desc
= _T("<no description>");
1683 if ( !ft
->GetOpenCommand(&cmd
,
1684 wxFileType::MessageParameters(fname
, _T(""))) )
1685 cmd
= _T("<no command available>");
1687 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
1688 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1697 static void TestMimeAssociate()
1699 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1701 wxFileTypeInfo
ftInfo(
1702 _T("application/x-xyz"),
1703 _T("xyzview '%s'"), // open cmd
1704 _T(""), // print cmd
1705 _T("XYZ File") // description
1706 _T(".xyz"), // extensions
1707 NULL
// end of extensions
1709 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1711 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1714 wxPuts(_T("ERROR: failed to create association!"));
1718 // TODO: read it back
1727 // ----------------------------------------------------------------------------
1728 // misc information functions
1729 // ----------------------------------------------------------------------------
1731 #ifdef TEST_INFO_FUNCTIONS
1733 #include "wx/utils.h"
1735 static void TestDiskInfo()
1737 puts("*** Testing wxGetDiskSpace() ***");
1742 printf("\nEnter a directory name: ");
1743 if ( !fgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1746 // kill the last '\n'
1747 pathname
[strlen(pathname
) - 1] = 0;
1749 wxLongLong total
, free
;
1750 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1752 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1756 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1757 (total
/ 1024).ToString().c_str(),
1758 (free
/ 1024).ToString().c_str(),
1764 static void TestOsInfo()
1766 puts("*** Testing OS info functions ***\n");
1769 wxGetOsVersion(&major
, &minor
);
1770 printf("Running under: %s, version %d.%d\n",
1771 wxGetOsDescription().c_str(), major
, minor
);
1773 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
1775 printf("Host name is %s (%s).\n",
1776 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1781 static void TestUserInfo()
1783 puts("*** Testing user info functions ***\n");
1785 printf("User id is:\t%s\n", wxGetUserId().c_str());
1786 printf("User name is:\t%s\n", wxGetUserName().c_str());
1787 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
1788 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
1793 #endif // TEST_INFO_FUNCTIONS
1795 // ----------------------------------------------------------------------------
1797 // ----------------------------------------------------------------------------
1799 #ifdef TEST_LONGLONG
1801 #include "wx/longlong.h"
1802 #include "wx/timer.h"
1804 // make a 64 bit number from 4 16 bit ones
1805 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
1807 // get a random 64 bit number
1808 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
1810 static const long testLongs
[] =
1821 #if wxUSE_LONGLONG_WX
1822 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
1823 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1824 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
1825 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1826 #endif // wxUSE_LONGLONG_WX
1828 static void TestSpeed()
1830 static const long max
= 100000000;
1837 for ( n
= 0; n
< max
; n
++ )
1842 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
1845 #if wxUSE_LONGLONG_NATIVE
1850 for ( n
= 0; n
< max
; n
++ )
1855 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
1857 #endif // wxUSE_LONGLONG_NATIVE
1863 for ( n
= 0; n
< max
; n
++ )
1868 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
1872 static void TestLongLongConversion()
1874 puts("*** Testing wxLongLong conversions ***\n");
1878 for ( size_t n
= 0; n
< 100000; n
++ )
1882 #if wxUSE_LONGLONG_NATIVE
1883 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
1885 wxASSERT_MSG( a
== b
, "conversions failure" );
1887 puts("Can't do it without native long long type, test skipped.");
1890 #endif // wxUSE_LONGLONG_NATIVE
1892 if ( !(nTested
% 1000) )
1904 static void TestMultiplication()
1906 puts("*** Testing wxLongLong multiplication ***\n");
1910 for ( size_t n
= 0; n
< 100000; n
++ )
1915 #if wxUSE_LONGLONG_NATIVE
1916 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
1917 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
1919 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
1920 #else // !wxUSE_LONGLONG_NATIVE
1921 puts("Can't do it without native long long type, test skipped.");
1924 #endif // wxUSE_LONGLONG_NATIVE
1926 if ( !(nTested
% 1000) )
1938 static void TestDivision()
1940 puts("*** Testing wxLongLong division ***\n");
1944 for ( size_t n
= 0; n
< 100000; n
++ )
1946 // get a random wxLongLong (shifting by 12 the MSB ensures that the
1947 // multiplication will not overflow)
1948 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
1950 // get a random (but non null) long (not wxLongLong for now) to divide
1962 #if wxUSE_LONGLONG_NATIVE
1963 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
1965 wxLongLongNative p
= m
/ l
, s
= m
% l
;
1966 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
1967 #else // !wxUSE_LONGLONG_NATIVE
1968 // verify the result
1969 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
1970 #endif // wxUSE_LONGLONG_NATIVE
1972 if ( !(nTested
% 1000) )
1984 static void TestAddition()
1986 puts("*** Testing wxLongLong addition ***\n");
1990 for ( size_t n
= 0; n
< 100000; n
++ )
1996 #if wxUSE_LONGLONG_NATIVE
1997 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
1998 wxLongLongNative(b
.GetHi(), b
.GetLo()),
1999 "addition failure" );
2000 #else // !wxUSE_LONGLONG_NATIVE
2001 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2002 #endif // wxUSE_LONGLONG_NATIVE
2004 if ( !(nTested
% 1000) )
2016 static void TestBitOperations()
2018 puts("*** Testing wxLongLong bit operation ***\n");
2022 for ( size_t n
= 0; n
< 100000; n
++ )
2026 #if wxUSE_LONGLONG_NATIVE
2027 for ( size_t n
= 0; n
< 33; n
++ )
2030 #else // !wxUSE_LONGLONG_NATIVE
2031 puts("Can't do it without native long long type, test skipped.");
2034 #endif // wxUSE_LONGLONG_NATIVE
2036 if ( !(nTested
% 1000) )
2048 static void TestLongLongComparison()
2050 #if wxUSE_LONGLONG_WX
2051 puts("*** Testing wxLongLong comparison ***\n");
2053 static const long ls
[2] =
2059 wxLongLongWx lls
[2];
2063 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2067 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2069 res
= lls
[m
] > testLongs
[n
];
2070 printf("0x%lx > 0x%lx is %s (%s)\n",
2071 ls
[m
], testLongs
[n
], res
? "true" : "false",
2072 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2074 res
= lls
[m
] < testLongs
[n
];
2075 printf("0x%lx < 0x%lx is %s (%s)\n",
2076 ls
[m
], testLongs
[n
], res
? "true" : "false",
2077 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2079 res
= lls
[m
] == testLongs
[n
];
2080 printf("0x%lx == 0x%lx is %s (%s)\n",
2081 ls
[m
], testLongs
[n
], res
? "true" : "false",
2082 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2085 #endif // wxUSE_LONGLONG_WX
2088 static void TestLongLongPrint()
2090 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2092 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2094 wxLongLong ll
= testLongs
[n
];
2095 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2098 wxLongLong
ll(0x12345678, 0x87654321);
2099 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2102 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2108 #endif // TEST_LONGLONG
2110 // ----------------------------------------------------------------------------
2112 // ----------------------------------------------------------------------------
2114 #ifdef TEST_PATHLIST
2116 static void TestPathList()
2118 puts("*** Testing wxPathList ***\n");
2120 wxPathList pathlist
;
2121 pathlist
.AddEnvList("PATH");
2122 wxString path
= pathlist
.FindValidPath("ls");
2125 printf("ERROR: command not found in the path.\n");
2129 printf("Command found in the path as '%s'.\n", path
.c_str());
2133 #endif // TEST_PATHLIST
2135 // ----------------------------------------------------------------------------
2136 // regular expressions
2137 // ----------------------------------------------------------------------------
2141 #include "wx/regex.h"
2143 static void TestRegExCompile()
2145 wxPuts(_T("*** Testing RE compilation ***\n"));
2147 static struct RegExCompTestData
2149 const wxChar
*pattern
;
2151 } regExCompTestData
[] =
2153 { _T("foo"), TRUE
},
2154 { _T("foo("), FALSE
},
2155 { _T("foo(bar"), FALSE
},
2156 { _T("foo(bar)"), TRUE
},
2157 { _T("foo["), FALSE
},
2158 { _T("foo[bar"), FALSE
},
2159 { _T("foo[bar]"), TRUE
},
2160 { _T("foo{"), TRUE
},
2161 { _T("foo{1"), FALSE
},
2162 { _T("foo{bar"), TRUE
},
2163 { _T("foo{1}"), TRUE
},
2164 { _T("foo{1,2}"), TRUE
},
2165 { _T("foo{bar}"), TRUE
},
2166 { _T("foo*"), TRUE
},
2167 { _T("foo**"), FALSE
},
2168 { _T("foo+"), TRUE
},
2169 { _T("foo++"), FALSE
},
2170 { _T("foo?"), TRUE
},
2171 { _T("foo??"), FALSE
},
2172 { _T("foo?+"), FALSE
},
2176 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2178 const RegExCompTestData
& data
= regExCompTestData
[n
];
2179 bool ok
= re
.Compile(data
.pattern
);
2181 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2183 ok
? _T("") : _T("not "),
2184 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2188 static void TestRegExMatch()
2190 wxPuts(_T("*** Testing RE matching ***\n"));
2192 static struct RegExMatchTestData
2194 const wxChar
*pattern
;
2197 } regExMatchTestData
[] =
2199 { _T("foo"), _T("bar"), FALSE
},
2200 { _T("foo"), _T("foobar"), TRUE
},
2201 { _T("^foo"), _T("foobar"), TRUE
},
2202 { _T("^foo"), _T("barfoo"), FALSE
},
2203 { _T("bar$"), _T("barbar"), TRUE
},
2204 { _T("bar$"), _T("barbar "), FALSE
},
2207 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2209 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2211 wxRegEx
re(data
.pattern
);
2212 bool ok
= re
.Matches(data
.text
);
2214 wxPrintf(_T("'%s' %s %s (%s)\n"),
2216 ok
? _T("matches") : _T("doesn't match"),
2218 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2222 static void TestRegExSubmatch()
2224 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2226 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2227 if ( !re
.IsValid() )
2229 wxPuts(_T("ERROR: compilation failed."));
2233 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2235 if ( !re
.Matches(text
) )
2237 wxPuts(_T("ERROR: match expected."));
2241 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2243 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2244 re
.GetMatch(text
, 3).c_str(),
2245 re
.GetMatch(text
, 2).c_str(),
2246 re
.GetMatch(text
, 4).c_str(),
2247 re
.GetMatch(text
, 1).c_str());
2251 static void TestRegExReplacement()
2253 wxPuts(_T("*** Testing RE replacement ***"));
2255 static struct RegExReplTestData
2259 const wxChar
*result
;
2261 } regExReplTestData
[] =
2263 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2264 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2265 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2266 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2267 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2268 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2269 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2272 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2273 wxRegEx
re(pattern
);
2275 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2277 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2279 const RegExReplTestData
& data
= regExReplTestData
[n
];
2281 wxString text
= data
.text
;
2282 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2284 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2285 data
.text
, data
.repl
,
2286 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2288 if ( text
== data
.result
&& nRepl
== data
.count
)
2294 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2295 data
.count
, data
.result
);
2300 static void TestRegExInteractive()
2302 wxPuts(_T("*** Testing RE interactively ***"));
2307 printf("\nEnter a pattern: ");
2308 if ( !fgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2311 // kill the last '\n'
2312 pattern
[strlen(pattern
) - 1] = 0;
2315 if ( !re
.Compile(pattern
) )
2323 printf("Enter text to match: ");
2324 if ( !fgets(text
, WXSIZEOF(text
), stdin
) )
2327 // kill the last '\n'
2328 text
[strlen(text
) - 1] = 0;
2330 if ( !re
.Matches(text
) )
2332 printf("No match.\n");
2336 printf("Pattern matches at '%s'\n", re
.GetMatch(text
).c_str());
2339 for ( size_t n
= 1; ; n
++ )
2341 if ( !re
.GetMatch(&start
, &len
, n
) )
2346 printf("Subexpr %u matched '%s'\n",
2347 n
, wxString(text
+ start
, len
).c_str());
2354 #endif // TEST_REGEX
2356 // ----------------------------------------------------------------------------
2358 // ----------------------------------------------------------------------------
2364 static void TestDbOpen()
2372 // ----------------------------------------------------------------------------
2373 // registry and related stuff
2374 // ----------------------------------------------------------------------------
2376 // this is for MSW only
2379 #undef TEST_REGISTRY
2384 #include "wx/confbase.h"
2385 #include "wx/msw/regconf.h"
2387 static void TestRegConfWrite()
2389 wxRegConfig
regconf(_T("console"), _T("wxwindows"));
2390 regconf
.Write(_T("Hello"), wxString(_T("world")));
2393 #endif // TEST_REGCONF
2395 #ifdef TEST_REGISTRY
2397 #include "wx/msw/registry.h"
2399 // I chose this one because I liked its name, but it probably only exists under
2401 static const wxChar
*TESTKEY
=
2402 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2404 static void TestRegistryRead()
2406 puts("*** testing registry reading ***");
2408 wxRegKey
key(TESTKEY
);
2409 printf("The test key name is '%s'.\n", key
.GetName().c_str());
2412 puts("ERROR: test key can't be opened, aborting test.");
2417 size_t nSubKeys
, nValues
;
2418 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2420 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
2423 printf("Enumerating values:\n");
2427 bool cont
= key
.GetFirstValue(value
, dummy
);
2430 printf("Value '%s': type ", value
.c_str());
2431 switch ( key
.GetValueType(value
) )
2433 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
2434 case wxRegKey::Type_String
: printf("SZ"); break;
2435 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
2436 case wxRegKey::Type_Binary
: printf("BINARY"); break;
2437 case wxRegKey::Type_Dword
: printf("DWORD"); break;
2438 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
2439 default: printf("other (unknown)"); break;
2442 printf(", value = ");
2443 if ( key
.IsNumericValue(value
) )
2446 key
.QueryValue(value
, &val
);
2452 key
.QueryValue(value
, val
);
2453 printf("'%s'", val
.c_str());
2455 key
.QueryRawValue(value
, val
);
2456 printf(" (raw value '%s')", val
.c_str());
2461 cont
= key
.GetNextValue(value
, dummy
);
2465 static void TestRegistryAssociation()
2468 The second call to deleteself genertaes an error message, with a
2469 messagebox saying .flo is crucial to system operation, while the .ddf
2470 call also fails, but with no error message
2475 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2477 key
= "ddxf_auto_file" ;
2478 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2480 key
= "ddxf_auto_file" ;
2481 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2484 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2486 key
= "program \"%1\"" ;
2488 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2490 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2492 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2494 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2498 #endif // TEST_REGISTRY
2500 // ----------------------------------------------------------------------------
2502 // ----------------------------------------------------------------------------
2506 #include "wx/socket.h"
2507 #include "wx/protocol/protocol.h"
2508 #include "wx/protocol/http.h"
2510 static void TestSocketServer()
2512 puts("*** Testing wxSocketServer ***\n");
2514 static const int PORT
= 3000;
2519 wxSocketServer
*server
= new wxSocketServer(addr
);
2520 if ( !server
->Ok() )
2522 puts("ERROR: failed to bind");
2529 printf("Server: waiting for connection on port %d...\n", PORT
);
2531 wxSocketBase
*socket
= server
->Accept();
2534 puts("ERROR: wxSocketServer::Accept() failed.");
2538 puts("Server: got a client.");
2540 server
->SetTimeout(60); // 1 min
2542 while ( socket
->IsConnected() )
2548 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2550 // don't log error if the client just close the connection
2551 if ( socket
->IsConnected() )
2553 puts("ERROR: in wxSocket::Read.");
2573 printf("Server: got '%s'.\n", s
.c_str());
2574 if ( s
== _T("bye") )
2581 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2582 socket
->Write("\r\n", 2);
2583 printf("Server: wrote '%s'.\n", s
.c_str());
2586 puts("Server: lost a client.");
2591 // same as "delete server" but is consistent with GUI programs
2595 static void TestSocketClient()
2597 puts("*** Testing wxSocketClient ***\n");
2599 static const char *hostname
= "www.wxwindows.org";
2602 addr
.Hostname(hostname
);
2605 printf("--- Attempting to connect to %s:80...\n", hostname
);
2607 wxSocketClient client
;
2608 if ( !client
.Connect(addr
) )
2610 printf("ERROR: failed to connect to %s\n", hostname
);
2614 printf("--- Connected to %s:%u...\n",
2615 addr
.Hostname().c_str(), addr
.Service());
2619 // could use simply "GET" here I suppose
2621 wxString::Format("GET http://%s/\r\n", hostname
);
2622 client
.Write(cmdGet
, cmdGet
.length());
2623 printf("--- Sent command '%s' to the server\n",
2624 MakePrintable(cmdGet
).c_str());
2625 client
.Read(buf
, WXSIZEOF(buf
));
2626 printf("--- Server replied:\n%s", buf
);
2630 #endif // TEST_SOCKETS
2632 // ----------------------------------------------------------------------------
2634 // ----------------------------------------------------------------------------
2638 #include "wx/protocol/ftp.h"
2642 #define FTP_ANONYMOUS
2644 #ifdef FTP_ANONYMOUS
2645 static const char *directory
= "/pub";
2646 static const char *filename
= "welcome.msg";
2648 static const char *directory
= "/etc";
2649 static const char *filename
= "issue";
2652 static bool TestFtpConnect()
2654 puts("*** Testing FTP connect ***");
2656 #ifdef FTP_ANONYMOUS
2657 static const char *hostname
= "ftp.wxwindows.org";
2659 printf("--- Attempting to connect to %s:21 anonymously...\n", hostname
);
2660 #else // !FTP_ANONYMOUS
2661 static const char *hostname
= "localhost";
2664 fgets(user
, WXSIZEOF(user
), stdin
);
2665 user
[strlen(user
) - 1] = '\0'; // chop off '\n'
2669 printf("Password for %s: ", password
);
2670 fgets(password
, WXSIZEOF(password
), stdin
);
2671 password
[strlen(password
) - 1] = '\0'; // chop off '\n'
2672 ftp
.SetPassword(password
);
2674 printf("--- Attempting to connect to %s:21 as %s...\n", hostname
, user
);
2675 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2677 if ( !ftp
.Connect(hostname
) )
2679 printf("ERROR: failed to connect to %s\n", hostname
);
2685 printf("--- Connected to %s, current directory is '%s'\n",
2686 hostname
, ftp
.Pwd().c_str());
2692 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2693 static void TestFtpWuFtpd()
2696 static const char *hostname
= "ftp.eudora.com";
2697 if ( !ftp
.Connect(hostname
) )
2699 printf("ERROR: failed to connect to %s\n", hostname
);
2703 static const char *filename
= "eudora/pubs/draft-gellens-submit-09.txt";
2704 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2707 printf("ERROR: couldn't get input stream for %s\n", filename
);
2711 size_t size
= in
->StreamSize();
2712 printf("Reading file %s (%u bytes)...", filename
, size
);
2714 char *data
= new char[size
];
2715 if ( !in
->Read(data
, size
) )
2717 puts("ERROR: read error");
2721 printf("Successfully retrieved the file.\n");
2730 static void TestFtpList()
2732 puts("*** Testing wxFTP file listing ***\n");
2735 if ( !ftp
.ChDir(directory
) )
2737 printf("ERROR: failed to cd to %s\n", directory
);
2740 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2742 // test NLIST and LIST
2743 wxArrayString files
;
2744 if ( !ftp
.GetFilesList(files
) )
2746 puts("ERROR: failed to get NLIST of files");
2750 printf("Brief list of files under '%s':\n", ftp
.Pwd().c_str());
2751 size_t count
= files
.GetCount();
2752 for ( size_t n
= 0; n
< count
; n
++ )
2754 printf("\t%s\n", files
[n
].c_str());
2756 puts("End of the file list");
2759 if ( !ftp
.GetDirList(files
) )
2761 puts("ERROR: failed to get LIST of files");
2765 printf("Detailed list of files under '%s':\n", ftp
.Pwd().c_str());
2766 size_t count
= files
.GetCount();
2767 for ( size_t n
= 0; n
< count
; n
++ )
2769 printf("\t%s\n", files
[n
].c_str());
2771 puts("End of the file list");
2774 if ( !ftp
.ChDir(_T("..")) )
2776 puts("ERROR: failed to cd to ..");
2779 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2782 static void TestFtpDownload()
2784 puts("*** Testing wxFTP download ***\n");
2787 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2790 printf("ERROR: couldn't get input stream for %s\n", filename
);
2794 size_t size
= in
->StreamSize();
2795 printf("Reading file %s (%u bytes)...", filename
, size
);
2798 char *data
= new char[size
];
2799 if ( !in
->Read(data
, size
) )
2801 puts("ERROR: read error");
2805 printf("\nContents of %s:\n%s\n", filename
, data
);
2813 static void TestFtpFileSize()
2815 puts("*** Testing FTP SIZE command ***");
2817 if ( !ftp
.ChDir(directory
) )
2819 printf("ERROR: failed to cd to %s\n", directory
);
2822 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2824 if ( ftp
.FileExists(filename
) )
2826 int size
= ftp
.GetFileSize(filename
);
2828 printf("ERROR: couldn't get size of '%s'\n", filename
);
2830 printf("Size of '%s' is %d bytes.\n", filename
, size
);
2834 printf("ERROR: '%s' doesn't exist\n", filename
);
2838 static void TestFtpMisc()
2840 puts("*** Testing miscellaneous wxFTP functions ***");
2842 if ( ftp
.SendCommand("STAT") != '2' )
2844 puts("ERROR: STAT failed");
2848 printf("STAT returned:\n\n%s\n", ftp
.GetLastResult().c_str());
2851 if ( ftp
.SendCommand("HELP SITE") != '2' )
2853 puts("ERROR: HELP SITE failed");
2857 printf("The list of site-specific commands:\n\n%s\n",
2858 ftp
.GetLastResult().c_str());
2862 static void TestFtpInteractive()
2864 puts("\n*** Interactive wxFTP test ***");
2870 printf("Enter FTP command: ");
2871 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2874 // kill the last '\n'
2875 buf
[strlen(buf
) - 1] = 0;
2877 // special handling of LIST and NLST as they require data connection
2878 wxString
start(buf
, 4);
2880 if ( start
== "LIST" || start
== "NLST" )
2883 if ( strlen(buf
) > 4 )
2886 wxArrayString files
;
2887 if ( !ftp
.GetList(files
, wildcard
, start
== "LIST") )
2889 printf("ERROR: failed to get %s of files\n", start
.c_str());
2893 printf("--- %s of '%s' under '%s':\n",
2894 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2895 size_t count
= files
.GetCount();
2896 for ( size_t n
= 0; n
< count
; n
++ )
2898 printf("\t%s\n", files
[n
].c_str());
2900 puts("--- End of the file list");
2905 char ch
= ftp
.SendCommand(buf
);
2906 printf("Command %s", ch
? "succeeded" : "failed");
2909 printf(" (return code %c)", ch
);
2912 printf(", server reply:\n%s\n\n", ftp
.GetLastResult().c_str());
2916 puts("\n*** done ***");
2919 static void TestFtpUpload()
2921 puts("*** Testing wxFTP uploading ***\n");
2924 static const char *file1
= "test1";
2925 static const char *file2
= "test2";
2926 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2929 printf("--- Uploading to %s ---\n", file1
);
2930 out
->Write("First hello", 11);
2934 // send a command to check the remote file
2935 if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' )
2937 printf("ERROR: STAT %s failed\n", file1
);
2941 printf("STAT %s returned:\n\n%s\n",
2942 file1
, ftp
.GetLastResult().c_str());
2945 out
= ftp
.GetOutputStream(file2
);
2948 printf("--- Uploading to %s ---\n", file1
);
2949 out
->Write("Second hello", 12);
2956 // ----------------------------------------------------------------------------
2958 // ----------------------------------------------------------------------------
2962 #include "wx/wfstream.h"
2963 #include "wx/mstream.h"
2965 static void TestFileStream()
2967 puts("*** Testing wxFileInputStream ***");
2969 static const wxChar
*filename
= _T("testdata.fs");
2971 wxFileOutputStream
fsOut(filename
);
2972 fsOut
.Write("foo", 3);
2975 wxFileInputStream
fsIn(filename
);
2976 printf("File stream size: %u\n", fsIn
.GetSize());
2977 while ( !fsIn
.Eof() )
2979 putchar(fsIn
.GetC());
2982 if ( !wxRemoveFile(filename
) )
2984 printf("ERROR: failed to remove the file '%s'.\n", filename
);
2987 puts("\n*** wxFileInputStream test done ***");
2990 static void TestMemoryStream()
2992 puts("*** Testing wxMemoryInputStream ***");
2995 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
2997 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
2998 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2999 while ( !memInpStream
.Eof() )
3001 putchar(memInpStream
.GetC());
3004 puts("\n*** wxMemoryInputStream test done ***");
3007 #endif // TEST_STREAMS
3009 // ----------------------------------------------------------------------------
3011 // ----------------------------------------------------------------------------
3015 #include "wx/timer.h"
3016 #include "wx/utils.h"
3018 static void TestStopWatch()
3020 puts("*** Testing wxStopWatch ***\n");
3023 printf("Sleeping 3 seconds...");
3025 printf("\telapsed time: %ldms\n", sw
.Time());
3028 printf("Sleeping 2 more seconds...");
3030 printf("\telapsed time: %ldms\n", sw
.Time());
3033 printf("And 3 more seconds...");
3035 printf("\telapsed time: %ldms\n", sw
.Time());
3038 puts("\nChecking for 'backwards clock' bug...");
3039 for ( size_t n
= 0; n
< 70; n
++ )
3043 for ( size_t m
= 0; m
< 100000; m
++ )
3045 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3047 puts("\ntime is negative - ERROR!");
3057 #endif // TEST_TIMER
3059 // ----------------------------------------------------------------------------
3061 // ----------------------------------------------------------------------------
3065 #include "wx/vcard.h"
3067 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3070 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3074 wxString(_T('\t'), level
).c_str(),
3075 vcObj
->GetName().c_str());
3078 switch ( vcObj
->GetType() )
3080 case wxVCardObject::String
:
3081 case wxVCardObject::UString
:
3084 vcObj
->GetValue(&val
);
3085 value
<< _T('"') << val
<< _T('"');
3089 case wxVCardObject::Int
:
3092 vcObj
->GetValue(&i
);
3093 value
.Printf(_T("%u"), i
);
3097 case wxVCardObject::Long
:
3100 vcObj
->GetValue(&l
);
3101 value
.Printf(_T("%lu"), l
);
3105 case wxVCardObject::None
:
3108 case wxVCardObject::Object
:
3109 value
= _T("<node>");
3113 value
= _T("<unknown value type>");
3117 printf(" = %s", value
.c_str());
3120 DumpVObject(level
+ 1, *vcObj
);
3123 vcObj
= vcard
.GetNextProp(&cookie
);
3127 static void DumpVCardAddresses(const wxVCard
& vcard
)
3129 puts("\nShowing all addresses from vCard:\n");
3133 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3137 int flags
= addr
->GetFlags();
3138 if ( flags
& wxVCardAddress::Domestic
)
3140 flagsStr
<< _T("domestic ");
3142 if ( flags
& wxVCardAddress::Intl
)
3144 flagsStr
<< _T("international ");
3146 if ( flags
& wxVCardAddress::Postal
)
3148 flagsStr
<< _T("postal ");
3150 if ( flags
& wxVCardAddress::Parcel
)
3152 flagsStr
<< _T("parcel ");
3154 if ( flags
& wxVCardAddress::Home
)
3156 flagsStr
<< _T("home ");
3158 if ( flags
& wxVCardAddress::Work
)
3160 flagsStr
<< _T("work ");
3163 printf("Address %u:\n"
3165 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3168 addr
->GetPostOffice().c_str(),
3169 addr
->GetExtAddress().c_str(),
3170 addr
->GetStreet().c_str(),
3171 addr
->GetLocality().c_str(),
3172 addr
->GetRegion().c_str(),
3173 addr
->GetPostalCode().c_str(),
3174 addr
->GetCountry().c_str()
3178 addr
= vcard
.GetNextAddress(&cookie
);
3182 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3184 puts("\nShowing all phone numbers from vCard:\n");
3188 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3192 int flags
= phone
->GetFlags();
3193 if ( flags
& wxVCardPhoneNumber::Voice
)
3195 flagsStr
<< _T("voice ");
3197 if ( flags
& wxVCardPhoneNumber::Fax
)
3199 flagsStr
<< _T("fax ");
3201 if ( flags
& wxVCardPhoneNumber::Cellular
)
3203 flagsStr
<< _T("cellular ");
3205 if ( flags
& wxVCardPhoneNumber::Modem
)
3207 flagsStr
<< _T("modem ");
3209 if ( flags
& wxVCardPhoneNumber::Home
)
3211 flagsStr
<< _T("home ");
3213 if ( flags
& wxVCardPhoneNumber::Work
)
3215 flagsStr
<< _T("work ");
3218 printf("Phone number %u:\n"
3223 phone
->GetNumber().c_str()
3227 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3231 static void TestVCardRead()
3233 puts("*** Testing wxVCard reading ***\n");
3235 wxVCard
vcard(_T("vcard.vcf"));
3236 if ( !vcard
.IsOk() )
3238 puts("ERROR: couldn't load vCard.");
3242 // read individual vCard properties
3243 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3247 vcObj
->GetValue(&value
);
3252 value
= _T("<none>");
3255 printf("Full name retrieved directly: %s\n", value
.c_str());
3258 if ( !vcard
.GetFullName(&value
) )
3260 value
= _T("<none>");
3263 printf("Full name from wxVCard API: %s\n", value
.c_str());
3265 // now show how to deal with multiply occuring properties
3266 DumpVCardAddresses(vcard
);
3267 DumpVCardPhoneNumbers(vcard
);
3269 // and finally show all
3270 puts("\nNow dumping the entire vCard:\n"
3271 "-----------------------------\n");
3273 DumpVObject(0, vcard
);
3277 static void TestVCardWrite()
3279 puts("*** Testing wxVCard writing ***\n");
3282 if ( !vcard
.IsOk() )
3284 puts("ERROR: couldn't create vCard.");
3289 vcard
.SetName("Zeitlin", "Vadim");
3290 vcard
.SetFullName("Vadim Zeitlin");
3291 vcard
.SetOrganization("wxWindows", "R&D");
3293 // just dump the vCard back
3294 puts("Entire vCard follows:\n");
3295 puts(vcard
.Write());
3299 #endif // TEST_VCARD
3301 // ----------------------------------------------------------------------------
3302 // wide char (Unicode) support
3303 // ----------------------------------------------------------------------------
3307 #include "wx/strconv.h"
3308 #include "wx/fontenc.h"
3309 #include "wx/encconv.h"
3310 #include "wx/buffer.h"
3312 static void TestUtf8()
3314 puts("*** Testing UTF8 support ***\n");
3316 static const char textInUtf8
[] =
3318 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3319 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3320 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3321 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3322 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3323 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3324 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3329 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
3331 puts("ERROR: UTF-8 decoding failed.");
3335 // using wxEncodingConverter
3337 wxEncodingConverter ec
;
3338 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3339 ec
.Convert(wbuf
, buf
);
3340 #else // using wxCSConv
3341 wxCSConv
conv(_T("koi8-r"));
3342 if ( conv
.WC2MB(buf
, wbuf
, 0 /* not needed wcslen(wbuf) */) <= 0 )
3344 puts("ERROR: conversion to KOI8-R failed.");
3349 printf("The resulting string (in koi8-r): %s\n", buf
);
3353 #endif // TEST_WCHAR
3355 // ----------------------------------------------------------------------------
3357 // ----------------------------------------------------------------------------
3361 #include "wx/filesys.h"
3362 #include "wx/fs_zip.h"
3363 #include "wx/zipstrm.h"
3365 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3367 static void TestZipStreamRead()
3369 puts("*** Testing ZIP reading ***\n");
3371 static const wxChar
*filename
= _T("foo");
3372 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3373 printf("Archive size: %u\n", istr
.GetSize());
3375 printf("Dumping the file '%s':\n", filename
);
3376 while ( !istr
.Eof() )
3378 putchar(istr
.GetC());
3382 puts("\n----- done ------");
3385 static void DumpZipDirectory(wxFileSystem
& fs
,
3386 const wxString
& dir
,
3387 const wxString
& indent
)
3389 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3390 TESTFILE_ZIP
, dir
.c_str());
3391 wxString wildcard
= prefix
+ _T("/*");
3393 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3394 while ( !dirname
.empty() )
3396 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3398 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3403 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3405 DumpZipDirectory(fs
, dirname
,
3406 indent
+ wxString(_T(' '), 4));
3408 dirname
= fs
.FindNext();
3411 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3412 while ( !filename
.empty() )
3414 if ( !filename
.StartsWith(prefix
, &filename
) )
3416 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3421 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3423 filename
= fs
.FindNext();
3427 static void TestZipFileSystem()
3429 puts("*** Testing ZIP file system ***\n");
3431 wxFileSystem::AddHandler(new wxZipFSHandler
);
3433 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3435 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3440 // ----------------------------------------------------------------------------
3442 // ----------------------------------------------------------------------------
3446 #include "wx/zstream.h"
3447 #include "wx/wfstream.h"
3449 static const wxChar
*FILENAME_GZ
= _T("test.gz");
3450 static const char *TEST_DATA
= "hello and hello again";
3452 static void TestZlibStreamWrite()
3454 puts("*** Testing Zlib stream reading ***\n");
3456 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
3457 wxZlibOutputStream
ostr(fileOutStream
, 0);
3458 printf("Compressing the test string... ");
3459 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
3462 puts("(ERROR: failed)");
3469 puts("\n----- done ------");
3472 static void TestZlibStreamRead()
3474 puts("*** Testing Zlib stream reading ***\n");
3476 wxFileInputStream
fileInStream(FILENAME_GZ
);
3477 wxZlibInputStream
istr(fileInStream
);
3478 printf("Archive size: %u\n", istr
.GetSize());
3480 puts("Dumping the file:");
3481 while ( !istr
.Eof() )
3483 putchar(istr
.GetC());
3487 puts("\n----- done ------");
3492 // ----------------------------------------------------------------------------
3494 // ----------------------------------------------------------------------------
3496 #ifdef TEST_DATETIME
3500 #include "wx/date.h"
3501 #include "wx/datetime.h"
3506 wxDateTime::wxDateTime_t day
;
3507 wxDateTime::Month month
;
3509 wxDateTime::wxDateTime_t hour
, min
, sec
;
3511 wxDateTime::WeekDay wday
;
3512 time_t gmticks
, ticks
;
3514 void Init(const wxDateTime::Tm
& tm
)
3523 gmticks
= ticks
= -1;
3526 wxDateTime
DT() const
3527 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
3529 bool SameDay(const wxDateTime::Tm
& tm
) const
3531 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
3534 wxString
Format() const
3537 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
3539 wxDateTime::GetMonthName(month
).c_str(),
3541 abs(wxDateTime::ConvertYearToBC(year
)),
3542 year
> 0 ? "AD" : "BC");
3546 wxString
FormatDate() const
3549 s
.Printf("%02d-%s-%4d%s",
3551 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3552 abs(wxDateTime::ConvertYearToBC(year
)),
3553 year
> 0 ? "AD" : "BC");
3558 static const Date testDates
[] =
3560 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
3561 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
3562 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
3563 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
3564 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
3565 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
3566 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
3567 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
3568 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
3569 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
3570 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
3571 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
3572 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
3573 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
3574 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
3577 // this test miscellaneous static wxDateTime functions
3578 static void TestTimeStatic()
3580 puts("\n*** wxDateTime static methods test ***");
3582 // some info about the current date
3583 int year
= wxDateTime::GetCurrentYear();
3584 printf("Current year %d is %sa leap one and has %d days.\n",
3586 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3587 wxDateTime::GetNumberOfDays(year
));
3589 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3590 printf("Current month is '%s' ('%s') and it has %d days\n",
3591 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3592 wxDateTime::GetMonthName(month
).c_str(),
3593 wxDateTime::GetNumberOfDays(month
));
3596 static const size_t nYears
= 5;
3597 static const size_t years
[2][nYears
] =
3599 // first line: the years to test
3600 { 1990, 1976, 2000, 2030, 1984, },
3602 // second line: TRUE if leap, FALSE otherwise
3603 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
3606 for ( size_t n
= 0; n
< nYears
; n
++ )
3608 int year
= years
[0][n
];
3609 bool should
= years
[1][n
] != 0,
3610 is
= wxDateTime::IsLeapYear(year
);
3612 printf("Year %d is %sa leap year (%s)\n",
3615 should
== is
? "ok" : "ERROR");
3617 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
3621 // test constructing wxDateTime objects
3622 static void TestTimeSet()
3624 puts("\n*** wxDateTime construction test ***");
3626 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3628 const Date
& d1
= testDates
[n
];
3629 wxDateTime dt
= d1
.DT();
3632 d2
.Init(dt
.GetTm());
3634 wxString s1
= d1
.Format(),
3637 printf("Date: %s == %s (%s)\n",
3638 s1
.c_str(), s2
.c_str(),
3639 s1
== s2
? "ok" : "ERROR");
3643 // test time zones stuff
3644 static void TestTimeZones()
3646 puts("\n*** wxDateTime timezone test ***");
3648 wxDateTime now
= wxDateTime::Now();
3650 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
3651 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
3652 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
3653 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
3654 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
3655 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
3657 wxDateTime::Tm tm
= now
.GetTm();
3658 if ( wxDateTime(tm
) != now
)
3660 printf("ERROR: got %s instead of %s\n",
3661 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3665 // test some minimal support for the dates outside the standard range
3666 static void TestTimeRange()
3668 puts("\n*** wxDateTime out-of-standard-range dates test ***");
3670 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
3672 printf("Unix epoch:\t%s\n",
3673 wxDateTime(2440587.5).Format(fmt
).c_str());
3674 printf("Feb 29, 0: \t%s\n",
3675 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3676 printf("JDN 0: \t%s\n",
3677 wxDateTime(0.0).Format(fmt
).c_str());
3678 printf("Jan 1, 1AD:\t%s\n",
3679 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3680 printf("May 29, 2099:\t%s\n",
3681 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3684 static void TestTimeTicks()
3686 puts("\n*** wxDateTime ticks test ***");
3688 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3690 const Date
& d
= testDates
[n
];
3691 if ( d
.ticks
== -1 )
3694 wxDateTime dt
= d
.DT();
3695 long ticks
= (dt
.GetValue() / 1000).ToLong();
3696 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3697 if ( ticks
== d
.ticks
)
3703 printf(" (ERROR: should be %ld, delta = %ld)\n",
3704 d
.ticks
, ticks
- d
.ticks
);
3707 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
3708 ticks
= (dt
.GetValue() / 1000).ToLong();
3709 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3710 if ( ticks
== d
.gmticks
)
3716 printf(" (ERROR: should be %ld, delta = %ld)\n",
3717 d
.gmticks
, ticks
- d
.gmticks
);
3724 // test conversions to JDN &c
3725 static void TestTimeJDN()
3727 puts("\n*** wxDateTime to JDN test ***");
3729 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3731 const Date
& d
= testDates
[n
];
3732 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3733 double jdn
= dt
.GetJulianDayNumber();
3735 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
3742 printf(" (ERROR: should be %f, delta = %f)\n",
3743 d
.jdn
, jdn
- d
.jdn
);
3748 // test week days computation
3749 static void TestTimeWDays()
3751 puts("\n*** wxDateTime weekday test ***");
3753 // test GetWeekDay()
3755 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3757 const Date
& d
= testDates
[n
];
3758 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3760 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
3763 wxDateTime::GetWeekDayName(wday
).c_str());
3764 if ( wday
== d
.wday
)
3770 printf(" (ERROR: should be %s)\n",
3771 wxDateTime::GetWeekDayName(d
.wday
).c_str());
3777 // test SetToWeekDay()
3778 struct WeekDateTestData
3780 Date date
; // the real date (precomputed)
3781 int nWeek
; // its week index in the month
3782 wxDateTime::WeekDay wday
; // the weekday
3783 wxDateTime::Month month
; // the month
3784 int year
; // and the year
3786 wxString
Format() const
3789 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
3791 case 1: which
= "first"; break;
3792 case 2: which
= "second"; break;
3793 case 3: which
= "third"; break;
3794 case 4: which
= "fourth"; break;
3795 case 5: which
= "fifth"; break;
3797 case -1: which
= "last"; break;
3802 which
+= " from end";
3805 s
.Printf("The %s %s of %s in %d",
3807 wxDateTime::GetWeekDayName(wday
).c_str(),
3808 wxDateTime::GetMonthName(month
).c_str(),
3815 // the array data was generated by the following python program
3817 from DateTime import *
3818 from whrandom import *
3819 from string import *
3821 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3822 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3824 week = DateTimeDelta(7)
3827 year = randint(1900, 2100)
3828 month = randint(1, 12)
3829 day = randint(1, 28)
3830 dt = DateTime(year, month, day)
3831 wday = dt.day_of_week
3833 countFromEnd = choice([-1, 1])
3836 while dt.month is month:
3837 dt = dt - countFromEnd * week
3838 weekNum = weekNum + countFromEnd
3840 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
3842 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
3843 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
3846 static const WeekDateTestData weekDatesTestData
[] =
3848 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
3849 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
3850 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
3851 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
3852 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
3853 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
3854 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
3855 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
3856 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
3857 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
3858 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
3859 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
3860 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
3861 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
3862 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
3863 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
3864 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
3865 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
3866 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
3867 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
3870 static const char *fmt
= "%d-%b-%Y";
3873 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
3875 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
3877 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
3879 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
3881 const Date
& d
= wd
.date
;
3882 if ( d
.SameDay(dt
.GetTm()) )
3888 dt
.Set(d
.day
, d
.month
, d
.year
);
3890 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
3895 // test the computation of (ISO) week numbers
3896 static void TestTimeWNumber()
3898 puts("\n*** wxDateTime week number test ***");
3900 struct WeekNumberTestData
3902 Date date
; // the date
3903 wxDateTime::wxDateTime_t week
; // the week number in the year
3904 wxDateTime::wxDateTime_t wmon
; // the week number in the month
3905 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
3906 wxDateTime::wxDateTime_t dnum
; // day number in the year
3909 // data generated with the following python script:
3911 from DateTime import *
3912 from whrandom import *
3913 from string import *
3915 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3916 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3918 def GetMonthWeek(dt):
3919 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
3920 if weekNumMonth < 0:
3921 weekNumMonth = weekNumMonth + 53
3924 def GetLastSundayBefore(dt):
3925 if dt.iso_week[2] == 7:
3928 return dt - DateTimeDelta(dt.iso_week[2])
3931 year = randint(1900, 2100)
3932 month = randint(1, 12)
3933 day = randint(1, 28)
3934 dt = DateTime(year, month, day)
3935 dayNum = dt.day_of_year
3936 weekNum = dt.iso_week[1]
3937 weekNumMonth = GetMonthWeek(dt)
3940 dtSunday = GetLastSundayBefore(dt)
3942 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
3943 weekNumMonth2 = weekNumMonth2 + 1
3944 dtSunday = dtSunday - DateTimeDelta(7)
3946 data = { 'day': rjust(`day`, 2), \
3947 'month': monthNames[month - 1], \
3949 'weekNum': rjust(`weekNum`, 2), \
3950 'weekNumMonth': weekNumMonth, \
3951 'weekNumMonth2': weekNumMonth2, \
3952 'dayNum': rjust(`dayNum`, 3) }
3954 print " { { %(day)s, "\
3955 "wxDateTime::%(month)s, "\
3958 "%(weekNumMonth)s, "\
3959 "%(weekNumMonth2)s, "\
3960 "%(dayNum)s }," % data
3963 static const WeekNumberTestData weekNumberTestDates
[] =
3965 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
3966 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
3967 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
3968 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
3969 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
3970 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
3971 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
3972 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
3973 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
3974 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
3975 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
3976 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
3977 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
3978 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
3979 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
3980 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
3981 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
3982 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
3983 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
3984 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
3987 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
3989 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
3990 const Date
& d
= wn
.date
;
3992 wxDateTime dt
= d
.DT();
3994 wxDateTime::wxDateTime_t
3995 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
3996 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3997 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3998 dnum
= dt
.GetDayOfYear();
4000 printf("%s: the day number is %d",
4001 d
.FormatDate().c_str(), dnum
);
4002 if ( dnum
== wn
.dnum
)
4008 printf(" (ERROR: should be %d)", wn
.dnum
);
4011 printf(", week in month is %d", wmon
);
4012 if ( wmon
== wn
.wmon
)
4018 printf(" (ERROR: should be %d)", wn
.wmon
);
4021 printf(" or %d", wmon2
);
4022 if ( wmon2
== wn
.wmon2
)
4028 printf(" (ERROR: should be %d)", wn
.wmon2
);
4031 printf(", week in year is %d", week
);
4032 if ( week
== wn
.week
)
4038 printf(" (ERROR: should be %d)\n", wn
.week
);
4043 // test DST calculations
4044 static void TestTimeDST()
4046 puts("\n*** wxDateTime DST test ***");
4048 printf("DST is%s in effect now.\n\n",
4049 wxDateTime::Now().IsDST() ? "" : " not");
4051 // taken from http://www.energy.ca.gov/daylightsaving.html
4052 static const Date datesDST
[2][2004 - 1900 + 1] =
4055 { 1, wxDateTime::Apr
, 1990 },
4056 { 7, wxDateTime::Apr
, 1991 },
4057 { 5, wxDateTime::Apr
, 1992 },
4058 { 4, wxDateTime::Apr
, 1993 },
4059 { 3, wxDateTime::Apr
, 1994 },
4060 { 2, wxDateTime::Apr
, 1995 },
4061 { 7, wxDateTime::Apr
, 1996 },
4062 { 6, wxDateTime::Apr
, 1997 },
4063 { 5, wxDateTime::Apr
, 1998 },
4064 { 4, wxDateTime::Apr
, 1999 },
4065 { 2, wxDateTime::Apr
, 2000 },
4066 { 1, wxDateTime::Apr
, 2001 },
4067 { 7, wxDateTime::Apr
, 2002 },
4068 { 6, wxDateTime::Apr
, 2003 },
4069 { 4, wxDateTime::Apr
, 2004 },
4072 { 28, wxDateTime::Oct
, 1990 },
4073 { 27, wxDateTime::Oct
, 1991 },
4074 { 25, wxDateTime::Oct
, 1992 },
4075 { 31, wxDateTime::Oct
, 1993 },
4076 { 30, wxDateTime::Oct
, 1994 },
4077 { 29, wxDateTime::Oct
, 1995 },
4078 { 27, wxDateTime::Oct
, 1996 },
4079 { 26, wxDateTime::Oct
, 1997 },
4080 { 25, wxDateTime::Oct
, 1998 },
4081 { 31, wxDateTime::Oct
, 1999 },
4082 { 29, wxDateTime::Oct
, 2000 },
4083 { 28, wxDateTime::Oct
, 2001 },
4084 { 27, wxDateTime::Oct
, 2002 },
4085 { 26, wxDateTime::Oct
, 2003 },
4086 { 31, wxDateTime::Oct
, 2004 },
4091 for ( year
= 1990; year
< 2005; year
++ )
4093 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
4094 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
4096 printf("DST period in the US for year %d: from %s to %s",
4097 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
4099 size_t n
= year
- 1990;
4100 const Date
& dBegin
= datesDST
[0][n
];
4101 const Date
& dEnd
= datesDST
[1][n
];
4103 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
4109 printf(" (ERROR: should be %s %d to %s %d)\n",
4110 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
4111 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
4117 for ( year
= 1990; year
< 2005; year
++ )
4119 printf("DST period in Europe for year %d: from %s to %s\n",
4121 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
4122 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
4126 // test wxDateTime -> text conversion
4127 static void TestTimeFormat()
4129 puts("\n*** wxDateTime formatting test ***");
4131 // some information may be lost during conversion, so store what kind
4132 // of info should we recover after a round trip
4135 CompareNone
, // don't try comparing
4136 CompareBoth
, // dates and times should be identical
4137 CompareDate
, // dates only
4138 CompareTime
// time only
4143 CompareKind compareKind
;
4145 } formatTestFormats
[] =
4147 { CompareBoth
, "---> %c" },
4148 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
4149 { CompareBoth
, "Date is %x, time is %X" },
4150 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
4151 { CompareNone
, "The day of year: %j, the week of year: %W" },
4152 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
4155 static const Date formatTestDates
[] =
4157 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
4158 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
4160 // this test can't work for other centuries because it uses two digit
4161 // years in formats, so don't even try it
4162 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
4163 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
4164 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
4168 // an extra test (as it doesn't depend on date, don't do it in the loop)
4169 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
4171 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
4175 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
4176 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
4178 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
4179 printf("%s", s
.c_str());
4181 // what can we recover?
4182 int kind
= formatTestFormats
[n
].compareKind
;
4186 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
4189 // converion failed - should it have?
4190 if ( kind
== CompareNone
)
4193 puts(" (ERROR: conversion back failed)");
4197 // should have parsed the entire string
4198 puts(" (ERROR: conversion back stopped too soon)");
4202 bool equal
= FALSE
; // suppress compilaer warning
4210 equal
= dt
.IsSameDate(dt2
);
4214 equal
= dt
.IsSameTime(dt2
);
4220 printf(" (ERROR: got back '%s' instead of '%s')\n",
4221 dt2
.Format().c_str(), dt
.Format().c_str());
4232 // test text -> wxDateTime conversion
4233 static void TestTimeParse()
4235 puts("\n*** wxDateTime parse test ***");
4237 struct ParseTestData
4244 static const ParseTestData parseTestDates
[] =
4246 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
4247 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
4250 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
4252 const char *format
= parseTestDates
[n
].format
;
4254 printf("%s => ", format
);
4257 if ( dt
.ParseRfc822Date(format
) )
4259 printf("%s ", dt
.Format().c_str());
4261 if ( parseTestDates
[n
].good
)
4263 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
4270 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
4275 puts("(ERROR: bad format)");
4280 printf("bad format (%s)\n",
4281 parseTestDates
[n
].good
? "ERROR" : "ok");
4286 static void TestDateTimeInteractive()
4288 puts("\n*** interactive wxDateTime tests ***");
4294 printf("Enter a date: ");
4295 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
4298 // kill the last '\n'
4299 buf
[strlen(buf
) - 1] = 0;
4302 const char *p
= dt
.ParseDate(buf
);
4305 printf("ERROR: failed to parse the date '%s'.\n", buf
);
4311 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
4314 printf("%s: day %u, week of month %u/%u, week of year %u\n",
4315 dt
.Format("%b %d, %Y").c_str(),
4317 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4318 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4319 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
4322 puts("\n*** done ***");
4325 static void TestTimeMS()
4327 puts("*** testing millisecond-resolution support in wxDateTime ***");
4329 wxDateTime dt1
= wxDateTime::Now(),
4330 dt2
= wxDateTime::UNow();
4332 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
4333 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4334 printf("Dummy loop: ");
4335 for ( int i
= 0; i
< 6000; i
++ )
4337 //for ( int j = 0; j < 10; j++ )
4340 s
.Printf("%g", sqrt(i
));
4349 dt2
= wxDateTime::UNow();
4350 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4352 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
4354 puts("\n*** done ***");
4357 static void TestTimeArithmetics()
4359 puts("\n*** testing arithmetic operations on wxDateTime ***");
4361 static const struct ArithmData
4363 ArithmData(const wxDateSpan
& sp
, const char *nam
)
4364 : span(sp
), name(nam
) { }
4368 } testArithmData
[] =
4370 ArithmData(wxDateSpan::Day(), "day"),
4371 ArithmData(wxDateSpan::Week(), "week"),
4372 ArithmData(wxDateSpan::Month(), "month"),
4373 ArithmData(wxDateSpan::Year(), "year"),
4374 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
4377 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
4379 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
4381 wxDateSpan span
= testArithmData
[n
].span
;
4385 const char *name
= testArithmData
[n
].name
;
4386 printf("%s + %s = %s, %s - %s = %s\n",
4387 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
4388 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
4390 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
4391 if ( dt1
- span
== dt
)
4397 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4400 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
4401 if ( dt2
+ span
== dt
)
4407 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4410 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
4411 if ( dt2
+ 2*span
== dt1
)
4417 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
4424 static void TestTimeHolidays()
4426 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
4428 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
4429 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
4430 dtEnd
= dtStart
.GetLastMonthDay();
4432 wxDateTimeArray hol
;
4433 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
4435 const wxChar
*format
= "%d-%b-%Y (%a)";
4437 printf("All holidays between %s and %s:\n",
4438 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
4440 size_t count
= hol
.GetCount();
4441 for ( size_t n
= 0; n
< count
; n
++ )
4443 printf("\t%s\n", hol
[n
].Format(format
).c_str());
4449 static void TestTimeZoneBug()
4451 puts("\n*** testing for DST/timezone bug ***\n");
4453 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
4454 for ( int i
= 0; i
< 31; i
++ )
4456 printf("Date %s: week day %s.\n",
4457 date
.Format(_T("%d-%m-%Y")).c_str(),
4458 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
4460 date
+= wxDateSpan::Day();
4466 static void TestTimeSpanFormat()
4468 puts("\n*** wxTimeSpan tests ***");
4470 static const char *formats
[] =
4472 _T("(default) %H:%M:%S"),
4473 _T("%E weeks and %D days"),
4474 _T("%l milliseconds"),
4475 _T("(with ms) %H:%M:%S:%l"),
4476 _T("100%% of minutes is %M"), // test "%%"
4477 _T("%D days and %H hours"),
4478 _T("or also %S seconds"),
4481 wxTimeSpan
ts1(1, 2, 3, 4),
4483 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
4485 printf("ts1 = %s\tts2 = %s\n",
4486 ts1
.Format(formats
[n
]).c_str(),
4487 ts2
.Format(formats
[n
]).c_str());
4495 // test compatibility with the old wxDate/wxTime classes
4496 static void TestTimeCompatibility()
4498 puts("\n*** wxDateTime compatibility test ***");
4500 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
4501 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
4503 double jdnNow
= wxDateTime::Now().GetJDN();
4504 long jdnMidnight
= (long)(jdnNow
- 0.5);
4505 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
4507 jdnMidnight
= wxDate().Set().GetJulianDate();
4508 printf("wxDateTime for today: %s\n",
4509 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
4511 int flags
= wxEUROPEAN
;//wxFULL;
4514 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
4515 for ( int n
= 0; n
< 7; n
++ )
4517 printf("Previous %s is %s\n",
4518 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
4519 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
4525 #endif // TEST_DATETIME
4527 // ----------------------------------------------------------------------------
4529 // ----------------------------------------------------------------------------
4533 #include "wx/thread.h"
4535 static size_t gs_counter
= (size_t)-1;
4536 static wxCriticalSection gs_critsect
;
4537 static wxCondition gs_cond
;
4539 class MyJoinableThread
: public wxThread
4542 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
4543 { m_n
= n
; Create(); }
4545 // thread execution starts here
4546 virtual ExitCode
Entry();
4552 wxThread::ExitCode
MyJoinableThread::Entry()
4554 unsigned long res
= 1;
4555 for ( size_t n
= 1; n
< m_n
; n
++ )
4559 // it's a loooong calculation :-)
4563 return (ExitCode
)res
;
4566 class MyDetachedThread
: public wxThread
4569 MyDetachedThread(size_t n
, char ch
)
4573 m_cancelled
= FALSE
;
4578 // thread execution starts here
4579 virtual ExitCode
Entry();
4582 virtual void OnExit();
4585 size_t m_n
; // number of characters to write
4586 char m_ch
; // character to write
4588 bool m_cancelled
; // FALSE if we exit normally
4591 wxThread::ExitCode
MyDetachedThread::Entry()
4594 wxCriticalSectionLocker
lock(gs_critsect
);
4595 if ( gs_counter
== (size_t)-1 )
4601 for ( size_t n
= 0; n
< m_n
; n
++ )
4603 if ( TestDestroy() )
4613 wxThread::Sleep(100);
4619 void MyDetachedThread::OnExit()
4621 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
4623 wxCriticalSectionLocker
lock(gs_critsect
);
4624 if ( !--gs_counter
&& !m_cancelled
)
4628 static void TestDetachedThreads()
4630 puts("\n*** Testing detached threads ***");
4632 static const size_t nThreads
= 3;
4633 MyDetachedThread
*threads
[nThreads
];
4635 for ( n
= 0; n
< nThreads
; n
++ )
4637 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
4640 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
4641 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
4643 for ( n
= 0; n
< nThreads
; n
++ )
4648 // wait until all threads terminate
4654 static void TestJoinableThreads()
4656 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
4658 // calc 10! in the background
4659 MyJoinableThread
thread(10);
4662 printf("\nThread terminated with exit code %lu.\n",
4663 (unsigned long)thread
.Wait());
4666 static void TestThreadSuspend()
4668 puts("\n*** Testing thread suspend/resume functions ***");
4670 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4674 // this is for this demo only, in a real life program we'd use another
4675 // condition variable which would be signaled from wxThread::Entry() to
4676 // tell us that the thread really started running - but here just wait a
4677 // bit and hope that it will be enough (the problem is, of course, that
4678 // the thread might still not run when we call Pause() which will result
4680 wxThread::Sleep(300);
4682 for ( size_t n
= 0; n
< 3; n
++ )
4686 puts("\nThread suspended");
4689 // don't sleep but resume immediately the first time
4690 wxThread::Sleep(300);
4692 puts("Going to resume the thread");
4697 puts("Waiting until it terminates now");
4699 // wait until the thread terminates
4705 static void TestThreadDelete()
4707 // As above, using Sleep() is only for testing here - we must use some
4708 // synchronisation object instead to ensure that the thread is still
4709 // running when we delete it - deleting a detached thread which already
4710 // terminated will lead to a crash!
4712 puts("\n*** Testing thread delete function ***");
4714 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4718 puts("\nDeleted a thread which didn't start to run yet.");
4720 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4724 wxThread::Sleep(300);
4728 puts("\nDeleted a running thread.");
4730 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4734 wxThread::Sleep(300);
4740 puts("\nDeleted a sleeping thread.");
4742 MyJoinableThread
thread3(20);
4747 puts("\nDeleted a joinable thread.");
4749 MyJoinableThread
thread4(2);
4752 wxThread::Sleep(300);
4756 puts("\nDeleted a joinable thread which already terminated.");
4761 class MyWaitingThread
: public wxThread
4764 MyWaitingThread(wxCondition
*condition
)
4766 m_condition
= condition
;
4771 virtual ExitCode
Entry()
4773 printf("Thread %lu has started running.\n", GetId());
4778 printf("Thread %lu starts to wait...\n", GetId());
4781 m_condition
->Wait();
4783 printf("Thread %lu finished to wait, exiting.\n", GetId());
4790 wxCondition
*m_condition
;
4793 static void TestThreadConditions()
4795 wxCondition condition
;
4797 // otherwise its difficult to understand which log messages pertain to
4799 wxLogTrace("thread", "Local condition var is %08x, gs_cond = %08x",
4800 condition
.GetId(), gs_cond
.GetId());
4802 // create and launch threads
4803 MyWaitingThread
*threads
[10];
4806 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4808 threads
[n
] = new MyWaitingThread(&condition
);
4811 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4816 // wait until all threads run
4817 puts("Main thread is waiting for the other threads to start");
4820 size_t nRunning
= 0;
4821 while ( nRunning
< WXSIZEOF(threads
) )
4827 printf("Main thread: %u already running\n", nRunning
);
4831 puts("Main thread: all threads started up.");
4834 wxThread::Sleep(500);
4837 // now wake one of them up
4838 printf("Main thread: about to signal the condition.\n");
4843 wxThread::Sleep(200);
4845 // wake all the (remaining) threads up, so that they can exit
4846 printf("Main thread: about to broadcast the condition.\n");
4848 condition
.Broadcast();
4850 // give them time to terminate (dirty!)
4851 wxThread::Sleep(500);
4854 #endif // TEST_THREADS
4856 // ----------------------------------------------------------------------------
4858 // ----------------------------------------------------------------------------
4862 #include "wx/dynarray.h"
4864 #define DefineCompare(name, T) \
4866 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
4868 return first - second; \
4871 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
4873 return *first - *second; \
4876 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
4878 return *second - *first; \
4881 DefineCompare(Short, short);
4882 DefineCompare(Int
, int);
4884 // test compilation of all macros
4885 WX_DEFINE_ARRAY(short, wxArrayShort
);
4886 WX_DEFINE_SORTED_ARRAY(short, wxSortedArrayShortNoCmp
);
4887 WX_DEFINE_SORTED_ARRAY_CMP(short, ShortCompareValues
, wxSortedArrayShort
);
4888 WX_DEFINE_SORTED_ARRAY_CMP(int, IntCompareValues
, wxSortedArrayInt
);
4890 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
4891 #include "wx/arrimpl.cpp"
4892 WX_DEFINE_OBJARRAY(ArrayBars
);
4894 static void PrintArray(const char* name
, const wxArrayString
& array
)
4896 printf("Dump of the array '%s'\n", name
);
4898 size_t nCount
= array
.GetCount();
4899 for ( size_t n
= 0; n
< nCount
; n
++ )
4901 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
4905 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
4906 const wxString
& second
)
4908 return first
.length() - second
.length();
4911 #define TestArrayOf(name) \
4913 static void PrintArray(const char* name, const wxSortedArray##name & array) \
4915 printf("Dump of the array '%s'\n", name); \
4917 size_t nCount = array.GetCount(); \
4918 for ( size_t n = 0; n < nCount; n++ ) \
4920 printf("\t%s[%u] = %d\n", name, n, array[n]); \
4924 static void PrintArray(const char* name, const wxArray##name & array) \
4926 printf("Dump of the array '%s'\n", name); \
4928 size_t nCount = array.GetCount(); \
4929 for ( size_t n = 0; n < nCount; n++ ) \
4931 printf("\t%s[%u] = %d\n", name, n, array[n]); \
4935 static void TestArrayOf ## name ## s() \
4937 printf("*** Testing wxArray%s ***\n", #name); \
4945 puts("Initially:"); \
4946 PrintArray("a", a); \
4948 puts("After sort:"); \
4949 a.Sort(name ## Compare); \
4950 PrintArray("a", a); \
4952 puts("After reverse sort:"); \
4953 a.Sort(name ## RevCompare); \
4954 PrintArray("a", a); \
4956 wxSortedArray##name b; \
4962 puts("Sorted array initially:"); \
4963 PrintArray("b", b); \
4969 static void TestArrayOfObjects()
4971 puts("*** Testing wxObjArray ***\n");
4975 Bar
bar("second bar");
4977 printf("Initially: %u objects in the array, %u objects total.\n",
4978 bars
.GetCount(), Bar::GetNumber());
4980 bars
.Add(new Bar("first bar"));
4983 printf("Now: %u objects in the array, %u objects total.\n",
4984 bars
.GetCount(), Bar::GetNumber());
4988 printf("After Empty(): %u objects in the array, %u objects total.\n",
4989 bars
.GetCount(), Bar::GetNumber());
4992 printf("Finally: no more objects in the array, %u objects total.\n",
4996 #endif // TEST_ARRAYS
4998 // ----------------------------------------------------------------------------
5000 // ----------------------------------------------------------------------------
5004 #include "wx/timer.h"
5005 #include "wx/tokenzr.h"
5007 static void TestStringConstruction()
5009 puts("*** Testing wxString constructores ***");
5011 #define TEST_CTOR(args, res) \
5014 printf("wxString%s = %s ", #args, s.c_str()); \
5021 printf("(ERROR: should be %s)\n", res); \
5025 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
5026 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
5027 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
5028 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
5030 static const wxChar
*s
= _T("?really!");
5031 const wxChar
*start
= wxStrchr(s
, _T('r'));
5032 const wxChar
*end
= wxStrchr(s
, _T('!'));
5033 TEST_CTOR((start
, end
), _T("really"));
5038 static void TestString()
5048 for (int i
= 0; i
< 1000000; ++i
)
5052 c
= "! How'ya doin'?";
5055 c
= "Hello world! What's up?";
5060 printf ("TestString elapsed time: %ld\n", sw
.Time());
5063 static void TestPChar()
5071 for (int i
= 0; i
< 1000000; ++i
)
5073 strcpy (a
, "Hello");
5074 strcpy (b
, " world");
5075 strcpy (c
, "! How'ya doin'?");
5078 strcpy (c
, "Hello world! What's up?");
5079 if (strcmp (c
, a
) == 0)
5083 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
5086 static void TestStringSub()
5088 wxString
s("Hello, world!");
5090 puts("*** Testing wxString substring extraction ***");
5092 printf("String = '%s'\n", s
.c_str());
5093 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
5094 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
5095 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
5096 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
5097 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
5098 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
5100 static const wxChar
*prefixes
[] =
5104 _T("Hello, world!"),
5105 _T("Hello, world!!!"),
5111 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
5113 wxString prefix
= prefixes
[n
], rest
;
5114 bool rc
= s
.StartsWith(prefix
, &rest
);
5115 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
5118 printf(" (the rest is '%s')\n", rest
.c_str());
5129 static void TestStringFormat()
5131 puts("*** Testing wxString formatting ***");
5134 s
.Printf("%03d", 18);
5136 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
5137 printf("Number 18: %s\n", s
.c_str());
5142 // returns "not found" for npos, value for all others
5143 static wxString
PosToString(size_t res
)
5145 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
5146 : wxString::Format(_T("%u"), res
);
5150 static void TestStringFind()
5152 puts("*** Testing wxString find() functions ***");
5154 static const wxChar
*strToFind
= _T("ell");
5155 static const struct StringFindTest
5159 result
; // of searching "ell" in str
5162 { _T("Well, hello world"), 0, 1 },
5163 { _T("Well, hello world"), 6, 7 },
5164 { _T("Well, hello world"), 9, wxString::npos
},
5167 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
5169 const StringFindTest
& ft
= findTestData
[n
];
5170 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
5172 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
5173 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
5175 size_t resTrue
= ft
.result
;
5176 if ( res
== resTrue
)
5182 printf(_T("(ERROR: should be %s)\n"),
5183 PosToString(resTrue
).c_str());
5190 static void TestStringTokenizer()
5192 puts("*** Testing wxStringTokenizer ***");
5194 static const wxChar
*modeNames
[] =
5198 _T("return all empty"),
5203 static const struct StringTokenizerTest
5205 const wxChar
*str
; // string to tokenize
5206 const wxChar
*delims
; // delimiters to use
5207 size_t count
; // count of token
5208 wxStringTokenizerMode mode
; // how should we tokenize it
5209 } tokenizerTestData
[] =
5211 { _T(""), _T(" "), 0 },
5212 { _T("Hello, world"), _T(" "), 2 },
5213 { _T("Hello, world "), _T(" "), 2 },
5214 { _T("Hello, world"), _T(","), 2 },
5215 { _T("Hello, world!"), _T(",!"), 2 },
5216 { _T("Hello,, world!"), _T(",!"), 3 },
5217 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
5218 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
5219 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
5220 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
5221 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
5222 { _T("01/02/99"), _T("/-"), 3 },
5223 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
5226 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
5228 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
5229 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
5231 size_t count
= tkz
.CountTokens();
5232 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
5233 MakePrintable(tt
.str
).c_str(),
5235 MakePrintable(tt
.delims
).c_str(),
5236 modeNames
[tkz
.GetMode()]);
5237 if ( count
== tt
.count
)
5243 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
5248 // if we emulate strtok(), check that we do it correctly
5249 wxChar
*buf
, *s
= NULL
, *last
;
5251 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
5253 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
5254 wxStrcpy(buf
, tt
.str
);
5256 s
= wxStrtok(buf
, tt
.delims
, &last
);
5263 // now show the tokens themselves
5265 while ( tkz
.HasMoreTokens() )
5267 wxString token
= tkz
.GetNextToken();
5269 printf(_T("\ttoken %u: '%s'"),
5271 MakePrintable(token
).c_str());
5281 printf(" (ERROR: should be %s)\n", s
);
5284 s
= wxStrtok(NULL
, tt
.delims
, &last
);
5288 // nothing to compare with
5293 if ( count2
!= count
)
5295 puts(_T("\tERROR: token count mismatch"));
5304 static void TestStringReplace()
5306 puts("*** Testing wxString::replace ***");
5308 static const struct StringReplaceTestData
5310 const wxChar
*original
; // original test string
5311 size_t start
, len
; // the part to replace
5312 const wxChar
*replacement
; // the replacement string
5313 const wxChar
*result
; // and the expected result
5314 } stringReplaceTestData
[] =
5316 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
5317 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
5318 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
5319 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
5320 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
5323 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
5325 const StringReplaceTestData data
= stringReplaceTestData
[n
];
5327 wxString original
= data
.original
;
5328 original
.replace(data
.start
, data
.len
, data
.replacement
);
5330 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
5331 data
.original
, data
.start
, data
.len
, data
.replacement
,
5334 if ( original
== data
.result
)
5340 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
5347 static void TestStringMatch()
5349 wxPuts(_T("*** Testing wxString::Matches() ***"));
5351 static const struct StringMatchTestData
5354 const wxChar
*wildcard
;
5356 } stringMatchTestData
[] =
5358 { _T("foobar"), _T("foo*"), 1 },
5359 { _T("foobar"), _T("*oo*"), 1 },
5360 { _T("foobar"), _T("*bar"), 1 },
5361 { _T("foobar"), _T("??????"), 1 },
5362 { _T("foobar"), _T("f??b*"), 1 },
5363 { _T("foobar"), _T("f?b*"), 0 },
5364 { _T("foobar"), _T("*goo*"), 0 },
5365 { _T("foobar"), _T("*foo"), 0 },
5366 { _T("foobarfoo"), _T("*foo"), 1 },
5367 { _T(""), _T("*"), 1 },
5368 { _T(""), _T("?"), 0 },
5371 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
5373 const StringMatchTestData
& data
= stringMatchTestData
[n
];
5374 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
5375 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
5377 matches
? _T("matches") : _T("doesn't match"),
5379 matches
== data
.matches
? _T("ok") : _T("ERROR"));
5385 #endif // TEST_STRINGS
5387 // ----------------------------------------------------------------------------
5389 // ----------------------------------------------------------------------------
5391 #ifdef TEST_SNGLINST
5392 #include "wx/snglinst.h"
5393 #endif // TEST_SNGLINST
5395 int main(int argc
, char **argv
)
5397 wxInitializer initializer
;
5400 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
5405 #ifdef TEST_SNGLINST
5406 wxSingleInstanceChecker checker
;
5407 if ( checker
.Create(_T(".wxconsole.lock")) )
5409 if ( checker
.IsAnotherRunning() )
5411 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
5416 // wait some time to give time to launch another instance
5417 wxPrintf(_T("Press \"Enter\" to continue..."));
5420 else // failed to create
5422 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
5424 #endif // TEST_SNGLINST
5428 #endif // TEST_CHARSET
5431 TestCmdLineConvert();
5433 #if wxUSE_CMDLINE_PARSER
5434 static const wxCmdLineEntryDesc cmdLineDesc
[] =
5436 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), "show this help message",
5437 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
5438 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
5439 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
5441 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
5442 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
5443 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
5444 wxCMD_LINE_VAL_NUMBER
},
5445 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
5446 wxCMD_LINE_VAL_DATE
},
5448 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
5449 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
5454 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
5456 parser
.AddOption("project_name", "", "full path to project file",
5457 wxCMD_LINE_VAL_STRING
,
5458 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
5460 switch ( parser
.Parse() )
5463 wxLogMessage("Help was given, terminating.");
5467 ShowCmdLine(parser
);
5471 wxLogMessage("Syntax error detected, aborting.");
5474 #endif // wxUSE_CMDLINE_PARSER
5476 #endif // TEST_CMDLINE
5484 TestStringConstruction();
5487 TestStringTokenizer();
5488 TestStringReplace();
5494 #endif // TEST_STRINGS
5507 puts("*** Initially:");
5509 PrintArray("a1", a1
);
5511 wxArrayString
a2(a1
);
5512 PrintArray("a2", a2
);
5514 wxSortedArrayString
a3(a1
);
5515 PrintArray("a3", a3
);
5517 puts("*** After deleting a string from a1");
5520 PrintArray("a1", a1
);
5521 PrintArray("a2", a2
);
5522 PrintArray("a3", a3
);
5524 puts("*** After reassigning a1 to a2 and a3");
5526 PrintArray("a2", a2
);
5527 PrintArray("a3", a3
);
5529 puts("*** After sorting a1");
5531 PrintArray("a1", a1
);
5533 puts("*** After sorting a1 in reverse order");
5535 PrintArray("a1", a1
);
5537 puts("*** After sorting a1 by the string length");
5538 a1
.Sort(StringLenCompare
);
5539 PrintArray("a1", a1
);
5541 TestArrayOfObjects();
5542 TestArrayOfShorts();
5546 #endif // TEST_ARRAYS
5556 #ifdef TEST_DLLLOADER
5558 #endif // TEST_DLLLOADER
5562 #endif // TEST_ENVIRON
5566 #endif // TEST_EXECUTE
5568 #ifdef TEST_FILECONF
5570 #endif // TEST_FILECONF
5578 #endif // TEST_LOCALE
5582 for ( size_t n
= 0; n
< 8000; n
++ )
5584 s
<< (char)('A' + (n
% 26));
5588 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
5590 // this one shouldn't be truncated
5593 // but this one will because log functions use fixed size buffer
5594 // (note that it doesn't need '\n' at the end neither - will be added
5596 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
5608 #ifdef TEST_FILENAME
5612 fn
.Assign("c:\\foo", "bar.baz");
5619 TestFileNameConstruction();
5620 TestFileNameMakeRelative();
5621 TestFileNameSplit();
5624 TestFileNameComparison();
5625 TestFileNameOperations();
5627 #endif // TEST_FILENAME
5629 #ifdef TEST_FILETIME
5632 #endif // TEST_FILETIME
5635 wxLog::AddTraceMask(FTP_TRACE_MASK
);
5636 if ( TestFtpConnect() )
5647 if ( TEST_INTERACTIVE
)
5648 TestFtpInteractive();
5650 //else: connecting to the FTP server failed
5656 #ifdef TEST_LONGLONG
5657 // seed pseudo random generator
5658 srand((unsigned)time(NULL
));
5667 TestMultiplication();
5670 TestLongLongConversion();
5671 TestBitOperations();
5672 TestLongLongComparison();
5673 TestLongLongPrint();
5675 #endif // TEST_LONGLONG
5683 #endif // TEST_HASHMAP
5686 wxLog::AddTraceMask(_T("mime"));
5694 TestMimeAssociate();
5697 #ifdef TEST_INFO_FUNCTIONS
5703 if ( TEST_INTERACTIVE
)
5706 #endif // TEST_INFO_FUNCTIONS
5708 #ifdef TEST_PATHLIST
5710 #endif // TEST_PATHLIST
5718 #endif // TEST_REGCONF
5721 // TODO: write a real test using src/regex/tests file
5726 TestRegExSubmatch();
5727 TestRegExReplacement();
5729 if ( TEST_INTERACTIVE
)
5730 TestRegExInteractive();
5732 #endif // TEST_REGEX
5734 #ifdef TEST_REGISTRY
5736 TestRegistryAssociation();
5737 #endif // TEST_REGISTRY
5742 #endif // TEST_SOCKETS
5747 #endif // TEST_STREAMS
5750 int nCPUs
= wxThread::GetCPUCount();
5751 printf("This system has %d CPUs\n", nCPUs
);
5753 wxThread::SetConcurrency(nCPUs
);
5757 TestDetachedThreads();
5758 TestJoinableThreads();
5759 TestThreadSuspend();
5763 TestThreadConditions();
5764 #endif // TEST_THREADS
5768 #endif // TEST_TIMER
5770 #ifdef TEST_DATETIME
5783 TestTimeArithmetics();
5786 TestTimeSpanFormat();
5792 if ( TEST_INTERACTIVE
)
5793 TestDateTimeInteractive();
5794 #endif // TEST_DATETIME
5797 puts("Sleeping for 3 seconds... z-z-z-z-z...");
5799 #endif // TEST_USLEEP
5804 #endif // TEST_VCARD
5808 #endif // TEST_WCHAR
5811 TestZipStreamRead();
5812 TestZipFileSystem();
5816 TestZlibStreamWrite();
5817 TestZlibStreamRead();