1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
24 #include "wx/string.h"
29 // without this pragma, the stupid compiler precompiles #defines below so that
30 // changing them doesn't "take place" later!
35 // ----------------------------------------------------------------------------
36 // conditional compilation
37 // ----------------------------------------------------------------------------
40 A note about all these conditional compilation macros: this file is used
41 both as a test suite for various non-GUI wxWindows classes and as a
42 scratchpad for quick tests. So there are two compilation modes: if you
43 define TEST_ALL all tests are run, otherwise you may enable the individual
44 tests individually in the "#else" branch below.
47 // what to test (in alphabetic order)? uncomment the line below to do all tests
55 #define TEST_DLLLOADER
62 // #define TEST_FTP --FIXME! (RN)
66 #define TEST_INFO_FUNCTIONS
78 #define TEST_SCOPEGUARD
80 // #define TEST_SOCKETS --FIXME! (RN)
83 #define TEST_TEXTSTREAM
87 // #define TEST_VCARD -- don't enable this (VZ)
88 // #define TEST_VOLUME --FIXME! (RN)
95 static const bool TEST_ALL
= true;
99 static const bool TEST_ALL
= false;
102 // some tests are interactive, define this to run them
103 #ifdef TEST_INTERACTIVE
104 #undef TEST_INTERACTIVE
106 static const bool TEST_INTERACTIVE
= true;
108 static const bool TEST_INTERACTIVE
= false;
111 // ----------------------------------------------------------------------------
112 // test class for container objects
113 // ----------------------------------------------------------------------------
115 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
117 class Bar
// Foo is already taken in the hash test
120 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
121 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
122 ~Bar() { ms_bars
--; }
124 static size_t GetNumber() { return ms_bars
; }
126 const wxChar
*GetName() const { return m_name
; }
131 static size_t ms_bars
;
134 size_t Bar::ms_bars
= 0;
136 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
138 // ============================================================================
140 // ============================================================================
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
148 // replace TABs with \t and CRs with \n
149 static wxString
MakePrintable(const wxChar
*s
)
152 (void)str
.Replace(_T("\t"), _T("\\t"));
153 (void)str
.Replace(_T("\n"), _T("\\n"));
154 (void)str
.Replace(_T("\r"), _T("\\r"));
159 #endif // MakePrintable() is used
161 // ----------------------------------------------------------------------------
162 // wxFontMapper::CharsetToEncoding
163 // ----------------------------------------------------------------------------
167 #include "wx/fontmap.h"
169 static void TestCharset()
171 static const wxChar
*charsets
[] =
173 // some vali charsets
182 // and now some bogus ones
189 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
191 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]);
192 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
194 wxFontMapper::Get()->GetEncodingName(enc
).c_str(),
195 wxFontMapper::Get()->GetEncodingDescription(enc
).c_str());
199 #endif // TEST_CHARSET
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
207 #include "wx/cmdline.h"
208 #include "wx/datetime.h"
210 #if wxUSE_CMDLINE_PARSER
212 static void ShowCmdLine(const wxCmdLineParser
& parser
)
214 wxString s
= _T("Input files: ");
216 size_t count
= parser
.GetParamCount();
217 for ( size_t param
= 0; param
< count
; param
++ )
219 s
<< parser
.GetParam(param
) << ' ';
223 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
224 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
229 if ( parser
.Found(_T("o"), &strVal
) )
230 s
<< _T("Output file:\t") << strVal
<< '\n';
231 if ( parser
.Found(_T("i"), &strVal
) )
232 s
<< _T("Input dir:\t") << strVal
<< '\n';
233 if ( parser
.Found(_T("s"), &lVal
) )
234 s
<< _T("Size:\t") << lVal
<< '\n';
235 if ( parser
.Found(_T("d"), &dt
) )
236 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
237 if ( parser
.Found(_T("project_name"), &strVal
) )
238 s
<< _T("Project:\t") << strVal
<< '\n';
243 #endif // wxUSE_CMDLINE_PARSER
245 static void TestCmdLineConvert()
247 static const wxChar
*cmdlines
[] =
250 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
251 _T("literal \\\" and \"\""),
254 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
256 const wxChar
*cmdline
= cmdlines
[n
];
257 wxPrintf(_T("Parsing: %s\n"), cmdline
);
258 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
260 size_t count
= args
.GetCount();
261 wxPrintf(_T("\targc = %u\n"), count
);
262 for ( size_t arg
= 0; arg
< count
; arg
++ )
264 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
269 #endif // TEST_CMDLINE
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
280 static const wxChar
*ROOTDIR
= _T("/");
281 static const wxChar
*TESTDIR
= _T("/usr/local/share");
282 #elif defined(__WXMSW__)
283 static const wxChar
*ROOTDIR
= _T("c:\\");
284 static const wxChar
*TESTDIR
= _T("d:\\");
286 #error "don't know where the root directory is"
289 static void TestDirEnumHelper(wxDir
& dir
,
290 int flags
= wxDIR_DEFAULT
,
291 const wxString
& filespec
= wxEmptyString
)
295 if ( !dir
.IsOpened() )
298 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
301 wxPrintf(_T("\t%s\n"), filename
.c_str());
303 cont
= dir
.GetNext(&filename
);
309 static void TestDirEnum()
311 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
313 wxString cwd
= wxGetCwd();
314 if ( !wxDir::Exists(cwd
) )
316 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
321 if ( !dir
.IsOpened() )
323 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
327 wxPuts(_T("Enumerating everything in current directory:"));
328 TestDirEnumHelper(dir
);
330 wxPuts(_T("Enumerating really everything in current directory:"));
331 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
333 wxPuts(_T("Enumerating object files in current directory:"));
334 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
336 wxPuts(_T("Enumerating directories in current directory:"));
337 TestDirEnumHelper(dir
, wxDIR_DIRS
);
339 wxPuts(_T("Enumerating files in current directory:"));
340 TestDirEnumHelper(dir
, wxDIR_FILES
);
342 wxPuts(_T("Enumerating files including hidden in current directory:"));
343 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
347 wxPuts(_T("Enumerating everything in root directory:"));
348 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
350 wxPuts(_T("Enumerating directories in root directory:"));
351 TestDirEnumHelper(dir
, wxDIR_DIRS
);
353 wxPuts(_T("Enumerating files in root directory:"));
354 TestDirEnumHelper(dir
, wxDIR_FILES
);
356 wxPuts(_T("Enumerating files including hidden in root directory:"));
357 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
359 wxPuts(_T("Enumerating files in non existing directory:"));
360 wxDir
dirNo(_T("nosuchdir"));
361 TestDirEnumHelper(dirNo
);
364 class DirPrintTraverser
: public wxDirTraverser
367 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
369 return wxDIR_CONTINUE
;
372 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
374 wxString path
, name
, ext
;
375 wxSplitPath(dirname
, &path
, &name
, &ext
);
378 name
<< _T('.') << ext
;
381 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
383 if ( wxIsPathSeparator(*p
) )
387 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
389 return wxDIR_CONTINUE
;
393 static void TestDirTraverse()
395 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
399 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
400 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
403 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
404 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
407 // enum again with custom traverser
408 wxPuts(_T("Now enumerating directories:"));
410 DirPrintTraverser traverser
;
411 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
414 static void TestDirExists()
416 wxPuts(_T("*** Testing wxDir::Exists() ***"));
418 static const wxChar
*dirnames
[] =
421 #if defined(__WXMSW__)
424 _T("\\\\share\\file"),
428 _T("c:\\autoexec.bat"),
429 #elif defined(__UNIX__)
438 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
440 wxPrintf(_T("%-40s: %s\n"),
442 wxDir::Exists(dirnames
[n
]) ? _T("exists")
443 : _T("doesn't exist"));
449 // ----------------------------------------------------------------------------
451 // ----------------------------------------------------------------------------
453 #ifdef TEST_DLLLOADER
455 #include "wx/dynlib.h"
457 static void TestDllLoad()
459 #if defined(__WXMSW__)
460 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
461 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
462 #elif defined(__UNIX__)
463 // weird: using just libc.so does *not* work!
464 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
465 static const wxChar
*FUNC_NAME
= _T("strlen");
467 #error "don't know how to test wxDllLoader on this platform"
470 wxPuts(_T("*** testing wxDllLoader ***\n"));
472 wxDynamicLibrary
lib(LIB_NAME
);
473 if ( !lib
.IsLoaded() )
475 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
479 typedef int (*wxStrlenType
)(const char *);
480 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
483 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
484 FUNC_NAME
, LIB_NAME
);
488 if ( pfnStrlen("foo") != 3 )
490 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
494 wxPuts(_T("... ok"));
500 #endif // TEST_DLLLOADER
502 // ----------------------------------------------------------------------------
504 // ----------------------------------------------------------------------------
508 #include "wx/utils.h"
510 static wxString
MyGetEnv(const wxString
& var
)
513 if ( !wxGetEnv(var
, &val
) )
516 val
= wxString(_T('\'')) + val
+ _T('\'');
521 static void TestEnvironment()
523 const wxChar
*var
= _T("wxTestVar");
525 wxPuts(_T("*** testing environment access functions ***"));
527 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
528 wxSetEnv(var
, _T("value for wxTestVar"));
529 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
530 wxSetEnv(var
, _T("another value"));
531 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
533 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
534 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
537 #endif // TEST_ENVIRON
539 // ----------------------------------------------------------------------------
541 // ----------------------------------------------------------------------------
545 #include "wx/utils.h"
547 static void TestExecute()
549 wxPuts(_T("*** testing wxExecute ***"));
552 #define COMMAND "cat -n ../../Makefile" // "echo hi"
553 #define SHELL_COMMAND "echo hi from shell"
554 #define REDIRECT_COMMAND COMMAND // "date"
555 #elif defined(__WXMSW__)
556 #define COMMAND "command.com /c echo hi"
557 #define SHELL_COMMAND "echo hi"
558 #define REDIRECT_COMMAND COMMAND
560 #error "no command to exec"
563 wxPrintf(_T("Testing wxShell: "));
565 if ( wxShell(_T(SHELL_COMMAND
)) )
568 wxPuts(_T("ERROR."));
570 wxPrintf(_T("Testing wxExecute: "));
572 if ( wxExecute(_T(COMMAND
), true /* sync */) == 0 )
575 wxPuts(_T("ERROR."));
577 #if 0 // no, it doesn't work (yet?)
578 wxPrintf(_T("Testing async wxExecute: "));
580 if ( wxExecute(COMMAND
) != 0 )
581 wxPuts(_T("Ok (command launched)."));
583 wxPuts(_T("ERROR."));
586 wxPrintf(_T("Testing wxExecute with redirection:\n"));
587 wxArrayString output
;
588 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
590 wxPuts(_T("ERROR."));
594 size_t count
= output
.GetCount();
595 for ( size_t n
= 0; n
< count
; n
++ )
597 wxPrintf(_T("\t%s\n"), output
[n
].c_str());
604 #endif // TEST_EXECUTE
606 // ----------------------------------------------------------------------------
608 // ----------------------------------------------------------------------------
613 #include "wx/ffile.h"
614 #include "wx/textfile.h"
616 static void TestFileRead()
618 wxPuts(_T("*** wxFile read test ***"));
620 wxFile
file(_T("testdata.fc"));
621 if ( file
.IsOpened() )
623 wxPrintf(_T("File length: %lu\n"), file
.Length());
625 wxPuts(_T("File dump:\n----------"));
627 static const off_t len
= 1024;
631 off_t nRead
= file
.Read(buf
, len
);
632 if ( nRead
== wxInvalidOffset
)
634 wxPrintf(_T("Failed to read the file."));
638 fwrite(buf
, nRead
, 1, stdout
);
644 wxPuts(_T("----------"));
648 wxPrintf(_T("ERROR: can't open test file.\n"));
654 static void TestTextFileRead()
656 wxPuts(_T("*** wxTextFile read test ***"));
658 wxTextFile
file(_T("testdata.fc"));
661 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
662 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
666 wxPuts(_T("\nDumping the entire file:"));
667 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
669 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
671 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
673 wxPuts(_T("\nAnd now backwards:"));
674 for ( s
= file
.GetLastLine();
675 file
.GetCurrentLine() != 0;
676 s
= file
.GetPrevLine() )
678 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
680 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
684 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
690 static void TestFileCopy()
692 wxPuts(_T("*** Testing wxCopyFile ***"));
694 static const wxChar
*filename1
= _T("testdata.fc");
695 static const wxChar
*filename2
= _T("test2");
696 if ( !wxCopyFile(filename1
, filename2
) )
698 wxPuts(_T("ERROR: failed to copy file"));
702 wxFFile
f1(filename1
, _T("rb")),
703 f2(filename2
, _T("rb"));
705 if ( !f1
.IsOpened() || !f2
.IsOpened() )
707 wxPuts(_T("ERROR: failed to open file(s)"));
712 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
714 wxPuts(_T("ERROR: failed to read file(s)"));
718 if ( (s1
.length() != s2
.length()) ||
719 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
721 wxPuts(_T("ERROR: copy error!"));
725 wxPuts(_T("File was copied ok."));
731 if ( !wxRemoveFile(filename2
) )
733 wxPuts(_T("ERROR: failed to remove the file"));
741 // ----------------------------------------------------------------------------
743 // ----------------------------------------------------------------------------
747 #include "wx/confbase.h"
748 #include "wx/fileconf.h"
750 static const struct FileConfTestData
752 const wxChar
*name
; // value name
753 const wxChar
*value
; // the value from the file
756 { _T("value1"), _T("one") },
757 { _T("value2"), _T("two") },
758 { _T("novalue"), _T("default") },
761 static void TestFileConfRead()
763 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
765 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
766 _T("testdata.fc"), wxEmptyString
,
767 wxCONFIG_USE_RELATIVE_PATH
);
769 // test simple reading
770 wxPuts(_T("\nReading config file:"));
771 wxString
defValue(_T("default")), value
;
772 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
774 const FileConfTestData
& data
= fcTestData
[n
];
775 value
= fileconf
.Read(data
.name
, defValue
);
776 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
777 if ( value
== data
.value
)
783 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
787 // test enumerating the entries
788 wxPuts(_T("\nEnumerating all root entries:"));
791 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
794 wxPrintf(_T("\t%s = %s\n"),
796 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
798 cont
= fileconf
.GetNextEntry(name
, dummy
);
801 static const wxChar
*testEntry
= _T("TestEntry");
802 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
803 fileconf
.Write(testEntry
, _T("A value"));
804 fileconf
.DeleteEntry(testEntry
);
805 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
808 #endif // TEST_FILECONF
810 // ----------------------------------------------------------------------------
812 // ----------------------------------------------------------------------------
816 #include "wx/filename.h"
818 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
822 wxString full
= fn
.GetFullPath();
824 wxString vol
, path
, name
, ext
;
825 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
827 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
828 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
830 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
831 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
832 path
.c_str(), name
.c_str(), ext
.c_str());
834 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
835 wxPrintf(_T("with volume: \t'%s'\n"),
836 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
837 wxPrintf(_T("with separator:\t'%s'\n"),
838 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
839 wxPrintf(_T("with both: \t'%s'\n"),
840 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
842 wxPuts(_T("The directories in the path are:"));
843 wxArrayString dirs
= fn
.GetDirs();
844 size_t count
= dirs
.GetCount();
845 for ( size_t n
= 0; n
< count
; n
++ )
847 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
851 static struct FileNameInfo
853 const wxChar
*fullname
;
854 const wxChar
*volume
;
863 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX
},
864 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX
},
865 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX
},
866 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX
},
867 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
868 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX
},
869 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX
},
870 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
871 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX
},
873 // Windows file names
874 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
875 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS
},
876 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
877 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
878 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS
},
879 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
880 { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
882 // wxFileName support for Mac file names is broken currently
885 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC
},
886 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC
},
887 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC
},
888 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC
},
889 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
890 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
894 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS
},
895 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS
},
898 static void TestFileNameConstruction()
900 wxPuts(_T("*** testing wxFileName construction ***"));
902 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
904 const FileNameInfo
& fni
= filenames
[n
];
906 wxFileName
fn(fni
.fullname
, fni
.format
);
908 wxString fullname
= fn
.GetFullPath(fni
.format
);
909 if ( fullname
!= fni
.fullname
)
911 wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni
.fullname
);
914 bool isAbsolute
= fn
.IsAbsolute(fni
.format
);
915 wxPrintf(_T("'%s' is %s (%s)\n\t"),
917 isAbsolute
? "absolute" : "relative",
918 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
920 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
922 wxPuts(_T("ERROR (couldn't be normalized)"));
926 wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
933 static void TestFileNameSplit()
935 wxPuts(_T("*** testing wxFileName splitting ***"));
937 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
939 const FileNameInfo
& fni
= filenames
[n
];
940 wxString volume
, path
, name
, ext
;
941 wxFileName::SplitPath(fni
.fullname
,
942 &volume
, &path
, &name
, &ext
, fni
.format
);
944 wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"),
946 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
948 if ( volume
!= fni
.volume
)
949 wxPrintf(_T(" (ERROR: volume = '%s')"), fni
.volume
);
950 if ( path
!= fni
.path
)
951 wxPrintf(_T(" (ERROR: path = '%s')"), fni
.path
);
952 if ( name
!= fni
.name
)
953 wxPrintf(_T(" (ERROR: name = '%s')"), fni
.name
);
954 if ( ext
!= fni
.ext
)
955 wxPrintf(_T(" (ERROR: ext = '%s')"), fni
.ext
);
961 static void TestFileNameTemp()
963 wxPuts(_T("*** testing wxFileName temp file creation ***"));
965 static const wxChar
*tmpprefixes
[] =
973 _T("/tmp/foo/bar"), // this one must be an error
977 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
979 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
982 // "error" is not in upper case because it may be ok
983 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
987 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
988 tmpprefixes
[n
], path
.c_str());
990 if ( !wxRemoveFile(path
) )
992 wxLogWarning(_T("Failed to remove temp file '%s'"),
999 static void TestFileNameMakeRelative()
1001 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
1003 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1005 const FileNameInfo
& fni
= filenames
[n
];
1007 wxFileName
fn(fni
.fullname
, fni
.format
);
1009 // choose the base dir of the same format
1011 switch ( fni
.format
)
1014 base
= _T("/usr/bin/");
1023 // TODO: I don't know how this is supposed to work there
1026 case wxPATH_NATIVE
: // make gcc happy
1028 wxFAIL_MSG( _T("unexpected path format") );
1031 wxPrintf(_T("'%s' relative to '%s': "),
1032 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
1034 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
1036 wxPuts(_T("unchanged"));
1040 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1045 static void TestFileNameMakeAbsolute()
1047 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
1049 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1051 const FileNameInfo
& fni
= filenames
[n
];
1052 wxFileName
fn(fni
.fullname
, fni
.format
);
1054 wxPrintf(_T("'%s' absolutized: "),
1055 fn
.GetFullPath(fni
.format
).c_str());
1057 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1063 static void TestFileNameDirManip()
1065 // TODO: test AppendDir(), RemoveDir(), ...
1068 static void TestFileNameComparison()
1073 static void TestFileNameOperations()
1078 static void TestFileNameCwd()
1083 #endif // TEST_FILENAME
1085 // ----------------------------------------------------------------------------
1086 // wxFileName time functions
1087 // ----------------------------------------------------------------------------
1089 #ifdef TEST_FILETIME
1091 #include <wx/filename.h>
1092 #include <wx/datetime.h>
1094 static void TestFileGetTimes()
1096 wxFileName
fn(_T("testdata.fc"));
1098 wxDateTime dtAccess
, dtMod
, dtCreate
;
1099 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
1101 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
1105 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
1107 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
1108 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
1109 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
1110 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1114 static void TestFileSetTimes()
1116 wxFileName
fn(_T("testdata.fc"));
1120 wxPrintf(_T("ERROR: Touch() failed.\n"));
1124 #endif // TEST_FILETIME
1126 // ----------------------------------------------------------------------------
1128 // ----------------------------------------------------------------------------
1132 #include "wx/hash.h"
1136 Foo(int n_
) { n
= n_
; count
++; }
1141 static size_t count
;
1144 size_t Foo::count
= 0;
1146 WX_DECLARE_LIST(Foo
, wxListFoos
);
1147 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1149 #include "wx/listimpl.cpp"
1151 WX_DEFINE_LIST(wxListFoos
);
1153 #include "wx/timer.h"
1155 static void TestHash()
1157 wxPuts(_T("*** Testing wxHashTable ***\n"));
1158 const int COUNT
= 100;
1165 wxHashTable
hash(wxKEY_INTEGER
, 10), hash2(wxKEY_STRING
);
1169 for ( i
= 0; i
< COUNT
; ++i
)
1170 hash
.Put(i
, &o
+ i
);
1173 wxHashTable::compatibility_iterator it
= hash
.Next();
1183 wxPuts(_T("Error in wxHashTable::compatibility_iterator\n"));
1185 for ( i
= 99; i
>= 0; --i
)
1186 if( hash
.Get(i
) != &o
+ i
)
1187 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1189 for ( i
= 0; i
< COUNT
; ++i
)
1190 hash
.Put(i
, &o
+ i
+ 20);
1192 for ( i
= 99; i
>= 0; --i
)
1193 if( hash
.Get(i
) != &o
+ i
)
1194 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1196 for ( i
= 0; i
< COUNT
/2; ++i
)
1197 if( hash
.Delete(i
) != &o
+ i
)
1198 wxPuts(_T("Error in wxHashTable::Delete\n"));
1200 for ( i
= COUNT
/2; i
< COUNT
; ++i
)
1201 if( hash
.Get(i
) != &o
+ i
)
1202 wxPuts(_T("Error (3) in wxHashTable::Get/Put\n"));
1204 for ( i
= 0; i
< COUNT
/2; ++i
)
1205 if( hash
.Get(i
) != &o
+ i
+ 20)
1206 wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n"));
1208 for ( i
= 0; i
< COUNT
/2; ++i
)
1209 if( hash
.Delete(i
) != &o
+ i
+ 20)
1210 wxPuts(_T("Error (2) in wxHashTable::Delete\n"));
1212 for ( i
= 0; i
< COUNT
/2; ++i
)
1213 if( hash
.Get(i
) != NULL
)
1214 wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n"));
1216 hash2
.Put(_T("foo"), &o
+ 1);
1217 hash2
.Put(_T("bar"), &o
+ 2);
1218 hash2
.Put(_T("baz"), &o
+ 3);
1220 if (hash2
.Get(_T("moo")) != NULL
)
1221 wxPuts(_T("Error in wxHashTable::Get\n"));
1223 if (hash2
.Get(_T("bar")) != &o
+ 2)
1224 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1226 hash2
.Put(_T("bar"), &o
+ 0);
1228 if (hash2
.Get(_T("bar")) != &o
+ 2)
1229 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1232 // and now some corner-case testing; 3 and 13 hash to the same bucket
1234 wxHashTable
hash(wxKEY_INTEGER
, 10);
1237 hash
.Put(3, &dummy
);
1240 if (hash
.Get(3) != NULL
)
1241 wxPuts(_T("Corner case 1 failure\n"));
1243 hash
.Put(3, &dummy
);
1244 hash
.Put(13, &dummy
);
1247 if (hash
.Get(3) != NULL
)
1248 wxPuts(_T("Corner case 2 failure\n"));
1252 if (hash
.Get(13) != NULL
)
1253 wxPuts(_T("Corner case 3 failure\n"));
1255 hash
.Put(3, &dummy
);
1256 hash
.Put(13, &dummy
);
1259 if (hash
.Get(13) != NULL
)
1260 wxPuts(_T("Corner case 4 failure\n"));
1264 if (hash
.Get(3) != NULL
)
1265 wxPuts(_T("Corner case 5 failure\n"));
1269 wxHashTable
hash(wxKEY_INTEGER
, 10);
1272 hash
.Put(3, 7, &dummy
+ 7);
1273 hash
.Put(4, 8, &dummy
+ 8);
1275 if (hash
.Get(7) != NULL
) wxPuts(_T("Key/Hash 1 failure\n"));
1276 if (hash
.Get(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 2 failure\n"));
1277 if (hash
.Get(4) != NULL
) wxPuts(_T("Key/Hash 3 failure\n"));
1278 if (hash
.Get(3) != NULL
) wxPuts(_T("Key/Hash 4 failure\n"));
1279 if (hash
.Get(8) != NULL
) wxPuts(_T("Key/Hash 5 failure\n"));
1280 if (hash
.Get(8, 4) != NULL
) wxPuts(_T("Key/Hash 6 failure\n"));
1282 if (hash
.Delete(7) != NULL
) wxPuts(_T("Key/Hash 7 failure\n"));
1283 if (hash
.Delete(3) != NULL
) wxPuts(_T("Key/Hash 8 failure\n"));
1284 if (hash
.Delete(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 8 failure\n"));
1289 hash
.DeleteContents(true);
1291 wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"),
1292 hash
.GetCount(), Foo::count
);
1294 static const int hashTestData
[] =
1296 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1300 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1302 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1305 wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"),
1306 hash
.GetCount(), Foo::count
);
1308 wxPuts(_T("Hash access test:"));
1309 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1311 wxPrintf(_T("\tGetting element with key %d, value %d: "),
1312 hashTestData
[n
], n
);
1313 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1316 wxPrintf(_T("ERROR, not found.\n"));
1320 wxPrintf(_T("%d (%s)\n"), foo
->n
,
1321 (size_t)foo
->n
== n
? "ok" : "ERROR");
1325 wxPrintf(_T("\nTrying to get an element not in hash: "));
1327 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1329 wxPuts(_T("ERROR: found!"));
1333 wxPuts(_T("ok (not found)"));
1336 Foo
* foo
= hash
.Delete(0);
1338 wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count
);
1342 wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count
);
1345 wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
);
1346 wxPuts(_T("*** Testing wxHashTable finished ***\n"));
1348 wxPrintf(_T("Time: %ld\n"), sw
.Time());
1353 // ----------------------------------------------------------------------------
1355 // ----------------------------------------------------------------------------
1359 #include "wx/hashmap.h"
1361 // test compilation of basic map types
1362 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1363 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1364 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1365 myUnsignedHashMap
);
1366 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1368 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1370 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1372 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1376 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1377 // myStringHashMap );
1378 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1380 typedef myStringHashMap::iterator Itor
;
1382 static void TestHashMap()
1384 wxPuts(_T("*** Testing wxHashMap ***\n"));
1385 myStringHashMap
sh(0); // as small as possible
1388 const size_t count
= 10000;
1390 // init with some data
1391 for( i
= 0; i
< count
; ++i
)
1393 buf
.Printf(wxT("%d"), i
);
1394 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1397 // test that insertion worked
1398 if( sh
.size() != count
)
1400 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
);
1403 for( i
= 0; i
< count
; ++i
)
1405 buf
.Printf(wxT("%d"), i
);
1406 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1408 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
1413 // check that iterators work
1415 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1419 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
1423 if( it
->second
!= sh
[it
->first
] )
1425 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
1430 if( sh
.size() != i
)
1432 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
);
1435 // test copy ctor, assignment operator
1436 myStringHashMap
h1( sh
), h2( 0 );
1439 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1441 if( h1
[it
->first
] != it
->second
)
1443 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str());
1446 if( h2
[it
->first
] != it
->second
)
1448 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str());
1453 for( i
= 0; i
< count
; ++i
)
1455 buf
.Printf(wxT("%d"), i
);
1456 size_t sz
= sh
.size();
1458 // test find() and erase(it)
1461 it
= sh
.find( buf
);
1462 if( it
!= sh
.end() )
1466 if( sh
.find( buf
) != sh
.end() )
1468 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1472 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
);
1477 size_t c
= sh
.erase( buf
);
1479 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
1481 if( sh
.find( buf
) != sh
.end() )
1483 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1487 // count should decrease
1488 if( sh
.size() != sz
- 1 )
1490 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
1494 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
1497 #endif // TEST_HASHMAP
1499 // ----------------------------------------------------------------------------
1501 // ----------------------------------------------------------------------------
1505 #include "wx/hashset.h"
1507 // test compilation of basic map types
1508 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet
);
1509 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet
);
1510 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
,
1511 myUnsignedHashSet
);
1512 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
,
1514 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
,
1516 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
,
1518 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
,
1520 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
,
1532 unsigned long operator()(const MyStruct
& s
) const
1533 { return m_dummy(s
.ptr
); }
1534 MyHash
& operator=(const MyHash
&) { return *this; }
1536 wxPointerHash m_dummy
;
1542 bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const
1543 { return s1
.ptr
== s2
.ptr
; }
1544 MyEqual
& operator=(const MyEqual
&) { return *this; }
1547 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet
);
1549 typedef myTestHashSet5 wxStringHashSet
;
1551 static void TestHashSet()
1553 wxPrintf(_T("*** Testing wxHashSet ***\n"));
1555 wxStringHashSet set1
;
1557 set1
.insert( _T("abc") );
1558 set1
.insert( _T("bbc") );
1559 set1
.insert( _T("cbc") );
1560 set1
.insert( _T("abc") );
1562 if( set1
.size() != 3 )
1563 wxPrintf(_T("*** ERROR IN INSERT ***\n"));
1569 tmp
.ptr
= &dummy
; tmp
.str
= _T("ABC");
1571 tmp
.ptr
= &dummy
+ 1;
1573 tmp
.ptr
= &dummy
; tmp
.str
= _T("CDE");
1576 if( set2
.size() != 2 )
1577 wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
1579 mySet::iterator it
= set2
.find( tmp
);
1581 if( it
== set2
.end() )
1582 wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
1583 if( it
->ptr
!= &dummy
)
1584 wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
1585 if( it
->str
!= _T("ABC") )
1586 wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
1588 wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
1591 #endif // TEST_HASHSET
1593 // ----------------------------------------------------------------------------
1595 // ----------------------------------------------------------------------------
1599 #include "wx/list.h"
1601 WX_DECLARE_LIST(Bar
, wxListBars
);
1602 #include "wx/listimpl.cpp"
1603 WX_DEFINE_LIST(wxListBars
);
1605 WX_DECLARE_LIST(int, wxListInt
);
1606 WX_DEFINE_LIST(wxListInt
);
1608 static void TestList()
1610 wxPuts(_T("*** Testing wxList operations ***\n"));
1616 for ( i
= 0; i
< 5; ++i
)
1617 list1
.Append(dummy
+ i
);
1619 if ( list1
.GetCount() != 5 )
1620 wxPuts(_T("Wrong number of items in list\n"));
1622 if ( list1
.Item(3)->GetData() != dummy
+ 3 )
1623 wxPuts(_T("Error in Item()\n"));
1625 if ( !list1
.Find(dummy
+ 4) )
1626 wxPuts(_T("Error in Find()\n"));
1628 wxListInt::compatibility_iterator node
= list1
.GetFirst();
1633 if ( node
->GetData() != dummy
+ i
)
1634 wxPuts(_T("Error in compatibility_iterator\n"));
1635 node
= node
->GetNext();
1639 if ( size_t(i
) != list1
.GetCount() )
1640 wxPuts(_T("Error in compatibility_iterator\n"));
1642 list1
.Insert(dummy
+ 0);
1643 list1
.Insert(1, dummy
+ 1);
1644 list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy
+ 2);
1646 node
= list1
.GetFirst();
1651 int* t
= node
->GetData();
1652 if ( t
!= dummy
+ i
)
1653 wxPuts(_T("Error in Insert\n"));
1654 node
= node
->GetNext();
1659 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1661 wxPuts(_T("*** Testing std::list operations ***\n"));
1665 wxListInt::iterator it
, en
;
1666 wxListInt::reverse_iterator rit
, ren
;
1668 for ( i
= 0; i
< 5; ++i
)
1669 list1
.push_back(i
+ &i
);
1671 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
1672 it
!= en
; ++it
, ++i
)
1673 if ( *it
!= i
+ &i
)
1674 wxPuts(_T("Error in iterator\n"));
1676 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
1677 rit
!= ren
; ++rit
, --i
)
1678 if ( *rit
!= i
+ &i
)
1679 wxPuts(_T("Error in reverse_iterator\n"));
1681 if ( *list1
.rbegin() != *--list1
.end() ||
1682 *list1
.begin() != *--list1
.rend() )
1683 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1684 if ( *list1
.begin() != *--++list1
.begin() ||
1685 *list1
.rbegin() != *--++list1
.rbegin() )
1686 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1688 if ( list1
.front() != &i
|| list1
.back() != &i
+ 4 )
1689 wxPuts(_T("Error in front()/back()\n"));
1691 list1
.erase(list1
.begin());
1692 list1
.erase(--list1
.end());
1694 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
1695 it
!= en
; ++it
, ++i
)
1696 if ( *it
!= i
+ &i
)
1697 wxPuts(_T("Error in erase()\n"));
1700 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1703 static void TestListCtor()
1705 wxPuts(_T("*** Testing wxList construction ***\n"));
1709 list1
.Append(new Bar(_T("first")));
1710 list1
.Append(new Bar(_T("second")));
1712 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
1713 list1
.GetCount(), Bar::GetNumber());
1718 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
1719 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1722 list1
.DeleteContents(true);
1724 WX_CLEAR_LIST(wxListBars
, list1
);
1728 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
1733 // ----------------------------------------------------------------------------
1735 // ----------------------------------------------------------------------------
1739 #include "wx/intl.h"
1740 #include "wx/utils.h" // for wxSetEnv
1742 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1744 // find the name of the language from its value
1745 static const wxChar
*GetLangName(int lang
)
1747 static const wxChar
*languageNames
[] =
1757 _T("ARABIC_ALGERIA"),
1758 _T("ARABIC_BAHRAIN"),
1761 _T("ARABIC_JORDAN"),
1762 _T("ARABIC_KUWAIT"),
1763 _T("ARABIC_LEBANON"),
1765 _T("ARABIC_MOROCCO"),
1768 _T("ARABIC_SAUDI_ARABIA"),
1771 _T("ARABIC_TUNISIA"),
1778 _T("AZERI_CYRILLIC"),
1793 _T("CHINESE_SIMPLIFIED"),
1794 _T("CHINESE_TRADITIONAL"),
1795 _T("CHINESE_HONGKONG"),
1796 _T("CHINESE_MACAU"),
1797 _T("CHINESE_SINGAPORE"),
1798 _T("CHINESE_TAIWAN"),
1804 _T("DUTCH_BELGIAN"),
1808 _T("ENGLISH_AUSTRALIA"),
1809 _T("ENGLISH_BELIZE"),
1810 _T("ENGLISH_BOTSWANA"),
1811 _T("ENGLISH_CANADA"),
1812 _T("ENGLISH_CARIBBEAN"),
1813 _T("ENGLISH_DENMARK"),
1815 _T("ENGLISH_JAMAICA"),
1816 _T("ENGLISH_NEW_ZEALAND"),
1817 _T("ENGLISH_PHILIPPINES"),
1818 _T("ENGLISH_SOUTH_AFRICA"),
1819 _T("ENGLISH_TRINIDAD"),
1820 _T("ENGLISH_ZIMBABWE"),
1828 _T("FRENCH_BELGIAN"),
1829 _T("FRENCH_CANADIAN"),
1830 _T("FRENCH_LUXEMBOURG"),
1831 _T("FRENCH_MONACO"),
1837 _T("GERMAN_AUSTRIAN"),
1838 _T("GERMAN_BELGIUM"),
1839 _T("GERMAN_LIECHTENSTEIN"),
1840 _T("GERMAN_LUXEMBOURG"),
1858 _T("ITALIAN_SWISS"),
1863 _T("KASHMIRI_INDIA"),
1881 _T("MALAY_BRUNEI_DARUSSALAM"),
1882 _T("MALAY_MALAYSIA"),
1892 _T("NORWEGIAN_BOKMAL"),
1893 _T("NORWEGIAN_NYNORSK"),
1900 _T("PORTUGUESE_BRAZILIAN"),
1903 _T("RHAETO_ROMANCE"),
1906 _T("RUSSIAN_UKRAINE"),
1912 _T("SERBIAN_CYRILLIC"),
1913 _T("SERBIAN_LATIN"),
1914 _T("SERBO_CROATIAN"),
1925 _T("SPANISH_ARGENTINA"),
1926 _T("SPANISH_BOLIVIA"),
1927 _T("SPANISH_CHILE"),
1928 _T("SPANISH_COLOMBIA"),
1929 _T("SPANISH_COSTA_RICA"),
1930 _T("SPANISH_DOMINICAN_REPUBLIC"),
1931 _T("SPANISH_ECUADOR"),
1932 _T("SPANISH_EL_SALVADOR"),
1933 _T("SPANISH_GUATEMALA"),
1934 _T("SPANISH_HONDURAS"),
1935 _T("SPANISH_MEXICAN"),
1936 _T("SPANISH_MODERN"),
1937 _T("SPANISH_NICARAGUA"),
1938 _T("SPANISH_PANAMA"),
1939 _T("SPANISH_PARAGUAY"),
1941 _T("SPANISH_PUERTO_RICO"),
1942 _T("SPANISH_URUGUAY"),
1944 _T("SPANISH_VENEZUELA"),
1948 _T("SWEDISH_FINLAND"),
1966 _T("URDU_PAKISTAN"),
1968 _T("UZBEK_CYRILLIC"),
1981 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1982 return languageNames
[lang
];
1984 return _T("INVALID");
1987 static void TestDefaultLang()
1989 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1991 static const wxChar
*langStrings
[] =
1993 NULL
, // system default
2000 _T("de_DE.iso88591"),
2002 _T("?"), // invalid lang spec
2003 _T("klingonese"), // I bet on some systems it does exist...
2006 wxPrintf(_T("The default system encoding is %s (%d)\n"),
2007 wxLocale::GetSystemEncodingName().c_str(),
2008 wxLocale::GetSystemEncoding());
2010 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
2012 const wxChar
*langStr
= langStrings
[n
];
2015 // FIXME: this doesn't do anything at all under Windows, we need
2016 // to create a new wxLocale!
2017 wxSetEnv(_T("LC_ALL"), langStr
);
2020 int lang
= gs_localeDefault
.GetSystemLanguage();
2021 wxPrintf(_T("Locale for '%s' is %s.\n"),
2022 langStr
? langStr
: _T("system default"), GetLangName(lang
));
2026 #endif // TEST_LOCALE
2028 // ----------------------------------------------------------------------------
2030 // ----------------------------------------------------------------------------
2034 #include "wx/mimetype.h"
2036 static void TestMimeEnum()
2038 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
2040 wxArrayString mimetypes
;
2042 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
2044 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
2049 for ( size_t n
= 0; n
< count
; n
++ )
2051 wxFileType
*filetype
=
2052 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
2055 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
2056 mimetypes
[n
].c_str());
2060 filetype
->GetDescription(&desc
);
2061 filetype
->GetExtensions(exts
);
2063 filetype
->GetIcon(NULL
);
2066 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
2069 extsAll
<< _T(", ");
2073 wxPrintf(_T("\t%s: %s (%s)\n"),
2074 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
2080 static void TestMimeOverride()
2082 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
2084 static const wxChar
*mailcap
= _T("/tmp/mailcap");
2085 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
2087 if ( wxFile::Exists(mailcap
) )
2088 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
2090 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
2092 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
2095 if ( wxFile::Exists(mimetypes
) )
2096 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
2098 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
2100 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
2106 static void TestMimeFilename()
2108 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
2110 static const wxChar
*filenames
[] =
2118 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
2120 const wxString fname
= filenames
[n
];
2121 wxString ext
= fname
.AfterLast(_T('.'));
2122 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
2125 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
2130 if ( !ft
->GetDescription(&desc
) )
2131 desc
= _T("<no description>");
2134 if ( !ft
->GetOpenCommand(&cmd
,
2135 wxFileType::MessageParameters(fname
, _T(""))) )
2136 cmd
= _T("<no command available>");
2138 cmd
= wxString(_T('"')) + cmd
+ _T('"');
2140 wxPrintf(_T("To open %s (%s) do %s.\n"),
2141 fname
.c_str(), desc
.c_str(), cmd
.c_str());
2150 static void TestMimeAssociate()
2152 wxPuts(_T("*** Testing creation of filetype association ***\n"));
2154 wxFileTypeInfo
ftInfo(
2155 _T("application/x-xyz"),
2156 _T("xyzview '%s'"), // open cmd
2157 _T(""), // print cmd
2158 _T("XYZ File"), // description
2159 _T(".xyz"), // extensions
2160 NULL
// end of extensions
2162 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
2164 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
2167 wxPuts(_T("ERROR: failed to create association!"));
2171 // TODO: read it back
2180 // ----------------------------------------------------------------------------
2181 // misc information functions
2182 // ----------------------------------------------------------------------------
2184 #ifdef TEST_INFO_FUNCTIONS
2186 #include "wx/utils.h"
2188 static void TestDiskInfo()
2190 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
2194 wxChar pathname
[128];
2195 wxPrintf(_T("\nEnter a directory name: "));
2196 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
2199 // kill the last '\n'
2200 pathname
[wxStrlen(pathname
) - 1] = 0;
2202 wxLongLong total
, free
;
2203 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
2205 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
2209 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
2210 (total
/ 1024).ToString().c_str(),
2211 (free
/ 1024).ToString().c_str(),
2217 static void TestOsInfo()
2219 wxPuts(_T("*** Testing OS info functions ***\n"));
2222 wxGetOsVersion(&major
, &minor
);
2223 wxPrintf(_T("Running under: %s, version %d.%d\n"),
2224 wxGetOsDescription().c_str(), major
, minor
);
2226 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
2228 wxPrintf(_T("Host name is %s (%s).\n"),
2229 wxGetHostName().c_str(), wxGetFullHostName().c_str());
2234 static void TestUserInfo()
2236 wxPuts(_T("*** Testing user info functions ***\n"));
2238 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
2239 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
2240 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
2241 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
2246 #endif // TEST_INFO_FUNCTIONS
2248 // ----------------------------------------------------------------------------
2250 // ----------------------------------------------------------------------------
2252 #ifdef TEST_LONGLONG
2254 #include "wx/longlong.h"
2255 #include "wx/timer.h"
2257 // make a 64 bit number from 4 16 bit ones
2258 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
2260 // get a random 64 bit number
2261 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
2263 static const long testLongs
[] =
2274 #if wxUSE_LONGLONG_WX
2275 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
2276 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2277 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
2278 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2279 #endif // wxUSE_LONGLONG_WX
2281 static void TestSpeed()
2283 static const long max
= 100000000;
2290 for ( n
= 0; n
< max
; n
++ )
2295 wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw
.Time());
2298 #if wxUSE_LONGLONG_NATIVE
2303 for ( n
= 0; n
< max
; n
++ )
2308 wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw
.Time());
2310 #endif // wxUSE_LONGLONG_NATIVE
2316 for ( n
= 0; n
< max
; n
++ )
2321 wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw
.Time());
2325 static void TestLongLongConversion()
2327 wxPuts(_T("*** Testing wxLongLong conversions ***\n"));
2331 for ( size_t n
= 0; n
< 100000; n
++ )
2335 #if wxUSE_LONGLONG_NATIVE
2336 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
2338 wxASSERT_MSG( a
== b
, _T("conversions failure") );
2340 wxPuts(_T("Can't do it without native long long type, test skipped."));
2343 #endif // wxUSE_LONGLONG_NATIVE
2345 if ( !(nTested
% 1000) )
2354 wxPuts(_T(" done!"));
2357 static void TestMultiplication()
2359 wxPuts(_T("*** Testing wxLongLong multiplication ***\n"));
2363 for ( size_t n
= 0; n
< 100000; n
++ )
2368 #if wxUSE_LONGLONG_NATIVE
2369 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
2370 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
2372 wxASSERT_MSG( a
*b
== aa
*bb
, _T("multiplication failure") );
2373 #else // !wxUSE_LONGLONG_NATIVE
2374 wxPuts(_T("Can't do it without native long long type, test skipped."));
2377 #endif // wxUSE_LONGLONG_NATIVE
2379 if ( !(nTested
% 1000) )
2388 wxPuts(_T(" done!"));
2391 static void TestDivision()
2393 wxPuts(_T("*** Testing wxLongLong division ***\n"));
2397 for ( size_t n
= 0; n
< 100000; n
++ )
2399 // get a random wxLongLong (shifting by 12 the MSB ensures that the
2400 // multiplication will not overflow)
2401 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
2403 // get a random (but non null) long (not wxLongLong for now) to divide
2415 #if wxUSE_LONGLONG_NATIVE
2416 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
2418 wxLongLongNative p
= m
/ l
, s
= m
% l
;
2419 wxASSERT_MSG( q
== p
&& r
== s
, _T("division failure") );
2420 #else // !wxUSE_LONGLONG_NATIVE
2421 // verify the result
2422 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
2423 #endif // wxUSE_LONGLONG_NATIVE
2425 if ( !(nTested
% 1000) )
2434 wxPuts(_T(" done!"));
2437 static void TestAddition()
2439 wxPuts(_T("*** Testing wxLongLong addition ***\n"));
2443 for ( size_t n
= 0; n
< 100000; n
++ )
2449 #if wxUSE_LONGLONG_NATIVE
2450 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
2451 wxLongLongNative(b
.GetHi(), b
.GetLo()),
2452 _T("addition failure") );
2453 #else // !wxUSE_LONGLONG_NATIVE
2454 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2455 #endif // wxUSE_LONGLONG_NATIVE
2457 if ( !(nTested
% 1000) )
2466 wxPuts(_T(" done!"));
2469 static void TestBitOperations()
2471 wxPuts(_T("*** Testing wxLongLong bit operation ***\n"));
2475 for ( size_t n
= 0; n
< 100000; n
++ )
2479 #if wxUSE_LONGLONG_NATIVE
2480 for ( size_t n
= 0; n
< 33; n
++ )
2483 #else // !wxUSE_LONGLONG_NATIVE
2484 wxPuts(_T("Can't do it without native long long type, test skipped."));
2487 #endif // wxUSE_LONGLONG_NATIVE
2489 if ( !(nTested
% 1000) )
2498 wxPuts(_T(" done!"));
2501 static void TestLongLongComparison()
2503 #if wxUSE_LONGLONG_WX
2504 wxPuts(_T("*** Testing wxLongLong comparison ***\n"));
2506 static const long ls
[2] =
2512 wxLongLongWx lls
[2];
2516 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2520 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2522 res
= lls
[m
] > testLongs
[n
];
2523 wxPrintf(_T("0x%lx > 0x%lx is %s (%s)\n"),
2524 ls
[m
], testLongs
[n
], res
? "true" : "false",
2525 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2527 res
= lls
[m
] < testLongs
[n
];
2528 wxPrintf(_T("0x%lx < 0x%lx is %s (%s)\n"),
2529 ls
[m
], testLongs
[n
], res
? "true" : "false",
2530 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2532 res
= lls
[m
] == testLongs
[n
];
2533 wxPrintf(_T("0x%lx == 0x%lx is %s (%s)\n"),
2534 ls
[m
], testLongs
[n
], res
? "true" : "false",
2535 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2538 #endif // wxUSE_LONGLONG_WX
2541 static void TestLongLongToString()
2543 wxPuts(_T("*** Testing wxLongLong::ToString() ***\n"));
2545 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2547 wxLongLong ll
= testLongs
[n
];
2548 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2551 wxLongLong
ll(0x12345678, 0x87654321);
2552 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2555 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2558 static void TestLongLongPrintf()
2560 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2562 #ifdef wxLongLongFmtSpec
2563 wxLongLong ll
= wxLL(0x1234567890abcdef);
2564 wxString s
= wxString::Format(_T("%") wxLongLongFmtSpec
_T("x"), ll
);
2565 wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"),
2566 s
.c_str(), s
== _T("1234567890abcdef") ? _T("ok") : _T("ERROR"));
2567 #else // !wxLongLongFmtSpec
2568 #error "wxLongLongFmtSpec not defined for this compiler/platform"
2575 #endif // TEST_LONGLONG
2577 // ----------------------------------------------------------------------------
2579 // ----------------------------------------------------------------------------
2581 #ifdef TEST_PATHLIST
2584 #define CMD_IN_PATH _T("ls")
2586 #define CMD_IN_PATH _T("command.com")
2589 static void TestPathList()
2591 wxPuts(_T("*** Testing wxPathList ***\n"));
2593 wxPathList pathlist
;
2594 pathlist
.AddEnvList(_T("PATH"));
2595 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
2598 wxPrintf(_T("ERROR: command not found in the path.\n"));
2602 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
2606 #endif // TEST_PATHLIST
2608 // ----------------------------------------------------------------------------
2609 // regular expressions
2610 // ----------------------------------------------------------------------------
2614 #include "wx/regex.h"
2616 static void TestRegExCompile()
2618 wxPuts(_T("*** Testing RE compilation ***\n"));
2620 static struct RegExCompTestData
2622 const wxChar
*pattern
;
2624 } regExCompTestData
[] =
2626 { _T("foo"), true },
2627 { _T("foo("), false },
2628 { _T("foo(bar"), false },
2629 { _T("foo(bar)"), true },
2630 { _T("foo["), false },
2631 { _T("foo[bar"), false },
2632 { _T("foo[bar]"), true },
2633 { _T("foo{"), true },
2634 { _T("foo{1"), false },
2635 { _T("foo{bar"), true },
2636 { _T("foo{1}"), true },
2637 { _T("foo{1,2}"), true },
2638 { _T("foo{bar}"), true },
2639 { _T("foo*"), true },
2640 { _T("foo**"), false },
2641 { _T("foo+"), true },
2642 { _T("foo++"), false },
2643 { _T("foo?"), true },
2644 { _T("foo??"), false },
2645 { _T("foo?+"), false },
2649 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2651 const RegExCompTestData
& data
= regExCompTestData
[n
];
2652 bool ok
= re
.Compile(data
.pattern
);
2654 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2656 ok
? _T("") : _T("not "),
2657 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2661 static void TestRegExMatch()
2663 wxPuts(_T("*** Testing RE matching ***\n"));
2665 static struct RegExMatchTestData
2667 const wxChar
*pattern
;
2670 } regExMatchTestData
[] =
2672 { _T("foo"), _T("bar"), false },
2673 { _T("foo"), _T("foobar"), true },
2674 { _T("^foo"), _T("foobar"), true },
2675 { _T("^foo"), _T("barfoo"), false },
2676 { _T("bar$"), _T("barbar"), true },
2677 { _T("bar$"), _T("barbar "), false },
2680 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2682 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2684 wxRegEx
re(data
.pattern
);
2685 bool ok
= re
.Matches(data
.text
);
2687 wxPrintf(_T("'%s' %s %s (%s)\n"),
2689 ok
? _T("matches") : _T("doesn't match"),
2691 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2695 static void TestRegExSubmatch()
2697 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2699 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2700 if ( !re
.IsValid() )
2702 wxPuts(_T("ERROR: compilation failed."));
2706 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2708 if ( !re
.Matches(text
) )
2710 wxPuts(_T("ERROR: match expected."));
2714 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2716 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2717 re
.GetMatch(text
, 3).c_str(),
2718 re
.GetMatch(text
, 2).c_str(),
2719 re
.GetMatch(text
, 4).c_str(),
2720 re
.GetMatch(text
, 1).c_str());
2724 static void TestRegExReplacement()
2726 wxPuts(_T("*** Testing RE replacement ***"));
2728 static struct RegExReplTestData
2732 const wxChar
*result
;
2734 } regExReplTestData
[] =
2736 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2737 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2738 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2739 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2740 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2741 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2742 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2745 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2746 wxRegEx
re(pattern
);
2748 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2750 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2752 const RegExReplTestData
& data
= regExReplTestData
[n
];
2754 wxString text
= data
.text
;
2755 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2757 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2758 data
.text
, data
.repl
,
2759 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2761 if ( text
== data
.result
&& nRepl
== data
.count
)
2767 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2768 data
.count
, data
.result
);
2773 static void TestRegExInteractive()
2775 wxPuts(_T("*** Testing RE interactively ***"));
2779 wxChar pattern
[128];
2780 wxPrintf(_T("\nEnter a pattern: "));
2781 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2784 // kill the last '\n'
2785 pattern
[wxStrlen(pattern
) - 1] = 0;
2788 if ( !re
.Compile(pattern
) )
2796 wxPrintf(_T("Enter text to match: "));
2797 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
2800 // kill the last '\n'
2801 text
[wxStrlen(text
) - 1] = 0;
2803 if ( !re
.Matches(text
) )
2805 wxPrintf(_T("No match.\n"));
2809 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
2812 for ( size_t n
= 1; ; n
++ )
2814 if ( !re
.GetMatch(&start
, &len
, n
) )
2819 wxPrintf(_T("Subexpr %u matched '%s'\n"),
2820 n
, wxString(text
+ start
, len
).c_str());
2827 #endif // TEST_REGEX
2829 // ----------------------------------------------------------------------------
2831 // ----------------------------------------------------------------------------
2841 static void TestDbOpen()
2849 // ----------------------------------------------------------------------------
2851 // ----------------------------------------------------------------------------
2854 NB: this stuff was taken from the glibc test suite and modified to build
2855 in wxWindows: if I read the copyright below properly, this shouldn't
2861 #ifdef wxTEST_PRINTF
2862 // use our functions from wxchar.cpp
2866 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
2867 // in the tests below
2868 int wxPrintf( const wxChar
*format
, ... );
2869 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
2872 #include "wx/longlong.h"
2876 static void rfg1 (void);
2877 static void rfg2 (void);
2881 fmtchk (const wxChar
*fmt
)
2883 (void) wxPrintf(_T("%s:\t`"), fmt
);
2884 (void) wxPrintf(fmt
, 0x12);
2885 (void) wxPrintf(_T("'\n"));
2889 fmtst1chk (const wxChar
*fmt
)
2891 (void) wxPrintf(_T("%s:\t`"), fmt
);
2892 (void) wxPrintf(fmt
, 4, 0x12);
2893 (void) wxPrintf(_T("'\n"));
2897 fmtst2chk (const wxChar
*fmt
)
2899 (void) wxPrintf(_T("%s:\t`"), fmt
);
2900 (void) wxPrintf(fmt
, 4, 4, 0x12);
2901 (void) wxPrintf(_T("'\n"));
2904 /* This page is covered by the following copyright: */
2906 /* (C) Copyright C E Chew
2908 * Feel free to copy, use and distribute this software provided:
2910 * 1. you do not pretend that you wrote it
2911 * 2. you leave this copyright notice intact.
2915 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2922 /* Formatted Output Test
2924 * This exercises the output formatting code.
2932 wxChar
*prefix
= buf
;
2935 wxPuts(_T("\nFormatted output test"));
2936 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
2937 wxStrcpy(prefix
, _T("%"));
2938 for (i
= 0; i
< 2; i
++) {
2939 for (j
= 0; j
< 2; j
++) {
2940 for (k
= 0; k
< 2; k
++) {
2941 for (l
= 0; l
< 2; l
++) {
2942 wxStrcpy(prefix
, _T("%"));
2943 if (i
== 0) wxStrcat(prefix
, _T("-"));
2944 if (j
== 0) wxStrcat(prefix
, _T("+"));
2945 if (k
== 0) wxStrcat(prefix
, _T("#"));
2946 if (l
== 0) wxStrcat(prefix
, _T("0"));
2947 wxPrintf(_T("%5s |"), prefix
);
2948 wxStrcpy(tp
, prefix
);
2949 wxStrcat(tp
, _T("6d |"));
2951 wxStrcpy(tp
, prefix
);
2952 wxStrcat(tp
, _T("6o |"));
2954 wxStrcpy(tp
, prefix
);
2955 wxStrcat(tp
, _T("6x |"));
2957 wxStrcpy(tp
, prefix
);
2958 wxStrcat(tp
, _T("6X |"));
2960 wxStrcpy(tp
, prefix
);
2961 wxStrcat(tp
, _T("6u |"));
2968 wxPrintf(_T("%10s\n"), (wxChar
*) NULL
);
2969 wxPrintf(_T("%-10s\n"), (wxChar
*) NULL
);
2972 static void TestPrintf()
2974 static wxChar shortstr
[] = _T("Hi, Z.");
2975 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
2976 I am ready for my first lesson today.");
2981 fmtchk(_T("%4.4x"));
2982 fmtchk(_T("%04.4x"));
2983 fmtchk(_T("%4.3x"));
2984 fmtchk(_T("%04.3x"));
2986 fmtst1chk(_T("%.*x"));
2987 fmtst1chk(_T("%0*x"));
2988 fmtst2chk(_T("%*.*x"));
2989 fmtst2chk(_T("%0*.*x"));
2991 wxPrintf(_T("bad format:\t\"%b\"\n"));
2992 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
2994 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
2995 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
2996 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
2997 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
2998 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
2999 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
3000 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
3001 wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456);
3002 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
3003 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
3005 wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr
);
3006 wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr
);
3007 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
3008 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
3009 wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar
*)NULL
);
3010 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
3012 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
3013 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
3014 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
3015 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
3016 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
3017 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
3018 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
3019 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
3020 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
3021 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
3022 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
3023 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
3025 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
3026 wxPrintf (_T(" %6.5f\n"), .1);
3027 wxPrintf (_T("x%5.4fx\n"), .5);
3029 wxPrintf (_T("%#03x\n"), 1);
3031 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
3037 while (niter
-- != 0)
3038 wxPrintf (_T("%.17e\n"), d
/ 2);
3042 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
3044 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
3045 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
3046 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
3047 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
3048 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
3049 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
3050 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
3051 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
3052 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
3053 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
3058 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
3060 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
3061 rc
, WXSIZEOF(buf
), buf
);
3064 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
3065 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
3071 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
3072 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
3073 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
3074 wxPrintf (_T("%g should be 123.456\n"), 123.456);
3075 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
3076 wxPrintf (_T("%g should be 10\n"), 10.0);
3077 wxPrintf (_T("%g should be 0.02\n"), 0.02);
3081 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
3087 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
3089 result
|= wxStrcmp (buf
,
3090 _T("onetwo three "));
3092 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
3099 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
3101 // for some reason below line fails under Borland
3102 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
3105 if (wxStrcmp (buf
, _T("40000000000")) != 0)
3108 wxPuts (_T("\tFAILED"));
3112 #endif // wxLongLong_t
3114 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
3115 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
3117 wxPuts (_T("--- Should be no further output. ---"));
3126 memset (bytes
, '\xff', sizeof bytes
);
3127 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
3128 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
3129 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
3131 wxPuts (_T("%hhn overwrite more bytes"));
3136 wxPuts (_T("%hhn wrote incorrect value"));
3148 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
3149 if (wxStrcmp (buf
, _T(" ")) != 0)
3150 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
3151 wxSprintf (buf
, _T("%5.f"), 33.3);
3152 if (wxStrcmp (buf
, _T(" 33")) != 0)
3153 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
3154 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
3155 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
3156 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
3157 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
3158 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
3159 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
3160 wxSprintf (buf
, _T("%.g"), 33.3);
3161 if (wxStrcmp (buf
, _T("3e+01")) != 0)
3162 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
3163 wxSprintf (buf
, _T("%.G"), 33.3);
3164 if (wxStrcmp (buf
, _T("3E+01")) != 0)
3165 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
3175 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
3176 if (wxStrcmp (buf
, _T("3")) != 0)
3177 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
3179 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
3180 if (wxStrcmp (buf
, _T("3")) != 0)
3181 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
3183 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
3184 if (wxStrcmp (buf
, _T(" 3")) != 0)
3185 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
3187 wxSprintf (buf
, _T("%04.*o"), prec
, 33);
3188 if (wxStrcmp (buf
, _T(" 041")) != 0)
3189 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
3191 wxSprintf (buf
, _T("%09.*u"), prec
, 33);
3192 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
3193 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
3195 wxSprintf (buf
, _T("%04.*x"), prec
, 33);
3196 if (wxStrcmp (buf
, _T(" 021")) != 0)
3197 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
3199 wxSprintf (buf
, _T("%04.*X"), prec
, 33);
3200 if (wxStrcmp (buf
, _T(" 021")) != 0)
3201 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
3204 #endif // TEST_PRINTF
3206 // ----------------------------------------------------------------------------
3207 // registry and related stuff
3208 // ----------------------------------------------------------------------------
3210 // this is for MSW only
3213 #undef TEST_REGISTRY
3218 #include "wx/confbase.h"
3219 #include "wx/msw/regconf.h"
3221 static void TestRegConfWrite()
3223 wxConfig
*config
= new wxConfig("myapp");
3224 config
->SetPath("/group1");
3225 config
->Write("entry1", "foo");
3226 config
->SetPath("/group2");
3227 config
->Write("entry1", "bar");
3230 static void TestRegConfRead()
3232 wxConfig
*config
= new wxConfig("myapp");
3236 config
->SetPath("/");
3237 puts("Enumerating / subgroups:");
3238 bool bCont
= config
->GetFirstGroup(str
, dummy
);
3242 bCont
= config
->GetNextGroup(str
, dummy
);
3246 #endif // TEST_REGCONF
3248 #ifdef TEST_REGISTRY
3250 #include "wx/msw/registry.h"
3252 // I chose this one because I liked its name, but it probably only exists under
3254 static const wxChar
*TESTKEY
=
3255 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
3257 static void TestRegistryRead()
3259 wxPuts(_T("*** testing registry reading ***"));
3261 wxRegKey
key(TESTKEY
);
3262 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
3265 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
3270 size_t nSubKeys
, nValues
;
3271 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
3273 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
3276 wxPrintf(_T("Enumerating values:\n"));
3280 bool cont
= key
.GetFirstValue(value
, dummy
);
3283 wxPrintf(_T("Value '%s': type "), value
.c_str());
3284 switch ( key
.GetValueType(value
) )
3286 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
3287 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
3288 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
3289 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
3290 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
3291 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
3292 default: wxPrintf(_T("other (unknown)")); break;
3295 wxPrintf(_T(", value = "));
3296 if ( key
.IsNumericValue(value
) )
3299 key
.QueryValue(value
, &val
);
3300 wxPrintf(_T("%ld"), val
);
3305 key
.QueryValue(value
, val
);
3306 wxPrintf(_T("'%s'"), val
.c_str());
3308 key
.QueryRawValue(value
, val
);
3309 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
3314 cont
= key
.GetNextValue(value
, dummy
);
3318 static void TestRegistryAssociation()
3321 The second call to deleteself genertaes an error message, with a
3322 messagebox saying .flo is crucial to system operation, while the .ddf
3323 call also fails, but with no error message
3328 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
3330 key
= _T("ddxf_auto_file") ;
3331 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
3333 key
= _T("ddxf_auto_file") ;
3334 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
3336 key
= _T("program,0") ;
3337 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
3339 key
= _T("program \"%1\"") ;
3341 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
3343 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
3345 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
3347 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
3351 #endif // TEST_REGISTRY
3353 // ----------------------------------------------------------------------------
3355 // ----------------------------------------------------------------------------
3357 #ifdef TEST_SCOPEGUARD
3359 #include "wx/scopeguard.h"
3361 static void function0() { puts("function0()"); }
3362 static void function1(int n
) { printf("function1(%d)\n", n
); }
3363 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
3367 void method0() { printf("method0()\n"); }
3368 void method1(int n
) { printf("method1(%d)\n", n
); }
3369 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
3372 static void TestScopeGuard()
3374 wxON_BLOCK_EXIT0(function0
);
3375 wxON_BLOCK_EXIT1(function1
, 17);
3376 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
3379 wxON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
);
3380 wxON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7);
3381 wxON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e');
3383 wxScopeGuard dismissed
= wxMakeGuard(function0
);
3384 dismissed
.Dismiss();
3389 // ----------------------------------------------------------------------------
3391 // ----------------------------------------------------------------------------
3395 #include "wx/socket.h"
3396 #include "wx/protocol/protocol.h"
3397 #include "wx/protocol/http.h"
3399 static void TestSocketServer()
3401 wxPuts(_T("*** Testing wxSocketServer ***\n"));
3403 static const int PORT
= 3000;
3408 wxSocketServer
*server
= new wxSocketServer(addr
);
3409 if ( !server
->Ok() )
3411 wxPuts(_T("ERROR: failed to bind"));
3419 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
3421 wxSocketBase
*socket
= server
->Accept();
3424 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
3428 wxPuts(_T("Server: got a client."));
3430 server
->SetTimeout(60); // 1 min
3433 while ( !close
&& socket
->IsConnected() )
3436 wxChar ch
= _T('\0');
3439 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
3441 // don't log error if the client just close the connection
3442 if ( socket
->IsConnected() )
3444 wxPuts(_T("ERROR: in wxSocket::Read."));
3464 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
3465 if ( s
== _T("close") )
3467 wxPuts(_T("Closing connection"));
3471 else if ( s
== _T("quit") )
3476 wxPuts(_T("Shutting down the server"));
3478 else // not a special command
3480 socket
->Write(s
.MakeUpper().c_str(), s
.length());
3481 socket
->Write("\r\n", 2);
3482 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
3488 wxPuts(_T("Server: lost a client unexpectedly."));
3494 // same as "delete server" but is consistent with GUI programs
3498 static void TestSocketClient()
3500 wxPuts(_T("*** Testing wxSocketClient ***\n"));
3502 static const wxChar
*hostname
= _T("www.wxwindows.org");
3505 addr
.Hostname(hostname
);
3508 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
3510 wxSocketClient client
;
3511 if ( !client
.Connect(addr
) )
3513 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3517 wxPrintf(_T("--- Connected to %s:%u...\n"),
3518 addr
.Hostname().c_str(), addr
.Service());
3522 // could use simply "GET" here I suppose
3524 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
3525 client
.Write(cmdGet
, cmdGet
.length());
3526 wxPrintf(_T("--- Sent command '%s' to the server\n"),
3527 MakePrintable(cmdGet
).c_str());
3528 client
.Read(buf
, WXSIZEOF(buf
));
3529 wxPrintf(_T("--- Server replied:\n%s"), buf
);
3533 #endif // TEST_SOCKETS
3535 // ----------------------------------------------------------------------------
3537 // ----------------------------------------------------------------------------
3541 #include "wx/protocol/ftp.h"
3545 #define FTP_ANONYMOUS
3547 #ifdef FTP_ANONYMOUS
3548 static const wxChar
*directory
= _T("/pub");
3549 static const wxChar
*filename
= _T("welcome.msg");
3551 static const wxChar
*directory
= _T("/etc");
3552 static const wxChar
*filename
= _T("issue");
3555 static bool TestFtpConnect()
3557 wxPuts(_T("*** Testing FTP connect ***"));
3559 #ifdef FTP_ANONYMOUS
3560 static const wxChar
*hostname
= _T("ftp.wxwindows.org");
3562 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
3563 #else // !FTP_ANONYMOUS
3564 static const wxChar
*hostname
= "localhost";
3567 wxFgets(user
, WXSIZEOF(user
), stdin
);
3568 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
3571 wxChar password
[256];
3572 wxPrintf(_T("Password for %s: "), password
);
3573 wxFgets(password
, WXSIZEOF(password
), stdin
);
3574 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
3575 ftp
.SetPassword(password
);
3577 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
3578 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
3580 if ( !ftp
.Connect(hostname
) )
3582 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3588 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
3589 hostname
, ftp
.Pwd().c_str());
3595 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
3596 static void TestFtpWuFtpd()
3599 static const wxChar
*hostname
= _T("ftp.eudora.com");
3600 if ( !ftp
.Connect(hostname
) )
3602 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3606 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
3607 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3610 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3614 size_t size
= in
->GetSize();
3615 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3617 wxChar
*data
= new wxChar
[size
];
3618 if ( !in
->Read(data
, size
) )
3620 wxPuts(_T("ERROR: read error"));
3624 wxPrintf(_T("Successfully retrieved the file.\n"));
3633 static void TestFtpList()
3635 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
3638 if ( !ftp
.ChDir(directory
) )
3640 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3643 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3645 // test NLIST and LIST
3646 wxArrayString files
;
3647 if ( !ftp
.GetFilesList(files
) )
3649 wxPuts(_T("ERROR: failed to get NLIST of files"));
3653 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
3654 size_t count
= files
.GetCount();
3655 for ( size_t n
= 0; n
< count
; n
++ )
3657 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3659 wxPuts(_T("End of the file list"));
3662 if ( !ftp
.GetDirList(files
) )
3664 wxPuts(_T("ERROR: failed to get LIST of files"));
3668 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
3669 size_t count
= files
.GetCount();
3670 for ( size_t n
= 0; n
< count
; n
++ )
3672 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3674 wxPuts(_T("End of the file list"));
3677 if ( !ftp
.ChDir(_T("..")) )
3679 wxPuts(_T("ERROR: failed to cd to .."));
3682 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3685 static void TestFtpDownload()
3687 wxPuts(_T("*** Testing wxFTP download ***\n"));
3690 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3693 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3697 size_t size
= in
->GetSize();
3698 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3701 wxChar
*data
= new wxChar
[size
];
3702 if ( !in
->Read(data
, size
) )
3704 wxPuts(_T("ERROR: read error"));
3708 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
3716 static void TestFtpFileSize()
3718 wxPuts(_T("*** Testing FTP SIZE command ***"));
3720 if ( !ftp
.ChDir(directory
) )
3722 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3725 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3727 if ( ftp
.FileExists(filename
) )
3729 int size
= ftp
.GetFileSize(filename
);
3731 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
3733 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
3737 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
3741 static void TestFtpMisc()
3743 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
3745 if ( ftp
.SendCommand(_T("STAT")) != '2' )
3747 wxPuts(_T("ERROR: STAT failed"));
3751 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
3754 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
3756 wxPuts(_T("ERROR: HELP SITE failed"));
3760 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
3761 ftp
.GetLastResult().c_str());
3765 static void TestFtpInteractive()
3767 wxPuts(_T("\n*** Interactive wxFTP test ***"));
3773 wxPrintf(_T("Enter FTP command: "));
3774 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3777 // kill the last '\n'
3778 buf
[wxStrlen(buf
) - 1] = 0;
3780 // special handling of LIST and NLST as they require data connection
3781 wxString
start(buf
, 4);
3783 if ( start
== _T("LIST") || start
== _T("NLST") )
3786 if ( wxStrlen(buf
) > 4 )
3789 wxArrayString files
;
3790 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
3792 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
3796 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
3797 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
3798 size_t count
= files
.GetCount();
3799 for ( size_t n
= 0; n
< count
; n
++ )
3801 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3803 wxPuts(_T("--- End of the file list"));
3808 wxChar ch
= ftp
.SendCommand(buf
);
3809 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
3812 wxPrintf(_T(" (return code %c)"), ch
);
3815 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
3819 wxPuts(_T("\n*** done ***"));
3822 static void TestFtpUpload()
3824 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
3827 static const wxChar
*file1
= _T("test1");
3828 static const wxChar
*file2
= _T("test2");
3829 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
3832 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3833 out
->Write("First hello", 11);
3837 // send a command to check the remote file
3838 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
3840 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
3844 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
3845 file1
, ftp
.GetLastResult().c_str());
3848 out
= ftp
.GetOutputStream(file2
);
3851 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3852 out
->Write("Second hello", 12);
3859 // ----------------------------------------------------------------------------
3861 // ----------------------------------------------------------------------------
3865 #include "wx/wfstream.h"
3866 #include "wx/mstream.h"
3868 static void TestFileStream()
3870 wxPuts(_T("*** Testing wxFileInputStream ***"));
3872 static const wxChar
*filename
= _T("testdata.fs");
3874 wxFileOutputStream
fsOut(filename
);
3875 fsOut
.Write("foo", 3);
3878 wxFileInputStream
fsIn(filename
);
3879 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
3880 while ( !fsIn
.Eof() )
3882 putchar(fsIn
.GetC());
3885 if ( !wxRemoveFile(filename
) )
3887 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
);
3890 wxPuts(_T("\n*** wxFileInputStream test done ***"));
3893 static void TestMemoryStream()
3895 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3897 wxMemoryOutputStream memOutStream
;
3898 wxPrintf(_T("Initially out stream offset: %lu\n"),
3899 (unsigned long)memOutStream
.TellO());
3901 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
3903 memOutStream
.PutC(*p
);
3906 wxPrintf(_T("Final out stream offset: %lu\n"),
3907 (unsigned long)memOutStream
.TellO());
3909 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
3912 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
3914 wxMemoryInputStream
memInpStream(buf
, len
);
3915 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3916 while ( !memInpStream
.Eof() )
3918 putchar(memInpStream
.GetC());
3921 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
3924 #endif // TEST_STREAMS
3926 // ----------------------------------------------------------------------------
3928 // ----------------------------------------------------------------------------
3932 #include "wx/timer.h"
3933 #include "wx/utils.h"
3935 static void TestStopWatch()
3937 wxPuts(_T("*** Testing wxStopWatch ***\n"));
3941 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
3944 wxPrintf(_T("\t%ldms\n"), sw
.Time());
3946 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
3950 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3953 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
3956 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3959 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
3962 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3965 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
3966 for ( size_t n
= 0; n
< 70; n
++ )
3970 for ( size_t m
= 0; m
< 100000; m
++ )
3972 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3974 wxPuts(_T("\ntime is negative - ERROR!"));
3982 wxPuts(_T(", ok."));
3985 #endif // TEST_TIMER
3987 // ----------------------------------------------------------------------------
3989 // ----------------------------------------------------------------------------
3993 #include "wx/vcard.h"
3995 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3998 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
4001 wxPrintf(_T("%s%s"),
4002 wxString(_T('\t'), level
).c_str(),
4003 vcObj
->GetName().c_str());
4006 switch ( vcObj
->GetType() )
4008 case wxVCardObject::String
:
4009 case wxVCardObject::UString
:
4012 vcObj
->GetValue(&val
);
4013 value
<< _T('"') << val
<< _T('"');
4017 case wxVCardObject::Int
:
4020 vcObj
->GetValue(&i
);
4021 value
.Printf(_T("%u"), i
);
4025 case wxVCardObject::Long
:
4028 vcObj
->GetValue(&l
);
4029 value
.Printf(_T("%lu"), l
);
4033 case wxVCardObject::None
:
4036 case wxVCardObject::Object
:
4037 value
= _T("<node>");
4041 value
= _T("<unknown value type>");
4045 wxPrintf(_T(" = %s"), value
.c_str());
4048 DumpVObject(level
+ 1, *vcObj
);
4051 vcObj
= vcard
.GetNextProp(&cookie
);
4055 static void DumpVCardAddresses(const wxVCard
& vcard
)
4057 wxPuts(_T("\nShowing all addresses from vCard:\n"));
4061 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
4065 int flags
= addr
->GetFlags();
4066 if ( flags
& wxVCardAddress::Domestic
)
4068 flagsStr
<< _T("domestic ");
4070 if ( flags
& wxVCardAddress::Intl
)
4072 flagsStr
<< _T("international ");
4074 if ( flags
& wxVCardAddress::Postal
)
4076 flagsStr
<< _T("postal ");
4078 if ( flags
& wxVCardAddress::Parcel
)
4080 flagsStr
<< _T("parcel ");
4082 if ( flags
& wxVCardAddress::Home
)
4084 flagsStr
<< _T("home ");
4086 if ( flags
& wxVCardAddress::Work
)
4088 flagsStr
<< _T("work ");
4091 wxPrintf(_T("Address %u:\n")
4093 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
4096 addr
->GetPostOffice().c_str(),
4097 addr
->GetExtAddress().c_str(),
4098 addr
->GetStreet().c_str(),
4099 addr
->GetLocality().c_str(),
4100 addr
->GetRegion().c_str(),
4101 addr
->GetPostalCode().c_str(),
4102 addr
->GetCountry().c_str()
4106 addr
= vcard
.GetNextAddress(&cookie
);
4110 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
4112 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
4116 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
4120 int flags
= phone
->GetFlags();
4121 if ( flags
& wxVCardPhoneNumber::Voice
)
4123 flagsStr
<< _T("voice ");
4125 if ( flags
& wxVCardPhoneNumber::Fax
)
4127 flagsStr
<< _T("fax ");
4129 if ( flags
& wxVCardPhoneNumber::Cellular
)
4131 flagsStr
<< _T("cellular ");
4133 if ( flags
& wxVCardPhoneNumber::Modem
)
4135 flagsStr
<< _T("modem ");
4137 if ( flags
& wxVCardPhoneNumber::Home
)
4139 flagsStr
<< _T("home ");
4141 if ( flags
& wxVCardPhoneNumber::Work
)
4143 flagsStr
<< _T("work ");
4146 wxPrintf(_T("Phone number %u:\n")
4151 phone
->GetNumber().c_str()
4155 phone
= vcard
.GetNextPhoneNumber(&cookie
);
4159 static void TestVCardRead()
4161 wxPuts(_T("*** Testing wxVCard reading ***\n"));
4163 wxVCard
vcard(_T("vcard.vcf"));
4164 if ( !vcard
.IsOk() )
4166 wxPuts(_T("ERROR: couldn't load vCard."));
4170 // read individual vCard properties
4171 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
4175 vcObj
->GetValue(&value
);
4180 value
= _T("<none>");
4183 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
4186 if ( !vcard
.GetFullName(&value
) )
4188 value
= _T("<none>");
4191 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
4193 // now show how to deal with multiply occuring properties
4194 DumpVCardAddresses(vcard
);
4195 DumpVCardPhoneNumbers(vcard
);
4197 // and finally show all
4198 wxPuts(_T("\nNow dumping the entire vCard:\n")
4199 "-----------------------------\n");
4201 DumpVObject(0, vcard
);
4205 static void TestVCardWrite()
4207 wxPuts(_T("*** Testing wxVCard writing ***\n"));
4210 if ( !vcard
.IsOk() )
4212 wxPuts(_T("ERROR: couldn't create vCard."));
4217 vcard
.SetName("Zeitlin", "Vadim");
4218 vcard
.SetFullName("Vadim Zeitlin");
4219 vcard
.SetOrganization("wxWindows", "R&D");
4221 // just dump the vCard back
4222 wxPuts(_T("Entire vCard follows:\n"));
4223 wxPuts(vcard
.Write());
4227 #endif // TEST_VCARD
4229 // ----------------------------------------------------------------------------
4231 // ----------------------------------------------------------------------------
4233 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
4239 #include "wx/volume.h"
4241 static const wxChar
*volumeKinds
[] =
4247 _T("network volume"),
4251 static void TestFSVolume()
4253 wxPuts(_T("*** Testing wxFSVolume class ***"));
4255 wxArrayString volumes
= wxFSVolume::GetVolumes();
4256 size_t count
= volumes
.GetCount();
4260 wxPuts(_T("ERROR: no mounted volumes?"));
4264 wxPrintf(_T("%u mounted volumes found:\n"), count
);
4266 for ( size_t n
= 0; n
< count
; n
++ )
4268 wxFSVolume
vol(volumes
[n
]);
4271 wxPuts(_T("ERROR: couldn't create volume"));
4275 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
4277 vol
.GetDisplayName().c_str(),
4278 vol
.GetName().c_str(),
4279 volumeKinds
[vol
.GetKind()],
4280 vol
.IsWritable() ? _T("rw") : _T("ro"),
4281 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
4286 #endif // TEST_VOLUME
4288 // ----------------------------------------------------------------------------
4289 // wide char and Unicode support
4290 // ----------------------------------------------------------------------------
4294 static void TestUnicodeToFromAscii()
4296 wxPuts(_T("Testing wxString::To/FromAscii()\n"));
4298 static const char *msg
= "Hello, world!";
4299 wxString s
= wxString::FromAscii(msg
);
4301 wxPrintf(_T("Message in Unicode: %s\n"), s
.c_str());
4302 printf("Message in ASCII: %s\n", (const char *)s
.ToAscii());
4304 wxPutchar(_T('\n'));
4307 #include "wx/textfile.h"
4309 static void TestUnicodeTextFileRead()
4311 wxPuts(_T("Testing wxTextFile in Unicode build\n"));
4314 if ( file
.Open(_T("testdata.fc"), wxConvLocal
) )
4316 const size_t count
= file
.GetLineCount();
4317 for ( size_t n
= 0; n
< count
; n
++ )
4319 const wxString
& s
= file
[n
];
4321 wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"),
4322 (unsigned)n
, s
.c_str(), (unsigned)s
.length(), s
.Last());
4327 #endif // TEST_UNICODE
4331 #include "wx/strconv.h"
4332 #include "wx/fontenc.h"
4333 #include "wx/encconv.h"
4334 #include "wx/buffer.h"
4336 static const unsigned char utf8koi8r
[] =
4338 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
4339 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
4340 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
4341 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
4342 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
4343 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
4344 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
4347 static const unsigned char utf8iso8859_1
[] =
4349 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
4350 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
4351 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
4352 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
4353 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
4356 static const unsigned char utf8Invalid
[] =
4358 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
4359 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
4360 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
4361 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
4365 static const struct Utf8Data
4367 const unsigned char *text
;
4369 const wxChar
*charset
;
4370 wxFontEncoding encoding
;
4373 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4374 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
4375 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4378 static void TestUtf8()
4380 wxPuts(_T("*** Testing UTF8 support ***\n"));
4385 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
4387 const Utf8Data
& u8d
= utf8data
[n
];
4388 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
4389 WXSIZEOF(wbuf
)) == (size_t)-1 )
4391 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4395 wxCSConv
conv(u8d
.charset
);
4396 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
4398 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
4402 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
4406 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
4408 s
= _T("<< conversion failed >>");
4409 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
4416 static void TestEncodingConverter()
4418 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
4420 // using wxEncodingConverter should give the same result as above
4423 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
4424 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
4426 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4430 wxEncodingConverter ec
;
4431 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
4432 ec
.Convert(wbuf
, buf
);
4433 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
4439 #endif // TEST_WCHAR
4441 // ----------------------------------------------------------------------------
4443 // ----------------------------------------------------------------------------
4447 #include "wx/filesys.h"
4448 #include "wx/fs_zip.h"
4449 #include "wx/zipstrm.h"
4451 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
4453 static void TestZipStreamRead()
4455 wxPuts(_T("*** Testing ZIP reading ***\n"));
4457 static const wxChar
*filename
= _T("foo");
4458 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
4459 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4461 wxPrintf(_T("Dumping the file '%s':\n"), filename
);
4462 while ( !istr
.Eof() )
4464 putchar(istr
.GetC());
4468 wxPuts(_T("\n----- done ------"));
4471 static void DumpZipDirectory(wxFileSystem
& fs
,
4472 const wxString
& dir
,
4473 const wxString
& indent
)
4475 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
4476 TESTFILE_ZIP
, dir
.c_str());
4477 wxString wildcard
= prefix
+ _T("/*");
4479 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
4480 while ( !dirname
.empty() )
4482 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
4484 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4489 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
4491 DumpZipDirectory(fs
, dirname
,
4492 indent
+ wxString(_T(' '), 4));
4494 dirname
= fs
.FindNext();
4497 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
4498 while ( !filename
.empty() )
4500 if ( !filename
.StartsWith(prefix
, &filename
) )
4502 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4507 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
4509 filename
= fs
.FindNext();
4513 static void TestZipFileSystem()
4515 wxPuts(_T("*** Testing ZIP file system ***\n"));
4517 wxFileSystem::AddHandler(new wxZipFSHandler
);
4519 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
4521 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
4526 // ----------------------------------------------------------------------------
4528 // ----------------------------------------------------------------------------
4532 #include "wx/zstream.h"
4533 #include "wx/wfstream.h"
4535 static const wxChar
*FILENAME_GZ
= _T("test.gz");
4536 static const wxChar
*TEST_DATA
= _T("hello and hello and hello and hello and hello");
4538 static void TestZlibStreamWrite()
4540 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4542 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
4543 wxZlibOutputStream
ostr(fileOutStream
);
4544 wxPrintf(_T("Compressing the test string... "));
4545 ostr
.Write(TEST_DATA
, wxStrlen(TEST_DATA
) + 1);
4548 wxPuts(_T("(ERROR: failed)"));
4555 wxPuts(_T("\n----- done ------"));
4558 static void TestZlibStreamRead()
4560 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4562 wxFileInputStream
fileInStream(FILENAME_GZ
);
4563 wxZlibInputStream
istr(fileInStream
);
4564 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4566 wxPuts(_T("Dumping the file:"));
4567 while ( !istr
.Eof() )
4569 putchar(istr
.GetC());
4573 wxPuts(_T("\n----- done ------"));
4578 // ----------------------------------------------------------------------------
4580 // ----------------------------------------------------------------------------
4584 #include "wx/wfstream.h"
4585 #include "wx/gzstream.h"
4586 #include "wx/filename.h"
4587 #include "wx/txtstrm.h"
4589 // Reads two input streams and verifies that they are the same (and non-emtpy)
4591 void GzipVerify(wxInputStream
&in1
, wxInputStream
&in2
)
4594 wxPuts(_T(" Can't verify"));
4598 const int BUFSIZE
= 8192;
4599 wxCharBuffer
buf1(BUFSIZE
);
4600 wxCharBuffer
buf2(BUFSIZE
);
4604 int n1
= in1
.Read(buf1
.data(), BUFSIZE
).LastRead();
4605 int n2
= in2
.Read(buf2
.data(), BUFSIZE
).LastRead();
4607 if (n1
!= n2
|| (n1
&& memcmp(buf1
, buf2
, n1
) != 0) || (!n1
&& none
)) {
4608 wxPuts(_T(" Failure"));
4613 wxPuts(_T(" Success"));
4621 in1
.Read(buf1
.data(), BUFSIZE
);
4623 in2
.Read(buf2
.data(), BUFSIZE
);
4626 // Write a gzip file and read it back.
4630 wxPuts(_T("*** Testing gzip streams ***\n"));
4632 const wxString testname
= _T("gziptest");
4633 const wxString gzipname
= testname
+ _T(".gz");
4635 // write some random test data to a testfile
4636 wxPuts(_T("Writing random test data to ") + testname
+ _T("..."));
4638 wxFFileOutputStream
outstream(testname
);
4639 wxTextOutputStream
textout(outstream
);
4641 for (int i
= 0; i
< 1000 && outstream
.Ok(); i
++)
4642 textout
<< rand() << rand() << rand() << rand() << endl
;
4644 wxPuts(_T(" Done"));
4647 wxFileName
fn(testname
);
4648 wxDateTime dt
= fn
.GetModificationTime();
4649 wxFFileInputStream
instream(testname
);
4651 // try writing a gzip file
4652 wxPuts(_T("Writing ") + gzipname
+ _T(" using wxGzipOutputStream..."));
4654 wxFFileOutputStream
outstream(gzipname
);
4655 wxGzipOutputStream
gzip(outstream
, testname
, dt
);
4657 if (!gzip
.Write(instream
))
4658 wxPuts(_T(" Failure"));
4660 wxPuts(_T(" Success"));
4663 // try reading the gzip file
4664 wxPuts(_T("Reading ") + gzipname
+ _T(" using wxGzipInputStream..."));
4667 wxFFileInputStream
instream2(gzipname
);
4668 wxGzipInputStream
gzip(instream2
);
4669 GzipVerify(instream
, gzip
);
4671 if (gzip
.GetName() != fn
.GetFullName())
4672 wxPuts(gzipname
+ _T(" contains incorrect filename: ")
4674 if (dt
.IsValid() && gzip
.GetDateTime() != dt
)
4675 wxPuts(gzipname
+ _T(" contains incorrect timestamp: ")
4676 + gzip
.GetDateTime().Format());
4680 // then verify it using gzip program if it is in the path
4681 wxPuts(_T("Reading ") + gzipname
+ _T(" using gzip program..."));
4682 wxFFile
file(popen((_T("gzip -d -c ") + gzipname
).mb_str(), "r"));
4684 wxFFileInputStream
instream2(file
);
4686 GzipVerify(instream
, instream2
);
4691 // try reading a gzip created by gzip program
4692 wxPuts(_T("Reading output of gzip program using wxGzipInputStream..."));
4693 file
.Attach(popen((_T("gzip -c ") + testname
).mb_str(), "r"));
4695 wxFFileInputStream
instream2(file
);
4696 wxGzipInputStream
gzip(instream2
);
4698 GzipVerify(instream
, gzip
);
4704 wxPuts(_T("\n--- Done gzip streams ---"));
4709 // ----------------------------------------------------------------------------
4711 // ----------------------------------------------------------------------------
4713 #ifdef TEST_DATETIME
4717 #include "wx/datetime.h"
4722 wxDateTime::wxDateTime_t day
;
4723 wxDateTime::Month month
;
4725 wxDateTime::wxDateTime_t hour
, min
, sec
;
4727 wxDateTime::WeekDay wday
;
4728 time_t gmticks
, ticks
;
4730 void Init(const wxDateTime::Tm
& tm
)
4739 gmticks
= ticks
= -1;
4742 wxDateTime
DT() const
4743 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
4745 bool SameDay(const wxDateTime::Tm
& tm
) const
4747 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
4750 wxString
Format() const
4753 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
4755 wxDateTime::GetMonthName(month
).c_str(),
4757 abs(wxDateTime::ConvertYearToBC(year
)),
4758 year
> 0 ? _T("AD") : _T("BC"));
4762 wxString
FormatDate() const
4765 s
.Printf(_T("%02d-%s-%4d%s"),
4767 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4768 abs(wxDateTime::ConvertYearToBC(year
)),
4769 year
> 0 ? _T("AD") : _T("BC"));
4774 static const Date testDates
[] =
4776 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
4777 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
4778 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
4779 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
4780 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
4781 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
4782 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
4783 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
4784 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
4785 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
4786 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
4787 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
4788 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
4789 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
4790 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
4791 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
4792 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
4793 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
4794 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
4797 // this test miscellaneous static wxDateTime functions
4798 static void TestTimeStatic()
4800 wxPuts(_T("\n*** wxDateTime static methods test ***"));
4802 // some info about the current date
4803 int year
= wxDateTime::GetCurrentYear();
4804 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
4806 wxDateTime::IsLeapYear(year
) ? "" : "not ",
4807 wxDateTime::GetNumberOfDays(year
));
4809 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
4810 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
4811 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4812 wxDateTime::GetMonthName(month
).c_str(),
4813 wxDateTime::GetNumberOfDays(month
));
4816 static const size_t nYears
= 5;
4817 static const size_t years
[2][nYears
] =
4819 // first line: the years to test
4820 { 1990, 1976, 2000, 2030, 1984, },
4822 // second line: true if leap, false otherwise
4823 { false, true, true, false, true }
4826 for ( size_t n
= 0; n
< nYears
; n
++ )
4828 int year
= years
[0][n
];
4829 bool should
= years
[1][n
] != 0,
4830 is
= wxDateTime::IsLeapYear(year
);
4832 wxPrintf(_T("Year %d is %sa leap year (%s)\n"),
4835 should
== is
? "ok" : "ERROR");
4837 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
4841 // test constructing wxDateTime objects
4842 static void TestTimeSet()
4844 wxPuts(_T("\n*** wxDateTime construction test ***"));
4846 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4848 const Date
& d1
= testDates
[n
];
4849 wxDateTime dt
= d1
.DT();
4852 d2
.Init(dt
.GetTm());
4854 wxString s1
= d1
.Format(),
4857 wxPrintf(_T("Date: %s == %s (%s)\n"),
4858 s1
.c_str(), s2
.c_str(),
4859 s1
== s2
? _T("ok") : _T("ERROR"));
4863 // test time zones stuff
4864 static void TestTimeZones()
4866 wxPuts(_T("\n*** wxDateTime timezone test ***"));
4868 wxDateTime now
= wxDateTime::Now();
4870 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
4871 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
4872 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
4873 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
4874 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
4875 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
4877 wxDateTime::Tm tm
= now
.GetTm();
4878 if ( wxDateTime(tm
) != now
)
4880 wxPrintf(_T("ERROR: got %s instead of %s\n"),
4881 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
4885 // test some minimal support for the dates outside the standard range
4886 static void TestTimeRange()
4888 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
4890 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
4892 wxPrintf(_T("Unix epoch:\t%s\n"),
4893 wxDateTime(2440587.5).Format(fmt
).c_str());
4894 wxPrintf(_T("Feb 29, 0: \t%s\n"),
4895 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
4896 wxPrintf(_T("JDN 0: \t%s\n"),
4897 wxDateTime(0.0).Format(fmt
).c_str());
4898 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
4899 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
4900 wxPrintf(_T("May 29, 2099:\t%s\n"),
4901 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
4904 static void TestTimeTicks()
4906 wxPuts(_T("\n*** wxDateTime ticks test ***"));
4908 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4910 const Date
& d
= testDates
[n
];
4911 if ( d
.ticks
== -1 )
4914 wxDateTime dt
= d
.DT();
4915 long ticks
= (dt
.GetValue() / 1000).ToLong();
4916 wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4917 if ( ticks
== d
.ticks
)
4919 wxPuts(_T(" (ok)"));
4923 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4924 (long)d
.ticks
, (long)(ticks
- d
.ticks
));
4927 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
4928 ticks
= (dt
.GetValue() / 1000).ToLong();
4929 wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4930 if ( ticks
== d
.gmticks
)
4932 wxPuts(_T(" (ok)"));
4936 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4937 (long)d
.gmticks
, (long)(ticks
- d
.gmticks
));
4944 // test conversions to JDN &c
4945 static void TestTimeJDN()
4947 wxPuts(_T("\n*** wxDateTime to JDN test ***"));
4949 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4951 const Date
& d
= testDates
[n
];
4952 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4953 double jdn
= dt
.GetJulianDayNumber();
4955 wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
);
4958 wxPuts(_T(" (ok)"));
4962 wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"),
4963 d
.jdn
, jdn
- d
.jdn
);
4968 // test week days computation
4969 static void TestTimeWDays()
4971 wxPuts(_T("\n*** wxDateTime weekday test ***"));
4973 // test GetWeekDay()
4975 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4977 const Date
& d
= testDates
[n
];
4978 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4980 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
4981 wxPrintf(_T("%s is: %s"),
4983 wxDateTime::GetWeekDayName(wday
).c_str());
4984 if ( wday
== d
.wday
)
4986 wxPuts(_T(" (ok)"));
4990 wxPrintf(_T(" (ERROR: should be %s)\n"),
4991 wxDateTime::GetWeekDayName(d
.wday
).c_str());
4997 // test SetToWeekDay()
4998 struct WeekDateTestData
5000 Date date
; // the real date (precomputed)
5001 int nWeek
; // its week index in the month
5002 wxDateTime::WeekDay wday
; // the weekday
5003 wxDateTime::Month month
; // the month
5004 int year
; // and the year
5006 wxString
Format() const
5009 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
5011 case 1: which
= _T("first"); break;
5012 case 2: which
= _T("second"); break;
5013 case 3: which
= _T("third"); break;
5014 case 4: which
= _T("fourth"); break;
5015 case 5: which
= _T("fifth"); break;
5017 case -1: which
= _T("last"); break;
5022 which
+= _T(" from end");
5025 s
.Printf(_T("The %s %s of %s in %d"),
5027 wxDateTime::GetWeekDayName(wday
).c_str(),
5028 wxDateTime::GetMonthName(month
).c_str(),
5035 // the array data was generated by the following python program
5037 from DateTime import *
5038 from whrandom import *
5039 from string import *
5041 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
5042 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
5044 week = DateTimeDelta(7)
5047 year = randint(1900, 2100)
5048 month = randint(1, 12)
5049 day = randint(1, 28)
5050 dt = DateTime(year, month, day)
5051 wday = dt.day_of_week
5053 countFromEnd = choice([-1, 1])
5056 while dt.month is month:
5057 dt = dt - countFromEnd * week
5058 weekNum = weekNum + countFromEnd
5060 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
5062 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
5063 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
5066 static const WeekDateTestData weekDatesTestData
[] =
5068 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
5069 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
5070 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
5071 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
5072 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
5073 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
5074 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
5075 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
5076 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
5077 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
5078 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
5079 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
5080 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
5081 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
5082 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
5083 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
5084 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
5085 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
5086 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
5087 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
5090 static const wxChar
*fmt
= _T("%d-%b-%Y");
5093 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
5095 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
5097 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
5099 wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str());
5101 const Date
& d
= wd
.date
;
5102 if ( d
.SameDay(dt
.GetTm()) )
5104 wxPuts(_T(" (ok)"));
5108 dt
.Set(d
.day
, d
.month
, d
.year
);
5110 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str());
5115 // test the computation of (ISO) week numbers
5116 static void TestTimeWNumber()
5118 wxPuts(_T("\n*** wxDateTime week number test ***"));
5120 struct WeekNumberTestData
5122 Date date
; // the date
5123 wxDateTime::wxDateTime_t week
; // the week number in the year
5124 wxDateTime::wxDateTime_t wmon
; // the week number in the month
5125 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
5126 wxDateTime::wxDateTime_t dnum
; // day number in the year
5129 // data generated with the following python script:
5131 from DateTime import *
5132 from whrandom import *
5133 from string import *
5135 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
5136 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
5138 def GetMonthWeek(dt):
5139 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
5140 if weekNumMonth < 0:
5141 weekNumMonth = weekNumMonth + 53
5144 def GetLastSundayBefore(dt):
5145 if dt.iso_week[2] == 7:
5148 return dt - DateTimeDelta(dt.iso_week[2])
5151 year = randint(1900, 2100)
5152 month = randint(1, 12)
5153 day = randint(1, 28)
5154 dt = DateTime(year, month, day)
5155 dayNum = dt.day_of_year
5156 weekNum = dt.iso_week[1]
5157 weekNumMonth = GetMonthWeek(dt)
5160 dtSunday = GetLastSundayBefore(dt)
5162 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
5163 weekNumMonth2 = weekNumMonth2 + 1
5164 dtSunday = dtSunday - DateTimeDelta(7)
5166 data = { 'day': rjust(`day`, 2), \
5167 'month': monthNames[month - 1], \
5169 'weekNum': rjust(`weekNum`, 2), \
5170 'weekNumMonth': weekNumMonth, \
5171 'weekNumMonth2': weekNumMonth2, \
5172 'dayNum': rjust(`dayNum`, 3) }
5174 print " { { %(day)s, "\
5175 "wxDateTime::%(month)s, "\
5178 "%(weekNumMonth)s, "\
5179 "%(weekNumMonth2)s, "\
5180 "%(dayNum)s }," % data
5183 static const WeekNumberTestData weekNumberTestDates
[] =
5185 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
5186 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
5187 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
5188 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
5189 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
5190 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
5191 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
5192 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
5193 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
5194 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
5195 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
5196 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
5197 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
5198 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
5199 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
5200 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
5201 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
5202 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
5203 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
5204 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
5207 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
5209 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
5210 const Date
& d
= wn
.date
;
5212 wxDateTime dt
= d
.DT();
5214 wxDateTime::wxDateTime_t
5215 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
5216 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
5217 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
5218 dnum
= dt
.GetDayOfYear();
5220 wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
);
5221 if ( dnum
== wn
.dnum
)
5223 wxPrintf(_T(" (ok)"));
5227 wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
);
5230 wxPrintf(_T(", week in month = %d"), wmon
);
5231 if ( wmon
!= wn
.wmon
)
5233 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
);
5236 wxPrintf(_T(" or %d"), wmon2
);
5237 if ( wmon2
== wn
.wmon2
)
5239 wxPrintf(_T(" (ok)"));
5243 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
);
5246 wxPrintf(_T(", week in year = %d"), week
);
5247 if ( week
!= wn
.week
)
5249 wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
);
5252 wxPutchar(_T('\n'));
5254 wxDateTime
dt2(1, wxDateTime::Jan
, d
.year
);
5255 dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay());
5259 d2
.Init(dt2
.GetTm());
5260 wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"),
5261 d2
.FormatDate().c_str());
5266 // test DST calculations
5267 static void TestTimeDST()
5269 wxPuts(_T("\n*** wxDateTime DST test ***"));
5271 wxPrintf(_T("DST is%s in effect now.\n\n"),
5272 wxDateTime::Now().IsDST() ? _T("") : _T(" not"));
5274 // taken from http://www.energy.ca.gov/daylightsaving.html
5275 static const Date datesDST
[2][2004 - 1900 + 1] =
5278 { 1, wxDateTime::Apr
, 1990 },
5279 { 7, wxDateTime::Apr
, 1991 },
5280 { 5, wxDateTime::Apr
, 1992 },
5281 { 4, wxDateTime::Apr
, 1993 },
5282 { 3, wxDateTime::Apr
, 1994 },
5283 { 2, wxDateTime::Apr
, 1995 },
5284 { 7, wxDateTime::Apr
, 1996 },
5285 { 6, wxDateTime::Apr
, 1997 },
5286 { 5, wxDateTime::Apr
, 1998 },
5287 { 4, wxDateTime::Apr
, 1999 },
5288 { 2, wxDateTime::Apr
, 2000 },
5289 { 1, wxDateTime::Apr
, 2001 },
5290 { 7, wxDateTime::Apr
, 2002 },
5291 { 6, wxDateTime::Apr
, 2003 },
5292 { 4, wxDateTime::Apr
, 2004 },
5295 { 28, wxDateTime::Oct
, 1990 },
5296 { 27, wxDateTime::Oct
, 1991 },
5297 { 25, wxDateTime::Oct
, 1992 },
5298 { 31, wxDateTime::Oct
, 1993 },
5299 { 30, wxDateTime::Oct
, 1994 },
5300 { 29, wxDateTime::Oct
, 1995 },
5301 { 27, wxDateTime::Oct
, 1996 },
5302 { 26, wxDateTime::Oct
, 1997 },
5303 { 25, wxDateTime::Oct
, 1998 },
5304 { 31, wxDateTime::Oct
, 1999 },
5305 { 29, wxDateTime::Oct
, 2000 },
5306 { 28, wxDateTime::Oct
, 2001 },
5307 { 27, wxDateTime::Oct
, 2002 },
5308 { 26, wxDateTime::Oct
, 2003 },
5309 { 31, wxDateTime::Oct
, 2004 },
5314 for ( year
= 1990; year
< 2005; year
++ )
5316 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
5317 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
5319 wxPrintf(_T("DST period in the US for year %d: from %s to %s"),
5320 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
5322 size_t n
= year
- 1990;
5323 const Date
& dBegin
= datesDST
[0][n
];
5324 const Date
& dEnd
= datesDST
[1][n
];
5326 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
5328 wxPuts(_T(" (ok)"));
5332 wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"),
5333 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
5334 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
5340 for ( year
= 1990; year
< 2005; year
++ )
5342 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
5344 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
5345 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
5349 // test wxDateTime -> text conversion
5350 static void TestTimeFormat()
5352 wxPuts(_T("\n*** wxDateTime formatting test ***"));
5354 // some information may be lost during conversion, so store what kind
5355 // of info should we recover after a round trip
5358 CompareNone
, // don't try comparing
5359 CompareBoth
, // dates and times should be identical
5360 CompareDate
, // dates only
5361 CompareTime
// time only
5366 CompareKind compareKind
;
5367 const wxChar
*format
;
5368 } formatTestFormats
[] =
5370 { CompareBoth
, _T("---> %c") },
5371 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
5372 { CompareBoth
, _T("Date is %x, time is %X") },
5373 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
5374 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
5375 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
5378 static const Date formatTestDates
[] =
5380 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
5381 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
5383 // this test can't work for other centuries because it uses two digit
5384 // years in formats, so don't even try it
5385 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
5386 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
5387 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
5391 // an extra test (as it doesn't depend on date, don't do it in the loop)
5392 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
5394 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
5398 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
5399 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
5401 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
5402 wxPrintf(_T("%s"), s
.c_str());
5404 // what can we recover?
5405 int kind
= formatTestFormats
[n
].compareKind
;
5409 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
5412 // converion failed - should it have?
5413 if ( kind
== CompareNone
)
5414 wxPuts(_T(" (ok)"));
5416 wxPuts(_T(" (ERROR: conversion back failed)"));
5420 // should have parsed the entire string
5421 wxPuts(_T(" (ERROR: conversion back stopped too soon)"));
5425 bool equal
= false; // suppress compilaer warning
5433 equal
= dt
.IsSameDate(dt2
);
5437 equal
= dt
.IsSameTime(dt2
);
5443 wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"),
5444 dt2
.Format().c_str(), dt
.Format().c_str());
5448 wxPuts(_T(" (ok)"));
5455 // test text -> wxDateTime conversion
5456 static void TestTimeParse()
5458 wxPuts(_T("\n*** wxDateTime parse test ***"));
5460 struct ParseTestData
5462 const wxChar
*format
;
5467 static const ParseTestData parseTestDates
[] =
5469 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
5470 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
5473 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
5475 const wxChar
*format
= parseTestDates
[n
].format
;
5477 wxPrintf(_T("%s => "), format
);
5480 if ( dt
.ParseRfc822Date(format
) )
5482 wxPrintf(_T("%s "), dt
.Format().c_str());
5484 if ( parseTestDates
[n
].good
)
5486 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
5493 wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str());
5498 wxPuts(_T("(ERROR: bad format)"));
5503 wxPrintf(_T("bad format (%s)\n"),
5504 parseTestDates
[n
].good
? "ERROR" : "ok");
5509 static void TestDateTimeInteractive()
5511 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
5517 wxPrintf(_T("Enter a date: "));
5518 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
5521 // kill the last '\n'
5522 buf
[wxStrlen(buf
) - 1] = 0;
5525 const wxChar
*p
= dt
.ParseDate(buf
);
5528 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
5534 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
5537 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
5538 dt
.Format(_T("%b %d, %Y")).c_str(),
5540 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
5541 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
5542 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
5545 wxPuts(_T("\n*** done ***"));
5548 static void TestTimeMS()
5550 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
5552 wxDateTime dt1
= wxDateTime::Now(),
5553 dt2
= wxDateTime::UNow();
5555 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
5556 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5557 wxPrintf(_T("Dummy loop: "));
5558 for ( int i
= 0; i
< 6000; i
++ )
5560 //for ( int j = 0; j < 10; j++ )
5563 s
.Printf(_T("%g"), sqrt(i
));
5569 wxPuts(_T(", done"));
5572 dt2
= wxDateTime::UNow();
5573 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5575 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
5577 wxPuts(_T("\n*** done ***"));
5580 static void TestTimeArithmetics()
5582 wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***"));
5584 static const struct ArithmData
5586 ArithmData(const wxDateSpan
& sp
, const wxChar
*nam
)
5587 : span(sp
), name(nam
) { }
5591 } testArithmData
[] =
5593 ArithmData(wxDateSpan::Day(), _T("day")),
5594 ArithmData(wxDateSpan::Week(), _T("week")),
5595 ArithmData(wxDateSpan::Month(), _T("month")),
5596 ArithmData(wxDateSpan::Year(), _T("year")),
5597 ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")),
5600 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
5602 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
5604 wxDateSpan span
= testArithmData
[n
].span
;
5608 const wxChar
*name
= testArithmData
[n
].name
;
5609 wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"),
5610 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
5611 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
5613 wxPrintf(_T("Going back: %s"), (dt1
- span
).FormatISODate().c_str());
5614 if ( dt1
- span
== dt
)
5616 wxPuts(_T(" (ok)"));
5620 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5623 wxPrintf(_T("Going forward: %s"), (dt2
+ span
).FormatISODate().c_str());
5624 if ( dt2
+ span
== dt
)
5626 wxPuts(_T(" (ok)"));
5630 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5633 wxPrintf(_T("Double increment: %s"), (dt2
+ 2*span
).FormatISODate().c_str());
5634 if ( dt2
+ 2*span
== dt1
)
5636 wxPuts(_T(" (ok)"));
5640 wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str());
5647 static void TestTimeHolidays()
5649 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
5651 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
5652 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
5653 dtEnd
= dtStart
.GetLastMonthDay();
5655 wxDateTimeArray hol
;
5656 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
5658 const wxChar
*format
= _T("%d-%b-%Y (%a)");
5660 wxPrintf(_T("All holidays between %s and %s:\n"),
5661 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
5663 size_t count
= hol
.GetCount();
5664 for ( size_t n
= 0; n
< count
; n
++ )
5666 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
5672 static void TestTimeZoneBug()
5674 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
5676 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
5677 for ( int i
= 0; i
< 31; i
++ )
5679 wxPrintf(_T("Date %s: week day %s.\n"),
5680 date
.Format(_T("%d-%m-%Y")).c_str(),
5681 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
5683 date
+= wxDateSpan::Day();
5689 static void TestTimeSpanFormat()
5691 wxPuts(_T("\n*** wxTimeSpan tests ***"));
5693 static const wxChar
*formats
[] =
5695 _T("(default) %H:%M:%S"),
5696 _T("%E weeks and %D days"),
5697 _T("%l milliseconds"),
5698 _T("(with ms) %H:%M:%S:%l"),
5699 _T("100%% of minutes is %M"), // test "%%"
5700 _T("%D days and %H hours"),
5701 _T("or also %S seconds"),
5704 wxTimeSpan
ts1(1, 2, 3, 4),
5706 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
5708 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
5709 ts1
.Format(formats
[n
]).c_str(),
5710 ts2
.Format(formats
[n
]).c_str());
5716 #endif // TEST_DATETIME
5718 // ----------------------------------------------------------------------------
5719 // wxTextInput/OutputStream
5720 // ----------------------------------------------------------------------------
5722 #ifdef TEST_TEXTSTREAM
5724 #include "wx/txtstrm.h"
5725 #include "wx/wfstream.h"
5727 static void TestTextInputStream()
5729 wxPuts(_T("\n*** wxTextInputStream test ***"));
5731 wxFileInputStream
fsIn(_T("testdata.fc"));
5734 wxPuts(_T("ERROR: couldn't open file."));
5738 wxTextInputStream
tis(fsIn
);
5743 const wxString s
= tis
.ReadLine();
5745 // line could be non empty if the last line of the file isn't
5746 // terminated with EOL
5747 if ( fsIn
.Eof() && s
.empty() )
5750 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
5755 #endif // TEST_TEXTSTREAM
5757 // ----------------------------------------------------------------------------
5759 // ----------------------------------------------------------------------------
5763 #include "wx/thread.h"
5765 static size_t gs_counter
= (size_t)-1;
5766 static wxCriticalSection gs_critsect
;
5767 static wxSemaphore gs_cond
;
5769 class MyJoinableThread
: public wxThread
5772 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
5773 { m_n
= n
; Create(); }
5775 // thread execution starts here
5776 virtual ExitCode
Entry();
5782 wxThread::ExitCode
MyJoinableThread::Entry()
5784 unsigned long res
= 1;
5785 for ( size_t n
= 1; n
< m_n
; n
++ )
5789 // it's a loooong calculation :-)
5793 return (ExitCode
)res
;
5796 class MyDetachedThread
: public wxThread
5799 MyDetachedThread(size_t n
, wxChar ch
)
5803 m_cancelled
= false;
5808 // thread execution starts here
5809 virtual ExitCode
Entry();
5812 virtual void OnExit();
5815 size_t m_n
; // number of characters to write
5816 wxChar m_ch
; // character to write
5818 bool m_cancelled
; // false if we exit normally
5821 wxThread::ExitCode
MyDetachedThread::Entry()
5824 wxCriticalSectionLocker
lock(gs_critsect
);
5825 if ( gs_counter
== (size_t)-1 )
5831 for ( size_t n
= 0; n
< m_n
; n
++ )
5833 if ( TestDestroy() )
5843 wxThread::Sleep(100);
5849 void MyDetachedThread::OnExit()
5851 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
5853 wxCriticalSectionLocker
lock(gs_critsect
);
5854 if ( !--gs_counter
&& !m_cancelled
)
5858 static void TestDetachedThreads()
5860 wxPuts(_T("\n*** Testing detached threads ***"));
5862 static const size_t nThreads
= 3;
5863 MyDetachedThread
*threads
[nThreads
];
5865 for ( n
= 0; n
< nThreads
; n
++ )
5867 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
5870 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
5871 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
5873 for ( n
= 0; n
< nThreads
; n
++ )
5878 // wait until all threads terminate
5884 static void TestJoinableThreads()
5886 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
5888 // calc 10! in the background
5889 MyJoinableThread
thread(10);
5892 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
5893 (unsigned long)thread
.Wait());
5896 static void TestThreadSuspend()
5898 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
5900 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
5904 // this is for this demo only, in a real life program we'd use another
5905 // condition variable which would be signaled from wxThread::Entry() to
5906 // tell us that the thread really started running - but here just wait a
5907 // bit and hope that it will be enough (the problem is, of course, that
5908 // the thread might still not run when we call Pause() which will result
5910 wxThread::Sleep(300);
5912 for ( size_t n
= 0; n
< 3; n
++ )
5916 wxPuts(_T("\nThread suspended"));
5919 // don't sleep but resume immediately the first time
5920 wxThread::Sleep(300);
5922 wxPuts(_T("Going to resume the thread"));
5927 wxPuts(_T("Waiting until it terminates now"));
5929 // wait until the thread terminates
5935 static void TestThreadDelete()
5937 // As above, using Sleep() is only for testing here - we must use some
5938 // synchronisation object instead to ensure that the thread is still
5939 // running when we delete it - deleting a detached thread which already
5940 // terminated will lead to a crash!
5942 wxPuts(_T("\n*** Testing thread delete function ***"));
5944 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
5948 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
5950 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
5954 wxThread::Sleep(300);
5958 wxPuts(_T("\nDeleted a running thread."));
5960 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
5964 wxThread::Sleep(300);
5970 wxPuts(_T("\nDeleted a sleeping thread."));
5972 MyJoinableThread
thread3(20);
5977 wxPuts(_T("\nDeleted a joinable thread."));
5979 MyJoinableThread
thread4(2);
5982 wxThread::Sleep(300);
5986 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
5991 class MyWaitingThread
: public wxThread
5994 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
5997 m_condition
= condition
;
6002 virtual ExitCode
Entry()
6004 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
6009 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
6013 m_condition
->Wait();
6016 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
6024 wxCondition
*m_condition
;
6027 static void TestThreadConditions()
6030 wxCondition
condition(mutex
);
6032 // otherwise its difficult to understand which log messages pertain to
6034 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
6035 // condition.GetId(), gs_cond.GetId());
6037 // create and launch threads
6038 MyWaitingThread
*threads
[10];
6041 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
6043 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
6046 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
6051 // wait until all threads run
6052 wxPuts(_T("Main thread is waiting for the other threads to start"));
6055 size_t nRunning
= 0;
6056 while ( nRunning
< WXSIZEOF(threads
) )
6062 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
6066 wxPuts(_T("Main thread: all threads started up."));
6069 wxThread::Sleep(500);
6072 // now wake one of them up
6073 wxPrintf(_T("Main thread: about to signal the condition.\n"));
6078 wxThread::Sleep(200);
6080 // wake all the (remaining) threads up, so that they can exit
6081 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
6083 condition
.Broadcast();
6085 // give them time to terminate (dirty!)
6086 wxThread::Sleep(500);
6089 #include "wx/utils.h"
6091 class MyExecThread
: public wxThread
6094 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
6100 virtual ExitCode
Entry()
6102 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
6109 static void TestThreadExec()
6111 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
6113 MyExecThread
thread(_T("true"));
6116 wxPrintf(_T("Main program exit code: %ld.\n"),
6117 wxExecute(_T("false"), wxEXEC_SYNC
));
6119 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
6123 #include "wx/datetime.h"
6125 class MySemaphoreThread
: public wxThread
6128 MySemaphoreThread(int i
, wxSemaphore
*sem
)
6129 : wxThread(wxTHREAD_JOINABLE
),
6136 virtual ExitCode
Entry()
6138 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
6139 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6143 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
6144 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6148 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
6149 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6161 WX_DEFINE_ARRAY(wxThread
*, ArrayThreads
);
6163 static void TestSemaphore()
6165 wxPuts(_T("*** Testing wxSemaphore class. ***"));
6167 static const int SEM_LIMIT
= 3;
6169 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
6170 ArrayThreads threads
;
6172 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
6174 threads
.Add(new MySemaphoreThread(i
, &sem
));
6175 threads
.Last()->Run();
6178 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
6185 #endif // TEST_THREADS
6187 // ----------------------------------------------------------------------------
6189 // ----------------------------------------------------------------------------
6193 #include "wx/dynarray.h"
6195 typedef unsigned short ushort
;
6197 static int MyStringCompare(wxString
* s1
, wxString
* s2
)
6199 return wxStrcmp(s1
->c_str(), s2
->c_str());
6202 static int MyStringReverseCompare(wxString
* s1
, wxString
* s2
)
6204 return -wxStrcmp(s1
->c_str(), s2
->c_str());
6208 #define DefineCompare(name, T) \
6210 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
6212 return first - second; \
6215 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
6217 return *first - *second; \
6220 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
6222 return *second - *first; \
6225 DefineCompare(UShort, ushort);
6226 DefineCompare(Int
, int);
6228 // test compilation of all macros
6229 WX_DEFINE_ARRAY_SHORT(ushort
, wxArrayUShort
);
6230 WX_DEFINE_SORTED_ARRAY_SHORT(ushort
, wxSortedArrayUShortNoCmp
);
6231 WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort
, UShortCompareValues
, wxSortedArrayUShort
);
6232 WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues
, wxSortedArrayInt
);
6234 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
6235 #include "wx/arrimpl.cpp"
6236 WX_DEFINE_OBJARRAY(ArrayBars
);
6238 static void PrintArray(const wxChar
* name
, const wxArrayString
& array
)
6240 wxPrintf(_T("Dump of the array '%s'\n"), name
);
6242 size_t nCount
= array
.GetCount();
6243 for ( size_t n
= 0; n
< nCount
; n
++ )
6245 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
6249 static void PrintArray(const wxChar
* name
, const wxSortedArrayString
& array
)
6251 wxPrintf(_T("Dump of the array '%s'\n"), name
);
6253 size_t nCount
= array
.GetCount();
6254 for ( size_t n
= 0; n
< nCount
; n
++ )
6256 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
6260 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
6261 const wxString
& second
)
6263 return first
.length() - second
.length();
6266 #define TestArrayOf(name) \
6268 static void PrintArray(const wxChar* name, const wxSortedArray##name & array) \
6270 wxPrintf(_T("Dump of the array '%s'\n"), name); \
6272 size_t nCount = array.GetCount(); \
6273 for ( size_t n = 0; n < nCount; n++ ) \
6275 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
6279 static void PrintArray(const wxChar* name, const wxArray##name & array) \
6281 wxPrintf(_T("Dump of the array '%s'\n"), name); \
6283 size_t nCount = array.GetCount(); \
6284 for ( size_t n = 0; n < nCount; n++ ) \
6286 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
6290 static void TestArrayOf ## name ## s() \
6292 wxPrintf(_T("*** Testing wxArray%s ***\n"), #name); \
6300 wxPuts(_T("Initially:")); \
6301 PrintArray(_T("a"), a); \
6303 wxPuts(_T("After sort:")); \
6304 a.Sort(name ## Compare); \
6305 PrintArray(_T("a"), a); \
6307 wxPuts(_T("After reverse sort:")); \
6308 a.Sort(name ## RevCompare); \
6309 PrintArray(_T("a"), a); \
6311 wxSortedArray##name b; \
6317 wxPuts(_T("Sorted array initially:")); \
6318 PrintArray(_T("b"), b); \
6321 TestArrayOf(UShort
);
6324 static void TestStlArray()
6326 wxPuts(_T("*** Testing std::vector operations ***\n"));
6330 wxArrayInt::iterator it
, en
;
6331 wxArrayInt::reverse_iterator rit
, ren
;
6333 for ( i
= 0; i
< 5; ++i
)
6336 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
6337 it
!= en
; ++it
, ++i
)
6339 wxPuts(_T("Error in iterator\n"));
6341 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
6342 rit
!= ren
; ++rit
, --i
)
6344 wxPuts(_T("Error in reverse_iterator\n"));
6346 if ( *list1
.rbegin() != *(list1
.end()-1) ||
6347 *list1
.begin() != *(list1
.rend()-1) )
6348 wxPuts(_T("Error in iterator/reverse_iterator\n"));
6350 it
= list1
.begin()+1;
6351 rit
= list1
.rbegin()+1;
6352 if ( *list1
.begin() != *(it
-1) ||
6353 *list1
.rbegin() != *(rit
-1) )
6354 wxPuts(_T("Error in iterator/reverse_iterator\n"));
6356 if ( list1
.front() != 0 || list1
.back() != 4 )
6357 wxPuts(_T("Error in front()/back()\n"));
6359 list1
.erase(list1
.begin());
6360 list1
.erase(list1
.end()-1);
6362 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
6363 it
!= en
; ++it
, ++i
)
6365 wxPuts(_T("Error in erase()\n"));
6368 wxPuts(_T("*** Testing std::vector operations finished ***\n"));
6371 static void TestArrayOfObjects()
6373 wxPuts(_T("*** Testing wxObjArray ***\n"));
6377 Bar
bar(_T("second bar (two copies!)"));
6379 wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"),
6380 bars
.GetCount(), Bar::GetNumber());
6382 bars
.Add(new Bar(_T("first bar")));
6385 wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"),
6386 bars
.GetCount(), Bar::GetNumber());
6388 bars
.RemoveAt(1, bars
.GetCount() - 1);
6390 wxPrintf(_T("After removing all but first element: %u objects in the ")
6391 _T("array, %u objects total.\n"),
6392 bars
.GetCount(), Bar::GetNumber());
6396 wxPrintf(_T("After Empty(): %u objects in the array, %u objects total.\n"),
6397 bars
.GetCount(), Bar::GetNumber());
6400 wxPrintf(_T("Finally: no more objects in the array, %u objects total.\n"),
6404 #endif // TEST_ARRAYS
6406 // ----------------------------------------------------------------------------
6408 // ----------------------------------------------------------------------------
6412 #include "wx/timer.h"
6413 #include "wx/tokenzr.h"
6415 static void TestStringConstruction()
6417 wxPuts(_T("*** Testing wxString constructores ***"));
6419 #define TEST_CTOR(args, res) \
6422 wxPrintf(_T("wxString%s = %s "), #args, s.c_str()); \
6425 wxPuts(_T("(ok)")); \
6429 wxPrintf(_T("(ERROR: should be %s)\n"), res); \
6433 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
6434 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
6435 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
6436 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
6438 static const wxChar
*s
= _T("?really!");
6439 const wxChar
*start
= wxStrchr(s
, _T('r'));
6440 const wxChar
*end
= wxStrchr(s
, _T('!'));
6441 TEST_CTOR((start
, end
), _T("really"));
6446 static void TestString()
6456 for (int i
= 0; i
< 1000000; ++i
)
6460 c
= _T("! How'ya doin'?");
6463 c
= _T("Hello world! What's up?");
6468 wxPrintf(_T("TestString elapsed time: %ld\n"), sw
.Time());
6471 static void TestPChar()
6479 for (int i
= 0; i
< 1000000; ++i
)
6481 wxStrcpy (a
, _T("Hello"));
6482 wxStrcpy (b
, _T(" world"));
6483 wxStrcpy (c
, _T("! How'ya doin'?"));
6486 wxStrcpy (c
, _T("Hello world! What's up?"));
6487 if (wxStrcmp (c
, a
) == 0)
6488 wxStrcpy (c
, _T("Doh!"));
6491 wxPrintf(_T("TestPChar elapsed time: %ld\n"), sw
.Time());
6494 static void TestStringSub()
6496 wxString
s(_T("Hello, world!"));
6498 wxPuts(_T("*** Testing wxString substring extraction ***"));
6500 wxPrintf(_T("String = '%s'\n"), s
.c_str());
6501 wxPrintf(_T("Left(5) = '%s'\n"), s
.Left(5).c_str());
6502 wxPrintf(_T("Right(6) = '%s'\n"), s
.Right(6).c_str());
6503 wxPrintf(_T("Mid(3, 5) = '%s'\n"), s(3, 5).c_str());
6504 wxPrintf(_T("Mid(3) = '%s'\n"), s
.Mid(3).c_str());
6505 wxPrintf(_T("substr(3, 5) = '%s'\n"), s
.substr(3, 5).c_str());
6506 wxPrintf(_T("substr(3) = '%s'\n"), s
.substr(3).c_str());
6508 static const wxChar
*prefixes
[] =
6512 _T("Hello, world!"),
6513 _T("Hello, world!!!"),
6519 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
6521 wxString prefix
= prefixes
[n
], rest
;
6522 bool rc
= s
.StartsWith(prefix
, &rest
);
6523 wxPrintf(_T("StartsWith('%s') = %s"), prefix
.c_str(), rc
? _T("true") : _T("false"));
6526 wxPrintf(_T(" (the rest is '%s')\n"), rest
.c_str());
6537 static void TestStringFormat()
6539 wxPuts(_T("*** Testing wxString formatting ***"));
6542 s
.Printf(_T("%03d"), 18);
6544 wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str());
6545 wxPrintf(_T("Number 18: %s\n"), s
.c_str());
6550 // returns "not found" for npos, value for all others
6551 static wxString
PosToString(size_t res
)
6553 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
6554 : wxString::Format(_T("%u"), res
);
6558 static void TestStringFind()
6560 wxPuts(_T("*** Testing wxString find() functions ***"));
6562 static const wxChar
*strToFind
= _T("ell");
6563 static const struct StringFindTest
6567 result
; // of searching "ell" in str
6570 { _T("Well, hello world"), 0, 1 },
6571 { _T("Well, hello world"), 6, 7 },
6572 { _T("Well, hello world"), 9, wxString::npos
},
6575 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
6577 const StringFindTest
& ft
= findTestData
[n
];
6578 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
6580 wxPrintf(_T("Index of '%s' in '%s' starting from %u is %s "),
6581 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
6583 size_t resTrue
= ft
.result
;
6584 if ( res
== resTrue
)
6590 wxPrintf(_T("(ERROR: should be %s)\n"),
6591 PosToString(resTrue
).c_str());
6598 static void TestStringTokenizer()
6600 wxPuts(_T("*** Testing wxStringTokenizer ***"));
6602 static const wxChar
*modeNames
[] =
6606 _T("return all empty"),
6611 static const struct StringTokenizerTest
6613 const wxChar
*str
; // string to tokenize
6614 const wxChar
*delims
; // delimiters to use
6615 size_t count
; // count of token
6616 wxStringTokenizerMode mode
; // how should we tokenize it
6617 } tokenizerTestData
[] =
6619 { _T(""), _T(" "), 0 },
6620 { _T("Hello, world"), _T(" "), 2 },
6621 { _T("Hello, world "), _T(" "), 2 },
6622 { _T("Hello, world"), _T(","), 2 },
6623 { _T("Hello, world!"), _T(",!"), 2 },
6624 { _T("Hello,, world!"), _T(",!"), 3 },
6625 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
6626 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
6627 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
6628 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
6629 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
6630 { _T("01/02/99"), _T("/-"), 3 },
6631 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
6634 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
6636 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
6637 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
6639 size_t count
= tkz
.CountTokens();
6640 wxPrintf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
6641 MakePrintable(tt
.str
).c_str(),
6643 MakePrintable(tt
.delims
).c_str(),
6644 modeNames
[tkz
.GetMode()]);
6645 if ( count
== tt
.count
)
6651 wxPrintf(_T("(ERROR: should be %u)\n"), tt
.count
);
6656 // if we emulate strtok(), check that we do it correctly
6657 wxChar
*buf
, *s
= NULL
, *last
;
6659 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
6661 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
6662 wxStrcpy(buf
, tt
.str
);
6664 s
= wxStrtok(buf
, tt
.delims
, &last
);
6671 // now show the tokens themselves
6673 while ( tkz
.HasMoreTokens() )
6675 wxString token
= tkz
.GetNextToken();
6677 wxPrintf(_T("\ttoken %u: '%s'"),
6679 MakePrintable(token
).c_str());
6685 wxPuts(_T(" (ok)"));
6689 wxPrintf(_T(" (ERROR: should be %s)\n"), s
);
6692 s
= wxStrtok(NULL
, tt
.delims
, &last
);
6696 // nothing to compare with
6701 if ( count2
!= count
)
6703 wxPuts(_T("\tERROR: token count mismatch"));
6712 static void TestStringReplace()
6714 wxPuts(_T("*** Testing wxString::replace ***"));
6716 static const struct StringReplaceTestData
6718 const wxChar
*original
; // original test string
6719 size_t start
, len
; // the part to replace
6720 const wxChar
*replacement
; // the replacement string
6721 const wxChar
*result
; // and the expected result
6722 } stringReplaceTestData
[] =
6724 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
6725 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
6726 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
6727 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
6728 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
6731 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
6733 const StringReplaceTestData data
= stringReplaceTestData
[n
];
6735 wxString original
= data
.original
;
6736 original
.replace(data
.start
, data
.len
, data
.replacement
);
6738 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
6739 data
.original
, data
.start
, data
.len
, data
.replacement
,
6742 if ( original
== data
.result
)
6748 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
6755 static void TestStringMatch()
6757 wxPuts(_T("*** Testing wxString::Matches() ***"));
6759 static const struct StringMatchTestData
6762 const wxChar
*wildcard
;
6764 } stringMatchTestData
[] =
6766 { _T("foobar"), _T("foo*"), 1 },
6767 { _T("foobar"), _T("*oo*"), 1 },
6768 { _T("foobar"), _T("*bar"), 1 },
6769 { _T("foobar"), _T("??????"), 1 },
6770 { _T("foobar"), _T("f??b*"), 1 },
6771 { _T("foobar"), _T("f?b*"), 0 },
6772 { _T("foobar"), _T("*goo*"), 0 },
6773 { _T("foobar"), _T("*foo"), 0 },
6774 { _T("foobarfoo"), _T("*foo"), 1 },
6775 { _T(""), _T("*"), 1 },
6776 { _T(""), _T("?"), 0 },
6779 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
6781 const StringMatchTestData
& data
= stringMatchTestData
[n
];
6782 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
6783 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
6785 matches
? _T("matches") : _T("doesn't match"),
6787 matches
== data
.matches
? _T("ok") : _T("ERROR"));
6793 // Sigh, I want Test::Simple, Test::More and Test::Harness...
6794 void ok(int line
, bool ok
, const wxString
& msg
= wxEmptyString
)
6797 wxPuts(_T("NOT OK: (") + wxString::Format(_T("%d"), line
) +
6801 void is(int line
, const wxString
& got
, const wxString
& expected
,
6802 const wxString
& msg
= wxEmptyString
)
6804 bool isOk
= got
== expected
;
6805 ok(line
, isOk
, msg
);
6808 wxPuts(_T("Got: ") + got
);
6809 wxPuts(_T("Expected: ") + expected
);
6814 void is(int line
, const wxChar
* got
, const wxChar
* expected
,
6815 const wxString
& msg
= wxEmptyString
)
6817 bool isOk
= wxStrcmp( got
, expected
) == 0;
6818 ok(line
, isOk
, msg
);
6821 wxPuts(_T("Got: ") + wxString(got
));
6822 wxPuts(_T("Expected: ") + wxString(expected
));
6827 void is(int line
, const wxChar
& got
, const wxChar
& expected
,
6828 const wxString
& msg
= wxEmptyString
)
6830 bool isOk
= got
== expected
;
6831 ok(line
, isOk
, msg
);
6834 wxPuts(_T("Got: ") + got
);
6835 wxPuts(_T("Expected: ") + expected
);
6839 void is(int line
, size_t got
, size_t expected
,
6840 const wxString
& msg
= wxEmptyString
)
6842 bool isOk
= got
== expected
;
6843 ok(line
, isOk
, msg
);
6846 wxPuts(wxString::Format(_T("Got: %ld"), got
));
6847 wxPuts(wxString::Format(_T("Expected: %ld"), expected
));
6851 #define is_m( got, expected, message ) is( __LINE__, (got), (expected), (message) )
6852 #define is_nom( got, expected ) is( __LINE__, (got), (expected), wxEmptyString )
6854 void TestStdString()
6856 wxPuts(_T("*** Testing std::string operations ***\n"));
6859 wxString
s1(_T("abcdefgh")),
6860 s2(_T("abcdefghijklm"), 8),
6861 s3(_T("abcdefghijklm")),
6865 s7(s3
.begin(), s3
.begin() + 8);
6866 wxString
s8(s1
, 4, 8), s9
, s10
, s11
;
6868 is( __LINE__
, s1
, _T("abcdefgh") );
6869 is( __LINE__
, s2
, s1
);
6870 is( __LINE__
, s4
, _T("aaaaaaaa") );
6871 is( __LINE__
, s5
, _T("abcdefgh") );
6872 is( __LINE__
, s6
, s1
);
6873 is( __LINE__
, s7
, s1
);
6874 is( __LINE__
, s8
, _T("efgh") );
6877 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("abc");
6878 s1
.append(_T("def"));
6879 s2
.append(_T("defgh"), 3);
6880 s3
.append(wxString(_T("abcdef")), 3, 6);
6882 s5
.append(3, _T('a'));
6883 s6
.append(s1
.begin() + 3, s1
.end());
6885 is( __LINE__
, s1
, _T("abcdef") );
6886 is( __LINE__
, s2
, _T("abcdef") );
6887 is( __LINE__
, s3
, _T("abcdef") );
6888 is( __LINE__
, s4
, _T("abcabcdef") );
6889 is( __LINE__
, s5
, _T("abcaaa") );
6890 is( __LINE__
, s6
, _T("abcdef") );
6893 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("abc");
6894 s1
.assign(_T("def"));
6895 s2
.assign(_T("defgh"), 3);
6896 s3
.assign(wxString(_T("abcdef")), 3, 6);
6898 s5
.assign(3, _T('a'));
6899 s6
.assign(s1
.begin() + 1, s1
.end());
6901 is( __LINE__
, s1
, _T("def") );
6902 is( __LINE__
, s2
, _T("def") );
6903 is( __LINE__
, s3
, _T("def") );
6904 is( __LINE__
, s4
, _T("def") );
6905 is( __LINE__
, s5
, _T("aaa") );
6906 is( __LINE__
, s6
, _T("ef") );
6909 s1
= _T("abcdefgh");
6910 s2
= _T("abcdefgh");
6912 s4
= _T("abcdefghi");
6915 s7
= _T("zabcdefg");
6917 ok( __LINE__
, s1
.compare(s2
) == 0 );
6918 ok( __LINE__
, s1
.compare(s3
) > 0 );
6919 ok( __LINE__
, s1
.compare(s4
) < 0 );
6920 ok( __LINE__
, s1
.compare(s5
) > 0 );
6921 ok( __LINE__
, s1
.compare(s6
) < 0 );
6922 ok( __LINE__
, s1
.compare(1, 12, s1
) > 0);
6923 ok( __LINE__
, s1
.compare(_T("abcdefgh")) == 0);
6924 ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh")) == 0);
6925 ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh"), 7) == 0);
6930 wxString::iterator it
= s3
.erase(s3
.begin() + 1);
6931 wxString::iterator it2
= s4
.erase(s4
.begin() + 4, s4
.begin() + 6);
6932 wxString::iterator it3
= s7
.erase(s7
.begin() + 4, s7
.begin() + 8);
6934 is( __LINE__
, s1
, _T("acdefgh") );
6935 is( __LINE__
, s2
, _T("abcd") );
6936 is( __LINE__
, s3
, _T("ac") );
6937 is( __LINE__
, s4
, _T("abcdghi") );
6938 is( __LINE__
, s7
, _T("zabc") );
6939 is( __LINE__
, *it
, _T('c') );
6940 is( __LINE__
, *it2
, _T('g') );
6941 ok( __LINE__
, it3
== s7
.end() );
6945 // 01234567890123456789012345
6946 s1
= _T("abcdefgABCDEFGabcABCabcABC");
6949 is_nom( s1
.find(_T('A')), 7u );
6950 is_nom( s1
.find(_T('A'), 7), 7u );
6951 is_nom( s1
.find(_T('Z')), wxString::npos
);
6952 is_nom( s1
.find(_T('C'), 22), 25u );
6954 is_nom( s1
.find(_T("gAB")), 6u );
6955 is_nom( s1
.find(_T("gAB"), 7), wxString::npos
);
6956 is_nom( s1
.find(_T("gAB"), 6), 6u );
6958 is_nom( s1
.find(_T("gABZZZ"), 2, 3), 6u );
6959 is_nom( s1
.find(_T("gABZZZ"), 7, 3), wxString::npos
);
6961 is_nom( s1
.find(s2
), 6u );
6962 is_nom( s1
.find(s2
, 7), wxString::npos
);
6963 is_nom( s1
.find(s2
, 6), 6u );
6965 // find_first_not_of
6967 // 01234567890123456789012345678901234
6968 s1
= _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
6971 is_nom( s1
.find_first_not_of(_T('a')), 6u );
6972 is_nom( s1
.find_first_not_of(_T('a'), 7), 7u );
6973 is_nom( s2
.find_first_not_of(_T('a')), wxString::npos
);
6975 is_nom( s1
.find_first_not_of(_T("abde"), 4), 7u );
6976 is_nom( s1
.find_first_not_of(_T("abde"), 7), 7u );
6977 is_nom( s1
.find_first_not_of(_T("abcdefghijkl")), wxString::npos
);
6979 is_nom( s1
.find_first_not_of(_T("abcdefghi"), 0, 4), 9u );
6982 is_nom( s1
.find_first_of(_T('c')), 7u );
6983 is_nom( s1
.find_first_of(_T('v')), wxString::npos
);
6984 is_nom( s1
.find_first_of(_T('c'), 10), 24u );
6986 is_nom( s1
.find_first_of(_T("ijkl")), 13u );
6987 is_nom( s1
.find_first_of(_T("ddcfg"), 17), 24u );
6988 is_nom( s1
.find_first_of(_T("ddcfga"), 17, 5), 24u );
6992 // 01234567890123456789012345678901234
6993 s1
= _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
6996 is_nom( s2
.find_last_not_of(_T('a')), wxString::npos
);
6997 is_nom( s1
.find_last_not_of(_T('d')), 33u );
6998 is_nom( s1
.find_last_not_of(_T('d'), 25), 24u );
7000 is_nom( s1
.find_last_not_of(_T("bcd")), 22u );
7001 is_nom( s1
.find_last_not_of(_T("abc"), 24), 16u );
7003 is_nom( s1
.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3), 16u );
7006 is_nom( s2
.find_last_of(_T('c')), wxString::npos
);
7007 is_nom( s1
.find_last_of(_T('a')), 22u );
7008 is_nom( s1
.find_last_of(_T('b'), 24), 23u );
7010 is_nom( s1
.find_last_of(_T("ijklm")), 16u );
7011 is_nom( s1
.find_last_of(_T("ijklma"), 33, 4), 16u );
7012 is_nom( s1
.find_last_of(_T("a"), 17), 17u );
7015 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("aaaa");
7016 s9
= s10
= _T("cdefg");
7018 s1
.insert(1, _T("cc") );
7019 s2
.insert(2, _T("cdef"), 3);
7021 s4
.insert(2, s10
, 3, 7);
7022 s5
.insert(1, 2, _T('c'));
7023 it
= s6
.insert(s6
.begin() + 3, _T('X'));
7024 s7
.insert(s7
.begin(), s9
.begin(), s9
.end() - 1);
7025 s8
.insert(s8
.begin(), 2, _T('c'));
7027 is( __LINE__
, s1
, _T("accaaa") );
7028 is( __LINE__
, s2
, _T("aacdeaa") );
7029 is( __LINE__
, s3
, _T("aacdefgaa") );
7030 is( __LINE__
, s4
, _T("aafgaa") );
7031 is( __LINE__
, s5
, _T("accaaa") );
7032 is( __LINE__
, s6
, _T("aaaXa") );
7033 is( __LINE__
, s7
, _T("cdefaaaa") );
7034 is( __LINE__
, s8
, _T("ccaaaa") );
7036 s1
= s2
= s3
= _T("aaaa");
7037 s1
.insert(0, _T("ccc"), 2);
7038 s2
.insert(4, _T("ccc"), 2);
7040 is( __LINE__
, s1
, _T("ccaaaa") );
7041 is( __LINE__
, s2
, _T("aaaacc") );
7044 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("QWERTYUIOP");
7045 s9
= s10
= _T("werty");
7047 s1
.replace(3, 4, _T("rtyu"));
7048 s1
.replace(8, 7, _T("opopop"));
7049 s2
.replace(10, 12, _T("WWWW"));
7050 s3
.replace(1, 5, s9
);
7051 s4
.replace(1, 4, s9
, 0, 4);
7052 s5
.replace(1, 2, s9
, 1, 12);
7053 s6
.replace(0, 123, s9
, 0, 123);
7054 s7
.replace(2, 7, s9
);
7056 is( __LINE__
, s1
, _T("QWErtyuIopopop") );
7057 is( __LINE__
, s2
, _T("QWERTYUIOPWWWW") );
7058 is( __LINE__
, s3
, _T("QwertyUIOP") );
7059 is( __LINE__
, s4
, _T("QwertYUIOP") );
7060 is( __LINE__
, s5
, _T("QertyRTYUIOP") );
7061 is( __LINE__
, s6
, s9
);
7062 is( __LINE__
, s7
, _T("QWwertyP") );
7066 // 01234567890123456789012345
7067 s1
= _T("abcdefgABCDEFGabcABCabcABC");
7071 is_nom( s1
.rfind(_T('A')), 23u );
7072 is_nom( s1
.rfind(_T('A'), 7), 7u );
7073 is_nom( s1
.rfind(_T('Z')), wxString::npos
);
7074 is_nom( s1
.rfind(_T('C'), 22), 19u );
7076 is_nom( s1
.rfind(_T("cAB")), 22u );
7077 is_nom( s1
.rfind(_T("cAB"), 15), wxString::npos
);
7078 is_nom( s1
.rfind(_T("cAB"), 21), 16u );
7080 is_nom( s1
.rfind(_T("gABZZZ"), 7, 3), 6u );
7081 is_nom( s1
.rfind(_T("gABZZZ"), 5, 3), wxString::npos
);
7083 is_nom( s1
.rfind(s2
), 6u );
7084 is_nom( s1
.rfind(s2
, 5), wxString::npos
);
7085 is_nom( s1
.rfind(s2
, 6), 6u );
7086 is_nom( s1
.rfind(s3
, 1), 0u );
7089 s1
= s2
= s3
= s4
= _T("abcABCdefDEF");
7093 s3
.resize( 14, _T(' ') );
7094 s4
.resize( 14, _T('W') );
7096 is_nom( s1
, _T("abcABCdefDEF") );
7097 is_nom( s2
, _T("abcABCdefD") );
7098 is_nom( s3
, _T("abcABCdefDEF ") );
7099 is_nom( s4
, _T("abcABCdefDEFWW") );
7102 s1
= _T("abcdefgABCDEFG");
7104 is_nom( s1
.substr( 0, 14 ), s1
);
7105 is_nom( s1
.substr( 1, 13 ), _T("bcdefgABCDEFG") );
7106 is_nom( s1
.substr( 1, 20 ), _T("bcdefgABCDEFG") );
7107 is_nom( s1
.substr( 14, 30 ), _T("") );
7109 wxPuts(_T("*** Testing std::string operations finished ***\n"));
7112 #endif // TEST_STRINGS
7114 // ----------------------------------------------------------------------------
7116 // ----------------------------------------------------------------------------
7118 #ifdef TEST_SNGLINST
7119 #include "wx/snglinst.h"
7120 #endif // TEST_SNGLINST
7122 int main(int argc
, char **argv
)
7124 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
7126 wxInitializer initializer
;
7129 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
7134 #ifdef TEST_SNGLINST
7135 wxSingleInstanceChecker checker
;
7136 if ( checker
.Create(_T(".wxconsole.lock")) )
7138 if ( checker
.IsAnotherRunning() )
7140 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
7145 // wait some time to give time to launch another instance
7146 wxPrintf(_T("Press \"Enter\" to continue..."));
7149 else // failed to create
7151 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
7153 #endif // TEST_SNGLINST
7157 #endif // TEST_CHARSET
7160 TestCmdLineConvert();
7162 #if wxUSE_CMDLINE_PARSER
7163 static const wxCmdLineEntryDesc cmdLineDesc
[] =
7165 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"),
7166 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
7167 { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") },
7168 { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"), _T("be quiet") },
7170 { wxCMD_LINE_OPTION
, _T("o"), _T("output"), _T("output file") },
7171 { wxCMD_LINE_OPTION
, _T("i"), _T("input"), _T("input dir") },
7172 { wxCMD_LINE_OPTION
, _T("s"), _T("size"), _T("output block size"),
7173 wxCMD_LINE_VAL_NUMBER
},
7174 { wxCMD_LINE_OPTION
, _T("d"), _T("date"), _T("output file date"),
7175 wxCMD_LINE_VAL_DATE
},
7177 { wxCMD_LINE_PARAM
, NULL
, NULL
, _T("input file"),
7178 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
7184 wxChar
**wargv
= new wxChar
*[argc
+ 1];
7189 for (n
= 0; n
< argc
; n
++ )
7191 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
7192 wargv
[n
] = wxStrdup(warg
);
7199 #endif // wxUSE_UNICODE
7201 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
7205 for ( int n
= 0; n
< argc
; n
++ )
7210 #endif // wxUSE_UNICODE
7212 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
7213 wxCMD_LINE_VAL_STRING
,
7214 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
7216 switch ( parser
.Parse() )
7219 wxLogMessage(_T("Help was given, terminating."));
7223 ShowCmdLine(parser
);
7227 wxLogMessage(_T("Syntax error detected, aborting."));
7230 #endif // wxUSE_CMDLINE_PARSER
7232 #endif // TEST_CMDLINE
7240 TestStringConstruction();
7243 TestStringTokenizer();
7244 TestStringReplace();
7252 #endif // TEST_STRINGS
7255 if ( 1 || TEST_ALL
)
7258 a1
.Add(_T("tiger"));
7260 a1
.Add(_T("lion"), 3);
7262 a1
.Add(_T("human"));
7265 wxPuts(_T("*** Initially:"));
7267 PrintArray(_T("a1"), a1
);
7269 wxArrayString
a2(a1
);
7270 PrintArray(_T("a2"), a2
);
7273 wxSortedArrayString
a3(a1
);
7275 wxSortedArrayString a3
;
7276 for (wxArrayString::iterator it
= a1
.begin(), en
= a1
.end();
7280 PrintArray(_T("a3"), a3
);
7282 wxPuts(_T("*** After deleting three strings from a1"));
7285 PrintArray(_T("a1"), a1
);
7286 PrintArray(_T("a2"), a2
);
7287 PrintArray(_T("a3"), a3
);
7290 wxPuts(_T("*** After reassigning a1 to a2 and a3"));
7292 PrintArray(_T("a2"), a2
);
7293 PrintArray(_T("a3"), a3
);
7296 wxPuts(_T("*** After sorting a1"));
7298 PrintArray(_T("a1"), a1
);
7300 wxPuts(_T("*** After sorting a1 in reverse order"));
7302 PrintArray(_T("a1"), a1
);
7305 wxPuts(_T("*** After sorting a1 by the string length"));
7306 a1
.Sort(&StringLenCompare
);
7307 PrintArray(_T("a1"), a1
);
7310 TestArrayOfObjects();
7311 TestArrayOfUShorts();
7316 #endif // TEST_ARRAYS
7327 #ifdef TEST_DLLLOADER
7329 #endif // TEST_DLLLOADER
7333 #endif // TEST_ENVIRON
7337 #endif // TEST_EXECUTE
7339 #ifdef TEST_FILECONF
7341 #endif // TEST_FILECONF
7350 #endif // TEST_LOCALE
7353 wxPuts(_T("*** Testing wxLog ***"));
7356 for ( size_t n
= 0; n
< 8000; n
++ )
7358 s
<< (wxChar
)(_T('A') + (n
% 26));
7361 wxLogWarning(_T("The length of the string is %lu"),
7362 (unsigned long)s
.length());
7365 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
7367 // this one shouldn't be truncated
7370 // but this one will because log functions use fixed size buffer
7371 // (note that it doesn't need '\n' at the end neither - will be added
7373 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
7385 #ifdef TEST_FILENAME
7388 TestFileNameConstruction();
7389 TestFileNameMakeRelative();
7390 TestFileNameMakeAbsolute();
7391 TestFileNameSplit();
7394 TestFileNameDirManip();
7395 TestFileNameComparison();
7396 TestFileNameOperations();
7398 #endif // TEST_FILENAME
7400 #ifdef TEST_FILETIME
7404 #endif // TEST_FILETIME
7407 wxLog::AddTraceMask(FTP_TRACE_MASK
);
7408 if ( TestFtpConnect() )
7419 if ( TEST_INTERACTIVE
)
7420 TestFtpInteractive();
7422 //else: connecting to the FTP server failed
7428 #ifdef TEST_LONGLONG
7429 // seed pseudo random generator
7430 srand((unsigned)time(NULL
));
7439 TestMultiplication();
7442 TestLongLongConversion();
7443 TestBitOperations();
7444 TestLongLongComparison();
7445 TestLongLongToString();
7446 TestLongLongPrintf();
7448 #endif // TEST_LONGLONG
7456 #endif // TEST_HASHMAP
7460 #endif // TEST_HASHSET
7463 wxLog::AddTraceMask(_T("mime"));
7468 TestMimeAssociate();
7473 #ifdef TEST_INFO_FUNCTIONS
7479 if ( TEST_INTERACTIVE
)
7482 #endif // TEST_INFO_FUNCTIONS
7484 #ifdef TEST_PATHLIST
7486 #endif // TEST_PATHLIST
7494 #endif // TEST_PRINTF
7497 //TestRegConfWrite();
7499 #endif // TEST_REGCONF
7502 // TODO: write a real test using src/regex/tests file
7507 TestRegExSubmatch();
7508 TestRegExReplacement();
7510 if ( TEST_INTERACTIVE
)
7511 TestRegExInteractive();
7513 #endif // TEST_REGEX
7515 #ifdef TEST_REGISTRY
7517 TestRegistryAssociation();
7518 #endif // TEST_REGISTRY
7523 #endif // TEST_SOCKETS
7531 #endif // TEST_STREAMS
7533 #ifdef TEST_TEXTSTREAM
7534 TestTextInputStream();
7535 #endif // TEST_TEXTSTREAM
7538 int nCPUs
= wxThread::GetCPUCount();
7539 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
7541 wxThread::SetConcurrency(nCPUs
);
7543 TestJoinableThreads();
7547 TestJoinableThreads();
7548 TestDetachedThreads();
7549 TestThreadSuspend();
7551 TestThreadConditions();
7555 #endif // TEST_THREADS
7559 #endif // TEST_TIMER
7561 #ifdef TEST_DATETIME
7574 TestTimeArithmetics();
7577 TestTimeSpanFormat();
7583 if ( TEST_INTERACTIVE
)
7584 TestDateTimeInteractive();
7585 #endif // TEST_DATETIME
7587 #ifdef TEST_SCOPEGUARD
7592 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
7594 #endif // TEST_USLEEP
7599 #endif // TEST_VCARD
7603 #endif // TEST_VOLUME
7606 TestUnicodeTextFileRead();
7609 TestUnicodeToFromAscii();
7611 #endif // TEST_UNICODE
7615 TestEncodingConverter();
7616 #endif // TEST_WCHAR
7619 TestZipStreamRead();
7620 TestZipFileSystem();
7624 TestZlibStreamWrite();
7625 TestZlibStreamRead();