1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
23 #error "This sample can't be compiled in GUI mode."
28 #include "wx/string.h"
33 // without this pragma, the stupid compiler precompiles #defines below so that
34 // changing them doesn't "take place" later!
39 // ----------------------------------------------------------------------------
40 // conditional compilation
41 // ----------------------------------------------------------------------------
44 A note about all these conditional compilation macros: this file is used
45 both as a test suite for various non-GUI wxWindows classes and as a
46 scratchpad for quick tests. So there are two compilation modes: if you
47 define TEST_ALL all tests are run, otherwise you may enable the individual
48 tests individually in the "#else" branch below.
51 // what to test (in alphabetic order)? uncomment the line below to do all tests
59 #define TEST_DLLLOADER
69 #define TEST_INFO_FUNCTIONS
81 #define TEST_SCOPEGUARD
86 #define TEST_TEXTSTREAM
90 // #define TEST_VCARD -- don't enable this (VZ)
97 static const bool TEST_ALL
= true;
102 #define TEST_SCOPEGUARD
104 static const bool TEST_ALL
= false;
107 // some tests are interactive, define this to run them
108 #ifdef TEST_INTERACTIVE
109 #undef TEST_INTERACTIVE
111 static const bool TEST_INTERACTIVE
= true;
113 static const bool TEST_INTERACTIVE
= false;
116 // ----------------------------------------------------------------------------
117 // test class for container objects
118 // ----------------------------------------------------------------------------
120 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
122 class Bar
// Foo is already taken in the hash test
125 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
126 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
127 ~Bar() { ms_bars
--; }
129 static size_t GetNumber() { return ms_bars
; }
131 const wxChar
*GetName() const { return m_name
; }
136 static size_t ms_bars
;
139 size_t Bar::ms_bars
= 0;
141 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
143 // ============================================================================
145 // ============================================================================
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
153 // replace TABs with \t and CRs with \n
154 static wxString
MakePrintable(const wxChar
*s
)
157 (void)str
.Replace(_T("\t"), _T("\\t"));
158 (void)str
.Replace(_T("\n"), _T("\\n"));
159 (void)str
.Replace(_T("\r"), _T("\\r"));
164 #endif // MakePrintable() is used
166 // ----------------------------------------------------------------------------
167 // wxFontMapper::CharsetToEncoding
168 // ----------------------------------------------------------------------------
172 #include "wx/fontmap.h"
174 static void TestCharset()
176 static const wxChar
*charsets
[] =
178 // some vali charsets
187 // and now some bogus ones
194 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
196 wxFontEncoding enc
= wxFontMapper::Get()->CharsetToEncoding(charsets
[n
]);
197 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
199 wxFontMapper::Get()->GetEncodingName(enc
).c_str(),
200 wxFontMapper::Get()->GetEncodingDescription(enc
).c_str());
204 #endif // TEST_CHARSET
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
212 #include "wx/cmdline.h"
213 #include "wx/datetime.h"
215 #if wxUSE_CMDLINE_PARSER
217 static void ShowCmdLine(const wxCmdLineParser
& parser
)
219 wxString s
= _T("Input files: ");
221 size_t count
= parser
.GetParamCount();
222 for ( size_t param
= 0; param
< count
; param
++ )
224 s
<< parser
.GetParam(param
) << ' ';
228 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
229 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
234 if ( parser
.Found(_T("o"), &strVal
) )
235 s
<< _T("Output file:\t") << strVal
<< '\n';
236 if ( parser
.Found(_T("i"), &strVal
) )
237 s
<< _T("Input dir:\t") << strVal
<< '\n';
238 if ( parser
.Found(_T("s"), &lVal
) )
239 s
<< _T("Size:\t") << lVal
<< '\n';
240 if ( parser
.Found(_T("d"), &dt
) )
241 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
242 if ( parser
.Found(_T("project_name"), &strVal
) )
243 s
<< _T("Project:\t") << strVal
<< '\n';
248 #endif // wxUSE_CMDLINE_PARSER
250 static void TestCmdLineConvert()
252 static const wxChar
*cmdlines
[] =
255 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
256 _T("literal \\\" and \"\""),
259 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
261 const wxChar
*cmdline
= cmdlines
[n
];
262 wxPrintf(_T("Parsing: %s\n"), cmdline
);
263 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
265 size_t count
= args
.GetCount();
266 wxPrintf(_T("\targc = %u\n"), count
);
267 for ( size_t arg
= 0; arg
< count
; arg
++ )
269 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
274 #endif // TEST_CMDLINE
276 // ----------------------------------------------------------------------------
278 // ----------------------------------------------------------------------------
285 static const wxChar
*ROOTDIR
= _T("/");
286 static const wxChar
*TESTDIR
= _T("/usr/local/share");
287 #elif defined(__WXMSW__)
288 static const wxChar
*ROOTDIR
= _T("c:\\");
289 static const wxChar
*TESTDIR
= _T("d:\\");
291 #error "don't know where the root directory is"
294 static void TestDirEnumHelper(wxDir
& dir
,
295 int flags
= wxDIR_DEFAULT
,
296 const wxString
& filespec
= wxEmptyString
)
300 if ( !dir
.IsOpened() )
303 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
306 wxPrintf(_T("\t%s\n"), filename
.c_str());
308 cont
= dir
.GetNext(&filename
);
314 static void TestDirEnum()
316 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
318 wxString cwd
= wxGetCwd();
319 if ( !wxDir::Exists(cwd
) )
321 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
326 if ( !dir
.IsOpened() )
328 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
332 wxPuts(_T("Enumerating everything in current directory:"));
333 TestDirEnumHelper(dir
);
335 wxPuts(_T("Enumerating really everything in current directory:"));
336 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
338 wxPuts(_T("Enumerating object files in current directory:"));
339 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o*");
341 wxPuts(_T("Enumerating directories in current directory:"));
342 TestDirEnumHelper(dir
, wxDIR_DIRS
);
344 wxPuts(_T("Enumerating files in current directory:"));
345 TestDirEnumHelper(dir
, wxDIR_FILES
);
347 wxPuts(_T("Enumerating files including hidden in current directory:"));
348 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
352 wxPuts(_T("Enumerating everything in root directory:"));
353 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
355 wxPuts(_T("Enumerating directories in root directory:"));
356 TestDirEnumHelper(dir
, wxDIR_DIRS
);
358 wxPuts(_T("Enumerating files in root directory:"));
359 TestDirEnumHelper(dir
, wxDIR_FILES
);
361 wxPuts(_T("Enumerating files including hidden in root directory:"));
362 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
364 wxPuts(_T("Enumerating files in non existing directory:"));
365 wxDir
dirNo("nosuchdir");
366 TestDirEnumHelper(dirNo
);
369 class DirPrintTraverser
: public wxDirTraverser
372 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
374 return wxDIR_CONTINUE
;
377 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
379 wxString path
, name
, ext
;
380 wxSplitPath(dirname
, &path
, &name
, &ext
);
383 name
<< _T('.') << ext
;
386 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
388 if ( wxIsPathSeparator(*p
) )
392 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
394 return wxDIR_CONTINUE
;
398 static void TestDirTraverse()
400 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
404 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
405 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
408 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
409 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
412 // enum again with custom traverser
413 wxPuts(_T("Now enumerating directories:"));
415 DirPrintTraverser traverser
;
416 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
419 static void TestDirExists()
421 wxPuts(_T("*** Testing wxDir::Exists() ***"));
423 static const wxChar
*dirnames
[] =
426 #if defined(__WXMSW__)
429 _T("\\\\share\\file"),
433 _T("c:\\autoexec.bat"),
434 #elif defined(__UNIX__)
443 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
445 wxPrintf(_T("%-40s: %s\n"),
447 wxDir::Exists(dirnames
[n
]) ? _T("exists")
448 : _T("doesn't exist"));
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 #ifdef TEST_DLLLOADER
460 #include "wx/dynlib.h"
462 static void TestDllLoad()
464 #if defined(__WXMSW__)
465 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
466 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
467 #elif defined(__UNIX__)
468 // weird: using just libc.so does *not* work!
469 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
470 static const wxChar
*FUNC_NAME
= _T("strlen");
472 #error "don't know how to test wxDllLoader on this platform"
475 wxPuts(_T("*** testing wxDllLoader ***\n"));
477 wxDynamicLibrary
lib(LIB_NAME
);
478 if ( !lib
.IsLoaded() )
480 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
484 typedef int (*wxStrlenType
)(const char *);
485 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
488 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
489 FUNC_NAME
, LIB_NAME
);
493 if ( pfnStrlen("foo") != 3 )
495 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
499 wxPuts(_T("... ok"));
505 #endif // TEST_DLLLOADER
507 // ----------------------------------------------------------------------------
509 // ----------------------------------------------------------------------------
513 #include "wx/utils.h"
515 static wxString
MyGetEnv(const wxString
& var
)
518 if ( !wxGetEnv(var
, &val
) )
521 val
= wxString(_T('\'')) + val
+ _T('\'');
526 static void TestEnvironment()
528 const wxChar
*var
= _T("wxTestVar");
530 wxPuts(_T("*** testing environment access functions ***"));
532 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
533 wxSetEnv(var
, _T("value for wxTestVar"));
534 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
535 wxSetEnv(var
, _T("another value"));
536 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
538 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
539 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
542 #endif // TEST_ENVIRON
544 // ----------------------------------------------------------------------------
546 // ----------------------------------------------------------------------------
550 #include "wx/utils.h"
552 static void TestExecute()
554 wxPuts(_T("*** testing wxExecute ***"));
557 #define COMMAND "cat -n ../../Makefile" // "echo hi"
558 #define SHELL_COMMAND "echo hi from shell"
559 #define REDIRECT_COMMAND COMMAND // "date"
560 #elif defined(__WXMSW__)
561 #define COMMAND "command.com /c echo hi"
562 #define SHELL_COMMAND "echo hi"
563 #define REDIRECT_COMMAND COMMAND
565 #error "no command to exec"
568 wxPrintf(_T("Testing wxShell: "));
570 if ( wxShell(SHELL_COMMAND
) )
573 wxPuts(_T("ERROR."));
575 wxPrintf(_T("Testing wxExecute: "));
577 if ( wxExecute(COMMAND
, true /* sync */) == 0 )
580 wxPuts(_T("ERROR."));
582 #if 0 // no, it doesn't work (yet?)
583 wxPrintf(_T("Testing async wxExecute: "));
585 if ( wxExecute(COMMAND
) != 0 )
586 wxPuts(_T("Ok (command launched)."));
588 wxPuts(_T("ERROR."));
591 wxPrintf(_T("Testing wxExecute with redirection:\n"));
592 wxArrayString output
;
593 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
595 wxPuts(_T("ERROR."));
599 size_t count
= output
.GetCount();
600 for ( size_t n
= 0; n
< count
; n
++ )
602 wxPrintf(_T("\t%s\n"), output
[n
].c_str());
609 #endif // TEST_EXECUTE
611 // ----------------------------------------------------------------------------
613 // ----------------------------------------------------------------------------
618 #include "wx/ffile.h"
619 #include "wx/textfile.h"
621 static void TestFileRead()
623 wxPuts(_T("*** wxFile read test ***"));
625 wxFile
file(_T("testdata.fc"));
626 if ( file
.IsOpened() )
628 wxPrintf(_T("File length: %lu\n"), file
.Length());
630 wxPuts(_T("File dump:\n----------"));
632 static const off_t len
= 1024;
636 off_t nRead
= file
.Read(buf
, len
);
637 if ( nRead
== wxInvalidOffset
)
639 wxPrintf(_T("Failed to read the file."));
643 fwrite(buf
, nRead
, 1, stdout
);
649 wxPuts(_T("----------"));
653 wxPrintf(_T("ERROR: can't open test file.\n"));
659 static void TestTextFileRead()
661 wxPuts(_T("*** wxTextFile read test ***"));
663 wxTextFile
file(_T("testdata.fc"));
666 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
667 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
671 wxPuts(_T("\nDumping the entire file:"));
672 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
674 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
676 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
678 wxPuts(_T("\nAnd now backwards:"));
679 for ( s
= file
.GetLastLine();
680 file
.GetCurrentLine() != 0;
681 s
= file
.GetPrevLine() )
683 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
685 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
689 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
695 static void TestFileCopy()
697 wxPuts(_T("*** Testing wxCopyFile ***"));
699 static const wxChar
*filename1
= _T("testdata.fc");
700 static const wxChar
*filename2
= _T("test2");
701 if ( !wxCopyFile(filename1
, filename2
) )
703 wxPuts(_T("ERROR: failed to copy file"));
707 wxFFile
f1(filename1
, "rb"),
710 if ( !f1
.IsOpened() || !f2
.IsOpened() )
712 wxPuts(_T("ERROR: failed to open file(s)"));
717 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
719 wxPuts(_T("ERROR: failed to read file(s)"));
723 if ( (s1
.length() != s2
.length()) ||
724 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
726 wxPuts(_T("ERROR: copy error!"));
730 wxPuts(_T("File was copied ok."));
736 if ( !wxRemoveFile(filename2
) )
738 wxPuts(_T("ERROR: failed to remove the file"));
746 // ----------------------------------------------------------------------------
748 // ----------------------------------------------------------------------------
752 #include "wx/confbase.h"
753 #include "wx/fileconf.h"
755 static const struct FileConfTestData
757 const wxChar
*name
; // value name
758 const wxChar
*value
; // the value from the file
761 { _T("value1"), _T("one") },
762 { _T("value2"), _T("two") },
763 { _T("novalue"), _T("default") },
766 static void TestFileConfRead()
768 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
770 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
771 _T("testdata.fc"), wxEmptyString
,
772 wxCONFIG_USE_RELATIVE_PATH
);
774 // test simple reading
775 wxPuts(_T("\nReading config file:"));
776 wxString
defValue(_T("default")), value
;
777 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
779 const FileConfTestData
& data
= fcTestData
[n
];
780 value
= fileconf
.Read(data
.name
, defValue
);
781 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
782 if ( value
== data
.value
)
788 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
792 // test enumerating the entries
793 wxPuts(_T("\nEnumerating all root entries:"));
796 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
799 wxPrintf(_T("\t%s = %s\n"),
801 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
803 cont
= fileconf
.GetNextEntry(name
, dummy
);
806 static const wxChar
*testEntry
= _T("TestEntry");
807 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
808 fileconf
.Write(testEntry
, _T("A value"));
809 fileconf
.DeleteEntry(testEntry
);
810 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
813 #endif // TEST_FILECONF
815 // ----------------------------------------------------------------------------
817 // ----------------------------------------------------------------------------
821 #include "wx/filename.h"
823 static void DumpFileName(const wxFileName
& fn
)
825 wxString full
= fn
.GetFullPath();
827 wxString vol
, path
, name
, ext
;
828 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
830 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
831 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
833 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
834 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
835 path
.c_str(), name
.c_str(), ext
.c_str());
837 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
838 wxPrintf(_T("with volume: \t'%s'\n"),
839 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
840 wxPrintf(_T("with separator:\t'%s'\n"),
841 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
842 wxPrintf(_T("with both: \t'%s'\n"),
843 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
845 wxPuts(_T("The directories in the path are:"));
846 wxArrayString dirs
= fn
.GetDirs();
847 size_t count
= dirs
.GetCount();
848 for ( size_t n
= 0; n
< count
; n
++ )
850 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
854 static struct FileNameInfo
856 const wxChar
*fullname
;
857 const wxChar
*volume
;
866 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX
},
867 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX
},
868 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX
},
869 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX
},
870 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
871 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX
},
872 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX
},
873 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
874 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX
},
876 // Windows file names
877 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
878 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS
},
879 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
880 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
881 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS
},
882 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
883 { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
885 // wxFileName support for Mac file names is broken currently
888 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC
},
889 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC
},
890 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC
},
891 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC
},
892 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
893 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
897 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS
},
898 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS
},
901 static void TestFileNameConstruction()
903 wxPuts(_T("*** testing wxFileName construction ***"));
905 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
907 const FileNameInfo
& fni
= filenames
[n
];
909 wxFileName
fn(fni
.fullname
, fni
.format
);
911 wxString fullname
= fn
.GetFullPath(fni
.format
);
912 if ( fullname
!= fni
.fullname
)
914 wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni
.fullname
);
917 bool isAbsolute
= fn
.IsAbsolute(fni
.format
);
918 wxPrintf(_T("'%s' is %s (%s)\n\t"),
920 isAbsolute
? "absolute" : "relative",
921 isAbsolute
== fni
.isAbsolute
? "ok" : "ERROR");
923 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) )
925 wxPuts(_T("ERROR (couldn't be normalized)"));
929 wxPrintf(_T("normalized: '%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
936 static void TestFileNameSplit()
938 wxPuts(_T("*** testing wxFileName splitting ***"));
940 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
942 const FileNameInfo
& fni
= filenames
[n
];
943 wxString volume
, path
, name
, ext
;
944 wxFileName::SplitPath(fni
.fullname
,
945 &volume
, &path
, &name
, &ext
, fni
.format
);
947 wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"),
949 volume
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
951 if ( volume
!= fni
.volume
)
952 wxPrintf(_T(" (ERROR: volume = '%s')"), fni
.volume
);
953 if ( path
!= fni
.path
)
954 wxPrintf(_T(" (ERROR: path = '%s')"), fni
.path
);
955 if ( name
!= fni
.name
)
956 wxPrintf(_T(" (ERROR: name = '%s')"), fni
.name
);
957 if ( ext
!= fni
.ext
)
958 wxPrintf(_T(" (ERROR: ext = '%s')"), fni
.ext
);
964 static void TestFileNameTemp()
966 wxPuts(_T("*** testing wxFileName temp file creation ***"));
968 static const wxChar
*tmpprefixes
[] =
976 _T("/tmp/foo/bar"), // this one must be an error
980 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
982 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
985 // "error" is not in upper case because it may be ok
986 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
990 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
991 tmpprefixes
[n
], path
.c_str());
993 if ( !wxRemoveFile(path
) )
995 wxLogWarning(_T("Failed to remove temp file '%s'"),
1002 static void TestFileNameMakeRelative()
1004 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
1006 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1008 const FileNameInfo
& fni
= filenames
[n
];
1010 wxFileName
fn(fni
.fullname
, fni
.format
);
1012 // choose the base dir of the same format
1014 switch ( fni
.format
)
1026 // TODO: I don't know how this is supposed to work there
1029 case wxPATH_NATIVE
: // make gcc happy
1031 wxFAIL_MSG( "unexpected path format" );
1034 wxPrintf(_T("'%s' relative to '%s': "),
1035 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
1037 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
1039 wxPuts(_T("unchanged"));
1043 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
1048 static void TestFileNameMakeAbsolute()
1050 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
1052 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1054 const FileNameInfo
& fni
= filenames
[n
];
1055 wxFileName
fn(fni
.fullname
, fni
.format
);
1057 wxPrintf(_T("'%s' absolutized: "),
1058 fn
.GetFullPath(fni
.format
).c_str());
1060 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
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());
1112 static void TestFileSetTimes()
1114 wxFileName
fn(_T("testdata.fc"));
1118 wxPrintf(_T("ERROR: Touch() failed.\n"));
1122 #endif // TEST_FILETIME
1124 // ----------------------------------------------------------------------------
1126 // ----------------------------------------------------------------------------
1130 #include "wx/hash.h"
1134 Foo(int n_
) { n
= n_
; count
++; }
1139 static size_t count
;
1142 size_t Foo::count
= 0;
1144 WX_DECLARE_LIST(Foo
, wxListFoos
);
1145 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
1147 #include "wx/listimpl.cpp"
1149 WX_DEFINE_LIST(wxListFoos
);
1151 static void TestHash()
1153 wxPuts(_T("*** Testing wxHashTable ***\n"));
1156 wxHashTable
hash(wxKEY_INTEGER
), hash2(wxKEY_STRING
);
1159 for ( i
= 0; i
< 100; ++i
)
1160 hash
.Put(i
, (wxObject
*)&i
+ i
);
1163 wxHashTable::compatibility_iterator it
= hash
.Next();
1173 wxPuts(_T("Error in wxHashTable::compatibility_iterator\n"));
1175 for ( i
= 99; i
>= 0; --i
)
1176 if( hash
.Get(i
) != (wxObject
*)&i
+ i
)
1177 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1179 hash2
.Put("foo", (wxObject
*)&i
+ 1);
1180 hash2
.Put("bar", (wxObject
*)&i
+ 2);
1181 hash2
.Put("baz", (wxObject
*)&i
+ 3);
1183 if (hash2
.Get("moo") != NULL
)
1184 wxPuts(_T("Error in wxHashTable::Get\n"));
1186 if (hash2
.Get("bar") != (wxObject
*)&i
+ 2)
1187 wxPuts(_T("Error in wxHashTable::Get/Put\n"));
1192 hash
.DeleteContents(true);
1194 wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"),
1195 hash
.GetCount(), Foo::count
);
1197 static const int hashTestData
[] =
1199 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
1203 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1205 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
1208 wxPrintf(_T("Hash filled: %u foos in hash, %u foos totally\n"),
1209 hash
.GetCount(), Foo::count
);
1211 wxPuts(_T("Hash access test:"));
1212 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
1214 wxPrintf(_T("\tGetting element with key %d, value %d: "),
1215 hashTestData
[n
], n
);
1216 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
1219 wxPrintf(_T("ERROR, not found.\n"));
1223 wxPrintf(_T("%d (%s)\n"), foo
->n
,
1224 (size_t)foo
->n
== n
? "ok" : "ERROR");
1228 wxPrintf(_T("\nTrying to get an element not in hash: "));
1230 if ( hash
.Get(1234) || hash
.Get(1, 0) )
1232 wxPuts(_T("ERROR: found!"));
1236 wxPuts(_T("ok (not found)"));
1241 wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count
);
1242 wxPuts(_T("*** Testing wxHashTable finished ***\n"));
1247 // ----------------------------------------------------------------------------
1249 // ----------------------------------------------------------------------------
1253 #include "wx/hashmap.h"
1255 // test compilation of basic map types
1256 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
1257 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
1258 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
1259 myUnsignedHashMap
);
1260 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1262 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
1264 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1266 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
1270 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
1271 // myStringHashMap );
1272 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
1274 typedef myStringHashMap::iterator Itor
;
1276 static void TestHashMap()
1278 wxPuts(_T("*** Testing wxHashMap ***\n"));
1279 myStringHashMap
sh(0); // as small as possible
1282 const size_t count
= 10000;
1284 // init with some data
1285 for( i
= 0; i
< count
; ++i
)
1287 buf
.Printf(wxT("%d"), i
);
1288 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1291 // test that insertion worked
1292 if( sh
.size() != count
)
1294 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
);
1297 for( i
= 0; i
< count
; ++i
)
1299 buf
.Printf(wxT("%d"), i
);
1300 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1302 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
1307 // check that iterators work
1309 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1313 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
1317 if( it
->second
!= sh
[it
->first
] )
1319 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
1324 if( sh
.size() != i
)
1326 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
);
1329 // test copy ctor, assignment operator
1330 myStringHashMap
h1( sh
), h2( 0 );
1333 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1335 if( h1
[it
->first
] != it
->second
)
1337 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str());
1340 if( h2
[it
->first
] != it
->second
)
1342 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str());
1347 for( i
= 0; i
< count
; ++i
)
1349 buf
.Printf(wxT("%d"), i
);
1350 size_t sz
= sh
.size();
1352 // test find() and erase(it)
1355 it
= sh
.find( buf
);
1356 if( it
!= sh
.end() )
1360 if( sh
.find( buf
) != sh
.end() )
1362 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1366 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
);
1371 size_t c
= sh
.erase( buf
);
1373 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
1375 if( sh
.find( buf
) != sh
.end() )
1377 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1381 // count should decrease
1382 if( sh
.size() != sz
- 1 )
1384 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
1388 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
1391 #endif // TEST_HASHMAP
1393 // ----------------------------------------------------------------------------
1395 // ----------------------------------------------------------------------------
1399 #include "wx/list.h"
1401 WX_DECLARE_LIST(Bar
, wxListBars
);
1402 #include "wx/listimpl.cpp"
1403 WX_DEFINE_LIST(wxListBars
);
1405 WX_DECLARE_LIST(int, wxListInt
);
1406 WX_DEFINE_LIST(wxListInt
);
1408 static void TestList()
1410 wxPuts(_T("*** Testing wxList operations ***\n"));
1416 for ( i
= 0; i
< 5; ++i
)
1417 list1
.Append(dummy
+ i
);
1419 if ( list1
.GetCount() != 5 )
1420 wxPuts(_T("Wrong number of items in list\n"));
1422 if ( list1
.Item(3)->GetData() != dummy
+ 3 )
1423 wxPuts(_T("Error in Item()\n"));
1425 if ( !list1
.Find(dummy
+ 4) )
1426 wxPuts(_T("Error in Find()\n"));
1428 wxListInt::compatibility_iterator node
= list1
.GetFirst();
1433 if ( node
->GetData() != dummy
+ i
)
1434 wxPuts(_T("Error in compatibility_iterator\n"));
1435 node
= node
->GetNext();
1439 if ( size_t(i
) != list1
.GetCount() )
1440 wxPuts(_T("Error in compatibility_iterator\n"));
1442 list1
.Insert(dummy
+ 0);
1443 list1
.Insert(1, dummy
+ 1);
1444 list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy
+ 2);
1446 node
= list1
.GetFirst();
1451 int* t
= node
->GetData();
1452 if ( t
!= dummy
+ i
)
1453 wxPuts(_T("Error in Insert\n"));
1454 node
= node
->GetNext();
1459 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1461 wxPuts(_T("*** Testing std::list operations ***\n"));
1465 wxListInt::iterator it
, en
;
1466 wxListInt::reverse_iterator rit
, ren
;
1468 for ( i
= 0; i
< 5; ++i
)
1469 list1
.push_back(i
+ &i
);
1471 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
1472 it
!= en
; ++it
, ++i
)
1473 if ( *it
!= i
+ &i
)
1474 wxPuts(_T("Error in iterator\n"));
1476 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
1477 rit
!= ren
; ++rit
, --i
)
1478 if ( *rit
!= i
+ &i
)
1479 wxPuts(_T("Error in reverse_iterator\n"));
1481 if ( *list1
.rbegin() != *--list1
.end() ||
1482 *list1
.begin() != *--list1
.rend() )
1483 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1484 if ( *list1
.begin() != *--++list1
.begin() ||
1485 *list1
.rbegin() != *--++list1
.rbegin() )
1486 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1488 if ( list1
.front() != &i
|| list1
.back() != &i
+ 4 )
1489 wxPuts(_T("Error in front()/back()\n"));
1491 list1
.erase(list1
.begin());
1492 list1
.erase(--list1
.end());
1494 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
1495 it
!= en
; ++it
, ++i
)
1496 if ( *it
!= i
+ &i
)
1497 wxPuts(_T("Error in erase()\n"));
1500 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1503 static void TestListCtor()
1505 wxPuts(_T("*** Testing wxList construction ***\n"));
1509 list1
.Append(new Bar(_T("first")));
1510 list1
.Append(new Bar(_T("second")));
1512 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
1513 list1
.GetCount(), Bar::GetNumber());
1518 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
1519 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1522 list1
.DeleteContents(true);
1524 WX_CLEAR_LIST(wxListBars
, list1
);
1528 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
1533 // ----------------------------------------------------------------------------
1535 // ----------------------------------------------------------------------------
1539 #include "wx/intl.h"
1540 #include "wx/utils.h" // for wxSetEnv
1542 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1544 // find the name of the language from its value
1545 static const wxChar
*GetLangName(int lang
)
1547 static const wxChar
*languageNames
[] =
1557 _T("ARABIC_ALGERIA"),
1558 _T("ARABIC_BAHRAIN"),
1561 _T("ARABIC_JORDAN"),
1562 _T("ARABIC_KUWAIT"),
1563 _T("ARABIC_LEBANON"),
1565 _T("ARABIC_MOROCCO"),
1568 _T("ARABIC_SAUDI_ARABIA"),
1571 _T("ARABIC_TUNISIA"),
1578 _T("AZERI_CYRILLIC"),
1593 _T("CHINESE_SIMPLIFIED"),
1594 _T("CHINESE_TRADITIONAL"),
1595 _T("CHINESE_HONGKONG"),
1596 _T("CHINESE_MACAU"),
1597 _T("CHINESE_SINGAPORE"),
1598 _T("CHINESE_TAIWAN"),
1604 _T("DUTCH_BELGIAN"),
1608 _T("ENGLISH_AUSTRALIA"),
1609 _T("ENGLISH_BELIZE"),
1610 _T("ENGLISH_BOTSWANA"),
1611 _T("ENGLISH_CANADA"),
1612 _T("ENGLISH_CARIBBEAN"),
1613 _T("ENGLISH_DENMARK"),
1615 _T("ENGLISH_JAMAICA"),
1616 _T("ENGLISH_NEW_ZEALAND"),
1617 _T("ENGLISH_PHILIPPINES"),
1618 _T("ENGLISH_SOUTH_AFRICA"),
1619 _T("ENGLISH_TRINIDAD"),
1620 _T("ENGLISH_ZIMBABWE"),
1628 _T("FRENCH_BELGIAN"),
1629 _T("FRENCH_CANADIAN"),
1630 _T("FRENCH_LUXEMBOURG"),
1631 _T("FRENCH_MONACO"),
1637 _T("GERMAN_AUSTRIAN"),
1638 _T("GERMAN_BELGIUM"),
1639 _T("GERMAN_LIECHTENSTEIN"),
1640 _T("GERMAN_LUXEMBOURG"),
1658 _T("ITALIAN_SWISS"),
1663 _T("KASHMIRI_INDIA"),
1681 _T("MALAY_BRUNEI_DARUSSALAM"),
1682 _T("MALAY_MALAYSIA"),
1692 _T("NORWEGIAN_BOKMAL"),
1693 _T("NORWEGIAN_NYNORSK"),
1700 _T("PORTUGUESE_BRAZILIAN"),
1703 _T("RHAETO_ROMANCE"),
1706 _T("RUSSIAN_UKRAINE"),
1712 _T("SERBIAN_CYRILLIC"),
1713 _T("SERBIAN_LATIN"),
1714 _T("SERBO_CROATIAN"),
1725 _T("SPANISH_ARGENTINA"),
1726 _T("SPANISH_BOLIVIA"),
1727 _T("SPANISH_CHILE"),
1728 _T("SPANISH_COLOMBIA"),
1729 _T("SPANISH_COSTA_RICA"),
1730 _T("SPANISH_DOMINICAN_REPUBLIC"),
1731 _T("SPANISH_ECUADOR"),
1732 _T("SPANISH_EL_SALVADOR"),
1733 _T("SPANISH_GUATEMALA"),
1734 _T("SPANISH_HONDURAS"),
1735 _T("SPANISH_MEXICAN"),
1736 _T("SPANISH_MODERN"),
1737 _T("SPANISH_NICARAGUA"),
1738 _T("SPANISH_PANAMA"),
1739 _T("SPANISH_PARAGUAY"),
1741 _T("SPANISH_PUERTO_RICO"),
1742 _T("SPANISH_URUGUAY"),
1744 _T("SPANISH_VENEZUELA"),
1748 _T("SWEDISH_FINLAND"),
1766 _T("URDU_PAKISTAN"),
1768 _T("UZBEK_CYRILLIC"),
1781 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1782 return languageNames
[lang
];
1784 return _T("INVALID");
1787 static void TestDefaultLang()
1789 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1791 static const wxChar
*langStrings
[] =
1793 NULL
, // system default
1800 _T("de_DE.iso88591"),
1802 _T("?"), // invalid lang spec
1803 _T("klingonese"), // I bet on some systems it does exist...
1806 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1807 wxLocale::GetSystemEncodingName().c_str(),
1808 wxLocale::GetSystemEncoding());
1810 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1812 const wxChar
*langStr
= langStrings
[n
];
1815 // FIXME: this doesn't do anything at all under Windows, we need
1816 // to create a new wxLocale!
1817 wxSetEnv(_T("LC_ALL"), langStr
);
1820 int lang
= gs_localeDefault
.GetSystemLanguage();
1821 wxPrintf(_T("Locale for '%s' is %s.\n"),
1822 langStr
? langStr
: _T("system default"), GetLangName(lang
));
1826 #endif // TEST_LOCALE
1828 // ----------------------------------------------------------------------------
1830 // ----------------------------------------------------------------------------
1834 #include "wx/mimetype.h"
1836 static void TestMimeEnum()
1838 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1840 wxArrayString mimetypes
;
1842 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1844 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1849 for ( size_t n
= 0; n
< count
; n
++ )
1851 wxFileType
*filetype
=
1852 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1855 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1856 mimetypes
[n
].c_str());
1860 filetype
->GetDescription(&desc
);
1861 filetype
->GetExtensions(exts
);
1863 filetype
->GetIcon(NULL
);
1866 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1869 extsAll
<< _T(", ");
1873 wxPrintf(_T("\t%s: %s (%s)\n"),
1874 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1880 static void TestMimeOverride()
1882 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1884 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1885 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1887 if ( wxFile::Exists(mailcap
) )
1888 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1890 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1892 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1895 if ( wxFile::Exists(mimetypes
) )
1896 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1898 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1900 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1906 static void TestMimeFilename()
1908 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1910 static const wxChar
*filenames
[] =
1918 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1920 const wxString fname
= filenames
[n
];
1921 wxString ext
= fname
.AfterLast(_T('.'));
1922 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1925 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1930 if ( !ft
->GetDescription(&desc
) )
1931 desc
= _T("<no description>");
1934 if ( !ft
->GetOpenCommand(&cmd
,
1935 wxFileType::MessageParameters(fname
, _T(""))) )
1936 cmd
= _T("<no command available>");
1938 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1940 wxPrintf(_T("To open %s (%s) do %s.\n"),
1941 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1950 static void TestMimeAssociate()
1952 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1954 wxFileTypeInfo
ftInfo(
1955 _T("application/x-xyz"),
1956 _T("xyzview '%s'"), // open cmd
1957 _T(""), // print cmd
1958 _T("XYZ File"), // description
1959 _T(".xyz"), // extensions
1960 NULL
// end of extensions
1962 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1964 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1967 wxPuts(_T("ERROR: failed to create association!"));
1971 // TODO: read it back
1980 // ----------------------------------------------------------------------------
1981 // misc information functions
1982 // ----------------------------------------------------------------------------
1984 #ifdef TEST_INFO_FUNCTIONS
1986 #include "wx/utils.h"
1988 static void TestDiskInfo()
1990 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1994 wxChar pathname
[128];
1995 wxPrintf(_T("\nEnter a directory name: "));
1996 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1999 // kill the last '\n'
2000 pathname
[wxStrlen(pathname
) - 1] = 0;
2002 wxLongLong total
, free
;
2003 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
2005 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
2009 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
2010 (total
/ 1024).ToString().c_str(),
2011 (free
/ 1024).ToString().c_str(),
2017 static void TestOsInfo()
2019 wxPuts(_T("*** Testing OS info functions ***\n"));
2022 wxGetOsVersion(&major
, &minor
);
2023 wxPrintf(_T("Running under: %s, version %d.%d\n"),
2024 wxGetOsDescription().c_str(), major
, minor
);
2026 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
2028 wxPrintf(_T("Host name is %s (%s).\n"),
2029 wxGetHostName().c_str(), wxGetFullHostName().c_str());
2034 static void TestUserInfo()
2036 wxPuts(_T("*** Testing user info functions ***\n"));
2038 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
2039 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
2040 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
2041 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
2046 #endif // TEST_INFO_FUNCTIONS
2048 // ----------------------------------------------------------------------------
2050 // ----------------------------------------------------------------------------
2052 #ifdef TEST_LONGLONG
2054 #include "wx/longlong.h"
2055 #include "wx/timer.h"
2057 // make a 64 bit number from 4 16 bit ones
2058 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
2060 // get a random 64 bit number
2061 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
2063 static const long testLongs
[] =
2074 #if wxUSE_LONGLONG_WX
2075 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
2076 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2077 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
2078 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
2079 #endif // wxUSE_LONGLONG_WX
2081 static void TestSpeed()
2083 static const long max
= 100000000;
2090 for ( n
= 0; n
< max
; n
++ )
2095 wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw
.Time());
2098 #if wxUSE_LONGLONG_NATIVE
2103 for ( n
= 0; n
< max
; n
++ )
2108 wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw
.Time());
2110 #endif // wxUSE_LONGLONG_NATIVE
2116 for ( n
= 0; n
< max
; n
++ )
2121 wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw
.Time());
2125 static void TestLongLongConversion()
2127 wxPuts(_T("*** Testing wxLongLong conversions ***\n"));
2131 for ( size_t n
= 0; n
< 100000; n
++ )
2135 #if wxUSE_LONGLONG_NATIVE
2136 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
2138 wxASSERT_MSG( a
== b
, "conversions failure" );
2140 wxPuts(_T("Can't do it without native long long type, test skipped."));
2143 #endif // wxUSE_LONGLONG_NATIVE
2145 if ( !(nTested
% 1000) )
2154 wxPuts(_T(" done!"));
2157 static void TestMultiplication()
2159 wxPuts(_T("*** Testing wxLongLong multiplication ***\n"));
2163 for ( size_t n
= 0; n
< 100000; n
++ )
2168 #if wxUSE_LONGLONG_NATIVE
2169 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
2170 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
2172 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
2173 #else // !wxUSE_LONGLONG_NATIVE
2174 wxPuts(_T("Can't do it without native long long type, test skipped."));
2177 #endif // wxUSE_LONGLONG_NATIVE
2179 if ( !(nTested
% 1000) )
2188 wxPuts(_T(" done!"));
2191 static void TestDivision()
2193 wxPuts(_T("*** Testing wxLongLong division ***\n"));
2197 for ( size_t n
= 0; n
< 100000; n
++ )
2199 // get a random wxLongLong (shifting by 12 the MSB ensures that the
2200 // multiplication will not overflow)
2201 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
2203 // get a random (but non null) long (not wxLongLong for now) to divide
2215 #if wxUSE_LONGLONG_NATIVE
2216 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
2218 wxLongLongNative p
= m
/ l
, s
= m
% l
;
2219 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
2220 #else // !wxUSE_LONGLONG_NATIVE
2221 // verify the result
2222 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
2223 #endif // wxUSE_LONGLONG_NATIVE
2225 if ( !(nTested
% 1000) )
2234 wxPuts(_T(" done!"));
2237 static void TestAddition()
2239 wxPuts(_T("*** Testing wxLongLong addition ***\n"));
2243 for ( size_t n
= 0; n
< 100000; n
++ )
2249 #if wxUSE_LONGLONG_NATIVE
2250 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
2251 wxLongLongNative(b
.GetHi(), b
.GetLo()),
2252 "addition failure" );
2253 #else // !wxUSE_LONGLONG_NATIVE
2254 wxASSERT_MSG( c
- b
== a
, "addition failure" );
2255 #endif // wxUSE_LONGLONG_NATIVE
2257 if ( !(nTested
% 1000) )
2266 wxPuts(_T(" done!"));
2269 static void TestBitOperations()
2271 wxPuts(_T("*** Testing wxLongLong bit operation ***\n"));
2275 for ( size_t n
= 0; n
< 100000; n
++ )
2279 #if wxUSE_LONGLONG_NATIVE
2280 for ( size_t n
= 0; n
< 33; n
++ )
2283 #else // !wxUSE_LONGLONG_NATIVE
2284 wxPuts(_T("Can't do it without native long long type, test skipped."));
2287 #endif // wxUSE_LONGLONG_NATIVE
2289 if ( !(nTested
% 1000) )
2298 wxPuts(_T(" done!"));
2301 static void TestLongLongComparison()
2303 #if wxUSE_LONGLONG_WX
2304 wxPuts(_T("*** Testing wxLongLong comparison ***\n"));
2306 static const long ls
[2] =
2312 wxLongLongWx lls
[2];
2316 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2320 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
2322 res
= lls
[m
] > testLongs
[n
];
2323 wxPrintf(_T("0x%lx > 0x%lx is %s (%s)\n"),
2324 ls
[m
], testLongs
[n
], res
? "true" : "false",
2325 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
2327 res
= lls
[m
] < testLongs
[n
];
2328 wxPrintf(_T("0x%lx < 0x%lx is %s (%s)\n"),
2329 ls
[m
], testLongs
[n
], res
? "true" : "false",
2330 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
2332 res
= lls
[m
] == testLongs
[n
];
2333 wxPrintf(_T("0x%lx == 0x%lx is %s (%s)\n"),
2334 ls
[m
], testLongs
[n
], res
? "true" : "false",
2335 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
2338 #endif // wxUSE_LONGLONG_WX
2341 static void TestLongLongToString()
2343 wxPuts(_T("*** Testing wxLongLong::ToString() ***\n"));
2345 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
2347 wxLongLong ll
= testLongs
[n
];
2348 wxPrintf(_T("%ld == %s\n"), testLongs
[n
], ll
.ToString().c_str());
2351 wxLongLong
ll(0x12345678, 0x87654321);
2352 wxPrintf(_T("0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2355 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll
.ToString().c_str());
2358 static void TestLongLongPrintf()
2360 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
2362 #ifdef wxLongLongFmtSpec
2363 wxLongLong ll
= wxLL(0x1234567890abcdef);
2364 wxString s
= wxString::Format(_T("%") wxLongLongFmtSpec
_T("x"), ll
);
2365 wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"),
2366 s
.c_str(), s
== _T("1234567890abcdef") ? _T("ok") : _T("ERROR"));
2367 #else // !wxLongLongFmtSpec
2368 #error "wxLongLongFmtSpec not defined for this compiler/platform"
2375 #endif // TEST_LONGLONG
2377 // ----------------------------------------------------------------------------
2379 // ----------------------------------------------------------------------------
2381 #ifdef TEST_PATHLIST
2384 #define CMD_IN_PATH _T("ls")
2386 #define CMD_IN_PATH _T("command.com")
2389 static void TestPathList()
2391 wxPuts(_T("*** Testing wxPathList ***\n"));
2393 wxPathList pathlist
;
2394 pathlist
.AddEnvList(_T("PATH"));
2395 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
2398 wxPrintf(_T("ERROR: command not found in the path.\n"));
2402 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
2406 #endif // TEST_PATHLIST
2408 // ----------------------------------------------------------------------------
2409 // regular expressions
2410 // ----------------------------------------------------------------------------
2414 #include "wx/regex.h"
2416 static void TestRegExCompile()
2418 wxPuts(_T("*** Testing RE compilation ***\n"));
2420 static struct RegExCompTestData
2422 const wxChar
*pattern
;
2424 } regExCompTestData
[] =
2426 { _T("foo"), true },
2427 { _T("foo("), false },
2428 { _T("foo(bar"), false },
2429 { _T("foo(bar)"), true },
2430 { _T("foo["), false },
2431 { _T("foo[bar"), false },
2432 { _T("foo[bar]"), true },
2433 { _T("foo{"), true },
2434 { _T("foo{1"), false },
2435 { _T("foo{bar"), true },
2436 { _T("foo{1}"), true },
2437 { _T("foo{1,2}"), true },
2438 { _T("foo{bar}"), true },
2439 { _T("foo*"), true },
2440 { _T("foo**"), false },
2441 { _T("foo+"), true },
2442 { _T("foo++"), false },
2443 { _T("foo?"), true },
2444 { _T("foo??"), false },
2445 { _T("foo?+"), false },
2449 for ( size_t n
= 0; n
< WXSIZEOF(regExCompTestData
); n
++ )
2451 const RegExCompTestData
& data
= regExCompTestData
[n
];
2452 bool ok
= re
.Compile(data
.pattern
);
2454 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
2456 ok
? _T("") : _T("not "),
2457 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2461 static void TestRegExMatch()
2463 wxPuts(_T("*** Testing RE matching ***\n"));
2465 static struct RegExMatchTestData
2467 const wxChar
*pattern
;
2470 } regExMatchTestData
[] =
2472 { _T("foo"), _T("bar"), false },
2473 { _T("foo"), _T("foobar"), true },
2474 { _T("^foo"), _T("foobar"), true },
2475 { _T("^foo"), _T("barfoo"), false },
2476 { _T("bar$"), _T("barbar"), true },
2477 { _T("bar$"), _T("barbar "), false },
2480 for ( size_t n
= 0; n
< WXSIZEOF(regExMatchTestData
); n
++ )
2482 const RegExMatchTestData
& data
= regExMatchTestData
[n
];
2484 wxRegEx
re(data
.pattern
);
2485 bool ok
= re
.Matches(data
.text
);
2487 wxPrintf(_T("'%s' %s %s (%s)\n"),
2489 ok
? _T("matches") : _T("doesn't match"),
2491 ok
== data
.correct
? _T("ok") : _T("ERROR"));
2495 static void TestRegExSubmatch()
2497 wxPuts(_T("*** Testing RE subexpressions ***\n"));
2499 wxRegEx
re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
2500 if ( !re
.IsValid() )
2502 wxPuts(_T("ERROR: compilation failed."));
2506 wxString text
= _T("Fri Jul 13 18:37:52 CEST 2001");
2508 if ( !re
.Matches(text
) )
2510 wxPuts(_T("ERROR: match expected."));
2514 wxPrintf(_T("Entire match: %s\n"), re
.GetMatch(text
).c_str());
2516 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
2517 re
.GetMatch(text
, 3).c_str(),
2518 re
.GetMatch(text
, 2).c_str(),
2519 re
.GetMatch(text
, 4).c_str(),
2520 re
.GetMatch(text
, 1).c_str());
2524 static void TestRegExReplacement()
2526 wxPuts(_T("*** Testing RE replacement ***"));
2528 static struct RegExReplTestData
2532 const wxChar
*result
;
2534 } regExReplTestData
[] =
2536 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2537 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2538 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2539 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2540 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2541 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2542 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2545 const wxChar
*pattern
= _T("([a-z]+)[^0-9]*([0-9]+)");
2546 wxRegEx
re(pattern
);
2548 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern
);
2550 for ( size_t n
= 0; n
< WXSIZEOF(regExReplTestData
); n
++ )
2552 const RegExReplTestData
& data
= regExReplTestData
[n
];
2554 wxString text
= data
.text
;
2555 size_t nRepl
= re
.Replace(&text
, data
.repl
);
2557 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2558 data
.text
, data
.repl
,
2559 nRepl
, nRepl
== 1 ? _T("") : _T("es"),
2561 if ( text
== data
.result
&& nRepl
== data
.count
)
2567 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2568 data
.count
, data
.result
);
2573 static void TestRegExInteractive()
2575 wxPuts(_T("*** Testing RE interactively ***"));
2579 wxChar pattern
[128];
2580 wxPrintf(_T("\nEnter a pattern: "));
2581 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
2584 // kill the last '\n'
2585 pattern
[wxStrlen(pattern
) - 1] = 0;
2588 if ( !re
.Compile(pattern
) )
2596 wxPrintf(_T("Enter text to match: "));
2597 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
2600 // kill the last '\n'
2601 text
[wxStrlen(text
) - 1] = 0;
2603 if ( !re
.Matches(text
) )
2605 wxPrintf(_T("No match.\n"));
2609 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
2612 for ( size_t n
= 1; ; n
++ )
2614 if ( !re
.GetMatch(&start
, &len
, n
) )
2619 wxPrintf(_T("Subexpr %u matched '%s'\n"),
2620 n
, wxString(text
+ start
, len
).c_str());
2627 #endif // TEST_REGEX
2629 // ----------------------------------------------------------------------------
2631 // ----------------------------------------------------------------------------
2641 static void TestDbOpen()
2649 // ----------------------------------------------------------------------------
2651 // ----------------------------------------------------------------------------
2654 NB: this stuff was taken from the glibc test suite and modified to build
2655 in wxWindows: if I read the copyright below properly, this shouldn't
2661 #ifdef wxTEST_PRINTF
2662 // use our functions from wxchar.cpp
2666 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
2667 // in the tests below
2668 int wxPrintf( const wxChar
*format
, ... );
2669 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
2672 #include "wx/longlong.h"
2676 static void rfg1 (void);
2677 static void rfg2 (void);
2681 fmtchk (const wxChar
*fmt
)
2683 (void) wxPrintf(_T("%s:\t`"), fmt
);
2684 (void) wxPrintf(fmt
, 0x12);
2685 (void) wxPrintf(_T("'\n"));
2689 fmtst1chk (const wxChar
*fmt
)
2691 (void) wxPrintf(_T("%s:\t`"), fmt
);
2692 (void) wxPrintf(fmt
, 4, 0x12);
2693 (void) wxPrintf(_T("'\n"));
2697 fmtst2chk (const wxChar
*fmt
)
2699 (void) wxPrintf(_T("%s:\t`"), fmt
);
2700 (void) wxPrintf(fmt
, 4, 4, 0x12);
2701 (void) wxPrintf(_T("'\n"));
2704 /* This page is covered by the following copyright: */
2706 /* (C) Copyright C E Chew
2708 * Feel free to copy, use and distribute this software provided:
2710 * 1. you do not pretend that you wrote it
2711 * 2. you leave this copyright notice intact.
2715 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2722 /* Formatted Output Test
2724 * This exercises the output formatting code.
2732 wxChar
*prefix
= buf
;
2735 wxPuts(_T("\nFormatted output test"));
2736 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
2737 wxStrcpy(prefix
, _T("%"));
2738 for (i
= 0; i
< 2; i
++) {
2739 for (j
= 0; j
< 2; j
++) {
2740 for (k
= 0; k
< 2; k
++) {
2741 for (l
= 0; l
< 2; l
++) {
2742 wxStrcpy(prefix
, _T("%"));
2743 if (i
== 0) wxStrcat(prefix
, _T("-"));
2744 if (j
== 0) wxStrcat(prefix
, _T("+"));
2745 if (k
== 0) wxStrcat(prefix
, _T("#"));
2746 if (l
== 0) wxStrcat(prefix
, _T("0"));
2747 wxPrintf(_T("%5s |"), prefix
);
2748 wxStrcpy(tp
, prefix
);
2749 wxStrcat(tp
, _T("6d |"));
2751 wxStrcpy(tp
, prefix
);
2752 wxStrcat(tp
, _T("6o |"));
2754 wxStrcpy(tp
, prefix
);
2755 wxStrcat(tp
, _T("6x |"));
2757 wxStrcpy(tp
, prefix
);
2758 wxStrcat(tp
, _T("6X |"));
2760 wxStrcpy(tp
, prefix
);
2761 wxStrcat(tp
, _T("6u |"));
2768 wxPrintf(_T("%10s\n"), (wxChar
*) NULL
);
2769 wxPrintf(_T("%-10s\n"), (wxChar
*) NULL
);
2772 static void TestPrintf()
2774 static wxChar shortstr
[] = _T("Hi, Z.");
2775 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
2776 I am ready for my first lesson today.");
2781 fmtchk(_T("%4.4x"));
2782 fmtchk(_T("%04.4x"));
2783 fmtchk(_T("%4.3x"));
2784 fmtchk(_T("%04.3x"));
2786 fmtst1chk(_T("%.*x"));
2787 fmtst1chk(_T("%0*x"));
2788 fmtst2chk(_T("%*.*x"));
2789 fmtst2chk(_T("%0*.*x"));
2791 wxPrintf(_T("bad format:\t\"%b\"\n"));
2792 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
2794 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
2795 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
2796 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
2797 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
2798 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
2799 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
2800 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
2801 wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456);
2802 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
2803 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
2805 wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr
);
2806 wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr
);
2807 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
2808 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
2809 wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar
*)NULL
);
2810 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
2812 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
2813 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
2814 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
2815 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
2816 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
2817 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
2818 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
2819 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
2820 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
2821 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
2822 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
2823 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
2825 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
2826 wxPrintf (_T(" %6.5f\n"), .1);
2827 wxPrintf (_T("x%5.4fx\n"), .5);
2829 wxPrintf (_T("%#03x\n"), 1);
2831 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
2837 while (niter
-- != 0)
2838 wxPrintf (_T("%.17e\n"), d
/ 2);
2842 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
2844 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
2845 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
2846 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
2847 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
2848 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
2849 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
2850 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
2851 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
2852 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
2853 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
2858 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
2860 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
2861 rc
, WXSIZEOF(buf
), buf
);
2864 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
2865 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
2871 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
2872 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
2873 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
2874 wxPrintf (_T("%g should be 123.456\n"), 123.456);
2875 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
2876 wxPrintf (_T("%g should be 10\n"), 10.0);
2877 wxPrintf (_T("%g should be 0.02\n"), 0.02);
2881 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
2887 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
2889 result
|= wxStrcmp (buf
,
2890 _T("onetwo three "));
2892 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
2899 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
2900 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
2902 if (wxStrcmp (buf
, _T("40000000000")) != 0)
2905 wxPuts (_T("\tFAILED"));
2909 #endif // wxLongLong_t
2911 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
2912 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
2914 wxPuts (_T("--- Should be no further output. ---"));
2923 memset (bytes
, '\xff', sizeof bytes
);
2924 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
2925 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
2926 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
2928 wxPuts (_T("%hhn overwrite more bytes"));
2933 wxPuts (_T("%hhn wrote incorrect value"));
2945 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2946 if (wxStrcmp (buf
, _T(" ")) != 0)
2947 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2948 wxSprintf (buf
, _T("%5.f"), 33.3);
2949 if (wxStrcmp (buf
, _T(" 33")) != 0)
2950 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2951 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2952 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2953 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2954 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2955 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2956 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2957 wxSprintf (buf
, _T("%.g"), 33.3);
2958 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2959 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2960 wxSprintf (buf
, _T("%.G"), 33.3);
2961 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2962 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2972 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2973 if (wxStrcmp (buf
, _T("3")) != 0)
2974 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2976 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2977 if (wxStrcmp (buf
, _T("3")) != 0)
2978 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2980 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2981 if (wxStrcmp (buf
, _T(" 3")) != 0)
2982 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2984 wxSprintf (buf
, _T("%04.*o"), prec
, 33);
2985 if (wxStrcmp (buf
, _T(" 041")) != 0)
2986 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2988 wxSprintf (buf
, _T("%09.*u"), prec
, 33);
2989 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2990 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2992 wxSprintf (buf
, _T("%04.*x"), prec
, 33);
2993 if (wxStrcmp (buf
, _T(" 021")) != 0)
2994 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2996 wxSprintf (buf
, _T("%04.*X"), prec
, 33);
2997 if (wxStrcmp (buf
, _T(" 021")) != 0)
2998 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
3001 #endif // TEST_PRINTF
3003 // ----------------------------------------------------------------------------
3004 // registry and related stuff
3005 // ----------------------------------------------------------------------------
3007 // this is for MSW only
3010 #undef TEST_REGISTRY
3015 #include "wx/confbase.h"
3016 #include "wx/msw/regconf.h"
3018 static void TestRegConfWrite()
3020 wxRegConfig
regconf(_T("console"), _T("wxwindows"));
3021 regconf
.Write(_T("Hello"), wxString(_T("world")));
3024 #endif // TEST_REGCONF
3026 #ifdef TEST_REGISTRY
3028 #include "wx/msw/registry.h"
3030 // I chose this one because I liked its name, but it probably only exists under
3032 static const wxChar
*TESTKEY
=
3033 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
3035 static void TestRegistryRead()
3037 wxPuts(_T("*** testing registry reading ***"));
3039 wxRegKey
key(TESTKEY
);
3040 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
3043 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
3048 size_t nSubKeys
, nValues
;
3049 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
3051 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
3054 wxPrintf(_T("Enumerating values:\n"));
3058 bool cont
= key
.GetFirstValue(value
, dummy
);
3061 wxPrintf(_T("Value '%s': type "), value
.c_str());
3062 switch ( key
.GetValueType(value
) )
3064 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
3065 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
3066 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
3067 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
3068 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
3069 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
3070 default: wxPrintf(_T("other (unknown)")); break;
3073 wxPrintf(_T(", value = "));
3074 if ( key
.IsNumericValue(value
) )
3077 key
.QueryValue(value
, &val
);
3078 wxPrintf(_T("%ld"), val
);
3083 key
.QueryValue(value
, val
);
3084 wxPrintf(_T("'%s'"), val
.c_str());
3086 key
.QueryRawValue(value
, val
);
3087 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
3092 cont
= key
.GetNextValue(value
, dummy
);
3096 static void TestRegistryAssociation()
3099 The second call to deleteself genertaes an error message, with a
3100 messagebox saying .flo is crucial to system operation, while the .ddf
3101 call also fails, but with no error message
3106 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
3108 key
= "ddxf_auto_file" ;
3109 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
3111 key
= "ddxf_auto_file" ;
3112 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
3115 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
3117 key
= "program \"%1\"" ;
3119 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
3121 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
3123 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
3125 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
3129 #endif // TEST_REGISTRY
3131 // ----------------------------------------------------------------------------
3133 // ----------------------------------------------------------------------------
3135 #ifdef TEST_SCOPEGUARD
3137 #include "wx/scopeguard.h"
3139 static void function0() { puts("function0()"); }
3140 static void function1(int n
) { printf("function1(%d)\n", n
); }
3141 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
3145 void method0() { printf("method0()\n"); }
3146 void method1(int n
) { printf("method1(%d)\n", n
); }
3147 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
3150 static void TestScopeGuard()
3152 ON_BLOCK_EXIT0(function0
);
3153 ON_BLOCK_EXIT1(function1
, 17);
3154 ON_BLOCK_EXIT2(function2
, 3.14, 'p');
3157 ON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
);
3158 ON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7);
3159 ON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e');
3161 wxScopeGuard dismissed
= wxMakeGuard(function0
);
3162 dismissed
.Dismiss();
3167 // ----------------------------------------------------------------------------
3169 // ----------------------------------------------------------------------------
3173 #include "wx/socket.h"
3174 #include "wx/protocol/protocol.h"
3175 #include "wx/protocol/http.h"
3177 static void TestSocketServer()
3179 wxPuts(_T("*** Testing wxSocketServer ***\n"));
3181 static const int PORT
= 3000;
3186 wxSocketServer
*server
= new wxSocketServer(addr
);
3187 if ( !server
->Ok() )
3189 wxPuts(_T("ERROR: failed to bind"));
3197 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
3199 wxSocketBase
*socket
= server
->Accept();
3202 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
3206 wxPuts(_T("Server: got a client."));
3208 server
->SetTimeout(60); // 1 min
3211 while ( !close
&& socket
->IsConnected() )
3214 wxChar ch
= _T('\0');
3217 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
3219 // don't log error if the client just close the connection
3220 if ( socket
->IsConnected() )
3222 wxPuts(_T("ERROR: in wxSocket::Read."));
3242 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
3243 if ( s
== _T("close") )
3245 wxPuts(_T("Closing connection"));
3249 else if ( s
== _T("quit") )
3254 wxPuts(_T("Shutting down the server"));
3256 else // not a special command
3258 socket
->Write(s
.MakeUpper().c_str(), s
.length());
3259 socket
->Write("\r\n", 2);
3260 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
3266 wxPuts(_T("Server: lost a client unexpectedly."));
3272 // same as "delete server" but is consistent with GUI programs
3276 static void TestSocketClient()
3278 wxPuts(_T("*** Testing wxSocketClient ***\n"));
3280 static const wxChar
*hostname
= _T("www.wxwindows.org");
3283 addr
.Hostname(hostname
);
3286 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
3288 wxSocketClient client
;
3289 if ( !client
.Connect(addr
) )
3291 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3295 wxPrintf(_T("--- Connected to %s:%u...\n"),
3296 addr
.Hostname().c_str(), addr
.Service());
3300 // could use simply "GET" here I suppose
3302 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
3303 client
.Write(cmdGet
, cmdGet
.length());
3304 wxPrintf(_T("--- Sent command '%s' to the server\n"),
3305 MakePrintable(cmdGet
).c_str());
3306 client
.Read(buf
, WXSIZEOF(buf
));
3307 wxPrintf(_T("--- Server replied:\n%s"), buf
);
3311 #endif // TEST_SOCKETS
3313 // ----------------------------------------------------------------------------
3315 // ----------------------------------------------------------------------------
3319 #include "wx/protocol/ftp.h"
3323 #define FTP_ANONYMOUS
3325 #ifdef FTP_ANONYMOUS
3326 static const wxChar
*directory
= _T("/pub");
3327 static const wxChar
*filename
= _T("welcome.msg");
3329 static const wxChar
*directory
= _T("/etc");
3330 static const wxChar
*filename
= _T("issue");
3333 static bool TestFtpConnect()
3335 wxPuts(_T("*** Testing FTP connect ***"));
3337 #ifdef FTP_ANONYMOUS
3338 static const wxChar
*hostname
= _T("ftp.wxwindows.org");
3340 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
3341 #else // !FTP_ANONYMOUS
3342 static const wxChar
*hostname
= "localhost";
3345 wxFgets(user
, WXSIZEOF(user
), stdin
);
3346 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
3349 wxChar password
[256];
3350 wxPrintf(_T("Password for %s: "), password
);
3351 wxFgets(password
, WXSIZEOF(password
), stdin
);
3352 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
3353 ftp
.SetPassword(password
);
3355 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
3356 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
3358 if ( !ftp
.Connect(hostname
) )
3360 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3366 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
3367 hostname
, ftp
.Pwd().c_str());
3373 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
3374 static void TestFtpWuFtpd()
3377 static const wxChar
*hostname
= _T("ftp.eudora.com");
3378 if ( !ftp
.Connect(hostname
) )
3380 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
3384 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
3385 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3388 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3392 size_t size
= in
->GetSize();
3393 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3395 wxChar
*data
= new wxChar
[size
];
3396 if ( !in
->Read(data
, size
) )
3398 wxPuts(_T("ERROR: read error"));
3402 wxPrintf(_T("Successfully retrieved the file.\n"));
3411 static void TestFtpList()
3413 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
3416 if ( !ftp
.ChDir(directory
) )
3418 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3421 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3423 // test NLIST and LIST
3424 wxArrayString files
;
3425 if ( !ftp
.GetFilesList(files
) )
3427 wxPuts(_T("ERROR: failed to get NLIST of files"));
3431 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
3432 size_t count
= files
.GetCount();
3433 for ( size_t n
= 0; n
< count
; n
++ )
3435 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3437 wxPuts(_T("End of the file list"));
3440 if ( !ftp
.GetDirList(files
) )
3442 wxPuts(_T("ERROR: failed to get LIST of files"));
3446 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
3447 size_t count
= files
.GetCount();
3448 for ( size_t n
= 0; n
< count
; n
++ )
3450 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3452 wxPuts(_T("End of the file list"));
3455 if ( !ftp
.ChDir(_T("..")) )
3457 wxPuts(_T("ERROR: failed to cd to .."));
3460 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3463 static void TestFtpDownload()
3465 wxPuts(_T("*** Testing wxFTP download ***\n"));
3468 wxInputStream
*in
= ftp
.GetInputStream(filename
);
3471 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
3475 size_t size
= in
->GetSize();
3476 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
3479 wxChar
*data
= new wxChar
[size
];
3480 if ( !in
->Read(data
, size
) )
3482 wxPuts(_T("ERROR: read error"));
3486 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
3494 static void TestFtpFileSize()
3496 wxPuts(_T("*** Testing FTP SIZE command ***"));
3498 if ( !ftp
.ChDir(directory
) )
3500 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
3503 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
3505 if ( ftp
.FileExists(filename
) )
3507 int size
= ftp
.GetFileSize(filename
);
3509 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
3511 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
3515 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
3519 static void TestFtpMisc()
3521 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
3523 if ( ftp
.SendCommand("STAT") != '2' )
3525 wxPuts(_T("ERROR: STAT failed"));
3529 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
3532 if ( ftp
.SendCommand("HELP SITE") != '2' )
3534 wxPuts(_T("ERROR: HELP SITE failed"));
3538 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
3539 ftp
.GetLastResult().c_str());
3543 static void TestFtpInteractive()
3545 wxPuts(_T("\n*** Interactive wxFTP test ***"));
3551 wxPrintf(_T("Enter FTP command: "));
3552 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3555 // kill the last '\n'
3556 buf
[wxStrlen(buf
) - 1] = 0;
3558 // special handling of LIST and NLST as they require data connection
3559 wxString
start(buf
, 4);
3561 if ( start
== "LIST" || start
== "NLST" )
3564 if ( wxStrlen(buf
) > 4 )
3567 wxArrayString files
;
3568 if ( !ftp
.GetList(files
, wildcard
, start
== "LIST") )
3570 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
3574 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
3575 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
3576 size_t count
= files
.GetCount();
3577 for ( size_t n
= 0; n
< count
; n
++ )
3579 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
3581 wxPuts(_T("--- End of the file list"));
3586 wxChar ch
= ftp
.SendCommand(buf
);
3587 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
3590 wxPrintf(_T(" (return code %c)"), ch
);
3593 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
3597 wxPuts(_T("\n*** done ***"));
3600 static void TestFtpUpload()
3602 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
3605 static const wxChar
*file1
= _T("test1");
3606 static const wxChar
*file2
= _T("test2");
3607 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
3610 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3611 out
->Write("First hello", 11);
3615 // send a command to check the remote file
3616 if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' )
3618 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
3622 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
3623 file1
, ftp
.GetLastResult().c_str());
3626 out
= ftp
.GetOutputStream(file2
);
3629 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3630 out
->Write("Second hello", 12);
3637 // ----------------------------------------------------------------------------
3639 // ----------------------------------------------------------------------------
3643 #include "wx/wfstream.h"
3644 #include "wx/mstream.h"
3646 static void TestFileStream()
3648 wxPuts(_T("*** Testing wxFileInputStream ***"));
3650 static const wxChar
*filename
= _T("testdata.fs");
3652 wxFileOutputStream
fsOut(filename
);
3653 fsOut
.Write("foo", 3);
3656 wxFileInputStream
fsIn(filename
);
3657 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
3658 while ( !fsIn
.Eof() )
3660 putchar(fsIn
.GetC());
3663 if ( !wxRemoveFile(filename
) )
3665 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
);
3668 wxPuts(_T("\n*** wxFileInputStream test done ***"));
3671 static void TestMemoryStream()
3673 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3675 wxMemoryOutputStream memOutStream
;
3676 wxPrintf(_T("Initially out stream offset: %lu\n"),
3677 (unsigned long)memOutStream
.TellO());
3679 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
3681 memOutStream
.PutC(*p
);
3684 wxPrintf(_T("Final out stream offset: %lu\n"),
3685 (unsigned long)memOutStream
.TellO());
3687 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
3690 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
3692 wxMemoryInputStream
memInpStream(buf
, len
);
3693 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3694 while ( !memInpStream
.Eof() )
3696 putchar(memInpStream
.GetC());
3699 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
3702 #endif // TEST_STREAMS
3704 // ----------------------------------------------------------------------------
3706 // ----------------------------------------------------------------------------
3710 #include "wx/timer.h"
3711 #include "wx/utils.h"
3713 static void TestStopWatch()
3715 wxPuts(_T("*** Testing wxStopWatch ***\n"));
3719 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
3722 wxPrintf(_T("\t%ldms\n"), sw
.Time());
3724 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
3728 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3731 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
3734 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3737 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
3740 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3743 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
3744 for ( size_t n
= 0; n
< 70; n
++ )
3748 for ( size_t m
= 0; m
< 100000; m
++ )
3750 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3752 wxPuts(_T("\ntime is negative - ERROR!"));
3760 wxPuts(_T(", ok."));
3763 #endif // TEST_TIMER
3765 // ----------------------------------------------------------------------------
3767 // ----------------------------------------------------------------------------
3771 #include "wx/vcard.h"
3773 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3776 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3779 wxPrintf(_T("%s%s"),
3780 wxString(_T('\t'), level
).c_str(),
3781 vcObj
->GetName().c_str());
3784 switch ( vcObj
->GetType() )
3786 case wxVCardObject::String
:
3787 case wxVCardObject::UString
:
3790 vcObj
->GetValue(&val
);
3791 value
<< _T('"') << val
<< _T('"');
3795 case wxVCardObject::Int
:
3798 vcObj
->GetValue(&i
);
3799 value
.Printf(_T("%u"), i
);
3803 case wxVCardObject::Long
:
3806 vcObj
->GetValue(&l
);
3807 value
.Printf(_T("%lu"), l
);
3811 case wxVCardObject::None
:
3814 case wxVCardObject::Object
:
3815 value
= _T("<node>");
3819 value
= _T("<unknown value type>");
3823 wxPrintf(_T(" = %s"), value
.c_str());
3826 DumpVObject(level
+ 1, *vcObj
);
3829 vcObj
= vcard
.GetNextProp(&cookie
);
3833 static void DumpVCardAddresses(const wxVCard
& vcard
)
3835 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3839 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3843 int flags
= addr
->GetFlags();
3844 if ( flags
& wxVCardAddress::Domestic
)
3846 flagsStr
<< _T("domestic ");
3848 if ( flags
& wxVCardAddress::Intl
)
3850 flagsStr
<< _T("international ");
3852 if ( flags
& wxVCardAddress::Postal
)
3854 flagsStr
<< _T("postal ");
3856 if ( flags
& wxVCardAddress::Parcel
)
3858 flagsStr
<< _T("parcel ");
3860 if ( flags
& wxVCardAddress::Home
)
3862 flagsStr
<< _T("home ");
3864 if ( flags
& wxVCardAddress::Work
)
3866 flagsStr
<< _T("work ");
3869 wxPrintf(_T("Address %u:\n")
3871 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3874 addr
->GetPostOffice().c_str(),
3875 addr
->GetExtAddress().c_str(),
3876 addr
->GetStreet().c_str(),
3877 addr
->GetLocality().c_str(),
3878 addr
->GetRegion().c_str(),
3879 addr
->GetPostalCode().c_str(),
3880 addr
->GetCountry().c_str()
3884 addr
= vcard
.GetNextAddress(&cookie
);
3888 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3890 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3894 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3898 int flags
= phone
->GetFlags();
3899 if ( flags
& wxVCardPhoneNumber::Voice
)
3901 flagsStr
<< _T("voice ");
3903 if ( flags
& wxVCardPhoneNumber::Fax
)
3905 flagsStr
<< _T("fax ");
3907 if ( flags
& wxVCardPhoneNumber::Cellular
)
3909 flagsStr
<< _T("cellular ");
3911 if ( flags
& wxVCardPhoneNumber::Modem
)
3913 flagsStr
<< _T("modem ");
3915 if ( flags
& wxVCardPhoneNumber::Home
)
3917 flagsStr
<< _T("home ");
3919 if ( flags
& wxVCardPhoneNumber::Work
)
3921 flagsStr
<< _T("work ");
3924 wxPrintf(_T("Phone number %u:\n")
3929 phone
->GetNumber().c_str()
3933 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3937 static void TestVCardRead()
3939 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3941 wxVCard
vcard(_T("vcard.vcf"));
3942 if ( !vcard
.IsOk() )
3944 wxPuts(_T("ERROR: couldn't load vCard."));
3948 // read individual vCard properties
3949 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3953 vcObj
->GetValue(&value
);
3958 value
= _T("<none>");
3961 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3964 if ( !vcard
.GetFullName(&value
) )
3966 value
= _T("<none>");
3969 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3971 // now show how to deal with multiply occuring properties
3972 DumpVCardAddresses(vcard
);
3973 DumpVCardPhoneNumbers(vcard
);
3975 // and finally show all
3976 wxPuts(_T("\nNow dumping the entire vCard:\n")
3977 "-----------------------------\n");
3979 DumpVObject(0, vcard
);
3983 static void TestVCardWrite()
3985 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3988 if ( !vcard
.IsOk() )
3990 wxPuts(_T("ERROR: couldn't create vCard."));
3995 vcard
.SetName("Zeitlin", "Vadim");
3996 vcard
.SetFullName("Vadim Zeitlin");
3997 vcard
.SetOrganization("wxWindows", "R&D");
3999 // just dump the vCard back
4000 wxPuts(_T("Entire vCard follows:\n"));
4001 wxPuts(vcard
.Write());
4005 #endif // TEST_VCARD
4007 // ----------------------------------------------------------------------------
4009 // ----------------------------------------------------------------------------
4011 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
4017 #include "wx/volume.h"
4019 static const wxChar
*volumeKinds
[] =
4025 _T("network volume"),
4029 static void TestFSVolume()
4031 wxPuts(_T("*** Testing wxFSVolume class ***"));
4033 wxArrayString volumes
= wxFSVolume::GetVolumes();
4034 size_t count
= volumes
.GetCount();
4038 wxPuts(_T("ERROR: no mounted volumes?"));
4042 wxPrintf(_T("%u mounted volumes found:\n"), count
);
4044 for ( size_t n
= 0; n
< count
; n
++ )
4046 wxFSVolume
vol(volumes
[n
]);
4049 wxPuts(_T("ERROR: couldn't create volume"));
4053 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
4055 vol
.GetDisplayName().c_str(),
4056 vol
.GetName().c_str(),
4057 volumeKinds
[vol
.GetKind()],
4058 vol
.IsWritable() ? _T("rw") : _T("ro"),
4059 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
4064 #endif // TEST_VOLUME
4066 // ----------------------------------------------------------------------------
4067 // wide char and Unicode support
4068 // ----------------------------------------------------------------------------
4072 static void TestUnicodeToFromAscii()
4074 wxPuts(_T("Testing wxString::To/FromAscii()\n"));
4076 static const char *msg
= "Hello, world!";
4077 wxString s
= wxString::FromAscii(msg
);
4079 wxPrintf(_T("Message in Unicode: %s\n"), s
.c_str());
4080 printf("Message in ASCII: %s\n", (const char *)s
.ToAscii());
4082 wxPutchar(_T('\n'));
4085 #endif // TEST_UNICODE
4089 #include "wx/strconv.h"
4090 #include "wx/fontenc.h"
4091 #include "wx/encconv.h"
4092 #include "wx/buffer.h"
4094 static const unsigned char utf8koi8r
[] =
4096 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
4097 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
4098 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
4099 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
4100 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
4101 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
4102 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
4105 static const unsigned char utf8iso8859_1
[] =
4107 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
4108 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
4109 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
4110 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
4111 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
4114 static const unsigned char utf8Invalid
[] =
4116 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
4117 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
4118 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
4119 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
4123 static const struct Utf8Data
4125 const unsigned char *text
;
4127 const wxChar
*charset
;
4128 wxFontEncoding encoding
;
4131 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4132 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
4133 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
4136 static void TestUtf8()
4138 wxPuts(_T("*** Testing UTF8 support ***\n"));
4143 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
4145 const Utf8Data
& u8d
= utf8data
[n
];
4146 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
4147 WXSIZEOF(wbuf
)) == (size_t)-1 )
4149 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4153 wxCSConv
conv(u8d
.charset
);
4154 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
4156 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
4160 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
4164 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
), *wxConvCurrent
);
4166 s
= _T("<< conversion failed >>");
4167 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
4174 static void TestEncodingConverter()
4176 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
4178 // using wxEncodingConverter should give the same result as above
4181 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
4182 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
4184 wxPuts(_T("ERROR: UTF-8 decoding failed."));
4188 wxEncodingConverter ec
;
4189 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
4190 ec
.Convert(wbuf
, buf
);
4191 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
4197 #endif // TEST_WCHAR
4199 // ----------------------------------------------------------------------------
4201 // ----------------------------------------------------------------------------
4205 #include "wx/filesys.h"
4206 #include "wx/fs_zip.h"
4207 #include "wx/zipstrm.h"
4209 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
4211 static void TestZipStreamRead()
4213 wxPuts(_T("*** Testing ZIP reading ***\n"));
4215 static const wxChar
*filename
= _T("foo");
4216 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
4217 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4219 wxPrintf(_T("Dumping the file '%s':\n"), filename
);
4220 while ( !istr
.Eof() )
4222 putchar(istr
.GetC());
4226 wxPuts(_T("\n----- done ------"));
4229 static void DumpZipDirectory(wxFileSystem
& fs
,
4230 const wxString
& dir
,
4231 const wxString
& indent
)
4233 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
4234 TESTFILE_ZIP
, dir
.c_str());
4235 wxString wildcard
= prefix
+ _T("/*");
4237 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
4238 while ( !dirname
.empty() )
4240 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
4242 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4247 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
4249 DumpZipDirectory(fs
, dirname
,
4250 indent
+ wxString(_T(' '), 4));
4252 dirname
= fs
.FindNext();
4255 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
4256 while ( !filename
.empty() )
4258 if ( !filename
.StartsWith(prefix
, &filename
) )
4260 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
4265 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
4267 filename
= fs
.FindNext();
4271 static void TestZipFileSystem()
4273 wxPuts(_T("*** Testing ZIP file system ***\n"));
4275 wxFileSystem::AddHandler(new wxZipFSHandler
);
4277 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
4279 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
4284 // ----------------------------------------------------------------------------
4286 // ----------------------------------------------------------------------------
4290 #include "wx/zstream.h"
4291 #include "wx/wfstream.h"
4293 static const wxChar
*FILENAME_GZ
= _T("test.gz");
4294 static const wxChar
*TEST_DATA
= _T("hello and hello and hello and hello and hello");
4296 static void TestZlibStreamWrite()
4298 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4300 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
4301 wxZlibOutputStream
ostr(fileOutStream
);
4302 wxPrintf(_T("Compressing the test string... "));
4303 ostr
.Write(TEST_DATA
, wxStrlen(TEST_DATA
) + 1);
4306 wxPuts(_T("(ERROR: failed)"));
4313 wxPuts(_T("\n----- done ------"));
4316 static void TestZlibStreamRead()
4318 wxPuts(_T("*** Testing Zlib stream reading ***\n"));
4320 wxFileInputStream
fileInStream(FILENAME_GZ
);
4321 wxZlibInputStream
istr(fileInStream
);
4322 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
4324 wxPuts(_T("Dumping the file:"));
4325 while ( !istr
.Eof() )
4327 putchar(istr
.GetC());
4331 wxPuts(_T("\n----- done ------"));
4336 // ----------------------------------------------------------------------------
4338 // ----------------------------------------------------------------------------
4340 #ifdef TEST_DATETIME
4344 #include "wx/datetime.h"
4349 wxDateTime::wxDateTime_t day
;
4350 wxDateTime::Month month
;
4352 wxDateTime::wxDateTime_t hour
, min
, sec
;
4354 wxDateTime::WeekDay wday
;
4355 time_t gmticks
, ticks
;
4357 void Init(const wxDateTime::Tm
& tm
)
4366 gmticks
= ticks
= -1;
4369 wxDateTime
DT() const
4370 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
4372 bool SameDay(const wxDateTime::Tm
& tm
) const
4374 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
4377 wxString
Format() const
4380 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
4382 wxDateTime::GetMonthName(month
).c_str(),
4384 abs(wxDateTime::ConvertYearToBC(year
)),
4385 year
> 0 ? _T("AD") : _T("BC"));
4389 wxString
FormatDate() const
4392 s
.Printf(_T("%02d-%s-%4d%s"),
4394 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4395 abs(wxDateTime::ConvertYearToBC(year
)),
4396 year
> 0 ? _T("AD") : _T("BC"));
4401 static const Date testDates
[] =
4403 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
4404 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
4405 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
4406 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
4407 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
4408 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
4409 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
4410 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
4411 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
4412 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
4413 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
4414 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
4415 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
4416 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
4417 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
4418 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
4419 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
4420 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
4421 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
4424 // this test miscellaneous static wxDateTime functions
4425 static void TestTimeStatic()
4427 wxPuts(_T("\n*** wxDateTime static methods test ***"));
4429 // some info about the current date
4430 int year
= wxDateTime::GetCurrentYear();
4431 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
4433 wxDateTime::IsLeapYear(year
) ? "" : "not ",
4434 wxDateTime::GetNumberOfDays(year
));
4436 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
4437 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
4438 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
4439 wxDateTime::GetMonthName(month
).c_str(),
4440 wxDateTime::GetNumberOfDays(month
));
4443 static const size_t nYears
= 5;
4444 static const size_t years
[2][nYears
] =
4446 // first line: the years to test
4447 { 1990, 1976, 2000, 2030, 1984, },
4449 // second line: true if leap, false otherwise
4450 { false, true, true, false, true }
4453 for ( size_t n
= 0; n
< nYears
; n
++ )
4455 int year
= years
[0][n
];
4456 bool should
= years
[1][n
] != 0,
4457 is
= wxDateTime::IsLeapYear(year
);
4459 wxPrintf(_T("Year %d is %sa leap year (%s)\n"),
4462 should
== is
? "ok" : "ERROR");
4464 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
4468 // test constructing wxDateTime objects
4469 static void TestTimeSet()
4471 wxPuts(_T("\n*** wxDateTime construction test ***"));
4473 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4475 const Date
& d1
= testDates
[n
];
4476 wxDateTime dt
= d1
.DT();
4479 d2
.Init(dt
.GetTm());
4481 wxString s1
= d1
.Format(),
4484 wxPrintf(_T("Date: %s == %s (%s)\n"),
4485 s1
.c_str(), s2
.c_str(),
4486 s1
== s2
? _T("ok") : _T("ERROR"));
4490 // test time zones stuff
4491 static void TestTimeZones()
4493 wxPuts(_T("\n*** wxDateTime timezone test ***"));
4495 wxDateTime now
= wxDateTime::Now();
4497 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
4498 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
4499 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
4500 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
4501 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
4502 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
4504 wxDateTime::Tm tm
= now
.GetTm();
4505 if ( wxDateTime(tm
) != now
)
4507 wxPrintf(_T("ERROR: got %s instead of %s\n"),
4508 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
4512 // test some minimal support for the dates outside the standard range
4513 static void TestTimeRange()
4515 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
4517 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
4519 wxPrintf(_T("Unix epoch:\t%s\n"),
4520 wxDateTime(2440587.5).Format(fmt
).c_str());
4521 wxPrintf(_T("Feb 29, 0: \t%s\n"),
4522 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
4523 wxPrintf(_T("JDN 0: \t%s\n"),
4524 wxDateTime(0.0).Format(fmt
).c_str());
4525 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
4526 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
4527 wxPrintf(_T("May 29, 2099:\t%s\n"),
4528 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
4531 static void TestTimeTicks()
4533 wxPuts(_T("\n*** wxDateTime ticks test ***"));
4535 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4537 const Date
& d
= testDates
[n
];
4538 if ( d
.ticks
== -1 )
4541 wxDateTime dt
= d
.DT();
4542 long ticks
= (dt
.GetValue() / 1000).ToLong();
4543 wxPrintf(_T("Ticks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4544 if ( ticks
== d
.ticks
)
4546 wxPuts(_T(" (ok)"));
4550 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4551 (long)d
.ticks
, (long)(ticks
- d
.ticks
));
4554 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
4555 ticks
= (dt
.GetValue() / 1000).ToLong();
4556 wxPrintf(_T("GMtks of %s:\t% 10ld"), d
.Format().c_str(), ticks
);
4557 if ( ticks
== d
.gmticks
)
4559 wxPuts(_T(" (ok)"));
4563 wxPrintf(_T(" (ERROR: should be %ld, delta = %ld)\n"),
4564 (long)d
.gmticks
, (long)(ticks
- d
.gmticks
));
4571 // test conversions to JDN &c
4572 static void TestTimeJDN()
4574 wxPuts(_T("\n*** wxDateTime to JDN test ***"));
4576 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4578 const Date
& d
= testDates
[n
];
4579 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4580 double jdn
= dt
.GetJulianDayNumber();
4582 wxPrintf(_T("JDN of %s is:\t% 15.6f"), d
.Format().c_str(), jdn
);
4585 wxPuts(_T(" (ok)"));
4589 wxPrintf(_T(" (ERROR: should be %f, delta = %f)\n"),
4590 d
.jdn
, jdn
- d
.jdn
);
4595 // test week days computation
4596 static void TestTimeWDays()
4598 wxPuts(_T("\n*** wxDateTime weekday test ***"));
4600 // test GetWeekDay()
4602 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
4604 const Date
& d
= testDates
[n
];
4605 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
4607 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
4608 wxPrintf(_T("%s is: %s"),
4610 wxDateTime::GetWeekDayName(wday
).c_str());
4611 if ( wday
== d
.wday
)
4613 wxPuts(_T(" (ok)"));
4617 wxPrintf(_T(" (ERROR: should be %s)\n"),
4618 wxDateTime::GetWeekDayName(d
.wday
).c_str());
4624 // test SetToWeekDay()
4625 struct WeekDateTestData
4627 Date date
; // the real date (precomputed)
4628 int nWeek
; // its week index in the month
4629 wxDateTime::WeekDay wday
; // the weekday
4630 wxDateTime::Month month
; // the month
4631 int year
; // and the year
4633 wxString
Format() const
4636 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
4638 case 1: which
= _T("first"); break;
4639 case 2: which
= _T("second"); break;
4640 case 3: which
= _T("third"); break;
4641 case 4: which
= _T("fourth"); break;
4642 case 5: which
= _T("fifth"); break;
4644 case -1: which
= _T("last"); break;
4649 which
+= _T(" from end");
4652 s
.Printf(_T("The %s %s of %s in %d"),
4654 wxDateTime::GetWeekDayName(wday
).c_str(),
4655 wxDateTime::GetMonthName(month
).c_str(),
4662 // the array data was generated by the following python program
4664 from DateTime import *
4665 from whrandom import *
4666 from string import *
4668 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4669 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4671 week = DateTimeDelta(7)
4674 year = randint(1900, 2100)
4675 month = randint(1, 12)
4676 day = randint(1, 28)
4677 dt = DateTime(year, month, day)
4678 wday = dt.day_of_week
4680 countFromEnd = choice([-1, 1])
4683 while dt.month is month:
4684 dt = dt - countFromEnd * week
4685 weekNum = weekNum + countFromEnd
4687 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
4689 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
4690 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
4693 static const WeekDateTestData weekDatesTestData
[] =
4695 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
4696 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
4697 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
4698 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
4699 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
4700 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
4701 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
4702 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
4703 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
4704 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
4705 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
4706 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
4707 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
4708 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
4709 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
4710 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
4711 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
4712 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
4713 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
4714 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
4717 static const wxChar
*fmt
= _T("%d-%b-%Y");
4720 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
4722 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
4724 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
4726 wxPrintf(_T("%s is %s"), wd
.Format().c_str(), dt
.Format(fmt
).c_str());
4728 const Date
& d
= wd
.date
;
4729 if ( d
.SameDay(dt
.GetTm()) )
4731 wxPuts(_T(" (ok)"));
4735 dt
.Set(d
.day
, d
.month
, d
.year
);
4737 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.Format(fmt
).c_str());
4742 // test the computation of (ISO) week numbers
4743 static void TestTimeWNumber()
4745 wxPuts(_T("\n*** wxDateTime week number test ***"));
4747 struct WeekNumberTestData
4749 Date date
; // the date
4750 wxDateTime::wxDateTime_t week
; // the week number in the year
4751 wxDateTime::wxDateTime_t wmon
; // the week number in the month
4752 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
4753 wxDateTime::wxDateTime_t dnum
; // day number in the year
4756 // data generated with the following python script:
4758 from DateTime import *
4759 from whrandom import *
4760 from string import *
4762 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
4763 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
4765 def GetMonthWeek(dt):
4766 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
4767 if weekNumMonth < 0:
4768 weekNumMonth = weekNumMonth + 53
4771 def GetLastSundayBefore(dt):
4772 if dt.iso_week[2] == 7:
4775 return dt - DateTimeDelta(dt.iso_week[2])
4778 year = randint(1900, 2100)
4779 month = randint(1, 12)
4780 day = randint(1, 28)
4781 dt = DateTime(year, month, day)
4782 dayNum = dt.day_of_year
4783 weekNum = dt.iso_week[1]
4784 weekNumMonth = GetMonthWeek(dt)
4787 dtSunday = GetLastSundayBefore(dt)
4789 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
4790 weekNumMonth2 = weekNumMonth2 + 1
4791 dtSunday = dtSunday - DateTimeDelta(7)
4793 data = { 'day': rjust(`day`, 2), \
4794 'month': monthNames[month - 1], \
4796 'weekNum': rjust(`weekNum`, 2), \
4797 'weekNumMonth': weekNumMonth, \
4798 'weekNumMonth2': weekNumMonth2, \
4799 'dayNum': rjust(`dayNum`, 3) }
4801 print " { { %(day)s, "\
4802 "wxDateTime::%(month)s, "\
4805 "%(weekNumMonth)s, "\
4806 "%(weekNumMonth2)s, "\
4807 "%(dayNum)s }," % data
4810 static const WeekNumberTestData weekNumberTestDates
[] =
4812 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
4813 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
4814 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
4815 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
4816 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
4817 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
4818 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
4819 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
4820 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
4821 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
4822 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
4823 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
4824 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
4825 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
4826 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
4827 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
4828 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
4829 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
4830 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
4831 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
4834 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
4836 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
4837 const Date
& d
= wn
.date
;
4839 wxDateTime dt
= d
.DT();
4841 wxDateTime::wxDateTime_t
4842 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
4843 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
4844 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
4845 dnum
= dt
.GetDayOfYear();
4847 wxPrintf(_T("%s: the day number is %d"), d
.FormatDate().c_str(), dnum
);
4848 if ( dnum
== wn
.dnum
)
4850 wxPrintf(_T(" (ok)"));
4854 wxPrintf(_T(" (ERROR: should be %d)"), wn
.dnum
);
4857 wxPrintf(_T(", week in month = %d"), wmon
);
4858 if ( wmon
!= wn
.wmon
)
4860 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon
);
4863 wxPrintf(_T(" or %d"), wmon2
);
4864 if ( wmon2
== wn
.wmon2
)
4866 wxPrintf(_T(" (ok)"));
4870 wxPrintf(_T(" (ERROR: should be %d)"), wn
.wmon2
);
4873 wxPrintf(_T(", week in year = %d"), week
);
4874 if ( week
!= wn
.week
)
4876 wxPrintf(_T(" (ERROR: should be %d)"), wn
.week
);
4879 wxPutchar(_T('\n'));
4881 wxDateTime
dt2(1, wxDateTime::Jan
, d
.year
);
4882 dt2
.SetToTheWeek(wn
.week
, dt
.GetWeekDay());
4886 d2
.Init(dt2
.GetTm());
4887 wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"),
4888 d2
.FormatDate().c_str());
4893 // test DST calculations
4894 static void TestTimeDST()
4896 wxPuts(_T("\n*** wxDateTime DST test ***"));
4898 wxPrintf(_T("DST is%s in effect now.\n\n"),
4899 wxDateTime::Now().IsDST() ? _T("") : _T(" not"));
4901 // taken from http://www.energy.ca.gov/daylightsaving.html
4902 static const Date datesDST
[2][2004 - 1900 + 1] =
4905 { 1, wxDateTime::Apr
, 1990 },
4906 { 7, wxDateTime::Apr
, 1991 },
4907 { 5, wxDateTime::Apr
, 1992 },
4908 { 4, wxDateTime::Apr
, 1993 },
4909 { 3, wxDateTime::Apr
, 1994 },
4910 { 2, wxDateTime::Apr
, 1995 },
4911 { 7, wxDateTime::Apr
, 1996 },
4912 { 6, wxDateTime::Apr
, 1997 },
4913 { 5, wxDateTime::Apr
, 1998 },
4914 { 4, wxDateTime::Apr
, 1999 },
4915 { 2, wxDateTime::Apr
, 2000 },
4916 { 1, wxDateTime::Apr
, 2001 },
4917 { 7, wxDateTime::Apr
, 2002 },
4918 { 6, wxDateTime::Apr
, 2003 },
4919 { 4, wxDateTime::Apr
, 2004 },
4922 { 28, wxDateTime::Oct
, 1990 },
4923 { 27, wxDateTime::Oct
, 1991 },
4924 { 25, wxDateTime::Oct
, 1992 },
4925 { 31, wxDateTime::Oct
, 1993 },
4926 { 30, wxDateTime::Oct
, 1994 },
4927 { 29, wxDateTime::Oct
, 1995 },
4928 { 27, wxDateTime::Oct
, 1996 },
4929 { 26, wxDateTime::Oct
, 1997 },
4930 { 25, wxDateTime::Oct
, 1998 },
4931 { 31, wxDateTime::Oct
, 1999 },
4932 { 29, wxDateTime::Oct
, 2000 },
4933 { 28, wxDateTime::Oct
, 2001 },
4934 { 27, wxDateTime::Oct
, 2002 },
4935 { 26, wxDateTime::Oct
, 2003 },
4936 { 31, wxDateTime::Oct
, 2004 },
4941 for ( year
= 1990; year
< 2005; year
++ )
4943 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
4944 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
4946 wxPrintf(_T("DST period in the US for year %d: from %s to %s"),
4947 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
4949 size_t n
= year
- 1990;
4950 const Date
& dBegin
= datesDST
[0][n
];
4951 const Date
& dEnd
= datesDST
[1][n
];
4953 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
4955 wxPuts(_T(" (ok)"));
4959 wxPrintf(_T(" (ERROR: should be %s %d to %s %d)\n"),
4960 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
4961 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
4967 for ( year
= 1990; year
< 2005; year
++ )
4969 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
4971 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
4972 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
4976 // test wxDateTime -> text conversion
4977 static void TestTimeFormat()
4979 wxPuts(_T("\n*** wxDateTime formatting test ***"));
4981 // some information may be lost during conversion, so store what kind
4982 // of info should we recover after a round trip
4985 CompareNone
, // don't try comparing
4986 CompareBoth
, // dates and times should be identical
4987 CompareDate
, // dates only
4988 CompareTime
// time only
4993 CompareKind compareKind
;
4994 const wxChar
*format
;
4995 } formatTestFormats
[] =
4997 { CompareBoth
, _T("---> %c") },
4998 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
4999 { CompareBoth
, _T("Date is %x, time is %X") },
5000 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
5001 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
5002 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
5005 static const Date formatTestDates
[] =
5007 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
5008 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
5010 // this test can't work for other centuries because it uses two digit
5011 // years in formats, so don't even try it
5012 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
5013 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
5014 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
5018 // an extra test (as it doesn't depend on date, don't do it in the loop)
5019 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
5021 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
5025 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
5026 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
5028 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
5029 wxPrintf(_T("%s"), s
.c_str());
5031 // what can we recover?
5032 int kind
= formatTestFormats
[n
].compareKind
;
5036 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
5039 // converion failed - should it have?
5040 if ( kind
== CompareNone
)
5041 wxPuts(_T(" (ok)"));
5043 wxPuts(_T(" (ERROR: conversion back failed)"));
5047 // should have parsed the entire string
5048 wxPuts(_T(" (ERROR: conversion back stopped too soon)"));
5052 bool equal
= false; // suppress compilaer warning
5060 equal
= dt
.IsSameDate(dt2
);
5064 equal
= dt
.IsSameTime(dt2
);
5070 wxPrintf(_T(" (ERROR: got back '%s' instead of '%s')\n"),
5071 dt2
.Format().c_str(), dt
.Format().c_str());
5075 wxPuts(_T(" (ok)"));
5082 // test text -> wxDateTime conversion
5083 static void TestTimeParse()
5085 wxPuts(_T("\n*** wxDateTime parse test ***"));
5087 struct ParseTestData
5089 const wxChar
*format
;
5094 static const ParseTestData parseTestDates
[] =
5096 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
5097 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
5100 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
5102 const wxChar
*format
= parseTestDates
[n
].format
;
5104 wxPrintf(_T("%s => "), format
);
5107 if ( dt
.ParseRfc822Date(format
) )
5109 wxPrintf(_T("%s "), dt
.Format().c_str());
5111 if ( parseTestDates
[n
].good
)
5113 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
5120 wxPrintf(_T("(ERROR: should be %s)\n"), dtReal
.Format().c_str());
5125 wxPuts(_T("(ERROR: bad format)"));
5130 wxPrintf(_T("bad format (%s)\n"),
5131 parseTestDates
[n
].good
? "ERROR" : "ok");
5136 static void TestDateTimeInteractive()
5138 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
5144 wxPrintf(_T("Enter a date: "));
5145 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
5148 // kill the last '\n'
5149 buf
[wxStrlen(buf
) - 1] = 0;
5152 const wxChar
*p
= dt
.ParseDate(buf
);
5155 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
5161 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
5164 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
5165 dt
.Format(_T("%b %d, %Y")).c_str(),
5167 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
5168 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
5169 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
5172 wxPuts(_T("\n*** done ***"));
5175 static void TestTimeMS()
5177 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
5179 wxDateTime dt1
= wxDateTime::Now(),
5180 dt2
= wxDateTime::UNow();
5182 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
5183 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5184 wxPrintf(_T("Dummy loop: "));
5185 for ( int i
= 0; i
< 6000; i
++ )
5187 //for ( int j = 0; j < 10; j++ )
5190 s
.Printf(_T("%g"), sqrt(i
));
5196 wxPuts(_T(", done"));
5199 dt2
= wxDateTime::UNow();
5200 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
5202 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
5204 wxPuts(_T("\n*** done ***"));
5207 static void TestTimeArithmetics()
5209 wxPuts(_T("\n*** testing arithmetic operations on wxDateTime ***"));
5211 static const struct ArithmData
5213 ArithmData(const wxDateSpan
& sp
, const wxChar
*nam
)
5214 : span(sp
), name(nam
) { }
5218 } testArithmData
[] =
5220 ArithmData(wxDateSpan::Day(), _T("day")),
5221 ArithmData(wxDateSpan::Week(), _T("week")),
5222 ArithmData(wxDateSpan::Month(), _T("month")),
5223 ArithmData(wxDateSpan::Year(), _T("year")),
5224 ArithmData(wxDateSpan(1, 2, 3, 4), _T("year, 2 months, 3 weeks, 4 days")),
5227 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
5229 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
5231 wxDateSpan span
= testArithmData
[n
].span
;
5235 const wxChar
*name
= testArithmData
[n
].name
;
5236 wxPrintf(_T("%s + %s = %s, %s - %s = %s\n"),
5237 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
5238 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
5240 wxPrintf(_T("Going back: %s"), (dt1
- span
).FormatISODate().c_str());
5241 if ( dt1
- span
== dt
)
5243 wxPuts(_T(" (ok)"));
5247 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5250 wxPrintf(_T("Going forward: %s"), (dt2
+ span
).FormatISODate().c_str());
5251 if ( dt2
+ span
== dt
)
5253 wxPuts(_T(" (ok)"));
5257 wxPrintf(_T(" (ERROR: should be %s)\n"), dt
.FormatISODate().c_str());
5260 wxPrintf(_T("Double increment: %s"), (dt2
+ 2*span
).FormatISODate().c_str());
5261 if ( dt2
+ 2*span
== dt1
)
5263 wxPuts(_T(" (ok)"));
5267 wxPrintf(_T(" (ERROR: should be %s)\n"), dt2
.FormatISODate().c_str());
5274 static void TestTimeHolidays()
5276 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
5278 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
5279 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
5280 dtEnd
= dtStart
.GetLastMonthDay();
5282 wxDateTimeArray hol
;
5283 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
5285 const wxChar
*format
= _T("%d-%b-%Y (%a)");
5287 wxPrintf(_T("All holidays between %s and %s:\n"),
5288 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
5290 size_t count
= hol
.GetCount();
5291 for ( size_t n
= 0; n
< count
; n
++ )
5293 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
5299 static void TestTimeZoneBug()
5301 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
5303 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
5304 for ( int i
= 0; i
< 31; i
++ )
5306 wxPrintf(_T("Date %s: week day %s.\n"),
5307 date
.Format(_T("%d-%m-%Y")).c_str(),
5308 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
5310 date
+= wxDateSpan::Day();
5316 static void TestTimeSpanFormat()
5318 wxPuts(_T("\n*** wxTimeSpan tests ***"));
5320 static const wxChar
*formats
[] =
5322 _T("(default) %H:%M:%S"),
5323 _T("%E weeks and %D days"),
5324 _T("%l milliseconds"),
5325 _T("(with ms) %H:%M:%S:%l"),
5326 _T("100%% of minutes is %M"), // test "%%"
5327 _T("%D days and %H hours"),
5328 _T("or also %S seconds"),
5331 wxTimeSpan
ts1(1, 2, 3, 4),
5333 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
5335 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
5336 ts1
.Format(formats
[n
]).c_str(),
5337 ts2
.Format(formats
[n
]).c_str());
5343 #endif // TEST_DATETIME
5345 // ----------------------------------------------------------------------------
5346 // wxTextInput/OutputStream
5347 // ----------------------------------------------------------------------------
5349 #ifdef TEST_TEXTSTREAM
5351 #include "wx/txtstrm.h"
5352 #include "wx/wfstream.h"
5354 static void TestTextInputStream()
5356 wxPuts(_T("\n*** wxTextInputStream test ***"));
5358 wxFileInputStream
fsIn(_T("testdata.fc"));
5361 wxPuts(_T("ERROR: couldn't open file."));
5365 wxTextInputStream
tis(fsIn
);
5370 const wxString s
= tis
.ReadLine();
5372 // line could be non empty if the last line of the file isn't
5373 // terminated with EOL
5374 if ( fsIn
.Eof() && s
.empty() )
5377 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
5382 #endif // TEST_TEXTSTREAM
5384 // ----------------------------------------------------------------------------
5386 // ----------------------------------------------------------------------------
5390 #include "wx/thread.h"
5392 static size_t gs_counter
= (size_t)-1;
5393 static wxCriticalSection gs_critsect
;
5394 static wxSemaphore gs_cond
;
5396 class MyJoinableThread
: public wxThread
5399 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
5400 { m_n
= n
; Create(); }
5402 // thread execution starts here
5403 virtual ExitCode
Entry();
5409 wxThread::ExitCode
MyJoinableThread::Entry()
5411 unsigned long res
= 1;
5412 for ( size_t n
= 1; n
< m_n
; n
++ )
5416 // it's a loooong calculation :-)
5420 return (ExitCode
)res
;
5423 class MyDetachedThread
: public wxThread
5426 MyDetachedThread(size_t n
, wxChar ch
)
5430 m_cancelled
= false;
5435 // thread execution starts here
5436 virtual ExitCode
Entry();
5439 virtual void OnExit();
5442 size_t m_n
; // number of characters to write
5443 wxChar m_ch
; // character to write
5445 bool m_cancelled
; // false if we exit normally
5448 wxThread::ExitCode
MyDetachedThread::Entry()
5451 wxCriticalSectionLocker
lock(gs_critsect
);
5452 if ( gs_counter
== (size_t)-1 )
5458 for ( size_t n
= 0; n
< m_n
; n
++ )
5460 if ( TestDestroy() )
5470 wxThread::Sleep(100);
5476 void MyDetachedThread::OnExit()
5478 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
5480 wxCriticalSectionLocker
lock(gs_critsect
);
5481 if ( !--gs_counter
&& !m_cancelled
)
5485 static void TestDetachedThreads()
5487 wxPuts(_T("\n*** Testing detached threads ***"));
5489 static const size_t nThreads
= 3;
5490 MyDetachedThread
*threads
[nThreads
];
5492 for ( n
= 0; n
< nThreads
; n
++ )
5494 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
5497 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
5498 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
5500 for ( n
= 0; n
< nThreads
; n
++ )
5505 // wait until all threads terminate
5511 static void TestJoinableThreads()
5513 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
5515 // calc 10! in the background
5516 MyJoinableThread
thread(10);
5519 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
5520 (unsigned long)thread
.Wait());
5523 static void TestThreadSuspend()
5525 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
5527 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
5531 // this is for this demo only, in a real life program we'd use another
5532 // condition variable which would be signaled from wxThread::Entry() to
5533 // tell us that the thread really started running - but here just wait a
5534 // bit and hope that it will be enough (the problem is, of course, that
5535 // the thread might still not run when we call Pause() which will result
5537 wxThread::Sleep(300);
5539 for ( size_t n
= 0; n
< 3; n
++ )
5543 wxPuts(_T("\nThread suspended"));
5546 // don't sleep but resume immediately the first time
5547 wxThread::Sleep(300);
5549 wxPuts(_T("Going to resume the thread"));
5554 wxPuts(_T("Waiting until it terminates now"));
5556 // wait until the thread terminates
5562 static void TestThreadDelete()
5564 // As above, using Sleep() is only for testing here - we must use some
5565 // synchronisation object instead to ensure that the thread is still
5566 // running when we delete it - deleting a detached thread which already
5567 // terminated will lead to a crash!
5569 wxPuts(_T("\n*** Testing thread delete function ***"));
5571 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
5575 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
5577 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
5581 wxThread::Sleep(300);
5585 wxPuts(_T("\nDeleted a running thread."));
5587 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
5591 wxThread::Sleep(300);
5597 wxPuts(_T("\nDeleted a sleeping thread."));
5599 MyJoinableThread
thread3(20);
5604 wxPuts(_T("\nDeleted a joinable thread."));
5606 MyJoinableThread
thread4(2);
5609 wxThread::Sleep(300);
5613 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
5618 class MyWaitingThread
: public wxThread
5621 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
5624 m_condition
= condition
;
5629 virtual ExitCode
Entry()
5631 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
5636 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
5640 m_condition
->Wait();
5643 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
5651 wxCondition
*m_condition
;
5654 static void TestThreadConditions()
5657 wxCondition
condition(mutex
);
5659 // otherwise its difficult to understand which log messages pertain to
5661 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
5662 // condition.GetId(), gs_cond.GetId());
5664 // create and launch threads
5665 MyWaitingThread
*threads
[10];
5668 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
5670 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
5673 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
5678 // wait until all threads run
5679 wxPuts(_T("Main thread is waiting for the other threads to start"));
5682 size_t nRunning
= 0;
5683 while ( nRunning
< WXSIZEOF(threads
) )
5689 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
5693 wxPuts(_T("Main thread: all threads started up."));
5696 wxThread::Sleep(500);
5699 // now wake one of them up
5700 wxPrintf(_T("Main thread: about to signal the condition.\n"));
5705 wxThread::Sleep(200);
5707 // wake all the (remaining) threads up, so that they can exit
5708 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
5710 condition
.Broadcast();
5712 // give them time to terminate (dirty!)
5713 wxThread::Sleep(500);
5716 #include "wx/utils.h"
5718 class MyExecThread
: public wxThread
5721 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
5727 virtual ExitCode
Entry()
5729 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
5736 static void TestThreadExec()
5738 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
5740 MyExecThread
thread(_T("true"));
5743 wxPrintf(_T("Main program exit code: %ld.\n"),
5744 wxExecute(_T("false"), wxEXEC_SYNC
));
5746 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
5750 #include "wx/datetime.h"
5752 class MySemaphoreThread
: public wxThread
5755 MySemaphoreThread(int i
, wxSemaphore
*sem
)
5756 : wxThread(wxTHREAD_JOINABLE
),
5763 virtual ExitCode
Entry()
5765 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
5766 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5770 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
5771 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5775 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
5776 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
5788 WX_DEFINE_ARRAY(wxThread
*, ArrayThreads
);
5790 static void TestSemaphore()
5792 wxPuts(_T("*** Testing wxSemaphore class. ***"));
5794 static const int SEM_LIMIT
= 3;
5796 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
5797 ArrayThreads threads
;
5799 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
5801 threads
.Add(new MySemaphoreThread(i
, &sem
));
5802 threads
.Last()->Run();
5805 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
5812 #endif // TEST_THREADS
5814 // ----------------------------------------------------------------------------
5816 // ----------------------------------------------------------------------------
5820 #include "wx/dynarray.h"
5822 typedef unsigned short ushort
;
5824 #define DefineCompare(name, T) \
5826 int wxCMPFUNC_CONV name ## CompareValues(T first, T second) \
5828 return first - second; \
5831 int wxCMPFUNC_CONV name ## Compare(T* first, T* second) \
5833 return *first - *second; \
5836 int wxCMPFUNC_CONV name ## RevCompare(T* first, T* second) \
5838 return *second - *first; \
5841 DefineCompare(UShort, ushort);
5842 DefineCompare(Int
, int);
5844 // test compilation of all macros
5845 WX_DEFINE_ARRAY_SHORT(ushort
, wxArrayUShort
);
5846 WX_DEFINE_SORTED_ARRAY_SHORT(ushort
, wxSortedArrayUShortNoCmp
);
5847 WX_DEFINE_SORTED_ARRAY_CMP_SHORT(ushort
, UShortCompareValues
, wxSortedArrayUShort
);
5848 WX_DEFINE_SORTED_ARRAY_CMP_INT(int, IntCompareValues
, wxSortedArrayInt
);
5850 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
5851 #include "wx/arrimpl.cpp"
5852 WX_DEFINE_OBJARRAY(ArrayBars
);
5854 static void PrintArray(const wxChar
* name
, const wxArrayString
& array
)
5856 wxPrintf(_T("Dump of the array '%s'\n"), name
);
5858 size_t nCount
= array
.GetCount();
5859 for ( size_t n
= 0; n
< nCount
; n
++ )
5861 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
5865 static void PrintArray(const wxChar
* name
, const wxSortedArrayString
& array
)
5867 wxPrintf(_T("Dump of the array '%s'\n"), name
);
5869 size_t nCount
= array
.GetCount();
5870 for ( size_t n
= 0; n
< nCount
; n
++ )
5872 wxPrintf(_T("\t%s[%u] = '%s'\n"), name
, n
, array
[n
].c_str());
5876 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
5877 const wxString
& second
)
5879 return first
.length() - second
.length();
5882 #define TestArrayOf(name) \
5884 static void PrintArray(const wxChar* name, const wxSortedArray##name & array) \
5886 wxPrintf(_T("Dump of the array '%s'\n"), name); \
5888 size_t nCount = array.GetCount(); \
5889 for ( size_t n = 0; n < nCount; n++ ) \
5891 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
5895 static void PrintArray(const wxChar* name, const wxArray##name & array) \
5897 wxPrintf(_T("Dump of the array '%s'\n"), name); \
5899 size_t nCount = array.GetCount(); \
5900 for ( size_t n = 0; n < nCount; n++ ) \
5902 wxPrintf(_T("\t%s[%u] = %d\n"), name, n, array[n]); \
5906 static void TestArrayOf ## name ## s() \
5908 wxPrintf(_T("*** Testing wxArray%s ***\n"), #name); \
5916 wxPuts(_T("Initially:")); \
5917 PrintArray(_T("a"), a); \
5919 wxPuts(_T("After sort:")); \
5920 a.Sort(name ## Compare); \
5921 PrintArray(_T("a"), a); \
5923 wxPuts(_T("After reverse sort:")); \
5924 a.Sort(name ## RevCompare); \
5925 PrintArray(_T("a"), a); \
5927 wxSortedArray##name b; \
5933 wxPuts(_T("Sorted array initially:")); \
5934 PrintArray(_T("b"), b); \
5937 TestArrayOf(UShort
);
5940 static void TestStlArray()
5942 wxPuts(_T("*** Testing std::vector operations ***\n"));
5946 wxArrayInt::iterator it
, en
;
5947 wxArrayInt::reverse_iterator rit
, ren
;
5949 for ( i
= 0; i
< 5; ++i
)
5952 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
5953 it
!= en
; ++it
, ++i
)
5955 wxPuts(_T("Error in iterator\n"));
5957 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
5958 rit
!= ren
; ++rit
, --i
)
5960 wxPuts(_T("Error in reverse_iterator\n"));
5962 if ( *list1
.rbegin() != *(list1
.end()-1) ||
5963 *list1
.begin() != *(list1
.rend()-1) )
5964 wxPuts(_T("Error in iterator/reverse_iterator\n"));
5966 it
= list1
.begin()+1;
5967 rit
= list1
.rbegin()+1;
5968 if ( *list1
.begin() != *(it
-1) ||
5969 *list1
.rbegin() != *(rit
-1) )
5970 wxPuts(_T("Error in iterator/reverse_iterator\n"));
5972 if ( list1
.front() != 0 || list1
.back() != 4 )
5973 wxPuts(_T("Error in front()/back()\n"));
5975 list1
.erase(list1
.begin());
5976 list1
.erase(list1
.end()-1);
5978 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
5979 it
!= en
; ++it
, ++i
)
5981 wxPuts(_T("Error in erase()\n"));
5984 wxPuts(_T("*** Testing std::vector operations finished ***\n"));
5987 static void TestArrayOfObjects()
5989 wxPuts(_T("*** Testing wxObjArray ***\n"));
5993 Bar
bar("second bar (two copies!)");
5995 wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"),
5996 bars
.GetCount(), Bar::GetNumber());
5998 bars
.Add(new Bar("first bar"));
6001 wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"),
6002 bars
.GetCount(), Bar::GetNumber());
6004 bars
.RemoveAt(1, bars
.GetCount() - 1);
6006 wxPrintf(_T("After removing all but first element: %u objects in the ")
6007 _T("array, %u objects total.\n"),
6008 bars
.GetCount(), Bar::GetNumber());
6012 wxPrintf(_T("After Empty(): %u objects in the array, %u objects total.\n"),
6013 bars
.GetCount(), Bar::GetNumber());
6016 wxPrintf(_T("Finally: no more objects in the array, %u objects total.\n"),
6020 #endif // TEST_ARRAYS
6022 // ----------------------------------------------------------------------------
6024 // ----------------------------------------------------------------------------
6028 #include "wx/timer.h"
6029 #include "wx/tokenzr.h"
6031 static void TestStringConstruction()
6033 wxPuts(_T("*** Testing wxString constructores ***"));
6035 #define TEST_CTOR(args, res) \
6038 wxPrintf(_T("wxString%s = %s "), #args, s.c_str()); \
6041 wxPuts(_T("(ok)")); \
6045 wxPrintf(_T("(ERROR: should be %s)\n"), res); \
6049 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
6050 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
6051 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
6052 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
6054 static const wxChar
*s
= _T("?really!");
6055 const wxChar
*start
= wxStrchr(s
, _T('r'));
6056 const wxChar
*end
= wxStrchr(s
, _T('!'));
6057 TEST_CTOR((start
, end
), _T("really"));
6062 static void TestString()
6072 for (int i
= 0; i
< 1000000; ++i
)
6076 c
= "! How'ya doin'?";
6079 c
= "Hello world! What's up?";
6084 wxPrintf(_T("TestString elapsed time: %ld\n"), sw
.Time());
6087 static void TestPChar()
6095 for (int i
= 0; i
< 1000000; ++i
)
6097 wxStrcpy (a
, _T("Hello"));
6098 wxStrcpy (b
, _T(" world"));
6099 wxStrcpy (c
, _T("! How'ya doin'?"));
6102 wxStrcpy (c
, _T("Hello world! What's up?"));
6103 if (wxStrcmp (c
, a
) == 0)
6104 wxStrcpy (c
, _T("Doh!"));
6107 wxPrintf(_T("TestPChar elapsed time: %ld\n"), sw
.Time());
6110 static void TestStringSub()
6112 wxString
s("Hello, world!");
6114 wxPuts(_T("*** Testing wxString substring extraction ***"));
6116 wxPrintf(_T("String = '%s'\n"), s
.c_str());
6117 wxPrintf(_T("Left(5) = '%s'\n"), s
.Left(5).c_str());
6118 wxPrintf(_T("Right(6) = '%s'\n"), s
.Right(6).c_str());
6119 wxPrintf(_T("Mid(3, 5) = '%s'\n"), s(3, 5).c_str());
6120 wxPrintf(_T("Mid(3) = '%s'\n"), s
.Mid(3).c_str());
6121 wxPrintf(_T("substr(3, 5) = '%s'\n"), s
.substr(3, 5).c_str());
6122 wxPrintf(_T("substr(3) = '%s'\n"), s
.substr(3).c_str());
6124 static const wxChar
*prefixes
[] =
6128 _T("Hello, world!"),
6129 _T("Hello, world!!!"),
6135 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
6137 wxString prefix
= prefixes
[n
], rest
;
6138 bool rc
= s
.StartsWith(prefix
, &rest
);
6139 wxPrintf(_T("StartsWith('%s') = %s"), prefix
.c_str(), rc
? _T("true") : _T("false"));
6142 wxPrintf(_T(" (the rest is '%s')\n"), rest
.c_str());
6153 static void TestStringFormat()
6155 wxPuts(_T("*** Testing wxString formatting ***"));
6158 s
.Printf(_T("%03d"), 18);
6160 wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str());
6161 wxPrintf(_T("Number 18: %s\n"), s
.c_str());
6166 // returns "not found" for npos, value for all others
6167 static wxString
PosToString(size_t res
)
6169 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
6170 : wxString::Format(_T("%u"), res
);
6174 static void TestStringFind()
6176 wxPuts(_T("*** Testing wxString find() functions ***"));
6178 static const wxChar
*strToFind
= _T("ell");
6179 static const struct StringFindTest
6183 result
; // of searching "ell" in str
6186 { _T("Well, hello world"), 0, 1 },
6187 { _T("Well, hello world"), 6, 7 },
6188 { _T("Well, hello world"), 9, wxString::npos
},
6191 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
6193 const StringFindTest
& ft
= findTestData
[n
];
6194 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
6196 wxPrintf(_T("Index of '%s' in '%s' starting from %u is %s "),
6197 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
6199 size_t resTrue
= ft
.result
;
6200 if ( res
== resTrue
)
6206 wxPrintf(_T("(ERROR: should be %s)\n"),
6207 PosToString(resTrue
).c_str());
6214 static void TestStringTokenizer()
6216 wxPuts(_T("*** Testing wxStringTokenizer ***"));
6218 static const wxChar
*modeNames
[] =
6222 _T("return all empty"),
6227 static const struct StringTokenizerTest
6229 const wxChar
*str
; // string to tokenize
6230 const wxChar
*delims
; // delimiters to use
6231 size_t count
; // count of token
6232 wxStringTokenizerMode mode
; // how should we tokenize it
6233 } tokenizerTestData
[] =
6235 { _T(""), _T(" "), 0 },
6236 { _T("Hello, world"), _T(" "), 2 },
6237 { _T("Hello, world "), _T(" "), 2 },
6238 { _T("Hello, world"), _T(","), 2 },
6239 { _T("Hello, world!"), _T(",!"), 2 },
6240 { _T("Hello,, world!"), _T(",!"), 3 },
6241 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
6242 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
6243 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
6244 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
6245 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
6246 { _T("01/02/99"), _T("/-"), 3 },
6247 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
6250 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
6252 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
6253 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
6255 size_t count
= tkz
.CountTokens();
6256 wxPrintf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
6257 MakePrintable(tt
.str
).c_str(),
6259 MakePrintable(tt
.delims
).c_str(),
6260 modeNames
[tkz
.GetMode()]);
6261 if ( count
== tt
.count
)
6267 wxPrintf(_T("(ERROR: should be %u)\n"), tt
.count
);
6272 // if we emulate strtok(), check that we do it correctly
6273 wxChar
*buf
, *s
= NULL
, *last
;
6275 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
6277 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
6278 wxStrcpy(buf
, tt
.str
);
6280 s
= wxStrtok(buf
, tt
.delims
, &last
);
6287 // now show the tokens themselves
6289 while ( tkz
.HasMoreTokens() )
6291 wxString token
= tkz
.GetNextToken();
6293 wxPrintf(_T("\ttoken %u: '%s'"),
6295 MakePrintable(token
).c_str());
6301 wxPuts(_T(" (ok)"));
6305 wxPrintf(_T(" (ERROR: should be %s)\n"), s
);
6308 s
= wxStrtok(NULL
, tt
.delims
, &last
);
6312 // nothing to compare with
6317 if ( count2
!= count
)
6319 wxPuts(_T("\tERROR: token count mismatch"));
6328 static void TestStringReplace()
6330 wxPuts(_T("*** Testing wxString::replace ***"));
6332 static const struct StringReplaceTestData
6334 const wxChar
*original
; // original test string
6335 size_t start
, len
; // the part to replace
6336 const wxChar
*replacement
; // the replacement string
6337 const wxChar
*result
; // and the expected result
6338 } stringReplaceTestData
[] =
6340 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
6341 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
6342 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
6343 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
6344 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
6347 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
6349 const StringReplaceTestData data
= stringReplaceTestData
[n
];
6351 wxString original
= data
.original
;
6352 original
.replace(data
.start
, data
.len
, data
.replacement
);
6354 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
6355 data
.original
, data
.start
, data
.len
, data
.replacement
,
6358 if ( original
== data
.result
)
6364 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
6371 static void TestStringMatch()
6373 wxPuts(_T("*** Testing wxString::Matches() ***"));
6375 static const struct StringMatchTestData
6378 const wxChar
*wildcard
;
6380 } stringMatchTestData
[] =
6382 { _T("foobar"), _T("foo*"), 1 },
6383 { _T("foobar"), _T("*oo*"), 1 },
6384 { _T("foobar"), _T("*bar"), 1 },
6385 { _T("foobar"), _T("??????"), 1 },
6386 { _T("foobar"), _T("f??b*"), 1 },
6387 { _T("foobar"), _T("f?b*"), 0 },
6388 { _T("foobar"), _T("*goo*"), 0 },
6389 { _T("foobar"), _T("*foo"), 0 },
6390 { _T("foobarfoo"), _T("*foo"), 1 },
6391 { _T(""), _T("*"), 1 },
6392 { _T(""), _T("?"), 0 },
6395 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
6397 const StringMatchTestData
& data
= stringMatchTestData
[n
];
6398 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
6399 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
6401 matches
? _T("matches") : _T("doesn't match"),
6403 matches
== data
.matches
? _T("ok") : _T("ERROR"));
6409 #endif // TEST_STRINGS
6411 // ----------------------------------------------------------------------------
6413 // ----------------------------------------------------------------------------
6415 #ifdef TEST_SNGLINST
6416 #include "wx/snglinst.h"
6417 #endif // TEST_SNGLINST
6419 static int MyStringCompare(wxString
* s1
, wxString
* s2
)
6421 return wxStrcmp(s1
->c_str(), s2
->c_str());
6424 static int MyStringReverseCompare(wxString
* s1
, wxString
* s2
)
6426 return -wxStrcmp(s1
->c_str(), s2
->c_str());
6429 int main(int argc
, char **argv
)
6431 wxApp::CheckBuildOptions(wxBuildOptions());
6433 wxInitializer initializer
;
6436 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
6441 #ifdef TEST_SNGLINST
6442 wxSingleInstanceChecker checker
;
6443 if ( checker
.Create(_T(".wxconsole.lock")) )
6445 if ( checker
.IsAnotherRunning() )
6447 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
6452 // wait some time to give time to launch another instance
6453 wxPrintf(_T("Press \"Enter\" to continue..."));
6456 else // failed to create
6458 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
6460 #endif // TEST_SNGLINST
6464 #endif // TEST_CHARSET
6467 TestCmdLineConvert();
6469 #if wxUSE_CMDLINE_PARSER
6470 static const wxCmdLineEntryDesc cmdLineDesc
[] =
6472 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"),
6473 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
6474 { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") },
6475 { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"), _T("be quiet") },
6477 { wxCMD_LINE_OPTION
, _T("o"), _T("output"), _T("output file") },
6478 { wxCMD_LINE_OPTION
, _T("i"), _T("input"), _T("input dir") },
6479 { wxCMD_LINE_OPTION
, _T("s"), _T("size"), _T("output block size"),
6480 wxCMD_LINE_VAL_NUMBER
},
6481 { wxCMD_LINE_OPTION
, _T("d"), _T("date"), _T("output file date"),
6482 wxCMD_LINE_VAL_DATE
},
6484 { wxCMD_LINE_PARAM
, NULL
, NULL
, _T("input file"),
6485 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
6491 wxChar
**wargv
= new wxChar
*[argc
+ 1];
6494 for ( int n
= 0; n
< argc
; n
++ )
6496 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
6497 wargv
[n
] = wxStrdup(warg
);
6504 #endif // wxUSE_UNICODE
6506 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
6510 for ( int n
= 0; n
< argc
; n
++ )
6515 #endif // wxUSE_UNICODE
6517 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
6518 wxCMD_LINE_VAL_STRING
,
6519 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
6521 switch ( parser
.Parse() )
6524 wxLogMessage(_T("Help was given, terminating."));
6528 ShowCmdLine(parser
);
6532 wxLogMessage(_T("Syntax error detected, aborting."));
6535 #endif // wxUSE_CMDLINE_PARSER
6537 #endif // TEST_CMDLINE
6545 TestStringConstruction();
6548 TestStringTokenizer();
6549 TestStringReplace();
6555 #endif // TEST_STRINGS
6558 if ( 1 || TEST_ALL
)
6561 a1
.Add(_T("tiger"));
6563 a1
.Add(_T("lion"), 3);
6565 a1
.Add(_T("human"));
6568 wxPuts(_T("*** Initially:"));
6570 PrintArray(_T("a1"), a1
);
6572 wxArrayString
a2(a1
);
6573 PrintArray(_T("a2"), a2
);
6576 wxSortedArrayString
a3(a1
);
6578 wxSortedArrayString a3
;
6579 for (wxArrayString::iterator it
= a1
.begin(), en
= a1
.end();
6583 PrintArray(_T("a3"), a3
);
6585 wxPuts(_T("*** After deleting three strings from a1"));
6588 PrintArray(_T("a1"), a1
);
6589 PrintArray(_T("a2"), a2
);
6590 PrintArray(_T("a3"), a3
);
6593 wxPuts(_T("*** After reassigning a1 to a2 and a3"));
6595 PrintArray(_T("a2"), a2
);
6596 PrintArray(_T("a3"), a3
);
6599 wxPuts(_T("*** After sorting a1"));
6600 a1
.Sort(&MyStringCompare
);
6601 PrintArray(_T("a1"), a1
);
6603 wxPuts(_T("*** After sorting a1 in reverse order"));
6604 a1
.Sort(&MyStringReverseCompare
);
6605 PrintArray(_T("a1"), a1
);
6608 wxPuts(_T("*** After sorting a1 by the string length"));
6609 a1
.Sort(&StringLenCompare
);
6610 PrintArray(_T("a1"), a1
);
6613 TestArrayOfObjects();
6614 TestArrayOfUShorts();
6619 #endif // TEST_ARRAYS
6630 #ifdef TEST_DLLLOADER
6632 #endif // TEST_DLLLOADER
6636 #endif // TEST_ENVIRON
6640 #endif // TEST_EXECUTE
6642 #ifdef TEST_FILECONF
6644 #endif // TEST_FILECONF
6653 #endif // TEST_LOCALE
6656 wxPuts(_T("*** Testing wxLog ***"));
6659 for ( size_t n
= 0; n
< 8000; n
++ )
6661 s
<< (wxChar
)(_T('A') + (n
% 26));
6664 wxLogWarning(_T("The length of the string is %lu"),
6665 (unsigned long)s
.length());
6668 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
6670 // this one shouldn't be truncated
6673 // but this one will because log functions use fixed size buffer
6674 // (note that it doesn't need '\n' at the end neither - will be added
6676 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
6688 #ifdef TEST_FILENAME
6692 fn
.Assign(_T("c:\\foo"), _T("bar.baz"));
6693 fn
.Assign(_T("/u/os9-port/Viewer/tvision/WEI2HZ-3B3-14_05-04-00MSC1.asc"));
6698 TestFileNameConstruction();
6701 TestFileNameConstruction();
6702 TestFileNameMakeRelative();
6703 TestFileNameMakeAbsolute();
6704 TestFileNameSplit();
6707 TestFileNameComparison();
6708 TestFileNameOperations();
6710 #endif // TEST_FILENAME
6712 #ifdef TEST_FILETIME
6716 #endif // TEST_FILETIME
6719 wxLog::AddTraceMask(FTP_TRACE_MASK
);
6720 if ( TestFtpConnect() )
6731 if ( TEST_INTERACTIVE
)
6732 TestFtpInteractive();
6734 //else: connecting to the FTP server failed
6740 #ifdef TEST_LONGLONG
6741 // seed pseudo random generator
6742 srand((unsigned)time(NULL
));
6751 TestMultiplication();
6754 TestLongLongConversion();
6755 TestBitOperations();
6756 TestLongLongComparison();
6757 TestLongLongToString();
6758 TestLongLongPrintf();
6760 #endif // TEST_LONGLONG
6768 #endif // TEST_HASHMAP
6771 wxLog::AddTraceMask(_T("mime"));
6776 TestMimeAssociate();
6781 #ifdef TEST_INFO_FUNCTIONS
6787 if ( TEST_INTERACTIVE
)
6790 #endif // TEST_INFO_FUNCTIONS
6792 #ifdef TEST_PATHLIST
6794 #endif // TEST_PATHLIST
6802 #endif // TEST_PRINTF
6806 #endif // TEST_REGCONF
6809 // TODO: write a real test using src/regex/tests file
6814 TestRegExSubmatch();
6815 TestRegExReplacement();
6817 if ( TEST_INTERACTIVE
)
6818 TestRegExInteractive();
6820 #endif // TEST_REGEX
6822 #ifdef TEST_REGISTRY
6824 TestRegistryAssociation();
6825 #endif // TEST_REGISTRY
6830 #endif // TEST_SOCKETS
6838 #endif // TEST_STREAMS
6840 #ifdef TEST_TEXTSTREAM
6841 TestTextInputStream();
6842 #endif // TEST_TEXTSTREAM
6845 int nCPUs
= wxThread::GetCPUCount();
6846 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
6848 wxThread::SetConcurrency(nCPUs
);
6850 TestDetachedThreads();
6853 TestJoinableThreads();
6854 TestThreadSuspend();
6856 TestThreadConditions();
6860 #endif // TEST_THREADS
6864 #endif // TEST_TIMER
6866 #ifdef TEST_DATETIME
6879 TestTimeArithmetics();
6882 TestTimeSpanFormat();
6890 if ( TEST_INTERACTIVE
)
6891 TestDateTimeInteractive();
6892 #endif // TEST_DATETIME
6894 #ifdef TEST_SCOPEGUARD
6899 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
6901 #endif // TEST_USLEEP
6906 #endif // TEST_VCARD
6910 #endif // TEST_VOLUME
6913 TestUnicodeToFromAscii();
6914 #endif // TEST_UNICODE
6918 TestEncodingConverter();
6919 #endif // TEST_WCHAR
6922 TestZipStreamRead();
6923 TestZipFileSystem();
6927 TestZlibStreamWrite();
6928 TestZlibStreamRead();