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
122 #else // #if TEST_ALL
123 #define TEST_DATETIME
125 #define TEST_STDPATHS
126 #define TEST_STACKWALKER
128 #define TEST_SNGLINST
132 // some tests are interactive, define this to run them
133 #ifdef TEST_INTERACTIVE
134 #undef TEST_INTERACTIVE
136 #define TEST_INTERACTIVE 1
138 #define TEST_INTERACTIVE 1
141 // ============================================================================
143 // ============================================================================
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
154 static const wxChar
*ROOTDIR
= wxT("/");
155 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
156 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
157 static const wxChar
*ROOTDIR
= wxT("c:\\");
158 static const wxChar
*TESTDIR
= wxT("d:\\");
160 #error "don't know where the root directory is"
163 static void TestDirEnumHelper(wxDir
& dir
,
164 int flags
= wxDIR_DEFAULT
,
165 const wxString
& filespec
= wxEmptyString
)
169 if ( !dir
.IsOpened() )
172 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
175 wxPrintf(wxT("\t%s\n"), filename
.c_str());
177 cont
= dir
.GetNext(&filename
);
180 wxPuts(wxEmptyString
);
185 static void TestDirEnum()
187 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
189 wxString cwd
= wxGetCwd();
190 if ( !wxDir::Exists(cwd
) )
192 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
197 if ( !dir
.IsOpened() )
199 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
203 wxPuts(wxT("Enumerating everything in current directory:"));
204 TestDirEnumHelper(dir
);
206 wxPuts(wxT("Enumerating really everything in current directory:"));
207 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
209 wxPuts(wxT("Enumerating object files in current directory:"));
210 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
212 wxPuts(wxT("Enumerating directories in current directory:"));
213 TestDirEnumHelper(dir
, wxDIR_DIRS
);
215 wxPuts(wxT("Enumerating files in current directory:"));
216 TestDirEnumHelper(dir
, wxDIR_FILES
);
218 wxPuts(wxT("Enumerating files including hidden in current directory:"));
219 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
223 wxPuts(wxT("Enumerating everything in root directory:"));
224 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
226 wxPuts(wxT("Enumerating directories in root directory:"));
227 TestDirEnumHelper(dir
, wxDIR_DIRS
);
229 wxPuts(wxT("Enumerating files in root directory:"));
230 TestDirEnumHelper(dir
, wxDIR_FILES
);
232 wxPuts(wxT("Enumerating files including hidden in root directory:"));
233 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
235 wxPuts(wxT("Enumerating files in non existing directory:"));
236 wxDir
dirNo(wxT("nosuchdir"));
237 TestDirEnumHelper(dirNo
);
242 class DirPrintTraverser
: public wxDirTraverser
245 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
247 return wxDIR_CONTINUE
;
250 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
252 wxString path
, name
, ext
;
253 wxFileName::SplitPath(dirname
, &path
, &name
, &ext
);
256 name
<< wxT('.') << ext
;
259 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
261 if ( wxIsPathSeparator(*p
) )
265 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
267 return wxDIR_CONTINUE
;
271 static void TestDirTraverse()
273 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
277 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
278 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
281 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
282 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
285 // enum again with custom traverser
286 wxPuts(wxT("Now enumerating directories:"));
288 DirPrintTraverser traverser
;
289 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
294 static void TestDirExists()
296 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
298 static const wxChar
*dirnames
[] =
301 #if defined(__WXMSW__)
304 wxT("\\\\share\\file"),
308 wxT("c:\\autoexec.bat"),
309 #elif defined(__UNIX__)
318 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
320 wxPrintf(wxT("%-40s: %s\n"),
322 wxDir::Exists(dirnames
[n
]) ? wxT("exists")
323 : wxT("doesn't exist"));
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
337 #include "wx/dynlib.h"
339 static void TestDllLoad()
341 #if defined(__WXMSW__)
342 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
343 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
344 #elif defined(__UNIX__)
345 // weird: using just libc.so does *not* work!
346 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
347 static const wxChar
*FUNC_NAME
= wxT("strlen");
349 #error "don't know how to test wxDllLoader on this platform"
352 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
354 wxDynamicLibrary
lib(LIB_NAME
);
355 if ( !lib
.IsLoaded() )
357 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
361 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
362 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
365 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
366 FUNC_NAME
, LIB_NAME
);
370 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
371 FUNC_NAME
, LIB_NAME
);
373 if ( pfnStrlen("foo") != 3 )
375 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
379 wxPuts(wxT("... ok"));
384 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
386 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
388 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
389 if ( !pfnStrlenAorW
)
391 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
392 FUNC_NAME_AW
, LIB_NAME
);
396 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
398 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
405 #if defined(__WXMSW__) || defined(__UNIX__)
407 static void TestDllListLoaded()
409 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
411 puts("\nLoaded modules:");
412 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
413 const size_t count
= dlls
.GetCount();
414 for ( size_t n
= 0; n
< count
; ++n
)
416 const wxDynamicLibraryDetails
& details
= dlls
[n
];
417 printf("%-45s", (const char *)details
.GetPath().mb_str());
419 void *addr
wxDUMMY_INITIALIZE(NULL
);
420 size_t len
wxDUMMY_INITIALIZE(0);
421 if ( details
.GetAddress(&addr
, &len
) )
423 printf(" %08lx:%08lx",
424 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
427 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
433 #endif // TEST_DYNLIB
435 // ----------------------------------------------------------------------------
437 // ----------------------------------------------------------------------------
441 #include "wx/utils.h"
443 static wxString
MyGetEnv(const wxString
& var
)
446 if ( !wxGetEnv(var
, &val
) )
447 val
= wxT("<empty>");
449 val
= wxString(wxT('\'')) + val
+ wxT('\'');
454 static void TestEnvironment()
456 const wxChar
*var
= wxT("wxTestVar");
458 wxPuts(wxT("*** testing environment access functions ***"));
460 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
461 wxSetEnv(var
, wxT("value for wxTestVar"));
462 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
463 wxSetEnv(var
, wxT("another value"));
464 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
466 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
467 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
470 #endif // TEST_ENVIRON
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
479 #include "wx/ffile.h"
480 #include "wx/textfile.h"
482 static void TestFileRead()
484 wxPuts(wxT("*** wxFile read test ***"));
486 wxFile
file(wxT("testdata.fc"));
487 if ( file
.IsOpened() )
489 wxPrintf(wxT("File length: %lu\n"), file
.Length());
491 wxPuts(wxT("File dump:\n----------"));
493 static const size_t len
= 1024;
497 size_t nRead
= file
.Read(buf
, len
);
498 if ( nRead
== (size_t)wxInvalidOffset
)
500 wxPrintf(wxT("Failed to read the file."));
504 fwrite(buf
, nRead
, 1, stdout
);
510 wxPuts(wxT("----------"));
514 wxPrintf(wxT("ERROR: can't open test file.\n"));
517 wxPuts(wxEmptyString
);
520 static void TestTextFileRead()
522 wxPuts(wxT("*** wxTextFile read test ***"));
524 wxTextFile
file(wxT("testdata.fc"));
527 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
528 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
532 wxPuts(wxT("\nDumping the entire file:"));
533 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
535 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
537 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
539 wxPuts(wxT("\nAnd now backwards:"));
540 for ( s
= file
.GetLastLine();
541 file
.GetCurrentLine() != 0;
542 s
= file
.GetPrevLine() )
544 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
546 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
550 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
553 wxPuts(wxEmptyString
);
556 static void TestFileCopy()
558 wxPuts(wxT("*** Testing wxCopyFile ***"));
560 static const wxChar
*filename1
= wxT("testdata.fc");
561 static const wxChar
*filename2
= wxT("test2");
562 if ( !wxCopyFile(filename1
, filename2
) )
564 wxPuts(wxT("ERROR: failed to copy file"));
568 wxFFile
f1(filename1
, wxT("rb")),
569 f2(filename2
, wxT("rb"));
571 if ( !f1
.IsOpened() || !f2
.IsOpened() )
573 wxPuts(wxT("ERROR: failed to open file(s)"));
578 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
580 wxPuts(wxT("ERROR: failed to read file(s)"));
584 if ( (s1
.length() != s2
.length()) ||
585 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
587 wxPuts(wxT("ERROR: copy error!"));
591 wxPuts(wxT("File was copied ok."));
597 if ( !wxRemoveFile(filename2
) )
599 wxPuts(wxT("ERROR: failed to remove the file"));
602 wxPuts(wxEmptyString
);
605 static void TestTempFile()
607 wxPuts(wxT("*** wxTempFile test ***"));
610 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
612 if ( tmpFile
.Commit() )
613 wxPuts(wxT("File committed."));
615 wxPuts(wxT("ERROR: could't commit temp file."));
617 wxRemoveFile(wxT("test2"));
620 wxPuts(wxEmptyString
);
625 // ----------------------------------------------------------------------------
627 // ----------------------------------------------------------------------------
631 #include "wx/confbase.h"
632 #include "wx/fileconf.h"
634 static const struct FileConfTestData
636 const wxChar
*name
; // value name
637 const wxChar
*value
; // the value from the file
640 { wxT("value1"), wxT("one") },
641 { wxT("value2"), wxT("two") },
642 { wxT("novalue"), wxT("default") },
645 static void TestFileConfRead()
647 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
649 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
650 wxT("testdata.fc"), wxEmptyString
,
651 wxCONFIG_USE_RELATIVE_PATH
);
653 // test simple reading
654 wxPuts(wxT("\nReading config file:"));
655 wxString
defValue(wxT("default")), value
;
656 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
658 const FileConfTestData
& data
= fcTestData
[n
];
659 value
= fileconf
.Read(data
.name
, defValue
);
660 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
661 if ( value
== data
.value
)
667 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
671 // test enumerating the entries
672 wxPuts(wxT("\nEnumerating all root entries:"));
675 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
678 wxPrintf(wxT("\t%s = %s\n"),
680 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
682 cont
= fileconf
.GetNextEntry(name
, dummy
);
685 static const wxChar
*testEntry
= wxT("TestEntry");
686 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
687 fileconf
.Write(testEntry
, wxT("A value"));
688 fileconf
.DeleteEntry(testEntry
);
689 wxPrintf(fileconf
.HasEntry(testEntry
) ? wxT("ERROR\n") : wxT("ok\n"));
692 #endif // TEST_FILECONF
694 // ----------------------------------------------------------------------------
696 // ----------------------------------------------------------------------------
700 #include "wx/filename.h"
703 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
707 wxString full
= fn
.GetFullPath();
709 wxString vol
, path
, name
, ext
;
710 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
712 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
713 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
715 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
716 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
717 path
.c_str(), name
.c_str(), ext
.c_str());
719 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
720 wxPrintf(wxT("with volume: \t'%s'\n"),
721 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
722 wxPrintf(wxT("with separator:\t'%s'\n"),
723 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
724 wxPrintf(wxT("with both: \t'%s'\n"),
725 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
727 wxPuts(wxT("The directories in the path are:"));
728 wxArrayString dirs
= fn
.GetDirs();
729 size_t count
= dirs
.GetCount();
730 for ( size_t n
= 0; n
< count
; n
++ )
732 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
737 static void TestFileNameTemp()
739 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
741 static const wxChar
*tmpprefixes
[] =
749 wxT("/tmp/foo/bar"), // this one must be an error
753 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
755 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
758 // "error" is not in upper case because it may be ok
759 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
763 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
764 tmpprefixes
[n
], path
.c_str());
766 if ( !wxRemoveFile(path
) )
768 wxLogWarning(wxT("Failed to remove temp file '%s'"),
775 static void TestFileNameDirManip()
777 // TODO: test AppendDir(), RemoveDir(), ...
780 static void TestFileNameComparison()
785 static void TestFileNameOperations()
790 static void TestFileNameCwd()
795 #endif // TEST_FILENAME
797 // ----------------------------------------------------------------------------
798 // wxFileName time functions
799 // ----------------------------------------------------------------------------
803 #include "wx/filename.h"
804 #include "wx/datetime.h"
806 static void TestFileGetTimes()
808 wxFileName
fn(wxT("testdata.fc"));
810 wxDateTime dtAccess
, dtMod
, dtCreate
;
811 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
813 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
817 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
819 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
820 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
821 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
822 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
827 static void TestFileSetTimes()
829 wxFileName
fn(wxT("testdata.fc"));
833 wxPrintf(wxT("ERROR: Touch() failed.\n"));
838 #endif // TEST_FILETIME
840 // ----------------------------------------------------------------------------
842 // ----------------------------------------------------------------------------
847 #include "wx/utils.h" // for wxSetEnv
849 static wxLocale gs_localeDefault
;
850 // NOTE: don't init it here as it needs a wxAppTraits object
851 // and thus must be init-ed after creation of the wxInitializer
852 // class in the main()
854 // find the name of the language from its value
855 static const wxChar
*GetLangName(int lang
)
857 static const wxChar
*languageNames
[] =
867 wxT("ARABIC_ALGERIA"),
868 wxT("ARABIC_BAHRAIN"),
871 wxT("ARABIC_JORDAN"),
872 wxT("ARABIC_KUWAIT"),
873 wxT("ARABIC_LEBANON"),
875 wxT("ARABIC_MOROCCO"),
878 wxT("ARABIC_SAUDI_ARABIA"),
881 wxT("ARABIC_TUNISIA"),
888 wxT("AZERI_CYRILLIC"),
903 wxT("CHINESE_SIMPLIFIED"),
904 wxT("CHINESE_TRADITIONAL"),
905 wxT("CHINESE_HONGKONG"),
906 wxT("CHINESE_MACAU"),
907 wxT("CHINESE_SINGAPORE"),
908 wxT("CHINESE_TAIWAN"),
914 wxT("DUTCH_BELGIAN"),
918 wxT("ENGLISH_AUSTRALIA"),
919 wxT("ENGLISH_BELIZE"),
920 wxT("ENGLISH_BOTSWANA"),
921 wxT("ENGLISH_CANADA"),
922 wxT("ENGLISH_CARIBBEAN"),
923 wxT("ENGLISH_DENMARK"),
925 wxT("ENGLISH_JAMAICA"),
926 wxT("ENGLISH_NEW_ZEALAND"),
927 wxT("ENGLISH_PHILIPPINES"),
928 wxT("ENGLISH_SOUTH_AFRICA"),
929 wxT("ENGLISH_TRINIDAD"),
930 wxT("ENGLISH_ZIMBABWE"),
938 wxT("FRENCH_BELGIAN"),
939 wxT("FRENCH_CANADIAN"),
940 wxT("FRENCH_LUXEMBOURG"),
941 wxT("FRENCH_MONACO"),
947 wxT("GERMAN_AUSTRIAN"),
948 wxT("GERMAN_BELGIUM"),
949 wxT("GERMAN_LIECHTENSTEIN"),
950 wxT("GERMAN_LUXEMBOURG"),
968 wxT("ITALIAN_SWISS"),
973 wxT("KASHMIRI_INDIA"),
991 wxT("MALAY_BRUNEI_DARUSSALAM"),
992 wxT("MALAY_MALAYSIA"),
1001 wxT("NEPALI_INDIA"),
1002 wxT("NORWEGIAN_BOKMAL"),
1003 wxT("NORWEGIAN_NYNORSK"),
1010 wxT("PORTUGUESE_BRAZILIAN"),
1013 wxT("RHAETO_ROMANCE"),
1016 wxT("RUSSIAN_UKRAINE"),
1020 wxT("SCOTS_GAELIC"),
1022 wxT("SERBIAN_CYRILLIC"),
1023 wxT("SERBIAN_LATIN"),
1024 wxT("SERBO_CROATIAN"),
1035 wxT("SPANISH_ARGENTINA"),
1036 wxT("SPANISH_BOLIVIA"),
1037 wxT("SPANISH_CHILE"),
1038 wxT("SPANISH_COLOMBIA"),
1039 wxT("SPANISH_COSTA_RICA"),
1040 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1041 wxT("SPANISH_ECUADOR"),
1042 wxT("SPANISH_EL_SALVADOR"),
1043 wxT("SPANISH_GUATEMALA"),
1044 wxT("SPANISH_HONDURAS"),
1045 wxT("SPANISH_MEXICAN"),
1046 wxT("SPANISH_MODERN"),
1047 wxT("SPANISH_NICARAGUA"),
1048 wxT("SPANISH_PANAMA"),
1049 wxT("SPANISH_PARAGUAY"),
1050 wxT("SPANISH_PERU"),
1051 wxT("SPANISH_PUERTO_RICO"),
1052 wxT("SPANISH_URUGUAY"),
1054 wxT("SPANISH_VENEZUELA"),
1058 wxT("SWEDISH_FINLAND"),
1076 wxT("URDU_PAKISTAN"),
1078 wxT("UZBEK_CYRILLIC"),
1091 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1092 return languageNames
[lang
];
1094 return wxT("INVALID");
1097 static void TestDefaultLang()
1099 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1101 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1103 static const wxChar
*langStrings
[] =
1105 NULL
, // system default
1112 wxT("de_DE.iso88591"),
1114 wxT("?"), // invalid lang spec
1115 wxT("klingonese"), // I bet on some systems it does exist...
1118 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1119 wxLocale::GetSystemEncodingName().c_str(),
1120 wxLocale::GetSystemEncoding());
1122 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1124 const wxChar
*langStr
= langStrings
[n
];
1127 // FIXME: this doesn't do anything at all under Windows, we need
1128 // to create a new wxLocale!
1129 wxSetEnv(wxT("LC_ALL"), langStr
);
1132 int lang
= gs_localeDefault
.GetSystemLanguage();
1133 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1134 langStr
? langStr
: wxT("system default"), GetLangName(lang
));
1138 #endif // TEST_LOCALE
1140 // ----------------------------------------------------------------------------
1142 // ----------------------------------------------------------------------------
1146 #include "wx/mimetype.h"
1148 static void TestMimeEnum()
1150 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1152 wxArrayString mimetypes
;
1154 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1156 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1161 for ( size_t n
= 0; n
< count
; n
++ )
1163 wxFileType
*filetype
=
1164 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1167 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1168 mimetypes
[n
].c_str());
1172 filetype
->GetDescription(&desc
);
1173 filetype
->GetExtensions(exts
);
1175 filetype
->GetIcon(NULL
);
1178 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1181 extsAll
<< wxT(", ");
1185 wxPrintf(wxT("\t%s: %s (%s)\n"),
1186 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1189 wxPuts(wxEmptyString
);
1192 static void TestMimeFilename()
1194 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1196 static const wxChar
*filenames
[] =
1199 wxT("document.pdf"),
1201 wxT("picture.jpeg"),
1204 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1206 const wxString fname
= filenames
[n
];
1207 wxString ext
= fname
.AfterLast(wxT('.'));
1208 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1211 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1216 if ( !ft
->GetDescription(&desc
) )
1217 desc
= wxT("<no description>");
1220 if ( !ft
->GetOpenCommand(&cmd
,
1221 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1222 cmd
= wxT("<no command available>");
1224 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1226 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1227 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1233 wxPuts(wxEmptyString
);
1236 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1239 static void TestMimeOverride()
1241 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1243 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1244 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1246 if ( wxFile::Exists(mailcap
) )
1247 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1249 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? wxT("ok") : wxT("ERROR"));
1251 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1254 if ( wxFile::Exists(mimetypes
) )
1255 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1257 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? wxT("ok") : wxT("ERROR"));
1259 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1262 wxPuts(wxEmptyString
);
1265 static void TestMimeAssociate()
1267 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1269 wxFileTypeInfo
ftInfo(
1270 wxT("application/x-xyz"),
1271 wxT("xyzview '%s'"), // open cmd
1272 wxT(""), // print cmd
1273 wxT("XYZ File"), // description
1274 wxT(".xyz"), // extensions
1275 wxNullPtr
// end of extensions
1277 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1279 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1282 wxPuts(wxT("ERROR: failed to create association!"));
1286 // TODO: read it back
1290 wxPuts(wxEmptyString
);
1297 // ----------------------------------------------------------------------------
1298 // module dependencies feature
1299 // ----------------------------------------------------------------------------
1303 #include "wx/module.h"
1305 class wxTestModule
: public wxModule
1308 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1309 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1312 class wxTestModuleA
: public wxTestModule
1317 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1320 class wxTestModuleB
: public wxTestModule
1325 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1328 class wxTestModuleC
: public wxTestModule
1333 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1336 class wxTestModuleD
: public wxTestModule
1341 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1344 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1345 wxTestModuleC::wxTestModuleC()
1347 AddDependency(CLASSINFO(wxTestModuleD
));
1350 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1351 wxTestModuleA::wxTestModuleA()
1353 AddDependency(CLASSINFO(wxTestModuleB
));
1354 AddDependency(CLASSINFO(wxTestModuleD
));
1357 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1358 wxTestModuleD::wxTestModuleD()
1362 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1363 wxTestModuleB::wxTestModuleB()
1365 AddDependency(CLASSINFO(wxTestModuleD
));
1366 AddDependency(CLASSINFO(wxTestModuleC
));
1369 #endif // TEST_MODULE
1371 // ----------------------------------------------------------------------------
1372 // misc information functions
1373 // ----------------------------------------------------------------------------
1375 #ifdef TEST_INFO_FUNCTIONS
1377 #include "wx/utils.h"
1379 #if TEST_INTERACTIVE
1380 static void TestDiskInfo()
1382 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1386 wxChar pathname
[128];
1387 wxPrintf(wxT("\nEnter a directory name: "));
1388 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1391 // kill the last '\n'
1392 pathname
[wxStrlen(pathname
) - 1] = 0;
1394 wxLongLong total
, free
;
1395 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1397 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1401 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1402 (total
/ 1024).ToString().c_str(),
1403 (free
/ 1024).ToString().c_str(),
1408 #endif // TEST_INTERACTIVE
1410 static void TestOsInfo()
1412 wxPuts(wxT("*** Testing OS info functions ***\n"));
1415 wxGetOsVersion(&major
, &minor
);
1416 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1417 wxGetOsDescription().c_str(), major
, minor
);
1419 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1421 wxPrintf(wxT("Host name is %s (%s).\n"),
1422 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1424 wxPuts(wxEmptyString
);
1427 static void TestPlatformInfo()
1429 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1431 // get this platform
1432 wxPlatformInfo plat
;
1434 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1435 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1436 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1437 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1438 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1439 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1441 wxPuts(wxEmptyString
);
1444 static void TestUserInfo()
1446 wxPuts(wxT("*** Testing user info functions ***\n"));
1448 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1449 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1450 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1451 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1453 wxPuts(wxEmptyString
);
1456 #endif // TEST_INFO_FUNCTIONS
1458 // ----------------------------------------------------------------------------
1460 // ----------------------------------------------------------------------------
1462 #ifdef TEST_PATHLIST
1465 #define CMD_IN_PATH wxT("ls")
1467 #define CMD_IN_PATH wxT("command.com")
1470 static void TestPathList()
1472 wxPuts(wxT("*** Testing wxPathList ***\n"));
1474 wxPathList pathlist
;
1475 pathlist
.AddEnvList(wxT("PATH"));
1476 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1479 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1483 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1487 #endif // TEST_PATHLIST
1489 // ----------------------------------------------------------------------------
1490 // regular expressions
1491 // ----------------------------------------------------------------------------
1493 #if defined TEST_REGEX && TEST_INTERACTIVE
1495 #include "wx/regex.h"
1497 static void TestRegExInteractive()
1499 wxPuts(wxT("*** Testing RE interactively ***"));
1503 wxChar pattern
[128];
1504 wxPrintf(wxT("\nEnter a pattern: "));
1505 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1508 // kill the last '\n'
1509 pattern
[wxStrlen(pattern
) - 1] = 0;
1512 if ( !re
.Compile(pattern
) )
1520 wxPrintf(wxT("Enter text to match: "));
1521 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1524 // kill the last '\n'
1525 text
[wxStrlen(text
) - 1] = 0;
1527 if ( !re
.Matches(text
) )
1529 wxPrintf(wxT("No match.\n"));
1533 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1536 for ( size_t n
= 1; ; n
++ )
1538 if ( !re
.GetMatch(&start
, &len
, n
) )
1543 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1544 n
, wxString(text
+ start
, len
).c_str());
1551 #endif // TEST_REGEX
1553 // ----------------------------------------------------------------------------
1555 // ----------------------------------------------------------------------------
1559 #include "wx/protocol/ftp.h"
1560 #include "wx/protocol/log.h"
1562 #define FTP_ANONYMOUS
1566 #ifdef FTP_ANONYMOUS
1567 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
1568 static const wxChar
*directory
= wxT("/pub");
1569 static const wxChar
*filename
= wxT("welcome.msg");
1571 static const wxChar
*hostname
= "localhost";
1572 static const wxChar
*directory
= wxT("/etc");
1573 static const wxChar
*filename
= wxT("issue");
1576 static bool TestFtpConnect()
1578 wxPuts(wxT("*** Testing FTP connect ***"));
1580 #ifdef FTP_ANONYMOUS
1581 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
1582 #else // !FTP_ANONYMOUS
1584 wxFgets(user
, WXSIZEOF(user
), stdin
);
1585 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
1588 wxChar password
[256];
1589 wxPrintf(wxT("Password for %s: "), password
);
1590 wxFgets(password
, WXSIZEOF(password
), stdin
);
1591 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
1592 ftp
->SetPassword(password
);
1594 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
1595 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
1597 if ( !ftp
->Connect(hostname
) )
1599 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
1605 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
1606 hostname
, ftp
->Pwd().c_str());
1613 #if TEST_INTERACTIVE
1614 static void TestFtpInteractive()
1616 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
1622 wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
1623 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
1626 // kill the last '\n'
1627 buf
[wxStrlen(buf
) - 1] = 0;
1629 // special handling of LIST and NLST as they require data connection
1630 wxString
start(buf
, 4);
1632 if ( start
== wxT("LIST") || start
== wxT("NLST") )
1635 if ( wxStrlen(buf
) > 4 )
1638 wxArrayString files
;
1639 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
1641 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
1645 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
1646 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
1647 size_t count
= files
.GetCount();
1648 for ( size_t n
= 0; n
< count
; n
++ )
1650 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
1652 wxPuts(wxT("--- End of the file list"));
1655 else if ( start
== wxT("QUIT") )
1657 break; // get out of here!
1661 wxChar ch
= ftp
->SendCommand(buf
);
1662 wxPrintf(wxT("Command %s"), ch
? wxT("succeeded") : wxT("failed"));
1665 wxPrintf(wxT(" (return code %c)"), ch
);
1668 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
1674 #endif // TEST_INTERACTIVE
1677 // ----------------------------------------------------------------------------
1679 // ----------------------------------------------------------------------------
1681 #ifdef TEST_STACKWALKER
1683 #if wxUSE_STACKWALKER
1685 #include "wx/stackwalk.h"
1687 class StackDump
: public wxStackWalker
1690 StackDump(const char *argv0
)
1691 : wxStackWalker(argv0
)
1695 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
1697 wxPuts(wxT("Stack dump:"));
1699 wxStackWalker::Walk(skip
, maxdepth
);
1703 virtual void OnStackFrame(const wxStackFrame
& frame
)
1705 printf("[%2d] ", (int) frame
.GetLevel());
1707 wxString name
= frame
.GetName();
1708 if ( !name
.empty() )
1710 printf("%-20.40s", (const char*)name
.mb_str());
1714 printf("0x%08lx", (unsigned long)frame
.GetAddress());
1717 if ( frame
.HasSourceLocation() )
1720 (const char*)frame
.GetFileName().mb_str(),
1721 (int)frame
.GetLine());
1727 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
1729 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
1730 (const char*)name
.mb_str(),
1731 (const char*)val
.mb_str());
1736 static void TestStackWalk(const char *argv0
)
1738 wxPuts(wxT("*** Testing wxStackWalker ***"));
1740 StackDump
dump(argv0
);
1746 #endif // wxUSE_STACKWALKER
1748 #endif // TEST_STACKWALKER
1750 // ----------------------------------------------------------------------------
1752 // ----------------------------------------------------------------------------
1754 #ifdef TEST_STDPATHS
1756 #include "wx/stdpaths.h"
1757 #include "wx/wxchar.h" // wxPrintf
1759 static void TestStandardPaths()
1761 wxPuts(wxT("*** Testing wxStandardPaths ***"));
1763 wxTheApp
->SetAppName(wxT("console"));
1765 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
1766 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
1767 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
1768 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
1769 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
1770 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
1771 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
1772 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
1773 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
1774 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
1775 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
1776 wxPrintf(wxT("Localized res. dir:\t%s\n"),
1777 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
1778 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
1779 stdp
.GetLocalizedResourcesDir
1782 wxStandardPaths::ResourceCat_Messages
1788 #endif // TEST_STDPATHS
1790 // ----------------------------------------------------------------------------
1792 // ----------------------------------------------------------------------------
1794 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
1800 #include "wx/volume.h"
1802 static const wxChar
*volumeKinds
[] =
1808 wxT("network volume"),
1809 wxT("other volume"),
1812 static void TestFSVolume()
1814 wxPuts(wxT("*** Testing wxFSVolume class ***"));
1816 wxArrayString volumes
= wxFSVolume::GetVolumes();
1817 size_t count
= volumes
.GetCount();
1821 wxPuts(wxT("ERROR: no mounted volumes?"));
1825 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
1827 for ( size_t n
= 0; n
< count
; n
++ )
1829 wxFSVolume
vol(volumes
[n
]);
1832 wxPuts(wxT("ERROR: couldn't create volume"));
1836 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
1838 vol
.GetDisplayName().c_str(),
1839 vol
.GetName().c_str(),
1840 volumeKinds
[vol
.GetKind()],
1841 vol
.IsWritable() ? wxT("rw") : wxT("ro"),
1842 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? wxT("removable")
1849 #endif // TEST_VOLUME
1851 // ----------------------------------------------------------------------------
1853 // ----------------------------------------------------------------------------
1855 #ifdef TEST_DATETIME
1857 #include "wx/math.h"
1858 #include "wx/datetime.h"
1860 #if TEST_INTERACTIVE
1862 static void TestDateTimeInteractive()
1864 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
1870 wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
1871 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
1874 // kill the last '\n'
1875 buf
[wxStrlen(buf
) - 1] = 0;
1877 if ( wxString(buf
).CmpNoCase("quit") == 0 )
1881 const wxChar
*p
= dt
.ParseDate(buf
);
1884 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
1890 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
1893 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
1894 dt
.Format(wxT("%b %d, %Y")).c_str(),
1896 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
1897 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
1898 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
1904 #endif // TEST_INTERACTIVE
1905 #endif // TEST_DATETIME
1907 // ----------------------------------------------------------------------------
1909 // ----------------------------------------------------------------------------
1911 #ifdef TEST_SNGLINST
1913 #include "wx/snglinst.h"
1915 static bool TestSingleIstance()
1917 wxPuts(wxT("\n*** Testing wxSingleInstanceChecker ***"));
1919 wxSingleInstanceChecker checker
;
1920 if ( checker
.Create(wxT(".wxconsole.lock")) )
1922 if ( checker
.IsAnotherRunning() )
1924 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
1929 // wait some time to give time to launch another instance
1930 wxPuts(wxT("If you try to run another instance of this program now, it won't start."));
1931 wxPrintf(wxT("Press \"Enter\" to exit wxSingleInstanceChecker test and proceed..."));
1934 else // failed to create
1936 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
1943 #endif // TEST_SNGLINST
1946 // ----------------------------------------------------------------------------
1948 // ----------------------------------------------------------------------------
1950 int main(int argc
, char **argv
)
1953 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
1958 for (n
= 0; n
< argc
; n
++ )
1960 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
1961 wxArgv
[n
] = wxStrdup(warg
);
1966 #else // !wxUSE_UNICODE
1968 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1970 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
1972 wxInitializer initializer
;
1975 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
1980 #ifdef TEST_SNGLINST
1981 if (!TestSingleIstance())
1983 #endif // TEST_SNGLINST
1995 TestDllListLoaded();
1996 #endif // TEST_DYNLIB
2000 #endif // TEST_ENVIRON
2002 #ifdef TEST_FILECONF
2004 #endif // TEST_FILECONF
2008 #endif // TEST_LOCALE
2011 wxPuts(wxT("*** Testing wxLog ***"));
2014 for ( size_t n
= 0; n
< 8000; n
++ )
2016 s
<< (wxChar
)(wxT('A') + (n
% 26));
2019 wxLogWarning(wxT("The length of the string is %lu"),
2020 (unsigned long)s
.length());
2023 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
2025 // this one shouldn't be truncated
2028 // but this one will because log functions use fixed size buffer
2029 // (note that it doesn't need '\n' at the end neither - will be added
2031 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
2041 #ifdef TEST_FILENAME
2044 TestFileNameDirManip();
2045 TestFileNameComparison();
2046 TestFileNameOperations();
2047 #endif // TEST_FILENAME
2049 #ifdef TEST_FILETIME
2054 #endif // TEST_FILETIME
2057 wxLog::AddTraceMask(FTP_TRACE_MASK
);
2059 // wxFTP cannot be a static variable as its ctor needs to access
2060 // wxWidgets internals after it has been initialized
2062 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
2063 if ( TestFtpConnect() )
2064 TestFtpInteractive();
2065 //else: connecting to the FTP server failed
2071 //wxLog::AddTraceMask(wxT("mime"));
2075 TestMimeAssociate();
2080 #ifdef TEST_INFO_FUNCTIONS
2085 #if TEST_INTERACTIVE
2088 #endif // TEST_INFO_FUNCTIONS
2090 #ifdef TEST_PATHLIST
2092 #endif // TEST_PATHLIST
2096 #endif // TEST_PRINTF
2098 #if defined TEST_REGEX && TEST_INTERACTIVE
2099 TestRegExInteractive();
2100 #endif // defined TEST_REGEX && TEST_INTERACTIVE
2102 #ifdef TEST_DATETIME
2103 #if TEST_INTERACTIVE
2104 TestDateTimeInteractive();
2106 #endif // TEST_DATETIME
2108 #ifdef TEST_STACKWALKER
2109 #if wxUSE_STACKWALKER
2110 TestStackWalk(argv
[0]);
2112 #endif // TEST_STACKWALKER
2114 #ifdef TEST_STDPATHS
2115 TestStandardPaths();
2119 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
2121 #endif // TEST_USLEEP
2125 #endif // TEST_VOLUME
2129 for ( int n
= 0; n
< argc
; n
++ )
2134 #endif // wxUSE_UNICODE