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", (const char *)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", (const char *)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 "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 int pid
= wxExecute(ASYNC_COMMAND
);
571 wxPuts(_T("Ok (command launched)."));
572 if ( wxKill(pid
) == -1 )
573 wxPuts("ERROR: failed to kill child process.");
576 wxPuts(_T("ERROR."));
578 wxPrintf(_T("Testing wxExecute with redirection:\n"));
579 wxArrayString output
;
580 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
582 wxPuts(_T("ERROR."));
586 // don't show too much output, MAX_LINES is enough
587 static const unsigned MAX_LINES
= 20;
589 const unsigned count
= output
.size();
590 for ( unsigned n
= 0;
591 n
< (count
> MAX_LINES
? MAX_LINES
/2 : count
);
594 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
597 if ( count
> MAX_LINES
)
599 wxPrintf("... skipping %u lines...\n", count
- MAX_LINES
);
601 for ( unsigned n
= count
- MAX_LINES
/2; n
< count
; n
++ )
603 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
611 #endif // TEST_EXECUTE
613 // ----------------------------------------------------------------------------
615 // ----------------------------------------------------------------------------
620 #include "wx/ffile.h"
621 #include "wx/textfile.h"
623 static void TestFileRead()
625 wxPuts(_T("*** wxFile read test ***"));
627 wxFile
file(_T("testdata.fc"));
628 if ( file
.IsOpened() )
630 wxPrintf(_T("File length: %lu\n"), file
.Length());
632 wxPuts(_T("File dump:\n----------"));
634 static const size_t len
= 1024;
638 size_t nRead
= file
.Read(buf
, len
);
639 if ( nRead
== (size_t)wxInvalidOffset
)
641 wxPrintf(_T("Failed to read the file."));
645 fwrite(buf
, nRead
, 1, stdout
);
651 wxPuts(_T("----------"));
655 wxPrintf(_T("ERROR: can't open test file.\n"));
658 wxPuts(wxEmptyString
);
661 static void TestTextFileRead()
663 wxPuts(_T("*** wxTextFile read test ***"));
665 wxTextFile
file(_T("testdata.fc"));
668 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
669 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
673 wxPuts(_T("\nDumping the entire file:"));
674 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
676 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
678 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
680 wxPuts(_T("\nAnd now backwards:"));
681 for ( s
= file
.GetLastLine();
682 file
.GetCurrentLine() != 0;
683 s
= file
.GetPrevLine() )
685 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
687 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
691 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
694 wxPuts(wxEmptyString
);
697 static void TestFileCopy()
699 wxPuts(_T("*** Testing wxCopyFile ***"));
701 static const wxChar
*filename1
= _T("testdata.fc");
702 static const wxChar
*filename2
= _T("test2");
703 if ( !wxCopyFile(filename1
, filename2
) )
705 wxPuts(_T("ERROR: failed to copy file"));
709 wxFFile
f1(filename1
, _T("rb")),
710 f2(filename2
, _T("rb"));
712 if ( !f1
.IsOpened() || !f2
.IsOpened() )
714 wxPuts(_T("ERROR: failed to open file(s)"));
719 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
721 wxPuts(_T("ERROR: failed to read file(s)"));
725 if ( (s1
.length() != s2
.length()) ||
726 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
728 wxPuts(_T("ERROR: copy error!"));
732 wxPuts(_T("File was copied ok."));
738 if ( !wxRemoveFile(filename2
) )
740 wxPuts(_T("ERROR: failed to remove the file"));
743 wxPuts(wxEmptyString
);
746 static void TestTempFile()
748 wxPuts(_T("*** wxTempFile test ***"));
751 if ( tmpFile
.Open(_T("test2")) && tmpFile
.Write(_T("the answer is 42")) )
753 if ( tmpFile
.Commit() )
754 wxPuts(_T("File committed."));
756 wxPuts(_T("ERROR: could't commit temp file."));
758 wxRemoveFile(_T("test2"));
761 wxPuts(wxEmptyString
);
766 // ----------------------------------------------------------------------------
768 // ----------------------------------------------------------------------------
772 #include "wx/confbase.h"
773 #include "wx/fileconf.h"
775 static const struct FileConfTestData
777 const wxChar
*name
; // value name
778 const wxChar
*value
; // the value from the file
781 { _T("value1"), _T("one") },
782 { _T("value2"), _T("two") },
783 { _T("novalue"), _T("default") },
786 static void TestFileConfRead()
788 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
790 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
791 _T("testdata.fc"), wxEmptyString
,
792 wxCONFIG_USE_RELATIVE_PATH
);
794 // test simple reading
795 wxPuts(_T("\nReading config file:"));
796 wxString
defValue(_T("default")), value
;
797 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
799 const FileConfTestData
& data
= fcTestData
[n
];
800 value
= fileconf
.Read(data
.name
, defValue
);
801 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
802 if ( value
== data
.value
)
808 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
812 // test enumerating the entries
813 wxPuts(_T("\nEnumerating all root entries:"));
816 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
819 wxPrintf(_T("\t%s = %s\n"),
821 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
823 cont
= fileconf
.GetNextEntry(name
, dummy
);
826 static const wxChar
*testEntry
= _T("TestEntry");
827 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
828 fileconf
.Write(testEntry
, _T("A value"));
829 fileconf
.DeleteEntry(testEntry
);
830 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
833 #endif // TEST_FILECONF
835 // ----------------------------------------------------------------------------
837 // ----------------------------------------------------------------------------
841 #include "wx/filename.h"
844 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
848 wxString full
= fn
.GetFullPath();
850 wxString vol
, path
, name
, ext
;
851 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
853 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
854 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
856 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
857 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
858 path
.c_str(), name
.c_str(), ext
.c_str());
860 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
861 wxPrintf(_T("with volume: \t'%s'\n"),
862 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
863 wxPrintf(_T("with separator:\t'%s'\n"),
864 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
865 wxPrintf(_T("with both: \t'%s'\n"),
866 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
868 wxPuts(_T("The directories in the path are:"));
869 wxArrayString dirs
= fn
.GetDirs();
870 size_t count
= dirs
.GetCount();
871 for ( size_t n
= 0; n
< count
; n
++ )
873 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
878 static void TestFileNameTemp()
880 wxPuts(_T("*** testing wxFileName temp file creation ***"));
882 static const wxChar
*tmpprefixes
[] =
890 _T("/tmp/foo/bar"), // this one must be an error
894 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
896 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
899 // "error" is not in upper case because it may be ok
900 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
904 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
905 tmpprefixes
[n
], path
.c_str());
907 if ( !wxRemoveFile(path
) )
909 wxLogWarning(_T("Failed to remove temp file '%s'"),
916 static void TestFileNameDirManip()
918 // TODO: test AppendDir(), RemoveDir(), ...
921 static void TestFileNameComparison()
926 static void TestFileNameOperations()
931 static void TestFileNameCwd()
936 #endif // TEST_FILENAME
938 // ----------------------------------------------------------------------------
939 // wxFileName time functions
940 // ----------------------------------------------------------------------------
944 #include "wx/filename.h"
945 #include "wx/datetime.h"
947 static void TestFileGetTimes()
949 wxFileName
fn(_T("testdata.fc"));
951 wxDateTime dtAccess
, dtMod
, dtCreate
;
952 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
954 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
958 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
960 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
961 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
962 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
963 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
968 static void TestFileSetTimes()
970 wxFileName
fn(_T("testdata.fc"));
974 wxPrintf(_T("ERROR: Touch() failed.\n"));
979 #endif // TEST_FILETIME
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
988 #include "wx/utils.h" // for wxSetEnv
990 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
992 // find the name of the language from its value
993 static const wxChar
*GetLangName(int lang
)
995 static const wxChar
*languageNames
[] =
1005 _T("ARABIC_ALGERIA"),
1006 _T("ARABIC_BAHRAIN"),
1009 _T("ARABIC_JORDAN"),
1010 _T("ARABIC_KUWAIT"),
1011 _T("ARABIC_LEBANON"),
1013 _T("ARABIC_MOROCCO"),
1016 _T("ARABIC_SAUDI_ARABIA"),
1019 _T("ARABIC_TUNISIA"),
1026 _T("AZERI_CYRILLIC"),
1041 _T("CHINESE_SIMPLIFIED"),
1042 _T("CHINESE_TRADITIONAL"),
1043 _T("CHINESE_HONGKONG"),
1044 _T("CHINESE_MACAU"),
1045 _T("CHINESE_SINGAPORE"),
1046 _T("CHINESE_TAIWAN"),
1052 _T("DUTCH_BELGIAN"),
1056 _T("ENGLISH_AUSTRALIA"),
1057 _T("ENGLISH_BELIZE"),
1058 _T("ENGLISH_BOTSWANA"),
1059 _T("ENGLISH_CANADA"),
1060 _T("ENGLISH_CARIBBEAN"),
1061 _T("ENGLISH_DENMARK"),
1063 _T("ENGLISH_JAMAICA"),
1064 _T("ENGLISH_NEW_ZEALAND"),
1065 _T("ENGLISH_PHILIPPINES"),
1066 _T("ENGLISH_SOUTH_AFRICA"),
1067 _T("ENGLISH_TRINIDAD"),
1068 _T("ENGLISH_ZIMBABWE"),
1076 _T("FRENCH_BELGIAN"),
1077 _T("FRENCH_CANADIAN"),
1078 _T("FRENCH_LUXEMBOURG"),
1079 _T("FRENCH_MONACO"),
1085 _T("GERMAN_AUSTRIAN"),
1086 _T("GERMAN_BELGIUM"),
1087 _T("GERMAN_LIECHTENSTEIN"),
1088 _T("GERMAN_LUXEMBOURG"),
1106 _T("ITALIAN_SWISS"),
1111 _T("KASHMIRI_INDIA"),
1129 _T("MALAY_BRUNEI_DARUSSALAM"),
1130 _T("MALAY_MALAYSIA"),
1140 _T("NORWEGIAN_BOKMAL"),
1141 _T("NORWEGIAN_NYNORSK"),
1148 _T("PORTUGUESE_BRAZILIAN"),
1151 _T("RHAETO_ROMANCE"),
1154 _T("RUSSIAN_UKRAINE"),
1160 _T("SERBIAN_CYRILLIC"),
1161 _T("SERBIAN_LATIN"),
1162 _T("SERBO_CROATIAN"),
1173 _T("SPANISH_ARGENTINA"),
1174 _T("SPANISH_BOLIVIA"),
1175 _T("SPANISH_CHILE"),
1176 _T("SPANISH_COLOMBIA"),
1177 _T("SPANISH_COSTA_RICA"),
1178 _T("SPANISH_DOMINICAN_REPUBLIC"),
1179 _T("SPANISH_ECUADOR"),
1180 _T("SPANISH_EL_SALVADOR"),
1181 _T("SPANISH_GUATEMALA"),
1182 _T("SPANISH_HONDURAS"),
1183 _T("SPANISH_MEXICAN"),
1184 _T("SPANISH_MODERN"),
1185 _T("SPANISH_NICARAGUA"),
1186 _T("SPANISH_PANAMA"),
1187 _T("SPANISH_PARAGUAY"),
1189 _T("SPANISH_PUERTO_RICO"),
1190 _T("SPANISH_URUGUAY"),
1192 _T("SPANISH_VENEZUELA"),
1196 _T("SWEDISH_FINLAND"),
1214 _T("URDU_PAKISTAN"),
1216 _T("UZBEK_CYRILLIC"),
1229 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1230 return languageNames
[lang
];
1232 return _T("INVALID");
1235 static void TestDefaultLang()
1237 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1239 static const wxChar
*langStrings
[] =
1241 NULL
, // system default
1248 _T("de_DE.iso88591"),
1250 _T("?"), // invalid lang spec
1251 _T("klingonese"), // I bet on some systems it does exist...
1254 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1255 wxLocale::GetSystemEncodingName().c_str(),
1256 wxLocale::GetSystemEncoding());
1258 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1260 const wxChar
*langStr
= langStrings
[n
];
1263 // FIXME: this doesn't do anything at all under Windows, we need
1264 // to create a new wxLocale!
1265 wxSetEnv(_T("LC_ALL"), langStr
);
1268 int lang
= gs_localeDefault
.GetSystemLanguage();
1269 wxPrintf(_T("Locale for '%s' is %s.\n"),
1270 langStr
? langStr
: _T("system default"), GetLangName(lang
));
1274 #endif // TEST_LOCALE
1276 // ----------------------------------------------------------------------------
1278 // ----------------------------------------------------------------------------
1282 #include "wx/mimetype.h"
1284 static void TestMimeEnum()
1286 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1288 wxArrayString mimetypes
;
1290 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1292 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1297 for ( size_t n
= 0; n
< count
; n
++ )
1299 wxFileType
*filetype
=
1300 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1303 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1304 mimetypes
[n
].c_str());
1308 filetype
->GetDescription(&desc
);
1309 filetype
->GetExtensions(exts
);
1311 filetype
->GetIcon(NULL
);
1314 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1317 extsAll
<< _T(", ");
1321 wxPrintf(_T("\t%s: %s (%s)\n"),
1322 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1325 wxPuts(wxEmptyString
);
1328 static void TestMimeFilename()
1330 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1332 static const wxChar
*filenames
[] =
1340 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1342 const wxString fname
= filenames
[n
];
1343 wxString ext
= fname
.AfterLast(_T('.'));
1344 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1347 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1352 if ( !ft
->GetDescription(&desc
) )
1353 desc
= _T("<no description>");
1356 if ( !ft
->GetOpenCommand(&cmd
,
1357 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1358 cmd
= _T("<no command available>");
1360 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1362 wxPrintf(_T("To open %s (%s) do %s.\n"),
1363 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1369 wxPuts(wxEmptyString
);
1372 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1375 static void TestMimeOverride()
1377 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1379 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1380 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1382 if ( wxFile::Exists(mailcap
) )
1383 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1385 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1387 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1390 if ( wxFile::Exists(mimetypes
) )
1391 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1393 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1395 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1398 wxPuts(wxEmptyString
);
1401 static void TestMimeAssociate()
1403 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1405 wxFileTypeInfo
ftInfo(
1406 _T("application/x-xyz"),
1407 _T("xyzview '%s'"), // open cmd
1408 _T(""), // print cmd
1409 _T("XYZ File"), // description
1410 _T(".xyz"), // extensions
1411 wxNullPtr
// end of extensions
1413 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1415 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1418 wxPuts(_T("ERROR: failed to create association!"));
1422 // TODO: read it back
1426 wxPuts(wxEmptyString
);
1433 // ----------------------------------------------------------------------------
1434 // module dependencies feature
1435 // ----------------------------------------------------------------------------
1439 #include "wx/module.h"
1441 class wxTestModule
: public wxModule
1444 virtual bool OnInit() { wxPrintf(_T("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1445 virtual void OnExit() { wxPrintf(_T("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1448 class wxTestModuleA
: public wxTestModule
1453 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1456 class wxTestModuleB
: public wxTestModule
1461 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1464 class wxTestModuleC
: public wxTestModule
1469 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1472 class wxTestModuleD
: public wxTestModule
1477 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1480 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1481 wxTestModuleC::wxTestModuleC()
1483 AddDependency(CLASSINFO(wxTestModuleD
));
1486 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1487 wxTestModuleA::wxTestModuleA()
1489 AddDependency(CLASSINFO(wxTestModuleB
));
1490 AddDependency(CLASSINFO(wxTestModuleD
));
1493 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1494 wxTestModuleD::wxTestModuleD()
1498 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1499 wxTestModuleB::wxTestModuleB()
1501 AddDependency(CLASSINFO(wxTestModuleD
));
1502 AddDependency(CLASSINFO(wxTestModuleC
));
1505 #endif // TEST_MODULE
1507 // ----------------------------------------------------------------------------
1508 // misc information functions
1509 // ----------------------------------------------------------------------------
1511 #ifdef TEST_INFO_FUNCTIONS
1513 #include "wx/utils.h"
1515 #if TEST_INTERACTIVE
1516 static void TestDiskInfo()
1518 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1522 wxChar pathname
[128];
1523 wxPrintf(_T("\nEnter a directory name: "));
1524 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1527 // kill the last '\n'
1528 pathname
[wxStrlen(pathname
) - 1] = 0;
1530 wxLongLong total
, free
;
1531 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1533 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1537 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1538 (total
/ 1024).ToString().c_str(),
1539 (free
/ 1024).ToString().c_str(),
1544 #endif // TEST_INTERACTIVE
1546 static void TestOsInfo()
1548 wxPuts(_T("*** Testing OS info functions ***\n"));
1551 wxGetOsVersion(&major
, &minor
);
1552 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1553 wxGetOsDescription().c_str(), major
, minor
);
1555 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1557 wxPrintf(_T("Host name is %s (%s).\n"),
1558 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1560 wxPuts(wxEmptyString
);
1563 static void TestPlatformInfo()
1565 wxPuts(_T("*** Testing wxPlatformInfo functions ***\n"));
1567 // get this platform
1568 wxPlatformInfo plat
;
1570 wxPrintf(_T("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1571 wxPrintf(_T("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1572 wxPrintf(_T("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1573 wxPrintf(_T("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1574 wxPrintf(_T("Architecture is: %s\n"), plat
.GetArchName().c_str());
1575 wxPrintf(_T("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1577 wxPuts(wxEmptyString
);
1580 static void TestUserInfo()
1582 wxPuts(_T("*** Testing user info functions ***\n"));
1584 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1585 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1586 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1587 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1589 wxPuts(wxEmptyString
);
1592 #endif // TEST_INFO_FUNCTIONS
1594 // ----------------------------------------------------------------------------
1596 // ----------------------------------------------------------------------------
1598 #ifdef TEST_PATHLIST
1601 #define CMD_IN_PATH _T("ls")
1603 #define CMD_IN_PATH _T("command.com")
1606 static void TestPathList()
1608 wxPuts(_T("*** Testing wxPathList ***\n"));
1610 wxPathList pathlist
;
1611 pathlist
.AddEnvList(_T("PATH"));
1612 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1615 wxPrintf(_T("ERROR: command not found in the path.\n"));
1619 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
1623 #endif // TEST_PATHLIST
1625 // ----------------------------------------------------------------------------
1626 // regular expressions
1627 // ----------------------------------------------------------------------------
1631 #include "wx/regex.h"
1633 static void TestRegExInteractive()
1635 wxPuts(_T("*** Testing RE interactively ***"));
1639 wxChar pattern
[128];
1640 wxPrintf(_T("\nEnter a pattern: "));
1641 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1644 // kill the last '\n'
1645 pattern
[wxStrlen(pattern
) - 1] = 0;
1648 if ( !re
.Compile(pattern
) )
1656 wxPrintf(_T("Enter text to match: "));
1657 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1660 // kill the last '\n'
1661 text
[wxStrlen(text
) - 1] = 0;
1663 if ( !re
.Matches(text
) )
1665 wxPrintf(_T("No match.\n"));
1669 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1672 for ( size_t n
= 1; ; n
++ )
1674 if ( !re
.GetMatch(&start
, &len
, n
) )
1679 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1680 n
, wxString(text
+ start
, len
).c_str());
1687 #endif // TEST_REGEX
1689 // ----------------------------------------------------------------------------
1691 // ----------------------------------------------------------------------------
1694 NB: this stuff was taken from the glibc test suite and modified to build
1695 in wxWidgets: if I read the copyright below properly, this shouldn't
1701 #ifdef wxTEST_PRINTF
1702 // use our functions from wxchar.cpp
1706 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1707 // in the tests below
1708 int wxPrintf( const wxChar
*format
, ... );
1709 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1712 #include "wx/longlong.h"
1716 static void rfg1 (void);
1717 static void rfg2 (void);
1721 fmtchk (const wxChar
*fmt
)
1723 (void) wxPrintf(_T("%s:\t`"), fmt
);
1724 (void) wxPrintf(fmt
, 0x12);
1725 (void) wxPrintf(_T("'\n"));
1729 fmtst1chk (const wxChar
*fmt
)
1731 (void) wxPrintf(_T("%s:\t`"), fmt
);
1732 (void) wxPrintf(fmt
, 4, 0x12);
1733 (void) wxPrintf(_T("'\n"));
1737 fmtst2chk (const wxChar
*fmt
)
1739 (void) wxPrintf(_T("%s:\t`"), fmt
);
1740 (void) wxPrintf(fmt
, 4, 4, 0x12);
1741 (void) wxPrintf(_T("'\n"));
1744 /* This page is covered by the following copyright: */
1746 /* (C) Copyright C E Chew
1748 * Feel free to copy, use and distribute this software provided:
1750 * 1. you do not pretend that you wrote it
1751 * 2. you leave this copyright notice intact.
1755 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1762 /* Formatted Output Test
1764 * This exercises the output formatting code.
1767 wxChar
*PointerNull
= NULL
;
1774 wxChar
*prefix
= buf
;
1777 wxPuts(_T("\nFormatted output test"));
1778 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
1779 wxStrcpy(prefix
, _T("%"));
1780 for (i
= 0; i
< 2; i
++) {
1781 for (j
= 0; j
< 2; j
++) {
1782 for (k
= 0; k
< 2; k
++) {
1783 for (l
= 0; l
< 2; l
++) {
1784 wxStrcpy(prefix
, _T("%"));
1785 if (i
== 0) wxStrcat(prefix
, _T("-"));
1786 if (j
== 0) wxStrcat(prefix
, _T("+"));
1787 if (k
== 0) wxStrcat(prefix
, _T("#"));
1788 if (l
== 0) wxStrcat(prefix
, _T("0"));
1789 wxPrintf(_T("%5s |"), prefix
);
1790 wxStrcpy(tp
, prefix
);
1791 wxStrcat(tp
, _T("6d |"));
1793 wxStrcpy(tp
, prefix
);
1794 wxStrcat(tp
, _T("6o |"));
1796 wxStrcpy(tp
, prefix
);
1797 wxStrcat(tp
, _T("6x |"));
1799 wxStrcpy(tp
, prefix
);
1800 wxStrcat(tp
, _T("6X |"));
1802 wxStrcpy(tp
, prefix
);
1803 wxStrcat(tp
, _T("6u |"));
1810 wxPrintf(_T("%10s\n"), PointerNull
);
1811 wxPrintf(_T("%-10s\n"), PointerNull
);
1814 static void TestPrintf()
1816 static wxChar shortstr
[] = _T("Hi, Z.");
1817 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
1818 I am ready for my first lesson today.");
1820 wxString test_format
;
1824 fmtchk(_T("%4.4x"));
1825 fmtchk(_T("%04.4x"));
1826 fmtchk(_T("%4.3x"));
1827 fmtchk(_T("%04.3x"));
1829 fmtst1chk(_T("%.*x"));
1830 fmtst1chk(_T("%0*x"));
1831 fmtst2chk(_T("%*.*x"));
1832 fmtst2chk(_T("%0*.*x"));
1834 wxString bad_format
= _T("bad format:\t\"%b\"\n");
1835 wxPrintf(bad_format
.c_str());
1836 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1838 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
1839 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
1840 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
1841 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
1842 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
1843 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1844 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1845 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
1846 wxPrintf(test_format
.c_str(), -123456);
1847 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1848 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1850 test_format
= _T("zero-padded string:\t\"%010s\"\n");
1851 wxPrintf(test_format
.c_str(), shortstr
);
1852 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
1853 wxPrintf(test_format
.c_str(), shortstr
);
1854 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
1855 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1856 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
1857 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
1859 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
1860 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
1861 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
1862 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
1863 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
1864 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
1865 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
1866 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
1867 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
1868 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
1869 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
1870 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
1872 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
1873 wxPrintf (_T(" %6.5f\n"), .1);
1874 wxPrintf (_T("x%5.4fx\n"), .5);
1876 wxPrintf (_T("%#03x\n"), 1);
1878 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
1884 while (niter
-- != 0)
1885 wxPrintf (_T("%.17e\n"), d
/ 2);
1890 // Open Watcom cause compiler error here
1891 // Error! E173: col(24) floating-point constant too small to represent
1892 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
1895 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
1896 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1897 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1898 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1899 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1900 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1901 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1902 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1903 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1904 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1909 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
1911 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1912 rc
, WXSIZEOF(buf
), buf
);
1915 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1916 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1922 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
1923 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
1924 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
1925 wxPrintf (_T("%g should be 123.456\n"), 123.456);
1926 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
1927 wxPrintf (_T("%g should be 10\n"), 10.0);
1928 wxPrintf (_T("%g should be 0.02\n"), 0.02);
1932 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1938 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
1940 result
|= wxStrcmp (buf
,
1941 _T("onetwo three "));
1943 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
1950 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
1952 // for some reason below line fails under Borland
1953 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1956 if (wxStrcmp (buf
, _T("40000000000")) != 0)
1959 wxPuts (_T("\tFAILED"));
1961 wxUnusedVar(result
);
1962 wxPuts (wxEmptyString
);
1964 #endif // wxLongLong_t
1966 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1967 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1969 wxPuts (_T("--- Should be no further output. ---"));
1978 memset (bytes
, '\xff', sizeof bytes
);
1979 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
1980 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1981 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1983 wxPuts (_T("%hhn overwrite more bytes"));
1988 wxPuts (_T("%hhn wrote incorrect value"));
2000 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2001 if (wxStrcmp (buf
, _T(" ")) != 0)
2002 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2003 wxSprintf (buf
, _T("%5.f"), 33.3);
2004 if (wxStrcmp (buf
, _T(" 33")) != 0)
2005 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2006 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2007 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2008 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2009 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2010 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2011 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2012 wxSprintf (buf
, _T("%.g"), 33.3);
2013 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2014 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2015 wxSprintf (buf
, _T("%.G"), 33.3);
2016 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2017 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2025 wxString test_format
;
2028 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2029 if (wxStrcmp (buf
, _T("3")) != 0)
2030 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2032 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2033 if (wxStrcmp (buf
, _T("3")) != 0)
2034 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2036 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2037 if (wxStrcmp (buf
, _T(" 3")) != 0)
2038 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2040 test_format
= _T("%04.*o");
2041 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2042 if (wxStrcmp (buf
, _T(" 041")) != 0)
2043 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2045 test_format
= _T("%09.*u");
2046 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2047 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2048 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2050 test_format
= _T("%04.*x");
2051 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2052 if (wxStrcmp (buf
, _T(" 021")) != 0)
2053 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2055 test_format
= _T("%04.*X");
2056 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2057 if (wxStrcmp (buf
, _T(" 021")) != 0)
2058 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2061 #endif // TEST_PRINTF
2063 // ----------------------------------------------------------------------------
2064 // registry and related stuff
2065 // ----------------------------------------------------------------------------
2067 // this is for MSW only
2070 #undef TEST_REGISTRY
2075 #include "wx/confbase.h"
2076 #include "wx/msw/regconf.h"
2079 static void TestRegConfWrite()
2081 wxConfig
*config
= new wxConfig(_T("myapp"));
2082 config
->SetPath(_T("/group1"));
2083 config
->Write(_T("entry1"), _T("foo"));
2084 config
->SetPath(_T("/group2"));
2085 config
->Write(_T("entry1"), _T("bar"));
2089 static void TestRegConfRead()
2091 wxRegConfig
*config
= new wxRegConfig(_T("myapp"));
2095 config
->SetPath(_T("/"));
2096 wxPuts(_T("Enumerating / subgroups:"));
2097 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2101 bCont
= config
->GetNextGroup(str
, dummy
);
2105 #endif // TEST_REGCONF
2107 #ifdef TEST_REGISTRY
2109 #include "wx/msw/registry.h"
2111 // I chose this one because I liked its name, but it probably only exists under
2113 static const wxChar
*TESTKEY
=
2114 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2116 static void TestRegistryRead()
2118 wxPuts(_T("*** testing registry reading ***"));
2120 wxRegKey
key(TESTKEY
);
2121 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2124 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2129 size_t nSubKeys
, nValues
;
2130 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2132 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2135 wxPrintf(_T("Enumerating values:\n"));
2139 bool cont
= key
.GetFirstValue(value
, dummy
);
2142 wxPrintf(_T("Value '%s': type "), value
.c_str());
2143 switch ( key
.GetValueType(value
) )
2145 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2146 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
2147 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2148 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
2149 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
2150 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2151 default: wxPrintf(_T("other (unknown)")); break;
2154 wxPrintf(_T(", value = "));
2155 if ( key
.IsNumericValue(value
) )
2158 key
.QueryValue(value
, &val
);
2159 wxPrintf(_T("%ld"), val
);
2164 key
.QueryValue(value
, val
);
2165 wxPrintf(_T("'%s'"), val
.c_str());
2167 key
.QueryRawValue(value
, val
);
2168 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2173 cont
= key
.GetNextValue(value
, dummy
);
2177 static void TestRegistryAssociation()
2180 The second call to deleteself genertaes an error message, with a
2181 messagebox saying .flo is crucial to system operation, while the .ddf
2182 call also fails, but with no error message
2187 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2189 key
= _T("ddxf_auto_file") ;
2190 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2192 key
= _T("ddxf_auto_file") ;
2193 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2195 key
= _T("program,0") ;
2196 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2198 key
= _T("program \"%1\"") ;
2200 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2202 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2204 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2206 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2210 #endif // TEST_REGISTRY
2212 // ----------------------------------------------------------------------------
2214 // ----------------------------------------------------------------------------
2216 #ifdef TEST_SCOPEGUARD
2218 #include "wx/scopeguard.h"
2220 static void function0() { puts("function0()"); }
2221 static void function1(int n
) { printf("function1(%d)\n", n
); }
2222 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2226 void method0() { printf("method0()\n"); }
2227 void method1(int n
) { printf("method1(%d)\n", n
); }
2228 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2231 static void TestScopeGuard()
2233 wxON_BLOCK_EXIT0(function0
);
2234 wxON_BLOCK_EXIT1(function1
, 17);
2235 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2238 wxON_BLOCK_EXIT_OBJ0(obj
, Object::method0
);
2239 wxON_BLOCK_EXIT_OBJ1(obj
, Object::method1
, 7);
2240 wxON_BLOCK_EXIT_OBJ2(obj
, Object::method2
, 2.71, 'e');
2242 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2243 dismissed
.Dismiss();
2248 // ----------------------------------------------------------------------------
2250 // ----------------------------------------------------------------------------
2254 #include "wx/socket.h"
2255 #include "wx/protocol/protocol.h"
2256 #include "wx/protocol/http.h"
2258 static void TestSocketServer()
2260 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2262 static const int PORT
= 3000;
2267 wxSocketServer
*server
= new wxSocketServer(addr
);
2268 if ( !server
->Ok() )
2270 wxPuts(_T("ERROR: failed to bind"));
2278 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2280 wxSocketBase
*socket
= server
->Accept();
2283 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2287 wxPuts(_T("Server: got a client."));
2289 server
->SetTimeout(60); // 1 min
2292 while ( !close
&& socket
->IsConnected() )
2295 wxChar ch
= _T('\0');
2298 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2300 // don't log error if the client just close the connection
2301 if ( socket
->IsConnected() )
2303 wxPuts(_T("ERROR: in wxSocket::Read."));
2323 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2324 if ( s
== _T("close") )
2326 wxPuts(_T("Closing connection"));
2330 else if ( s
== _T("quit") )
2335 wxPuts(_T("Shutting down the server"));
2337 else // not a special command
2339 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2340 socket
->Write("\r\n", 2);
2341 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
2347 wxPuts(_T("Server: lost a client unexpectedly."));
2353 // same as "delete server" but is consistent with GUI programs
2357 static void TestSocketClient()
2359 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2361 static const wxChar
*hostname
= _T("www.wxwidgets.org");
2364 addr
.Hostname(hostname
);
2367 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
2369 wxSocketClient client
;
2370 if ( !client
.Connect(addr
) )
2372 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2376 wxPrintf(_T("--- Connected to %s:%u...\n"),
2377 addr
.Hostname().c_str(), addr
.Service());
2381 // could use simply "GET" here I suppose
2383 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
2384 client
.Write(cmdGet
, cmdGet
.length());
2385 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2386 MakePrintable(cmdGet
).c_str());
2387 client
.Read(buf
, WXSIZEOF(buf
));
2388 wxPrintf(_T("--- Server replied:\n%s"), buf
);
2392 #endif // TEST_SOCKETS
2394 // ----------------------------------------------------------------------------
2396 // ----------------------------------------------------------------------------
2400 #include "wx/protocol/ftp.h"
2404 #define FTP_ANONYMOUS
2406 #ifdef FTP_ANONYMOUS
2407 static const wxChar
*directory
= _T("/pub");
2408 static const wxChar
*filename
= _T("welcome.msg");
2410 static const wxChar
*directory
= _T("/etc");
2411 static const wxChar
*filename
= _T("issue");
2414 static bool TestFtpConnect()
2416 wxPuts(_T("*** Testing FTP connect ***"));
2418 #ifdef FTP_ANONYMOUS
2419 static const wxChar
*hostname
= _T("ftp.wxwidgets.org");
2421 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2422 #else // !FTP_ANONYMOUS
2423 static const wxChar
*hostname
= "localhost";
2426 wxFgets(user
, WXSIZEOF(user
), stdin
);
2427 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2430 wxChar password
[256];
2431 wxPrintf(_T("Password for %s: "), password
);
2432 wxFgets(password
, WXSIZEOF(password
), stdin
);
2433 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2434 ftp
.SetPassword(password
);
2436 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2437 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2439 if ( !ftp
.Connect(hostname
) )
2441 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2447 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2448 hostname
, ftp
.Pwd().c_str());
2455 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2456 static void TestFtpWuFtpd()
2459 static const wxChar
*hostname
= _T("ftp.eudora.com");
2460 if ( !ftp
.Connect(hostname
) )
2462 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2466 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
2467 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2470 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2474 size_t size
= in
->GetSize();
2475 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2477 wxChar
*data
= new wxChar
[size
];
2478 if ( !in
->Read(data
, size
) )
2480 wxPuts(_T("ERROR: read error"));
2484 wxPrintf(_T("Successfully retrieved the file.\n"));
2493 static void TestFtpList()
2495 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2498 if ( !ftp
.ChDir(directory
) )
2500 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2503 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2505 // test NLIST and LIST
2506 wxArrayString files
;
2507 if ( !ftp
.GetFilesList(files
) )
2509 wxPuts(_T("ERROR: failed to get NLIST of files"));
2513 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
2514 size_t count
= files
.GetCount();
2515 for ( size_t n
= 0; n
< count
; n
++ )
2517 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2519 wxPuts(_T("End of the file list"));
2522 if ( !ftp
.GetDirList(files
) )
2524 wxPuts(_T("ERROR: failed to get LIST of files"));
2528 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
2529 size_t count
= files
.GetCount();
2530 for ( size_t n
= 0; n
< count
; n
++ )
2532 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2534 wxPuts(_T("End of the file list"));
2537 if ( !ftp
.ChDir(_T("..")) )
2539 wxPuts(_T("ERROR: failed to cd to .."));
2542 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2545 static void TestFtpDownload()
2547 wxPuts(_T("*** Testing wxFTP download ***\n"));
2550 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2553 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2557 size_t size
= in
->GetSize();
2558 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2561 wxChar
*data
= new wxChar
[size
];
2562 if ( !in
->Read(data
, size
) )
2564 wxPuts(_T("ERROR: read error"));
2568 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
2576 static void TestFtpFileSize()
2578 wxPuts(_T("*** Testing FTP SIZE command ***"));
2580 if ( !ftp
.ChDir(directory
) )
2582 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2585 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2587 if ( ftp
.FileExists(filename
) )
2589 int size
= ftp
.GetFileSize(filename
);
2591 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
2593 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
2597 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
2601 static void TestFtpMisc()
2603 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2605 if ( ftp
.SendCommand(_T("STAT")) != '2' )
2607 wxPuts(_T("ERROR: STAT failed"));
2611 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
2614 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
2616 wxPuts(_T("ERROR: HELP SITE failed"));
2620 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2621 ftp
.GetLastResult().c_str());
2625 static void TestFtpInteractive()
2627 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2633 wxPrintf(_T("Enter FTP command: "));
2634 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2637 // kill the last '\n'
2638 buf
[wxStrlen(buf
) - 1] = 0;
2640 // special handling of LIST and NLST as they require data connection
2641 wxString
start(buf
, 4);
2643 if ( start
== _T("LIST") || start
== _T("NLST") )
2646 if ( wxStrlen(buf
) > 4 )
2649 wxArrayString files
;
2650 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
2652 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
2656 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2657 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2658 size_t count
= files
.GetCount();
2659 for ( size_t n
= 0; n
< count
; n
++ )
2661 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2663 wxPuts(_T("--- End of the file list"));
2668 wxChar ch
= ftp
.SendCommand(buf
);
2669 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
2672 wxPrintf(_T(" (return code %c)"), ch
);
2675 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
2679 wxPuts(_T("\n*** done ***"));
2682 static void TestFtpUpload()
2684 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2687 static const wxChar
*file1
= _T("test1");
2688 static const wxChar
*file2
= _T("test2");
2689 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2692 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2693 out
->Write("First hello", 11);
2697 // send a command to check the remote file
2698 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
2700 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
2704 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2705 file1
, ftp
.GetLastResult().c_str());
2708 out
= ftp
.GetOutputStream(file2
);
2711 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2712 out
->Write("Second hello", 12);
2719 // ----------------------------------------------------------------------------
2721 // ----------------------------------------------------------------------------
2723 #ifdef TEST_STACKWALKER
2725 #if wxUSE_STACKWALKER
2727 #include "wx/stackwalk.h"
2729 class StackDump
: public wxStackWalker
2732 StackDump(const char *argv0
)
2733 : wxStackWalker(argv0
)
2737 virtual void Walk(size_t skip
= 1)
2739 wxPuts(_T("Stack dump:"));
2741 wxStackWalker::Walk(skip
);
2745 virtual void OnStackFrame(const wxStackFrame
& frame
)
2747 printf("[%2d] ", (int) frame
.GetLevel());
2749 wxString name
= frame
.GetName();
2750 if ( !name
.empty() )
2752 printf("%-20.40s", (const char*)name
.mb_str());
2756 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2759 if ( frame
.HasSourceLocation() )
2762 (const char*)frame
.GetFileName().mb_str(),
2763 (int)frame
.GetLine());
2769 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2771 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2772 (const char*)name
.mb_str(),
2773 (const char*)val
.mb_str());
2778 static void TestStackWalk(const char *argv0
)
2780 wxPuts(_T("*** Testing wxStackWalker ***\n"));
2782 StackDump
dump(argv0
);
2786 #endif // wxUSE_STACKWALKER
2788 #endif // TEST_STACKWALKER
2790 // ----------------------------------------------------------------------------
2792 // ----------------------------------------------------------------------------
2794 #ifdef TEST_STDPATHS
2796 #include "wx/stdpaths.h"
2797 #include "wx/wxchar.h" // wxPrintf
2799 static void TestStandardPaths()
2801 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
2803 wxTheApp
->SetAppName(_T("console"));
2805 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
2806 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2807 wxPrintf(_T("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2808 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2809 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2810 wxPrintf(_T("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2811 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2812 wxPrintf(_T("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2813 wxPrintf(_T("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2814 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2815 wxPrintf(_T("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2816 wxPrintf(_T("Localized res. dir:\t%s\n"),
2817 stdp
.GetLocalizedResourcesDir(_T("fr")).c_str());
2818 wxPrintf(_T("Message catalogs dir:\t%s\n"),
2819 stdp
.GetLocalizedResourcesDir
2822 wxStandardPaths::ResourceCat_Messages
2826 #endif // TEST_STDPATHS
2828 // ----------------------------------------------------------------------------
2830 // ----------------------------------------------------------------------------
2834 #include "wx/wfstream.h"
2835 #include "wx/mstream.h"
2837 static void TestFileStream()
2839 wxPuts(_T("*** Testing wxFileInputStream ***"));
2841 static const wxString filename
= _T("testdata.fs");
2843 wxFileOutputStream
fsOut(filename
);
2844 fsOut
.Write("foo", 3);
2848 wxFileInputStream
fsIn(filename
);
2849 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
2850 while ( !fsIn
.Eof() )
2852 wxPutchar(fsIn
.GetC());
2856 if ( !wxRemoveFile(filename
) )
2858 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2861 wxPuts(_T("\n*** wxFileInputStream test done ***"));
2864 static void TestMemoryStream()
2866 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
2868 wxMemoryOutputStream memOutStream
;
2869 wxPrintf(_T("Initially out stream offset: %lu\n"),
2870 (unsigned long)memOutStream
.TellO());
2872 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
2874 memOutStream
.PutC(*p
);
2877 wxPrintf(_T("Final out stream offset: %lu\n"),
2878 (unsigned long)memOutStream
.TellO());
2880 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
2883 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2885 wxMemoryInputStream
memInpStream(buf
, len
);
2886 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2887 while ( !memInpStream
.Eof() )
2889 wxPutchar(memInpStream
.GetC());
2892 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
2895 #endif // TEST_STREAMS
2897 // ----------------------------------------------------------------------------
2899 // ----------------------------------------------------------------------------
2903 #include "wx/stopwatch.h"
2904 #include "wx/utils.h"
2906 static void TestStopWatch()
2908 wxPuts(_T("*** Testing wxStopWatch ***\n"));
2912 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
2915 wxPrintf(_T("\t%ldms\n"), sw
.Time());
2917 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
2921 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2924 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
2927 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2930 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
2933 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2936 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
2937 for ( size_t n
= 0; n
< 70; n
++ )
2941 for ( size_t m
= 0; m
< 100000; m
++ )
2943 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2945 wxPuts(_T("\ntime is negative - ERROR!"));
2953 wxPuts(_T(", ok."));
2956 #include "wx/timer.h"
2957 #include "wx/evtloop.h"
2961 wxPuts(_T("*** Testing wxTimer ***\n"));
2963 class MyTimer
: public wxTimer
2966 MyTimer() : wxTimer() { m_num
= 0; }
2968 virtual void Notify()
2970 wxPrintf(_T("%d"), m_num
++);
2975 wxPrintf(_T("... exiting the event loop"));
2978 wxEventLoop::GetActive()->Exit(0);
2979 wxPuts(_T(", ok."));
2992 timer1
.Start(100, true /* one shot */);
2994 timer1
.Start(100, true /* one shot */);
3002 #endif // TEST_TIMER
3004 // ----------------------------------------------------------------------------
3006 // ----------------------------------------------------------------------------
3010 #include "wx/vcard.h"
3012 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3015 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3018 wxPrintf(_T("%s%s"),
3019 wxString(_T('\t'), level
).c_str(),
3020 vcObj
->GetName().c_str());
3023 switch ( vcObj
->GetType() )
3025 case wxVCardObject::String
:
3026 case wxVCardObject::UString
:
3029 vcObj
->GetValue(&val
);
3030 value
<< _T('"') << val
<< _T('"');
3034 case wxVCardObject::Int
:
3037 vcObj
->GetValue(&i
);
3038 value
.Printf(_T("%u"), i
);
3042 case wxVCardObject::Long
:
3045 vcObj
->GetValue(&l
);
3046 value
.Printf(_T("%lu"), l
);
3050 case wxVCardObject::None
:
3053 case wxVCardObject::Object
:
3054 value
= _T("<node>");
3058 value
= _T("<unknown value type>");
3062 wxPrintf(_T(" = %s"), value
.c_str());
3065 DumpVObject(level
+ 1, *vcObj
);
3068 vcObj
= vcard
.GetNextProp(&cookie
);
3072 static void DumpVCardAddresses(const wxVCard
& vcard
)
3074 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3078 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3082 int flags
= addr
->GetFlags();
3083 if ( flags
& wxVCardAddress::Domestic
)
3085 flagsStr
<< _T("domestic ");
3087 if ( flags
& wxVCardAddress::Intl
)
3089 flagsStr
<< _T("international ");
3091 if ( flags
& wxVCardAddress::Postal
)
3093 flagsStr
<< _T("postal ");
3095 if ( flags
& wxVCardAddress::Parcel
)
3097 flagsStr
<< _T("parcel ");
3099 if ( flags
& wxVCardAddress::Home
)
3101 flagsStr
<< _T("home ");
3103 if ( flags
& wxVCardAddress::Work
)
3105 flagsStr
<< _T("work ");
3108 wxPrintf(_T("Address %u:\n")
3110 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3113 addr
->GetPostOffice().c_str(),
3114 addr
->GetExtAddress().c_str(),
3115 addr
->GetStreet().c_str(),
3116 addr
->GetLocality().c_str(),
3117 addr
->GetRegion().c_str(),
3118 addr
->GetPostalCode().c_str(),
3119 addr
->GetCountry().c_str()
3123 addr
= vcard
.GetNextAddress(&cookie
);
3127 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3129 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3133 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3137 int flags
= phone
->GetFlags();
3138 if ( flags
& wxVCardPhoneNumber::Voice
)
3140 flagsStr
<< _T("voice ");
3142 if ( flags
& wxVCardPhoneNumber::Fax
)
3144 flagsStr
<< _T("fax ");
3146 if ( flags
& wxVCardPhoneNumber::Cellular
)
3148 flagsStr
<< _T("cellular ");
3150 if ( flags
& wxVCardPhoneNumber::Modem
)
3152 flagsStr
<< _T("modem ");
3154 if ( flags
& wxVCardPhoneNumber::Home
)
3156 flagsStr
<< _T("home ");
3158 if ( flags
& wxVCardPhoneNumber::Work
)
3160 flagsStr
<< _T("work ");
3163 wxPrintf(_T("Phone number %u:\n")
3168 phone
->GetNumber().c_str()
3172 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3176 static void TestVCardRead()
3178 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3180 wxVCard
vcard(_T("vcard.vcf"));
3181 if ( !vcard
.IsOk() )
3183 wxPuts(_T("ERROR: couldn't load vCard."));
3187 // read individual vCard properties
3188 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3192 vcObj
->GetValue(&value
);
3197 value
= _T("<none>");
3200 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3203 if ( !vcard
.GetFullName(&value
) )
3205 value
= _T("<none>");
3208 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3210 // now show how to deal with multiply occurring properties
3211 DumpVCardAddresses(vcard
);
3212 DumpVCardPhoneNumbers(vcard
);
3214 // and finally show all
3215 wxPuts(_T("\nNow dumping the entire vCard:\n")
3216 "-----------------------------\n");
3218 DumpVObject(0, vcard
);
3222 static void TestVCardWrite()
3224 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3227 if ( !vcard
.IsOk() )
3229 wxPuts(_T("ERROR: couldn't create vCard."));
3234 vcard
.SetName("Zeitlin", "Vadim");
3235 vcard
.SetFullName("Vadim Zeitlin");
3236 vcard
.SetOrganization("wxWidgets", "R&D");
3238 // just dump the vCard back
3239 wxPuts(_T("Entire vCard follows:\n"));
3240 wxPuts(vcard
.Write());
3244 #endif // TEST_VCARD
3246 // ----------------------------------------------------------------------------
3248 // ----------------------------------------------------------------------------
3250 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3256 #include "wx/volume.h"
3258 static const wxChar
*volumeKinds
[] =
3264 _T("network volume"),
3268 static void TestFSVolume()
3270 wxPuts(_T("*** Testing wxFSVolume class ***"));
3272 wxArrayString volumes
= wxFSVolume::GetVolumes();
3273 size_t count
= volumes
.GetCount();
3277 wxPuts(_T("ERROR: no mounted volumes?"));
3281 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3283 for ( size_t n
= 0; n
< count
; n
++ )
3285 wxFSVolume
vol(volumes
[n
]);
3288 wxPuts(_T("ERROR: couldn't create volume"));
3292 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3294 vol
.GetDisplayName().c_str(),
3295 vol
.GetName().c_str(),
3296 volumeKinds
[vol
.GetKind()],
3297 vol
.IsWritable() ? _T("rw") : _T("ro"),
3298 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3303 #endif // TEST_VOLUME
3305 // ----------------------------------------------------------------------------
3306 // wide char and Unicode support
3307 // ----------------------------------------------------------------------------
3311 #include "wx/strconv.h"
3312 #include "wx/fontenc.h"
3313 #include "wx/encconv.h"
3314 #include "wx/buffer.h"
3316 static const unsigned char utf8koi8r
[] =
3318 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3319 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3320 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3321 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3322 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3323 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3324 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3327 static const unsigned char utf8iso8859_1
[] =
3329 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3330 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3331 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3332 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3333 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3336 static const unsigned char utf8Invalid
[] =
3338 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3339 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3340 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3341 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3345 static const struct Utf8Data
3347 const unsigned char *text
;
3349 const wxChar
*charset
;
3350 wxFontEncoding encoding
;
3353 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3354 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3355 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3358 static void TestUtf8()
3360 wxPuts(_T("*** Testing UTF8 support ***\n"));
3365 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3367 const Utf8Data
& u8d
= utf8data
[n
];
3368 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3369 WXSIZEOF(wbuf
)) == (size_t)-1 )
3371 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3375 wxCSConv
conv(u8d
.charset
);
3376 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3378 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3382 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3386 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3388 s
= _T("<< conversion failed >>");
3389 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3393 wxPuts(wxEmptyString
);
3396 static void TestEncodingConverter()
3398 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3400 // using wxEncodingConverter should give the same result as above
3403 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3404 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3406 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3410 wxEncodingConverter ec
;
3411 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3412 ec
.Convert(wbuf
, buf
);
3413 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3416 wxPuts(wxEmptyString
);
3419 #endif // TEST_WCHAR
3421 // ----------------------------------------------------------------------------
3423 // ----------------------------------------------------------------------------
3427 #include "wx/filesys.h"
3428 #include "wx/fs_zip.h"
3429 #include "wx/zipstrm.h"
3431 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3433 static void TestZipStreamRead()
3435 wxPuts(_T("*** Testing ZIP reading ***\n"));
3437 static const wxString filename
= _T("foo");
3438 wxFFileInputStream
in(TESTFILE_ZIP
);
3439 wxZipInputStream
istr(in
);
3440 wxZipEntry
entry(filename
);
3441 istr
.OpenEntry(entry
);
3443 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3445 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3446 while ( !istr
.Eof() )
3448 wxPutchar(istr
.GetC());
3452 wxPuts(_T("\n----- done ------"));
3455 static void DumpZipDirectory(wxFileSystem
& fs
,
3456 const wxString
& dir
,
3457 const wxString
& indent
)
3459 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3460 TESTFILE_ZIP
, dir
.c_str());
3461 wxString wildcard
= prefix
+ _T("/*");
3463 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3464 while ( !dirname
.empty() )
3466 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3468 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3473 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3475 DumpZipDirectory(fs
, dirname
,
3476 indent
+ wxString(_T(' '), 4));
3478 dirname
= fs
.FindNext();
3481 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3482 while ( !filename
.empty() )
3484 if ( !filename
.StartsWith(prefix
, &filename
) )
3486 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3491 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3493 filename
= fs
.FindNext();
3497 static void TestZipFileSystem()
3499 wxPuts(_T("*** Testing ZIP file system ***\n"));
3501 wxFileSystem::AddHandler(new wxZipFSHandler
);
3503 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3505 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3510 // ----------------------------------------------------------------------------
3512 // ----------------------------------------------------------------------------
3514 #ifdef TEST_DATETIME
3516 #include "wx/math.h"
3517 #include "wx/datetime.h"
3519 // this test miscellaneous static wxDateTime functions
3523 static void TestTimeStatic()
3525 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3527 // some info about the current date
3528 int year
= wxDateTime::GetCurrentYear();
3529 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3531 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3532 wxDateTime::GetNumberOfDays(year
));
3534 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3535 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3536 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3537 wxDateTime::GetMonthName(month
).c_str(),
3538 wxDateTime::GetNumberOfDays(month
));
3541 // test time zones stuff
3542 static void TestTimeZones()
3544 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3546 wxDateTime now
= wxDateTime::Now();
3548 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
3549 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
3550 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
3551 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
3552 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
3553 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
3555 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3557 wxDateTime::Tm tm
= now
.GetTm();
3558 if ( wxDateTime(tm
) != now
)
3560 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3561 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3565 // test some minimal support for the dates outside the standard range
3566 static void TestTimeRange()
3568 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3570 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
3572 wxPrintf(_T("Unix epoch:\t%s\n"),
3573 wxDateTime(2440587.5).Format(fmt
).c_str());
3574 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3575 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3576 wxPrintf(_T("JDN 0: \t%s\n"),
3577 wxDateTime(0.0).Format(fmt
).c_str());
3578 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3579 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3580 wxPrintf(_T("May 29, 2099:\t%s\n"),
3581 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3584 // test DST calculations
3585 static void TestTimeDST()
3587 wxPuts(_T("\n*** wxDateTime DST test ***"));
3589 wxPrintf(_T("DST is%s in effect now.\n\n"),
3590 wxDateTime::Now().IsDST() ? wxEmptyString
: _T(" not"));
3592 for ( int year
= 1990; year
< 2005; year
++ )
3594 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3596 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3597 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3603 #if TEST_INTERACTIVE
3605 static void TestDateTimeInteractive()
3607 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3613 wxPrintf(_T("Enter a date: "));
3614 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3617 // kill the last '\n'
3618 buf
[wxStrlen(buf
) - 1] = 0;
3621 const wxChar
*p
= dt
.ParseDate(buf
);
3624 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
3630 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
3633 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3634 dt
.Format(_T("%b %d, %Y")).c_str(),
3636 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3637 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3638 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3641 wxPuts(_T("\n*** done ***"));
3644 #endif // TEST_INTERACTIVE
3648 static void TestTimeMS()
3650 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3652 wxDateTime dt1
= wxDateTime::Now(),
3653 dt2
= wxDateTime::UNow();
3655 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
3656 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3657 wxPrintf(_T("Dummy loop: "));
3658 for ( int i
= 0; i
< 6000; i
++ )
3660 //for ( int j = 0; j < 10; j++ )
3663 s
.Printf(_T("%g"), sqrt((float)i
));
3669 wxPuts(_T(", done"));
3672 dt2
= wxDateTime::UNow();
3673 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3675 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
3677 wxPuts(_T("\n*** done ***"));
3680 static void TestTimeHolidays()
3682 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3684 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3685 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3686 dtEnd
= dtStart
.GetLastMonthDay();
3688 wxDateTimeArray hol
;
3689 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3691 const wxChar
*format
= _T("%d-%b-%Y (%a)");
3693 wxPrintf(_T("All holidays between %s and %s:\n"),
3694 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3696 size_t count
= hol
.GetCount();
3697 for ( size_t n
= 0; n
< count
; n
++ )
3699 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
3702 wxPuts(wxEmptyString
);
3705 static void TestTimeZoneBug()
3707 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3709 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3710 for ( int i
= 0; i
< 31; i
++ )
3712 wxPrintf(_T("Date %s: week day %s.\n"),
3713 date
.Format(_T("%d-%m-%Y")).c_str(),
3714 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3716 date
+= wxDateSpan::Day();
3719 wxPuts(wxEmptyString
);
3722 static void TestTimeSpanFormat()
3724 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3726 static const wxChar
*formats
[] =
3728 _T("(default) %H:%M:%S"),
3729 _T("%E weeks and %D days"),
3730 _T("%l milliseconds"),
3731 _T("(with ms) %H:%M:%S:%l"),
3732 _T("100%% of minutes is %M"), // test "%%"
3733 _T("%D days and %H hours"),
3734 _T("or also %S seconds"),
3737 wxTimeSpan
ts1(1, 2, 3, 4),
3739 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3741 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3742 ts1
.Format(formats
[n
]).c_str(),
3743 ts2
.Format(formats
[n
]).c_str());
3746 wxPuts(wxEmptyString
);
3751 #endif // TEST_DATETIME
3753 // ----------------------------------------------------------------------------
3754 // wxTextInput/OutputStream
3755 // ----------------------------------------------------------------------------
3757 #ifdef TEST_TEXTSTREAM
3759 #include "wx/txtstrm.h"
3760 #include "wx/wfstream.h"
3762 static void TestTextInputStream()
3764 wxPuts(_T("\n*** wxTextInputStream test ***"));
3766 wxString filename
= _T("testdata.fc");
3767 wxFileInputStream
fsIn(filename
);
3770 wxPuts(_T("ERROR: couldn't open file."));
3774 wxTextInputStream
tis(fsIn
);
3779 const wxString s
= tis
.ReadLine();
3781 // line could be non empty if the last line of the file isn't
3782 // terminated with EOL
3783 if ( fsIn
.Eof() && s
.empty() )
3786 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
3791 #endif // TEST_TEXTSTREAM
3793 // ----------------------------------------------------------------------------
3795 // ----------------------------------------------------------------------------
3799 #include "wx/thread.h"
3801 static size_t gs_counter
= (size_t)-1;
3802 static wxCriticalSection gs_critsect
;
3803 static wxSemaphore gs_cond
;
3805 class MyJoinableThread
: public wxThread
3808 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3809 { m_n
= n
; Create(); }
3811 // thread execution starts here
3812 virtual ExitCode
Entry();
3818 wxThread::ExitCode
MyJoinableThread::Entry()
3820 unsigned long res
= 1;
3821 for ( size_t n
= 1; n
< m_n
; n
++ )
3825 // it's a loooong calculation :-)
3829 return (ExitCode
)res
;
3832 class MyDetachedThread
: public wxThread
3835 MyDetachedThread(size_t n
, wxChar ch
)
3839 m_cancelled
= false;
3844 // thread execution starts here
3845 virtual ExitCode
Entry();
3848 virtual void OnExit();
3851 size_t m_n
; // number of characters to write
3852 wxChar m_ch
; // character to write
3854 bool m_cancelled
; // false if we exit normally
3857 wxThread::ExitCode
MyDetachedThread::Entry()
3860 wxCriticalSectionLocker
lock(gs_critsect
);
3861 if ( gs_counter
== (size_t)-1 )
3867 for ( size_t n
= 0; n
< m_n
; n
++ )
3869 if ( TestDestroy() )
3879 wxThread::Sleep(100);
3885 void MyDetachedThread::OnExit()
3887 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
3889 wxCriticalSectionLocker
lock(gs_critsect
);
3890 if ( !--gs_counter
&& !m_cancelled
)
3894 static void TestDetachedThreads()
3896 wxPuts(_T("\n*** Testing detached threads ***"));
3898 static const size_t nThreads
= 3;
3899 MyDetachedThread
*threads
[nThreads
];
3901 for ( n
= 0; n
< nThreads
; n
++ )
3903 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3906 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3907 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3909 for ( n
= 0; n
< nThreads
; n
++ )
3914 // wait until all threads terminate
3917 wxPuts(wxEmptyString
);
3920 static void TestJoinableThreads()
3922 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
3924 // calc 10! in the background
3925 MyJoinableThread
thread(10);
3928 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
3929 (unsigned long)thread
.Wait());
3932 static void TestThreadSuspend()
3934 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
3936 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3940 // this is for this demo only, in a real life program we'd use another
3941 // condition variable which would be signaled from wxThread::Entry() to
3942 // tell us that the thread really started running - but here just wait a
3943 // bit and hope that it will be enough (the problem is, of course, that
3944 // the thread might still not run when we call Pause() which will result
3946 wxThread::Sleep(300);
3948 for ( size_t n
= 0; n
< 3; n
++ )
3952 wxPuts(_T("\nThread suspended"));
3955 // don't sleep but resume immediately the first time
3956 wxThread::Sleep(300);
3958 wxPuts(_T("Going to resume the thread"));
3963 wxPuts(_T("Waiting until it terminates now"));
3965 // wait until the thread terminates
3968 wxPuts(wxEmptyString
);
3971 static void TestThreadDelete()
3973 // As above, using Sleep() is only for testing here - we must use some
3974 // synchronisation object instead to ensure that the thread is still
3975 // running when we delete it - deleting a detached thread which already
3976 // terminated will lead to a crash!
3978 wxPuts(_T("\n*** Testing thread delete function ***"));
3980 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3984 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
3986 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3990 wxThread::Sleep(300);
3994 wxPuts(_T("\nDeleted a running thread."));
3996 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4000 wxThread::Sleep(300);
4006 wxPuts(_T("\nDeleted a sleeping thread."));
4008 MyJoinableThread
thread3(20);
4013 wxPuts(_T("\nDeleted a joinable thread."));
4015 MyJoinableThread
thread4(2);
4018 wxThread::Sleep(300);
4022 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
4024 wxPuts(wxEmptyString
);
4027 class MyWaitingThread
: public wxThread
4030 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
4033 m_condition
= condition
;
4038 virtual ExitCode
Entry()
4040 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
4045 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
4049 m_condition
->Wait();
4052 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
4060 wxCondition
*m_condition
;
4063 static void TestThreadConditions()
4066 wxCondition
condition(mutex
);
4068 // otherwise its difficult to understand which log messages pertain to
4070 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
4071 // condition.GetId(), gs_cond.GetId());
4073 // create and launch threads
4074 MyWaitingThread
*threads
[10];
4077 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4079 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
4082 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4087 // wait until all threads run
4088 wxPuts(_T("Main thread is waiting for the other threads to start"));
4091 size_t nRunning
= 0;
4092 while ( nRunning
< WXSIZEOF(threads
) )
4098 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
4102 wxPuts(_T("Main thread: all threads started up."));
4105 wxThread::Sleep(500);
4108 // now wake one of them up
4109 wxPrintf(_T("Main thread: about to signal the condition.\n"));
4114 wxThread::Sleep(200);
4116 // wake all the (remaining) threads up, so that they can exit
4117 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
4119 condition
.Broadcast();
4121 // give them time to terminate (dirty!)
4122 wxThread::Sleep(500);
4125 #include "wx/utils.h"
4127 class MyExecThread
: public wxThread
4130 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
4136 virtual ExitCode
Entry()
4138 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
4145 static void TestThreadExec()
4147 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4149 MyExecThread
thread(_T("true"));
4152 wxPrintf(_T("Main program exit code: %ld.\n"),
4153 wxExecute(_T("false"), wxEXEC_SYNC
));
4155 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
4159 #include "wx/datetime.h"
4161 class MySemaphoreThread
: public wxThread
4164 MySemaphoreThread(int i
, wxSemaphore
*sem
)
4165 : wxThread(wxTHREAD_JOINABLE
),
4172 virtual ExitCode
Entry()
4174 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4175 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4179 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4180 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4184 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4185 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4197 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
4199 static void TestSemaphore()
4201 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4203 static const int SEM_LIMIT
= 3;
4205 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
4206 ArrayThreads threads
;
4208 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
4210 threads
.Add(new MySemaphoreThread(i
, &sem
));
4211 threads
.Last()->Run();
4214 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
4221 #endif // TEST_THREADS
4223 // ----------------------------------------------------------------------------
4225 // ----------------------------------------------------------------------------
4227 #ifdef TEST_SNGLINST
4228 #include "wx/snglinst.h"
4229 #endif // TEST_SNGLINST
4231 int main(int argc
, char **argv
)
4234 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
4239 for (n
= 0; n
< argc
; n
++ )
4241 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
4242 wxArgv
[n
] = wxStrdup(warg
);
4247 #else // !wxUSE_UNICODE
4249 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
4251 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
4253 wxInitializer initializer
;
4256 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
4261 #ifdef TEST_SNGLINST
4262 wxSingleInstanceChecker checker
;
4263 if ( checker
.Create(_T(".wxconsole.lock")) )
4265 if ( checker
.IsAnotherRunning() )
4267 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4272 // wait some time to give time to launch another instance
4273 wxPrintf(_T("Press \"Enter\" to continue..."));
4276 else // failed to create
4278 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4280 #endif // TEST_SNGLINST
4283 TestCmdLineConvert();
4285 #if wxUSE_CMDLINE_PARSER
4286 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4288 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
4289 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
4290 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
4291 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
4293 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
4294 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
4295 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
4296 wxCMD_LINE_VAL_NUMBER
},
4297 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
4298 wxCMD_LINE_VAL_DATE
},
4299 { wxCMD_LINE_OPTION
, "f", "double", "output double",
4300 wxCMD_LINE_VAL_DOUBLE
},
4302 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
4303 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4308 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
4310 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4311 wxCMD_LINE_VAL_STRING
,
4312 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4314 switch ( parser
.Parse() )
4317 wxLogMessage(_T("Help was given, terminating."));
4321 ShowCmdLine(parser
);
4325 wxLogMessage(_T("Syntax error detected, aborting."));
4328 #endif // wxUSE_CMDLINE_PARSER
4330 #endif // TEST_CMDLINE
4342 TestDllListLoaded();
4343 #endif // TEST_DYNLIB
4347 #endif // TEST_ENVIRON
4351 #endif // TEST_EXECUTE
4353 #ifdef TEST_FILECONF
4355 #endif // TEST_FILECONF
4359 #endif // TEST_LOCALE
4362 wxPuts(_T("*** Testing wxLog ***"));
4365 for ( size_t n
= 0; n
< 8000; n
++ )
4367 s
<< (wxChar
)(_T('A') + (n
% 26));
4370 wxLogWarning(_T("The length of the string is %lu"),
4371 (unsigned long)s
.length());
4374 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
4376 // this one shouldn't be truncated
4379 // but this one will because log functions use fixed size buffer
4380 // (note that it doesn't need '\n' at the end neither - will be added
4382 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
4392 #ifdef TEST_FILENAME
4395 TestFileNameDirManip();
4396 TestFileNameComparison();
4397 TestFileNameOperations();
4398 #endif // TEST_FILENAME
4400 #ifdef TEST_FILETIME
4405 #endif // TEST_FILETIME
4408 wxLog::AddTraceMask(FTP_TRACE_MASK
);
4409 if ( TestFtpConnect() )
4419 #if TEST_INTERACTIVE
4420 TestFtpInteractive();
4423 //else: connecting to the FTP server failed
4431 //wxLog::AddTraceMask(_T("mime"));
4435 TestMimeAssociate();
4440 #ifdef TEST_INFO_FUNCTIONS
4445 #if TEST_INTERACTIVE
4448 #endif // TEST_INFO_FUNCTIONS
4450 #ifdef TEST_PATHLIST
4452 #endif // TEST_PATHLIST
4456 #endif // TEST_PRINTF
4463 #endif // TEST_REGCONF
4465 #if defined TEST_REGEX && TEST_INTERACTIVE
4466 TestRegExInteractive();
4467 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4469 #ifdef TEST_REGISTRY
4471 TestRegistryAssociation();
4472 #endif // TEST_REGISTRY
4477 #endif // TEST_SOCKETS
4484 #endif // TEST_STREAMS
4486 #ifdef TEST_TEXTSTREAM
4487 TestTextInputStream();
4488 #endif // TEST_TEXTSTREAM
4491 int nCPUs
= wxThread::GetCPUCount();
4492 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
4494 wxThread::SetConcurrency(nCPUs
);
4496 TestJoinableThreads();
4499 TestJoinableThreads();
4500 TestDetachedThreads();
4501 TestThreadSuspend();
4503 TestThreadConditions();
4507 #endif // TEST_THREADS
4512 #endif // TEST_TIMER
4514 #ifdef TEST_DATETIME
4521 TestTimeSpanFormat();
4527 #if TEST_INTERACTIVE
4528 TestDateTimeInteractive();
4530 #endif // TEST_DATETIME
4532 #ifdef TEST_SCOPEGUARD
4536 #ifdef TEST_STACKWALKER
4537 #if wxUSE_STACKWALKER
4538 TestStackWalk(argv
[0]);
4540 #endif // TEST_STACKWALKER
4542 #ifdef TEST_STDPATHS
4543 TestStandardPaths();
4547 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4549 #endif // TEST_USLEEP
4554 #endif // TEST_VCARD
4558 #endif // TEST_VOLUME
4562 TestEncodingConverter();
4563 #endif // TEST_WCHAR
4566 TestZipStreamRead();
4567 TestZipFileSystem();
4572 for ( int n
= 0; n
< argc
; n
++ )
4577 #endif // wxUSE_UNICODE