]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
d1f7c65422cec7767062126ab65b987c253f6b59
[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_CMDLINE
109 #define TEST_DATETIME
110 #define TEST_DIR
111 #define TEST_DYNLIB
112 #define TEST_ENVIRON
113 #define TEST_FILE
114 #define TEST_FILECONF
115 #define TEST_FILENAME
116 #define TEST_FILETIME
117 #define TEST_FTP
118 #define TEST_INFO_FUNCTIONS
119 #define TEST_LOCALE
120 #define TEST_LOG
121 #define TEST_MIME
122 #define TEST_MODULE
123 #define TEST_PATHLIST
124 #define TEST_PRINTF
125 #define TEST_REGCONF
126 #define TEST_REGEX
127 #define TEST_REGISTRY
128 #define TEST_SCOPEGUARD
129 #define TEST_SNGLINST
130 // #define TEST_SOCKETS --FIXME! (RN)
131 #define TEST_STACKWALKER
132 #define TEST_STDPATHS
133 #define TEST_STREAMS
134 #define TEST_TIMER
135 // #define TEST_VOLUME --FIXME! (RN)
136 #define TEST_WCHAR
137 #else // #if TEST_ALL
138 #define TEST_DATETIME
139 #endif
140
141 // some tests are interactive, define this to run them
142 #ifdef TEST_INTERACTIVE
143 #undef TEST_INTERACTIVE
144
145 #define TEST_INTERACTIVE 1
146 #else
147 #define TEST_INTERACTIVE 1
148 #endif
149
150 // ============================================================================
151 // implementation
152 // ============================================================================
153
154 // ----------------------------------------------------------------------------
155 // helper functions
156 // ----------------------------------------------------------------------------
157
158 #if defined(TEST_SOCKETS)
159
160 // replace TABs with \t and CRs with \n
161 static wxString MakePrintable(const wxChar *s)
162 {
163 wxString str(s);
164 (void)str.Replace(wxT("\t"), wxT("\\t"));
165 (void)str.Replace(wxT("\n"), wxT("\\n"));
166 (void)str.Replace(wxT("\r"), wxT("\\r"));
167
168 return str;
169 }
170
171 #endif // MakePrintable() is used
172
173 // ----------------------------------------------------------------------------
174 // wxCmdLineParser
175 // ----------------------------------------------------------------------------
176
177 #ifdef TEST_CMDLINE
178
179 #include "wx/cmdline.h"
180 #include "wx/datetime.h"
181
182 #if wxUSE_CMDLINE_PARSER
183
184 static void ShowCmdLine(const wxCmdLineParser& parser)
185 {
186 wxString s = wxT("Command line parsed successfully:\nInput files: ");
187
188 size_t count = parser.GetParamCount();
189 for ( size_t param = 0; param < count; param++ )
190 {
191 s << parser.GetParam(param) << ' ';
192 }
193
194 s << '\n'
195 << wxT("Verbose:\t") << (parser.Found(wxT("v")) ? wxT("yes") : wxT("no")) << '\n'
196 << wxT("Quiet:\t") << (parser.Found(wxT("q")) ? wxT("yes") : wxT("no")) << '\n';
197
198 wxString strVal;
199 long lVal;
200 double dVal;
201 wxDateTime dt;
202 if ( parser.Found(wxT("o"), &strVal) )
203 s << wxT("Output file:\t") << strVal << '\n';
204 if ( parser.Found(wxT("i"), &strVal) )
205 s << wxT("Input dir:\t") << strVal << '\n';
206 if ( parser.Found(wxT("s"), &lVal) )
207 s << wxT("Size:\t") << lVal << '\n';
208 if ( parser.Found(wxT("f"), &dVal) )
209 s << wxT("Double:\t") << dVal << '\n';
210 if ( parser.Found(wxT("d"), &dt) )
211 s << wxT("Date:\t") << dt.FormatISODate() << '\n';
212 if ( parser.Found(wxT("project_name"), &strVal) )
213 s << wxT("Project:\t") << strVal << '\n';
214
215 wxLogMessage(s);
216 }
217
218 #endif // wxUSE_CMDLINE_PARSER
219
220 static void TestCmdLineConvert()
221 {
222 static const wxChar *cmdlines[] =
223 {
224 wxT("arg1 arg2"),
225 wxT("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
226 wxT("literal \\\" and \"\""),
227 };
228
229 for ( size_t n = 0; n < WXSIZEOF(cmdlines); n++ )
230 {
231 const wxChar *cmdline = cmdlines[n];
232 wxPrintf(wxT("Parsing: %s\n"), cmdline);
233 wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdline);
234
235 size_t count = args.GetCount();
236 wxPrintf(wxT("\targc = %u\n"), count);
237 for ( size_t arg = 0; arg < count; arg++ )
238 {
239 wxPrintf(wxT("\targv[%u] = %s\n"), arg, args[arg].c_str());
240 }
241 }
242 }
243
244 #endif // TEST_CMDLINE
245
246 // ----------------------------------------------------------------------------
247 // wxDir
248 // ----------------------------------------------------------------------------
249
250 #ifdef TEST_DIR
251
252 #include "wx/dir.h"
253
254 #ifdef __UNIX__
255 static const wxChar *ROOTDIR = wxT("/");
256 static const wxChar *TESTDIR = wxT("/usr/local/share");
257 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
258 static const wxChar *ROOTDIR = wxT("c:\\");
259 static const wxChar *TESTDIR = wxT("d:\\");
260 #else
261 #error "don't know where the root directory is"
262 #endif
263
264 static void TestDirEnumHelper(wxDir& dir,
265 int flags = wxDIR_DEFAULT,
266 const wxString& filespec = wxEmptyString)
267 {
268 wxString filename;
269
270 if ( !dir.IsOpened() )
271 return;
272
273 bool cont = dir.GetFirst(&filename, filespec, flags);
274 while ( cont )
275 {
276 wxPrintf(wxT("\t%s\n"), filename.c_str());
277
278 cont = dir.GetNext(&filename);
279 }
280
281 wxPuts(wxEmptyString);
282 }
283
284 #if TEST_ALL
285
286 static void TestDirEnum()
287 {
288 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
289
290 wxString cwd = wxGetCwd();
291 if ( !wxDir::Exists(cwd) )
292 {
293 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str());
294 return;
295 }
296
297 wxDir dir(cwd);
298 if ( !dir.IsOpened() )
299 {
300 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd.c_str());
301 return;
302 }
303
304 wxPuts(wxT("Enumerating everything in current directory:"));
305 TestDirEnumHelper(dir);
306
307 wxPuts(wxT("Enumerating really everything in current directory:"));
308 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
309
310 wxPuts(wxT("Enumerating object files in current directory:"));
311 TestDirEnumHelper(dir, wxDIR_DEFAULT, wxT("*.o*"));
312
313 wxPuts(wxT("Enumerating directories in current directory:"));
314 TestDirEnumHelper(dir, wxDIR_DIRS);
315
316 wxPuts(wxT("Enumerating files in current directory:"));
317 TestDirEnumHelper(dir, wxDIR_FILES);
318
319 wxPuts(wxT("Enumerating files including hidden in current directory:"));
320 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
321
322 dir.Open(ROOTDIR);
323
324 wxPuts(wxT("Enumerating everything in root directory:"));
325 TestDirEnumHelper(dir, wxDIR_DEFAULT);
326
327 wxPuts(wxT("Enumerating directories in root directory:"));
328 TestDirEnumHelper(dir, wxDIR_DIRS);
329
330 wxPuts(wxT("Enumerating files in root directory:"));
331 TestDirEnumHelper(dir, wxDIR_FILES);
332
333 wxPuts(wxT("Enumerating files including hidden in root directory:"));
334 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
335
336 wxPuts(wxT("Enumerating files in non existing directory:"));
337 wxDir dirNo(wxT("nosuchdir"));
338 TestDirEnumHelper(dirNo);
339 }
340
341 #endif // TEST_ALL
342
343 class DirPrintTraverser : public wxDirTraverser
344 {
345 public:
346 virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename))
347 {
348 return wxDIR_CONTINUE;
349 }
350
351 virtual wxDirTraverseResult OnDir(const wxString& dirname)
352 {
353 wxString path, name, ext;
354 wxFileName::SplitPath(dirname, &path, &name, &ext);
355
356 if ( !ext.empty() )
357 name << wxT('.') << ext;
358
359 wxString indent;
360 for ( const wxChar *p = path.c_str(); *p; p++ )
361 {
362 if ( wxIsPathSeparator(*p) )
363 indent += wxT(" ");
364 }
365
366 wxPrintf(wxT("%s%s\n"), indent.c_str(), name.c_str());
367
368 return wxDIR_CONTINUE;
369 }
370 };
371
372 static void TestDirTraverse()
373 {
374 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
375
376 // enum all files
377 wxArrayString files;
378 size_t n = wxDir::GetAllFiles(TESTDIR, &files);
379 wxPrintf(wxT("There are %u files under '%s'\n"), n, TESTDIR);
380 if ( n > 1 )
381 {
382 wxPrintf(wxT("First one is '%s'\n"), files[0u].c_str());
383 wxPrintf(wxT(" last one is '%s'\n"), files[n - 1].c_str());
384 }
385
386 // enum again with custom traverser
387 wxPuts(wxT("Now enumerating directories:"));
388 wxDir dir(TESTDIR);
389 DirPrintTraverser traverser;
390 dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
391 }
392
393 #if TEST_ALL
394
395 static void TestDirExists()
396 {
397 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
398
399 static const wxChar *dirnames[] =
400 {
401 wxT("."),
402 #if defined(__WXMSW__)
403 wxT("c:"),
404 wxT("c:\\"),
405 wxT("\\\\share\\file"),
406 wxT("c:\\dos"),
407 wxT("c:\\dos\\"),
408 wxT("c:\\dos\\\\"),
409 wxT("c:\\autoexec.bat"),
410 #elif defined(__UNIX__)
411 wxT("/"),
412 wxT("//"),
413 wxT("/usr/bin"),
414 wxT("/usr//bin"),
415 wxT("/usr///bin"),
416 #endif
417 };
418
419 for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ )
420 {
421 wxPrintf(wxT("%-40s: %s\n"),
422 dirnames[n],
423 wxDir::Exists(dirnames[n]) ? wxT("exists")
424 : wxT("doesn't exist"));
425 }
426 }
427
428 #endif // TEST_ALL
429
430 #endif // TEST_DIR
431
432 // ----------------------------------------------------------------------------
433 // wxDllLoader
434 // ----------------------------------------------------------------------------
435
436 #ifdef TEST_DYNLIB
437
438 #include "wx/dynlib.h"
439
440 static void TestDllLoad()
441 {
442 #if defined(__WXMSW__)
443 static const wxChar *LIB_NAME = wxT("kernel32.dll");
444 static const wxChar *FUNC_NAME = wxT("lstrlenA");
445 #elif defined(__UNIX__)
446 // weird: using just libc.so does *not* work!
447 static const wxChar *LIB_NAME = wxT("/lib/libc.so.6");
448 static const wxChar *FUNC_NAME = wxT("strlen");
449 #else
450 #error "don't know how to test wxDllLoader on this platform"
451 #endif
452
453 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
454
455 wxDynamicLibrary lib(LIB_NAME);
456 if ( !lib.IsLoaded() )
457 {
458 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME);
459 }
460 else
461 {
462 typedef int (wxSTDCALL *wxStrlenType)(const char *);
463 wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
464 if ( !pfnStrlen )
465 {
466 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
467 FUNC_NAME, LIB_NAME);
468 }
469 else
470 {
471 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
472 FUNC_NAME, LIB_NAME);
473
474 if ( pfnStrlen("foo") != 3 )
475 {
476 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
477 }
478 else
479 {
480 wxPuts(wxT("... ok"));
481 }
482 }
483
484 #ifdef __WXMSW__
485 static const wxChar *FUNC_NAME_AW = wxT("lstrlen");
486
487 typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
488 wxStrlenTypeAorW
489 pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
490 if ( !pfnStrlenAorW )
491 {
492 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
493 FUNC_NAME_AW, LIB_NAME);
494 }
495 else
496 {
497 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
498 {
499 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
500 }
501 }
502 #endif // __WXMSW__
503 }
504 }
505
506 #if defined(__WXMSW__) || defined(__UNIX__)
507
508 static void TestDllListLoaded()
509 {
510 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
511
512 puts("\nLoaded modules:");
513 wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
514 const size_t count = dlls.GetCount();
515 for ( size_t n = 0; n < count; ++n )
516 {
517 const wxDynamicLibraryDetails& details = dlls[n];
518 printf("%-45s", (const char *)details.GetPath().mb_str());
519
520 void *addr wxDUMMY_INITIALIZE(NULL);
521 size_t len wxDUMMY_INITIALIZE(0);
522 if ( details.GetAddress(&addr, &len) )
523 {
524 printf(" %08lx:%08lx",
525 (unsigned long)addr, (unsigned long)((char *)addr + len));
526 }
527
528 printf(" %s\n", (const char *)details.GetVersion().mb_str());
529 }
530 }
531
532 #endif
533
534 #endif // TEST_DYNLIB
535
536 // ----------------------------------------------------------------------------
537 // wxGet/SetEnv
538 // ----------------------------------------------------------------------------
539
540 #ifdef TEST_ENVIRON
541
542 #include "wx/utils.h"
543
544 static wxString MyGetEnv(const wxString& var)
545 {
546 wxString val;
547 if ( !wxGetEnv(var, &val) )
548 val = wxT("<empty>");
549 else
550 val = wxString(wxT('\'')) + val + wxT('\'');
551
552 return val;
553 }
554
555 static void TestEnvironment()
556 {
557 const wxChar *var = wxT("wxTestVar");
558
559 wxPuts(wxT("*** testing environment access functions ***"));
560
561 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
562 wxSetEnv(var, wxT("value for wxTestVar"));
563 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
564 wxSetEnv(var, wxT("another value"));
565 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
566 wxUnsetEnv(var);
567 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
568 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
569 }
570
571 #endif // TEST_ENVIRON
572
573 // ----------------------------------------------------------------------------
574 // file
575 // ----------------------------------------------------------------------------
576
577 #ifdef TEST_FILE
578
579 #include "wx/file.h"
580 #include "wx/ffile.h"
581 #include "wx/textfile.h"
582
583 static void TestFileRead()
584 {
585 wxPuts(wxT("*** wxFile read test ***"));
586
587 wxFile file(wxT("testdata.fc"));
588 if ( file.IsOpened() )
589 {
590 wxPrintf(wxT("File length: %lu\n"), file.Length());
591
592 wxPuts(wxT("File dump:\n----------"));
593
594 static const size_t len = 1024;
595 wxChar buf[len];
596 for ( ;; )
597 {
598 size_t nRead = file.Read(buf, len);
599 if ( nRead == (size_t)wxInvalidOffset )
600 {
601 wxPrintf(wxT("Failed to read the file."));
602 break;
603 }
604
605 fwrite(buf, nRead, 1, stdout);
606
607 if ( nRead < len )
608 break;
609 }
610
611 wxPuts(wxT("----------"));
612 }
613 else
614 {
615 wxPrintf(wxT("ERROR: can't open test file.\n"));
616 }
617
618 wxPuts(wxEmptyString);
619 }
620
621 static void TestTextFileRead()
622 {
623 wxPuts(wxT("*** wxTextFile read test ***"));
624
625 wxTextFile file(wxT("testdata.fc"));
626 if ( file.Open() )
627 {
628 wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount());
629 wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str());
630
631 wxString s;
632
633 wxPuts(wxT("\nDumping the entire file:"));
634 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
635 {
636 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
637 }
638 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
639
640 wxPuts(wxT("\nAnd now backwards:"));
641 for ( s = file.GetLastLine();
642 file.GetCurrentLine() != 0;
643 s = file.GetPrevLine() )
644 {
645 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
646 }
647 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
648 }
649 else
650 {
651 wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName());
652 }
653
654 wxPuts(wxEmptyString);
655 }
656
657 static void TestFileCopy()
658 {
659 wxPuts(wxT("*** Testing wxCopyFile ***"));
660
661 static const wxChar *filename1 = wxT("testdata.fc");
662 static const wxChar *filename2 = wxT("test2");
663 if ( !wxCopyFile(filename1, filename2) )
664 {
665 wxPuts(wxT("ERROR: failed to copy file"));
666 }
667 else
668 {
669 wxFFile f1(filename1, wxT("rb")),
670 f2(filename2, wxT("rb"));
671
672 if ( !f1.IsOpened() || !f2.IsOpened() )
673 {
674 wxPuts(wxT("ERROR: failed to open file(s)"));
675 }
676 else
677 {
678 wxString s1, s2;
679 if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
680 {
681 wxPuts(wxT("ERROR: failed to read file(s)"));
682 }
683 else
684 {
685 if ( (s1.length() != s2.length()) ||
686 (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
687 {
688 wxPuts(wxT("ERROR: copy error!"));
689 }
690 else
691 {
692 wxPuts(wxT("File was copied ok."));
693 }
694 }
695 }
696 }
697
698 if ( !wxRemoveFile(filename2) )
699 {
700 wxPuts(wxT("ERROR: failed to remove the file"));
701 }
702
703 wxPuts(wxEmptyString);
704 }
705
706 static void TestTempFile()
707 {
708 wxPuts(wxT("*** wxTempFile test ***"));
709
710 wxTempFile tmpFile;
711 if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) )
712 {
713 if ( tmpFile.Commit() )
714 wxPuts(wxT("File committed."));
715 else
716 wxPuts(wxT("ERROR: could't commit temp file."));
717
718 wxRemoveFile(wxT("test2"));
719 }
720
721 wxPuts(wxEmptyString);
722 }
723
724 #endif // TEST_FILE
725
726 // ----------------------------------------------------------------------------
727 // wxFileConfig
728 // ----------------------------------------------------------------------------
729
730 #ifdef TEST_FILECONF
731
732 #include "wx/confbase.h"
733 #include "wx/fileconf.h"
734
735 static const struct FileConfTestData
736 {
737 const wxChar *name; // value name
738 const wxChar *value; // the value from the file
739 } fcTestData[] =
740 {
741 { wxT("value1"), wxT("one") },
742 { wxT("value2"), wxT("two") },
743 { wxT("novalue"), wxT("default") },
744 };
745
746 static void TestFileConfRead()
747 {
748 wxPuts(wxT("*** testing wxFileConfig loading/reading ***"));
749
750 wxFileConfig fileconf(wxT("test"), wxEmptyString,
751 wxT("testdata.fc"), wxEmptyString,
752 wxCONFIG_USE_RELATIVE_PATH);
753
754 // test simple reading
755 wxPuts(wxT("\nReading config file:"));
756 wxString defValue(wxT("default")), value;
757 for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
758 {
759 const FileConfTestData& data = fcTestData[n];
760 value = fileconf.Read(data.name, defValue);
761 wxPrintf(wxT("\t%s = %s "), data.name, value.c_str());
762 if ( value == data.value )
763 {
764 wxPuts(wxT("(ok)"));
765 }
766 else
767 {
768 wxPrintf(wxT("(ERROR: should be %s)\n"), data.value);
769 }
770 }
771
772 // test enumerating the entries
773 wxPuts(wxT("\nEnumerating all root entries:"));
774 long dummy;
775 wxString name;
776 bool cont = fileconf.GetFirstEntry(name, dummy);
777 while ( cont )
778 {
779 wxPrintf(wxT("\t%s = %s\n"),
780 name.c_str(),
781 fileconf.Read(name.c_str(), wxT("ERROR")).c_str());
782
783 cont = fileconf.GetNextEntry(name, dummy);
784 }
785
786 static const wxChar *testEntry = wxT("TestEntry");
787 wxPrintf(wxT("\nTesting deletion of newly created \"Test\" entry: "));
788 fileconf.Write(testEntry, wxT("A value"));
789 fileconf.DeleteEntry(testEntry);
790 wxPrintf(fileconf.HasEntry(testEntry) ? wxT("ERROR\n") : wxT("ok\n"));
791 }
792
793 #endif // TEST_FILECONF
794
795 // ----------------------------------------------------------------------------
796 // wxFileName
797 // ----------------------------------------------------------------------------
798
799 #ifdef TEST_FILENAME
800
801 #include "wx/filename.h"
802
803 #if 0
804 static void DumpFileName(const wxChar *desc, const wxFileName& fn)
805 {
806 wxPuts(desc);
807
808 wxString full = fn.GetFullPath();
809
810 wxString vol, path, name, ext;
811 wxFileName::SplitPath(full, &vol, &path, &name, &ext);
812
813 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
814 full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
815
816 wxFileName::SplitPath(full, &path, &name, &ext);
817 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
818 path.c_str(), name.c_str(), ext.c_str());
819
820 wxPrintf(wxT("path is also:\t'%s'\n"), fn.GetPath().c_str());
821 wxPrintf(wxT("with volume: \t'%s'\n"),
822 fn.GetPath(wxPATH_GET_VOLUME).c_str());
823 wxPrintf(wxT("with separator:\t'%s'\n"),
824 fn.GetPath(wxPATH_GET_SEPARATOR).c_str());
825 wxPrintf(wxT("with both: \t'%s'\n"),
826 fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str());
827
828 wxPuts(wxT("The directories in the path are:"));
829 wxArrayString dirs = fn.GetDirs();
830 size_t count = dirs.GetCount();
831 for ( size_t n = 0; n < count; n++ )
832 {
833 wxPrintf(wxT("\t%u: %s\n"), n, dirs[n].c_str());
834 }
835 }
836 #endif
837
838 static void TestFileNameTemp()
839 {
840 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
841
842 static const wxChar *tmpprefixes[] =
843 {
844 wxT(""),
845 wxT("foo"),
846 wxT(".."),
847 wxT("../bar"),
848 #ifdef __UNIX__
849 wxT("/tmp/foo"),
850 wxT("/tmp/foo/bar"), // this one must be an error
851 #endif // __UNIX__
852 };
853
854 for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
855 {
856 wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
857 if ( path.empty() )
858 {
859 // "error" is not in upper case because it may be ok
860 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
861 }
862 else
863 {
864 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
865 tmpprefixes[n], path.c_str());
866
867 if ( !wxRemoveFile(path) )
868 {
869 wxLogWarning(wxT("Failed to remove temp file '%s'"),
870 path.c_str());
871 }
872 }
873 }
874 }
875
876 static void TestFileNameDirManip()
877 {
878 // TODO: test AppendDir(), RemoveDir(), ...
879 }
880
881 static void TestFileNameComparison()
882 {
883 // TODO!
884 }
885
886 static void TestFileNameOperations()
887 {
888 // TODO!
889 }
890
891 static void TestFileNameCwd()
892 {
893 // TODO!
894 }
895
896 #endif // TEST_FILENAME
897
898 // ----------------------------------------------------------------------------
899 // wxFileName time functions
900 // ----------------------------------------------------------------------------
901
902 #ifdef TEST_FILETIME
903
904 #include "wx/filename.h"
905 #include "wx/datetime.h"
906
907 static void TestFileGetTimes()
908 {
909 wxFileName fn(wxT("testdata.fc"));
910
911 wxDateTime dtAccess, dtMod, dtCreate;
912 if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
913 {
914 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
915 }
916 else
917 {
918 static const wxChar *fmt = wxT("%Y-%b-%d %H:%M:%S");
919
920 wxPrintf(wxT("File times for '%s':\n"), fn.GetFullPath().c_str());
921 wxPrintf(wxT("Creation: \t%s\n"), dtCreate.Format(fmt).c_str());
922 wxPrintf(wxT("Last read: \t%s\n"), dtAccess.Format(fmt).c_str());
923 wxPrintf(wxT("Last write: \t%s\n"), dtMod.Format(fmt).c_str());
924 }
925 }
926
927 #if 0
928 static void TestFileSetTimes()
929 {
930 wxFileName fn(wxT("testdata.fc"));
931
932 if ( !fn.Touch() )
933 {
934 wxPrintf(wxT("ERROR: Touch() failed.\n"));
935 }
936 }
937 #endif
938
939 #endif // TEST_FILETIME
940
941 // ----------------------------------------------------------------------------
942 // wxLocale
943 // ----------------------------------------------------------------------------
944
945 #ifdef TEST_LOCALE
946
947 #include "wx/intl.h"
948 #include "wx/utils.h" // for wxSetEnv
949
950 static wxLocale gs_localeDefault;
951 // NOTE: don't init it here as it needs a wxAppTraits object
952 // and thus must be init-ed after creation of the wxInitializer
953 // class in the main()
954
955 // find the name of the language from its value
956 static const wxChar *GetLangName(int lang)
957 {
958 static const wxChar *languageNames[] =
959 {
960 wxT("DEFAULT"),
961 wxT("UNKNOWN"),
962 wxT("ABKHAZIAN"),
963 wxT("AFAR"),
964 wxT("AFRIKAANS"),
965 wxT("ALBANIAN"),
966 wxT("AMHARIC"),
967 wxT("ARABIC"),
968 wxT("ARABIC_ALGERIA"),
969 wxT("ARABIC_BAHRAIN"),
970 wxT("ARABIC_EGYPT"),
971 wxT("ARABIC_IRAQ"),
972 wxT("ARABIC_JORDAN"),
973 wxT("ARABIC_KUWAIT"),
974 wxT("ARABIC_LEBANON"),
975 wxT("ARABIC_LIBYA"),
976 wxT("ARABIC_MOROCCO"),
977 wxT("ARABIC_OMAN"),
978 wxT("ARABIC_QATAR"),
979 wxT("ARABIC_SAUDI_ARABIA"),
980 wxT("ARABIC_SUDAN"),
981 wxT("ARABIC_SYRIA"),
982 wxT("ARABIC_TUNISIA"),
983 wxT("ARABIC_UAE"),
984 wxT("ARABIC_YEMEN"),
985 wxT("ARMENIAN"),
986 wxT("ASSAMESE"),
987 wxT("AYMARA"),
988 wxT("AZERI"),
989 wxT("AZERI_CYRILLIC"),
990 wxT("AZERI_LATIN"),
991 wxT("BASHKIR"),
992 wxT("BASQUE"),
993 wxT("BELARUSIAN"),
994 wxT("BENGALI"),
995 wxT("BHUTANI"),
996 wxT("BIHARI"),
997 wxT("BISLAMA"),
998 wxT("BRETON"),
999 wxT("BULGARIAN"),
1000 wxT("BURMESE"),
1001 wxT("CAMBODIAN"),
1002 wxT("CATALAN"),
1003 wxT("CHINESE"),
1004 wxT("CHINESE_SIMPLIFIED"),
1005 wxT("CHINESE_TRADITIONAL"),
1006 wxT("CHINESE_HONGKONG"),
1007 wxT("CHINESE_MACAU"),
1008 wxT("CHINESE_SINGAPORE"),
1009 wxT("CHINESE_TAIWAN"),
1010 wxT("CORSICAN"),
1011 wxT("CROATIAN"),
1012 wxT("CZECH"),
1013 wxT("DANISH"),
1014 wxT("DUTCH"),
1015 wxT("DUTCH_BELGIAN"),
1016 wxT("ENGLISH"),
1017 wxT("ENGLISH_UK"),
1018 wxT("ENGLISH_US"),
1019 wxT("ENGLISH_AUSTRALIA"),
1020 wxT("ENGLISH_BELIZE"),
1021 wxT("ENGLISH_BOTSWANA"),
1022 wxT("ENGLISH_CANADA"),
1023 wxT("ENGLISH_CARIBBEAN"),
1024 wxT("ENGLISH_DENMARK"),
1025 wxT("ENGLISH_EIRE"),
1026 wxT("ENGLISH_JAMAICA"),
1027 wxT("ENGLISH_NEW_ZEALAND"),
1028 wxT("ENGLISH_PHILIPPINES"),
1029 wxT("ENGLISH_SOUTH_AFRICA"),
1030 wxT("ENGLISH_TRINIDAD"),
1031 wxT("ENGLISH_ZIMBABWE"),
1032 wxT("ESPERANTO"),
1033 wxT("ESTONIAN"),
1034 wxT("FAEROESE"),
1035 wxT("FARSI"),
1036 wxT("FIJI"),
1037 wxT("FINNISH"),
1038 wxT("FRENCH"),
1039 wxT("FRENCH_BELGIAN"),
1040 wxT("FRENCH_CANADIAN"),
1041 wxT("FRENCH_LUXEMBOURG"),
1042 wxT("FRENCH_MONACO"),
1043 wxT("FRENCH_SWISS"),
1044 wxT("FRISIAN"),
1045 wxT("GALICIAN"),
1046 wxT("GEORGIAN"),
1047 wxT("GERMAN"),
1048 wxT("GERMAN_AUSTRIAN"),
1049 wxT("GERMAN_BELGIUM"),
1050 wxT("GERMAN_LIECHTENSTEIN"),
1051 wxT("GERMAN_LUXEMBOURG"),
1052 wxT("GERMAN_SWISS"),
1053 wxT("GREEK"),
1054 wxT("GREENLANDIC"),
1055 wxT("GUARANI"),
1056 wxT("GUJARATI"),
1057 wxT("HAUSA"),
1058 wxT("HEBREW"),
1059 wxT("HINDI"),
1060 wxT("HUNGARIAN"),
1061 wxT("ICELANDIC"),
1062 wxT("INDONESIAN"),
1063 wxT("INTERLINGUA"),
1064 wxT("INTERLINGUE"),
1065 wxT("INUKTITUT"),
1066 wxT("INUPIAK"),
1067 wxT("IRISH"),
1068 wxT("ITALIAN"),
1069 wxT("ITALIAN_SWISS"),
1070 wxT("JAPANESE"),
1071 wxT("JAVANESE"),
1072 wxT("KANNADA"),
1073 wxT("KASHMIRI"),
1074 wxT("KASHMIRI_INDIA"),
1075 wxT("KAZAKH"),
1076 wxT("KERNEWEK"),
1077 wxT("KINYARWANDA"),
1078 wxT("KIRGHIZ"),
1079 wxT("KIRUNDI"),
1080 wxT("KONKANI"),
1081 wxT("KOREAN"),
1082 wxT("KURDISH"),
1083 wxT("LAOTHIAN"),
1084 wxT("LATIN"),
1085 wxT("LATVIAN"),
1086 wxT("LINGALA"),
1087 wxT("LITHUANIAN"),
1088 wxT("MACEDONIAN"),
1089 wxT("MALAGASY"),
1090 wxT("MALAY"),
1091 wxT("MALAYALAM"),
1092 wxT("MALAY_BRUNEI_DARUSSALAM"),
1093 wxT("MALAY_MALAYSIA"),
1094 wxT("MALTESE"),
1095 wxT("MANIPURI"),
1096 wxT("MAORI"),
1097 wxT("MARATHI"),
1098 wxT("MOLDAVIAN"),
1099 wxT("MONGOLIAN"),
1100 wxT("NAURU"),
1101 wxT("NEPALI"),
1102 wxT("NEPALI_INDIA"),
1103 wxT("NORWEGIAN_BOKMAL"),
1104 wxT("NORWEGIAN_NYNORSK"),
1105 wxT("OCCITAN"),
1106 wxT("ORIYA"),
1107 wxT("OROMO"),
1108 wxT("PASHTO"),
1109 wxT("POLISH"),
1110 wxT("PORTUGUESE"),
1111 wxT("PORTUGUESE_BRAZILIAN"),
1112 wxT("PUNJABI"),
1113 wxT("QUECHUA"),
1114 wxT("RHAETO_ROMANCE"),
1115 wxT("ROMANIAN"),
1116 wxT("RUSSIAN"),
1117 wxT("RUSSIAN_UKRAINE"),
1118 wxT("SAMOAN"),
1119 wxT("SANGHO"),
1120 wxT("SANSKRIT"),
1121 wxT("SCOTS_GAELIC"),
1122 wxT("SERBIAN"),
1123 wxT("SERBIAN_CYRILLIC"),
1124 wxT("SERBIAN_LATIN"),
1125 wxT("SERBO_CROATIAN"),
1126 wxT("SESOTHO"),
1127 wxT("SETSWANA"),
1128 wxT("SHONA"),
1129 wxT("SINDHI"),
1130 wxT("SINHALESE"),
1131 wxT("SISWATI"),
1132 wxT("SLOVAK"),
1133 wxT("SLOVENIAN"),
1134 wxT("SOMALI"),
1135 wxT("SPANISH"),
1136 wxT("SPANISH_ARGENTINA"),
1137 wxT("SPANISH_BOLIVIA"),
1138 wxT("SPANISH_CHILE"),
1139 wxT("SPANISH_COLOMBIA"),
1140 wxT("SPANISH_COSTA_RICA"),
1141 wxT("SPANISH_DOMINICAN_REPUBLIC"),
1142 wxT("SPANISH_ECUADOR"),
1143 wxT("SPANISH_EL_SALVADOR"),
1144 wxT("SPANISH_GUATEMALA"),
1145 wxT("SPANISH_HONDURAS"),
1146 wxT("SPANISH_MEXICAN"),
1147 wxT("SPANISH_MODERN"),
1148 wxT("SPANISH_NICARAGUA"),
1149 wxT("SPANISH_PANAMA"),
1150 wxT("SPANISH_PARAGUAY"),
1151 wxT("SPANISH_PERU"),
1152 wxT("SPANISH_PUERTO_RICO"),
1153 wxT("SPANISH_URUGUAY"),
1154 wxT("SPANISH_US"),
1155 wxT("SPANISH_VENEZUELA"),
1156 wxT("SUNDANESE"),
1157 wxT("SWAHILI"),
1158 wxT("SWEDISH"),
1159 wxT("SWEDISH_FINLAND"),
1160 wxT("TAGALOG"),
1161 wxT("TAJIK"),
1162 wxT("TAMIL"),
1163 wxT("TATAR"),
1164 wxT("TELUGU"),
1165 wxT("THAI"),
1166 wxT("TIBETAN"),
1167 wxT("TIGRINYA"),
1168 wxT("TONGA"),
1169 wxT("TSONGA"),
1170 wxT("TURKISH"),
1171 wxT("TURKMEN"),
1172 wxT("TWI"),
1173 wxT("UIGHUR"),
1174 wxT("UKRAINIAN"),
1175 wxT("URDU"),
1176 wxT("URDU_INDIA"),
1177 wxT("URDU_PAKISTAN"),
1178 wxT("UZBEK"),
1179 wxT("UZBEK_CYRILLIC"),
1180 wxT("UZBEK_LATIN"),
1181 wxT("VIETNAMESE"),
1182 wxT("VOLAPUK"),
1183 wxT("WELSH"),
1184 wxT("WOLOF"),
1185 wxT("XHOSA"),
1186 wxT("YIDDISH"),
1187 wxT("YORUBA"),
1188 wxT("ZHUANG"),
1189 wxT("ZULU"),
1190 };
1191
1192 if ( (size_t)lang < WXSIZEOF(languageNames) )
1193 return languageNames[lang];
1194 else
1195 return wxT("INVALID");
1196 }
1197
1198 static void TestDefaultLang()
1199 {
1200 wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
1201
1202 gs_localeDefault.Init(wxLANGUAGE_ENGLISH);
1203
1204 static const wxChar *langStrings[] =
1205 {
1206 NULL, // system default
1207 wxT("C"),
1208 wxT("fr"),
1209 wxT("fr_FR"),
1210 wxT("en"),
1211 wxT("en_GB"),
1212 wxT("en_US"),
1213 wxT("de_DE.iso88591"),
1214 wxT("german"),
1215 wxT("?"), // invalid lang spec
1216 wxT("klingonese"), // I bet on some systems it does exist...
1217 };
1218
1219 wxPrintf(wxT("The default system encoding is %s (%d)\n"),
1220 wxLocale::GetSystemEncodingName().c_str(),
1221 wxLocale::GetSystemEncoding());
1222
1223 for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
1224 {
1225 const wxChar *langStr = langStrings[n];
1226 if ( langStr )
1227 {
1228 // FIXME: this doesn't do anything at all under Windows, we need
1229 // to create a new wxLocale!
1230 wxSetEnv(wxT("LC_ALL"), langStr);
1231 }
1232
1233 int lang = gs_localeDefault.GetSystemLanguage();
1234 wxPrintf(wxT("Locale for '%s' is %s.\n"),
1235 langStr ? langStr : wxT("system default"), GetLangName(lang));
1236 }
1237 }
1238
1239 #endif // TEST_LOCALE
1240
1241 // ----------------------------------------------------------------------------
1242 // MIME types
1243 // ----------------------------------------------------------------------------
1244
1245 #ifdef TEST_MIME
1246
1247 #include "wx/mimetype.h"
1248
1249 static void TestMimeEnum()
1250 {
1251 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1252
1253 wxArrayString mimetypes;
1254
1255 size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
1256
1257 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count);
1258
1259 wxArrayString exts;
1260 wxString desc;
1261
1262 for ( size_t n = 0; n < count; n++ )
1263 {
1264 wxFileType *filetype =
1265 wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
1266 if ( !filetype )
1267 {
1268 wxPrintf(wxT("nothing known about the filetype '%s'!\n"),
1269 mimetypes[n].c_str());
1270 continue;
1271 }
1272
1273 filetype->GetDescription(&desc);
1274 filetype->GetExtensions(exts);
1275
1276 filetype->GetIcon(NULL);
1277
1278 wxString extsAll;
1279 for ( size_t e = 0; e < exts.GetCount(); e++ )
1280 {
1281 if ( e > 0 )
1282 extsAll << wxT(", ");
1283 extsAll += exts[e];
1284 }
1285
1286 wxPrintf(wxT("\t%s: %s (%s)\n"),
1287 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
1288 }
1289
1290 wxPuts(wxEmptyString);
1291 }
1292
1293 static void TestMimeFilename()
1294 {
1295 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
1296
1297 static const wxChar *filenames[] =
1298 {
1299 wxT("readme.txt"),
1300 wxT("document.pdf"),
1301 wxT("image.gif"),
1302 wxT("picture.jpeg"),
1303 };
1304
1305 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
1306 {
1307 const wxString fname = filenames[n];
1308 wxString ext = fname.AfterLast(wxT('.'));
1309 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
1310 if ( !ft )
1311 {
1312 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext.c_str());
1313 }
1314 else
1315 {
1316 wxString desc;
1317 if ( !ft->GetDescription(&desc) )
1318 desc = wxT("<no description>");
1319
1320 wxString cmd;
1321 if ( !ft->GetOpenCommand(&cmd,
1322 wxFileType::MessageParameters(fname, wxEmptyString)) )
1323 cmd = wxT("<no command available>");
1324 else
1325 cmd = wxString(wxT('"')) + cmd + wxT('"');
1326
1327 wxPrintf(wxT("To open %s (%s) do %s.\n"),
1328 fname.c_str(), desc.c_str(), cmd.c_str());
1329
1330 delete ft;
1331 }
1332 }
1333
1334 wxPuts(wxEmptyString);
1335 }
1336
1337 // these tests were broken by wxMimeTypesManager changes, temporarily disabling
1338 #if 0
1339
1340 static void TestMimeOverride()
1341 {
1342 wxPuts(wxT("*** Testing wxMimeTypesManager additional files loading ***\n"));
1343
1344 static const wxChar *mailcap = wxT("/tmp/mailcap");
1345 static const wxChar *mimetypes = wxT("/tmp/mime.types");
1346
1347 if ( wxFile::Exists(mailcap) )
1348 wxPrintf(wxT("Loading mailcap from '%s': %s\n"),
1349 mailcap,
1350 wxTheMimeTypesManager->ReadMailcap(mailcap) ? wxT("ok") : wxT("ERROR"));
1351 else
1352 wxPrintf(wxT("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1353 mailcap);
1354
1355 if ( wxFile::Exists(mimetypes) )
1356 wxPrintf(wxT("Loading mime.types from '%s': %s\n"),
1357 mimetypes,
1358 wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? wxT("ok") : wxT("ERROR"));
1359 else
1360 wxPrintf(wxT("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1361 mimetypes);
1362
1363 wxPuts(wxEmptyString);
1364 }
1365
1366 static void TestMimeAssociate()
1367 {
1368 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
1369
1370 wxFileTypeInfo ftInfo(
1371 wxT("application/x-xyz"),
1372 wxT("xyzview '%s'"), // open cmd
1373 wxT(""), // print cmd
1374 wxT("XYZ File"), // description
1375 wxT(".xyz"), // extensions
1376 wxNullPtr // end of extensions
1377 );
1378 ftInfo.SetShortDesc(wxT("XYZFile")); // used under Win32 only
1379
1380 wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
1381 if ( !ft )
1382 {
1383 wxPuts(wxT("ERROR: failed to create association!"));
1384 }
1385 else
1386 {
1387 // TODO: read it back
1388 delete ft;
1389 }
1390
1391 wxPuts(wxEmptyString);
1392 }
1393
1394 #endif // 0
1395
1396 #endif // TEST_MIME
1397
1398 // ----------------------------------------------------------------------------
1399 // module dependencies feature
1400 // ----------------------------------------------------------------------------
1401
1402 #ifdef TEST_MODULE
1403
1404 #include "wx/module.h"
1405
1406 class wxTestModule : public wxModule
1407 {
1408 protected:
1409 virtual bool OnInit() { wxPrintf(wxT("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
1410 virtual void OnExit() { wxPrintf(wxT("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
1411 };
1412
1413 class wxTestModuleA : public wxTestModule
1414 {
1415 public:
1416 wxTestModuleA();
1417 private:
1418 DECLARE_DYNAMIC_CLASS(wxTestModuleA)
1419 };
1420
1421 class wxTestModuleB : public wxTestModule
1422 {
1423 public:
1424 wxTestModuleB();
1425 private:
1426 DECLARE_DYNAMIC_CLASS(wxTestModuleB)
1427 };
1428
1429 class wxTestModuleC : public wxTestModule
1430 {
1431 public:
1432 wxTestModuleC();
1433 private:
1434 DECLARE_DYNAMIC_CLASS(wxTestModuleC)
1435 };
1436
1437 class wxTestModuleD : public wxTestModule
1438 {
1439 public:
1440 wxTestModuleD();
1441 private:
1442 DECLARE_DYNAMIC_CLASS(wxTestModuleD)
1443 };
1444
1445 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC, wxModule)
1446 wxTestModuleC::wxTestModuleC()
1447 {
1448 AddDependency(CLASSINFO(wxTestModuleD));
1449 }
1450
1451 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA, wxModule)
1452 wxTestModuleA::wxTestModuleA()
1453 {
1454 AddDependency(CLASSINFO(wxTestModuleB));
1455 AddDependency(CLASSINFO(wxTestModuleD));
1456 }
1457
1458 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD, wxModule)
1459 wxTestModuleD::wxTestModuleD()
1460 {
1461 }
1462
1463 IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB, wxModule)
1464 wxTestModuleB::wxTestModuleB()
1465 {
1466 AddDependency(CLASSINFO(wxTestModuleD));
1467 AddDependency(CLASSINFO(wxTestModuleC));
1468 }
1469
1470 #endif // TEST_MODULE
1471
1472 // ----------------------------------------------------------------------------
1473 // misc information functions
1474 // ----------------------------------------------------------------------------
1475
1476 #ifdef TEST_INFO_FUNCTIONS
1477
1478 #include "wx/utils.h"
1479
1480 #if TEST_INTERACTIVE
1481 static void TestDiskInfo()
1482 {
1483 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
1484
1485 for ( ;; )
1486 {
1487 wxChar pathname[128];
1488 wxPrintf(wxT("\nEnter a directory name: "));
1489 if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
1490 break;
1491
1492 // kill the last '\n'
1493 pathname[wxStrlen(pathname) - 1] = 0;
1494
1495 wxLongLong total, free;
1496 if ( !wxGetDiskSpace(pathname, &total, &free) )
1497 {
1498 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
1499 }
1500 else
1501 {
1502 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
1503 (total / 1024).ToString().c_str(),
1504 (free / 1024).ToString().c_str(),
1505 pathname);
1506 }
1507 }
1508 }
1509 #endif // TEST_INTERACTIVE
1510
1511 static void TestOsInfo()
1512 {
1513 wxPuts(wxT("*** Testing OS info functions ***\n"));
1514
1515 int major, minor;
1516 wxGetOsVersion(&major, &minor);
1517 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
1518 wxGetOsDescription().c_str(), major, minor);
1519
1520 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
1521
1522 wxPrintf(wxT("Host name is %s (%s).\n"),
1523 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1524
1525 wxPuts(wxEmptyString);
1526 }
1527
1528 static void TestPlatformInfo()
1529 {
1530 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
1531
1532 // get this platform
1533 wxPlatformInfo plat;
1534
1535 wxPrintf(wxT("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str());
1536 wxPrintf(wxT("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str());
1537 wxPrintf(wxT("Port ID name is: %s\n"), plat.GetPortIdName().c_str());
1538 wxPrintf(wxT("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str());
1539 wxPrintf(wxT("Architecture is: %s\n"), plat.GetArchName().c_str());
1540 wxPrintf(wxT("Endianness is: %s\n"), plat.GetEndiannessName().c_str());
1541
1542 wxPuts(wxEmptyString);
1543 }
1544
1545 static void TestUserInfo()
1546 {
1547 wxPuts(wxT("*** Testing user info functions ***\n"));
1548
1549 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
1550 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
1551 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1552 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1553
1554 wxPuts(wxEmptyString);
1555 }
1556
1557 #endif // TEST_INFO_FUNCTIONS
1558
1559 // ----------------------------------------------------------------------------
1560 // path list
1561 // ----------------------------------------------------------------------------
1562
1563 #ifdef TEST_PATHLIST
1564
1565 #ifdef __UNIX__
1566 #define CMD_IN_PATH wxT("ls")
1567 #else
1568 #define CMD_IN_PATH wxT("command.com")
1569 #endif
1570
1571 static void TestPathList()
1572 {
1573 wxPuts(wxT("*** Testing wxPathList ***\n"));
1574
1575 wxPathList pathlist;
1576 pathlist.AddEnvList(wxT("PATH"));
1577 wxString path = pathlist.FindValidPath(CMD_IN_PATH);
1578 if ( path.empty() )
1579 {
1580 wxPrintf(wxT("ERROR: command not found in the path.\n"));
1581 }
1582 else
1583 {
1584 wxPrintf(wxT("Command found in the path as '%s'.\n"), path.c_str());
1585 }
1586 }
1587
1588 #endif // TEST_PATHLIST
1589
1590 // ----------------------------------------------------------------------------
1591 // regular expressions
1592 // ----------------------------------------------------------------------------
1593
1594 #if defined TEST_REGEX && TEST_INTERACTIVE
1595
1596 #include "wx/regex.h"
1597
1598 static void TestRegExInteractive()
1599 {
1600 wxPuts(wxT("*** Testing RE interactively ***"));
1601
1602 for ( ;; )
1603 {
1604 wxChar pattern[128];
1605 wxPrintf(wxT("\nEnter a pattern: "));
1606 if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
1607 break;
1608
1609 // kill the last '\n'
1610 pattern[wxStrlen(pattern) - 1] = 0;
1611
1612 wxRegEx re;
1613 if ( !re.Compile(pattern) )
1614 {
1615 continue;
1616 }
1617
1618 wxChar text[128];
1619 for ( ;; )
1620 {
1621 wxPrintf(wxT("Enter text to match: "));
1622 if ( !wxFgets(text, WXSIZEOF(text), stdin) )
1623 break;
1624
1625 // kill the last '\n'
1626 text[wxStrlen(text) - 1] = 0;
1627
1628 if ( !re.Matches(text) )
1629 {
1630 wxPrintf(wxT("No match.\n"));
1631 }
1632 else
1633 {
1634 wxPrintf(wxT("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());
1635
1636 size_t start, len;
1637 for ( size_t n = 1; ; n++ )
1638 {
1639 if ( !re.GetMatch(&start, &len, n) )
1640 {
1641 break;
1642 }
1643
1644 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1645 n, wxString(text + start, len).c_str());
1646 }
1647 }
1648 }
1649 }
1650 }
1651
1652 #endif // TEST_REGEX
1653
1654 // ----------------------------------------------------------------------------
1655 // printf() tests
1656 // ----------------------------------------------------------------------------
1657
1658 /*
1659 NB: this stuff was taken from the glibc test suite and modified to build
1660 in wxWidgets: if I read the copyright below properly, this shouldn't
1661 be a problem
1662 */
1663
1664 #ifdef TEST_PRINTF
1665
1666 #ifdef wxTEST_PRINTF
1667 // use our functions from wxchar.cpp
1668 #undef wxPrintf
1669 #undef wxSprintf
1670
1671 // NB: do _not_ use WX_ATTRIBUTE_PRINTF here, we have some invalid formats
1672 // in the tests below
1673 int wxPrintf( const wxChar *format, ... );
1674 int wxSprintf( wxChar *str, const wxChar *format, ... );
1675 #endif
1676
1677 #include "wx/longlong.h"
1678
1679 #include <float.h>
1680
1681 static void rfg1 (void);
1682 static void rfg2 (void);
1683
1684
1685 static void
1686 fmtchk (const wxChar *fmt)
1687 {
1688 (void) wxPrintf(wxT("%s:\t`"), fmt);
1689 (void) wxPrintf(fmt, 0x12);
1690 (void) wxPrintf(wxT("'\n"));
1691 }
1692
1693 static void
1694 fmtst1chk (const wxChar *fmt)
1695 {
1696 (void) wxPrintf(wxT("%s:\t`"), fmt);
1697 (void) wxPrintf(fmt, 4, 0x12);
1698 (void) wxPrintf(wxT("'\n"));
1699 }
1700
1701 static void
1702 fmtst2chk (const wxChar *fmt)
1703 {
1704 (void) wxPrintf(wxT("%s:\t`"), fmt);
1705 (void) wxPrintf(fmt, 4, 4, 0x12);
1706 (void) wxPrintf(wxT("'\n"));
1707 }
1708
1709 /* This page is covered by the following copyright: */
1710
1711 /* (C) Copyright C E Chew
1712 *
1713 * Feel free to copy, use and distribute this software provided:
1714 *
1715 * 1. you do not pretend that you wrote it
1716 * 2. you leave this copyright notice intact.
1717 */
1718
1719 /*
1720 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1721 */
1722
1723 #define DEC -123
1724 #define INT 255
1725 #define UNS (~0)
1726
1727 /* Formatted Output Test
1728 *
1729 * This exercises the output formatting code.
1730 */
1731
1732 wxChar *PointerNull = NULL;
1733
1734 static void
1735 fp_test (void)
1736 {
1737 int i, j, k, l;
1738 wxChar buf[7];
1739 wxChar *prefix = buf;
1740 wxChar tp[20];
1741
1742 wxPuts(wxT("\nFormatted output test"));
1743 wxPrintf(wxT("prefix 6d 6o 6x 6X 6u\n"));
1744 wxStrcpy(prefix, wxT("%"));
1745 for (i = 0; i < 2; i++) {
1746 for (j = 0; j < 2; j++) {
1747 for (k = 0; k < 2; k++) {
1748 for (l = 0; l < 2; l++) {
1749 wxStrcpy(prefix, wxT("%"));
1750 if (i == 0) wxStrcat(prefix, wxT("-"));
1751 if (j == 0) wxStrcat(prefix, wxT("+"));
1752 if (k == 0) wxStrcat(prefix, wxT("#"));
1753 if (l == 0) wxStrcat(prefix, wxT("0"));
1754 wxPrintf(wxT("%5s |"), prefix);
1755 wxStrcpy(tp, prefix);
1756 wxStrcat(tp, wxT("6d |"));
1757 wxPrintf(tp, DEC);
1758 wxStrcpy(tp, prefix);
1759 wxStrcat(tp, wxT("6o |"));
1760 wxPrintf(tp, INT);
1761 wxStrcpy(tp, prefix);
1762 wxStrcat(tp, wxT("6x |"));
1763 wxPrintf(tp, INT);
1764 wxStrcpy(tp, prefix);
1765 wxStrcat(tp, wxT("6X |"));
1766 wxPrintf(tp, INT);
1767 wxStrcpy(tp, prefix);
1768 wxStrcat(tp, wxT("6u |"));
1769 wxPrintf(tp, UNS);
1770 wxPrintf(wxT("\n"));
1771 }
1772 }
1773 }
1774 }
1775 wxPrintf(wxT("%10s\n"), PointerNull);
1776 wxPrintf(wxT("%-10s\n"), PointerNull);
1777 }
1778
1779 static void TestPrintf()
1780 {
1781 static wxChar shortstr[] = wxT("Hi, Z.");
1782 static wxChar longstr[] = wxT("Good morning, Doctor Chandra. This is Hal. \
1783 I am ready for my first lesson today.");
1784 int result = 0;
1785 wxString test_format;
1786
1787 fmtchk(wxT("%.4x"));
1788 fmtchk(wxT("%04x"));
1789 fmtchk(wxT("%4.4x"));
1790 fmtchk(wxT("%04.4x"));
1791 fmtchk(wxT("%4.3x"));
1792 fmtchk(wxT("%04.3x"));
1793
1794 fmtst1chk(wxT("%.*x"));
1795 fmtst1chk(wxT("%0*x"));
1796 fmtst2chk(wxT("%*.*x"));
1797 fmtst2chk(wxT("%0*.*x"));
1798
1799 wxString bad_format = wxT("bad format:\t\"%b\"\n");
1800 wxPrintf(bad_format.c_str());
1801 wxPrintf(wxT("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL);
1802
1803 wxPrintf(wxT("decimal negative:\t\"%d\"\n"), -2345);
1804 wxPrintf(wxT("octal negative:\t\"%o\"\n"), -2345);
1805 wxPrintf(wxT("hex negative:\t\"%x\"\n"), -2345);
1806 wxPrintf(wxT("long decimal number:\t\"%ld\"\n"), -123456L);
1807 wxPrintf(wxT("long octal negative:\t\"%lo\"\n"), -2345L);
1808 wxPrintf(wxT("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1809 wxPrintf(wxT("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1810 test_format = wxT("left-adjusted ZLDN:\t\"%-010ld\"\n");
1811 wxPrintf(test_format.c_str(), -123456);
1812 wxPrintf(wxT("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1813 wxPrintf(wxT("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1814
1815 test_format = wxT("zero-padded string:\t\"%010s\"\n");
1816 wxPrintf(test_format.c_str(), shortstr);
1817 test_format = wxT("left-adjusted Z string:\t\"%-010s\"\n");
1818 wxPrintf(test_format.c_str(), shortstr);
1819 wxPrintf(wxT("space-padded string:\t\"%10s\"\n"), shortstr);
1820 wxPrintf(wxT("left-adjusted S string:\t\"%-10s\"\n"), shortstr);
1821 wxPrintf(wxT("null string:\t\"%s\"\n"), PointerNull);
1822 wxPrintf(wxT("limited string:\t\"%.22s\"\n"), longstr);
1823
1824 wxPrintf(wxT("e-style >= 1:\t\"%e\"\n"), 12.34);
1825 wxPrintf(wxT("e-style >= .1:\t\"%e\"\n"), 0.1234);
1826 wxPrintf(wxT("e-style < .1:\t\"%e\"\n"), 0.001234);
1827 wxPrintf(wxT("e-style big:\t\"%.60e\"\n"), 1e20);
1828 wxPrintf(wxT("e-style == .1:\t\"%e\"\n"), 0.1);
1829 wxPrintf(wxT("f-style >= 1:\t\"%f\"\n"), 12.34);
1830 wxPrintf(wxT("f-style >= .1:\t\"%f\"\n"), 0.1234);
1831 wxPrintf(wxT("f-style < .1:\t\"%f\"\n"), 0.001234);
1832 wxPrintf(wxT("g-style >= 1:\t\"%g\"\n"), 12.34);
1833 wxPrintf(wxT("g-style >= .1:\t\"%g\"\n"), 0.1234);
1834 wxPrintf(wxT("g-style < .1:\t\"%g\"\n"), 0.001234);
1835 wxPrintf(wxT("g-style big:\t\"%.60g\"\n"), 1e20);
1836
1837 wxPrintf (wxT(" %6.5f\n"), .099999999860301614);
1838 wxPrintf (wxT(" %6.5f\n"), .1);
1839 wxPrintf (wxT("x%5.4fx\n"), .5);
1840
1841 wxPrintf (wxT("%#03x\n"), 1);
1842
1843 //wxPrintf (wxT("something really insane: %.10000f\n"), 1.0);
1844
1845 {
1846 double d = FLT_MIN;
1847 int niter = 17;
1848
1849 while (niter-- != 0)
1850 wxPrintf (wxT("%.17e\n"), d / 2);
1851 fflush (stdout);
1852 }
1853
1854 #ifndef __WATCOMC__
1855 // Open Watcom cause compiler error here
1856 // Error! E173: col(24) floating-point constant too small to represent
1857 wxPrintf (wxT("%15.5e\n"), 4.9406564584124654e-324);
1858 #endif
1859
1860 #define FORMAT wxT("|%12.4f|%12.4e|%12.4g|\n")
1861 wxPrintf (FORMAT, 0.0, 0.0, 0.0);
1862 wxPrintf (FORMAT, 1.0, 1.0, 1.0);
1863 wxPrintf (FORMAT, -1.0, -1.0, -1.0);
1864 wxPrintf (FORMAT, 100.0, 100.0, 100.0);
1865 wxPrintf (FORMAT, 1000.0, 1000.0, 1000.0);
1866 wxPrintf (FORMAT, 10000.0, 10000.0, 10000.0);
1867 wxPrintf (FORMAT, 12345.0, 12345.0, 12345.0);
1868 wxPrintf (FORMAT, 100000.0, 100000.0, 100000.0);
1869 wxPrintf (FORMAT, 123456.0, 123456.0, 123456.0);
1870 #undef FORMAT
1871
1872 {
1873 wxChar buf[20];
1874 int rc = wxSnprintf (buf, WXSIZEOF(buf), wxT("%30s"), wxT("foo"));
1875
1876 wxPrintf(wxT("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1877 rc, WXSIZEOF(buf), buf);
1878 #if 0
1879 wxChar buf2[512];
1880 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1881 wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10));
1882 #endif
1883 }
1884
1885 fp_test ();
1886
1887 wxPrintf (wxT("%e should be 1.234568e+06\n"), 1234567.8);
1888 wxPrintf (wxT("%f should be 1234567.800000\n"), 1234567.8);
1889 wxPrintf (wxT("%g should be 1.23457e+06\n"), 1234567.8);
1890 wxPrintf (wxT("%g should be 123.456\n"), 123.456);
1891 wxPrintf (wxT("%g should be 1e+06\n"), 1000000.0);
1892 wxPrintf (wxT("%g should be 10\n"), 10.0);
1893 wxPrintf (wxT("%g should be 0.02\n"), 0.02);
1894
1895 {
1896 double x=1.0;
1897 wxPrintf(wxT("%.17f\n"),(1.0/x/10.0+1.0)*x-x);
1898 }
1899
1900 {
1901 wxChar buf[200];
1902
1903 wxSprintf(buf,wxT("%*s%*s%*s"),-1,wxT("one"),-20,wxT("two"),-30,wxT("three"));
1904
1905 result |= wxStrcmp (buf,
1906 wxT("onetwo three "));
1907
1908 wxPuts (result != 0 ? wxT("Test failed!") : wxT("Test ok."));
1909 }
1910
1911 #ifdef wxLongLong_t
1912 {
1913 wxChar buf[200];
1914
1915 wxSprintf(buf, "%07" wxLongLongFmtSpec "o", wxLL(040000000000));
1916 #if 0
1917 // for some reason below line fails under Borland
1918 wxPrintf (wxT("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf);
1919 #endif
1920
1921 if (wxStrcmp (buf, wxT("40000000000")) != 0)
1922 {
1923 result = 1;
1924 wxPuts (wxT("\tFAILED"));
1925 }
1926 wxUnusedVar(result);
1927 wxPuts (wxEmptyString);
1928 }
1929 #endif // wxLongLong_t
1930
1931 wxPrintf (wxT("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX + 2, UCHAR_MAX + 2);
1932 wxPrintf (wxT("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX + 2, USHRT_MAX + 2);
1933
1934 wxPuts (wxT("--- Should be no further output. ---"));
1935 rfg1 ();
1936 rfg2 ();
1937
1938 #if 0
1939 {
1940 wxChar bytes[7];
1941 wxChar buf[20];
1942
1943 memset (bytes, '\xff', sizeof bytes);
1944 wxSprintf (buf, wxT("foo%hhn\n"), &bytes[3]);
1945 if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff'
1946 || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff')
1947 {
1948 wxPuts (wxT("%hhn overwrite more bytes"));
1949 result = 1;
1950 }
1951 if (bytes[3] != 3)
1952 {
1953 wxPuts (wxT("%hhn wrote incorrect value"));
1954 result = 1;
1955 }
1956 }
1957 #endif
1958 }
1959
1960 static void
1961 rfg1 (void)
1962 {
1963 wxChar buf[100];
1964
1965 wxSprintf (buf, wxT("%5.s"), wxT("xyz"));
1966 if (wxStrcmp (buf, wxT(" ")) != 0)
1967 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" "));
1968 wxSprintf (buf, wxT("%5.f"), 33.3);
1969 if (wxStrcmp (buf, wxT(" 33")) != 0)
1970 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 33"));
1971 wxSprintf (buf, wxT("%8.e"), 33.3e7);
1972 if (wxStrcmp (buf, wxT(" 3e+08")) != 0)
1973 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3e+08"));
1974 wxSprintf (buf, wxT("%8.E"), 33.3e7);
1975 if (wxStrcmp (buf, wxT(" 3E+08")) != 0)
1976 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3E+08"));
1977 wxSprintf (buf, wxT("%.g"), 33.3);
1978 if (wxStrcmp (buf, wxT("3e+01")) != 0)
1979 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3e+01"));
1980 wxSprintf (buf, wxT("%.G"), 33.3);
1981 if (wxStrcmp (buf, wxT("3E+01")) != 0)
1982 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3E+01"));
1983 }
1984
1985 static void
1986 rfg2 (void)
1987 {
1988 int prec;
1989 wxChar buf[100];
1990 wxString test_format;
1991
1992 prec = 0;
1993 wxSprintf (buf, wxT("%.*g"), prec, 3.3);
1994 if (wxStrcmp (buf, wxT("3")) != 0)
1995 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3"));
1996 prec = 0;
1997 wxSprintf (buf, wxT("%.*G"), prec, 3.3);
1998 if (wxStrcmp (buf, wxT("3")) != 0)
1999 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT("3"));
2000 prec = 0;
2001 wxSprintf (buf, wxT("%7.*G"), prec, 3.33);
2002 if (wxStrcmp (buf, wxT(" 3")) != 0)
2003 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 3"));
2004 prec = 3;
2005 test_format = wxT("%04.*o");
2006 wxSprintf (buf, test_format.c_str(), prec, 33);
2007 if (wxStrcmp (buf, wxT(" 041")) != 0)
2008 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 041"));
2009 prec = 7;
2010 test_format = wxT("%09.*u");
2011 wxSprintf (buf, test_format.c_str(), prec, 33);
2012 if (wxStrcmp (buf, wxT(" 0000033")) != 0)
2013 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 0000033"));
2014 prec = 3;
2015 test_format = wxT("%04.*x");
2016 wxSprintf (buf, test_format.c_str(), prec, 33);
2017 if (wxStrcmp (buf, wxT(" 021")) != 0)
2018 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 021"));
2019 prec = 3;
2020 test_format = wxT("%04.*X");
2021 wxSprintf (buf, test_format.c_str(), prec, 33);
2022 if (wxStrcmp (buf, wxT(" 021")) != 0)
2023 wxPrintf (wxT("got: '%s', expected: '%s'\n"), buf, wxT(" 021"));
2024 }
2025
2026 #endif // TEST_PRINTF
2027
2028 // ----------------------------------------------------------------------------
2029 // registry and related stuff
2030 // ----------------------------------------------------------------------------
2031
2032 // this is for MSW only
2033 #ifndef __WXMSW__
2034 #undef TEST_REGCONF
2035 #undef TEST_REGISTRY
2036 #endif
2037
2038 #ifdef TEST_REGCONF
2039
2040 #include "wx/confbase.h"
2041 #include "wx/msw/regconf.h"
2042
2043 #if 0
2044 static void TestRegConfWrite()
2045 {
2046 wxConfig *config = new wxConfig(wxT("myapp"));
2047 config->SetPath(wxT("/group1"));
2048 config->Write(wxT("entry1"), wxT("foo"));
2049 config->SetPath(wxT("/group2"));
2050 config->Write(wxT("entry1"), wxT("bar"));
2051 }
2052 #endif
2053
2054 static void TestRegConfRead()
2055 {
2056 wxRegConfig *config = new wxRegConfig(wxT("myapp"));
2057
2058 wxString str;
2059 long dummy;
2060 config->SetPath(wxT("/"));
2061 wxPuts(wxT("Enumerating / subgroups:"));
2062 bool bCont = config->GetFirstGroup(str, dummy);
2063 while(bCont)
2064 {
2065 wxPuts(str);
2066 bCont = config->GetNextGroup(str, dummy);
2067 }
2068 }
2069
2070 #endif // TEST_REGCONF
2071
2072 #ifdef TEST_REGISTRY
2073
2074 #include "wx/msw/registry.h"
2075
2076 // I chose this one because I liked its name, but it probably only exists under
2077 // NT
2078 static const wxChar *TESTKEY =
2079 wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2080
2081 static void TestRegistryRead()
2082 {
2083 wxPuts(wxT("*** testing registry reading ***"));
2084
2085 wxRegKey key(TESTKEY);
2086 wxPrintf(wxT("The test key name is '%s'.\n"), key.GetName().c_str());
2087 if ( !key.Open() )
2088 {
2089 wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
2090
2091 return;
2092 }
2093
2094 size_t nSubKeys, nValues;
2095 if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
2096 {
2097 wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys, nValues);
2098 }
2099
2100 wxPrintf(wxT("Enumerating values:\n"));
2101
2102 long dummy;
2103 wxString value;
2104 bool cont = key.GetFirstValue(value, dummy);
2105 while ( cont )
2106 {
2107 wxPrintf(wxT("Value '%s': type "), value.c_str());
2108 switch ( key.GetValueType(value) )
2109 {
2110 case wxRegKey::Type_None: wxPrintf(wxT("ERROR (none)")); break;
2111 case wxRegKey::Type_String: wxPrintf(wxT("SZ")); break;
2112 case wxRegKey::Type_Expand_String: wxPrintf(wxT("EXPAND_SZ")); break;
2113 case wxRegKey::Type_Binary: wxPrintf(wxT("BINARY")); break;
2114 case wxRegKey::Type_Dword: wxPrintf(wxT("DWORD")); break;
2115 case wxRegKey::Type_Multi_String: wxPrintf(wxT("MULTI_SZ")); break;
2116 default: wxPrintf(wxT("other (unknown)")); break;
2117 }
2118
2119 wxPrintf(wxT(", value = "));
2120 if ( key.IsNumericValue(value) )
2121 {
2122 long val;
2123 key.QueryValue(value, &val);
2124 wxPrintf(wxT("%ld"), val);
2125 }
2126 else // string
2127 {
2128 wxString val;
2129 key.QueryValue(value, val);
2130 wxPrintf(wxT("'%s'"), val.c_str());
2131
2132 key.QueryRawValue(value, val);
2133 wxPrintf(wxT(" (raw value '%s')"), val.c_str());
2134 }
2135
2136 wxPutchar('\n');
2137
2138 cont = key.GetNextValue(value, dummy);
2139 }
2140 }
2141
2142 static void TestRegistryAssociation()
2143 {
2144 /*
2145 The second call to deleteself genertaes an error message, with a
2146 messagebox saying .flo is crucial to system operation, while the .ddf
2147 call also fails, but with no error message
2148 */
2149
2150 wxRegKey key;
2151
2152 key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2153 key.Create();
2154 key = wxT("ddxf_auto_file") ;
2155 key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2156 key.Create();
2157 key = wxT("ddxf_auto_file") ;
2158 key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2159 key.Create();
2160 key = wxT("program,0") ;
2161 key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2162 key.Create();
2163 key = wxT("program \"%1\"") ;
2164
2165 key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
2166 key.DeleteSelf();
2167 key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
2168 key.DeleteSelf();
2169 key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2170 key.DeleteSelf();
2171 key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2172 key.DeleteSelf();
2173 }
2174
2175 #endif // TEST_REGISTRY
2176
2177 // ----------------------------------------------------------------------------
2178 // scope guard
2179 // ----------------------------------------------------------------------------
2180
2181 #ifdef TEST_SCOPEGUARD
2182
2183 #include "wx/scopeguard.h"
2184
2185 static void function0() { puts("function0()"); }
2186 static void function1(int n) { printf("function1(%d)\n", n); }
2187 static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); }
2188
2189 struct Object
2190 {
2191 void method0() { printf("method0()\n"); }
2192 void method1(int n) { printf("method1(%d)\n", n); }
2193 void method2(double x, char c) { printf("method2(%g, %c)\n", x, c); }
2194 };
2195
2196 static void TestScopeGuard()
2197 {
2198 wxON_BLOCK_EXIT0(function0);
2199 wxON_BLOCK_EXIT1(function1, 17);
2200 wxON_BLOCK_EXIT2(function2, 3.14, 'p');
2201
2202 Object obj;
2203 wxON_BLOCK_EXIT_OBJ0(obj, Object::method0);
2204 wxON_BLOCK_EXIT_OBJ1(obj, Object::method1, 7);
2205 wxON_BLOCK_EXIT_OBJ2(obj, Object::method2, 2.71, 'e');
2206
2207 wxScopeGuard dismissed = wxMakeGuard(function0);
2208 dismissed.Dismiss();
2209 }
2210
2211 #endif
2212
2213 // ----------------------------------------------------------------------------
2214 // sockets
2215 // ----------------------------------------------------------------------------
2216
2217 #ifdef TEST_SOCKETS
2218
2219 #include "wx/socket.h"
2220 #include "wx/protocol/protocol.h"
2221 #include "wx/protocol/http.h"
2222
2223 static void TestSocketServer()
2224 {
2225 wxPuts(wxT("*** Testing wxSocketServer ***\n"));
2226
2227 static const int PORT = 3000;
2228
2229 wxIPV4address addr;
2230 addr.Service(PORT);
2231
2232 wxSocketServer *server = new wxSocketServer(addr);
2233 if ( !server->Ok() )
2234 {
2235 wxPuts(wxT("ERROR: failed to bind"));
2236
2237 return;
2238 }
2239
2240 bool quit = false;
2241 while ( !quit )
2242 {
2243 wxPrintf(wxT("Server: waiting for connection on port %d...\n"), PORT);
2244
2245 wxSocketBase *socket = server->Accept();
2246 if ( !socket )
2247 {
2248 wxPuts(wxT("ERROR: wxSocketServer::Accept() failed."));
2249 break;
2250 }
2251
2252 wxPuts(wxT("Server: got a client."));
2253
2254 server->SetTimeout(60); // 1 min
2255
2256 bool close = false;
2257 while ( !close && socket->IsConnected() )
2258 {
2259 wxString s;
2260 wxChar ch = wxT('\0');
2261 for ( ;; )
2262 {
2263 if ( socket->Read(&ch, sizeof(ch)).Error() )
2264 {
2265 // don't log error if the client just close the connection
2266 if ( socket->IsConnected() )
2267 {
2268 wxPuts(wxT("ERROR: in wxSocket::Read."));
2269 }
2270
2271 break;
2272 }
2273
2274 if ( ch == '\r' )
2275 continue;
2276
2277 if ( ch == '\n' )
2278 break;
2279
2280 s += ch;
2281 }
2282
2283 if ( ch != '\n' )
2284 {
2285 break;
2286 }
2287
2288 wxPrintf(wxT("Server: got '%s'.\n"), s.c_str());
2289 if ( s == wxT("close") )
2290 {
2291 wxPuts(wxT("Closing connection"));
2292
2293 close = true;
2294 }
2295 else if ( s == wxT("quit") )
2296 {
2297 close =
2298 quit = true;
2299
2300 wxPuts(wxT("Shutting down the server"));
2301 }
2302 else // not a special command
2303 {
2304 socket->Write(s.MakeUpper().c_str(), s.length());
2305 socket->Write("\r\n", 2);
2306 wxPrintf(wxT("Server: wrote '%s'.\n"), s.c_str());
2307 }
2308 }
2309
2310 if ( !close )
2311 {
2312 wxPuts(wxT("Server: lost a client unexpectedly."));
2313 }
2314
2315 socket->Destroy();
2316 }
2317
2318 // same as "delete server" but is consistent with GUI programs
2319 server->Destroy();
2320 }
2321
2322 static void TestSocketClient()
2323 {
2324 wxPuts(wxT("*** Testing wxSocketClient ***\n"));
2325
2326 static const wxChar *hostname = wxT("www.wxwidgets.org");
2327
2328 wxIPV4address addr;
2329 addr.Hostname(hostname);
2330 addr.Service(80);
2331
2332 wxPrintf(wxT("--- Attempting to connect to %s:80...\n"), hostname);
2333
2334 wxSocketClient client;
2335 if ( !client.Connect(addr) )
2336 {
2337 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname);
2338 }
2339 else
2340 {
2341 wxPrintf(wxT("--- Connected to %s:%u...\n"),
2342 addr.Hostname().c_str(), addr.Service());
2343
2344 wxChar buf[8192];
2345
2346 // could use simply "GET" here I suppose
2347 wxString cmdGet =
2348 wxString::Format(wxT("GET http://%s/\r\n"), hostname);
2349 client.Write(cmdGet, cmdGet.length());
2350 wxPrintf(wxT("--- Sent command '%s' to the server\n"),
2351 MakePrintable(cmdGet).c_str());
2352 client.Read(buf, WXSIZEOF(buf));
2353 wxPrintf(wxT("--- Server replied:\n%s"), buf);
2354 }
2355 }
2356
2357 #endif // TEST_SOCKETS
2358
2359 // ----------------------------------------------------------------------------
2360 // FTP
2361 // ----------------------------------------------------------------------------
2362
2363 #ifdef TEST_FTP
2364
2365 #include "wx/protocol/ftp.h"
2366 #include "wx/protocol/log.h"
2367
2368 #define FTP_ANONYMOUS
2369
2370 static wxFTP *ftp;
2371
2372 #ifdef FTP_ANONYMOUS
2373 static const wxChar *directory = wxT("/pub");
2374 static const wxChar *filename = wxT("welcome.msg");
2375 #else
2376 static const wxChar *directory = wxT("/etc");
2377 static const wxChar *filename = wxT("issue");
2378 #endif
2379
2380 static bool TestFtpConnect()
2381 {
2382 wxPuts(wxT("*** Testing FTP connect ***"));
2383
2384 #ifdef FTP_ANONYMOUS
2385 static const wxChar *hostname = wxT("ftp.wxwidgets.org");
2386
2387 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
2388 #else // !FTP_ANONYMOUS
2389 static const wxChar *hostname = "localhost";
2390
2391 wxChar user[256];
2392 wxFgets(user, WXSIZEOF(user), stdin);
2393 user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
2394 ftp->SetUser(user);
2395
2396 wxChar password[256];
2397 wxPrintf(wxT("Password for %s: "), password);
2398 wxFgets(password, WXSIZEOF(password), stdin);
2399 password[wxStrlen(password) - 1] = '\0'; // chop off '\n'
2400 ftp->SetPassword(password);
2401
2402 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname, user);
2403 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2404
2405 if ( !ftp->Connect(hostname) )
2406 {
2407 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname);
2408
2409 return false;
2410 }
2411 else
2412 {
2413 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
2414 hostname, ftp->Pwd().c_str());
2415 ftp->Close();
2416 }
2417
2418 return true;
2419 }
2420
2421 static void TestFtpList()
2422 {
2423 wxPuts(wxT("*** Testing wxFTP file listing ***\n"));
2424
2425 // test CWD
2426 if ( !ftp->ChDir(directory) )
2427 {
2428 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory);
2429 }
2430
2431 wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
2432
2433 // test NLIST and LIST
2434 wxArrayString files;
2435 if ( !ftp->GetFilesList(files) )
2436 {
2437 wxPuts(wxT("ERROR: failed to get NLIST of files"));
2438 }
2439 else
2440 {
2441 wxPrintf(wxT("Brief list of files under '%s':\n"), ftp->Pwd().c_str());
2442 size_t count = files.GetCount();
2443 for ( size_t n = 0; n < count; n++ )
2444 {
2445 wxPrintf(wxT("\t%s\n"), files[n].c_str());
2446 }
2447 wxPuts(wxT("End of the file list"));
2448 }
2449
2450 if ( !ftp->GetDirList(files) )
2451 {
2452 wxPuts(wxT("ERROR: failed to get LIST of files"));
2453 }
2454 else
2455 {
2456 wxPrintf(wxT("Detailed list of files under '%s':\n"), ftp->Pwd().c_str());
2457 size_t count = files.GetCount();
2458 for ( size_t n = 0; n < count; n++ )
2459 {
2460 wxPrintf(wxT("\t%s\n"), files[n].c_str());
2461 }
2462 wxPuts(wxT("End of the file list"));
2463 }
2464
2465 if ( !ftp->ChDir(wxT("..")) )
2466 {
2467 wxPuts(wxT("ERROR: failed to cd to .."));
2468 }
2469
2470 wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
2471 }
2472
2473 static void TestFtpDownload()
2474 {
2475 wxPuts(wxT("*** Testing wxFTP download ***\n"));
2476
2477 // test RETR
2478 wxInputStream *in = ftp->GetInputStream(filename);
2479 if ( !in )
2480 {
2481 wxPrintf(wxT("ERROR: couldn't get input stream for %s\n"), filename);
2482 }
2483 else
2484 {
2485 size_t size = in->GetSize();
2486 wxPrintf(wxT("Reading file %s (%u bytes)..."), filename, size);
2487 fflush(stdout);
2488
2489 wxChar *data = new wxChar[size];
2490 if ( !in->Read(data, size) )
2491 {
2492 wxPuts(wxT("ERROR: read error"));
2493 }
2494 else
2495 {
2496 wxPrintf(wxT("\nContents of %s:\n%s\n"), filename, data);
2497 }
2498
2499 delete [] data;
2500 delete in;
2501 }
2502 }
2503
2504 static void TestFtpFileSize()
2505 {
2506 wxPuts(wxT("*** Testing FTP SIZE command ***"));
2507
2508 if ( !ftp->ChDir(directory) )
2509 {
2510 wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory);
2511 }
2512
2513 wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
2514
2515 if ( ftp->FileExists(filename) )
2516 {
2517 int size = ftp->GetFileSize(filename);
2518 if ( size == -1 )
2519 wxPrintf(wxT("ERROR: couldn't get size of '%s'\n"), filename);
2520 else
2521 wxPrintf(wxT("Size of '%s' is %d bytes.\n"), filename, size);
2522 }
2523 else
2524 {
2525 wxPrintf(wxT("ERROR: '%s' doesn't exist\n"), filename);
2526 }
2527 }
2528
2529 static void TestFtpMisc()
2530 {
2531 wxPuts(wxT("*** Testing miscellaneous wxFTP functions ***"));
2532
2533 if ( ftp->SendCommand(wxT("STAT")) != '2' )
2534 {
2535 wxPuts(wxT("ERROR: STAT failed"));
2536 }
2537 else
2538 {
2539 wxPrintf(wxT("STAT returned:\n\n%s\n"), ftp->GetLastResult().c_str());
2540 }
2541
2542 if ( ftp->SendCommand(wxT("HELP SITE")) != '2' )
2543 {
2544 wxPuts(wxT("ERROR: HELP SITE failed"));
2545 }
2546 else
2547 {
2548 wxPrintf(wxT("The list of site-specific commands:\n\n%s\n"),
2549 ftp->GetLastResult().c_str());
2550 }
2551 }
2552
2553 #if TEST_INTERACTIVE
2554
2555 static void TestFtpInteractive()
2556 {
2557 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
2558
2559 wxChar buf[128];
2560
2561 for ( ;; )
2562 {
2563 wxPrintf(wxT("Enter FTP command: "));
2564 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
2565 break;
2566
2567 // kill the last '\n'
2568 buf[wxStrlen(buf) - 1] = 0;
2569
2570 // special handling of LIST and NLST as they require data connection
2571 wxString start(buf, 4);
2572 start.MakeUpper();
2573 if ( start == wxT("LIST") || start == wxT("NLST") )
2574 {
2575 wxString wildcard;
2576 if ( wxStrlen(buf) > 4 )
2577 wildcard = buf + 5;
2578
2579 wxArrayString files;
2580 if ( !ftp->GetList(files, wildcard, start == wxT("LIST")) )
2581 {
2582 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start.c_str());
2583 }
2584 else
2585 {
2586 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
2587 start.c_str(), wildcard.c_str(), ftp->Pwd().c_str());
2588 size_t count = files.GetCount();
2589 for ( size_t n = 0; n < count; n++ )
2590 {
2591 wxPrintf(wxT("\t%s\n"), files[n].c_str());
2592 }
2593 wxPuts(wxT("--- End of the file list"));
2594 }
2595 }
2596 else // !list
2597 {
2598 wxChar ch = ftp->SendCommand(buf);
2599 wxPrintf(wxT("Command %s"), ch ? wxT("succeeded") : wxT("failed"));
2600 if ( ch )
2601 {
2602 wxPrintf(wxT(" (return code %c)"), ch);
2603 }
2604
2605 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp->GetLastResult().c_str());
2606 }
2607 }
2608
2609 wxPuts(wxT("\n*** done ***"));
2610 }
2611
2612 #endif // TEST_INTERACTIVE
2613
2614 static void TestFtpUpload()
2615 {
2616 wxPuts(wxT("*** Testing wxFTP uploading ***\n"));
2617
2618 // upload a file
2619 static const wxChar *file1 = wxT("test1");
2620 static const wxChar *file2 = wxT("test2");
2621 wxOutputStream *out = ftp->GetOutputStream(file1);
2622 if ( out )
2623 {
2624 wxPrintf(wxT("--- Uploading to %s ---\n"), file1);
2625 out->Write("First hello", 11);
2626 delete out;
2627 }
2628
2629 // send a command to check the remote file
2630 if ( ftp->SendCommand(wxString(wxT("STAT ")) + file1) != '2' )
2631 {
2632 wxPrintf(wxT("ERROR: STAT %s failed\n"), file1);
2633 }
2634 else
2635 {
2636 wxPrintf(wxT("STAT %s returned:\n\n%s\n"),
2637 file1, ftp->GetLastResult().c_str());
2638 }
2639
2640 out = ftp->GetOutputStream(file2);
2641 if ( out )
2642 {
2643 wxPrintf(wxT("--- Uploading to %s ---\n"), file1);
2644 out->Write("Second hello", 12);
2645 delete out;
2646 }
2647 }
2648
2649 #endif // TEST_FTP
2650
2651 // ----------------------------------------------------------------------------
2652 // stack backtrace
2653 // ----------------------------------------------------------------------------
2654
2655 #ifdef TEST_STACKWALKER
2656
2657 #if wxUSE_STACKWALKER
2658
2659 #include "wx/stackwalk.h"
2660
2661 class StackDump : public wxStackWalker
2662 {
2663 public:
2664 StackDump(const char *argv0)
2665 : wxStackWalker(argv0)
2666 {
2667 }
2668
2669 virtual void Walk(size_t skip = 1, size_t maxdepth = wxSTACKWALKER_MAX_DEPTH)
2670 {
2671 wxPuts(wxT("Stack dump:"));
2672
2673 wxStackWalker::Walk(skip, maxdepth);
2674 }
2675
2676 protected:
2677 virtual void OnStackFrame(const wxStackFrame& frame)
2678 {
2679 printf("[%2d] ", (int) frame.GetLevel());
2680
2681 wxString name = frame.GetName();
2682 if ( !name.empty() )
2683 {
2684 printf("%-20.40s", (const char*)name.mb_str());
2685 }
2686 else
2687 {
2688 printf("0x%08lx", (unsigned long)frame.GetAddress());
2689 }
2690
2691 if ( frame.HasSourceLocation() )
2692 {
2693 printf("\t%s:%d",
2694 (const char*)frame.GetFileName().mb_str(),
2695 (int)frame.GetLine());
2696 }
2697
2698 puts("");
2699
2700 wxString type, val;
2701 for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
2702 {
2703 printf("\t%s %s = %s\n", (const char*)type.mb_str(),
2704 (const char*)name.mb_str(),
2705 (const char*)val.mb_str());
2706 }
2707 }
2708 };
2709
2710 static void TestStackWalk(const char *argv0)
2711 {
2712 wxPuts(wxT("*** Testing wxStackWalker ***\n"));
2713
2714 StackDump dump(argv0);
2715 dump.Walk();
2716 }
2717
2718 #endif // wxUSE_STACKWALKER
2719
2720 #endif // TEST_STACKWALKER
2721
2722 // ----------------------------------------------------------------------------
2723 // standard paths
2724 // ----------------------------------------------------------------------------
2725
2726 #ifdef TEST_STDPATHS
2727
2728 #include "wx/stdpaths.h"
2729 #include "wx/wxchar.h" // wxPrintf
2730
2731 static void TestStandardPaths()
2732 {
2733 wxPuts(wxT("*** Testing wxStandardPaths ***\n"));
2734
2735 wxTheApp->SetAppName(wxT("console"));
2736
2737 wxStandardPathsBase& stdp = wxStandardPaths::Get();
2738 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
2739 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
2740 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
2741 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str());
2742 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
2743 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
2744 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str());
2745 wxPrintf(wxT("Executable path:\t%s\n"), stdp.GetExecutablePath().c_str());
2746 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
2747 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str());
2748 wxPrintf(wxT("Localized res. dir:\t%s\n"),
2749 stdp.GetLocalizedResourcesDir(wxT("fr")).c_str());
2750 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
2751 stdp.GetLocalizedResourcesDir
2752 (
2753 wxT("fr"),
2754 wxStandardPaths::ResourceCat_Messages
2755 ).c_str());
2756 }
2757
2758 #endif // TEST_STDPATHS
2759
2760 // ----------------------------------------------------------------------------
2761 // streams
2762 // ----------------------------------------------------------------------------
2763
2764 #ifdef TEST_STREAMS
2765
2766 #include "wx/wfstream.h"
2767 #include "wx/mstream.h"
2768
2769 static void TestFileStream()
2770 {
2771 wxPuts(wxT("*** Testing wxFileInputStream ***"));
2772
2773 static const wxString filename = wxT("testdata.fs");
2774 {
2775 wxFileOutputStream fsOut(filename);
2776 fsOut.Write("foo", 3);
2777 }
2778
2779 {
2780 wxFileInputStream fsIn(filename);
2781 wxPrintf(wxT("File stream size: %u\n"), fsIn.GetSize());
2782 int c;
2783 while ( (c=fsIn.GetC()) != wxEOF )
2784 {
2785 wxPutchar(c);
2786 }
2787 }
2788
2789 if ( !wxRemoveFile(filename) )
2790 {
2791 wxPrintf(wxT("ERROR: failed to remove the file '%s'.\n"), filename.c_str());
2792 }
2793
2794 wxPuts(wxT("\n*** wxFileInputStream test done ***"));
2795 }
2796
2797 static void TestMemoryStream()
2798 {
2799 wxPuts(wxT("*** Testing wxMemoryOutputStream ***"));
2800
2801 wxMemoryOutputStream memOutStream;
2802 wxPrintf(wxT("Initially out stream offset: %lu\n"),
2803 (unsigned long)memOutStream.TellO());
2804
2805 for ( const wxChar *p = wxT("Hello, stream!"); *p; p++ )
2806 {
2807 memOutStream.PutC(*p);
2808 }
2809
2810 wxPrintf(wxT("Final out stream offset: %lu\n"),
2811 (unsigned long)memOutStream.TellO());
2812
2813 wxPuts(wxT("*** Testing wxMemoryInputStream ***"));
2814
2815 wxChar buf[1024];
2816 size_t len = memOutStream.CopyTo(buf, WXSIZEOF(buf));
2817
2818 wxMemoryInputStream memInpStream(buf, len);
2819 wxPrintf(wxT("Memory stream size: %u\n"), memInpStream.GetSize());
2820 int c;
2821 while ( (c=memInpStream.GetC()) != wxEOF )
2822 {
2823 wxPutchar(c);
2824 }
2825
2826 wxPuts(wxT("\n*** wxMemoryInputStream test done ***"));
2827 }
2828
2829 #endif // TEST_STREAMS
2830
2831 // ----------------------------------------------------------------------------
2832 // timers
2833 // ----------------------------------------------------------------------------
2834
2835 #ifdef TEST_TIMER
2836
2837 #include "wx/stopwatch.h"
2838 #include "wx/utils.h"
2839
2840 static void TestStopWatch()
2841 {
2842 wxPuts(wxT("*** Testing wxStopWatch ***\n"));
2843
2844 wxStopWatch sw;
2845 sw.Pause();
2846 wxPrintf(wxT("Initially paused, after 2 seconds time is..."));
2847 fflush(stdout);
2848 wxSleep(2);
2849 wxPrintf(wxT("\t%ldms\n"), sw.Time());
2850
2851 wxPrintf(wxT("Resuming stopwatch and sleeping 3 seconds..."));
2852 fflush(stdout);
2853 sw.Resume();
2854 wxSleep(3);
2855 wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time());
2856
2857 sw.Pause();
2858 wxPrintf(wxT("Pausing agan and sleeping 2 more seconds..."));
2859 fflush(stdout);
2860 wxSleep(2);
2861 wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time());
2862
2863 sw.Resume();
2864 wxPrintf(wxT("Finally resuming and sleeping 2 more seconds..."));
2865 fflush(stdout);
2866 wxSleep(2);
2867 wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time());
2868
2869 wxStopWatch sw2;
2870 wxPuts(wxT("\nChecking for 'backwards clock' bug..."));
2871 for ( size_t n = 0; n < 70; n++ )
2872 {
2873 sw2.Start();
2874
2875 for ( size_t m = 0; m < 100000; m++ )
2876 {
2877 if ( sw.Time() < 0 || sw2.Time() < 0 )
2878 {
2879 wxPuts(wxT("\ntime is negative - ERROR!"));
2880 }
2881 }
2882
2883 wxPutchar('.');
2884 fflush(stdout);
2885 }
2886
2887 wxPuts(wxT(", ok."));
2888 }
2889
2890 #include "wx/timer.h"
2891 #include "wx/evtloop.h"
2892
2893 void TestTimer()
2894 {
2895 wxPuts(wxT("*** Testing wxTimer ***\n"));
2896
2897 class MyTimer : public wxTimer
2898 {
2899 public:
2900 MyTimer() : wxTimer() { m_num = 0; }
2901
2902 virtual void Notify()
2903 {
2904 wxPrintf(wxT("%d"), m_num++);
2905 fflush(stdout);
2906
2907 if ( m_num == 10 )
2908 {
2909 wxPrintf(wxT("... exiting the event loop"));
2910 Stop();
2911
2912 wxEventLoop::GetActive()->Exit(0);
2913 wxPuts(wxT(", ok."));
2914 }
2915
2916 fflush(stdout);
2917 }
2918
2919 private:
2920 int m_num;
2921 };
2922
2923 wxEventLoop loop;
2924
2925 wxTimer timer1;
2926 timer1.Start(100, true /* one shot */);
2927 timer1.Stop();
2928 timer1.Start(100, true /* one shot */);
2929
2930 MyTimer timer;
2931 timer.Start(500);
2932
2933 loop.Run();
2934 }
2935
2936 #endif // TEST_TIMER
2937
2938 // ----------------------------------------------------------------------------
2939 // wxVolume tests
2940 // ----------------------------------------------------------------------------
2941
2942 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
2943 #undef TEST_VOLUME
2944 #endif
2945
2946 #ifdef TEST_VOLUME
2947
2948 #include "wx/volume.h"
2949
2950 static const wxChar *volumeKinds[] =
2951 {
2952 wxT("floppy"),
2953 wxT("hard disk"),
2954 wxT("CD-ROM"),
2955 wxT("DVD-ROM"),
2956 wxT("network volume"),
2957 wxT("other volume"),
2958 };
2959
2960 static void TestFSVolume()
2961 {
2962 wxPuts(wxT("*** Testing wxFSVolume class ***"));
2963
2964 wxArrayString volumes = wxFSVolume::GetVolumes();
2965 size_t count = volumes.GetCount();
2966
2967 if ( !count )
2968 {
2969 wxPuts(wxT("ERROR: no mounted volumes?"));
2970 return;
2971 }
2972
2973 wxPrintf(wxT("%u mounted volumes found:\n"), count);
2974
2975 for ( size_t n = 0; n < count; n++ )
2976 {
2977 wxFSVolume vol(volumes[n]);
2978 if ( !vol.IsOk() )
2979 {
2980 wxPuts(wxT("ERROR: couldn't create volume"));
2981 continue;
2982 }
2983
2984 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
2985 n + 1,
2986 vol.GetDisplayName().c_str(),
2987 vol.GetName().c_str(),
2988 volumeKinds[vol.GetKind()],
2989 vol.IsWritable() ? wxT("rw") : wxT("ro"),
2990 vol.GetFlags() & wxFS_VOL_REMOVABLE ? wxT("removable")
2991 : wxT("fixed"));
2992 }
2993 }
2994
2995 #endif // TEST_VOLUME
2996
2997 // ----------------------------------------------------------------------------
2998 // wide char and Unicode support
2999 // ----------------------------------------------------------------------------
3000
3001 #ifdef TEST_WCHAR
3002
3003 #include "wx/strconv.h"
3004 #include "wx/fontenc.h"
3005 #include "wx/encconv.h"
3006 #include "wx/buffer.h"
3007
3008 static const unsigned char utf8koi8r[] =
3009 {
3010 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3011 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3012 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3013 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3014 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3015 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3016 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3017 };
3018
3019 static const unsigned char utf8iso8859_1[] =
3020 {
3021 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3022 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3023 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3024 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3025 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3026 };
3027
3028 static const unsigned char utf8Invalid[] =
3029 {
3030 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3031 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3032 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3033 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3034 0x6c, 0x61, 0x79, 0
3035 };
3036
3037 static const struct Utf8Data
3038 {
3039 const unsigned char *text;
3040 size_t len;
3041 const wxChar *charset;
3042 wxFontEncoding encoding;
3043 } utf8data[] =
3044 {
3045 { utf8Invalid, WXSIZEOF(utf8Invalid), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1 },
3046 { utf8koi8r, WXSIZEOF(utf8koi8r), wxT("koi8-r"), wxFONTENCODING_KOI8 },
3047 { utf8iso8859_1, WXSIZEOF(utf8iso8859_1), wxT("iso8859-1"), wxFONTENCODING_ISO8859_1 },
3048 };
3049
3050 static void TestUtf8()
3051 {
3052 wxPuts(wxT("*** Testing UTF8 support ***\n"));
3053
3054 char buf[1024];
3055 wchar_t wbuf[1024];
3056
3057 for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
3058 {
3059 const Utf8Data& u8d = utf8data[n];
3060 if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text,
3061 WXSIZEOF(wbuf)) == (size_t)-1 )
3062 {
3063 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3064 }
3065 else
3066 {
3067 wxCSConv conv(u8d.charset);
3068 if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 )
3069 {
3070 wxPrintf(wxT("ERROR: conversion to %s failed.\n"), u8d.charset);
3071 }
3072 else
3073 {
3074 wxPrintf(wxT("String in %s: %s\n"), u8d.charset, buf);
3075 }
3076 }
3077
3078 wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
3079 if ( s.empty() )
3080 s = wxT("<< conversion failed >>");
3081 wxPrintf(wxT("String in current cset: %s\n"), s.c_str());
3082
3083 }
3084
3085 wxPuts(wxEmptyString);
3086 }
3087
3088 static void TestEncodingConverter()
3089 {
3090 wxPuts(wxT("*** Testing wxEncodingConverter ***\n"));
3091
3092 // using wxEncodingConverter should give the same result as above
3093 char buf[1024];
3094 wchar_t wbuf[1024];
3095 if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r,
3096 WXSIZEOF(utf8koi8r)) == (size_t)-1 )
3097 {
3098 wxPuts(wxT("ERROR: UTF-8 decoding failed."));
3099 }
3100 else
3101 {
3102 wxEncodingConverter ec;
3103 ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
3104 ec.Convert(wbuf, buf);
3105 wxPrintf(wxT("The same KOI8-R string using wxEC: %s\n"), buf);
3106 }
3107
3108 wxPuts(wxEmptyString);
3109 }
3110
3111 #endif // TEST_WCHAR
3112
3113
3114 // ----------------------------------------------------------------------------
3115 // date time
3116 // ----------------------------------------------------------------------------
3117
3118 #ifdef TEST_DATETIME
3119
3120 #include "wx/math.h"
3121 #include "wx/datetime.h"
3122
3123 #if TEST_INTERACTIVE
3124
3125 static void TestDateTimeInteractive()
3126 {
3127 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
3128
3129 wxChar buf[128];
3130
3131 for ( ;; )
3132 {
3133 wxPrintf(wxT("Enter a date: "));
3134 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
3135 break;
3136
3137 // kill the last '\n'
3138 buf[wxStrlen(buf) - 1] = 0;
3139
3140 wxDateTime dt;
3141 const wxChar *p = dt.ParseDate(buf);
3142 if ( !p )
3143 {
3144 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf);
3145
3146 continue;
3147 }
3148 else if ( *p )
3149 {
3150 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p - buf);
3151 }
3152
3153 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
3154 dt.Format(wxT("%b %d, %Y")).c_str(),
3155 dt.GetDayOfYear(),
3156 dt.GetWeekOfMonth(wxDateTime::Monday_First),
3157 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
3158 dt.GetWeekOfYear(wxDateTime::Monday_First));
3159 }
3160
3161 wxPuts(wxT("\n*** done ***"));
3162 }
3163
3164 #endif // TEST_INTERACTIVE
3165 #endif // TEST_DATETIME
3166
3167 // ----------------------------------------------------------------------------
3168 // entry point
3169 // ----------------------------------------------------------------------------
3170
3171 #ifdef TEST_SNGLINST
3172 #include "wx/snglinst.h"
3173 #endif // TEST_SNGLINST
3174
3175 int main(int argc, char **argv)
3176 {
3177 #if wxUSE_UNICODE
3178 wxChar **wxArgv = new wxChar *[argc + 1];
3179
3180 {
3181 int n;
3182
3183 for (n = 0; n < argc; n++ )
3184 {
3185 wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
3186 wxArgv[n] = wxStrdup(warg);
3187 }
3188
3189 wxArgv[n] = NULL;
3190 }
3191 #else // !wxUSE_UNICODE
3192 #define wxArgv argv
3193 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
3194
3195 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
3196
3197 wxInitializer initializer;
3198 if ( !initializer )
3199 {
3200 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
3201
3202 return -1;
3203 }
3204
3205 #ifdef TEST_SNGLINST
3206 wxSingleInstanceChecker checker;
3207 if ( checker.Create(wxT(".wxconsole.lock")) )
3208 {
3209 if ( checker.IsAnotherRunning() )
3210 {
3211 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
3212
3213 return 1;
3214 }
3215
3216 // wait some time to give time to launch another instance
3217 wxPrintf(wxT("Press \"Enter\" to continue..."));
3218 wxFgetc(stdin);
3219 }
3220 else // failed to create
3221 {
3222 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
3223 }
3224 #endif // TEST_SNGLINST
3225
3226 #ifdef TEST_CMDLINE
3227 TestCmdLineConvert();
3228
3229 #if wxUSE_CMDLINE_PARSER
3230 static const wxCmdLineEntryDesc cmdLineDesc[] =
3231 {
3232 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
3233 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
3234 { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
3235 { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" },
3236
3237 { wxCMD_LINE_OPTION, "o", "output", "output file" },
3238 { wxCMD_LINE_OPTION, "i", "input", "input dir" },
3239 { wxCMD_LINE_OPTION, "s", "size", "output block size",
3240 wxCMD_LINE_VAL_NUMBER },
3241 { wxCMD_LINE_OPTION, "d", "date", "output file date",
3242 wxCMD_LINE_VAL_DATE },
3243 { wxCMD_LINE_OPTION, "f", "double", "output double",
3244 wxCMD_LINE_VAL_DOUBLE },
3245
3246 { wxCMD_LINE_PARAM, NULL, NULL, "input file",
3247 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
3248
3249 { wxCMD_LINE_NONE }
3250 };
3251
3252 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
3253
3254 parser.AddOption(wxT("project_name"), wxT(""), wxT("full path to project file"),
3255 wxCMD_LINE_VAL_STRING,
3256 wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);
3257
3258 switch ( parser.Parse() )
3259 {
3260 case -1:
3261 wxLogMessage(wxT("Help was given, terminating."));
3262 break;
3263
3264 case 0:
3265 ShowCmdLine(parser);
3266 break;
3267
3268 default:
3269 wxLogMessage(wxT("Syntax error detected, aborting."));
3270 break;
3271 }
3272 #endif // wxUSE_CMDLINE_PARSER
3273
3274 #endif // TEST_CMDLINE
3275
3276 #ifdef TEST_DIR
3277 #if TEST_ALL
3278 TestDirExists();
3279 TestDirEnum();
3280 #endif
3281 TestDirTraverse();
3282 #endif // TEST_DIR
3283
3284 #ifdef TEST_DYNLIB
3285 TestDllLoad();
3286 TestDllListLoaded();
3287 #endif // TEST_DYNLIB
3288
3289 #ifdef TEST_ENVIRON
3290 TestEnvironment();
3291 #endif // TEST_ENVIRON
3292
3293 #ifdef TEST_FILECONF
3294 TestFileConfRead();
3295 #endif // TEST_FILECONF
3296
3297 #ifdef TEST_LOCALE
3298 TestDefaultLang();
3299 #endif // TEST_LOCALE
3300
3301 #ifdef TEST_LOG
3302 wxPuts(wxT("*** Testing wxLog ***"));
3303
3304 wxString s;
3305 for ( size_t n = 0; n < 8000; n++ )
3306 {
3307 s << (wxChar)(wxT('A') + (n % 26));
3308 }
3309
3310 wxLogWarning(wxT("The length of the string is %lu"),
3311 (unsigned long)s.length());
3312
3313 wxString msg;
3314 msg.Printf(wxT("A very very long message: '%s', the end!\n"), s.c_str());
3315
3316 // this one shouldn't be truncated
3317 wxPrintf(msg);
3318
3319 // but this one will because log functions use fixed size buffer
3320 // (note that it doesn't need '\n' at the end neither - will be added
3321 // by wxLog anyhow)
3322 wxLogMessage(wxT("A very very long message 2: '%s', the end!"), s.c_str());
3323 #endif // TEST_LOG
3324
3325 #ifdef TEST_FILE
3326 TestFileRead();
3327 TestTextFileRead();
3328 TestFileCopy();
3329 TestTempFile();
3330 #endif // TEST_FILE
3331
3332 #ifdef TEST_FILENAME
3333 TestFileNameTemp();
3334 TestFileNameCwd();
3335 TestFileNameDirManip();
3336 TestFileNameComparison();
3337 TestFileNameOperations();
3338 #endif // TEST_FILENAME
3339
3340 #ifdef TEST_FILETIME
3341 TestFileGetTimes();
3342 #if 0
3343 TestFileSetTimes();
3344 #endif
3345 #endif // TEST_FILETIME
3346
3347 #ifdef TEST_FTP
3348 wxLog::AddTraceMask(FTP_TRACE_MASK);
3349
3350 // wxFTP cannot be a static variable as its ctor needs to access
3351 // wxWidgets internals after it has been initialized
3352 ftp = new wxFTP;
3353 ftp->SetLog(new wxProtocolLog(FTP_TRACE_MASK));
3354
3355 if ( TestFtpConnect() )
3356 {
3357 #if TEST_ALL
3358 TestFtpList();
3359 TestFtpDownload();
3360 TestFtpMisc();
3361 TestFtpFileSize();
3362 TestFtpUpload();
3363 #endif // TEST_ALL
3364
3365 #if TEST_INTERACTIVE
3366 //TestFtpInteractive();
3367 #endif
3368 }
3369 //else: connecting to the FTP server failed
3370
3371 delete ftp;
3372 #endif // TEST_FTP
3373
3374 #ifdef TEST_MIME
3375 //wxLog::AddTraceMask(wxT("mime"));
3376 TestMimeEnum();
3377 #if 0
3378 TestMimeOverride();
3379 TestMimeAssociate();
3380 #endif
3381 TestMimeFilename();
3382 #endif // TEST_MIME
3383
3384 #ifdef TEST_INFO_FUNCTIONS
3385 TestOsInfo();
3386 TestPlatformInfo();
3387 TestUserInfo();
3388
3389 #if TEST_INTERACTIVE
3390 TestDiskInfo();
3391 #endif
3392 #endif // TEST_INFO_FUNCTIONS
3393
3394 #ifdef TEST_PATHLIST
3395 TestPathList();
3396 #endif // TEST_PATHLIST
3397
3398 #ifdef TEST_PRINTF
3399 TestPrintf();
3400 #endif // TEST_PRINTF
3401
3402 #ifdef TEST_REGCONF
3403 #if 0
3404 TestRegConfWrite();
3405 #endif
3406 TestRegConfRead();
3407 #endif // TEST_REGCONF
3408
3409 #if defined TEST_REGEX && TEST_INTERACTIVE
3410 TestRegExInteractive();
3411 #endif // defined TEST_REGEX && TEST_INTERACTIVE
3412
3413 #ifdef TEST_REGISTRY
3414 TestRegistryRead();
3415 TestRegistryAssociation();
3416 #endif // TEST_REGISTRY
3417
3418 #ifdef TEST_SOCKETS
3419 TestSocketServer();
3420 TestSocketClient();
3421 #endif // TEST_SOCKETS
3422
3423 #ifdef TEST_STREAMS
3424 #if TEST_ALL
3425 TestFileStream();
3426 #endif
3427 TestMemoryStream();
3428 #endif // TEST_STREAMS
3429
3430 #ifdef TEST_TIMER
3431 TestStopWatch();
3432 TestTimer();
3433 #endif // TEST_TIMER
3434
3435 #ifdef TEST_DATETIME
3436 #if TEST_INTERACTIVE
3437 TestDateTimeInteractive();
3438 #endif
3439 #endif // TEST_DATETIME
3440
3441 #ifdef TEST_SCOPEGUARD
3442 TestScopeGuard();
3443 #endif
3444
3445 #ifdef TEST_STACKWALKER
3446 #if wxUSE_STACKWALKER
3447 TestStackWalk(argv[0]);
3448 #endif
3449 #endif // TEST_STACKWALKER
3450
3451 #ifdef TEST_STDPATHS
3452 TestStandardPaths();
3453 #endif
3454
3455 #ifdef TEST_USLEEP
3456 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
3457 wxUsleep(3000);
3458 #endif // TEST_USLEEP
3459
3460 #ifdef TEST_VOLUME
3461 TestFSVolume();
3462 #endif // TEST_VOLUME
3463
3464 #ifdef TEST_WCHAR
3465 TestUtf8();
3466 TestEncodingConverter();
3467 #endif // TEST_WCHAR
3468
3469 #if wxUSE_UNICODE
3470 {
3471 for ( int n = 0; n < argc; n++ )
3472 free(wxArgv[n]);
3473
3474 delete [] wxArgv;
3475 }
3476 #endif // wxUSE_UNICODE
3477
3478 wxUnusedVar(argc);
3479 wxUnusedVar(argv);
3480 return 0;
3481 }