remove some tests from the console sample:
[wxWidgets.git] / samples / console / console.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // IMPORTANT NOTE FOR WXWIDGETS USERS:
13 // If you're a wxWidgets user and you're looking at this file to learn how to
14 // structure a wxWidgets console application, then you don't have much to learn.
15 // This application is used more for testing rather than as sample but
16 // basically the following simple block is enough for you to start your
17 // own console application:
18
19 /*
20 int main(int argc, char **argv)
21 {
22 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
23
24 wxInitializer initializer;
25 if ( !initializer )
26 {
27 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
28 return -1;
29 }
30
31 static const wxCmdLineEntryDesc cmdLineDesc[] =
32 {
33 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
34 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
35 // ... your other command line options here...
36
37 { wxCMD_LINE_NONE }
38 };
39
40 wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
41 switch ( parser.Parse() )
42 {
43 case -1:
44 wxLogMessage(wxT("Help was given, terminating."));
45 break;
46
47 case 0:
48 // everything is ok; proceed
49 break;
50
51 default:
52 wxLogMessage(wxT("Syntax error detected, aborting."));
53 break;
54 }
55
56 // do something useful here
57
58 return 0;
59 }
60 */
61
62
63 // ============================================================================
64 // declarations
65 // ============================================================================
66
67 // ----------------------------------------------------------------------------
68 // headers
69 // ----------------------------------------------------------------------------
70
71 #include "wx/defs.h"
72
73 #include <stdio.h>
74
75 #include "wx/string.h"
76 #include "wx/file.h"
77 #include "wx/filename.h"
78 #include "wx/app.h"
79 #include "wx/log.h"
80 #include "wx/apptrait.h"
81 #include "wx/platinfo.h"
82 #include "wx/wxchar.h"
83
84 // without this pragma, the stupid compiler precompiles #defines below so that
85 // changing them doesn't "take place" later!
86 #ifdef __VISUALC__
87 #pragma hdrstop
88 #endif
89
90 // ----------------------------------------------------------------------------
91 // conditional compilation
92 // ----------------------------------------------------------------------------
93
94 /*
95 A note about all these conditional compilation macros: this file is used
96 both as a test suite for various non-GUI wxWidgets classes and as a
97 scratchpad for quick tests. So there are two compilation modes: if you
98 define TEST_ALL all tests are run, otherwise you may enable the individual
99 tests individually in the "#else" branch below.
100 */
101
102 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
103 // test, define it to 1 to do all tests.
104 #define TEST_ALL 0
105
106
107 #if TEST_ALL
108 #define TEST_DIR
109 #define TEST_DYNLIB
110 #define TEST_ENVIRON
111 #define TEST_FILE
112 #define TEST_FILENAME
113 #define TEST_FILETIME
114 #else // #if TEST_ALL
115 #define TEST_DATETIME
116 #define TEST_VOLUME
117 #define TEST_STDPATHS
118 #define TEST_STACKWALKER
119 #define TEST_FTP
120 #define TEST_SNGLINST
121 #define TEST_REGEX
122 #define TEST_INFO_FUNCTIONS
123 #define TEST_MIME
124 #endif
125
126 // some tests are interactive, define this to run them
127 #ifdef TEST_INTERACTIVE
128 #undef TEST_INTERACTIVE
129
130 #define TEST_INTERACTIVE 1
131 #else
132 #define TEST_INTERACTIVE 1
133 #endif
134
135 // ============================================================================
136 // implementation
137 // ============================================================================
138
139 // ----------------------------------------------------------------------------
140 // wxDir
141 // ----------------------------------------------------------------------------
142
143 #ifdef TEST_DIR
144
145 #include "wx/dir.h"
146
147 #ifdef __UNIX__
148 static const wxChar *ROOTDIR = wxT("/");
149 static const wxChar *TESTDIR = wxT("/usr/local/share");
150 #elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
151 static const wxChar *ROOTDIR = wxT("c:\\");
152 static const wxChar *TESTDIR = wxT("d:\\");
153 #else
154 #error "don't know where the root directory is"
155 #endif
156
157 static void TestDirEnumHelper(wxDir& dir,
158 int flags = wxDIR_DEFAULT,
159 const wxString& filespec = wxEmptyString)
160 {
161 wxString filename;
162
163 if ( !dir.IsOpened() )
164 return;
165
166 bool cont = dir.GetFirst(&filename, filespec, flags);
167 while ( cont )
168 {
169 wxPrintf(wxT("\t%s\n"), filename.c_str());
170
171 cont = dir.GetNext(&filename);
172 }
173
174 wxPuts(wxEmptyString);
175 }
176
177 #if TEST_ALL
178
179 static void TestDirEnum()
180 {
181 wxPuts(wxT("*** Testing wxDir::GetFirst/GetNext ***"));
182
183 wxString cwd = wxGetCwd();
184 if ( !wxDir::Exists(cwd) )
185 {
186 wxPrintf(wxT("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str());
187 return;
188 }
189
190 wxDir dir(cwd);
191 if ( !dir.IsOpened() )
192 {
193 wxPrintf(wxT("ERROR: failed to open current directory '%s'.\n"), cwd.c_str());
194 return;
195 }
196
197 wxPuts(wxT("Enumerating everything in current directory:"));
198 TestDirEnumHelper(dir);
199
200 wxPuts(wxT("Enumerating really everything in current directory:"));
201 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
202
203 wxPuts(wxT("Enumerating object files in current directory:"));
204 TestDirEnumHelper(dir, wxDIR_DEFAULT, wxT("*.o*"));
205
206 wxPuts(wxT("Enumerating directories in current directory:"));
207 TestDirEnumHelper(dir, wxDIR_DIRS);
208
209 wxPuts(wxT("Enumerating files in current directory:"));
210 TestDirEnumHelper(dir, wxDIR_FILES);
211
212 wxPuts(wxT("Enumerating files including hidden in current directory:"));
213 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
214
215 dir.Open(ROOTDIR);
216
217 wxPuts(wxT("Enumerating everything in root directory:"));
218 TestDirEnumHelper(dir, wxDIR_DEFAULT);
219
220 wxPuts(wxT("Enumerating directories in root directory:"));
221 TestDirEnumHelper(dir, wxDIR_DIRS);
222
223 wxPuts(wxT("Enumerating files in root directory:"));
224 TestDirEnumHelper(dir, wxDIR_FILES);
225
226 wxPuts(wxT("Enumerating files including hidden in root directory:"));
227 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
228
229 wxPuts(wxT("Enumerating files in non existing directory:"));
230 wxDir dirNo(wxT("nosuchdir"));
231 TestDirEnumHelper(dirNo);
232 }
233
234 #endif // TEST_ALL
235
236 class DirPrintTraverser : public wxDirTraverser
237 {
238 public:
239 virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename))
240 {
241 return wxDIR_CONTINUE;
242 }
243
244 virtual wxDirTraverseResult OnDir(const wxString& dirname)
245 {
246 wxString path, name, ext;
247 wxFileName::SplitPath(dirname, &path, &name, &ext);
248
249 if ( !ext.empty() )
250 name << wxT('.') << ext;
251
252 wxString indent;
253 for ( const wxChar *p = path.c_str(); *p; p++ )
254 {
255 if ( wxIsPathSeparator(*p) )
256 indent += wxT(" ");
257 }
258
259 wxPrintf(wxT("%s%s\n"), indent.c_str(), name.c_str());
260
261 return wxDIR_CONTINUE;
262 }
263 };
264
265 static void TestDirTraverse()
266 {
267 wxPuts(wxT("*** Testing wxDir::Traverse() ***"));
268
269 // enum all files
270 wxArrayString files;
271 size_t n = wxDir::GetAllFiles(TESTDIR, &files);
272 wxPrintf(wxT("There are %u files under '%s'\n"), n, TESTDIR);
273 if ( n > 1 )
274 {
275 wxPrintf(wxT("First one is '%s'\n"), files[0u].c_str());
276 wxPrintf(wxT(" last one is '%s'\n"), files[n - 1].c_str());
277 }
278
279 // enum again with custom traverser
280 wxPuts(wxT("Now enumerating directories:"));
281 wxDir dir(TESTDIR);
282 DirPrintTraverser traverser;
283 dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
284 }
285
286 #if TEST_ALL
287
288 static void TestDirExists()
289 {
290 wxPuts(wxT("*** Testing wxDir::Exists() ***"));
291
292 static const wxChar *dirnames[] =
293 {
294 wxT("."),
295 #if defined(__WXMSW__)
296 wxT("c:"),
297 wxT("c:\\"),
298 wxT("\\\\share\\file"),
299 wxT("c:\\dos"),
300 wxT("c:\\dos\\"),
301 wxT("c:\\dos\\\\"),
302 wxT("c:\\autoexec.bat"),
303 #elif defined(__UNIX__)
304 wxT("/"),
305 wxT("//"),
306 wxT("/usr/bin"),
307 wxT("/usr//bin"),
308 wxT("/usr///bin"),
309 #endif
310 };
311
312 for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ )
313 {
314 wxPrintf(wxT("%-40s: %s\n"),
315 dirnames[n],
316 wxDir::Exists(dirnames[n]) ? wxT("exists")
317 : wxT("doesn't exist"));
318 }
319 }
320
321 #endif // TEST_ALL
322
323 #endif // TEST_DIR
324
325 // ----------------------------------------------------------------------------
326 // wxDllLoader
327 // ----------------------------------------------------------------------------
328
329 #ifdef TEST_DYNLIB
330
331 #include "wx/dynlib.h"
332
333 static void TestDllLoad()
334 {
335 #if defined(__WXMSW__)
336 static const wxChar *LIB_NAME = wxT("kernel32.dll");
337 static const wxChar *FUNC_NAME = wxT("lstrlenA");
338 #elif defined(__UNIX__)
339 // weird: using just libc.so does *not* work!
340 static const wxChar *LIB_NAME = wxT("/lib/libc.so.6");
341 static const wxChar *FUNC_NAME = wxT("strlen");
342 #else
343 #error "don't know how to test wxDllLoader on this platform"
344 #endif
345
346 wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
347
348 wxDynamicLibrary lib(LIB_NAME);
349 if ( !lib.IsLoaded() )
350 {
351 wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME);
352 }
353 else
354 {
355 typedef int (wxSTDCALL *wxStrlenType)(const char *);
356 wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
357 if ( !pfnStrlen )
358 {
359 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
360 FUNC_NAME, LIB_NAME);
361 }
362 else
363 {
364 wxPrintf(wxT("Calling %s dynamically loaded from %s "),
365 FUNC_NAME, LIB_NAME);
366
367 if ( pfnStrlen("foo") != 3 )
368 {
369 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
370 }
371 else
372 {
373 wxPuts(wxT("... ok"));
374 }
375 }
376
377 #ifdef __WXMSW__
378 static const wxChar *FUNC_NAME_AW = wxT("lstrlen");
379
380 typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
381 wxStrlenTypeAorW
382 pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
383 if ( !pfnStrlenAorW )
384 {
385 wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
386 FUNC_NAME_AW, LIB_NAME);
387 }
388 else
389 {
390 if ( pfnStrlenAorW(wxT("foobar")) != 6 )
391 {
392 wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
393 }
394 }
395 #endif // __WXMSW__
396 }
397 }
398
399 #if defined(__WXMSW__) || defined(__UNIX__)
400
401 static void TestDllListLoaded()
402 {
403 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
404
405 puts("\nLoaded modules:");
406 wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
407 const size_t count = dlls.GetCount();
408 for ( size_t n = 0; n < count; ++n )
409 {
410 const wxDynamicLibraryDetails& details = dlls[n];
411 printf("%-45s", (const char *)details.GetPath().mb_str());
412
413 void *addr wxDUMMY_INITIALIZE(NULL);
414 size_t len wxDUMMY_INITIALIZE(0);
415 if ( details.GetAddress(&addr, &len) )
416 {
417 printf(" %08lx:%08lx",
418 (unsigned long)addr, (unsigned long)((char *)addr + len));
419 }
420
421 printf(" %s\n", (const char *)details.GetVersion().mb_str());
422 }
423 }
424
425 #endif
426
427 #endif // TEST_DYNLIB
428
429 // ----------------------------------------------------------------------------
430 // wxGet/SetEnv
431 // ----------------------------------------------------------------------------
432
433 #ifdef TEST_ENVIRON
434
435 #include "wx/utils.h"
436
437 static wxString MyGetEnv(const wxString& var)
438 {
439 wxString val;
440 if ( !wxGetEnv(var, &val) )
441 val = wxT("<empty>");
442 else
443 val = wxString(wxT('\'')) + val + wxT('\'');
444
445 return val;
446 }
447
448 static void TestEnvironment()
449 {
450 const wxChar *var = wxT("wxTestVar");
451
452 wxPuts(wxT("*** testing environment access functions ***"));
453
454 wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
455 wxSetEnv(var, wxT("value for wxTestVar"));
456 wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
457 wxSetEnv(var, wxT("another value"));
458 wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
459 wxUnsetEnv(var);
460 wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
461 wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
462 }
463
464 #endif // TEST_ENVIRON
465
466 // ----------------------------------------------------------------------------
467 // file
468 // ----------------------------------------------------------------------------
469
470 #ifdef TEST_FILE
471
472 #include "wx/file.h"
473 #include "wx/ffile.h"
474 #include "wx/textfile.h"
475
476 static void TestFileRead()
477 {
478 wxPuts(wxT("*** wxFile read test ***"));
479
480 wxFile file(wxT("testdata.fc"));
481 if ( file.IsOpened() )
482 {
483 wxPrintf(wxT("File length: %lu\n"), file.Length());
484
485 wxPuts(wxT("File dump:\n----------"));
486
487 static const size_t len = 1024;
488 wxChar buf[len];
489 for ( ;; )
490 {
491 size_t nRead = file.Read(buf, len);
492 if ( nRead == (size_t)wxInvalidOffset )
493 {
494 wxPrintf(wxT("Failed to read the file."));
495 break;
496 }
497
498 fwrite(buf, nRead, 1, stdout);
499
500 if ( nRead < len )
501 break;
502 }
503
504 wxPuts(wxT("----------"));
505 }
506 else
507 {
508 wxPrintf(wxT("ERROR: can't open test file.\n"));
509 }
510
511 wxPuts(wxEmptyString);
512 }
513
514 static void TestTextFileRead()
515 {
516 wxPuts(wxT("*** wxTextFile read test ***"));
517
518 wxTextFile file(wxT("testdata.fc"));
519 if ( file.Open() )
520 {
521 wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount());
522 wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str());
523
524 wxString s;
525
526 wxPuts(wxT("\nDumping the entire file:"));
527 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
528 {
529 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
530 }
531 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
532
533 wxPuts(wxT("\nAnd now backwards:"));
534 for ( s = file.GetLastLine();
535 file.GetCurrentLine() != 0;
536 s = file.GetPrevLine() )
537 {
538 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
539 }
540 wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
541 }
542 else
543 {
544 wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName());
545 }
546
547 wxPuts(wxEmptyString);
548 }
549
550 static void TestFileCopy()
551 {
552 wxPuts(wxT("*** Testing wxCopyFile ***"));
553
554 static const wxChar *filename1 = wxT("testdata.fc");
555 static const wxChar *filename2 = wxT("test2");
556 if ( !wxCopyFile(filename1, filename2) )
557 {
558 wxPuts(wxT("ERROR: failed to copy file"));
559 }
560 else
561 {
562 wxFFile f1(filename1, wxT("rb")),
563 f2(filename2, wxT("rb"));
564
565 if ( !f1.IsOpened() || !f2.IsOpened() )
566 {
567 wxPuts(wxT("ERROR: failed to open file(s)"));
568 }
569 else
570 {
571 wxString s1, s2;
572 if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
573 {
574 wxPuts(wxT("ERROR: failed to read file(s)"));
575 }
576 else
577 {
578 if ( (s1.length() != s2.length()) ||
579 (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
580 {
581 wxPuts(wxT("ERROR: copy error!"));
582 }
583 else
584 {
585 wxPuts(wxT("File was copied ok."));
586 }
587 }
588 }
589 }
590
591 if ( !wxRemoveFile(filename2) )
592 {
593 wxPuts(wxT("ERROR: failed to remove the file"));
594 }
595
596 wxPuts(wxEmptyString);
597 }
598
599 static void TestTempFile()
600 {
601 wxPuts(wxT("*** wxTempFile test ***"));
602
603 wxTempFile tmpFile;
604 if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) )
605 {
606 if ( tmpFile.Commit() )
607 wxPuts(wxT("File committed."));
608 else
609 wxPuts(wxT("ERROR: could't commit temp file."));
610
611 wxRemoveFile(wxT("test2"));
612 }
613
614 wxPuts(wxEmptyString);
615 }
616
617 #endif // TEST_FILE
618
619 // ----------------------------------------------------------------------------
620 // wxFileName
621 // ----------------------------------------------------------------------------
622
623 #ifdef TEST_FILENAME
624
625 #include "wx/filename.h"
626
627 #if 0
628 static void DumpFileName(const wxChar *desc, const wxFileName& fn)
629 {
630 wxPuts(desc);
631
632 wxString full = fn.GetFullPath();
633
634 wxString vol, path, name, ext;
635 wxFileName::SplitPath(full, &vol, &path, &name, &ext);
636
637 wxPrintf(wxT("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
638 full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
639
640 wxFileName::SplitPath(full, &path, &name, &ext);
641 wxPrintf(wxT("or\t\t-> path '%s', name '%s', ext '%s'\n"),
642 path.c_str(), name.c_str(), ext.c_str());
643
644 wxPrintf(wxT("path is also:\t'%s'\n"), fn.GetPath().c_str());
645 wxPrintf(wxT("with volume: \t'%s'\n"),
646 fn.GetPath(wxPATH_GET_VOLUME).c_str());
647 wxPrintf(wxT("with separator:\t'%s'\n"),
648 fn.GetPath(wxPATH_GET_SEPARATOR).c_str());
649 wxPrintf(wxT("with both: \t'%s'\n"),
650 fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str());
651
652 wxPuts(wxT("The directories in the path are:"));
653 wxArrayString dirs = fn.GetDirs();
654 size_t count = dirs.GetCount();
655 for ( size_t n = 0; n < count; n++ )
656 {
657 wxPrintf(wxT("\t%u: %s\n"), n, dirs[n].c_str());
658 }
659 }
660 #endif
661
662 static void TestFileNameTemp()
663 {
664 wxPuts(wxT("*** testing wxFileName temp file creation ***"));
665
666 static const wxChar *tmpprefixes[] =
667 {
668 wxT(""),
669 wxT("foo"),
670 wxT(".."),
671 wxT("../bar"),
672 #ifdef __UNIX__
673 wxT("/tmp/foo"),
674 wxT("/tmp/foo/bar"), // this one must be an error
675 #endif // __UNIX__
676 };
677
678 for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
679 {
680 wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
681 if ( path.empty() )
682 {
683 // "error" is not in upper case because it may be ok
684 wxPrintf(wxT("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
685 }
686 else
687 {
688 wxPrintf(wxT("Prefix '%s'\t-> temp file '%s'\n"),
689 tmpprefixes[n], path.c_str());
690
691 if ( !wxRemoveFile(path) )
692 {
693 wxLogWarning(wxT("Failed to remove temp file '%s'"),
694 path.c_str());
695 }
696 }
697 }
698 }
699
700 static void TestFileNameDirManip()
701 {
702 // TODO: test AppendDir(), RemoveDir(), ...
703 }
704
705 static void TestFileNameComparison()
706 {
707 // TODO!
708 }
709
710 static void TestFileNameOperations()
711 {
712 // TODO!
713 }
714
715 static void TestFileNameCwd()
716 {
717 // TODO!
718 }
719
720 #endif // TEST_FILENAME
721
722 // ----------------------------------------------------------------------------
723 // wxFileName time functions
724 // ----------------------------------------------------------------------------
725
726 #ifdef TEST_FILETIME
727
728 #include "wx/filename.h"
729 #include "wx/datetime.h"
730
731 static void TestFileGetTimes()
732 {
733 wxFileName fn(wxT("testdata.fc"));
734
735 wxDateTime dtAccess, dtMod, dtCreate;
736 if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
737 {
738 wxPrintf(wxT("ERROR: GetTimes() failed.\n"));
739 }
740 else
741 {
742 static const wxChar *fmt = wxT("%Y-%b-%d %H:%M:%S");
743
744 wxPrintf(wxT("File times for '%s':\n"), fn.GetFullPath().c_str());
745 wxPrintf(wxT("Creation: \t%s\n"), dtCreate.Format(fmt).c_str());
746 wxPrintf(wxT("Last read: \t%s\n"), dtAccess.Format(fmt).c_str());
747 wxPrintf(wxT("Last write: \t%s\n"), dtMod.Format(fmt).c_str());
748 }
749 }
750
751 #if 0
752 static void TestFileSetTimes()
753 {
754 wxFileName fn(wxT("testdata.fc"));
755
756 if ( !fn.Touch() )
757 {
758 wxPrintf(wxT("ERROR: Touch() failed.\n"));
759 }
760 }
761 #endif
762
763 #endif // TEST_FILETIME
764
765 // ----------------------------------------------------------------------------
766 // MIME types
767 // ----------------------------------------------------------------------------
768
769 #ifdef TEST_MIME
770
771 #include "wx/mimetype.h"
772
773 static void TestMimeEnum()
774 {
775 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
776
777 wxArrayString mimetypes;
778
779 size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
780
781 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count);
782
783 wxArrayString exts;
784 wxString desc;
785
786 for ( size_t n = 0; n < count; n++ )
787 {
788 wxFileType *filetype =
789 wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
790 if ( !filetype )
791 {
792 wxPrintf(wxT(" nothing known about the filetype '%s'!\n"),
793 mimetypes[n].c_str());
794 continue;
795 }
796
797 filetype->GetDescription(&desc);
798 filetype->GetExtensions(exts);
799
800 filetype->GetIcon(NULL);
801
802 wxString extsAll;
803 for ( size_t e = 0; e < exts.GetCount(); e++ )
804 {
805 if ( e > 0 )
806 extsAll << wxT(", ");
807 extsAll += exts[e];
808 }
809
810 wxPrintf(wxT(" %s: %s (%s)\n"),
811 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
812 }
813
814 wxPuts(wxEmptyString);
815 }
816
817 static void TestMimeFilename()
818 {
819 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
820
821 static const wxChar *filenames[] =
822 {
823 wxT("readme.txt"),
824 wxT("document.pdf"),
825 wxT("image.gif"),
826 wxT("picture.jpeg"),
827 };
828
829 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
830 {
831 const wxString fname = filenames[n];
832 wxString ext = fname.AfterLast(wxT('.'));
833 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
834 if ( !ft )
835 {
836 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext.c_str());
837 }
838 else
839 {
840 wxString desc;
841 if ( !ft->GetDescription(&desc) )
842 desc = wxT("<no description>");
843
844 wxString cmd;
845 if ( !ft->GetOpenCommand(&cmd,
846 wxFileType::MessageParameters(fname, wxEmptyString)) )
847 cmd = wxT("<no command available>");
848 else
849 cmd = wxString(wxT('"')) + cmd + wxT('"');
850
851 wxPrintf(wxT("To open %s (%s) run:\n %s\n"),
852 fname.c_str(), desc.c_str(), cmd.c_str());
853
854 delete ft;
855 }
856 }
857
858 wxPuts(wxEmptyString);
859 }
860
861 static void TestMimeAssociate()
862 {
863 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
864
865 wxFileTypeInfo ftInfo(
866 wxT("application/x-xyz"),
867 wxT("xyzview '%s'"), // open cmd
868 wxT(""), // print cmd
869 wxT("XYZ File"), // description
870 wxT(".xyz"), // extensions
871 wxNullPtr // end of extensions
872 );
873 ftInfo.SetShortDesc(wxT("XYZFile")); // used under Win32 only
874
875 wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
876 if ( !ft )
877 {
878 wxPuts(wxT("ERROR: failed to create association!"));
879 }
880 else
881 {
882 // TODO: read it back
883 delete ft;
884 }
885
886 wxPuts(wxEmptyString);
887 }
888
889 #endif // TEST_MIME
890
891
892 // ----------------------------------------------------------------------------
893 // misc information functions
894 // ----------------------------------------------------------------------------
895
896 #ifdef TEST_INFO_FUNCTIONS
897
898 #include "wx/utils.h"
899
900 #if TEST_INTERACTIVE
901 static void TestDiskInfo()
902 {
903 wxPuts(wxT("*** Testing wxGetDiskSpace() ***"));
904
905 for ( ;; )
906 {
907 wxChar pathname[128];
908 wxPrintf(wxT("\nEnter a directory name (or 'quit' to escape): "));
909 if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
910 break;
911
912 // kill the last '\n'
913 pathname[wxStrlen(pathname) - 1] = 0;
914
915 if (wxStrcmp(pathname, "quit") == 0)
916 break;
917
918 wxLongLong total, free;
919 if ( !wxGetDiskSpace(pathname, &total, &free) )
920 {
921 wxPuts(wxT("ERROR: wxGetDiskSpace failed."));
922 }
923 else
924 {
925 wxPrintf(wxT("%sKb total, %sKb free on '%s'.\n"),
926 (total / 1024).ToString().c_str(),
927 (free / 1024).ToString().c_str(),
928 pathname);
929 }
930 }
931 }
932 #endif // TEST_INTERACTIVE
933
934 static void TestOsInfo()
935 {
936 wxPuts(wxT("*** Testing OS info functions ***\n"));
937
938 int major, minor;
939 wxGetOsVersion(&major, &minor);
940 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
941 wxGetOsDescription().c_str(), major, minor);
942
943 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
944
945 wxPrintf(wxT("Host name is %s (%s).\n"),
946 wxGetHostName().c_str(), wxGetFullHostName().c_str());
947
948 wxPuts(wxEmptyString);
949 }
950
951 static void TestPlatformInfo()
952 {
953 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
954
955 // get this platform
956 wxPlatformInfo plat;
957
958 wxPrintf(wxT("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str());
959 wxPrintf(wxT("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str());
960 wxPrintf(wxT("Port ID name is: %s\n"), plat.GetPortIdName().c_str());
961 wxPrintf(wxT("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str());
962 wxPrintf(wxT("Architecture is: %s\n"), plat.GetArchName().c_str());
963 wxPrintf(wxT("Endianness is: %s\n"), plat.GetEndiannessName().c_str());
964
965 wxPuts(wxEmptyString);
966 }
967
968 static void TestUserInfo()
969 {
970 wxPuts(wxT("*** Testing user info functions ***\n"));
971
972 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
973 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
974 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
975 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
976
977 wxPuts(wxEmptyString);
978 }
979
980 #endif // TEST_INFO_FUNCTIONS
981
982 // ----------------------------------------------------------------------------
983 // regular expressions
984 // ----------------------------------------------------------------------------
985
986 #if defined TEST_REGEX && TEST_INTERACTIVE
987
988 #include "wx/regex.h"
989
990 static void TestRegExInteractive()
991 {
992 wxPuts(wxT("*** Testing RE interactively ***"));
993
994 for ( ;; )
995 {
996 wxChar pattern[128];
997 wxPrintf(wxT("\nEnter a pattern (or 'quit' to escape): "));
998 if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
999 break;
1000
1001 // kill the last '\n'
1002 pattern[wxStrlen(pattern) - 1] = 0;
1003
1004 if (wxStrcmp(pattern, "quit") == 0)
1005 break;
1006
1007 wxRegEx re;
1008 if ( !re.Compile(pattern) )
1009 {
1010 continue;
1011 }
1012
1013 wxChar text[128];
1014 for ( ;; )
1015 {
1016 wxPrintf(wxT("Enter text to match: "));
1017 if ( !wxFgets(text, WXSIZEOF(text), stdin) )
1018 break;
1019
1020 // kill the last '\n'
1021 text[wxStrlen(text) - 1] = 0;
1022
1023 if ( !re.Matches(text) )
1024 {
1025 wxPrintf(wxT("No match.\n"));
1026 }
1027 else
1028 {
1029 wxPrintf(wxT("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());
1030
1031 size_t start, len;
1032 for ( size_t n = 1; ; n++ )
1033 {
1034 if ( !re.GetMatch(&start, &len, n) )
1035 {
1036 break;
1037 }
1038
1039 wxPrintf(wxT("Subexpr %u matched '%s'\n"),
1040 n, wxString(text + start, len).c_str());
1041 }
1042 }
1043 }
1044 }
1045 }
1046
1047 #endif // TEST_REGEX
1048
1049 // ----------------------------------------------------------------------------
1050 // FTP
1051 // ----------------------------------------------------------------------------
1052
1053 #ifdef TEST_FTP
1054
1055 #include "wx/protocol/ftp.h"
1056 #include "wx/protocol/log.h"
1057
1058 #define FTP_ANONYMOUS
1059
1060 static wxFTP *ftp;
1061
1062 #ifdef FTP_ANONYMOUS
1063 static const wxChar *hostname = wxT("ftp.wxwidgets.org");
1064 static const wxChar *directory = wxT("/pub");
1065 static const wxChar *filename = wxT("welcome.msg");
1066 #else
1067 static const wxChar *hostname = "localhost";
1068 static const wxChar *directory = wxT("/etc");
1069 static const wxChar *filename = wxT("issue");
1070 #endif
1071
1072 static bool TestFtpConnect()
1073 {
1074 wxPuts(wxT("*** Testing FTP connect ***"));
1075
1076 #ifdef FTP_ANONYMOUS
1077 wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
1078 #else // !FTP_ANONYMOUS
1079 wxChar user[256];
1080 wxFgets(user, WXSIZEOF(user), stdin);
1081 user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
1082 ftp->SetUser(user);
1083
1084 wxChar password[256];
1085 wxPrintf(wxT("Password for %s: "), password);
1086 wxFgets(password, WXSIZEOF(password), stdin);
1087 password[wxStrlen(password) - 1] = '\0'; // chop off '\n'
1088 ftp->SetPassword(password);
1089
1090 wxPrintf(wxT("--- Attempting to connect to %s:21 as %s...\n"), hostname, user);
1091 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
1092
1093 if ( !ftp->Connect(hostname) )
1094 {
1095 wxPrintf(wxT("ERROR: failed to connect to %s\n"), hostname);
1096
1097 return false;
1098 }
1099 else
1100 {
1101 wxPrintf(wxT("--- Connected to %s, current directory is '%s'\n"),
1102 hostname, ftp->Pwd().c_str());
1103 ftp->Close();
1104 }
1105
1106 return true;
1107 }
1108
1109 #if TEST_INTERACTIVE
1110 static void TestFtpInteractive()
1111 {
1112 wxPuts(wxT("\n*** Interactive wxFTP test ***"));
1113
1114 wxChar buf[128];
1115
1116 for ( ;; )
1117 {
1118 wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
1119 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
1120 break;
1121
1122 // kill the last '\n'
1123 buf[wxStrlen(buf) - 1] = 0;
1124
1125 // special handling of LIST and NLST as they require data connection
1126 wxString start(buf, 4);
1127 start.MakeUpper();
1128 if ( start == wxT("LIST") || start == wxT("NLST") )
1129 {
1130 wxString wildcard;
1131 if ( wxStrlen(buf) > 4 )
1132 wildcard = buf + 5;
1133
1134 wxArrayString files;
1135 if ( !ftp->GetList(files, wildcard, start == wxT("LIST")) )
1136 {
1137 wxPrintf(wxT("ERROR: failed to get %s of files\n"), start.c_str());
1138 }
1139 else
1140 {
1141 wxPrintf(wxT("--- %s of '%s' under '%s':\n"),
1142 start.c_str(), wildcard.c_str(), ftp->Pwd().c_str());
1143 size_t count = files.GetCount();
1144 for ( size_t n = 0; n < count; n++ )
1145 {
1146 wxPrintf(wxT("\t%s\n"), files[n].c_str());
1147 }
1148 wxPuts(wxT("--- End of the file list"));
1149 }
1150 }
1151 else if ( start == wxT("QUIT") )
1152 {
1153 break; // get out of here!
1154 }
1155 else // !list
1156 {
1157 wxChar ch = ftp->SendCommand(buf);
1158 wxPrintf(wxT("Command %s"), ch ? wxT("succeeded") : wxT("failed"));
1159 if ( ch )
1160 {
1161 wxPrintf(wxT(" (return code %c)"), ch);
1162 }
1163
1164 wxPrintf(wxT(", server reply:\n%s\n\n"), ftp->GetLastResult().c_str());
1165 }
1166 }
1167
1168 wxPuts(wxT("\n"));
1169 }
1170 #endif // TEST_INTERACTIVE
1171 #endif // TEST_FTP
1172
1173 // ----------------------------------------------------------------------------
1174 // stack backtrace
1175 // ----------------------------------------------------------------------------
1176
1177 #ifdef TEST_STACKWALKER
1178
1179 #if wxUSE_STACKWALKER
1180
1181 #include "wx/stackwalk.h"
1182
1183 class StackDump : public wxStackWalker
1184 {
1185 public:
1186 StackDump(const char *argv0)
1187 : wxStackWalker(argv0)
1188 {
1189 }
1190
1191 virtual void Walk(size_t skip = 1, size_t maxdepth = wxSTACKWALKER_MAX_DEPTH)
1192 {
1193 wxPuts(wxT("Stack dump:"));
1194
1195 wxStackWalker::Walk(skip, maxdepth);
1196 }
1197
1198 protected:
1199 virtual void OnStackFrame(const wxStackFrame& frame)
1200 {
1201 printf("[%2d] ", (int) frame.GetLevel());
1202
1203 wxString name = frame.GetName();
1204 if ( !name.empty() )
1205 {
1206 printf("%-20.40s", (const char*)name.mb_str());
1207 }
1208 else
1209 {
1210 printf("0x%08lx", (unsigned long)frame.GetAddress());
1211 }
1212
1213 if ( frame.HasSourceLocation() )
1214 {
1215 printf("\t%s:%d",
1216 (const char*)frame.GetFileName().mb_str(),
1217 (int)frame.GetLine());
1218 }
1219
1220 puts("");
1221
1222 wxString type, val;
1223 for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
1224 {
1225 printf("\t%s %s = %s\n", (const char*)type.mb_str(),
1226 (const char*)name.mb_str(),
1227 (const char*)val.mb_str());
1228 }
1229 }
1230 };
1231
1232 static void TestStackWalk(const char *argv0)
1233 {
1234 wxPuts(wxT("*** Testing wxStackWalker ***"));
1235
1236 StackDump dump(argv0);
1237 dump.Walk();
1238
1239 wxPuts("\n");
1240 }
1241
1242 #endif // wxUSE_STACKWALKER
1243
1244 #endif // TEST_STACKWALKER
1245
1246 // ----------------------------------------------------------------------------
1247 // standard paths
1248 // ----------------------------------------------------------------------------
1249
1250 #ifdef TEST_STDPATHS
1251
1252 #include "wx/stdpaths.h"
1253 #include "wx/wxchar.h" // wxPrintf
1254
1255 static void TestStandardPaths()
1256 {
1257 wxPuts(wxT("*** Testing wxStandardPaths ***"));
1258
1259 wxTheApp->SetAppName(wxT("console"));
1260
1261 wxStandardPathsBase& stdp = wxStandardPaths::Get();
1262 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
1263 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
1264 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
1265 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str());
1266 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
1267 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
1268 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str());
1269 wxPrintf(wxT("Executable path:\t%s\n"), stdp.GetExecutablePath().c_str());
1270 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
1271 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str());
1272 wxPrintf(wxT("Localized res. dir:\t%s\n"),
1273 stdp.GetLocalizedResourcesDir(wxT("fr")).c_str());
1274 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
1275 stdp.GetLocalizedResourcesDir
1276 (
1277 wxT("fr"),
1278 wxStandardPaths::ResourceCat_Messages
1279 ).c_str());
1280
1281 wxPuts("\n");
1282 }
1283
1284 #endif // TEST_STDPATHS
1285
1286 // ----------------------------------------------------------------------------
1287 // wxVolume tests
1288 // ----------------------------------------------------------------------------
1289
1290 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
1291 #undef TEST_VOLUME
1292 #endif
1293
1294 #ifdef TEST_VOLUME
1295
1296 #include "wx/volume.h"
1297
1298 static const wxChar *volumeKinds[] =
1299 {
1300 wxT("floppy"),
1301 wxT("hard disk"),
1302 wxT("CD-ROM"),
1303 wxT("DVD-ROM"),
1304 wxT("network volume"),
1305 wxT("other volume"),
1306 };
1307
1308 static void TestFSVolume()
1309 {
1310 wxPuts(wxT("*** Testing wxFSVolume class ***"));
1311
1312 wxArrayString volumes = wxFSVolume::GetVolumes();
1313 size_t count = volumes.GetCount();
1314
1315 if ( !count )
1316 {
1317 wxPuts(wxT("ERROR: no mounted volumes?"));
1318 return;
1319 }
1320
1321 wxPrintf(wxT("%u mounted volumes found:\n"), count);
1322
1323 for ( size_t n = 0; n < count; n++ )
1324 {
1325 wxFSVolume vol(volumes[n]);
1326 if ( !vol.IsOk() )
1327 {
1328 wxPuts(wxT("ERROR: couldn't create volume"));
1329 continue;
1330 }
1331
1332 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
1333 n + 1,
1334 vol.GetDisplayName().c_str(),
1335 vol.GetName().c_str(),
1336 volumeKinds[vol.GetKind()],
1337 vol.IsWritable() ? wxT("rw") : wxT("ro"),
1338 vol.GetFlags() & wxFS_VOL_REMOVABLE ? wxT("removable")
1339 : wxT("fixed"));
1340 }
1341
1342 wxPuts("\n");
1343 }
1344
1345 #endif // TEST_VOLUME
1346
1347 // ----------------------------------------------------------------------------
1348 // date time
1349 // ----------------------------------------------------------------------------
1350
1351 #ifdef TEST_DATETIME
1352
1353 #include "wx/math.h"
1354 #include "wx/datetime.h"
1355
1356 #if TEST_INTERACTIVE
1357
1358 static void TestDateTimeInteractive()
1359 {
1360 wxPuts(wxT("\n*** interactive wxDateTime tests ***"));
1361
1362 wxChar buf[128];
1363
1364 for ( ;; )
1365 {
1366 wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
1367 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
1368 break;
1369
1370 // kill the last '\n'
1371 buf[wxStrlen(buf) - 1] = 0;
1372
1373 if ( wxString(buf).CmpNoCase("quit") == 0 )
1374 break;
1375
1376 wxDateTime dt;
1377 const wxChar *p = dt.ParseDate(buf);
1378 if ( !p )
1379 {
1380 wxPrintf(wxT("ERROR: failed to parse the date '%s'.\n"), buf);
1381
1382 continue;
1383 }
1384 else if ( *p )
1385 {
1386 wxPrintf(wxT("WARNING: parsed only first %u characters.\n"), p - buf);
1387 }
1388
1389 wxPrintf(wxT("%s: day %u, week of month %u/%u, week of year %u\n"),
1390 dt.Format(wxT("%b %d, %Y")).c_str(),
1391 dt.GetDayOfYear(),
1392 dt.GetWeekOfMonth(wxDateTime::Monday_First),
1393 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
1394 dt.GetWeekOfYear(wxDateTime::Monday_First));
1395 }
1396
1397 wxPuts("\n");
1398 }
1399
1400 #endif // TEST_INTERACTIVE
1401 #endif // TEST_DATETIME
1402
1403 // ----------------------------------------------------------------------------
1404 // single instance
1405 // ----------------------------------------------------------------------------
1406
1407 #ifdef TEST_SNGLINST
1408
1409 #include "wx/snglinst.h"
1410
1411 static bool TestSingleIstance()
1412 {
1413 wxPuts(wxT("\n*** Testing wxSingleInstanceChecker ***"));
1414
1415 wxSingleInstanceChecker checker;
1416 if ( checker.Create(wxT(".wxconsole.lock")) )
1417 {
1418 if ( checker.IsAnotherRunning() )
1419 {
1420 wxPrintf(wxT("Another instance of the program is running, exiting.\n"));
1421
1422 return false;
1423 }
1424
1425 // wait some time to give time to launch another instance
1426 wxPuts(wxT("If you try to run another instance of this program now, it won't start."));
1427 wxPrintf(wxT("Press \"Enter\" to exit wxSingleInstanceChecker test and proceed..."));
1428 wxFgetc(stdin);
1429 }
1430 else // failed to create
1431 {
1432 wxPrintf(wxT("Failed to init wxSingleInstanceChecker.\n"));
1433 }
1434
1435 wxPuts("\n");
1436
1437 return true;
1438 }
1439 #endif // TEST_SNGLINST
1440
1441
1442 // ----------------------------------------------------------------------------
1443 // entry point
1444 // ----------------------------------------------------------------------------
1445
1446 int main(int argc, char **argv)
1447 {
1448 #if wxUSE_UNICODE
1449 wxChar **wxArgv = new wxChar *[argc + 1];
1450
1451 {
1452 int n;
1453
1454 for (n = 0; n < argc; n++ )
1455 {
1456 wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
1457 wxArgv[n] = wxStrdup(warg);
1458 }
1459
1460 wxArgv[n] = NULL;
1461 }
1462 #else // !wxUSE_UNICODE
1463 #define wxArgv argv
1464 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1465
1466 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
1467
1468 wxInitializer initializer;
1469 if ( !initializer )
1470 {
1471 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
1472
1473 return -1;
1474 }
1475
1476 #ifdef TEST_SNGLINST
1477 if (!TestSingleIstance())
1478 return 1;
1479 #endif // TEST_SNGLINST
1480
1481 #ifdef TEST_DIR
1482 #if TEST_ALL
1483 TestDirExists();
1484 TestDirEnum();
1485 #endif
1486 TestDirTraverse();
1487 #endif // TEST_DIR
1488
1489 #ifdef TEST_DYNLIB
1490 TestDllLoad();
1491 TestDllListLoaded();
1492 #endif // TEST_DYNLIB
1493
1494 #ifdef TEST_ENVIRON
1495 TestEnvironment();
1496 #endif // TEST_ENVIRON
1497
1498 #ifdef TEST_FILE
1499 TestFileRead();
1500 TestTextFileRead();
1501 TestFileCopy();
1502 TestTempFile();
1503 #endif // TEST_FILE
1504
1505 #ifdef TEST_FILENAME
1506 TestFileNameTemp();
1507 TestFileNameCwd();
1508 TestFileNameDirManip();
1509 TestFileNameComparison();
1510 TestFileNameOperations();
1511 #endif // TEST_FILENAME
1512
1513 #ifdef TEST_FILETIME
1514 TestFileGetTimes();
1515 #if 0
1516 TestFileSetTimes();
1517 #endif
1518 #endif // TEST_FILETIME
1519
1520 #ifdef TEST_FTP
1521 wxLog::AddTraceMask(FTP_TRACE_MASK);
1522
1523 // wxFTP cannot be a static variable as its ctor needs to access
1524 // wxWidgets internals after it has been initialized
1525 ftp = new wxFTP;
1526 ftp->SetLog(new wxProtocolLog(FTP_TRACE_MASK));
1527 if ( TestFtpConnect() )
1528 TestFtpInteractive();
1529 //else: connecting to the FTP server failed
1530
1531 delete ftp;
1532 #endif // TEST_FTP
1533
1534 #ifdef TEST_MIME
1535 //wxLog::AddTraceMask(wxT("mime"));
1536 TestMimeEnum();
1537 TestMimeAssociate();
1538 TestMimeFilename();
1539 #endif // TEST_MIME
1540
1541 #ifdef TEST_INFO_FUNCTIONS
1542 TestOsInfo();
1543 TestPlatformInfo();
1544 TestUserInfo();
1545
1546 #if TEST_INTERACTIVE
1547 TestDiskInfo();
1548 #endif
1549 #endif // TEST_INFO_FUNCTIONS
1550
1551 #ifdef TEST_PRINTF
1552 TestPrintf();
1553 #endif // TEST_PRINTF
1554
1555 #if defined TEST_REGEX && TEST_INTERACTIVE
1556 TestRegExInteractive();
1557 #endif // defined TEST_REGEX && TEST_INTERACTIVE
1558
1559 #ifdef TEST_DATETIME
1560 #if TEST_INTERACTIVE
1561 TestDateTimeInteractive();
1562 #endif
1563 #endif // TEST_DATETIME
1564
1565 #ifdef TEST_STACKWALKER
1566 #if wxUSE_STACKWALKER
1567 TestStackWalk(argv[0]);
1568 #endif
1569 #endif // TEST_STACKWALKER
1570
1571 #ifdef TEST_STDPATHS
1572 TestStandardPaths();
1573 #endif
1574
1575 #ifdef TEST_USLEEP
1576 wxPuts(wxT("Sleeping for 3 seconds... z-z-z-z-z..."));
1577 wxUsleep(3000);
1578 #endif // TEST_USLEEP
1579
1580 #ifdef TEST_VOLUME
1581 TestFSVolume();
1582 #endif // TEST_VOLUME
1583
1584 #if wxUSE_UNICODE
1585 {
1586 for ( int n = 0; n < argc; n++ )
1587 free(wxArgv[n]);
1588
1589 delete [] wxArgv;
1590 }
1591 #endif // wxUSE_UNICODE
1592
1593 wxUnusedVar(argc);
1594 wxUnusedVar(argv);
1595 return 0;
1596 }