1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
23 #error "This sample can't be compiled in GUI mode."
28 #include <wx/string.h>
32 // without this pragma, the stupid compiler precompiles #defines below so that
33 // changing them doesn't "take place" later!
38 // ----------------------------------------------------------------------------
39 // conditional compilation
40 // ----------------------------------------------------------------------------
42 // what to test (in alphabetic order)?
45 //#define TEST_CHARSET
46 //#define TEST_CMDLINE
47 //#define TEST_DATETIME
49 //#define TEST_DLLLOADER
50 //#define TEST_ENVIRON
51 //#define TEST_EXECUTE
53 //#define TEST_FILECONF
54 //#define TEST_FILENAME
57 //#define TEST_INFO_FUNCTIONS
61 //#define TEST_LONGLONG
63 //#define TEST_PATHLIST
64 //#define TEST_REGCONF
65 //#define TEST_REGISTRY
66 //#define TEST_SNGLINST
67 //#define TEST_SOCKETS
68 //#define TEST_STREAMS
70 //#define TEST_THREADS
72 //#define TEST_VCARD -- don't enable this (VZ)
78 #include <wx/snglinst.h>
79 #endif // TEST_SNGLINST
81 // ----------------------------------------------------------------------------
82 // test class for container objects
83 // ----------------------------------------------------------------------------
85 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
87 class Bar
// Foo is already taken in the hash test
90 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
93 static size_t GetNumber() { return ms_bars
; }
95 const char *GetName() const { return m_name
; }
100 static size_t ms_bars
;
103 size_t Bar::ms_bars
= 0;
105 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
107 // ============================================================================
109 // ============================================================================
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
117 // replace TABs with \t and CRs with \n
118 static wxString
MakePrintable(const wxChar
*s
)
121 (void)str
.Replace(_T("\t"), _T("\\t"));
122 (void)str
.Replace(_T("\n"), _T("\\n"));
123 (void)str
.Replace(_T("\r"), _T("\\r"));
128 #endif // MakePrintable() is used
130 // ----------------------------------------------------------------------------
131 // wxFontMapper::CharsetToEncoding
132 // ----------------------------------------------------------------------------
136 #include <wx/fontmap.h>
138 static void TestCharset()
140 static const wxChar
*charsets
[] =
142 // some vali charsets
151 // and now some bogus ones
158 for ( size_t n
= 0; n
< WXSIZEOF(charsets
); n
++ )
160 wxFontEncoding enc
= wxTheFontMapper
->CharsetToEncoding(charsets
[n
]);
161 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
163 wxTheFontMapper
->GetEncodingName(enc
).c_str(),
164 wxTheFontMapper
->GetEncodingDescription(enc
).c_str());
168 #endif // TEST_CHARSET
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
176 #include <wx/cmdline.h>
177 #include <wx/datetime.h>
179 static void ShowCmdLine(const wxCmdLineParser
& parser
)
181 wxString s
= "Input files: ";
183 size_t count
= parser
.GetParamCount();
184 for ( size_t param
= 0; param
< count
; param
++ )
186 s
<< parser
.GetParam(param
) << ' ';
190 << "Verbose:\t" << (parser
.Found("v") ? "yes" : "no") << '\n'
191 << "Quiet:\t" << (parser
.Found("q") ? "yes" : "no") << '\n';
196 if ( parser
.Found("o", &strVal
) )
197 s
<< "Output file:\t" << strVal
<< '\n';
198 if ( parser
.Found("i", &strVal
) )
199 s
<< "Input dir:\t" << strVal
<< '\n';
200 if ( parser
.Found("s", &lVal
) )
201 s
<< "Size:\t" << lVal
<< '\n';
202 if ( parser
.Found("d", &dt
) )
203 s
<< "Date:\t" << dt
.FormatISODate() << '\n';
204 if ( parser
.Found("project_name", &strVal
) )
205 s
<< "Project:\t" << strVal
<< '\n';
210 #endif // TEST_CMDLINE
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
221 static const wxChar
*ROOTDIR
= _T("/");
222 static const wxChar
*TESTDIR
= _T("/usr");
223 #elif defined(__WXMSW__)
224 static const wxChar
*ROOTDIR
= _T("c:\\");
225 static const wxChar
*TESTDIR
= _T("d:\\");
227 #error "don't know where the root directory is"
230 static void TestDirEnumHelper(wxDir
& dir
,
231 int flags
= wxDIR_DEFAULT
,
232 const wxString
& filespec
= wxEmptyString
)
236 if ( !dir
.IsOpened() )
239 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
242 printf("\t%s\n", filename
.c_str());
244 cont
= dir
.GetNext(&filename
);
250 static void TestDirEnum()
252 puts("*** Testing wxDir::GetFirst/GetNext ***");
254 wxDir
dir(wxGetCwd());
256 puts("Enumerating everything in current directory:");
257 TestDirEnumHelper(dir
);
259 puts("Enumerating really everything in current directory:");
260 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
262 puts("Enumerating object files in current directory:");
263 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o");
265 puts("Enumerating directories in current directory:");
266 TestDirEnumHelper(dir
, wxDIR_DIRS
);
268 puts("Enumerating files in current directory:");
269 TestDirEnumHelper(dir
, wxDIR_FILES
);
271 puts("Enumerating files including hidden in current directory:");
272 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
276 puts("Enumerating everything in root directory:");
277 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
279 puts("Enumerating directories in root directory:");
280 TestDirEnumHelper(dir
, wxDIR_DIRS
);
282 puts("Enumerating files in root directory:");
283 TestDirEnumHelper(dir
, wxDIR_FILES
);
285 puts("Enumerating files including hidden in root directory:");
286 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
288 puts("Enumerating files in non existing directory:");
289 wxDir
dirNo("nosuchdir");
290 TestDirEnumHelper(dirNo
);
293 class DirPrintTraverser
: public wxDirTraverser
296 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
298 return wxDIR_CONTINUE
;
301 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
303 wxString path
, name
, ext
;
304 wxSplitPath(dirname
, &path
, &name
, &ext
);
307 name
<< _T('.') << ext
;
310 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
312 if ( wxIsPathSeparator(*p
) )
316 printf("%s%s\n", indent
.c_str(), name
.c_str());
318 return wxDIR_CONTINUE
;
322 static void TestDirTraverse()
324 puts("*** Testing wxDir::Traverse() ***");
328 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
329 printf("There are %u files under '%s'\n", n
, TESTDIR
);
332 printf("First one is '%s'\n", files
[0u].c_str());
333 printf(" last one is '%s'\n", files
[n
- 1].c_str());
336 // enum again with custom traverser
338 DirPrintTraverser traverser
;
339 dir
.Traverse(traverser
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
344 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
348 #ifdef TEST_DLLLOADER
350 #include <wx/dynlib.h>
352 static void TestDllLoad()
354 #if defined(__WXMSW__)
355 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
356 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
357 #elif defined(__UNIX__)
358 // weird: using just libc.so does *not* work!
359 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
360 static const wxChar
*FUNC_NAME
= _T("strlen");
362 #error "don't know how to test wxDllLoader on this platform"
365 puts("*** testing wxDllLoader ***\n");
367 wxDllType dllHandle
= wxDllLoader::LoadLibrary(LIB_NAME
);
370 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
374 typedef int (*strlenType
)(char *);
375 strlenType pfnStrlen
= (strlenType
)wxDllLoader::GetSymbol(dllHandle
, FUNC_NAME
);
378 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
379 FUNC_NAME
, LIB_NAME
);
383 if ( pfnStrlen("foo") != 3 )
385 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
393 wxDllLoader::UnloadLibrary(dllHandle
);
397 #endif // TEST_DLLLOADER
399 // ----------------------------------------------------------------------------
401 // ----------------------------------------------------------------------------
405 #include <wx/utils.h>
407 static wxString
MyGetEnv(const wxString
& var
)
410 if ( !wxGetEnv(var
, &val
) )
413 val
= wxString(_T('\'')) + val
+ _T('\'');
418 static void TestEnvironment()
420 const wxChar
*var
= _T("wxTestVar");
422 puts("*** testing environment access functions ***");
424 printf("Initially getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
425 wxSetEnv(var
, _T("value for wxTestVar"));
426 printf("After wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
427 wxSetEnv(var
, _T("another value"));
428 printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
430 printf("After wxUnsetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
431 printf("PATH = %s\n", MyGetEnv(_T("PATH")).c_str());
434 #endif // TEST_ENVIRON
436 // ----------------------------------------------------------------------------
438 // ----------------------------------------------------------------------------
442 #include <wx/utils.h>
444 static void TestExecute()
446 puts("*** testing wxExecute ***");
449 #define COMMAND "cat -n ../../Makefile" // "echo hi"
450 #define SHELL_COMMAND "echo hi from shell"
451 #define REDIRECT_COMMAND COMMAND // "date"
452 #elif defined(__WXMSW__)
453 #define COMMAND "command.com -c 'echo hi'"
454 #define SHELL_COMMAND "echo hi"
455 #define REDIRECT_COMMAND COMMAND
457 #error "no command to exec"
460 printf("Testing wxShell: ");
462 if ( wxShell(SHELL_COMMAND
) )
467 printf("Testing wxExecute: ");
469 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
474 #if 0 // no, it doesn't work (yet?)
475 printf("Testing async wxExecute: ");
477 if ( wxExecute(COMMAND
) != 0 )
478 puts("Ok (command launched).");
483 printf("Testing wxExecute with redirection:\n");
484 wxArrayString output
;
485 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
491 size_t count
= output
.GetCount();
492 for ( size_t n
= 0; n
< count
; n
++ )
494 printf("\t%s\n", output
[n
].c_str());
501 #endif // TEST_EXECUTE
503 // ----------------------------------------------------------------------------
505 // ----------------------------------------------------------------------------
510 #include <wx/ffile.h>
511 #include <wx/textfile.h>
513 static void TestFileRead()
515 puts("*** wxFile read test ***");
517 wxFile
file(_T("testdata.fc"));
518 if ( file
.IsOpened() )
520 printf("File length: %lu\n", file
.Length());
522 puts("File dump:\n----------");
524 static const off_t len
= 1024;
528 off_t nRead
= file
.Read(buf
, len
);
529 if ( nRead
== wxInvalidOffset
)
531 printf("Failed to read the file.");
535 fwrite(buf
, nRead
, 1, stdout
);
545 printf("ERROR: can't open test file.\n");
551 static void TestTextFileRead()
553 puts("*** wxTextFile read test ***");
555 wxTextFile
file(_T("testdata.fc"));
558 printf("Number of lines: %u\n", file
.GetLineCount());
559 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
563 puts("\nDumping the entire file:");
564 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
566 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
568 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
570 puts("\nAnd now backwards:");
571 for ( s
= file
.GetLastLine();
572 file
.GetCurrentLine() != 0;
573 s
= file
.GetPrevLine() )
575 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
577 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
581 printf("ERROR: can't open '%s'\n", file
.GetName());
587 static void TestFileCopy()
589 puts("*** Testing wxCopyFile ***");
591 static const wxChar
*filename1
= _T("testdata.fc");
592 static const wxChar
*filename2
= _T("test2");
593 if ( !wxCopyFile(filename1
, filename2
) )
595 puts("ERROR: failed to copy file");
599 wxFFile
f1(filename1
, "rb"),
602 if ( !f1
.IsOpened() || !f2
.IsOpened() )
604 puts("ERROR: failed to open file(s)");
609 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
611 puts("ERROR: failed to read file(s)");
615 if ( (s1
.length() != s2
.length()) ||
616 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
618 puts("ERROR: copy error!");
622 puts("File was copied ok.");
628 if ( !wxRemoveFile(filename2
) )
630 puts("ERROR: failed to remove the file");
638 // ----------------------------------------------------------------------------
640 // ----------------------------------------------------------------------------
644 #include <wx/confbase.h>
645 #include <wx/fileconf.h>
647 static const struct FileConfTestData
649 const wxChar
*name
; // value name
650 const wxChar
*value
; // the value from the file
653 { _T("value1"), _T("one") },
654 { _T("value2"), _T("two") },
655 { _T("novalue"), _T("default") },
658 static void TestFileConfRead()
660 puts("*** testing wxFileConfig loading/reading ***");
662 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
663 _T("testdata.fc"), wxEmptyString
,
664 wxCONFIG_USE_RELATIVE_PATH
);
666 // test simple reading
667 puts("\nReading config file:");
668 wxString
defValue(_T("default")), value
;
669 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
671 const FileConfTestData
& data
= fcTestData
[n
];
672 value
= fileconf
.Read(data
.name
, defValue
);
673 printf("\t%s = %s ", data
.name
, value
.c_str());
674 if ( value
== data
.value
)
680 printf("(ERROR: should be %s)\n", data
.value
);
684 // test enumerating the entries
685 puts("\nEnumerating all root entries:");
688 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
691 printf("\t%s = %s\n",
693 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
695 cont
= fileconf
.GetNextEntry(name
, dummy
);
699 #endif // TEST_FILECONF
701 // ----------------------------------------------------------------------------
703 // ----------------------------------------------------------------------------
707 #include <wx/filename.h>
709 static struct FileNameInfo
711 const wxChar
*fullname
;
717 { _T("/usr/bin/ls"), _T("/usr/bin"), _T("ls"), _T("") },
718 { _T("/usr/bin/"), _T("/usr/bin"), _T(""), _T("") },
719 { _T("~/.zshrc"), _T("~"), _T(".zshrc"), _T("") },
720 { _T("../../foo"), _T("../.."), _T("foo"), _T("") },
721 { _T("foo.bar"), _T(""), _T("foo"), _T("bar") },
722 { _T("~/foo.bar"), _T("~"), _T("foo"), _T("bar") },
723 { _T("Mahogany-0.60/foo.bar"), _T("Mahogany-0.60"), _T("foo"), _T("bar") },
724 { _T("/tmp/wxwin.tar.bz"), _T("/tmp"), _T("wxwin.tar"), _T("bz") },
727 static void TestFileNameConstruction()
729 puts("*** testing wxFileName construction ***");
731 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
733 wxFileName
fn(filenames
[n
].fullname
, wxPATH_UNIX
);
735 printf("Filename: '%s'\t", fn
.GetFullPath().c_str());
736 if ( !fn
.Normalize(wxPATH_NORM_ALL
, _T(""), wxPATH_UNIX
) )
738 puts("ERROR (couldn't be normalized)");
742 printf("normalized: '%s'\n", fn
.GetFullPath().c_str());
749 static void TestFileNameSplit()
751 puts("*** testing wxFileName splitting ***");
753 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
755 const FileNameInfo
&fni
= filenames
[n
];
756 wxString path
, name
, ext
;
757 wxFileName::SplitPath(fni
.fullname
, &path
, &name
, &ext
);
759 printf("%s -> path = '%s', name = '%s', ext = '%s'",
760 fni
.fullname
, path
.c_str(), name
.c_str(), ext
.c_str());
761 if ( path
!= fni
.path
)
762 printf(" (ERROR: path = '%s')", fni
.path
);
763 if ( name
!= fni
.name
)
764 printf(" (ERROR: name = '%s')", fni
.name
);
765 if ( ext
!= fni
.ext
)
766 printf(" (ERROR: ext = '%s')", fni
.ext
);
773 static void TestFileNameComparison()
778 static void TestFileNameOperations()
783 static void TestFileNameCwd()
788 #endif // TEST_FILENAME
790 // ----------------------------------------------------------------------------
792 // ----------------------------------------------------------------------------
800 Foo(int n_
) { n
= n_
; count
++; }
808 size_t Foo::count
= 0;
810 WX_DECLARE_LIST(Foo
, wxListFoos
);
811 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
813 #include <wx/listimpl.cpp>
815 WX_DEFINE_LIST(wxListFoos
);
817 static void TestHash()
819 puts("*** Testing wxHashTable ***\n");
823 hash
.DeleteContents(TRUE
);
825 printf("Hash created: %u foos in hash, %u foos totally\n",
826 hash
.GetCount(), Foo::count
);
828 static const int hashTestData
[] =
830 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
834 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
836 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
839 printf("Hash filled: %u foos in hash, %u foos totally\n",
840 hash
.GetCount(), Foo::count
);
842 puts("Hash access test:");
843 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
845 printf("\tGetting element with key %d, value %d: ",
847 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
850 printf("ERROR, not found.\n");
854 printf("%d (%s)\n", foo
->n
,
855 (size_t)foo
->n
== n
? "ok" : "ERROR");
859 printf("\nTrying to get an element not in hash: ");
861 if ( hash
.Get(1234) || hash
.Get(1, 0) )
863 puts("ERROR: found!");
867 puts("ok (not found)");
871 printf("Hash destroyed: %u foos left\n", Foo::count
);
876 // ----------------------------------------------------------------------------
878 // ----------------------------------------------------------------------------
884 WX_DECLARE_LIST(Bar
, wxListBars
);
885 #include <wx/listimpl.cpp>
886 WX_DEFINE_LIST(wxListBars
);
888 static void TestListCtor()
890 puts("*** Testing wxList construction ***\n");
894 list1
.Append(new Bar(_T("first")));
895 list1
.Append(new Bar(_T("second")));
897 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
898 list1
.GetCount(), Bar::GetNumber());
903 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
904 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
906 list1
.DeleteContents(TRUE
);
909 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
914 // ----------------------------------------------------------------------------
916 // ----------------------------------------------------------------------------
921 #include "wx/utils.h" // for wxSetEnv
923 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
925 // find the name of the language from its value
926 static const char *GetLangName(int lang
)
928 static const char *languageNames
[] =
949 "ARABIC_SAUDI_ARABIA",
974 "CHINESE_SIMPLIFIED",
975 "CHINESE_TRADITIONAL",
997 "ENGLISH_NEW_ZEALAND",
998 "ENGLISH_PHILIPPINES",
999 "ENGLISH_SOUTH_AFRICA",
1011 "FRENCH_LUXEMBOURG",
1020 "GERMAN_LIECHTENSTEIN",
1021 "GERMAN_LUXEMBOURG",
1062 "MALAY_BRUNEI_DARUSSALAM",
1074 "NORWEGIAN_NYNORSK",
1081 "PORTUGUESE_BRAZILIAN",
1106 "SPANISH_ARGENTINA",
1110 "SPANISH_COSTA_RICA",
1111 "SPANISH_DOMINICAN_REPUBLIC",
1113 "SPANISH_EL_SALVADOR",
1114 "SPANISH_GUATEMALA",
1118 "SPANISH_NICARAGUA",
1122 "SPANISH_PUERTO_RICO",
1125 "SPANISH_VENEZUELA",
1162 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1163 return languageNames
[lang
];
1168 static void TestDefaultLang()
1170 puts("*** Testing wxLocale::GetSystemLanguage ***");
1172 static const wxChar
*langStrings
[] =
1174 NULL
, // system default
1181 _T("de_DE.iso88591"),
1183 _T("?"), // invalid lang spec
1184 _T("klingonese"), // I bet on some systems it does exist...
1187 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1188 wxLocale::GetSystemEncodingName().c_str(),
1189 wxLocale::GetSystemEncoding());
1191 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1193 const char *langStr
= langStrings
[n
];
1196 // FIXME: this doesn't do anything at all under Windows, we need
1197 // to create a new wxLocale!
1198 wxSetEnv(_T("LC_ALL"), langStr
);
1201 int lang
= gs_localeDefault
.GetSystemLanguage();
1202 printf("Locale for '%s' is %s.\n",
1203 langStr
? langStr
: "system default", GetLangName(lang
));
1207 #endif // TEST_LOCALE
1209 // ----------------------------------------------------------------------------
1211 // ----------------------------------------------------------------------------
1215 #include <wx/mimetype.h>
1217 static void TestMimeEnum()
1219 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1221 wxArrayString mimetypes
;
1223 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1225 printf("*** All %u known filetypes: ***\n", count
);
1230 for ( size_t n
= 0; n
< count
; n
++ )
1232 wxFileType
*filetype
=
1233 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1236 printf("nothing known about the filetype '%s'!\n",
1237 mimetypes
[n
].c_str());
1241 filetype
->GetDescription(&desc
);
1242 filetype
->GetExtensions(exts
);
1244 filetype
->GetIcon(NULL
);
1247 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1250 extsAll
<< _T(", ");
1254 printf("\t%s: %s (%s)\n",
1255 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1261 static void TestMimeOverride()
1263 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1265 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1266 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1268 if ( wxFile::Exists(mailcap
) )
1269 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1271 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1273 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1276 if ( wxFile::Exists(mimetypes
) )
1277 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1279 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1281 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1287 static void TestMimeFilename()
1289 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1291 static const wxChar
*filenames
[] =
1298 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1300 const wxString fname
= filenames
[n
];
1301 wxString ext
= fname
.AfterLast(_T('.'));
1302 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1305 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1310 if ( !ft
->GetDescription(&desc
) )
1311 desc
= _T("<no description>");
1314 if ( !ft
->GetOpenCommand(&cmd
,
1315 wxFileType::MessageParameters(fname
, _T(""))) )
1316 cmd
= _T("<no command available>");
1318 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
1319 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1328 static void TestMimeAssociate()
1330 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1332 wxFileTypeInfo
ftInfo(
1333 _T("application/x-xyz"),
1334 _T("xyzview '%s'"), // open cmd
1335 _T(""), // print cmd
1336 _T("XYZ File") // description
1337 _T(".xyz"), // extensions
1338 NULL
// end of extensions
1340 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1342 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1345 wxPuts(_T("ERROR: failed to create association!"));
1349 // TODO: read it back
1358 // ----------------------------------------------------------------------------
1359 // misc information functions
1360 // ----------------------------------------------------------------------------
1362 #ifdef TEST_INFO_FUNCTIONS
1364 #include <wx/utils.h>
1366 static void TestOsInfo()
1368 puts("*** Testing OS info functions ***\n");
1371 wxGetOsVersion(&major
, &minor
);
1372 printf("Running under: %s, version %d.%d\n",
1373 wxGetOsDescription().c_str(), major
, minor
);
1375 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
1377 printf("Host name is %s (%s).\n",
1378 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1383 static void TestUserInfo()
1385 puts("*** Testing user info functions ***\n");
1387 printf("User id is:\t%s\n", wxGetUserId().c_str());
1388 printf("User name is:\t%s\n", wxGetUserName().c_str());
1389 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
1390 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
1395 #endif // TEST_INFO_FUNCTIONS
1397 // ----------------------------------------------------------------------------
1399 // ----------------------------------------------------------------------------
1401 #ifdef TEST_LONGLONG
1403 #include <wx/longlong.h>
1404 #include <wx/timer.h>
1406 // make a 64 bit number from 4 16 bit ones
1407 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
1409 // get a random 64 bit number
1410 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
1412 #if wxUSE_LONGLONG_WX
1413 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
1414 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1415 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
1416 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
1417 #endif // wxUSE_LONGLONG_WX
1419 static void TestSpeed()
1421 static const long max
= 100000000;
1428 for ( n
= 0; n
< max
; n
++ )
1433 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
1436 #if wxUSE_LONGLONG_NATIVE
1441 for ( n
= 0; n
< max
; n
++ )
1446 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
1448 #endif // wxUSE_LONGLONG_NATIVE
1454 for ( n
= 0; n
< max
; n
++ )
1459 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
1463 static void TestLongLongConversion()
1465 puts("*** Testing wxLongLong conversions ***\n");
1469 for ( size_t n
= 0; n
< 100000; n
++ )
1473 #if wxUSE_LONGLONG_NATIVE
1474 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
1476 wxASSERT_MSG( a
== b
, "conversions failure" );
1478 puts("Can't do it without native long long type, test skipped.");
1481 #endif // wxUSE_LONGLONG_NATIVE
1483 if ( !(nTested
% 1000) )
1495 static void TestMultiplication()
1497 puts("*** Testing wxLongLong multiplication ***\n");
1501 for ( size_t n
= 0; n
< 100000; n
++ )
1506 #if wxUSE_LONGLONG_NATIVE
1507 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
1508 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
1510 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
1511 #else // !wxUSE_LONGLONG_NATIVE
1512 puts("Can't do it without native long long type, test skipped.");
1515 #endif // wxUSE_LONGLONG_NATIVE
1517 if ( !(nTested
% 1000) )
1529 static void TestDivision()
1531 puts("*** Testing wxLongLong division ***\n");
1535 for ( size_t n
= 0; n
< 100000; n
++ )
1537 // get a random wxLongLong (shifting by 12 the MSB ensures that the
1538 // multiplication will not overflow)
1539 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
1541 // get a random long (not wxLongLong for now) to divide it with
1546 #if wxUSE_LONGLONG_NATIVE
1547 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
1549 wxLongLongNative p
= m
/ l
, s
= m
% l
;
1550 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
1551 #else // !wxUSE_LONGLONG_NATIVE
1552 // verify the result
1553 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
1554 #endif // wxUSE_LONGLONG_NATIVE
1556 if ( !(nTested
% 1000) )
1568 static void TestAddition()
1570 puts("*** Testing wxLongLong addition ***\n");
1574 for ( size_t n
= 0; n
< 100000; n
++ )
1580 #if wxUSE_LONGLONG_NATIVE
1581 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
1582 wxLongLongNative(b
.GetHi(), b
.GetLo()),
1583 "addition failure" );
1584 #else // !wxUSE_LONGLONG_NATIVE
1585 wxASSERT_MSG( c
- b
== a
, "addition failure" );
1586 #endif // wxUSE_LONGLONG_NATIVE
1588 if ( !(nTested
% 1000) )
1600 static void TestBitOperations()
1602 puts("*** Testing wxLongLong bit operation ***\n");
1606 for ( size_t n
= 0; n
< 100000; n
++ )
1610 #if wxUSE_LONGLONG_NATIVE
1611 for ( size_t n
= 0; n
< 33; n
++ )
1614 #else // !wxUSE_LONGLONG_NATIVE
1615 puts("Can't do it without native long long type, test skipped.");
1618 #endif // wxUSE_LONGLONG_NATIVE
1620 if ( !(nTested
% 1000) )
1632 static void TestLongLongComparison()
1634 #if wxUSE_LONGLONG_WX
1635 puts("*** Testing wxLongLong comparison ***\n");
1637 static const long testLongs
[] =
1648 static const long ls
[2] =
1654 wxLongLongWx lls
[2];
1658 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
1662 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
1664 res
= lls
[m
] > testLongs
[n
];
1665 printf("0x%lx > 0x%lx is %s (%s)\n",
1666 ls
[m
], testLongs
[n
], res
? "true" : "false",
1667 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
1669 res
= lls
[m
] < testLongs
[n
];
1670 printf("0x%lx < 0x%lx is %s (%s)\n",
1671 ls
[m
], testLongs
[n
], res
? "true" : "false",
1672 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
1674 res
= lls
[m
] == testLongs
[n
];
1675 printf("0x%lx == 0x%lx is %s (%s)\n",
1676 ls
[m
], testLongs
[n
], res
? "true" : "false",
1677 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
1680 #endif // wxUSE_LONGLONG_WX
1686 #endif // TEST_LONGLONG
1688 // ----------------------------------------------------------------------------
1690 // ----------------------------------------------------------------------------
1692 #ifdef TEST_PATHLIST
1694 static void TestPathList()
1696 puts("*** Testing wxPathList ***\n");
1698 wxPathList pathlist
;
1699 pathlist
.AddEnvList("PATH");
1700 wxString path
= pathlist
.FindValidPath("ls");
1703 printf("ERROR: command not found in the path.\n");
1707 printf("Command found in the path as '%s'.\n", path
.c_str());
1711 #endif // TEST_PATHLIST
1713 // ----------------------------------------------------------------------------
1714 // registry and related stuff
1715 // ----------------------------------------------------------------------------
1717 // this is for MSW only
1720 #undef TEST_REGISTRY
1725 #include <wx/confbase.h>
1726 #include <wx/msw/regconf.h>
1728 static void TestRegConfWrite()
1730 wxRegConfig
regconf(_T("console"), _T("wxwindows"));
1731 regconf
.Write(_T("Hello"), wxString(_T("world")));
1734 #endif // TEST_REGCONF
1736 #ifdef TEST_REGISTRY
1738 #include <wx/msw/registry.h>
1740 // I chose this one because I liked its name, but it probably only exists under
1742 static const wxChar
*TESTKEY
=
1743 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1745 static void TestRegistryRead()
1747 puts("*** testing registry reading ***");
1749 wxRegKey
key(TESTKEY
);
1750 printf("The test key name is '%s'.\n", key
.GetName().c_str());
1753 puts("ERROR: test key can't be opened, aborting test.");
1758 size_t nSubKeys
, nValues
;
1759 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
1761 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
1764 printf("Enumerating values:\n");
1768 bool cont
= key
.GetFirstValue(value
, dummy
);
1771 printf("Value '%s': type ", value
.c_str());
1772 switch ( key
.GetValueType(value
) )
1774 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
1775 case wxRegKey::Type_String
: printf("SZ"); break;
1776 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
1777 case wxRegKey::Type_Binary
: printf("BINARY"); break;
1778 case wxRegKey::Type_Dword
: printf("DWORD"); break;
1779 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
1780 default: printf("other (unknown)"); break;
1783 printf(", value = ");
1784 if ( key
.IsNumericValue(value
) )
1787 key
.QueryValue(value
, &val
);
1793 key
.QueryValue(value
, val
);
1794 printf("'%s'", val
.c_str());
1796 key
.QueryRawValue(value
, val
);
1797 printf(" (raw value '%s')", val
.c_str());
1802 cont
= key
.GetNextValue(value
, dummy
);
1806 static void TestRegistryAssociation()
1809 The second call to deleteself genertaes an error message, with a
1810 messagebox saying .flo is crucial to system operation, while the .ddf
1811 call also fails, but with no error message
1816 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1818 key
= "ddxf_auto_file" ;
1819 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1821 key
= "ddxf_auto_file" ;
1822 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1825 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1827 key
= "program \"%1\"" ;
1829 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1831 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1833 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1835 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1839 #endif // TEST_REGISTRY
1841 // ----------------------------------------------------------------------------
1843 // ----------------------------------------------------------------------------
1847 #include <wx/socket.h>
1848 #include <wx/protocol/protocol.h>
1849 #include <wx/protocol/http.h>
1851 static void TestSocketServer()
1853 puts("*** Testing wxSocketServer ***\n");
1855 static const int PORT
= 3000;
1860 wxSocketServer
*server
= new wxSocketServer(addr
);
1861 if ( !server
->Ok() )
1863 puts("ERROR: failed to bind");
1870 printf("Server: waiting for connection on port %d...\n", PORT
);
1872 wxSocketBase
*socket
= server
->Accept();
1875 puts("ERROR: wxSocketServer::Accept() failed.");
1879 puts("Server: got a client.");
1881 server
->SetTimeout(60); // 1 min
1883 while ( socket
->IsConnected() )
1889 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
1891 // don't log error if the client just close the connection
1892 if ( socket
->IsConnected() )
1894 puts("ERROR: in wxSocket::Read.");
1914 printf("Server: got '%s'.\n", s
.c_str());
1915 if ( s
== _T("bye") )
1922 socket
->Write(s
.MakeUpper().c_str(), s
.length());
1923 socket
->Write("\r\n", 2);
1924 printf("Server: wrote '%s'.\n", s
.c_str());
1927 puts("Server: lost a client.");
1932 // same as "delete server" but is consistent with GUI programs
1936 static void TestSocketClient()
1938 puts("*** Testing wxSocketClient ***\n");
1940 static const char *hostname
= "www.wxwindows.org";
1943 addr
.Hostname(hostname
);
1946 printf("--- Attempting to connect to %s:80...\n", hostname
);
1948 wxSocketClient client
;
1949 if ( !client
.Connect(addr
) )
1951 printf("ERROR: failed to connect to %s\n", hostname
);
1955 printf("--- Connected to %s:%u...\n",
1956 addr
.Hostname().c_str(), addr
.Service());
1960 // could use simply "GET" here I suppose
1962 wxString::Format("GET http://%s/\r\n", hostname
);
1963 client
.Write(cmdGet
, cmdGet
.length());
1964 printf("--- Sent command '%s' to the server\n",
1965 MakePrintable(cmdGet
).c_str());
1966 client
.Read(buf
, WXSIZEOF(buf
));
1967 printf("--- Server replied:\n%s", buf
);
1971 #endif // TEST_SOCKETS
1973 // ----------------------------------------------------------------------------
1975 // ----------------------------------------------------------------------------
1979 #include <wx/protocol/ftp.h>
1983 #define FTP_ANONYMOUS
1985 #ifdef FTP_ANONYMOUS
1986 static const char *directory
= "/pub";
1987 static const char *filename
= "welcome.msg";
1989 static const char *directory
= "/etc";
1990 static const char *filename
= "issue";
1993 static bool TestFtpConnect()
1995 puts("*** Testing FTP connect ***");
1997 #ifdef FTP_ANONYMOUS
1998 static const char *hostname
= "ftp.wxwindows.org";
2000 printf("--- Attempting to connect to %s:21 anonymously...\n", hostname
);
2001 #else // !FTP_ANONYMOUS
2002 static const char *hostname
= "localhost";
2005 fgets(user
, WXSIZEOF(user
), stdin
);
2006 user
[strlen(user
) - 1] = '\0'; // chop off '\n'
2010 printf("Password for %s: ", password
);
2011 fgets(password
, WXSIZEOF(password
), stdin
);
2012 password
[strlen(password
) - 1] = '\0'; // chop off '\n'
2013 ftp
.SetPassword(password
);
2015 printf("--- Attempting to connect to %s:21 as %s...\n", hostname
, user
);
2016 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2018 if ( !ftp
.Connect(hostname
) )
2020 printf("ERROR: failed to connect to %s\n", hostname
);
2026 printf("--- Connected to %s, current directory is '%s'\n",
2027 hostname
, ftp
.Pwd().c_str());
2033 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2034 static void TestFtpWuFtpd()
2037 static const char *hostname
= "ftp.eudora.com";
2038 if ( !ftp
.Connect(hostname
) )
2040 printf("ERROR: failed to connect to %s\n", hostname
);
2044 static const char *filename
= "eudora/pubs/draft-gellens-submit-09.txt";
2045 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2048 printf("ERROR: couldn't get input stream for %s\n", filename
);
2052 size_t size
= in
->StreamSize();
2053 printf("Reading file %s (%u bytes)...", filename
, size
);
2055 char *data
= new char[size
];
2056 if ( !in
->Read(data
, size
) )
2058 puts("ERROR: read error");
2062 printf("Successfully retrieved the file.\n");
2071 static void TestFtpList()
2073 puts("*** Testing wxFTP file listing ***\n");
2076 if ( !ftp
.ChDir(directory
) )
2078 printf("ERROR: failed to cd to %s\n", directory
);
2081 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2083 // test NLIST and LIST
2084 wxArrayString files
;
2085 if ( !ftp
.GetFilesList(files
) )
2087 puts("ERROR: failed to get NLIST of files");
2091 printf("Brief list of files under '%s':\n", ftp
.Pwd().c_str());
2092 size_t count
= files
.GetCount();
2093 for ( size_t n
= 0; n
< count
; n
++ )
2095 printf("\t%s\n", files
[n
].c_str());
2097 puts("End of the file list");
2100 if ( !ftp
.GetDirList(files
) )
2102 puts("ERROR: failed to get LIST of files");
2106 printf("Detailed list of files under '%s':\n", ftp
.Pwd().c_str());
2107 size_t count
= files
.GetCount();
2108 for ( size_t n
= 0; n
< count
; n
++ )
2110 printf("\t%s\n", files
[n
].c_str());
2112 puts("End of the file list");
2115 if ( !ftp
.ChDir(_T("..")) )
2117 puts("ERROR: failed to cd to ..");
2120 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2123 static void TestFtpDownload()
2125 puts("*** Testing wxFTP download ***\n");
2128 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2131 printf("ERROR: couldn't get input stream for %s\n", filename
);
2135 size_t size
= in
->StreamSize();
2136 printf("Reading file %s (%u bytes)...", filename
, size
);
2139 char *data
= new char[size
];
2140 if ( !in
->Read(data
, size
) )
2142 puts("ERROR: read error");
2146 printf("\nContents of %s:\n%s\n", filename
, data
);
2154 static void TestFtpFileSize()
2156 puts("*** Testing FTP SIZE command ***");
2158 if ( !ftp
.ChDir(directory
) )
2160 printf("ERROR: failed to cd to %s\n", directory
);
2163 printf("Current directory is '%s'\n", ftp
.Pwd().c_str());
2165 if ( ftp
.FileExists(filename
) )
2167 int size
= ftp
.GetFileSize(filename
);
2169 printf("ERROR: couldn't get size of '%s'\n", filename
);
2171 printf("Size of '%s' is %d bytes.\n", filename
, size
);
2175 printf("ERROR: '%s' doesn't exist\n", filename
);
2179 static void TestFtpMisc()
2181 puts("*** Testing miscellaneous wxFTP functions ***");
2183 if ( ftp
.SendCommand("STAT") != '2' )
2185 puts("ERROR: STAT failed");
2189 printf("STAT returned:\n\n%s\n", ftp
.GetLastResult().c_str());
2192 if ( ftp
.SendCommand("HELP SITE") != '2' )
2194 puts("ERROR: HELP SITE failed");
2198 printf("The list of site-specific commands:\n\n%s\n",
2199 ftp
.GetLastResult().c_str());
2203 static void TestFtpInteractive()
2205 puts("\n*** Interactive wxFTP test ***");
2211 printf("Enter FTP command: ");
2212 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2215 // kill the last '\n'
2216 buf
[strlen(buf
) - 1] = 0;
2218 // special handling of LIST and NLST as they require data connection
2219 wxString
start(buf
, 4);
2221 if ( start
== "LIST" || start
== "NLST" )
2224 if ( strlen(buf
) > 4 )
2227 wxArrayString files
;
2228 if ( !ftp
.GetList(files
, wildcard
, start
== "LIST") )
2230 printf("ERROR: failed to get %s of files\n", start
.c_str());
2234 printf("--- %s of '%s' under '%s':\n",
2235 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2236 size_t count
= files
.GetCount();
2237 for ( size_t n
= 0; n
< count
; n
++ )
2239 printf("\t%s\n", files
[n
].c_str());
2241 puts("--- End of the file list");
2246 char ch
= ftp
.SendCommand(buf
);
2247 printf("Command %s", ch
? "succeeded" : "failed");
2250 printf(" (return code %c)", ch
);
2253 printf(", server reply:\n%s\n\n", ftp
.GetLastResult().c_str());
2257 puts("\n*** done ***");
2260 static void TestFtpUpload()
2262 puts("*** Testing wxFTP uploading ***\n");
2265 static const char *file1
= "test1";
2266 static const char *file2
= "test2";
2267 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2270 printf("--- Uploading to %s ---\n", file1
);
2271 out
->Write("First hello", 11);
2275 // send a command to check the remote file
2276 if ( ftp
.SendCommand(wxString("STAT ") + file1
) != '2' )
2278 printf("ERROR: STAT %s failed\n", file1
);
2282 printf("STAT %s returned:\n\n%s\n",
2283 file1
, ftp
.GetLastResult().c_str());
2286 out
= ftp
.GetOutputStream(file2
);
2289 printf("--- Uploading to %s ---\n", file1
);
2290 out
->Write("Second hello", 12);
2297 // ----------------------------------------------------------------------------
2299 // ----------------------------------------------------------------------------
2303 #include <wx/wfstream.h>
2304 #include <wx/mstream.h>
2306 static void TestFileStream()
2308 puts("*** Testing wxFileInputStream ***");
2310 static const wxChar
*filename
= _T("testdata.fs");
2312 wxFileOutputStream
fsOut(filename
);
2313 fsOut
.Write("foo", 3);
2316 wxFileInputStream
fsIn(filename
);
2317 printf("File stream size: %u\n", fsIn
.GetSize());
2318 while ( !fsIn
.Eof() )
2320 putchar(fsIn
.GetC());
2323 if ( !wxRemoveFile(filename
) )
2325 printf("ERROR: failed to remove the file '%s'.\n", filename
);
2328 puts("\n*** wxFileInputStream test done ***");
2331 static void TestMemoryStream()
2333 puts("*** Testing wxMemoryInputStream ***");
2336 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
2338 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
2339 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
2340 while ( !memInpStream
.Eof() )
2342 putchar(memInpStream
.GetC());
2345 puts("\n*** wxMemoryInputStream test done ***");
2348 #endif // TEST_STREAMS
2350 // ----------------------------------------------------------------------------
2352 // ----------------------------------------------------------------------------
2356 #include <wx/timer.h>
2357 #include <wx/utils.h>
2359 static void TestStopWatch()
2361 puts("*** Testing wxStopWatch ***\n");
2364 printf("Sleeping 3 seconds...");
2366 printf("\telapsed time: %ldms\n", sw
.Time());
2369 printf("Sleeping 2 more seconds...");
2371 printf("\telapsed time: %ldms\n", sw
.Time());
2374 printf("And 3 more seconds...");
2376 printf("\telapsed time: %ldms\n", sw
.Time());
2379 puts("\nChecking for 'backwards clock' bug...");
2380 for ( size_t n
= 0; n
< 70; n
++ )
2384 for ( size_t m
= 0; m
< 100000; m
++ )
2386 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
2388 puts("\ntime is negative - ERROR!");
2398 #endif // TEST_TIMER
2400 // ----------------------------------------------------------------------------
2402 // ----------------------------------------------------------------------------
2406 #include <wx/vcard.h>
2408 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
2411 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
2415 wxString(_T('\t'), level
).c_str(),
2416 vcObj
->GetName().c_str());
2419 switch ( vcObj
->GetType() )
2421 case wxVCardObject::String
:
2422 case wxVCardObject::UString
:
2425 vcObj
->GetValue(&val
);
2426 value
<< _T('"') << val
<< _T('"');
2430 case wxVCardObject::Int
:
2433 vcObj
->GetValue(&i
);
2434 value
.Printf(_T("%u"), i
);
2438 case wxVCardObject::Long
:
2441 vcObj
->GetValue(&l
);
2442 value
.Printf(_T("%lu"), l
);
2446 case wxVCardObject::None
:
2449 case wxVCardObject::Object
:
2450 value
= _T("<node>");
2454 value
= _T("<unknown value type>");
2458 printf(" = %s", value
.c_str());
2461 DumpVObject(level
+ 1, *vcObj
);
2464 vcObj
= vcard
.GetNextProp(&cookie
);
2468 static void DumpVCardAddresses(const wxVCard
& vcard
)
2470 puts("\nShowing all addresses from vCard:\n");
2474 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
2478 int flags
= addr
->GetFlags();
2479 if ( flags
& wxVCardAddress::Domestic
)
2481 flagsStr
<< _T("domestic ");
2483 if ( flags
& wxVCardAddress::Intl
)
2485 flagsStr
<< _T("international ");
2487 if ( flags
& wxVCardAddress::Postal
)
2489 flagsStr
<< _T("postal ");
2491 if ( flags
& wxVCardAddress::Parcel
)
2493 flagsStr
<< _T("parcel ");
2495 if ( flags
& wxVCardAddress::Home
)
2497 flagsStr
<< _T("home ");
2499 if ( flags
& wxVCardAddress::Work
)
2501 flagsStr
<< _T("work ");
2504 printf("Address %u:\n"
2506 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
2509 addr
->GetPostOffice().c_str(),
2510 addr
->GetExtAddress().c_str(),
2511 addr
->GetStreet().c_str(),
2512 addr
->GetLocality().c_str(),
2513 addr
->GetRegion().c_str(),
2514 addr
->GetPostalCode().c_str(),
2515 addr
->GetCountry().c_str()
2519 addr
= vcard
.GetNextAddress(&cookie
);
2523 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
2525 puts("\nShowing all phone numbers from vCard:\n");
2529 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
2533 int flags
= phone
->GetFlags();
2534 if ( flags
& wxVCardPhoneNumber::Voice
)
2536 flagsStr
<< _T("voice ");
2538 if ( flags
& wxVCardPhoneNumber::Fax
)
2540 flagsStr
<< _T("fax ");
2542 if ( flags
& wxVCardPhoneNumber::Cellular
)
2544 flagsStr
<< _T("cellular ");
2546 if ( flags
& wxVCardPhoneNumber::Modem
)
2548 flagsStr
<< _T("modem ");
2550 if ( flags
& wxVCardPhoneNumber::Home
)
2552 flagsStr
<< _T("home ");
2554 if ( flags
& wxVCardPhoneNumber::Work
)
2556 flagsStr
<< _T("work ");
2559 printf("Phone number %u:\n"
2564 phone
->GetNumber().c_str()
2568 phone
= vcard
.GetNextPhoneNumber(&cookie
);
2572 static void TestVCardRead()
2574 puts("*** Testing wxVCard reading ***\n");
2576 wxVCard
vcard(_T("vcard.vcf"));
2577 if ( !vcard
.IsOk() )
2579 puts("ERROR: couldn't load vCard.");
2583 // read individual vCard properties
2584 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
2588 vcObj
->GetValue(&value
);
2593 value
= _T("<none>");
2596 printf("Full name retrieved directly: %s\n", value
.c_str());
2599 if ( !vcard
.GetFullName(&value
) )
2601 value
= _T("<none>");
2604 printf("Full name from wxVCard API: %s\n", value
.c_str());
2606 // now show how to deal with multiply occuring properties
2607 DumpVCardAddresses(vcard
);
2608 DumpVCardPhoneNumbers(vcard
);
2610 // and finally show all
2611 puts("\nNow dumping the entire vCard:\n"
2612 "-----------------------------\n");
2614 DumpVObject(0, vcard
);
2618 static void TestVCardWrite()
2620 puts("*** Testing wxVCard writing ***\n");
2623 if ( !vcard
.IsOk() )
2625 puts("ERROR: couldn't create vCard.");
2630 vcard
.SetName("Zeitlin", "Vadim");
2631 vcard
.SetFullName("Vadim Zeitlin");
2632 vcard
.SetOrganization("wxWindows", "R&D");
2634 // just dump the vCard back
2635 puts("Entire vCard follows:\n");
2636 puts(vcard
.Write());
2640 #endif // TEST_VCARD
2642 // ----------------------------------------------------------------------------
2643 // wide char (Unicode) support
2644 // ----------------------------------------------------------------------------
2648 #include <wx/strconv.h>
2649 #include <wx/fontenc.h>
2650 #include <wx/encconv.h>
2651 #include <wx/buffer.h>
2653 static void TestUtf8()
2655 puts("*** Testing UTF8 support ***\n");
2657 static const char textInUtf8
[] =
2659 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
2660 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
2661 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
2662 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
2663 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
2664 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
2665 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
2670 if ( wxConvUTF8
.MB2WC(wbuf
, textInUtf8
, WXSIZEOF(textInUtf8
)) <= 0 )
2672 puts("ERROR: UTF-8 decoding failed.");
2676 // using wxEncodingConverter
2678 wxEncodingConverter ec
;
2679 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
2680 ec
.Convert(wbuf
, buf
);
2681 #else // using wxCSConv
2682 wxCSConv
conv(_T("koi8-r"));
2683 if ( conv
.WC2MB(buf
, wbuf
, 0 /* not needed wcslen(wbuf) */) <= 0 )
2685 puts("ERROR: conversion to KOI8-R failed.");
2690 printf("The resulting string (in koi8-r): %s\n", buf
);
2694 #endif // TEST_WCHAR
2696 // ----------------------------------------------------------------------------
2698 // ----------------------------------------------------------------------------
2702 #include "wx/filesys.h"
2703 #include "wx/fs_zip.h"
2704 #include "wx/zipstrm.h"
2706 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
2708 static void TestZipStreamRead()
2710 puts("*** Testing ZIP reading ***\n");
2712 static const wxChar
*filename
= _T("foo");
2713 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
2714 printf("Archive size: %u\n", istr
.GetSize());
2716 printf("Dumping the file '%s':\n", filename
);
2717 while ( !istr
.Eof() )
2719 putchar(istr
.GetC());
2723 puts("\n----- done ------");
2726 static void DumpZipDirectory(wxFileSystem
& fs
,
2727 const wxString
& dir
,
2728 const wxString
& indent
)
2730 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
2731 TESTFILE_ZIP
, dir
.c_str());
2732 wxString wildcard
= prefix
+ _T("/*");
2734 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
2735 while ( !dirname
.empty() )
2737 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
2739 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
2744 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
2746 DumpZipDirectory(fs
, dirname
,
2747 indent
+ wxString(_T(' '), 4));
2749 dirname
= fs
.FindNext();
2752 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
2753 while ( !filename
.empty() )
2755 if ( !filename
.StartsWith(prefix
, &filename
) )
2757 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
2762 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
2764 filename
= fs
.FindNext();
2768 static void TestZipFileSystem()
2770 puts("*** Testing ZIP file system ***\n");
2772 wxFileSystem::AddHandler(new wxZipFSHandler
);
2774 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
2776 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
2781 // ----------------------------------------------------------------------------
2783 // ----------------------------------------------------------------------------
2787 #include <wx/zstream.h>
2788 #include <wx/wfstream.h>
2790 static const wxChar
*FILENAME_GZ
= _T("test.gz");
2791 static const char *TEST_DATA
= "hello and hello again";
2793 static void TestZlibStreamWrite()
2795 puts("*** Testing Zlib stream reading ***\n");
2797 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
2798 wxZlibOutputStream
ostr(fileOutStream
, 0);
2799 printf("Compressing the test string... ");
2800 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
2803 puts("(ERROR: failed)");
2810 puts("\n----- done ------");
2813 static void TestZlibStreamRead()
2815 puts("*** Testing Zlib stream reading ***\n");
2817 wxFileInputStream
fileInStream(FILENAME_GZ
);
2818 wxZlibInputStream
istr(fileInStream
);
2819 printf("Archive size: %u\n", istr
.GetSize());
2821 puts("Dumping the file:");
2822 while ( !istr
.Eof() )
2824 putchar(istr
.GetC());
2828 puts("\n----- done ------");
2833 // ----------------------------------------------------------------------------
2835 // ----------------------------------------------------------------------------
2837 #ifdef TEST_DATETIME
2841 #include <wx/date.h>
2843 #include <wx/datetime.h>
2848 wxDateTime::wxDateTime_t day
;
2849 wxDateTime::Month month
;
2851 wxDateTime::wxDateTime_t hour
, min
, sec
;
2853 wxDateTime::WeekDay wday
;
2854 time_t gmticks
, ticks
;
2856 void Init(const wxDateTime::Tm
& tm
)
2865 gmticks
= ticks
= -1;
2868 wxDateTime
DT() const
2869 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
2871 bool SameDay(const wxDateTime::Tm
& tm
) const
2873 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
2876 wxString
Format() const
2879 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
2881 wxDateTime::GetMonthName(month
).c_str(),
2883 abs(wxDateTime::ConvertYearToBC(year
)),
2884 year
> 0 ? "AD" : "BC");
2888 wxString
FormatDate() const
2891 s
.Printf("%02d-%s-%4d%s",
2893 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
2894 abs(wxDateTime::ConvertYearToBC(year
)),
2895 year
> 0 ? "AD" : "BC");
2900 static const Date testDates
[] =
2902 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
2903 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
2904 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
2905 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
2906 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
2907 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
2908 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
2909 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
2910 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
2911 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
2912 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
2913 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
2914 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
2915 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
2916 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
2919 // this test miscellaneous static wxDateTime functions
2920 static void TestTimeStatic()
2922 puts("\n*** wxDateTime static methods test ***");
2924 // some info about the current date
2925 int year
= wxDateTime::GetCurrentYear();
2926 printf("Current year %d is %sa leap one and has %d days.\n",
2928 wxDateTime::IsLeapYear(year
) ? "" : "not ",
2929 wxDateTime::GetNumberOfDays(year
));
2931 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
2932 printf("Current month is '%s' ('%s') and it has %d days\n",
2933 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
2934 wxDateTime::GetMonthName(month
).c_str(),
2935 wxDateTime::GetNumberOfDays(month
));
2938 static const size_t nYears
= 5;
2939 static const size_t years
[2][nYears
] =
2941 // first line: the years to test
2942 { 1990, 1976, 2000, 2030, 1984, },
2944 // second line: TRUE if leap, FALSE otherwise
2945 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
2948 for ( size_t n
= 0; n
< nYears
; n
++ )
2950 int year
= years
[0][n
];
2951 bool should
= years
[1][n
] != 0,
2952 is
= wxDateTime::IsLeapYear(year
);
2954 printf("Year %d is %sa leap year (%s)\n",
2957 should
== is
? "ok" : "ERROR");
2959 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
2963 // test constructing wxDateTime objects
2964 static void TestTimeSet()
2966 puts("\n*** wxDateTime construction test ***");
2968 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2970 const Date
& d1
= testDates
[n
];
2971 wxDateTime dt
= d1
.DT();
2974 d2
.Init(dt
.GetTm());
2976 wxString s1
= d1
.Format(),
2979 printf("Date: %s == %s (%s)\n",
2980 s1
.c_str(), s2
.c_str(),
2981 s1
== s2
? "ok" : "ERROR");
2985 // test time zones stuff
2986 static void TestTimeZones()
2988 puts("\n*** wxDateTime timezone test ***");
2990 wxDateTime now
= wxDateTime::Now();
2992 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
2993 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
2994 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
2995 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
2996 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
2997 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
2999 wxDateTime::Tm tm
= now
.GetTm();
3000 if ( wxDateTime(tm
) != now
)
3002 printf("ERROR: got %s instead of %s\n",
3003 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3007 // test some minimal support for the dates outside the standard range
3008 static void TestTimeRange()
3010 puts("\n*** wxDateTime out-of-standard-range dates test ***");
3012 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
3014 printf("Unix epoch:\t%s\n",
3015 wxDateTime(2440587.5).Format(fmt
).c_str());
3016 printf("Feb 29, 0: \t%s\n",
3017 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3018 printf("JDN 0: \t%s\n",
3019 wxDateTime(0.0).Format(fmt
).c_str());
3020 printf("Jan 1, 1AD:\t%s\n",
3021 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3022 printf("May 29, 2099:\t%s\n",
3023 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3026 static void TestTimeTicks()
3028 puts("\n*** wxDateTime ticks test ***");
3030 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3032 const Date
& d
= testDates
[n
];
3033 if ( d
.ticks
== -1 )
3036 wxDateTime dt
= d
.DT();
3037 long ticks
= (dt
.GetValue() / 1000).ToLong();
3038 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3039 if ( ticks
== d
.ticks
)
3045 printf(" (ERROR: should be %ld, delta = %ld)\n",
3046 d
.ticks
, ticks
- d
.ticks
);
3049 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
3050 ticks
= (dt
.GetValue() / 1000).ToLong();
3051 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
3052 if ( ticks
== d
.gmticks
)
3058 printf(" (ERROR: should be %ld, delta = %ld)\n",
3059 d
.gmticks
, ticks
- d
.gmticks
);
3066 // test conversions to JDN &c
3067 static void TestTimeJDN()
3069 puts("\n*** wxDateTime to JDN test ***");
3071 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3073 const Date
& d
= testDates
[n
];
3074 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3075 double jdn
= dt
.GetJulianDayNumber();
3077 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
3084 printf(" (ERROR: should be %f, delta = %f)\n",
3085 d
.jdn
, jdn
- d
.jdn
);
3090 // test week days computation
3091 static void TestTimeWDays()
3093 puts("\n*** wxDateTime weekday test ***");
3095 // test GetWeekDay()
3097 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
3099 const Date
& d
= testDates
[n
];
3100 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
3102 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
3105 wxDateTime::GetWeekDayName(wday
).c_str());
3106 if ( wday
== d
.wday
)
3112 printf(" (ERROR: should be %s)\n",
3113 wxDateTime::GetWeekDayName(d
.wday
).c_str());
3119 // test SetToWeekDay()
3120 struct WeekDateTestData
3122 Date date
; // the real date (precomputed)
3123 int nWeek
; // its week index in the month
3124 wxDateTime::WeekDay wday
; // the weekday
3125 wxDateTime::Month month
; // the month
3126 int year
; // and the year
3128 wxString
Format() const
3131 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
3133 case 1: which
= "first"; break;
3134 case 2: which
= "second"; break;
3135 case 3: which
= "third"; break;
3136 case 4: which
= "fourth"; break;
3137 case 5: which
= "fifth"; break;
3139 case -1: which
= "last"; break;
3144 which
+= " from end";
3147 s
.Printf("The %s %s of %s in %d",
3149 wxDateTime::GetWeekDayName(wday
).c_str(),
3150 wxDateTime::GetMonthName(month
).c_str(),
3157 // the array data was generated by the following python program
3159 from DateTime import *
3160 from whrandom import *
3161 from string import *
3163 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3164 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3166 week = DateTimeDelta(7)
3169 year = randint(1900, 2100)
3170 month = randint(1, 12)
3171 day = randint(1, 28)
3172 dt = DateTime(year, month, day)
3173 wday = dt.day_of_week
3175 countFromEnd = choice([-1, 1])
3178 while dt.month is month:
3179 dt = dt - countFromEnd * week
3180 weekNum = weekNum + countFromEnd
3182 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
3184 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
3185 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
3188 static const WeekDateTestData weekDatesTestData
[] =
3190 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
3191 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
3192 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
3193 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
3194 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
3195 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
3196 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
3197 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
3198 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
3199 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
3200 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
3201 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
3202 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
3203 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
3204 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
3205 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
3206 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
3207 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
3208 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
3209 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
3212 static const char *fmt
= "%d-%b-%Y";
3215 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
3217 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
3219 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
3221 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
3223 const Date
& d
= wd
.date
;
3224 if ( d
.SameDay(dt
.GetTm()) )
3230 dt
.Set(d
.day
, d
.month
, d
.year
);
3232 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
3237 // test the computation of (ISO) week numbers
3238 static void TestTimeWNumber()
3240 puts("\n*** wxDateTime week number test ***");
3242 struct WeekNumberTestData
3244 Date date
; // the date
3245 wxDateTime::wxDateTime_t week
; // the week number in the year
3246 wxDateTime::wxDateTime_t wmon
; // the week number in the month
3247 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
3248 wxDateTime::wxDateTime_t dnum
; // day number in the year
3251 // data generated with the following python script:
3253 from DateTime import *
3254 from whrandom import *
3255 from string import *
3257 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3258 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3260 def GetMonthWeek(dt):
3261 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
3262 if weekNumMonth < 0:
3263 weekNumMonth = weekNumMonth + 53
3266 def GetLastSundayBefore(dt):
3267 if dt.iso_week[2] == 7:
3270 return dt - DateTimeDelta(dt.iso_week[2])
3273 year = randint(1900, 2100)
3274 month = randint(1, 12)
3275 day = randint(1, 28)
3276 dt = DateTime(year, month, day)
3277 dayNum = dt.day_of_year
3278 weekNum = dt.iso_week[1]
3279 weekNumMonth = GetMonthWeek(dt)
3282 dtSunday = GetLastSundayBefore(dt)
3284 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
3285 weekNumMonth2 = weekNumMonth2 + 1
3286 dtSunday = dtSunday - DateTimeDelta(7)
3288 data = { 'day': rjust(`day`, 2), \
3289 'month': monthNames[month - 1], \
3291 'weekNum': rjust(`weekNum`, 2), \
3292 'weekNumMonth': weekNumMonth, \
3293 'weekNumMonth2': weekNumMonth2, \
3294 'dayNum': rjust(`dayNum`, 3) }
3296 print " { { %(day)s, "\
3297 "wxDateTime::%(month)s, "\
3300 "%(weekNumMonth)s, "\
3301 "%(weekNumMonth2)s, "\
3302 "%(dayNum)s }," % data
3305 static const WeekNumberTestData weekNumberTestDates
[] =
3307 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
3308 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
3309 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
3310 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
3311 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
3312 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
3313 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
3314 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
3315 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
3316 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
3317 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
3318 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
3319 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
3320 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
3321 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
3322 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
3323 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
3324 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
3325 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
3326 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
3329 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
3331 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
3332 const Date
& d
= wn
.date
;
3334 wxDateTime dt
= d
.DT();
3336 wxDateTime::wxDateTime_t
3337 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
3338 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3339 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3340 dnum
= dt
.GetDayOfYear();
3342 printf("%s: the day number is %d",
3343 d
.FormatDate().c_str(), dnum
);
3344 if ( dnum
== wn
.dnum
)
3350 printf(" (ERROR: should be %d)", wn
.dnum
);
3353 printf(", week in month is %d", wmon
);
3354 if ( wmon
== wn
.wmon
)
3360 printf(" (ERROR: should be %d)", wn
.wmon
);
3363 printf(" or %d", wmon2
);
3364 if ( wmon2
== wn
.wmon2
)
3370 printf(" (ERROR: should be %d)", wn
.wmon2
);
3373 printf(", week in year is %d", week
);
3374 if ( week
== wn
.week
)
3380 printf(" (ERROR: should be %d)\n", wn
.week
);
3385 // test DST calculations
3386 static void TestTimeDST()
3388 puts("\n*** wxDateTime DST test ***");
3390 printf("DST is%s in effect now.\n\n",
3391 wxDateTime::Now().IsDST() ? "" : " not");
3393 // taken from http://www.energy.ca.gov/daylightsaving.html
3394 static const Date datesDST
[2][2004 - 1900 + 1] =
3397 { 1, wxDateTime::Apr
, 1990 },
3398 { 7, wxDateTime::Apr
, 1991 },
3399 { 5, wxDateTime::Apr
, 1992 },
3400 { 4, wxDateTime::Apr
, 1993 },
3401 { 3, wxDateTime::Apr
, 1994 },
3402 { 2, wxDateTime::Apr
, 1995 },
3403 { 7, wxDateTime::Apr
, 1996 },
3404 { 6, wxDateTime::Apr
, 1997 },
3405 { 5, wxDateTime::Apr
, 1998 },
3406 { 4, wxDateTime::Apr
, 1999 },
3407 { 2, wxDateTime::Apr
, 2000 },
3408 { 1, wxDateTime::Apr
, 2001 },
3409 { 7, wxDateTime::Apr
, 2002 },
3410 { 6, wxDateTime::Apr
, 2003 },
3411 { 4, wxDateTime::Apr
, 2004 },
3414 { 28, wxDateTime::Oct
, 1990 },
3415 { 27, wxDateTime::Oct
, 1991 },
3416 { 25, wxDateTime::Oct
, 1992 },
3417 { 31, wxDateTime::Oct
, 1993 },
3418 { 30, wxDateTime::Oct
, 1994 },
3419 { 29, wxDateTime::Oct
, 1995 },
3420 { 27, wxDateTime::Oct
, 1996 },
3421 { 26, wxDateTime::Oct
, 1997 },
3422 { 25, wxDateTime::Oct
, 1998 },
3423 { 31, wxDateTime::Oct
, 1999 },
3424 { 29, wxDateTime::Oct
, 2000 },
3425 { 28, wxDateTime::Oct
, 2001 },
3426 { 27, wxDateTime::Oct
, 2002 },
3427 { 26, wxDateTime::Oct
, 2003 },
3428 { 31, wxDateTime::Oct
, 2004 },
3433 for ( year
= 1990; year
< 2005; year
++ )
3435 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
3436 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
3438 printf("DST period in the US for year %d: from %s to %s",
3439 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
3441 size_t n
= year
- 1990;
3442 const Date
& dBegin
= datesDST
[0][n
];
3443 const Date
& dEnd
= datesDST
[1][n
];
3445 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
3451 printf(" (ERROR: should be %s %d to %s %d)\n",
3452 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
3453 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
3459 for ( year
= 1990; year
< 2005; year
++ )
3461 printf("DST period in Europe for year %d: from %s to %s\n",
3463 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3464 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3468 // test wxDateTime -> text conversion
3469 static void TestTimeFormat()
3471 puts("\n*** wxDateTime formatting test ***");
3473 // some information may be lost during conversion, so store what kind
3474 // of info should we recover after a round trip
3477 CompareNone
, // don't try comparing
3478 CompareBoth
, // dates and times should be identical
3479 CompareDate
, // dates only
3480 CompareTime
// time only
3485 CompareKind compareKind
;
3487 } formatTestFormats
[] =
3489 { CompareBoth
, "---> %c" },
3490 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
3491 { CompareBoth
, "Date is %x, time is %X" },
3492 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
3493 { CompareNone
, "The day of year: %j, the week of year: %W" },
3494 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
3497 static const Date formatTestDates
[] =
3499 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
3500 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
3502 // this test can't work for other centuries because it uses two digit
3503 // years in formats, so don't even try it
3504 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
3505 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
3506 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
3510 // an extra test (as it doesn't depend on date, don't do it in the loop)
3511 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
3513 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
3517 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
3518 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
3520 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
3521 printf("%s", s
.c_str());
3523 // what can we recover?
3524 int kind
= formatTestFormats
[n
].compareKind
;
3528 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
3531 // converion failed - should it have?
3532 if ( kind
== CompareNone
)
3535 puts(" (ERROR: conversion back failed)");
3539 // should have parsed the entire string
3540 puts(" (ERROR: conversion back stopped too soon)");
3544 bool equal
= FALSE
; // suppress compilaer warning
3552 equal
= dt
.IsSameDate(dt2
);
3556 equal
= dt
.IsSameTime(dt2
);
3562 printf(" (ERROR: got back '%s' instead of '%s')\n",
3563 dt2
.Format().c_str(), dt
.Format().c_str());
3574 // test text -> wxDateTime conversion
3575 static void TestTimeParse()
3577 puts("\n*** wxDateTime parse test ***");
3579 struct ParseTestData
3586 static const ParseTestData parseTestDates
[] =
3588 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
3589 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
3592 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
3594 const char *format
= parseTestDates
[n
].format
;
3596 printf("%s => ", format
);
3599 if ( dt
.ParseRfc822Date(format
) )
3601 printf("%s ", dt
.Format().c_str());
3603 if ( parseTestDates
[n
].good
)
3605 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
3612 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
3617 puts("(ERROR: bad format)");
3622 printf("bad format (%s)\n",
3623 parseTestDates
[n
].good
? "ERROR" : "ok");
3628 static void TestDateTimeInteractive()
3630 puts("\n*** interactive wxDateTime tests ***");
3636 printf("Enter a date: ");
3637 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
3640 // kill the last '\n'
3641 buf
[strlen(buf
) - 1] = 0;
3644 const char *p
= dt
.ParseDate(buf
);
3647 printf("ERROR: failed to parse the date '%s'.\n", buf
);
3653 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
3656 printf("%s: day %u, week of month %u/%u, week of year %u\n",
3657 dt
.Format("%b %d, %Y").c_str(),
3659 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3660 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3661 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3664 puts("\n*** done ***");
3667 static void TestTimeMS()
3669 puts("*** testing millisecond-resolution support in wxDateTime ***");
3671 wxDateTime dt1
= wxDateTime::Now(),
3672 dt2
= wxDateTime::UNow();
3674 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
3675 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
3676 printf("Dummy loop: ");
3677 for ( int i
= 0; i
< 6000; i
++ )
3679 //for ( int j = 0; j < 10; j++ )
3682 s
.Printf("%g", sqrt(i
));
3691 dt2
= wxDateTime::UNow();
3692 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
3694 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
3696 puts("\n*** done ***");
3699 static void TestTimeArithmetics()
3701 puts("\n*** testing arithmetic operations on wxDateTime ***");
3703 static const struct ArithmData
3705 ArithmData(const wxDateSpan
& sp
, const char *nam
)
3706 : span(sp
), name(nam
) { }
3710 } testArithmData
[] =
3712 ArithmData(wxDateSpan::Day(), "day"),
3713 ArithmData(wxDateSpan::Week(), "week"),
3714 ArithmData(wxDateSpan::Month(), "month"),
3715 ArithmData(wxDateSpan::Year(), "year"),
3716 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
3719 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
3721 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
3723 wxDateSpan span
= testArithmData
[n
].span
;
3727 const char *name
= testArithmData
[n
].name
;
3728 printf("%s + %s = %s, %s - %s = %s\n",
3729 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
3730 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
3732 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
3733 if ( dt1
- span
== dt
)
3739 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
3742 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
3743 if ( dt2
+ span
== dt
)
3749 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
3752 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
3753 if ( dt2
+ 2*span
== dt1
)
3759 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
3766 static void TestTimeHolidays()
3768 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
3770 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3771 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3772 dtEnd
= dtStart
.GetLastMonthDay();
3774 wxDateTimeArray hol
;
3775 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3777 const wxChar
*format
= "%d-%b-%Y (%a)";
3779 printf("All holidays between %s and %s:\n",
3780 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3782 size_t count
= hol
.GetCount();
3783 for ( size_t n
= 0; n
< count
; n
++ )
3785 printf("\t%s\n", hol
[n
].Format(format
).c_str());
3791 static void TestTimeZoneBug()
3793 puts("\n*** testing for DST/timezone bug ***\n");
3795 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3796 for ( int i
= 0; i
< 31; i
++ )
3798 printf("Date %s: week day %s.\n",
3799 date
.Format(_T("%d-%m-%Y")).c_str(),
3800 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3802 date
+= wxDateSpan::Day();
3808 static void TestTimeSpanFormat()
3810 puts("\n*** wxTimeSpan tests ***");
3812 static const char *formats
[] =
3814 _T("(default) %H:%M:%S"),
3815 _T("%E weeks and %D days"),
3816 _T("%l milliseconds"),
3817 _T("(with ms) %H:%M:%S:%l"),
3818 _T("100%% of minutes is %M"), // test "%%"
3819 _T("%D days and %H hours"),
3822 wxTimeSpan
ts1(1, 2, 3, 4),
3824 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3826 printf("ts1 = %s\tts2 = %s\n",
3827 ts1
.Format(formats
[n
]).c_str(),
3828 ts2
.Format(formats
[n
]).c_str());
3836 // test compatibility with the old wxDate/wxTime classes
3837 static void TestTimeCompatibility()
3839 puts("\n*** wxDateTime compatibility test ***");
3841 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
3842 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
3844 double jdnNow
= wxDateTime::Now().GetJDN();
3845 long jdnMidnight
= (long)(jdnNow
- 0.5);
3846 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
3848 jdnMidnight
= wxDate().Set().GetJulianDate();
3849 printf("wxDateTime for today: %s\n",
3850 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
3852 int flags
= wxEUROPEAN
;//wxFULL;
3855 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
3856 for ( int n
= 0; n
< 7; n
++ )
3858 printf("Previous %s is %s\n",
3859 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
3860 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
3866 #endif // TEST_DATETIME
3868 // ----------------------------------------------------------------------------
3870 // ----------------------------------------------------------------------------
3874 #include <wx/thread.h>
3876 static size_t gs_counter
= (size_t)-1;
3877 static wxCriticalSection gs_critsect
;
3878 static wxCondition gs_cond
;
3880 class MyJoinableThread
: public wxThread
3883 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3884 { m_n
= n
; Create(); }
3886 // thread execution starts here
3887 virtual ExitCode
Entry();
3893 wxThread::ExitCode
MyJoinableThread::Entry()
3895 unsigned long res
= 1;
3896 for ( size_t n
= 1; n
< m_n
; n
++ )
3900 // it's a loooong calculation :-)
3904 return (ExitCode
)res
;
3907 class MyDetachedThread
: public wxThread
3910 MyDetachedThread(size_t n
, char ch
)
3914 m_cancelled
= FALSE
;
3919 // thread execution starts here
3920 virtual ExitCode
Entry();
3923 virtual void OnExit();
3926 size_t m_n
; // number of characters to write
3927 char m_ch
; // character to write
3929 bool m_cancelled
; // FALSE if we exit normally
3932 wxThread::ExitCode
MyDetachedThread::Entry()
3935 wxCriticalSectionLocker
lock(gs_critsect
);
3936 if ( gs_counter
== (size_t)-1 )
3942 for ( size_t n
= 0; n
< m_n
; n
++ )
3944 if ( TestDestroy() )
3954 wxThread::Sleep(100);
3960 void MyDetachedThread::OnExit()
3962 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
3964 wxCriticalSectionLocker
lock(gs_critsect
);
3965 if ( !--gs_counter
&& !m_cancelled
)
3969 void TestDetachedThreads()
3971 puts("\n*** Testing detached threads ***");
3973 static const size_t nThreads
= 3;
3974 MyDetachedThread
*threads
[nThreads
];
3976 for ( n
= 0; n
< nThreads
; n
++ )
3978 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3981 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3982 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3984 for ( n
= 0; n
< nThreads
; n
++ )
3989 // wait until all threads terminate
3995 void TestJoinableThreads()
3997 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
3999 // calc 10! in the background
4000 MyJoinableThread
thread(10);
4003 printf("\nThread terminated with exit code %lu.\n",
4004 (unsigned long)thread
.Wait());
4007 void TestThreadSuspend()
4009 puts("\n*** Testing thread suspend/resume functions ***");
4011 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4015 // this is for this demo only, in a real life program we'd use another
4016 // condition variable which would be signaled from wxThread::Entry() to
4017 // tell us that the thread really started running - but here just wait a
4018 // bit and hope that it will be enough (the problem is, of course, that
4019 // the thread might still not run when we call Pause() which will result
4021 wxThread::Sleep(300);
4023 for ( size_t n
= 0; n
< 3; n
++ )
4027 puts("\nThread suspended");
4030 // don't sleep but resume immediately the first time
4031 wxThread::Sleep(300);
4033 puts("Going to resume the thread");
4038 puts("Waiting until it terminates now");
4040 // wait until the thread terminates
4046 void TestThreadDelete()
4048 // As above, using Sleep() is only for testing here - we must use some
4049 // synchronisation object instead to ensure that the thread is still
4050 // running when we delete it - deleting a detached thread which already
4051 // terminated will lead to a crash!
4053 puts("\n*** Testing thread delete function ***");
4055 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4059 puts("\nDeleted a thread which didn't start to run yet.");
4061 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4065 wxThread::Sleep(300);
4069 puts("\nDeleted a running thread.");
4071 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4075 wxThread::Sleep(300);
4081 puts("\nDeleted a sleeping thread.");
4083 MyJoinableThread
thread3(20);
4088 puts("\nDeleted a joinable thread.");
4090 MyJoinableThread
thread4(2);
4093 wxThread::Sleep(300);
4097 puts("\nDeleted a joinable thread which already terminated.");
4102 #endif // TEST_THREADS
4104 // ----------------------------------------------------------------------------
4106 // ----------------------------------------------------------------------------
4110 static void PrintArray(const char* name
, const wxArrayString
& array
)
4112 printf("Dump of the array '%s'\n", name
);
4114 size_t nCount
= array
.GetCount();
4115 for ( size_t n
= 0; n
< nCount
; n
++ )
4117 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
4121 static void PrintArray(const char* name
, const wxArrayInt
& array
)
4123 printf("Dump of the array '%s'\n", name
);
4125 size_t nCount
= array
.GetCount();
4126 for ( size_t n
= 0; n
< nCount
; n
++ )
4128 printf("\t%s[%u] = %d\n", name
, n
, array
[n
]);
4132 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
4133 const wxString
& second
)
4135 return first
.length() - second
.length();
4138 int wxCMPFUNC_CONV
IntCompare(int *first
,
4141 return *first
- *second
;
4144 int wxCMPFUNC_CONV
IntRevCompare(int *first
,
4147 return *second
- *first
;
4150 static void TestArrayOfInts()
4152 puts("*** Testing wxArrayInt ***\n");
4163 puts("After sort:");
4167 puts("After reverse sort:");
4168 a
.Sort(IntRevCompare
);
4172 #include "wx/dynarray.h"
4174 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
4175 #include "wx/arrimpl.cpp"
4176 WX_DEFINE_OBJARRAY(ArrayBars
);
4178 static void TestArrayOfObjects()
4180 puts("*** Testing wxObjArray ***\n");
4184 Bar
bar("second bar");
4186 printf("Initially: %u objects in the array, %u objects total.\n",
4187 bars
.GetCount(), Bar::GetNumber());
4189 bars
.Add(new Bar("first bar"));
4192 printf("Now: %u objects in the array, %u objects total.\n",
4193 bars
.GetCount(), Bar::GetNumber());
4197 printf("After Empty(): %u objects in the array, %u objects total.\n",
4198 bars
.GetCount(), Bar::GetNumber());
4201 printf("Finally: no more objects in the array, %u objects total.\n",
4205 #endif // TEST_ARRAYS
4207 // ----------------------------------------------------------------------------
4209 // ----------------------------------------------------------------------------
4213 #include "wx/timer.h"
4214 #include "wx/tokenzr.h"
4216 static void TestStringConstruction()
4218 puts("*** Testing wxString constructores ***");
4220 #define TEST_CTOR(args, res) \
4223 printf("wxString%s = %s ", #args, s.c_str()); \
4230 printf("(ERROR: should be %s)\n", res); \
4234 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
4235 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
4236 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
4237 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
4239 static const wxChar
*s
= _T("?really!");
4240 const wxChar
*start
= wxStrchr(s
, _T('r'));
4241 const wxChar
*end
= wxStrchr(s
, _T('!'));
4242 TEST_CTOR((start
, end
), _T("really"));
4247 static void TestString()
4257 for (int i
= 0; i
< 1000000; ++i
)
4261 c
= "! How'ya doin'?";
4264 c
= "Hello world! What's up?";
4269 printf ("TestString elapsed time: %ld\n", sw
.Time());
4272 static void TestPChar()
4280 for (int i
= 0; i
< 1000000; ++i
)
4282 strcpy (a
, "Hello");
4283 strcpy (b
, " world");
4284 strcpy (c
, "! How'ya doin'?");
4287 strcpy (c
, "Hello world! What's up?");
4288 if (strcmp (c
, a
) == 0)
4292 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
4295 static void TestStringSub()
4297 wxString
s("Hello, world!");
4299 puts("*** Testing wxString substring extraction ***");
4301 printf("String = '%s'\n", s
.c_str());
4302 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
4303 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
4304 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
4305 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
4306 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
4307 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
4309 static const wxChar
*prefixes
[] =
4313 _T("Hello, world!"),
4314 _T("Hello, world!!!"),
4320 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
4322 wxString prefix
= prefixes
[n
], rest
;
4323 bool rc
= s
.StartsWith(prefix
, &rest
);
4324 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
4327 printf(" (the rest is '%s')\n", rest
.c_str());
4338 static void TestStringFormat()
4340 puts("*** Testing wxString formatting ***");
4343 s
.Printf("%03d", 18);
4345 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
4346 printf("Number 18: %s\n", s
.c_str());
4351 // returns "not found" for npos, value for all others
4352 static wxString
PosToString(size_t res
)
4354 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
4355 : wxString::Format(_T("%u"), res
);
4359 static void TestStringFind()
4361 puts("*** Testing wxString find() functions ***");
4363 static const wxChar
*strToFind
= _T("ell");
4364 static const struct StringFindTest
4368 result
; // of searching "ell" in str
4371 { _T("Well, hello world"), 0, 1 },
4372 { _T("Well, hello world"), 6, 7 },
4373 { _T("Well, hello world"), 9, wxString::npos
},
4376 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
4378 const StringFindTest
& ft
= findTestData
[n
];
4379 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
4381 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
4382 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
4384 size_t resTrue
= ft
.result
;
4385 if ( res
== resTrue
)
4391 printf(_T("(ERROR: should be %s)\n"),
4392 PosToString(resTrue
).c_str());
4399 static void TestStringTokenizer()
4401 puts("*** Testing wxStringTokenizer ***");
4403 static const wxChar
*modeNames
[] =
4407 _T("return all empty"),
4412 static const struct StringTokenizerTest
4414 const wxChar
*str
; // string to tokenize
4415 const wxChar
*delims
; // delimiters to use
4416 size_t count
; // count of token
4417 wxStringTokenizerMode mode
; // how should we tokenize it
4418 } tokenizerTestData
[] =
4420 { _T(""), _T(" "), 0 },
4421 { _T("Hello, world"), _T(" "), 2 },
4422 { _T("Hello, world "), _T(" "), 2 },
4423 { _T("Hello, world"), _T(","), 2 },
4424 { _T("Hello, world!"), _T(",!"), 2 },
4425 { _T("Hello,, world!"), _T(",!"), 3 },
4426 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
4427 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
4428 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
4429 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
4430 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
4431 { _T("01/02/99"), _T("/-"), 3 },
4432 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
4435 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
4437 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
4438 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
4440 size_t count
= tkz
.CountTokens();
4441 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
4442 MakePrintable(tt
.str
).c_str(),
4444 MakePrintable(tt
.delims
).c_str(),
4445 modeNames
[tkz
.GetMode()]);
4446 if ( count
== tt
.count
)
4452 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
4457 // if we emulate strtok(), check that we do it correctly
4458 wxChar
*buf
, *s
= NULL
, *last
;
4460 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
4462 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
4463 wxStrcpy(buf
, tt
.str
);
4465 s
= wxStrtok(buf
, tt
.delims
, &last
);
4472 // now show the tokens themselves
4474 while ( tkz
.HasMoreTokens() )
4476 wxString token
= tkz
.GetNextToken();
4478 printf(_T("\ttoken %u: '%s'"),
4480 MakePrintable(token
).c_str());
4490 printf(" (ERROR: should be %s)\n", s
);
4493 s
= wxStrtok(NULL
, tt
.delims
, &last
);
4497 // nothing to compare with
4502 if ( count2
!= count
)
4504 puts(_T("\tERROR: token count mismatch"));
4513 static void TestStringReplace()
4515 puts("*** Testing wxString::replace ***");
4517 static const struct StringReplaceTestData
4519 const wxChar
*original
; // original test string
4520 size_t start
, len
; // the part to replace
4521 const wxChar
*replacement
; // the replacement string
4522 const wxChar
*result
; // and the expected result
4523 } stringReplaceTestData
[] =
4525 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
4526 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
4527 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
4528 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
4529 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
4532 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
4534 const StringReplaceTestData data
= stringReplaceTestData
[n
];
4536 wxString original
= data
.original
;
4537 original
.replace(data
.start
, data
.len
, data
.replacement
);
4539 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
4540 data
.original
, data
.start
, data
.len
, data
.replacement
,
4543 if ( original
== data
.result
)
4549 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
4556 static void TestStringMatch()
4558 wxPuts(_T("*** Testing wxString::Matches() ***"));
4560 static const struct StringMatchTestData
4563 const wxChar
*wildcard
;
4565 } stringMatchTestData
[] =
4567 { _T("foobar"), _T("foo*"), 1 },
4568 { _T("foobar"), _T("*oo*"), 1 },
4569 { _T("foobar"), _T("*bar"), 1 },
4570 { _T("foobar"), _T("??????"), 1 },
4571 { _T("foobar"), _T("f??b*"), 1 },
4572 { _T("foobar"), _T("f?b*"), 0 },
4573 { _T("foobar"), _T("*goo*"), 0 },
4574 { _T("foobar"), _T("*foo"), 0 },
4575 { _T("foobarfoo"), _T("*foo"), 1 },
4576 { _T(""), _T("*"), 1 },
4577 { _T(""), _T("?"), 0 },
4580 for ( size_t n
= 0; n
< WXSIZEOF(stringMatchTestData
); n
++ )
4582 const StringMatchTestData
& data
= stringMatchTestData
[n
];
4583 bool matches
= wxString(data
.text
).Matches(data
.wildcard
);
4584 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
4586 matches
? _T("matches") : _T("doesn't match"),
4588 matches
== data
.matches
? _T("ok") : _T("ERROR"));
4594 #endif // TEST_STRINGS
4596 // ----------------------------------------------------------------------------
4598 // ----------------------------------------------------------------------------
4600 int main(int argc
, char **argv
)
4602 wxInitializer initializer
;
4605 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
4610 #ifdef TEST_SNGLINST
4611 wxSingleInstanceChecker checker
;
4612 if ( checker
.Create(_T(".wxconsole.lock")) )
4614 if ( checker
.IsAnotherRunning() )
4616 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4621 // wait some time to give time to launch another instance
4622 wxPrintf(_T("Press \"Enter\" to continue..."));
4625 else // failed to create
4627 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4629 #endif // TEST_SNGLINST
4633 #endif // TEST_CHARSET
4636 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4638 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
4639 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
4641 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
4642 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
4643 { wxCMD_LINE_OPTION
, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER
},
4644 { wxCMD_LINE_OPTION
, "d", "date", "output file date", wxCMD_LINE_VAL_DATE
},
4646 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
4647 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4652 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
4654 parser
.AddOption("project_name", "", "full path to project file",
4655 wxCMD_LINE_VAL_STRING
,
4656 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4658 switch ( parser
.Parse() )
4661 wxLogMessage("Help was given, terminating.");
4665 ShowCmdLine(parser
);
4669 wxLogMessage("Syntax error detected, aborting.");
4672 #endif // TEST_CMDLINE
4680 TestStringConstruction();
4683 TestStringTokenizer();
4684 TestStringReplace();
4687 #endif // TEST_STRINGS
4700 puts("*** Initially:");
4702 PrintArray("a1", a1
);
4704 wxArrayString
a2(a1
);
4705 PrintArray("a2", a2
);
4707 wxSortedArrayString
a3(a1
);
4708 PrintArray("a3", a3
);
4710 puts("*** After deleting a string from a1");
4713 PrintArray("a1", a1
);
4714 PrintArray("a2", a2
);
4715 PrintArray("a3", a3
);
4717 puts("*** After reassigning a1 to a2 and a3");
4719 PrintArray("a2", a2
);
4720 PrintArray("a3", a3
);
4722 puts("*** After sorting a1");
4724 PrintArray("a1", a1
);
4726 puts("*** After sorting a1 in reverse order");
4728 PrintArray("a1", a1
);
4730 puts("*** After sorting a1 by the string length");
4731 a1
.Sort(StringLenCompare
);
4732 PrintArray("a1", a1
);
4734 TestArrayOfObjects();
4737 #endif // TEST_ARRAYS
4745 #ifdef TEST_DLLLOADER
4747 #endif // TEST_DLLLOADER
4751 #endif // TEST_ENVIRON
4755 #endif // TEST_EXECUTE
4757 #ifdef TEST_FILECONF
4759 #endif // TEST_FILECONF
4767 #endif // TEST_LOCALE
4771 for ( size_t n
= 0; n
< 8000; n
++ )
4773 s
<< (char)('A' + (n
% 26));
4777 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
4779 // this one shouldn't be truncated
4782 // but this one will because log functions use fixed size buffer
4783 // (note that it doesn't need '\n' at the end neither - will be added
4785 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
4797 #ifdef TEST_FILENAME
4798 TestFileNameSplit();
4801 TestFileNameConstruction();
4803 TestFileNameComparison();
4804 TestFileNameOperations();
4806 #endif // TEST_FILENAME
4809 int nCPUs
= wxThread::GetCPUCount();
4810 printf("This system has %d CPUs\n", nCPUs
);
4812 wxThread::SetConcurrency(nCPUs
);
4814 if ( argc
> 1 && argv
[1][0] == 't' )
4815 wxLog::AddTraceMask("thread");
4818 TestDetachedThreads();
4820 TestJoinableThreads();
4822 TestThreadSuspend();
4826 #endif // TEST_THREADS
4828 #ifdef TEST_LONGLONG
4829 // seed pseudo random generator
4830 srand((unsigned)time(NULL
));
4838 TestMultiplication();
4841 TestLongLongConversion();
4842 TestBitOperations();
4844 TestLongLongComparison();
4845 #endif // TEST_LONGLONG
4852 wxLog::AddTraceMask(_T("mime"));
4860 TestMimeAssociate();
4863 #ifdef TEST_INFO_FUNCTIONS
4866 #endif // TEST_INFO_FUNCTIONS
4868 #ifdef TEST_PATHLIST
4870 #endif // TEST_PATHLIST
4874 #endif // TEST_REGCONF
4876 #ifdef TEST_REGISTRY
4879 TestRegistryAssociation();
4880 #endif // TEST_REGISTRY
4888 #endif // TEST_SOCKETS
4891 wxLog::AddTraceMask(FTP_TRACE_MASK
);
4892 if ( TestFtpConnect() )
4903 TestFtpInteractive();
4905 //else: connecting to the FTP server failed
4915 #endif // TEST_STREAMS
4919 #endif // TEST_TIMER
4921 #ifdef TEST_DATETIME
4934 TestTimeArithmetics();
4941 TestTimeSpanFormat();
4943 TestDateTimeInteractive();
4944 #endif // TEST_DATETIME
4947 puts("Sleeping for 3 seconds... z-z-z-z-z...");
4949 #endif // TEST_USLEEP
4955 #endif // TEST_VCARD
4959 #endif // TEST_WCHAR
4963 TestZipStreamRead();
4964 TestZipFileSystem();
4969 TestZlibStreamWrite();
4970 TestZlibStreamRead();