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