1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
24 #include "wx/string.h"
28 #include "wx/apptrait.h"
29 #include "wx/platinfo.h"
30 #include "wx/wxchar.h"
32 // without this pragma, the stupid compiler precompiles #defines below so that
33 // changing them doesn't "take place" later!
38 // ----------------------------------------------------------------------------
39 // conditional compilation
40 // ----------------------------------------------------------------------------
43 A note about all these conditional compilation macros: this file is used
44 both as a test suite for various non-GUI wxWidgets classes and as a
45 scratchpad for quick tests. So there are two compilation modes: if you
46 define TEST_ALL all tests are run, otherwise you may enable the individual
47 tests individually in the "#else" branch below.
50 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
51 // test, define it to 1 to do all tests.
66 // #define TEST_FTP --FIXME! (RN)
67 #define TEST_INFO_FUNCTIONS
77 #define TEST_SCOPEGUARD
79 // #define TEST_SOCKETS --FIXME! (RN)
80 #define TEST_STACKWALKER
83 #define TEST_TEXTSTREAM
86 // #define TEST_VCARD -- don't enable this (VZ)
87 // #define TEST_VOLUME --FIXME! (RN)
94 // some tests are interactive, define this to run them
95 #ifdef TEST_INTERACTIVE
96 #undef TEST_INTERACTIVE
98 #define TEST_INTERACTIVE 1
100 #define TEST_INTERACTIVE 0
103 // ============================================================================
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 #if defined(TEST_SOCKETS)
113 // replace TABs with \t and CRs with \n
114 static wxString
MakePrintable(const wxChar
*s
)
117 (void)str
.Replace(_T("\t"), _T("\\t"));
118 (void)str
.Replace(_T("\n"), _T("\\n"));
119 (void)str
.Replace(_T("\r"), _T("\\r"));
124 #endif // MakePrintable() is used
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
132 #include "wx/cmdline.h"
133 #include "wx/datetime.h"
135 #if wxUSE_CMDLINE_PARSER
137 static void ShowCmdLine(const wxCmdLineParser
& parser
)
139 wxString s
= _T("Command line parsed successfully:\nInput files: ");
141 size_t count
= parser
.GetParamCount();
142 for ( size_t param
= 0; param
< count
; param
++ )
144 s
<< parser
.GetParam(param
) << ' ';
148 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
149 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
155 if ( parser
.Found(_T("o"), &strVal
) )
156 s
<< _T("Output file:\t") << strVal
<< '\n';
157 if ( parser
.Found(_T("i"), &strVal
) )
158 s
<< _T("Input dir:\t") << strVal
<< '\n';
159 if ( parser
.Found(_T("s"), &lVal
) )
160 s
<< _T("Size:\t") << lVal
<< '\n';
161 if ( parser
.Found(_T("f"), &dVal
) )
162 s
<< _T("Double:\t") << dVal
<< '\n';
163 if ( parser
.Found(_T("d"), &dt
) )
164 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
165 if ( parser
.Found(_T("project_name"), &strVal
) )
166 s
<< _T("Project:\t") << strVal
<< '\n';
171 #endif // wxUSE_CMDLINE_PARSER
173 static void TestCmdLineConvert()
175 static const wxChar
*cmdlines
[] =
178 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
179 _T("literal \\\" and \"\""),
182 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
184 const wxChar
*cmdline
= cmdlines
[n
];
185 wxPrintf(_T("Parsing: %s\n"), cmdline
);
186 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
188 size_t count
= args
.GetCount();
189 wxPrintf(_T("\targc = %u\n"), count
);
190 for ( size_t arg
= 0; arg
< count
; arg
++ )
192 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
197 #endif // TEST_CMDLINE
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
208 static const wxChar
*ROOTDIR
= _T("/");
209 static const wxChar
*TESTDIR
= _T("/usr/local/share");
210 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
211 static const wxChar
*ROOTDIR
= _T("c:\\");
212 static const wxChar
*TESTDIR
= _T("d:\\");
214 #error "don't know where the root directory is"
217 static void TestDirEnumHelper(wxDir
& dir
,
218 int flags
= wxDIR_DEFAULT
,
219 const wxString
& filespec
= wxEmptyString
)
223 if ( !dir
.IsOpened() )
226 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
229 wxPrintf(_T("\t%s\n"), filename
.c_str());
231 cont
= dir
.GetNext(&filename
);
234 wxPuts(wxEmptyString
);
239 static void TestDirEnum()
241 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
243 wxString cwd
= wxGetCwd();
244 if ( !wxDir::Exists(cwd
) )
246 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
251 if ( !dir
.IsOpened() )
253 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
257 wxPuts(_T("Enumerating everything in current directory:"));
258 TestDirEnumHelper(dir
);
260 wxPuts(_T("Enumerating really everything in current directory:"));
261 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
263 wxPuts(_T("Enumerating object files in current directory:"));
264 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
266 wxPuts(_T("Enumerating directories in current directory:"));
267 TestDirEnumHelper(dir
, wxDIR_DIRS
);
269 wxPuts(_T("Enumerating files in current directory:"));
270 TestDirEnumHelper(dir
, wxDIR_FILES
);
272 wxPuts(_T("Enumerating files including hidden in current directory:"));
273 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
277 wxPuts(_T("Enumerating everything in root directory:"));
278 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
280 wxPuts(_T("Enumerating directories in root directory:"));
281 TestDirEnumHelper(dir
, wxDIR_DIRS
);
283 wxPuts(_T("Enumerating files in root directory:"));
284 TestDirEnumHelper(dir
, wxDIR_FILES
);
286 wxPuts(_T("Enumerating files including hidden in root directory:"));
287 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
289 wxPuts(_T("Enumerating files in non existing directory:"));
290 wxDir
dirNo(_T("nosuchdir"));
291 TestDirEnumHelper(dirNo
);
296 class DirPrintTraverser
: public wxDirTraverser
299 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
301 return wxDIR_CONTINUE
;
304 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
306 wxString path
, name
, ext
;
307 wxSplitPath(dirname
, &path
, &name
, &ext
);
310 name
<< _T('.') << ext
;
313 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
315 if ( wxIsPathSeparator(*p
) )
319 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
321 return wxDIR_CONTINUE
;
325 static void TestDirTraverse()
327 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
331 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
332 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
335 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
336 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
339 // enum again with custom traverser
340 wxPuts(_T("Now enumerating directories:"));
342 DirPrintTraverser traverser
;
343 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
348 static void TestDirExists()
350 wxPuts(_T("*** Testing wxDir::Exists() ***"));
352 static const wxChar
*dirnames
[] =
355 #if defined(__WXMSW__)
358 _T("\\\\share\\file"),
362 _T("c:\\autoexec.bat"),
363 #elif defined(__UNIX__)
372 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
374 wxPrintf(_T("%-40s: %s\n"),
376 wxDir::Exists(dirnames
[n
]) ? _T("exists")
377 : _T("doesn't exist"));
385 // ----------------------------------------------------------------------------
387 // ----------------------------------------------------------------------------
391 #include "wx/dynlib.h"
393 static void TestDllLoad()
395 #if defined(__WXMSW__)
396 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
397 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
398 #elif defined(__UNIX__)
399 // weird: using just libc.so does *not* work!
400 static const wxChar
*LIB_NAME
= _T("/lib/libc.so.6");
401 static const wxChar
*FUNC_NAME
= _T("strlen");
403 #error "don't know how to test wxDllLoader on this platform"
406 wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
408 wxDynamicLibrary
lib(LIB_NAME
);
409 if ( !lib
.IsLoaded() )
411 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
415 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
416 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
419 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
420 FUNC_NAME
, LIB_NAME
);
424 wxPrintf(_T("Calling %s dynamically loaded from %s "),
425 FUNC_NAME
, LIB_NAME
);
427 if ( pfnStrlen("foo") != 3 )
429 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
433 wxPuts(_T("... ok"));
438 static const wxChar
*FUNC_NAME_AW
= _T("lstrlen");
440 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
442 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
443 if ( !pfnStrlenAorW
)
445 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
446 FUNC_NAME_AW
, LIB_NAME
);
450 if ( pfnStrlenAorW(_T("foobar")) != 6 )
452 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
459 #if defined(__WXMSW__) || defined(__UNIX__)
461 static void TestDllListLoaded()
463 wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
465 puts("\nLoaded modules:");
466 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
467 const size_t count
= dlls
.GetCount();
468 for ( size_t n
= 0; n
< count
; ++n
)
470 const wxDynamicLibraryDetails
& details
= dlls
[n
];
471 printf("%-45s", details
.GetPath().mb_str());
475 if ( details
.GetAddress(&addr
, &len
) )
477 printf(" %08lx:%08lx",
478 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
481 printf(" %s\n", details
.GetVersion().mb_str());
487 #endif // TEST_DYNLIB
489 // ----------------------------------------------------------------------------
491 // ----------------------------------------------------------------------------
495 #include "wx/utils.h"
497 static wxString
MyGetEnv(const wxString
& var
)
500 if ( !wxGetEnv(var
, &val
) )
503 val
= wxString(_T('\'')) + val
+ _T('\'');
508 static void TestEnvironment()
510 const wxChar
*var
= _T("wxTestVar");
512 wxPuts(_T("*** testing environment access functions ***"));
514 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
515 wxSetEnv(var
, _T("value for wxTestVar"));
516 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
517 wxSetEnv(var
, _T("another value"));
518 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
520 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
521 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
524 #endif // TEST_ENVIRON
526 // ----------------------------------------------------------------------------
528 // ----------------------------------------------------------------------------
532 #include "wx/utils.h"
534 static void TestExecute()
536 wxPuts(_T("*** testing wxExecute ***"));
539 #define COMMAND "echo hi"
540 #define ASYNC_COMMAND "xclock"
541 #define SHELL_COMMAND "echo hi from shell"
542 #define REDIRECT_COMMAND COMMAND "cat -n Makefile"
543 #elif defined(__WXMSW__)
544 #define COMMAND "command.com /c echo hi"
545 #define ASYNC_COMMAND "notepad"
546 #define SHELL_COMMAND "echo hi"
547 #define REDIRECT_COMMAND COMMAND
549 #error "no command to exec"
552 wxPrintf(_T("Testing wxShell: "));
554 if ( wxShell(_T(SHELL_COMMAND
)) )
557 wxPuts(_T("ERROR."));
559 wxPrintf(_T("Testing wxExecute: "));
561 if ( wxExecute(_T(COMMAND
), wxEXEC_SYNC
) == 0 )
564 wxPuts(_T("ERROR."));
566 wxPrintf(_T("Testing async wxExecute: "));
568 if ( wxExecute(ASYNC_COMMAND
) != 0 )
569 wxPuts(_T("Ok (command launched)."));
571 wxPuts(_T("ERROR."));
573 wxPrintf(_T("Testing wxExecute with redirection:\n"));
574 wxArrayString output
;
575 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
577 wxPuts(_T("ERROR."));
581 unsigned count
= output
.GetCount();
582 for ( unsigned n
= 0; n
< count
; n
++ )
584 wxPrintf("%04u:\t%s\n", n
, output
[n
]);
591 #endif // TEST_EXECUTE
593 // ----------------------------------------------------------------------------
595 // ----------------------------------------------------------------------------
600 #include "wx/ffile.h"
601 #include "wx/textfile.h"
603 static void TestFileRead()
605 wxPuts(_T("*** wxFile read test ***"));
607 wxFile
file(_T("testdata.fc"));
608 if ( file
.IsOpened() )
610 wxPrintf(_T("File length: %lu\n"), file
.Length());
612 wxPuts(_T("File dump:\n----------"));
614 static const size_t len
= 1024;
618 size_t nRead
= file
.Read(buf
, len
);
619 if ( nRead
== (size_t)wxInvalidOffset
)
621 wxPrintf(_T("Failed to read the file."));
625 fwrite(buf
, nRead
, 1, stdout
);
631 wxPuts(_T("----------"));
635 wxPrintf(_T("ERROR: can't open test file.\n"));
638 wxPuts(wxEmptyString
);
641 static void TestTextFileRead()
643 wxPuts(_T("*** wxTextFile read test ***"));
645 wxTextFile
file(_T("testdata.fc"));
648 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
649 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
653 wxPuts(_T("\nDumping the entire file:"));
654 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
656 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
658 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
660 wxPuts(_T("\nAnd now backwards:"));
661 for ( s
= file
.GetLastLine();
662 file
.GetCurrentLine() != 0;
663 s
= file
.GetPrevLine() )
665 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
667 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
671 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
674 wxPuts(wxEmptyString
);
677 static void TestFileCopy()
679 wxPuts(_T("*** Testing wxCopyFile ***"));
681 static const wxChar
*filename1
= _T("testdata.fc");
682 static const wxChar
*filename2
= _T("test2");
683 if ( !wxCopyFile(filename1
, filename2
) )
685 wxPuts(_T("ERROR: failed to copy file"));
689 wxFFile
f1(filename1
, _T("rb")),
690 f2(filename2
, _T("rb"));
692 if ( !f1
.IsOpened() || !f2
.IsOpened() )
694 wxPuts(_T("ERROR: failed to open file(s)"));
699 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
701 wxPuts(_T("ERROR: failed to read file(s)"));
705 if ( (s1
.length() != s2
.length()) ||
706 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
708 wxPuts(_T("ERROR: copy error!"));
712 wxPuts(_T("File was copied ok."));
718 if ( !wxRemoveFile(filename2
) )
720 wxPuts(_T("ERROR: failed to remove the file"));
723 wxPuts(wxEmptyString
);
726 static void TestTempFile()
728 wxPuts(_T("*** wxTempFile test ***"));
731 if ( tmpFile
.Open(_T("test2")) && tmpFile
.Write(_T("the answer is 42")) )
733 if ( tmpFile
.Commit() )
734 wxPuts(_T("File committed."));
736 wxPuts(_T("ERROR: could't commit temp file."));
738 wxRemoveFile(_T("test2"));
741 wxPuts(wxEmptyString
);
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"
824 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
828 wxString full
= fn
.GetFullPath();
830 wxString vol
, path
, name
, ext
;
831 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
833 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
834 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
836 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
837 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
838 path
.c_str(), name
.c_str(), ext
.c_str());
840 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
841 wxPrintf(_T("with volume: \t'%s'\n"),
842 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
843 wxPrintf(_T("with separator:\t'%s'\n"),
844 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
845 wxPrintf(_T("with both: \t'%s'\n"),
846 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
848 wxPuts(_T("The directories in the path are:"));
849 wxArrayString dirs
= fn
.GetDirs();
850 size_t count
= dirs
.GetCount();
851 for ( size_t n
= 0; n
< count
; n
++ )
853 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
858 static void TestFileNameTemp()
860 wxPuts(_T("*** testing wxFileName temp file creation ***"));
862 static const wxChar
*tmpprefixes
[] =
870 _T("/tmp/foo/bar"), // this one must be an error
874 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
876 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
879 // "error" is not in upper case because it may be ok
880 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
884 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
885 tmpprefixes
[n
], path
.c_str());
887 if ( !wxRemoveFile(path
) )
889 wxLogWarning(_T("Failed to remove temp file '%s'"),
896 static void TestFileNameDirManip()
898 // TODO: test AppendDir(), RemoveDir(), ...
901 static void TestFileNameComparison()
906 static void TestFileNameOperations()
911 static void TestFileNameCwd()
916 #endif // TEST_FILENAME
918 // ----------------------------------------------------------------------------
919 // wxFileName time functions
920 // ----------------------------------------------------------------------------
924 #include "wx/filename.h"
925 #include "wx/datetime.h"
927 static void TestFileGetTimes()
929 wxFileName
fn(_T("testdata.fc"));
931 wxDateTime dtAccess
, dtMod
, dtCreate
;
932 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
934 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
938 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
940 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
941 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
942 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
943 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
948 static void TestFileSetTimes()
950 wxFileName
fn(_T("testdata.fc"));
954 wxPrintf(_T("ERROR: Touch() failed.\n"));
959 #endif // TEST_FILETIME
961 // ----------------------------------------------------------------------------
963 // ----------------------------------------------------------------------------
968 #include "wx/utils.h" // for wxSetEnv
970 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
972 // find the name of the language from its value
973 static const wxChar
*GetLangName(int lang
)
975 static const wxChar
*languageNames
[] =
985 _T("ARABIC_ALGERIA"),
986 _T("ARABIC_BAHRAIN"),
991 _T("ARABIC_LEBANON"),
993 _T("ARABIC_MOROCCO"),
996 _T("ARABIC_SAUDI_ARABIA"),
999 _T("ARABIC_TUNISIA"),
1006 _T("AZERI_CYRILLIC"),
1021 _T("CHINESE_SIMPLIFIED"),
1022 _T("CHINESE_TRADITIONAL"),
1023 _T("CHINESE_HONGKONG"),
1024 _T("CHINESE_MACAU"),
1025 _T("CHINESE_SINGAPORE"),
1026 _T("CHINESE_TAIWAN"),
1032 _T("DUTCH_BELGIAN"),
1036 _T("ENGLISH_AUSTRALIA"),
1037 _T("ENGLISH_BELIZE"),
1038 _T("ENGLISH_BOTSWANA"),
1039 _T("ENGLISH_CANADA"),
1040 _T("ENGLISH_CARIBBEAN"),
1041 _T("ENGLISH_DENMARK"),
1043 _T("ENGLISH_JAMAICA"),
1044 _T("ENGLISH_NEW_ZEALAND"),
1045 _T("ENGLISH_PHILIPPINES"),
1046 _T("ENGLISH_SOUTH_AFRICA"),
1047 _T("ENGLISH_TRINIDAD"),
1048 _T("ENGLISH_ZIMBABWE"),
1056 _T("FRENCH_BELGIAN"),
1057 _T("FRENCH_CANADIAN"),
1058 _T("FRENCH_LUXEMBOURG"),
1059 _T("FRENCH_MONACO"),
1065 _T("GERMAN_AUSTRIAN"),
1066 _T("GERMAN_BELGIUM"),
1067 _T("GERMAN_LIECHTENSTEIN"),
1068 _T("GERMAN_LUXEMBOURG"),
1086 _T("ITALIAN_SWISS"),
1091 _T("KASHMIRI_INDIA"),
1109 _T("MALAY_BRUNEI_DARUSSALAM"),
1110 _T("MALAY_MALAYSIA"),
1120 _T("NORWEGIAN_BOKMAL"),
1121 _T("NORWEGIAN_NYNORSK"),
1128 _T("PORTUGUESE_BRAZILIAN"),
1131 _T("RHAETO_ROMANCE"),
1134 _T("RUSSIAN_UKRAINE"),
1140 _T("SERBIAN_CYRILLIC"),
1141 _T("SERBIAN_LATIN"),
1142 _T("SERBO_CROATIAN"),
1153 _T("SPANISH_ARGENTINA"),
1154 _T("SPANISH_BOLIVIA"),
1155 _T("SPANISH_CHILE"),
1156 _T("SPANISH_COLOMBIA"),
1157 _T("SPANISH_COSTA_RICA"),
1158 _T("SPANISH_DOMINICAN_REPUBLIC"),
1159 _T("SPANISH_ECUADOR"),
1160 _T("SPANISH_EL_SALVADOR"),
1161 _T("SPANISH_GUATEMALA"),
1162 _T("SPANISH_HONDURAS"),
1163 _T("SPANISH_MEXICAN"),
1164 _T("SPANISH_MODERN"),
1165 _T("SPANISH_NICARAGUA"),
1166 _T("SPANISH_PANAMA"),
1167 _T("SPANISH_PARAGUAY"),
1169 _T("SPANISH_PUERTO_RICO"),
1170 _T("SPANISH_URUGUAY"),
1172 _T("SPANISH_VENEZUELA"),
1176 _T("SWEDISH_FINLAND"),
1194 _T("URDU_PAKISTAN"),
1196 _T("UZBEK_CYRILLIC"),
1209 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1210 return languageNames
[lang
];
1212 return _T("INVALID");
1215 static void TestDefaultLang()
1217 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1219 static const wxChar
*langStrings
[] =
1221 NULL
, // system default
1228 _T("de_DE.iso88591"),
1230 _T("?"), // invalid lang spec
1231 _T("klingonese"), // I bet on some systems it does exist...
1234 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1235 wxLocale::GetSystemEncodingName().c_str(),
1236 wxLocale::GetSystemEncoding());
1238 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1240 const wxChar
*langStr
= langStrings
[n
];
1243 // FIXME: this doesn't do anything at all under Windows, we need
1244 // to create a new wxLocale!
1245 wxSetEnv(_T("LC_ALL"), langStr
);
1248 int lang
= gs_localeDefault
.GetSystemLanguage();
1249 wxPrintf(_T("Locale for '%s' is %s.\n"),
1250 langStr
? langStr
: _T("system default"), GetLangName(lang
));
1254 #endif // TEST_LOCALE
1256 // ----------------------------------------------------------------------------
1258 // ----------------------------------------------------------------------------
1262 #include "wx/mimetype.h"
1264 static void TestMimeEnum()
1266 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1268 wxArrayString mimetypes
;
1270 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1272 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1277 for ( size_t n
= 0; n
< count
; n
++ )
1279 wxFileType
*filetype
=
1280 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1283 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1284 mimetypes
[n
].c_str());
1288 filetype
->GetDescription(&desc
);
1289 filetype
->GetExtensions(exts
);
1291 filetype
->GetIcon(NULL
);
1294 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1297 extsAll
<< _T(", ");
1301 wxPrintf(_T("\t%s: %s (%s)\n"),
1302 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1305 wxPuts(wxEmptyString
);
1308 static void TestMimeOverride()
1310 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1312 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1313 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1315 if ( wxFile::Exists(mailcap
) )
1316 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1318 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1320 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1323 if ( wxFile::Exists(mimetypes
) )
1324 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1326 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1328 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1331 wxPuts(wxEmptyString
);
1334 static void TestMimeFilename()
1336 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1338 static const wxChar
*filenames
[] =
1346 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1348 const wxString fname
= filenames
[n
];
1349 wxString ext
= fname
.AfterLast(_T('.'));
1350 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1353 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1358 if ( !ft
->GetDescription(&desc
) )
1359 desc
= _T("<no description>");
1362 if ( !ft
->GetOpenCommand(&cmd
,
1363 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1364 cmd
= _T("<no command available>");
1366 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1368 wxPrintf(_T("To open %s (%s) do %s.\n"),
1369 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1375 wxPuts(wxEmptyString
);
1378 static void TestMimeAssociate()
1380 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1382 wxFileTypeInfo
ftInfo(
1383 _T("application/x-xyz"),
1384 _T("xyzview '%s'"), // open cmd
1385 _T(""), // print cmd
1386 _T("XYZ File"), // description
1387 _T(".xyz"), // extensions
1388 wxNullPtr
// end of extensions
1390 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1392 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1395 wxPuts(_T("ERROR: failed to create association!"));
1399 // TODO: read it back
1403 wxPuts(wxEmptyString
);
1408 // ----------------------------------------------------------------------------
1409 // module dependencies feature
1410 // ----------------------------------------------------------------------------
1414 #include "wx/module.h"
1416 class wxTestModule
: public wxModule
1419 virtual bool OnInit() { wxPrintf(_T("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1420 virtual void OnExit() { wxPrintf(_T("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1423 class wxTestModuleA
: public wxTestModule
1428 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1431 class wxTestModuleB
: public wxTestModule
1436 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1439 class wxTestModuleC
: public wxTestModule
1444 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1447 class wxTestModuleD
: public wxTestModule
1452 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1455 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1456 wxTestModuleC::wxTestModuleC()
1458 AddDependency(CLASSINFO(wxTestModuleD
));
1461 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1462 wxTestModuleA::wxTestModuleA()
1464 AddDependency(CLASSINFO(wxTestModuleB
));
1465 AddDependency(CLASSINFO(wxTestModuleD
));
1468 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1469 wxTestModuleD::wxTestModuleD()
1473 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1474 wxTestModuleB::wxTestModuleB()
1476 AddDependency(CLASSINFO(wxTestModuleD
));
1477 AddDependency(CLASSINFO(wxTestModuleC
));
1480 #endif // TEST_MODULE
1482 // ----------------------------------------------------------------------------
1483 // misc information functions
1484 // ----------------------------------------------------------------------------
1486 #ifdef TEST_INFO_FUNCTIONS
1488 #include "wx/utils.h"
1490 #if TEST_INTERACTIVE
1491 static void TestDiskInfo()
1493 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1497 wxChar pathname
[128];
1498 wxPrintf(_T("\nEnter a directory name: "));
1499 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1502 // kill the last '\n'
1503 pathname
[wxStrlen(pathname
) - 1] = 0;
1505 wxLongLong total
, free
;
1506 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1508 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1512 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1513 (total
/ 1024).ToString().c_str(),
1514 (free
/ 1024).ToString().c_str(),
1519 #endif // TEST_INTERACTIVE
1521 static void TestOsInfo()
1523 wxPuts(_T("*** Testing OS info functions ***\n"));
1526 wxGetOsVersion(&major
, &minor
);
1527 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1528 wxGetOsDescription().c_str(), major
, minor
);
1530 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1532 wxPrintf(_T("Host name is %s (%s).\n"),
1533 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1535 wxPuts(wxEmptyString
);
1538 static void TestPlatformInfo()
1540 wxPuts(_T("*** Testing wxPlatformInfo functions ***\n"));
1542 // get this platform
1543 wxPlatformInfo plat
;
1545 wxPrintf(_T("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1546 wxPrintf(_T("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1547 wxPrintf(_T("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1548 wxPrintf(_T("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1549 wxPrintf(_T("Architecture is: %s\n"), plat
.GetArchName().c_str());
1550 wxPrintf(_T("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1552 wxPuts(wxEmptyString
);
1555 static void TestUserInfo()
1557 wxPuts(_T("*** Testing user info functions ***\n"));
1559 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1560 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1561 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1562 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1564 wxPuts(wxEmptyString
);
1567 #endif // TEST_INFO_FUNCTIONS
1569 // ----------------------------------------------------------------------------
1571 // ----------------------------------------------------------------------------
1573 #ifdef TEST_PATHLIST
1576 #define CMD_IN_PATH _T("ls")
1578 #define CMD_IN_PATH _T("command.com")
1581 static void TestPathList()
1583 wxPuts(_T("*** Testing wxPathList ***\n"));
1585 wxPathList pathlist
;
1586 pathlist
.AddEnvList(_T("PATH"));
1587 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1590 wxPrintf(_T("ERROR: command not found in the path.\n"));
1594 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
1598 #endif // TEST_PATHLIST
1600 // ----------------------------------------------------------------------------
1601 // regular expressions
1602 // ----------------------------------------------------------------------------
1606 #include "wx/regex.h"
1608 static void TestRegExInteractive()
1610 wxPuts(_T("*** Testing RE interactively ***"));
1614 wxChar pattern
[128];
1615 wxPrintf(_T("\nEnter a pattern: "));
1616 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1619 // kill the last '\n'
1620 pattern
[wxStrlen(pattern
) - 1] = 0;
1623 if ( !re
.Compile(pattern
) )
1631 wxPrintf(_T("Enter text to match: "));
1632 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1635 // kill the last '\n'
1636 text
[wxStrlen(text
) - 1] = 0;
1638 if ( !re
.Matches(text
) )
1640 wxPrintf(_T("No match.\n"));
1644 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1647 for ( size_t n
= 1; ; n
++ )
1649 if ( !re
.GetMatch(&start
, &len
, n
) )
1654 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1655 n
, wxString(text
+ start
, len
).c_str());
1662 #endif // TEST_REGEX
1664 // ----------------------------------------------------------------------------
1666 // ----------------------------------------------------------------------------
1669 NB: this stuff was taken from the glibc test suite and modified to build
1670 in wxWidgets: if I read the copyright below properly, this shouldn't
1676 #ifdef wxTEST_PRINTF
1677 // use our functions from wxchar.cpp
1681 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1682 // in the tests below
1683 int wxPrintf( const wxChar
*format
, ... );
1684 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1687 #include "wx/longlong.h"
1691 static void rfg1 (void);
1692 static void rfg2 (void);
1696 fmtchk (const wxChar
*fmt
)
1698 (void) wxPrintf(_T("%s:\t`"), fmt
);
1699 (void) wxPrintf(fmt
, 0x12);
1700 (void) wxPrintf(_T("'\n"));
1704 fmtst1chk (const wxChar
*fmt
)
1706 (void) wxPrintf(_T("%s:\t`"), fmt
);
1707 (void) wxPrintf(fmt
, 4, 0x12);
1708 (void) wxPrintf(_T("'\n"));
1712 fmtst2chk (const wxChar
*fmt
)
1714 (void) wxPrintf(_T("%s:\t`"), fmt
);
1715 (void) wxPrintf(fmt
, 4, 4, 0x12);
1716 (void) wxPrintf(_T("'\n"));
1719 /* This page is covered by the following copyright: */
1721 /* (C) Copyright C E Chew
1723 * Feel free to copy, use and distribute this software provided:
1725 * 1. you do not pretend that you wrote it
1726 * 2. you leave this copyright notice intact.
1730 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1737 /* Formatted Output Test
1739 * This exercises the output formatting code.
1742 wxChar
*PointerNull
= NULL
;
1749 wxChar
*prefix
= buf
;
1752 wxPuts(_T("\nFormatted output test"));
1753 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
1754 wxStrcpy(prefix
, _T("%"));
1755 for (i
= 0; i
< 2; i
++) {
1756 for (j
= 0; j
< 2; j
++) {
1757 for (k
= 0; k
< 2; k
++) {
1758 for (l
= 0; l
< 2; l
++) {
1759 wxStrcpy(prefix
, _T("%"));
1760 if (i
== 0) wxStrcat(prefix
, _T("-"));
1761 if (j
== 0) wxStrcat(prefix
, _T("+"));
1762 if (k
== 0) wxStrcat(prefix
, _T("#"));
1763 if (l
== 0) wxStrcat(prefix
, _T("0"));
1764 wxPrintf(_T("%5s |"), prefix
);
1765 wxStrcpy(tp
, prefix
);
1766 wxStrcat(tp
, _T("6d |"));
1768 wxStrcpy(tp
, prefix
);
1769 wxStrcat(tp
, _T("6o |"));
1771 wxStrcpy(tp
, prefix
);
1772 wxStrcat(tp
, _T("6x |"));
1774 wxStrcpy(tp
, prefix
);
1775 wxStrcat(tp
, _T("6X |"));
1777 wxStrcpy(tp
, prefix
);
1778 wxStrcat(tp
, _T("6u |"));
1785 wxPrintf(_T("%10s\n"), PointerNull
);
1786 wxPrintf(_T("%-10s\n"), PointerNull
);
1789 static void TestPrintf()
1791 static wxChar shortstr
[] = _T("Hi, Z.");
1792 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
1793 I am ready for my first lesson today.");
1795 wxString test_format
;
1799 fmtchk(_T("%4.4x"));
1800 fmtchk(_T("%04.4x"));
1801 fmtchk(_T("%4.3x"));
1802 fmtchk(_T("%04.3x"));
1804 fmtst1chk(_T("%.*x"));
1805 fmtst1chk(_T("%0*x"));
1806 fmtst2chk(_T("%*.*x"));
1807 fmtst2chk(_T("%0*.*x"));
1809 wxString bad_format
= _T("bad format:\t\"%b\"\n");
1810 wxPrintf(bad_format
.c_str());
1811 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1813 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
1814 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
1815 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
1816 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
1817 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
1818 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1819 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1820 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
1821 wxPrintf(test_format
.c_str(), -123456);
1822 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1823 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1825 test_format
= _T("zero-padded string:\t\"%010s\"\n");
1826 wxPrintf(test_format
.c_str(), shortstr
);
1827 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
1828 wxPrintf(test_format
.c_str(), shortstr
);
1829 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
1830 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1831 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
1832 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
1834 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
1835 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
1836 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
1837 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
1838 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
1839 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
1840 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
1841 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
1842 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
1843 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
1844 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
1845 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
1847 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
1848 wxPrintf (_T(" %6.5f\n"), .1);
1849 wxPrintf (_T("x%5.4fx\n"), .5);
1851 wxPrintf (_T("%#03x\n"), 1);
1853 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
1859 while (niter
-- != 0)
1860 wxPrintf (_T("%.17e\n"), d
/ 2);
1865 // Open Watcom cause compiler error here
1866 // Error! E173: col(24) floating-point constant too small to represent
1867 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
1870 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
1871 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1872 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1873 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1874 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1875 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1876 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1877 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1878 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1879 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1884 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
1886 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1887 rc
, WXSIZEOF(buf
), buf
);
1890 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1891 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1897 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
1898 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
1899 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
1900 wxPrintf (_T("%g should be 123.456\n"), 123.456);
1901 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
1902 wxPrintf (_T("%g should be 10\n"), 10.0);
1903 wxPrintf (_T("%g should be 0.02\n"), 0.02);
1907 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1913 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
1915 result
|= wxStrcmp (buf
,
1916 _T("onetwo three "));
1918 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
1925 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
1927 // for some reason below line fails under Borland
1928 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1931 if (wxStrcmp (buf
, _T("40000000000")) != 0)
1934 wxPuts (_T("\tFAILED"));
1936 wxUnusedVar(result
);
1937 wxPuts (wxEmptyString
);
1939 #endif // wxLongLong_t
1941 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1942 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1944 wxPuts (_T("--- Should be no further output. ---"));
1953 memset (bytes
, '\xff', sizeof bytes
);
1954 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
1955 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1956 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1958 wxPuts (_T("%hhn overwrite more bytes"));
1963 wxPuts (_T("%hhn wrote incorrect value"));
1975 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
1976 if (wxStrcmp (buf
, _T(" ")) != 0)
1977 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
1978 wxSprintf (buf
, _T("%5.f"), 33.3);
1979 if (wxStrcmp (buf
, _T(" 33")) != 0)
1980 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
1981 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
1982 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
1983 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
1984 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
1985 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
1986 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
1987 wxSprintf (buf
, _T("%.g"), 33.3);
1988 if (wxStrcmp (buf
, _T("3e+01")) != 0)
1989 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
1990 wxSprintf (buf
, _T("%.G"), 33.3);
1991 if (wxStrcmp (buf
, _T("3E+01")) != 0)
1992 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2000 wxString test_format
;
2003 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2004 if (wxStrcmp (buf
, _T("3")) != 0)
2005 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2007 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2008 if (wxStrcmp (buf
, _T("3")) != 0)
2009 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2011 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2012 if (wxStrcmp (buf
, _T(" 3")) != 0)
2013 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2015 test_format
= _T("%04.*o");
2016 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2017 if (wxStrcmp (buf
, _T(" 041")) != 0)
2018 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2020 test_format
= _T("%09.*u");
2021 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2022 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2023 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2025 test_format
= _T("%04.*x");
2026 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2027 if (wxStrcmp (buf
, _T(" 021")) != 0)
2028 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2030 test_format
= _T("%04.*X");
2031 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2032 if (wxStrcmp (buf
, _T(" 021")) != 0)
2033 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2036 #endif // TEST_PRINTF
2038 // ----------------------------------------------------------------------------
2039 // registry and related stuff
2040 // ----------------------------------------------------------------------------
2042 // this is for MSW only
2045 #undef TEST_REGISTRY
2050 #include "wx/confbase.h"
2051 #include "wx/msw/regconf.h"
2054 static void TestRegConfWrite()
2056 wxConfig
*config
= new wxConfig(_T("myapp"));
2057 config
->SetPath(_T("/group1"));
2058 config
->Write(_T("entry1"), _T("foo"));
2059 config
->SetPath(_T("/group2"));
2060 config
->Write(_T("entry1"), _T("bar"));
2064 static void TestRegConfRead()
2066 wxConfig
*config
= new wxConfig(_T("myapp"));
2070 config
->SetPath(_T("/"));
2071 wxPuts(_T("Enumerating / subgroups:"));
2072 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2076 bCont
= config
->GetNextGroup(str
, dummy
);
2080 #endif // TEST_REGCONF
2082 #ifdef TEST_REGISTRY
2084 #include "wx/msw/registry.h"
2086 // I chose this one because I liked its name, but it probably only exists under
2088 static const wxChar
*TESTKEY
=
2089 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2091 static void TestRegistryRead()
2093 wxPuts(_T("*** testing registry reading ***"));
2095 wxRegKey
key(TESTKEY
);
2096 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2099 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2104 size_t nSubKeys
, nValues
;
2105 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2107 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2110 wxPrintf(_T("Enumerating values:\n"));
2114 bool cont
= key
.GetFirstValue(value
, dummy
);
2117 wxPrintf(_T("Value '%s': type "), value
.c_str());
2118 switch ( key
.GetValueType(value
) )
2120 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2121 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
2122 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2123 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
2124 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
2125 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2126 default: wxPrintf(_T("other (unknown)")); break;
2129 wxPrintf(_T(", value = "));
2130 if ( key
.IsNumericValue(value
) )
2133 key
.QueryValue(value
, &val
);
2134 wxPrintf(_T("%ld"), val
);
2139 key
.QueryValue(value
, val
);
2140 wxPrintf(_T("'%s'"), val
.c_str());
2142 key
.QueryRawValue(value
, val
);
2143 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2148 cont
= key
.GetNextValue(value
, dummy
);
2152 static void TestRegistryAssociation()
2155 The second call to deleteself genertaes an error message, with a
2156 messagebox saying .flo is crucial to system operation, while the .ddf
2157 call also fails, but with no error message
2162 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2164 key
= _T("ddxf_auto_file") ;
2165 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2167 key
= _T("ddxf_auto_file") ;
2168 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2170 key
= _T("program,0") ;
2171 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2173 key
= _T("program \"%1\"") ;
2175 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2177 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2179 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2181 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2185 #endif // TEST_REGISTRY
2187 // ----------------------------------------------------------------------------
2189 // ----------------------------------------------------------------------------
2191 #ifdef TEST_SCOPEGUARD
2193 #include "wx/scopeguard.h"
2195 static void function0() { puts("function0()"); }
2196 static void function1(int n
) { printf("function1(%d)\n", n
); }
2197 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2201 void method0() { printf("method0()\n"); }
2202 void method1(int n
) { printf("method1(%d)\n", n
); }
2203 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2206 static void TestScopeGuard()
2208 wxON_BLOCK_EXIT0(function0
);
2209 wxON_BLOCK_EXIT1(function1
, 17);
2210 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2213 wxON_BLOCK_EXIT_OBJ0(obj
, Object::method0
);
2214 wxON_BLOCK_EXIT_OBJ1(obj
, Object::method1
, 7);
2215 wxON_BLOCK_EXIT_OBJ2(obj
, Object::method2
, 2.71, 'e');
2217 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2218 dismissed
.Dismiss();
2223 // ----------------------------------------------------------------------------
2225 // ----------------------------------------------------------------------------
2229 #include "wx/socket.h"
2230 #include "wx/protocol/protocol.h"
2231 #include "wx/protocol/http.h"
2233 static void TestSocketServer()
2235 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2237 static const int PORT
= 3000;
2242 wxSocketServer
*server
= new wxSocketServer(addr
);
2243 if ( !server
->Ok() )
2245 wxPuts(_T("ERROR: failed to bind"));
2253 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2255 wxSocketBase
*socket
= server
->Accept();
2258 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2262 wxPuts(_T("Server: got a client."));
2264 server
->SetTimeout(60); // 1 min
2267 while ( !close
&& socket
->IsConnected() )
2270 wxChar ch
= _T('\0');
2273 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2275 // don't log error if the client just close the connection
2276 if ( socket
->IsConnected() )
2278 wxPuts(_T("ERROR: in wxSocket::Read."));
2298 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2299 if ( s
== _T("close") )
2301 wxPuts(_T("Closing connection"));
2305 else if ( s
== _T("quit") )
2310 wxPuts(_T("Shutting down the server"));
2312 else // not a special command
2314 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2315 socket
->Write("\r\n", 2);
2316 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
2322 wxPuts(_T("Server: lost a client unexpectedly."));
2328 // same as "delete server" but is consistent with GUI programs
2332 static void TestSocketClient()
2334 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2336 static const wxChar
*hostname
= _T("www.wxwidgets.org");
2339 addr
.Hostname(hostname
);
2342 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
2344 wxSocketClient client
;
2345 if ( !client
.Connect(addr
) )
2347 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2351 wxPrintf(_T("--- Connected to %s:%u...\n"),
2352 addr
.Hostname().c_str(), addr
.Service());
2356 // could use simply "GET" here I suppose
2358 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
2359 client
.Write(cmdGet
, cmdGet
.length());
2360 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2361 MakePrintable(cmdGet
).c_str());
2362 client
.Read(buf
, WXSIZEOF(buf
));
2363 wxPrintf(_T("--- Server replied:\n%s"), buf
);
2367 #endif // TEST_SOCKETS
2369 // ----------------------------------------------------------------------------
2371 // ----------------------------------------------------------------------------
2375 #include "wx/protocol/ftp.h"
2379 #define FTP_ANONYMOUS
2381 #ifdef FTP_ANONYMOUS
2382 static const wxChar
*directory
= _T("/pub");
2383 static const wxChar
*filename
= _T("welcome.msg");
2385 static const wxChar
*directory
= _T("/etc");
2386 static const wxChar
*filename
= _T("issue");
2389 static bool TestFtpConnect()
2391 wxPuts(_T("*** Testing FTP connect ***"));
2393 #ifdef FTP_ANONYMOUS
2394 static const wxChar
*hostname
= _T("ftp.wxwidgets.org");
2396 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2397 #else // !FTP_ANONYMOUS
2398 static const wxChar
*hostname
= "localhost";
2401 wxFgets(user
, WXSIZEOF(user
), stdin
);
2402 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2405 wxChar password
[256];
2406 wxPrintf(_T("Password for %s: "), password
);
2407 wxFgets(password
, WXSIZEOF(password
), stdin
);
2408 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2409 ftp
.SetPassword(password
);
2411 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2412 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2414 if ( !ftp
.Connect(hostname
) )
2416 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2422 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2423 hostname
, ftp
.Pwd().c_str());
2430 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2431 static void TestFtpWuFtpd()
2434 static const wxChar
*hostname
= _T("ftp.eudora.com");
2435 if ( !ftp
.Connect(hostname
) )
2437 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2441 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
2442 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2445 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2449 size_t size
= in
->GetSize();
2450 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2452 wxChar
*data
= new wxChar
[size
];
2453 if ( !in
->Read(data
, size
) )
2455 wxPuts(_T("ERROR: read error"));
2459 wxPrintf(_T("Successfully retrieved the file.\n"));
2468 static void TestFtpList()
2470 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2473 if ( !ftp
.ChDir(directory
) )
2475 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2478 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2480 // test NLIST and LIST
2481 wxArrayString files
;
2482 if ( !ftp
.GetFilesList(files
) )
2484 wxPuts(_T("ERROR: failed to get NLIST of files"));
2488 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
2489 size_t count
= files
.GetCount();
2490 for ( size_t n
= 0; n
< count
; n
++ )
2492 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2494 wxPuts(_T("End of the file list"));
2497 if ( !ftp
.GetDirList(files
) )
2499 wxPuts(_T("ERROR: failed to get LIST of files"));
2503 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
2504 size_t count
= files
.GetCount();
2505 for ( size_t n
= 0; n
< count
; n
++ )
2507 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2509 wxPuts(_T("End of the file list"));
2512 if ( !ftp
.ChDir(_T("..")) )
2514 wxPuts(_T("ERROR: failed to cd to .."));
2517 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2520 static void TestFtpDownload()
2522 wxPuts(_T("*** Testing wxFTP download ***\n"));
2525 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2528 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2532 size_t size
= in
->GetSize();
2533 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2536 wxChar
*data
= new wxChar
[size
];
2537 if ( !in
->Read(data
, size
) )
2539 wxPuts(_T("ERROR: read error"));
2543 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
2551 static void TestFtpFileSize()
2553 wxPuts(_T("*** Testing FTP SIZE command ***"));
2555 if ( !ftp
.ChDir(directory
) )
2557 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2560 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2562 if ( ftp
.FileExists(filename
) )
2564 int size
= ftp
.GetFileSize(filename
);
2566 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
2568 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
2572 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
2576 static void TestFtpMisc()
2578 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2580 if ( ftp
.SendCommand(_T("STAT")) != '2' )
2582 wxPuts(_T("ERROR: STAT failed"));
2586 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
2589 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
2591 wxPuts(_T("ERROR: HELP SITE failed"));
2595 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2596 ftp
.GetLastResult().c_str());
2600 static void TestFtpInteractive()
2602 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2608 wxPrintf(_T("Enter FTP command: "));
2609 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2612 // kill the last '\n'
2613 buf
[wxStrlen(buf
) - 1] = 0;
2615 // special handling of LIST and NLST as they require data connection
2616 wxString
start(buf
, 4);
2618 if ( start
== _T("LIST") || start
== _T("NLST") )
2621 if ( wxStrlen(buf
) > 4 )
2624 wxArrayString files
;
2625 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
2627 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
2631 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2632 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2633 size_t count
= files
.GetCount();
2634 for ( size_t n
= 0; n
< count
; n
++ )
2636 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2638 wxPuts(_T("--- End of the file list"));
2643 wxChar ch
= ftp
.SendCommand(buf
);
2644 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
2647 wxPrintf(_T(" (return code %c)"), ch
);
2650 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
2654 wxPuts(_T("\n*** done ***"));
2657 static void TestFtpUpload()
2659 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2662 static const wxChar
*file1
= _T("test1");
2663 static const wxChar
*file2
= _T("test2");
2664 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2667 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2668 out
->Write("First hello", 11);
2672 // send a command to check the remote file
2673 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
2675 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
2679 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2680 file1
, ftp
.GetLastResult().c_str());
2683 out
= ftp
.GetOutputStream(file2
);
2686 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2687 out
->Write("Second hello", 12);
2694 // ----------------------------------------------------------------------------
2696 // ----------------------------------------------------------------------------
2698 #ifdef TEST_STACKWALKER
2700 #if wxUSE_STACKWALKER
2702 #include "wx/stackwalk.h"
2704 class StackDump
: public wxStackWalker
2707 StackDump(const char *argv0
)
2708 : wxStackWalker(argv0
)
2712 virtual void Walk(size_t skip
= 1)
2714 wxPuts(_T("Stack dump:"));
2716 wxStackWalker::Walk(skip
);
2720 virtual void OnStackFrame(const wxStackFrame
& frame
)
2722 printf("[%2d] ", frame
.GetLevel());
2724 wxString name
= frame
.GetName();
2725 if ( !name
.empty() )
2727 printf("%-20.40s", name
.mb_str());
2731 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2734 if ( frame
.HasSourceLocation() )
2737 frame
.GetFileName().mb_str(),
2744 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2746 printf("\t%s %s = %s\n", type
.mb_str(), name
.mb_str(), val
.mb_str());
2751 static void TestStackWalk(const char *argv0
)
2753 wxPuts(_T("*** Testing wxStackWalker ***\n"));
2755 StackDump
dump(argv0
);
2759 #endif // wxUSE_STACKWALKER
2761 #endif // TEST_STACKWALKER
2763 // ----------------------------------------------------------------------------
2765 // ----------------------------------------------------------------------------
2767 #ifdef TEST_STDPATHS
2769 #include "wx/stdpaths.h"
2770 #include "wx/wxchar.h" // wxPrintf
2772 static void TestStandardPaths()
2774 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
2776 wxTheApp
->SetAppName(_T("console"));
2778 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
2779 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2780 wxPrintf(_T("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2781 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2782 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2783 wxPrintf(_T("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2784 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2785 wxPrintf(_T("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2786 wxPrintf(_T("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2787 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2788 wxPrintf(_T("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2789 wxPrintf(_T("Localized res. dir:\t%s\n"),
2790 stdp
.GetLocalizedResourcesDir(_T("fr")).c_str());
2791 wxPrintf(_T("Message catalogs dir:\t%s\n"),
2792 stdp
.GetLocalizedResourcesDir
2795 wxStandardPaths::ResourceCat_Messages
2799 #endif // TEST_STDPATHS
2801 // ----------------------------------------------------------------------------
2803 // ----------------------------------------------------------------------------
2807 #include "wx/wfstream.h"
2808 #include "wx/mstream.h"
2810 static void TestFileStream()
2812 wxPuts(_T("*** Testing wxFileInputStream ***"));
2814 static const wxString filename
= _T("testdata.fs");
2816 wxFileOutputStream
fsOut(filename
);
2817 fsOut
.Write("foo", 3);
2821 wxFileInputStream
fsIn(filename
);
2822 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
2823 while ( !fsIn
.Eof() )
2825 wxPutchar(fsIn
.GetC());
2829 if ( !wxRemoveFile(filename
) )
2831 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2834 wxPuts(_T("\n*** wxFileInputStream test done ***"));
2837 static void TestMemoryStream()
2839 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
2841 wxMemoryOutputStream memOutStream
;
2842 wxPrintf(_T("Initially out stream offset: %lu\n"),
2843 (unsigned long)memOutStream
.TellO());
2845 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
2847 memOutStream
.PutC(*p
);
2850 wxPrintf(_T("Final out stream offset: %lu\n"),
2851 (unsigned long)memOutStream
.TellO());
2853 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
2856 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2858 wxMemoryInputStream
memInpStream(buf
, len
);
2859 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2860 while ( !memInpStream
.Eof() )
2862 wxPutchar(memInpStream
.GetC());
2865 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
2868 #endif // TEST_STREAMS
2870 // ----------------------------------------------------------------------------
2872 // ----------------------------------------------------------------------------
2876 #include "wx/stopwatch.h"
2877 #include "wx/utils.h"
2879 static void TestStopWatch()
2881 wxPuts(_T("*** Testing wxStopWatch ***\n"));
2885 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
2888 wxPrintf(_T("\t%ldms\n"), sw
.Time());
2890 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
2894 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2897 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
2900 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2903 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
2906 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2909 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
2910 for ( size_t n
= 0; n
< 70; n
++ )
2914 for ( size_t m
= 0; m
< 100000; m
++ )
2916 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2918 wxPuts(_T("\ntime is negative - ERROR!"));
2926 wxPuts(_T(", ok."));
2929 #include "wx/timer.h"
2930 #include "wx/evtloop.h"
2934 wxPuts(_T("*** Testing wxTimer ***\n"));
2936 class MyTimer
: public wxTimer
2939 MyTimer() : wxTimer() { m_num
= 0; }
2941 virtual void Notify()
2943 wxPrintf(_T("%d"), m_num
++);
2948 wxPrintf(_T("... exiting the event loop"));
2951 wxEventLoop::GetActive()->Exit(0);
2952 wxPuts(_T(", ok."));
2965 timer1
.Start(100, true /* one shot */);
2967 timer1
.Start(100, true /* one shot */);
2975 #endif // TEST_TIMER
2977 // ----------------------------------------------------------------------------
2979 // ----------------------------------------------------------------------------
2983 #include "wx/vcard.h"
2985 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
2988 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
2991 wxPrintf(_T("%s%s"),
2992 wxString(_T('\t'), level
).c_str(),
2993 vcObj
->GetName().c_str());
2996 switch ( vcObj
->GetType() )
2998 case wxVCardObject::String
:
2999 case wxVCardObject::UString
:
3002 vcObj
->GetValue(&val
);
3003 value
<< _T('"') << val
<< _T('"');
3007 case wxVCardObject::Int
:
3010 vcObj
->GetValue(&i
);
3011 value
.Printf(_T("%u"), i
);
3015 case wxVCardObject::Long
:
3018 vcObj
->GetValue(&l
);
3019 value
.Printf(_T("%lu"), l
);
3023 case wxVCardObject::None
:
3026 case wxVCardObject::Object
:
3027 value
= _T("<node>");
3031 value
= _T("<unknown value type>");
3035 wxPrintf(_T(" = %s"), value
.c_str());
3038 DumpVObject(level
+ 1, *vcObj
);
3041 vcObj
= vcard
.GetNextProp(&cookie
);
3045 static void DumpVCardAddresses(const wxVCard
& vcard
)
3047 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3051 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3055 int flags
= addr
->GetFlags();
3056 if ( flags
& wxVCardAddress::Domestic
)
3058 flagsStr
<< _T("domestic ");
3060 if ( flags
& wxVCardAddress::Intl
)
3062 flagsStr
<< _T("international ");
3064 if ( flags
& wxVCardAddress::Postal
)
3066 flagsStr
<< _T("postal ");
3068 if ( flags
& wxVCardAddress::Parcel
)
3070 flagsStr
<< _T("parcel ");
3072 if ( flags
& wxVCardAddress::Home
)
3074 flagsStr
<< _T("home ");
3076 if ( flags
& wxVCardAddress::Work
)
3078 flagsStr
<< _T("work ");
3081 wxPrintf(_T("Address %u:\n")
3083 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3086 addr
->GetPostOffice().c_str(),
3087 addr
->GetExtAddress().c_str(),
3088 addr
->GetStreet().c_str(),
3089 addr
->GetLocality().c_str(),
3090 addr
->GetRegion().c_str(),
3091 addr
->GetPostalCode().c_str(),
3092 addr
->GetCountry().c_str()
3096 addr
= vcard
.GetNextAddress(&cookie
);
3100 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3102 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3106 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3110 int flags
= phone
->GetFlags();
3111 if ( flags
& wxVCardPhoneNumber::Voice
)
3113 flagsStr
<< _T("voice ");
3115 if ( flags
& wxVCardPhoneNumber::Fax
)
3117 flagsStr
<< _T("fax ");
3119 if ( flags
& wxVCardPhoneNumber::Cellular
)
3121 flagsStr
<< _T("cellular ");
3123 if ( flags
& wxVCardPhoneNumber::Modem
)
3125 flagsStr
<< _T("modem ");
3127 if ( flags
& wxVCardPhoneNumber::Home
)
3129 flagsStr
<< _T("home ");
3131 if ( flags
& wxVCardPhoneNumber::Work
)
3133 flagsStr
<< _T("work ");
3136 wxPrintf(_T("Phone number %u:\n")
3141 phone
->GetNumber().c_str()
3145 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3149 static void TestVCardRead()
3151 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3153 wxVCard
vcard(_T("vcard.vcf"));
3154 if ( !vcard
.IsOk() )
3156 wxPuts(_T("ERROR: couldn't load vCard."));
3160 // read individual vCard properties
3161 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3165 vcObj
->GetValue(&value
);
3170 value
= _T("<none>");
3173 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3176 if ( !vcard
.GetFullName(&value
) )
3178 value
= _T("<none>");
3181 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3183 // now show how to deal with multiply occurring properties
3184 DumpVCardAddresses(vcard
);
3185 DumpVCardPhoneNumbers(vcard
);
3187 // and finally show all
3188 wxPuts(_T("\nNow dumping the entire vCard:\n")
3189 "-----------------------------\n");
3191 DumpVObject(0, vcard
);
3195 static void TestVCardWrite()
3197 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3200 if ( !vcard
.IsOk() )
3202 wxPuts(_T("ERROR: couldn't create vCard."));
3207 vcard
.SetName("Zeitlin", "Vadim");
3208 vcard
.SetFullName("Vadim Zeitlin");
3209 vcard
.SetOrganization("wxWidgets", "R&D");
3211 // just dump the vCard back
3212 wxPuts(_T("Entire vCard follows:\n"));
3213 wxPuts(vcard
.Write());
3217 #endif // TEST_VCARD
3219 // ----------------------------------------------------------------------------
3221 // ----------------------------------------------------------------------------
3223 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3229 #include "wx/volume.h"
3231 static const wxChar
*volumeKinds
[] =
3237 _T("network volume"),
3241 static void TestFSVolume()
3243 wxPuts(_T("*** Testing wxFSVolume class ***"));
3245 wxArrayString volumes
= wxFSVolume::GetVolumes();
3246 size_t count
= volumes
.GetCount();
3250 wxPuts(_T("ERROR: no mounted volumes?"));
3254 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3256 for ( size_t n
= 0; n
< count
; n
++ )
3258 wxFSVolume
vol(volumes
[n
]);
3261 wxPuts(_T("ERROR: couldn't create volume"));
3265 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3267 vol
.GetDisplayName().c_str(),
3268 vol
.GetName().c_str(),
3269 volumeKinds
[vol
.GetKind()],
3270 vol
.IsWritable() ? _T("rw") : _T("ro"),
3271 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3276 #endif // TEST_VOLUME
3278 // ----------------------------------------------------------------------------
3279 // wide char and Unicode support
3280 // ----------------------------------------------------------------------------
3284 #include "wx/strconv.h"
3285 #include "wx/fontenc.h"
3286 #include "wx/encconv.h"
3287 #include "wx/buffer.h"
3289 static const unsigned char utf8koi8r
[] =
3291 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3292 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3293 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3294 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3295 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3296 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3297 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3300 static const unsigned char utf8iso8859_1
[] =
3302 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3303 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3304 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3305 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3306 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3309 static const unsigned char utf8Invalid
[] =
3311 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3312 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3313 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3314 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3318 static const struct Utf8Data
3320 const unsigned char *text
;
3322 const wxChar
*charset
;
3323 wxFontEncoding encoding
;
3326 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3327 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3328 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3331 static void TestUtf8()
3333 wxPuts(_T("*** Testing UTF8 support ***\n"));
3338 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3340 const Utf8Data
& u8d
= utf8data
[n
];
3341 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3342 WXSIZEOF(wbuf
)) == (size_t)-1 )
3344 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3348 wxCSConv
conv(u8d
.charset
);
3349 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3351 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3355 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3359 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3361 s
= _T("<< conversion failed >>");
3362 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3366 wxPuts(wxEmptyString
);
3369 static void TestEncodingConverter()
3371 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3373 // using wxEncodingConverter should give the same result as above
3376 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3377 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3379 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3383 wxEncodingConverter ec
;
3384 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3385 ec
.Convert(wbuf
, buf
);
3386 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3389 wxPuts(wxEmptyString
);
3392 #endif // TEST_WCHAR
3394 // ----------------------------------------------------------------------------
3396 // ----------------------------------------------------------------------------
3400 #include "wx/filesys.h"
3401 #include "wx/fs_zip.h"
3402 #include "wx/zipstrm.h"
3404 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3406 static void TestZipStreamRead()
3408 wxPuts(_T("*** Testing ZIP reading ***\n"));
3410 static const wxString filename
= _T("foo");
3411 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3412 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3414 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3415 while ( !istr
.Eof() )
3417 wxPutchar(istr
.GetC());
3421 wxPuts(_T("\n----- done ------"));
3424 static void DumpZipDirectory(wxFileSystem
& fs
,
3425 const wxString
& dir
,
3426 const wxString
& indent
)
3428 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3429 TESTFILE_ZIP
, dir
.c_str());
3430 wxString wildcard
= prefix
+ _T("/*");
3432 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3433 while ( !dirname
.empty() )
3435 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3437 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3442 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3444 DumpZipDirectory(fs
, dirname
,
3445 indent
+ wxString(_T(' '), 4));
3447 dirname
= fs
.FindNext();
3450 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3451 while ( !filename
.empty() )
3453 if ( !filename
.StartsWith(prefix
, &filename
) )
3455 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3460 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3462 filename
= fs
.FindNext();
3466 static void TestZipFileSystem()
3468 wxPuts(_T("*** Testing ZIP file system ***\n"));
3470 wxFileSystem::AddHandler(new wxZipFSHandler
);
3472 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3474 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3479 // ----------------------------------------------------------------------------
3481 // ----------------------------------------------------------------------------
3483 #ifdef TEST_DATETIME
3485 #include "wx/math.h"
3486 #include "wx/datetime.h"
3488 // this test miscellaneous static wxDateTime functions
3492 static void TestTimeStatic()
3494 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3496 // some info about the current date
3497 int year
= wxDateTime::GetCurrentYear();
3498 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3500 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3501 wxDateTime::GetNumberOfDays(year
));
3503 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3504 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3505 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3506 wxDateTime::GetMonthName(month
).c_str(),
3507 wxDateTime::GetNumberOfDays(month
));
3510 // test time zones stuff
3511 static void TestTimeZones()
3513 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3515 wxDateTime now
= wxDateTime::Now();
3517 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
3518 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
3519 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
3520 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
3521 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
3522 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
3524 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3526 wxDateTime::Tm tm
= now
.GetTm();
3527 if ( wxDateTime(tm
) != now
)
3529 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3530 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3534 // test some minimal support for the dates outside the standard range
3535 static void TestTimeRange()
3537 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3539 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
3541 wxPrintf(_T("Unix epoch:\t%s\n"),
3542 wxDateTime(2440587.5).Format(fmt
).c_str());
3543 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3544 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3545 wxPrintf(_T("JDN 0: \t%s\n"),
3546 wxDateTime(0.0).Format(fmt
).c_str());
3547 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3548 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3549 wxPrintf(_T("May 29, 2099:\t%s\n"),
3550 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3553 // test DST calculations
3554 static void TestTimeDST()
3556 wxPuts(_T("\n*** wxDateTime DST test ***"));
3558 wxPrintf(_T("DST is%s in effect now.\n\n"),
3559 wxDateTime::Now().IsDST() ? wxEmptyString
: _T(" not"));
3561 for ( int year
= 1990; year
< 2005; year
++ )
3563 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3565 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3566 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3572 #if TEST_INTERACTIVE
3574 static void TestDateTimeInteractive()
3576 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3582 wxPrintf(_T("Enter a date: "));
3583 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3586 // kill the last '\n'
3587 buf
[wxStrlen(buf
) - 1] = 0;
3590 const wxChar
*p
= dt
.ParseDate(buf
);
3593 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
3599 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
3602 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3603 dt
.Format(_T("%b %d, %Y")).c_str(),
3605 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3606 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3607 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3610 wxPuts(_T("\n*** done ***"));
3613 #endif // TEST_INTERACTIVE
3617 static void TestTimeMS()
3619 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3621 wxDateTime dt1
= wxDateTime::Now(),
3622 dt2
= wxDateTime::UNow();
3624 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
3625 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3626 wxPrintf(_T("Dummy loop: "));
3627 for ( int i
= 0; i
< 6000; i
++ )
3629 //for ( int j = 0; j < 10; j++ )
3632 s
.Printf(_T("%g"), sqrt((float)i
));
3638 wxPuts(_T(", done"));
3641 dt2
= wxDateTime::UNow();
3642 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3644 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
3646 wxPuts(_T("\n*** done ***"));
3649 static void TestTimeHolidays()
3651 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3653 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3654 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3655 dtEnd
= dtStart
.GetLastMonthDay();
3657 wxDateTimeArray hol
;
3658 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3660 const wxChar
*format
= _T("%d-%b-%Y (%a)");
3662 wxPrintf(_T("All holidays between %s and %s:\n"),
3663 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3665 size_t count
= hol
.GetCount();
3666 for ( size_t n
= 0; n
< count
; n
++ )
3668 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
3671 wxPuts(wxEmptyString
);
3674 static void TestTimeZoneBug()
3676 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3678 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3679 for ( int i
= 0; i
< 31; i
++ )
3681 wxPrintf(_T("Date %s: week day %s.\n"),
3682 date
.Format(_T("%d-%m-%Y")).c_str(),
3683 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3685 date
+= wxDateSpan::Day();
3688 wxPuts(wxEmptyString
);
3691 static void TestTimeSpanFormat()
3693 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3695 static const wxChar
*formats
[] =
3697 _T("(default) %H:%M:%S"),
3698 _T("%E weeks and %D days"),
3699 _T("%l milliseconds"),
3700 _T("(with ms) %H:%M:%S:%l"),
3701 _T("100%% of minutes is %M"), // test "%%"
3702 _T("%D days and %H hours"),
3703 _T("or also %S seconds"),
3706 wxTimeSpan
ts1(1, 2, 3, 4),
3708 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3710 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3711 ts1
.Format(formats
[n
]).c_str(),
3712 ts2
.Format(formats
[n
]).c_str());
3715 wxPuts(wxEmptyString
);
3720 #endif // TEST_DATETIME
3722 // ----------------------------------------------------------------------------
3723 // wxTextInput/OutputStream
3724 // ----------------------------------------------------------------------------
3726 #ifdef TEST_TEXTSTREAM
3728 #include "wx/txtstrm.h"
3729 #include "wx/wfstream.h"
3731 static void TestTextInputStream()
3733 wxPuts(_T("\n*** wxTextInputStream test ***"));
3735 wxString filename
= _T("testdata.fc");
3736 wxFileInputStream
fsIn(filename
);
3739 wxPuts(_T("ERROR: couldn't open file."));
3743 wxTextInputStream
tis(fsIn
);
3748 const wxString s
= tis
.ReadLine();
3750 // line could be non empty if the last line of the file isn't
3751 // terminated with EOL
3752 if ( fsIn
.Eof() && s
.empty() )
3755 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
3760 #endif // TEST_TEXTSTREAM
3762 // ----------------------------------------------------------------------------
3764 // ----------------------------------------------------------------------------
3768 #include "wx/thread.h"
3770 static size_t gs_counter
= (size_t)-1;
3771 static wxCriticalSection gs_critsect
;
3772 static wxSemaphore gs_cond
;
3774 class MyJoinableThread
: public wxThread
3777 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3778 { m_n
= n
; Create(); }
3780 // thread execution starts here
3781 virtual ExitCode
Entry();
3787 wxThread::ExitCode
MyJoinableThread::Entry()
3789 unsigned long res
= 1;
3790 for ( size_t n
= 1; n
< m_n
; n
++ )
3794 // it's a loooong calculation :-)
3798 return (ExitCode
)res
;
3801 class MyDetachedThread
: public wxThread
3804 MyDetachedThread(size_t n
, wxChar ch
)
3808 m_cancelled
= false;
3813 // thread execution starts here
3814 virtual ExitCode
Entry();
3817 virtual void OnExit();
3820 size_t m_n
; // number of characters to write
3821 wxChar m_ch
; // character to write
3823 bool m_cancelled
; // false if we exit normally
3826 wxThread::ExitCode
MyDetachedThread::Entry()
3829 wxCriticalSectionLocker
lock(gs_critsect
);
3830 if ( gs_counter
== (size_t)-1 )
3836 for ( size_t n
= 0; n
< m_n
; n
++ )
3838 if ( TestDestroy() )
3848 wxThread::Sleep(100);
3854 void MyDetachedThread::OnExit()
3856 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
3858 wxCriticalSectionLocker
lock(gs_critsect
);
3859 if ( !--gs_counter
&& !m_cancelled
)
3863 static void TestDetachedThreads()
3865 wxPuts(_T("\n*** Testing detached threads ***"));
3867 static const size_t nThreads
= 3;
3868 MyDetachedThread
*threads
[nThreads
];
3870 for ( n
= 0; n
< nThreads
; n
++ )
3872 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3875 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3876 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3878 for ( n
= 0; n
< nThreads
; n
++ )
3883 // wait until all threads terminate
3886 wxPuts(wxEmptyString
);
3889 static void TestJoinableThreads()
3891 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
3893 // calc 10! in the background
3894 MyJoinableThread
thread(10);
3897 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
3898 (unsigned long)thread
.Wait());
3901 static void TestThreadSuspend()
3903 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
3905 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3909 // this is for this demo only, in a real life program we'd use another
3910 // condition variable which would be signaled from wxThread::Entry() to
3911 // tell us that the thread really started running - but here just wait a
3912 // bit and hope that it will be enough (the problem is, of course, that
3913 // the thread might still not run when we call Pause() which will result
3915 wxThread::Sleep(300);
3917 for ( size_t n
= 0; n
< 3; n
++ )
3921 wxPuts(_T("\nThread suspended"));
3924 // don't sleep but resume immediately the first time
3925 wxThread::Sleep(300);
3927 wxPuts(_T("Going to resume the thread"));
3932 wxPuts(_T("Waiting until it terminates now"));
3934 // wait until the thread terminates
3937 wxPuts(wxEmptyString
);
3940 static void TestThreadDelete()
3942 // As above, using Sleep() is only for testing here - we must use some
3943 // synchronisation object instead to ensure that the thread is still
3944 // running when we delete it - deleting a detached thread which already
3945 // terminated will lead to a crash!
3947 wxPuts(_T("\n*** Testing thread delete function ***"));
3949 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3953 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
3955 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3959 wxThread::Sleep(300);
3963 wxPuts(_T("\nDeleted a running thread."));
3965 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
3969 wxThread::Sleep(300);
3975 wxPuts(_T("\nDeleted a sleeping thread."));
3977 MyJoinableThread
thread3(20);
3982 wxPuts(_T("\nDeleted a joinable thread."));
3984 MyJoinableThread
thread4(2);
3987 wxThread::Sleep(300);
3991 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
3993 wxPuts(wxEmptyString
);
3996 class MyWaitingThread
: public wxThread
3999 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
4002 m_condition
= condition
;
4007 virtual ExitCode
Entry()
4009 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
4014 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
4018 m_condition
->Wait();
4021 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
4029 wxCondition
*m_condition
;
4032 static void TestThreadConditions()
4035 wxCondition
condition(mutex
);
4037 // otherwise its difficult to understand which log messages pertain to
4039 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
4040 // condition.GetId(), gs_cond.GetId());
4042 // create and launch threads
4043 MyWaitingThread
*threads
[10];
4046 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4048 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
4051 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4056 // wait until all threads run
4057 wxPuts(_T("Main thread is waiting for the other threads to start"));
4060 size_t nRunning
= 0;
4061 while ( nRunning
< WXSIZEOF(threads
) )
4067 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
4071 wxPuts(_T("Main thread: all threads started up."));
4074 wxThread::Sleep(500);
4077 // now wake one of them up
4078 wxPrintf(_T("Main thread: about to signal the condition.\n"));
4083 wxThread::Sleep(200);
4085 // wake all the (remaining) threads up, so that they can exit
4086 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
4088 condition
.Broadcast();
4090 // give them time to terminate (dirty!)
4091 wxThread::Sleep(500);
4094 #include "wx/utils.h"
4096 class MyExecThread
: public wxThread
4099 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
4105 virtual ExitCode
Entry()
4107 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
4114 static void TestThreadExec()
4116 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4118 MyExecThread
thread(_T("true"));
4121 wxPrintf(_T("Main program exit code: %ld.\n"),
4122 wxExecute(_T("false"), wxEXEC_SYNC
));
4124 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
4128 #include "wx/datetime.h"
4130 class MySemaphoreThread
: public wxThread
4133 MySemaphoreThread(int i
, wxSemaphore
*sem
)
4134 : wxThread(wxTHREAD_JOINABLE
),
4141 virtual ExitCode
Entry()
4143 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4144 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4148 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4149 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4153 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4154 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4166 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
4168 static void TestSemaphore()
4170 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4172 static const int SEM_LIMIT
= 3;
4174 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
4175 ArrayThreads threads
;
4177 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
4179 threads
.Add(new MySemaphoreThread(i
, &sem
));
4180 threads
.Last()->Run();
4183 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
4190 #endif // TEST_THREADS
4192 // ----------------------------------------------------------------------------
4194 // ----------------------------------------------------------------------------
4196 #ifdef TEST_SNGLINST
4197 #include "wx/snglinst.h"
4198 #endif // TEST_SNGLINST
4200 int main(int argc
, char **argv
)
4203 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
4208 for (n
= 0; n
< argc
; n
++ )
4210 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
4211 wxArgv
[n
] = wxStrdup(warg
);
4216 #else // !wxUSE_UNICODE
4218 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
4220 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
4222 wxInitializer initializer
;
4225 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
4230 #ifdef TEST_SNGLINST
4231 wxSingleInstanceChecker checker
;
4232 if ( checker
.Create(_T(".wxconsole.lock")) )
4234 if ( checker
.IsAnotherRunning() )
4236 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4241 // wait some time to give time to launch another instance
4242 wxPrintf(_T("Press \"Enter\" to continue..."));
4245 else // failed to create
4247 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4249 #endif // TEST_SNGLINST
4252 TestCmdLineConvert();
4254 #if wxUSE_CMDLINE_PARSER
4255 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4257 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
4258 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
4259 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
4260 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
4262 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
4263 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
4264 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
4265 wxCMD_LINE_VAL_NUMBER
},
4266 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
4267 wxCMD_LINE_VAL_DATE
},
4268 { wxCMD_LINE_OPTION
, "f", "double", "output double",
4269 wxCMD_LINE_VAL_DOUBLE
},
4271 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
4272 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4277 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
4279 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4280 wxCMD_LINE_VAL_STRING
,
4281 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4283 switch ( parser
.Parse() )
4286 wxLogMessage(_T("Help was given, terminating."));
4290 ShowCmdLine(parser
);
4294 wxLogMessage(_T("Syntax error detected, aborting."));
4297 #endif // wxUSE_CMDLINE_PARSER
4299 #endif // TEST_CMDLINE
4311 TestDllListLoaded();
4312 #endif // TEST_DYNLIB
4316 #endif // TEST_ENVIRON
4320 #endif // TEST_EXECUTE
4322 #ifdef TEST_FILECONF
4324 #endif // TEST_FILECONF
4328 #endif // TEST_LOCALE
4331 wxPuts(_T("*** Testing wxLog ***"));
4334 for ( size_t n
= 0; n
< 8000; n
++ )
4336 s
<< (wxChar
)(_T('A') + (n
% 26));
4339 wxLogWarning(_T("The length of the string is %lu"),
4340 (unsigned long)s
.length());
4343 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
4345 // this one shouldn't be truncated
4348 // but this one will because log functions use fixed size buffer
4349 // (note that it doesn't need '\n' at the end neither - will be added
4351 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
4361 #ifdef TEST_FILENAME
4364 TestFileNameDirManip();
4365 TestFileNameComparison();
4366 TestFileNameOperations();
4367 #endif // TEST_FILENAME
4369 #ifdef TEST_FILETIME
4374 #endif // TEST_FILETIME
4377 wxLog::AddTraceMask(FTP_TRACE_MASK
);
4378 if ( TestFtpConnect() )
4388 #if TEST_INTERACTIVE
4389 TestFtpInteractive();
4392 //else: connecting to the FTP server failed
4400 //wxLog::AddTraceMask(_T("mime"));
4403 // TestMimeAssociate();
4407 #ifdef TEST_INFO_FUNCTIONS
4412 #if TEST_INTERACTIVE
4415 #endif // TEST_INFO_FUNCTIONS
4417 #ifdef TEST_PATHLIST
4419 #endif // TEST_PATHLIST
4423 #endif // TEST_PRINTF
4430 #endif // TEST_REGCONF
4432 #if defined TEST_REGEX && TEST_INTERACTIVE
4433 TestRegExInteractive();
4434 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4436 #ifdef TEST_REGISTRY
4438 TestRegistryAssociation();
4439 #endif // TEST_REGISTRY
4444 #endif // TEST_SOCKETS
4451 #endif // TEST_STREAMS
4453 #ifdef TEST_TEXTSTREAM
4454 TestTextInputStream();
4455 #endif // TEST_TEXTSTREAM
4458 int nCPUs
= wxThread::GetCPUCount();
4459 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
4461 wxThread::SetConcurrency(nCPUs
);
4463 TestJoinableThreads();
4466 TestJoinableThreads();
4467 TestDetachedThreads();
4468 TestThreadSuspend();
4470 TestThreadConditions();
4474 #endif // TEST_THREADS
4479 #endif // TEST_TIMER
4481 #ifdef TEST_DATETIME
4488 TestTimeSpanFormat();
4494 #if TEST_INTERACTIVE
4495 TestDateTimeInteractive();
4497 #endif // TEST_DATETIME
4499 #ifdef TEST_SCOPEGUARD
4503 #ifdef TEST_STACKWALKER
4504 #if wxUSE_STACKWALKER
4505 TestStackWalk(argv
[0]);
4507 #endif // TEST_STACKWALKER
4509 #ifdef TEST_STDPATHS
4510 TestStandardPaths();
4514 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4516 #endif // TEST_USLEEP
4521 #endif // TEST_VCARD
4525 #endif // TEST_VOLUME
4529 TestEncodingConverter();
4530 #endif // TEST_WCHAR
4533 TestZipStreamRead();
4534 TestZipFileSystem();
4539 for ( int n
= 0; n
< argc
; n
++ )
4544 #endif // wxUSE_UNICODE