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