]>
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 | ||
42fb9cdf FM |
12 | // IMPORTANT NOTE FOR WXWIDGETS USERS: |
13 | // If you're a wxWidgets user and you're looking at this file to learn how to | |
14 | // structure a wxWidgets console application, then you don't have much to learn. | |
15 | // This application is used more for testing rather than as sample but | |
16 | // basically the following simple block is enough for you to start your | |
17 | // own console application: | |
18 | ||
19 | /* | |
20 | int main(int argc, char **argv) | |
21 | { | |
22 | wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); | |
23 | ||
24 | wxInitializer initializer; | |
25 | if ( !initializer ) | |
26 | { | |
27 | fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); | |
28 | return -1; | |
29 | } | |
30 | ||
31 | static const wxCmdLineEntryDesc cmdLineDesc[] = | |
32 | { | |
33 | { wxCMD_LINE_SWITCH, "h", "help", "show this help message", | |
34 | wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, | |
35 | // ... your other command line options here... | |
36 | ||
37 | { wxCMD_LINE_NONE } | |
38 | }; | |
39 | ||
40 | wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); | |
41 | switch ( parser.Parse() ) | |
42 | { | |
43 | case -1: | |
9a83f860 | 44 | wxLogMessage(wxT("Help was given, terminating.")); |
42fb9cdf FM |
45 | break; |
46 | ||
47 | case 0: | |
48 | // everything is ok; proceed | |
49 | break; | |
50 | ||
51 | default: | |
9a83f860 | 52 | wxLogMessage(wxT("Syntax error detected, aborting.")); |
42fb9cdf FM |
53 | break; |
54 | } | |
55 | ||
56 | // do something useful here | |
57 | ||
58 | return 0; | |
59 | } | |
60 | */ | |
61 | ||
62 | ||
e87271f3 VZ |
63 | // ============================================================================ |
64 | // declarations | |
65 | // ============================================================================ | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // headers | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
e84010cf | 71 | #include "wx/defs.h" |
b11a23f3 | 72 | |
37667812 VZ |
73 | #include <stdio.h> |
74 | ||
e84010cf GD |
75 | #include "wx/string.h" |
76 | #include "wx/file.h" | |
06fe46e2 | 77 | #include "wx/filename.h" |
e84010cf | 78 | #include "wx/app.h" |
e046e5f1 | 79 | #include "wx/log.h" |
8bb6b2c0 VZ |
80 | #include "wx/apptrait.h" |
81 | #include "wx/platinfo.h" | |
74e10fcc | 82 | #include "wx/wxchar.h" |
e87271f3 | 83 | |
d31b7b68 VZ |
84 | // without this pragma, the stupid compiler precompiles #defines below so that |
85 | // changing them doesn't "take place" later! | |
86 | #ifdef __VISUALC__ | |
87 | #pragma hdrstop | |
88 | #endif | |
89 | ||
e87271f3 VZ |
90 | // ---------------------------------------------------------------------------- |
91 | // conditional compilation | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
daa2c7d9 VZ |
94 | /* |
95 | A note about all these conditional compilation macros: this file is used | |
be5a51fb | 96 | both as a test suite for various non-GUI wxWidgets classes and as a |
daa2c7d9 VZ |
97 | scratchpad for quick tests. So there are two compilation modes: if you |
98 | define TEST_ALL all tests are run, otherwise you may enable the individual | |
99 | tests individually in the "#else" branch below. | |
100 | */ | |
101 | ||
e9d2bb6f DS |
102 | // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single |
103 | // test, define it to 1 to do all tests. | |
91ee2f35 | 104 | #define TEST_ALL 0 |
e9d2bb6f DS |
105 | |
106 | ||
107 | #if TEST_ALL | |
31f6de22 VZ |
108 | #define TEST_DATETIME |
109 | #define TEST_DIR | |
93ed8ff7 | 110 | #define TEST_DYNLIB |
31f6de22 | 111 | #define TEST_ENVIRON |
31f6de22 VZ |
112 | #define TEST_FILE |
113 | #define TEST_FILECONF | |
114 | #define TEST_FILENAME | |
115 | #define TEST_FILETIME | |
31f6de22 | 116 | #define TEST_INFO_FUNCTIONS |
31f6de22 VZ |
117 | #define TEST_LOCALE |
118 | #define TEST_LOG | |
31f6de22 | 119 | #define TEST_MIME |
af266e5b | 120 | #define TEST_MODULE |
31f6de22 | 121 | #define TEST_PATHLIST |
7aeebdcd | 122 | #define TEST_PRINTF |
31f6de22 VZ |
123 | #define TEST_REGCONF |
124 | #define TEST_REGEX | |
125 | #define TEST_REGISTRY | |
e9d2bb6f | 126 | #else // #if TEST_ALL |
91ee2f35 | 127 | #define TEST_DATETIME |
45cb7053 | 128 | #define TEST_VOLUME |
ec0e0939 FM |
129 | #define TEST_STDPATHS |
130 | #define TEST_STACKWALKER | |
131 | #define TEST_FTP | |
30ccbb89 | 132 | #define TEST_SNGLINST |
31f6de22 | 133 | #endif |
f6bcfd97 | 134 | |
daa2c7d9 VZ |
135 | // some tests are interactive, define this to run them |
136 | #ifdef TEST_INTERACTIVE | |
137 | #undef TEST_INTERACTIVE | |
138 | ||
e9d2bb6f | 139 | #define TEST_INTERACTIVE 1 |
daa2c7d9 | 140 | #else |
91ee2f35 | 141 | #define TEST_INTERACTIVE 1 |
daa2c7d9 | 142 | #endif |
58b24a56 | 143 | |
e87271f3 VZ |
144 | // ============================================================================ |
145 | // implementation | |
146 | // ============================================================================ | |
147 | ||
1944c6bd VZ |
148 | // ---------------------------------------------------------------------------- |
149 | // wxDir | |
150 | // ---------------------------------------------------------------------------- | |
151 | ||
152 | #ifdef TEST_DIR | |
153 | ||
e84010cf | 154 | #include "wx/dir.h" |
1944c6bd | 155 | |
35332784 | 156 | #ifdef __UNIX__ |
9a83f860 VZ |
157 | static const wxChar *ROOTDIR = wxT("/"); |
158 | static const wxChar *TESTDIR = wxT("/usr/local/share"); | |
65e324b4 | 159 | #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__) |
9a83f860 VZ |
160 | static const wxChar *ROOTDIR = wxT("c:\\"); |
161 | static const wxChar *TESTDIR = wxT("d:\\"); | |
35332784 VZ |
162 | #else |
163 | #error "don't know where the root directory is" | |
164 | #endif | |
165 | ||
1944c6bd VZ |
166 | static void TestDirEnumHelper(wxDir& dir, |
167 | int flags = wxDIR_DEFAULT, | |
168 | const wxString& filespec = wxEmptyString) | |
169 | { | |
170 | wxString filename; | |
171 | ||
172 | if ( !dir.IsOpened() ) | |
173 | return; | |
174 | ||
175 | bool cont = dir.GetFirst(&filename, filespec, flags); | |
176 | while ( cont ) | |
177 | { | |
9a83f860 | 178 | wxPrintf(wxT("\t%s\n"), filename.c_str()); |
1944c6bd VZ |
179 | |
180 | cont = dir.GetNext(&filename); | |
181 | } | |
182 | ||
e9d2bb6f | 183 | wxPuts(wxEmptyString); |
1944c6bd VZ |
184 | } |
185 | ||
dab6fbae WS |
186 | #if TEST_ALL |
187 | ||
1944c6bd VZ |
188 | static void TestDirEnum() |
189 | { | |
9a83f860 | 190 | wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***")); |
35332784 | 191 | |
149147e1 | 192 | wxString cwd = wxGetCwd(); |
9475670f | 193 | if ( !wxDir::Exists(cwd) ) |
149147e1 | 194 | { |
9a83f860 | 195 | wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str()); |
149147e1 VZ |
196 | return; |
197 | } | |
198 | ||
ee3ef281 | 199 | wxDir dir(cwd); |
149147e1 VZ |
200 | if ( !dir.IsOpened() ) |
201 | { | |
9a83f860 | 202 | wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd.c_str()); |
149147e1 VZ |
203 | return; |
204 | } | |
1944c6bd | 205 | |
9a83f860 | 206 | wxPuts(wxT("Enumerating everything in current directory:")); |
1944c6bd VZ |
207 | TestDirEnumHelper(dir); |
208 | ||
9a83f860 | 209 | wxPuts(wxT("Enumerating really everything in current directory:")); |
1944c6bd VZ |
210 | TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT); |
211 | ||
9a83f860 VZ |
212 | wxPuts(wxT("Enumerating object files in current directory:")); |
213 | TestDirEnumHelper(dir, wxDIR_DEFAULT, wxT("*.o*")); | |
1944c6bd | 214 | |
9a83f860 | 215 | wxPuts(wxT("Enumerating directories in current directory:")); |
1944c6bd VZ |
216 | TestDirEnumHelper(dir, wxDIR_DIRS); |
217 | ||
9a83f860 | 218 | wxPuts(wxT("Enumerating files in current directory:")); |
1944c6bd VZ |
219 | TestDirEnumHelper(dir, wxDIR_FILES); |
220 | ||
9a83f860 | 221 | wxPuts(wxT("Enumerating files including hidden in current directory:")); |
1944c6bd VZ |
222 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
223 | ||
35332784 | 224 | dir.Open(ROOTDIR); |
1944c6bd | 225 | |
9a83f860 | 226 | wxPuts(wxT("Enumerating everything in root directory:")); |
1944c6bd VZ |
227 | TestDirEnumHelper(dir, wxDIR_DEFAULT); |
228 | ||
9a83f860 | 229 | wxPuts(wxT("Enumerating directories in root directory:")); |
1944c6bd VZ |
230 | TestDirEnumHelper(dir, wxDIR_DIRS); |
231 | ||
9a83f860 | 232 | wxPuts(wxT("Enumerating files in root directory:")); |
1944c6bd VZ |
233 | TestDirEnumHelper(dir, wxDIR_FILES); |
234 | ||
9a83f860 | 235 | wxPuts(wxT("Enumerating files including hidden in root directory:")); |
1944c6bd VZ |
236 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
237 | ||
9a83f860 VZ |
238 | wxPuts(wxT("Enumerating files in non existing directory:")); |
239 | wxDir dirNo(wxT("nosuchdir")); | |
1944c6bd VZ |
240 | TestDirEnumHelper(dirNo); |
241 | } | |
242 | ||
dab6fbae WS |
243 | #endif // TEST_ALL |
244 | ||
35332784 VZ |
245 | class DirPrintTraverser : public wxDirTraverser |
246 | { | |
247 | public: | |
e9d2bb6f | 248 | virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) |
35332784 VZ |
249 | { |
250 | return wxDIR_CONTINUE; | |
251 | } | |
252 | ||
253 | virtual wxDirTraverseResult OnDir(const wxString& dirname) | |
254 | { | |
255 | wxString path, name, ext; | |
bd365871 | 256 | wxFileName::SplitPath(dirname, &path, &name, &ext); |
35332784 VZ |
257 | |
258 | if ( !ext.empty() ) | |
9a83f860 | 259 | name << wxT('.') << ext; |
35332784 VZ |
260 | |
261 | wxString indent; | |
262 | for ( const wxChar *p = path.c_str(); *p; p++ ) | |
263 | { | |
264 | if ( wxIsPathSeparator(*p) ) | |
9a83f860 | 265 | indent += wxT(" "); |
35332784 VZ |
266 | } |
267 | ||
9a83f860 | 268 | wxPrintf(wxT("%s%s\n"), indent.c_str(), name.c_str()); |
35332784 VZ |
269 | |
270 | return wxDIR_CONTINUE; | |
271 | } | |
272 | }; | |
273 | ||
274 | static void TestDirTraverse() | |
275 | { | |
9a83f860 | 276 | wxPuts(wxT("*** Testing wxDir::Traverse() ***")); |
35332784 VZ |
277 | |
278 | // enum all files | |
279 | wxArrayString files; | |
280 | size_t n = wxDir::GetAllFiles(TESTDIR, &files); | |
9a83f860 | 281 | wxPrintf(wxT("There are %u files under '%s'\n"), n, TESTDIR); |
35332784 VZ |
282 | if ( n > 1 ) |
283 | { | |
9a83f860 VZ |
284 | wxPrintf(wxT("First one is '%s'\n"), files[0u].c_str()); |
285 | wxPrintf(wxT(" last one is '%s'\n"), files[n - 1].c_str()); | |
35332784 VZ |
286 | } |
287 | ||
288 | // enum again with custom traverser | |
9a83f860 | 289 | wxPuts(wxT("Now enumerating directories:")); |
35332784 VZ |
290 | wxDir dir(TESTDIR); |
291 | DirPrintTraverser traverser; | |
e9d2bb6f | 292 | dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN); |
35332784 VZ |
293 | } |
294 | ||
dab6fbae WS |
295 | #if TEST_ALL |
296 | ||
149147e1 VZ |
297 | static void TestDirExists() |
298 | { | |
9a83f860 | 299 | wxPuts(wxT("*** Testing wxDir::Exists() ***")); |
149147e1 | 300 | |
456ae26d | 301 | static const wxChar *dirnames[] = |
149147e1 | 302 | { |
9a83f860 | 303 | wxT("."), |
149147e1 | 304 | #if defined(__WXMSW__) |
9a83f860 VZ |
305 | wxT("c:"), |
306 | wxT("c:\\"), | |
307 | wxT("\\\\share\\file"), | |
308 | wxT("c:\\dos"), | |
309 | wxT("c:\\dos\\"), | |
310 | wxT("c:\\dos\\\\"), | |
311 | wxT("c:\\autoexec.bat"), | |
149147e1 | 312 | #elif defined(__UNIX__) |
9a83f860 VZ |
313 | wxT("/"), |
314 | wxT("//"), | |
315 | wxT("/usr/bin"), | |
316 | wxT("/usr//bin"), | |
317 | wxT("/usr///bin"), | |
149147e1 VZ |
318 | #endif |
319 | }; | |
320 | ||
321 | for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ ) | |
322 | { | |
9a83f860 | 323 | wxPrintf(wxT("%-40s: %s\n"), |
456ae26d | 324 | dirnames[n], |
9a83f860 VZ |
325 | wxDir::Exists(dirnames[n]) ? wxT("exists") |
326 | : wxT("doesn't exist")); | |
149147e1 VZ |
327 | } |
328 | } | |
329 | ||
dab6fbae WS |
330 | #endif // TEST_ALL |
331 | ||
1944c6bd VZ |
332 | #endif // TEST_DIR |
333 | ||
f6bcfd97 BP |
334 | // ---------------------------------------------------------------------------- |
335 | // wxDllLoader | |
336 | // ---------------------------------------------------------------------------- | |
337 | ||
93ed8ff7 | 338 | #ifdef TEST_DYNLIB |
f6bcfd97 | 339 | |
e84010cf | 340 | #include "wx/dynlib.h" |
f6bcfd97 BP |
341 | |
342 | static void TestDllLoad() | |
343 | { | |
344 | #if defined(__WXMSW__) | |
9a83f860 VZ |
345 | static const wxChar *LIB_NAME = wxT("kernel32.dll"); |
346 | static const wxChar *FUNC_NAME = wxT("lstrlenA"); | |
f6bcfd97 BP |
347 | #elif defined(__UNIX__) |
348 | // weird: using just libc.so does *not* work! | |
9a83f860 VZ |
349 | static const wxChar *LIB_NAME = wxT("/lib/libc.so.6"); |
350 | static const wxChar *FUNC_NAME = wxT("strlen"); | |
f6bcfd97 BP |
351 | #else |
352 | #error "don't know how to test wxDllLoader on this platform" | |
353 | #endif | |
354 | ||
9a83f860 | 355 | wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n")); |
f6bcfd97 | 356 | |
456ae26d VZ |
357 | wxDynamicLibrary lib(LIB_NAME); |
358 | if ( !lib.IsLoaded() ) | |
f6bcfd97 | 359 | { |
9a83f860 | 360 | wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME); |
f6bcfd97 BP |
361 | } |
362 | else | |
363 | { | |
93ed8ff7 | 364 | typedef int (wxSTDCALL *wxStrlenType)(const char *); |
456ae26d | 365 | wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME); |
f6bcfd97 BP |
366 | if ( !pfnStrlen ) |
367 | { | |
9a83f860 | 368 | wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"), |
f6bcfd97 BP |
369 | FUNC_NAME, LIB_NAME); |
370 | } | |
371 | else | |
372 | { | |
9a83f860 | 373 | wxPrintf(wxT("Calling %s dynamically loaded from %s "), |
e259f83e VZ |
374 | FUNC_NAME, LIB_NAME); |
375 | ||
f6bcfd97 BP |
376 | if ( pfnStrlen("foo") != 3 ) |
377 | { | |
9a83f860 | 378 | wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n")); |
f6bcfd97 BP |
379 | } |
380 | else | |
381 | { | |
9a83f860 | 382 | wxPuts(wxT("... ok")); |
f6bcfd97 BP |
383 | } |
384 | } | |
93ed8ff7 VZ |
385 | |
386 | #ifdef __WXMSW__ | |
9a83f860 | 387 | static const wxChar *FUNC_NAME_AW = wxT("lstrlen"); |
93ed8ff7 VZ |
388 | |
389 | typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *); | |
390 | wxStrlenTypeAorW | |
391 | pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW); | |
392 | if ( !pfnStrlenAorW ) | |
393 | { | |
9a83f860 | 394 | wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"), |
93ed8ff7 VZ |
395 | FUNC_NAME_AW, LIB_NAME); |
396 | } | |
397 | else | |
398 | { | |
9a83f860 | 399 | if ( pfnStrlenAorW(wxT("foobar")) != 6 ) |
93ed8ff7 | 400 | { |
9a83f860 | 401 | wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n")); |
93ed8ff7 VZ |
402 | } |
403 | } | |
404 | #endif // __WXMSW__ | |
f6bcfd97 BP |
405 | } |
406 | } | |
407 | ||
297ebe6b VZ |
408 | #if defined(__WXMSW__) || defined(__UNIX__) |
409 | ||
410 | static void TestDllListLoaded() | |
411 | { | |
9a83f860 | 412 | wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n")); |
297ebe6b VZ |
413 | |
414 | puts("\nLoaded modules:"); | |
415 | wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded(); | |
416 | const size_t count = dlls.GetCount(); | |
417 | for ( size_t n = 0; n < count; ++n ) | |
418 | { | |
419 | const wxDynamicLibraryDetails& details = dlls[n]; | |
bf3bf677 | 420 | printf("%-45s", (const char *)details.GetPath().mb_str()); |
297ebe6b | 421 | |
92981c93 VZ |
422 | void *addr wxDUMMY_INITIALIZE(NULL); |
423 | size_t len wxDUMMY_INITIALIZE(0); | |
297ebe6b VZ |
424 | if ( details.GetAddress(&addr, &len) ) |
425 | { | |
426 | printf(" %08lx:%08lx", | |
427 | (unsigned long)addr, (unsigned long)((char *)addr + len)); | |
428 | } | |
429 | ||
bf3bf677 | 430 | printf(" %s\n", (const char *)details.GetVersion().mb_str()); |
297ebe6b VZ |
431 | } |
432 | } | |
433 | ||
434 | #endif | |
435 | ||
93ed8ff7 | 436 | #endif // TEST_DYNLIB |
f6bcfd97 | 437 | |
8fd0d89b VZ |
438 | // ---------------------------------------------------------------------------- |
439 | // wxGet/SetEnv | |
440 | // ---------------------------------------------------------------------------- | |
441 | ||
442 | #ifdef TEST_ENVIRON | |
443 | ||
e84010cf | 444 | #include "wx/utils.h" |
8fd0d89b | 445 | |
308978f6 VZ |
446 | static wxString MyGetEnv(const wxString& var) |
447 | { | |
448 | wxString val; | |
449 | if ( !wxGetEnv(var, &val) ) | |
9a83f860 | 450 | val = wxT("<empty>"); |
308978f6 | 451 | else |
9a83f860 | 452 | val = wxString(wxT('\'')) + val + wxT('\''); |
308978f6 VZ |
453 | |
454 | return val; | |
455 | } | |
456 | ||
8fd0d89b VZ |
457 | static void TestEnvironment() |
458 | { | |
9a83f860 | 459 | const wxChar *var = wxT("wxTestVar"); |
8fd0d89b | 460 | |
9a83f860 | 461 | wxPuts(wxT("*** testing environment access functions ***")); |
8fd0d89b | 462 | |
9a83f860 VZ |
463 | wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
464 | wxSetEnv(var, wxT("value for wxTestVar")); | |
465 | wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); | |
466 | wxSetEnv(var, wxT("another value")); | |
467 | wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); | |
8fd0d89b | 468 | wxUnsetEnv(var); |
9a83f860 VZ |
469 | wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
470 | wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str()); | |
8fd0d89b VZ |
471 | } |
472 | ||
473 | #endif // TEST_ENVIRON | |
474 | ||
f6bcfd97 BP |
475 | // ---------------------------------------------------------------------------- |
476 | // file | |
477 | // ---------------------------------------------------------------------------- | |
478 | ||
479 | #ifdef TEST_FILE | |
480 | ||
e84010cf GD |
481 | #include "wx/file.h" |
482 | #include "wx/ffile.h" | |
483 | #include "wx/textfile.h" | |
f6bcfd97 BP |
484 | |
485 | static void TestFileRead() | |
486 | { | |
9a83f860 | 487 | wxPuts(wxT("*** wxFile read test ***")); |
f6bcfd97 | 488 | |
9a83f860 | 489 | wxFile file(wxT("testdata.fc")); |
f6bcfd97 BP |
490 | if ( file.IsOpened() ) |
491 | { | |
9a83f860 | 492 | wxPrintf(wxT("File length: %lu\n"), file.Length()); |
f6bcfd97 | 493 | |
9a83f860 | 494 | wxPuts(wxT("File dump:\n----------")); |
f6bcfd97 | 495 | |
30984dea | 496 | static const size_t len = 1024; |
456ae26d | 497 | wxChar buf[len]; |
f6bcfd97 BP |
498 | for ( ;; ) |
499 | { | |
30984dea VZ |
500 | size_t nRead = file.Read(buf, len); |
501 | if ( nRead == (size_t)wxInvalidOffset ) | |
f6bcfd97 | 502 | { |
9a83f860 | 503 | wxPrintf(wxT("Failed to read the file.")); |
f6bcfd97 BP |
504 | break; |
505 | } | |
506 | ||
507 | fwrite(buf, nRead, 1, stdout); | |
508 | ||
509 | if ( nRead < len ) | |
510 | break; | |
511 | } | |
512 | ||
9a83f860 | 513 | wxPuts(wxT("----------")); |
f6bcfd97 BP |
514 | } |
515 | else | |
516 | { | |
9a83f860 | 517 | wxPrintf(wxT("ERROR: can't open test file.\n")); |
f6bcfd97 BP |
518 | } |
519 | ||
e9d2bb6f | 520 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
521 | } |
522 | ||
523 | static void TestTextFileRead() | |
524 | { | |
9a83f860 | 525 | wxPuts(wxT("*** wxTextFile read test ***")); |
f6bcfd97 | 526 | |
9a83f860 | 527 | wxTextFile file(wxT("testdata.fc")); |
f6bcfd97 BP |
528 | if ( file.Open() ) |
529 | { | |
9a83f860 VZ |
530 | wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount()); |
531 | wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str()); | |
3ca6a5f0 BP |
532 | |
533 | wxString s; | |
534 | ||
9a83f860 | 535 | wxPuts(wxT("\nDumping the entire file:")); |
3ca6a5f0 BP |
536 | for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() ) |
537 | { | |
9a83f860 | 538 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 539 | } |
9a83f860 | 540 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 541 | |
9a83f860 | 542 | wxPuts(wxT("\nAnd now backwards:")); |
3ca6a5f0 BP |
543 | for ( s = file.GetLastLine(); |
544 | file.GetCurrentLine() != 0; | |
545 | s = file.GetPrevLine() ) | |
546 | { | |
9a83f860 | 547 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 548 | } |
9a83f860 | 549 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
f6bcfd97 BP |
550 | } |
551 | else | |
552 | { | |
9a83f860 | 553 | wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName()); |
f6bcfd97 BP |
554 | } |
555 | ||
e9d2bb6f | 556 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
557 | } |
558 | ||
a339970a VZ |
559 | static void TestFileCopy() |
560 | { | |
9a83f860 | 561 | wxPuts(wxT("*** Testing wxCopyFile ***")); |
a339970a | 562 | |
9a83f860 VZ |
563 | static const wxChar *filename1 = wxT("testdata.fc"); |
564 | static const wxChar *filename2 = wxT("test2"); | |
a339970a VZ |
565 | if ( !wxCopyFile(filename1, filename2) ) |
566 | { | |
9a83f860 | 567 | wxPuts(wxT("ERROR: failed to copy file")); |
a339970a VZ |
568 | } |
569 | else | |
570 | { | |
9a83f860 VZ |
571 | wxFFile f1(filename1, wxT("rb")), |
572 | f2(filename2, wxT("rb")); | |
a339970a VZ |
573 | |
574 | if ( !f1.IsOpened() || !f2.IsOpened() ) | |
575 | { | |
9a83f860 | 576 | wxPuts(wxT("ERROR: failed to open file(s)")); |
a339970a VZ |
577 | } |
578 | else | |
579 | { | |
580 | wxString s1, s2; | |
581 | if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) ) | |
582 | { | |
9a83f860 | 583 | wxPuts(wxT("ERROR: failed to read file(s)")); |
a339970a VZ |
584 | } |
585 | else | |
586 | { | |
587 | if ( (s1.length() != s2.length()) || | |
588 | (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) ) | |
589 | { | |
9a83f860 | 590 | wxPuts(wxT("ERROR: copy error!")); |
a339970a VZ |
591 | } |
592 | else | |
593 | { | |
9a83f860 | 594 | wxPuts(wxT("File was copied ok.")); |
a339970a VZ |
595 | } |
596 | } | |
597 | } | |
598 | } | |
599 | ||
600 | if ( !wxRemoveFile(filename2) ) | |
601 | { | |
9a83f860 | 602 | wxPuts(wxT("ERROR: failed to remove the file")); |
a339970a VZ |
603 | } |
604 | ||
e9d2bb6f | 605 | wxPuts(wxEmptyString); |
a339970a VZ |
606 | } |
607 | ||
59062ec1 VZ |
608 | static void TestTempFile() |
609 | { | |
9a83f860 | 610 | wxPuts(wxT("*** wxTempFile test ***")); |
59062ec1 VZ |
611 | |
612 | wxTempFile tmpFile; | |
9a83f860 | 613 | if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) ) |
59062ec1 VZ |
614 | { |
615 | if ( tmpFile.Commit() ) | |
9a83f860 | 616 | wxPuts(wxT("File committed.")); |
59062ec1 | 617 | else |
9a83f860 | 618 | wxPuts(wxT("ERROR: could't commit temp file.")); |
59062ec1 | 619 | |
9a83f860 | 620 | wxRemoveFile(wxT("test2")); |
59062ec1 VZ |
621 | } |
622 | ||
623 | wxPuts(wxEmptyString); | |
624 | } | |
625 | ||
f6bcfd97 BP |
626 | #endif // TEST_FILE |
627 | ||
ee6e1b1d VZ |
628 | // ---------------------------------------------------------------------------- |
629 | // wxFileConfig | |
630 | // ---------------------------------------------------------------------------- | |
631 | ||
632 | #ifdef TEST_FILECONF | |
633 | ||
e84010cf GD |
634 | #include "wx/confbase.h" |
635 | #include "wx/fileconf.h" | |
ee6e1b1d VZ |
636 | |
637 | static const struct FileConfTestData | |
638 | { | |
639 | const wxChar *name; // value name | |
640 | const wxChar *value; // the value from the file | |
641 | } fcTestData[] = | |
642 | { | |
9a83f860 VZ |
643 | { wxT("value1"), wxT("one") }, |
644 | { wxT("value2"), wxT("two") }, | |
645 | { wxT("novalue"), wxT("default") }, | |
ee6e1b1d VZ |
646 | }; |
647 | ||
648 | static void TestFileConfRead() | |
649 | { | |
9a83f860 | 650 | wxPuts(wxT("*** testing wxFileConfig loading/reading ***")); |
ee6e1b1d | 651 | |
9a83f860 VZ |
652 | wxFileConfig fileconf(wxT("test"), wxEmptyString, |
653 | wxT("testdata.fc"), wxEmptyString, | |
ee6e1b1d VZ |
654 | wxCONFIG_USE_RELATIVE_PATH); |
655 | ||
656 | // test simple reading | |
9a83f860 VZ |
657 | wxPuts(wxT("\nReading config file:")); |
658 | wxString defValue(wxT("default")), value; | |
ee6e1b1d VZ |
659 | for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ ) |
660 | { | |
661 | const FileConfTestData& data = fcTestData[n]; | |
662 | value = fileconf.Read(data.name, defValue); | |
9a83f860 | 663 | wxPrintf(wxT("\t%s = %s "), data.name, value.c_str()); |
ee6e1b1d VZ |
664 | if ( value == data.value ) |
665 | { | |
9a83f860 | 666 | wxPuts(wxT("(ok)")); |
ee6e1b1d VZ |
667 | } |
668 | else | |
669 | { | |
9a83f860 | 670 | wxPrintf(wxT("(ERROR: should be %s)\n"), data.value); |
ee6e1b1d VZ |
671 | } |
672 | } | |
673 | ||
674 | // test enumerating the entries | |
9a83f860 | 675 | wxPuts(wxT("\nEnumerating all root entries:")); |
ee6e1b1d VZ |
676 | long dummy; |
677 | wxString name; | |
678 | bool cont = fileconf.GetFirstEntry(name, dummy); | |
679 | while ( cont ) | |
680 | { | |
9a83f860 | 681 | wxPrintf(wxT("\t%s = %s\n"), |
ee6e1b1d | 682 | name.c_str(), |
9a83f860 | 683 | fileconf.Read(name.c_str(), wxT("ERROR")).c_str()); |
ee6e1b1d VZ |
684 | |
685 | cont = fileconf.GetNextEntry(name, dummy); | |
686 | } | |
7e0777da | 687 | |
9a83f860 VZ |
688 | static const wxChar *testEntry = wxT("TestEntry"); |
689 | wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: ")); | |
690 | fileconf.Write(testEntry, wxT("A value")); | |
7e0777da | 691 | fileconf.DeleteEntry(testEntry); |
9a83f860 | 692 | wxPrintf(fileconf.HasEntry(testEntry) ? wxT("ERROR\n") : wxT("ok\n")); |
ee6e1b1d VZ |
693 | } |
694 | ||
695 | #endif // TEST_FILECONF | |
696 | ||
844f90fb VZ |
697 | // ---------------------------------------------------------------------------- |
698 | // wxFileName | |
699 | // ---------------------------------------------------------------------------- | |
700 | ||
701 | #ifdef TEST_FILENAME | |
702 | ||
e84010cf | 703 | #include "wx/filename.h" |
844f90fb | 704 | |
e9d2bb6f | 705 | #if 0 |
5bc1deeb | 706 | static void DumpFileName(const wxChar *desc, const wxFileName& fn) |
81f25632 | 707 | { |
5bc1deeb VZ |
708 | wxPuts(desc); |
709 | ||
81f25632 VZ |
710 | wxString full = fn.GetFullPath(); |
711 | ||
712 | wxString vol, path, name, ext; | |
713 | wxFileName::SplitPath(full, &vol, &path, &name, &ext); | |
714 | ||
9a83f860 | 715 | wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"), |
81f25632 | 716 | full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str()); |
a5b7374f VZ |
717 | |
718 | wxFileName::SplitPath(full, &path, &name, &ext); | |
9a83f860 | 719 | wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"), |
a5b7374f VZ |
720 | path.c_str(), name.c_str(), ext.c_str()); |
721 | ||
9a83f860 VZ |
722 | wxPrintf(wxT("path is also:\t'%s'\n"), fn.GetPath().c_str()); |
723 | wxPrintf(wxT("with volume: \t'%s'\n"), | |
a5b7374f | 724 | fn.GetPath(wxPATH_GET_VOLUME).c_str()); |
9a83f860 | 725 | wxPrintf(wxT("with separator:\t'%s'\n"), |
a5b7374f | 726 | fn.GetPath(wxPATH_GET_SEPARATOR).c_str()); |
9a83f860 | 727 | wxPrintf(wxT("with both: \t'%s'\n"), |
a5b7374f | 728 | fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str()); |
9cb47ea2 | 729 | |
9a83f860 | 730 | wxPuts(wxT("The directories in the path are:")); |
9cb47ea2 VZ |
731 | wxArrayString dirs = fn.GetDirs(); |
732 | size_t count = dirs.GetCount(); | |
733 | for ( size_t n = 0; n < count; n++ ) | |
734 | { | |
9a83f860 | 735 | wxPrintf(wxT("\t%u: %s\n"), n, dirs[n].c_str()); |
9cb47ea2 | 736 | } |
81f25632 | 737 | } |
e9d2bb6f | 738 | #endif |
81f25632 | 739 | |
ade35f11 VZ |
740 | static void TestFileNameTemp() |
741 | { | |
9a83f860 | 742 | wxPuts(wxT("*** testing wxFileName temp file creation ***")); |
ade35f11 | 743 | |
456ae26d | 744 | static const wxChar *tmpprefixes[] = |
ade35f11 | 745 | { |
9a83f860 VZ |
746 | wxT(""), |
747 | wxT("foo"), | |
748 | wxT(".."), | |
749 | wxT("../bar"), | |
a2fa5040 | 750 | #ifdef __UNIX__ |
9a83f860 VZ |
751 | wxT("/tmp/foo"), |
752 | wxT("/tmp/foo/bar"), // this one must be an error | |
a2fa5040 | 753 | #endif // __UNIX__ |
ade35f11 VZ |
754 | }; |
755 | ||
756 | for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ ) | |
757 | { | |
758 | wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]); | |
2db991f4 VZ |
759 | if ( path.empty() ) |
760 | { | |
761 | // "error" is not in upper case because it may be ok | |
9a83f860 | 762 | wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes[n]); |
2db991f4 VZ |
763 | } |
764 | else | |
ade35f11 | 765 | { |
9a83f860 | 766 | wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"), |
ade35f11 VZ |
767 | tmpprefixes[n], path.c_str()); |
768 | ||
769 | if ( !wxRemoveFile(path) ) | |
770 | { | |
9a83f860 | 771 | wxLogWarning(wxT("Failed to remove temp file '%s'"), |
456ae26d | 772 | path.c_str()); |
ade35f11 VZ |
773 | } |
774 | } | |
775 | } | |
776 | } | |
777 | ||
0aa29b6b VZ |
778 | static void TestFileNameDirManip() |
779 | { | |
780 | // TODO: test AppendDir(), RemoveDir(), ... | |
781 | } | |
782 | ||
844f90fb VZ |
783 | static void TestFileNameComparison() |
784 | { | |
785 | // TODO! | |
786 | } | |
787 | ||
788 | static void TestFileNameOperations() | |
789 | { | |
790 | // TODO! | |
791 | } | |
792 | ||
793 | static void TestFileNameCwd() | |
794 | { | |
795 | // TODO! | |
796 | } | |
797 | ||
798 | #endif // TEST_FILENAME | |
799 | ||
d56e2b97 VZ |
800 | // ---------------------------------------------------------------------------- |
801 | // wxFileName time functions | |
802 | // ---------------------------------------------------------------------------- | |
803 | ||
804 | #ifdef TEST_FILETIME | |
805 | ||
b20edf8b WS |
806 | #include "wx/filename.h" |
807 | #include "wx/datetime.h" | |
d56e2b97 VZ |
808 | |
809 | static void TestFileGetTimes() | |
810 | { | |
9a83f860 | 811 | wxFileName fn(wxT("testdata.fc")); |
d56e2b97 | 812 | |
6dbb903b VZ |
813 | wxDateTime dtAccess, dtMod, dtCreate; |
814 | if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) ) | |
d56e2b97 | 815 | { |
9a83f860 | 816 | wxPrintf(wxT("ERROR: GetTimes() failed.\n")); |
d56e2b97 VZ |
817 | } |
818 | else | |
819 | { | |
9a83f860 | 820 | static const wxChar *fmt = wxT("%Y-%b-%d %H:%M:%S"); |
d56e2b97 | 821 | |
9a83f860 VZ |
822 | wxPrintf(wxT("File times for '%s':\n"), fn.GetFullPath().c_str()); |
823 | wxPrintf(wxT("Creation: \t%s\n"), dtCreate.Format(fmt).c_str()); | |
824 | wxPrintf(wxT("Last read: \t%s\n"), dtAccess.Format(fmt).c_str()); | |
825 | wxPrintf(wxT("Last write: \t%s\n"), dtMod.Format(fmt).c_str()); | |
d56e2b97 VZ |
826 | } |
827 | } | |
828 | ||
e9d2bb6f | 829 | #if 0 |
d56e2b97 VZ |
830 | static void TestFileSetTimes() |
831 | { | |
9a83f860 | 832 | wxFileName fn(wxT("testdata.fc")); |
d56e2b97 | 833 | |
d56e2b97 VZ |
834 | if ( !fn.Touch() ) |
835 | { | |
9a83f860 | 836 | wxPrintf(wxT("ERROR: Touch() failed.\n")); |
d56e2b97 VZ |
837 | } |
838 | } | |
e9d2bb6f | 839 | #endif |
d56e2b97 VZ |
840 | |
841 | #endif // TEST_FILETIME | |
842 | ||
ec37df57 VZ |
843 | // ---------------------------------------------------------------------------- |
844 | // wxLocale | |
845 | // ---------------------------------------------------------------------------- | |
846 | ||
847 | #ifdef TEST_LOCALE | |
848 | ||
849 | #include "wx/intl.h" | |
850 | #include "wx/utils.h" // for wxSetEnv | |
851 | ||
3e231024 FM |
852 | static wxLocale gs_localeDefault; |
853 | // NOTE: don't init it here as it needs a wxAppTraits object | |
854 | // and thus must be init-ed after creation of the wxInitializer | |
855 | // class in the main() | |
ec37df57 VZ |
856 | |
857 | // find the name of the language from its value | |
456ae26d VZ |
858 | static const wxChar *GetLangName(int lang) |
859 | { | |
860 | static const wxChar *languageNames[] = | |
861 | { | |
9a83f860 VZ |
862 | wxT("DEFAULT"), |
863 | wxT("UNKNOWN"), | |
864 | wxT("ABKHAZIAN"), | |
865 | wxT("AFAR"), | |
866 | wxT("AFRIKAANS"), | |
867 | wxT("ALBANIAN"), | |
868 | wxT("AMHARIC"), | |
869 | wxT("ARABIC"), | |
870 | wxT("ARABIC_ALGERIA"), | |
871 | wxT("ARABIC_BAHRAIN"), | |
872 | wxT("ARABIC_EGYPT"), | |
873 | wxT("ARABIC_IRAQ"), | |
874 | wxT("ARABIC_JORDAN"), | |
875 | wxT("ARABIC_KUWAIT"), | |
876 | wxT("ARABIC_LEBANON"), | |
877 | wxT("ARABIC_LIBYA"), | |
878 | wxT("ARABIC_MOROCCO"), | |
879 | wxT("ARABIC_OMAN"), | |
880 | wxT("ARABIC_QATAR"), | |
881 | wxT("ARABIC_SAUDI_ARABIA"), | |
882 | wxT("ARABIC_SUDAN"), | |
883 | wxT("ARABIC_SYRIA"), | |
884 | wxT("ARABIC_TUNISIA"), | |
885 | wxT("ARABIC_UAE"), | |
886 | wxT("ARABIC_YEMEN"), | |
887 | wxT("ARMENIAN"), | |
888 | wxT("ASSAMESE"), | |
889 | wxT("AYMARA"), | |
890 | wxT("AZERI"), | |
891 | wxT("AZERI_CYRILLIC"), | |
892 | wxT("AZERI_LATIN"), | |
893 | wxT("BASHKIR"), | |
894 | wxT("BASQUE"), | |
895 | wxT("BELARUSIAN"), | |
896 | wxT("BENGALI"), | |
897 | wxT("BHUTANI"), | |
898 | wxT("BIHARI"), | |
899 | wxT("BISLAMA"), | |
900 | wxT("BRETON"), | |
901 | wxT("BULGARIAN"), | |
902 | wxT("BURMESE"), | |
903 | wxT("CAMBODIAN"), | |
904 | wxT("CATALAN"), | |
905 | wxT("CHINESE"), | |
906 | wxT("CHINESE_SIMPLIFIED"), | |
907 | wxT("CHINESE_TRADITIONAL"), | |
908 | wxT("CHINESE_HONGKONG"), | |
909 | wxT("CHINESE_MACAU"), | |
910 | wxT("CHINESE_SINGAPORE"), | |
911 | wxT("CHINESE_TAIWAN"), | |
912 | wxT("CORSICAN"), | |
913 | wxT("CROATIAN"), | |
914 | wxT("CZECH"), | |
915 | wxT("DANISH"), | |
916 | wxT("DUTCH"), | |
917 | wxT("DUTCH_BELGIAN"), | |
918 | wxT("ENGLISH"), | |
919 | wxT("ENGLISH_UK"), | |
920 | wxT("ENGLISH_US"), | |
921 | wxT("ENGLISH_AUSTRALIA"), | |
922 | wxT("ENGLISH_BELIZE"), | |
923 | wxT("ENGLISH_BOTSWANA"), | |
924 | wxT("ENGLISH_CANADA"), | |
925 | wxT("ENGLISH_CARIBBEAN"), | |
926 | wxT("ENGLISH_DENMARK"), | |
927 | wxT("ENGLISH_EIRE"), | |
928 | wxT("ENGLISH_JAMAICA"), | |
929 | wxT("ENGLISH_NEW_ZEALAND"), | |
930 | wxT("ENGLISH_PHILIPPINES"), | |
931 | wxT("ENGLISH_SOUTH_AFRICA"), | |
932 | wxT("ENGLISH_TRINIDAD"), | |
933 | wxT("ENGLISH_ZIMBABWE"), | |
934 | wxT("ESPERANTO"), | |
935 | wxT("ESTONIAN"), | |
936 | wxT("FAEROESE"), | |
937 | wxT("FARSI"), | |
938 | wxT("FIJI"), | |
939 | wxT("FINNISH"), | |
940 | wxT("FRENCH"), | |
941 | wxT("FRENCH_BELGIAN"), | |
942 | wxT("FRENCH_CANADIAN"), | |
943 | wxT("FRENCH_LUXEMBOURG"), | |
944 | wxT("FRENCH_MONACO"), | |
945 | wxT("FRENCH_SWISS"), | |
946 | wxT("FRISIAN"), | |
947 | wxT("GALICIAN"), | |
948 | wxT("GEORGIAN"), | |
949 | wxT("GERMAN"), | |
950 | wxT("GERMAN_AUSTRIAN"), | |
951 | wxT("GERMAN_BELGIUM"), | |
952 | wxT("GERMAN_LIECHTENSTEIN"), | |
953 | wxT("GERMAN_LUXEMBOURG"), | |
954 | wxT("GERMAN_SWISS"), | |
955 | wxT("GREEK"), | |
956 | wxT("GREENLANDIC"), | |
957 | wxT("GUARANI"), | |
958 | wxT("GUJARATI"), | |
959 | wxT("HAUSA"), | |
960 | wxT("HEBREW"), | |
961 | wxT("HINDI"), | |
962 | wxT("HUNGARIAN"), | |
963 | wxT("ICELANDIC"), | |
964 | wxT("INDONESIAN"), | |
965 | wxT("INTERLINGUA"), | |
966 | wxT("INTERLINGUE"), | |
967 | wxT("INUKTITUT"), | |
968 | wxT("INUPIAK"), | |
969 | wxT("IRISH"), | |
970 | wxT("ITALIAN"), | |
971 | wxT("ITALIAN_SWISS"), | |
972 | wxT("JAPANESE"), | |
973 | wxT("JAVANESE"), | |
974 | wxT("KANNADA"), | |
975 | wxT("KASHMIRI"), | |
976 | wxT("KASHMIRI_INDIA"), | |
977 | wxT("KAZAKH"), | |
978 | wxT("KERNEWEK"), | |
979 | wxT("KINYARWANDA"), | |
980 | wxT("KIRGHIZ"), | |
981 | wxT("KIRUNDI"), | |
982 | wxT("KONKANI"), | |
983 | wxT("KOREAN"), | |
984 | wxT("KURDISH"), | |
985 | wxT("LAOTHIAN"), | |
986 | wxT("LATIN"), | |
987 | wxT("LATVIAN"), | |
988 | wxT("LINGALA"), | |
989 | wxT("LITHUANIAN"), | |
990 | wxT("MACEDONIAN"), | |
991 | wxT("MALAGASY"), | |
992 | wxT("MALAY"), | |
993 | wxT("MALAYALAM"), | |
994 | wxT("MALAY_BRUNEI_DARUSSALAM"), | |
995 | wxT("MALAY_MALAYSIA"), | |
996 | wxT("MALTESE"), | |
997 | wxT("MANIPURI"), | |
998 | wxT("MAORI"), | |
999 | wxT("MARATHI"), | |
1000 | wxT("MOLDAVIAN"), | |
1001 | wxT("MONGOLIAN"), | |
1002 | wxT("NAURU"), | |
1003 | wxT("NEPALI"), | |
1004 | wxT("NEPALI_INDIA"), | |
1005 | wxT("NORWEGIAN_BOKMAL"), | |
1006 | wxT("NORWEGIAN_NYNORSK"), | |
1007 | wxT("OCCITAN"), | |
1008 | wxT("ORIYA"), | |
1009 | wxT("OROMO"), | |
1010 | wxT("PASHTO"), | |
1011 | wxT("POLISH"), | |
1012 | wxT("PORTUGUESE"), | |
1013 | wxT("PORTUGUESE_BRAZILIAN"), | |
1014 | wxT("PUNJABI"), | |
1015 | wxT("QUECHUA"), | |
1016 | wxT("RHAETO_ROMANCE"), | |
1017 | wxT("ROMANIAN"), | |
1018 | wxT("RUSSIAN"), | |
1019 | wxT("RUSSIAN_UKRAINE"), | |
1020 | wxT("SAMOAN"), | |
1021 | wxT("SANGHO"), | |
1022 | wxT("SANSKRIT"), | |
1023 | wxT("SCOTS_GAELIC"), | |
1024 | wxT("SERBIAN"), | |
1025 | wxT("SERBIAN_CYRILLIC"), | |
1026 | wxT("SERBIAN_LATIN"), | |
1027 | wxT("SERBO_CROATIAN"), | |
1028 | wxT("SESOTHO"), | |
1029 | wxT("SETSWANA"), | |
1030 | wxT("SHONA"), | |
1031 | wxT("SINDHI"), | |
1032 | wxT("SINHALESE"), | |
1033 | wxT("SISWATI"), | |
1034 | wxT("SLOVAK"), | |
1035 | wxT("SLOVENIAN"), | |
1036 | wxT("SOMALI"), | |
1037 | wxT("SPANISH"), | |
1038 | wxT("SPANISH_ARGENTINA"), | |
1039 | wxT("SPANISH_BOLIVIA"), | |
1040 | wxT("SPANISH_CHILE"), | |
1041 | wxT("SPANISH_COLOMBIA"), | |
1042 | wxT("SPANISH_COSTA_RICA"), | |
1043 | wxT("SPANISH_DOMINICAN_REPUBLIC"), | |
1044 | wxT("SPANISH_ECUADOR"), | |
1045 | wxT("SPANISH_EL_SALVADOR"), | |
1046 | wxT("SPANISH_GUATEMALA"), | |
1047 | wxT("SPANISH_HONDURAS"), | |
1048 | wxT("SPANISH_MEXICAN"), | |
1049 | wxT("SPANISH_MODERN"), | |
1050 | wxT("SPANISH_NICARAGUA"), | |
1051 | wxT("SPANISH_PANAMA"), | |
1052 | wxT("SPANISH_PARAGUAY"), | |
1053 | wxT("SPANISH_PERU"), | |
1054 | wxT("SPANISH_PUERTO_RICO"), | |
1055 | wxT("SPANISH_URUGUAY"), | |
1056 | wxT("SPANISH_US"), | |
1057 | wxT("SPANISH_VENEZUELA"), | |
1058 | wxT("SUNDANESE"), | |
1059 | wxT("SWAHILI"), | |
1060 | wxT("SWEDISH"), | |
1061 | wxT("SWEDISH_FINLAND"), | |
1062 | wxT("TAGALOG"), | |
1063 | wxT("TAJIK"), | |
1064 | wxT("TAMIL"), | |
1065 | wxT("TATAR"), | |
1066 | wxT("TELUGU"), | |
1067 | wxT("THAI"), | |
1068 | wxT("TIBETAN"), | |
1069 | wxT("TIGRINYA"), | |
1070 | wxT("TONGA"), | |
1071 | wxT("TSONGA"), | |
1072 | wxT("TURKISH"), | |
1073 | wxT("TURKMEN"), | |
1074 | wxT("TWI"), | |
1075 | wxT("UIGHUR"), | |
1076 | wxT("UKRAINIAN"), | |
1077 | wxT("URDU"), | |
1078 | wxT("URDU_INDIA"), | |
1079 | wxT("URDU_PAKISTAN"), | |
1080 | wxT("UZBEK"), | |
1081 | wxT("UZBEK_CYRILLIC"), | |
1082 | wxT("UZBEK_LATIN"), | |
1083 | wxT("VIETNAMESE"), | |
1084 | wxT("VOLAPUK"), | |
1085 | wxT("WELSH"), | |
1086 | wxT("WOLOF"), | |
1087 | wxT("XHOSA"), | |
1088 | wxT("YIDDISH"), | |
1089 | wxT("YORUBA"), | |
1090 | wxT("ZHUANG"), | |
1091 | wxT("ZULU"), | |
ec37df57 VZ |
1092 | }; |
1093 | ||
1094 | if ( (size_t)lang < WXSIZEOF(languageNames) ) | |
1095 | return languageNames[lang]; | |
1096 | else | |
9a83f860 | 1097 | return wxT("INVALID"); |
ec37df57 VZ |
1098 | } |
1099 | ||
1100 | static void TestDefaultLang() | |
1101 | { | |
9a83f860 | 1102 | wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***")); |
ec37df57 | 1103 | |
3e231024 FM |
1104 | gs_localeDefault.Init(wxLANGUAGE_ENGLISH); |
1105 | ||
ec37df57 VZ |
1106 | static const wxChar *langStrings[] = |
1107 | { | |
1108 | NULL, // system default | |
9a83f860 VZ |
1109 | wxT("C"), |
1110 | wxT("fr"), | |
1111 | wxT("fr_FR"), | |
1112 | wxT("en"), | |
1113 | wxT("en_GB"), | |
1114 | wxT("en_US"), | |
1115 | wxT("de_DE.iso88591"), | |
1116 | wxT("german"), | |
1117 | wxT("?"), // invalid lang spec | |
1118 | wxT("klingonese"), // I bet on some systems it does exist... | |
ec37df57 VZ |
1119 | }; |
1120 | ||
9a83f860 | 1121 | wxPrintf(wxT("The default system encoding is %s (%d)\n"), |
dccce9ea VZ |
1122 | wxLocale::GetSystemEncodingName().c_str(), |
1123 | wxLocale::GetSystemEncoding()); | |
1124 | ||
ec37df57 VZ |
1125 | for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ ) |
1126 | { | |
456ae26d | 1127 | const wxChar *langStr = langStrings[n]; |
ec37df57 | 1128 | if ( langStr ) |
dccce9ea VZ |
1129 | { |
1130 | // FIXME: this doesn't do anything at all under Windows, we need | |
1131 | // to create a new wxLocale! | |
9a83f860 | 1132 | wxSetEnv(wxT("LC_ALL"), langStr); |
dccce9ea | 1133 | } |
ec37df57 VZ |
1134 | |
1135 | int lang = gs_localeDefault.GetSystemLanguage(); | |
9a83f860 VZ |
1136 | wxPrintf(wxT("Locale for '%s' is %s.\n"), |
1137 | langStr ? langStr : wxT("system default"), GetLangName(lang)); | |
ec37df57 VZ |
1138 | } |
1139 | } | |
1140 | ||
1141 | #endif // TEST_LOCALE | |
1142 | ||
696e1ea0 VZ |
1143 | // ---------------------------------------------------------------------------- |
1144 | // MIME types | |
1145 | // ---------------------------------------------------------------------------- | |
1146 | ||
1147 | #ifdef TEST_MIME | |
1148 | ||
e84010cf | 1149 | #include "wx/mimetype.h" |
696e1ea0 VZ |
1150 | |
1151 | static void TestMimeEnum() | |
1152 | { | |
9a83f860 | 1153 | wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n")); |
a6c65e88 | 1154 | |
696e1ea0 VZ |
1155 | wxArrayString mimetypes; |
1156 | ||
39189b9d | 1157 | size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes); |
696e1ea0 | 1158 | |
9a83f860 | 1159 | wxPrintf(wxT("*** All %u known filetypes: ***\n"), count); |
696e1ea0 VZ |
1160 | |
1161 | wxArrayString exts; | |
1162 | wxString desc; | |
1163 | ||
1164 | for ( size_t n = 0; n < count; n++ ) | |
1165 | { | |
39189b9d VZ |
1166 | wxFileType *filetype = |
1167 | wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]); | |
696e1ea0 | 1168 | if ( !filetype ) |
c61f4f6d | 1169 | { |
9a83f860 | 1170 | wxPrintf(wxT("nothing known about the filetype '%s'!\n"), |
97e0ceea | 1171 | mimetypes[n].c_str()); |
696e1ea0 | 1172 | continue; |
c61f4f6d VZ |
1173 | } |
1174 | ||
696e1ea0 VZ |
1175 | filetype->GetDescription(&desc); |
1176 | filetype->GetExtensions(exts); | |
1177 | ||
299fcbfe VZ |
1178 | filetype->GetIcon(NULL); |
1179 | ||
696e1ea0 VZ |
1180 | wxString extsAll; |
1181 | for ( size_t e = 0; e < exts.GetCount(); e++ ) | |
1182 | { | |
1183 | if ( e > 0 ) | |
9a83f860 | 1184 | extsAll << wxT(", "); |
696e1ea0 VZ |
1185 | extsAll += exts[e]; |
1186 | } | |
1187 | ||
9a83f860 | 1188 | wxPrintf(wxT("\t%s: %s (%s)\n"), |
54acce90 | 1189 | mimetypes[n].c_str(), desc.c_str(), extsAll.c_str()); |
696e1ea0 | 1190 | } |
39189b9d | 1191 | |
e9d2bb6f | 1192 | wxPuts(wxEmptyString); |
696e1ea0 VZ |
1193 | } |
1194 | ||
f6bcfd97 BP |
1195 | static void TestMimeFilename() |
1196 | { | |
9a83f860 | 1197 | wxPuts(wxT("*** Testing MIME type from filename query ***\n")); |
f6bcfd97 BP |
1198 | |
1199 | static const wxChar *filenames[] = | |
1200 | { | |
9a83f860 VZ |
1201 | wxT("readme.txt"), |
1202 | wxT("document.pdf"), | |
1203 | wxT("image.gif"), | |
1204 | wxT("picture.jpeg"), | |
f6bcfd97 BP |
1205 | }; |
1206 | ||
1207 | for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) | |
1208 | { | |
1209 | const wxString fname = filenames[n]; | |
9a83f860 | 1210 | wxString ext = fname.AfterLast(wxT('.')); |
39189b9d | 1211 | wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); |
f6bcfd97 BP |
1212 | if ( !ft ) |
1213 | { | |
9a83f860 | 1214 | wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext.c_str()); |
f6bcfd97 BP |
1215 | } |
1216 | else | |
1217 | { | |
1218 | wxString desc; | |
1219 | if ( !ft->GetDescription(&desc) ) | |
9a83f860 | 1220 | desc = wxT("<no description>"); |
f6bcfd97 BP |
1221 | |
1222 | wxString cmd; | |
1223 | if ( !ft->GetOpenCommand(&cmd, | |
e9d2bb6f | 1224 | wxFileType::MessageParameters(fname, wxEmptyString)) ) |
9a83f860 | 1225 | cmd = wxT("<no command available>"); |
7aeebdcd | 1226 | else |
9a83f860 | 1227 | cmd = wxString(wxT('"')) + cmd + wxT('"'); |
f6bcfd97 | 1228 | |
9a83f860 | 1229 | wxPrintf(wxT("To open %s (%s) do %s.\n"), |
f6bcfd97 BP |
1230 | fname.c_str(), desc.c_str(), cmd.c_str()); |
1231 | ||
1232 | delete ft; | |
1233 | } | |
1234 | } | |
39189b9d | 1235 | |
e9d2bb6f | 1236 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
1237 | } |
1238 | ||
c19c2f6e VZ |
1239 | // these tests were broken by wxMimeTypesManager changes, temporarily disabling |
1240 | #if 0 | |
1241 | ||
1242 | static void TestMimeOverride() | |
1243 | { | |
9a83f860 | 1244 | wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n")); |
c19c2f6e | 1245 | |
9a83f860 VZ |
1246 | static const wxChar *mailcap = wxT("/tmp/mailcap"); |
1247 | static const wxChar *mimetypes = wxT("/tmp/mime.types"); | |
c19c2f6e VZ |
1248 | |
1249 | if ( wxFile::Exists(mailcap) ) | |
9a83f860 | 1250 | wxPrintf(wxT("Loading mailcap from '%s': %s\n"), |
c19c2f6e | 1251 | mailcap, |
9a83f860 | 1252 | wxTheMimeTypesManager->ReadMailcap(mailcap) ? wxT("ok") : wxT("ERROR")); |
c19c2f6e | 1253 | else |
9a83f860 | 1254 | wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), |
c19c2f6e VZ |
1255 | mailcap); |
1256 | ||
1257 | if ( wxFile::Exists(mimetypes) ) | |
9a83f860 | 1258 | wxPrintf(wxT("Loading mime.types from '%s': %s\n"), |
c19c2f6e | 1259 | mimetypes, |
9a83f860 | 1260 | wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? wxT("ok") : wxT("ERROR")); |
c19c2f6e | 1261 | else |
9a83f860 | 1262 | wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), |
c19c2f6e VZ |
1263 | mimetypes); |
1264 | ||
1265 | wxPuts(wxEmptyString); | |
1266 | } | |
1267 | ||
c7ce8392 VZ |
1268 | static void TestMimeAssociate() |
1269 | { | |
9a83f860 | 1270 | wxPuts(wxT("*** Testing creation of filetype association ***\n")); |
c7ce8392 | 1271 | |
a6c65e88 | 1272 | wxFileTypeInfo ftInfo( |
9a83f860 VZ |
1273 | wxT("application/x-xyz"), |
1274 | wxT("xyzview '%s'"), // open cmd | |
1275 | wxT(""), // print cmd | |
1276 | wxT("XYZ File"), // description | |
1277 | wxT(".xyz"), // extensions | |
b61af837 | 1278 | wxNullPtr // end of extensions |
a6c65e88 | 1279 | ); |
9a83f860 | 1280 | ftInfo.SetShortDesc(wxT("XYZFile")); // used under Win32 only |
a6c65e88 | 1281 | |
39189b9d | 1282 | wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo); |
c7ce8392 VZ |
1283 | if ( !ft ) |
1284 | { | |
9a83f860 | 1285 | wxPuts(wxT("ERROR: failed to create association!")); |
c7ce8392 VZ |
1286 | } |
1287 | else | |
1288 | { | |
a6c65e88 | 1289 | // TODO: read it back |
c7ce8392 VZ |
1290 | delete ft; |
1291 | } | |
39189b9d | 1292 | |
e9d2bb6f | 1293 | wxPuts(wxEmptyString); |
c7ce8392 VZ |
1294 | } |
1295 | ||
c19c2f6e VZ |
1296 | #endif // 0 |
1297 | ||
696e1ea0 VZ |
1298 | #endif // TEST_MIME |
1299 | ||
af266e5b VZ |
1300 | // ---------------------------------------------------------------------------- |
1301 | // module dependencies feature | |
1302 | // ---------------------------------------------------------------------------- | |
1303 | ||
1304 | #ifdef TEST_MODULE | |
1305 | ||
1306 | #include "wx/module.h" | |
1307 | ||
1308 | class wxTestModule : public wxModule | |
1309 | { | |
1310 | protected: | |
9a83f860 VZ |
1311 | virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; } |
1312 | virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); } | |
af266e5b VZ |
1313 | }; |
1314 | ||
1315 | class wxTestModuleA : public wxTestModule | |
1316 | { | |
1317 | public: | |
1318 | wxTestModuleA(); | |
1319 | private: | |
1320 | DECLARE_DYNAMIC_CLASS(wxTestModuleA) | |
1321 | }; | |
1322 | ||
1323 | class wxTestModuleB : public wxTestModule | |
1324 | { | |
1325 | public: | |
1326 | wxTestModuleB(); | |
1327 | private: | |
1328 | DECLARE_DYNAMIC_CLASS(wxTestModuleB) | |
1329 | }; | |
1330 | ||
1331 | class wxTestModuleC : public wxTestModule | |
1332 | { | |
1333 | public: | |
1334 | wxTestModuleC(); | |
1335 | private: | |
1336 | DECLARE_DYNAMIC_CLASS(wxTestModuleC) | |
1337 | }; | |
1338 | ||
1339 | class wxTestModuleD : public wxTestModule | |
1340 | { | |
1341 | public: | |
1342 | wxTestModuleD(); | |
1343 | private: | |
1344 | DECLARE_DYNAMIC_CLASS(wxTestModuleD) | |
1345 | }; | |
1346 | ||
1347 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC, wxModule) | |
1348 | wxTestModuleC::wxTestModuleC() | |
1349 | { | |
1350 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1351 | } | |
1352 | ||
1353 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA, wxModule) | |
1354 | wxTestModuleA::wxTestModuleA() | |
1355 | { | |
1356 | AddDependency(CLASSINFO(wxTestModuleB)); | |
1357 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1358 | } | |
1359 | ||
1360 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD, wxModule) | |
1361 | wxTestModuleD::wxTestModuleD() | |
1362 | { | |
1363 | } | |
1364 | ||
1365 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB, wxModule) | |
1366 | wxTestModuleB::wxTestModuleB() | |
1367 | { | |
1368 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1369 | AddDependency(CLASSINFO(wxTestModuleC)); | |
1370 | } | |
1371 | ||
1372 | #endif // TEST_MODULE | |
1373 | ||
89e60357 VZ |
1374 | // ---------------------------------------------------------------------------- |
1375 | // misc information functions | |
1376 | // ---------------------------------------------------------------------------- | |
1377 | ||
1378 | #ifdef TEST_INFO_FUNCTIONS | |
1379 | ||
e84010cf | 1380 | #include "wx/utils.h" |
89e60357 | 1381 | |
0219fd2f | 1382 | #if TEST_INTERACTIVE |
3a994742 VZ |
1383 | static void TestDiskInfo() |
1384 | { | |
9a83f860 | 1385 | wxPuts(wxT("*** Testing wxGetDiskSpace() ***")); |
3a994742 VZ |
1386 | |
1387 | for ( ;; ) | |
1388 | { | |
456ae26d | 1389 | wxChar pathname[128]; |
9a83f860 | 1390 | wxPrintf(wxT("\nEnter a directory name: ")); |
456ae26d | 1391 | if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) ) |
3a994742 VZ |
1392 | break; |
1393 | ||
1394 | // kill the last '\n' | |
456ae26d | 1395 | pathname[wxStrlen(pathname) - 1] = 0; |
3a994742 VZ |
1396 | |
1397 | wxLongLong total, free; | |
1398 | if ( !wxGetDiskSpace(pathname, &total, &free) ) | |
1399 | { | |
9a83f860 | 1400 | wxPuts(wxT("ERROR: wxGetDiskSpace failed.")); |
3a994742 VZ |
1401 | } |
1402 | else | |
1403 | { | |
9a83f860 | 1404 | wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"), |
eadd7bd2 VZ |
1405 | (total / 1024).ToString().c_str(), |
1406 | (free / 1024).ToString().c_str(), | |
3a994742 VZ |
1407 | pathname); |
1408 | } | |
1409 | } | |
1410 | } | |
0219fd2f | 1411 | #endif // TEST_INTERACTIVE |
3a994742 | 1412 | |
89e60357 VZ |
1413 | static void TestOsInfo() |
1414 | { | |
9a83f860 | 1415 | wxPuts(wxT("*** Testing OS info functions ***\n")); |
89e60357 VZ |
1416 | |
1417 | int major, minor; | |
1418 | wxGetOsVersion(&major, &minor); | |
9a83f860 | 1419 | wxPrintf(wxT("Running under: %s, version %d.%d\n"), |
89e60357 VZ |
1420 | wxGetOsDescription().c_str(), major, minor); |
1421 | ||
9a83f860 | 1422 | wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong()); |
89e60357 | 1423 | |
9a83f860 | 1424 | wxPrintf(wxT("Host name is %s (%s).\n"), |
89e60357 | 1425 | wxGetHostName().c_str(), wxGetFullHostName().c_str()); |
bd3277fe | 1426 | |
e9d2bb6f | 1427 | wxPuts(wxEmptyString); |
89e60357 VZ |
1428 | } |
1429 | ||
8bb6b2c0 VZ |
1430 | static void TestPlatformInfo() |
1431 | { | |
9a83f860 | 1432 | wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n")); |
8bb6b2c0 VZ |
1433 | |
1434 | // get this platform | |
1435 | wxPlatformInfo plat; | |
1436 | ||
9a83f860 VZ |
1437 | wxPrintf(wxT("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str()); |
1438 | wxPrintf(wxT("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str()); | |
1439 | wxPrintf(wxT("Port ID name is: %s\n"), plat.GetPortIdName().c_str()); | |
1440 | wxPrintf(wxT("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str()); | |
1441 | wxPrintf(wxT("Architecture is: %s\n"), plat.GetArchName().c_str()); | |
1442 | wxPrintf(wxT("Endianness is: %s\n"), plat.GetEndiannessName().c_str()); | |
8bb6b2c0 VZ |
1443 | |
1444 | wxPuts(wxEmptyString); | |
1445 | } | |
1446 | ||
89e60357 VZ |
1447 | static void TestUserInfo() |
1448 | { | |
9a83f860 | 1449 | wxPuts(wxT("*** Testing user info functions ***\n")); |
89e60357 | 1450 | |
9a83f860 VZ |
1451 | wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str()); |
1452 | wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str()); | |
1453 | wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); | |
1454 | wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str()); | |
bd3277fe | 1455 | |
e9d2bb6f | 1456 | wxPuts(wxEmptyString); |
89e60357 VZ |
1457 | } |
1458 | ||
1459 | #endif // TEST_INFO_FUNCTIONS | |
1460 | ||
39189b9d VZ |
1461 | // ---------------------------------------------------------------------------- |
1462 | // path list | |
1463 | // ---------------------------------------------------------------------------- | |
1464 | ||
1465 | #ifdef TEST_PATHLIST | |
1466 | ||
ee3ef281 | 1467 | #ifdef __UNIX__ |
9a83f860 | 1468 | #define CMD_IN_PATH wxT("ls") |
ee3ef281 | 1469 | #else |
9a83f860 | 1470 | #define CMD_IN_PATH wxT("command.com") |
ee3ef281 VZ |
1471 | #endif |
1472 | ||
39189b9d VZ |
1473 | static void TestPathList() |
1474 | { | |
9a83f860 | 1475 | wxPuts(wxT("*** Testing wxPathList ***\n")); |
39189b9d VZ |
1476 | |
1477 | wxPathList pathlist; | |
9a83f860 | 1478 | pathlist.AddEnvList(wxT("PATH")); |
ee3ef281 | 1479 | wxString path = pathlist.FindValidPath(CMD_IN_PATH); |
39189b9d VZ |
1480 | if ( path.empty() ) |
1481 | { | |
9a83f860 | 1482 | wxPrintf(wxT("ERROR: command not found in the path.\n")); |
39189b9d VZ |
1483 | } |
1484 | else | |
1485 | { | |
9a83f860 | 1486 | wxPrintf(wxT("Command found in the path as '%s'.\n"), path.c_str()); |
39189b9d VZ |
1487 | } |
1488 | } | |
1489 | ||
1490 | #endif // TEST_PATHLIST | |
1491 | ||
07a56e45 VZ |
1492 | // ---------------------------------------------------------------------------- |
1493 | // regular expressions | |
1494 | // ---------------------------------------------------------------------------- | |
1495 | ||
eb835127 | 1496 | #if defined TEST_REGEX && TEST_INTERACTIVE |
07a56e45 | 1497 | |
e84010cf | 1498 | #include "wx/regex.h" |
07a56e45 | 1499 | |
07a56e45 VZ |
1500 | static void TestRegExInteractive() |
1501 | { | |
9a83f860 | 1502 | wxPuts(wxT("*** Testing RE interactively ***")); |
07a56e45 VZ |
1503 | |
1504 | for ( ;; ) | |
1505 | { | |
456ae26d | 1506 | wxChar pattern[128]; |
9a83f860 | 1507 | wxPrintf(wxT("\nEnter a pattern: ")); |
456ae26d | 1508 | if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) ) |
07a56e45 VZ |
1509 | break; |
1510 | ||
1511 | // kill the last '\n' | |
456ae26d | 1512 | pattern[wxStrlen(pattern) - 1] = 0; |
07a56e45 VZ |
1513 | |
1514 | wxRegEx re; | |
1515 | if ( !re.Compile(pattern) ) | |
1516 | { | |
1517 | continue; | |
1518 | } | |
1519 | ||
456ae26d | 1520 | wxChar text[128]; |
07a56e45 VZ |
1521 | for ( ;; ) |
1522 | { | |
9a83f860 | 1523 | wxPrintf(wxT("Enter text to match: ")); |
456ae26d | 1524 | if ( !wxFgets(text, WXSIZEOF(text), stdin) ) |
07a56e45 VZ |
1525 | break; |
1526 | ||
1527 | // kill the last '\n' | |
456ae26d | 1528 | text[wxStrlen(text) - 1] = 0; |
07a56e45 VZ |
1529 | |
1530 | if ( !re.Matches(text) ) | |
1531 | { | |
9a83f860 | 1532 | wxPrintf(wxT("No match.\n")); |
07a56e45 VZ |
1533 | } |
1534 | else | |
1535 | { | |
9a83f860 | 1536 | wxPrintf(wxT("Pattern matches at '%s'\n"), re.GetMatch(text).c_str()); |
07a56e45 VZ |
1537 | |
1538 | size_t start, len; | |
1539 | for ( size_t n = 1; ; n++ ) | |
1540 | { | |
1541 | if ( !re.GetMatch(&start, &len, n) ) | |
1542 | { | |
1543 | break; | |
1544 | } | |
1545 | ||
9a83f860 | 1546 | wxPrintf(wxT("Subexpr %u matched '%s'\n"), |
456ae26d | 1547 | n, wxString(text + start, len).c_str()); |
07a56e45 VZ |
1548 | } |
1549 | } | |
1550 | } | |
1551 | } | |
1552 | } | |
1553 | ||
1554 | #endif // TEST_REGEX | |
1555 | ||
7aeebdcd VZ |
1556 | // ---------------------------------------------------------------------------- |
1557 | // printf() tests | |
1558 | // ---------------------------------------------------------------------------- | |
1559 | ||
1560 | /* | |
1561 | NB: this stuff was taken from the glibc test suite and modified to build | |
be5a51fb | 1562 | in wxWidgets: if I read the copyright below properly, this shouldn't |
7aeebdcd VZ |
1563 | be a problem |
1564 | */ | |
1565 | ||
1566 | #ifdef TEST_PRINTF | |
1567 | ||
1568 | #ifdef wxTEST_PRINTF | |
1569 | // use our functions from wxchar.cpp | |
1570 | #undef wxPrintf | |
1571 | #undef wxSprintf | |
1572 | ||
862bb5c7 | 1573 | // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats |
7aeebdcd VZ |
1574 | // in the tests below |
1575 | int wxPrintf( const wxChar *format, ... ); | |
1576 | int wxSprintf( wxChar *str, const wxChar *format, ... ); | |
1577 | #endif | |
1578 | ||
f1389d46 VZ |
1579 | #include "wx/longlong.h" |
1580 | ||
7aeebdcd VZ |
1581 | #include <float.h> |
1582 | ||
1583 | static void rfg1 (void); | |
1584 | static void rfg2 (void); | |
1585 | ||
1586 | ||
1587 | static void | |
1588 | fmtchk (const wxChar *fmt) | |
1589 | { | |
9a83f860 | 1590 | (void) wxPrintf(wxT("%s:\t`"), fmt); |
7aeebdcd | 1591 | (void) wxPrintf(fmt, 0x12); |
9a83f860 | 1592 | (void) wxPrintf(wxT("'\n")); |
7aeebdcd VZ |
1593 | } |
1594 | ||
1595 | static void | |
1596 | fmtst1chk (const wxChar *fmt) | |
1597 | { | |
9a83f860 | 1598 | (void) wxPrintf(wxT("%s:\t`"), fmt); |
7aeebdcd | 1599 | (void) wxPrintf(fmt, 4, 0x12); |
9a83f860 | 1600 | (void) wxPrintf(wxT("'\n")); |
7aeebdcd VZ |
1601 | } |
1602 | ||
1603 | static void | |
1604 | fmtst2chk (const wxChar *fmt) | |
1605 | { | |
9a83f860 | 1606 | (void) wxPrintf(wxT("%s:\t`"), fmt); |
7aeebdcd | 1607 | (void) wxPrintf(fmt, 4, 4, 0x12); |
9a83f860 | 1608 | (void) wxPrintf(wxT("'\n")); |
7aeebdcd VZ |
1609 | } |
1610 | ||
1611 | /* This page is covered by the following copyright: */ | |
1612 | ||
1613 | /* (C) Copyright C E Chew | |
1614 | * | |
1615 | * Feel free to copy, use and distribute this software provided: | |
1616 | * | |
1617 | * 1. you do not pretend that you wrote it | |
1618 | * 2. you leave this copyright notice intact. | |
1619 | */ | |
1620 | ||
1621 | /* | |
1622 | * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. | |
1623 | */ | |
1624 | ||
1625 | #define DEC -123 | |
1626 | #define INT 255 | |
1627 | #define UNS (~0) | |
1628 | ||
1629 | /* Formatted Output Test | |
1630 | * | |
1631 | * This exercises the output formatting code. | |
1632 | */ | |
1633 | ||
e9d2bb6f DS |
1634 | wxChar *PointerNull = NULL; |
1635 | ||
7aeebdcd VZ |
1636 | static void |
1637 | fp_test (void) | |
1638 | { | |
1639 | int i, j, k, l; | |
1640 | wxChar buf[7]; | |
1641 | wxChar *prefix = buf; | |
1642 | wxChar tp[20]; | |
1643 | ||
9a83f860 VZ |
1644 | wxPuts(wxT("\nFormatted output test")); |
1645 | wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n")); | |
1646 | wxStrcpy(prefix, wxT("%")); | |
7aeebdcd VZ |
1647 | for (i = 0; i < 2; i++) { |
1648 | for (j = 0; j < 2; j++) { | |
1649 | for (k = 0; k < 2; k++) { | |
1650 | for (l = 0; l < 2; l++) { | |
9a83f860 VZ |
1651 | wxStrcpy(prefix, wxT("%")); |
1652 | if (i == 0) wxStrcat(prefix, wxT("-")); | |
1653 | if (j == 0) wxStrcat(prefix, wxT("+")); | |
1654 | if (k == 0) wxStrcat(prefix, wxT("#")); | |
1655 | if (l == 0) wxStrcat(prefix, wxT("0")); | |
1656 | wxPrintf(wxT("%5s |"), prefix); | |
7aeebdcd | 1657 | wxStrcpy(tp, prefix); |
9a83f860 | 1658 | wxStrcat(tp, wxT("6d |")); |
7aeebdcd VZ |
1659 | wxPrintf(tp, DEC); |
1660 | wxStrcpy(tp, prefix); | |
9a83f860 | 1661 | wxStrcat(tp, wxT("6o |")); |
7aeebdcd VZ |
1662 | wxPrintf(tp, INT); |
1663 | wxStrcpy(tp, prefix); | |
9a83f860 | 1664 | wxStrcat(tp, wxT("6x |")); |
7aeebdcd VZ |
1665 | wxPrintf(tp, INT); |
1666 | wxStrcpy(tp, prefix); | |
9a83f860 | 1667 | wxStrcat(tp, wxT("6X |")); |
7aeebdcd VZ |
1668 | wxPrintf(tp, INT); |
1669 | wxStrcpy(tp, prefix); | |
9a83f860 | 1670 | wxStrcat(tp, wxT("6u |")); |
7aeebdcd | 1671 | wxPrintf(tp, UNS); |
9a83f860 | 1672 | wxPrintf(wxT("\n")); |
7aeebdcd VZ |
1673 | } |
1674 | } | |
1675 | } | |
1676 | } | |
9a83f860 VZ |
1677 | wxPrintf(wxT("%10s\n"), PointerNull); |
1678 | wxPrintf(wxT("%-10s\n"), PointerNull); | |
7aeebdcd VZ |
1679 | } |
1680 | ||
1681 | static void TestPrintf() | |
1682 | { | |
9a83f860 VZ |
1683 | static wxChar shortstr[] = wxT("Hi, Z."); |
1684 | static wxChar longstr[] = wxT("Good morning, Doctor Chandra. This is Hal. \ | |
f1389d46 | 1685 | I am ready for my first lesson today."); |
7aeebdcd | 1686 | int result = 0; |
e9d2bb6f | 1687 | wxString test_format; |
7aeebdcd | 1688 | |
9a83f860 VZ |
1689 | fmtchk(wxT("%.4x")); |
1690 | fmtchk(wxT("%04x")); | |
1691 | fmtchk(wxT("%4.4x")); | |
1692 | fmtchk(wxT("%04.4x")); | |
1693 | fmtchk(wxT("%4.3x")); | |
1694 | fmtchk(wxT("%04.3x")); | |
7aeebdcd | 1695 | |
9a83f860 VZ |
1696 | fmtst1chk(wxT("%.*x")); |
1697 | fmtst1chk(wxT("%0*x")); | |
1698 | fmtst2chk(wxT("%*.*x")); | |
1699 | fmtst2chk(wxT("%0*.*x")); | |
7aeebdcd | 1700 | |
9a83f860 | 1701 | wxString bad_format = wxT("bad format:\t\"%b\"\n"); |
e9d2bb6f | 1702 | wxPrintf(bad_format.c_str()); |
9a83f860 VZ |
1703 | wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL); |
1704 | ||
1705 | wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345); | |
1706 | wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345); | |
1707 | wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345); | |
1708 | wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L); | |
1709 | wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L); | |
1710 | wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L); | |
1711 | wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L); | |
1712 | test_format = wxT("left-adjusted ZLDN:\t\"%-010ld\"\n"); | |
e9d2bb6f | 1713 | wxPrintf(test_format.c_str(), -123456); |
9a83f860 VZ |
1714 | wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L); |
1715 | wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); | |
7aeebdcd | 1716 | |
9a83f860 | 1717 | test_format = wxT("zero-padded string:\t\"%010s\"\n"); |
e9d2bb6f | 1718 | wxPrintf(test_format.c_str(), shortstr); |
9a83f860 | 1719 | test_format = wxT("left-adjusted Z string:\t\"%-010s\"\n"); |
e9d2bb6f | 1720 | wxPrintf(test_format.c_str(), shortstr); |
9a83f860 VZ |
1721 | wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr); |
1722 | wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr); | |
1723 | wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull); | |
1724 | wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr); | |
1725 | ||
1726 | wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34); | |
1727 | wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234); | |
1728 | wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234); | |
1729 | wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20); | |
1730 | wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1); | |
1731 | wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34); | |
1732 | wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234); | |
1733 | wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234); | |
1734 | wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34); | |
1735 | wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234); | |
1736 | wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234); | |
1737 | wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20); | |
1738 | ||
1739 | wxPrintf (wxT(" %6.5f\n"), .099999999860301614); | |
1740 | wxPrintf (wxT(" %6.5f\n"), .1); | |
1741 | wxPrintf (wxT("x%5.4fx\n"), .5); | |
1742 | ||
1743 | wxPrintf (wxT("%#03x\n"), 1); | |
1744 | ||
1745 | //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0); | |
7aeebdcd VZ |
1746 | |
1747 | { | |
1748 | double d = FLT_MIN; | |
1749 | int niter = 17; | |
1750 | ||
1751 | while (niter-- != 0) | |
9a83f860 | 1752 | wxPrintf (wxT("%.17e\n"), d / 2); |
7aeebdcd VZ |
1753 | fflush (stdout); |
1754 | } | |
1755 | ||
e9d2bb6f DS |
1756 | #ifndef __WATCOMC__ |
1757 | // Open Watcom cause compiler error here | |
1758 | // Error! E173: col(24) floating-point constant too small to represent | |
9a83f860 | 1759 | wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324); |
e9d2bb6f | 1760 | #endif |
7aeebdcd | 1761 | |
9a83f860 | 1762 | #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n") |
7aeebdcd VZ |
1763 | wxPrintf (FORMAT, 0.0, 0.0, 0.0); |
1764 | wxPrintf (FORMAT, 1.0, 1.0, 1.0); | |
1765 | wxPrintf (FORMAT, -1.0, -1.0, -1.0); | |
1766 | wxPrintf (FORMAT, 100.0, 100.0, 100.0); | |
1767 | wxPrintf (FORMAT, 1000.0, 1000.0, 1000.0); | |
1768 | wxPrintf (FORMAT, 10000.0, 10000.0, 10000.0); | |
1769 | wxPrintf (FORMAT, 12345.0, 12345.0, 12345.0); | |
1770 | wxPrintf (FORMAT, 100000.0, 100000.0, 100000.0); | |
1771 | wxPrintf (FORMAT, 123456.0, 123456.0, 123456.0); | |
1772 | #undef FORMAT | |
1773 | ||
1774 | { | |
1775 | wxChar buf[20]; | |
9a83f860 | 1776 | int rc = wxSnprintf (buf, WXSIZEOF(buf), wxT("%30s"), wxT("foo")); |
7aeebdcd | 1777 | |
9a83f860 | 1778 | wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"), |
7aeebdcd VZ |
1779 | rc, WXSIZEOF(buf), buf); |
1780 | #if 0 | |
1781 | wxChar buf2[512]; | |
1782 | wxPrintf ("snprintf (\"%%.999999u\", 10)\n", | |
1783 | wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10)); | |
1784 | #endif | |
1785 | } | |
1786 | ||
1787 | fp_test (); | |
1788 | ||
9a83f860 VZ |
1789 | wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8); |
1790 | wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8); | |
1791 | wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8); | |
1792 | wxPrintf (wxT("%g should be 123.456\n"), 123.456); | |
1793 | wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0); | |
1794 | wxPrintf (wxT("%g should be 10\n"), 10.0); | |
1795 | wxPrintf (wxT("%g should be 0.02\n"), 0.02); | |
7aeebdcd VZ |
1796 | |
1797 | { | |
1798 | double x=1.0; | |
9a83f860 | 1799 | wxPrintf(wxT("%.17f\n"),(1.0/x/10.0+1.0)*x-x); |
7aeebdcd VZ |
1800 | } |
1801 | ||
1802 | { | |
1803 | wxChar buf[200]; | |
1804 | ||
9a83f860 | 1805 | wxSprintf(buf,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three")); |
7aeebdcd VZ |
1806 | |
1807 | result |= wxStrcmp (buf, | |
9a83f860 | 1808 | wxT("onetwo three ")); |
7aeebdcd | 1809 | |
9a83f860 | 1810 | wxPuts (result != 0 ? wxT("Test failed!") : wxT("Test ok.")); |
7aeebdcd VZ |
1811 | } |
1812 | ||
f1389d46 | 1813 | #ifdef wxLongLong_t |
7aeebdcd | 1814 | { |
f1389d46 | 1815 | wxChar buf[200]; |
7aeebdcd | 1816 | |
65154866 | 1817 | wxSprintf(buf, "%07" wxLongLongFmtSpec "o", wxLL(040000000000)); |
f2cb8a17 JS |
1818 | #if 0 |
1819 | // for some reason below line fails under Borland | |
9a83f860 | 1820 | wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf); |
f2cb8a17 | 1821 | #endif |
7aeebdcd | 1822 | |
9a83f860 | 1823 | if (wxStrcmp (buf, wxT("40000000000")) != 0) |
7aeebdcd | 1824 | { |
f1389d46 | 1825 | result = 1; |
9a83f860 | 1826 | wxPuts (wxT("\tFAILED")); |
7aeebdcd | 1827 | } |
e9d2bb6f DS |
1828 | wxUnusedVar(result); |
1829 | wxPuts (wxEmptyString); | |
7aeebdcd | 1830 | } |
f1389d46 | 1831 | #endif // wxLongLong_t |
7aeebdcd | 1832 | |
9a83f860 VZ |
1833 | wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX + 2, UCHAR_MAX + 2); |
1834 | wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX + 2, USHRT_MAX + 2); | |
7aeebdcd | 1835 | |
9a83f860 | 1836 | wxPuts (wxT("--- Should be no further output. ---")); |
7aeebdcd VZ |
1837 | rfg1 (); |
1838 | rfg2 (); | |
1839 | ||
1840 | #if 0 | |
1841 | { | |
1842 | wxChar bytes[7]; | |
1843 | wxChar buf[20]; | |
1844 | ||
1845 | memset (bytes, '\xff', sizeof bytes); | |
9a83f860 | 1846 | wxSprintf (buf, wxT("foo%hhn\n"), &bytes[3]); |
7aeebdcd VZ |
1847 | if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff' |
1848 | || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff') | |
1849 | { | |
9a83f860 | 1850 | wxPuts (wxT("%hhn overwrite more bytes")); |
7aeebdcd VZ |
1851 | result = 1; |
1852 | } | |
1853 | if (bytes[3] != 3) | |
1854 | { | |
9a83f860 | 1855 | wxPuts (wxT("%hhn wrote incorrect value")); |
7aeebdcd VZ |
1856 | result = 1; |
1857 | } | |
1858 | } | |
1859 | #endif | |
1860 | } | |
1861 | ||
1862 | static void | |
1863 | rfg1 (void) | |
1864 | { | |
1865 | wxChar buf[100]; | |
1866 | ||
9a83f860 VZ |
1867 | wxSprintf (buf, wxT("%5.s"), wxT("xyz")); |
1868 | if (wxStrcmp (buf, wxT(" ")) != 0) | |
1869 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" ")); | |
1870 | wxSprintf (buf, wxT("%5.f"), 33.3); | |
1871 | if (wxStrcmp (buf, wxT(" 33")) != 0) | |
1872 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 33")); | |
1873 | wxSprintf (buf, wxT("%8.e"), 33.3e7); | |
1874 | if (wxStrcmp (buf, wxT(" 3e+08")) != 0) | |
1875 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3e+08")); | |
1876 | wxSprintf (buf, wxT("%8.E"), 33.3e7); | |
1877 | if (wxStrcmp (buf, wxT(" 3E+08")) != 0) | |
1878 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3E+08")); | |
1879 | wxSprintf (buf, wxT("%.g"), 33.3); | |
1880 | if (wxStrcmp (buf, wxT("3e+01")) != 0) | |
1881 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3e+01")); | |
1882 | wxSprintf (buf, wxT("%.G"), 33.3); | |
1883 | if (wxStrcmp (buf, wxT("3E+01")) != 0) | |
1884 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3E+01")); | |
7aeebdcd VZ |
1885 | } |
1886 | ||
1887 | static void | |
1888 | rfg2 (void) | |
1889 | { | |
1890 | int prec; | |
1891 | wxChar buf[100]; | |
e9d2bb6f | 1892 | wxString test_format; |
7aeebdcd VZ |
1893 | |
1894 | prec = 0; | |
9a83f860 VZ |
1895 | wxSprintf (buf, wxT("%.*g"), prec, 3.3); |
1896 | if (wxStrcmp (buf, wxT("3")) != 0) | |
1897 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3")); | |
7aeebdcd | 1898 | prec = 0; |
9a83f860 VZ |
1899 | wxSprintf (buf, wxT("%.*G"), prec, 3.3); |
1900 | if (wxStrcmp (buf, wxT("3")) != 0) | |
1901 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3")); | |
7aeebdcd | 1902 | prec = 0; |
9a83f860 VZ |
1903 | wxSprintf (buf, wxT("%7.*G"), prec, 3.33); |
1904 | if (wxStrcmp (buf, wxT(" 3")) != 0) | |
1905 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3")); | |
7aeebdcd | 1906 | prec = 3; |
9a83f860 | 1907 | test_format = wxT("%04.*o"); |
e9d2bb6f | 1908 | wxSprintf (buf, test_format.c_str(), prec, 33); |
9a83f860 VZ |
1909 | if (wxStrcmp (buf, wxT(" 041")) != 0) |
1910 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 041")); | |
7aeebdcd | 1911 | prec = 7; |
9a83f860 | 1912 | test_format = wxT("%09.*u"); |
e9d2bb6f | 1913 | wxSprintf (buf, test_format.c_str(), prec, 33); |
9a83f860 VZ |
1914 | if (wxStrcmp (buf, wxT(" 0000033")) != 0) |
1915 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 0000033")); | |
7aeebdcd | 1916 | prec = 3; |
9a83f860 | 1917 | test_format = wxT("%04.*x"); |
e9d2bb6f | 1918 | wxSprintf (buf, test_format.c_str(), prec, 33); |
9a83f860 VZ |
1919 | if (wxStrcmp (buf, wxT(" 021")) != 0) |
1920 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 021")); | |
7aeebdcd | 1921 | prec = 3; |
9a83f860 | 1922 | test_format = wxT("%04.*X"); |
e9d2bb6f | 1923 | wxSprintf (buf, test_format.c_str(), prec, 33); |
9a83f860 VZ |
1924 | if (wxStrcmp (buf, wxT(" 021")) != 0) |
1925 | wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 021")); | |
7aeebdcd VZ |
1926 | } |
1927 | ||
1928 | #endif // TEST_PRINTF | |
1929 | ||
6dfec4b8 | 1930 | // ---------------------------------------------------------------------------- |
7ba4fbeb | 1931 | // registry and related stuff |
6dfec4b8 VZ |
1932 | // ---------------------------------------------------------------------------- |
1933 | ||
1934 | // this is for MSW only | |
1935 | #ifndef __WXMSW__ | |
7ba4fbeb | 1936 | #undef TEST_REGCONF |
6dfec4b8 VZ |
1937 | #undef TEST_REGISTRY |
1938 | #endif | |
1939 | ||
7ba4fbeb VZ |
1940 | #ifdef TEST_REGCONF |
1941 | ||
e84010cf GD |
1942 | #include "wx/confbase.h" |
1943 | #include "wx/msw/regconf.h" | |
7ba4fbeb | 1944 | |
e9d2bb6f | 1945 | #if 0 |
7ba4fbeb VZ |
1946 | static void TestRegConfWrite() |
1947 | { | |
9a83f860 VZ |
1948 | wxConfig *config = new wxConfig(wxT("myapp")); |
1949 | config->SetPath(wxT("/group1")); | |
1950 | config->Write(wxT("entry1"), wxT("foo")); | |
1951 | config->SetPath(wxT("/group2")); | |
1952 | config->Write(wxT("entry1"), wxT("bar")); | |
0aa29b6b | 1953 | } |
e9d2bb6f | 1954 | #endif |
0aa29b6b VZ |
1955 | |
1956 | static void TestRegConfRead() | |
1957 | { | |
9a83f860 | 1958 | wxRegConfig *config = new wxRegConfig(wxT("myapp")); |
0aa29b6b VZ |
1959 | |
1960 | wxString str; | |
1961 | long dummy; | |
9a83f860 VZ |
1962 | config->SetPath(wxT("/")); |
1963 | wxPuts(wxT("Enumerating / subgroups:")); | |
0aa29b6b VZ |
1964 | bool bCont = config->GetFirstGroup(str, dummy); |
1965 | while(bCont) | |
1966 | { | |
e9d2bb6f | 1967 | wxPuts(str); |
0aa29b6b VZ |
1968 | bCont = config->GetNextGroup(str, dummy); |
1969 | } | |
7ba4fbeb VZ |
1970 | } |
1971 | ||
1972 | #endif // TEST_REGCONF | |
1973 | ||
6dfec4b8 VZ |
1974 | #ifdef TEST_REGISTRY |
1975 | ||
e84010cf | 1976 | #include "wx/msw/registry.h" |
6dfec4b8 VZ |
1977 | |
1978 | // I chose this one because I liked its name, but it probably only exists under | |
1979 | // NT | |
1980 | static const wxChar *TESTKEY = | |
9a83f860 | 1981 | wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl"); |
6dfec4b8 VZ |
1982 | |
1983 | static void TestRegistryRead() | |
1984 | { | |
9a83f860 | 1985 | wxPuts(wxT("*** testing registry reading ***")); |
6dfec4b8 VZ |
1986 | |
1987 | wxRegKey key(TESTKEY); | |
9a83f860 | 1988 | wxPrintf(wxT("The test key name is '%s'.\n"), key.GetName().c_str()); |
6dfec4b8 VZ |
1989 | if ( !key.Open() ) |
1990 | { | |
9a83f860 | 1991 | wxPuts(wxT("ERROR: test key can't be opened, aborting test.")); |
6dfec4b8 VZ |
1992 | |
1993 | return; | |
1994 | } | |
1995 | ||
1996 | size_t nSubKeys, nValues; | |
1997 | if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) ) | |
1998 | { | |
9a83f860 | 1999 | wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys, nValues); |
6dfec4b8 VZ |
2000 | } |
2001 | ||
9a83f860 | 2002 | wxPrintf(wxT("Enumerating values:\n")); |
6dfec4b8 VZ |
2003 | |
2004 | long dummy; | |
2005 | wxString value; | |
2006 | bool cont = key.GetFirstValue(value, dummy); | |
2007 | while ( cont ) | |
2008 | { | |
9a83f860 | 2009 | wxPrintf(wxT("Value '%s': type "), value.c_str()); |
6dfec4b8 VZ |
2010 | switch ( key.GetValueType(value) ) |
2011 | { | |
9a83f860 VZ |
2012 | case wxRegKey::Type_None: wxPrintf(wxT("ERROR (none)")); break; |
2013 | case wxRegKey::Type_String: wxPrintf(wxT("SZ")); break; | |
2014 | case wxRegKey::Type_Expand_String: wxPrintf(wxT("EXPAND_SZ")); break; | |
2015 | case wxRegKey::Type_Binary: wxPrintf(wxT("BINARY")); break; | |
2016 | case wxRegKey::Type_Dword: wxPrintf(wxT("DWORD")); break; | |
2017 | case wxRegKey::Type_Multi_String: wxPrintf(wxT("MULTI_SZ")); break; | |
2018 | default: wxPrintf(wxT("other (unknown)")); break; | |
6dfec4b8 VZ |
2019 | } |
2020 | ||
9a83f860 | 2021 | wxPrintf(wxT(", value = ")); |
6dfec4b8 VZ |
2022 | if ( key.IsNumericValue(value) ) |
2023 | { | |
2024 | long val; | |
2025 | key.QueryValue(value, &val); | |
9a83f860 | 2026 | wxPrintf(wxT("%ld"), val); |
6dfec4b8 VZ |
2027 | } |
2028 | else // string | |
2029 | { | |
2030 | wxString val; | |
2031 | key.QueryValue(value, val); | |
9a83f860 | 2032 | wxPrintf(wxT("'%s'"), val.c_str()); |
6dfec4b8 VZ |
2033 | |
2034 | key.QueryRawValue(value, val); | |
9a83f860 | 2035 | wxPrintf(wxT(" (raw value '%s')"), val.c_str()); |
6dfec4b8 VZ |
2036 | } |
2037 | ||
e9d2bb6f | 2038 | wxPutchar('\n'); |
6dfec4b8 VZ |
2039 | |
2040 | cont = key.GetNextValue(value, dummy); | |
2041 | } | |
2042 | } | |
2043 | ||
6ba63600 VZ |
2044 | static void TestRegistryAssociation() |
2045 | { | |
2046 | /* | |
2047 | The second call to deleteself genertaes an error message, with a | |
2048 | messagebox saying .flo is crucial to system operation, while the .ddf | |
2049 | call also fails, but with no error message | |
2050 | */ | |
2051 | ||
2052 | wxRegKey key; | |
2053 | ||
9a83f860 | 2054 | key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") ); |
6ba63600 | 2055 | key.Create(); |
9a83f860 VZ |
2056 | key = wxT("ddxf_auto_file") ; |
2057 | key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") ); | |
6ba63600 | 2058 | key.Create(); |
9a83f860 VZ |
2059 | key = wxT("ddxf_auto_file") ; |
2060 | key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); | |
6ba63600 | 2061 | key.Create(); |
9a83f860 VZ |
2062 | key = wxT("program,0") ; |
2063 | key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); | |
6ba63600 | 2064 | key.Create(); |
9a83f860 | 2065 | key = wxT("program \"%1\"") ; |
6ba63600 | 2066 | |
9a83f860 | 2067 | key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") ); |
6ba63600 | 2068 | key.DeleteSelf(); |
9a83f860 | 2069 | key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") ); |
6ba63600 | 2070 | key.DeleteSelf(); |
9a83f860 | 2071 | key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); |
6ba63600 | 2072 | key.DeleteSelf(); |
9a83f860 | 2073 | key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); |
6ba63600 VZ |
2074 | key.DeleteSelf(); |
2075 | } | |
2076 | ||
6dfec4b8 VZ |
2077 | #endif // TEST_REGISTRY |
2078 | ||
b92fd37c VZ |
2079 | // ---------------------------------------------------------------------------- |
2080 | // FTP | |
2081 | // ---------------------------------------------------------------------------- | |
2082 | ||
2e907fab VZ |
2083 | #ifdef TEST_FTP |
2084 | ||
e84010cf | 2085 | #include "wx/protocol/ftp.h" |
0576cd9e | 2086 | #include "wx/protocol/log.h" |
2e907fab | 2087 | |
b92fd37c VZ |
2088 | #define FTP_ANONYMOUS |
2089 | ||
d6accb8c FM |
2090 | static wxFTP *ftp; |
2091 | ||
b92fd37c | 2092 | #ifdef FTP_ANONYMOUS |
ec0e0939 | 2093 | static const wxChar *hostname = wxT("ftp.wxwidgets.org"); |
9a83f860 VZ |
2094 | static const wxChar *directory = wxT("/pub"); |
2095 | static const wxChar *filename = wxT("welcome.msg"); | |
b92fd37c | 2096 | #else |
ec0e0939 | 2097 | static const wxChar *hostname = "localhost"; |
9a83f860 VZ |
2098 | static const wxChar *directory = wxT("/etc"); |
2099 | static const wxChar *filename = wxT("issue"); | |
b92fd37c VZ |
2100 | #endif |
2101 | ||
2102 | static bool TestFtpConnect() | |
8e907a13 | 2103 | { |
9a83f860 | 2104 | wxPuts(wxT("*** Testing FTP connect ***")); |
8e907a13 | 2105 | |
b92fd37c | 2106 | #ifdef FTP_ANONYMOUS |
9a83f860 | 2107 | wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname); |
b92fd37c | 2108 | #else // !FTP_ANONYMOUS |
456ae26d VZ |
2109 | wxChar user[256]; |
2110 | wxFgets(user, WXSIZEOF(user), stdin); | |
2111 | user[wxStrlen(user) - 1] = '\0'; // chop off '\n' | |
d6accb8c | 2112 | ftp->SetUser(user); |
b92fd37c | 2113 | |
456ae26d | 2114 | wxChar password[256]; |
9a83f860 | 2115 | wxPrintf(wxT("Password for %s: "), password); |
456ae26d VZ |
2116 | wxFgets(password, WXSIZEOF(password), stdin); |
2117 | password[wxStrlen(password) - 1] = '\0'; // chop off '\n' | |
d6accb8c | 2118 | ftp->SetPassword(password); |
b92fd37c | 2119 | |
9a83f860 | 2120 | wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname, user); |
b92fd37c VZ |
2121 | #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS |
2122 | ||
d6accb8c | 2123 | if ( !ftp->Connect(hostname) ) |
b92fd37c | 2124 | { |
9a83f860 | 2125 | wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname); |
b92fd37c | 2126 | |
cab8f76e | 2127 | return false; |
b92fd37c VZ |
2128 | } |
2129 | else | |
2130 | { | |
9a83f860 | 2131 | wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"), |
d6accb8c FM |
2132 | hostname, ftp->Pwd().c_str()); |
2133 | ftp->Close(); | |
b92fd37c VZ |
2134 | } |
2135 | ||
cab8f76e | 2136 | return true; |
b92fd37c | 2137 | } |
b1229561 | 2138 | |
30ccbb89 | 2139 | #if TEST_INTERACTIVE |
b92fd37c VZ |
2140 | static void TestFtpInteractive() |
2141 | { | |
9a83f860 | 2142 | wxPuts(wxT("\n*** Interactive wxFTP test ***")); |
b92fd37c | 2143 | |
456ae26d | 2144 | wxChar buf[128]; |
b92fd37c VZ |
2145 | |
2146 | for ( ;; ) | |
2147 | { | |
ec0e0939 | 2148 | wxPrintf(wxT("Enter FTP command (or 'quit' to escape): ")); |
456ae26d | 2149 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) |
b92fd37c VZ |
2150 | break; |
2151 | ||
2152 | // kill the last '\n' | |
456ae26d | 2153 | buf[wxStrlen(buf) - 1] = 0; |
b92fd37c VZ |
2154 | |
2155 | // special handling of LIST and NLST as they require data connection | |
2156 | wxString start(buf, 4); | |
2157 | start.MakeUpper(); | |
9a83f860 | 2158 | if ( start == wxT("LIST") || start == wxT("NLST") ) |
8e907a13 | 2159 | { |
b92fd37c | 2160 | wxString wildcard; |
456ae26d | 2161 | if ( wxStrlen(buf) > 4 ) |
b92fd37c | 2162 | wildcard = buf + 5; |
8e907a13 | 2163 | |
b92fd37c | 2164 | wxArrayString files; |
9a83f860 | 2165 | if ( !ftp->GetList(files, wildcard, start == wxT("LIST")) ) |
8e907a13 | 2166 | { |
9a83f860 | 2167 | wxPrintf(wxT("ERROR: failed to get %s of files\n"), start.c_str()); |
8e907a13 VZ |
2168 | } |
2169 | else | |
2170 | { | |
9a83f860 | 2171 | wxPrintf(wxT("--- %s of '%s' under '%s':\n"), |
d6accb8c | 2172 | start.c_str(), wildcard.c_str(), ftp->Pwd().c_str()); |
b92fd37c VZ |
2173 | size_t count = files.GetCount(); |
2174 | for ( size_t n = 0; n < count; n++ ) | |
2175 | { | |
9a83f860 | 2176 | wxPrintf(wxT("\t%s\n"), files[n].c_str()); |
b92fd37c | 2177 | } |
9a83f860 | 2178 | wxPuts(wxT("--- End of the file list")); |
8e907a13 | 2179 | } |
2e907fab | 2180 | } |
ec0e0939 FM |
2181 | else if ( start == wxT("QUIT") ) |
2182 | { | |
2183 | break; // get out of here! | |
2184 | } | |
b92fd37c | 2185 | else // !list |
2e907fab | 2186 | { |
d6accb8c | 2187 | wxChar ch = ftp->SendCommand(buf); |
9a83f860 | 2188 | wxPrintf(wxT("Command %s"), ch ? wxT("succeeded") : wxT("failed")); |
b92fd37c VZ |
2189 | if ( ch ) |
2190 | { | |
9a83f860 | 2191 | wxPrintf(wxT(" (return code %c)"), ch); |
b92fd37c | 2192 | } |
2e907fab | 2193 | |
9a83f860 | 2194 | wxPrintf(wxT(", server reply:\n%s\n\n"), ftp->GetLastResult().c_str()); |
2e907fab | 2195 | } |
2c8e4738 | 2196 | } |
b92fd37c | 2197 | |
30ccbb89 | 2198 | wxPuts(wxT("\n")); |
2c8e4738 | 2199 | } |
30ccbb89 | 2200 | #endif // TEST_INTERACTIVE |
2e907fab | 2201 | #endif // TEST_FTP |
2c8e4738 | 2202 | |
eaff0f0d VZ |
2203 | // ---------------------------------------------------------------------------- |
2204 | // stack backtrace | |
2205 | // ---------------------------------------------------------------------------- | |
2206 | ||
2207 | #ifdef TEST_STACKWALKER | |
2208 | ||
74e2116a MB |
2209 | #if wxUSE_STACKWALKER |
2210 | ||
eaff0f0d VZ |
2211 | #include "wx/stackwalk.h" |
2212 | ||
2213 | class StackDump : public wxStackWalker | |
2214 | { | |
2215 | public: | |
2216 | StackDump(const char *argv0) | |
2217 | : wxStackWalker(argv0) | |
2218 | { | |
2219 | } | |
2220 | ||
eb835127 | 2221 | virtual void Walk(size_t skip = 1, size_t maxdepth = wxSTACKWALKER_MAX_DEPTH) |
eaff0f0d | 2222 | { |
9a83f860 | 2223 | wxPuts(wxT("Stack dump:")); |
eaff0f0d | 2224 | |
eb835127 | 2225 | wxStackWalker::Walk(skip, maxdepth); |
eaff0f0d VZ |
2226 | } |
2227 | ||
2228 | protected: | |
2229 | virtual void OnStackFrame(const wxStackFrame& frame) | |
2230 | { | |
bf3bf677 | 2231 | printf("[%2d] ", (int) frame.GetLevel()); |
eaff0f0d VZ |
2232 | |
2233 | wxString name = frame.GetName(); | |
2234 | if ( !name.empty() ) | |
2235 | { | |
bf3bf677 | 2236 | printf("%-20.40s", (const char*)name.mb_str()); |
eaff0f0d VZ |
2237 | } |
2238 | else | |
2239 | { | |
2240 | printf("0x%08lx", (unsigned long)frame.GetAddress()); | |
2241 | } | |
2242 | ||
2243 | if ( frame.HasSourceLocation() ) | |
2244 | { | |
2245 | printf("\t%s:%d", | |
bf3bf677 VZ |
2246 | (const char*)frame.GetFileName().mb_str(), |
2247 | (int)frame.GetLine()); | |
eaff0f0d VZ |
2248 | } |
2249 | ||
2250 | puts(""); | |
2251 | ||
2252 | wxString type, val; | |
2253 | for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ ) | |
2254 | { | |
3e231024 FM |
2255 | printf("\t%s %s = %s\n", (const char*)type.mb_str(), |
2256 | (const char*)name.mb_str(), | |
bf3bf677 | 2257 | (const char*)val.mb_str()); |
eaff0f0d VZ |
2258 | } |
2259 | } | |
2260 | }; | |
2261 | ||
2262 | static void TestStackWalk(const char *argv0) | |
2263 | { | |
30ccbb89 | 2264 | wxPuts(wxT("*** Testing wxStackWalker ***")); |
eaff0f0d VZ |
2265 | |
2266 | StackDump dump(argv0); | |
2267 | dump.Walk(); | |
ec0e0939 FM |
2268 | |
2269 | wxPuts("\n"); | |
eaff0f0d VZ |
2270 | } |
2271 | ||
74e2116a MB |
2272 | #endif // wxUSE_STACKWALKER |
2273 | ||
eaff0f0d VZ |
2274 | #endif // TEST_STACKWALKER |
2275 | ||
af33b199 VZ |
2276 | // ---------------------------------------------------------------------------- |
2277 | // standard paths | |
2278 | // ---------------------------------------------------------------------------- | |
2279 | ||
2280 | #ifdef TEST_STDPATHS | |
2281 | ||
2282 | #include "wx/stdpaths.h" | |
6f207e66 | 2283 | #include "wx/wxchar.h" // wxPrintf |
af33b199 VZ |
2284 | |
2285 | static void TestStandardPaths() | |
2286 | { | |
30ccbb89 | 2287 | wxPuts(wxT("*** Testing wxStandardPaths ***")); |
af33b199 | 2288 | |
9a83f860 | 2289 | wxTheApp->SetAppName(wxT("console")); |
af33b199 | 2290 | |
5ba95b79 | 2291 | wxStandardPathsBase& stdp = wxStandardPaths::Get(); |
9a83f860 VZ |
2292 | wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str()); |
2293 | wxPrintf(wxT("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str()); | |
2294 | wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str()); | |
2295 | wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str()); | |
2296 | wxPrintf(wxT("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str()); | |
2297 | wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str()); | |
2298 | wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str()); | |
2299 | wxPrintf(wxT("Executable path:\t%s\n"), stdp.GetExecutablePath().c_str()); | |
2300 | wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str()); | |
2301 | wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str()); | |
2302 | wxPrintf(wxT("Localized res. dir:\t%s\n"), | |
2303 | stdp.GetLocalizedResourcesDir(wxT("fr")).c_str()); | |
2304 | wxPrintf(wxT("Message catalogs dir:\t%s\n"), | |
3af9f2de VZ |
2305 | stdp.GetLocalizedResourcesDir |
2306 | ( | |
9a83f860 | 2307 | wxT("fr"), |
3af9f2de VZ |
2308 | wxStandardPaths::ResourceCat_Messages |
2309 | ).c_str()); | |
ec0e0939 FM |
2310 | |
2311 | wxPuts("\n"); | |
af33b199 VZ |
2312 | } |
2313 | ||
2314 | #endif // TEST_STDPATHS | |
2315 | ||
0e2c5534 VZ |
2316 | // ---------------------------------------------------------------------------- |
2317 | // wxVolume tests | |
2318 | // ---------------------------------------------------------------------------- | |
2319 | ||
ba6ea19e | 2320 | #if !defined(__WIN32__) || !wxUSE_FSVOLUME |
0e2c5534 VZ |
2321 | #undef TEST_VOLUME |
2322 | #endif | |
2323 | ||
2324 | #ifdef TEST_VOLUME | |
2325 | ||
2326 | #include "wx/volume.h" | |
2327 | ||
2328 | static const wxChar *volumeKinds[] = | |
2329 | { | |
9a83f860 VZ |
2330 | wxT("floppy"), |
2331 | wxT("hard disk"), | |
2332 | wxT("CD-ROM"), | |
2333 | wxT("DVD-ROM"), | |
2334 | wxT("network volume"), | |
2335 | wxT("other volume"), | |
0e2c5534 VZ |
2336 | }; |
2337 | ||
2338 | static void TestFSVolume() | |
2339 | { | |
9a83f860 | 2340 | wxPuts(wxT("*** Testing wxFSVolume class ***")); |
0e2c5534 VZ |
2341 | |
2342 | wxArrayString volumes = wxFSVolume::GetVolumes(); | |
2343 | size_t count = volumes.GetCount(); | |
2344 | ||
2345 | if ( !count ) | |
2346 | { | |
9a83f860 | 2347 | wxPuts(wxT("ERROR: no mounted volumes?")); |
0e2c5534 VZ |
2348 | return; |
2349 | } | |
2350 | ||
9a83f860 | 2351 | wxPrintf(wxT("%u mounted volumes found:\n"), count); |
0e2c5534 VZ |
2352 | |
2353 | for ( size_t n = 0; n < count; n++ ) | |
2354 | { | |
2355 | wxFSVolume vol(volumes[n]); | |
2356 | if ( !vol.IsOk() ) | |
2357 | { | |
9a83f860 | 2358 | wxPuts(wxT("ERROR: couldn't create volume")); |
0e2c5534 VZ |
2359 | continue; |
2360 | } | |
2361 | ||
9a83f860 | 2362 | wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"), |
0e2c5534 VZ |
2363 | n + 1, |
2364 | vol.GetDisplayName().c_str(), | |
2365 | vol.GetName().c_str(), | |
2366 | volumeKinds[vol.GetKind()], | |
9a83f860 VZ |
2367 | vol.IsWritable() ? wxT("rw") : wxT("ro"), |
2368 | vol.GetFlags() & wxFS_VOL_REMOVABLE ? wxT("removable") | |
2369 | : wxT("fixed")); | |
0e2c5534 | 2370 | } |
ec0e0939 FM |
2371 | |
2372 | wxPuts("\n"); | |
0e2c5534 VZ |
2373 | } |
2374 | ||
2375 | #endif // TEST_VOLUME | |
2376 | ||
b76b015e VZ |
2377 | // ---------------------------------------------------------------------------- |
2378 | // date time | |
2379 | // ---------------------------------------------------------------------------- | |
2380 | ||
d31b7b68 | 2381 | #ifdef TEST_DATETIME |
b76b015e | 2382 | |
b713f891 | 2383 | #include "wx/math.h" |
e84010cf | 2384 | #include "wx/datetime.h" |
b76b015e | 2385 | |
4b586201 WS |
2386 | #if TEST_INTERACTIVE |
2387 | ||
b92fd37c | 2388 | static void TestDateTimeInteractive() |
9d9b7755 | 2389 | { |
9a83f860 | 2390 | wxPuts(wxT("\n*** interactive wxDateTime tests ***")); |
9d9b7755 | 2391 | |
456ae26d | 2392 | wxChar buf[128]; |
9d9b7755 VZ |
2393 | |
2394 | for ( ;; ) | |
2395 | { | |
ec0e0939 | 2396 | wxPrintf(wxT("Enter a date (or 'quit' to escape): ")); |
456ae26d | 2397 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) |
9d9b7755 VZ |
2398 | break; |
2399 | ||
f6bcfd97 | 2400 | // kill the last '\n' |
456ae26d | 2401 | buf[wxStrlen(buf) - 1] = 0; |
ec0e0939 FM |
2402 | |
2403 | if ( wxString(buf).CmpNoCase("quit") == 0 ) | |
2404 | break; | |
f6bcfd97 | 2405 | |
9d9b7755 | 2406 | wxDateTime dt; |
456ae26d | 2407 | const wxChar *p = dt.ParseDate(buf); |
f6bcfd97 | 2408 | if ( !p ) |
9d9b7755 | 2409 | { |
9a83f860 | 2410 | wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf); |
9d9b7755 VZ |
2411 | |
2412 | continue; | |
2413 | } | |
f6bcfd97 BP |
2414 | else if ( *p ) |
2415 | { | |
9a83f860 | 2416 | wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p - buf); |
f6bcfd97 | 2417 | } |
9d9b7755 | 2418 | |
9a83f860 VZ |
2419 | wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"), |
2420 | dt.Format(wxT("%b %d, %Y")).c_str(), | |
456ae26d VZ |
2421 | dt.GetDayOfYear(), |
2422 | dt.GetWeekOfMonth(wxDateTime::Monday_First), | |
2423 | dt.GetWeekOfMonth(wxDateTime::Sunday_First), | |
2424 | dt.GetWeekOfYear(wxDateTime::Monday_First)); | |
9d9b7755 | 2425 | } |
ec0e0939 FM |
2426 | |
2427 | wxPuts("\n"); | |
9d9b7755 VZ |
2428 | } |
2429 | ||
4b586201 | 2430 | #endif // TEST_INTERACTIVE |
d31b7b68 | 2431 | #endif // TEST_DATETIME |
b76b015e | 2432 | |
e87271f3 | 2433 | // ---------------------------------------------------------------------------- |
30ccbb89 | 2434 | // single instance |
e87271f3 VZ |
2435 | // ---------------------------------------------------------------------------- |
2436 | ||
daa2c7d9 | 2437 | #ifdef TEST_SNGLINST |
30ccbb89 FM |
2438 | |
2439 | #include "wx/snglinst.h" | |
2440 | ||
2441 | static bool TestSingleIstance() | |
2442 | { | |
2443 | wxPuts(wxT("\n*** Testing wxSingleInstanceChecker ***")); | |
2444 | ||
2445 | wxSingleInstanceChecker checker; | |
2446 | if ( checker.Create(wxT(".wxconsole.lock")) ) | |
2447 | { | |
2448 | if ( checker.IsAnotherRunning() ) | |
2449 | { | |
2450 | wxPrintf(wxT("Another instance of the program is running, exiting.\n")); | |
2451 | ||
2452 | return false; | |
2453 | } | |
2454 | ||
2455 | // wait some time to give time to launch another instance | |
2456 | wxPuts(wxT("If you try to run another instance of this program now, it won't start.")); | |
2457 | wxPrintf(wxT("Press \"Enter\" to exit wxSingleInstanceChecker test and proceed...")); | |
2458 | wxFgetc(stdin); | |
2459 | } | |
2460 | else // failed to create | |
2461 | { | |
2462 | wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n")); | |
2463 | } | |
2464 | ||
2465 | wxPuts("\n"); | |
2466 | ||
2467 | return true; | |
2468 | } | |
daa2c7d9 VZ |
2469 | #endif // TEST_SNGLINST |
2470 | ||
30ccbb89 FM |
2471 | |
2472 | // ---------------------------------------------------------------------------- | |
2473 | // entry point | |
2474 | // ---------------------------------------------------------------------------- | |
2475 | ||
bbfa0322 | 2476 | int main(int argc, char **argv) |
37667812 | 2477 | { |
5ba95b79 WS |
2478 | #if wxUSE_UNICODE |
2479 | wxChar **wxArgv = new wxChar *[argc + 1]; | |
2480 | ||
2481 | { | |
2482 | int n; | |
2483 | ||
2484 | for (n = 0; n < argc; n++ ) | |
2485 | { | |
2486 | wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); | |
2487 | wxArgv[n] = wxStrdup(warg); | |
2488 | } | |
2489 | ||
2490 | wxArgv[n] = NULL; | |
2491 | } | |
2492 | #else // !wxUSE_UNICODE | |
2493 | #define wxArgv argv | |
2494 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE | |
2495 | ||
6f35ed60 | 2496 | wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); |
9cb47ea2 | 2497 | |
58b24a56 VZ |
2498 | wxInitializer initializer; |
2499 | if ( !initializer ) | |
37667812 | 2500 | { |
be5a51fb | 2501 | fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); |
58b24a56 VZ |
2502 | |
2503 | return -1; | |
2504 | } | |
2505 | ||
2506 | #ifdef TEST_SNGLINST | |
30ccbb89 FM |
2507 | if (!TestSingleIstance()) |
2508 | return 1; | |
58b24a56 VZ |
2509 | #endif // TEST_SNGLINST |
2510 | ||
1944c6bd | 2511 | #ifdef TEST_DIR |
e9d2bb6f | 2512 | #if TEST_ALL |
99a5af7f | 2513 | TestDirExists(); |
2f0c19d0 | 2514 | TestDirEnum(); |
e9d2bb6f | 2515 | #endif |
2f0c19d0 | 2516 | TestDirTraverse(); |
1944c6bd VZ |
2517 | #endif // TEST_DIR |
2518 | ||
93ed8ff7 | 2519 | #ifdef TEST_DYNLIB |
f6bcfd97 | 2520 | TestDllLoad(); |
297ebe6b | 2521 | TestDllListLoaded(); |
93ed8ff7 | 2522 | #endif // TEST_DYNLIB |
f6bcfd97 | 2523 | |
8fd0d89b VZ |
2524 | #ifdef TEST_ENVIRON |
2525 | TestEnvironment(); | |
2526 | #endif // TEST_ENVIRON | |
2527 | ||
ee6e1b1d VZ |
2528 | #ifdef TEST_FILECONF |
2529 | TestFileConfRead(); | |
2530 | #endif // TEST_FILECONF | |
2531 | ||
ec37df57 VZ |
2532 | #ifdef TEST_LOCALE |
2533 | TestDefaultLang(); | |
2534 | #endif // TEST_LOCALE | |
2535 | ||
378b05f7 | 2536 | #ifdef TEST_LOG |
9a83f860 | 2537 | wxPuts(wxT("*** Testing wxLog ***")); |
cab8f76e | 2538 | |
378b05f7 VZ |
2539 | wxString s; |
2540 | for ( size_t n = 0; n < 8000; n++ ) | |
2541 | { | |
9a83f860 | 2542 | s << (wxChar)(wxT('A') + (n % 26)); |
378b05f7 VZ |
2543 | } |
2544 | ||
9a83f860 | 2545 | wxLogWarning(wxT("The length of the string is %lu"), |
cab8f76e VZ |
2546 | (unsigned long)s.length()); |
2547 | ||
378b05f7 | 2548 | wxString msg; |
9a83f860 | 2549 | msg.Printf(wxT("A very very long message: '%s', the end!\n"), s.c_str()); |
378b05f7 VZ |
2550 | |
2551 | // this one shouldn't be truncated | |
456ae26d | 2552 | wxPrintf(msg); |
378b05f7 VZ |
2553 | |
2554 | // but this one will because log functions use fixed size buffer | |
b568d04f VZ |
2555 | // (note that it doesn't need '\n' at the end neither - will be added |
2556 | // by wxLog anyhow) | |
9a83f860 | 2557 | wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s.c_str()); |
378b05f7 VZ |
2558 | #endif // TEST_LOG |
2559 | ||
f6bcfd97 | 2560 | #ifdef TEST_FILE |
e9d2bb6f DS |
2561 | TestFileRead(); |
2562 | TestTextFileRead(); | |
2563 | TestFileCopy(); | |
59062ec1 | 2564 | TestTempFile(); |
f6bcfd97 BP |
2565 | #endif // TEST_FILE |
2566 | ||
844f90fb | 2567 | #ifdef TEST_FILENAME |
e9d2bb6f DS |
2568 | TestFileNameTemp(); |
2569 | TestFileNameCwd(); | |
2570 | TestFileNameDirManip(); | |
2571 | TestFileNameComparison(); | |
2572 | TestFileNameOperations(); | |
844f90fb VZ |
2573 | #endif // TEST_FILENAME |
2574 | ||
d56e2b97 VZ |
2575 | #ifdef TEST_FILETIME |
2576 | TestFileGetTimes(); | |
e9d2bb6f | 2577 | #if 0 |
d56e2b97 | 2578 | TestFileSetTimes(); |
e9d2bb6f | 2579 | #endif |
d56e2b97 VZ |
2580 | #endif // TEST_FILETIME |
2581 | ||
07a56e45 VZ |
2582 | #ifdef TEST_FTP |
2583 | wxLog::AddTraceMask(FTP_TRACE_MASK); | |
eb835127 FM |
2584 | |
2585 | // wxFTP cannot be a static variable as its ctor needs to access | |
2586 | // wxWidgets internals after it has been initialized | |
2587 | ftp = new wxFTP; | |
0576cd9e | 2588 | ftp->SetLog(new wxProtocolLog(FTP_TRACE_MASK)); |
07a56e45 | 2589 | if ( TestFtpConnect() ) |
ec0e0939 | 2590 | TestFtpInteractive(); |
07a56e45 VZ |
2591 | //else: connecting to the FTP server failed |
2592 | ||
eb835127 | 2593 | delete ftp; |
07a56e45 VZ |
2594 | #endif // TEST_FTP |
2595 | ||
696e1ea0 | 2596 | #ifdef TEST_MIME |
9a83f860 | 2597 | //wxLog::AddTraceMask(wxT("mime")); |
b61af837 | 2598 | TestMimeEnum(); |
c19c2f6e | 2599 | #if 0 |
b61af837 | 2600 | TestMimeOverride(); |
c19c2f6e VZ |
2601 | TestMimeAssociate(); |
2602 | #endif | |
f06ef5f4 | 2603 | TestMimeFilename(); |
696e1ea0 VZ |
2604 | #endif // TEST_MIME |
2605 | ||
89e60357 | 2606 | #ifdef TEST_INFO_FUNCTIONS |
8bb6b2c0 VZ |
2607 | TestOsInfo(); |
2608 | TestPlatformInfo(); | |
2609 | TestUserInfo(); | |
19f45995 | 2610 | |
8bb6b2c0 VZ |
2611 | #if TEST_INTERACTIVE |
2612 | TestDiskInfo(); | |
e9d2bb6f | 2613 | #endif |
89e60357 VZ |
2614 | #endif // TEST_INFO_FUNCTIONS |
2615 | ||
39189b9d VZ |
2616 | #ifdef TEST_PATHLIST |
2617 | TestPathList(); | |
2618 | #endif // TEST_PATHLIST | |
2619 | ||
7aeebdcd VZ |
2620 | #ifdef TEST_PRINTF |
2621 | TestPrintf(); | |
2622 | #endif // TEST_PRINTF | |
2623 | ||
7ba4fbeb | 2624 | #ifdef TEST_REGCONF |
e9d2bb6f DS |
2625 | #if 0 |
2626 | TestRegConfWrite(); | |
2627 | #endif | |
0aa29b6b | 2628 | TestRegConfRead(); |
7ba4fbeb VZ |
2629 | #endif // TEST_REGCONF |
2630 | ||
bc10103e VS |
2631 | #if defined TEST_REGEX && TEST_INTERACTIVE |
2632 | TestRegExInteractive(); | |
2633 | #endif // defined TEST_REGEX && TEST_INTERACTIVE | |
07a56e45 | 2634 | |
6dfec4b8 | 2635 | #ifdef TEST_REGISTRY |
daa2c7d9 | 2636 | TestRegistryRead(); |
6ba63600 | 2637 | TestRegistryAssociation(); |
6dfec4b8 VZ |
2638 | #endif // TEST_REGISTRY |
2639 | ||
d31b7b68 | 2640 | #ifdef TEST_DATETIME |
e9d2bb6f | 2641 | #if TEST_INTERACTIVE |
b92fd37c | 2642 | TestDateTimeInteractive(); |
e9d2bb6f | 2643 | #endif |
d31b7b68 | 2644 | #endif // TEST_DATETIME |
b76b015e | 2645 | |
eaff0f0d | 2646 | #ifdef TEST_STACKWALKER |
60c474a0 | 2647 | #if wxUSE_STACKWALKER |
eaff0f0d | 2648 | TestStackWalk(argv[0]); |
60c474a0 | 2649 | #endif |
eaff0f0d VZ |
2650 | #endif // TEST_STACKWALKER |
2651 | ||
af33b199 VZ |
2652 | #ifdef TEST_STDPATHS |
2653 | TestStandardPaths(); | |
2654 | #endif | |
2655 | ||
551fe3a6 | 2656 | #ifdef TEST_USLEEP |
9a83f860 | 2657 | wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z...")); |
551fe3a6 VZ |
2658 | wxUsleep(3000); |
2659 | #endif // TEST_USLEEP | |
2660 | ||
0e2c5534 VZ |
2661 | #ifdef TEST_VOLUME |
2662 | TestFSVolume(); | |
2663 | #endif // TEST_VOLUME | |
2664 | ||
5ba95b79 WS |
2665 | #if wxUSE_UNICODE |
2666 | { | |
2667 | for ( int n = 0; n < argc; n++ ) | |
2668 | free(wxArgv[n]); | |
2669 | ||
2670 | delete [] wxArgv; | |
2671 | } | |
2672 | #endif // wxUSE_UNICODE | |
2673 | ||
e9d2bb6f DS |
2674 | wxUnusedVar(argc); |
2675 | wxUnusedVar(argv); | |
37667812 VZ |
2676 | return 0; |
2677 | } |