1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWidgets
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
24 #include "wx/string.h"
29 // without this pragma, the stupid compiler precompiles #defines below so that
30 // changing them doesn't "take place" later!
35 // ----------------------------------------------------------------------------
36 // conditional compilation
37 // ----------------------------------------------------------------------------
40 A note about all these conditional compilation macros: this file is used
41 both as a test suite for various non-GUI wxWidgets classes and as a
42 scratchpad for quick tests. So there are two compilation modes: if you
43 define TEST_ALL all tests are run, otherwise you may enable the individual
44 tests individually in the "#else" branch below.
47 // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
48 // test, define it to 1 to do all tests.
56 #define TEST_DLLLOADER
63 // #define TEST_FTP --FIXME! (RN)
66 #define TEST_INFO_FUNCTIONS
77 #define TEST_SCOPEGUARD
79 // #define TEST_SOCKETS --FIXME! (RN)
82 #define TEST_TEXTSTREAM
85 // #define TEST_VCARD -- don't enable this (VZ)
86 // #define TEST_VOLUME --FIXME! (RN)
93 // some tests are interactive, define this to run them
94 #ifdef TEST_INTERACTIVE
95 #undef TEST_INTERACTIVE
97 #define TEST_INTERACTIVE 1
99 #define TEST_INTERACTIVE 0
102 // ----------------------------------------------------------------------------
103 // test class for container objects
104 // ----------------------------------------------------------------------------
106 #if defined(TEST_LIST)
108 class Bar
// Foo is already taken in the hash test
111 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
112 Bar(const Bar
& bar
) : m_name(bar
.m_name
) { ms_bars
++; }
113 ~Bar() { ms_bars
--; }
115 static size_t GetNumber() { return ms_bars
; }
117 const wxChar
*GetName() const { return m_name
; }
122 static size_t ms_bars
;
125 size_t Bar::ms_bars
= 0;
127 #endif // defined(TEST_LIST)
129 // ============================================================================
131 // ============================================================================
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 #if defined(TEST_SOCKETS)
139 // replace TABs with \t and CRs with \n
140 static wxString
MakePrintable(const wxChar
*s
)
143 (void)str
.Replace(_T("\t"), _T("\\t"));
144 (void)str
.Replace(_T("\n"), _T("\\n"));
145 (void)str
.Replace(_T("\r"), _T("\\r"));
150 #endif // MakePrintable() is used
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
158 #include "wx/cmdline.h"
159 #include "wx/datetime.h"
161 #if wxUSE_CMDLINE_PARSER
163 static void ShowCmdLine(const wxCmdLineParser
& parser
)
165 wxString s
= _T("Input files: ");
167 size_t count
= parser
.GetParamCount();
168 for ( size_t param
= 0; param
< count
; param
++ )
170 s
<< parser
.GetParam(param
) << ' ';
174 << _T("Verbose:\t") << (parser
.Found(_T("v")) ? _T("yes") : _T("no")) << '\n'
175 << _T("Quiet:\t") << (parser
.Found(_T("q")) ? _T("yes") : _T("no")) << '\n';
180 if ( parser
.Found(_T("o"), &strVal
) )
181 s
<< _T("Output file:\t") << strVal
<< '\n';
182 if ( parser
.Found(_T("i"), &strVal
) )
183 s
<< _T("Input dir:\t") << strVal
<< '\n';
184 if ( parser
.Found(_T("s"), &lVal
) )
185 s
<< _T("Size:\t") << lVal
<< '\n';
186 if ( parser
.Found(_T("d"), &dt
) )
187 s
<< _T("Date:\t") << dt
.FormatISODate() << '\n';
188 if ( parser
.Found(_T("project_name"), &strVal
) )
189 s
<< _T("Project:\t") << strVal
<< '\n';
194 #endif // wxUSE_CMDLINE_PARSER
196 static void TestCmdLineConvert()
198 static const wxChar
*cmdlines
[] =
201 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
202 _T("literal \\\" and \"\""),
205 for ( size_t n
= 0; n
< WXSIZEOF(cmdlines
); n
++ )
207 const wxChar
*cmdline
= cmdlines
[n
];
208 wxPrintf(_T("Parsing: %s\n"), cmdline
);
209 wxArrayString args
= wxCmdLineParser::ConvertStringToArgs(cmdline
);
211 size_t count
= args
.GetCount();
212 wxPrintf(_T("\targc = %u\n"), count
);
213 for ( size_t arg
= 0; arg
< count
; arg
++ )
215 wxPrintf(_T("\targv[%u] = %s\n"), arg
, args
[arg
].c_str());
220 #endif // TEST_CMDLINE
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
231 static const wxChar
*ROOTDIR
= _T("/");
232 static const wxChar
*TESTDIR
= _T("/usr/local/share");
233 #elif defined(__WXMSW__)
234 static const wxChar
*ROOTDIR
= _T("c:\\");
235 static const wxChar
*TESTDIR
= _T("d:\\");
237 #error "don't know where the root directory is"
240 static void TestDirEnumHelper(wxDir
& dir
,
241 int flags
= wxDIR_DEFAULT
,
242 const wxString
& filespec
= wxEmptyString
)
246 if ( !dir
.IsOpened() )
249 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
252 wxPrintf(_T("\t%s\n"), filename
.c_str());
254 cont
= dir
.GetNext(&filename
);
257 wxPuts(wxEmptyString
);
260 static void TestDirEnum()
262 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
264 wxString cwd
= wxGetCwd();
265 if ( !wxDir::Exists(cwd
) )
267 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd
.c_str());
272 if ( !dir
.IsOpened() )
274 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd
.c_str());
278 wxPuts(_T("Enumerating everything in current directory:"));
279 TestDirEnumHelper(dir
);
281 wxPuts(_T("Enumerating really everything in current directory:"));
282 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
284 wxPuts(_T("Enumerating object files in current directory:"));
285 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, _T("*.o*"));
287 wxPuts(_T("Enumerating directories in current directory:"));
288 TestDirEnumHelper(dir
, wxDIR_DIRS
);
290 wxPuts(_T("Enumerating files in current directory:"));
291 TestDirEnumHelper(dir
, wxDIR_FILES
);
293 wxPuts(_T("Enumerating files including hidden in current directory:"));
294 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
298 wxPuts(_T("Enumerating everything in root directory:"));
299 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
301 wxPuts(_T("Enumerating directories in root directory:"));
302 TestDirEnumHelper(dir
, wxDIR_DIRS
);
304 wxPuts(_T("Enumerating files in root directory:"));
305 TestDirEnumHelper(dir
, wxDIR_FILES
);
307 wxPuts(_T("Enumerating files including hidden in root directory:"));
308 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
310 wxPuts(_T("Enumerating files in non existing directory:"));
311 wxDir
dirNo(_T("nosuchdir"));
312 TestDirEnumHelper(dirNo
);
315 class DirPrintTraverser
: public wxDirTraverser
318 virtual wxDirTraverseResult
OnFile(const wxString
& WXUNUSED(filename
))
320 return wxDIR_CONTINUE
;
323 virtual wxDirTraverseResult
OnDir(const wxString
& dirname
)
325 wxString path
, name
, ext
;
326 wxSplitPath(dirname
, &path
, &name
, &ext
);
329 name
<< _T('.') << ext
;
332 for ( const wxChar
*p
= path
.c_str(); *p
; p
++ )
334 if ( wxIsPathSeparator(*p
) )
338 wxPrintf(_T("%s%s\n"), indent
.c_str(), name
.c_str());
340 return wxDIR_CONTINUE
;
344 static void TestDirTraverse()
346 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
350 size_t n
= wxDir::GetAllFiles(TESTDIR
, &files
);
351 wxPrintf(_T("There are %u files under '%s'\n"), n
, TESTDIR
);
354 wxPrintf(_T("First one is '%s'\n"), files
[0u].c_str());
355 wxPrintf(_T(" last one is '%s'\n"), files
[n
- 1].c_str());
358 // enum again with custom traverser
359 wxPuts(_T("Now enumerating directories:"));
361 DirPrintTraverser traverser
;
362 dir
.Traverse(traverser
, wxEmptyString
, wxDIR_DIRS
| wxDIR_HIDDEN
);
365 static void TestDirExists()
367 wxPuts(_T("*** Testing wxDir::Exists() ***"));
369 static const wxChar
*dirnames
[] =
372 #if defined(__WXMSW__)
375 _T("\\\\share\\file"),
379 _T("c:\\autoexec.bat"),
380 #elif defined(__UNIX__)
389 for ( size_t n
= 0; n
< WXSIZEOF(dirnames
); n
++ )
391 wxPrintf(_T("%-40s: %s\n"),
393 wxDir::Exists(dirnames
[n
]) ? _T("exists")
394 : _T("doesn't exist"));
400 // ----------------------------------------------------------------------------
402 // ----------------------------------------------------------------------------
404 #ifdef TEST_DLLLOADER
406 #include "wx/dynlib.h"
408 static void TestDllLoad()
410 #if defined(__WXMSW__)
411 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
412 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
413 #elif defined(__UNIX__)
414 // weird: using just libc.so does *not* work!
415 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
416 static const wxChar
*FUNC_NAME
= _T("strlen");
418 #error "don't know how to test wxDllLoader on this platform"
421 wxPuts(_T("*** testing wxDllLoader ***\n"));
423 wxDynamicLibrary
lib(LIB_NAME
);
424 if ( !lib
.IsLoaded() )
426 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
430 typedef int (*wxStrlenType
)(const char *);
431 wxStrlenType pfnStrlen
= (wxStrlenType
)lib
.GetSymbol(FUNC_NAME
);
434 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
435 FUNC_NAME
, LIB_NAME
);
439 if ( pfnStrlen("foo") != 3 )
441 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
445 wxPuts(_T("... ok"));
451 #endif // TEST_DLLLOADER
453 // ----------------------------------------------------------------------------
455 // ----------------------------------------------------------------------------
459 #include "wx/utils.h"
461 static wxString
MyGetEnv(const wxString
& var
)
464 if ( !wxGetEnv(var
, &val
) )
467 val
= wxString(_T('\'')) + val
+ _T('\'');
472 static void TestEnvironment()
474 const wxChar
*var
= _T("wxTestVar");
476 wxPuts(_T("*** testing environment access functions ***"));
478 wxPrintf(_T("Initially getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
479 wxSetEnv(var
, _T("value for wxTestVar"));
480 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
481 wxSetEnv(var
, _T("another value"));
482 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
484 wxPrintf(_T("After wxUnsetEnv: getenv(%s) = %s\n"), var
, MyGetEnv(var
).c_str());
485 wxPrintf(_T("PATH = %s\n"), MyGetEnv(_T("PATH")).c_str());
488 #endif // TEST_ENVIRON
490 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
496 #include "wx/utils.h"
498 static void TestExecute()
500 wxPuts(_T("*** testing wxExecute ***"));
503 #define COMMAND "cat -n ../../Makefile" // "echo hi"
504 #define SHELL_COMMAND "echo hi from shell"
505 #define REDIRECT_COMMAND COMMAND // "date"
506 #elif defined(__WXMSW__)
507 #define COMMAND "command.com /c echo hi"
508 #define SHELL_COMMAND "echo hi"
509 #define REDIRECT_COMMAND COMMAND
511 #error "no command to exec"
514 wxPrintf(_T("Testing wxShell: "));
516 if ( wxShell(_T(SHELL_COMMAND
)) )
519 wxPuts(_T("ERROR."));
521 wxPrintf(_T("Testing wxExecute: "));
523 if ( wxExecute(_T(COMMAND
), true /* sync */) == 0 )
526 wxPuts(_T("ERROR."));
528 #if 0 // no, it doesn't work (yet?)
529 wxPrintf(_T("Testing async wxExecute: "));
531 if ( wxExecute(COMMAND
) != 0 )
532 wxPuts(_T("Ok (command launched)."));
534 wxPuts(_T("ERROR."));
537 wxPrintf(_T("Testing wxExecute with redirection:\n"));
538 wxArrayString output
;
539 if ( wxExecute(_T(REDIRECT_COMMAND
), output
) != 0 )
541 wxPuts(_T("ERROR."));
545 size_t count
= output
.GetCount();
546 for ( size_t n
= 0; n
< count
; n
++ )
548 wxPrintf(_T("\t%s\n"), output
[n
].c_str());
555 #endif // TEST_EXECUTE
557 // ----------------------------------------------------------------------------
559 // ----------------------------------------------------------------------------
564 #include "wx/ffile.h"
565 #include "wx/textfile.h"
567 static void TestFileRead()
569 wxPuts(_T("*** wxFile read test ***"));
571 wxFile
file(_T("testdata.fc"));
572 if ( file
.IsOpened() )
574 wxPrintf(_T("File length: %lu\n"), file
.Length());
576 wxPuts(_T("File dump:\n----------"));
578 static const off_t len
= 1024;
582 off_t nRead
= file
.Read(buf
, len
);
583 if ( nRead
== wxInvalidOffset
)
585 wxPrintf(_T("Failed to read the file."));
589 fwrite(buf
, nRead
, 1, stdout
);
595 wxPuts(_T("----------"));
599 wxPrintf(_T("ERROR: can't open test file.\n"));
602 wxPuts(wxEmptyString
);
605 static void TestTextFileRead()
607 wxPuts(_T("*** wxTextFile read test ***"));
609 wxTextFile
file(_T("testdata.fc"));
612 wxPrintf(_T("Number of lines: %u\n"), file
.GetLineCount());
613 wxPrintf(_T("Last line: '%s'\n"), file
.GetLastLine().c_str());
617 wxPuts(_T("\nDumping the entire file:"));
618 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
620 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
622 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
624 wxPuts(_T("\nAnd now backwards:"));
625 for ( s
= file
.GetLastLine();
626 file
.GetCurrentLine() != 0;
627 s
= file
.GetPrevLine() )
629 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
631 wxPrintf(_T("%6u: %s\n"), file
.GetCurrentLine() + 1, s
.c_str());
635 wxPrintf(_T("ERROR: can't open '%s'\n"), file
.GetName());
638 wxPuts(wxEmptyString
);
641 static void TestFileCopy()
643 wxPuts(_T("*** Testing wxCopyFile ***"));
645 static const wxChar
*filename1
= _T("testdata.fc");
646 static const wxChar
*filename2
= _T("test2");
647 if ( !wxCopyFile(filename1
, filename2
) )
649 wxPuts(_T("ERROR: failed to copy file"));
653 wxFFile
f1(filename1
, _T("rb")),
654 f2(filename2
, _T("rb"));
656 if ( !f1
.IsOpened() || !f2
.IsOpened() )
658 wxPuts(_T("ERROR: failed to open file(s)"));
663 if ( !f1
.ReadAll(&s1
) || !f2
.ReadAll(&s2
) )
665 wxPuts(_T("ERROR: failed to read file(s)"));
669 if ( (s1
.length() != s2
.length()) ||
670 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) != 0) )
672 wxPuts(_T("ERROR: copy error!"));
676 wxPuts(_T("File was copied ok."));
682 if ( !wxRemoveFile(filename2
) )
684 wxPuts(_T("ERROR: failed to remove the file"));
687 wxPuts(wxEmptyString
);
692 // ----------------------------------------------------------------------------
694 // ----------------------------------------------------------------------------
698 #include "wx/confbase.h"
699 #include "wx/fileconf.h"
701 static const struct FileConfTestData
703 const wxChar
*name
; // value name
704 const wxChar
*value
; // the value from the file
707 { _T("value1"), _T("one") },
708 { _T("value2"), _T("two") },
709 { _T("novalue"), _T("default") },
712 static void TestFileConfRead()
714 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
716 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
717 _T("testdata.fc"), wxEmptyString
,
718 wxCONFIG_USE_RELATIVE_PATH
);
720 // test simple reading
721 wxPuts(_T("\nReading config file:"));
722 wxString
defValue(_T("default")), value
;
723 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
725 const FileConfTestData
& data
= fcTestData
[n
];
726 value
= fileconf
.Read(data
.name
, defValue
);
727 wxPrintf(_T("\t%s = %s "), data
.name
, value
.c_str());
728 if ( value
== data
.value
)
734 wxPrintf(_T("(ERROR: should be %s)\n"), data
.value
);
738 // test enumerating the entries
739 wxPuts(_T("\nEnumerating all root entries:"));
742 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
745 wxPrintf(_T("\t%s = %s\n"),
747 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
749 cont
= fileconf
.GetNextEntry(name
, dummy
);
752 static const wxChar
*testEntry
= _T("TestEntry");
753 wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
754 fileconf
.Write(testEntry
, _T("A value"));
755 fileconf
.DeleteEntry(testEntry
);
756 wxPrintf(fileconf
.HasEntry(testEntry
) ? _T("ERROR\n") : _T("ok\n"));
759 #endif // TEST_FILECONF
761 // ----------------------------------------------------------------------------
763 // ----------------------------------------------------------------------------
767 #include "wx/filename.h"
770 static void DumpFileName(const wxChar
*desc
, const wxFileName
& fn
)
774 wxString full
= fn
.GetFullPath();
776 wxString vol
, path
, name
, ext
;
777 wxFileName::SplitPath(full
, &vol
, &path
, &name
, &ext
);
779 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
780 full
.c_str(), vol
.c_str(), path
.c_str(), name
.c_str(), ext
.c_str());
782 wxFileName::SplitPath(full
, &path
, &name
, &ext
);
783 wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
784 path
.c_str(), name
.c_str(), ext
.c_str());
786 wxPrintf(_T("path is also:\t'%s'\n"), fn
.GetPath().c_str());
787 wxPrintf(_T("with volume: \t'%s'\n"),
788 fn
.GetPath(wxPATH_GET_VOLUME
).c_str());
789 wxPrintf(_T("with separator:\t'%s'\n"),
790 fn
.GetPath(wxPATH_GET_SEPARATOR
).c_str());
791 wxPrintf(_T("with both: \t'%s'\n"),
792 fn
.GetPath(wxPATH_GET_SEPARATOR
| wxPATH_GET_VOLUME
).c_str());
794 wxPuts(_T("The directories in the path are:"));
795 wxArrayString dirs
= fn
.GetDirs();
796 size_t count
= dirs
.GetCount();
797 for ( size_t n
= 0; n
< count
; n
++ )
799 wxPrintf(_T("\t%u: %s\n"), n
, dirs
[n
].c_str());
804 static void TestFileNameTemp()
806 wxPuts(_T("*** testing wxFileName temp file creation ***"));
808 static const wxChar
*tmpprefixes
[] =
816 _T("/tmp/foo/bar"), // this one must be an error
820 for ( size_t n
= 0; n
< WXSIZEOF(tmpprefixes
); n
++ )
822 wxString path
= wxFileName::CreateTempFileName(tmpprefixes
[n
]);
825 // "error" is not in upper case because it may be ok
826 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes
[n
]);
830 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
831 tmpprefixes
[n
], path
.c_str());
833 if ( !wxRemoveFile(path
) )
835 wxLogWarning(_T("Failed to remove temp file '%s'"),
842 static void TestFileNameMakeRelative()
844 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
846 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
848 const FileNameInfo
& fni
= filenames
[n
];
850 wxFileName
fn(fni
.fullname
, fni
.format
);
852 // choose the base dir of the same format
854 switch ( fni
.format
)
857 base
= _T("/usr/bin/");
866 // TODO: I don't know how this is supposed to work there
869 case wxPATH_NATIVE
: // make gcc happy
871 wxFAIL_MSG( _T("unexpected path format") );
874 wxPrintf(_T("'%s' relative to '%s': "),
875 fn
.GetFullPath(fni
.format
).c_str(), base
.c_str());
877 if ( !fn
.MakeRelativeTo(base
, fni
.format
) )
879 wxPuts(_T("unchanged"));
883 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
888 static void TestFileNameMakeAbsolute()
890 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
892 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
894 const FileNameInfo
& fni
= filenames
[n
];
895 wxFileName
fn(fni
.fullname
, fni
.format
);
897 wxPrintf(_T("'%s' absolutized: "),
898 fn
.GetFullPath(fni
.format
).c_str());
900 wxPrintf(_T("'%s'\n"), fn
.GetFullPath(fni
.format
).c_str());
903 wxPuts(wxEmptyString
);
906 static void TestFileNameDirManip()
908 // TODO: test AppendDir(), RemoveDir(), ...
911 static void TestFileNameComparison()
916 static void TestFileNameOperations()
921 static void TestFileNameCwd()
926 #endif // TEST_FILENAME
928 // ----------------------------------------------------------------------------
929 // wxFileName time functions
930 // ----------------------------------------------------------------------------
934 #include <wx/filename.h>
935 #include <wx/datetime.h>
937 static void TestFileGetTimes()
939 wxFileName
fn(_T("testdata.fc"));
941 wxDateTime dtAccess
, dtMod
, dtCreate
;
942 if ( !fn
.GetTimes(&dtAccess
, &dtMod
, &dtCreate
) )
944 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
948 static const wxChar
*fmt
= _T("%Y-%b-%d %H:%M:%S");
950 wxPrintf(_T("File times for '%s':\n"), fn
.GetFullPath().c_str());
951 wxPrintf(_T("Creation: \t%s\n"), dtCreate
.Format(fmt
).c_str());
952 wxPrintf(_T("Last read: \t%s\n"), dtAccess
.Format(fmt
).c_str());
953 wxPrintf(_T("Last write: \t%s\n"), dtMod
.Format(fmt
).c_str());
958 static void TestFileSetTimes()
960 wxFileName
fn(_T("testdata.fc"));
964 wxPrintf(_T("ERROR: Touch() failed.\n"));
969 #endif // TEST_FILETIME
971 // ----------------------------------------------------------------------------
973 // ----------------------------------------------------------------------------
977 #include "wx/hashmap.h"
979 // test compilation of basic map types
980 WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash
, wxPointerEqual
, myPtrHashMap
);
981 WX_DECLARE_HASH_MAP( long, long, wxIntegerHash
, wxIntegerEqual
, myLongHashMap
);
982 WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash
, wxIntegerEqual
,
984 WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash
, wxIntegerEqual
,
986 WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash
, wxIntegerEqual
,
988 WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash
, wxIntegerEqual
,
990 WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash
, wxIntegerEqual
,
994 // WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
995 // myStringHashMap );
996 WX_DECLARE_STRING_HASH_MAP(wxString
, myStringHashMap
);
998 typedef myStringHashMap::iterator Itor
;
1000 static void TestHashMap()
1002 wxPuts(_T("*** Testing wxHashMap ***\n"));
1003 myStringHashMap
sh(0); // as small as possible
1006 const size_t count
= 10000;
1008 // init with some data
1009 for( i
= 0; i
< count
; ++i
)
1011 buf
.Printf(wxT("%d"), i
);
1012 sh
[buf
] = wxT("A") + buf
+ wxT("C");
1015 // test that insertion worked
1016 if( sh
.size() != count
)
1018 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh
.size(), count
);
1021 for( i
= 0; i
< count
; ++i
)
1023 buf
.Printf(wxT("%d"), i
);
1024 if( sh
[buf
] != wxT("A") + buf
+ wxT("C") )
1026 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
1031 // check that iterators work
1033 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1037 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
1041 if( it
->second
!= sh
[it
->first
] )
1043 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
1048 if( sh
.size() != i
)
1050 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i
, count
);
1053 // test copy ctor, assignment operator
1054 myStringHashMap
h1( sh
), h2( 0 );
1057 for( i
= 0, it
= sh
.begin(); it
!= sh
.end(); ++it
, ++i
)
1059 if( h1
[it
->first
] != it
->second
)
1061 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it
->first
.c_str());
1064 if( h2
[it
->first
] != it
->second
)
1066 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it
->first
.c_str());
1071 for( i
= 0; i
< count
; ++i
)
1073 buf
.Printf(wxT("%d"), i
);
1074 size_t sz
= sh
.size();
1076 // test find() and erase(it)
1079 it
= sh
.find( buf
);
1080 if( it
!= sh
.end() )
1084 if( sh
.find( buf
) != sh
.end() )
1086 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1090 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i
);
1095 size_t c
= sh
.erase( buf
);
1097 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
1099 if( sh
.find( buf
) != sh
.end() )
1101 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i
);
1105 // count should decrease
1106 if( sh
.size() != sz
- 1 )
1108 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
1112 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
1115 #endif // TEST_HASHMAP
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1123 #include "wx/hashset.h"
1125 // test compilation of basic map types
1126 WX_DECLARE_HASH_SET( int*, wxPointerHash
, wxPointerEqual
, myPtrHashSet
);
1127 WX_DECLARE_HASH_SET( long, wxIntegerHash
, wxIntegerEqual
, myLongHashSet
);
1128 WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash
, wxIntegerEqual
,
1129 myUnsignedHashSet
);
1130 WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash
, wxIntegerEqual
,
1132 WX_DECLARE_HASH_SET( int, wxIntegerHash
, wxIntegerEqual
,
1134 WX_DECLARE_HASH_SET( short, wxIntegerHash
, wxIntegerEqual
,
1136 WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash
, wxIntegerEqual
,
1138 WX_DECLARE_HASH_SET( wxString
, wxStringHash
, wxStringEqual
,
1150 unsigned long operator()(const MyStruct
& s
) const
1151 { return m_dummy(s
.ptr
); }
1152 MyHash
& operator=(const MyHash
&) { return *this; }
1154 wxPointerHash m_dummy
;
1160 bool operator()(const MyStruct
& s1
, const MyStruct
& s2
) const
1161 { return s1
.ptr
== s2
.ptr
; }
1162 MyEqual
& operator=(const MyEqual
&) { return *this; }
1165 WX_DECLARE_HASH_SET( MyStruct
, MyHash
, MyEqual
, mySet
);
1167 typedef myTestHashSet5 wxStringHashSet
;
1169 static void TestHashSet()
1171 wxPrintf(_T("*** Testing wxHashSet ***\n"));
1173 wxStringHashSet set1
;
1175 set1
.insert( _T("abc") );
1176 set1
.insert( _T("bbc") );
1177 set1
.insert( _T("cbc") );
1178 set1
.insert( _T("abc") );
1180 if( set1
.size() != 3 )
1181 wxPrintf(_T("*** ERROR IN INSERT ***\n"));
1187 tmp
.ptr
= &dummy
; tmp
.str
= _T("ABC");
1189 tmp
.ptr
= &dummy
+ 1;
1191 tmp
.ptr
= &dummy
; tmp
.str
= _T("CDE");
1194 if( set2
.size() != 2 )
1195 wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
1197 mySet::iterator it
= set2
.find( tmp
);
1199 if( it
== set2
.end() )
1200 wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
1201 if( it
->ptr
!= &dummy
)
1202 wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
1203 if( it
->str
!= _T("ABC") )
1204 wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
1206 wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
1209 #endif // TEST_HASHSET
1211 // ----------------------------------------------------------------------------
1213 // ----------------------------------------------------------------------------
1217 #include "wx/list.h"
1219 WX_DECLARE_LIST(Bar
, wxListBars
);
1220 #include "wx/listimpl.cpp"
1221 WX_DEFINE_LIST(wxListBars
);
1223 WX_DECLARE_LIST(int, wxListInt
);
1224 WX_DEFINE_LIST(wxListInt
);
1226 static void TestList()
1228 wxPuts(_T("*** Testing wxList operations ***\n"));
1234 for ( i
= 0; i
< 5; ++i
)
1235 list1
.Append(dummy
+ i
);
1237 if ( list1
.GetCount() != 5 )
1238 wxPuts(_T("Wrong number of items in list\n"));
1240 if ( list1
.Item(3)->GetData() != dummy
+ 3 )
1241 wxPuts(_T("Error in Item()\n"));
1243 if ( !list1
.Find(dummy
+ 4) )
1244 wxPuts(_T("Error in Find()\n"));
1246 wxListInt::compatibility_iterator node
= list1
.GetFirst();
1251 if ( node
->GetData() != dummy
+ i
)
1252 wxPuts(_T("Error in compatibility_iterator\n"));
1253 node
= node
->GetNext();
1257 if ( size_t(i
) != list1
.GetCount() )
1258 wxPuts(_T("Error in compatibility_iterator\n"));
1260 list1
.Insert(dummy
+ 0);
1261 list1
.Insert(1, dummy
+ 1);
1262 list1
.Insert(list1
.GetFirst()->GetNext()->GetNext(), dummy
+ 2);
1264 node
= list1
.GetFirst();
1269 int* t
= node
->GetData();
1270 if ( t
!= dummy
+ i
)
1271 wxPuts(_T("Error in Insert\n"));
1272 node
= node
->GetNext();
1277 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1279 wxPuts(_T("*** Testing std::list operations ***\n"));
1283 wxListInt::iterator it
, en
;
1284 wxListInt::reverse_iterator rit
, ren
;
1286 for ( i
= 0; i
< 5; ++i
)
1287 list1
.push_back(i
+ &i
);
1289 for ( it
= list1
.begin(), en
= list1
.end(), i
= 0;
1290 it
!= en
; ++it
, ++i
)
1291 if ( *it
!= i
+ &i
)
1292 wxPuts(_T("Error in iterator\n"));
1294 for ( rit
= list1
.rbegin(), ren
= list1
.rend(), i
= 4;
1295 rit
!= ren
; ++rit
, --i
)
1296 if ( *rit
!= i
+ &i
)
1297 wxPuts(_T("Error in reverse_iterator\n"));
1299 if ( *list1
.rbegin() != *--list1
.end() ||
1300 *list1
.begin() != *--list1
.rend() )
1301 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1302 if ( *list1
.begin() != *--++list1
.begin() ||
1303 *list1
.rbegin() != *--++list1
.rbegin() )
1304 wxPuts(_T("Error in iterator/reverse_iterator\n"));
1306 if ( list1
.front() != &i
|| list1
.back() != &i
+ 4 )
1307 wxPuts(_T("Error in front()/back()\n"));
1309 list1
.erase(list1
.begin());
1310 list1
.erase(--list1
.end());
1312 for ( it
= list1
.begin(), en
= list1
.end(), i
= 1;
1313 it
!= en
; ++it
, ++i
)
1314 if ( *it
!= i
+ &i
)
1315 wxPuts(_T("Error in erase()\n"));
1318 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1321 static void TestListCtor()
1323 wxPuts(_T("*** Testing wxList construction ***\n"));
1327 list1
.Append(new Bar(_T("first")));
1328 list1
.Append(new Bar(_T("second")));
1330 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
1331 list1
.GetCount(), Bar::GetNumber());
1336 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
1337 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
1340 list1
.DeleteContents(true);
1342 WX_CLEAR_LIST(wxListBars
, list1
);
1346 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
1351 // ----------------------------------------------------------------------------
1353 // ----------------------------------------------------------------------------
1357 #include "wx/intl.h"
1358 #include "wx/utils.h" // for wxSetEnv
1360 static wxLocale
gs_localeDefault(wxLANGUAGE_ENGLISH
);
1362 // find the name of the language from its value
1363 static const wxChar
*GetLangName(int lang
)
1365 static const wxChar
*languageNames
[] =
1375 _T("ARABIC_ALGERIA"),
1376 _T("ARABIC_BAHRAIN"),
1379 _T("ARABIC_JORDAN"),
1380 _T("ARABIC_KUWAIT"),
1381 _T("ARABIC_LEBANON"),
1383 _T("ARABIC_MOROCCO"),
1386 _T("ARABIC_SAUDI_ARABIA"),
1389 _T("ARABIC_TUNISIA"),
1396 _T("AZERI_CYRILLIC"),
1411 _T("CHINESE_SIMPLIFIED"),
1412 _T("CHINESE_TRADITIONAL"),
1413 _T("CHINESE_HONGKONG"),
1414 _T("CHINESE_MACAU"),
1415 _T("CHINESE_SINGAPORE"),
1416 _T("CHINESE_TAIWAN"),
1422 _T("DUTCH_BELGIAN"),
1426 _T("ENGLISH_AUSTRALIA"),
1427 _T("ENGLISH_BELIZE"),
1428 _T("ENGLISH_BOTSWANA"),
1429 _T("ENGLISH_CANADA"),
1430 _T("ENGLISH_CARIBBEAN"),
1431 _T("ENGLISH_DENMARK"),
1433 _T("ENGLISH_JAMAICA"),
1434 _T("ENGLISH_NEW_ZEALAND"),
1435 _T("ENGLISH_PHILIPPINES"),
1436 _T("ENGLISH_SOUTH_AFRICA"),
1437 _T("ENGLISH_TRINIDAD"),
1438 _T("ENGLISH_ZIMBABWE"),
1446 _T("FRENCH_BELGIAN"),
1447 _T("FRENCH_CANADIAN"),
1448 _T("FRENCH_LUXEMBOURG"),
1449 _T("FRENCH_MONACO"),
1455 _T("GERMAN_AUSTRIAN"),
1456 _T("GERMAN_BELGIUM"),
1457 _T("GERMAN_LIECHTENSTEIN"),
1458 _T("GERMAN_LUXEMBOURG"),
1476 _T("ITALIAN_SWISS"),
1481 _T("KASHMIRI_INDIA"),
1499 _T("MALAY_BRUNEI_DARUSSALAM"),
1500 _T("MALAY_MALAYSIA"),
1510 _T("NORWEGIAN_BOKMAL"),
1511 _T("NORWEGIAN_NYNORSK"),
1518 _T("PORTUGUESE_BRAZILIAN"),
1521 _T("RHAETO_ROMANCE"),
1524 _T("RUSSIAN_UKRAINE"),
1530 _T("SERBIAN_CYRILLIC"),
1531 _T("SERBIAN_LATIN"),
1532 _T("SERBO_CROATIAN"),
1543 _T("SPANISH_ARGENTINA"),
1544 _T("SPANISH_BOLIVIA"),
1545 _T("SPANISH_CHILE"),
1546 _T("SPANISH_COLOMBIA"),
1547 _T("SPANISH_COSTA_RICA"),
1548 _T("SPANISH_DOMINICAN_REPUBLIC"),
1549 _T("SPANISH_ECUADOR"),
1550 _T("SPANISH_EL_SALVADOR"),
1551 _T("SPANISH_GUATEMALA"),
1552 _T("SPANISH_HONDURAS"),
1553 _T("SPANISH_MEXICAN"),
1554 _T("SPANISH_MODERN"),
1555 _T("SPANISH_NICARAGUA"),
1556 _T("SPANISH_PANAMA"),
1557 _T("SPANISH_PARAGUAY"),
1559 _T("SPANISH_PUERTO_RICO"),
1560 _T("SPANISH_URUGUAY"),
1562 _T("SPANISH_VENEZUELA"),
1566 _T("SWEDISH_FINLAND"),
1584 _T("URDU_PAKISTAN"),
1586 _T("UZBEK_CYRILLIC"),
1599 if ( (size_t)lang
< WXSIZEOF(languageNames
) )
1600 return languageNames
[lang
];
1602 return _T("INVALID");
1605 static void TestDefaultLang()
1607 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
1609 static const wxChar
*langStrings
[] =
1611 NULL
, // system default
1618 _T("de_DE.iso88591"),
1620 _T("?"), // invalid lang spec
1621 _T("klingonese"), // I bet on some systems it does exist...
1624 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1625 wxLocale::GetSystemEncodingName().c_str(),
1626 wxLocale::GetSystemEncoding());
1628 for ( size_t n
= 0; n
< WXSIZEOF(langStrings
); n
++ )
1630 const wxChar
*langStr
= langStrings
[n
];
1633 // FIXME: this doesn't do anything at all under Windows, we need
1634 // to create a new wxLocale!
1635 wxSetEnv(_T("LC_ALL"), langStr
);
1638 int lang
= gs_localeDefault
.GetSystemLanguage();
1639 wxPrintf(_T("Locale for '%s' is %s.\n"),
1640 langStr
? langStr
: _T("system default"), GetLangName(lang
));
1644 #endif // TEST_LOCALE
1646 // ----------------------------------------------------------------------------
1648 // ----------------------------------------------------------------------------
1652 #include "wx/mimetype.h"
1654 static void TestMimeEnum()
1656 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1658 wxArrayString mimetypes
;
1660 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
1662 wxPrintf(_T("*** All %u known filetypes: ***\n"), count
);
1667 for ( size_t n
= 0; n
< count
; n
++ )
1669 wxFileType
*filetype
=
1670 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
1673 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
1674 mimetypes
[n
].c_str());
1678 filetype
->GetDescription(&desc
);
1679 filetype
->GetExtensions(exts
);
1681 filetype
->GetIcon(NULL
);
1684 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
1687 extsAll
<< _T(", ");
1691 wxPrintf(_T("\t%s: %s (%s)\n"),
1692 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
1695 wxPuts(wxEmptyString
);
1698 static void TestMimeOverride()
1700 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1702 static const wxChar
*mailcap
= _T("/tmp/mailcap");
1703 static const wxChar
*mimetypes
= _T("/tmp/mime.types");
1705 if ( wxFile::Exists(mailcap
) )
1706 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1708 wxTheMimeTypesManager
->ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
1710 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1713 if ( wxFile::Exists(mimetypes
) )
1714 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1716 wxTheMimeTypesManager
->ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
1718 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1721 wxPuts(wxEmptyString
);
1724 static void TestMimeFilename()
1726 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1728 static const wxChar
*filenames
[] =
1736 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
1738 const wxString fname
= filenames
[n
];
1739 wxString ext
= fname
.AfterLast(_T('.'));
1740 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
1743 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
1748 if ( !ft
->GetDescription(&desc
) )
1749 desc
= _T("<no description>");
1752 if ( !ft
->GetOpenCommand(&cmd
,
1753 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
1754 cmd
= _T("<no command available>");
1756 cmd
= wxString(_T('"')) + cmd
+ _T('"');
1758 wxPrintf(_T("To open %s (%s) do %s.\n"),
1759 fname
.c_str(), desc
.c_str(), cmd
.c_str());
1765 wxPuts(wxEmptyString
);
1768 static void TestMimeAssociate()
1770 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1772 wxFileTypeInfo
ftInfo(
1773 _T("application/x-xyz"),
1774 _T("xyzview '%s'"), // open cmd
1775 _T(""), // print cmd
1776 _T("XYZ File"), // description
1777 _T(".xyz"), // extensions
1778 NULL
// end of extensions
1780 ftInfo
.SetShortDesc(_T("XYZFile")); // used under Win32 only
1782 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
1785 wxPuts(_T("ERROR: failed to create association!"));
1789 // TODO: read it back
1793 wxPuts(wxEmptyString
);
1798 // ----------------------------------------------------------------------------
1799 // misc information functions
1800 // ----------------------------------------------------------------------------
1802 #ifdef TEST_INFO_FUNCTIONS
1804 #include "wx/utils.h"
1806 static void TestDiskInfo()
1808 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
1812 wxChar pathname
[128];
1813 wxPrintf(_T("\nEnter a directory name: "));
1814 if ( !wxFgets(pathname
, WXSIZEOF(pathname
), stdin
) )
1817 // kill the last '\n'
1818 pathname
[wxStrlen(pathname
) - 1] = 0;
1820 wxLongLong total
, free
;
1821 if ( !wxGetDiskSpace(pathname
, &total
, &free
) )
1823 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1827 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1828 (total
/ 1024).ToString().c_str(),
1829 (free
/ 1024).ToString().c_str(),
1835 static void TestOsInfo()
1837 wxPuts(_T("*** Testing OS info functions ***\n"));
1840 wxGetOsVersion(&major
, &minor
);
1841 wxPrintf(_T("Running under: %s, version %d.%d\n"),
1842 wxGetOsDescription().c_str(), major
, minor
);
1844 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
1846 wxPrintf(_T("Host name is %s (%s).\n"),
1847 wxGetHostName().c_str(), wxGetFullHostName().c_str());
1849 wxPuts(wxEmptyString
);
1852 static void TestUserInfo()
1854 wxPuts(_T("*** Testing user info functions ***\n"));
1856 wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
1857 wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
1858 wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
1859 wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
1861 wxPuts(wxEmptyString
);
1864 #endif // TEST_INFO_FUNCTIONS
1866 // ----------------------------------------------------------------------------
1868 // ----------------------------------------------------------------------------
1870 #ifdef TEST_PATHLIST
1873 #define CMD_IN_PATH _T("ls")
1875 #define CMD_IN_PATH _T("command.com")
1878 static void TestPathList()
1880 wxPuts(_T("*** Testing wxPathList ***\n"));
1882 wxPathList pathlist
;
1883 pathlist
.AddEnvList(_T("PATH"));
1884 wxString path
= pathlist
.FindValidPath(CMD_IN_PATH
);
1887 wxPrintf(_T("ERROR: command not found in the path.\n"));
1891 wxPrintf(_T("Command found in the path as '%s'.\n"), path
.c_str());
1895 #endif // TEST_PATHLIST
1897 // ----------------------------------------------------------------------------
1898 // regular expressions
1899 // ----------------------------------------------------------------------------
1903 #include "wx/regex.h"
1905 static void TestRegExInteractive()
1907 wxPuts(_T("*** Testing RE interactively ***"));
1911 wxChar pattern
[128];
1912 wxPrintf(_T("\nEnter a pattern: "));
1913 if ( !wxFgets(pattern
, WXSIZEOF(pattern
), stdin
) )
1916 // kill the last '\n'
1917 pattern
[wxStrlen(pattern
) - 1] = 0;
1920 if ( !re
.Compile(pattern
) )
1928 wxPrintf(_T("Enter text to match: "));
1929 if ( !wxFgets(text
, WXSIZEOF(text
), stdin
) )
1932 // kill the last '\n'
1933 text
[wxStrlen(text
) - 1] = 0;
1935 if ( !re
.Matches(text
) )
1937 wxPrintf(_T("No match.\n"));
1941 wxPrintf(_T("Pattern matches at '%s'\n"), re
.GetMatch(text
).c_str());
1944 for ( size_t n
= 1; ; n
++ )
1946 if ( !re
.GetMatch(&start
, &len
, n
) )
1951 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1952 n
, wxString(text
+ start
, len
).c_str());
1959 #endif // TEST_REGEX
1961 // ----------------------------------------------------------------------------
1963 // ----------------------------------------------------------------------------
1973 static void TestDbOpen()
1981 // ----------------------------------------------------------------------------
1983 // ----------------------------------------------------------------------------
1986 NB: this stuff was taken from the glibc test suite and modified to build
1987 in wxWidgets: if I read the copyright below properly, this shouldn't
1993 #ifdef wxTEST_PRINTF
1994 // use our functions from wxchar.cpp
1998 // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats
1999 // in the tests below
2000 int wxPrintf( const wxChar
*format
, ... );
2001 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... );
2004 #include "wx/longlong.h"
2008 static void rfg1 (void);
2009 static void rfg2 (void);
2013 fmtchk (const wxChar
*fmt
)
2015 (void) wxPrintf(_T("%s:\t`"), fmt
);
2016 (void) wxPrintf(fmt
, 0x12);
2017 (void) wxPrintf(_T("'\n"));
2021 fmtst1chk (const wxChar
*fmt
)
2023 (void) wxPrintf(_T("%s:\t`"), fmt
);
2024 (void) wxPrintf(fmt
, 4, 0x12);
2025 (void) wxPrintf(_T("'\n"));
2029 fmtst2chk (const wxChar
*fmt
)
2031 (void) wxPrintf(_T("%s:\t`"), fmt
);
2032 (void) wxPrintf(fmt
, 4, 4, 0x12);
2033 (void) wxPrintf(_T("'\n"));
2036 /* This page is covered by the following copyright: */
2038 /* (C) Copyright C E Chew
2040 * Feel free to copy, use and distribute this software provided:
2042 * 1. you do not pretend that you wrote it
2043 * 2. you leave this copyright notice intact.
2047 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2054 /* Formatted Output Test
2056 * This exercises the output formatting code.
2059 wxChar
*PointerNull
= NULL
;
2066 wxChar
*prefix
= buf
;
2069 wxPuts(_T("\nFormatted output test"));
2070 wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n"));
2071 wxStrcpy(prefix
, _T("%"));
2072 for (i
= 0; i
< 2; i
++) {
2073 for (j
= 0; j
< 2; j
++) {
2074 for (k
= 0; k
< 2; k
++) {
2075 for (l
= 0; l
< 2; l
++) {
2076 wxStrcpy(prefix
, _T("%"));
2077 if (i
== 0) wxStrcat(prefix
, _T("-"));
2078 if (j
== 0) wxStrcat(prefix
, _T("+"));
2079 if (k
== 0) wxStrcat(prefix
, _T("#"));
2080 if (l
== 0) wxStrcat(prefix
, _T("0"));
2081 wxPrintf(_T("%5s |"), prefix
);
2082 wxStrcpy(tp
, prefix
);
2083 wxStrcat(tp
, _T("6d |"));
2085 wxStrcpy(tp
, prefix
);
2086 wxStrcat(tp
, _T("6o |"));
2088 wxStrcpy(tp
, prefix
);
2089 wxStrcat(tp
, _T("6x |"));
2091 wxStrcpy(tp
, prefix
);
2092 wxStrcat(tp
, _T("6X |"));
2094 wxStrcpy(tp
, prefix
);
2095 wxStrcat(tp
, _T("6u |"));
2102 wxPrintf(_T("%10s\n"), PointerNull
);
2103 wxPrintf(_T("%-10s\n"), PointerNull
);
2106 static void TestPrintf()
2108 static wxChar shortstr
[] = _T("Hi, Z.");
2109 static wxChar longstr
[] = _T("Good morning, Doctor Chandra. This is Hal. \
2110 I am ready for my first lesson today.");
2112 wxString test_format
;
2116 fmtchk(_T("%4.4x"));
2117 fmtchk(_T("%04.4x"));
2118 fmtchk(_T("%4.3x"));
2119 fmtchk(_T("%04.3x"));
2121 fmtst1chk(_T("%.*x"));
2122 fmtst1chk(_T("%0*x"));
2123 fmtst2chk(_T("%*.*x"));
2124 fmtst2chk(_T("%0*.*x"));
2126 wxString bad_format
= _T("bad format:\t\"%b\"\n");
2127 wxPrintf(bad_format
.c_str());
2128 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL
);
2130 wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
2131 wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345);
2132 wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345);
2133 wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L);
2134 wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
2135 wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
2136 wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
2137 test_format
= _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
2138 wxPrintf(test_format
.c_str(), -123456);
2139 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
2140 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
2142 test_format
= _T("zero-padded string:\t\"%010s\"\n");
2143 wxPrintf(test_format
.c_str(), shortstr
);
2144 test_format
= _T("left-adjusted Z string:\t\"%-010s\"\n");
2145 wxPrintf(test_format
.c_str(), shortstr
);
2146 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr
);
2147 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr
);
2148 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull
);
2149 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr
);
2151 wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
2152 wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234);
2153 wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234);
2154 wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20
);
2155 wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1);
2156 wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34);
2157 wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234);
2158 wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234);
2159 wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34);
2160 wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234);
2161 wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234);
2162 wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20
);
2164 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
2165 wxPrintf (_T(" %6.5f\n"), .1);
2166 wxPrintf (_T("x%5.4fx\n"), .5);
2168 wxPrintf (_T("%#03x\n"), 1);
2170 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
2176 while (niter
-- != 0)
2177 wxPrintf (_T("%.17e\n"), d
/ 2);
2182 // Open Watcom cause compiler error here
2183 // Error! E173: col(24) floating-point constant too small to represent
2184 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
2187 #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
2188 wxPrintf (FORMAT
, 0.0, 0.0, 0.0);
2189 wxPrintf (FORMAT
, 1.0, 1.0, 1.0);
2190 wxPrintf (FORMAT
, -1.0, -1.0, -1.0);
2191 wxPrintf (FORMAT
, 100.0, 100.0, 100.0);
2192 wxPrintf (FORMAT
, 1000.0, 1000.0, 1000.0);
2193 wxPrintf (FORMAT
, 10000.0, 10000.0, 10000.0);
2194 wxPrintf (FORMAT
, 12345.0, 12345.0, 12345.0);
2195 wxPrintf (FORMAT
, 100000.0, 100000.0, 100000.0);
2196 wxPrintf (FORMAT
, 123456.0, 123456.0, 123456.0);
2201 int rc
= wxSnprintf (buf
, WXSIZEOF(buf
), _T("%30s"), _T("foo"));
2203 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
2204 rc
, WXSIZEOF(buf
), buf
);
2207 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
2208 wxSnprintf(buf2
, WXSIZEOFbuf2
), "%.999999u", 10));
2214 wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8);
2215 wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8);
2216 wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8);
2217 wxPrintf (_T("%g should be 123.456\n"), 123.456);
2218 wxPrintf (_T("%g should be 1e+06\n"), 1000000.0);
2219 wxPrintf (_T("%g should be 10\n"), 10.0);
2220 wxPrintf (_T("%g should be 0.02\n"), 0.02);
2224 wxPrintf(_T("%.17f\n"),(1.0/x
/10.0+1.0)*x
-x
);
2230 wxSprintf(buf
,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
2232 result
|= wxStrcmp (buf
,
2233 _T("onetwo three "));
2235 wxPuts (result
!= 0 ? _T("Test failed!") : _T("Test ok."));
2242 wxSprintf(buf
, _T("%07") wxLongLongFmtSpec
_T("o"), wxLL(040000000000));
2244 // for some reason below line fails under Borland
2245 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf
);
2248 if (wxStrcmp (buf
, _T("40000000000")) != 0)
2251 wxPuts (_T("\tFAILED"));
2253 wxUnusedVar(result
);
2254 wxPuts (wxEmptyString
);
2256 #endif // wxLongLong_t
2258 wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX
+ 2, UCHAR_MAX
+ 2);
2259 wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX
+ 2, USHRT_MAX
+ 2);
2261 wxPuts (_T("--- Should be no further output. ---"));
2270 memset (bytes
, '\xff', sizeof bytes
);
2271 wxSprintf (buf
, _T("foo%hhn\n"), &bytes
[3]);
2272 if (bytes
[0] != '\xff' || bytes
[1] != '\xff' || bytes
[2] != '\xff'
2273 || bytes
[4] != '\xff' || bytes
[5] != '\xff' || bytes
[6] != '\xff')
2275 wxPuts (_T("%hhn overwrite more bytes"));
2280 wxPuts (_T("%hhn wrote incorrect value"));
2292 wxSprintf (buf
, _T("%5.s"), _T("xyz"));
2293 if (wxStrcmp (buf
, _T(" ")) != 0)
2294 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" "));
2295 wxSprintf (buf
, _T("%5.f"), 33.3);
2296 if (wxStrcmp (buf
, _T(" 33")) != 0)
2297 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 33"));
2298 wxSprintf (buf
, _T("%8.e"), 33.3e7
);
2299 if (wxStrcmp (buf
, _T(" 3e+08")) != 0)
2300 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3e+08"));
2301 wxSprintf (buf
, _T("%8.E"), 33.3e7
);
2302 if (wxStrcmp (buf
, _T(" 3E+08")) != 0)
2303 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3E+08"));
2304 wxSprintf (buf
, _T("%.g"), 33.3);
2305 if (wxStrcmp (buf
, _T("3e+01")) != 0)
2306 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3e+01"));
2307 wxSprintf (buf
, _T("%.G"), 33.3);
2308 if (wxStrcmp (buf
, _T("3E+01")) != 0)
2309 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3E+01"));
2317 wxString test_format
;
2320 wxSprintf (buf
, _T("%.*g"), prec
, 3.3);
2321 if (wxStrcmp (buf
, _T("3")) != 0)
2322 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2324 wxSprintf (buf
, _T("%.*G"), prec
, 3.3);
2325 if (wxStrcmp (buf
, _T("3")) != 0)
2326 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T("3"));
2328 wxSprintf (buf
, _T("%7.*G"), prec
, 3.33);
2329 if (wxStrcmp (buf
, _T(" 3")) != 0)
2330 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 3"));
2332 test_format
= _T("%04.*o");
2333 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2334 if (wxStrcmp (buf
, _T(" 041")) != 0)
2335 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 041"));
2337 test_format
= _T("%09.*u");
2338 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2339 if (wxStrcmp (buf
, _T(" 0000033")) != 0)
2340 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 0000033"));
2342 test_format
= _T("%04.*x");
2343 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2344 if (wxStrcmp (buf
, _T(" 021")) != 0)
2345 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2347 test_format
= _T("%04.*X");
2348 wxSprintf (buf
, test_format
.c_str(), prec
, 33);
2349 if (wxStrcmp (buf
, _T(" 021")) != 0)
2350 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf
, _T(" 021"));
2353 #endif // TEST_PRINTF
2355 // ----------------------------------------------------------------------------
2356 // registry and related stuff
2357 // ----------------------------------------------------------------------------
2359 // this is for MSW only
2362 #undef TEST_REGISTRY
2367 #include "wx/confbase.h"
2368 #include "wx/msw/regconf.h"
2371 static void TestRegConfWrite()
2373 wxConfig
*config
= new wxConfig(_T("myapp"));
2374 config
->SetPath(_T("/group1"));
2375 config
->Write(_T("entry1"), _T("foo"));
2376 config
->SetPath(_T("/group2"));
2377 config
->Write(_T("entry1"), _T("bar"));
2381 static void TestRegConfRead()
2383 wxConfig
*config
= new wxConfig(_T("myapp"));
2387 config
->SetPath(_T("/"));
2388 wxPuts(_T("Enumerating / subgroups:"));
2389 bool bCont
= config
->GetFirstGroup(str
, dummy
);
2393 bCont
= config
->GetNextGroup(str
, dummy
);
2397 #endif // TEST_REGCONF
2399 #ifdef TEST_REGISTRY
2401 #include "wx/msw/registry.h"
2403 // I chose this one because I liked its name, but it probably only exists under
2405 static const wxChar
*TESTKEY
=
2406 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2408 static void TestRegistryRead()
2410 wxPuts(_T("*** testing registry reading ***"));
2412 wxRegKey
key(TESTKEY
);
2413 wxPrintf(_T("The test key name is '%s'.\n"), key
.GetName().c_str());
2416 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
2421 size_t nSubKeys
, nValues
;
2422 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
2424 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys
, nValues
);
2427 wxPrintf(_T("Enumerating values:\n"));
2431 bool cont
= key
.GetFirstValue(value
, dummy
);
2434 wxPrintf(_T("Value '%s': type "), value
.c_str());
2435 switch ( key
.GetValueType(value
) )
2437 case wxRegKey::Type_None
: wxPrintf(_T("ERROR (none)")); break;
2438 case wxRegKey::Type_String
: wxPrintf(_T("SZ")); break;
2439 case wxRegKey::Type_Expand_String
: wxPrintf(_T("EXPAND_SZ")); break;
2440 case wxRegKey::Type_Binary
: wxPrintf(_T("BINARY")); break;
2441 case wxRegKey::Type_Dword
: wxPrintf(_T("DWORD")); break;
2442 case wxRegKey::Type_Multi_String
: wxPrintf(_T("MULTI_SZ")); break;
2443 default: wxPrintf(_T("other (unknown)")); break;
2446 wxPrintf(_T(", value = "));
2447 if ( key
.IsNumericValue(value
) )
2450 key
.QueryValue(value
, &val
);
2451 wxPrintf(_T("%ld"), val
);
2456 key
.QueryValue(value
, val
);
2457 wxPrintf(_T("'%s'"), val
.c_str());
2459 key
.QueryRawValue(value
, val
);
2460 wxPrintf(_T(" (raw value '%s')"), val
.c_str());
2465 cont
= key
.GetNextValue(value
, dummy
);
2469 static void TestRegistryAssociation()
2472 The second call to deleteself genertaes an error message, with a
2473 messagebox saying .flo is crucial to system operation, while the .ddf
2474 call also fails, but with no error message
2479 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2481 key
= _T("ddxf_auto_file") ;
2482 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2484 key
= _T("ddxf_auto_file") ;
2485 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2487 key
= _T("program,0") ;
2488 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2490 key
= _T("program \"%1\"") ;
2492 key
.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
2494 key
.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
2496 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
2498 key
.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
2502 #endif // TEST_REGISTRY
2504 // ----------------------------------------------------------------------------
2506 // ----------------------------------------------------------------------------
2508 #ifdef TEST_SCOPEGUARD
2510 #include "wx/scopeguard.h"
2512 static void function0() { puts("function0()"); }
2513 static void function1(int n
) { printf("function1(%d)\n", n
); }
2514 static void function2(double x
, char c
) { printf("function2(%g, %c)\n", x
, c
); }
2518 void method0() { printf("method0()\n"); }
2519 void method1(int n
) { printf("method1(%d)\n", n
); }
2520 void method2(double x
, char c
) { printf("method2(%g, %c)\n", x
, c
); }
2523 static void TestScopeGuard()
2525 wxON_BLOCK_EXIT0(function0
);
2526 wxON_BLOCK_EXIT1(function1
, 17);
2527 wxON_BLOCK_EXIT2(function2
, 3.14, 'p');
2530 wxON_BLOCK_EXIT_OBJ0(obj
, &Object::method0
);
2531 wxON_BLOCK_EXIT_OBJ1(obj
, &Object::method1
, 7);
2532 wxON_BLOCK_EXIT_OBJ2(obj
, &Object::method2
, 2.71, 'e');
2534 wxScopeGuard dismissed
= wxMakeGuard(function0
);
2535 dismissed
.Dismiss();
2540 // ----------------------------------------------------------------------------
2542 // ----------------------------------------------------------------------------
2546 #include "wx/socket.h"
2547 #include "wx/protocol/protocol.h"
2548 #include "wx/protocol/http.h"
2550 static void TestSocketServer()
2552 wxPuts(_T("*** Testing wxSocketServer ***\n"));
2554 static const int PORT
= 3000;
2559 wxSocketServer
*server
= new wxSocketServer(addr
);
2560 if ( !server
->Ok() )
2562 wxPuts(_T("ERROR: failed to bind"));
2570 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT
);
2572 wxSocketBase
*socket
= server
->Accept();
2575 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
2579 wxPuts(_T("Server: got a client."));
2581 server
->SetTimeout(60); // 1 min
2584 while ( !close
&& socket
->IsConnected() )
2587 wxChar ch
= _T('\0');
2590 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
2592 // don't log error if the client just close the connection
2593 if ( socket
->IsConnected() )
2595 wxPuts(_T("ERROR: in wxSocket::Read."));
2615 wxPrintf(_T("Server: got '%s'.\n"), s
.c_str());
2616 if ( s
== _T("close") )
2618 wxPuts(_T("Closing connection"));
2622 else if ( s
== _T("quit") )
2627 wxPuts(_T("Shutting down the server"));
2629 else // not a special command
2631 socket
->Write(s
.MakeUpper().c_str(), s
.length());
2632 socket
->Write("\r\n", 2);
2633 wxPrintf(_T("Server: wrote '%s'.\n"), s
.c_str());
2639 wxPuts(_T("Server: lost a client unexpectedly."));
2645 // same as "delete server" but is consistent with GUI programs
2649 static void TestSocketClient()
2651 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2653 static const wxChar
*hostname
= _T("www.wxwidgets.org");
2656 addr
.Hostname(hostname
);
2659 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname
);
2661 wxSocketClient client
;
2662 if ( !client
.Connect(addr
) )
2664 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2668 wxPrintf(_T("--- Connected to %s:%u...\n"),
2669 addr
.Hostname().c_str(), addr
.Service());
2673 // could use simply "GET" here I suppose
2675 wxString::Format(_T("GET http://%s/\r\n"), hostname
);
2676 client
.Write(cmdGet
, cmdGet
.length());
2677 wxPrintf(_T("--- Sent command '%s' to the server\n"),
2678 MakePrintable(cmdGet
).c_str());
2679 client
.Read(buf
, WXSIZEOF(buf
));
2680 wxPrintf(_T("--- Server replied:\n%s"), buf
);
2684 #endif // TEST_SOCKETS
2686 // ----------------------------------------------------------------------------
2688 // ----------------------------------------------------------------------------
2692 #include "wx/protocol/ftp.h"
2696 #define FTP_ANONYMOUS
2698 #ifdef FTP_ANONYMOUS
2699 static const wxChar
*directory
= _T("/pub");
2700 static const wxChar
*filename
= _T("welcome.msg");
2702 static const wxChar
*directory
= _T("/etc");
2703 static const wxChar
*filename
= _T("issue");
2706 static bool TestFtpConnect()
2708 wxPuts(_T("*** Testing FTP connect ***"));
2710 #ifdef FTP_ANONYMOUS
2711 static const wxChar
*hostname
= _T("ftp.wxwidgets.org");
2713 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname
);
2714 #else // !FTP_ANONYMOUS
2715 static const wxChar
*hostname
= "localhost";
2718 wxFgets(user
, WXSIZEOF(user
), stdin
);
2719 user
[wxStrlen(user
) - 1] = '\0'; // chop off '\n'
2722 wxChar password
[256];
2723 wxPrintf(_T("Password for %s: "), password
);
2724 wxFgets(password
, WXSIZEOF(password
), stdin
);
2725 password
[wxStrlen(password
) - 1] = '\0'; // chop off '\n'
2726 ftp
.SetPassword(password
);
2728 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname
, user
);
2729 #endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2731 if ( !ftp
.Connect(hostname
) )
2733 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2739 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
2740 hostname
, ftp
.Pwd().c_str());
2747 // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2748 static void TestFtpWuFtpd()
2751 static const wxChar
*hostname
= _T("ftp.eudora.com");
2752 if ( !ftp
.Connect(hostname
) )
2754 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname
);
2758 static const wxChar
*filename
= _T("eudora/pubs/draft-gellens-submit-09.txt");
2759 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2762 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2766 size_t size
= in
->GetSize();
2767 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2769 wxChar
*data
= new wxChar
[size
];
2770 if ( !in
->Read(data
, size
) )
2772 wxPuts(_T("ERROR: read error"));
2776 wxPrintf(_T("Successfully retrieved the file.\n"));
2785 static void TestFtpList()
2787 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
2790 if ( !ftp
.ChDir(directory
) )
2792 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2795 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2797 // test NLIST and LIST
2798 wxArrayString files
;
2799 if ( !ftp
.GetFilesList(files
) )
2801 wxPuts(_T("ERROR: failed to get NLIST of files"));
2805 wxPrintf(_T("Brief list of files under '%s':\n"), ftp
.Pwd().c_str());
2806 size_t count
= files
.GetCount();
2807 for ( size_t n
= 0; n
< count
; n
++ )
2809 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2811 wxPuts(_T("End of the file list"));
2814 if ( !ftp
.GetDirList(files
) )
2816 wxPuts(_T("ERROR: failed to get LIST of files"));
2820 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp
.Pwd().c_str());
2821 size_t count
= files
.GetCount();
2822 for ( size_t n
= 0; n
< count
; n
++ )
2824 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2826 wxPuts(_T("End of the file list"));
2829 if ( !ftp
.ChDir(_T("..")) )
2831 wxPuts(_T("ERROR: failed to cd to .."));
2834 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2837 static void TestFtpDownload()
2839 wxPuts(_T("*** Testing wxFTP download ***\n"));
2842 wxInputStream
*in
= ftp
.GetInputStream(filename
);
2845 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename
);
2849 size_t size
= in
->GetSize();
2850 wxPrintf(_T("Reading file %s (%u bytes)..."), filename
, size
);
2853 wxChar
*data
= new wxChar
[size
];
2854 if ( !in
->Read(data
, size
) )
2856 wxPuts(_T("ERROR: read error"));
2860 wxPrintf(_T("\nContents of %s:\n%s\n"), filename
, data
);
2868 static void TestFtpFileSize()
2870 wxPuts(_T("*** Testing FTP SIZE command ***"));
2872 if ( !ftp
.ChDir(directory
) )
2874 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory
);
2877 wxPrintf(_T("Current directory is '%s'\n"), ftp
.Pwd().c_str());
2879 if ( ftp
.FileExists(filename
) )
2881 int size
= ftp
.GetFileSize(filename
);
2883 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename
);
2885 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename
, size
);
2889 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename
);
2893 static void TestFtpMisc()
2895 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
2897 if ( ftp
.SendCommand(_T("STAT")) != '2' )
2899 wxPuts(_T("ERROR: STAT failed"));
2903 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp
.GetLastResult().c_str());
2906 if ( ftp
.SendCommand(_T("HELP SITE")) != '2' )
2908 wxPuts(_T("ERROR: HELP SITE failed"));
2912 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
2913 ftp
.GetLastResult().c_str());
2917 static void TestFtpInteractive()
2919 wxPuts(_T("\n*** Interactive wxFTP test ***"));
2925 wxPrintf(_T("Enter FTP command: "));
2926 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
2929 // kill the last '\n'
2930 buf
[wxStrlen(buf
) - 1] = 0;
2932 // special handling of LIST and NLST as they require data connection
2933 wxString
start(buf
, 4);
2935 if ( start
== _T("LIST") || start
== _T("NLST") )
2938 if ( wxStrlen(buf
) > 4 )
2941 wxArrayString files
;
2942 if ( !ftp
.GetList(files
, wildcard
, start
== _T("LIST")) )
2944 wxPrintf(_T("ERROR: failed to get %s of files\n"), start
.c_str());
2948 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
2949 start
.c_str(), wildcard
.c_str(), ftp
.Pwd().c_str());
2950 size_t count
= files
.GetCount();
2951 for ( size_t n
= 0; n
< count
; n
++ )
2953 wxPrintf(_T("\t%s\n"), files
[n
].c_str());
2955 wxPuts(_T("--- End of the file list"));
2960 wxChar ch
= ftp
.SendCommand(buf
);
2961 wxPrintf(_T("Command %s"), ch
? _T("succeeded") : _T("failed"));
2964 wxPrintf(_T(" (return code %c)"), ch
);
2967 wxPrintf(_T(", server reply:\n%s\n\n"), ftp
.GetLastResult().c_str());
2971 wxPuts(_T("\n*** done ***"));
2974 static void TestFtpUpload()
2976 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
2979 static const wxChar
*file1
= _T("test1");
2980 static const wxChar
*file2
= _T("test2");
2981 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
2984 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
2985 out
->Write("First hello", 11);
2989 // send a command to check the remote file
2990 if ( ftp
.SendCommand(wxString(_T("STAT ")) + file1
) != '2' )
2992 wxPrintf(_T("ERROR: STAT %s failed\n"), file1
);
2996 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
2997 file1
, ftp
.GetLastResult().c_str());
3000 out
= ftp
.GetOutputStream(file2
);
3003 wxPrintf(_T("--- Uploading to %s ---\n"), file1
);
3004 out
->Write("Second hello", 12);
3011 // ----------------------------------------------------------------------------
3013 // ----------------------------------------------------------------------------
3015 #ifdef TEST_STDPATHS
3017 #include "wx/stdpaths.h"
3019 static void TestStandardPaths()
3021 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
3023 wxTheApp
->SetAppName(_T("console"));
3025 wxStandardPaths
& stdp
= wxStandardPaths::Get();
3026 wxPrintf(_T("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
3027 wxPrintf(_T("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
3028 wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
3029 wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
3030 wxPrintf(_T("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
3031 wxPrintf(_T("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
3032 wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
3035 #endif // TEST_STDPATHS
3037 // ----------------------------------------------------------------------------
3039 // ----------------------------------------------------------------------------
3043 #include "wx/wfstream.h"
3044 #include "wx/mstream.h"
3046 static void TestFileStream()
3048 wxPuts(_T("*** Testing wxFileInputStream ***"));
3050 static const wxString filename
= _T("testdata.fs");
3052 wxFileOutputStream
fsOut(filename
);
3053 fsOut
.Write("foo", 3);
3056 wxFileInputStream
fsIn(filename
);
3057 wxPrintf(_T("File stream size: %u\n"), fsIn
.GetSize());
3058 while ( !fsIn
.Eof() )
3060 wxPutchar(fsIn
.GetC());
3063 if ( !wxRemoveFile(filename
) )
3065 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename
.c_str());
3068 wxPuts(_T("\n*** wxFileInputStream test done ***"));
3071 static void TestMemoryStream()
3073 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3075 wxMemoryOutputStream memOutStream
;
3076 wxPrintf(_T("Initially out stream offset: %lu\n"),
3077 (unsigned long)memOutStream
.TellO());
3079 for ( const wxChar
*p
= _T("Hello, stream!"); *p
; p
++ )
3081 memOutStream
.PutC(*p
);
3084 wxPrintf(_T("Final out stream offset: %lu\n"),
3085 (unsigned long)memOutStream
.TellO());
3087 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
3090 size_t len
= memOutStream
.CopyTo(buf
, WXSIZEOF(buf
));
3092 wxMemoryInputStream
memInpStream(buf
, len
);
3093 wxPrintf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
3094 while ( !memInpStream
.Eof() )
3096 wxPutchar(memInpStream
.GetC());
3099 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
3102 #endif // TEST_STREAMS
3104 // ----------------------------------------------------------------------------
3106 // ----------------------------------------------------------------------------
3110 #include "wx/timer.h"
3111 #include "wx/utils.h"
3113 static void TestStopWatch()
3115 wxPuts(_T("*** Testing wxStopWatch ***\n"));
3119 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
3122 wxPrintf(_T("\t%ldms\n"), sw
.Time());
3124 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
3128 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3131 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
3134 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3137 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
3140 wxPrintf(_T("\telapsed time: %ldms\n"), sw
.Time());
3143 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
3144 for ( size_t n
= 0; n
< 70; n
++ )
3148 for ( size_t m
= 0; m
< 100000; m
++ )
3150 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
3152 wxPuts(_T("\ntime is negative - ERROR!"));
3160 wxPuts(_T(", ok."));
3163 #endif // TEST_TIMER
3165 // ----------------------------------------------------------------------------
3167 // ----------------------------------------------------------------------------
3171 #include "wx/vcard.h"
3173 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
3176 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
3179 wxPrintf(_T("%s%s"),
3180 wxString(_T('\t'), level
).c_str(),
3181 vcObj
->GetName().c_str());
3184 switch ( vcObj
->GetType() )
3186 case wxVCardObject::String
:
3187 case wxVCardObject::UString
:
3190 vcObj
->GetValue(&val
);
3191 value
<< _T('"') << val
<< _T('"');
3195 case wxVCardObject::Int
:
3198 vcObj
->GetValue(&i
);
3199 value
.Printf(_T("%u"), i
);
3203 case wxVCardObject::Long
:
3206 vcObj
->GetValue(&l
);
3207 value
.Printf(_T("%lu"), l
);
3211 case wxVCardObject::None
:
3214 case wxVCardObject::Object
:
3215 value
= _T("<node>");
3219 value
= _T("<unknown value type>");
3223 wxPrintf(_T(" = %s"), value
.c_str());
3226 DumpVObject(level
+ 1, *vcObj
);
3229 vcObj
= vcard
.GetNextProp(&cookie
);
3233 static void DumpVCardAddresses(const wxVCard
& vcard
)
3235 wxPuts(_T("\nShowing all addresses from vCard:\n"));
3239 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
3243 int flags
= addr
->GetFlags();
3244 if ( flags
& wxVCardAddress::Domestic
)
3246 flagsStr
<< _T("domestic ");
3248 if ( flags
& wxVCardAddress::Intl
)
3250 flagsStr
<< _T("international ");
3252 if ( flags
& wxVCardAddress::Postal
)
3254 flagsStr
<< _T("postal ");
3256 if ( flags
& wxVCardAddress::Parcel
)
3258 flagsStr
<< _T("parcel ");
3260 if ( flags
& wxVCardAddress::Home
)
3262 flagsStr
<< _T("home ");
3264 if ( flags
& wxVCardAddress::Work
)
3266 flagsStr
<< _T("work ");
3269 wxPrintf(_T("Address %u:\n")
3271 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3274 addr
->GetPostOffice().c_str(),
3275 addr
->GetExtAddress().c_str(),
3276 addr
->GetStreet().c_str(),
3277 addr
->GetLocality().c_str(),
3278 addr
->GetRegion().c_str(),
3279 addr
->GetPostalCode().c_str(),
3280 addr
->GetCountry().c_str()
3284 addr
= vcard
.GetNextAddress(&cookie
);
3288 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
3290 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
3294 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
3298 int flags
= phone
->GetFlags();
3299 if ( flags
& wxVCardPhoneNumber::Voice
)
3301 flagsStr
<< _T("voice ");
3303 if ( flags
& wxVCardPhoneNumber::Fax
)
3305 flagsStr
<< _T("fax ");
3307 if ( flags
& wxVCardPhoneNumber::Cellular
)
3309 flagsStr
<< _T("cellular ");
3311 if ( flags
& wxVCardPhoneNumber::Modem
)
3313 flagsStr
<< _T("modem ");
3315 if ( flags
& wxVCardPhoneNumber::Home
)
3317 flagsStr
<< _T("home ");
3319 if ( flags
& wxVCardPhoneNumber::Work
)
3321 flagsStr
<< _T("work ");
3324 wxPrintf(_T("Phone number %u:\n")
3329 phone
->GetNumber().c_str()
3333 phone
= vcard
.GetNextPhoneNumber(&cookie
);
3337 static void TestVCardRead()
3339 wxPuts(_T("*** Testing wxVCard reading ***\n"));
3341 wxVCard
vcard(_T("vcard.vcf"));
3342 if ( !vcard
.IsOk() )
3344 wxPuts(_T("ERROR: couldn't load vCard."));
3348 // read individual vCard properties
3349 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
3353 vcObj
->GetValue(&value
);
3358 value
= _T("<none>");
3361 wxPrintf(_T("Full name retrieved directly: %s\n"), value
.c_str());
3364 if ( !vcard
.GetFullName(&value
) )
3366 value
= _T("<none>");
3369 wxPrintf(_T("Full name from wxVCard API: %s\n"), value
.c_str());
3371 // now show how to deal with multiply occuring properties
3372 DumpVCardAddresses(vcard
);
3373 DumpVCardPhoneNumbers(vcard
);
3375 // and finally show all
3376 wxPuts(_T("\nNow dumping the entire vCard:\n")
3377 "-----------------------------\n");
3379 DumpVObject(0, vcard
);
3383 static void TestVCardWrite()
3385 wxPuts(_T("*** Testing wxVCard writing ***\n"));
3388 if ( !vcard
.IsOk() )
3390 wxPuts(_T("ERROR: couldn't create vCard."));
3395 vcard
.SetName("Zeitlin", "Vadim");
3396 vcard
.SetFullName("Vadim Zeitlin");
3397 vcard
.SetOrganization("wxWidgets", "R&D");
3399 // just dump the vCard back
3400 wxPuts(_T("Entire vCard follows:\n"));
3401 wxPuts(vcard
.Write());
3405 #endif // TEST_VCARD
3407 // ----------------------------------------------------------------------------
3409 // ----------------------------------------------------------------------------
3411 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
3417 #include "wx/volume.h"
3419 static const wxChar
*volumeKinds
[] =
3425 _T("network volume"),
3429 static void TestFSVolume()
3431 wxPuts(_T("*** Testing wxFSVolume class ***"));
3433 wxArrayString volumes
= wxFSVolume::GetVolumes();
3434 size_t count
= volumes
.GetCount();
3438 wxPuts(_T("ERROR: no mounted volumes?"));
3442 wxPrintf(_T("%u mounted volumes found:\n"), count
);
3444 for ( size_t n
= 0; n
< count
; n
++ )
3446 wxFSVolume
vol(volumes
[n
]);
3449 wxPuts(_T("ERROR: couldn't create volume"));
3453 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3455 vol
.GetDisplayName().c_str(),
3456 vol
.GetName().c_str(),
3457 volumeKinds
[vol
.GetKind()],
3458 vol
.IsWritable() ? _T("rw") : _T("ro"),
3459 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? _T("removable")
3464 #endif // TEST_VOLUME
3466 // ----------------------------------------------------------------------------
3467 // wide char and Unicode support
3468 // ----------------------------------------------------------------------------
3472 #include "wx/strconv.h"
3473 #include "wx/fontenc.h"
3474 #include "wx/encconv.h"
3475 #include "wx/buffer.h"
3477 static const unsigned char utf8koi8r
[] =
3479 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
3480 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208,
3481 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
3482 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
3483 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
3484 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
3485 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
3488 static const unsigned char utf8iso8859_1
[] =
3490 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e,
3491 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65,
3492 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65,
3493 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65,
3494 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0
3497 static const unsigned char utf8Invalid
[] =
3499 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30,
3500 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6,
3501 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88,
3502 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70,
3506 static const struct Utf8Data
3508 const unsigned char *text
;
3510 const wxChar
*charset
;
3511 wxFontEncoding encoding
;
3514 { utf8Invalid
, WXSIZEOF(utf8Invalid
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3515 { utf8koi8r
, WXSIZEOF(utf8koi8r
), _T("koi8-r"), wxFONTENCODING_KOI8
},
3516 { utf8iso8859_1
, WXSIZEOF(utf8iso8859_1
), _T("iso8859-1"), wxFONTENCODING_ISO8859_1
},
3519 static void TestUtf8()
3521 wxPuts(_T("*** Testing UTF8 support ***\n"));
3526 for ( size_t n
= 0; n
< WXSIZEOF(utf8data
); n
++ )
3528 const Utf8Data
& u8d
= utf8data
[n
];
3529 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)u8d
.text
,
3530 WXSIZEOF(wbuf
)) == (size_t)-1 )
3532 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3536 wxCSConv
conv(u8d
.charset
);
3537 if ( conv
.WC2MB(buf
, wbuf
, WXSIZEOF(buf
)) == (size_t)-1 )
3539 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d
.charset
);
3543 wxPrintf(_T("String in %s: %s\n"), u8d
.charset
, buf
);
3547 wxString
s(wxConvUTF8
.cMB2WC((const char *)u8d
.text
));
3549 s
= _T("<< conversion failed >>");
3550 wxPrintf(_T("String in current cset: %s\n"), s
.c_str());
3554 wxPuts(wxEmptyString
);
3557 static void TestEncodingConverter()
3559 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3561 // using wxEncodingConverter should give the same result as above
3564 if ( wxConvUTF8
.MB2WC(wbuf
, (const char *)utf8koi8r
,
3565 WXSIZEOF(utf8koi8r
)) == (size_t)-1 )
3567 wxPuts(_T("ERROR: UTF-8 decoding failed."));
3571 wxEncodingConverter ec
;
3572 ec
.Init(wxFONTENCODING_UNICODE
, wxFONTENCODING_KOI8
);
3573 ec
.Convert(wbuf
, buf
);
3574 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf
);
3577 wxPuts(wxEmptyString
);
3580 #endif // TEST_WCHAR
3582 // ----------------------------------------------------------------------------
3584 // ----------------------------------------------------------------------------
3588 #include "wx/filesys.h"
3589 #include "wx/fs_zip.h"
3590 #include "wx/zipstrm.h"
3592 static const wxChar
*TESTFILE_ZIP
= _T("testdata.zip");
3594 static void TestZipStreamRead()
3596 wxPuts(_T("*** Testing ZIP reading ***\n"));
3598 static const wxString filename
= _T("foo");
3599 wxZipInputStream
istr(TESTFILE_ZIP
, filename
);
3600 wxPrintf(_T("Archive size: %u\n"), istr
.GetSize());
3602 wxPrintf(_T("Dumping the file '%s':\n"), filename
.c_str());
3603 while ( !istr
.Eof() )
3605 wxPutchar(istr
.GetC());
3609 wxPuts(_T("\n----- done ------"));
3612 static void DumpZipDirectory(wxFileSystem
& fs
,
3613 const wxString
& dir
,
3614 const wxString
& indent
)
3616 wxString prefix
= wxString::Format(_T("%s#zip:%s"),
3617 TESTFILE_ZIP
, dir
.c_str());
3618 wxString wildcard
= prefix
+ _T("/*");
3620 wxString dirname
= fs
.FindFirst(wildcard
, wxDIR
);
3621 while ( !dirname
.empty() )
3623 if ( !dirname
.StartsWith(prefix
+ _T('/'), &dirname
) )
3625 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3630 wxPrintf(_T("%s%s\n"), indent
.c_str(), dirname
.c_str());
3632 DumpZipDirectory(fs
, dirname
,
3633 indent
+ wxString(_T(' '), 4));
3635 dirname
= fs
.FindNext();
3638 wxString filename
= fs
.FindFirst(wildcard
, wxFILE
);
3639 while ( !filename
.empty() )
3641 if ( !filename
.StartsWith(prefix
, &filename
) )
3643 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3648 wxPrintf(_T("%s%s\n"), indent
.c_str(), filename
.c_str());
3650 filename
= fs
.FindNext();
3654 static void TestZipFileSystem()
3656 wxPuts(_T("*** Testing ZIP file system ***\n"));
3658 wxFileSystem::AddHandler(new wxZipFSHandler
);
3660 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP
);
3662 DumpZipDirectory(fs
, _T(""), wxString(_T(' '), 4));
3667 // ----------------------------------------------------------------------------
3669 // ----------------------------------------------------------------------------
3671 #ifdef TEST_DATETIME
3675 #include "wx/datetime.h"
3677 // this test miscellaneous static wxDateTime functions
3681 static void TestTimeStatic()
3683 wxPuts(_T("\n*** wxDateTime static methods test ***"));
3685 // some info about the current date
3686 int year
= wxDateTime::GetCurrentYear();
3687 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
3689 wxDateTime::IsLeapYear(year
) ? "" : "not ",
3690 wxDateTime::GetNumberOfDays(year
));
3692 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
3693 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
3694 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
3695 wxDateTime::GetMonthName(month
).c_str(),
3696 wxDateTime::GetNumberOfDays(month
));
3699 // test time zones stuff
3700 static void TestTimeZones()
3702 wxPuts(_T("\n*** wxDateTime timezone test ***"));
3704 wxDateTime now
= wxDateTime::Now();
3706 wxPrintf(_T("Current GMT time:\t%s\n"), now
.Format(_T("%c"), wxDateTime::GMT0
).c_str());
3707 wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0
).c_str());
3708 wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST
).c_str());
3709 wxPrintf(_T("Current time in Paris:\t%s\n"), now
.Format(_T("%c"), wxDateTime::CET
).c_str());
3710 wxPrintf(_T(" Moscow:\t%s\n"), now
.Format(_T("%c"), wxDateTime::MSK
).c_str());
3711 wxPrintf(_T(" New York:\t%s\n"), now
.Format(_T("%c"), wxDateTime::EST
).c_str());
3713 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3715 wxDateTime::Tm tm
= now
.GetTm();
3716 if ( wxDateTime(tm
) != now
)
3718 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3719 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
3723 // test some minimal support for the dates outside the standard range
3724 static void TestTimeRange()
3726 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
3728 static const wxChar
*fmt
= _T("%d-%b-%Y %H:%M:%S");
3730 wxPrintf(_T("Unix epoch:\t%s\n"),
3731 wxDateTime(2440587.5).Format(fmt
).c_str());
3732 wxPrintf(_T("Feb 29, 0: \t%s\n"),
3733 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
3734 wxPrintf(_T("JDN 0: \t%s\n"),
3735 wxDateTime(0.0).Format(fmt
).c_str());
3736 wxPrintf(_T("Jan 1, 1AD:\t%s\n"),
3737 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
3738 wxPrintf(_T("May 29, 2099:\t%s\n"),
3739 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
3742 // test DST calculations
3743 static void TestTimeDST()
3745 wxPuts(_T("\n*** wxDateTime DST test ***"));
3747 wxPrintf(_T("DST is%s in effect now.\n\n"),
3748 wxDateTime::Now().IsDST() ? wxEmptyString
: _T(" not"));
3750 for ( int year
= 1990; year
< 2005; year
++ )
3752 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3754 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
3755 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
3761 #if TEST_INTERACTIVE
3763 static void TestDateTimeInteractive()
3765 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
3771 wxPrintf(_T("Enter a date: "));
3772 if ( !wxFgets(buf
, WXSIZEOF(buf
), stdin
) )
3775 // kill the last '\n'
3776 buf
[wxStrlen(buf
) - 1] = 0;
3779 const wxChar
*p
= dt
.ParseDate(buf
);
3782 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf
);
3788 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p
- buf
);
3791 wxPrintf(_T("%s: day %u, week of month %u/%u, week of year %u\n"),
3792 dt
.Format(_T("%b %d, %Y")).c_str(),
3794 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
3795 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
3796 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
3799 wxPuts(_T("\n*** done ***"));
3802 #endif // TEST_INTERACTIVE
3806 static void TestTimeMS()
3808 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
3810 wxDateTime dt1
= wxDateTime::Now(),
3811 dt2
= wxDateTime::UNow();
3813 wxPrintf(_T("Now = %s\n"), dt1
.Format(_T("%H:%M:%S:%l")).c_str());
3814 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3815 wxPrintf(_T("Dummy loop: "));
3816 for ( int i
= 0; i
< 6000; i
++ )
3818 //for ( int j = 0; j < 10; j++ )
3821 s
.Printf(_T("%g"), sqrt((float)i
));
3827 wxPuts(_T(", done"));
3830 dt2
= wxDateTime::UNow();
3831 wxPrintf(_T("UNow = %s\n"), dt2
.Format(_T("%H:%M:%S:%l")).c_str());
3833 wxPrintf(_T("Loop executed in %s ms\n"), (dt2
- dt1
).Format(_T("%l")).c_str());
3835 wxPuts(_T("\n*** done ***"));
3838 static void TestTimeHolidays()
3840 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
3842 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
3843 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
3844 dtEnd
= dtStart
.GetLastMonthDay();
3846 wxDateTimeArray hol
;
3847 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
3849 const wxChar
*format
= _T("%d-%b-%Y (%a)");
3851 wxPrintf(_T("All holidays between %s and %s:\n"),
3852 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
3854 size_t count
= hol
.GetCount();
3855 for ( size_t n
= 0; n
< count
; n
++ )
3857 wxPrintf(_T("\t%s\n"), hol
[n
].Format(format
).c_str());
3860 wxPuts(wxEmptyString
);
3863 static void TestTimeZoneBug()
3865 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
3867 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
3868 for ( int i
= 0; i
< 31; i
++ )
3870 wxPrintf(_T("Date %s: week day %s.\n"),
3871 date
.Format(_T("%d-%m-%Y")).c_str(),
3872 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
3874 date
+= wxDateSpan::Day();
3877 wxPuts(wxEmptyString
);
3880 static void TestTimeSpanFormat()
3882 wxPuts(_T("\n*** wxTimeSpan tests ***"));
3884 static const wxChar
*formats
[] =
3886 _T("(default) %H:%M:%S"),
3887 _T("%E weeks and %D days"),
3888 _T("%l milliseconds"),
3889 _T("(with ms) %H:%M:%S:%l"),
3890 _T("100%% of minutes is %M"), // test "%%"
3891 _T("%D days and %H hours"),
3892 _T("or also %S seconds"),
3895 wxTimeSpan
ts1(1, 2, 3, 4),
3897 for ( size_t n
= 0; n
< WXSIZEOF(formats
); n
++ )
3899 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
3900 ts1
.Format(formats
[n
]).c_str(),
3901 ts2
.Format(formats
[n
]).c_str());
3904 wxPuts(wxEmptyString
);
3909 #endif // TEST_DATETIME
3911 // ----------------------------------------------------------------------------
3912 // wxTextInput/OutputStream
3913 // ----------------------------------------------------------------------------
3915 #ifdef TEST_TEXTSTREAM
3917 #include "wx/txtstrm.h"
3918 #include "wx/wfstream.h"
3920 static void TestTextInputStream()
3922 wxPuts(_T("\n*** wxTextInputStream test ***"));
3924 wxString filename
= _T("testdata.fc");
3925 wxFileInputStream
fsIn(filename
);
3928 wxPuts(_T("ERROR: couldn't open file."));
3932 wxTextInputStream
tis(fsIn
);
3937 const wxString s
= tis
.ReadLine();
3939 // line could be non empty if the last line of the file isn't
3940 // terminated with EOL
3941 if ( fsIn
.Eof() && s
.empty() )
3944 wxPrintf(_T("Line %d: %s\n"), line
++, s
.c_str());
3949 #endif // TEST_TEXTSTREAM
3951 // ----------------------------------------------------------------------------
3953 // ----------------------------------------------------------------------------
3957 #include "wx/thread.h"
3959 static size_t gs_counter
= (size_t)-1;
3960 static wxCriticalSection gs_critsect
;
3961 static wxSemaphore gs_cond
;
3963 class MyJoinableThread
: public wxThread
3966 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
3967 { m_n
= n
; Create(); }
3969 // thread execution starts here
3970 virtual ExitCode
Entry();
3976 wxThread::ExitCode
MyJoinableThread::Entry()
3978 unsigned long res
= 1;
3979 for ( size_t n
= 1; n
< m_n
; n
++ )
3983 // it's a loooong calculation :-)
3987 return (ExitCode
)res
;
3990 class MyDetachedThread
: public wxThread
3993 MyDetachedThread(size_t n
, wxChar ch
)
3997 m_cancelled
= false;
4002 // thread execution starts here
4003 virtual ExitCode
Entry();
4006 virtual void OnExit();
4009 size_t m_n
; // number of characters to write
4010 wxChar m_ch
; // character to write
4012 bool m_cancelled
; // false if we exit normally
4015 wxThread::ExitCode
MyDetachedThread::Entry()
4018 wxCriticalSectionLocker
lock(gs_critsect
);
4019 if ( gs_counter
== (size_t)-1 )
4025 for ( size_t n
= 0; n
< m_n
; n
++ )
4027 if ( TestDestroy() )
4037 wxThread::Sleep(100);
4043 void MyDetachedThread::OnExit()
4045 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
4047 wxCriticalSectionLocker
lock(gs_critsect
);
4048 if ( !--gs_counter
&& !m_cancelled
)
4052 static void TestDetachedThreads()
4054 wxPuts(_T("\n*** Testing detached threads ***"));
4056 static const size_t nThreads
= 3;
4057 MyDetachedThread
*threads
[nThreads
];
4059 for ( n
= 0; n
< nThreads
; n
++ )
4061 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
4064 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
4065 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
4067 for ( n
= 0; n
< nThreads
; n
++ )
4072 // wait until all threads terminate
4075 wxPuts(wxEmptyString
);
4078 static void TestJoinableThreads()
4080 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
4082 // calc 10! in the background
4083 MyJoinableThread
thread(10);
4086 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
4087 (unsigned long)thread
.Wait());
4090 static void TestThreadSuspend()
4092 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
4094 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
4098 // this is for this demo only, in a real life program we'd use another
4099 // condition variable which would be signaled from wxThread::Entry() to
4100 // tell us that the thread really started running - but here just wait a
4101 // bit and hope that it will be enough (the problem is, of course, that
4102 // the thread might still not run when we call Pause() which will result
4104 wxThread::Sleep(300);
4106 for ( size_t n
= 0; n
< 3; n
++ )
4110 wxPuts(_T("\nThread suspended"));
4113 // don't sleep but resume immediately the first time
4114 wxThread::Sleep(300);
4116 wxPuts(_T("Going to resume the thread"));
4121 wxPuts(_T("Waiting until it terminates now"));
4123 // wait until the thread terminates
4126 wxPuts(wxEmptyString
);
4129 static void TestThreadDelete()
4131 // As above, using Sleep() is only for testing here - we must use some
4132 // synchronisation object instead to ensure that the thread is still
4133 // running when we delete it - deleting a detached thread which already
4134 // terminated will lead to a crash!
4136 wxPuts(_T("\n*** Testing thread delete function ***"));
4138 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
4142 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
4144 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
4148 wxThread::Sleep(300);
4152 wxPuts(_T("\nDeleted a running thread."));
4154 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
4158 wxThread::Sleep(300);
4164 wxPuts(_T("\nDeleted a sleeping thread."));
4166 MyJoinableThread
thread3(20);
4171 wxPuts(_T("\nDeleted a joinable thread."));
4173 MyJoinableThread
thread4(2);
4176 wxThread::Sleep(300);
4180 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
4182 wxPuts(wxEmptyString
);
4185 class MyWaitingThread
: public wxThread
4188 MyWaitingThread( wxMutex
*mutex
, wxCondition
*condition
)
4191 m_condition
= condition
;
4196 virtual ExitCode
Entry()
4198 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
4203 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
4207 m_condition
->Wait();
4210 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
4218 wxCondition
*m_condition
;
4221 static void TestThreadConditions()
4224 wxCondition
condition(mutex
);
4226 // otherwise its difficult to understand which log messages pertain to
4228 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
4229 // condition.GetId(), gs_cond.GetId());
4231 // create and launch threads
4232 MyWaitingThread
*threads
[10];
4235 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4237 threads
[n
] = new MyWaitingThread( &mutex
, &condition
);
4240 for ( n
= 0; n
< WXSIZEOF(threads
); n
++ )
4245 // wait until all threads run
4246 wxPuts(_T("Main thread is waiting for the other threads to start"));
4249 size_t nRunning
= 0;
4250 while ( nRunning
< WXSIZEOF(threads
) )
4256 wxPrintf(_T("Main thread: %u already running\n"), nRunning
);
4260 wxPuts(_T("Main thread: all threads started up."));
4263 wxThread::Sleep(500);
4266 // now wake one of them up
4267 wxPrintf(_T("Main thread: about to signal the condition.\n"));
4272 wxThread::Sleep(200);
4274 // wake all the (remaining) threads up, so that they can exit
4275 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
4277 condition
.Broadcast();
4279 // give them time to terminate (dirty!)
4280 wxThread::Sleep(500);
4283 #include "wx/utils.h"
4285 class MyExecThread
: public wxThread
4288 MyExecThread(const wxString
& command
) : wxThread(wxTHREAD_JOINABLE
),
4294 virtual ExitCode
Entry()
4296 return (ExitCode
)wxExecute(m_command
, wxEXEC_SYNC
);
4303 static void TestThreadExec()
4305 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4307 MyExecThread
thread(_T("true"));
4310 wxPrintf(_T("Main program exit code: %ld.\n"),
4311 wxExecute(_T("false"), wxEXEC_SYNC
));
4313 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread
.Wait());
4317 #include "wx/datetime.h"
4319 class MySemaphoreThread
: public wxThread
4322 MySemaphoreThread(int i
, wxSemaphore
*sem
)
4323 : wxThread(wxTHREAD_JOINABLE
),
4330 virtual ExitCode
Entry()
4332 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4333 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4337 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4338 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4342 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4343 wxDateTime::Now().FormatTime().c_str(), m_i
, (long)GetId());
4355 WX_DEFINE_ARRAY_PTR(wxThread
*, ArrayThreads
);
4357 static void TestSemaphore()
4359 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4361 static const int SEM_LIMIT
= 3;
4363 wxSemaphore
sem(SEM_LIMIT
, SEM_LIMIT
);
4364 ArrayThreads threads
;
4366 for ( int i
= 0; i
< 3*SEM_LIMIT
; i
++ )
4368 threads
.Add(new MySemaphoreThread(i
, &sem
));
4369 threads
.Last()->Run();
4372 for ( size_t n
= 0; n
< threads
.GetCount(); n
++ )
4379 #endif // TEST_THREADS
4381 // ----------------------------------------------------------------------------
4383 // ----------------------------------------------------------------------------
4385 #ifdef TEST_SNGLINST
4386 #include "wx/snglinst.h"
4387 #endif // TEST_SNGLINST
4389 int main(int argc
, char **argv
)
4391 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
4393 wxInitializer initializer
;
4396 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
4401 #ifdef TEST_SNGLINST
4402 wxSingleInstanceChecker checker
;
4403 if ( checker
.Create(_T(".wxconsole.lock")) )
4405 if ( checker
.IsAnotherRunning() )
4407 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
4412 // wait some time to give time to launch another instance
4413 wxPrintf(_T("Press \"Enter\" to continue..."));
4416 else // failed to create
4418 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4420 #endif // TEST_SNGLINST
4423 TestCmdLineConvert();
4425 #if wxUSE_CMDLINE_PARSER
4426 static const wxCmdLineEntryDesc cmdLineDesc
[] =
4428 { wxCMD_LINE_SWITCH
, _T("h"), _T("help"), _T("show this help message"),
4429 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
4430 { wxCMD_LINE_SWITCH
, _T("v"), _T("verbose"), _T("be verbose") },
4431 { wxCMD_LINE_SWITCH
, _T("q"), _T("quiet"), _T("be quiet") },
4433 { wxCMD_LINE_OPTION
, _T("o"), _T("output"), _T("output file") },
4434 { wxCMD_LINE_OPTION
, _T("i"), _T("input"), _T("input dir") },
4435 { wxCMD_LINE_OPTION
, _T("s"), _T("size"), _T("output block size"),
4436 wxCMD_LINE_VAL_NUMBER
},
4437 { wxCMD_LINE_OPTION
, _T("d"), _T("date"), _T("output file date"),
4438 wxCMD_LINE_VAL_DATE
},
4440 { wxCMD_LINE_PARAM
, NULL
, NULL
, _T("input file"),
4441 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
4447 wxChar
**wargv
= new wxChar
*[argc
+ 1];
4452 for (n
= 0; n
< argc
; n
++ )
4454 wxMB2WXbuf warg
= wxConvertMB2WX(argv
[n
]);
4455 wargv
[n
] = wxStrdup(warg
);
4462 #endif // wxUSE_UNICODE
4464 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
4468 for ( int n
= 0; n
< argc
; n
++ )
4473 #endif // wxUSE_UNICODE
4475 parser
.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
4476 wxCMD_LINE_VAL_STRING
,
4477 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
4479 switch ( parser
.Parse() )
4482 wxLogMessage(_T("Help was given, terminating."));
4486 ShowCmdLine(parser
);
4490 wxLogMessage(_T("Syntax error detected, aborting."));
4493 #endif // wxUSE_CMDLINE_PARSER
4495 #endif // TEST_CMDLINE
4505 #ifdef TEST_DLLLOADER
4507 #endif // TEST_DLLLOADER
4511 #endif // TEST_ENVIRON
4515 #endif // TEST_EXECUTE
4517 #ifdef TEST_FILECONF
4519 #endif // TEST_FILECONF
4528 #endif // TEST_LOCALE
4531 wxPuts(_T("*** Testing wxLog ***"));
4534 for ( size_t n
= 0; n
< 8000; n
++ )
4536 s
<< (wxChar
)(_T('A') + (n
% 26));
4539 wxLogWarning(_T("The length of the string is %lu"),
4540 (unsigned long)s
.length());
4543 msg
.Printf(_T("A very very long message: '%s', the end!\n"), s
.c_str());
4545 // this one shouldn't be truncated
4548 // but this one will because log functions use fixed size buffer
4549 // (note that it doesn't need '\n' at the end neither - will be added
4551 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s
.c_str());
4560 #ifdef TEST_FILENAME
4561 TestFileNameConstruction();
4562 TestFileNameMakeRelative();
4563 TestFileNameMakeAbsolute();
4564 TestFileNameSplit();
4567 TestFileNameDirManip();
4568 TestFileNameComparison();
4569 TestFileNameOperations();
4570 #endif // TEST_FILENAME
4572 #ifdef TEST_FILETIME
4577 #endif // TEST_FILETIME
4580 wxLog::AddTraceMask(FTP_TRACE_MASK
);
4581 if ( TestFtpConnect() )
4591 #if TEST_INTERACTIVE
4592 TestFtpInteractive();
4595 //else: connecting to the FTP server failed
4604 #endif // TEST_HASHMAP
4608 #endif // TEST_HASHSET
4611 wxLog::AddTraceMask(_T("mime"));
4615 TestMimeAssociate();
4620 #ifdef TEST_INFO_FUNCTIONS
4625 #if TEST_INTERACTIVE
4629 #endif // TEST_INFO_FUNCTIONS
4631 #ifdef TEST_PATHLIST
4633 #endif // TEST_PATHLIST
4641 #endif // TEST_PRINTF
4648 #endif // TEST_REGCONF
4650 #if defined TEST_REGEX && TEST_INTERACTIVE
4651 TestRegExInteractive();
4652 #endif // defined TEST_REGEX && TEST_INTERACTIVE
4654 #ifdef TEST_REGISTRY
4656 TestRegistryAssociation();
4657 #endif // TEST_REGISTRY
4662 #endif // TEST_SOCKETS
4669 #endif // TEST_STREAMS
4671 #ifdef TEST_TEXTSTREAM
4672 TestTextInputStream();
4673 #endif // TEST_TEXTSTREAM
4676 int nCPUs
= wxThread::GetCPUCount();
4677 wxPrintf(_T("This system has %d CPUs\n"), nCPUs
);
4679 wxThread::SetConcurrency(nCPUs
);
4681 TestJoinableThreads();
4684 TestJoinableThreads();
4685 TestDetachedThreads();
4686 TestThreadSuspend();
4688 TestThreadConditions();
4692 #endif // TEST_THREADS
4696 #endif // TEST_TIMER
4698 #ifdef TEST_DATETIME
4710 TestTimeArithmetics();
4712 TestTimeSpanFormat();
4718 #if TEST_INTERACTIVE
4719 TestDateTimeInteractive();
4721 #endif // TEST_DATETIME
4723 #ifdef TEST_SCOPEGUARD
4727 #ifdef TEST_STDPATHS
4728 TestStandardPaths();
4732 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
4734 #endif // TEST_USLEEP
4739 #endif // TEST_VCARD
4743 #endif // TEST_VOLUME
4747 TestEncodingConverter();
4748 #endif // TEST_WCHAR
4751 TestZipStreamRead();
4752 TestZipFileSystem();