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.
108 #define TEST_DATETIME
113 #define TEST_FILECONF
114 #define TEST_FILENAME
115 #define TEST_FILETIME
116 #define TEST_INFO_FUNCTIONS
121 #define TEST_PATHLIST
124 #else // #if TEST_ALL
125 #define TEST_DATETIME
127 #define TEST_STDPATHS
128 #define TEST_STACKWALKER
130 #define TEST_SNGLINST
133 // some tests are interactive, define this to run them
134 #ifdef TEST_INTERACTIVE
135 #undef TEST_INTERACTIVE
137 #define TEST_INTERACTIVE 1
139 #define TEST_INTERACTIVE 1
142 // ============================================================================
144 // ============================================================================
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
155 static const wxChar
*ROOTDIR
= wxT("/");
156 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
157 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
158 static const wxChar
*ROOTDIR
= wxT("c:\\");
159 static const wxChar
*TESTDIR
= wxT("d:\\");
161 #error "don't know where the root directory is"
164 static void TestDirEnumHelper(wxDir
& dir
,
165 int flags
= wxDIR_DEFAULT
,
166 const wxString
& filespec
= wxEmptyString
)
170 if ( !dir
.IsOpened() )
173 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
176 wxPrintf(wxT("\t%s\n"), filename
.c_str());
178 cont
= dir
.GetNext(&filename
);
181 wxPuts(wxEmptyString
);
186 static void TestDirEnum()
188 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
190 wxString cwd
= wxGetCwd();
191 if ( !wxDir
::Exists(cwd
) )
193 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
198 if ( !dir
.IsOpened() )
200 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
204 wxPuts(wxT("Enumerating everything in current directory:"));
205 TestDirEnumHelper(dir
);
207 wxPuts(wxT("Enumerating really everything in current directory:"));
208 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
210 wxPuts(wxT("Enumerating object files in current directory:"));
211 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
213 wxPuts(wxT("Enumerating directories in current directory:"));
214 TestDirEnumHelper(dir
, wxDIR_DIRS
);
216 wxPuts(wxT("Enumerating files in current directory:"));
217 TestDirEnumHelper(dir
, wxDIR_FILES
);
219 wxPuts(wxT("Enumerating files including hidden in current directory:"));
220 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
224 wxPuts(wxT("Enumerating everything in root directory:"));
225 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
227 wxPuts(wxT("Enumerating directories in root directory:"));
228 TestDirEnumHelper(dir
, wxDIR_DIRS
);
230 wxPuts(wxT("Enumerating files in root directory:"));
231 TestDirEnumHelper(dir
, wxDIR_FILES
);
233 wxPuts(wxT("Enumerating files including hidden in root directory:"));
234 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
236 wxPuts(wxT("Enumerating files in non existing directory:"));
237 wxDir
dirNo(wxT("nosuchdir"));
238 TestDirEnumHelper(dirNo
);
243 class DirPrintTraverser
: public wxDirTraverser
246 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
248 return wxDIR_CONTINUE
;
251 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
253 wxString path
, name
, ext
;
254 wxFileName
::SplitPath(dirname
, &path
, &name
, &ext
);
257 name
<< wxT('.') << ext
;
260 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
262 if ( wxIsPathSeparator(*p
) )
266 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
268 return wxDIR_CONTINUE
;
272 static void TestDirTraverse()
274 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
278 size_t n
= wxDir
::GetAllFiles(TESTDIR
, &files
);
279 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
282 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
283 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
286 // enum again with custom traverser
287 wxPuts(wxT("Now enumerating directories:"));
289 DirPrintTraverser traverser
;
290 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
295 static void TestDirExists()
297 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
299 static const wxChar
*dirnames
[] =
302 #if defined(__WXMSW__)
305 wxT("\\\\share\\file"),
309 wxT("c:\\autoexec.bat"),
310 #elif defined(__UNIX__)
319 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
321 wxPrintf(wxT("%-40s: %s\n"),
323 wxDir
::Exists(dirnames
[n
]) ?
wxT("exists")
324 : wxT("doesn't exist"));
332 // ----------------------------------------------------------------------------
334 // ----------------------------------------------------------------------------
338 #include "wx/dynlib.h"
340 static void TestDllLoad()
342 #if defined(__WXMSW__)
343 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
344 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
345 #elif defined(__UNIX__)
346 // weird: using just libc.so does *not* work!
347 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
348 static const wxChar
*FUNC_NAME
= wxT("strlen");
350 #error "don't know how to test wxDllLoader on this platform"
353 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
355 wxDynamicLibrary
lib(LIB_NAME
);
356 if ( !lib
.IsLoaded() )
358 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
362 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
363 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
366 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
367 FUNC_NAME
, LIB_NAME
);
371 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
372 FUNC_NAME
, LIB_NAME
);
374 if ( pfnStrlen("foo") != 3 )
376 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
380 wxPuts(wxT("... ok"));
385 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
387 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
389 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
390 if ( !pfnStrlenAorW
)
392 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
393 FUNC_NAME_AW
, LIB_NAME
);
397 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
399 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
406 #if defined(__WXMSW__) || defined(__UNIX__)
408 static void TestDllListLoaded()
410 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
412 puts("\nLoaded modules:");
413 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary
::ListLoaded();
414 const size_t count
= dlls
.GetCount();
415 for ( size_t n
= 0; n
< count
; ++n
)
417 const wxDynamicLibraryDetails
& details
= dlls
[n
];
418 printf("%-45s", (const char *)details
.GetPath().mb_str());
420 void *addr
wxDUMMY_INITIALIZE(NULL
);
421 size_t len
wxDUMMY_INITIALIZE(0);
422 if ( details
.GetAddress(&addr
, &len
) )
424 printf(" %08lx:%08lx",
425 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
428 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
434 #endif // TEST_DYNLIB
436 // ----------------------------------------------------------------------------
438 // ----------------------------------------------------------------------------
442 #include "wx/utils.h"
444 static wxString
MyGetEnv(const wxString
& var
)
447 if ( !wxGetEnv(var
, &val
) )
448 val
= wxT("<empty>");
450 val
= wxString(wxT('\'')) + val
+ wxT('\'');
455 static void TestEnvironment()
457 const wxChar
*var
= wxT("wxTestVar");
459 wxPuts(wxT("*** testing environment access functions ***"));
461 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
462 wxSetEnv(var
, wxT("value for wxTestVar"));
463 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
464 wxSetEnv(var
, wxT("another value"));
465 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
467 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
468 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
471 #endif // TEST_ENVIRON
473 // ----------------------------------------------------------------------------
475 // ----------------------------------------------------------------------------
480 #include "wx/ffile.h"
481 #include "wx/textfile.h"
483 static void TestFileRead()
485 wxPuts(wxT("*** wxFile read test ***"));
487 wxFile
file(wxT("testdata.fc"));
488 if ( file
.IsOpened() )
490 wxPrintf(wxT("File length: %lu\n"), file
.Length());
492 wxPuts(wxT("File dump:\n----------"));
494 static const size_t len
= 1024;
498 size_t nRead
= file
.Read(buf
, len
);
499 if ( nRead
== (size_t)wxInvalidOffset
)
501 wxPrintf(wxT("Failed to read the file."));
505 fwrite(buf
, nRead
, 1, stdout
);
511 wxPuts(wxT("----------"));
515 wxPrintf(wxT("ERROR: can't open test file.\n"));
518 wxPuts(wxEmptyString
);
521 static void TestTextFileRead()
523 wxPuts(wxT("*** wxTextFile read test ***"));
525 wxTextFile
file(wxT("testdata.fc"));
528 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
529 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
533 wxPuts(wxT("\nDumping the entire file:"));
534 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
536 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
538 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
540 wxPuts(wxT("\nAnd now backwards:"));
541 for ( s
= file
.GetLastLine();
542 file
.GetCurrentLine() != 0;
543 s
= file
.GetPrevLine() )
545 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
547 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
551 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
554 wxPuts(wxEmptyString
);
557 static void TestFileCopy()
559 wxPuts(wxT("*** Testing wxCopyFile ***"));
561 static const wxChar
*filename1
= wxT("testdata.fc");
562 static const wxChar
*filename2
= wxT("test2");
563 if ( !wxCopyFile(filename1
, filename2
) )
565 wxPuts(wxT("ERROR: failed to copy file"));
569 wxFFile
f1(filename1
, wxT("rb")),
570 f2(filename2
, wxT("rb"));
572 if ( !f1
.IsOpened() || !f2
.IsOpened() )
574 wxPuts(wxT("ERROR: failed to open file(s)"));
579 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
581 wxPuts(wxT("ERROR: failed to read file(s)"));
585 if ( (s1
.length() != s2
.length()) ||
586 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
588 wxPuts(wxT("ERROR: copy error!"));
592 wxPuts(wxT("File was copied ok."));
598 if ( !wxRemoveFile(filename2
) )
600 wxPuts(wxT("ERROR: failed to remove the file"));
603 wxPuts(wxEmptyString
);
606 static void TestTempFile()
608 wxPuts(wxT("*** wxTempFile test ***"));
611 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
613 if ( tmpFile
.Commit() )
614 wxPuts(wxT("File committed."));
616 wxPuts(wxT("ERROR: could't commit temp file."));
618 wxRemoveFile(wxT("test2"));
621 wxPuts(wxEmptyString
);
626 // ----------------------------------------------------------------------------
628 // ----------------------------------------------------------------------------
632 #include "wx/confbase.h"
633 #include "wx/fileconf.h"
635 static const struct FileConfTestData
637 const wxChar
*name
; // value name
638 const wxChar
*value
; // the value from the file
641 { wxT("value1"), wxT("one") },
642 { wxT("value2"), wxT("two") },
643 { wxT("novalue"), wxT("default") },
646 static void TestFileConfRead()
648 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
650 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
651 wxT("testdata.fc"), wxEmptyString
,
652 wxCONFIG_USE_RELATIVE_PATH
);
654 // test simple reading
655 wxPuts(wxT("\nReading config file:"));
656 wxString
defValue(wxT("default")), value
;
657 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
659 const FileConfTestData
& data
= fcTestData
[n
];
660 value
= fileconf
.Read(data
.name
, defValue
);
661 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
662 if ( value
== data
.value
)
668 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
672 // test enumerating the entries
673 wxPuts(wxT("\nEnumerating all root entries:"));
676 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
679 wxPrintf(wxT("\t%s = %s\n"),
681 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
683 cont
= fileconf
.GetNextEntry(name
, dummy
);
686 static const wxChar
*testEntry
= wxT("TestEntry");
687 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
688 fileconf
.Write(testEntry
, wxT("A value"));
689 fileconf
.DeleteEntry(testEntry
);
690 wxPrintf(fileconf
.HasEntry(testEntry
) ?
wxT("ERROR\n") : wxT("ok\n"));
693 #endif // TEST_FILECONF
695 // ----------------------------------------------------------------------------
697 // ----------------------------------------------------------------------------
701 #include "wx/filename.h"
704 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
708 wxString full
= fn
.GetFullPath();
710 wxString vol
, path
, name
, ext
;
711 wxFileName
::SplitPath(full
, &vol
, &path
, &name
, &ext
);
713 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
714 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
716 wxFileName
::SplitPath(full
, &path
, &name
, &ext
);
717 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
718 path
.c_str(), name
.c_str(), ext
.c_str());
720 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
721 wxPrintf(wxT("with volume: \t'%s'\n"),
722 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
723 wxPrintf(wxT("with separator:\t'%s'\n"),
724 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
725 wxPrintf(wxT("with both: \t'%s'\n"),
726 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
728 wxPuts(wxT("The directories in the path are:"));
729 wxArrayString dirs
= fn
.GetDirs();
730 size_t count
= dirs
.GetCount();
731 for ( size_t n
= 0; n
< count
; n
++ )
733 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
738 static void TestFileNameTemp()
740 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
742 static const wxChar
*tmpprefixes
[] =
750 wxT("/tmp/foo/bar"), // this one must be an error
754 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
756 wxString path
= wxFileName
::CreateTempFileName(tmpprefixes
[n
]);
759 // "error" is not in upper case because it may be ok
760 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
764 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
765 tmpprefixes
[n
], path
.c_str());
767 if ( !wxRemoveFile(path
) )
769 wxLogWarning(wxT("Failed to remove temp file '%s'"),
776 static void TestFileNameDirManip()
778 // TODO: test AppendDir(), RemoveDir(), ...
781 static void TestFileNameComparison()
786 static void TestFileNameOperations()
791 static void TestFileNameCwd()
796 #endif // TEST_FILENAME
798 // ----------------------------------------------------------------------------
799 // wxFileName time functions
800 // ----------------------------------------------------------------------------
804 #include "wx/filename.h"
805 #include "wx/datetime.h"
807 static void TestFileGetTimes()
809 wxFileName
fn(wxT("testdata.fc"));
811 wxDateTime dtAccess
, dtMod
, dtCreate
;
812 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
814 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
818 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
820 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
821 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
822 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
823 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
828 static void TestFileSetTimes()
830 wxFileName
fn(wxT("testdata.fc"));
834 wxPrintf(wxT("ERROR: Touch() failed.\n"));
839 #endif // TEST_FILETIME
841 // ----------------------------------------------------------------------------
843 // ----------------------------------------------------------------------------
848 #include "wx/utils.h" // for wxSetEnv
850 static wxLocale gs_localeDefault
;
851 // NOTE: don't init it here as it needs a wxAppTraits object
852 // and thus must be init-ed after creation of the wxInitializer
853 // class in the main()
855 // find the name of the language from its value
856 static const wxChar
*GetLangName(int lang
)
858 static const wxChar
*languageNames
[] =
868 wxT("ARABIC_ALGERIA"),
869 wxT("ARABIC_BAHRAIN"),
872 wxT("ARABIC_JORDAN"),
873 wxT("ARABIC_KUWAIT"),
874 wxT("ARABIC_LEBANON"),
876 wxT("ARABIC_MOROCCO"),
879 wxT("ARABIC_SAUDI_ARABIA"),
882 wxT("ARABIC_TUNISIA"),
889 wxT("AZERI_CYRILLIC"),
904 wxT("CHINESE_SIMPLIFIED"),
905 wxT("CHINESE_TRADITIONAL"),
906 wxT("CHINESE_HONGKONG"),
907 wxT("CHINESE_MACAU"),
908 wxT("CHINESE_SINGAPORE"),
909 wxT("CHINESE_TAIWAN"),
915 wxT("DUTCH_BELGIAN"),
919 wxT("ENGLISH_AUSTRALIA"),
920 wxT("ENGLISH_BELIZE"),
921 wxT("ENGLISH_BOTSWANA"),
922 wxT("ENGLISH_CANADA"),
923 wxT("ENGLISH_CARIBBEAN"),
924 wxT("ENGLISH_DENMARK"),
926 wxT("ENGLISH_JAMAICA"),
927 wxT("ENGLISH_NEW_ZEALAND"),
928 wxT("ENGLISH_PHILIPPINES"),
929 wxT("ENGLISH_SOUTH_AFRICA"),
930 wxT("ENGLISH_TRINIDAD"),
931 wxT("ENGLISH_ZIMBABWE"),
939 wxT("FRENCH_BELGIAN"),
940 wxT("FRENCH_CANADIAN"),
941 wxT("FRENCH_LUXEMBOURG"),
942 wxT("FRENCH_MONACO"),
948 wxT("GERMAN_AUSTRIAN"),
949 wxT("GERMAN_BELGIUM"),
950 wxT("GERMAN_LIECHTENSTEIN"),
951 wxT("GERMAN_LUXEMBOURG"),
969 wxT("ITALIAN_SWISS"),
974 wxT("KASHMIRI_INDIA"),
992 wxT("MALAY_BRUNEI_DARUSSALAM"),
993 wxT("MALAY_MALAYSIA"),
1002 wxT("NEPALI_INDIA"),
1003 wxT("NORWEGIAN_BOKMAL"),
1004 wxT("NORWEGIAN_NYNORSK"),
1011 wxT("PORTUGUESE_BRAZILIAN"),
1014 wxT("RHAETO_ROMANCE"),
1017 wxT("RUSSIAN_UKRAINE"),
1021 wxT("SCOTS_GAELIC"),
1023 wxT("SERBIAN_CYRILLIC"),
1024 wxT("SERBIAN_LATIN"),
1025 wxT("SERBO_CROATIAN"),
1036 wxT("SPANISH_ARGENTINA"),
1037 wxT("SPANISH_BOLIVIA"),
1038 wxT("SPANISH_CHILE"),
1039 wxT("SPANISH_COLOMBIA"),
1040 wxT("SPANISH_COSTA_RICA"),
1041 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1042 wxT("SPANISH_ECUADOR"),
1043 wxT("SPANISH_EL_SALVADOR"),
1044 wxT("SPANISH_GUATEMALA"),
1045 wxT("SPANISH_HONDURAS"),
1046 wxT("SPANISH_MEXICAN"),
1047 wxT("SPANISH_MODERN"),
1048 wxT("SPANISH_NICARAGUA"),
1049 wxT("SPANISH_PANAMA"),
1050 wxT("SPANISH_PARAGUAY"),
1051 wxT("SPANISH_PERU"),
1052 wxT("SPANISH_PUERTO_RICO"),
1053 wxT("SPANISH_URUGUAY"),
1055 wxT("SPANISH_VENEZUELA"),
1059 wxT("SWEDISH_FINLAND"),
1077 wxT("URDU_PAKISTAN"),
1079 wxT("UZBEK_CYRILLIC"),
1092 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1093 return languageNames
[lang
];
1095 return wxT("INVALID");
1098 static void TestDefaultLang()
1100 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1102 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1104 static const wxChar
*langStrings
[] =
1106 NULL
, // system default
1113 wxT("de_DE.iso88591"),
1115 wxT("?"), // invalid lang spec
1116 wxT("klingonese"), // I bet on some systems it does exist...
1119 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1120 wxLocale
::GetSystemEncodingName().c_str(),
1121 wxLocale
::GetSystemEncoding());
1123 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1125 const wxChar
*langStr
= langStrings
[n
];
1128 // FIXME: this doesn't do anything at all under Windows, we need
1129 // to create a new wxLocale!
1130 wxSetEnv(wxT("LC_ALL"), langStr
);
1133 int lang
= gs_localeDefault
.GetSystemLanguage();
1134 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1135 langStr ? langStr
: wxT("system default"), GetLangName(lang
));
1139 #endif // TEST_LOCALE
1141 // ----------------------------------------------------------------------------
1143 // ----------------------------------------------------------------------------
1147 #include "wx/mimetype.h"
1149 static void TestMimeEnum()
1151 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1153 wxArrayString mimetypes
;
1155 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1157 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1162 for ( size_t n
= 0; n
< count
; n
++ )
1164 wxFileType
*filetype
=
1165 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1168 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1169 mimetypes
[n
].c_str());
1173 filetype
->GetDescription(&desc
);
1174 filetype
->GetExtensions(exts
);
1176 filetype
->GetIcon(NULL
);
1179 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1182 extsAll
<< wxT(", ");
1186 wxPrintf(wxT("\t%s: %s (%s)\n"),
1187 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1190 wxPuts(wxEmptyString
);
1193 static void TestMimeFilename()
1195 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1197 static const wxChar
*filenames
[] =
1200 wxT("document.pdf"),
1202 wxT("picture.jpeg"),
1205 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1207 const wxString fname
= filenames
[n
];
1208 wxString ext
= fname
.AfterLast(wxT('.'));
1209 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1212 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1217 if ( !ft
->GetDescription(&desc
) )
1218 desc
= wxT("<no description>");
1221 if ( !ft
->GetOpenCommand(&cmd
,
1222 wxFileType
::MessageParameters(fname
, wxEmptyString
)) )
1223 cmd
= wxT("<no command available>");
1225 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1227 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1228 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1234 wxPuts(wxEmptyString
);
1237 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1240 static void TestMimeOverride()
1242 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1244 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1245 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1247 if ( wxFile
::Exists(mailcap
) )
1248 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1250 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ?
wxT("ok") : wxT("ERROR"));
1252 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1255 if ( wxFile
::Exists(mimetypes
) )
1256 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1258 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ?
wxT("ok") : wxT("ERROR"));
1260 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1263 wxPuts(wxEmptyString
);
1266 static void TestMimeAssociate()
1268 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1270 wxFileTypeInfo
ftInfo(
1271 wxT("application/x-xyz"),
1272 wxT("xyzview '%s'"), // open cmd
1273 wxT(""), // print cmd
1274 wxT("XYZ File"), // description
1275 wxT(".xyz"), // extensions
1276 wxNullPtr
// end of extensions
1278 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1280 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1283 wxPuts(wxT("ERROR: failed to create association!"));
1287 // TODO: read it back
1291 wxPuts(wxEmptyString
);
1298 // ----------------------------------------------------------------------------
1299 // module dependencies feature
1300 // ----------------------------------------------------------------------------
1304 #include "wx/module.h"
1306 class wxTestModule
: public wxModule
1309 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1310 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1313 class wxTestModuleA
: public wxTestModule
1318 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1321 class wxTestModuleB
: public wxTestModule
1326 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1329 class wxTestModuleC
: public wxTestModule
1334 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1337 class wxTestModuleD
: public wxTestModule
1342 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1345 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1346 wxTestModuleC
::wxTestModuleC()
1348 AddDependency(CLASSINFO(wxTestModuleD
));
1351 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1352 wxTestModuleA
::wxTestModuleA()
1354 AddDependency(CLASSINFO(wxTestModuleB
));
1355 AddDependency(CLASSINFO(wxTestModuleD
));
1358 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1359 wxTestModuleD
::wxTestModuleD()
1363 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1364 wxTestModuleB
::wxTestModuleB()
1366 AddDependency(CLASSINFO(wxTestModuleD
));
1367 AddDependency(CLASSINFO(wxTestModuleC
));
1370 #endif // TEST_MODULE
1372 // ----------------------------------------------------------------------------
1373 // misc information functions
1374 // ----------------------------------------------------------------------------
1376 #ifdef TEST_INFO_FUNCTIONS
1378 #include "wx/utils.h"
1380 #if TEST_INTERACTIVE
1381 static void TestDiskInfo()
1383 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1387 wxChar pathname
[128];
1388 wxPrintf(wxT("\nEnter a directory name: "));
1389 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1392 // kill the last '\n'
1393 pathname
[wxStrlen(pathname
) - 1] = 0;
1395 wxLongLong total
, free
;
1396 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1398 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1402 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1403 (total
/ 1024).ToString().c_str(),
1404 (free
/ 1024).ToString().c_str(),
1409 #endif // TEST_INTERACTIVE
1411 static void TestOsInfo()
1413 wxPuts(wxT("*** Testing OS info functions ***\n"));
1416 wxGetOsVersion(&major
, &minor
);
1417 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1418 wxGetOsDescription().c_str(), major
, minor
);
1420 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1422 wxPrintf(wxT("Host name is %s (%s).\n"),
1423 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1425 wxPuts(wxEmptyString
);
1428 static void TestPlatformInfo()
1430 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1432 // get this platform
1433 wxPlatformInfo plat
;
1435 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1436 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1437 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1438 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1439 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1440 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1442 wxPuts(wxEmptyString
);
1445 static void TestUserInfo()
1447 wxPuts(wxT("*** Testing user info functions ***\n"));
1449 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1450 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1451 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1452 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1454 wxPuts(wxEmptyString
);
1457 #endif // TEST_INFO_FUNCTIONS
1459 // ----------------------------------------------------------------------------
1461 // ----------------------------------------------------------------------------
1463 #ifdef TEST_PATHLIST
1466 #define CMD_IN_PATH wxT("ls")
1468 #define CMD_IN_PATH wxT("command.com")
1471 static void TestPathList()
1473 wxPuts(wxT("*** Testing wxPathList ***\n"));
1475 wxPathList pathlist
;
1476 pathlist
.AddEnvList(wxT("PATH"));
1477 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1480 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1484 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1488 #endif // TEST_PATHLIST
1490 // ----------------------------------------------------------------------------
1491 // regular expressions
1492 // ----------------------------------------------------------------------------
1494 #if defined TEST_REGEX && TEST_INTERACTIVE
1496 #include "wx/regex.h"
1498 static void TestRegExInteractive()
1500 wxPuts(wxT("*** Testing RE interactively ***"));
1504 wxChar pattern
[128];
1505 wxPrintf(wxT("\nEnter a pattern: "));
1506 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1509 // kill the last '\n'
1510 pattern
[wxStrlen(pattern
) - 1] = 0;
1513 if ( !re
.Compile(pattern
) )
1521 wxPrintf(wxT("Enter text to match: "));
1522 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1525 // kill the last '\n'
1526 text
[wxStrlen(text
) - 1] = 0;
1528 if ( !re
.Matches(text
) )
1530 wxPrintf(wxT("No match.\n"));
1534 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1537 for ( size_t n
= 1; ; n
++ )
1539 if ( !re
.GetMatch(&start
, &len
, n
) )
1544 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1545 n
, wxString(text
+ start
, len
).c_str());
1552 #endif // TEST_REGEX
1554 // ----------------------------------------------------------------------------
1556 // ----------------------------------------------------------------------------
1559 NB: this stuff was taken from the glibc test suite and modified to build
1560 in wxWidgets: if I read the copyright below properly, this shouldn't
1566 #ifdef wxTEST_PRINTF
1567 // use our functions from wxchar.cpp
1571 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1572 // in the tests below
1573 int wxPrintf( const wxChar
*format
, ... );
1574 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1577 #include "wx/longlong.h"
1581 static void rfg1 (void);
1582 static void rfg2 (void);
1586 fmtchk (const wxChar
*fmt
)
1588 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1589 (void) wxPrintf(fmt
, 0x12);
1590 (void) wxPrintf(wxT("'\n"));
1594 fmtst1chk (const wxChar
*fmt
)
1596 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1597 (void) wxPrintf(fmt
, 4, 0x12);
1598 (void) wxPrintf(wxT("'\n"));
1602 fmtst2chk (const wxChar
*fmt
)
1604 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1605 (void) wxPrintf(fmt
, 4, 4, 0x12);
1606 (void) wxPrintf(wxT("'\n"));
1609 /* This page is covered by the following copyright: */
1611 /* (C) Copyright C E Chew
1613 * Feel free to copy, use and distribute this software provided:
1615 * 1. you do not pretend that you wrote it
1616 * 2. you leave this copyright notice intact.
1620 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1627 /* Formatted Output Test
1629 * This exercises the output formatting code.
1632 wxChar
*PointerNull
= NULL
;
1639 wxChar
*prefix
= buf
;
1642 wxPuts(wxT("\nFormatted output test"));
1643 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1644 wxStrcpy(prefix
, wxT("%"));
1645 for (i
= 0; i
< 2; i
++) {
1646 for (j
= 0; j
< 2; j
++) {
1647 for (k
= 0; k
< 2; k
++) {
1648 for (l
= 0; l
< 2; l
++) {
1649 wxStrcpy(prefix
, wxT("%"));
1650 if (i
== 0) wxStrcat(prefix
, wxT("-"));
1651 if (j
== 0) wxStrcat(prefix
, wxT("+"));
1652 if (k
== 0) wxStrcat(prefix
, wxT("#"));
1653 if (l
== 0) wxStrcat(prefix
, wxT("0"));
1654 wxPrintf(wxT("%5s |"), prefix
);
1655 wxStrcpy(tp
, prefix
);
1656 wxStrcat(tp
, wxT("6d |"));
1658 wxStrcpy(tp
, prefix
);
1659 wxStrcat(tp
, wxT("6o |"));
1661 wxStrcpy(tp
, prefix
);
1662 wxStrcat(tp
, wxT("6x |"));
1664 wxStrcpy(tp
, prefix
);
1665 wxStrcat(tp
, wxT("6X |"));
1667 wxStrcpy(tp
, prefix
);
1668 wxStrcat(tp
, wxT("6u |"));
1670 wxPrintf(wxT("\n"));
1675 wxPrintf(wxT("%10s\n"), PointerNull
);
1676 wxPrintf(wxT("%-10s\n"), PointerNull
);
1679 static void TestPrintf()
1681 static wxChar shortstr
[] = wxT("Hi, Z.");
1682 static wxChar longstr
[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1683 I am ready for my first lesson today.");
1685 wxString test_format
;
1687 fmtchk(wxT("%.4x"));
1688 fmtchk(wxT("%04x"));
1689 fmtchk(wxT("%4.4x"));
1690 fmtchk(wxT("%04.4x"));
1691 fmtchk(wxT("%4.3x"));
1692 fmtchk(wxT("%04.3x"));
1694 fmtst1chk(wxT("%.*x"));
1695 fmtst1chk(wxT("%0*x"));
1696 fmtst2chk(wxT("%*.*x"));
1697 fmtst2chk(wxT("%0*.*x"));
1699 wxString bad_format
= wxT("bad format:\t\"%b\"\n");
1700 wxPrintf(bad_format
.c_str());
1701 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1703 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1704 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1705 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1706 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1707 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1708 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1709 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1710 test_format
= wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1711 wxPrintf(test_format
.c_str(), -123456);
1712 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1713 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1715 test_format
= wxT("zero-padded string:\t\"%010s\"\n");
1716 wxPrintf(test_format
.c_str(), shortstr
);
1717 test_format
= wxT("left-adjusted Z string:\t\"%-010s\"\n");
1718 wxPrintf(test_format
.c_str(), shortstr
);
1719 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr
);
1720 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1721 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull
);
1722 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr
);
1724 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1725 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1726 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1727 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20
);
1728 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1729 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1730 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1731 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1732 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1733 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1734 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1735 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20
);
1737 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1738 wxPrintf (wxT(" %6.5f\n"), .1);
1739 wxPrintf (wxT("x%5.4fx\n"), .5);
1741 wxPrintf (wxT("%#03x\n"), 1);
1743 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1749 while (niter
-- != 0)
1750 wxPrintf (wxT("%.17e\n"), d
/ 2);
1755 // Open Watcom cause compiler error here
1756 // Error! E173: col(24) floating-point constant too small to represent
1757 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1760 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1761 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1762 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1763 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1764 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1765 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1766 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1767 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1768 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1769 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1774 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), wxT("%30s"), wxT("foo"));
1776 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1777 rc
, WXSIZEOF(buf
), buf
);
1780 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1781 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1787 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1788 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1789 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1790 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1791 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1792 wxPrintf (wxT("%g should be 10\n"), 10.0);
1793 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1797 wxPrintf(wxT("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1803 wxSprintf(buf
,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1805 result
|= wxStrcmp (buf
,
1806 wxT("onetwo three "));
1808 wxPuts (result
!= 0 ?
wxT("Test failed!") : wxT("Test ok."));
1815 wxSprintf(buf
, "%07" wxLongLongFmtSpec
"o", wxLL(040000000000));
1817 // for some reason below line fails under Borland
1818 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1821 if (wxStrcmp (buf
, wxT("40000000000")) != 0)
1824 wxPuts (wxT("\tFAILED"));
1826 wxUnusedVar(result
);
1827 wxPuts (wxEmptyString
);
1829 #endif // wxLongLong_t
1831 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1832 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1834 wxPuts (wxT("--- Should be no further output. ---"));
1843 memset (bytes
, '\xff', sizeof bytes
);
1844 wxSprintf (buf
, wxT("foo%hhn\n"), &bytes
[3]);
1845 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1846 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1848 wxPuts (wxT("%hhn overwrite more bytes"));
1853 wxPuts (wxT("%hhn wrote incorrect value"));
1865 wxSprintf (buf
, wxT("%5.s"), wxT("xyz"));
1866 if (wxStrcmp (buf
, wxT(" ")) != 0)
1867 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" "));
1868 wxSprintf (buf
, wxT("%5.f"), 33.3);
1869 if (wxStrcmp (buf
, wxT(" 33")) != 0)
1870 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 33"));
1871 wxSprintf (buf
, wxT("%8.e"), 33.3e7
);
1872 if (wxStrcmp (buf
, wxT(" 3e+08")) != 0)
1873 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3e+08"));
1874 wxSprintf (buf
, wxT("%8.E"), 33.3e7
);
1875 if (wxStrcmp (buf
, wxT(" 3E+08")) != 0)
1876 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3E+08"));
1877 wxSprintf (buf
, wxT("%.g"), 33.3);
1878 if (wxStrcmp (buf
, wxT("3e+01")) != 0)
1879 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3e+01"));
1880 wxSprintf (buf
, wxT("%.G"), 33.3);
1881 if (wxStrcmp (buf
, wxT("3E+01")) != 0)
1882 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3E+01"));
1890 wxString test_format
;
1893 wxSprintf (buf
, wxT("%.*g"), prec
, 3.3);
1894 if (wxStrcmp (buf
, wxT("3")) != 0)
1895 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1897 wxSprintf (buf
, wxT("%.*G"), prec
, 3.3);
1898 if (wxStrcmp (buf
, wxT("3")) != 0)
1899 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1901 wxSprintf (buf
, wxT("%7.*G"), prec
, 3.33);
1902 if (wxStrcmp (buf
, wxT(" 3")) != 0)
1903 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3"));
1905 test_format
= wxT("%04.*o");
1906 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1907 if (wxStrcmp (buf
, wxT(" 041")) != 0)
1908 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 041"));
1910 test_format
= wxT("%09.*u");
1911 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1912 if (wxStrcmp (buf
, wxT(" 0000033")) != 0)
1913 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 0000033"));
1915 test_format
= wxT("%04.*x");
1916 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1917 if (wxStrcmp (buf
, wxT(" 021")) != 0)
1918 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
1920 test_format
= wxT("%04.*X");
1921 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1922 if (wxStrcmp (buf
, wxT(" 021")) != 0)
1923 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
1926 #endif // TEST_PRINTF
1928 // ----------------------------------------------------------------------------
1930 // ----------------------------------------------------------------------------
1934 #include "wx/protocol/ftp.h"
1935 #include "wx/protocol/log.h"
1937 #define FTP_ANONYMOUS
1941 #ifdef FTP_ANONYMOUS
1942 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
1943 static const wxChar
*directory
= wxT("/pub");
1944 static const wxChar
*filename
= wxT("welcome.msg");
1946 static const wxChar
*hostname
= "localhost";
1947 static const wxChar
*directory
= wxT("/etc");
1948 static const wxChar
*filename
= wxT("issue");
1951 static bool TestFtpConnect()
1953 wxPuts(wxT("*** Testing FTP connect ***"));
1955 #ifdef FTP_ANONYMOUS
1956 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
1957 #else // !FTP_ANONYMOUS
1959 wxFgets(user
, WXSIZEOF(user
), stdin
);
1960 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
1963 wxChar password
[256];
1964 wxPrintf(wxT("Password for %s: "), password
);
1965 wxFgets(password
, WXSIZEOF(password
), stdin
);
1966 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
1967 ftp
->SetPassword(password
);
1969 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
1970 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
1972 if ( !ftp
->Connect(hostname
) )
1974 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
1980 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
1981 hostname
, ftp
->Pwd().c_str());
1988 #if TEST_INTERACTIVE
1989 static void TestFtpInteractive()
1991 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
1997 wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
1998 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2001 // kill the last '\n'
2002 buf
[wxStrlen(buf
) - 1] = 0;
2004 // special handling of LIST and NLST as they require data connection
2005 wxString
start(buf
, 4);
2007 if ( start
== wxT("LIST") || start
== wxT("NLST") )
2010 if ( wxStrlen(buf
) > 4 )
2013 wxArrayString files
;
2014 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
2016 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
2020 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2021 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2022 size_t count
= files
.GetCount();
2023 for ( size_t n
= 0; n
< count
; n
++ )
2025 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2027 wxPuts(wxT("--- End of the file list"));
2030 else if ( start
== wxT("QUIT") )
2032 break; // get out of here!
2036 wxChar ch
= ftp
->SendCommand(buf
);
2037 wxPrintf(wxT("Command %s"), ch ?
wxT("succeeded") : wxT("failed"));
2040 wxPrintf(wxT(" (return code %c)"), ch
);
2043 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2049 #endif // TEST_INTERACTIVE
2052 // ----------------------------------------------------------------------------
2054 // ----------------------------------------------------------------------------
2056 #ifdef TEST_STACKWALKER
2058 #if wxUSE_STACKWALKER
2060 #include "wx/stackwalk.h"
2062 class StackDump
: public wxStackWalker
2065 StackDump(const char *argv0
)
2066 : wxStackWalker(argv0
)
2070 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
2072 wxPuts(wxT("Stack dump:"));
2074 wxStackWalker
::Walk(skip
, maxdepth
);
2078 virtual void OnStackFrame(const wxStackFrame
& frame
)
2080 printf("[%2d] ", (int) frame
.GetLevel());
2082 wxString name
= frame
.GetName();
2083 if ( !name
.empty() )
2085 printf("%-20.40s", (const char*)name
.mb_str());
2089 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2092 if ( frame
.HasSourceLocation() )
2095 (const char*)frame
.GetFileName().mb_str(),
2096 (int)frame
.GetLine());
2102 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2104 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2105 (const char*)name
.mb_str(),
2106 (const char*)val
.mb_str());
2111 static void TestStackWalk(const char *argv0
)
2113 wxPuts(wxT("*** Testing wxStackWalker ***"));
2115 StackDump
dump(argv0
);
2121 #endif // wxUSE_STACKWALKER
2123 #endif // TEST_STACKWALKER
2125 // ----------------------------------------------------------------------------
2127 // ----------------------------------------------------------------------------
2129 #ifdef TEST_STDPATHS
2131 #include "wx/stdpaths.h"
2132 #include "wx/wxchar.h" // wxPrintf
2134 static void TestStandardPaths()
2136 wxPuts(wxT("*** Testing wxStandardPaths ***"));
2138 wxTheApp
->SetAppName(wxT("console"));
2140 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
2141 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2142 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2143 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2144 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2145 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2146 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2147 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2148 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2149 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2150 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2151 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2152 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
2153 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2154 stdp
.GetLocalizedResourcesDir
2157 wxStandardPaths
::ResourceCat_Messages
2163 #endif // TEST_STDPATHS
2165 // ----------------------------------------------------------------------------
2167 // ----------------------------------------------------------------------------
2169 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2175 #include "wx/volume.h"
2177 static const wxChar
*volumeKinds
[] =
2183 wxT("network volume"),
2184 wxT("other volume"),
2187 static void TestFSVolume()
2189 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2191 wxArrayString volumes
= wxFSVolume
::GetVolumes();
2192 size_t count
= volumes
.GetCount();
2196 wxPuts(wxT("ERROR: no mounted volumes?"));
2200 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
2202 for ( size_t n
= 0; n
< count
; n
++ )
2204 wxFSVolume
vol(volumes
[n
]);
2207 wxPuts(wxT("ERROR: couldn't create volume"));
2211 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2213 vol
.GetDisplayName().c_str(),
2214 vol
.GetName().c_str(),
2215 volumeKinds
[vol
.GetKind()],
2216 vol
.IsWritable() ?
wxT("rw") : wxT("ro"),
2217 vol
.GetFlags() & wxFS_VOL_REMOVABLE ?
wxT("removable")
2224 #endif // TEST_VOLUME
2226 // ----------------------------------------------------------------------------
2228 // ----------------------------------------------------------------------------
2230 #ifdef TEST_DATETIME
2232 #include "wx/math.h"
2233 #include "wx/datetime.h"
2235 #if TEST_INTERACTIVE
2237 static void TestDateTimeInteractive()
2239 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
2245 wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
2246 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2249 // kill the last '\n'
2250 buf
[wxStrlen(buf
) - 1] = 0;
2252 if ( wxString(buf
).CmpNoCase("quit") == 0 )
2256 const wxChar
*p
= dt
.ParseDate(buf
);
2259 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
2265 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
2268 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
2269 dt
.Format(wxT("%b %d, %Y")).c_str(),
2271 dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
2272 dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
2273 dt
.GetWeekOfYear(wxDateTime
::Monday_First
));
2279 #endif // TEST_INTERACTIVE
2280 #endif // TEST_DATETIME
2282 // ----------------------------------------------------------------------------
2284 // ----------------------------------------------------------------------------
2286 #ifdef TEST_SNGLINST
2288 #include "wx/snglinst.h"
2290 static bool TestSingleIstance()
2292 wxPuts(wxT("\n*** Testing wxSingleInstanceChecker ***"));
2294 wxSingleInstanceChecker checker
;
2295 if ( checker
.Create(wxT(".wxconsole.lock")) )
2297 if ( checker
.IsAnotherRunning() )
2299 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
2304 // wait some time to give time to launch another instance
2305 wxPuts(wxT("If you try to run another instance of this program now, it won't start."));
2306 wxPrintf(wxT("Press \"Enter\" to exit wxSingleInstanceChecker test and proceed..."));
2309 else // failed to create
2311 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
2318 #endif // TEST_SNGLINST
2321 // ----------------------------------------------------------------------------
2323 // ----------------------------------------------------------------------------
2325 int main(int argc
, char **argv
)
2328 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
2333 for (n
= 0; n
< argc
; n
++ )
2335 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
2336 wxArgv
[n
] = wxStrdup(warg
);
2341 #else // !wxUSE_UNICODE
2343 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2345 wxApp
::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
2347 wxInitializer initializer
;
2350 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
2355 #ifdef TEST_SNGLINST
2356 if (!TestSingleIstance())
2358 #endif // TEST_SNGLINST
2370 TestDllListLoaded();
2371 #endif // TEST_DYNLIB
2375 #endif // TEST_ENVIRON
2377 #ifdef TEST_FILECONF
2379 #endif // TEST_FILECONF
2383 #endif // TEST_LOCALE
2386 wxPuts(wxT("*** Testing wxLog ***"));
2389 for ( size_t n
= 0; n
< 8000; n
++ )
2391 s
<< (wxChar
)(wxT('A') + (n
% 26));
2394 wxLogWarning(wxT("The length of the string is %lu"),
2395 (unsigned long)s
.length());
2398 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
2400 // this one shouldn't be truncated
2403 // but this one will because log functions use fixed size buffer
2404 // (note that it doesn't need '\n' at the end neither - will be added
2406 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
2416 #ifdef TEST_FILENAME
2419 TestFileNameDirManip();
2420 TestFileNameComparison();
2421 TestFileNameOperations();
2422 #endif // TEST_FILENAME
2424 #ifdef TEST_FILETIME
2429 #endif // TEST_FILETIME
2432 wxLog
::AddTraceMask(FTP_TRACE_MASK
);
2434 // wxFTP cannot be a static variable as its ctor needs to access
2435 // wxWidgets internals after it has been initialized
2437 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
2438 if ( TestFtpConnect() )
2439 TestFtpInteractive();
2440 //else: connecting to the FTP server failed
2446 //wxLog::AddTraceMask(wxT("mime"));
2450 TestMimeAssociate();
2455 #ifdef TEST_INFO_FUNCTIONS
2460 #if TEST_INTERACTIVE
2463 #endif // TEST_INFO_FUNCTIONS
2465 #ifdef TEST_PATHLIST
2467 #endif // TEST_PATHLIST
2471 #endif // TEST_PRINTF
2473 #if defined TEST_REGEX && TEST_INTERACTIVE
2474 TestRegExInteractive();
2475 #endif // defined TEST_REGEX && TEST_INTERACTIVE
2477 #ifdef TEST_DATETIME
2478 #if TEST_INTERACTIVE
2479 TestDateTimeInteractive();
2481 #endif // TEST_DATETIME
2483 #ifdef TEST_STACKWALKER
2484 #if wxUSE_STACKWALKER
2485 TestStackWalk(argv
[0]);
2487 #endif // TEST_STACKWALKER
2489 #ifdef TEST_STDPATHS
2490 TestStandardPaths();
2494 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
2496 #endif // TEST_USLEEP
2500 #endif // TEST_VOLUME
2504 for ( int n
= 0; n
< argc
; n
++ )
2509 #endif // wxUSE_UNICODE