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 // IMPORTANT NOTE FOR WXWIDGETS USERS:
13 // If you're a wxWidgets user and you're looking at this file to learn how to
14 // structure a wxWidgets console application, then you don't have much to learn.
15 // This application is used more for testing rather than as sample but
16 // basically the following simple block is enough for you to start your
17 // own console application:
20 int main(int argc, char **argv)
22 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
24 wxInitializer initializer;
27 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
31 static const wxCmdLineEntryDesc cmdLineDesc[] =
33 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
34 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
35 // ... your other command line options here...
40 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
41 switch ( parser.Parse() )
44 wxLogMessage(_T("Help was given, terminating."));
48 // everything is ok; proceed
52 wxLogMessage(_T("Syntax error detected, aborting."));
56 // do something useful here
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
75 #include "wx/string.h"
77 #include "wx/filename.h"
80 #include "wx/apptrait.h"
81 #include "wx/platinfo.h"
82 #include "wx/wxchar.h"
84 // without this pragma, the stupid compiler precompiles #defines below so that
85 // changing them doesn't "take place" later!
90 // ----------------------------------------------------------------------------
91 // conditional compilation
92 // ----------------------------------------------------------------------------
95 A note about all these conditional compilation macros: this file is used
96 both as a test suite for various non-GUI wxWidgets classes and as a
97 scratchpad for quick tests. So there are two compilation modes: if you
98 define TEST_ALL all tests are run, otherwise you may enable the individual
99 tests individually in the "#else" branch below.
102 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
103 // test, define it to 1 to do all tests.
109 #define TEST_DATETIME
115 #define TEST_FILECONF
116 #define TEST_FILENAME
117 #define TEST_FILETIME
118 // #define TEST_FTP --FIXME! (RN)
119 #define TEST_INFO_FUNCTIONS
124 #define TEST_PATHLIST
128 #define TEST_REGISTRY
129 #define TEST_SCOPEGUARD
130 #define TEST_SNGLINST
131 // #define TEST_SOCKETS --FIXME! (RN)
132 #define TEST_STACKWALKER
133 #define TEST_STDPATHS
135 #define TEST_TEXTSTREAM
138 // #define TEST_VCARD -- don't enable this (VZ)
139 // #define TEST_VOLUME --FIXME! (RN)
142 #else // #if TEST_ALL
146 // some tests are interactive, define this to run them
147 #ifdef TEST_INTERACTIVE
148 #undef TEST_INTERACTIVE
150 #define TEST_INTERACTIVE 1
152 #define TEST_INTERACTIVE 0
155 // ============================================================================
157 // ============================================================================
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 #if defined(TEST_SOCKETS)
165 // replace TABs with \t and CRs with \n
166 static wxString
MakePrintable(const wxChar
*s
)
169 (void)str
.Replace(_T("\t"), _T("\\t"));
170 (void)str
.Replace(_T("\n"), _T("\\n"));
171 (void)str
.Replace(_T("\r"), _T("\\r"));
176 #endif // MakePrintable() is used
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
184 #include "wx/cmdline.h"
185 #include "wx/datetime.h"
187 #if wxUSE_CMDLINE_PARSER
189 static void ShowCmdLine(const wxCmdLineParser
& parser
)
191 wxString s
= _T("Command line parsed successfully:\nInput files: ");
193 size_t count
= parser
.GetParamCount();
194 for ( size_t param
= 0; param
< count
; param
++ )
196 s
<< parser
.GetParam(param
) << ' ';
200 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
201 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
207 if ( parser
.Found(_T("o"), &strVal
) )
208 s
<< _T("Output file:\t") << strVal
<< '\n';
209 if ( parser
.Found(_T("i"), &strVal
) )
210 s
<< _T("Input dir:\t") << strVal
<< '\n';
211 if ( parser
.Found(_T("s"), &lVal
) )
212 s
<< _T("Size:\t") << lVal
<< '\n';
213 if ( parser
.Found(_T("f"), &dVal
) )
214 s
<< _T("Double:\t") << dVal
<< '\n';
215 if ( parser
.Found(_T("d"), &dt
) )
216 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
217 if ( parser
.Found(_T("project_name"), &strVal
) )
218 s
<< _T("Project:\t") << strVal
<< '\n';
223 #endif // wxUSE_CMDLINE_PARSER
225 static void TestCmdLineConvert()
227 static const wxChar
*cmdlines
[] =
230 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
231 _T("literal \\\" and \"\""),
234 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
236 const wxChar
*cmdline
= cmdlines
[n
];
237 wxPrintf(_T("Parsing: %s\n"), cmdline
);
238 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
240 size_t count
= args
.GetCount();
241 wxPrintf(_T("\targc = %u\n"), count
);
242 for ( size_t arg
= 0; arg
< count
; arg
++ )
244 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
249 #endif // TEST_CMDLINE
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
260 static const wxChar
*ROOTDIR
= _T("/");
261 static const wxChar
*TESTDIR
= _T("/usr/local/share");
262 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
263 static const wxChar
*ROOTDIR
= _T("c:\\");
264 static const wxChar
*TESTDIR
= _T("d:\\");
266 #error "don't know where the root directory is"
269 static void TestDirEnumHelper(wxDir
& dir
,
270 int flags
= wxDIR_DEFAULT
,
271 const wxString
& filespec
= wxEmptyString
)
275 if ( !dir
.IsOpened() )
278 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
281 wxPrintf(_T("\t%s\n"), filename
.c_str());
283 cont
= dir
.GetNext(&filename
);
286 wxPuts(wxEmptyString
);
291 static void TestDirEnum()
293 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
295 wxString cwd
= wxGetCwd();
296 if ( !wxDir::Exists(cwd
) )
298 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
303 if ( !dir
.IsOpened() )
305 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
309 wxPuts(_T("Enumerating everything in current directory:"));
310 TestDirEnumHelper(dir
);
312 wxPuts(_T("Enumerating really everything in current directory:"));
313 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
315 wxPuts(_T("Enumerating object files in current directory:"));
316 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
318 wxPuts(_T("Enumerating directories in current directory:"));
319 TestDirEnumHelper(dir
, wxDIR_DIRS
);
321 wxPuts(_T("Enumerating files in current directory:"));
322 TestDirEnumHelper(dir
, wxDIR_FILES
);
324 wxPuts(_T("Enumerating files including hidden in current directory:"));
325 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
329 wxPuts(_T("Enumerating everything in root directory:"));
330 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
332 wxPuts(_T("Enumerating directories in root directory:"));
333 TestDirEnumHelper(dir
, wxDIR_DIRS
);
335 wxPuts(_T("Enumerating files in root directory:"));
336 TestDirEnumHelper(dir
, wxDIR_FILES
);
338 wxPuts(_T("Enumerating files including hidden in root directory:"));
339 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
341 wxPuts(_T("Enumerating files in non existing directory:"));
342 wxDir
dirNo(_T("nosuchdir"));
343 TestDirEnumHelper(dirNo
);
348 class DirPrintTraverser
: public wxDirTraverser
351 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
353 return wxDIR_CONTINUE
;
356 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
358 wxString path
, name
, ext
;
359 wxFileName::SplitPath(dirname
, &path
, &name
, &ext
);
362 name
<< _T('.') << ext
;
365 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
367 if ( wxIsPathSeparator(*p
) )
371 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
373 return wxDIR_CONTINUE
;
377 static void TestDirTraverse()
379 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
383 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
384 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
387 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
388 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
391 // enum again with custom traverser
392 wxPuts(_T("Now enumerating directories:"));
394 DirPrintTraverser traverser
;
395 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
400 static void TestDirExists()
402 wxPuts(_T("*** Testing wxDir::Exists() ***"));
404 static const wxChar
*dirnames
[] =
407 #if defined(__WXMSW__)
410 _T("\\\\share\\file"),
414 _T("c:\\autoexec.bat"),
415 #elif defined(__UNIX__)
424 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
426 wxPrintf(_T("%-40s: %s\n"),
428 wxDir::Exists(dirnames
[n
]) ? _T("exists")
429 : _T("doesn't exist"));
437 // ----------------------------------------------------------------------------
439 // ----------------------------------------------------------------------------
443 #include "wx/dynlib.h"
445 static void TestDllLoad()
447 #if defined(__WXMSW__)
448 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
449 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
450 #elif defined(__UNIX__)
451 // weird: using just libc.so does *not* work!
452 static const wxChar
*LIB_NAME
= _T("/lib/libc.so.6");
453 static const wxChar
*FUNC_NAME
= _T("strlen");
455 #error "don't know how to test wxDllLoader on this platform"
458 wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
460 wxDynamicLibrary
lib(LIB_NAME
);
461 if ( !lib
.IsLoaded() )
463 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
467 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
468 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
471 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
472 FUNC_NAME
, LIB_NAME
);
476 wxPrintf(_T("Calling %s dynamically loaded from %s "),
477 FUNC_NAME
, LIB_NAME
);
479 if ( pfnStrlen("foo") != 3 )
481 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
485 wxPuts(_T("... ok"));
490 static const wxChar
*FUNC_NAME_AW
= _T("lstrlen");
492 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
494 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
495 if ( !pfnStrlenAorW
)
497 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
498 FUNC_NAME_AW
, LIB_NAME
);
502 if ( pfnStrlenAorW(_T("foobar")) != 6 )
504 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
511 #if defined(__WXMSW__) || defined(__UNIX__)
513 static void TestDllListLoaded()
515 wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
517 puts("\nLoaded modules:");
518 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
519 const size_t count
= dlls
.GetCount();
520 for ( size_t n
= 0; n
< count
; ++n
)
522 const wxDynamicLibraryDetails
& details
= dlls
[n
];
523 printf("%-45s", (const char *)details
.GetPath().mb_str());
527 if ( details
.GetAddress(&addr
, &len
) )
529 printf(" %08lx:%08lx",
530 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
533 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
539 #endif // TEST_DYNLIB
541 // ----------------------------------------------------------------------------
543 // ----------------------------------------------------------------------------
547 #include "wx/utils.h"
549 static wxString
MyGetEnv(const wxString
& var
)
552 if ( !wxGetEnv(var
, &val
) )
555 val
= wxString(_T('\'')) + val
+ _T('\'');
560 static void TestEnvironment()
562 const wxChar
*var
= _T("wxTestVar");
564 wxPuts(_T("*** testing environment access functions ***"));
566 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
567 wxSetEnv(var
, _T("value for wxTestVar"));
568 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
569 wxSetEnv(var
, _T("another value"));
570 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
572 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
573 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
576 #endif // TEST_ENVIRON
578 // ----------------------------------------------------------------------------
580 // ----------------------------------------------------------------------------
584 #include "wx/utils.h"
586 static void TestExecute()
588 wxPuts(_T("*** testing wxExecute ***"));
591 #define COMMAND "echo hi"
592 #define ASYNC_COMMAND "xclock"
593 #define SHELL_COMMAND "echo hi from shell"
594 #define REDIRECT_COMMAND "cat -n Makefile"
595 #elif defined(__WXMSW__)
596 #define COMMAND "command.com /c echo hi"
597 #define ASYNC_COMMAND "notepad"
598 #define SHELL_COMMAND "echo hi"
599 #define REDIRECT_COMMAND COMMAND
601 #error "no command to exec"
604 wxPrintf(_T("Testing wxShell: "));
606 if ( wxShell(_T(SHELL_COMMAND
)) )
609 wxPuts(_T("ERROR."));
611 wxPrintf(_T("Testing wxExecute: "));
613 if ( wxExecute(_T(COMMAND
), wxEXEC_SYNC
) == 0 )
616 wxPuts(_T("ERROR."));
618 wxPrintf(_T("Testing async wxExecute: "));
620 int pid
= wxExecute(ASYNC_COMMAND
);
623 wxPuts(_T("Ok (command launched)."));
624 if ( wxKill(pid
) == -1 )
625 wxPuts("ERROR: failed to kill child process.");
628 wxPuts(_T("ERROR."));
630 wxPrintf(_T("Testing wxExecute with redirection:\n"));
631 wxArrayString output
;
632 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
634 wxPuts(_T("ERROR."));
638 // don't show too much output, MAX_LINES is enough
639 static const unsigned MAX_LINES
= 20;
641 const unsigned count
= output
.size();
642 for ( unsigned n
= 0;
643 n
< (count
> MAX_LINES
? MAX_LINES
/2 : count
);
646 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
649 if ( count
> MAX_LINES
)
651 wxPrintf("... skipping %u lines...\n", count
- MAX_LINES
);
653 for ( unsigned n
= count
- MAX_LINES
/2; n
< count
; n
++ )
655 wxPrintf("%04u:\t%s\n", n
+ 1, output
[n
]);
663 #endif // TEST_EXECUTE
665 // ----------------------------------------------------------------------------
667 // ----------------------------------------------------------------------------
672 #include "wx/ffile.h"
673 #include "wx/textfile.h"
675 static void TestFileRead()
677 wxPuts(_T("*** wxFile read test ***"));
679 wxFile
file(_T("testdata.fc"));
680 if ( file
.IsOpened() )
682 wxPrintf(_T("File length: %lu\n"), file
.Length());
684 wxPuts(_T("File dump:\n----------"));
686 static const size_t len
= 1024;
690 size_t nRead
= file
.Read(buf
, len
);
691 if ( nRead
== (size_t)wxInvalidOffset
)
693 wxPrintf(_T("Failed to read the file."));
697 fwrite(buf
, nRead
, 1, stdout
);
703 wxPuts(_T("----------"));
707 wxPrintf(_T("ERROR: can't open test file.\n"));
710 wxPuts(wxEmptyString
);
713 static void TestTextFileRead()
715 wxPuts(_T("*** wxTextFile read test ***"));
717 wxTextFile
file(_T("testdata.fc"));
720 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
721 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
725 wxPuts(_T("\nDumping the entire file:"));
726 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
728 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
730 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
732 wxPuts(_T("\nAnd now backwards:"));
733 for ( s
= file
.GetLastLine();
734 file
.GetCurrentLine() != 0;
735 s
= file
.GetPrevLine() )
737 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
739 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
743 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
746 wxPuts(wxEmptyString
);
749 static void TestFileCopy()
751 wxPuts(_T("*** Testing wxCopyFile ***"));
753 static const wxChar
*filename1
= _T("testdata.fc");
754 static const wxChar
*filename2
= _T("test2");
755 if ( !wxCopyFile(filename1
, filename2
) )
757 wxPuts(_T("ERROR: failed to copy file"));
761 wxFFile
f1(filename1
, _T("rb")),
762 f2(filename2
, _T("rb"));
764 if ( !f1
.IsOpened() || !f2
.IsOpened() )
766 wxPuts(_T("ERROR: failed to open file(s)"));
771 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
773 wxPuts(_T("ERROR: failed to read file(s)"));
777 if ( (s1
.length() != s2
.length()) ||
778 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
780 wxPuts(_T("ERROR: copy error!"));
784 wxPuts(_T("File was copied ok."));
790 if ( !wxRemoveFile(filename2
) )
792 wxPuts(_T("ERROR: failed to remove the file"));
795 wxPuts(wxEmptyString
);
798 static void TestTempFile()
800 wxPuts(_T("*** wxTempFile test ***"));
803 if ( tmpFile
.Open(_T("test2")) && tmpFile
.Write(_T("the answer is 42")) )
805 if ( tmpFile
.Commit() )
806 wxPuts(_T("File committed."));
808 wxPuts(_T("ERROR: could't commit temp file."));
810 wxRemoveFile(_T("test2"));
813 wxPuts(wxEmptyString
);
818 // ----------------------------------------------------------------------------
820 // ----------------------------------------------------------------------------
824 #include "wx/confbase.h"
825 #include "wx/fileconf.h"
827 static const struct FileConfTestData
829 const wxChar
*name
; // value name
830 const wxChar
*value
; // the value from the file
833 { _T("value1"), _T("one") },
834 { _T("value2"), _T("two") },
835 { _T("novalue"), _T("default") },
838 static void TestFileConfRead()
840 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
842 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
843 _T("testdata.fc"), wxEmptyString
,
844 wxCONFIG_USE_RELATIVE_PATH
);
846 // test simple reading
847 wxPuts(_T("\nReading config file:"));
848 wxString
defValue(_T("default")), value
;
849 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
851 const FileConfTestData
& data
= fcTestData
[n
];
852 value
= fileconf
.Read(data
.name
, defValue
);
853 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
854 if ( value
== data
.value
)
860 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
864 // test enumerating the entries
865 wxPuts(_T("\nEnumerating all root entries:"));
868 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
871 wxPrintf(_T("\t%s = %s\n"),
873 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
875 cont
= fileconf
.GetNextEntry(name
, dummy
);
878 static const wxChar
*testEntry
= _T("TestEntry");
879 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
880 fileconf
.Write(testEntry
, _T("A value"));
881 fileconf
.DeleteEntry(testEntry
);
882 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
885 #endif // TEST_FILECONF
887 // ----------------------------------------------------------------------------
889 // ----------------------------------------------------------------------------
893 #include "wx/filename.h"
896 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
900 wxString full
= fn
.GetFullPath();
902 wxString vol
, path
, name
, ext
;
903 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
905 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
906 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
908 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
909 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
910 path
.c_str(), name
.c_str(), ext
.c_str());
912 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
913 wxPrintf(_T("with volume: \t'%s'\n"),
914 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
915 wxPrintf(_T("with separator:\t'%s'\n"),
916 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
917 wxPrintf(_T("with both: \t'%s'\n"),
918 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
920 wxPuts(_T("The directories in the path are:"));
921 wxArrayString dirs
= fn
.GetDirs();
922 size_t count
= dirs
.GetCount();
923 for ( size_t n
= 0; n
< count
; n
++ )
925 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
930 static void TestFileNameTemp()
932 wxPuts(_T("*** testing wxFileName temp file creation ***"));
934 static const wxChar
*tmpprefixes
[] =
942 _T("/tmp/foo/bar"), // this one must be an error
946 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
948 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
951 // "error" is not in upper case because it may be ok
952 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
956 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
957 tmpprefixes
[n
], path
.c_str());
959 if ( !wxRemoveFile(path
) )
961 wxLogWarning(_T("Failed to remove temp file '%s'"),
968 static void TestFileNameDirManip()
970 // TODO: test AppendDir(), RemoveDir(), ...
973 static void TestFileNameComparison()
978 static void TestFileNameOperations()
983 static void TestFileNameCwd()
988 #endif // TEST_FILENAME
990 // ----------------------------------------------------------------------------
991 // wxFileName time functions
992 // ----------------------------------------------------------------------------
996 #include "wx/filename.h"
997 #include "wx/datetime.h"
999 static void TestFileGetTimes()
1001 wxFileName
fn(_T("testdata.fc"));
1003 wxDateTime dtAccess
, dtMod
, dtCreate
;
1004 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
1006 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
1010 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
1012 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
1013 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
1014 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
1015 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
1020 static void TestFileSetTimes()
1022 wxFileName
fn(_T("testdata.fc"));
1026 wxPrintf(_T("ERROR: Touch() failed.\n"));
1031 #endif // TEST_FILETIME
1033 // ----------------------------------------------------------------------------
1035 // ----------------------------------------------------------------------------
1039 #include "wx/intl.h"
1040 #include "wx/utils.h" // for wxSetEnv
1042 static wxLocale gs_localeDefault
;
1043 // NOTE: don't init it here as it needs a wxAppTraits object
1044 // and thus must be init-ed after creation of the wxInitializer
1045 // class in the main()
1047 // find the name of the language from its value
1048 static const wxChar
*GetLangName(int lang
)
1050 static const wxChar
*languageNames
[] =
1060 _T("ARABIC_ALGERIA"),
1061 _T("ARABIC_BAHRAIN"),
1064 _T("ARABIC_JORDAN"),
1065 _T("ARABIC_KUWAIT"),
1066 _T("ARABIC_LEBANON"),
1068 _T("ARABIC_MOROCCO"),
1071 _T("ARABIC_SAUDI_ARABIA"),
1074 _T("ARABIC_TUNISIA"),
1081 _T("AZERI_CYRILLIC"),
1096 _T("CHINESE_SIMPLIFIED"),
1097 _T("CHINESE_TRADITIONAL"),
1098 _T("CHINESE_HONGKONG"),
1099 _T("CHINESE_MACAU"),
1100 _T("CHINESE_SINGAPORE"),
1101 _T("CHINESE_TAIWAN"),
1107 _T("DUTCH_BELGIAN"),
1111 _T("ENGLISH_AUSTRALIA"),
1112 _T("ENGLISH_BELIZE"),
1113 _T("ENGLISH_BOTSWANA"),
1114 _T("ENGLISH_CANADA"),
1115 _T("ENGLISH_CARIBBEAN"),
1116 _T("ENGLISH_DENMARK"),
1118 _T("ENGLISH_JAMAICA"),
1119 _T("ENGLISH_NEW_ZEALAND"),
1120 _T("ENGLISH_PHILIPPINES"),
1121 _T("ENGLISH_SOUTH_AFRICA"),
1122 _T("ENGLISH_TRINIDAD"),
1123 _T("ENGLISH_ZIMBABWE"),
1131 _T("FRENCH_BELGIAN"),
1132 _T("FRENCH_CANADIAN"),
1133 _T("FRENCH_LUXEMBOURG"),
1134 _T("FRENCH_MONACO"),
1140 _T("GERMAN_AUSTRIAN"),
1141 _T("GERMAN_BELGIUM"),
1142 _T("GERMAN_LIECHTENSTEIN"),
1143 _T("GERMAN_LUXEMBOURG"),
1161 _T("ITALIAN_SWISS"),
1166 _T("KASHMIRI_INDIA"),
1184 _T("MALAY_BRUNEI_DARUSSALAM"),
1185 _T("MALAY_MALAYSIA"),
1195 _T("NORWEGIAN_BOKMAL"),
1196 _T("NORWEGIAN_NYNORSK"),
1203 _T("PORTUGUESE_BRAZILIAN"),
1206 _T("RHAETO_ROMANCE"),
1209 _T("RUSSIAN_UKRAINE"),
1215 _T("SERBIAN_CYRILLIC"),
1216 _T("SERBIAN_LATIN"),
1217 _T("SERBO_CROATIAN"),
1228 _T("SPANISH_ARGENTINA"),
1229 _T("SPANISH_BOLIVIA"),
1230 _T("SPANISH_CHILE"),
1231 _T("SPANISH_COLOMBIA"),
1232 _T("SPANISH_COSTA_RICA"),
1233 _T("SPANISH_DOMINICAN_REPUBLIC"),
1234 _T("SPANISH_ECUADOR"),
1235 _T("SPANISH_EL_SALVADOR"),
1236 _T("SPANISH_GUATEMALA"),
1237 _T("SPANISH_HONDURAS"),
1238 _T("SPANISH_MEXICAN"),
1239 _T("SPANISH_MODERN"),
1240 _T("SPANISH_NICARAGUA"),
1241 _T("SPANISH_PANAMA"),
1242 _T("SPANISH_PARAGUAY"),
1244 _T("SPANISH_PUERTO_RICO"),
1245 _T("SPANISH_URUGUAY"),
1247 _T("SPANISH_VENEZUELA"),
1251 _T("SWEDISH_FINLAND"),
1269 _T("URDU_PAKISTAN"),
1271 _T("UZBEK_CYRILLIC"),
1284 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1285 return languageNames
[lang
];
1287 return _T("INVALID");
1290 static void TestDefaultLang()
1292 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1294 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1296 static const wxChar
*langStrings
[] =
1298 NULL
, // system default
1305 _T("de_DE.iso88591"),
1307 _T("?"), // invalid lang spec
1308 _T("klingonese"), // I bet on some systems it does exist...
1311 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1312 wxLocale::GetSystemEncodingName().c_str(),
1313 wxLocale::GetSystemEncoding());
1315 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1317 const wxChar
*langStr
= langStrings
[n
];
1320 // FIXME: this doesn't do anything at all under Windows, we need
1321 // to create a new wxLocale!
1322 wxSetEnv(_T("LC_ALL"), langStr
);
1325 int lang
= gs_localeDefault
.GetSystemLanguage();
1326 wxPrintf(_T("Locale for '%s' is %s.\n"),
1327 langStr
? langStr
: _T("system default"), GetLangName(lang
));
1331 #endif // TEST_LOCALE
1333 // ----------------------------------------------------------------------------
1335 // ----------------------------------------------------------------------------
1339 #include "wx/mimetype.h"
1341 static void TestMimeEnum()
1343 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1345 wxArrayString mimetypes
;
1347 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1349 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1354 for ( size_t n
= 0; n
< count
; n
++ )
1356 wxFileType
*filetype
=
1357 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1360 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1361 mimetypes
[n
].c_str());
1365 filetype
->GetDescription(&desc
);
1366 filetype
->GetExtensions(exts
);
1368 filetype
->GetIcon(NULL
);
1371 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1374 extsAll
<< _T(", ");
1378 wxPrintf(_T("\t%s: %s (%s)\n"),
1379 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1382 wxPuts(wxEmptyString
);
1385 static void TestMimeFilename()
1387 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1389 static const wxChar
*filenames
[] =
1397 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1399 const wxString fname
= filenames
[n
];
1400 wxString ext
= fname
.AfterLast(_T('.'));
1401 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1404 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1409 if ( !ft
->GetDescription(&desc
) )
1410 desc
= _T("<no description>");
1413 if ( !ft
->GetOpenCommand(&cmd
,
1414 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1415 cmd
= _T("<no command available>");
1417 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1419 wxPrintf(_T("To open %s (%s) do %s.\n"),
1420 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1426 wxPuts(wxEmptyString
);
1429 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1432 static void TestMimeOverride()
1434 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1436 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1437 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1439 if ( wxFile::Exists(mailcap
) )
1440 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1442 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1444 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1447 if ( wxFile::Exists(mimetypes
) )
1448 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1450 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1452 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1455 wxPuts(wxEmptyString
);
1458 static void TestMimeAssociate()
1460 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1462 wxFileTypeInfo
ftInfo(
1463 _T("application/x-xyz"),
1464 _T("xyzview '%s'"), // open cmd
1465 _T(""), // print cmd
1466 _T("XYZ File"), // description
1467 _T(".xyz"), // extensions
1468 wxNullPtr
// end of extensions
1470 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1472 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1475 wxPuts(_T("ERROR: failed to create association!"));
1479 // TODO: read it back
1483 wxPuts(wxEmptyString
);
1490 // ----------------------------------------------------------------------------
1491 // module dependencies feature
1492 // ----------------------------------------------------------------------------
1496 #include "wx/module.h"
1498 class wxTestModule
: public wxModule
1501 virtual bool OnInit() { wxPrintf(_T("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1502 virtual void OnExit() { wxPrintf(_T("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1505 class wxTestModuleA
: public wxTestModule
1510 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1513 class wxTestModuleB
: public wxTestModule
1518 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1521 class wxTestModuleC
: public wxTestModule
1526 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1529 class wxTestModuleD
: public wxTestModule
1534 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1537 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1538 wxTestModuleC::wxTestModuleC()
1540 AddDependency(CLASSINFO(wxTestModuleD
));
1543 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1544 wxTestModuleA::wxTestModuleA()
1546 AddDependency(CLASSINFO(wxTestModuleB
));
1547 AddDependency(CLASSINFO(wxTestModuleD
));
1550 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1551 wxTestModuleD::wxTestModuleD()
1555 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1556 wxTestModuleB::wxTestModuleB()
1558 AddDependency(CLASSINFO(wxTestModuleD
));
1559 AddDependency(CLASSINFO(wxTestModuleC
));
1562 #endif // TEST_MODULE
1564 // ----------------------------------------------------------------------------
1565 // misc information functions
1566 // ----------------------------------------------------------------------------
1568 #ifdef TEST_INFO_FUNCTIONS
1570 #include "wx/utils.h"
1572 #if TEST_INTERACTIVE
1573 static void TestDiskInfo()
1575 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1579 wxChar pathname
[128];
1580 wxPrintf(_T("\nEnter a directory name: "));
1581 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1584 // kill the last '\n'
1585 pathname
[wxStrlen(pathname
) - 1] = 0;
1587 wxLongLong total
, free
;
1588 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1590 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1594 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1595 (total
/ 1024).ToString().c_str(),
1596 (free
/ 1024).ToString().c_str(),
1601 #endif // TEST_INTERACTIVE
1603 static void TestOsInfo()
1605 wxPuts(_T("*** Testing OS info functions ***\n"));
1608 wxGetOsVersion(&major
, &minor
);
1609 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1610 wxGetOsDescription().c_str(), major
, minor
);
1612 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1614 wxPrintf(_T("Host name is %s (%s).\n"),
1615 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1617 wxPuts(wxEmptyString
);
1620 static void TestPlatformInfo()
1622 wxPuts(_T("*** Testing wxPlatformInfo functions ***\n"));
1624 // get this platform
1625 wxPlatformInfo plat
;
1627 wxPrintf(_T("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1628 wxPrintf(_T("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1629 wxPrintf(_T("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1630 wxPrintf(_T("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1631 wxPrintf(_T("Architecture is: %s\n"), plat
.GetArchName().c_str());
1632 wxPrintf(_T("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1634 wxPuts(wxEmptyString
);
1637 static void TestUserInfo()
1639 wxPuts(_T("*** Testing user info functions ***\n"));
1641 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1642 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1643 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1644 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1646 wxPuts(wxEmptyString
);
1649 #endif // TEST_INFO_FUNCTIONS
1651 // ----------------------------------------------------------------------------
1653 // ----------------------------------------------------------------------------
1655 #ifdef TEST_PATHLIST
1658 #define CMD_IN_PATH _T("ls")
1660 #define CMD_IN_PATH _T("command.com")
1663 static void TestPathList()
1665 wxPuts(_T("*** Testing wxPathList ***\n"));
1667 wxPathList pathlist
;
1668 pathlist
.AddEnvList(_T("PATH"));
1669 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1672 wxPrintf(_T("ERROR: command not found in the path.\n"));
1676 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
1680 #endif // TEST_PATHLIST
1682 // ----------------------------------------------------------------------------
1683 // regular expressions
1684 // ----------------------------------------------------------------------------
1688 #include "wx/regex.h"
1690 static void TestRegExInteractive()
1692 wxPuts(_T("*** Testing RE interactively ***"));
1696 wxChar pattern
[128];
1697 wxPrintf(_T("\nEnter a pattern: "));
1698 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1701 // kill the last '\n'
1702 pattern
[wxStrlen(pattern
) - 1] = 0;
1705 if ( !re
.Compile(pattern
) )
1713 wxPrintf(_T("Enter text to match: "));
1714 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1717 // kill the last '\n'
1718 text
[wxStrlen(text
) - 1] = 0;
1720 if ( !re
.Matches(text
) )
1722 wxPrintf(_T("No match.\n"));
1726 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1729 for ( size_t n
= 1; ; n
++ )
1731 if ( !re
.GetMatch(&start
, &len
, n
) )
1736 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1737 n
, wxString(text
+ start
, len
).c_str());
1744 #endif // TEST_REGEX
1746 // ----------------------------------------------------------------------------
1748 // ----------------------------------------------------------------------------
1751 NB: this stuff was taken from the glibc test suite and modified to build
1752 in wxWidgets: if I read the copyright below properly, this shouldn't
1758 #ifdef wxTEST_PRINTF
1759 // use our functions from wxchar.cpp
1763 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1764 // in the tests below
1765 int wxPrintf( const wxChar
*format
, ... );
1766 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1769 #include "wx/longlong.h"
1773 static void rfg1 (void);
1774 static void rfg2 (void);
1778 fmtchk (const wxChar
*fmt
)
1780 (void) wxPrintf(_T("%s:\t`"), fmt
);
1781 (void) wxPrintf(fmt
, 0x12);
1782 (void) wxPrintf(_T("'\n"));
1786 fmtst1chk (const wxChar
*fmt
)
1788 (void) wxPrintf(_T("%s:\t`"), fmt
);
1789 (void) wxPrintf(fmt
, 4, 0x12);
1790 (void) wxPrintf(_T("'\n"));
1794 fmtst2chk (const wxChar
*fmt
)
1796 (void) wxPrintf(_T("%s:\t`"), fmt
);
1797 (void) wxPrintf(fmt
, 4, 4, 0x12);
1798 (void) wxPrintf(_T("'\n"));
1801 /* This page is covered by the following copyright: */
1803 /* (C) Copyright C E Chew
1805 * Feel free to copy, use and distribute this software provided:
1807 * 1. you do not pretend that you wrote it
1808 * 2. you leave this copyright notice intact.
1812 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1819 /* Formatted Output Test
1821 * This exercises the output formatting code.
1824 wxChar
*PointerNull
= NULL
;
1831 wxChar
*prefix
= buf
;
1834 wxPuts(_T("\nFormatted output test"));
1835 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
1836 wxStrcpy(prefix
, _T("%"));
1837 for (i
= 0; i
< 2; i
++) {
1838 for (j
= 0; j
< 2; j
++) {
1839 for (k
= 0; k
< 2; k
++) {
1840 for (l
= 0; l
< 2; l
++) {
1841 wxStrcpy(prefix
, _T("%"));
1842 if (i
== 0) wxStrcat(prefix
, _T("-"));
1843 if (j
== 0) wxStrcat(prefix
, _T("+"));
1844 if (k
== 0) wxStrcat(prefix
, _T("#"));
1845 if (l
== 0) wxStrcat(prefix
, _T("0"));
1846 wxPrintf(_T("%5s |"), prefix
);
1847 wxStrcpy(tp
, prefix
);
1848 wxStrcat(tp
, _T("6d |"));
1850 wxStrcpy(tp
, prefix
);
1851 wxStrcat(tp
, _T("6o |"));
1853 wxStrcpy(tp
, prefix
);
1854 wxStrcat(tp
, _T("6x |"));
1856 wxStrcpy(tp
, prefix
);
1857 wxStrcat(tp
, _T("6X |"));
1859 wxStrcpy(tp
, prefix
);
1860 wxStrcat(tp
, _T("6u |"));
1867 wxPrintf(_T("%10s\n"), PointerNull
);
1868 wxPrintf(_T("%-10s\n"), PointerNull
);
1871 static void TestPrintf()
1873 static wxChar shortstr
[] = _T("Hi, Z.");
1874 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
1875 I am ready for my first lesson today.");
1877 wxString test_format
;
1881 fmtchk(_T("%4.4x"));
1882 fmtchk(_T("%04.4x"));
1883 fmtchk(_T("%4.3x"));
1884 fmtchk(_T("%04.3x"));
1886 fmtst1chk(_T("%.*x"));
1887 fmtst1chk(_T("%0*x"));
1888 fmtst2chk(_T("%*.*x"));
1889 fmtst2chk(_T("%0*.*x"));
1891 wxString bad_format
= _T("bad format:\t\"%b\"\n");
1892 wxPrintf(bad_format
.c_str());
1893 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1895 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
1896 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
1897 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
1898 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
1899 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
1900 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1901 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1902 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
1903 wxPrintf(test_format
.c_str(), -123456);
1904 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1905 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1907 test_format
= _T("zero-padded string:\t\"%010s\"\n");
1908 wxPrintf(test_format
.c_str(), shortstr
);
1909 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
1910 wxPrintf(test_format
.c_str(), shortstr
);
1911 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
1912 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1913 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
1914 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
1916 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
1917 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
1918 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
1919 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
1920 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
1921 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
1922 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
1923 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
1924 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
1925 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
1926 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
1927 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
1929 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
1930 wxPrintf (_T(" %6.5f\n"), .1);
1931 wxPrintf (_T("x%5.4fx\n"), .5);
1933 wxPrintf (_T("%#03x\n"), 1);
1935 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
1941 while (niter
-- != 0)
1942 wxPrintf (_T("%.17e\n"), d
/ 2);
1947 // Open Watcom cause compiler error here
1948 // Error! E173: col(24) floating-point constant too small to represent
1949 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
1952 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
1953 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1954 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1955 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1956 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1957 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1958 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1959 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1960 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1961 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1966 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
1968 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1969 rc
, WXSIZEOF(buf
), buf
);
1972 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1973 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1979 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
1980 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
1981 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
1982 wxPrintf (_T("%g should be 123.456\n"), 123.456);
1983 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
1984 wxPrintf (_T("%g should be 10\n"), 10.0);
1985 wxPrintf (_T("%g should be 0.02\n"), 0.02);
1989 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1995 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
1997 result
|= wxStrcmp (buf
,
1998 _T("onetwo three "));
2000 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
2007 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
2009 // for some reason below line fails under Borland
2010 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
2013 if (wxStrcmp (buf
, _T("40000000000")) != 0)
2016 wxPuts (_T("\tFAILED"));
2018 wxUnusedVar(result
);
2019 wxPuts (wxEmptyString
);
2021 #endif // wxLongLong_t
2023 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
2024 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
2026 wxPuts (_T("--- Should be no further output. ---"));
2035 memset (bytes
, '\xff', sizeof bytes
);
2036 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
2037 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
2038 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
2040 wxPuts (_T("%hhn overwrite more bytes"));
2045 wxPuts (_T("%hhn wrote incorrect value"));
2057 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2058 if (wxStrcmp (buf
, _T(" ")) != 0)
2059 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2060 wxSprintf (buf
, _T("%5.f"), 33.3);
2061 if (wxStrcmp (buf
, _T(" 33")) != 0)
2062 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2063 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2064 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2065 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2066 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2067 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2068 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2069 wxSprintf (buf
, _T("%.g"), 33.3);
2070 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2071 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2072 wxSprintf (buf
, _T("%.G"), 33.3);
2073 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2074 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2082 wxString test_format
;
2085 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2086 if (wxStrcmp (buf
, _T("3")) != 0)
2087 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2089 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2090 if (wxStrcmp (buf
, _T("3")) != 0)
2091 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2093 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2094 if (wxStrcmp (buf
, _T(" 3")) != 0)
2095 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2097 test_format
= _T("%04.*o");
2098 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2099 if (wxStrcmp (buf
, _T(" 041")) != 0)
2100 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2102 test_format
= _T("%09.*u");
2103 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2104 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2105 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2107 test_format
= _T("%04.*x");
2108 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2109 if (wxStrcmp (buf
, _T(" 021")) != 0)
2110 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2112 test_format
= _T("%04.*X");
2113 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2114 if (wxStrcmp (buf
, _T(" 021")) != 0)
2115 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2118 #endif // TEST_PRINTF
2120 // ----------------------------------------------------------------------------
2121 // registry and related stuff
2122 // ----------------------------------------------------------------------------
2124 // this is for MSW only
2127 #undef TEST_REGISTRY
2132 #include "wx/confbase.h"
2133 #include "wx/msw/regconf.h"
2136 static void TestRegConfWrite()
2138 wxConfig
*config
= new wxConfig(_T("myapp"));
2139 config
->SetPath(_T("/group1"));
2140 config
->Write(_T("entry1"), _T("foo"));
2141 config
->SetPath(_T("/group2"));
2142 config
->Write(_T("entry1"), _T("bar"));
2146 static void TestRegConfRead()
2148 wxRegConfig
*config
= new wxRegConfig(_T("myapp"));
2152 config
->SetPath(_T("/"));
2153 wxPuts(_T("Enumerating / subgroups:"));
2154 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2158 bCont
= config
->GetNextGroup(str
, dummy
);
2162 #endif // TEST_REGCONF
2164 #ifdef TEST_REGISTRY
2166 #include "wx/msw/registry.h"
2168 // I chose this one because I liked its name, but it probably only exists under
2170 static const wxChar
*TESTKEY
=
2171 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2173 static void TestRegistryRead()
2175 wxPuts(_T("*** testing registry reading ***"));
2177 wxRegKey
key(TESTKEY
);
2178 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2181 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2186 size_t nSubKeys
, nValues
;
2187 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2189 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2192 wxPrintf(_T("Enumerating values:\n"));
2196 bool cont
= key
.GetFirstValue(value
, dummy
);
2199 wxPrintf(_T("Value '%s': type "), value
.c_str());
2200 switch ( key
.GetValueType(value
) )
2202 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2203 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
2204 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2205 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
2206 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
2207 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2208 default: wxPrintf(_T("other (unknown)")); break;
2211 wxPrintf(_T(", value = "));
2212 if ( key
.IsNumericValue(value
) )
2215 key
.QueryValue(value
, &val
);
2216 wxPrintf(_T("%ld"), val
);
2221 key
.QueryValue(value
, val
);
2222 wxPrintf(_T("'%s'"), val
.c_str());
2224 key
.QueryRawValue(value
, val
);
2225 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2230 cont
= key
.GetNextValue(value
, dummy
);
2234 static void TestRegistryAssociation()
2237 The second call to deleteself genertaes an error message, with a
2238 messagebox saying .flo is crucial to system operation, while the .ddf
2239 call also fails, but with no error message
2244 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2246 key
= _T("ddxf_auto_file") ;
2247 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2249 key
= _T("ddxf_auto_file") ;
2250 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2252 key
= _T("program,0") ;
2253 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2255 key
= _T("program \"%1\"") ;
2257 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2259 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2261 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2263 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2267 #endif // TEST_REGISTRY
2269 // ----------------------------------------------------------------------------
2271 // ----------------------------------------------------------------------------
2273 #ifdef TEST_SCOPEGUARD
2275 #include "wx/scopeguard.h"
2277 static void function0() { puts("function0()"); }
2278 static void function1(int n
) { printf("function1(%d)\n", n
); }
2279 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2283 void method0() { printf("method0()\n"); }
2284 void method1(int n
) { printf("method1(%d)\n", n
); }
2285 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2288 static void TestScopeGuard()
2290 wxON_BLOCK_EXIT0(function0
);
2291 wxON_BLOCK_EXIT1(function1
, 17);
2292 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2295 wxON_BLOCK_EXIT_OBJ0(obj
, Object::method0
);
2296 wxON_BLOCK_EXIT_OBJ1(obj
, Object::method1
, 7);
2297 wxON_BLOCK_EXIT_OBJ2(obj
, Object::method2
, 2.71, 'e');
2299 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2300 dismissed
.Dismiss();
2305 // ----------------------------------------------------------------------------
2307 // ----------------------------------------------------------------------------
2311 #include "wx/socket.h"
2312 #include "wx/protocol/protocol.h"
2313 #include "wx/protocol/http.h"
2315 static void TestSocketServer()
2317 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2319 static const int PORT
= 3000;
2324 wxSocketServer
*server
= new wxSocketServer(addr
);
2325 if ( !server
->Ok() )
2327 wxPuts(_T("ERROR: failed to bind"));
2335 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2337 wxSocketBase
*socket
= server
->Accept();
2340 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2344 wxPuts(_T("Server: got a client."));
2346 server
->SetTimeout(60); // 1 min
2349 while ( !close
&& socket
->IsConnected() )
2352 wxChar ch
= _T('\0');
2355 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2357 // don't log error if the client just close the connection
2358 if ( socket
->IsConnected() )
2360 wxPuts(_T("ERROR: in wxSocket::Read."));
2380 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2381 if ( s
== _T("close") )
2383 wxPuts(_T("Closing connection"));
2387 else if ( s
== _T("quit") )
2392 wxPuts(_T("Shutting down the server"));
2394 else // not a special command
2396 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2397 socket
->Write("\r\n", 2);
2398 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
2404 wxPuts(_T("Server: lost a client unexpectedly."));
2410 // same as "delete server" but is consistent with GUI programs
2414 static void TestSocketClient()
2416 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2418 static const wxChar
*hostname
= _T("www.wxwidgets.org");
2421 addr
.Hostname(hostname
);
2424 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
2426 wxSocketClient client
;
2427 if ( !client
.Connect(addr
) )
2429 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2433 wxPrintf(_T("--- Connected to %s:%u...\n"),
2434 addr
.Hostname().c_str(), addr
.Service());
2438 // could use simply "GET" here I suppose
2440 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
2441 client
.Write(cmdGet
, cmdGet
.length());
2442 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2443 MakePrintable(cmdGet
).c_str());
2444 client
.Read(buf
, WXSIZEOF(buf
));
2445 wxPrintf(_T("--- Server replied:\n%s"), buf
);
2449 #endif // TEST_SOCKETS
2451 // ----------------------------------------------------------------------------
2453 // ----------------------------------------------------------------------------
2457 #include "wx/protocol/ftp.h"
2459 #define FTP_ANONYMOUS
2463 #ifdef FTP_ANONYMOUS
2464 static const wxChar
*directory
= _T("/pub");
2465 static const wxChar
*filename
= _T("welcome.msg");
2467 static const wxChar
*directory
= _T("/etc");
2468 static const wxChar
*filename
= _T("issue");
2471 static bool TestFtpConnect()
2473 wxPuts(_T("*** Testing FTP connect ***"));
2475 // wxFTP cannot be a static variable as its ctor needs to access
2476 // wxWidgets internals after it has been initialized
2479 #ifdef FTP_ANONYMOUS
2480 static const wxChar
*hostname
= _T("ftp.wxwidgets.org");
2482 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2483 #else // !FTP_ANONYMOUS
2484 static const wxChar
*hostname
= "localhost";
2487 wxFgets(user
, WXSIZEOF(user
), stdin
);
2488 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2491 wxChar password
[256];
2492 wxPrintf(_T("Password for %s: "), password
);
2493 wxFgets(password
, WXSIZEOF(password
), stdin
);
2494 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2495 ftp
->SetPassword(password
);
2497 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2498 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2500 if ( !ftp
->Connect(hostname
) )
2502 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2508 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2509 hostname
, ftp
->Pwd().c_str());
2516 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2517 static void TestFtpWuFtpd()
2520 static const wxChar
*hostname
= _T("ftp.eudora.com");
2521 if ( !ftp
.Connect(hostname
) )
2523 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2527 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
2528 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2531 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2535 size_t size
= in
->GetSize();
2536 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2538 wxChar
*data
= new wxChar
[size
];
2539 if ( !in
->Read(data
, size
) )
2541 wxPuts(_T("ERROR: read error"));
2545 wxPrintf(_T("Successfully retrieved the file.\n"));
2554 static void TestFtpList()
2556 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2559 if ( !ftp
->ChDir(directory
) )
2561 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2564 wxPrintf(_T("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2566 // test NLIST and LIST
2567 wxArrayString files
;
2568 if ( !ftp
->GetFilesList(files
) )
2570 wxPuts(_T("ERROR: failed to get NLIST of files"));
2574 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
->Pwd().c_str());
2575 size_t count
= files
.GetCount();
2576 for ( size_t n
= 0; n
< count
; n
++ )
2578 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2580 wxPuts(_T("End of the file list"));
2583 if ( !ftp
->GetDirList(files
) )
2585 wxPuts(_T("ERROR: failed to get LIST of files"));
2589 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
->Pwd().c_str());
2590 size_t count
= files
.GetCount();
2591 for ( size_t n
= 0; n
< count
; n
++ )
2593 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2595 wxPuts(_T("End of the file list"));
2598 if ( !ftp
->ChDir(_T("..")) )
2600 wxPuts(_T("ERROR: failed to cd to .."));
2603 wxPrintf(_T("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2606 static void TestFtpDownload()
2608 wxPuts(_T("*** Testing wxFTP download ***\n"));
2611 wxInputStream
*in
= ftp
->GetInputStream(filename
);
2614 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2618 size_t size
= in
->GetSize();
2619 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2622 wxChar
*data
= new wxChar
[size
];
2623 if ( !in
->Read(data
, size
) )
2625 wxPuts(_T("ERROR: read error"));
2629 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
2637 static void TestFtpFileSize()
2639 wxPuts(_T("*** Testing FTP SIZE command ***"));
2641 if ( !ftp
->ChDir(directory
) )
2643 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2646 wxPrintf(_T("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2648 if ( ftp
->FileExists(filename
) )
2650 int size
= ftp
->GetFileSize(filename
);
2652 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
2654 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
2658 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
2662 static void TestFtpMisc()
2664 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2666 if ( ftp
->SendCommand(_T("STAT")) != '2' )
2668 wxPuts(_T("ERROR: STAT failed"));
2672 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
->GetLastResult().c_str());
2675 if ( ftp
->SendCommand(_T("HELP SITE")) != '2' )
2677 wxPuts(_T("ERROR: HELP SITE failed"));
2681 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2682 ftp
->GetLastResult().c_str());
2686 static void TestFtpInteractive()
2688 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2694 wxPrintf(_T("Enter FTP command: "));
2695 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2698 // kill the last '\n'
2699 buf
[wxStrlen(buf
) - 1] = 0;
2701 // special handling of LIST and NLST as they require data connection
2702 wxString
start(buf
, 4);
2704 if ( start
== _T("LIST") || start
== _T("NLST") )
2707 if ( wxStrlen(buf
) > 4 )
2710 wxArrayString files
;
2711 if ( !ftp
->GetList(files
, wildcard
, start
== _T("LIST")) )
2713 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
2717 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2718 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2719 size_t count
= files
.GetCount();
2720 for ( size_t n
= 0; n
< count
; n
++ )
2722 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2724 wxPuts(_T("--- End of the file list"));
2729 wxChar ch
= ftp
->SendCommand(buf
);
2730 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
2733 wxPrintf(_T(" (return code %c)"), ch
);
2736 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2740 wxPuts(_T("\n*** done ***"));
2743 static void TestFtpUpload()
2745 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2748 static const wxChar
*file1
= _T("test1");
2749 static const wxChar
*file2
= _T("test2");
2750 wxOutputStream
*out
= ftp
->GetOutputStream(file1
);
2753 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2754 out
->Write("First hello", 11);
2758 // send a command to check the remote file
2759 if ( ftp
->SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
2761 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
2765 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2766 file1
, ftp
->GetLastResult().c_str());
2769 out
= ftp
->GetOutputStream(file2
);
2772 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2773 out
->Write("Second hello", 12);
2780 // ----------------------------------------------------------------------------
2782 // ----------------------------------------------------------------------------
2784 #ifdef TEST_STACKWALKER
2786 #if wxUSE_STACKWALKER
2788 #include "wx/stackwalk.h"
2790 class StackDump
: public wxStackWalker
2793 StackDump(const char *argv0
)
2794 : wxStackWalker(argv0
)
2798 virtual void Walk(size_t skip
= 1)
2800 wxPuts(_T("Stack dump:"));
2802 wxStackWalker::Walk(skip
);
2806 virtual void OnStackFrame(const wxStackFrame
& frame
)
2808 printf("[%2d] ", (int) frame
.GetLevel());
2810 wxString name
= frame
.GetName();
2811 if ( !name
.empty() )
2813 printf("%-20.40s", (const char*)name
.mb_str());
2817 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2820 if ( frame
.HasSourceLocation() )
2823 (const char*)frame
.GetFileName().mb_str(),
2824 (int)frame
.GetLine());
2830 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2832 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2833 (const char*)name
.mb_str(),
2834 (const char*)val
.mb_str());
2839 static void TestStackWalk(const char *argv0
)
2841 wxPuts(_T("*** Testing wxStackWalker ***\n"));
2843 StackDump
dump(argv0
);
2847 #endif // wxUSE_STACKWALKER
2849 #endif // TEST_STACKWALKER
2851 // ----------------------------------------------------------------------------
2853 // ----------------------------------------------------------------------------
2855 #ifdef TEST_STDPATHS
2857 #include "wx/stdpaths.h"
2858 #include "wx/wxchar.h" // wxPrintf
2860 static void TestStandardPaths()
2862 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
2864 wxTheApp
->SetAppName(_T("console"));
2866 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
2867 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2868 wxPrintf(_T("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2869 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2870 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2871 wxPrintf(_T("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2872 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2873 wxPrintf(_T("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2874 wxPrintf(_T("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2875 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2876 wxPrintf(_T("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2877 wxPrintf(_T("Localized res. dir:\t%s\n"),
2878 stdp
.GetLocalizedResourcesDir(_T("fr")).c_str());
2879 wxPrintf(_T("Message catalogs dir:\t%s\n"),
2880 stdp
.GetLocalizedResourcesDir
2883 wxStandardPaths::ResourceCat_Messages
2887 #endif // TEST_STDPATHS
2889 // ----------------------------------------------------------------------------
2891 // ----------------------------------------------------------------------------
2895 #include "wx/wfstream.h"
2896 #include "wx/mstream.h"
2898 static void TestFileStream()
2900 wxPuts(_T("*** Testing wxFileInputStream ***"));
2902 static const wxString filename
= _T("testdata.fs");
2904 wxFileOutputStream
fsOut(filename
);
2905 fsOut
.Write("foo", 3);
2909 wxFileInputStream
fsIn(filename
);
2910 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
2911 while ( !fsIn
.Eof() )
2913 wxPutchar(fsIn
.GetC());
2917 if ( !wxRemoveFile(filename
) )
2919 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2922 wxPuts(_T("\n*** wxFileInputStream test done ***"));
2925 static void TestMemoryStream()
2927 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
2929 wxMemoryOutputStream memOutStream
;
2930 wxPrintf(_T("Initially out stream offset: %lu\n"),
2931 (unsigned long)memOutStream
.TellO());
2933 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
2935 memOutStream
.PutC(*p
);
2938 wxPrintf(_T("Final out stream offset: %lu\n"),
2939 (unsigned long)memOutStream
.TellO());
2941 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
2944 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2946 wxMemoryInputStream
memInpStream(buf
, len
);
2947 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2948 while ( !memInpStream
.Eof() )
2950 wxPutchar(memInpStream
.GetC());
2953 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
2956 #endif // TEST_STREAMS
2958 // ----------------------------------------------------------------------------
2960 // ----------------------------------------------------------------------------
2964 #include "wx/stopwatch.h"
2965 #include "wx/utils.h"
2967 static void TestStopWatch()
2969 wxPuts(_T("*** Testing wxStopWatch ***\n"));
2973 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
2976 wxPrintf(_T("\t%ldms\n"), sw
.Time());
2978 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
2982 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2985 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
2988 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2991 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
2994 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
2997 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
2998 for ( size_t n
= 0; n
< 70; n
++ )
3002 for ( size_t m
= 0; m
< 100000; m
++ )
3004 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3006 wxPuts(_T("\ntime is negative - ERROR!"));
3014 wxPuts(_T(", ok."));
3017 #include "wx/timer.h"
3018 #include "wx/evtloop.h"
3022 wxPuts(_T("*** Testing wxTimer ***\n"));
3024 class MyTimer
: public wxTimer
3027 MyTimer() : wxTimer() { m_num
= 0; }
3029 virtual void Notify()
3031 wxPrintf(_T("%d"), m_num
++);
3036 wxPrintf(_T("... exiting the event loop"));
3039 wxEventLoop::GetActive()->Exit(0);
3040 wxPuts(_T(", ok."));
3053 timer1
.Start(100, true /* one shot */);
3055 timer1
.Start(100, true /* one shot */);
3063 #endif // TEST_TIMER
3065 // ----------------------------------------------------------------------------
3067 // ----------------------------------------------------------------------------
3071 #include "wx/vcard.h"
3073 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3076 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3079 wxPrintf(_T("%s%s"),
3080 wxString(_T('\t'), level
).c_str(),
3081 vcObj
->GetName().c_str());
3084 switch ( vcObj
->GetType() )
3086 case wxVCardObject::String
:
3087 case wxVCardObject::UString
:
3090 vcObj
->GetValue(&val
);
3091 value
<< _T('"') << val
<< _T('"');
3095 case wxVCardObject::Int
:
3098 vcObj
->GetValue(&i
);
3099 value
.Printf(_T("%u"), i
);
3103 case wxVCardObject::Long
:
3106 vcObj
->GetValue(&l
);
3107 value
.Printf(_T("%lu"), l
);
3111 case wxVCardObject::None
:
3114 case wxVCardObject::Object
:
3115 value
= _T("<node>");
3119 value
= _T("<unknown value type>");
3123 wxPrintf(_T(" = %s"), value
.c_str());
3126 DumpVObject(level
+ 1, *vcObj
);
3129 vcObj
= vcard
.GetNextProp(&cookie
);
3133 static void DumpVCardAddresses(const wxVCard
& vcard
)
3135 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3139 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3143 int flags
= addr
->GetFlags();
3144 if ( flags
& wxVCardAddress::Domestic
)
3146 flagsStr
<< _T("domestic ");
3148 if ( flags
& wxVCardAddress::Intl
)
3150 flagsStr
<< _T("international ");
3152 if ( flags
& wxVCardAddress::Postal
)
3154 flagsStr
<< _T("postal ");
3156 if ( flags
& wxVCardAddress::Parcel
)
3158 flagsStr
<< _T("parcel ");
3160 if ( flags
& wxVCardAddress::Home
)
3162 flagsStr
<< _T("home ");
3164 if ( flags
& wxVCardAddress::Work
)
3166 flagsStr
<< _T("work ");
3169 wxPrintf(_T("Address %u:\n")
3171 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3174 addr
->GetPostOffice().c_str(),
3175 addr
->GetExtAddress().c_str(),
3176 addr
->GetStreet().c_str(),
3177 addr
->GetLocality().c_str(),
3178 addr
->GetRegion().c_str(),
3179 addr
->GetPostalCode().c_str(),
3180 addr
->GetCountry().c_str()
3184 addr
= vcard
.GetNextAddress(&cookie
);
3188 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3190 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3194 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3198 int flags
= phone
->GetFlags();
3199 if ( flags
& wxVCardPhoneNumber::Voice
)
3201 flagsStr
<< _T("voice ");
3203 if ( flags
& wxVCardPhoneNumber::Fax
)
3205 flagsStr
<< _T("fax ");
3207 if ( flags
& wxVCardPhoneNumber::Cellular
)
3209 flagsStr
<< _T("cellular ");
3211 if ( flags
& wxVCardPhoneNumber::Modem
)
3213 flagsStr
<< _T("modem ");
3215 if ( flags
& wxVCardPhoneNumber::Home
)
3217 flagsStr
<< _T("home ");
3219 if ( flags
& wxVCardPhoneNumber::Work
)
3221 flagsStr
<< _T("work ");
3224 wxPrintf(_T("Phone number %u:\n")
3229 phone
->GetNumber().c_str()
3233 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3237 static void TestVCardRead()
3239 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3241 wxVCard
vcard(_T("vcard.vcf"));
3242 if ( !vcard
.IsOk() )
3244 wxPuts(_T("ERROR: couldn't load vCard."));
3248 // read individual vCard properties
3249 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3253 vcObj
->GetValue(&value
);
3258 value
= _T("<none>");
3261 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3264 if ( !vcard
.GetFullName(&value
) )
3266 value
= _T("<none>");
3269 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3271 // now show how to deal with multiply occurring properties
3272 DumpVCardAddresses(vcard
);
3273 DumpVCardPhoneNumbers(vcard
);
3275 // and finally show all
3276 wxPuts(_T("\nNow dumping the entire vCard:\n")
3277 "-----------------------------\n");
3279 DumpVObject(0, vcard
);
3283 static void TestVCardWrite()
3285 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3288 if ( !vcard
.IsOk() )
3290 wxPuts(_T("ERROR: couldn't create vCard."));
3295 vcard
.SetName("Zeitlin", "Vadim");
3296 vcard
.SetFullName("Vadim Zeitlin");
3297 vcard
.SetOrganization("wxWidgets", "R&D");
3299 // just dump the vCard back
3300 wxPuts(_T("Entire vCard follows:\n"));
3301 wxPuts(vcard
.Write());
3305 #endif // TEST_VCARD
3307 // ----------------------------------------------------------------------------
3309 // ----------------------------------------------------------------------------
3311 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3317 #include "wx/volume.h"
3319 static const wxChar
*volumeKinds
[] =
3325 _T("network volume"),
3329 static void TestFSVolume()
3331 wxPuts(_T("*** Testing wxFSVolume class ***"));
3333 wxArrayString volumes
= wxFSVolume::GetVolumes();
3334 size_t count
= volumes
.GetCount();
3338 wxPuts(_T("ERROR: no mounted volumes?"));
3342 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3344 for ( size_t n
= 0; n
< count
; n
++ )
3346 wxFSVolume
vol(volumes
[n
]);
3349 wxPuts(_T("ERROR: couldn't create volume"));
3353 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3355 vol
.GetDisplayName().c_str(),
3356 vol
.GetName().c_str(),
3357 volumeKinds
[vol
.GetKind()],
3358 vol
.IsWritable() ? _T("rw") : _T("ro"),
3359 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3364 #endif // TEST_VOLUME
3366 // ----------------------------------------------------------------------------
3367 // wide char and Unicode support
3368 // ----------------------------------------------------------------------------
3372 #include "wx/strconv.h"
3373 #include "wx/fontenc.h"
3374 #include "wx/encconv.h"
3375 #include "wx/buffer.h"
3377 static const unsigned char utf8koi8r
[] =
3379 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3380 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3381 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3382 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3383 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3384 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3385 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3388 static const unsigned char utf8iso8859_1
[] =
3390 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3391 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3392 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3393 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3394 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3397 static const unsigned char utf8Invalid
[] =
3399 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3400 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3401 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3402 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3406 static const struct Utf8Data
3408 const unsigned char *text
;
3410 const wxChar
*charset
;
3411 wxFontEncoding encoding
;
3414 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3415 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3416 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3419 static void TestUtf8()
3421 wxPuts(_T("*** Testing UTF8 support ***\n"));
3426 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3428 const Utf8Data
& u8d
= utf8data
[n
];
3429 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3430 WXSIZEOF(wbuf
)) == (size_t)-1 )
3432 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3436 wxCSConv
conv(u8d
.charset
);
3437 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3439 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3443 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3447 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3449 s
= _T("<< conversion failed >>");
3450 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3454 wxPuts(wxEmptyString
);
3457 static void TestEncodingConverter()
3459 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3461 // using wxEncodingConverter should give the same result as above
3464 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3465 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3467 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3471 wxEncodingConverter ec
;
3472 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3473 ec
.Convert(wbuf
, buf
);
3474 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3477 wxPuts(wxEmptyString
);
3480 #endif // TEST_WCHAR
3482 // ----------------------------------------------------------------------------
3484 // ----------------------------------------------------------------------------
3488 #include "wx/filesys.h"
3489 #include "wx/fs_zip.h"
3490 #include "wx/zipstrm.h"
3492 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3494 static void TestZipStreamRead()
3496 wxPuts(_T("*** Testing ZIP reading ***\n"));
3498 static const wxString filename
= _T("foo");
3499 wxFFileInputStream
in(TESTFILE_ZIP
);
3500 wxZipInputStream
istr(in
);
3501 wxZipEntry
entry(filename
);
3502 istr
.OpenEntry(entry
);
3504 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3506 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3507 while ( !istr
.Eof() )
3509 wxPutchar(istr
.GetC());
3513 wxPuts(_T("\n----- done ------"));
3516 static void DumpZipDirectory(wxFileSystem
& fs
,
3517 const wxString
& dir
,
3518 const wxString
& indent
)
3520 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3521 TESTFILE_ZIP
, dir
.c_str());
3522 wxString wildcard
= prefix
+ _T("/*");
3524 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3525 while ( !dirname
.empty() )
3527 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3529 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3534 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3536 DumpZipDirectory(fs
, dirname
,
3537 indent
+ wxString(_T(' '), 4));
3539 dirname
= fs
.FindNext();
3542 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3543 while ( !filename
.empty() )
3545 if ( !filename
.StartsWith(prefix
, &filename
) )
3547 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3552 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3554 filename
= fs
.FindNext();
3558 static void TestZipFileSystem()
3560 wxPuts(_T("*** Testing ZIP file system ***\n"));
3562 wxFileSystem::AddHandler(new wxZipFSHandler
);
3564 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3566 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3571 // ----------------------------------------------------------------------------
3573 // ----------------------------------------------------------------------------
3575 #ifdef TEST_DATETIME
3577 #include "wx/math.h"
3578 #include "wx/datetime.h"
3580 // this test miscellaneous static wxDateTime functions
3584 static void TestTimeStatic()
3586 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3588 // some info about the current date
3589 int year
= wxDateTime::GetCurrentYear();
3590 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3592 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3593 wxDateTime::GetNumberOfDays(year
));
3595 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3596 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3597 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3598 wxDateTime::GetMonthName(month
).c_str(),
3599 wxDateTime::GetNumberOfDays(month
));
3602 // test time zones stuff
3603 static void TestTimeZones()
3605 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3607 wxDateTime now
= wxDateTime::Now();
3609 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
3610 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
3611 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
3612 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
3613 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
3614 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
3616 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3618 wxDateTime::Tm tm
= now
.GetTm();
3619 if ( wxDateTime(tm
) != now
)
3621 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3622 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3626 // test some minimal support for the dates outside the standard range
3627 static void TestTimeRange()
3629 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3631 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
3633 wxPrintf(_T("Unix epoch:\t%s\n"),
3634 wxDateTime(2440587.5).Format(fmt
).c_str());
3635 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3636 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3637 wxPrintf(_T("JDN 0: \t%s\n"),
3638 wxDateTime(0.0).Format(fmt
).c_str());
3639 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3640 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3641 wxPrintf(_T("May 29, 2099:\t%s\n"),
3642 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3645 // test DST calculations
3646 static void TestTimeDST()
3648 wxPuts(_T("\n*** wxDateTime DST test ***"));
3650 wxPrintf(_T("DST is%s in effect now.\n\n"),
3651 wxDateTime::Now().IsDST() ? wxEmptyString
: _T(" not"));
3653 for ( int year
= 1990; year
< 2005; year
++ )
3655 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3657 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3658 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3664 #if TEST_INTERACTIVE
3666 static void TestDateTimeInteractive()
3668 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3674 wxPrintf(_T("Enter a date: "));
3675 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3678 // kill the last '\n'
3679 buf
[wxStrlen(buf
) - 1] = 0;
3682 const wxChar
*p
= dt
.ParseDate(buf
);
3685 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
3691 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
3694 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3695 dt
.Format(_T("%b %d, %Y")).c_str(),
3697 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3698 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3699 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3702 wxPuts(_T("\n*** done ***"));
3705 #endif // TEST_INTERACTIVE
3709 static void TestTimeMS()
3711 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3713 wxDateTime dt1
= wxDateTime::Now(),
3714 dt2
= wxDateTime::UNow();
3716 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
3717 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3718 wxPrintf(_T("Dummy loop: "));
3719 for ( int i
= 0; i
< 6000; i
++ )
3721 //for ( int j = 0; j < 10; j++ )
3724 s
.Printf(_T("%g"), sqrt((float)i
));
3730 wxPuts(_T(", done"));
3733 dt2
= wxDateTime::UNow();
3734 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3736 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
3738 wxPuts(_T("\n*** done ***"));
3741 static void TestTimeHolidays()
3743 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3745 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3746 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3747 dtEnd
= dtStart
.GetLastMonthDay();
3749 wxDateTimeArray hol
;
3750 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3752 const wxChar
*format
= _T("%d-%b-%Y (%a)");
3754 wxPrintf(_T("All holidays between %s and %s:\n"),
3755 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3757 size_t count
= hol
.GetCount();
3758 for ( size_t n
= 0; n
< count
; n
++ )
3760 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
3763 wxPuts(wxEmptyString
);
3766 static void TestTimeZoneBug()
3768 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3770 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3771 for ( int i
= 0; i
< 31; i
++ )
3773 wxPrintf(_T("Date %s: week day %s.\n"),
3774 date
.Format(_T("%d-%m-%Y")).c_str(),
3775 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3777 date
+= wxDateSpan::Day();
3780 wxPuts(wxEmptyString
);
3783 static void TestTimeSpanFormat()
3785 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3787 static const wxChar
*formats
[] =
3789 _T("(default) %H:%M:%S"),
3790 _T("%E weeks and %D days"),
3791 _T("%l milliseconds"),
3792 _T("(with ms) %H:%M:%S:%l"),
3793 _T("100%% of minutes is %M"), // test "%%"
3794 _T("%D days and %H hours"),
3795 _T("or also %S seconds"),
3798 wxTimeSpan
ts1(1, 2, 3, 4),
3800 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3802 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3803 ts1
.Format(formats
[n
]).c_str(),
3804 ts2
.Format(formats
[n
]).c_str());
3807 wxPuts(wxEmptyString
);
3812 #endif // TEST_DATETIME
3814 // ----------------------------------------------------------------------------
3815 // wxTextInput/OutputStream
3816 // ----------------------------------------------------------------------------
3818 #ifdef TEST_TEXTSTREAM
3820 #include "wx/txtstrm.h"
3821 #include "wx/wfstream.h"
3823 static void TestTextInputStream()
3825 wxPuts(_T("\n*** wxTextInputStream test ***"));
3827 wxString filename
= _T("testdata.fc");
3828 wxFileInputStream
fsIn(filename
);
3831 wxPuts(_T("ERROR: couldn't open file."));
3835 wxTextInputStream
tis(fsIn
);
3840 const wxString s
= tis
.ReadLine();
3842 // line could be non empty if the last line of the file isn't
3843 // terminated with EOL
3844 if ( fsIn
.Eof() && s
.empty() )
3847 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
3852 #endif // TEST_TEXTSTREAM
3854 // ----------------------------------------------------------------------------
3856 // ----------------------------------------------------------------------------
3860 #include "wx/thread.h"
3862 static size_t gs_counter
= (size_t)-1;
3863 static wxCriticalSection gs_critsect
;
3864 static wxSemaphore gs_cond
;
3866 class MyJoinableThread
: public wxThread
3869 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3870 { m_n
= n
; Create(); }
3872 // thread execution starts here
3873 virtual ExitCode
Entry();
3879 wxThread::ExitCode
MyJoinableThread::Entry()
3881 unsigned long res
= 1;
3882 for ( size_t n
= 1; n
< m_n
; n
++ )
3886 // it's a loooong calculation :-)
3890 return (ExitCode
)res
;
3893 class MyDetachedThread
: public wxThread
3896 MyDetachedThread(size_t n
, wxChar ch
)
3900 m_cancelled
= false;
3905 // thread execution starts here
3906 virtual ExitCode
Entry();
3909 virtual void OnExit();
3912 size_t m_n
; // number of characters to write
3913 wxChar m_ch
; // character to write
3915 bool m_cancelled
; // false if we exit normally
3918 wxThread::ExitCode
MyDetachedThread::Entry()
3921 wxCriticalSectionLocker
lock(gs_critsect
);
3922 if ( gs_counter
== (size_t)-1 )
3928 for ( size_t n
= 0; n
< m_n
; n
++ )
3930 if ( TestDestroy() )
3940 wxThread::Sleep(100);
3946 void MyDetachedThread::OnExit()
3948 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
3950 wxCriticalSectionLocker
lock(gs_critsect
);
3951 if ( !--gs_counter
&& !m_cancelled
)
3955 static void TestDetachedThreads()
3957 wxPuts(_T("\n*** Testing detached threads ***"));
3959 static const size_t nThreads
= 3;
3960 MyDetachedThread
*threads
[nThreads
];
3962 for ( n
= 0; n
< nThreads
; n
++ )
3964 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3967 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3968 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3970 for ( n
= 0; n
< nThreads
; n
++ )
3975 // wait until all threads terminate
3978 wxPuts(wxEmptyString
);
3981 static void TestJoinableThreads()
3983 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
3985 // calc 10! in the background
3986 MyJoinableThread
thread(10);
3989 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
3990 (unsigned long)thread
.Wait());
3993 static void TestThreadSuspend()
3995 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
3997 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4001 // this is for this demo only, in a real life program we'd use another
4002 // condition variable which would be signaled from wxThread::Entry() to
4003 // tell us that the thread really started running - but here just wait a
4004 // bit and hope that it will be enough (the problem is, of course, that
4005 // the thread might still not run when we call Pause() which will result
4007 wxThread::Sleep(300);
4009 for ( size_t n
= 0; n
< 3; n
++ )
4013 wxPuts(_T("\nThread suspended"));
4016 // don't sleep but resume immediately the first time
4017 wxThread::Sleep(300);
4019 wxPuts(_T("Going to resume the thread"));
4024 wxPuts(_T("Waiting until it terminates now"));
4026 // wait until the thread terminates
4029 wxPuts(wxEmptyString
);
4032 static void TestThreadDelete()
4034 // As above, using Sleep() is only for testing here - we must use some
4035 // synchronisation object instead to ensure that the thread is still
4036 // running when we delete it - deleting a detached thread which already
4037 // terminated will lead to a crash!
4039 wxPuts(_T("\n*** Testing thread delete function ***"));
4041 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4045 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
4047 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4051 wxThread::Sleep(300);
4055 wxPuts(_T("\nDeleted a running thread."));
4057 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4061 wxThread::Sleep(300);
4067 wxPuts(_T("\nDeleted a sleeping thread."));
4069 MyJoinableThread
thread3(20);
4074 wxPuts(_T("\nDeleted a joinable thread."));
4076 MyJoinableThread
thread4(2);
4079 wxThread::Sleep(300);
4083 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
4085 wxPuts(wxEmptyString
);
4088 class MyWaitingThread
: public wxThread
4091 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
4094 m_condition
= condition
;
4099 virtual ExitCode
Entry()
4101 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
4106 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
4110 m_condition
->Wait();
4113 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
4121 wxCondition
*m_condition
;
4124 static void TestThreadConditions()
4127 wxCondition
condition(mutex
);
4129 // otherwise its difficult to understand which log messages pertain to
4131 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
4132 // condition.GetId(), gs_cond.GetId());
4134 // create and launch threads
4135 MyWaitingThread
*threads
[10];
4138 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4140 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
4143 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4148 // wait until all threads run
4149 wxPuts(_T("Main thread is waiting for the other threads to start"));
4152 size_t nRunning
= 0;
4153 while ( nRunning
< WXSIZEOF(threads
) )
4159 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
4163 wxPuts(_T("Main thread: all threads started up."));
4166 wxThread::Sleep(500);
4169 // now wake one of them up
4170 wxPrintf(_T("Main thread: about to signal the condition.\n"));
4175 wxThread::Sleep(200);
4177 // wake all the (remaining) threads up, so that they can exit
4178 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
4180 condition
.Broadcast();
4182 // give them time to terminate (dirty!)
4183 wxThread::Sleep(500);
4186 #include "wx/utils.h"
4188 class MyExecThread
: public wxThread
4191 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
4197 virtual ExitCode
Entry()
4199 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
4206 static void TestThreadExec()
4208 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4210 MyExecThread
thread(_T("true"));
4213 wxPrintf(_T("Main program exit code: %ld.\n"),
4214 wxExecute(_T("false"), wxEXEC_SYNC
));
4216 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
4220 #include "wx/datetime.h"
4222 class MySemaphoreThread
: public wxThread
4225 MySemaphoreThread(int i
, wxSemaphore
*sem
)
4226 : wxThread(wxTHREAD_JOINABLE
),
4233 virtual ExitCode
Entry()
4235 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4236 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4240 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4241 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4245 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4246 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4258 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
4260 static void TestSemaphore()
4262 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4264 static const int SEM_LIMIT
= 3;
4266 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
4267 ArrayThreads threads
;
4269 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
4271 threads
.Add(new MySemaphoreThread(i
, &sem
));
4272 threads
.Last()->Run();
4275 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
4282 #endif // TEST_THREADS
4284 // ----------------------------------------------------------------------------
4286 // ----------------------------------------------------------------------------
4288 #ifdef TEST_SNGLINST
4289 #include "wx/snglinst.h"
4290 #endif // TEST_SNGLINST
4292 int main(int argc
, char **argv
)
4295 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
4300 for (n
= 0; n
< argc
; n
++ )
4302 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
4303 wxArgv
[n
] = wxStrdup(warg
);
4308 #else // !wxUSE_UNICODE
4310 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
4312 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
4314 wxInitializer initializer
;
4317 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
4322 #ifdef TEST_SNGLINST
4323 wxSingleInstanceChecker checker
;
4324 if ( checker
.Create(_T(".wxconsole.lock")) )
4326 if ( checker
.IsAnotherRunning() )
4328 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4333 // wait some time to give time to launch another instance
4334 wxPrintf(_T("Press \"Enter\" to continue..."));
4337 else // failed to create
4339 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4341 #endif // TEST_SNGLINST
4344 TestCmdLineConvert();
4346 #if wxUSE_CMDLINE_PARSER
4347 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4349 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
4350 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
4351 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
4352 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
4354 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
4355 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
4356 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
4357 wxCMD_LINE_VAL_NUMBER
},
4358 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
4359 wxCMD_LINE_VAL_DATE
},
4360 { wxCMD_LINE_OPTION
, "f", "double", "output double",
4361 wxCMD_LINE_VAL_DOUBLE
},
4363 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
4364 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4369 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
4371 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4372 wxCMD_LINE_VAL_STRING
,
4373 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4375 switch ( parser
.Parse() )
4378 wxLogMessage(_T("Help was given, terminating."));
4382 ShowCmdLine(parser
);
4386 wxLogMessage(_T("Syntax error detected, aborting."));
4389 #endif // wxUSE_CMDLINE_PARSER
4391 #endif // TEST_CMDLINE
4403 TestDllListLoaded();
4404 #endif // TEST_DYNLIB
4408 #endif // TEST_ENVIRON
4412 #endif // TEST_EXECUTE
4414 #ifdef TEST_FILECONF
4416 #endif // TEST_FILECONF
4420 #endif // TEST_LOCALE
4423 wxPuts(_T("*** Testing wxLog ***"));
4426 for ( size_t n
= 0; n
< 8000; n
++ )
4428 s
<< (wxChar
)(_T('A') + (n
% 26));
4431 wxLogWarning(_T("The length of the string is %lu"),
4432 (unsigned long)s
.length());
4435 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
4437 // this one shouldn't be truncated
4440 // but this one will because log functions use fixed size buffer
4441 // (note that it doesn't need '\n' at the end neither - will be added
4443 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
4453 #ifdef TEST_FILENAME
4456 TestFileNameDirManip();
4457 TestFileNameComparison();
4458 TestFileNameOperations();
4459 #endif // TEST_FILENAME
4461 #ifdef TEST_FILETIME
4466 #endif // TEST_FILETIME
4469 wxLog::AddTraceMask(FTP_TRACE_MASK
);
4470 if ( TestFtpConnect() )
4480 #if TEST_INTERACTIVE
4481 TestFtpInteractive();
4484 //else: connecting to the FTP server failed
4492 //wxLog::AddTraceMask(_T("mime"));
4496 TestMimeAssociate();
4501 #ifdef TEST_INFO_FUNCTIONS
4506 #if TEST_INTERACTIVE
4509 #endif // TEST_INFO_FUNCTIONS
4511 #ifdef TEST_PATHLIST
4513 #endif // TEST_PATHLIST
4517 #endif // TEST_PRINTF
4524 #endif // TEST_REGCONF
4526 #if defined TEST_REGEX && TEST_INTERACTIVE
4527 TestRegExInteractive();
4528 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4530 #ifdef TEST_REGISTRY
4532 TestRegistryAssociation();
4533 #endif // TEST_REGISTRY
4538 #endif // TEST_SOCKETS
4545 #endif // TEST_STREAMS
4547 #ifdef TEST_TEXTSTREAM
4548 TestTextInputStream();
4549 #endif // TEST_TEXTSTREAM
4552 int nCPUs
= wxThread::GetCPUCount();
4553 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
4555 wxThread::SetConcurrency(nCPUs
);
4557 TestJoinableThreads();
4560 TestJoinableThreads();
4561 TestDetachedThreads();
4562 TestThreadSuspend();
4564 TestThreadConditions();
4568 #endif // TEST_THREADS
4573 #endif // TEST_TIMER
4575 #ifdef TEST_DATETIME
4582 TestTimeSpanFormat();
4588 #if TEST_INTERACTIVE
4589 TestDateTimeInteractive();
4591 #endif // TEST_DATETIME
4593 #ifdef TEST_SCOPEGUARD
4597 #ifdef TEST_STACKWALKER
4598 #if wxUSE_STACKWALKER
4599 TestStackWalk(argv
[0]);
4601 #endif // TEST_STACKWALKER
4603 #ifdef TEST_STDPATHS
4604 TestStandardPaths();
4608 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4610 #endif // TEST_USLEEP
4615 #endif // TEST_VCARD
4619 #endif // TEST_VOLUME
4623 TestEncodingConverter();
4624 #endif // TEST_WCHAR
4627 TestZipStreamRead();
4628 TestZipFileSystem();
4633 for ( int n
= 0; n
< argc
; n
++ )
4638 #endif // wxUSE_UNICODE