]>
Commit | Line | Data |
---|---|---|
37667812 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: samples/console/console.cpp | |
f6c9f2ed | 3 | // Purpose: A sample console (as opposed to GUI) program using wxWidgets |
37667812 VZ |
4 | // Author: Vadim Zeitlin |
5 | // Modified by: | |
6 | // Created: 04.10.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
e87271f3 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
e84010cf | 20 | #include "wx/defs.h" |
b11a23f3 | 21 | |
37667812 VZ |
22 | #include <stdio.h> |
23 | ||
e84010cf GD |
24 | #include "wx/string.h" |
25 | #include "wx/file.h" | |
26 | #include "wx/app.h" | |
e046e5f1 | 27 | #include "wx/log.h" |
e87271f3 | 28 | |
d31b7b68 VZ |
29 | // without this pragma, the stupid compiler precompiles #defines below so that |
30 | // changing them doesn't "take place" later! | |
31 | #ifdef __VISUALC__ | |
32 | #pragma hdrstop | |
33 | #endif | |
34 | ||
e87271f3 VZ |
35 | // ---------------------------------------------------------------------------- |
36 | // conditional compilation | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
daa2c7d9 VZ |
39 | /* |
40 | A note about all these conditional compilation macros: this file is used | |
be5a51fb | 41 | both as a test suite for various non-GUI wxWidgets classes and as a |
daa2c7d9 VZ |
42 | scratchpad for quick tests. So there are two compilation modes: if you |
43 | define TEST_ALL all tests are run, otherwise you may enable the individual | |
44 | tests individually in the "#else" branch below. | |
45 | */ | |
46 | ||
e9d2bb6f DS |
47 | // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single |
48 | // test, define it to 1 to do all tests. | |
49 | #define TEST_ALL 0 | |
50 | ||
51 | ||
52 | #if TEST_ALL | |
31f6de22 VZ |
53 | #define TEST_CMDLINE |
54 | #define TEST_DATETIME | |
55 | #define TEST_DIR | |
93ed8ff7 | 56 | #define TEST_DYNLIB |
31f6de22 VZ |
57 | #define TEST_ENVIRON |
58 | #define TEST_EXECUTE | |
59 | #define TEST_FILE | |
60 | #define TEST_FILECONF | |
61 | #define TEST_FILENAME | |
62 | #define TEST_FILETIME | |
8d4dc98f | 63 | // #define TEST_FTP --FIXME! (RN) |
31f6de22 | 64 | #define TEST_INFO_FUNCTIONS |
31f6de22 VZ |
65 | #define TEST_LOCALE |
66 | #define TEST_LOG | |
31f6de22 VZ |
67 | #define TEST_MIME |
68 | #define TEST_PATHLIST | |
8d5eff60 | 69 | #define TEST_ODBC |
7aeebdcd | 70 | #define TEST_PRINTF |
31f6de22 VZ |
71 | #define TEST_REGCONF |
72 | #define TEST_REGEX | |
73 | #define TEST_REGISTRY | |
24c8053b | 74 | #define TEST_SCOPEGUARD |
31f6de22 | 75 | #define TEST_SNGLINST |
8d4dc98f | 76 | // #define TEST_SOCKETS --FIXME! (RN) |
eaff0f0d | 77 | #define TEST_STACKWALKER |
af33b199 | 78 | #define TEST_STDPATHS |
31f6de22 | 79 | #define TEST_STREAMS |
39937656 | 80 | #define TEST_TEXTSTREAM |
31f6de22 VZ |
81 | #define TEST_THREADS |
82 | #define TEST_TIMER | |
83 | // #define TEST_VCARD -- don't enable this (VZ) | |
8d4dc98f | 84 | // #define TEST_VOLUME --FIXME! (RN) |
31f6de22 VZ |
85 | #define TEST_WCHAR |
86 | #define TEST_ZIP | |
e9d2bb6f | 87 | #else // #if TEST_ALL |
3af9f2de | 88 | #define TEST_STDPATHS |
31f6de22 | 89 | #endif |
f6bcfd97 | 90 | |
daa2c7d9 VZ |
91 | // some tests are interactive, define this to run them |
92 | #ifdef TEST_INTERACTIVE | |
93 | #undef TEST_INTERACTIVE | |
94 | ||
e9d2bb6f | 95 | #define TEST_INTERACTIVE 1 |
daa2c7d9 | 96 | #else |
e9d2bb6f | 97 | #define TEST_INTERACTIVE 0 |
daa2c7d9 | 98 | #endif |
58b24a56 | 99 | |
e87271f3 VZ |
100 | // ============================================================================ |
101 | // implementation | |
102 | // ============================================================================ | |
103 | ||
8e907a13 VZ |
104 | // ---------------------------------------------------------------------------- |
105 | // helper functions | |
106 | // ---------------------------------------------------------------------------- | |
107 | ||
1cd53e88 | 108 | #if defined(TEST_SOCKETS) |
8e907a13 VZ |
109 | |
110 | // replace TABs with \t and CRs with \n | |
111 | static wxString MakePrintable(const wxChar *s) | |
112 | { | |
113 | wxString str(s); | |
114 | (void)str.Replace(_T("\t"), _T("\\t")); | |
115 | (void)str.Replace(_T("\n"), _T("\\n")); | |
116 | (void)str.Replace(_T("\r"), _T("\\r")); | |
117 | ||
118 | return str; | |
119 | } | |
120 | ||
121 | #endif // MakePrintable() is used | |
122 | ||
d34bce84 VZ |
123 | // ---------------------------------------------------------------------------- |
124 | // wxCmdLineParser | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
d31b7b68 VZ |
127 | #ifdef TEST_CMDLINE |
128 | ||
e84010cf GD |
129 | #include "wx/cmdline.h" |
130 | #include "wx/datetime.h" | |
d34bce84 | 131 | |
31f6de22 VZ |
132 | #if wxUSE_CMDLINE_PARSER |
133 | ||
d34bce84 VZ |
134 | static void ShowCmdLine(const wxCmdLineParser& parser) |
135 | { | |
456ae26d | 136 | wxString s = _T("Input files: "); |
d34bce84 VZ |
137 | |
138 | size_t count = parser.GetParamCount(); | |
139 | for ( size_t param = 0; param < count; param++ ) | |
140 | { | |
141 | s << parser.GetParam(param) << ' '; | |
142 | } | |
143 | ||
144 | s << '\n' | |
456ae26d VZ |
145 | << _T("Verbose:\t") << (parser.Found(_T("v")) ? _T("yes") : _T("no")) << '\n' |
146 | << _T("Quiet:\t") << (parser.Found(_T("q")) ? _T("yes") : _T("no")) << '\n'; | |
d34bce84 VZ |
147 | |
148 | wxString strVal; | |
149 | long lVal; | |
150 | wxDateTime dt; | |
456ae26d VZ |
151 | if ( parser.Found(_T("o"), &strVal) ) |
152 | s << _T("Output file:\t") << strVal << '\n'; | |
153 | if ( parser.Found(_T("i"), &strVal) ) | |
154 | s << _T("Input dir:\t") << strVal << '\n'; | |
155 | if ( parser.Found(_T("s"), &lVal) ) | |
156 | s << _T("Size:\t") << lVal << '\n'; | |
157 | if ( parser.Found(_T("d"), &dt) ) | |
158 | s << _T("Date:\t") << dt.FormatISODate() << '\n'; | |
159 | if ( parser.Found(_T("project_name"), &strVal) ) | |
160 | s << _T("Project:\t") << strVal << '\n'; | |
d34bce84 VZ |
161 | |
162 | wxLogMessage(s); | |
163 | } | |
164 | ||
31f6de22 VZ |
165 | #endif // wxUSE_CMDLINE_PARSER |
166 | ||
167 | static void TestCmdLineConvert() | |
168 | { | |
456ae26d | 169 | static const wxChar *cmdlines[] = |
31f6de22 | 170 | { |
456ae26d VZ |
171 | _T("arg1 arg2"), |
172 | _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""), | |
173 | _T("literal \\\" and \"\""), | |
31f6de22 VZ |
174 | }; |
175 | ||
176 | for ( size_t n = 0; n < WXSIZEOF(cmdlines); n++ ) | |
177 | { | |
456ae26d VZ |
178 | const wxChar *cmdline = cmdlines[n]; |
179 | wxPrintf(_T("Parsing: %s\n"), cmdline); | |
31f6de22 VZ |
180 | wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdline); |
181 | ||
182 | size_t count = args.GetCount(); | |
456ae26d | 183 | wxPrintf(_T("\targc = %u\n"), count); |
31f6de22 VZ |
184 | for ( size_t arg = 0; arg < count; arg++ ) |
185 | { | |
456ae26d | 186 | wxPrintf(_T("\targv[%u] = %s\n"), arg, args[arg].c_str()); |
31f6de22 VZ |
187 | } |
188 | } | |
189 | } | |
190 | ||
d34bce84 VZ |
191 | #endif // TEST_CMDLINE |
192 | ||
1944c6bd VZ |
193 | // ---------------------------------------------------------------------------- |
194 | // wxDir | |
195 | // ---------------------------------------------------------------------------- | |
196 | ||
197 | #ifdef TEST_DIR | |
198 | ||
e84010cf | 199 | #include "wx/dir.h" |
1944c6bd | 200 | |
35332784 VZ |
201 | #ifdef __UNIX__ |
202 | static const wxChar *ROOTDIR = _T("/"); | |
2f0c19d0 | 203 | static const wxChar *TESTDIR = _T("/usr/local/share"); |
65e324b4 | 204 | #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__) |
35332784 VZ |
205 | static const wxChar *ROOTDIR = _T("c:\\"); |
206 | static const wxChar *TESTDIR = _T("d:\\"); | |
207 | #else | |
208 | #error "don't know where the root directory is" | |
209 | #endif | |
210 | ||
1944c6bd VZ |
211 | static void TestDirEnumHelper(wxDir& dir, |
212 | int flags = wxDIR_DEFAULT, | |
213 | const wxString& filespec = wxEmptyString) | |
214 | { | |
215 | wxString filename; | |
216 | ||
217 | if ( !dir.IsOpened() ) | |
218 | return; | |
219 | ||
220 | bool cont = dir.GetFirst(&filename, filespec, flags); | |
221 | while ( cont ) | |
222 | { | |
456ae26d | 223 | wxPrintf(_T("\t%s\n"), filename.c_str()); |
1944c6bd VZ |
224 | |
225 | cont = dir.GetNext(&filename); | |
226 | } | |
227 | ||
e9d2bb6f | 228 | wxPuts(wxEmptyString); |
1944c6bd VZ |
229 | } |
230 | ||
dab6fbae WS |
231 | #if TEST_ALL |
232 | ||
1944c6bd VZ |
233 | static void TestDirEnum() |
234 | { | |
456ae26d | 235 | wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***")); |
35332784 | 236 | |
149147e1 | 237 | wxString cwd = wxGetCwd(); |
9475670f | 238 | if ( !wxDir::Exists(cwd) ) |
149147e1 | 239 | { |
456ae26d | 240 | wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str()); |
149147e1 VZ |
241 | return; |
242 | } | |
243 | ||
ee3ef281 | 244 | wxDir dir(cwd); |
149147e1 VZ |
245 | if ( !dir.IsOpened() ) |
246 | { | |
456ae26d | 247 | wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd.c_str()); |
149147e1 VZ |
248 | return; |
249 | } | |
1944c6bd | 250 | |
456ae26d | 251 | wxPuts(_T("Enumerating everything in current directory:")); |
1944c6bd VZ |
252 | TestDirEnumHelper(dir); |
253 | ||
456ae26d | 254 | wxPuts(_T("Enumerating really everything in current directory:")); |
1944c6bd VZ |
255 | TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT); |
256 | ||
456ae26d | 257 | wxPuts(_T("Enumerating object files in current directory:")); |
f2cb8a17 | 258 | TestDirEnumHelper(dir, wxDIR_DEFAULT, _T("*.o*")); |
1944c6bd | 259 | |
456ae26d | 260 | wxPuts(_T("Enumerating directories in current directory:")); |
1944c6bd VZ |
261 | TestDirEnumHelper(dir, wxDIR_DIRS); |
262 | ||
456ae26d | 263 | wxPuts(_T("Enumerating files in current directory:")); |
1944c6bd VZ |
264 | TestDirEnumHelper(dir, wxDIR_FILES); |
265 | ||
456ae26d | 266 | wxPuts(_T("Enumerating files including hidden in current directory:")); |
1944c6bd VZ |
267 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
268 | ||
35332784 | 269 | dir.Open(ROOTDIR); |
1944c6bd | 270 | |
456ae26d | 271 | wxPuts(_T("Enumerating everything in root directory:")); |
1944c6bd VZ |
272 | TestDirEnumHelper(dir, wxDIR_DEFAULT); |
273 | ||
456ae26d | 274 | wxPuts(_T("Enumerating directories in root directory:")); |
1944c6bd VZ |
275 | TestDirEnumHelper(dir, wxDIR_DIRS); |
276 | ||
456ae26d | 277 | wxPuts(_T("Enumerating files in root directory:")); |
1944c6bd VZ |
278 | TestDirEnumHelper(dir, wxDIR_FILES); |
279 | ||
456ae26d | 280 | wxPuts(_T("Enumerating files including hidden in root directory:")); |
1944c6bd VZ |
281 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
282 | ||
456ae26d | 283 | wxPuts(_T("Enumerating files in non existing directory:")); |
f2cb8a17 | 284 | wxDir dirNo(_T("nosuchdir")); |
1944c6bd VZ |
285 | TestDirEnumHelper(dirNo); |
286 | } | |
287 | ||
dab6fbae WS |
288 | #endif // TEST_ALL |
289 | ||
35332784 VZ |
290 | class DirPrintTraverser : public wxDirTraverser |
291 | { | |
292 | public: | |
e9d2bb6f | 293 | virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) |
35332784 VZ |
294 | { |
295 | return wxDIR_CONTINUE; | |
296 | } | |
297 | ||
298 | virtual wxDirTraverseResult OnDir(const wxString& dirname) | |
299 | { | |
300 | wxString path, name, ext; | |
301 | wxSplitPath(dirname, &path, &name, &ext); | |
302 | ||
303 | if ( !ext.empty() ) | |
304 | name << _T('.') << ext; | |
305 | ||
306 | wxString indent; | |
307 | for ( const wxChar *p = path.c_str(); *p; p++ ) | |
308 | { | |
309 | if ( wxIsPathSeparator(*p) ) | |
310 | indent += _T(" "); | |
311 | } | |
312 | ||
456ae26d | 313 | wxPrintf(_T("%s%s\n"), indent.c_str(), name.c_str()); |
35332784 VZ |
314 | |
315 | return wxDIR_CONTINUE; | |
316 | } | |
317 | }; | |
318 | ||
319 | static void TestDirTraverse() | |
320 | { | |
456ae26d | 321 | wxPuts(_T("*** Testing wxDir::Traverse() ***")); |
35332784 VZ |
322 | |
323 | // enum all files | |
324 | wxArrayString files; | |
325 | size_t n = wxDir::GetAllFiles(TESTDIR, &files); | |
456ae26d | 326 | wxPrintf(_T("There are %u files under '%s'\n"), n, TESTDIR); |
35332784 VZ |
327 | if ( n > 1 ) |
328 | { | |
456ae26d VZ |
329 | wxPrintf(_T("First one is '%s'\n"), files[0u].c_str()); |
330 | wxPrintf(_T(" last one is '%s'\n"), files[n - 1].c_str()); | |
35332784 VZ |
331 | } |
332 | ||
333 | // enum again with custom traverser | |
2f0c19d0 | 334 | wxPuts(_T("Now enumerating directories:")); |
35332784 VZ |
335 | wxDir dir(TESTDIR); |
336 | DirPrintTraverser traverser; | |
e9d2bb6f | 337 | dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN); |
35332784 VZ |
338 | } |
339 | ||
dab6fbae WS |
340 | #if TEST_ALL |
341 | ||
149147e1 VZ |
342 | static void TestDirExists() |
343 | { | |
344 | wxPuts(_T("*** Testing wxDir::Exists() ***")); | |
345 | ||
456ae26d | 346 | static const wxChar *dirnames[] = |
149147e1 VZ |
347 | { |
348 | _T("."), | |
349 | #if defined(__WXMSW__) | |
350 | _T("c:"), | |
351 | _T("c:\\"), | |
352 | _T("\\\\share\\file"), | |
353 | _T("c:\\dos"), | |
354 | _T("c:\\dos\\"), | |
355 | _T("c:\\dos\\\\"), | |
356 | _T("c:\\autoexec.bat"), | |
357 | #elif defined(__UNIX__) | |
358 | _T("/"), | |
359 | _T("//"), | |
360 | _T("/usr/bin"), | |
361 | _T("/usr//bin"), | |
362 | _T("/usr///bin"), | |
363 | #endif | |
364 | }; | |
365 | ||
366 | for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ ) | |
367 | { | |
456ae26d VZ |
368 | wxPrintf(_T("%-40s: %s\n"), |
369 | dirnames[n], | |
370 | wxDir::Exists(dirnames[n]) ? _T("exists") | |
371 | : _T("doesn't exist")); | |
149147e1 VZ |
372 | } |
373 | } | |
374 | ||
dab6fbae WS |
375 | #endif // TEST_ALL |
376 | ||
1944c6bd VZ |
377 | #endif // TEST_DIR |
378 | ||
f6bcfd97 BP |
379 | // ---------------------------------------------------------------------------- |
380 | // wxDllLoader | |
381 | // ---------------------------------------------------------------------------- | |
382 | ||
93ed8ff7 | 383 | #ifdef TEST_DYNLIB |
f6bcfd97 | 384 | |
e84010cf | 385 | #include "wx/dynlib.h" |
f6bcfd97 BP |
386 | |
387 | static void TestDllLoad() | |
388 | { | |
389 | #if defined(__WXMSW__) | |
390 | static const wxChar *LIB_NAME = _T("kernel32.dll"); | |
391 | static const wxChar *FUNC_NAME = _T("lstrlenA"); | |
392 | #elif defined(__UNIX__) | |
393 | // weird: using just libc.so does *not* work! | |
e259f83e | 394 | static const wxChar *LIB_NAME = _T("/lib/libc.so.6"); |
f6bcfd97 BP |
395 | static const wxChar *FUNC_NAME = _T("strlen"); |
396 | #else | |
397 | #error "don't know how to test wxDllLoader on this platform" | |
398 | #endif | |
399 | ||
297ebe6b | 400 | wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n")); |
f6bcfd97 | 401 | |
456ae26d VZ |
402 | wxDynamicLibrary lib(LIB_NAME); |
403 | if ( !lib.IsLoaded() ) | |
f6bcfd97 BP |
404 | { |
405 | wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME); | |
406 | } | |
407 | else | |
408 | { | |
93ed8ff7 | 409 | typedef int (wxSTDCALL *wxStrlenType)(const char *); |
456ae26d | 410 | wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME); |
f6bcfd97 BP |
411 | if ( !pfnStrlen ) |
412 | { | |
413 | wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"), | |
414 | FUNC_NAME, LIB_NAME); | |
415 | } | |
416 | else | |
417 | { | |
e259f83e VZ |
418 | wxPrintf(_T("Calling %s dynamically loaded from %s "), |
419 | FUNC_NAME, LIB_NAME); | |
420 | ||
f6bcfd97 BP |
421 | if ( pfnStrlen("foo") != 3 ) |
422 | { | |
456ae26d | 423 | wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n")); |
f6bcfd97 BP |
424 | } |
425 | else | |
426 | { | |
456ae26d | 427 | wxPuts(_T("... ok")); |
f6bcfd97 BP |
428 | } |
429 | } | |
93ed8ff7 VZ |
430 | |
431 | #ifdef __WXMSW__ | |
432 | static const wxChar *FUNC_NAME_AW = _T("lstrlen"); | |
433 | ||
434 | typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *); | |
435 | wxStrlenTypeAorW | |
436 | pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW); | |
437 | if ( !pfnStrlenAorW ) | |
438 | { | |
439 | wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"), | |
440 | FUNC_NAME_AW, LIB_NAME); | |
441 | } | |
442 | else | |
443 | { | |
444 | if ( pfnStrlenAorW(_T("foobar")) != 6 ) | |
445 | { | |
446 | wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n")); | |
447 | } | |
448 | } | |
449 | #endif // __WXMSW__ | |
f6bcfd97 BP |
450 | } |
451 | } | |
452 | ||
297ebe6b VZ |
453 | #if defined(__WXMSW__) || defined(__UNIX__) |
454 | ||
455 | static void TestDllListLoaded() | |
456 | { | |
457 | wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n")); | |
458 | ||
459 | puts("\nLoaded modules:"); | |
460 | wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded(); | |
461 | const size_t count = dlls.GetCount(); | |
462 | for ( size_t n = 0; n < count; ++n ) | |
463 | { | |
464 | const wxDynamicLibraryDetails& details = dlls[n]; | |
eaff0f0d | 465 | printf("%-45s", details.GetPath().mb_str()); |
297ebe6b VZ |
466 | |
467 | void *addr; | |
468 | size_t len; | |
469 | if ( details.GetAddress(&addr, &len) ) | |
470 | { | |
471 | printf(" %08lx:%08lx", | |
472 | (unsigned long)addr, (unsigned long)((char *)addr + len)); | |
473 | } | |
474 | ||
eaff0f0d | 475 | printf(" %s\n", details.GetVersion().mb_str()); |
297ebe6b VZ |
476 | } |
477 | } | |
478 | ||
479 | #endif | |
480 | ||
93ed8ff7 | 481 | #endif // TEST_DYNLIB |
f6bcfd97 | 482 | |
8fd0d89b VZ |
483 | // ---------------------------------------------------------------------------- |
484 | // wxGet/SetEnv | |
485 | // ---------------------------------------------------------------------------- | |
486 | ||
487 | #ifdef TEST_ENVIRON | |
488 | ||
e84010cf | 489 | #include "wx/utils.h" |
8fd0d89b | 490 | |
308978f6 VZ |
491 | static wxString MyGetEnv(const wxString& var) |
492 | { | |
493 | wxString val; | |
494 | if ( !wxGetEnv(var, &val) ) | |
495 | val = _T("<empty>"); | |
496 | else | |
497 | val = wxString(_T('\'')) + val + _T('\''); | |
498 | ||
499 | return val; | |
500 | } | |
501 | ||
8fd0d89b VZ |
502 | static void TestEnvironment() |
503 | { | |
504 | const wxChar *var = _T("wxTestVar"); | |
505 | ||
456ae26d | 506 | wxPuts(_T("*** testing environment access functions ***")); |
8fd0d89b | 507 | |
456ae26d | 508 | wxPrintf(_T("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
8fd0d89b | 509 | wxSetEnv(var, _T("value for wxTestVar")); |
456ae26d | 510 | wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
8fd0d89b | 511 | wxSetEnv(var, _T("another value")); |
456ae26d | 512 | wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
8fd0d89b | 513 | wxUnsetEnv(var); |
456ae26d VZ |
514 | wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
515 | wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str()); | |
8fd0d89b VZ |
516 | } |
517 | ||
518 | #endif // TEST_ENVIRON | |
519 | ||
d93c719a VZ |
520 | // ---------------------------------------------------------------------------- |
521 | // wxExecute | |
522 | // ---------------------------------------------------------------------------- | |
523 | ||
524 | #ifdef TEST_EXECUTE | |
525 | ||
e84010cf | 526 | #include "wx/utils.h" |
d93c719a VZ |
527 | |
528 | static void TestExecute() | |
529 | { | |
456ae26d | 530 | wxPuts(_T("*** testing wxExecute ***")); |
d93c719a VZ |
531 | |
532 | #ifdef __UNIX__ | |
a1f79c1e | 533 | #define COMMAND "cat -n ../../Makefile" // "echo hi" |
2c8e4738 | 534 | #define SHELL_COMMAND "echo hi from shell" |
a1f79c1e | 535 | #define REDIRECT_COMMAND COMMAND // "date" |
d93c719a | 536 | #elif defined(__WXMSW__) |
50ded68d | 537 | #define COMMAND "command.com /c echo hi" |
2c8e4738 VZ |
538 | #define SHELL_COMMAND "echo hi" |
539 | #define REDIRECT_COMMAND COMMAND | |
d93c719a VZ |
540 | #else |
541 | #error "no command to exec" | |
542 | #endif // OS | |
543 | ||
456ae26d | 544 | wxPrintf(_T("Testing wxShell: ")); |
2c8e4738 | 545 | fflush(stdout); |
f2cb8a17 | 546 | if ( wxShell(_T(SHELL_COMMAND)) ) |
456ae26d | 547 | wxPuts(_T("Ok.")); |
d93c719a | 548 | else |
456ae26d | 549 | wxPuts(_T("ERROR.")); |
2c8e4738 | 550 | |
456ae26d | 551 | wxPrintf(_T("Testing wxExecute: ")); |
2c8e4738 | 552 | fflush(stdout); |
f2cb8a17 | 553 | if ( wxExecute(_T(COMMAND), true /* sync */) == 0 ) |
456ae26d | 554 | wxPuts(_T("Ok.")); |
2c8e4738 | 555 | else |
456ae26d | 556 | wxPuts(_T("ERROR.")); |
2c8e4738 VZ |
557 | |
558 | #if 0 // no, it doesn't work (yet?) | |
456ae26d | 559 | wxPrintf(_T("Testing async wxExecute: ")); |
2c8e4738 VZ |
560 | fflush(stdout); |
561 | if ( wxExecute(COMMAND) != 0 ) | |
456ae26d | 562 | wxPuts(_T("Ok (command launched).")); |
2c8e4738 | 563 | else |
456ae26d | 564 | wxPuts(_T("ERROR.")); |
2c8e4738 VZ |
565 | #endif // 0 |
566 | ||
456ae26d | 567 | wxPrintf(_T("Testing wxExecute with redirection:\n")); |
2c8e4738 | 568 | wxArrayString output; |
f2cb8a17 | 569 | if ( wxExecute(_T(REDIRECT_COMMAND), output) != 0 ) |
2c8e4738 | 570 | { |
456ae26d | 571 | wxPuts(_T("ERROR.")); |
2c8e4738 VZ |
572 | } |
573 | else | |
574 | { | |
575 | size_t count = output.GetCount(); | |
576 | for ( size_t n = 0; n < count; n++ ) | |
577 | { | |
456ae26d | 578 | wxPrintf(_T("\t%s\n"), output[n].c_str()); |
2c8e4738 VZ |
579 | } |
580 | ||
456ae26d | 581 | wxPuts(_T("Ok.")); |
2c8e4738 | 582 | } |
d93c719a VZ |
583 | } |
584 | ||
585 | #endif // TEST_EXECUTE | |
586 | ||
f6bcfd97 BP |
587 | // ---------------------------------------------------------------------------- |
588 | // file | |
589 | // ---------------------------------------------------------------------------- | |
590 | ||
591 | #ifdef TEST_FILE | |
592 | ||
e84010cf GD |
593 | #include "wx/file.h" |
594 | #include "wx/ffile.h" | |
595 | #include "wx/textfile.h" | |
f6bcfd97 BP |
596 | |
597 | static void TestFileRead() | |
598 | { | |
456ae26d | 599 | wxPuts(_T("*** wxFile read test ***")); |
f6bcfd97 BP |
600 | |
601 | wxFile file(_T("testdata.fc")); | |
602 | if ( file.IsOpened() ) | |
603 | { | |
456ae26d | 604 | wxPrintf(_T("File length: %lu\n"), file.Length()); |
f6bcfd97 | 605 | |
456ae26d | 606 | wxPuts(_T("File dump:\n----------")); |
f6bcfd97 | 607 | |
30984dea | 608 | static const size_t len = 1024; |
456ae26d | 609 | wxChar buf[len]; |
f6bcfd97 BP |
610 | for ( ;; ) |
611 | { | |
30984dea VZ |
612 | size_t nRead = file.Read(buf, len); |
613 | if ( nRead == (size_t)wxInvalidOffset ) | |
f6bcfd97 | 614 | { |
456ae26d | 615 | wxPrintf(_T("Failed to read the file.")); |
f6bcfd97 BP |
616 | break; |
617 | } | |
618 | ||
619 | fwrite(buf, nRead, 1, stdout); | |
620 | ||
621 | if ( nRead < len ) | |
622 | break; | |
623 | } | |
624 | ||
456ae26d | 625 | wxPuts(_T("----------")); |
f6bcfd97 BP |
626 | } |
627 | else | |
628 | { | |
456ae26d | 629 | wxPrintf(_T("ERROR: can't open test file.\n")); |
f6bcfd97 BP |
630 | } |
631 | ||
e9d2bb6f | 632 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
633 | } |
634 | ||
635 | static void TestTextFileRead() | |
636 | { | |
456ae26d | 637 | wxPuts(_T("*** wxTextFile read test ***")); |
f6bcfd97 BP |
638 | |
639 | wxTextFile file(_T("testdata.fc")); | |
640 | if ( file.Open() ) | |
641 | { | |
456ae26d VZ |
642 | wxPrintf(_T("Number of lines: %u\n"), file.GetLineCount()); |
643 | wxPrintf(_T("Last line: '%s'\n"), file.GetLastLine().c_str()); | |
3ca6a5f0 BP |
644 | |
645 | wxString s; | |
646 | ||
456ae26d | 647 | wxPuts(_T("\nDumping the entire file:")); |
3ca6a5f0 BP |
648 | for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() ) |
649 | { | |
456ae26d | 650 | wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 651 | } |
456ae26d | 652 | wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 653 | |
456ae26d | 654 | wxPuts(_T("\nAnd now backwards:")); |
3ca6a5f0 BP |
655 | for ( s = file.GetLastLine(); |
656 | file.GetCurrentLine() != 0; | |
657 | s = file.GetPrevLine() ) | |
658 | { | |
456ae26d | 659 | wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 660 | } |
456ae26d | 661 | wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
f6bcfd97 BP |
662 | } |
663 | else | |
664 | { | |
456ae26d | 665 | wxPrintf(_T("ERROR: can't open '%s'\n"), file.GetName()); |
f6bcfd97 BP |
666 | } |
667 | ||
e9d2bb6f | 668 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
669 | } |
670 | ||
a339970a VZ |
671 | static void TestFileCopy() |
672 | { | |
456ae26d | 673 | wxPuts(_T("*** Testing wxCopyFile ***")); |
a339970a VZ |
674 | |
675 | static const wxChar *filename1 = _T("testdata.fc"); | |
676 | static const wxChar *filename2 = _T("test2"); | |
677 | if ( !wxCopyFile(filename1, filename2) ) | |
678 | { | |
456ae26d | 679 | wxPuts(_T("ERROR: failed to copy file")); |
a339970a VZ |
680 | } |
681 | else | |
682 | { | |
f2cb8a17 JS |
683 | wxFFile f1(filename1, _T("rb")), |
684 | f2(filename2, _T("rb")); | |
a339970a VZ |
685 | |
686 | if ( !f1.IsOpened() || !f2.IsOpened() ) | |
687 | { | |
456ae26d | 688 | wxPuts(_T("ERROR: failed to open file(s)")); |
a339970a VZ |
689 | } |
690 | else | |
691 | { | |
692 | wxString s1, s2; | |
693 | if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) ) | |
694 | { | |
456ae26d | 695 | wxPuts(_T("ERROR: failed to read file(s)")); |
a339970a VZ |
696 | } |
697 | else | |
698 | { | |
699 | if ( (s1.length() != s2.length()) || | |
700 | (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) ) | |
701 | { | |
456ae26d | 702 | wxPuts(_T("ERROR: copy error!")); |
a339970a VZ |
703 | } |
704 | else | |
705 | { | |
456ae26d | 706 | wxPuts(_T("File was copied ok.")); |
a339970a VZ |
707 | } |
708 | } | |
709 | } | |
710 | } | |
711 | ||
712 | if ( !wxRemoveFile(filename2) ) | |
713 | { | |
456ae26d | 714 | wxPuts(_T("ERROR: failed to remove the file")); |
a339970a VZ |
715 | } |
716 | ||
e9d2bb6f | 717 | wxPuts(wxEmptyString); |
a339970a VZ |
718 | } |
719 | ||
f6bcfd97 BP |
720 | #endif // TEST_FILE |
721 | ||
ee6e1b1d VZ |
722 | // ---------------------------------------------------------------------------- |
723 | // wxFileConfig | |
724 | // ---------------------------------------------------------------------------- | |
725 | ||
726 | #ifdef TEST_FILECONF | |
727 | ||
e84010cf GD |
728 | #include "wx/confbase.h" |
729 | #include "wx/fileconf.h" | |
ee6e1b1d VZ |
730 | |
731 | static const struct FileConfTestData | |
732 | { | |
733 | const wxChar *name; // value name | |
734 | const wxChar *value; // the value from the file | |
735 | } fcTestData[] = | |
736 | { | |
737 | { _T("value1"), _T("one") }, | |
738 | { _T("value2"), _T("two") }, | |
739 | { _T("novalue"), _T("default") }, | |
740 | }; | |
741 | ||
742 | static void TestFileConfRead() | |
743 | { | |
456ae26d | 744 | wxPuts(_T("*** testing wxFileConfig loading/reading ***")); |
ee6e1b1d VZ |
745 | |
746 | wxFileConfig fileconf(_T("test"), wxEmptyString, | |
747 | _T("testdata.fc"), wxEmptyString, | |
748 | wxCONFIG_USE_RELATIVE_PATH); | |
749 | ||
750 | // test simple reading | |
456ae26d | 751 | wxPuts(_T("\nReading config file:")); |
ee6e1b1d VZ |
752 | wxString defValue(_T("default")), value; |
753 | for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ ) | |
754 | { | |
755 | const FileConfTestData& data = fcTestData[n]; | |
756 | value = fileconf.Read(data.name, defValue); | |
456ae26d | 757 | wxPrintf(_T("\t%s = %s "), data.name, value.c_str()); |
ee6e1b1d VZ |
758 | if ( value == data.value ) |
759 | { | |
456ae26d | 760 | wxPuts(_T("(ok)")); |
ee6e1b1d VZ |
761 | } |
762 | else | |
763 | { | |
456ae26d | 764 | wxPrintf(_T("(ERROR: should be %s)\n"), data.value); |
ee6e1b1d VZ |
765 | } |
766 | } | |
767 | ||
768 | // test enumerating the entries | |
456ae26d | 769 | wxPuts(_T("\nEnumerating all root entries:")); |
ee6e1b1d VZ |
770 | long dummy; |
771 | wxString name; | |
772 | bool cont = fileconf.GetFirstEntry(name, dummy); | |
773 | while ( cont ) | |
774 | { | |
456ae26d | 775 | wxPrintf(_T("\t%s = %s\n"), |
ee6e1b1d VZ |
776 | name.c_str(), |
777 | fileconf.Read(name.c_str(), _T("ERROR")).c_str()); | |
778 | ||
779 | cont = fileconf.GetNextEntry(name, dummy); | |
780 | } | |
7e0777da VZ |
781 | |
782 | static const wxChar *testEntry = _T("TestEntry"); | |
783 | wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: ")); | |
784 | fileconf.Write(testEntry, _T("A value")); | |
785 | fileconf.DeleteEntry(testEntry); | |
786 | wxPrintf(fileconf.HasEntry(testEntry) ? _T("ERROR\n") : _T("ok\n")); | |
ee6e1b1d VZ |
787 | } |
788 | ||
789 | #endif // TEST_FILECONF | |
790 | ||
844f90fb VZ |
791 | // ---------------------------------------------------------------------------- |
792 | // wxFileName | |
793 | // ---------------------------------------------------------------------------- | |
794 | ||
795 | #ifdef TEST_FILENAME | |
796 | ||
e84010cf | 797 | #include "wx/filename.h" |
844f90fb | 798 | |
e9d2bb6f | 799 | #if 0 |
5bc1deeb | 800 | static void DumpFileName(const wxChar *desc, const wxFileName& fn) |
81f25632 | 801 | { |
5bc1deeb VZ |
802 | wxPuts(desc); |
803 | ||
81f25632 VZ |
804 | wxString full = fn.GetFullPath(); |
805 | ||
806 | wxString vol, path, name, ext; | |
807 | wxFileName::SplitPath(full, &vol, &path, &name, &ext); | |
808 | ||
a5b7374f | 809 | wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"), |
81f25632 | 810 | full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str()); |
a5b7374f VZ |
811 | |
812 | wxFileName::SplitPath(full, &path, &name, &ext); | |
813 | wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"), | |
814 | path.c_str(), name.c_str(), ext.c_str()); | |
815 | ||
816 | wxPrintf(_T("path is also:\t'%s'\n"), fn.GetPath().c_str()); | |
817 | wxPrintf(_T("with volume: \t'%s'\n"), | |
818 | fn.GetPath(wxPATH_GET_VOLUME).c_str()); | |
819 | wxPrintf(_T("with separator:\t'%s'\n"), | |
820 | fn.GetPath(wxPATH_GET_SEPARATOR).c_str()); | |
821 | wxPrintf(_T("with both: \t'%s'\n"), | |
822 | fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str()); | |
9cb47ea2 VZ |
823 | |
824 | wxPuts(_T("The directories in the path are:")); | |
825 | wxArrayString dirs = fn.GetDirs(); | |
826 | size_t count = dirs.GetCount(); | |
827 | for ( size_t n = 0; n < count; n++ ) | |
828 | { | |
829 | wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str()); | |
830 | } | |
81f25632 | 831 | } |
e9d2bb6f | 832 | #endif |
81f25632 | 833 | |
ade35f11 VZ |
834 | static void TestFileNameTemp() |
835 | { | |
456ae26d | 836 | wxPuts(_T("*** testing wxFileName temp file creation ***")); |
ade35f11 | 837 | |
456ae26d | 838 | static const wxChar *tmpprefixes[] = |
ade35f11 | 839 | { |
456ae26d VZ |
840 | _T(""), |
841 | _T("foo"), | |
842 | _T(".."), | |
843 | _T("../bar"), | |
a2fa5040 | 844 | #ifdef __UNIX__ |
456ae26d VZ |
845 | _T("/tmp/foo"), |
846 | _T("/tmp/foo/bar"), // this one must be an error | |
a2fa5040 | 847 | #endif // __UNIX__ |
ade35f11 VZ |
848 | }; |
849 | ||
850 | for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ ) | |
851 | { | |
852 | wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]); | |
2db991f4 VZ |
853 | if ( path.empty() ) |
854 | { | |
855 | // "error" is not in upper case because it may be ok | |
456ae26d | 856 | wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes[n]); |
2db991f4 VZ |
857 | } |
858 | else | |
ade35f11 | 859 | { |
456ae26d | 860 | wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"), |
ade35f11 VZ |
861 | tmpprefixes[n], path.c_str()); |
862 | ||
863 | if ( !wxRemoveFile(path) ) | |
864 | { | |
456ae26d VZ |
865 | wxLogWarning(_T("Failed to remove temp file '%s'"), |
866 | path.c_str()); | |
ade35f11 VZ |
867 | } |
868 | } | |
869 | } | |
870 | } | |
871 | ||
0aa29b6b VZ |
872 | static void TestFileNameDirManip() |
873 | { | |
874 | // TODO: test AppendDir(), RemoveDir(), ... | |
875 | } | |
876 | ||
844f90fb VZ |
877 | static void TestFileNameComparison() |
878 | { | |
879 | // TODO! | |
880 | } | |
881 | ||
882 | static void TestFileNameOperations() | |
883 | { | |
884 | // TODO! | |
885 | } | |
886 | ||
887 | static void TestFileNameCwd() | |
888 | { | |
889 | // TODO! | |
890 | } | |
891 | ||
892 | #endif // TEST_FILENAME | |
893 | ||
d56e2b97 VZ |
894 | // ---------------------------------------------------------------------------- |
895 | // wxFileName time functions | |
896 | // ---------------------------------------------------------------------------- | |
897 | ||
898 | #ifdef TEST_FILETIME | |
899 | ||
b20edf8b WS |
900 | #include "wx/filename.h" |
901 | #include "wx/datetime.h" | |
d56e2b97 VZ |
902 | |
903 | static void TestFileGetTimes() | |
904 | { | |
905 | wxFileName fn(_T("testdata.fc")); | |
906 | ||
6dbb903b VZ |
907 | wxDateTime dtAccess, dtMod, dtCreate; |
908 | if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) ) | |
d56e2b97 VZ |
909 | { |
910 | wxPrintf(_T("ERROR: GetTimes() failed.\n")); | |
911 | } | |
912 | else | |
913 | { | |
914 | static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S"); | |
915 | ||
916 | wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str()); | |
6dbb903b VZ |
917 | wxPrintf(_T("Creation: \t%s\n"), dtCreate.Format(fmt).c_str()); |
918 | wxPrintf(_T("Last read: \t%s\n"), dtAccess.Format(fmt).c_str()); | |
919 | wxPrintf(_T("Last write: \t%s\n"), dtMod.Format(fmt).c_str()); | |
d56e2b97 VZ |
920 | } |
921 | } | |
922 | ||
e9d2bb6f | 923 | #if 0 |
d56e2b97 VZ |
924 | static void TestFileSetTimes() |
925 | { | |
926 | wxFileName fn(_T("testdata.fc")); | |
927 | ||
d56e2b97 VZ |
928 | if ( !fn.Touch() ) |
929 | { | |
930 | wxPrintf(_T("ERROR: Touch() failed.\n")); | |
931 | } | |
932 | } | |
e9d2bb6f | 933 | #endif |
d56e2b97 VZ |
934 | |
935 | #endif // TEST_FILETIME | |
936 | ||
ec37df57 VZ |
937 | // ---------------------------------------------------------------------------- |
938 | // wxLocale | |
939 | // ---------------------------------------------------------------------------- | |
940 | ||
941 | #ifdef TEST_LOCALE | |
942 | ||
943 | #include "wx/intl.h" | |
944 | #include "wx/utils.h" // for wxSetEnv | |
945 | ||
946 | static wxLocale gs_localeDefault(wxLANGUAGE_ENGLISH); | |
947 | ||
948 | // find the name of the language from its value | |
456ae26d VZ |
949 | static const wxChar *GetLangName(int lang) |
950 | { | |
951 | static const wxChar *languageNames[] = | |
952 | { | |
953 | _T("DEFAULT"), | |
954 | _T("UNKNOWN"), | |
955 | _T("ABKHAZIAN"), | |
956 | _T("AFAR"), | |
957 | _T("AFRIKAANS"), | |
958 | _T("ALBANIAN"), | |
959 | _T("AMHARIC"), | |
960 | _T("ARABIC"), | |
961 | _T("ARABIC_ALGERIA"), | |
962 | _T("ARABIC_BAHRAIN"), | |
963 | _T("ARABIC_EGYPT"), | |
964 | _T("ARABIC_IRAQ"), | |
965 | _T("ARABIC_JORDAN"), | |
966 | _T("ARABIC_KUWAIT"), | |
967 | _T("ARABIC_LEBANON"), | |
968 | _T("ARABIC_LIBYA"), | |
969 | _T("ARABIC_MOROCCO"), | |
970 | _T("ARABIC_OMAN"), | |
971 | _T("ARABIC_QATAR"), | |
972 | _T("ARABIC_SAUDI_ARABIA"), | |
973 | _T("ARABIC_SUDAN"), | |
974 | _T("ARABIC_SYRIA"), | |
975 | _T("ARABIC_TUNISIA"), | |
976 | _T("ARABIC_UAE"), | |
977 | _T("ARABIC_YEMEN"), | |
978 | _T("ARMENIAN"), | |
979 | _T("ASSAMESE"), | |
980 | _T("AYMARA"), | |
981 | _T("AZERI"), | |
982 | _T("AZERI_CYRILLIC"), | |
983 | _T("AZERI_LATIN"), | |
984 | _T("BASHKIR"), | |
985 | _T("BASQUE"), | |
986 | _T("BELARUSIAN"), | |
987 | _T("BENGALI"), | |
988 | _T("BHUTANI"), | |
989 | _T("BIHARI"), | |
990 | _T("BISLAMA"), | |
991 | _T("BRETON"), | |
992 | _T("BULGARIAN"), | |
993 | _T("BURMESE"), | |
994 | _T("CAMBODIAN"), | |
995 | _T("CATALAN"), | |
996 | _T("CHINESE"), | |
997 | _T("CHINESE_SIMPLIFIED"), | |
998 | _T("CHINESE_TRADITIONAL"), | |
999 | _T("CHINESE_HONGKONG"), | |
1000 | _T("CHINESE_MACAU"), | |
1001 | _T("CHINESE_SINGAPORE"), | |
1002 | _T("CHINESE_TAIWAN"), | |
1003 | _T("CORSICAN"), | |
1004 | _T("CROATIAN"), | |
1005 | _T("CZECH"), | |
1006 | _T("DANISH"), | |
1007 | _T("DUTCH"), | |
1008 | _T("DUTCH_BELGIAN"), | |
1009 | _T("ENGLISH"), | |
1010 | _T("ENGLISH_UK"), | |
1011 | _T("ENGLISH_US"), | |
1012 | _T("ENGLISH_AUSTRALIA"), | |
1013 | _T("ENGLISH_BELIZE"), | |
1014 | _T("ENGLISH_BOTSWANA"), | |
1015 | _T("ENGLISH_CANADA"), | |
1016 | _T("ENGLISH_CARIBBEAN"), | |
1017 | _T("ENGLISH_DENMARK"), | |
1018 | _T("ENGLISH_EIRE"), | |
1019 | _T("ENGLISH_JAMAICA"), | |
1020 | _T("ENGLISH_NEW_ZEALAND"), | |
1021 | _T("ENGLISH_PHILIPPINES"), | |
1022 | _T("ENGLISH_SOUTH_AFRICA"), | |
1023 | _T("ENGLISH_TRINIDAD"), | |
1024 | _T("ENGLISH_ZIMBABWE"), | |
1025 | _T("ESPERANTO"), | |
1026 | _T("ESTONIAN"), | |
1027 | _T("FAEROESE"), | |
1028 | _T("FARSI"), | |
1029 | _T("FIJI"), | |
1030 | _T("FINNISH"), | |
1031 | _T("FRENCH"), | |
1032 | _T("FRENCH_BELGIAN"), | |
1033 | _T("FRENCH_CANADIAN"), | |
1034 | _T("FRENCH_LUXEMBOURG"), | |
1035 | _T("FRENCH_MONACO"), | |
1036 | _T("FRENCH_SWISS"), | |
1037 | _T("FRISIAN"), | |
1038 | _T("GALICIAN"), | |
1039 | _T("GEORGIAN"), | |
1040 | _T("GERMAN"), | |
1041 | _T("GERMAN_AUSTRIAN"), | |
1042 | _T("GERMAN_BELGIUM"), | |
1043 | _T("GERMAN_LIECHTENSTEIN"), | |
1044 | _T("GERMAN_LUXEMBOURG"), | |
1045 | _T("GERMAN_SWISS"), | |
1046 | _T("GREEK"), | |
1047 | _T("GREENLANDIC"), | |
1048 | _T("GUARANI"), | |
1049 | _T("GUJARATI"), | |
1050 | _T("HAUSA"), | |
1051 | _T("HEBREW"), | |
1052 | _T("HINDI"), | |
1053 | _T("HUNGARIAN"), | |
1054 | _T("ICELANDIC"), | |
1055 | _T("INDONESIAN"), | |
1056 | _T("INTERLINGUA"), | |
1057 | _T("INTERLINGUE"), | |
1058 | _T("INUKTITUT"), | |
1059 | _T("INUPIAK"), | |
1060 | _T("IRISH"), | |
1061 | _T("ITALIAN"), | |
1062 | _T("ITALIAN_SWISS"), | |
1063 | _T("JAPANESE"), | |
1064 | _T("JAVANESE"), | |
1065 | _T("KANNADA"), | |
1066 | _T("KASHMIRI"), | |
1067 | _T("KASHMIRI_INDIA"), | |
1068 | _T("KAZAKH"), | |
1069 | _T("KERNEWEK"), | |
1070 | _T("KINYARWANDA"), | |
1071 | _T("KIRGHIZ"), | |
1072 | _T("KIRUNDI"), | |
1073 | _T("KONKANI"), | |
1074 | _T("KOREAN"), | |
1075 | _T("KURDISH"), | |
1076 | _T("LAOTHIAN"), | |
1077 | _T("LATIN"), | |
1078 | _T("LATVIAN"), | |
1079 | _T("LINGALA"), | |
1080 | _T("LITHUANIAN"), | |
1081 | _T("MACEDONIAN"), | |
1082 | _T("MALAGASY"), | |
1083 | _T("MALAY"), | |
1084 | _T("MALAYALAM"), | |
1085 | _T("MALAY_BRUNEI_DARUSSALAM"), | |
1086 | _T("MALAY_MALAYSIA"), | |
1087 | _T("MALTESE"), | |
1088 | _T("MANIPURI"), | |
1089 | _T("MAORI"), | |
1090 | _T("MARATHI"), | |
1091 | _T("MOLDAVIAN"), | |
1092 | _T("MONGOLIAN"), | |
1093 | _T("NAURU"), | |
1094 | _T("NEPALI"), | |
1095 | _T("NEPALI_INDIA"), | |
1096 | _T("NORWEGIAN_BOKMAL"), | |
1097 | _T("NORWEGIAN_NYNORSK"), | |
1098 | _T("OCCITAN"), | |
1099 | _T("ORIYA"), | |
1100 | _T("OROMO"), | |
1101 | _T("PASHTO"), | |
1102 | _T("POLISH"), | |
1103 | _T("PORTUGUESE"), | |
1104 | _T("PORTUGUESE_BRAZILIAN"), | |
1105 | _T("PUNJABI"), | |
1106 | _T("QUECHUA"), | |
1107 | _T("RHAETO_ROMANCE"), | |
1108 | _T("ROMANIAN"), | |
1109 | _T("RUSSIAN"), | |
1110 | _T("RUSSIAN_UKRAINE"), | |
1111 | _T("SAMOAN"), | |
1112 | _T("SANGHO"), | |
1113 | _T("SANSKRIT"), | |
1114 | _T("SCOTS_GAELIC"), | |
1115 | _T("SERBIAN"), | |
1116 | _T("SERBIAN_CYRILLIC"), | |
1117 | _T("SERBIAN_LATIN"), | |
1118 | _T("SERBO_CROATIAN"), | |
1119 | _T("SESOTHO"), | |
1120 | _T("SETSWANA"), | |
1121 | _T("SHONA"), | |
1122 | _T("SINDHI"), | |
1123 | _T("SINHALESE"), | |
1124 | _T("SISWATI"), | |
1125 | _T("SLOVAK"), | |
1126 | _T("SLOVENIAN"), | |
1127 | _T("SOMALI"), | |
1128 | _T("SPANISH"), | |
1129 | _T("SPANISH_ARGENTINA"), | |
1130 | _T("SPANISH_BOLIVIA"), | |
1131 | _T("SPANISH_CHILE"), | |
1132 | _T("SPANISH_COLOMBIA"), | |
1133 | _T("SPANISH_COSTA_RICA"), | |
1134 | _T("SPANISH_DOMINICAN_REPUBLIC"), | |
1135 | _T("SPANISH_ECUADOR"), | |
1136 | _T("SPANISH_EL_SALVADOR"), | |
1137 | _T("SPANISH_GUATEMALA"), | |
1138 | _T("SPANISH_HONDURAS"), | |
1139 | _T("SPANISH_MEXICAN"), | |
1140 | _T("SPANISH_MODERN"), | |
1141 | _T("SPANISH_NICARAGUA"), | |
1142 | _T("SPANISH_PANAMA"), | |
1143 | _T("SPANISH_PARAGUAY"), | |
1144 | _T("SPANISH_PERU"), | |
1145 | _T("SPANISH_PUERTO_RICO"), | |
1146 | _T("SPANISH_URUGUAY"), | |
1147 | _T("SPANISH_US"), | |
1148 | _T("SPANISH_VENEZUELA"), | |
1149 | _T("SUNDANESE"), | |
1150 | _T("SWAHILI"), | |
1151 | _T("SWEDISH"), | |
1152 | _T("SWEDISH_FINLAND"), | |
1153 | _T("TAGALOG"), | |
1154 | _T("TAJIK"), | |
1155 | _T("TAMIL"), | |
1156 | _T("TATAR"), | |
1157 | _T("TELUGU"), | |
1158 | _T("THAI"), | |
1159 | _T("TIBETAN"), | |
1160 | _T("TIGRINYA"), | |
1161 | _T("TONGA"), | |
1162 | _T("TSONGA"), | |
1163 | _T("TURKISH"), | |
1164 | _T("TURKMEN"), | |
1165 | _T("TWI"), | |
1166 | _T("UIGHUR"), | |
1167 | _T("UKRAINIAN"), | |
1168 | _T("URDU"), | |
1169 | _T("URDU_INDIA"), | |
1170 | _T("URDU_PAKISTAN"), | |
1171 | _T("UZBEK"), | |
1172 | _T("UZBEK_CYRILLIC"), | |
1173 | _T("UZBEK_LATIN"), | |
1174 | _T("VIETNAMESE"), | |
1175 | _T("VOLAPUK"), | |
1176 | _T("WELSH"), | |
1177 | _T("WOLOF"), | |
1178 | _T("XHOSA"), | |
1179 | _T("YIDDISH"), | |
1180 | _T("YORUBA"), | |
1181 | _T("ZHUANG"), | |
1182 | _T("ZULU"), | |
ec37df57 VZ |
1183 | }; |
1184 | ||
1185 | if ( (size_t)lang < WXSIZEOF(languageNames) ) | |
1186 | return languageNames[lang]; | |
1187 | else | |
456ae26d | 1188 | return _T("INVALID"); |
ec37df57 VZ |
1189 | } |
1190 | ||
1191 | static void TestDefaultLang() | |
1192 | { | |
456ae26d | 1193 | wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***")); |
ec37df57 VZ |
1194 | |
1195 | static const wxChar *langStrings[] = | |
1196 | { | |
1197 | NULL, // system default | |
1198 | _T("C"), | |
1199 | _T("fr"), | |
1200 | _T("fr_FR"), | |
1201 | _T("en"), | |
1202 | _T("en_GB"), | |
1203 | _T("en_US"), | |
1204 | _T("de_DE.iso88591"), | |
1205 | _T("german"), | |
1206 | _T("?"), // invalid lang spec | |
1207 | _T("klingonese"), // I bet on some systems it does exist... | |
1208 | }; | |
1209 | ||
dccce9ea VZ |
1210 | wxPrintf(_T("The default system encoding is %s (%d)\n"), |
1211 | wxLocale::GetSystemEncodingName().c_str(), | |
1212 | wxLocale::GetSystemEncoding()); | |
1213 | ||
ec37df57 VZ |
1214 | for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ ) |
1215 | { | |
456ae26d | 1216 | const wxChar *langStr = langStrings[n]; |
ec37df57 | 1217 | if ( langStr ) |
dccce9ea VZ |
1218 | { |
1219 | // FIXME: this doesn't do anything at all under Windows, we need | |
1220 | // to create a new wxLocale! | |
ec37df57 | 1221 | wxSetEnv(_T("LC_ALL"), langStr); |
dccce9ea | 1222 | } |
ec37df57 VZ |
1223 | |
1224 | int lang = gs_localeDefault.GetSystemLanguage(); | |
456ae26d VZ |
1225 | wxPrintf(_T("Locale for '%s' is %s.\n"), |
1226 | langStr ? langStr : _T("system default"), GetLangName(lang)); | |
ec37df57 VZ |
1227 | } |
1228 | } | |
1229 | ||
1230 | #endif // TEST_LOCALE | |
1231 | ||
696e1ea0 VZ |
1232 | // ---------------------------------------------------------------------------- |
1233 | // MIME types | |
1234 | // ---------------------------------------------------------------------------- | |
1235 | ||
1236 | #ifdef TEST_MIME | |
1237 | ||
e84010cf | 1238 | #include "wx/mimetype.h" |
696e1ea0 VZ |
1239 | |
1240 | static void TestMimeEnum() | |
1241 | { | |
a6c65e88 VZ |
1242 | wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n")); |
1243 | ||
696e1ea0 VZ |
1244 | wxArrayString mimetypes; |
1245 | ||
39189b9d | 1246 | size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes); |
696e1ea0 | 1247 | |
456ae26d | 1248 | wxPrintf(_T("*** All %u known filetypes: ***\n"), count); |
696e1ea0 VZ |
1249 | |
1250 | wxArrayString exts; | |
1251 | wxString desc; | |
1252 | ||
1253 | for ( size_t n = 0; n < count; n++ ) | |
1254 | { | |
39189b9d VZ |
1255 | wxFileType *filetype = |
1256 | wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]); | |
696e1ea0 | 1257 | if ( !filetype ) |
c61f4f6d | 1258 | { |
456ae26d | 1259 | wxPrintf(_T("nothing known about the filetype '%s'!\n"), |
97e0ceea | 1260 | mimetypes[n].c_str()); |
696e1ea0 | 1261 | continue; |
c61f4f6d VZ |
1262 | } |
1263 | ||
696e1ea0 VZ |
1264 | filetype->GetDescription(&desc); |
1265 | filetype->GetExtensions(exts); | |
1266 | ||
299fcbfe VZ |
1267 | filetype->GetIcon(NULL); |
1268 | ||
696e1ea0 VZ |
1269 | wxString extsAll; |
1270 | for ( size_t e = 0; e < exts.GetCount(); e++ ) | |
1271 | { | |
1272 | if ( e > 0 ) | |
1273 | extsAll << _T(", "); | |
1274 | extsAll += exts[e]; | |
1275 | } | |
1276 | ||
456ae26d | 1277 | wxPrintf(_T("\t%s: %s (%s)\n"), |
54acce90 | 1278 | mimetypes[n].c_str(), desc.c_str(), extsAll.c_str()); |
696e1ea0 | 1279 | } |
39189b9d | 1280 | |
e9d2bb6f | 1281 | wxPuts(wxEmptyString); |
696e1ea0 VZ |
1282 | } |
1283 | ||
f6bcfd97 BP |
1284 | static void TestMimeOverride() |
1285 | { | |
1286 | wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n")); | |
1287 | ||
39189b9d VZ |
1288 | static const wxChar *mailcap = _T("/tmp/mailcap"); |
1289 | static const wxChar *mimetypes = _T("/tmp/mime.types"); | |
1290 | ||
1291 | if ( wxFile::Exists(mailcap) ) | |
1292 | wxPrintf(_T("Loading mailcap from '%s': %s\n"), | |
1293 | mailcap, | |
1294 | wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR")); | |
1295 | else | |
1296 | wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), | |
1297 | mailcap); | |
f6bcfd97 | 1298 | |
39189b9d VZ |
1299 | if ( wxFile::Exists(mimetypes) ) |
1300 | wxPrintf(_T("Loading mime.types from '%s': %s\n"), | |
1301 | mimetypes, | |
1302 | wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR")); | |
1303 | else | |
1304 | wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), | |
1305 | mimetypes); | |
1306 | ||
e9d2bb6f | 1307 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
1308 | } |
1309 | ||
1310 | static void TestMimeFilename() | |
1311 | { | |
1312 | wxPuts(_T("*** Testing MIME type from filename query ***\n")); | |
1313 | ||
1314 | static const wxChar *filenames[] = | |
1315 | { | |
1316 | _T("readme.txt"), | |
1317 | _T("document.pdf"), | |
1318 | _T("image.gif"), | |
f06ef5f4 | 1319 | _T("picture.jpeg"), |
f6bcfd97 BP |
1320 | }; |
1321 | ||
1322 | for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) | |
1323 | { | |
1324 | const wxString fname = filenames[n]; | |
1325 | wxString ext = fname.AfterLast(_T('.')); | |
39189b9d | 1326 | wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); |
f6bcfd97 BP |
1327 | if ( !ft ) |
1328 | { | |
1329 | wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str()); | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | wxString desc; | |
1334 | if ( !ft->GetDescription(&desc) ) | |
1335 | desc = _T("<no description>"); | |
1336 | ||
1337 | wxString cmd; | |
1338 | if ( !ft->GetOpenCommand(&cmd, | |
e9d2bb6f | 1339 | wxFileType::MessageParameters(fname, wxEmptyString)) ) |
f6bcfd97 | 1340 | cmd = _T("<no command available>"); |
7aeebdcd | 1341 | else |
2b5f62a0 | 1342 | cmd = wxString(_T('"')) + cmd + _T('"'); |
f6bcfd97 | 1343 | |
7aeebdcd | 1344 | wxPrintf(_T("To open %s (%s) do %s.\n"), |
f6bcfd97 BP |
1345 | fname.c_str(), desc.c_str(), cmd.c_str()); |
1346 | ||
1347 | delete ft; | |
1348 | } | |
1349 | } | |
39189b9d | 1350 | |
e9d2bb6f | 1351 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
1352 | } |
1353 | ||
c7ce8392 VZ |
1354 | static void TestMimeAssociate() |
1355 | { | |
1356 | wxPuts(_T("*** Testing creation of filetype association ***\n")); | |
1357 | ||
a6c65e88 VZ |
1358 | wxFileTypeInfo ftInfo( |
1359 | _T("application/x-xyz"), | |
1360 | _T("xyzview '%s'"), // open cmd | |
1361 | _T(""), // print cmd | |
df0dc216 VZ |
1362 | _T("XYZ File"), // description |
1363 | _T(".xyz"), // extensions | |
1364 | NULL // end of extensions | |
a6c65e88 VZ |
1365 | ); |
1366 | ftInfo.SetShortDesc(_T("XYZFile")); // used under Win32 only | |
1367 | ||
39189b9d | 1368 | wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo); |
c7ce8392 VZ |
1369 | if ( !ft ) |
1370 | { | |
1371 | wxPuts(_T("ERROR: failed to create association!")); | |
1372 | } | |
1373 | else | |
1374 | { | |
a6c65e88 | 1375 | // TODO: read it back |
c7ce8392 VZ |
1376 | delete ft; |
1377 | } | |
39189b9d | 1378 | |
e9d2bb6f | 1379 | wxPuts(wxEmptyString); |
c7ce8392 VZ |
1380 | } |
1381 | ||
696e1ea0 VZ |
1382 | #endif // TEST_MIME |
1383 | ||
89e60357 VZ |
1384 | // ---------------------------------------------------------------------------- |
1385 | // misc information functions | |
1386 | // ---------------------------------------------------------------------------- | |
1387 | ||
1388 | #ifdef TEST_INFO_FUNCTIONS | |
1389 | ||
e84010cf | 1390 | #include "wx/utils.h" |
89e60357 | 1391 | |
3a994742 VZ |
1392 | static void TestDiskInfo() |
1393 | { | |
456ae26d | 1394 | wxPuts(_T("*** Testing wxGetDiskSpace() ***")); |
3a994742 VZ |
1395 | |
1396 | for ( ;; ) | |
1397 | { | |
456ae26d VZ |
1398 | wxChar pathname[128]; |
1399 | wxPrintf(_T("\nEnter a directory name: ")); | |
1400 | if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) ) | |
3a994742 VZ |
1401 | break; |
1402 | ||
1403 | // kill the last '\n' | |
456ae26d | 1404 | pathname[wxStrlen(pathname) - 1] = 0; |
3a994742 VZ |
1405 | |
1406 | wxLongLong total, free; | |
1407 | if ( !wxGetDiskSpace(pathname, &total, &free) ) | |
1408 | { | |
1409 | wxPuts(_T("ERROR: wxGetDiskSpace failed.")); | |
1410 | } | |
1411 | else | |
1412 | { | |
eadd7bd2 VZ |
1413 | wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"), |
1414 | (total / 1024).ToString().c_str(), | |
1415 | (free / 1024).ToString().c_str(), | |
3a994742 VZ |
1416 | pathname); |
1417 | } | |
1418 | } | |
1419 | } | |
1420 | ||
89e60357 VZ |
1421 | static void TestOsInfo() |
1422 | { | |
456ae26d | 1423 | wxPuts(_T("*** Testing OS info functions ***\n")); |
89e60357 VZ |
1424 | |
1425 | int major, minor; | |
1426 | wxGetOsVersion(&major, &minor); | |
456ae26d | 1427 | wxPrintf(_T("Running under: %s, version %d.%d\n"), |
89e60357 VZ |
1428 | wxGetOsDescription().c_str(), major, minor); |
1429 | ||
456ae26d | 1430 | wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory()); |
89e60357 | 1431 | |
456ae26d | 1432 | wxPrintf(_T("Host name is %s (%s).\n"), |
89e60357 | 1433 | wxGetHostName().c_str(), wxGetFullHostName().c_str()); |
bd3277fe | 1434 | |
e9d2bb6f | 1435 | wxPuts(wxEmptyString); |
89e60357 VZ |
1436 | } |
1437 | ||
1438 | static void TestUserInfo() | |
1439 | { | |
456ae26d | 1440 | wxPuts(_T("*** Testing user info functions ***\n")); |
89e60357 | 1441 | |
456ae26d VZ |
1442 | wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str()); |
1443 | wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str()); | |
1444 | wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); | |
1445 | wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str()); | |
bd3277fe | 1446 | |
e9d2bb6f | 1447 | wxPuts(wxEmptyString); |
89e60357 VZ |
1448 | } |
1449 | ||
1450 | #endif // TEST_INFO_FUNCTIONS | |
1451 | ||
39189b9d VZ |
1452 | // ---------------------------------------------------------------------------- |
1453 | // path list | |
1454 | // ---------------------------------------------------------------------------- | |
1455 | ||
1456 | #ifdef TEST_PATHLIST | |
1457 | ||
ee3ef281 VZ |
1458 | #ifdef __UNIX__ |
1459 | #define CMD_IN_PATH _T("ls") | |
1460 | #else | |
1461 | #define CMD_IN_PATH _T("command.com") | |
1462 | #endif | |
1463 | ||
39189b9d VZ |
1464 | static void TestPathList() |
1465 | { | |
456ae26d | 1466 | wxPuts(_T("*** Testing wxPathList ***\n")); |
39189b9d VZ |
1467 | |
1468 | wxPathList pathlist; | |
ee3ef281 VZ |
1469 | pathlist.AddEnvList(_T("PATH")); |
1470 | wxString path = pathlist.FindValidPath(CMD_IN_PATH); | |
39189b9d VZ |
1471 | if ( path.empty() ) |
1472 | { | |
456ae26d | 1473 | wxPrintf(_T("ERROR: command not found in the path.\n")); |
39189b9d VZ |
1474 | } |
1475 | else | |
1476 | { | |
456ae26d | 1477 | wxPrintf(_T("Command found in the path as '%s'.\n"), path.c_str()); |
39189b9d VZ |
1478 | } |
1479 | } | |
1480 | ||
1481 | #endif // TEST_PATHLIST | |
1482 | ||
07a56e45 VZ |
1483 | // ---------------------------------------------------------------------------- |
1484 | // regular expressions | |
1485 | // ---------------------------------------------------------------------------- | |
1486 | ||
1487 | #ifdef TEST_REGEX | |
1488 | ||
e84010cf | 1489 | #include "wx/regex.h" |
07a56e45 | 1490 | |
07a56e45 VZ |
1491 | static void TestRegExInteractive() |
1492 | { | |
1493 | wxPuts(_T("*** Testing RE interactively ***")); | |
1494 | ||
1495 | for ( ;; ) | |
1496 | { | |
456ae26d VZ |
1497 | wxChar pattern[128]; |
1498 | wxPrintf(_T("\nEnter a pattern: ")); | |
1499 | if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) ) | |
07a56e45 VZ |
1500 | break; |
1501 | ||
1502 | // kill the last '\n' | |
456ae26d | 1503 | pattern[wxStrlen(pattern) - 1] = 0; |
07a56e45 VZ |
1504 | |
1505 | wxRegEx re; | |
1506 | if ( !re.Compile(pattern) ) | |
1507 | { | |
1508 | continue; | |
1509 | } | |
1510 | ||
456ae26d | 1511 | wxChar text[128]; |
07a56e45 VZ |
1512 | for ( ;; ) |
1513 | { | |
456ae26d VZ |
1514 | wxPrintf(_T("Enter text to match: ")); |
1515 | if ( !wxFgets(text, WXSIZEOF(text), stdin) ) | |
07a56e45 VZ |
1516 | break; |
1517 | ||
1518 | // kill the last '\n' | |
456ae26d | 1519 | text[wxStrlen(text) - 1] = 0; |
07a56e45 VZ |
1520 | |
1521 | if ( !re.Matches(text) ) | |
1522 | { | |
456ae26d | 1523 | wxPrintf(_T("No match.\n")); |
07a56e45 VZ |
1524 | } |
1525 | else | |
1526 | { | |
456ae26d | 1527 | wxPrintf(_T("Pattern matches at '%s'\n"), re.GetMatch(text).c_str()); |
07a56e45 VZ |
1528 | |
1529 | size_t start, len; | |
1530 | for ( size_t n = 1; ; n++ ) | |
1531 | { | |
1532 | if ( !re.GetMatch(&start, &len, n) ) | |
1533 | { | |
1534 | break; | |
1535 | } | |
1536 | ||
456ae26d VZ |
1537 | wxPrintf(_T("Subexpr %u matched '%s'\n"), |
1538 | n, wxString(text + start, len).c_str()); | |
07a56e45 VZ |
1539 | } |
1540 | } | |
1541 | } | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | #endif // TEST_REGEX | |
1546 | ||
8d5eff60 VZ |
1547 | // ---------------------------------------------------------------------------- |
1548 | // database | |
1549 | // ---------------------------------------------------------------------------- | |
1550 | ||
ba6ea19e VZ |
1551 | #if !wxUSE_ODBC |
1552 | #undef TEST_ODBC | |
1553 | #endif | |
1554 | ||
8d5eff60 VZ |
1555 | #ifdef TEST_ODBC |
1556 | ||
b20edf8b | 1557 | #include "wx/db.h" |
8d5eff60 VZ |
1558 | |
1559 | static void TestDbOpen() | |
1560 | { | |
1561 | HENV henv; | |
1562 | wxDb db(henv); | |
1563 | } | |
1564 | ||
1565 | #endif // TEST_ODBC | |
1566 | ||
7aeebdcd VZ |
1567 | // ---------------------------------------------------------------------------- |
1568 | // printf() tests | |
1569 | // ---------------------------------------------------------------------------- | |
1570 | ||
1571 | /* | |
1572 | NB: this stuff was taken from the glibc test suite and modified to build | |
be5a51fb | 1573 | in wxWidgets: if I read the copyright below properly, this shouldn't |
7aeebdcd VZ |
1574 | be a problem |
1575 | */ | |
1576 | ||
1577 | #ifdef TEST_PRINTF | |
1578 | ||
1579 | #ifdef wxTEST_PRINTF | |
1580 | // use our functions from wxchar.cpp | |
1581 | #undef wxPrintf | |
1582 | #undef wxSprintf | |
1583 | ||
1584 | // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats | |
1585 | // in the tests below | |
1586 | int wxPrintf( const wxChar *format, ... ); | |
1587 | int wxSprintf( wxChar *str, const wxChar *format, ... ); | |
1588 | #endif | |
1589 | ||
f1389d46 VZ |
1590 | #include "wx/longlong.h" |
1591 | ||
7aeebdcd VZ |
1592 | #include <float.h> |
1593 | ||
1594 | static void rfg1 (void); | |
1595 | static void rfg2 (void); | |
1596 | ||
1597 | ||
1598 | static void | |
1599 | fmtchk (const wxChar *fmt) | |
1600 | { | |
1601 | (void) wxPrintf(_T("%s:\t`"), fmt); | |
1602 | (void) wxPrintf(fmt, 0x12); | |
1603 | (void) wxPrintf(_T("'\n")); | |
1604 | } | |
1605 | ||
1606 | static void | |
1607 | fmtst1chk (const wxChar *fmt) | |
1608 | { | |
1609 | (void) wxPrintf(_T("%s:\t`"), fmt); | |
1610 | (void) wxPrintf(fmt, 4, 0x12); | |
1611 | (void) wxPrintf(_T("'\n")); | |
1612 | } | |
1613 | ||
1614 | static void | |
1615 | fmtst2chk (const wxChar *fmt) | |
1616 | { | |
1617 | (void) wxPrintf(_T("%s:\t`"), fmt); | |
1618 | (void) wxPrintf(fmt, 4, 4, 0x12); | |
1619 | (void) wxPrintf(_T("'\n")); | |
1620 | } | |
1621 | ||
1622 | /* This page is covered by the following copyright: */ | |
1623 | ||
1624 | /* (C) Copyright C E Chew | |
1625 | * | |
1626 | * Feel free to copy, use and distribute this software provided: | |
1627 | * | |
1628 | * 1. you do not pretend that you wrote it | |
1629 | * 2. you leave this copyright notice intact. | |
1630 | */ | |
1631 | ||
1632 | /* | |
1633 | * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. | |
1634 | */ | |
1635 | ||
1636 | #define DEC -123 | |
1637 | #define INT 255 | |
1638 | #define UNS (~0) | |
1639 | ||
1640 | /* Formatted Output Test | |
1641 | * | |
1642 | * This exercises the output formatting code. | |
1643 | */ | |
1644 | ||
e9d2bb6f DS |
1645 | wxChar *PointerNull = NULL; |
1646 | ||
7aeebdcd VZ |
1647 | static void |
1648 | fp_test (void) | |
1649 | { | |
1650 | int i, j, k, l; | |
1651 | wxChar buf[7]; | |
1652 | wxChar *prefix = buf; | |
1653 | wxChar tp[20]; | |
1654 | ||
1655 | wxPuts(_T("\nFormatted output test")); | |
1656 | wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n")); | |
1657 | wxStrcpy(prefix, _T("%")); | |
1658 | for (i = 0; i < 2; i++) { | |
1659 | for (j = 0; j < 2; j++) { | |
1660 | for (k = 0; k < 2; k++) { | |
1661 | for (l = 0; l < 2; l++) { | |
1662 | wxStrcpy(prefix, _T("%")); | |
1663 | if (i == 0) wxStrcat(prefix, _T("-")); | |
1664 | if (j == 0) wxStrcat(prefix, _T("+")); | |
1665 | if (k == 0) wxStrcat(prefix, _T("#")); | |
1666 | if (l == 0) wxStrcat(prefix, _T("0")); | |
1667 | wxPrintf(_T("%5s |"), prefix); | |
1668 | wxStrcpy(tp, prefix); | |
1669 | wxStrcat(tp, _T("6d |")); | |
1670 | wxPrintf(tp, DEC); | |
1671 | wxStrcpy(tp, prefix); | |
1672 | wxStrcat(tp, _T("6o |")); | |
1673 | wxPrintf(tp, INT); | |
1674 | wxStrcpy(tp, prefix); | |
1675 | wxStrcat(tp, _T("6x |")); | |
1676 | wxPrintf(tp, INT); | |
1677 | wxStrcpy(tp, prefix); | |
1678 | wxStrcat(tp, _T("6X |")); | |
1679 | wxPrintf(tp, INT); | |
1680 | wxStrcpy(tp, prefix); | |
1681 | wxStrcat(tp, _T("6u |")); | |
1682 | wxPrintf(tp, UNS); | |
1683 | wxPrintf(_T("\n")); | |
1684 | } | |
1685 | } | |
1686 | } | |
1687 | } | |
e9d2bb6f DS |
1688 | wxPrintf(_T("%10s\n"), PointerNull); |
1689 | wxPrintf(_T("%-10s\n"), PointerNull); | |
7aeebdcd VZ |
1690 | } |
1691 | ||
1692 | static void TestPrintf() | |
1693 | { | |
1694 | static wxChar shortstr[] = _T("Hi, Z."); | |
f1389d46 VZ |
1695 | static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \ |
1696 | I am ready for my first lesson today."); | |
7aeebdcd | 1697 | int result = 0; |
e9d2bb6f | 1698 | wxString test_format; |
7aeebdcd VZ |
1699 | |
1700 | fmtchk(_T("%.4x")); | |
1701 | fmtchk(_T("%04x")); | |
1702 | fmtchk(_T("%4.4x")); | |
1703 | fmtchk(_T("%04.4x")); | |
1704 | fmtchk(_T("%4.3x")); | |
1705 | fmtchk(_T("%04.3x")); | |
1706 | ||
1707 | fmtst1chk(_T("%.*x")); | |
1708 | fmtst1chk(_T("%0*x")); | |
1709 | fmtst2chk(_T("%*.*x")); | |
1710 | fmtst2chk(_T("%0*.*x")); | |
1711 | ||
e9d2bb6f DS |
1712 | wxString bad_format = _T("bad format:\t\"%b\"\n"); |
1713 | wxPrintf(bad_format.c_str()); | |
7aeebdcd VZ |
1714 | wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL); |
1715 | ||
1716 | wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345); | |
1717 | wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345); | |
1718 | wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345); | |
1719 | wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L); | |
1720 | wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L); | |
1721 | wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L); | |
1722 | wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L); | |
e9d2bb6f DS |
1723 | test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n"); |
1724 | wxPrintf(test_format.c_str(), -123456); | |
7aeebdcd VZ |
1725 | wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L); |
1726 | wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); | |
1727 | ||
e9d2bb6f DS |
1728 | test_format = _T("zero-padded string:\t\"%010s\"\n"); |
1729 | wxPrintf(test_format.c_str(), shortstr); | |
1730 | test_format = _T("left-adjusted Z string:\t\"%-010s\"\n"); | |
1731 | wxPrintf(test_format.c_str(), shortstr); | |
7aeebdcd VZ |
1732 | wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr); |
1733 | wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr); | |
e9d2bb6f | 1734 | wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull); |
7aeebdcd VZ |
1735 | wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr); |
1736 | ||
1737 | wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34); | |
1738 | wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234); | |
1739 | wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234); | |
1740 | wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20); | |
1741 | wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1); | |
1742 | wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34); | |
1743 | wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234); | |
1744 | wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234); | |
1745 | wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34); | |
1746 | wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234); | |
1747 | wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234); | |
1748 | wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20); | |
1749 | ||
1750 | wxPrintf (_T(" %6.5f\n"), .099999999860301614); | |
1751 | wxPrintf (_T(" %6.5f\n"), .1); | |
1752 | wxPrintf (_T("x%5.4fx\n"), .5); | |
1753 | ||
1754 | wxPrintf (_T("%#03x\n"), 1); | |
1755 | ||
1756 | //wxPrintf (_T("something really insane: %.10000f\n"), 1.0); | |
1757 | ||
1758 | { | |
1759 | double d = FLT_MIN; | |
1760 | int niter = 17; | |
1761 | ||
1762 | while (niter-- != 0) | |
1763 | wxPrintf (_T("%.17e\n"), d / 2); | |
1764 | fflush (stdout); | |
1765 | } | |
1766 | ||
e9d2bb6f DS |
1767 | #ifndef __WATCOMC__ |
1768 | // Open Watcom cause compiler error here | |
1769 | // Error! E173: col(24) floating-point constant too small to represent | |
7aeebdcd | 1770 | wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324); |
e9d2bb6f | 1771 | #endif |
7aeebdcd VZ |
1772 | |
1773 | #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n") | |
1774 | wxPrintf (FORMAT, 0.0, 0.0, 0.0); | |
1775 | wxPrintf (FORMAT, 1.0, 1.0, 1.0); | |
1776 | wxPrintf (FORMAT, -1.0, -1.0, -1.0); | |
1777 | wxPrintf (FORMAT, 100.0, 100.0, 100.0); | |
1778 | wxPrintf (FORMAT, 1000.0, 1000.0, 1000.0); | |
1779 | wxPrintf (FORMAT, 10000.0, 10000.0, 10000.0); | |
1780 | wxPrintf (FORMAT, 12345.0, 12345.0, 12345.0); | |
1781 | wxPrintf (FORMAT, 100000.0, 100000.0, 100000.0); | |
1782 | wxPrintf (FORMAT, 123456.0, 123456.0, 123456.0); | |
1783 | #undef FORMAT | |
1784 | ||
1785 | { | |
1786 | wxChar buf[20]; | |
1787 | int rc = wxSnprintf (buf, WXSIZEOF(buf), _T("%30s"), _T("foo")); | |
1788 | ||
1789 | wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"), | |
1790 | rc, WXSIZEOF(buf), buf); | |
1791 | #if 0 | |
1792 | wxChar buf2[512]; | |
1793 | wxPrintf ("snprintf (\"%%.999999u\", 10)\n", | |
1794 | wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10)); | |
1795 | #endif | |
1796 | } | |
1797 | ||
1798 | fp_test (); | |
1799 | ||
1800 | wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8); | |
1801 | wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8); | |
1802 | wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8); | |
1803 | wxPrintf (_T("%g should be 123.456\n"), 123.456); | |
1804 | wxPrintf (_T("%g should be 1e+06\n"), 1000000.0); | |
1805 | wxPrintf (_T("%g should be 10\n"), 10.0); | |
1806 | wxPrintf (_T("%g should be 0.02\n"), 0.02); | |
1807 | ||
1808 | { | |
1809 | double x=1.0; | |
1810 | wxPrintf(_T("%.17f\n"),(1.0/x/10.0+1.0)*x-x); | |
1811 | } | |
1812 | ||
1813 | { | |
1814 | wxChar buf[200]; | |
1815 | ||
1816 | wxSprintf(buf,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three")); | |
1817 | ||
1818 | result |= wxStrcmp (buf, | |
1819 | _T("onetwo three ")); | |
1820 | ||
1821 | wxPuts (result != 0 ? _T("Test failed!") : _T("Test ok.")); | |
1822 | } | |
1823 | ||
f1389d46 | 1824 | #ifdef wxLongLong_t |
7aeebdcd | 1825 | { |
f1389d46 | 1826 | wxChar buf[200]; |
7aeebdcd | 1827 | |
2b5f62a0 | 1828 | wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000)); |
f2cb8a17 JS |
1829 | #if 0 |
1830 | // for some reason below line fails under Borland | |
f1389d46 | 1831 | wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf); |
f2cb8a17 | 1832 | #endif |
7aeebdcd | 1833 | |
f1389d46 | 1834 | if (wxStrcmp (buf, _T("40000000000")) != 0) |
7aeebdcd | 1835 | { |
f1389d46 VZ |
1836 | result = 1; |
1837 | wxPuts (_T("\tFAILED")); | |
7aeebdcd | 1838 | } |
e9d2bb6f DS |
1839 | wxUnusedVar(result); |
1840 | wxPuts (wxEmptyString); | |
7aeebdcd | 1841 | } |
f1389d46 | 1842 | #endif // wxLongLong_t |
7aeebdcd VZ |
1843 | |
1844 | wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX + 2, UCHAR_MAX + 2); | |
1845 | wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX + 2, USHRT_MAX + 2); | |
1846 | ||
1847 | wxPuts (_T("--- Should be no further output. ---")); | |
1848 | rfg1 (); | |
1849 | rfg2 (); | |
1850 | ||
1851 | #if 0 | |
1852 | { | |
1853 | wxChar bytes[7]; | |
1854 | wxChar buf[20]; | |
1855 | ||
1856 | memset (bytes, '\xff', sizeof bytes); | |
1857 | wxSprintf (buf, _T("foo%hhn\n"), &bytes[3]); | |
1858 | if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff' | |
1859 | || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff') | |
1860 | { | |
1861 | wxPuts (_T("%hhn overwrite more bytes")); | |
1862 | result = 1; | |
1863 | } | |
1864 | if (bytes[3] != 3) | |
1865 | { | |
1866 | wxPuts (_T("%hhn wrote incorrect value")); | |
1867 | result = 1; | |
1868 | } | |
1869 | } | |
1870 | #endif | |
1871 | } | |
1872 | ||
1873 | static void | |
1874 | rfg1 (void) | |
1875 | { | |
1876 | wxChar buf[100]; | |
1877 | ||
1878 | wxSprintf (buf, _T("%5.s"), _T("xyz")); | |
1879 | if (wxStrcmp (buf, _T(" ")) != 0) | |
1880 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" ")); | |
1881 | wxSprintf (buf, _T("%5.f"), 33.3); | |
1882 | if (wxStrcmp (buf, _T(" 33")) != 0) | |
1883 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 33")); | |
1884 | wxSprintf (buf, _T("%8.e"), 33.3e7); | |
1885 | if (wxStrcmp (buf, _T(" 3e+08")) != 0) | |
1886 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3e+08")); | |
1887 | wxSprintf (buf, _T("%8.E"), 33.3e7); | |
1888 | if (wxStrcmp (buf, _T(" 3E+08")) != 0) | |
1889 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3E+08")); | |
1890 | wxSprintf (buf, _T("%.g"), 33.3); | |
1891 | if (wxStrcmp (buf, _T("3e+01")) != 0) | |
1892 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3e+01")); | |
1893 | wxSprintf (buf, _T("%.G"), 33.3); | |
1894 | if (wxStrcmp (buf, _T("3E+01")) != 0) | |
1895 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3E+01")); | |
1896 | } | |
1897 | ||
1898 | static void | |
1899 | rfg2 (void) | |
1900 | { | |
1901 | int prec; | |
1902 | wxChar buf[100]; | |
e9d2bb6f | 1903 | wxString test_format; |
7aeebdcd VZ |
1904 | |
1905 | prec = 0; | |
1906 | wxSprintf (buf, _T("%.*g"), prec, 3.3); | |
1907 | if (wxStrcmp (buf, _T("3")) != 0) | |
1908 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3")); | |
1909 | prec = 0; | |
1910 | wxSprintf (buf, _T("%.*G"), prec, 3.3); | |
1911 | if (wxStrcmp (buf, _T("3")) != 0) | |
1912 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3")); | |
1913 | prec = 0; | |
1914 | wxSprintf (buf, _T("%7.*G"), prec, 3.33); | |
1915 | if (wxStrcmp (buf, _T(" 3")) != 0) | |
1916 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3")); | |
1917 | prec = 3; | |
e9d2bb6f DS |
1918 | test_format = _T("%04.*o"); |
1919 | wxSprintf (buf, test_format.c_str(), prec, 33); | |
7aeebdcd VZ |
1920 | if (wxStrcmp (buf, _T(" 041")) != 0) |
1921 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041")); | |
1922 | prec = 7; | |
e9d2bb6f DS |
1923 | test_format = _T("%09.*u"); |
1924 | wxSprintf (buf, test_format.c_str(), prec, 33); | |
7aeebdcd VZ |
1925 | if (wxStrcmp (buf, _T(" 0000033")) != 0) |
1926 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033")); | |
1927 | prec = 3; | |
e9d2bb6f DS |
1928 | test_format = _T("%04.*x"); |
1929 | wxSprintf (buf, test_format.c_str(), prec, 33); | |
7aeebdcd VZ |
1930 | if (wxStrcmp (buf, _T(" 021")) != 0) |
1931 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); | |
1932 | prec = 3; | |
e9d2bb6f DS |
1933 | test_format = _T("%04.*X"); |
1934 | wxSprintf (buf, test_format.c_str(), prec, 33); | |
7aeebdcd VZ |
1935 | if (wxStrcmp (buf, _T(" 021")) != 0) |
1936 | wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); | |
1937 | } | |
1938 | ||
1939 | #endif // TEST_PRINTF | |
1940 | ||
6dfec4b8 | 1941 | // ---------------------------------------------------------------------------- |
7ba4fbeb | 1942 | // registry and related stuff |
6dfec4b8 VZ |
1943 | // ---------------------------------------------------------------------------- |
1944 | ||
1945 | // this is for MSW only | |
1946 | #ifndef __WXMSW__ | |
7ba4fbeb | 1947 | #undef TEST_REGCONF |
6dfec4b8 VZ |
1948 | #undef TEST_REGISTRY |
1949 | #endif | |
1950 | ||
7ba4fbeb VZ |
1951 | #ifdef TEST_REGCONF |
1952 | ||
e84010cf GD |
1953 | #include "wx/confbase.h" |
1954 | #include "wx/msw/regconf.h" | |
7ba4fbeb | 1955 | |
e9d2bb6f | 1956 | #if 0 |
7ba4fbeb VZ |
1957 | static void TestRegConfWrite() |
1958 | { | |
e9d2bb6f DS |
1959 | wxConfig *config = new wxConfig(_T("myapp")); |
1960 | config->SetPath(_T("/group1")); | |
1961 | config->Write(_T("entry1"), _T("foo")); | |
1962 | config->SetPath(_T("/group2")); | |
1963 | config->Write(_T("entry1"), _T("bar")); | |
0aa29b6b | 1964 | } |
e9d2bb6f | 1965 | #endif |
0aa29b6b VZ |
1966 | |
1967 | static void TestRegConfRead() | |
1968 | { | |
e9d2bb6f | 1969 | wxConfig *config = new wxConfig(_T("myapp")); |
0aa29b6b VZ |
1970 | |
1971 | wxString str; | |
1972 | long dummy; | |
e9d2bb6f DS |
1973 | config->SetPath(_T("/")); |
1974 | wxPuts(_T("Enumerating / subgroups:")); | |
0aa29b6b VZ |
1975 | bool bCont = config->GetFirstGroup(str, dummy); |
1976 | while(bCont) | |
1977 | { | |
e9d2bb6f | 1978 | wxPuts(str); |
0aa29b6b VZ |
1979 | bCont = config->GetNextGroup(str, dummy); |
1980 | } | |
7ba4fbeb VZ |
1981 | } |
1982 | ||
1983 | #endif // TEST_REGCONF | |
1984 | ||
6dfec4b8 VZ |
1985 | #ifdef TEST_REGISTRY |
1986 | ||
e84010cf | 1987 | #include "wx/msw/registry.h" |
6dfec4b8 VZ |
1988 | |
1989 | // I chose this one because I liked its name, but it probably only exists under | |
1990 | // NT | |
1991 | static const wxChar *TESTKEY = | |
1992 | _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl"); | |
1993 | ||
1994 | static void TestRegistryRead() | |
1995 | { | |
456ae26d | 1996 | wxPuts(_T("*** testing registry reading ***")); |
6dfec4b8 VZ |
1997 | |
1998 | wxRegKey key(TESTKEY); | |
456ae26d | 1999 | wxPrintf(_T("The test key name is '%s'.\n"), key.GetName().c_str()); |
6dfec4b8 VZ |
2000 | if ( !key.Open() ) |
2001 | { | |
456ae26d | 2002 | wxPuts(_T("ERROR: test key can't be opened, aborting test.")); |
6dfec4b8 VZ |
2003 | |
2004 | return; | |
2005 | } | |
2006 | ||
2007 | size_t nSubKeys, nValues; | |
2008 | if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) ) | |
2009 | { | |
456ae26d | 2010 | wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys, nValues); |
6dfec4b8 VZ |
2011 | } |
2012 | ||
456ae26d | 2013 | wxPrintf(_T("Enumerating values:\n")); |
6dfec4b8 VZ |
2014 | |
2015 | long dummy; | |
2016 | wxString value; | |
2017 | bool cont = key.GetFirstValue(value, dummy); | |
2018 | while ( cont ) | |
2019 | { | |
456ae26d | 2020 | wxPrintf(_T("Value '%s': type "), value.c_str()); |
6dfec4b8 VZ |
2021 | switch ( key.GetValueType(value) ) |
2022 | { | |
456ae26d VZ |
2023 | case wxRegKey::Type_None: wxPrintf(_T("ERROR (none)")); break; |
2024 | case wxRegKey::Type_String: wxPrintf(_T("SZ")); break; | |
2025 | case wxRegKey::Type_Expand_String: wxPrintf(_T("EXPAND_SZ")); break; | |
2026 | case wxRegKey::Type_Binary: wxPrintf(_T("BINARY")); break; | |
2027 | case wxRegKey::Type_Dword: wxPrintf(_T("DWORD")); break; | |
2028 | case wxRegKey::Type_Multi_String: wxPrintf(_T("MULTI_SZ")); break; | |
2029 | default: wxPrintf(_T("other (unknown)")); break; | |
6dfec4b8 VZ |
2030 | } |
2031 | ||
456ae26d | 2032 | wxPrintf(_T(", value = ")); |
6dfec4b8 VZ |
2033 | if ( key.IsNumericValue(value) ) |
2034 | { | |
2035 | long val; | |
2036 | key.QueryValue(value, &val); | |
456ae26d | 2037 | wxPrintf(_T("%ld"), val); |
6dfec4b8 VZ |
2038 | } |
2039 | else // string | |
2040 | { | |
2041 | wxString val; | |
2042 | key.QueryValue(value, val); | |
456ae26d | 2043 | wxPrintf(_T("'%s'"), val.c_str()); |
6dfec4b8 VZ |
2044 | |
2045 | key.QueryRawValue(value, val); | |
456ae26d | 2046 | wxPrintf(_T(" (raw value '%s')"), val.c_str()); |
6dfec4b8 VZ |
2047 | } |
2048 | ||
e9d2bb6f | 2049 | wxPutchar('\n'); |
6dfec4b8 VZ |
2050 | |
2051 | cont = key.GetNextValue(value, dummy); | |
2052 | } | |
2053 | } | |
2054 | ||
6ba63600 VZ |
2055 | static void TestRegistryAssociation() |
2056 | { | |
2057 | /* | |
2058 | The second call to deleteself genertaes an error message, with a | |
2059 | messagebox saying .flo is crucial to system operation, while the .ddf | |
2060 | call also fails, but with no error message | |
2061 | */ | |
2062 | ||
2063 | wxRegKey key; | |
2064 | ||
f2cb8a17 | 2065 | key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); |
6ba63600 | 2066 | key.Create(); |
f2cb8a17 JS |
2067 | key = _T("ddxf_auto_file") ; |
2068 | key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); | |
6ba63600 | 2069 | key.Create(); |
f2cb8a17 JS |
2070 | key = _T("ddxf_auto_file") ; |
2071 | key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); | |
6ba63600 | 2072 | key.Create(); |
f2cb8a17 JS |
2073 | key = _T("program,0") ; |
2074 | key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); | |
6ba63600 | 2075 | key.Create(); |
f2cb8a17 | 2076 | key = _T("program \"%1\"") ; |
6ba63600 | 2077 | |
f2cb8a17 | 2078 | key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); |
6ba63600 | 2079 | key.DeleteSelf(); |
f2cb8a17 | 2080 | key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); |
6ba63600 | 2081 | key.DeleteSelf(); |
f2cb8a17 | 2082 | key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); |
6ba63600 | 2083 | key.DeleteSelf(); |
f2cb8a17 | 2084 | key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); |
6ba63600 VZ |
2085 | key.DeleteSelf(); |
2086 | } | |
2087 | ||
6dfec4b8 VZ |
2088 | #endif // TEST_REGISTRY |
2089 | ||
c66cca2a VZ |
2090 | // ---------------------------------------------------------------------------- |
2091 | // scope guard | |
2092 | // ---------------------------------------------------------------------------- | |
2093 | ||
df5168c4 MB |
2094 | #ifdef TEST_SCOPEGUARD |
2095 | ||
c66cca2a VZ |
2096 | #include "wx/scopeguard.h" |
2097 | ||
2098 | static void function0() { puts("function0()"); } | |
2099 | static void function1(int n) { printf("function1(%d)\n", n); } | |
2100 | static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); } | |
2101 | ||
2102 | struct Object | |
2103 | { | |
2104 | void method0() { printf("method0()\n"); } | |
2105 | void method1(int n) { printf("method1(%d)\n", n); } | |
2106 | void method2(double x, char c) { printf("method2(%g, %c)\n", x, c); } | |
2107 | }; | |
2108 | ||
2109 | static void TestScopeGuard() | |
2110 | { | |
24c8053b RN |
2111 | wxON_BLOCK_EXIT0(function0); |
2112 | wxON_BLOCK_EXIT1(function1, 17); | |
2113 | wxON_BLOCK_EXIT2(function2, 3.14, 'p'); | |
c66cca2a VZ |
2114 | |
2115 | Object obj; | |
eb42e596 VZ |
2116 | wxON_BLOCK_EXIT_OBJ0(obj, Object::method0); |
2117 | wxON_BLOCK_EXIT_OBJ1(obj, Object::method1, 7); | |
2118 | wxON_BLOCK_EXIT_OBJ2(obj, Object::method2, 2.71, 'e'); | |
c66cca2a VZ |
2119 | |
2120 | wxScopeGuard dismissed = wxMakeGuard(function0); | |
2121 | dismissed.Dismiss(); | |
2122 | } | |
2123 | ||
df5168c4 MB |
2124 | #endif |
2125 | ||
2c8e4738 VZ |
2126 | // ---------------------------------------------------------------------------- |
2127 | // sockets | |
2128 | // ---------------------------------------------------------------------------- | |
2129 | ||
2130 | #ifdef TEST_SOCKETS | |
2131 | ||
e84010cf GD |
2132 | #include "wx/socket.h" |
2133 | #include "wx/protocol/protocol.h" | |
2134 | #include "wx/protocol/http.h" | |
8e907a13 VZ |
2135 | |
2136 | static void TestSocketServer() | |
2137 | { | |
456ae26d | 2138 | wxPuts(_T("*** Testing wxSocketServer ***\n")); |
8e907a13 | 2139 | |
ccdb23df VZ |
2140 | static const int PORT = 3000; |
2141 | ||
8e907a13 | 2142 | wxIPV4address addr; |
ccdb23df | 2143 | addr.Service(PORT); |
8e907a13 VZ |
2144 | |
2145 | wxSocketServer *server = new wxSocketServer(addr); | |
2146 | if ( !server->Ok() ) | |
2147 | { | |
456ae26d | 2148 | wxPuts(_T("ERROR: failed to bind")); |
ccdb23df VZ |
2149 | |
2150 | return; | |
8e907a13 | 2151 | } |
8dfea369 | 2152 | |
cab8f76e VZ |
2153 | bool quit = false; |
2154 | while ( !quit ) | |
8dfea369 | 2155 | { |
456ae26d | 2156 | wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT); |
8dfea369 VZ |
2157 | |
2158 | wxSocketBase *socket = server->Accept(); | |
2159 | if ( !socket ) | |
2160 | { | |
456ae26d | 2161 | wxPuts(_T("ERROR: wxSocketServer::Accept() failed.")); |
8dfea369 VZ |
2162 | break; |
2163 | } | |
2164 | ||
456ae26d | 2165 | wxPuts(_T("Server: got a client.")); |
8dfea369 | 2166 | |
ccdb23df VZ |
2167 | server->SetTimeout(60); // 1 min |
2168 | ||
cab8f76e VZ |
2169 | bool close = false; |
2170 | while ( !close && socket->IsConnected() ) | |
8dfea369 | 2171 | { |
ccdb23df | 2172 | wxString s; |
456ae26d | 2173 | wxChar ch = _T('\0'); |
ccdb23df | 2174 | for ( ;; ) |
8dfea369 | 2175 | { |
ccdb23df VZ |
2176 | if ( socket->Read(&ch, sizeof(ch)).Error() ) |
2177 | { | |
2178 | // don't log error if the client just close the connection | |
2179 | if ( socket->IsConnected() ) | |
2180 | { | |
456ae26d | 2181 | wxPuts(_T("ERROR: in wxSocket::Read.")); |
ccdb23df | 2182 | } |
8dfea369 | 2183 | |
ccdb23df VZ |
2184 | break; |
2185 | } | |
8dfea369 | 2186 | |
ccdb23df VZ |
2187 | if ( ch == '\r' ) |
2188 | continue; | |
8dfea369 | 2189 | |
ccdb23df VZ |
2190 | if ( ch == '\n' ) |
2191 | break; | |
8dfea369 | 2192 | |
ccdb23df VZ |
2193 | s += ch; |
2194 | } | |
8dfea369 | 2195 | |
ccdb23df VZ |
2196 | if ( ch != '\n' ) |
2197 | { | |
2198 | break; | |
2199 | } | |
8dfea369 | 2200 | |
456ae26d | 2201 | wxPrintf(_T("Server: got '%s'.\n"), s.c_str()); |
cab8f76e | 2202 | if ( s == _T("close") ) |
ccdb23df | 2203 | { |
cab8f76e | 2204 | wxPuts(_T("Closing connection")); |
8dfea369 | 2205 | |
cab8f76e | 2206 | close = true; |
ccdb23df | 2207 | } |
cab8f76e VZ |
2208 | else if ( s == _T("quit") ) |
2209 | { | |
2210 | close = | |
2211 | quit = true; | |
ccdb23df | 2212 | |
cab8f76e VZ |
2213 | wxPuts(_T("Shutting down the server")); |
2214 | } | |
2215 | else // not a special command | |
2216 | { | |
2217 | socket->Write(s.MakeUpper().c_str(), s.length()); | |
2218 | socket->Write("\r\n", 2); | |
2219 | wxPrintf(_T("Server: wrote '%s'.\n"), s.c_str()); | |
2220 | } | |
8dfea369 VZ |
2221 | } |
2222 | ||
cab8f76e VZ |
2223 | if ( !close ) |
2224 | { | |
2225 | wxPuts(_T("Server: lost a client unexpectedly.")); | |
2226 | } | |
8dfea369 | 2227 | |
ccdb23df | 2228 | socket->Destroy(); |
8dfea369 | 2229 | } |
9fc3cba7 | 2230 | |
ccdb23df VZ |
2231 | // same as "delete server" but is consistent with GUI programs |
2232 | server->Destroy(); | |
8e907a13 | 2233 | } |
2c8e4738 VZ |
2234 | |
2235 | static void TestSocketClient() | |
2236 | { | |
456ae26d | 2237 | wxPuts(_T("*** Testing wxSocketClient ***\n")); |
2c8e4738 | 2238 | |
be5a51fb | 2239 | static const wxChar *hostname = _T("www.wxwidgets.org"); |
8e907a13 VZ |
2240 | |
2241 | wxIPV4address addr; | |
2242 | addr.Hostname(hostname); | |
2243 | addr.Service(80); | |
2244 | ||
456ae26d | 2245 | wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname); |
2c8e4738 VZ |
2246 | |
2247 | wxSocketClient client; | |
8e907a13 | 2248 | if ( !client.Connect(addr) ) |
2c8e4738 | 2249 | { |
456ae26d | 2250 | wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname); |
2c8e4738 VZ |
2251 | } |
2252 | else | |
2253 | { | |
456ae26d | 2254 | wxPrintf(_T("--- Connected to %s:%u...\n"), |
8e907a13 VZ |
2255 | addr.Hostname().c_str(), addr.Service()); |
2256 | ||
456ae26d | 2257 | wxChar buf[8192]; |
2c8e4738 | 2258 | |
8e907a13 VZ |
2259 | // could use simply "GET" here I suppose |
2260 | wxString cmdGet = | |
456ae26d | 2261 | wxString::Format(_T("GET http://%s/\r\n"), hostname); |
8e907a13 | 2262 | client.Write(cmdGet, cmdGet.length()); |
456ae26d | 2263 | wxPrintf(_T("--- Sent command '%s' to the server\n"), |
8e907a13 | 2264 | MakePrintable(cmdGet).c_str()); |
2c8e4738 | 2265 | client.Read(buf, WXSIZEOF(buf)); |
456ae26d | 2266 | wxPrintf(_T("--- Server replied:\n%s"), buf); |
8e907a13 VZ |
2267 | } |
2268 | } | |
2269 | ||
2e907fab VZ |
2270 | #endif // TEST_SOCKETS |
2271 | ||
b92fd37c VZ |
2272 | // ---------------------------------------------------------------------------- |
2273 | // FTP | |
2274 | // ---------------------------------------------------------------------------- | |
2275 | ||
2e907fab VZ |
2276 | #ifdef TEST_FTP |
2277 | ||
e84010cf | 2278 | #include "wx/protocol/ftp.h" |
2e907fab | 2279 | |
b92fd37c VZ |
2280 | static wxFTP ftp; |
2281 | ||
2282 | #define FTP_ANONYMOUS | |
2283 | ||
2284 | #ifdef FTP_ANONYMOUS | |
456ae26d VZ |
2285 | static const wxChar *directory = _T("/pub"); |
2286 | static const wxChar *filename = _T("welcome.msg"); | |
b92fd37c | 2287 | #else |
456ae26d VZ |
2288 | static const wxChar *directory = _T("/etc"); |
2289 | static const wxChar *filename = _T("issue"); | |
b92fd37c VZ |
2290 | #endif |
2291 | ||
2292 | static bool TestFtpConnect() | |
8e907a13 | 2293 | { |
456ae26d | 2294 | wxPuts(_T("*** Testing FTP connect ***")); |
8e907a13 | 2295 | |
b92fd37c | 2296 | #ifdef FTP_ANONYMOUS |
be5a51fb | 2297 | static const wxChar *hostname = _T("ftp.wxwidgets.org"); |
b92fd37c | 2298 | |
456ae26d | 2299 | wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname); |
b92fd37c | 2300 | #else // !FTP_ANONYMOUS |
456ae26d | 2301 | static const wxChar *hostname = "localhost"; |
b92fd37c | 2302 | |
456ae26d VZ |
2303 | wxChar user[256]; |
2304 | wxFgets(user, WXSIZEOF(user), stdin); | |
2305 | user[wxStrlen(user) - 1] = '\0'; // chop off '\n' | |
b92fd37c VZ |
2306 | ftp.SetUser(user); |
2307 | ||
456ae26d VZ |
2308 | wxChar password[256]; |
2309 | wxPrintf(_T("Password for %s: "), password); | |
2310 | wxFgets(password, WXSIZEOF(password), stdin); | |
2311 | password[wxStrlen(password) - 1] = '\0'; // chop off '\n' | |
b92fd37c VZ |
2312 | ftp.SetPassword(password); |
2313 | ||
456ae26d | 2314 | wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname, user); |
b92fd37c VZ |
2315 | #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS |
2316 | ||
2317 | if ( !ftp.Connect(hostname) ) | |
2318 | { | |
456ae26d | 2319 | wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname); |
b92fd37c | 2320 | |
cab8f76e | 2321 | return false; |
b92fd37c VZ |
2322 | } |
2323 | else | |
2324 | { | |
456ae26d | 2325 | wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"), |
af33b199 VZ |
2326 | hostname, ftp.Pwd().c_str()); |
2327 | ftp.Close(); | |
b92fd37c VZ |
2328 | } |
2329 | ||
cab8f76e | 2330 | return true; |
b92fd37c | 2331 | } |
b1229561 | 2332 | |
b92fd37c VZ |
2333 | // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0? |
2334 | static void TestFtpWuFtpd() | |
2335 | { | |
2336 | wxFTP ftp; | |
456ae26d | 2337 | static const wxChar *hostname = _T("ftp.eudora.com"); |
b1229561 VZ |
2338 | if ( !ftp.Connect(hostname) ) |
2339 | { | |
456ae26d | 2340 | wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname); |
b1229561 VZ |
2341 | } |
2342 | else | |
2343 | { | |
456ae26d | 2344 | static const wxChar *filename = _T("eudora/pubs/draft-gellens-submit-09.txt"); |
b1229561 VZ |
2345 | wxInputStream *in = ftp.GetInputStream(filename); |
2346 | if ( !in ) | |
2347 | { | |
456ae26d | 2348 | wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename); |
b1229561 VZ |
2349 | } |
2350 | else | |
2351 | { | |
4c51b688 | 2352 | size_t size = in->GetSize(); |
456ae26d | 2353 | wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size); |
b1229561 | 2354 | |
456ae26d | 2355 | wxChar *data = new wxChar[size]; |
b1229561 VZ |
2356 | if ( !in->Read(data, size) ) |
2357 | { | |
456ae26d | 2358 | wxPuts(_T("ERROR: read error")); |
b1229561 VZ |
2359 | } |
2360 | else | |
2361 | { | |
456ae26d | 2362 | wxPrintf(_T("Successfully retrieved the file.\n")); |
b1229561 VZ |
2363 | } |
2364 | ||
2365 | delete [] data; | |
2366 | delete in; | |
2367 | } | |
2368 | } | |
b92fd37c | 2369 | } |
b1229561 | 2370 | |
b92fd37c VZ |
2371 | static void TestFtpList() |
2372 | { | |
456ae26d | 2373 | wxPuts(_T("*** Testing wxFTP file listing ***\n")); |
8e907a13 | 2374 | |
b92fd37c VZ |
2375 | // test CWD |
2376 | if ( !ftp.ChDir(directory) ) | |
2377 | { | |
456ae26d | 2378 | wxPrintf(_T("ERROR: failed to cd to %s\n"), directory); |
b92fd37c | 2379 | } |
2e907fab | 2380 | |
456ae26d | 2381 | wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str()); |
2e907fab | 2382 | |
b92fd37c VZ |
2383 | // test NLIST and LIST |
2384 | wxArrayString files; | |
2385 | if ( !ftp.GetFilesList(files) ) | |
8e907a13 | 2386 | { |
456ae26d | 2387 | wxPuts(_T("ERROR: failed to get NLIST of files")); |
8e907a13 VZ |
2388 | } |
2389 | else | |
2390 | { | |
456ae26d | 2391 | wxPrintf(_T("Brief list of files under '%s':\n"), ftp.Pwd().c_str()); |
b92fd37c VZ |
2392 | size_t count = files.GetCount(); |
2393 | for ( size_t n = 0; n < count; n++ ) | |
8e907a13 | 2394 | { |
456ae26d | 2395 | wxPrintf(_T("\t%s\n"), files[n].c_str()); |
8e907a13 | 2396 | } |
456ae26d | 2397 | wxPuts(_T("End of the file list")); |
b92fd37c | 2398 | } |
8e907a13 | 2399 | |
b92fd37c VZ |
2400 | if ( !ftp.GetDirList(files) ) |
2401 | { | |
456ae26d | 2402 | wxPuts(_T("ERROR: failed to get LIST of files")); |
b92fd37c VZ |
2403 | } |
2404 | else | |
2405 | { | |
456ae26d | 2406 | wxPrintf(_T("Detailed list of files under '%s':\n"), ftp.Pwd().c_str()); |
b92fd37c VZ |
2407 | size_t count = files.GetCount(); |
2408 | for ( size_t n = 0; n < count; n++ ) | |
8e907a13 | 2409 | { |
456ae26d | 2410 | wxPrintf(_T("\t%s\n"), files[n].c_str()); |
2e907fab | 2411 | } |
456ae26d | 2412 | wxPuts(_T("End of the file list")); |
b92fd37c VZ |
2413 | } |
2414 | ||
2415 | if ( !ftp.ChDir(_T("..")) ) | |
2416 | { | |
456ae26d | 2417 | wxPuts(_T("ERROR: failed to cd to ..")); |
b92fd37c | 2418 | } |
2e907fab | 2419 | |
456ae26d | 2420 | wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str()); |
b92fd37c VZ |
2421 | } |
2422 | ||
2423 | static void TestFtpDownload() | |
2424 | { | |
456ae26d | 2425 | wxPuts(_T("*** Testing wxFTP download ***\n")); |
b92fd37c VZ |
2426 | |
2427 | // test RETR | |
2428 | wxInputStream *in = ftp.GetInputStream(filename); | |
2429 | if ( !in ) | |
2430 | { | |
456ae26d | 2431 | wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename); |
b92fd37c VZ |
2432 | } |
2433 | else | |
2434 | { | |
4c51b688 | 2435 | size_t size = in->GetSize(); |
456ae26d | 2436 | wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size); |
b92fd37c VZ |
2437 | fflush(stdout); |
2438 | ||
456ae26d | 2439 | wxChar *data = new wxChar[size]; |
b92fd37c | 2440 | if ( !in->Read(data, size) ) |
2e907fab | 2441 | { |
456ae26d | 2442 | wxPuts(_T("ERROR: read error")); |
2e907fab VZ |
2443 | } |
2444 | else | |
2445 | { | |
456ae26d | 2446 | wxPrintf(_T("\nContents of %s:\n%s\n"), filename, data); |
8e907a13 VZ |
2447 | } |
2448 | ||
b92fd37c VZ |
2449 | delete [] data; |
2450 | delete in; | |
2451 | } | |
2452 | } | |
8e907a13 | 2453 | |
b92fd37c VZ |
2454 | static void TestFtpFileSize() |
2455 | { | |
456ae26d | 2456 | wxPuts(_T("*** Testing FTP SIZE command ***")); |
b92fd37c VZ |
2457 | |
2458 | if ( !ftp.ChDir(directory) ) | |
2459 | { | |
456ae26d | 2460 | wxPrintf(_T("ERROR: failed to cd to %s\n"), directory); |
b92fd37c VZ |
2461 | } |
2462 | ||
456ae26d | 2463 | wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str()); |
b92fd37c VZ |
2464 | |
2465 | if ( ftp.FileExists(filename) ) | |
2466 | { | |
2467 | int size = ftp.GetFileSize(filename); | |
2468 | if ( size == -1 ) | |
456ae26d | 2469 | wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename); |
8e907a13 | 2470 | else |
456ae26d | 2471 | wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename, size); |
b92fd37c VZ |
2472 | } |
2473 | else | |
2474 | { | |
456ae26d | 2475 | wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename); |
b92fd37c VZ |
2476 | } |
2477 | } | |
2478 | ||
2479 | static void TestFtpMisc() | |
2480 | { | |
456ae26d | 2481 | wxPuts(_T("*** Testing miscellaneous wxFTP functions ***")); |
b92fd37c | 2482 | |
f2cb8a17 | 2483 | if ( ftp.SendCommand(_T("STAT")) != '2' ) |
b92fd37c | 2484 | { |
456ae26d | 2485 | wxPuts(_T("ERROR: STAT failed")); |
b92fd37c VZ |
2486 | } |
2487 | else | |
2488 | { | |
456ae26d | 2489 | wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str()); |
b92fd37c VZ |
2490 | } |
2491 | ||
f2cb8a17 | 2492 | if ( ftp.SendCommand(_T("HELP SITE")) != '2' ) |
b92fd37c | 2493 | { |
456ae26d | 2494 | wxPuts(_T("ERROR: HELP SITE failed")); |
b92fd37c VZ |
2495 | } |
2496 | else | |
2497 | { | |
456ae26d | 2498 | wxPrintf(_T("The list of site-specific commands:\n\n%s\n"), |
b92fd37c VZ |
2499 | ftp.GetLastResult().c_str()); |
2500 | } | |
2501 | } | |
2502 | ||
2503 | static void TestFtpInteractive() | |
2504 | { | |
456ae26d | 2505 | wxPuts(_T("\n*** Interactive wxFTP test ***")); |
b92fd37c | 2506 | |
456ae26d | 2507 | wxChar buf[128]; |
b92fd37c VZ |
2508 | |
2509 | for ( ;; ) | |
2510 | { | |
456ae26d VZ |
2511 | wxPrintf(_T("Enter FTP command: ")); |
2512 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) | |
b92fd37c VZ |
2513 | break; |
2514 | ||
2515 | // kill the last '\n' | |
456ae26d | 2516 | buf[wxStrlen(buf) - 1] = 0; |
b92fd37c VZ |
2517 | |
2518 | // special handling of LIST and NLST as they require data connection | |
2519 | wxString start(buf, 4); | |
2520 | start.MakeUpper(); | |
f2cb8a17 | 2521 | if ( start == _T("LIST") || start == _T("NLST") ) |
8e907a13 | 2522 | { |
b92fd37c | 2523 | wxString wildcard; |
456ae26d | 2524 | if ( wxStrlen(buf) > 4 ) |
b92fd37c | 2525 | wildcard = buf + 5; |
8e907a13 | 2526 | |
b92fd37c | 2527 | wxArrayString files; |
f2cb8a17 | 2528 | if ( !ftp.GetList(files, wildcard, start == _T("LIST")) ) |
8e907a13 | 2529 | { |
456ae26d | 2530 | wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str()); |
8e907a13 VZ |
2531 | } |
2532 | else | |
2533 | { | |
456ae26d | 2534 | wxPrintf(_T("--- %s of '%s' under '%s':\n"), |
b92fd37c VZ |
2535 | start.c_str(), wildcard.c_str(), ftp.Pwd().c_str()); |
2536 | size_t count = files.GetCount(); | |
2537 | for ( size_t n = 0; n < count; n++ ) | |
2538 | { | |
456ae26d | 2539 | wxPrintf(_T("\t%s\n"), files[n].c_str()); |
b92fd37c | 2540 | } |
456ae26d | 2541 | wxPuts(_T("--- End of the file list")); |
8e907a13 | 2542 | } |
2e907fab | 2543 | } |
b92fd37c | 2544 | else // !list |
2e907fab | 2545 | { |
456ae26d VZ |
2546 | wxChar ch = ftp.SendCommand(buf); |
2547 | wxPrintf(_T("Command %s"), ch ? _T("succeeded") : _T("failed")); | |
b92fd37c VZ |
2548 | if ( ch ) |
2549 | { | |
456ae26d | 2550 | wxPrintf(_T(" (return code %c)"), ch); |
b92fd37c | 2551 | } |
2e907fab | 2552 | |
456ae26d | 2553 | wxPrintf(_T(", server reply:\n%s\n\n"), ftp.GetLastResult().c_str()); |
2e907fab | 2554 | } |
2c8e4738 | 2555 | } |
b92fd37c | 2556 | |
456ae26d | 2557 | wxPuts(_T("\n*** done ***")); |
2c8e4738 VZ |
2558 | } |
2559 | ||
b92fd37c | 2560 | static void TestFtpUpload() |
f6bcfd97 | 2561 | { |
456ae26d | 2562 | wxPuts(_T("*** Testing wxFTP uploading ***\n")); |
f6bcfd97 | 2563 | |
b92fd37c | 2564 | // upload a file |
456ae26d VZ |
2565 | static const wxChar *file1 = _T("test1"); |
2566 | static const wxChar *file2 = _T("test2"); | |
b92fd37c VZ |
2567 | wxOutputStream *out = ftp.GetOutputStream(file1); |
2568 | if ( out ) | |
2569 | { | |
456ae26d | 2570 | wxPrintf(_T("--- Uploading to %s ---\n"), file1); |
b92fd37c VZ |
2571 | out->Write("First hello", 11); |
2572 | delete out; | |
2573 | } | |
f6bcfd97 | 2574 | |
b92fd37c | 2575 | // send a command to check the remote file |
f2cb8a17 | 2576 | if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' ) |
f6bcfd97 | 2577 | { |
456ae26d | 2578 | wxPrintf(_T("ERROR: STAT %s failed\n"), file1); |
f6bcfd97 BP |
2579 | } |
2580 | else | |
2581 | { | |
456ae26d | 2582 | wxPrintf(_T("STAT %s returned:\n\n%s\n"), |
b92fd37c VZ |
2583 | file1, ftp.GetLastResult().c_str()); |
2584 | } | |
2e907fab | 2585 | |
b92fd37c VZ |
2586 | out = ftp.GetOutputStream(file2); |
2587 | if ( out ) | |
2588 | { | |
456ae26d | 2589 | wxPrintf(_T("--- Uploading to %s ---\n"), file1); |
b92fd37c VZ |
2590 | out->Write("Second hello", 12); |
2591 | delete out; | |
f6bcfd97 BP |
2592 | } |
2593 | } | |
2594 | ||
2e907fab | 2595 | #endif // TEST_FTP |
2c8e4738 | 2596 | |
eaff0f0d VZ |
2597 | // ---------------------------------------------------------------------------- |
2598 | // stack backtrace | |
2599 | // ---------------------------------------------------------------------------- | |
2600 | ||
2601 | #ifdef TEST_STACKWALKER | |
2602 | ||
74e2116a MB |
2603 | #if wxUSE_STACKWALKER |
2604 | ||
eaff0f0d VZ |
2605 | #include "wx/stackwalk.h" |
2606 | ||
2607 | class StackDump : public wxStackWalker | |
2608 | { | |
2609 | public: | |
2610 | StackDump(const char *argv0) | |
2611 | : wxStackWalker(argv0) | |
2612 | { | |
2613 | } | |
2614 | ||
5ba95b79 | 2615 | virtual void Walk(size_t skip = 1) |
eaff0f0d VZ |
2616 | { |
2617 | wxPuts(_T("Stack dump:")); | |
2618 | ||
5ba95b79 | 2619 | wxStackWalker::Walk(skip); |
eaff0f0d VZ |
2620 | } |
2621 | ||
2622 | protected: | |
2623 | virtual void OnStackFrame(const wxStackFrame& frame) | |
2624 | { | |
2625 | printf("[%2d] ", frame.GetLevel()); | |
2626 | ||
2627 | wxString name = frame.GetName(); | |
2628 | if ( !name.empty() ) | |
2629 | { | |
2630 | printf("%-20.40s", name.mb_str()); | |
2631 | } | |
2632 | else | |
2633 | { | |
2634 | printf("0x%08lx", (unsigned long)frame.GetAddress()); | |
2635 | } | |
2636 | ||
2637 | if ( frame.HasSourceLocation() ) | |
2638 | { | |
2639 | printf("\t%s:%d", | |
2640 | frame.GetFileName().mb_str(), | |
2641 | frame.GetLine()); | |
2642 | } | |
2643 | ||
2644 | puts(""); | |
2645 | ||
2646 | wxString type, val; | |
2647 | for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ ) | |
2648 | { | |
2649 | printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str()); | |
2650 | } | |
2651 | } | |
2652 | }; | |
2653 | ||
2654 | static void TestStackWalk(const char *argv0) | |
2655 | { | |
2656 | wxPuts(_T("*** Testing wxStackWalker ***\n")); | |
2657 | ||
2658 | StackDump dump(argv0); | |
2659 | dump.Walk(); | |
2660 | } | |
2661 | ||
74e2116a MB |
2662 | #endif // wxUSE_STACKWALKER |
2663 | ||
eaff0f0d VZ |
2664 | #endif // TEST_STACKWALKER |
2665 | ||
af33b199 VZ |
2666 | // ---------------------------------------------------------------------------- |
2667 | // standard paths | |
2668 | // ---------------------------------------------------------------------------- | |
2669 | ||
2670 | #ifdef TEST_STDPATHS | |
2671 | ||
2672 | #include "wx/stdpaths.h" | |
2673 | ||
2674 | static void TestStandardPaths() | |
2675 | { | |
2676 | wxPuts(_T("*** Testing wxStandardPaths ***\n")); | |
2677 | ||
2678 | wxTheApp->SetAppName(_T("console")); | |
2679 | ||
5ba95b79 | 2680 | wxStandardPathsBase& stdp = wxStandardPaths::Get(); |
af33b199 VZ |
2681 | wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str()); |
2682 | wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str()); | |
2683 | wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str()); | |
2684 | wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str()); | |
2685 | wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str()); | |
2686 | wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str()); | |
2687 | wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str()); | |
3af9f2de VZ |
2688 | wxPrintf(_T("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str()); |
2689 | wxPrintf(_T("Localized res. dir:\t%s\n"), | |
2690 | stdp.GetLocalizedResourcesDir(_T("fr")).c_str()); | |
2691 | wxPrintf(_T("Message catalogs dir:\t%s\n"), | |
2692 | stdp.GetLocalizedResourcesDir | |
2693 | ( | |
2694 | _T("fr"), | |
2695 | wxStandardPaths::ResourceCat_Messages | |
2696 | ).c_str()); | |
af33b199 VZ |
2697 | } |
2698 | ||
2699 | #endif // TEST_STDPATHS | |
2700 | ||
83141d3a VZ |
2701 | // ---------------------------------------------------------------------------- |
2702 | // streams | |
2703 | // ---------------------------------------------------------------------------- | |
2704 | ||
2705 | #ifdef TEST_STREAMS | |
2706 | ||
e84010cf GD |
2707 | #include "wx/wfstream.h" |
2708 | #include "wx/mstream.h" | |
83141d3a | 2709 | |
24f25c8a VZ |
2710 | static void TestFileStream() |
2711 | { | |
456ae26d | 2712 | wxPuts(_T("*** Testing wxFileInputStream ***")); |
24f25c8a | 2713 | |
e9d2bb6f | 2714 | static const wxString filename = _T("testdata.fs"); |
24f25c8a VZ |
2715 | { |
2716 | wxFileOutputStream fsOut(filename); | |
2717 | fsOut.Write("foo", 3); | |
2718 | } | |
2719 | ||
2720 | wxFileInputStream fsIn(filename); | |
456ae26d | 2721 | wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize()); |
24f25c8a VZ |
2722 | while ( !fsIn.Eof() ) |
2723 | { | |
e9d2bb6f | 2724 | wxPutchar(fsIn.GetC()); |
24f25c8a VZ |
2725 | } |
2726 | ||
2727 | if ( !wxRemoveFile(filename) ) | |
2728 | { | |
e9d2bb6f | 2729 | wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str()); |
24f25c8a VZ |
2730 | } |
2731 | ||
456ae26d | 2732 | wxPuts(_T("\n*** wxFileInputStream test done ***")); |
24f25c8a VZ |
2733 | } |
2734 | ||
83141d3a VZ |
2735 | static void TestMemoryStream() |
2736 | { | |
99a5af7f VZ |
2737 | wxPuts(_T("*** Testing wxMemoryOutputStream ***")); |
2738 | ||
2739 | wxMemoryOutputStream memOutStream; | |
2740 | wxPrintf(_T("Initially out stream offset: %lu\n"), | |
2741 | (unsigned long)memOutStream.TellO()); | |
2742 | ||
2743 | for ( const wxChar *p = _T("Hello, stream!"); *p; p++ ) | |
2744 | { | |
2745 | memOutStream.PutC(*p); | |
2746 | } | |
2747 | ||
2748 | wxPrintf(_T("Final out stream offset: %lu\n"), | |
2749 | (unsigned long)memOutStream.TellO()); | |
2750 | ||
2751 | wxPuts(_T("*** Testing wxMemoryInputStream ***")); | |
83141d3a VZ |
2752 | |
2753 | wxChar buf[1024]; | |
99a5af7f | 2754 | size_t len = memOutStream.CopyTo(buf, WXSIZEOF(buf)); |
83141d3a | 2755 | |
99a5af7f VZ |
2756 | wxMemoryInputStream memInpStream(buf, len); |
2757 | wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize()); | |
83141d3a VZ |
2758 | while ( !memInpStream.Eof() ) |
2759 | { | |
e9d2bb6f | 2760 | wxPutchar(memInpStream.GetC()); |
83141d3a VZ |
2761 | } |
2762 | ||
456ae26d | 2763 | wxPuts(_T("\n*** wxMemoryInputStream test done ***")); |
83141d3a VZ |
2764 | } |
2765 | ||
2766 | #endif // TEST_STREAMS | |
2767 | ||
d31b7b68 VZ |
2768 | // ---------------------------------------------------------------------------- |
2769 | // timers | |
2770 | // ---------------------------------------------------------------------------- | |
2771 | ||
2772 | #ifdef TEST_TIMER | |
2773 | ||
5ba95b79 | 2774 | #include "wx/stopwatch.h" |
e84010cf | 2775 | #include "wx/utils.h" |
d31b7b68 VZ |
2776 | |
2777 | static void TestStopWatch() | |
2778 | { | |
456ae26d | 2779 | wxPuts(_T("*** Testing wxStopWatch ***\n")); |
d31b7b68 VZ |
2780 | |
2781 | wxStopWatch sw; | |
677eff07 | 2782 | sw.Pause(); |
456ae26d | 2783 | wxPrintf(_T("Initially paused, after 2 seconds time is...")); |
677eff07 VZ |
2784 | fflush(stdout); |
2785 | wxSleep(2); | |
456ae26d | 2786 | wxPrintf(_T("\t%ldms\n"), sw.Time()); |
677eff07 | 2787 | |
456ae26d | 2788 | wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds...")); |
677eff07 VZ |
2789 | fflush(stdout); |
2790 | sw.Resume(); | |
d31b7b68 | 2791 | wxSleep(3); |
456ae26d | 2792 | wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time()); |
d31b7b68 VZ |
2793 | |
2794 | sw.Pause(); | |
456ae26d | 2795 | wxPrintf(_T("Pausing agan and sleeping 2 more seconds...")); |
677eff07 | 2796 | fflush(stdout); |
d31b7b68 | 2797 | wxSleep(2); |
456ae26d | 2798 | wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time()); |
d31b7b68 VZ |
2799 | |
2800 | sw.Resume(); | |
456ae26d | 2801 | wxPrintf(_T("Finally resuming and sleeping 2 more seconds...")); |
677eff07 VZ |
2802 | fflush(stdout); |
2803 | wxSleep(2); | |
456ae26d | 2804 | wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time()); |
87798c00 VZ |
2805 | |
2806 | wxStopWatch sw2; | |
456ae26d | 2807 | wxPuts(_T("\nChecking for 'backwards clock' bug...")); |
87798c00 VZ |
2808 | for ( size_t n = 0; n < 70; n++ ) |
2809 | { | |
2810 | sw2.Start(); | |
89e6463c GRG |
2811 | |
2812 | for ( size_t m = 0; m < 100000; m++ ) | |
87798c00 | 2813 | { |
89e6463c GRG |
2814 | if ( sw.Time() < 0 || sw2.Time() < 0 ) |
2815 | { | |
456ae26d | 2816 | wxPuts(_T("\ntime is negative - ERROR!")); |
89e6463c | 2817 | } |
87798c00 VZ |
2818 | } |
2819 | ||
e9d2bb6f | 2820 | wxPutchar('.'); |
677eff07 | 2821 | fflush(stdout); |
87798c00 VZ |
2822 | } |
2823 | ||
456ae26d | 2824 | wxPuts(_T(", ok.")); |
d31b7b68 VZ |
2825 | } |
2826 | ||
2827 | #endif // TEST_TIMER | |
2828 | ||
f6bcfd97 BP |
2829 | // ---------------------------------------------------------------------------- |
2830 | // vCard support | |
2831 | // ---------------------------------------------------------------------------- | |
2832 | ||
2833 | #ifdef TEST_VCARD | |
2834 | ||
e84010cf | 2835 | #include "wx/vcard.h" |
f6bcfd97 BP |
2836 | |
2837 | static void DumpVObject(size_t level, const wxVCardObject& vcard) | |
2838 | { | |
2839 | void *cookie; | |
2840 | wxVCardObject *vcObj = vcard.GetFirstProp(&cookie); | |
2841 | while ( vcObj ) | |
2842 | { | |
456ae26d | 2843 | wxPrintf(_T("%s%s"), |
f6bcfd97 BP |
2844 | wxString(_T('\t'), level).c_str(), |
2845 | vcObj->GetName().c_str()); | |
2846 | ||
2847 | wxString value; | |
2848 | switch ( vcObj->GetType() ) | |
2849 | { | |
2850 | case wxVCardObject::String: | |
2851 | case wxVCardObject::UString: | |
2852 | { | |
2853 | wxString val; | |
2854 | vcObj->GetValue(&val); | |
2855 | value << _T('"') << val << _T('"'); | |
2856 | } | |
2857 | break; | |
2858 | ||
2859 | case wxVCardObject::Int: | |
2860 | { | |
2861 | unsigned int i; | |
2862 | vcObj->GetValue(&i); | |
2863 | value.Printf(_T("%u"), i); | |
2864 | } | |
2865 | break; | |
2866 | ||
2867 | case wxVCardObject::Long: | |
2868 | { | |
2869 | unsigned long l; | |
2870 | vcObj->GetValue(&l); | |
2871 | value.Printf(_T("%lu"), l); | |
2872 | } | |
2873 | break; | |
2874 | ||
2875 | case wxVCardObject::None: | |
2876 | break; | |
2877 | ||
2878 | case wxVCardObject::Object: | |
2879 | value = _T("<node>"); | |
2880 | break; | |
2881 | ||
2882 | default: | |
2883 | value = _T("<unknown value type>"); | |
2884 | } | |
2885 | ||
2886 | if ( !!value ) | |
456ae26d | 2887 | wxPrintf(_T(" = %s"), value.c_str()); |
e9d2bb6f | 2888 | wxPutchar('\n'); |
f6bcfd97 BP |
2889 | |
2890 | DumpVObject(level + 1, *vcObj); | |
2891 | ||
2892 | delete vcObj; | |
2893 | vcObj = vcard.GetNextProp(&cookie); | |
2894 | } | |
2895 | } | |
2896 | ||
2897 | static void DumpVCardAddresses(const wxVCard& vcard) | |
2898 | { | |
456ae26d | 2899 | wxPuts(_T("\nShowing all addresses from vCard:\n")); |
f6bcfd97 BP |
2900 | |
2901 | size_t nAdr = 0; | |
2902 | void *cookie; | |
2903 | wxVCardAddress *addr = vcard.GetFirstAddress(&cookie); | |
2904 | while ( addr ) | |
2905 | { | |
2906 | wxString flagsStr; | |
2907 | int flags = addr->GetFlags(); | |
2908 | if ( flags & wxVCardAddress::Domestic ) | |
2909 | { | |
2910 | flagsStr << _T("domestic "); | |
2911 | } | |
2912 | if ( flags & wxVCardAddress::Intl ) | |
2913 | { | |
2914 | flagsStr << _T("international "); | |
2915 | } | |
2916 | if ( flags & wxVCardAddress::Postal ) | |
2917 | { | |
2918 | flagsStr << _T("postal "); | |
2919 | } | |
2920 | if ( flags & wxVCardAddress::Parcel ) | |
2921 | { | |
2922 | flagsStr << _T("parcel "); | |
2923 | } | |
2924 | if ( flags & wxVCardAddress::Home ) | |
2925 | { | |
2926 | flagsStr << _T("home "); | |
2927 | } | |
2928 | if ( flags & wxVCardAddress::Work ) | |
2929 | { | |
2930 | flagsStr << _T("work "); | |
2931 | } | |
2932 | ||
456ae26d | 2933 | wxPrintf(_T("Address %u:\n") |
f6bcfd97 BP |
2934 | "\tflags = %s\n" |
2935 | "\tvalue = %s;%s;%s;%s;%s;%s;%s\n", | |
2936 | ++nAdr, | |
2937 | flagsStr.c_str(), | |
2938 | addr->GetPostOffice().c_str(), | |
2939 | addr->GetExtAddress().c_str(), | |
2940 | addr->GetStreet().c_str(), | |
2941 | addr->GetLocality().c_str(), | |
2942 | addr->GetRegion().c_str(), | |
2943 | addr->GetPostalCode().c_str(), | |
2944 | addr->GetCountry().c_str() | |
2945 | ); | |
2946 | ||
2947 | delete addr; | |
2948 | addr = vcard.GetNextAddress(&cookie); | |
2949 | } | |
2950 | } | |
2951 | ||
2952 | static void DumpVCardPhoneNumbers(const wxVCard& vcard) | |
2953 | { | |
456ae26d | 2954 | wxPuts(_T("\nShowing all phone numbers from vCard:\n")); |
f6bcfd97 BP |
2955 | |
2956 | size_t nPhone = 0; | |
2957 | void *cookie; | |
2958 | wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie); | |
2959 | while ( phone ) | |
2960 | { | |
2961 | wxString flagsStr; | |
2962 | int flags = phone->GetFlags(); | |
2963 | if ( flags & wxVCardPhoneNumber::Voice ) | |
2964 | { | |
2965 | flagsStr << _T("voice "); | |
2966 | } | |
2967 | if ( flags & wxVCardPhoneNumber::Fax ) | |
2968 | { | |
2969 | flagsStr << _T("fax "); | |
2970 | } | |
2971 | if ( flags & wxVCardPhoneNumber::Cellular ) | |
2972 | { | |
2973 | flagsStr << _T("cellular "); | |
2974 | } | |
2975 | if ( flags & wxVCardPhoneNumber::Modem ) | |
2976 | { | |
2977 | flagsStr << _T("modem "); | |
2978 | } | |
2979 | if ( flags & wxVCardPhoneNumber::Home ) | |
2980 | { | |
2981 | flagsStr << _T("home "); | |
2982 | } | |
2983 | if ( flags & wxVCardPhoneNumber::Work ) | |
2984 | { | |
2985 | flagsStr << _T("work "); | |
2986 | } | |
2987 | ||
456ae26d | 2988 | wxPrintf(_T("Phone number %u:\n") |
f6bcfd97 BP |
2989 | "\tflags = %s\n" |
2990 | "\tvalue = %s\n", | |
2991 | ++nPhone, | |
2992 | flagsStr.c_str(), | |
2993 | phone->GetNumber().c_str() | |
2994 | ); | |
2995 | ||
2996 | delete phone; | |
2997 | phone = vcard.GetNextPhoneNumber(&cookie); | |
2998 | } | |
2999 | } | |
3000 | ||
3001 | static void TestVCardRead() | |
3002 | { | |
456ae26d | 3003 | wxPuts(_T("*** Testing wxVCard reading ***\n")); |
f6bcfd97 BP |
3004 | |
3005 | wxVCard vcard(_T("vcard.vcf")); | |
3006 | if ( !vcard.IsOk() ) | |
3007 | { | |
456ae26d | 3008 | wxPuts(_T("ERROR: couldn't load vCard.")); |
f6bcfd97 BP |
3009 | } |
3010 | else | |
3011 | { | |
3012 | // read individual vCard properties | |
3013 | wxVCardObject *vcObj = vcard.GetProperty("FN"); | |
3014 | wxString value; | |
3015 | if ( vcObj ) | |
3016 | { | |
3017 | vcObj->GetValue(&value); | |
3018 | delete vcObj; | |
3019 | } | |
3020 | else | |
3021 | { | |
3022 | value = _T("<none>"); | |
3023 | } | |
3024 | ||
456ae26d | 3025 | wxPrintf(_T("Full name retrieved directly: %s\n"), value.c_str()); |
f6bcfd97 BP |
3026 | |
3027 | ||
3028 | if ( !vcard.GetFullName(&value) ) | |
3029 | { | |
3030 | value = _T("<none>"); | |
3031 | } | |
3032 | ||
456ae26d | 3033 | wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str()); |
f6bcfd97 | 3034 | |
3103e8a9 | 3035 | // now show how to deal with multiply occurring properties |
f6bcfd97 BP |
3036 | DumpVCardAddresses(vcard); |
3037 | DumpVCardPhoneNumbers(vcard); | |
3038 | ||
3039 | // and finally show all | |
456ae26d | 3040 | wxPuts(_T("\nNow dumping the entire vCard:\n") |
f6bcfd97 BP |
3041 | "-----------------------------\n"); |
3042 | ||
3043 | DumpVObject(0, vcard); | |
3044 | } | |
3045 | } | |
3046 | ||
3047 | static void TestVCardWrite() | |
3048 | { | |
456ae26d | 3049 | wxPuts(_T("*** Testing wxVCard writing ***\n")); |
f6bcfd97 BP |
3050 | |
3051 | wxVCard vcard; | |
3052 | if ( !vcard.IsOk() ) | |
3053 | { | |
456ae26d | 3054 | wxPuts(_T("ERROR: couldn't create vCard.")); |
f6bcfd97 BP |
3055 | } |
3056 | else | |
3057 | { | |
3058 | // set some fields | |
3059 | vcard.SetName("Zeitlin", "Vadim"); | |
3060 | vcard.SetFullName("Vadim Zeitlin"); | |
be5a51fb | 3061 | vcard.SetOrganization("wxWidgets", "R&D"); |
f6bcfd97 BP |
3062 | |
3063 | // just dump the vCard back | |
456ae26d VZ |
3064 | wxPuts(_T("Entire vCard follows:\n")); |
3065 | wxPuts(vcard.Write()); | |
f6bcfd97 BP |
3066 | } |
3067 | } | |
3068 | ||
3069 | #endif // TEST_VCARD | |
3070 | ||
0e2c5534 VZ |
3071 | // ---------------------------------------------------------------------------- |
3072 | // wxVolume tests | |
3073 | // ---------------------------------------------------------------------------- | |
3074 | ||
ba6ea19e | 3075 | #if !defined(__WIN32__) || !wxUSE_FSVOLUME |
0e2c5534 VZ |
3076 | #undef TEST_VOLUME |
3077 | #endif | |
3078 | ||
3079 | #ifdef TEST_VOLUME | |
3080 | ||
3081 | #include "wx/volume.h" | |
3082 | ||
3083 | static const wxChar *volumeKinds[] = | |
3084 | { | |
3085 | _T("floppy"), | |
3086 | _T("hard disk"), | |
3087 | _T("CD-ROM"), | |
3088 | _T("DVD-ROM"), | |
3089 | _T("network volume"), | |
3090 | _T("other volume"), | |
3091 | }; | |
3092 | ||
3093 | static void TestFSVolume() | |
3094 | { | |
3095 | wxPuts(_T("*** Testing wxFSVolume class ***")); | |
3096 | ||
3097 | wxArrayString volumes = wxFSVolume::GetVolumes(); | |
3098 | size_t count = volumes.GetCount(); | |
3099 | ||
3100 | if ( !count ) | |
3101 | { | |
3102 | wxPuts(_T("ERROR: no mounted volumes?")); | |
3103 | return; | |
3104 | } | |
3105 | ||
3106 | wxPrintf(_T("%u mounted volumes found:\n"), count); | |
3107 | ||
3108 | for ( size_t n = 0; n < count; n++ ) | |
3109 | { | |
3110 | wxFSVolume vol(volumes[n]); | |
3111 | if ( !vol.IsOk() ) | |
3112 | { | |
3113 | wxPuts(_T("ERROR: couldn't create volume")); | |
3114 | continue; | |
3115 | } | |
3116 | ||
3117 | wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"), | |
3118 | n + 1, | |
3119 | vol.GetDisplayName().c_str(), | |
3120 | vol.GetName().c_str(), | |
3121 | volumeKinds[vol.GetKind()], | |
3122 | vol.IsWritable() ? _T("rw") : _T("ro"), | |
3123 | vol.GetFlags() & wxFS_VOL_REMOVABLE ? _T("removable") | |
3124 | : _T("fixed")); | |
3125 | } | |
3126 | } | |
3127 | ||
3128 | #endif // TEST_VOLUME | |
3129 | ||
f6bcfd97 | 3130 | // ---------------------------------------------------------------------------- |
e7d41190 | 3131 | // wide char and Unicode support |
f6bcfd97 BP |
3132 | // ---------------------------------------------------------------------------- |
3133 | ||
3134 | #ifdef TEST_WCHAR | |
3135 | ||
e84010cf GD |
3136 | #include "wx/strconv.h" |
3137 | #include "wx/fontenc.h" | |
3138 | #include "wx/encconv.h" | |
3139 | #include "wx/buffer.h" | |
f6bcfd97 | 3140 | |
2b5f62a0 | 3141 | static const unsigned char utf8koi8r[] = |
ac511156 VZ |
3142 | { |
3143 | 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176, | |
3144 | 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208, | |
3145 | 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188, | |
3146 | 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208, | |
3147 | 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181, | |
3148 | 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208, | |
3149 | 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0 | |
3150 | }; | |
3151 | ||
2b5f62a0 VZ |
3152 | static const unsigned char utf8iso8859_1[] = |
3153 | { | |
3154 | 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e, | |
3155 | 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65, | |
3156 | 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65, | |
3157 | 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65, | |
3158 | 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0 | |
3159 | }; | |
3160 | ||
3161 | static const unsigned char utf8Invalid[] = | |
3162 | { | |
3163 | 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30, | |
3164 | 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6, | |
3165 | 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88, | |
3166 | 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70, | |
3167 | 0x6c, 0x61, 0x79, 0 | |
3168 | }; | |
3169 | ||
3170 | static const struct Utf8Data | |
3171 | { | |
3172 | const unsigned char *text; | |
3173 | size_t len; | |
3174 | const wxChar *charset; | |
3175 | wxFontEncoding encoding; | |
3176 | } utf8data[] = | |
3177 | { | |
3178 | { utf8Invalid, WXSIZEOF(utf8Invalid), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 }, | |
3179 | { utf8koi8r, WXSIZEOF(utf8koi8r), _T("koi8-r"), wxFONTENCODING_KOI8 }, | |
3180 | { utf8iso8859_1, WXSIZEOF(utf8iso8859_1), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 }, | |
3181 | }; | |
456ae26d | 3182 | |
f6bcfd97 BP |
3183 | static void TestUtf8() |
3184 | { | |
456ae26d | 3185 | wxPuts(_T("*** Testing UTF8 support ***\n")); |
f6bcfd97 | 3186 | |
24f25c8a VZ |
3187 | char buf[1024]; |
3188 | wchar_t wbuf[1024]; | |
2b5f62a0 VZ |
3189 | |
3190 | for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ ) | |
24f25c8a | 3191 | { |
2b5f62a0 VZ |
3192 | const Utf8Data& u8d = utf8data[n]; |
3193 | if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text, | |
3194 | WXSIZEOF(wbuf)) == (size_t)-1 ) | |
24f25c8a | 3195 | { |
2b5f62a0 | 3196 | wxPuts(_T("ERROR: UTF-8 decoding failed.")); |
24f25c8a VZ |
3197 | } |
3198 | else | |
ac511156 | 3199 | { |
2b5f62a0 VZ |
3200 | wxCSConv conv(u8d.charset); |
3201 | if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 ) | |
3202 | { | |
3203 | wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d.charset); | |
3204 | } | |
3205 | else | |
3206 | { | |
3207 | wxPrintf(_T("String in %s: %s\n"), u8d.charset, buf); | |
3208 | } | |
ac511156 | 3209 | } |
ac511156 | 3210 | |
5bc1deeb | 3211 | wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text)); |
2b5f62a0 VZ |
3212 | if ( s.empty() ) |
3213 | s = _T("<< conversion failed >>"); | |
3214 | wxPrintf(_T("String in current cset: %s\n"), s.c_str()); | |
3215 | ||
ac511156 VZ |
3216 | } |
3217 | ||
e9d2bb6f | 3218 | wxPuts(wxEmptyString); |
ac511156 | 3219 | } |
f6bcfd97 | 3220 | |
ac511156 VZ |
3221 | static void TestEncodingConverter() |
3222 | { | |
3223 | wxPuts(_T("*** Testing wxEncodingConverter ***\n")); | |
3224 | ||
3225 | // using wxEncodingConverter should give the same result as above | |
3226 | char buf[1024]; | |
3227 | wchar_t wbuf[1024]; | |
2b5f62a0 VZ |
3228 | if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r, |
3229 | WXSIZEOF(utf8koi8r)) == (size_t)-1 ) | |
ac511156 | 3230 | { |
456ae26d | 3231 | wxPuts(_T("ERROR: UTF-8 decoding failed.")); |
ac511156 VZ |
3232 | } |
3233 | else | |
3234 | { | |
3235 | wxEncodingConverter ec; | |
3236 | ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8); | |
3237 | ec.Convert(wbuf, buf); | |
2b5f62a0 | 3238 | wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf); |
24f25c8a | 3239 | } |
ac511156 | 3240 | |
e9d2bb6f | 3241 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
3242 | } |
3243 | ||
3244 | #endif // TEST_WCHAR | |
3245 | ||
3246 | // ---------------------------------------------------------------------------- | |
3247 | // ZIP stream | |
3248 | // ---------------------------------------------------------------------------- | |
3249 | ||
3250 | #ifdef TEST_ZIP | |
3251 | ||
2ca8b884 VZ |
3252 | #include "wx/filesys.h" |
3253 | #include "wx/fs_zip.h" | |
f6bcfd97 BP |
3254 | #include "wx/zipstrm.h" |
3255 | ||
2ca8b884 VZ |
3256 | static const wxChar *TESTFILE_ZIP = _T("testdata.zip"); |
3257 | ||
f6bcfd97 BP |
3258 | static void TestZipStreamRead() |
3259 | { | |
456ae26d | 3260 | wxPuts(_T("*** Testing ZIP reading ***\n")); |
f6bcfd97 | 3261 | |
e9d2bb6f | 3262 | static const wxString filename = _T("foo"); |
2ca8b884 | 3263 | wxZipInputStream istr(TESTFILE_ZIP, filename); |
456ae26d | 3264 | wxPrintf(_T("Archive size: %u\n"), istr.GetSize()); |
f6bcfd97 | 3265 | |
e9d2bb6f | 3266 | wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str()); |
f6bcfd97 BP |
3267 | while ( !istr.Eof() ) |
3268 | { | |
e9d2bb6f | 3269 | wxPutchar(istr.GetC()); |
f6bcfd97 BP |
3270 | fflush(stdout); |
3271 | } | |
3272 | ||
456ae26d | 3273 | wxPuts(_T("\n----- done ------")); |
f6bcfd97 BP |
3274 | } |
3275 | ||
2ca8b884 VZ |
3276 | static void DumpZipDirectory(wxFileSystem& fs, |
3277 | const wxString& dir, | |
3278 | const wxString& indent) | |
3279 | { | |
3280 | wxString prefix = wxString::Format(_T("%s#zip:%s"), | |
3281 | TESTFILE_ZIP, dir.c_str()); | |
3282 | wxString wildcard = prefix + _T("/*"); | |
3283 | ||
3284 | wxString dirname = fs.FindFirst(wildcard, wxDIR); | |
3285 | while ( !dirname.empty() ) | |
3286 | { | |
3287 | if ( !dirname.StartsWith(prefix + _T('/'), &dirname) ) | |
3288 | { | |
3289 | wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); | |
3290 | ||
3291 | break; | |
3292 | } | |
3293 | ||
3294 | wxPrintf(_T("%s%s\n"), indent.c_str(), dirname.c_str()); | |
3295 | ||
3296 | DumpZipDirectory(fs, dirname, | |
3297 | indent + wxString(_T(' '), 4)); | |
3298 | ||
3299 | dirname = fs.FindNext(); | |
3300 | } | |
3301 | ||
3302 | wxString filename = fs.FindFirst(wildcard, wxFILE); | |
3303 | while ( !filename.empty() ) | |
3304 | { | |
3305 | if ( !filename.StartsWith(prefix, &filename) ) | |
3306 | { | |
3307 | wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n")); | |
3308 | ||
3309 | break; | |
3310 | } | |
3311 | ||
3312 | wxPrintf(_T("%s%s\n"), indent.c_str(), filename.c_str()); | |
3313 | ||
3314 | filename = fs.FindNext(); | |
3315 | } | |
3316 | } | |
3317 | ||
3318 | static void TestZipFileSystem() | |
3319 | { | |
456ae26d | 3320 | wxPuts(_T("*** Testing ZIP file system ***\n")); |
2ca8b884 VZ |
3321 | |
3322 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
3323 | wxFileSystem fs; | |
3324 | wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP); | |
3325 | ||
3326 | DumpZipDirectory(fs, _T(""), wxString(_T(' '), 4)); | |
3327 | } | |
3328 | ||
f6bcfd97 BP |
3329 | #endif // TEST_ZIP |
3330 | ||
b76b015e VZ |
3331 | // ---------------------------------------------------------------------------- |
3332 | // date time | |
3333 | // ---------------------------------------------------------------------------- | |
3334 | ||
d31b7b68 | 3335 | #ifdef TEST_DATETIME |
b76b015e | 3336 | |
b713f891 | 3337 | #include "wx/math.h" |
e84010cf | 3338 | #include "wx/datetime.h" |
b76b015e | 3339 | |
2f02cb89 | 3340 | // this test miscellaneous static wxDateTime functions |
4b586201 WS |
3341 | |
3342 | #if TEST_ALL | |
3343 | ||
2f02cb89 VZ |
3344 | static void TestTimeStatic() |
3345 | { | |
456ae26d | 3346 | wxPuts(_T("\n*** wxDateTime static methods test ***")); |
2f02cb89 VZ |
3347 | |
3348 | // some info about the current date | |
3349 | int year = wxDateTime::GetCurrentYear(); | |
456ae26d | 3350 | wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"), |
2f02cb89 VZ |
3351 | year, |
3352 | wxDateTime::IsLeapYear(year) ? "" : "not ", | |
3353 | wxDateTime::GetNumberOfDays(year)); | |
3354 | ||
3355 | wxDateTime::Month month = wxDateTime::GetCurrentMonth(); | |
456ae26d | 3356 | wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"), |
f0f951fa | 3357 | wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(), |
2f02cb89 VZ |
3358 | wxDateTime::GetMonthName(month).c_str(), |
3359 | wxDateTime::GetNumberOfDays(month)); | |
2f02cb89 VZ |
3360 | } |
3361 | ||
fcc3d7cb VZ |
3362 | // test time zones stuff |
3363 | static void TestTimeZones() | |
3364 | { | |
456ae26d | 3365 | wxPuts(_T("\n*** wxDateTime timezone test ***")); |
fcc3d7cb VZ |
3366 | |
3367 | wxDateTime now = wxDateTime::Now(); | |
3368 | ||
456ae26d VZ |
3369 | wxPrintf(_T("Current GMT time:\t%s\n"), now.Format(_T("%c"), wxDateTime::GMT0).c_str()); |
3370 | wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0).c_str()); | |
3371 | wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST).c_str()); | |
3372 | wxPrintf(_T("Current time in Paris:\t%s\n"), now.Format(_T("%c"), wxDateTime::CET).c_str()); | |
3373 | wxPrintf(_T(" Moscow:\t%s\n"), now.Format(_T("%c"), wxDateTime::MSK).c_str()); | |
3374 | wxPrintf(_T(" New York:\t%s\n"), now.Format(_T("%c"), wxDateTime::EST).c_str()); | |
9d9b7755 | 3375 | |
ccd6aacd VZ |
3376 | wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str()); |
3377 | ||
9d9b7755 VZ |
3378 | wxDateTime::Tm tm = now.GetTm(); |
3379 | if ( wxDateTime(tm) != now ) | |
3380 | { | |
456ae26d VZ |
3381 | wxPrintf(_T("ERROR: got %s instead of %s\n"), |
3382 | wxDateTime(tm).Format().c_str(), now.Format().c_str()); | |
9d9b7755 | 3383 | } |
fcc3d7cb VZ |
3384 | } |
3385 | ||
e6ec579c VZ |
3386 | // test some minimal support for the dates outside the standard range |
3387 | static void TestTimeRange() | |
3388 | { | |
456ae26d | 3389 | wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***")); |
e6ec579c | 3390 | |
456ae26d | 3391 | static const wxChar *fmt = _T("%d-%b-%Y %H:%M:%S"); |
211c2250 | 3392 | |
456ae26d VZ |
3393 | wxPrintf(_T("Unix epoch:\t%s\n"), |
3394 | wxDateTime(2440587.5).Format(fmt).c_str()); | |
3395 | wxPrintf(_T("Feb 29, 0: \t%s\n"), | |
3396 | wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str()); | |
3397 | wxPrintf(_T("JDN 0: \t%s\n"), | |
3398 | wxDateTime(0.0).Format(fmt).c_str()); | |
3399 | wxPrintf(_T("Jan 1, 1AD:\t%s\n"), | |
3400 | wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str()); | |
3401 | wxPrintf(_T("May 29, 2099:\t%s\n"), | |
3402 | wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str()); | |
e6ec579c VZ |
3403 | } |
3404 | ||
239446b4 VZ |
3405 | // test DST calculations |
3406 | static void TestTimeDST() | |
3407 | { | |
456ae26d | 3408 | wxPuts(_T("\n*** wxDateTime DST test ***")); |
239446b4 | 3409 | |
456ae26d | 3410 | wxPrintf(_T("DST is%s in effect now.\n\n"), |
e9d2bb6f | 3411 | wxDateTime::Now().IsDST() ? wxEmptyString : _T(" not")); |
239446b4 | 3412 | |
ccd6aacd | 3413 | for ( int year = 1990; year < 2005; year++ ) |
239446b4 | 3414 | { |
456ae26d VZ |
3415 | wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"), |
3416 | year, | |
3417 | wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(), | |
3418 | wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str()); | |
239446b4 VZ |
3419 | } |
3420 | } | |
3421 | ||
4b586201 WS |
3422 | #endif // TEST_ALL |
3423 | ||
3424 | #if TEST_INTERACTIVE | |
3425 | ||
b92fd37c | 3426 | static void TestDateTimeInteractive() |
9d9b7755 | 3427 | { |
456ae26d | 3428 | wxPuts(_T("\n*** interactive wxDateTime tests ***")); |
9d9b7755 | 3429 | |
456ae26d | 3430 | wxChar buf[128]; |
9d9b7755 VZ |
3431 | |
3432 | for ( ;; ) | |
3433 | { | |
456ae26d VZ |
3434 | wxPrintf(_T("Enter a date: ")); |
3435 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) | |
9d9b7755 VZ |
3436 | break; |
3437 | ||
f6bcfd97 | 3438 | // kill the last '\n' |
456ae26d | 3439 | buf[wxStrlen(buf) - 1] = 0; |
f6bcfd97 | 3440 | |
9d9b7755 | 3441 | wxDateTime dt; |
456ae26d | 3442 | const wxChar *p = dt.ParseDate(buf); |
f6bcfd97 | 3443 | if ( !p ) |
9d9b7755 | 3444 | { |
456ae26d | 3445 | wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf); |
9d9b7755 VZ |
3446 | |
3447 | continue; | |
3448 | } | |
f6bcfd97 BP |
3449 | else if ( *p ) |
3450 | { | |
456ae26d | 3451 | wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p - buf); |
f6bcfd97 | 3452 | } |
9d9b7755 | 3453 | |
456ae26d VZ |
3454 | wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"), |
3455 | dt.Format(_T("%b %d, %Y")).c_str(), | |
3456 | dt.GetDayOfYear(), | |
3457 | dt.GetWeekOfMonth(wxDateTime::Monday_First), | |
3458 | dt.GetWeekOfMonth(wxDateTime::Sunday_First), | |
3459 | dt.GetWeekOfYear(wxDateTime::Monday_First)); | |
9d9b7755 VZ |
3460 | } |
3461 | ||
456ae26d | 3462 | wxPuts(_T("\n*** done ***")); |
9d9b7755 VZ |
3463 | } |
3464 | ||
4b586201 WS |
3465 | #endif // TEST_INTERACTIVE |
3466 | ||
3467 | #if TEST_ALL | |
3468 | ||
f6bcfd97 BP |
3469 | static void TestTimeMS() |
3470 | { | |
456ae26d | 3471 | wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***")); |
f6bcfd97 BP |
3472 | |
3473 | wxDateTime dt1 = wxDateTime::Now(), | |
3474 | dt2 = wxDateTime::UNow(); | |
3475 | ||
456ae26d VZ |
3476 | wxPrintf(_T("Now = %s\n"), dt1.Format(_T("%H:%M:%S:%l")).c_str()); |
3477 | wxPrintf(_T("UNow = %s\n"), dt2.Format(_T("%H:%M:%S:%l")).c_str()); | |
3478 | wxPrintf(_T("Dummy loop: ")); | |
3ca6a5f0 BP |
3479 | for ( int i = 0; i < 6000; i++ ) |
3480 | { | |
3481 | //for ( int j = 0; j < 10; j++ ) | |
3482 | { | |
3483 | wxString s; | |
ccd6aacd | 3484 | s.Printf(_T("%g"), sqrt((float)i)); |
3ca6a5f0 BP |
3485 | } |
3486 | ||
3487 | if ( !(i % 100) ) | |
e9d2bb6f | 3488 | wxPutchar('.'); |
3ca6a5f0 | 3489 | } |
456ae26d | 3490 | wxPuts(_T(", done")); |
3ca6a5f0 BP |
3491 | |
3492 | dt1 = dt2; | |
3493 | dt2 = wxDateTime::UNow(); | |
456ae26d | 3494 | wxPrintf(_T("UNow = %s\n"), dt2.Format(_T("%H:%M:%S:%l")).c_str()); |
3ca6a5f0 | 3495 | |
456ae26d | 3496 | wxPrintf(_T("Loop executed in %s ms\n"), (dt2 - dt1).Format(_T("%l")).c_str()); |
f6bcfd97 | 3497 | |
456ae26d | 3498 | wxPuts(_T("\n*** done ***")); |
f6bcfd97 BP |
3499 | } |
3500 | ||
0de868d9 VZ |
3501 | static void TestTimeHolidays() |
3502 | { | |
456ae26d | 3503 | wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n")); |
0de868d9 VZ |
3504 | |
3505 | wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm(); | |
3506 | wxDateTime dtStart(1, tm.mon, tm.year), | |
3507 | dtEnd = dtStart.GetLastMonthDay(); | |
3508 | ||
3509 | wxDateTimeArray hol; | |
3510 | wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol); | |
3511 | ||
456ae26d | 3512 | const wxChar *format = _T("%d-%b-%Y (%a)"); |
0de868d9 | 3513 | |
456ae26d | 3514 | wxPrintf(_T("All holidays between %s and %s:\n"), |
0de868d9 VZ |
3515 | dtStart.Format(format).c_str(), dtEnd.Format(format).c_str()); |
3516 | ||
3517 | size_t count = hol.GetCount(); | |
3518 | for ( size_t n = 0; n < count; n++ ) | |
3519 | { | |
456ae26d | 3520 | wxPrintf(_T("\t%s\n"), hol[n].Format(format).c_str()); |
0de868d9 VZ |
3521 | } |
3522 | ||
e9d2bb6f | 3523 | wxPuts(wxEmptyString); |
0de868d9 VZ |
3524 | } |
3525 | ||
f6bcfd97 BP |
3526 | static void TestTimeZoneBug() |
3527 | { | |
456ae26d | 3528 | wxPuts(_T("\n*** testing for DST/timezone bug ***\n")); |
f6bcfd97 BP |
3529 | |
3530 | wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000); | |
3531 | for ( int i = 0; i < 31; i++ ) | |
3532 | { | |
456ae26d | 3533 | wxPrintf(_T("Date %s: week day %s.\n"), |
f6bcfd97 BP |
3534 | date.Format(_T("%d-%m-%Y")).c_str(), |
3535 | date.GetWeekDayName(date.GetWeekDay()).c_str()); | |
3536 | ||
3537 | date += wxDateSpan::Day(); | |
3538 | } | |
3539 | ||
e9d2bb6f | 3540 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
3541 | } |
3542 | ||
df05cdc5 VZ |
3543 | static void TestTimeSpanFormat() |
3544 | { | |
456ae26d | 3545 | wxPuts(_T("\n*** wxTimeSpan tests ***")); |
df05cdc5 | 3546 | |
456ae26d | 3547 | static const wxChar *formats[] = |
df05cdc5 VZ |
3548 | { |
3549 | _T("(default) %H:%M:%S"), | |
3550 | _T("%E weeks and %D days"), | |
3551 | _T("%l milliseconds"), | |
3552 | _T("(with ms) %H:%M:%S:%l"), | |
3553 | _T("100%% of minutes is %M"), // test "%%" | |
3554 | _T("%D days and %H hours"), | |
a8625337 | 3555 | _T("or also %S seconds"), |
df05cdc5 VZ |
3556 | }; |
3557 | ||
3558 | wxTimeSpan ts1(1, 2, 3, 4), | |
3559 | ts2(111, 222, 333); | |
3560 | for ( size_t n = 0; n < WXSIZEOF(formats); n++ ) | |
3561 | { | |
456ae26d | 3562 | wxPrintf(_T("ts1 = %s\tts2 = %s\n"), |
df05cdc5 VZ |
3563 | ts1.Format(formats[n]).c_str(), |
3564 | ts2.Format(formats[n]).c_str()); | |
3565 | } | |
3566 | ||
e9d2bb6f | 3567 | wxPuts(wxEmptyString); |
df05cdc5 VZ |
3568 | } |
3569 | ||
4b586201 WS |
3570 | #endif // TEST_ALL |
3571 | ||
d31b7b68 | 3572 | #endif // TEST_DATETIME |
b76b015e | 3573 | |
39937656 VZ |
3574 | // ---------------------------------------------------------------------------- |
3575 | // wxTextInput/OutputStream | |
3576 | // ---------------------------------------------------------------------------- | |
3577 | ||
3578 | #ifdef TEST_TEXTSTREAM | |
3579 | ||
3580 | #include "wx/txtstrm.h" | |
3581 | #include "wx/wfstream.h" | |
3582 | ||
3583 | static void TestTextInputStream() | |
3584 | { | |
3585 | wxPuts(_T("\n*** wxTextInputStream test ***")); | |
3586 | ||
e9d2bb6f DS |
3587 | wxString filename = _T("testdata.fc"); |
3588 | wxFileInputStream fsIn(filename); | |
39937656 VZ |
3589 | if ( !fsIn.Ok() ) |
3590 | { | |
3591 | wxPuts(_T("ERROR: couldn't open file.")); | |
3592 | } | |
3593 | else | |
3594 | { | |
3595 | wxTextInputStream tis(fsIn); | |
3596 | ||
3597 | size_t line = 1; | |
3598 | for ( ;; ) | |
3599 | { | |
3600 | const wxString s = tis.ReadLine(); | |
3601 | ||
3602 | // line could be non empty if the last line of the file isn't | |
3603 | // terminated with EOL | |
3604 | if ( fsIn.Eof() && s.empty() ) | |
3605 | break; | |
3606 | ||
3607 | wxPrintf(_T("Line %d: %s\n"), line++, s.c_str()); | |
3608 | } | |
3609 | } | |
3610 | } | |
3611 | ||
3612 | #endif // TEST_TEXTSTREAM | |
3613 | ||
e87271f3 VZ |
3614 | // ---------------------------------------------------------------------------- |
3615 | // threads | |
3616 | // ---------------------------------------------------------------------------- | |
3617 | ||
3618 | #ifdef TEST_THREADS | |
3619 | ||
e84010cf | 3620 | #include "wx/thread.h" |
37667812 | 3621 | |
bbfa0322 VZ |
3622 | static size_t gs_counter = (size_t)-1; |
3623 | static wxCriticalSection gs_critsect; | |
c112e100 | 3624 | static wxSemaphore gs_cond; |
bbfa0322 | 3625 | |
b568d04f | 3626 | class MyJoinableThread : public wxThread |
bbfa0322 VZ |
3627 | { |
3628 | public: | |
b568d04f VZ |
3629 | MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE) |
3630 | { m_n = n; Create(); } | |
bbfa0322 VZ |
3631 | |
3632 | // thread execution starts here | |
b568d04f | 3633 | virtual ExitCode Entry(); |
bbfa0322 | 3634 | |
b568d04f VZ |
3635 | private: |
3636 | size_t m_n; | |
bbfa0322 VZ |
3637 | }; |
3638 | ||
b568d04f | 3639 | wxThread::ExitCode MyJoinableThread::Entry() |
bbfa0322 | 3640 | { |
b568d04f VZ |
3641 | unsigned long res = 1; |
3642 | for ( size_t n = 1; n < m_n; n++ ) | |
3643 | { | |
3644 | res *= n; | |
3645 | ||
3646 | // it's a loooong calculation :-) | |
3647 | Sleep(100); | |
3648 | } | |
bbfa0322 | 3649 | |
b568d04f | 3650 | return (ExitCode)res; |
bbfa0322 VZ |
3651 | } |
3652 | ||
b568d04f VZ |
3653 | class MyDetachedThread : public wxThread |
3654 | { | |
3655 | public: | |
456ae26d | 3656 | MyDetachedThread(size_t n, wxChar ch) |
fcc3d7cb VZ |
3657 | { |
3658 | m_n = n; | |
3659 | m_ch = ch; | |
cab8f76e | 3660 | m_cancelled = false; |
fcc3d7cb VZ |
3661 | |
3662 | Create(); | |
3663 | } | |
b568d04f VZ |
3664 | |
3665 | // thread execution starts here | |
3666 | virtual ExitCode Entry(); | |
3667 | ||
3668 | // and stops here | |
3669 | virtual void OnExit(); | |
3670 | ||
3671 | private: | |
9fc3ad34 | 3672 | size_t m_n; // number of characters to write |
456ae26d | 3673 | wxChar m_ch; // character to write |
fcc3d7cb | 3674 | |
cab8f76e | 3675 | bool m_cancelled; // false if we exit normally |
b568d04f VZ |
3676 | }; |
3677 | ||
3678 | wxThread::ExitCode MyDetachedThread::Entry() | |
bbfa0322 VZ |
3679 | { |
3680 | { | |
3681 | wxCriticalSectionLocker lock(gs_critsect); | |
3682 | if ( gs_counter == (size_t)-1 ) | |
3683 | gs_counter = 1; | |
3684 | else | |
3685 | gs_counter++; | |
3686 | } | |
3687 | ||
9fc3ad34 | 3688 | for ( size_t n = 0; n < m_n; n++ ) |
bbfa0322 VZ |
3689 | { |
3690 | if ( TestDestroy() ) | |
fcc3d7cb | 3691 | { |
cab8f76e | 3692 | m_cancelled = true; |
fcc3d7cb | 3693 | |
bbfa0322 | 3694 | break; |
fcc3d7cb | 3695 | } |
bbfa0322 | 3696 | |
e9d2bb6f | 3697 | wxPutchar(m_ch); |
bbfa0322 VZ |
3698 | fflush(stdout); |
3699 | ||
3700 | wxThread::Sleep(100); | |
3701 | } | |
3702 | ||
b568d04f | 3703 | return 0; |
bbfa0322 VZ |
3704 | } |
3705 | ||
b568d04f | 3706 | void MyDetachedThread::OnExit() |
bbfa0322 | 3707 | { |
456ae26d | 3708 | wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId()); |
9fc3ad34 | 3709 | |
bbfa0322 | 3710 | wxCriticalSectionLocker lock(gs_critsect); |
fcc3d7cb | 3711 | if ( !--gs_counter && !m_cancelled ) |
c112e100 | 3712 | gs_cond.Post(); |
bbfa0322 VZ |
3713 | } |
3714 | ||
2f2f3e2a | 3715 | static void TestDetachedThreads() |
9fc3ad34 | 3716 | { |
456ae26d | 3717 | wxPuts(_T("\n*** Testing detached threads ***")); |
9fc3ad34 VZ |
3718 | |
3719 | static const size_t nThreads = 3; | |
3720 | MyDetachedThread *threads[nThreads]; | |
3721 | size_t n; | |
3722 | for ( n = 0; n < nThreads; n++ ) | |
3723 | { | |
3724 | threads[n] = new MyDetachedThread(10, 'A' + n); | |
3725 | } | |
3726 | ||
3727 | threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY); | |
3728 | threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY); | |
3729 | ||
3730 | for ( n = 0; n < nThreads; n++ ) | |
3731 | { | |
3732 | threads[n]->Run(); | |
3733 | } | |
3734 | ||
3735 | // wait until all threads terminate | |
3736 | gs_cond.Wait(); | |
3737 | ||
e9d2bb6f | 3738 | wxPuts(wxEmptyString); |
9fc3ad34 VZ |
3739 | } |
3740 | ||
2f2f3e2a | 3741 | static void TestJoinableThreads() |
9fc3ad34 | 3742 | { |
456ae26d | 3743 | wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***")); |
9fc3ad34 VZ |
3744 | |
3745 | // calc 10! in the background | |
3746 | MyJoinableThread thread(10); | |
3747 | thread.Run(); | |
3748 | ||
456ae26d | 3749 | wxPrintf(_T("\nThread terminated with exit code %lu.\n"), |
5bc1deeb | 3750 | (unsigned long)thread.Wait()); |
9fc3ad34 VZ |
3751 | } |
3752 | ||
2f2f3e2a | 3753 | static void TestThreadSuspend() |
9fc3ad34 | 3754 | { |
456ae26d | 3755 | wxPuts(_T("\n*** Testing thread suspend/resume functions ***")); |
2f02cb89 VZ |
3756 | |
3757 | MyDetachedThread *thread = new MyDetachedThread(15, 'X'); | |
9fc3ad34 VZ |
3758 | |
3759 | thread->Run(); | |
3760 | ||
3761 | // this is for this demo only, in a real life program we'd use another | |
3762 | // condition variable which would be signaled from wxThread::Entry() to | |
3763 | // tell us that the thread really started running - but here just wait a | |
3764 | // bit and hope that it will be enough (the problem is, of course, that | |
3765 | // the thread might still not run when we call Pause() which will result | |
3766 | // in an error) | |
3767 | wxThread::Sleep(300); | |
3768 | ||
3769 | for ( size_t n = 0; n < 3; n++ ) | |
3770 | { | |
3771 | thread->Pause(); | |
3772 | ||
456ae26d | 3773 | wxPuts(_T("\nThread suspended")); |
9fc3ad34 VZ |
3774 | if ( n > 0 ) |
3775 | { | |
3776 | // don't sleep but resume immediately the first time | |
3777 | wxThread::Sleep(300); | |
3778 | } | |
456ae26d | 3779 | wxPuts(_T("Going to resume the thread")); |
9fc3ad34 VZ |
3780 | |
3781 | thread->Resume(); | |
3782 | } | |
3783 | ||
456ae26d | 3784 | wxPuts(_T("Waiting until it terminates now")); |
4c460b34 | 3785 | |
9fc3ad34 VZ |
3786 | // wait until the thread terminates |
3787 | gs_cond.Wait(); | |
3788 | ||
e9d2bb6f | 3789 | wxPuts(wxEmptyString); |
9fc3ad34 VZ |
3790 | } |
3791 | ||
2f2f3e2a | 3792 | static void TestThreadDelete() |
2f02cb89 VZ |
3793 | { |
3794 | // As above, using Sleep() is only for testing here - we must use some | |
3795 | // synchronisation object instead to ensure that the thread is still | |
3796 | // running when we delete it - deleting a detached thread which already | |
3797 | // terminated will lead to a crash! | |
3798 | ||
456ae26d | 3799 | wxPuts(_T("\n*** Testing thread delete function ***")); |
2f02cb89 | 3800 | |
4c460b34 VZ |
3801 | MyDetachedThread *thread0 = new MyDetachedThread(30, 'W'); |
3802 | ||
3803 | thread0->Delete(); | |
3804 | ||
456ae26d | 3805 | wxPuts(_T("\nDeleted a thread which didn't start to run yet.")); |
4c460b34 | 3806 | |
2f02cb89 VZ |
3807 | MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y'); |
3808 | ||
3809 | thread1->Run(); | |
3810 | ||
3811 | wxThread::Sleep(300); | |
3812 | ||
3813 | thread1->Delete(); | |
3814 | ||
456ae26d | 3815 | wxPuts(_T("\nDeleted a running thread.")); |
2f02cb89 VZ |
3816 | |
3817 | MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z'); | |
3818 | ||
3819 | thread2->Run(); | |
3820 | ||
3821 | wxThread::Sleep(300); | |
3822 | ||
3823 | thread2->Pause(); | |
3824 | ||
3825 | thread2->Delete(); | |
3826 | ||
456ae26d | 3827 | wxPuts(_T("\nDeleted a sleeping thread.")); |
2f02cb89 | 3828 | |
4c460b34 VZ |
3829 | MyJoinableThread thread3(20); |
3830 | thread3.Run(); | |
2f02cb89 | 3831 | |
4c460b34 | 3832 | thread3.Delete(); |
2f02cb89 | 3833 | |
456ae26d | 3834 | wxPuts(_T("\nDeleted a joinable thread.")); |
2f02cb89 | 3835 | |
4c460b34 VZ |
3836 | MyJoinableThread thread4(2); |
3837 | thread4.Run(); | |
2f02cb89 VZ |
3838 | |
3839 | wxThread::Sleep(300); | |
3840 | ||
4c460b34 | 3841 | thread4.Delete(); |
2f02cb89 | 3842 | |
456ae26d | 3843 | wxPuts(_T("\nDeleted a joinable thread which already terminated.")); |
2f02cb89 | 3844 | |
e9d2bb6f | 3845 | wxPuts(wxEmptyString); |
2f02cb89 VZ |
3846 | } |
3847 | ||
2f2f3e2a VZ |
3848 | class MyWaitingThread : public wxThread |
3849 | { | |
3850 | public: | |
c112e100 | 3851 | MyWaitingThread( wxMutex *mutex, wxCondition *condition ) |
2f2f3e2a | 3852 | { |
c112e100 | 3853 | m_mutex = mutex; |
2f2f3e2a VZ |
3854 | m_condition = condition; |
3855 | ||
3856 | Create(); | |
3857 | } | |
3858 | ||
3859 | virtual ExitCode Entry() | |
3860 | { | |
456ae26d | 3861 | wxPrintf(_T("Thread %lu has started running.\n"), GetId()); |
2f2f3e2a VZ |
3862 | fflush(stdout); |
3863 | ||
c112e100 | 3864 | gs_cond.Post(); |
2f2f3e2a | 3865 | |
456ae26d | 3866 | wxPrintf(_T("Thread %lu starts to wait...\n"), GetId()); |
2f2f3e2a VZ |
3867 | fflush(stdout); |
3868 | ||
c112e100 | 3869 | m_mutex->Lock(); |
2f2f3e2a | 3870 | m_condition->Wait(); |
c112e100 | 3871 | m_mutex->Unlock(); |
2f2f3e2a | 3872 | |
456ae26d | 3873 | wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId()); |
2f2f3e2a VZ |
3874 | fflush(stdout); |
3875 | ||
3876 | return 0; | |
3877 | } | |
3878 | ||
3879 | private: | |
c112e100 | 3880 | wxMutex *m_mutex; |
2f2f3e2a VZ |
3881 | wxCondition *m_condition; |
3882 | }; | |
3883 | ||
3884 | static void TestThreadConditions() | |
3885 | { | |
c112e100 VZ |
3886 | wxMutex mutex; |
3887 | wxCondition condition(mutex); | |
2f2f3e2a | 3888 | |
8d5eff60 VZ |
3889 | // otherwise its difficult to understand which log messages pertain to |
3890 | // which condition | |
456ae26d | 3891 | //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"), |
c112e100 | 3892 | // condition.GetId(), gs_cond.GetId()); |
8d5eff60 | 3893 | |
2f2f3e2a | 3894 | // create and launch threads |
60ce696e | 3895 | MyWaitingThread *threads[10]; |
2f2f3e2a VZ |
3896 | |
3897 | size_t n; | |
3898 | for ( n = 0; n < WXSIZEOF(threads); n++ ) | |
3899 | { | |
c112e100 | 3900 | threads[n] = new MyWaitingThread( &mutex, &condition ); |
2f2f3e2a VZ |
3901 | } |
3902 | ||
3903 | for ( n = 0; n < WXSIZEOF(threads); n++ ) | |
3904 | { | |
3905 | threads[n]->Run(); | |
3906 | } | |
3907 | ||
3908 | // wait until all threads run | |
456ae26d | 3909 | wxPuts(_T("Main thread is waiting for the other threads to start")); |
2f2f3e2a VZ |
3910 | fflush(stdout); |
3911 | ||
3912 | size_t nRunning = 0; | |
3913 | while ( nRunning < WXSIZEOF(threads) ) | |
3914 | { | |
3915 | gs_cond.Wait(); | |
3916 | ||
2f2f3e2a | 3917 | nRunning++; |
8d5eff60 | 3918 | |
456ae26d | 3919 | wxPrintf(_T("Main thread: %u already running\n"), nRunning); |
8d5eff60 | 3920 | fflush(stdout); |
2f2f3e2a VZ |
3921 | } |
3922 | ||
456ae26d | 3923 | wxPuts(_T("Main thread: all threads started up.")); |
2f2f3e2a VZ |
3924 | fflush(stdout); |
3925 | ||
8d5eff60 VZ |
3926 | wxThread::Sleep(500); |
3927 | ||
60ce696e | 3928 | #if 1 |
8d5eff60 | 3929 | // now wake one of them up |
456ae26d | 3930 | wxPrintf(_T("Main thread: about to signal the condition.\n")); |
2f2f3e2a VZ |
3931 | fflush(stdout); |
3932 | condition.Signal(); | |
8d5eff60 | 3933 | #endif |
2f2f3e2a | 3934 | |
60ce696e VZ |
3935 | wxThread::Sleep(200); |
3936 | ||
8d5eff60 | 3937 | // wake all the (remaining) threads up, so that they can exit |
456ae26d | 3938 | wxPrintf(_T("Main thread: about to broadcast the condition.\n")); |
2f2f3e2a VZ |
3939 | fflush(stdout); |
3940 | condition.Broadcast(); | |
3941 | ||
8d5eff60 VZ |
3942 | // give them time to terminate (dirty!) |
3943 | wxThread::Sleep(500); | |
2f2f3e2a VZ |
3944 | } |
3945 | ||
c112e100 VZ |
3946 | #include "wx/utils.h" |
3947 | ||
3948 | class MyExecThread : public wxThread | |
3949 | { | |
3950 | public: | |
3951 | MyExecThread(const wxString& command) : wxThread(wxTHREAD_JOINABLE), | |
3952 | m_command(command) | |
3953 | { | |
3954 | Create(); | |
3955 | } | |
3956 | ||
3957 | virtual ExitCode Entry() | |
3958 | { | |
3959 | return (ExitCode)wxExecute(m_command, wxEXEC_SYNC); | |
3960 | } | |
3961 | ||
3962 | private: | |
3963 | wxString m_command; | |
3964 | }; | |
3965 | ||
3966 | static void TestThreadExec() | |
3967 | { | |
3968 | wxPuts(_T("*** Testing wxExecute interaction with threads ***\n")); | |
3969 | ||
3970 | MyExecThread thread(_T("true")); | |
3971 | thread.Run(); | |
3972 | ||
3973 | wxPrintf(_T("Main program exit code: %ld.\n"), | |
3974 | wxExecute(_T("false"), wxEXEC_SYNC)); | |
3975 | ||
3976 | wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread.Wait()); | |
3977 | } | |
3978 | ||
3979 | // semaphore tests | |
3980 | #include "wx/datetime.h" | |
3981 | ||
3982 | class MySemaphoreThread : public wxThread | |
3983 | { | |
3984 | public: | |
3985 | MySemaphoreThread(int i, wxSemaphore *sem) | |
3986 | : wxThread(wxTHREAD_JOINABLE), | |
3987 | m_sem(sem), | |
3988 | m_i(i) | |
3989 | { | |
3990 | Create(); | |
3991 | } | |
3992 | ||
3993 | virtual ExitCode Entry() | |
3994 | { | |
f06ef5f4 VZ |
3995 | wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"), |
3996 | wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId()); | |
c112e100 VZ |
3997 | |
3998 | m_sem->Wait(); | |
3999 | ||
f06ef5f4 VZ |
4000 | wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"), |
4001 | wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId()); | |
c112e100 VZ |
4002 | |
4003 | Sleep(1000); | |
4004 | ||
f06ef5f4 VZ |
4005 | wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"), |
4006 | wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId()); | |
c112e100 VZ |
4007 | |
4008 | m_sem->Post(); | |
4009 | ||
4010 | return 0; | |
4011 | } | |
4012 | ||
4013 | private: | |
4014 | wxSemaphore *m_sem; | |
4015 | int m_i; | |
4016 | }; | |
4017 | ||
e9d2bb6f | 4018 | WX_DEFINE_ARRAY_PTR(wxThread *, ArrayThreads); |
c112e100 VZ |
4019 | |
4020 | static void TestSemaphore() | |
4021 | { | |
4022 | wxPuts(_T("*** Testing wxSemaphore class. ***")); | |
4023 | ||
4024 | static const int SEM_LIMIT = 3; | |
4025 | ||
4026 | wxSemaphore sem(SEM_LIMIT, SEM_LIMIT); | |
4027 | ArrayThreads threads; | |
4028 | ||
4029 | for ( int i = 0; i < 3*SEM_LIMIT; i++ ) | |
4030 | { | |
4031 | threads.Add(new MySemaphoreThread(i, &sem)); | |
4032 | threads.Last()->Run(); | |
4033 | } | |
4034 | ||
4035 | for ( size_t n = 0; n < threads.GetCount(); n++ ) | |
4036 | { | |
4037 | threads[n]->Wait(); | |
4038 | delete threads[n]; | |
4039 | } | |
4040 | } | |
4041 | ||
e87271f3 VZ |
4042 | #endif // TEST_THREADS |
4043 | ||
e87271f3 VZ |
4044 | // ---------------------------------------------------------------------------- |
4045 | // entry point | |
4046 | // ---------------------------------------------------------------------------- | |
4047 | ||
daa2c7d9 VZ |
4048 | #ifdef TEST_SNGLINST |
4049 | #include "wx/snglinst.h" | |
4050 | #endif // TEST_SNGLINST | |
4051 | ||
bbfa0322 | 4052 | int main(int argc, char **argv) |
37667812 | 4053 | { |
5ba95b79 WS |
4054 | #if wxUSE_UNICODE |
4055 | wxChar **wxArgv = new wxChar *[argc + 1]; | |
4056 | ||
4057 | { | |
4058 | int n; | |
4059 | ||
4060 | for (n = 0; n < argc; n++ ) | |
4061 | { | |
4062 | wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); | |
4063 | wxArgv[n] = wxStrdup(warg); | |
4064 | } | |
4065 | ||
4066 | wxArgv[n] = NULL; | |
4067 | } | |
4068 | #else // !wxUSE_UNICODE | |
4069 | #define wxArgv argv | |
4070 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE | |
4071 | ||
6f35ed60 | 4072 | wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); |
9cb47ea2 | 4073 | |
58b24a56 VZ |
4074 | wxInitializer initializer; |
4075 | if ( !initializer ) | |
37667812 | 4076 | { |
be5a51fb | 4077 | fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); |
58b24a56 VZ |
4078 | |
4079 | return -1; | |
4080 | } | |
4081 | ||
4082 | #ifdef TEST_SNGLINST | |
b5299791 VZ |
4083 | wxSingleInstanceChecker checker; |
4084 | if ( checker.Create(_T(".wxconsole.lock")) ) | |
58b24a56 | 4085 | { |
b5299791 VZ |
4086 | if ( checker.IsAnotherRunning() ) |
4087 | { | |
4088 | wxPrintf(_T("Another instance of the program is running, exiting.\n")); | |
58b24a56 | 4089 | |
b5299791 VZ |
4090 | return 1; |
4091 | } | |
37667812 | 4092 | |
b5299791 VZ |
4093 | // wait some time to give time to launch another instance |
4094 | wxPrintf(_T("Press \"Enter\" to continue...")); | |
4095 | wxFgetc(stdin); | |
4096 | } | |
4097 | else // failed to create | |
4098 | { | |
4099 | wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n")); | |
4100 | } | |
58b24a56 VZ |
4101 | #endif // TEST_SNGLINST |
4102 | ||
d34bce84 | 4103 | #ifdef TEST_CMDLINE |
31f6de22 VZ |
4104 | TestCmdLineConvert(); |
4105 | ||
4106 | #if wxUSE_CMDLINE_PARSER | |
d34bce84 VZ |
4107 | static const wxCmdLineEntryDesc cmdLineDesc[] = |
4108 | { | |
456ae26d | 4109 | { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"), |
31a06b07 | 4110 | wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
456ae26d VZ |
4111 | { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") }, |
4112 | { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") }, | |
d34bce84 | 4113 | |
456ae26d VZ |
4114 | { wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file") }, |
4115 | { wxCMD_LINE_OPTION, _T("i"), _T("input"), _T("input dir") }, | |
4116 | { wxCMD_LINE_OPTION, _T("s"), _T("size"), _T("output block size"), | |
31a06b07 | 4117 | wxCMD_LINE_VAL_NUMBER }, |
456ae26d | 4118 | { wxCMD_LINE_OPTION, _T("d"), _T("date"), _T("output file date"), |
31a06b07 | 4119 | wxCMD_LINE_VAL_DATE }, |
d34bce84 | 4120 | |
456ae26d | 4121 | { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"), |
d34bce84 VZ |
4122 | wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE }, |
4123 | ||
4124 | { wxCMD_LINE_NONE } | |
4125 | }; | |
4126 | ||
5ba95b79 | 4127 | wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); |
456ae26d VZ |
4128 | |
4129 | parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"), | |
f6bcfd97 BP |
4130 | wxCMD_LINE_VAL_STRING, |
4131 | wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR); | |
4132 | ||
d34bce84 VZ |
4133 | switch ( parser.Parse() ) |
4134 | { | |
4135 | case -1: | |
456ae26d | 4136 | wxLogMessage(_T("Help was given, terminating.")); |
d34bce84 VZ |
4137 | break; |
4138 | ||
4139 | case 0: | |
4140 | ShowCmdLine(parser); | |
4141 | break; | |
4142 | ||
4143 | default: | |
456ae26d | 4144 | wxLogMessage(_T("Syntax error detected, aborting.")); |
d34bce84 VZ |
4145 | break; |
4146 | } | |
31f6de22 VZ |
4147 | #endif // wxUSE_CMDLINE_PARSER |
4148 | ||
d34bce84 VZ |
4149 | #endif // TEST_CMDLINE |
4150 | ||
1944c6bd | 4151 | #ifdef TEST_DIR |
e9d2bb6f | 4152 | #if TEST_ALL |
99a5af7f | 4153 | TestDirExists(); |
2f0c19d0 | 4154 | TestDirEnum(); |
e9d2bb6f | 4155 | #endif |
2f0c19d0 | 4156 | TestDirTraverse(); |
1944c6bd VZ |
4157 | #endif // TEST_DIR |
4158 | ||
93ed8ff7 | 4159 | #ifdef TEST_DYNLIB |
f6bcfd97 | 4160 | TestDllLoad(); |
297ebe6b | 4161 | TestDllListLoaded(); |
93ed8ff7 | 4162 | #endif // TEST_DYNLIB |
f6bcfd97 | 4163 | |
8fd0d89b VZ |
4164 | #ifdef TEST_ENVIRON |
4165 | TestEnvironment(); | |
4166 | #endif // TEST_ENVIRON | |
4167 | ||
d93c719a VZ |
4168 | #ifdef TEST_EXECUTE |
4169 | TestExecute(); | |
4170 | #endif // TEST_EXECUTE | |
4171 | ||
ee6e1b1d VZ |
4172 | #ifdef TEST_FILECONF |
4173 | TestFileConfRead(); | |
4174 | #endif // TEST_FILECONF | |
4175 | ||
ec37df57 VZ |
4176 | #ifdef TEST_LOCALE |
4177 | TestDefaultLang(); | |
4178 | #endif // TEST_LOCALE | |
4179 | ||
378b05f7 | 4180 | #ifdef TEST_LOG |
cab8f76e VZ |
4181 | wxPuts(_T("*** Testing wxLog ***")); |
4182 | ||
378b05f7 VZ |
4183 | wxString s; |
4184 | for ( size_t n = 0; n < 8000; n++ ) | |
4185 | { | |
456ae26d | 4186 | s << (wxChar)(_T('A') + (n % 26)); |
378b05f7 VZ |
4187 | } |
4188 | ||
cab8f76e VZ |
4189 | wxLogWarning(_T("The length of the string is %lu"), |
4190 | (unsigned long)s.length()); | |
4191 | ||
378b05f7 | 4192 | wxString msg; |
456ae26d | 4193 | msg.Printf(_T("A very very long message: '%s', the end!\n"), s.c_str()); |
378b05f7 VZ |
4194 | |
4195 | // this one shouldn't be truncated | |
456ae26d | 4196 | wxPrintf(msg); |
378b05f7 VZ |
4197 | |
4198 | // but this one will because log functions use fixed size buffer | |
b568d04f VZ |
4199 | // (note that it doesn't need '\n' at the end neither - will be added |
4200 | // by wxLog anyhow) | |
456ae26d | 4201 | wxLogMessage(_T("A very very long message 2: '%s', the end!"), s.c_str()); |
378b05f7 VZ |
4202 | #endif // TEST_LOG |
4203 | ||
f6bcfd97 | 4204 | #ifdef TEST_FILE |
e9d2bb6f DS |
4205 | TestFileRead(); |
4206 | TestTextFileRead(); | |
4207 | TestFileCopy(); | |
f6bcfd97 BP |
4208 | #endif // TEST_FILE |
4209 | ||
844f90fb | 4210 | #ifdef TEST_FILENAME |
e9d2bb6f DS |
4211 | TestFileNameTemp(); |
4212 | TestFileNameCwd(); | |
4213 | TestFileNameDirManip(); | |
4214 | TestFileNameComparison(); | |
4215 | TestFileNameOperations(); | |
844f90fb VZ |
4216 | #endif // TEST_FILENAME |
4217 | ||
d56e2b97 VZ |
4218 | #ifdef TEST_FILETIME |
4219 | TestFileGetTimes(); | |
e9d2bb6f | 4220 | #if 0 |
d56e2b97 | 4221 | TestFileSetTimes(); |
e9d2bb6f | 4222 | #endif |
d56e2b97 VZ |
4223 | #endif // TEST_FILETIME |
4224 | ||
07a56e45 VZ |
4225 | #ifdef TEST_FTP |
4226 | wxLog::AddTraceMask(FTP_TRACE_MASK); | |
4227 | if ( TestFtpConnect() ) | |
4228 | { | |
e9d2bb6f | 4229 | #if TEST_ALL |
07a56e45 VZ |
4230 | TestFtpList(); |
4231 | TestFtpDownload(); | |
4232 | TestFtpMisc(); | |
daa2c7d9 | 4233 | TestFtpFileSize(); |
07a56e45 | 4234 | TestFtpUpload(); |
af33b199 | 4235 | #endif // TEST_ALL |
daa2c7d9 | 4236 | |
e9d2bb6f | 4237 | #if TEST_INTERACTIVE |
daa2c7d9 | 4238 | TestFtpInteractive(); |
e9d2bb6f | 4239 | #endif |
07a56e45 VZ |
4240 | } |
4241 | //else: connecting to the FTP server failed | |
4242 | ||
e9d2bb6f | 4243 | #if 0 |
07a56e45 | 4244 | TestFtpWuFtpd(); |
e9d2bb6f | 4245 | #endif |
07a56e45 VZ |
4246 | #endif // TEST_FTP |
4247 | ||
696e1ea0 | 4248 | #ifdef TEST_MIME |
f6bcfd97 | 4249 | wxLog::AddTraceMask(_T("mime")); |
e9d2bb6f | 4250 | #if TEST_ALL |
f6bcfd97 | 4251 | TestMimeEnum(); |
c7ce8392 | 4252 | TestMimeOverride(); |
f06ef5f4 | 4253 | TestMimeAssociate(); |
e9d2bb6f | 4254 | #endif |
f06ef5f4 | 4255 | TestMimeFilename(); |
696e1ea0 VZ |
4256 | #endif // TEST_MIME |
4257 | ||
89e60357 | 4258 | #ifdef TEST_INFO_FUNCTIONS |
e9d2bb6f | 4259 | #if TEST_ALL |
3a994742 VZ |
4260 | TestOsInfo(); |
4261 | TestUserInfo(); | |
19f45995 | 4262 | |
e9d2bb6f | 4263 | #if TEST_INTERACTIVE |
19f45995 | 4264 | TestDiskInfo(); |
e9d2bb6f DS |
4265 | #endif |
4266 | #endif | |
89e60357 VZ |
4267 | #endif // TEST_INFO_FUNCTIONS |
4268 | ||
39189b9d VZ |
4269 | #ifdef TEST_PATHLIST |
4270 | TestPathList(); | |
4271 | #endif // TEST_PATHLIST | |
4272 | ||
8d5eff60 VZ |
4273 | #ifdef TEST_ODBC |
4274 | TestDbOpen(); | |
4275 | #endif // TEST_ODBC | |
4276 | ||
7aeebdcd VZ |
4277 | #ifdef TEST_PRINTF |
4278 | TestPrintf(); | |
4279 | #endif // TEST_PRINTF | |
4280 | ||
7ba4fbeb | 4281 | #ifdef TEST_REGCONF |
e9d2bb6f DS |
4282 | #if 0 |
4283 | TestRegConfWrite(); | |
4284 | #endif | |
0aa29b6b | 4285 | TestRegConfRead(); |
7ba4fbeb VZ |
4286 | #endif // TEST_REGCONF |
4287 | ||
bc10103e VS |
4288 | #if defined TEST_REGEX && TEST_INTERACTIVE |
4289 | TestRegExInteractive(); | |
4290 | #endif // defined TEST_REGEX && TEST_INTERACTIVE | |
07a56e45 | 4291 | |
6dfec4b8 | 4292 | #ifdef TEST_REGISTRY |
daa2c7d9 | 4293 | TestRegistryRead(); |
6ba63600 | 4294 | TestRegistryAssociation(); |
6dfec4b8 VZ |
4295 | #endif // TEST_REGISTRY |
4296 | ||
2c8e4738 | 4297 | #ifdef TEST_SOCKETS |
daa2c7d9 VZ |
4298 | TestSocketServer(); |
4299 | TestSocketClient(); | |
2c8e4738 VZ |
4300 | #endif // TEST_SOCKETS |
4301 | ||
83141d3a | 4302 | #ifdef TEST_STREAMS |
e9d2bb6f | 4303 | #if TEST_ALL |
99a5af7f | 4304 | TestFileStream(); |
e9d2bb6f | 4305 | #endif |
99a5af7f | 4306 | TestMemoryStream(); |
83141d3a VZ |
4307 | #endif // TEST_STREAMS |
4308 | ||
39937656 VZ |
4309 | #ifdef TEST_TEXTSTREAM |
4310 | TestTextInputStream(); | |
4311 | #endif // TEST_TEXTSTREAM | |
4312 | ||
8d5eff60 VZ |
4313 | #ifdef TEST_THREADS |
4314 | int nCPUs = wxThread::GetCPUCount(); | |
456ae26d | 4315 | wxPrintf(_T("This system has %d CPUs\n"), nCPUs); |
8d5eff60 VZ |
4316 | if ( nCPUs != -1 ) |
4317 | wxThread::SetConcurrency(nCPUs); | |
4318 | ||
5bc1deeb VZ |
4319 | TestJoinableThreads(); |
4320 | ||
e9d2bb6f | 4321 | #if TEST_ALL |
8d5eff60 | 4322 | TestJoinableThreads(); |
5bc1deeb | 4323 | TestDetachedThreads(); |
8d5eff60 VZ |
4324 | TestThreadSuspend(); |
4325 | TestThreadDelete(); | |
c112e100 VZ |
4326 | TestThreadConditions(); |
4327 | TestThreadExec(); | |
7aeebdcd | 4328 | TestSemaphore(); |
e9d2bb6f | 4329 | #endif |
8d5eff60 VZ |
4330 | #endif // TEST_THREADS |
4331 | ||
d31b7b68 VZ |
4332 | #ifdef TEST_TIMER |
4333 | TestStopWatch(); | |
4334 | #endif // TEST_TIMER | |
4335 | ||
4336 | #ifdef TEST_DATETIME | |
e9d2bb6f | 4337 | #if TEST_ALL |
9d9b7755 VZ |
4338 | TestTimeStatic(); |
4339 | TestTimeRange(); | |
4340 | TestTimeZones(); | |
9d9b7755 | 4341 | TestTimeDST(); |
f6bcfd97 | 4342 | TestTimeHolidays(); |
daa2c7d9 | 4343 | TestTimeSpanFormat(); |
3ca6a5f0 | 4344 | TestTimeMS(); |
f6bcfd97 BP |
4345 | |
4346 | TestTimeZoneBug(); | |
e9d2bb6f | 4347 | #endif |
2b5f62a0 | 4348 | |
e9d2bb6f | 4349 | #if TEST_INTERACTIVE |
b92fd37c | 4350 | TestDateTimeInteractive(); |
e9d2bb6f | 4351 | #endif |
d31b7b68 | 4352 | #endif // TEST_DATETIME |
b76b015e | 4353 | |
df5168c4 MB |
4354 | #ifdef TEST_SCOPEGUARD |
4355 | TestScopeGuard(); | |
4356 | #endif | |
4357 | ||
eaff0f0d | 4358 | #ifdef TEST_STACKWALKER |
60c474a0 | 4359 | #if wxUSE_STACKWALKER |
eaff0f0d | 4360 | TestStackWalk(argv[0]); |
60c474a0 | 4361 | #endif |
eaff0f0d VZ |
4362 | #endif // TEST_STACKWALKER |
4363 | ||
af33b199 VZ |
4364 | #ifdef TEST_STDPATHS |
4365 | TestStandardPaths(); | |
4366 | #endif | |
4367 | ||
551fe3a6 | 4368 | #ifdef TEST_USLEEP |
456ae26d | 4369 | wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z...")); |
551fe3a6 VZ |
4370 | wxUsleep(3000); |
4371 | #endif // TEST_USLEEP | |
4372 | ||
f6bcfd97 | 4373 | #ifdef TEST_VCARD |
f6bcfd97 BP |
4374 | TestVCardRead(); |
4375 | TestVCardWrite(); | |
4376 | #endif // TEST_VCARD | |
4377 | ||
0e2c5534 VZ |
4378 | #ifdef TEST_VOLUME |
4379 | TestFSVolume(); | |
4380 | #endif // TEST_VOLUME | |
4381 | ||
f6bcfd97 BP |
4382 | #ifdef TEST_WCHAR |
4383 | TestUtf8(); | |
ac511156 | 4384 | TestEncodingConverter(); |
f6bcfd97 BP |
4385 | #endif // TEST_WCHAR |
4386 | ||
4387 | #ifdef TEST_ZIP | |
daa2c7d9 | 4388 | TestZipStreamRead(); |
2ca8b884 | 4389 | TestZipFileSystem(); |
f6bcfd97 BP |
4390 | #endif // TEST_ZIP |
4391 | ||
5ba95b79 WS |
4392 | #if wxUSE_UNICODE |
4393 | { | |
4394 | for ( int n = 0; n < argc; n++ ) | |
4395 | free(wxArgv[n]); | |
4396 | ||
4397 | delete [] wxArgv; | |
4398 | } | |
4399 | #endif // wxUSE_UNICODE | |
4400 | ||
e9d2bb6f DS |
4401 | wxUnusedVar(argc); |
4402 | wxUnusedVar(argv); | |
37667812 VZ |
4403 | return 0; |
4404 | } |