]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
[1231183] 'cleanup: mismatched indentation' and other cleanings.
[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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/defs.h"
21
22 #include <stdio.h>
23
24 #include "wx/string.h"
25 #include "wx/file.h"
26 #include "wx/app.h"
27 #include "wx/log.h"
28
29 // without this pragma, the stupid compiler precompiles #defines below so that
30 // changing them doesn't "take place" later!
31 #ifdef __VISUALC__
32 #pragma hdrstop
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // conditional compilation
37 // ----------------------------------------------------------------------------
38
39 /*
40 A note about all these conditional compilation macros: this file is used
41 both as a test suite for various non-GUI wxWidgets classes and as a
42 scratchpad for quick tests. So there are two compilation modes: if you
43 define TEST_ALL all tests are run, otherwise you may enable the individual
44 tests individually in the "#else" branch below.
45 */
46
47 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
48 // test, define it to 1 to do all tests.
49 #define TEST_ALL 0
50
51
52 #if TEST_ALL
53 #define TEST_CMDLINE
54 #define TEST_DATETIME
55 #define TEST_DIR
56 #define TEST_DLLLOADER
57 #define TEST_ENVIRON
58 #define TEST_EXECUTE
59 #define TEST_FILE
60 #define TEST_FILECONF
61 #define TEST_FILENAME
62 #define TEST_FILETIME
63 // #define TEST_FTP --FIXME! (RN)
64 #define TEST_INFO_FUNCTIONS
65 #define TEST_LOCALE
66 #define TEST_LOG
67 #define TEST_MIME
68 #define TEST_PATHLIST
69 #define TEST_ODBC
70 #define TEST_PRINTF
71 #define TEST_REGCONF
72 #define TEST_REGEX
73 #define TEST_REGISTRY
74 #define TEST_SCOPEGUARD
75 #define TEST_SNGLINST
76 // #define TEST_SOCKETS --FIXME! (RN)
77 #define TEST_STACKWALKER
78 #define TEST_STDPATHS
79 #define TEST_STREAMS
80 #define TEST_TEXTSTREAM
81 #define TEST_THREADS
82 #define TEST_TIMER
83 // #define TEST_VCARD -- don't enable this (VZ)
84 // #define TEST_VOLUME --FIXME! (RN)
85 #define TEST_WCHAR
86 #define TEST_ZIP
87 #else // #if TEST_ALL
88 #define TEST_STACKWALKER
89 #endif
90
91 // some tests are interactive, define this to run them
92 #ifdef TEST_INTERACTIVE
93 #undef TEST_INTERACTIVE
94
95 #define TEST_INTERACTIVE 1
96 #else
97 #define TEST_INTERACTIVE 0
98 #endif
99
100 // ============================================================================
101 // implementation
102 // ============================================================================
103
104 // ----------------------------------------------------------------------------
105 // helper functions
106 // ----------------------------------------------------------------------------
107
108 #if defined(TEST_SOCKETS)
109
110 // replace TABs with \t and CRs with \n
111 static wxString MakePrintable(const wxChar *s)
112 {
113 wxString str(s);
114 (void)str.Replace(_T("\t"), _T("\\t"));
115 (void)str.Replace(_T("\n"), _T("\\n"));
116 (void)str.Replace(_T("\r"), _T("\\r"));
117
118 return str;
119 }
120
121 #endif // MakePrintable() is used
122
123 // ----------------------------------------------------------------------------
124 // wxCmdLineParser
125 // ----------------------------------------------------------------------------
126
127 #ifdef TEST_CMDLINE
128
129 #include "wx/cmdline.h"
130 #include "wx/datetime.h"
131
132 #if wxUSE_CMDLINE_PARSER
133
134 static void ShowCmdLine(const wxCmdLineParser& parser)
135 {
136 wxString s = _T("Input files: ");
137
138 size_t count = parser.GetParamCount();
139 for ( size_t param = 0; param < count; param++ )
140 {
141 s << parser.GetParam(param) << ' ';
142 }
143
144 s << '\n'
145 << _T("Verbose:\t") << (parser.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
146 << _T("Quiet:\t") << (parser.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
147
148 wxString strVal;
149 long lVal;
150 wxDateTime dt;
151 if ( parser.Found(_T("o"), &strVal) )
152 s << _T("Output file:\t") << strVal << '\n';
153 if ( parser.Found(_T("i"), &strVal) )
154 s << _T("Input dir:\t") << strVal << '\n';
155 if ( parser.Found(_T("s"), &lVal) )
156 s << _T("Size:\t") << lVal << '\n';
157 if ( parser.Found(_T("d"), &dt) )
158 s << _T("Date:\t") << dt.FormatISODate() << '\n';
159 if ( parser.Found(_T("project_name"), &strVal) )
160 s << _T("Project:\t") << strVal << '\n';
161
162 wxLogMessage(s);
163 }
164
165 #endif // wxUSE_CMDLINE_PARSER
166
167 static void TestCmdLineConvert()
168 {
169 static const wxChar *cmdlines[] =
170 {
171 _T("arg1 arg2"),
172 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
173 _T("literal \\\" and \"\""),
174 };
175
176 for ( size_t n = 0; n < WXSIZEOF(cmdlines); n++ )
177 {
178 const wxChar *cmdline = cmdlines[n];
179 wxPrintf(_T("Parsing: %s\n"), cmdline);
180 wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdline);
181
182 size_t count = args.GetCount();
183 wxPrintf(_T("\targc = %u\n"), count);
184 for ( size_t arg = 0; arg < count; arg++ )
185 {
186 wxPrintf(_T("\targv[%u] = %s\n"), arg, args[arg].c_str());
187 }
188 }
189 }
190
191 #endif // TEST_CMDLINE
192
193 // ----------------------------------------------------------------------------
194 // wxDir
195 // ----------------------------------------------------------------------------
196
197 #ifdef TEST_DIR
198
199 #include "wx/dir.h"
200
201 #ifdef __UNIX__
202 static const wxChar *ROOTDIR = _T("/");
203 static const wxChar *TESTDIR = _T("/usr/local/share");
204 #elif defined(__WXMSW__)
205 static const wxChar *ROOTDIR = _T("c:\\");
206 static const wxChar *TESTDIR = _T("d:\\");
207 #else
208 #error "don't know where the root directory is"
209 #endif
210
211 static void TestDirEnumHelper(wxDir& dir,
212 int flags = wxDIR_DEFAULT,
213 const wxString& filespec = wxEmptyString)
214 {
215 wxString filename;
216
217 if ( !dir.IsOpened() )
218 return;
219
220 bool cont = dir.GetFirst(&filename, filespec, flags);
221 while ( cont )
222 {
223 wxPrintf(_T("\t%s\n"), filename.c_str());
224
225 cont = dir.GetNext(&filename);
226 }
227
228 wxPuts(wxEmptyString);
229 }
230
231 static void TestDirEnum()
232 {
233 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
234
235 wxString cwd = wxGetCwd();
236 if ( !wxDir::Exists(cwd) )
237 {
238 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str());
239 return;
240 }
241
242 wxDir dir(cwd);
243 if ( !dir.IsOpened() )
244 {
245 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd.c_str());
246 return;
247 }
248
249 wxPuts(_T("Enumerating everything in current directory:"));
250 TestDirEnumHelper(dir);
251
252 wxPuts(_T("Enumerating really everything in current directory:"));
253 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
254
255 wxPuts(_T("Enumerating object files in current directory:"));
256 TestDirEnumHelper(dir, wxDIR_DEFAULT, _T("*.o*"));
257
258 wxPuts(_T("Enumerating directories in current directory:"));
259 TestDirEnumHelper(dir, wxDIR_DIRS);
260
261 wxPuts(_T("Enumerating files in current directory:"));
262 TestDirEnumHelper(dir, wxDIR_FILES);
263
264 wxPuts(_T("Enumerating files including hidden in current directory:"));
265 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
266
267 dir.Open(ROOTDIR);
268
269 wxPuts(_T("Enumerating everything in root directory:"));
270 TestDirEnumHelper(dir, wxDIR_DEFAULT);
271
272 wxPuts(_T("Enumerating directories in root directory:"));
273 TestDirEnumHelper(dir, wxDIR_DIRS);
274
275 wxPuts(_T("Enumerating files in root directory:"));
276 TestDirEnumHelper(dir, wxDIR_FILES);
277
278 wxPuts(_T("Enumerating files including hidden in root directory:"));
279 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
280
281 wxPuts(_T("Enumerating files in non existing directory:"));
282 wxDir dirNo(_T("nosuchdir"));
283 TestDirEnumHelper(dirNo);
284 }
285
286 class DirPrintTraverser : public wxDirTraverser
287 {
288 public:
289 virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename))
290 {
291 return wxDIR_CONTINUE;
292 }
293
294 virtual wxDirTraverseResult OnDir(const wxString& dirname)
295 {
296 wxString path, name, ext;
297 wxSplitPath(dirname, &path, &name, &ext);
298
299 if ( !ext.empty() )
300 name << _T('.') << ext;
301
302 wxString indent;
303 for ( const wxChar *p = path.c_str(); *p; p++ )
304 {
305 if ( wxIsPathSeparator(*p) )
306 indent += _T(" ");
307 }
308
309 wxPrintf(_T("%s%s\n"), indent.c_str(), name.c_str());
310
311 return wxDIR_CONTINUE;
312 }
313 };
314
315 static void TestDirTraverse()
316 {
317 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
318
319 // enum all files
320 wxArrayString files;
321 size_t n = wxDir::GetAllFiles(TESTDIR, &files);
322 wxPrintf(_T("There are %u files under '%s'\n"), n, TESTDIR);
323 if ( n > 1 )
324 {
325 wxPrintf(_T("First one is '%s'\n"), files[0u].c_str());
326 wxPrintf(_T(" last one is '%s'\n"), files[n - 1].c_str());
327 }
328
329 // enum again with custom traverser
330 wxPuts(_T("Now enumerating directories:"));
331 wxDir dir(TESTDIR);
332 DirPrintTraverser traverser;
333 dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
334 }
335
336 static void TestDirExists()
337 {
338 wxPuts(_T("*** Testing wxDir::Exists() ***"));
339
340 static const wxChar *dirnames[] =
341 {
342 _T("."),
343 #if defined(__WXMSW__)
344 _T("c:"),
345 _T("c:\\"),
346 _T("\\\\share\\file"),
347 _T("c:\\dos"),
348 _T("c:\\dos\\"),
349 _T("c:\\dos\\\\"),
350 _T("c:\\autoexec.bat"),
351 #elif defined(__UNIX__)
352 _T("/"),
353 _T("//"),
354 _T("/usr/bin"),
355 _T("/usr//bin"),
356 _T("/usr///bin"),
357 #endif
358 };
359
360 for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ )
361 {
362 wxPrintf(_T("%-40s: %s\n"),
363 dirnames[n],
364 wxDir::Exists(dirnames[n]) ? _T("exists")
365 : _T("doesn't exist"));
366 }
367 }
368
369 #endif // TEST_DIR
370
371 // ----------------------------------------------------------------------------
372 // wxDllLoader
373 // ----------------------------------------------------------------------------
374
375 #ifdef TEST_DLLLOADER
376
377 #include "wx/dynlib.h"
378
379 static void TestDllLoad()
380 {
381 #if defined(__WXMSW__)
382 static const wxChar *LIB_NAME = _T("kernel32.dll");
383 static const wxChar *FUNC_NAME = _T("lstrlenA");
384 #elif defined(__UNIX__)
385 // weird: using just libc.so does *not* work!
386 static const wxChar *LIB_NAME = _T("/lib/libc.so.6");
387 static const wxChar *FUNC_NAME = _T("strlen");
388 #else
389 #error "don't know how to test wxDllLoader on this platform"
390 #endif
391
392 wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
393
394 wxDynamicLibrary lib(LIB_NAME);
395 if ( !lib.IsLoaded() )
396 {
397 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME);
398 }
399 else
400 {
401 typedef int (*wxStrlenType)(const char *);
402 wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
403 if ( !pfnStrlen )
404 {
405 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
406 FUNC_NAME, LIB_NAME);
407 }
408 else
409 {
410 wxPrintf(_T("Calling %s dynamically loaded from %s "),
411 FUNC_NAME, LIB_NAME);
412
413 if ( pfnStrlen("foo") != 3 )
414 {
415 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
416 }
417 else
418 {
419 wxPuts(_T("... ok"));
420 }
421 }
422 }
423 }
424
425 #if defined(__WXMSW__) || defined(__UNIX__)
426
427 static void TestDllListLoaded()
428 {
429 wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
430
431 puts("\nLoaded modules:");
432 wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
433 const size_t count = dlls.GetCount();
434 for ( size_t n = 0; n < count; ++n )
435 {
436 const wxDynamicLibraryDetails& details = dlls[n];
437 printf("%-45s", details.GetPath().mb_str());
438
439 void *addr;
440 size_t len;
441 if ( details.GetAddress(&addr, &len) )
442 {
443 printf(" %08lx:%08lx",
444 (unsigned long)addr, (unsigned long)((char *)addr + len));
445 }
446
447 printf(" %s\n", details.GetVersion().mb_str());
448 }
449 }
450
451 #endif
452
453 #endif // TEST_DLLLOADER
454
455 // ----------------------------------------------------------------------------
456 // wxGet/SetEnv
457 // ----------------------------------------------------------------------------
458
459 #ifdef TEST_ENVIRON
460
461 #include "wx/utils.h"
462
463 static wxString MyGetEnv(const wxString& var)
464 {
465 wxString val;
466 if ( !wxGetEnv(var, &val) )
467 val = _T("<empty>");
468 else
469 val = wxString(_T('\'')) + val + _T('\'');
470
471 return val;
472 }
473
474 static void TestEnvironment()
475 {
476 const wxChar *var = _T("wxTestVar");
477
478 wxPuts(_T("*** testing environment access functions ***"));
479
480 wxPrintf(_T("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
481 wxSetEnv(var, _T("value for wxTestVar"));
482 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
483 wxSetEnv(var, _T("another value"));
484 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
485 wxUnsetEnv(var);
486 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
487 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
488 }
489
490 #endif // TEST_ENVIRON
491
492 // ----------------------------------------------------------------------------
493 // wxExecute
494 // ----------------------------------------------------------------------------
495
496 #ifdef TEST_EXECUTE
497
498 #include "wx/utils.h"
499
500 static void TestExecute()
501 {
502 wxPuts(_T("*** testing wxExecute ***"));
503
504 #ifdef __UNIX__
505 #define COMMAND "cat -n ../../Makefile" // "echo hi"
506 #define SHELL_COMMAND "echo hi from shell"
507 #define REDIRECT_COMMAND COMMAND // "date"
508 #elif defined(__WXMSW__)
509 #define COMMAND "command.com /c echo hi"
510 #define SHELL_COMMAND "echo hi"
511 #define REDIRECT_COMMAND COMMAND
512 #else
513 #error "no command to exec"
514 #endif // OS
515
516 wxPrintf(_T("Testing wxShell: "));
517 fflush(stdout);
518 if ( wxShell(_T(SHELL_COMMAND)) )
519 wxPuts(_T("Ok."));
520 else
521 wxPuts(_T("ERROR."));
522
523 wxPrintf(_T("Testing wxExecute: "));
524 fflush(stdout);
525 if ( wxExecute(_T(COMMAND), true /* sync */) == 0 )
526 wxPuts(_T("Ok."));
527 else
528 wxPuts(_T("ERROR."));
529
530 #if 0 // no, it doesn't work (yet?)
531 wxPrintf(_T("Testing async wxExecute: "));
532 fflush(stdout);
533 if ( wxExecute(COMMAND) != 0 )
534 wxPuts(_T("Ok (command launched)."));
535 else
536 wxPuts(_T("ERROR."));
537 #endif // 0
538
539 wxPrintf(_T("Testing wxExecute with redirection:\n"));
540 wxArrayString output;
541 if ( wxExecute(_T(REDIRECT_COMMAND), output) != 0 )
542 {
543 wxPuts(_T("ERROR."));
544 }
545 else
546 {
547 size_t count = output.GetCount();
548 for ( size_t n = 0; n < count; n++ )
549 {
550 wxPrintf(_T("\t%s\n"), output[n].c_str());
551 }
552
553 wxPuts(_T("Ok."));
554 }
555 }
556
557 #endif // TEST_EXECUTE
558
559 // ----------------------------------------------------------------------------
560 // file
561 // ----------------------------------------------------------------------------
562
563 #ifdef TEST_FILE
564
565 #include "wx/file.h"
566 #include "wx/ffile.h"
567 #include "wx/textfile.h"
568
569 static void TestFileRead()
570 {
571 wxPuts(_T("*** wxFile read test ***"));
572
573 wxFile file(_T("testdata.fc"));
574 if ( file.IsOpened() )
575 {
576 wxPrintf(_T("File length: %lu\n"), file.Length());
577
578 wxPuts(_T("File dump:\n----------"));
579
580 static const size_t len = 1024;
581 wxChar buf[len];
582 for ( ;; )
583 {
584 size_t nRead = file.Read(buf, len);
585 if ( nRead == (size_t)wxInvalidOffset )
586 {
587 wxPrintf(_T("Failed to read the file."));
588 break;
589 }
590
591 fwrite(buf, nRead, 1, stdout);
592
593 if ( nRead < len )
594 break;
595 }
596
597 wxPuts(_T("----------"));
598 }
599 else
600 {
601 wxPrintf(_T("ERROR: can't open test file.\n"));
602 }
603
604 wxPuts(wxEmptyString);
605 }
606
607 static void TestTextFileRead()
608 {
609 wxPuts(_T("*** wxTextFile read test ***"));
610
611 wxTextFile file(_T("testdata.fc"));
612 if ( file.Open() )
613 {
614 wxPrintf(_T("Number of lines: %u\n"), file.GetLineCount());
615 wxPrintf(_T("Last line: '%s'\n"), file.GetLastLine().c_str());
616
617 wxString s;
618
619 wxPuts(_T("\nDumping the entire file:"));
620 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
621 {
622 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
623 }
624 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
625
626 wxPuts(_T("\nAnd now backwards:"));
627 for ( s = file.GetLastLine();
628 file.GetCurrentLine() != 0;
629 s = file.GetPrevLine() )
630 {
631 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
632 }
633 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
634 }
635 else
636 {
637 wxPrintf(_T("ERROR: can't open '%s'\n"), file.GetName());
638 }
639
640 wxPuts(wxEmptyString);
641 }
642
643 static void TestFileCopy()
644 {
645 wxPuts(_T("*** Testing wxCopyFile ***"));
646
647 static const wxChar *filename1 = _T("testdata.fc");
648 static const wxChar *filename2 = _T("test2");
649 if ( !wxCopyFile(filename1, filename2) )
650 {
651 wxPuts(_T("ERROR: failed to copy file"));
652 }
653 else
654 {
655 wxFFile f1(filename1, _T("rb")),
656 f2(filename2, _T("rb"));
657
658 if ( !f1.IsOpened() || !f2.IsOpened() )
659 {
660 wxPuts(_T("ERROR: failed to open file(s)"));
661 }
662 else
663 {
664 wxString s1, s2;
665 if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
666 {
667 wxPuts(_T("ERROR: failed to read file(s)"));
668 }
669 else
670 {
671 if ( (s1.length() != s2.length()) ||
672 (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
673 {
674 wxPuts(_T("ERROR: copy error!"));
675 }
676 else
677 {
678 wxPuts(_T("File was copied ok."));
679 }
680 }
681 }
682 }
683
684 if ( !wxRemoveFile(filename2) )
685 {
686 wxPuts(_T("ERROR: failed to remove the file"));
687 }
688
689 wxPuts(wxEmptyString);
690 }
691
692 #endif // TEST_FILE
693
694 // ----------------------------------------------------------------------------
695 // wxFileConfig
696 // ----------------------------------------------------------------------------
697
698 #ifdef TEST_FILECONF
699
700 #include "wx/confbase.h"
701 #include "wx/fileconf.h"
702
703 static const struct FileConfTestData
704 {
705 const wxChar *name; // value name
706 const wxChar *value; // the value from the file
707 } fcTestData[] =
708 {
709 { _T("value1"), _T("one") },
710 { _T("value2"), _T("two") },
711 { _T("novalue"), _T("default") },
712 };
713
714 static void TestFileConfRead()
715 {
716 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
717
718 wxFileConfig fileconf(_T("test"), wxEmptyString,
719 _T("testdata.fc"), wxEmptyString,
720 wxCONFIG_USE_RELATIVE_PATH);
721
722 // test simple reading
723 wxPuts(_T("\nReading config file:"));
724 wxString defValue(_T("default")), value;
725 for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
726 {
727 const FileConfTestData& data = fcTestData[n];
728 value = fileconf.Read(data.name, defValue);
729 wxPrintf(_T("\t%s = %s "), data.name, value.c_str());
730 if ( value == data.value )
731 {
732 wxPuts(_T("(ok)"));
733 }
734 else
735 {
736 wxPrintf(_T("(ERROR: should be %s)\n"), data.value);
737 }
738 }
739
740 // test enumerating the entries
741 wxPuts(_T("\nEnumerating all root entries:"));
742 long dummy;
743 wxString name;
744 bool cont = fileconf.GetFirstEntry(name, dummy);
745 while ( cont )
746 {
747 wxPrintf(_T("\t%s = %s\n"),
748 name.c_str(),
749 fileconf.Read(name.c_str(), _T("ERROR")).c_str());
750
751 cont = fileconf.GetNextEntry(name, dummy);
752 }
753
754 static const wxChar *testEntry = _T("TestEntry");
755 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
756 fileconf.Write(testEntry, _T("A value"));
757 fileconf.DeleteEntry(testEntry);
758 wxPrintf(fileconf.HasEntry(testEntry) ? _T("ERROR\n") : _T("ok\n"));
759 }
760
761 #endif // TEST_FILECONF
762
763 // ----------------------------------------------------------------------------
764 // wxFileName
765 // ----------------------------------------------------------------------------
766
767 #ifdef TEST_FILENAME
768
769 #include "wx/filename.h"
770
771 #if 0
772 static void DumpFileName(const wxChar *desc, const wxFileName& fn)
773 {
774 wxPuts(desc);
775
776 wxString full = fn.GetFullPath();
777
778 wxString vol, path, name, ext;
779 wxFileName::SplitPath(full, &vol, &path, &name, &ext);
780
781 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
782 full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
783
784 wxFileName::SplitPath(full, &path, &name, &ext);
785 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
786 path.c_str(), name.c_str(), ext.c_str());
787
788 wxPrintf(_T("path is also:\t'%s'\n"), fn.GetPath().c_str());
789 wxPrintf(_T("with volume: \t'%s'\n"),
790 fn.GetPath(wxPATH_GET_VOLUME).c_str());
791 wxPrintf(_T("with separator:\t'%s'\n"),
792 fn.GetPath(wxPATH_GET_SEPARATOR).c_str());
793 wxPrintf(_T("with both: \t'%s'\n"),
794 fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str());
795
796 wxPuts(_T("The directories in the path are:"));
797 wxArrayString dirs = fn.GetDirs();
798 size_t count = dirs.GetCount();
799 for ( size_t n = 0; n < count; n++ )
800 {
801 wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str());
802 }
803 }
804 #endif
805
806 static void TestFileNameTemp()
807 {
808 wxPuts(_T("*** testing wxFileName temp file creation ***"));
809
810 static const wxChar *tmpprefixes[] =
811 {
812 _T(""),
813 _T("foo"),
814 _T(".."),
815 _T("../bar"),
816 #ifdef __UNIX__
817 _T("/tmp/foo"),
818 _T("/tmp/foo/bar"), // this one must be an error
819 #endif // __UNIX__
820 };
821
822 for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
823 {
824 wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
825 if ( path.empty() )
826 {
827 // "error" is not in upper case because it may be ok
828 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
829 }
830 else
831 {
832 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
833 tmpprefixes[n], path.c_str());
834
835 if ( !wxRemoveFile(path) )
836 {
837 wxLogWarning(_T("Failed to remove temp file '%s'"),
838 path.c_str());
839 }
840 }
841 }
842 }
843
844 static void TestFileNameDirManip()
845 {
846 // TODO: test AppendDir(), RemoveDir(), ...
847 }
848
849 static void TestFileNameComparison()
850 {
851 // TODO!
852 }
853
854 static void TestFileNameOperations()
855 {
856 // TODO!
857 }
858
859 static void TestFileNameCwd()
860 {
861 // TODO!
862 }
863
864 #endif // TEST_FILENAME
865
866 // ----------------------------------------------------------------------------
867 // wxFileName time functions
868 // ----------------------------------------------------------------------------
869
870 #ifdef TEST_FILETIME
871
872 #include <wx/filename.h>
873 #include <wx/datetime.h>
874
875 static void TestFileGetTimes()
876 {
877 wxFileName fn(_T("testdata.fc"));
878
879 wxDateTime dtAccess, dtMod, dtCreate;
880 if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
881 {
882 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
883 }
884 else
885 {
886 static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S");
887
888 wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str());
889 wxPrintf(_T("Creation: \t%s\n"), dtCreate.Format(fmt).c_str());
890 wxPrintf(_T("Last read: \t%s\n"), dtAccess.Format(fmt).c_str());
891 wxPrintf(_T("Last write: \t%s\n"), dtMod.Format(fmt).c_str());
892 }
893 }
894
895 #if 0
896 static void TestFileSetTimes()
897 {
898 wxFileName fn(_T("testdata.fc"));
899
900 if ( !fn.Touch() )
901 {
902 wxPrintf(_T("ERROR: Touch() failed.\n"));
903 }
904 }
905 #endif
906
907 #endif // TEST_FILETIME
908
909 // ----------------------------------------------------------------------------
910 // wxLocale
911 // ----------------------------------------------------------------------------
912
913 #ifdef TEST_LOCALE
914
915 #include "wx/intl.h"
916 #include "wx/utils.h" // for wxSetEnv
917
918 static wxLocale gs_localeDefault(wxLANGUAGE_ENGLISH);
919
920 // find the name of the language from its value
921 static const wxChar *GetLangName(int lang)
922 {
923 static const wxChar *languageNames[] =
924 {
925 _T("DEFAULT"),
926 _T("UNKNOWN"),
927 _T("ABKHAZIAN"),
928 _T("AFAR"),
929 _T("AFRIKAANS"),
930 _T("ALBANIAN"),
931 _T("AMHARIC"),
932 _T("ARABIC"),
933 _T("ARABIC_ALGERIA"),
934 _T("ARABIC_BAHRAIN"),
935 _T("ARABIC_EGYPT"),
936 _T("ARABIC_IRAQ"),
937 _T("ARABIC_JORDAN"),
938 _T("ARABIC_KUWAIT"),
939 _T("ARABIC_LEBANON"),
940 _T("ARABIC_LIBYA"),
941 _T("ARABIC_MOROCCO"),
942 _T("ARABIC_OMAN"),
943 _T("ARABIC_QATAR"),
944 _T("ARABIC_SAUDI_ARABIA"),
945 _T("ARABIC_SUDAN"),
946 _T("ARABIC_SYRIA"),
947 _T("ARABIC_TUNISIA"),
948 _T("ARABIC_UAE"),
949 _T("ARABIC_YEMEN"),
950 _T("ARMENIAN"),
951 _T("ASSAMESE"),
952 _T("AYMARA"),
953 _T("AZERI"),
954 _T("AZERI_CYRILLIC"),
955 _T("AZERI_LATIN"),
956 _T("BASHKIR"),
957 _T("BASQUE"),
958 _T("BELARUSIAN"),
959 _T("BENGALI"),
960 _T("BHUTANI"),
961 _T("BIHARI"),
962 _T("BISLAMA"),
963 _T("BRETON"),
964 _T("BULGARIAN"),
965 _T("BURMESE"),
966 _T("CAMBODIAN"),
967 _T("CATALAN"),
968 _T("CHINESE"),
969 _T("CHINESE_SIMPLIFIED"),
970 _T("CHINESE_TRADITIONAL"),
971 _T("CHINESE_HONGKONG"),
972 _T("CHINESE_MACAU"),
973 _T("CHINESE_SINGAPORE"),
974 _T("CHINESE_TAIWAN"),
975 _T("CORSICAN"),
976 _T("CROATIAN"),
977 _T("CZECH"),
978 _T("DANISH"),
979 _T("DUTCH"),
980 _T("DUTCH_BELGIAN"),
981 _T("ENGLISH"),
982 _T("ENGLISH_UK"),
983 _T("ENGLISH_US"),
984 _T("ENGLISH_AUSTRALIA"),
985 _T("ENGLISH_BELIZE"),
986 _T("ENGLISH_BOTSWANA"),
987 _T("ENGLISH_CANADA"),
988 _T("ENGLISH_CARIBBEAN"),
989 _T("ENGLISH_DENMARK"),
990 _T("ENGLISH_EIRE"),
991 _T("ENGLISH_JAMAICA"),
992 _T("ENGLISH_NEW_ZEALAND"),
993 _T("ENGLISH_PHILIPPINES"),
994 _T("ENGLISH_SOUTH_AFRICA"),
995 _T("ENGLISH_TRINIDAD"),
996 _T("ENGLISH_ZIMBABWE"),
997 _T("ESPERANTO"),
998 _T("ESTONIAN"),
999 _T("FAEROESE"),
1000 _T("FARSI"),
1001 _T("FIJI"),
1002 _T("FINNISH"),
1003 _T("FRENCH"),
1004 _T("FRENCH_BELGIAN"),
1005 _T("FRENCH_CANADIAN"),
1006 _T("FRENCH_LUXEMBOURG"),
1007 _T("FRENCH_MONACO"),
1008 _T("FRENCH_SWISS"),
1009 _T("FRISIAN"),
1010 _T("GALICIAN"),
1011 _T("GEORGIAN"),
1012 _T("GERMAN"),
1013 _T("GERMAN_AUSTRIAN"),
1014 _T("GERMAN_BELGIUM"),
1015 _T("GERMAN_LIECHTENSTEIN"),
1016 _T("GERMAN_LUXEMBOURG"),
1017 _T("GERMAN_SWISS"),
1018 _T("GREEK"),
1019 _T("GREENLANDIC"),
1020 _T("GUARANI"),
1021 _T("GUJARATI"),
1022 _T("HAUSA"),
1023 _T("HEBREW"),
1024 _T("HINDI"),
1025 _T("HUNGARIAN"),
1026 _T("ICELANDIC"),
1027 _T("INDONESIAN"),
1028 _T("INTERLINGUA"),
1029 _T("INTERLINGUE"),
1030 _T("INUKTITUT"),
1031 _T("INUPIAK"),
1032 _T("IRISH"),
1033 _T("ITALIAN"),
1034 _T("ITALIAN_SWISS"),
1035 _T("JAPANESE"),
1036 _T("JAVANESE"),
1037 _T("KANNADA"),
1038 _T("KASHMIRI"),
1039 _T("KASHMIRI_INDIA"),
1040 _T("KAZAKH"),
1041 _T("KERNEWEK"),
1042 _T("KINYARWANDA"),
1043 _T("KIRGHIZ"),
1044 _T("KIRUNDI"),
1045 _T("KONKANI"),
1046 _T("KOREAN"),
1047 _T("KURDISH"),
1048 _T("LAOTHIAN"),
1049 _T("LATIN"),
1050 _T("LATVIAN"),
1051 _T("LINGALA"),
1052 _T("LITHUANIAN"),
1053 _T("MACEDONIAN"),
1054 _T("MALAGASY"),
1055 _T("MALAY"),
1056 _T("MALAYALAM"),
1057 _T("MALAY_BRUNEI_DARUSSALAM"),
1058 _T("MALAY_MALAYSIA"),
1059 _T("MALTESE"),
1060 _T("MANIPURI"),
1061 _T("MAORI"),
1062 _T("MARATHI"),
1063 _T("MOLDAVIAN"),
1064 _T("MONGOLIAN"),
1065 _T("NAURU"),
1066 _T("NEPALI"),
1067 _T("NEPALI_INDIA"),
1068 _T("NORWEGIAN_BOKMAL"),
1069 _T("NORWEGIAN_NYNORSK"),
1070 _T("OCCITAN"),
1071 _T("ORIYA"),
1072 _T("OROMO"),
1073 _T("PASHTO"),
1074 _T("POLISH"),
1075 _T("PORTUGUESE"),
1076 _T("PORTUGUESE_BRAZILIAN"),
1077 _T("PUNJABI"),
1078 _T("QUECHUA"),
1079 _T("RHAETO_ROMANCE"),
1080 _T("ROMANIAN"),
1081 _T("RUSSIAN"),
1082 _T("RUSSIAN_UKRAINE"),
1083 _T("SAMOAN"),
1084 _T("SANGHO"),
1085 _T("SANSKRIT"),
1086 _T("SCOTS_GAELIC"),
1087 _T("SERBIAN"),
1088 _T("SERBIAN_CYRILLIC"),
1089 _T("SERBIAN_LATIN"),
1090 _T("SERBO_CROATIAN"),
1091 _T("SESOTHO"),
1092 _T("SETSWANA"),
1093 _T("SHONA"),
1094 _T("SINDHI"),
1095 _T("SINHALESE"),
1096 _T("SISWATI"),
1097 _T("SLOVAK"),
1098 _T("SLOVENIAN"),
1099 _T("SOMALI"),
1100 _T("SPANISH"),
1101 _T("SPANISH_ARGENTINA"),
1102 _T("SPANISH_BOLIVIA"),
1103 _T("SPANISH_CHILE"),
1104 _T("SPANISH_COLOMBIA"),
1105 _T("SPANISH_COSTA_RICA"),
1106 _T("SPANISH_DOMINICAN_REPUBLIC"),
1107 _T("SPANISH_ECUADOR"),
1108 _T("SPANISH_EL_SALVADOR"),
1109 _T("SPANISH_GUATEMALA"),
1110 _T("SPANISH_HONDURAS"),
1111 _T("SPANISH_MEXICAN"),
1112 _T("SPANISH_MODERN"),
1113 _T("SPANISH_NICARAGUA"),
1114 _T("SPANISH_PANAMA"),
1115 _T("SPANISH_PARAGUAY"),
1116 _T("SPANISH_PERU"),
1117 _T("SPANISH_PUERTO_RICO"),
1118 _T("SPANISH_URUGUAY"),
1119 _T("SPANISH_US"),
1120 _T("SPANISH_VENEZUELA"),
1121 _T("SUNDANESE"),
1122 _T("SWAHILI"),
1123 _T("SWEDISH"),
1124 _T("SWEDISH_FINLAND"),
1125 _T("TAGALOG"),
1126 _T("TAJIK"),
1127 _T("TAMIL"),
1128 _T("TATAR"),
1129 _T("TELUGU"),
1130 _T("THAI"),
1131 _T("TIBETAN"),
1132 _T("TIGRINYA"),
1133 _T("TONGA"),
1134 _T("TSONGA"),
1135 _T("TURKISH"),
1136 _T("TURKMEN"),
1137 _T("TWI"),
1138 _T("UIGHUR"),
1139 _T("UKRAINIAN"),
1140 _T("URDU"),
1141 _T("URDU_INDIA"),
1142 _T("URDU_PAKISTAN"),
1143 _T("UZBEK"),
1144 _T("UZBEK_CYRILLIC"),
1145 _T("UZBEK_LATIN"),
1146 _T("VIETNAMESE"),
1147 _T("VOLAPUK"),
1148 _T("WELSH"),
1149 _T("WOLOF"),
1150 _T("XHOSA"),
1151 _T("YIDDISH"),
1152 _T("YORUBA"),
1153 _T("ZHUANG"),
1154 _T("ZULU"),
1155 };
1156
1157 if ( (size_t)lang < WXSIZEOF(languageNames) )
1158 return languageNames[lang];
1159 else
1160 return _T("INVALID");
1161 }
1162
1163 static void TestDefaultLang()
1164 {
1165 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1166
1167 static const wxChar *langStrings[] =
1168 {
1169 NULL, // system default
1170 _T("C"),
1171 _T("fr"),
1172 _T("fr_FR"),
1173 _T("en"),
1174 _T("en_GB"),
1175 _T("en_US"),
1176 _T("de_DE.iso88591"),
1177 _T("german"),
1178 _T("?"), // invalid lang spec
1179 _T("klingonese"), // I bet on some systems it does exist...
1180 };
1181
1182 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1183 wxLocale::GetSystemEncodingName().c_str(),
1184 wxLocale::GetSystemEncoding());
1185
1186 for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
1187 {
1188 const wxChar *langStr = langStrings[n];
1189 if ( langStr )
1190 {
1191 // FIXME: this doesn't do anything at all under Windows, we need
1192 // to create a new wxLocale!
1193 wxSetEnv(_T("LC_ALL"), langStr);
1194 }
1195
1196 int lang = gs_localeDefault.GetSystemLanguage();
1197 wxPrintf(_T("Locale for '%s' is %s.\n"),
1198 langStr ? langStr : _T("system default"), GetLangName(lang));
1199 }
1200 }
1201
1202 #endif // TEST_LOCALE
1203
1204 // ----------------------------------------------------------------------------
1205 // MIME types
1206 // ----------------------------------------------------------------------------
1207
1208 #ifdef TEST_MIME
1209
1210 #include "wx/mimetype.h"
1211
1212 static void TestMimeEnum()
1213 {
1214 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1215
1216 wxArrayString mimetypes;
1217
1218 size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
1219
1220 wxPrintf(_T("*** All %u known filetypes: ***\n"), count);
1221
1222 wxArrayString exts;
1223 wxString desc;
1224
1225 for ( size_t n = 0; n < count; n++ )
1226 {
1227 wxFileType *filetype =
1228 wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
1229 if ( !filetype )
1230 {
1231 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1232 mimetypes[n].c_str());
1233 continue;
1234 }
1235
1236 filetype->GetDescription(&desc);
1237 filetype->GetExtensions(exts);
1238
1239 filetype->GetIcon(NULL);
1240
1241 wxString extsAll;
1242 for ( size_t e = 0; e < exts.GetCount(); e++ )
1243 {
1244 if ( e > 0 )
1245 extsAll << _T(", ");
1246 extsAll += exts[e];
1247 }
1248
1249 wxPrintf(_T("\t%s: %s (%s)\n"),
1250 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
1251 }
1252
1253 wxPuts(wxEmptyString);
1254 }
1255
1256 static void TestMimeOverride()
1257 {
1258 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1259
1260 static const wxChar *mailcap = _T("/tmp/mailcap");
1261 static const wxChar *mimetypes = _T("/tmp/mime.types");
1262
1263 if ( wxFile::Exists(mailcap) )
1264 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1265 mailcap,
1266 wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR"));
1267 else
1268 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1269 mailcap);
1270
1271 if ( wxFile::Exists(mimetypes) )
1272 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1273 mimetypes,
1274 wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR"));
1275 else
1276 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1277 mimetypes);
1278
1279 wxPuts(wxEmptyString);
1280 }
1281
1282 static void TestMimeFilename()
1283 {
1284 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1285
1286 static const wxChar *filenames[] =
1287 {
1288 _T("readme.txt"),
1289 _T("document.pdf"),
1290 _T("image.gif"),
1291 _T("picture.jpeg"),
1292 };
1293
1294 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
1295 {
1296 const wxString fname = filenames[n];
1297 wxString ext = fname.AfterLast(_T('.'));
1298 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
1299 if ( !ft )
1300 {
1301 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str());
1302 }
1303 else
1304 {
1305 wxString desc;
1306 if ( !ft->GetDescription(&desc) )
1307 desc = _T("<no description>");
1308
1309 wxString cmd;
1310 if ( !ft->GetOpenCommand(&cmd,
1311 wxFileType::MessageParameters(fname, wxEmptyString)) )
1312 cmd = _T("<no command available>");
1313 else
1314 cmd = wxString(_T('"')) + cmd + _T('"');
1315
1316 wxPrintf(_T("To open %s (%s) do %s.\n"),
1317 fname.c_str(), desc.c_str(), cmd.c_str());
1318
1319 delete ft;
1320 }
1321 }
1322
1323 wxPuts(wxEmptyString);
1324 }
1325
1326 static void TestMimeAssociate()
1327 {
1328 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1329
1330 wxFileTypeInfo ftInfo(
1331 _T("application/x-xyz"),
1332 _T("xyzview '%s'"), // open cmd
1333 _T(""), // print cmd
1334 _T("XYZ File"), // description
1335 _T(".xyz"), // extensions
1336 NULL // end of extensions
1337 );
1338 ftInfo.SetShortDesc(_T("XYZFile")); // used under Win32 only
1339
1340 wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
1341 if ( !ft )
1342 {
1343 wxPuts(_T("ERROR: failed to create association!"));
1344 }
1345 else
1346 {
1347 // TODO: read it back
1348 delete ft;
1349 }
1350
1351 wxPuts(wxEmptyString);
1352 }
1353
1354 #endif // TEST_MIME
1355
1356 // ----------------------------------------------------------------------------
1357 // misc information functions
1358 // ----------------------------------------------------------------------------
1359
1360 #ifdef TEST_INFO_FUNCTIONS
1361
1362 #include "wx/utils.h"
1363
1364 static void TestDiskInfo()
1365 {
1366 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1367
1368 for ( ;; )
1369 {
1370 wxChar pathname[128];
1371 wxPrintf(_T("\nEnter a directory name: "));
1372 if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
1373 break;
1374
1375 // kill the last '\n'
1376 pathname[wxStrlen(pathname) - 1] = 0;
1377
1378 wxLongLong total, free;
1379 if ( !wxGetDiskSpace(pathname, &total, &free) )
1380 {
1381 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1382 }
1383 else
1384 {
1385 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1386 (total / 1024).ToString().c_str(),
1387 (free / 1024).ToString().c_str(),
1388 pathname);
1389 }
1390 }
1391 }
1392
1393 static void TestOsInfo()
1394 {
1395 wxPuts(_T("*** Testing OS info functions ***\n"));
1396
1397 int major, minor;
1398 wxGetOsVersion(&major, &minor);
1399 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1400 wxGetOsDescription().c_str(), major, minor);
1401
1402 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
1403
1404 wxPrintf(_T("Host name is %s (%s).\n"),
1405 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1406
1407 wxPuts(wxEmptyString);
1408 }
1409
1410 static void TestUserInfo()
1411 {
1412 wxPuts(_T("*** Testing user info functions ***\n"));
1413
1414 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1415 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1416 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1417 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1418
1419 wxPuts(wxEmptyString);
1420 }
1421
1422 #endif // TEST_INFO_FUNCTIONS
1423
1424 // ----------------------------------------------------------------------------
1425 // path list
1426 // ----------------------------------------------------------------------------
1427
1428 #ifdef TEST_PATHLIST
1429
1430 #ifdef __UNIX__
1431 #define CMD_IN_PATH _T("ls")
1432 #else
1433 #define CMD_IN_PATH _T("command.com")
1434 #endif
1435
1436 static void TestPathList()
1437 {
1438 wxPuts(_T("*** Testing wxPathList ***\n"));
1439
1440 wxPathList pathlist;
1441 pathlist.AddEnvList(_T("PATH"));
1442 wxString path = pathlist.FindValidPath(CMD_IN_PATH);
1443 if ( path.empty() )
1444 {
1445 wxPrintf(_T("ERROR: command not found in the path.\n"));
1446 }
1447 else
1448 {
1449 wxPrintf(_T("Command found in the path as '%s'.\n"), path.c_str());
1450 }
1451 }
1452
1453 #endif // TEST_PATHLIST
1454
1455 // ----------------------------------------------------------------------------
1456 // regular expressions
1457 // ----------------------------------------------------------------------------
1458
1459 #ifdef TEST_REGEX
1460
1461 #include "wx/regex.h"
1462
1463 static void TestRegExInteractive()
1464 {
1465 wxPuts(_T("*** Testing RE interactively ***"));
1466
1467 for ( ;; )
1468 {
1469 wxChar pattern[128];
1470 wxPrintf(_T("\nEnter a pattern: "));
1471 if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
1472 break;
1473
1474 // kill the last '\n'
1475 pattern[wxStrlen(pattern) - 1] = 0;
1476
1477 wxRegEx re;
1478 if ( !re.Compile(pattern) )
1479 {
1480 continue;
1481 }
1482
1483 wxChar text[128];
1484 for ( ;; )
1485 {
1486 wxPrintf(_T("Enter text to match: "));
1487 if ( !wxFgets(text, WXSIZEOF(text), stdin) )
1488 break;
1489
1490 // kill the last '\n'
1491 text[wxStrlen(text) - 1] = 0;
1492
1493 if ( !re.Matches(text) )
1494 {
1495 wxPrintf(_T("No match.\n"));
1496 }
1497 else
1498 {
1499 wxPrintf(_T("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());
1500
1501 size_t start, len;
1502 for ( size_t n = 1; ; n++ )
1503 {
1504 if ( !re.GetMatch(&start, &len, n) )
1505 {
1506 break;
1507 }
1508
1509 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1510 n, wxString(text + start, len).c_str());
1511 }
1512 }
1513 }
1514 }
1515 }
1516
1517 #endif // TEST_REGEX
1518
1519 // ----------------------------------------------------------------------------
1520 // database
1521 // ----------------------------------------------------------------------------
1522
1523 #if !wxUSE_ODBC
1524 #undef TEST_ODBC
1525 #endif
1526
1527 #ifdef TEST_ODBC
1528
1529 #include <wx/db.h>
1530
1531 static void TestDbOpen()
1532 {
1533 HENV henv;
1534 wxDb db(henv);
1535 }
1536
1537 #endif // TEST_ODBC
1538
1539 // ----------------------------------------------------------------------------
1540 // printf() tests
1541 // ----------------------------------------------------------------------------
1542
1543 /*
1544 NB: this stuff was taken from the glibc test suite and modified to build
1545 in wxWidgets: if I read the copyright below properly, this shouldn't
1546 be a problem
1547 */
1548
1549 #ifdef TEST_PRINTF
1550
1551 #ifdef wxTEST_PRINTF
1552 // use our functions from wxchar.cpp
1553 #undef wxPrintf
1554 #undef wxSprintf
1555
1556 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1557 // in the tests below
1558 int wxPrintf( const wxChar *format, ... );
1559 int wxSprintf( wxChar *str, const wxChar *format, ... );
1560 #endif
1561
1562 #include "wx/longlong.h"
1563
1564 #include <float.h>
1565
1566 static void rfg1 (void);
1567 static void rfg2 (void);
1568
1569
1570 static void
1571 fmtchk (const wxChar *fmt)
1572 {
1573 (void) wxPrintf(_T("%s:\t`"), fmt);
1574 (void) wxPrintf(fmt, 0x12);
1575 (void) wxPrintf(_T("'\n"));
1576 }
1577
1578 static void
1579 fmtst1chk (const wxChar *fmt)
1580 {
1581 (void) wxPrintf(_T("%s:\t`"), fmt);
1582 (void) wxPrintf(fmt, 4, 0x12);
1583 (void) wxPrintf(_T("'\n"));
1584 }
1585
1586 static void
1587 fmtst2chk (const wxChar *fmt)
1588 {
1589 (void) wxPrintf(_T("%s:\t`"), fmt);
1590 (void) wxPrintf(fmt, 4, 4, 0x12);
1591 (void) wxPrintf(_T("'\n"));
1592 }
1593
1594 /* This page is covered by the following copyright: */
1595
1596 /* (C) Copyright C E Chew
1597 *
1598 * Feel free to copy, use and distribute this software provided:
1599 *
1600 * 1. you do not pretend that you wrote it
1601 * 2. you leave this copyright notice intact.
1602 */
1603
1604 /*
1605 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
1606 */
1607
1608 #define DEC -123
1609 #define INT 255
1610 #define UNS (~0)
1611
1612 /* Formatted Output Test
1613 *
1614 * This exercises the output formatting code.
1615 */
1616
1617 wxChar *PointerNull = NULL;
1618
1619 static void
1620 fp_test (void)
1621 {
1622 int i, j, k, l;
1623 wxChar buf[7];
1624 wxChar *prefix = buf;
1625 wxChar tp[20];
1626
1627 wxPuts(_T("\nFormatted output test"));
1628 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
1629 wxStrcpy(prefix, _T("%"));
1630 for (i = 0; i < 2; i++) {
1631 for (j = 0; j < 2; j++) {
1632 for (k = 0; k < 2; k++) {
1633 for (l = 0; l < 2; l++) {
1634 wxStrcpy(prefix, _T("%"));
1635 if (i == 0) wxStrcat(prefix, _T("-"));
1636 if (j == 0) wxStrcat(prefix, _T("+"));
1637 if (k == 0) wxStrcat(prefix, _T("#"));
1638 if (l == 0) wxStrcat(prefix, _T("0"));
1639 wxPrintf(_T("%5s |"), prefix);
1640 wxStrcpy(tp, prefix);
1641 wxStrcat(tp, _T("6d |"));
1642 wxPrintf(tp, DEC);
1643 wxStrcpy(tp, prefix);
1644 wxStrcat(tp, _T("6o |"));
1645 wxPrintf(tp, INT);
1646 wxStrcpy(tp, prefix);
1647 wxStrcat(tp, _T("6x |"));
1648 wxPrintf(tp, INT);
1649 wxStrcpy(tp, prefix);
1650 wxStrcat(tp, _T("6X |"));
1651 wxPrintf(tp, INT);
1652 wxStrcpy(tp, prefix);
1653 wxStrcat(tp, _T("6u |"));
1654 wxPrintf(tp, UNS);
1655 wxPrintf(_T("\n"));
1656 }
1657 }
1658 }
1659 }
1660 wxPrintf(_T("%10s\n"), PointerNull);
1661 wxPrintf(_T("%-10s\n"), PointerNull);
1662 }
1663
1664 static void TestPrintf()
1665 {
1666 static wxChar shortstr[] = _T("Hi, Z.");
1667 static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \
1668 I am ready for my first lesson today.");
1669 int result = 0;
1670 wxString test_format;
1671
1672 fmtchk(_T("%.4x"));
1673 fmtchk(_T("%04x"));
1674 fmtchk(_T("%4.4x"));
1675 fmtchk(_T("%04.4x"));
1676 fmtchk(_T("%4.3x"));
1677 fmtchk(_T("%04.3x"));
1678
1679 fmtst1chk(_T("%.*x"));
1680 fmtst1chk(_T("%0*x"));
1681 fmtst2chk(_T("%*.*x"));
1682 fmtst2chk(_T("%0*.*x"));
1683
1684 wxString bad_format = _T("bad format:\t\"%b\"\n");
1685 wxPrintf(bad_format.c_str());
1686 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL);
1687
1688 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
1689 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
1690 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
1691 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
1692 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
1693 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
1694 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
1695 test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
1696 wxPrintf(test_format.c_str(), -123456);
1697 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
1698 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
1699
1700 test_format = _T("zero-padded string:\t\"%010s\"\n");
1701 wxPrintf(test_format.c_str(), shortstr);
1702 test_format = _T("left-adjusted Z string:\t\"%-010s\"\n");
1703 wxPrintf(test_format.c_str(), shortstr);
1704 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr);
1705 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr);
1706 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull);
1707 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr);
1708
1709 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
1710 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
1711 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
1712 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20);
1713 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
1714 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
1715 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
1716 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
1717 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
1718 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
1719 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
1720 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20);
1721
1722 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
1723 wxPrintf (_T(" %6.5f\n"), .1);
1724 wxPrintf (_T("x%5.4fx\n"), .5);
1725
1726 wxPrintf (_T("%#03x\n"), 1);
1727
1728 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
1729
1730 {
1731 double d = FLT_MIN;
1732 int niter = 17;
1733
1734 while (niter-- != 0)
1735 wxPrintf (_T("%.17e\n"), d / 2);
1736 fflush (stdout);
1737 }
1738
1739 #ifndef __WATCOMC__
1740 // Open Watcom cause compiler error here
1741 // Error! E173: col(24) floating-point constant too small to represent
1742 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
1743 #endif
1744
1745 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
1746 wxPrintf (FORMAT, 0.0, 0.0, 0.0);
1747 wxPrintf (FORMAT, 1.0, 1.0, 1.0);
1748 wxPrintf (FORMAT, -1.0, -1.0, -1.0);
1749 wxPrintf (FORMAT, 100.0, 100.0, 100.0);
1750 wxPrintf (FORMAT, 1000.0, 1000.0, 1000.0);
1751 wxPrintf (FORMAT, 10000.0, 10000.0, 10000.0);
1752 wxPrintf (FORMAT, 12345.0, 12345.0, 12345.0);
1753 wxPrintf (FORMAT, 100000.0, 100000.0, 100000.0);
1754 wxPrintf (FORMAT, 123456.0, 123456.0, 123456.0);
1755 #undef FORMAT
1756
1757 {
1758 wxChar buf[20];
1759 int rc = wxSnprintf (buf, WXSIZEOF(buf), _T("%30s"), _T("foo"));
1760
1761 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
1762 rc, WXSIZEOF(buf), buf);
1763 #if 0
1764 wxChar buf2[512];
1765 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
1766 wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10));
1767 #endif
1768 }
1769
1770 fp_test ();
1771
1772 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
1773 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
1774 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
1775 wxPrintf (_T("%g should be 123.456\n"), 123.456);
1776 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
1777 wxPrintf (_T("%g should be 10\n"), 10.0);
1778 wxPrintf (_T("%g should be 0.02\n"), 0.02);
1779
1780 {
1781 double x=1.0;
1782 wxPrintf(_T("%.17f\n"),(1.0/x/10.0+1.0)*x-x);
1783 }
1784
1785 {
1786 wxChar buf[200];
1787
1788 wxSprintf(buf,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
1789
1790 result |= wxStrcmp (buf,
1791 _T("onetwo three "));
1792
1793 wxPuts (result != 0 ? _T("Test failed!") : _T("Test ok."));
1794 }
1795
1796 #ifdef wxLongLong_t
1797 {
1798 wxChar buf[200];
1799
1800 wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000));
1801 #if 0
1802 // for some reason below line fails under Borland
1803 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf);
1804 #endif
1805
1806 if (wxStrcmp (buf, _T("40000000000")) != 0)
1807 {
1808 result = 1;
1809 wxPuts (_T("\tFAILED"));
1810 }
1811 wxUnusedVar(result);
1812 wxPuts (wxEmptyString);
1813 }
1814 #endif // wxLongLong_t
1815
1816 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX + 2, UCHAR_MAX + 2);
1817 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX + 2, USHRT_MAX + 2);
1818
1819 wxPuts (_T("--- Should be no further output. ---"));
1820 rfg1 ();
1821 rfg2 ();
1822
1823 #if 0
1824 {
1825 wxChar bytes[7];
1826 wxChar buf[20];
1827
1828 memset (bytes, '\xff', sizeof bytes);
1829 wxSprintf (buf, _T("foo%hhn\n"), &bytes[3]);
1830 if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff'
1831 || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff')
1832 {
1833 wxPuts (_T("%hhn overwrite more bytes"));
1834 result = 1;
1835 }
1836 if (bytes[3] != 3)
1837 {
1838 wxPuts (_T("%hhn wrote incorrect value"));
1839 result = 1;
1840 }
1841 }
1842 #endif
1843 }
1844
1845 static void
1846 rfg1 (void)
1847 {
1848 wxChar buf[100];
1849
1850 wxSprintf (buf, _T("%5.s"), _T("xyz"));
1851 if (wxStrcmp (buf, _T(" ")) != 0)
1852 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" "));
1853 wxSprintf (buf, _T("%5.f"), 33.3);
1854 if (wxStrcmp (buf, _T(" 33")) != 0)
1855 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 33"));
1856 wxSprintf (buf, _T("%8.e"), 33.3e7);
1857 if (wxStrcmp (buf, _T(" 3e+08")) != 0)
1858 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3e+08"));
1859 wxSprintf (buf, _T("%8.E"), 33.3e7);
1860 if (wxStrcmp (buf, _T(" 3E+08")) != 0)
1861 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3E+08"));
1862 wxSprintf (buf, _T("%.g"), 33.3);
1863 if (wxStrcmp (buf, _T("3e+01")) != 0)
1864 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3e+01"));
1865 wxSprintf (buf, _T("%.G"), 33.3);
1866 if (wxStrcmp (buf, _T("3E+01")) != 0)
1867 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3E+01"));
1868 }
1869
1870 static void
1871 rfg2 (void)
1872 {
1873 int prec;
1874 wxChar buf[100];
1875 wxString test_format;
1876
1877 prec = 0;
1878 wxSprintf (buf, _T("%.*g"), prec, 3.3);
1879 if (wxStrcmp (buf, _T("3")) != 0)
1880 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3"));
1881 prec = 0;
1882 wxSprintf (buf, _T("%.*G"), prec, 3.3);
1883 if (wxStrcmp (buf, _T("3")) != 0)
1884 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3"));
1885 prec = 0;
1886 wxSprintf (buf, _T("%7.*G"), prec, 3.33);
1887 if (wxStrcmp (buf, _T(" 3")) != 0)
1888 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3"));
1889 prec = 3;
1890 test_format = _T("%04.*o");
1891 wxSprintf (buf, test_format.c_str(), prec, 33);
1892 if (wxStrcmp (buf, _T(" 041")) != 0)
1893 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041"));
1894 prec = 7;
1895 test_format = _T("%09.*u");
1896 wxSprintf (buf, test_format.c_str(), prec, 33);
1897 if (wxStrcmp (buf, _T(" 0000033")) != 0)
1898 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033"));
1899 prec = 3;
1900 test_format = _T("%04.*x");
1901 wxSprintf (buf, test_format.c_str(), prec, 33);
1902 if (wxStrcmp (buf, _T(" 021")) != 0)
1903 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
1904 prec = 3;
1905 test_format = _T("%04.*X");
1906 wxSprintf (buf, test_format.c_str(), prec, 33);
1907 if (wxStrcmp (buf, _T(" 021")) != 0)
1908 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
1909 }
1910
1911 #endif // TEST_PRINTF
1912
1913 // ----------------------------------------------------------------------------
1914 // registry and related stuff
1915 // ----------------------------------------------------------------------------
1916
1917 // this is for MSW only
1918 #ifndef __WXMSW__
1919 #undef TEST_REGCONF
1920 #undef TEST_REGISTRY
1921 #endif
1922
1923 #ifdef TEST_REGCONF
1924
1925 #include "wx/confbase.h"
1926 #include "wx/msw/regconf.h"
1927
1928 #if 0
1929 static void TestRegConfWrite()
1930 {
1931 wxConfig *config = new wxConfig(_T("myapp"));
1932 config->SetPath(_T("/group1"));
1933 config->Write(_T("entry1"), _T("foo"));
1934 config->SetPath(_T("/group2"));
1935 config->Write(_T("entry1"), _T("bar"));
1936 }
1937 #endif
1938
1939 static void TestRegConfRead()
1940 {
1941 wxConfig *config = new wxConfig(_T("myapp"));
1942
1943 wxString str;
1944 long dummy;
1945 config->SetPath(_T("/"));
1946 wxPuts(_T("Enumerating / subgroups:"));
1947 bool bCont = config->GetFirstGroup(str, dummy);
1948 while(bCont)
1949 {
1950 wxPuts(str);
1951 bCont = config->GetNextGroup(str, dummy);
1952 }
1953 }
1954
1955 #endif // TEST_REGCONF
1956
1957 #ifdef TEST_REGISTRY
1958
1959 #include "wx/msw/registry.h"
1960
1961 // I chose this one because I liked its name, but it probably only exists under
1962 // NT
1963 static const wxChar *TESTKEY =
1964 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1965
1966 static void TestRegistryRead()
1967 {
1968 wxPuts(_T("*** testing registry reading ***"));
1969
1970 wxRegKey key(TESTKEY);
1971 wxPrintf(_T("The test key name is '%s'.\n"), key.GetName().c_str());
1972 if ( !key.Open() )
1973 {
1974 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
1975
1976 return;
1977 }
1978
1979 size_t nSubKeys, nValues;
1980 if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
1981 {
1982 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys, nValues);
1983 }
1984
1985 wxPrintf(_T("Enumerating values:\n"));
1986
1987 long dummy;
1988 wxString value;
1989 bool cont = key.GetFirstValue(value, dummy);
1990 while ( cont )
1991 {
1992 wxPrintf(_T("Value '%s': type "), value.c_str());
1993 switch ( key.GetValueType(value) )
1994 {
1995 case wxRegKey::Type_None: wxPrintf(_T("ERROR (none)")); break;
1996 case wxRegKey::Type_String: wxPrintf(_T("SZ")); break;
1997 case wxRegKey::Type_Expand_String: wxPrintf(_T("EXPAND_SZ")); break;
1998 case wxRegKey::Type_Binary: wxPrintf(_T("BINARY")); break;
1999 case wxRegKey::Type_Dword: wxPrintf(_T("DWORD")); break;
2000 case wxRegKey::Type_Multi_String: wxPrintf(_T("MULTI_SZ")); break;
2001 default: wxPrintf(_T("other (unknown)")); break;
2002 }
2003
2004 wxPrintf(_T(", value = "));
2005 if ( key.IsNumericValue(value) )
2006 {
2007 long val;
2008 key.QueryValue(value, &val);
2009 wxPrintf(_T("%ld"), val);
2010 }
2011 else // string
2012 {
2013 wxString val;
2014 key.QueryValue(value, val);
2015 wxPrintf(_T("'%s'"), val.c_str());
2016
2017 key.QueryRawValue(value, val);
2018 wxPrintf(_T(" (raw value '%s')"), val.c_str());
2019 }
2020
2021 wxPutchar('\n');
2022
2023 cont = key.GetNextValue(value, dummy);
2024 }
2025 }
2026
2027 static void TestRegistryAssociation()
2028 {
2029 /*
2030 The second call to deleteself genertaes an error message, with a
2031 messagebox saying .flo is crucial to system operation, while the .ddf
2032 call also fails, but with no error message
2033 */
2034
2035 wxRegKey key;
2036
2037 key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2038 key.Create();
2039 key = _T("ddxf_auto_file") ;
2040 key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2041 key.Create();
2042 key = _T("ddxf_auto_file") ;
2043 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2044 key.Create();
2045 key = _T("program,0") ;
2046 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2047 key.Create();
2048 key = _T("program \"%1\"") ;
2049
2050 key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2051 key.DeleteSelf();
2052 key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2053 key.DeleteSelf();
2054 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2055 key.DeleteSelf();
2056 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2057 key.DeleteSelf();
2058 }
2059
2060 #endif // TEST_REGISTRY
2061
2062 // ----------------------------------------------------------------------------
2063 // scope guard
2064 // ----------------------------------------------------------------------------
2065
2066 #ifdef TEST_SCOPEGUARD
2067
2068 #include "wx/scopeguard.h"
2069
2070 static void function0() { puts("function0()"); }
2071 static void function1(int n) { printf("function1(%d)\n", n); }
2072 static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); }
2073
2074 struct Object
2075 {
2076 void method0() { printf("method0()\n"); }
2077 void method1(int n) { printf("method1(%d)\n", n); }
2078 void method2(double x, char c) { printf("method2(%g, %c)\n", x, c); }
2079 };
2080
2081 static void TestScopeGuard()
2082 {
2083 wxON_BLOCK_EXIT0(function0);
2084 wxON_BLOCK_EXIT1(function1, 17);
2085 wxON_BLOCK_EXIT2(function2, 3.14, 'p');
2086
2087 Object obj;
2088 wxON_BLOCK_EXIT_OBJ0(obj, &Object::method0);
2089 wxON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7);
2090 wxON_BLOCK_EXIT_OBJ2(obj, &Object::method2, 2.71, 'e');
2091
2092 wxScopeGuard dismissed = wxMakeGuard(function0);
2093 dismissed.Dismiss();
2094 }
2095
2096 #endif
2097
2098 // ----------------------------------------------------------------------------
2099 // sockets
2100 // ----------------------------------------------------------------------------
2101
2102 #ifdef TEST_SOCKETS
2103
2104 #include "wx/socket.h"
2105 #include "wx/protocol/protocol.h"
2106 #include "wx/protocol/http.h"
2107
2108 static void TestSocketServer()
2109 {
2110 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2111
2112 static const int PORT = 3000;
2113
2114 wxIPV4address addr;
2115 addr.Service(PORT);
2116
2117 wxSocketServer *server = new wxSocketServer(addr);
2118 if ( !server->Ok() )
2119 {
2120 wxPuts(_T("ERROR: failed to bind"));
2121
2122 return;
2123 }
2124
2125 bool quit = false;
2126 while ( !quit )
2127 {
2128 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT);
2129
2130 wxSocketBase *socket = server->Accept();
2131 if ( !socket )
2132 {
2133 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2134 break;
2135 }
2136
2137 wxPuts(_T("Server: got a client."));
2138
2139 server->SetTimeout(60); // 1 min
2140
2141 bool close = false;
2142 while ( !close && socket->IsConnected() )
2143 {
2144 wxString s;
2145 wxChar ch = _T('\0');
2146 for ( ;; )
2147 {
2148 if ( socket->Read(&ch, sizeof(ch)).Error() )
2149 {
2150 // don't log error if the client just close the connection
2151 if ( socket->IsConnected() )
2152 {
2153 wxPuts(_T("ERROR: in wxSocket::Read."));
2154 }
2155
2156 break;
2157 }
2158
2159 if ( ch == '\r' )
2160 continue;
2161
2162 if ( ch == '\n' )
2163 break;
2164
2165 s += ch;
2166 }
2167
2168 if ( ch != '\n' )
2169 {
2170 break;
2171 }
2172
2173 wxPrintf(_T("Server: got '%s'.\n"), s.c_str());
2174 if ( s == _T("close") )
2175 {
2176 wxPuts(_T("Closing connection"));
2177
2178 close = true;
2179 }
2180 else if ( s == _T("quit") )
2181 {
2182 close =
2183 quit = true;
2184
2185 wxPuts(_T("Shutting down the server"));
2186 }
2187 else // not a special command
2188 {
2189 socket->Write(s.MakeUpper().c_str(), s.length());
2190 socket->Write("\r\n", 2);
2191 wxPrintf(_T("Server: wrote '%s'.\n"), s.c_str());
2192 }
2193 }
2194
2195 if ( !close )
2196 {
2197 wxPuts(_T("Server: lost a client unexpectedly."));
2198 }
2199
2200 socket->Destroy();
2201 }
2202
2203 // same as "delete server" but is consistent with GUI programs
2204 server->Destroy();
2205 }
2206
2207 static void TestSocketClient()
2208 {
2209 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2210
2211 static const wxChar *hostname = _T("www.wxwidgets.org");
2212
2213 wxIPV4address addr;
2214 addr.Hostname(hostname);
2215 addr.Service(80);
2216
2217 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname);
2218
2219 wxSocketClient client;
2220 if ( !client.Connect(addr) )
2221 {
2222 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
2223 }
2224 else
2225 {
2226 wxPrintf(_T("--- Connected to %s:%u...\n"),
2227 addr.Hostname().c_str(), addr.Service());
2228
2229 wxChar buf[8192];
2230
2231 // could use simply "GET" here I suppose
2232 wxString cmdGet =
2233 wxString::Format(_T("GET http://%s/\r\n"), hostname);
2234 client.Write(cmdGet, cmdGet.length());
2235 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2236 MakePrintable(cmdGet).c_str());
2237 client.Read(buf, WXSIZEOF(buf));
2238 wxPrintf(_T("--- Server replied:\n%s"), buf);
2239 }
2240 }
2241
2242 #endif // TEST_SOCKETS
2243
2244 // ----------------------------------------------------------------------------
2245 // FTP
2246 // ----------------------------------------------------------------------------
2247
2248 #ifdef TEST_FTP
2249
2250 #include "wx/protocol/ftp.h"
2251
2252 static wxFTP ftp;
2253
2254 #define FTP_ANONYMOUS
2255
2256 #ifdef FTP_ANONYMOUS
2257 static const wxChar *directory = _T("/pub");
2258 static const wxChar *filename = _T("welcome.msg");
2259 #else
2260 static const wxChar *directory = _T("/etc");
2261 static const wxChar *filename = _T("issue");
2262 #endif
2263
2264 static bool TestFtpConnect()
2265 {
2266 wxPuts(_T("*** Testing FTP connect ***"));
2267
2268 #ifdef FTP_ANONYMOUS
2269 static const wxChar *hostname = _T("ftp.wxwidgets.org");
2270
2271 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
2272 #else // !FTP_ANONYMOUS
2273 static const wxChar *hostname = "localhost";
2274
2275 wxChar user[256];
2276 wxFgets(user, WXSIZEOF(user), stdin);
2277 user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
2278 ftp.SetUser(user);
2279
2280 wxChar password[256];
2281 wxPrintf(_T("Password for %s: "), password);
2282 wxFgets(password, WXSIZEOF(password), stdin);
2283 password[wxStrlen(password) - 1] = '\0'; // chop off '\n'
2284 ftp.SetPassword(password);
2285
2286 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname, user);
2287 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2288
2289 if ( !ftp.Connect(hostname) )
2290 {
2291 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
2292
2293 return false;
2294 }
2295 else
2296 {
2297 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2298 hostname, ftp.Pwd().c_str());
2299 ftp.Close();
2300 }
2301
2302 return true;
2303 }
2304
2305 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2306 static void TestFtpWuFtpd()
2307 {
2308 wxFTP ftp;
2309 static const wxChar *hostname = _T("ftp.eudora.com");
2310 if ( !ftp.Connect(hostname) )
2311 {
2312 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
2313 }
2314 else
2315 {
2316 static const wxChar *filename = _T("eudora/pubs/draft-gellens-submit-09.txt");
2317 wxInputStream *in = ftp.GetInputStream(filename);
2318 if ( !in )
2319 {
2320 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
2321 }
2322 else
2323 {
2324 size_t size = in->GetSize();
2325 wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
2326
2327 wxChar *data = new wxChar[size];
2328 if ( !in->Read(data, size) )
2329 {
2330 wxPuts(_T("ERROR: read error"));
2331 }
2332 else
2333 {
2334 wxPrintf(_T("Successfully retrieved the file.\n"));
2335 }
2336
2337 delete [] data;
2338 delete in;
2339 }
2340 }
2341 }
2342
2343 static void TestFtpList()
2344 {
2345 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2346
2347 // test CWD
2348 if ( !ftp.ChDir(directory) )
2349 {
2350 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
2351 }
2352
2353 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
2354
2355 // test NLIST and LIST
2356 wxArrayString files;
2357 if ( !ftp.GetFilesList(files) )
2358 {
2359 wxPuts(_T("ERROR: failed to get NLIST of files"));
2360 }
2361 else
2362 {
2363 wxPrintf(_T("Brief list of files under '%s':\n"), ftp.Pwd().c_str());
2364 size_t count = files.GetCount();
2365 for ( size_t n = 0; n < count; n++ )
2366 {
2367 wxPrintf(_T("\t%s\n"), files[n].c_str());
2368 }
2369 wxPuts(_T("End of the file list"));
2370 }
2371
2372 if ( !ftp.GetDirList(files) )
2373 {
2374 wxPuts(_T("ERROR: failed to get LIST of files"));
2375 }
2376 else
2377 {
2378 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp.Pwd().c_str());
2379 size_t count = files.GetCount();
2380 for ( size_t n = 0; n < count; n++ )
2381 {
2382 wxPrintf(_T("\t%s\n"), files[n].c_str());
2383 }
2384 wxPuts(_T("End of the file list"));
2385 }
2386
2387 if ( !ftp.ChDir(_T("..")) )
2388 {
2389 wxPuts(_T("ERROR: failed to cd to .."));
2390 }
2391
2392 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
2393 }
2394
2395 static void TestFtpDownload()
2396 {
2397 wxPuts(_T("*** Testing wxFTP download ***\n"));
2398
2399 // test RETR
2400 wxInputStream *in = ftp.GetInputStream(filename);
2401 if ( !in )
2402 {
2403 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
2404 }
2405 else
2406 {
2407 size_t size = in->GetSize();
2408 wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
2409 fflush(stdout);
2410
2411 wxChar *data = new wxChar[size];
2412 if ( !in->Read(data, size) )
2413 {
2414 wxPuts(_T("ERROR: read error"));
2415 }
2416 else
2417 {
2418 wxPrintf(_T("\nContents of %s:\n%s\n"), filename, data);
2419 }
2420
2421 delete [] data;
2422 delete in;
2423 }
2424 }
2425
2426 static void TestFtpFileSize()
2427 {
2428 wxPuts(_T("*** Testing FTP SIZE command ***"));
2429
2430 if ( !ftp.ChDir(directory) )
2431 {
2432 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
2433 }
2434
2435 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
2436
2437 if ( ftp.FileExists(filename) )
2438 {
2439 int size = ftp.GetFileSize(filename);
2440 if ( size == -1 )
2441 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename);
2442 else
2443 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename, size);
2444 }
2445 else
2446 {
2447 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename);
2448 }
2449 }
2450
2451 static void TestFtpMisc()
2452 {
2453 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2454
2455 if ( ftp.SendCommand(_T("STAT")) != '2' )
2456 {
2457 wxPuts(_T("ERROR: STAT failed"));
2458 }
2459 else
2460 {
2461 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str());
2462 }
2463
2464 if ( ftp.SendCommand(_T("HELP SITE")) != '2' )
2465 {
2466 wxPuts(_T("ERROR: HELP SITE failed"));
2467 }
2468 else
2469 {
2470 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2471 ftp.GetLastResult().c_str());
2472 }
2473 }
2474
2475 static void TestFtpInteractive()
2476 {
2477 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2478
2479 wxChar buf[128];
2480
2481 for ( ;; )
2482 {
2483 wxPrintf(_T("Enter FTP command: "));
2484 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
2485 break;
2486
2487 // kill the last '\n'
2488 buf[wxStrlen(buf) - 1] = 0;
2489
2490 // special handling of LIST and NLST as they require data connection
2491 wxString start(buf, 4);
2492 start.MakeUpper();
2493 if ( start == _T("LIST") || start == _T("NLST") )
2494 {
2495 wxString wildcard;
2496 if ( wxStrlen(buf) > 4 )
2497 wildcard = buf + 5;
2498
2499 wxArrayString files;
2500 if ( !ftp.GetList(files, wildcard, start == _T("LIST")) )
2501 {
2502 wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str());
2503 }
2504 else
2505 {
2506 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2507 start.c_str(), wildcard.c_str(), ftp.Pwd().c_str());
2508 size_t count = files.GetCount();
2509 for ( size_t n = 0; n < count; n++ )
2510 {
2511 wxPrintf(_T("\t%s\n"), files[n].c_str());
2512 }
2513 wxPuts(_T("--- End of the file list"));
2514 }
2515 }
2516 else // !list
2517 {
2518 wxChar ch = ftp.SendCommand(buf);
2519 wxPrintf(_T("Command %s"), ch ? _T("succeeded") : _T("failed"));
2520 if ( ch )
2521 {
2522 wxPrintf(_T(" (return code %c)"), ch);
2523 }
2524
2525 wxPrintf(_T(", server reply:\n%s\n\n"), ftp.GetLastResult().c_str());
2526 }
2527 }
2528
2529 wxPuts(_T("\n*** done ***"));
2530 }
2531
2532 static void TestFtpUpload()
2533 {
2534 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2535
2536 // upload a file
2537 static const wxChar *file1 = _T("test1");
2538 static const wxChar *file2 = _T("test2");
2539 wxOutputStream *out = ftp.GetOutputStream(file1);
2540 if ( out )
2541 {
2542 wxPrintf(_T("--- Uploading to %s ---\n"), file1);
2543 out->Write("First hello", 11);
2544 delete out;
2545 }
2546
2547 // send a command to check the remote file
2548 if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' )
2549 {
2550 wxPrintf(_T("ERROR: STAT %s failed\n"), file1);
2551 }
2552 else
2553 {
2554 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2555 file1, ftp.GetLastResult().c_str());
2556 }
2557
2558 out = ftp.GetOutputStream(file2);
2559 if ( out )
2560 {
2561 wxPrintf(_T("--- Uploading to %s ---\n"), file1);
2562 out->Write("Second hello", 12);
2563 delete out;
2564 }
2565 }
2566
2567 #endif // TEST_FTP
2568
2569 // ----------------------------------------------------------------------------
2570 // stack backtrace
2571 // ----------------------------------------------------------------------------
2572
2573 #ifdef TEST_STACKWALKER
2574
2575 #if wxUSE_STACKWALKER
2576
2577 #include "wx/stackwalk.h"
2578
2579 class StackDump : public wxStackWalker
2580 {
2581 public:
2582 StackDump(const char *argv0)
2583 : wxStackWalker(argv0)
2584 {
2585 }
2586
2587 virtual void Walk(size_t skip = 1)
2588 {
2589 wxPuts(_T("Stack dump:"));
2590
2591 wxStackWalker::Walk(skip);
2592 }
2593
2594 protected:
2595 virtual void OnStackFrame(const wxStackFrame& frame)
2596 {
2597 printf("[%2d] ", frame.GetLevel());
2598
2599 wxString name = frame.GetName();
2600 if ( !name.empty() )
2601 {
2602 printf("%-20.40s", name.mb_str());
2603 }
2604 else
2605 {
2606 printf("0x%08lx", (unsigned long)frame.GetAddress());
2607 }
2608
2609 if ( frame.HasSourceLocation() )
2610 {
2611 printf("\t%s:%d",
2612 frame.GetFileName().mb_str(),
2613 frame.GetLine());
2614 }
2615
2616 puts("");
2617
2618 wxString type, val;
2619 for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
2620 {
2621 printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str());
2622 }
2623 }
2624 };
2625
2626 static void TestStackWalk(const char *argv0)
2627 {
2628 wxPuts(_T("*** Testing wxStackWalker ***\n"));
2629
2630 StackDump dump(argv0);
2631 dump.Walk();
2632 }
2633
2634 #endif // wxUSE_STACKWALKER
2635
2636 #endif // TEST_STACKWALKER
2637
2638 // ----------------------------------------------------------------------------
2639 // standard paths
2640 // ----------------------------------------------------------------------------
2641
2642 #ifdef TEST_STDPATHS
2643
2644 #include "wx/stdpaths.h"
2645
2646 static void TestStandardPaths()
2647 {
2648 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
2649
2650 wxTheApp->SetAppName(_T("console"));
2651
2652 wxStandardPathsBase& stdp = wxStandardPaths::Get();
2653 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
2654 wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
2655 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
2656 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str());
2657 wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
2658 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
2659 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
2660 }
2661
2662 #endif // TEST_STDPATHS
2663
2664 // ----------------------------------------------------------------------------
2665 // streams
2666 // ----------------------------------------------------------------------------
2667
2668 #ifdef TEST_STREAMS
2669
2670 #include "wx/wfstream.h"
2671 #include "wx/mstream.h"
2672
2673 static void TestFileStream()
2674 {
2675 wxPuts(_T("*** Testing wxFileInputStream ***"));
2676
2677 static const wxString filename = _T("testdata.fs");
2678 {
2679 wxFileOutputStream fsOut(filename);
2680 fsOut.Write("foo", 3);
2681 }
2682
2683 wxFileInputStream fsIn(filename);
2684 wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
2685 while ( !fsIn.Eof() )
2686 {
2687 wxPutchar(fsIn.GetC());
2688 }
2689
2690 if ( !wxRemoveFile(filename) )
2691 {
2692 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str());
2693 }
2694
2695 wxPuts(_T("\n*** wxFileInputStream test done ***"));
2696 }
2697
2698 static void TestMemoryStream()
2699 {
2700 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
2701
2702 wxMemoryOutputStream memOutStream;
2703 wxPrintf(_T("Initially out stream offset: %lu\n"),
2704 (unsigned long)memOutStream.TellO());
2705
2706 for ( const wxChar *p = _T("Hello, stream!"); *p; p++ )
2707 {
2708 memOutStream.PutC(*p);
2709 }
2710
2711 wxPrintf(_T("Final out stream offset: %lu\n"),
2712 (unsigned long)memOutStream.TellO());
2713
2714 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
2715
2716 wxChar buf[1024];
2717 size_t len = memOutStream.CopyTo(buf, WXSIZEOF(buf));
2718
2719 wxMemoryInputStream memInpStream(buf, len);
2720 wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
2721 while ( !memInpStream.Eof() )
2722 {
2723 wxPutchar(memInpStream.GetC());
2724 }
2725
2726 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
2727 }
2728
2729 #endif // TEST_STREAMS
2730
2731 // ----------------------------------------------------------------------------
2732 // timers
2733 // ----------------------------------------------------------------------------
2734
2735 #ifdef TEST_TIMER
2736
2737 #include "wx/stopwatch.h"
2738 #include "wx/utils.h"
2739
2740 static void TestStopWatch()
2741 {
2742 wxPuts(_T("*** Testing wxStopWatch ***\n"));
2743
2744 wxStopWatch sw;
2745 sw.Pause();
2746 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
2747 fflush(stdout);
2748 wxSleep(2);
2749 wxPrintf(_T("\t%ldms\n"), sw.Time());
2750
2751 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
2752 fflush(stdout);
2753 sw.Resume();
2754 wxSleep(3);
2755 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
2756
2757 sw.Pause();
2758 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
2759 fflush(stdout);
2760 wxSleep(2);
2761 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
2762
2763 sw.Resume();
2764 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
2765 fflush(stdout);
2766 wxSleep(2);
2767 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
2768
2769 wxStopWatch sw2;
2770 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
2771 for ( size_t n = 0; n < 70; n++ )
2772 {
2773 sw2.Start();
2774
2775 for ( size_t m = 0; m < 100000; m++ )
2776 {
2777 if ( sw.Time() < 0 || sw2.Time() < 0 )
2778 {
2779 wxPuts(_T("\ntime is negative - ERROR!"));
2780 }
2781 }
2782
2783 wxPutchar('.');
2784 fflush(stdout);
2785 }
2786
2787 wxPuts(_T(", ok."));
2788 }
2789
2790 #endif // TEST_TIMER
2791
2792 // ----------------------------------------------------------------------------
2793 // vCard support
2794 // ----------------------------------------------------------------------------
2795
2796 #ifdef TEST_VCARD
2797
2798 #include "wx/vcard.h"
2799
2800 static void DumpVObject(size_t level, const wxVCardObject& vcard)
2801 {
2802 void *cookie;
2803 wxVCardObject *vcObj = vcard.GetFirstProp(&cookie);
2804 while ( vcObj )
2805 {
2806 wxPrintf(_T("%s%s"),
2807 wxString(_T('\t'), level).c_str(),
2808 vcObj->GetName().c_str());
2809
2810 wxString value;
2811 switch ( vcObj->GetType() )
2812 {
2813 case wxVCardObject::String:
2814 case wxVCardObject::UString:
2815 {
2816 wxString val;
2817 vcObj->GetValue(&val);
2818 value << _T('"') << val << _T('"');
2819 }
2820 break;
2821
2822 case wxVCardObject::Int:
2823 {
2824 unsigned int i;
2825 vcObj->GetValue(&i);
2826 value.Printf(_T("%u"), i);
2827 }
2828 break;
2829
2830 case wxVCardObject::Long:
2831 {
2832 unsigned long l;
2833 vcObj->GetValue(&l);
2834 value.Printf(_T("%lu"), l);
2835 }
2836 break;
2837
2838 case wxVCardObject::None:
2839 break;
2840
2841 case wxVCardObject::Object:
2842 value = _T("<node>");
2843 break;
2844
2845 default:
2846 value = _T("<unknown value type>");
2847 }
2848
2849 if ( !!value )
2850 wxPrintf(_T(" = %s"), value.c_str());
2851 wxPutchar('\n');
2852
2853 DumpVObject(level + 1, *vcObj);
2854
2855 delete vcObj;
2856 vcObj = vcard.GetNextProp(&cookie);
2857 }
2858 }
2859
2860 static void DumpVCardAddresses(const wxVCard& vcard)
2861 {
2862 wxPuts(_T("\nShowing all addresses from vCard:\n"));
2863
2864 size_t nAdr = 0;
2865 void *cookie;
2866 wxVCardAddress *addr = vcard.GetFirstAddress(&cookie);
2867 while ( addr )
2868 {
2869 wxString flagsStr;
2870 int flags = addr->GetFlags();
2871 if ( flags & wxVCardAddress::Domestic )
2872 {
2873 flagsStr << _T("domestic ");
2874 }
2875 if ( flags & wxVCardAddress::Intl )
2876 {
2877 flagsStr << _T("international ");
2878 }
2879 if ( flags & wxVCardAddress::Postal )
2880 {
2881 flagsStr << _T("postal ");
2882 }
2883 if ( flags & wxVCardAddress::Parcel )
2884 {
2885 flagsStr << _T("parcel ");
2886 }
2887 if ( flags & wxVCardAddress::Home )
2888 {
2889 flagsStr << _T("home ");
2890 }
2891 if ( flags & wxVCardAddress::Work )
2892 {
2893 flagsStr << _T("work ");
2894 }
2895
2896 wxPrintf(_T("Address %u:\n")
2897 "\tflags = %s\n"
2898 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
2899 ++nAdr,
2900 flagsStr.c_str(),
2901 addr->GetPostOffice().c_str(),
2902 addr->GetExtAddress().c_str(),
2903 addr->GetStreet().c_str(),
2904 addr->GetLocality().c_str(),
2905 addr->GetRegion().c_str(),
2906 addr->GetPostalCode().c_str(),
2907 addr->GetCountry().c_str()
2908 );
2909
2910 delete addr;
2911 addr = vcard.GetNextAddress(&cookie);
2912 }
2913 }
2914
2915 static void DumpVCardPhoneNumbers(const wxVCard& vcard)
2916 {
2917 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
2918
2919 size_t nPhone = 0;
2920 void *cookie;
2921 wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie);
2922 while ( phone )
2923 {
2924 wxString flagsStr;
2925 int flags = phone->GetFlags();
2926 if ( flags & wxVCardPhoneNumber::Voice )
2927 {
2928 flagsStr << _T("voice ");
2929 }
2930 if ( flags & wxVCardPhoneNumber::Fax )
2931 {
2932 flagsStr << _T("fax ");
2933 }
2934 if ( flags & wxVCardPhoneNumber::Cellular )
2935 {
2936 flagsStr << _T("cellular ");
2937 }
2938 if ( flags & wxVCardPhoneNumber::Modem )
2939 {
2940 flagsStr << _T("modem ");
2941 }
2942 if ( flags & wxVCardPhoneNumber::Home )
2943 {
2944 flagsStr << _T("home ");
2945 }
2946 if ( flags & wxVCardPhoneNumber::Work )
2947 {
2948 flagsStr << _T("work ");
2949 }
2950
2951 wxPrintf(_T("Phone number %u:\n")
2952 "\tflags = %s\n"
2953 "\tvalue = %s\n",
2954 ++nPhone,
2955 flagsStr.c_str(),
2956 phone->GetNumber().c_str()
2957 );
2958
2959 delete phone;
2960 phone = vcard.GetNextPhoneNumber(&cookie);
2961 }
2962 }
2963
2964 static void TestVCardRead()
2965 {
2966 wxPuts(_T("*** Testing wxVCard reading ***\n"));
2967
2968 wxVCard vcard(_T("vcard.vcf"));
2969 if ( !vcard.IsOk() )
2970 {
2971 wxPuts(_T("ERROR: couldn't load vCard."));
2972 }
2973 else
2974 {
2975 // read individual vCard properties
2976 wxVCardObject *vcObj = vcard.GetProperty("FN");
2977 wxString value;
2978 if ( vcObj )
2979 {
2980 vcObj->GetValue(&value);
2981 delete vcObj;
2982 }
2983 else
2984 {
2985 value = _T("<none>");
2986 }
2987
2988 wxPrintf(_T("Full name retrieved directly: %s\n"), value.c_str());
2989
2990
2991 if ( !vcard.GetFullName(&value) )
2992 {
2993 value = _T("<none>");
2994 }
2995
2996 wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
2997
2998 // now show how to deal with multiply occurring properties
2999 DumpVCardAddresses(vcard);
3000 DumpVCardPhoneNumbers(vcard);
3001
3002 // and finally show all
3003 wxPuts(_T("\nNow dumping the entire vCard:\n")
3004 "-----------------------------\n");
3005
3006 DumpVObject(0, vcard);
3007 }
3008 }
3009
3010 static void TestVCardWrite()
3011 {
3012 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3013
3014 wxVCard vcard;
3015 if ( !vcard.IsOk() )
3016 {
3017 wxPuts(_T("ERROR: couldn't create vCard."));
3018 }
3019 else
3020 {
3021 // set some fields
3022 vcard.SetName("Zeitlin", "Vadim");
3023 vcard.SetFullName("Vadim Zeitlin");
3024 vcard.SetOrganization("wxWidgets", "R&D");
3025
3026 // just dump the vCard back
3027 wxPuts(_T("Entire vCard follows:\n"));
3028 wxPuts(vcard.Write());
3029 }
3030 }
3031
3032 #endif // TEST_VCARD
3033
3034 // ----------------------------------------------------------------------------
3035 // wxVolume tests
3036 // ----------------------------------------------------------------------------
3037
3038 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3039 #undef TEST_VOLUME
3040 #endif
3041
3042 #ifdef TEST_VOLUME
3043
3044 #include "wx/volume.h"
3045
3046 static const wxChar *volumeKinds[] =
3047 {
3048 _T("floppy"),
3049 _T("hard disk"),
3050 _T("CD-ROM"),
3051 _T("DVD-ROM"),
3052 _T("network volume"),
3053 _T("other volume"),
3054 };
3055
3056 static void TestFSVolume()
3057 {
3058 wxPuts(_T("*** Testing wxFSVolume class ***"));
3059
3060 wxArrayString volumes = wxFSVolume::GetVolumes();
3061 size_t count = volumes.GetCount();
3062
3063 if ( !count )
3064 {
3065 wxPuts(_T("ERROR: no mounted volumes?"));
3066 return;
3067 }
3068
3069 wxPrintf(_T("%u mounted volumes found:\n"), count);
3070
3071 for ( size_t n = 0; n < count; n++ )
3072 {
3073 wxFSVolume vol(volumes[n]);
3074 if ( !vol.IsOk() )
3075 {
3076 wxPuts(_T("ERROR: couldn't create volume"));
3077 continue;
3078 }
3079
3080 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3081 n + 1,
3082 vol.GetDisplayName().c_str(),
3083 vol.GetName().c_str(),
3084 volumeKinds[vol.GetKind()],
3085 vol.IsWritable() ? _T("rw") : _T("ro"),
3086 vol.GetFlags() & wxFS_VOL_REMOVABLE ? _T("removable")
3087 : _T("fixed"));
3088 }
3089 }
3090
3091 #endif // TEST_VOLUME
3092
3093 // ----------------------------------------------------------------------------
3094 // wide char and Unicode support
3095 // ----------------------------------------------------------------------------
3096
3097 #ifdef TEST_WCHAR
3098
3099 #include "wx/strconv.h"
3100 #include "wx/fontenc.h"
3101 #include "wx/encconv.h"
3102 #include "wx/buffer.h"
3103
3104 static const unsigned char utf8koi8r[] =
3105 {
3106 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3107 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3108 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3109 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3110 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3111 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3112 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3113 };
3114
3115 static const unsigned char utf8iso8859_1[] =
3116 {
3117 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3118 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3119 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3120 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3121 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3122 };
3123
3124 static const unsigned char utf8Invalid[] =
3125 {
3126 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3127 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3128 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3129 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3130 0x6c, 0x61, 0x79, 0
3131 };
3132
3133 static const struct Utf8Data
3134 {
3135 const unsigned char *text;
3136 size_t len;
3137 const wxChar *charset;
3138 wxFontEncoding encoding;
3139 } utf8data[] =
3140 {
3141 { utf8Invalid, WXSIZEOF(utf8Invalid), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 },
3142 { utf8koi8r, WXSIZEOF(utf8koi8r), _T("koi8-r"), wxFONTENCODING_KOI8 },
3143 { utf8iso8859_1, WXSIZEOF(utf8iso8859_1), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 },
3144 };
3145
3146 static void TestUtf8()
3147 {
3148 wxPuts(_T("*** Testing UTF8 support ***\n"));
3149
3150 char buf[1024];
3151 wchar_t wbuf[1024];
3152
3153 for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
3154 {
3155 const Utf8Data& u8d = utf8data[n];
3156 if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text,
3157 WXSIZEOF(wbuf)) == (size_t)-1 )
3158 {
3159 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3160 }
3161 else
3162 {
3163 wxCSConv conv(u8d.charset);
3164 if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 )
3165 {
3166 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d.charset);
3167 }
3168 else
3169 {
3170 wxPrintf(_T("String in %s: %s\n"), u8d.charset, buf);
3171 }
3172 }
3173
3174 wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
3175 if ( s.empty() )
3176 s = _T("<< conversion failed >>");
3177 wxPrintf(_T("String in current cset: %s\n"), s.c_str());
3178
3179 }
3180
3181 wxPuts(wxEmptyString);
3182 }
3183
3184 static void TestEncodingConverter()
3185 {
3186 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3187
3188 // using wxEncodingConverter should give the same result as above
3189 char buf[1024];
3190 wchar_t wbuf[1024];
3191 if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r,
3192 WXSIZEOF(utf8koi8r)) == (size_t)-1 )
3193 {
3194 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3195 }
3196 else
3197 {
3198 wxEncodingConverter ec;
3199 ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
3200 ec.Convert(wbuf, buf);
3201 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf);
3202 }
3203
3204 wxPuts(wxEmptyString);
3205 }
3206
3207 #endif // TEST_WCHAR
3208
3209 // ----------------------------------------------------------------------------
3210 // ZIP stream
3211 // ----------------------------------------------------------------------------
3212
3213 #ifdef TEST_ZIP
3214
3215 #include "wx/filesys.h"
3216 #include "wx/fs_zip.h"
3217 #include "wx/zipstrm.h"
3218
3219 static const wxChar *TESTFILE_ZIP = _T("testdata.zip");
3220
3221 static void TestZipStreamRead()
3222 {
3223 wxPuts(_T("*** Testing ZIP reading ***\n"));
3224
3225 static const wxString filename = _T("foo");
3226 wxZipInputStream istr(TESTFILE_ZIP, filename);
3227 wxPrintf(_T("Archive size: %u\n"), istr.GetSize());
3228
3229 wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str());
3230 while ( !istr.Eof() )
3231 {
3232 wxPutchar(istr.GetC());
3233 fflush(stdout);
3234 }
3235
3236 wxPuts(_T("\n----- done ------"));
3237 }
3238
3239 static void DumpZipDirectory(wxFileSystem& fs,
3240 const wxString& dir,
3241 const wxString& indent)
3242 {
3243 wxString prefix = wxString::Format(_T("%s#zip:%s"),
3244 TESTFILE_ZIP, dir.c_str());
3245 wxString wildcard = prefix + _T("/*");
3246
3247 wxString dirname = fs.FindFirst(wildcard, wxDIR);
3248 while ( !dirname.empty() )
3249 {
3250 if ( !dirname.StartsWith(prefix + _T('/'), &dirname) )
3251 {
3252 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3253
3254 break;
3255 }
3256
3257 wxPrintf(_T("%s%s\n"), indent.c_str(), dirname.c_str());
3258
3259 DumpZipDirectory(fs, dirname,
3260 indent + wxString(_T(' '), 4));
3261
3262 dirname = fs.FindNext();
3263 }
3264
3265 wxString filename = fs.FindFirst(wildcard, wxFILE);
3266 while ( !filename.empty() )
3267 {
3268 if ( !filename.StartsWith(prefix, &filename) )
3269 {
3270 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3271
3272 break;
3273 }
3274
3275 wxPrintf(_T("%s%s\n"), indent.c_str(), filename.c_str());
3276
3277 filename = fs.FindNext();
3278 }
3279 }
3280
3281 static void TestZipFileSystem()
3282 {
3283 wxPuts(_T("*** Testing ZIP file system ***\n"));
3284
3285 wxFileSystem::AddHandler(new wxZipFSHandler);
3286 wxFileSystem fs;
3287 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP);
3288
3289 DumpZipDirectory(fs, _T(""), wxString(_T(' '), 4));
3290 }
3291
3292 #endif // TEST_ZIP
3293
3294 // ----------------------------------------------------------------------------
3295 // date time
3296 // ----------------------------------------------------------------------------
3297
3298 #ifdef TEST_DATETIME
3299
3300 #include "wx/math.h"
3301 #include "wx/datetime.h"
3302
3303 // this test miscellaneous static wxDateTime functions
3304
3305 #if TEST_ALL
3306
3307 static void TestTimeStatic()
3308 {
3309 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3310
3311 // some info about the current date
3312 int year = wxDateTime::GetCurrentYear();
3313 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3314 year,
3315 wxDateTime::IsLeapYear(year) ? "" : "not ",
3316 wxDateTime::GetNumberOfDays(year));
3317
3318 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
3319 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3320 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
3321 wxDateTime::GetMonthName(month).c_str(),
3322 wxDateTime::GetNumberOfDays(month));
3323 }
3324
3325 // test time zones stuff
3326 static void TestTimeZones()
3327 {
3328 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3329
3330 wxDateTime now = wxDateTime::Now();
3331
3332 wxPrintf(_T("Current GMT time:\t%s\n"), now.Format(_T("%c"), wxDateTime::GMT0).c_str());
3333 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0).c_str());
3334 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST).c_str());
3335 wxPrintf(_T("Current time in Paris:\t%s\n"), now.Format(_T("%c"), wxDateTime::CET).c_str());
3336 wxPrintf(_T(" Moscow:\t%s\n"), now.Format(_T("%c"), wxDateTime::MSK).c_str());
3337 wxPrintf(_T(" New York:\t%s\n"), now.Format(_T("%c"), wxDateTime::EST).c_str());
3338
3339 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3340
3341 wxDateTime::Tm tm = now.GetTm();
3342 if ( wxDateTime(tm) != now )
3343 {
3344 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3345 wxDateTime(tm).Format().c_str(), now.Format().c_str());
3346 }
3347 }
3348
3349 // test some minimal support for the dates outside the standard range
3350 static void TestTimeRange()
3351 {
3352 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3353
3354 static const wxChar *fmt = _T("%d-%b-%Y %H:%M:%S");
3355
3356 wxPrintf(_T("Unix epoch:\t%s\n"),
3357 wxDateTime(2440587.5).Format(fmt).c_str());
3358 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3359 wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str());
3360 wxPrintf(_T("JDN 0: \t%s\n"),
3361 wxDateTime(0.0).Format(fmt).c_str());
3362 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3363 wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str());
3364 wxPrintf(_T("May 29, 2099:\t%s\n"),
3365 wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str());
3366 }
3367
3368 // test DST calculations
3369 static void TestTimeDST()
3370 {
3371 wxPuts(_T("\n*** wxDateTime DST test ***"));
3372
3373 wxPrintf(_T("DST is%s in effect now.\n\n"),
3374 wxDateTime::Now().IsDST() ? wxEmptyString : _T(" not"));
3375
3376 for ( int year = 1990; year < 2005; year++ )
3377 {
3378 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3379 year,
3380 wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
3381 wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
3382 }
3383 }
3384
3385 #endif // TEST_ALL
3386
3387 #if TEST_INTERACTIVE
3388
3389 static void TestDateTimeInteractive()
3390 {
3391 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3392
3393 wxChar buf[128];
3394
3395 for ( ;; )
3396 {
3397 wxPrintf(_T("Enter a date: "));
3398 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
3399 break;
3400
3401 // kill the last '\n'
3402 buf[wxStrlen(buf) - 1] = 0;
3403
3404 wxDateTime dt;
3405 const wxChar *p = dt.ParseDate(buf);
3406 if ( !p )
3407 {
3408 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf);
3409
3410 continue;
3411 }
3412 else if ( *p )
3413 {
3414 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p - buf);
3415 }
3416
3417 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3418 dt.Format(_T("%b %d, %Y")).c_str(),
3419 dt.GetDayOfYear(),
3420 dt.GetWeekOfMonth(wxDateTime::Monday_First),
3421 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
3422 dt.GetWeekOfYear(wxDateTime::Monday_First));
3423 }
3424
3425 wxPuts(_T("\n*** done ***"));
3426 }
3427
3428 #endif // TEST_INTERACTIVE
3429
3430 #if TEST_ALL
3431
3432 static void TestTimeMS()
3433 {
3434 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3435
3436 wxDateTime dt1 = wxDateTime::Now(),
3437 dt2 = wxDateTime::UNow();
3438
3439 wxPrintf(_T("Now = %s\n"), dt1.Format(_T("%H:%M:%S:%l")).c_str());
3440 wxPrintf(_T("UNow = %s\n"), dt2.Format(_T("%H:%M:%S:%l")).c_str());
3441 wxPrintf(_T("Dummy loop: "));
3442 for ( int i = 0; i < 6000; i++ )
3443 {
3444 //for ( int j = 0; j < 10; j++ )
3445 {
3446 wxString s;
3447 s.Printf(_T("%g"), sqrt((float)i));
3448 }
3449
3450 if ( !(i % 100) )
3451 wxPutchar('.');
3452 }
3453 wxPuts(_T(", done"));
3454
3455 dt1 = dt2;
3456 dt2 = wxDateTime::UNow();
3457 wxPrintf(_T("UNow = %s\n"), dt2.Format(_T("%H:%M:%S:%l")).c_str());
3458
3459 wxPrintf(_T("Loop executed in %s ms\n"), (dt2 - dt1).Format(_T("%l")).c_str());
3460
3461 wxPuts(_T("\n*** done ***"));
3462 }
3463
3464 static void TestTimeHolidays()
3465 {
3466 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3467
3468 wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
3469 wxDateTime dtStart(1, tm.mon, tm.year),
3470 dtEnd = dtStart.GetLastMonthDay();
3471
3472 wxDateTimeArray hol;
3473 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
3474
3475 const wxChar *format = _T("%d-%b-%Y (%a)");
3476
3477 wxPrintf(_T("All holidays between %s and %s:\n"),
3478 dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
3479
3480 size_t count = hol.GetCount();
3481 for ( size_t n = 0; n < count; n++ )
3482 {
3483 wxPrintf(_T("\t%s\n"), hol[n].Format(format).c_str());
3484 }
3485
3486 wxPuts(wxEmptyString);
3487 }
3488
3489 static void TestTimeZoneBug()
3490 {
3491 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3492
3493 wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000);
3494 for ( int i = 0; i < 31; i++ )
3495 {
3496 wxPrintf(_T("Date %s: week day %s.\n"),
3497 date.Format(_T("%d-%m-%Y")).c_str(),
3498 date.GetWeekDayName(date.GetWeekDay()).c_str());
3499
3500 date += wxDateSpan::Day();
3501 }
3502
3503 wxPuts(wxEmptyString);
3504 }
3505
3506 static void TestTimeSpanFormat()
3507 {
3508 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3509
3510 static const wxChar *formats[] =
3511 {
3512 _T("(default) %H:%M:%S"),
3513 _T("%E weeks and %D days"),
3514 _T("%l milliseconds"),
3515 _T("(with ms) %H:%M:%S:%l"),
3516 _T("100%% of minutes is %M"), // test "%%"
3517 _T("%D days and %H hours"),
3518 _T("or also %S seconds"),
3519 };
3520
3521 wxTimeSpan ts1(1, 2, 3, 4),
3522 ts2(111, 222, 333);
3523 for ( size_t n = 0; n < WXSIZEOF(formats); n++ )
3524 {
3525 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3526 ts1.Format(formats[n]).c_str(),
3527 ts2.Format(formats[n]).c_str());
3528 }
3529
3530 wxPuts(wxEmptyString);
3531 }
3532
3533 #endif // TEST_ALL
3534
3535 #endif // TEST_DATETIME
3536
3537 // ----------------------------------------------------------------------------
3538 // wxTextInput/OutputStream
3539 // ----------------------------------------------------------------------------
3540
3541 #ifdef TEST_TEXTSTREAM
3542
3543 #include "wx/txtstrm.h"
3544 #include "wx/wfstream.h"
3545
3546 static void TestTextInputStream()
3547 {
3548 wxPuts(_T("\n*** wxTextInputStream test ***"));
3549
3550 wxString filename = _T("testdata.fc");
3551 wxFileInputStream fsIn(filename);
3552 if ( !fsIn.Ok() )
3553 {
3554 wxPuts(_T("ERROR: couldn't open file."));
3555 }
3556 else
3557 {
3558 wxTextInputStream tis(fsIn);
3559
3560 size_t line = 1;
3561 for ( ;; )
3562 {
3563 const wxString s = tis.ReadLine();
3564
3565 // line could be non empty if the last line of the file isn't
3566 // terminated with EOL
3567 if ( fsIn.Eof() && s.empty() )
3568 break;
3569
3570 wxPrintf(_T("Line %d: %s\n"), line++, s.c_str());
3571 }
3572 }
3573 }
3574
3575 #endif // TEST_TEXTSTREAM
3576
3577 // ----------------------------------------------------------------------------
3578 // threads
3579 // ----------------------------------------------------------------------------
3580
3581 #ifdef TEST_THREADS
3582
3583 #include "wx/thread.h"
3584
3585 static size_t gs_counter = (size_t)-1;
3586 static wxCriticalSection gs_critsect;
3587 static wxSemaphore gs_cond;
3588
3589 class MyJoinableThread : public wxThread
3590 {
3591 public:
3592 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
3593 { m_n = n; Create(); }
3594
3595 // thread execution starts here
3596 virtual ExitCode Entry();
3597
3598 private:
3599 size_t m_n;
3600 };
3601
3602 wxThread::ExitCode MyJoinableThread::Entry()
3603 {
3604 unsigned long res = 1;
3605 for ( size_t n = 1; n < m_n; n++ )
3606 {
3607 res *= n;
3608
3609 // it's a loooong calculation :-)
3610 Sleep(100);
3611 }
3612
3613 return (ExitCode)res;
3614 }
3615
3616 class MyDetachedThread : public wxThread
3617 {
3618 public:
3619 MyDetachedThread(size_t n, wxChar ch)
3620 {
3621 m_n = n;
3622 m_ch = ch;
3623 m_cancelled = false;
3624
3625 Create();
3626 }
3627
3628 // thread execution starts here
3629 virtual ExitCode Entry();
3630
3631 // and stops here
3632 virtual void OnExit();
3633
3634 private:
3635 size_t m_n; // number of characters to write
3636 wxChar m_ch; // character to write
3637
3638 bool m_cancelled; // false if we exit normally
3639 };
3640
3641 wxThread::ExitCode MyDetachedThread::Entry()
3642 {
3643 {
3644 wxCriticalSectionLocker lock(gs_critsect);
3645 if ( gs_counter == (size_t)-1 )
3646 gs_counter = 1;
3647 else
3648 gs_counter++;
3649 }
3650
3651 for ( size_t n = 0; n < m_n; n++ )
3652 {
3653 if ( TestDestroy() )
3654 {
3655 m_cancelled = true;
3656
3657 break;
3658 }
3659
3660 wxPutchar(m_ch);
3661 fflush(stdout);
3662
3663 wxThread::Sleep(100);
3664 }
3665
3666 return 0;
3667 }
3668
3669 void MyDetachedThread::OnExit()
3670 {
3671 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
3672
3673 wxCriticalSectionLocker lock(gs_critsect);
3674 if ( !--gs_counter && !m_cancelled )
3675 gs_cond.Post();
3676 }
3677
3678 static void TestDetachedThreads()
3679 {
3680 wxPuts(_T("\n*** Testing detached threads ***"));
3681
3682 static const size_t nThreads = 3;
3683 MyDetachedThread *threads[nThreads];
3684 size_t n;
3685 for ( n = 0; n < nThreads; n++ )
3686 {
3687 threads[n] = new MyDetachedThread(10, 'A' + n);
3688 }
3689
3690 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
3691 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
3692
3693 for ( n = 0; n < nThreads; n++ )
3694 {
3695 threads[n]->Run();
3696 }
3697
3698 // wait until all threads terminate
3699 gs_cond.Wait();
3700
3701 wxPuts(wxEmptyString);
3702 }
3703
3704 static void TestJoinableThreads()
3705 {
3706 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
3707
3708 // calc 10! in the background
3709 MyJoinableThread thread(10);
3710 thread.Run();
3711
3712 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
3713 (unsigned long)thread.Wait());
3714 }
3715
3716 static void TestThreadSuspend()
3717 {
3718 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
3719
3720 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
3721
3722 thread->Run();
3723
3724 // this is for this demo only, in a real life program we'd use another
3725 // condition variable which would be signaled from wxThread::Entry() to
3726 // tell us that the thread really started running - but here just wait a
3727 // bit and hope that it will be enough (the problem is, of course, that
3728 // the thread might still not run when we call Pause() which will result
3729 // in an error)
3730 wxThread::Sleep(300);
3731
3732 for ( size_t n = 0; n < 3; n++ )
3733 {
3734 thread->Pause();
3735
3736 wxPuts(_T("\nThread suspended"));
3737 if ( n > 0 )
3738 {
3739 // don't sleep but resume immediately the first time
3740 wxThread::Sleep(300);
3741 }
3742 wxPuts(_T("Going to resume the thread"));
3743
3744 thread->Resume();
3745 }
3746
3747 wxPuts(_T("Waiting until it terminates now"));
3748
3749 // wait until the thread terminates
3750 gs_cond.Wait();
3751
3752 wxPuts(wxEmptyString);
3753 }
3754
3755 static void TestThreadDelete()
3756 {
3757 // As above, using Sleep() is only for testing here - we must use some
3758 // synchronisation object instead to ensure that the thread is still
3759 // running when we delete it - deleting a detached thread which already
3760 // terminated will lead to a crash!
3761
3762 wxPuts(_T("\n*** Testing thread delete function ***"));
3763
3764 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
3765
3766 thread0->Delete();
3767
3768 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
3769
3770 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
3771
3772 thread1->Run();
3773
3774 wxThread::Sleep(300);
3775
3776 thread1->Delete();
3777
3778 wxPuts(_T("\nDeleted a running thread."));
3779
3780 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
3781
3782 thread2->Run();
3783
3784 wxThread::Sleep(300);
3785
3786 thread2->Pause();
3787
3788 thread2->Delete();
3789
3790 wxPuts(_T("\nDeleted a sleeping thread."));
3791
3792 MyJoinableThread thread3(20);
3793 thread3.Run();
3794
3795 thread3.Delete();
3796
3797 wxPuts(_T("\nDeleted a joinable thread."));
3798
3799 MyJoinableThread thread4(2);
3800 thread4.Run();
3801
3802 wxThread::Sleep(300);
3803
3804 thread4.Delete();
3805
3806 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
3807
3808 wxPuts(wxEmptyString);
3809 }
3810
3811 class MyWaitingThread : public wxThread
3812 {
3813 public:
3814 MyWaitingThread( wxMutex *mutex, wxCondition *condition )
3815 {
3816 m_mutex = mutex;
3817 m_condition = condition;
3818
3819 Create();
3820 }
3821
3822 virtual ExitCode Entry()
3823 {
3824 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
3825 fflush(stdout);
3826
3827 gs_cond.Post();
3828
3829 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
3830 fflush(stdout);
3831
3832 m_mutex->Lock();
3833 m_condition->Wait();
3834 m_mutex->Unlock();
3835
3836 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
3837 fflush(stdout);
3838
3839 return 0;
3840 }
3841
3842 private:
3843 wxMutex *m_mutex;
3844 wxCondition *m_condition;
3845 };
3846
3847 static void TestThreadConditions()
3848 {
3849 wxMutex mutex;
3850 wxCondition condition(mutex);
3851
3852 // otherwise its difficult to understand which log messages pertain to
3853 // which condition
3854 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
3855 // condition.GetId(), gs_cond.GetId());
3856
3857 // create and launch threads
3858 MyWaitingThread *threads[10];
3859
3860 size_t n;
3861 for ( n = 0; n < WXSIZEOF(threads); n++ )
3862 {
3863 threads[n] = new MyWaitingThread( &mutex, &condition );
3864 }
3865
3866 for ( n = 0; n < WXSIZEOF(threads); n++ )
3867 {
3868 threads[n]->Run();
3869 }
3870
3871 // wait until all threads run
3872 wxPuts(_T("Main thread is waiting for the other threads to start"));
3873 fflush(stdout);
3874
3875 size_t nRunning = 0;
3876 while ( nRunning < WXSIZEOF(threads) )
3877 {
3878 gs_cond.Wait();
3879
3880 nRunning++;
3881
3882 wxPrintf(_T("Main thread: %u already running\n"), nRunning);
3883 fflush(stdout);
3884 }
3885
3886 wxPuts(_T("Main thread: all threads started up."));
3887 fflush(stdout);
3888
3889 wxThread::Sleep(500);
3890
3891 #if 1
3892 // now wake one of them up
3893 wxPrintf(_T("Main thread: about to signal the condition.\n"));
3894 fflush(stdout);
3895 condition.Signal();
3896 #endif
3897
3898 wxThread::Sleep(200);
3899
3900 // wake all the (remaining) threads up, so that they can exit
3901 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
3902 fflush(stdout);
3903 condition.Broadcast();
3904
3905 // give them time to terminate (dirty!)
3906 wxThread::Sleep(500);
3907 }
3908
3909 #include "wx/utils.h"
3910
3911 class MyExecThread : public wxThread
3912 {
3913 public:
3914 MyExecThread(const wxString& command) : wxThread(wxTHREAD_JOINABLE),
3915 m_command(command)
3916 {
3917 Create();
3918 }
3919
3920 virtual ExitCode Entry()
3921 {
3922 return (ExitCode)wxExecute(m_command, wxEXEC_SYNC);
3923 }
3924
3925 private:
3926 wxString m_command;
3927 };
3928
3929 static void TestThreadExec()
3930 {
3931 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
3932
3933 MyExecThread thread(_T("true"));
3934 thread.Run();
3935
3936 wxPrintf(_T("Main program exit code: %ld.\n"),
3937 wxExecute(_T("false"), wxEXEC_SYNC));
3938
3939 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread.Wait());
3940 }
3941
3942 // semaphore tests
3943 #include "wx/datetime.h"
3944
3945 class MySemaphoreThread : public wxThread
3946 {
3947 public:
3948 MySemaphoreThread(int i, wxSemaphore *sem)
3949 : wxThread(wxTHREAD_JOINABLE),
3950 m_sem(sem),
3951 m_i(i)
3952 {
3953 Create();
3954 }
3955
3956 virtual ExitCode Entry()
3957 {
3958 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
3959 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
3960
3961 m_sem->Wait();
3962
3963 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
3964 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
3965
3966 Sleep(1000);
3967
3968 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
3969 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
3970
3971 m_sem->Post();
3972
3973 return 0;
3974 }
3975
3976 private:
3977 wxSemaphore *m_sem;
3978 int m_i;
3979 };
3980
3981 WX_DEFINE_ARRAY_PTR(wxThread *, ArrayThreads);
3982
3983 static void TestSemaphore()
3984 {
3985 wxPuts(_T("*** Testing wxSemaphore class. ***"));
3986
3987 static const int SEM_LIMIT = 3;
3988
3989 wxSemaphore sem(SEM_LIMIT, SEM_LIMIT);
3990 ArrayThreads threads;
3991
3992 for ( int i = 0; i < 3*SEM_LIMIT; i++ )
3993 {
3994 threads.Add(new MySemaphoreThread(i, &sem));
3995 threads.Last()->Run();
3996 }
3997
3998 for ( size_t n = 0; n < threads.GetCount(); n++ )
3999 {
4000 threads[n]->Wait();
4001 delete threads[n];
4002 }
4003 }
4004
4005 #endif // TEST_THREADS
4006
4007 // ----------------------------------------------------------------------------
4008 // entry point
4009 // ----------------------------------------------------------------------------
4010
4011 #ifdef TEST_SNGLINST
4012 #include "wx/snglinst.h"
4013 #endif // TEST_SNGLINST
4014
4015 int main(int argc, char **argv)
4016 {
4017 #if wxUSE_UNICODE
4018 wxChar **wxArgv = new wxChar *[argc + 1];
4019
4020 {
4021 int n;
4022
4023 for (n = 0; n < argc; n++ )
4024 {
4025 wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
4026 wxArgv[n] = wxStrdup(warg);
4027 }
4028
4029 wxArgv[n] = NULL;
4030 }
4031 #else // !wxUSE_UNICODE
4032 #define wxArgv argv
4033 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
4034
4035 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
4036
4037 wxInitializer initializer;
4038 if ( !initializer )
4039 {
4040 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
4041
4042 return -1;
4043 }
4044
4045 #ifdef TEST_SNGLINST
4046 wxSingleInstanceChecker checker;
4047 if ( checker.Create(_T(".wxconsole.lock")) )
4048 {
4049 if ( checker.IsAnotherRunning() )
4050 {
4051 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4052
4053 return 1;
4054 }
4055
4056 // wait some time to give time to launch another instance
4057 wxPrintf(_T("Press \"Enter\" to continue..."));
4058 wxFgetc(stdin);
4059 }
4060 else // failed to create
4061 {
4062 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4063 }
4064 #endif // TEST_SNGLINST
4065
4066 #ifdef TEST_CMDLINE
4067 TestCmdLineConvert();
4068
4069 #if wxUSE_CMDLINE_PARSER
4070 static const wxCmdLineEntryDesc cmdLineDesc[] =
4071 {
4072 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"),
4073 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
4074 { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") },
4075 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
4076
4077 { wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file") },
4078 { wxCMD_LINE_OPTION, _T("i"), _T("input"), _T("input dir") },
4079 { wxCMD_LINE_OPTION, _T("s"), _T("size"), _T("output block size"),
4080 wxCMD_LINE_VAL_NUMBER },
4081 { wxCMD_LINE_OPTION, _T("d"), _T("date"), _T("output file date"),
4082 wxCMD_LINE_VAL_DATE },
4083
4084 { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
4085 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
4086
4087 { wxCMD_LINE_NONE }
4088 };
4089
4090 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
4091
4092 parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4093 wxCMD_LINE_VAL_STRING,
4094 wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);
4095
4096 switch ( parser.Parse() )
4097 {
4098 case -1:
4099 wxLogMessage(_T("Help was given, terminating."));
4100 break;
4101
4102 case 0:
4103 ShowCmdLine(parser);
4104 break;
4105
4106 default:
4107 wxLogMessage(_T("Syntax error detected, aborting."));
4108 break;
4109 }
4110 #endif // wxUSE_CMDLINE_PARSER
4111
4112 #endif // TEST_CMDLINE
4113
4114 #ifdef TEST_DIR
4115 #if TEST_ALL
4116 TestDirExists();
4117 TestDirEnum();
4118 #endif
4119 TestDirTraverse();
4120 #endif // TEST_DIR
4121
4122 #ifdef TEST_DLLLOADER
4123 TestDllLoad();
4124 TestDllListLoaded();
4125 #endif // TEST_DLLLOADER
4126
4127 #ifdef TEST_ENVIRON
4128 TestEnvironment();
4129 #endif // TEST_ENVIRON
4130
4131 #ifdef TEST_EXECUTE
4132 TestExecute();
4133 #endif // TEST_EXECUTE
4134
4135 #ifdef TEST_FILECONF
4136 TestFileConfRead();
4137 #endif // TEST_FILECONF
4138
4139 #ifdef TEST_LOCALE
4140 TestDefaultLang();
4141 #endif // TEST_LOCALE
4142
4143 #ifdef TEST_LOG
4144 wxPuts(_T("*** Testing wxLog ***"));
4145
4146 wxString s;
4147 for ( size_t n = 0; n < 8000; n++ )
4148 {
4149 s << (wxChar)(_T('A') + (n % 26));
4150 }
4151
4152 wxLogWarning(_T("The length of the string is %lu"),
4153 (unsigned long)s.length());
4154
4155 wxString msg;
4156 msg.Printf(_T("A very very long message: '%s', the end!\n"), s.c_str());
4157
4158 // this one shouldn't be truncated
4159 wxPrintf(msg);
4160
4161 // but this one will because log functions use fixed size buffer
4162 // (note that it doesn't need '\n' at the end neither - will be added
4163 // by wxLog anyhow)
4164 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s.c_str());
4165 #endif // TEST_LOG
4166
4167 #ifdef TEST_FILE
4168 TestFileRead();
4169 TestTextFileRead();
4170 TestFileCopy();
4171 #endif // TEST_FILE
4172
4173 #ifdef TEST_FILENAME
4174 TestFileNameTemp();
4175 TestFileNameCwd();
4176 TestFileNameDirManip();
4177 TestFileNameComparison();
4178 TestFileNameOperations();
4179 #endif // TEST_FILENAME
4180
4181 #ifdef TEST_FILETIME
4182 TestFileGetTimes();
4183 #if 0
4184 TestFileSetTimes();
4185 #endif
4186 #endif // TEST_FILETIME
4187
4188 #ifdef TEST_FTP
4189 wxLog::AddTraceMask(FTP_TRACE_MASK);
4190 if ( TestFtpConnect() )
4191 {
4192 #if TEST_ALL
4193 TestFtpList();
4194 TestFtpDownload();
4195 TestFtpMisc();
4196 TestFtpFileSize();
4197 TestFtpUpload();
4198 #endif // TEST_ALL
4199
4200 #if TEST_INTERACTIVE
4201 TestFtpInteractive();
4202 #endif
4203 }
4204 //else: connecting to the FTP server failed
4205
4206 #if 0
4207 TestFtpWuFtpd();
4208 #endif
4209 #endif // TEST_FTP
4210
4211 #ifdef TEST_MIME
4212 wxLog::AddTraceMask(_T("mime"));
4213 #if TEST_ALL
4214 TestMimeEnum();
4215 TestMimeOverride();
4216 TestMimeAssociate();
4217 #endif
4218 TestMimeFilename();
4219 #endif // TEST_MIME
4220
4221 #ifdef TEST_INFO_FUNCTIONS
4222 #if TEST_ALL
4223 TestOsInfo();
4224 TestUserInfo();
4225
4226 #if TEST_INTERACTIVE
4227 TestDiskInfo();
4228 #endif
4229 #endif
4230 #endif // TEST_INFO_FUNCTIONS
4231
4232 #ifdef TEST_PATHLIST
4233 TestPathList();
4234 #endif // TEST_PATHLIST
4235
4236 #ifdef TEST_ODBC
4237 TestDbOpen();
4238 #endif // TEST_ODBC
4239
4240 #ifdef TEST_PRINTF
4241 TestPrintf();
4242 #endif // TEST_PRINTF
4243
4244 #ifdef TEST_REGCONF
4245 #if 0
4246 TestRegConfWrite();
4247 #endif
4248 TestRegConfRead();
4249 #endif // TEST_REGCONF
4250
4251 #if defined TEST_REGEX && TEST_INTERACTIVE
4252 TestRegExInteractive();
4253 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4254
4255 #ifdef TEST_REGISTRY
4256 TestRegistryRead();
4257 TestRegistryAssociation();
4258 #endif // TEST_REGISTRY
4259
4260 #ifdef TEST_SOCKETS
4261 TestSocketServer();
4262 TestSocketClient();
4263 #endif // TEST_SOCKETS
4264
4265 #ifdef TEST_STREAMS
4266 #if TEST_ALL
4267 TestFileStream();
4268 #endif
4269 TestMemoryStream();
4270 #endif // TEST_STREAMS
4271
4272 #ifdef TEST_TEXTSTREAM
4273 TestTextInputStream();
4274 #endif // TEST_TEXTSTREAM
4275
4276 #ifdef TEST_THREADS
4277 int nCPUs = wxThread::GetCPUCount();
4278 wxPrintf(_T("This system has %d CPUs\n"), nCPUs);
4279 if ( nCPUs != -1 )
4280 wxThread::SetConcurrency(nCPUs);
4281
4282 TestJoinableThreads();
4283
4284 #if TEST_ALL
4285 TestJoinableThreads();
4286 TestDetachedThreads();
4287 TestThreadSuspend();
4288 TestThreadDelete();
4289 TestThreadConditions();
4290 TestThreadExec();
4291 TestSemaphore();
4292 #endif
4293 #endif // TEST_THREADS
4294
4295 #ifdef TEST_TIMER
4296 TestStopWatch();
4297 #endif // TEST_TIMER
4298
4299 #ifdef TEST_DATETIME
4300 #if TEST_ALL
4301 TestTimeStatic();
4302 TestTimeRange();
4303 TestTimeZones();
4304 TestTimeDST();
4305 TestTimeHolidays();
4306 TestTimeSpanFormat();
4307 TestTimeMS();
4308
4309 TestTimeZoneBug();
4310 #endif
4311
4312 #if TEST_INTERACTIVE
4313 TestDateTimeInteractive();
4314 #endif
4315 #endif // TEST_DATETIME
4316
4317 #ifdef TEST_SCOPEGUARD
4318 TestScopeGuard();
4319 #endif
4320
4321 #ifdef TEST_STACKWALKER
4322 #if wxUSE_STACKWALKER
4323 TestStackWalk(argv[0]);
4324 #endif
4325 #endif // TEST_STACKWALKER
4326
4327 #ifdef TEST_STDPATHS
4328 TestStandardPaths();
4329 #endif
4330
4331 #ifdef TEST_USLEEP
4332 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4333 wxUsleep(3000);
4334 #endif // TEST_USLEEP
4335
4336 #ifdef TEST_VCARD
4337 TestVCardRead();
4338 TestVCardWrite();
4339 #endif // TEST_VCARD
4340
4341 #ifdef TEST_VOLUME
4342 TestFSVolume();
4343 #endif // TEST_VOLUME
4344
4345 #ifdef TEST_WCHAR
4346 TestUtf8();
4347 TestEncodingConverter();
4348 #endif // TEST_WCHAR
4349
4350 #ifdef TEST_ZIP
4351 TestZipStreamRead();
4352 TestZipFileSystem();
4353 #endif // TEST_ZIP
4354
4355 #if wxUSE_UNICODE
4356 {
4357 for ( int n = 0; n < argc; n++ )
4358 free(wxArgv[n]);
4359
4360 delete [] wxArgv;
4361 }
4362 #endif // wxUSE_UNICODE
4363
4364 wxUnusedVar(argc);
4365 wxUnusedVar(argv);
4366 return 0;
4367 }
4368