]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
implemented wxLongLong division - seems to work
[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 // ----------------------------------------------------------------------------
27 // conditional compilation
28 // ----------------------------------------------------------------------------
29
30 // what to test?
31
32 //#define TEST_ARRAYS
33 //#define TEST_DIR
34 //#define TEST_LOG
35 //#define TEST_LONGLONG
36 //#define TEST_MIME
37 //#define TEST_STRINGS
38 //#define TEST_THREADS
39 #define TEST_TIME
40
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // wxDir
47 // ----------------------------------------------------------------------------
48
49 #ifdef TEST_DIR
50
51 #include <wx/dir.h>
52
53 static void TestDirEnumHelper(wxDir& dir,
54 int flags = wxDIR_DEFAULT,
55 const wxString& filespec = wxEmptyString)
56 {
57 wxString filename;
58
59 if ( !dir.IsOpened() )
60 return;
61
62 bool cont = dir.GetFirst(&filename, filespec, flags);
63 while ( cont )
64 {
65 printf("\t%s\n", filename.c_str());
66
67 cont = dir.GetNext(&filename);
68 }
69
70 puts("");
71 }
72
73 static void TestDirEnum()
74 {
75 wxDir dir(wxGetCwd());
76
77 puts("Enumerating everything in current directory:");
78 TestDirEnumHelper(dir);
79
80 puts("Enumerating really everything in current directory:");
81 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
82
83 puts("Enumerating object files in current directory:");
84 TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o");
85
86 puts("Enumerating directories in current directory:");
87 TestDirEnumHelper(dir, wxDIR_DIRS);
88
89 puts("Enumerating files in current directory:");
90 TestDirEnumHelper(dir, wxDIR_FILES);
91
92 puts("Enumerating files including hidden in current directory:");
93 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
94
95 #ifdef __UNIX__
96 dir.Open("/");
97 #elif defined(__WXMSW__)
98 dir.Open("c:\\");
99 #else
100 #error "don't know where the root directory is"
101 #endif
102
103 puts("Enumerating everything in root directory:");
104 TestDirEnumHelper(dir, wxDIR_DEFAULT);
105
106 puts("Enumerating directories in root directory:");
107 TestDirEnumHelper(dir, wxDIR_DIRS);
108
109 puts("Enumerating files in root directory:");
110 TestDirEnumHelper(dir, wxDIR_FILES);
111
112 puts("Enumerating files including hidden in root directory:");
113 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
114
115 puts("Enumerating files in non existing directory:");
116 wxDir dirNo("nosuchdir");
117 TestDirEnumHelper(dirNo);
118 }
119
120 #endif // TEST_DIR
121
122 // ----------------------------------------------------------------------------
123 // MIME types
124 // ----------------------------------------------------------------------------
125
126 #ifdef TEST_MIME
127
128 #include <wx/mimetype.h>
129
130 static void TestMimeEnum()
131 {
132 wxMimeTypesManager mimeTM;
133 wxArrayString mimetypes;
134
135 size_t count = mimeTM.EnumAllFileTypes(mimetypes);
136
137 printf("*** All %u known filetypes: ***\n", count);
138
139 wxArrayString exts;
140 wxString desc;
141
142 for ( size_t n = 0; n < count; n++ )
143 {
144 wxFileType *filetype = mimeTM.GetFileTypeFromMimeType(mimetypes[n]);
145 if ( !filetype )
146 {
147 printf("nothing known about the filetype '%s'!\n",
148 mimetypes[n].c_str());
149 continue;
150 }
151
152 filetype->GetDescription(&desc);
153 filetype->GetExtensions(exts);
154
155 filetype->GetIcon(NULL);
156
157 wxString extsAll;
158 for ( size_t e = 0; e < exts.GetCount(); e++ )
159 {
160 if ( e > 0 )
161 extsAll << _T(", ");
162 extsAll += exts[e];
163 }
164
165 printf("\t%s: %s (%s)\n",
166 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
167 }
168 }
169
170 #endif // TEST_MIME
171
172 // ----------------------------------------------------------------------------
173 // long long
174 // ----------------------------------------------------------------------------
175
176 #ifdef TEST_LONGLONG
177
178 #include <wx/longlong.h>
179 #include <wx/timer.h>
180
181 static void TestSpeed()
182 {
183 static const long max = 100000000;
184 long n;
185
186 {
187 wxStopWatch sw;
188
189 long l = 0;
190 for ( n = 0; n < max; n++ )
191 {
192 l += n;
193 }
194
195 printf("Summing longs took %ld milliseconds.\n", sw.Time());
196 }
197
198 #if wxUSE_LONGLONG_NATIVE
199 {
200 wxStopWatch sw;
201
202 wxLongLong_t l = 0;
203 for ( n = 0; n < max; n++ )
204 {
205 l += n;
206 }
207
208 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw.Time());
209 }
210 #endif // wxUSE_LONGLONG_NATIVE
211
212 {
213 wxStopWatch sw;
214
215 wxLongLong l;
216 for ( n = 0; n < max; n++ )
217 {
218 l += n;
219 }
220
221 printf("Summing wxLongLongs took %ld milliseconds.\n", sw.Time());
222 }
223 }
224
225 static void TestDivision()
226 {
227 puts("*** Testing wxLongLong division ***\n");
228
229 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
230
231 // seed pseudo random generator
232 srand((unsigned)time(NULL));
233
234 wxLongLong q, r;
235 size_t nTested = 0;
236 for ( size_t n = 0; n < 100000; n++ )
237 {
238 // get a random wxLongLong (shifting by 12 the MSB ensures that the
239 // multiplication will not overflow)
240 wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
241
242 // get a random long (not wxLongLong for now) to divide it with
243 long l = rand();
244 q = ll / l;
245 r = ll % l;
246
247 // verify the result
248 wxASSERT_MSG( ll == q*l + r, "division failure" );
249
250 if ( !(nTested % 1000) )
251 {
252 putchar('.');
253 fflush(stdout);
254 }
255
256 nTested++;
257 }
258
259 puts(" done!");
260
261 #undef MAKE_LL
262 }
263
264 #endif // TEST_LONGLONG
265
266 // ----------------------------------------------------------------------------
267 // date time
268 // ----------------------------------------------------------------------------
269
270 #ifdef TEST_TIME
271
272 #include <wx/date.h>
273
274 #include <wx/datetime.h>
275
276 // the test data
277 struct Date
278 {
279 wxDateTime::wxDateTime_t day;
280 wxDateTime::Month month;
281 int year;
282 wxDateTime::wxDateTime_t hour, min, sec;
283 double jdn;
284 wxDateTime::WeekDay wday;
285 time_t gmticks, ticks;
286
287 void Init(const wxDateTime::Tm& tm)
288 {
289 day = tm.mday;
290 month = tm.mon;
291 year = tm.year;
292 hour = tm.hour;
293 min = tm.min;
294 sec = tm.sec;
295 jdn = 0.0;
296 gmticks = ticks = -1;
297 }
298
299 wxDateTime DT() const
300 { return wxDateTime(day, month, year, hour, min, sec); }
301
302 bool SameDay(const wxDateTime::Tm& tm) const
303 {
304 return day == tm.mday && month == tm.mon && year == tm.year;
305 }
306
307 wxString Format() const
308 {
309 wxString s;
310 s.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
311 hour, min, sec,
312 wxDateTime::GetMonthName(month).c_str(),
313 day,
314 abs(wxDateTime::ConvertYearToBC(year)),
315 year > 0 ? "AD" : "BC");
316 return s;
317 }
318
319 wxString FormatDate() const
320 {
321 wxString s;
322 s.Printf("%02d-%s-%4d%s",
323 day,
324 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
325 abs(wxDateTime::ConvertYearToBC(year)),
326 year > 0 ? "AD" : "BC");
327 return s;
328 }
329 };
330
331 static const Date testDates[] =
332 {
333 { 1, wxDateTime::Jan, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu, 0, -3600 },
334 { 21, wxDateTime::Jan, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon, -1, -1 },
335 { 29, wxDateTime::May, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat, 202219200, 202212000 },
336 { 29, wxDateTime::Feb, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun, 194400000, 194396400 },
337 { 1, wxDateTime::Jan, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon, -1, -1 },
338 { 1, wxDateTime::Jan, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon, -1, -1 },
339 { 15, wxDateTime::Oct, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri, -1, -1 },
340 { 4, wxDateTime::Oct, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon, -1, -1 },
341 { 1, wxDateTime::Mar, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu, -1, -1 },
342 { 1, wxDateTime::Jan, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon, -1, -1 },
343 { 31, wxDateTime::Dec, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun, -1, -1 },
344 { 1, wxDateTime::Jan, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat, -1, -1 },
345 { 12, wxDateTime::Aug, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri, -1, -1 },
346 { 12, wxDateTime::Aug, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat, -1, -1 },
347 { 24, wxDateTime::Nov, -4713, 00, 00, 00, -0.5, wxDateTime::Mon, -1, -1 },
348 };
349
350 // this test miscellaneous static wxDateTime functions
351 static void TestTimeStatic()
352 {
353 puts("\n*** wxDateTime static methods test ***");
354
355 // some info about the current date
356 int year = wxDateTime::GetCurrentYear();
357 printf("Current year %d is %sa leap one and has %d days.\n",
358 year,
359 wxDateTime::IsLeapYear(year) ? "" : "not ",
360 wxDateTime::GetNumberOfDays(year));
361
362 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
363 printf("Current month is '%s' ('%s') and it has %d days\n",
364 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
365 wxDateTime::GetMonthName(month).c_str(),
366 wxDateTime::GetNumberOfDays(month));
367
368 // leap year logic
369 static const size_t nYears = 5;
370 static const size_t years[2][nYears] =
371 {
372 // first line: the years to test
373 { 1990, 1976, 2000, 2030, 1984, },
374
375 // second line: TRUE if leap, FALSE otherwise
376 { FALSE, TRUE, TRUE, FALSE, TRUE }
377 };
378
379 for ( size_t n = 0; n < nYears; n++ )
380 {
381 int year = years[0][n];
382 bool should = years[1][n] != 0,
383 is = wxDateTime::IsLeapYear(year);
384
385 printf("Year %d is %sa leap year (%s)\n",
386 year,
387 is ? "" : "not ",
388 should == is ? "ok" : "ERROR");
389
390 wxASSERT( should == wxDateTime::IsLeapYear(year) );
391 }
392 }
393
394 // test constructing wxDateTime objects
395 static void TestTimeSet()
396 {
397 puts("\n*** wxDateTime construction test ***");
398
399 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
400 {
401 const Date& d1 = testDates[n];
402 wxDateTime dt = d1.DT();
403
404 Date d2;
405 d2.Init(dt.GetTm());
406
407 wxString s1 = d1.Format(),
408 s2 = d2.Format();
409
410 printf("Date: %s == %s (%s)\n",
411 s1.c_str(), s2.c_str(),
412 s1 == s2 ? "ok" : "ERROR");
413 }
414 }
415
416 // test time zones stuff
417 static void TestTimeZones()
418 {
419 puts("\n*** wxDateTime timezone test ***");
420
421 wxDateTime now = wxDateTime::Now();
422
423 printf("Current GMT time:\t%s\n", now.Format("%c", wxDateTime::GMT0).c_str());
424 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0).c_str());
425 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST).c_str());
426 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
427 printf(" Moscow:\t%s\n", now.Format("%c", wxDateTime::MSK).c_str());
428 printf(" New York:\t%s\n", now.Format("%c", wxDateTime::EST).c_str());
429 }
430
431 // test some minimal support for the dates outside the standard range
432 static void TestTimeRange()
433 {
434 puts("\n*** wxDateTime out-of-standard-range dates test ***");
435
436 static const char *fmt = "%d-%b-%Y %H:%M:%S";
437
438 printf("Unix epoch:\t%s\n",
439 wxDateTime(2440587.5).Format(fmt).c_str());
440 printf("Feb 29, 0: \t%s\n",
441 wxDateTime(29, wxDateTime::Feb, 0).Format(fmt).c_str());
442 printf("JDN 0: \t%s\n",
443 wxDateTime(0.0).Format(fmt).c_str());
444 printf("Jan 1, 1AD:\t%s\n",
445 wxDateTime(1, wxDateTime::Jan, 1).Format(fmt).c_str());
446 printf("May 29, 2099:\t%s\n",
447 wxDateTime(29, wxDateTime::May, 2099).Format(fmt).c_str());
448 }
449
450 static void TestTimeTicks()
451 {
452 puts("\n*** wxDateTime ticks test ***");
453
454 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
455 {
456 const Date& d = testDates[n];
457 if ( d.ticks == -1 )
458 continue;
459
460 wxDateTime dt = d.DT();
461 long ticks = (dt.GetValue() / 1000).ToLong();
462 printf("Ticks of %s:\t% 10ld", d.Format().c_str(), ticks);
463 if ( ticks == d.ticks )
464 {
465 puts(" (ok)");
466 }
467 else
468 {
469 printf(" (ERROR: should be %ld, delta = %ld)\n",
470 d.ticks, ticks - d.ticks);
471 }
472
473 dt = d.DT().ToTimezone(wxDateTime::GMT0);
474 ticks = (dt.GetValue() / 1000).ToLong();
475 printf("GMtks of %s:\t% 10ld", d.Format().c_str(), ticks);
476 if ( ticks == d.gmticks )
477 {
478 puts(" (ok)");
479 }
480 else
481 {
482 printf(" (ERROR: should be %ld, delta = %ld)\n",
483 d.gmticks, ticks - d.gmticks);
484 }
485 }
486
487 puts("");
488 }
489
490 // test conversions to JDN &c
491 static void TestTimeJDN()
492 {
493 puts("\n*** wxDateTime to JDN test ***");
494
495 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
496 {
497 const Date& d = testDates[n];
498 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
499 double jdn = dt.GetJulianDayNumber();
500
501 printf("JDN of %s is:\t% 15.6f", d.Format().c_str(), jdn);
502 if ( jdn == d.jdn )
503 {
504 puts(" (ok)");
505 }
506 else
507 {
508 printf(" (ERROR: should be %f, delta = %f)\n",
509 d.jdn, jdn - d.jdn);
510 }
511 }
512 }
513
514 // test week days computation
515 static void TestTimeWDays()
516 {
517 puts("\n*** wxDateTime weekday test ***");
518
519 // test GetWeekDay()
520 size_t n;
521 for ( n = 0; n < WXSIZEOF(testDates); n++ )
522 {
523 const Date& d = testDates[n];
524 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
525
526 wxDateTime::WeekDay wday = dt.GetWeekDay();
527 printf("%s is: %s",
528 d.Format().c_str(),
529 wxDateTime::GetWeekDayName(wday).c_str());
530 if ( wday == d.wday )
531 {
532 puts(" (ok)");
533 }
534 else
535 {
536 printf(" (ERROR: should be %s)\n",
537 wxDateTime::GetWeekDayName(d.wday).c_str());
538 }
539 }
540
541 puts("");
542
543 // test SetToWeekDay()
544 struct WeekDateTestData
545 {
546 Date date; // the real date (precomputed)
547 int nWeek; // its week index in the month
548 wxDateTime::WeekDay wday; // the weekday
549 wxDateTime::Month month; // the month
550 int year; // and the year
551
552 wxString Format() const
553 {
554 wxString s, which;
555 switch ( nWeek < -1 ? -nWeek : nWeek )
556 {
557 case 1: which = "first"; break;
558 case 2: which = "second"; break;
559 case 3: which = "third"; break;
560 case 4: which = "fourth"; break;
561 case 5: which = "fifth"; break;
562
563 case -1: which = "last"; break;
564 }
565
566 if ( nWeek < -1 )
567 {
568 which += " from end";
569 }
570
571 s.Printf("The %s %s of %s in %d",
572 which.c_str(),
573 wxDateTime::GetWeekDayName(wday).c_str(),
574 wxDateTime::GetMonthName(month).c_str(),
575 year);
576
577 return s;
578 }
579 };
580
581 // the array data was generated by the following python program
582 /*
583 from DateTime import *
584 from whrandom import *
585 from string import *
586
587 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
588 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
589
590 week = DateTimeDelta(7)
591
592 for n in range(20):
593 year = randint(1900, 2100)
594 month = randint(1, 12)
595 day = randint(1, 28)
596 dt = DateTime(year, month, day)
597 wday = dt.day_of_week
598
599 countFromEnd = choice([-1, 1])
600 weekNum = 0;
601
602 while dt.month is month:
603 dt = dt - countFromEnd * week
604 weekNum = weekNum + countFromEnd
605
606 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
607
608 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
609 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
610 */
611
612 static const WeekDateTestData weekDatesTestData[] =
613 {
614 { { 20, wxDateTime::Mar, 2045 }, 3, wxDateTime::Mon, wxDateTime::Mar, 2045 },
615 { { 5, wxDateTime::Jun, 1985 }, -4, wxDateTime::Wed, wxDateTime::Jun, 1985 },
616 { { 12, wxDateTime::Nov, 1961 }, -3, wxDateTime::Sun, wxDateTime::Nov, 1961 },
617 { { 27, wxDateTime::Feb, 2093 }, -1, wxDateTime::Fri, wxDateTime::Feb, 2093 },
618 { { 4, wxDateTime::Jul, 2070 }, -4, wxDateTime::Fri, wxDateTime::Jul, 2070 },
619 { { 2, wxDateTime::Apr, 1906 }, -5, wxDateTime::Mon, wxDateTime::Apr, 1906 },
620 { { 19, wxDateTime::Jul, 2023 }, -2, wxDateTime::Wed, wxDateTime::Jul, 2023 },
621 { { 5, wxDateTime::May, 1958 }, -4, wxDateTime::Mon, wxDateTime::May, 1958 },
622 { { 11, wxDateTime::Aug, 1900 }, 2, wxDateTime::Sat, wxDateTime::Aug, 1900 },
623 { { 14, wxDateTime::Feb, 1945 }, 2, wxDateTime::Wed, wxDateTime::Feb, 1945 },
624 { { 25, wxDateTime::Jul, 1967 }, -1, wxDateTime::Tue, wxDateTime::Jul, 1967 },
625 { { 9, wxDateTime::May, 1916 }, -4, wxDateTime::Tue, wxDateTime::May, 1916 },
626 { { 20, wxDateTime::Jun, 1927 }, 3, wxDateTime::Mon, wxDateTime::Jun, 1927 },
627 { { 2, wxDateTime::Aug, 2000 }, 1, wxDateTime::Wed, wxDateTime::Aug, 2000 },
628 { { 20, wxDateTime::Apr, 2044 }, 3, wxDateTime::Wed, wxDateTime::Apr, 2044 },
629 { { 20, wxDateTime::Feb, 1932 }, -2, wxDateTime::Sat, wxDateTime::Feb, 1932 },
630 { { 25, wxDateTime::Jul, 2069 }, 4, wxDateTime::Thu, wxDateTime::Jul, 2069 },
631 { { 3, wxDateTime::Apr, 1925 }, 1, wxDateTime::Fri, wxDateTime::Apr, 1925 },
632 { { 21, wxDateTime::Mar, 2093 }, 3, wxDateTime::Sat, wxDateTime::Mar, 2093 },
633 { { 3, wxDateTime::Dec, 2074 }, -5, wxDateTime::Mon, wxDateTime::Dec, 2074 },
634 };
635
636 static const char *fmt = "%d-%b-%Y";
637
638 wxDateTime dt;
639 for ( n = 0; n < WXSIZEOF(weekDatesTestData); n++ )
640 {
641 const WeekDateTestData& wd = weekDatesTestData[n];
642
643 dt.SetToWeekDay(wd.wday, wd.nWeek, wd.month, wd.year);
644
645 printf("%s is %s", wd.Format().c_str(), dt.Format(fmt).c_str());
646
647 const Date& d = wd.date;
648 if ( d.SameDay(dt.GetTm()) )
649 {
650 puts(" (ok)");
651 }
652 else
653 {
654 dt.Set(d.day, d.month, d.year);
655
656 printf(" (ERROR: should be %s)\n", dt.Format(fmt).c_str());
657 }
658 }
659 }
660
661 // test the computation of (ISO) week numbers
662 static void TestTimeWNumber()
663 {
664 puts("\n*** wxDateTime week number test ***");
665
666 struct WeekNumberTestData
667 {
668 Date date; // the date
669 wxDateTime::wxDateTime_t week; // the week number
670 wxDateTime::wxDateTime_t dnum; // day number in the year
671 };
672
673 // data generated with the following python script:
674 /*
675 from DateTime import *
676 from whrandom import *
677 from string import *
678
679 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
680 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
681
682 for n in range(20):
683 year = randint(1900, 2100)
684 month = randint(1, 12)
685 day = randint(1, 28)
686 dt = DateTime(year, month, day)
687 dayNum = dt.day_of_year
688 weekNum = dt.iso_week[1]
689
690 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'dayNum': rjust(`dayNum`, 3) }
691
692 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)s, "\
693 "%(dayNum)s }," % data
694 */
695 static const WeekNumberTestData weekNumberTestDates[] =
696 {
697 { { 2, wxDateTime::Jul, 2093 }, 27, 183 },
698 { { 25, wxDateTime::Jun, 1986 }, 26, 176 },
699 { { 15, wxDateTime::Jun, 2014 }, 24, 166 },
700 { { 20, wxDateTime::Jul, 2018 }, 29, 201 },
701 { { 3, wxDateTime::Aug, 2074 }, 31, 215 },
702 { { 26, wxDateTime::Jul, 2012 }, 30, 208 },
703 { { 4, wxDateTime::Nov, 1915 }, 44, 308 },
704 { { 11, wxDateTime::Feb, 2035 }, 6, 42 },
705 { { 15, wxDateTime::Feb, 1942 }, 7, 46 },
706 { { 5, wxDateTime::Jan, 2087 }, 1, 5 },
707 { { 6, wxDateTime::Nov, 2016 }, 44, 311 },
708 { { 6, wxDateTime::Jun, 2057 }, 23, 157 },
709 { { 25, wxDateTime::Feb, 1976 }, 9, 56 },
710 { { 12, wxDateTime::Jan, 2073 }, 2, 12 },
711 { { 12, wxDateTime::Sep, 2040 }, 37, 256 },
712 { { 15, wxDateTime::Jul, 1931 }, 29, 196 },
713 { { 23, wxDateTime::Mar, 2084 }, 12, 83 },
714 { { 12, wxDateTime::Dec, 1970 }, 50, 346 },
715 { { 6, wxDateTime::Sep, 1996 }, 36, 250 },
716 { { 7, wxDateTime::Jan, 2076 }, 2, 7 },
717 };
718
719 for ( size_t n = 0; n < WXSIZEOF(weekNumberTestDates); n++ )
720 {
721 const WeekNumberTestData& wn = weekNumberTestDates[n];
722 const Date& d = wn.date;
723
724 wxDateTime dt = d.DT();
725
726 wxDateTime::wxDateTime_t week = dt.GetWeekOfYear(),
727 dnum = dt.GetDayOfYear();
728
729 printf("%s: the day number is %d",
730 d.FormatDate().c_str(), dnum);
731 if ( dnum == wn.dnum )
732 {
733 printf(" (ok)");
734 }
735 else
736 {
737 printf(" (ERROR: should be %d)", wn.dnum);
738 }
739
740 printf(", week number is %d", week);
741 if ( week == wn.week )
742 {
743 puts(" (ok)");
744 }
745 else
746 {
747 printf(" (ERROR: should be %d)\n", wn.week);
748 }
749 }
750 }
751
752 // test DST calculations
753 static void TestTimeDST()
754 {
755 puts("\n*** wxDateTime DST test ***");
756
757 printf("DST is%s in effect now.\n\n",
758 wxDateTime::Now().IsDST() ? "" : " not");
759
760 // taken from http://www.energy.ca.gov/daylightsaving.html
761 static const Date datesDST[2][2004 - 1900 + 1] =
762 {
763 {
764 { 1, wxDateTime::Apr, 1990 },
765 { 7, wxDateTime::Apr, 1991 },
766 { 5, wxDateTime::Apr, 1992 },
767 { 4, wxDateTime::Apr, 1993 },
768 { 3, wxDateTime::Apr, 1994 },
769 { 2, wxDateTime::Apr, 1995 },
770 { 7, wxDateTime::Apr, 1996 },
771 { 6, wxDateTime::Apr, 1997 },
772 { 5, wxDateTime::Apr, 1998 },
773 { 4, wxDateTime::Apr, 1999 },
774 { 2, wxDateTime::Apr, 2000 },
775 { 1, wxDateTime::Apr, 2001 },
776 { 7, wxDateTime::Apr, 2002 },
777 { 6, wxDateTime::Apr, 2003 },
778 { 4, wxDateTime::Apr, 2004 },
779 },
780 {
781 { 28, wxDateTime::Oct, 1990 },
782 { 27, wxDateTime::Oct, 1991 },
783 { 25, wxDateTime::Oct, 1992 },
784 { 31, wxDateTime::Oct, 1993 },
785 { 30, wxDateTime::Oct, 1994 },
786 { 29, wxDateTime::Oct, 1995 },
787 { 27, wxDateTime::Oct, 1996 },
788 { 26, wxDateTime::Oct, 1997 },
789 { 25, wxDateTime::Oct, 1998 },
790 { 31, wxDateTime::Oct, 1999 },
791 { 29, wxDateTime::Oct, 2000 },
792 { 28, wxDateTime::Oct, 2001 },
793 { 27, wxDateTime::Oct, 2002 },
794 { 26, wxDateTime::Oct, 2003 },
795 { 31, wxDateTime::Oct, 2004 },
796 }
797 };
798
799 int year;
800 for ( year = 1990; year < 2005; year++ )
801 {
802 wxDateTime dtBegin = wxDateTime::GetBeginDST(year, wxDateTime::USA),
803 dtEnd = wxDateTime::GetEndDST(year, wxDateTime::USA);
804
805 printf("DST period in the US for year %d: from %s to %s",
806 year, dtBegin.Format().c_str(), dtEnd.Format().c_str());
807
808 size_t n = year - 1990;
809 const Date& dBegin = datesDST[0][n];
810 const Date& dEnd = datesDST[1][n];
811
812 if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
813 {
814 puts(" (ok)");
815 }
816 else
817 {
818 printf(" (ERROR: should be %s %d to %s %d)\n",
819 wxDateTime::GetMonthName(dBegin.month).c_str(), dBegin.day,
820 wxDateTime::GetMonthName(dEnd.month).c_str(), dEnd.day);
821 }
822 }
823
824 puts("");
825
826 for ( year = 1990; year < 2005; year++ )
827 {
828 printf("DST period in Europe for year %d: from %s to %s\n",
829 year,
830 wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
831 wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
832 }
833 }
834
835 // test wxDateTime -> text conversion
836 static void TestTimeFormat()
837 {
838 puts("\n*** wxDateTime formatting test ***");
839
840 // some information may be lost during conversion, so store what kind
841 // of info should we recover after a round trip
842 enum CompareKind
843 {
844 CompareNone, // don't try comparing
845 CompareBoth, // dates and times should be identical
846 CompareDate, // dates only
847 CompareTime // time only
848 };
849
850 static const struct
851 {
852 CompareKind compareKind;
853 const char *format;
854 } formatTestFormats[] =
855 {
856 { CompareBoth, "---> %c" },
857 { CompareDate, "Date is %A, %d of %B, in year %Y" },
858 { CompareBoth, "Date is %x, time is %X" },
859 { CompareTime, "Time is %H:%M:%S or %I:%M:%S %p" },
860 { CompareNone, "The day of year: %j, the week of year: %W" },
861 };
862
863 static const Date formatTestDates[] =
864 {
865 { 29, wxDateTime::May, 1976, 18, 30, 00 },
866 { 31, wxDateTime::Dec, 1999, 23, 30, 00 },
867 #if 0
868 // this test can't work for other centuries because it uses two digit
869 // years in formats, so don't even try it
870 { 29, wxDateTime::May, 2076, 18, 30, 00 },
871 { 29, wxDateTime::Feb, 2400, 02, 15, 25 },
872 { 01, wxDateTime::Jan, -52, 03, 16, 47 },
873 #endif
874 };
875
876 // an extra test (as it doesn't depend on date, don't do it in the loop)
877 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
878
879 for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ )
880 {
881 puts("");
882
883 wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT();
884 for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
885 {
886 wxString s = dt.Format(formatTestFormats[n].format);
887 printf("%s", s.c_str());
888
889 // what can we recover?
890 int kind = formatTestFormats[n].compareKind;
891
892 // convert back
893 wxDateTime dt2;
894 const wxChar *result = dt2.ParseFormat(s, formatTestFormats[n].format);
895 if ( !result )
896 {
897 // converion failed - should it have?
898 if ( kind == CompareNone )
899 puts(" (ok)");
900 else
901 puts(" (ERROR: conversion back failed)");
902 }
903 else if ( *result )
904 {
905 // should have parsed the entire string
906 puts(" (ERROR: conversion back stopped too soon)");
907 }
908 else
909 {
910 bool equal = FALSE; // suppress compilaer warning
911 switch ( kind )
912 {
913 case CompareBoth:
914 equal = dt2 == dt;
915 break;
916
917 case CompareDate:
918 equal = dt.IsSameDate(dt2);
919 break;
920
921 case CompareTime:
922 equal = dt.IsSameTime(dt2);
923 break;
924 }
925
926 if ( !equal )
927 {
928 printf(" (ERROR: got back '%s' instead of '%s')\n",
929 dt2.Format().c_str(), dt.Format().c_str());
930 }
931 else
932 {
933 puts(" (ok)");
934 }
935 }
936 }
937 }
938 }
939
940 // test text -> wxDateTime conversion
941 static void TestTimeParse()
942 {
943 puts("\n*** wxDateTime parse test ***");
944
945 struct ParseTestData
946 {
947 const char *format;
948 Date date;
949 bool good;
950 };
951
952 static const ParseTestData parseTestDates[] =
953 {
954 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, TRUE },
955 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec, 1999, 03, 17, 20 }, TRUE },
956 };
957
958 for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
959 {
960 const char *format = parseTestDates[n].format;
961
962 printf("%s => ", format);
963
964 wxDateTime dt;
965 if ( dt.ParseRfc822Date(format) )
966 {
967 printf("%s ", dt.Format().c_str());
968
969 if ( parseTestDates[n].good )
970 {
971 wxDateTime dtReal = parseTestDates[n].date.DT();
972 if ( dt == dtReal )
973 {
974 puts("(ok)");
975 }
976 else
977 {
978 printf("(ERROR: should be %s)\n", dtReal.Format().c_str());
979 }
980 }
981 else
982 {
983 puts("(ERROR: bad format)");
984 }
985 }
986 else
987 {
988 printf("bad format (%s)\n",
989 parseTestDates[n].good ? "ERROR" : "ok");
990 }
991 }
992 }
993
994 #if 0
995
996 // test compatibility with the old wxDate/wxTime classes
997 static void TestTimeCompatibility()
998 {
999 puts("\n*** wxDateTime compatibility test ***");
1000
1001 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
1002 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
1003
1004 double jdnNow = wxDateTime::Now().GetJDN();
1005 long jdnMidnight = (long)(jdnNow - 0.5);
1006 printf("wxDate for today: %s\n", wxDate(jdnMidnight).FormatDate().c_str());
1007
1008 jdnMidnight = wxDate().Set().GetJulianDate();
1009 printf("wxDateTime for today: %s\n",
1010 wxDateTime((double)(jdnMidnight + 0.5)).Format("%c", wxDateTime::GMT0).c_str());
1011
1012 int flags = wxEUROPEAN;//wxFULL;
1013 wxDate date;
1014 date.Set();
1015 printf("Today is %s\n", date.FormatDate(flags).c_str());
1016 for ( int n = 0; n < 7; n++ )
1017 {
1018 printf("Previous %s is %s\n",
1019 wxDateTime::GetWeekDayName((wxDateTime::WeekDay)n),
1020 date.Previous(n + 1).FormatDate(flags).c_str());
1021 }
1022 }
1023
1024 #endif // 0
1025
1026 #endif // TEST_TIME
1027
1028 // ----------------------------------------------------------------------------
1029 // threads
1030 // ----------------------------------------------------------------------------
1031
1032 #ifdef TEST_THREADS
1033
1034 #include <wx/thread.h>
1035
1036 static size_t gs_counter = (size_t)-1;
1037 static wxCriticalSection gs_critsect;
1038 static wxCondition gs_cond;
1039
1040 class MyJoinableThread : public wxThread
1041 {
1042 public:
1043 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
1044 { m_n = n; Create(); }
1045
1046 // thread execution starts here
1047 virtual ExitCode Entry();
1048
1049 private:
1050 size_t m_n;
1051 };
1052
1053 wxThread::ExitCode MyJoinableThread::Entry()
1054 {
1055 unsigned long res = 1;
1056 for ( size_t n = 1; n < m_n; n++ )
1057 {
1058 res *= n;
1059
1060 // it's a loooong calculation :-)
1061 Sleep(100);
1062 }
1063
1064 return (ExitCode)res;
1065 }
1066
1067 class MyDetachedThread : public wxThread
1068 {
1069 public:
1070 MyDetachedThread(size_t n, char ch)
1071 {
1072 m_n = n;
1073 m_ch = ch;
1074 m_cancelled = FALSE;
1075
1076 Create();
1077 }
1078
1079 // thread execution starts here
1080 virtual ExitCode Entry();
1081
1082 // and stops here
1083 virtual void OnExit();
1084
1085 private:
1086 size_t m_n; // number of characters to write
1087 char m_ch; // character to write
1088
1089 bool m_cancelled; // FALSE if we exit normally
1090 };
1091
1092 wxThread::ExitCode MyDetachedThread::Entry()
1093 {
1094 {
1095 wxCriticalSectionLocker lock(gs_critsect);
1096 if ( gs_counter == (size_t)-1 )
1097 gs_counter = 1;
1098 else
1099 gs_counter++;
1100 }
1101
1102 for ( size_t n = 0; n < m_n; n++ )
1103 {
1104 if ( TestDestroy() )
1105 {
1106 m_cancelled = TRUE;
1107
1108 break;
1109 }
1110
1111 putchar(m_ch);
1112 fflush(stdout);
1113
1114 wxThread::Sleep(100);
1115 }
1116
1117 return 0;
1118 }
1119
1120 void MyDetachedThread::OnExit()
1121 {
1122 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
1123
1124 wxCriticalSectionLocker lock(gs_critsect);
1125 if ( !--gs_counter && !m_cancelled )
1126 gs_cond.Signal();
1127 }
1128
1129 void TestDetachedThreads()
1130 {
1131 puts("\n*** Testing detached threads ***");
1132
1133 static const size_t nThreads = 3;
1134 MyDetachedThread *threads[nThreads];
1135 size_t n;
1136 for ( n = 0; n < nThreads; n++ )
1137 {
1138 threads[n] = new MyDetachedThread(10, 'A' + n);
1139 }
1140
1141 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
1142 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
1143
1144 for ( n = 0; n < nThreads; n++ )
1145 {
1146 threads[n]->Run();
1147 }
1148
1149 // wait until all threads terminate
1150 gs_cond.Wait();
1151
1152 puts("");
1153 }
1154
1155 void TestJoinableThreads()
1156 {
1157 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
1158
1159 // calc 10! in the background
1160 MyJoinableThread thread(10);
1161 thread.Run();
1162
1163 printf("\nThread terminated with exit code %lu.\n",
1164 (unsigned long)thread.Wait());
1165 }
1166
1167 void TestThreadSuspend()
1168 {
1169 puts("\n*** Testing thread suspend/resume functions ***");
1170
1171 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
1172
1173 thread->Run();
1174
1175 // this is for this demo only, in a real life program we'd use another
1176 // condition variable which would be signaled from wxThread::Entry() to
1177 // tell us that the thread really started running - but here just wait a
1178 // bit and hope that it will be enough (the problem is, of course, that
1179 // the thread might still not run when we call Pause() which will result
1180 // in an error)
1181 wxThread::Sleep(300);
1182
1183 for ( size_t n = 0; n < 3; n++ )
1184 {
1185 thread->Pause();
1186
1187 puts("\nThread suspended");
1188 if ( n > 0 )
1189 {
1190 // don't sleep but resume immediately the first time
1191 wxThread::Sleep(300);
1192 }
1193 puts("Going to resume the thread");
1194
1195 thread->Resume();
1196 }
1197
1198 puts("Waiting until it terminates now");
1199
1200 // wait until the thread terminates
1201 gs_cond.Wait();
1202
1203 puts("");
1204 }
1205
1206 void TestThreadDelete()
1207 {
1208 // As above, using Sleep() is only for testing here - we must use some
1209 // synchronisation object instead to ensure that the thread is still
1210 // running when we delete it - deleting a detached thread which already
1211 // terminated will lead to a crash!
1212
1213 puts("\n*** Testing thread delete function ***");
1214
1215 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
1216
1217 thread0->Delete();
1218
1219 puts("\nDeleted a thread which didn't start to run yet.");
1220
1221 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
1222
1223 thread1->Run();
1224
1225 wxThread::Sleep(300);
1226
1227 thread1->Delete();
1228
1229 puts("\nDeleted a running thread.");
1230
1231 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
1232
1233 thread2->Run();
1234
1235 wxThread::Sleep(300);
1236
1237 thread2->Pause();
1238
1239 thread2->Delete();
1240
1241 puts("\nDeleted a sleeping thread.");
1242
1243 MyJoinableThread thread3(20);
1244 thread3.Run();
1245
1246 thread3.Delete();
1247
1248 puts("\nDeleted a joinable thread.");
1249
1250 MyJoinableThread thread4(2);
1251 thread4.Run();
1252
1253 wxThread::Sleep(300);
1254
1255 thread4.Delete();
1256
1257 puts("\nDeleted a joinable thread which already terminated.");
1258
1259 puts("");
1260 }
1261
1262 #endif // TEST_THREADS
1263
1264 // ----------------------------------------------------------------------------
1265 // arrays
1266 // ----------------------------------------------------------------------------
1267
1268 #ifdef TEST_ARRAYS
1269
1270 void PrintArray(const char* name, const wxArrayString& array)
1271 {
1272 printf("Dump of the array '%s'\n", name);
1273
1274 size_t nCount = array.GetCount();
1275 for ( size_t n = 0; n < nCount; n++ )
1276 {
1277 printf("\t%s[%u] = '%s'\n", name, n, array[n].c_str());
1278 }
1279 }
1280
1281 #endif // TEST_ARRAYS
1282
1283 // ----------------------------------------------------------------------------
1284 // strings
1285 // ----------------------------------------------------------------------------
1286
1287 #ifdef TEST_STRINGS
1288
1289 #include "wx/timer.h"
1290
1291 static void TestString()
1292 {
1293 wxStopWatch sw;
1294
1295 wxString a, b, c;
1296
1297 a.reserve (128);
1298 b.reserve (128);
1299 c.reserve (128);
1300
1301 for (int i = 0; i < 1000000; ++i)
1302 {
1303 a = "Hello";
1304 b = " world";
1305 c = "! How'ya doin'?";
1306 a += b;
1307 a += c;
1308 c = "Hello world! What's up?";
1309 if (c != a)
1310 c = "Doh!";
1311 }
1312
1313 printf ("TestString elapsed time: %ld\n", sw.Time());
1314 }
1315
1316 static void TestPChar()
1317 {
1318 wxStopWatch sw;
1319
1320 char a [128];
1321 char b [128];
1322 char c [128];
1323
1324 for (int i = 0; i < 1000000; ++i)
1325 {
1326 strcpy (a, "Hello");
1327 strcpy (b, " world");
1328 strcpy (c, "! How'ya doin'?");
1329 strcat (a, b);
1330 strcat (a, c);
1331 strcpy (c, "Hello world! What's up?");
1332 if (strcmp (c, a) == 0)
1333 strcpy (c, "Doh!");
1334 }
1335
1336 printf ("TestPChar elapsed time: %ld\n", sw.Time());
1337 }
1338
1339 static void TestStringSub()
1340 {
1341 wxString s("Hello, world!");
1342
1343 puts("*** Testing wxString substring extraction ***");
1344
1345 printf("String = '%s'\n", s.c_str());
1346 printf("Left(5) = '%s'\n", s.Left(5).c_str());
1347 printf("Right(6) = '%s'\n", s.Right(6).c_str());
1348 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
1349 printf("Mid(3) = '%s'\n", s.Mid(3).c_str());
1350 printf("substr(3, 5) = '%s'\n", s.substr(3, 5).c_str());
1351 printf("substr(3) = '%s'\n", s.substr(3).c_str());
1352
1353 puts("");
1354 }
1355
1356 static void TestStringFormat()
1357 {
1358 puts("*** Testing wxString formatting ***");
1359
1360 wxString s;
1361 s.Printf("%03d", 18);
1362
1363 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
1364 printf("Number 18: %s\n", s.c_str());
1365
1366 puts("");
1367 }
1368
1369 #endif // TEST_STRINGS
1370
1371 // ----------------------------------------------------------------------------
1372 // entry point
1373 // ----------------------------------------------------------------------------
1374
1375 int main(int argc, char **argv)
1376 {
1377 if ( !wxInitialize() )
1378 {
1379 fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
1380 }
1381
1382 #ifdef TEST_STRINGS
1383 if ( 0 )
1384 {
1385 TestPChar();
1386 TestString();
1387 }
1388 if ( 0 )
1389 {
1390 TestStringSub();
1391 }
1392 TestStringFormat();
1393 #endif // TEST_STRINGS
1394
1395 #ifdef TEST_ARRAYS
1396 wxArrayString a1;
1397 a1.Add("tiger");
1398 a1.Add("cat");
1399 a1.Add("lion");
1400 a1.Add("dog");
1401 a1.Add("human");
1402 a1.Add("ape");
1403
1404 puts("*** Initially:");
1405
1406 PrintArray("a1", a1);
1407
1408 wxArrayString a2(a1);
1409 PrintArray("a2", a2);
1410
1411 wxSortedArrayString a3(a1);
1412 PrintArray("a3", a3);
1413
1414 puts("*** After deleting a string from a1");
1415 a1.Remove(2);
1416
1417 PrintArray("a1", a1);
1418 PrintArray("a2", a2);
1419 PrintArray("a3", a3);
1420
1421 puts("*** After reassigning a1 to a2 and a3");
1422 a3 = a2 = a1;
1423 PrintArray("a2", a2);
1424 PrintArray("a3", a3);
1425 #endif // TEST_ARRAYS
1426
1427 #ifdef TEST_DIR
1428 TestDirEnum();
1429 #endif // TEST_DIR
1430
1431 #ifdef TEST_LOG
1432 wxString s;
1433 for ( size_t n = 0; n < 8000; n++ )
1434 {
1435 s << (char)('A' + (n % 26));
1436 }
1437
1438 wxString msg;
1439 msg.Printf("A very very long message: '%s', the end!\n", s.c_str());
1440
1441 // this one shouldn't be truncated
1442 printf(msg);
1443
1444 // but this one will because log functions use fixed size buffer
1445 // (note that it doesn't need '\n' at the end neither - will be added
1446 // by wxLog anyhow)
1447 wxLogMessage("A very very long message 2: '%s', the end!", s.c_str());
1448 #endif // TEST_LOG
1449
1450 #ifdef TEST_THREADS
1451 int nCPUs = wxThread::GetCPUCount();
1452 printf("This system has %d CPUs\n", nCPUs);
1453 if ( nCPUs != -1 )
1454 wxThread::SetConcurrency(nCPUs);
1455
1456 if ( argc > 1 && argv[1][0] == 't' )
1457 wxLog::AddTraceMask("thread");
1458
1459 if ( 1 )
1460 TestDetachedThreads();
1461 if ( 1 )
1462 TestJoinableThreads();
1463 if ( 1 )
1464 TestThreadSuspend();
1465 if ( 1 )
1466 TestThreadDelete();
1467
1468 #endif // TEST_THREADS
1469
1470 #ifdef TEST_LONGLONG
1471 if ( 0 )
1472 TestSpeed();
1473 if ( 1 )
1474 TestDivision();
1475 #endif // TEST_LONGLONG
1476
1477 #ifdef TEST_MIME
1478 TestMimeEnum();
1479 #endif // TEST_MIME
1480
1481 #ifdef TEST_TIME
1482 if ( 0 )
1483 {
1484 TestTimeSet();
1485 TestTimeStatic();
1486 TestTimeZones();
1487 TestTimeRange();
1488 TestTimeTicks();
1489 TestTimeJDN();
1490 TestTimeDST();
1491 TestTimeWDays();
1492 TestTimeWNumber();
1493 TestTimeParse();
1494 }
1495
1496 TestTimeFormat();
1497 #endif // TEST_TIME
1498
1499 wxUninitialize();
1500
1501 return 0;
1502 }