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