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