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