1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // IMPORTANT NOTE FOR WXWIDGETS USERS:
13 // If you're a wxWidgets user and you're looking at this file to learn how to
14 // structure a wxWidgets console application, then you don't have much to learn.
15 // This application is used more for testing rather than as sample but
16 // basically the following simple block is enough for you to start your
17 // own console application:
20 int main(int argc, char **argv)
22 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
24 wxInitializer initializer;
27 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
31 static const wxCmdLineEntryDesc cmdLineDesc[] =
33 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
34 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
35 // ... your other command line options here...
40 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
41 switch ( parser.Parse() )
44 wxLogMessage(wxT("Help was given, terminating."));
48 // everything is ok; proceed
52 wxLogMessage(wxT("Syntax error detected, aborting."));
56 // do something useful here
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
75 #include "wx/string.h"
77 #include "wx/filename.h"
80 #include "wx/apptrait.h"
81 #include "wx/platinfo.h"
82 #include "wx/wxchar.h"
84 // without this pragma, the stupid compiler precompiles #defines below so that
85 // changing them doesn't "take place" later!
90 // ----------------------------------------------------------------------------
91 // conditional compilation
92 // ----------------------------------------------------------------------------
95 A note about all these conditional compilation macros: this file is used
96 both as a test suite for various non-GUI wxWidgets classes and as a
97 scratchpad for quick tests. So there are two compilation modes: if you
98 define TEST_ALL all tests are run, otherwise you may enable the individual
99 tests individually in the "#else" branch below.
102 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
103 // test, define it to 1 to do all tests.
109 #define TEST_DATETIME
114 #define TEST_FILECONF
115 #define TEST_FILENAME
116 #define TEST_FILETIME
117 #define TEST_INFO_FUNCTIONS
122 #define TEST_PATHLIST
126 #define TEST_REGISTRY
127 #define TEST_SCOPEGUARD
128 #define TEST_SNGLINST
129 // #define TEST_SOCKETS --FIXME! (RN)
130 #else // #if TEST_ALL
131 #define TEST_DATETIME
133 #define TEST_STDPATHS
134 #define TEST_STACKWALKER
138 // some tests are interactive, define this to run them
139 #ifdef TEST_INTERACTIVE
140 #undef TEST_INTERACTIVE
142 #define TEST_INTERACTIVE 1
144 #define TEST_INTERACTIVE 1
147 // ============================================================================
149 // ============================================================================
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 #if defined(TEST_SOCKETS)
157 // replace TABs with \t and CRs with \n
158 static wxString
MakePrintable(const wxChar
*s
)
161 (void)str
.Replace(wxT("\t"), wxT("\\t"));
162 (void)str
.Replace(wxT("\n"), wxT("\\n"));
163 (void)str
.Replace(wxT("\r"), wxT("\\r"));
168 #endif // MakePrintable() is used
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
176 #include "wx/cmdline.h"
177 #include "wx/datetime.h"
179 #if wxUSE_CMDLINE_PARSER
181 static void ShowCmdLine(const wxCmdLineParser
& parser
)
183 wxString s
= wxT("Command line parsed successfully:\nInput files: ");
185 size_t count
= parser
.GetParamCount();
186 for ( size_t param
= 0; param
< count
; param
++ )
188 s
<< parser
.GetParam(param
) << ' ';
192 << wxT("Verbose:\t") << (parser
.Found(wxT("v")) ?
wxT("yes") : wxT("no")) << '\n'
193 << wxT("Quiet:\t") << (parser
.Found(wxT("q")) ?
wxT("yes") : wxT("no")) << '\n';
199 if ( parser
.Found(wxT("o"), &strVal
) )
200 s
<< wxT("Output file:\t") << strVal
<< '\n';
201 if ( parser
.Found(wxT("i"), &strVal
) )
202 s
<< wxT("Input dir:\t") << strVal
<< '\n';
203 if ( parser
.Found(wxT("s"), &lVal
) )
204 s
<< wxT("Size:\t") << lVal
<< '\n';
205 if ( parser
.Found(wxT("f"), &dVal
) )
206 s
<< wxT("Double:\t") << dVal
<< '\n';
207 if ( parser
.Found(wxT("d"), &dt
) )
208 s
<< wxT("Date:\t") << dt
.FormatISODate() << '\n';
209 if ( parser
.Found(wxT("project_name"), &strVal
) )
210 s
<< wxT("Project:\t") << strVal
<< '\n';
215 #endif // wxUSE_CMDLINE_PARSER
217 static void TestCmdLineConvert()
219 static const wxChar
*cmdlines
[] =
222 wxT("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
223 wxT("literal \\\" and \"\""),
226 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
228 const wxChar
*cmdline
= cmdlines
[n
];
229 wxPrintf(wxT("Parsing: %s\n"), cmdline
);
230 wxArrayString args
= wxCmdLineParser
::ConvertStringToArgs(cmdline
);
232 size_t count
= args
.GetCount();
233 wxPrintf(wxT("\targc = %u\n"), count
);
234 for ( size_t arg
= 0; arg
< count
; arg
++ )
236 wxPrintf(wxT("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
241 #endif // TEST_CMDLINE
243 // ----------------------------------------------------------------------------
245 // ----------------------------------------------------------------------------
252 static const wxChar
*ROOTDIR
= wxT("/");
253 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
254 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
255 static const wxChar
*ROOTDIR
= wxT("c:\\");
256 static const wxChar
*TESTDIR
= wxT("d:\\");
258 #error "don't know where the root directory is"
261 static void TestDirEnumHelper(wxDir
& dir
,
262 int flags
= wxDIR_DEFAULT
,
263 const wxString
& filespec
= wxEmptyString
)
267 if ( !dir
.IsOpened() )
270 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
273 wxPrintf(wxT("\t%s\n"), filename
.c_str());
275 cont
= dir
.GetNext(&filename
);
278 wxPuts(wxEmptyString
);
283 static void TestDirEnum()
285 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
287 wxString cwd
= wxGetCwd();
288 if ( !wxDir
::Exists(cwd
) )
290 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
295 if ( !dir
.IsOpened() )
297 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
301 wxPuts(wxT("Enumerating everything in current directory:"));
302 TestDirEnumHelper(dir
);
304 wxPuts(wxT("Enumerating really everything in current directory:"));
305 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
307 wxPuts(wxT("Enumerating object files in current directory:"));
308 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
310 wxPuts(wxT("Enumerating directories in current directory:"));
311 TestDirEnumHelper(dir
, wxDIR_DIRS
);
313 wxPuts(wxT("Enumerating files in current directory:"));
314 TestDirEnumHelper(dir
, wxDIR_FILES
);
316 wxPuts(wxT("Enumerating files including hidden in current directory:"));
317 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
321 wxPuts(wxT("Enumerating everything in root directory:"));
322 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
324 wxPuts(wxT("Enumerating directories in root directory:"));
325 TestDirEnumHelper(dir
, wxDIR_DIRS
);
327 wxPuts(wxT("Enumerating files in root directory:"));
328 TestDirEnumHelper(dir
, wxDIR_FILES
);
330 wxPuts(wxT("Enumerating files including hidden in root directory:"));
331 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
333 wxPuts(wxT("Enumerating files in non existing directory:"));
334 wxDir
dirNo(wxT("nosuchdir"));
335 TestDirEnumHelper(dirNo
);
340 class DirPrintTraverser
: public wxDirTraverser
343 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
345 return wxDIR_CONTINUE
;
348 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
350 wxString path
, name
, ext
;
351 wxFileName
::SplitPath(dirname
, &path
, &name
, &ext
);
354 name
<< wxT('.') << ext
;
357 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
359 if ( wxIsPathSeparator(*p
) )
363 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
365 return wxDIR_CONTINUE
;
369 static void TestDirTraverse()
371 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
375 size_t n
= wxDir
::GetAllFiles(TESTDIR
, &files
);
376 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
379 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
380 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
383 // enum again with custom traverser
384 wxPuts(wxT("Now enumerating directories:"));
386 DirPrintTraverser traverser
;
387 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
392 static void TestDirExists()
394 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
396 static const wxChar
*dirnames
[] =
399 #if defined(__WXMSW__)
402 wxT("\\\\share\\file"),
406 wxT("c:\\autoexec.bat"),
407 #elif defined(__UNIX__)
416 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
418 wxPrintf(wxT("%-40s: %s\n"),
420 wxDir
::Exists(dirnames
[n
]) ?
wxT("exists")
421 : wxT("doesn't exist"));
429 // ----------------------------------------------------------------------------
431 // ----------------------------------------------------------------------------
435 #include "wx/dynlib.h"
437 static void TestDllLoad()
439 #if defined(__WXMSW__)
440 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
441 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
442 #elif defined(__UNIX__)
443 // weird: using just libc.so does *not* work!
444 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
445 static const wxChar
*FUNC_NAME
= wxT("strlen");
447 #error "don't know how to test wxDllLoader on this platform"
450 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
452 wxDynamicLibrary
lib(LIB_NAME
);
453 if ( !lib
.IsLoaded() )
455 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
459 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
460 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
463 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
464 FUNC_NAME
, LIB_NAME
);
468 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
469 FUNC_NAME
, LIB_NAME
);
471 if ( pfnStrlen("foo") != 3 )
473 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
477 wxPuts(wxT("... ok"));
482 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
484 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
486 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
487 if ( !pfnStrlenAorW
)
489 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
490 FUNC_NAME_AW
, LIB_NAME
);
494 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
496 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
503 #if defined(__WXMSW__) || defined(__UNIX__)
505 static void TestDllListLoaded()
507 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
509 puts("\nLoaded modules:");
510 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary
::ListLoaded();
511 const size_t count
= dlls
.GetCount();
512 for ( size_t n
= 0; n
< count
; ++n
)
514 const wxDynamicLibraryDetails
& details
= dlls
[n
];
515 printf("%-45s", (const char *)details
.GetPath().mb_str());
517 void *addr
wxDUMMY_INITIALIZE(NULL
);
518 size_t len
wxDUMMY_INITIALIZE(0);
519 if ( details
.GetAddress(&addr
, &len
) )
521 printf(" %08lx:%08lx",
522 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
525 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
531 #endif // TEST_DYNLIB
533 // ----------------------------------------------------------------------------
535 // ----------------------------------------------------------------------------
539 #include "wx/utils.h"
541 static wxString
MyGetEnv(const wxString
& var
)
544 if ( !wxGetEnv(var
, &val
) )
545 val
= wxT("<empty>");
547 val
= wxString(wxT('\'')) + val
+ wxT('\'');
552 static void TestEnvironment()
554 const wxChar
*var
= wxT("wxTestVar");
556 wxPuts(wxT("*** testing environment access functions ***"));
558 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
559 wxSetEnv(var
, wxT("value for wxTestVar"));
560 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
561 wxSetEnv(var
, wxT("another value"));
562 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
564 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
565 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
568 #endif // TEST_ENVIRON
570 // ----------------------------------------------------------------------------
572 // ----------------------------------------------------------------------------
577 #include "wx/ffile.h"
578 #include "wx/textfile.h"
580 static void TestFileRead()
582 wxPuts(wxT("*** wxFile read test ***"));
584 wxFile
file(wxT("testdata.fc"));
585 if ( file
.IsOpened() )
587 wxPrintf(wxT("File length: %lu\n"), file
.Length());
589 wxPuts(wxT("File dump:\n----------"));
591 static const size_t len
= 1024;
595 size_t nRead
= file
.Read(buf
, len
);
596 if ( nRead
== (size_t)wxInvalidOffset
)
598 wxPrintf(wxT("Failed to read the file."));
602 fwrite(buf
, nRead
, 1, stdout
);
608 wxPuts(wxT("----------"));
612 wxPrintf(wxT("ERROR: can't open test file.\n"));
615 wxPuts(wxEmptyString
);
618 static void TestTextFileRead()
620 wxPuts(wxT("*** wxTextFile read test ***"));
622 wxTextFile
file(wxT("testdata.fc"));
625 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
626 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
630 wxPuts(wxT("\nDumping the entire file:"));
631 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
633 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
635 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
637 wxPuts(wxT("\nAnd now backwards:"));
638 for ( s
= file
.GetLastLine();
639 file
.GetCurrentLine() != 0;
640 s
= file
.GetPrevLine() )
642 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
644 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
648 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
651 wxPuts(wxEmptyString
);
654 static void TestFileCopy()
656 wxPuts(wxT("*** Testing wxCopyFile ***"));
658 static const wxChar
*filename1
= wxT("testdata.fc");
659 static const wxChar
*filename2
= wxT("test2");
660 if ( !wxCopyFile(filename1
, filename2
) )
662 wxPuts(wxT("ERROR: failed to copy file"));
666 wxFFile
f1(filename1
, wxT("rb")),
667 f2(filename2
, wxT("rb"));
669 if ( !f1
.IsOpened() || !f2
.IsOpened() )
671 wxPuts(wxT("ERROR: failed to open file(s)"));
676 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
678 wxPuts(wxT("ERROR: failed to read file(s)"));
682 if ( (s1
.length() != s2
.length()) ||
683 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
685 wxPuts(wxT("ERROR: copy error!"));
689 wxPuts(wxT("File was copied ok."));
695 if ( !wxRemoveFile(filename2
) )
697 wxPuts(wxT("ERROR: failed to remove the file"));
700 wxPuts(wxEmptyString
);
703 static void TestTempFile()
705 wxPuts(wxT("*** wxTempFile test ***"));
708 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
710 if ( tmpFile
.Commit() )
711 wxPuts(wxT("File committed."));
713 wxPuts(wxT("ERROR: could't commit temp file."));
715 wxRemoveFile(wxT("test2"));
718 wxPuts(wxEmptyString
);
723 // ----------------------------------------------------------------------------
725 // ----------------------------------------------------------------------------
729 #include "wx/confbase.h"
730 #include "wx/fileconf.h"
732 static const struct FileConfTestData
734 const wxChar
*name
; // value name
735 const wxChar
*value
; // the value from the file
738 { wxT("value1"), wxT("one") },
739 { wxT("value2"), wxT("two") },
740 { wxT("novalue"), wxT("default") },
743 static void TestFileConfRead()
745 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
747 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
748 wxT("testdata.fc"), wxEmptyString
,
749 wxCONFIG_USE_RELATIVE_PATH
);
751 // test simple reading
752 wxPuts(wxT("\nReading config file:"));
753 wxString
defValue(wxT("default")), value
;
754 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
756 const FileConfTestData
& data
= fcTestData
[n
];
757 value
= fileconf
.Read(data
.name
, defValue
);
758 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
759 if ( value
== data
.value
)
765 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
769 // test enumerating the entries
770 wxPuts(wxT("\nEnumerating all root entries:"));
773 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
776 wxPrintf(wxT("\t%s = %s\n"),
778 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
780 cont
= fileconf
.GetNextEntry(name
, dummy
);
783 static const wxChar
*testEntry
= wxT("TestEntry");
784 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
785 fileconf
.Write(testEntry
, wxT("A value"));
786 fileconf
.DeleteEntry(testEntry
);
787 wxPrintf(fileconf
.HasEntry(testEntry
) ?
wxT("ERROR\n") : wxT("ok\n"));
790 #endif // TEST_FILECONF
792 // ----------------------------------------------------------------------------
794 // ----------------------------------------------------------------------------
798 #include "wx/filename.h"
801 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
805 wxString full
= fn
.GetFullPath();
807 wxString vol
, path
, name
, ext
;
808 wxFileName
::SplitPath(full
, &vol
, &path
, &name
, &ext
);
810 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
811 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
813 wxFileName
::SplitPath(full
, &path
, &name
, &ext
);
814 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
815 path
.c_str(), name
.c_str(), ext
.c_str());
817 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
818 wxPrintf(wxT("with volume: \t'%s'\n"),
819 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
820 wxPrintf(wxT("with separator:\t'%s'\n"),
821 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
822 wxPrintf(wxT("with both: \t'%s'\n"),
823 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
825 wxPuts(wxT("The directories in the path are:"));
826 wxArrayString dirs
= fn
.GetDirs();
827 size_t count
= dirs
.GetCount();
828 for ( size_t n
= 0; n
< count
; n
++ )
830 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
835 static void TestFileNameTemp()
837 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
839 static const wxChar
*tmpprefixes
[] =
847 wxT("/tmp/foo/bar"), // this one must be an error
851 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
853 wxString path
= wxFileName
::CreateTempFileName(tmpprefixes
[n
]);
856 // "error" is not in upper case because it may be ok
857 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
861 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
862 tmpprefixes
[n
], path
.c_str());
864 if ( !wxRemoveFile(path
) )
866 wxLogWarning(wxT("Failed to remove temp file '%s'"),
873 static void TestFileNameDirManip()
875 // TODO: test AppendDir(), RemoveDir(), ...
878 static void TestFileNameComparison()
883 static void TestFileNameOperations()
888 static void TestFileNameCwd()
893 #endif // TEST_FILENAME
895 // ----------------------------------------------------------------------------
896 // wxFileName time functions
897 // ----------------------------------------------------------------------------
901 #include "wx/filename.h"
902 #include "wx/datetime.h"
904 static void TestFileGetTimes()
906 wxFileName
fn(wxT("testdata.fc"));
908 wxDateTime dtAccess
, dtMod
, dtCreate
;
909 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
911 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
915 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
917 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
918 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
919 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
920 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
925 static void TestFileSetTimes()
927 wxFileName
fn(wxT("testdata.fc"));
931 wxPrintf(wxT("ERROR: Touch() failed.\n"));
936 #endif // TEST_FILETIME
938 // ----------------------------------------------------------------------------
940 // ----------------------------------------------------------------------------
945 #include "wx/utils.h" // for wxSetEnv
947 static wxLocale gs_localeDefault
;
948 // NOTE: don't init it here as it needs a wxAppTraits object
949 // and thus must be init-ed after creation of the wxInitializer
950 // class in the main()
952 // find the name of the language from its value
953 static const wxChar
*GetLangName(int lang
)
955 static const wxChar
*languageNames
[] =
965 wxT("ARABIC_ALGERIA"),
966 wxT("ARABIC_BAHRAIN"),
969 wxT("ARABIC_JORDAN"),
970 wxT("ARABIC_KUWAIT"),
971 wxT("ARABIC_LEBANON"),
973 wxT("ARABIC_MOROCCO"),
976 wxT("ARABIC_SAUDI_ARABIA"),
979 wxT("ARABIC_TUNISIA"),
986 wxT("AZERI_CYRILLIC"),
1001 wxT("CHINESE_SIMPLIFIED"),
1002 wxT("CHINESE_TRADITIONAL"),
1003 wxT("CHINESE_HONGKONG"),
1004 wxT("CHINESE_MACAU"),
1005 wxT("CHINESE_SINGAPORE"),
1006 wxT("CHINESE_TAIWAN"),
1012 wxT("DUTCH_BELGIAN"),
1016 wxT("ENGLISH_AUSTRALIA"),
1017 wxT("ENGLISH_BELIZE"),
1018 wxT("ENGLISH_BOTSWANA"),
1019 wxT("ENGLISH_CANADA"),
1020 wxT("ENGLISH_CARIBBEAN"),
1021 wxT("ENGLISH_DENMARK"),
1022 wxT("ENGLISH_EIRE"),
1023 wxT("ENGLISH_JAMAICA"),
1024 wxT("ENGLISH_NEW_ZEALAND"),
1025 wxT("ENGLISH_PHILIPPINES"),
1026 wxT("ENGLISH_SOUTH_AFRICA"),
1027 wxT("ENGLISH_TRINIDAD"),
1028 wxT("ENGLISH_ZIMBABWE"),
1036 wxT("FRENCH_BELGIAN"),
1037 wxT("FRENCH_CANADIAN"),
1038 wxT("FRENCH_LUXEMBOURG"),
1039 wxT("FRENCH_MONACO"),
1040 wxT("FRENCH_SWISS"),
1045 wxT("GERMAN_AUSTRIAN"),
1046 wxT("GERMAN_BELGIUM"),
1047 wxT("GERMAN_LIECHTENSTEIN"),
1048 wxT("GERMAN_LUXEMBOURG"),
1049 wxT("GERMAN_SWISS"),
1066 wxT("ITALIAN_SWISS"),
1071 wxT("KASHMIRI_INDIA"),
1089 wxT("MALAY_BRUNEI_DARUSSALAM"),
1090 wxT("MALAY_MALAYSIA"),
1099 wxT("NEPALI_INDIA"),
1100 wxT("NORWEGIAN_BOKMAL"),
1101 wxT("NORWEGIAN_NYNORSK"),
1108 wxT("PORTUGUESE_BRAZILIAN"),
1111 wxT("RHAETO_ROMANCE"),
1114 wxT("RUSSIAN_UKRAINE"),
1118 wxT("SCOTS_GAELIC"),
1120 wxT("SERBIAN_CYRILLIC"),
1121 wxT("SERBIAN_LATIN"),
1122 wxT("SERBO_CROATIAN"),
1133 wxT("SPANISH_ARGENTINA"),
1134 wxT("SPANISH_BOLIVIA"),
1135 wxT("SPANISH_CHILE"),
1136 wxT("SPANISH_COLOMBIA"),
1137 wxT("SPANISH_COSTA_RICA"),
1138 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1139 wxT("SPANISH_ECUADOR"),
1140 wxT("SPANISH_EL_SALVADOR"),
1141 wxT("SPANISH_GUATEMALA"),
1142 wxT("SPANISH_HONDURAS"),
1143 wxT("SPANISH_MEXICAN"),
1144 wxT("SPANISH_MODERN"),
1145 wxT("SPANISH_NICARAGUA"),
1146 wxT("SPANISH_PANAMA"),
1147 wxT("SPANISH_PARAGUAY"),
1148 wxT("SPANISH_PERU"),
1149 wxT("SPANISH_PUERTO_RICO"),
1150 wxT("SPANISH_URUGUAY"),
1152 wxT("SPANISH_VENEZUELA"),
1156 wxT("SWEDISH_FINLAND"),
1174 wxT("URDU_PAKISTAN"),
1176 wxT("UZBEK_CYRILLIC"),
1189 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1190 return languageNames
[lang
];
1192 return wxT("INVALID");
1195 static void TestDefaultLang()
1197 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1199 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1201 static const wxChar
*langStrings
[] =
1203 NULL
, // system default
1210 wxT("de_DE.iso88591"),
1212 wxT("?"), // invalid lang spec
1213 wxT("klingonese"), // I bet on some systems it does exist...
1216 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1217 wxLocale
::GetSystemEncodingName().c_str(),
1218 wxLocale
::GetSystemEncoding());
1220 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1222 const wxChar
*langStr
= langStrings
[n
];
1225 // FIXME: this doesn't do anything at all under Windows, we need
1226 // to create a new wxLocale!
1227 wxSetEnv(wxT("LC_ALL"), langStr
);
1230 int lang
= gs_localeDefault
.GetSystemLanguage();
1231 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1232 langStr ? langStr
: wxT("system default"), GetLangName(lang
));
1236 #endif // TEST_LOCALE
1238 // ----------------------------------------------------------------------------
1240 // ----------------------------------------------------------------------------
1244 #include "wx/mimetype.h"
1246 static void TestMimeEnum()
1248 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1250 wxArrayString mimetypes
;
1252 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1254 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1259 for ( size_t n
= 0; n
< count
; n
++ )
1261 wxFileType
*filetype
=
1262 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1265 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1266 mimetypes
[n
].c_str());
1270 filetype
->GetDescription(&desc
);
1271 filetype
->GetExtensions(exts
);
1273 filetype
->GetIcon(NULL
);
1276 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1279 extsAll
<< wxT(", ");
1283 wxPrintf(wxT("\t%s: %s (%s)\n"),
1284 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1287 wxPuts(wxEmptyString
);
1290 static void TestMimeFilename()
1292 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1294 static const wxChar
*filenames
[] =
1297 wxT("document.pdf"),
1299 wxT("picture.jpeg"),
1302 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1304 const wxString fname
= filenames
[n
];
1305 wxString ext
= fname
.AfterLast(wxT('.'));
1306 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1309 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1314 if ( !ft
->GetDescription(&desc
) )
1315 desc
= wxT("<no description>");
1318 if ( !ft
->GetOpenCommand(&cmd
,
1319 wxFileType
::MessageParameters(fname
, wxEmptyString
)) )
1320 cmd
= wxT("<no command available>");
1322 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1324 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1325 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1331 wxPuts(wxEmptyString
);
1334 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1337 static void TestMimeOverride()
1339 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1341 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1342 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1344 if ( wxFile
::Exists(mailcap
) )
1345 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1347 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ?
wxT("ok") : wxT("ERROR"));
1349 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1352 if ( wxFile
::Exists(mimetypes
) )
1353 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1355 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ?
wxT("ok") : wxT("ERROR"));
1357 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1360 wxPuts(wxEmptyString
);
1363 static void TestMimeAssociate()
1365 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1367 wxFileTypeInfo
ftInfo(
1368 wxT("application/x-xyz"),
1369 wxT("xyzview '%s'"), // open cmd
1370 wxT(""), // print cmd
1371 wxT("XYZ File"), // description
1372 wxT(".xyz"), // extensions
1373 wxNullPtr
// end of extensions
1375 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1377 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1380 wxPuts(wxT("ERROR: failed to create association!"));
1384 // TODO: read it back
1388 wxPuts(wxEmptyString
);
1395 // ----------------------------------------------------------------------------
1396 // module dependencies feature
1397 // ----------------------------------------------------------------------------
1401 #include "wx/module.h"
1403 class wxTestModule
: public wxModule
1406 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1407 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1410 class wxTestModuleA
: public wxTestModule
1415 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1418 class wxTestModuleB
: public wxTestModule
1423 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1426 class wxTestModuleC
: public wxTestModule
1431 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1434 class wxTestModuleD
: public wxTestModule
1439 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1442 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1443 wxTestModuleC
::wxTestModuleC()
1445 AddDependency(CLASSINFO(wxTestModuleD
));
1448 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1449 wxTestModuleA
::wxTestModuleA()
1451 AddDependency(CLASSINFO(wxTestModuleB
));
1452 AddDependency(CLASSINFO(wxTestModuleD
));
1455 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1456 wxTestModuleD
::wxTestModuleD()
1460 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1461 wxTestModuleB
::wxTestModuleB()
1463 AddDependency(CLASSINFO(wxTestModuleD
));
1464 AddDependency(CLASSINFO(wxTestModuleC
));
1467 #endif // TEST_MODULE
1469 // ----------------------------------------------------------------------------
1470 // misc information functions
1471 // ----------------------------------------------------------------------------
1473 #ifdef TEST_INFO_FUNCTIONS
1475 #include "wx/utils.h"
1477 #if TEST_INTERACTIVE
1478 static void TestDiskInfo()
1480 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1484 wxChar pathname
[128];
1485 wxPrintf(wxT("\nEnter a directory name: "));
1486 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1489 // kill the last '\n'
1490 pathname
[wxStrlen(pathname
) - 1] = 0;
1492 wxLongLong total
, free
;
1493 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1495 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1499 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1500 (total
/ 1024).ToString().c_str(),
1501 (free
/ 1024).ToString().c_str(),
1506 #endif // TEST_INTERACTIVE
1508 static void TestOsInfo()
1510 wxPuts(wxT("*** Testing OS info functions ***\n"));
1513 wxGetOsVersion(&major
, &minor
);
1514 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1515 wxGetOsDescription().c_str(), major
, minor
);
1517 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1519 wxPrintf(wxT("Host name is %s (%s).\n"),
1520 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1522 wxPuts(wxEmptyString
);
1525 static void TestPlatformInfo()
1527 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1529 // get this platform
1530 wxPlatformInfo plat
;
1532 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1533 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1534 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1535 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1536 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1537 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1539 wxPuts(wxEmptyString
);
1542 static void TestUserInfo()
1544 wxPuts(wxT("*** Testing user info functions ***\n"));
1546 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1547 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1548 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1549 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1551 wxPuts(wxEmptyString
);
1554 #endif // TEST_INFO_FUNCTIONS
1556 // ----------------------------------------------------------------------------
1558 // ----------------------------------------------------------------------------
1560 #ifdef TEST_PATHLIST
1563 #define CMD_IN_PATH wxT("ls")
1565 #define CMD_IN_PATH wxT("command.com")
1568 static void TestPathList()
1570 wxPuts(wxT("*** Testing wxPathList ***\n"));
1572 wxPathList pathlist
;
1573 pathlist
.AddEnvList(wxT("PATH"));
1574 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1577 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1581 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1585 #endif // TEST_PATHLIST
1587 // ----------------------------------------------------------------------------
1588 // regular expressions
1589 // ----------------------------------------------------------------------------
1591 #if defined TEST_REGEX && TEST_INTERACTIVE
1593 #include "wx/regex.h"
1595 static void TestRegExInteractive()
1597 wxPuts(wxT("*** Testing RE interactively ***"));
1601 wxChar pattern
[128];
1602 wxPrintf(wxT("\nEnter a pattern: "));
1603 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1606 // kill the last '\n'
1607 pattern
[wxStrlen(pattern
) - 1] = 0;
1610 if ( !re
.Compile(pattern
) )
1618 wxPrintf(wxT("Enter text to match: "));
1619 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1622 // kill the last '\n'
1623 text
[wxStrlen(text
) - 1] = 0;
1625 if ( !re
.Matches(text
) )
1627 wxPrintf(wxT("No match.\n"));
1631 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1634 for ( size_t n
= 1; ; n
++ )
1636 if ( !re
.GetMatch(&start
, &len
, n
) )
1641 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1642 n
, wxString(text
+ start
, len
).c_str());
1649 #endif // TEST_REGEX
1651 // ----------------------------------------------------------------------------
1653 // ----------------------------------------------------------------------------
1656 NB: this stuff was taken from the glibc test suite and modified to build
1657 in wxWidgets: if I read the copyright below properly, this shouldn't
1663 #ifdef wxTEST_PRINTF
1664 // use our functions from wxchar.cpp
1668 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1669 // in the tests below
1670 int wxPrintf( const wxChar
*format
, ... );
1671 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1674 #include "wx/longlong.h"
1678 static void rfg1 (void);
1679 static void rfg2 (void);
1683 fmtchk (const wxChar
*fmt
)
1685 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1686 (void) wxPrintf(fmt
, 0x12);
1687 (void) wxPrintf(wxT("'\n"));
1691 fmtst1chk (const wxChar
*fmt
)
1693 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1694 (void) wxPrintf(fmt
, 4, 0x12);
1695 (void) wxPrintf(wxT("'\n"));
1699 fmtst2chk (const wxChar
*fmt
)
1701 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1702 (void) wxPrintf(fmt
, 4, 4, 0x12);
1703 (void) wxPrintf(wxT("'\n"));
1706 /* This page is covered by the following copyright: */
1708 /* (C) Copyright C E Chew
1710 * Feel free to copy, use and distribute this software provided:
1712 * 1. you do not pretend that you wrote it
1713 * 2. you leave this copyright notice intact.
1717 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1724 /* Formatted Output Test
1726 * This exercises the output formatting code.
1729 wxChar
*PointerNull
= NULL
;
1736 wxChar
*prefix
= buf
;
1739 wxPuts(wxT("\nFormatted output test"));
1740 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1741 wxStrcpy(prefix
, wxT("%"));
1742 for (i
= 0; i
< 2; i
++) {
1743 for (j
= 0; j
< 2; j
++) {
1744 for (k
= 0; k
< 2; k
++) {
1745 for (l
= 0; l
< 2; l
++) {
1746 wxStrcpy(prefix
, wxT("%"));
1747 if (i
== 0) wxStrcat(prefix
, wxT("-"));
1748 if (j
== 0) wxStrcat(prefix
, wxT("+"));
1749 if (k
== 0) wxStrcat(prefix
, wxT("#"));
1750 if (l
== 0) wxStrcat(prefix
, wxT("0"));
1751 wxPrintf(wxT("%5s |"), prefix
);
1752 wxStrcpy(tp
, prefix
);
1753 wxStrcat(tp
, wxT("6d |"));
1755 wxStrcpy(tp
, prefix
);
1756 wxStrcat(tp
, wxT("6o |"));
1758 wxStrcpy(tp
, prefix
);
1759 wxStrcat(tp
, wxT("6x |"));
1761 wxStrcpy(tp
, prefix
);
1762 wxStrcat(tp
, wxT("6X |"));
1764 wxStrcpy(tp
, prefix
);
1765 wxStrcat(tp
, wxT("6u |"));
1767 wxPrintf(wxT("\n"));
1772 wxPrintf(wxT("%10s\n"), PointerNull
);
1773 wxPrintf(wxT("%-10s\n"), PointerNull
);
1776 static void TestPrintf()
1778 static wxChar shortstr
[] = wxT("Hi, Z.");
1779 static wxChar longstr
[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1780 I am ready for my first lesson today.");
1782 wxString test_format
;
1784 fmtchk(wxT("%.4x"));
1785 fmtchk(wxT("%04x"));
1786 fmtchk(wxT("%4.4x"));
1787 fmtchk(wxT("%04.4x"));
1788 fmtchk(wxT("%4.3x"));
1789 fmtchk(wxT("%04.3x"));
1791 fmtst1chk(wxT("%.*x"));
1792 fmtst1chk(wxT("%0*x"));
1793 fmtst2chk(wxT("%*.*x"));
1794 fmtst2chk(wxT("%0*.*x"));
1796 wxString bad_format
= wxT("bad format:\t\"%b\"\n");
1797 wxPrintf(bad_format
.c_str());
1798 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1800 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1801 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1802 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1803 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1804 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1805 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1806 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1807 test_format
= wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1808 wxPrintf(test_format
.c_str(), -123456);
1809 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1810 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1812 test_format
= wxT("zero-padded string:\t\"%010s\"\n");
1813 wxPrintf(test_format
.c_str(), shortstr
);
1814 test_format
= wxT("left-adjusted Z string:\t\"%-010s\"\n");
1815 wxPrintf(test_format
.c_str(), shortstr
);
1816 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr
);
1817 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1818 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull
);
1819 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr
);
1821 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1822 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1823 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1824 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20
);
1825 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1826 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1827 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1828 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1829 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1830 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1831 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1832 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20
);
1834 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1835 wxPrintf (wxT(" %6.5f\n"), .1);
1836 wxPrintf (wxT("x%5.4fx\n"), .5);
1838 wxPrintf (wxT("%#03x\n"), 1);
1840 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1846 while (niter
-- != 0)
1847 wxPrintf (wxT("%.17e\n"), d
/ 2);
1852 // Open Watcom cause compiler error here
1853 // Error! E173: col(24) floating-point constant too small to represent
1854 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1857 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1858 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1859 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1860 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1861 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1862 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1863 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1864 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1865 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1866 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1871 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), wxT("%30s"), wxT("foo"));
1873 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1874 rc
, WXSIZEOF(buf
), buf
);
1877 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1878 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1884 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1885 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1886 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1887 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1888 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1889 wxPrintf (wxT("%g should be 10\n"), 10.0);
1890 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1894 wxPrintf(wxT("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1900 wxSprintf(buf
,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1902 result
|= wxStrcmp (buf
,
1903 wxT("onetwo three "));
1905 wxPuts (result
!= 0 ?
wxT("Test failed!") : wxT("Test ok."));
1912 wxSprintf(buf
, "%07" wxLongLongFmtSpec
"o", wxLL(040000000000));
1914 // for some reason below line fails under Borland
1915 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1918 if (wxStrcmp (buf
, wxT("40000000000")) != 0)
1921 wxPuts (wxT("\tFAILED"));
1923 wxUnusedVar(result
);
1924 wxPuts (wxEmptyString
);
1926 #endif // wxLongLong_t
1928 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1929 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1931 wxPuts (wxT("--- Should be no further output. ---"));
1940 memset (bytes
, '\xff', sizeof bytes
);
1941 wxSprintf (buf
, wxT("foo%hhn\n"), &bytes
[3]);
1942 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1943 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1945 wxPuts (wxT("%hhn overwrite more bytes"));
1950 wxPuts (wxT("%hhn wrote incorrect value"));
1962 wxSprintf (buf
, wxT("%5.s"), wxT("xyz"));
1963 if (wxStrcmp (buf
, wxT(" ")) != 0)
1964 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" "));
1965 wxSprintf (buf
, wxT("%5.f"), 33.3);
1966 if (wxStrcmp (buf
, wxT(" 33")) != 0)
1967 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 33"));
1968 wxSprintf (buf
, wxT("%8.e"), 33.3e7
);
1969 if (wxStrcmp (buf
, wxT(" 3e+08")) != 0)
1970 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3e+08"));
1971 wxSprintf (buf
, wxT("%8.E"), 33.3e7
);
1972 if (wxStrcmp (buf
, wxT(" 3E+08")) != 0)
1973 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3E+08"));
1974 wxSprintf (buf
, wxT("%.g"), 33.3);
1975 if (wxStrcmp (buf
, wxT("3e+01")) != 0)
1976 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3e+01"));
1977 wxSprintf (buf
, wxT("%.G"), 33.3);
1978 if (wxStrcmp (buf
, wxT("3E+01")) != 0)
1979 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3E+01"));
1987 wxString test_format
;
1990 wxSprintf (buf
, wxT("%.*g"), prec
, 3.3);
1991 if (wxStrcmp (buf
, wxT("3")) != 0)
1992 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1994 wxSprintf (buf
, wxT("%.*G"), prec
, 3.3);
1995 if (wxStrcmp (buf
, wxT("3")) != 0)
1996 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1998 wxSprintf (buf
, wxT("%7.*G"), prec
, 3.33);
1999 if (wxStrcmp (buf
, wxT(" 3")) != 0)
2000 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3"));
2002 test_format
= wxT("%04.*o");
2003 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2004 if (wxStrcmp (buf
, wxT(" 041")) != 0)
2005 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 041"));
2007 test_format
= wxT("%09.*u");
2008 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2009 if (wxStrcmp (buf
, wxT(" 0000033")) != 0)
2010 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 0000033"));
2012 test_format
= wxT("%04.*x");
2013 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2014 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2015 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2017 test_format
= wxT("%04.*X");
2018 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2019 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2020 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2023 #endif // TEST_PRINTF
2025 // ----------------------------------------------------------------------------
2026 // registry and related stuff
2027 // ----------------------------------------------------------------------------
2029 // this is for MSW only
2032 #undef TEST_REGISTRY
2037 #include "wx/confbase.h"
2038 #include "wx/msw/regconf.h"
2041 static void TestRegConfWrite()
2043 wxConfig
*config
= new wxConfig(wxT("myapp"));
2044 config
->SetPath(wxT("/group1"));
2045 config
->Write(wxT("entry1"), wxT("foo"));
2046 config
->SetPath(wxT("/group2"));
2047 config
->Write(wxT("entry1"), wxT("bar"));
2051 static void TestRegConfRead()
2053 wxRegConfig
*config
= new wxRegConfig(wxT("myapp"));
2057 config
->SetPath(wxT("/"));
2058 wxPuts(wxT("Enumerating / subgroups:"));
2059 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2063 bCont
= config
->GetNextGroup(str
, dummy
);
2067 #endif // TEST_REGCONF
2069 #ifdef TEST_REGISTRY
2071 #include "wx/msw/registry.h"
2073 // I chose this one because I liked its name, but it probably only exists under
2075 static const wxChar
*TESTKEY
=
2076 wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2078 static void TestRegistryRead()
2080 wxPuts(wxT("*** testing registry reading ***"));
2082 wxRegKey
key(TESTKEY
);
2083 wxPrintf(wxT("The test key name is '%s'.\n"), key
.GetName().c_str());
2086 wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
2091 size_t nSubKeys
, nValues
;
2092 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2094 wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2097 wxPrintf(wxT("Enumerating values:\n"));
2101 bool cont
= key
.GetFirstValue(value
, dummy
);
2104 wxPrintf(wxT("Value '%s': type "), value
.c_str());
2105 switch ( key
.GetValueType(value
) )
2107 case wxRegKey
::Type_None
: wxPrintf(wxT("ERROR (none)")); break;
2108 case wxRegKey
::Type_String
: wxPrintf(wxT("SZ")); break;
2109 case wxRegKey
::Type_Expand_String
: wxPrintf(wxT("EXPAND_SZ")); break;
2110 case wxRegKey
::Type_Binary
: wxPrintf(wxT("BINARY")); break;
2111 case wxRegKey
::Type_Dword
: wxPrintf(wxT("DWORD")); break;
2112 case wxRegKey
::Type_Multi_String
: wxPrintf(wxT("MULTI_SZ")); break;
2113 default: wxPrintf(wxT("other (unknown)")); break;
2116 wxPrintf(wxT(", value = "));
2117 if ( key
.IsNumericValue(value
) )
2120 key
.QueryValue(value
, &val
);
2121 wxPrintf(wxT("%ld"), val
);
2126 key
.QueryValue(value
, val
);
2127 wxPrintf(wxT("'%s'"), val
.c_str());
2129 key
.QueryRawValue(value
, val
);
2130 wxPrintf(wxT(" (raw value '%s')"), val
.c_str());
2135 cont
= key
.GetNextValue(value
, dummy
);
2139 static void TestRegistryAssociation()
2142 The second call to deleteself genertaes an error message, with a
2143 messagebox saying .flo is crucial to system operation, while the .ddf
2144 call also fails, but with no error message
2149 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2151 key
= wxT("ddxf_auto_file") ;
2152 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2154 key
= wxT("ddxf_auto_file") ;
2155 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2157 key
= wxT("program,0") ;
2158 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2160 key
= wxT("program \"%1\"") ;
2162 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2164 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2166 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2168 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2172 #endif // TEST_REGISTRY
2174 // ----------------------------------------------------------------------------
2176 // ----------------------------------------------------------------------------
2178 #ifdef TEST_SCOPEGUARD
2180 #include "wx/scopeguard.h"
2182 static void function0() { puts("function0()"); }
2183 static void function1(int n
) { printf("function1(%d)\n", n
); }
2184 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2188 void method0() { printf("method0()\n"); }
2189 void method1(int n
) { printf("method1(%d)\n", n
); }
2190 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2193 static void TestScopeGuard()
2195 wxON_BLOCK_EXIT0(function0
);
2196 wxON_BLOCK_EXIT1(function1
, 17);
2197 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2200 wxON_BLOCK_EXIT_OBJ0(obj
, Object
::method0
);
2201 wxON_BLOCK_EXIT_OBJ1(obj
, Object
::method1
, 7);
2202 wxON_BLOCK_EXIT_OBJ2(obj
, Object
::method2
, 2.71, 'e');
2204 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2205 dismissed
.Dismiss();
2210 // ----------------------------------------------------------------------------
2212 // ----------------------------------------------------------------------------
2216 #include "wx/socket.h"
2217 #include "wx/protocol/protocol.h"
2218 #include "wx/protocol/http.h"
2220 static void TestSocketServer()
2222 wxPuts(wxT("*** Testing wxSocketServer ***\n"));
2224 static const int PORT
= 3000;
2229 wxSocketServer
*server
= new wxSocketServer(addr
);
2230 if ( !server
->Ok() )
2232 wxPuts(wxT("ERROR: failed to bind"));
2240 wxPrintf(wxT("Server: waiting for connection on port %d...\n"), PORT
);
2242 wxSocketBase
*socket
= server
->Accept();
2245 wxPuts(wxT("ERROR: wxSocketServer::Accept() failed."));
2249 wxPuts(wxT("Server: got a client."));
2251 server
->SetTimeout(60); // 1 min
2254 while ( !close
&& socket
->IsConnected() )
2257 wxChar ch
= wxT('\0');
2260 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2262 // don't log error if the client just close the connection
2263 if ( socket
->IsConnected() )
2265 wxPuts(wxT("ERROR: in wxSocket::Read."));
2285 wxPrintf(wxT("Server: got '%s'.\n"), s
.c_str());
2286 if ( s
== wxT("close") )
2288 wxPuts(wxT("Closing connection"));
2292 else if ( s
== wxT("quit") )
2297 wxPuts(wxT("Shutting down the server"));
2299 else // not a special command
2301 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2302 socket
->Write("\r\n", 2);
2303 wxPrintf(wxT("Server: wrote '%s'.\n"), s
.c_str());
2309 wxPuts(wxT("Server: lost a client unexpectedly."));
2315 // same as "delete server" but is consistent with GUI programs
2319 static void TestSocketClient()
2321 wxPuts(wxT("*** Testing wxSocketClient ***\n"));
2323 static const wxChar
*hostname
= wxT("www.wxwidgets.org");
2326 addr
.Hostname(hostname
);
2329 wxPrintf(wxT("--- Attempting to connect to %s:80...\n"), hostname
);
2331 wxSocketClient client
;
2332 if ( !client
.Connect(addr
) )
2334 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2338 wxPrintf(wxT("--- Connected to %s:%u...\n"),
2339 addr
.Hostname().c_str(), addr
.Service());
2343 // could use simply "GET" here I suppose
2345 wxString
::Format(wxT("GET http://%s/\r\n"), hostname
);
2346 client
.Write(cmdGet
, cmdGet
.length());
2347 wxPrintf(wxT("--- Sent command '%s' to the server\n"),
2348 MakePrintable(cmdGet
).c_str());
2349 client
.Read(buf
, WXSIZEOF(buf
));
2350 wxPrintf(wxT("--- Server replied:\n%s"), buf
);
2354 #endif // TEST_SOCKETS
2356 // ----------------------------------------------------------------------------
2358 // ----------------------------------------------------------------------------
2362 #include "wx/protocol/ftp.h"
2363 #include "wx/protocol/log.h"
2365 #define FTP_ANONYMOUS
2369 #ifdef FTP_ANONYMOUS
2370 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
2371 static const wxChar
*directory
= wxT("/pub");
2372 static const wxChar
*filename
= wxT("welcome.msg");
2374 static const wxChar
*hostname
= "localhost";
2375 static const wxChar
*directory
= wxT("/etc");
2376 static const wxChar
*filename
= wxT("issue");
2379 static bool TestFtpConnect()
2381 wxPuts(wxT("*** Testing FTP connect ***"));
2383 #ifdef FTP_ANONYMOUS
2384 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2385 #else // !FTP_ANONYMOUS
2387 wxFgets(user
, WXSIZEOF(user
), stdin
);
2388 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2391 wxChar password
[256];
2392 wxPrintf(wxT("Password for %s: "), password
);
2393 wxFgets(password
, WXSIZEOF(password
), stdin
);
2394 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2395 ftp
->SetPassword(password
);
2397 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2398 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2400 if ( !ftp
->Connect(hostname
) )
2402 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2408 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
2409 hostname
, ftp
->Pwd().c_str());
2416 static void TestFtpInteractive()
2418 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
2424 wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
2425 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2428 // kill the last '\n'
2429 buf
[wxStrlen(buf
) - 1] = 0;
2431 // special handling of LIST and NLST as they require data connection
2432 wxString
start(buf
, 4);
2434 if ( start
== wxT("LIST") || start
== wxT("NLST") )
2437 if ( wxStrlen(buf
) > 4 )
2440 wxArrayString files
;
2441 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
2443 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
2447 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2448 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2449 size_t count
= files
.GetCount();
2450 for ( size_t n
= 0; n
< count
; n
++ )
2452 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2454 wxPuts(wxT("--- End of the file list"));
2457 else if ( start
== wxT("QUIT") )
2459 break; // get out of here!
2463 wxChar ch
= ftp
->SendCommand(buf
);
2464 wxPrintf(wxT("Command %s"), ch ?
wxT("succeeded") : wxT("failed"));
2467 wxPrintf(wxT(" (return code %c)"), ch
);
2470 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2474 wxPuts(wxT("\n*** done ***"));
2479 // ----------------------------------------------------------------------------
2481 // ----------------------------------------------------------------------------
2483 #ifdef TEST_STACKWALKER
2485 #if wxUSE_STACKWALKER
2487 #include "wx/stackwalk.h"
2489 class StackDump
: public wxStackWalker
2492 StackDump(const char *argv0
)
2493 : wxStackWalker(argv0
)
2497 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
2499 wxPuts(wxT("Stack dump:"));
2501 wxStackWalker
::Walk(skip
, maxdepth
);
2505 virtual void OnStackFrame(const wxStackFrame
& frame
)
2507 printf("[%2d] ", (int) frame
.GetLevel());
2509 wxString name
= frame
.GetName();
2510 if ( !name
.empty() )
2512 printf("%-20.40s", (const char*)name
.mb_str());
2516 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2519 if ( frame
.HasSourceLocation() )
2522 (const char*)frame
.GetFileName().mb_str(),
2523 (int)frame
.GetLine());
2529 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2531 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2532 (const char*)name
.mb_str(),
2533 (const char*)val
.mb_str());
2538 static void TestStackWalk(const char *argv0
)
2540 wxPuts(wxT("*** Testing wxStackWalker ***\n"));
2542 StackDump
dump(argv0
);
2548 #endif // wxUSE_STACKWALKER
2550 #endif // TEST_STACKWALKER
2552 // ----------------------------------------------------------------------------
2554 // ----------------------------------------------------------------------------
2556 #ifdef TEST_STDPATHS
2558 #include "wx/stdpaths.h"
2559 #include "wx/wxchar.h" // wxPrintf
2561 static void TestStandardPaths()
2563 wxPuts(wxT("*** Testing wxStandardPaths ***\n"));
2565 wxTheApp
->SetAppName(wxT("console"));
2567 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
2568 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2569 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2570 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2571 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2572 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2573 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2574 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2575 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2576 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2577 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2578 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2579 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
2580 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2581 stdp
.GetLocalizedResourcesDir
2584 wxStandardPaths
::ResourceCat_Messages
2590 #endif // TEST_STDPATHS
2592 // ----------------------------------------------------------------------------
2594 // ----------------------------------------------------------------------------
2596 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2602 #include "wx/volume.h"
2604 static const wxChar
*volumeKinds
[] =
2610 wxT("network volume"),
2611 wxT("other volume"),
2614 static void TestFSVolume()
2616 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2618 wxArrayString volumes
= wxFSVolume
::GetVolumes();
2619 size_t count
= volumes
.GetCount();
2623 wxPuts(wxT("ERROR: no mounted volumes?"));
2627 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
2629 for ( size_t n
= 0; n
< count
; n
++ )
2631 wxFSVolume
vol(volumes
[n
]);
2634 wxPuts(wxT("ERROR: couldn't create volume"));
2638 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2640 vol
.GetDisplayName().c_str(),
2641 vol
.GetName().c_str(),
2642 volumeKinds
[vol
.GetKind()],
2643 vol
.IsWritable() ?
wxT("rw") : wxT("ro"),
2644 vol
.GetFlags() & wxFS_VOL_REMOVABLE ?
wxT("removable")
2651 #endif // TEST_VOLUME
2653 // ----------------------------------------------------------------------------
2655 // ----------------------------------------------------------------------------
2657 #ifdef TEST_DATETIME
2659 #include "wx/math.h"
2660 #include "wx/datetime.h"
2662 #if TEST_INTERACTIVE
2664 static void TestDateTimeInteractive()
2666 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
2672 wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
2673 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2676 // kill the last '\n'
2677 buf
[wxStrlen(buf
) - 1] = 0;
2679 if ( wxString(buf
).CmpNoCase("quit") == 0 )
2683 const wxChar
*p
= dt
.ParseDate(buf
);
2686 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
2692 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
2695 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
2696 dt
.Format(wxT("%b %d, %Y")).c_str(),
2698 dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
2699 dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
2700 dt
.GetWeekOfYear(wxDateTime
::Monday_First
));
2706 #endif // TEST_INTERACTIVE
2707 #endif // TEST_DATETIME
2709 // ----------------------------------------------------------------------------
2711 // ----------------------------------------------------------------------------
2713 #ifdef TEST_SNGLINST
2714 #include "wx/snglinst.h"
2715 #endif // TEST_SNGLINST
2717 int main(int argc
, char **argv
)
2720 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
2725 for (n
= 0; n
< argc
; n
++ )
2727 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
2728 wxArgv
[n
] = wxStrdup(warg
);
2733 #else // !wxUSE_UNICODE
2735 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2737 wxApp
::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
2739 wxInitializer initializer
;
2742 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
2747 #ifdef TEST_SNGLINST
2748 wxSingleInstanceChecker checker
;
2749 if ( checker
.Create(wxT(".wxconsole.lock")) )
2751 if ( checker
.IsAnotherRunning() )
2753 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
2758 // wait some time to give time to launch another instance
2759 wxPrintf(wxT("Press \"Enter\" to continue..."));
2762 else // failed to create
2764 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
2766 #endif // TEST_SNGLINST
2769 TestCmdLineConvert();
2771 #if wxUSE_CMDLINE_PARSER
2772 static const wxCmdLineEntryDesc cmdLineDesc
[] =
2774 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
2775 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
2776 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
2777 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
2779 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
2780 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
2781 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
2782 wxCMD_LINE_VAL_NUMBER
},
2783 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
2784 wxCMD_LINE_VAL_DATE
},
2785 { wxCMD_LINE_OPTION
, "f", "double", "output double",
2786 wxCMD_LINE_VAL_DOUBLE
},
2788 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
2789 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
2794 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
2796 parser
.AddOption(wxT("project_name"), wxT(""), wxT("full path to project file"),
2797 wxCMD_LINE_VAL_STRING
,
2798 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
2800 switch ( parser
.Parse() )
2803 wxLogMessage(wxT("Help was given, terminating."));
2807 ShowCmdLine(parser
);
2811 wxLogMessage(wxT("Syntax error detected, aborting."));
2814 #endif // wxUSE_CMDLINE_PARSER
2816 #endif // TEST_CMDLINE
2828 TestDllListLoaded();
2829 #endif // TEST_DYNLIB
2833 #endif // TEST_ENVIRON
2835 #ifdef TEST_FILECONF
2837 #endif // TEST_FILECONF
2841 #endif // TEST_LOCALE
2844 wxPuts(wxT("*** Testing wxLog ***"));
2847 for ( size_t n
= 0; n
< 8000; n
++ )
2849 s
<< (wxChar
)(wxT('A') + (n
% 26));
2852 wxLogWarning(wxT("The length of the string is %lu"),
2853 (unsigned long)s
.length());
2856 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
2858 // this one shouldn't be truncated
2861 // but this one will because log functions use fixed size buffer
2862 // (note that it doesn't need '\n' at the end neither - will be added
2864 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
2874 #ifdef TEST_FILENAME
2877 TestFileNameDirManip();
2878 TestFileNameComparison();
2879 TestFileNameOperations();
2880 #endif // TEST_FILENAME
2882 #ifdef TEST_FILETIME
2887 #endif // TEST_FILETIME
2890 wxLog
::AddTraceMask(FTP_TRACE_MASK
);
2892 // wxFTP cannot be a static variable as its ctor needs to access
2893 // wxWidgets internals after it has been initialized
2895 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
2897 if ( TestFtpConnect() )
2899 TestFtpInteractive();
2901 //else: connecting to the FTP server failed
2907 //wxLog::AddTraceMask(wxT("mime"));
2911 TestMimeAssociate();
2916 #ifdef TEST_INFO_FUNCTIONS
2921 #if TEST_INTERACTIVE
2924 #endif // TEST_INFO_FUNCTIONS
2926 #ifdef TEST_PATHLIST
2928 #endif // TEST_PATHLIST
2932 #endif // TEST_PRINTF
2939 #endif // TEST_REGCONF
2941 #if defined TEST_REGEX && TEST_INTERACTIVE
2942 TestRegExInteractive();
2943 #endif // defined TEST_REGEX && TEST_INTERACTIVE
2945 #ifdef TEST_REGISTRY
2947 TestRegistryAssociation();
2948 #endif // TEST_REGISTRY
2953 #endif // TEST_SOCKETS
2955 #ifdef TEST_DATETIME
2956 #if TEST_INTERACTIVE
2957 TestDateTimeInteractive();
2959 #endif // TEST_DATETIME
2961 #ifdef TEST_SCOPEGUARD
2965 #ifdef TEST_STACKWALKER
2966 #if wxUSE_STACKWALKER
2967 TestStackWalk(argv
[0]);
2969 #endif // TEST_STACKWALKER
2971 #ifdef TEST_STDPATHS
2972 TestStandardPaths();
2976 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
2978 #endif // TEST_USLEEP
2982 #endif // TEST_VOLUME
2986 for ( int n
= 0; n
< argc
; n
++ )
2991 #endif // wxUSE_UNICODE