]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
a60440aae9e5b07d83aa09e5df5729b5e1932da2
[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_MIME
36 //#define TEST_STRINGS
37 //#define TEST_THREADS
38 //#define TEST_TIME
39 //#define TEST_LONGLONG
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 {
199 wxStopWatch sw;
200
201 __int64 l = 0;
202 for ( n = 0; n < max; n++ )
203 {
204 l += n;
205 }
206
207 printf("Summing __int64s took %ld milliseconds.\n", sw.Time());
208 }
209
210 {
211 wxStopWatch sw;
212
213 wxLongLong l;
214 for ( n = 0; n < max; n++ )
215 {
216 l += n;
217 }
218
219 printf("Summing wxLongLongs took %ld milliseconds.\n", sw.Time());
220 }
221 }
222
223 static void TestDivision()
224 {
225 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
226
227 // seed pseudo random generator
228 //srand((unsigned)time(NULL));
229
230 size_t nTested = 0;
231 for ( size_t n = 0; n < 10000; n++ )
232 {
233 // get a random wxLongLong (shifting by 12 the MSB ensures that the
234 // multiplication will not overflow)
235 wxLongLong ll = MAKE_LL((rand() >> 12), rand(), rand(), rand());
236
237 wxASSERT( (ll * 1000l)/1000l == ll );
238
239 nTested++;
240 }
241
242 printf("\n*** Tested %u divisions/multiplications: ok\n", nTested);
243
244 #undef MAKE_LL
245 }
246
247 #endif // TEST_LONGLONG
248
249 // ----------------------------------------------------------------------------
250 // date time
251 // ----------------------------------------------------------------------------
252
253 #ifdef TEST_TIME
254
255 #include <wx/datetime.h>
256
257 // the test data
258 struct Date
259 {
260 wxDateTime::wxDateTime_t day;
261 wxDateTime::Month month;
262 int year;
263 wxDateTime::wxDateTime_t hour, min, sec;
264 double jdn;
265 time_t gmticks, ticks;
266
267 void Init(const wxDateTime::Tm& tm)
268 {
269 day = tm.mday;
270 month = tm.mon;
271 year = tm.year;
272 hour = tm.hour;
273 min = tm.min;
274 sec = tm.sec;
275 jdn = 0.0;
276 gmticks = ticks = -1;
277 }
278
279 wxDateTime DT() const
280 { return wxDateTime(day, month, year, hour, min, sec); }
281
282 wxString Format() const
283 {
284 wxString s;
285 s.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
286 hour, min, sec,
287 wxDateTime::GetMonthName(month).c_str(),
288 day,
289 abs(wxDateTime::ConvertYearToBC(year)),
290 year > 0 ? "AD" : "BC");
291 return s;
292 }
293 };
294
295 static const Date testDates[] =
296 {
297 { 1, wxDateTime::Jan, 1970, 00, 00, 00, 2440587.5, 0, -3600 },
298 { 21, wxDateTime::Jan, 2222, 00, 00, 00, 2532648.5, -1, -1 },
299 { 29, wxDateTime::May, 1976, 12, 00, 00, 2442928.0, 202219200, 202212000 },
300 { 29, wxDateTime::Feb, 1976, 00, 00, 00, 2442837.5, 194400000, 194396400 },
301 { 1, wxDateTime::Jan, 1900, 12, 00, 00, 2415021.0, -1, -1 },
302 { 1, wxDateTime::Jan, 1900, 00, 00, 00, 2415020.5, -1, -1 },
303 { 15, wxDateTime::Oct, 1582, 00, 00, 00, 2299160.5, -1, -1 },
304 { 4, wxDateTime::Oct, 1582, 00, 00, 00, 2299149.5, -1, -1 },
305 { 1, wxDateTime::Mar, 1, 00, 00, 00, 1721484.5, -1, -1 },
306 { 1, wxDateTime::Jan, 1, 00, 00, 00, 1721425.5, -1, -1 },
307 { 31, wxDateTime::Dec, 0, 00, 00, 00, 1721424.5, -1, -1 },
308 { 1, wxDateTime::Jan, 0, 00, 00, 00, 1721059.5, -1, -1 },
309 { 12, wxDateTime::Aug, -1234, 00, 00, 00, 1270573.5, -1, -1 },
310 { 12, wxDateTime::Aug, -4000, 00, 00, 00, 260313.5, -1, -1 },
311 { 24, wxDateTime::Nov, -4713, 00, 00, 00, -0.5, -1, -1 },
312 };
313
314 // this test miscellaneous static wxDateTime functions
315 static void TestTimeStatic()
316 {
317 puts("\n*** wxDateTime static methods test ***");
318
319 // some info about the current date
320 int year = wxDateTime::GetCurrentYear();
321 printf("Current year %d is %sa leap one and has %d days.\n",
322 year,
323 wxDateTime::IsLeapYear(year) ? "" : "not ",
324 wxDateTime::GetNumberOfDays(year));
325
326 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
327 printf("Current month is '%s' ('%s') and it has %d days\n",
328 wxDateTime::GetMonthName(month, TRUE).c_str(),
329 wxDateTime::GetMonthName(month).c_str(),
330 wxDateTime::GetNumberOfDays(month));
331
332 // leap year logic
333 static const size_t nYears = 5;
334 static const size_t years[2][nYears] =
335 {
336 // first line: the years to test
337 { 1990, 1976, 2000, 2030, 1984, },
338
339 // second line: TRUE if leap, FALSE otherwise
340 { FALSE, TRUE, TRUE, FALSE, TRUE }
341 };
342
343 for ( size_t n = 0; n < nYears; n++ )
344 {
345 int year = years[0][n];
346 bool should = years[1][n] != 0;
347
348 printf("Year %d is %sa leap year (should be: %s)\n",
349 year,
350 wxDateTime::IsLeapYear(year) ? "" : "not ",
351 should ? "yes" : "no");
352
353 wxASSERT( should == wxDateTime::IsLeapYear(year) );
354 }
355 }
356
357 // test constructing wxDateTime objects
358 static void TestTimeSet()
359 {
360 puts("\n*** wxDateTime construction test ***");
361
362 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
363 {
364 const Date& d1 = testDates[n];
365 wxDateTime dt = d1.DT();
366
367 Date d2;
368 d2.Init(dt.GetTm());
369
370 wxString s1 = d1.Format(),
371 s2 = d2.Format();
372
373 printf("Date: %s == %s (%s)\n",
374 s1.c_str(), s2.c_str(),
375 s1 == s2 ? "ok" : "ERROR");
376 }
377 }
378
379 // test time zones stuff
380 static void TestTimeZones()
381 {
382 puts("\n*** wxDateTime timezone test ***");
383
384 wxDateTime now = wxDateTime::Now();
385
386 printf("Current GMT time:\t%s\n", now.Format("%c", wxDateTime::GMT0).c_str());
387 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0).c_str());
388 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST).c_str());
389 printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
390 printf(" Moscow:\t%s\n", now.Format("%c", wxDateTime::MSK).c_str());
391 printf(" New York:\t%s\n", now.Format("%c", wxDateTime::EST).c_str());
392 }
393
394 // test some minimal support for the dates outside the standard range
395 static void TestTimeRange()
396 {
397 puts("\n*** wxDateTime out-of-standard-range dates test ***");
398
399 printf("Unix epoch:\t%s\n",
400 wxDateTime(2440587.5).Format().c_str());
401 printf("Feb 29, 0: \t%s\n",
402 wxDateTime(29, wxDateTime::Feb, 0).Format().c_str());
403 printf("JDN 0: \t%s\n",
404 wxDateTime(0.0).Format().c_str());
405 printf("Jan 1, 1AD:\t%s\n",
406 wxDateTime(1, wxDateTime::Jan, 1).Format().c_str());
407 printf("May 29, 2099:\t%s\n",
408 wxDateTime(29, wxDateTime::May, 2099).Format().c_str());
409 }
410
411 static void TestTimeTicks()
412 {
413 puts("\n*** wxDateTime ticks test ***");
414
415 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
416 {
417 const Date& d = testDates[n];
418 if ( d.ticks == -1 )
419 continue;
420
421 wxDateTime dt = d.DT();
422 long ticks = (dt.GetValue() / 1000).ToLong();
423 printf("Ticks of %s:\t% 10ld", d.Format().c_str(), ticks);
424 if ( ticks == d.ticks )
425 {
426 puts(" (ok)");
427 }
428 else
429 {
430 printf(" (ERROR: should be %ld, delta = %ld)\n",
431 d.ticks, ticks - d.ticks);
432 }
433
434 dt = d.DT().ToTimezone(wxDateTime::GMT0);
435 ticks = (dt.GetValue() / 1000).ToLong();
436 printf("GMtks of %s:\t% 10ld", d.Format().c_str(), ticks);
437 if ( ticks == d.gmticks )
438 {
439 puts(" (ok)");
440 }
441 else
442 {
443 printf(" (ERROR: should be %ld, delta = %ld)\n",
444 d.gmticks, ticks - d.gmticks);
445 }
446 }
447
448 puts("");
449 }
450
451 // test conversions to JDN &c
452 static void TestTimeJDN()
453 {
454 puts("\n*** wxDateTime to JDN test ***");
455
456 for ( size_t n = 0; n < WXSIZEOF(testDates); n++ )
457 {
458 const Date& d = testDates[n];
459 wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
460 double jdn = dt.GetJulianDayNumber();
461
462 printf("JDN of %s is:\t% 15.6f", d.Format().c_str(), jdn);
463 if ( jdn == d.jdn )
464 {
465 puts(" (ok)");
466 }
467 else
468 {
469 printf(" (ERROR: should be %f, delta = %f)\n",
470 d.jdn, jdn - d.jdn);
471 }
472 }
473 }
474
475 #endif // TEST_TIME
476
477 // ----------------------------------------------------------------------------
478 // threads
479 // ----------------------------------------------------------------------------
480
481 #ifdef TEST_THREADS
482
483 #include <wx/thread.h>
484
485 static size_t gs_counter = (size_t)-1;
486 static wxCriticalSection gs_critsect;
487 static wxCondition gs_cond;
488
489 class MyJoinableThread : public wxThread
490 {
491 public:
492 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
493 { m_n = n; Create(); }
494
495 // thread execution starts here
496 virtual ExitCode Entry();
497
498 private:
499 size_t m_n;
500 };
501
502 wxThread::ExitCode MyJoinableThread::Entry()
503 {
504 unsigned long res = 1;
505 for ( size_t n = 1; n < m_n; n++ )
506 {
507 res *= n;
508
509 // it's a loooong calculation :-)
510 Sleep(100);
511 }
512
513 return (ExitCode)res;
514 }
515
516 class MyDetachedThread : public wxThread
517 {
518 public:
519 MyDetachedThread(size_t n, char ch)
520 {
521 m_n = n;
522 m_ch = ch;
523 m_cancelled = FALSE;
524
525 Create();
526 }
527
528 // thread execution starts here
529 virtual ExitCode Entry();
530
531 // and stops here
532 virtual void OnExit();
533
534 private:
535 size_t m_n; // number of characters to write
536 char m_ch; // character to write
537
538 bool m_cancelled; // FALSE if we exit normally
539 };
540
541 wxThread::ExitCode MyDetachedThread::Entry()
542 {
543 {
544 wxCriticalSectionLocker lock(gs_critsect);
545 if ( gs_counter == (size_t)-1 )
546 gs_counter = 1;
547 else
548 gs_counter++;
549 }
550
551 for ( size_t n = 0; n < m_n; n++ )
552 {
553 if ( TestDestroy() )
554 {
555 m_cancelled = TRUE;
556
557 break;
558 }
559
560 putchar(m_ch);
561 fflush(stdout);
562
563 wxThread::Sleep(100);
564 }
565
566 return 0;
567 }
568
569 void MyDetachedThread::OnExit()
570 {
571 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
572
573 wxCriticalSectionLocker lock(gs_critsect);
574 if ( !--gs_counter && !m_cancelled )
575 gs_cond.Signal();
576 }
577
578 void TestDetachedThreads()
579 {
580 puts("\n*** Testing detached threads ***");
581
582 static const size_t nThreads = 3;
583 MyDetachedThread *threads[nThreads];
584 size_t n;
585 for ( n = 0; n < nThreads; n++ )
586 {
587 threads[n] = new MyDetachedThread(10, 'A' + n);
588 }
589
590 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
591 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
592
593 for ( n = 0; n < nThreads; n++ )
594 {
595 threads[n]->Run();
596 }
597
598 // wait until all threads terminate
599 gs_cond.Wait();
600
601 puts("");
602 }
603
604 void TestJoinableThreads()
605 {
606 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
607
608 // calc 10! in the background
609 MyJoinableThread thread(10);
610 thread.Run();
611
612 printf("\nThread terminated with exit code %lu.\n",
613 (unsigned long)thread.Wait());
614 }
615
616 void TestThreadSuspend()
617 {
618 puts("\n*** Testing thread suspend/resume functions ***");
619
620 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
621
622 thread->Run();
623
624 // this is for this demo only, in a real life program we'd use another
625 // condition variable which would be signaled from wxThread::Entry() to
626 // tell us that the thread really started running - but here just wait a
627 // bit and hope that it will be enough (the problem is, of course, that
628 // the thread might still not run when we call Pause() which will result
629 // in an error)
630 wxThread::Sleep(300);
631
632 for ( size_t n = 0; n < 3; n++ )
633 {
634 thread->Pause();
635
636 puts("\nThread suspended");
637 if ( n > 0 )
638 {
639 // don't sleep but resume immediately the first time
640 wxThread::Sleep(300);
641 }
642 puts("Going to resume the thread");
643
644 thread->Resume();
645 }
646
647 puts("Waiting until it terminates now");
648
649 // wait until the thread terminates
650 gs_cond.Wait();
651
652 puts("");
653 }
654
655 void TestThreadDelete()
656 {
657 // As above, using Sleep() is only for testing here - we must use some
658 // synchronisation object instead to ensure that the thread is still
659 // running when we delete it - deleting a detached thread which already
660 // terminated will lead to a crash!
661
662 puts("\n*** Testing thread delete function ***");
663
664 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
665
666 thread0->Delete();
667
668 puts("\nDeleted a thread which didn't start to run yet.");
669
670 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
671
672 thread1->Run();
673
674 wxThread::Sleep(300);
675
676 thread1->Delete();
677
678 puts("\nDeleted a running thread.");
679
680 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
681
682 thread2->Run();
683
684 wxThread::Sleep(300);
685
686 thread2->Pause();
687
688 thread2->Delete();
689
690 puts("\nDeleted a sleeping thread.");
691
692 MyJoinableThread thread3(20);
693 thread3.Run();
694
695 thread3.Delete();
696
697 puts("\nDeleted a joinable thread.");
698
699 MyJoinableThread thread4(2);
700 thread4.Run();
701
702 wxThread::Sleep(300);
703
704 thread4.Delete();
705
706 puts("\nDeleted a joinable thread which already terminated.");
707
708 puts("");
709 }
710
711 #endif // TEST_THREADS
712
713 // ----------------------------------------------------------------------------
714 // arrays
715 // ----------------------------------------------------------------------------
716
717 #ifdef TEST_ARRAYS
718
719 void PrintArray(const char* name, const wxArrayString& array)
720 {
721 printf("Dump of the array '%s'\n", name);
722
723 size_t nCount = array.GetCount();
724 for ( size_t n = 0; n < nCount; n++ )
725 {
726 printf("\t%s[%u] = '%s'\n", name, n, array[n].c_str());
727 }
728 }
729
730 #endif // TEST_ARRAYS
731
732 // ----------------------------------------------------------------------------
733 // strings
734 // ----------------------------------------------------------------------------
735
736 #ifdef TEST_STRINGS
737
738 #include "wx/timer.h"
739
740 static void TestString()
741 {
742 wxStopWatch sw;
743
744 wxString a, b, c;
745
746 a.reserve (128);
747 b.reserve (128);
748 c.reserve (128);
749
750 for (int i = 0; i < 1000000; ++i)
751 {
752 a = "Hello";
753 b = " world";
754 c = "! How'ya doin'?";
755 a += b;
756 a += c;
757 c = "Hello world! What's up?";
758 if (c != a)
759 c = "Doh!";
760 }
761
762 printf ("TestString elapsed time: %ld\n", sw.Time());
763 }
764
765 static void TestPChar()
766 {
767 wxStopWatch sw;
768
769 char a [128];
770 char b [128];
771 char c [128];
772
773 for (int i = 0; i < 1000000; ++i)
774 {
775 strcpy (a, "Hello");
776 strcpy (b, " world");
777 strcpy (c, "! How'ya doin'?");
778 strcat (a, b);
779 strcat (a, c);
780 strcpy (c, "Hello world! What's up?");
781 if (strcmp (c, a) == 0)
782 strcpy (c, "Doh!");
783 }
784
785 printf ("TestPChar elapsed time: %ld\n", sw.Time());
786 }
787
788 static void TestStringSub()
789 {
790 wxString s("Hello, world!");
791
792 puts("*** Testing wxString substring extraction ***");
793
794 printf("String = '%s'\n", s.c_str());
795 printf("Left(5) = '%s'\n", s.Left(5).c_str());
796 printf("Right(6) = '%s'\n", s.Right(6).c_str());
797 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
798 printf("Mid(3) = '%s'\n", s.Mid(3).c_str());
799 printf("substr(3, 5) = '%s'\n", s.substr(3, 5).c_str());
800 printf("substr(3) = '%s'\n", s.substr(3).c_str());
801
802 puts("");
803 }
804
805 #endif // TEST_STRINGS
806
807 // ----------------------------------------------------------------------------
808 // entry point
809 // ----------------------------------------------------------------------------
810
811 int main(int argc, char **argv)
812 {
813 if ( !wxInitialize() )
814 {
815 fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
816 }
817
818 #ifdef TEST_STRINGS
819 if ( 0 )
820 {
821 TestPChar();
822 TestString();
823 }
824 TestStringSub();
825 #endif // TEST_STRINGS
826
827 #ifdef TEST_ARRAYS
828 wxArrayString a1;
829 a1.Add("tiger");
830 a1.Add("cat");
831 a1.Add("lion");
832 a1.Add("dog");
833 a1.Add("human");
834 a1.Add("ape");
835
836 puts("*** Initially:");
837
838 PrintArray("a1", a1);
839
840 wxArrayString a2(a1);
841 PrintArray("a2", a2);
842
843 wxSortedArrayString a3(a1);
844 PrintArray("a3", a3);
845
846 puts("*** After deleting a string from a1");
847 a1.Remove(2);
848
849 PrintArray("a1", a1);
850 PrintArray("a2", a2);
851 PrintArray("a3", a3);
852
853 puts("*** After reassigning a1 to a2 and a3");
854 a3 = a2 = a1;
855 PrintArray("a2", a2);
856 PrintArray("a3", a3);
857 #endif // TEST_ARRAYS
858
859 #ifdef TEST_DIR
860 TestDirEnum();
861 #endif // TEST_DIR
862
863 #ifdef TEST_LOG
864 wxString s;
865 for ( size_t n = 0; n < 8000; n++ )
866 {
867 s << (char)('A' + (n % 26));
868 }
869
870 wxString msg;
871 msg.Printf("A very very long message: '%s', the end!\n", s.c_str());
872
873 // this one shouldn't be truncated
874 printf(msg);
875
876 // but this one will because log functions use fixed size buffer
877 // (note that it doesn't need '\n' at the end neither - will be added
878 // by wxLog anyhow)
879 wxLogMessage("A very very long message 2: '%s', the end!", s.c_str());
880 #endif // TEST_LOG
881
882 #ifdef TEST_THREADS
883 int nCPUs = wxThread::GetCPUCount();
884 printf("This system has %d CPUs\n", nCPUs);
885 if ( nCPUs != -1 )
886 wxThread::SetConcurrency(nCPUs);
887
888 if ( argc > 1 && argv[1][0] == 't' )
889 wxLog::AddTraceMask("thread");
890
891 if ( 1 )
892 TestDetachedThreads();
893 if ( 1 )
894 TestJoinableThreads();
895 if ( 1 )
896 TestThreadSuspend();
897 if ( 1 )
898 TestThreadDelete();
899
900 #endif // TEST_THREADS
901
902 #ifdef TEST_LONGLONG
903 if ( 0 )
904 TestSpeed();
905 if ( 1 )
906 TestDivision();
907 #endif // TEST_LONGLONG
908
909 #ifdef TEST_MIME
910 TestMimeEnum();
911 #endif // TEST_MIME
912
913 #ifdef TEST_TIME
914 TestTimeSet();
915 if ( 0 )
916 {
917 TestTimeStatic();
918 TestTimeZones();
919 TestTimeRange();
920 TestTimeTicks();
921 }
922 TestTimeJDN();
923 #endif // TEST_TIME
924
925 wxUninitialize();
926
927 return 0;
928 }