1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // IMPORTANT NOTE FOR WXWIDGETS USERS:
13 // If you're a wxWidgets user and you're looking at this file to learn how to
14 // structure a wxWidgets console application, then you don't have much to learn.
15 // This application is used more for testing rather than as sample but
16 // basically the following simple block is enough for you to start your
17 // own console application:
20 int main(int argc, char **argv)
22 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
24 wxInitializer initializer;
27 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
31 static const wxCmdLineEntryDesc cmdLineDesc[] =
33 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
34 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
35 // ... your other command line options here...
40 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
41 switch ( parser.Parse() )
44 wxLogMessage(wxT("Help was given, terminating."));
48 // everything is ok; proceed
52 wxLogMessage(wxT("Syntax error detected, aborting."));
56 // do something useful here
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
75 #include "wx/string.h"
77 #include "wx/filename.h"
80 #include "wx/apptrait.h"
81 #include "wx/platinfo.h"
82 #include "wx/wxchar.h"
84 // without this pragma, the stupid compiler precompiles #defines below so that
85 // changing them doesn't "take place" later!
90 // ----------------------------------------------------------------------------
91 // conditional compilation
92 // ----------------------------------------------------------------------------
95 A note about all these conditional compilation macros: this file is used
96 both as a test suite for various non-GUI wxWidgets classes and as a
97 scratchpad for quick tests. So there are two compilation modes: if you
98 define TEST_ALL all tests are run, otherwise you may enable the individual
99 tests individually in the "#else" branch below.
102 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
103 // test, define it to 1 to do all tests.
109 #define TEST_DATETIME
114 #define TEST_FILECONF
115 #define TEST_FILENAME
116 #define TEST_FILETIME
118 #define TEST_INFO_FUNCTIONS
123 #define TEST_PATHLIST
127 #define TEST_REGISTRY
128 #define TEST_SCOPEGUARD
129 #define TEST_SNGLINST
130 // #define TEST_SOCKETS --FIXME! (RN)
131 #define TEST_STACKWALKER
132 #define TEST_STDPATHS
135 // #define TEST_VOLUME --FIXME! (RN)
138 #else // #if TEST_ALL
142 // some tests are interactive, define this to run them
143 #ifdef TEST_INTERACTIVE
144 #undef TEST_INTERACTIVE
146 #define TEST_INTERACTIVE 1
148 #define TEST_INTERACTIVE 0
151 // ============================================================================
153 // ============================================================================
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 #if defined(TEST_SOCKETS)
161 // replace TABs with \t and CRs with \n
162 static wxString
MakePrintable(const wxChar
*s
)
165 (void)str
.Replace(wxT("\t"), wxT("\\t"));
166 (void)str
.Replace(wxT("\n"), wxT("\\n"));
167 (void)str
.Replace(wxT("\r"), wxT("\\r"));
172 #endif // MakePrintable() is used
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
180 #include "wx/cmdline.h"
181 #include "wx/datetime.h"
183 #if wxUSE_CMDLINE_PARSER
185 static void ShowCmdLine(const wxCmdLineParser
& parser
)
187 wxString s
= wxT("Command line parsed successfully:\nInput files: ");
189 size_t count
= parser
.GetParamCount();
190 for ( size_t param
= 0; param
< count
; param
++ )
192 s
<< parser
.GetParam(param
) << ' ';
196 << wxT("Verbose:\t") << (parser
.Found(wxT("v")) ? wxT("yes") : wxT("no")) << '\n'
197 << wxT("Quiet:\t") << (parser
.Found(wxT("q")) ? wxT("yes") : wxT("no")) << '\n';
203 if ( parser
.Found(wxT("o"), &strVal
) )
204 s
<< wxT("Output file:\t") << strVal
<< '\n';
205 if ( parser
.Found(wxT("i"), &strVal
) )
206 s
<< wxT("Input dir:\t") << strVal
<< '\n';
207 if ( parser
.Found(wxT("s"), &lVal
) )
208 s
<< wxT("Size:\t") << lVal
<< '\n';
209 if ( parser
.Found(wxT("f"), &dVal
) )
210 s
<< wxT("Double:\t") << dVal
<< '\n';
211 if ( parser
.Found(wxT("d"), &dt
) )
212 s
<< wxT("Date:\t") << dt
.FormatISODate() << '\n';
213 if ( parser
.Found(wxT("project_name"), &strVal
) )
214 s
<< wxT("Project:\t") << strVal
<< '\n';
219 #endif // wxUSE_CMDLINE_PARSER
221 static void TestCmdLineConvert()
223 static const wxChar
*cmdlines
[] =
226 wxT("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
227 wxT("literal \\\" and \"\""),
230 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
232 const wxChar
*cmdline
= cmdlines
[n
];
233 wxPrintf(wxT("Parsing: %s\n"), cmdline
);
234 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
236 size_t count
= args
.GetCount();
237 wxPrintf(wxT("\targc = %u\n"), count
);
238 for ( size_t arg
= 0; arg
< count
; arg
++ )
240 wxPrintf(wxT("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
245 #endif // TEST_CMDLINE
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
256 static const wxChar
*ROOTDIR
= wxT("/");
257 static const wxChar
*TESTDIR
= wxT("/usr/local/share");
258 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
259 static const wxChar
*ROOTDIR
= wxT("c:\\");
260 static const wxChar
*TESTDIR
= wxT("d:\\");
262 #error "don't know where the root directory is"
265 static void TestDirEnumHelper(wxDir
& dir
,
266 int flags
= wxDIR_DEFAULT
,
267 const wxString
& filespec
= wxEmptyString
)
271 if ( !dir
.IsOpened() )
274 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
277 wxPrintf(wxT("\t%s\n"), filename
.c_str());
279 cont
= dir
.GetNext(&filename
);
282 wxPuts(wxEmptyString
);
287 static void TestDirEnum()
289 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
291 wxString cwd
= wxGetCwd();
292 if ( !wxDir::Exists(cwd
) )
294 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
299 if ( !dir
.IsOpened() )
301 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
305 wxPuts(wxT("Enumerating everything in current directory:"));
306 TestDirEnumHelper(dir
);
308 wxPuts(wxT("Enumerating really everything in current directory:"));
309 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
311 wxPuts(wxT("Enumerating object files in current directory:"));
312 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, wxT("*.o*"));
314 wxPuts(wxT("Enumerating directories in current directory:"));
315 TestDirEnumHelper(dir
, wxDIR_DIRS
);
317 wxPuts(wxT("Enumerating files in current directory:"));
318 TestDirEnumHelper(dir
, wxDIR_FILES
);
320 wxPuts(wxT("Enumerating files including hidden in current directory:"));
321 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
325 wxPuts(wxT("Enumerating everything in root directory:"));
326 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
328 wxPuts(wxT("Enumerating directories in root directory:"));
329 TestDirEnumHelper(dir
, wxDIR_DIRS
);
331 wxPuts(wxT("Enumerating files in root directory:"));
332 TestDirEnumHelper(dir
, wxDIR_FILES
);
334 wxPuts(wxT("Enumerating files including hidden in root directory:"));
335 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
337 wxPuts(wxT("Enumerating files in non existing directory:"));
338 wxDir
dirNo(wxT("nosuchdir"));
339 TestDirEnumHelper(dirNo
);
344 class DirPrintTraverser
: public wxDirTraverser
347 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
349 return wxDIR_CONTINUE
;
352 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
354 wxString path
, name
, ext
;
355 wxFileName::SplitPath(dirname
, &path
, &name
, &ext
);
358 name
<< wxT('.') << ext
;
361 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
363 if ( wxIsPathSeparator(*p
) )
367 wxPrintf(wxT("%s%s\n"), indent
.c_str(), name
.c_str());
369 return wxDIR_CONTINUE
;
373 static void TestDirTraverse()
375 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
379 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
380 wxPrintf(wxT("There are %u files under '%s'\n"), n
, TESTDIR
);
383 wxPrintf(wxT("First one is '%s'\n"), files
[0u].c_str());
384 wxPrintf(wxT(" last one is '%s'\n"), files
[n
- 1].c_str());
387 // enum again with custom traverser
388 wxPuts(wxT("Now enumerating directories:"));
390 DirPrintTraverser traverser
;
391 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
396 static void TestDirExists()
398 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
400 static const wxChar
*dirnames
[] =
403 #if defined(__WXMSW__)
406 wxT("\\\\share\\file"),
410 wxT("c:\\autoexec.bat"),
411 #elif defined(__UNIX__)
420 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
422 wxPrintf(wxT("%-40s: %s\n"),
424 wxDir::Exists(dirnames
[n
]) ? wxT("exists")
425 : wxT("doesn't exist"));
433 // ----------------------------------------------------------------------------
435 // ----------------------------------------------------------------------------
439 #include "wx/dynlib.h"
441 static void TestDllLoad()
443 #if defined(__WXMSW__)
444 static const wxChar
*LIB_NAME
= wxT("kernel32.dll");
445 static const wxChar
*FUNC_NAME
= wxT("lstrlenA");
446 #elif defined(__UNIX__)
447 // weird: using just libc.so does *not* work!
448 static const wxChar
*LIB_NAME
= wxT("/lib/libc.so.6");
449 static const wxChar
*FUNC_NAME
= wxT("strlen");
451 #error "don't know how to test wxDllLoader on this platform"
454 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
456 wxDynamicLibrary
lib(LIB_NAME
);
457 if ( !lib
.IsLoaded() )
459 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME
);
463 typedef int (wxSTDCALL
*wxStrlenType
)(const char *);
464 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
467 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
468 FUNC_NAME
, LIB_NAME
);
472 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
473 FUNC_NAME
, LIB_NAME
);
475 if ( pfnStrlen("foo") != 3 )
477 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
481 wxPuts(wxT("... ok"));
486 static const wxChar
*FUNC_NAME_AW
= wxT("lstrlen");
488 typedef int (wxSTDCALL
*wxStrlenTypeAorW
)(const wxChar
*);
490 pfnStrlenAorW
= (wxStrlenTypeAorW
)lib
.GetSymbolAorW(FUNC_NAME_AW
);
491 if ( !pfnStrlenAorW
)
493 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
494 FUNC_NAME_AW
, LIB_NAME
);
498 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
500 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
507 #if defined(__WXMSW__) || defined(__UNIX__)
509 static void TestDllListLoaded()
511 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
513 puts("\nLoaded modules:");
514 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
515 const size_t count
= dlls
.GetCount();
516 for ( size_t n
= 0; n
< count
; ++n
)
518 const wxDynamicLibraryDetails
& details
= dlls
[n
];
519 printf("%-45s", (const char *)details
.GetPath().mb_str());
521 void *addr
wxDUMMY_INITIALIZE(NULL
);
522 size_t len
wxDUMMY_INITIALIZE(0);
523 if ( details
.GetAddress(&addr
, &len
) )
525 printf(" %08lx:%08lx",
526 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
529 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
535 #endif // TEST_DYNLIB
537 // ----------------------------------------------------------------------------
539 // ----------------------------------------------------------------------------
543 #include "wx/utils.h"
545 static wxString
MyGetEnv(const wxString
& var
)
548 if ( !wxGetEnv(var
, &val
) )
549 val
= wxT("<empty>");
551 val
= wxString(wxT('\'')) + val
+ wxT('\'');
556 static void TestEnvironment()
558 const wxChar
*var
= wxT("wxTestVar");
560 wxPuts(wxT("*** testing environment access functions ***"));
562 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
563 wxSetEnv(var
, wxT("value for wxTestVar"));
564 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
565 wxSetEnv(var
, wxT("another value"));
566 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
568 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
569 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
572 #endif // TEST_ENVIRON
574 // ----------------------------------------------------------------------------
576 // ----------------------------------------------------------------------------
581 #include "wx/ffile.h"
582 #include "wx/textfile.h"
584 static void TestFileRead()
586 wxPuts(wxT("*** wxFile read test ***"));
588 wxFile
file(wxT("testdata.fc"));
589 if ( file
.IsOpened() )
591 wxPrintf(wxT("File length: %lu\n"), file
.Length());
593 wxPuts(wxT("File dump:\n----------"));
595 static const size_t len
= 1024;
599 size_t nRead
= file
.Read(buf
, len
);
600 if ( nRead
== (size_t)wxInvalidOffset
)
602 wxPrintf(wxT("Failed to read the file."));
606 fwrite(buf
, nRead
, 1, stdout
);
612 wxPuts(wxT("----------"));
616 wxPrintf(wxT("ERROR: can't open test file.\n"));
619 wxPuts(wxEmptyString
);
622 static void TestTextFileRead()
624 wxPuts(wxT("*** wxTextFile read test ***"));
626 wxTextFile
file(wxT("testdata.fc"));
629 wxPrintf(wxT("Number of lines: %u\n"), file
.GetLineCount());
630 wxPrintf(wxT("Last line: '%s'\n"), file
.GetLastLine().c_str());
634 wxPuts(wxT("\nDumping the entire file:"));
635 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
637 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
639 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
641 wxPuts(wxT("\nAnd now backwards:"));
642 for ( s
= file
.GetLastLine();
643 file
.GetCurrentLine() != 0;
644 s
= file
.GetPrevLine() )
646 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
648 wxPrintf(wxT("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
652 wxPrintf(wxT("ERROR: can't open '%s'\n"), file
.GetName());
655 wxPuts(wxEmptyString
);
658 static void TestFileCopy()
660 wxPuts(wxT("*** Testing wxCopyFile ***"));
662 static const wxChar
*filename1
= wxT("testdata.fc");
663 static const wxChar
*filename2
= wxT("test2");
664 if ( !wxCopyFile(filename1
, filename2
) )
666 wxPuts(wxT("ERROR: failed to copy file"));
670 wxFFile
f1(filename1
, wxT("rb")),
671 f2(filename2
, wxT("rb"));
673 if ( !f1
.IsOpened() || !f2
.IsOpened() )
675 wxPuts(wxT("ERROR: failed to open file(s)"));
680 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
682 wxPuts(wxT("ERROR: failed to read file(s)"));
686 if ( (s1
.length() != s2
.length()) ||
687 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
689 wxPuts(wxT("ERROR: copy error!"));
693 wxPuts(wxT("File was copied ok."));
699 if ( !wxRemoveFile(filename2
) )
701 wxPuts(wxT("ERROR: failed to remove the file"));
704 wxPuts(wxEmptyString
);
707 static void TestTempFile()
709 wxPuts(wxT("*** wxTempFile test ***"));
712 if ( tmpFile
.Open(wxT("test2")) && tmpFile
.Write(wxT("the answer is 42")) )
714 if ( tmpFile
.Commit() )
715 wxPuts(wxT("File committed."));
717 wxPuts(wxT("ERROR: could't commit temp file."));
719 wxRemoveFile(wxT("test2"));
722 wxPuts(wxEmptyString
);
727 // ----------------------------------------------------------------------------
729 // ----------------------------------------------------------------------------
733 #include "wx/confbase.h"
734 #include "wx/fileconf.h"
736 static const struct FileConfTestData
738 const wxChar
*name
; // value name
739 const wxChar
*value
; // the value from the file
742 { wxT("value1"), wxT("one") },
743 { wxT("value2"), wxT("two") },
744 { wxT("novalue"), wxT("default") },
747 static void TestFileConfRead()
749 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
751 wxFileConfig
fileconf(wxT("test"), wxEmptyString
,
752 wxT("testdata.fc"), wxEmptyString
,
753 wxCONFIG_USE_RELATIVE_PATH
);
755 // test simple reading
756 wxPuts(wxT("\nReading config file:"));
757 wxString
defValue(wxT("default")), value
;
758 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
760 const FileConfTestData
& data
= fcTestData
[n
];
761 value
= fileconf
.Read(data
.name
, defValue
);
762 wxPrintf(wxT("\t%s = %s "), data
.name
, value
.c_str());
763 if ( value
== data
.value
)
769 wxPrintf(wxT("(ERROR: should be %s)\n"), data
.value
);
773 // test enumerating the entries
774 wxPuts(wxT("\nEnumerating all root entries:"));
777 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
780 wxPrintf(wxT("\t%s = %s\n"),
782 fileconf
.Read(name
.c_str(), wxT("ERROR")).c_str());
784 cont
= fileconf
.GetNextEntry(name
, dummy
);
787 static const wxChar
*testEntry
= wxT("TestEntry");
788 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
789 fileconf
.Write(testEntry
, wxT("A value"));
790 fileconf
.DeleteEntry(testEntry
);
791 wxPrintf(fileconf
.HasEntry(testEntry
) ? wxT("ERROR\n") : wxT("ok\n"));
794 #endif // TEST_FILECONF
796 // ----------------------------------------------------------------------------
798 // ----------------------------------------------------------------------------
802 #include "wx/filename.h"
805 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
809 wxString full
= fn
.GetFullPath();
811 wxString vol
, path
, name
, ext
;
812 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
814 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
815 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
817 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
818 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
819 path
.c_str(), name
.c_str(), ext
.c_str());
821 wxPrintf(wxT("path is also:\t'%s'\n"), fn
.GetPath().c_str());
822 wxPrintf(wxT("with volume: \t'%s'\n"),
823 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
824 wxPrintf(wxT("with separator:\t'%s'\n"),
825 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
826 wxPrintf(wxT("with both: \t'%s'\n"),
827 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
829 wxPuts(wxT("The directories in the path are:"));
830 wxArrayString dirs
= fn
.GetDirs();
831 size_t count
= dirs
.GetCount();
832 for ( size_t n
= 0; n
< count
; n
++ )
834 wxPrintf(wxT("\t%u: %s\n"), n
, dirs
[n
].c_str());
839 static void TestFileNameTemp()
841 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
843 static const wxChar
*tmpprefixes
[] =
851 wxT("/tmp/foo/bar"), // this one must be an error
855 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
857 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
860 // "error" is not in upper case because it may be ok
861 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
865 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
866 tmpprefixes
[n
], path
.c_str());
868 if ( !wxRemoveFile(path
) )
870 wxLogWarning(wxT("Failed to remove temp file '%s'"),
877 static void TestFileNameDirManip()
879 // TODO: test AppendDir(), RemoveDir(), ...
882 static void TestFileNameComparison()
887 static void TestFileNameOperations()
892 static void TestFileNameCwd()
897 #endif // TEST_FILENAME
899 // ----------------------------------------------------------------------------
900 // wxFileName time functions
901 // ----------------------------------------------------------------------------
905 #include "wx/filename.h"
906 #include "wx/datetime.h"
908 static void TestFileGetTimes()
910 wxFileName
fn(wxT("testdata.fc"));
912 wxDateTime dtAccess
, dtMod
, dtCreate
;
913 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
915 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
919 static const wxChar
*fmt
= wxT("%Y-%b-%d %H:%M:%S");
921 wxPrintf(wxT("File times for '%s':\n"), fn
.GetFullPath().c_str());
922 wxPrintf(wxT("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
923 wxPrintf(wxT("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
924 wxPrintf(wxT("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
929 static void TestFileSetTimes()
931 wxFileName
fn(wxT("testdata.fc"));
935 wxPrintf(wxT("ERROR: Touch() failed.\n"));
940 #endif // TEST_FILETIME
942 // ----------------------------------------------------------------------------
944 // ----------------------------------------------------------------------------
949 #include "wx/utils.h" // for wxSetEnv
951 static wxLocale gs_localeDefault
;
952 // NOTE: don't init it here as it needs a wxAppTraits object
953 // and thus must be init-ed after creation of the wxInitializer
954 // class in the main()
956 // find the name of the language from its value
957 static const wxChar
*GetLangName(int lang
)
959 static const wxChar
*languageNames
[] =
969 wxT("ARABIC_ALGERIA"),
970 wxT("ARABIC_BAHRAIN"),
973 wxT("ARABIC_JORDAN"),
974 wxT("ARABIC_KUWAIT"),
975 wxT("ARABIC_LEBANON"),
977 wxT("ARABIC_MOROCCO"),
980 wxT("ARABIC_SAUDI_ARABIA"),
983 wxT("ARABIC_TUNISIA"),
990 wxT("AZERI_CYRILLIC"),
1005 wxT("CHINESE_SIMPLIFIED"),
1006 wxT("CHINESE_TRADITIONAL"),
1007 wxT("CHINESE_HONGKONG"),
1008 wxT("CHINESE_MACAU"),
1009 wxT("CHINESE_SINGAPORE"),
1010 wxT("CHINESE_TAIWAN"),
1016 wxT("DUTCH_BELGIAN"),
1020 wxT("ENGLISH_AUSTRALIA"),
1021 wxT("ENGLISH_BELIZE"),
1022 wxT("ENGLISH_BOTSWANA"),
1023 wxT("ENGLISH_CANADA"),
1024 wxT("ENGLISH_CARIBBEAN"),
1025 wxT("ENGLISH_DENMARK"),
1026 wxT("ENGLISH_EIRE"),
1027 wxT("ENGLISH_JAMAICA"),
1028 wxT("ENGLISH_NEW_ZEALAND"),
1029 wxT("ENGLISH_PHILIPPINES"),
1030 wxT("ENGLISH_SOUTH_AFRICA"),
1031 wxT("ENGLISH_TRINIDAD"),
1032 wxT("ENGLISH_ZIMBABWE"),
1040 wxT("FRENCH_BELGIAN"),
1041 wxT("FRENCH_CANADIAN"),
1042 wxT("FRENCH_LUXEMBOURG"),
1043 wxT("FRENCH_MONACO"),
1044 wxT("FRENCH_SWISS"),
1049 wxT("GERMAN_AUSTRIAN"),
1050 wxT("GERMAN_BELGIUM"),
1051 wxT("GERMAN_LIECHTENSTEIN"),
1052 wxT("GERMAN_LUXEMBOURG"),
1053 wxT("GERMAN_SWISS"),
1070 wxT("ITALIAN_SWISS"),
1075 wxT("KASHMIRI_INDIA"),
1093 wxT("MALAY_BRUNEI_DARUSSALAM"),
1094 wxT("MALAY_MALAYSIA"),
1103 wxT("NEPALI_INDIA"),
1104 wxT("NORWEGIAN_BOKMAL"),
1105 wxT("NORWEGIAN_NYNORSK"),
1112 wxT("PORTUGUESE_BRAZILIAN"),
1115 wxT("RHAETO_ROMANCE"),
1118 wxT("RUSSIAN_UKRAINE"),
1122 wxT("SCOTS_GAELIC"),
1124 wxT("SERBIAN_CYRILLIC"),
1125 wxT("SERBIAN_LATIN"),
1126 wxT("SERBO_CROATIAN"),
1137 wxT("SPANISH_ARGENTINA"),
1138 wxT("SPANISH_BOLIVIA"),
1139 wxT("SPANISH_CHILE"),
1140 wxT("SPANISH_COLOMBIA"),
1141 wxT("SPANISH_COSTA_RICA"),
1142 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1143 wxT("SPANISH_ECUADOR"),
1144 wxT("SPANISH_EL_SALVADOR"),
1145 wxT("SPANISH_GUATEMALA"),
1146 wxT("SPANISH_HONDURAS"),
1147 wxT("SPANISH_MEXICAN"),
1148 wxT("SPANISH_MODERN"),
1149 wxT("SPANISH_NICARAGUA"),
1150 wxT("SPANISH_PANAMA"),
1151 wxT("SPANISH_PARAGUAY"),
1152 wxT("SPANISH_PERU"),
1153 wxT("SPANISH_PUERTO_RICO"),
1154 wxT("SPANISH_URUGUAY"),
1156 wxT("SPANISH_VENEZUELA"),
1160 wxT("SWEDISH_FINLAND"),
1178 wxT("URDU_PAKISTAN"),
1180 wxT("UZBEK_CYRILLIC"),
1193 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1194 return languageNames
[lang
];
1196 return wxT("INVALID");
1199 static void TestDefaultLang()
1201 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1203 gs_localeDefault
.Init(wxLANGUAGE_ENGLISH
);
1205 static const wxChar
*langStrings
[] =
1207 NULL
, // system default
1214 wxT("de_DE.iso88591"),
1216 wxT("?"), // invalid lang spec
1217 wxT("klingonese"), // I bet on some systems it does exist...
1220 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1221 wxLocale::GetSystemEncodingName().c_str(),
1222 wxLocale::GetSystemEncoding());
1224 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1226 const wxChar
*langStr
= langStrings
[n
];
1229 // FIXME: this doesn't do anything at all under Windows, we need
1230 // to create a new wxLocale!
1231 wxSetEnv(wxT("LC_ALL"), langStr
);
1234 int lang
= gs_localeDefault
.GetSystemLanguage();
1235 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1236 langStr
? langStr
: wxT("system default"), GetLangName(lang
));
1240 #endif // TEST_LOCALE
1242 // ----------------------------------------------------------------------------
1244 // ----------------------------------------------------------------------------
1248 #include "wx/mimetype.h"
1250 static void TestMimeEnum()
1252 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1254 wxArrayString mimetypes
;
1256 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1258 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
1263 for ( size_t n
= 0; n
< count
; n
++ )
1265 wxFileType
*filetype
=
1266 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1269 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1270 mimetypes
[n
].c_str());
1274 filetype
->GetDescription(&desc
);
1275 filetype
->GetExtensions(exts
);
1277 filetype
->GetIcon(NULL
);
1280 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1283 extsAll
<< wxT(", ");
1287 wxPrintf(wxT("\t%s: %s (%s)\n"),
1288 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1291 wxPuts(wxEmptyString
);
1294 static void TestMimeFilename()
1296 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1298 static const wxChar
*filenames
[] =
1301 wxT("document.pdf"),
1303 wxT("picture.jpeg"),
1306 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1308 const wxString fname
= filenames
[n
];
1309 wxString ext
= fname
.AfterLast(wxT('.'));
1310 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1313 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1318 if ( !ft
->GetDescription(&desc
) )
1319 desc
= wxT("<no description>");
1322 if ( !ft
->GetOpenCommand(&cmd
,
1323 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1324 cmd
= wxT("<no command available>");
1326 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
1328 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1329 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1335 wxPuts(wxEmptyString
);
1338 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1341 static void TestMimeOverride()
1343 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1345 static const wxChar
*mailcap
= wxT("/tmp/mailcap");
1346 static const wxChar
*mimetypes
= wxT("/tmp/mime.types");
1348 if ( wxFile::Exists(mailcap
) )
1349 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1351 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? wxT("ok") : wxT("ERROR"));
1353 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1356 if ( wxFile::Exists(mimetypes
) )
1357 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1359 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? wxT("ok") : wxT("ERROR"));
1361 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1364 wxPuts(wxEmptyString
);
1367 static void TestMimeAssociate()
1369 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1371 wxFileTypeInfo
ftInfo(
1372 wxT("application/x-xyz"),
1373 wxT("xyzview '%s'"), // open cmd
1374 wxT(""), // print cmd
1375 wxT("XYZ File"), // description
1376 wxT(".xyz"), // extensions
1377 wxNullPtr
// end of extensions
1379 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1381 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1384 wxPuts(wxT("ERROR: failed to create association!"));
1388 // TODO: read it back
1392 wxPuts(wxEmptyString
);
1399 // ----------------------------------------------------------------------------
1400 // module dependencies feature
1401 // ----------------------------------------------------------------------------
1405 #include "wx/module.h"
1407 class wxTestModule
: public wxModule
1410 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1411 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1414 class wxTestModuleA
: public wxTestModule
1419 DECLARE_DYNAMIC_CLASS(wxTestModuleA
)
1422 class wxTestModuleB
: public wxTestModule
1427 DECLARE_DYNAMIC_CLASS(wxTestModuleB
)
1430 class wxTestModuleC
: public wxTestModule
1435 DECLARE_DYNAMIC_CLASS(wxTestModuleC
)
1438 class wxTestModuleD
: public wxTestModule
1443 DECLARE_DYNAMIC_CLASS(wxTestModuleD
)
1446 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC
, wxModule
)
1447 wxTestModuleC::wxTestModuleC()
1449 AddDependency(CLASSINFO(wxTestModuleD
));
1452 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA
, wxModule
)
1453 wxTestModuleA::wxTestModuleA()
1455 AddDependency(CLASSINFO(wxTestModuleB
));
1456 AddDependency(CLASSINFO(wxTestModuleD
));
1459 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD
, wxModule
)
1460 wxTestModuleD::wxTestModuleD()
1464 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB
, wxModule
)
1465 wxTestModuleB::wxTestModuleB()
1467 AddDependency(CLASSINFO(wxTestModuleD
));
1468 AddDependency(CLASSINFO(wxTestModuleC
));
1471 #endif // TEST_MODULE
1473 // ----------------------------------------------------------------------------
1474 // misc information functions
1475 // ----------------------------------------------------------------------------
1477 #ifdef TEST_INFO_FUNCTIONS
1479 #include "wx/utils.h"
1481 #if TEST_INTERACTIVE
1482 static void TestDiskInfo()
1484 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1488 wxChar pathname
[128];
1489 wxPrintf(wxT("\nEnter a directory name: "));
1490 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1493 // kill the last '\n'
1494 pathname
[wxStrlen(pathname
) - 1] = 0;
1496 wxLongLong total
, free
;
1497 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1499 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1503 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1504 (total
/ 1024).ToString().c_str(),
1505 (free
/ 1024).ToString().c_str(),
1510 #endif // TEST_INTERACTIVE
1512 static void TestOsInfo()
1514 wxPuts(wxT("*** Testing OS info functions ***\n"));
1517 wxGetOsVersion(&major
, &minor
);
1518 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1519 wxGetOsDescription().c_str(), major
, minor
);
1521 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1523 wxPrintf(wxT("Host name is %s (%s).\n"),
1524 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1526 wxPuts(wxEmptyString
);
1529 static void TestPlatformInfo()
1531 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1533 // get this platform
1534 wxPlatformInfo plat
;
1536 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
1537 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
1538 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
1539 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
1540 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
1541 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
1543 wxPuts(wxEmptyString
);
1546 static void TestUserInfo()
1548 wxPuts(wxT("*** Testing user info functions ***\n"));
1550 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1551 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1552 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1553 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1555 wxPuts(wxEmptyString
);
1558 #endif // TEST_INFO_FUNCTIONS
1560 // ----------------------------------------------------------------------------
1562 // ----------------------------------------------------------------------------
1564 #ifdef TEST_PATHLIST
1567 #define CMD_IN_PATH wxT("ls")
1569 #define CMD_IN_PATH wxT("command.com")
1572 static void TestPathList()
1574 wxPuts(wxT("*** Testing wxPathList ***\n"));
1576 wxPathList pathlist
;
1577 pathlist
.AddEnvList(wxT("PATH"));
1578 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1581 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1585 wxPrintf(wxT("Command found in the path as '%s'.\n"), path
.c_str());
1589 #endif // TEST_PATHLIST
1591 // ----------------------------------------------------------------------------
1592 // regular expressions
1593 // ----------------------------------------------------------------------------
1595 #if defined TEST_REGEX && TEST_INTERACTIVE
1597 #include "wx/regex.h"
1599 static void TestRegExInteractive()
1601 wxPuts(wxT("*** Testing RE interactively ***"));
1605 wxChar pattern
[128];
1606 wxPrintf(wxT("\nEnter a pattern: "));
1607 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1610 // kill the last '\n'
1611 pattern
[wxStrlen(pattern
) - 1] = 0;
1614 if ( !re
.Compile(pattern
) )
1622 wxPrintf(wxT("Enter text to match: "));
1623 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1626 // kill the last '\n'
1627 text
[wxStrlen(text
) - 1] = 0;
1629 if ( !re
.Matches(text
) )
1631 wxPrintf(wxT("No match.\n"));
1635 wxPrintf(wxT("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1638 for ( size_t n
= 1; ; n
++ )
1640 if ( !re
.GetMatch(&start
, &len
, n
) )
1645 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1646 n
, wxString(text
+ start
, len
).c_str());
1653 #endif // TEST_REGEX
1655 // ----------------------------------------------------------------------------
1657 // ----------------------------------------------------------------------------
1660 NB: this stuff was taken from the glibc test suite and modified to build
1661 in wxWidgets: if I read the copyright below properly, this shouldn't
1667 #ifdef wxTEST_PRINTF
1668 // use our functions from wxchar.cpp
1672 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1673 // in the tests below
1674 int wxPrintf( const wxChar
*format
, ... );
1675 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
1678 #include "wx/longlong.h"
1682 static void rfg1 (void);
1683 static void rfg2 (void);
1687 fmtchk (const wxChar
*fmt
)
1689 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1690 (void) wxPrintf(fmt
, 0x12);
1691 (void) wxPrintf(wxT("'\n"));
1695 fmtst1chk (const wxChar
*fmt
)
1697 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1698 (void) wxPrintf(fmt
, 4, 0x12);
1699 (void) wxPrintf(wxT("'\n"));
1703 fmtst2chk (const wxChar
*fmt
)
1705 (void) wxPrintf(wxT("%s:\t`"), fmt
);
1706 (void) wxPrintf(fmt
, 4, 4, 0x12);
1707 (void) wxPrintf(wxT("'\n"));
1710 /* This page is covered by the following copyright: */
1712 /* (C) Copyright C E Chew
1714 * Feel free to copy, use and distribute this software provided:
1716 * 1. you do not pretend that you wrote it
1717 * 2. you leave this copyright notice intact.
1721 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1728 /* Formatted Output Test
1730 * This exercises the output formatting code.
1733 wxChar
*PointerNull
= NULL
;
1740 wxChar
*prefix
= buf
;
1743 wxPuts(wxT("\nFormatted output test"));
1744 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1745 wxStrcpy(prefix
, wxT("%"));
1746 for (i
= 0; i
< 2; i
++) {
1747 for (j
= 0; j
< 2; j
++) {
1748 for (k
= 0; k
< 2; k
++) {
1749 for (l
= 0; l
< 2; l
++) {
1750 wxStrcpy(prefix
, wxT("%"));
1751 if (i
== 0) wxStrcat(prefix
, wxT("-"));
1752 if (j
== 0) wxStrcat(prefix
, wxT("+"));
1753 if (k
== 0) wxStrcat(prefix
, wxT("#"));
1754 if (l
== 0) wxStrcat(prefix
, wxT("0"));
1755 wxPrintf(wxT("%5s |"), prefix
);
1756 wxStrcpy(tp
, prefix
);
1757 wxStrcat(tp
, wxT("6d |"));
1759 wxStrcpy(tp
, prefix
);
1760 wxStrcat(tp
, wxT("6o |"));
1762 wxStrcpy(tp
, prefix
);
1763 wxStrcat(tp
, wxT("6x |"));
1765 wxStrcpy(tp
, prefix
);
1766 wxStrcat(tp
, wxT("6X |"));
1768 wxStrcpy(tp
, prefix
);
1769 wxStrcat(tp
, wxT("6u |"));
1771 wxPrintf(wxT("\n"));
1776 wxPrintf(wxT("%10s\n"), PointerNull
);
1777 wxPrintf(wxT("%-10s\n"), PointerNull
);
1780 static void TestPrintf()
1782 static wxChar shortstr
[] = wxT("Hi, Z.");
1783 static wxChar longstr
[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1784 I am ready for my first lesson today.");
1786 wxString test_format
;
1788 fmtchk(wxT("%.4x"));
1789 fmtchk(wxT("%04x"));
1790 fmtchk(wxT("%4.4x"));
1791 fmtchk(wxT("%04.4x"));
1792 fmtchk(wxT("%4.3x"));
1793 fmtchk(wxT("%04.3x"));
1795 fmtst1chk(wxT("%.*x"));
1796 fmtst1chk(wxT("%0*x"));
1797 fmtst2chk(wxT("%*.*x"));
1798 fmtst2chk(wxT("%0*.*x"));
1800 wxString bad_format
= wxT("bad format:\t\"%b\"\n");
1801 wxPrintf(bad_format
.c_str());
1802 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
1804 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1805 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1806 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1807 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1808 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1809 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1810 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1811 test_format
= wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1812 wxPrintf(test_format
.c_str(), -123456);
1813 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1814 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1816 test_format
= wxT("zero-padded string:\t\"%010s\"\n");
1817 wxPrintf(test_format
.c_str(), shortstr
);
1818 test_format
= wxT("left-adjusted Z string:\t\"%-010s\"\n");
1819 wxPrintf(test_format
.c_str(), shortstr
);
1820 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr
);
1821 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
1822 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull
);
1823 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr
);
1825 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1826 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1827 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1828 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20
);
1829 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1830 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1831 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1832 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1833 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1834 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1835 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1836 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20
);
1838 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1839 wxPrintf (wxT(" %6.5f\n"), .1);
1840 wxPrintf (wxT("x%5.4fx\n"), .5);
1842 wxPrintf (wxT("%#03x\n"), 1);
1844 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1850 while (niter
-- != 0)
1851 wxPrintf (wxT("%.17e\n"), d
/ 2);
1856 // Open Watcom cause compiler error here
1857 // Error! E173: col(24) floating-point constant too small to represent
1858 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1861 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1862 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
1863 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
1864 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
1865 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
1866 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
1867 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
1868 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
1869 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
1870 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
1875 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), wxT("%30s"), wxT("foo"));
1877 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1878 rc
, WXSIZEOF(buf
), buf
);
1881 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1882 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
1888 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1889 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1890 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1891 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1892 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1893 wxPrintf (wxT("%g should be 10\n"), 10.0);
1894 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1898 wxPrintf(wxT("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
1904 wxSprintf(buf
,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1906 result
|= wxStrcmp (buf
,
1907 wxT("onetwo three "));
1909 wxPuts (result
!= 0 ? wxT("Test failed!") : wxT("Test ok."));
1916 wxSprintf(buf
, "%07" wxLongLongFmtSpec
"o", wxLL(040000000000));
1918 // for some reason below line fails under Borland
1919 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
1922 if (wxStrcmp (buf
, wxT("40000000000")) != 0)
1925 wxPuts (wxT("\tFAILED"));
1927 wxUnusedVar(result
);
1928 wxPuts (wxEmptyString
);
1930 #endif // wxLongLong_t
1932 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
1933 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
1935 wxPuts (wxT("--- Should be no further output. ---"));
1944 memset (bytes
, '\xff', sizeof bytes
);
1945 wxSprintf (buf
, wxT("foo%hhn\n"), &bytes
[3]);
1946 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
1947 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
1949 wxPuts (wxT("%hhn overwrite more bytes"));
1954 wxPuts (wxT("%hhn wrote incorrect value"));
1966 wxSprintf (buf
, wxT("%5.s"), wxT("xyz"));
1967 if (wxStrcmp (buf
, wxT(" ")) != 0)
1968 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" "));
1969 wxSprintf (buf
, wxT("%5.f"), 33.3);
1970 if (wxStrcmp (buf
, wxT(" 33")) != 0)
1971 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 33"));
1972 wxSprintf (buf
, wxT("%8.e"), 33.3e7
);
1973 if (wxStrcmp (buf
, wxT(" 3e+08")) != 0)
1974 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3e+08"));
1975 wxSprintf (buf
, wxT("%8.E"), 33.3e7
);
1976 if (wxStrcmp (buf
, wxT(" 3E+08")) != 0)
1977 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3E+08"));
1978 wxSprintf (buf
, wxT("%.g"), 33.3);
1979 if (wxStrcmp (buf
, wxT("3e+01")) != 0)
1980 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3e+01"));
1981 wxSprintf (buf
, wxT("%.G"), 33.3);
1982 if (wxStrcmp (buf
, wxT("3E+01")) != 0)
1983 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3E+01"));
1991 wxString test_format
;
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("%.*G"), prec
, 3.3);
1999 if (wxStrcmp (buf
, wxT("3")) != 0)
2000 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT("3"));
2002 wxSprintf (buf
, wxT("%7.*G"), prec
, 3.33);
2003 if (wxStrcmp (buf
, wxT(" 3")) != 0)
2004 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 3"));
2006 test_format
= wxT("%04.*o");
2007 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2008 if (wxStrcmp (buf
, wxT(" 041")) != 0)
2009 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 041"));
2011 test_format
= wxT("%09.*u");
2012 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2013 if (wxStrcmp (buf
, wxT(" 0000033")) != 0)
2014 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 0000033"));
2016 test_format
= wxT("%04.*x");
2017 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2018 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2019 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2021 test_format
= wxT("%04.*X");
2022 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2023 if (wxStrcmp (buf
, wxT(" 021")) != 0)
2024 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf
, wxT(" 021"));
2027 #endif // TEST_PRINTF
2029 // ----------------------------------------------------------------------------
2030 // registry and related stuff
2031 // ----------------------------------------------------------------------------
2033 // this is for MSW only
2036 #undef TEST_REGISTRY
2041 #include "wx/confbase.h"
2042 #include "wx/msw/regconf.h"
2045 static void TestRegConfWrite()
2047 wxConfig
*config
= new wxConfig(wxT("myapp"));
2048 config
->SetPath(wxT("/group1"));
2049 config
->Write(wxT("entry1"), wxT("foo"));
2050 config
->SetPath(wxT("/group2"));
2051 config
->Write(wxT("entry1"), wxT("bar"));
2055 static void TestRegConfRead()
2057 wxRegConfig
*config
= new wxRegConfig(wxT("myapp"));
2061 config
->SetPath(wxT("/"));
2062 wxPuts(wxT("Enumerating / subgroups:"));
2063 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2067 bCont
= config
->GetNextGroup(str
, dummy
);
2071 #endif // TEST_REGCONF
2073 #ifdef TEST_REGISTRY
2075 #include "wx/msw/registry.h"
2077 // I chose this one because I liked its name, but it probably only exists under
2079 static const wxChar
*TESTKEY
=
2080 wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2082 static void TestRegistryRead()
2084 wxPuts(wxT("*** testing registry reading ***"));
2086 wxRegKey
key(TESTKEY
);
2087 wxPrintf(wxT("The test key name is '%s'.\n"), key
.GetName().c_str());
2090 wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
2095 size_t nSubKeys
, nValues
;
2096 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2098 wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2101 wxPrintf(wxT("Enumerating values:\n"));
2105 bool cont
= key
.GetFirstValue(value
, dummy
);
2108 wxPrintf(wxT("Value '%s': type "), value
.c_str());
2109 switch ( key
.GetValueType(value
) )
2111 case wxRegKey::Type_None
: wxPrintf(wxT("ERROR (none)")); break;
2112 case wxRegKey::Type_String
: wxPrintf(wxT("SZ")); break;
2113 case wxRegKey::Type_Expand_String
: wxPrintf(wxT("EXPAND_SZ")); break;
2114 case wxRegKey::Type_Binary
: wxPrintf(wxT("BINARY")); break;
2115 case wxRegKey::Type_Dword
: wxPrintf(wxT("DWORD")); break;
2116 case wxRegKey::Type_Multi_String
: wxPrintf(wxT("MULTI_SZ")); break;
2117 default: wxPrintf(wxT("other (unknown)")); break;
2120 wxPrintf(wxT(", value = "));
2121 if ( key
.IsNumericValue(value
) )
2124 key
.QueryValue(value
, &val
);
2125 wxPrintf(wxT("%ld"), val
);
2130 key
.QueryValue(value
, val
);
2131 wxPrintf(wxT("'%s'"), val
.c_str());
2133 key
.QueryRawValue(value
, val
);
2134 wxPrintf(wxT(" (raw value '%s')"), val
.c_str());
2139 cont
= key
.GetNextValue(value
, dummy
);
2143 static void TestRegistryAssociation()
2146 The second call to deleteself genertaes an error message, with a
2147 messagebox saying .flo is crucial to system operation, while the .ddf
2148 call also fails, but with no error message
2153 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2155 key
= wxT("ddxf_auto_file") ;
2156 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2158 key
= wxT("ddxf_auto_file") ;
2159 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2161 key
= wxT("program,0") ;
2162 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2164 key
= wxT("program \"%1\"") ;
2166 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2168 key
.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2170 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2172 key
.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2176 #endif // TEST_REGISTRY
2178 // ----------------------------------------------------------------------------
2180 // ----------------------------------------------------------------------------
2182 #ifdef TEST_SCOPEGUARD
2184 #include "wx/scopeguard.h"
2186 static void function0() { puts("function0()"); }
2187 static void function1(int n
) { printf("function1(%d)\n", n
); }
2188 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2192 void method0() { printf("method0()\n"); }
2193 void method1(int n
) { printf("method1(%d)\n", n
); }
2194 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2197 static void TestScopeGuard()
2199 wxON_BLOCK_EXIT0(function0
);
2200 wxON_BLOCK_EXIT1(function1
, 17);
2201 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2204 wxON_BLOCK_EXIT_OBJ0(obj
, Object::method0
);
2205 wxON_BLOCK_EXIT_OBJ1(obj
, Object::method1
, 7);
2206 wxON_BLOCK_EXIT_OBJ2(obj
, Object::method2
, 2.71, 'e');
2208 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2209 dismissed
.Dismiss();
2214 // ----------------------------------------------------------------------------
2216 // ----------------------------------------------------------------------------
2220 #include "wx/socket.h"
2221 #include "wx/protocol/protocol.h"
2222 #include "wx/protocol/http.h"
2224 static void TestSocketServer()
2226 wxPuts(wxT("*** Testing wxSocketServer ***\n"));
2228 static const int PORT
= 3000;
2233 wxSocketServer
*server
= new wxSocketServer(addr
);
2234 if ( !server
->Ok() )
2236 wxPuts(wxT("ERROR: failed to bind"));
2244 wxPrintf(wxT("Server: waiting for connection on port %d...\n"), PORT
);
2246 wxSocketBase
*socket
= server
->Accept();
2249 wxPuts(wxT("ERROR: wxSocketServer::Accept() failed."));
2253 wxPuts(wxT("Server: got a client."));
2255 server
->SetTimeout(60); // 1 min
2258 while ( !close
&& socket
->IsConnected() )
2261 wxChar ch
= wxT('\0');
2264 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2266 // don't log error if the client just close the connection
2267 if ( socket
->IsConnected() )
2269 wxPuts(wxT("ERROR: in wxSocket::Read."));
2289 wxPrintf(wxT("Server: got '%s'.\n"), s
.c_str());
2290 if ( s
== wxT("close") )
2292 wxPuts(wxT("Closing connection"));
2296 else if ( s
== wxT("quit") )
2301 wxPuts(wxT("Shutting down the server"));
2303 else // not a special command
2305 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2306 socket
->Write("\r\n", 2);
2307 wxPrintf(wxT("Server: wrote '%s'.\n"), s
.c_str());
2313 wxPuts(wxT("Server: lost a client unexpectedly."));
2319 // same as "delete server" but is consistent with GUI programs
2323 static void TestSocketClient()
2325 wxPuts(wxT("*** Testing wxSocketClient ***\n"));
2327 static const wxChar
*hostname
= wxT("www.wxwidgets.org");
2330 addr
.Hostname(hostname
);
2333 wxPrintf(wxT("--- Attempting to connect to %s:80...\n"), hostname
);
2335 wxSocketClient client
;
2336 if ( !client
.Connect(addr
) )
2338 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2342 wxPrintf(wxT("--- Connected to %s:%u...\n"),
2343 addr
.Hostname().c_str(), addr
.Service());
2347 // could use simply "GET" here I suppose
2349 wxString::Format(wxT("GET http://%s/\r\n"), hostname
);
2350 client
.Write(cmdGet
, cmdGet
.length());
2351 wxPrintf(wxT("--- Sent command '%s' to the server\n"),
2352 MakePrintable(cmdGet
).c_str());
2353 client
.Read(buf
, WXSIZEOF(buf
));
2354 wxPrintf(wxT("--- Server replied:\n%s"), buf
);
2358 #endif // TEST_SOCKETS
2360 // ----------------------------------------------------------------------------
2362 // ----------------------------------------------------------------------------
2366 #include "wx/protocol/ftp.h"
2367 #include "wx/protocol/log.h"
2369 #define FTP_ANONYMOUS
2373 #ifdef FTP_ANONYMOUS
2374 static const wxChar
*directory
= wxT("/pub");
2375 static const wxChar
*filename
= wxT("welcome.msg");
2377 static const wxChar
*directory
= wxT("/etc");
2378 static const wxChar
*filename
= wxT("issue");
2381 static bool TestFtpConnect()
2383 wxPuts(wxT("*** Testing FTP connect ***"));
2385 #ifdef FTP_ANONYMOUS
2386 static const wxChar
*hostname
= wxT("ftp.wxwidgets.org");
2388 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2389 #else // !FTP_ANONYMOUS
2390 static const wxChar
*hostname
= "localhost";
2393 wxFgets(user
, WXSIZEOF(user
), stdin
);
2394 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2397 wxChar password
[256];
2398 wxPrintf(wxT("Password for %s: "), password
);
2399 wxFgets(password
, WXSIZEOF(password
), stdin
);
2400 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2401 ftp
->SetPassword(password
);
2403 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2404 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2406 if ( !ftp
->Connect(hostname
) )
2408 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname
);
2414 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
2415 hostname
, ftp
->Pwd().c_str());
2422 static void TestFtpList()
2424 wxPuts(wxT("*** Testing wxFTP file listing ***\n"));
2427 if ( !ftp
->ChDir(directory
) )
2429 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory
);
2432 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2434 // test NLIST and LIST
2435 wxArrayString files
;
2436 if ( !ftp
->GetFilesList(files
) )
2438 wxPuts(wxT("ERROR: failed to get NLIST of files"));
2442 wxPrintf(wxT("Brief list of files under '%s':\n"), ftp
->Pwd().c_str());
2443 size_t count
= files
.GetCount();
2444 for ( size_t n
= 0; n
< count
; n
++ )
2446 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2448 wxPuts(wxT("End of the file list"));
2451 if ( !ftp
->GetDirList(files
) )
2453 wxPuts(wxT("ERROR: failed to get LIST of files"));
2457 wxPrintf(wxT("Detailed list of files under '%s':\n"), ftp
->Pwd().c_str());
2458 size_t count
= files
.GetCount();
2459 for ( size_t n
= 0; n
< count
; n
++ )
2461 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2463 wxPuts(wxT("End of the file list"));
2466 if ( !ftp
->ChDir(wxT("..")) )
2468 wxPuts(wxT("ERROR: failed to cd to .."));
2471 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2474 static void TestFtpDownload()
2476 wxPuts(wxT("*** Testing wxFTP download ***\n"));
2479 wxInputStream
*in
= ftp
->GetInputStream(filename
);
2482 wxPrintf(wxT("ERROR: couldn't get input stream for %s\n"), filename
);
2486 size_t size
= in
->GetSize();
2487 wxPrintf(wxT("Reading file %s (%u bytes)..."), filename
, size
);
2490 wxChar
*data
= new wxChar
[size
];
2491 if ( !in
->Read(data
, size
) )
2493 wxPuts(wxT("ERROR: read error"));
2497 wxPrintf(wxT("\nContents of %s:\n%s\n"), filename
, data
);
2505 static void TestFtpFileSize()
2507 wxPuts(wxT("*** Testing FTP SIZE command ***"));
2509 if ( !ftp
->ChDir(directory
) )
2511 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory
);
2514 wxPrintf(wxT("Current directory is '%s'\n"), ftp
->Pwd().c_str());
2516 if ( ftp
->FileExists(filename
) )
2518 int size
= ftp
->GetFileSize(filename
);
2520 wxPrintf(wxT("ERROR: couldn't get size of '%s'\n"), filename
);
2522 wxPrintf(wxT("Size of '%s' is %d bytes.\n"), filename
, size
);
2526 wxPrintf(wxT("ERROR: '%s' doesn't exist\n"), filename
);
2530 static void TestFtpMisc()
2532 wxPuts(wxT("*** Testing miscellaneous wxFTP functions ***"));
2534 if ( ftp
->SendCommand(wxT("STAT")) != '2' )
2536 wxPuts(wxT("ERROR: STAT failed"));
2540 wxPrintf(wxT("STAT returned:\n\n%s\n"), ftp
->GetLastResult().c_str());
2543 if ( ftp
->SendCommand(wxT("HELP SITE")) != '2' )
2545 wxPuts(wxT("ERROR: HELP SITE failed"));
2549 wxPrintf(wxT("The list of site-specific commands:\n\n%s\n"),
2550 ftp
->GetLastResult().c_str());
2554 #if TEST_INTERACTIVE
2556 static void TestFtpInteractive()
2558 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
2564 wxPrintf(wxT("Enter FTP command: "));
2565 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2568 // kill the last '\n'
2569 buf
[wxStrlen(buf
) - 1] = 0;
2571 // special handling of LIST and NLST as they require data connection
2572 wxString
start(buf
, 4);
2574 if ( start
== wxT("LIST") || start
== wxT("NLST") )
2577 if ( wxStrlen(buf
) > 4 )
2580 wxArrayString files
;
2581 if ( !ftp
->GetList(files
, wildcard
, start
== wxT("LIST")) )
2583 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start
.c_str());
2587 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2588 start
.c_str(), wildcard
.c_str(), ftp
->Pwd().c_str());
2589 size_t count
= files
.GetCount();
2590 for ( size_t n
= 0; n
< count
; n
++ )
2592 wxPrintf(wxT("\t%s\n"), files
[n
].c_str());
2594 wxPuts(wxT("--- End of the file list"));
2599 wxChar ch
= ftp
->SendCommand(buf
);
2600 wxPrintf(wxT("Command %s"), ch
? wxT("succeeded") : wxT("failed"));
2603 wxPrintf(wxT(" (return code %c)"), ch
);
2606 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp
->GetLastResult().c_str());
2610 wxPuts(wxT("\n*** done ***"));
2613 #endif // TEST_INTERACTIVE
2615 static void TestFtpUpload()
2617 wxPuts(wxT("*** Testing wxFTP uploading ***\n"));
2620 static const wxChar
*file1
= wxT("test1");
2621 static const wxChar
*file2
= wxT("test2");
2622 wxOutputStream
*out
= ftp
->GetOutputStream(file1
);
2625 wxPrintf(wxT("--- Uploading to %s ---\n"), file1
);
2626 out
->Write("First hello", 11);
2630 // send a command to check the remote file
2631 if ( ftp
->SendCommand(wxString(wxT("STAT ")) + file1
) != '2' )
2633 wxPrintf(wxT("ERROR: STAT %s failed\n"), file1
);
2637 wxPrintf(wxT("STAT %s returned:\n\n%s\n"),
2638 file1
, ftp
->GetLastResult().c_str());
2641 out
= ftp
->GetOutputStream(file2
);
2644 wxPrintf(wxT("--- Uploading to %s ---\n"), file1
);
2645 out
->Write("Second hello", 12);
2652 // ----------------------------------------------------------------------------
2654 // ----------------------------------------------------------------------------
2656 #ifdef TEST_STACKWALKER
2658 #if wxUSE_STACKWALKER
2660 #include "wx/stackwalk.h"
2662 class StackDump
: public wxStackWalker
2665 StackDump(const char *argv0
)
2666 : wxStackWalker(argv0
)
2670 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
2672 wxPuts(wxT("Stack dump:"));
2674 wxStackWalker::Walk(skip
, maxdepth
);
2678 virtual void OnStackFrame(const wxStackFrame
& frame
)
2680 printf("[%2d] ", (int) frame
.GetLevel());
2682 wxString name
= frame
.GetName();
2683 if ( !name
.empty() )
2685 printf("%-20.40s", (const char*)name
.mb_str());
2689 printf("0x%08lx", (unsigned long)frame
.GetAddress());
2692 if ( frame
.HasSourceLocation() )
2695 (const char*)frame
.GetFileName().mb_str(),
2696 (int)frame
.GetLine());
2702 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
2704 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
2705 (const char*)name
.mb_str(),
2706 (const char*)val
.mb_str());
2711 static void TestStackWalk(const char *argv0
)
2713 wxPuts(wxT("*** Testing wxStackWalker ***\n"));
2715 StackDump
dump(argv0
);
2719 #endif // wxUSE_STACKWALKER
2721 #endif // TEST_STACKWALKER
2723 // ----------------------------------------------------------------------------
2725 // ----------------------------------------------------------------------------
2727 #ifdef TEST_STDPATHS
2729 #include "wx/stdpaths.h"
2730 #include "wx/wxchar.h" // wxPrintf
2732 static void TestStandardPaths()
2734 wxPuts(wxT("*** Testing wxStandardPaths ***\n"));
2736 wxTheApp
->SetAppName(wxT("console"));
2738 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
2739 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
2740 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
2741 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
2742 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
2743 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
2744 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
2745 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
2746 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
2747 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
2748 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
2749 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2750 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
2751 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2752 stdp
.GetLocalizedResourcesDir
2755 wxStandardPaths::ResourceCat_Messages
2759 #endif // TEST_STDPATHS
2761 // ----------------------------------------------------------------------------
2763 // ----------------------------------------------------------------------------
2767 #include "wx/wfstream.h"
2768 #include "wx/mstream.h"
2770 static void TestFileStream()
2772 wxPuts(wxT("*** Testing wxFileInputStream ***"));
2774 static const wxString filename
= wxT("testdata.fs");
2776 wxFileOutputStream
fsOut(filename
);
2777 fsOut
.Write("foo", 3);
2781 wxFileInputStream
fsIn(filename
);
2782 wxPrintf(wxT("File stream size: %u\n"), fsIn
.GetSize());
2784 while ( (c
=fsIn
.GetC()) != wxEOF
)
2790 if ( !wxRemoveFile(filename
) )
2792 wxPrintf(wxT("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
2795 wxPuts(wxT("\n*** wxFileInputStream test done ***"));
2798 static void TestMemoryStream()
2800 wxPuts(wxT("*** Testing wxMemoryOutputStream ***"));
2802 wxMemoryOutputStream memOutStream
;
2803 wxPrintf(wxT("Initially out stream offset: %lu\n"),
2804 (unsigned long)memOutStream
.TellO());
2806 for ( const wxChar
*p
= wxT("Hello, stream!"); *p
; p
++ )
2808 memOutStream
.PutC(*p
);
2811 wxPrintf(wxT("Final out stream offset: %lu\n"),
2812 (unsigned long)memOutStream
.TellO());
2814 wxPuts(wxT("*** Testing wxMemoryInputStream ***"));
2817 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
2819 wxMemoryInputStream
memInpStream(buf
, len
);
2820 wxPrintf(wxT("Memory stream size: %u\n"), memInpStream
.GetSize());
2822 while ( (c
=memInpStream
.GetC()) != wxEOF
)
2827 wxPuts(wxT("\n*** wxMemoryInputStream test done ***"));
2830 #endif // TEST_STREAMS
2832 // ----------------------------------------------------------------------------
2834 // ----------------------------------------------------------------------------
2838 #include "wx/stopwatch.h"
2839 #include "wx/utils.h"
2841 static void TestStopWatch()
2843 wxPuts(wxT("*** Testing wxStopWatch ***\n"));
2847 wxPrintf(wxT("Initially paused, after 2 seconds time is..."));
2850 wxPrintf(wxT("\t%ldms\n"), sw
.Time());
2852 wxPrintf(wxT("Resuming stopwatch and sleeping 3 seconds..."));
2856 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2859 wxPrintf(wxT("Pausing agan and sleeping 2 more seconds..."));
2862 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2865 wxPrintf(wxT("Finally resuming and sleeping 2 more seconds..."));
2868 wxPrintf(wxT("\telapsed time: %ldms\n"), sw
.Time());
2871 wxPuts(wxT("\nChecking for 'backwards clock' bug..."));
2872 for ( size_t n
= 0; n
< 70; n
++ )
2876 for ( size_t m
= 0; m
< 100000; m
++ )
2878 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2880 wxPuts(wxT("\ntime is negative - ERROR!"));
2888 wxPuts(wxT(", ok."));
2891 #include "wx/timer.h"
2892 #include "wx/evtloop.h"
2896 wxPuts(wxT("*** Testing wxTimer ***\n"));
2898 class MyTimer
: public wxTimer
2901 MyTimer() : wxTimer() { m_num
= 0; }
2903 virtual void Notify()
2905 wxPrintf(wxT("%d"), m_num
++);
2910 wxPrintf(wxT("... exiting the event loop"));
2913 wxEventLoop::GetActive()->Exit(0);
2914 wxPuts(wxT(", ok."));
2927 timer1
.Start(100, true /* one shot */);
2929 timer1
.Start(100, true /* one shot */);
2937 #endif // TEST_TIMER
2939 // ----------------------------------------------------------------------------
2941 // ----------------------------------------------------------------------------
2943 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2949 #include "wx/volume.h"
2951 static const wxChar
*volumeKinds
[] =
2957 wxT("network volume"),
2958 wxT("other volume"),
2961 static void TestFSVolume()
2963 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2965 wxArrayString volumes
= wxFSVolume::GetVolumes();
2966 size_t count
= volumes
.GetCount();
2970 wxPuts(wxT("ERROR: no mounted volumes?"));
2974 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
2976 for ( size_t n
= 0; n
< count
; n
++ )
2978 wxFSVolume
vol(volumes
[n
]);
2981 wxPuts(wxT("ERROR: couldn't create volume"));
2985 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2987 vol
.GetDisplayName().c_str(),
2988 vol
.GetName().c_str(),
2989 volumeKinds
[vol
.GetKind()],
2990 vol
.IsWritable() ? wxT("rw") : wxT("ro"),
2991 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? wxT("removable")
2996 #endif // TEST_VOLUME
2998 // ----------------------------------------------------------------------------
2999 // wide char and Unicode support
3000 // ----------------------------------------------------------------------------
3004 #include "wx/strconv.h"
3005 #include "wx/fontenc.h"
3006 #include "wx/encconv.h"
3007 #include "wx/buffer.h"
3009 static const unsigned char utf8koi8r
[] =
3011 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3012 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3013 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3014 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3015 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3016 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3017 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3020 static const unsigned char utf8iso8859_1
[] =
3022 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3023 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3024 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3025 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3026 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3029 static const unsigned char utf8Invalid
[] =
3031 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3032 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3033 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3034 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3038 static const struct Utf8Data
3040 const unsigned char *text
;
3042 const wxChar
*charset
;
3043 wxFontEncoding encoding
;
3046 { utf8Invalid
, WXSIZEOF(utf8Invalid
), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3047 { utf8koi8r
, WXSIZEOF(utf8koi8r
), wxT("koi8-r"), wxFONTENCODING_KOI8
},
3048 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3051 static void TestUtf8()
3053 wxPuts(wxT("*** Testing UTF8 support ***\n"));
3058 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3060 const Utf8Data
& u8d
= utf8data
[n
];
3061 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3062 WXSIZEOF(wbuf
)) == (size_t)-1 )
3064 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3068 wxCSConv
conv(u8d
.charset
);
3069 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3071 wxPrintf(wxT("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3075 wxPrintf(wxT("String in %s: %s\n"), u8d
.charset
, buf
);
3079 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3081 s
= wxT("<< conversion failed >>");
3082 wxPrintf(wxT("String in current cset: %s\n"), s
.c_str());
3086 wxPuts(wxEmptyString
);
3089 static void TestEncodingConverter()
3091 wxPuts(wxT("*** Testing wxEncodingConverter ***\n"));
3093 // using wxEncodingConverter should give the same result as above
3096 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3097 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3099 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3103 wxEncodingConverter ec
;
3104 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3105 ec
.Convert(wbuf
, buf
);
3106 wxPrintf(wxT("The same KOI8-R string using wxEC: %s\n"), buf
);
3109 wxPuts(wxEmptyString
);
3112 #endif // TEST_WCHAR
3114 // ----------------------------------------------------------------------------
3116 // ----------------------------------------------------------------------------
3120 #include "wx/filesys.h"
3121 #include "wx/fs_zip.h"
3122 #include "wx/zipstrm.h"
3124 static const wxChar
*TESTFILE_ZIP
= wxT("testdata.zip");
3126 static void TestZipStreamRead()
3128 wxPuts(wxT("*** Testing ZIP reading ***\n"));
3130 static const wxString filename
= wxT("foo");
3131 wxFFileInputStream
in(TESTFILE_ZIP
);
3132 wxZipInputStream
istr(in
);
3133 wxZipEntry
entry(filename
);
3134 istr
.OpenEntry(entry
);
3136 wxPrintf(wxT("Archive size: %u\n"), istr
.GetSize());
3138 wxPrintf(wxT("Dumping the file '%s':\n"), filename
.c_str());
3140 while ( (c
=istr
.GetC()) != wxEOF
)
3146 wxPuts(wxT("\n----- done ------"));
3149 static void DumpZipDirectory(wxFileSystem
& fs
,
3150 const wxString
& dir
,
3151 const wxString
& indent
)
3153 wxString prefix
= wxString::Format(wxT("%s#zip:%s"),
3154 TESTFILE_ZIP
, dir
.c_str());
3155 wxString wildcard
= prefix
+ wxT("/*");
3157 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3158 while ( !dirname
.empty() )
3160 if ( !dirname
.StartsWith(prefix
+ wxT('/'), &dirname
) )
3162 wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
3167 wxPrintf(wxT("%s%s\n"), indent
.c_str(), dirname
.c_str());
3169 DumpZipDirectory(fs
, dirname
,
3170 indent
+ wxString(wxT(' '), 4));
3172 dirname
= fs
.FindNext();
3175 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3176 while ( !filename
.empty() )
3178 if ( !filename
.StartsWith(prefix
, &filename
) )
3180 wxPrintf(wxT("ERROR: unexpected wxFileSystem::FindNext result\n"));
3185 wxPrintf(wxT("%s%s\n"), indent
.c_str(), filename
.c_str());
3187 filename
= fs
.FindNext();
3191 static void TestZipFileSystem()
3193 wxPuts(wxT("*** Testing ZIP file system ***\n"));
3195 wxFileSystem::AddHandler(new wxZipFSHandler
);
3197 wxPrintf(wxT("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3199 DumpZipDirectory(fs
, wxT(""), wxString(wxT(' '), 4));
3204 // ----------------------------------------------------------------------------
3206 // ----------------------------------------------------------------------------
3208 #ifdef TEST_DATETIME
3210 #include "wx/math.h"
3211 #include "wx/datetime.h"
3213 // this test miscellaneous static wxDateTime functions
3217 static void TestTimeStatic()
3219 wxPuts(wxT("\n*** wxDateTime static methods test ***"));
3221 // some info about the current date
3222 int year
= wxDateTime::GetCurrentYear();
3223 wxPrintf(wxT("Current year %d is %sa leap one and has %d days.\n"),
3225 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3226 wxDateTime::GetNumberOfDays(year
));
3228 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3229 wxPrintf(wxT("Current month is '%s' ('%s') and it has %d days\n"),
3230 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3231 wxDateTime::GetMonthName(month
).c_str(),
3232 wxDateTime::GetNumberOfDays(month
));
3235 // test time zones stuff
3236 static void TestTimeZones()
3238 wxPuts(wxT("\n*** wxDateTime timezone test ***"));
3240 wxDateTime now
= wxDateTime::Now();
3242 wxPrintf(wxT("Current GMT time:\t%s\n"), now
.Format(wxT("%c"), wxDateTime::GMT0
).c_str());
3243 wxPrintf(wxT("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime::GMT0
).c_str());
3244 wxPrintf(wxT("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(wxT("%c"), wxDateTime::EST
).c_str());
3245 wxPrintf(wxT("Current time in Paris:\t%s\n"), now
.Format(wxT("%c"), wxDateTime::CET
).c_str());
3246 wxPrintf(wxT(" Moscow:\t%s\n"), now
.Format(wxT("%c"), wxDateTime::MSK
).c_str());
3247 wxPrintf(wxT(" New York:\t%s\n"), now
.Format(wxT("%c"), wxDateTime::EST
).c_str());
3249 wxPrintf(wxT("%s\n"), wxDateTime::Now().Format(wxT("Our timezone is %Z")).c_str());
3251 wxDateTime::Tm tm
= now
.GetTm();
3252 if ( wxDateTime(tm
) != now
)
3254 wxPrintf(wxT("ERROR: got %s instead of %s\n"),
3255 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3259 // test some minimal support for the dates outside the standard range
3260 static void TestTimeRange()
3262 wxPuts(wxT("\n*** wxDateTime out-of-standard-range dates test ***"));
3264 static const wxChar
*fmt
= wxT("%d-%b-%Y %H:%M:%S");
3266 wxPrintf(wxT("Unix epoch:\t%s\n"),
3267 wxDateTime(2440587.5).Format(fmt
).c_str());
3268 wxPrintf(wxT("Feb 29, 0: \t%s\n"),
3269 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3270 wxPrintf(wxT("JDN 0: \t%s\n"),
3271 wxDateTime(0.0).Format(fmt
).c_str());
3272 wxPrintf(wxT("Jan 1, 1AD:\t%s\n"),
3273 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3274 wxPrintf(wxT("May 29, 2099:\t%s\n"),
3275 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3278 // test DST calculations
3279 static void TestTimeDST()
3281 wxPuts(wxT("\n*** wxDateTime DST test ***"));
3283 wxPrintf(wxT("DST is%s in effect now.\n\n"),
3284 wxDateTime::Now().IsDST() ? wxEmptyString
: wxT(" not"));
3286 for ( int year
= 1990; year
< 2005; year
++ )
3288 wxPrintf(wxT("DST period in Europe for year %d: from %s to %s\n"),
3290 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3291 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3297 #if TEST_INTERACTIVE
3299 static void TestDateTimeInteractive()
3301 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
3307 wxPrintf(wxT("Enter a date: "));
3308 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3311 // kill the last '\n'
3312 buf
[wxStrlen(buf
) - 1] = 0;
3315 const wxChar
*p
= dt
.ParseDate(buf
);
3318 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf
);
3324 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p
- buf
);
3327 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
3328 dt
.Format(wxT("%b %d, %Y")).c_str(),
3330 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3331 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3332 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3335 wxPuts(wxT("\n*** done ***"));
3338 #endif // TEST_INTERACTIVE
3342 static void TestTimeMS()
3344 wxPuts(wxT("*** testing millisecond-resolution support in wxDateTime ***"));
3346 wxDateTime dt1
= wxDateTime::Now(),
3347 dt2
= wxDateTime::UNow();
3349 wxPrintf(wxT("Now = %s\n"), dt1
.Format(wxT("%H:%M:%S:%l")).c_str());
3350 wxPrintf(wxT("UNow = %s\n"), dt2
.Format(wxT("%H:%M:%S:%l")).c_str());
3351 wxPrintf(wxT("Dummy loop: "));
3352 for ( int i
= 0; i
< 6000; i
++ )
3354 //for ( int j = 0; j < 10; j++ )
3357 s
.Printf(wxT("%g"), sqrt((float)i
));
3363 wxPuts(wxT(", done"));
3366 dt2
= wxDateTime::UNow();
3367 wxPrintf(wxT("UNow = %s\n"), dt2
.Format(wxT("%H:%M:%S:%l")).c_str());
3369 wxPrintf(wxT("Loop executed in %s ms\n"), (dt2
- dt1
).Format(wxT("%l")).c_str());
3371 wxPuts(wxT("\n*** done ***"));
3374 static void TestTimeHolidays()
3376 wxPuts(wxT("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3378 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3379 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3380 dtEnd
= dtStart
.GetLastMonthDay();
3382 wxDateTimeArray hol
;
3383 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3385 const wxChar
*format
= wxT("%d-%b-%Y (%a)");
3387 wxPrintf(wxT("All holidays between %s and %s:\n"),
3388 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3390 size_t count
= hol
.GetCount();
3391 for ( size_t n
= 0; n
< count
; n
++ )
3393 wxPrintf(wxT("\t%s\n"), hol
[n
].Format(format
).c_str());
3396 wxPuts(wxEmptyString
);
3399 static void TestTimeZoneBug()
3401 wxPuts(wxT("\n*** testing for DST/timezone bug ***\n"));
3403 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3404 for ( int i
= 0; i
< 31; i
++ )
3406 wxPrintf(wxT("Date %s: week day %s.\n"),
3407 date
.Format(wxT("%d-%m-%Y")).c_str(),
3408 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3410 date
+= wxDateSpan::Day();
3413 wxPuts(wxEmptyString
);
3416 static void TestTimeSpanFormat()
3418 wxPuts(wxT("\n*** wxTimeSpan tests ***"));
3420 static const wxChar
*formats
[] =
3422 wxT("(default) %H:%M:%S"),
3423 wxT("%E weeks and %D days"),
3424 wxT("%l milliseconds"),
3425 wxT("(with ms) %H:%M:%S:%l"),
3426 wxT("100%% of minutes is %M"), // test "%%"
3427 wxT("%D days and %H hours"),
3428 wxT("or also %S seconds"),
3431 wxTimeSpan
ts1(1, 2, 3, 4),
3433 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3435 wxPrintf(wxT("ts1 = %s\tts2 = %s\n"),
3436 ts1
.Format(formats
[n
]).c_str(),
3437 ts2
.Format(formats
[n
]).c_str());
3440 wxPuts(wxEmptyString
);
3445 #endif // TEST_DATETIME
3448 // ----------------------------------------------------------------------------
3450 // ----------------------------------------------------------------------------
3452 #ifdef TEST_SNGLINST
3453 #include "wx/snglinst.h"
3454 #endif // TEST_SNGLINST
3456 int main(int argc
, char **argv
)
3459 wxChar
**wxArgv
= new wxChar
*[argc
+ 1];
3464 for (n
= 0; n
< argc
; n
++ )
3466 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
3467 wxArgv
[n
] = wxStrdup(warg
);
3472 #else // !wxUSE_UNICODE
3474 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
3476 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
3478 wxInitializer initializer
;
3481 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
3486 #ifdef TEST_SNGLINST
3487 wxSingleInstanceChecker checker
;
3488 if ( checker
.Create(wxT(".wxconsole.lock")) )
3490 if ( checker
.IsAnotherRunning() )
3492 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
3497 // wait some time to give time to launch another instance
3498 wxPrintf(wxT("Press \"Enter\" to continue..."));
3501 else // failed to create
3503 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
3505 #endif // TEST_SNGLINST
3508 TestCmdLineConvert();
3510 #if wxUSE_CMDLINE_PARSER
3511 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3513 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
3514 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
3515 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3516 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3518 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3519 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3520 { wxCMD_LINE_OPTION
, "s", "size", "output block size",
3521 wxCMD_LINE_VAL_NUMBER
},
3522 { wxCMD_LINE_OPTION
, "d", "date", "output file date",
3523 wxCMD_LINE_VAL_DATE
},
3524 { wxCMD_LINE_OPTION
, "f", "double", "output double",
3525 wxCMD_LINE_VAL_DOUBLE
},
3527 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3528 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3533 wxCmdLineParser
parser(cmdLineDesc
, argc
, wxArgv
);
3535 parser
.AddOption(wxT("project_name"), wxT(""), wxT("full path to project file"),
3536 wxCMD_LINE_VAL_STRING
,
3537 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3539 switch ( parser
.Parse() )
3542 wxLogMessage(wxT("Help was given, terminating."));
3546 ShowCmdLine(parser
);
3550 wxLogMessage(wxT("Syntax error detected, aborting."));
3553 #endif // wxUSE_CMDLINE_PARSER
3555 #endif // TEST_CMDLINE
3567 TestDllListLoaded();
3568 #endif // TEST_DYNLIB
3572 #endif // TEST_ENVIRON
3574 #ifdef TEST_FILECONF
3576 #endif // TEST_FILECONF
3580 #endif // TEST_LOCALE
3583 wxPuts(wxT("*** Testing wxLog ***"));
3586 for ( size_t n
= 0; n
< 8000; n
++ )
3588 s
<< (wxChar
)(wxT('A') + (n
% 26));
3591 wxLogWarning(wxT("The length of the string is %lu"),
3592 (unsigned long)s
.length());
3595 msg
.Printf(wxT("A very very long message: '%s', the end!\n"), s
.c_str());
3597 // this one shouldn't be truncated
3600 // but this one will because log functions use fixed size buffer
3601 // (note that it doesn't need '\n' at the end neither - will be added
3603 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s
.c_str());
3613 #ifdef TEST_FILENAME
3616 TestFileNameDirManip();
3617 TestFileNameComparison();
3618 TestFileNameOperations();
3619 #endif // TEST_FILENAME
3621 #ifdef TEST_FILETIME
3626 #endif // TEST_FILETIME
3629 wxLog::AddTraceMask(FTP_TRACE_MASK
);
3631 // wxFTP cannot be a static variable as its ctor needs to access
3632 // wxWidgets internals after it has been initialized
3634 ftp
->SetLog(new wxProtocolLog(FTP_TRACE_MASK
));
3636 if ( TestFtpConnect() )
3646 #if TEST_INTERACTIVE
3647 //TestFtpInteractive();
3650 //else: connecting to the FTP server failed
3656 //wxLog::AddTraceMask(wxT("mime"));
3660 TestMimeAssociate();
3665 #ifdef TEST_INFO_FUNCTIONS
3670 #if TEST_INTERACTIVE
3673 #endif // TEST_INFO_FUNCTIONS
3675 #ifdef TEST_PATHLIST
3677 #endif // TEST_PATHLIST
3681 #endif // TEST_PRINTF
3688 #endif // TEST_REGCONF
3690 #if defined TEST_REGEX && TEST_INTERACTIVE
3691 TestRegExInteractive();
3692 #endif // defined TEST_REGEX && TEST_INTERACTIVE
3694 #ifdef TEST_REGISTRY
3696 TestRegistryAssociation();
3697 #endif // TEST_REGISTRY
3702 #endif // TEST_SOCKETS
3709 #endif // TEST_STREAMS
3714 #endif // TEST_TIMER
3716 #ifdef TEST_DATETIME
3723 TestTimeSpanFormat();
3729 #if TEST_INTERACTIVE
3730 TestDateTimeInteractive();
3732 #endif // TEST_DATETIME
3734 #ifdef TEST_SCOPEGUARD
3738 #ifdef TEST_STACKWALKER
3739 #if wxUSE_STACKWALKER
3740 TestStackWalk(argv
[0]);
3742 #endif // TEST_STACKWALKER
3744 #ifdef TEST_STDPATHS
3745 TestStandardPaths();
3749 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
3751 #endif // TEST_USLEEP
3755 #endif // TEST_VOLUME
3759 TestEncodingConverter();
3760 #endif // TEST_WCHAR
3763 TestZipStreamRead();
3764 TestZipFileSystem();
3769 for ( int n
= 0; n
< argc
; n
++ )
3774 #endif // wxUSE_UNICODE