]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
1. some more tests in console
[wxWidgets.git] / samples / console / console.cpp
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
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include <stdio.h>
21
22 #include <wx/string.h>
23 #include <wx/file.h>
24 #include <wx/app.h>
25
26 // without this pragma, the stupid compiler precompiles #defines below so that
27 // changing them doesn't "take place" later!
28 #ifdef __VISUALC__
29 #pragma hdrstop
30 #endif
31
32 // ----------------------------------------------------------------------------
33 // conditional compilation
34 // ----------------------------------------------------------------------------
35
36 // what to test (in alphabetic order)?
37
38 //#define TEST_ARRAYS
39 //#define TEST_CMDLINE
40 //#define TEST_DATETIME
41 //#define TEST_DIR
42 //#define TEST_DLLLOADER
43 //#define TEST_EXECUTE
44 //#define TEST_FILE
45 //#define TEST_FILECONF
46 //#define TEST_HASH
47 //#define TEST_LIST
48 //#define TEST_LOG
49 //#define TEST_LONGLONG
50 //#define TEST_MIME
51 //#define TEST_INFO_FUNCTIONS
52 #define TEST_REGISTRY
53 //#define TEST_SOCKETS
54 //#define TEST_STREAMS
55 //#define TEST_STRINGS
56 //#define TEST_THREADS
57 //#define TEST_TIMER
58 //#define TEST_VCARD -- don't enable this (VZ)
59 //#define TEST_WCHAR
60 //#define TEST_ZIP
61 //#define TEST_ZLIB
62
63 // ----------------------------------------------------------------------------
64 // test class for container objects
65 // ----------------------------------------------------------------------------
66
67 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
68
69 class Bar // Foo is already taken in the hash test
70 {
71 public:
72 Bar(const wxString& name) : m_name(name) { ms_bars++; }
73 ~Bar() { ms_bars--; }
74
75 static size_t GetNumber() { return ms_bars; }
76
77 const char *GetName() const { return m_name; }
78
79 private:
80 wxString m_name;
81
82 static size_t ms_bars;
83 };
84
85 size_t Bar::ms_bars = 0;
86
87 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
88
89 // ============================================================================
90 // implementation
91 // ============================================================================
92
93 // ----------------------------------------------------------------------------
94 // helper functions
95 // ----------------------------------------------------------------------------
96
97 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
98
99 // replace TABs with \t and CRs with \n
100 static wxString MakePrintable(const wxChar *s)
101 {
102 wxString str(s);
103 (void)str.Replace(_T("\t"), _T("\\t"));
104 (void)str.Replace(_T("\n"), _T("\\n"));
105 (void)str.Replace(_T("\r"), _T("\\r"));
106
107 return str;
108 }
109
110 #endif // MakePrintable() is used
111
112 // ----------------------------------------------------------------------------
113 // wxCmdLineParser
114 // ----------------------------------------------------------------------------
115
116 #ifdef TEST_CMDLINE
117
118 #include <wx/cmdline.h>
119 #include <wx/datetime.h>
120
121 static void ShowCmdLine(const wxCmdLineParser& parser)
122 {
123 wxString s = "Input files: ";
124
125 size_t count = parser.GetParamCount();
126 for ( size_t param = 0; param < count; param++ )
127 {
128 s << parser.GetParam(param) << ' ';
129 }
130
131 s << '\n'
132 << "Verbose:\t" << (parser.Found("v") ? "yes" : "no") << '\n'
133 << "Quiet:\t" << (parser.Found("q") ? "yes" : "no") << '\n';
134
135 wxString strVal;
136 long lVal;
137 wxDateTime dt;
138 if ( parser.Found("o", &strVal) )
139 s << "Output file:\t" << strVal << '\n';
140 if ( parser.Found("i", &strVal) )
141 s << "Input dir:\t" << strVal << '\n';
142 if ( parser.Found("s", &lVal) )
143 s << "Size:\t" << lVal << '\n';
144 if ( parser.Found("d", &dt) )
145 s << "Date:\t" << dt.FormatISODate() << '\n';
146 if ( parser.Found("project_name", &strVal) )
147 s << "Project:\t" << strVal << '\n';
148
149 wxLogMessage(s);
150 }
151
152 #endif // TEST_CMDLINE
153
154 // ----------------------------------------------------------------------------
155 // wxDir
156 // ----------------------------------------------------------------------------
157
158 #ifdef TEST_DIR
159
160 #include <wx/dir.h>
161
162 static void TestDirEnumHelper(wxDir& dir,
163 int flags = wxDIR_DEFAULT,
164 const wxString& filespec = wxEmptyString)
165 {
166 wxString filename;
167
168 if ( !dir.IsOpened() )
169 return;
170
171 bool cont = dir.GetFirst(&filename, filespec, flags);
172 while ( cont )
173 {
174 printf("\t%s\n", filename.c_str());
175
176 cont = dir.GetNext(&filename);
177 }
178
179 puts("");
180 }
181
182 static void TestDirEnum()
183 {
184 wxDir dir(wxGetCwd());
185
186 puts("Enumerating everything in current directory:");
187 TestDirEnumHelper(dir);
188
189 puts("Enumerating really everything in current directory:");
190 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
191
192 puts("Enumerating object files in current directory:");
193 TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o");
194
195 puts("Enumerating directories in current directory:");
196 TestDirEnumHelper(dir, wxDIR_DIRS);
197
198 puts("Enumerating files in current directory:");
199 TestDirEnumHelper(dir, wxDIR_FILES);
200
201 puts("Enumerating files including hidden in current directory:");
202 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
203
204 #ifdef __UNIX__
205 dir.Open("/");
206 #elif defined(__WXMSW__)
207 dir.Open("c:\\");
208 #else
209 #error "don't know where the root directory is"
210 #endif
211
212 puts("Enumerating everything in root directory:");
213 TestDirEnumHelper(dir, wxDIR_DEFAULT);
214
215 puts("Enumerating directories in root directory:");
216 TestDirEnumHelper(dir, wxDIR_DIRS);
217
218 puts("Enumerating files in root directory:");
219 TestDirEnumHelper(dir, wxDIR_FILES);
220
221 puts("Enumerating files including hidden in root directory:");
222 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
223
224 puts("Enumerating files in non existing directory:");
225 wxDir dirNo("nosuchdir");
226 TestDirEnumHelper(dirNo);
227 }
228
229 #endif // TEST_DIR
230
231 // ----------------------------------------------------------------------------
232 // wxDllLoader
233 // ----------------------------------------------------------------------------
234
235 #ifdef TEST_DLLLOADER
236
237 #include <wx/dynlib.h>
238
239 static void TestDllLoad()
240 {
241 #if defined(__WXMSW__)
242 static const wxChar *LIB_NAME = _T("kernel32.dll");
243 static const wxChar *FUNC_NAME = _T("lstrlenA");
244 #elif defined(__UNIX__)
245 // weird: using just libc.so does *not* work!
246 static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
247 static const wxChar *FUNC_NAME = _T("strlen");
248 #else
249 #error "don't know how to test wxDllLoader on this platform"
250 #endif
251
252 puts("*** testing wxDllLoader ***\n");
253
254 wxDllType dllHandle = wxDllLoader::LoadLibrary(LIB_NAME);
255 if ( !dllHandle )
256 {
257 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME);
258 }
259 else
260 {
261 typedef int (*strlenType)(char *);
262 strlenType pfnStrlen = (strlenType)wxDllLoader::GetSymbol(dllHandle, FUNC_NAME);
263 if ( !pfnStrlen )
264 {
265 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
266 FUNC_NAME, LIB_NAME);
267 }
268 else
269 {
270 if ( pfnStrlen("foo") != 3 )
271 {
272 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
273 }
274 else
275 {
276 puts("... ok");
277 }
278 }
279
280 wxDllLoader::UnloadLibrary(dllHandle);
281 }
282 }
283
284 #endif // TEST_DLLLOADER
285
286 // ----------------------------------------------------------------------------
287 // wxExecute
288 // ----------------------------------------------------------------------------
289
290 #ifdef TEST_EXECUTE
291
292 #include <wx/utils.h>
293
294 static void TestExecute()
295 {
296 puts("*** testing wxExecute ***");
297
298 #ifdef __UNIX__
299 #define COMMAND "echo hi"
300 #define SHELL_COMMAND "echo hi from shell"
301 #define REDIRECT_COMMAND "date"
302 #elif defined(__WXMSW__)
303 #define COMMAND "command.com -c 'echo hi'"
304 #define SHELL_COMMAND "echo hi"
305 #define REDIRECT_COMMAND COMMAND
306 #else
307 #error "no command to exec"
308 #endif // OS
309
310 printf("Testing wxShell: ");
311 fflush(stdout);
312 if ( wxShell(SHELL_COMMAND) )
313 puts("Ok.");
314 else
315 puts("ERROR.");
316
317 printf("Testing wxExecute: ");
318 fflush(stdout);
319 if ( wxExecute(COMMAND, TRUE /* sync */) == 0 )
320 puts("Ok.");
321 else
322 puts("ERROR.");
323
324 #if 0 // no, it doesn't work (yet?)
325 printf("Testing async wxExecute: ");
326 fflush(stdout);
327 if ( wxExecute(COMMAND) != 0 )
328 puts("Ok (command launched).");
329 else
330 puts("ERROR.");
331 #endif // 0
332
333 printf("Testing wxExecute with redirection:\n");
334 wxArrayString output;
335 if ( wxExecute(REDIRECT_COMMAND, output) != 0 )
336 {
337 puts("ERROR.");
338 }
339 else
340 {
341 size_t count = output.GetCount();
342 for ( size_t n = 0; n < count; n++ )
343 {
344 printf("\t%s\n", output[n].c_str());
345 }
346
347 puts("Ok.");
348 }
349 }
350
351 #endif // TEST_EXECUTE
352
353 // ----------------------------------------------------------------------------
354 // file
355 // ----------------------------------------------------------------------------
356
357 #ifdef TEST_FILE
358
359 #include <wx/file.h>
360 #include <wx/textfile.h>
361
362 static void TestFileRead()
363 {
364 puts("*** wxFile read test ***");
365
366 wxFile file(_T("testdata.fc"));
367 if ( file.IsOpened() )
368 {
369 printf("File length: %lu\n", file.Length());
370
371 puts("File dump:\n----------");
372
373 static const off_t len = 1024;
374 char buf[len];
375 for ( ;; )
376 {
377 off_t nRead = file.Read(buf, len);
378 if ( nRead == wxInvalidOffset )
379 {
380 printf("Failed to read the file.");
381 break;
382 }
383
384 fwrite(buf, nRead, 1, stdout);
385
386 if ( nRead < len )
387 break;
388 }
389
390 puts("----------");
391 }
392 else
393 {
394 printf("ERROR: can't open test file.\n");
395 }
396
397 puts("");
398 }
399
400 static void TestTextFileRead()
401 {
402 puts("*** wxTextFile read test ***");
403
404 wxTextFile file(_T("testdata.fc"));
405 if ( file.Open() )
406 {
407 printf("Number of lines: %u\n", file.GetLineCount());
408 printf("Last line: '%s'\n", file.GetLastLine().c_str());
409
410 wxString s;
411
412 puts("\nDumping the entire file:");
413 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
414 {
415 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
416 }
417 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
418
419 puts("\nAnd now backwards:");
420 for ( s = file.GetLastLine();
421 file.GetCurrentLine() != 0;
422 s = file.GetPrevLine() )
423 {
424 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
425 }
426 printf("%6u: %s\n", file.GetCurrentLine() + 1, s.c_str());
427 }
428 else
429 {
430 printf("ERROR: can't open '%s'\n", file.GetName());
431 }
432
433 puts("");
434 }
435
436 #endif // TEST_FILE
437
438 // ----------------------------------------------------------------------------
439 // wxFileConfig
440 // ----------------------------------------------------------------------------
441
442 #ifdef TEST_FILECONF
443
444 #include <wx/confbase.h>
445 #include <wx/fileconf.h>
446
447 static const struct FileConfTestData
448 {
449 const wxChar *name; // value name
450 const wxChar *value; // the value from the file
451 } fcTestData[] =
452 {
453 { _T("value1"), _T("one") },
454 { _T("value2"), _T("two") },
455 { _T("novalue"), _T("default") },
456 };
457
458 static void TestFileConfRead()
459 {
460 puts("*** testing wxFileConfig loading/reading ***");
461
462 wxFileConfig fileconf(_T("test"), wxEmptyString,
463 _T("testdata.fc"), wxEmptyString,
464 wxCONFIG_USE_RELATIVE_PATH);
465
466 // test simple reading
467 puts("\nReading config file:");
468 wxString defValue(_T("default")), value;
469 for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
470 {
471 const FileConfTestData& data = fcTestData[n];
472 value = fileconf.Read(data.name, defValue);
473 printf("\t%s = %s ", data.name, value.c_str());
474 if ( value == data.value )
475 {
476 puts("(ok)");
477 }
478 else
479 {
480 printf("(ERROR: should be %s)\n", data.value);
481 }
482 }
483
484 // test enumerating the entries
485 puts("\nEnumerating all root entries:");
486 long dummy;
487 wxString name;
488 bool cont = fileconf.GetFirstEntry(name, dummy);
489 while ( cont )
490 {
491 printf("\t%s = %s\n",
492 name.c_str(),
493 fileconf.Read(name.c_str(), _T("ERROR")).c_str());
494
495 cont = fileconf.GetNextEntry(name, dummy);
496 }
497 }
498
499 #endif // TEST_FILECONF
500
501 // ----------------------------------------------------------------------------
502 // wxHashTable
503 // ----------------------------------------------------------------------------
504
505 #ifdef TEST_HASH
506
507 #include <wx/hash.h>
508
509 struct Foo
510 {
511 Foo(int n_) { n = n_; count++; }
512 ~Foo() { count--; }
513
514 int n;
515
516 static size_t count;
517 };
518
519 size_t Foo::count = 0;
520
521 WX_DECLARE_LIST(Foo, wxListFoos);
522 WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos);
523
524 #include <wx/listimpl.cpp>
525
526 WX_DEFINE_LIST(wxListFoos);
527
528 static void TestHash()
529 {
530 puts("*** Testing wxHashTable ***\n");
531
532 {
533 wxHashFoos hash;
534 hash.DeleteContents(TRUE);
535
536 printf("Hash created: %u foos in hash, %u foos totally\n",
537 hash.GetCount(), Foo::count);
538
539 static const int hashTestData[] =
540 {
541 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
542 };
543
544 size_t n;
545 for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
546 {
547 hash.Put(hashTestData[n], n, new Foo(n));
548 }
549
550 printf("Hash filled: %u foos in hash, %u foos totally\n",
551 hash.GetCount(), Foo::count);
552
553 puts("Hash access test:");
554 for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
555 {
556 printf("\tGetting element with key %d, value %d: ",
557 hashTestData[n], n);
558 Foo *foo = hash.Get(hashTestData[n], n);
559 if ( !foo )
560 {
561 printf("ERROR, not found.\n");
562 }
563 else
564 {
565 printf("%d (%s)\n", foo->n,
566 (size_t)foo->n == n ? "ok" : "ERROR");
567 }
568 }
569
570 printf("\nTrying to get an element not in hash: ");
571
572 if ( hash.Get(1234) || hash.Get(1, 0) )
573 {
574 puts("ERROR: found!");
575 }
576 else
577 {
578 puts("ok (not found)");
579 }
580 }
581
582 printf("Hash destroyed: %u foos left\n", Foo::count);
583 }
584
585 #endif // TEST_HASH
586
587 // ----------------------------------------------------------------------------
588 // wxList
589 // ----------------------------------------------------------------------------
590
591 #ifdef TEST_LIST
592
593 #include <wx/list.h>
594
595 WX_DECLARE_LIST(Bar, wxListBars);
596 #include <wx/listimpl.cpp>
597 WX_DEFINE_LIST(wxListBars);
598
599 static void TestListCtor()
600 {
601 puts("*** Testing wxList construction ***\n");
602
603 {
604 wxListBars list1;
605 list1.Append(new Bar(_T("first")));
606 list1.Append(new Bar(_T("second")));
607
608 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
609 list1.GetCount(), Bar::GetNumber());
610
611 wxListBars list2;
612 list2 = list1;
613
614 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
615 list1.GetCount(), list2.GetCount(), Bar::GetNumber());
616
617 list1.DeleteContents(TRUE);
618 }
619
620 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
621 }
622
623 #endif // TEST_LIST
624
625 // ----------------------------------------------------------------------------
626 // MIME types
627 // ----------------------------------------------------------------------------
628
629 #ifdef TEST_MIME
630
631 #include <wx/mimetype.h>
632
633 static wxMimeTypesManager g_mimeManager;
634
635 static void TestMimeEnum()
636 {
637 wxArrayString mimetypes;
638
639 size_t count = g_mimeManager.EnumAllFileTypes(mimetypes);
640
641 printf("*** All %u known filetypes: ***\n", count);
642
643 wxArrayString exts;
644 wxString desc;
645
646 for ( size_t n = 0; n < count; n++ )
647 {
648 wxFileType *filetype = g_mimeManager.GetFileTypeFromMimeType(mimetypes[n]);
649 if ( !filetype )
650 {
651 printf("nothing known about the filetype '%s'!\n",
652 mimetypes[n].c_str());
653 continue;
654 }
655
656 filetype->GetDescription(&desc);
657 filetype->GetExtensions(exts);
658
659 filetype->GetIcon(NULL);
660
661 wxString extsAll;
662 for ( size_t e = 0; e < exts.GetCount(); e++ )
663 {
664 if ( e > 0 )
665 extsAll << _T(", ");
666 extsAll += exts[e];
667 }
668
669 printf("\t%s: %s (%s)\n",
670 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
671 }
672 }
673
674 static void TestMimeOverride()
675 {
676 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
677
678 wxString mailcap = _T("/tmp/mailcap"),
679 mimetypes = _T("/tmp/mime.types");
680
681 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
682 mailcap.c_str(),
683 g_mimeManager.ReadMailcap(mailcap) ? _T("ok") : _T("ERROR"));
684 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
685 mimetypes.c_str(),
686 g_mimeManager.ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR"));
687 }
688
689 static void TestMimeFilename()
690 {
691 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
692
693 static const wxChar *filenames[] =
694 {
695 _T("readme.txt"),
696 _T("document.pdf"),
697 _T("image.gif"),
698 };
699
700 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
701 {
702 const wxString fname = filenames[n];
703 wxString ext = fname.AfterLast(_T('.'));
704 wxFileType *ft = g_mimeManager.GetFileTypeFromExtension(ext);
705 if ( !ft )
706 {
707 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str());
708 }
709 else
710 {
711 wxString desc;
712 if ( !ft->GetDescription(&desc) )
713 desc = _T("<no description>");
714
715 wxString cmd;
716 if ( !ft->GetOpenCommand(&cmd,
717 wxFileType::MessageParameters(fname, _T(""))) )
718 cmd = _T("<no command available>");
719
720 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
721 fname.c_str(), desc.c_str(), cmd.c_str());
722
723 delete ft;
724 }
725 }
726 }
727
728 #endif // TEST_MIME
729
730 // ----------------------------------------------------------------------------
731 // misc information functions
732 // ----------------------------------------------------------------------------
733
734 #ifdef TEST_INFO_FUNCTIONS
735
736 #include <wx/utils.h>
737
738 static void TestOsInfo()
739 {
740 puts("*** Testing OS info functions ***\n");
741
742 int major, minor;
743 wxGetOsVersion(&major, &minor);
744 printf("Running under: %s, version %d.%d\n",
745 wxGetOsDescription().c_str(), major, minor);
746
747 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
748
749 printf("Host name is %s (%s).\n",
750 wxGetHostName().c_str(), wxGetFullHostName().c_str());
751
752 puts("");
753 }
754
755 static void TestUserInfo()
756 {
757 puts("*** Testing user info functions ***\n");
758
759 printf("User id is:\t%s\n", wxGetUserId().c_str());
760 printf("User name is:\t%s\n", wxGetUserName().c_str());
761 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
762 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
763
764 puts("");
765 }
766
767 #endif // TEST_INFO_FUNCTIONS
768
769 // ----------------------------------------------------------------------------
770 // long long
771 // ----------------------------------------------------------------------------
772
773 #ifdef TEST_LONGLONG
774
775 #include <wx/longlong.h>
776 #include <wx/timer.h>
777
778 // make a 64 bit number from 4 16 bit ones
779 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
780
781 // get a random 64 bit number
782 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
783
784 #if wxUSE_LONGLONG_WX
785 inline bool operator==(const wxLongLongWx& a, const wxLongLongNative& b)
786 { return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); }
787 inline bool operator==(const wxLongLongNative& a, const wxLongLongWx& b)
788 { return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); }
789 #endif // wxUSE_LONGLONG_WX
790
791 static void TestSpeed()
792 {
793 static const long max = 100000000;
794 long n;
795
796 {
797 wxStopWatch sw;
798
799 long l = 0;
800 for ( n = 0; n < max; n++ )
801 {
802 l += n;
803 }
804
805 printf("Summing longs took %ld milliseconds.\n", sw.Time());
806 }
807
808 #if wxUSE_LONGLONG_NATIVE
809 {
810 wxStopWatch sw;
811
812 wxLongLong_t l = 0;
813 for ( n = 0; n < max; n++ )
814 {
815 l += n;
816 }
817
818 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw.Time());
819 }
820 #endif // wxUSE_LONGLONG_NATIVE
821
822 {
823 wxStopWatch sw;
824
825 wxLongLong l;
826 for ( n = 0; n < max; n++ )
827 {
828 l += n;
829 }
830
831 printf("Summing wxLongLongs took %ld milliseconds.\n", sw.Time());
832 }
833 }
834
835 static void TestLongLongConversion()
836 {
837 puts("*** Testing wxLongLong conversions ***\n");
838
839 wxLongLong a;
840 size_t nTested = 0;
841 for ( size_t n = 0; n < 100000; n++ )
842 {
843 a = RAND_LL();
844
845 #if wxUSE_LONGLONG_NATIVE
846 wxLongLongNative b(a.GetHi(), a.GetLo());
847
848 wxASSERT_MSG( a == b, "conversions failure" );
849 #else
850 puts("Can't do it without native long long type, test skipped.");
851
852 return;
853 #endif // wxUSE_LONGLONG_NATIVE
854
855 if ( !(nTested % 1000) )
856 {
857 putchar('.');
858 fflush(stdout);
859 }
860
861 nTested++;
862 }
863
864 puts(" done!");
865 }
866
867 static void TestMultiplication()
868 {
869 puts("*** Testing wxLongLong multiplication ***\n");
870
871 wxLongLong a, b;
872 size_t nTested = 0;
873 for ( size_t n = 0; n < 100000; n++ )
874 {
875 a = RAND_LL();
876 b = RAND_LL();
877
878 #if wxUSE_LONGLONG_NATIVE
879 wxLongLongNative aa(a.GetHi(), a.GetLo());
880 wxLongLongNative bb(b.GetHi(), b.GetLo());
881
882 wxASSERT_MSG( a*b == aa*bb, "multiplication failure" );
883 #else // !wxUSE_LONGLONG_NATIVE
884 puts("Can't do it without native long long type, test skipped.");
885
886 return;
887 #endif // wxUSE_LONGLONG_NATIVE
888
889 if ( !(nTested % 1000) )
890 {
891 putchar('.');
892 fflush(stdout);
893 }
894
895 nTested++;
896 }
897
898 puts(" done!");
899 }
900
901 static void TestDivision()
902 {
903 puts("*** Testing wxLongLong division ***\n");
904
905 wxLongLong q, r;
906 size_t nTested = 0;
907 for ( size_t n = 0; n < 100000; n++ )
908 {
909 // get a random wxLongLong (shifting by 12 the MSB ensures that the
910 // multiplication will not overflow)
911 wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
912
913 // get a random long (not wxLongLong for now) to divide it with
914 long l = rand();
915 q = ll / l;
916 r = ll % l;
917
918 #if wxUSE_LONGLONG_NATIVE
919 wxLongLongNative m(ll.GetHi(), ll.GetLo());
920
921 wxLongLongNative p = m / l, s = m % l;
922 wxASSERT_MSG( q == p && r == s, "division failure" );
923 #else // !wxUSE_LONGLONG_NATIVE
924 // verify the result
925 wxASSERT_MSG( ll == q*l + r, "division failure" );
926 #endif // wxUSE_LONGLONG_NATIVE
927
928 if ( !(nTested % 1000) )
929 {
930 putchar('.');
931 fflush(stdout);
932 }
933
934 nTested++;
935 }
936
937 puts(" done!");
938 }
939
940 static void TestAddition()
941 {
942 puts("*** Testing wxLongLong addition ***\n");
943
944 wxLongLong a, b, c;
945 size_t nTested = 0;
946 for ( size_t n = 0; n < 100000; n++ )
947 {
948 a = RAND_LL();
949 b = RAND_LL();
950 c = a + b;
951
952 #if wxUSE_LONGLONG_NATIVE
953 wxASSERT_MSG( c == wxLongLongNative(a.GetHi(), a.GetLo()) +
954 wxLongLongNative(b.GetHi(), b.GetLo()),
955 "addition failure" );
956 #else // !wxUSE_LONGLONG_NATIVE
957 wxASSERT_MSG( c - b == a, "addition failure" );
958 #endif // wxUSE_LONGLONG_NATIVE
959
960 if ( !(nTested % 1000) )
961 {
962 putchar('.');
963 fflush(stdout);
964 }
965
966 nTested++;
967 }
968
969 puts(" done!");
970 }
971
972 static void TestBitOperations()
973 {
974 puts("*** Testing wxLongLong bit operation ***\n");
975
976 wxLongLong ll;
977 size_t nTested = 0;
978 for ( size_t n = 0; n < 100000; n++ )
979 {
980 ll = RAND_LL();
981
982 #if wxUSE_LONGLONG_NATIVE
983 for ( size_t n = 0; n < 33; n++ )
984 {
985 }
986 #else // !wxUSE_LONGLONG_NATIVE
987 puts("Can't do it without native long long type, test skipped.");
988
989 return;
990 #endif // wxUSE_LONGLONG_NATIVE
991
992 if ( !(nTested % 1000) )
993 {
994 putchar('.');
995 fflush(stdout);
996 }
997
998 nTested++;
999 }
1000
1001 puts(" done!");
1002 }
1003
1004 static void TestLongLongComparison()
1005 {
1006 puts("*** Testing wxLongLong comparison ***\n");
1007
1008 static const long testLongs[] =
1009 {
1010 0,
1011 1,
1012 -1,
1013 LONG_MAX,
1014 LONG_MIN,
1015 0x1234,
1016 -0x1234
1017 };
1018
1019 static const long ls[2] =
1020 {
1021 0x1234,
1022 -0x1234,
1023 };
1024
1025 wxLongLongWx lls[2];
1026 lls[0] = ls[0];
1027 lls[1] = ls[1];
1028
1029 for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ )
1030 {
1031 bool res;
1032
1033 for ( size_t m = 0; m < WXSIZEOF(lls); m++ )
1034 {
1035 res = lls[m] > testLongs[n];
1036 printf("0x%lx > 0x%lx is %s (%s)\n",
1037 ls[m], testLongs[n], res ? "true" : "false",
1038 res == (ls[m] > testLongs[n]) ? "ok" : "ERROR");
1039
1040 res = lls[m] < testLongs[n];
1041 printf("0x%lx < 0x%lx is %s (%s)\n",
1042 ls[m], testLongs[n], res ? "true" : "false",
1043 res == (ls[m] < testLongs[n]) ? "ok" : "ERROR");
1044
1045 res = lls[m] == testLongs[n];
1046 printf("0x%lx == 0x%lx is %s (%s)\n",
1047 ls[m], testLongs[n], res ? "true" : "false",
1048 res == (ls[m] == testLongs[n]) ? "ok" : "ERROR");
1049 }
1050 }
1051 }
1052
1053 #undef MAKE_LL
1054 #undef RAND_LL
1055
1056 #endif // TEST_LONGLONG
1057
1058 // ----------------------------------------------------------------------------
1059 // registry
1060 // ----------------------------------------------------------------------------
1061
1062 // this is for MSW only
1063 #ifndef __WXMSW__
1064 #undef TEST_REGISTRY
1065 #endif
1066
1067 #ifdef TEST_REGISTRY
1068
1069 #include <wx/msw/registry.h>
1070
1071 // I chose this one because I liked its name, but it probably only exists under
1072 // NT
1073 static const wxChar *TESTKEY =
1074 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1075
1076 static void TestRegistryRead()
1077 {
1078 puts("*** testing registry reading ***");
1079
1080 wxRegKey key(TESTKEY);
1081 printf("The test key name is '%s'.\n", key.GetName().c_str());
1082 if ( !key.Open() )
1083 {
1084 puts("ERROR: test key can't be opened, aborting test.");
1085
1086 return;
1087 }
1088
1089 size_t nSubKeys, nValues;
1090 if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
1091 {
1092 printf("It has %u subkeys and %u values.\n", nSubKeys, nValues);
1093 }
1094
1095 printf("Enumerating values:\n");
1096
1097 long dummy;
1098 wxString value;
1099 bool cont = key.GetFirstValue(value, dummy);
1100 while ( cont )
1101 {
1102 printf("Value '%s': type ", value.c_str());
1103 switch ( key.GetValueType(value) )
1104 {
1105 case wxRegKey::Type_None: printf("ERROR (none)"); break;
1106 case wxRegKey::Type_String: printf("SZ"); break;
1107 case wxRegKey::Type_Expand_String: printf("EXPAND_SZ"); break;
1108 case wxRegKey::Type_Binary: printf("BINARY"); break;
1109 case wxRegKey::Type_Dword: printf("DWORD"); break;
1110 case wxRegKey::Type_Multi_String: printf("MULTI_SZ"); break;
1111 default: printf("other (unknown)"); break;
1112 }
1113
1114 printf(", value = ");
1115 if ( key.IsNumericValue(value) )
1116 {
1117 long val;
1118 key.QueryValue(value, &val);
1119 printf("%ld", val);
1120 }
1121 else // string
1122 {
1123 wxString val;
1124 key.QueryValue(value, val);
1125 printf("'%s'", val.c_str());
1126
1127 key.QueryRawValue(value, val);
1128 printf(" (raw value '%s')", val.c_str());
1129 }
1130
1131 putchar('\n');
1132
1133 cont = key.GetNextValue(value, dummy);
1134 }
1135 }
1136
1137 static void TestRegistryAssociation()
1138 {
1139 /*
1140 The second call to deleteself genertaes an error message, with a
1141 messagebox saying .flo is crucial to system operation, while the .ddf
1142 call also fails, but with no error message
1143 */
1144
1145 wxRegKey key;
1146
1147 key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1148 key.Create();
1149 key = "ddxf_auto_file" ;
1150 key.SetName("HKEY_CLASSES_ROOT\\.flo" );
1151 key.Create();
1152 key = "ddxf_auto_file" ;
1153 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1154 key.Create();
1155 key = "program,0" ;
1156 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1157 key.Create();
1158 key = "program \"%1\"" ;
1159
1160 key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1161 key.DeleteSelf();
1162 key.SetName("HKEY_CLASSES_ROOT\\.flo" );
1163 key.DeleteSelf();
1164 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1165 key.DeleteSelf();
1166 key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1167 key.DeleteSelf();
1168 }
1169
1170 #endif // TEST_REGISTRY
1171
1172 // ----------------------------------------------------------------------------
1173 // sockets
1174 // ----------------------------------------------------------------------------
1175
1176 #ifdef TEST_SOCKETS
1177
1178 #include <wx/socket.h>
1179 #include <wx/protocol/protocol.h>
1180 #include <wx/protocol/ftp.h>
1181 #include <wx/protocol/http.h>
1182
1183 static void TestSocketServer()
1184 {
1185 puts("*** Testing wxSocketServer ***\n");
1186
1187 static const int PORT = 3000;
1188
1189 wxIPV4address addr;
1190 addr.Service(PORT);
1191
1192 wxSocketServer *server = new wxSocketServer(addr);
1193 if ( !server->Ok() )
1194 {
1195 puts("ERROR: failed to bind");
1196
1197 return;
1198 }
1199
1200 for ( ;; )
1201 {
1202 printf("Server: waiting for connection on port %d...\n", PORT);
1203
1204 wxSocketBase *socket = server->Accept();
1205 if ( !socket )
1206 {
1207 puts("ERROR: wxSocketServer::Accept() failed.");
1208 break;
1209 }
1210
1211 puts("Server: got a client.");
1212
1213 server->SetTimeout(60); // 1 min
1214
1215 while ( socket->IsConnected() )
1216 {
1217 wxString s;
1218 char ch = '\0';
1219 for ( ;; )
1220 {
1221 if ( socket->Read(&ch, sizeof(ch)).Error() )
1222 {
1223 // don't log error if the client just close the connection
1224 if ( socket->IsConnected() )
1225 {
1226 puts("ERROR: in wxSocket::Read.");
1227 }
1228
1229 break;
1230 }
1231
1232 if ( ch == '\r' )
1233 continue;
1234
1235 if ( ch == '\n' )
1236 break;
1237
1238 s += ch;
1239 }
1240
1241 if ( ch != '\n' )
1242 {
1243 break;
1244 }
1245
1246 printf("Server: got '%s'.\n", s.c_str());
1247 if ( s == _T("bye") )
1248 {
1249 delete socket;
1250
1251 break;
1252 }
1253
1254 socket->Write(s.MakeUpper().c_str(), s.length());
1255 socket->Write("\r\n", 2);
1256 printf("Server: wrote '%s'.\n", s.c_str());
1257 }
1258
1259 puts("Server: lost a client.");
1260
1261 socket->Destroy();
1262 }
1263
1264 // same as "delete server" but is consistent with GUI programs
1265 server->Destroy();
1266 }
1267
1268 static void TestSocketClient()
1269 {
1270 puts("*** Testing wxSocketClient ***\n");
1271
1272 static const char *hostname = "www.wxwindows.org";
1273
1274 wxIPV4address addr;
1275 addr.Hostname(hostname);
1276 addr.Service(80);
1277
1278 printf("--- Attempting to connect to %s:80...\n", hostname);
1279
1280 wxSocketClient client;
1281 if ( !client.Connect(addr) )
1282 {
1283 printf("ERROR: failed to connect to %s\n", hostname);
1284 }
1285 else
1286 {
1287 printf("--- Connected to %s:%u...\n",
1288 addr.Hostname().c_str(), addr.Service());
1289
1290 char buf[8192];
1291
1292 // could use simply "GET" here I suppose
1293 wxString cmdGet =
1294 wxString::Format("GET http://%s/\r\n", hostname);
1295 client.Write(cmdGet, cmdGet.length());
1296 printf("--- Sent command '%s' to the server\n",
1297 MakePrintable(cmdGet).c_str());
1298 client.Read(buf, WXSIZEOF(buf));
1299 printf("--- Server replied:\n%s", buf);
1300 }
1301 }
1302
1303 static void TestProtocolFtp()
1304 {
1305 puts("*** Testing wxFTP download ***\n");
1306
1307 wxLog::AddTraceMask(_T("ftp"));
1308
1309 static const char *hostname = "ftp.wxwindows.org";
1310
1311 printf("--- Attempting to connect to %s:21...\n", hostname);
1312
1313 wxFTP ftp;
1314 if ( !ftp.Connect(hostname) )
1315 {
1316 printf("ERROR: failed to connect to %s\n", hostname);
1317 }
1318 else
1319 {
1320 printf("--- Connected to %s, current directory is '%s'\n",
1321 hostname, ftp.Pwd().c_str());
1322 if ( !ftp.ChDir(_T("pub")) )
1323 {
1324 puts("ERROR: failed to cd to pub");
1325 }
1326
1327 wxArrayString files;
1328 if ( !ftp.GetList(files) )
1329 {
1330 puts("ERROR: failed to get list of files");
1331 }
1332 else
1333 {
1334 printf("List of files under '%s':\n", ftp.Pwd().c_str());
1335 size_t count = files.GetCount();
1336 for ( size_t n = 0; n < count; n++ )
1337 {
1338 printf("\t%s\n", files[n].c_str());
1339 }
1340 puts("End of the file list");
1341 }
1342
1343 if ( !ftp.ChDir(_T("..")) )
1344 {
1345 puts("ERROR: failed to cd to ..");
1346 }
1347
1348 static const char *filename = "welcome.msg";
1349 wxInputStream *in = ftp.GetInputStream(filename);
1350 if ( !in )
1351 {
1352 puts("ERROR: couldn't get input stream");
1353 }
1354 else
1355 {
1356 size_t size = in->StreamSize();
1357 printf("Reading file %s (%u bytes)...", filename, size);
1358
1359 char *data = new char[size];
1360 if ( !in->Read(data, size) )
1361 {
1362 puts("ERROR: read error");
1363 }
1364 else
1365 {
1366 printf("\nContents of %s:\n%s\n", filename, data);
1367 }
1368
1369 delete [] data;
1370 delete in;
1371 }
1372 }
1373 }
1374
1375 static void TestProtocolFtpUpload()
1376 {
1377 puts("*** Testing wxFTP uploading ***\n");
1378
1379 wxLog::AddTraceMask(_T("ftp"));
1380
1381 static const char *hostname = "localhost";
1382
1383 printf("--- Attempting to connect to %s:21...\n", hostname);
1384
1385 wxFTP ftp;
1386 ftp.SetUser("zeitlin");
1387 ftp.SetPassword("insert your password here");
1388 if ( !ftp.Connect(hostname) )
1389 {
1390 printf("ERROR: failed to connect to %s\n", hostname);
1391 }
1392 else
1393 {
1394 printf("--- Connected to %s, current directory is '%s'\n",
1395 hostname, ftp.Pwd().c_str());
1396
1397 // upload a file
1398 static const char *file1 = "test1";
1399 static const char *file2 = "test2";
1400 wxOutputStream *out = ftp.GetOutputStream(file1);
1401 if ( out )
1402 {
1403 printf("--- Uploading to %s ---\n", file1);
1404 out->Write("First hello", 11);
1405 delete out;
1406 }
1407
1408 out = ftp.GetOutputStream(file2);
1409 if ( out )
1410 {
1411 printf("--- Uploading to %s ---\n", file1);
1412 out->Write("Second hello", 12);
1413 delete out;
1414 }
1415 }
1416 }
1417
1418 #endif // TEST_SOCKETS
1419
1420 // ----------------------------------------------------------------------------
1421 // streams
1422 // ----------------------------------------------------------------------------
1423
1424 #ifdef TEST_STREAMS
1425
1426 #include <wx/mstream.h>
1427
1428 static void TestMemoryStream()
1429 {
1430 puts("*** Testing wxMemoryInputStream ***");
1431
1432 wxChar buf[1024];
1433 wxStrncpy(buf, _T("Hello, stream!"), WXSIZEOF(buf));
1434
1435 wxMemoryInputStream memInpStream(buf, wxStrlen(buf));
1436 printf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
1437 while ( !memInpStream.Eof() )
1438 {
1439 putchar(memInpStream.GetC());
1440 }
1441
1442 puts("\n*** wxMemoryInputStream test done ***");
1443 }
1444
1445 #endif // TEST_STREAMS
1446
1447 // ----------------------------------------------------------------------------
1448 // timers
1449 // ----------------------------------------------------------------------------
1450
1451 #ifdef TEST_TIMER
1452
1453 #include <wx/timer.h>
1454 #include <wx/utils.h>
1455
1456 static void TestStopWatch()
1457 {
1458 puts("*** Testing wxStopWatch ***\n");
1459
1460 wxStopWatch sw;
1461 printf("Sleeping 3 seconds...");
1462 wxSleep(3);
1463 printf("\telapsed time: %ldms\n", sw.Time());
1464
1465 sw.Pause();
1466 printf("Sleeping 2 more seconds...");
1467 wxSleep(2);
1468 printf("\telapsed time: %ldms\n", sw.Time());
1469
1470 sw.Resume();
1471 printf("And 3 more seconds...");
1472 wxSleep(3);
1473 printf("\telapsed time: %ldms\n", sw.Time());
1474
1475 wxStopWatch sw2;
1476 puts("\nChecking for 'backwards clock' bug...");
1477 for ( size_t n = 0; n < 70; n++ )
1478 {
1479 sw2.Start();
1480
1481 for ( size_t m = 0; m < 100000; m++ )
1482 {
1483 if ( sw.Time() < 0 || sw2.Time() < 0 )
1484 {
1485 puts("\ntime is negative - ERROR!");
1486 }
1487 }
1488
1489 putchar('.');
1490 }
1491
1492 puts(", ok.");
1493 }
1494
1495 #endif // TEST_TIMER
1496
1497 // ----------------------------------------------------------------------------
1498 // vCard support
1499 // ----------------------------------------------------------------------------
1500
1501 #ifdef TEST_VCARD
1502
1503 #include <wx/vcard.h>
1504
1505 static void DumpVObject(size_t level, const wxVCardObject& vcard)
1506 {
1507 void *cookie;
1508 wxVCardObject *vcObj = vcard.GetFirstProp(&cookie);
1509 while ( vcObj )
1510 {
1511 printf("%s%s",
1512 wxString(_T('\t'), level).c_str(),
1513 vcObj->GetName().c_str());
1514
1515 wxString value;
1516 switch ( vcObj->GetType() )
1517 {
1518 case wxVCardObject::String:
1519 case wxVCardObject::UString:
1520 {
1521 wxString val;
1522 vcObj->GetValue(&val);
1523 value << _T('"') << val << _T('"');
1524 }
1525 break;
1526
1527 case wxVCardObject::Int:
1528 {
1529 unsigned int i;
1530 vcObj->GetValue(&i);
1531 value.Printf(_T("%u"), i);
1532 }
1533 break;
1534
1535 case wxVCardObject::Long:
1536 {
1537 unsigned long l;
1538 vcObj->GetValue(&l);
1539 value.Printf(_T("%lu"), l);
1540 }
1541 break;
1542
1543 case wxVCardObject::None:
1544 break;
1545
1546 case wxVCardObject::Object:
1547 value = _T("<node>");
1548 break;
1549
1550 default:
1551 value = _T("<unknown value type>");
1552 }
1553
1554 if ( !!value )
1555 printf(" = %s", value.c_str());
1556 putchar('\n');
1557
1558 DumpVObject(level + 1, *vcObj);
1559
1560 delete vcObj;
1561 vcObj = vcard.GetNextProp(&cookie);
1562 }
1563 }
1564
1565 static void DumpVCardAddresses(const wxVCard& vcard)
1566 {
1567 puts("\nShowing all addresses from vCard:\n");
1568
1569 size_t nAdr = 0;
1570 void *cookie;
1571 wxVCardAddress *addr = vcard.GetFirstAddress(&cookie);
1572 while ( addr )
1573 {
1574 wxString flagsStr;
1575 int flags = addr->GetFlags();
1576 if ( flags & wxVCardAddress::Domestic )
1577 {
1578 flagsStr << _T("domestic ");
1579 }
1580 if ( flags & wxVCardAddress::Intl )
1581 {
1582 flagsStr << _T("international ");
1583 }
1584 if ( flags & wxVCardAddress::Postal )
1585 {
1586 flagsStr << _T("postal ");
1587 }
1588 if ( flags & wxVCardAddress::Parcel )
1589 {
1590 flagsStr << _T("parcel ");
1591 }
1592 if ( flags & wxVCardAddress::Home )
1593 {
1594 flagsStr << _T("home ");
1595 }
1596 if ( flags & wxVCardAddress::Work )
1597 {
1598 flagsStr << _T("work ");
1599 }
1600
1601 printf("Address %u:\n"
1602 "\tflags = %s\n"
1603 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
1604 ++nAdr,
1605 flagsStr.c_str(),
1606 addr->GetPostOffice().c_str(),
1607 addr->GetExtAddress().c_str(),
1608 addr->GetStreet().c_str(),
1609 addr->GetLocality().c_str(),
1610 addr->GetRegion().c_str(),
1611 addr->GetPostalCode().c_str(),
1612 addr->GetCountry().c_str()
1613 );
1614
1615 delete addr;
1616 addr = vcard.GetNextAddress(&cookie);
1617 }
1618 }
1619
1620 static void DumpVCardPhoneNumbers(const wxVCard& vcard)
1621 {
1622 puts("\nShowing all phone numbers from vCard:\n");
1623
1624 size_t nPhone = 0;
1625 void *cookie;
1626 wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie);
1627 while ( phone )
1628 {
1629 wxString flagsStr;
1630 int flags = phone->GetFlags();
1631 if ( flags & wxVCardPhoneNumber::Voice )
1632 {
1633 flagsStr << _T("voice ");
1634 }
1635 if ( flags & wxVCardPhoneNumber::Fax )
1636 {
1637 flagsStr << _T("fax ");
1638 }
1639 if ( flags & wxVCardPhoneNumber::Cellular )
1640 {
1641 flagsStr << _T("cellular ");
1642 }
1643 if ( flags & wxVCardPhoneNumber::Modem )
1644 {
1645 flagsStr << _T("modem ");
1646 }
1647 if ( flags & wxVCardPhoneNumber::Home )
1648 {
1649 flagsStr << _T("home ");
1650 }
1651 if ( flags & wxVCardPhoneNumber::Work )
1652 {
1653 flagsStr << _T("work ");
1654 }
1655
1656 printf("Phone number %u:\n"
1657 "\tflags = %s\n"
1658 "\tvalue = %s\n",
1659 ++nPhone,
1660 flagsStr.c_str(),
1661 phone->GetNumber().c_str()
1662 );
1663
1664 delete phone;
1665 phone = vcard.GetNextPhoneNumber(&cookie);
1666 }
1667 }
1668
1669 static void TestVCardRead()
1670 {
1671 puts("*** Testing wxVCard reading ***\n");
1672
1673 wxVCard vcard(_T("vcard.vcf"));
1674 if ( !vcard.IsOk() )
1675 {
1676 puts("ERROR: couldn't load vCard.");
1677 }
1678 else
1679 {
1680 // read individual vCard properties
1681 wxVCardObject *vcObj = vcard.GetProperty("FN");
1682 wxString value;
1683 if ( vcObj )
1684 {
1685 vcObj->GetValue(&value);
1686 delete vcObj;
1687 }
1688 else
1689 {
1690 value = _T("<none>");
1691 }
1692
1693 printf("Full name retrieved directly: %s\n", value.c_str());
1694
1695
1696 if ( !vcard.GetFullName(&value) )
1697 {
1698 value = _T("<none>");
1699 }
1700
1701 printf("Full name from wxVCard API: %s\n", value.c_str());
1702
1703 // now show how to deal with multiply occuring properties
1704 DumpVCardAddresses(vcard);
1705 DumpVCardPhoneNumbers(vcard);
1706
1707 // and finally show all
1708 puts("\nNow dumping the entire vCard:\n"
1709 "-----------------------------\n");
1710
1711 DumpVObject(0, vcard);
1712 }
1713 }
1714
1715 static void TestVCardWrite()
1716 {
1717 puts("*** Testing wxVCard writing ***\n");
1718
1719 wxVCard vcard;
1720 if ( !vcard.IsOk() )
1721 {
1722 puts("ERROR: couldn't create vCard.");
1723 }
1724 else
1725 {
1726 // set some fields
1727 vcard.SetName("Zeitlin", "Vadim");
1728 vcard.SetFullName("Vadim Zeitlin");
1729 vcard.SetOrganization("wxWindows", "R&D");
1730
1731 // just dump the vCard back
1732 puts("Entire vCard follows:\n");
1733 puts(vcard.Write());
1734 }
1735 }
1736
1737 #endif // TEST_VCARD
1738
1739 // ----------------------------------------------------------------------------
1740 // wide char (Unicode) support
1741 // ----------------------------------------------------------------------------
1742
1743 #ifdef TEST_WCHAR
1744
1745 #include <wx/strconv.h>
1746 #include <wx/buffer.h>
1747
1748 static void TestUtf8()
1749 {
1750 puts("*** Testing UTF8 support ***\n");
1751
1752 wxString testString = "français";
1753 #if 0
1754 "************ French - Français ****************"
1755 "Juste un petit exemple pour dire que les français aussi"
1756 "ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
1757 #endif
1758
1759 wxWCharBuffer wchBuf = testString.wc_str(wxConvUTF8);
1760 const wchar_t *pwz = (const wchar_t *)wchBuf;
1761 wxString testString2(pwz, wxConvLocal);
1762
1763 printf("Decoding '%s' => '%s'\n", testString.c_str(), testString2.c_str());
1764
1765 char *psz = "fran" "\xe7" "ais";
1766 size_t len = strlen(psz);
1767 wchar_t *pwz2 = new wchar_t[len + 1];
1768 for ( size_t n = 0; n <= len; n++ )
1769 {
1770 pwz2[n] = (wchar_t)(unsigned char)psz[n];
1771 }
1772
1773 wxString testString3(pwz2, wxConvUTF8);
1774 delete [] pwz2;
1775
1776 printf("Encoding '%s' -> '%s'\n", psz, testString3.c_str());
1777 }
1778
1779 #endif // TEST_WCHAR
1780
1781 // ----------------------------------------------------------------------------
1782 // ZIP stream
1783 // ----------------------------------------------------------------------------
1784
1785 #ifdef TEST_ZIP
1786
1787 #include "wx/zipstrm.h"
1788
1789 static void TestZipStreamRead()
1790 {
1791 puts("*** Testing ZIP reading ***\n");
1792
1793 wxZipInputStream istr(_T("idx.zip"), _T("IDX.txt"));
1794 printf("Archive size: %u\n", istr.GetSize());
1795
1796 puts("Dumping the file:");
1797 while ( !istr.Eof() )
1798 {
1799 putchar(istr.GetC());
1800 fflush(stdout);
1801 }
1802
1803 puts("\n----- done ------");
1804 }
1805
1806 #endif // TEST_ZIP
1807
1808 // ----------------------------------------------------------------------------
1809 // ZLIB stream
1810 // ----------------------------------------------------------------------------
1811
1812 #ifdef TEST_ZLIB
1813
1814 #include <wx/zstream.h>
1815 #include <wx/wfstream.h>
1816
1817 static const wxChar *FILENAME_GZ = _T("test.gz");
1818 static const char *TEST_DATA = "hello and hello again";
1819
1820 static void TestZlibStreamWrite()
1821 {
1822 puts("*** Testing Zlib stream reading ***\n");
1823
1824 wxFileOutputStream fileOutStream(FILENAME_GZ);
1825 wxZlibOutputStream ostr(fileOutStream, 0);
1826 printf("Compressing the test string... ");
1827 ostr.Write(TEST_DATA, sizeof(TEST_DATA));
1828 if ( !ostr )
1829 {
1830 puts("(ERROR: failed)");
1831 }
1832 else
1833 {
1834 puts("(ok)");
1835 }
1836
1837 puts("\n----- done ------");
1838 }
1839
1840 static void TestZlibStreamRead()
1841 {
1842 puts("*** Testing Zlib stream reading ***\n");
1843
1844 wxFileInputStream fileInStream(FILENAME_GZ);
1845 wxZlibInputStream istr(fileInStream);
1846 printf("Archive size: %u\n", istr.GetSize());
1847
1848 puts("Dumping the file:");
1849 while ( !istr.Eof() )
1850 {
1851 putchar(istr.GetC());
1852 fflush(stdout);
1853 }
1854
1855 puts("\n----- done ------");
1856 }
1857
1858 #endif // TEST_ZLIB
1859
1860 // ----------------------------------------------------------------------------
1861 // date time
1862 // ----------------------------------------------------------------------------
1863
1864 #ifdef TEST_DATETIME
1865
1866 #include <wx/date.h>
1867
1868 #include <wx/datetime.h>
1869
1870 // the test data
1871 struct Date
1872 {
1873 wxDateTime::wxDateTime_t day;
1874 wxDateTime::Month month;
1875 int year;
1876 wxDateTime::wxDateTime_t hour, min, sec;
1877 double jdn;
1878 wxDateTime::WeekDay wday;
1879 time_t gmticks, ticks;
1880
1881 void Init(const wxDateTime::Tm& tm)
1882 {
1883 day = tm.mday;
1884 month = tm.mon;
1885 year = tm.year;
1886 hour = tm.hour;
1887 min = tm.min;
1888 sec = tm.sec;
1889 jdn = 0.0;
1890 gmticks = ticks = -1;
1891 }
1892
1893 wxDateTime DT() const
1894 { return wxDateTime(day, month, year, hour, min, sec); }
1895
1896 bool SameDay(const wxDateTime::Tm& tm) const
1897 {
1898 return day == tm.mday && month == tm.mon && year == tm.year;
1899 }
1900
1901 wxString Format() const
1902 {
1903 wxString s;
1904 s.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
1905 hour, min, sec,
1906 wxDateTime::GetMonthName(month).c_str(),
1907 day,
1908 abs(wxDateTime::ConvertYearToBC(year)),
1909 year > 0 ? "AD" : "BC");
1910 return s;
1911 }
1912
1913 wxString FormatDate() const
1914 {
1915 wxString s;
1916 s.Printf("%02d-%s-%4d%s",
1917 day,
1918 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
1919 abs(wxDateTime::ConvertYearToBC(year)),
1920 year > 0 ? "AD" : "BC");
1921 return s;
1922 }
1923 };
1924
1925 static const Date testDates[] =
1926 {
1927 { 1, wxDateTime::Jan, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu, 0, -3600 },
1928 { 21, wxDateTime::Jan, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon, -1, -1 },
1929 { 29, wxDateTime::May, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat, 202219200, 202212000 },
1930 { 29, wxDateTime::Feb, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun, 194400000, 194396400 },
1931 { 1, wxDateTime::Jan, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon, -1, -1 },
1932 { 1, wxDateTime::Jan, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon, -1, -1 },
1933 { 15, wxDateTime::Oct, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri, -1, -1 },
1934 { 4, wxDateTime::Oct, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon, -1, -1 },
1935 { 1, wxDateTime::Mar, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu, -1, -1 },
1936 { 1, wxDateTime::Jan, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon, -1, -1 },
1937 { 31, wxDateTime::Dec, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun, -1, -1 },
1938 { 1, wxDateTime::Jan, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat, -1, -1 },
1939 { 12, wxDateTime::Aug, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri, -1, -1 },
1940 { 12, wxDateTime::Aug, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat, -1, -1 },
1941 { 24, wxDateTime::Nov, -4713, 00, 00, 00, -0.5, wxDateTime::Mon, -1, -1 },
1942 };
1943
1944 // this test miscellaneous static wxDateTime functions
1945 static void TestTimeStatic()
1946 {
1947 puts("\n*** wxDateTime static methods test ***");
1948
1949 // some info about the current date
1950 int year = wxDateTime::GetCurrentYear();
1951 printf("Current year %d is %sa leap one and has %d days.\n",
1952 year,
1953 wxDateTime::IsLeapYear(year) ? "" : "not ",
1954 wxDateTime::GetNumberOfDays(year));
1955
1956 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
1957 printf("Current month is '%s' ('%s') and it has %d days\n",
1958 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
1959 wxDateTime::GetMonthName(month).c_str(),
1960 wxDateTime::GetNumberOfDays(month));
1961
1962 // leap year logic
1963 static const size_t nYears = 5;
1964 static const size_t years[2][nYears] =
1965 {
1966 // first line: the years to test
1967 { 1990, 1976, 2000, 2030, 1984, },
1968
1969 // second line: TRUE if leap, FALSE otherwise
1970 { FALSE, TRUE, TRUE, FALSE, TRUE }
1971 };
1972
1973 for ( size_t n = 0; n < nYears; n++ )
1974 {
1975 int year = years[0][n];
1976 bool should = years[1][n] != 0,
1977 is = wxDateTime::IsLeapYear(year);
1978
1979 printf("Year %d is %sa leap year (%s)\n",
1980 year,
1981 is ? "" : "not ",
1982 should == is ? "ok" : "ERROR");
1983
1984 wxASSERT( should == wxDateTime::IsLeapYear(year) );
1985 }
1986 }
1987
1988 // test constructing wxDateTime objects
1989 static void TestTimeSet()
1990 {
1991 puts("\n*** wxDateTime construction test ***");
1992
1993 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
1994 {
1995 const Date& d1 = testDates[n];
1996 wxDateTime dt = d1.DT();
1997
1998 Date d2;
1999 d2.Init(dt.GetTm());
2000
2001 wxString s1 = d1.Format(),
2002 s2 = d2.Format();
2003
2004 printf("Date: %s == %s (%s)\n",
2005 s1.c_str(), s2.c_str(),
2006 s1 == s2 ? "ok" : "ERROR");
2007 }
2008 }
2009
2010 // test time zones stuff
2011 static void TestTimeZones()
2012 {
2013 puts("\n*** wxDateTime timezone test ***");
2014
2015 wxDateTime now = wxDateTime::Now();
2016
2017 printf("Current GMT time:\t%s\n", now.Format("%c", wxDateTime::GMT0).c_str());
2018 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0).c_str());
2019 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST).c_str());
2020 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
2021 printf(" Moscow:\t%s\n", now.Format("%c", wxDateTime::MSK).c_str());
2022 printf(" New York:\t%s\n", now.Format("%c", wxDateTime::EST).c_str());
2023
2024 wxDateTime::Tm tm = now.GetTm();
2025 if ( wxDateTime(tm) != now )
2026 {
2027 printf("ERROR: got %s instead of %s\n",
2028 wxDateTime(tm).Format().c_str(), now.Format().c_str());
2029 }
2030 }
2031
2032 // test some minimal support for the dates outside the standard range
2033 static void TestTimeRange()
2034 {
2035 puts("\n*** wxDateTime out-of-standard-range dates test ***");
2036
2037 static const char *fmt = "%d-%b-%Y %H:%M:%S";
2038
2039 printf("Unix epoch:\t%s\n",
2040 wxDateTime(2440587.5).Format(fmt).c_str());
2041 printf("Feb 29, 0: \t%s\n",
2042 wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str());
2043 printf("JDN 0: \t%s\n",
2044 wxDateTime(0.0).Format(fmt).c_str());
2045 printf("Jan 1, 1AD:\t%s\n",
2046 wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str());
2047 printf("May 29, 2099:\t%s\n",
2048 wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str());
2049 }
2050
2051 static void TestTimeTicks()
2052 {
2053 puts("\n*** wxDateTime ticks test ***");
2054
2055 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
2056 {
2057 const Date& d = testDates[n];
2058 if ( d.ticks == -1 )
2059 continue;
2060
2061 wxDateTime dt = d.DT();
2062 long ticks = (dt.GetValue() / 1000).ToLong();
2063 printf("Ticks of %s:\t% 10ld", d.Format().c_str(), ticks);
2064 if ( ticks == d.ticks )
2065 {
2066 puts(" (ok)");
2067 }
2068 else
2069 {
2070 printf(" (ERROR: should be %ld, delta = %ld)\n",
2071 d.ticks, ticks - d.ticks);
2072 }
2073
2074 dt = d.DT().ToTimezone(wxDateTime::GMT0);
2075 ticks = (dt.GetValue() / 1000).ToLong();
2076 printf("GMtks of %s:\t% 10ld", d.Format().c_str(), ticks);
2077 if ( ticks == d.gmticks )
2078 {
2079 puts(" (ok)");
2080 }
2081 else
2082 {
2083 printf(" (ERROR: should be %ld, delta = %ld)\n",
2084 d.gmticks, ticks - d.gmticks);
2085 }
2086 }
2087
2088 puts("");
2089 }
2090
2091 // test conversions to JDN &c
2092 static void TestTimeJDN()
2093 {
2094 puts("\n*** wxDateTime to JDN test ***");
2095
2096 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
2097 {
2098 const Date& d = testDates[n];
2099 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
2100 double jdn = dt.GetJulianDayNumber();
2101
2102 printf("JDN of %s is:\t% 15.6f", d.Format().c_str(), jdn);
2103 if ( jdn == d.jdn )
2104 {
2105 puts(" (ok)");
2106 }
2107 else
2108 {
2109 printf(" (ERROR: should be %f, delta = %f)\n",
2110 d.jdn, jdn - d.jdn);
2111 }
2112 }
2113 }
2114
2115 // test week days computation
2116 static void TestTimeWDays()
2117 {
2118 puts("\n*** wxDateTime weekday test ***");
2119
2120 // test GetWeekDay()
2121 size_t n;
2122 for ( n = 0; n < WXSIZEOF(testDates); n++ )
2123 {
2124 const Date& d = testDates[n];
2125 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
2126
2127 wxDateTime::WeekDay wday = dt.GetWeekDay();
2128 printf("%s is: %s",
2129 d.Format().c_str(),
2130 wxDateTime::GetWeekDayName(wday).c_str());
2131 if ( wday == d.wday )
2132 {
2133 puts(" (ok)");
2134 }
2135 else
2136 {
2137 printf(" (ERROR: should be %s)\n",
2138 wxDateTime::GetWeekDayName(d.wday).c_str());
2139 }
2140 }
2141
2142 puts("");
2143
2144 // test SetToWeekDay()
2145 struct WeekDateTestData
2146 {
2147 Date date; // the real date (precomputed)
2148 int nWeek; // its week index in the month
2149 wxDateTime::WeekDay wday; // the weekday
2150 wxDateTime::Month month; // the month
2151 int year; // and the year
2152
2153 wxString Format() const
2154 {
2155 wxString s, which;
2156 switch ( nWeek < -1 ? -nWeek : nWeek )
2157 {
2158 case 1: which = "first"; break;
2159 case 2: which = "second"; break;
2160 case 3: which = "third"; break;
2161 case 4: which = "fourth"; break;
2162 case 5: which = "fifth"; break;
2163
2164 case -1: which = "last"; break;
2165 }
2166
2167 if ( nWeek < -1 )
2168 {
2169 which += " from end";
2170 }
2171
2172 s.Printf("The %s %s of %s in %d",
2173 which.c_str(),
2174 wxDateTime::GetWeekDayName(wday).c_str(),
2175 wxDateTime::GetMonthName(month).c_str(),
2176 year);
2177
2178 return s;
2179 }
2180 };
2181
2182 // the array data was generated by the following python program
2183 /*
2184 from DateTime import *
2185 from whrandom import *
2186 from string import *
2187
2188 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2189 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2190
2191 week = DateTimeDelta(7)
2192
2193 for n in range(20):
2194 year = randint(1900, 2100)
2195 month = randint(1, 12)
2196 day = randint(1, 28)
2197 dt = DateTime(year, month, day)
2198 wday = dt.day_of_week
2199
2200 countFromEnd = choice([-1, 1])
2201 weekNum = 0;
2202
2203 while dt.month is month:
2204 dt = dt - countFromEnd * week
2205 weekNum = weekNum + countFromEnd
2206
2207 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
2208
2209 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
2210 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
2211 */
2212
2213 static const WeekDateTestData weekDatesTestData[] =
2214 {
2215 { { 20, wxDateTime::Mar, 2045 }, 3, wxDateTime::Mon, wxDateTime::Mar, 2045 },
2216 { { 5, wxDateTime::Jun, 1985 }, -4, wxDateTime::Wed, wxDateTime::Jun, 1985 },
2217 { { 12, wxDateTime::Nov, 1961 }, -3, wxDateTime::Sun, wxDateTime::Nov, 1961 },
2218 { { 27, wxDateTime::Feb, 2093 }, -1, wxDateTime::Fri, wxDateTime::Feb, 2093 },
2219 { { 4, wxDateTime::Jul, 2070 }, -4, wxDateTime::Fri, wxDateTime::Jul, 2070 },
2220 { { 2, wxDateTime::Apr, 1906 }, -5, wxDateTime::Mon, wxDateTime::Apr, 1906 },
2221 { { 19, wxDateTime::Jul, 2023 }, -2, wxDateTime::Wed, wxDateTime::Jul, 2023 },
2222 { { 5, wxDateTime::May, 1958 }, -4, wxDateTime::Mon, wxDateTime::May, 1958 },
2223 { { 11, wxDateTime::Aug, 1900 }, 2, wxDateTime::Sat, wxDateTime::Aug, 1900 },
2224 { { 14, wxDateTime::Feb, 1945 }, 2, wxDateTime::Wed, wxDateTime::Feb, 1945 },
2225 { { 25, wxDateTime::Jul, 1967 }, -1, wxDateTime::Tue, wxDateTime::Jul, 1967 },
2226 { { 9, wxDateTime::May, 1916 }, -4, wxDateTime::Tue, wxDateTime::May, 1916 },
2227 { { 20, wxDateTime::Jun, 1927 }, 3, wxDateTime::Mon, wxDateTime::Jun, 1927 },
2228 { { 2, wxDateTime::Aug, 2000 }, 1, wxDateTime::Wed, wxDateTime::Aug, 2000 },
2229 { { 20, wxDateTime::Apr, 2044 }, 3, wxDateTime::Wed, wxDateTime::Apr, 2044 },
2230 { { 20, wxDateTime::Feb, 1932 }, -2, wxDateTime::Sat, wxDateTime::Feb, 1932 },
2231 { { 25, wxDateTime::Jul, 2069 }, 4, wxDateTime::Thu, wxDateTime::Jul, 2069 },
2232 { { 3, wxDateTime::Apr, 1925 }, 1, wxDateTime::Fri, wxDateTime::Apr, 1925 },
2233 { { 21, wxDateTime::Mar, 2093 }, 3, wxDateTime::Sat, wxDateTime::Mar, 2093 },
2234 { { 3, wxDateTime::Dec, 2074 }, -5, wxDateTime::Mon, wxDateTime::Dec, 2074 },
2235 };
2236
2237 static const char *fmt = "%d-%b-%Y";
2238
2239 wxDateTime dt;
2240 for ( n = 0; n < WXSIZEOF(weekDatesTestData); n++ )
2241 {
2242 const WeekDateTestData& wd = weekDatesTestData[n];
2243
2244 dt.SetToWeekDay(wd.wday, wd.nWeek, wd.month, wd.year);
2245
2246 printf("%s is %s", wd.Format().c_str(), dt.Format(fmt).c_str());
2247
2248 const Date& d = wd.date;
2249 if ( d.SameDay(dt.GetTm()) )
2250 {
2251 puts(" (ok)");
2252 }
2253 else
2254 {
2255 dt.Set(d.day, d.month, d.year);
2256
2257 printf(" (ERROR: should be %s)\n", dt.Format(fmt).c_str());
2258 }
2259 }
2260 }
2261
2262 // test the computation of (ISO) week numbers
2263 static void TestTimeWNumber()
2264 {
2265 puts("\n*** wxDateTime week number test ***");
2266
2267 struct WeekNumberTestData
2268 {
2269 Date date; // the date
2270 wxDateTime::wxDateTime_t week; // the week number in the year
2271 wxDateTime::wxDateTime_t wmon; // the week number in the month
2272 wxDateTime::wxDateTime_t wmon2; // same but week starts with Sun
2273 wxDateTime::wxDateTime_t dnum; // day number in the year
2274 };
2275
2276 // data generated with the following python script:
2277 /*
2278 from DateTime import *
2279 from whrandom import *
2280 from string import *
2281
2282 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2283 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2284
2285 def GetMonthWeek(dt):
2286 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
2287 if weekNumMonth < 0:
2288 weekNumMonth = weekNumMonth + 53
2289 return weekNumMonth
2290
2291 def GetLastSundayBefore(dt):
2292 if dt.iso_week[2] == 7:
2293 return dt
2294 else:
2295 return dt - DateTimeDelta(dt.iso_week[2])
2296
2297 for n in range(20):
2298 year = randint(1900, 2100)
2299 month = randint(1, 12)
2300 day = randint(1, 28)
2301 dt = DateTime(year, month, day)
2302 dayNum = dt.day_of_year
2303 weekNum = dt.iso_week[1]
2304 weekNumMonth = GetMonthWeek(dt)
2305
2306 weekNumMonth2 = 0
2307 dtSunday = GetLastSundayBefore(dt)
2308
2309 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
2310 weekNumMonth2 = weekNumMonth2 + 1
2311 dtSunday = dtSunday - DateTimeDelta(7)
2312
2313 data = { 'day': rjust(`day`, 2), \
2314 'month': monthNames[month - 1], \
2315 'year': year, \
2316 'weekNum': rjust(`weekNum`, 2), \
2317 'weekNumMonth': weekNumMonth, \
2318 'weekNumMonth2': weekNumMonth2, \
2319 'dayNum': rjust(`dayNum`, 3) }
2320
2321 print " { { %(day)s, "\
2322 "wxDateTime::%(month)s, "\
2323 "%(year)d }, "\
2324 "%(weekNum)s, "\
2325 "%(weekNumMonth)s, "\
2326 "%(weekNumMonth2)s, "\
2327 "%(dayNum)s }," % data
2328
2329 */
2330 static const WeekNumberTestData weekNumberTestDates[] =
2331 {
2332 { { 27, wxDateTime::Dec, 1966 }, 52, 5, 5, 361 },
2333 { { 22, wxDateTime::Jul, 1926 }, 29, 4, 4, 203 },
2334 { { 22, wxDateTime::Oct, 2076 }, 43, 4, 4, 296 },
2335 { { 1, wxDateTime::Jul, 1967 }, 26, 1, 1, 182 },
2336 { { 8, wxDateTime::Nov, 2004 }, 46, 2, 2, 313 },
2337 { { 21, wxDateTime::Mar, 1920 }, 12, 3, 4, 81 },
2338 { { 7, wxDateTime::Jan, 1965 }, 1, 2, 2, 7 },
2339 { { 19, wxDateTime::Oct, 1999 }, 42, 4, 4, 292 },
2340 { { 13, wxDateTime::Aug, 1955 }, 32, 2, 2, 225 },
2341 { { 18, wxDateTime::Jul, 2087 }, 29, 3, 3, 199 },
2342 { { 2, wxDateTime::Sep, 2028 }, 35, 1, 1, 246 },
2343 { { 28, wxDateTime::Jul, 1945 }, 30, 5, 4, 209 },
2344 { { 15, wxDateTime::Jun, 1901 }, 24, 3, 3, 166 },
2345 { { 10, wxDateTime::Oct, 1939 }, 41, 3, 2, 283 },
2346 { { 3, wxDateTime::Dec, 1965 }, 48, 1, 1, 337 },
2347 { { 23, wxDateTime::Feb, 1940 }, 8, 4, 4, 54 },
2348 { { 2, wxDateTime::Jan, 1987 }, 1, 1, 1, 2 },
2349 { { 11, wxDateTime::Aug, 2079 }, 32, 2, 2, 223 },
2350 { { 2, wxDateTime::Feb, 2063 }, 5, 1, 1, 33 },
2351 { { 16, wxDateTime::Oct, 1942 }, 42, 3, 3, 289 },
2352 };
2353
2354 for ( size_t n = 0; n < WXSIZEOF(weekNumberTestDates); n++ )
2355 {
2356 const WeekNumberTestData& wn = weekNumberTestDates[n];
2357 const Date& d = wn.date;
2358
2359 wxDateTime dt = d.DT();
2360
2361 wxDateTime::wxDateTime_t
2362 week = dt.GetWeekOfYear(wxDateTime::Monday_First),
2363 wmon = dt.GetWeekOfMonth(wxDateTime::Monday_First),
2364 wmon2 = dt.GetWeekOfMonth(wxDateTime::Sunday_First),
2365 dnum = dt.GetDayOfYear();
2366
2367 printf("%s: the day number is %d",
2368 d.FormatDate().c_str(), dnum);
2369 if ( dnum == wn.dnum )
2370 {
2371 printf(" (ok)");
2372 }
2373 else
2374 {
2375 printf(" (ERROR: should be %d)", wn.dnum);
2376 }
2377
2378 printf(", week in month is %d", wmon);
2379 if ( wmon == wn.wmon )
2380 {
2381 printf(" (ok)");
2382 }
2383 else
2384 {
2385 printf(" (ERROR: should be %d)", wn.wmon);
2386 }
2387
2388 printf(" or %d", wmon2);
2389 if ( wmon2 == wn.wmon2 )
2390 {
2391 printf(" (ok)");
2392 }
2393 else
2394 {
2395 printf(" (ERROR: should be %d)", wn.wmon2);
2396 }
2397
2398 printf(", week in year is %d", week);
2399 if ( week == wn.week )
2400 {
2401 puts(" (ok)");
2402 }
2403 else
2404 {
2405 printf(" (ERROR: should be %d)\n", wn.week);
2406 }
2407 }
2408 }
2409
2410 // test DST calculations
2411 static void TestTimeDST()
2412 {
2413 puts("\n*** wxDateTime DST test ***");
2414
2415 printf("DST is%s in effect now.\n\n",
2416 wxDateTime::Now().IsDST() ? "" : " not");
2417
2418 // taken from http://www.energy.ca.gov/daylightsaving.html
2419 static const Date datesDST[2][2004 - 1900 + 1] =
2420 {
2421 {
2422 { 1, wxDateTime::Apr, 1990 },
2423 { 7, wxDateTime::Apr, 1991 },
2424 { 5, wxDateTime::Apr, 1992 },
2425 { 4, wxDateTime::Apr, 1993 },
2426 { 3, wxDateTime::Apr, 1994 },
2427 { 2, wxDateTime::Apr, 1995 },
2428 { 7, wxDateTime::Apr, 1996 },
2429 { 6, wxDateTime::Apr, 1997 },
2430 { 5, wxDateTime::Apr, 1998 },
2431 { 4, wxDateTime::Apr, 1999 },
2432 { 2, wxDateTime::Apr, 2000 },
2433 { 1, wxDateTime::Apr, 2001 },
2434 { 7, wxDateTime::Apr, 2002 },
2435 { 6, wxDateTime::Apr, 2003 },
2436 { 4, wxDateTime::Apr, 2004 },
2437 },
2438 {
2439 { 28, wxDateTime::Oct, 1990 },
2440 { 27, wxDateTime::Oct, 1991 },
2441 { 25, wxDateTime::Oct, 1992 },
2442 { 31, wxDateTime::Oct, 1993 },
2443 { 30, wxDateTime::Oct, 1994 },
2444 { 29, wxDateTime::Oct, 1995 },
2445 { 27, wxDateTime::Oct, 1996 },
2446 { 26, wxDateTime::Oct, 1997 },
2447 { 25, wxDateTime::Oct, 1998 },
2448 { 31, wxDateTime::Oct, 1999 },
2449 { 29, wxDateTime::Oct, 2000 },
2450 { 28, wxDateTime::Oct, 2001 },
2451 { 27, wxDateTime::Oct, 2002 },
2452 { 26, wxDateTime::Oct, 2003 },
2453 { 31, wxDateTime::Oct, 2004 },
2454 }
2455 };
2456
2457 int year;
2458 for ( year = 1990; year < 2005; year++ )
2459 {
2460 wxDateTime dtBegin = wxDateTime::GetBeginDST(year, wxDateTime::USA),
2461 dtEnd = wxDateTime::GetEndDST(year, wxDateTime::USA);
2462
2463 printf("DST period in the US for year %d: from %s to %s",
2464 year, dtBegin.Format().c_str(), dtEnd.Format().c_str());
2465
2466 size_t n = year - 1990;
2467 const Date& dBegin = datesDST[0][n];
2468 const Date& dEnd = datesDST[1][n];
2469
2470 if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
2471 {
2472 puts(" (ok)");
2473 }
2474 else
2475 {
2476 printf(" (ERROR: should be %s %d to %s %d)\n",
2477 wxDateTime::GetMonthName(dBegin.month).c_str(), dBegin.day,
2478 wxDateTime::GetMonthName(dEnd.month).c_str(), dEnd.day);
2479 }
2480 }
2481
2482 puts("");
2483
2484 for ( year = 1990; year < 2005; year++ )
2485 {
2486 printf("DST period in Europe for year %d: from %s to %s\n",
2487 year,
2488 wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
2489 wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
2490 }
2491 }
2492
2493 // test wxDateTime -> text conversion
2494 static void TestTimeFormat()
2495 {
2496 puts("\n*** wxDateTime formatting test ***");
2497
2498 // some information may be lost during conversion, so store what kind
2499 // of info should we recover after a round trip
2500 enum CompareKind
2501 {
2502 CompareNone, // don't try comparing
2503 CompareBoth, // dates and times should be identical
2504 CompareDate, // dates only
2505 CompareTime // time only
2506 };
2507
2508 static const struct
2509 {
2510 CompareKind compareKind;
2511 const char *format;
2512 } formatTestFormats[] =
2513 {
2514 { CompareBoth, "---> %c" },
2515 { CompareDate, "Date is %A, %d of %B, in year %Y" },
2516 { CompareBoth, "Date is %x, time is %X" },
2517 { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
2518 { CompareNone, "The day of year: %j, the week of year: %W" },
2519 { CompareDate, "ISO date without separators: %4Y%2m%2d" },
2520 };
2521
2522 static const Date formatTestDates[] =
2523 {
2524 { 29, wxDateTime::May, 1976, 18, 30, 00 },
2525 { 31, wxDateTime::Dec, 1999, 23, 30, 00 },
2526 #if 0
2527 // this test can't work for other centuries because it uses two digit
2528 // years in formats, so don't even try it
2529 { 29, wxDateTime::May, 2076, 18, 30, 00 },
2530 { 29, wxDateTime::Feb, 2400, 02, 15, 25 },
2531 { 01, wxDateTime::Jan, -52, 03, 16, 47 },
2532 #endif
2533 };
2534
2535 // an extra test (as it doesn't depend on date, don't do it in the loop)
2536 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
2537
2538 for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ )
2539 {
2540 puts("");
2541
2542 wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT();
2543 for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
2544 {
2545 wxString s = dt.Format(formatTestFormats[n].format);
2546 printf("%s", s.c_str());
2547
2548 // what can we recover?
2549 int kind = formatTestFormats[n].compareKind;
2550
2551 // convert back
2552 wxDateTime dt2;
2553 const wxChar *result = dt2.ParseFormat(s, formatTestFormats[n].format);
2554 if ( !result )
2555 {
2556 // converion failed - should it have?
2557 if ( kind == CompareNone )
2558 puts(" (ok)");
2559 else
2560 puts(" (ERROR: conversion back failed)");
2561 }
2562 else if ( *result )
2563 {
2564 // should have parsed the entire string
2565 puts(" (ERROR: conversion back stopped too soon)");
2566 }
2567 else
2568 {
2569 bool equal = FALSE; // suppress compilaer warning
2570 switch ( kind )
2571 {
2572 case CompareBoth:
2573 equal = dt2 == dt;
2574 break;
2575
2576 case CompareDate:
2577 equal = dt.IsSameDate(dt2);
2578 break;
2579
2580 case CompareTime:
2581 equal = dt.IsSameTime(dt2);
2582 break;
2583 }
2584
2585 if ( !equal )
2586 {
2587 printf(" (ERROR: got back '%s' instead of '%s')\n",
2588 dt2.Format().c_str(), dt.Format().c_str());
2589 }
2590 else
2591 {
2592 puts(" (ok)");
2593 }
2594 }
2595 }
2596 }
2597 }
2598
2599 // test text -> wxDateTime conversion
2600 static void TestTimeParse()
2601 {
2602 puts("\n*** wxDateTime parse test ***");
2603
2604 struct ParseTestData
2605 {
2606 const char *format;
2607 Date date;
2608 bool good;
2609 };
2610
2611 static const ParseTestData parseTestDates[] =
2612 {
2613 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, TRUE },
2614 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec, 1999, 03, 17, 20 }, TRUE },
2615 };
2616
2617 for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
2618 {
2619 const char *format = parseTestDates[n].format;
2620
2621 printf("%s => ", format);
2622
2623 wxDateTime dt;
2624 if ( dt.ParseRfc822Date(format) )
2625 {
2626 printf("%s ", dt.Format().c_str());
2627
2628 if ( parseTestDates[n].good )
2629 {
2630 wxDateTime dtReal = parseTestDates[n].date.DT();
2631 if ( dt == dtReal )
2632 {
2633 puts("(ok)");
2634 }
2635 else
2636 {
2637 printf("(ERROR: should be %s)\n", dtReal.Format().c_str());
2638 }
2639 }
2640 else
2641 {
2642 puts("(ERROR: bad format)");
2643 }
2644 }
2645 else
2646 {
2647 printf("bad format (%s)\n",
2648 parseTestDates[n].good ? "ERROR" : "ok");
2649 }
2650 }
2651 }
2652
2653 static void TestInteractive()
2654 {
2655 puts("\n*** interactive wxDateTime tests ***");
2656
2657 char buf[128];
2658
2659 for ( ;; )
2660 {
2661 printf("Enter a date: ");
2662 if ( !fgets(buf, WXSIZEOF(buf), stdin) )
2663 break;
2664
2665 // kill the last '\n'
2666 buf[strlen(buf) - 1] = 0;
2667
2668 wxDateTime dt;
2669 const char *p = dt.ParseDate(buf);
2670 if ( !p )
2671 {
2672 printf("ERROR: failed to parse the date '%s'.\n", buf);
2673
2674 continue;
2675 }
2676 else if ( *p )
2677 {
2678 printf("WARNING: parsed only first %u characters.\n", p - buf);
2679 }
2680
2681 printf("%s: day %u, week of month %u/%u, week of year %u\n",
2682 dt.Format("%b %d, %Y").c_str(),
2683 dt.GetDayOfYear(),
2684 dt.GetWeekOfMonth(wxDateTime::Monday_First),
2685 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
2686 dt.GetWeekOfYear(wxDateTime::Monday_First));
2687 }
2688
2689 puts("\n*** done ***");
2690 }
2691
2692 static void TestTimeMS()
2693 {
2694 puts("*** testing millisecond-resolution support in wxDateTime ***");
2695
2696 wxDateTime dt1 = wxDateTime::Now(),
2697 dt2 = wxDateTime::UNow();
2698
2699 printf("Now = %s\n", dt1.Format("%H:%M:%S:%l").c_str());
2700 printf("UNow = %s\n", dt2.Format("%H:%M:%S:%l").c_str());
2701 printf("Dummy loop: ");
2702 for ( int i = 0; i < 6000; i++ )
2703 {
2704 //for ( int j = 0; j < 10; j++ )
2705 {
2706 wxString s;
2707 s.Printf("%g", sqrt(i));
2708 }
2709
2710 if ( !(i % 100) )
2711 putchar('.');
2712 }
2713 puts(", done");
2714
2715 dt1 = dt2;
2716 dt2 = wxDateTime::UNow();
2717 printf("UNow = %s\n", dt2.Format("%H:%M:%S:%l").c_str());
2718
2719 printf("Loop executed in %s ms\n", (dt2 - dt1).Format("%l").c_str());
2720
2721 puts("\n*** done ***");
2722 }
2723
2724 static void TestTimeArithmetics()
2725 {
2726 puts("\n*** testing arithmetic operations on wxDateTime ***");
2727
2728 static const struct ArithmData
2729 {
2730 ArithmData(const wxDateSpan& sp, const char *nam)
2731 : span(sp), name(nam) { }
2732
2733 wxDateSpan span;
2734 const char *name;
2735 } testArithmData[] =
2736 {
2737 ArithmData(wxDateSpan::Day(), "day"),
2738 ArithmData(wxDateSpan::Week(), "week"),
2739 ArithmData(wxDateSpan::Month(), "month"),
2740 ArithmData(wxDateSpan::Year(), "year"),
2741 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
2742 };
2743
2744 wxDateTime dt(29, wxDateTime::Dec, 1999), dt1, dt2;
2745
2746 for ( size_t n = 0; n < WXSIZEOF(testArithmData); n++ )
2747 {
2748 wxDateSpan span = testArithmData[n].span;
2749 dt1 = dt + span;
2750 dt2 = dt - span;
2751
2752 const char *name = testArithmData[n].name;
2753 printf("%s + %s = %s, %s - %s = %s\n",
2754 dt.FormatISODate().c_str(), name, dt1.FormatISODate().c_str(),
2755 dt.FormatISODate().c_str(), name, dt2.FormatISODate().c_str());
2756
2757 printf("Going back: %s", (dt1 - span).FormatISODate().c_str());
2758 if ( dt1 - span == dt )
2759 {
2760 puts(" (ok)");
2761 }
2762 else
2763 {
2764 printf(" (ERROR: should be %s)\n", dt.FormatISODate().c_str());
2765 }
2766
2767 printf("Going forward: %s", (dt2 + span).FormatISODate().c_str());
2768 if ( dt2 + span == dt )
2769 {
2770 puts(" (ok)");
2771 }
2772 else
2773 {
2774 printf(" (ERROR: should be %s)\n", dt.FormatISODate().c_str());
2775 }
2776
2777 printf("Double increment: %s", (dt2 + 2*span).FormatISODate().c_str());
2778 if ( dt2 + 2*span == dt1 )
2779 {
2780 puts(" (ok)");
2781 }
2782 else
2783 {
2784 printf(" (ERROR: should be %s)\n", dt2.FormatISODate().c_str());
2785 }
2786
2787 puts("");
2788 }
2789 }
2790
2791 static void TestTimeHolidays()
2792 {
2793 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
2794
2795 wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
2796 wxDateTime dtStart(1, tm.mon, tm.year),
2797 dtEnd = dtStart.GetLastMonthDay();
2798
2799 wxDateTimeArray hol;
2800 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
2801
2802 const wxChar *format = "%d-%b-%Y (%a)";
2803
2804 printf("All holidays between %s and %s:\n",
2805 dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
2806
2807 size_t count = hol.GetCount();
2808 for ( size_t n = 0; n < count; n++ )
2809 {
2810 printf("\t%s\n", hol[n].Format(format).c_str());
2811 }
2812
2813 puts("");
2814 }
2815
2816 static void TestTimeZoneBug()
2817 {
2818 puts("\n*** testing for DST/timezone bug ***\n");
2819
2820 wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000);
2821 for ( int i = 0; i < 31; i++ )
2822 {
2823 printf("Date %s: week day %s.\n",
2824 date.Format(_T("%d-%m-%Y")).c_str(),
2825 date.GetWeekDayName(date.GetWeekDay()).c_str());
2826
2827 date += wxDateSpan::Day();
2828 }
2829
2830 puts("");
2831 }
2832
2833 #if 0
2834
2835 // test compatibility with the old wxDate/wxTime classes
2836 static void TestTimeCompatibility()
2837 {
2838 puts("\n*** wxDateTime compatibility test ***");
2839
2840 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
2841 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
2842
2843 double jdnNow = wxDateTime::Now().GetJDN();
2844 long jdnMidnight = (long)(jdnNow - 0.5);
2845 printf("wxDate for today: %s\n", wxDate(jdnMidnight).FormatDate().c_str());
2846
2847 jdnMidnight = wxDate().Set().GetJulianDate();
2848 printf("wxDateTime for today: %s\n",
2849 wxDateTime((double)(jdnMidnight + 0.5)).Format("%c", wxDateTime::GMT0).c_str());
2850
2851 int flags = wxEUROPEAN;//wxFULL;
2852 wxDate date;
2853 date.Set();
2854 printf("Today is %s\n", date.FormatDate(flags).c_str());
2855 for ( int n = 0; n < 7; n++ )
2856 {
2857 printf("Previous %s is %s\n",
2858 wxDateTime::GetWeekDayName((wxDateTime::WeekDay)n),
2859 date.Previous(n + 1).FormatDate(flags).c_str());
2860 }
2861 }
2862
2863 #endif // 0
2864
2865 #endif // TEST_DATETIME
2866
2867 // ----------------------------------------------------------------------------
2868 // threads
2869 // ----------------------------------------------------------------------------
2870
2871 #ifdef TEST_THREADS
2872
2873 #include <wx/thread.h>
2874
2875 static size_t gs_counter = (size_t)-1;
2876 static wxCriticalSection gs_critsect;
2877 static wxCondition gs_cond;
2878
2879 class MyJoinableThread : public wxThread
2880 {
2881 public:
2882 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
2883 { m_n = n; Create(); }
2884
2885 // thread execution starts here
2886 virtual ExitCode Entry();
2887
2888 private:
2889 size_t m_n;
2890 };
2891
2892 wxThread::ExitCode MyJoinableThread::Entry()
2893 {
2894 unsigned long res = 1;
2895 for ( size_t n = 1; n < m_n; n++ )
2896 {
2897 res *= n;
2898
2899 // it's a loooong calculation :-)
2900 Sleep(100);
2901 }
2902
2903 return (ExitCode)res;
2904 }
2905
2906 class MyDetachedThread : public wxThread
2907 {
2908 public:
2909 MyDetachedThread(size_t n, char ch)
2910 {
2911 m_n = n;
2912 m_ch = ch;
2913 m_cancelled = FALSE;
2914
2915 Create();
2916 }
2917
2918 // thread execution starts here
2919 virtual ExitCode Entry();
2920
2921 // and stops here
2922 virtual void OnExit();
2923
2924 private:
2925 size_t m_n; // number of characters to write
2926 char m_ch; // character to write
2927
2928 bool m_cancelled; // FALSE if we exit normally
2929 };
2930
2931 wxThread::ExitCode MyDetachedThread::Entry()
2932 {
2933 {
2934 wxCriticalSectionLocker lock(gs_critsect);
2935 if ( gs_counter == (size_t)-1 )
2936 gs_counter = 1;
2937 else
2938 gs_counter++;
2939 }
2940
2941 for ( size_t n = 0; n < m_n; n++ )
2942 {
2943 if ( TestDestroy() )
2944 {
2945 m_cancelled = TRUE;
2946
2947 break;
2948 }
2949
2950 putchar(m_ch);
2951 fflush(stdout);
2952
2953 wxThread::Sleep(100);
2954 }
2955
2956 return 0;
2957 }
2958
2959 void MyDetachedThread::OnExit()
2960 {
2961 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
2962
2963 wxCriticalSectionLocker lock(gs_critsect);
2964 if ( !--gs_counter && !m_cancelled )
2965 gs_cond.Signal();
2966 }
2967
2968 void TestDetachedThreads()
2969 {
2970 puts("\n*** Testing detached threads ***");
2971
2972 static const size_t nThreads = 3;
2973 MyDetachedThread *threads[nThreads];
2974 size_t n;
2975 for ( n = 0; n < nThreads; n++ )
2976 {
2977 threads[n] = new MyDetachedThread(10, 'A' + n);
2978 }
2979
2980 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
2981 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
2982
2983 for ( n = 0; n < nThreads; n++ )
2984 {
2985 threads[n]->Run();
2986 }
2987
2988 // wait until all threads terminate
2989 gs_cond.Wait();
2990
2991 puts("");
2992 }
2993
2994 void TestJoinableThreads()
2995 {
2996 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
2997
2998 // calc 10! in the background
2999 MyJoinableThread thread(10);
3000 thread.Run();
3001
3002 printf("\nThread terminated with exit code %lu.\n",
3003 (unsigned long)thread.Wait());
3004 }
3005
3006 void TestThreadSuspend()
3007 {
3008 puts("\n*** Testing thread suspend/resume functions ***");
3009
3010 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
3011
3012 thread->Run();
3013
3014 // this is for this demo only, in a real life program we'd use another
3015 // condition variable which would be signaled from wxThread::Entry() to
3016 // tell us that the thread really started running - but here just wait a
3017 // bit and hope that it will be enough (the problem is, of course, that
3018 // the thread might still not run when we call Pause() which will result
3019 // in an error)
3020 wxThread::Sleep(300);
3021
3022 for ( size_t n = 0; n < 3; n++ )
3023 {
3024 thread->Pause();
3025
3026 puts("\nThread suspended");
3027 if ( n > 0 )
3028 {
3029 // don't sleep but resume immediately the first time
3030 wxThread::Sleep(300);
3031 }
3032 puts("Going to resume the thread");
3033
3034 thread->Resume();
3035 }
3036
3037 puts("Waiting until it terminates now");
3038
3039 // wait until the thread terminates
3040 gs_cond.Wait();
3041
3042 puts("");
3043 }
3044
3045 void TestThreadDelete()
3046 {
3047 // As above, using Sleep() is only for testing here - we must use some
3048 // synchronisation object instead to ensure that the thread is still
3049 // running when we delete it - deleting a detached thread which already
3050 // terminated will lead to a crash!
3051
3052 puts("\n*** Testing thread delete function ***");
3053
3054 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
3055
3056 thread0->Delete();
3057
3058 puts("\nDeleted a thread which didn't start to run yet.");
3059
3060 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
3061
3062 thread1->Run();
3063
3064 wxThread::Sleep(300);
3065
3066 thread1->Delete();
3067
3068 puts("\nDeleted a running thread.");
3069
3070 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
3071
3072 thread2->Run();
3073
3074 wxThread::Sleep(300);
3075
3076 thread2->Pause();
3077
3078 thread2->Delete();
3079
3080 puts("\nDeleted a sleeping thread.");
3081
3082 MyJoinableThread thread3(20);
3083 thread3.Run();
3084
3085 thread3.Delete();
3086
3087 puts("\nDeleted a joinable thread.");
3088
3089 MyJoinableThread thread4(2);
3090 thread4.Run();
3091
3092 wxThread::Sleep(300);
3093
3094 thread4.Delete();
3095
3096 puts("\nDeleted a joinable thread which already terminated.");
3097
3098 puts("");
3099 }
3100
3101 #endif // TEST_THREADS
3102
3103 // ----------------------------------------------------------------------------
3104 // arrays
3105 // ----------------------------------------------------------------------------
3106
3107 #ifdef TEST_ARRAYS
3108
3109 static void PrintArray(const char* name, const wxArrayString& array)
3110 {
3111 printf("Dump of the array '%s'\n", name);
3112
3113 size_t nCount = array.GetCount();
3114 for ( size_t n = 0; n < nCount; n++ )
3115 {
3116 printf("\t%s[%u] = '%s'\n", name, n, array[n].c_str());
3117 }
3118 }
3119
3120 static int StringLenCompare(const wxString& first, const wxString& second)
3121 {
3122 return first.length() - second.length();
3123 }
3124
3125 #include "wx/dynarray.h"
3126
3127 WX_DECLARE_OBJARRAY(Bar, ArrayBars);
3128 #include "wx/arrimpl.cpp"
3129 WX_DEFINE_OBJARRAY(ArrayBars);
3130
3131 static void TestArrayOfObjects()
3132 {
3133 puts("*** Testing wxObjArray ***\n");
3134
3135 {
3136 ArrayBars bars;
3137 Bar bar("second bar");
3138
3139 printf("Initially: %u objects in the array, %u objects total.\n",
3140 bars.GetCount(), Bar::GetNumber());
3141
3142 bars.Add(new Bar("first bar"));
3143 bars.Add(bar);
3144
3145 printf("Now: %u objects in the array, %u objects total.\n",
3146 bars.GetCount(), Bar::GetNumber());
3147
3148 bars.Empty();
3149
3150 printf("After Empty(): %u objects in the array, %u objects total.\n",
3151 bars.GetCount(), Bar::GetNumber());
3152 }
3153
3154 printf("Finally: no more objects in the array, %u objects total.\n",
3155 Bar::GetNumber());
3156 }
3157
3158 #endif // TEST_ARRAYS
3159
3160 // ----------------------------------------------------------------------------
3161 // strings
3162 // ----------------------------------------------------------------------------
3163
3164 #ifdef TEST_STRINGS
3165
3166 #include "wx/timer.h"
3167 #include "wx/tokenzr.h"
3168
3169 static void TestStringConstruction()
3170 {
3171 puts("*** Testing wxString constructores ***");
3172
3173 #define TEST_CTOR(args, res) \
3174 { \
3175 wxString s args ; \
3176 printf("wxString%s = %s ", #args, s.c_str()); \
3177 if ( s == res ) \
3178 { \
3179 puts("(ok)"); \
3180 } \
3181 else \
3182 { \
3183 printf("(ERROR: should be %s)\n", res); \
3184 } \
3185 }
3186
3187 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
3188 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
3189 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
3190 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
3191
3192 static const wxChar *s = _T("?really!");
3193 const wxChar *start = wxStrchr(s, _T('r'));
3194 const wxChar *end = wxStrchr(s, _T('!'));
3195 TEST_CTOR((start, end), _T("really"));
3196
3197 puts("");
3198 }
3199
3200 static void TestString()
3201 {
3202 wxStopWatch sw;
3203
3204 wxString a, b, c;
3205
3206 a.reserve (128);
3207 b.reserve (128);
3208 c.reserve (128);
3209
3210 for (int i = 0; i < 1000000; ++i)
3211 {
3212 a = "Hello";
3213 b = " world";
3214 c = "! How'ya doin'?";
3215 a += b;
3216 a += c;
3217 c = "Hello world! What's up?";
3218 if (c != a)
3219 c = "Doh!";
3220 }
3221
3222 printf ("TestString elapsed time: %ld\n", sw.Time());
3223 }
3224
3225 static void TestPChar()
3226 {
3227 wxStopWatch sw;
3228
3229 char a [128];
3230 char b [128];
3231 char c [128];
3232
3233 for (int i = 0; i < 1000000; ++i)
3234 {
3235 strcpy (a, "Hello");
3236 strcpy (b, " world");
3237 strcpy (c, "! How'ya doin'?");
3238 strcat (a, b);
3239 strcat (a, c);
3240 strcpy (c, "Hello world! What's up?");
3241 if (strcmp (c, a) == 0)
3242 strcpy (c, "Doh!");
3243 }
3244
3245 printf ("TestPChar elapsed time: %ld\n", sw.Time());
3246 }
3247
3248 static void TestStringSub()
3249 {
3250 wxString s("Hello, world!");
3251
3252 puts("*** Testing wxString substring extraction ***");
3253
3254 printf("String = '%s'\n", s.c_str());
3255 printf("Left(5) = '%s'\n", s.Left(5).c_str());
3256 printf("Right(6) = '%s'\n", s.Right(6).c_str());
3257 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
3258 printf("Mid(3) = '%s'\n", s.Mid(3).c_str());
3259 printf("substr(3, 5) = '%s'\n", s.substr(3, 5).c_str());
3260 printf("substr(3) = '%s'\n", s.substr(3).c_str());
3261
3262 static const wxChar *prefixes[] =
3263 {
3264 _T("Hello"),
3265 _T("Hello, "),
3266 _T("Hello, world!"),
3267 _T("Hello, world!!!"),
3268 _T(""),
3269 _T("Goodbye"),
3270 _T("Hi"),
3271 };
3272
3273 for ( size_t n = 0; n < WXSIZEOF(prefixes); n++ )
3274 {
3275 wxString prefix = prefixes[n], rest;
3276 bool rc = s.StartsWith(prefix, &rest);
3277 printf("StartsWith('%s') = %s", prefix.c_str(), rc ? "TRUE" : "FALSE");
3278 if ( rc )
3279 {
3280 printf(" (the rest is '%s')\n", rest.c_str());
3281 }
3282 else
3283 {
3284 putchar('\n');
3285 }
3286 }
3287
3288 puts("");
3289 }
3290
3291 static void TestStringFormat()
3292 {
3293 puts("*** Testing wxString formatting ***");
3294
3295 wxString s;
3296 s.Printf("%03d", 18);
3297
3298 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
3299 printf("Number 18: %s\n", s.c_str());
3300
3301 puts("");
3302 }
3303
3304 // returns "not found" for npos, value for all others
3305 static wxString PosToString(size_t res)
3306 {
3307 wxString s = res == wxString::npos ? wxString(_T("not found"))
3308 : wxString::Format(_T("%u"), res);
3309 return s;
3310 }
3311
3312 static void TestStringFind()
3313 {
3314 puts("*** Testing wxString find() functions ***");
3315
3316 static const wxChar *strToFind = _T("ell");
3317 static const struct StringFindTest
3318 {
3319 const wxChar *str;
3320 size_t start,
3321 result; // of searching "ell" in str
3322 } findTestData[] =
3323 {
3324 { _T("Well, hello world"), 0, 1 },
3325 { _T("Well, hello world"), 6, 7 },
3326 { _T("Well, hello world"), 9, wxString::npos },
3327 };
3328
3329 for ( size_t n = 0; n < WXSIZEOF(findTestData); n++ )
3330 {
3331 const StringFindTest& ft = findTestData[n];
3332 size_t res = wxString(ft.str).find(strToFind, ft.start);
3333
3334 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
3335 strToFind, ft.str, ft.start, PosToString(res).c_str());
3336
3337 size_t resTrue = ft.result;
3338 if ( res == resTrue )
3339 {
3340 puts(_T("(ok)"));
3341 }
3342 else
3343 {
3344 printf(_T("(ERROR: should be %s)\n"),
3345 PosToString(resTrue).c_str());
3346 }
3347 }
3348
3349 puts("");
3350 }
3351
3352 static void TestStringTokenizer()
3353 {
3354 puts("*** Testing wxStringTokenizer ***");
3355
3356 static const wxChar *modeNames[] =
3357 {
3358 _T("default"),
3359 _T("return empty"),
3360 _T("return all empty"),
3361 _T("with delims"),
3362 _T("like strtok"),
3363 };
3364
3365 static const struct StringTokenizerTest
3366 {
3367 const wxChar *str; // string to tokenize
3368 const wxChar *delims; // delimiters to use
3369 size_t count; // count of token
3370 wxStringTokenizerMode mode; // how should we tokenize it
3371 } tokenizerTestData[] =
3372 {
3373 { _T(""), _T(" "), 0 },
3374 { _T("Hello, world"), _T(" "), 2 },
3375 { _T("Hello, world "), _T(" "), 2 },
3376 { _T("Hello, world"), _T(","), 2 },
3377 { _T("Hello, world!"), _T(",!"), 2 },
3378 { _T("Hello,, world!"), _T(",!"), 3 },
3379 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL },
3380 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
3381 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 4 },
3382 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 6, wxTOKEN_RET_EMPTY },
3383 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS, 9, wxTOKEN_RET_EMPTY_ALL },
3384 { _T("01/02/99"), _T("/-"), 3 },
3385 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS },
3386 };
3387
3388 for ( size_t n = 0; n < WXSIZEOF(tokenizerTestData); n++ )
3389 {
3390 const StringTokenizerTest& tt = tokenizerTestData[n];
3391 wxStringTokenizer tkz(tt.str, tt.delims, tt.mode);
3392
3393 size_t count = tkz.CountTokens();
3394 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
3395 MakePrintable(tt.str).c_str(),
3396 count,
3397 MakePrintable(tt.delims).c_str(),
3398 modeNames[tkz.GetMode()]);
3399 if ( count == tt.count )
3400 {
3401 puts(_T("(ok)"));
3402 }
3403 else
3404 {
3405 printf(_T("(ERROR: should be %u)\n"), tt.count);
3406
3407 continue;
3408 }
3409
3410 // if we emulate strtok(), check that we do it correctly
3411 wxChar *buf, *s = NULL, *last;
3412
3413 if ( tkz.GetMode() == wxTOKEN_STRTOK )
3414 {
3415 buf = new wxChar[wxStrlen(tt.str) + 1];
3416 wxStrcpy(buf, tt.str);
3417
3418 s = wxStrtok(buf, tt.delims, &last);
3419 }
3420 else
3421 {
3422 buf = NULL;
3423 }
3424
3425 // now show the tokens themselves
3426 size_t count2 = 0;
3427 while ( tkz.HasMoreTokens() )
3428 {
3429 wxString token = tkz.GetNextToken();
3430
3431 printf(_T("\ttoken %u: '%s'"),
3432 ++count2,
3433 MakePrintable(token).c_str());
3434
3435 if ( buf )
3436 {
3437 if ( token == s )
3438 {
3439 puts(" (ok)");
3440 }
3441 else
3442 {
3443 printf(" (ERROR: should be %s)\n", s);
3444 }
3445
3446 s = wxStrtok(NULL, tt.delims, &last);
3447 }
3448 else
3449 {
3450 // nothing to compare with
3451 puts("");
3452 }
3453 }
3454
3455 if ( count2 != count )
3456 {
3457 puts(_T("\tERROR: token count mismatch"));
3458 }
3459
3460 delete [] buf;
3461 }
3462
3463 puts("");
3464 }
3465
3466 static void TestStringReplace()
3467 {
3468 puts("*** Testing wxString::replace ***");
3469
3470 static const struct StringReplaceTestData
3471 {
3472 const wxChar *original; // original test string
3473 size_t start, len; // the part to replace
3474 const wxChar *replacement; // the replacement string
3475 const wxChar *result; // and the expected result
3476 } stringReplaceTestData[] =
3477 {
3478 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
3479 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
3480 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
3481 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
3482 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
3483 };
3484
3485 for ( size_t n = 0; n < WXSIZEOF(stringReplaceTestData); n++ )
3486 {
3487 const StringReplaceTestData data = stringReplaceTestData[n];
3488
3489 wxString original = data.original;
3490 original.replace(data.start, data.len, data.replacement);
3491
3492 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
3493 data.original, data.start, data.len, data.replacement,
3494 original.c_str());
3495
3496 if ( original == data.result )
3497 {
3498 puts("(ok)");
3499 }
3500 else
3501 {
3502 wxPrintf(_T("(ERROR: should be '%s')\n"), data.result);
3503 }
3504 }
3505
3506 puts("");
3507 }
3508
3509 #endif // TEST_STRINGS
3510
3511 // ----------------------------------------------------------------------------
3512 // entry point
3513 // ----------------------------------------------------------------------------
3514
3515 int main(int argc, char **argv)
3516 {
3517 if ( !wxInitialize() )
3518 {
3519 fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
3520 }
3521
3522 #ifdef TEST_USLEEP
3523 puts("Sleeping for 3 seconds... z-z-z-z-z...");
3524 wxUsleep(3000);
3525 #endif // TEST_USLEEP
3526
3527 #ifdef TEST_CMDLINE
3528 static const wxCmdLineEntryDesc cmdLineDesc[] =
3529 {
3530 { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
3531 { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" },
3532
3533 { wxCMD_LINE_OPTION, "o", "output", "output file" },
3534 { wxCMD_LINE_OPTION, "i", "input", "input dir" },
3535 { wxCMD_LINE_OPTION, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER },
3536 { wxCMD_LINE_OPTION, "d", "date", "output file date", wxCMD_LINE_VAL_DATE },
3537
3538 { wxCMD_LINE_PARAM, NULL, NULL, "input file",
3539 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
3540
3541 { wxCMD_LINE_NONE }
3542 };
3543
3544 wxCmdLineParser parser(cmdLineDesc, argc, argv);
3545
3546 parser.AddOption("project_name", "", "full path to project file",
3547 wxCMD_LINE_VAL_STRING,
3548 wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);
3549
3550 switch ( parser.Parse() )
3551 {
3552 case -1:
3553 wxLogMessage("Help was given, terminating.");
3554 break;
3555
3556 case 0:
3557 ShowCmdLine(parser);
3558 break;
3559
3560 default:
3561 wxLogMessage("Syntax error detected, aborting.");
3562 break;
3563 }
3564 #endif // TEST_CMDLINE
3565
3566 #ifdef TEST_STRINGS
3567 if ( 0 )
3568 {
3569 TestPChar();
3570 TestString();
3571 }
3572 TestStringSub();
3573 if ( 0 )
3574 {
3575 TestStringConstruction();
3576 TestStringFormat();
3577 TestStringFind();
3578 TestStringTokenizer();
3579 TestStringReplace();
3580 }
3581 #endif // TEST_STRINGS
3582
3583 #ifdef TEST_ARRAYS
3584 wxArrayString a1;
3585 a1.Add("tiger");
3586 a1.Add("cat");
3587 a1.Add("lion");
3588 a1.Add("dog");
3589 a1.Add("human");
3590 a1.Add("ape");
3591
3592 puts("*** Initially:");
3593
3594 PrintArray("a1", a1);
3595
3596 wxArrayString a2(a1);
3597 PrintArray("a2", a2);
3598
3599 wxSortedArrayString a3(a1);
3600 PrintArray("a3", a3);
3601
3602 puts("*** After deleting a string from a1");
3603 a1.Remove(2);
3604
3605 PrintArray("a1", a1);
3606 PrintArray("a2", a2);
3607 PrintArray("a3", a3);
3608
3609 puts("*** After reassigning a1 to a2 and a3");
3610 a3 = a2 = a1;
3611 PrintArray("a2", a2);
3612 PrintArray("a3", a3);
3613
3614 puts("*** After sorting a1");
3615 a1.Sort();
3616 PrintArray("a1", a1);
3617
3618 puts("*** After sorting a1 in reverse order");
3619 a1.Sort(TRUE);
3620 PrintArray("a1", a1);
3621
3622 puts("*** After sorting a1 by the string length");
3623 a1.Sort(StringLenCompare);
3624 PrintArray("a1", a1);
3625
3626 TestArrayOfObjects();
3627 #endif // TEST_ARRAYS
3628
3629 #ifdef TEST_DIR
3630 TestDirEnum();
3631 #endif // TEST_DIR
3632
3633 #ifdef TEST_DLLLOADER
3634 TestDllLoad();
3635 #endif // TEST_DLLLOADER
3636
3637 #ifdef TEST_EXECUTE
3638 TestExecute();
3639 #endif // TEST_EXECUTE
3640
3641 #ifdef TEST_FILECONF
3642 TestFileConfRead();
3643 #endif // TEST_FILECONF
3644
3645 #ifdef TEST_LIST
3646 TestListCtor();
3647 #endif // TEST_LIST
3648
3649 #ifdef TEST_LOG
3650 wxString s;
3651 for ( size_t n = 0; n < 8000; n++ )
3652 {
3653 s << (char)('A' + (n % 26));
3654 }
3655
3656 wxString msg;
3657 msg.Printf("A very very long message: '%s', the end!\n", s.c_str());
3658
3659 // this one shouldn't be truncated
3660 printf(msg);
3661
3662 // but this one will because log functions use fixed size buffer
3663 // (note that it doesn't need '\n' at the end neither - will be added
3664 // by wxLog anyhow)
3665 wxLogMessage("A very very long message 2: '%s', the end!", s.c_str());
3666 #endif // TEST_LOG
3667
3668 #ifdef TEST_FILE
3669 if ( 0 )
3670 TestFileRead();
3671 TestTextFileRead();
3672 #endif // TEST_FILE
3673
3674 #ifdef TEST_THREADS
3675 int nCPUs = wxThread::GetCPUCount();
3676 printf("This system has %d CPUs\n", nCPUs);
3677 if ( nCPUs != -1 )
3678 wxThread::SetConcurrency(nCPUs);
3679
3680 if ( argc > 1 && argv[1][0] == 't' )
3681 wxLog::AddTraceMask("thread");
3682
3683 if ( 1 )
3684 TestDetachedThreads();
3685 if ( 1 )
3686 TestJoinableThreads();
3687 if ( 1 )
3688 TestThreadSuspend();
3689 if ( 1 )
3690 TestThreadDelete();
3691
3692 #endif // TEST_THREADS
3693
3694 #ifdef TEST_LONGLONG
3695 // seed pseudo random generator
3696 srand((unsigned)time(NULL));
3697
3698 if ( 0 )
3699 {
3700 TestSpeed();
3701 }
3702 if ( 0 )
3703 {
3704 TestMultiplication();
3705 TestDivision();
3706 TestAddition();
3707 TestLongLongConversion();
3708 TestBitOperations();
3709 }
3710 TestLongLongComparison();
3711 #endif // TEST_LONGLONG
3712
3713 #ifdef TEST_HASH
3714 TestHash();
3715 #endif // TEST_HASH
3716
3717 #ifdef TEST_MIME
3718 wxLog::AddTraceMask(_T("mime"));
3719 if ( 0 )
3720 TestMimeEnum();
3721 TestMimeOverride();
3722 TestMimeFilename();
3723 #endif // TEST_MIME
3724
3725 #ifdef TEST_INFO_FUNCTIONS
3726 TestOsInfo();
3727 TestUserInfo();
3728 #endif // TEST_INFO_FUNCTIONS
3729
3730 #ifdef TEST_REGISTRY
3731 if ( 0 )
3732 TestRegistryRead();
3733 TestRegistryAssociation();
3734 #endif // TEST_REGISTRY
3735
3736 #ifdef TEST_SOCKETS
3737 if ( 0 )
3738 {
3739 TestSocketServer();
3740 TestSocketClient();
3741 TestProtocolFtp();
3742 }
3743 TestProtocolFtpUpload();
3744 #endif // TEST_SOCKETS
3745
3746 #ifdef TEST_STREAMS
3747 TestMemoryStream();
3748 #endif // TEST_STREAMS
3749
3750 #ifdef TEST_TIMER
3751 TestStopWatch();
3752 #endif // TEST_TIMER
3753
3754 #ifdef TEST_DATETIME
3755 if ( 0 )
3756 {
3757 TestTimeSet();
3758 TestTimeStatic();
3759 TestTimeRange();
3760 TestTimeZones();
3761 TestTimeTicks();
3762 TestTimeJDN();
3763 TestTimeDST();
3764 TestTimeWDays();
3765 TestTimeWNumber();
3766 TestTimeParse();
3767 TestTimeArithmetics();
3768 TestTimeHolidays();
3769 TestTimeFormat();
3770 TestTimeMS();
3771
3772 TestTimeZoneBug();
3773 }
3774 if ( 0 )
3775 TestInteractive();
3776 #endif // TEST_DATETIME
3777
3778 #ifdef TEST_VCARD
3779 if ( 0 )
3780 TestVCardRead();
3781 TestVCardWrite();
3782 #endif // TEST_VCARD
3783
3784 #ifdef TEST_WCHAR
3785 TestUtf8();
3786 #endif // TEST_WCHAR
3787
3788 #ifdef TEST_ZIP
3789 TestZipStreamRead();
3790 #endif // TEST_ZIP
3791
3792 #ifdef TEST_ZLIB
3793 if ( 0 )
3794 TestZlibStreamWrite();
3795 TestZlibStreamRead();
3796 #endif // TEST_ZLIB
3797
3798 wxUninitialize();
3799
3800 return 0;
3801 }
3802