]> git.saurik.com Git - wxWidgets.git/blame - samples/console/console.cpp
somehow this got missed on the last commit..
[wxWidgets.git] / samples / console / console.cpp
CommitLineData
37667812
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: samples/console/console.cpp
3// Purpose: a sample console (as opposed to GUI) progam using wxWindows
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
e87271f3
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e84010cf 20#include "wx/defs.h"
b11a23f3
VZ
21
22#if wxUSE_GUI
23 #error "This sample can't be compiled in GUI mode."
24#endif // wxUSE_GUI
25
37667812
VZ
26#include <stdio.h>
27
e84010cf
GD
28#include "wx/string.h"
29#include "wx/file.h"
30#include "wx/app.h"
e87271f3 31
d31b7b68
VZ
32// without this pragma, the stupid compiler precompiles #defines below so that
33// changing them doesn't "take place" later!
34#ifdef __VISUALC__
35 #pragma hdrstop
36#endif
37
e87271f3
VZ
38// ----------------------------------------------------------------------------
39// conditional compilation
40// ----------------------------------------------------------------------------
41
31f6de22
VZ
42// what to test (in alphabetic order)? uncomment the line below to do all tests
43//#define TEST_ALL
44#ifdef TEST_ALL
45 #define TEST_ARRAYS
46 #define TEST_CHARSET
47 #define TEST_CMDLINE
48 #define TEST_DATETIME
49 #define TEST_DIR
50 #define TEST_DLLLOADER
51 #define TEST_ENVIRON
52 #define TEST_EXECUTE
53 #define TEST_FILE
54 #define TEST_FILECONF
55 #define TEST_FILENAME
56 #define TEST_FILETIME
57 #define TEST_FTP
58 #define TEST_HASH
59 #define TEST_INFO_FUNCTIONS
60 #define TEST_LIST
61 #define TEST_LOCALE
62 #define TEST_LOG
63 #define TEST_LONGLONG
64 #define TEST_MIME
65 #define TEST_PATHLIST
66 #define TEST_REGCONF
67 #define TEST_REGEX
68 #define TEST_REGISTRY
69 #define TEST_SNGLINST
70 #define TEST_SOCKETS
71 #define TEST_STREAMS
72 #define TEST_STRINGS
73 #define TEST_THREADS
74 #define TEST_TIMER
75 // #define TEST_VCARD -- don't enable this (VZ)
76 #define TEST_WCHAR
77 #define TEST_ZIP
78 #define TEST_ZLIB
79#else
a874db92 80 #define TEST_FILENAME
31f6de22 81#endif
f6bcfd97 82
58b24a56 83#ifdef TEST_SNGLINST
e84010cf 84 #include "wx/snglinst.h"
58b24a56
VZ
85#endif // TEST_SNGLINST
86
f6bcfd97
BP
87// ----------------------------------------------------------------------------
88// test class for container objects
89// ----------------------------------------------------------------------------
90
91#if defined(TEST_ARRAYS) || defined(TEST_LIST)
92
93class Bar // Foo is already taken in the hash test
94{
95public:
96 Bar(const wxString& name) : m_name(name) { ms_bars++; }
97 ~Bar() { ms_bars--; }
98
99 static size_t GetNumber() { return ms_bars; }
100
101 const char *GetName() const { return m_name; }
102
103private:
104 wxString m_name;
105
106 static size_t ms_bars;
107};
108
109size_t Bar::ms_bars = 0;
110
111#endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
e87271f3
VZ
112
113// ============================================================================
114// implementation
115// ============================================================================
116
8e907a13
VZ
117// ----------------------------------------------------------------------------
118// helper functions
119// ----------------------------------------------------------------------------
120
121#if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
122
123// replace TABs with \t and CRs with \n
124static wxString MakePrintable(const wxChar *s)
125{
126 wxString str(s);
127 (void)str.Replace(_T("\t"), _T("\\t"));
128 (void)str.Replace(_T("\n"), _T("\\n"));
129 (void)str.Replace(_T("\r"), _T("\\r"));
130
131 return str;
132}
133
134#endif // MakePrintable() is used
135
551fe3a6
VZ
136// ----------------------------------------------------------------------------
137// wxFontMapper::CharsetToEncoding
138// ----------------------------------------------------------------------------
139
140#ifdef TEST_CHARSET
141
e84010cf 142#include "wx/fontmap.h"
551fe3a6
VZ
143
144static void TestCharset()
145{
146 static const wxChar *charsets[] =
147 {
148 // some vali charsets
149 _T("us-ascii "),
150 _T("iso8859-1 "),
151 _T("iso-8859-12 "),
152 _T("koi8-r "),
153 _T("utf-7 "),
154 _T("cp1250 "),
155 _T("windows-1252"),
156
157 // and now some bogus ones
158 _T(" "),
159 _T("cp1249 "),
160 _T("iso--8859-1 "),
161 _T("iso-8859-19 "),
162 };
163
164 for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
165 {
166 wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(charsets[n]);
167 wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
168 charsets[n],
169 wxTheFontMapper->GetEncodingName(enc).c_str(),
170 wxTheFontMapper->GetEncodingDescription(enc).c_str());
171 }
172}
173
174#endif // TEST_CHARSET
175
d34bce84
VZ
176// ----------------------------------------------------------------------------
177// wxCmdLineParser
178// ----------------------------------------------------------------------------
179
d31b7b68
VZ
180#ifdef TEST_CMDLINE
181
e84010cf
GD
182#include "wx/cmdline.h"
183#include "wx/datetime.h"
d34bce84 184
31f6de22
VZ
185#if wxUSE_CMDLINE_PARSER
186
d34bce84
VZ
187static void ShowCmdLine(const wxCmdLineParser& parser)
188{
189 wxString s = "Input 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 << "Verbose:\t" << (parser.Found("v") ? "yes" : "no") << '\n'
199 << "Quiet:\t" << (parser.Found("q") ? "yes" : "no") << '\n';
200
201 wxString strVal;
202 long lVal;
203 wxDateTime dt;
204 if ( parser.Found("o", &strVal) )
205 s << "Output file:\t" << strVal << '\n';
206 if ( parser.Found("i", &strVal) )
207 s << "Input dir:\t" << strVal << '\n';
208 if ( parser.Found("s", &lVal) )
209 s << "Size:\t" << lVal << '\n';
210 if ( parser.Found("d", &dt) )
211 s << "Date:\t" << dt.FormatISODate() << '\n';
f6bcfd97
BP
212 if ( parser.Found("project_name", &strVal) )
213 s << "Project:\t" << strVal << '\n';
d34bce84
VZ
214
215 wxLogMessage(s);
216}
217
31f6de22
VZ
218#endif // wxUSE_CMDLINE_PARSER
219
220static void TestCmdLineConvert()
221{
222 static const char *cmdlines[] =
223 {
224 "arg1 arg2",
225 "-a \"-bstring 1\" -c\"string 2\" \"string 3\"",
226 "literal \\\" and \"\"",
227 };
228
229 for ( size_t n = 0; n < WXSIZEOF(cmdlines); n++ )
230 {
231 const char *cmdline = cmdlines[n];
232 printf("Parsing: %s\n", cmdline);
233 wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdline);
234
235 size_t count = args.GetCount();
236 printf("\targc = %u\n", count);
237 for ( size_t arg = 0; arg < count; arg++ )
238 {
239 printf("\targv[%u] = %s\n", arg, args[arg]);
240 }
241 }
242}
243
d34bce84
VZ
244#endif // TEST_CMDLINE
245
1944c6bd
VZ
246// ----------------------------------------------------------------------------
247// wxDir
248// ----------------------------------------------------------------------------
249
250#ifdef TEST_DIR
251
e84010cf 252#include "wx/dir.h"
1944c6bd 253
35332784
VZ
254#ifdef __UNIX__
255 static const wxChar *ROOTDIR = _T("/");
256 static const wxChar *TESTDIR = _T("/usr");
257#elif defined(__WXMSW__)
258 static const wxChar *ROOTDIR = _T("c:\\");
259 static const wxChar *TESTDIR = _T("d:\\");
260#else
261 #error "don't know where the root directory is"
262#endif
263
1944c6bd
VZ
264static void TestDirEnumHelper(wxDir& dir,
265 int flags = wxDIR_DEFAULT,
266 const wxString& filespec = wxEmptyString)
267{
268 wxString filename;
269
270 if ( !dir.IsOpened() )
271 return;
272
273 bool cont = dir.GetFirst(&filename, filespec, flags);
274 while ( cont )
275 {
276 printf("\t%s\n", filename.c_str());
277
278 cont = dir.GetNext(&filename);
279 }
280
281 puts("");
282}
283
284static void TestDirEnum()
285{
35332784
VZ
286 puts("*** Testing wxDir::GetFirst/GetNext ***");
287
1944c6bd
VZ
288 wxDir dir(wxGetCwd());
289
290 puts("Enumerating everything in current directory:");
291 TestDirEnumHelper(dir);
292
293 puts("Enumerating really everything in current directory:");
294 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
295
296 puts("Enumerating object files in current directory:");
297 TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o");
298
299 puts("Enumerating directories in current directory:");
300 TestDirEnumHelper(dir, wxDIR_DIRS);
301
302 puts("Enumerating files in current directory:");
303 TestDirEnumHelper(dir, wxDIR_FILES);
304
305 puts("Enumerating files including hidden in current directory:");
306 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
307
35332784 308 dir.Open(ROOTDIR);
1944c6bd
VZ
309
310 puts("Enumerating everything in root directory:");
311 TestDirEnumHelper(dir, wxDIR_DEFAULT);
312
313 puts("Enumerating directories in root directory:");
314 TestDirEnumHelper(dir, wxDIR_DIRS);
315
316 puts("Enumerating files in root directory:");
317 TestDirEnumHelper(dir, wxDIR_FILES);
318
319 puts("Enumerating files including hidden in root directory:");
320 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
321
322 puts("Enumerating files in non existing directory:");
323 wxDir dirNo("nosuchdir");
324 TestDirEnumHelper(dirNo);
325}
326
35332784
VZ
327class DirPrintTraverser : public wxDirTraverser
328{
329public:
330 virtual wxDirTraverseResult OnFile(const wxString& filename)
331 {
332 return wxDIR_CONTINUE;
333 }
334
335 virtual wxDirTraverseResult OnDir(const wxString& dirname)
336 {
337 wxString path, name, ext;
338 wxSplitPath(dirname, &path, &name, &ext);
339
340 if ( !ext.empty() )
341 name << _T('.') << ext;
342
343 wxString indent;
344 for ( const wxChar *p = path.c_str(); *p; p++ )
345 {
346 if ( wxIsPathSeparator(*p) )
347 indent += _T(" ");
348 }
349
350 printf("%s%s\n", indent.c_str(), name.c_str());
351
352 return wxDIR_CONTINUE;
353 }
354};
355
356static void TestDirTraverse()
357{
358 puts("*** Testing wxDir::Traverse() ***");
359
360 // enum all files
361 wxArrayString files;
362 size_t n = wxDir::GetAllFiles(TESTDIR, &files);
363 printf("There are %u files under '%s'\n", n, TESTDIR);
364 if ( n > 1 )
365 {
2d3112ad
VZ
366 printf("First one is '%s'\n", files[0u].c_str());
367 printf(" last one is '%s'\n", files[n - 1].c_str());
35332784
VZ
368 }
369
370 // enum again with custom traverser
371 wxDir dir(TESTDIR);
372 DirPrintTraverser traverser;
373 dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN);
374}
375
1944c6bd
VZ
376#endif // TEST_DIR
377
f6bcfd97
BP
378// ----------------------------------------------------------------------------
379// wxDllLoader
380// ----------------------------------------------------------------------------
381
382#ifdef TEST_DLLLOADER
383
e84010cf 384#include "wx/dynlib.h"
f6bcfd97
BP
385
386static void TestDllLoad()
387{
388#if defined(__WXMSW__)
389 static const wxChar *LIB_NAME = _T("kernel32.dll");
390 static const wxChar *FUNC_NAME = _T("lstrlenA");
391#elif defined(__UNIX__)
392 // weird: using just libc.so does *not* work!
393 static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
394 static const wxChar *FUNC_NAME = _T("strlen");
395#else
396 #error "don't know how to test wxDllLoader on this platform"
397#endif
398
399 puts("*** testing wxDllLoader ***\n");
400
401 wxDllType dllHandle = wxDllLoader::LoadLibrary(LIB_NAME);
402 if ( !dllHandle )
403 {
404 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME);
405 }
406 else
407 {
e84010cf 408 typedef int (*strlenType)(const char *);
f6bcfd97
BP
409 strlenType pfnStrlen = (strlenType)wxDllLoader::GetSymbol(dllHandle, FUNC_NAME);
410 if ( !pfnStrlen )
411 {
412 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
413 FUNC_NAME, LIB_NAME);
414 }
415 else
416 {
417 if ( pfnStrlen("foo") != 3 )
418 {
419 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
420 }
421 else
422 {
423 puts("... ok");
424 }
425 }
426
427 wxDllLoader::UnloadLibrary(dllHandle);
428 }
429}
430
431#endif // TEST_DLLLOADER
432
8fd0d89b
VZ
433// ----------------------------------------------------------------------------
434// wxGet/SetEnv
435// ----------------------------------------------------------------------------
436
437#ifdef TEST_ENVIRON
438
e84010cf 439#include "wx/utils.h"
8fd0d89b 440
308978f6
VZ
441static wxString MyGetEnv(const wxString& var)
442{
443 wxString val;
444 if ( !wxGetEnv(var, &val) )
445 val = _T("<empty>");
446 else
447 val = wxString(_T('\'')) + val + _T('\'');
448
449 return val;
450}
451
8fd0d89b
VZ
452static void TestEnvironment()
453{
454 const wxChar *var = _T("wxTestVar");
455
456 puts("*** testing environment access functions ***");
457
308978f6 458 printf("Initially getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
8fd0d89b 459 wxSetEnv(var, _T("value for wxTestVar"));
308978f6 460 printf("After wxSetEnv: getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
8fd0d89b 461 wxSetEnv(var, _T("another value"));
308978f6 462 printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
8fd0d89b 463 wxUnsetEnv(var);
308978f6 464 printf("After wxUnsetEnv: getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
2d3112ad 465 printf("PATH = %s\n", MyGetEnv(_T("PATH")).c_str());
8fd0d89b
VZ
466}
467
468#endif // TEST_ENVIRON
469
d93c719a
VZ
470// ----------------------------------------------------------------------------
471// wxExecute
472// ----------------------------------------------------------------------------
473
474#ifdef TEST_EXECUTE
475
e84010cf 476#include "wx/utils.h"
d93c719a
VZ
477
478static void TestExecute()
479{
480 puts("*** testing wxExecute ***");
481
482#ifdef __UNIX__
a1f79c1e 483 #define COMMAND "cat -n ../../Makefile" // "echo hi"
2c8e4738 484 #define SHELL_COMMAND "echo hi from shell"
a1f79c1e 485 #define REDIRECT_COMMAND COMMAND // "date"
d93c719a
VZ
486#elif defined(__WXMSW__)
487 #define COMMAND "command.com -c 'echo hi'"
2c8e4738
VZ
488 #define SHELL_COMMAND "echo hi"
489 #define REDIRECT_COMMAND COMMAND
d93c719a
VZ
490#else
491 #error "no command to exec"
492#endif // OS
493
2c8e4738
VZ
494 printf("Testing wxShell: ");
495 fflush(stdout);
496 if ( wxShell(SHELL_COMMAND) )
497 puts("Ok.");
d93c719a 498 else
2c8e4738
VZ
499 puts("ERROR.");
500
501 printf("Testing wxExecute: ");
502 fflush(stdout);
503 if ( wxExecute(COMMAND, TRUE /* sync */) == 0 )
504 puts("Ok.");
505 else
506 puts("ERROR.");
507
508#if 0 // no, it doesn't work (yet?)
509 printf("Testing async wxExecute: ");
510 fflush(stdout);
511 if ( wxExecute(COMMAND) != 0 )
512 puts("Ok (command launched).");
513 else
514 puts("ERROR.");
515#endif // 0
516
517 printf("Testing wxExecute with redirection:\n");
518 wxArrayString output;
519 if ( wxExecute(REDIRECT_COMMAND, output) != 0 )
520 {
521 puts("ERROR.");
522 }
523 else
524 {
525 size_t count = output.GetCount();
526 for ( size_t n = 0; n < count; n++ )
527 {
528 printf("\t%s\n", output[n].c_str());
529 }
530
531 puts("Ok.");
532 }
d93c719a
VZ
533}
534
535#endif // TEST_EXECUTE
536
f6bcfd97
BP
537// ----------------------------------------------------------------------------
538// file
539// ----------------------------------------------------------------------------
540
541#ifdef TEST_FILE
542
e84010cf
GD
543#include "wx/file.h"
544#include "wx/ffile.h"
545#include "wx/textfile.h"
f6bcfd97
BP
546
547static void TestFileRead()
548{
549 puts("*** wxFile read test ***");
550
551 wxFile file(_T("testdata.fc"));
552 if ( file.IsOpened() )
553 {
554 printf("File length: %lu\n", file.Length());
555
556 puts("File dump:\n----------");
557
3ca6a5f0 558 static const off_t len = 1024;
f6bcfd97
BP
559 char buf[len];
560 for ( ;; )
561 {
562 off_t nRead = file.Read(buf, len);
563 if ( nRead == wxInvalidOffset )
564 {
565 printf("Failed to read the file.");
566 break;
567 }
568
569 fwrite(buf, nRead, 1, stdout);
570
571 if ( nRead < len )
572 break;
573 }
574
575 puts("----------");
576 }
577 else
578 {
579 printf("ERROR: can't open test file.\n");
580 }
581
582 puts("");
583}
584
585static void TestTextFileRead()
586{
587 puts("*** wxTextFile read test ***");
588
589 wxTextFile file(_T("testdata.fc"));
590 if ( file.Open() )
591 {
592 printf("Number of lines: %u\n", file.GetLineCount());
593 printf("Last line: '%s'\n", file.GetLastLine().c_str());
3ca6a5f0
BP
594
595 wxString s;
596
597 puts("\nDumping the entire file:");
598 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
599 {
600 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
601 }
602 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
603
604 puts("\nAnd now backwards:");
605 for ( s = file.GetLastLine();
606 file.GetCurrentLine() != 0;
607 s = file.GetPrevLine() )
608 {
609 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
610 }
611 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
f6bcfd97
BP
612 }
613 else
614 {
615 printf("ERROR: can't open '%s'\n", file.GetName());
616 }
617
618 puts("");
619}
620
a339970a
VZ
621static void TestFileCopy()
622{
623 puts("*** Testing wxCopyFile ***");
624
625 static const wxChar *filename1 = _T("testdata.fc");
626 static const wxChar *filename2 = _T("test2");
627 if ( !wxCopyFile(filename1, filename2) )
628 {
629 puts("ERROR: failed to copy file");
630 }
631 else
632 {
633 wxFFile f1(filename1, "rb"),
634 f2(filename2, "rb");
635
636 if ( !f1.IsOpened() || !f2.IsOpened() )
637 {
638 puts("ERROR: failed to open file(s)");
639 }
640 else
641 {
642 wxString s1, s2;
643 if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
644 {
645 puts("ERROR: failed to read file(s)");
646 }
647 else
648 {
649 if ( (s1.length() != s2.length()) ||
650 (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
651 {
652 puts("ERROR: copy error!");
653 }
654 else
655 {
656 puts("File was copied ok.");
657 }
658 }
659 }
660 }
661
662 if ( !wxRemoveFile(filename2) )
663 {
664 puts("ERROR: failed to remove the file");
665 }
666
667 puts("");
668}
669
f6bcfd97
BP
670#endif // TEST_FILE
671
ee6e1b1d
VZ
672// ----------------------------------------------------------------------------
673// wxFileConfig
674// ----------------------------------------------------------------------------
675
676#ifdef TEST_FILECONF
677
e84010cf
GD
678#include "wx/confbase.h"
679#include "wx/fileconf.h"
ee6e1b1d
VZ
680
681static const struct FileConfTestData
682{
683 const wxChar *name; // value name
684 const wxChar *value; // the value from the file
685} fcTestData[] =
686{
687 { _T("value1"), _T("one") },
688 { _T("value2"), _T("two") },
689 { _T("novalue"), _T("default") },
690};
691
692static void TestFileConfRead()
693{
694 puts("*** testing wxFileConfig loading/reading ***");
695
696 wxFileConfig fileconf(_T("test"), wxEmptyString,
697 _T("testdata.fc"), wxEmptyString,
698 wxCONFIG_USE_RELATIVE_PATH);
699
700 // test simple reading
701 puts("\nReading config file:");
702 wxString defValue(_T("default")), value;
703 for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
704 {
705 const FileConfTestData& data = fcTestData[n];
706 value = fileconf.Read(data.name, defValue);
707 printf("\t%s = %s ", data.name, value.c_str());
708 if ( value == data.value )
709 {
710 puts("(ok)");
711 }
712 else
713 {
714 printf("(ERROR: should be %s)\n", data.value);
715 }
716 }
717
718 // test enumerating the entries
719 puts("\nEnumerating all root entries:");
720 long dummy;
721 wxString name;
722 bool cont = fileconf.GetFirstEntry(name, dummy);
723 while ( cont )
724 {
725 printf("\t%s = %s\n",
726 name.c_str(),
727 fileconf.Read(name.c_str(), _T("ERROR")).c_str());
728
729 cont = fileconf.GetNextEntry(name, dummy);
730 }
731}
732
733#endif // TEST_FILECONF
734
844f90fb
VZ
735// ----------------------------------------------------------------------------
736// wxFileName
737// ----------------------------------------------------------------------------
738
739#ifdef TEST_FILENAME
740
e84010cf 741#include "wx/filename.h"
844f90fb 742
8e7dda21 743static struct FileNameInfo
42b1f941 744{
8e7dda21 745 const wxChar *fullname;
a874db92 746 const wxChar *volume;
8e7dda21
VZ
747 const wxChar *path;
748 const wxChar *name;
749 const wxChar *ext;
a874db92
VZ
750 bool isAbsolute;
751 wxPathFormat format;
8e7dda21
VZ
752} filenames[] =
753{
a874db92
VZ
754 // Unix file names
755 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), TRUE, wxPATH_UNIX },
756 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), TRUE, wxPATH_UNIX },
757 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), TRUE, wxPATH_UNIX },
758 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), FALSE, wxPATH_UNIX },
759 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_UNIX },
760 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), TRUE, wxPATH_UNIX },
761 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), TRUE, wxPATH_UNIX },
762 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), FALSE, wxPATH_UNIX },
763 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), TRUE, wxPATH_UNIX },
764
765 // Windows file names
766 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_DOS },
767 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), FALSE, wxPATH_DOS },
768 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_DOS },
769 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS },
770 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), TRUE, wxPATH_DOS },
771 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS },
772
773 // Mac file names
774 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE, wxPATH_MAC },
775 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), FALSE, wxPATH_MAC },
776 { _T(":File"), _T(""), _T(""), _T("File"), _T(""), FALSE, wxPATH_MAC },
777 { _T("File"), _T(""), _T(""), _T("File"), _T(""), FALSE, wxPATH_MAC },
778
779 // VMS file names
780 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), TRUE, wxPATH_VMS },
781 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), FALSE, wxPATH_VMS },
42b1f941
VZ
782};
783
844f90fb
VZ
784static void TestFileNameConstruction()
785{
786 puts("*** testing wxFileName construction ***");
787
844f90fb
VZ
788 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
789 {
a874db92
VZ
790 const FileNameInfo& fni = filenames[n];
791
792 wxFileName fn(fni.fullname, fni.format);
793
794 wxString fullname = fn.GetFullPath(fni.format);
795 if ( fullname != fni.fullname )
796 {
797 printf("ERROR: fullname should be '%s'\n", fni.fullname);
798 }
844f90fb 799
a874db92
VZ
800 bool isAbsolute = fn.IsAbsolute(fni.format);
801 printf("'%s' is %s (%s)\n\t",
802 fullname.c_str(),
803 isAbsolute ? "absolute" : "relative",
804 isAbsolute == fni.isAbsolute ? "ok" : "ERROR");
805
806 if ( !fn.Normalize(wxPATH_NORM_ALL, _T(""), fni.format) )
844f90fb
VZ
807 {
808 puts("ERROR (couldn't be normalized)");
809 }
810 else
811 {
a874db92 812 printf("normalized: '%s'\n", fn.GetFullPath(fni.format).c_str());
844f90fb
VZ
813 }
814 }
815
816 puts("");
817}
818
42b1f941
VZ
819static void TestFileNameSplit()
820{
821 puts("*** testing wxFileName splitting ***");
822
823 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
824 {
a874db92
VZ
825 const FileNameInfo& fni = filenames[n];
826 wxString volume, path, name, ext;
827 wxFileName::SplitPath(fni.fullname,
828 &volume, &path, &name, &ext, fni.format);
829
830 printf("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'",
831 fni.fullname,
832 volume.c_str(), path.c_str(), name.c_str(), ext.c_str());
8e7dda21 833
a874db92
VZ
834 if ( volume != fni.volume )
835 printf(" (ERROR: volume = '%s')", fni.volume);
8e7dda21
VZ
836 if ( path != fni.path )
837 printf(" (ERROR: path = '%s')", fni.path);
838 if ( name != fni.name )
839 printf(" (ERROR: name = '%s')", fni.name);
840 if ( ext != fni.ext )
841 printf(" (ERROR: ext = '%s')", fni.ext);
a874db92 842
8e7dda21 843 puts("");
42b1f941 844 }
42b1f941
VZ
845}
846
844f90fb
VZ
847static void TestFileNameComparison()
848{
849 // TODO!
850}
851
852static void TestFileNameOperations()
853{
854 // TODO!
855}
856
857static void TestFileNameCwd()
858{
859 // TODO!
860}
861
862#endif // TEST_FILENAME
863
d56e2b97
VZ
864// ----------------------------------------------------------------------------
865// wxFileName time functions
866// ----------------------------------------------------------------------------
867
868#ifdef TEST_FILETIME
869
870#include <wx/filename.h>
871#include <wx/datetime.h>
872
873static void TestFileGetTimes()
874{
875 wxFileName fn(_T("testdata.fc"));
876
877 wxDateTime dtAccess, dtMod, dtChange;
878 if ( !fn.GetTimes(&dtAccess, &dtMod, &dtChange) )
879 {
880 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
881 }
882 else
883 {
884 static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S");
885
886 wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str());
887 wxPrintf(_T("Access: \t%s\n"), dtAccess.Format(fmt).c_str());
888 wxPrintf(_T("Mod/creation:\t%s\n"), dtMod.Format(fmt).c_str());
889 wxPrintf(_T("Change: \t%s\n"), dtChange.Format(fmt).c_str());
890 }
891}
892
893static void TestFileSetTimes()
894{
895 wxFileName fn(_T("testdata.fc"));
896
897 wxDateTime dtAccess, dtMod, dtChange;
898 if ( !fn.Touch() )
899 {
900 wxPrintf(_T("ERROR: Touch() failed.\n"));
901 }
902}
903
904#endif // TEST_FILETIME
905
2c8e4738
VZ
906// ----------------------------------------------------------------------------
907// wxHashTable
908// ----------------------------------------------------------------------------
909
910#ifdef TEST_HASH
911
e84010cf 912#include "wx/hash.h"
2c8e4738
VZ
913
914struct Foo
915{
916 Foo(int n_) { n = n_; count++; }
917 ~Foo() { count--; }
918
919 int n;
920
921 static size_t count;
922};
923
924size_t Foo::count = 0;
925
926WX_DECLARE_LIST(Foo, wxListFoos);
927WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos);
928
e84010cf 929#include "wx/listimpl.cpp"
2c8e4738
VZ
930
931WX_DEFINE_LIST(wxListFoos);
932
933static void TestHash()
934{
935 puts("*** Testing wxHashTable ***\n");
936
937 {
938 wxHashFoos hash;
939 hash.DeleteContents(TRUE);
940
941 printf("Hash created: %u foos in hash, %u foos totally\n",
942 hash.GetCount(), Foo::count);
943
944 static const int hashTestData[] =
945 {
946 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
947 };
948
949 size_t n;
950 for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
951 {
952 hash.Put(hashTestData[n], n, new Foo(n));
953 }
954
955 printf("Hash filled: %u foos in hash, %u foos totally\n",
956 hash.GetCount(), Foo::count);
957
958 puts("Hash access test:");
959 for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
960 {
961 printf("\tGetting element with key %d, value %d: ",
962 hashTestData[n], n);
963 Foo *foo = hash.Get(hashTestData[n], n);
964 if ( !foo )
965 {
966 printf("ERROR, not found.\n");
967 }
968 else
969 {
970 printf("%d (%s)\n", foo->n,
971 (size_t)foo->n == n ? "ok" : "ERROR");
972 }
973 }
974
975 printf("\nTrying to get an element not in hash: ");
976
977 if ( hash.Get(1234) || hash.Get(1, 0) )
978 {
979 puts("ERROR: found!");
980 }
981 else
982 {
983 puts("ok (not found)");
984 }
985 }
986
987 printf("Hash destroyed: %u foos left\n", Foo::count);
988}
989
990#endif // TEST_HASH
991
f6bcfd97
BP
992// ----------------------------------------------------------------------------
993// wxList
994// ----------------------------------------------------------------------------
995
996#ifdef TEST_LIST
997
e84010cf 998#include "wx/list.h"
f6bcfd97
BP
999
1000WX_DECLARE_LIST(Bar, wxListBars);
e84010cf 1001#include "wx/listimpl.cpp"
f6bcfd97
BP
1002WX_DEFINE_LIST(wxListBars);
1003
1004static void TestListCtor()
1005{
1006 puts("*** Testing wxList construction ***\n");
1007
1008 {
1009 wxListBars list1;
1010 list1.Append(new Bar(_T("first")));
1011 list1.Append(new Bar(_T("second")));
1012
1013 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
1014 list1.GetCount(), Bar::GetNumber());
1015
1016 wxListBars list2;
1017 list2 = list1;
1018
1019 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
1020 list1.GetCount(), list2.GetCount(), Bar::GetNumber());
1021
1022 list1.DeleteContents(TRUE);
1023 }
1024
1025 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
1026}
1027
1028#endif // TEST_LIST
1029
ec37df57
VZ
1030// ----------------------------------------------------------------------------
1031// wxLocale
1032// ----------------------------------------------------------------------------
1033
1034#ifdef TEST_LOCALE
1035
1036#include "wx/intl.h"
1037#include "wx/utils.h" // for wxSetEnv
1038
1039static wxLocale gs_localeDefault(wxLANGUAGE_ENGLISH);
1040
1041// find the name of the language from its value
1042static const char *GetLangName(int lang)
1043{
1044 static const char *languageNames[] =
1045 {
1046 "DEFAULT",
1047 "UNKNOWN",
1048 "ABKHAZIAN",
1049 "AFAR",
1050 "AFRIKAANS",
1051 "ALBANIAN",
1052 "AMHARIC",
1053 "ARABIC",
1054 "ARABIC_ALGERIA",
1055 "ARABIC_BAHRAIN",
1056 "ARABIC_EGYPT",
1057 "ARABIC_IRAQ",
1058 "ARABIC_JORDAN",
1059 "ARABIC_KUWAIT",
1060 "ARABIC_LEBANON",
1061 "ARABIC_LIBYA",
1062 "ARABIC_MOROCCO",
1063 "ARABIC_OMAN",
1064 "ARABIC_QATAR",
1065 "ARABIC_SAUDI_ARABIA",
1066 "ARABIC_SUDAN",
1067 "ARABIC_SYRIA",
1068 "ARABIC_TUNISIA",
1069 "ARABIC_UAE",
1070 "ARABIC_YEMEN",
1071 "ARMENIAN",
1072 "ASSAMESE",
1073 "AYMARA",
1074 "AZERI",
1075 "AZERI_CYRILLIC",
1076 "AZERI_LATIN",
1077 "BASHKIR",
1078 "BASQUE",
1079 "BELARUSIAN",
1080 "BENGALI",
1081 "BHUTANI",
1082 "BIHARI",
1083 "BISLAMA",
1084 "BRETON",
1085 "BULGARIAN",
1086 "BURMESE",
1087 "CAMBODIAN",
1088 "CATALAN",
1089 "CHINESE",
1090 "CHINESE_SIMPLIFIED",
1091 "CHINESE_TRADITIONAL",
1092 "CHINESE_HONGKONG",
1093 "CHINESE_MACAU",
1094 "CHINESE_SINGAPORE",
1095 "CHINESE_TAIWAN",
1096 "CORSICAN",
1097 "CROATIAN",
1098 "CZECH",
1099 "DANISH",
1100 "DUTCH",
1101 "DUTCH_BELGIAN",
1102 "ENGLISH",
1103 "ENGLISH_UK",
1104 "ENGLISH_US",
1105 "ENGLISH_AUSTRALIA",
1106 "ENGLISH_BELIZE",
1107 "ENGLISH_BOTSWANA",
1108 "ENGLISH_CANADA",
1109 "ENGLISH_CARIBBEAN",
1110 "ENGLISH_DENMARK",
1111 "ENGLISH_EIRE",
1112 "ENGLISH_JAMAICA",
1113 "ENGLISH_NEW_ZEALAND",
1114 "ENGLISH_PHILIPPINES",
1115 "ENGLISH_SOUTH_AFRICA",
1116 "ENGLISH_TRINIDAD",
1117 "ENGLISH_ZIMBABWE",
1118 "ESPERANTO",
1119 "ESTONIAN",
1120 "FAEROESE",
1121 "FARSI",
1122 "FIJI",
1123 "FINNISH",
1124 "FRENCH",
1125 "FRENCH_BELGIAN",
1126 "FRENCH_CANADIAN",
1127 "FRENCH_LUXEMBOURG",
1128 "FRENCH_MONACO",
1129 "FRENCH_SWISS",
1130 "FRISIAN",
1131 "GALICIAN",
1132 "GEORGIAN",
1133 "GERMAN",
1134 "GERMAN_AUSTRIAN",
1135 "GERMAN_BELGIUM",
1136 "GERMAN_LIECHTENSTEIN",
1137 "GERMAN_LUXEMBOURG",
1138 "GERMAN_SWISS",
1139 "GREEK",
1140 "GREENLANDIC",
1141 "GUARANI",
1142 "GUJARATI",
1143 "HAUSA",
1144 "HEBREW",
1145 "HINDI",
1146 "HUNGARIAN",
1147 "ICELANDIC",
1148 "INDONESIAN",
1149 "INTERLINGUA",
1150 "INTERLINGUE",
1151 "INUKTITUT",
1152 "INUPIAK",
1153 "IRISH",
1154 "ITALIAN",
1155 "ITALIAN_SWISS",
1156 "JAPANESE",
1157 "JAVANESE",
1158 "KANNADA",
1159 "KASHMIRI",
1160 "KASHMIRI_INDIA",
1161 "KAZAKH",
1162 "KERNEWEK",
1163 "KINYARWANDA",
1164 "KIRGHIZ",
1165 "KIRUNDI",
1166 "KONKANI",
1167 "KOREAN",
1168 "KURDISH",
1169 "LAOTHIAN",
1170 "LATIN",
1171 "LATVIAN",
1172 "LINGALA",
1173 "LITHUANIAN",
1174 "MACEDONIAN",
1175 "MALAGASY",
1176 "MALAY",
1177 "MALAYALAM",
1178 "MALAY_BRUNEI_DARUSSALAM",
1179 "MALAY_MALAYSIA",
1180 "MALTESE",
1181 "MANIPURI",
1182 "MAORI",
1183 "MARATHI",
1184 "MOLDAVIAN",
1185 "MONGOLIAN",
1186 "NAURU",
1187 "NEPALI",
1188 "NEPALI_INDIA",
1189 "NORWEGIAN_BOKMAL",
1190 "NORWEGIAN_NYNORSK",
1191 "OCCITAN",
1192 "ORIYA",
1193 "OROMO",
1194 "PASHTO",
1195 "POLISH",
1196 "PORTUGUESE",
1197 "PORTUGUESE_BRAZILIAN",
1198 "PUNJABI",
1199 "QUECHUA",
1200 "RHAETO_ROMANCE",
1201 "ROMANIAN",
1202 "RUSSIAN",
1203 "RUSSIAN_UKRAINE",
1204 "SAMOAN",
1205 "SANGHO",
1206 "SANSKRIT",
1207 "SCOTS_GAELIC",
1208 "SERBIAN",
1209 "SERBIAN_CYRILLIC",
1210 "SERBIAN_LATIN",
1211 "SERBO_CROATIAN",
1212 "SESOTHO",
1213 "SETSWANA",
1214 "SHONA",
1215 "SINDHI",
1216 "SINHALESE",
1217 "SISWATI",
1218 "SLOVAK",
1219 "SLOVENIAN",
1220 "SOMALI",
1221 "SPANISH",
1222 "SPANISH_ARGENTINA",
1223 "SPANISH_BOLIVIA",
1224 "SPANISH_CHILE",
1225 "SPANISH_COLOMBIA",
1226 "SPANISH_COSTA_RICA",
1227 "SPANISH_DOMINICAN_REPUBLIC",
1228 "SPANISH_ECUADOR",
1229 "SPANISH_EL_SALVADOR",
1230 "SPANISH_GUATEMALA",
1231 "SPANISH_HONDURAS",
1232 "SPANISH_MEXICAN",
1233 "SPANISH_MODERN",
1234 "SPANISH_NICARAGUA",
1235 "SPANISH_PANAMA",
1236 "SPANISH_PARAGUAY",
1237 "SPANISH_PERU",
1238 "SPANISH_PUERTO_RICO",
1239 "SPANISH_URUGUAY",
1240 "SPANISH_US",
1241 "SPANISH_VENEZUELA",
1242 "SUNDANESE",
1243 "SWAHILI",
1244 "SWEDISH",
1245 "SWEDISH_FINLAND",
1246 "TAGALOG",
1247 "TAJIK",
1248 "TAMIL",
1249 "TATAR",
1250 "TELUGU",
1251 "THAI",
1252 "TIBETAN",
1253 "TIGRINYA",
1254 "TONGA",
1255 "TSONGA",
1256 "TURKISH",
1257 "TURKMEN",
1258 "TWI",
1259 "UIGHUR",
1260 "UKRAINIAN",
1261 "URDU",
1262 "URDU_INDIA",
1263 "URDU_PAKISTAN",
1264 "UZBEK",
1265 "UZBEK_CYRILLIC",
1266 "UZBEK_LATIN",
1267 "VIETNAMESE",
1268 "VOLAPUK",
1269 "WELSH",
1270 "WOLOF",
1271 "XHOSA",
1272 "YIDDISH",
1273 "YORUBA",
1274 "ZHUANG",
1275 "ZULU",
1276 };
1277
1278 if ( (size_t)lang < WXSIZEOF(languageNames) )
1279 return languageNames[lang];
1280 else
1281 return "INVALID";
1282}
1283
1284static void TestDefaultLang()
1285{
1286 puts("*** Testing wxLocale::GetSystemLanguage ***");
1287
1288 static const wxChar *langStrings[] =
1289 {
1290 NULL, // system default
1291 _T("C"),
1292 _T("fr"),
1293 _T("fr_FR"),
1294 _T("en"),
1295 _T("en_GB"),
1296 _T("en_US"),
1297 _T("de_DE.iso88591"),
1298 _T("german"),
1299 _T("?"), // invalid lang spec
1300 _T("klingonese"), // I bet on some systems it does exist...
1301 };
1302
dccce9ea
VZ
1303 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1304 wxLocale::GetSystemEncodingName().c_str(),
1305 wxLocale::GetSystemEncoding());
1306
ec37df57
VZ
1307 for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
1308 {
1309 const char *langStr = langStrings[n];
1310 if ( langStr )
dccce9ea
VZ
1311 {
1312 // FIXME: this doesn't do anything at all under Windows, we need
1313 // to create a new wxLocale!
ec37df57 1314 wxSetEnv(_T("LC_ALL"), langStr);
dccce9ea 1315 }
ec37df57
VZ
1316
1317 int lang = gs_localeDefault.GetSystemLanguage();
1318 printf("Locale for '%s' is %s.\n",
1319 langStr ? langStr : "system default", GetLangName(lang));
1320 }
1321}
1322
1323#endif // TEST_LOCALE
1324
696e1ea0
VZ
1325// ----------------------------------------------------------------------------
1326// MIME types
1327// ----------------------------------------------------------------------------
1328
1329#ifdef TEST_MIME
1330
e84010cf 1331#include "wx/mimetype.h"
696e1ea0
VZ
1332
1333static void TestMimeEnum()
1334{
a6c65e88
VZ
1335 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1336
696e1ea0
VZ
1337 wxArrayString mimetypes;
1338
39189b9d 1339 size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
696e1ea0
VZ
1340
1341 printf("*** All %u known filetypes: ***\n", count);
1342
1343 wxArrayString exts;
1344 wxString desc;
1345
1346 for ( size_t n = 0; n < count; n++ )
1347 {
39189b9d
VZ
1348 wxFileType *filetype =
1349 wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
696e1ea0 1350 if ( !filetype )
c61f4f6d 1351 {
97e0ceea
VZ
1352 printf("nothing known about the filetype '%s'!\n",
1353 mimetypes[n].c_str());
696e1ea0 1354 continue;
c61f4f6d
VZ
1355 }
1356
696e1ea0
VZ
1357 filetype->GetDescription(&desc);
1358 filetype->GetExtensions(exts);
1359
299fcbfe
VZ
1360 filetype->GetIcon(NULL);
1361
696e1ea0
VZ
1362 wxString extsAll;
1363 for ( size_t e = 0; e < exts.GetCount(); e++ )
1364 {
1365 if ( e > 0 )
1366 extsAll << _T(", ");
1367 extsAll += exts[e];
1368 }
1369
54acce90
VZ
1370 printf("\t%s: %s (%s)\n",
1371 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
696e1ea0 1372 }
39189b9d
VZ
1373
1374 puts("");
696e1ea0
VZ
1375}
1376
f6bcfd97
BP
1377static void TestMimeOverride()
1378{
1379 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1380
39189b9d
VZ
1381 static const wxChar *mailcap = _T("/tmp/mailcap");
1382 static const wxChar *mimetypes = _T("/tmp/mime.types");
1383
1384 if ( wxFile::Exists(mailcap) )
1385 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1386 mailcap,
1387 wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR"));
1388 else
1389 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1390 mailcap);
f6bcfd97 1391
39189b9d
VZ
1392 if ( wxFile::Exists(mimetypes) )
1393 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1394 mimetypes,
1395 wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR"));
1396 else
1397 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1398 mimetypes);
1399
1400 puts("");
f6bcfd97
BP
1401}
1402
1403static void TestMimeFilename()
1404{
1405 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1406
1407 static const wxChar *filenames[] =
1408 {
1409 _T("readme.txt"),
1410 _T("document.pdf"),
1411 _T("image.gif"),
1412 };
1413
1414 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
1415 {
1416 const wxString fname = filenames[n];
1417 wxString ext = fname.AfterLast(_T('.'));
39189b9d 1418 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
f6bcfd97
BP
1419 if ( !ft )
1420 {
1421 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str());
1422 }
1423 else
1424 {
1425 wxString desc;
1426 if ( !ft->GetDescription(&desc) )
1427 desc = _T("<no description>");
1428
1429 wxString cmd;
1430 if ( !ft->GetOpenCommand(&cmd,
1431 wxFileType::MessageParameters(fname, _T(""))) )
1432 cmd = _T("<no command available>");
1433
1434 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
1435 fname.c_str(), desc.c_str(), cmd.c_str());
1436
1437 delete ft;
1438 }
1439 }
39189b9d
VZ
1440
1441 puts("");
f6bcfd97
BP
1442}
1443
c7ce8392
VZ
1444static void TestMimeAssociate()
1445{
1446 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1447
a6c65e88
VZ
1448 wxFileTypeInfo ftInfo(
1449 _T("application/x-xyz"),
1450 _T("xyzview '%s'"), // open cmd
1451 _T(""), // print cmd
1452 _T("XYZ File") // description
1453 _T(".xyz"), // extensions
1454 NULL // end of extensions
1455 );
1456 ftInfo.SetShortDesc(_T("XYZFile")); // used under Win32 only
1457
39189b9d 1458 wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
c7ce8392
VZ
1459 if ( !ft )
1460 {
1461 wxPuts(_T("ERROR: failed to create association!"));
1462 }
1463 else
1464 {
a6c65e88 1465 // TODO: read it back
c7ce8392
VZ
1466 delete ft;
1467 }
39189b9d
VZ
1468
1469 puts("");
c7ce8392
VZ
1470}
1471
696e1ea0
VZ
1472#endif // TEST_MIME
1473
89e60357
VZ
1474// ----------------------------------------------------------------------------
1475// misc information functions
1476// ----------------------------------------------------------------------------
1477
1478#ifdef TEST_INFO_FUNCTIONS
1479
e84010cf 1480#include "wx/utils.h"
89e60357 1481
3a994742
VZ
1482static void TestDiskInfo()
1483{
eadd7bd2 1484 puts("*** Testing wxGetDiskSpace() ***");
3a994742
VZ
1485
1486 for ( ;; )
1487 {
1488 char pathname[128];
1489 printf("\nEnter a directory name: ");
1490 if ( !fgets(pathname, WXSIZEOF(pathname), stdin) )
1491 break;
1492
1493 // kill the last '\n'
1494 pathname[strlen(pathname) - 1] = 0;
1495
1496 wxLongLong total, free;
1497 if ( !wxGetDiskSpace(pathname, &total, &free) )
1498 {
1499 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1500 }
1501 else
1502 {
eadd7bd2
VZ
1503 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1504 (total / 1024).ToString().c_str(),
1505 (free / 1024).ToString().c_str(),
3a994742
VZ
1506 pathname);
1507 }
1508 }
1509}
1510
89e60357
VZ
1511static void TestOsInfo()
1512{
1513 puts("*** Testing OS info functions ***\n");
1514
1515 int major, minor;
1516 wxGetOsVersion(&major, &minor);
1517 printf("Running under: %s, version %d.%d\n",
1518 wxGetOsDescription().c_str(), major, minor);
1519
bd3277fe 1520 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
89e60357
VZ
1521
1522 printf("Host name is %s (%s).\n",
1523 wxGetHostName().c_str(), wxGetFullHostName().c_str());
bd3277fe
VZ
1524
1525 puts("");
89e60357
VZ
1526}
1527
1528static void TestUserInfo()
1529{
1530 puts("*** Testing user info functions ***\n");
1531
1532 printf("User id is:\t%s\n", wxGetUserId().c_str());
1533 printf("User name is:\t%s\n", wxGetUserName().c_str());
1534 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
1535 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
bd3277fe
VZ
1536
1537 puts("");
89e60357
VZ
1538}
1539
1540#endif // TEST_INFO_FUNCTIONS
1541
b76b015e
VZ
1542// ----------------------------------------------------------------------------
1543// long long
1544// ----------------------------------------------------------------------------
1545
1546#ifdef TEST_LONGLONG
1547
e84010cf
GD
1548#include "wx/longlong.h"
1549#include "wx/timer.h"
b76b015e 1550
2a310492
VZ
1551// make a 64 bit number from 4 16 bit ones
1552#define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
1553
1554// get a random 64 bit number
1555#define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
1556
3a994742
VZ
1557static const long testLongs[] =
1558{
1559 0,
1560 1,
1561 -1,
1562 LONG_MAX,
1563 LONG_MIN,
1564 0x1234,
1565 -0x1234
1566};
1567
7d0bb74d 1568#if wxUSE_LONGLONG_WX
2a310492
VZ
1569inline bool operator==(const wxLongLongWx& a, const wxLongLongNative& b)
1570 { return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); }
1571inline bool operator==(const wxLongLongNative& a, const wxLongLongWx& b)
1572 { return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); }
7d0bb74d 1573#endif // wxUSE_LONGLONG_WX
2a310492 1574
b76b015e
VZ
1575static void TestSpeed()
1576{
1577 static const long max = 100000000;
1578 long n;
9fc3ad34 1579
b76b015e
VZ
1580 {
1581 wxStopWatch sw;
1582
1583 long l = 0;
1584 for ( n = 0; n < max; n++ )
1585 {
1586 l += n;
1587 }
1588
1589 printf("Summing longs took %ld milliseconds.\n", sw.Time());
1590 }
1591
2ea24d9f 1592#if wxUSE_LONGLONG_NATIVE
b76b015e
VZ
1593 {
1594 wxStopWatch sw;
1595
2ea24d9f 1596 wxLongLong_t l = 0;
b76b015e
VZ
1597 for ( n = 0; n < max; n++ )
1598 {
1599 l += n;
1600 }
1601
2ea24d9f 1602 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw.Time());
b76b015e 1603 }
2ea24d9f 1604#endif // wxUSE_LONGLONG_NATIVE
b76b015e
VZ
1605
1606 {
1607 wxStopWatch sw;
1608
1609 wxLongLong l;
1610 for ( n = 0; n < max; n++ )
1611 {
1612 l += n;
1613 }
1614
1615 printf("Summing wxLongLongs took %ld milliseconds.\n", sw.Time());
1616 }
1617}
1618
2a310492 1619static void TestLongLongConversion()
b76b015e 1620{
2a310492
VZ
1621 puts("*** Testing wxLongLong conversions ***\n");
1622
1623 wxLongLong a;
1624 size_t nTested = 0;
1625 for ( size_t n = 0; n < 100000; n++ )
1626 {
1627 a = RAND_LL();
1628
1629#if wxUSE_LONGLONG_NATIVE
1630 wxLongLongNative b(a.GetHi(), a.GetLo());
5e6a0e83 1631
2a310492
VZ
1632 wxASSERT_MSG( a == b, "conversions failure" );
1633#else
1634 puts("Can't do it without native long long type, test skipped.");
b76b015e 1635
2a310492
VZ
1636 return;
1637#endif // wxUSE_LONGLONG_NATIVE
1638
1639 if ( !(nTested % 1000) )
1640 {
1641 putchar('.');
1642 fflush(stdout);
1643 }
1644
1645 nTested++;
1646 }
1647
1648 puts(" done!");
1649}
1650
1651static void TestMultiplication()
1652{
1653 puts("*** Testing wxLongLong multiplication ***\n");
1654
1655 wxLongLong a, b;
1656 size_t nTested = 0;
1657 for ( size_t n = 0; n < 100000; n++ )
1658 {
1659 a = RAND_LL();
1660 b = RAND_LL();
1661
1662#if wxUSE_LONGLONG_NATIVE
1663 wxLongLongNative aa(a.GetHi(), a.GetLo());
1664 wxLongLongNative bb(b.GetHi(), b.GetLo());
1665
1666 wxASSERT_MSG( a*b == aa*bb, "multiplication failure" );
1667#else // !wxUSE_LONGLONG_NATIVE
1668 puts("Can't do it without native long long type, test skipped.");
1669
1670 return;
1671#endif // wxUSE_LONGLONG_NATIVE
1672
1673 if ( !(nTested % 1000) )
1674 {
1675 putchar('.');
1676 fflush(stdout);
1677 }
1678
1679 nTested++;
1680 }
1681
1682 puts(" done!");
1683}
1684
1685static void TestDivision()
1686{
1687 puts("*** Testing wxLongLong division ***\n");
2f02cb89 1688
2ea24d9f 1689 wxLongLong q, r;
2f02cb89 1690 size_t nTested = 0;
5e6a0e83 1691 for ( size_t n = 0; n < 100000; n++ )
2f02cb89
VZ
1692 {
1693 // get a random wxLongLong (shifting by 12 the MSB ensures that the
1694 // multiplication will not overflow)
1695 wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
1696
2ea24d9f
VZ
1697 // get a random long (not wxLongLong for now) to divide it with
1698 long l = rand();
1699 q = ll / l;
1700 r = ll % l;
1701
2a310492
VZ
1702#if wxUSE_LONGLONG_NATIVE
1703 wxLongLongNative m(ll.GetHi(), ll.GetLo());
1704
1705 wxLongLongNative p = m / l, s = m % l;
1706 wxASSERT_MSG( q == p && r == s, "division failure" );
1707#else // !wxUSE_LONGLONG_NATIVE
5e6a0e83 1708 // verify the result
2ea24d9f 1709 wxASSERT_MSG( ll == q*l + r, "division failure" );
2a310492 1710#endif // wxUSE_LONGLONG_NATIVE
2f02cb89 1711
5e6a0e83
VZ
1712 if ( !(nTested % 1000) )
1713 {
1714 putchar('.');
1715 fflush(stdout);
1716 }
1717
2f02cb89
VZ
1718 nTested++;
1719 }
1720
5e6a0e83 1721 puts(" done!");
2a310492 1722}
2f02cb89 1723
2a310492
VZ
1724static void TestAddition()
1725{
1726 puts("*** Testing wxLongLong addition ***\n");
1727
1728 wxLongLong a, b, c;
1729 size_t nTested = 0;
1730 for ( size_t n = 0; n < 100000; n++ )
1731 {
1732 a = RAND_LL();
1733 b = RAND_LL();
1734 c = a + b;
1735
1736#if wxUSE_LONGLONG_NATIVE
1737 wxASSERT_MSG( c == wxLongLongNative(a.GetHi(), a.GetLo()) +
1738 wxLongLongNative(b.GetHi(), b.GetLo()),
7c968cee 1739 "addition failure" );
2a310492
VZ
1740#else // !wxUSE_LONGLONG_NATIVE
1741 wxASSERT_MSG( c - b == a, "addition failure" );
1742#endif // wxUSE_LONGLONG_NATIVE
1743
1744 if ( !(nTested % 1000) )
1745 {
1746 putchar('.');
1747 fflush(stdout);
1748 }
1749
1750 nTested++;
1751 }
1752
1753 puts(" done!");
b76b015e
VZ
1754}
1755
2a310492
VZ
1756static void TestBitOperations()
1757{
1758 puts("*** Testing wxLongLong bit operation ***\n");
1759
f6bcfd97 1760 wxLongLong ll;
2a310492
VZ
1761 size_t nTested = 0;
1762 for ( size_t n = 0; n < 100000; n++ )
1763 {
f6bcfd97 1764 ll = RAND_LL();
2a310492
VZ
1765
1766#if wxUSE_LONGLONG_NATIVE
1767 for ( size_t n = 0; n < 33; n++ )
1768 {
2a310492 1769 }
2a310492
VZ
1770#else // !wxUSE_LONGLONG_NATIVE
1771 puts("Can't do it without native long long type, test skipped.");
1772
1773 return;
1774#endif // wxUSE_LONGLONG_NATIVE
1775
1776 if ( !(nTested % 1000) )
1777 {
1778 putchar('.');
1779 fflush(stdout);
1780 }
1781
1782 nTested++;
1783 }
1784
1785 puts(" done!");
1786}
1787
f6bcfd97
BP
1788static void TestLongLongComparison()
1789{
2d3112ad 1790#if wxUSE_LONGLONG_WX
f6bcfd97
BP
1791 puts("*** Testing wxLongLong comparison ***\n");
1792
f6bcfd97
BP
1793 static const long ls[2] =
1794 {
1795 0x1234,
1796 -0x1234,
1797 };
1798
1799 wxLongLongWx lls[2];
1800 lls[0] = ls[0];
3a994742 1801 lls[1] = ls[1];
f6bcfd97
BP
1802
1803 for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ )
1804 {
1805 bool res;
1806
1807 for ( size_t m = 0; m < WXSIZEOF(lls); m++ )
1808 {
1809 res = lls[m] > testLongs[n];
1810 printf("0x%lx > 0x%lx is %s (%s)\n",
1811 ls[m], testLongs[n], res ? "true" : "false",
1812 res == (ls[m] > testLongs[n]) ? "ok" : "ERROR");
1813
1814 res = lls[m] < testLongs[n];
1815 printf("0x%lx < 0x%lx is %s (%s)\n",
1816 ls[m], testLongs[n], res ? "true" : "false",
1817 res == (ls[m] < testLongs[n]) ? "ok" : "ERROR");
1818
1819 res = lls[m] == testLongs[n];
1820 printf("0x%lx == 0x%lx is %s (%s)\n",
1821 ls[m], testLongs[n], res ? "true" : "false",
1822 res == (ls[m] == testLongs[n]) ? "ok" : "ERROR");
1823 }
1824 }
2d3112ad 1825#endif // wxUSE_LONGLONG_WX
f6bcfd97
BP
1826}
1827
3a994742
VZ
1828static void TestLongLongPrint()
1829{
1830 wxPuts(_T("*** Testing wxLongLong printing ***\n"));
1831
1832 for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ )
1833 {
1834 wxLongLong ll = testLongs[n];
1835 wxPrintf(_T("%ld == %s\n"), testLongs[n], ll.ToString().c_str());
1836 }
1837
1838 wxLongLong ll(0x12345678, 0x87654321);
1839 wxPrintf(_T("0x1234567887654321 = %s\n"), ll.ToString().c_str());
1840
1841 ll.Negate();
1842 wxPrintf(_T("-0x1234567887654321 = %s\n"), ll.ToString().c_str());
1843}
1844
2a310492
VZ
1845#undef MAKE_LL
1846#undef RAND_LL
1847
b76b015e
VZ
1848#endif // TEST_LONGLONG
1849
39189b9d
VZ
1850// ----------------------------------------------------------------------------
1851// path list
1852// ----------------------------------------------------------------------------
1853
1854#ifdef TEST_PATHLIST
1855
1856static void TestPathList()
1857{
1858 puts("*** Testing wxPathList ***\n");
1859
1860 wxPathList pathlist;
1861 pathlist.AddEnvList("PATH");
1862 wxString path = pathlist.FindValidPath("ls");
1863 if ( path.empty() )
1864 {
1865 printf("ERROR: command not found in the path.\n");
1866 }
1867 else
1868 {
1869 printf("Command found in the path as '%s'.\n", path.c_str());
1870 }
1871}
1872
1873#endif // TEST_PATHLIST
1874
07a56e45
VZ
1875// ----------------------------------------------------------------------------
1876// regular expressions
1877// ----------------------------------------------------------------------------
1878
1879#ifdef TEST_REGEX
1880
e84010cf 1881#include "wx/regex.h"
07a56e45
VZ
1882
1883static void TestRegExCompile()
1884{
1885 wxPuts(_T("*** Testing RE compilation ***\n"));
1886
1887 static struct RegExCompTestData
1888 {
1889 const wxChar *pattern;
1890 bool correct;
1891 } regExCompTestData[] =
1892 {
1893 { _T("foo"), TRUE },
1894 { _T("foo("), FALSE },
1895 { _T("foo(bar"), FALSE },
1896 { _T("foo(bar)"), TRUE },
1897 { _T("foo["), FALSE },
1898 { _T("foo[bar"), FALSE },
1899 { _T("foo[bar]"), TRUE },
1900 { _T("foo{"), TRUE },
1901 { _T("foo{1"), FALSE },
1902 { _T("foo{bar"), TRUE },
1903 { _T("foo{1}"), TRUE },
1904 { _T("foo{1,2}"), TRUE },
1905 { _T("foo{bar}"), TRUE },
1906 { _T("foo*"), TRUE },
1907 { _T("foo**"), FALSE },
1908 { _T("foo+"), TRUE },
1909 { _T("foo++"), FALSE },
1910 { _T("foo?"), TRUE },
1911 { _T("foo??"), FALSE },
1912 { _T("foo?+"), FALSE },
1913 };
1914
1915 wxRegEx re;
1916 for ( size_t n = 0; n < WXSIZEOF(regExCompTestData); n++ )
1917 {
1918 const RegExCompTestData& data = regExCompTestData[n];
1919 bool ok = re.Compile(data.pattern);
1920
1921 wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
1922 data.pattern,
1923 ok ? _T("") : _T("not "),
1924 ok == data.correct ? _T("ok") : _T("ERROR"));
1925 }
1926}
1927
1928static void TestRegExMatch()
1929{
1930 wxPuts(_T("*** Testing RE matching ***\n"));
1931
1932 static struct RegExMatchTestData
1933 {
1934 const wxChar *pattern;
1935 const wxChar *text;
1936 bool correct;
1937 } regExMatchTestData[] =
1938 {
1939 { _T("foo"), _T("bar"), FALSE },
1940 { _T("foo"), _T("foobar"), TRUE },
1941 { _T("^foo"), _T("foobar"), TRUE },
1942 { _T("^foo"), _T("barfoo"), FALSE },
1943 { _T("bar$"), _T("barbar"), TRUE },
1944 { _T("bar$"), _T("barbar "), FALSE },
1945 };
1946
1947 for ( size_t n = 0; n < WXSIZEOF(regExMatchTestData); n++ )
1948 {
1949 const RegExMatchTestData& data = regExMatchTestData[n];
1950
1951 wxRegEx re(data.pattern);
1952 bool ok = re.Matches(data.text);
1953
1954 wxPrintf(_T("'%s' %s %s (%s)\n"),
1955 data.pattern,
1956 ok ? _T("matches") : _T("doesn't match"),
1957 data.text,
1958 ok == data.correct ? _T("ok") : _T("ERROR"));
1959 }
1960}
1961
1962static void TestRegExSubmatch()
1963{
1964 wxPuts(_T("*** Testing RE subexpressions ***\n"));
1965
1966 wxRegEx re(_T("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).*([[:digit:]]+)$"));
1967 if ( !re.IsValid() )
1968 {
1969 wxPuts(_T("ERROR: compilation failed."));
1970 return;
1971 }
1972
1973 wxString text = _T("Fri Jul 13 18:37:52 CEST 2001");
1974
1975 if ( !re.Matches(text) )
1976 {
1977 wxPuts(_T("ERROR: match expected."));
1978 }
1979 else
1980 {
1981 wxPrintf(_T("Entire match: %s\n"), re.GetMatch(text).c_str());
1982
1983 wxPrintf(_T("Date: %s/%s/%s, wday: %s\n"),
1984 re.GetMatch(text, 3).c_str(),
1985 re.GetMatch(text, 2).c_str(),
1986 re.GetMatch(text, 4).c_str(),
1987 re.GetMatch(text, 1).c_str());
1988 }
1989}
1990
765624f7
VZ
1991static void TestRegExReplacement()
1992{
1993 wxPuts(_T("*** Testing RE replacement ***"));
1994
1995 static struct RegExReplTestData
1996 {
1997 const wxChar *text;
1998 const wxChar *repl;
1999 const wxChar *result;
2000 size_t count;
2001 } regExReplTestData[] =
2002 {
2003 { _T("foo123"), _T("bar"), _T("bar"), 1 },
2004 { _T("foo123"), _T("\\2\\1"), _T("123foo"), 1 },
2005 { _T("foo_123"), _T("\\2\\1"), _T("123foo"), 1 },
2006 { _T("123foo"), _T("bar"), _T("123foo"), 0 },
2007 { _T("123foo456foo"), _T("&&"), _T("123foo456foo456foo"), 1 },
2008 { _T("foo123foo123"), _T("bar"), _T("barbar"), 2 },
2009 { _T("foo123_foo456_foo789"), _T("bar"), _T("bar_bar_bar"), 3 },
2010 };
2011
2012 const wxChar *pattern = _T("([a-z]+)[^0-9]*([0-9]+)");
2013 wxRegEx re = pattern;
2014
2015 wxPrintf(_T("Using pattern '%s' for replacement.\n"), pattern);
2016
2017 for ( size_t n = 0; n < WXSIZEOF(regExReplTestData); n++ )
2018 {
2019 const RegExReplTestData& data = regExReplTestData[n];
2020
2021 wxString text = data.text;
2022 size_t nRepl = re.Replace(&text, data.repl);
2023
2024 wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
2025 data.text, data.repl,
2026 nRepl, nRepl == 1 ? _T("") : _T("es"),
2027 text.c_str());
2028 if ( text == data.result && nRepl == data.count )
2029 {
2030 wxPuts(_T("ok)"));
2031 }
2032 else
2033 {
2034 wxPrintf(_T("ERROR: should be %u and '%s')\n"),
2035 data.count, data.result);
2036 }
2037 }
2038}
2039
07a56e45
VZ
2040static void TestRegExInteractive()
2041{
2042 wxPuts(_T("*** Testing RE interactively ***"));
2043
2044 for ( ;; )
2045 {
2046 char pattern[128];
2047 printf("\nEnter a pattern: ");
2048 if ( !fgets(pattern, WXSIZEOF(pattern), stdin) )
2049 break;
2050
2051 // kill the last '\n'
2052 pattern[strlen(pattern) - 1] = 0;
2053
2054 wxRegEx re;
2055 if ( !re.Compile(pattern) )
2056 {
2057 continue;
2058 }
2059
2060 char text[128];
2061 for ( ;; )
2062 {
2063 printf("Enter text to match: ");
2064 if ( !fgets(text, WXSIZEOF(text), stdin) )
2065 break;
2066
2067 // kill the last '\n'
2068 text[strlen(text) - 1] = 0;
2069
2070 if ( !re.Matches(text) )
2071 {
2072 printf("No match.\n");
2073 }
2074 else
2075 {
2076 printf("Pattern matches at '%s'\n", re.GetMatch(text).c_str());
2077
2078 size_t start, len;
2079 for ( size_t n = 1; ; n++ )
2080 {
2081 if ( !re.GetMatch(&start, &len, n) )
2082 {
2083 break;
2084 }
2085
2086 printf("Subexpr %u matched '%s'\n",
2087 n, wxString(text + start, len).c_str());
2088 }
2089 }
2090 }
2091 }
2092}
2093
2094#endif // TEST_REGEX
2095
6dfec4b8 2096// ----------------------------------------------------------------------------
7ba4fbeb 2097// registry and related stuff
6dfec4b8
VZ
2098// ----------------------------------------------------------------------------
2099
2100// this is for MSW only
2101#ifndef __WXMSW__
7ba4fbeb 2102 #undef TEST_REGCONF
6dfec4b8
VZ
2103 #undef TEST_REGISTRY
2104#endif
2105
7ba4fbeb
VZ
2106#ifdef TEST_REGCONF
2107
e84010cf
GD
2108#include "wx/confbase.h"
2109#include "wx/msw/regconf.h"
7ba4fbeb
VZ
2110
2111static void TestRegConfWrite()
2112{
2113 wxRegConfig regconf(_T("console"), _T("wxwindows"));
2114 regconf.Write(_T("Hello"), wxString(_T("world")));
2115}
2116
2117#endif // TEST_REGCONF
2118
6dfec4b8
VZ
2119#ifdef TEST_REGISTRY
2120
e84010cf 2121#include "wx/msw/registry.h"
6dfec4b8
VZ
2122
2123// I chose this one because I liked its name, but it probably only exists under
2124// NT
2125static const wxChar *TESTKEY =
2126 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2127
2128static void TestRegistryRead()
2129{
2130 puts("*** testing registry reading ***");
2131
2132 wxRegKey key(TESTKEY);
2133 printf("The test key name is '%s'.\n", key.GetName().c_str());
2134 if ( !key.Open() )
2135 {
2136 puts("ERROR: test key can't be opened, aborting test.");
2137
2138 return;
2139 }
2140
2141 size_t nSubKeys, nValues;
2142 if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
2143 {
2144 printf("It has %u subkeys and %u values.\n", nSubKeys, nValues);
2145 }
2146
2147 printf("Enumerating values:\n");
2148
2149 long dummy;
2150 wxString value;
2151 bool cont = key.GetFirstValue(value, dummy);
2152 while ( cont )
2153 {
2154 printf("Value '%s': type ", value.c_str());
2155 switch ( key.GetValueType(value) )
2156 {
2157 case wxRegKey::Type_None: printf("ERROR (none)"); break;
2158 case wxRegKey::Type_String: printf("SZ"); break;
2159 case wxRegKey::Type_Expand_String: printf("EXPAND_SZ"); break;
2160 case wxRegKey::Type_Binary: printf("BINARY"); break;
2161 case wxRegKey::Type_Dword: printf("DWORD"); break;
2162 case wxRegKey::Type_Multi_String: printf("MULTI_SZ"); break;
2163 default: printf("other (unknown)"); break;
2164 }
2165
2166 printf(", value = ");
2167 if ( key.IsNumericValue(value) )
2168 {
2169 long val;
2170 key.QueryValue(value, &val);
2171 printf("%ld", val);
2172 }
2173 else // string
2174 {
2175 wxString val;
2176 key.QueryValue(value, val);
2177 printf("'%s'", val.c_str());
2178
2179 key.QueryRawValue(value, val);
2180 printf(" (raw value '%s')", val.c_str());
2181 }
2182
2183 putchar('\n');
2184
2185 cont = key.GetNextValue(value, dummy);
2186 }
2187}
2188
6ba63600
VZ
2189static void TestRegistryAssociation()
2190{
2191 /*
2192 The second call to deleteself genertaes an error message, with a
2193 messagebox saying .flo is crucial to system operation, while the .ddf
2194 call also fails, but with no error message
2195 */
2196
2197 wxRegKey key;
2198
2199 key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2200 key.Create();
2201 key = "ddxf_auto_file" ;
2202 key.SetName("HKEY_CLASSES_ROOT\\.flo" );
2203 key.Create();
2204 key = "ddxf_auto_file" ;
2205 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2206 key.Create();
2207 key = "program,0" ;
2208 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2209 key.Create();
2210 key = "program \"%1\"" ;
2211
2212 key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
2213 key.DeleteSelf();
2214 key.SetName("HKEY_CLASSES_ROOT\\.flo" );
2215 key.DeleteSelf();
2216 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
2217 key.DeleteSelf();
2218 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
2219 key.DeleteSelf();
2220}
2221
6dfec4b8
VZ
2222#endif // TEST_REGISTRY
2223
2c8e4738
VZ
2224// ----------------------------------------------------------------------------
2225// sockets
2226// ----------------------------------------------------------------------------
2227
2228#ifdef TEST_SOCKETS
2229
e84010cf
GD
2230#include "wx/socket.h"
2231#include "wx/protocol/protocol.h"
2232#include "wx/protocol/http.h"
8e907a13
VZ
2233
2234static void TestSocketServer()
2235{
2236 puts("*** Testing wxSocketServer ***\n");
2237
ccdb23df
VZ
2238 static const int PORT = 3000;
2239
8e907a13 2240 wxIPV4address addr;
ccdb23df 2241 addr.Service(PORT);
8e907a13
VZ
2242
2243 wxSocketServer *server = new wxSocketServer(addr);
2244 if ( !server->Ok() )
2245 {
2246 puts("ERROR: failed to bind");
ccdb23df
VZ
2247
2248 return;
8e907a13 2249 }
8dfea369
VZ
2250
2251 for ( ;; )
2252 {
ccdb23df 2253 printf("Server: waiting for connection on port %d...\n", PORT);
8dfea369
VZ
2254
2255 wxSocketBase *socket = server->Accept();
2256 if ( !socket )
2257 {
2258 puts("ERROR: wxSocketServer::Accept() failed.");
2259 break;
2260 }
2261
2262 puts("Server: got a client.");
2263
ccdb23df
VZ
2264 server->SetTimeout(60); // 1 min
2265
2266 while ( socket->IsConnected() )
8dfea369 2267 {
ccdb23df
VZ
2268 wxString s;
2269 char ch = '\0';
2270 for ( ;; )
8dfea369 2271 {
ccdb23df
VZ
2272 if ( socket->Read(&ch, sizeof(ch)).Error() )
2273 {
2274 // don't log error if the client just close the connection
2275 if ( socket->IsConnected() )
2276 {
2277 puts("ERROR: in wxSocket::Read.");
2278 }
8dfea369 2279
ccdb23df
VZ
2280 break;
2281 }
8dfea369 2282
ccdb23df
VZ
2283 if ( ch == '\r' )
2284 continue;
8dfea369 2285
ccdb23df
VZ
2286 if ( ch == '\n' )
2287 break;
8dfea369 2288
ccdb23df
VZ
2289 s += ch;
2290 }
8dfea369 2291
ccdb23df
VZ
2292 if ( ch != '\n' )
2293 {
2294 break;
2295 }
8dfea369 2296
ccdb23df
VZ
2297 printf("Server: got '%s'.\n", s.c_str());
2298 if ( s == _T("bye") )
2299 {
2300 delete socket;
8dfea369 2301
ccdb23df
VZ
2302 break;
2303 }
2304
2305 socket->Write(s.MakeUpper().c_str(), s.length());
2306 socket->Write("\r\n", 2);
2307 printf("Server: wrote '%s'.\n", s.c_str());
8dfea369
VZ
2308 }
2309
ccdb23df 2310 puts("Server: lost a client.");
8dfea369 2311
ccdb23df 2312 socket->Destroy();
8dfea369 2313 }
9fc3cba7 2314
ccdb23df
VZ
2315 // same as "delete server" but is consistent with GUI programs
2316 server->Destroy();
8e907a13 2317}
2c8e4738
VZ
2318
2319static void TestSocketClient()
2320{
2321 puts("*** Testing wxSocketClient ***\n");
2322
8e907a13
VZ
2323 static const char *hostname = "www.wxwindows.org";
2324
2325 wxIPV4address addr;
2326 addr.Hostname(hostname);
2327 addr.Service(80);
2328
2329 printf("--- Attempting to connect to %s:80...\n", hostname);
2c8e4738
VZ
2330
2331 wxSocketClient client;
8e907a13 2332 if ( !client.Connect(addr) )
2c8e4738 2333 {
8e907a13 2334 printf("ERROR: failed to connect to %s\n", hostname);
2c8e4738
VZ
2335 }
2336 else
2337 {
8e907a13
VZ
2338 printf("--- Connected to %s:%u...\n",
2339 addr.Hostname().c_str(), addr.Service());
2340
2c8e4738
VZ
2341 char buf[8192];
2342
8e907a13
VZ
2343 // could use simply "GET" here I suppose
2344 wxString cmdGet =
2345 wxString::Format("GET http://%s/\r\n", hostname);
2346 client.Write(cmdGet, cmdGet.length());
2347 printf("--- Sent command '%s' to the server\n",
2348 MakePrintable(cmdGet).c_str());
2c8e4738 2349 client.Read(buf, WXSIZEOF(buf));
8e907a13
VZ
2350 printf("--- Server replied:\n%s", buf);
2351 }
2352}
2353
2e907fab
VZ
2354#endif // TEST_SOCKETS
2355
b92fd37c
VZ
2356// ----------------------------------------------------------------------------
2357// FTP
2358// ----------------------------------------------------------------------------
2359
2e907fab
VZ
2360#ifdef TEST_FTP
2361
e84010cf 2362#include "wx/protocol/ftp.h"
2e907fab 2363
b92fd37c
VZ
2364static wxFTP ftp;
2365
2366#define FTP_ANONYMOUS
2367
2368#ifdef FTP_ANONYMOUS
2369 static const char *directory = "/pub";
2370 static const char *filename = "welcome.msg";
2371#else
2372 static const char *directory = "/etc";
2373 static const char *filename = "issue";
2374#endif
2375
2376static bool TestFtpConnect()
8e907a13 2377{
b92fd37c 2378 puts("*** Testing FTP connect ***");
8e907a13 2379
b92fd37c
VZ
2380#ifdef FTP_ANONYMOUS
2381 static const char *hostname = "ftp.wxwindows.org";
2382
2383 printf("--- Attempting to connect to %s:21 anonymously...\n", hostname);
2384#else // !FTP_ANONYMOUS
2385 static const char *hostname = "localhost";
2386
2387 char user[256];
2388 fgets(user, WXSIZEOF(user), stdin);
2389 user[strlen(user) - 1] = '\0'; // chop off '\n'
2390 ftp.SetUser(user);
2391
2392 char password[256];
2393 printf("Password for %s: ", password);
2394 fgets(password, WXSIZEOF(password), stdin);
2395 password[strlen(password) - 1] = '\0'; // chop off '\n'
2396 ftp.SetPassword(password);
2397
2398 printf("--- Attempting to connect to %s:21 as %s...\n", hostname, user);
2399#endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2400
2401 if ( !ftp.Connect(hostname) )
2402 {
2403 printf("ERROR: failed to connect to %s\n", hostname);
2404
2405 return FALSE;
2406 }
2407 else
2408 {
2409 printf("--- Connected to %s, current directory is '%s'\n",
2410 hostname, ftp.Pwd().c_str());
2411 }
2412
2413 return TRUE;
2414}
b1229561 2415
b92fd37c
VZ
2416// test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2417static void TestFtpWuFtpd()
2418{
2419 wxFTP ftp;
b1229561
VZ
2420 static const char *hostname = "ftp.eudora.com";
2421 if ( !ftp.Connect(hostname) )
2422 {
2423 printf("ERROR: failed to connect to %s\n", hostname);
2424 }
2425 else
2426 {
2427 static const char *filename = "eudora/pubs/draft-gellens-submit-09.txt";
2428 wxInputStream *in = ftp.GetInputStream(filename);
2429 if ( !in )
2430 {
2431 printf("ERROR: couldn't get input stream for %s\n", filename);
2432 }
2433 else
2434 {
2435 size_t size = in->StreamSize();
2436 printf("Reading file %s (%u bytes)...", filename, size);
2437
2438 char *data = new char[size];
2439 if ( !in->Read(data, size) )
2440 {
2441 puts("ERROR: read error");
2442 }
2443 else
2444 {
2445 printf("Successfully retrieved the file.\n");
2446 }
2447
2448 delete [] data;
2449 delete in;
2450 }
2451 }
b92fd37c 2452}
b1229561 2453
b92fd37c
VZ
2454static void TestFtpList()
2455{
2456 puts("*** Testing wxFTP file listing ***\n");
8e907a13 2457
b92fd37c
VZ
2458 // test CWD
2459 if ( !ftp.ChDir(directory) )
2460 {
2461 printf("ERROR: failed to cd to %s\n", directory);
2462 }
2e907fab 2463
b92fd37c 2464 printf("Current directory is '%s'\n", ftp.Pwd().c_str());
2e907fab 2465
b92fd37c
VZ
2466 // test NLIST and LIST
2467 wxArrayString files;
2468 if ( !ftp.GetFilesList(files) )
8e907a13 2469 {
b92fd37c 2470 puts("ERROR: failed to get NLIST of files");
8e907a13
VZ
2471 }
2472 else
2473 {
b92fd37c
VZ
2474 printf("Brief list of files under '%s':\n", ftp.Pwd().c_str());
2475 size_t count = files.GetCount();
2476 for ( size_t n = 0; n < count; n++ )
8e907a13 2477 {
b92fd37c 2478 printf("\t%s\n", files[n].c_str());
8e907a13 2479 }
b92fd37c
VZ
2480 puts("End of the file list");
2481 }
8e907a13 2482
b92fd37c
VZ
2483 if ( !ftp.GetDirList(files) )
2484 {
2485 puts("ERROR: failed to get LIST of files");
2486 }
2487 else
2488 {
2489 printf("Detailed list of files under '%s':\n", ftp.Pwd().c_str());
2490 size_t count = files.GetCount();
2491 for ( size_t n = 0; n < count; n++ )
8e907a13 2492 {
b92fd37c 2493 printf("\t%s\n", files[n].c_str());
2e907fab 2494 }
b92fd37c
VZ
2495 puts("End of the file list");
2496 }
2497
2498 if ( !ftp.ChDir(_T("..")) )
2499 {
2500 puts("ERROR: failed to cd to ..");
2501 }
2e907fab 2502
b92fd37c
VZ
2503 printf("Current directory is '%s'\n", ftp.Pwd().c_str());
2504}
2505
2506static void TestFtpDownload()
2507{
2508 puts("*** Testing wxFTP download ***\n");
2509
2510 // test RETR
2511 wxInputStream *in = ftp.GetInputStream(filename);
2512 if ( !in )
2513 {
2514 printf("ERROR: couldn't get input stream for %s\n", filename);
2515 }
2516 else
2517 {
2518 size_t size = in->StreamSize();
2519 printf("Reading file %s (%u bytes)...", filename, size);
2520 fflush(stdout);
2521
2522 char *data = new char[size];
2523 if ( !in->Read(data, size) )
2e907fab 2524 {
b92fd37c 2525 puts("ERROR: read error");
2e907fab
VZ
2526 }
2527 else
2528 {
b92fd37c 2529 printf("\nContents of %s:\n%s\n", filename, data);
8e907a13
VZ
2530 }
2531
b92fd37c
VZ
2532 delete [] data;
2533 delete in;
2534 }
2535}
8e907a13 2536
b92fd37c
VZ
2537static void TestFtpFileSize()
2538{
2539 puts("*** Testing FTP SIZE command ***");
2540
2541 if ( !ftp.ChDir(directory) )
2542 {
2543 printf("ERROR: failed to cd to %s\n", directory);
2544 }
2545
2546 printf("Current directory is '%s'\n", ftp.Pwd().c_str());
2547
2548 if ( ftp.FileExists(filename) )
2549 {
2550 int size = ftp.GetFileSize(filename);
2551 if ( size == -1 )
2552 printf("ERROR: couldn't get size of '%s'\n", filename);
8e907a13 2553 else
b92fd37c
VZ
2554 printf("Size of '%s' is %d bytes.\n", filename, size);
2555 }
2556 else
2557 {
2558 printf("ERROR: '%s' doesn't exist\n", filename);
2559 }
2560}
2561
2562static void TestFtpMisc()
2563{
2564 puts("*** Testing miscellaneous wxFTP functions ***");
2565
2566 if ( ftp.SendCommand("STAT") != '2' )
2567 {
2568 puts("ERROR: STAT failed");
2569 }
2570 else
2571 {
2572 printf("STAT returned:\n\n%s\n", ftp.GetLastResult().c_str());
2573 }
2574
2575 if ( ftp.SendCommand("HELP SITE") != '2' )
2576 {
2577 puts("ERROR: HELP SITE failed");
2578 }
2579 else
2580 {
2581 printf("The list of site-specific commands:\n\n%s\n",
2582 ftp.GetLastResult().c_str());
2583 }
2584}
2585
2586static void TestFtpInteractive()
2587{
2588 puts("\n*** Interactive wxFTP test ***");
2589
2590 char buf[128];
2591
2592 for ( ;; )
2593 {
2594 printf("Enter FTP command: ");
2595 if ( !fgets(buf, WXSIZEOF(buf), stdin) )
2596 break;
2597
2598 // kill the last '\n'
2599 buf[strlen(buf) - 1] = 0;
2600
2601 // special handling of LIST and NLST as they require data connection
2602 wxString start(buf, 4);
2603 start.MakeUpper();
2604 if ( start == "LIST" || start == "NLST" )
8e907a13 2605 {
b92fd37c
VZ
2606 wxString wildcard;
2607 if ( strlen(buf) > 4 )
2608 wildcard = buf + 5;
8e907a13 2609
b92fd37c
VZ
2610 wxArrayString files;
2611 if ( !ftp.GetList(files, wildcard, start == "LIST") )
8e907a13 2612 {
b92fd37c 2613 printf("ERROR: failed to get %s of files\n", start.c_str());
8e907a13
VZ
2614 }
2615 else
2616 {
b92fd37c
VZ
2617 printf("--- %s of '%s' under '%s':\n",
2618 start.c_str(), wildcard.c_str(), ftp.Pwd().c_str());
2619 size_t count = files.GetCount();
2620 for ( size_t n = 0; n < count; n++ )
2621 {
2622 printf("\t%s\n", files[n].c_str());
2623 }
2624 puts("--- End of the file list");
8e907a13 2625 }
2e907fab 2626 }
b92fd37c 2627 else // !list
2e907fab 2628 {
b92fd37c
VZ
2629 char ch = ftp.SendCommand(buf);
2630 printf("Command %s", ch ? "succeeded" : "failed");
2631 if ( ch )
2632 {
2633 printf(" (return code %c)", ch);
2634 }
2e907fab 2635
b92fd37c 2636 printf(", server reply:\n%s\n\n", ftp.GetLastResult().c_str());
2e907fab 2637 }
2c8e4738 2638 }
b92fd37c
VZ
2639
2640 puts("\n*** done ***");
2c8e4738
VZ
2641}
2642
b92fd37c 2643static void TestFtpUpload()
f6bcfd97
BP
2644{
2645 puts("*** Testing wxFTP uploading ***\n");
2646
b92fd37c
VZ
2647 // upload a file
2648 static const char *file1 = "test1";
2649 static const char *file2 = "test2";
2650 wxOutputStream *out = ftp.GetOutputStream(file1);
2651 if ( out )
2652 {
2653 printf("--- Uploading to %s ---\n", file1);
2654 out->Write("First hello", 11);
2655 delete out;
2656 }
f6bcfd97 2657
b92fd37c
VZ
2658 // send a command to check the remote file
2659 if ( ftp.SendCommand(wxString("STAT ") + file1) != '2' )
f6bcfd97 2660 {
b92fd37c 2661 printf("ERROR: STAT %s failed\n", file1);
f6bcfd97
BP
2662 }
2663 else
2664 {
b92fd37c
VZ
2665 printf("STAT %s returned:\n\n%s\n",
2666 file1, ftp.GetLastResult().c_str());
2667 }
2e907fab 2668
b92fd37c
VZ
2669 out = ftp.GetOutputStream(file2);
2670 if ( out )
2671 {
2672 printf("--- Uploading to %s ---\n", file1);
2673 out->Write("Second hello", 12);
2674 delete out;
f6bcfd97
BP
2675 }
2676}
2677
2e907fab 2678#endif // TEST_FTP
2c8e4738 2679
83141d3a
VZ
2680// ----------------------------------------------------------------------------
2681// streams
2682// ----------------------------------------------------------------------------
2683
2684#ifdef TEST_STREAMS
2685
e84010cf
GD
2686#include "wx/wfstream.h"
2687#include "wx/mstream.h"
83141d3a 2688
24f25c8a
VZ
2689static void TestFileStream()
2690{
2691 puts("*** Testing wxFileInputStream ***");
2692
2693 static const wxChar *filename = _T("testdata.fs");
2694 {
2695 wxFileOutputStream fsOut(filename);
2696 fsOut.Write("foo", 3);
2697 }
2698
2699 wxFileInputStream fsIn(filename);
2700 printf("File stream size: %u\n", fsIn.GetSize());
2701 while ( !fsIn.Eof() )
2702 {
2703 putchar(fsIn.GetC());
2704 }
2705
2706 if ( !wxRemoveFile(filename) )
2707 {
2708 printf("ERROR: failed to remove the file '%s'.\n", filename);
2709 }
2710
2711 puts("\n*** wxFileInputStream test done ***");
2712}
2713
83141d3a
VZ
2714static void TestMemoryStream()
2715{
2716 puts("*** Testing wxMemoryInputStream ***");
2717
2718 wxChar buf[1024];
2719 wxStrncpy(buf, _T("Hello, stream!"), WXSIZEOF(buf));
2720
2721 wxMemoryInputStream memInpStream(buf, wxStrlen(buf));
2722 printf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
2723 while ( !memInpStream.Eof() )
2724 {
2725 putchar(memInpStream.GetC());
2726 }
2727
2728 puts("\n*** wxMemoryInputStream test done ***");
2729}
2730
2731#endif // TEST_STREAMS
2732
d31b7b68
VZ
2733// ----------------------------------------------------------------------------
2734// timers
2735// ----------------------------------------------------------------------------
2736
2737#ifdef TEST_TIMER
2738
e84010cf
GD
2739#include "wx/timer.h"
2740#include "wx/utils.h"
d31b7b68
VZ
2741
2742static void TestStopWatch()
2743{
2744 puts("*** Testing wxStopWatch ***\n");
2745
2746 wxStopWatch sw;
2747 printf("Sleeping 3 seconds...");
2748 wxSleep(3);
87798c00 2749 printf("\telapsed time: %ldms\n", sw.Time());
d31b7b68
VZ
2750
2751 sw.Pause();
2752 printf("Sleeping 2 more seconds...");
2753 wxSleep(2);
87798c00 2754 printf("\telapsed time: %ldms\n", sw.Time());
d31b7b68
VZ
2755
2756 sw.Resume();
2757 printf("And 3 more seconds...");
2758 wxSleep(3);
87798c00
VZ
2759 printf("\telapsed time: %ldms\n", sw.Time());
2760
2761 wxStopWatch sw2;
2762 puts("\nChecking for 'backwards clock' bug...");
2763 for ( size_t n = 0; n < 70; n++ )
2764 {
2765 sw2.Start();
89e6463c
GRG
2766
2767 for ( size_t m = 0; m < 100000; m++ )
87798c00 2768 {
89e6463c
GRG
2769 if ( sw.Time() < 0 || sw2.Time() < 0 )
2770 {
2771 puts("\ntime is negative - ERROR!");
2772 }
87798c00
VZ
2773 }
2774
2775 putchar('.');
2776 }
2777
2778 puts(", ok.");
d31b7b68
VZ
2779}
2780
2781#endif // TEST_TIMER
2782
f6bcfd97
BP
2783// ----------------------------------------------------------------------------
2784// vCard support
2785// ----------------------------------------------------------------------------
2786
2787#ifdef TEST_VCARD
2788
e84010cf 2789#include "wx/vcard.h"
f6bcfd97
BP
2790
2791static void DumpVObject(size_t level, const wxVCardObject& vcard)
2792{
2793 void *cookie;
2794 wxVCardObject *vcObj = vcard.GetFirstProp(&cookie);
2795 while ( vcObj )
2796 {
2797 printf("%s%s",
2798 wxString(_T('\t'), level).c_str(),
2799 vcObj->GetName().c_str());
2800
2801 wxString value;
2802 switch ( vcObj->GetType() )
2803 {
2804 case wxVCardObject::String:
2805 case wxVCardObject::UString:
2806 {
2807 wxString val;
2808 vcObj->GetValue(&val);
2809 value << _T('"') << val << _T('"');
2810 }
2811 break;
2812
2813 case wxVCardObject::Int:
2814 {
2815 unsigned int i;
2816 vcObj->GetValue(&i);
2817 value.Printf(_T("%u"), i);
2818 }
2819 break;
2820
2821 case wxVCardObject::Long:
2822 {
2823 unsigned long l;
2824 vcObj->GetValue(&l);
2825 value.Printf(_T("%lu"), l);
2826 }
2827 break;
2828
2829 case wxVCardObject::None:
2830 break;
2831
2832 case wxVCardObject::Object:
2833 value = _T("<node>");
2834 break;
2835
2836 default:
2837 value = _T("<unknown value type>");
2838 }
2839
2840 if ( !!value )
2841 printf(" = %s", value.c_str());
2842 putchar('\n');
2843
2844 DumpVObject(level + 1, *vcObj);
2845
2846 delete vcObj;
2847 vcObj = vcard.GetNextProp(&cookie);
2848 }
2849}
2850
2851static void DumpVCardAddresses(const wxVCard& vcard)
2852{
2853 puts("\nShowing all addresses from vCard:\n");
2854
2855 size_t nAdr = 0;
2856 void *cookie;
2857 wxVCardAddress *addr = vcard.GetFirstAddress(&cookie);
2858 while ( addr )
2859 {
2860 wxString flagsStr;
2861 int flags = addr->GetFlags();
2862 if ( flags & wxVCardAddress::Domestic )
2863 {
2864 flagsStr << _T("domestic ");
2865 }
2866 if ( flags & wxVCardAddress::Intl )
2867 {
2868 flagsStr << _T("international ");
2869 }
2870 if ( flags & wxVCardAddress::Postal )
2871 {
2872 flagsStr << _T("postal ");
2873 }
2874 if ( flags & wxVCardAddress::Parcel )
2875 {
2876 flagsStr << _T("parcel ");
2877 }
2878 if ( flags & wxVCardAddress::Home )
2879 {
2880 flagsStr << _T("home ");
2881 }
2882 if ( flags & wxVCardAddress::Work )
2883 {
2884 flagsStr << _T("work ");
2885 }
2886
2887 printf("Address %u:\n"
2888 "\tflags = %s\n"
2889 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
2890 ++nAdr,
2891 flagsStr.c_str(),
2892 addr->GetPostOffice().c_str(),
2893 addr->GetExtAddress().c_str(),
2894 addr->GetStreet().c_str(),
2895 addr->GetLocality().c_str(),
2896 addr->GetRegion().c_str(),
2897 addr->GetPostalCode().c_str(),
2898 addr->GetCountry().c_str()
2899 );
2900
2901 delete addr;
2902 addr = vcard.GetNextAddress(&cookie);
2903 }
2904}
2905
2906static void DumpVCardPhoneNumbers(const wxVCard& vcard)
2907{
2908 puts("\nShowing all phone numbers from vCard:\n");
2909
2910 size_t nPhone = 0;
2911 void *cookie;
2912 wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie);
2913 while ( phone )
2914 {
2915 wxString flagsStr;
2916 int flags = phone->GetFlags();
2917 if ( flags & wxVCardPhoneNumber::Voice )
2918 {
2919 flagsStr << _T("voice ");
2920 }
2921 if ( flags & wxVCardPhoneNumber::Fax )
2922 {
2923 flagsStr << _T("fax ");
2924 }
2925 if ( flags & wxVCardPhoneNumber::Cellular )
2926 {
2927 flagsStr << _T("cellular ");
2928 }
2929 if ( flags & wxVCardPhoneNumber::Modem )
2930 {
2931 flagsStr << _T("modem ");
2932 }
2933 if ( flags & wxVCardPhoneNumber::Home )
2934 {
2935 flagsStr << _T("home ");
2936 }
2937 if ( flags & wxVCardPhoneNumber::Work )
2938 {
2939 flagsStr << _T("work ");
2940 }
2941
2942 printf("Phone number %u:\n"
2943 "\tflags = %s\n"
2944 "\tvalue = %s\n",
2945 ++nPhone,
2946 flagsStr.c_str(),
2947 phone->GetNumber().c_str()
2948 );
2949
2950 delete phone;
2951 phone = vcard.GetNextPhoneNumber(&cookie);
2952 }
2953}
2954
2955static void TestVCardRead()
2956{
2957 puts("*** Testing wxVCard reading ***\n");
2958
2959 wxVCard vcard(_T("vcard.vcf"));
2960 if ( !vcard.IsOk() )
2961 {
2962 puts("ERROR: couldn't load vCard.");
2963 }
2964 else
2965 {
2966 // read individual vCard properties
2967 wxVCardObject *vcObj = vcard.GetProperty("FN");
2968 wxString value;
2969 if ( vcObj )
2970 {
2971 vcObj->GetValue(&value);
2972 delete vcObj;
2973 }
2974 else
2975 {
2976 value = _T("<none>");
2977 }
2978
2979 printf("Full name retrieved directly: %s\n", value.c_str());
2980
2981
2982 if ( !vcard.GetFullName(&value) )
2983 {
2984 value = _T("<none>");
2985 }
2986
2987 printf("Full name from wxVCard API: %s\n", value.c_str());
2988
2989 // now show how to deal with multiply occuring properties
2990 DumpVCardAddresses(vcard);
2991 DumpVCardPhoneNumbers(vcard);
2992
2993 // and finally show all
2994 puts("\nNow dumping the entire vCard:\n"
2995 "-----------------------------\n");
2996
2997 DumpVObject(0, vcard);
2998 }
2999}
3000
3001static void TestVCardWrite()
3002{
3003 puts("*** Testing wxVCard writing ***\n");
3004
3005 wxVCard vcard;
3006 if ( !vcard.IsOk() )
3007 {
3008 puts("ERROR: couldn't create vCard.");
3009 }
3010 else
3011 {
3012 // set some fields
3013 vcard.SetName("Zeitlin", "Vadim");
3014 vcard.SetFullName("Vadim Zeitlin");
3015 vcard.SetOrganization("wxWindows", "R&D");
3016
3017 // just dump the vCard back
3018 puts("Entire vCard follows:\n");
3019 puts(vcard.Write());
3020 }
3021}
3022
3023#endif // TEST_VCARD
3024
3025// ----------------------------------------------------------------------------
3026// wide char (Unicode) support
3027// ----------------------------------------------------------------------------
3028
3029#ifdef TEST_WCHAR
3030
e84010cf
GD
3031#include "wx/strconv.h"
3032#include "wx/fontenc.h"
3033#include "wx/encconv.h"
3034#include "wx/buffer.h"
f6bcfd97
BP
3035
3036static void TestUtf8()
3037{
3038 puts("*** Testing UTF8 support ***\n");
3039
24f25c8a
VZ
3040 static const char textInUtf8[] =
3041 {
3042 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3043 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3044 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3045 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3046 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3047 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3048 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3049 };
f6bcfd97 3050
24f25c8a
VZ
3051 char buf[1024];
3052 wchar_t wbuf[1024];
3053 if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 )
f6bcfd97 3054 {
24f25c8a 3055 puts("ERROR: UTF-8 decoding failed.");
f6bcfd97 3056 }
24f25c8a
VZ
3057 else
3058 {
3059 // using wxEncodingConverter
3060#if 0
3061 wxEncodingConverter ec;
3062 ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
3063 ec.Convert(wbuf, buf);
3064#else // using wxCSConv
3065 wxCSConv conv(_T("koi8-r"));
3066 if ( conv.WC2MB(buf, wbuf, 0 /* not needed wcslen(wbuf) */) <= 0 )
3067 {
3068 puts("ERROR: conversion to KOI8-R failed.");
3069 }
3070 else
3071#endif
f6bcfd97 3072
24f25c8a
VZ
3073 printf("The resulting string (in koi8-r): %s\n", buf);
3074 }
f6bcfd97
BP
3075}
3076
3077#endif // TEST_WCHAR
3078
3079// ----------------------------------------------------------------------------
3080// ZIP stream
3081// ----------------------------------------------------------------------------
3082
3083#ifdef TEST_ZIP
3084
2ca8b884
VZ
3085#include "wx/filesys.h"
3086#include "wx/fs_zip.h"
f6bcfd97
BP
3087#include "wx/zipstrm.h"
3088
2ca8b884
VZ
3089static const wxChar *TESTFILE_ZIP = _T("testdata.zip");
3090
f6bcfd97
BP
3091static void TestZipStreamRead()
3092{
3093 puts("*** Testing ZIP reading ***\n");
3094
2ca8b884
VZ
3095 static const wxChar *filename = _T("foo");
3096 wxZipInputStream istr(TESTFILE_ZIP, filename);
f6bcfd97
BP
3097 printf("Archive size: %u\n", istr.GetSize());
3098
2ca8b884 3099 printf("Dumping the file '%s':\n", filename);
f6bcfd97
BP
3100 while ( !istr.Eof() )
3101 {
3102 putchar(istr.GetC());
3103 fflush(stdout);
3104 }
3105
3106 puts("\n----- done ------");
3107}
3108
2ca8b884
VZ
3109static void DumpZipDirectory(wxFileSystem& fs,
3110 const wxString& dir,
3111 const wxString& indent)
3112{
3113 wxString prefix = wxString::Format(_T("%s#zip:%s"),
3114 TESTFILE_ZIP, dir.c_str());
3115 wxString wildcard = prefix + _T("/*");
3116
3117 wxString dirname = fs.FindFirst(wildcard, wxDIR);
3118 while ( !dirname.empty() )
3119 {
3120 if ( !dirname.StartsWith(prefix + _T('/'), &dirname) )
3121 {
3122 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3123
3124 break;
3125 }
3126
3127 wxPrintf(_T("%s%s\n"), indent.c_str(), dirname.c_str());
3128
3129 DumpZipDirectory(fs, dirname,
3130 indent + wxString(_T(' '), 4));
3131
3132 dirname = fs.FindNext();
3133 }
3134
3135 wxString filename = fs.FindFirst(wildcard, wxFILE);
3136 while ( !filename.empty() )
3137 {
3138 if ( !filename.StartsWith(prefix, &filename) )
3139 {
3140 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3141
3142 break;
3143 }
3144
3145 wxPrintf(_T("%s%s\n"), indent.c_str(), filename.c_str());
3146
3147 filename = fs.FindNext();
3148 }
3149}
3150
3151static void TestZipFileSystem()
3152{
3153 puts("*** Testing ZIP file system ***\n");
3154
3155 wxFileSystem::AddHandler(new wxZipFSHandler);
3156 wxFileSystem fs;
3157 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP);
3158
3159 DumpZipDirectory(fs, _T(""), wxString(_T(' '), 4));
3160}
3161
f6bcfd97
BP
3162#endif // TEST_ZIP
3163
3ca6a5f0
BP
3164// ----------------------------------------------------------------------------
3165// ZLIB stream
3166// ----------------------------------------------------------------------------
3167
3168#ifdef TEST_ZLIB
3169
e84010cf
GD
3170#include "wx/zstream.h"
3171#include "wx/wfstream.h"
3ca6a5f0
BP
3172
3173static const wxChar *FILENAME_GZ = _T("test.gz");
3174static const char *TEST_DATA = "hello and hello again";
3175
3176static void TestZlibStreamWrite()
3177{
3178 puts("*** Testing Zlib stream reading ***\n");
3179
3180 wxFileOutputStream fileOutStream(FILENAME_GZ);
3181 wxZlibOutputStream ostr(fileOutStream, 0);
3182 printf("Compressing the test string... ");
3183 ostr.Write(TEST_DATA, sizeof(TEST_DATA));
3184 if ( !ostr )
3185 {
3186 puts("(ERROR: failed)");
3187 }
3188 else
3189 {
3190 puts("(ok)");
3191 }
3192
3193 puts("\n----- done ------");
3194}
3195
3196static void TestZlibStreamRead()
3197{
3198 puts("*** Testing Zlib stream reading ***\n");
3199
3200 wxFileInputStream fileInStream(FILENAME_GZ);
3201 wxZlibInputStream istr(fileInStream);
3202 printf("Archive size: %u\n", istr.GetSize());
3203
3204 puts("Dumping the file:");
3205 while ( !istr.Eof() )
3206 {
3207 putchar(istr.GetC());
3208 fflush(stdout);
3209 }
3210
3211 puts("\n----- done ------");
3212}
3213
3214#endif // TEST_ZLIB
3215
b76b015e
VZ
3216// ----------------------------------------------------------------------------
3217// date time
3218// ----------------------------------------------------------------------------
3219
d31b7b68 3220#ifdef TEST_DATETIME
b76b015e 3221
551fe3a6
VZ
3222#include <math.h>
3223
e84010cf
GD
3224#include "wx/date.h"
3225#include "wx/datetime.h"
b76b015e 3226
299fcbfe
VZ
3227// the test data
3228struct Date
3229{
3230 wxDateTime::wxDateTime_t day;
3231 wxDateTime::Month month;
3232 int year;
3233 wxDateTime::wxDateTime_t hour, min, sec;
3234 double jdn;
211c2250 3235 wxDateTime::WeekDay wday;
299fcbfe
VZ
3236 time_t gmticks, ticks;
3237
3238 void Init(const wxDateTime::Tm& tm)
3239 {
3240 day = tm.mday;
3241 month = tm.mon;
3242 year = tm.year;
3243 hour = tm.hour;
3244 min = tm.min;
3245 sec = tm.sec;
3246 jdn = 0.0;
3247 gmticks = ticks = -1;
3248 }
3249
3250 wxDateTime DT() const
3251 { return wxDateTime(day, month, year, hour, min, sec); }
3252
239446b4
VZ
3253 bool SameDay(const wxDateTime::Tm& tm) const
3254 {
3255 return day == tm.mday && month == tm.mon && year == tm.year;
3256 }
3257
299fcbfe
VZ
3258 wxString Format() const
3259 {
3260 wxString s;
3261 s.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
3262 hour, min, sec,
3263 wxDateTime::GetMonthName(month).c_str(),
3264 day,
3265 abs(wxDateTime::ConvertYearToBC(year)),
3266 year > 0 ? "AD" : "BC");
3267 return s;
3268 }
239446b4
VZ
3269
3270 wxString FormatDate() const
3271 {
3272 wxString s;
3273 s.Printf("%02d-%s-%4d%s",
3274 day,
f0f951fa 3275 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
239446b4
VZ
3276 abs(wxDateTime::ConvertYearToBC(year)),
3277 year > 0 ? "AD" : "BC");
3278 return s;
3279 }
299fcbfe
VZ
3280};
3281
3282static const Date testDates[] =
3283{
211c2250
VZ
3284 { 1, wxDateTime::Jan, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu, 0, -3600 },
3285 { 21, wxDateTime::Jan, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon, -1, -1 },
3286 { 29, wxDateTime::May, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat, 202219200, 202212000 },
3287 { 29, wxDateTime::Feb, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun, 194400000, 194396400 },
3288 { 1, wxDateTime::Jan, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon, -1, -1 },
3289 { 1, wxDateTime::Jan, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon, -1, -1 },
3290 { 15, wxDateTime::Oct, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri, -1, -1 },
3291 { 4, wxDateTime::Oct, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon, -1, -1 },
3292 { 1, wxDateTime::Mar, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu, -1, -1 },
3293 { 1, wxDateTime::Jan, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon, -1, -1 },
239446b4
VZ
3294 { 31, wxDateTime::Dec, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun, -1, -1 },
3295 { 1, wxDateTime::Jan, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat, -1, -1 },
3296 { 12, wxDateTime::Aug, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri, -1, -1 },
3297 { 12, wxDateTime::Aug, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat, -1, -1 },
211c2250 3298 { 24, wxDateTime::Nov, -4713, 00, 00, 00, -0.5, wxDateTime::Mon, -1, -1 },
299fcbfe
VZ
3299};
3300
2f02cb89
VZ
3301// this test miscellaneous static wxDateTime functions
3302static void TestTimeStatic()
3303{
3304 puts("\n*** wxDateTime static methods test ***");
3305
3306 // some info about the current date
3307 int year = wxDateTime::GetCurrentYear();
3308 printf("Current year %d is %sa leap one and has %d days.\n",
3309 year,
3310 wxDateTime::IsLeapYear(year) ? "" : "not ",
3311 wxDateTime::GetNumberOfDays(year));
3312
3313 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
3314 printf("Current month is '%s' ('%s') and it has %d days\n",
f0f951fa 3315 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
2f02cb89
VZ
3316 wxDateTime::GetMonthName(month).c_str(),
3317 wxDateTime::GetNumberOfDays(month));
3318
3319 // leap year logic
fcc3d7cb
VZ
3320 static const size_t nYears = 5;
3321 static const size_t years[2][nYears] =
2f02cb89
VZ
3322 {
3323 // first line: the years to test
3324 { 1990, 1976, 2000, 2030, 1984, },
3325
3326 // second line: TRUE if leap, FALSE otherwise
3327 { FALSE, TRUE, TRUE, FALSE, TRUE }
3328 };
3329
3330 for ( size_t n = 0; n < nYears; n++ )
3331 {
3332 int year = years[0][n];
239446b4
VZ
3333 bool should = years[1][n] != 0,
3334 is = wxDateTime::IsLeapYear(year);
2f02cb89 3335
239446b4 3336 printf("Year %d is %sa leap year (%s)\n",
2f02cb89 3337 year,
239446b4
VZ
3338 is ? "" : "not ",
3339 should == is ? "ok" : "ERROR");
2f02cb89
VZ
3340
3341 wxASSERT( should == wxDateTime::IsLeapYear(year) );
3342 }
3343}
3344
3345// test constructing wxDateTime objects
3346static void TestTimeSet()
3347{
3348 puts("\n*** wxDateTime construction test ***");
3349
299fcbfe
VZ
3350 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
3351 {
3352 const Date& d1 = testDates[n];
3353 wxDateTime dt = d1.DT();
3354
3355 Date d2;
3356 d2.Init(dt.GetTm());
3357
3358 wxString s1 = d1.Format(),
3359 s2 = d2.Format();
3360
3361 printf("Date: %s == %s (%s)\n",
3362 s1.c_str(), s2.c_str(),
3363 s1 == s2 ? "ok" : "ERROR");
3364 }
2f02cb89
VZ
3365}
3366
fcc3d7cb
VZ
3367// test time zones stuff
3368static void TestTimeZones()
3369{
3370 puts("\n*** wxDateTime timezone test ***");
3371
3372 wxDateTime now = wxDateTime::Now();
3373
299fcbfe
VZ
3374 printf("Current GMT time:\t%s\n", now.Format("%c", wxDateTime::GMT0).c_str());
3375 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0).c_str());
3376 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST).c_str());
3377 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
3378 printf(" Moscow:\t%s\n", now.Format("%c", wxDateTime::MSK).c_str());
3379 printf(" New York:\t%s\n", now.Format("%c", wxDateTime::EST).c_str());
9d9b7755
VZ
3380
3381 wxDateTime::Tm tm = now.GetTm();
3382 if ( wxDateTime(tm) != now )
3383 {
3384 printf("ERROR: got %s instead of %s\n",
3385 wxDateTime(tm).Format().c_str(), now.Format().c_str());
3386 }
fcc3d7cb
VZ
3387}
3388
e6ec579c
VZ
3389// test some minimal support for the dates outside the standard range
3390static void TestTimeRange()
3391{
3392 puts("\n*** wxDateTime out-of-standard-range dates test ***");
3393
211c2250
VZ
3394 static const char *fmt = "%d-%b-%Y %H:%M:%S";
3395
1ef54dcf 3396 printf("Unix epoch:\t%s\n",
211c2250 3397 wxDateTime(2440587.5).Format(fmt).c_str());
1ef54dcf 3398 printf("Feb 29, 0: \t%s\n",
211c2250 3399 wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str());
e6ec579c 3400 printf("JDN 0: \t%s\n",
211c2250 3401 wxDateTime(0.0).Format(fmt).c_str());
e6ec579c 3402 printf("Jan 1, 1AD:\t%s\n",
211c2250 3403 wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str());
e6ec579c 3404 printf("May 29, 2099:\t%s\n",
211c2250 3405 wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str());
e6ec579c
VZ
3406}
3407
299fcbfe 3408static void TestTimeTicks()
e6ec579c 3409{
299fcbfe 3410 puts("\n*** wxDateTime ticks test ***");
e6ec579c 3411
299fcbfe 3412 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
1ef54dcf 3413 {
299fcbfe
VZ
3414 const Date& d = testDates[n];
3415 if ( d.ticks == -1 )
3416 continue;
1ef54dcf 3417
299fcbfe
VZ
3418 wxDateTime dt = d.DT();
3419 long ticks = (dt.GetValue() / 1000).ToLong();
3420 printf("Ticks of %s:\t% 10ld", d.Format().c_str(), ticks);
3421 if ( ticks == d.ticks )
3422 {
3423 puts(" (ok)");
3424 }
3425 else
3426 {
3427 printf(" (ERROR: should be %ld, delta = %ld)\n",
3428 d.ticks, ticks - d.ticks);
3429 }
3430
3431 dt = d.DT().ToTimezone(wxDateTime::GMT0);
3432 ticks = (dt.GetValue() / 1000).ToLong();
3433 printf("GMtks of %s:\t% 10ld", d.Format().c_str(), ticks);
3434 if ( ticks == d.gmticks )
3435 {
3436 puts(" (ok)");
3437 }
3438 else
3439 {
3440 printf(" (ERROR: should be %ld, delta = %ld)\n",
3441 d.gmticks, ticks - d.gmticks);
3442 }
3443 }
3444
3445 puts("");
3446}
3447
3448// test conversions to JDN &c
3449static void TestTimeJDN()
3450{
3451 puts("\n*** wxDateTime to JDN test ***");
1ef54dcf
VZ
3452
3453 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
3454 {
3455 const Date& d = testDates[n];
299fcbfe 3456 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
1ef54dcf
VZ
3457 double jdn = dt.GetJulianDayNumber();
3458
299fcbfe 3459 printf("JDN of %s is:\t% 15.6f", d.Format().c_str(), jdn);
1ef54dcf
VZ
3460 if ( jdn == d.jdn )
3461 {
3462 puts(" (ok)");
3463 }
3464 else
3465 {
3466 printf(" (ERROR: should be %f, delta = %f)\n",
3467 d.jdn, jdn - d.jdn);
3468 }
3469 }
e6ec579c
VZ
3470}
3471
211c2250
VZ
3472// test week days computation
3473static void TestTimeWDays()
3474{
3475 puts("\n*** wxDateTime weekday test ***");
3476
239446b4
VZ
3477 // test GetWeekDay()
3478 size_t n;
3479 for ( n = 0; n < WXSIZEOF(testDates); n++ )
211c2250
VZ
3480 {
3481 const Date& d = testDates[n];
3482 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
3483
3484 wxDateTime::WeekDay wday = dt.GetWeekDay();
3485 printf("%s is: %s",
3486 d.Format().c_str(),
239446b4 3487 wxDateTime::GetWeekDayName(wday).c_str());
211c2250
VZ
3488 if ( wday == d.wday )
3489 {
3490 puts(" (ok)");
3491 }
3492 else
3493 {
3494 printf(" (ERROR: should be %s)\n",
239446b4
VZ
3495 wxDateTime::GetWeekDayName(d.wday).c_str());
3496 }
3497 }
3498
3499 puts("");
3500
3501 // test SetToWeekDay()
3502 struct WeekDateTestData
3503 {
3504 Date date; // the real date (precomputed)
3505 int nWeek; // its week index in the month
3506 wxDateTime::WeekDay wday; // the weekday
3507 wxDateTime::Month month; // the month
3508 int year; // and the year
3509
3510 wxString Format() const
3511 {
3512 wxString s, which;
3513 switch ( nWeek < -1 ? -nWeek : nWeek )
3514 {
3515 case 1: which = "first"; break;
3516 case 2: which = "second"; break;
3517 case 3: which = "third"; break;
3518 case 4: which = "fourth"; break;
3519 case 5: which = "fifth"; break;
3520
3521 case -1: which = "last"; break;
3522 }
3523
3524 if ( nWeek < -1 )
3525 {
3526 which += " from end";
3527 }
3528
3529 s.Printf("The %s %s of %s in %d",
3530 which.c_str(),
3531 wxDateTime::GetWeekDayName(wday).c_str(),
3532 wxDateTime::GetMonthName(month).c_str(),
3533 year);
3534
3535 return s;
3536 }
3537 };
3538
3539 // the array data was generated by the following python program
3540 /*
3541from DateTime import *
3542from whrandom import *
3543from string import *
3544
3545monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3546wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3547
3548week = DateTimeDelta(7)
3549
3550for n in range(20):
3551 year = randint(1900, 2100)
3552 month = randint(1, 12)
3553 day = randint(1, 28)
3554 dt = DateTime(year, month, day)
3555 wday = dt.day_of_week
3556
3557 countFromEnd = choice([-1, 1])
3558 weekNum = 0;
3559
3560 while dt.month is month:
3561 dt = dt - countFromEnd * week
3562 weekNum = weekNum + countFromEnd
3563
3564 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
97e0ceea 3565
239446b4
VZ
3566 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
3567 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
97e0ceea 3568 */
239446b4
VZ
3569
3570 static const WeekDateTestData weekDatesTestData[] =
3571 {
3572 { { 20, wxDateTime::Mar, 2045 }, 3, wxDateTime::Mon, wxDateTime::Mar, 2045 },
3573 { { 5, wxDateTime::Jun, 1985 }, -4, wxDateTime::Wed, wxDateTime::Jun, 1985 },
3574 { { 12, wxDateTime::Nov, 1961 }, -3, wxDateTime::Sun, wxDateTime::Nov, 1961 },
3575 { { 27, wxDateTime::Feb, 2093 }, -1, wxDateTime::Fri, wxDateTime::Feb, 2093 },
3576 { { 4, wxDateTime::Jul, 2070 }, -4, wxDateTime::Fri, wxDateTime::Jul, 2070 },
3577 { { 2, wxDateTime::Apr, 1906 }, -5, wxDateTime::Mon, wxDateTime::Apr, 1906 },
3578 { { 19, wxDateTime::Jul, 2023 }, -2, wxDateTime::Wed, wxDateTime::Jul, 2023 },
3579 { { 5, wxDateTime::May, 1958 }, -4, wxDateTime::Mon, wxDateTime::May, 1958 },
3580 { { 11, wxDateTime::Aug, 1900 }, 2, wxDateTime::Sat, wxDateTime::Aug, 1900 },
3581 { { 14, wxDateTime::Feb, 1945 }, 2, wxDateTime::Wed, wxDateTime::Feb, 1945 },
3582 { { 25, wxDateTime::Jul, 1967 }, -1, wxDateTime::Tue, wxDateTime::Jul, 1967 },
3583 { { 9, wxDateTime::May, 1916 }, -4, wxDateTime::Tue, wxDateTime::May, 1916 },
3584 { { 20, wxDateTime::Jun, 1927 }, 3, wxDateTime::Mon, wxDateTime::Jun, 1927 },
3585 { { 2, wxDateTime::Aug, 2000 }, 1, wxDateTime::Wed, wxDateTime::Aug, 2000 },
3586 { { 20, wxDateTime::Apr, 2044 }, 3, wxDateTime::Wed, wxDateTime::Apr, 2044 },
3587 { { 20, wxDateTime::Feb, 1932 }, -2, wxDateTime::Sat, wxDateTime::Feb, 1932 },
3588 { { 25, wxDateTime::Jul, 2069 }, 4, wxDateTime::Thu, wxDateTime::Jul, 2069 },
3589 { { 3, wxDateTime::Apr, 1925 }, 1, wxDateTime::Fri, wxDateTime::Apr, 1925 },
3590 { { 21, wxDateTime::Mar, 2093 }, 3, wxDateTime::Sat, wxDateTime::Mar, 2093 },
3591 { { 3, wxDateTime::Dec, 2074 }, -5, wxDateTime::Mon, wxDateTime::Dec, 2074 },
3592 };
3593
3594 static const char *fmt = "%d-%b-%Y";
3595
3596 wxDateTime dt;
3597 for ( n = 0; n < WXSIZEOF(weekDatesTestData); n++ )
3598 {
3599 const WeekDateTestData& wd = weekDatesTestData[n];
3600
3601 dt.SetToWeekDay(wd.wday, wd.nWeek, wd.month, wd.year);
3602
3603 printf("%s is %s", wd.Format().c_str(), dt.Format(fmt).c_str());
3604
3605 const Date& d = wd.date;
3606 if ( d.SameDay(dt.GetTm()) )
3607 {
3608 puts(" (ok)");
3609 }
3610 else
3611 {
3612 dt.Set(d.day, d.month, d.year);
3613
3614 printf(" (ERROR: should be %s)\n", dt.Format(fmt).c_str());
211c2250
VZ
3615 }
3616 }
3617}
3618
239446b4
VZ
3619// test the computation of (ISO) week numbers
3620static void TestTimeWNumber()
3621{
3622 puts("\n*** wxDateTime week number test ***");
3623
3624 struct WeekNumberTestData
3625 {
3626 Date date; // the date
9d9b7755
VZ
3627 wxDateTime::wxDateTime_t week; // the week number in the year
3628 wxDateTime::wxDateTime_t wmon; // the week number in the month
3629 wxDateTime::wxDateTime_t wmon2; // same but week starts with Sun
239446b4
VZ
3630 wxDateTime::wxDateTime_t dnum; // day number in the year
3631 };
3632
3633 // data generated with the following python script:
3634 /*
3635from DateTime import *
3636from whrandom import *
3637from string import *
3638
3639monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
3640wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
3641
9d9b7755
VZ
3642def GetMonthWeek(dt):
3643 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
3644 if weekNumMonth < 0:
3645 weekNumMonth = weekNumMonth + 53
3646 return weekNumMonth
7c968cee 3647
9d9b7755
VZ
3648def GetLastSundayBefore(dt):
3649 if dt.iso_week[2] == 7:
3650 return dt
3651 else:
3652 return dt - DateTimeDelta(dt.iso_week[2])
3653
239446b4
VZ
3654for n in range(20):
3655 year = randint(1900, 2100)
3656 month = randint(1, 12)
3657 day = randint(1, 28)
3658 dt = DateTime(year, month, day)
3659 dayNum = dt.day_of_year
3660 weekNum = dt.iso_week[1]
9d9b7755
VZ
3661 weekNumMonth = GetMonthWeek(dt)
3662
3663 weekNumMonth2 = 0
3664 dtSunday = GetLastSundayBefore(dt)
3665
3666 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
3667 weekNumMonth2 = weekNumMonth2 + 1
3668 dtSunday = dtSunday - DateTimeDelta(7)
3669
3670 data = { 'day': rjust(`day`, 2), \
3671 'month': monthNames[month - 1], \
3672 'year': year, \
3673 'weekNum': rjust(`weekNum`, 2), \
3674 'weekNumMonth': weekNumMonth, \
3675 'weekNumMonth2': weekNumMonth2, \
3676 'dayNum': rjust(`dayNum`, 3) }
3677
3678 print " { { %(day)s, "\
3679 "wxDateTime::%(month)s, "\
3680 "%(year)d }, "\
3681 "%(weekNum)s, "\
3682 "%(weekNumMonth)s, "\
3683 "%(weekNumMonth2)s, "\
239446b4 3684 "%(dayNum)s }," % data
9d9b7755 3685
239446b4
VZ
3686 */
3687 static const WeekNumberTestData weekNumberTestDates[] =
3688 {
9d9b7755
VZ
3689 { { 27, wxDateTime::Dec, 1966 }, 52, 5, 5, 361 },
3690 { { 22, wxDateTime::Jul, 1926 }, 29, 4, 4, 203 },
3691 { { 22, wxDateTime::Oct, 2076 }, 43, 4, 4, 296 },
3692 { { 1, wxDateTime::Jul, 1967 }, 26, 1, 1, 182 },
3693 { { 8, wxDateTime::Nov, 2004 }, 46, 2, 2, 313 },
3694 { { 21, wxDateTime::Mar, 1920 }, 12, 3, 4, 81 },
3695 { { 7, wxDateTime::Jan, 1965 }, 1, 2, 2, 7 },
3696 { { 19, wxDateTime::Oct, 1999 }, 42, 4, 4, 292 },
3697 { { 13, wxDateTime::Aug, 1955 }, 32, 2, 2, 225 },
3698 { { 18, wxDateTime::Jul, 2087 }, 29, 3, 3, 199 },
3699 { { 2, wxDateTime::Sep, 2028 }, 35, 1, 1, 246 },
3700 { { 28, wxDateTime::Jul, 1945 }, 30, 5, 4, 209 },
3701 { { 15, wxDateTime::Jun, 1901 }, 24, 3, 3, 166 },
3702 { { 10, wxDateTime::Oct, 1939 }, 41, 3, 2, 283 },
3703 { { 3, wxDateTime::Dec, 1965 }, 48, 1, 1, 337 },
3704 { { 23, wxDateTime::Feb, 1940 }, 8, 4, 4, 54 },
3705 { { 2, wxDateTime::Jan, 1987 }, 1, 1, 1, 2 },
3706 { { 11, wxDateTime::Aug, 2079 }, 32, 2, 2, 223 },
3707 { { 2, wxDateTime::Feb, 2063 }, 5, 1, 1, 33 },
3708 { { 16, wxDateTime::Oct, 1942 }, 42, 3, 3, 289 },
239446b4
VZ
3709 };
3710
3711 for ( size_t n = 0; n < WXSIZEOF(weekNumberTestDates); n++ )
3712 {
3713 const WeekNumberTestData& wn = weekNumberTestDates[n];
3714 const Date& d = wn.date;
3715
3716 wxDateTime dt = d.DT();
3717
9d9b7755
VZ
3718 wxDateTime::wxDateTime_t
3719 week = dt.GetWeekOfYear(wxDateTime::Monday_First),
3720 wmon = dt.GetWeekOfMonth(wxDateTime::Monday_First),
3721 wmon2 = dt.GetWeekOfMonth(wxDateTime::Sunday_First),
3722 dnum = dt.GetDayOfYear();
239446b4
VZ
3723
3724 printf("%s: the day number is %d",
3725 d.FormatDate().c_str(), dnum);
3726 if ( dnum == wn.dnum )
3727 {
3728 printf(" (ok)");
3729 }
3730 else
3731 {
3732 printf(" (ERROR: should be %d)", wn.dnum);
3733 }
3734
9d9b7755
VZ
3735 printf(", week in month is %d", wmon);
3736 if ( wmon == wn.wmon )
3737 {
3738 printf(" (ok)");
3739 }
3740 else
3741 {
3742 printf(" (ERROR: should be %d)", wn.wmon);
3743 }
3744
3745 printf(" or %d", wmon2);
3746 if ( wmon2 == wn.wmon2 )
3747 {
3748 printf(" (ok)");
3749 }
3750 else
3751 {
3752 printf(" (ERROR: should be %d)", wn.wmon2);
3753 }
3754
3755 printf(", week in year is %d", week);
239446b4
VZ
3756 if ( week == wn.week )
3757 {
3758 puts(" (ok)");
3759 }
3760 else
3761 {
3762 printf(" (ERROR: should be %d)\n", wn.week);
3763 }
3764 }
3765}
3766
3767// test DST calculations
3768static void TestTimeDST()
3769{
3770 puts("\n*** wxDateTime DST test ***");
3771
3772 printf("DST is%s in effect now.\n\n",
3773 wxDateTime::Now().IsDST() ? "" : " not");
3774
3775 // taken from http://www.energy.ca.gov/daylightsaving.html
3776 static const Date datesDST[2][2004 - 1900 + 1] =
3777 {
3778 {
3779 { 1, wxDateTime::Apr, 1990 },
3780 { 7, wxDateTime::Apr, 1991 },
3781 { 5, wxDateTime::Apr, 1992 },
3782 { 4, wxDateTime::Apr, 1993 },
3783 { 3, wxDateTime::Apr, 1994 },
3784 { 2, wxDateTime::Apr, 1995 },
3785 { 7, wxDateTime::Apr, 1996 },
3786 { 6, wxDateTime::Apr, 1997 },
3787 { 5, wxDateTime::Apr, 1998 },
3788 { 4, wxDateTime::Apr, 1999 },
3789 { 2, wxDateTime::Apr, 2000 },
3790 { 1, wxDateTime::Apr, 2001 },
3791 { 7, wxDateTime::Apr, 2002 },
3792 { 6, wxDateTime::Apr, 2003 },
3793 { 4, wxDateTime::Apr, 2004 },
3794 },
3795 {
3796 { 28, wxDateTime::Oct, 1990 },
3797 { 27, wxDateTime::Oct, 1991 },
3798 { 25, wxDateTime::Oct, 1992 },
3799 { 31, wxDateTime::Oct, 1993 },
3800 { 30, wxDateTime::Oct, 1994 },
3801 { 29, wxDateTime::Oct, 1995 },
3802 { 27, wxDateTime::Oct, 1996 },
3803 { 26, wxDateTime::Oct, 1997 },
3804 { 25, wxDateTime::Oct, 1998 },
3805 { 31, wxDateTime::Oct, 1999 },
3806 { 29, wxDateTime::Oct, 2000 },
3807 { 28, wxDateTime::Oct, 2001 },
3808 { 27, wxDateTime::Oct, 2002 },
3809 { 26, wxDateTime::Oct, 2003 },
3810 { 31, wxDateTime::Oct, 2004 },
3811 }
3812 };
3813
3814 int year;
3815 for ( year = 1990; year < 2005; year++ )
3816 {
3817 wxDateTime dtBegin = wxDateTime::GetBeginDST(year, wxDateTime::USA),
3818 dtEnd = wxDateTime::GetEndDST(year, wxDateTime::USA);
3819
3820 printf("DST period in the US for year %d: from %s to %s",
3821 year, dtBegin.Format().c_str(), dtEnd.Format().c_str());
3822
3823 size_t n = year - 1990;
3824 const Date& dBegin = datesDST[0][n];
3825 const Date& dEnd = datesDST[1][n];
97e0ceea 3826
239446b4
VZ
3827 if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
3828 {
3829 puts(" (ok)");
3830 }
3831 else
3832 {
3833 printf(" (ERROR: should be %s %d to %s %d)\n",
3834 wxDateTime::GetMonthName(dBegin.month).c_str(), dBegin.day,
3835 wxDateTime::GetMonthName(dEnd.month).c_str(), dEnd.day);
3836 }
3837 }
3838
3839 puts("");
3840
3841 for ( year = 1990; year < 2005; year++ )
3842 {
3843 printf("DST period in Europe for year %d: from %s to %s\n",
3844 year,
3845 wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
3846 wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
3847 }
3848}
3849
68ee7c47
VZ
3850// test wxDateTime -> text conversion
3851static void TestTimeFormat()
3852{
3853 puts("\n*** wxDateTime formatting test ***");
3854
b38e2f7d
VZ
3855 // some information may be lost during conversion, so store what kind
3856 // of info should we recover after a round trip
3857 enum CompareKind
68ee7c47 3858 {
b38e2f7d
VZ
3859 CompareNone, // don't try comparing
3860 CompareBoth, // dates and times should be identical
3861 CompareDate, // dates only
3862 CompareTime // time only
3863 };
3864
3865 static const struct
3866 {
3867 CompareKind compareKind;
3868 const char *format;
3869 } formatTestFormats[] =
3870 {
3871 { CompareBoth, "---> %c" },
3872 { CompareDate, "Date is %A, %d of %B, in year %Y" },
3873 { CompareBoth, "Date is %x, time is %X" },
3874 { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
3875 { CompareNone, "The day of year: %j, the week of year: %W" },
f6bcfd97 3876 { CompareDate, "ISO date without separators: %4Y%2m%2d" },
68ee7c47
VZ
3877 };
3878
3879 static const Date formatTestDates[] =
3880 {
68ee7c47
VZ
3881 { 29, wxDateTime::May, 1976, 18, 30, 00 },
3882 { 31, wxDateTime::Dec, 1999, 23, 30, 00 },
b38e2f7d
VZ
3883#if 0
3884 // this test can't work for other centuries because it uses two digit
3885 // years in formats, so don't even try it
68ee7c47
VZ
3886 { 29, wxDateTime::May, 2076, 18, 30, 00 },
3887 { 29, wxDateTime::Feb, 2400, 02, 15, 25 },
3888 { 01, wxDateTime::Jan, -52, 03, 16, 47 },
b38e2f7d 3889#endif
68ee7c47
VZ
3890 };
3891
3892 // an extra test (as it doesn't depend on date, don't do it in the loop)
3893 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
3894
b38e2f7d 3895 for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ )
68ee7c47
VZ
3896 {
3897 puts("");
3898
b38e2f7d 3899 wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT();
68ee7c47
VZ
3900 for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
3901 {
b38e2f7d 3902 wxString s = dt.Format(formatTestFormats[n].format);
f0f951fa
VZ
3903 printf("%s", s.c_str());
3904
b38e2f7d
VZ
3905 // what can we recover?
3906 int kind = formatTestFormats[n].compareKind;
3907
f0f951fa
VZ
3908 // convert back
3909 wxDateTime dt2;
b38e2f7d 3910 const wxChar *result = dt2.ParseFormat(s, formatTestFormats[n].format);
f0f951fa
VZ
3911 if ( !result )
3912 {
b38e2f7d
VZ
3913 // converion failed - should it have?
3914 if ( kind == CompareNone )
3915 puts(" (ok)");
3916 else
3917 puts(" (ERROR: conversion back failed)");
f0f951fa
VZ
3918 }
3919 else if ( *result )
3920 {
3921 // should have parsed the entire string
3922 puts(" (ERROR: conversion back stopped too soon)");
3923 }
f0f951fa
VZ
3924 else
3925 {
b38e2f7d
VZ
3926 bool equal = FALSE; // suppress compilaer warning
3927 switch ( kind )
3928 {
3929 case CompareBoth:
3930 equal = dt2 == dt;
3931 break;
3932
3933 case CompareDate:
3934 equal = dt.IsSameDate(dt2);
3935 break;
3936
3937 case CompareTime:
3938 equal = dt.IsSameTime(dt2);
3939 break;
3940 }
3941
3942 if ( !equal )
3943 {
3944 printf(" (ERROR: got back '%s' instead of '%s')\n",
3945 dt2.Format().c_str(), dt.Format().c_str());
3946 }
3947 else
3948 {
3949 puts(" (ok)");
3950 }
f0f951fa 3951 }
68ee7c47
VZ
3952 }
3953 }
3954}
3955
97e0ceea
VZ
3956// test text -> wxDateTime conversion
3957static void TestTimeParse()
3958{
3959 puts("\n*** wxDateTime parse test ***");
3960
3961 struct ParseTestData
3962 {
3963 const char *format;
3964 Date date;
3965 bool good;
3966 };
3967
3968 static const ParseTestData parseTestDates[] =
3969 {
68ee7c47
VZ
3970 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, TRUE },
3971 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec, 1999, 03, 17, 20 }, TRUE },
97e0ceea
VZ
3972 };
3973
3974 for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
3975 {
3976 const char *format = parseTestDates[n].format;
3977
3978 printf("%s => ", format);
3979
3980 wxDateTime dt;
3981 if ( dt.ParseRfc822Date(format) )
3982 {
3983 printf("%s ", dt.Format().c_str());
3984
3985 if ( parseTestDates[n].good )
3986 {
3987 wxDateTime dtReal = parseTestDates[n].date.DT();
3988 if ( dt == dtReal )
3989 {
3990 puts("(ok)");
3991 }
3992 else
3993 {
3994 printf("(ERROR: should be %s)\n", dtReal.Format().c_str());
3995 }
3996 }
3997 else
3998 {
3999 puts("(ERROR: bad format)");
4000 }
4001 }
4002 else
4003 {
4004 printf("bad format (%s)\n",
4005 parseTestDates[n].good ? "ERROR" : "ok");
4006 }
4007 }
4008}
4009
b92fd37c 4010static void TestDateTimeInteractive()
9d9b7755
VZ
4011{
4012 puts("\n*** interactive wxDateTime tests ***");
4013
4014 char buf[128];
4015
4016 for ( ;; )
4017 {
4018 printf("Enter a date: ");
4019 if ( !fgets(buf, WXSIZEOF(buf), stdin) )
4020 break;
4021
f6bcfd97
BP
4022 // kill the last '\n'
4023 buf[strlen(buf) - 1] = 0;
4024
9d9b7755 4025 wxDateTime dt;
f6bcfd97
BP
4026 const char *p = dt.ParseDate(buf);
4027 if ( !p )
9d9b7755 4028 {
f6bcfd97 4029 printf("ERROR: failed to parse the date '%s'.\n", buf);
9d9b7755
VZ
4030
4031 continue;
4032 }
f6bcfd97
BP
4033 else if ( *p )
4034 {
4035 printf("WARNING: parsed only first %u characters.\n", p - buf);
4036 }
9d9b7755
VZ
4037
4038 printf("%s: day %u, week of month %u/%u, week of year %u\n",
f6bcfd97 4039 dt.Format("%b %d, %Y").c_str(),
9d9b7755
VZ
4040 dt.GetDayOfYear(),
4041 dt.GetWeekOfMonth(wxDateTime::Monday_First),
4042 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
4043 dt.GetWeekOfYear(wxDateTime::Monday_First));
4044 }
4045
4046 puts("\n*** done ***");
4047}
4048
f6bcfd97
BP
4049static void TestTimeMS()
4050{
4051 puts("*** testing millisecond-resolution support in wxDateTime ***");
4052
4053 wxDateTime dt1 = wxDateTime::Now(),
4054 dt2 = wxDateTime::UNow();
4055
4056 printf("Now = %s\n", dt1.Format("%H:%M:%S:%l").c_str());
4057 printf("UNow = %s\n", dt2.Format("%H:%M:%S:%l").c_str());
3ca6a5f0
BP
4058 printf("Dummy loop: ");
4059 for ( int i = 0; i < 6000; i++ )
4060 {
4061 //for ( int j = 0; j < 10; j++ )
4062 {
4063 wxString s;
4064 s.Printf("%g", sqrt(i));
4065 }
4066
4067 if ( !(i % 100) )
4068 putchar('.');
4069 }
4070 puts(", done");
4071
4072 dt1 = dt2;
4073 dt2 = wxDateTime::UNow();
4074 printf("UNow = %s\n", dt2.Format("%H:%M:%S:%l").c_str());
4075
4076 printf("Loop executed in %s ms\n", (dt2 - dt1).Format("%l").c_str());
f6bcfd97
BP
4077
4078 puts("\n*** done ***");
4079}
4080
9d9b7755
VZ
4081static void TestTimeArithmetics()
4082{
4083 puts("\n*** testing arithmetic operations on wxDateTime ***");
4084
f6bcfd97 4085 static const struct ArithmData
9d9b7755 4086 {
f6bcfd97
BP
4087 ArithmData(const wxDateSpan& sp, const char *nam)
4088 : span(sp), name(nam) { }
4089
9d9b7755
VZ
4090 wxDateSpan span;
4091 const char *name;
7c968cee 4092 } testArithmData[] =
9d9b7755 4093 {
f6bcfd97
BP
4094 ArithmData(wxDateSpan::Day(), "day"),
4095 ArithmData(wxDateSpan::Week(), "week"),
4096 ArithmData(wxDateSpan::Month(), "month"),
4097 ArithmData(wxDateSpan::Year(), "year"),
4098 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
9d9b7755 4099 };
7c968cee 4100
9d9b7755
VZ
4101 wxDateTime dt(29, wxDateTime::Dec, 1999), dt1, dt2;
4102
4103 for ( size_t n = 0; n < WXSIZEOF(testArithmData); n++ )
4104 {
4105 wxDateSpan span = testArithmData[n].span;
4106 dt1 = dt + span;
4107 dt2 = dt - span;
4108
4109 const char *name = testArithmData[n].name;
4110 printf("%s + %s = %s, %s - %s = %s\n",
4111 dt.FormatISODate().c_str(), name, dt1.FormatISODate().c_str(),
4112 dt.FormatISODate().c_str(), name, dt2.FormatISODate().c_str());
4113
4114 printf("Going back: %s", (dt1 - span).FormatISODate().c_str());
4115 if ( dt1 - span == dt )
4116 {
4117 puts(" (ok)");
4118 }
4119 else
4120 {
4121 printf(" (ERROR: should be %s)\n", dt.FormatISODate().c_str());
4122 }
4123
4124 printf("Going forward: %s", (dt2 + span).FormatISODate().c_str());
4125 if ( dt2 + span == dt )
4126 {
4127 puts(" (ok)");
4128 }
4129 else
4130 {
4131 printf(" (ERROR: should be %s)\n", dt.FormatISODate().c_str());
4132 }
4133
4134 printf("Double increment: %s", (dt2 + 2*span).FormatISODate().c_str());
4135 if ( dt2 + 2*span == dt1 )
4136 {
4137 puts(" (ok)");
4138 }
4139 else
4140 {
4141 printf(" (ERROR: should be %s)\n", dt2.FormatISODate().c_str());
4142 }
4143
4144 puts("");
4145 }
4146}
4147
0de868d9
VZ
4148static void TestTimeHolidays()
4149{
4150 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
4151
4152 wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
4153 wxDateTime dtStart(1, tm.mon, tm.year),
4154 dtEnd = dtStart.GetLastMonthDay();
4155
4156 wxDateTimeArray hol;
4157 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
4158
4159 const wxChar *format = "%d-%b-%Y (%a)";
4160
4161 printf("All holidays between %s and %s:\n",
4162 dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
4163
4164 size_t count = hol.GetCount();
4165 for ( size_t n = 0; n < count; n++ )
4166 {
4167 printf("\t%s\n", hol[n].Format(format).c_str());
4168 }
4169
4170 puts("");
4171}
4172
f6bcfd97
BP
4173static void TestTimeZoneBug()
4174{
4175 puts("\n*** testing for DST/timezone bug ***\n");
4176
4177 wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000);
4178 for ( int i = 0; i < 31; i++ )
4179 {
4180 printf("Date %s: week day %s.\n",
4181 date.Format(_T("%d-%m-%Y")).c_str(),
4182 date.GetWeekDayName(date.GetWeekDay()).c_str());
4183
4184 date += wxDateSpan::Day();
4185 }
4186
4187 puts("");
4188}
4189
df05cdc5
VZ
4190static void TestTimeSpanFormat()
4191{
4192 puts("\n*** wxTimeSpan tests ***");
4193
4194 static const char *formats[] =
4195 {
4196 _T("(default) %H:%M:%S"),
4197 _T("%E weeks and %D days"),
4198 _T("%l milliseconds"),
4199 _T("(with ms) %H:%M:%S:%l"),
4200 _T("100%% of minutes is %M"), // test "%%"
4201 _T("%D days and %H hours"),
a8625337 4202 _T("or also %S seconds"),
df05cdc5
VZ
4203 };
4204
4205 wxTimeSpan ts1(1, 2, 3, 4),
4206 ts2(111, 222, 333);
4207 for ( size_t n = 0; n < WXSIZEOF(formats); n++ )
4208 {
4209 printf("ts1 = %s\tts2 = %s\n",
4210 ts1.Format(formats[n]).c_str(),
4211 ts2.Format(formats[n]).c_str());
4212 }
4213
4214 puts("");
4215}
4216
68ee7c47
VZ
4217#if 0
4218
97e0ceea
VZ
4219// test compatibility with the old wxDate/wxTime classes
4220static void TestTimeCompatibility()
4221{
4222 puts("\n*** wxDateTime compatibility test ***");
4223
4224 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
4225 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
4226
4227 double jdnNow = wxDateTime::Now().GetJDN();
4228 long jdnMidnight = (long)(jdnNow - 0.5);
4229 printf("wxDate for today: %s\n", wxDate(jdnMidnight).FormatDate().c_str());
4230
4231 jdnMidnight = wxDate().Set().GetJulianDate();
4232 printf("wxDateTime for today: %s\n",
4233 wxDateTime((double)(jdnMidnight + 0.5)).Format("%c", wxDateTime::GMT0).c_str());
4234
4235 int flags = wxEUROPEAN;//wxFULL;
4236 wxDate date;
4237 date.Set();
4238 printf("Today is %s\n", date.FormatDate(flags).c_str());
4239 for ( int n = 0; n < 7; n++ )
4240 {
4241 printf("Previous %s is %s\n",
4242 wxDateTime::GetWeekDayName((wxDateTime::WeekDay)n),
4243 date.Previous(n + 1).FormatDate(flags).c_str());
4244 }
4245}
4246
68ee7c47
VZ
4247#endif // 0
4248
d31b7b68 4249#endif // TEST_DATETIME
b76b015e 4250
e87271f3
VZ
4251// ----------------------------------------------------------------------------
4252// threads
4253// ----------------------------------------------------------------------------
4254
4255#ifdef TEST_THREADS
4256
e84010cf 4257#include "wx/thread.h"
37667812 4258
bbfa0322
VZ
4259static size_t gs_counter = (size_t)-1;
4260static wxCriticalSection gs_critsect;
b568d04f 4261static wxCondition gs_cond;
bbfa0322 4262
b568d04f 4263class MyJoinableThread : public wxThread
bbfa0322
VZ
4264{
4265public:
b568d04f
VZ
4266 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
4267 { m_n = n; Create(); }
bbfa0322
VZ
4268
4269 // thread execution starts here
b568d04f 4270 virtual ExitCode Entry();
bbfa0322 4271
b568d04f
VZ
4272private:
4273 size_t m_n;
bbfa0322
VZ
4274};
4275
b568d04f 4276wxThread::ExitCode MyJoinableThread::Entry()
bbfa0322 4277{
b568d04f
VZ
4278 unsigned long res = 1;
4279 for ( size_t n = 1; n < m_n; n++ )
4280 {
4281 res *= n;
4282
4283 // it's a loooong calculation :-)
4284 Sleep(100);
4285 }
bbfa0322 4286
b568d04f 4287 return (ExitCode)res;
bbfa0322
VZ
4288}
4289
b568d04f
VZ
4290class MyDetachedThread : public wxThread
4291{
4292public:
fcc3d7cb
VZ
4293 MyDetachedThread(size_t n, char ch)
4294 {
4295 m_n = n;
4296 m_ch = ch;
4297 m_cancelled = FALSE;
4298
4299 Create();
4300 }
b568d04f
VZ
4301
4302 // thread execution starts here
4303 virtual ExitCode Entry();
4304
4305 // and stops here
4306 virtual void OnExit();
4307
4308private:
9fc3ad34
VZ
4309 size_t m_n; // number of characters to write
4310 char m_ch; // character to write
fcc3d7cb
VZ
4311
4312 bool m_cancelled; // FALSE if we exit normally
b568d04f
VZ
4313};
4314
4315wxThread::ExitCode MyDetachedThread::Entry()
bbfa0322
VZ
4316{
4317 {
4318 wxCriticalSectionLocker lock(gs_critsect);
4319 if ( gs_counter == (size_t)-1 )
4320 gs_counter = 1;
4321 else
4322 gs_counter++;
4323 }
4324
9fc3ad34 4325 for ( size_t n = 0; n < m_n; n++ )
bbfa0322
VZ
4326 {
4327 if ( TestDestroy() )
fcc3d7cb
VZ
4328 {
4329 m_cancelled = TRUE;
4330
bbfa0322 4331 break;
fcc3d7cb 4332 }
bbfa0322
VZ
4333
4334 putchar(m_ch);
4335 fflush(stdout);
4336
4337 wxThread::Sleep(100);
4338 }
4339
b568d04f 4340 return 0;
bbfa0322
VZ
4341}
4342
b568d04f 4343void MyDetachedThread::OnExit()
bbfa0322 4344{
9fc3ad34
VZ
4345 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
4346
bbfa0322 4347 wxCriticalSectionLocker lock(gs_critsect);
fcc3d7cb 4348 if ( !--gs_counter && !m_cancelled )
b568d04f 4349 gs_cond.Signal();
bbfa0322
VZ
4350}
4351
9fc3ad34
VZ
4352void TestDetachedThreads()
4353{
2f02cb89 4354 puts("\n*** Testing detached threads ***");
9fc3ad34
VZ
4355
4356 static const size_t nThreads = 3;
4357 MyDetachedThread *threads[nThreads];
4358 size_t n;
4359 for ( n = 0; n < nThreads; n++ )
4360 {
4361 threads[n] = new MyDetachedThread(10, 'A' + n);
4362 }
4363
4364 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
4365 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
4366
4367 for ( n = 0; n < nThreads; n++ )
4368 {
4369 threads[n]->Run();
4370 }
4371
4372 // wait until all threads terminate
4373 gs_cond.Wait();
4374
4375 puts("");
4376}
4377
4378void TestJoinableThreads()
4379{
2f02cb89 4380 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
9fc3ad34
VZ
4381
4382 // calc 10! in the background
4383 MyJoinableThread thread(10);
4384 thread.Run();
4385
4386 printf("\nThread terminated with exit code %lu.\n",
4387 (unsigned long)thread.Wait());
4388}
4389
4390void TestThreadSuspend()
4391{
2f02cb89
VZ
4392 puts("\n*** Testing thread suspend/resume functions ***");
4393
4394 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
9fc3ad34
VZ
4395
4396 thread->Run();
4397
4398 // this is for this demo only, in a real life program we'd use another
4399 // condition variable which would be signaled from wxThread::Entry() to
4400 // tell us that the thread really started running - but here just wait a
4401 // bit and hope that it will be enough (the problem is, of course, that
4402 // the thread might still not run when we call Pause() which will result
4403 // in an error)
4404 wxThread::Sleep(300);
4405
4406 for ( size_t n = 0; n < 3; n++ )
4407 {
4408 thread->Pause();
4409
4410 puts("\nThread suspended");
4411 if ( n > 0 )
4412 {
4413 // don't sleep but resume immediately the first time
4414 wxThread::Sleep(300);
4415 }
4416 puts("Going to resume the thread");
4417
4418 thread->Resume();
4419 }
4420
4c460b34
VZ
4421 puts("Waiting until it terminates now");
4422
9fc3ad34
VZ
4423 // wait until the thread terminates
4424 gs_cond.Wait();
4425
4426 puts("");
4427}
4428
2f02cb89
VZ
4429void TestThreadDelete()
4430{
4431 // As above, using Sleep() is only for testing here - we must use some
4432 // synchronisation object instead to ensure that the thread is still
4433 // running when we delete it - deleting a detached thread which already
4434 // terminated will lead to a crash!
4435
4436 puts("\n*** Testing thread delete function ***");
4437
4c460b34
VZ
4438 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
4439
4440 thread0->Delete();
4441
4442 puts("\nDeleted a thread which didn't start to run yet.");
4443
2f02cb89
VZ
4444 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
4445
4446 thread1->Run();
4447
4448 wxThread::Sleep(300);
4449
4450 thread1->Delete();
4451
4452 puts("\nDeleted a running thread.");
4453
4454 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
4455
4456 thread2->Run();
4457
4458 wxThread::Sleep(300);
4459
4460 thread2->Pause();
4461
4462 thread2->Delete();
4463
4464 puts("\nDeleted a sleeping thread.");
4465
4c460b34
VZ
4466 MyJoinableThread thread3(20);
4467 thread3.Run();
2f02cb89 4468
4c460b34 4469 thread3.Delete();
2f02cb89
VZ
4470
4471 puts("\nDeleted a joinable thread.");
4472
4c460b34
VZ
4473 MyJoinableThread thread4(2);
4474 thread4.Run();
2f02cb89
VZ
4475
4476 wxThread::Sleep(300);
4477
4c460b34 4478 thread4.Delete();
2f02cb89
VZ
4479
4480 puts("\nDeleted a joinable thread which already terminated.");
4481
4482 puts("");
4483}
4484
e87271f3
VZ
4485#endif // TEST_THREADS
4486
4487// ----------------------------------------------------------------------------
4488// arrays
4489// ----------------------------------------------------------------------------
4490
4491#ifdef TEST_ARRAYS
4492
f6bcfd97 4493static void PrintArray(const char* name, const wxArrayString& array)
e87271f3
VZ
4494{
4495 printf("Dump of the array '%s'\n", name);
4496
4497 size_t nCount = array.GetCount();
4498 for ( size_t n = 0; n < nCount; n++ )
4499 {
4500 printf("\t%s[%u] = '%s'\n", name, n, array[n].c_str());
4501 }
4502}
4503
d6c9c1b7
VZ
4504static void PrintArray(const char* name, const wxArrayInt& array)
4505{
4506 printf("Dump of the array '%s'\n", name);
4507
4508 size_t nCount = array.GetCount();
4509 for ( size_t n = 0; n < nCount; n++ )
4510 {
4511 printf("\t%s[%u] = %d\n", name, n, array[n]);
4512 }
4513}
4514
4515int wxCMPFUNC_CONV StringLenCompare(const wxString& first,
4516 const wxString& second)
f6bcfd97
BP
4517{
4518 return first.length() - second.length();
4519}
4520
d6c9c1b7
VZ
4521int wxCMPFUNC_CONV IntCompare(int *first,
4522 int *second)
4523{
4524 return *first - *second;
4525}
4526
4527int wxCMPFUNC_CONV IntRevCompare(int *first,
4528 int *second)
4529{
4530 return *second - *first;
4531}
4532
4533static void TestArrayOfInts()
4534{
4535 puts("*** Testing wxArrayInt ***\n");
4536
4537 wxArrayInt a;
4538 a.Add(1);
4539 a.Add(17);
4540 a.Add(5);
4541 a.Add(3);
4542
4543 puts("Initially:");
4544 PrintArray("a", a);
4545
4546 puts("After sort:");
4547 a.Sort(IntCompare);
4548 PrintArray("a", a);
4549
4550 puts("After reverse sort:");
4551 a.Sort(IntRevCompare);
4552 PrintArray("a", a);
4553}
4554
f6bcfd97
BP
4555#include "wx/dynarray.h"
4556
4557WX_DECLARE_OBJARRAY(Bar, ArrayBars);
4558#include "wx/arrimpl.cpp"
4559WX_DEFINE_OBJARRAY(ArrayBars);
4560
4561static void TestArrayOfObjects()
4562{
4563 puts("*** Testing wxObjArray ***\n");
4564
4565 {
4566 ArrayBars bars;
4567 Bar bar("second bar");
4568
4569 printf("Initially: %u objects in the array, %u objects total.\n",
4570 bars.GetCount(), Bar::GetNumber());
4571
4572 bars.Add(new Bar("first bar"));
4573 bars.Add(bar);
4574
4575 printf("Now: %u objects in the array, %u objects total.\n",
4576 bars.GetCount(), Bar::GetNumber());
4577
4578 bars.Empty();
4579
4580 printf("After Empty(): %u objects in the array, %u objects total.\n",
4581 bars.GetCount(), Bar::GetNumber());
4582 }
4583
4584 printf("Finally: no more objects in the array, %u objects total.\n",
4585 Bar::GetNumber());
4586}
4587
e87271f3
VZ
4588#endif // TEST_ARRAYS
4589
9fc3ad34
VZ
4590// ----------------------------------------------------------------------------
4591// strings
4592// ----------------------------------------------------------------------------
4593
4594#ifdef TEST_STRINGS
4595
4596#include "wx/timer.h"
bbf8fc53 4597#include "wx/tokenzr.h"
9fc3ad34 4598
7c968cee
VZ
4599static void TestStringConstruction()
4600{
4601 puts("*** Testing wxString constructores ***");
4602
4603 #define TEST_CTOR(args, res) \
4604 { \
4605 wxString s args ; \
4606 printf("wxString%s = %s ", #args, s.c_str()); \
4607 if ( s == res ) \
4608 { \
4609 puts("(ok)"); \
4610 } \
4611 else \
4612 { \
4613 printf("(ERROR: should be %s)\n", res); \
4614 } \
4615 }
4616
4617 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
4618 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
4619 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
4620 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
4621
4622 static const wxChar *s = _T("?really!");
4623 const wxChar *start = wxStrchr(s, _T('r'));
4624 const wxChar *end = wxStrchr(s, _T('!'));
4625 TEST_CTOR((start, end), _T("really"));
4626
4627 puts("");
4628}
4629
299fcbfe 4630static void TestString()
9fc3ad34
VZ
4631{
4632 wxStopWatch sw;
4633
4634 wxString a, b, c;
4635
4636 a.reserve (128);
4637 b.reserve (128);
4638 c.reserve (128);
4639
4640 for (int i = 0; i < 1000000; ++i)
4641 {
4642 a = "Hello";
4643 b = " world";
4644 c = "! How'ya doin'?";
4645 a += b;
4646 a += c;
4647 c = "Hello world! What's up?";
4648 if (c != a)
4649 c = "Doh!";
4650 }
4651
4652 printf ("TestString elapsed time: %ld\n", sw.Time());
4653}
4654
299fcbfe 4655static void TestPChar()
9fc3ad34
VZ
4656{
4657 wxStopWatch sw;
4658
4659 char a [128];
4660 char b [128];
4661 char c [128];
4662
4663 for (int i = 0; i < 1000000; ++i)
4664 {
4665 strcpy (a, "Hello");
4666 strcpy (b, " world");
4667 strcpy (c, "! How'ya doin'?");
4668 strcat (a, b);
4669 strcat (a, c);
4670 strcpy (c, "Hello world! What's up?");
4671 if (strcmp (c, a) == 0)
4672 strcpy (c, "Doh!");
4673 }
4674
4675 printf ("TestPChar elapsed time: %ld\n", sw.Time());
4676}
4677
299fcbfe
VZ
4678static void TestStringSub()
4679{
4680 wxString s("Hello, world!");
4681
4682 puts("*** Testing wxString substring extraction ***");
4683
4684 printf("String = '%s'\n", s.c_str());
4685 printf("Left(5) = '%s'\n", s.Left(5).c_str());
4686 printf("Right(6) = '%s'\n", s.Right(6).c_str());
4687 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
4688 printf("Mid(3) = '%s'\n", s.Mid(3).c_str());
4689 printf("substr(3, 5) = '%s'\n", s.substr(3, 5).c_str());
4690 printf("substr(3) = '%s'\n", s.substr(3).c_str());
4691
f6bcfd97
BP
4692 static const wxChar *prefixes[] =
4693 {
4694 _T("Hello"),
4695 _T("Hello, "),
4696 _T("Hello, world!"),
4697 _T("Hello, world!!!"),
4698 _T(""),
4699 _T("Goodbye"),
4700 _T("Hi"),
4701 };
4702
4703 for ( size_t n = 0; n < WXSIZEOF(prefixes); n++ )
4704 {
4705 wxString prefix = prefixes[n], rest;
4706 bool rc = s.StartsWith(prefix, &rest);
4707 printf("StartsWith('%s') = %s", prefix.c_str(), rc ? "TRUE" : "FALSE");
4708 if ( rc )
4709 {
4710 printf(" (the rest is '%s')\n", rest.c_str());
4711 }
4712 else
4713 {
4714 putchar('\n');
4715 }
4716 }
4717
299fcbfe
VZ
4718 puts("");
4719}
4720
f0f951fa
VZ
4721static void TestStringFormat()
4722{
4723 puts("*** Testing wxString formatting ***");
4724
4725 wxString s;
4726 s.Printf("%03d", 18);
4727
4728 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
4729 printf("Number 18: %s\n", s.c_str());
4730
4731 puts("");
4732}
4733
d71fa6fb
VZ
4734// returns "not found" for npos, value for all others
4735static wxString PosToString(size_t res)
4736{
4737 wxString s = res == wxString::npos ? wxString(_T("not found"))
4738 : wxString::Format(_T("%u"), res);
4739 return s;
4740}
4741
4742static void TestStringFind()
4743{
4744 puts("*** Testing wxString find() functions ***");
4745
4746 static const wxChar *strToFind = _T("ell");
4747 static const struct StringFindTest
4748 {
4749 const wxChar *str;
4750 size_t start,
4751 result; // of searching "ell" in str
4752 } findTestData[] =
4753 {
4754 { _T("Well, hello world"), 0, 1 },
4755 { _T("Well, hello world"), 6, 7 },
4756 { _T("Well, hello world"), 9, wxString::npos },
4757 };
4758
4759 for ( size_t n = 0; n < WXSIZEOF(findTestData); n++ )
4760 {
4761 const StringFindTest& ft = findTestData[n];
4762 size_t res = wxString(ft.str).find(strToFind, ft.start);
4763
4764 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
4765 strToFind, ft.str, ft.start, PosToString(res).c_str());
4766
4767 size_t resTrue = ft.result;
4768 if ( res == resTrue )
4769 {
4770 puts(_T("(ok)"));
4771 }
4772 else
4773 {
4774 printf(_T("(ERROR: should be %s)\n"),
4775 PosToString(resTrue).c_str());
4776 }
4777 }
4778
4779 puts("");
4780}
4781
bbf8fc53
VZ
4782static void TestStringTokenizer()
4783{
4784 puts("*** Testing wxStringTokenizer ***");
4785
7c968cee
VZ
4786 static const wxChar *modeNames[] =
4787 {
4788 _T("default"),
4789 _T("return empty"),
4790 _T("return all empty"),
4791 _T("with delims"),
4792 _T("like strtok"),
4793 };
4794
bbf8fc53
VZ
4795 static const struct StringTokenizerTest
4796 {
7c968cee
VZ
4797 const wxChar *str; // string to tokenize
4798 const wxChar *delims; // delimiters to use
4799 size_t count; // count of token
4800 wxStringTokenizerMode mode; // how should we tokenize it
4801 } tokenizerTestData[] =
4802 {
4803 { _T(""), _T(" "), 0 },
4804 { _T("Hello, world"), _T(" "), 2 },
4805 { _T("Hello, world "), _T(" "), 2 },
4806 { _T("Hello, world"), _T(","), 2 },
4807 { _T("Hello, world!"), _T(",!"), 2 },
4808 { _T("Hello,, world!"), _T(",!"), 3 },
4809 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL },
4810 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
4811 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 4 },
4812 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 6, wxTOKEN_RET_EMPTY },
4813 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 9, wxTOKEN_RET_EMPTY_ALL },
4814 { _T("01/02/99"), _T("/-"), 3 },
4815 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS },
bbf8fc53
VZ
4816 };
4817
4818 for ( size_t n = 0; n < WXSIZEOF(tokenizerTestData); n++ )
4819 {
4820 const StringTokenizerTest& tt = tokenizerTestData[n];
7c968cee 4821 wxStringTokenizer tkz(tt.str, tt.delims, tt.mode);
bbf8fc53
VZ
4822
4823 size_t count = tkz.CountTokens();
7c968cee
VZ
4824 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
4825 MakePrintable(tt.str).c_str(),
bbf8fc53 4826 count,
7c968cee
VZ
4827 MakePrintable(tt.delims).c_str(),
4828 modeNames[tkz.GetMode()]);
bbf8fc53
VZ
4829 if ( count == tt.count )
4830 {
4831 puts(_T("(ok)"));
4832 }
4833 else
4834 {
4835 printf(_T("(ERROR: should be %u)\n"), tt.count);
4836
4837 continue;
4838 }
4839
7c968cee 4840 // if we emulate strtok(), check that we do it correctly
f6bcfd97 4841 wxChar *buf, *s = NULL, *last;
7c968cee
VZ
4842
4843 if ( tkz.GetMode() == wxTOKEN_STRTOK )
4844 {
4845 buf = new wxChar[wxStrlen(tt.str) + 1];
4846 wxStrcpy(buf, tt.str);
4847
4848 s = wxStrtok(buf, tt.delims, &last);
4849 }
4850 else
4851 {
4852 buf = NULL;
4853 }
4854
bbf8fc53
VZ
4855 // now show the tokens themselves
4856 size_t count2 = 0;
4857 while ( tkz.HasMoreTokens() )
4858 {
7c968cee
VZ
4859 wxString token = tkz.GetNextToken();
4860
4861 printf(_T("\ttoken %u: '%s'"),
bbf8fc53 4862 ++count2,
7c968cee
VZ
4863 MakePrintable(token).c_str());
4864
4865 if ( buf )
4866 {
4867 if ( token == s )
4868 {
4869 puts(" (ok)");
4870 }
4871 else
4872 {
4873 printf(" (ERROR: should be %s)\n", s);
4874 }
4875
4876 s = wxStrtok(NULL, tt.delims, &last);
4877 }
4878 else
4879 {
4880 // nothing to compare with
4881 puts("");
4882 }
bbf8fc53
VZ
4883 }
4884
4885 if ( count2 != count )
4886 {
7c968cee 4887 puts(_T("\tERROR: token count mismatch"));
bbf8fc53 4888 }
7c968cee
VZ
4889
4890 delete [] buf;
bbf8fc53
VZ
4891 }
4892
4893 puts("");
4894}
4895
f6bcfd97
BP
4896static void TestStringReplace()
4897{
4898 puts("*** Testing wxString::replace ***");
4899
4900 static const struct StringReplaceTestData
4901 {
4902 const wxChar *original; // original test string
4903 size_t start, len; // the part to replace
4904 const wxChar *replacement; // the replacement string
4905 const wxChar *result; // and the expected result
4906 } stringReplaceTestData[] =
4907 {
4908 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
4909 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
4910 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
4911 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
4912 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
4913 };
4914
4915 for ( size_t n = 0; n < WXSIZEOF(stringReplaceTestData); n++ )
4916 {
4917 const StringReplaceTestData data = stringReplaceTestData[n];
4918
4919 wxString original = data.original;
4920 original.replace(data.start, data.len, data.replacement);
4921
4922 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
4923 data.original, data.start, data.len, data.replacement,
4924 original.c_str());
4925
4926 if ( original == data.result )
4927 {
4928 puts("(ok)");
4929 }
4930 else
4931 {
4932 wxPrintf(_T("(ERROR: should be '%s')\n"), data.result);
4933 }
4934 }
4935
4936 puts("");
4937}
4938
9a4232dc
VZ
4939static void TestStringMatch()
4940{
4941 wxPuts(_T("*** Testing wxString::Matches() ***"));
4942
4943 static const struct StringMatchTestData
4944 {
4945 const wxChar *text;
4946 const wxChar *wildcard;
4947 bool matches;
4948 } stringMatchTestData[] =
4949 {
4950 { _T("foobar"), _T("foo*"), 1 },
4951 { _T("foobar"), _T("*oo*"), 1 },
4952 { _T("foobar"), _T("*bar"), 1 },
4953 { _T("foobar"), _T("??????"), 1 },
4954 { _T("foobar"), _T("f??b*"), 1 },
4955 { _T("foobar"), _T("f?b*"), 0 },
4956 { _T("foobar"), _T("*goo*"), 0 },
4957 { _T("foobar"), _T("*foo"), 0 },
4958 { _T("foobarfoo"), _T("*foo"), 1 },
4959 { _T(""), _T("*"), 1 },
4960 { _T(""), _T("?"), 0 },
4961 };
4962
4963 for ( size_t n = 0; n < WXSIZEOF(stringMatchTestData); n++ )
4964 {
4965 const StringMatchTestData& data = stringMatchTestData[n];
4966 bool matches = wxString(data.text).Matches(data.wildcard);
4967 wxPrintf(_T("'%s' %s '%s' (%s)\n"),
4968 data.wildcard,
4969 matches ? _T("matches") : _T("doesn't match"),
4970 data.text,
4971 matches == data.matches ? _T("ok") : _T("ERROR"));
4972 }
4973
4974 wxPuts(_T(""));
4975}
4976
9fc3ad34
VZ
4977#endif // TEST_STRINGS
4978
e87271f3
VZ
4979// ----------------------------------------------------------------------------
4980// entry point
4981// ----------------------------------------------------------------------------
4982
bbfa0322 4983int main(int argc, char **argv)
37667812 4984{
58b24a56
VZ
4985 wxInitializer initializer;
4986 if ( !initializer )
37667812
VZ
4987 {
4988 fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
58b24a56
VZ
4989
4990 return -1;
4991 }
4992
4993#ifdef TEST_SNGLINST
b5299791
VZ
4994 wxSingleInstanceChecker checker;
4995 if ( checker.Create(_T(".wxconsole.lock")) )
58b24a56 4996 {
b5299791
VZ
4997 if ( checker.IsAnotherRunning() )
4998 {
4999 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
58b24a56 5000
b5299791
VZ
5001 return 1;
5002 }
37667812 5003
b5299791
VZ
5004 // wait some time to give time to launch another instance
5005 wxPrintf(_T("Press \"Enter\" to continue..."));
5006 wxFgetc(stdin);
5007 }
5008 else // failed to create
5009 {
5010 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
5011 }
58b24a56
VZ
5012#endif // TEST_SNGLINST
5013
551fe3a6
VZ
5014#ifdef TEST_CHARSET
5015 TestCharset();
5016#endif // TEST_CHARSET
0de868d9 5017
d34bce84 5018#ifdef TEST_CMDLINE
31f6de22
VZ
5019 TestCmdLineConvert();
5020
5021#if wxUSE_CMDLINE_PARSER
d34bce84
VZ
5022 static const wxCmdLineEntryDesc cmdLineDesc[] =
5023 {
31a06b07
VZ
5024 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), "show this help message",
5025 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
d34bce84
VZ
5026 { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
5027 { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" },
5028
5029 { wxCMD_LINE_OPTION, "o", "output", "output file" },
5030 { wxCMD_LINE_OPTION, "i", "input", "input dir" },
31a06b07
VZ
5031 { wxCMD_LINE_OPTION, "s", "size", "output block size",
5032 wxCMD_LINE_VAL_NUMBER },
5033 { wxCMD_LINE_OPTION, "d", "date", "output file date",
5034 wxCMD_LINE_VAL_DATE },
d34bce84
VZ
5035
5036 { wxCMD_LINE_PARAM, NULL, NULL, "input file",
5037 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
5038
5039 { wxCMD_LINE_NONE }
5040 };
5041
5042 wxCmdLineParser parser(cmdLineDesc, argc, argv);
5043
f6bcfd97
BP
5044 parser.AddOption("project_name", "", "full path to project file",
5045 wxCMD_LINE_VAL_STRING,
5046 wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);
5047
d34bce84
VZ
5048 switch ( parser.Parse() )
5049 {
5050 case -1:
5051 wxLogMessage("Help was given, terminating.");
5052 break;
5053
5054 case 0:
5055 ShowCmdLine(parser);
5056 break;
5057
5058 default:
5059 wxLogMessage("Syntax error detected, aborting.");
5060 break;
5061 }
31f6de22
VZ
5062#endif // wxUSE_CMDLINE_PARSER
5063
d34bce84
VZ
5064#endif // TEST_CMDLINE
5065
9fc3ad34 5066#ifdef TEST_STRINGS
299fcbfe
VZ
5067 if ( 0 )
5068 {
5069 TestPChar();
5070 TestString();
f6bcfd97 5071 TestStringSub();
7c968cee 5072 TestStringConstruction();
d71fa6fb 5073 TestStringFormat();
bbf8fc53 5074 TestStringFind();
7c968cee 5075 TestStringTokenizer();
f6bcfd97 5076 TestStringReplace();
ee6e1b1d 5077 }
9a4232dc 5078 TestStringMatch();
9fc3ad34
VZ
5079#endif // TEST_STRINGS
5080
e87271f3 5081#ifdef TEST_ARRAYS
d6c9c1b7
VZ
5082 if ( 0 )
5083 {
e87271f3
VZ
5084 wxArrayString a1;
5085 a1.Add("tiger");
5086 a1.Add("cat");
5087 a1.Add("lion");
5088 a1.Add("dog");
5089 a1.Add("human");
5090 a1.Add("ape");
5091
5092 puts("*** Initially:");
5093
5094 PrintArray("a1", a1);
5095
5096 wxArrayString a2(a1);
5097 PrintArray("a2", a2);
5098
5099 wxSortedArrayString a3(a1);
5100 PrintArray("a3", a3);
5101
5102 puts("*** After deleting a string from a1");
5103 a1.Remove(2);
5104
5105 PrintArray("a1", a1);
5106 PrintArray("a2", a2);
5107 PrintArray("a3", a3);
5108
5109 puts("*** After reassigning a1 to a2 and a3");
5110 a3 = a2 = a1;
5111 PrintArray("a2", a2);
5112 PrintArray("a3", a3);
f6bcfd97
BP
5113
5114 puts("*** After sorting a1");
5115 a1.Sort();
5116 PrintArray("a1", a1);
5117
5118 puts("*** After sorting a1 in reverse order");
5119 a1.Sort(TRUE);
5120 PrintArray("a1", a1);
5121
5122 puts("*** After sorting a1 by the string length");
5123 a1.Sort(StringLenCompare);
5124 PrintArray("a1", a1);
5125
5126 TestArrayOfObjects();
d6c9c1b7
VZ
5127 }
5128 TestArrayOfInts();
e87271f3
VZ
5129#endif // TEST_ARRAYS
5130
1944c6bd 5131#ifdef TEST_DIR
35332784
VZ
5132 if ( 0 )
5133 TestDirEnum();
5134 TestDirTraverse();
1944c6bd
VZ
5135#endif // TEST_DIR
5136
f6bcfd97
BP
5137#ifdef TEST_DLLLOADER
5138 TestDllLoad();
5139#endif // TEST_DLLLOADER
5140
8fd0d89b
VZ
5141#ifdef TEST_ENVIRON
5142 TestEnvironment();
5143#endif // TEST_ENVIRON
5144
d93c719a
VZ
5145#ifdef TEST_EXECUTE
5146 TestExecute();
5147#endif // TEST_EXECUTE
5148
ee6e1b1d
VZ
5149#ifdef TEST_FILECONF
5150 TestFileConfRead();
5151#endif // TEST_FILECONF
5152
f6bcfd97
BP
5153#ifdef TEST_LIST
5154 TestListCtor();
5155#endif // TEST_LIST
5156
ec37df57
VZ
5157#ifdef TEST_LOCALE
5158 TestDefaultLang();
5159#endif // TEST_LOCALE
5160
378b05f7
VZ
5161#ifdef TEST_LOG
5162 wxString s;
5163 for ( size_t n = 0; n < 8000; n++ )
5164 {
5165 s << (char)('A' + (n % 26));
5166 }
5167
5168 wxString msg;
5169 msg.Printf("A very very long message: '%s', the end!\n", s.c_str());
5170
5171 // this one shouldn't be truncated
5172 printf(msg);
5173
5174 // but this one will because log functions use fixed size buffer
b568d04f
VZ
5175 // (note that it doesn't need '\n' at the end neither - will be added
5176 // by wxLog anyhow)
5177 wxLogMessage("A very very long message 2: '%s', the end!", s.c_str());
378b05f7
VZ
5178#endif // TEST_LOG
5179
f6bcfd97 5180#ifdef TEST_FILE
3ca6a5f0 5181 if ( 0 )
a339970a 5182 {
3ca6a5f0 5183 TestFileRead();
a339970a
VZ
5184 TestTextFileRead();
5185 }
5186 TestFileCopy();
f6bcfd97
BP
5187#endif // TEST_FILE
5188
844f90fb 5189#ifdef TEST_FILENAME
a874db92 5190 TestFileNameConstruction();
42b1f941 5191 TestFileNameSplit();
9e8d8607
VZ
5192 if ( 0 )
5193 {
5194 TestFileNameCwd();
5195 TestFileNameComparison();
5196 TestFileNameOperations();
5197 }
844f90fb
VZ
5198#endif // TEST_FILENAME
5199
d56e2b97
VZ
5200#ifdef TEST_FILETIME
5201 TestFileGetTimes();
5202 TestFileSetTimes();
5203#endif // TEST_FILETIME
5204
07a56e45
VZ
5205#ifdef TEST_FTP
5206 wxLog::AddTraceMask(FTP_TRACE_MASK);
5207 if ( TestFtpConnect() )
5208 {
5209 TestFtpFileSize();
5210 if ( 0 )
5211 {
5212 TestFtpList();
5213 TestFtpDownload();
5214 TestFtpMisc();
5215 TestFtpUpload();
5216 }
5217 if ( 0 )
5218 TestFtpInteractive();
5219 }
5220 //else: connecting to the FTP server failed
5221
5222 if ( 0 )
5223 TestFtpWuFtpd();
5224#endif // TEST_FTP
5225
e87271f3 5226#ifdef TEST_THREADS
696e1ea0
VZ
5227 int nCPUs = wxThread::GetCPUCount();
5228 printf("This system has %d CPUs\n", nCPUs);
5229 if ( nCPUs != -1 )
5230 wxThread::SetConcurrency(nCPUs);
ef8d96c2 5231
9fc3ad34
VZ
5232 if ( argc > 1 && argv[1][0] == 't' )
5233 wxLog::AddTraceMask("thread");
b568d04f 5234
4c460b34 5235 if ( 1 )
2f02cb89 5236 TestDetachedThreads();
4c460b34 5237 if ( 1 )
2f02cb89 5238 TestJoinableThreads();
4c460b34 5239 if ( 1 )
2f02cb89
VZ
5240 TestThreadSuspend();
5241 if ( 1 )
5242 TestThreadDelete();
5243
e87271f3 5244#endif // TEST_THREADS
37667812 5245
b76b015e 5246#ifdef TEST_LONGLONG
2a310492
VZ
5247 // seed pseudo random generator
5248 srand((unsigned)time(NULL));
5249
b76b015e 5250 if ( 0 )
2a310492 5251 {
b76b015e 5252 TestSpeed();
2a310492 5253 }
2a310492
VZ
5254 if ( 0 )
5255 {
f6bcfd97 5256 TestMultiplication();
b76b015e 5257 TestDivision();
2a310492
VZ
5258 TestAddition();
5259 TestLongLongConversion();
5260 TestBitOperations();
3a994742 5261 TestLongLongComparison();
2a310492 5262 }
3a994742 5263 TestLongLongPrint();
b76b015e
VZ
5264#endif // TEST_LONGLONG
5265
2c8e4738
VZ
5266#ifdef TEST_HASH
5267 TestHash();
5268#endif // TEST_HASH
5269
696e1ea0 5270#ifdef TEST_MIME
f6bcfd97 5271 wxLog::AddTraceMask(_T("mime"));
a6c65e88 5272 if ( 1 )
c7ce8392 5273 {
f6bcfd97 5274 TestMimeEnum();
c7ce8392
VZ
5275 TestMimeOverride();
5276 TestMimeFilename();
5277 }
a6c65e88
VZ
5278 else
5279 TestMimeAssociate();
696e1ea0
VZ
5280#endif // TEST_MIME
5281
89e60357 5282#ifdef TEST_INFO_FUNCTIONS
3a994742
VZ
5283 TestDiskInfo();
5284 if ( 0 )
5285 {
5286 TestOsInfo();
5287 TestUserInfo();
5288 }
89e60357
VZ
5289#endif // TEST_INFO_FUNCTIONS
5290
39189b9d
VZ
5291#ifdef TEST_PATHLIST
5292 TestPathList();
5293#endif // TEST_PATHLIST
5294
7ba4fbeb
VZ
5295#ifdef TEST_REGCONF
5296 TestRegConfWrite();
5297#endif // TEST_REGCONF
5298
07a56e45
VZ
5299#ifdef TEST_REGEX
5300 // TODO: write a real test using src/regex/tests file
5301 if ( 0 )
5302 {
5303 TestRegExCompile();
5304 TestRegExMatch();
5305 TestRegExSubmatch();
765624f7 5306 TestRegExInteractive();
07a56e45 5307 }
765624f7 5308 TestRegExReplacement();
07a56e45
VZ
5309#endif // TEST_REGEX
5310
6dfec4b8 5311#ifdef TEST_REGISTRY
6ba63600
VZ
5312 if ( 0 )
5313 TestRegistryRead();
5314 TestRegistryAssociation();
6dfec4b8
VZ
5315#endif // TEST_REGISTRY
5316
2c8e4738 5317#ifdef TEST_SOCKETS
ccdb23df 5318 if ( 0 )
8e907a13 5319 {
f6bcfd97 5320 TestSocketServer();
8dfea369 5321 }
2e907fab 5322 TestSocketClient();
2c8e4738
VZ
5323#endif // TEST_SOCKETS
5324
83141d3a 5325#ifdef TEST_STREAMS
24f25c8a
VZ
5326 if ( 0 )
5327 TestFileStream();
83141d3a
VZ
5328 TestMemoryStream();
5329#endif // TEST_STREAMS
5330
d31b7b68
VZ
5331#ifdef TEST_TIMER
5332 TestStopWatch();
5333#endif // TEST_TIMER
5334
5335#ifdef TEST_DATETIME
df05cdc5 5336 if ( 0 )
299fcbfe 5337 {
9d9b7755
VZ
5338 TestTimeSet();
5339 TestTimeStatic();
5340 TestTimeRange();
5341 TestTimeZones();
5342 TestTimeTicks();
5343 TestTimeJDN();
5344 TestTimeDST();
5345 TestTimeWDays();
5346 TestTimeWNumber();
5347 TestTimeParse();
9d9b7755 5348 TestTimeArithmetics();
f6bcfd97
BP
5349 TestTimeHolidays();
5350 TestTimeFormat();
3ca6a5f0 5351 TestTimeMS();
f6bcfd97
BP
5352
5353 TestTimeZoneBug();
41acf5c0 5354 }
df05cdc5 5355 TestTimeSpanFormat();
9d9b7755 5356 if ( 0 )
b92fd37c 5357 TestDateTimeInteractive();
d31b7b68 5358#endif // TEST_DATETIME
b76b015e 5359
551fe3a6
VZ
5360#ifdef TEST_USLEEP
5361 puts("Sleeping for 3 seconds... z-z-z-z-z...");
5362 wxUsleep(3000);
5363#endif // TEST_USLEEP
5364
f6bcfd97
BP
5365#ifdef TEST_VCARD
5366 if ( 0 )
5367 TestVCardRead();
5368 TestVCardWrite();
5369#endif // TEST_VCARD
5370
5371#ifdef TEST_WCHAR
5372 TestUtf8();
5373#endif // TEST_WCHAR
5374
5375#ifdef TEST_ZIP
2ca8b884
VZ
5376 if ( 0 )
5377 TestZipStreamRead();
5378 TestZipFileSystem();
f6bcfd97
BP
5379#endif // TEST_ZIP
5380
3ca6a5f0
BP
5381#ifdef TEST_ZLIB
5382 if ( 0 )
5383 TestZlibStreamWrite();
5384 TestZlibStreamRead();
5385#endif // TEST_ZLIB
5386
37667812
VZ
5387 return 0;
5388}
f6bcfd97 5389