]>
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 | 108 | #define TEST_DIR |
93ed8ff7 | 109 | #define TEST_DYNLIB |
31f6de22 | 110 | #define TEST_ENVIRON |
31f6de22 | 111 | #define TEST_FILE |
31f6de22 VZ |
112 | #define TEST_FILENAME |
113 | #define TEST_FILETIME | |
31f6de22 | 114 | #define TEST_INFO_FUNCTIONS |
31f6de22 VZ |
115 | #define TEST_LOCALE |
116 | #define TEST_LOG | |
31f6de22 | 117 | #define TEST_MIME |
af266e5b | 118 | #define TEST_MODULE |
31f6de22 | 119 | #define TEST_PATHLIST |
e9d2bb6f | 120 | #else // #if TEST_ALL |
91ee2f35 | 121 | #define TEST_DATETIME |
45cb7053 | 122 | #define TEST_VOLUME |
ec0e0939 FM |
123 | #define TEST_STDPATHS |
124 | #define TEST_STACKWALKER | |
125 | #define TEST_FTP | |
30ccbb89 | 126 | #define TEST_SNGLINST |
36340644 | 127 | #define TEST_REGEX |
31f6de22 | 128 | #endif |
f6bcfd97 | 129 | |
daa2c7d9 VZ |
130 | // some tests are interactive, define this to run them |
131 | #ifdef TEST_INTERACTIVE | |
132 | #undef TEST_INTERACTIVE | |
133 | ||
e9d2bb6f | 134 | #define TEST_INTERACTIVE 1 |
daa2c7d9 | 135 | #else |
91ee2f35 | 136 | #define TEST_INTERACTIVE 1 |
daa2c7d9 | 137 | #endif |
58b24a56 | 138 | |
e87271f3 VZ |
139 | // ============================================================================ |
140 | // implementation | |
141 | // ============================================================================ | |
142 | ||
1944c6bd VZ |
143 | // ---------------------------------------------------------------------------- |
144 | // wxDir | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
147 | #ifdef TEST_DIR | |
148 | ||
e84010cf | 149 | #include "wx/dir.h" |
1944c6bd | 150 | |
35332784 | 151 | #ifdef __UNIX__ |
9a83f860 VZ |
152 | static const wxChar *ROOTDIR = wxT("/"); |
153 | static const wxChar *TESTDIR = wxT("/usr/local/share"); | |
65e324b4 | 154 | #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__) |
9a83f860 VZ |
155 | static const wxChar *ROOTDIR = wxT("c:\\"); |
156 | static const wxChar *TESTDIR = wxT("d:\\"); | |
35332784 VZ |
157 | #else |
158 | #error "don't know where the root directory is" | |
159 | #endif | |
160 | ||
1944c6bd VZ |
161 | static void TestDirEnumHelper(wxDir& dir, |
162 | int flags = wxDIR_DEFAULT, | |
163 | const wxString& filespec = wxEmptyString) | |
164 | { | |
165 | wxString filename; | |
166 | ||
167 | if ( !dir.IsOpened() ) | |
168 | return; | |
169 | ||
170 | bool cont = dir.GetFirst(&filename, filespec, flags); | |
171 | while ( cont ) | |
172 | { | |
9a83f860 | 173 | wxPrintf(wxT("\t%s\n"), filename.c_str()); |
1944c6bd VZ |
174 | |
175 | cont = dir.GetNext(&filename); | |
176 | } | |
177 | ||
e9d2bb6f | 178 | wxPuts(wxEmptyString); |
1944c6bd VZ |
179 | } |
180 | ||
dab6fbae WS |
181 | #if TEST_ALL |
182 | ||
1944c6bd VZ |
183 | static void TestDirEnum() |
184 | { | |
9a83f860 | 185 | wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***")); |
35332784 | 186 | |
149147e1 | 187 | wxString cwd = wxGetCwd(); |
9475670f | 188 | if ( !wxDir::Exists(cwd) ) |
149147e1 | 189 | { |
9a83f860 | 190 | wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str()); |
149147e1 VZ |
191 | return; |
192 | } | |
193 | ||
ee3ef281 | 194 | wxDir dir(cwd); |
149147e1 VZ |
195 | if ( !dir.IsOpened() ) |
196 | { | |
9a83f860 | 197 | wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd.c_str()); |
149147e1 VZ |
198 | return; |
199 | } | |
1944c6bd | 200 | |
9a83f860 | 201 | wxPuts(wxT("Enumerating everything in current directory:")); |
1944c6bd VZ |
202 | TestDirEnumHelper(dir); |
203 | ||
9a83f860 | 204 | wxPuts(wxT("Enumerating really everything in current directory:")); |
1944c6bd VZ |
205 | TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT); |
206 | ||
9a83f860 VZ |
207 | wxPuts(wxT("Enumerating object files in current directory:")); |
208 | TestDirEnumHelper(dir, wxDIR_DEFAULT, wxT("*.o*")); | |
1944c6bd | 209 | |
9a83f860 | 210 | wxPuts(wxT("Enumerating directories in current directory:")); |
1944c6bd VZ |
211 | TestDirEnumHelper(dir, wxDIR_DIRS); |
212 | ||
9a83f860 | 213 | wxPuts(wxT("Enumerating files in current directory:")); |
1944c6bd VZ |
214 | TestDirEnumHelper(dir, wxDIR_FILES); |
215 | ||
9a83f860 | 216 | wxPuts(wxT("Enumerating files including hidden in current directory:")); |
1944c6bd VZ |
217 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
218 | ||
35332784 | 219 | dir.Open(ROOTDIR); |
1944c6bd | 220 | |
9a83f860 | 221 | wxPuts(wxT("Enumerating everything in root directory:")); |
1944c6bd VZ |
222 | TestDirEnumHelper(dir, wxDIR_DEFAULT); |
223 | ||
9a83f860 | 224 | wxPuts(wxT("Enumerating directories in root directory:")); |
1944c6bd VZ |
225 | TestDirEnumHelper(dir, wxDIR_DIRS); |
226 | ||
9a83f860 | 227 | wxPuts(wxT("Enumerating files in root directory:")); |
1944c6bd VZ |
228 | TestDirEnumHelper(dir, wxDIR_FILES); |
229 | ||
9a83f860 | 230 | wxPuts(wxT("Enumerating files including hidden in root directory:")); |
1944c6bd VZ |
231 | TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); |
232 | ||
9a83f860 VZ |
233 | wxPuts(wxT("Enumerating files in non existing directory:")); |
234 | wxDir dirNo(wxT("nosuchdir")); | |
1944c6bd VZ |
235 | TestDirEnumHelper(dirNo); |
236 | } | |
237 | ||
dab6fbae WS |
238 | #endif // TEST_ALL |
239 | ||
35332784 VZ |
240 | class DirPrintTraverser : public wxDirTraverser |
241 | { | |
242 | public: | |
e9d2bb6f | 243 | virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) |
35332784 VZ |
244 | { |
245 | return wxDIR_CONTINUE; | |
246 | } | |
247 | ||
248 | virtual wxDirTraverseResult OnDir(const wxString& dirname) | |
249 | { | |
250 | wxString path, name, ext; | |
bd365871 | 251 | wxFileName::SplitPath(dirname, &path, &name, &ext); |
35332784 VZ |
252 | |
253 | if ( !ext.empty() ) | |
9a83f860 | 254 | name << wxT('.') << ext; |
35332784 VZ |
255 | |
256 | wxString indent; | |
257 | for ( const wxChar *p = path.c_str(); *p; p++ ) | |
258 | { | |
259 | if ( wxIsPathSeparator(*p) ) | |
9a83f860 | 260 | indent += wxT(" "); |
35332784 VZ |
261 | } |
262 | ||
9a83f860 | 263 | wxPrintf(wxT("%s%s\n"), indent.c_str(), name.c_str()); |
35332784 VZ |
264 | |
265 | return wxDIR_CONTINUE; | |
266 | } | |
267 | }; | |
268 | ||
269 | static void TestDirTraverse() | |
270 | { | |
9a83f860 | 271 | wxPuts(wxT("*** Testing wxDir::Traverse() ***")); |
35332784 VZ |
272 | |
273 | // enum all files | |
274 | wxArrayString files; | |
275 | size_t n = wxDir::GetAllFiles(TESTDIR, &files); | |
9a83f860 | 276 | wxPrintf(wxT("There are %u files under '%s'\n"), n, TESTDIR); |
35332784 VZ |
277 | if ( n > 1 ) |
278 | { | |
9a83f860 VZ |
279 | wxPrintf(wxT("First one is '%s'\n"), files[0u].c_str()); |
280 | wxPrintf(wxT(" last one is '%s'\n"), files[n - 1].c_str()); | |
35332784 VZ |
281 | } |
282 | ||
283 | // enum again with custom traverser | |
9a83f860 | 284 | wxPuts(wxT("Now enumerating directories:")); |
35332784 VZ |
285 | wxDir dir(TESTDIR); |
286 | DirPrintTraverser traverser; | |
e9d2bb6f | 287 | dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN); |
35332784 VZ |
288 | } |
289 | ||
dab6fbae WS |
290 | #if TEST_ALL |
291 | ||
149147e1 VZ |
292 | static void TestDirExists() |
293 | { | |
9a83f860 | 294 | wxPuts(wxT("*** Testing wxDir::Exists() ***")); |
149147e1 | 295 | |
456ae26d | 296 | static const wxChar *dirnames[] = |
149147e1 | 297 | { |
9a83f860 | 298 | wxT("."), |
149147e1 | 299 | #if defined(__WXMSW__) |
9a83f860 VZ |
300 | wxT("c:"), |
301 | wxT("c:\\"), | |
302 | wxT("\\\\share\\file"), | |
303 | wxT("c:\\dos"), | |
304 | wxT("c:\\dos\\"), | |
305 | wxT("c:\\dos\\\\"), | |
306 | wxT("c:\\autoexec.bat"), | |
149147e1 | 307 | #elif defined(__UNIX__) |
9a83f860 VZ |
308 | wxT("/"), |
309 | wxT("//"), | |
310 | wxT("/usr/bin"), | |
311 | wxT("/usr//bin"), | |
312 | wxT("/usr///bin"), | |
149147e1 VZ |
313 | #endif |
314 | }; | |
315 | ||
316 | for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ ) | |
317 | { | |
9a83f860 | 318 | wxPrintf(wxT("%-40s: %s\n"), |
456ae26d | 319 | dirnames[n], |
9a83f860 VZ |
320 | wxDir::Exists(dirnames[n]) ? wxT("exists") |
321 | : wxT("doesn't exist")); | |
149147e1 VZ |
322 | } |
323 | } | |
324 | ||
dab6fbae WS |
325 | #endif // TEST_ALL |
326 | ||
1944c6bd VZ |
327 | #endif // TEST_DIR |
328 | ||
f6bcfd97 BP |
329 | // ---------------------------------------------------------------------------- |
330 | // wxDllLoader | |
331 | // ---------------------------------------------------------------------------- | |
332 | ||
93ed8ff7 | 333 | #ifdef TEST_DYNLIB |
f6bcfd97 | 334 | |
e84010cf | 335 | #include "wx/dynlib.h" |
f6bcfd97 BP |
336 | |
337 | static void TestDllLoad() | |
338 | { | |
339 | #if defined(__WXMSW__) | |
9a83f860 VZ |
340 | static const wxChar *LIB_NAME = wxT("kernel32.dll"); |
341 | static const wxChar *FUNC_NAME = wxT("lstrlenA"); | |
f6bcfd97 BP |
342 | #elif defined(__UNIX__) |
343 | // weird: using just libc.so does *not* work! | |
9a83f860 VZ |
344 | static const wxChar *LIB_NAME = wxT("/lib/libc.so.6"); |
345 | static const wxChar *FUNC_NAME = wxT("strlen"); | |
f6bcfd97 BP |
346 | #else |
347 | #error "don't know how to test wxDllLoader on this platform" | |
348 | #endif | |
349 | ||
9a83f860 | 350 | wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n")); |
f6bcfd97 | 351 | |
456ae26d VZ |
352 | wxDynamicLibrary lib(LIB_NAME); |
353 | if ( !lib.IsLoaded() ) | |
f6bcfd97 | 354 | { |
9a83f860 | 355 | wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME); |
f6bcfd97 BP |
356 | } |
357 | else | |
358 | { | |
93ed8ff7 | 359 | typedef int (wxSTDCALL *wxStrlenType)(const char *); |
456ae26d | 360 | wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME); |
f6bcfd97 BP |
361 | if ( !pfnStrlen ) |
362 | { | |
9a83f860 | 363 | wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"), |
f6bcfd97 BP |
364 | FUNC_NAME, LIB_NAME); |
365 | } | |
366 | else | |
367 | { | |
9a83f860 | 368 | wxPrintf(wxT("Calling %s dynamically loaded from %s "), |
e259f83e VZ |
369 | FUNC_NAME, LIB_NAME); |
370 | ||
f6bcfd97 BP |
371 | if ( pfnStrlen("foo") != 3 ) |
372 | { | |
9a83f860 | 373 | wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n")); |
f6bcfd97 BP |
374 | } |
375 | else | |
376 | { | |
9a83f860 | 377 | wxPuts(wxT("... ok")); |
f6bcfd97 BP |
378 | } |
379 | } | |
93ed8ff7 VZ |
380 | |
381 | #ifdef __WXMSW__ | |
9a83f860 | 382 | static const wxChar *FUNC_NAME_AW = wxT("lstrlen"); |
93ed8ff7 VZ |
383 | |
384 | typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *); | |
385 | wxStrlenTypeAorW | |
386 | pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW); | |
387 | if ( !pfnStrlenAorW ) | |
388 | { | |
9a83f860 | 389 | wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"), |
93ed8ff7 VZ |
390 | FUNC_NAME_AW, LIB_NAME); |
391 | } | |
392 | else | |
393 | { | |
9a83f860 | 394 | if ( pfnStrlenAorW(wxT("foobar")) != 6 ) |
93ed8ff7 | 395 | { |
9a83f860 | 396 | wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n")); |
93ed8ff7 VZ |
397 | } |
398 | } | |
399 | #endif // __WXMSW__ | |
f6bcfd97 BP |
400 | } |
401 | } | |
402 | ||
297ebe6b VZ |
403 | #if defined(__WXMSW__) || defined(__UNIX__) |
404 | ||
405 | static void TestDllListLoaded() | |
406 | { | |
9a83f860 | 407 | wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n")); |
297ebe6b VZ |
408 | |
409 | puts("\nLoaded modules:"); | |
410 | wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded(); | |
411 | const size_t count = dlls.GetCount(); | |
412 | for ( size_t n = 0; n < count; ++n ) | |
413 | { | |
414 | const wxDynamicLibraryDetails& details = dlls[n]; | |
bf3bf677 | 415 | printf("%-45s", (const char *)details.GetPath().mb_str()); |
297ebe6b | 416 | |
92981c93 VZ |
417 | void *addr wxDUMMY_INITIALIZE(NULL); |
418 | size_t len wxDUMMY_INITIALIZE(0); | |
297ebe6b VZ |
419 | if ( details.GetAddress(&addr, &len) ) |
420 | { | |
421 | printf(" %08lx:%08lx", | |
422 | (unsigned long)addr, (unsigned long)((char *)addr + len)); | |
423 | } | |
424 | ||
bf3bf677 | 425 | printf(" %s\n", (const char *)details.GetVersion().mb_str()); |
297ebe6b VZ |
426 | } |
427 | } | |
428 | ||
429 | #endif | |
430 | ||
93ed8ff7 | 431 | #endif // TEST_DYNLIB |
f6bcfd97 | 432 | |
8fd0d89b VZ |
433 | // ---------------------------------------------------------------------------- |
434 | // wxGet/SetEnv | |
435 | // ---------------------------------------------------------------------------- | |
436 | ||
437 | #ifdef TEST_ENVIRON | |
438 | ||
e84010cf | 439 | #include "wx/utils.h" |
8fd0d89b | 440 | |
308978f6 VZ |
441 | static wxString MyGetEnv(const wxString& var) |
442 | { | |
443 | wxString val; | |
444 | if ( !wxGetEnv(var, &val) ) | |
9a83f860 | 445 | val = wxT("<empty>"); |
308978f6 | 446 | else |
9a83f860 | 447 | val = wxString(wxT('\'')) + val + wxT('\''); |
308978f6 VZ |
448 | |
449 | return val; | |
450 | } | |
451 | ||
8fd0d89b VZ |
452 | static void TestEnvironment() |
453 | { | |
9a83f860 | 454 | const wxChar *var = wxT("wxTestVar"); |
8fd0d89b | 455 | |
9a83f860 | 456 | wxPuts(wxT("*** testing environment access functions ***")); |
8fd0d89b | 457 | |
9a83f860 VZ |
458 | wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
459 | wxSetEnv(var, wxT("value for wxTestVar")); | |
460 | wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); | |
461 | wxSetEnv(var, wxT("another value")); | |
462 | wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); | |
8fd0d89b | 463 | wxUnsetEnv(var); |
9a83f860 VZ |
464 | wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str()); |
465 | wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str()); | |
8fd0d89b VZ |
466 | } |
467 | ||
468 | #endif // TEST_ENVIRON | |
469 | ||
f6bcfd97 BP |
470 | // ---------------------------------------------------------------------------- |
471 | // file | |
472 | // ---------------------------------------------------------------------------- | |
473 | ||
474 | #ifdef TEST_FILE | |
475 | ||
e84010cf GD |
476 | #include "wx/file.h" |
477 | #include "wx/ffile.h" | |
478 | #include "wx/textfile.h" | |
f6bcfd97 BP |
479 | |
480 | static void TestFileRead() | |
481 | { | |
9a83f860 | 482 | wxPuts(wxT("*** wxFile read test ***")); |
f6bcfd97 | 483 | |
9a83f860 | 484 | wxFile file(wxT("testdata.fc")); |
f6bcfd97 BP |
485 | if ( file.IsOpened() ) |
486 | { | |
9a83f860 | 487 | wxPrintf(wxT("File length: %lu\n"), file.Length()); |
f6bcfd97 | 488 | |
9a83f860 | 489 | wxPuts(wxT("File dump:\n----------")); |
f6bcfd97 | 490 | |
30984dea | 491 | static const size_t len = 1024; |
456ae26d | 492 | wxChar buf[len]; |
f6bcfd97 BP |
493 | for ( ;; ) |
494 | { | |
30984dea VZ |
495 | size_t nRead = file.Read(buf, len); |
496 | if ( nRead == (size_t)wxInvalidOffset ) | |
f6bcfd97 | 497 | { |
9a83f860 | 498 | wxPrintf(wxT("Failed to read the file.")); |
f6bcfd97 BP |
499 | break; |
500 | } | |
501 | ||
502 | fwrite(buf, nRead, 1, stdout); | |
503 | ||
504 | if ( nRead < len ) | |
505 | break; | |
506 | } | |
507 | ||
9a83f860 | 508 | wxPuts(wxT("----------")); |
f6bcfd97 BP |
509 | } |
510 | else | |
511 | { | |
9a83f860 | 512 | wxPrintf(wxT("ERROR: can't open test file.\n")); |
f6bcfd97 BP |
513 | } |
514 | ||
e9d2bb6f | 515 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
516 | } |
517 | ||
518 | static void TestTextFileRead() | |
519 | { | |
9a83f860 | 520 | wxPuts(wxT("*** wxTextFile read test ***")); |
f6bcfd97 | 521 | |
9a83f860 | 522 | wxTextFile file(wxT("testdata.fc")); |
f6bcfd97 BP |
523 | if ( file.Open() ) |
524 | { | |
9a83f860 VZ |
525 | wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount()); |
526 | wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str()); | |
3ca6a5f0 BP |
527 | |
528 | wxString s; | |
529 | ||
9a83f860 | 530 | wxPuts(wxT("\nDumping the entire file:")); |
3ca6a5f0 BP |
531 | for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() ) |
532 | { | |
9a83f860 | 533 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 534 | } |
9a83f860 | 535 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 536 | |
9a83f860 | 537 | wxPuts(wxT("\nAnd now backwards:")); |
3ca6a5f0 BP |
538 | for ( s = file.GetLastLine(); |
539 | file.GetCurrentLine() != 0; | |
540 | s = file.GetPrevLine() ) | |
541 | { | |
9a83f860 | 542 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
3ca6a5f0 | 543 | } |
9a83f860 | 544 | wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str()); |
f6bcfd97 BP |
545 | } |
546 | else | |
547 | { | |
9a83f860 | 548 | wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName()); |
f6bcfd97 BP |
549 | } |
550 | ||
e9d2bb6f | 551 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
552 | } |
553 | ||
a339970a VZ |
554 | static void TestFileCopy() |
555 | { | |
9a83f860 | 556 | wxPuts(wxT("*** Testing wxCopyFile ***")); |
a339970a | 557 | |
9a83f860 VZ |
558 | static const wxChar *filename1 = wxT("testdata.fc"); |
559 | static const wxChar *filename2 = wxT("test2"); | |
a339970a VZ |
560 | if ( !wxCopyFile(filename1, filename2) ) |
561 | { | |
9a83f860 | 562 | wxPuts(wxT("ERROR: failed to copy file")); |
a339970a VZ |
563 | } |
564 | else | |
565 | { | |
9a83f860 VZ |
566 | wxFFile f1(filename1, wxT("rb")), |
567 | f2(filename2, wxT("rb")); | |
a339970a VZ |
568 | |
569 | if ( !f1.IsOpened() || !f2.IsOpened() ) | |
570 | { | |
9a83f860 | 571 | wxPuts(wxT("ERROR: failed to open file(s)")); |
a339970a VZ |
572 | } |
573 | else | |
574 | { | |
575 | wxString s1, s2; | |
576 | if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) ) | |
577 | { | |
9a83f860 | 578 | wxPuts(wxT("ERROR: failed to read file(s)")); |
a339970a VZ |
579 | } |
580 | else | |
581 | { | |
582 | if ( (s1.length() != s2.length()) || | |
583 | (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) ) | |
584 | { | |
9a83f860 | 585 | wxPuts(wxT("ERROR: copy error!")); |
a339970a VZ |
586 | } |
587 | else | |
588 | { | |
9a83f860 | 589 | wxPuts(wxT("File was copied ok.")); |
a339970a VZ |
590 | } |
591 | } | |
592 | } | |
593 | } | |
594 | ||
595 | if ( !wxRemoveFile(filename2) ) | |
596 | { | |
9a83f860 | 597 | wxPuts(wxT("ERROR: failed to remove the file")); |
a339970a VZ |
598 | } |
599 | ||
e9d2bb6f | 600 | wxPuts(wxEmptyString); |
a339970a VZ |
601 | } |
602 | ||
59062ec1 VZ |
603 | static void TestTempFile() |
604 | { | |
9a83f860 | 605 | wxPuts(wxT("*** wxTempFile test ***")); |
59062ec1 VZ |
606 | |
607 | wxTempFile tmpFile; | |
9a83f860 | 608 | if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) ) |
59062ec1 VZ |
609 | { |
610 | if ( tmpFile.Commit() ) | |
9a83f860 | 611 | wxPuts(wxT("File committed.")); |
59062ec1 | 612 | else |
9a83f860 | 613 | wxPuts(wxT("ERROR: could't commit temp file.")); |
59062ec1 | 614 | |
9a83f860 | 615 | wxRemoveFile(wxT("test2")); |
59062ec1 VZ |
616 | } |
617 | ||
618 | wxPuts(wxEmptyString); | |
619 | } | |
620 | ||
f6bcfd97 BP |
621 | #endif // TEST_FILE |
622 | ||
844f90fb VZ |
623 | // ---------------------------------------------------------------------------- |
624 | // wxFileName | |
625 | // ---------------------------------------------------------------------------- | |
626 | ||
627 | #ifdef TEST_FILENAME | |
628 | ||
e84010cf | 629 | #include "wx/filename.h" |
844f90fb | 630 | |
e9d2bb6f | 631 | #if 0 |
5bc1deeb | 632 | static void DumpFileName(const wxChar *desc, const wxFileName& fn) |
81f25632 | 633 | { |
5bc1deeb VZ |
634 | wxPuts(desc); |
635 | ||
81f25632 VZ |
636 | wxString full = fn.GetFullPath(); |
637 | ||
638 | wxString vol, path, name, ext; | |
639 | wxFileName::SplitPath(full, &vol, &path, &name, &ext); | |
640 | ||
9a83f860 | 641 | wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"), |
81f25632 | 642 | full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str()); |
a5b7374f VZ |
643 | |
644 | wxFileName::SplitPath(full, &path, &name, &ext); | |
9a83f860 | 645 | wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"), |
a5b7374f VZ |
646 | path.c_str(), name.c_str(), ext.c_str()); |
647 | ||
9a83f860 VZ |
648 | wxPrintf(wxT("path is also:\t'%s'\n"), fn.GetPath().c_str()); |
649 | wxPrintf(wxT("with volume: \t'%s'\n"), | |
a5b7374f | 650 | fn.GetPath(wxPATH_GET_VOLUME).c_str()); |
9a83f860 | 651 | wxPrintf(wxT("with separator:\t'%s'\n"), |
a5b7374f | 652 | fn.GetPath(wxPATH_GET_SEPARATOR).c_str()); |
9a83f860 | 653 | wxPrintf(wxT("with both: \t'%s'\n"), |
a5b7374f | 654 | fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str()); |
9cb47ea2 | 655 | |
9a83f860 | 656 | wxPuts(wxT("The directories in the path are:")); |
9cb47ea2 VZ |
657 | wxArrayString dirs = fn.GetDirs(); |
658 | size_t count = dirs.GetCount(); | |
659 | for ( size_t n = 0; n < count; n++ ) | |
660 | { | |
9a83f860 | 661 | wxPrintf(wxT("\t%u: %s\n"), n, dirs[n].c_str()); |
9cb47ea2 | 662 | } |
81f25632 | 663 | } |
e9d2bb6f | 664 | #endif |
81f25632 | 665 | |
ade35f11 VZ |
666 | static void TestFileNameTemp() |
667 | { | |
9a83f860 | 668 | wxPuts(wxT("*** testing wxFileName temp file creation ***")); |
ade35f11 | 669 | |
456ae26d | 670 | static const wxChar *tmpprefixes[] = |
ade35f11 | 671 | { |
9a83f860 VZ |
672 | wxT(""), |
673 | wxT("foo"), | |
674 | wxT(".."), | |
675 | wxT("../bar"), | |
a2fa5040 | 676 | #ifdef __UNIX__ |
9a83f860 VZ |
677 | wxT("/tmp/foo"), |
678 | wxT("/tmp/foo/bar"), // this one must be an error | |
a2fa5040 | 679 | #endif // __UNIX__ |
ade35f11 VZ |
680 | }; |
681 | ||
682 | for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ ) | |
683 | { | |
684 | wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]); | |
2db991f4 VZ |
685 | if ( path.empty() ) |
686 | { | |
687 | // "error" is not in upper case because it may be ok | |
9a83f860 | 688 | wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes[n]); |
2db991f4 VZ |
689 | } |
690 | else | |
ade35f11 | 691 | { |
9a83f860 | 692 | wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"), |
ade35f11 VZ |
693 | tmpprefixes[n], path.c_str()); |
694 | ||
695 | if ( !wxRemoveFile(path) ) | |
696 | { | |
9a83f860 | 697 | wxLogWarning(wxT("Failed to remove temp file '%s'"), |
456ae26d | 698 | path.c_str()); |
ade35f11 VZ |
699 | } |
700 | } | |
701 | } | |
702 | } | |
703 | ||
0aa29b6b VZ |
704 | static void TestFileNameDirManip() |
705 | { | |
706 | // TODO: test AppendDir(), RemoveDir(), ... | |
707 | } | |
708 | ||
844f90fb VZ |
709 | static void TestFileNameComparison() |
710 | { | |
711 | // TODO! | |
712 | } | |
713 | ||
714 | static void TestFileNameOperations() | |
715 | { | |
716 | // TODO! | |
717 | } | |
718 | ||
719 | static void TestFileNameCwd() | |
720 | { | |
721 | // TODO! | |
722 | } | |
723 | ||
724 | #endif // TEST_FILENAME | |
725 | ||
d56e2b97 VZ |
726 | // ---------------------------------------------------------------------------- |
727 | // wxFileName time functions | |
728 | // ---------------------------------------------------------------------------- | |
729 | ||
730 | #ifdef TEST_FILETIME | |
731 | ||
b20edf8b WS |
732 | #include "wx/filename.h" |
733 | #include "wx/datetime.h" | |
d56e2b97 VZ |
734 | |
735 | static void TestFileGetTimes() | |
736 | { | |
9a83f860 | 737 | wxFileName fn(wxT("testdata.fc")); |
d56e2b97 | 738 | |
6dbb903b VZ |
739 | wxDateTime dtAccess, dtMod, dtCreate; |
740 | if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) ) | |
d56e2b97 | 741 | { |
9a83f860 | 742 | wxPrintf(wxT("ERROR: GetTimes() failed.\n")); |
d56e2b97 VZ |
743 | } |
744 | else | |
745 | { | |
9a83f860 | 746 | static const wxChar *fmt = wxT("%Y-%b-%d %H:%M:%S"); |
d56e2b97 | 747 | |
9a83f860 VZ |
748 | wxPrintf(wxT("File times for '%s':\n"), fn.GetFullPath().c_str()); |
749 | wxPrintf(wxT("Creation: \t%s\n"), dtCreate.Format(fmt).c_str()); | |
750 | wxPrintf(wxT("Last read: \t%s\n"), dtAccess.Format(fmt).c_str()); | |
751 | wxPrintf(wxT("Last write: \t%s\n"), dtMod.Format(fmt).c_str()); | |
d56e2b97 VZ |
752 | } |
753 | } | |
754 | ||
e9d2bb6f | 755 | #if 0 |
d56e2b97 VZ |
756 | static void TestFileSetTimes() |
757 | { | |
9a83f860 | 758 | wxFileName fn(wxT("testdata.fc")); |
d56e2b97 | 759 | |
d56e2b97 VZ |
760 | if ( !fn.Touch() ) |
761 | { | |
9a83f860 | 762 | wxPrintf(wxT("ERROR: Touch() failed.\n")); |
d56e2b97 VZ |
763 | } |
764 | } | |
e9d2bb6f | 765 | #endif |
d56e2b97 VZ |
766 | |
767 | #endif // TEST_FILETIME | |
768 | ||
ec37df57 VZ |
769 | // ---------------------------------------------------------------------------- |
770 | // wxLocale | |
771 | // ---------------------------------------------------------------------------- | |
772 | ||
773 | #ifdef TEST_LOCALE | |
774 | ||
775 | #include "wx/intl.h" | |
776 | #include "wx/utils.h" // for wxSetEnv | |
777 | ||
3e231024 FM |
778 | static wxLocale gs_localeDefault; |
779 | // NOTE: don't init it here as it needs a wxAppTraits object | |
780 | // and thus must be init-ed after creation of the wxInitializer | |
781 | // class in the main() | |
ec37df57 VZ |
782 | |
783 | // find the name of the language from its value | |
456ae26d VZ |
784 | static const wxChar *GetLangName(int lang) |
785 | { | |
786 | static const wxChar *languageNames[] = | |
787 | { | |
9a83f860 VZ |
788 | wxT("DEFAULT"), |
789 | wxT("UNKNOWN"), | |
790 | wxT("ABKHAZIAN"), | |
791 | wxT("AFAR"), | |
792 | wxT("AFRIKAANS"), | |
793 | wxT("ALBANIAN"), | |
794 | wxT("AMHARIC"), | |
795 | wxT("ARABIC"), | |
796 | wxT("ARABIC_ALGERIA"), | |
797 | wxT("ARABIC_BAHRAIN"), | |
798 | wxT("ARABIC_EGYPT"), | |
799 | wxT("ARABIC_IRAQ"), | |
800 | wxT("ARABIC_JORDAN"), | |
801 | wxT("ARABIC_KUWAIT"), | |
802 | wxT("ARABIC_LEBANON"), | |
803 | wxT("ARABIC_LIBYA"), | |
804 | wxT("ARABIC_MOROCCO"), | |
805 | wxT("ARABIC_OMAN"), | |
806 | wxT("ARABIC_QATAR"), | |
807 | wxT("ARABIC_SAUDI_ARABIA"), | |
808 | wxT("ARABIC_SUDAN"), | |
809 | wxT("ARABIC_SYRIA"), | |
810 | wxT("ARABIC_TUNISIA"), | |
811 | wxT("ARABIC_UAE"), | |
812 | wxT("ARABIC_YEMEN"), | |
813 | wxT("ARMENIAN"), | |
814 | wxT("ASSAMESE"), | |
815 | wxT("AYMARA"), | |
816 | wxT("AZERI"), | |
817 | wxT("AZERI_CYRILLIC"), | |
818 | wxT("AZERI_LATIN"), | |
819 | wxT("BASHKIR"), | |
820 | wxT("BASQUE"), | |
821 | wxT("BELARUSIAN"), | |
822 | wxT("BENGALI"), | |
823 | wxT("BHUTANI"), | |
824 | wxT("BIHARI"), | |
825 | wxT("BISLAMA"), | |
826 | wxT("BRETON"), | |
827 | wxT("BULGARIAN"), | |
828 | wxT("BURMESE"), | |
829 | wxT("CAMBODIAN"), | |
830 | wxT("CATALAN"), | |
831 | wxT("CHINESE"), | |
832 | wxT("CHINESE_SIMPLIFIED"), | |
833 | wxT("CHINESE_TRADITIONAL"), | |
834 | wxT("CHINESE_HONGKONG"), | |
835 | wxT("CHINESE_MACAU"), | |
836 | wxT("CHINESE_SINGAPORE"), | |
837 | wxT("CHINESE_TAIWAN"), | |
838 | wxT("CORSICAN"), | |
839 | wxT("CROATIAN"), | |
840 | wxT("CZECH"), | |
841 | wxT("DANISH"), | |
842 | wxT("DUTCH"), | |
843 | wxT("DUTCH_BELGIAN"), | |
844 | wxT("ENGLISH"), | |
845 | wxT("ENGLISH_UK"), | |
846 | wxT("ENGLISH_US"), | |
847 | wxT("ENGLISH_AUSTRALIA"), | |
848 | wxT("ENGLISH_BELIZE"), | |
849 | wxT("ENGLISH_BOTSWANA"), | |
850 | wxT("ENGLISH_CANADA"), | |
851 | wxT("ENGLISH_CARIBBEAN"), | |
852 | wxT("ENGLISH_DENMARK"), | |
853 | wxT("ENGLISH_EIRE"), | |
854 | wxT("ENGLISH_JAMAICA"), | |
855 | wxT("ENGLISH_NEW_ZEALAND"), | |
856 | wxT("ENGLISH_PHILIPPINES"), | |
857 | wxT("ENGLISH_SOUTH_AFRICA"), | |
858 | wxT("ENGLISH_TRINIDAD"), | |
859 | wxT("ENGLISH_ZIMBABWE"), | |
860 | wxT("ESPERANTO"), | |
861 | wxT("ESTONIAN"), | |
862 | wxT("FAEROESE"), | |
863 | wxT("FARSI"), | |
864 | wxT("FIJI"), | |
865 | wxT("FINNISH"), | |
866 | wxT("FRENCH"), | |
867 | wxT("FRENCH_BELGIAN"), | |
868 | wxT("FRENCH_CANADIAN"), | |
869 | wxT("FRENCH_LUXEMBOURG"), | |
870 | wxT("FRENCH_MONACO"), | |
871 | wxT("FRENCH_SWISS"), | |
872 | wxT("FRISIAN"), | |
873 | wxT("GALICIAN"), | |
874 | wxT("GEORGIAN"), | |
875 | wxT("GERMAN"), | |
876 | wxT("GERMAN_AUSTRIAN"), | |
877 | wxT("GERMAN_BELGIUM"), | |
878 | wxT("GERMAN_LIECHTENSTEIN"), | |
879 | wxT("GERMAN_LUXEMBOURG"), | |
880 | wxT("GERMAN_SWISS"), | |
881 | wxT("GREEK"), | |
882 | wxT("GREENLANDIC"), | |
883 | wxT("GUARANI"), | |
884 | wxT("GUJARATI"), | |
885 | wxT("HAUSA"), | |
886 | wxT("HEBREW"), | |
887 | wxT("HINDI"), | |
888 | wxT("HUNGARIAN"), | |
889 | wxT("ICELANDIC"), | |
890 | wxT("INDONESIAN"), | |
891 | wxT("INTERLINGUA"), | |
892 | wxT("INTERLINGUE"), | |
893 | wxT("INUKTITUT"), | |
894 | wxT("INUPIAK"), | |
895 | wxT("IRISH"), | |
896 | wxT("ITALIAN"), | |
897 | wxT("ITALIAN_SWISS"), | |
898 | wxT("JAPANESE"), | |
899 | wxT("JAVANESE"), | |
900 | wxT("KANNADA"), | |
901 | wxT("KASHMIRI"), | |
902 | wxT("KASHMIRI_INDIA"), | |
903 | wxT("KAZAKH"), | |
904 | wxT("KERNEWEK"), | |
905 | wxT("KINYARWANDA"), | |
906 | wxT("KIRGHIZ"), | |
907 | wxT("KIRUNDI"), | |
908 | wxT("KONKANI"), | |
909 | wxT("KOREAN"), | |
910 | wxT("KURDISH"), | |
911 | wxT("LAOTHIAN"), | |
912 | wxT("LATIN"), | |
913 | wxT("LATVIAN"), | |
914 | wxT("LINGALA"), | |
915 | wxT("LITHUANIAN"), | |
916 | wxT("MACEDONIAN"), | |
917 | wxT("MALAGASY"), | |
918 | wxT("MALAY"), | |
919 | wxT("MALAYALAM"), | |
920 | wxT("MALAY_BRUNEI_DARUSSALAM"), | |
921 | wxT("MALAY_MALAYSIA"), | |
922 | wxT("MALTESE"), | |
923 | wxT("MANIPURI"), | |
924 | wxT("MAORI"), | |
925 | wxT("MARATHI"), | |
926 | wxT("MOLDAVIAN"), | |
927 | wxT("MONGOLIAN"), | |
928 | wxT("NAURU"), | |
929 | wxT("NEPALI"), | |
930 | wxT("NEPALI_INDIA"), | |
931 | wxT("NORWEGIAN_BOKMAL"), | |
932 | wxT("NORWEGIAN_NYNORSK"), | |
933 | wxT("OCCITAN"), | |
934 | wxT("ORIYA"), | |
935 | wxT("OROMO"), | |
936 | wxT("PASHTO"), | |
937 | wxT("POLISH"), | |
938 | wxT("PORTUGUESE"), | |
939 | wxT("PORTUGUESE_BRAZILIAN"), | |
940 | wxT("PUNJABI"), | |
941 | wxT("QUECHUA"), | |
942 | wxT("RHAETO_ROMANCE"), | |
943 | wxT("ROMANIAN"), | |
944 | wxT("RUSSIAN"), | |
945 | wxT("RUSSIAN_UKRAINE"), | |
946 | wxT("SAMOAN"), | |
947 | wxT("SANGHO"), | |
948 | wxT("SANSKRIT"), | |
949 | wxT("SCOTS_GAELIC"), | |
950 | wxT("SERBIAN"), | |
951 | wxT("SERBIAN_CYRILLIC"), | |
952 | wxT("SERBIAN_LATIN"), | |
953 | wxT("SERBO_CROATIAN"), | |
954 | wxT("SESOTHO"), | |
955 | wxT("SETSWANA"), | |
956 | wxT("SHONA"), | |
957 | wxT("SINDHI"), | |
958 | wxT("SINHALESE"), | |
959 | wxT("SISWATI"), | |
960 | wxT("SLOVAK"), | |
961 | wxT("SLOVENIAN"), | |
962 | wxT("SOMALI"), | |
963 | wxT("SPANISH"), | |
964 | wxT("SPANISH_ARGENTINA"), | |
965 | wxT("SPANISH_BOLIVIA"), | |
966 | wxT("SPANISH_CHILE"), | |
967 | wxT("SPANISH_COLOMBIA"), | |
968 | wxT("SPANISH_COSTA_RICA"), | |
969 | wxT("SPANISH_DOMINICAN_REPUBLIC"), | |
970 | wxT("SPANISH_ECUADOR"), | |
971 | wxT("SPANISH_EL_SALVADOR"), | |
972 | wxT("SPANISH_GUATEMALA"), | |
973 | wxT("SPANISH_HONDURAS"), | |
974 | wxT("SPANISH_MEXICAN"), | |
975 | wxT("SPANISH_MODERN"), | |
976 | wxT("SPANISH_NICARAGUA"), | |
977 | wxT("SPANISH_PANAMA"), | |
978 | wxT("SPANISH_PARAGUAY"), | |
979 | wxT("SPANISH_PERU"), | |
980 | wxT("SPANISH_PUERTO_RICO"), | |
981 | wxT("SPANISH_URUGUAY"), | |
982 | wxT("SPANISH_US"), | |
983 | wxT("SPANISH_VENEZUELA"), | |
984 | wxT("SUNDANESE"), | |
985 | wxT("SWAHILI"), | |
986 | wxT("SWEDISH"), | |
987 | wxT("SWEDISH_FINLAND"), | |
988 | wxT("TAGALOG"), | |
989 | wxT("TAJIK"), | |
990 | wxT("TAMIL"), | |
991 | wxT("TATAR"), | |
992 | wxT("TELUGU"), | |
993 | wxT("THAI"), | |
994 | wxT("TIBETAN"), | |
995 | wxT("TIGRINYA"), | |
996 | wxT("TONGA"), | |
997 | wxT("TSONGA"), | |
998 | wxT("TURKISH"), | |
999 | wxT("TURKMEN"), | |
1000 | wxT("TWI"), | |
1001 | wxT("UIGHUR"), | |
1002 | wxT("UKRAINIAN"), | |
1003 | wxT("URDU"), | |
1004 | wxT("URDU_INDIA"), | |
1005 | wxT("URDU_PAKISTAN"), | |
1006 | wxT("UZBEK"), | |
1007 | wxT("UZBEK_CYRILLIC"), | |
1008 | wxT("UZBEK_LATIN"), | |
1009 | wxT("VIETNAMESE"), | |
1010 | wxT("VOLAPUK"), | |
1011 | wxT("WELSH"), | |
1012 | wxT("WOLOF"), | |
1013 | wxT("XHOSA"), | |
1014 | wxT("YIDDISH"), | |
1015 | wxT("YORUBA"), | |
1016 | wxT("ZHUANG"), | |
1017 | wxT("ZULU"), | |
ec37df57 VZ |
1018 | }; |
1019 | ||
1020 | if ( (size_t)lang < WXSIZEOF(languageNames) ) | |
1021 | return languageNames[lang]; | |
1022 | else | |
9a83f860 | 1023 | return wxT("INVALID"); |
ec37df57 VZ |
1024 | } |
1025 | ||
1026 | static void TestDefaultLang() | |
1027 | { | |
9a83f860 | 1028 | wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***")); |
ec37df57 | 1029 | |
3e231024 FM |
1030 | gs_localeDefault.Init(wxLANGUAGE_ENGLISH); |
1031 | ||
ec37df57 VZ |
1032 | static const wxChar *langStrings[] = |
1033 | { | |
1034 | NULL, // system default | |
9a83f860 VZ |
1035 | wxT("C"), |
1036 | wxT("fr"), | |
1037 | wxT("fr_FR"), | |
1038 | wxT("en"), | |
1039 | wxT("en_GB"), | |
1040 | wxT("en_US"), | |
1041 | wxT("de_DE.iso88591"), | |
1042 | wxT("german"), | |
1043 | wxT("?"), // invalid lang spec | |
1044 | wxT("klingonese"), // I bet on some systems it does exist... | |
ec37df57 VZ |
1045 | }; |
1046 | ||
9a83f860 | 1047 | wxPrintf(wxT("The default system encoding is %s (%d)\n"), |
dccce9ea VZ |
1048 | wxLocale::GetSystemEncodingName().c_str(), |
1049 | wxLocale::GetSystemEncoding()); | |
1050 | ||
ec37df57 VZ |
1051 | for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ ) |
1052 | { | |
456ae26d | 1053 | const wxChar *langStr = langStrings[n]; |
ec37df57 | 1054 | if ( langStr ) |
dccce9ea VZ |
1055 | { |
1056 | // FIXME: this doesn't do anything at all under Windows, we need | |
1057 | // to create a new wxLocale! | |
9a83f860 | 1058 | wxSetEnv(wxT("LC_ALL"), langStr); |
dccce9ea | 1059 | } |
ec37df57 VZ |
1060 | |
1061 | int lang = gs_localeDefault.GetSystemLanguage(); | |
9a83f860 VZ |
1062 | wxPrintf(wxT("Locale for '%s' is %s.\n"), |
1063 | langStr ? langStr : wxT("system default"), GetLangName(lang)); | |
ec37df57 VZ |
1064 | } |
1065 | } | |
1066 | ||
1067 | #endif // TEST_LOCALE | |
1068 | ||
696e1ea0 VZ |
1069 | // ---------------------------------------------------------------------------- |
1070 | // MIME types | |
1071 | // ---------------------------------------------------------------------------- | |
1072 | ||
1073 | #ifdef TEST_MIME | |
1074 | ||
e84010cf | 1075 | #include "wx/mimetype.h" |
696e1ea0 VZ |
1076 | |
1077 | static void TestMimeEnum() | |
1078 | { | |
9a83f860 | 1079 | wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n")); |
a6c65e88 | 1080 | |
696e1ea0 VZ |
1081 | wxArrayString mimetypes; |
1082 | ||
39189b9d | 1083 | size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes); |
696e1ea0 | 1084 | |
9a83f860 | 1085 | wxPrintf(wxT("*** All %u known filetypes: ***\n"), count); |
696e1ea0 VZ |
1086 | |
1087 | wxArrayString exts; | |
1088 | wxString desc; | |
1089 | ||
1090 | for ( size_t n = 0; n < count; n++ ) | |
1091 | { | |
39189b9d VZ |
1092 | wxFileType *filetype = |
1093 | wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]); | |
696e1ea0 | 1094 | if ( !filetype ) |
c61f4f6d | 1095 | { |
9a83f860 | 1096 | wxPrintf(wxT("nothing known about the filetype '%s'!\n"), |
97e0ceea | 1097 | mimetypes[n].c_str()); |
696e1ea0 | 1098 | continue; |
c61f4f6d VZ |
1099 | } |
1100 | ||
696e1ea0 VZ |
1101 | filetype->GetDescription(&desc); |
1102 | filetype->GetExtensions(exts); | |
1103 | ||
299fcbfe VZ |
1104 | filetype->GetIcon(NULL); |
1105 | ||
696e1ea0 VZ |
1106 | wxString extsAll; |
1107 | for ( size_t e = 0; e < exts.GetCount(); e++ ) | |
1108 | { | |
1109 | if ( e > 0 ) | |
9a83f860 | 1110 | extsAll << wxT(", "); |
696e1ea0 VZ |
1111 | extsAll += exts[e]; |
1112 | } | |
1113 | ||
9a83f860 | 1114 | wxPrintf(wxT("\t%s: %s (%s)\n"), |
54acce90 | 1115 | mimetypes[n].c_str(), desc.c_str(), extsAll.c_str()); |
696e1ea0 | 1116 | } |
39189b9d | 1117 | |
e9d2bb6f | 1118 | wxPuts(wxEmptyString); |
696e1ea0 VZ |
1119 | } |
1120 | ||
f6bcfd97 BP |
1121 | static void TestMimeFilename() |
1122 | { | |
9a83f860 | 1123 | wxPuts(wxT("*** Testing MIME type from filename query ***\n")); |
f6bcfd97 BP |
1124 | |
1125 | static const wxChar *filenames[] = | |
1126 | { | |
9a83f860 VZ |
1127 | wxT("readme.txt"), |
1128 | wxT("document.pdf"), | |
1129 | wxT("image.gif"), | |
1130 | wxT("picture.jpeg"), | |
f6bcfd97 BP |
1131 | }; |
1132 | ||
1133 | for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) | |
1134 | { | |
1135 | const wxString fname = filenames[n]; | |
9a83f860 | 1136 | wxString ext = fname.AfterLast(wxT('.')); |
39189b9d | 1137 | wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); |
f6bcfd97 BP |
1138 | if ( !ft ) |
1139 | { | |
9a83f860 | 1140 | wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext.c_str()); |
f6bcfd97 BP |
1141 | } |
1142 | else | |
1143 | { | |
1144 | wxString desc; | |
1145 | if ( !ft->GetDescription(&desc) ) | |
9a83f860 | 1146 | desc = wxT("<no description>"); |
f6bcfd97 BP |
1147 | |
1148 | wxString cmd; | |
1149 | if ( !ft->GetOpenCommand(&cmd, | |
e9d2bb6f | 1150 | wxFileType::MessageParameters(fname, wxEmptyString)) ) |
9a83f860 | 1151 | cmd = wxT("<no command available>"); |
7aeebdcd | 1152 | else |
9a83f860 | 1153 | cmd = wxString(wxT('"')) + cmd + wxT('"'); |
f6bcfd97 | 1154 | |
9a83f860 | 1155 | wxPrintf(wxT("To open %s (%s) do %s.\n"), |
f6bcfd97 BP |
1156 | fname.c_str(), desc.c_str(), cmd.c_str()); |
1157 | ||
1158 | delete ft; | |
1159 | } | |
1160 | } | |
39189b9d | 1161 | |
e9d2bb6f | 1162 | wxPuts(wxEmptyString); |
f6bcfd97 BP |
1163 | } |
1164 | ||
c19c2f6e VZ |
1165 | // these tests were broken by wxMimeTypesManager changes, temporarily disabling |
1166 | #if 0 | |
1167 | ||
1168 | static void TestMimeOverride() | |
1169 | { | |
9a83f860 | 1170 | wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n")); |
c19c2f6e | 1171 | |
9a83f860 VZ |
1172 | static const wxChar *mailcap = wxT("/tmp/mailcap"); |
1173 | static const wxChar *mimetypes = wxT("/tmp/mime.types"); | |
c19c2f6e VZ |
1174 | |
1175 | if ( wxFile::Exists(mailcap) ) | |
9a83f860 | 1176 | wxPrintf(wxT("Loading mailcap from '%s': %s\n"), |
c19c2f6e | 1177 | mailcap, |
9a83f860 | 1178 | wxTheMimeTypesManager->ReadMailcap(mailcap) ? wxT("ok") : wxT("ERROR")); |
c19c2f6e | 1179 | else |
9a83f860 | 1180 | wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), |
c19c2f6e VZ |
1181 | mailcap); |
1182 | ||
1183 | if ( wxFile::Exists(mimetypes) ) | |
9a83f860 | 1184 | wxPrintf(wxT("Loading mime.types from '%s': %s\n"), |
c19c2f6e | 1185 | mimetypes, |
9a83f860 | 1186 | wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? wxT("ok") : wxT("ERROR")); |
c19c2f6e | 1187 | else |
9a83f860 | 1188 | wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), |
c19c2f6e VZ |
1189 | mimetypes); |
1190 | ||
1191 | wxPuts(wxEmptyString); | |
1192 | } | |
1193 | ||
c7ce8392 VZ |
1194 | static void TestMimeAssociate() |
1195 | { | |
9a83f860 | 1196 | wxPuts(wxT("*** Testing creation of filetype association ***\n")); |
c7ce8392 | 1197 | |
a6c65e88 | 1198 | wxFileTypeInfo ftInfo( |
9a83f860 VZ |
1199 | wxT("application/x-xyz"), |
1200 | wxT("xyzview '%s'"), // open cmd | |
1201 | wxT(""), // print cmd | |
1202 | wxT("XYZ File"), // description | |
1203 | wxT(".xyz"), // extensions | |
b61af837 | 1204 | wxNullPtr // end of extensions |
a6c65e88 | 1205 | ); |
9a83f860 | 1206 | ftInfo.SetShortDesc(wxT("XYZFile")); // used under Win32 only |
a6c65e88 | 1207 | |
39189b9d | 1208 | wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo); |
c7ce8392 VZ |
1209 | if ( !ft ) |
1210 | { | |
9a83f860 | 1211 | wxPuts(wxT("ERROR: failed to create association!")); |
c7ce8392 VZ |
1212 | } |
1213 | else | |
1214 | { | |
a6c65e88 | 1215 | // TODO: read it back |
c7ce8392 VZ |
1216 | delete ft; |
1217 | } | |
39189b9d | 1218 | |
e9d2bb6f | 1219 | wxPuts(wxEmptyString); |
c7ce8392 VZ |
1220 | } |
1221 | ||
c19c2f6e VZ |
1222 | #endif // 0 |
1223 | ||
696e1ea0 VZ |
1224 | #endif // TEST_MIME |
1225 | ||
af266e5b VZ |
1226 | // ---------------------------------------------------------------------------- |
1227 | // module dependencies feature | |
1228 | // ---------------------------------------------------------------------------- | |
1229 | ||
1230 | #ifdef TEST_MODULE | |
1231 | ||
1232 | #include "wx/module.h" | |
1233 | ||
1234 | class wxTestModule : public wxModule | |
1235 | { | |
1236 | protected: | |
9a83f860 VZ |
1237 | virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; } |
1238 | virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); } | |
af266e5b VZ |
1239 | }; |
1240 | ||
1241 | class wxTestModuleA : public wxTestModule | |
1242 | { | |
1243 | public: | |
1244 | wxTestModuleA(); | |
1245 | private: | |
1246 | DECLARE_DYNAMIC_CLASS(wxTestModuleA) | |
1247 | }; | |
1248 | ||
1249 | class wxTestModuleB : public wxTestModule | |
1250 | { | |
1251 | public: | |
1252 | wxTestModuleB(); | |
1253 | private: | |
1254 | DECLARE_DYNAMIC_CLASS(wxTestModuleB) | |
1255 | }; | |
1256 | ||
1257 | class wxTestModuleC : public wxTestModule | |
1258 | { | |
1259 | public: | |
1260 | wxTestModuleC(); | |
1261 | private: | |
1262 | DECLARE_DYNAMIC_CLASS(wxTestModuleC) | |
1263 | }; | |
1264 | ||
1265 | class wxTestModuleD : public wxTestModule | |
1266 | { | |
1267 | public: | |
1268 | wxTestModuleD(); | |
1269 | private: | |
1270 | DECLARE_DYNAMIC_CLASS(wxTestModuleD) | |
1271 | }; | |
1272 | ||
1273 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC, wxModule) | |
1274 | wxTestModuleC::wxTestModuleC() | |
1275 | { | |
1276 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1277 | } | |
1278 | ||
1279 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA, wxModule) | |
1280 | wxTestModuleA::wxTestModuleA() | |
1281 | { | |
1282 | AddDependency(CLASSINFO(wxTestModuleB)); | |
1283 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1284 | } | |
1285 | ||
1286 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD, wxModule) | |
1287 | wxTestModuleD::wxTestModuleD() | |
1288 | { | |
1289 | } | |
1290 | ||
1291 | IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB, wxModule) | |
1292 | wxTestModuleB::wxTestModuleB() | |
1293 | { | |
1294 | AddDependency(CLASSINFO(wxTestModuleD)); | |
1295 | AddDependency(CLASSINFO(wxTestModuleC)); | |
1296 | } | |
1297 | ||
1298 | #endif // TEST_MODULE | |
1299 | ||
89e60357 VZ |
1300 | // ---------------------------------------------------------------------------- |
1301 | // misc information functions | |
1302 | // ---------------------------------------------------------------------------- | |
1303 | ||
1304 | #ifdef TEST_INFO_FUNCTIONS | |
1305 | ||
e84010cf | 1306 | #include "wx/utils.h" |
89e60357 | 1307 | |
0219fd2f | 1308 | #if TEST_INTERACTIVE |
3a994742 VZ |
1309 | static void TestDiskInfo() |
1310 | { | |
9a83f860 | 1311 | wxPuts(wxT("*** Testing wxGetDiskSpace() ***")); |
3a994742 VZ |
1312 | |
1313 | for ( ;; ) | |
1314 | { | |
456ae26d | 1315 | wxChar pathname[128]; |
9a83f860 | 1316 | wxPrintf(wxT("\nEnter a directory name: ")); |
456ae26d | 1317 | if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) ) |
3a994742 VZ |
1318 | break; |
1319 | ||
1320 | // kill the last '\n' | |
456ae26d | 1321 | pathname[wxStrlen(pathname) - 1] = 0; |
3a994742 VZ |
1322 | |
1323 | wxLongLong total, free; | |
1324 | if ( !wxGetDiskSpace(pathname, &total, &free) ) | |
1325 | { | |
9a83f860 | 1326 | wxPuts(wxT("ERROR: wxGetDiskSpace failed.")); |
3a994742 VZ |
1327 | } |
1328 | else | |
1329 | { | |
9a83f860 | 1330 | wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"), |
eadd7bd2 VZ |
1331 | (total / 1024).ToString().c_str(), |
1332 | (free / 1024).ToString().c_str(), | |
3a994742 VZ |
1333 | pathname); |
1334 | } | |
1335 | } | |
1336 | } | |
0219fd2f | 1337 | #endif // TEST_INTERACTIVE |
3a994742 | 1338 | |
89e60357 VZ |
1339 | static void TestOsInfo() |
1340 | { | |
9a83f860 | 1341 | wxPuts(wxT("*** Testing OS info functions ***\n")); |
89e60357 VZ |
1342 | |
1343 | int major, minor; | |
1344 | wxGetOsVersion(&major, &minor); | |
9a83f860 | 1345 | wxPrintf(wxT("Running under: %s, version %d.%d\n"), |
89e60357 VZ |
1346 | wxGetOsDescription().c_str(), major, minor); |
1347 | ||
9a83f860 | 1348 | wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong()); |
89e60357 | 1349 | |
9a83f860 | 1350 | wxPrintf(wxT("Host name is %s (%s).\n"), |
89e60357 | 1351 | wxGetHostName().c_str(), wxGetFullHostName().c_str()); |
bd3277fe | 1352 | |
e9d2bb6f | 1353 | wxPuts(wxEmptyString); |
89e60357 VZ |
1354 | } |
1355 | ||
8bb6b2c0 VZ |
1356 | static void TestPlatformInfo() |
1357 | { | |
9a83f860 | 1358 | wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n")); |
8bb6b2c0 VZ |
1359 | |
1360 | // get this platform | |
1361 | wxPlatformInfo plat; | |
1362 | ||
9a83f860 VZ |
1363 | wxPrintf(wxT("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str()); |
1364 | wxPrintf(wxT("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str()); | |
1365 | wxPrintf(wxT("Port ID name is: %s\n"), plat.GetPortIdName().c_str()); | |
1366 | wxPrintf(wxT("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str()); | |
1367 | wxPrintf(wxT("Architecture is: %s\n"), plat.GetArchName().c_str()); | |
1368 | wxPrintf(wxT("Endianness is: %s\n"), plat.GetEndiannessName().c_str()); | |
8bb6b2c0 VZ |
1369 | |
1370 | wxPuts(wxEmptyString); | |
1371 | } | |
1372 | ||
89e60357 VZ |
1373 | static void TestUserInfo() |
1374 | { | |
9a83f860 | 1375 | wxPuts(wxT("*** Testing user info functions ***\n")); |
89e60357 | 1376 | |
9a83f860 VZ |
1377 | wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str()); |
1378 | wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str()); | |
1379 | wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); | |
1380 | wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str()); | |
bd3277fe | 1381 | |
e9d2bb6f | 1382 | wxPuts(wxEmptyString); |
89e60357 VZ |
1383 | } |
1384 | ||
1385 | #endif // TEST_INFO_FUNCTIONS | |
1386 | ||
39189b9d VZ |
1387 | // ---------------------------------------------------------------------------- |
1388 | // path list | |
1389 | // ---------------------------------------------------------------------------- | |
1390 | ||
1391 | #ifdef TEST_PATHLIST | |
1392 | ||
ee3ef281 | 1393 | #ifdef __UNIX__ |
9a83f860 | 1394 | #define CMD_IN_PATH wxT("ls") |
ee3ef281 | 1395 | #else |
9a83f860 | 1396 | #define CMD_IN_PATH wxT("command.com") |
ee3ef281 VZ |
1397 | #endif |
1398 | ||
39189b9d VZ |
1399 | static void TestPathList() |
1400 | { | |
9a83f860 | 1401 | wxPuts(wxT("*** Testing wxPathList ***\n")); |
39189b9d VZ |
1402 | |
1403 | wxPathList pathlist; | |
9a83f860 | 1404 | pathlist.AddEnvList(wxT("PATH")); |
ee3ef281 | 1405 | wxString path = pathlist.FindValidPath(CMD_IN_PATH); |
39189b9d VZ |
1406 | if ( path.empty() ) |
1407 | { | |
9a83f860 | 1408 | wxPrintf(wxT("ERROR: command not found in the path.\n")); |
39189b9d VZ |
1409 | } |
1410 | else | |
1411 | { | |
9a83f860 | 1412 | wxPrintf(wxT("Command found in the path as '%s'.\n"), path.c_str()); |
39189b9d VZ |
1413 | } |
1414 | } | |
1415 | ||
1416 | #endif // TEST_PATHLIST | |
1417 | ||
07a56e45 VZ |
1418 | // ---------------------------------------------------------------------------- |
1419 | // regular expressions | |
1420 | // ---------------------------------------------------------------------------- | |
1421 | ||
eb835127 | 1422 | #if defined TEST_REGEX && TEST_INTERACTIVE |
07a56e45 | 1423 | |
e84010cf | 1424 | #include "wx/regex.h" |
07a56e45 | 1425 | |
07a56e45 VZ |
1426 | static void TestRegExInteractive() |
1427 | { | |
9a83f860 | 1428 | wxPuts(wxT("*** Testing RE interactively ***")); |
07a56e45 VZ |
1429 | |
1430 | for ( ;; ) | |
1431 | { | |
456ae26d | 1432 | wxChar pattern[128]; |
9a83f860 | 1433 | wxPrintf(wxT("\nEnter a pattern: ")); |
456ae26d | 1434 | if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) ) |
07a56e45 VZ |
1435 | break; |
1436 | ||
1437 | // kill the last '\n' | |
456ae26d | 1438 | pattern[wxStrlen(pattern) - 1] = 0; |
07a56e45 VZ |
1439 | |
1440 | wxRegEx re; | |
1441 | if ( !re.Compile(pattern) ) | |
1442 | { | |
1443 | continue; | |
1444 | } | |
1445 | ||
456ae26d | 1446 | wxChar text[128]; |
07a56e45 VZ |
1447 | for ( ;; ) |
1448 | { | |
9a83f860 | 1449 | wxPrintf(wxT("Enter text to match: ")); |
456ae26d | 1450 | if ( !wxFgets(text, WXSIZEOF(text), stdin) ) |
07a56e45 VZ |
1451 | break; |
1452 | ||
1453 | // kill the last '\n' | |
456ae26d | 1454 | text[wxStrlen(text) - 1] = 0; |
07a56e45 VZ |
1455 | |
1456 | if ( !re.Matches(text) ) | |
1457 | { | |
9a83f860 | 1458 | wxPrintf(wxT("No match.\n")); |
07a56e45 VZ |
1459 | } |
1460 | else | |
1461 | { | |
9a83f860 | 1462 | wxPrintf(wxT("Pattern matches at '%s'\n"), re.GetMatch(text).c_str()); |
07a56e45 VZ |
1463 | |
1464 | size_t start, len; | |
1465 | for ( size_t n = 1; ; n++ ) | |
1466 | { | |
1467 | if ( !re.GetMatch(&start, &len, n) ) | |
1468 | { | |
1469 | break; | |
1470 | } | |
1471 | ||
9a83f860 | 1472 | wxPrintf(wxT("Subexpr %u matched '%s'\n"), |
456ae26d | 1473 | n, wxString(text + start, len).c_str()); |
07a56e45 VZ |
1474 | } |
1475 | } | |
1476 | } | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | #endif // TEST_REGEX | |
1481 | ||
b92fd37c VZ |
1482 | // ---------------------------------------------------------------------------- |
1483 | // FTP | |
1484 | // ---------------------------------------------------------------------------- | |
1485 | ||
2e907fab VZ |
1486 | #ifdef TEST_FTP |
1487 | ||
e84010cf | 1488 | #include "wx/protocol/ftp.h" |
0576cd9e | 1489 | #include "wx/protocol/log.h" |
2e907fab | 1490 | |
b92fd37c VZ |
1491 | #define FTP_ANONYMOUS |
1492 | ||
d6accb8c FM |
1493 | static wxFTP *ftp; |
1494 | ||
b92fd37c | 1495 | #ifdef FTP_ANONYMOUS |
ec0e0939 | 1496 | static const wxChar *hostname = wxT("ftp.wxwidgets.org"); |
9a83f860 VZ |
1497 | static const wxChar *directory = wxT("/pub"); |
1498 | static const wxChar *filename = wxT("welcome.msg"); | |
b92fd37c | 1499 | #else |
ec0e0939 | 1500 | static const wxChar *hostname = "localhost"; |
9a83f860 VZ |
1501 | static const wxChar *directory = wxT("/etc"); |
1502 | static const wxChar *filename = wxT("issue"); | |
b92fd37c VZ |
1503 | #endif |
1504 | ||
1505 | static bool TestFtpConnect() | |
8e907a13 | 1506 | { |
9a83f860 | 1507 | wxPuts(wxT("*** Testing FTP connect ***")); |
8e907a13 | 1508 | |
b92fd37c | 1509 | #ifdef FTP_ANONYMOUS |
9a83f860 | 1510 | wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname); |
b92fd37c | 1511 | #else // !FTP_ANONYMOUS |
456ae26d VZ |
1512 | wxChar user[256]; |
1513 | wxFgets(user, WXSIZEOF(user), stdin); | |
1514 | user[wxStrlen(user) - 1] = '\0'; // chop off '\n' | |
d6accb8c | 1515 | ftp->SetUser(user); |
b92fd37c | 1516 | |
456ae26d | 1517 | wxChar password[256]; |
9a83f860 | 1518 | wxPrintf(wxT("Password for %s: "), password); |
456ae26d VZ |
1519 | wxFgets(password, WXSIZEOF(password), stdin); |
1520 | password[wxStrlen(password) - 1] = '\0'; // chop off '\n' | |
d6accb8c | 1521 | ftp->SetPassword(password); |
b92fd37c | 1522 | |
9a83f860 | 1523 | wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname, user); |
b92fd37c VZ |
1524 | #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS |
1525 | ||
d6accb8c | 1526 | if ( !ftp->Connect(hostname) ) |
b92fd37c | 1527 | { |
9a83f860 | 1528 | wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname); |
b92fd37c | 1529 | |
cab8f76e | 1530 | return false; |
b92fd37c VZ |
1531 | } |
1532 | else | |
1533 | { | |
9a83f860 | 1534 | wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"), |
d6accb8c FM |
1535 | hostname, ftp->Pwd().c_str()); |
1536 | ftp->Close(); | |
b92fd37c VZ |
1537 | } |
1538 | ||
cab8f76e | 1539 | return true; |
b92fd37c | 1540 | } |
b1229561 | 1541 | |
30ccbb89 | 1542 | #if TEST_INTERACTIVE |
b92fd37c VZ |
1543 | static void TestFtpInteractive() |
1544 | { | |
9a83f860 | 1545 | wxPuts(wxT("\n*** Interactive wxFTP test ***")); |
b92fd37c | 1546 | |
456ae26d | 1547 | wxChar buf[128]; |
b92fd37c VZ |
1548 | |
1549 | for ( ;; ) | |
1550 | { | |
ec0e0939 | 1551 | wxPrintf(wxT("Enter FTP command (or 'quit' to escape): ")); |
456ae26d | 1552 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) |
b92fd37c VZ |
1553 | break; |
1554 | ||
1555 | // kill the last '\n' | |
456ae26d | 1556 | buf[wxStrlen(buf) - 1] = 0; |
b92fd37c VZ |
1557 | |
1558 | // special handling of LIST and NLST as they require data connection | |
1559 | wxString start(buf, 4); | |
1560 | start.MakeUpper(); | |
9a83f860 | 1561 | if ( start == wxT("LIST") || start == wxT("NLST") ) |
8e907a13 | 1562 | { |
b92fd37c | 1563 | wxString wildcard; |
456ae26d | 1564 | if ( wxStrlen(buf) > 4 ) |
b92fd37c | 1565 | wildcard = buf + 5; |
8e907a13 | 1566 | |
b92fd37c | 1567 | wxArrayString files; |
9a83f860 | 1568 | if ( !ftp->GetList(files, wildcard, start == wxT("LIST")) ) |
8e907a13 | 1569 | { |
9a83f860 | 1570 | wxPrintf(wxT("ERROR: failed to get %s of files\n"), start.c_str()); |
8e907a13 VZ |
1571 | } |
1572 | else | |
1573 | { | |
9a83f860 | 1574 | wxPrintf(wxT("--- %s of '%s' under '%s':\n"), |
d6accb8c | 1575 | start.c_str(), wildcard.c_str(), ftp->Pwd().c_str()); |
b92fd37c VZ |
1576 | size_t count = files.GetCount(); |
1577 | for ( size_t n = 0; n < count; n++ ) | |
1578 | { | |
9a83f860 | 1579 | wxPrintf(wxT("\t%s\n"), files[n].c_str()); |
b92fd37c | 1580 | } |
9a83f860 | 1581 | wxPuts(wxT("--- End of the file list")); |
8e907a13 | 1582 | } |
2e907fab | 1583 | } |
ec0e0939 FM |
1584 | else if ( start == wxT("QUIT") ) |
1585 | { | |
1586 | break; // get out of here! | |
1587 | } | |
b92fd37c | 1588 | else // !list |
2e907fab | 1589 | { |
d6accb8c | 1590 | wxChar ch = ftp->SendCommand(buf); |
9a83f860 | 1591 | wxPrintf(wxT("Command %s"), ch ? wxT("succeeded") : wxT("failed")); |
b92fd37c VZ |
1592 | if ( ch ) |
1593 | { | |
9a83f860 | 1594 | wxPrintf(wxT(" (return code %c)"), ch); |
b92fd37c | 1595 | } |
2e907fab | 1596 | |
9a83f860 | 1597 | wxPrintf(wxT(", server reply:\n%s\n\n"), ftp->GetLastResult().c_str()); |
2e907fab | 1598 | } |
2c8e4738 | 1599 | } |
b92fd37c | 1600 | |
30ccbb89 | 1601 | wxPuts(wxT("\n")); |
2c8e4738 | 1602 | } |
30ccbb89 | 1603 | #endif // TEST_INTERACTIVE |
2e907fab | 1604 | #endif // TEST_FTP |
2c8e4738 | 1605 | |
eaff0f0d VZ |
1606 | // ---------------------------------------------------------------------------- |
1607 | // stack backtrace | |
1608 | // ---------------------------------------------------------------------------- | |
1609 | ||
1610 | #ifdef TEST_STACKWALKER | |
1611 | ||
74e2116a MB |
1612 | #if wxUSE_STACKWALKER |
1613 | ||
eaff0f0d VZ |
1614 | #include "wx/stackwalk.h" |
1615 | ||
1616 | class StackDump : public wxStackWalker | |
1617 | { | |
1618 | public: | |
1619 | StackDump(const char *argv0) | |
1620 | : wxStackWalker(argv0) | |
1621 | { | |
1622 | } | |
1623 | ||
eb835127 | 1624 | virtual void Walk(size_t skip = 1, size_t maxdepth = wxSTACKWALKER_MAX_DEPTH) |
eaff0f0d | 1625 | { |
9a83f860 | 1626 | wxPuts(wxT("Stack dump:")); |
eaff0f0d | 1627 | |
eb835127 | 1628 | wxStackWalker::Walk(skip, maxdepth); |
eaff0f0d VZ |
1629 | } |
1630 | ||
1631 | protected: | |
1632 | virtual void OnStackFrame(const wxStackFrame& frame) | |
1633 | { | |
bf3bf677 | 1634 | printf("[%2d] ", (int) frame.GetLevel()); |
eaff0f0d VZ |
1635 | |
1636 | wxString name = frame.GetName(); | |
1637 | if ( !name.empty() ) | |
1638 | { | |
bf3bf677 | 1639 | printf("%-20.40s", (const char*)name.mb_str()); |
eaff0f0d VZ |
1640 | } |
1641 | else | |
1642 | { | |
1643 | printf("0x%08lx", (unsigned long)frame.GetAddress()); | |
1644 | } | |
1645 | ||
1646 | if ( frame.HasSourceLocation() ) | |
1647 | { | |
1648 | printf("\t%s:%d", | |
bf3bf677 VZ |
1649 | (const char*)frame.GetFileName().mb_str(), |
1650 | (int)frame.GetLine()); | |
eaff0f0d VZ |
1651 | } |
1652 | ||
1653 | puts(""); | |
1654 | ||
1655 | wxString type, val; | |
1656 | for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ ) | |
1657 | { | |
3e231024 FM |
1658 | printf("\t%s %s = %s\n", (const char*)type.mb_str(), |
1659 | (const char*)name.mb_str(), | |
bf3bf677 | 1660 | (const char*)val.mb_str()); |
eaff0f0d VZ |
1661 | } |
1662 | } | |
1663 | }; | |
1664 | ||
1665 | static void TestStackWalk(const char *argv0) | |
1666 | { | |
30ccbb89 | 1667 | wxPuts(wxT("*** Testing wxStackWalker ***")); |
eaff0f0d VZ |
1668 | |
1669 | StackDump dump(argv0); | |
1670 | dump.Walk(); | |
ec0e0939 FM |
1671 | |
1672 | wxPuts("\n"); | |
eaff0f0d VZ |
1673 | } |
1674 | ||
74e2116a MB |
1675 | #endif // wxUSE_STACKWALKER |
1676 | ||
eaff0f0d VZ |
1677 | #endif // TEST_STACKWALKER |
1678 | ||
af33b199 VZ |
1679 | // ---------------------------------------------------------------------------- |
1680 | // standard paths | |
1681 | // ---------------------------------------------------------------------------- | |
1682 | ||
1683 | #ifdef TEST_STDPATHS | |
1684 | ||
1685 | #include "wx/stdpaths.h" | |
6f207e66 | 1686 | #include "wx/wxchar.h" // wxPrintf |
af33b199 VZ |
1687 | |
1688 | static void TestStandardPaths() | |
1689 | { | |
30ccbb89 | 1690 | wxPuts(wxT("*** Testing wxStandardPaths ***")); |
af33b199 | 1691 | |
9a83f860 | 1692 | wxTheApp->SetAppName(wxT("console")); |
af33b199 | 1693 | |
5ba95b79 | 1694 | wxStandardPathsBase& stdp = wxStandardPaths::Get(); |
9a83f860 VZ |
1695 | wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str()); |
1696 | wxPrintf(wxT("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str()); | |
1697 | wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str()); | |
1698 | wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str()); | |
1699 | wxPrintf(wxT("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str()); | |
1700 | wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str()); | |
1701 | wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str()); | |
1702 | wxPrintf(wxT("Executable path:\t%s\n"), stdp.GetExecutablePath().c_str()); | |
1703 | wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str()); | |
1704 | wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str()); | |
1705 | wxPrintf(wxT("Localized res. dir:\t%s\n"), | |
1706 | stdp.GetLocalizedResourcesDir(wxT("fr")).c_str()); | |
1707 | wxPrintf(wxT("Message catalogs dir:\t%s\n"), | |
3af9f2de VZ |
1708 | stdp.GetLocalizedResourcesDir |
1709 | ( | |
9a83f860 | 1710 | wxT("fr"), |
3af9f2de VZ |
1711 | wxStandardPaths::ResourceCat_Messages |
1712 | ).c_str()); | |
ec0e0939 FM |
1713 | |
1714 | wxPuts("\n"); | |
af33b199 VZ |
1715 | } |
1716 | ||
1717 | #endif // TEST_STDPATHS | |
1718 | ||
0e2c5534 VZ |
1719 | // ---------------------------------------------------------------------------- |
1720 | // wxVolume tests | |
1721 | // ---------------------------------------------------------------------------- | |
1722 | ||
ba6ea19e | 1723 | #if !defined(__WIN32__) || !wxUSE_FSVOLUME |
0e2c5534 VZ |
1724 | #undef TEST_VOLUME |
1725 | #endif | |
1726 | ||
1727 | #ifdef TEST_VOLUME | |
1728 | ||
1729 | #include "wx/volume.h" | |
1730 | ||
1731 | static const wxChar *volumeKinds[] = | |
1732 | { | |
9a83f860 VZ |
1733 | wxT("floppy"), |
1734 | wxT("hard disk"), | |
1735 | wxT("CD-ROM"), | |
1736 | wxT("DVD-ROM"), | |
1737 | wxT("network volume"), | |
1738 | wxT("other volume"), | |
0e2c5534 VZ |
1739 | }; |
1740 | ||
1741 | static void TestFSVolume() | |
1742 | { | |
9a83f860 | 1743 | wxPuts(wxT("*** Testing wxFSVolume class ***")); |
0e2c5534 VZ |
1744 | |
1745 | wxArrayString volumes = wxFSVolume::GetVolumes(); | |
1746 | size_t count = volumes.GetCount(); | |
1747 | ||
1748 | if ( !count ) | |
1749 | { | |
9a83f860 | 1750 | wxPuts(wxT("ERROR: no mounted volumes?")); |
0e2c5534 VZ |
1751 | return; |
1752 | } | |
1753 | ||
9a83f860 | 1754 | wxPrintf(wxT("%u mounted volumes found:\n"), count); |
0e2c5534 VZ |
1755 | |
1756 | for ( size_t n = 0; n < count; n++ ) | |
1757 | { | |
1758 | wxFSVolume vol(volumes[n]); | |
1759 | if ( !vol.IsOk() ) | |
1760 | { | |
9a83f860 | 1761 | wxPuts(wxT("ERROR: couldn't create volume")); |
0e2c5534 VZ |
1762 | continue; |
1763 | } | |
1764 | ||
9a83f860 | 1765 | wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"), |
0e2c5534 VZ |
1766 | n + 1, |
1767 | vol.GetDisplayName().c_str(), | |
1768 | vol.GetName().c_str(), | |
1769 | volumeKinds[vol.GetKind()], | |
9a83f860 VZ |
1770 | vol.IsWritable() ? wxT("rw") : wxT("ro"), |
1771 | vol.GetFlags() & wxFS_VOL_REMOVABLE ? wxT("removable") | |
1772 | : wxT("fixed")); | |
0e2c5534 | 1773 | } |
ec0e0939 FM |
1774 | |
1775 | wxPuts("\n"); | |
0e2c5534 VZ |
1776 | } |
1777 | ||
1778 | #endif // TEST_VOLUME | |
1779 | ||
b76b015e VZ |
1780 | // ---------------------------------------------------------------------------- |
1781 | // date time | |
1782 | // ---------------------------------------------------------------------------- | |
1783 | ||
d31b7b68 | 1784 | #ifdef TEST_DATETIME |
b76b015e | 1785 | |
b713f891 | 1786 | #include "wx/math.h" |
e84010cf | 1787 | #include "wx/datetime.h" |
b76b015e | 1788 | |
4b586201 WS |
1789 | #if TEST_INTERACTIVE |
1790 | ||
b92fd37c | 1791 | static void TestDateTimeInteractive() |
9d9b7755 | 1792 | { |
9a83f860 | 1793 | wxPuts(wxT("\n*** interactive wxDateTime tests ***")); |
9d9b7755 | 1794 | |
456ae26d | 1795 | wxChar buf[128]; |
9d9b7755 VZ |
1796 | |
1797 | for ( ;; ) | |
1798 | { | |
ec0e0939 | 1799 | wxPrintf(wxT("Enter a date (or 'quit' to escape): ")); |
456ae26d | 1800 | if ( !wxFgets(buf, WXSIZEOF(buf), stdin) ) |
9d9b7755 VZ |
1801 | break; |
1802 | ||
f6bcfd97 | 1803 | // kill the last '\n' |
456ae26d | 1804 | buf[wxStrlen(buf) - 1] = 0; |
ec0e0939 FM |
1805 | |
1806 | if ( wxString(buf).CmpNoCase("quit") == 0 ) | |
1807 | break; | |
f6bcfd97 | 1808 | |
9d9b7755 | 1809 | wxDateTime dt; |
456ae26d | 1810 | const wxChar *p = dt.ParseDate(buf); |
f6bcfd97 | 1811 | if ( !p ) |
9d9b7755 | 1812 | { |
9a83f860 | 1813 | wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf); |
9d9b7755 VZ |
1814 | |
1815 | continue; | |
1816 | } | |
f6bcfd97 BP |
1817 | else if ( *p ) |
1818 | { | |
9a83f860 | 1819 | wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p - buf); |
f6bcfd97 | 1820 | } |
9d9b7755 | 1821 | |
9a83f860 VZ |
1822 | wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"), |
1823 | dt.Format(wxT("%b %d, %Y")).c_str(), | |
456ae26d VZ |
1824 | dt.GetDayOfYear(), |
1825 | dt.GetWeekOfMonth(wxDateTime::Monday_First), | |
1826 | dt.GetWeekOfMonth(wxDateTime::Sunday_First), | |
1827 | dt.GetWeekOfYear(wxDateTime::Monday_First)); | |
9d9b7755 | 1828 | } |
ec0e0939 FM |
1829 | |
1830 | wxPuts("\n"); | |
9d9b7755 VZ |
1831 | } |
1832 | ||
4b586201 | 1833 | #endif // TEST_INTERACTIVE |
d31b7b68 | 1834 | #endif // TEST_DATETIME |
b76b015e | 1835 | |
e87271f3 | 1836 | // ---------------------------------------------------------------------------- |
30ccbb89 | 1837 | // single instance |
e87271f3 VZ |
1838 | // ---------------------------------------------------------------------------- |
1839 | ||
daa2c7d9 | 1840 | #ifdef TEST_SNGLINST |
30ccbb89 FM |
1841 | |
1842 | #include "wx/snglinst.h" | |
1843 | ||
1844 | static bool TestSingleIstance() | |
1845 | { | |
1846 | wxPuts(wxT("\n*** Testing wxSingleInstanceChecker ***")); | |
1847 | ||
1848 | wxSingleInstanceChecker checker; | |
1849 | if ( checker.Create(wxT(".wxconsole.lock")) ) | |
1850 | { | |
1851 | if ( checker.IsAnotherRunning() ) | |
1852 | { | |
1853 | wxPrintf(wxT("Another instance of the program is running, exiting.\n")); | |
1854 | ||
1855 | return false; | |
1856 | } | |
1857 | ||
1858 | // wait some time to give time to launch another instance | |
1859 | wxPuts(wxT("If you try to run another instance of this program now, it won't start.")); | |
1860 | wxPrintf(wxT("Press \"Enter\" to exit wxSingleInstanceChecker test and proceed...")); | |
1861 | wxFgetc(stdin); | |
1862 | } | |
1863 | else // failed to create | |
1864 | { | |
1865 | wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n")); | |
1866 | } | |
1867 | ||
1868 | wxPuts("\n"); | |
1869 | ||
1870 | return true; | |
1871 | } | |
daa2c7d9 VZ |
1872 | #endif // TEST_SNGLINST |
1873 | ||
30ccbb89 FM |
1874 | |
1875 | // ---------------------------------------------------------------------------- | |
1876 | // entry point | |
1877 | // ---------------------------------------------------------------------------- | |
1878 | ||
bbfa0322 | 1879 | int main(int argc, char **argv) |
37667812 | 1880 | { |
5ba95b79 WS |
1881 | #if wxUSE_UNICODE |
1882 | wxChar **wxArgv = new wxChar *[argc + 1]; | |
1883 | ||
1884 | { | |
1885 | int n; | |
1886 | ||
1887 | for (n = 0; n < argc; n++ ) | |
1888 | { | |
1889 | wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); | |
1890 | wxArgv[n] = wxStrdup(warg); | |
1891 | } | |
1892 | ||
1893 | wxArgv[n] = NULL; | |
1894 | } | |
1895 | #else // !wxUSE_UNICODE | |
1896 | #define wxArgv argv | |
1897 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE | |
1898 | ||
6f35ed60 | 1899 | wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); |
9cb47ea2 | 1900 | |
58b24a56 VZ |
1901 | wxInitializer initializer; |
1902 | if ( !initializer ) | |
37667812 | 1903 | { |
be5a51fb | 1904 | fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); |
58b24a56 VZ |
1905 | |
1906 | return -1; | |
1907 | } | |
1908 | ||
1909 | #ifdef TEST_SNGLINST | |
30ccbb89 FM |
1910 | if (!TestSingleIstance()) |
1911 | return 1; | |
58b24a56 VZ |
1912 | #endif // TEST_SNGLINST |
1913 | ||
1944c6bd | 1914 | #ifdef TEST_DIR |
e9d2bb6f | 1915 | #if TEST_ALL |
99a5af7f | 1916 | TestDirExists(); |
2f0c19d0 | 1917 | TestDirEnum(); |
e9d2bb6f | 1918 | #endif |
2f0c19d0 | 1919 | TestDirTraverse(); |
1944c6bd VZ |
1920 | #endif // TEST_DIR |
1921 | ||
93ed8ff7 | 1922 | #ifdef TEST_DYNLIB |
f6bcfd97 | 1923 | TestDllLoad(); |
297ebe6b | 1924 | TestDllListLoaded(); |
93ed8ff7 | 1925 | #endif // TEST_DYNLIB |
f6bcfd97 | 1926 | |
8fd0d89b VZ |
1927 | #ifdef TEST_ENVIRON |
1928 | TestEnvironment(); | |
1929 | #endif // TEST_ENVIRON | |
1930 | ||
ec37df57 VZ |
1931 | #ifdef TEST_LOCALE |
1932 | TestDefaultLang(); | |
1933 | #endif // TEST_LOCALE | |
1934 | ||
378b05f7 | 1935 | #ifdef TEST_LOG |
9a83f860 | 1936 | wxPuts(wxT("*** Testing wxLog ***")); |
cab8f76e | 1937 | |
378b05f7 VZ |
1938 | wxString s; |
1939 | for ( size_t n = 0; n < 8000; n++ ) | |
1940 | { | |
9a83f860 | 1941 | s << (wxChar)(wxT('A') + (n % 26)); |
378b05f7 VZ |
1942 | } |
1943 | ||
9a83f860 | 1944 | wxLogWarning(wxT("The length of the string is %lu"), |
cab8f76e VZ |
1945 | (unsigned long)s.length()); |
1946 | ||
378b05f7 | 1947 | wxString msg; |
9a83f860 | 1948 | msg.Printf(wxT("A very very long message: '%s', the end!\n"), s.c_str()); |
378b05f7 VZ |
1949 | |
1950 | // this one shouldn't be truncated | |
456ae26d | 1951 | wxPrintf(msg); |
378b05f7 VZ |
1952 | |
1953 | // but this one will because log functions use fixed size buffer | |
b568d04f VZ |
1954 | // (note that it doesn't need '\n' at the end neither - will be added |
1955 | // by wxLog anyhow) | |
9a83f860 | 1956 | wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s.c_str()); |
378b05f7 VZ |
1957 | #endif // TEST_LOG |
1958 | ||
f6bcfd97 | 1959 | #ifdef TEST_FILE |
e9d2bb6f DS |
1960 | TestFileRead(); |
1961 | TestTextFileRead(); | |
1962 | TestFileCopy(); | |
59062ec1 | 1963 | TestTempFile(); |
f6bcfd97 BP |
1964 | #endif // TEST_FILE |
1965 | ||
844f90fb | 1966 | #ifdef TEST_FILENAME |
e9d2bb6f DS |
1967 | TestFileNameTemp(); |
1968 | TestFileNameCwd(); | |
1969 | TestFileNameDirManip(); | |
1970 | TestFileNameComparison(); | |
1971 | TestFileNameOperations(); | |
844f90fb VZ |
1972 | #endif // TEST_FILENAME |
1973 | ||
d56e2b97 VZ |
1974 | #ifdef TEST_FILETIME |
1975 | TestFileGetTimes(); | |
e9d2bb6f | 1976 | #if 0 |
d56e2b97 | 1977 | TestFileSetTimes(); |
e9d2bb6f | 1978 | #endif |
d56e2b97 VZ |
1979 | #endif // TEST_FILETIME |
1980 | ||
07a56e45 VZ |
1981 | #ifdef TEST_FTP |
1982 | wxLog::AddTraceMask(FTP_TRACE_MASK); | |
eb835127 FM |
1983 | |
1984 | // wxFTP cannot be a static variable as its ctor needs to access | |
1985 | // wxWidgets internals after it has been initialized | |
1986 | ftp = new wxFTP; | |
0576cd9e | 1987 | ftp->SetLog(new wxProtocolLog(FTP_TRACE_MASK)); |
07a56e45 | 1988 | if ( TestFtpConnect() ) |
ec0e0939 | 1989 | TestFtpInteractive(); |
07a56e45 VZ |
1990 | //else: connecting to the FTP server failed |
1991 | ||
eb835127 | 1992 | delete ftp; |
07a56e45 VZ |
1993 | #endif // TEST_FTP |
1994 | ||
696e1ea0 | 1995 | #ifdef TEST_MIME |
9a83f860 | 1996 | //wxLog::AddTraceMask(wxT("mime")); |
b61af837 | 1997 | TestMimeEnum(); |
c19c2f6e | 1998 | #if 0 |
b61af837 | 1999 | TestMimeOverride(); |
c19c2f6e VZ |
2000 | TestMimeAssociate(); |
2001 | #endif | |
f06ef5f4 | 2002 | TestMimeFilename(); |
696e1ea0 VZ |
2003 | #endif // TEST_MIME |
2004 | ||
89e60357 | 2005 | #ifdef TEST_INFO_FUNCTIONS |
8bb6b2c0 VZ |
2006 | TestOsInfo(); |
2007 | TestPlatformInfo(); | |
2008 | TestUserInfo(); | |
19f45995 | 2009 | |
8bb6b2c0 VZ |
2010 | #if TEST_INTERACTIVE |
2011 | TestDiskInfo(); | |
e9d2bb6f | 2012 | #endif |
89e60357 VZ |
2013 | #endif // TEST_INFO_FUNCTIONS |
2014 | ||
39189b9d VZ |
2015 | #ifdef TEST_PATHLIST |
2016 | TestPathList(); | |
2017 | #endif // TEST_PATHLIST | |
2018 | ||
7aeebdcd VZ |
2019 | #ifdef TEST_PRINTF |
2020 | TestPrintf(); | |
2021 | #endif // TEST_PRINTF | |
2022 | ||
bc10103e VS |
2023 | #if defined TEST_REGEX && TEST_INTERACTIVE |
2024 | TestRegExInteractive(); | |
2025 | #endif // defined TEST_REGEX && TEST_INTERACTIVE | |
07a56e45 | 2026 | |
d31b7b68 | 2027 | #ifdef TEST_DATETIME |
e9d2bb6f | 2028 | #if TEST_INTERACTIVE |
b92fd37c | 2029 | TestDateTimeInteractive(); |
e9d2bb6f | 2030 | #endif |
d31b7b68 | 2031 | #endif // TEST_DATETIME |
b76b015e | 2032 | |
eaff0f0d | 2033 | #ifdef TEST_STACKWALKER |
60c474a0 | 2034 | #if wxUSE_STACKWALKER |
eaff0f0d | 2035 | TestStackWalk(argv[0]); |
60c474a0 | 2036 | #endif |
eaff0f0d VZ |
2037 | #endif // TEST_STACKWALKER |
2038 | ||
af33b199 VZ |
2039 | #ifdef TEST_STDPATHS |
2040 | TestStandardPaths(); | |
2041 | #endif | |
2042 | ||
551fe3a6 | 2043 | #ifdef TEST_USLEEP |
9a83f860 | 2044 | wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z...")); |
551fe3a6 VZ |
2045 | wxUsleep(3000); |
2046 | #endif // TEST_USLEEP | |
2047 | ||
0e2c5534 VZ |
2048 | #ifdef TEST_VOLUME |
2049 | TestFSVolume(); | |
2050 | #endif // TEST_VOLUME | |
2051 | ||
5ba95b79 WS |
2052 | #if wxUSE_UNICODE |
2053 | { | |
2054 | for ( int n = 0; n < argc; n++ ) | |
2055 | free(wxArgv[n]); | |
2056 | ||
2057 | delete [] wxArgv; | |
2058 | } | |
2059 | #endif // wxUSE_UNICODE | |
2060 | ||
e9d2bb6f DS |
2061 | wxUnusedVar(argc); |
2062 | wxUnusedVar(argv); | |
37667812 VZ |
2063 | return 0; |
2064 | } |