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