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
66 #define TEST_INFO_FUNCTIONS
79 #define TEST_SCOPEGUARD
84 #define TEST_TEXTSTREAM
88 // #define TEST_VCARD -- don't enable this (VZ)
96 static const bool TEST_ALL
= true;
100 static const bool TEST_ALL
= false;
103 // some tests are interactive, define this to run them
104 #ifdef TEST_INTERACTIVE
105 #undef TEST_INTERACTIVE
107 static const bool TEST_INTERACTIVE
= true;
109 static const bool TEST_INTERACTIVE
= false;
112 // ----------------------------------------------------------------------------
113 // test class for container objects
114 // ----------------------------------------------------------------------------
116 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
118 class Bar
// Foo is already taken in the hash test
121 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
122 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
123 ~Bar() { ms_bars
--; }
125 static size_t GetNumber() { return ms_bars
; }
127 const wxChar
*GetName() const { return m_name
; }
132 static size_t ms_bars
;
135 size_t Bar::ms_bars
= 0;
137 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
139 // ============================================================================
141 // ============================================================================
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
149 // replace TABs with \t and CRs with \n
150 static wxString
MakePrintable(const wxChar
*s
)
153 (void)str
.Replace(_T("\t"), _T("\\t"));
154 (void)str
.Replace(_T("\n"), _T("\\n"));
155 (void)str
.Replace(_T("\r"), _T("\\r"));
160 #endif // MakePrintable() is used
162 // ----------------------------------------------------------------------------
163 // wxFontMapper::CharsetToEncoding
164 // ----------------------------------------------------------------------------
168 #include "wx/fontmap.h"
170 static void TestCharset()
172 static const wxChar
*charsets
[] =
174 // some vali charsets
183 // and now some bogus ones
190 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
192 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]);
193 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
195 wxFontMapper::Get()->GetEncodingName(enc
).c_str(),
196 wxFontMapper::Get()->GetEncodingDescription(enc
).c_str());
200 #endif // TEST_CHARSET
202 // ----------------------------------------------------------------------------
204 // ----------------------------------------------------------------------------
208 #include "wx/cmdline.h"
209 #include "wx/datetime.h"
211 #if wxUSE_CMDLINE_PARSER
213 static void ShowCmdLine(const wxCmdLineParser
& parser
)
215 wxString s
= _T("Input files: ");
217 size_t count
= parser
.GetParamCount();
218 for ( size_t param
= 0; param
< count
; param
++ )
220 s
<< parser
.GetParam(param
) << ' ';
224 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
225 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
230 if ( parser
.Found(_T("o"), &strVal
) )
231 s
<< _T("Output file:\t") << strVal
<< '\n';
232 if ( parser
.Found(_T("i"), &strVal
) )
233 s
<< _T("Input dir:\t") << strVal
<< '\n';
234 if ( parser
.Found(_T("s"), &lVal
) )
235 s
<< _T("Size:\t") << lVal
<< '\n';
236 if ( parser
.Found(_T("d"), &dt
) )
237 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
238 if ( parser
.Found(_T("project_name"), &strVal
) )
239 s
<< _T("Project:\t") << strVal
<< '\n';
244 #endif // wxUSE_CMDLINE_PARSER
246 static void TestCmdLineConvert()
248 static const wxChar
*cmdlines
[] =
251 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
252 _T("literal \\\" and \"\""),
255 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
257 const wxChar
*cmdline
= cmdlines
[n
];
258 wxPrintf(_T("Parsing: %s\n"), cmdline
);
259 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
261 size_t count
= args
.GetCount();
262 wxPrintf(_T("\targc = %u\n"), count
);
263 for ( size_t arg
= 0; arg
< count
; arg
++ )
265 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
270 #endif // TEST_CMDLINE
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
281 static const wxChar
*ROOTDIR
= _T("/");
282 static const wxChar
*TESTDIR
= _T("/usr/local/share");
283 #elif defined(__WXMSW__)
284 static const wxChar
*ROOTDIR
= _T("c:\\");
285 static const wxChar
*TESTDIR
= _T("d:\\");
287 #error "don't know where the root directory is"
290 static void TestDirEnumHelper(wxDir
& dir
,
291 int flags
= wxDIR_DEFAULT
,
292 const wxString
& filespec
= wxEmptyString
)
296 if ( !dir
.IsOpened() )
299 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
302 wxPrintf(_T("\t%s\n"), filename
.c_str());
304 cont
= dir
.GetNext(&filename
);
310 static void TestDirEnum()
312 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
314 wxString cwd
= wxGetCwd();
315 if ( !wxDir::Exists(cwd
) )
317 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
322 if ( !dir
.IsOpened() )
324 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
328 wxPuts(_T("Enumerating everything in current directory:"));
329 TestDirEnumHelper(dir
);
331 wxPuts(_T("Enumerating really everything in current directory:"));
332 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
334 wxPuts(_T("Enumerating object files in current directory:"));
335 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
337 wxPuts(_T("Enumerating directories in current directory:"));
338 TestDirEnumHelper(dir
, wxDIR_DIRS
);
340 wxPuts(_T("Enumerating files in current directory:"));
341 TestDirEnumHelper(dir
, wxDIR_FILES
);
343 wxPuts(_T("Enumerating files including hidden in current directory:"));
344 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
348 wxPuts(_T("Enumerating everything in root directory:"));
349 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
351 wxPuts(_T("Enumerating directories in root directory:"));
352 TestDirEnumHelper(dir
, wxDIR_DIRS
);
354 wxPuts(_T("Enumerating files in root directory:"));
355 TestDirEnumHelper(dir
, wxDIR_FILES
);
357 wxPuts(_T("Enumerating files including hidden in root directory:"));
358 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
360 wxPuts(_T("Enumerating files in non existing directory:"));
361 wxDir
dirNo(_T("nosuchdir"));
362 TestDirEnumHelper(dirNo
);
365 class DirPrintTraverser
: public wxDirTraverser
368 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
370 return wxDIR_CONTINUE
;
373 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
375 wxString path
, name
, ext
;
376 wxSplitPath(dirname
, &path
, &name
, &ext
);
379 name
<< _T('.') << ext
;
382 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
384 if ( wxIsPathSeparator(*p
) )
388 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
390 return wxDIR_CONTINUE
;
394 static void TestDirTraverse()
396 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
400 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
401 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
404 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
405 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
408 // enum again with custom traverser
409 wxPuts(_T("Now enumerating directories:"));
411 DirPrintTraverser traverser
;
412 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
415 static void TestDirExists()
417 wxPuts(_T("*** Testing wxDir::Exists() ***"));
419 static const wxChar
*dirnames
[] =
422 #if defined(__WXMSW__)
425 _T("\\\\share\\file"),
429 _T("c:\\autoexec.bat"),
430 #elif defined(__UNIX__)
439 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
441 wxPrintf(_T("%-40s: %s\n"),
443 wxDir::Exists(dirnames
[n
]) ? _T("exists")
444 : _T("doesn't exist"));
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 #ifdef TEST_DLLLOADER
456 #include "wx/dynlib.h"
458 static void TestDllLoad()
460 #if defined(__WXMSW__)
461 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
462 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
463 #elif defined(__UNIX__)
464 // weird: using just libc.so does *not* work!
465 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
466 static const wxChar
*FUNC_NAME
= _T("strlen");
468 #error "don't know how to test wxDllLoader on this platform"
471 wxPuts(_T("*** testing wxDllLoader ***\n"));
473 wxDynamicLibrary
lib(LIB_NAME
);
474 if ( !lib
.IsLoaded() )
476 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
480 typedef int (*wxStrlenType
)(const char *);
481 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
484 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
485 FUNC_NAME
, LIB_NAME
);
489 if ( pfnStrlen("foo") != 3 )
491 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
495 wxPuts(_T("... ok"));
501 #endif // TEST_DLLLOADER
503 // ----------------------------------------------------------------------------
505 // ----------------------------------------------------------------------------
509 #include "wx/utils.h"
511 static wxString
MyGetEnv(const wxString
& var
)
514 if ( !wxGetEnv(var
, &val
) )
517 val
= wxString(_T('\'')) + val
+ _T('\'');
522 static void TestEnvironment()
524 const wxChar
*var
= _T("wxTestVar");
526 wxPuts(_T("*** testing environment access functions ***"));
528 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
529 wxSetEnv(var
, _T("value for wxTestVar"));
530 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
531 wxSetEnv(var
, _T("another value"));
532 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
534 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
535 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
538 #endif // TEST_ENVIRON
540 // ----------------------------------------------------------------------------
542 // ----------------------------------------------------------------------------
546 #include "wx/utils.h"
548 static void TestExecute()
550 wxPuts(_T("*** testing wxExecute ***"));
553 #define COMMAND "cat -n ../../Makefile" // "echo hi"
554 #define SHELL_COMMAND "echo hi from shell"
555 #define REDIRECT_COMMAND COMMAND // "date"
556 #elif defined(__WXMSW__)
557 #define COMMAND "command.com /c echo hi"
558 #define SHELL_COMMAND "echo hi"
559 #define REDIRECT_COMMAND COMMAND
561 #error "no command to exec"
564 wxPrintf(_T("Testing wxShell: "));
566 if ( wxShell(_T(SHELL_COMMAND
)) )
569 wxPuts(_T("ERROR."));
571 wxPrintf(_T("Testing wxExecute: "));
573 if ( wxExecute(_T(COMMAND
), true /* sync */) == 0 )
576 wxPuts(_T("ERROR."));
578 #if 0 // no, it doesn't work (yet?)
579 wxPrintf(_T("Testing async wxExecute: "));
581 if ( wxExecute(COMMAND
) != 0 )
582 wxPuts(_T("Ok (command launched)."));
584 wxPuts(_T("ERROR."));
587 wxPrintf(_T("Testing wxExecute with redirection:\n"));
588 wxArrayString output
;
589 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
591 wxPuts(_T("ERROR."));
595 size_t count
= output
.GetCount();
596 for ( size_t n
= 0; n
< count
; n
++ )
598 wxPrintf(_T("\t%s\n"), output
[n
].c_str());
605 #endif // TEST_EXECUTE
607 // ----------------------------------------------------------------------------
609 // ----------------------------------------------------------------------------
614 #include "wx/ffile.h"
615 #include "wx/textfile.h"
617 static void TestFileRead()
619 wxPuts(_T("*** wxFile read test ***"));
621 wxFile
file(_T("testdata.fc"));
622 if ( file
.IsOpened() )
624 wxPrintf(_T("File length: %lu\n"), file
.Length());
626 wxPuts(_T("File dump:\n----------"));
628 static const off_t len
= 1024;
632 off_t nRead
= file
.Read(buf
, len
);
633 if ( nRead
== wxInvalidOffset
)
635 wxPrintf(_T("Failed to read the file."));
639 fwrite(buf
, nRead
, 1, stdout
);
645 wxPuts(_T("----------"));
649 wxPrintf(_T("ERROR: can't open test file.\n"));
655 static void TestTextFileRead()
657 wxPuts(_T("*** wxTextFile read test ***"));
659 wxTextFile
file(_T("testdata.fc"));
662 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
663 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
667 wxPuts(_T("\nDumping the entire file:"));
668 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
670 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
672 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
674 wxPuts(_T("\nAnd now backwards:"));
675 for ( s
= file
.GetLastLine();
676 file
.GetCurrentLine() != 0;
677 s
= file
.GetPrevLine() )
679 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
681 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
685 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
691 static void TestFileCopy()
693 wxPuts(_T("*** Testing wxCopyFile ***"));
695 static const wxChar
*filename1
= _T("testdata.fc");
696 static const wxChar
*filename2
= _T("test2");
697 if ( !wxCopyFile(filename1
, filename2
) )
699 wxPuts(_T("ERROR: failed to copy file"));
703 wxFFile
f1(filename1
, _T("rb")),
704 f2(filename2
, _T("rb"));
706 if ( !f1
.IsOpened() || !f2
.IsOpened() )
708 wxPuts(_T("ERROR: failed to open file(s)"));
713 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
715 wxPuts(_T("ERROR: failed to read file(s)"));
719 if ( (s1
.length() != s2
.length()) ||
720 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
722 wxPuts(_T("ERROR: copy error!"));
726 wxPuts(_T("File was copied ok."));
732 if ( !wxRemoveFile(filename2
) )
734 wxPuts(_T("ERROR: failed to remove the file"));
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
748 #include "wx/confbase.h"
749 #include "wx/fileconf.h"
751 static const struct FileConfTestData
753 const wxChar
*name
; // value name
754 const wxChar
*value
; // the value from the file
757 { _T("value1"), _T("one") },
758 { _T("value2"), _T("two") },
759 { _T("novalue"), _T("default") },
762 static void TestFileConfRead()
764 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
766 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
767 _T("testdata.fc"), wxEmptyString
,
768 wxCONFIG_USE_RELATIVE_PATH
);
770 // test simple reading
771 wxPuts(_T("\nReading config file:"));
772 wxString
defValue(_T("default")), value
;
773 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
775 const FileConfTestData
& data
= fcTestData
[n
];
776 value
= fileconf
.Read(data
.name
, defValue
);
777 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
778 if ( value
== data
.value
)
784 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
788 // test enumerating the entries
789 wxPuts(_T("\nEnumerating all root entries:"));
792 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
795 wxPrintf(_T("\t%s = %s\n"),
797 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
799 cont
= fileconf
.GetNextEntry(name
, dummy
);
802 static const wxChar
*testEntry
= _T("TestEntry");
803 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
804 fileconf
.Write(testEntry
, _T("A value"));
805 fileconf
.DeleteEntry(testEntry
);
806 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
809 #endif // TEST_FILECONF
811 // ----------------------------------------------------------------------------
813 // ----------------------------------------------------------------------------
817 #include "wx/filename.h"
819 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
823 wxString full
= fn
.GetFullPath();
825 wxString vol
, path
, name
, ext
;
826 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
828 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
829 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
831 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
832 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
833 path
.c_str(), name
.c_str(), ext
.c_str());
835 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
836 wxPrintf(_T("with volume: \t'%s'\n"),
837 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
838 wxPrintf(_T("with separator:\t'%s'\n"),
839 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
840 wxPrintf(_T("with both: \t'%s'\n"),
841 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
843 wxPuts(_T("The directories in the path are:"));
844 wxArrayString dirs
= fn
.GetDirs();
845 size_t count
= dirs
.GetCount();
846 for ( size_t n
= 0; n
< count
; n
++ )
848 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
852 static struct FileNameInfo
854 const wxChar
*fullname
;
855 const wxChar
*volume
;
864 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX
},
865 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX
},
866 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX
},
867 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX
},
868 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
869 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX
},
870 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX
},
871 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
872 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX
},
874 // Windows file names
875 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
876 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS
},
877 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
878 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
879 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS
},
880 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
881 { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
883 // wxFileName support for Mac file names is broken currently
886 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC
},
887 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC
},
888 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC
},
889 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC
},
890 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
891 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
895 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS
},
896 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS
},
899 static void TestFileNameConstruction()
901 wxPuts(_T("*** testing wxFileName construction ***"));
903 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
905 const FileNameInfo
& fni
= filenames
[n
];
907 wxFileName
fn(fni
.fullname
, fni
.format
);
909 wxString fullname
= fn
.GetFullPath(fni
.format
);
910 if ( fullname
!= fni
.fullname
)
912 wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni
.fullname
);
915 bool isAbsolute
= fn
.IsAbsolute(fni
.format
);
916 wxPrintf(_T("'%s' is %s (%s)\n\t"),
918 isAbsolute
? "absolute" : "relative",
919 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
921 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
923 wxPuts(_T("ERROR (couldn't be normalized)"));
927 wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
934 static void TestFileNameSplit()
936 wxPuts(_T("*** testing wxFileName splitting ***"));
938 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
940 const FileNameInfo
& fni
= filenames
[n
];
941 wxString volume
, path
, name
, ext
;
942 wxFileName::SplitPath(fni
.fullname
,
943 &volume
, &path
, &name
, &ext
, fni
.format
);
945 wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"),
947 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
949 if ( volume
!= fni
.volume
)
950 wxPrintf(_T(" (ERROR: volume = '%s')"), fni
.volume
);
951 if ( path
!= fni
.path
)
952 wxPrintf(_T(" (ERROR: path = '%s')"), fni
.path
);
953 if ( name
!= fni
.name
)
954 wxPrintf(_T(" (ERROR: name = '%s')"), fni
.name
);
955 if ( ext
!= fni
.ext
)
956 wxPrintf(_T(" (ERROR: ext = '%s')"), fni
.ext
);
962 static void TestFileNameTemp()
964 wxPuts(_T("*** testing wxFileName temp file creation ***"));
966 static const wxChar
*tmpprefixes
[] =
974 _T("/tmp/foo/bar"), // this one must be an error
978 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
980 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
983 // "error" is not in upper case because it may be ok
984 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
988 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
989 tmpprefixes
[n
], path
.c_str());
991 if ( !wxRemoveFile(path
) )
993 wxLogWarning(_T("Failed to remove temp file '%s'"),
1000 static void TestFileNameMakeRelative()
1002 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
1004 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1006 const FileNameInfo
& fni
= filenames
[n
];
1008 wxFileName
fn(fni
.fullname
, fni
.format
);
1010 // choose the base dir of the same format
1012 switch ( fni
.format
)
1015 base
= _T("/usr/bin/");
1024 // TODO: I don't know how this is supposed to work there
1027 case wxPATH_NATIVE
: // make gcc happy
1029 wxFAIL_MSG( _T("unexpected path format") );
1032 wxPrintf(_T("'%s' relative to '%s': "),
1033 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
1035 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
1037 wxPuts(_T("unchanged"));
1041 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1046 static void TestFileNameMakeAbsolute()
1048 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
1050 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1052 const FileNameInfo
& fni
= filenames
[n
];
1053 wxFileName
fn(fni
.fullname
, fni
.format
);
1055 wxPrintf(_T("'%s' absolutized: "),
1056 fn
.GetFullPath(fni
.format
).c_str());
1058 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1064 static void TestFileNameDirManip()
1066 // TODO: test AppendDir(), RemoveDir(), ...
1069 static void TestFileNameComparison()
1074 static void TestFileNameOperations()
1079 static void TestFileNameCwd()
1084 #endif // TEST_FILENAME
1086 // ----------------------------------------------------------------------------
1087 // wxFileName time functions
1088 // ----------------------------------------------------------------------------
1090 #ifdef TEST_FILETIME
1092 #include <wx/filename.h>
1093 #include <wx/datetime.h>
1095 static void TestFileGetTimes()
1097 wxFileName
fn(_T("testdata.fc"));
1099 wxDateTime dtAccess
, dtMod
, dtCreate
;
1100 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
1102 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
1106 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
1108 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
1109 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
1110 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
1111 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1115 static void TestFileSetTimes()
1117 wxFileName
fn(_T("testdata.fc"));
1121 wxPrintf(_T("ERROR: Touch() failed.\n"));
1125 #endif // TEST_FILETIME
1127 // ----------------------------------------------------------------------------
1129 // ----------------------------------------------------------------------------
1133 #include "wx/hash.h"
1137 Foo(int n_
) { n
= n_
; count
++; }
1142 static size_t count
;
1145 size_t Foo::count
= 0;
1147 WX_DECLARE_LIST(Foo
, wxListFoos
);
1148 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1150 #include "wx/listimpl.cpp"
1152 WX_DEFINE_LIST(wxListFoos
);
1154 #include "wx/timer.h"
1156 static void TestHash()
1158 wxPuts(_T("*** Testing wxHashTable ***\n"));
1159 const int COUNT
= 100;
1166 wxHashTable
hash(wxKEY_INTEGER
, 10), hash2(wxKEY_STRING
);
1170 for ( i
= 0; i
< COUNT
; ++i
)
1171 hash
.Put(i
, &o
+ i
);
1174 wxHashTable::compatibility_iterator it
= hash
.Next();
1184 wxPuts(_T("Error in wxHashTable::compatibility_iterator\n"));
1186 for ( i
= 99; i
>= 0; --i
)
1187 if( hash
.Get(i
) != &o
+ i
)
1188 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1190 for ( i
= 0; i
< COUNT
; ++i
)
1191 hash
.Put(i
, &o
+ i
+ 20);
1193 for ( i
= 99; i
>= 0; --i
)
1194 if( hash
.Get(i
) != &o
+ i
)
1195 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1197 for ( i
= 0; i
< COUNT
/2; ++i
)
1198 if( hash
.Delete(i
) != &o
+ i
)
1199 wxPuts(_T("Error in wxHashTable::Delete\n"));
1201 for ( i
= COUNT
/2; i
< COUNT
; ++i
)
1202 if( hash
.Get(i
) != &o
+ i
)
1203 wxPuts(_T("Error (3) in wxHashTable::Get/Put\n"));
1205 for ( i
= 0; i
< COUNT
/2; ++i
)
1206 if( hash
.Get(i
) != &o
+ i
+ 20)
1207 wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n"));
1209 for ( i
= 0; i
< COUNT
/2; ++i
)
1210 if( hash
.Delete(i
) != &o
+ i
+ 20)
1211 wxPuts(_T("Error (2) in wxHashTable::Delete\n"));
1213 for ( i
= 0; i
< COUNT
/2; ++i
)
1214 if( hash
.Get(i
) != NULL
)
1215 wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n"));
1217 hash2
.Put(_T("foo"), &o
+ 1);
1218 hash2
.Put(_T("bar"), &o
+ 2);
1219 hash2
.Put(_T("baz"), &o
+ 3);
1221 if (hash2
.Get(_T("moo")) != NULL
)
1222 wxPuts(_T("Error in wxHashTable::Get\n"));
1224 if (hash2
.Get(_T("bar")) != &o
+ 2)
1225 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1227 hash2
.Put(_T("bar"), &o
+ 0);
1229 if (hash2
.Get(_T("bar")) != &o
+ 2)
1230 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1233 // and now some corner-case testing; 3 and 13 hash to the same bucket
1235 wxHashTable
hash(wxKEY_INTEGER
, 10);
1238 hash
.Put(3, &dummy
);
1241 if (hash
.Get(3) != NULL
)
1242 wxPuts(_T("Corner case 1 failure\n"));
1244 hash
.Put(3, &dummy
);
1245 hash
.Put(13, &dummy
);
1248 if (hash
.Get(3) != NULL
)
1249 wxPuts(_T("Corner case 2 failure\n"));
1253 if (hash
.Get(13) != NULL
)
1254 wxPuts(_T("Corner case 3 failure\n"));
1256 hash
.Put(3, &dummy
);
1257 hash
.Put(13, &dummy
);
1260 if (hash
.Get(13) != NULL
)
1261 wxPuts(_T("Corner case 4 failure\n"));
1265 if (hash
.Get(3) != NULL
)
1266 wxPuts(_T("Corner case 5 failure\n"));
1270 wxHashTable
hash(wxKEY_INTEGER
, 10);
1273 hash
.Put(3, 7, &dummy
+ 7);
1274 hash
.Put(4, 8, &dummy
+ 8);
1276 if (hash
.Get(7) != NULL
) wxPuts(_T("Key/Hash 1 failure\n"));
1277 if (hash
.Get(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 2 failure\n"));
1278 if (hash
.Get(4) != NULL
) wxPuts(_T("Key/Hash 3 failure\n"));
1279 if (hash
.Get(3) != NULL
) wxPuts(_T("Key/Hash 4 failure\n"));
1280 if (hash
.Get(8) != NULL
) wxPuts(_T("Key/Hash 5 failure\n"));
1281 if (hash
.Get(8, 4) != NULL
) wxPuts(_T("Key/Hash 6 failure\n"));
1283 if (hash
.Delete(7) != NULL
) wxPuts(_T("Key/Hash 7 failure\n"));
1284 if (hash
.Delete(3) != NULL
) wxPuts(_T("Key/Hash 8 failure\n"));
1285 if (hash
.Delete(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 8 failure\n"));
1290 hash
.DeleteContents(true);
1292 wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"),
1293 hash
.GetCount(), Foo::count
);
1295 static const int hashTestData
[] =
1297 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1301 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1303 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1306 wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"),
1307 hash
.GetCount(), Foo::count
);
1309 wxPuts(_T("Hash access test:"));
1310 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1312 wxPrintf(_T("\tGetting element with key %d, value %d: "),
1313 hashTestData
[n
], n
);
1314 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1317 wxPrintf(_T("ERROR, not found.\n"));
1321 wxPrintf(_T("%d (%s)\n"), foo
->n
,
1322 (size_t)foo
->n
== n
? "ok" : "ERROR");
1326 wxPrintf(_T("\nTrying to get an element not in hash: "));
1328 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1330 wxPuts(_T("ERROR: found!"));
1334 wxPuts(_T("ok (not found)"));
1337 Foo
* foo
= hash
.Delete(0);
1339 wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count
);
1343 wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count
);
1346 wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
);
1347 wxPuts(_T("*** Testing wxHashTable finished ***\n"));
1349 wxPrintf(_T("Time: %ld\n"), sw
.Time());
1354 // ----------------------------------------------------------------------------
1356 // ----------------------------------------------------------------------------
1360 #include "wx/hashmap.h"
1362 // test compilation of basic map types
1363 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1364 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1365 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1366 myUnsignedHashMap
);
1367 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1369 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1371 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1373 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1377 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1378 // myStringHashMap );
1379 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1381 typedef myStringHashMap::iterator Itor
;
1383 static void TestHashMap()
1385 wxPuts(_T("*** Testing wxHashMap ***\n"));
1386 myStringHashMap
sh(0); // as small as possible
1389 const size_t count
= 10000;
1391 // init with some data
1392 for( i
= 0; i
< count
; ++i
)
1394 buf
.Printf(wxT("%d"), i
);
1395 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1398 // test that insertion worked
1399 if( sh
.size() != count
)
1401 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
);
1404 for( i
= 0; i
< count
; ++i
)
1406 buf
.Printf(wxT("%d"), i
);
1407 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1409 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
1414 // check that iterators work
1416 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1420 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
1424 if( it
->second
!= sh
[it
->first
] )
1426 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
1431 if( sh
.size() != i
)
1433 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
);
1436 // test copy ctor, assignment operator
1437 myStringHashMap
h1( sh
), h2( 0 );
1440 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1442 if( h1
[it
->first
] != it
->second
)
1444 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str());
1447 if( h2
[it
->first
] != it
->second
)
1449 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str());
1454 for( i
= 0; i
< count
; ++i
)
1456 buf
.Printf(wxT("%d"), i
);
1457 size_t sz
= sh
.size();
1459 // test find() and erase(it)
1462 it
= sh
.find( buf
);
1463 if( it
!= sh
.end() )
1467 if( sh
.find( buf
) != sh
.end() )
1469 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1473 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
);
1478 size_t c
= sh
.erase( buf
);
1480 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
1482 if( sh
.find( buf
) != sh
.end() )
1484 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1488 // count should decrease
1489 if( sh
.size() != sz
- 1 )
1491 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
1495 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
1498 #endif // TEST_HASHMAP
1500 // ----------------------------------------------------------------------------
1502 // ----------------------------------------------------------------------------
1506 #include "wx/hashset.h"
1508 // test compilation of basic map types
1509 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet
);
1510 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet
);
1511 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
,
1512 myUnsignedHashSet
);
1513 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
,
1515 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
,
1517 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
,
1519 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
,
1521 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
,
1533 unsigned long operator()(const MyStruct
& s
) const
1534 { return m_dummy(s
.ptr
); }
1535 MyHash
& operator=(const MyHash
&) { return *this; }
1537 wxPointerHash m_dummy
;
1543 bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const
1544 { return s1
.ptr
== s2
.ptr
; }
1545 MyEqual
& operator=(const MyEqual
&) { return *this; }
1548 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet
);
1550 typedef myTestHashSet5 wxStringHashSet
;
1552 static void TestHashSet()
1554 wxPrintf(_T("*** Testing wxHashSet ***\n"));
1556 wxStringHashSet set1
;
1558 set1
.insert( _T("abc") );
1559 set1
.insert( _T("bbc") );
1560 set1
.insert( _T("cbc") );
1561 set1
.insert( _T("abc") );
1563 if( set1
.size() != 3 )
1564 wxPrintf(_T("*** ERROR IN INSERT ***\n"));
1570 tmp
.ptr
= &dummy
; tmp
.str
= _T("ABC");
1572 tmp
.ptr
= &dummy
+ 1;
1574 tmp
.ptr
= &dummy
; tmp
.str
= _T("CDE");
1577 if( set2
.size() != 2 )
1578 wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
1580 mySet::iterator it
= set2
.find( tmp
);
1582 if( it
== set2
.end() )
1583 wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
1584 if( it
->ptr
!= &dummy
)
1585 wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
1586 if( it
->str
!= _T("ABC") )
1587 wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
1589 wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
1592 #endif // TEST_HASHSET
1594 // ----------------------------------------------------------------------------
1596 // ----------------------------------------------------------------------------
1600 #include "wx/list.h"
1602 WX_DECLARE_LIST(Bar
, wxListBars
);
1603 #include "wx/listimpl.cpp"
1604 WX_DEFINE_LIST(wxListBars
);
1606 WX_DECLARE_LIST(int, wxListInt
);
1607 WX_DEFINE_LIST(wxListInt
);
1609 static void TestList()
1611 wxPuts(_T("*** Testing wxList operations ***\n"));
1617 for ( i
= 0; i
< 5; ++i
)
1618 list1
.Append(dummy
+ i
);
1620 if ( list1
.GetCount() != 5 )
1621 wxPuts(_T("Wrong number of items in list\n"));
1623 if ( list1
.Item(3)->GetData() != dummy
+ 3 )
1624 wxPuts(_T("Error in Item()\n"));
1626 if ( !list1
.Find(dummy
+ 4) )
1627 wxPuts(_T("Error in Find()\n"));
1629 wxListInt::compatibility_iterator node
= list1
.GetFirst();
1634 if ( node
->GetData() != dummy
+ i
)
1635 wxPuts(_T("Error in compatibility_iterator\n"));
1636 node
= node
->GetNext();
1640 if ( size_t(i
) != list1
.GetCount() )
1641 wxPuts(_T("Error in compatibility_iterator\n"));
1643 list1
.Insert(dummy
+ 0);
1644 list1
.Insert(1, dummy
+ 1);
1645 list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy
+ 2);
1647 node
= list1
.GetFirst();
1652 int* t
= node
->GetData();
1653 if ( t
!= dummy
+ i
)
1654 wxPuts(_T("Error in Insert\n"));
1655 node
= node
->GetNext();
1660 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1662 wxPuts(_T("*** Testing std::list operations ***\n"));
1666 wxListInt::iterator it
, en
;
1667 wxListInt::reverse_iterator rit
, ren
;
1669 for ( i
= 0; i
< 5; ++i
)
1670 list1
.push_back(i
+ &i
);
1672 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
1673 it
!= en
; ++it
, ++i
)
1674 if ( *it
!= i
+ &i
)
1675 wxPuts(_T("Error in iterator\n"));
1677 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
1678 rit
!= ren
; ++rit
, --i
)
1679 if ( *rit
!= i
+ &i
)
1680 wxPuts(_T("Error in reverse_iterator\n"));
1682 if ( *list1
.rbegin() != *--list1
.end() ||
1683 *list1
.begin() != *--list1
.rend() )
1684 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1685 if ( *list1
.begin() != *--++list1
.begin() ||
1686 *list1
.rbegin() != *--++list1
.rbegin() )
1687 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1689 if ( list1
.front() != &i
|| list1
.back() != &i
+ 4 )
1690 wxPuts(_T("Error in front()/back()\n"));
1692 list1
.erase(list1
.begin());
1693 list1
.erase(--list1
.end());
1695 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
1696 it
!= en
; ++it
, ++i
)
1697 if ( *it
!= i
+ &i
)
1698 wxPuts(_T("Error in erase()\n"));
1701 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1704 static void TestListCtor()
1706 wxPuts(_T("*** Testing wxList construction ***\n"));
1710 list1
.Append(new Bar(_T("first")));
1711 list1
.Append(new Bar(_T("second")));
1713 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
1714 list1
.GetCount(), Bar::GetNumber());
1719 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
1720 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1723 list1
.DeleteContents(true);
1725 WX_CLEAR_LIST(wxListBars
, list1
);
1729 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
1734 // ----------------------------------------------------------------------------
1736 // ----------------------------------------------------------------------------
1740 #include "wx/intl.h"
1741 #include "wx/utils.h" // for wxSetEnv
1743 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1745 // find the name of the language from its value
1746 static const wxChar
*GetLangName(int lang
)
1748 static const wxChar
*languageNames
[] =
1758 _T("ARABIC_ALGERIA"),
1759 _T("ARABIC_BAHRAIN"),
1762 _T("ARABIC_JORDAN"),
1763 _T("ARABIC_KUWAIT"),
1764 _T("ARABIC_LEBANON"),
1766 _T("ARABIC_MOROCCO"),
1769 _T("ARABIC_SAUDI_ARABIA"),
1772 _T("ARABIC_TUNISIA"),
1779 _T("AZERI_CYRILLIC"),
1794 _T("CHINESE_SIMPLIFIED"),
1795 _T("CHINESE_TRADITIONAL"),
1796 _T("CHINESE_HONGKONG"),
1797 _T("CHINESE_MACAU"),
1798 _T("CHINESE_SINGAPORE"),
1799 _T("CHINESE_TAIWAN"),
1805 _T("DUTCH_BELGIAN"),
1809 _T("ENGLISH_AUSTRALIA"),
1810 _T("ENGLISH_BELIZE"),
1811 _T("ENGLISH_BOTSWANA"),
1812 _T("ENGLISH_CANADA"),
1813 _T("ENGLISH_CARIBBEAN"),
1814 _T("ENGLISH_DENMARK"),
1816 _T("ENGLISH_JAMAICA"),
1817 _T("ENGLISH_NEW_ZEALAND"),
1818 _T("ENGLISH_PHILIPPINES"),
1819 _T("ENGLISH_SOUTH_AFRICA"),
1820 _T("ENGLISH_TRINIDAD"),
1821 _T("ENGLISH_ZIMBABWE"),
1829 _T("FRENCH_BELGIAN"),
1830 _T("FRENCH_CANADIAN"),
1831 _T("FRENCH_LUXEMBOURG"),
1832 _T("FRENCH_MONACO"),
1838 _T("GERMAN_AUSTRIAN"),
1839 _T("GERMAN_BELGIUM"),
1840 _T("GERMAN_LIECHTENSTEIN"),
1841 _T("GERMAN_LUXEMBOURG"),
1859 _T("ITALIAN_SWISS"),
1864 _T("KASHMIRI_INDIA"),
1882 _T("MALAY_BRUNEI_DARUSSALAM"),
1883 _T("MALAY_MALAYSIA"),
1893 _T("NORWEGIAN_BOKMAL"),
1894 _T("NORWEGIAN_NYNORSK"),
1901 _T("PORTUGUESE_BRAZILIAN"),
1904 _T("RHAETO_ROMANCE"),
1907 _T("RUSSIAN_UKRAINE"),
1913 _T("SERBIAN_CYRILLIC"),
1914 _T("SERBIAN_LATIN"),
1915 _T("SERBO_CROATIAN"),
1926 _T("SPANISH_ARGENTINA"),
1927 _T("SPANISH_BOLIVIA"),
1928 _T("SPANISH_CHILE"),
1929 _T("SPANISH_COLOMBIA"),
1930 _T("SPANISH_COSTA_RICA"),
1931 _T("SPANISH_DOMINICAN_REPUBLIC"),
1932 _T("SPANISH_ECUADOR"),
1933 _T("SPANISH_EL_SALVADOR"),
1934 _T("SPANISH_GUATEMALA"),
1935 _T("SPANISH_HONDURAS"),
1936 _T("SPANISH_MEXICAN"),
1937 _T("SPANISH_MODERN"),
1938 _T("SPANISH_NICARAGUA"),
1939 _T("SPANISH_PANAMA"),
1940 _T("SPANISH_PARAGUAY"),
1942 _T("SPANISH_PUERTO_RICO"),
1943 _T("SPANISH_URUGUAY"),
1945 _T("SPANISH_VENEZUELA"),
1949 _T("SWEDISH_FINLAND"),
1967 _T("URDU_PAKISTAN"),
1969 _T("UZBEK_CYRILLIC"),
1982 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1983 return languageNames
[lang
];
1985 return _T("INVALID");
1988 static void TestDefaultLang()
1990 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1992 static const wxChar
*langStrings
[] =
1994 NULL
, // system default
2001 _T("de_DE.iso88591"),
2003 _T("?"), // invalid lang spec
2004 _T("klingonese"), // I bet on some systems it does exist...
2007 wxPrintf(_T("The default system encoding is %s (%d)\n"),
2008 wxLocale::GetSystemEncodingName().c_str(),
2009 wxLocale::GetSystemEncoding());
2011 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
2013 const wxChar
*langStr
= langStrings
[n
];
2016 // FIXME: this doesn't do anything at all under Windows, we need
2017 // to create a new wxLocale!
2018 wxSetEnv(_T("LC_ALL"), langStr
);
2021 int lang
= gs_localeDefault
.GetSystemLanguage();
2022 wxPrintf(_T("Locale for '%s' is %s.\n"),
2023 langStr
? langStr
: _T("system default"), GetLangName(lang
));
2027 #endif // TEST_LOCALE
2029 // ----------------------------------------------------------------------------
2031 // ----------------------------------------------------------------------------
2035 #include "wx/mimetype.h"
2037 static void TestMimeEnum()
2039 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
2041 wxArrayString mimetypes
;
2043 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
2045 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
2050 for ( size_t n
= 0; n
< count
; n
++ )
2052 wxFileType
*filetype
=
2053 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
2056 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
2057 mimetypes
[n
].c_str());
2061 filetype
->GetDescription(&desc
);
2062 filetype
->GetExtensions(exts
);
2064 filetype
->GetIcon(NULL
);
2067 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
2070 extsAll
<< _T(", ");
2074 wxPrintf(_T("\t%s: %s (%s)\n"),
2075 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
2081 static void TestMimeOverride()
2083 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
2085 static const wxChar
*mailcap
= _T("/tmp/mailcap");
2086 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
2088 if ( wxFile::Exists(mailcap
) )
2089 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
2091 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
2093 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
2096 if ( wxFile::Exists(mimetypes
) )
2097 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
2099 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
2101 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
2107 static void TestMimeFilename()
2109 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
2111 static const wxChar
*filenames
[] =
2119 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
2121 const wxString fname
= filenames
[n
];
2122 wxString ext
= fname
.AfterLast(_T('.'));
2123 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
2126 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
2131 if ( !ft
->GetDescription(&desc
) )
2132 desc
= _T("<no description>");
2135 if ( !ft
->GetOpenCommand(&cmd
,
2136 wxFileType::MessageParameters(fname
, _T(""))) )
2137 cmd
= _T("<no command available>");
2139 cmd
= wxString(_T('"')) + cmd
+ _T('"');
2141 wxPrintf(_T("To open %s (%s) do %s.\n"),
2142 fname
.c_str(), desc
.c_str(), cmd
.c_str());
2151 static void TestMimeAssociate()
2153 wxPuts(_T("*** Testing creation of filetype association ***\n"));
2155 wxFileTypeInfo
ftInfo(
2156 _T("application/x-xyz"),
2157 _T("xyzview '%s'"), // open cmd
2158 _T(""), // print cmd
2159 _T("XYZ File"), // description
2160 _T(".xyz"), // extensions
2161 NULL
// end of extensions
2163 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
2165 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
2168 wxPuts(_T("ERROR: failed to create association!"));
2172 // TODO: read it back
2181 // ----------------------------------------------------------------------------
2182 // misc information functions
2183 // ----------------------------------------------------------------------------
2185 #ifdef TEST_INFO_FUNCTIONS
2187 #include "wx/utils.h"
2189 static void TestDiskInfo()
2191 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
2195 wxChar pathname
[128];
2196 wxPrintf(_T("\nEnter a directory name: "));
2197 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
2200 // kill the last '\n'
2201 pathname
[wxStrlen(pathname
) - 1] = 0;
2203 wxLongLong total
, free
;
2204 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
2206 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
2210 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
2211 (total
/ 1024).ToString().c_str(),
2212 (free
/ 1024).ToString().c_str(),
2218 static void TestOsInfo()
2220 wxPuts(_T("*** Testing OS info functions ***\n"));
2223 wxGetOsVersion(&major
, &minor
);
2224 wxPrintf(_T("Running under: %s, version %d.%d\n"),
2225 wxGetOsDescription().c_str(), major
, minor
);
2227 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
2229 wxPrintf(_T("Host name is %s (%s).\n"),
2230 wxGetHostName().c_str(), wxGetFullHostName().c_str());
2235 static void TestUserInfo()
2237 wxPuts(_T("*** Testing user info functions ***\n"));
2239 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
2240 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
2241 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
2242 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
2247 #endif // TEST_INFO_FUNCTIONS
2249 // ----------------------------------------------------------------------------
2251 // ----------------------------------------------------------------------------
2253 #ifdef TEST_LONGLONG
2255 #include "wx/longlong.h"
2256 #include "wx/timer.h"
2258 // make a 64 bit number from 4 16 bit ones
2259 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
2261 // get a random 64 bit number
2262 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
2264 static const long testLongs
[] =
2275 #if wxUSE_LONGLONG_WX
2276 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
2277 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2278 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
2279 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2280 #endif // wxUSE_LONGLONG_WX
2282 static void TestSpeed()
2284 static const long max
= 100000000;
2291 for ( n
= 0; n
< max
; n
++ )
2296 wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw
.Time());
2299 #if wxUSE_LONGLONG_NATIVE
2304 for ( n
= 0; n
< max
; n
++ )
2309 wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw
.Time());
2311 #endif // wxUSE_LONGLONG_NATIVE
2317 for ( n
= 0; n
< max
; n
++ )
2322 wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw
.Time());
2326 static void TestLongLongConversion()
2328 wxPuts(_T("*** Testing wxLongLong conversions ***\n"));
2332 for ( size_t n
= 0; n
< 100000; n
++ )
2336 #if wxUSE_LONGLONG_NATIVE
2337 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
2339 wxASSERT_MSG( a
== b
, _T("conversions failure") );
2341 wxPuts(_T("Can't do it without native long long type, test skipped."));
2344 #endif // wxUSE_LONGLONG_NATIVE
2346 if ( !(nTested
% 1000) )
2355 wxPuts(_T(" done!"));
2358 static void TestMultiplication()
2360 wxPuts(_T("*** Testing wxLongLong multiplication ***\n"));
2364 for ( size_t n
= 0; n
< 100000; n
++ )
2369 #if wxUSE_LONGLONG_NATIVE
2370 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
2371 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
2373 wxASSERT_MSG( a
*b
== aa
*bb
, _T("multiplication failure") );
2374 #else // !wxUSE_LONGLONG_NATIVE
2375 wxPuts(_T("Can't do it without native long long type, test skipped."));
2378 #endif // wxUSE_LONGLONG_NATIVE
2380 if ( !(nTested
% 1000) )
2389 wxPuts(_T(" done!"));
2392 static void TestDivision()
2394 wxPuts(_T("*** Testing wxLongLong division ***\n"));
2398 for ( size_t n
= 0; n
< 100000; n
++ )
2400 // get a random wxLongLong (shifting by 12 the MSB ensures that the
2401 // multiplication will not overflow)
2402 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
2404 // get a random (but non null) long (not wxLongLong for now) to divide
2416 #if wxUSE_LONGLONG_NATIVE
2417 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
2419 wxLongLongNative p
= m
/ l
, s
= m
% l
;
2420 wxASSERT_MSG( q
== p
&& r
== s
, _T("division failure") );
2421 #else // !wxUSE_LONGLONG_NATIVE
2422 // verify the result
2423 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
2424 #endif // wxUSE_LONGLONG_NATIVE
2426 if ( !(nTested
% 1000) )
2435 wxPuts(_T(" done!"));
2438 static void TestAddition()
2440 wxPuts(_T("*** Testing wxLongLong addition ***\n"));
2444 for ( size_t n
= 0; n
< 100000; n
++ )
2450 #if wxUSE_LONGLONG_NATIVE
2451 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
2452 wxLongLongNative(b
.GetHi(), b
.GetLo()),
2453 _T("addition failure") );
2454 #else // !wxUSE_LONGLONG_NATIVE
2455 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2456 #endif // wxUSE_LONGLONG_NATIVE
2458 if ( !(nTested
% 1000) )
2467 wxPuts(_T(" done!"));
2470 static void TestBitOperations()
2472 wxPuts(_T("*** Testing wxLongLong bit operation ***\n"));
2476 for ( size_t n
= 0; n
< 100000; n
++ )
2480 #if wxUSE_LONGLONG_NATIVE
2481 for ( size_t n
= 0; n
< 33; n
++ )
2484 #else // !wxUSE_LONGLONG_NATIVE
2485 wxPuts(_T("Can't do it without native long long type, test skipped."));
2488 #endif // wxUSE_LONGLONG_NATIVE
2490 if ( !(nTested
% 1000) )
2499 wxPuts(_T(" done!"));
2502 static void TestLongLongComparison()
2504 #if wxUSE_LONGLONG_WX
2505 wxPuts(_T("*** Testing wxLongLong comparison ***\n"));
2507 static const long ls
[2] =
2513 wxLongLongWx lls
[2];
2517 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2521 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2523 res
= lls
[m
] > testLongs
[n
];
2524 wxPrintf(_T("0x%lx > 0x%lx is %s (%s)\n"),
2525 ls
[m
], testLongs
[n
], res
? "true" : "false",
2526 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2528 res
= lls
[m
] < testLongs
[n
];
2529 wxPrintf(_T("0x%lx < 0x%lx is %s (%s)\n"),
2530 ls
[m
], testLongs
[n
], res
? "true" : "false",
2531 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2533 res
= lls
[m
] == testLongs
[n
];
2534 wxPrintf(_T("0x%lx == 0x%lx is %s (%s)\n"),
2535 ls
[m
], testLongs
[n
], res
? "true" : "false",
2536 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2539 #endif // wxUSE_LONGLONG_WX
2542 static void TestLongLongToString()
2544 wxPuts(_T("*** Testing wxLongLong::ToString() ***\n"));
2546 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2548 wxLongLong ll
= testLongs
[n
];
2549 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2552 wxLongLong
ll(0x12345678, 0x87654321);
2553 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2556 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2559 static void TestLongLongPrintf()
2561 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2563 #ifdef wxLongLongFmtSpec
2564 wxLongLong ll
= wxLL(0x1234567890abcdef);
2565 wxString s
= wxString::Format(_T("%") wxLongLongFmtSpec
_T("x"), ll
);
2566 wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"),
2567 s
.c_str(), s
== _T("1234567890abcdef") ? _T("ok") : _T("ERROR"));
2568 #else // !wxLongLongFmtSpec
2569 #error "wxLongLongFmtSpec not defined for this compiler/platform"
2576 #endif // TEST_LONGLONG
2578 // ----------------------------------------------------------------------------
2580 // ----------------------------------------------------------------------------
2582 #ifdef TEST_PATHLIST
2585 #define CMD_IN_PATH _T("ls")
2587 #define CMD_IN_PATH _T("command.com")
2590 static void TestPathList()
2592 wxPuts(_T("*** Testing wxPathList ***\n"));
2594 wxPathList pathlist
;
2595 pathlist
.AddEnvList(_T("PATH"));
2596 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
2599 wxPrintf(_T("ERROR: command not found in the path.\n"));
2603 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
2607 #endif // TEST_PATHLIST
2609 // ----------------------------------------------------------------------------
2610 // regular expressions
2611 // ----------------------------------------------------------------------------
2615 #include "wx/regex.h"
2617 static void TestRegExCompile()
2619 wxPuts(_T("*** Testing RE compilation ***\n"));
2621 static struct RegExCompTestData
2623 const wxChar
*pattern
;
2625 } regExCompTestData
[] =
2627 { _T("foo"), true },
2628 { _T("foo("), false },
2629 { _T("foo(bar"), false },
2630 { _T("foo(bar)"), true },
2631 { _T("foo["), false },
2632 { _T("foo[bar"), false },
2633 { _T("foo[bar]"), true },
2634 { _T("foo{"), true },
2635 { _T("foo{1"), false },
2636 { _T("foo{bar"), true },
2637 { _T("foo{1}"), true },
2638 { _T("foo{1,2}"), true },
2639 { _T("foo{bar}"), true },
2640 { _T("foo*"), true },
2641 { _T("foo**"), false },
2642 { _T("foo+"), true },
2643 { _T("foo++"), false },
2644 { _T("foo?"), true },
2645 { _T("foo??"), false },
2646 { _T("foo?+"), false },
2650 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2652 const RegExCompTestData
& data
= regExCompTestData
[n
];
2653 bool ok
= re
.Compile(data
.pattern
);
2655 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2657 ok
? _T("") : _T("not "),
2658 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2662 static void TestRegExMatch()
2664 wxPuts(_T("*** Testing RE matching ***\n"));
2666 static struct RegExMatchTestData
2668 const wxChar
*pattern
;
2671 } regExMatchTestData
[] =
2673 { _T("foo"), _T("bar"), false },
2674 { _T("foo"), _T("foobar"), true },
2675 { _T("^foo"), _T("foobar"), true },
2676 { _T("^foo"), _T("barfoo"), false },
2677 { _T("bar$"), _T("barbar"), true },
2678 { _T("bar$"), _T("barbar "), false },
2681 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2683 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2685 wxRegEx
re(data
.pattern
);
2686 bool ok
= re
.Matches(data
.text
);
2688 wxPrintf(_T("'%s' %s %s (%s)\n"),
2690 ok
? _T("matches") : _T("doesn't match"),
2692 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2696 static void TestRegExSubmatch()
2698 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2700 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2701 if ( !re
.IsValid() )
2703 wxPuts(_T("ERROR: compilation failed."));
2707 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2709 if ( !re
.Matches(text
) )
2711 wxPuts(_T("ERROR: match expected."));
2715 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2717 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2718 re
.GetMatch(text
, 3).c_str(),
2719 re
.GetMatch(text
, 2).c_str(),
2720 re
.GetMatch(text
, 4).c_str(),
2721 re
.GetMatch(text
, 1).c_str());
2725 static void TestRegExReplacement()
2727 wxPuts(_T("*** Testing RE replacement ***"));
2729 static struct RegExReplTestData
2733 const wxChar
*result
;
2735 } regExReplTestData
[] =
2737 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2738 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2739 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2740 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2741 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2742 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2743 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2746 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2747 wxRegEx
re(pattern
);
2749 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2751 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2753 const RegExReplTestData
& data
= regExReplTestData
[n
];
2755 wxString text
= data
.text
;
2756 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2758 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2759 data
.text
, data
.repl
,
2760 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2762 if ( text
== data
.result
&& nRepl
== data
.count
)
2768 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2769 data
.count
, data
.result
);
2774 static void TestRegExInteractive()
2776 wxPuts(_T("*** Testing RE interactively ***"));
2780 wxChar pattern
[128];
2781 wxPrintf(_T("\nEnter a pattern: "));
2782 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2785 // kill the last '\n'
2786 pattern
[wxStrlen(pattern
) - 1] = 0;
2789 if ( !re
.Compile(pattern
) )
2797 wxPrintf(_T("Enter text to match: "));
2798 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
2801 // kill the last '\n'
2802 text
[wxStrlen(text
) - 1] = 0;
2804 if ( !re
.Matches(text
) )
2806 wxPrintf(_T("No match.\n"));
2810 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
2813 for ( size_t n
= 1; ; n
++ )
2815 if ( !re
.GetMatch(&start
, &len
, n
) )
2820 wxPrintf(_T("Subexpr %u matched '%s'\n"),
2821 n
, wxString(text
+ start
, len
).c_str());
2828 #endif // TEST_REGEX
2830 // ----------------------------------------------------------------------------
2832 // ----------------------------------------------------------------------------
2842 static void TestDbOpen()
2850 // ----------------------------------------------------------------------------
2852 // ----------------------------------------------------------------------------
2855 NB: this stuff was taken from the glibc test suite and modified to build
2856 in wxWindows: if I read the copyright below properly, this shouldn't
2862 #ifdef wxTEST_PRINTF
2863 // use our functions from wxchar.cpp
2867 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
2868 // in the tests below
2869 int wxPrintf( const wxChar
*format
, ... );
2870 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
2873 #include "wx/longlong.h"
2877 static void rfg1 (void);
2878 static void rfg2 (void);
2882 fmtchk (const wxChar
*fmt
)
2884 (void) wxPrintf(_T("%s:\t`"), fmt
);
2885 (void) wxPrintf(fmt
, 0x12);
2886 (void) wxPrintf(_T("'\n"));
2890 fmtst1chk (const wxChar
*fmt
)
2892 (void) wxPrintf(_T("%s:\t`"), fmt
);
2893 (void) wxPrintf(fmt
, 4, 0x12);
2894 (void) wxPrintf(_T("'\n"));
2898 fmtst2chk (const wxChar
*fmt
)
2900 (void) wxPrintf(_T("%s:\t`"), fmt
);
2901 (void) wxPrintf(fmt
, 4, 4, 0x12);
2902 (void) wxPrintf(_T("'\n"));
2905 /* This page is covered by the following copyright: */
2907 /* (C) Copyright C E Chew
2909 * Feel free to copy, use and distribute this software provided:
2911 * 1. you do not pretend that you wrote it
2912 * 2. you leave this copyright notice intact.
2916 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2923 /* Formatted Output Test
2925 * This exercises the output formatting code.
2933 wxChar
*prefix
= buf
;
2936 wxPuts(_T("\nFormatted output test"));
2937 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
2938 wxStrcpy(prefix
, _T("%"));
2939 for (i
= 0; i
< 2; i
++) {
2940 for (j
= 0; j
< 2; j
++) {
2941 for (k
= 0; k
< 2; k
++) {
2942 for (l
= 0; l
< 2; l
++) {
2943 wxStrcpy(prefix
, _T("%"));
2944 if (i
== 0) wxStrcat(prefix
, _T("-"));
2945 if (j
== 0) wxStrcat(prefix
, _T("+"));
2946 if (k
== 0) wxStrcat(prefix
, _T("#"));
2947 if (l
== 0) wxStrcat(prefix
, _T("0"));
2948 wxPrintf(_T("%5s |"), prefix
);
2949 wxStrcpy(tp
, prefix
);
2950 wxStrcat(tp
, _T("6d |"));
2952 wxStrcpy(tp
, prefix
);
2953 wxStrcat(tp
, _T("6o |"));
2955 wxStrcpy(tp
, prefix
);
2956 wxStrcat(tp
, _T("6x |"));
2958 wxStrcpy(tp
, prefix
);
2959 wxStrcat(tp
, _T("6X |"));
2961 wxStrcpy(tp
, prefix
);
2962 wxStrcat(tp
, _T("6u |"));
2969 wxPrintf(_T("%10s\n"), (wxChar
*) NULL
);
2970 wxPrintf(_T("%-10s\n"), (wxChar
*) NULL
);
2973 static void TestPrintf()
2975 static wxChar shortstr
[] = _T("Hi, Z.");
2976 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
2977 I am ready for my first lesson today.");
2982 fmtchk(_T("%4.4x"));
2983 fmtchk(_T("%04.4x"));
2984 fmtchk(_T("%4.3x"));
2985 fmtchk(_T("%04.3x"));
2987 fmtst1chk(_T("%.*x"));
2988 fmtst1chk(_T("%0*x"));
2989 fmtst2chk(_T("%*.*x"));
2990 fmtst2chk(_T("%0*.*x"));
2992 wxPrintf(_T("bad format:\t\"%b\"\n"));
2993 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
2995 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
2996 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
2997 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
2998 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
2999 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
3000 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
3001 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
3002 wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456);
3003 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
3004 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
3006 wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr
);
3007 wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr
);
3008 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
3009 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
3010 wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar
*)NULL
);
3011 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
3013 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
3014 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
3015 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
3016 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
3017 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
3018 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
3019 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
3020 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
3021 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
3022 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
3023 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
3024 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
3026 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
3027 wxPrintf (_T(" %6.5f\n"), .1);
3028 wxPrintf (_T("x%5.4fx\n"), .5);
3030 wxPrintf (_T("%#03x\n"), 1);
3032 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
3038 while (niter
-- != 0)
3039 wxPrintf (_T("%.17e\n"), d
/ 2);
3043 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
3045 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
3046 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
3047 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
3048 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
3049 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
3050 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
3051 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
3052 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
3053 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
3054 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
3059 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
3061 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
3062 rc
, WXSIZEOF(buf
), buf
);
3065 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
3066 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
3072 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
3073 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
3074 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
3075 wxPrintf (_T("%g should be 123.456\n"), 123.456);
3076 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
3077 wxPrintf (_T("%g should be 10\n"), 10.0);
3078 wxPrintf (_T("%g should be 0.02\n"), 0.02);
3082 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
3088 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
3090 result
|= wxStrcmp (buf
,
3091 _T("onetwo three "));
3093 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
3100 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
3102 // for some reason below line fails under Borland
3103 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
3106 if (wxStrcmp (buf
, _T("40000000000")) != 0)
3109 wxPuts (_T("\tFAILED"));
3113 #endif // wxLongLong_t
3115 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
3116 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
3118 wxPuts (_T("--- Should be no further output. ---"));
3127 memset (bytes
, '\xff', sizeof bytes
);
3128 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
3129 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
3130 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
3132 wxPuts (_T("%hhn overwrite more bytes"));
3137 wxPuts (_T("%hhn wrote incorrect value"));
3149 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
3150 if (wxStrcmp (buf
, _T(" ")) != 0)
3151 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
3152 wxSprintf (buf
, _T("%5.f"), 33.3);
3153 if (wxStrcmp (buf
, _T(" 33")) != 0)
3154 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
3155 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
3156 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
3157 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
3158 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
3159 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
3160 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
3161 wxSprintf (buf
, _T("%.g"), 33.3);
3162 if (wxStrcmp (buf
, _T("3e+01")) != 0)
3163 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
3164 wxSprintf (buf
, _T("%.G"), 33.3);
3165 if (wxStrcmp (buf
, _T("3E+01")) != 0)
3166 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
3176 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
3177 if (wxStrcmp (buf
, _T("3")) != 0)
3178 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
3180 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
3181 if (wxStrcmp (buf
, _T("3")) != 0)
3182 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
3184 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
3185 if (wxStrcmp (buf
, _T(" 3")) != 0)
3186 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
3188 wxSprintf (buf
, _T("%04.*o"), prec
, 33);
3189 if (wxStrcmp (buf
, _T(" 041")) != 0)
3190 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
3192 wxSprintf (buf
, _T("%09.*u"), prec
, 33);
3193 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
3194 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
3196 wxSprintf (buf
, _T("%04.*x"), prec
, 33);
3197 if (wxStrcmp (buf
, _T(" 021")) != 0)
3198 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
3200 wxSprintf (buf
, _T("%04.*X"), prec
, 33);
3201 if (wxStrcmp (buf
, _T(" 021")) != 0)
3202 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
3205 #endif // TEST_PRINTF
3207 // ----------------------------------------------------------------------------
3208 // registry and related stuff
3209 // ----------------------------------------------------------------------------
3211 // this is for MSW only
3214 #undef TEST_REGISTRY
3219 #include "wx/confbase.h"
3220 #include "wx/msw/regconf.h"
3222 static void TestRegConfWrite()
3224 wxConfig
*config
= new wxConfig("myapp");
3225 config
->SetPath("/group1");
3226 config
->Write("entry1", "foo");
3227 config
->SetPath("/group2");
3228 config
->Write("entry1", "bar");
3231 static void TestRegConfRead()
3233 wxConfig
*config
= new wxConfig("myapp");
3237 config
->SetPath("/");
3238 puts("Enumerating / subgroups:");
3239 bool bCont
= config
->GetFirstGroup(str
, dummy
);
3243 bCont
= config
->GetNextGroup(str
, dummy
);
3247 #endif // TEST_REGCONF
3249 #ifdef TEST_REGISTRY
3251 #include "wx/msw/registry.h"
3253 // I chose this one because I liked its name, but it probably only exists under
3255 static const wxChar
*TESTKEY
=
3256 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
3258 static void TestRegistryRead()
3260 wxPuts(_T("*** testing registry reading ***"));
3262 wxRegKey
key(TESTKEY
);
3263 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
3266 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
3271 size_t nSubKeys
, nValues
;
3272 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
3274 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
3277 wxPrintf(_T("Enumerating values:\n"));
3281 bool cont
= key
.GetFirstValue(value
, dummy
);
3284 wxPrintf(_T("Value '%s': type "), value
.c_str());
3285 switch ( key
.GetValueType(value
) )
3287 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
3288 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
3289 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
3290 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
3291 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
3292 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
3293 default: wxPrintf(_T("other (unknown)")); break;
3296 wxPrintf(_T(", value = "));
3297 if ( key
.IsNumericValue(value
) )
3300 key
.QueryValue(value
, &val
);
3301 wxPrintf(_T("%ld"), val
);
3306 key
.QueryValue(value
, val
);
3307 wxPrintf(_T("'%s'"), val
.c_str());
3309 key
.QueryRawValue(value
, val
);
3310 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
3315 cont
= key
.GetNextValue(value
, dummy
);
3319 static void TestRegistryAssociation()
3322 The second call to deleteself genertaes an error message, with a
3323 messagebox saying .flo is crucial to system operation, while the .ddf
3324 call also fails, but with no error message
3329 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
3331 key
= _T("ddxf_auto_file") ;
3332 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
3334 key
= _T("ddxf_auto_file") ;
3335 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
3337 key
= _T("program,0") ;
3338 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
3340 key
= _T("program \"%1\"") ;
3342 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
3344 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
3346 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
3348 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
3352 #endif // TEST_REGISTRY
3354 // ----------------------------------------------------------------------------
3356 // ----------------------------------------------------------------------------
3358 #ifdef TEST_SCOPEGUARD
3360 #include "wx/scopeguard.h"
3362 static void function0() { puts("function0()"); }
3363 static void function1(int n
) { printf("function1(%d)\n", n
); }
3364 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
3368 void method0() { printf("method0()\n"); }
3369 void method1(int n
) { printf("method1(%d)\n", n
); }
3370 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
3373 static void TestScopeGuard()
3375 ON_BLOCK_EXIT0(function0
);
3376 ON_BLOCK_EXIT1(function1
, 17);
3377 ON_BLOCK_EXIT2(function2
, 3.14, 'p');
3380 ON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
);
3381 ON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7);
3382 ON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e');
3384 wxScopeGuard dismissed
= wxMakeGuard(function0
);
3385 dismissed
.Dismiss();
3390 // ----------------------------------------------------------------------------
3392 // ----------------------------------------------------------------------------
3396 #include "wx/socket.h"
3397 #include "wx/protocol/protocol.h"
3398 #include "wx/protocol/http.h"
3400 static void TestSocketServer()
3402 wxPuts(_T("*** Testing wxSocketServer ***\n"));
3404 static const int PORT
= 3000;
3409 wxSocketServer
*server
= new wxSocketServer(addr
);
3410 if ( !server
->Ok() )
3412 wxPuts(_T("ERROR: failed to bind"));
3420 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
3422 wxSocketBase
*socket
= server
->Accept();
3425 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
3429 wxPuts(_T("Server: got a client."));
3431 server
->SetTimeout(60); // 1 min
3434 while ( !close
&& socket
->IsConnected() )
3437 wxChar ch
= _T('\0');
3440 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
3442 // don't log error if the client just close the connection
3443 if ( socket
->IsConnected() )
3445 wxPuts(_T("ERROR: in wxSocket::Read."));
3465 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
3466 if ( s
== _T("close") )
3468 wxPuts(_T("Closing connection"));
3472 else if ( s
== _T("quit") )
3477 wxPuts(_T("Shutting down the server"));
3479 else // not a special command
3481 socket
->Write(s
.MakeUpper().c_str(), s
.length());
3482 socket
->Write("\r\n", 2);
3483 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
3489 wxPuts(_T("Server: lost a client unexpectedly."));
3495 // same as "delete server" but is consistent with GUI programs
3499 static void TestSocketClient()
3501 wxPuts(_T("*** Testing wxSocketClient ***\n"));
3503 static const wxChar
*hostname
= _T("www.wxwindows.org");
3506 addr
.Hostname(hostname
);
3509 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
3511 wxSocketClient client
;
3512 if ( !client
.Connect(addr
) )
3514 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3518 wxPrintf(_T("--- Connected to %s:%u...\n"),
3519 addr
.Hostname().c_str(), addr
.Service());
3523 // could use simply "GET" here I suppose
3525 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
3526 client
.Write(cmdGet
, cmdGet
.length());
3527 wxPrintf(_T("--- Sent command '%s' to the server\n"),
3528 MakePrintable(cmdGet
).c_str());
3529 client
.Read(buf
, WXSIZEOF(buf
));
3530 wxPrintf(_T("--- Server replied:\n%s"), buf
);
3534 #endif // TEST_SOCKETS
3536 // ----------------------------------------------------------------------------
3538 // ----------------------------------------------------------------------------
3542 #include "wx/protocol/ftp.h"
3546 #define FTP_ANONYMOUS
3548 #ifdef FTP_ANONYMOUS
3549 static const wxChar
*directory
= _T("/pub");
3550 static const wxChar
*filename
= _T("welcome.msg");
3552 static const wxChar
*directory
= _T("/etc");
3553 static const wxChar
*filename
= _T("issue");
3556 static bool TestFtpConnect()
3558 wxPuts(_T("*** Testing FTP connect ***"));
3560 #ifdef FTP_ANONYMOUS
3561 static const wxChar
*hostname
= _T("ftp.wxwindows.org");
3563 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
3564 #else // !FTP_ANONYMOUS
3565 static const wxChar
*hostname
= "localhost";
3568 wxFgets(user
, WXSIZEOF(user
), stdin
);
3569 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
3572 wxChar password
[256];
3573 wxPrintf(_T("Password for %s: "), password
);
3574 wxFgets(password
, WXSIZEOF(password
), stdin
);
3575 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
3576 ftp
.SetPassword(password
);
3578 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
3579 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
3581 if ( !ftp
.Connect(hostname
) )
3583 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3589 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
3590 hostname
, ftp
.Pwd().c_str());
3596 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
3597 static void TestFtpWuFtpd()
3600 static const wxChar
*hostname
= _T("ftp.eudora.com");
3601 if ( !ftp
.Connect(hostname
) )
3603 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3607 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
3608 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3611 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3615 size_t size
= in
->GetSize();
3616 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3618 wxChar
*data
= new wxChar
[size
];
3619 if ( !in
->Read(data
, size
) )
3621 wxPuts(_T("ERROR: read error"));
3625 wxPrintf(_T("Successfully retrieved the file.\n"));
3634 static void TestFtpList()
3636 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
3639 if ( !ftp
.ChDir(directory
) )
3641 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3644 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3646 // test NLIST and LIST
3647 wxArrayString files
;
3648 if ( !ftp
.GetFilesList(files
) )
3650 wxPuts(_T("ERROR: failed to get NLIST of files"));
3654 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
3655 size_t count
= files
.GetCount();
3656 for ( size_t n
= 0; n
< count
; n
++ )
3658 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3660 wxPuts(_T("End of the file list"));
3663 if ( !ftp
.GetDirList(files
) )
3665 wxPuts(_T("ERROR: failed to get LIST of files"));
3669 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
3670 size_t count
= files
.GetCount();
3671 for ( size_t n
= 0; n
< count
; n
++ )
3673 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3675 wxPuts(_T("End of the file list"));
3678 if ( !ftp
.ChDir(_T("..")) )
3680 wxPuts(_T("ERROR: failed to cd to .."));
3683 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3686 static void TestFtpDownload()
3688 wxPuts(_T("*** Testing wxFTP download ***\n"));
3691 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3694 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3698 size_t size
= in
->GetSize();
3699 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3702 wxChar
*data
= new wxChar
[size
];
3703 if ( !in
->Read(data
, size
) )
3705 wxPuts(_T("ERROR: read error"));
3709 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
3717 static void TestFtpFileSize()
3719 wxPuts(_T("*** Testing FTP SIZE command ***"));
3721 if ( !ftp
.ChDir(directory
) )
3723 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3726 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3728 if ( ftp
.FileExists(filename
) )
3730 int size
= ftp
.GetFileSize(filename
);
3732 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
3734 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
3738 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
3742 static void TestFtpMisc()
3744 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
3746 if ( ftp
.SendCommand(_T("STAT")) != '2' )
3748 wxPuts(_T("ERROR: STAT failed"));
3752 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
3755 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
3757 wxPuts(_T("ERROR: HELP SITE failed"));
3761 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
3762 ftp
.GetLastResult().c_str());
3766 static void TestFtpInteractive()
3768 wxPuts(_T("\n*** Interactive wxFTP test ***"));
3774 wxPrintf(_T("Enter FTP command: "));
3775 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3778 // kill the last '\n'
3779 buf
[wxStrlen(buf
) - 1] = 0;
3781 // special handling of LIST and NLST as they require data connection
3782 wxString
start(buf
, 4);
3784 if ( start
== _T("LIST") || start
== _T("NLST") )
3787 if ( wxStrlen(buf
) > 4 )
3790 wxArrayString files
;
3791 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
3793 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
3797 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
3798 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
3799 size_t count
= files
.GetCount();
3800 for ( size_t n
= 0; n
< count
; n
++ )
3802 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3804 wxPuts(_T("--- End of the file list"));
3809 wxChar ch
= ftp
.SendCommand(buf
);
3810 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
3813 wxPrintf(_T(" (return code %c)"), ch
);
3816 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
3820 wxPuts(_T("\n*** done ***"));
3823 static void TestFtpUpload()
3825 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
3828 static const wxChar
*file1
= _T("test1");
3829 static const wxChar
*file2
= _T("test2");
3830 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
3833 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3834 out
->Write("First hello", 11);
3838 // send a command to check the remote file
3839 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
3841 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
3845 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
3846 file1
, ftp
.GetLastResult().c_str());
3849 out
= ftp
.GetOutputStream(file2
);
3852 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3853 out
->Write("Second hello", 12);
3860 // ----------------------------------------------------------------------------
3862 // ----------------------------------------------------------------------------
3866 #include "wx/wfstream.h"
3867 #include "wx/mstream.h"
3869 static void TestFileStream()
3871 wxPuts(_T("*** Testing wxFileInputStream ***"));
3873 static const wxChar
*filename
= _T("testdata.fs");
3875 wxFileOutputStream
fsOut(filename
);
3876 fsOut
.Write("foo", 3);
3879 wxFileInputStream
fsIn(filename
);
3880 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
3881 while ( !fsIn
.Eof() )
3883 putchar(fsIn
.GetC());
3886 if ( !wxRemoveFile(filename
) )
3888 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
);
3891 wxPuts(_T("\n*** wxFileInputStream test done ***"));
3894 static void TestMemoryStream()
3896 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3898 wxMemoryOutputStream memOutStream
;
3899 wxPrintf(_T("Initially out stream offset: %lu\n"),
3900 (unsigned long)memOutStream
.TellO());
3902 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
3904 memOutStream
.PutC(*p
);
3907 wxPrintf(_T("Final out stream offset: %lu\n"),
3908 (unsigned long)memOutStream
.TellO());
3910 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
3913 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
3915 wxMemoryInputStream
memInpStream(buf
, len
);
3916 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3917 while ( !memInpStream
.Eof() )
3919 putchar(memInpStream
.GetC());
3922 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
3925 #endif // TEST_STREAMS
3927 // ----------------------------------------------------------------------------
3929 // ----------------------------------------------------------------------------
3933 #include "wx/timer.h"
3934 #include "wx/utils.h"
3936 static void TestStopWatch()
3938 wxPuts(_T("*** Testing wxStopWatch ***\n"));
3942 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
3945 wxPrintf(_T("\t%ldms\n"), sw
.Time());
3947 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
3951 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3954 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
3957 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3960 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
3963 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3966 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
3967 for ( size_t n
= 0; n
< 70; n
++ )
3971 for ( size_t m
= 0; m
< 100000; m
++ )
3973 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3975 wxPuts(_T("\ntime is negative - ERROR!"));
3983 wxPuts(_T(", ok."));
3986 #endif // TEST_TIMER
3988 // ----------------------------------------------------------------------------
3990 // ----------------------------------------------------------------------------
3994 #include "wx/vcard.h"
3996 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3999 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
4002 wxPrintf(_T("%s%s"),
4003 wxString(_T('\t'), level
).c_str(),
4004 vcObj
->GetName().c_str());
4007 switch ( vcObj
->GetType() )
4009 case wxVCardObject::String
:
4010 case wxVCardObject::UString
:
4013 vcObj
->GetValue(&val
);
4014 value
<< _T('"') << val
<< _T('"');
4018 case wxVCardObject::Int
:
4021 vcObj
->GetValue(&i
);
4022 value
.Printf(_T("%u"), i
);
4026 case wxVCardObject::Long
:
4029 vcObj
->GetValue(&l
);
4030 value
.Printf(_T("%lu"), l
);
4034 case wxVCardObject::None
:
4037 case wxVCardObject::Object
:
4038 value
= _T("<node>");
4042 value
= _T("<unknown value type>");
4046 wxPrintf(_T(" = %s"), value
.c_str());
4049 DumpVObject(level
+ 1, *vcObj
);
4052 vcObj
= vcard
.GetNextProp(&cookie
);
4056 static void DumpVCardAddresses(const wxVCard
& vcard
)
4058 wxPuts(_T("\nShowing all addresses from vCard:\n"));
4062 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
4066 int flags
= addr
->GetFlags();
4067 if ( flags
& wxVCardAddress::Domestic
)
4069 flagsStr
<< _T("domestic ");
4071 if ( flags
& wxVCardAddress::Intl
)
4073 flagsStr
<< _T("international ");
4075 if ( flags
& wxVCardAddress::Postal
)
4077 flagsStr
<< _T("postal ");
4079 if ( flags
& wxVCardAddress::Parcel
)
4081 flagsStr
<< _T("parcel ");
4083 if ( flags
& wxVCardAddress::Home
)
4085 flagsStr
<< _T("home ");
4087 if ( flags
& wxVCardAddress::Work
)
4089 flagsStr
<< _T("work ");
4092 wxPrintf(_T("Address %u:\n")
4094 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
4097 addr
->GetPostOffice().c_str(),
4098 addr
->GetExtAddress().c_str(),
4099 addr
->GetStreet().c_str(),
4100 addr
->GetLocality().c_str(),
4101 addr
->GetRegion().c_str(),
4102 addr
->GetPostalCode().c_str(),
4103 addr
->GetCountry().c_str()
4107 addr
= vcard
.GetNextAddress(&cookie
);
4111 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
4113 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
4117 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
4121 int flags
= phone
->GetFlags();
4122 if ( flags
& wxVCardPhoneNumber::Voice
)
4124 flagsStr
<< _T("voice ");
4126 if ( flags
& wxVCardPhoneNumber::Fax
)
4128 flagsStr
<< _T("fax ");
4130 if ( flags
& wxVCardPhoneNumber::Cellular
)
4132 flagsStr
<< _T("cellular ");
4134 if ( flags
& wxVCardPhoneNumber::Modem
)
4136 flagsStr
<< _T("modem ");
4138 if ( flags
& wxVCardPhoneNumber::Home
)
4140 flagsStr
<< _T("home ");
4142 if ( flags
& wxVCardPhoneNumber::Work
)
4144 flagsStr
<< _T("work ");
4147 wxPrintf(_T("Phone number %u:\n")
4152 phone
->GetNumber().c_str()
4156 phone
= vcard
.GetNextPhoneNumber(&cookie
);
4160 static void TestVCardRead()
4162 wxPuts(_T("*** Testing wxVCard reading ***\n"));
4164 wxVCard
vcard(_T("vcard.vcf"));
4165 if ( !vcard
.IsOk() )
4167 wxPuts(_T("ERROR: couldn't load vCard."));
4171 // read individual vCard properties
4172 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
4176 vcObj
->GetValue(&value
);
4181 value
= _T("<none>");
4184 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
4187 if ( !vcard
.GetFullName(&value
) )
4189 value
= _T("<none>");
4192 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
4194 // now show how to deal with multiply occuring properties
4195 DumpVCardAddresses(vcard
);
4196 DumpVCardPhoneNumbers(vcard
);
4198 // and finally show all
4199 wxPuts(_T("\nNow dumping the entire vCard:\n")
4200 "-----------------------------\n");
4202 DumpVObject(0, vcard
);
4206 static void TestVCardWrite()
4208 wxPuts(_T("*** Testing wxVCard writing ***\n"));
4211 if ( !vcard
.IsOk() )
4213 wxPuts(_T("ERROR: couldn't create vCard."));
4218 vcard
.SetName("Zeitlin", "Vadim");
4219 vcard
.SetFullName("Vadim Zeitlin");
4220 vcard
.SetOrganization("wxWindows", "R&D");
4222 // just dump the vCard back
4223 wxPuts(_T("Entire vCard follows:\n"));
4224 wxPuts(vcard
.Write());
4228 #endif // TEST_VCARD
4230 // ----------------------------------------------------------------------------
4232 // ----------------------------------------------------------------------------
4234 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
4240 #include "wx/volume.h"
4242 static const wxChar
*volumeKinds
[] =
4248 _T("network volume"),
4252 static void TestFSVolume()
4254 wxPuts(_T("*** Testing wxFSVolume class ***"));
4256 wxArrayString volumes
= wxFSVolume::GetVolumes();
4257 size_t count
= volumes
.GetCount();
4261 wxPuts(_T("ERROR: no mounted volumes?"));
4265 wxPrintf(_T("%u mounted volumes found:\n"), count
);
4267 for ( size_t n
= 0; n
< count
; n
++ )
4269 wxFSVolume
vol(volumes
[n
]);
4272 wxPuts(_T("ERROR: couldn't create volume"));
4276 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
4278 vol
.GetDisplayName().c_str(),
4279 vol
.GetName().c_str(),
4280 volumeKinds
[vol
.GetKind()],
4281 vol
.IsWritable() ? _T("rw") : _T("ro"),
4282 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
4287 #endif // TEST_VOLUME
4289 // ----------------------------------------------------------------------------
4290 // wide char and Unicode support
4291 // ----------------------------------------------------------------------------
4295 static void TestUnicodeToFromAscii()
4297 wxPuts(_T("Testing wxString::To/FromAscii()\n"));
4299 static const char *msg
= "Hello, world!";
4300 wxString s
= wxString::FromAscii(msg
);
4302 wxPrintf(_T("Message in Unicode: %s\n"), s
.c_str());
4303 printf("Message in ASCII: %s\n", (const char *)s
.ToAscii());
4305 wxPutchar(_T('\n'));
4308 #include "wx/textfile.h"
4310 static void TestUnicodeTextFileRead()
4312 wxPuts(_T("Testing wxTextFile in Unicode build\n"));
4315 if ( file
.Open(_T("testdata.fc"), wxConvLocal
) )
4317 const size_t count
= file
.GetLineCount();
4318 for ( size_t n
= 0; n
< count
; n
++ )
4320 const wxString
& s
= file
[n
];
4322 wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"),
4323 (unsigned)n
, s
.c_str(), (unsigned)s
.length(), s
.Last());
4328 #endif // TEST_UNICODE
4332 #include "wx/strconv.h"
4333 #include "wx/fontenc.h"
4334 #include "wx/encconv.h"
4335 #include "wx/buffer.h"
4337 static const unsigned char utf8koi8r
[] =
4339 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
4340 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
4341 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
4342 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
4343 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
4344 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
4345 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
4348 static const unsigned char utf8iso8859_1
[] =
4350 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
4351 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
4352 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
4353 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
4354 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
4357 static const unsigned char utf8Invalid
[] =
4359 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
4360 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
4361 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
4362 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
4366 static const struct Utf8Data
4368 const unsigned char *text
;
4370 const wxChar
*charset
;
4371 wxFontEncoding encoding
;
4374 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4375 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
4376 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4379 static void TestUtf8()
4381 wxPuts(_T("*** Testing UTF8 support ***\n"));
4386 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
4388 const Utf8Data
& u8d
= utf8data
[n
];
4389 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
4390 WXSIZEOF(wbuf
)) == (size_t)-1 )
4392 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4396 wxCSConv
conv(u8d
.charset
);
4397 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
4399 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
4403 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
4407 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
4409 s
= _T("<< conversion failed >>");
4410 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
4417 static void TestEncodingConverter()
4419 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
4421 // using wxEncodingConverter should give the same result as above
4424 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
4425 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
4427 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4431 wxEncodingConverter ec
;
4432 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
4433 ec
.Convert(wbuf
, buf
);
4434 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
4440 #endif // TEST_WCHAR
4442 // ----------------------------------------------------------------------------
4444 // ----------------------------------------------------------------------------
4448 #include "wx/filesys.h"
4449 #include "wx/fs_zip.h"
4450 #include "wx/zipstrm.h"
4452 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
4454 static void TestZipStreamRead()
4456 wxPuts(_T("*** Testing ZIP reading ***\n"));
4458 static const wxChar
*filename
= _T("foo");
4459 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
4460 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4462 wxPrintf(_T("Dumping the file '%s':\n"), filename
);
4463 while ( !istr
.Eof() )
4465 putchar(istr
.GetC());
4469 wxPuts(_T("\n----- done ------"));
4472 static void DumpZipDirectory(wxFileSystem
& fs
,
4473 const wxString
& dir
,
4474 const wxString
& indent
)
4476 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
4477 TESTFILE_ZIP
, dir
.c_str());
4478 wxString wildcard
= prefix
+ _T("/*");
4480 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
4481 while ( !dirname
.empty() )
4483 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
4485 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4490 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
4492 DumpZipDirectory(fs
, dirname
,
4493 indent
+ wxString(_T(' '), 4));
4495 dirname
= fs
.FindNext();
4498 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
4499 while ( !filename
.empty() )
4501 if ( !filename
.StartsWith(prefix
, &filename
) )
4503 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4508 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
4510 filename
= fs
.FindNext();
4514 static void TestZipFileSystem()
4516 wxPuts(_T("*** Testing ZIP file system ***\n"));
4518 wxFileSystem::AddHandler(new wxZipFSHandler
);
4520 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
4522 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
4527 // ----------------------------------------------------------------------------
4529 // ----------------------------------------------------------------------------
4533 #include "wx/zstream.h"
4534 #include "wx/wfstream.h"
4536 static const wxChar
*FILENAME_GZ
= _T("test.gz");
4537 static const wxChar
*TEST_DATA
= _T("hello and hello and hello and hello and hello");
4539 static void TestZlibStreamWrite()
4541 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4543 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
4544 wxZlibOutputStream
ostr(fileOutStream
);
4545 wxPrintf(_T("Compressing the test string... "));
4546 ostr
.Write(TEST_DATA
, wxStrlen(TEST_DATA
) + 1);
4549 wxPuts(_T("(ERROR: failed)"));
4556 wxPuts(_T("\n----- done ------"));
4559 static void TestZlibStreamRead()
4561 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4563 wxFileInputStream
fileInStream(FILENAME_GZ
);
4564 wxZlibInputStream
istr(fileInStream
);
4565 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4567 wxPuts(_T("Dumping the file:"));
4568 while ( !istr
.Eof() )
4570 putchar(istr
.GetC());
4574 wxPuts(_T("\n----- done ------"));
4579 // ----------------------------------------------------------------------------
4581 // ----------------------------------------------------------------------------
4585 #include "wx/wfstream.h"
4586 #include "wx/gzstream.h"
4587 #include "wx/filename.h"
4588 #include "wx/txtstrm.h"
4590 // Reads two input streams and verifies that they are the same (and non-emtpy)
4592 void GzipVerify(wxInputStream
&in1
, wxInputStream
&in2
)
4595 wxPuts(_T(" Can't verify"));
4599 const int BUFSIZE
= 8192;
4600 wxCharBuffer
buf1(BUFSIZE
);
4601 wxCharBuffer
buf2(BUFSIZE
);
4605 int n1
= in1
.Read(buf1
.data(), BUFSIZE
).LastRead();
4606 int n2
= in2
.Read(buf2
.data(), BUFSIZE
).LastRead();
4608 if (n1
!= n2
|| (n1
&& memcmp(buf1
, buf2
, n1
) != 0) || (!n1
&& none
)) {
4609 wxPuts(_T(" Failure"));
4614 wxPuts(_T(" Success"));
4622 in1
.Read(buf1
.data(), BUFSIZE
);
4624 in2
.Read(buf2
.data(), BUFSIZE
);
4627 // Write a gzip file and read it back.
4631 wxPuts(_T("*** Testing gzip streams ***\n"));
4633 const wxString testname
= _T("gziptest");
4634 const wxString gzipname
= testname
+ _T(".gz");
4636 // write some random test data to a testfile
4637 wxPuts(_T("Writing random test data to ") + testname
+ _T("..."));
4639 wxFFileOutputStream
outstream(testname
);
4640 wxTextOutputStream
textout(outstream
);
4642 for (int i
= 0; i
< 1000 && outstream
.Ok(); i
++)
4643 textout
<< rand() << rand() << rand() << rand() << endl
;
4645 wxPuts(_T(" Done"));
4648 wxFileName
fn(testname
);
4649 wxDateTime dt
= fn
.GetModificationTime();
4650 wxFFileInputStream
instream(testname
);
4652 // try writing a gzip file
4653 wxPuts(_T("Writing ") + gzipname
+ _T(" using wxGzipOutputStream..."));
4655 wxFFileOutputStream
outstream(gzipname
);
4656 wxGzipOutputStream
gzip(outstream
, testname
, dt
);
4658 if (!gzip
.Write(instream
))
4659 wxPuts(_T(" Failure"));
4661 wxPuts(_T(" Success"));
4664 // try reading the gzip file
4665 wxPuts(_T("Reading ") + gzipname
+ _T(" using wxGzipInputStream..."));
4668 wxFFileInputStream
instream2(gzipname
);
4669 wxGzipInputStream
gzip(instream2
);
4670 GzipVerify(instream
, gzip
);
4672 if (gzip
.GetName() != fn
.GetFullName())
4673 wxPuts(gzipname
+ _T(" contains incorrect filename: ")
4675 if (dt
.IsValid() && gzip
.GetDateTime() != dt
)
4676 wxPuts(gzipname
+ _T(" contains incorrect timestamp: ")
4677 + gzip
.GetDateTime().Format());
4681 // then verify it using gzip program if it is in the path
4682 wxPuts(_T("Reading ") + gzipname
+ _T(" using gzip program..."));
4683 wxFFile
file(popen((_T("gzip -d -c ") + gzipname
).mb_str(), "r"));
4685 wxFFileInputStream
instream2(file
);
4687 GzipVerify(instream
, instream2
);
4692 // try reading a gzip created by gzip program
4693 wxPuts(_T("Reading output of gzip program using wxGzipInputStream..."));
4694 file
.Attach(popen((_T("gzip -c ") + testname
).mb_str(), "r"));
4696 wxFFileInputStream
instream2(file
);
4697 wxGzipInputStream
gzip(instream2
);
4699 GzipVerify(instream
, gzip
);
4705 wxPuts(_T("\n--- Done gzip streams ---"));
4710 // ----------------------------------------------------------------------------
4712 // ----------------------------------------------------------------------------
4714 #ifdef TEST_DATETIME
4718 #include "wx/datetime.h"
4723 wxDateTime::wxDateTime_t day
;
4724 wxDateTime::Month month
;
4726 wxDateTime::wxDateTime_t hour
, min
, sec
;
4728 wxDateTime::WeekDay wday
;
4729 time_t gmticks
, ticks
;
4731 void Init(const wxDateTime::Tm
& tm
)
4740 gmticks
= ticks
= -1;
4743 wxDateTime
DT() const
4744 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
4746 bool SameDay(const wxDateTime::Tm
& tm
) const
4748 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
4751 wxString
Format() const
4754 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
4756 wxDateTime::GetMonthName(month
).c_str(),
4758 abs(wxDateTime::ConvertYearToBC(year
)),
4759 year
> 0 ? _T("AD") : _T("BC"));
4763 wxString
FormatDate() const
4766 s
.Printf(_T("%02d-%s-%4d%s"),
4768 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4769 abs(wxDateTime::ConvertYearToBC(year
)),
4770 year
> 0 ? _T("AD") : _T("BC"));
4775 static const Date testDates
[] =
4777 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
4778 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
4779 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
4780 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
4781 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
4782 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
4783 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
4784 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
4785 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
4786 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
4787 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
4788 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
4789 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
4790 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
4791 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
4792 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
4793 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
4794 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
4795 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
4798 // this test miscellaneous static wxDateTime functions
4799 static void TestTimeStatic()
4801 wxPuts(_T("\n*** wxDateTime static methods test ***"));
4803 // some info about the current date
4804 int year
= wxDateTime::GetCurrentYear();
4805 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
4807 wxDateTime::IsLeapYear(year
) ? "" : "not ",
4808 wxDateTime::GetNumberOfDays(year
));
4810 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
4811 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
4812 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4813 wxDateTime::GetMonthName(month
).c_str(),
4814 wxDateTime::GetNumberOfDays(month
));
4817 static const size_t nYears
= 5;
4818 static const size_t years
[2][nYears
] =
4820 // first line: the years to test
4821 { 1990, 1976, 2000, 2030, 1984, },
4823 // second line: true if leap, false otherwise
4824 { false, true, true, false, true }
4827 for ( size_t n
= 0; n
< nYears
; n
++ )
4829 int year
= years
[0][n
];
4830 bool should
= years
[1][n
] != 0,
4831 is
= wxDateTime::IsLeapYear(year
);
4833 wxPrintf(_T("Year %d is %sa leap year (%s)\n"),
4836 should
== is
? "ok" : "ERROR");
4838 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
4842 // test constructing wxDateTime objects
4843 static void TestTimeSet()
4845 wxPuts(_T("\n*** wxDateTime construction test ***"));
4847 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4849 const Date
& d1
= testDates
[n
];
4850 wxDateTime dt
= d1
.DT();
4853 d2
.Init(dt
.GetTm());
4855 wxString s1
= d1
.Format(),
4858 wxPrintf(_T("Date: %s == %s (%s)\n"),
4859 s1
.c_str(), s2
.c_str(),
4860 s1
== s2
? _T("ok") : _T("ERROR"));
4864 // test time zones stuff
4865 static void TestTimeZones()
4867 wxPuts(_T("\n*** wxDateTime timezone test ***"));
4869 wxDateTime now
= wxDateTime::Now();
4871 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
4872 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
4873 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
4874 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
4875 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
4876 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
4878 wxDateTime::Tm tm
= now
.GetTm();
4879 if ( wxDateTime(tm
) != now
)
4881 wxPrintf(_T("ERROR: got %s instead of %s\n"),
4882 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
4886 // test some minimal support for the dates outside the standard range
4887 static void TestTimeRange()
4889 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
4891 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
4893 wxPrintf(_T("Unix epoch:\t%s\n"),
4894 wxDateTime(2440587.5).Format(fmt
).c_str());
4895 wxPrintf(_T("Feb 29, 0: \t%s\n"),
4896 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
4897 wxPrintf(_T("JDN 0: \t%s\n"),
4898 wxDateTime(0.0).Format(fmt
).c_str());
4899 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
4900 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
4901 wxPrintf(_T("May 29, 2099:\t%s\n"),
4902 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
4905 static void TestTimeTicks()
4907 wxPuts(_T("\n*** wxDateTime ticks test ***"));
4909 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4911 const Date
& d
= testDates
[n
];
4912 if ( d
.ticks
== -1 )
4915 wxDateTime dt
= d
.DT();
4916 long ticks
= (dt
.GetValue() / 1000).ToLong();
4917 wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4918 if ( ticks
== d
.ticks
)
4920 wxPuts(_T(" (ok)"));
4924 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4925 (long)d
.ticks
, (long)(ticks
- d
.ticks
));
4928 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
4929 ticks
= (dt
.GetValue() / 1000).ToLong();
4930 wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4931 if ( ticks
== d
.gmticks
)
4933 wxPuts(_T(" (ok)"));
4937 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4938 (long)d
.gmticks
, (long)(ticks
- d
.gmticks
));
4945 // test conversions to JDN &c
4946 static void TestTimeJDN()
4948 wxPuts(_T("\n*** wxDateTime to JDN test ***"));
4950 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4952 const Date
& d
= testDates
[n
];
4953 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4954 double jdn
= dt
.GetJulianDayNumber();
4956 wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
);
4959 wxPuts(_T(" (ok)"));
4963 wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"),
4964 d
.jdn
, jdn
- d
.jdn
);
4969 // test week days computation
4970 static void TestTimeWDays()
4972 wxPuts(_T("\n*** wxDateTime weekday test ***"));
4974 // test GetWeekDay()
4976 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4978 const Date
& d
= testDates
[n
];
4979 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4981 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
4982 wxPrintf(_T("%s is: %s"),
4984 wxDateTime::GetWeekDayName(wday
).c_str());
4985 if ( wday
== d
.wday
)
4987 wxPuts(_T(" (ok)"));
4991 wxPrintf(_T(" (ERROR: should be %s)\n"),
4992 wxDateTime::GetWeekDayName(d
.wday
).c_str());
4998 // test SetToWeekDay()
4999 struct WeekDateTestData
5001 Date date
; // the real date (precomputed)
5002 int nWeek
; // its week index in the month
5003 wxDateTime::WeekDay wday
; // the weekday
5004 wxDateTime::Month month
; // the month
5005 int year
; // and the year
5007 wxString
Format() const
5010 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
5012 case 1: which
= _T("first"); break;
5013 case 2: which
= _T("second"); break;
5014 case 3: which
= _T("third"); break;
5015 case 4: which
= _T("fourth"); break;
5016 case 5: which
= _T("fifth"); break;
5018 case -1: which
= _T("last"); break;
5023 which
+= _T(" from end");
5026 s
.Printf(_T("The %s %s of %s in %d"),
5028 wxDateTime::GetWeekDayName(wday
).c_str(),
5029 wxDateTime::GetMonthName(month
).c_str(),
5036 // the array data was generated by the following python program
5038 from DateTime import *
5039 from whrandom import *
5040 from string import *
5042 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
5043 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
5045 week = DateTimeDelta(7)
5048 year = randint(1900, 2100)
5049 month = randint(1, 12)
5050 day = randint(1, 28)
5051 dt = DateTime(year, month, day)
5052 wday = dt.day_of_week
5054 countFromEnd = choice([-1, 1])
5057 while dt.month is month:
5058 dt = dt - countFromEnd * week
5059 weekNum = weekNum + countFromEnd
5061 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
5063 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
5064 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
5067 static const WeekDateTestData weekDatesTestData
[] =
5069 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
5070 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
5071 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
5072 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
5073 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
5074 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
5075 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
5076 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
5077 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
5078 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
5079 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
5080 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
5081 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
5082 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
5083 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
5084 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
5085 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
5086 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
5087 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
5088 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
5091 static const wxChar
*fmt
= _T("%d-%b-%Y");
5094 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
5096 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
5098 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
5100 wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str());
5102 const Date
& d
= wd
.date
;
5103 if ( d
.SameDay(dt
.GetTm()) )
5105 wxPuts(_T(" (ok)"));
5109 dt
.Set(d
.day
, d
.month
, d
.year
);
5111 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str());
5116 // test the computation of (ISO) week numbers
5117 static void TestTimeWNumber()
5119 wxPuts(_T("\n*** wxDateTime week number test ***"));
5121 struct WeekNumberTestData
5123 Date date
; // the date
5124 wxDateTime::wxDateTime_t week
; // the week number in the year
5125 wxDateTime::wxDateTime_t wmon
; // the week number in the month
5126 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
5127 wxDateTime::wxDateTime_t dnum
; // day number in the year
5130 // data generated with the following python script:
5132 from DateTime import *
5133 from whrandom import *
5134 from string import *
5136 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
5137 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
5139 def GetMonthWeek(dt):
5140 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
5141 if weekNumMonth < 0:
5142 weekNumMonth = weekNumMonth + 53
5145 def GetLastSundayBefore(dt):
5146 if dt.iso_week[2] == 7:
5149 return dt - DateTimeDelta(dt.iso_week[2])
5152 year = randint(1900, 2100)
5153 month = randint(1, 12)
5154 day = randint(1, 28)
5155 dt = DateTime(year, month, day)
5156 dayNum = dt.day_of_year
5157 weekNum = dt.iso_week[1]
5158 weekNumMonth = GetMonthWeek(dt)
5161 dtSunday = GetLastSundayBefore(dt)
5163 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
5164 weekNumMonth2 = weekNumMonth2 + 1
5165 dtSunday = dtSunday - DateTimeDelta(7)
5167 data = { 'day': rjust(`day`, 2), \
5168 'month': monthNames[month - 1], \
5170 'weekNum': rjust(`weekNum`, 2), \
5171 'weekNumMonth': weekNumMonth, \
5172 'weekNumMonth2': weekNumMonth2, \
5173 'dayNum': rjust(`dayNum`, 3) }
5175 print " { { %(day)s, "\
5176 "wxDateTime::%(month)s, "\
5179 "%(weekNumMonth)s, "\
5180 "%(weekNumMonth2)s, "\
5181 "%(dayNum)s }," % data
5184 static const WeekNumberTestData weekNumberTestDates
[] =
5186 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
5187 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
5188 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
5189 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
5190 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
5191 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
5192 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
5193 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
5194 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
5195 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
5196 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
5197 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
5198 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
5199 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
5200 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
5201 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
5202 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
5203 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
5204 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
5205 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
5208 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
5210 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
5211 const Date
& d
= wn
.date
;
5213 wxDateTime dt
= d
.DT();
5215 wxDateTime::wxDateTime_t
5216 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
5217 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
5218 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
5219 dnum
= dt
.GetDayOfYear();
5221 wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
);
5222 if ( dnum
== wn
.dnum
)
5224 wxPrintf(_T(" (ok)"));
5228 wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
);
5231 wxPrintf(_T(", week in month = %d"), wmon
);
5232 if ( wmon
!= wn
.wmon
)
5234 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
);
5237 wxPrintf(_T(" or %d"), wmon2
);
5238 if ( wmon2
== wn
.wmon2
)
5240 wxPrintf(_T(" (ok)"));
5244 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
);
5247 wxPrintf(_T(", week in year = %d"), week
);
5248 if ( week
!= wn
.week
)
5250 wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
);
5253 wxPutchar(_T('\n'));
5255 wxDateTime
dt2(1, wxDateTime::Jan
, d
.year
);
5256 dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay());
5260 d2
.Init(dt2
.GetTm());
5261 wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"),
5262 d2
.FormatDate().c_str());
5267 // test DST calculations
5268 static void TestTimeDST()
5270 wxPuts(_T("\n*** wxDateTime DST test ***"));
5272 wxPrintf(_T("DST is%s in effect now.\n\n"),
5273 wxDateTime::Now().IsDST() ? _T("") : _T(" not"));
5275 // taken from http://www.energy.ca.gov/daylightsaving.html
5276 static const Date datesDST
[2][2004 - 1900 + 1] =
5279 { 1, wxDateTime::Apr
, 1990 },
5280 { 7, wxDateTime::Apr
, 1991 },
5281 { 5, wxDateTime::Apr
, 1992 },
5282 { 4, wxDateTime::Apr
, 1993 },
5283 { 3, wxDateTime::Apr
, 1994 },
5284 { 2, wxDateTime::Apr
, 1995 },
5285 { 7, wxDateTime::Apr
, 1996 },
5286 { 6, wxDateTime::Apr
, 1997 },
5287 { 5, wxDateTime::Apr
, 1998 },
5288 { 4, wxDateTime::Apr
, 1999 },
5289 { 2, wxDateTime::Apr
, 2000 },
5290 { 1, wxDateTime::Apr
, 2001 },
5291 { 7, wxDateTime::Apr
, 2002 },
5292 { 6, wxDateTime::Apr
, 2003 },
5293 { 4, wxDateTime::Apr
, 2004 },
5296 { 28, wxDateTime::Oct
, 1990 },
5297 { 27, wxDateTime::Oct
, 1991 },
5298 { 25, wxDateTime::Oct
, 1992 },
5299 { 31, wxDateTime::Oct
, 1993 },
5300 { 30, wxDateTime::Oct
, 1994 },
5301 { 29, wxDateTime::Oct
, 1995 },
5302 { 27, wxDateTime::Oct
, 1996 },
5303 { 26, wxDateTime::Oct
, 1997 },
5304 { 25, wxDateTime::Oct
, 1998 },
5305 { 31, wxDateTime::Oct
, 1999 },
5306 { 29, wxDateTime::Oct
, 2000 },
5307 { 28, wxDateTime::Oct
, 2001 },
5308 { 27, wxDateTime::Oct
, 2002 },
5309 { 26, wxDateTime::Oct
, 2003 },
5310 { 31, wxDateTime::Oct
, 2004 },
5315 for ( year
= 1990; year
< 2005; year
++ )
5317 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
5318 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
5320 wxPrintf(_T("DST period in the US for year %d: from %s to %s"),
5321 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
5323 size_t n
= year
- 1990;
5324 const Date
& dBegin
= datesDST
[0][n
];
5325 const Date
& dEnd
= datesDST
[1][n
];
5327 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
5329 wxPuts(_T(" (ok)"));
5333 wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"),
5334 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
5335 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
5341 for ( year
= 1990; year
< 2005; year
++ )
5343 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
5345 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
5346 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
5350 // test wxDateTime -> text conversion
5351 static void TestTimeFormat()
5353 wxPuts(_T("\n*** wxDateTime formatting test ***"));
5355 // some information may be lost during conversion, so store what kind
5356 // of info should we recover after a round trip
5359 CompareNone
, // don't try comparing
5360 CompareBoth
, // dates and times should be identical
5361 CompareDate
, // dates only
5362 CompareTime
// time only
5367 CompareKind compareKind
;
5368 const wxChar
*format
;
5369 } formatTestFormats
[] =
5371 { CompareBoth
, _T("---> %c") },
5372 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
5373 { CompareBoth
, _T("Date is %x, time is %X") },
5374 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
5375 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
5376 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
5379 static const Date formatTestDates
[] =
5381 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
5382 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
5384 // this test can't work for other centuries because it uses two digit
5385 // years in formats, so don't even try it
5386 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
5387 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
5388 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
5392 // an extra test (as it doesn't depend on date, don't do it in the loop)
5393 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
5395 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
5399 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
5400 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
5402 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
5403 wxPrintf(_T("%s"), s
.c_str());
5405 // what can we recover?
5406 int kind
= formatTestFormats
[n
].compareKind
;
5410 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
5413 // converion failed - should it have?
5414 if ( kind
== CompareNone
)
5415 wxPuts(_T(" (ok)"));
5417 wxPuts(_T(" (ERROR: conversion back failed)"));
5421 // should have parsed the entire string
5422 wxPuts(_T(" (ERROR: conversion back stopped too soon)"));
5426 bool equal
= false; // suppress compilaer warning
5434 equal
= dt
.IsSameDate(dt2
);
5438 equal
= dt
.IsSameTime(dt2
);
5444 wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"),
5445 dt2
.Format().c_str(), dt
.Format().c_str());
5449 wxPuts(_T(" (ok)"));
5456 // test text -> wxDateTime conversion
5457 static void TestTimeParse()
5459 wxPuts(_T("\n*** wxDateTime parse test ***"));
5461 struct ParseTestData
5463 const wxChar
*format
;
5468 static const ParseTestData parseTestDates
[] =
5470 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
5471 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
5474 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
5476 const wxChar
*format
= parseTestDates
[n
].format
;
5478 wxPrintf(_T("%s => "), format
);
5481 if ( dt
.ParseRfc822Date(format
) )
5483 wxPrintf(_T("%s "), dt
.Format().c_str());
5485 if ( parseTestDates
[n
].good
)
5487 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
5494 wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str());
5499 wxPuts(_T("(ERROR: bad format)"));
5504 wxPrintf(_T("bad format (%s)\n"),
5505 parseTestDates
[n
].good
? "ERROR" : "ok");
5510 static void TestDateTimeInteractive()
5512 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
5518 wxPrintf(_T("Enter a date: "));
5519 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
5522 // kill the last '\n'
5523 buf
[wxStrlen(buf
) - 1] = 0;
5526 const wxChar
*p
= dt
.ParseDate(buf
);
5529 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
5535 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
5538 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
5539 dt
.Format(_T("%b %d, %Y")).c_str(),
5541 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
5542 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
5543 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
5546 wxPuts(_T("\n*** done ***"));
5549 static void TestTimeMS()
5551 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
5553 wxDateTime dt1
= wxDateTime::Now(),
5554 dt2
= wxDateTime::UNow();
5556 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
5557 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5558 wxPrintf(_T("Dummy loop: "));
5559 for ( int i
= 0; i
< 6000; i
++ )
5561 //for ( int j = 0; j < 10; j++ )
5564 s
.Printf(_T("%g"), sqrt(i
));
5570 wxPuts(_T(", done"));
5573 dt2
= wxDateTime::UNow();
5574 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5576 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
5578 wxPuts(_T("\n*** done ***"));
5581 static void TestTimeArithmetics()
5583 wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***"));
5585 static const struct ArithmData
5587 ArithmData(const wxDateSpan
& sp
, const wxChar
*nam
)
5588 : span(sp
), name(nam
) { }
5592 } testArithmData
[] =
5594 ArithmData(wxDateSpan::Day(), _T("day")),
5595 ArithmData(wxDateSpan::Week(), _T("week")),
5596 ArithmData(wxDateSpan::Month(), _T("month")),
5597 ArithmData(wxDateSpan::Year(), _T("year")),
5598 ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")),
5601 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
5603 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
5605 wxDateSpan span
= testArithmData
[n
].span
;
5609 const wxChar
*name
= testArithmData
[n
].name
;
5610 wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"),
5611 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
5612 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
5614 wxPrintf(_T("Going back: %s"), (dt1
- span
).FormatISODate().c_str());
5615 if ( dt1
- span
== dt
)
5617 wxPuts(_T(" (ok)"));
5621 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5624 wxPrintf(_T("Going forward: %s"), (dt2
+ span
).FormatISODate().c_str());
5625 if ( dt2
+ span
== dt
)
5627 wxPuts(_T(" (ok)"));
5631 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5634 wxPrintf(_T("Double increment: %s"), (dt2
+ 2*span
).FormatISODate().c_str());
5635 if ( dt2
+ 2*span
== dt1
)
5637 wxPuts(_T(" (ok)"));
5641 wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str());
5648 static void TestTimeHolidays()
5650 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
5652 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
5653 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
5654 dtEnd
= dtStart
.GetLastMonthDay();
5656 wxDateTimeArray hol
;
5657 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
5659 const wxChar
*format
= _T("%d-%b-%Y (%a)");
5661 wxPrintf(_T("All holidays between %s and %s:\n"),
5662 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
5664 size_t count
= hol
.GetCount();
5665 for ( size_t n
= 0; n
< count
; n
++ )
5667 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
5673 static void TestTimeZoneBug()
5675 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
5677 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
5678 for ( int i
= 0; i
< 31; i
++ )
5680 wxPrintf(_T("Date %s: week day %s.\n"),
5681 date
.Format(_T("%d-%m-%Y")).c_str(),
5682 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
5684 date
+= wxDateSpan::Day();
5690 static void TestTimeSpanFormat()
5692 wxPuts(_T("\n*** wxTimeSpan tests ***"));
5694 static const wxChar
*formats
[] =
5696 _T("(default) %H:%M:%S"),
5697 _T("%E weeks and %D days"),
5698 _T("%l milliseconds"),
5699 _T("(with ms) %H:%M:%S:%l"),
5700 _T("100%% of minutes is %M"), // test "%%"
5701 _T("%D days and %H hours"),
5702 _T("or also %S seconds"),
5705 wxTimeSpan
ts1(1, 2, 3, 4),
5707 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
5709 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
5710 ts1
.Format(formats
[n
]).c_str(),
5711 ts2
.Format(formats
[n
]).c_str());
5717 #endif // TEST_DATETIME
5719 // ----------------------------------------------------------------------------
5720 // wxTextInput/OutputStream
5721 // ----------------------------------------------------------------------------
5723 #ifdef TEST_TEXTSTREAM
5725 #include "wx/txtstrm.h"
5726 #include "wx/wfstream.h"
5728 static void TestTextInputStream()
5730 wxPuts(_T("\n*** wxTextInputStream test ***"));
5732 wxFileInputStream
fsIn(_T("testdata.fc"));
5735 wxPuts(_T("ERROR: couldn't open file."));
5739 wxTextInputStream
tis(fsIn
);
5744 const wxString s
= tis
.ReadLine();
5746 // line could be non empty if the last line of the file isn't
5747 // terminated with EOL
5748 if ( fsIn
.Eof() && s
.empty() )
5751 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
5756 #endif // TEST_TEXTSTREAM
5758 // ----------------------------------------------------------------------------
5760 // ----------------------------------------------------------------------------
5764 #include "wx/thread.h"
5766 static size_t gs_counter
= (size_t)-1;
5767 static wxCriticalSection gs_critsect
;
5768 static wxSemaphore gs_cond
;
5770 class MyJoinableThread
: public wxThread
5773 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
5774 { m_n
= n
; Create(); }
5776 // thread execution starts here
5777 virtual ExitCode
Entry();
5783 wxThread::ExitCode
MyJoinableThread::Entry()
5785 unsigned long res
= 1;
5786 for ( size_t n
= 1; n
< m_n
; n
++ )
5790 // it's a loooong calculation :-)
5794 return (ExitCode
)res
;
5797 class MyDetachedThread
: public wxThread
5800 MyDetachedThread(size_t n
, wxChar ch
)
5804 m_cancelled
= false;
5809 // thread execution starts here
5810 virtual ExitCode
Entry();
5813 virtual void OnExit();
5816 size_t m_n
; // number of characters to write
5817 wxChar m_ch
; // character to write
5819 bool m_cancelled
; // false if we exit normally
5822 wxThread::ExitCode
MyDetachedThread::Entry()
5825 wxCriticalSectionLocker
lock(gs_critsect
);
5826 if ( gs_counter
== (size_t)-1 )
5832 for ( size_t n
= 0; n
< m_n
; n
++ )
5834 if ( TestDestroy() )
5844 wxThread::Sleep(100);
5850 void MyDetachedThread::OnExit()
5852 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
5854 wxCriticalSectionLocker
lock(gs_critsect
);
5855 if ( !--gs_counter
&& !m_cancelled
)
5859 static void TestDetachedThreads()
5861 wxPuts(_T("\n*** Testing detached threads ***"));
5863 static const size_t nThreads
= 3;
5864 MyDetachedThread
*threads
[nThreads
];
5866 for ( n
= 0; n
< nThreads
; n
++ )
5868 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
5871 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
5872 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
5874 for ( n
= 0; n
< nThreads
; n
++ )
5879 // wait until all threads terminate
5885 static void TestJoinableThreads()
5887 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
5889 // calc 10! in the background
5890 MyJoinableThread
thread(10);
5893 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
5894 (unsigned long)thread
.Wait());
5897 static void TestThreadSuspend()
5899 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
5901 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
5905 // this is for this demo only, in a real life program we'd use another
5906 // condition variable which would be signaled from wxThread::Entry() to
5907 // tell us that the thread really started running - but here just wait a
5908 // bit and hope that it will be enough (the problem is, of course, that
5909 // the thread might still not run when we call Pause() which will result
5911 wxThread::Sleep(300);
5913 for ( size_t n
= 0; n
< 3; n
++ )
5917 wxPuts(_T("\nThread suspended"));
5920 // don't sleep but resume immediately the first time
5921 wxThread::Sleep(300);
5923 wxPuts(_T("Going to resume the thread"));
5928 wxPuts(_T("Waiting until it terminates now"));
5930 // wait until the thread terminates
5936 static void TestThreadDelete()
5938 // As above, using Sleep() is only for testing here - we must use some
5939 // synchronisation object instead to ensure that the thread is still
5940 // running when we delete it - deleting a detached thread which already
5941 // terminated will lead to a crash!
5943 wxPuts(_T("\n*** Testing thread delete function ***"));
5945 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
5949 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
5951 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
5955 wxThread::Sleep(300);
5959 wxPuts(_T("\nDeleted a running thread."));
5961 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
5965 wxThread::Sleep(300);
5971 wxPuts(_T("\nDeleted a sleeping thread."));
5973 MyJoinableThread
thread3(20);
5978 wxPuts(_T("\nDeleted a joinable thread."));
5980 MyJoinableThread
thread4(2);
5983 wxThread::Sleep(300);
5987 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
5992 class MyWaitingThread
: public wxThread
5995 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
5998 m_condition
= condition
;
6003 virtual ExitCode
Entry()
6005 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
6010 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
6014 m_condition
->Wait();
6017 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
6025 wxCondition
*m_condition
;
6028 static void TestThreadConditions()
6031 wxCondition
condition(mutex
);
6033 // otherwise its difficult to understand which log messages pertain to
6035 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
6036 // condition.GetId(), gs_cond.GetId());
6038 // create and launch threads
6039 MyWaitingThread
*threads
[10];
6042 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
6044 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
6047 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
6052 // wait until all threads run
6053 wxPuts(_T("Main thread is waiting for the other threads to start"));
6056 size_t nRunning
= 0;
6057 while ( nRunning
< WXSIZEOF(threads
) )
6063 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
6067 wxPuts(_T("Main thread: all threads started up."));
6070 wxThread::Sleep(500);
6073 // now wake one of them up
6074 wxPrintf(_T("Main thread: about to signal the condition.\n"));
6079 wxThread::Sleep(200);
6081 // wake all the (remaining) threads up, so that they can exit
6082 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
6084 condition
.Broadcast();
6086 // give them time to terminate (dirty!)
6087 wxThread::Sleep(500);
6090 #include "wx/utils.h"
6092 class MyExecThread
: public wxThread
6095 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
6101 virtual ExitCode
Entry()
6103 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
6110 static void TestThreadExec()
6112 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
6114 MyExecThread
thread(_T("true"));
6117 wxPrintf(_T("Main program exit code: %ld.\n"),
6118 wxExecute(_T("false"), wxEXEC_SYNC
));
6120 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
6124 #include "wx/datetime.h"
6126 class MySemaphoreThread
: public wxThread
6129 MySemaphoreThread(int i
, wxSemaphore
*sem
)
6130 : wxThread(wxTHREAD_JOINABLE
),
6137 virtual ExitCode
Entry()
6139 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
6140 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6144 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
6145 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6149 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
6150 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
6162 WX_DEFINE_ARRAY(wxThread
*, ArrayThreads
);
6164 static void TestSemaphore()
6166 wxPuts(_T("*** Testing wxSemaphore class. ***"));
6168 static const int SEM_LIMIT
= 3;
6170 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
6171 ArrayThreads threads
;
6173 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
6175 threads
.Add(new MySemaphoreThread(i
, &sem
));
6176 threads
.Last()->Run();
6179 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
6186 #endif // TEST_THREADS
6188 // ----------------------------------------------------------------------------
6190 // ----------------------------------------------------------------------------
6194 #include "wx/dynarray.h"
6196 typedef unsigned short ushort
;
6198 static int MyStringCompare(wxString
* s1
, wxString
* s2
)
6200 return wxStrcmp(s1
->c_str(), s2
->c_str());
6203 static int MyStringReverseCompare(wxString
* s1
, wxString
* s2
)
6205 return -wxStrcmp(s1
->c_str(), s2
->c_str());
6209 #define DefineCompare(name, T) \
6211 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
6213 return first - second; \
6216 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
6218 return *first - *second; \
6221 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
6223 return *second - *first; \
6226 DefineCompare(UShort, ushort);
6227 DefineCompare(Int
, int);
6229 // test compilation of all macros
6230 WX_DEFINE_ARRAY_SHORT(ushort
, wxArrayUShort
);
6231 WX_DEFINE_SORTED_ARRAY_SHORT(ushort
, wxSortedArrayUShortNoCmp
);
6232 WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort
, UShortCompareValues
, wxSortedArrayUShort
);
6233 WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues
, wxSortedArrayInt
);
6235 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
6236 #include "wx/arrimpl.cpp"
6237 WX_DEFINE_OBJARRAY(ArrayBars
);
6239 static void PrintArray(const wxChar
* name
, const wxArrayString
& array
)
6241 wxPrintf(_T("Dump of the array '%s'\n"), name
);
6243 size_t nCount
= array
.GetCount();
6244 for ( size_t n
= 0; n
< nCount
; n
++ )
6246 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
6250 static void PrintArray(const wxChar
* name
, const wxSortedArrayString
& array
)
6252 wxPrintf(_T("Dump of the array '%s'\n"), name
);
6254 size_t nCount
= array
.GetCount();
6255 for ( size_t n
= 0; n
< nCount
; n
++ )
6257 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
6261 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
6262 const wxString
& second
)
6264 return first
.length() - second
.length();
6267 #define TestArrayOf(name) \
6269 static void PrintArray(const wxChar* name, const wxSortedArray##name & array) \
6271 wxPrintf(_T("Dump of the array '%s'\n"), name); \
6273 size_t nCount = array.GetCount(); \
6274 for ( size_t n = 0; n < nCount; n++ ) \
6276 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
6280 static void PrintArray(const wxChar* name, const wxArray##name & array) \
6282 wxPrintf(_T("Dump of the array '%s'\n"), name); \
6284 size_t nCount = array.GetCount(); \
6285 for ( size_t n = 0; n < nCount; n++ ) \
6287 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
6291 static void TestArrayOf ## name ## s() \
6293 wxPrintf(_T("*** Testing wxArray%s ***\n"), #name); \
6301 wxPuts(_T("Initially:")); \
6302 PrintArray(_T("a"), a); \
6304 wxPuts(_T("After sort:")); \
6305 a.Sort(name ## Compare); \
6306 PrintArray(_T("a"), a); \
6308 wxPuts(_T("After reverse sort:")); \
6309 a.Sort(name ## RevCompare); \
6310 PrintArray(_T("a"), a); \
6312 wxSortedArray##name b; \
6318 wxPuts(_T("Sorted array initially:")); \
6319 PrintArray(_T("b"), b); \
6322 TestArrayOf(UShort
);
6325 static void TestStlArray()
6327 wxPuts(_T("*** Testing std::vector operations ***\n"));
6331 wxArrayInt::iterator it
, en
;
6332 wxArrayInt::reverse_iterator rit
, ren
;
6334 for ( i
= 0; i
< 5; ++i
)
6337 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
6338 it
!= en
; ++it
, ++i
)
6340 wxPuts(_T("Error in iterator\n"));
6342 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
6343 rit
!= ren
; ++rit
, --i
)
6345 wxPuts(_T("Error in reverse_iterator\n"));
6347 if ( *list1
.rbegin() != *(list1
.end()-1) ||
6348 *list1
.begin() != *(list1
.rend()-1) )
6349 wxPuts(_T("Error in iterator/reverse_iterator\n"));
6351 it
= list1
.begin()+1;
6352 rit
= list1
.rbegin()+1;
6353 if ( *list1
.begin() != *(it
-1) ||
6354 *list1
.rbegin() != *(rit
-1) )
6355 wxPuts(_T("Error in iterator/reverse_iterator\n"));
6357 if ( list1
.front() != 0 || list1
.back() != 4 )
6358 wxPuts(_T("Error in front()/back()\n"));
6360 list1
.erase(list1
.begin());
6361 list1
.erase(list1
.end()-1);
6363 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
6364 it
!= en
; ++it
, ++i
)
6366 wxPuts(_T("Error in erase()\n"));
6369 wxPuts(_T("*** Testing std::vector operations finished ***\n"));
6372 static void TestArrayOfObjects()
6374 wxPuts(_T("*** Testing wxObjArray ***\n"));
6378 Bar
bar(_T("second bar (two copies!)"));
6380 wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"),
6381 bars
.GetCount(), Bar::GetNumber());
6383 bars
.Add(new Bar(_T("first bar")));
6386 wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"),
6387 bars
.GetCount(), Bar::GetNumber());
6389 bars
.RemoveAt(1, bars
.GetCount() - 1);
6391 wxPrintf(_T("After removing all but first element: %u objects in the ")
6392 _T("array, %u objects total.\n"),
6393 bars
.GetCount(), Bar::GetNumber());
6397 wxPrintf(_T("After Empty(): %u objects in the array, %u objects total.\n"),
6398 bars
.GetCount(), Bar::GetNumber());
6401 wxPrintf(_T("Finally: no more objects in the array, %u objects total.\n"),
6405 #endif // TEST_ARRAYS
6407 // ----------------------------------------------------------------------------
6409 // ----------------------------------------------------------------------------
6413 #include "wx/timer.h"
6414 #include "wx/tokenzr.h"
6416 static void TestStringConstruction()
6418 wxPuts(_T("*** Testing wxString constructores ***"));
6420 #define TEST_CTOR(args, res) \
6423 wxPrintf(_T("wxString%s = %s "), #args, s.c_str()); \
6426 wxPuts(_T("(ok)")); \
6430 wxPrintf(_T("(ERROR: should be %s)\n"), res); \
6434 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
6435 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
6436 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
6437 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
6439 static const wxChar
*s
= _T("?really!");
6440 const wxChar
*start
= wxStrchr(s
, _T('r'));
6441 const wxChar
*end
= wxStrchr(s
, _T('!'));
6442 TEST_CTOR((start
, end
), _T("really"));
6447 static void TestString()
6457 for (int i
= 0; i
< 1000000; ++i
)
6461 c
= _T("! How'ya doin'?");
6464 c
= _T("Hello world! What's up?");
6469 wxPrintf(_T("TestString elapsed time: %ld\n"), sw
.Time());
6472 static void TestPChar()
6480 for (int i
= 0; i
< 1000000; ++i
)
6482 wxStrcpy (a
, _T("Hello"));
6483 wxStrcpy (b
, _T(" world"));
6484 wxStrcpy (c
, _T("! How'ya doin'?"));
6487 wxStrcpy (c
, _T("Hello world! What's up?"));
6488 if (wxStrcmp (c
, a
) == 0)
6489 wxStrcpy (c
, _T("Doh!"));
6492 wxPrintf(_T("TestPChar elapsed time: %ld\n"), sw
.Time());
6495 static void TestStringSub()
6497 wxString
s(_T("Hello, world!"));
6499 wxPuts(_T("*** Testing wxString substring extraction ***"));
6501 wxPrintf(_T("String = '%s'\n"), s
.c_str());
6502 wxPrintf(_T("Left(5) = '%s'\n"), s
.Left(5).c_str());
6503 wxPrintf(_T("Right(6) = '%s'\n"), s
.Right(6).c_str());
6504 wxPrintf(_T("Mid(3, 5) = '%s'\n"), s(3, 5).c_str());
6505 wxPrintf(_T("Mid(3) = '%s'\n"), s
.Mid(3).c_str());
6506 wxPrintf(_T("substr(3, 5) = '%s'\n"), s
.substr(3, 5).c_str());
6507 wxPrintf(_T("substr(3) = '%s'\n"), s
.substr(3).c_str());
6509 static const wxChar
*prefixes
[] =
6513 _T("Hello, world!"),
6514 _T("Hello, world!!!"),
6520 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
6522 wxString prefix
= prefixes
[n
], rest
;
6523 bool rc
= s
.StartsWith(prefix
, &rest
);
6524 wxPrintf(_T("StartsWith('%s') = %s"), prefix
.c_str(), rc
? _T("true") : _T("false"));
6527 wxPrintf(_T(" (the rest is '%s')\n"), rest
.c_str());
6538 static void TestStringFormat()
6540 wxPuts(_T("*** Testing wxString formatting ***"));
6543 s
.Printf(_T("%03d"), 18);
6545 wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str());
6546 wxPrintf(_T("Number 18: %s\n"), s
.c_str());
6551 // returns "not found" for npos, value for all others
6552 static wxString
PosToString(size_t res
)
6554 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
6555 : wxString::Format(_T("%u"), res
);
6559 static void TestStringFind()
6561 wxPuts(_T("*** Testing wxString find() functions ***"));
6563 static const wxChar
*strToFind
= _T("ell");
6564 static const struct StringFindTest
6568 result
; // of searching "ell" in str
6571 { _T("Well, hello world"), 0, 1 },
6572 { _T("Well, hello world"), 6, 7 },
6573 { _T("Well, hello world"), 9, wxString::npos
},
6576 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
6578 const StringFindTest
& ft
= findTestData
[n
];
6579 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
6581 wxPrintf(_T("Index of '%s' in '%s' starting from %u is %s "),
6582 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
6584 size_t resTrue
= ft
.result
;
6585 if ( res
== resTrue
)
6591 wxPrintf(_T("(ERROR: should be %s)\n"),
6592 PosToString(resTrue
).c_str());
6599 static void TestStringTokenizer()
6601 wxPuts(_T("*** Testing wxStringTokenizer ***"));
6603 static const wxChar
*modeNames
[] =
6607 _T("return all empty"),
6612 static const struct StringTokenizerTest
6614 const wxChar
*str
; // string to tokenize
6615 const wxChar
*delims
; // delimiters to use
6616 size_t count
; // count of token
6617 wxStringTokenizerMode mode
; // how should we tokenize it
6618 } tokenizerTestData
[] =
6620 { _T(""), _T(" "), 0 },
6621 { _T("Hello, world"), _T(" "), 2 },
6622 { _T("Hello, world "), _T(" "), 2 },
6623 { _T("Hello, world"), _T(","), 2 },
6624 { _T("Hello, world!"), _T(",!"), 2 },
6625 { _T("Hello,, world!"), _T(",!"), 3 },
6626 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
6627 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
6628 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
6629 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
6630 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
6631 { _T("01/02/99"), _T("/-"), 3 },
6632 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
6635 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
6637 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
6638 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
6640 size_t count
= tkz
.CountTokens();
6641 wxPrintf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
6642 MakePrintable(tt
.str
).c_str(),
6644 MakePrintable(tt
.delims
).c_str(),
6645 modeNames
[tkz
.GetMode()]);
6646 if ( count
== tt
.count
)
6652 wxPrintf(_T("(ERROR: should be %u)\n"), tt
.count
);
6657 // if we emulate strtok(), check that we do it correctly
6658 wxChar
*buf
, *s
= NULL
, *last
;
6660 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
6662 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
6663 wxStrcpy(buf
, tt
.str
);
6665 s
= wxStrtok(buf
, tt
.delims
, &last
);
6672 // now show the tokens themselves
6674 while ( tkz
.HasMoreTokens() )
6676 wxString token
= tkz
.GetNextToken();
6678 wxPrintf(_T("\ttoken %u: '%s'"),
6680 MakePrintable(token
).c_str());
6686 wxPuts(_T(" (ok)"));
6690 wxPrintf(_T(" (ERROR: should be %s)\n"), s
);
6693 s
= wxStrtok(NULL
, tt
.delims
, &last
);
6697 // nothing to compare with
6702 if ( count2
!= count
)
6704 wxPuts(_T("\tERROR: token count mismatch"));
6713 static void TestStringReplace()
6715 wxPuts(_T("*** Testing wxString::replace ***"));
6717 static const struct StringReplaceTestData
6719 const wxChar
*original
; // original test string
6720 size_t start
, len
; // the part to replace
6721 const wxChar
*replacement
; // the replacement string
6722 const wxChar
*result
; // and the expected result
6723 } stringReplaceTestData
[] =
6725 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
6726 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
6727 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
6728 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
6729 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
6732 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
6734 const StringReplaceTestData data
= stringReplaceTestData
[n
];
6736 wxString original
= data
.original
;
6737 original
.replace(data
.start
, data
.len
, data
.replacement
);
6739 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
6740 data
.original
, data
.start
, data
.len
, data
.replacement
,
6743 if ( original
== data
.result
)
6749 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
6756 static void TestStringMatch()
6758 wxPuts(_T("*** Testing wxString::Matches() ***"));
6760 static const struct StringMatchTestData
6763 const wxChar
*wildcard
;
6765 } stringMatchTestData
[] =
6767 { _T("foobar"), _T("foo*"), 1 },
6768 { _T("foobar"), _T("*oo*"), 1 },
6769 { _T("foobar"), _T("*bar"), 1 },
6770 { _T("foobar"), _T("??????"), 1 },
6771 { _T("foobar"), _T("f??b*"), 1 },
6772 { _T("foobar"), _T("f?b*"), 0 },
6773 { _T("foobar"), _T("*goo*"), 0 },
6774 { _T("foobar"), _T("*foo"), 0 },
6775 { _T("foobarfoo"), _T("*foo"), 1 },
6776 { _T(""), _T("*"), 1 },
6777 { _T(""), _T("?"), 0 },
6780 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
6782 const StringMatchTestData
& data
= stringMatchTestData
[n
];
6783 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
6784 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
6786 matches
? _T("matches") : _T("doesn't match"),
6788 matches
== data
.matches
? _T("ok") : _T("ERROR"));
6794 // Sigh, I want Test::Simple, Test::More and Test::Harness...
6795 void ok(int line
, bool ok
, const wxString
& msg
= wxEmptyString
)
6798 wxPuts(_T("NOT OK: (") + wxString::Format(_T("%d"), line
) +
6802 void is(int line
, const wxString
& got
, const wxString
& expected
,
6803 const wxString
& msg
= wxEmptyString
)
6805 bool isOk
= got
== expected
;
6806 ok(line
, isOk
, msg
);
6809 wxPuts(_T("Got: ") + got
);
6810 wxPuts(_T("Expected: ") + expected
);
6815 void is(int line
, const wxChar
* got
, const wxChar
* expected
,
6816 const wxString
& msg
= wxEmptyString
)
6818 bool isOk
= wxStrcmp( got
, expected
) == 0;
6819 ok(line
, isOk
, msg
);
6822 wxPuts(_T("Got: ") + wxString(got
));
6823 wxPuts(_T("Expected: ") + wxString(expected
));
6828 void is(int line
, const wxChar
& got
, const wxChar
& expected
,
6829 const wxString
& msg
= wxEmptyString
)
6831 bool isOk
= got
== expected
;
6832 ok(line
, isOk
, msg
);
6835 wxPuts(_T("Got: ") + got
);
6836 wxPuts(_T("Expected: ") + expected
);
6840 void is(int line
, size_t got
, size_t expected
,
6841 const wxString
& msg
= wxEmptyString
)
6843 bool isOk
= got
== expected
;
6844 ok(line
, isOk
, msg
);
6847 wxPuts(wxString::Format(_T("Got: %ld"), got
));
6848 wxPuts(wxString::Format(_T("Expected: %ld"), expected
));
6852 #define is_m( got, expected, message ) is( __LINE__, (got), (expected), (message) )
6853 #define is_nom( got, expected ) is( __LINE__, (got), (expected), wxEmptyString )
6855 void TestStdString()
6857 wxPuts(_T("*** Testing std::string operations ***\n"));
6860 wxString
s1(_T("abcdefgh")),
6861 s2(_T("abcdefghijklm"), 8),
6862 s3(_T("abcdefghijklm")),
6866 s7(s3
.begin(), s3
.begin() + 8);
6867 wxString
s8(s1
, 4, 8), s9
, s10
, s11
;
6869 is( __LINE__
, s1
, _T("abcdefgh") );
6870 is( __LINE__
, s2
, s1
);
6871 is( __LINE__
, s4
, _T("aaaaaaaa") );
6872 is( __LINE__
, s5
, _T("abcdefgh") );
6873 is( __LINE__
, s6
, s1
);
6874 is( __LINE__
, s7
, s1
);
6875 is( __LINE__
, s8
, _T("efgh") );
6878 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("abc");
6879 s1
.append(_T("def"));
6880 s2
.append(_T("defgh"), 3);
6881 s3
.append(wxString(_T("abcdef")), 3, 6);
6883 s5
.append(3, _T('a'));
6884 s6
.append(s1
.begin() + 3, s1
.end());
6886 is( __LINE__
, s1
, _T("abcdef") );
6887 is( __LINE__
, s2
, _T("abcdef") );
6888 is( __LINE__
, s3
, _T("abcdef") );
6889 is( __LINE__
, s4
, _T("abcabcdef") );
6890 is( __LINE__
, s5
, _T("abcaaa") );
6891 is( __LINE__
, s6
, _T("abcdef") );
6894 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("abc");
6895 s1
.assign(_T("def"));
6896 s2
.assign(_T("defgh"), 3);
6897 s3
.assign(wxString(_T("abcdef")), 3, 6);
6899 s5
.assign(3, _T('a'));
6900 s6
.assign(s1
.begin() + 1, s1
.end());
6902 is( __LINE__
, s1
, _T("def") );
6903 is( __LINE__
, s2
, _T("def") );
6904 is( __LINE__
, s3
, _T("def") );
6905 is( __LINE__
, s4
, _T("def") );
6906 is( __LINE__
, s5
, _T("aaa") );
6907 is( __LINE__
, s6
, _T("ef") );
6910 s1
= _T("abcdefgh");
6911 s2
= _T("abcdefgh");
6913 s4
= _T("abcdefghi");
6916 s7
= _T("zabcdefg");
6918 ok( __LINE__
, s1
.compare(s2
) == 0 );
6919 ok( __LINE__
, s1
.compare(s3
) > 0 );
6920 ok( __LINE__
, s1
.compare(s4
) < 0 );
6921 ok( __LINE__
, s1
.compare(s5
) > 0 );
6922 ok( __LINE__
, s1
.compare(s6
) < 0 );
6923 ok( __LINE__
, s1
.compare(1, 12, s1
) > 0);
6924 ok( __LINE__
, s1
.compare(_T("abcdefgh")) == 0);
6925 ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh")) == 0);
6926 ok( __LINE__
, s1
.compare(1, 7, _T("bcdefgh"), 7) == 0);
6931 wxString::iterator it
= s3
.erase(s3
.begin() + 1);
6932 wxString::iterator it2
= s4
.erase(s4
.begin() + 4, s4
.begin() + 6);
6933 wxString::iterator it3
= s7
.erase(s7
.begin() + 4, s7
.begin() + 8);
6935 is( __LINE__
, s1
, _T("acdefgh") );
6936 is( __LINE__
, s2
, _T("abcd") );
6937 is( __LINE__
, s3
, _T("ac") );
6938 is( __LINE__
, s4
, _T("abcdghi") );
6939 is( __LINE__
, s7
, _T("zabc") );
6940 is( __LINE__
, *it
, _T('c') );
6941 is( __LINE__
, *it2
, _T('g') );
6942 ok( __LINE__
, it3
== s7
.end() );
6946 // 01234567890123456789012345
6947 s1
= _T("abcdefgABCDEFGabcABCabcABC");
6950 is_nom( s1
.find(_T('A')), 7u );
6951 is_nom( s1
.find(_T('A'), 7), 7u );
6952 is_nom( s1
.find(_T('Z')), wxString::npos
);
6953 is_nom( s1
.find(_T('C'), 22), 25u );
6955 is_nom( s1
.find(_T("gAB")), 6u );
6956 is_nom( s1
.find(_T("gAB"), 7), wxString::npos
);
6957 is_nom( s1
.find(_T("gAB"), 6), 6u );
6959 is_nom( s1
.find(_T("gABZZZ"), 2, 3), 6u );
6960 is_nom( s1
.find(_T("gABZZZ"), 7, 3), wxString::npos
);
6962 is_nom( s1
.find(s2
), 6u );
6963 is_nom( s1
.find(s2
, 7), wxString::npos
);
6964 is_nom( s1
.find(s2
, 6), 6u );
6966 // find_first_not_of
6968 // 01234567890123456789012345678901234
6969 s1
= _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
6972 is_nom( s1
.find_first_not_of(_T('a')), 6u );
6973 is_nom( s1
.find_first_not_of(_T('a'), 7), 7u );
6974 is_nom( s2
.find_first_not_of(_T('a')), wxString::npos
);
6976 is_nom( s1
.find_first_not_of(_T("abde"), 4), 7u );
6977 is_nom( s1
.find_first_not_of(_T("abde"), 7), 7u );
6978 is_nom( s1
.find_first_not_of(_T("abcdefghijkl")), wxString::npos
);
6980 is_nom( s1
.find_first_not_of(_T("abcdefghi"), 0, 4), 9u );
6983 is_nom( s1
.find_first_of(_T('c')), 7u );
6984 is_nom( s1
.find_first_of(_T('v')), wxString::npos
);
6985 is_nom( s1
.find_first_of(_T('c'), 10), 24u );
6987 is_nom( s1
.find_first_of(_T("ijkl")), 13u );
6988 is_nom( s1
.find_first_of(_T("ddcfg"), 17), 24u );
6989 is_nom( s1
.find_first_of(_T("ddcfga"), 17, 5), 24u );
6993 // 01234567890123456789012345678901234
6994 s1
= _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
6997 is_nom( s2
.find_last_not_of(_T('a')), wxString::npos
);
6998 is_nom( s1
.find_last_not_of(_T('d')), 33u );
6999 is_nom( s1
.find_last_not_of(_T('d'), 25), 24u );
7001 is_nom( s1
.find_last_not_of(_T("bcd")), 22u );
7002 is_nom( s1
.find_last_not_of(_T("abc"), 24), 16u );
7004 is_nom( s1
.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3), 16u );
7007 is_nom( s2
.find_last_of(_T('c')), wxString::npos
);
7008 is_nom( s1
.find_last_of(_T('a')), 22u );
7009 is_nom( s1
.find_last_of(_T('b'), 24), 23u );
7011 is_nom( s1
.find_last_of(_T("ijklm")), 16u );
7012 is_nom( s1
.find_last_of(_T("ijklma"), 33, 4), 16u );
7013 is_nom( s1
.find_last_of(_T("a"), 17), 17u );
7016 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("aaaa");
7017 s9
= s10
= _T("cdefg");
7019 s1
.insert(1, _T("cc") );
7020 s2
.insert(2, _T("cdef"), 3);
7022 s4
.insert(2, s10
, 3, 7);
7023 s5
.insert(1, 2, _T('c'));
7024 it
= s6
.insert(s6
.begin() + 3, _T('X'));
7025 s7
.insert(s7
.begin(), s9
.begin(), s9
.end() - 1);
7026 s8
.insert(s8
.begin(), 2, _T('c'));
7028 is( __LINE__
, s1
, _T("accaaa") );
7029 is( __LINE__
, s2
, _T("aacdeaa") );
7030 is( __LINE__
, s3
, _T("aacdefgaa") );
7031 is( __LINE__
, s4
, _T("aafgaa") );
7032 is( __LINE__
, s5
, _T("accaaa") );
7033 is( __LINE__
, s6
, _T("aaaXa") );
7034 is( __LINE__
, s7
, _T("cdefaaaa") );
7035 is( __LINE__
, s8
, _T("ccaaaa") );
7037 s1
= s2
= s3
= _T("aaaa");
7038 s1
.insert(0, _T("ccc"), 2);
7039 s2
.insert(4, _T("ccc"), 2);
7041 is( __LINE__
, s1
, _T("ccaaaa") );
7042 is( __LINE__
, s2
, _T("aaaacc") );
7045 s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= _T("QWERTYUIOP");
7046 s9
= s10
= _T("werty");
7048 s1
.replace(3, 4, _T("rtyu"));
7049 s1
.replace(8, 7, _T("opopop"));
7050 s2
.replace(10, 12, _T("WWWW"));
7051 s3
.replace(1, 5, s9
);
7052 s4
.replace(1, 4, s9
, 0, 4);
7053 s5
.replace(1, 2, s9
, 1, 12);
7054 s6
.replace(0, 123, s9
, 0, 123);
7055 s7
.replace(2, 7, s9
);
7057 is( __LINE__
, s1
, _T("QWErtyuIopopop") );
7058 is( __LINE__
, s2
, _T("QWERTYUIOPWWWW") );
7059 is( __LINE__
, s3
, _T("QwertyUIOP") );
7060 is( __LINE__
, s4
, _T("QwertYUIOP") );
7061 is( __LINE__
, s5
, _T("QertyRTYUIOP") );
7062 is( __LINE__
, s6
, s9
);
7063 is( __LINE__
, s7
, _T("QWwertyP") );
7067 // 01234567890123456789012345
7068 s1
= _T("abcdefgABCDEFGabcABCabcABC");
7072 is_nom( s1
.rfind(_T('A')), 23u );
7073 is_nom( s1
.rfind(_T('A'), 7), 7u );
7074 is_nom( s1
.rfind(_T('Z')), wxString::npos
);
7075 is_nom( s1
.rfind(_T('C'), 22), 19u );
7077 is_nom( s1
.rfind(_T("cAB")), 22u );
7078 is_nom( s1
.rfind(_T("cAB"), 15), wxString::npos
);
7079 is_nom( s1
.rfind(_T("cAB"), 21), 16u );
7081 is_nom( s1
.rfind(_T("gABZZZ"), 7, 3), 6u );
7082 is_nom( s1
.rfind(_T("gABZZZ"), 5, 3), wxString::npos
);
7084 is_nom( s1
.rfind(s2
), 6u );
7085 is_nom( s1
.rfind(s2
, 5), wxString::npos
);
7086 is_nom( s1
.rfind(s2
, 6), 6u );
7087 is_nom( s1
.rfind(s3
, 1), 0u );
7090 s1
= s2
= s3
= s4
= _T("abcABCdefDEF");
7094 s3
.resize( 14, _T(' ') );
7095 s4
.resize( 14, _T('W') );
7097 is_nom( s1
, _T("abcABCdefDEF") );
7098 is_nom( s2
, _T("abcABCdefD") );
7099 is_nom( s3
, _T("abcABCdefDEF ") );
7100 is_nom( s4
, _T("abcABCdefDEFWW") );
7103 s1
= _T("abcdefgABCDEFG");
7105 is_nom( s1
.substr( 0, 14 ), s1
);
7106 is_nom( s1
.substr( 1, 13 ), _T("bcdefgABCDEFG") );
7107 is_nom( s1
.substr( 1, 20 ), _T("bcdefgABCDEFG") );
7108 is_nom( s1
.substr( 14, 30 ), _T("") );
7110 wxPuts(_T("*** Testing std::string operations finished ***\n"));
7113 #endif // TEST_STRINGS
7115 // ----------------------------------------------------------------------------
7117 // ----------------------------------------------------------------------------
7119 #ifdef TEST_SNGLINST
7120 #include "wx/snglinst.h"
7121 #endif // TEST_SNGLINST
7123 int main(int argc
, char **argv
)
7125 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
7127 wxInitializer initializer
;
7130 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
7135 #ifdef TEST_SNGLINST
7136 wxSingleInstanceChecker checker
;
7137 if ( checker
.Create(_T(".wxconsole.lock")) )
7139 if ( checker
.IsAnotherRunning() )
7141 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
7146 // wait some time to give time to launch another instance
7147 wxPrintf(_T("Press \"Enter\" to continue..."));
7150 else // failed to create
7152 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
7154 #endif // TEST_SNGLINST
7158 #endif // TEST_CHARSET
7161 TestCmdLineConvert();
7163 #if wxUSE_CMDLINE_PARSER
7164 static const wxCmdLineEntryDesc cmdLineDesc
[] =
7166 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"),
7167 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
7168 { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") },
7169 { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"), _T("be quiet") },
7171 { wxCMD_LINE_OPTION
, _T("o"), _T("output"), _T("output file") },
7172 { wxCMD_LINE_OPTION
, _T("i"), _T("input"), _T("input dir") },
7173 { wxCMD_LINE_OPTION
, _T("s"), _T("size"), _T("output block size"),
7174 wxCMD_LINE_VAL_NUMBER
},
7175 { wxCMD_LINE_OPTION
, _T("d"), _T("date"), _T("output file date"),
7176 wxCMD_LINE_VAL_DATE
},
7178 { wxCMD_LINE_PARAM
, NULL
, NULL
, _T("input file"),
7179 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
7185 wxChar
**wargv
= new wxChar
*[argc
+ 1];
7190 for (n
= 0; n
< argc
; n
++ )
7192 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
7193 wargv
[n
] = wxStrdup(warg
);
7200 #endif // wxUSE_UNICODE
7202 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
7206 for ( int n
= 0; n
< argc
; n
++ )
7211 #endif // wxUSE_UNICODE
7213 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
7214 wxCMD_LINE_VAL_STRING
,
7215 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
7217 switch ( parser
.Parse() )
7220 wxLogMessage(_T("Help was given, terminating."));
7224 ShowCmdLine(parser
);
7228 wxLogMessage(_T("Syntax error detected, aborting."));
7231 #endif // wxUSE_CMDLINE_PARSER
7233 #endif // TEST_CMDLINE
7241 TestStringConstruction();
7244 TestStringTokenizer();
7245 TestStringReplace();
7253 #endif // TEST_STRINGS
7256 if ( 1 || TEST_ALL
)
7259 a1
.Add(_T("tiger"));
7261 a1
.Add(_T("lion"), 3);
7263 a1
.Add(_T("human"));
7266 wxPuts(_T("*** Initially:"));
7268 PrintArray(_T("a1"), a1
);
7270 wxArrayString
a2(a1
);
7271 PrintArray(_T("a2"), a2
);
7274 wxSortedArrayString
a3(a1
);
7276 wxSortedArrayString a3
;
7277 for (wxArrayString::iterator it
= a1
.begin(), en
= a1
.end();
7281 PrintArray(_T("a3"), a3
);
7283 wxPuts(_T("*** After deleting three strings from a1"));
7286 PrintArray(_T("a1"), a1
);
7287 PrintArray(_T("a2"), a2
);
7288 PrintArray(_T("a3"), a3
);
7291 wxPuts(_T("*** After reassigning a1 to a2 and a3"));
7293 PrintArray(_T("a2"), a2
);
7294 PrintArray(_T("a3"), a3
);
7297 wxPuts(_T("*** After sorting a1"));
7299 PrintArray(_T("a1"), a1
);
7301 wxPuts(_T("*** After sorting a1 in reverse order"));
7303 PrintArray(_T("a1"), a1
);
7306 wxPuts(_T("*** After sorting a1 by the string length"));
7307 a1
.Sort(&StringLenCompare
);
7308 PrintArray(_T("a1"), a1
);
7311 TestArrayOfObjects();
7312 TestArrayOfUShorts();
7317 #endif // TEST_ARRAYS
7328 #ifdef TEST_DLLLOADER
7330 #endif // TEST_DLLLOADER
7334 #endif // TEST_ENVIRON
7338 #endif // TEST_EXECUTE
7340 #ifdef TEST_FILECONF
7342 #endif // TEST_FILECONF
7351 #endif // TEST_LOCALE
7354 wxPuts(_T("*** Testing wxLog ***"));
7357 for ( size_t n
= 0; n
< 8000; n
++ )
7359 s
<< (wxChar
)(_T('A') + (n
% 26));
7362 wxLogWarning(_T("The length of the string is %lu"),
7363 (unsigned long)s
.length());
7366 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
7368 // this one shouldn't be truncated
7371 // but this one will because log functions use fixed size buffer
7372 // (note that it doesn't need '\n' at the end neither - will be added
7374 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
7386 #ifdef TEST_FILENAME
7389 TestFileNameConstruction();
7390 TestFileNameMakeRelative();
7391 TestFileNameMakeAbsolute();
7392 TestFileNameSplit();
7395 TestFileNameDirManip();
7396 TestFileNameComparison();
7397 TestFileNameOperations();
7399 #endif // TEST_FILENAME
7401 #ifdef TEST_FILETIME
7405 #endif // TEST_FILETIME
7408 wxLog::AddTraceMask(FTP_TRACE_MASK
);
7409 if ( TestFtpConnect() )
7420 if ( TEST_INTERACTIVE
)
7421 TestFtpInteractive();
7423 //else: connecting to the FTP server failed
7429 #ifdef TEST_LONGLONG
7430 // seed pseudo random generator
7431 srand((unsigned)time(NULL
));
7440 TestMultiplication();
7443 TestLongLongConversion();
7444 TestBitOperations();
7445 TestLongLongComparison();
7446 TestLongLongToString();
7447 TestLongLongPrintf();
7449 #endif // TEST_LONGLONG
7457 #endif // TEST_HASHMAP
7461 #endif // TEST_HASHSET
7464 wxLog::AddTraceMask(_T("mime"));
7469 TestMimeAssociate();
7474 #ifdef TEST_INFO_FUNCTIONS
7480 if ( TEST_INTERACTIVE
)
7483 #endif // TEST_INFO_FUNCTIONS
7485 #ifdef TEST_PATHLIST
7487 #endif // TEST_PATHLIST
7495 #endif // TEST_PRINTF
7498 //TestRegConfWrite();
7500 #endif // TEST_REGCONF
7503 // TODO: write a real test using src/regex/tests file
7508 TestRegExSubmatch();
7509 TestRegExReplacement();
7511 if ( TEST_INTERACTIVE
)
7512 TestRegExInteractive();
7514 #endif // TEST_REGEX
7516 #ifdef TEST_REGISTRY
7518 TestRegistryAssociation();
7519 #endif // TEST_REGISTRY
7524 #endif // TEST_SOCKETS
7532 #endif // TEST_STREAMS
7534 #ifdef TEST_TEXTSTREAM
7535 TestTextInputStream();
7536 #endif // TEST_TEXTSTREAM
7539 int nCPUs
= wxThread::GetCPUCount();
7540 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
7542 wxThread::SetConcurrency(nCPUs
);
7544 TestJoinableThreads();
7548 TestJoinableThreads();
7549 TestDetachedThreads();
7550 TestThreadSuspend();
7552 TestThreadConditions();
7556 #endif // TEST_THREADS
7560 #endif // TEST_TIMER
7562 #ifdef TEST_DATETIME
7575 TestTimeArithmetics();
7578 TestTimeSpanFormat();
7584 if ( TEST_INTERACTIVE
)
7585 TestDateTimeInteractive();
7586 #endif // TEST_DATETIME
7588 #ifdef TEST_SCOPEGUARD
7593 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
7595 #endif // TEST_USLEEP
7600 #endif // TEST_VCARD
7604 #endif // TEST_VOLUME
7607 TestUnicodeTextFileRead();
7610 TestUnicodeToFromAscii();
7612 #endif // TEST_UNICODE
7616 TestEncodingConverter();
7617 #endif // TEST_WCHAR
7620 TestZipStreamRead();
7621 TestZipFileSystem();
7625 TestZlibStreamWrite();
7626 TestZlibStreamRead();