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"
26 #include "wx/filename.h"
29 #include "wx/apptrait.h"
30 #include "wx/platinfo.h"
31 #include "wx/wxchar.h"
33 // without this pragma, the stupid compiler precompiles #defines below so that
34 // changing them doesn't "take place" later!
39 // ----------------------------------------------------------------------------
40 // conditional compilation
41 // ----------------------------------------------------------------------------
44 A note about all these conditional compilation macros: this file is used
45 both as a test suite for various non-GUI wxWidgets classes and as a
46 scratchpad for quick tests. So there are two compilation modes: if you
47 define TEST_ALL all tests are run, otherwise you may enable the individual
48 tests individually in the "#else" branch below.
51 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
52 // test, define it to 1 to do all tests.
67 // #define TEST_FTP --FIXME! (RN)
68 #define TEST_INFO_FUNCTIONS
78 #define TEST_SCOPEGUARD
80 // #define TEST_SOCKETS --FIXME! (RN)
81 #define TEST_STACKWALKER
84 #define TEST_TEXTSTREAM
87 // #define TEST_VCARD -- don't enable this (VZ)
88 // #define TEST_VOLUME --FIXME! (RN)
95 // some tests are interactive, define this to run them
96 #ifdef TEST_INTERACTIVE
97 #undef TEST_INTERACTIVE
99 #define TEST_INTERACTIVE 1
101 #define TEST_INTERACTIVE 0
104 // ============================================================================
106 // ============================================================================
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 #if defined(TEST_SOCKETS)
114 // replace TABs with \t and CRs with \n
115 static wxString
MakePrintable(const wxChar
*s
)
118 (void)str
.Replace(_T("\t"), _T("\\t"));
119 (void)str
.Replace(_T("\n"), _T("\\n"));
120 (void)str
.Replace(_T("\r"), _T("\\r"));
125 #endif // MakePrintable() is used
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
133 #include "wx/cmdline.h"
134 #include "wx/datetime.h"
136 #if wxUSE_CMDLINE_PARSER
138 static void ShowCmdLine(const wxCmdLineParser
& parser
)
140 wxString s
= _T("Command line parsed successfully:\nInput files: ");
142 size_t count
= parser
.GetParamCount();
143 for ( size_t param
= 0; param
< count
; param
++ )
145 s
<< parser
.GetParam(param
) << ' ';
149 << _T("Verbose:\t") << (parser
.Found(_T("v")) ?
_T("yes") : _T("no")) << '\n'
150 << _T("Quiet:\t") << (parser
.Found(_T("q")) ?
_T("yes") : _T("no")) << '\n';
156 if ( parser
.Found(_T("o"), &strVal
) )
157 s
<< _T("Output file:\t") << strVal
<< '\n';
158 if ( parser
.Found(_T("i"), &strVal
) )
159 s
<< _T("Input dir:\t") << strVal
<< '\n';
160 if ( parser
.Found(_T("s"), &lVal
) )
161 s
<< _T("Size:\t") << lVal
<< '\n';
162 if ( parser
.Found(_T("f"), &dVal
) )
163 s
<< _T("Double:\t") << dVal
<< '\n';
164 if ( parser
.Found(_T("d"), &dt
) )
165 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
166 if ( parser
.Found(_T("project_name"), &strVal
) )
167 s
<< _T("Project:\t") << strVal
<< '\n';
172 #endif // wxUSE_CMDLINE_PARSER
174 static void TestCmdLineConvert()
176 static const wxChar
*cmdlines
[] =
179 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
180 _T("literal \\\" and \"\""),
183 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
185 const wxChar
*cmdline
= cmdlines
[n
];
186 wxPrintf(_T("Parsing: %s\n"), cmdline
);
187 wxArrayString args
= wxCmdLineParser
::ConvertStringToArgs(cmdline
);
189 size_t count
= args
.GetCount();
190 wxPrintf(_T("\targc = %u\n"), count
);
191 for ( size_t arg
= 0; arg
< count
; arg
++ )
193 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
198 #endif // TEST_CMDLINE
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
209 static const wxChar
*ROOTDIR
= _T("/");
210 static const wxChar
*TESTDIR
= _T("/usr/local/share");
211 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
212 static const wxChar
*ROOTDIR
= _T("c:\\");
213 static const wxChar
*TESTDIR
= _T("d:\\");
215 #error "don't know where the root directory is"
218 static void TestDirEnumHelper(wxDir
& dir
,
219 int flags
= wxDIR_DEFAULT
,
220 const wxString
& filespec
= wxEmptyString
)
224 if ( !dir
.IsOpened() )
227 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
230 wxPrintf(_T("\t%s\n"), filename
.c_str());
232 cont
= dir
.GetNext(&filename
);
235 wxPuts(wxEmptyString
);
240 static void TestDirEnum()
242 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
244 wxString cwd
= wxGetCwd();
245 if ( !wxDir
::Exists(cwd
) )
247 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
252 if ( !dir
.IsOpened() )
254 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
258 wxPuts(_T("Enumerating everything in current directory:"));
259 TestDirEnumHelper(dir
);
261 wxPuts(_T("Enumerating really everything in current directory:"));
262 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
264 wxPuts(_T("Enumerating object files in current directory:"));
265 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
267 wxPuts(_T("Enumerating directories in current directory:"));
268 TestDirEnumHelper(dir
, wxDIR_DIRS
);
270 wxPuts(_T("Enumerating files in current directory:"));
271 TestDirEnumHelper(dir
, wxDIR_FILES
);
273 wxPuts(_T("Enumerating files including hidden in current directory:"));
274 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
278 wxPuts(_T("Enumerating everything in root directory:"));
279 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
281 wxPuts(_T("Enumerating directories in root directory:"));
282 TestDirEnumHelper(dir
, wxDIR_DIRS
);
284 wxPuts(_T("Enumerating files in root directory:"));
285 TestDirEnumHelper(dir
, wxDIR_FILES
);
287 wxPuts(_T("Enumerating files including hidden in root directory:"));
288 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
290 wxPuts(_T("Enumerating files in non existing directory:"));
291 wxDir
dirNo(_T("nosuchdir"));
292 TestDirEnumHelper(dirNo
);
297 class DirPrintTraverser
: public wxDirTraverser
300 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
302 return wxDIR_CONTINUE
;
305 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
307 wxString path
, name
, ext
;
308 wxFileName
::SplitPath(dirname
, &path
, &name
, &ext
);
311 name
<< _T('.') << ext
;
314 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
316 if ( wxIsPathSeparator(*p
) )
320 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
322 return wxDIR_CONTINUE
;
326 static void TestDirTraverse()
328 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
332 size_t n
= wxDir
::GetAllFiles(TESTDIR
, &files
);
333 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
336 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
337 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
340 // enum again with custom traverser
341 wxPuts(_T("Now enumerating directories:"));
343 DirPrintTraverser traverser
;
344 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
349 static void TestDirExists()
351 wxPuts(_T("*** Testing wxDir::Exists() ***"));
353 static const wxChar
*dirnames
[] =
356 #if defined(__WXMSW__)
359 _T("\\\\share\\file"),
363 _T("c:\\autoexec.bat"),
364 #elif defined(__UNIX__)
373 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
375 wxPrintf(_T("%-40s: %s\n"),
377 wxDir
::Exists(dirnames
[n
]) ?
_T("exists")
378 : _T("doesn't exist"));
386 // ----------------------------------------------------------------------------
388 // ----------------------------------------------------------------------------
392 #include "wx/dynlib.h"
394 static void TestDllLoad()
396 #if defined(__WXMSW__)
397 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
398 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
399 #elif defined(__UNIX__)
400 // weird: using just libc.so does *not* work!
401 static const wxChar
*LIB_NAME
= _T("/lib/libc.so.6");
402 static const wxChar
*FUNC_NAME
= _T("strlen");
404 #error "don't know how to test wxDllLoader on this platform"
407 wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
409 wxDynamicLibrary
lib(LIB_NAME
);
410 if ( !lib
.IsLoaded() )
412 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
416 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
417 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
420 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
421 FUNC_NAME
, LIB_NAME
);
425 wxPrintf(_T("Calling %s dynamically loaded from %s "),
426 FUNC_NAME
, LIB_NAME
);
428 if ( pfnStrlen("foo") != 3 )
430 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
434 wxPuts(_T("... ok"));
439 static const wxChar
*FUNC_NAME_AW
= _T("lstrlen");
441 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
443 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
444 if ( !pfnStrlenAorW
)
446 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
447 FUNC_NAME_AW
, LIB_NAME
);
451 if ( pfnStrlenAorW(_T("foobar")) != 6 )
453 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
460 #if defined(__WXMSW__) || defined(__UNIX__)
462 static void TestDllListLoaded()
464 wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
466 puts("\nLoaded modules:");
467 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary
::ListLoaded();
468 const size_t count
= dlls
.GetCount();
469 for ( size_t n
= 0; n
< count
; ++n
)
471 const wxDynamicLibraryDetails
& details
= dlls
[n
];
472 printf("%-45s", (const char *)details
.GetPath().mb_str());
476 if ( details
.GetAddress(&addr
, &len
) )
478 printf(" %08lx:%08lx",
479 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
482 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
488 #endif // TEST_DYNLIB
490 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
496 #include "wx/utils.h"
498 static wxString
MyGetEnv(const wxString
& var
)
501 if ( !wxGetEnv(var
, &val
) )
504 val
= wxString(_T('\'')) + val
+ _T('\'');
509 static void TestEnvironment()
511 const wxChar
*var
= _T("wxTestVar");
513 wxPuts(_T("*** testing environment access functions ***"));
515 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
516 wxSetEnv(var
, _T("value for wxTestVar"));
517 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
518 wxSetEnv(var
, _T("another value"));
519 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
521 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
522 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
525 #endif // TEST_ENVIRON
527 // ----------------------------------------------------------------------------
529 // ----------------------------------------------------------------------------
533 #include "wx/utils.h"
535 static void TestExecute()
537 wxPuts(_T("*** testing wxExecute ***"));
540 #define COMMAND "echo hi"
541 #define ASYNC_COMMAND "xclock"
542 #define SHELL_COMMAND "echo hi from shell"
543 #define REDIRECT_COMMAND "cat -n Makefile"
544 #elif defined(__WXMSW__)
545 #define COMMAND "command.com /c echo hi"
546 #define ASYNC_COMMAND "notepad"
547 #define SHELL_COMMAND "echo hi"
548 #define REDIRECT_COMMAND COMMAND
550 #error "no command to exec"
553 wxPrintf(_T("Testing wxShell: "));
555 if ( wxShell(_T(SHELL_COMMAND
)) )
558 wxPuts(_T("ERROR."));
560 wxPrintf(_T("Testing wxExecute: "));
562 if ( wxExecute(_T(COMMAND
), wxEXEC_SYNC
) == 0 )
565 wxPuts(_T("ERROR."));
567 wxPrintf(_T("Testing async wxExecute: "));
569 int pid
= wxExecute(ASYNC_COMMAND
);
572 wxPuts(_T("Ok (command launched)."));
573 if ( wxKill(pid
) == -1 )
574 wxPuts("ERROR: failed to kill child process.");
577 wxPuts(_T("ERROR."));
579 wxPrintf(_T("Testing wxExecute with redirection:\n"));
580 wxArrayString output
;
581 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
583 wxPuts(_T("ERROR."));
587 // don't show too much output, MAX_LINES is enough
588 static const unsigned MAX_LINES
= 20;
590 const unsigned count
= output
.size();
591 for ( unsigned n
= 0;
592 n
< (count
> MAX_LINES ? MAX_LINES
/2 : count
);
595 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
598 if ( count
> MAX_LINES
)
600 wxPrintf("... skipping %u lines...\n", count
- MAX_LINES
);
602 for ( unsigned n
= count
- MAX_LINES
/2; n
< count
; n
++ )
604 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
612 #endif // TEST_EXECUTE
614 // ----------------------------------------------------------------------------
616 // ----------------------------------------------------------------------------
621 #include "wx/ffile.h"
622 #include "wx/textfile.h"
624 static void TestFileRead()
626 wxPuts(_T("*** wxFile read test ***"));
628 wxFile
file(_T("testdata.fc"));
629 if ( file
.IsOpened() )
631 wxPrintf(_T("File length: %lu\n"), file
.Length());
633 wxPuts(_T("File dump:\n----------"));
635 static const size_t len
= 1024;
639 size_t nRead
= file
.Read(buf
, len
);
640 if ( nRead
== (size_t)wxInvalidOffset
)
642 wxPrintf(_T("Failed to read the file."));
646 fwrite(buf
, nRead
, 1, stdout
);
652 wxPuts(_T("----------"));
656 wxPrintf(_T("ERROR: can't open test file.\n"));
659 wxPuts(wxEmptyString
);
662 static void TestTextFileRead()
664 wxPuts(_T("*** wxTextFile read test ***"));
666 wxTextFile
file(_T("testdata.fc"));
669 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
670 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
674 wxPuts(_T("\nDumping the entire file:"));
675 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
677 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
679 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
681 wxPuts(_T("\nAnd now backwards:"));
682 for ( s
= file
.GetLastLine();
683 file
.GetCurrentLine() != 0;
684 s
= file
.GetPrevLine() )
686 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
688 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
692 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
695 wxPuts(wxEmptyString
);
698 static void TestFileCopy()
700 wxPuts(_T("*** Testing wxCopyFile ***"));
702 static const wxChar
*filename1
= _T("testdata.fc");
703 static const wxChar
*filename2
= _T("test2");
704 if ( !wxCopyFile(filename1
, filename2
) )
706 wxPuts(_T("ERROR: failed to copy file"));
710 wxFFile
f1(filename1
, _T("rb")),
711 f2(filename2
, _T("rb"));
713 if ( !f1
.IsOpened() || !f2
.IsOpened() )
715 wxPuts(_T("ERROR: failed to open file(s)"));
720 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
722 wxPuts(_T("ERROR: failed to read file(s)"));
726 if ( (s1
.length() != s2
.length()) ||
727 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
729 wxPuts(_T("ERROR: copy error!"));
733 wxPuts(_T("File was copied ok."));
739 if ( !wxRemoveFile(filename2
) )
741 wxPuts(_T("ERROR: failed to remove the file"));
744 wxPuts(wxEmptyString
);
747 static void TestTempFile()
749 wxPuts(_T("*** wxTempFile test ***"));
752 if ( tmpFile
.Open(_T("test2")) && tmpFile
.Write(_T("the answer is 42")) )
754 if ( tmpFile
.Commit() )
755 wxPuts(_T("File committed."));
757 wxPuts(_T("ERROR: could't commit temp file."));
759 wxRemoveFile(_T("test2"));
762 wxPuts(wxEmptyString
);
767 // ----------------------------------------------------------------------------
769 // ----------------------------------------------------------------------------
773 #include "wx/confbase.h"
774 #include "wx/fileconf.h"
776 static const struct FileConfTestData
778 const wxChar
*name
; // value name
779 const wxChar
*value
; // the value from the file
782 { _T("value1"), _T("one") },
783 { _T("value2"), _T("two") },
784 { _T("novalue"), _T("default") },
787 static void TestFileConfRead()
789 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
791 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
792 _T("testdata.fc"), wxEmptyString
,
793 wxCONFIG_USE_RELATIVE_PATH
);
795 // test simple reading
796 wxPuts(_T("\nReading config file:"));
797 wxString
defValue(_T("default")), value
;
798 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
800 const FileConfTestData
& data
= fcTestData
[n
];
801 value
= fileconf
.Read(data
.name
, defValue
);
802 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
803 if ( value
== data
.value
)
809 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
813 // test enumerating the entries
814 wxPuts(_T("\nEnumerating all root entries:"));
817 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
820 wxPrintf(_T("\t%s = %s\n"),
822 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
824 cont
= fileconf
.GetNextEntry(name
, dummy
);
827 static const wxChar
*testEntry
= _T("TestEntry");
828 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
829 fileconf
.Write(testEntry
, _T("A value"));
830 fileconf
.DeleteEntry(testEntry
);
831 wxPrintf(fileconf
.HasEntry(testEntry
) ?
_T("ERROR\n") : _T("ok\n"));
834 #endif // TEST_FILECONF
836 // ----------------------------------------------------------------------------
838 // ----------------------------------------------------------------------------
842 #include "wx/filename.h"
845 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
849 wxString full
= fn
.GetFullPath();
851 wxString vol
, path
, name
, ext
;
852 wxFileName
::SplitPath(full
, &vol
, &path
, &name
, &ext
);
854 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
855 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
857 wxFileName
::SplitPath(full
, &path
, &name
, &ext
);
858 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
859 path
.c_str(), name
.c_str(), ext
.c_str());
861 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
862 wxPrintf(_T("with volume: \t'%s'\n"),
863 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
864 wxPrintf(_T("with separator:\t'%s'\n"),
865 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
866 wxPrintf(_T("with both: \t'%s'\n"),
867 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
869 wxPuts(_T("The directories in the path are:"));
870 wxArrayString dirs
= fn
.GetDirs();
871 size_t count
= dirs
.GetCount();
872 for ( size_t n
= 0; n
< count
; n
++ )
874 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
879 static void TestFileNameTemp()
881 wxPuts(_T("*** testing wxFileName temp file creation ***"));
883 static const wxChar
*tmpprefixes
[] =
891 _T("/tmp/foo/bar"), // this one must be an error
895 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
897 wxString path
= wxFileName
::CreateTempFileName(tmpprefixes
[n
]);
900 // "error" is not in upper case because it may be ok
901 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
905 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
906 tmpprefixes
[n
], path
.c_str());
908 if ( !wxRemoveFile(path
) )
910 wxLogWarning(_T("Failed to remove temp file '%s'"),
917 static void TestFileNameDirManip()
919 // TODO: test AppendDir(), RemoveDir(), ...
922 static void TestFileNameComparison()
927 static void TestFileNameOperations()
932 static void TestFileNameCwd()
937 #endif // TEST_FILENAME
939 // ----------------------------------------------------------------------------
940 // wxFileName time functions
941 // ----------------------------------------------------------------------------
945 #include "wx/filename.h"
946 #include "wx/datetime.h"
948 static void TestFileGetTimes()
950 wxFileName
fn(_T("testdata.fc"));
952 wxDateTime dtAccess
, dtMod
, dtCreate
;
953 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
955 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
959 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
961 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
962 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
963 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
964 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
969 static void TestFileSetTimes()
971 wxFileName
fn(_T("testdata.fc"));
975 wxPrintf(_T("ERROR: Touch() failed.\n"));
980 #endif // TEST_FILETIME
982 // ----------------------------------------------------------------------------
984 // ----------------------------------------------------------------------------
989 #include "wx/utils.h" // for wxSetEnv
991 static wxLocale gs_localeDefault
;
992 // NOTE: don't init it here as it needs a wxAppTraits object
993 // and thus must be init-ed after creation of the wxInitializer
994 // class in the main()
996 // find the name of the language from its value
997 static const wxChar
*GetLangName(int lang
)
999 static const wxChar
*languageNames
[] =
1009 _T("ARABIC_ALGERIA"),
1010 _T("ARABIC_BAHRAIN"),
1013 _T("ARABIC_JORDAN"),
1014 _T("ARABIC_KUWAIT"),
1015 _T("ARABIC_LEBANON"),
1017 _T("ARABIC_MOROCCO"),
1020 _T("ARABIC_SAUDI_ARABIA"),
1023 _T("ARABIC_TUNISIA"),
1030 _T("AZERI_CYRILLIC"),
1045 _T("CHINESE_SIMPLIFIED"),
1046 _T("CHINESE_TRADITIONAL"),
1047 _T("CHINESE_HONGKONG"),
1048 _T("CHINESE_MACAU"),
1049 _T("CHINESE_SINGAPORE"),
1050 _T("CHINESE_TAIWAN"),
1056 _T("DUTCH_BELGIAN"),
1060 _T("ENGLISH_AUSTRALIA"),
1061 _T("ENGLISH_BELIZE"),
1062 _T("ENGLISH_BOTSWANA"),
1063 _T("ENGLISH_CANADA"),
1064 _T("ENGLISH_CARIBBEAN"),
1065 _T("ENGLISH_DENMARK"),
1067 _T("ENGLISH_JAMAICA"),
1068 _T("ENGLISH_NEW_ZEALAND"),
1069 _T("ENGLISH_PHILIPPINES"),
1070 _T("ENGLISH_SOUTH_AFRICA"),
1071 _T("ENGLISH_TRINIDAD"),
1072 _T("ENGLISH_ZIMBABWE"),
1080 _T("FRENCH_BELGIAN"),
1081 _T("FRENCH_CANADIAN"),
1082 _T("FRENCH_LUXEMBOURG"),
1083 _T("FRENCH_MONACO"),
1089 _T("GERMAN_AUSTRIAN"),
1090 _T("GERMAN_BELGIUM"),
1091 _T("GERMAN_LIECHTENSTEIN"),
1092 _T("GERMAN_LUXEMBOURG"),
1110 _T("ITALIAN_SWISS"),
1115 _T("KASHMIRI_INDIA"),
1133 _T("MALAY_BRUNEI_DARUSSALAM"),
1134 _T("MALAY_MALAYSIA"),
1144 _T("NORWEGIAN_BOKMAL"),
1145 _T("NORWEGIAN_NYNORSK"),
1152 _T("PORTUGUESE_BRAZILIAN"),
1155 _T("RHAETO_ROMANCE"),
1158 _T("RUSSIAN_UKRAINE"),
1164 _T("SERBIAN_CYRILLIC"),
1165 _T("SERBIAN_LATIN"),
1166 _T("SERBO_CROATIAN"),
1177 _T("SPANISH_ARGENTINA"),
1178 _T("SPANISH_BOLIVIA"),
1179 _T("SPANISH_CHILE"),
1180 _T("SPANISH_COLOMBIA"),
1181 _T("SPANISH_COSTA_RICA"),
1182 _T("SPANISH_DOMINICAN_REPUBLIC"),
1183 _T("SPANISH_ECUADOR"),
1184 _T("SPANISH_EL_SALVADOR"),
1185 _T("SPANISH_GUATEMALA"),
1186 _T("SPANISH_HONDURAS"),
1187 _T("SPANISH_MEXICAN"),
1188 _T("SPANISH_MODERN"),
1189 _T("SPANISH_NICARAGUA"),
1190 _T("SPANISH_PANAMA"),
1191 _T("SPANISH_PARAGUAY"),
1193 _T("SPANISH_PUERTO_RICO"),
1194 _T("SPANISH_URUGUAY"),
1196 _T("SPANISH_VENEZUELA"),
1200 _T("SWEDISH_FINLAND"),
1218 _T("URDU_PAKISTAN"),
1220 _T("UZBEK_CYRILLIC"),
1233 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1234 return languageNames
[lang
];
1236 return _T("INVALID");
1239 static void TestDefaultLang()
1241 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1243 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1245 static const wxChar
*langStrings
[] =
1247 NULL
, // system default
1254 _T("de_DE.iso88591"),
1256 _T("?"), // invalid lang spec
1257 _T("klingonese"), // I bet on some systems it does exist...
1260 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1261 wxLocale
::GetSystemEncodingName().c_str(),
1262 wxLocale
::GetSystemEncoding());
1264 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1266 const wxChar
*langStr
= langStrings
[n
];
1269 // FIXME: this doesn't do anything at all under Windows, we need
1270 // to create a new wxLocale!
1271 wxSetEnv(_T("LC_ALL"), langStr
);
1274 int lang
= gs_localeDefault
.GetSystemLanguage();
1275 wxPrintf(_T("Locale for '%s' is %s.\n"),
1276 langStr ? langStr
: _T("system default"), GetLangName(lang
));
1280 #endif // TEST_LOCALE
1282 // ----------------------------------------------------------------------------
1284 // ----------------------------------------------------------------------------
1288 #include "wx/mimetype.h"
1290 static void TestMimeEnum()
1292 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1294 wxArrayString mimetypes
;
1296 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1298 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1303 for ( size_t n
= 0; n
< count
; n
++ )
1305 wxFileType
*filetype
=
1306 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1309 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1310 mimetypes
[n
].c_str());
1314 filetype
->GetDescription(&desc
);
1315 filetype
->GetExtensions(exts
);
1317 filetype
->GetIcon(NULL
);
1320 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1323 extsAll
<< _T(", ");
1327 wxPrintf(_T("\t%s: %s (%s)\n"),
1328 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1331 wxPuts(wxEmptyString
);
1334 static void TestMimeFilename()
1336 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1338 static const wxChar
*filenames
[] =
1346 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1348 const wxString fname
= filenames
[n
];
1349 wxString ext
= fname
.AfterLast(_T('.'));
1350 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1353 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1358 if ( !ft
->GetDescription(&desc
) )
1359 desc
= _T("<no description>");
1362 if ( !ft
->GetOpenCommand(&cmd
,
1363 wxFileType
::MessageParameters(fname
, wxEmptyString
)) )
1364 cmd
= _T("<no command available>");
1366 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1368 wxPrintf(_T("To open %s (%s) do %s.\n"),
1369 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1375 wxPuts(wxEmptyString
);
1378 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1381 static void TestMimeOverride()
1383 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1385 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1386 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1388 if ( wxFile
::Exists(mailcap
) )
1389 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1391 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ?
_T("ok") : _T("ERROR"));
1393 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1396 if ( wxFile
::Exists(mimetypes
) )
1397 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1399 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ?
_T("ok") : _T("ERROR"));
1401 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1404 wxPuts(wxEmptyString
);
1407 static void TestMimeAssociate()
1409 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1411 wxFileTypeInfo
ftInfo(
1412 _T("application/x-xyz"),
1413 _T("xyzview '%s'"), // open cmd
1414 _T(""), // print cmd
1415 _T("XYZ File"), // description
1416 _T(".xyz"), // extensions
1417 wxNullPtr
// end of extensions
1419 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1421 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1424 wxPuts(_T("ERROR: failed to create association!"));
1428 // TODO: read it back
1432 wxPuts(wxEmptyString
);
1439 // ----------------------------------------------------------------------------
1440 // module dependencies feature
1441 // ----------------------------------------------------------------------------
1445 #include "wx/module.h"
1447 class wxTestModule
: public wxModule
1450 virtual bool OnInit() { wxPrintf(_T("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1451 virtual void OnExit() { wxPrintf(_T("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1454 class wxTestModuleA
: public wxTestModule
1459 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1462 class wxTestModuleB
: public wxTestModule
1467 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1470 class wxTestModuleC
: public wxTestModule
1475 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1478 class wxTestModuleD
: public wxTestModule
1483 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1486 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1487 wxTestModuleC
::wxTestModuleC()
1489 AddDependency(CLASSINFO(wxTestModuleD
));
1492 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1493 wxTestModuleA
::wxTestModuleA()
1495 AddDependency(CLASSINFO(wxTestModuleB
));
1496 AddDependency(CLASSINFO(wxTestModuleD
));
1499 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1500 wxTestModuleD
::wxTestModuleD()
1504 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1505 wxTestModuleB
::wxTestModuleB()
1507 AddDependency(CLASSINFO(wxTestModuleD
));
1508 AddDependency(CLASSINFO(wxTestModuleC
));
1511 #endif // TEST_MODULE
1513 // ----------------------------------------------------------------------------
1514 // misc information functions
1515 // ----------------------------------------------------------------------------
1517 #ifdef TEST_INFO_FUNCTIONS
1519 #include "wx/utils.h"
1521 #if TEST_INTERACTIVE
1522 static void TestDiskInfo()
1524 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1528 wxChar pathname
[128];
1529 wxPrintf(_T("\nEnter a directory name: "));
1530 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1533 // kill the last '\n'
1534 pathname
[wxStrlen(pathname
) - 1] = 0;
1536 wxLongLong total
, free
;
1537 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1539 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1543 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1544 (total
/ 1024).ToString().c_str(),
1545 (free
/ 1024).ToString().c_str(),
1550 #endif // TEST_INTERACTIVE
1552 static void TestOsInfo()
1554 wxPuts(_T("*** Testing OS info functions ***\n"));
1557 wxGetOsVersion(&major
, &minor
);
1558 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1559 wxGetOsDescription().c_str(), major
, minor
);
1561 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1563 wxPrintf(_T("Host name is %s (%s).\n"),
1564 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1566 wxPuts(wxEmptyString
);
1569 static void TestPlatformInfo()
1571 wxPuts(_T("*** Testing wxPlatformInfo functions ***\n"));
1573 // get this platform
1574 wxPlatformInfo plat
;
1576 wxPrintf(_T("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1577 wxPrintf(_T("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1578 wxPrintf(_T("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1579 wxPrintf(_T("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1580 wxPrintf(_T("Architecture is: %s\n"), plat
.GetArchName().c_str());
1581 wxPrintf(_T("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1583 wxPuts(wxEmptyString
);
1586 static void TestUserInfo()
1588 wxPuts(_T("*** Testing user info functions ***\n"));
1590 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1591 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1592 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1593 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1595 wxPuts(wxEmptyString
);
1598 #endif // TEST_INFO_FUNCTIONS
1600 // ----------------------------------------------------------------------------
1602 // ----------------------------------------------------------------------------
1604 #ifdef TEST_PATHLIST
1607 #define CMD_IN_PATH _T("ls")
1609 #define CMD_IN_PATH _T("command.com")
1612 static void TestPathList()
1614 wxPuts(_T("*** Testing wxPathList ***\n"));
1616 wxPathList pathlist
;
1617 pathlist
.AddEnvList(_T("PATH"));
1618 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1621 wxPrintf(_T("ERROR: command not found in the path.\n"));
1625 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
1629 #endif // TEST_PATHLIST
1631 // ----------------------------------------------------------------------------
1632 // regular expressions
1633 // ----------------------------------------------------------------------------
1637 #include "wx/regex.h"
1639 static void TestRegExInteractive()
1641 wxPuts(_T("*** Testing RE interactively ***"));
1645 wxChar pattern
[128];
1646 wxPrintf(_T("\nEnter a pattern: "));
1647 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1650 // kill the last '\n'
1651 pattern
[wxStrlen(pattern
) - 1] = 0;
1654 if ( !re
.Compile(pattern
) )
1662 wxPrintf(_T("Enter text to match: "));
1663 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1666 // kill the last '\n'
1667 text
[wxStrlen(text
) - 1] = 0;
1669 if ( !re
.Matches(text
) )
1671 wxPrintf(_T("No match.\n"));
1675 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1678 for ( size_t n
= 1; ; n
++ )
1680 if ( !re
.GetMatch(&start
, &len
, n
) )
1685 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1686 n
, wxString(text
+ start
, len
).c_str());
1693 #endif // TEST_REGEX
1695 // ----------------------------------------------------------------------------
1697 // ----------------------------------------------------------------------------
1700 NB: this stuff was taken from the glibc test suite and modified to build
1701 in wxWidgets: if I read the copyright below properly, this shouldn't
1707 #ifdef wxTEST_PRINTF
1708 // use our functions from wxchar.cpp
1712 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1713 // in the tests below
1714 int wxPrintf( const wxChar
*format
, ... );
1715 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1718 #include "wx/longlong.h"
1722 static void rfg1 (void);
1723 static void rfg2 (void);
1727 fmtchk (const wxChar
*fmt
)
1729 (void) wxPrintf(_T("%s:\t`"), fmt
);
1730 (void) wxPrintf(fmt
, 0x12);
1731 (void) wxPrintf(_T("'\n"));
1735 fmtst1chk (const wxChar
*fmt
)
1737 (void) wxPrintf(_T("%s:\t`"), fmt
);
1738 (void) wxPrintf(fmt
, 4, 0x12);
1739 (void) wxPrintf(_T("'\n"));
1743 fmtst2chk (const wxChar
*fmt
)
1745 (void) wxPrintf(_T("%s:\t`"), fmt
);
1746 (void) wxPrintf(fmt
, 4, 4, 0x12);
1747 (void) wxPrintf(_T("'\n"));
1750 /* This page is covered by the following copyright: */
1752 /* (C) Copyright C E Chew
1754 * Feel free to copy, use and distribute this software provided:
1756 * 1. you do not pretend that you wrote it
1757 * 2. you leave this copyright notice intact.
1761 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1768 /* Formatted Output Test
1770 * This exercises the output formatting code.
1773 wxChar
*PointerNull
= NULL
;
1780 wxChar
*prefix
= buf
;
1783 wxPuts(_T("\nFormatted output test"));
1784 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
1785 wxStrcpy(prefix
, _T("%"));
1786 for (i
= 0; i
< 2; i
++) {
1787 for (j
= 0; j
< 2; j
++) {
1788 for (k
= 0; k
< 2; k
++) {
1789 for (l
= 0; l
< 2; l
++) {
1790 wxStrcpy(prefix
, _T("%"));
1791 if (i
== 0) wxStrcat(prefix
, _T("-"));
1792 if (j
== 0) wxStrcat(prefix
, _T("+"));
1793 if (k
== 0) wxStrcat(prefix
, _T("#"));
1794 if (l
== 0) wxStrcat(prefix
, _T("0"));
1795 wxPrintf(_T("%5s |"), prefix
);
1796 wxStrcpy(tp
, prefix
);
1797 wxStrcat(tp
, _T("6d |"));
1799 wxStrcpy(tp
, prefix
);
1800 wxStrcat(tp
, _T("6o |"));
1802 wxStrcpy(tp
, prefix
);
1803 wxStrcat(tp
, _T("6x |"));
1805 wxStrcpy(tp
, prefix
);
1806 wxStrcat(tp
, _T("6X |"));
1808 wxStrcpy(tp
, prefix
);
1809 wxStrcat(tp
, _T("6u |"));
1816 wxPrintf(_T("%10s\n"), PointerNull
);
1817 wxPrintf(_T("%-10s\n"), PointerNull
);
1820 static void TestPrintf()
1822 static wxChar shortstr
[] = _T("Hi, Z.");
1823 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
1824 I am ready for my first lesson today.");
1826 wxString test_format
;
1830 fmtchk(_T("%4.4x"));
1831 fmtchk(_T("%04.4x"));
1832 fmtchk(_T("%4.3x"));
1833 fmtchk(_T("%04.3x"));
1835 fmtst1chk(_T("%.*x"));
1836 fmtst1chk(_T("%0*x"));
1837 fmtst2chk(_T("%*.*x"));
1838 fmtst2chk(_T("%0*.*x"));
1840 wxString bad_format
= _T("bad format:\t\"%b\"\n");
1841 wxPrintf(bad_format
.c_str());
1842 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1844 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
1845 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
1846 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
1847 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
1848 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
1849 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1850 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1851 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
1852 wxPrintf(test_format
.c_str(), -123456);
1853 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1854 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1856 test_format
= _T("zero-padded string:\t\"%010s\"\n");
1857 wxPrintf(test_format
.c_str(), shortstr
);
1858 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
1859 wxPrintf(test_format
.c_str(), shortstr
);
1860 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
1861 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1862 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
1863 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
1865 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
1866 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
1867 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
1868 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
1869 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
1870 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
1871 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
1872 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
1873 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
1874 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
1875 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
1876 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
1878 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
1879 wxPrintf (_T(" %6.5f\n"), .1);
1880 wxPrintf (_T("x%5.4fx\n"), .5);
1882 wxPrintf (_T("%#03x\n"), 1);
1884 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
1890 while (niter
-- != 0)
1891 wxPrintf (_T("%.17e\n"), d
/ 2);
1896 // Open Watcom cause compiler error here
1897 // Error! E173: col(24) floating-point constant too small to represent
1898 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
1901 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
1902 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1903 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1904 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1905 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1906 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1907 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1908 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1909 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1910 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1915 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
1917 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1918 rc
, WXSIZEOF(buf
), buf
);
1921 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1922 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1928 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
1929 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
1930 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
1931 wxPrintf (_T("%g should be 123.456\n"), 123.456);
1932 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
1933 wxPrintf (_T("%g should be 10\n"), 10.0);
1934 wxPrintf (_T("%g should be 0.02\n"), 0.02);
1938 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1944 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
1946 result
|= wxStrcmp (buf
,
1947 _T("onetwo three "));
1949 wxPuts (result
!= 0 ?
_T("Test failed!") : _T("Test ok."));
1956 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
1958 // for some reason below line fails under Borland
1959 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1962 if (wxStrcmp (buf
, _T("40000000000")) != 0)
1965 wxPuts (_T("\tFAILED"));
1967 wxUnusedVar(result
);
1968 wxPuts (wxEmptyString
);
1970 #endif // wxLongLong_t
1972 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1973 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1975 wxPuts (_T("--- Should be no further output. ---"));
1984 memset (bytes
, '\xff', sizeof bytes
);
1985 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
1986 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1987 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1989 wxPuts (_T("%hhn overwrite more bytes"));
1994 wxPuts (_T("%hhn wrote incorrect value"));
2006 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2007 if (wxStrcmp (buf
, _T(" ")) != 0)
2008 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2009 wxSprintf (buf
, _T("%5.f"), 33.3);
2010 if (wxStrcmp (buf
, _T(" 33")) != 0)
2011 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2012 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2013 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2014 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2015 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2016 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2017 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2018 wxSprintf (buf
, _T("%.g"), 33.3);
2019 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2020 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2021 wxSprintf (buf
, _T("%.G"), 33.3);
2022 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2023 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2031 wxString test_format
;
2034 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2035 if (wxStrcmp (buf
, _T("3")) != 0)
2036 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2038 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2039 if (wxStrcmp (buf
, _T("3")) != 0)
2040 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2042 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2043 if (wxStrcmp (buf
, _T(" 3")) != 0)
2044 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2046 test_format
= _T("%04.*o");
2047 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2048 if (wxStrcmp (buf
, _T(" 041")) != 0)
2049 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2051 test_format
= _T("%09.*u");
2052 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2053 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2054 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2056 test_format
= _T("%04.*x");
2057 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2058 if (wxStrcmp (buf
, _T(" 021")) != 0)
2059 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2061 test_format
= _T("%04.*X");
2062 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2063 if (wxStrcmp (buf
, _T(" 021")) != 0)
2064 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2067 #endif // TEST_PRINTF
2069 // ----------------------------------------------------------------------------
2070 // registry and related stuff
2071 // ----------------------------------------------------------------------------
2073 // this is for MSW only
2076 #undef TEST_REGISTRY
2081 #include "wx/confbase.h"
2082 #include "wx/msw/regconf.h"
2085 static void TestRegConfWrite()
2087 wxConfig
*config
= new wxConfig(_T("myapp"));
2088 config
->SetPath(_T("/group1"));
2089 config
->Write(_T("entry1"), _T("foo"));
2090 config
->SetPath(_T("/group2"));
2091 config
->Write(_T("entry1"), _T("bar"));
2095 static void TestRegConfRead()
2097 wxRegConfig
*config
= new wxRegConfig(_T("myapp"));
2101 config
->SetPath(_T("/"));
2102 wxPuts(_T("Enumerating / subgroups:"));
2103 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2107 bCont
= config
->GetNextGroup(str
, dummy
);
2111 #endif // TEST_REGCONF
2113 #ifdef TEST_REGISTRY
2115 #include "wx/msw/registry.h"
2117 // I chose this one because I liked its name, but it probably only exists under
2119 static const wxChar
*TESTKEY
=
2120 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2122 static void TestRegistryRead()
2124 wxPuts(_T("*** testing registry reading ***"));
2126 wxRegKey
key(TESTKEY
);
2127 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2130 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2135 size_t nSubKeys
, nValues
;
2136 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2138 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2141 wxPrintf(_T("Enumerating values:\n"));
2145 bool cont
= key
.GetFirstValue(value
, dummy
);
2148 wxPrintf(_T("Value '%s': type "), value
.c_str());
2149 switch ( key
.GetValueType(value
) )
2151 case wxRegKey
::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2152 case wxRegKey
::Type_String
: wxPrintf(_T("SZ")); break;
2153 case wxRegKey
::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2154 case wxRegKey
::Type_Binary
: wxPrintf(_T("BINARY")); break;
2155 case wxRegKey
::Type_Dword
: wxPrintf(_T("DWORD")); break;
2156 case wxRegKey
::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2157 default: wxPrintf(_T("other (unknown)")); break;
2160 wxPrintf(_T(", value = "));
2161 if ( key
.IsNumericValue(value
) )
2164 key
.QueryValue(value
, &val
);
2165 wxPrintf(_T("%ld"), val
);
2170 key
.QueryValue(value
, val
);
2171 wxPrintf(_T("'%s'"), val
.c_str());
2173 key
.QueryRawValue(value
, val
);
2174 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2179 cont
= key
.GetNextValue(value
, dummy
);
2183 static void TestRegistryAssociation()
2186 The second call to deleteself genertaes an error message, with a
2187 messagebox saying .flo is crucial to system operation, while the .ddf
2188 call also fails, but with no error message
2193 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2195 key
= _T("ddxf_auto_file") ;
2196 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2198 key
= _T("ddxf_auto_file") ;
2199 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2201 key
= _T("program,0") ;
2202 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2204 key
= _T("program \"%1\"") ;
2206 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2208 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2210 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2212 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2216 #endif // TEST_REGISTRY
2218 // ----------------------------------------------------------------------------
2220 // ----------------------------------------------------------------------------
2222 #ifdef TEST_SCOPEGUARD
2224 #include "wx/scopeguard.h"
2226 static void function0() { puts("function0()"); }
2227 static void function1(int n
) { printf("function1(%d)\n", n
); }
2228 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2232 void method0() { printf("method0()\n"); }
2233 void method1(int n
) { printf("method1(%d)\n", n
); }
2234 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2237 static void TestScopeGuard()
2239 wxON_BLOCK_EXIT0(function0
);
2240 wxON_BLOCK_EXIT1(function1
, 17);
2241 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2244 wxON_BLOCK_EXIT_OBJ0(obj
, Object
::method0
);
2245 wxON_BLOCK_EXIT_OBJ1(obj
, Object
::method1
, 7);
2246 wxON_BLOCK_EXIT_OBJ2(obj
, Object
::method2
, 2.71, 'e');
2248 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2249 dismissed
.Dismiss();
2254 // ----------------------------------------------------------------------------
2256 // ----------------------------------------------------------------------------
2260 #include "wx/socket.h"
2261 #include "wx/protocol/protocol.h"
2262 #include "wx/protocol/http.h"
2264 static void TestSocketServer()
2266 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2268 static const int PORT
= 3000;
2273 wxSocketServer
*server
= new wxSocketServer(addr
);
2274 if ( !server
->Ok() )
2276 wxPuts(_T("ERROR: failed to bind"));
2284 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2286 wxSocketBase
*socket
= server
->Accept();
2289 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2293 wxPuts(_T("Server: got a client."));
2295 server
->SetTimeout(60); // 1 min
2298 while ( !close
&& socket
->IsConnected() )
2301 wxChar ch
= _T('\0');
2304 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2306 // don't log error if the client just close the connection
2307 if ( socket
->IsConnected() )
2309 wxPuts(_T("ERROR: in wxSocket::Read."));
2329 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2330 if ( s
== _T("close") )
2332 wxPuts(_T("Closing connection"));
2336 else if ( s
== _T("quit") )
2341 wxPuts(_T("Shutting down the server"));
2343 else // not a special command
2345 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2346 socket
->Write("\r\n", 2);
2347 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
2353 wxPuts(_T("Server: lost a client unexpectedly."));
2359 // same as "delete server" but is consistent with GUI programs
2363 static void TestSocketClient()
2365 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2367 static const wxChar
*hostname
= _T("www.wxwidgets.org");
2370 addr
.Hostname(hostname
);
2373 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
2375 wxSocketClient client
;
2376 if ( !client
.Connect(addr
) )
2378 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2382 wxPrintf(_T("--- Connected to %s:%u...\n"),
2383 addr
.Hostname().c_str(), addr
.Service());
2387 // could use simply "GET" here I suppose
2389 wxString
::Format(_T("GET http://%s/\r\n"), hostname
);
2390 client
.Write(cmdGet
, cmdGet
.length());
2391 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2392 MakePrintable(cmdGet
).c_str());
2393 client
.Read(buf
, WXSIZEOF(buf
));
2394 wxPrintf(_T("--- Server replied:\n%s"), buf
);
2398 #endif // TEST_SOCKETS
2400 // ----------------------------------------------------------------------------
2402 // ----------------------------------------------------------------------------
2406 #include "wx/protocol/ftp.h"
2408 #define FTP_ANONYMOUS
2410 #ifdef FTP_ANONYMOUS
2411 static const wxChar
*directory
= _T("/pub");
2412 static const wxChar
*filename
= _T("welcome.msg");
2414 static const wxChar
*directory
= _T("/etc");
2415 static const wxChar
*filename
= _T("issue");
2418 static bool TestFtpConnect()
2420 wxPuts(_T("*** Testing FTP connect ***"));
2422 #ifdef FTP_ANONYMOUS
2423 static const wxChar
*hostname
= _T("ftp.wxwidgets.org");
2425 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2426 #else // !FTP_ANONYMOUS
2427 static const wxChar
*hostname
= "localhost";
2430 wxFgets(user
, WXSIZEOF(user
), stdin
);
2431 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2434 wxChar password
[256];
2435 wxPrintf(_T("Password for %s: "), password
);
2436 wxFgets(password
, WXSIZEOF(password
), stdin
);
2437 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2438 ftp
.SetPassword(password
);
2440 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2441 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2443 if ( !ftp
.Connect(hostname
) )
2445 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2451 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2452 hostname
, ftp
.Pwd().c_str());
2459 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2460 static void TestFtpWuFtpd()
2463 static const wxChar
*hostname
= _T("ftp.eudora.com");
2464 if ( !ftp
.Connect(hostname
) )
2466 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2470 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
2471 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2474 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2478 size_t size
= in
->GetSize();
2479 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2481 wxChar
*data
= new wxChar
[size
];
2482 if ( !in
->Read(data
, size
) )
2484 wxPuts(_T("ERROR: read error"));
2488 wxPrintf(_T("Successfully retrieved the file.\n"));
2497 static void TestFtpList()
2499 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2502 if ( !ftp
.ChDir(directory
) )
2504 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2507 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2509 // test NLIST and LIST
2510 wxArrayString files
;
2511 if ( !ftp
.GetFilesList(files
) )
2513 wxPuts(_T("ERROR: failed to get NLIST of files"));
2517 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
2518 size_t count
= files
.GetCount();
2519 for ( size_t n
= 0; n
< count
; n
++ )
2521 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2523 wxPuts(_T("End of the file list"));
2526 if ( !ftp
.GetDirList(files
) )
2528 wxPuts(_T("ERROR: failed to get LIST of files"));
2532 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
2533 size_t count
= files
.GetCount();
2534 for ( size_t n
= 0; n
< count
; n
++ )
2536 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2538 wxPuts(_T("End of the file list"));
2541 if ( !ftp
.ChDir(_T("..")) )
2543 wxPuts(_T("ERROR: failed to cd to .."));
2546 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2549 static void TestFtpDownload()
2551 wxPuts(_T("*** Testing wxFTP download ***\n"));
2554 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2557 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2561 size_t size
= in
->GetSize();
2562 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2565 wxChar
*data
= new wxChar
[size
];
2566 if ( !in
->Read(data
, size
) )
2568 wxPuts(_T("ERROR: read error"));
2572 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
2580 static void TestFtpFileSize()
2582 wxPuts(_T("*** Testing FTP SIZE command ***"));
2584 if ( !ftp
.ChDir(directory
) )
2586 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2589 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2591 if ( ftp
.FileExists(filename
) )
2593 int size
= ftp
.GetFileSize(filename
);
2595 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
2597 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
2601 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
2605 static void TestFtpMisc()
2607 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2609 if ( ftp
.SendCommand(_T("STAT")) != '2' )
2611 wxPuts(_T("ERROR: STAT failed"));
2615 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
2618 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
2620 wxPuts(_T("ERROR: HELP SITE failed"));
2624 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2625 ftp
.GetLastResult().c_str());
2629 static void TestFtpInteractive()
2631 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2637 wxPrintf(_T("Enter FTP command: "));
2638 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2641 // kill the last '\n'
2642 buf
[wxStrlen(buf
) - 1] = 0;
2644 // special handling of LIST and NLST as they require data connection
2645 wxString
start(buf
, 4);
2647 if ( start
== _T("LIST") || start
== _T("NLST") )
2650 if ( wxStrlen(buf
) > 4 )
2653 wxArrayString files
;
2654 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
2656 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
2660 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2661 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2662 size_t count
= files
.GetCount();
2663 for ( size_t n
= 0; n
< count
; n
++ )
2665 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2667 wxPuts(_T("--- End of the file list"));
2672 wxChar ch
= ftp
.SendCommand(buf
);
2673 wxPrintf(_T("Command %s"), ch ?
_T("succeeded") : _T("failed"));
2676 wxPrintf(_T(" (return code %c)"), ch
);
2679 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
2683 wxPuts(_T("\n*** done ***"));
2686 static void TestFtpUpload()
2688 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2691 static const wxChar
*file1
= _T("test1");
2692 static const wxChar
*file2
= _T("test2");
2693 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2696 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2697 out
->Write("First hello", 11);
2701 // send a command to check the remote file
2702 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
2704 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
2708 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2709 file1
, ftp
.GetLastResult().c_str());
2712 out
= ftp
.GetOutputStream(file2
);
2715 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2716 out
->Write("Second hello", 12);
2723 // ----------------------------------------------------------------------------
2725 // ----------------------------------------------------------------------------
2727 #ifdef TEST_STACKWALKER
2729 #if wxUSE_STACKWALKER
2731 #include "wx/stackwalk.h"
2733 class StackDump
: public wxStackWalker
2736 StackDump(const char *argv0
)
2737 : wxStackWalker(argv0
)
2741 virtual void Walk(size_t skip
= 1)
2743 wxPuts(_T("Stack dump:"));
2745 wxStackWalker
::Walk(skip
);
2749 virtual void OnStackFrame(const wxStackFrame
& frame
)
2751 printf("[%2d] ", (int) frame
.GetLevel());
2753 wxString name
= frame
.GetName();
2754 if ( !name
.empty() )
2756 printf("%-20.40s", (const char*)name
.mb_str());
2760 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2763 if ( frame
.HasSourceLocation() )
2766 (const char*)frame
.GetFileName().mb_str(),
2767 (int)frame
.GetLine());
2773 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2775 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2776 (const char*)name
.mb_str(),
2777 (const char*)val
.mb_str());
2782 static void TestStackWalk(const char *argv0
)
2784 wxPuts(_T("*** Testing wxStackWalker ***\n"));
2786 StackDump
dump(argv0
);
2790 #endif // wxUSE_STACKWALKER
2792 #endif // TEST_STACKWALKER
2794 // ----------------------------------------------------------------------------
2796 // ----------------------------------------------------------------------------
2798 #ifdef TEST_STDPATHS
2800 #include "wx/stdpaths.h"
2801 #include "wx/wxchar.h" // wxPrintf
2803 static void TestStandardPaths()
2805 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
2807 wxTheApp
->SetAppName(_T("console"));
2809 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
2810 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2811 wxPrintf(_T("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2812 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2813 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2814 wxPrintf(_T("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2815 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2816 wxPrintf(_T("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2817 wxPrintf(_T("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2818 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2819 wxPrintf(_T("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2820 wxPrintf(_T("Localized res. dir:\t%s\n"),
2821 stdp
.GetLocalizedResourcesDir(_T("fr")).c_str());
2822 wxPrintf(_T("Message catalogs dir:\t%s\n"),
2823 stdp
.GetLocalizedResourcesDir
2826 wxStandardPaths
::ResourceCat_Messages
2830 #endif // TEST_STDPATHS
2832 // ----------------------------------------------------------------------------
2834 // ----------------------------------------------------------------------------
2838 #include "wx/wfstream.h"
2839 #include "wx/mstream.h"
2841 static void TestFileStream()
2843 wxPuts(_T("*** Testing wxFileInputStream ***"));
2845 static const wxString filename
= _T("testdata.fs");
2847 wxFileOutputStream
fsOut(filename
);
2848 fsOut
.Write("foo", 3);
2852 wxFileInputStream
fsIn(filename
);
2853 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
2854 while ( !fsIn
.Eof() )
2856 wxPutchar(fsIn
.GetC());
2860 if ( !wxRemoveFile(filename
) )
2862 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2865 wxPuts(_T("\n*** wxFileInputStream test done ***"));
2868 static void TestMemoryStream()
2870 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
2872 wxMemoryOutputStream memOutStream
;
2873 wxPrintf(_T("Initially out stream offset: %lu\n"),
2874 (unsigned long)memOutStream
.TellO());
2876 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
2878 memOutStream
.PutC(*p
);
2881 wxPrintf(_T("Final out stream offset: %lu\n"),
2882 (unsigned long)memOutStream
.TellO());
2884 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
2887 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2889 wxMemoryInputStream
memInpStream(buf
, len
);
2890 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2891 while ( !memInpStream
.Eof() )
2893 wxPutchar(memInpStream
.GetC());
2896 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
2899 #endif // TEST_STREAMS
2901 // ----------------------------------------------------------------------------
2903 // ----------------------------------------------------------------------------
2907 #include "wx/stopwatch.h"
2908 #include "wx/utils.h"
2910 static void TestStopWatch()
2912 wxPuts(_T("*** Testing wxStopWatch ***\n"));
2916 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
2919 wxPrintf(_T("\t%ldms\n"), sw
.Time());
2921 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
2925 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2928 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
2931 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2934 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
2937 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2940 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
2941 for ( size_t n
= 0; n
< 70; n
++ )
2945 for ( size_t m
= 0; m
< 100000; m
++ )
2947 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2949 wxPuts(_T("\ntime is negative - ERROR!"));
2957 wxPuts(_T(", ok."));
2960 #include "wx/timer.h"
2961 #include "wx/evtloop.h"
2965 wxPuts(_T("*** Testing wxTimer ***\n"));
2967 class MyTimer
: public wxTimer
2970 MyTimer() : wxTimer() { m_num
= 0; }
2972 virtual void Notify()
2974 wxPrintf(_T("%d"), m_num
++);
2979 wxPrintf(_T("... exiting the event loop"));
2982 wxEventLoop
::GetActive()->Exit(0);
2983 wxPuts(_T(", ok."));
2996 timer1
.Start(100, true /* one shot */);
2998 timer1
.Start(100, true /* one shot */);
3006 #endif // TEST_TIMER
3008 // ----------------------------------------------------------------------------
3010 // ----------------------------------------------------------------------------
3014 #include "wx/vcard.h"
3016 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3019 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3022 wxPrintf(_T("%s%s"),
3023 wxString(_T('\t'), level
).c_str(),
3024 vcObj
->GetName().c_str());
3027 switch ( vcObj
->GetType() )
3029 case wxVCardObject
::String
:
3030 case wxVCardObject
::UString
:
3033 vcObj
->GetValue(&val
);
3034 value
<< _T('"') << val
<< _T('"');
3038 case wxVCardObject
::Int
:
3041 vcObj
->GetValue(&i
);
3042 value
.Printf(_T("%u"), i
);
3046 case wxVCardObject
::Long
:
3049 vcObj
->GetValue(&l
);
3050 value
.Printf(_T("%lu"), l
);
3054 case wxVCardObject
::None
:
3057 case wxVCardObject
::Object
:
3058 value
= _T("<node>");
3062 value
= _T("<unknown value type>");
3066 wxPrintf(_T(" = %s"), value
.c_str());
3069 DumpVObject(level
+ 1, *vcObj
);
3072 vcObj
= vcard
.GetNextProp(&cookie
);
3076 static void DumpVCardAddresses(const wxVCard
& vcard
)
3078 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3082 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3086 int flags
= addr
->GetFlags();
3087 if ( flags
& wxVCardAddress
::Domestic
)
3089 flagsStr
<< _T("domestic ");
3091 if ( flags
& wxVCardAddress
::Intl
)
3093 flagsStr
<< _T("international ");
3095 if ( flags
& wxVCardAddress
::Postal
)
3097 flagsStr
<< _T("postal ");
3099 if ( flags
& wxVCardAddress
::Parcel
)
3101 flagsStr
<< _T("parcel ");
3103 if ( flags
& wxVCardAddress
::Home
)
3105 flagsStr
<< _T("home ");
3107 if ( flags
& wxVCardAddress
::Work
)
3109 flagsStr
<< _T("work ");
3112 wxPrintf(_T("Address %u:\n")
3114 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3117 addr
->GetPostOffice().c_str(),
3118 addr
->GetExtAddress().c_str(),
3119 addr
->GetStreet().c_str(),
3120 addr
->GetLocality().c_str(),
3121 addr
->GetRegion().c_str(),
3122 addr
->GetPostalCode().c_str(),
3123 addr
->GetCountry().c_str()
3127 addr
= vcard
.GetNextAddress(&cookie
);
3131 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3133 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3137 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3141 int flags
= phone
->GetFlags();
3142 if ( flags
& wxVCardPhoneNumber
::Voice
)
3144 flagsStr
<< _T("voice ");
3146 if ( flags
& wxVCardPhoneNumber
::Fax
)
3148 flagsStr
<< _T("fax ");
3150 if ( flags
& wxVCardPhoneNumber
::Cellular
)
3152 flagsStr
<< _T("cellular ");
3154 if ( flags
& wxVCardPhoneNumber
::Modem
)
3156 flagsStr
<< _T("modem ");
3158 if ( flags
& wxVCardPhoneNumber
::Home
)
3160 flagsStr
<< _T("home ");
3162 if ( flags
& wxVCardPhoneNumber
::Work
)
3164 flagsStr
<< _T("work ");
3167 wxPrintf(_T("Phone number %u:\n")
3172 phone
->GetNumber().c_str()
3176 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3180 static void TestVCardRead()
3182 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3184 wxVCard
vcard(_T("vcard.vcf"));
3185 if ( !vcard
.IsOk() )
3187 wxPuts(_T("ERROR: couldn't load vCard."));
3191 // read individual vCard properties
3192 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3196 vcObj
->GetValue(&value
);
3201 value
= _T("<none>");
3204 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3207 if ( !vcard
.GetFullName(&value
) )
3209 value
= _T("<none>");
3212 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3214 // now show how to deal with multiply occurring properties
3215 DumpVCardAddresses(vcard
);
3216 DumpVCardPhoneNumbers(vcard
);
3218 // and finally show all
3219 wxPuts(_T("\nNow dumping the entire vCard:\n")
3220 "-----------------------------\n");
3222 DumpVObject(0, vcard
);
3226 static void TestVCardWrite()
3228 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3231 if ( !vcard
.IsOk() )
3233 wxPuts(_T("ERROR: couldn't create vCard."));
3238 vcard
.SetName("Zeitlin", "Vadim");
3239 vcard
.SetFullName("Vadim Zeitlin");
3240 vcard
.SetOrganization("wxWidgets", "R&D");
3242 // just dump the vCard back
3243 wxPuts(_T("Entire vCard follows:\n"));
3244 wxPuts(vcard
.Write());
3248 #endif // TEST_VCARD
3250 // ----------------------------------------------------------------------------
3252 // ----------------------------------------------------------------------------
3254 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3260 #include "wx/volume.h"
3262 static const wxChar
*volumeKinds
[] =
3268 _T("network volume"),
3272 static void TestFSVolume()
3274 wxPuts(_T("*** Testing wxFSVolume class ***"));
3276 wxArrayString volumes
= wxFSVolume
::GetVolumes();
3277 size_t count
= volumes
.GetCount();
3281 wxPuts(_T("ERROR: no mounted volumes?"));
3285 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3287 for ( size_t n
= 0; n
< count
; n
++ )
3289 wxFSVolume
vol(volumes
[n
]);
3292 wxPuts(_T("ERROR: couldn't create volume"));
3296 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3298 vol
.GetDisplayName().c_str(),
3299 vol
.GetName().c_str(),
3300 volumeKinds
[vol
.GetKind()],
3301 vol
.IsWritable() ?
_T("rw") : _T("ro"),
3302 vol
.GetFlags() & wxFS_VOL_REMOVABLE ?
_T("removable")
3307 #endif // TEST_VOLUME
3309 // ----------------------------------------------------------------------------
3310 // wide char and Unicode support
3311 // ----------------------------------------------------------------------------
3315 #include "wx/strconv.h"
3316 #include "wx/fontenc.h"
3317 #include "wx/encconv.h"
3318 #include "wx/buffer.h"
3320 static const unsigned char utf8koi8r
[] =
3322 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3323 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3324 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3325 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3326 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3327 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3328 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3331 static const unsigned char utf8iso8859_1
[] =
3333 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3334 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3335 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3336 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3337 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3340 static const unsigned char utf8Invalid
[] =
3342 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3343 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3344 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3345 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3349 static const struct Utf8Data
3351 const unsigned char *text
;
3353 const wxChar
*charset
;
3354 wxFontEncoding encoding
;
3357 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3358 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3359 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3362 static void TestUtf8()
3364 wxPuts(_T("*** Testing UTF8 support ***\n"));
3369 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3371 const Utf8Data
& u8d
= utf8data
[n
];
3372 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3373 WXSIZEOF(wbuf
)) == (size_t)-1 )
3375 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3379 wxCSConv
conv(u8d
.charset
);
3380 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3382 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3386 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3390 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3392 s
= _T("<< conversion failed >>");
3393 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3397 wxPuts(wxEmptyString
);
3400 static void TestEncodingConverter()
3402 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3404 // using wxEncodingConverter should give the same result as above
3407 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3408 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3410 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3414 wxEncodingConverter ec
;
3415 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3416 ec
.Convert(wbuf
, buf
);
3417 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3420 wxPuts(wxEmptyString
);
3423 #endif // TEST_WCHAR
3425 // ----------------------------------------------------------------------------
3427 // ----------------------------------------------------------------------------
3431 #include "wx/filesys.h"
3432 #include "wx/fs_zip.h"
3433 #include "wx/zipstrm.h"
3435 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3437 static void TestZipStreamRead()
3439 wxPuts(_T("*** Testing ZIP reading ***\n"));
3441 static const wxString filename
= _T("foo");
3442 wxFFileInputStream
in(TESTFILE_ZIP
);
3443 wxZipInputStream
istr(in
);
3444 wxZipEntry
entry(filename
);
3445 istr
.OpenEntry(entry
);
3447 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3449 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3450 while ( !istr
.Eof() )
3452 wxPutchar(istr
.GetC());
3456 wxPuts(_T("\n----- done ------"));
3459 static void DumpZipDirectory(wxFileSystem
& fs
,
3460 const wxString
& dir
,
3461 const wxString
& indent
)
3463 wxString prefix
= wxString
::Format(_T("%s#zip:%s"),
3464 TESTFILE_ZIP
, dir
.c_str());
3465 wxString wildcard
= prefix
+ _T("/*");
3467 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3468 while ( !dirname
.empty() )
3470 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3472 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3477 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3479 DumpZipDirectory(fs
, dirname
,
3480 indent
+ wxString(_T(' '), 4));
3482 dirname
= fs
.FindNext();
3485 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3486 while ( !filename
.empty() )
3488 if ( !filename
.StartsWith(prefix
, &filename
) )
3490 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3495 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3497 filename
= fs
.FindNext();
3501 static void TestZipFileSystem()
3503 wxPuts(_T("*** Testing ZIP file system ***\n"));
3505 wxFileSystem
::AddHandler(new wxZipFSHandler
);
3507 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3509 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3514 // ----------------------------------------------------------------------------
3516 // ----------------------------------------------------------------------------
3518 #ifdef TEST_DATETIME
3520 #include "wx/math.h"
3521 #include "wx/datetime.h"
3523 // this test miscellaneous static wxDateTime functions
3527 static void TestTimeStatic()
3529 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3531 // some info about the current date
3532 int year
= wxDateTime
::GetCurrentYear();
3533 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3535 wxDateTime
::IsLeapYear(year
) ?
"" : "not ",
3536 wxDateTime
::GetNumberOfDays(year
));
3538 wxDateTime
::Month month
= wxDateTime
::GetCurrentMonth();
3539 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3540 wxDateTime
::GetMonthName(month
, wxDateTime
::Name_Abbr
).c_str(),
3541 wxDateTime
::GetMonthName(month
).c_str(),
3542 wxDateTime
::GetNumberOfDays(month
));
3545 // test time zones stuff
3546 static void TestTimeZones()
3548 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3550 wxDateTime now
= wxDateTime
::Now();
3552 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime
::GMT0
).c_str());
3553 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime
::GMT0
).c_str());
3554 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime
::EST
).c_str());
3555 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime
::CET
).c_str());
3556 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime
::MSK
).c_str());
3557 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime
::EST
).c_str());
3559 wxPrintf(_T("%s\n"), wxDateTime
::Now().Format(_T("Our timezone is %Z")).c_str());
3561 wxDateTime
::Tm tm
= now
.GetTm();
3562 if ( wxDateTime(tm
) != now
)
3564 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3565 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3569 // test some minimal support for the dates outside the standard range
3570 static void TestTimeRange()
3572 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3574 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
3576 wxPrintf(_T("Unix epoch:\t%s\n"),
3577 wxDateTime(2440587.5).Format(fmt
).c_str());
3578 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3579 wxDateTime(29, wxDateTime
::Feb
, 0).Format(fmt
).c_str());
3580 wxPrintf(_T("JDN 0: \t%s\n"),
3581 wxDateTime(0.0).Format(fmt
).c_str());
3582 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3583 wxDateTime(1, wxDateTime
::Jan
, 1).Format(fmt
).c_str());
3584 wxPrintf(_T("May 29, 2099:\t%s\n"),
3585 wxDateTime(29, wxDateTime
::May
, 2099).Format(fmt
).c_str());
3588 // test DST calculations
3589 static void TestTimeDST()
3591 wxPuts(_T("\n*** wxDateTime DST test ***"));
3593 wxPrintf(_T("DST is%s in effect now.\n\n"),
3594 wxDateTime
::Now().IsDST() ? wxEmptyString
: _T(" not"));
3596 for ( int year
= 1990; year
< 2005; year
++ )
3598 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3600 wxDateTime
::GetBeginDST(year
, wxDateTime
::Country_EEC
).Format().c_str(),
3601 wxDateTime
::GetEndDST(year
, wxDateTime
::Country_EEC
).Format().c_str());
3607 #if TEST_INTERACTIVE
3609 static void TestDateTimeInteractive()
3611 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3617 wxPrintf(_T("Enter a date: "));
3618 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3621 // kill the last '\n'
3622 buf
[wxStrlen(buf
) - 1] = 0;
3625 const wxChar
*p
= dt
.ParseDate(buf
);
3628 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
3634 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
3637 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3638 dt
.Format(_T("%b %d, %Y")).c_str(),
3640 dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
3641 dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
3642 dt
.GetWeekOfYear(wxDateTime
::Monday_First
));
3645 wxPuts(_T("\n*** done ***"));
3648 #endif // TEST_INTERACTIVE
3652 static void TestTimeMS()
3654 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3656 wxDateTime dt1
= wxDateTime
::Now(),
3657 dt2
= wxDateTime
::UNow();
3659 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
3660 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3661 wxPrintf(_T("Dummy loop: "));
3662 for ( int i
= 0; i
< 6000; i
++ )
3664 //for ( int j = 0; j < 10; j++ )
3667 s
.Printf(_T("%g"), sqrt((float)i
));
3673 wxPuts(_T(", done"));
3676 dt2
= wxDateTime
::UNow();
3677 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3679 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
3681 wxPuts(_T("\n*** done ***"));
3684 static void TestTimeHolidays()
3686 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3688 wxDateTime
::Tm tm
= wxDateTime(29, wxDateTime
::May
, 2000).GetTm();
3689 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3690 dtEnd
= dtStart
.GetLastMonthDay();
3692 wxDateTimeArray hol
;
3693 wxDateTimeHolidayAuthority
::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3695 const wxChar
*format
= _T("%d-%b-%Y (%a)");
3697 wxPrintf(_T("All holidays between %s and %s:\n"),
3698 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3700 size_t count
= hol
.GetCount();
3701 for ( size_t n
= 0; n
< count
; n
++ )
3703 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
3706 wxPuts(wxEmptyString
);
3709 static void TestTimeZoneBug()
3711 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3713 wxDateTime date
= wxDateTime(1, wxDateTime
::Mar
, 2000);
3714 for ( int i
= 0; i
< 31; i
++ )
3716 wxPrintf(_T("Date %s: week day %s.\n"),
3717 date
.Format(_T("%d-%m-%Y")).c_str(),
3718 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3720 date
+= wxDateSpan
::Day();
3723 wxPuts(wxEmptyString
);
3726 static void TestTimeSpanFormat()
3728 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3730 static const wxChar
*formats
[] =
3732 _T("(default) %H:%M:%S"),
3733 _T("%E weeks and %D days"),
3734 _T("%l milliseconds"),
3735 _T("(with ms) %H:%M:%S:%l"),
3736 _T("100%% of minutes is %M"), // test "%%"
3737 _T("%D days and %H hours"),
3738 _T("or also %S seconds"),
3741 wxTimeSpan
ts1(1, 2, 3, 4),
3743 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3745 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3746 ts1
.Format(formats
[n
]).c_str(),
3747 ts2
.Format(formats
[n
]).c_str());
3750 wxPuts(wxEmptyString
);
3755 #endif // TEST_DATETIME
3757 // ----------------------------------------------------------------------------
3758 // wxTextInput/OutputStream
3759 // ----------------------------------------------------------------------------
3761 #ifdef TEST_TEXTSTREAM
3763 #include "wx/txtstrm.h"
3764 #include "wx/wfstream.h"
3766 static void TestTextInputStream()
3768 wxPuts(_T("\n*** wxTextInputStream test ***"));
3770 wxString filename
= _T("testdata.fc");
3771 wxFileInputStream
fsIn(filename
);
3774 wxPuts(_T("ERROR: couldn't open file."));
3778 wxTextInputStream
tis(fsIn
);
3783 const wxString s
= tis
.ReadLine();
3785 // line could be non empty if the last line of the file isn't
3786 // terminated with EOL
3787 if ( fsIn
.Eof() && s
.empty() )
3790 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
3795 #endif // TEST_TEXTSTREAM
3797 // ----------------------------------------------------------------------------
3799 // ----------------------------------------------------------------------------
3803 #include "wx/thread.h"
3805 static size_t gs_counter
= (size_t)-1;
3806 static wxCriticalSection gs_critsect
;
3807 static wxSemaphore gs_cond
;
3809 class MyJoinableThread
: public wxThread
3812 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3813 { m_n
= n
; Create(); }
3815 // thread execution starts here
3816 virtual ExitCode
Entry();
3822 wxThread
::ExitCode MyJoinableThread
::Entry()
3824 unsigned long res
= 1;
3825 for ( size_t n
= 1; n
< m_n
; n
++ )
3829 // it's a loooong calculation :-)
3833 return (ExitCode
)res
;
3836 class MyDetachedThread
: public wxThread
3839 MyDetachedThread(size_t n
, wxChar ch
)
3843 m_cancelled
= false;
3848 // thread execution starts here
3849 virtual ExitCode
Entry();
3852 virtual void OnExit();
3855 size_t m_n
; // number of characters to write
3856 wxChar m_ch
; // character to write
3858 bool m_cancelled
; // false if we exit normally
3861 wxThread
::ExitCode MyDetachedThread
::Entry()
3864 wxCriticalSectionLocker
lock(gs_critsect
);
3865 if ( gs_counter
== (size_t)-1 )
3871 for ( size_t n
= 0; n
< m_n
; n
++ )
3873 if ( TestDestroy() )
3883 wxThread
::Sleep(100);
3889 void MyDetachedThread
::OnExit()
3891 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
3893 wxCriticalSectionLocker
lock(gs_critsect
);
3894 if ( !--gs_counter
&& !m_cancelled
)
3898 static void TestDetachedThreads()
3900 wxPuts(_T("\n*** Testing detached threads ***"));
3902 static const size_t nThreads
= 3;
3903 MyDetachedThread
*threads
[nThreads
];
3905 for ( n
= 0; n
< nThreads
; n
++ )
3907 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3910 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3911 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3913 for ( n
= 0; n
< nThreads
; n
++ )
3918 // wait until all threads terminate
3921 wxPuts(wxEmptyString
);
3924 static void TestJoinableThreads()
3926 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
3928 // calc 10! in the background
3929 MyJoinableThread
thread(10);
3932 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
3933 (unsigned long)thread
.Wait());
3936 static void TestThreadSuspend()
3938 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
3940 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3944 // this is for this demo only, in a real life program we'd use another
3945 // condition variable which would be signaled from wxThread::Entry() to
3946 // tell us that the thread really started running - but here just wait a
3947 // bit and hope that it will be enough (the problem is, of course, that
3948 // the thread might still not run when we call Pause() which will result
3950 wxThread
::Sleep(300);
3952 for ( size_t n
= 0; n
< 3; n
++ )
3956 wxPuts(_T("\nThread suspended"));
3959 // don't sleep but resume immediately the first time
3960 wxThread
::Sleep(300);
3962 wxPuts(_T("Going to resume the thread"));
3967 wxPuts(_T("Waiting until it terminates now"));
3969 // wait until the thread terminates
3972 wxPuts(wxEmptyString
);
3975 static void TestThreadDelete()
3977 // As above, using Sleep() is only for testing here - we must use some
3978 // synchronisation object instead to ensure that the thread is still
3979 // running when we delete it - deleting a detached thread which already
3980 // terminated will lead to a crash!
3982 wxPuts(_T("\n*** Testing thread delete function ***"));
3984 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3988 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
3990 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3994 wxThread
::Sleep(300);
3998 wxPuts(_T("\nDeleted a running thread."));
4000 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4004 wxThread
::Sleep(300);
4010 wxPuts(_T("\nDeleted a sleeping thread."));
4012 MyJoinableThread
thread3(20);
4017 wxPuts(_T("\nDeleted a joinable thread."));
4019 MyJoinableThread
thread4(2);
4022 wxThread
::Sleep(300);
4026 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
4028 wxPuts(wxEmptyString
);
4031 class MyWaitingThread
: public wxThread
4034 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
4037 m_condition
= condition
;
4042 virtual ExitCode
Entry()
4044 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
4049 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
4053 m_condition
->Wait();
4056 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
4064 wxCondition
*m_condition
;
4067 static void TestThreadConditions()
4070 wxCondition
condition(mutex
);
4072 // otherwise its difficult to understand which log messages pertain to
4074 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
4075 // condition.GetId(), gs_cond.GetId());
4077 // create and launch threads
4078 MyWaitingThread
*threads
[10];
4081 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4083 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
4086 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4091 // wait until all threads run
4092 wxPuts(_T("Main thread is waiting for the other threads to start"));
4095 size_t nRunning
= 0;
4096 while ( nRunning
< WXSIZEOF(threads
) )
4102 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
4106 wxPuts(_T("Main thread: all threads started up."));
4109 wxThread
::Sleep(500);
4112 // now wake one of them up
4113 wxPrintf(_T("Main thread: about to signal the condition.\n"));
4118 wxThread
::Sleep(200);
4120 // wake all the (remaining) threads up, so that they can exit
4121 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
4123 condition
.Broadcast();
4125 // give them time to terminate (dirty!)
4126 wxThread
::Sleep(500);
4129 #include "wx/utils.h"
4131 class MyExecThread
: public wxThread
4134 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
4140 virtual ExitCode
Entry()
4142 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
4149 static void TestThreadExec()
4151 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4153 MyExecThread
thread(_T("true"));
4156 wxPrintf(_T("Main program exit code: %ld.\n"),
4157 wxExecute(_T("false"), wxEXEC_SYNC
));
4159 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
4163 #include "wx/datetime.h"
4165 class MySemaphoreThread
: public wxThread
4168 MySemaphoreThread(int i
, wxSemaphore
*sem
)
4169 : wxThread(wxTHREAD_JOINABLE
),
4176 virtual ExitCode
Entry()
4178 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4179 wxDateTime
::Now().FormatTime().c_str(), m_i
, (long)GetId());
4183 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4184 wxDateTime
::Now().FormatTime().c_str(), m_i
, (long)GetId());
4188 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4189 wxDateTime
::Now().FormatTime().c_str(), m_i
, (long)GetId());
4201 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
4203 static void TestSemaphore()
4205 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4207 static const int SEM_LIMIT
= 3;
4209 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
4210 ArrayThreads threads
;
4212 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
4214 threads
.Add(new MySemaphoreThread(i
, &sem
));
4215 threads
.Last()->Run();
4218 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
4225 #endif // TEST_THREADS
4227 // ----------------------------------------------------------------------------
4229 // ----------------------------------------------------------------------------
4231 #ifdef TEST_SNGLINST
4232 #include "wx/snglinst.h"
4233 #endif // TEST_SNGLINST
4235 int main(int argc
, char **argv
)
4238 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
4243 for (n
= 0; n
< argc
; n
++ )
4245 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
4246 wxArgv
[n
] = wxStrdup(warg
);
4251 #else // !wxUSE_UNICODE
4253 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
4255 wxApp
::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
4257 wxInitializer initializer
;
4260 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
4265 #ifdef TEST_SNGLINST
4266 wxSingleInstanceChecker checker
;
4267 if ( checker
.Create(_T(".wxconsole.lock")) )
4269 if ( checker
.IsAnotherRunning() )
4271 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4276 // wait some time to give time to launch another instance
4277 wxPrintf(_T("Press \"Enter\" to continue..."));
4280 else // failed to create
4282 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4284 #endif // TEST_SNGLINST
4287 TestCmdLineConvert();
4289 #if wxUSE_CMDLINE_PARSER
4290 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4292 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
4293 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
4294 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
4295 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
4297 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
4298 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
4299 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
4300 wxCMD_LINE_VAL_NUMBER
},
4301 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
4302 wxCMD_LINE_VAL_DATE
},
4303 { wxCMD_LINE_OPTION
, "f", "double", "output double",
4304 wxCMD_LINE_VAL_DOUBLE
},
4306 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
4307 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4312 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
4314 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4315 wxCMD_LINE_VAL_STRING
,
4316 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4318 switch ( parser
.Parse() )
4321 wxLogMessage(_T("Help was given, terminating."));
4325 ShowCmdLine(parser
);
4329 wxLogMessage(_T("Syntax error detected, aborting."));
4332 #endif // wxUSE_CMDLINE_PARSER
4334 #endif // TEST_CMDLINE
4346 TestDllListLoaded();
4347 #endif // TEST_DYNLIB
4351 #endif // TEST_ENVIRON
4355 #endif // TEST_EXECUTE
4357 #ifdef TEST_FILECONF
4359 #endif // TEST_FILECONF
4363 #endif // TEST_LOCALE
4366 wxPuts(_T("*** Testing wxLog ***"));
4369 for ( size_t n
= 0; n
< 8000; n
++ )
4371 s
<< (wxChar
)(_T('A') + (n
% 26));
4374 wxLogWarning(_T("The length of the string is %lu"),
4375 (unsigned long)s
.length());
4378 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
4380 // this one shouldn't be truncated
4383 // but this one will because log functions use fixed size buffer
4384 // (note that it doesn't need '\n' at the end neither - will be added
4386 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
4396 #ifdef TEST_FILENAME
4399 TestFileNameDirManip();
4400 TestFileNameComparison();
4401 TestFileNameOperations();
4402 #endif // TEST_FILENAME
4404 #ifdef TEST_FILETIME
4409 #endif // TEST_FILETIME
4412 wxLog
::AddTraceMask(FTP_TRACE_MASK
);
4413 if ( TestFtpConnect() )
4423 #if TEST_INTERACTIVE
4424 TestFtpInteractive();
4427 //else: connecting to the FTP server failed
4435 //wxLog::AddTraceMask(_T("mime"));
4439 TestMimeAssociate();
4444 #ifdef TEST_INFO_FUNCTIONS
4449 #if TEST_INTERACTIVE
4452 #endif // TEST_INFO_FUNCTIONS
4454 #ifdef TEST_PATHLIST
4456 #endif // TEST_PATHLIST
4460 #endif // TEST_PRINTF
4467 #endif // TEST_REGCONF
4469 #if defined TEST_REGEX && TEST_INTERACTIVE
4470 TestRegExInteractive();
4471 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4473 #ifdef TEST_REGISTRY
4475 TestRegistryAssociation();
4476 #endif // TEST_REGISTRY
4481 #endif // TEST_SOCKETS
4488 #endif // TEST_STREAMS
4490 #ifdef TEST_TEXTSTREAM
4491 TestTextInputStream();
4492 #endif // TEST_TEXTSTREAM
4495 int nCPUs
= wxThread
::GetCPUCount();
4496 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
4498 wxThread
::SetConcurrency(nCPUs
);
4500 TestJoinableThreads();
4503 TestJoinableThreads();
4504 TestDetachedThreads();
4505 TestThreadSuspend();
4507 TestThreadConditions();
4511 #endif // TEST_THREADS
4516 #endif // TEST_TIMER
4518 #ifdef TEST_DATETIME
4525 TestTimeSpanFormat();
4531 #if TEST_INTERACTIVE
4532 TestDateTimeInteractive();
4534 #endif // TEST_DATETIME
4536 #ifdef TEST_SCOPEGUARD
4540 #ifdef TEST_STACKWALKER
4541 #if wxUSE_STACKWALKER
4542 TestStackWalk(argv
[0]);
4544 #endif // TEST_STACKWALKER
4546 #ifdef TEST_STDPATHS
4547 TestStandardPaths();
4551 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4553 #endif // TEST_USLEEP
4558 #endif // TEST_VCARD
4562 #endif // TEST_VOLUME
4566 TestEncodingConverter();
4567 #endif // TEST_WCHAR
4570 TestZipStreamRead();
4571 TestZipFileSystem();
4576 for ( int n
= 0; n
< argc
; n
++ )
4581 #endif // wxUSE_UNICODE