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
},
806 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
807 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), TRUE
, wxPATH_MAC
},
808 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), TRUE
, wxPATH_MAC
},
809 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), FALSE
, wxPATH_MAC
},
810 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
811 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE
, wxPATH_MAC
},
814 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), TRUE
, wxPATH_VMS
},
815 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), FALSE
, wxPATH_VMS
},
818 static void TestFileNameConstruction()
820 puts("*** testing wxFileName construction ***");
822 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
824 const FileNameInfo
& fni
= filenames
[n
];
826 wxFileName
fn(fni
.fullname
, fni
.format
);
828 wxString fullname
= fn
.GetFullPath(fni
.format
);
829 if ( fullname
!= fni
.fullname
)
831 printf("ERROR: fullname should be '%s'\n", fni
.fullname
);
834 bool isAbsolute
= fn
.IsAbsolute();
835 printf("'%s' is %s (%s)\n\t",
837 isAbsolute
? "absolute" : "relative",
838 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
840 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
842 puts("ERROR (couldn't be normalized)");
846 printf("normalized: '%s'\n", fn
.GetFullPath(fni
.format
).c_str());
853 static void TestFileNameSplit()
855 puts("*** testing wxFileName splitting ***");
857 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
859 const FileNameInfo
& fni
= filenames
[n
];
860 wxString volume
, path
, name
, ext
;
861 wxFileName::SplitPath(fni
.fullname
,
862 &volume
, &path
, &name
, &ext
, fni
.format
);
864 printf("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'",
866 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
868 if ( volume
!= fni
.volume
)
869 printf(" (ERROR: volume = '%s')", fni
.volume
);
870 if ( path
!= fni
.path
)
871 printf(" (ERROR: path = '%s')", fni
.path
);
872 if ( name
!= fni
.name
)
873 printf(" (ERROR: name = '%s')", fni
.name
);
874 if ( ext
!= fni
.ext
)
875 printf(" (ERROR: ext = '%s')", fni
.ext
);
881 static void TestFileNameTemp()
883 puts("*** testing wxFileName temp file creation ***");
885 static const char *tmpprefixes
[] =
891 "/tmp/foo/bar", // this one must be an error
894 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
896 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
899 printf("Prefix '%s'\t-> temp file '%s'\n",
900 tmpprefixes
[n
], path
.c_str());
902 if ( !wxRemoveFile(path
) )
904 wxLogWarning("Failed to remove temp file '%s'", path
.c_str());
910 static void TestFileNameMakeRelative()
912 puts("*** testing wxFileName::MakeRelativeTo() ***");
914 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
916 const FileNameInfo
& fni
= filenames
[n
];
918 wxFileName
fn(fni
.fullname
, fni
.format
);
920 // choose the base dir of the same format
922 switch ( fni
.format
)
934 // TODO: I don't know how this is supposed to work there
937 case wxPATH_NATIVE
: // make gcc happy
939 wxFAIL_MSG( "unexpected path format" );
942 printf("'%s' relative to '%s': ",
943 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
945 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
951 printf("'%s'\n", fn
.GetFullPath(fni
.format
).c_str());
956 static void TestFileNameComparison()
961 static void TestFileNameOperations()
966 static void TestFileNameCwd()
971 #endif // TEST_FILENAME
973 // ----------------------------------------------------------------------------
974 // wxFileName time functions
975 // ----------------------------------------------------------------------------
979 #include <wx/filename.h>
980 #include <wx/datetime.h>
982 static void TestFileGetTimes()
984 wxFileName
fn(_T("testdata.fc"));
986 wxDateTime dtAccess
, dtMod
, dtCreate
;
987 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
989 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
993 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
995 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
996 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
997 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
998 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1002 static void TestFileSetTimes()
1004 wxFileName
fn(_T("testdata.fc"));
1008 wxPrintf(_T("ERROR: Touch() failed.\n"));
1012 #endif // TEST_FILETIME
1014 // ----------------------------------------------------------------------------
1016 // ----------------------------------------------------------------------------
1020 #include "wx/hash.h"
1024 Foo(int n_
) { n
= n_
; count
++; }
1029 static size_t count
;
1032 size_t Foo::count
= 0;
1034 WX_DECLARE_LIST(Foo
, wxListFoos
);
1035 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1037 #include "wx/listimpl.cpp"
1039 WX_DEFINE_LIST(wxListFoos
);
1041 static void TestHash()
1043 puts("*** Testing wxHashTable ***\n");
1047 hash
.DeleteContents(TRUE
);
1049 printf("Hash created: %u foos in hash, %u foos totally\n",
1050 hash
.GetCount(), Foo::count
);
1052 static const int hashTestData
[] =
1054 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1058 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1060 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1063 printf("Hash filled: %u foos in hash, %u foos totally\n",
1064 hash
.GetCount(), Foo::count
);
1066 puts("Hash access test:");
1067 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1069 printf("\tGetting element with key %d, value %d: ",
1070 hashTestData
[n
], n
);
1071 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1074 printf("ERROR, not found.\n");
1078 printf("%d (%s)\n", foo
->n
,
1079 (size_t)foo
->n
== n
? "ok" : "ERROR");
1083 printf("\nTrying to get an element not in hash: ");
1085 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1087 puts("ERROR: found!");
1091 puts("ok (not found)");
1095 printf("Hash destroyed: %u foos left\n", Foo::count
);
1100 // ----------------------------------------------------------------------------
1102 // ----------------------------------------------------------------------------
1106 #include "wx/hashmap.h"
1108 // test compilation of basic map types
1109 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1110 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1111 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1112 myUnsignedHashMap
);
1113 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1115 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1117 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1119 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1123 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1124 // myStringHashMap );
1125 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1127 typedef myStringHashMap::iterator Itor
;
1129 static void TestHashMap()
1131 puts("*** Testing wxHashMap ***\n");
1132 myStringHashMap
sh(0); // as small as possible
1135 const size_t count
= 10000;
1137 // init with some data
1138 for( i
= 0; i
< count
; ++i
)
1140 buf
.Printf(wxT("%d"), i
);
1141 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1144 // test that insertion worked
1145 if( sh
.size() != count
)
1147 printf("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n", sh
.size(), count
);
1150 for( i
= 0; i
< count
; ++i
)
1152 buf
.Printf(wxT("%d"), i
);
1153 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1155 printf("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n");
1160 // check that iterators work
1162 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1166 printf("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n");
1170 if( it
->second
!= sh
[it
->first
] )
1172 printf("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n");
1177 if( sh
.size() != i
)
1179 printf("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n", i
, count
);
1182 // test copy ctor, assignment operator
1183 myStringHashMap
h1( sh
), h2( 0 );
1186 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1188 if( h1
[it
->first
] != it
->second
)
1190 printf("*** ERROR: COPY CTOR BROKEN %s ***\n", it
->first
.c_str());
1193 if( h2
[it
->first
] != it
->second
)
1195 printf("*** ERROR: OPERATOR= BROKEN %s ***\n", it
->first
.c_str());
1200 for( i
= 0; i
< count
; ++i
)
1202 buf
.Printf(wxT("%d"), i
);
1203 size_t sz
= sh
.size();
1205 // test find() and erase(it)
1208 it
= sh
.find( buf
);
1209 if( it
!= sh
.end() )
1213 if( sh
.find( buf
) != sh
.end() )
1215 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1219 printf("*** ERROR: CANT FIND ELEMENT %u ***\n", i
);
1224 size_t c
= sh
.erase( buf
);
1226 printf("*** ERROR: SHOULD RETURN 1 ***\n");
1228 if( sh
.find( buf
) != sh
.end() )
1230 printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i
);
1234 // count should decrease
1235 if( sh
.size() != sz
- 1 )
1237 printf("*** ERROR: COUNT DID NOT DECREASE ***\n");
1241 printf("*** Finished testing wxHashMap ***\n");
1244 #endif // TEST_HASHMAP
1246 // ----------------------------------------------------------------------------
1248 // ----------------------------------------------------------------------------
1252 #include "wx/list.h"
1254 WX_DECLARE_LIST(Bar
, wxListBars
);
1255 #include "wx/listimpl.cpp"
1256 WX_DEFINE_LIST(wxListBars
);
1258 static void TestListCtor()
1260 puts("*** Testing wxList construction ***\n");
1264 list1
.Append(new Bar(_T("first")));
1265 list1
.Append(new Bar(_T("second")));
1267 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
1268 list1
.GetCount(), Bar::GetNumber());
1273 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
1274 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1276 list1
.DeleteContents(TRUE
);
1279 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
1284 // ----------------------------------------------------------------------------
1286 // ----------------------------------------------------------------------------
1290 #include "wx/intl.h"
1291 #include "wx/utils.h" // for wxSetEnv
1293 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1295 // find the name of the language from its value
1296 static const char *GetLangName(int lang
)
1298 static const char *languageNames
[] =
1319 "ARABIC_SAUDI_ARABIA",
1344 "CHINESE_SIMPLIFIED",
1345 "CHINESE_TRADITIONAL",
1348 "CHINESE_SINGAPORE",
1359 "ENGLISH_AUSTRALIA",
1363 "ENGLISH_CARIBBEAN",
1367 "ENGLISH_NEW_ZEALAND",
1368 "ENGLISH_PHILIPPINES",
1369 "ENGLISH_SOUTH_AFRICA",
1381 "FRENCH_LUXEMBOURG",
1390 "GERMAN_LIECHTENSTEIN",
1391 "GERMAN_LUXEMBOURG",
1432 "MALAY_BRUNEI_DARUSSALAM",
1444 "NORWEGIAN_NYNORSK",
1451 "PORTUGUESE_BRAZILIAN",
1476 "SPANISH_ARGENTINA",
1480 "SPANISH_COSTA_RICA",
1481 "SPANISH_DOMINICAN_REPUBLIC",
1483 "SPANISH_EL_SALVADOR",
1484 "SPANISH_GUATEMALA",
1488 "SPANISH_NICARAGUA",
1492 "SPANISH_PUERTO_RICO",
1495 "SPANISH_VENEZUELA",
1532 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1533 return languageNames
[lang
];
1538 static void TestDefaultLang()
1540 puts("*** Testing wxLocale::GetSystemLanguage ***");
1542 static const wxChar
*langStrings
[] =
1544 NULL
, // system default
1551 _T("de_DE.iso88591"),
1553 _T("?"), // invalid lang spec
1554 _T("klingonese"), // I bet on some systems it does exist...
1557 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1558 wxLocale::GetSystemEncodingName().c_str(),
1559 wxLocale::GetSystemEncoding());
1561 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1563 const char *langStr
= langStrings
[n
];
1566 // FIXME: this doesn't do anything at all under Windows, we need
1567 // to create a new wxLocale!
1568 wxSetEnv(_T("LC_ALL"), langStr
);
1571 int lang
= gs_localeDefault
.GetSystemLanguage();
1572 printf("Locale for '%s' is %s.\n",
1573 langStr
? langStr
: "system default", GetLangName(lang
));
1577 #endif // TEST_LOCALE
1579 // ----------------------------------------------------------------------------
1581 // ----------------------------------------------------------------------------
1585 #include "wx/mimetype.h"
1587 static void TestMimeEnum()
1589 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1591 wxArrayString mimetypes
;
1593 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1595 printf("*** All %u known filetypes: ***\n", count
);
1600 for ( size_t n
= 0; n
< count
; n
++ )
1602 wxFileType
*filetype
=
1603 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1606 printf("nothing known about the filetype '%s'!\n",
1607 mimetypes
[n
].c_str());
1611 filetype
->GetDescription(&desc
);
1612 filetype
->GetExtensions(exts
);
1614 filetype
->GetIcon(NULL
);
1617 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1620 extsAll
<< _T(", ");
1624 printf("\t%s: %s (%s)\n",
1625 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1631 static void TestMimeOverride()
1633 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1635 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1636 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1638 if ( wxFile::Exists(mailcap
) )
1639 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1641 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1643 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1646 if ( wxFile::Exists(mimetypes
) )
1647 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1649 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1651 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1657 static void TestMimeFilename()
1659 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1661 static const wxChar
*filenames
[] =
1668 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1670 const wxString fname
= filenames
[n
];
1671 wxString ext
= fname
.AfterLast(_T('.'));
1672 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1675 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1680 if ( !ft
->GetDescription(&desc
) )
1681 desc
= _T("<no description>");
1684 if ( !ft
->GetOpenCommand(&cmd
,
1685 wxFileType::MessageParameters(fname
, _T(""))) )
1686 cmd
= _T("<no command available>");
1688 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
1689 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1698 static void TestMimeAssociate()
1700 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1702 wxFileTypeInfo
ftInfo(
1703 _T("application/x-xyz"),
1704 _T("xyzview '%s'"), // open cmd
1705 _T(""), // print cmd
1706 _T("XYZ File"), // description
1707 _T(".xyz"), // extensions
1708 NULL
// end of extensions
1710 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1712 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1715 wxPuts(_T("ERROR: failed to create association!"));
1719 // TODO: read it back
1728 // ----------------------------------------------------------------------------
1729 // misc information functions
1730 // ----------------------------------------------------------------------------
1732 #ifdef TEST_INFO_FUNCTIONS
1734 #include "wx/utils.h"
1736 static void TestDiskInfo()
1738 puts("*** Testing wxGetDiskSpace() ***");
1743 printf("\nEnter a directory name: ");
1744 if ( !fgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1747 // kill the last '\n'
1748 pathname
[strlen(pathname
) - 1] = 0;
1750 wxLongLong total
, free
;
1751 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1753 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1757 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1758 (total
/ 1024).ToString().c_str(),
1759 (free
/ 1024).ToString().c_str(),
1765 static void TestOsInfo()
1767 puts("*** Testing OS info functions ***\n");
1770 wxGetOsVersion(&major
, &minor
);
1771 printf("Running under: %s, version %d.%d\n",
1772 wxGetOsDescription().c_str(), major
, minor
);
1774 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
1776 printf("Host name is %s (%s).\n",
1777 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1782 static void TestUserInfo()
1784 puts("*** Testing user info functions ***\n");
1786 printf("User id is:\t%s\n", wxGetUserId().c_str());
1787 printf("User name is:\t%s\n", wxGetUserName().c_str());
1788 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
1789 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
1794 #endif // TEST_INFO_FUNCTIONS
1796 // ----------------------------------------------------------------------------
1798 // ----------------------------------------------------------------------------
1800 #ifdef TEST_LONGLONG
1802 #include "wx/longlong.h"
1803 #include "wx/timer.h"
1805 // make a 64 bit number from 4 16 bit ones
1806 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
1808 // get a random 64 bit number
1809 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
1811 static const long testLongs
[] =
1822 #if wxUSE_LONGLONG_WX
1823 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
1824 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1825 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
1826 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1827 #endif // wxUSE_LONGLONG_WX
1829 static void TestSpeed()
1831 static const long max
= 100000000;
1838 for ( n
= 0; n
< max
; n
++ )
1843 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
1846 #if wxUSE_LONGLONG_NATIVE
1851 for ( n
= 0; n
< max
; n
++ )
1856 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
1858 #endif // wxUSE_LONGLONG_NATIVE
1864 for ( n
= 0; n
< max
; n
++ )
1869 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
1873 static void TestLongLongConversion()
1875 puts("*** Testing wxLongLong conversions ***\n");
1879 for ( size_t n
= 0; n
< 100000; n
++ )
1883 #if wxUSE_LONGLONG_NATIVE
1884 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
1886 wxASSERT_MSG( a
== b
, "conversions failure" );
1888 puts("Can't do it without native long long type, test skipped.");
1891 #endif // wxUSE_LONGLONG_NATIVE
1893 if ( !(nTested
% 1000) )
1905 static void TestMultiplication()
1907 puts("*** Testing wxLongLong multiplication ***\n");
1911 for ( size_t n
= 0; n
< 100000; n
++ )
1916 #if wxUSE_LONGLONG_NATIVE
1917 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
1918 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
1920 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
1921 #else // !wxUSE_LONGLONG_NATIVE
1922 puts("Can't do it without native long long type, test skipped.");
1925 #endif // wxUSE_LONGLONG_NATIVE
1927 if ( !(nTested
% 1000) )
1939 static void TestDivision()
1941 puts("*** Testing wxLongLong division ***\n");
1945 for ( size_t n
= 0; n
< 100000; n
++ )
1947 // get a random wxLongLong (shifting by 12 the MSB ensures that the
1948 // multiplication will not overflow)
1949 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
1951 // get a random (but non null) long (not wxLongLong for now) to divide
1963 #if wxUSE_LONGLONG_NATIVE
1964 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
1966 wxLongLongNative p
= m
/ l
, s
= m
% l
;
1967 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
1968 #else // !wxUSE_LONGLONG_NATIVE
1969 // verify the result
1970 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
1971 #endif // wxUSE_LONGLONG_NATIVE
1973 if ( !(nTested
% 1000) )
1985 static void TestAddition()
1987 puts("*** Testing wxLongLong addition ***\n");
1991 for ( size_t n
= 0; n
< 100000; n
++ )
1997 #if wxUSE_LONGLONG_NATIVE
1998 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
1999 wxLongLongNative(b
.GetHi(), b
.GetLo()),
2000 "addition failure" );
2001 #else // !wxUSE_LONGLONG_NATIVE
2002 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2003 #endif // wxUSE_LONGLONG_NATIVE
2005 if ( !(nTested
% 1000) )
2017 static void TestBitOperations()
2019 puts("*** Testing wxLongLong bit operation ***\n");
2023 for ( size_t n
= 0; n
< 100000; n
++ )
2027 #if wxUSE_LONGLONG_NATIVE
2028 for ( size_t n
= 0; n
< 33; n
++ )
2031 #else // !wxUSE_LONGLONG_NATIVE
2032 puts("Can't do it without native long long type, test skipped.");
2035 #endif // wxUSE_LONGLONG_NATIVE
2037 if ( !(nTested
% 1000) )
2049 static void TestLongLongComparison()
2051 #if wxUSE_LONGLONG_WX
2052 puts("*** Testing wxLongLong comparison ***\n");
2054 static const long ls
[2] =
2060 wxLongLongWx lls
[2];
2064 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2068 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2070 res
= lls
[m
] > testLongs
[n
];
2071 printf("0x%lx > 0x%lx is %s (%s)\n",
2072 ls
[m
], testLongs
[n
], res
? "true" : "false",
2073 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2075 res
= lls
[m
] < testLongs
[n
];
2076 printf("0x%lx < 0x%lx is %s (%s)\n",
2077 ls
[m
], testLongs
[n
], res
? "true" : "false",
2078 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2080 res
= lls
[m
] == testLongs
[n
];
2081 printf("0x%lx == 0x%lx is %s (%s)\n",
2082 ls
[m
], testLongs
[n
], res
? "true" : "false",
2083 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2086 #endif // wxUSE_LONGLONG_WX
2089 static void TestLongLongPrint()
2091 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2093 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2095 wxLongLong ll
= testLongs
[n
];
2096 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2099 wxLongLong
ll(0x12345678, 0x87654321);
2100 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2103 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2109 #endif // TEST_LONGLONG
2111 // ----------------------------------------------------------------------------
2113 // ----------------------------------------------------------------------------
2115 #ifdef TEST_PATHLIST
2117 static void TestPathList()
2119 puts("*** Testing wxPathList ***\n");
2121 wxPathList pathlist
;
2122 pathlist
.AddEnvList("PATH");
2123 wxString path
= pathlist
.FindValidPath("ls");
2126 printf("ERROR: command not found in the path.\n");
2130 printf("Command found in the path as '%s'.\n", path
.c_str());
2134 #endif // TEST_PATHLIST
2136 // ----------------------------------------------------------------------------
2137 // regular expressions
2138 // ----------------------------------------------------------------------------
2142 #include "wx/regex.h"
2144 static void TestRegExCompile()
2146 wxPuts(_T("*** Testing RE compilation ***\n"));
2148 static struct RegExCompTestData
2150 const wxChar
*pattern
;
2152 } regExCompTestData
[] =
2154 { _T("foo"), TRUE
},
2155 { _T("foo("), FALSE
},
2156 { _T("foo(bar"), FALSE
},
2157 { _T("foo(bar)"), TRUE
},
2158 { _T("foo["), FALSE
},
2159 { _T("foo[bar"), FALSE
},
2160 { _T("foo[bar]"), TRUE
},
2161 { _T("foo{"), TRUE
},
2162 { _T("foo{1"), FALSE
},
2163 { _T("foo{bar"), TRUE
},
2164 { _T("foo{1}"), TRUE
},
2165 { _T("foo{1,2}"), TRUE
},
2166 { _T("foo{bar}"), TRUE
},
2167 { _T("foo*"), TRUE
},
2168 { _T("foo**"), FALSE
},
2169 { _T("foo+"), TRUE
},
2170 { _T("foo++"), FALSE
},
2171 { _T("foo?"), TRUE
},
2172 { _T("foo??"), FALSE
},
2173 { _T("foo?+"), FALSE
},
2177 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2179 const RegExCompTestData
& data
= regExCompTestData
[n
];
2180 bool ok
= re
.Compile(data
.pattern
);
2182 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2184 ok
? _T("") : _T("not "),
2185 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2189 static void TestRegExMatch()
2191 wxPuts(_T("*** Testing RE matching ***\n"));
2193 static struct RegExMatchTestData
2195 const wxChar
*pattern
;
2198 } regExMatchTestData
[] =
2200 { _T("foo"), _T("bar"), FALSE
},
2201 { _T("foo"), _T("foobar"), TRUE
},
2202 { _T("^foo"), _T("foobar"), TRUE
},
2203 { _T("^foo"), _T("barfoo"), FALSE
},
2204 { _T("bar$"), _T("barbar"), TRUE
},
2205 { _T("bar$"), _T("barbar "), FALSE
},
2208 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2210 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2212 wxRegEx
re(data
.pattern
);
2213 bool ok
= re
.Matches(data
.text
);
2215 wxPrintf(_T("'%s' %s %s (%s)\n"),
2217 ok
? _T("matches") : _T("doesn't match"),
2219 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2223 static void TestRegExSubmatch()
2225 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2227 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2228 if ( !re
.IsValid() )
2230 wxPuts(_T("ERROR: compilation failed."));
2234 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2236 if ( !re
.Matches(text
) )
2238 wxPuts(_T("ERROR: match expected."));
2242 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2244 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2245 re
.GetMatch(text
, 3).c_str(),
2246 re
.GetMatch(text
, 2).c_str(),
2247 re
.GetMatch(text
, 4).c_str(),
2248 re
.GetMatch(text
, 1).c_str());
2252 static void TestRegExReplacement()
2254 wxPuts(_T("*** Testing RE replacement ***"));
2256 static struct RegExReplTestData
2260 const wxChar
*result
;
2262 } regExReplTestData
[] =
2264 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2265 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2266 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2267 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2268 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2269 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2270 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2273 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2274 wxRegEx
re(pattern
);
2276 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2278 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2280 const RegExReplTestData
& data
= regExReplTestData
[n
];
2282 wxString text
= data
.text
;
2283 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2285 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2286 data
.text
, data
.repl
,
2287 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2289 if ( text
== data
.result
&& nRepl
== data
.count
)
2295 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2296 data
.count
, data
.result
);
2301 static void TestRegExInteractive()
2303 wxPuts(_T("*** Testing RE interactively ***"));
2308 printf("\nEnter a pattern: ");
2309 if ( !fgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2312 // kill the last '\n'
2313 pattern
[strlen(pattern
) - 1] = 0;
2316 if ( !re
.Compile(pattern
) )
2324 printf("Enter text to match: ");
2325 if ( !fgets(text
, WXSIZEOF(text
), stdin
) )
2328 // kill the last '\n'
2329 text
[strlen(text
) - 1] = 0;
2331 if ( !re
.Matches(text
) )
2333 printf("No match.\n");
2337 printf("Pattern matches at '%s'\n", re
.GetMatch(text
).c_str());
2340 for ( size_t n
= 1; ; n
++ )
2342 if ( !re
.GetMatch(&start
, &len
, n
) )
2347 printf("Subexpr %u matched '%s'\n",
2348 n
, wxString(text
+ start
, len
).c_str());
2355 #endif // TEST_REGEX
2357 // ----------------------------------------------------------------------------
2359 // ----------------------------------------------------------------------------
2365 static void TestDbOpen()
2373 // ----------------------------------------------------------------------------
2374 // registry and related stuff
2375 // ----------------------------------------------------------------------------
2377 // this is for MSW only
2380 #undef TEST_REGISTRY
2385 #include "wx/confbase.h"
2386 #include "wx/msw/regconf.h"
2388 static void TestRegConfWrite()
2390 wxRegConfig
regconf(_T("console"), _T("wxwindows"));
2391 regconf
.Write(_T("Hello"), wxString(_T("world")));
2394 #endif // TEST_REGCONF
2396 #ifdef TEST_REGISTRY
2398 #include "wx/msw/registry.h"
2400 // I chose this one because I liked its name, but it probably only exists under
2402 static const wxChar
*TESTKEY
=
2403 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2405 static void TestRegistryRead()
2407 puts("*** testing registry reading ***");
2409 wxRegKey
key(TESTKEY
);
2410 printf("The test key name is '%s'.\n", key
.GetName().c_str());
2413 puts("ERROR: test key can't be opened, aborting test.");
2418 size_t nSubKeys
, nValues
;
2419 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2421 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
2424 printf("Enumerating values:\n");
2428 bool cont
= key
.GetFirstValue(value
, dummy
);
2431 printf("Value '%s': type ", value
.c_str());
2432 switch ( key
.GetValueType(value
) )
2434 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
2435 case wxRegKey::Type_String
: printf("SZ"); break;
2436 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
2437 case wxRegKey::Type_Binary
: printf("BINARY"); break;
2438 case wxRegKey::Type_Dword
: printf("DWORD"); break;
2439 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
2440 default: printf("other (unknown)"); break;
2443 printf(", value = ");
2444 if ( key
.IsNumericValue(value
) )
2447 key
.QueryValue(value
, &val
);
2453 key
.QueryValue(value
, val
);
2454 printf("'%s'", val
.c_str());
2456 key
.QueryRawValue(value
, val
);
2457 printf(" (raw value '%s')", val
.c_str());
2462 cont
= key
.GetNextValue(value
, dummy
);
2466 static void TestRegistryAssociation()
2469 The second call to deleteself genertaes an error message, with a
2470 messagebox saying .flo is crucial to system operation, while the .ddf
2471 call also fails, but with no error message
2476 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2478 key
= "ddxf_auto_file" ;
2479 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2481 key
= "ddxf_auto_file" ;
2482 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2485 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2487 key
= "program \"%1\"" ;
2489 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2491 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
2493 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2495 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2499 #endif // TEST_REGISTRY
2501 // ----------------------------------------------------------------------------
2503 // ----------------------------------------------------------------------------
2507 #include "wx/socket.h"
2508 #include "wx/protocol/protocol.h"
2509 #include "wx/protocol/http.h"
2511 static void TestSocketServer()
2513 puts("*** Testing wxSocketServer ***\n");
2515 static const int PORT
= 3000;
2520 wxSocketServer
*server
= new wxSocketServer(addr
);
2521 if ( !server
->Ok() )
2523 puts("ERROR: failed to bind");
2530 printf("Server: waiting for connection on port %d...\n", PORT
);
2532 wxSocketBase
*socket
= server
->Accept();
2535 puts("ERROR: wxSocketServer::Accept() failed.");
2539 puts("Server: got a client.");
2541 server
->SetTimeout(60); // 1 min
2543 while ( socket
->IsConnected() )
2549 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2551 // don't log error if the client just close the connection
2552 if ( socket
->IsConnected() )
2554 puts("ERROR: in wxSocket::Read.");
2574 printf("Server: got '%s'.\n", s
.c_str());
2575 if ( s
== _T("bye") )
2582 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2583 socket
->Write("\r\n", 2);
2584 printf("Server: wrote '%s'.\n", s
.c_str());
2587 puts("Server: lost a client.");
2592 // same as "delete server" but is consistent with GUI programs
2596 static void TestSocketClient()
2598 puts("*** Testing wxSocketClient ***\n");
2600 static const char *hostname
= "www.wxwindows.org";
2603 addr
.Hostname(hostname
);
2606 printf("--- Attempting to connect to %s:80...\n", hostname
);
2608 wxSocketClient client
;
2609 if ( !client
.Connect(addr
) )
2611 printf("ERROR: failed to connect to %s\n", hostname
);
2615 printf("--- Connected to %s:%u...\n",
2616 addr
.Hostname().c_str(), addr
.Service());
2620 // could use simply "GET" here I suppose
2622 wxString::Format("GET http://%s/\r\n", hostname
);
2623 client
.Write(cmdGet
, cmdGet
.length());
2624 printf("--- Sent command '%s' to the server\n",
2625 MakePrintable(cmdGet
).c_str());
2626 client
.Read(buf
, WXSIZEOF(buf
));
2627 printf("--- Server replied:\n%s", buf
);
2631 #endif // TEST_SOCKETS
2633 // ----------------------------------------------------------------------------
2635 // ----------------------------------------------------------------------------
2639 #include "wx/protocol/ftp.h"
2643 #define FTP_ANONYMOUS
2645 #ifdef FTP_ANONYMOUS
2646 static const char *directory
= "/pub";
2647 static const char *filename
= "welcome.msg";
2649 static const char *directory
= "/etc";
2650 static const char *filename
= "issue";
2653 static bool TestFtpConnect()
2655 puts("*** Testing FTP connect ***");
2657 #ifdef FTP_ANONYMOUS
2658 static const char *hostname
= "ftp.wxwindows.org";
2660 printf("--- Attempting to connect to %s:21 anonymously...\n", hostname
);
2661 #else // !FTP_ANONYMOUS
2662 static const char *hostname
= "localhost";
2665 fgets(user
, WXSIZEOF(user
), stdin
);
2666 user
[strlen(user
) - 1] = '\0'; // chop off '\n'
2670 printf("Password for %s: ", password
);
2671 fgets(password
, WXSIZEOF(password
), stdin
);
2672 password
[strlen(password
) - 1] = '\0'; // chop off '\n'
2673 ftp
.SetPassword(password
);
2675 printf("--- Attempting to connect to %s:21 as %s...\n", hostname
, user
);
2676 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2678 if ( !ftp
.Connect(hostname
) )
2680 printf("ERROR: failed to connect to %s\n", hostname
);
2686 printf("--- Connected to %s, current directory is '%s'\n",
2687 hostname
, ftp
.Pwd().c_str());
2693 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2694 static void TestFtpWuFtpd()
2697 static const char *hostname
= "ftp.eudora.com";
2698 if ( !ftp
.Connect(hostname
) )
2700 printf("ERROR: failed to connect to %s\n", hostname
);
2704 static const char *filename
= "eudora/pubs/draft-gellens-submit-09.txt";
2705 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2708 printf("ERROR: couldn't get input stream for %s\n", filename
);
2712 size_t size
= in
->StreamSize();
2713 printf("Reading file %s (%u bytes)...", filename
, size
);
2715 char *data
= new char[size
];
2716 if ( !in
->Read(data
, size
) )
2718 puts("ERROR: read error");
2722 printf("Successfully retrieved the file.\n");
2731 static void TestFtpList()
2733 puts("*** Testing wxFTP file listing ***\n");
2736 if ( !ftp
.ChDir(directory
) )
2738 printf("ERROR: failed to cd to %s\n", directory
);
2741 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2743 // test NLIST and LIST
2744 wxArrayString files
;
2745 if ( !ftp
.GetFilesList(files
) )
2747 puts("ERROR: failed to get NLIST of files");
2751 printf("Brief list of files under '%s':\n", ftp
.Pwd().c_str());
2752 size_t count
= files
.GetCount();
2753 for ( size_t n
= 0; n
< count
; n
++ )
2755 printf("\t%s\n", files
[n
].c_str());
2757 puts("End of the file list");
2760 if ( !ftp
.GetDirList(files
) )
2762 puts("ERROR: failed to get LIST of files");
2766 printf("Detailed list of files under '%s':\n", ftp
.Pwd().c_str());
2767 size_t count
= files
.GetCount();
2768 for ( size_t n
= 0; n
< count
; n
++ )
2770 printf("\t%s\n", files
[n
].c_str());
2772 puts("End of the file list");
2775 if ( !ftp
.ChDir(_T("..")) )
2777 puts("ERROR: failed to cd to ..");
2780 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2783 static void TestFtpDownload()
2785 puts("*** Testing wxFTP download ***\n");
2788 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2791 printf("ERROR: couldn't get input stream for %s\n", filename
);
2795 size_t size
= in
->StreamSize();
2796 printf("Reading file %s (%u bytes)...", filename
, size
);
2799 char *data
= new char[size
];
2800 if ( !in
->Read(data
, size
) )
2802 puts("ERROR: read error");
2806 printf("\nContents of %s:\n%s\n", filename
, data
);
2814 static void TestFtpFileSize()
2816 puts("*** Testing FTP SIZE command ***");
2818 if ( !ftp
.ChDir(directory
) )
2820 printf("ERROR: failed to cd to %s\n", directory
);
2823 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2825 if ( ftp
.FileExists(filename
) )
2827 int size
= ftp
.GetFileSize(filename
);
2829 printf("ERROR: couldn't get size of '%s'\n", filename
);
2831 printf("Size of '%s' is %d bytes.\n", filename
, size
);
2835 printf("ERROR: '%s' doesn't exist\n", filename
);
2839 static void TestFtpMisc()
2841 puts("*** Testing miscellaneous wxFTP functions ***");
2843 if ( ftp
.SendCommand("STAT") != '2' )
2845 puts("ERROR: STAT failed");
2849 printf("STAT returned:\n\n%s\n", ftp
.GetLastResult().c_str());
2852 if ( ftp
.SendCommand("HELP SITE") != '2' )
2854 puts("ERROR: HELP SITE failed");
2858 printf("The list of site-specific commands:\n\n%s\n",
2859 ftp
.GetLastResult().c_str());
2863 static void TestFtpInteractive()
2865 puts("\n*** Interactive wxFTP test ***");
2871 printf("Enter FTP command: ");
2872 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2875 // kill the last '\n'
2876 buf
[strlen(buf
) - 1] = 0;
2878 // special handling of LIST and NLST as they require data connection
2879 wxString
start(buf
, 4);
2881 if ( start
== "LIST" || start
== "NLST" )
2884 if ( strlen(buf
) > 4 )
2887 wxArrayString files
;
2888 if ( !ftp
.GetList(files
, wildcard
, start
== "LIST") )
2890 printf("ERROR: failed to get %s of files\n", start
.c_str());
2894 printf("--- %s of '%s' under '%s':\n",
2895 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2896 size_t count
= files
.GetCount();
2897 for ( size_t n
= 0; n
< count
; n
++ )
2899 printf("\t%s\n", files
[n
].c_str());
2901 puts("--- End of the file list");
2906 char ch
= ftp
.SendCommand(buf
);
2907 printf("Command %s", ch
? "succeeded" : "failed");
2910 printf(" (return code %c)", ch
);
2913 printf(", server reply:\n%s\n\n", ftp
.GetLastResult().c_str());
2917 puts("\n*** done ***");
2920 static void TestFtpUpload()
2922 puts("*** Testing wxFTP uploading ***\n");
2925 static const char *file1
= "test1";
2926 static const char *file2
= "test2";
2927 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2930 printf("--- Uploading to %s ---\n", file1
);
2931 out
->Write("First hello", 11);
2935 // send a command to check the remote file
2936 if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' )
2938 printf("ERROR: STAT %s failed\n", file1
);
2942 printf("STAT %s returned:\n\n%s\n",
2943 file1
, ftp
.GetLastResult().c_str());
2946 out
= ftp
.GetOutputStream(file2
);
2949 printf("--- Uploading to %s ---\n", file1
);
2950 out
->Write("Second hello", 12);
2957 // ----------------------------------------------------------------------------
2959 // ----------------------------------------------------------------------------
2963 #include "wx/wfstream.h"
2964 #include "wx/mstream.h"
2966 static void TestFileStream()
2968 puts("*** Testing wxFileInputStream ***");
2970 static const wxChar
*filename
= _T("testdata.fs");
2972 wxFileOutputStream
fsOut(filename
);
2973 fsOut
.Write("foo", 3);
2976 wxFileInputStream
fsIn(filename
);
2977 printf("File stream size: %u\n", fsIn
.GetSize());
2978 while ( !fsIn
.Eof() )
2980 putchar(fsIn
.GetC());
2983 if ( !wxRemoveFile(filename
) )
2985 printf("ERROR: failed to remove the file '%s'.\n", filename
);
2988 puts("\n*** wxFileInputStream test done ***");
2991 static void TestMemoryStream()
2993 puts("*** Testing wxMemoryInputStream ***");
2996 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
2998 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
2999 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3000 while ( !memInpStream
.Eof() )
3002 putchar(memInpStream
.GetC());
3005 puts("\n*** wxMemoryInputStream test done ***");
3008 #endif // TEST_STREAMS
3010 // ----------------------------------------------------------------------------
3012 // ----------------------------------------------------------------------------
3016 #include "wx/timer.h"
3017 #include "wx/utils.h"
3019 static void TestStopWatch()
3021 puts("*** Testing wxStopWatch ***\n");
3024 printf("Sleeping 3 seconds...");
3026 printf("\telapsed time: %ldms\n", sw
.Time());
3029 printf("Sleeping 2 more seconds...");
3031 printf("\telapsed time: %ldms\n", sw
.Time());
3034 printf("And 3 more seconds...");
3036 printf("\telapsed time: %ldms\n", sw
.Time());
3039 puts("\nChecking for 'backwards clock' bug...");
3040 for ( size_t n
= 0; n
< 70; n
++ )
3044 for ( size_t m
= 0; m
< 100000; m
++ )
3046 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3048 puts("\ntime is negative - ERROR!");
3058 #endif // TEST_TIMER
3060 // ----------------------------------------------------------------------------
3062 // ----------------------------------------------------------------------------
3066 #include "wx/vcard.h"
3068 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3071 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3075 wxString(_T('\t'), level
).c_str(),
3076 vcObj
->GetName().c_str());
3079 switch ( vcObj
->GetType() )
3081 case wxVCardObject::String
:
3082 case wxVCardObject::UString
:
3085 vcObj
->GetValue(&val
);
3086 value
<< _T('"') << val
<< _T('"');
3090 case wxVCardObject::Int
:
3093 vcObj
->GetValue(&i
);
3094 value
.Printf(_T("%u"), i
);
3098 case wxVCardObject::Long
:
3101 vcObj
->GetValue(&l
);
3102 value
.Printf(_T("%lu"), l
);
3106 case wxVCardObject::None
:
3109 case wxVCardObject::Object
:
3110 value
= _T("<node>");
3114 value
= _T("<unknown value type>");
3118 printf(" = %s", value
.c_str());
3121 DumpVObject(level
+ 1, *vcObj
);
3124 vcObj
= vcard
.GetNextProp(&cookie
);
3128 static void DumpVCardAddresses(const wxVCard
& vcard
)
3130 puts("\nShowing all addresses from vCard:\n");
3134 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3138 int flags
= addr
->GetFlags();
3139 if ( flags
& wxVCardAddress::Domestic
)
3141 flagsStr
<< _T("domestic ");
3143 if ( flags
& wxVCardAddress::Intl
)
3145 flagsStr
<< _T("international ");
3147 if ( flags
& wxVCardAddress::Postal
)
3149 flagsStr
<< _T("postal ");
3151 if ( flags
& wxVCardAddress::Parcel
)
3153 flagsStr
<< _T("parcel ");
3155 if ( flags
& wxVCardAddress::Home
)
3157 flagsStr
<< _T("home ");
3159 if ( flags
& wxVCardAddress::Work
)
3161 flagsStr
<< _T("work ");
3164 printf("Address %u:\n"
3166 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3169 addr
->GetPostOffice().c_str(),
3170 addr
->GetExtAddress().c_str(),
3171 addr
->GetStreet().c_str(),
3172 addr
->GetLocality().c_str(),
3173 addr
->GetRegion().c_str(),
3174 addr
->GetPostalCode().c_str(),
3175 addr
->GetCountry().c_str()
3179 addr
= vcard
.GetNextAddress(&cookie
);
3183 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3185 puts("\nShowing all phone numbers from vCard:\n");
3189 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3193 int flags
= phone
->GetFlags();
3194 if ( flags
& wxVCardPhoneNumber::Voice
)
3196 flagsStr
<< _T("voice ");
3198 if ( flags
& wxVCardPhoneNumber::Fax
)
3200 flagsStr
<< _T("fax ");
3202 if ( flags
& wxVCardPhoneNumber::Cellular
)
3204 flagsStr
<< _T("cellular ");
3206 if ( flags
& wxVCardPhoneNumber::Modem
)
3208 flagsStr
<< _T("modem ");
3210 if ( flags
& wxVCardPhoneNumber::Home
)
3212 flagsStr
<< _T("home ");
3214 if ( flags
& wxVCardPhoneNumber::Work
)
3216 flagsStr
<< _T("work ");
3219 printf("Phone number %u:\n"
3224 phone
->GetNumber().c_str()
3228 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3232 static void TestVCardRead()
3234 puts("*** Testing wxVCard reading ***\n");
3236 wxVCard
vcard(_T("vcard.vcf"));
3237 if ( !vcard
.IsOk() )
3239 puts("ERROR: couldn't load vCard.");
3243 // read individual vCard properties
3244 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3248 vcObj
->GetValue(&value
);
3253 value
= _T("<none>");
3256 printf("Full name retrieved directly: %s\n", value
.c_str());
3259 if ( !vcard
.GetFullName(&value
) )
3261 value
= _T("<none>");
3264 printf("Full name from wxVCard API: %s\n", value
.c_str());
3266 // now show how to deal with multiply occuring properties
3267 DumpVCardAddresses(vcard
);
3268 DumpVCardPhoneNumbers(vcard
);
3270 // and finally show all
3271 puts("\nNow dumping the entire vCard:\n"
3272 "-----------------------------\n");
3274 DumpVObject(0, vcard
);
3278 static void TestVCardWrite()
3280 puts("*** Testing wxVCard writing ***\n");
3283 if ( !vcard
.IsOk() )
3285 puts("ERROR: couldn't create vCard.");
3290 vcard
.SetName("Zeitlin", "Vadim");
3291 vcard
.SetFullName("Vadim Zeitlin");
3292 vcard
.SetOrganization("wxWindows", "R&D");
3294 // just dump the vCard back
3295 puts("Entire vCard follows:\n");
3296 puts(vcard
.Write());
3300 #endif // TEST_VCARD
3302 // ----------------------------------------------------------------------------
3304 // ----------------------------------------------------------------------------
3312 #include "wx/volume.h"
3314 static const wxChar
*volumeKinds
[] =
3320 _T("network volume"),
3324 static void TestFSVolume()
3326 wxPuts(_T("*** Testing wxFSVolume class ***"));
3328 wxArrayString volumes
= wxFSVolume::GetVolumes();
3329 size_t count
= volumes
.GetCount();
3333 wxPuts(_T("ERROR: no mounted volumes?"));
3337 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3339 for ( size_t n
= 0; n
< count
; n
++ )
3341 wxFSVolume
vol(volumes
[n
]);
3344 wxPuts(_T("ERROR: couldn't create volume"));
3348 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3350 vol
.GetDisplayName().c_str(),
3351 vol
.GetName().c_str(),
3352 volumeKinds
[vol
.GetKind()],
3353 vol
.IsWritable() ? _T("rw") : _T("ro"),
3354 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3359 #endif // TEST_VOLUME
3361 // ----------------------------------------------------------------------------
3362 // wide char (Unicode) support
3363 // ----------------------------------------------------------------------------
3367 #include "wx/strconv.h"
3368 #include "wx/fontenc.h"
3369 #include "wx/encconv.h"
3370 #include "wx/buffer.h"
3372 static const char textInUtf8
[] =
3374 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3375 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3376 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3377 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3378 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3379 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3380 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3383 static void TestUtf8()
3385 puts("*** Testing UTF8 support ***\n");
3389 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
3391 puts("ERROR: UTF-8 decoding failed.");
3395 wxCSConv
conv(_T("koi8-r"));
3396 if ( conv
.WC2MB(buf
, wbuf
, 0 /* not needed wcslen(wbuf) */) <= 0 )
3398 puts("ERROR: conversion to KOI8-R failed.");
3402 printf("The resulting string (in KOI8-R): %s\n", buf
);
3406 if ( wxConvUTF8
.WC2MB(buf
, L
"Ã la", WXSIZEOF(buf
)) <= 0 )
3408 puts("ERROR: conversion to UTF-8 failed.");
3412 printf("The string in UTF-8: %s\n", buf
);
3418 static void TestEncodingConverter()
3420 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3422 // using wxEncodingConverter should give the same result as above
3425 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
3427 puts("ERROR: UTF-8 decoding failed.");
3431 wxEncodingConverter ec
;
3432 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3433 ec
.Convert(wbuf
, buf
);
3434 printf("The same string obtained using wxEC: %s\n", buf
);
3440 #endif // TEST_WCHAR
3442 // ----------------------------------------------------------------------------
3444 // ----------------------------------------------------------------------------
3448 #include "wx/filesys.h"
3449 #include "wx/fs_zip.h"
3450 #include "wx/zipstrm.h"
3452 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3454 static void TestZipStreamRead()
3456 puts("*** Testing ZIP reading ***\n");
3458 static const wxChar
*filename
= _T("foo");
3459 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3460 printf("Archive size: %u\n", istr
.GetSize());
3462 printf("Dumping the file '%s':\n", filename
);
3463 while ( !istr
.Eof() )
3465 putchar(istr
.GetC());
3469 puts("\n----- done ------");
3472 static void DumpZipDirectory(wxFileSystem
& fs
,
3473 const wxString
& dir
,
3474 const wxString
& indent
)
3476 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3477 TESTFILE_ZIP
, dir
.c_str());
3478 wxString wildcard
= prefix
+ _T("/*");
3480 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3481 while ( !dirname
.empty() )
3483 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3485 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3490 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3492 DumpZipDirectory(fs
, dirname
,
3493 indent
+ wxString(_T(' '), 4));
3495 dirname
= fs
.FindNext();
3498 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3499 while ( !filename
.empty() )
3501 if ( !filename
.StartsWith(prefix
, &filename
) )
3503 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3508 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3510 filename
= fs
.FindNext();
3514 static void TestZipFileSystem()
3516 puts("*** Testing ZIP file system ***\n");
3518 wxFileSystem::AddHandler(new wxZipFSHandler
);
3520 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3522 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3527 // ----------------------------------------------------------------------------
3529 // ----------------------------------------------------------------------------
3533 #include "wx/zstream.h"
3534 #include "wx/wfstream.h"
3536 static const wxChar
*FILENAME_GZ
= _T("test.gz");
3537 static const char *TEST_DATA
= "hello and hello again";
3539 static void TestZlibStreamWrite()
3541 puts("*** Testing Zlib stream reading ***\n");
3543 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
3544 wxZlibOutputStream
ostr(fileOutStream
, 0);
3545 printf("Compressing the test string... ");
3546 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
3549 puts("(ERROR: failed)");
3556 puts("\n----- done ------");
3559 static void TestZlibStreamRead()
3561 puts("*** Testing Zlib stream reading ***\n");
3563 wxFileInputStream
fileInStream(FILENAME_GZ
);
3564 wxZlibInputStream
istr(fileInStream
);
3565 printf("Archive size: %u\n", istr
.GetSize());
3567 puts("Dumping the file:");
3568 while ( !istr
.Eof() )
3570 putchar(istr
.GetC());
3574 puts("\n----- done ------");
3579 // ----------------------------------------------------------------------------
3581 // ----------------------------------------------------------------------------
3583 #ifdef TEST_DATETIME
3587 #include "wx/date.h"
3588 #include "wx/datetime.h"
3593 wxDateTime::wxDateTime_t day
;
3594 wxDateTime::Month month
;
3596 wxDateTime::wxDateTime_t hour
, min
, sec
;
3598 wxDateTime::WeekDay wday
;
3599 time_t gmticks
, ticks
;
3601 void Init(const wxDateTime::Tm
& tm
)
3610 gmticks
= ticks
= -1;
3613 wxDateTime
DT() const
3614 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
3616 bool SameDay(const wxDateTime::Tm
& tm
) const
3618 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
3621 wxString
Format() const
3624 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
3626 wxDateTime::GetMonthName(month
).c_str(),
3628 abs(wxDateTime::ConvertYearToBC(year
)),
3629 year
> 0 ? "AD" : "BC");
3633 wxString
FormatDate() const
3636 s
.Printf("%02d-%s-%4d%s",
3638 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3639 abs(wxDateTime::ConvertYearToBC(year
)),
3640 year
> 0 ? "AD" : "BC");
3645 static const Date testDates
[] =
3647 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
3648 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
3649 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
3650 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
3651 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
3652 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
3653 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
3654 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
3655 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
3656 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
3657 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
3658 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
3659 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
3660 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
3661 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
3664 // this test miscellaneous static wxDateTime functions
3665 static void TestTimeStatic()
3667 puts("\n*** wxDateTime static methods test ***");
3669 // some info about the current date
3670 int year
= wxDateTime::GetCurrentYear();
3671 printf("Current year %d is %sa leap one and has %d days.\n",
3673 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3674 wxDateTime::GetNumberOfDays(year
));
3676 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3677 printf("Current month is '%s' ('%s') and it has %d days\n",
3678 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3679 wxDateTime::GetMonthName(month
).c_str(),
3680 wxDateTime::GetNumberOfDays(month
));
3683 static const size_t nYears
= 5;
3684 static const size_t years
[2][nYears
] =
3686 // first line: the years to test
3687 { 1990, 1976, 2000, 2030, 1984, },
3689 // second line: TRUE if leap, FALSE otherwise
3690 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
3693 for ( size_t n
= 0; n
< nYears
; n
++ )
3695 int year
= years
[0][n
];
3696 bool should
= years
[1][n
] != 0,
3697 is
= wxDateTime::IsLeapYear(year
);
3699 printf("Year %d is %sa leap year (%s)\n",
3702 should
== is
? "ok" : "ERROR");
3704 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
3708 // test constructing wxDateTime objects
3709 static void TestTimeSet()
3711 puts("\n*** wxDateTime construction test ***");
3713 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3715 const Date
& d1
= testDates
[n
];
3716 wxDateTime dt
= d1
.DT();
3719 d2
.Init(dt
.GetTm());
3721 wxString s1
= d1
.Format(),
3724 printf("Date: %s == %s (%s)\n",
3725 s1
.c_str(), s2
.c_str(),
3726 s1
== s2
? "ok" : "ERROR");
3730 // test time zones stuff
3731 static void TestTimeZones()
3733 puts("\n*** wxDateTime timezone test ***");
3735 wxDateTime now
= wxDateTime::Now();
3737 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
3738 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
3739 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
3740 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
3741 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
3742 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
3744 wxDateTime::Tm tm
= now
.GetTm();
3745 if ( wxDateTime(tm
) != now
)
3747 printf("ERROR: got %s instead of %s\n",
3748 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3752 // test some minimal support for the dates outside the standard range
3753 static void TestTimeRange()
3755 puts("\n*** wxDateTime out-of-standard-range dates test ***");
3757 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
3759 printf("Unix epoch:\t%s\n",
3760 wxDateTime(2440587.5).Format(fmt
).c_str());
3761 printf("Feb 29, 0: \t%s\n",
3762 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3763 printf("JDN 0: \t%s\n",
3764 wxDateTime(0.0).Format(fmt
).c_str());
3765 printf("Jan 1, 1AD:\t%s\n",
3766 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3767 printf("May 29, 2099:\t%s\n",
3768 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3771 static void TestTimeTicks()
3773 puts("\n*** wxDateTime ticks test ***");
3775 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3777 const Date
& d
= testDates
[n
];
3778 if ( d
.ticks
== -1 )
3781 wxDateTime dt
= d
.DT();
3782 long ticks
= (dt
.GetValue() / 1000).ToLong();
3783 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3784 if ( ticks
== d
.ticks
)
3790 printf(" (ERROR: should be %ld, delta = %ld)\n",
3791 d
.ticks
, ticks
- d
.ticks
);
3794 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
3795 ticks
= (dt
.GetValue() / 1000).ToLong();
3796 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3797 if ( ticks
== d
.gmticks
)
3803 printf(" (ERROR: should be %ld, delta = %ld)\n",
3804 d
.gmticks
, ticks
- d
.gmticks
);
3811 // test conversions to JDN &c
3812 static void TestTimeJDN()
3814 puts("\n*** wxDateTime to JDN test ***");
3816 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3818 const Date
& d
= testDates
[n
];
3819 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3820 double jdn
= dt
.GetJulianDayNumber();
3822 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
3829 printf(" (ERROR: should be %f, delta = %f)\n",
3830 d
.jdn
, jdn
- d
.jdn
);
3835 // test week days computation
3836 static void TestTimeWDays()
3838 puts("\n*** wxDateTime weekday test ***");
3840 // test GetWeekDay()
3842 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3844 const Date
& d
= testDates
[n
];
3845 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3847 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
3850 wxDateTime::GetWeekDayName(wday
).c_str());
3851 if ( wday
== d
.wday
)
3857 printf(" (ERROR: should be %s)\n",
3858 wxDateTime::GetWeekDayName(d
.wday
).c_str());
3864 // test SetToWeekDay()
3865 struct WeekDateTestData
3867 Date date
; // the real date (precomputed)
3868 int nWeek
; // its week index in the month
3869 wxDateTime::WeekDay wday
; // the weekday
3870 wxDateTime::Month month
; // the month
3871 int year
; // and the year
3873 wxString
Format() const
3876 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
3878 case 1: which
= "first"; break;
3879 case 2: which
= "second"; break;
3880 case 3: which
= "third"; break;
3881 case 4: which
= "fourth"; break;
3882 case 5: which
= "fifth"; break;
3884 case -1: which
= "last"; break;
3889 which
+= " from end";
3892 s
.Printf("The %s %s of %s in %d",
3894 wxDateTime::GetWeekDayName(wday
).c_str(),
3895 wxDateTime::GetMonthName(month
).c_str(),
3902 // the array data was generated by the following python program
3904 from DateTime import *
3905 from whrandom import *
3906 from string import *
3908 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3909 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3911 week = DateTimeDelta(7)
3914 year = randint(1900, 2100)
3915 month = randint(1, 12)
3916 day = randint(1, 28)
3917 dt = DateTime(year, month, day)
3918 wday = dt.day_of_week
3920 countFromEnd = choice([-1, 1])
3923 while dt.month is month:
3924 dt = dt - countFromEnd * week
3925 weekNum = weekNum + countFromEnd
3927 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
3929 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
3930 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
3933 static const WeekDateTestData weekDatesTestData
[] =
3935 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
3936 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
3937 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
3938 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
3939 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
3940 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
3941 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
3942 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
3943 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
3944 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
3945 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
3946 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
3947 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
3948 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
3949 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
3950 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
3951 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
3952 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
3953 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
3954 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
3957 static const char *fmt
= "%d-%b-%Y";
3960 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
3962 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
3964 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
3966 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
3968 const Date
& d
= wd
.date
;
3969 if ( d
.SameDay(dt
.GetTm()) )
3975 dt
.Set(d
.day
, d
.month
, d
.year
);
3977 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
3982 // test the computation of (ISO) week numbers
3983 static void TestTimeWNumber()
3985 puts("\n*** wxDateTime week number test ***");
3987 struct WeekNumberTestData
3989 Date date
; // the date
3990 wxDateTime::wxDateTime_t week
; // the week number in the year
3991 wxDateTime::wxDateTime_t wmon
; // the week number in the month
3992 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
3993 wxDateTime::wxDateTime_t dnum
; // day number in the year
3996 // data generated with the following python script:
3998 from DateTime import *
3999 from whrandom import *
4000 from string import *
4002 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4003 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4005 def GetMonthWeek(dt):
4006 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
4007 if weekNumMonth < 0:
4008 weekNumMonth = weekNumMonth + 53
4011 def GetLastSundayBefore(dt):
4012 if dt.iso_week[2] == 7:
4015 return dt - DateTimeDelta(dt.iso_week[2])
4018 year = randint(1900, 2100)
4019 month = randint(1, 12)
4020 day = randint(1, 28)
4021 dt = DateTime(year, month, day)
4022 dayNum = dt.day_of_year
4023 weekNum = dt.iso_week[1]
4024 weekNumMonth = GetMonthWeek(dt)
4027 dtSunday = GetLastSundayBefore(dt)
4029 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
4030 weekNumMonth2 = weekNumMonth2 + 1
4031 dtSunday = dtSunday - DateTimeDelta(7)
4033 data = { 'day': rjust(`day`, 2), \
4034 'month': monthNames[month - 1], \
4036 'weekNum': rjust(`weekNum`, 2), \
4037 'weekNumMonth': weekNumMonth, \
4038 'weekNumMonth2': weekNumMonth2, \
4039 'dayNum': rjust(`dayNum`, 3) }
4041 print " { { %(day)s, "\
4042 "wxDateTime::%(month)s, "\
4045 "%(weekNumMonth)s, "\
4046 "%(weekNumMonth2)s, "\
4047 "%(dayNum)s }," % data
4050 static const WeekNumberTestData weekNumberTestDates
[] =
4052 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
4053 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
4054 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
4055 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
4056 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
4057 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
4058 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
4059 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
4060 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
4061 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
4062 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
4063 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
4064 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
4065 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
4066 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
4067 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
4068 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
4069 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
4070 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
4071 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
4074 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
4076 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
4077 const Date
& d
= wn
.date
;
4079 wxDateTime dt
= d
.DT();
4081 wxDateTime::wxDateTime_t
4082 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
4083 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4084 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4085 dnum
= dt
.GetDayOfYear();
4087 printf("%s: the day number is %d",
4088 d
.FormatDate().c_str(), dnum
);
4089 if ( dnum
== wn
.dnum
)
4095 printf(" (ERROR: should be %d)", wn
.dnum
);
4098 printf(", week in month is %d", wmon
);
4099 if ( wmon
== wn
.wmon
)
4105 printf(" (ERROR: should be %d)", wn
.wmon
);
4108 printf(" or %d", wmon2
);
4109 if ( wmon2
== wn
.wmon2
)
4115 printf(" (ERROR: should be %d)", wn
.wmon2
);
4118 printf(", week in year is %d", week
);
4119 if ( week
== wn
.week
)
4125 printf(" (ERROR: should be %d)\n", wn
.week
);
4130 // test DST calculations
4131 static void TestTimeDST()
4133 puts("\n*** wxDateTime DST test ***");
4135 printf("DST is%s in effect now.\n\n",
4136 wxDateTime::Now().IsDST() ? "" : " not");
4138 // taken from http://www.energy.ca.gov/daylightsaving.html
4139 static const Date datesDST
[2][2004 - 1900 + 1] =
4142 { 1, wxDateTime::Apr
, 1990 },
4143 { 7, wxDateTime::Apr
, 1991 },
4144 { 5, wxDateTime::Apr
, 1992 },
4145 { 4, wxDateTime::Apr
, 1993 },
4146 { 3, wxDateTime::Apr
, 1994 },
4147 { 2, wxDateTime::Apr
, 1995 },
4148 { 7, wxDateTime::Apr
, 1996 },
4149 { 6, wxDateTime::Apr
, 1997 },
4150 { 5, wxDateTime::Apr
, 1998 },
4151 { 4, wxDateTime::Apr
, 1999 },
4152 { 2, wxDateTime::Apr
, 2000 },
4153 { 1, wxDateTime::Apr
, 2001 },
4154 { 7, wxDateTime::Apr
, 2002 },
4155 { 6, wxDateTime::Apr
, 2003 },
4156 { 4, wxDateTime::Apr
, 2004 },
4159 { 28, wxDateTime::Oct
, 1990 },
4160 { 27, wxDateTime::Oct
, 1991 },
4161 { 25, wxDateTime::Oct
, 1992 },
4162 { 31, wxDateTime::Oct
, 1993 },
4163 { 30, wxDateTime::Oct
, 1994 },
4164 { 29, wxDateTime::Oct
, 1995 },
4165 { 27, wxDateTime::Oct
, 1996 },
4166 { 26, wxDateTime::Oct
, 1997 },
4167 { 25, wxDateTime::Oct
, 1998 },
4168 { 31, wxDateTime::Oct
, 1999 },
4169 { 29, wxDateTime::Oct
, 2000 },
4170 { 28, wxDateTime::Oct
, 2001 },
4171 { 27, wxDateTime::Oct
, 2002 },
4172 { 26, wxDateTime::Oct
, 2003 },
4173 { 31, wxDateTime::Oct
, 2004 },
4178 for ( year
= 1990; year
< 2005; year
++ )
4180 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
4181 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
4183 printf("DST period in the US for year %d: from %s to %s",
4184 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
4186 size_t n
= year
- 1990;
4187 const Date
& dBegin
= datesDST
[0][n
];
4188 const Date
& dEnd
= datesDST
[1][n
];
4190 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
4196 printf(" (ERROR: should be %s %d to %s %d)\n",
4197 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
4198 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
4204 for ( year
= 1990; year
< 2005; year
++ )
4206 printf("DST period in Europe for year %d: from %s to %s\n",
4208 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
4209 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
4213 // test wxDateTime -> text conversion
4214 static void TestTimeFormat()
4216 puts("\n*** wxDateTime formatting test ***");
4218 // some information may be lost during conversion, so store what kind
4219 // of info should we recover after a round trip
4222 CompareNone
, // don't try comparing
4223 CompareBoth
, // dates and times should be identical
4224 CompareDate
, // dates only
4225 CompareTime
// time only
4230 CompareKind compareKind
;
4232 } formatTestFormats
[] =
4234 { CompareBoth
, "---> %c" },
4235 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
4236 { CompareBoth
, "Date is %x, time is %X" },
4237 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
4238 { CompareNone
, "The day of year: %j, the week of year: %W" },
4239 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
4242 static const Date formatTestDates
[] =
4244 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
4245 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
4247 // this test can't work for other centuries because it uses two digit
4248 // years in formats, so don't even try it
4249 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
4250 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
4251 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
4255 // an extra test (as it doesn't depend on date, don't do it in the loop)
4256 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
4258 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
4262 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
4263 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
4265 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
4266 printf("%s", s
.c_str());
4268 // what can we recover?
4269 int kind
= formatTestFormats
[n
].compareKind
;
4273 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
4276 // converion failed - should it have?
4277 if ( kind
== CompareNone
)
4280 puts(" (ERROR: conversion back failed)");
4284 // should have parsed the entire string
4285 puts(" (ERROR: conversion back stopped too soon)");
4289 bool equal
= FALSE
; // suppress compilaer warning
4297 equal
= dt
.IsSameDate(dt2
);
4301 equal
= dt
.IsSameTime(dt2
);
4307 printf(" (ERROR: got back '%s' instead of '%s')\n",
4308 dt2
.Format().c_str(), dt
.Format().c_str());
4319 // test text -> wxDateTime conversion
4320 static void TestTimeParse()
4322 puts("\n*** wxDateTime parse test ***");
4324 struct ParseTestData
4331 static const ParseTestData parseTestDates
[] =
4333 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
4334 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
4337 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
4339 const char *format
= parseTestDates
[n
].format
;
4341 printf("%s => ", format
);
4344 if ( dt
.ParseRfc822Date(format
) )
4346 printf("%s ", dt
.Format().c_str());
4348 if ( parseTestDates
[n
].good
)
4350 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
4357 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
4362 puts("(ERROR: bad format)");
4367 printf("bad format (%s)\n",
4368 parseTestDates
[n
].good
? "ERROR" : "ok");
4373 static void TestDateTimeInteractive()
4375 puts("\n*** interactive wxDateTime tests ***");
4381 printf("Enter a date: ");
4382 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
4385 // kill the last '\n'
4386 buf
[strlen(buf
) - 1] = 0;
4389 const char *p
= dt
.ParseDate(buf
);
4392 printf("ERROR: failed to parse the date '%s'.\n", buf
);
4398 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
4401 printf("%s: day %u, week of month %u/%u, week of year %u\n",
4402 dt
.Format("%b %d, %Y").c_str(),
4404 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4405 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4406 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
4409 puts("\n*** done ***");
4412 static void TestTimeMS()
4414 puts("*** testing millisecond-resolution support in wxDateTime ***");
4416 wxDateTime dt1
= wxDateTime::Now(),
4417 dt2
= wxDateTime::UNow();
4419 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
4420 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4421 printf("Dummy loop: ");
4422 for ( int i
= 0; i
< 6000; i
++ )
4424 //for ( int j = 0; j < 10; j++ )
4427 s
.Printf("%g", sqrt(i
));
4436 dt2
= wxDateTime::UNow();
4437 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
4439 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
4441 puts("\n*** done ***");
4444 static void TestTimeArithmetics()
4446 puts("\n*** testing arithmetic operations on wxDateTime ***");
4448 static const struct ArithmData
4450 ArithmData(const wxDateSpan
& sp
, const char *nam
)
4451 : span(sp
), name(nam
) { }
4455 } testArithmData
[] =
4457 ArithmData(wxDateSpan::Day(), "day"),
4458 ArithmData(wxDateSpan::Week(), "week"),
4459 ArithmData(wxDateSpan::Month(), "month"),
4460 ArithmData(wxDateSpan::Year(), "year"),
4461 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
4464 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
4466 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
4468 wxDateSpan span
= testArithmData
[n
].span
;
4472 const char *name
= testArithmData
[n
].name
;
4473 printf("%s + %s = %s, %s - %s = %s\n",
4474 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
4475 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
4477 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
4478 if ( dt1
- span
== dt
)
4484 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4487 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
4488 if ( dt2
+ span
== dt
)
4494 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
4497 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
4498 if ( dt2
+ 2*span
== dt1
)
4504 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
4511 static void TestTimeHolidays()
4513 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
4515 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
4516 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
4517 dtEnd
= dtStart
.GetLastMonthDay();
4519 wxDateTimeArray hol
;
4520 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
4522 const wxChar
*format
= "%d-%b-%Y (%a)";
4524 printf("All holidays between %s and %s:\n",
4525 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
4527 size_t count
= hol
.GetCount();
4528 for ( size_t n
= 0; n
< count
; n
++ )
4530 printf("\t%s\n", hol
[n
].Format(format
).c_str());
4536 static void TestTimeZoneBug()
4538 puts("\n*** testing for DST/timezone bug ***\n");
4540 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
4541 for ( int i
= 0; i
< 31; i
++ )
4543 printf("Date %s: week day %s.\n",
4544 date
.Format(_T("%d-%m-%Y")).c_str(),
4545 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
4547 date
+= wxDateSpan::Day();
4553 static void TestTimeSpanFormat()
4555 puts("\n*** wxTimeSpan tests ***");
4557 static const char *formats
[] =
4559 _T("(default) %H:%M:%S"),
4560 _T("%E weeks and %D days"),
4561 _T("%l milliseconds"),
4562 _T("(with ms) %H:%M:%S:%l"),
4563 _T("100%% of minutes is %M"), // test "%%"
4564 _T("%D days and %H hours"),
4565 _T("or also %S seconds"),
4568 wxTimeSpan
ts1(1, 2, 3, 4),
4570 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
4572 printf("ts1 = %s\tts2 = %s\n",
4573 ts1
.Format(formats
[n
]).c_str(),
4574 ts2
.Format(formats
[n
]).c_str());
4582 // test compatibility with the old wxDate/wxTime classes
4583 static void TestTimeCompatibility()
4585 puts("\n*** wxDateTime compatibility test ***");
4587 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
4588 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
4590 double jdnNow
= wxDateTime::Now().GetJDN();
4591 long jdnMidnight
= (long)(jdnNow
- 0.5);
4592 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
4594 jdnMidnight
= wxDate().Set().GetJulianDate();
4595 printf("wxDateTime for today: %s\n",
4596 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
4598 int flags
= wxEUROPEAN
;//wxFULL;
4601 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
4602 for ( int n
= 0; n
< 7; n
++ )
4604 printf("Previous %s is %s\n",
4605 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
4606 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
4612 #endif // TEST_DATETIME
4614 // ----------------------------------------------------------------------------
4616 // ----------------------------------------------------------------------------
4620 #include "wx/thread.h"
4622 static size_t gs_counter
= (size_t)-1;
4623 static wxCriticalSection gs_critsect
;
4624 static wxCondition gs_cond
;
4626 class MyJoinableThread
: public wxThread
4629 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
4630 { m_n
= n
; Create(); }
4632 // thread execution starts here
4633 virtual ExitCode
Entry();
4639 wxThread::ExitCode
MyJoinableThread::Entry()
4641 unsigned long res
= 1;
4642 for ( size_t n
= 1; n
< m_n
; n
++ )
4646 // it's a loooong calculation :-)
4650 return (ExitCode
)res
;
4653 class MyDetachedThread
: public wxThread
4656 MyDetachedThread(size_t n
, char ch
)
4660 m_cancelled
= FALSE
;
4665 // thread execution starts here
4666 virtual ExitCode
Entry();
4669 virtual void OnExit();
4672 size_t m_n
; // number of characters to write
4673 char m_ch
; // character to write
4675 bool m_cancelled
; // FALSE if we exit normally
4678 wxThread::ExitCode
MyDetachedThread::Entry()
4681 wxCriticalSectionLocker
lock(gs_critsect
);
4682 if ( gs_counter
== (size_t)-1 )
4688 for ( size_t n
= 0; n
< m_n
; n
++ )
4690 if ( TestDestroy() )
4700 wxThread::Sleep(100);
4706 void MyDetachedThread::OnExit()
4708 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
4710 wxCriticalSectionLocker
lock(gs_critsect
);
4711 if ( !--gs_counter
&& !m_cancelled
)
4715 static void TestDetachedThreads()
4717 puts("\n*** Testing detached threads ***");
4719 static const size_t nThreads
= 3;
4720 MyDetachedThread
*threads
[nThreads
];
4722 for ( n
= 0; n
< nThreads
; n
++ )
4724 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
4727 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
4728 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
4730 for ( n
= 0; n
< nThreads
; n
++ )
4735 // wait until all threads terminate
4741 static void TestJoinableThreads()
4743 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
4745 // calc 10! in the background
4746 MyJoinableThread
thread(10);
4749 printf("\nThread terminated with exit code %lu.\n",
4750 (unsigned long)thread
.Wait());
4753 static void TestThreadSuspend()
4755 puts("\n*** Testing thread suspend/resume functions ***");
4757 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4761 // this is for this demo only, in a real life program we'd use another
4762 // condition variable which would be signaled from wxThread::Entry() to
4763 // tell us that the thread really started running - but here just wait a
4764 // bit and hope that it will be enough (the problem is, of course, that
4765 // the thread might still not run when we call Pause() which will result
4767 wxThread::Sleep(300);
4769 for ( size_t n
= 0; n
< 3; n
++ )
4773 puts("\nThread suspended");
4776 // don't sleep but resume immediately the first time
4777 wxThread::Sleep(300);
4779 puts("Going to resume the thread");
4784 puts("Waiting until it terminates now");
4786 // wait until the thread terminates
4792 static void TestThreadDelete()
4794 // As above, using Sleep() is only for testing here - we must use some
4795 // synchronisation object instead to ensure that the thread is still
4796 // running when we delete it - deleting a detached thread which already
4797 // terminated will lead to a crash!
4799 puts("\n*** Testing thread delete function ***");
4801 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4805 puts("\nDeleted a thread which didn't start to run yet.");
4807 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4811 wxThread::Sleep(300);
4815 puts("\nDeleted a running thread.");
4817 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4821 wxThread::Sleep(300);
4827 puts("\nDeleted a sleeping thread.");
4829 MyJoinableThread
thread3(20);
4834 puts("\nDeleted a joinable thread.");
4836 MyJoinableThread
thread4(2);
4839 wxThread::Sleep(300);
4843 puts("\nDeleted a joinable thread which already terminated.");
4848 class MyWaitingThread
: public wxThread
4851 MyWaitingThread(wxCondition
*condition
)
4853 m_condition
= condition
;
4858 virtual ExitCode
Entry()
4860 printf("Thread %lu has started running.\n", GetId());
4865 printf("Thread %lu starts to wait...\n", GetId());
4868 m_condition
->Wait();
4870 printf("Thread %lu finished to wait, exiting.\n", GetId());
4877 wxCondition
*m_condition
;
4880 static void TestThreadConditions()
4882 wxCondition condition
;
4884 // otherwise its difficult to understand which log messages pertain to
4886 wxLogTrace("thread", "Local condition var is %08x, gs_cond = %08x",
4887 condition
.GetId(), gs_cond
.GetId());
4889 // create and launch threads
4890 MyWaitingThread
*threads
[10];
4893 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4895 threads
[n
] = new MyWaitingThread(&condition
);
4898 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4903 // wait until all threads run
4904 puts("Main thread is waiting for the other threads to start");
4907 size_t nRunning
= 0;
4908 while ( nRunning
< WXSIZEOF(threads
) )
4914 printf("Main thread: %u already running\n", nRunning
);
4918 puts("Main thread: all threads started up.");
4921 wxThread::Sleep(500);
4924 // now wake one of them up
4925 printf("Main thread: about to signal the condition.\n");
4930 wxThread::Sleep(200);
4932 // wake all the (remaining) threads up, so that they can exit
4933 printf("Main thread: about to broadcast the condition.\n");
4935 condition
.Broadcast();
4937 // give them time to terminate (dirty!)
4938 wxThread::Sleep(500);
4941 #endif // TEST_THREADS
4943 // ----------------------------------------------------------------------------
4945 // ----------------------------------------------------------------------------
4949 #include "wx/dynarray.h"
4951 #define DefineCompare(name, T) \
4953 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
4955 return first - second; \
4958 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
4960 return *first - *second; \
4963 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
4965 return *second - *first; \
4968 DefineCompare(Short, short);
4969 DefineCompare(Int
, int);
4971 // test compilation of all macros
4972 WX_DEFINE_ARRAY(short, wxArrayShort
);
4973 WX_DEFINE_SORTED_ARRAY(short, wxSortedArrayShortNoCmp
);
4974 WX_DEFINE_SORTED_ARRAY_CMP(short, ShortCompareValues
, wxSortedArrayShort
);
4975 WX_DEFINE_SORTED_ARRAY_CMP(int, IntCompareValues
, wxSortedArrayInt
);
4977 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
4978 #include "wx/arrimpl.cpp"
4979 WX_DEFINE_OBJARRAY(ArrayBars
);
4981 static void PrintArray(const char* name
, const wxArrayString
& array
)
4983 printf("Dump of the array '%s'\n", name
);
4985 size_t nCount
= array
.GetCount();
4986 for ( size_t n
= 0; n
< nCount
; n
++ )
4988 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
4992 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
4993 const wxString
& second
)
4995 return first
.length() - second
.length();
4998 #define TestArrayOf(name) \
5000 static void PrintArray(const char* name, const wxSortedArray##name & array) \
5002 printf("Dump of the array '%s'\n", name); \
5004 size_t nCount = array.GetCount(); \
5005 for ( size_t n = 0; n < nCount; n++ ) \
5007 printf("\t%s[%u] = %d\n", name, n, array[n]); \
5011 static void PrintArray(const char* name, const wxArray##name & array) \
5013 printf("Dump of the array '%s'\n", name); \
5015 size_t nCount = array.GetCount(); \
5016 for ( size_t n = 0; n < nCount; n++ ) \
5018 printf("\t%s[%u] = %d\n", name, n, array[n]); \
5022 static void TestArrayOf ## name ## s() \
5024 printf("*** Testing wxArray%s ***\n", #name); \
5032 puts("Initially:"); \
5033 PrintArray("a", a); \
5035 puts("After sort:"); \
5036 a.Sort(name ## Compare); \
5037 PrintArray("a", a); \
5039 puts("After reverse sort:"); \
5040 a.Sort(name ## RevCompare); \
5041 PrintArray("a", a); \
5043 wxSortedArray##name b; \
5049 puts("Sorted array initially:"); \
5050 PrintArray("b", b); \
5056 static void TestArrayOfObjects()
5058 puts("*** Testing wxObjArray ***\n");
5062 Bar
bar("second bar");
5064 printf("Initially: %u objects in the array, %u objects total.\n",
5065 bars
.GetCount(), Bar::GetNumber());
5067 bars
.Add(new Bar("first bar"));
5070 printf("Now: %u objects in the array, %u objects total.\n",
5071 bars
.GetCount(), Bar::GetNumber());
5075 printf("After Empty(): %u objects in the array, %u objects total.\n",
5076 bars
.GetCount(), Bar::GetNumber());
5079 printf("Finally: no more objects in the array, %u objects total.\n",
5083 #endif // TEST_ARRAYS
5085 // ----------------------------------------------------------------------------
5087 // ----------------------------------------------------------------------------
5091 #include "wx/timer.h"
5092 #include "wx/tokenzr.h"
5094 static void TestStringConstruction()
5096 puts("*** Testing wxString constructores ***");
5098 #define TEST_CTOR(args, res) \
5101 printf("wxString%s = %s ", #args, s.c_str()); \
5108 printf("(ERROR: should be %s)\n", res); \
5112 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
5113 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
5114 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
5115 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
5117 static const wxChar
*s
= _T("?really!");
5118 const wxChar
*start
= wxStrchr(s
, _T('r'));
5119 const wxChar
*end
= wxStrchr(s
, _T('!'));
5120 TEST_CTOR((start
, end
), _T("really"));
5125 static void TestString()
5135 for (int i
= 0; i
< 1000000; ++i
)
5139 c
= "! How'ya doin'?";
5142 c
= "Hello world! What's up?";
5147 printf ("TestString elapsed time: %ld\n", sw
.Time());
5150 static void TestPChar()
5158 for (int i
= 0; i
< 1000000; ++i
)
5160 strcpy (a
, "Hello");
5161 strcpy (b
, " world");
5162 strcpy (c
, "! How'ya doin'?");
5165 strcpy (c
, "Hello world! What's up?");
5166 if (strcmp (c
, a
) == 0)
5170 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
5173 static void TestStringSub()
5175 wxString
s("Hello, world!");
5177 puts("*** Testing wxString substring extraction ***");
5179 printf("String = '%s'\n", s
.c_str());
5180 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
5181 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
5182 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
5183 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
5184 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
5185 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
5187 static const wxChar
*prefixes
[] =
5191 _T("Hello, world!"),
5192 _T("Hello, world!!!"),
5198 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
5200 wxString prefix
= prefixes
[n
], rest
;
5201 bool rc
= s
.StartsWith(prefix
, &rest
);
5202 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
5205 printf(" (the rest is '%s')\n", rest
.c_str());
5216 static void TestStringFormat()
5218 puts("*** Testing wxString formatting ***");
5221 s
.Printf("%03d", 18);
5223 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
5224 printf("Number 18: %s\n", s
.c_str());
5229 // returns "not found" for npos, value for all others
5230 static wxString
PosToString(size_t res
)
5232 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
5233 : wxString::Format(_T("%u"), res
);
5237 static void TestStringFind()
5239 puts("*** Testing wxString find() functions ***");
5241 static const wxChar
*strToFind
= _T("ell");
5242 static const struct StringFindTest
5246 result
; // of searching "ell" in str
5249 { _T("Well, hello world"), 0, 1 },
5250 { _T("Well, hello world"), 6, 7 },
5251 { _T("Well, hello world"), 9, wxString::npos
},
5254 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
5256 const StringFindTest
& ft
= findTestData
[n
];
5257 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
5259 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
5260 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
5262 size_t resTrue
= ft
.result
;
5263 if ( res
== resTrue
)
5269 printf(_T("(ERROR: should be %s)\n"),
5270 PosToString(resTrue
).c_str());
5277 static void TestStringTokenizer()
5279 puts("*** Testing wxStringTokenizer ***");
5281 static const wxChar
*modeNames
[] =
5285 _T("return all empty"),
5290 static const struct StringTokenizerTest
5292 const wxChar
*str
; // string to tokenize
5293 const wxChar
*delims
; // delimiters to use
5294 size_t count
; // count of token
5295 wxStringTokenizerMode mode
; // how should we tokenize it
5296 } tokenizerTestData
[] =
5298 { _T(""), _T(" "), 0 },
5299 { _T("Hello, world"), _T(" "), 2 },
5300 { _T("Hello, world "), _T(" "), 2 },
5301 { _T("Hello, world"), _T(","), 2 },
5302 { _T("Hello, world!"), _T(",!"), 2 },
5303 { _T("Hello,, world!"), _T(",!"), 3 },
5304 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
5305 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
5306 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
5307 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
5308 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
5309 { _T("01/02/99"), _T("/-"), 3 },
5310 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
5313 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
5315 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
5316 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
5318 size_t count
= tkz
.CountTokens();
5319 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
5320 MakePrintable(tt
.str
).c_str(),
5322 MakePrintable(tt
.delims
).c_str(),
5323 modeNames
[tkz
.GetMode()]);
5324 if ( count
== tt
.count
)
5330 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
5335 // if we emulate strtok(), check that we do it correctly
5336 wxChar
*buf
, *s
= NULL
, *last
;
5338 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
5340 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
5341 wxStrcpy(buf
, tt
.str
);
5343 s
= wxStrtok(buf
, tt
.delims
, &last
);
5350 // now show the tokens themselves
5352 while ( tkz
.HasMoreTokens() )
5354 wxString token
= tkz
.GetNextToken();
5356 printf(_T("\ttoken %u: '%s'"),
5358 MakePrintable(token
).c_str());
5368 printf(" (ERROR: should be %s)\n", s
);
5371 s
= wxStrtok(NULL
, tt
.delims
, &last
);
5375 // nothing to compare with
5380 if ( count2
!= count
)
5382 puts(_T("\tERROR: token count mismatch"));
5391 static void TestStringReplace()
5393 puts("*** Testing wxString::replace ***");
5395 static const struct StringReplaceTestData
5397 const wxChar
*original
; // original test string
5398 size_t start
, len
; // the part to replace
5399 const wxChar
*replacement
; // the replacement string
5400 const wxChar
*result
; // and the expected result
5401 } stringReplaceTestData
[] =
5403 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
5404 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
5405 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
5406 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
5407 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
5410 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
5412 const StringReplaceTestData data
= stringReplaceTestData
[n
];
5414 wxString original
= data
.original
;
5415 original
.replace(data
.start
, data
.len
, data
.replacement
);
5417 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
5418 data
.original
, data
.start
, data
.len
, data
.replacement
,
5421 if ( original
== data
.result
)
5427 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
5434 static void TestStringMatch()
5436 wxPuts(_T("*** Testing wxString::Matches() ***"));
5438 static const struct StringMatchTestData
5441 const wxChar
*wildcard
;
5443 } stringMatchTestData
[] =
5445 { _T("foobar"), _T("foo*"), 1 },
5446 { _T("foobar"), _T("*oo*"), 1 },
5447 { _T("foobar"), _T("*bar"), 1 },
5448 { _T("foobar"), _T("??????"), 1 },
5449 { _T("foobar"), _T("f??b*"), 1 },
5450 { _T("foobar"), _T("f?b*"), 0 },
5451 { _T("foobar"), _T("*goo*"), 0 },
5452 { _T("foobar"), _T("*foo"), 0 },
5453 { _T("foobarfoo"), _T("*foo"), 1 },
5454 { _T(""), _T("*"), 1 },
5455 { _T(""), _T("?"), 0 },
5458 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
5460 const StringMatchTestData
& data
= stringMatchTestData
[n
];
5461 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
5462 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
5464 matches
? _T("matches") : _T("doesn't match"),
5466 matches
== data
.matches
? _T("ok") : _T("ERROR"));
5472 #endif // TEST_STRINGS
5474 // ----------------------------------------------------------------------------
5476 // ----------------------------------------------------------------------------
5478 #ifdef TEST_SNGLINST
5479 #include "wx/snglinst.h"
5480 #endif // TEST_SNGLINST
5482 int main(int argc
, char **argv
)
5484 wxInitializer initializer
;
5487 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
5492 #ifdef TEST_SNGLINST
5493 wxSingleInstanceChecker checker
;
5494 if ( checker
.Create(_T(".wxconsole.lock")) )
5496 if ( checker
.IsAnotherRunning() )
5498 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
5503 // wait some time to give time to launch another instance
5504 wxPrintf(_T("Press \"Enter\" to continue..."));
5507 else // failed to create
5509 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
5511 #endif // TEST_SNGLINST
5515 #endif // TEST_CHARSET
5518 TestCmdLineConvert();
5520 #if wxUSE_CMDLINE_PARSER
5521 static const wxCmdLineEntryDesc cmdLineDesc
[] =
5523 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), "show this help message",
5524 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
5525 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
5526 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
5528 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
5529 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
5530 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
5531 wxCMD_LINE_VAL_NUMBER
},
5532 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
5533 wxCMD_LINE_VAL_DATE
},
5535 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
5536 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
5541 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
5543 parser
.AddOption("project_name", "", "full path to project file",
5544 wxCMD_LINE_VAL_STRING
,
5545 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
5547 switch ( parser
.Parse() )
5550 wxLogMessage("Help was given, terminating.");
5554 ShowCmdLine(parser
);
5558 wxLogMessage("Syntax error detected, aborting.");
5561 #endif // wxUSE_CMDLINE_PARSER
5563 #endif // TEST_CMDLINE
5571 TestStringConstruction();
5574 TestStringTokenizer();
5575 TestStringReplace();
5581 #endif // TEST_STRINGS
5594 puts("*** Initially:");
5596 PrintArray("a1", a1
);
5598 wxArrayString
a2(a1
);
5599 PrintArray("a2", a2
);
5601 wxSortedArrayString
a3(a1
);
5602 PrintArray("a3", a3
);
5604 puts("*** After deleting a string from a1");
5607 PrintArray("a1", a1
);
5608 PrintArray("a2", a2
);
5609 PrintArray("a3", a3
);
5611 puts("*** After reassigning a1 to a2 and a3");
5613 PrintArray("a2", a2
);
5614 PrintArray("a3", a3
);
5616 puts("*** After sorting a1");
5618 PrintArray("a1", a1
);
5620 puts("*** After sorting a1 in reverse order");
5622 PrintArray("a1", a1
);
5624 puts("*** After sorting a1 by the string length");
5625 a1
.Sort(StringLenCompare
);
5626 PrintArray("a1", a1
);
5628 TestArrayOfObjects();
5629 TestArrayOfShorts();
5633 #endif // TEST_ARRAYS
5643 #ifdef TEST_DLLLOADER
5645 #endif // TEST_DLLLOADER
5649 #endif // TEST_ENVIRON
5653 #endif // TEST_EXECUTE
5655 #ifdef TEST_FILECONF
5657 #endif // TEST_FILECONF
5665 #endif // TEST_LOCALE
5669 for ( size_t n
= 0; n
< 8000; n
++ )
5671 s
<< (char)('A' + (n
% 26));
5675 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
5677 // this one shouldn't be truncated
5680 // but this one will because log functions use fixed size buffer
5681 // (note that it doesn't need '\n' at the end neither - will be added
5683 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
5695 #ifdef TEST_FILENAME
5699 fn
.Assign("c:\\foo", "bar.baz");
5706 TestFileNameConstruction();
5707 TestFileNameMakeRelative();
5708 TestFileNameSplit();
5711 TestFileNameComparison();
5712 TestFileNameOperations();
5714 #endif // TEST_FILENAME
5716 #ifdef TEST_FILETIME
5719 #endif // TEST_FILETIME
5722 wxLog::AddTraceMask(FTP_TRACE_MASK
);
5723 if ( TestFtpConnect() )
5734 if ( TEST_INTERACTIVE
)
5735 TestFtpInteractive();
5737 //else: connecting to the FTP server failed
5743 #ifdef TEST_LONGLONG
5744 // seed pseudo random generator
5745 srand((unsigned)time(NULL
));
5754 TestMultiplication();
5757 TestLongLongConversion();
5758 TestBitOperations();
5759 TestLongLongComparison();
5760 TestLongLongPrint();
5762 #endif // TEST_LONGLONG
5770 #endif // TEST_HASHMAP
5773 wxLog::AddTraceMask(_T("mime"));
5781 TestMimeAssociate();
5784 #ifdef TEST_INFO_FUNCTIONS
5790 if ( TEST_INTERACTIVE
)
5793 #endif // TEST_INFO_FUNCTIONS
5795 #ifdef TEST_PATHLIST
5797 #endif // TEST_PATHLIST
5805 #endif // TEST_REGCONF
5808 // TODO: write a real test using src/regex/tests file
5813 TestRegExSubmatch();
5814 TestRegExReplacement();
5816 if ( TEST_INTERACTIVE
)
5817 TestRegExInteractive();
5819 #endif // TEST_REGEX
5821 #ifdef TEST_REGISTRY
5823 TestRegistryAssociation();
5824 #endif // TEST_REGISTRY
5829 #endif // TEST_SOCKETS
5834 #endif // TEST_STREAMS
5837 int nCPUs
= wxThread::GetCPUCount();
5838 printf("This system has %d CPUs\n", nCPUs
);
5840 wxThread::SetConcurrency(nCPUs
);
5844 TestDetachedThreads();
5845 TestJoinableThreads();
5846 TestThreadSuspend();
5850 TestThreadConditions();
5851 #endif // TEST_THREADS
5855 #endif // TEST_TIMER
5857 #ifdef TEST_DATETIME
5870 TestTimeArithmetics();
5873 TestTimeSpanFormat();
5879 if ( TEST_INTERACTIVE
)
5880 TestDateTimeInteractive();
5881 #endif // TEST_DATETIME
5884 puts("Sleeping for 3 seconds... z-z-z-z-z...");
5886 #endif // TEST_USLEEP
5891 #endif // TEST_VCARD
5895 #endif // TEST_VOLUME
5899 TestEncodingConverter();
5900 #endif // TEST_WCHAR
5903 TestZipStreamRead();
5904 TestZipFileSystem();
5908 TestZlibStreamWrite();
5909 TestZlibStreamRead();