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