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)? Define TEST_ALL to 0 to do a single
48 // test, define it to 1 to do all tests.
58 #define TEST_DLLLOADER
65 // #define TEST_FTP --FIXME! (RN)
69 #define TEST_INFO_FUNCTIONS
80 #define TEST_SCOPEGUARD
82 // #define TEST_SOCKETS --FIXME! (RN)
84 #define TEST_TEXTSTREAM
87 // #define TEST_VCARD -- don't enable this (VZ)
88 // #define TEST_VOLUME --FIXME! (RN)
98 // some tests are interactive, define this to run them
99 #ifdef TEST_INTERACTIVE
100 #undef TEST_INTERACTIVE
102 #define TEST_INTERACTIVE 1
104 #define TEST_INTERACTIVE 0
107 // ----------------------------------------------------------------------------
108 // test class for container objects
109 // ----------------------------------------------------------------------------
111 #if defined(TEST_LIST)
113 class Bar
// Foo is already taken in the hash test
116 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
117 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
118 ~Bar() { ms_bars
--; }
120 static size_t GetNumber() { return ms_bars
; }
122 const wxChar
*GetName() const { return m_name
; }
127 static size_t ms_bars
;
130 size_t Bar::ms_bars
= 0;
132 #endif // defined(TEST_LIST)
134 // ============================================================================
136 // ============================================================================
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 #if defined(TEST_SOCKETS)
144 // replace TABs with \t and CRs with \n
145 static wxString
MakePrintable(const wxChar
*s
)
148 (void)str
.Replace(_T("\t"), _T("\\t"));
149 (void)str
.Replace(_T("\n"), _T("\\n"));
150 (void)str
.Replace(_T("\r"), _T("\\r"));
155 #endif // MakePrintable() is used
157 // ----------------------------------------------------------------------------
158 // wxFontMapper::CharsetToEncoding
159 // ----------------------------------------------------------------------------
163 #include "wx/fontmap.h"
165 static void TestCharset()
167 static const wxChar
*charsets
[] =
169 // some vali charsets
178 // and now some bogus ones
185 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
187 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]);
188 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
190 wxFontMapper::Get()->GetEncodingName(enc
).c_str(),
191 wxFontMapper::Get()->GetEncodingDescription(enc
).c_str());
195 #endif // TEST_CHARSET
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
203 #include "wx/cmdline.h"
204 #include "wx/datetime.h"
206 #if wxUSE_CMDLINE_PARSER
208 static void ShowCmdLine(const wxCmdLineParser
& parser
)
210 wxString s
= _T("Input files: ");
212 size_t count
= parser
.GetParamCount();
213 for ( size_t param
= 0; param
< count
; param
++ )
215 s
<< parser
.GetParam(param
) << ' ';
219 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
220 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
225 if ( parser
.Found(_T("o"), &strVal
) )
226 s
<< _T("Output file:\t") << strVal
<< '\n';
227 if ( parser
.Found(_T("i"), &strVal
) )
228 s
<< _T("Input dir:\t") << strVal
<< '\n';
229 if ( parser
.Found(_T("s"), &lVal
) )
230 s
<< _T("Size:\t") << lVal
<< '\n';
231 if ( parser
.Found(_T("d"), &dt
) )
232 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
233 if ( parser
.Found(_T("project_name"), &strVal
) )
234 s
<< _T("Project:\t") << strVal
<< '\n';
239 #endif // wxUSE_CMDLINE_PARSER
241 static void TestCmdLineConvert()
243 static const wxChar
*cmdlines
[] =
246 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
247 _T("literal \\\" and \"\""),
250 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
252 const wxChar
*cmdline
= cmdlines
[n
];
253 wxPrintf(_T("Parsing: %s\n"), cmdline
);
254 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
256 size_t count
= args
.GetCount();
257 wxPrintf(_T("\targc = %u\n"), count
);
258 for ( size_t arg
= 0; arg
< count
; arg
++ )
260 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
265 #endif // TEST_CMDLINE
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
276 static const wxChar
*ROOTDIR
= _T("/");
277 static const wxChar
*TESTDIR
= _T("/usr/local/share");
278 #elif defined(__WXMSW__)
279 static const wxChar
*ROOTDIR
= _T("c:\\");
280 static const wxChar
*TESTDIR
= _T("d:\\");
282 #error "don't know where the root directory is"
285 static void TestDirEnumHelper(wxDir
& dir
,
286 int flags
= wxDIR_DEFAULT
,
287 const wxString
& filespec
= wxEmptyString
)
291 if ( !dir
.IsOpened() )
294 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
297 wxPrintf(_T("\t%s\n"), filename
.c_str());
299 cont
= dir
.GetNext(&filename
);
302 wxPuts(wxEmptyString
);
305 static void TestDirEnum()
307 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
309 wxString cwd
= wxGetCwd();
310 if ( !wxDir::Exists(cwd
) )
312 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
317 if ( !dir
.IsOpened() )
319 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
323 wxPuts(_T("Enumerating everything in current directory:"));
324 TestDirEnumHelper(dir
);
326 wxPuts(_T("Enumerating really everything in current directory:"));
327 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
329 wxPuts(_T("Enumerating object files in current directory:"));
330 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
332 wxPuts(_T("Enumerating directories in current directory:"));
333 TestDirEnumHelper(dir
, wxDIR_DIRS
);
335 wxPuts(_T("Enumerating files in current directory:"));
336 TestDirEnumHelper(dir
, wxDIR_FILES
);
338 wxPuts(_T("Enumerating files including hidden in current directory:"));
339 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
343 wxPuts(_T("Enumerating everything in root directory:"));
344 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
346 wxPuts(_T("Enumerating directories in root directory:"));
347 TestDirEnumHelper(dir
, wxDIR_DIRS
);
349 wxPuts(_T("Enumerating files in root directory:"));
350 TestDirEnumHelper(dir
, wxDIR_FILES
);
352 wxPuts(_T("Enumerating files including hidden in root directory:"));
353 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
355 wxPuts(_T("Enumerating files in non existing directory:"));
356 wxDir
dirNo(_T("nosuchdir"));
357 TestDirEnumHelper(dirNo
);
360 class DirPrintTraverser
: public wxDirTraverser
363 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
365 return wxDIR_CONTINUE
;
368 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
370 wxString path
, name
, ext
;
371 wxSplitPath(dirname
, &path
, &name
, &ext
);
374 name
<< _T('.') << ext
;
377 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
379 if ( wxIsPathSeparator(*p
) )
383 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
385 return wxDIR_CONTINUE
;
389 static void TestDirTraverse()
391 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
395 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
396 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
399 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
400 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
403 // enum again with custom traverser
404 wxPuts(_T("Now enumerating directories:"));
406 DirPrintTraverser traverser
;
407 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
410 static void TestDirExists()
412 wxPuts(_T("*** Testing wxDir::Exists() ***"));
414 static const wxChar
*dirnames
[] =
417 #if defined(__WXMSW__)
420 _T("\\\\share\\file"),
424 _T("c:\\autoexec.bat"),
425 #elif defined(__UNIX__)
434 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
436 wxPrintf(_T("%-40s: %s\n"),
438 wxDir::Exists(dirnames
[n
]) ? _T("exists")
439 : _T("doesn't exist"));
445 // ----------------------------------------------------------------------------
447 // ----------------------------------------------------------------------------
449 #ifdef TEST_DLLLOADER
451 #include "wx/dynlib.h"
453 static void TestDllLoad()
455 #if defined(__WXMSW__)
456 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
457 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
458 #elif defined(__UNIX__)
459 // weird: using just libc.so does *not* work!
460 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
461 static const wxChar
*FUNC_NAME
= _T("strlen");
463 #error "don't know how to test wxDllLoader on this platform"
466 wxPuts(_T("*** testing wxDllLoader ***\n"));
468 wxDynamicLibrary
lib(LIB_NAME
);
469 if ( !lib
.IsLoaded() )
471 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
475 typedef int (*wxStrlenType
)(const char *);
476 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
479 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
480 FUNC_NAME
, LIB_NAME
);
484 if ( pfnStrlen("foo") != 3 )
486 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
490 wxPuts(_T("... ok"));
496 #endif // TEST_DLLLOADER
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
504 #include "wx/utils.h"
506 static wxString
MyGetEnv(const wxString
& var
)
509 if ( !wxGetEnv(var
, &val
) )
512 val
= wxString(_T('\'')) + val
+ _T('\'');
517 static void TestEnvironment()
519 const wxChar
*var
= _T("wxTestVar");
521 wxPuts(_T("*** testing environment access functions ***"));
523 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
524 wxSetEnv(var
, _T("value for wxTestVar"));
525 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
526 wxSetEnv(var
, _T("another value"));
527 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
529 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
530 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
533 #endif // TEST_ENVIRON
535 // ----------------------------------------------------------------------------
537 // ----------------------------------------------------------------------------
541 #include "wx/utils.h"
543 static void TestExecute()
545 wxPuts(_T("*** testing wxExecute ***"));
548 #define COMMAND "cat -n ../../Makefile" // "echo hi"
549 #define SHELL_COMMAND "echo hi from shell"
550 #define REDIRECT_COMMAND COMMAND // "date"
551 #elif defined(__WXMSW__)
552 #define COMMAND "command.com /c echo hi"
553 #define SHELL_COMMAND "echo hi"
554 #define REDIRECT_COMMAND COMMAND
556 #error "no command to exec"
559 wxPrintf(_T("Testing wxShell: "));
561 if ( wxShell(_T(SHELL_COMMAND
)) )
564 wxPuts(_T("ERROR."));
566 wxPrintf(_T("Testing wxExecute: "));
568 if ( wxExecute(_T(COMMAND
), true /* sync */) == 0 )
571 wxPuts(_T("ERROR."));
573 #if 0 // no, it doesn't work (yet?)
574 wxPrintf(_T("Testing async wxExecute: "));
576 if ( wxExecute(COMMAND
) != 0 )
577 wxPuts(_T("Ok (command launched)."));
579 wxPuts(_T("ERROR."));
582 wxPrintf(_T("Testing wxExecute with redirection:\n"));
583 wxArrayString output
;
584 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
586 wxPuts(_T("ERROR."));
590 size_t count
= output
.GetCount();
591 for ( size_t n
= 0; n
< count
; n
++ )
593 wxPrintf(_T("\t%s\n"), output
[n
].c_str());
600 #endif // TEST_EXECUTE
602 // ----------------------------------------------------------------------------
604 // ----------------------------------------------------------------------------
609 #include "wx/ffile.h"
610 #include "wx/textfile.h"
612 static void TestFileRead()
614 wxPuts(_T("*** wxFile read test ***"));
616 wxFile
file(_T("testdata.fc"));
617 if ( file
.IsOpened() )
619 wxPrintf(_T("File length: %lu\n"), file
.Length());
621 wxPuts(_T("File dump:\n----------"));
623 static const off_t len
= 1024;
627 off_t nRead
= file
.Read(buf
, len
);
628 if ( nRead
== wxInvalidOffset
)
630 wxPrintf(_T("Failed to read the file."));
634 fwrite(buf
, nRead
, 1, stdout
);
640 wxPuts(_T("----------"));
644 wxPrintf(_T("ERROR: can't open test file.\n"));
647 wxPuts(wxEmptyString
);
650 static void TestTextFileRead()
652 wxPuts(_T("*** wxTextFile read test ***"));
654 wxTextFile
file(_T("testdata.fc"));
657 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
658 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
662 wxPuts(_T("\nDumping the entire file:"));
663 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
665 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
667 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
669 wxPuts(_T("\nAnd now backwards:"));
670 for ( s
= file
.GetLastLine();
671 file
.GetCurrentLine() != 0;
672 s
= file
.GetPrevLine() )
674 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
676 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
680 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
683 wxPuts(wxEmptyString
);
686 static void TestFileCopy()
688 wxPuts(_T("*** Testing wxCopyFile ***"));
690 static const wxChar
*filename1
= _T("testdata.fc");
691 static const wxChar
*filename2
= _T("test2");
692 if ( !wxCopyFile(filename1
, filename2
) )
694 wxPuts(_T("ERROR: failed to copy file"));
698 wxFFile
f1(filename1
, _T("rb")),
699 f2(filename2
, _T("rb"));
701 if ( !f1
.IsOpened() || !f2
.IsOpened() )
703 wxPuts(_T("ERROR: failed to open file(s)"));
708 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
710 wxPuts(_T("ERROR: failed to read file(s)"));
714 if ( (s1
.length() != s2
.length()) ||
715 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
717 wxPuts(_T("ERROR: copy error!"));
721 wxPuts(_T("File was copied ok."));
727 if ( !wxRemoveFile(filename2
) )
729 wxPuts(_T("ERROR: failed to remove the file"));
732 wxPuts(wxEmptyString
);
737 // ----------------------------------------------------------------------------
739 // ----------------------------------------------------------------------------
743 #include "wx/confbase.h"
744 #include "wx/fileconf.h"
746 static const struct FileConfTestData
748 const wxChar
*name
; // value name
749 const wxChar
*value
; // the value from the file
752 { _T("value1"), _T("one") },
753 { _T("value2"), _T("two") },
754 { _T("novalue"), _T("default") },
757 static void TestFileConfRead()
759 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
761 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
762 _T("testdata.fc"), wxEmptyString
,
763 wxCONFIG_USE_RELATIVE_PATH
);
765 // test simple reading
766 wxPuts(_T("\nReading config file:"));
767 wxString
defValue(_T("default")), value
;
768 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
770 const FileConfTestData
& data
= fcTestData
[n
];
771 value
= fileconf
.Read(data
.name
, defValue
);
772 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
773 if ( value
== data
.value
)
779 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
783 // test enumerating the entries
784 wxPuts(_T("\nEnumerating all root entries:"));
787 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
790 wxPrintf(_T("\t%s = %s\n"),
792 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
794 cont
= fileconf
.GetNextEntry(name
, dummy
);
797 static const wxChar
*testEntry
= _T("TestEntry");
798 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
799 fileconf
.Write(testEntry
, _T("A value"));
800 fileconf
.DeleteEntry(testEntry
);
801 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
804 #endif // TEST_FILECONF
806 // ----------------------------------------------------------------------------
808 // ----------------------------------------------------------------------------
812 #include "wx/filename.h"
815 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
819 wxString full
= fn
.GetFullPath();
821 wxString vol
, path
, name
, ext
;
822 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
824 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
825 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
827 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
828 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
829 path
.c_str(), name
.c_str(), ext
.c_str());
831 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
832 wxPrintf(_T("with volume: \t'%s'\n"),
833 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
834 wxPrintf(_T("with separator:\t'%s'\n"),
835 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
836 wxPrintf(_T("with both: \t'%s'\n"),
837 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
839 wxPuts(_T("The directories in the path are:"));
840 wxArrayString dirs
= fn
.GetDirs();
841 size_t count
= dirs
.GetCount();
842 for ( size_t n
= 0; n
< count
; n
++ )
844 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
849 static struct FileNameInfo
851 const wxChar
*fullname
;
852 const wxChar
*volume
;
861 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX
},
862 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX
},
863 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX
},
864 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX
},
865 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
866 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX
},
867 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX
},
868 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
869 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX
},
871 // Windows file names
872 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
873 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS
},
874 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
875 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
876 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS
},
877 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
878 { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
880 // wxFileName support for Mac file names is broken currently
883 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC
},
884 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC
},
885 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC
},
886 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC
},
887 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
888 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
892 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS
},
893 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS
},
896 static void TestFileNameConstruction()
898 wxPuts(_T("*** testing wxFileName construction ***"));
900 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
902 const FileNameInfo
& fni
= filenames
[n
];
904 wxFileName
fn(fni
.fullname
, fni
.format
);
906 wxString fullname
= fn
.GetFullPath(fni
.format
);
907 if ( fullname
!= fni
.fullname
)
909 wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni
.fullname
);
912 bool isAbsolute
= fn
.IsAbsolute(fni
.format
);
913 wxPrintf(_T("'%s' is %s (%s)\n\t"),
915 isAbsolute
? "absolute" : "relative",
916 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
918 if ( !fn
.Normalize(wxPATH_NORM_ALL
, wxEmptyString
, fni
.format
) )
920 wxPuts(_T("ERROR (couldn't be normalized)"));
924 wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
928 wxPuts(wxEmptyString
);
931 static void TestFileNameSplit()
933 wxPuts(_T("*** testing wxFileName splitting ***"));
935 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
937 const FileNameInfo
& fni
= filenames
[n
];
938 wxString volume
, path
, name
, ext
;
939 wxFileName::SplitPath(fni
.fullname
,
940 &volume
, &path
, &name
, &ext
, fni
.format
);
942 wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"),
944 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
946 if ( volume
!= fni
.volume
)
947 wxPrintf(_T(" (ERROR: volume = '%s')"), fni
.volume
);
948 if ( path
!= fni
.path
)
949 wxPrintf(_T(" (ERROR: path = '%s')"), fni
.path
);
950 if ( name
!= fni
.name
)
951 wxPrintf(_T(" (ERROR: name = '%s')"), fni
.name
);
952 if ( ext
!= fni
.ext
)
953 wxPrintf(_T(" (ERROR: ext = '%s')"), fni
.ext
);
955 wxPuts(wxEmptyString
);
959 static void TestFileNameTemp()
961 wxPuts(_T("*** testing wxFileName temp file creation ***"));
963 static const wxChar
*tmpprefixes
[] =
971 _T("/tmp/foo/bar"), // this one must be an error
975 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
977 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
980 // "error" is not in upper case because it may be ok
981 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
985 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
986 tmpprefixes
[n
], path
.c_str());
988 if ( !wxRemoveFile(path
) )
990 wxLogWarning(_T("Failed to remove temp file '%s'"),
997 static void TestFileNameMakeRelative()
999 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
1001 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1003 const FileNameInfo
& fni
= filenames
[n
];
1005 wxFileName
fn(fni
.fullname
, fni
.format
);
1007 // choose the base dir of the same format
1009 switch ( fni
.format
)
1012 base
= _T("/usr/bin/");
1021 // TODO: I don't know how this is supposed to work there
1024 case wxPATH_NATIVE
: // make gcc happy
1026 wxFAIL_MSG( _T("unexpected path format") );
1029 wxPrintf(_T("'%s' relative to '%s': "),
1030 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
1032 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
1034 wxPuts(_T("unchanged"));
1038 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1043 static void TestFileNameMakeAbsolute()
1045 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
1047 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1049 const FileNameInfo
& fni
= filenames
[n
];
1050 wxFileName
fn(fni
.fullname
, fni
.format
);
1052 wxPrintf(_T("'%s' absolutized: "),
1053 fn
.GetFullPath(fni
.format
).c_str());
1055 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1058 wxPuts(wxEmptyString
);
1061 static void TestFileNameDirManip()
1063 // TODO: test AppendDir(), RemoveDir(), ...
1066 static void TestFileNameComparison()
1071 static void TestFileNameOperations()
1076 static void TestFileNameCwd()
1081 #endif // TEST_FILENAME
1083 // ----------------------------------------------------------------------------
1084 // wxFileName time functions
1085 // ----------------------------------------------------------------------------
1087 #ifdef TEST_FILETIME
1089 #include <wx/filename.h>
1090 #include <wx/datetime.h>
1092 static void TestFileGetTimes()
1094 wxFileName
fn(_T("testdata.fc"));
1096 wxDateTime dtAccess
, dtMod
, dtCreate
;
1097 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
1099 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
1103 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
1105 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
1106 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
1107 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
1108 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1113 static void TestFileSetTimes()
1115 wxFileName
fn(_T("testdata.fc"));
1119 wxPrintf(_T("ERROR: Touch() failed.\n"));
1124 #endif // TEST_FILETIME
1126 // ----------------------------------------------------------------------------
1128 // ----------------------------------------------------------------------------
1132 #include "wx/hash.h"
1136 Foo(int n_
) { n
= n_
; count
++; }
1141 static size_t count
;
1144 size_t Foo::count
= 0;
1146 WX_DECLARE_LIST(Foo
, wxListFoos
);
1147 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1149 #include "wx/listimpl.cpp"
1151 WX_DEFINE_LIST(wxListFoos
);
1153 #include "wx/timer.h"
1155 static void TestHash()
1157 wxPuts(_T("*** Testing wxHashTable ***\n"));
1158 const int COUNT
= 100;
1165 wxHashTable
hash(wxKEY_INTEGER
, 10), hash2(wxKEY_STRING
);
1169 for ( i
= 0; i
< COUNT
; ++i
)
1170 hash
.Put(i
, &o
+ i
);
1173 wxHashTable::compatibility_iterator it
= hash
.Next();
1183 wxPuts(_T("Error in wxHashTable::compatibility_iterator\n"));
1185 for ( i
= 99; i
>= 0; --i
)
1186 if( hash
.Get(i
) != &o
+ i
)
1187 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1189 for ( i
= 0; i
< COUNT
; ++i
)
1190 hash
.Put(i
, &o
+ i
+ 20);
1192 for ( i
= 99; i
>= 0; --i
)
1193 if( hash
.Get(i
) != &o
+ i
)
1194 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1196 for ( i
= 0; i
< COUNT
/2; ++i
)
1197 if( hash
.Delete(i
) != &o
+ i
)
1198 wxPuts(_T("Error in wxHashTable::Delete\n"));
1200 for ( i
= COUNT
/2; i
< COUNT
; ++i
)
1201 if( hash
.Get(i
) != &o
+ i
)
1202 wxPuts(_T("Error (3) in wxHashTable::Get/Put\n"));
1204 for ( i
= 0; i
< COUNT
/2; ++i
)
1205 if( hash
.Get(i
) != &o
+ i
+ 20)
1206 wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n"));
1208 for ( i
= 0; i
< COUNT
/2; ++i
)
1209 if( hash
.Delete(i
) != &o
+ i
+ 20)
1210 wxPuts(_T("Error (2) in wxHashTable::Delete\n"));
1212 for ( i
= 0; i
< COUNT
/2; ++i
)
1213 if( hash
.Get(i
) != NULL
)
1214 wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n"));
1216 hash2
.Put(_T("foo"), &o
+ 1);
1217 hash2
.Put(_T("bar"), &o
+ 2);
1218 hash2
.Put(_T("baz"), &o
+ 3);
1220 if (hash2
.Get(_T("moo")) != NULL
)
1221 wxPuts(_T("Error in wxHashTable::Get\n"));
1223 if (hash2
.Get(_T("bar")) != &o
+ 2)
1224 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1226 hash2
.Put(_T("bar"), &o
+ 0);
1228 if (hash2
.Get(_T("bar")) != &o
+ 2)
1229 wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
1232 // and now some corner-case testing; 3 and 13 hash to the same bucket
1234 wxHashTable
hash(wxKEY_INTEGER
, 10);
1237 hash
.Put(3, &dummy
);
1240 if (hash
.Get(3) != NULL
)
1241 wxPuts(_T("Corner case 1 failure\n"));
1243 hash
.Put(3, &dummy
);
1244 hash
.Put(13, &dummy
);
1247 if (hash
.Get(3) != NULL
)
1248 wxPuts(_T("Corner case 2 failure\n"));
1252 if (hash
.Get(13) != NULL
)
1253 wxPuts(_T("Corner case 3 failure\n"));
1255 hash
.Put(3, &dummy
);
1256 hash
.Put(13, &dummy
);
1259 if (hash
.Get(13) != NULL
)
1260 wxPuts(_T("Corner case 4 failure\n"));
1264 if (hash
.Get(3) != NULL
)
1265 wxPuts(_T("Corner case 5 failure\n"));
1269 wxHashTable
hash(wxKEY_INTEGER
, 10);
1272 hash
.Put(3, 7, &dummy
+ 7);
1273 hash
.Put(4, 8, &dummy
+ 8);
1275 if (hash
.Get(7) != NULL
) wxPuts(_T("Key/Hash 1 failure\n"));
1276 if (hash
.Get(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 2 failure\n"));
1277 if (hash
.Get(4) != NULL
) wxPuts(_T("Key/Hash 3 failure\n"));
1278 if (hash
.Get(3) != NULL
) wxPuts(_T("Key/Hash 4 failure\n"));
1279 if (hash
.Get(8) != NULL
) wxPuts(_T("Key/Hash 5 failure\n"));
1280 if (hash
.Get(8, 4) != NULL
) wxPuts(_T("Key/Hash 6 failure\n"));
1282 if (hash
.Delete(7) != NULL
) wxPuts(_T("Key/Hash 7 failure\n"));
1283 if (hash
.Delete(3) != NULL
) wxPuts(_T("Key/Hash 8 failure\n"));
1284 if (hash
.Delete(3, 7) != &dummy
+ 7) wxPuts(_T("Key/Hash 8 failure\n"));
1289 hash
.DeleteContents(true);
1291 wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"),
1292 hash
.GetCount(), Foo::count
);
1294 static const int hashTestData
[] =
1296 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1300 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1302 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1305 wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"),
1306 hash
.GetCount(), Foo::count
);
1308 wxPuts(_T("Hash access test:"));
1309 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1311 wxPrintf(_T("\tGetting element with key %d, value %d: "),
1312 hashTestData
[n
], n
);
1313 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1316 wxPrintf(_T("ERROR, not found.\n"));
1320 wxPrintf(_T("%d (%s)\n"), foo
->n
,
1321 (size_t)foo
->n
== n
? "ok" : "ERROR");
1325 wxPrintf(_T("\nTrying to get an element not in hash: "));
1327 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1329 wxPuts(_T("ERROR: found!"));
1333 wxPuts(_T("ok (not found)"));
1336 Foo
* foo
= hash
.Delete(0);
1338 wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count
);
1342 wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count
);
1345 wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
);
1346 wxPuts(_T("*** Testing wxHashTable finished ***\n"));
1348 wxPrintf(_T("Time: %ld\n"), sw
.Time());
1353 // ----------------------------------------------------------------------------
1355 // ----------------------------------------------------------------------------
1359 #include "wx/hashmap.h"
1361 // test compilation of basic map types
1362 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1363 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1364 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1365 myUnsignedHashMap
);
1366 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1368 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1370 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1372 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1376 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1377 // myStringHashMap );
1378 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1380 typedef myStringHashMap::iterator Itor
;
1382 static void TestHashMap()
1384 wxPuts(_T("*** Testing wxHashMap ***\n"));
1385 myStringHashMap
sh(0); // as small as possible
1388 const size_t count
= 10000;
1390 // init with some data
1391 for( i
= 0; i
< count
; ++i
)
1393 buf
.Printf(wxT("%d"), i
);
1394 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1397 // test that insertion worked
1398 if( sh
.size() != count
)
1400 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
);
1403 for( i
= 0; i
< count
; ++i
)
1405 buf
.Printf(wxT("%d"), i
);
1406 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1408 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
1413 // check that iterators work
1415 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1419 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
1423 if( it
->second
!= sh
[it
->first
] )
1425 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
1430 if( sh
.size() != i
)
1432 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
);
1435 // test copy ctor, assignment operator
1436 myStringHashMap
h1( sh
), h2( 0 );
1439 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1441 if( h1
[it
->first
] != it
->second
)
1443 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str());
1446 if( h2
[it
->first
] != it
->second
)
1448 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str());
1453 for( i
= 0; i
< count
; ++i
)
1455 buf
.Printf(wxT("%d"), i
);
1456 size_t sz
= sh
.size();
1458 // test find() and erase(it)
1461 it
= sh
.find( buf
);
1462 if( it
!= sh
.end() )
1466 if( sh
.find( buf
) != sh
.end() )
1468 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1472 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
);
1477 size_t c
= sh
.erase( buf
);
1479 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
1481 if( sh
.find( buf
) != sh
.end() )
1483 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1487 // count should decrease
1488 if( sh
.size() != sz
- 1 )
1490 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
1494 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
1497 #endif // TEST_HASHMAP
1499 // ----------------------------------------------------------------------------
1501 // ----------------------------------------------------------------------------
1505 #include "wx/hashset.h"
1507 // test compilation of basic map types
1508 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet
);
1509 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet
);
1510 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
,
1511 myUnsignedHashSet
);
1512 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
,
1514 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
,
1516 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
,
1518 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
,
1520 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
,
1532 unsigned long operator()(const MyStruct
& s
) const
1533 { return m_dummy(s
.ptr
); }
1534 MyHash
& operator=(const MyHash
&) { return *this; }
1536 wxPointerHash m_dummy
;
1542 bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const
1543 { return s1
.ptr
== s2
.ptr
; }
1544 MyEqual
& operator=(const MyEqual
&) { return *this; }
1547 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet
);
1549 typedef myTestHashSet5 wxStringHashSet
;
1551 static void TestHashSet()
1553 wxPrintf(_T("*** Testing wxHashSet ***\n"));
1555 wxStringHashSet set1
;
1557 set1
.insert( _T("abc") );
1558 set1
.insert( _T("bbc") );
1559 set1
.insert( _T("cbc") );
1560 set1
.insert( _T("abc") );
1562 if( set1
.size() != 3 )
1563 wxPrintf(_T("*** ERROR IN INSERT ***\n"));
1569 tmp
.ptr
= &dummy
; tmp
.str
= _T("ABC");
1571 tmp
.ptr
= &dummy
+ 1;
1573 tmp
.ptr
= &dummy
; tmp
.str
= _T("CDE");
1576 if( set2
.size() != 2 )
1577 wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
1579 mySet::iterator it
= set2
.find( tmp
);
1581 if( it
== set2
.end() )
1582 wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
1583 if( it
->ptr
!= &dummy
)
1584 wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
1585 if( it
->str
!= _T("ABC") )
1586 wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
1588 wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
1591 #endif // TEST_HASHSET
1593 // ----------------------------------------------------------------------------
1595 // ----------------------------------------------------------------------------
1599 #include "wx/list.h"
1601 WX_DECLARE_LIST(Bar
, wxListBars
);
1602 #include "wx/listimpl.cpp"
1603 WX_DEFINE_LIST(wxListBars
);
1605 WX_DECLARE_LIST(int, wxListInt
);
1606 WX_DEFINE_LIST(wxListInt
);
1608 static void TestList()
1610 wxPuts(_T("*** Testing wxList operations ***\n"));
1616 for ( i
= 0; i
< 5; ++i
)
1617 list1
.Append(dummy
+ i
);
1619 if ( list1
.GetCount() != 5 )
1620 wxPuts(_T("Wrong number of items in list\n"));
1622 if ( list1
.Item(3)->GetData() != dummy
+ 3 )
1623 wxPuts(_T("Error in Item()\n"));
1625 if ( !list1
.Find(dummy
+ 4) )
1626 wxPuts(_T("Error in Find()\n"));
1628 wxListInt::compatibility_iterator node
= list1
.GetFirst();
1633 if ( node
->GetData() != dummy
+ i
)
1634 wxPuts(_T("Error in compatibility_iterator\n"));
1635 node
= node
->GetNext();
1639 if ( size_t(i
) != list1
.GetCount() )
1640 wxPuts(_T("Error in compatibility_iterator\n"));
1642 list1
.Insert(dummy
+ 0);
1643 list1
.Insert(1, dummy
+ 1);
1644 list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy
+ 2);
1646 node
= list1
.GetFirst();
1651 int* t
= node
->GetData();
1652 if ( t
!= dummy
+ i
)
1653 wxPuts(_T("Error in Insert\n"));
1654 node
= node
->GetNext();
1659 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1661 wxPuts(_T("*** Testing std::list operations ***\n"));
1665 wxListInt::iterator it
, en
;
1666 wxListInt::reverse_iterator rit
, ren
;
1668 for ( i
= 0; i
< 5; ++i
)
1669 list1
.push_back(i
+ &i
);
1671 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
1672 it
!= en
; ++it
, ++i
)
1673 if ( *it
!= i
+ &i
)
1674 wxPuts(_T("Error in iterator\n"));
1676 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
1677 rit
!= ren
; ++rit
, --i
)
1678 if ( *rit
!= i
+ &i
)
1679 wxPuts(_T("Error in reverse_iterator\n"));
1681 if ( *list1
.rbegin() != *--list1
.end() ||
1682 *list1
.begin() != *--list1
.rend() )
1683 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1684 if ( *list1
.begin() != *--++list1
.begin() ||
1685 *list1
.rbegin() != *--++list1
.rbegin() )
1686 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1688 if ( list1
.front() != &i
|| list1
.back() != &i
+ 4 )
1689 wxPuts(_T("Error in front()/back()\n"));
1691 list1
.erase(list1
.begin());
1692 list1
.erase(--list1
.end());
1694 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
1695 it
!= en
; ++it
, ++i
)
1696 if ( *it
!= i
+ &i
)
1697 wxPuts(_T("Error in erase()\n"));
1700 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1703 static void TestListCtor()
1705 wxPuts(_T("*** Testing wxList construction ***\n"));
1709 list1
.Append(new Bar(_T("first")));
1710 list1
.Append(new Bar(_T("second")));
1712 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
1713 list1
.GetCount(), Bar::GetNumber());
1718 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
1719 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1722 list1
.DeleteContents(true);
1724 WX_CLEAR_LIST(wxListBars
, list1
);
1728 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
1733 // ----------------------------------------------------------------------------
1735 // ----------------------------------------------------------------------------
1739 #include "wx/intl.h"
1740 #include "wx/utils.h" // for wxSetEnv
1742 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1744 // find the name of the language from its value
1745 static const wxChar
*GetLangName(int lang
)
1747 static const wxChar
*languageNames
[] =
1757 _T("ARABIC_ALGERIA"),
1758 _T("ARABIC_BAHRAIN"),
1761 _T("ARABIC_JORDAN"),
1762 _T("ARABIC_KUWAIT"),
1763 _T("ARABIC_LEBANON"),
1765 _T("ARABIC_MOROCCO"),
1768 _T("ARABIC_SAUDI_ARABIA"),
1771 _T("ARABIC_TUNISIA"),
1778 _T("AZERI_CYRILLIC"),
1793 _T("CHINESE_SIMPLIFIED"),
1794 _T("CHINESE_TRADITIONAL"),
1795 _T("CHINESE_HONGKONG"),
1796 _T("CHINESE_MACAU"),
1797 _T("CHINESE_SINGAPORE"),
1798 _T("CHINESE_TAIWAN"),
1804 _T("DUTCH_BELGIAN"),
1808 _T("ENGLISH_AUSTRALIA"),
1809 _T("ENGLISH_BELIZE"),
1810 _T("ENGLISH_BOTSWANA"),
1811 _T("ENGLISH_CANADA"),
1812 _T("ENGLISH_CARIBBEAN"),
1813 _T("ENGLISH_DENMARK"),
1815 _T("ENGLISH_JAMAICA"),
1816 _T("ENGLISH_NEW_ZEALAND"),
1817 _T("ENGLISH_PHILIPPINES"),
1818 _T("ENGLISH_SOUTH_AFRICA"),
1819 _T("ENGLISH_TRINIDAD"),
1820 _T("ENGLISH_ZIMBABWE"),
1828 _T("FRENCH_BELGIAN"),
1829 _T("FRENCH_CANADIAN"),
1830 _T("FRENCH_LUXEMBOURG"),
1831 _T("FRENCH_MONACO"),
1837 _T("GERMAN_AUSTRIAN"),
1838 _T("GERMAN_BELGIUM"),
1839 _T("GERMAN_LIECHTENSTEIN"),
1840 _T("GERMAN_LUXEMBOURG"),
1858 _T("ITALIAN_SWISS"),
1863 _T("KASHMIRI_INDIA"),
1881 _T("MALAY_BRUNEI_DARUSSALAM"),
1882 _T("MALAY_MALAYSIA"),
1892 _T("NORWEGIAN_BOKMAL"),
1893 _T("NORWEGIAN_NYNORSK"),
1900 _T("PORTUGUESE_BRAZILIAN"),
1903 _T("RHAETO_ROMANCE"),
1906 _T("RUSSIAN_UKRAINE"),
1912 _T("SERBIAN_CYRILLIC"),
1913 _T("SERBIAN_LATIN"),
1914 _T("SERBO_CROATIAN"),
1925 _T("SPANISH_ARGENTINA"),
1926 _T("SPANISH_BOLIVIA"),
1927 _T("SPANISH_CHILE"),
1928 _T("SPANISH_COLOMBIA"),
1929 _T("SPANISH_COSTA_RICA"),
1930 _T("SPANISH_DOMINICAN_REPUBLIC"),
1931 _T("SPANISH_ECUADOR"),
1932 _T("SPANISH_EL_SALVADOR"),
1933 _T("SPANISH_GUATEMALA"),
1934 _T("SPANISH_HONDURAS"),
1935 _T("SPANISH_MEXICAN"),
1936 _T("SPANISH_MODERN"),
1937 _T("SPANISH_NICARAGUA"),
1938 _T("SPANISH_PANAMA"),
1939 _T("SPANISH_PARAGUAY"),
1941 _T("SPANISH_PUERTO_RICO"),
1942 _T("SPANISH_URUGUAY"),
1944 _T("SPANISH_VENEZUELA"),
1948 _T("SWEDISH_FINLAND"),
1966 _T("URDU_PAKISTAN"),
1968 _T("UZBEK_CYRILLIC"),
1981 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1982 return languageNames
[lang
];
1984 return _T("INVALID");
1987 static void TestDefaultLang()
1989 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1991 static const wxChar
*langStrings
[] =
1993 NULL
, // system default
2000 _T("de_DE.iso88591"),
2002 _T("?"), // invalid lang spec
2003 _T("klingonese"), // I bet on some systems it does exist...
2006 wxPrintf(_T("The default system encoding is %s (%d)\n"),
2007 wxLocale::GetSystemEncodingName().c_str(),
2008 wxLocale::GetSystemEncoding());
2010 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
2012 const wxChar
*langStr
= langStrings
[n
];
2015 // FIXME: this doesn't do anything at all under Windows, we need
2016 // to create a new wxLocale!
2017 wxSetEnv(_T("LC_ALL"), langStr
);
2020 int lang
= gs_localeDefault
.GetSystemLanguage();
2021 wxPrintf(_T("Locale for '%s' is %s.\n"),
2022 langStr
? langStr
: _T("system default"), GetLangName(lang
));
2026 #endif // TEST_LOCALE
2028 // ----------------------------------------------------------------------------
2030 // ----------------------------------------------------------------------------
2034 #include "wx/mimetype.h"
2036 static void TestMimeEnum()
2038 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
2040 wxArrayString mimetypes
;
2042 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
2044 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
2049 for ( size_t n
= 0; n
< count
; n
++ )
2051 wxFileType
*filetype
=
2052 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
2055 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
2056 mimetypes
[n
].c_str());
2060 filetype
->GetDescription(&desc
);
2061 filetype
->GetExtensions(exts
);
2063 filetype
->GetIcon(NULL
);
2066 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
2069 extsAll
<< _T(", ");
2073 wxPrintf(_T("\t%s: %s (%s)\n"),
2074 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
2077 wxPuts(wxEmptyString
);
2080 static void TestMimeOverride()
2082 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
2084 static const wxChar
*mailcap
= _T("/tmp/mailcap");
2085 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
2087 if ( wxFile::Exists(mailcap
) )
2088 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
2090 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
2092 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
2095 if ( wxFile::Exists(mimetypes
) )
2096 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
2098 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
2100 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
2103 wxPuts(wxEmptyString
);
2106 static void TestMimeFilename()
2108 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
2110 static const wxChar
*filenames
[] =
2118 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
2120 const wxString fname
= filenames
[n
];
2121 wxString ext
= fname
.AfterLast(_T('.'));
2122 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
2125 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
2130 if ( !ft
->GetDescription(&desc
) )
2131 desc
= _T("<no description>");
2134 if ( !ft
->GetOpenCommand(&cmd
,
2135 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
2136 cmd
= _T("<no command available>");
2138 cmd
= wxString(_T('"')) + cmd
+ _T('"');
2140 wxPrintf(_T("To open %s (%s) do %s.\n"),
2141 fname
.c_str(), desc
.c_str(), cmd
.c_str());
2147 wxPuts(wxEmptyString
);
2150 static void TestMimeAssociate()
2152 wxPuts(_T("*** Testing creation of filetype association ***\n"));
2154 wxFileTypeInfo
ftInfo(
2155 _T("application/x-xyz"),
2156 _T("xyzview '%s'"), // open cmd
2157 _T(""), // print cmd
2158 _T("XYZ File"), // description
2159 _T(".xyz"), // extensions
2160 NULL
// end of extensions
2162 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
2164 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
2167 wxPuts(_T("ERROR: failed to create association!"));
2171 // TODO: read it back
2175 wxPuts(wxEmptyString
);
2180 // ----------------------------------------------------------------------------
2181 // misc information functions
2182 // ----------------------------------------------------------------------------
2184 #ifdef TEST_INFO_FUNCTIONS
2186 #include "wx/utils.h"
2188 static void TestDiskInfo()
2190 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
2194 wxChar pathname
[128];
2195 wxPrintf(_T("\nEnter a directory name: "));
2196 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
2199 // kill the last '\n'
2200 pathname
[wxStrlen(pathname
) - 1] = 0;
2202 wxLongLong total
, free
;
2203 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
2205 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
2209 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
2210 (total
/ 1024).ToString().c_str(),
2211 (free
/ 1024).ToString().c_str(),
2217 static void TestOsInfo()
2219 wxPuts(_T("*** Testing OS info functions ***\n"));
2222 wxGetOsVersion(&major
, &minor
);
2223 wxPrintf(_T("Running under: %s, version %d.%d\n"),
2224 wxGetOsDescription().c_str(), major
, minor
);
2226 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
2228 wxPrintf(_T("Host name is %s (%s).\n"),
2229 wxGetHostName().c_str(), wxGetFullHostName().c_str());
2231 wxPuts(wxEmptyString
);
2234 static void TestUserInfo()
2236 wxPuts(_T("*** Testing user info functions ***\n"));
2238 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
2239 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
2240 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
2241 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
2243 wxPuts(wxEmptyString
);
2246 #endif // TEST_INFO_FUNCTIONS
2248 // ----------------------------------------------------------------------------
2250 // ----------------------------------------------------------------------------
2252 #ifdef TEST_PATHLIST
2255 #define CMD_IN_PATH _T("ls")
2257 #define CMD_IN_PATH _T("command.com")
2260 static void TestPathList()
2262 wxPuts(_T("*** Testing wxPathList ***\n"));
2264 wxPathList pathlist
;
2265 pathlist
.AddEnvList(_T("PATH"));
2266 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
2269 wxPrintf(_T("ERROR: command not found in the path.\n"));
2273 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
2277 #endif // TEST_PATHLIST
2279 // ----------------------------------------------------------------------------
2280 // regular expressions
2281 // ----------------------------------------------------------------------------
2285 #include "wx/regex.h"
2287 static void TestRegExInteractive()
2289 wxPuts(_T("*** Testing RE interactively ***"));
2293 wxChar pattern
[128];
2294 wxPrintf(_T("\nEnter a pattern: "));
2295 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2298 // kill the last '\n'
2299 pattern
[wxStrlen(pattern
) - 1] = 0;
2302 if ( !re
.Compile(pattern
) )
2310 wxPrintf(_T("Enter text to match: "));
2311 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
2314 // kill the last '\n'
2315 text
[wxStrlen(text
) - 1] = 0;
2317 if ( !re
.Matches(text
) )
2319 wxPrintf(_T("No match.\n"));
2323 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
2326 for ( size_t n
= 1; ; n
++ )
2328 if ( !re
.GetMatch(&start
, &len
, n
) )
2333 wxPrintf(_T("Subexpr %u matched '%s'\n"),
2334 n
, wxString(text
+ start
, len
).c_str());
2341 #endif // TEST_REGEX
2343 // ----------------------------------------------------------------------------
2345 // ----------------------------------------------------------------------------
2355 static void TestDbOpen()
2363 // ----------------------------------------------------------------------------
2365 // ----------------------------------------------------------------------------
2368 NB: this stuff was taken from the glibc test suite and modified to build
2369 in wxWindows: if I read the copyright below properly, this shouldn't
2375 #ifdef wxTEST_PRINTF
2376 // use our functions from wxchar.cpp
2380 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
2381 // in the tests below
2382 int wxPrintf( const wxChar
*format
, ... );
2383 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
2386 #include "wx/longlong.h"
2390 static void rfg1 (void);
2391 static void rfg2 (void);
2395 fmtchk (const wxChar
*fmt
)
2397 (void) wxPrintf(_T("%s:\t`"), fmt
);
2398 (void) wxPrintf(fmt
, 0x12);
2399 (void) wxPrintf(_T("'\n"));
2403 fmtst1chk (const wxChar
*fmt
)
2405 (void) wxPrintf(_T("%s:\t`"), fmt
);
2406 (void) wxPrintf(fmt
, 4, 0x12);
2407 (void) wxPrintf(_T("'\n"));
2411 fmtst2chk (const wxChar
*fmt
)
2413 (void) wxPrintf(_T("%s:\t`"), fmt
);
2414 (void) wxPrintf(fmt
, 4, 4, 0x12);
2415 (void) wxPrintf(_T("'\n"));
2418 /* This page is covered by the following copyright: */
2420 /* (C) Copyright C E Chew
2422 * Feel free to copy, use and distribute this software provided:
2424 * 1. you do not pretend that you wrote it
2425 * 2. you leave this copyright notice intact.
2429 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2436 /* Formatted Output Test
2438 * This exercises the output formatting code.
2441 wxChar
*PointerNull
= NULL
;
2448 wxChar
*prefix
= buf
;
2451 wxPuts(_T("\nFormatted output test"));
2452 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
2453 wxStrcpy(prefix
, _T("%"));
2454 for (i
= 0; i
< 2; i
++) {
2455 for (j
= 0; j
< 2; j
++) {
2456 for (k
= 0; k
< 2; k
++) {
2457 for (l
= 0; l
< 2; l
++) {
2458 wxStrcpy(prefix
, _T("%"));
2459 if (i
== 0) wxStrcat(prefix
, _T("-"));
2460 if (j
== 0) wxStrcat(prefix
, _T("+"));
2461 if (k
== 0) wxStrcat(prefix
, _T("#"));
2462 if (l
== 0) wxStrcat(prefix
, _T("0"));
2463 wxPrintf(_T("%5s |"), prefix
);
2464 wxStrcpy(tp
, prefix
);
2465 wxStrcat(tp
, _T("6d |"));
2467 wxStrcpy(tp
, prefix
);
2468 wxStrcat(tp
, _T("6o |"));
2470 wxStrcpy(tp
, prefix
);
2471 wxStrcat(tp
, _T("6x |"));
2473 wxStrcpy(tp
, prefix
);
2474 wxStrcat(tp
, _T("6X |"));
2476 wxStrcpy(tp
, prefix
);
2477 wxStrcat(tp
, _T("6u |"));
2484 wxPrintf(_T("%10s\n"), PointerNull
);
2485 wxPrintf(_T("%-10s\n"), PointerNull
);
2488 static void TestPrintf()
2490 static wxChar shortstr
[] = _T("Hi, Z.");
2491 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
2492 I am ready for my first lesson today.");
2494 wxString test_format
;
2498 fmtchk(_T("%4.4x"));
2499 fmtchk(_T("%04.4x"));
2500 fmtchk(_T("%4.3x"));
2501 fmtchk(_T("%04.3x"));
2503 fmtst1chk(_T("%.*x"));
2504 fmtst1chk(_T("%0*x"));
2505 fmtst2chk(_T("%*.*x"));
2506 fmtst2chk(_T("%0*.*x"));
2508 wxString bad_format
= _T("bad format:\t\"%b\"\n");
2509 wxPrintf(bad_format
.c_str());
2510 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
2512 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
2513 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
2514 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
2515 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
2516 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
2517 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
2518 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
2519 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
2520 wxPrintf(test_format
.c_str(), -123456);
2521 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
2522 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
2524 test_format
= _T("zero-padded string:\t\"%010s\"\n");
2525 wxPrintf(test_format
.c_str(), shortstr
);
2526 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
2527 wxPrintf(test_format
.c_str(), shortstr
);
2528 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
2529 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
2530 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
2531 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
2533 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
2534 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
2535 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
2536 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
2537 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
2538 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
2539 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
2540 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
2541 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
2542 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
2543 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
2544 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
2546 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
2547 wxPrintf (_T(" %6.5f\n"), .1);
2548 wxPrintf (_T("x%5.4fx\n"), .5);
2550 wxPrintf (_T("%#03x\n"), 1);
2552 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
2558 while (niter
-- != 0)
2559 wxPrintf (_T("%.17e\n"), d
/ 2);
2564 // Open Watcom cause compiler error here
2565 // Error! E173: col(24) floating-point constant too small to represent
2566 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
2569 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
2570 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
2571 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
2572 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
2573 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
2574 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
2575 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
2576 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
2577 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
2578 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
2583 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
2585 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
2586 rc
, WXSIZEOF(buf
), buf
);
2589 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
2590 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
2596 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
2597 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
2598 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
2599 wxPrintf (_T("%g should be 123.456\n"), 123.456);
2600 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
2601 wxPrintf (_T("%g should be 10\n"), 10.0);
2602 wxPrintf (_T("%g should be 0.02\n"), 0.02);
2606 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
2612 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
2614 result
|= wxStrcmp (buf
,
2615 _T("onetwo three "));
2617 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
2624 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
2626 // for some reason below line fails under Borland
2627 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
2630 if (wxStrcmp (buf
, _T("40000000000")) != 0)
2633 wxPuts (_T("\tFAILED"));
2635 wxUnusedVar(result
);
2636 wxPuts (wxEmptyString
);
2638 #endif // wxLongLong_t
2640 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
2641 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
2643 wxPuts (_T("--- Should be no further output. ---"));
2652 memset (bytes
, '\xff', sizeof bytes
);
2653 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
2654 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
2655 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
2657 wxPuts (_T("%hhn overwrite more bytes"));
2662 wxPuts (_T("%hhn wrote incorrect value"));
2674 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2675 if (wxStrcmp (buf
, _T(" ")) != 0)
2676 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2677 wxSprintf (buf
, _T("%5.f"), 33.3);
2678 if (wxStrcmp (buf
, _T(" 33")) != 0)
2679 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2680 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2681 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2682 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2683 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2684 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2685 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2686 wxSprintf (buf
, _T("%.g"), 33.3);
2687 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2688 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2689 wxSprintf (buf
, _T("%.G"), 33.3);
2690 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2691 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2699 wxString test_format
;
2702 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2703 if (wxStrcmp (buf
, _T("3")) != 0)
2704 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2706 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2707 if (wxStrcmp (buf
, _T("3")) != 0)
2708 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2710 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2711 if (wxStrcmp (buf
, _T(" 3")) != 0)
2712 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2714 test_format
= _T("%04.*o");
2715 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2716 if (wxStrcmp (buf
, _T(" 041")) != 0)
2717 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2719 test_format
= _T("%09.*u");
2720 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2721 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2722 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2724 test_format
= _T("%04.*x");
2725 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2726 if (wxStrcmp (buf
, _T(" 021")) != 0)
2727 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2729 test_format
= _T("%04.*X");
2730 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2731 if (wxStrcmp (buf
, _T(" 021")) != 0)
2732 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2735 #endif // TEST_PRINTF
2737 // ----------------------------------------------------------------------------
2738 // registry and related stuff
2739 // ----------------------------------------------------------------------------
2741 // this is for MSW only
2744 #undef TEST_REGISTRY
2749 #include "wx/confbase.h"
2750 #include "wx/msw/regconf.h"
2753 static void TestRegConfWrite()
2755 wxConfig
*config
= new wxConfig(_T("myapp"));
2756 config
->SetPath(_T("/group1"));
2757 config
->Write(_T("entry1"), _T("foo"));
2758 config
->SetPath(_T("/group2"));
2759 config
->Write(_T("entry1"), _T("bar"));
2763 static void TestRegConfRead()
2765 wxConfig
*config
= new wxConfig(_T("myapp"));
2769 config
->SetPath(_T("/"));
2770 wxPuts(_T("Enumerating / subgroups:"));
2771 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2775 bCont
= config
->GetNextGroup(str
, dummy
);
2779 #endif // TEST_REGCONF
2781 #ifdef TEST_REGISTRY
2783 #include "wx/msw/registry.h"
2785 // I chose this one because I liked its name, but it probably only exists under
2787 static const wxChar
*TESTKEY
=
2788 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2790 static void TestRegistryRead()
2792 wxPuts(_T("*** testing registry reading ***"));
2794 wxRegKey
key(TESTKEY
);
2795 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2798 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2803 size_t nSubKeys
, nValues
;
2804 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2806 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2809 wxPrintf(_T("Enumerating values:\n"));
2813 bool cont
= key
.GetFirstValue(value
, dummy
);
2816 wxPrintf(_T("Value '%s': type "), value
.c_str());
2817 switch ( key
.GetValueType(value
) )
2819 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2820 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
2821 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2822 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
2823 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
2824 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2825 default: wxPrintf(_T("other (unknown)")); break;
2828 wxPrintf(_T(", value = "));
2829 if ( key
.IsNumericValue(value
) )
2832 key
.QueryValue(value
, &val
);
2833 wxPrintf(_T("%ld"), val
);
2838 key
.QueryValue(value
, val
);
2839 wxPrintf(_T("'%s'"), val
.c_str());
2841 key
.QueryRawValue(value
, val
);
2842 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2847 cont
= key
.GetNextValue(value
, dummy
);
2851 static void TestRegistryAssociation()
2854 The second call to deleteself genertaes an error message, with a
2855 messagebox saying .flo is crucial to system operation, while the .ddf
2856 call also fails, but with no error message
2861 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2863 key
= _T("ddxf_auto_file") ;
2864 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2866 key
= _T("ddxf_auto_file") ;
2867 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2869 key
= _T("program,0") ;
2870 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2872 key
= _T("program \"%1\"") ;
2874 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2876 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2878 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2880 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2884 #endif // TEST_REGISTRY
2886 // ----------------------------------------------------------------------------
2888 // ----------------------------------------------------------------------------
2890 #ifdef TEST_SCOPEGUARD
2892 #include "wx/scopeguard.h"
2894 static void function0() { puts("function0()"); }
2895 static void function1(int n
) { printf("function1(%d)\n", n
); }
2896 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2900 void method0() { printf("method0()\n"); }
2901 void method1(int n
) { printf("method1(%d)\n", n
); }
2902 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2905 static void TestScopeGuard()
2907 wxON_BLOCK_EXIT0(function0
);
2908 wxON_BLOCK_EXIT1(function1
, 17);
2909 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2912 wxON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
);
2913 wxON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7);
2914 wxON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e');
2916 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2917 dismissed
.Dismiss();
2922 // ----------------------------------------------------------------------------
2924 // ----------------------------------------------------------------------------
2928 #include "wx/socket.h"
2929 #include "wx/protocol/protocol.h"
2930 #include "wx/protocol/http.h"
2932 static void TestSocketServer()
2934 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2936 static const int PORT
= 3000;
2941 wxSocketServer
*server
= new wxSocketServer(addr
);
2942 if ( !server
->Ok() )
2944 wxPuts(_T("ERROR: failed to bind"));
2952 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2954 wxSocketBase
*socket
= server
->Accept();
2957 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2961 wxPuts(_T("Server: got a client."));
2963 server
->SetTimeout(60); // 1 min
2966 while ( !close
&& socket
->IsConnected() )
2969 wxChar ch
= _T('\0');
2972 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2974 // don't log error if the client just close the connection
2975 if ( socket
->IsConnected() )
2977 wxPuts(_T("ERROR: in wxSocket::Read."));
2997 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2998 if ( s
== _T("close") )
3000 wxPuts(_T("Closing connection"));
3004 else if ( s
== _T("quit") )
3009 wxPuts(_T("Shutting down the server"));
3011 else // not a special command
3013 socket
->Write(s
.MakeUpper().c_str(), s
.length());
3014 socket
->Write("\r\n", 2);
3015 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
3021 wxPuts(_T("Server: lost a client unexpectedly."));
3027 // same as "delete server" but is consistent with GUI programs
3031 static void TestSocketClient()
3033 wxPuts(_T("*** Testing wxSocketClient ***\n"));
3035 static const wxChar
*hostname
= _T("www.wxwindows.org");
3038 addr
.Hostname(hostname
);
3041 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
3043 wxSocketClient client
;
3044 if ( !client
.Connect(addr
) )
3046 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3050 wxPrintf(_T("--- Connected to %s:%u...\n"),
3051 addr
.Hostname().c_str(), addr
.Service());
3055 // could use simply "GET" here I suppose
3057 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
3058 client
.Write(cmdGet
, cmdGet
.length());
3059 wxPrintf(_T("--- Sent command '%s' to the server\n"),
3060 MakePrintable(cmdGet
).c_str());
3061 client
.Read(buf
, WXSIZEOF(buf
));
3062 wxPrintf(_T("--- Server replied:\n%s"), buf
);
3066 #endif // TEST_SOCKETS
3068 // ----------------------------------------------------------------------------
3070 // ----------------------------------------------------------------------------
3074 #include "wx/protocol/ftp.h"
3078 #define FTP_ANONYMOUS
3080 #ifdef FTP_ANONYMOUS
3081 static const wxChar
*directory
= _T("/pub");
3082 static const wxChar
*filename
= _T("welcome.msg");
3084 static const wxChar
*directory
= _T("/etc");
3085 static const wxChar
*filename
= _T("issue");
3088 static bool TestFtpConnect()
3090 wxPuts(_T("*** Testing FTP connect ***"));
3092 #ifdef FTP_ANONYMOUS
3093 static const wxChar
*hostname
= _T("ftp.wxwindows.org");
3095 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
3096 #else // !FTP_ANONYMOUS
3097 static const wxChar
*hostname
= "localhost";
3100 wxFgets(user
, WXSIZEOF(user
), stdin
);
3101 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
3104 wxChar password
[256];
3105 wxPrintf(_T("Password for %s: "), password
);
3106 wxFgets(password
, WXSIZEOF(password
), stdin
);
3107 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
3108 ftp
.SetPassword(password
);
3110 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
3111 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
3113 if ( !ftp
.Connect(hostname
) )
3115 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3121 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
3122 hostname
, ftp
.Pwd().c_str());
3128 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
3129 static void TestFtpWuFtpd()
3132 static const wxChar
*hostname
= _T("ftp.eudora.com");
3133 if ( !ftp
.Connect(hostname
) )
3135 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3139 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
3140 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3143 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3147 size_t size
= in
->GetSize();
3148 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3150 wxChar
*data
= new wxChar
[size
];
3151 if ( !in
->Read(data
, size
) )
3153 wxPuts(_T("ERROR: read error"));
3157 wxPrintf(_T("Successfully retrieved the file.\n"));
3166 static void TestFtpList()
3168 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
3171 if ( !ftp
.ChDir(directory
) )
3173 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3176 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3178 // test NLIST and LIST
3179 wxArrayString files
;
3180 if ( !ftp
.GetFilesList(files
) )
3182 wxPuts(_T("ERROR: failed to get NLIST of files"));
3186 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
3187 size_t count
= files
.GetCount();
3188 for ( size_t n
= 0; n
< count
; n
++ )
3190 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3192 wxPuts(_T("End of the file list"));
3195 if ( !ftp
.GetDirList(files
) )
3197 wxPuts(_T("ERROR: failed to get LIST of files"));
3201 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
3202 size_t count
= files
.GetCount();
3203 for ( size_t n
= 0; n
< count
; n
++ )
3205 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3207 wxPuts(_T("End of the file list"));
3210 if ( !ftp
.ChDir(_T("..")) )
3212 wxPuts(_T("ERROR: failed to cd to .."));
3215 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3218 static void TestFtpDownload()
3220 wxPuts(_T("*** Testing wxFTP download ***\n"));
3223 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3226 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3230 size_t size
= in
->GetSize();
3231 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3234 wxChar
*data
= new wxChar
[size
];
3235 if ( !in
->Read(data
, size
) )
3237 wxPuts(_T("ERROR: read error"));
3241 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
3249 static void TestFtpFileSize()
3251 wxPuts(_T("*** Testing FTP SIZE command ***"));
3253 if ( !ftp
.ChDir(directory
) )
3255 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3258 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3260 if ( ftp
.FileExists(filename
) )
3262 int size
= ftp
.GetFileSize(filename
);
3264 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
3266 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
3270 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
3274 static void TestFtpMisc()
3276 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
3278 if ( ftp
.SendCommand(_T("STAT")) != '2' )
3280 wxPuts(_T("ERROR: STAT failed"));
3284 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
3287 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
3289 wxPuts(_T("ERROR: HELP SITE failed"));
3293 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
3294 ftp
.GetLastResult().c_str());
3298 static void TestFtpInteractive()
3300 wxPuts(_T("\n*** Interactive wxFTP test ***"));
3306 wxPrintf(_T("Enter FTP command: "));
3307 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3310 // kill the last '\n'
3311 buf
[wxStrlen(buf
) - 1] = 0;
3313 // special handling of LIST and NLST as they require data connection
3314 wxString
start(buf
, 4);
3316 if ( start
== _T("LIST") || start
== _T("NLST") )
3319 if ( wxStrlen(buf
) > 4 )
3322 wxArrayString files
;
3323 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
3325 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
3329 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
3330 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
3331 size_t count
= files
.GetCount();
3332 for ( size_t n
= 0; n
< count
; n
++ )
3334 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3336 wxPuts(_T("--- End of the file list"));
3341 wxChar ch
= ftp
.SendCommand(buf
);
3342 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
3345 wxPrintf(_T(" (return code %c)"), ch
);
3348 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
3352 wxPuts(_T("\n*** done ***"));
3355 static void TestFtpUpload()
3357 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
3360 static const wxChar
*file1
= _T("test1");
3361 static const wxChar
*file2
= _T("test2");
3362 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
3365 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3366 out
->Write("First hello", 11);
3370 // send a command to check the remote file
3371 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
3373 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
3377 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
3378 file1
, ftp
.GetLastResult().c_str());
3381 out
= ftp
.GetOutputStream(file2
);
3384 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3385 out
->Write("Second hello", 12);
3392 // ----------------------------------------------------------------------------
3394 // ----------------------------------------------------------------------------
3398 #include "wx/wfstream.h"
3399 #include "wx/mstream.h"
3401 static void TestFileStream()
3403 wxPuts(_T("*** Testing wxFileInputStream ***"));
3405 static const wxString filename
= _T("testdata.fs");
3407 wxFileOutputStream
fsOut(filename
);
3408 fsOut
.Write("foo", 3);
3411 wxFileInputStream
fsIn(filename
);
3412 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
3413 while ( !fsIn
.Eof() )
3415 wxPutchar(fsIn
.GetC());
3418 if ( !wxRemoveFile(filename
) )
3420 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
3423 wxPuts(_T("\n*** wxFileInputStream test done ***"));
3426 static void TestMemoryStream()
3428 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3430 wxMemoryOutputStream memOutStream
;
3431 wxPrintf(_T("Initially out stream offset: %lu\n"),
3432 (unsigned long)memOutStream
.TellO());
3434 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
3436 memOutStream
.PutC(*p
);
3439 wxPrintf(_T("Final out stream offset: %lu\n"),
3440 (unsigned long)memOutStream
.TellO());
3442 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
3445 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
3447 wxMemoryInputStream
memInpStream(buf
, len
);
3448 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3449 while ( !memInpStream
.Eof() )
3451 wxPutchar(memInpStream
.GetC());
3454 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
3457 #endif // TEST_STREAMS
3459 // ----------------------------------------------------------------------------
3461 // ----------------------------------------------------------------------------
3465 #include "wx/timer.h"
3466 #include "wx/utils.h"
3468 static void TestStopWatch()
3470 wxPuts(_T("*** Testing wxStopWatch ***\n"));
3474 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
3477 wxPrintf(_T("\t%ldms\n"), sw
.Time());
3479 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
3483 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3486 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
3489 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3492 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
3495 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3498 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
3499 for ( size_t n
= 0; n
< 70; n
++ )
3503 for ( size_t m
= 0; m
< 100000; m
++ )
3505 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3507 wxPuts(_T("\ntime is negative - ERROR!"));
3515 wxPuts(_T(", ok."));
3518 #endif // TEST_TIMER
3520 // ----------------------------------------------------------------------------
3522 // ----------------------------------------------------------------------------
3526 #include "wx/vcard.h"
3528 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3531 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3534 wxPrintf(_T("%s%s"),
3535 wxString(_T('\t'), level
).c_str(),
3536 vcObj
->GetName().c_str());
3539 switch ( vcObj
->GetType() )
3541 case wxVCardObject::String
:
3542 case wxVCardObject::UString
:
3545 vcObj
->GetValue(&val
);
3546 value
<< _T('"') << val
<< _T('"');
3550 case wxVCardObject::Int
:
3553 vcObj
->GetValue(&i
);
3554 value
.Printf(_T("%u"), i
);
3558 case wxVCardObject::Long
:
3561 vcObj
->GetValue(&l
);
3562 value
.Printf(_T("%lu"), l
);
3566 case wxVCardObject::None
:
3569 case wxVCardObject::Object
:
3570 value
= _T("<node>");
3574 value
= _T("<unknown value type>");
3578 wxPrintf(_T(" = %s"), value
.c_str());
3581 DumpVObject(level
+ 1, *vcObj
);
3584 vcObj
= vcard
.GetNextProp(&cookie
);
3588 static void DumpVCardAddresses(const wxVCard
& vcard
)
3590 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3594 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3598 int flags
= addr
->GetFlags();
3599 if ( flags
& wxVCardAddress::Domestic
)
3601 flagsStr
<< _T("domestic ");
3603 if ( flags
& wxVCardAddress::Intl
)
3605 flagsStr
<< _T("international ");
3607 if ( flags
& wxVCardAddress::Postal
)
3609 flagsStr
<< _T("postal ");
3611 if ( flags
& wxVCardAddress::Parcel
)
3613 flagsStr
<< _T("parcel ");
3615 if ( flags
& wxVCardAddress::Home
)
3617 flagsStr
<< _T("home ");
3619 if ( flags
& wxVCardAddress::Work
)
3621 flagsStr
<< _T("work ");
3624 wxPrintf(_T("Address %u:\n")
3626 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3629 addr
->GetPostOffice().c_str(),
3630 addr
->GetExtAddress().c_str(),
3631 addr
->GetStreet().c_str(),
3632 addr
->GetLocality().c_str(),
3633 addr
->GetRegion().c_str(),
3634 addr
->GetPostalCode().c_str(),
3635 addr
->GetCountry().c_str()
3639 addr
= vcard
.GetNextAddress(&cookie
);
3643 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3645 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3649 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3653 int flags
= phone
->GetFlags();
3654 if ( flags
& wxVCardPhoneNumber::Voice
)
3656 flagsStr
<< _T("voice ");
3658 if ( flags
& wxVCardPhoneNumber::Fax
)
3660 flagsStr
<< _T("fax ");
3662 if ( flags
& wxVCardPhoneNumber::Cellular
)
3664 flagsStr
<< _T("cellular ");
3666 if ( flags
& wxVCardPhoneNumber::Modem
)
3668 flagsStr
<< _T("modem ");
3670 if ( flags
& wxVCardPhoneNumber::Home
)
3672 flagsStr
<< _T("home ");
3674 if ( flags
& wxVCardPhoneNumber::Work
)
3676 flagsStr
<< _T("work ");
3679 wxPrintf(_T("Phone number %u:\n")
3684 phone
->GetNumber().c_str()
3688 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3692 static void TestVCardRead()
3694 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3696 wxVCard
vcard(_T("vcard.vcf"));
3697 if ( !vcard
.IsOk() )
3699 wxPuts(_T("ERROR: couldn't load vCard."));
3703 // read individual vCard properties
3704 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3708 vcObj
->GetValue(&value
);
3713 value
= _T("<none>");
3716 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3719 if ( !vcard
.GetFullName(&value
) )
3721 value
= _T("<none>");
3724 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3726 // now show how to deal with multiply occuring properties
3727 DumpVCardAddresses(vcard
);
3728 DumpVCardPhoneNumbers(vcard
);
3730 // and finally show all
3731 wxPuts(_T("\nNow dumping the entire vCard:\n")
3732 "-----------------------------\n");
3734 DumpVObject(0, vcard
);
3738 static void TestVCardWrite()
3740 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3743 if ( !vcard
.IsOk() )
3745 wxPuts(_T("ERROR: couldn't create vCard."));
3750 vcard
.SetName("Zeitlin", "Vadim");
3751 vcard
.SetFullName("Vadim Zeitlin");
3752 vcard
.SetOrganization("wxWindows", "R&D");
3754 // just dump the vCard back
3755 wxPuts(_T("Entire vCard follows:\n"));
3756 wxPuts(vcard
.Write());
3760 #endif // TEST_VCARD
3762 // ----------------------------------------------------------------------------
3764 // ----------------------------------------------------------------------------
3766 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3772 #include "wx/volume.h"
3774 static const wxChar
*volumeKinds
[] =
3780 _T("network volume"),
3784 static void TestFSVolume()
3786 wxPuts(_T("*** Testing wxFSVolume class ***"));
3788 wxArrayString volumes
= wxFSVolume::GetVolumes();
3789 size_t count
= volumes
.GetCount();
3793 wxPuts(_T("ERROR: no mounted volumes?"));
3797 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3799 for ( size_t n
= 0; n
< count
; n
++ )
3801 wxFSVolume
vol(volumes
[n
]);
3804 wxPuts(_T("ERROR: couldn't create volume"));
3808 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3810 vol
.GetDisplayName().c_str(),
3811 vol
.GetName().c_str(),
3812 volumeKinds
[vol
.GetKind()],
3813 vol
.IsWritable() ? _T("rw") : _T("ro"),
3814 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3819 #endif // TEST_VOLUME
3821 // ----------------------------------------------------------------------------
3822 // wide char and Unicode support
3823 // ----------------------------------------------------------------------------
3827 #include "wx/strconv.h"
3828 #include "wx/fontenc.h"
3829 #include "wx/encconv.h"
3830 #include "wx/buffer.h"
3832 static const unsigned char utf8koi8r
[] =
3834 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3835 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3836 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3837 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3838 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3839 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3840 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3843 static const unsigned char utf8iso8859_1
[] =
3845 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3846 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3847 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3848 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3849 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3852 static const unsigned char utf8Invalid
[] =
3854 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3855 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3856 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3857 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3861 static const struct Utf8Data
3863 const unsigned char *text
;
3865 const wxChar
*charset
;
3866 wxFontEncoding encoding
;
3869 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3870 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3871 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3874 static void TestUtf8()
3876 wxPuts(_T("*** Testing UTF8 support ***\n"));
3881 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3883 const Utf8Data
& u8d
= utf8data
[n
];
3884 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3885 WXSIZEOF(wbuf
)) == (size_t)-1 )
3887 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3891 wxCSConv
conv(u8d
.charset
);
3892 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3894 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3898 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3902 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3904 s
= _T("<< conversion failed >>");
3905 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3909 wxPuts(wxEmptyString
);
3912 static void TestEncodingConverter()
3914 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3916 // using wxEncodingConverter should give the same result as above
3919 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3920 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3922 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3926 wxEncodingConverter ec
;
3927 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3928 ec
.Convert(wbuf
, buf
);
3929 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3932 wxPuts(wxEmptyString
);
3935 #endif // TEST_WCHAR
3937 // ----------------------------------------------------------------------------
3939 // ----------------------------------------------------------------------------
3943 #include "wx/filesys.h"
3944 #include "wx/fs_zip.h"
3945 #include "wx/zipstrm.h"
3947 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3949 static void TestZipStreamRead()
3951 wxPuts(_T("*** Testing ZIP reading ***\n"));
3953 static const wxString filename
= _T("foo");
3954 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3955 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3957 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3958 while ( !istr
.Eof() )
3960 wxPutchar(istr
.GetC());
3964 wxPuts(_T("\n----- done ------"));
3967 static void DumpZipDirectory(wxFileSystem
& fs
,
3968 const wxString
& dir
,
3969 const wxString
& indent
)
3971 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3972 TESTFILE_ZIP
, dir
.c_str());
3973 wxString wildcard
= prefix
+ _T("/*");
3975 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3976 while ( !dirname
.empty() )
3978 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3980 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3985 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3987 DumpZipDirectory(fs
, dirname
,
3988 indent
+ wxString(_T(' '), 4));
3990 dirname
= fs
.FindNext();
3993 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3994 while ( !filename
.empty() )
3996 if ( !filename
.StartsWith(prefix
, &filename
) )
3998 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4003 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
4005 filename
= fs
.FindNext();
4009 static void TestZipFileSystem()
4011 wxPuts(_T("*** Testing ZIP file system ***\n"));
4013 wxFileSystem::AddHandler(new wxZipFSHandler
);
4015 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
4017 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
4022 // ----------------------------------------------------------------------------
4024 // ----------------------------------------------------------------------------
4026 #ifdef TEST_DATETIME
4030 #include "wx/datetime.h"
4035 wxDateTime::wxDateTime_t day
;
4036 wxDateTime::Month month
;
4038 wxDateTime::wxDateTime_t hour
, min
, sec
;
4040 wxDateTime::WeekDay wday
;
4041 time_t gmticks
, ticks
;
4043 void Init(const wxDateTime::Tm
& tm
)
4052 gmticks
= ticks
= -1;
4055 wxDateTime
DT() const
4056 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
4058 bool SameDay(const wxDateTime::Tm
& tm
) const
4060 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
4063 wxString
Format() const
4066 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
4068 wxDateTime::GetMonthName(month
).c_str(),
4070 abs(wxDateTime::ConvertYearToBC(year
)),
4071 year
> 0 ? _T("AD") : _T("BC"));
4075 wxString
FormatDate() const
4078 s
.Printf(_T("%02d-%s-%4d%s"),
4080 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4081 abs(wxDateTime::ConvertYearToBC(year
)),
4082 year
> 0 ? _T("AD") : _T("BC"));
4087 static const Date testDates
[] =
4089 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
4090 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
4091 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
4092 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
4093 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
4094 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
4095 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
4096 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
4097 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
4098 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
4099 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
4100 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
4101 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
4102 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
4103 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
4104 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
4105 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
4106 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
4107 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
4110 // this test miscellaneous static wxDateTime functions
4111 static void TestTimeStatic()
4113 wxPuts(_T("\n*** wxDateTime static methods test ***"));
4115 // some info about the current date
4116 int year
= wxDateTime::GetCurrentYear();
4117 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
4119 wxDateTime::IsLeapYear(year
) ? "" : "not ",
4120 wxDateTime::GetNumberOfDays(year
));
4122 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
4123 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
4124 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4125 wxDateTime::GetMonthName(month
).c_str(),
4126 wxDateTime::GetNumberOfDays(month
));
4129 static const size_t nYears
= 5;
4130 static const size_t years
[2][nYears
] =
4132 // first line: the years to test
4133 { 1990, 1976, 2000, 2030, 1984, },
4135 // second line: true if leap, false otherwise
4136 { false, true, true, false, true }
4139 for ( size_t n
= 0; n
< nYears
; n
++ )
4141 int year
= years
[0][n
];
4142 bool should
= years
[1][n
] != 0,
4143 is
= wxDateTime::IsLeapYear(year
);
4145 wxPrintf(_T("Year %d is %sa leap year (%s)\n"),
4148 should
== is
? "ok" : "ERROR");
4150 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
4154 // test constructing wxDateTime objects
4155 static void TestTimeSet()
4157 wxPuts(_T("\n*** wxDateTime construction test ***"));
4159 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4161 const Date
& d1
= testDates
[n
];
4162 wxDateTime dt
= d1
.DT();
4165 d2
.Init(dt
.GetTm());
4167 wxString s1
= d1
.Format(),
4170 wxPrintf(_T("Date: %s == %s (%s)\n"),
4171 s1
.c_str(), s2
.c_str(),
4172 s1
== s2
? _T("ok") : _T("ERROR"));
4176 // test time zones stuff
4177 static void TestTimeZones()
4179 wxPuts(_T("\n*** wxDateTime timezone test ***"));
4181 wxDateTime now
= wxDateTime::Now();
4183 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
4184 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
4185 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
4186 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
4187 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
4188 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
4190 wxDateTime::Tm tm
= now
.GetTm();
4191 if ( wxDateTime(tm
) != now
)
4193 wxPrintf(_T("ERROR: got %s instead of %s\n"),
4194 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
4198 // test some minimal support for the dates outside the standard range
4199 static void TestTimeRange()
4201 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
4203 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
4205 wxPrintf(_T("Unix epoch:\t%s\n"),
4206 wxDateTime(2440587.5).Format(fmt
).c_str());
4207 wxPrintf(_T("Feb 29, 0: \t%s\n"),
4208 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
4209 wxPrintf(_T("JDN 0: \t%s\n"),
4210 wxDateTime(0.0).Format(fmt
).c_str());
4211 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
4212 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
4213 wxPrintf(_T("May 29, 2099:\t%s\n"),
4214 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
4217 static void TestTimeTicks()
4219 wxPuts(_T("\n*** wxDateTime ticks test ***"));
4221 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4223 const Date
& d
= testDates
[n
];
4224 if ( d
.ticks
== -1 )
4227 wxDateTime dt
= d
.DT();
4228 long ticks
= (dt
.GetValue() / 1000).ToLong();
4229 wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4230 if ( ticks
== d
.ticks
)
4232 wxPuts(_T(" (ok)"));
4236 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4237 (long)d
.ticks
, (long)(ticks
- d
.ticks
));
4240 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
4241 ticks
= (dt
.GetValue() / 1000).ToLong();
4242 wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4243 if ( ticks
== d
.gmticks
)
4245 wxPuts(_T(" (ok)"));
4249 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4250 (long)d
.gmticks
, (long)(ticks
- d
.gmticks
));
4254 wxPuts(wxEmptyString
);
4257 // test conversions to JDN &c
4258 static void TestTimeJDN()
4260 wxPuts(_T("\n*** wxDateTime to JDN test ***"));
4262 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4264 const Date
& d
= testDates
[n
];
4265 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4266 double jdn
= dt
.GetJulianDayNumber();
4268 wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
);
4271 wxPuts(_T(" (ok)"));
4275 wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"),
4276 d
.jdn
, jdn
- d
.jdn
);
4281 // test week days computation
4282 static void TestTimeWDays()
4284 wxPuts(_T("\n*** wxDateTime weekday test ***"));
4286 // test GetWeekDay()
4288 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4290 const Date
& d
= testDates
[n
];
4291 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4293 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
4294 wxPrintf(_T("%s is: %s"),
4296 wxDateTime::GetWeekDayName(wday
).c_str());
4297 if ( wday
== d
.wday
)
4299 wxPuts(_T(" (ok)"));
4303 wxPrintf(_T(" (ERROR: should be %s)\n"),
4304 wxDateTime::GetWeekDayName(d
.wday
).c_str());
4308 wxPuts(wxEmptyString
);
4310 // test SetToWeekDay()
4311 struct WeekDateTestData
4313 Date date
; // the real date (precomputed)
4314 int nWeek
; // its week index in the month
4315 wxDateTime::WeekDay wday
; // the weekday
4316 wxDateTime::Month month
; // the month
4317 int year
; // and the year
4319 wxString
Format() const
4322 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
4324 case 1: which
= _T("first"); break;
4325 case 2: which
= _T("second"); break;
4326 case 3: which
= _T("third"); break;
4327 case 4: which
= _T("fourth"); break;
4328 case 5: which
= _T("fifth"); break;
4330 case -1: which
= _T("last"); break;
4335 which
+= _T(" from end");
4338 s
.Printf(_T("The %s %s of %s in %d"),
4340 wxDateTime::GetWeekDayName(wday
).c_str(),
4341 wxDateTime::GetMonthName(month
).c_str(),
4348 // the array data was generated by the following python program
4350 from DateTime import *
4351 from whrandom import *
4352 from string import *
4354 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4355 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4357 week = DateTimeDelta(7)
4360 year = randint(1900, 2100)
4361 month = randint(1, 12)
4362 day = randint(1, 28)
4363 dt = DateTime(year, month, day)
4364 wday = dt.day_of_week
4366 countFromEnd = choice([-1, 1])
4369 while dt.month is month:
4370 dt = dt - countFromEnd * week
4371 weekNum = weekNum + countFromEnd
4373 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
4375 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
4376 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
4379 static const WeekDateTestData weekDatesTestData
[] =
4381 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
4382 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
4383 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
4384 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
4385 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
4386 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
4387 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
4388 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
4389 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
4390 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
4391 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
4392 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
4393 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
4394 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
4395 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
4396 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
4397 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
4398 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
4399 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
4400 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
4403 static const wxChar
*fmt
= _T("%d-%b-%Y");
4406 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
4408 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
4410 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
4412 wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str());
4414 const Date
& d
= wd
.date
;
4415 if ( d
.SameDay(dt
.GetTm()) )
4417 wxPuts(_T(" (ok)"));
4421 dt
.Set(d
.day
, d
.month
, d
.year
);
4423 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str());
4428 // test the computation of (ISO) week numbers
4429 static void TestTimeWNumber()
4431 wxPuts(_T("\n*** wxDateTime week number test ***"));
4433 struct WeekNumberTestData
4435 Date date
; // the date
4436 wxDateTime::wxDateTime_t week
; // the week number in the year
4437 wxDateTime::wxDateTime_t wmon
; // the week number in the month
4438 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
4439 wxDateTime::wxDateTime_t dnum
; // day number in the year
4442 // data generated with the following python script:
4444 from DateTime import *
4445 from whrandom import *
4446 from string import *
4448 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4449 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4451 def GetMonthWeek(dt):
4452 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
4453 if weekNumMonth < 0:
4454 weekNumMonth = weekNumMonth + 53
4457 def GetLastSundayBefore(dt):
4458 if dt.iso_week[2] == 7:
4461 return dt - DateTimeDelta(dt.iso_week[2])
4464 year = randint(1900, 2100)
4465 month = randint(1, 12)
4466 day = randint(1, 28)
4467 dt = DateTime(year, month, day)
4468 dayNum = dt.day_of_year
4469 weekNum = dt.iso_week[1]
4470 weekNumMonth = GetMonthWeek(dt)
4473 dtSunday = GetLastSundayBefore(dt)
4475 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
4476 weekNumMonth2 = weekNumMonth2 + 1
4477 dtSunday = dtSunday - DateTimeDelta(7)
4479 data = { 'day': rjust(`day`, 2), \
4480 'month': monthNames[month - 1], \
4482 'weekNum': rjust(`weekNum`, 2), \
4483 'weekNumMonth': weekNumMonth, \
4484 'weekNumMonth2': weekNumMonth2, \
4485 'dayNum': rjust(`dayNum`, 3) }
4487 print " { { %(day)s, "\
4488 "wxDateTime::%(month)s, "\
4491 "%(weekNumMonth)s, "\
4492 "%(weekNumMonth2)s, "\
4493 "%(dayNum)s }," % data
4496 static const WeekNumberTestData weekNumberTestDates
[] =
4498 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
4499 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
4500 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
4501 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
4502 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
4503 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
4504 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
4505 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
4506 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
4507 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
4508 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
4509 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
4510 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
4511 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
4512 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
4513 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
4514 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
4515 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
4516 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
4517 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
4520 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
4522 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
4523 const Date
& d
= wn
.date
;
4525 wxDateTime dt
= d
.DT();
4527 wxDateTime::wxDateTime_t
4528 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
4529 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4530 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4531 dnum
= dt
.GetDayOfYear();
4533 wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
);
4534 if ( dnum
== wn
.dnum
)
4536 wxPrintf(_T(" (ok)"));
4540 wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
);
4543 wxPrintf(_T(", week in month = %d"), wmon
);
4544 if ( wmon
!= wn
.wmon
)
4546 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
);
4549 wxPrintf(_T(" or %d"), wmon2
);
4550 if ( wmon2
== wn
.wmon2
)
4552 wxPrintf(_T(" (ok)"));
4556 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
);
4559 wxPrintf(_T(", week in year = %d"), week
);
4560 if ( week
!= wn
.week
)
4562 wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
);
4565 wxPutchar(_T('\n'));
4567 wxDateTime
dt2(1, wxDateTime::Jan
, d
.year
);
4568 dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay());
4572 d2
.Init(dt2
.GetTm());
4573 wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"),
4574 d2
.FormatDate().c_str());
4579 // test DST calculations
4580 static void TestTimeDST()
4582 wxPuts(_T("\n*** wxDateTime DST test ***"));
4584 wxPrintf(_T("DST is%s in effect now.\n\n"),
4585 wxDateTime::Now().IsDST() ? wxEmptyString
: _T(" not"));
4587 // taken from http://www.energy.ca.gov/daylightsaving.html
4588 static const Date datesDST
[2][2004 - 1900 + 1] =
4591 { 1, wxDateTime::Apr
, 1990 },
4592 { 7, wxDateTime::Apr
, 1991 },
4593 { 5, wxDateTime::Apr
, 1992 },
4594 { 4, wxDateTime::Apr
, 1993 },
4595 { 3, wxDateTime::Apr
, 1994 },
4596 { 2, wxDateTime::Apr
, 1995 },
4597 { 7, wxDateTime::Apr
, 1996 },
4598 { 6, wxDateTime::Apr
, 1997 },
4599 { 5, wxDateTime::Apr
, 1998 },
4600 { 4, wxDateTime::Apr
, 1999 },
4601 { 2, wxDateTime::Apr
, 2000 },
4602 { 1, wxDateTime::Apr
, 2001 },
4603 { 7, wxDateTime::Apr
, 2002 },
4604 { 6, wxDateTime::Apr
, 2003 },
4605 { 4, wxDateTime::Apr
, 2004 },
4608 { 28, wxDateTime::Oct
, 1990 },
4609 { 27, wxDateTime::Oct
, 1991 },
4610 { 25, wxDateTime::Oct
, 1992 },
4611 { 31, wxDateTime::Oct
, 1993 },
4612 { 30, wxDateTime::Oct
, 1994 },
4613 { 29, wxDateTime::Oct
, 1995 },
4614 { 27, wxDateTime::Oct
, 1996 },
4615 { 26, wxDateTime::Oct
, 1997 },
4616 { 25, wxDateTime::Oct
, 1998 },
4617 { 31, wxDateTime::Oct
, 1999 },
4618 { 29, wxDateTime::Oct
, 2000 },
4619 { 28, wxDateTime::Oct
, 2001 },
4620 { 27, wxDateTime::Oct
, 2002 },
4621 { 26, wxDateTime::Oct
, 2003 },
4622 { 31, wxDateTime::Oct
, 2004 },
4627 for ( year
= 1990; year
< 2005; year
++ )
4629 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
4630 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
4632 wxPrintf(_T("DST period in the US for year %d: from %s to %s"),
4633 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
4635 size_t n
= year
- 1990;
4636 const Date
& dBegin
= datesDST
[0][n
];
4637 const Date
& dEnd
= datesDST
[1][n
];
4639 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
4641 wxPuts(_T(" (ok)"));
4645 wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"),
4646 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
4647 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
4651 wxPuts(wxEmptyString
);
4653 for ( year
= 1990; year
< 2005; year
++ )
4655 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
4657 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
4658 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
4662 // test wxDateTime -> text conversion
4663 static void TestTimeFormat()
4665 wxPuts(_T("\n*** wxDateTime formatting test ***"));
4667 // some information may be lost during conversion, so store what kind
4668 // of info should we recover after a round trip
4671 CompareNone
, // don't try comparing
4672 CompareBoth
, // dates and times should be identical
4673 CompareDate
, // dates only
4674 CompareTime
// time only
4679 CompareKind compareKind
;
4680 const wxChar
*format
;
4681 } formatTestFormats
[] =
4683 { CompareBoth
, _T("---> %c") },
4684 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
4685 { CompareBoth
, _T("Date is %x, time is %X") },
4686 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
4687 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
4688 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
4691 static const Date formatTestDates
[] =
4693 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
4694 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
4696 // this test can't work for other centuries because it uses two digit
4697 // years in formats, so don't even try it
4698 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
4699 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
4700 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
4704 // an extra test (as it doesn't depend on date, don't do it in the loop)
4705 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
4707 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
4709 wxPuts(wxEmptyString
);
4711 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
4712 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
4714 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
4715 wxPrintf(_T("%s"), s
.c_str());
4717 // what can we recover?
4718 int kind
= formatTestFormats
[n
].compareKind
;
4722 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
4725 // converion failed - should it have?
4726 if ( kind
== CompareNone
)
4727 wxPuts(_T(" (ok)"));
4729 wxPuts(_T(" (ERROR: conversion back failed)"));
4733 // should have parsed the entire string
4734 wxPuts(_T(" (ERROR: conversion back stopped too soon)"));
4738 bool equal
= false; // suppress compilaer warning
4746 equal
= dt
.IsSameDate(dt2
);
4750 equal
= dt
.IsSameTime(dt2
);
4756 wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"),
4757 dt2
.Format().c_str(), dt
.Format().c_str());
4761 wxPuts(_T(" (ok)"));
4768 // test text -> wxDateTime conversion
4769 static void TestTimeParse()
4771 wxPuts(_T("\n*** wxDateTime parse test ***"));
4773 struct ParseTestData
4775 const wxChar
*format
;
4780 static const ParseTestData parseTestDates
[] =
4782 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
4783 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
4786 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
4788 const wxChar
*format
= parseTestDates
[n
].format
;
4790 wxPrintf(_T("%s => "), format
);
4793 if ( dt
.ParseRfc822Date(format
) )
4795 wxPrintf(_T("%s "), dt
.Format().c_str());
4797 if ( parseTestDates
[n
].good
)
4799 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
4806 wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str());
4811 wxPuts(_T("(ERROR: bad format)"));
4816 wxPrintf(_T("bad format (%s)\n"),
4817 parseTestDates
[n
].good
? "ERROR" : "ok");
4822 static void TestDateTimeInteractive()
4824 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
4830 wxPrintf(_T("Enter a date: "));
4831 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
4834 // kill the last '\n'
4835 buf
[wxStrlen(buf
) - 1] = 0;
4838 const wxChar
*p
= dt
.ParseDate(buf
);
4841 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
4847 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
4850 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
4851 dt
.Format(_T("%b %d, %Y")).c_str(),
4853 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4854 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4855 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
4858 wxPuts(_T("\n*** done ***"));
4861 static void TestTimeMS()
4863 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
4865 wxDateTime dt1
= wxDateTime::Now(),
4866 dt2
= wxDateTime::UNow();
4868 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
4869 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
4870 wxPrintf(_T("Dummy loop: "));
4871 for ( int i
= 0; i
< 6000; i
++ )
4873 //for ( int j = 0; j < 10; j++ )
4876 s
.Printf(_T("%g"), sqrt(i
));
4882 wxPuts(_T(", done"));
4885 dt2
= wxDateTime::UNow();
4886 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
4888 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
4890 wxPuts(_T("\n*** done ***"));
4893 static void TestTimeArithmetics()
4895 wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***"));
4897 static const struct ArithmData
4899 ArithmData(const wxDateSpan
& sp
, const wxChar
*nam
)
4900 : span(sp
), name(nam
) { }
4904 } testArithmData
[] =
4906 ArithmData(wxDateSpan::Day(), _T("day")),
4907 ArithmData(wxDateSpan::Week(), _T("week")),
4908 ArithmData(wxDateSpan::Month(), _T("month")),
4909 ArithmData(wxDateSpan::Year(), _T("year")),
4910 ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")),
4913 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
4915 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
4917 wxDateSpan span
= testArithmData
[n
].span
;
4921 const wxChar
*name
= testArithmData
[n
].name
;
4922 wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"),
4923 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
4924 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
4926 wxPrintf(_T("Going back: %s"), (dt1
- span
).FormatISODate().c_str());
4927 if ( dt1
- span
== dt
)
4929 wxPuts(_T(" (ok)"));
4933 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
4936 wxPrintf(_T("Going forward: %s"), (dt2
+ span
).FormatISODate().c_str());
4937 if ( dt2
+ span
== dt
)
4939 wxPuts(_T(" (ok)"));
4943 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
4946 wxPrintf(_T("Double increment: %s"), (dt2
+ 2*span
).FormatISODate().c_str());
4947 if ( dt2
+ 2*span
== dt1
)
4949 wxPuts(_T(" (ok)"));
4953 wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str());
4956 wxPuts(wxEmptyString
);
4960 static void TestTimeHolidays()
4962 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
4964 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
4965 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
4966 dtEnd
= dtStart
.GetLastMonthDay();
4968 wxDateTimeArray hol
;
4969 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
4971 const wxChar
*format
= _T("%d-%b-%Y (%a)");
4973 wxPrintf(_T("All holidays between %s and %s:\n"),
4974 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
4976 size_t count
= hol
.GetCount();
4977 for ( size_t n
= 0; n
< count
; n
++ )
4979 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
4982 wxPuts(wxEmptyString
);
4985 static void TestTimeZoneBug()
4987 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
4989 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
4990 for ( int i
= 0; i
< 31; i
++ )
4992 wxPrintf(_T("Date %s: week day %s.\n"),
4993 date
.Format(_T("%d-%m-%Y")).c_str(),
4994 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
4996 date
+= wxDateSpan::Day();
4999 wxPuts(wxEmptyString
);
5002 static void TestTimeSpanFormat()
5004 wxPuts(_T("\n*** wxTimeSpan tests ***"));
5006 static const wxChar
*formats
[] =
5008 _T("(default) %H:%M:%S"),
5009 _T("%E weeks and %D days"),
5010 _T("%l milliseconds"),
5011 _T("(with ms) %H:%M:%S:%l"),
5012 _T("100%% of minutes is %M"), // test "%%"
5013 _T("%D days and %H hours"),
5014 _T("or also %S seconds"),
5017 wxTimeSpan
ts1(1, 2, 3, 4),
5019 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
5021 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
5022 ts1
.Format(formats
[n
]).c_str(),
5023 ts2
.Format(formats
[n
]).c_str());
5026 wxPuts(wxEmptyString
);
5029 #endif // TEST_DATETIME
5031 // ----------------------------------------------------------------------------
5032 // wxTextInput/OutputStream
5033 // ----------------------------------------------------------------------------
5035 #ifdef TEST_TEXTSTREAM
5037 #include "wx/txtstrm.h"
5038 #include "wx/wfstream.h"
5040 static void TestTextInputStream()
5042 wxPuts(_T("\n*** wxTextInputStream test ***"));
5044 wxString filename
= _T("testdata.fc");
5045 wxFileInputStream
fsIn(filename
);
5048 wxPuts(_T("ERROR: couldn't open file."));
5052 wxTextInputStream
tis(fsIn
);
5057 const wxString s
= tis
.ReadLine();
5059 // line could be non empty if the last line of the file isn't
5060 // terminated with EOL
5061 if ( fsIn
.Eof() && s
.empty() )
5064 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
5069 #endif // TEST_TEXTSTREAM
5071 // ----------------------------------------------------------------------------
5073 // ----------------------------------------------------------------------------
5077 #include "wx/thread.h"
5079 static size_t gs_counter
= (size_t)-1;
5080 static wxCriticalSection gs_critsect
;
5081 static wxSemaphore gs_cond
;
5083 class MyJoinableThread
: public wxThread
5086 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
5087 { m_n
= n
; Create(); }
5089 // thread execution starts here
5090 virtual ExitCode
Entry();
5096 wxThread::ExitCode
MyJoinableThread::Entry()
5098 unsigned long res
= 1;
5099 for ( size_t n
= 1; n
< m_n
; n
++ )
5103 // it's a loooong calculation :-)
5107 return (ExitCode
)res
;
5110 class MyDetachedThread
: public wxThread
5113 MyDetachedThread(size_t n
, wxChar ch
)
5117 m_cancelled
= false;
5122 // thread execution starts here
5123 virtual ExitCode
Entry();
5126 virtual void OnExit();
5129 size_t m_n
; // number of characters to write
5130 wxChar m_ch
; // character to write
5132 bool m_cancelled
; // false if we exit normally
5135 wxThread::ExitCode
MyDetachedThread::Entry()
5138 wxCriticalSectionLocker
lock(gs_critsect
);
5139 if ( gs_counter
== (size_t)-1 )
5145 for ( size_t n
= 0; n
< m_n
; n
++ )
5147 if ( TestDestroy() )
5157 wxThread::Sleep(100);
5163 void MyDetachedThread::OnExit()
5165 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
5167 wxCriticalSectionLocker
lock(gs_critsect
);
5168 if ( !--gs_counter
&& !m_cancelled
)
5172 static void TestDetachedThreads()
5174 wxPuts(_T("\n*** Testing detached threads ***"));
5176 static const size_t nThreads
= 3;
5177 MyDetachedThread
*threads
[nThreads
];
5179 for ( n
= 0; n
< nThreads
; n
++ )
5181 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
5184 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
5185 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
5187 for ( n
= 0; n
< nThreads
; n
++ )
5192 // wait until all threads terminate
5195 wxPuts(wxEmptyString
);
5198 static void TestJoinableThreads()
5200 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
5202 // calc 10! in the background
5203 MyJoinableThread
thread(10);
5206 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
5207 (unsigned long)thread
.Wait());
5210 static void TestThreadSuspend()
5212 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
5214 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
5218 // this is for this demo only, in a real life program we'd use another
5219 // condition variable which would be signaled from wxThread::Entry() to
5220 // tell us that the thread really started running - but here just wait a
5221 // bit and hope that it will be enough (the problem is, of course, that
5222 // the thread might still not run when we call Pause() which will result
5224 wxThread::Sleep(300);
5226 for ( size_t n
= 0; n
< 3; n
++ )
5230 wxPuts(_T("\nThread suspended"));
5233 // don't sleep but resume immediately the first time
5234 wxThread::Sleep(300);
5236 wxPuts(_T("Going to resume the thread"));
5241 wxPuts(_T("Waiting until it terminates now"));
5243 // wait until the thread terminates
5246 wxPuts(wxEmptyString
);
5249 static void TestThreadDelete()
5251 // As above, using Sleep() is only for testing here - we must use some
5252 // synchronisation object instead to ensure that the thread is still
5253 // running when we delete it - deleting a detached thread which already
5254 // terminated will lead to a crash!
5256 wxPuts(_T("\n*** Testing thread delete function ***"));
5258 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
5262 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
5264 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
5268 wxThread::Sleep(300);
5272 wxPuts(_T("\nDeleted a running thread."));
5274 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
5278 wxThread::Sleep(300);
5284 wxPuts(_T("\nDeleted a sleeping thread."));
5286 MyJoinableThread
thread3(20);
5291 wxPuts(_T("\nDeleted a joinable thread."));
5293 MyJoinableThread
thread4(2);
5296 wxThread::Sleep(300);
5300 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
5302 wxPuts(wxEmptyString
);
5305 class MyWaitingThread
: public wxThread
5308 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
5311 m_condition
= condition
;
5316 virtual ExitCode
Entry()
5318 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
5323 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
5327 m_condition
->Wait();
5330 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
5338 wxCondition
*m_condition
;
5341 static void TestThreadConditions()
5344 wxCondition
condition(mutex
);
5346 // otherwise its difficult to understand which log messages pertain to
5348 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
5349 // condition.GetId(), gs_cond.GetId());
5351 // create and launch threads
5352 MyWaitingThread
*threads
[10];
5355 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
5357 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
5360 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
5365 // wait until all threads run
5366 wxPuts(_T("Main thread is waiting for the other threads to start"));
5369 size_t nRunning
= 0;
5370 while ( nRunning
< WXSIZEOF(threads
) )
5376 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
5380 wxPuts(_T("Main thread: all threads started up."));
5383 wxThread::Sleep(500);
5386 // now wake one of them up
5387 wxPrintf(_T("Main thread: about to signal the condition.\n"));
5392 wxThread::Sleep(200);
5394 // wake all the (remaining) threads up, so that they can exit
5395 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
5397 condition
.Broadcast();
5399 // give them time to terminate (dirty!)
5400 wxThread::Sleep(500);
5403 #include "wx/utils.h"
5405 class MyExecThread
: public wxThread
5408 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
5414 virtual ExitCode
Entry()
5416 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
5423 static void TestThreadExec()
5425 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
5427 MyExecThread
thread(_T("true"));
5430 wxPrintf(_T("Main program exit code: %ld.\n"),
5431 wxExecute(_T("false"), wxEXEC_SYNC
));
5433 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
5437 #include "wx/datetime.h"
5439 class MySemaphoreThread
: public wxThread
5442 MySemaphoreThread(int i
, wxSemaphore
*sem
)
5443 : wxThread(wxTHREAD_JOINABLE
),
5450 virtual ExitCode
Entry()
5452 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
5453 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5457 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
5458 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5462 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
5463 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5475 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
5477 static void TestSemaphore()
5479 wxPuts(_T("*** Testing wxSemaphore class. ***"));
5481 static const int SEM_LIMIT
= 3;
5483 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
5484 ArrayThreads threads
;
5486 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
5488 threads
.Add(new MySemaphoreThread(i
, &sem
));
5489 threads
.Last()->Run();
5492 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
5499 #endif // TEST_THREADS
5501 // ----------------------------------------------------------------------------
5503 // ----------------------------------------------------------------------------
5505 #ifdef TEST_SNGLINST
5506 #include "wx/snglinst.h"
5507 #endif // TEST_SNGLINST
5509 int main(int argc
, char **argv
)
5511 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
5513 wxInitializer initializer
;
5516 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
5521 #ifdef TEST_SNGLINST
5522 wxSingleInstanceChecker checker
;
5523 if ( checker
.Create(_T(".wxconsole.lock")) )
5525 if ( checker
.IsAnotherRunning() )
5527 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
5532 // wait some time to give time to launch another instance
5533 wxPrintf(_T("Press \"Enter\" to continue..."));
5536 else // failed to create
5538 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
5540 #endif // TEST_SNGLINST
5544 #endif // TEST_CHARSET
5547 TestCmdLineConvert();
5549 #if wxUSE_CMDLINE_PARSER
5550 static const wxCmdLineEntryDesc cmdLineDesc
[] =
5552 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"),
5553 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
5554 { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") },
5555 { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"), _T("be quiet") },
5557 { wxCMD_LINE_OPTION
, _T("o"), _T("output"), _T("output file") },
5558 { wxCMD_LINE_OPTION
, _T("i"), _T("input"), _T("input dir") },
5559 { wxCMD_LINE_OPTION
, _T("s"), _T("size"), _T("output block size"),
5560 wxCMD_LINE_VAL_NUMBER
},
5561 { wxCMD_LINE_OPTION
, _T("d"), _T("date"), _T("output file date"),
5562 wxCMD_LINE_VAL_DATE
},
5564 { wxCMD_LINE_PARAM
, NULL
, NULL
, _T("input file"),
5565 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
5571 wxChar
**wargv
= new wxChar
*[argc
+ 1];
5576 for (n
= 0; n
< argc
; n
++ )
5578 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
5579 wargv
[n
] = wxStrdup(warg
);
5586 #endif // wxUSE_UNICODE
5588 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
5592 for ( int n
= 0; n
< argc
; n
++ )
5597 #endif // wxUSE_UNICODE
5599 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
5600 wxCMD_LINE_VAL_STRING
,
5601 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
5603 switch ( parser
.Parse() )
5606 wxLogMessage(_T("Help was given, terminating."));
5610 ShowCmdLine(parser
);
5614 wxLogMessage(_T("Syntax error detected, aborting."));
5617 #endif // wxUSE_CMDLINE_PARSER
5619 #endif // TEST_CMDLINE
5629 #ifdef TEST_DLLLOADER
5631 #endif // TEST_DLLLOADER
5635 #endif // TEST_ENVIRON
5639 #endif // TEST_EXECUTE
5641 #ifdef TEST_FILECONF
5643 #endif // TEST_FILECONF
5652 #endif // TEST_LOCALE
5655 wxPuts(_T("*** Testing wxLog ***"));
5658 for ( size_t n
= 0; n
< 8000; n
++ )
5660 s
<< (wxChar
)(_T('A') + (n
% 26));
5663 wxLogWarning(_T("The length of the string is %lu"),
5664 (unsigned long)s
.length());
5667 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
5669 // this one shouldn't be truncated
5672 // but this one will because log functions use fixed size buffer
5673 // (note that it doesn't need '\n' at the end neither - will be added
5675 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
5684 #ifdef TEST_FILENAME
5685 TestFileNameConstruction();
5686 TestFileNameMakeRelative();
5687 TestFileNameMakeAbsolute();
5688 TestFileNameSplit();
5691 TestFileNameDirManip();
5692 TestFileNameComparison();
5693 TestFileNameOperations();
5694 #endif // TEST_FILENAME
5696 #ifdef TEST_FILETIME
5701 #endif // TEST_FILETIME
5704 wxLog::AddTraceMask(FTP_TRACE_MASK
);
5705 if ( TestFtpConnect() )
5715 #if TEST_INTERACTIVE
5716 TestFtpInteractive();
5719 //else: connecting to the FTP server failed
5732 #endif // TEST_HASHMAP
5736 #endif // TEST_HASHSET
5739 wxLog::AddTraceMask(_T("mime"));
5743 TestMimeAssociate();
5748 #ifdef TEST_INFO_FUNCTIONS
5753 #if TEST_INTERACTIVE
5757 #endif // TEST_INFO_FUNCTIONS
5759 #ifdef TEST_PATHLIST
5761 #endif // TEST_PATHLIST
5769 #endif // TEST_PRINTF
5776 #endif // TEST_REGCONF
5778 #if defined TEST_REGEX && TEST_INTERACTIVE
5779 TestRegExInteractive();
5780 #endif // defined TEST_REGEX && TEST_INTERACTIVE
5782 #ifdef TEST_REGISTRY
5784 TestRegistryAssociation();
5785 #endif // TEST_REGISTRY
5790 #endif // TEST_SOCKETS
5797 #endif // TEST_STREAMS
5799 #ifdef TEST_TEXTSTREAM
5800 TestTextInputStream();
5801 #endif // TEST_TEXTSTREAM
5804 int nCPUs
= wxThread::GetCPUCount();
5805 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
5807 wxThread::SetConcurrency(nCPUs
);
5809 TestJoinableThreads();
5812 TestJoinableThreads();
5813 TestDetachedThreads();
5814 TestThreadSuspend();
5816 TestThreadConditions();
5820 #endif // TEST_THREADS
5824 #endif // TEST_TIMER
5826 #ifdef TEST_DATETIME
5838 TestTimeArithmetics();
5841 TestTimeSpanFormat();
5847 #if TEST_INTERACTIVE
5848 TestDateTimeInteractive();
5850 #endif // TEST_DATETIME
5852 #ifdef TEST_SCOPEGUARD
5857 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
5859 #endif // TEST_USLEEP
5864 #endif // TEST_VCARD
5868 #endif // TEST_VOLUME
5872 TestEncodingConverter();
5873 #endif // TEST_WCHAR
5876 TestZipStreamRead();
5877 TestZipFileSystem();