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 #else // #if TEST_ALL
130 #define TEST_DATETIME
132 #define TEST_STDPATHS
133 #define TEST_STACKWALKER
137 // some tests are interactive, define this to run them
138 #ifdef TEST_INTERACTIVE
139 #undef TEST_INTERACTIVE
141 #define TEST_INTERACTIVE 1
143 #define TEST_INTERACTIVE 1
146 // ============================================================================
148 // ============================================================================
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
156 #include "wx/cmdline.h"
157 #include "wx/datetime.h"
159 #if wxUSE_CMDLINE_PARSER
161 static void ShowCmdLine(const wxCmdLineParser
& parser
)
163 wxString s
= wxT("Command line parsed successfully:\nInput files: ");
165 size_t count
= parser
.GetParamCount();
166 for ( size_t param
= 0; param
< count
; param
++ )
168 s
<< parser
.GetParam(param
) << ' ';
172 << wxT("Verbose:\t") << (parser
.Found(wxT("v")) ? wxT("yes") : wxT("no")) << '\n'
173 << wxT("Quiet:\t") << (parser
.Found(wxT("q")) ? wxT("yes") : wxT("no")) << '\n';
179 if ( parser
.Found(wxT("o"), &strVal
) )
180 s
<< wxT("Output file:\t") << strVal
<< '\n';
181 if ( parser
.Found(wxT("i"), &strVal
) )
182 s
<< wxT("Input dir:\t") << strVal
<< '\n';
183 if ( parser
.Found(wxT("s"), &lVal
) )
184 s
<< wxT("Size:\t") << lVal
<< '\n';
185 if ( parser
.Found(wxT("f"), &dVal
) )
186 s
<< wxT("Double:\t") << dVal
<< '\n';
187 if ( parser
.Found(wxT("d"), &dt
) )
188 s
<< wxT("Date:\t") << dt
.FormatISODate() << '\n';
189 if ( parser
.Found(wxT("project_name"), &strVal
) )
190 s
<< wxT("Project:\t") << strVal
<< '\n';
195 #endif // wxUSE_CMDLINE_PARSER
197 static void TestCmdLineConvert()
199 static const wxChar
*cmdlines
[] =
202 wxT("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
203 wxT("literal \\\" and \"\""),
206 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
208 const wxChar
*cmdline
= cmdlines
[n
];
209 wxPrintf(wxT("Parsing: %s\n"), cmdline
);
210 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
212 size_t count
= args
.GetCount();
213 wxPrintf(wxT("\targc = %u\n"), count
);
214 for ( size_t arg
= 0; arg
< count
; arg
++ )
216 wxPrintf(wxT("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
221 #endif // TEST_CMDLINE
223 // ----------------------------------------------------------------------------
225 // ----------------------------------------------------------------------------
232 static const wxChar
*ROOTDIR
= wxT("/");
233 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
234 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
235 static const wxChar
*ROOTDIR
= wxT("c:\\");
236 static const wxChar
*TESTDIR
= wxT("d:\\");
238 #error "don't know where the root directory is"
241 static void TestDirEnumHelper(wxDir
& dir
,
242 int flags
= wxDIR_DEFAULT
,
243 const wxString
& filespec
= wxEmptyString
)
247 if ( !dir
.IsOpened() )
250 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
253 wxPrintf(wxT("\t%s\n"), filename
.c_str());
255 cont
= dir
.GetNext(&filename
);
258 wxPuts(wxEmptyString
);
263 static void TestDirEnum()
265 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
267 wxString cwd
= wxGetCwd();
268 if ( !wxDir::Exists(cwd
) )
270 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
275 if ( !dir
.IsOpened() )
277 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
281 wxPuts(wxT("Enumerating everything in current directory:"));
282 TestDirEnumHelper(dir
);
284 wxPuts(wxT("Enumerating really everything in current directory:"));
285 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
287 wxPuts(wxT("Enumerating object files in current directory:"));
288 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
290 wxPuts(wxT("Enumerating directories in current directory:"));
291 TestDirEnumHelper(dir
, wxDIR_DIRS
);
293 wxPuts(wxT("Enumerating files in current directory:"));
294 TestDirEnumHelper(dir
, wxDIR_FILES
);
296 wxPuts(wxT("Enumerating files including hidden in current directory:"));
297 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
301 wxPuts(wxT("Enumerating everything in root directory:"));
302 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
304 wxPuts(wxT("Enumerating directories in root directory:"));
305 TestDirEnumHelper(dir
, wxDIR_DIRS
);
307 wxPuts(wxT("Enumerating files in root directory:"));
308 TestDirEnumHelper(dir
, wxDIR_FILES
);
310 wxPuts(wxT("Enumerating files including hidden in root directory:"));
311 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
313 wxPuts(wxT("Enumerating files in non existing directory:"));
314 wxDir
dirNo(wxT("nosuchdir"));
315 TestDirEnumHelper(dirNo
);
320 class DirPrintTraverser
: public wxDirTraverser
323 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
325 return wxDIR_CONTINUE
;
328 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
330 wxString path
, name
, ext
;
331 wxFileName::SplitPath(dirname
, &path
, &name
, &ext
);
334 name
<< wxT('.') << ext
;
337 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
339 if ( wxIsPathSeparator(*p
) )
343 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
345 return wxDIR_CONTINUE
;
349 static void TestDirTraverse()
351 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
355 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
356 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
359 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
360 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
363 // enum again with custom traverser
364 wxPuts(wxT("Now enumerating directories:"));
366 DirPrintTraverser traverser
;
367 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
372 static void TestDirExists()
374 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
376 static const wxChar
*dirnames
[] =
379 #if defined(__WXMSW__)
382 wxT("\\\\share\\file"),
386 wxT("c:\\autoexec.bat"),
387 #elif defined(__UNIX__)
396 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
398 wxPrintf(wxT("%-40s: %s\n"),
400 wxDir::Exists(dirnames
[n
]) ? wxT("exists")
401 : wxT("doesn't exist"));
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
415 #include "wx/dynlib.h"
417 static void TestDllLoad()
419 #if defined(__WXMSW__)
420 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
421 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
422 #elif defined(__UNIX__)
423 // weird: using just libc.so does *not* work!
424 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
425 static const wxChar
*FUNC_NAME
= wxT("strlen");
427 #error "don't know how to test wxDllLoader on this platform"
430 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
432 wxDynamicLibrary
lib(LIB_NAME
);
433 if ( !lib
.IsLoaded() )
435 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
439 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
440 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
443 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
444 FUNC_NAME
, LIB_NAME
);
448 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
449 FUNC_NAME
, LIB_NAME
);
451 if ( pfnStrlen("foo") != 3 )
453 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
457 wxPuts(wxT("... ok"));
462 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
464 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
466 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
467 if ( !pfnStrlenAorW
)
469 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
470 FUNC_NAME_AW
, LIB_NAME
);
474 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
476 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
483 #if defined(__WXMSW__) || defined(__UNIX__)
485 static void TestDllListLoaded()
487 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
489 puts("\nLoaded modules:");
490 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
491 const size_t count
= dlls
.GetCount();
492 for ( size_t n
= 0; n
< count
; ++n
)
494 const wxDynamicLibraryDetails
& details
= dlls
[n
];
495 printf("%-45s", (const char *)details
.GetPath().mb_str());
497 void *addr
wxDUMMY_INITIALIZE(NULL
);
498 size_t len
wxDUMMY_INITIALIZE(0);
499 if ( details
.GetAddress(&addr
, &len
) )
501 printf(" %08lx:%08lx",
502 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
505 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
511 #endif // TEST_DYNLIB
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
519 #include "wx/utils.h"
521 static wxString
MyGetEnv(const wxString
& var
)
524 if ( !wxGetEnv(var
, &val
) )
525 val
= wxT("<empty>");
527 val
= wxString(wxT('\'')) + val
+ wxT('\'');
532 static void TestEnvironment()
534 const wxChar
*var
= wxT("wxTestVar");
536 wxPuts(wxT("*** testing environment access functions ***"));
538 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
539 wxSetEnv(var
, wxT("value for wxTestVar"));
540 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
541 wxSetEnv(var
, wxT("another value"));
542 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
544 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
545 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
548 #endif // TEST_ENVIRON
550 // ----------------------------------------------------------------------------
552 // ----------------------------------------------------------------------------
557 #include "wx/ffile.h"
558 #include "wx/textfile.h"
560 static void TestFileRead()
562 wxPuts(wxT("*** wxFile read test ***"));
564 wxFile
file(wxT("testdata.fc"));
565 if ( file
.IsOpened() )
567 wxPrintf(wxT("File length: %lu\n"), file
.Length());
569 wxPuts(wxT("File dump:\n----------"));
571 static const size_t len
= 1024;
575 size_t nRead
= file
.Read(buf
, len
);
576 if ( nRead
== (size_t)wxInvalidOffset
)
578 wxPrintf(wxT("Failed to read the file."));
582 fwrite(buf
, nRead
, 1, stdout
);
588 wxPuts(wxT("----------"));
592 wxPrintf(wxT("ERROR: can't open test file.\n"));
595 wxPuts(wxEmptyString
);
598 static void TestTextFileRead()
600 wxPuts(wxT("*** wxTextFile read test ***"));
602 wxTextFile
file(wxT("testdata.fc"));
605 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
606 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
610 wxPuts(wxT("\nDumping the entire file:"));
611 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
613 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
615 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
617 wxPuts(wxT("\nAnd now backwards:"));
618 for ( s
= file
.GetLastLine();
619 file
.GetCurrentLine() != 0;
620 s
= file
.GetPrevLine() )
622 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
624 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
628 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
631 wxPuts(wxEmptyString
);
634 static void TestFileCopy()
636 wxPuts(wxT("*** Testing wxCopyFile ***"));
638 static const wxChar
*filename1
= wxT("testdata.fc");
639 static const wxChar
*filename2
= wxT("test2");
640 if ( !wxCopyFile(filename1
, filename2
) )
642 wxPuts(wxT("ERROR: failed to copy file"));
646 wxFFile
f1(filename1
, wxT("rb")),
647 f2(filename2
, wxT("rb"));
649 if ( !f1
.IsOpened() || !f2
.IsOpened() )
651 wxPuts(wxT("ERROR: failed to open file(s)"));
656 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
658 wxPuts(wxT("ERROR: failed to read file(s)"));
662 if ( (s1
.length() != s2
.length()) ||
663 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
665 wxPuts(wxT("ERROR: copy error!"));
669 wxPuts(wxT("File was copied ok."));
675 if ( !wxRemoveFile(filename2
) )
677 wxPuts(wxT("ERROR: failed to remove the file"));
680 wxPuts(wxEmptyString
);
683 static void TestTempFile()
685 wxPuts(wxT("*** wxTempFile test ***"));
688 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
690 if ( tmpFile
.Commit() )
691 wxPuts(wxT("File committed."));
693 wxPuts(wxT("ERROR: could't commit temp file."));
695 wxRemoveFile(wxT("test2"));
698 wxPuts(wxEmptyString
);
703 // ----------------------------------------------------------------------------
705 // ----------------------------------------------------------------------------
709 #include "wx/confbase.h"
710 #include "wx/fileconf.h"
712 static const struct FileConfTestData
714 const wxChar
*name
; // value name
715 const wxChar
*value
; // the value from the file
718 { wxT("value1"), wxT("one") },
719 { wxT("value2"), wxT("two") },
720 { wxT("novalue"), wxT("default") },
723 static void TestFileConfRead()
725 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
727 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
728 wxT("testdata.fc"), wxEmptyString
,
729 wxCONFIG_USE_RELATIVE_PATH
);
731 // test simple reading
732 wxPuts(wxT("\nReading config file:"));
733 wxString
defValue(wxT("default")), value
;
734 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
736 const FileConfTestData
& data
= fcTestData
[n
];
737 value
= fileconf
.Read(data
.name
, defValue
);
738 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
739 if ( value
== data
.value
)
745 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
749 // test enumerating the entries
750 wxPuts(wxT("\nEnumerating all root entries:"));
753 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
756 wxPrintf(wxT("\t%s = %s\n"),
758 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
760 cont
= fileconf
.GetNextEntry(name
, dummy
);
763 static const wxChar
*testEntry
= wxT("TestEntry");
764 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
765 fileconf
.Write(testEntry
, wxT("A value"));
766 fileconf
.DeleteEntry(testEntry
);
767 wxPrintf(fileconf
.HasEntry(testEntry
) ? wxT("ERROR\n") : wxT("ok\n"));
770 #endif // TEST_FILECONF
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
778 #include "wx/filename.h"
781 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
785 wxString full
= fn
.GetFullPath();
787 wxString vol
, path
, name
, ext
;
788 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
790 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
791 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
793 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
794 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
795 path
.c_str(), name
.c_str(), ext
.c_str());
797 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
798 wxPrintf(wxT("with volume: \t'%s'\n"),
799 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
800 wxPrintf(wxT("with separator:\t'%s'\n"),
801 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
802 wxPrintf(wxT("with both: \t'%s'\n"),
803 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
805 wxPuts(wxT("The directories in the path are:"));
806 wxArrayString dirs
= fn
.GetDirs();
807 size_t count
= dirs
.GetCount();
808 for ( size_t n
= 0; n
< count
; n
++ )
810 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
815 static void TestFileNameTemp()
817 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
819 static const wxChar
*tmpprefixes
[] =
827 wxT("/tmp/foo/bar"), // this one must be an error
831 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
833 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
836 // "error" is not in upper case because it may be ok
837 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
841 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
842 tmpprefixes
[n
], path
.c_str());
844 if ( !wxRemoveFile(path
) )
846 wxLogWarning(wxT("Failed to remove temp file '%s'"),
853 static void TestFileNameDirManip()
855 // TODO: test AppendDir(), RemoveDir(), ...
858 static void TestFileNameComparison()
863 static void TestFileNameOperations()
868 static void TestFileNameCwd()
873 #endif // TEST_FILENAME
875 // ----------------------------------------------------------------------------
876 // wxFileName time functions
877 // ----------------------------------------------------------------------------
881 #include "wx/filename.h"
882 #include "wx/datetime.h"
884 static void TestFileGetTimes()
886 wxFileName
fn(wxT("testdata.fc"));
888 wxDateTime dtAccess
, dtMod
, dtCreate
;
889 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
891 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
895 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
897 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
898 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
899 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
900 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
905 static void TestFileSetTimes()
907 wxFileName
fn(wxT("testdata.fc"));
911 wxPrintf(wxT("ERROR: Touch() failed.\n"));
916 #endif // TEST_FILETIME
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
925 #include "wx/utils.h" // for wxSetEnv
927 static wxLocale gs_localeDefault
;
928 // NOTE: don't init it here as it needs a wxAppTraits object
929 // and thus must be init-ed after creation of the wxInitializer
930 // class in the main()
932 // find the name of the language from its value
933 static const wxChar
*GetLangName(int lang
)
935 static const wxChar
*languageNames
[] =
945 wxT("ARABIC_ALGERIA"),
946 wxT("ARABIC_BAHRAIN"),
949 wxT("ARABIC_JORDAN"),
950 wxT("ARABIC_KUWAIT"),
951 wxT("ARABIC_LEBANON"),
953 wxT("ARABIC_MOROCCO"),
956 wxT("ARABIC_SAUDI_ARABIA"),
959 wxT("ARABIC_TUNISIA"),
966 wxT("AZERI_CYRILLIC"),
981 wxT("CHINESE_SIMPLIFIED"),
982 wxT("CHINESE_TRADITIONAL"),
983 wxT("CHINESE_HONGKONG"),
984 wxT("CHINESE_MACAU"),
985 wxT("CHINESE_SINGAPORE"),
986 wxT("CHINESE_TAIWAN"),
992 wxT("DUTCH_BELGIAN"),
996 wxT("ENGLISH_AUSTRALIA"),
997 wxT("ENGLISH_BELIZE"),
998 wxT("ENGLISH_BOTSWANA"),
999 wxT("ENGLISH_CANADA"),
1000 wxT("ENGLISH_CARIBBEAN"),
1001 wxT("ENGLISH_DENMARK"),
1002 wxT("ENGLISH_EIRE"),
1003 wxT("ENGLISH_JAMAICA"),
1004 wxT("ENGLISH_NEW_ZEALAND"),
1005 wxT("ENGLISH_PHILIPPINES"),
1006 wxT("ENGLISH_SOUTH_AFRICA"),
1007 wxT("ENGLISH_TRINIDAD"),
1008 wxT("ENGLISH_ZIMBABWE"),
1016 wxT("FRENCH_BELGIAN"),
1017 wxT("FRENCH_CANADIAN"),
1018 wxT("FRENCH_LUXEMBOURG"),
1019 wxT("FRENCH_MONACO"),
1020 wxT("FRENCH_SWISS"),
1025 wxT("GERMAN_AUSTRIAN"),
1026 wxT("GERMAN_BELGIUM"),
1027 wxT("GERMAN_LIECHTENSTEIN"),
1028 wxT("GERMAN_LUXEMBOURG"),
1029 wxT("GERMAN_SWISS"),
1046 wxT("ITALIAN_SWISS"),
1051 wxT("KASHMIRI_INDIA"),
1069 wxT("MALAY_BRUNEI_DARUSSALAM"),
1070 wxT("MALAY_MALAYSIA"),
1079 wxT("NEPALI_INDIA"),
1080 wxT("NORWEGIAN_BOKMAL"),
1081 wxT("NORWEGIAN_NYNORSK"),
1088 wxT("PORTUGUESE_BRAZILIAN"),
1091 wxT("RHAETO_ROMANCE"),
1094 wxT("RUSSIAN_UKRAINE"),
1098 wxT("SCOTS_GAELIC"),
1100 wxT("SERBIAN_CYRILLIC"),
1101 wxT("SERBIAN_LATIN"),
1102 wxT("SERBO_CROATIAN"),
1113 wxT("SPANISH_ARGENTINA"),
1114 wxT("SPANISH_BOLIVIA"),
1115 wxT("SPANISH_CHILE"),
1116 wxT("SPANISH_COLOMBIA"),
1117 wxT("SPANISH_COSTA_RICA"),
1118 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1119 wxT("SPANISH_ECUADOR"),
1120 wxT("SPANISH_EL_SALVADOR"),
1121 wxT("SPANISH_GUATEMALA"),
1122 wxT("SPANISH_HONDURAS"),
1123 wxT("SPANISH_MEXICAN"),
1124 wxT("SPANISH_MODERN"),
1125 wxT("SPANISH_NICARAGUA"),
1126 wxT("SPANISH_PANAMA"),
1127 wxT("SPANISH_PARAGUAY"),
1128 wxT("SPANISH_PERU"),
1129 wxT("SPANISH_PUERTO_RICO"),
1130 wxT("SPANISH_URUGUAY"),
1132 wxT("SPANISH_VENEZUELA"),
1136 wxT("SWEDISH_FINLAND"),
1154 wxT("URDU_PAKISTAN"),
1156 wxT("UZBEK_CYRILLIC"),
1169 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1170 return languageNames
[lang
];
1172 return wxT("INVALID");
1175 static void TestDefaultLang()
1177 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1179 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1181 static const wxChar
*langStrings
[] =
1183 NULL
, // system default
1190 wxT("de_DE.iso88591"),
1192 wxT("?"), // invalid lang spec
1193 wxT("klingonese"), // I bet on some systems it does exist...
1196 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1197 wxLocale::GetSystemEncodingName().c_str(),
1198 wxLocale::GetSystemEncoding());
1200 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1202 const wxChar
*langStr
= langStrings
[n
];
1205 // FIXME: this doesn't do anything at all under Windows, we need
1206 // to create a new wxLocale!
1207 wxSetEnv(wxT("LC_ALL"), langStr
);
1210 int lang
= gs_localeDefault
.GetSystemLanguage();
1211 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1212 langStr
? langStr
: wxT("system default"), GetLangName(lang
));
1216 #endif // TEST_LOCALE
1218 // ----------------------------------------------------------------------------
1220 // ----------------------------------------------------------------------------
1224 #include "wx/mimetype.h"
1226 static void TestMimeEnum()
1228 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1230 wxArrayString mimetypes
;
1232 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1234 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1239 for ( size_t n
= 0; n
< count
; n
++ )
1241 wxFileType
*filetype
=
1242 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1245 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1246 mimetypes
[n
].c_str());
1250 filetype
->GetDescription(&desc
);
1251 filetype
->GetExtensions(exts
);
1253 filetype
->GetIcon(NULL
);
1256 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1259 extsAll
<< wxT(", ");
1263 wxPrintf(wxT("\t%s: %s (%s)\n"),
1264 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1267 wxPuts(wxEmptyString
);
1270 static void TestMimeFilename()
1272 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1274 static const wxChar
*filenames
[] =
1277 wxT("document.pdf"),
1279 wxT("picture.jpeg"),
1282 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1284 const wxString fname
= filenames
[n
];
1285 wxString ext
= fname
.AfterLast(wxT('.'));
1286 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1289 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1294 if ( !ft
->GetDescription(&desc
) )
1295 desc
= wxT("<no description>");
1298 if ( !ft
->GetOpenCommand(&cmd
,
1299 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1300 cmd
= wxT("<no command available>");
1302 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1304 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1305 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1311 wxPuts(wxEmptyString
);
1314 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1317 static void TestMimeOverride()
1319 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1321 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1322 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1324 if ( wxFile::Exists(mailcap
) )
1325 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1327 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? wxT("ok") : wxT("ERROR"));
1329 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1332 if ( wxFile::Exists(mimetypes
) )
1333 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1335 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? wxT("ok") : wxT("ERROR"));
1337 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1340 wxPuts(wxEmptyString
);
1343 static void TestMimeAssociate()
1345 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1347 wxFileTypeInfo
ftInfo(
1348 wxT("application/x-xyz"),
1349 wxT("xyzview '%s'"), // open cmd
1350 wxT(""), // print cmd
1351 wxT("XYZ File"), // description
1352 wxT(".xyz"), // extensions
1353 wxNullPtr
// end of extensions
1355 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1357 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1360 wxPuts(wxT("ERROR: failed to create association!"));
1364 // TODO: read it back
1368 wxPuts(wxEmptyString
);
1375 // ----------------------------------------------------------------------------
1376 // module dependencies feature
1377 // ----------------------------------------------------------------------------
1381 #include "wx/module.h"
1383 class wxTestModule
: public wxModule
1386 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1387 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1390 class wxTestModuleA
: public wxTestModule
1395 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1398 class wxTestModuleB
: public wxTestModule
1403 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1406 class wxTestModuleC
: public wxTestModule
1411 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1414 class wxTestModuleD
: public wxTestModule
1419 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1422 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1423 wxTestModuleC::wxTestModuleC()
1425 AddDependency(CLASSINFO(wxTestModuleD
));
1428 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1429 wxTestModuleA::wxTestModuleA()
1431 AddDependency(CLASSINFO(wxTestModuleB
));
1432 AddDependency(CLASSINFO(wxTestModuleD
));
1435 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1436 wxTestModuleD::wxTestModuleD()
1440 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1441 wxTestModuleB::wxTestModuleB()
1443 AddDependency(CLASSINFO(wxTestModuleD
));
1444 AddDependency(CLASSINFO(wxTestModuleC
));
1447 #endif // TEST_MODULE
1449 // ----------------------------------------------------------------------------
1450 // misc information functions
1451 // ----------------------------------------------------------------------------
1453 #ifdef TEST_INFO_FUNCTIONS
1455 #include "wx/utils.h"
1457 #if TEST_INTERACTIVE
1458 static void TestDiskInfo()
1460 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1464 wxChar pathname
[128];
1465 wxPrintf(wxT("\nEnter a directory name: "));
1466 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1469 // kill the last '\n'
1470 pathname
[wxStrlen(pathname
) - 1] = 0;
1472 wxLongLong total
, free
;
1473 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1475 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1479 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1480 (total
/ 1024).ToString().c_str(),
1481 (free
/ 1024).ToString().c_str(),
1486 #endif // TEST_INTERACTIVE
1488 static void TestOsInfo()
1490 wxPuts(wxT("*** Testing OS info functions ***\n"));
1493 wxGetOsVersion(&major
, &minor
);
1494 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1495 wxGetOsDescription().c_str(), major
, minor
);
1497 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1499 wxPrintf(wxT("Host name is %s (%s).\n"),
1500 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1502 wxPuts(wxEmptyString
);
1505 static void TestPlatformInfo()
1507 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1509 // get this platform
1510 wxPlatformInfo plat
;
1512 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1513 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1514 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1515 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1516 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1517 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1519 wxPuts(wxEmptyString
);
1522 static void TestUserInfo()
1524 wxPuts(wxT("*** Testing user info functions ***\n"));
1526 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1527 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1528 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1529 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1531 wxPuts(wxEmptyString
);
1534 #endif // TEST_INFO_FUNCTIONS
1536 // ----------------------------------------------------------------------------
1538 // ----------------------------------------------------------------------------
1540 #ifdef TEST_PATHLIST
1543 #define CMD_IN_PATH wxT("ls")
1545 #define CMD_IN_PATH wxT("command.com")
1548 static void TestPathList()
1550 wxPuts(wxT("*** Testing wxPathList ***\n"));
1552 wxPathList pathlist
;
1553 pathlist
.AddEnvList(wxT("PATH"));
1554 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1557 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1561 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1565 #endif // TEST_PATHLIST
1567 // ----------------------------------------------------------------------------
1568 // regular expressions
1569 // ----------------------------------------------------------------------------
1571 #if defined TEST_REGEX && TEST_INTERACTIVE
1573 #include "wx/regex.h"
1575 static void TestRegExInteractive()
1577 wxPuts(wxT("*** Testing RE interactively ***"));
1581 wxChar pattern
[128];
1582 wxPrintf(wxT("\nEnter a pattern: "));
1583 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1586 // kill the last '\n'
1587 pattern
[wxStrlen(pattern
) - 1] = 0;
1590 if ( !re
.Compile(pattern
) )
1598 wxPrintf(wxT("Enter text to match: "));
1599 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1602 // kill the last '\n'
1603 text
[wxStrlen(text
) - 1] = 0;
1605 if ( !re
.Matches(text
) )
1607 wxPrintf(wxT("No match.\n"));
1611 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1614 for ( size_t n
= 1; ; n
++ )
1616 if ( !re
.GetMatch(&start
, &len
, n
) )
1621 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1622 n
, wxString(text
+ start
, len
).c_str());
1629 #endif // TEST_REGEX
1631 // ----------------------------------------------------------------------------
1633 // ----------------------------------------------------------------------------
1636 NB: this stuff was taken from the glibc test suite and modified to build
1637 in wxWidgets: if I read the copyright below properly, this shouldn't
1643 #ifdef wxTEST_PRINTF
1644 // use our functions from wxchar.cpp
1648 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1649 // in the tests below
1650 int wxPrintf( const wxChar
*format
, ... );
1651 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1654 #include "wx/longlong.h"
1658 static void rfg1 (void);
1659 static void rfg2 (void);
1663 fmtchk (const wxChar
*fmt
)
1665 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1666 (void) wxPrintf(fmt
, 0x12);
1667 (void) wxPrintf(wxT("'\n"));
1671 fmtst1chk (const wxChar
*fmt
)
1673 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1674 (void) wxPrintf(fmt
, 4, 0x12);
1675 (void) wxPrintf(wxT("'\n"));
1679 fmtst2chk (const wxChar
*fmt
)
1681 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1682 (void) wxPrintf(fmt
, 4, 4, 0x12);
1683 (void) wxPrintf(wxT("'\n"));
1686 /* This page is covered by the following copyright: */
1688 /* (C) Copyright C E Chew
1690 * Feel free to copy, use and distribute this software provided:
1692 * 1. you do not pretend that you wrote it
1693 * 2. you leave this copyright notice intact.
1697 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1704 /* Formatted Output Test
1706 * This exercises the output formatting code.
1709 wxChar
*PointerNull
= NULL
;
1716 wxChar
*prefix
= buf
;
1719 wxPuts(wxT("\nFormatted output test"));
1720 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1721 wxStrcpy(prefix
, wxT("%"));
1722 for (i
= 0; i
< 2; i
++) {
1723 for (j
= 0; j
< 2; j
++) {
1724 for (k
= 0; k
< 2; k
++) {
1725 for (l
= 0; l
< 2; l
++) {
1726 wxStrcpy(prefix
, wxT("%"));
1727 if (i
== 0) wxStrcat(prefix
, wxT("-"));
1728 if (j
== 0) wxStrcat(prefix
, wxT("+"));
1729 if (k
== 0) wxStrcat(prefix
, wxT("#"));
1730 if (l
== 0) wxStrcat(prefix
, wxT("0"));
1731 wxPrintf(wxT("%5s |"), prefix
);
1732 wxStrcpy(tp
, prefix
);
1733 wxStrcat(tp
, wxT("6d |"));
1735 wxStrcpy(tp
, prefix
);
1736 wxStrcat(tp
, wxT("6o |"));
1738 wxStrcpy(tp
, prefix
);
1739 wxStrcat(tp
, wxT("6x |"));
1741 wxStrcpy(tp
, prefix
);
1742 wxStrcat(tp
, wxT("6X |"));
1744 wxStrcpy(tp
, prefix
);
1745 wxStrcat(tp
, wxT("6u |"));
1747 wxPrintf(wxT("\n"));
1752 wxPrintf(wxT("%10s\n"), PointerNull
);
1753 wxPrintf(wxT("%-10s\n"), PointerNull
);
1756 static void TestPrintf()
1758 static wxChar shortstr
[] = wxT("Hi, Z.");
1759 static wxChar longstr
[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1760 I am ready for my first lesson today.");
1762 wxString test_format
;
1764 fmtchk(wxT("%.4x"));
1765 fmtchk(wxT("%04x"));
1766 fmtchk(wxT("%4.4x"));
1767 fmtchk(wxT("%04.4x"));
1768 fmtchk(wxT("%4.3x"));
1769 fmtchk(wxT("%04.3x"));
1771 fmtst1chk(wxT("%.*x"));
1772 fmtst1chk(wxT("%0*x"));
1773 fmtst2chk(wxT("%*.*x"));
1774 fmtst2chk(wxT("%0*.*x"));
1776 wxString bad_format
= wxT("bad format:\t\"%b\"\n");
1777 wxPrintf(bad_format
.c_str());
1778 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1780 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1781 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1782 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1783 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1784 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1785 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1786 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1787 test_format
= wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1788 wxPrintf(test_format
.c_str(), -123456);
1789 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1790 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1792 test_format
= wxT("zero-padded string:\t\"%010s\"\n");
1793 wxPrintf(test_format
.c_str(), shortstr
);
1794 test_format
= wxT("left-adjusted Z string:\t\"%-010s\"\n");
1795 wxPrintf(test_format
.c_str(), shortstr
);
1796 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr
);
1797 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1798 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull
);
1799 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr
);
1801 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1802 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1803 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1804 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20
);
1805 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1806 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1807 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1808 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1809 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1810 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1811 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1812 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20
);
1814 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1815 wxPrintf (wxT(" %6.5f\n"), .1);
1816 wxPrintf (wxT("x%5.4fx\n"), .5);
1818 wxPrintf (wxT("%#03x\n"), 1);
1820 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1826 while (niter
-- != 0)
1827 wxPrintf (wxT("%.17e\n"), d
/ 2);
1832 // Open Watcom cause compiler error here
1833 // Error! E173: col(24) floating-point constant too small to represent
1834 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1837 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1838 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1839 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1840 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1841 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1842 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1843 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1844 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1845 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1846 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1851 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), wxT("%30s"), wxT("foo"));
1853 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1854 rc
, WXSIZEOF(buf
), buf
);
1857 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1858 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1864 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1865 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1866 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1867 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1868 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1869 wxPrintf (wxT("%g should be 10\n"), 10.0);
1870 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1874 wxPrintf(wxT("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1880 wxSprintf(buf
,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1882 result
|= wxStrcmp (buf
,
1883 wxT("onetwo three "));
1885 wxPuts (result
!= 0 ? wxT("Test failed!") : wxT("Test ok."));
1892 wxSprintf(buf
, "%07" wxLongLongFmtSpec
"o", wxLL(040000000000));
1894 // for some reason below line fails under Borland
1895 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1898 if (wxStrcmp (buf
, wxT("40000000000")) != 0)
1901 wxPuts (wxT("\tFAILED"));
1903 wxUnusedVar(result
);
1904 wxPuts (wxEmptyString
);
1906 #endif // wxLongLong_t
1908 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1909 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1911 wxPuts (wxT("--- Should be no further output. ---"));
1920 memset (bytes
, '\xff', sizeof bytes
);
1921 wxSprintf (buf
, wxT("foo%hhn\n"), &bytes
[3]);
1922 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1923 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1925 wxPuts (wxT("%hhn overwrite more bytes"));
1930 wxPuts (wxT("%hhn wrote incorrect value"));
1942 wxSprintf (buf
, wxT("%5.s"), wxT("xyz"));
1943 if (wxStrcmp (buf
, wxT(" ")) != 0)
1944 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" "));
1945 wxSprintf (buf
, wxT("%5.f"), 33.3);
1946 if (wxStrcmp (buf
, wxT(" 33")) != 0)
1947 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 33"));
1948 wxSprintf (buf
, wxT("%8.e"), 33.3e7
);
1949 if (wxStrcmp (buf
, wxT(" 3e+08")) != 0)
1950 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3e+08"));
1951 wxSprintf (buf
, wxT("%8.E"), 33.3e7
);
1952 if (wxStrcmp (buf
, wxT(" 3E+08")) != 0)
1953 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3E+08"));
1954 wxSprintf (buf
, wxT("%.g"), 33.3);
1955 if (wxStrcmp (buf
, wxT("3e+01")) != 0)
1956 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3e+01"));
1957 wxSprintf (buf
, wxT("%.G"), 33.3);
1958 if (wxStrcmp (buf
, wxT("3E+01")) != 0)
1959 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3E+01"));
1967 wxString test_format
;
1970 wxSprintf (buf
, wxT("%.*g"), prec
, 3.3);
1971 if (wxStrcmp (buf
, wxT("3")) != 0)
1972 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1974 wxSprintf (buf
, wxT("%.*G"), prec
, 3.3);
1975 if (wxStrcmp (buf
, wxT("3")) != 0)
1976 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
1978 wxSprintf (buf
, wxT("%7.*G"), prec
, 3.33);
1979 if (wxStrcmp (buf
, wxT(" 3")) != 0)
1980 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3"));
1982 test_format
= wxT("%04.*o");
1983 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1984 if (wxStrcmp (buf
, wxT(" 041")) != 0)
1985 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 041"));
1987 test_format
= wxT("%09.*u");
1988 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1989 if (wxStrcmp (buf
, wxT(" 0000033")) != 0)
1990 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 0000033"));
1992 test_format
= wxT("%04.*x");
1993 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1994 if (wxStrcmp (buf
, wxT(" 021")) != 0)
1995 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
1997 test_format
= wxT("%04.*X");
1998 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
1999 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2000 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2003 #endif // TEST_PRINTF
2005 // ----------------------------------------------------------------------------
2006 // registry and related stuff
2007 // ----------------------------------------------------------------------------
2009 // this is for MSW only
2012 #undef TEST_REGISTRY
2017 #include "wx/confbase.h"
2018 #include "wx/msw/regconf.h"
2021 static void TestRegConfWrite()
2023 wxConfig
*config
= new wxConfig(wxT("myapp"));
2024 config
->SetPath(wxT("/group1"));
2025 config
->Write(wxT("entry1"), wxT("foo"));
2026 config
->SetPath(wxT("/group2"));
2027 config
->Write(wxT("entry1"), wxT("bar"));
2031 static void TestRegConfRead()
2033 wxRegConfig
*config
= new wxRegConfig(wxT("myapp"));
2037 config
->SetPath(wxT("/"));
2038 wxPuts(wxT("Enumerating / subgroups:"));
2039 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2043 bCont
= config
->GetNextGroup(str
, dummy
);
2047 #endif // TEST_REGCONF
2049 #ifdef TEST_REGISTRY
2051 #include "wx/msw/registry.h"
2053 // I chose this one because I liked its name, but it probably only exists under
2055 static const wxChar
*TESTKEY
=
2056 wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2058 static void TestRegistryRead()
2060 wxPuts(wxT("*** testing registry reading ***"));
2062 wxRegKey
key(TESTKEY
);
2063 wxPrintf(wxT("The test key name is '%s'.\n"), key
.GetName().c_str());
2066 wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
2071 size_t nSubKeys
, nValues
;
2072 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2074 wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2077 wxPrintf(wxT("Enumerating values:\n"));
2081 bool cont
= key
.GetFirstValue(value
, dummy
);
2084 wxPrintf(wxT("Value '%s': type "), value
.c_str());
2085 switch ( key
.GetValueType(value
) )
2087 case wxRegKey::Type_None
: wxPrintf(wxT("ERROR (none)")); break;
2088 case wxRegKey::Type_String
: wxPrintf(wxT("SZ")); break;
2089 case wxRegKey::Type_Expand_String
: wxPrintf(wxT("EXPAND_SZ")); break;
2090 case wxRegKey::Type_Binary
: wxPrintf(wxT("BINARY")); break;
2091 case wxRegKey::Type_Dword
: wxPrintf(wxT("DWORD")); break;
2092 case wxRegKey::Type_Multi_String
: wxPrintf(wxT("MULTI_SZ")); break;
2093 default: wxPrintf(wxT("other (unknown)")); break;
2096 wxPrintf(wxT(", value = "));
2097 if ( key
.IsNumericValue(value
) )
2100 key
.QueryValue(value
, &val
);
2101 wxPrintf(wxT("%ld"), val
);
2106 key
.QueryValue(value
, val
);
2107 wxPrintf(wxT("'%s'"), val
.c_str());
2109 key
.QueryRawValue(value
, val
);
2110 wxPrintf(wxT(" (raw value '%s')"), val
.c_str());
2115 cont
= key
.GetNextValue(value
, dummy
);
2119 static void TestRegistryAssociation()
2122 The second call to deleteself genertaes an error message, with a
2123 messagebox saying .flo is crucial to system operation, while the .ddf
2124 call also fails, but with no error message
2129 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2131 key
= wxT("ddxf_auto_file") ;
2132 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2134 key
= wxT("ddxf_auto_file") ;
2135 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2137 key
= wxT("program,0") ;
2138 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2140 key
= wxT("program \"%1\"") ;
2142 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2144 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2146 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2148 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2152 #endif // TEST_REGISTRY
2154 // ----------------------------------------------------------------------------
2156 // ----------------------------------------------------------------------------
2158 #ifdef TEST_SCOPEGUARD
2160 #include "wx/scopeguard.h"
2162 static void function0() { puts("function0()"); }
2163 static void function1(int n
) { printf("function1(%d)\n", n
); }
2164 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2168 void method0() { printf("method0()\n"); }
2169 void method1(int n
) { printf("method1(%d)\n", n
); }
2170 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2173 static void TestScopeGuard()
2175 wxON_BLOCK_EXIT0(function0
);
2176 wxON_BLOCK_EXIT1(function1
, 17);
2177 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2180 wxON_BLOCK_EXIT_OBJ0(obj
, Object::method0
);
2181 wxON_BLOCK_EXIT_OBJ1(obj
, Object::method1
, 7);
2182 wxON_BLOCK_EXIT_OBJ2(obj
, Object::method2
, 2.71, 'e');
2184 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2185 dismissed
.Dismiss();
2190 // ----------------------------------------------------------------------------
2192 // ----------------------------------------------------------------------------
2196 #include "wx/protocol/ftp.h"
2197 #include "wx/protocol/log.h"
2199 #define FTP_ANONYMOUS
2203 #ifdef FTP_ANONYMOUS
2204 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
2205 static const wxChar
*directory
= wxT("/pub");
2206 static const wxChar
*filename
= wxT("welcome.msg");
2208 static const wxChar
*hostname
= "localhost";
2209 static const wxChar
*directory
= wxT("/etc");
2210 static const wxChar
*filename
= wxT("issue");
2213 static bool TestFtpConnect()
2215 wxPuts(wxT("*** Testing FTP connect ***"));
2217 #ifdef FTP_ANONYMOUS
2218 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2219 #else // !FTP_ANONYMOUS
2221 wxFgets(user
, WXSIZEOF(user
), stdin
);
2222 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2225 wxChar password
[256];
2226 wxPrintf(wxT("Password for %s: "), password
);
2227 wxFgets(password
, WXSIZEOF(password
), stdin
);
2228 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2229 ftp
->SetPassword(password
);
2231 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2232 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2234 if ( !ftp
->Connect(hostname
) )
2236 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2242 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
2243 hostname
, ftp
->Pwd().c_str());
2250 static void TestFtpInteractive()
2252 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
2258 wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
2259 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2262 // kill the last '\n'
2263 buf
[wxStrlen(buf
) - 1] = 0;
2265 // special handling of LIST and NLST as they require data connection
2266 wxString
start(buf
, 4);
2268 if ( start
== wxT("LIST") || start
== wxT("NLST") )
2271 if ( wxStrlen(buf
) > 4 )
2274 wxArrayString files
;
2275 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
2277 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
2281 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2282 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2283 size_t count
= files
.GetCount();
2284 for ( size_t n
= 0; n
< count
; n
++ )
2286 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2288 wxPuts(wxT("--- End of the file list"));
2291 else if ( start
== wxT("QUIT") )
2293 break; // get out of here!
2297 wxChar ch
= ftp
->SendCommand(buf
);
2298 wxPrintf(wxT("Command %s"), ch
? wxT("succeeded") : wxT("failed"));
2301 wxPrintf(wxT(" (return code %c)"), ch
);
2304 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2308 wxPuts(wxT("\n*** done ***"));
2313 // ----------------------------------------------------------------------------
2315 // ----------------------------------------------------------------------------
2317 #ifdef TEST_STACKWALKER
2319 #if wxUSE_STACKWALKER
2321 #include "wx/stackwalk.h"
2323 class StackDump
: public wxStackWalker
2326 StackDump(const char *argv0
)
2327 : wxStackWalker(argv0
)
2331 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
2333 wxPuts(wxT("Stack dump:"));
2335 wxStackWalker::Walk(skip
, maxdepth
);
2339 virtual void OnStackFrame(const wxStackFrame
& frame
)
2341 printf("[%2d] ", (int) frame
.GetLevel());
2343 wxString name
= frame
.GetName();
2344 if ( !name
.empty() )
2346 printf("%-20.40s", (const char*)name
.mb_str());
2350 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2353 if ( frame
.HasSourceLocation() )
2356 (const char*)frame
.GetFileName().mb_str(),
2357 (int)frame
.GetLine());
2363 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2365 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2366 (const char*)name
.mb_str(),
2367 (const char*)val
.mb_str());
2372 static void TestStackWalk(const char *argv0
)
2374 wxPuts(wxT("*** Testing wxStackWalker ***\n"));
2376 StackDump
dump(argv0
);
2382 #endif // wxUSE_STACKWALKER
2384 #endif // TEST_STACKWALKER
2386 // ----------------------------------------------------------------------------
2388 // ----------------------------------------------------------------------------
2390 #ifdef TEST_STDPATHS
2392 #include "wx/stdpaths.h"
2393 #include "wx/wxchar.h" // wxPrintf
2395 static void TestStandardPaths()
2397 wxPuts(wxT("*** Testing wxStandardPaths ***\n"));
2399 wxTheApp
->SetAppName(wxT("console"));
2401 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
2402 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2403 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2404 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2405 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2406 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2407 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2408 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2409 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2410 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2411 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2412 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2413 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
2414 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2415 stdp
.GetLocalizedResourcesDir
2418 wxStandardPaths::ResourceCat_Messages
2424 #endif // TEST_STDPATHS
2426 // ----------------------------------------------------------------------------
2428 // ----------------------------------------------------------------------------
2430 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2436 #include "wx/volume.h"
2438 static const wxChar
*volumeKinds
[] =
2444 wxT("network volume"),
2445 wxT("other volume"),
2448 static void TestFSVolume()
2450 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2452 wxArrayString volumes
= wxFSVolume::GetVolumes();
2453 size_t count
= volumes
.GetCount();
2457 wxPuts(wxT("ERROR: no mounted volumes?"));
2461 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
2463 for ( size_t n
= 0; n
< count
; n
++ )
2465 wxFSVolume
vol(volumes
[n
]);
2468 wxPuts(wxT("ERROR: couldn't create volume"));
2472 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2474 vol
.GetDisplayName().c_str(),
2475 vol
.GetName().c_str(),
2476 volumeKinds
[vol
.GetKind()],
2477 vol
.IsWritable() ? wxT("rw") : wxT("ro"),
2478 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? wxT("removable")
2485 #endif // TEST_VOLUME
2487 // ----------------------------------------------------------------------------
2489 // ----------------------------------------------------------------------------
2491 #ifdef TEST_DATETIME
2493 #include "wx/math.h"
2494 #include "wx/datetime.h"
2496 #if TEST_INTERACTIVE
2498 static void TestDateTimeInteractive()
2500 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
2506 wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
2507 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2510 // kill the last '\n'
2511 buf
[wxStrlen(buf
) - 1] = 0;
2513 if ( wxString(buf
).CmpNoCase("quit") == 0 )
2517 const wxChar
*p
= dt
.ParseDate(buf
);
2520 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
2526 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
2529 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
2530 dt
.Format(wxT("%b %d, %Y")).c_str(),
2532 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2533 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2534 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
2540 #endif // TEST_INTERACTIVE
2541 #endif // TEST_DATETIME
2543 // ----------------------------------------------------------------------------
2545 // ----------------------------------------------------------------------------
2547 #ifdef TEST_SNGLINST
2548 #include "wx/snglinst.h"
2549 #endif // TEST_SNGLINST
2551 int main(int argc
, char **argv
)
2554 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
2559 for (n
= 0; n
< argc
; n
++ )
2561 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
2562 wxArgv
[n
] = wxStrdup(warg
);
2567 #else // !wxUSE_UNICODE
2569 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2571 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
2573 wxInitializer initializer
;
2576 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
2581 #ifdef TEST_SNGLINST
2582 wxSingleInstanceChecker checker
;
2583 if ( checker
.Create(wxT(".wxconsole.lock")) )
2585 if ( checker
.IsAnotherRunning() )
2587 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
2592 // wait some time to give time to launch another instance
2593 wxPrintf(wxT("Press \"Enter\" to continue..."));
2596 else // failed to create
2598 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
2600 #endif // TEST_SNGLINST
2603 TestCmdLineConvert();
2605 #if wxUSE_CMDLINE_PARSER
2606 static const wxCmdLineEntryDesc cmdLineDesc
[] =
2608 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
2609 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
2610 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
2611 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
2613 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
2614 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
2615 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
2616 wxCMD_LINE_VAL_NUMBER
},
2617 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
2618 wxCMD_LINE_VAL_DATE
},
2619 { wxCMD_LINE_OPTION
, "f", "double", "output double",
2620 wxCMD_LINE_VAL_DOUBLE
},
2622 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
2623 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
2628 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
2630 parser
.AddOption(wxT("project_name"), wxT(""), wxT("full path to project file"),
2631 wxCMD_LINE_VAL_STRING
,
2632 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
2634 switch ( parser
.Parse() )
2637 wxLogMessage(wxT("Help was given, terminating."));
2641 ShowCmdLine(parser
);
2645 wxLogMessage(wxT("Syntax error detected, aborting."));
2648 #endif // wxUSE_CMDLINE_PARSER
2650 #endif // TEST_CMDLINE
2662 TestDllListLoaded();
2663 #endif // TEST_DYNLIB
2667 #endif // TEST_ENVIRON
2669 #ifdef TEST_FILECONF
2671 #endif // TEST_FILECONF
2675 #endif // TEST_LOCALE
2678 wxPuts(wxT("*** Testing wxLog ***"));
2681 for ( size_t n
= 0; n
< 8000; n
++ )
2683 s
<< (wxChar
)(wxT('A') + (n
% 26));
2686 wxLogWarning(wxT("The length of the string is %lu"),
2687 (unsigned long)s
.length());
2690 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
2692 // this one shouldn't be truncated
2695 // but this one will because log functions use fixed size buffer
2696 // (note that it doesn't need '\n' at the end neither - will be added
2698 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
2708 #ifdef TEST_FILENAME
2711 TestFileNameDirManip();
2712 TestFileNameComparison();
2713 TestFileNameOperations();
2714 #endif // TEST_FILENAME
2716 #ifdef TEST_FILETIME
2721 #endif // TEST_FILETIME
2724 wxLog::AddTraceMask(FTP_TRACE_MASK
);
2726 // wxFTP cannot be a static variable as its ctor needs to access
2727 // wxWidgets internals after it has been initialized
2729 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
2731 if ( TestFtpConnect() )
2733 TestFtpInteractive();
2735 //else: connecting to the FTP server failed
2741 //wxLog::AddTraceMask(wxT("mime"));
2745 TestMimeAssociate();
2750 #ifdef TEST_INFO_FUNCTIONS
2755 #if TEST_INTERACTIVE
2758 #endif // TEST_INFO_FUNCTIONS
2760 #ifdef TEST_PATHLIST
2762 #endif // TEST_PATHLIST
2766 #endif // TEST_PRINTF
2773 #endif // TEST_REGCONF
2775 #if defined TEST_REGEX && TEST_INTERACTIVE
2776 TestRegExInteractive();
2777 #endif // defined TEST_REGEX && TEST_INTERACTIVE
2779 #ifdef TEST_REGISTRY
2781 TestRegistryAssociation();
2782 #endif // TEST_REGISTRY
2784 #ifdef TEST_DATETIME
2785 #if TEST_INTERACTIVE
2786 TestDateTimeInteractive();
2788 #endif // TEST_DATETIME
2790 #ifdef TEST_SCOPEGUARD
2794 #ifdef TEST_STACKWALKER
2795 #if wxUSE_STACKWALKER
2796 TestStackWalk(argv
[0]);
2798 #endif // TEST_STACKWALKER
2800 #ifdef TEST_STDPATHS
2801 TestStandardPaths();
2805 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
2807 #endif // TEST_USLEEP
2811 #endif // TEST_VOLUME
2815 for ( int n
= 0; n
< argc
; n
++ )
2820 #endif // wxUSE_UNICODE