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(wxT("Help was given, terminating."));
48 // everything is ok; proceed
52 wxLogMessage(wxT("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
114 #define TEST_FILECONF
115 #define TEST_FILENAME
116 #define TEST_FILETIME
118 #define TEST_INFO_FUNCTIONS
123 #define TEST_PATHLIST
127 #define TEST_REGISTRY
128 #define TEST_SCOPEGUARD
129 #define TEST_SNGLINST
130 // #define TEST_SOCKETS --FIXME! (RN)
131 #define TEST_STACKWALKER
132 #define TEST_STDPATHS
134 #define TEST_TEXTSTREAM
136 // #define TEST_VOLUME --FIXME! (RN)
139 #else // #if TEST_ALL
143 // some tests are interactive, define this to run them
144 #ifdef TEST_INTERACTIVE
145 #undef TEST_INTERACTIVE
147 #define TEST_INTERACTIVE 1
149 #define TEST_INTERACTIVE 0
152 // ============================================================================
154 // ============================================================================
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 #if defined(TEST_SOCKETS)
162 // replace TABs with \t and CRs with \n
163 static wxString
MakePrintable(const wxChar
*s
)
166 (void)str
.Replace(wxT("\t"), wxT("\\t"));
167 (void)str
.Replace(wxT("\n"), wxT("\\n"));
168 (void)str
.Replace(wxT("\r"), wxT("\\r"));
173 #endif // MakePrintable() is used
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
181 #include "wx/cmdline.h"
182 #include "wx/datetime.h"
184 #if wxUSE_CMDLINE_PARSER
186 static void ShowCmdLine(const wxCmdLineParser
& parser
)
188 wxString s
= wxT("Command line parsed successfully:\nInput files: ");
190 size_t count
= parser
.GetParamCount();
191 for ( size_t param
= 0; param
< count
; param
++ )
193 s
<< parser
.GetParam(param
) << ' ';
197 << wxT("Verbose:\t") << (parser
.Found(wxT("v")) ?
wxT("yes") : wxT("no")) << '\n'
198 << wxT("Quiet:\t") << (parser
.Found(wxT("q")) ?
wxT("yes") : wxT("no")) << '\n';
204 if ( parser
.Found(wxT("o"), &strVal
) )
205 s
<< wxT("Output file:\t") << strVal
<< '\n';
206 if ( parser
.Found(wxT("i"), &strVal
) )
207 s
<< wxT("Input dir:\t") << strVal
<< '\n';
208 if ( parser
.Found(wxT("s"), &lVal
) )
209 s
<< wxT("Size:\t") << lVal
<< '\n';
210 if ( parser
.Found(wxT("f"), &dVal
) )
211 s
<< wxT("Double:\t") << dVal
<< '\n';
212 if ( parser
.Found(wxT("d"), &dt
) )
213 s
<< wxT("Date:\t") << dt
.FormatISODate() << '\n';
214 if ( parser
.Found(wxT("project_name"), &strVal
) )
215 s
<< wxT("Project:\t") << strVal
<< '\n';
220 #endif // wxUSE_CMDLINE_PARSER
222 static void TestCmdLineConvert()
224 static const wxChar
*cmdlines
[] =
227 wxT("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
228 wxT("literal \\\" and \"\""),
231 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
233 const wxChar
*cmdline
= cmdlines
[n
];
234 wxPrintf(wxT("Parsing: %s\n"), cmdline
);
235 wxArrayString args
= wxCmdLineParser
::ConvertStringToArgs(cmdline
);
237 size_t count
= args
.GetCount();
238 wxPrintf(wxT("\targc = %u\n"), count
);
239 for ( size_t arg
= 0; arg
< count
; arg
++ )
241 wxPrintf(wxT("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
246 #endif // TEST_CMDLINE
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
257 static const wxChar
*ROOTDIR
= wxT("/");
258 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
259 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
260 static const wxChar
*ROOTDIR
= wxT("c:\\");
261 static const wxChar
*TESTDIR
= wxT("d:\\");
263 #error "don't know where the root directory is"
266 static void TestDirEnumHelper(wxDir
& dir
,
267 int flags
= wxDIR_DEFAULT
,
268 const wxString
& filespec
= wxEmptyString
)
272 if ( !dir
.IsOpened() )
275 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
278 wxPrintf(wxT("\t%s\n"), filename
.c_str());
280 cont
= dir
.GetNext(&filename
);
283 wxPuts(wxEmptyString
);
288 static void TestDirEnum()
290 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
292 wxString cwd
= wxGetCwd();
293 if ( !wxDir
::Exists(cwd
) )
295 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
300 if ( !dir
.IsOpened() )
302 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
306 wxPuts(wxT("Enumerating everything in current directory:"));
307 TestDirEnumHelper(dir
);
309 wxPuts(wxT("Enumerating really everything in current directory:"));
310 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
312 wxPuts(wxT("Enumerating object files in current directory:"));
313 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
315 wxPuts(wxT("Enumerating directories in current directory:"));
316 TestDirEnumHelper(dir
, wxDIR_DIRS
);
318 wxPuts(wxT("Enumerating files in current directory:"));
319 TestDirEnumHelper(dir
, wxDIR_FILES
);
321 wxPuts(wxT("Enumerating files including hidden in current directory:"));
322 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
326 wxPuts(wxT("Enumerating everything in root directory:"));
327 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
329 wxPuts(wxT("Enumerating directories in root directory:"));
330 TestDirEnumHelper(dir
, wxDIR_DIRS
);
332 wxPuts(wxT("Enumerating files in root directory:"));
333 TestDirEnumHelper(dir
, wxDIR_FILES
);
335 wxPuts(wxT("Enumerating files including hidden in root directory:"));
336 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
338 wxPuts(wxT("Enumerating files in non existing directory:"));
339 wxDir
dirNo(wxT("nosuchdir"));
340 TestDirEnumHelper(dirNo
);
345 class DirPrintTraverser
: public wxDirTraverser
348 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
350 return wxDIR_CONTINUE
;
353 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
355 wxString path
, name
, ext
;
356 wxFileName
::SplitPath(dirname
, &path
, &name
, &ext
);
359 name
<< wxT('.') << ext
;
362 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
364 if ( wxIsPathSeparator(*p
) )
368 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
370 return wxDIR_CONTINUE
;
374 static void TestDirTraverse()
376 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
380 size_t n
= wxDir
::GetAllFiles(TESTDIR
, &files
);
381 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
384 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
385 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
388 // enum again with custom traverser
389 wxPuts(wxT("Now enumerating directories:"));
391 DirPrintTraverser traverser
;
392 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
397 static void TestDirExists()
399 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
401 static const wxChar
*dirnames
[] =
404 #if defined(__WXMSW__)
407 wxT("\\\\share\\file"),
411 wxT("c:\\autoexec.bat"),
412 #elif defined(__UNIX__)
421 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
423 wxPrintf(wxT("%-40s: %s\n"),
425 wxDir
::Exists(dirnames
[n
]) ?
wxT("exists")
426 : wxT("doesn't exist"));
434 // ----------------------------------------------------------------------------
436 // ----------------------------------------------------------------------------
440 #include "wx/dynlib.h"
442 static void TestDllLoad()
444 #if defined(__WXMSW__)
445 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
446 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
447 #elif defined(__UNIX__)
448 // weird: using just libc.so does *not* work!
449 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
450 static const wxChar
*FUNC_NAME
= wxT("strlen");
452 #error "don't know how to test wxDllLoader on this platform"
455 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
457 wxDynamicLibrary
lib(LIB_NAME
);
458 if ( !lib
.IsLoaded() )
460 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
464 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
465 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
468 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
469 FUNC_NAME
, LIB_NAME
);
473 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
474 FUNC_NAME
, LIB_NAME
);
476 if ( pfnStrlen("foo") != 3 )
478 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
482 wxPuts(wxT("... ok"));
487 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
489 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
491 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
492 if ( !pfnStrlenAorW
)
494 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
495 FUNC_NAME_AW
, LIB_NAME
);
499 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
501 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
508 #if defined(__WXMSW__) || defined(__UNIX__)
510 static void TestDllListLoaded()
512 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
514 puts("\nLoaded modules:");
515 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary
::ListLoaded();
516 const size_t count
= dlls
.GetCount();
517 for ( size_t n
= 0; n
< count
; ++n
)
519 const wxDynamicLibraryDetails
& details
= dlls
[n
];
520 printf("%-45s", (const char *)details
.GetPath().mb_str());
522 void *addr
wxDUMMY_INITIALIZE(NULL
);
523 size_t len
wxDUMMY_INITIALIZE(0);
524 if ( details
.GetAddress(&addr
, &len
) )
526 printf(" %08lx:%08lx",
527 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
530 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
536 #endif // TEST_DYNLIB
538 // ----------------------------------------------------------------------------
540 // ----------------------------------------------------------------------------
544 #include "wx/utils.h"
546 static wxString
MyGetEnv(const wxString
& var
)
549 if ( !wxGetEnv(var
, &val
) )
550 val
= wxT("<empty>");
552 val
= wxString(wxT('\'')) + val
+ wxT('\'');
557 static void TestEnvironment()
559 const wxChar
*var
= wxT("wxTestVar");
561 wxPuts(wxT("*** testing environment access functions ***"));
563 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
564 wxSetEnv(var
, wxT("value for wxTestVar"));
565 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
566 wxSetEnv(var
, wxT("another value"));
567 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
569 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
570 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
573 #endif // TEST_ENVIRON
575 // ----------------------------------------------------------------------------
577 // ----------------------------------------------------------------------------
582 #include "wx/ffile.h"
583 #include "wx/textfile.h"
585 static void TestFileRead()
587 wxPuts(wxT("*** wxFile read test ***"));
589 wxFile
file(wxT("testdata.fc"));
590 if ( file
.IsOpened() )
592 wxPrintf(wxT("File length: %lu\n"), file
.Length());
594 wxPuts(wxT("File dump:\n----------"));
596 static const size_t len
= 1024;
600 size_t nRead
= file
.Read(buf
, len
);
601 if ( nRead
== (size_t)wxInvalidOffset
)
603 wxPrintf(wxT("Failed to read the file."));
607 fwrite(buf
, nRead
, 1, stdout
);
613 wxPuts(wxT("----------"));
617 wxPrintf(wxT("ERROR: can't open test file.\n"));
620 wxPuts(wxEmptyString
);
623 static void TestTextFileRead()
625 wxPuts(wxT("*** wxTextFile read test ***"));
627 wxTextFile
file(wxT("testdata.fc"));
630 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
631 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
635 wxPuts(wxT("\nDumping the entire file:"));
636 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
638 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
640 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
642 wxPuts(wxT("\nAnd now backwards:"));
643 for ( s
= file
.GetLastLine();
644 file
.GetCurrentLine() != 0;
645 s
= file
.GetPrevLine() )
647 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
649 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
653 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
656 wxPuts(wxEmptyString
);
659 static void TestFileCopy()
661 wxPuts(wxT("*** Testing wxCopyFile ***"));
663 static const wxChar
*filename1
= wxT("testdata.fc");
664 static const wxChar
*filename2
= wxT("test2");
665 if ( !wxCopyFile(filename1
, filename2
) )
667 wxPuts(wxT("ERROR: failed to copy file"));
671 wxFFile
f1(filename1
, wxT("rb")),
672 f2(filename2
, wxT("rb"));
674 if ( !f1
.IsOpened() || !f2
.IsOpened() )
676 wxPuts(wxT("ERROR: failed to open file(s)"));
681 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
683 wxPuts(wxT("ERROR: failed to read file(s)"));
687 if ( (s1
.length() != s2
.length()) ||
688 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
690 wxPuts(wxT("ERROR: copy error!"));
694 wxPuts(wxT("File was copied ok."));
700 if ( !wxRemoveFile(filename2
) )
702 wxPuts(wxT("ERROR: failed to remove the file"));
705 wxPuts(wxEmptyString
);
708 static void TestTempFile()
710 wxPuts(wxT("*** wxTempFile test ***"));
713 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
715 if ( tmpFile
.Commit() )
716 wxPuts(wxT("File committed."));
718 wxPuts(wxT("ERROR: could't commit temp file."));
720 wxRemoveFile(wxT("test2"));
723 wxPuts(wxEmptyString
);
728 // ----------------------------------------------------------------------------
730 // ----------------------------------------------------------------------------
734 #include "wx/confbase.h"
735 #include "wx/fileconf.h"
737 static const struct FileConfTestData
739 const wxChar
*name
; // value name
740 const wxChar
*value
; // the value from the file
743 { wxT("value1"), wxT("one") },
744 { wxT("value2"), wxT("two") },
745 { wxT("novalue"), wxT("default") },
748 static void TestFileConfRead()
750 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
752 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
753 wxT("testdata.fc"), wxEmptyString
,
754 wxCONFIG_USE_RELATIVE_PATH
);
756 // test simple reading
757 wxPuts(wxT("\nReading config file:"));
758 wxString
defValue(wxT("default")), value
;
759 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
761 const FileConfTestData
& data
= fcTestData
[n
];
762 value
= fileconf
.Read(data
.name
, defValue
);
763 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
764 if ( value
== data
.value
)
770 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
774 // test enumerating the entries
775 wxPuts(wxT("\nEnumerating all root entries:"));
778 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
781 wxPrintf(wxT("\t%s = %s\n"),
783 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
785 cont
= fileconf
.GetNextEntry(name
, dummy
);
788 static const wxChar
*testEntry
= wxT("TestEntry");
789 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
790 fileconf
.Write(testEntry
, wxT("A value"));
791 fileconf
.DeleteEntry(testEntry
);
792 wxPrintf(fileconf
.HasEntry(testEntry
) ?
wxT("ERROR\n") : wxT("ok\n"));
795 #endif // TEST_FILECONF
797 // ----------------------------------------------------------------------------
799 // ----------------------------------------------------------------------------
803 #include "wx/filename.h"
806 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
810 wxString full
= fn
.GetFullPath();
812 wxString vol
, path
, name
, ext
;
813 wxFileName
::SplitPath(full
, &vol
, &path
, &name
, &ext
);
815 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
816 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
818 wxFileName
::SplitPath(full
, &path
, &name
, &ext
);
819 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
820 path
.c_str(), name
.c_str(), ext
.c_str());
822 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
823 wxPrintf(wxT("with volume: \t'%s'\n"),
824 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
825 wxPrintf(wxT("with separator:\t'%s'\n"),
826 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
827 wxPrintf(wxT("with both: \t'%s'\n"),
828 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
830 wxPuts(wxT("The directories in the path are:"));
831 wxArrayString dirs
= fn
.GetDirs();
832 size_t count
= dirs
.GetCount();
833 for ( size_t n
= 0; n
< count
; n
++ )
835 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
840 static void TestFileNameTemp()
842 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
844 static const wxChar
*tmpprefixes
[] =
852 wxT("/tmp/foo/bar"), // this one must be an error
856 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
858 wxString path
= wxFileName
::CreateTempFileName(tmpprefixes
[n
]);
861 // "error" is not in upper case because it may be ok
862 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
866 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
867 tmpprefixes
[n
], path
.c_str());
869 if ( !wxRemoveFile(path
) )
871 wxLogWarning(wxT("Failed to remove temp file '%s'"),
878 static void TestFileNameDirManip()
880 // TODO: test AppendDir(), RemoveDir(), ...
883 static void TestFileNameComparison()
888 static void TestFileNameOperations()
893 static void TestFileNameCwd()
898 #endif // TEST_FILENAME
900 // ----------------------------------------------------------------------------
901 // wxFileName time functions
902 // ----------------------------------------------------------------------------
906 #include "wx/filename.h"
907 #include "wx/datetime.h"
909 static void TestFileGetTimes()
911 wxFileName
fn(wxT("testdata.fc"));
913 wxDateTime dtAccess
, dtMod
, dtCreate
;
914 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
916 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
920 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
922 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
923 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
924 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
925 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
930 static void TestFileSetTimes()
932 wxFileName
fn(wxT("testdata.fc"));
936 wxPrintf(wxT("ERROR: Touch() failed.\n"));
941 #endif // TEST_FILETIME
943 // ----------------------------------------------------------------------------
945 // ----------------------------------------------------------------------------
950 #include "wx/utils.h" // for wxSetEnv
952 static wxLocale gs_localeDefault
;
953 // NOTE: don't init it here as it needs a wxAppTraits object
954 // and thus must be init-ed after creation of the wxInitializer
955 // class in the main()
957 // find the name of the language from its value
958 static const wxChar
*GetLangName(int lang
)
960 static const wxChar
*languageNames
[] =
970 wxT("ARABIC_ALGERIA"),
971 wxT("ARABIC_BAHRAIN"),
974 wxT("ARABIC_JORDAN"),
975 wxT("ARABIC_KUWAIT"),
976 wxT("ARABIC_LEBANON"),
978 wxT("ARABIC_MOROCCO"),
981 wxT("ARABIC_SAUDI_ARABIA"),
984 wxT("ARABIC_TUNISIA"),
991 wxT("AZERI_CYRILLIC"),
1006 wxT("CHINESE_SIMPLIFIED"),
1007 wxT("CHINESE_TRADITIONAL"),
1008 wxT("CHINESE_HONGKONG"),
1009 wxT("CHINESE_MACAU"),
1010 wxT("CHINESE_SINGAPORE"),
1011 wxT("CHINESE_TAIWAN"),
1017 wxT("DUTCH_BELGIAN"),
1021 wxT("ENGLISH_AUSTRALIA"),
1022 wxT("ENGLISH_BELIZE"),
1023 wxT("ENGLISH_BOTSWANA"),
1024 wxT("ENGLISH_CANADA"),
1025 wxT("ENGLISH_CARIBBEAN"),
1026 wxT("ENGLISH_DENMARK"),
1027 wxT("ENGLISH_EIRE"),
1028 wxT("ENGLISH_JAMAICA"),
1029 wxT("ENGLISH_NEW_ZEALAND"),
1030 wxT("ENGLISH_PHILIPPINES"),
1031 wxT("ENGLISH_SOUTH_AFRICA"),
1032 wxT("ENGLISH_TRINIDAD"),
1033 wxT("ENGLISH_ZIMBABWE"),
1041 wxT("FRENCH_BELGIAN"),
1042 wxT("FRENCH_CANADIAN"),
1043 wxT("FRENCH_LUXEMBOURG"),
1044 wxT("FRENCH_MONACO"),
1045 wxT("FRENCH_SWISS"),
1050 wxT("GERMAN_AUSTRIAN"),
1051 wxT("GERMAN_BELGIUM"),
1052 wxT("GERMAN_LIECHTENSTEIN"),
1053 wxT("GERMAN_LUXEMBOURG"),
1054 wxT("GERMAN_SWISS"),
1071 wxT("ITALIAN_SWISS"),
1076 wxT("KASHMIRI_INDIA"),
1094 wxT("MALAY_BRUNEI_DARUSSALAM"),
1095 wxT("MALAY_MALAYSIA"),
1104 wxT("NEPALI_INDIA"),
1105 wxT("NORWEGIAN_BOKMAL"),
1106 wxT("NORWEGIAN_NYNORSK"),
1113 wxT("PORTUGUESE_BRAZILIAN"),
1116 wxT("RHAETO_ROMANCE"),
1119 wxT("RUSSIAN_UKRAINE"),
1123 wxT("SCOTS_GAELIC"),
1125 wxT("SERBIAN_CYRILLIC"),
1126 wxT("SERBIAN_LATIN"),
1127 wxT("SERBO_CROATIAN"),
1138 wxT("SPANISH_ARGENTINA"),
1139 wxT("SPANISH_BOLIVIA"),
1140 wxT("SPANISH_CHILE"),
1141 wxT("SPANISH_COLOMBIA"),
1142 wxT("SPANISH_COSTA_RICA"),
1143 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1144 wxT("SPANISH_ECUADOR"),
1145 wxT("SPANISH_EL_SALVADOR"),
1146 wxT("SPANISH_GUATEMALA"),
1147 wxT("SPANISH_HONDURAS"),
1148 wxT("SPANISH_MEXICAN"),
1149 wxT("SPANISH_MODERN"),
1150 wxT("SPANISH_NICARAGUA"),
1151 wxT("SPANISH_PANAMA"),
1152 wxT("SPANISH_PARAGUAY"),
1153 wxT("SPANISH_PERU"),
1154 wxT("SPANISH_PUERTO_RICO"),
1155 wxT("SPANISH_URUGUAY"),
1157 wxT("SPANISH_VENEZUELA"),
1161 wxT("SWEDISH_FINLAND"),
1179 wxT("URDU_PAKISTAN"),
1181 wxT("UZBEK_CYRILLIC"),
1194 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1195 return languageNames
[lang
];
1197 return wxT("INVALID");
1200 static void TestDefaultLang()
1202 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1204 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1206 static const wxChar
*langStrings
[] =
1208 NULL
, // system default
1215 wxT("de_DE.iso88591"),
1217 wxT("?"), // invalid lang spec
1218 wxT("klingonese"), // I bet on some systems it does exist...
1221 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1222 wxLocale
::GetSystemEncodingName().c_str(),
1223 wxLocale
::GetSystemEncoding());
1225 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1227 const wxChar
*langStr
= langStrings
[n
];
1230 // FIXME: this doesn't do anything at all under Windows, we need
1231 // to create a new wxLocale!
1232 wxSetEnv(wxT("LC_ALL"), langStr
);
1235 int lang
= gs_localeDefault
.GetSystemLanguage();
1236 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1237 langStr ? langStr
: wxT("system default"), GetLangName(lang
));
1241 #endif // TEST_LOCALE
1243 // ----------------------------------------------------------------------------
1245 // ----------------------------------------------------------------------------
1249 #include "wx/mimetype.h"
1251 static void TestMimeEnum()
1253 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1255 wxArrayString mimetypes
;
1257 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1259 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1264 for ( size_t n
= 0; n
< count
; n
++ )
1266 wxFileType
*filetype
=
1267 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1270 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1271 mimetypes
[n
].c_str());
1275 filetype
->GetDescription(&desc
);
1276 filetype
->GetExtensions(exts
);
1278 filetype
->GetIcon(NULL
);
1281 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1284 extsAll
<< wxT(", ");
1288 wxPrintf(wxT("\t%s: %s (%s)\n"),
1289 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1292 wxPuts(wxEmptyString
);
1295 static void TestMimeFilename()
1297 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1299 static const wxChar
*filenames
[] =
1302 wxT("document.pdf"),
1304 wxT("picture.jpeg"),
1307 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1309 const wxString fname
= filenames
[n
];
1310 wxString ext
= fname
.AfterLast(wxT('.'));
1311 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1314 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1319 if ( !ft
->GetDescription(&desc
) )
1320 desc
= wxT("<no description>");
1323 if ( !ft
->GetOpenCommand(&cmd
,
1324 wxFileType
::MessageParameters(fname
, wxEmptyString
)) )
1325 cmd
= wxT("<no command available>");
1327 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1329 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1330 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1336 wxPuts(wxEmptyString
);
1339 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1342 static void TestMimeOverride()
1344 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1346 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1347 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1349 if ( wxFile
::Exists(mailcap
) )
1350 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1352 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ?
wxT("ok") : wxT("ERROR"));
1354 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1357 if ( wxFile
::Exists(mimetypes
) )
1358 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1360 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ?
wxT("ok") : wxT("ERROR"));
1362 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1365 wxPuts(wxEmptyString
);
1368 static void TestMimeAssociate()
1370 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1372 wxFileTypeInfo
ftInfo(
1373 wxT("application/x-xyz"),
1374 wxT("xyzview '%s'"), // open cmd
1375 wxT(""), // print cmd
1376 wxT("XYZ File"), // description
1377 wxT(".xyz"), // extensions
1378 wxNullPtr
// end of extensions
1380 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1382 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1385 wxPuts(wxT("ERROR: failed to create association!"));
1389 // TODO: read it back
1393 wxPuts(wxEmptyString
);
1400 // ----------------------------------------------------------------------------
1401 // module dependencies feature
1402 // ----------------------------------------------------------------------------
1406 #include "wx/module.h"
1408 class wxTestModule
: public wxModule
1411 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1412 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1415 class wxTestModuleA
: public wxTestModule
1420 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1423 class wxTestModuleB
: public wxTestModule
1428 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1431 class wxTestModuleC
: public wxTestModule
1436 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1439 class wxTestModuleD
: public wxTestModule
1444 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1447 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1448 wxTestModuleC
::wxTestModuleC()
1450 AddDependency(CLASSINFO(wxTestModuleD
));
1453 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1454 wxTestModuleA
::wxTestModuleA()
1456 AddDependency(CLASSINFO(wxTestModuleB
));
1457 AddDependency(CLASSINFO(wxTestModuleD
));
1460 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1461 wxTestModuleD
::wxTestModuleD()
1465 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1466 wxTestModuleB
::wxTestModuleB()
1468 AddDependency(CLASSINFO(wxTestModuleD
));
1469 AddDependency(CLASSINFO(wxTestModuleC
));
1472 #endif // TEST_MODULE
1474 // ----------------------------------------------------------------------------
1475 // misc information functions
1476 // ----------------------------------------------------------------------------
1478 #ifdef TEST_INFO_FUNCTIONS
1480 #include "wx/utils.h"
1482 #if TEST_INTERACTIVE
1483 static void TestDiskInfo()
1485 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1489 wxChar pathname
[128];
1490 wxPrintf(wxT("\nEnter a directory name: "));
1491 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1494 // kill the last '\n'
1495 pathname
[wxStrlen(pathname
) - 1] = 0;
1497 wxLongLong total
, free
;
1498 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1500 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1504 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1505 (total
/ 1024).ToString().c_str(),
1506 (free
/ 1024).ToString().c_str(),
1511 #endif // TEST_INTERACTIVE
1513 static void TestOsInfo()
1515 wxPuts(wxT("*** Testing OS info functions ***\n"));
1518 wxGetOsVersion(&major
, &minor
);
1519 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1520 wxGetOsDescription().c_str(), major
, minor
);
1522 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1524 wxPrintf(wxT("Host name is %s (%s).\n"),
1525 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1527 wxPuts(wxEmptyString
);
1530 static void TestPlatformInfo()
1532 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1534 // get this platform
1535 wxPlatformInfo plat
;
1537 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1538 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1539 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1540 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1541 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1542 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1544 wxPuts(wxEmptyString
);
1547 static void TestUserInfo()
1549 wxPuts(wxT("*** Testing user info functions ***\n"));
1551 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1552 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1553 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1554 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1556 wxPuts(wxEmptyString
);
1559 #endif // TEST_INFO_FUNCTIONS
1561 // ----------------------------------------------------------------------------
1563 // ----------------------------------------------------------------------------
1565 #ifdef TEST_PATHLIST
1568 #define CMD_IN_PATH wxT("ls")
1570 #define CMD_IN_PATH wxT("command.com")
1573 static void TestPathList()
1575 wxPuts(wxT("*** Testing wxPathList ***\n"));
1577 wxPathList pathlist
;
1578 pathlist
.AddEnvList(wxT("PATH"));
1579 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1582 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1586 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1590 #endif // TEST_PATHLIST
1592 // ----------------------------------------------------------------------------
1593 // regular expressions
1594 // ----------------------------------------------------------------------------
1596 #if defined TEST_REGEX && TEST_INTERACTIVE
1598 #include "wx/regex.h"
1600 static void TestRegExInteractive()
1602 wxPuts(wxT("*** Testing RE interactively ***"));
1606 wxChar pattern
[128];
1607 wxPrintf(wxT("\nEnter a pattern: "));
1608 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1611 // kill the last '\n'
1612 pattern
[wxStrlen(pattern
) - 1] = 0;
1615 if ( !re
.Compile(pattern
) )
1623 wxPrintf(wxT("Enter text to match: "));
1624 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1627 // kill the last '\n'
1628 text
[wxStrlen(text
) - 1] = 0;
1630 if ( !re
.Matches(text
) )
1632 wxPrintf(wxT("No match.\n"));
1636 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1639 for ( size_t n
= 1; ; n
++ )
1641 if ( !re
.GetMatch(&start
, &len
, n
) )
1646 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1647 n
, wxString(text
+ start
, len
).c_str());
1654 #endif // TEST_REGEX
1656 // ----------------------------------------------------------------------------
1658 // ----------------------------------------------------------------------------
1661 NB: this stuff was taken from the glibc test suite and modified to build
1662 in wxWidgets: if I read the copyright below properly, this shouldn't
1668 #ifdef wxTEST_PRINTF
1669 // use our functions from wxchar.cpp
1673 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1674 // in the tests below
1675 int wxPrintf( const wxChar
*format
, ... );
1676 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1679 #include "wx/longlong.h"
1683 static void rfg1 (void);
1684 static void rfg2 (void);
1688 fmtchk (const wxChar
*fmt
)
1690 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1691 (void) wxPrintf(fmt
, 0x12);
1692 (void) wxPrintf(wxT("'\n"));
1696 fmtst1chk (const wxChar
*fmt
)
1698 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1699 (void) wxPrintf(fmt
, 4, 0x12);
1700 (void) wxPrintf(wxT("'\n"));
1704 fmtst2chk (const wxChar
*fmt
)
1706 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1707 (void) wxPrintf(fmt
, 4, 4, 0x12);
1708 (void) wxPrintf(wxT("'\n"));
1711 /* This page is covered by the following copyright: */
1713 /* (C) Copyright C E Chew
1715 * Feel free to copy, use and distribute this software provided:
1717 * 1. you do not pretend that you wrote it
1718 * 2. you leave this copyright notice intact.
1722 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1729 /* Formatted Output Test
1731 * This exercises the output formatting code.
1734 wxChar
*PointerNull
= NULL
;
1741 wxChar
*prefix
= buf
;
1744 wxPuts(wxT("\nFormatted output test"));
1745 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1746 wxStrcpy(prefix
, wxT("%"));
1747 for (i
= 0; i
< 2; i
++) {
1748 for (j
= 0; j
< 2; j
++) {
1749 for (k
= 0; k
< 2; k
++) {
1750 for (l
= 0; l
< 2; l
++) {
1751 wxStrcpy(prefix
, wxT("%"));
1752 if (i
== 0) wxStrcat(prefix
, wxT("-"));
1753 if (j
== 0) wxStrcat(prefix
, wxT("+"));
1754 if (k
== 0) wxStrcat(prefix
, wxT("#"));
1755 if (l
== 0) wxStrcat(prefix
, wxT("0"));
1756 wxPrintf(wxT("%5s |"), prefix
);
1757 wxStrcpy(tp
, prefix
);
1758 wxStrcat(tp
, wxT("6d |"));
1760 wxStrcpy(tp
, prefix
);
1761 wxStrcat(tp
, wxT("6o |"));
1763 wxStrcpy(tp
, prefix
);
1764 wxStrcat(tp
, wxT("6x |"));
1766 wxStrcpy(tp
, prefix
);
1767 wxStrcat(tp
, wxT("6X |"));
1769 wxStrcpy(tp
, prefix
);
1770 wxStrcat(tp
, wxT("6u |"));
1772 wxPrintf(wxT("\n"));
1777 wxPrintf(wxT("%10s\n"), PointerNull
);
1778 wxPrintf(wxT("%-10s\n"), PointerNull
);
1781 static void TestPrintf()
1783 static wxChar shortstr
[] = wxT("Hi, Z.");
1784 static wxChar longstr
[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1785 I am ready for my first lesson today.");
1787 wxString test_format
;
1789 fmtchk(wxT("%.4x"));
1790 fmtchk(wxT("%04x"));
1791 fmtchk(wxT("%4.4x"));
1792 fmtchk(wxT("%04.4x"));
1793 fmtchk(wxT("%4.3x"));
1794 fmtchk(wxT("%04.3x"));
1796 fmtst1chk(wxT("%.*x"));
1797 fmtst1chk(wxT("%0*x"));
1798 fmtst2chk(wxT("%*.*x"));
1799 fmtst2chk(wxT("%0*.*x"));
1801 wxString bad_format
= wxT("bad format:\t\"%b\"\n");
1802 wxPrintf(bad_format
.c_str());
1803 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1805 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1806 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1807 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1808 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1809 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1810 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1811 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1812 test_format
= wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1813 wxPrintf(test_format
.c_str(), -123456);
1814 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1815 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1817 test_format
= wxT("zero-padded string:\t\"%010s\"\n");
1818 wxPrintf(test_format
.c_str(), shortstr
);
1819 test_format
= wxT("left-adjusted Z string:\t\"%-010s\"\n");
1820 wxPrintf(test_format
.c_str(), shortstr
);
1821 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr
);
1822 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1823 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull
);
1824 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr
);
1826 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1827 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1828 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1829 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20
);
1830 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1831 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1832 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1833 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1834 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1835 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1836 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1837 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20
);
1839 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1840 wxPrintf (wxT(" %6.5f\n"), .1);
1841 wxPrintf (wxT("x%5.4fx\n"), .5);
1843 wxPrintf (wxT("%#03x\n"), 1);
1845 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1851 while (niter
-- != 0)
1852 wxPrintf (wxT("%.17e\n"), d
/ 2);
1857 // Open Watcom cause compiler error here
1858 // Error! E173: col(24) floating-point constant too small to represent
1859 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1862 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1863 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1864 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1865 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1866 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1867 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1868 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1869 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1870 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1871 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1876 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), wxT("%30s"), wxT("foo"));
1878 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1879 rc
, WXSIZEOF(buf
), buf
);
1882 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1883 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1889 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1890 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1891 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1892 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1893 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1894 wxPrintf (wxT("%g should be 10\n"), 10.0);
1895 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1899 wxPrintf(wxT("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1905 wxSprintf(buf
,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1907 result
|= wxStrcmp (buf
,
1908 wxT("onetwo three "));
1910 wxPuts (result
!= 0 ?
wxT("Test failed!") : wxT("Test ok."));
1917 wxSprintf(buf
, "%07" wxLongLongFmtSpec
"o", wxLL(040000000000));
1919 // for some reason below line fails under Borland
1920 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1923 if (wxStrcmp (buf
, wxT("40000000000")) != 0)
1926 wxPuts (wxT("\tFAILED"));
1928 wxUnusedVar(result
);
1929 wxPuts (wxEmptyString
);
1931 #endif // wxLongLong_t
1933 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1934 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1936 wxPuts (wxT("--- Should be no further output. ---"));
1945 memset (bytes
, '\xff', sizeof bytes
);
1946 wxSprintf (buf
, wxT("foo%hhn\n"), &bytes
[3]);
1947 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1948 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1950 wxPuts (wxT("%hhn overwrite more bytes"));
1955 wxPuts (wxT("%hhn wrote incorrect value"));
1967 wxSprintf (buf
, wxT("%5.s"), wxT("xyz"));
1968 if (wxStrcmp (buf
, wxT(" ")) != 0)
1969 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" "));
1970 wxSprintf (buf
, wxT("%5.f"), 33.3);
1971 if (wxStrcmp (buf
, wxT(" 33")) != 0)
1972 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 33"));
1973 wxSprintf (buf
, wxT("%8.e"), 33.3e7
);
1974 if (wxStrcmp (buf
, wxT(" 3e+08")) != 0)
1975 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3e+08"));
1976 wxSprintf (buf
, wxT("%8.E"), 33.3e7
);
1977 if (wxStrcmp (buf
, wxT(" 3E+08")) != 0)
1978 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3E+08"));
1979 wxSprintf (buf
, wxT("%.g"), 33.3);
1980 if (wxStrcmp (buf
, wxT("3e+01")) != 0)
1981 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3e+01"));
1982 wxSprintf (buf
, wxT("%.G"), 33.3);
1983 if (wxStrcmp (buf
, wxT("3E+01")) != 0)
1984 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3E+01"));
1992 wxString test_format
;
1995 wxSprintf (buf
, wxT("%.*g"), prec
, 3.3);
1996 if (wxStrcmp (buf
, wxT("3")) != 0)
1997 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1999 wxSprintf (buf
, wxT("%.*G"), prec
, 3.3);
2000 if (wxStrcmp (buf
, wxT("3")) != 0)
2001 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
2003 wxSprintf (buf
, wxT("%7.*G"), prec
, 3.33);
2004 if (wxStrcmp (buf
, wxT(" 3")) != 0)
2005 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3"));
2007 test_format
= wxT("%04.*o");
2008 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2009 if (wxStrcmp (buf
, wxT(" 041")) != 0)
2010 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 041"));
2012 test_format
= wxT("%09.*u");
2013 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2014 if (wxStrcmp (buf
, wxT(" 0000033")) != 0)
2015 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 0000033"));
2017 test_format
= wxT("%04.*x");
2018 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2019 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2020 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2022 test_format
= wxT("%04.*X");
2023 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2024 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2025 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2028 #endif // TEST_PRINTF
2030 // ----------------------------------------------------------------------------
2031 // registry and related stuff
2032 // ----------------------------------------------------------------------------
2034 // this is for MSW only
2037 #undef TEST_REGISTRY
2042 #include "wx/confbase.h"
2043 #include "wx/msw/regconf.h"
2046 static void TestRegConfWrite()
2048 wxConfig
*config
= new wxConfig(wxT("myapp"));
2049 config
->SetPath(wxT("/group1"));
2050 config
->Write(wxT("entry1"), wxT("foo"));
2051 config
->SetPath(wxT("/group2"));
2052 config
->Write(wxT("entry1"), wxT("bar"));
2056 static void TestRegConfRead()
2058 wxRegConfig
*config
= new wxRegConfig(wxT("myapp"));
2062 config
->SetPath(wxT("/"));
2063 wxPuts(wxT("Enumerating / subgroups:"));
2064 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2068 bCont
= config
->GetNextGroup(str
, dummy
);
2072 #endif // TEST_REGCONF
2074 #ifdef TEST_REGISTRY
2076 #include "wx/msw/registry.h"
2078 // I chose this one because I liked its name, but it probably only exists under
2080 static const wxChar
*TESTKEY
=
2081 wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2083 static void TestRegistryRead()
2085 wxPuts(wxT("*** testing registry reading ***"));
2087 wxRegKey
key(TESTKEY
);
2088 wxPrintf(wxT("The test key name is '%s'.\n"), key
.GetName().c_str());
2091 wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
2096 size_t nSubKeys
, nValues
;
2097 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2099 wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2102 wxPrintf(wxT("Enumerating values:\n"));
2106 bool cont
= key
.GetFirstValue(value
, dummy
);
2109 wxPrintf(wxT("Value '%s': type "), value
.c_str());
2110 switch ( key
.GetValueType(value
) )
2112 case wxRegKey
::Type_None
: wxPrintf(wxT("ERROR (none)")); break;
2113 case wxRegKey
::Type_String
: wxPrintf(wxT("SZ")); break;
2114 case wxRegKey
::Type_Expand_String
: wxPrintf(wxT("EXPAND_SZ")); break;
2115 case wxRegKey
::Type_Binary
: wxPrintf(wxT("BINARY")); break;
2116 case wxRegKey
::Type_Dword
: wxPrintf(wxT("DWORD")); break;
2117 case wxRegKey
::Type_Multi_String
: wxPrintf(wxT("MULTI_SZ")); break;
2118 default: wxPrintf(wxT("other (unknown)")); break;
2121 wxPrintf(wxT(", value = "));
2122 if ( key
.IsNumericValue(value
) )
2125 key
.QueryValue(value
, &val
);
2126 wxPrintf(wxT("%ld"), val
);
2131 key
.QueryValue(value
, val
);
2132 wxPrintf(wxT("'%s'"), val
.c_str());
2134 key
.QueryRawValue(value
, val
);
2135 wxPrintf(wxT(" (raw value '%s')"), val
.c_str());
2140 cont
= key
.GetNextValue(value
, dummy
);
2144 static void TestRegistryAssociation()
2147 The second call to deleteself genertaes an error message, with a
2148 messagebox saying .flo is crucial to system operation, while the .ddf
2149 call also fails, but with no error message
2154 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2156 key
= wxT("ddxf_auto_file") ;
2157 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2159 key
= wxT("ddxf_auto_file") ;
2160 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2162 key
= wxT("program,0") ;
2163 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2165 key
= wxT("program \"%1\"") ;
2167 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2169 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2171 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2173 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2177 #endif // TEST_REGISTRY
2179 // ----------------------------------------------------------------------------
2181 // ----------------------------------------------------------------------------
2183 #ifdef TEST_SCOPEGUARD
2185 #include "wx/scopeguard.h"
2187 static void function0() { puts("function0()"); }
2188 static void function1(int n
) { printf("function1(%d)\n", n
); }
2189 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2193 void method0() { printf("method0()\n"); }
2194 void method1(int n
) { printf("method1(%d)\n", n
); }
2195 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2198 static void TestScopeGuard()
2200 wxON_BLOCK_EXIT0(function0
);
2201 wxON_BLOCK_EXIT1(function1
, 17);
2202 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2205 wxON_BLOCK_EXIT_OBJ0(obj
, Object
::method0
);
2206 wxON_BLOCK_EXIT_OBJ1(obj
, Object
::method1
, 7);
2207 wxON_BLOCK_EXIT_OBJ2(obj
, Object
::method2
, 2.71, 'e');
2209 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2210 dismissed
.Dismiss();
2215 // ----------------------------------------------------------------------------
2217 // ----------------------------------------------------------------------------
2221 #include "wx/socket.h"
2222 #include "wx/protocol/protocol.h"
2223 #include "wx/protocol/http.h"
2225 static void TestSocketServer()
2227 wxPuts(wxT("*** Testing wxSocketServer ***\n"));
2229 static const int PORT
= 3000;
2234 wxSocketServer
*server
= new wxSocketServer(addr
);
2235 if ( !server
->Ok() )
2237 wxPuts(wxT("ERROR: failed to bind"));
2245 wxPrintf(wxT("Server: waiting for connection on port %d...\n"), PORT
);
2247 wxSocketBase
*socket
= server
->Accept();
2250 wxPuts(wxT("ERROR: wxSocketServer::Accept() failed."));
2254 wxPuts(wxT("Server: got a client."));
2256 server
->SetTimeout(60); // 1 min
2259 while ( !close
&& socket
->IsConnected() )
2262 wxChar ch
= wxT('\0');
2265 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2267 // don't log error if the client just close the connection
2268 if ( socket
->IsConnected() )
2270 wxPuts(wxT("ERROR: in wxSocket::Read."));
2290 wxPrintf(wxT("Server: got '%s'.\n"), s
.c_str());
2291 if ( s
== wxT("close") )
2293 wxPuts(wxT("Closing connection"));
2297 else if ( s
== wxT("quit") )
2302 wxPuts(wxT("Shutting down the server"));
2304 else // not a special command
2306 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2307 socket
->Write("\r\n", 2);
2308 wxPrintf(wxT("Server: wrote '%s'.\n"), s
.c_str());
2314 wxPuts(wxT("Server: lost a client unexpectedly."));
2320 // same as "delete server" but is consistent with GUI programs
2324 static void TestSocketClient()
2326 wxPuts(wxT("*** Testing wxSocketClient ***\n"));
2328 static const wxChar
*hostname
= wxT("www.wxwidgets.org");
2331 addr
.Hostname(hostname
);
2334 wxPrintf(wxT("--- Attempting to connect to %s:80...\n"), hostname
);
2336 wxSocketClient client
;
2337 if ( !client
.Connect(addr
) )
2339 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2343 wxPrintf(wxT("--- Connected to %s:%u...\n"),
2344 addr
.Hostname().c_str(), addr
.Service());
2348 // could use simply "GET" here I suppose
2350 wxString
::Format(wxT("GET http://%s/\r\n"), hostname
);
2351 client
.Write(cmdGet
, cmdGet
.length());
2352 wxPrintf(wxT("--- Sent command '%s' to the server\n"),
2353 MakePrintable(cmdGet
).c_str());
2354 client
.Read(buf
, WXSIZEOF(buf
));
2355 wxPrintf(wxT("--- Server replied:\n%s"), buf
);
2359 #endif // TEST_SOCKETS
2361 // ----------------------------------------------------------------------------
2363 // ----------------------------------------------------------------------------
2367 #include "wx/protocol/ftp.h"
2368 #include "wx/protocol/log.h"
2370 #define FTP_ANONYMOUS
2374 #ifdef FTP_ANONYMOUS
2375 static const wxChar
*directory
= wxT("/pub");
2376 static const wxChar
*filename
= wxT("welcome.msg");
2378 static const wxChar
*directory
= wxT("/etc");
2379 static const wxChar
*filename
= wxT("issue");
2382 static bool TestFtpConnect()
2384 wxPuts(wxT("*** Testing FTP connect ***"));
2386 #ifdef FTP_ANONYMOUS
2387 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
2389 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2390 #else // !FTP_ANONYMOUS
2391 static const wxChar
*hostname
= "localhost";
2394 wxFgets(user
, WXSIZEOF(user
), stdin
);
2395 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2398 wxChar password
[256];
2399 wxPrintf(wxT("Password for %s: "), password
);
2400 wxFgets(password
, WXSIZEOF(password
), stdin
);
2401 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2402 ftp
->SetPassword(password
);
2404 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2405 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2407 if ( !ftp
->Connect(hostname
) )
2409 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2415 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
2416 hostname
, ftp
->Pwd().c_str());
2423 static void TestFtpList()
2425 wxPuts(wxT("*** Testing wxFTP file listing ***\n"));
2428 if ( !ftp
->ChDir(directory
) )
2430 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory
);
2433 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2435 // test NLIST and LIST
2436 wxArrayString files
;
2437 if ( !ftp
->GetFilesList(files
) )
2439 wxPuts(wxT("ERROR: failed to get NLIST of files"));
2443 wxPrintf(wxT("Brief list of files under '%s':\n"), ftp
->Pwd().c_str());
2444 size_t count
= files
.GetCount();
2445 for ( size_t n
= 0; n
< count
; n
++ )
2447 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2449 wxPuts(wxT("End of the file list"));
2452 if ( !ftp
->GetDirList(files
) )
2454 wxPuts(wxT("ERROR: failed to get LIST of files"));
2458 wxPrintf(wxT("Detailed list of files under '%s':\n"), ftp
->Pwd().c_str());
2459 size_t count
= files
.GetCount();
2460 for ( size_t n
= 0; n
< count
; n
++ )
2462 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2464 wxPuts(wxT("End of the file list"));
2467 if ( !ftp
->ChDir(wxT("..")) )
2469 wxPuts(wxT("ERROR: failed to cd to .."));
2472 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2475 static void TestFtpDownload()
2477 wxPuts(wxT("*** Testing wxFTP download ***\n"));
2480 wxInputStream
*in
= ftp
->GetInputStream(filename
);
2483 wxPrintf(wxT("ERROR: couldn't get input stream for %s\n"), filename
);
2487 size_t size
= in
->GetSize();
2488 wxPrintf(wxT("Reading file %s (%u bytes)..."), filename
, size
);
2491 wxChar
*data
= new wxChar
[size
];
2492 if ( !in
->Read(data
, size
) )
2494 wxPuts(wxT("ERROR: read error"));
2498 wxPrintf(wxT("\nContents of %s:\n%s\n"), filename
, data
);
2506 static void TestFtpFileSize()
2508 wxPuts(wxT("*** Testing FTP SIZE command ***"));
2510 if ( !ftp
->ChDir(directory
) )
2512 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory
);
2515 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2517 if ( ftp
->FileExists(filename
) )
2519 int size
= ftp
->GetFileSize(filename
);
2521 wxPrintf(wxT("ERROR: couldn't get size of '%s'\n"), filename
);
2523 wxPrintf(wxT("Size of '%s' is %d bytes.\n"), filename
, size
);
2527 wxPrintf(wxT("ERROR: '%s' doesn't exist\n"), filename
);
2531 static void TestFtpMisc()
2533 wxPuts(wxT("*** Testing miscellaneous wxFTP functions ***"));
2535 if ( ftp
->SendCommand(wxT("STAT")) != '2' )
2537 wxPuts(wxT("ERROR: STAT failed"));
2541 wxPrintf(wxT("STAT returned:\n\n%s\n"), ftp
->GetLastResult().c_str());
2544 if ( ftp
->SendCommand(wxT("HELP SITE")) != '2' )
2546 wxPuts(wxT("ERROR: HELP SITE failed"));
2550 wxPrintf(wxT("The list of site-specific commands:\n\n%s\n"),
2551 ftp
->GetLastResult().c_str());
2555 #if TEST_INTERACTIVE
2557 static void TestFtpInteractive()
2559 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
2565 wxPrintf(wxT("Enter FTP command: "));
2566 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2569 // kill the last '\n'
2570 buf
[wxStrlen(buf
) - 1] = 0;
2572 // special handling of LIST and NLST as they require data connection
2573 wxString
start(buf
, 4);
2575 if ( start
== wxT("LIST") || start
== wxT("NLST") )
2578 if ( wxStrlen(buf
) > 4 )
2581 wxArrayString files
;
2582 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
2584 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
2588 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2589 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2590 size_t count
= files
.GetCount();
2591 for ( size_t n
= 0; n
< count
; n
++ )
2593 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2595 wxPuts(wxT("--- End of the file list"));
2600 wxChar ch
= ftp
->SendCommand(buf
);
2601 wxPrintf(wxT("Command %s"), ch ?
wxT("succeeded") : wxT("failed"));
2604 wxPrintf(wxT(" (return code %c)"), ch
);
2607 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2611 wxPuts(wxT("\n*** done ***"));
2614 #endif // TEST_INTERACTIVE
2616 static void TestFtpUpload()
2618 wxPuts(wxT("*** Testing wxFTP uploading ***\n"));
2621 static const wxChar
*file1
= wxT("test1");
2622 static const wxChar
*file2
= wxT("test2");
2623 wxOutputStream
*out
= ftp
->GetOutputStream(file1
);
2626 wxPrintf(wxT("--- Uploading to %s ---\n"), file1
);
2627 out
->Write("First hello", 11);
2631 // send a command to check the remote file
2632 if ( ftp
->SendCommand(wxString(wxT("STAT ")) + file1
) != '2' )
2634 wxPrintf(wxT("ERROR: STAT %s failed\n"), file1
);
2638 wxPrintf(wxT("STAT %s returned:\n\n%s\n"),
2639 file1
, ftp
->GetLastResult().c_str());
2642 out
= ftp
->GetOutputStream(file2
);
2645 wxPrintf(wxT("--- Uploading to %s ---\n"), file1
);
2646 out
->Write("Second hello", 12);
2653 // ----------------------------------------------------------------------------
2655 // ----------------------------------------------------------------------------
2657 #ifdef TEST_STACKWALKER
2659 #if wxUSE_STACKWALKER
2661 #include "wx/stackwalk.h"
2663 class StackDump
: public wxStackWalker
2666 StackDump(const char *argv0
)
2667 : wxStackWalker(argv0
)
2671 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
2673 wxPuts(wxT("Stack dump:"));
2675 wxStackWalker
::Walk(skip
, maxdepth
);
2679 virtual void OnStackFrame(const wxStackFrame
& frame
)
2681 printf("[%2d] ", (int) frame
.GetLevel());
2683 wxString name
= frame
.GetName();
2684 if ( !name
.empty() )
2686 printf("%-20.40s", (const char*)name
.mb_str());
2690 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2693 if ( frame
.HasSourceLocation() )
2696 (const char*)frame
.GetFileName().mb_str(),
2697 (int)frame
.GetLine());
2703 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2705 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2706 (const char*)name
.mb_str(),
2707 (const char*)val
.mb_str());
2712 static void TestStackWalk(const char *argv0
)
2714 wxPuts(wxT("*** Testing wxStackWalker ***\n"));
2716 StackDump
dump(argv0
);
2720 #endif // wxUSE_STACKWALKER
2722 #endif // TEST_STACKWALKER
2724 // ----------------------------------------------------------------------------
2726 // ----------------------------------------------------------------------------
2728 #ifdef TEST_STDPATHS
2730 #include "wx/stdpaths.h"
2731 #include "wx/wxchar.h" // wxPrintf
2733 static void TestStandardPaths()
2735 wxPuts(wxT("*** Testing wxStandardPaths ***\n"));
2737 wxTheApp
->SetAppName(wxT("console"));
2739 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
2740 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2741 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2742 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2743 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2744 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2745 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2746 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2747 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2748 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2749 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2750 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2751 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
2752 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2753 stdp
.GetLocalizedResourcesDir
2756 wxStandardPaths
::ResourceCat_Messages
2760 #endif // TEST_STDPATHS
2762 // ----------------------------------------------------------------------------
2764 // ----------------------------------------------------------------------------
2768 #include "wx/wfstream.h"
2769 #include "wx/mstream.h"
2771 static void TestFileStream()
2773 wxPuts(wxT("*** Testing wxFileInputStream ***"));
2775 static const wxString filename
= wxT("testdata.fs");
2777 wxFileOutputStream
fsOut(filename
);
2778 fsOut
.Write("foo", 3);
2782 wxFileInputStream
fsIn(filename
);
2783 wxPrintf(wxT("File stream size: %u\n"), fsIn
.GetSize());
2785 while ( (c
=fsIn
.GetC()) != wxEOF
)
2791 if ( !wxRemoveFile(filename
) )
2793 wxPrintf(wxT("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2796 wxPuts(wxT("\n*** wxFileInputStream test done ***"));
2799 static void TestMemoryStream()
2801 wxPuts(wxT("*** Testing wxMemoryOutputStream ***"));
2803 wxMemoryOutputStream memOutStream
;
2804 wxPrintf(wxT("Initially out stream offset: %lu\n"),
2805 (unsigned long)memOutStream
.TellO());
2807 for ( const wxChar
*p
= wxT("Hello, stream!"); *p
; p
++ )
2809 memOutStream
.PutC(*p
);
2812 wxPrintf(wxT("Final out stream offset: %lu\n"),
2813 (unsigned long)memOutStream
.TellO());
2815 wxPuts(wxT("*** Testing wxMemoryInputStream ***"));
2818 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2820 wxMemoryInputStream
memInpStream(buf
, len
);
2821 wxPrintf(wxT("Memory stream size: %u\n"), memInpStream
.GetSize());
2823 while ( (c
=memInpStream
.GetC()) != wxEOF
)
2828 wxPuts(wxT("\n*** wxMemoryInputStream test done ***"));
2831 #endif // TEST_STREAMS
2833 // ----------------------------------------------------------------------------
2835 // ----------------------------------------------------------------------------
2839 #include "wx/stopwatch.h"
2840 #include "wx/utils.h"
2842 static void TestStopWatch()
2844 wxPuts(wxT("*** Testing wxStopWatch ***\n"));
2848 wxPrintf(wxT("Initially paused, after 2 seconds time is..."));
2851 wxPrintf(wxT("\t%ldms\n"), sw
.Time());
2853 wxPrintf(wxT("Resuming stopwatch and sleeping 3 seconds..."));
2857 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2860 wxPrintf(wxT("Pausing agan and sleeping 2 more seconds..."));
2863 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2866 wxPrintf(wxT("Finally resuming and sleeping 2 more seconds..."));
2869 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2872 wxPuts(wxT("\nChecking for 'backwards clock' bug..."));
2873 for ( size_t n
= 0; n
< 70; n
++ )
2877 for ( size_t m
= 0; m
< 100000; m
++ )
2879 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2881 wxPuts(wxT("\ntime is negative - ERROR!"));
2889 wxPuts(wxT(", ok."));
2892 #include "wx/timer.h"
2893 #include "wx/evtloop.h"
2897 wxPuts(wxT("*** Testing wxTimer ***\n"));
2899 class MyTimer
: public wxTimer
2902 MyTimer() : wxTimer() { m_num
= 0; }
2904 virtual void Notify()
2906 wxPrintf(wxT("%d"), m_num
++);
2911 wxPrintf(wxT("... exiting the event loop"));
2914 wxEventLoop
::GetActive()->Exit(0);
2915 wxPuts(wxT(", ok."));
2928 timer1
.Start(100, true /* one shot */);
2930 timer1
.Start(100, true /* one shot */);
2938 #endif // TEST_TIMER
2940 // ----------------------------------------------------------------------------
2942 // ----------------------------------------------------------------------------
2944 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2950 #include "wx/volume.h"
2952 static const wxChar
*volumeKinds
[] =
2958 wxT("network volume"),
2959 wxT("other volume"),
2962 static void TestFSVolume()
2964 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2966 wxArrayString volumes
= wxFSVolume
::GetVolumes();
2967 size_t count
= volumes
.GetCount();
2971 wxPuts(wxT("ERROR: no mounted volumes?"));
2975 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
2977 for ( size_t n
= 0; n
< count
; n
++ )
2979 wxFSVolume
vol(volumes
[n
]);
2982 wxPuts(wxT("ERROR: couldn't create volume"));
2986 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2988 vol
.GetDisplayName().c_str(),
2989 vol
.GetName().c_str(),
2990 volumeKinds
[vol
.GetKind()],
2991 vol
.IsWritable() ?
wxT("rw") : wxT("ro"),
2992 vol
.GetFlags() & wxFS_VOL_REMOVABLE ?
wxT("removable")
2997 #endif // TEST_VOLUME
2999 // ----------------------------------------------------------------------------
3000 // wide char and Unicode support
3001 // ----------------------------------------------------------------------------
3005 #include "wx/strconv.h"
3006 #include "wx/fontenc.h"
3007 #include "wx/encconv.h"
3008 #include "wx/buffer.h"
3010 static const unsigned char utf8koi8r
[] =
3012 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3013 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3014 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3015 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3016 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3017 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3018 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3021 static const unsigned char utf8iso8859_1
[] =
3023 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3024 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3025 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3026 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3027 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3030 static const unsigned char utf8Invalid
[] =
3032 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3033 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3034 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3035 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3039 static const struct Utf8Data
3041 const unsigned char *text
;
3043 const wxChar
*charset
;
3044 wxFontEncoding encoding
;
3047 { utf8Invalid
, WXSIZEOF(utf8Invalid
), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3048 { utf8koi8r
, WXSIZEOF(utf8koi8r
), wxT("koi8-r"), wxFONTENCODING_KOI8
},
3049 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3052 static void TestUtf8()
3054 wxPuts(wxT("*** Testing UTF8 support ***\n"));
3059 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3061 const Utf8Data
& u8d
= utf8data
[n
];
3062 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3063 WXSIZEOF(wbuf
)) == (size_t)-1 )
3065 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3069 wxCSConv
conv(u8d
.charset
);
3070 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3072 wxPrintf(wxT("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3076 wxPrintf(wxT("String in %s: %s\n"), u8d
.charset
, buf
);
3080 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3082 s
= wxT("<< conversion failed >>");
3083 wxPrintf(wxT("String in current cset: %s\n"), s
.c_str());
3087 wxPuts(wxEmptyString
);
3090 static void TestEncodingConverter()
3092 wxPuts(wxT("*** Testing wxEncodingConverter ***\n"));
3094 // using wxEncodingConverter should give the same result as above
3097 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3098 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3100 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3104 wxEncodingConverter ec
;
3105 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3106 ec
.Convert(wbuf
, buf
);
3107 wxPrintf(wxT("The same KOI8-R string using wxEC: %s\n"), buf
);
3110 wxPuts(wxEmptyString
);
3113 #endif // TEST_WCHAR
3115 // ----------------------------------------------------------------------------
3117 // ----------------------------------------------------------------------------
3121 #include "wx/filesys.h"
3122 #include "wx/fs_zip.h"
3123 #include "wx/zipstrm.h"
3125 static const wxChar
*TESTFILE_ZIP
= wxT("testdata.zip");
3127 static void TestZipStreamRead()
3129 wxPuts(wxT("*** Testing ZIP reading ***\n"));
3131 static const wxString filename
= wxT("foo");
3132 wxFFileInputStream
in(TESTFILE_ZIP
);
3133 wxZipInputStream
istr(in
);
3134 wxZipEntry
entry(filename
);
3135 istr
.OpenEntry(entry
);
3137 wxPrintf(wxT("Archive size: %u\n"), istr
.GetSize());
3139 wxPrintf(wxT("Dumping the file '%s':\n"), filename
.c_str());
3141 while ( (c
=istr
.GetC()) != wxEOF
)
3147 wxPuts(wxT("\n----- done ------"));
3150 static void DumpZipDirectory(wxFileSystem
& fs
,
3151 const wxString
& dir
,
3152 const wxString
& indent
)
3154 wxString prefix
= wxString
::Format(wxT("%s#zip:%s"),
3155 TESTFILE_ZIP
, dir
.c_str());
3156 wxString wildcard
= prefix
+ wxT("/*");
3158 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3159 while ( !dirname
.empty() )
3161 if ( !dirname
.StartsWith(prefix
+ wxT('/'), &dirname
) )
3163 wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
3168 wxPrintf(wxT("%s%s\n"), indent
.c_str(), dirname
.c_str());
3170 DumpZipDirectory(fs
, dirname
,
3171 indent
+ wxString(wxT(' '), 4));
3173 dirname
= fs
.FindNext();
3176 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3177 while ( !filename
.empty() )
3179 if ( !filename
.StartsWith(prefix
, &filename
) )
3181 wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
3186 wxPrintf(wxT("%s%s\n"), indent
.c_str(), filename
.c_str());
3188 filename
= fs
.FindNext();
3192 static void TestZipFileSystem()
3194 wxPuts(wxT("*** Testing ZIP file system ***\n"));
3196 wxFileSystem
::AddHandler(new wxZipFSHandler
);
3198 wxPrintf(wxT("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3200 DumpZipDirectory(fs
, wxT(""), wxString(wxT(' '), 4));
3205 // ----------------------------------------------------------------------------
3207 // ----------------------------------------------------------------------------
3209 #ifdef TEST_DATETIME
3211 #include "wx/math.h"
3212 #include "wx/datetime.h"
3214 // this test miscellaneous static wxDateTime functions
3218 static void TestTimeStatic()
3220 wxPuts(wxT("\n*** wxDateTime static methods test ***"));
3222 // some info about the current date
3223 int year
= wxDateTime
::GetCurrentYear();
3224 wxPrintf(wxT("Current year %d is %sa leap one and has %d days.\n"),
3226 wxDateTime
::IsLeapYear(year
) ?
"" : "not ",
3227 wxDateTime
::GetNumberOfDays(year
));
3229 wxDateTime
::Month month
= wxDateTime
::GetCurrentMonth();
3230 wxPrintf(wxT("Current month is '%s' ('%s') and it has %d days\n"),
3231 wxDateTime
::GetMonthName(month
, wxDateTime
::Name_Abbr
).c_str(),
3232 wxDateTime
::GetMonthName(month
).c_str(),
3233 wxDateTime
::GetNumberOfDays(month
));
3236 // test time zones stuff
3237 static void TestTimeZones()
3239 wxPuts(wxT("\n*** wxDateTime timezone test ***"));
3241 wxDateTime now
= wxDateTime
::Now();
3243 wxPrintf(wxT("Current GMT time:\t%s\n"), now
.Format(wxT("%c"), wxDateTime
::GMT0
).c_str());
3244 wxPrintf(wxT("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime
::GMT0
).c_str());
3245 wxPrintf(wxT("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime
::EST
).c_str());
3246 wxPrintf(wxT("Current time in Paris:\t%s\n"), now
.Format(wxT("%c"), wxDateTime
::CET
).c_str());
3247 wxPrintf(wxT(" Moscow:\t%s\n"), now
.Format(wxT("%c"), wxDateTime
::MSK
).c_str());
3248 wxPrintf(wxT(" New York:\t%s\n"), now
.Format(wxT("%c"), wxDateTime
::EST
).c_str());
3250 wxPrintf(wxT("%s\n"), wxDateTime
::Now().Format(wxT("Our timezone is %Z")).c_str());
3252 wxDateTime
::Tm tm
= now
.GetTm();
3253 if ( wxDateTime(tm
) != now
)
3255 wxPrintf(wxT("ERROR: got %s instead of %s\n"),
3256 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3260 // test some minimal support for the dates outside the standard range
3261 static void TestTimeRange()
3263 wxPuts(wxT("\n*** wxDateTime out-of-standard-range dates test ***"));
3265 static const wxChar
*fmt
= wxT("%d-%b-%Y %H:%M:%S");
3267 wxPrintf(wxT("Unix epoch:\t%s\n"),
3268 wxDateTime(2440587.5).Format(fmt
).c_str());
3269 wxPrintf(wxT("Feb 29, 0: \t%s\n"),
3270 wxDateTime(29, wxDateTime
::Feb
, 0).Format(fmt
).c_str());
3271 wxPrintf(wxT("JDN 0: \t%s\n"),
3272 wxDateTime(0.0).Format(fmt
).c_str());
3273 wxPrintf(wxT("Jan 1, 1AD:\t%s\n"),
3274 wxDateTime(1, wxDateTime
::Jan
, 1).Format(fmt
).c_str());
3275 wxPrintf(wxT("May 29, 2099:\t%s\n"),
3276 wxDateTime(29, wxDateTime
::May
, 2099).Format(fmt
).c_str());
3279 // test DST calculations
3280 static void TestTimeDST()
3282 wxPuts(wxT("\n*** wxDateTime DST test ***"));
3284 wxPrintf(wxT("DST is%s in effect now.\n\n"),
3285 wxDateTime
::Now().IsDST() ? wxEmptyString
: wxT(" not"));
3287 for ( int year
= 1990; year
< 2005; year
++ )
3289 wxPrintf(wxT("DST period in Europe for year %d: from %s to %s\n"),
3291 wxDateTime
::GetBeginDST(year
, wxDateTime
::Country_EEC
).Format().c_str(),
3292 wxDateTime
::GetEndDST(year
, wxDateTime
::Country_EEC
).Format().c_str());
3298 #if TEST_INTERACTIVE
3300 static void TestDateTimeInteractive()
3302 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
3308 wxPrintf(wxT("Enter a date: "));
3309 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3312 // kill the last '\n'
3313 buf
[wxStrlen(buf
) - 1] = 0;
3316 const wxChar
*p
= dt
.ParseDate(buf
);
3319 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
3325 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
3328 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
3329 dt
.Format(wxT("%b %d, %Y")).c_str(),
3331 dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
3332 dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
3333 dt
.GetWeekOfYear(wxDateTime
::Monday_First
));
3336 wxPuts(wxT("\n*** done ***"));
3339 #endif // TEST_INTERACTIVE
3343 static void TestTimeMS()
3345 wxPuts(wxT("*** testing millisecond-resolution support in wxDateTime ***"));
3347 wxDateTime dt1
= wxDateTime
::Now(),
3348 dt2
= wxDateTime
::UNow();
3350 wxPrintf(wxT("Now = %s\n"), dt1
.Format(wxT("%H:%M:%S:%l")).c_str());
3351 wxPrintf(wxT("UNow = %s\n"), dt2
.Format(wxT("%H:%M:%S:%l")).c_str());
3352 wxPrintf(wxT("Dummy loop: "));
3353 for ( int i
= 0; i
< 6000; i
++ )
3355 //for ( int j = 0; j < 10; j++ )
3358 s
.Printf(wxT("%g"), sqrt((float)i
));
3364 wxPuts(wxT(", done"));
3367 dt2
= wxDateTime
::UNow();
3368 wxPrintf(wxT("UNow = %s\n"), dt2
.Format(wxT("%H:%M:%S:%l")).c_str());
3370 wxPrintf(wxT("Loop executed in %s ms\n"), (dt2
- dt1
).Format(wxT("%l")).c_str());
3372 wxPuts(wxT("\n*** done ***"));
3375 static void TestTimeHolidays()
3377 wxPuts(wxT("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3379 wxDateTime
::Tm tm
= wxDateTime(29, wxDateTime
::May
, 2000).GetTm();
3380 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3381 dtEnd
= dtStart
.GetLastMonthDay();
3383 wxDateTimeArray hol
;
3384 wxDateTimeHolidayAuthority
::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3386 const wxChar
*format
= wxT("%d-%b-%Y (%a)");
3388 wxPrintf(wxT("All holidays between %s and %s:\n"),
3389 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3391 size_t count
= hol
.GetCount();
3392 for ( size_t n
= 0; n
< count
; n
++ )
3394 wxPrintf(wxT("\t%s\n"), hol
[n
].Format(format
).c_str());
3397 wxPuts(wxEmptyString
);
3400 static void TestTimeZoneBug()
3402 wxPuts(wxT("\n*** testing for DST/timezone bug ***\n"));
3404 wxDateTime date
= wxDateTime(1, wxDateTime
::Mar
, 2000);
3405 for ( int i
= 0; i
< 31; i
++ )
3407 wxPrintf(wxT("Date %s: week day %s.\n"),
3408 date
.Format(wxT("%d-%m-%Y")).c_str(),
3409 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3411 date
+= wxDateSpan
::Day();
3414 wxPuts(wxEmptyString
);
3417 static void TestTimeSpanFormat()
3419 wxPuts(wxT("\n*** wxTimeSpan tests ***"));
3421 static const wxChar
*formats
[] =
3423 wxT("(default) %H:%M:%S"),
3424 wxT("%E weeks and %D days"),
3425 wxT("%l milliseconds"),
3426 wxT("(with ms) %H:%M:%S:%l"),
3427 wxT("100%% of minutes is %M"), // test "%%"
3428 wxT("%D days and %H hours"),
3429 wxT("or also %S seconds"),
3432 wxTimeSpan
ts1(1, 2, 3, 4),
3434 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3436 wxPrintf(wxT("ts1 = %s\tts2 = %s\n"),
3437 ts1
.Format(formats
[n
]).c_str(),
3438 ts2
.Format(formats
[n
]).c_str());
3441 wxPuts(wxEmptyString
);
3446 #endif // TEST_DATETIME
3448 // ----------------------------------------------------------------------------
3449 // wxTextInput/OutputStream
3450 // ----------------------------------------------------------------------------
3452 #ifdef TEST_TEXTSTREAM
3454 #include "wx/txtstrm.h"
3455 #include "wx/wfstream.h"
3457 static void TestTextInputStream()
3459 wxPuts(wxT("\n*** wxTextInputStream test ***"));
3461 wxString filename
= wxT("testdata.fc");
3462 wxFileInputStream
fsIn(filename
);
3465 wxPuts(wxT("ERROR: couldn't open file."));
3469 wxTextInputStream
tis(fsIn
);
3474 const wxString s
= tis
.ReadLine();
3476 // line could be non empty if the last line of the file isn't
3477 // terminated with EOL
3478 if ( fsIn
.Eof() && s
.empty() )
3481 wxPrintf(wxT("Line %d: %s\n"), line
++, s
.c_str());
3486 #endif // TEST_TEXTSTREAM
3488 // ----------------------------------------------------------------------------
3490 // ----------------------------------------------------------------------------
3492 #ifdef TEST_SNGLINST
3493 #include "wx/snglinst.h"
3494 #endif // TEST_SNGLINST
3496 int main(int argc
, char **argv
)
3499 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
3504 for (n
= 0; n
< argc
; n
++ )
3506 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
3507 wxArgv
[n
] = wxStrdup(warg
);
3512 #else // !wxUSE_UNICODE
3514 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
3516 wxApp
::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
3518 wxInitializer initializer
;
3521 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
3526 #ifdef TEST_SNGLINST
3527 wxSingleInstanceChecker checker
;
3528 if ( checker
.Create(wxT(".wxconsole.lock")) )
3530 if ( checker
.IsAnotherRunning() )
3532 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
3537 // wait some time to give time to launch another instance
3538 wxPrintf(wxT("Press \"Enter\" to continue..."));
3541 else // failed to create
3543 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
3545 #endif // TEST_SNGLINST
3548 TestCmdLineConvert();
3550 #if wxUSE_CMDLINE_PARSER
3551 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3553 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
3554 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
3555 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3556 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3558 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3559 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3560 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
3561 wxCMD_LINE_VAL_NUMBER
},
3562 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
3563 wxCMD_LINE_VAL_DATE
},
3564 { wxCMD_LINE_OPTION
, "f", "double", "output double",
3565 wxCMD_LINE_VAL_DOUBLE
},
3567 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3568 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3573 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
3575 parser
.AddOption(wxT("project_name"), wxT(""), wxT("full path to project file"),
3576 wxCMD_LINE_VAL_STRING
,
3577 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3579 switch ( parser
.Parse() )
3582 wxLogMessage(wxT("Help was given, terminating."));
3586 ShowCmdLine(parser
);
3590 wxLogMessage(wxT("Syntax error detected, aborting."));
3593 #endif // wxUSE_CMDLINE_PARSER
3595 #endif // TEST_CMDLINE
3607 TestDllListLoaded();
3608 #endif // TEST_DYNLIB
3612 #endif // TEST_ENVIRON
3614 #ifdef TEST_FILECONF
3616 #endif // TEST_FILECONF
3620 #endif // TEST_LOCALE
3623 wxPuts(wxT("*** Testing wxLog ***"));
3626 for ( size_t n
= 0; n
< 8000; n
++ )
3628 s
<< (wxChar
)(wxT('A') + (n
% 26));
3631 wxLogWarning(wxT("The length of the string is %lu"),
3632 (unsigned long)s
.length());
3635 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
3637 // this one shouldn't be truncated
3640 // but this one will because log functions use fixed size buffer
3641 // (note that it doesn't need '\n' at the end neither - will be added
3643 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
3653 #ifdef TEST_FILENAME
3656 TestFileNameDirManip();
3657 TestFileNameComparison();
3658 TestFileNameOperations();
3659 #endif // TEST_FILENAME
3661 #ifdef TEST_FILETIME
3666 #endif // TEST_FILETIME
3669 wxLog
::AddTraceMask(FTP_TRACE_MASK
);
3671 // wxFTP cannot be a static variable as its ctor needs to access
3672 // wxWidgets internals after it has been initialized
3674 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
3676 if ( TestFtpConnect() )
3686 #if TEST_INTERACTIVE
3687 //TestFtpInteractive();
3690 //else: connecting to the FTP server failed
3696 //wxLog::AddTraceMask(wxT("mime"));
3700 TestMimeAssociate();
3705 #ifdef TEST_INFO_FUNCTIONS
3710 #if TEST_INTERACTIVE
3713 #endif // TEST_INFO_FUNCTIONS
3715 #ifdef TEST_PATHLIST
3717 #endif // TEST_PATHLIST
3721 #endif // TEST_PRINTF
3728 #endif // TEST_REGCONF
3730 #if defined TEST_REGEX && TEST_INTERACTIVE
3731 TestRegExInteractive();
3732 #endif // defined TEST_REGEX && TEST_INTERACTIVE
3734 #ifdef TEST_REGISTRY
3736 TestRegistryAssociation();
3737 #endif // TEST_REGISTRY
3742 #endif // TEST_SOCKETS
3749 #endif // TEST_STREAMS
3751 #ifdef TEST_TEXTSTREAM
3752 TestTextInputStream();
3753 #endif // TEST_TEXTSTREAM
3758 #endif // TEST_TIMER
3760 #ifdef TEST_DATETIME
3767 TestTimeSpanFormat();
3773 #if TEST_INTERACTIVE
3774 TestDateTimeInteractive();
3776 #endif // TEST_DATETIME
3778 #ifdef TEST_SCOPEGUARD
3782 #ifdef TEST_STACKWALKER
3783 #if wxUSE_STACKWALKER
3784 TestStackWalk(argv
[0]);
3786 #endif // TEST_STACKWALKER
3788 #ifdef TEST_STDPATHS
3789 TestStandardPaths();
3793 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
3795 #endif // TEST_USLEEP
3799 #endif // TEST_VOLUME
3803 TestEncodingConverter();
3804 #endif // TEST_WCHAR
3807 TestZipStreamRead();
3808 TestZipFileSystem();
3813 for ( int n
= 0; n
< argc
; n
++ )
3818 #endif // wxUSE_UNICODE