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)
92 static const bool TEST_ALL
= TRUE
;
96 static const bool TEST_ALL
= FALSE
;
99 // some tests are interactive, define this to run them
100 #ifdef TEST_INTERACTIVE
101 #undef TEST_INTERACTIVE
103 static const bool TEST_INTERACTIVE
= TRUE
;
105 static const bool TEST_INTERACTIVE
= FALSE
;
108 // ----------------------------------------------------------------------------
109 // test class for container objects
110 // ----------------------------------------------------------------------------
112 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
114 class Bar
// Foo is already taken in the hash test
117 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
118 ~Bar() { ms_bars
--; }
120 static size_t GetNumber() { return ms_bars
; }
122 const char *GetName() const { return m_name
; }
127 static size_t ms_bars
;
130 size_t Bar::ms_bars
= 0;
132 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
134 // ============================================================================
136 // ============================================================================
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
144 // replace TABs with \t and CRs with \n
145 static wxString
MakePrintable(const wxChar
*s
)
148 (void)str
.Replace(_T("\t"), _T("\\t"));
149 (void)str
.Replace(_T("\n"), _T("\\n"));
150 (void)str
.Replace(_T("\r"), _T("\\r"));
155 #endif // MakePrintable() is used
157 // ----------------------------------------------------------------------------
158 // wxFontMapper::CharsetToEncoding
159 // ----------------------------------------------------------------------------
163 #include "wx/fontmap.h"
165 static void TestCharset()
167 static const wxChar
*charsets
[] =
169 // some vali charsets
178 // and now some bogus ones
185 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
187 wxFontEncoding enc
= wxTheFontMapper
->CharsetToEncoding(charsets
[n
]);
188 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
190 wxTheFontMapper
->GetEncodingName(enc
).c_str(),
191 wxTheFontMapper
->GetEncodingDescription(enc
).c_str());
195 #endif // TEST_CHARSET
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
203 #include "wx/cmdline.h"
204 #include "wx/datetime.h"
206 #if wxUSE_CMDLINE_PARSER
208 static void ShowCmdLine(const wxCmdLineParser
& parser
)
210 wxString s
= "Input files: ";
212 size_t count
= parser
.GetParamCount();
213 for ( size_t param
= 0; param
< count
; param
++ )
215 s
<< parser
.GetParam(param
) << ' ';
219 << "Verbose:\t" << (parser
.Found("v") ? "yes" : "no") << '\n'
220 << "Quiet:\t" << (parser
.Found("q") ? "yes" : "no") << '\n';
225 if ( parser
.Found("o", &strVal
) )
226 s
<< "Output file:\t" << strVal
<< '\n';
227 if ( parser
.Found("i", &strVal
) )
228 s
<< "Input dir:\t" << strVal
<< '\n';
229 if ( parser
.Found("s", &lVal
) )
230 s
<< "Size:\t" << lVal
<< '\n';
231 if ( parser
.Found("d", &dt
) )
232 s
<< "Date:\t" << dt
.FormatISODate() << '\n';
233 if ( parser
.Found("project_name", &strVal
) )
234 s
<< "Project:\t" << strVal
<< '\n';
239 #endif // wxUSE_CMDLINE_PARSER
241 static void TestCmdLineConvert()
243 static const char *cmdlines
[] =
246 "-a \"-bstring 1\" -c\"string 2\" \"string 3\"",
247 "literal \\\" and \"\"",
250 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
252 const char *cmdline
= cmdlines
[n
];
253 printf("Parsing: %s\n", cmdline
);
254 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
256 size_t count
= args
.GetCount();
257 printf("\targc = %u\n", count
);
258 for ( size_t arg
= 0; arg
< count
; arg
++ )
260 printf("\targv[%u] = %s\n", arg
, args
[arg
].c_str());
265 #endif // TEST_CMDLINE
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
276 static const wxChar
*ROOTDIR
= _T("/");
277 static const wxChar
*TESTDIR
= _T("/usr");
278 #elif defined(__WXMSW__)
279 static const wxChar
*ROOTDIR
= _T("c:\\");
280 static const wxChar
*TESTDIR
= _T("d:\\");
282 #error "don't know where the root directory is"
285 static void TestDirEnumHelper(wxDir
& dir
,
286 int flags
= wxDIR_DEFAULT
,
287 const wxString
& filespec
= wxEmptyString
)
291 if ( !dir
.IsOpened() )
294 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
297 printf("\t%s\n", filename
.c_str());
299 cont
= dir
.GetNext(&filename
);
305 static void TestDirEnum()
307 puts("*** Testing wxDir::GetFirst/GetNext ***");
309 wxDir
dir(wxGetCwd());
311 puts("Enumerating everything in current directory:");
312 TestDirEnumHelper(dir
);
314 puts("Enumerating really everything in current directory:");
315 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
317 puts("Enumerating object files in current directory:");
318 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o");
320 puts("Enumerating directories in current directory:");
321 TestDirEnumHelper(dir
, wxDIR_DIRS
);
323 puts("Enumerating files in current directory:");
324 TestDirEnumHelper(dir
, wxDIR_FILES
);
326 puts("Enumerating files including hidden in current directory:");
327 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
331 puts("Enumerating everything in root directory:");
332 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
334 puts("Enumerating directories in root directory:");
335 TestDirEnumHelper(dir
, wxDIR_DIRS
);
337 puts("Enumerating files in root directory:");
338 TestDirEnumHelper(dir
, wxDIR_FILES
);
340 puts("Enumerating files including hidden in root directory:");
341 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
343 puts("Enumerating files in non existing directory:");
344 wxDir
dirNo("nosuchdir");
345 TestDirEnumHelper(dirNo
);
348 class DirPrintTraverser
: public wxDirTraverser
351 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
353 return wxDIR_CONTINUE
;
356 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
358 wxString path
, name
, ext
;
359 wxSplitPath(dirname
, &path
, &name
, &ext
);
362 name
<< _T('.') << ext
;
365 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
367 if ( wxIsPathSeparator(*p
) )
371 printf("%s%s\n", indent
.c_str(), name
.c_str());
373 return wxDIR_CONTINUE
;
377 static void TestDirTraverse()
379 puts("*** Testing wxDir::Traverse() ***");
383 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
384 printf("There are %u files under '%s'\n", n
, TESTDIR
);
387 printf("First one is '%s'\n", files
[0u].c_str());
388 printf(" last one is '%s'\n", files
[n
- 1].c_str());
391 // enum again with custom traverser
393 DirPrintTraverser traverser
;
394 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
399 // ----------------------------------------------------------------------------
401 // ----------------------------------------------------------------------------
403 #ifdef TEST_DLLLOADER
405 #include "wx/dynlib.h"
407 static void TestDllLoad()
409 #if defined(__WXMSW__)
410 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
411 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
412 #elif defined(__UNIX__)
413 // weird: using just libc.so does *not* work!
414 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
415 static const wxChar
*FUNC_NAME
= _T("strlen");
417 #error "don't know how to test wxDllLoader on this platform"
420 puts("*** testing wxDllLoader ***\n");
422 wxDllType dllHandle
= wxDllLoader::LoadLibrary(LIB_NAME
);
425 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
429 typedef int (*strlenType
)(const char *);
430 strlenType pfnStrlen
= (strlenType
)wxDllLoader::GetSymbol(dllHandle
, FUNC_NAME
);
433 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
434 FUNC_NAME
, LIB_NAME
);
438 if ( pfnStrlen("foo") != 3 )
440 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
448 wxDllLoader::UnloadLibrary(dllHandle
);
452 #endif // TEST_DLLLOADER
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
460 #include "wx/utils.h"
462 static wxString
MyGetEnv(const wxString
& var
)
465 if ( !wxGetEnv(var
, &val
) )
468 val
= wxString(_T('\'')) + val
+ _T('\'');
473 static void TestEnvironment()
475 const wxChar
*var
= _T("wxTestVar");
477 puts("*** testing environment access functions ***");
479 printf("Initially getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
480 wxSetEnv(var
, _T("value for wxTestVar"));
481 printf("After wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
482 wxSetEnv(var
, _T("another value"));
483 printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
485 printf("After wxUnsetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
486 printf("PATH = %s\n", MyGetEnv(_T("PATH")).c_str());
489 #endif // TEST_ENVIRON
491 // ----------------------------------------------------------------------------
493 // ----------------------------------------------------------------------------
497 #include "wx/utils.h"
499 static void TestExecute()
501 puts("*** testing wxExecute ***");
504 #define COMMAND "cat -n ../../Makefile" // "echo hi"
505 #define SHELL_COMMAND "echo hi from shell"
506 #define REDIRECT_COMMAND COMMAND // "date"
507 #elif defined(__WXMSW__)
508 #define COMMAND "command.com -c 'echo hi'"
509 #define SHELL_COMMAND "echo hi"
510 #define REDIRECT_COMMAND COMMAND
512 #error "no command to exec"
515 printf("Testing wxShell: ");
517 if ( wxShell(SHELL_COMMAND
) )
522 printf("Testing wxExecute: ");
524 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
529 #if 0 // no, it doesn't work (yet?)
530 printf("Testing async wxExecute: ");
532 if ( wxExecute(COMMAND
) != 0 )
533 puts("Ok (command launched).");
538 printf("Testing wxExecute with redirection:\n");
539 wxArrayString output
;
540 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
546 size_t count
= output
.GetCount();
547 for ( size_t n
= 0; n
< count
; n
++ )
549 printf("\t%s\n", output
[n
].c_str());
556 #endif // TEST_EXECUTE
558 // ----------------------------------------------------------------------------
560 // ----------------------------------------------------------------------------
565 #include "wx/ffile.h"
566 #include "wx/textfile.h"
568 static void TestFileRead()
570 puts("*** wxFile read test ***");
572 wxFile
file(_T("testdata.fc"));
573 if ( file
.IsOpened() )
575 printf("File length: %lu\n", file
.Length());
577 puts("File dump:\n----------");
579 static const off_t len
= 1024;
583 off_t nRead
= file
.Read(buf
, len
);
584 if ( nRead
== wxInvalidOffset
)
586 printf("Failed to read the file.");
590 fwrite(buf
, nRead
, 1, stdout
);
600 printf("ERROR: can't open test file.\n");
606 static void TestTextFileRead()
608 puts("*** wxTextFile read test ***");
610 wxTextFile
file(_T("testdata.fc"));
613 printf("Number of lines: %u\n", file
.GetLineCount());
614 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
618 puts("\nDumping the entire file:");
619 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
621 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
623 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
625 puts("\nAnd now backwards:");
626 for ( s
= file
.GetLastLine();
627 file
.GetCurrentLine() != 0;
628 s
= file
.GetPrevLine() )
630 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
632 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
636 printf("ERROR: can't open '%s'\n", file
.GetName());
642 static void TestFileCopy()
644 puts("*** Testing wxCopyFile ***");
646 static const wxChar
*filename1
= _T("testdata.fc");
647 static const wxChar
*filename2
= _T("test2");
648 if ( !wxCopyFile(filename1
, filename2
) )
650 puts("ERROR: failed to copy file");
654 wxFFile
f1(filename1
, "rb"),
657 if ( !f1
.IsOpened() || !f2
.IsOpened() )
659 puts("ERROR: failed to open file(s)");
664 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
666 puts("ERROR: failed to read file(s)");
670 if ( (s1
.length() != s2
.length()) ||
671 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
673 puts("ERROR: copy error!");
677 puts("File was copied ok.");
683 if ( !wxRemoveFile(filename2
) )
685 puts("ERROR: failed to remove the file");
693 // ----------------------------------------------------------------------------
695 // ----------------------------------------------------------------------------
699 #include "wx/confbase.h"
700 #include "wx/fileconf.h"
702 static const struct FileConfTestData
704 const wxChar
*name
; // value name
705 const wxChar
*value
; // the value from the file
708 { _T("value1"), _T("one") },
709 { _T("value2"), _T("two") },
710 { _T("novalue"), _T("default") },
713 static void TestFileConfRead()
715 puts("*** testing wxFileConfig loading/reading ***");
717 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
718 _T("testdata.fc"), wxEmptyString
,
719 wxCONFIG_USE_RELATIVE_PATH
);
721 // test simple reading
722 puts("\nReading config file:");
723 wxString
defValue(_T("default")), value
;
724 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
726 const FileConfTestData
& data
= fcTestData
[n
];
727 value
= fileconf
.Read(data
.name
, defValue
);
728 printf("\t%s = %s ", data
.name
, value
.c_str());
729 if ( value
== data
.value
)
735 printf("(ERROR: should be %s)\n", data
.value
);
739 // test enumerating the entries
740 puts("\nEnumerating all root entries:");
743 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
746 printf("\t%s = %s\n",
748 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
750 cont
= fileconf
.GetNextEntry(name
, dummy
);
754 #endif // TEST_FILECONF
756 // ----------------------------------------------------------------------------
758 // ----------------------------------------------------------------------------
762 #include "wx/filename.h"
764 static void DumpFileName(const wxFileName
& fn
)
766 wxString full
= fn
.GetFullPath();
768 wxString vol
, path
, name
, ext
;
769 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
771 wxPrintf(_T("Filename '%s' -> vol '%s', path '%s', name '%s', ext '%s'\n"),
772 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
775 static struct FileNameInfo
777 const wxChar
*fullname
;
778 const wxChar
*volume
;
787 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), TRUE
, wxPATH_UNIX
},
788 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), TRUE
, wxPATH_UNIX
},
789 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), TRUE
, wxPATH_UNIX
},
790 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), FALSE
, wxPATH_UNIX
},
791 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_UNIX
},
792 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), TRUE
, wxPATH_UNIX
},
793 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), TRUE
, wxPATH_UNIX
},
794 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), FALSE
, wxPATH_UNIX
},
795 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), TRUE
, wxPATH_UNIX
},
797 // Windows file names
798 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
799 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
800 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), FALSE
, wxPATH_DOS
},
801 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), TRUE
, wxPATH_DOS
},
802 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), TRUE
, wxPATH_DOS
},
803 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), TRUE
, wxPATH_DOS
},
805 // wxFileName support for Mac file names is broken crurently
808 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
809 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
810 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), TRUE
, wxPATH_MAC
},
811 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), FALSE
, wxPATH_MAC
},
812 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
813 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
817 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), TRUE
, wxPATH_VMS
},
818 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), FALSE
, wxPATH_VMS
},
821 static void TestFileNameConstruction()
823 puts("*** testing wxFileName construction ***");
825 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
827 const FileNameInfo
& fni
= filenames
[n
];
829 wxFileName
fn(fni
.fullname
, fni
.format
);
831 wxString fullname
= fn
.GetFullPath(fni
.format
);
832 if ( fullname
!= fni
.fullname
)
834 printf("ERROR: fullname should be '%s'\n", fni
.fullname
);
837 bool isAbsolute
= fn
.IsAbsolute(fni
.format
);
838 printf("'%s' is %s (%s)\n\t",
840 isAbsolute
? "absolute" : "relative",
841 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
843 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
845 puts("ERROR (couldn't be normalized)");
849 printf("normalized: '%s'\n", fn
.GetFullPath(fni
.format
).c_str());
856 static void TestFileNameSplit()
858 puts("*** testing wxFileName splitting ***");
860 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
862 const FileNameInfo
& fni
= filenames
[n
];
863 wxString volume
, path
, name
, ext
;
864 wxFileName::SplitPath(fni
.fullname
,
865 &volume
, &path
, &name
, &ext
, fni
.format
);
867 printf("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'",
869 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
871 if ( volume
!= fni
.volume
)
872 printf(" (ERROR: volume = '%s')", fni
.volume
);
873 if ( path
!= fni
.path
)
874 printf(" (ERROR: path = '%s')", fni
.path
);
875 if ( name
!= fni
.name
)
876 printf(" (ERROR: name = '%s')", fni
.name
);
877 if ( ext
!= fni
.ext
)
878 printf(" (ERROR: ext = '%s')", fni
.ext
);
884 static void TestFileNameTemp()
886 puts("*** testing wxFileName temp file creation ***");
888 static const char *tmpprefixes
[] =
896 "/tmp/foo/bar", // this one must be an error
900 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
902 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
905 printf("Prefix '%s'\t-> temp file '%s'\n",
906 tmpprefixes
[n
], path
.c_str());
908 if ( !wxRemoveFile(path
) )
910 wxLogWarning("Failed to remove temp file '%s'", path
.c_str());
916 static void TestFileNameMakeRelative()
918 puts("*** testing wxFileName::MakeRelativeTo() ***");
920 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
922 const FileNameInfo
& fni
= filenames
[n
];
924 wxFileName
fn(fni
.fullname
, fni
.format
);
926 // choose the base dir of the same format
928 switch ( fni
.format
)
940 // TODO: I don't know how this is supposed to work there
943 case wxPATH_NATIVE
: // make gcc happy
945 wxFAIL_MSG( "unexpected path format" );
948 printf("'%s' relative to '%s': ",
949 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
951 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
957 printf("'%s'\n", fn
.GetFullPath(fni
.format
).c_str());
962 static void TestFileNameComparison()
967 static void TestFileNameOperations()
972 static void TestFileNameCwd()
977 #endif // TEST_FILENAME
979 // ----------------------------------------------------------------------------
980 // wxFileName time functions
981 // ----------------------------------------------------------------------------
985 #include <wx/filename.h>
986 #include <wx/datetime.h>
988 static void TestFileGetTimes()
990 wxFileName
fn(_T("testdata.fc"));
992 wxDateTime dtAccess
, dtMod
, dtCreate
;
993 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
995 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
999 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
1001 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
1002 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
1003 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
1004 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1008 static void TestFileSetTimes()
1010 wxFileName
fn(_T("testdata.fc"));
1014 wxPrintf(_T("ERROR: Touch() failed.\n"));
1018 #endif // TEST_FILETIME
1020 // ----------------------------------------------------------------------------
1022 // ----------------------------------------------------------------------------
1026 #include "wx/hash.h"
1030 Foo(int n_
) { n
= n_
; count
++; }
1035 static size_t count
;
1038 size_t Foo::count
= 0;
1040 WX_DECLARE_LIST(Foo
, wxListFoos
);
1041 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1043 #include "wx/listimpl.cpp"
1045 WX_DEFINE_LIST(wxListFoos
);
1047 static void TestHash()
1049 puts("*** Testing wxHashTable ***\n");
1053 hash
.DeleteContents(TRUE
);
1055 printf("Hash created: %u foos in hash, %u foos totally\n",
1056 hash
.GetCount(), Foo::count
);
1058 static const int hashTestData
[] =
1060 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1064 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1066 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1069 printf("Hash filled: %u foos in hash, %u foos totally\n",
1070 hash
.GetCount(), Foo::count
);
1072 puts("Hash access test:");
1073 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1075 printf("\tGetting element with key %d, value %d: ",
1076 hashTestData
[n
], n
);
1077 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1080 printf("ERROR, not found.\n");
1084 printf("%d (%s)\n", foo
->n
,
1085 (size_t)foo
->n
== n
? "ok" : "ERROR");
1089 printf("\nTrying to get an element not in hash: ");
1091 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1093 puts("ERROR: found!");
1097 puts("ok (not found)");
1101 printf("Hash destroyed: %u foos left\n", Foo::count
);
1106 // ----------------------------------------------------------------------------
1108 // ----------------------------------------------------------------------------
1112 #include "wx/hashmap.h"
1114 // test compilation of basic map types
1115 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1116 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1117 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1118 myUnsignedHashMap
);
1119 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1121 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1123 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1125 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1129 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1130 // myStringHashMap );
1131 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1133 typedef myStringHashMap::iterator Itor
;
1135 static void TestHashMap()
1137 puts("*** Testing wxHashMap ***\n");
1138 myStringHashMap
sh(0); // as small as possible
1141 const size_t count
= 10000;
1143 // init with some data
1144 for( i
= 0; i
< count
; ++i
)
1146 buf
.Printf(wxT("%d"), i
);
1147 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1150 // test that insertion worked
1151 if( sh
.size() != count
)
1153 printf("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n", sh
.size(), count
);
1156 for( i
= 0; i
< count
; ++i
)
1158 buf
.Printf(wxT("%d"), i
);
1159 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1161 printf("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n");
1166 // check that iterators work
1168 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1172 printf("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n");
1176 if( it
->second
!= sh
[it
->first
] )
1178 printf("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n");
1183 if( sh
.size() != i
)
1185 printf("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n", i
, count
);
1188 // test copy ctor, assignment operator
1189 myStringHashMap
h1( sh
), h2( 0 );
1192 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1194 if( h1
[it
->first
] != it
->second
)
1196 printf("*** ERROR: COPY CTOR BROKEN %s ***\n", it
->first
.c_str());
1199 if( h2
[it
->first
] != it
->second
)
1201 printf("*** ERROR: OPERATOR= BROKEN %s ***\n", it
->first
.c_str());
1206 for( i
= 0; i
< count
; ++i
)
1208 buf
.Printf(wxT("%d"), i
);
1209 size_t sz
= sh
.size();
1211 // test find() and erase(it)
1214 it
= sh
.find( buf
);
1215 if( it
!= sh
.end() )
1219 if( sh
.find( buf
) != sh
.end() )
1221 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1225 printf("*** ERROR: CANT FIND ELEMENT %u ***\n", i
);
1230 size_t c
= sh
.erase( buf
);
1232 printf("*** ERROR: SHOULD RETURN 1 ***\n");
1234 if( sh
.find( buf
) != sh
.end() )
1236 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1240 // count should decrease
1241 if( sh
.size() != sz
- 1 )
1243 printf("*** ERROR: COUNT DID NOT DECREASE ***\n");
1247 printf("*** Finished testing wxHashMap ***\n");
1250 #endif // TEST_HASHMAP
1252 // ----------------------------------------------------------------------------
1254 // ----------------------------------------------------------------------------
1258 #include "wx/list.h"
1260 WX_DECLARE_LIST(Bar
, wxListBars
);
1261 #include "wx/listimpl.cpp"
1262 WX_DEFINE_LIST(wxListBars
);
1264 static void TestListCtor()
1266 puts("*** Testing wxList construction ***\n");
1270 list1
.Append(new Bar(_T("first")));
1271 list1
.Append(new Bar(_T("second")));
1273 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
1274 list1
.GetCount(), Bar::GetNumber());
1279 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
1280 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1282 list1
.DeleteContents(TRUE
);
1285 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
1290 // ----------------------------------------------------------------------------
1292 // ----------------------------------------------------------------------------
1296 #include "wx/intl.h"
1297 #include "wx/utils.h" // for wxSetEnv
1299 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1301 // find the name of the language from its value
1302 static const char *GetLangName(int lang
)
1304 static const char *languageNames
[] =
1325 "ARABIC_SAUDI_ARABIA",
1350 "CHINESE_SIMPLIFIED",
1351 "CHINESE_TRADITIONAL",
1354 "CHINESE_SINGAPORE",
1365 "ENGLISH_AUSTRALIA",
1369 "ENGLISH_CARIBBEAN",
1373 "ENGLISH_NEW_ZEALAND",
1374 "ENGLISH_PHILIPPINES",
1375 "ENGLISH_SOUTH_AFRICA",
1387 "FRENCH_LUXEMBOURG",
1396 "GERMAN_LIECHTENSTEIN",
1397 "GERMAN_LUXEMBOURG",
1438 "MALAY_BRUNEI_DARUSSALAM",
1450 "NORWEGIAN_NYNORSK",
1457 "PORTUGUESE_BRAZILIAN",
1482 "SPANISH_ARGENTINA",
1486 "SPANISH_COSTA_RICA",
1487 "SPANISH_DOMINICAN_REPUBLIC",
1489 "SPANISH_EL_SALVADOR",
1490 "SPANISH_GUATEMALA",
1494 "SPANISH_NICARAGUA",
1498 "SPANISH_PUERTO_RICO",
1501 "SPANISH_VENEZUELA",
1538 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1539 return languageNames
[lang
];
1544 static void TestDefaultLang()
1546 puts("*** Testing wxLocale::GetSystemLanguage ***");
1548 static const wxChar
*langStrings
[] =
1550 NULL
, // system default
1557 _T("de_DE.iso88591"),
1559 _T("?"), // invalid lang spec
1560 _T("klingonese"), // I bet on some systems it does exist...
1563 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1564 wxLocale::GetSystemEncodingName().c_str(),
1565 wxLocale::GetSystemEncoding());
1567 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1569 const char *langStr
= langStrings
[n
];
1572 // FIXME: this doesn't do anything at all under Windows, we need
1573 // to create a new wxLocale!
1574 wxSetEnv(_T("LC_ALL"), langStr
);
1577 int lang
= gs_localeDefault
.GetSystemLanguage();
1578 printf("Locale for '%s' is %s.\n",
1579 langStr
? langStr
: "system default", GetLangName(lang
));
1583 #endif // TEST_LOCALE
1585 // ----------------------------------------------------------------------------
1587 // ----------------------------------------------------------------------------
1591 #include "wx/mimetype.h"
1593 static void TestMimeEnum()
1595 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1597 wxArrayString mimetypes
;
1599 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1601 printf("*** All %u known filetypes: ***\n", count
);
1606 for ( size_t n
= 0; n
< count
; n
++ )
1608 wxFileType
*filetype
=
1609 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1612 printf("nothing known about the filetype '%s'!\n",
1613 mimetypes
[n
].c_str());
1617 filetype
->GetDescription(&desc
);
1618 filetype
->GetExtensions(exts
);
1620 filetype
->GetIcon(NULL
);
1623 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1626 extsAll
<< _T(", ");
1630 printf("\t%s: %s (%s)\n",
1631 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1637 static void TestMimeOverride()
1639 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1641 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1642 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1644 if ( wxFile::Exists(mailcap
) )
1645 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1647 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1649 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1652 if ( wxFile::Exists(mimetypes
) )
1653 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1655 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1657 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1663 static void TestMimeFilename()
1665 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1667 static const wxChar
*filenames
[] =
1674 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1676 const wxString fname
= filenames
[n
];
1677 wxString ext
= fname
.AfterLast(_T('.'));
1678 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1681 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1686 if ( !ft
->GetDescription(&desc
) )
1687 desc
= _T("<no description>");
1690 if ( !ft
->GetOpenCommand(&cmd
,
1691 wxFileType::MessageParameters(fname
, _T(""))) )
1692 cmd
= _T("<no command available>");
1694 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
1695 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1704 static void TestMimeAssociate()
1706 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1708 wxFileTypeInfo
ftInfo(
1709 _T("application/x-xyz"),
1710 _T("xyzview '%s'"), // open cmd
1711 _T(""), // print cmd
1712 _T("XYZ File"), // description
1713 _T(".xyz"), // extensions
1714 NULL
// end of extensions
1716 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1718 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1721 wxPuts(_T("ERROR: failed to create association!"));
1725 // TODO: read it back
1734 // ----------------------------------------------------------------------------
1735 // misc information functions
1736 // ----------------------------------------------------------------------------
1738 #ifdef TEST_INFO_FUNCTIONS
1740 #include "wx/utils.h"
1742 static void TestDiskInfo()
1744 puts("*** Testing wxGetDiskSpace() ***");
1749 printf("\nEnter a directory name: ");
1750 if ( !fgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1753 // kill the last '\n'
1754 pathname
[strlen(pathname
) - 1] = 0;
1756 wxLongLong total
, free
;
1757 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1759 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1763 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1764 (total
/ 1024).ToString().c_str(),
1765 (free
/ 1024).ToString().c_str(),
1771 static void TestOsInfo()
1773 puts("*** Testing OS info functions ***\n");
1776 wxGetOsVersion(&major
, &minor
);
1777 printf("Running under: %s, version %d.%d\n",
1778 wxGetOsDescription().c_str(), major
, minor
);
1780 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
1782 printf("Host name is %s (%s).\n",
1783 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1788 static void TestUserInfo()
1790 puts("*** Testing user info functions ***\n");
1792 printf("User id is:\t%s\n", wxGetUserId().c_str());
1793 printf("User name is:\t%s\n", wxGetUserName().c_str());
1794 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
1795 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
1800 #endif // TEST_INFO_FUNCTIONS
1802 // ----------------------------------------------------------------------------
1804 // ----------------------------------------------------------------------------
1806 #ifdef TEST_LONGLONG
1808 #include "wx/longlong.h"
1809 #include "wx/timer.h"
1811 // make a 64 bit number from 4 16 bit ones
1812 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
1814 // get a random 64 bit number
1815 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
1817 static const long testLongs
[] =
1828 #if wxUSE_LONGLONG_WX
1829 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
1830 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1831 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
1832 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1833 #endif // wxUSE_LONGLONG_WX
1835 static void TestSpeed()
1837 static const long max
= 100000000;
1844 for ( n
= 0; n
< max
; n
++ )
1849 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
1852 #if wxUSE_LONGLONG_NATIVE
1857 for ( n
= 0; n
< max
; n
++ )
1862 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
1864 #endif // wxUSE_LONGLONG_NATIVE
1870 for ( n
= 0; n
< max
; n
++ )
1875 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
1879 static void TestLongLongConversion()
1881 puts("*** Testing wxLongLong conversions ***\n");
1885 for ( size_t n
= 0; n
< 100000; n
++ )
1889 #if wxUSE_LONGLONG_NATIVE
1890 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
1892 wxASSERT_MSG( a
== b
, "conversions failure" );
1894 puts("Can't do it without native long long type, test skipped.");
1897 #endif // wxUSE_LONGLONG_NATIVE
1899 if ( !(nTested
% 1000) )
1911 static void TestMultiplication()
1913 puts("*** Testing wxLongLong multiplication ***\n");
1917 for ( size_t n
= 0; n
< 100000; n
++ )
1922 #if wxUSE_LONGLONG_NATIVE
1923 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
1924 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
1926 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
1927 #else // !wxUSE_LONGLONG_NATIVE
1928 puts("Can't do it without native long long type, test skipped.");
1931 #endif // wxUSE_LONGLONG_NATIVE
1933 if ( !(nTested
% 1000) )
1945 static void TestDivision()
1947 puts("*** Testing wxLongLong division ***\n");
1951 for ( size_t n
= 0; n
< 100000; n
++ )
1953 // get a random wxLongLong (shifting by 12 the MSB ensures that the
1954 // multiplication will not overflow)
1955 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
1957 // get a random (but non null) long (not wxLongLong for now) to divide
1969 #if wxUSE_LONGLONG_NATIVE
1970 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
1972 wxLongLongNative p
= m
/ l
, s
= m
% l
;
1973 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
1974 #else // !wxUSE_LONGLONG_NATIVE
1975 // verify the result
1976 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
1977 #endif // wxUSE_LONGLONG_NATIVE
1979 if ( !(nTested
% 1000) )
1991 static void TestAddition()
1993 puts("*** Testing wxLongLong addition ***\n");
1997 for ( size_t n
= 0; n
< 100000; n
++ )
2003 #if wxUSE_LONGLONG_NATIVE
2004 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
2005 wxLongLongNative(b
.GetHi(), b
.GetLo()),
2006 "addition failure" );
2007 #else // !wxUSE_LONGLONG_NATIVE
2008 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2009 #endif // wxUSE_LONGLONG_NATIVE
2011 if ( !(nTested
% 1000) )
2023 static void TestBitOperations()
2025 puts("*** Testing wxLongLong bit operation ***\n");
2029 for ( size_t n
= 0; n
< 100000; n
++ )
2033 #if wxUSE_LONGLONG_NATIVE
2034 for ( size_t n
= 0; n
< 33; n
++ )
2037 #else // !wxUSE_LONGLONG_NATIVE
2038 puts("Can't do it without native long long type, test skipped.");
2041 #endif // wxUSE_LONGLONG_NATIVE
2043 if ( !(nTested
% 1000) )
2055 static void TestLongLongComparison()
2057 #if wxUSE_LONGLONG_WX
2058 puts("*** Testing wxLongLong comparison ***\n");
2060 static const long ls
[2] =
2066 wxLongLongWx lls
[2];
2070 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2074 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2076 res
= lls
[m
] > testLongs
[n
];
2077 printf("0x%lx > 0x%lx is %s (%s)\n",
2078 ls
[m
], testLongs
[n
], res
? "true" : "false",
2079 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2081 res
= lls
[m
] < testLongs
[n
];
2082 printf("0x%lx < 0x%lx is %s (%s)\n",
2083 ls
[m
], testLongs
[n
], res
? "true" : "false",
2084 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2086 res
= lls
[m
] == testLongs
[n
];
2087 printf("0x%lx == 0x%lx is %s (%s)\n",
2088 ls
[m
], testLongs
[n
], res
? "true" : "false",
2089 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2092 #endif // wxUSE_LONGLONG_WX
2095 static void TestLongLongPrint()
2097 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2099 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2101 wxLongLong ll
= testLongs
[n
];
2102 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2105 wxLongLong
ll(0x12345678, 0x87654321);
2106 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2109 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2115 #endif // TEST_LONGLONG
2117 // ----------------------------------------------------------------------------
2119 // ----------------------------------------------------------------------------
2121 #ifdef TEST_PATHLIST
2123 static void TestPathList()
2125 puts("*** Testing wxPathList ***\n");
2127 wxPathList pathlist
;
2128 pathlist
.AddEnvList("PATH");
2129 wxString path
= pathlist
.FindValidPath("ls");
2132 printf("ERROR: command not found in the path.\n");
2136 printf("Command found in the path as '%s'.\n", path
.c_str());
2140 #endif // TEST_PATHLIST
2142 // ----------------------------------------------------------------------------
2143 // regular expressions
2144 // ----------------------------------------------------------------------------
2148 #include "wx/regex.h"
2150 static void TestRegExCompile()
2152 wxPuts(_T("*** Testing RE compilation ***\n"));
2154 static struct RegExCompTestData
2156 const wxChar
*pattern
;
2158 } regExCompTestData
[] =
2160 { _T("foo"), TRUE
},
2161 { _T("foo("), FALSE
},
2162 { _T("foo(bar"), FALSE
},
2163 { _T("foo(bar)"), TRUE
},
2164 { _T("foo["), FALSE
},
2165 { _T("foo[bar"), FALSE
},
2166 { _T("foo[bar]"), TRUE
},
2167 { _T("foo{"), TRUE
},
2168 { _T("foo{1"), FALSE
},
2169 { _T("foo{bar"), TRUE
},
2170 { _T("foo{1}"), TRUE
},
2171 { _T("foo{1,2}"), TRUE
},
2172 { _T("foo{bar}"), TRUE
},
2173 { _T("foo*"), TRUE
},
2174 { _T("foo**"), FALSE
},
2175 { _T("foo+"), TRUE
},
2176 { _T("foo++"), FALSE
},
2177 { _T("foo?"), TRUE
},
2178 { _T("foo??"), FALSE
},
2179 { _T("foo?+"), FALSE
},
2183 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2185 const RegExCompTestData
& data
= regExCompTestData
[n
];
2186 bool ok
= re
.Compile(data
.pattern
);
2188 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2190 ok
? _T("") : _T("not "),
2191 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2195 static void TestRegExMatch()
2197 wxPuts(_T("*** Testing RE matching ***\n"));
2199 static struct RegExMatchTestData
2201 const wxChar
*pattern
;
2204 } regExMatchTestData
[] =
2206 { _T("foo"), _T("bar"), FALSE
},
2207 { _T("foo"), _T("foobar"), TRUE
},
2208 { _T("^foo"), _T("foobar"), TRUE
},
2209 { _T("^foo"), _T("barfoo"), FALSE
},
2210 { _T("bar$"), _T("barbar"), TRUE
},
2211 { _T("bar$"), _T("barbar "), FALSE
},
2214 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2216 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2218 wxRegEx
re(data
.pattern
);
2219 bool ok
= re
.Matches(data
.text
);
2221 wxPrintf(_T("'%s' %s %s (%s)\n"),
2223 ok
? _T("matches") : _T("doesn't match"),
2225 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2229 static void TestRegExSubmatch()
2231 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2233 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2234 if ( !re
.IsValid() )
2236 wxPuts(_T("ERROR: compilation failed."));
2240 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2242 if ( !re
.Matches(text
) )
2244 wxPuts(_T("ERROR: match expected."));
2248 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2250 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2251 re
.GetMatch(text
, 3).c_str(),
2252 re
.GetMatch(text
, 2).c_str(),
2253 re
.GetMatch(text
, 4).c_str(),
2254 re
.GetMatch(text
, 1).c_str());
2258 static void TestRegExReplacement()
2260 wxPuts(_T("*** Testing RE replacement ***"));
2262 static struct RegExReplTestData
2266 const wxChar
*result
;
2268 } regExReplTestData
[] =
2270 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2271 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2272 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2273 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2274 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2275 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2276 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2279 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2280 wxRegEx
re(pattern
);
2282 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2284 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2286 const RegExReplTestData
& data
= regExReplTestData
[n
];
2288 wxString text
= data
.text
;
2289 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2291 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2292 data
.text
, data
.repl
,
2293 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2295 if ( text
== data
.result
&& nRepl
== data
.count
)
2301 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2302 data
.count
, data
.result
);
2307 static void TestRegExInteractive()
2309 wxPuts(_T("*** Testing RE interactively ***"));
2314 printf("\nEnter a pattern: ");
2315 if ( !fgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2318 // kill the last '\n'
2319 pattern
[strlen(pattern
) - 1] = 0;
2322 if ( !re
.Compile(pattern
) )
2330 printf("Enter text to match: ");
2331 if ( !fgets(text
, WXSIZEOF(text
), stdin
) )
2334 // kill the last '\n'
2335 text
[strlen(text
) - 1] = 0;
2337 if ( !re
.Matches(text
) )
2339 printf("No match.\n");
2343 printf("Pattern matches at '%s'\n", re
.GetMatch(text
).c_str());
2346 for ( size_t n
= 1; ; n
++ )
2348 if ( !re
.GetMatch(&start
, &len
, n
) )
2353 printf("Subexpr %u matched '%s'\n",
2354 n
, wxString(text
+ start
, len
).c_str());
2361 #endif // TEST_REGEX
2363 // ----------------------------------------------------------------------------
2365 // ----------------------------------------------------------------------------
2371 static void TestDbOpen()
2379 // ----------------------------------------------------------------------------
2380 // registry and related stuff
2381 // ----------------------------------------------------------------------------
2383 // this is for MSW only
2386 #undef TEST_REGISTRY
2391 #include "wx/confbase.h"
2392 #include "wx/msw/regconf.h"
2394 static void TestRegConfWrite()
2396 wxRegConfig
regconf(_T("console"), _T("wxwindows"));
2397 regconf
.Write(_T("Hello"), wxString(_T("world")));
2400 #endif // TEST_REGCONF
2402 #ifdef TEST_REGISTRY
2404 #include "wx/msw/registry.h"
2406 // I chose this one because I liked its name, but it probably only exists under
2408 static const wxChar
*TESTKEY
=
2409 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2411 static void TestRegistryRead()
2413 puts("*** testing registry reading ***");
2415 wxRegKey
key(TESTKEY
);
2416 printf("The test key name is '%s'.\n", key
.GetName().c_str());
2419 puts("ERROR: test key can't be opened, aborting test.");
2424 size_t nSubKeys
, nValues
;
2425 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2427 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
2430 printf("Enumerating values:\n");
2434 bool cont
= key
.GetFirstValue(value
, dummy
);
2437 printf("Value '%s': type ", value
.c_str());
2438 switch ( key
.GetValueType(value
) )
2440 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
2441 case wxRegKey::Type_String
: printf("SZ"); break;
2442 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
2443 case wxRegKey::Type_Binary
: printf("BINARY"); break;
2444 case wxRegKey::Type_Dword
: printf("DWORD"); break;
2445 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
2446 default: printf("other (unknown)"); break;
2449 printf(", value = ");
2450 if ( key
.IsNumericValue(value
) )
2453 key
.QueryValue(value
, &val
);
2459 key
.QueryValue(value
, val
);
2460 printf("'%s'", val
.c_str());
2462 key
.QueryRawValue(value
, val
);
2463 printf(" (raw value '%s')", val
.c_str());
2468 cont
= key
.GetNextValue(value
, dummy
);
2472 static void TestRegistryAssociation()
2475 The second call to deleteself genertaes an error message, with a
2476 messagebox saying .flo is crucial to system operation, while the .ddf
2477 call also fails, but with no error message
2482 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2484 key
= "ddxf_auto_file" ;
2485 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2487 key
= "ddxf_auto_file" ;
2488 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2491 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2493 key
= "program \"%1\"" ;
2495 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2497 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2499 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2501 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2505 #endif // TEST_REGISTRY
2507 // ----------------------------------------------------------------------------
2509 // ----------------------------------------------------------------------------
2513 #include "wx/socket.h"
2514 #include "wx/protocol/protocol.h"
2515 #include "wx/protocol/http.h"
2517 static void TestSocketServer()
2519 puts("*** Testing wxSocketServer ***\n");
2521 static const int PORT
= 3000;
2526 wxSocketServer
*server
= new wxSocketServer(addr
);
2527 if ( !server
->Ok() )
2529 puts("ERROR: failed to bind");
2536 printf("Server: waiting for connection on port %d...\n", PORT
);
2538 wxSocketBase
*socket
= server
->Accept();
2541 puts("ERROR: wxSocketServer::Accept() failed.");
2545 puts("Server: got a client.");
2547 server
->SetTimeout(60); // 1 min
2549 while ( socket
->IsConnected() )
2555 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2557 // don't log error if the client just close the connection
2558 if ( socket
->IsConnected() )
2560 puts("ERROR: in wxSocket::Read.");
2580 printf("Server: got '%s'.\n", s
.c_str());
2581 if ( s
== _T("bye") )
2588 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2589 socket
->Write("\r\n", 2);
2590 printf("Server: wrote '%s'.\n", s
.c_str());
2593 puts("Server: lost a client.");
2598 // same as "delete server" but is consistent with GUI programs
2602 static void TestSocketClient()
2604 puts("*** Testing wxSocketClient ***\n");
2606 static const char *hostname
= "www.wxwindows.org";
2609 addr
.Hostname(hostname
);
2612 printf("--- Attempting to connect to %s:80...\n", hostname
);
2614 wxSocketClient client
;
2615 if ( !client
.Connect(addr
) )
2617 printf("ERROR: failed to connect to %s\n", hostname
);
2621 printf("--- Connected to %s:%u...\n",
2622 addr
.Hostname().c_str(), addr
.Service());
2626 // could use simply "GET" here I suppose
2628 wxString::Format("GET http://%s/\r\n", hostname
);
2629 client
.Write(cmdGet
, cmdGet
.length());
2630 printf("--- Sent command '%s' to the server\n",
2631 MakePrintable(cmdGet
).c_str());
2632 client
.Read(buf
, WXSIZEOF(buf
));
2633 printf("--- Server replied:\n%s", buf
);
2637 #endif // TEST_SOCKETS
2639 // ----------------------------------------------------------------------------
2641 // ----------------------------------------------------------------------------
2645 #include "wx/protocol/ftp.h"
2649 #define FTP_ANONYMOUS
2651 #ifdef FTP_ANONYMOUS
2652 static const char *directory
= "/pub";
2653 static const char *filename
= "welcome.msg";
2655 static const char *directory
= "/etc";
2656 static const char *filename
= "issue";
2659 static bool TestFtpConnect()
2661 puts("*** Testing FTP connect ***");
2663 #ifdef FTP_ANONYMOUS
2664 static const char *hostname
= "ftp.wxwindows.org";
2666 printf("--- Attempting to connect to %s:21 anonymously...\n", hostname
);
2667 #else // !FTP_ANONYMOUS
2668 static const char *hostname
= "localhost";
2671 fgets(user
, WXSIZEOF(user
), stdin
);
2672 user
[strlen(user
) - 1] = '\0'; // chop off '\n'
2676 printf("Password for %s: ", password
);
2677 fgets(password
, WXSIZEOF(password
), stdin
);
2678 password
[strlen(password
) - 1] = '\0'; // chop off '\n'
2679 ftp
.SetPassword(password
);
2681 printf("--- Attempting to connect to %s:21 as %s...\n", hostname
, user
);
2682 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2684 if ( !ftp
.Connect(hostname
) )
2686 printf("ERROR: failed to connect to %s\n", hostname
);
2692 printf("--- Connected to %s, current directory is '%s'\n",
2693 hostname
, ftp
.Pwd().c_str());
2699 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2700 static void TestFtpWuFtpd()
2703 static const char *hostname
= "ftp.eudora.com";
2704 if ( !ftp
.Connect(hostname
) )
2706 printf("ERROR: failed to connect to %s\n", hostname
);
2710 static const char *filename
= "eudora/pubs/draft-gellens-submit-09.txt";
2711 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2714 printf("ERROR: couldn't get input stream for %s\n", filename
);
2718 size_t size
= in
->StreamSize();
2719 printf("Reading file %s (%u bytes)...", filename
, size
);
2721 char *data
= new char[size
];
2722 if ( !in
->Read(data
, size
) )
2724 puts("ERROR: read error");
2728 printf("Successfully retrieved the file.\n");
2737 static void TestFtpList()
2739 puts("*** Testing wxFTP file listing ***\n");
2742 if ( !ftp
.ChDir(directory
) )
2744 printf("ERROR: failed to cd to %s\n", directory
);
2747 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2749 // test NLIST and LIST
2750 wxArrayString files
;
2751 if ( !ftp
.GetFilesList(files
) )
2753 puts("ERROR: failed to get NLIST of files");
2757 printf("Brief list of files under '%s':\n", ftp
.Pwd().c_str());
2758 size_t count
= files
.GetCount();
2759 for ( size_t n
= 0; n
< count
; n
++ )
2761 printf("\t%s\n", files
[n
].c_str());
2763 puts("End of the file list");
2766 if ( !ftp
.GetDirList(files
) )
2768 puts("ERROR: failed to get LIST of files");
2772 printf("Detailed list of files under '%s':\n", ftp
.Pwd().c_str());
2773 size_t count
= files
.GetCount();
2774 for ( size_t n
= 0; n
< count
; n
++ )
2776 printf("\t%s\n", files
[n
].c_str());
2778 puts("End of the file list");
2781 if ( !ftp
.ChDir(_T("..")) )
2783 puts("ERROR: failed to cd to ..");
2786 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2789 static void TestFtpDownload()
2791 puts("*** Testing wxFTP download ***\n");
2794 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2797 printf("ERROR: couldn't get input stream for %s\n", filename
);
2801 size_t size
= in
->StreamSize();
2802 printf("Reading file %s (%u bytes)...", filename
, size
);
2805 char *data
= new char[size
];
2806 if ( !in
->Read(data
, size
) )
2808 puts("ERROR: read error");
2812 printf("\nContents of %s:\n%s\n", filename
, data
);
2820 static void TestFtpFileSize()
2822 puts("*** Testing FTP SIZE command ***");
2824 if ( !ftp
.ChDir(directory
) )
2826 printf("ERROR: failed to cd to %s\n", directory
);
2829 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2831 if ( ftp
.FileExists(filename
) )
2833 int size
= ftp
.GetFileSize(filename
);
2835 printf("ERROR: couldn't get size of '%s'\n", filename
);
2837 printf("Size of '%s' is %d bytes.\n", filename
, size
);
2841 printf("ERROR: '%s' doesn't exist\n", filename
);
2845 static void TestFtpMisc()
2847 puts("*** Testing miscellaneous wxFTP functions ***");
2849 if ( ftp
.SendCommand("STAT") != '2' )
2851 puts("ERROR: STAT failed");
2855 printf("STAT returned:\n\n%s\n", ftp
.GetLastResult().c_str());
2858 if ( ftp
.SendCommand("HELP SITE") != '2' )
2860 puts("ERROR: HELP SITE failed");
2864 printf("The list of site-specific commands:\n\n%s\n",
2865 ftp
.GetLastResult().c_str());
2869 static void TestFtpInteractive()
2871 puts("\n*** Interactive wxFTP test ***");
2877 printf("Enter FTP command: ");
2878 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2881 // kill the last '\n'
2882 buf
[strlen(buf
) - 1] = 0;
2884 // special handling of LIST and NLST as they require data connection
2885 wxString
start(buf
, 4);
2887 if ( start
== "LIST" || start
== "NLST" )
2890 if ( strlen(buf
) > 4 )
2893 wxArrayString files
;
2894 if ( !ftp
.GetList(files
, wildcard
, start
== "LIST") )
2896 printf("ERROR: failed to get %s of files\n", start
.c_str());
2900 printf("--- %s of '%s' under '%s':\n",
2901 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2902 size_t count
= files
.GetCount();
2903 for ( size_t n
= 0; n
< count
; n
++ )
2905 printf("\t%s\n", files
[n
].c_str());
2907 puts("--- End of the file list");
2912 char ch
= ftp
.SendCommand(buf
);
2913 printf("Command %s", ch
? "succeeded" : "failed");
2916 printf(" (return code %c)", ch
);
2919 printf(", server reply:\n%s\n\n", ftp
.GetLastResult().c_str());
2923 puts("\n*** done ***");
2926 static void TestFtpUpload()
2928 puts("*** Testing wxFTP uploading ***\n");
2931 static const char *file1
= "test1";
2932 static const char *file2
= "test2";
2933 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2936 printf("--- Uploading to %s ---\n", file1
);
2937 out
->Write("First hello", 11);
2941 // send a command to check the remote file
2942 if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' )
2944 printf("ERROR: STAT %s failed\n", file1
);
2948 printf("STAT %s returned:\n\n%s\n",
2949 file1
, ftp
.GetLastResult().c_str());
2952 out
= ftp
.GetOutputStream(file2
);
2955 printf("--- Uploading to %s ---\n", file1
);
2956 out
->Write("Second hello", 12);
2963 // ----------------------------------------------------------------------------
2965 // ----------------------------------------------------------------------------
2969 #include "wx/wfstream.h"
2970 #include "wx/mstream.h"
2972 static void TestFileStream()
2974 puts("*** Testing wxFileInputStream ***");
2976 static const wxChar
*filename
= _T("testdata.fs");
2978 wxFileOutputStream
fsOut(filename
);
2979 fsOut
.Write("foo", 3);
2982 wxFileInputStream
fsIn(filename
);
2983 printf("File stream size: %u\n", fsIn
.GetSize());
2984 while ( !fsIn
.Eof() )
2986 putchar(fsIn
.GetC());
2989 if ( !wxRemoveFile(filename
) )
2991 printf("ERROR: failed to remove the file '%s'.\n", filename
);
2994 puts("\n*** wxFileInputStream test done ***");
2997 static void TestMemoryStream()
2999 puts("*** Testing wxMemoryInputStream ***");
3002 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
3004 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
3005 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3006 while ( !memInpStream
.Eof() )
3008 putchar(memInpStream
.GetC());
3011 puts("\n*** wxMemoryInputStream test done ***");
3014 #endif // TEST_STREAMS
3016 // ----------------------------------------------------------------------------
3018 // ----------------------------------------------------------------------------
3022 #include "wx/timer.h"
3023 #include "wx/utils.h"
3025 static void TestStopWatch()
3027 puts("*** Testing wxStopWatch ***\n");
3030 printf("Sleeping 3 seconds...");
3032 printf("\telapsed time: %ldms\n", sw
.Time());
3035 printf("Sleeping 2 more seconds...");
3037 printf("\telapsed time: %ldms\n", sw
.Time());
3040 printf("And 3 more seconds...");
3042 printf("\telapsed time: %ldms\n", sw
.Time());
3045 puts("\nChecking for 'backwards clock' bug...");
3046 for ( size_t n
= 0; n
< 70; n
++ )
3050 for ( size_t m
= 0; m
< 100000; m
++ )
3052 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3054 puts("\ntime is negative - ERROR!");
3064 #endif // TEST_TIMER
3066 // ----------------------------------------------------------------------------
3068 // ----------------------------------------------------------------------------
3072 #include "wx/vcard.h"
3074 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3077 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3081 wxString(_T('\t'), level
).c_str(),
3082 vcObj
->GetName().c_str());
3085 switch ( vcObj
->GetType() )
3087 case wxVCardObject::String
:
3088 case wxVCardObject::UString
:
3091 vcObj
->GetValue(&val
);
3092 value
<< _T('"') << val
<< _T('"');
3096 case wxVCardObject::Int
:
3099 vcObj
->GetValue(&i
);
3100 value
.Printf(_T("%u"), i
);
3104 case wxVCardObject::Long
:
3107 vcObj
->GetValue(&l
);
3108 value
.Printf(_T("%lu"), l
);
3112 case wxVCardObject::None
:
3115 case wxVCardObject::Object
:
3116 value
= _T("<node>");
3120 value
= _T("<unknown value type>");
3124 printf(" = %s", value
.c_str());
3127 DumpVObject(level
+ 1, *vcObj
);
3130 vcObj
= vcard
.GetNextProp(&cookie
);
3134 static void DumpVCardAddresses(const wxVCard
& vcard
)
3136 puts("\nShowing all addresses from vCard:\n");
3140 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3144 int flags
= addr
->GetFlags();
3145 if ( flags
& wxVCardAddress::Domestic
)
3147 flagsStr
<< _T("domestic ");
3149 if ( flags
& wxVCardAddress::Intl
)
3151 flagsStr
<< _T("international ");
3153 if ( flags
& wxVCardAddress::Postal
)
3155 flagsStr
<< _T("postal ");
3157 if ( flags
& wxVCardAddress::Parcel
)
3159 flagsStr
<< _T("parcel ");
3161 if ( flags
& wxVCardAddress::Home
)
3163 flagsStr
<< _T("home ");
3165 if ( flags
& wxVCardAddress::Work
)
3167 flagsStr
<< _T("work ");
3170 printf("Address %u:\n"
3172 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3175 addr
->GetPostOffice().c_str(),
3176 addr
->GetExtAddress().c_str(),
3177 addr
->GetStreet().c_str(),
3178 addr
->GetLocality().c_str(),
3179 addr
->GetRegion().c_str(),
3180 addr
->GetPostalCode().c_str(),
3181 addr
->GetCountry().c_str()
3185 addr
= vcard
.GetNextAddress(&cookie
);
3189 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3191 puts("\nShowing all phone numbers from vCard:\n");
3195 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3199 int flags
= phone
->GetFlags();
3200 if ( flags
& wxVCardPhoneNumber::Voice
)
3202 flagsStr
<< _T("voice ");
3204 if ( flags
& wxVCardPhoneNumber::Fax
)
3206 flagsStr
<< _T("fax ");
3208 if ( flags
& wxVCardPhoneNumber::Cellular
)
3210 flagsStr
<< _T("cellular ");
3212 if ( flags
& wxVCardPhoneNumber::Modem
)
3214 flagsStr
<< _T("modem ");
3216 if ( flags
& wxVCardPhoneNumber::Home
)
3218 flagsStr
<< _T("home ");
3220 if ( flags
& wxVCardPhoneNumber::Work
)
3222 flagsStr
<< _T("work ");
3225 printf("Phone number %u:\n"
3230 phone
->GetNumber().c_str()
3234 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3238 static void TestVCardRead()
3240 puts("*** Testing wxVCard reading ***\n");
3242 wxVCard
vcard(_T("vcard.vcf"));
3243 if ( !vcard
.IsOk() )
3245 puts("ERROR: couldn't load vCard.");
3249 // read individual vCard properties
3250 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3254 vcObj
->GetValue(&value
);
3259 value
= _T("<none>");
3262 printf("Full name retrieved directly: %s\n", value
.c_str());
3265 if ( !vcard
.GetFullName(&value
) )
3267 value
= _T("<none>");
3270 printf("Full name from wxVCard API: %s\n", value
.c_str());
3272 // now show how to deal with multiply occuring properties
3273 DumpVCardAddresses(vcard
);
3274 DumpVCardPhoneNumbers(vcard
);
3276 // and finally show all
3277 puts("\nNow dumping the entire vCard:\n"
3278 "-----------------------------\n");
3280 DumpVObject(0, vcard
);
3284 static void TestVCardWrite()
3286 puts("*** Testing wxVCard writing ***\n");
3289 if ( !vcard
.IsOk() )
3291 puts("ERROR: couldn't create vCard.");
3296 vcard
.SetName("Zeitlin", "Vadim");
3297 vcard
.SetFullName("Vadim Zeitlin");
3298 vcard
.SetOrganization("wxWindows", "R&D");
3300 // just dump the vCard back
3301 puts("Entire vCard follows:\n");
3302 puts(vcard
.Write());
3306 #endif // TEST_VCARD
3308 // ----------------------------------------------------------------------------
3310 // ----------------------------------------------------------------------------
3318 #include "wx/volume.h"
3320 static const wxChar
*volumeKinds
[] =
3326 _T("network volume"),
3330 static void TestFSVolume()
3332 wxPuts(_T("*** Testing wxFSVolume class ***"));
3334 wxArrayString volumes
= wxFSVolume::GetVolumes();
3335 size_t count
= volumes
.GetCount();
3339 wxPuts(_T("ERROR: no mounted volumes?"));
3343 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3345 for ( size_t n
= 0; n
< count
; n
++ )
3347 wxFSVolume
vol(volumes
[n
]);
3350 wxPuts(_T("ERROR: couldn't create volume"));
3354 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3356 vol
.GetDisplayName().c_str(),
3357 vol
.GetName().c_str(),
3358 volumeKinds
[vol
.GetKind()],
3359 vol
.IsWritable() ? _T("rw") : _T("ro"),
3360 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3365 #endif // TEST_VOLUME
3367 // ----------------------------------------------------------------------------
3368 // wide char (Unicode) support
3369 // ----------------------------------------------------------------------------
3373 #include "wx/strconv.h"
3374 #include "wx/fontenc.h"
3375 #include "wx/encconv.h"
3376 #include "wx/buffer.h"
3378 static const char textInUtf8
[] =
3380 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3381 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3382 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3383 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3384 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3385 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3386 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3389 static void TestUtf8()
3391 puts("*** Testing UTF8 support ***\n");
3395 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
3397 puts("ERROR: UTF-8 decoding failed.");
3401 wxCSConv
conv(_T("koi8-r"));
3402 if ( conv
.WC2MB(buf
, wbuf
, 0 /* not needed wcslen(wbuf) */) <= 0 )
3404 puts("ERROR: conversion to KOI8-R failed.");
3408 printf("The resulting string (in KOI8-R): %s\n", buf
);
3412 if ( wxConvUTF8
.WC2MB(buf
, L
"Ã la", WXSIZEOF(buf
)) <= 0 )
3414 puts("ERROR: conversion to UTF-8 failed.");
3418 printf("The string in UTF-8: %s\n", buf
);
3424 static void TestEncodingConverter()
3426 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3428 // using wxEncodingConverter should give the same result as above
3431 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
3433 puts("ERROR: UTF-8 decoding failed.");
3437 wxEncodingConverter ec
;
3438 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3439 ec
.Convert(wbuf
, buf
);
3440 printf("The same string obtained using wxEC: %s\n", buf
);
3446 #endif // TEST_WCHAR
3448 // ----------------------------------------------------------------------------
3450 // ----------------------------------------------------------------------------
3454 #include "wx/filesys.h"
3455 #include "wx/fs_zip.h"
3456 #include "wx/zipstrm.h"
3458 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3460 static void TestZipStreamRead()
3462 puts("*** Testing ZIP reading ***\n");
3464 static const wxChar
*filename
= _T("foo");
3465 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3466 printf("Archive size: %u\n", istr
.GetSize());
3468 printf("Dumping the file '%s':\n", filename
);
3469 while ( !istr
.Eof() )
3471 putchar(istr
.GetC());
3475 puts("\n----- done ------");
3478 static void DumpZipDirectory(wxFileSystem
& fs
,
3479 const wxString
& dir
,
3480 const wxString
& indent
)
3482 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3483 TESTFILE_ZIP
, dir
.c_str());
3484 wxString wildcard
= prefix
+ _T("/*");
3486 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3487 while ( !dirname
.empty() )
3489 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3491 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3496 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3498 DumpZipDirectory(fs
, dirname
,
3499 indent
+ wxString(_T(' '), 4));
3501 dirname
= fs
.FindNext();
3504 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3505 while ( !filename
.empty() )
3507 if ( !filename
.StartsWith(prefix
, &filename
) )
3509 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3514 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3516 filename
= fs
.FindNext();
3520 static void TestZipFileSystem()
3522 puts("*** Testing ZIP file system ***\n");
3524 wxFileSystem::AddHandler(new wxZipFSHandler
);
3526 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3528 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3533 // ----------------------------------------------------------------------------
3535 // ----------------------------------------------------------------------------
3539 #include "wx/zstream.h"
3540 #include "wx/wfstream.h"
3542 static const wxChar
*FILENAME_GZ
= _T("test.gz");
3543 static const char *TEST_DATA
= "hello and hello again";
3545 static void TestZlibStreamWrite()
3547 puts("*** Testing Zlib stream reading ***\n");
3549 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
3550 wxZlibOutputStream
ostr(fileOutStream
, 0);
3551 printf("Compressing the test string... ");
3552 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
3555 puts("(ERROR: failed)");
3562 puts("\n----- done ------");
3565 static void TestZlibStreamRead()
3567 puts("*** Testing Zlib stream reading ***\n");
3569 wxFileInputStream
fileInStream(FILENAME_GZ
);
3570 wxZlibInputStream
istr(fileInStream
);
3571 printf("Archive size: %u\n", istr
.GetSize());
3573 puts("Dumping the file:");
3574 while ( !istr
.Eof() )
3576 putchar(istr
.GetC());
3580 puts("\n----- done ------");
3585 // ----------------------------------------------------------------------------
3587 // ----------------------------------------------------------------------------
3589 #ifdef TEST_DATETIME
3593 #include "wx/date.h"
3594 #include "wx/datetime.h"
3599 wxDateTime::wxDateTime_t day
;
3600 wxDateTime::Month month
;
3602 wxDateTime::wxDateTime_t hour
, min
, sec
;
3604 wxDateTime::WeekDay wday
;
3605 time_t gmticks
, ticks
;
3607 void Init(const wxDateTime::Tm
& tm
)
3616 gmticks
= ticks
= -1;
3619 wxDateTime
DT() const
3620 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
3622 bool SameDay(const wxDateTime::Tm
& tm
) const
3624 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
3627 wxString
Format() const
3630 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
3632 wxDateTime::GetMonthName(month
).c_str(),
3634 abs(wxDateTime::ConvertYearToBC(year
)),
3635 year
> 0 ? "AD" : "BC");
3639 wxString
FormatDate() const
3642 s
.Printf("%02d-%s-%4d%s",
3644 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3645 abs(wxDateTime::ConvertYearToBC(year
)),
3646 year
> 0 ? "AD" : "BC");
3651 static const Date testDates
[] =
3653 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
3654 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
3655 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
3656 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
3657 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
3658 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
3659 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
3660 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
3661 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
3662 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
3663 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
3664 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
3665 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
3666 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
3667 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
3670 // this test miscellaneous static wxDateTime functions
3671 static void TestTimeStatic()
3673 puts("\n*** wxDateTime static methods test ***");
3675 // some info about the current date
3676 int year
= wxDateTime::GetCurrentYear();
3677 printf("Current year %d is %sa leap one and has %d days.\n",
3679 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3680 wxDateTime::GetNumberOfDays(year
));
3682 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3683 printf("Current month is '%s' ('%s') and it has %d days\n",
3684 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3685 wxDateTime::GetMonthName(month
).c_str(),
3686 wxDateTime::GetNumberOfDays(month
));
3689 static const size_t nYears
= 5;
3690 static const size_t years
[2][nYears
] =
3692 // first line: the years to test
3693 { 1990, 1976, 2000, 2030, 1984, },
3695 // second line: TRUE if leap, FALSE otherwise
3696 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
3699 for ( size_t n
= 0; n
< nYears
; n
++ )
3701 int year
= years
[0][n
];
3702 bool should
= years
[1][n
] != 0,
3703 is
= wxDateTime::IsLeapYear(year
);
3705 printf("Year %d is %sa leap year (%s)\n",
3708 should
== is
? "ok" : "ERROR");
3710 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
3714 // test constructing wxDateTime objects
3715 static void TestTimeSet()
3717 puts("\n*** wxDateTime construction test ***");
3719 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3721 const Date
& d1
= testDates
[n
];
3722 wxDateTime dt
= d1
.DT();
3725 d2
.Init(dt
.GetTm());
3727 wxString s1
= d1
.Format(),
3730 printf("Date: %s == %s (%s)\n",
3731 s1
.c_str(), s2
.c_str(),
3732 s1
== s2
? "ok" : "ERROR");
3736 // test time zones stuff
3737 static void TestTimeZones()
3739 puts("\n*** wxDateTime timezone test ***");
3741 wxDateTime now
= wxDateTime::Now();
3743 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
3744 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
3745 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
3746 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
3747 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
3748 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
3750 wxDateTime::Tm tm
= now
.GetTm();
3751 if ( wxDateTime(tm
) != now
)
3753 printf("ERROR: got %s instead of %s\n",
3754 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3758 // test some minimal support for the dates outside the standard range
3759 static void TestTimeRange()
3761 puts("\n*** wxDateTime out-of-standard-range dates test ***");
3763 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
3765 printf("Unix epoch:\t%s\n",
3766 wxDateTime(2440587.5).Format(fmt
).c_str());
3767 printf("Feb 29, 0: \t%s\n",
3768 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3769 printf("JDN 0: \t%s\n",
3770 wxDateTime(0.0).Format(fmt
).c_str());
3771 printf("Jan 1, 1AD:\t%s\n",
3772 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3773 printf("May 29, 2099:\t%s\n",
3774 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3777 static void TestTimeTicks()
3779 puts("\n*** wxDateTime ticks test ***");
3781 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3783 const Date
& d
= testDates
[n
];
3784 if ( d
.ticks
== -1 )
3787 wxDateTime dt
= d
.DT();
3788 long ticks
= (dt
.GetValue() / 1000).ToLong();
3789 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3790 if ( ticks
== d
.ticks
)
3796 printf(" (ERROR: should be %ld, delta = %ld)\n",
3797 d
.ticks
, ticks
- d
.ticks
);
3800 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
3801 ticks
= (dt
.GetValue() / 1000).ToLong();
3802 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3803 if ( ticks
== d
.gmticks
)
3809 printf(" (ERROR: should be %ld, delta = %ld)\n",
3810 d
.gmticks
, ticks
- d
.gmticks
);
3817 // test conversions to JDN &c
3818 static void TestTimeJDN()
3820 puts("\n*** wxDateTime to JDN test ***");
3822 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3824 const Date
& d
= testDates
[n
];
3825 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3826 double jdn
= dt
.GetJulianDayNumber();
3828 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
3835 printf(" (ERROR: should be %f, delta = %f)\n",
3836 d
.jdn
, jdn
- d
.jdn
);
3841 // test week days computation
3842 static void TestTimeWDays()
3844 puts("\n*** wxDateTime weekday test ***");
3846 // test GetWeekDay()
3848 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3850 const Date
& d
= testDates
[n
];
3851 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3853 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
3856 wxDateTime::GetWeekDayName(wday
).c_str());
3857 if ( wday
== d
.wday
)
3863 printf(" (ERROR: should be %s)\n",
3864 wxDateTime::GetWeekDayName(d
.wday
).c_str());
3870 // test SetToWeekDay()
3871 struct WeekDateTestData
3873 Date date
; // the real date (precomputed)
3874 int nWeek
; // its week index in the month
3875 wxDateTime::WeekDay wday
; // the weekday
3876 wxDateTime::Month month
; // the month
3877 int year
; // and the year
3879 wxString
Format() const
3882 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
3884 case 1: which
= "first"; break;
3885 case 2: which
= "second"; break;
3886 case 3: which
= "third"; break;
3887 case 4: which
= "fourth"; break;
3888 case 5: which
= "fifth"; break;
3890 case -1: which
= "last"; break;
3895 which
+= " from end";
3898 s
.Printf("The %s %s of %s in %d",
3900 wxDateTime::GetWeekDayName(wday
).c_str(),
3901 wxDateTime::GetMonthName(month
).c_str(),
3908 // the array data was generated by the following python program
3910 from DateTime import *
3911 from whrandom import *
3912 from string import *
3914 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3915 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3917 week = DateTimeDelta(7)
3920 year = randint(1900, 2100)
3921 month = randint(1, 12)
3922 day = randint(1, 28)
3923 dt = DateTime(year, month, day)
3924 wday = dt.day_of_week
3926 countFromEnd = choice([-1, 1])
3929 while dt.month is month:
3930 dt = dt - countFromEnd * week
3931 weekNum = weekNum + countFromEnd
3933 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
3935 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
3936 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
3939 static const WeekDateTestData weekDatesTestData
[] =
3941 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
3942 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
3943 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
3944 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
3945 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
3946 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
3947 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
3948 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
3949 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
3950 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
3951 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
3952 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
3953 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
3954 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
3955 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
3956 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
3957 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
3958 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
3959 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
3960 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
3963 static const char *fmt
= "%d-%b-%Y";
3966 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
3968 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
3970 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
3972 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
3974 const Date
& d
= wd
.date
;
3975 if ( d
.SameDay(dt
.GetTm()) )
3981 dt
.Set(d
.day
, d
.month
, d
.year
);
3983 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
3988 // test the computation of (ISO) week numbers
3989 static void TestTimeWNumber()
3991 puts("\n*** wxDateTime week number test ***");
3993 struct WeekNumberTestData
3995 Date date
; // the date
3996 wxDateTime::wxDateTime_t week
; // the week number in the year
3997 wxDateTime::wxDateTime_t wmon
; // the week number in the month
3998 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
3999 wxDateTime::wxDateTime_t dnum
; // day number in the year
4002 // data generated with the following python script:
4004 from DateTime import *
4005 from whrandom import *
4006 from string import *
4008 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4009 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4011 def GetMonthWeek(dt):
4012 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
4013 if weekNumMonth < 0:
4014 weekNumMonth = weekNumMonth + 53
4017 def GetLastSundayBefore(dt):
4018 if dt.iso_week[2] == 7:
4021 return dt - DateTimeDelta(dt.iso_week[2])
4024 year = randint(1900, 2100)
4025 month = randint(1, 12)
4026 day = randint(1, 28)
4027 dt = DateTime(year, month, day)
4028 dayNum = dt.day_of_year
4029 weekNum = dt.iso_week[1]
4030 weekNumMonth = GetMonthWeek(dt)
4033 dtSunday = GetLastSundayBefore(dt)
4035 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
4036 weekNumMonth2 = weekNumMonth2 + 1
4037 dtSunday = dtSunday - DateTimeDelta(7)
4039 data = { 'day': rjust(`day`, 2), \
4040 'month': monthNames[month - 1], \
4042 'weekNum': rjust(`weekNum`, 2), \
4043 'weekNumMonth': weekNumMonth, \
4044 'weekNumMonth2': weekNumMonth2, \
4045 'dayNum': rjust(`dayNum`, 3) }
4047 print " { { %(day)s, "\
4048 "wxDateTime::%(month)s, "\
4051 "%(weekNumMonth)s, "\
4052 "%(weekNumMonth2)s, "\
4053 "%(dayNum)s }," % data
4056 static const WeekNumberTestData weekNumberTestDates
[] =
4058 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
4059 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
4060 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
4061 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
4062 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
4063 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
4064 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
4065 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
4066 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
4067 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
4068 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
4069 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
4070 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
4071 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
4072 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
4073 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
4074 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
4075 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
4076 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
4077 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
4080 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
4082 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
4083 const Date
& d
= wn
.date
;
4085 wxDateTime dt
= d
.DT();
4087 wxDateTime::wxDateTime_t
4088 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
4089 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4090 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4091 dnum
= dt
.GetDayOfYear();
4093 printf("%s: the day number is %d",
4094 d
.FormatDate().c_str(), dnum
);
4095 if ( dnum
== wn
.dnum
)
4101 printf(" (ERROR: should be %d)", wn
.dnum
);
4104 printf(", week in month is %d", wmon
);
4105 if ( wmon
== wn
.wmon
)
4111 printf(" (ERROR: should be %d)", wn
.wmon
);
4114 printf(" or %d", wmon2
);
4115 if ( wmon2
== wn
.wmon2
)
4121 printf(" (ERROR: should be %d)", wn
.wmon2
);
4124 printf(", week in year is %d", week
);
4125 if ( week
== wn
.week
)
4131 printf(" (ERROR: should be %d)\n", wn
.week
);
4136 // test DST calculations
4137 static void TestTimeDST()
4139 puts("\n*** wxDateTime DST test ***");
4141 printf("DST is%s in effect now.\n\n",
4142 wxDateTime::Now().IsDST() ? "" : " not");
4144 // taken from http://www.energy.ca.gov/daylightsaving.html
4145 static const Date datesDST
[2][2004 - 1900 + 1] =
4148 { 1, wxDateTime::Apr
, 1990 },
4149 { 7, wxDateTime::Apr
, 1991 },
4150 { 5, wxDateTime::Apr
, 1992 },
4151 { 4, wxDateTime::Apr
, 1993 },
4152 { 3, wxDateTime::Apr
, 1994 },
4153 { 2, wxDateTime::Apr
, 1995 },
4154 { 7, wxDateTime::Apr
, 1996 },
4155 { 6, wxDateTime::Apr
, 1997 },
4156 { 5, wxDateTime::Apr
, 1998 },
4157 { 4, wxDateTime::Apr
, 1999 },
4158 { 2, wxDateTime::Apr
, 2000 },
4159 { 1, wxDateTime::Apr
, 2001 },
4160 { 7, wxDateTime::Apr
, 2002 },
4161 { 6, wxDateTime::Apr
, 2003 },
4162 { 4, wxDateTime::Apr
, 2004 },
4165 { 28, wxDateTime::Oct
, 1990 },
4166 { 27, wxDateTime::Oct
, 1991 },
4167 { 25, wxDateTime::Oct
, 1992 },
4168 { 31, wxDateTime::Oct
, 1993 },
4169 { 30, wxDateTime::Oct
, 1994 },
4170 { 29, wxDateTime::Oct
, 1995 },
4171 { 27, wxDateTime::Oct
, 1996 },
4172 { 26, wxDateTime::Oct
, 1997 },
4173 { 25, wxDateTime::Oct
, 1998 },
4174 { 31, wxDateTime::Oct
, 1999 },
4175 { 29, wxDateTime::Oct
, 2000 },
4176 { 28, wxDateTime::Oct
, 2001 },
4177 { 27, wxDateTime::Oct
, 2002 },
4178 { 26, wxDateTime::Oct
, 2003 },
4179 { 31, wxDateTime::Oct
, 2004 },
4184 for ( year
= 1990; year
< 2005; year
++ )
4186 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
4187 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
4189 printf("DST period in the US for year %d: from %s to %s",
4190 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
4192 size_t n
= year
- 1990;
4193 const Date
& dBegin
= datesDST
[0][n
];
4194 const Date
& dEnd
= datesDST
[1][n
];
4196 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
4202 printf(" (ERROR: should be %s %d to %s %d)\n",
4203 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
4204 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
4210 for ( year
= 1990; year
< 2005; year
++ )
4212 printf("DST period in Europe for year %d: from %s to %s\n",
4214 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
4215 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
4219 // test wxDateTime -> text conversion
4220 static void TestTimeFormat()
4222 puts("\n*** wxDateTime formatting test ***");
4224 // some information may be lost during conversion, so store what kind
4225 // of info should we recover after a round trip
4228 CompareNone
, // don't try comparing
4229 CompareBoth
, // dates and times should be identical
4230 CompareDate
, // dates only
4231 CompareTime
// time only
4236 CompareKind compareKind
;
4238 } formatTestFormats
[] =
4240 { CompareBoth
, "---> %c" },
4241 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
4242 { CompareBoth
, "Date is %x, time is %X" },
4243 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
4244 { CompareNone
, "The day of year: %j, the week of year: %W" },
4245 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
4248 static const Date formatTestDates
[] =
4250 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
4251 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
4253 // this test can't work for other centuries because it uses two digit
4254 // years in formats, so don't even try it
4255 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
4256 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
4257 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
4261 // an extra test (as it doesn't depend on date, don't do it in the loop)
4262 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
4264 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
4268 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
4269 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
4271 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
4272 printf("%s", s
.c_str());
4274 // what can we recover?
4275 int kind
= formatTestFormats
[n
].compareKind
;
4279 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
4282 // converion failed - should it have?
4283 if ( kind
== CompareNone
)
4286 puts(" (ERROR: conversion back failed)");
4290 // should have parsed the entire string
4291 puts(" (ERROR: conversion back stopped too soon)");
4295 bool equal
= FALSE
; // suppress compilaer warning
4303 equal
= dt
.IsSameDate(dt2
);
4307 equal
= dt
.IsSameTime(dt2
);
4313 printf(" (ERROR: got back '%s' instead of '%s')\n",
4314 dt2
.Format().c_str(), dt
.Format().c_str());
4325 // test text -> wxDateTime conversion
4326 static void TestTimeParse()
4328 puts("\n*** wxDateTime parse test ***");
4330 struct ParseTestData
4337 static const ParseTestData parseTestDates
[] =
4339 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
4340 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
4343 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
4345 const char *format
= parseTestDates
[n
].format
;
4347 printf("%s => ", format
);
4350 if ( dt
.ParseRfc822Date(format
) )
4352 printf("%s ", dt
.Format().c_str());
4354 if ( parseTestDates
[n
].good
)
4356 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
4363 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
4368 puts("(ERROR: bad format)");
4373 printf("bad format (%s)\n",
4374 parseTestDates
[n
].good
? "ERROR" : "ok");
4379 static void TestDateTimeInteractive()
4381 puts("\n*** interactive wxDateTime tests ***");
4387 printf("Enter a date: ");
4388 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
4391 // kill the last '\n'
4392 buf
[strlen(buf
) - 1] = 0;
4395 const char *p
= dt
.ParseDate(buf
);
4398 printf("ERROR: failed to parse the date '%s'.\n", buf
);
4404 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
4407 printf("%s: day %u, week of month %u/%u, week of year %u\n",
4408 dt
.Format("%b %d, %Y").c_str(),
4410 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4411 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4412 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
4415 puts("\n*** done ***");
4418 static void TestTimeMS()
4420 puts("*** testing millisecond-resolution support in wxDateTime ***");
4422 wxDateTime dt1
= wxDateTime::Now(),
4423 dt2
= wxDateTime::UNow();
4425 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
4426 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4427 printf("Dummy loop: ");
4428 for ( int i
= 0; i
< 6000; i
++ )
4430 //for ( int j = 0; j < 10; j++ )
4433 s
.Printf("%g", sqrt(i
));
4442 dt2
= wxDateTime::UNow();
4443 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4445 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
4447 puts("\n*** done ***");
4450 static void TestTimeArithmetics()
4452 puts("\n*** testing arithmetic operations on wxDateTime ***");
4454 static const struct ArithmData
4456 ArithmData(const wxDateSpan
& sp
, const char *nam
)
4457 : span(sp
), name(nam
) { }
4461 } testArithmData
[] =
4463 ArithmData(wxDateSpan::Day(), "day"),
4464 ArithmData(wxDateSpan::Week(), "week"),
4465 ArithmData(wxDateSpan::Month(), "month"),
4466 ArithmData(wxDateSpan::Year(), "year"),
4467 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
4470 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
4472 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
4474 wxDateSpan span
= testArithmData
[n
].span
;
4478 const char *name
= testArithmData
[n
].name
;
4479 printf("%s + %s = %s, %s - %s = %s\n",
4480 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
4481 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
4483 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
4484 if ( dt1
- span
== dt
)
4490 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4493 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
4494 if ( dt2
+ span
== dt
)
4500 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4503 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
4504 if ( dt2
+ 2*span
== dt1
)
4510 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
4517 static void TestTimeHolidays()
4519 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
4521 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
4522 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
4523 dtEnd
= dtStart
.GetLastMonthDay();
4525 wxDateTimeArray hol
;
4526 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
4528 const wxChar
*format
= "%d-%b-%Y (%a)";
4530 printf("All holidays between %s and %s:\n",
4531 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
4533 size_t count
= hol
.GetCount();
4534 for ( size_t n
= 0; n
< count
; n
++ )
4536 printf("\t%s\n", hol
[n
].Format(format
).c_str());
4542 static void TestTimeZoneBug()
4544 puts("\n*** testing for DST/timezone bug ***\n");
4546 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
4547 for ( int i
= 0; i
< 31; i
++ )
4549 printf("Date %s: week day %s.\n",
4550 date
.Format(_T("%d-%m-%Y")).c_str(),
4551 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
4553 date
+= wxDateSpan::Day();
4559 static void TestTimeSpanFormat()
4561 puts("\n*** wxTimeSpan tests ***");
4563 static const char *formats
[] =
4565 _T("(default) %H:%M:%S"),
4566 _T("%E weeks and %D days"),
4567 _T("%l milliseconds"),
4568 _T("(with ms) %H:%M:%S:%l"),
4569 _T("100%% of minutes is %M"), // test "%%"
4570 _T("%D days and %H hours"),
4571 _T("or also %S seconds"),
4574 wxTimeSpan
ts1(1, 2, 3, 4),
4576 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
4578 printf("ts1 = %s\tts2 = %s\n",
4579 ts1
.Format(formats
[n
]).c_str(),
4580 ts2
.Format(formats
[n
]).c_str());
4588 // test compatibility with the old wxDate/wxTime classes
4589 static void TestTimeCompatibility()
4591 puts("\n*** wxDateTime compatibility test ***");
4593 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
4594 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
4596 double jdnNow
= wxDateTime::Now().GetJDN();
4597 long jdnMidnight
= (long)(jdnNow
- 0.5);
4598 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
4600 jdnMidnight
= wxDate().Set().GetJulianDate();
4601 printf("wxDateTime for today: %s\n",
4602 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
4604 int flags
= wxEUROPEAN
;//wxFULL;
4607 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
4608 for ( int n
= 0; n
< 7; n
++ )
4610 printf("Previous %s is %s\n",
4611 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
4612 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
4618 #endif // TEST_DATETIME
4620 // ----------------------------------------------------------------------------
4622 // ----------------------------------------------------------------------------
4626 #include "wx/thread.h"
4628 static size_t gs_counter
= (size_t)-1;
4629 static wxCriticalSection gs_critsect
;
4630 static wxCondition gs_cond
;
4632 class MyJoinableThread
: public wxThread
4635 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
4636 { m_n
= n
; Create(); }
4638 // thread execution starts here
4639 virtual ExitCode
Entry();
4645 wxThread::ExitCode
MyJoinableThread::Entry()
4647 unsigned long res
= 1;
4648 for ( size_t n
= 1; n
< m_n
; n
++ )
4652 // it's a loooong calculation :-)
4656 return (ExitCode
)res
;
4659 class MyDetachedThread
: public wxThread
4662 MyDetachedThread(size_t n
, char ch
)
4666 m_cancelled
= FALSE
;
4671 // thread execution starts here
4672 virtual ExitCode
Entry();
4675 virtual void OnExit();
4678 size_t m_n
; // number of characters to write
4679 char m_ch
; // character to write
4681 bool m_cancelled
; // FALSE if we exit normally
4684 wxThread::ExitCode
MyDetachedThread::Entry()
4687 wxCriticalSectionLocker
lock(gs_critsect
);
4688 if ( gs_counter
== (size_t)-1 )
4694 for ( size_t n
= 0; n
< m_n
; n
++ )
4696 if ( TestDestroy() )
4706 wxThread::Sleep(100);
4712 void MyDetachedThread::OnExit()
4714 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
4716 wxCriticalSectionLocker
lock(gs_critsect
);
4717 if ( !--gs_counter
&& !m_cancelled
)
4721 static void TestDetachedThreads()
4723 puts("\n*** Testing detached threads ***");
4725 static const size_t nThreads
= 3;
4726 MyDetachedThread
*threads
[nThreads
];
4728 for ( n
= 0; n
< nThreads
; n
++ )
4730 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
4733 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
4734 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
4736 for ( n
= 0; n
< nThreads
; n
++ )
4741 // wait until all threads terminate
4747 static void TestJoinableThreads()
4749 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
4751 // calc 10! in the background
4752 MyJoinableThread
thread(10);
4755 printf("\nThread terminated with exit code %lu.\n",
4756 (unsigned long)thread
.Wait());
4759 static void TestThreadSuspend()
4761 puts("\n*** Testing thread suspend/resume functions ***");
4763 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4767 // this is for this demo only, in a real life program we'd use another
4768 // condition variable which would be signaled from wxThread::Entry() to
4769 // tell us that the thread really started running - but here just wait a
4770 // bit and hope that it will be enough (the problem is, of course, that
4771 // the thread might still not run when we call Pause() which will result
4773 wxThread::Sleep(300);
4775 for ( size_t n
= 0; n
< 3; n
++ )
4779 puts("\nThread suspended");
4782 // don't sleep but resume immediately the first time
4783 wxThread::Sleep(300);
4785 puts("Going to resume the thread");
4790 puts("Waiting until it terminates now");
4792 // wait until the thread terminates
4798 static void TestThreadDelete()
4800 // As above, using Sleep() is only for testing here - we must use some
4801 // synchronisation object instead to ensure that the thread is still
4802 // running when we delete it - deleting a detached thread which already
4803 // terminated will lead to a crash!
4805 puts("\n*** Testing thread delete function ***");
4807 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4811 puts("\nDeleted a thread which didn't start to run yet.");
4813 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4817 wxThread::Sleep(300);
4821 puts("\nDeleted a running thread.");
4823 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4827 wxThread::Sleep(300);
4833 puts("\nDeleted a sleeping thread.");
4835 MyJoinableThread
thread3(20);
4840 puts("\nDeleted a joinable thread.");
4842 MyJoinableThread
thread4(2);
4845 wxThread::Sleep(300);
4849 puts("\nDeleted a joinable thread which already terminated.");
4854 class MyWaitingThread
: public wxThread
4857 MyWaitingThread(wxCondition
*condition
)
4859 m_condition
= condition
;
4864 virtual ExitCode
Entry()
4866 printf("Thread %lu has started running.\n", GetId());
4871 printf("Thread %lu starts to wait...\n", GetId());
4874 m_condition
->Wait();
4876 printf("Thread %lu finished to wait, exiting.\n", GetId());
4883 wxCondition
*m_condition
;
4886 static void TestThreadConditions()
4888 wxCondition condition
;
4890 // otherwise its difficult to understand which log messages pertain to
4892 wxLogTrace("thread", "Local condition var is %08x, gs_cond = %08x",
4893 condition
.GetId(), gs_cond
.GetId());
4895 // create and launch threads
4896 MyWaitingThread
*threads
[10];
4899 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4901 threads
[n
] = new MyWaitingThread(&condition
);
4904 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4909 // wait until all threads run
4910 puts("Main thread is waiting for the other threads to start");
4913 size_t nRunning
= 0;
4914 while ( nRunning
< WXSIZEOF(threads
) )
4920 printf("Main thread: %u already running\n", nRunning
);
4924 puts("Main thread: all threads started up.");
4927 wxThread::Sleep(500);
4930 // now wake one of them up
4931 printf("Main thread: about to signal the condition.\n");
4936 wxThread::Sleep(200);
4938 // wake all the (remaining) threads up, so that they can exit
4939 printf("Main thread: about to broadcast the condition.\n");
4941 condition
.Broadcast();
4943 // give them time to terminate (dirty!)
4944 wxThread::Sleep(500);
4947 #endif // TEST_THREADS
4949 // ----------------------------------------------------------------------------
4951 // ----------------------------------------------------------------------------
4955 #include "wx/dynarray.h"
4957 #define DefineCompare(name, T) \
4959 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
4961 return first - second; \
4964 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
4966 return *first - *second; \
4969 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
4971 return *second - *first; \
4974 DefineCompare(Short, short);
4975 DefineCompare(Int
, int);
4977 // test compilation of all macros
4978 WX_DEFINE_ARRAY(short, wxArrayShort
);
4979 WX_DEFINE_SORTED_ARRAY(short, wxSortedArrayShortNoCmp
);
4980 WX_DEFINE_SORTED_ARRAY_CMP(short, ShortCompareValues
, wxSortedArrayShort
);
4981 WX_DEFINE_SORTED_ARRAY_CMP(int, IntCompareValues
, wxSortedArrayInt
);
4983 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
4984 #include "wx/arrimpl.cpp"
4985 WX_DEFINE_OBJARRAY(ArrayBars
);
4987 static void PrintArray(const char* name
, const wxArrayString
& array
)
4989 printf("Dump of the array '%s'\n", name
);
4991 size_t nCount
= array
.GetCount();
4992 for ( size_t n
= 0; n
< nCount
; n
++ )
4994 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
4998 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
4999 const wxString
& second
)
5001 return first
.length() - second
.length();
5004 #define TestArrayOf(name) \
5006 static void PrintArray(const char* name, const wxSortedArray##name & array) \
5008 printf("Dump of the array '%s'\n", name); \
5010 size_t nCount = array.GetCount(); \
5011 for ( size_t n = 0; n < nCount; n++ ) \
5013 printf("\t%s[%u] = %d\n", name, n, array[n]); \
5017 static void PrintArray(const char* name, const wxArray##name & array) \
5019 printf("Dump of the array '%s'\n", name); \
5021 size_t nCount = array.GetCount(); \
5022 for ( size_t n = 0; n < nCount; n++ ) \
5024 printf("\t%s[%u] = %d\n", name, n, array[n]); \
5028 static void TestArrayOf ## name ## s() \
5030 printf("*** Testing wxArray%s ***\n", #name); \
5038 puts("Initially:"); \
5039 PrintArray("a", a); \
5041 puts("After sort:"); \
5042 a.Sort(name ## Compare); \
5043 PrintArray("a", a); \
5045 puts("After reverse sort:"); \
5046 a.Sort(name ## RevCompare); \
5047 PrintArray("a", a); \
5049 wxSortedArray##name b; \
5055 puts("Sorted array initially:"); \
5056 PrintArray("b", b); \
5062 static void TestArrayOfObjects()
5064 puts("*** Testing wxObjArray ***\n");
5068 Bar
bar("second bar");
5070 printf("Initially: %u objects in the array, %u objects total.\n",
5071 bars
.GetCount(), Bar::GetNumber());
5073 bars
.Add(new Bar("first bar"));
5076 printf("Now: %u objects in the array, %u objects total.\n",
5077 bars
.GetCount(), Bar::GetNumber());
5081 printf("After Empty(): %u objects in the array, %u objects total.\n",
5082 bars
.GetCount(), Bar::GetNumber());
5085 printf("Finally: no more objects in the array, %u objects total.\n",
5089 #endif // TEST_ARRAYS
5091 // ----------------------------------------------------------------------------
5093 // ----------------------------------------------------------------------------
5097 #include "wx/timer.h"
5098 #include "wx/tokenzr.h"
5100 static void TestStringConstruction()
5102 puts("*** Testing wxString constructores ***");
5104 #define TEST_CTOR(args, res) \
5107 printf("wxString%s = %s ", #args, s.c_str()); \
5114 printf("(ERROR: should be %s)\n", res); \
5118 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
5119 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
5120 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
5121 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
5123 static const wxChar
*s
= _T("?really!");
5124 const wxChar
*start
= wxStrchr(s
, _T('r'));
5125 const wxChar
*end
= wxStrchr(s
, _T('!'));
5126 TEST_CTOR((start
, end
), _T("really"));
5131 static void TestString()
5141 for (int i
= 0; i
< 1000000; ++i
)
5145 c
= "! How'ya doin'?";
5148 c
= "Hello world! What's up?";
5153 printf ("TestString elapsed time: %ld\n", sw
.Time());
5156 static void TestPChar()
5164 for (int i
= 0; i
< 1000000; ++i
)
5166 strcpy (a
, "Hello");
5167 strcpy (b
, " world");
5168 strcpy (c
, "! How'ya doin'?");
5171 strcpy (c
, "Hello world! What's up?");
5172 if (strcmp (c
, a
) == 0)
5176 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
5179 static void TestStringSub()
5181 wxString
s("Hello, world!");
5183 puts("*** Testing wxString substring extraction ***");
5185 printf("String = '%s'\n", s
.c_str());
5186 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
5187 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
5188 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
5189 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
5190 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
5191 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
5193 static const wxChar
*prefixes
[] =
5197 _T("Hello, world!"),
5198 _T("Hello, world!!!"),
5204 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
5206 wxString prefix
= prefixes
[n
], rest
;
5207 bool rc
= s
.StartsWith(prefix
, &rest
);
5208 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
5211 printf(" (the rest is '%s')\n", rest
.c_str());
5222 static void TestStringFormat()
5224 puts("*** Testing wxString formatting ***");
5227 s
.Printf("%03d", 18);
5229 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
5230 printf("Number 18: %s\n", s
.c_str());
5235 // returns "not found" for npos, value for all others
5236 static wxString
PosToString(size_t res
)
5238 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
5239 : wxString::Format(_T("%u"), res
);
5243 static void TestStringFind()
5245 puts("*** Testing wxString find() functions ***");
5247 static const wxChar
*strToFind
= _T("ell");
5248 static const struct StringFindTest
5252 result
; // of searching "ell" in str
5255 { _T("Well, hello world"), 0, 1 },
5256 { _T("Well, hello world"), 6, 7 },
5257 { _T("Well, hello world"), 9, wxString::npos
},
5260 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
5262 const StringFindTest
& ft
= findTestData
[n
];
5263 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
5265 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
5266 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
5268 size_t resTrue
= ft
.result
;
5269 if ( res
== resTrue
)
5275 printf(_T("(ERROR: should be %s)\n"),
5276 PosToString(resTrue
).c_str());
5283 static void TestStringTokenizer()
5285 puts("*** Testing wxStringTokenizer ***");
5287 static const wxChar
*modeNames
[] =
5291 _T("return all empty"),
5296 static const struct StringTokenizerTest
5298 const wxChar
*str
; // string to tokenize
5299 const wxChar
*delims
; // delimiters to use
5300 size_t count
; // count of token
5301 wxStringTokenizerMode mode
; // how should we tokenize it
5302 } tokenizerTestData
[] =
5304 { _T(""), _T(" "), 0 },
5305 { _T("Hello, world"), _T(" "), 2 },
5306 { _T("Hello, world "), _T(" "), 2 },
5307 { _T("Hello, world"), _T(","), 2 },
5308 { _T("Hello, world!"), _T(",!"), 2 },
5309 { _T("Hello,, world!"), _T(",!"), 3 },
5310 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
5311 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
5312 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
5313 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
5314 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
5315 { _T("01/02/99"), _T("/-"), 3 },
5316 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
5319 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
5321 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
5322 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
5324 size_t count
= tkz
.CountTokens();
5325 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
5326 MakePrintable(tt
.str
).c_str(),
5328 MakePrintable(tt
.delims
).c_str(),
5329 modeNames
[tkz
.GetMode()]);
5330 if ( count
== tt
.count
)
5336 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
5341 // if we emulate strtok(), check that we do it correctly
5342 wxChar
*buf
, *s
= NULL
, *last
;
5344 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
5346 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
5347 wxStrcpy(buf
, tt
.str
);
5349 s
= wxStrtok(buf
, tt
.delims
, &last
);
5356 // now show the tokens themselves
5358 while ( tkz
.HasMoreTokens() )
5360 wxString token
= tkz
.GetNextToken();
5362 printf(_T("\ttoken %u: '%s'"),
5364 MakePrintable(token
).c_str());
5374 printf(" (ERROR: should be %s)\n", s
);
5377 s
= wxStrtok(NULL
, tt
.delims
, &last
);
5381 // nothing to compare with
5386 if ( count2
!= count
)
5388 puts(_T("\tERROR: token count mismatch"));
5397 static void TestStringReplace()
5399 puts("*** Testing wxString::replace ***");
5401 static const struct StringReplaceTestData
5403 const wxChar
*original
; // original test string
5404 size_t start
, len
; // the part to replace
5405 const wxChar
*replacement
; // the replacement string
5406 const wxChar
*result
; // and the expected result
5407 } stringReplaceTestData
[] =
5409 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
5410 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
5411 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
5412 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
5413 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
5416 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
5418 const StringReplaceTestData data
= stringReplaceTestData
[n
];
5420 wxString original
= data
.original
;
5421 original
.replace(data
.start
, data
.len
, data
.replacement
);
5423 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
5424 data
.original
, data
.start
, data
.len
, data
.replacement
,
5427 if ( original
== data
.result
)
5433 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
5440 static void TestStringMatch()
5442 wxPuts(_T("*** Testing wxString::Matches() ***"));
5444 static const struct StringMatchTestData
5447 const wxChar
*wildcard
;
5449 } stringMatchTestData
[] =
5451 { _T("foobar"), _T("foo*"), 1 },
5452 { _T("foobar"), _T("*oo*"), 1 },
5453 { _T("foobar"), _T("*bar"), 1 },
5454 { _T("foobar"), _T("??????"), 1 },
5455 { _T("foobar"), _T("f??b*"), 1 },
5456 { _T("foobar"), _T("f?b*"), 0 },
5457 { _T("foobar"), _T("*goo*"), 0 },
5458 { _T("foobar"), _T("*foo"), 0 },
5459 { _T("foobarfoo"), _T("*foo"), 1 },
5460 { _T(""), _T("*"), 1 },
5461 { _T(""), _T("?"), 0 },
5464 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
5466 const StringMatchTestData
& data
= stringMatchTestData
[n
];
5467 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
5468 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
5470 matches
? _T("matches") : _T("doesn't match"),
5472 matches
== data
.matches
? _T("ok") : _T("ERROR"));
5478 #endif // TEST_STRINGS
5480 // ----------------------------------------------------------------------------
5482 // ----------------------------------------------------------------------------
5484 #ifdef TEST_SNGLINST
5485 #include "wx/snglinst.h"
5486 #endif // TEST_SNGLINST
5488 int main(int argc
, char **argv
)
5490 wxInitializer initializer
;
5493 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
5498 #ifdef TEST_SNGLINST
5499 wxSingleInstanceChecker checker
;
5500 if ( checker
.Create(_T(".wxconsole.lock")) )
5502 if ( checker
.IsAnotherRunning() )
5504 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
5509 // wait some time to give time to launch another instance
5510 wxPrintf(_T("Press \"Enter\" to continue..."));
5513 else // failed to create
5515 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
5517 #endif // TEST_SNGLINST
5521 #endif // TEST_CHARSET
5524 TestCmdLineConvert();
5526 #if wxUSE_CMDLINE_PARSER
5527 static const wxCmdLineEntryDesc cmdLineDesc
[] =
5529 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), "show this help message",
5530 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
5531 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
5532 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
5534 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
5535 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
5536 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
5537 wxCMD_LINE_VAL_NUMBER
},
5538 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
5539 wxCMD_LINE_VAL_DATE
},
5541 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
5542 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
5547 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
5549 parser
.AddOption("project_name", "", "full path to project file",
5550 wxCMD_LINE_VAL_STRING
,
5551 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
5553 switch ( parser
.Parse() )
5556 wxLogMessage("Help was given, terminating.");
5560 ShowCmdLine(parser
);
5564 wxLogMessage("Syntax error detected, aborting.");
5567 #endif // wxUSE_CMDLINE_PARSER
5569 #endif // TEST_CMDLINE
5577 TestStringConstruction();
5580 TestStringTokenizer();
5581 TestStringReplace();
5587 #endif // TEST_STRINGS
5600 puts("*** Initially:");
5602 PrintArray("a1", a1
);
5604 wxArrayString
a2(a1
);
5605 PrintArray("a2", a2
);
5607 wxSortedArrayString
a3(a1
);
5608 PrintArray("a3", a3
);
5610 puts("*** After deleting a string from a1");
5613 PrintArray("a1", a1
);
5614 PrintArray("a2", a2
);
5615 PrintArray("a3", a3
);
5617 puts("*** After reassigning a1 to a2 and a3");
5619 PrintArray("a2", a2
);
5620 PrintArray("a3", a3
);
5622 puts("*** After sorting a1");
5624 PrintArray("a1", a1
);
5626 puts("*** After sorting a1 in reverse order");
5628 PrintArray("a1", a1
);
5630 puts("*** After sorting a1 by the string length");
5631 a1
.Sort(StringLenCompare
);
5632 PrintArray("a1", a1
);
5634 TestArrayOfObjects();
5635 TestArrayOfShorts();
5639 #endif // TEST_ARRAYS
5649 #ifdef TEST_DLLLOADER
5651 #endif // TEST_DLLLOADER
5655 #endif // TEST_ENVIRON
5659 #endif // TEST_EXECUTE
5661 #ifdef TEST_FILECONF
5663 #endif // TEST_FILECONF
5671 #endif // TEST_LOCALE
5675 for ( size_t n
= 0; n
< 8000; n
++ )
5677 s
<< (char)('A' + (n
% 26));
5681 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
5683 // this one shouldn't be truncated
5686 // but this one will because log functions use fixed size buffer
5687 // (note that it doesn't need '\n' at the end neither - will be added
5689 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
5701 #ifdef TEST_FILENAME
5705 fn
.Assign("c:\\foo", "bar.baz");
5712 TestFileNameConstruction();
5713 TestFileNameMakeRelative();
5714 TestFileNameSplit();
5717 TestFileNameComparison();
5718 TestFileNameOperations();
5720 #endif // TEST_FILENAME
5722 #ifdef TEST_FILETIME
5725 #endif // TEST_FILETIME
5728 wxLog::AddTraceMask(FTP_TRACE_MASK
);
5729 if ( TestFtpConnect() )
5740 if ( TEST_INTERACTIVE
)
5741 TestFtpInteractive();
5743 //else: connecting to the FTP server failed
5749 #ifdef TEST_LONGLONG
5750 // seed pseudo random generator
5751 srand((unsigned)time(NULL
));
5760 TestMultiplication();
5763 TestLongLongConversion();
5764 TestBitOperations();
5765 TestLongLongComparison();
5766 TestLongLongPrint();
5768 #endif // TEST_LONGLONG
5776 #endif // TEST_HASHMAP
5779 wxLog::AddTraceMask(_T("mime"));
5787 TestMimeAssociate();
5790 #ifdef TEST_INFO_FUNCTIONS
5796 if ( TEST_INTERACTIVE
)
5799 #endif // TEST_INFO_FUNCTIONS
5801 #ifdef TEST_PATHLIST
5803 #endif // TEST_PATHLIST
5811 #endif // TEST_REGCONF
5814 // TODO: write a real test using src/regex/tests file
5819 TestRegExSubmatch();
5820 TestRegExReplacement();
5822 if ( TEST_INTERACTIVE
)
5823 TestRegExInteractive();
5825 #endif // TEST_REGEX
5827 #ifdef TEST_REGISTRY
5829 TestRegistryAssociation();
5830 #endif // TEST_REGISTRY
5835 #endif // TEST_SOCKETS
5840 #endif // TEST_STREAMS
5843 int nCPUs
= wxThread::GetCPUCount();
5844 printf("This system has %d CPUs\n", nCPUs
);
5846 wxThread::SetConcurrency(nCPUs
);
5850 TestDetachedThreads();
5851 TestJoinableThreads();
5852 TestThreadSuspend();
5856 TestThreadConditions();
5857 #endif // TEST_THREADS
5861 #endif // TEST_TIMER
5863 #ifdef TEST_DATETIME
5876 TestTimeArithmetics();
5879 TestTimeSpanFormat();
5885 if ( TEST_INTERACTIVE
)
5886 TestDateTimeInteractive();
5887 #endif // TEST_DATETIME
5890 puts("Sleeping for 3 seconds... z-z-z-z-z...");
5892 #endif // TEST_USLEEP
5897 #endif // TEST_VCARD
5901 #endif // TEST_VOLUME
5905 TestEncodingConverter();
5906 #endif // TEST_WCHAR
5909 TestZipStreamRead();
5910 TestZipFileSystem();
5914 TestZlibStreamWrite();
5915 TestZlibStreamRead();