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