]> git.saurik.com Git - wxWidgets.git/blame - samples/console/console.cpp
removed src/gtk/eggtrayicon.h
[wxWidgets.git] / samples / console / console.cpp
CommitLineData
37667812
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: samples/console/console.cpp
be5a51fb 3// Purpose: a sample console (as opposed to GUI) progam using wxWidgets
37667812
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 04.10.99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
e87271f3
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e84010cf 20#include "wx/defs.h"
b11a23f3 21
37667812
VZ
22#include <stdio.h>
23
e84010cf
GD
24#include "wx/string.h"
25#include "wx/file.h"
26#include "wx/app.h"
e046e5f1 27#include "wx/log.h"
e87271f3 28
d31b7b68
VZ
29// without this pragma, the stupid compiler precompiles #defines below so that
30// changing them doesn't "take place" later!
31#ifdef __VISUALC__
32 #pragma hdrstop
33#endif
34
e87271f3
VZ
35// ----------------------------------------------------------------------------
36// conditional compilation
37// ----------------------------------------------------------------------------
38
daa2c7d9
VZ
39/*
40 A note about all these conditional compilation macros: this file is used
be5a51fb 41 both as a test suite for various non-GUI wxWidgets classes and as a
daa2c7d9
VZ
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.
45 */
46
e9d2bb6f
DS
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.
49#define TEST_ALL 0
50
51
52#if TEST_ALL
31f6de22
VZ
53 #define TEST_CMDLINE
54 #define TEST_DATETIME
55 #define TEST_DIR
56 #define TEST_DLLLOADER
57 #define TEST_ENVIRON
58 #define TEST_EXECUTE
59 #define TEST_FILE
60 #define TEST_FILECONF
61 #define TEST_FILENAME
62 #define TEST_FILETIME
8d4dc98f 63 // #define TEST_FTP --FIXME! (RN)
0508ba2a 64 #define TEST_HASHMAP
8142d704 65 #define TEST_HASHSET
31f6de22
VZ
66 #define TEST_INFO_FUNCTIONS
67 #define TEST_LIST
68 #define TEST_LOCALE
69 #define TEST_LOG
31f6de22
VZ
70 #define TEST_MIME
71 #define TEST_PATHLIST
8d5eff60 72 #define TEST_ODBC
7aeebdcd 73 #define TEST_PRINTF
31f6de22
VZ
74 #define TEST_REGCONF
75 #define TEST_REGEX
76 #define TEST_REGISTRY
24c8053b 77 #define TEST_SCOPEGUARD
31f6de22 78 #define TEST_SNGLINST
8d4dc98f 79// #define TEST_SOCKETS --FIXME! (RN)
af33b199 80 #define TEST_STDPATHS
31f6de22 81 #define TEST_STREAMS
39937656 82 #define TEST_TEXTSTREAM
31f6de22
VZ
83 #define TEST_THREADS
84 #define TEST_TIMER
85 // #define TEST_VCARD -- don't enable this (VZ)
8d4dc98f 86// #define TEST_VOLUME --FIXME! (RN)
31f6de22
VZ
87 #define TEST_WCHAR
88 #define TEST_ZIP
e9d2bb6f 89#else // #if TEST_ALL
af33b199 90 #define TEST_STDPATHS
31f6de22 91#endif
f6bcfd97 92
daa2c7d9
VZ
93// some tests are interactive, define this to run them
94#ifdef TEST_INTERACTIVE
95 #undef TEST_INTERACTIVE
96
e9d2bb6f 97 #define TEST_INTERACTIVE 1
daa2c7d9 98#else
e9d2bb6f 99 #define TEST_INTERACTIVE 0
daa2c7d9 100#endif
58b24a56 101
f6bcfd97
BP
102// ----------------------------------------------------------------------------
103// test class for container objects
104// ----------------------------------------------------------------------------
105
cf1014a2 106#if defined(TEST_LIST)
f6bcfd97
BP
107
108class Bar // Foo is already taken in the hash test
109{
110public:
111 Bar(const wxString& name) : m_name(name) { ms_bars++; }
3dc01741 112 Bar(const Bar& bar) : m_name(bar.m_name) { ms_bars++; }
f6bcfd97
BP
113 ~Bar() { ms_bars--; }
114
115 static size_t GetNumber() { return ms_bars; }
116
456ae26d 117 const wxChar *GetName() const { return m_name; }
f6bcfd97
BP
118
119private:
120 wxString m_name;
121
122 static size_t ms_bars;
123};
124
125size_t Bar::ms_bars = 0;
126
cf1014a2 127#endif // defined(TEST_LIST)
e87271f3
VZ
128
129// ============================================================================
130// implementation
131// ============================================================================
132
8e907a13
VZ
133// ----------------------------------------------------------------------------
134// helper functions
135// ----------------------------------------------------------------------------
136
1cd53e88 137#if defined(TEST_SOCKETS)
8e907a13
VZ
138
139// replace TABs with \t and CRs with \n
140static wxString MakePrintable(const wxChar *s)
141{
142 wxString str(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"));
146
147 return str;
148}
149
150#endif // MakePrintable() is used
151
d34bce84
VZ
152// ----------------------------------------------------------------------------
153// wxCmdLineParser
154// ----------------------------------------------------------------------------
155
d31b7b68
VZ
156#ifdef TEST_CMDLINE
157
e84010cf
GD
158#include "wx/cmdline.h"
159#include "wx/datetime.h"
d34bce84 160
31f6de22
VZ
161#if wxUSE_CMDLINE_PARSER
162
d34bce84
VZ
163static void ShowCmdLine(const wxCmdLineParser& parser)
164{
456ae26d 165 wxString s = _T("Input files: ");
d34bce84
VZ
166
167 size_t count = parser.GetParamCount();
168 for ( size_t param = 0; param < count; param++ )
169 {
170 s << parser.GetParam(param) << ' ';
171 }
172
173 s << '\n'
456ae26d
VZ
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';
d34bce84
VZ
176
177 wxString strVal;
178 long lVal;
179 wxDateTime dt;
456ae26d
VZ
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';
d34bce84
VZ
190
191 wxLogMessage(s);
192}
193
31f6de22
VZ
194#endif // wxUSE_CMDLINE_PARSER
195
196static void TestCmdLineConvert()
197{
456ae26d 198 static const wxChar *cmdlines[] =
31f6de22 199 {
456ae26d
VZ
200 _T("arg1 arg2"),
201 _T("-a \"-bstring 1\" -c\"string 2\" \"string 3\""),
202 _T("literal \\\" and \"\""),
31f6de22
VZ
203 };
204
205 for ( size_t n = 0; n < WXSIZEOF(cmdlines); n++ )
206 {
456ae26d
VZ
207 const wxChar *cmdline = cmdlines[n];
208 wxPrintf(_T("Parsing: %s\n"), cmdline);
31f6de22
VZ
209 wxArrayString args = wxCmdLineParser::ConvertStringToArgs(cmdline);
210
211 size_t count = args.GetCount();
456ae26d 212 wxPrintf(_T("\targc = %u\n"), count);
31f6de22
VZ
213 for ( size_t arg = 0; arg < count; arg++ )
214 {
456ae26d 215 wxPrintf(_T("\targv[%u] = %s\n"), arg, args[arg].c_str());
31f6de22
VZ
216 }
217 }
218}
219
d34bce84
VZ
220#endif // TEST_CMDLINE
221
1944c6bd
VZ
222// ----------------------------------------------------------------------------
223// wxDir
224// ----------------------------------------------------------------------------
225
226#ifdef TEST_DIR
227
e84010cf 228#include "wx/dir.h"
1944c6bd 229
35332784
VZ
230#ifdef __UNIX__
231 static const wxChar *ROOTDIR = _T("/");
2f0c19d0 232 static const wxChar *TESTDIR = _T("/usr/local/share");
35332784
VZ
233#elif defined(__WXMSW__)
234 static const wxChar *ROOTDIR = _T("c:\\");
235 static const wxChar *TESTDIR = _T("d:\\");
236#else
237 #error "don't know where the root directory is"
238#endif
239
1944c6bd
VZ
240static void TestDirEnumHelper(wxDir& dir,
241 int flags = wxDIR_DEFAULT,
242 const wxString& filespec = wxEmptyString)
243{
244 wxString filename;
245
246 if ( !dir.IsOpened() )
247 return;
248
249 bool cont = dir.GetFirst(&filename, filespec, flags);
250 while ( cont )
251 {
456ae26d 252 wxPrintf(_T("\t%s\n"), filename.c_str());
1944c6bd
VZ
253
254 cont = dir.GetNext(&filename);
255 }
256
e9d2bb6f 257 wxPuts(wxEmptyString);
1944c6bd
VZ
258}
259
260static void TestDirEnum()
261{
456ae26d 262 wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
35332784 263
149147e1 264 wxString cwd = wxGetCwd();
9475670f 265 if ( !wxDir::Exists(cwd) )
149147e1 266 {
456ae26d 267 wxPrintf(_T("ERROR: current directory '%s' doesn't exist?\n"), cwd.c_str());
149147e1
VZ
268 return;
269 }
270
ee3ef281 271 wxDir dir(cwd);
149147e1
VZ
272 if ( !dir.IsOpened() )
273 {
456ae26d 274 wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd.c_str());
149147e1
VZ
275 return;
276 }
1944c6bd 277
456ae26d 278 wxPuts(_T("Enumerating everything in current directory:"));
1944c6bd
VZ
279 TestDirEnumHelper(dir);
280
456ae26d 281 wxPuts(_T("Enumerating really everything in current directory:"));
1944c6bd
VZ
282 TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
283
456ae26d 284 wxPuts(_T("Enumerating object files in current directory:"));
f2cb8a17 285 TestDirEnumHelper(dir, wxDIR_DEFAULT, _T("*.o*"));
1944c6bd 286
456ae26d 287 wxPuts(_T("Enumerating directories in current directory:"));
1944c6bd
VZ
288 TestDirEnumHelper(dir, wxDIR_DIRS);
289
456ae26d 290 wxPuts(_T("Enumerating files in current directory:"));
1944c6bd
VZ
291 TestDirEnumHelper(dir, wxDIR_FILES);
292
456ae26d 293 wxPuts(_T("Enumerating files including hidden in current directory:"));
1944c6bd
VZ
294 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
295
35332784 296 dir.Open(ROOTDIR);
1944c6bd 297
456ae26d 298 wxPuts(_T("Enumerating everything in root directory:"));
1944c6bd
VZ
299 TestDirEnumHelper(dir, wxDIR_DEFAULT);
300
456ae26d 301 wxPuts(_T("Enumerating directories in root directory:"));
1944c6bd
VZ
302 TestDirEnumHelper(dir, wxDIR_DIRS);
303
456ae26d 304 wxPuts(_T("Enumerating files in root directory:"));
1944c6bd
VZ
305 TestDirEnumHelper(dir, wxDIR_FILES);
306
456ae26d 307 wxPuts(_T("Enumerating files including hidden in root directory:"));
1944c6bd
VZ
308 TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
309
456ae26d 310 wxPuts(_T("Enumerating files in non existing directory:"));
f2cb8a17 311 wxDir dirNo(_T("nosuchdir"));
1944c6bd
VZ
312 TestDirEnumHelper(dirNo);
313}
314
35332784
VZ
315class DirPrintTraverser : public wxDirTraverser
316{
317public:
e9d2bb6f 318 virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename))
35332784
VZ
319 {
320 return wxDIR_CONTINUE;
321 }
322
323 virtual wxDirTraverseResult OnDir(const wxString& dirname)
324 {
325 wxString path, name, ext;
326 wxSplitPath(dirname, &path, &name, &ext);
327
328 if ( !ext.empty() )
329 name << _T('.') << ext;
330
331 wxString indent;
332 for ( const wxChar *p = path.c_str(); *p; p++ )
333 {
334 if ( wxIsPathSeparator(*p) )
335 indent += _T(" ");
336 }
337
456ae26d 338 wxPrintf(_T("%s%s\n"), indent.c_str(), name.c_str());
35332784
VZ
339
340 return wxDIR_CONTINUE;
341 }
342};
343
344static void TestDirTraverse()
345{
456ae26d 346 wxPuts(_T("*** Testing wxDir::Traverse() ***"));
35332784
VZ
347
348 // enum all files
349 wxArrayString files;
350 size_t n = wxDir::GetAllFiles(TESTDIR, &files);
456ae26d 351 wxPrintf(_T("There are %u files under '%s'\n"), n, TESTDIR);
35332784
VZ
352 if ( n > 1 )
353 {
456ae26d
VZ
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());
35332784
VZ
356 }
357
358 // enum again with custom traverser
2f0c19d0 359 wxPuts(_T("Now enumerating directories:"));
35332784
VZ
360 wxDir dir(TESTDIR);
361 DirPrintTraverser traverser;
e9d2bb6f 362 dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
35332784
VZ
363}
364
149147e1
VZ
365static void TestDirExists()
366{
367 wxPuts(_T("*** Testing wxDir::Exists() ***"));
368
456ae26d 369 static const wxChar *dirnames[] =
149147e1
VZ
370 {
371 _T("."),
372#if defined(__WXMSW__)
373 _T("c:"),
374 _T("c:\\"),
375 _T("\\\\share\\file"),
376 _T("c:\\dos"),
377 _T("c:\\dos\\"),
378 _T("c:\\dos\\\\"),
379 _T("c:\\autoexec.bat"),
380#elif defined(__UNIX__)
381 _T("/"),
382 _T("//"),
383 _T("/usr/bin"),
384 _T("/usr//bin"),
385 _T("/usr///bin"),
386#endif
387 };
388
389 for ( size_t n = 0; n < WXSIZEOF(dirnames); n++ )
390 {
456ae26d
VZ
391 wxPrintf(_T("%-40s: %s\n"),
392 dirnames[n],
393 wxDir::Exists(dirnames[n]) ? _T("exists")
394 : _T("doesn't exist"));
149147e1
VZ
395 }
396}
397
1944c6bd
VZ
398#endif // TEST_DIR
399
f6bcfd97
BP
400// ----------------------------------------------------------------------------
401// wxDllLoader
402// ----------------------------------------------------------------------------
403
404#ifdef TEST_DLLLOADER
405
e84010cf 406#include "wx/dynlib.h"
f6bcfd97
BP
407
408static void TestDllLoad()
409{
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");
417#else
418 #error "don't know how to test wxDllLoader on this platform"
419#endif
420
456ae26d 421 wxPuts(_T("*** testing wxDllLoader ***\n"));
f6bcfd97 422
456ae26d
VZ
423 wxDynamicLibrary lib(LIB_NAME);
424 if ( !lib.IsLoaded() )
f6bcfd97
BP
425 {
426 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME);
427 }
428 else
429 {
456ae26d
VZ
430 typedef int (*wxStrlenType)(const char *);
431 wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
f6bcfd97
BP
432 if ( !pfnStrlen )
433 {
434 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
435 FUNC_NAME, LIB_NAME);
436 }
437 else
438 {
439 if ( pfnStrlen("foo") != 3 )
440 {
456ae26d 441 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
f6bcfd97
BP
442 }
443 else
444 {
456ae26d 445 wxPuts(_T("... ok"));
f6bcfd97
BP
446 }
447 }
f6bcfd97
BP
448 }
449}
450
451#endif // TEST_DLLLOADER
452
8fd0d89b
VZ
453// ----------------------------------------------------------------------------
454// wxGet/SetEnv
455// ----------------------------------------------------------------------------
456
457#ifdef TEST_ENVIRON
458
e84010cf 459#include "wx/utils.h"
8fd0d89b 460
308978f6
VZ
461static wxString MyGetEnv(const wxString& var)
462{
463 wxString val;
464 if ( !wxGetEnv(var, &val) )
465 val = _T("<empty>");
466 else
467 val = wxString(_T('\'')) + val + _T('\'');
468
469 return val;
470}
471
8fd0d89b
VZ
472static void TestEnvironment()
473{
474 const wxChar *var = _T("wxTestVar");
475
456ae26d 476 wxPuts(_T("*** testing environment access functions ***"));
8fd0d89b 477
456ae26d 478 wxPrintf(_T("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
8fd0d89b 479 wxSetEnv(var, _T("value for wxTestVar"));
456ae26d 480 wxPrintf(_T("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
8fd0d89b 481 wxSetEnv(var, _T("another value"));
456ae26d 482 wxPrintf(_T("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
8fd0d89b 483 wxUnsetEnv(var);
456ae26d
VZ
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());
8fd0d89b
VZ
486}
487
488#endif // TEST_ENVIRON
489
d93c719a
VZ
490// ----------------------------------------------------------------------------
491// wxExecute
492// ----------------------------------------------------------------------------
493
494#ifdef TEST_EXECUTE
495
e84010cf 496#include "wx/utils.h"
d93c719a
VZ
497
498static void TestExecute()
499{
456ae26d 500 wxPuts(_T("*** testing wxExecute ***"));
d93c719a
VZ
501
502#ifdef __UNIX__
a1f79c1e 503 #define COMMAND "cat -n ../../Makefile" // "echo hi"
2c8e4738 504 #define SHELL_COMMAND "echo hi from shell"
a1f79c1e 505 #define REDIRECT_COMMAND COMMAND // "date"
d93c719a 506#elif defined(__WXMSW__)
50ded68d 507 #define COMMAND "command.com /c echo hi"
2c8e4738
VZ
508 #define SHELL_COMMAND "echo hi"
509 #define REDIRECT_COMMAND COMMAND
d93c719a
VZ
510#else
511 #error "no command to exec"
512#endif // OS
513
456ae26d 514 wxPrintf(_T("Testing wxShell: "));
2c8e4738 515 fflush(stdout);
f2cb8a17 516 if ( wxShell(_T(SHELL_COMMAND)) )
456ae26d 517 wxPuts(_T("Ok."));
d93c719a 518 else
456ae26d 519 wxPuts(_T("ERROR."));
2c8e4738 520
456ae26d 521 wxPrintf(_T("Testing wxExecute: "));
2c8e4738 522 fflush(stdout);
f2cb8a17 523 if ( wxExecute(_T(COMMAND), true /* sync */) == 0 )
456ae26d 524 wxPuts(_T("Ok."));
2c8e4738 525 else
456ae26d 526 wxPuts(_T("ERROR."));
2c8e4738
VZ
527
528#if 0 // no, it doesn't work (yet?)
456ae26d 529 wxPrintf(_T("Testing async wxExecute: "));
2c8e4738
VZ
530 fflush(stdout);
531 if ( wxExecute(COMMAND) != 0 )
456ae26d 532 wxPuts(_T("Ok (command launched)."));
2c8e4738 533 else
456ae26d 534 wxPuts(_T("ERROR."));
2c8e4738
VZ
535#endif // 0
536
456ae26d 537 wxPrintf(_T("Testing wxExecute with redirection:\n"));
2c8e4738 538 wxArrayString output;
f2cb8a17 539 if ( wxExecute(_T(REDIRECT_COMMAND), output) != 0 )
2c8e4738 540 {
456ae26d 541 wxPuts(_T("ERROR."));
2c8e4738
VZ
542 }
543 else
544 {
545 size_t count = output.GetCount();
546 for ( size_t n = 0; n < count; n++ )
547 {
456ae26d 548 wxPrintf(_T("\t%s\n"), output[n].c_str());
2c8e4738
VZ
549 }
550
456ae26d 551 wxPuts(_T("Ok."));
2c8e4738 552 }
d93c719a
VZ
553}
554
555#endif // TEST_EXECUTE
556
f6bcfd97
BP
557// ----------------------------------------------------------------------------
558// file
559// ----------------------------------------------------------------------------
560
561#ifdef TEST_FILE
562
e84010cf
GD
563#include "wx/file.h"
564#include "wx/ffile.h"
565#include "wx/textfile.h"
f6bcfd97
BP
566
567static void TestFileRead()
568{
456ae26d 569 wxPuts(_T("*** wxFile read test ***"));
f6bcfd97
BP
570
571 wxFile file(_T("testdata.fc"));
572 if ( file.IsOpened() )
573 {
456ae26d 574 wxPrintf(_T("File length: %lu\n"), file.Length());
f6bcfd97 575
456ae26d 576 wxPuts(_T("File dump:\n----------"));
f6bcfd97 577
3ca6a5f0 578 static const off_t len = 1024;
456ae26d 579 wxChar buf[len];
f6bcfd97
BP
580 for ( ;; )
581 {
582 off_t nRead = file.Read(buf, len);
583 if ( nRead == wxInvalidOffset )
584 {
456ae26d 585 wxPrintf(_T("Failed to read the file."));
f6bcfd97
BP
586 break;
587 }
588
589 fwrite(buf, nRead, 1, stdout);
590
591 if ( nRead < len )
592 break;
593 }
594
456ae26d 595 wxPuts(_T("----------"));
f6bcfd97
BP
596 }
597 else
598 {
456ae26d 599 wxPrintf(_T("ERROR: can't open test file.\n"));
f6bcfd97
BP
600 }
601
e9d2bb6f 602 wxPuts(wxEmptyString);
f6bcfd97
BP
603}
604
605static void TestTextFileRead()
606{
456ae26d 607 wxPuts(_T("*** wxTextFile read test ***"));
f6bcfd97
BP
608
609 wxTextFile file(_T("testdata.fc"));
610 if ( file.Open() )
611 {
456ae26d
VZ
612 wxPrintf(_T("Number of lines: %u\n"), file.GetLineCount());
613 wxPrintf(_T("Last line: '%s'\n"), file.GetLastLine().c_str());
3ca6a5f0
BP
614
615 wxString s;
616
456ae26d 617 wxPuts(_T("\nDumping the entire file:"));
3ca6a5f0
BP
618 for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
619 {
456ae26d 620 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
3ca6a5f0 621 }
456ae26d 622 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
3ca6a5f0 623
456ae26d 624 wxPuts(_T("\nAnd now backwards:"));
3ca6a5f0
BP
625 for ( s = file.GetLastLine();
626 file.GetCurrentLine() != 0;
627 s = file.GetPrevLine() )
628 {
456ae26d 629 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
3ca6a5f0 630 }
456ae26d 631 wxPrintf(_T("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
f6bcfd97
BP
632 }
633 else
634 {
456ae26d 635 wxPrintf(_T("ERROR: can't open '%s'\n"), file.GetName());
f6bcfd97
BP
636 }
637
e9d2bb6f 638 wxPuts(wxEmptyString);
f6bcfd97
BP
639}
640
a339970a
VZ
641static void TestFileCopy()
642{
456ae26d 643 wxPuts(_T("*** Testing wxCopyFile ***"));
a339970a
VZ
644
645 static const wxChar *filename1 = _T("testdata.fc");
646 static const wxChar *filename2 = _T("test2");
647 if ( !wxCopyFile(filename1, filename2) )
648 {
456ae26d 649 wxPuts(_T("ERROR: failed to copy file"));
a339970a
VZ
650 }
651 else
652 {
f2cb8a17
JS
653 wxFFile f1(filename1, _T("rb")),
654 f2(filename2, _T("rb"));
a339970a
VZ
655
656 if ( !f1.IsOpened() || !f2.IsOpened() )
657 {
456ae26d 658 wxPuts(_T("ERROR: failed to open file(s)"));
a339970a
VZ
659 }
660 else
661 {
662 wxString s1, s2;
663 if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
664 {
456ae26d 665 wxPuts(_T("ERROR: failed to read file(s)"));
a339970a
VZ
666 }
667 else
668 {
669 if ( (s1.length() != s2.length()) ||
670 (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
671 {
456ae26d 672 wxPuts(_T("ERROR: copy error!"));
a339970a
VZ
673 }
674 else
675 {
456ae26d 676 wxPuts(_T("File was copied ok."));
a339970a
VZ
677 }
678 }
679 }
680 }
681
682 if ( !wxRemoveFile(filename2) )
683 {
456ae26d 684 wxPuts(_T("ERROR: failed to remove the file"));
a339970a
VZ
685 }
686
e9d2bb6f 687 wxPuts(wxEmptyString);
a339970a
VZ
688}
689
f6bcfd97
BP
690#endif // TEST_FILE
691
ee6e1b1d
VZ
692// ----------------------------------------------------------------------------
693// wxFileConfig
694// ----------------------------------------------------------------------------
695
696#ifdef TEST_FILECONF
697
e84010cf
GD
698#include "wx/confbase.h"
699#include "wx/fileconf.h"
ee6e1b1d
VZ
700
701static const struct FileConfTestData
702{
703 const wxChar *name; // value name
704 const wxChar *value; // the value from the file
705} fcTestData[] =
706{
707 { _T("value1"), _T("one") },
708 { _T("value2"), _T("two") },
709 { _T("novalue"), _T("default") },
710};
711
712static void TestFileConfRead()
713{
456ae26d 714 wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
ee6e1b1d
VZ
715
716 wxFileConfig fileconf(_T("test"), wxEmptyString,
717 _T("testdata.fc"), wxEmptyString,
718 wxCONFIG_USE_RELATIVE_PATH);
719
720 // test simple reading
456ae26d 721 wxPuts(_T("\nReading config file:"));
ee6e1b1d
VZ
722 wxString defValue(_T("default")), value;
723 for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
724 {
725 const FileConfTestData& data = fcTestData[n];
726 value = fileconf.Read(data.name, defValue);
456ae26d 727 wxPrintf(_T("\t%s = %s "), data.name, value.c_str());
ee6e1b1d
VZ
728 if ( value == data.value )
729 {
456ae26d 730 wxPuts(_T("(ok)"));
ee6e1b1d
VZ
731 }
732 else
733 {
456ae26d 734 wxPrintf(_T("(ERROR: should be %s)\n"), data.value);
ee6e1b1d
VZ
735 }
736 }
737
738 // test enumerating the entries
456ae26d 739 wxPuts(_T("\nEnumerating all root entries:"));
ee6e1b1d
VZ
740 long dummy;
741 wxString name;
742 bool cont = fileconf.GetFirstEntry(name, dummy);
743 while ( cont )
744 {
456ae26d 745 wxPrintf(_T("\t%s = %s\n"),
ee6e1b1d
VZ
746 name.c_str(),
747 fileconf.Read(name.c_str(), _T("ERROR")).c_str());
748
749 cont = fileconf.GetNextEntry(name, dummy);
750 }
7e0777da
VZ
751
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"));
ee6e1b1d
VZ
757}
758
759#endif // TEST_FILECONF
760
844f90fb
VZ
761// ----------------------------------------------------------------------------
762// wxFileName
763// ----------------------------------------------------------------------------
764
765#ifdef TEST_FILENAME
766
e84010cf 767#include "wx/filename.h"
844f90fb 768
e9d2bb6f 769#if 0
5bc1deeb 770static void DumpFileName(const wxChar *desc, const wxFileName& fn)
81f25632 771{
5bc1deeb
VZ
772 wxPuts(desc);
773
81f25632
VZ
774 wxString full = fn.GetFullPath();
775
776 wxString vol, path, name, ext;
777 wxFileName::SplitPath(full, &vol, &path, &name, &ext);
778
a5b7374f 779 wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
81f25632 780 full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
a5b7374f
VZ
781
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());
785
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());
9cb47ea2
VZ
793
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++ )
798 {
799 wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str());
800 }
81f25632 801}
e9d2bb6f 802#endif
81f25632 803
ade35f11
VZ
804static void TestFileNameTemp()
805{
456ae26d 806 wxPuts(_T("*** testing wxFileName temp file creation ***"));
ade35f11 807
456ae26d 808 static const wxChar *tmpprefixes[] =
ade35f11 809 {
456ae26d
VZ
810 _T(""),
811 _T("foo"),
812 _T(".."),
813 _T("../bar"),
a2fa5040 814#ifdef __UNIX__
456ae26d
VZ
815 _T("/tmp/foo"),
816 _T("/tmp/foo/bar"), // this one must be an error
a2fa5040 817#endif // __UNIX__
ade35f11
VZ
818 };
819
820 for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
821 {
822 wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
2db991f4
VZ
823 if ( path.empty() )
824 {
825 // "error" is not in upper case because it may be ok
456ae26d 826 wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
2db991f4
VZ
827 }
828 else
ade35f11 829 {
456ae26d 830 wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
ade35f11
VZ
831 tmpprefixes[n], path.c_str());
832
833 if ( !wxRemoveFile(path) )
834 {
456ae26d
VZ
835 wxLogWarning(_T("Failed to remove temp file '%s'"),
836 path.c_str());
ade35f11
VZ
837 }
838 }
839 }
840}
841
f7d886af
VZ
842static void TestFileNameMakeRelative()
843{
456ae26d 844 wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
f7d886af
VZ
845
846 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
847 {
848 const FileNameInfo& fni = filenames[n];
849
850 wxFileName fn(fni.fullname, fni.format);
851
852 // choose the base dir of the same format
853 wxString base;
854 switch ( fni.format )
855 {
856 case wxPATH_UNIX:
f2cb8a17 857 base = _T("/usr/bin/");
f7d886af
VZ
858 break;
859
860 case wxPATH_DOS:
f2cb8a17 861 base = _T("c:\\");
f7d886af
VZ
862 break;
863
864 case wxPATH_MAC:
865 case wxPATH_VMS:
866 // TODO: I don't know how this is supposed to work there
867 continue;
daa2c7d9
VZ
868
869 case wxPATH_NATIVE: // make gcc happy
870 default:
f2cb8a17 871 wxFAIL_MSG( _T("unexpected path format") );
f7d886af
VZ
872 }
873
456ae26d 874 wxPrintf(_T("'%s' relative to '%s': "),
f7d886af
VZ
875 fn.GetFullPath(fni.format).c_str(), base.c_str());
876
877 if ( !fn.MakeRelativeTo(base, fni.format) )
878 {
456ae26d 879 wxPuts(_T("unchanged"));
f7d886af
VZ
880 }
881 else
882 {
456ae26d 883 wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
f7d886af
VZ
884 }
885 }
886}
887
e7266247
VS
888static void TestFileNameMakeAbsolute()
889{
890 wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
891
892 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
893 {
894 const FileNameInfo& fni = filenames[n];
895 wxFileName fn(fni.fullname, fni.format);
2ab25aca 896
e7266247
VS
897 wxPrintf(_T("'%s' absolutized: "),
898 fn.GetFullPath(fni.format).c_str());
899 fn.MakeAbsolute();
900 wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
901 }
902
e9d2bb6f 903 wxPuts(wxEmptyString);
e7266247
VS
904}
905
0aa29b6b
VZ
906static void TestFileNameDirManip()
907{
908 // TODO: test AppendDir(), RemoveDir(), ...
909}
910
844f90fb
VZ
911static void TestFileNameComparison()
912{
913 // TODO!
914}
915
916static void TestFileNameOperations()
917{
918 // TODO!
919}
920
921static void TestFileNameCwd()
922{
923 // TODO!
924}
925
926#endif // TEST_FILENAME
927
d56e2b97
VZ
928// ----------------------------------------------------------------------------
929// wxFileName time functions
930// ----------------------------------------------------------------------------
931
932#ifdef TEST_FILETIME
933
934#include <wx/filename.h>
935#include <wx/datetime.h>
936
937static void TestFileGetTimes()
938{
939 wxFileName fn(_T("testdata.fc"));
940
6dbb903b
VZ
941 wxDateTime dtAccess, dtMod, dtCreate;
942 if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
d56e2b97
VZ
943 {
944 wxPrintf(_T("ERROR: GetTimes() failed.\n"));
945 }
946 else
947 {
948 static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S");
949
950 wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str());
6dbb903b
VZ
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());
d56e2b97
VZ
954 }
955}
956
e9d2bb6f 957#if 0
d56e2b97
VZ
958static void TestFileSetTimes()
959{
960 wxFileName fn(_T("testdata.fc"));
961
d56e2b97
VZ
962 if ( !fn.Touch() )
963 {
964 wxPrintf(_T("ERROR: Touch() failed.\n"));
965 }
966}
e9d2bb6f 967#endif
d56e2b97
VZ
968
969#endif // TEST_FILETIME
970
0508ba2a
MB
971// ----------------------------------------------------------------------------
972// wxHashMap
973// ----------------------------------------------------------------------------
974
975#ifdef TEST_HASHMAP
976
977#include "wx/hashmap.h"
978
979// test compilation of basic map types
980WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash, wxPointerEqual, myPtrHashMap );
981WX_DECLARE_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual, myLongHashMap );
982WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash, wxIntegerEqual,
983 myUnsignedHashMap );
984WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash, wxIntegerEqual,
985 myTestHashMap1 );
986WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash, wxIntegerEqual,
987 myTestHashMap2 );
988WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash, wxIntegerEqual,
989 myTestHashMap3 );
990WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash, wxIntegerEqual,
991 myTestHashMap4 );
60ce696e
VZ
992
993// same as:
994// WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
995// myStringHashMap );
996WX_DECLARE_STRING_HASH_MAP(wxString, myStringHashMap);
0508ba2a
MB
997
998typedef myStringHashMap::iterator Itor;
999
1000static void TestHashMap()
1001{
456ae26d 1002 wxPuts(_T("*** Testing wxHashMap ***\n"));
0508ba2a
MB
1003 myStringHashMap sh(0); // as small as possible
1004 wxString buf;
1005 size_t i;
1006 const size_t count = 10000;
1007
1008 // init with some data
1009 for( i = 0; i < count; ++i )
1010 {
1011 buf.Printf(wxT("%d"), i );
1012 sh[buf] = wxT("A") + buf + wxT("C");
1013 }
1014
1015 // test that insertion worked
1016 if( sh.size() != count )
1017 {
456ae26d 1018 wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh.size(), count);
0508ba2a
MB
1019 }
1020
1021 for( i = 0; i < count; ++i )
1022 {
1023 buf.Printf(wxT("%d"), i );
1024 if( sh[buf] != wxT("A") + buf + wxT("C") )
1025 {
456ae26d 1026 wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
0508ba2a
MB
1027 return;
1028 }
1029 }
1030
1031 // check that iterators work
1032 Itor it;
1033 for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
1034 {
1035 if( i == count )
1036 {
456ae26d 1037 wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
0508ba2a
MB
1038 return;
1039 }
1040
1041 if( it->second != sh[it->first] )
1042 {
456ae26d 1043 wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
0508ba2a
MB
1044 return;
1045 }
1046 }
1047
1048 if( sh.size() != i )
1049 {
456ae26d 1050 wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i, count);
0508ba2a
MB
1051 }
1052
1053 // test copy ctor, assignment operator
1054 myStringHashMap h1( sh ), h2( 0 );
1055 h2 = sh;
1056
1057 for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
1058 {
1059 if( h1[it->first] != it->second )
1060 {
456ae26d 1061 wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it->first.c_str());
0508ba2a
MB
1062 }
1063
1064 if( h2[it->first] != it->second )
1065 {
456ae26d 1066 wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it->first.c_str());
0508ba2a
MB
1067 }
1068 }
1069
1070 // other tests
1071 for( i = 0; i < count; ++i )
1072 {
1073 buf.Printf(wxT("%d"), i );
1074 size_t sz = sh.size();
1075
1076 // test find() and erase(it)
1077 if( i < 100 )
1078 {
1079 it = sh.find( buf );
1080 if( it != sh.end() )
1081 {
1082 sh.erase( it );
1083
1084 if( sh.find( buf ) != sh.end() )
1085 {
456ae26d 1086 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
0508ba2a
MB
1087 }
1088 }
1089 else
456ae26d 1090 wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i);
0508ba2a
MB
1091 }
1092 else
1093 // test erase(key)
1094 {
1095 size_t c = sh.erase( buf );
1096 if( c != 1 )
456ae26d 1097 wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
0508ba2a
MB
1098
1099 if( sh.find( buf ) != sh.end() )
1100 {
456ae26d 1101 wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
0508ba2a
MB
1102 }
1103 }
1104
1105 // count should decrease
1106 if( sh.size() != sz - 1 )
1107 {
456ae26d 1108 wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
0508ba2a
MB
1109 }
1110 }
1111
456ae26d 1112 wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
0508ba2a
MB
1113}
1114
60ce696e 1115#endif // TEST_HASHMAP
0508ba2a 1116
8142d704
MB
1117// ----------------------------------------------------------------------------
1118// wxHashSet
1119// ----------------------------------------------------------------------------
1120
1121#ifdef TEST_HASHSET
1122
1123#include "wx/hashset.h"
1124
1125// test compilation of basic map types
1126WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet );
1127WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet );
1128WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual,
1129 myUnsignedHashSet );
1130WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual,
1131 myTestHashSet1 );
1132WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual,
1133 myTestHashSet2 );
1134WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual,
1135 myTestHashSet3 );
1136WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual,
1137 myTestHashSet4 );
1138WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual,
1139 myTestHashSet5 );
1140
1141struct MyStruct
1142{
1143 int* ptr;
1144 wxString str;
1145};
1146
1147class MyHash
1148{
1149public:
1150 unsigned long operator()(const MyStruct& s) const
1151 { return m_dummy(s.ptr); }
1152 MyHash& operator=(const MyHash&) { return *this; }
1153private:
1154 wxPointerHash m_dummy;
1155};
1156
1157class MyEqual
1158{
1159public:
1160 bool operator()(const MyStruct& s1, const MyStruct& s2) const
1161 { return s1.ptr == s2.ptr; }
1162 MyEqual& operator=(const MyEqual&) { return *this; }
1163};
1164
1165WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet );
1166
1167typedef myTestHashSet5 wxStringHashSet;
1168
1169static void TestHashSet()
1170{
1171 wxPrintf(_T("*** Testing wxHashSet ***\n"));
1172
1173 wxStringHashSet set1;
1174
1175 set1.insert( _T("abc") );
1176 set1.insert( _T("bbc") );
1177 set1.insert( _T("cbc") );
1178 set1.insert( _T("abc") );
1179
1180 if( set1.size() != 3 )
1181 wxPrintf(_T("*** ERROR IN INSERT ***\n"));
1182
1183 mySet set2;
1184 int dummy;
1185 MyStruct tmp;
1186
1187 tmp.ptr = &dummy; tmp.str = _T("ABC");
1188 set2.insert( tmp );
1189 tmp.ptr = &dummy + 1;
1190 set2.insert( tmp );
1191 tmp.ptr = &dummy; tmp.str = _T("CDE");
1192 set2.insert( tmp );
1193
1194 if( set2.size() != 2 )
1195 wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
1196
1197 mySet::iterator it = set2.find( tmp );
1198
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"));
1205
1206 wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
1207}
1208
1209#endif // TEST_HASHSET
1210
f6bcfd97
BP
1211// ----------------------------------------------------------------------------
1212// wxList
1213// ----------------------------------------------------------------------------
1214
1215#ifdef TEST_LIST
1216
e84010cf 1217#include "wx/list.h"
f6bcfd97
BP
1218
1219WX_DECLARE_LIST(Bar, wxListBars);
e84010cf 1220#include "wx/listimpl.cpp"
f6bcfd97
BP
1221WX_DEFINE_LIST(wxListBars);
1222
df5168c4
MB
1223WX_DECLARE_LIST(int, wxListInt);
1224WX_DEFINE_LIST(wxListInt);
1225
1226static void TestList()
1227{
1228 wxPuts(_T("*** Testing wxList operations ***\n"));
1229 {
1230 wxListInt list1;
1231 int dummy[5];
1232 int i;
1233
1234 for ( i = 0; i < 5; ++i )
1235 list1.Append(dummy + i);
1236
1237 if ( list1.GetCount() != 5 )
1238 wxPuts(_T("Wrong number of items in list\n"));
1239
1240 if ( list1.Item(3)->GetData() != dummy + 3 )
1241 wxPuts(_T("Error in Item()\n"));
1242
1243 if ( !list1.Find(dummy + 4) )
1244 wxPuts(_T("Error in Find()\n"));
1245
1246 wxListInt::compatibility_iterator node = list1.GetFirst();
1247 i = 0;
1248
1249 while (node)
1250 {
1251 if ( node->GetData() != dummy + i )
1252 wxPuts(_T("Error in compatibility_iterator\n"));
1253 node = node->GetNext();
1254 ++i;
1255 }
1256
1257 if ( size_t(i) != list1.GetCount() )
1258 wxPuts(_T("Error in compatibility_iterator\n"));
1259
1260 list1.Insert(dummy + 0);
1261 list1.Insert(1, dummy + 1);
1262 list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2);
1263
1264 node = list1.GetFirst();
1265 i = 0;
1266
1267 while (i < 3)
1268 {
1269 int* t = node->GetData();
1270 if ( t != dummy + i )
1271 wxPuts(_T("Error in Insert\n"));
1272 node = node->GetNext();
1273 ++i;
1274 }
1275 }
1276
1277 wxPuts(_T("*** Testing wxList operations finished ***\n"));
1278
1279 wxPuts(_T("*** Testing std::list operations ***\n"));
1280
1281 {
1282 wxListInt list1;
1283 wxListInt::iterator it, en;
1284 wxListInt::reverse_iterator rit, ren;
1285 int i;
1286 for ( i = 0; i < 5; ++i )
1287 list1.push_back(i + &i);
1288
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"));
1293
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"));
1298
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"));
1305
1306 if ( list1.front() != &i || list1.back() != &i + 4 )
1307 wxPuts(_T("Error in front()/back()\n"));
1308
1309 list1.erase(list1.begin());
1310 list1.erase(--list1.end());
1311
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"));
1316 }
e9d2bb6f 1317
df5168c4
MB
1318 wxPuts(_T("*** Testing std::list operations finished ***\n"));
1319}
1320
f6bcfd97
BP
1321static void TestListCtor()
1322{
456ae26d 1323 wxPuts(_T("*** Testing wxList construction ***\n"));
f6bcfd97
BP
1324
1325 {
1326 wxListBars list1;
1327 list1.Append(new Bar(_T("first")));
1328 list1.Append(new Bar(_T("second")));
1329
456ae26d 1330 wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
f6bcfd97
BP
1331 list1.GetCount(), Bar::GetNumber());
1332
1333 wxListBars list2;
1334 list2 = list1;
1335
456ae26d 1336 wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
f6bcfd97
BP
1337 list1.GetCount(), list2.GetCount(), Bar::GetNumber());
1338
df5168c4 1339#if !wxUSE_STL
cab8f76e 1340 list1.DeleteContents(true);
df5168c4
MB
1341#else
1342 WX_CLEAR_LIST(wxListBars, list1);
1343#endif
f6bcfd97
BP
1344 }
1345
456ae26d 1346 wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
f6bcfd97
BP
1347}
1348
1349#endif // TEST_LIST
1350
ec37df57
VZ
1351// ----------------------------------------------------------------------------
1352// wxLocale
1353// ----------------------------------------------------------------------------
1354
1355#ifdef TEST_LOCALE
1356
1357#include "wx/intl.h"
1358#include "wx/utils.h" // for wxSetEnv
1359
1360static wxLocale gs_localeDefault(wxLANGUAGE_ENGLISH);
1361
1362// find the name of the language from its value
456ae26d
VZ
1363static const wxChar *GetLangName(int lang)
1364{
1365 static const wxChar *languageNames[] =
1366 {
1367 _T("DEFAULT"),
1368 _T("UNKNOWN"),
1369 _T("ABKHAZIAN"),
1370 _T("AFAR"),
1371 _T("AFRIKAANS"),
1372 _T("ALBANIAN"),
1373 _T("AMHARIC"),
1374 _T("ARABIC"),
1375 _T("ARABIC_ALGERIA"),
1376 _T("ARABIC_BAHRAIN"),
1377 _T("ARABIC_EGYPT"),
1378 _T("ARABIC_IRAQ"),
1379 _T("ARABIC_JORDAN"),
1380 _T("ARABIC_KUWAIT"),
1381 _T("ARABIC_LEBANON"),
1382 _T("ARABIC_LIBYA"),
1383 _T("ARABIC_MOROCCO"),
1384 _T("ARABIC_OMAN"),
1385 _T("ARABIC_QATAR"),
1386 _T("ARABIC_SAUDI_ARABIA"),
1387 _T("ARABIC_SUDAN"),
1388 _T("ARABIC_SYRIA"),
1389 _T("ARABIC_TUNISIA"),
1390 _T("ARABIC_UAE"),
1391 _T("ARABIC_YEMEN"),
1392 _T("ARMENIAN"),
1393 _T("ASSAMESE"),
1394 _T("AYMARA"),
1395 _T("AZERI"),
1396 _T("AZERI_CYRILLIC"),
1397 _T("AZERI_LATIN"),
1398 _T("BASHKIR"),
1399 _T("BASQUE"),
1400 _T("BELARUSIAN"),
1401 _T("BENGALI"),
1402 _T("BHUTANI"),
1403 _T("BIHARI"),
1404 _T("BISLAMA"),
1405 _T("BRETON"),
1406 _T("BULGARIAN"),
1407 _T("BURMESE"),
1408 _T("CAMBODIAN"),
1409 _T("CATALAN"),
1410 _T("CHINESE"),
1411 _T("CHINESE_SIMPLIFIED"),
1412 _T("CHINESE_TRADITIONAL"),
1413 _T("CHINESE_HONGKONG"),
1414 _T("CHINESE_MACAU"),
1415 _T("CHINESE_SINGAPORE"),
1416 _T("CHINESE_TAIWAN"),
1417 _T("CORSICAN"),
1418 _T("CROATIAN"),
1419 _T("CZECH"),
1420 _T("DANISH"),
1421 _T("DUTCH"),
1422 _T("DUTCH_BELGIAN"),
1423 _T("ENGLISH"),
1424 _T("ENGLISH_UK"),
1425 _T("ENGLISH_US"),
1426 _T("ENGLISH_AUSTRALIA"),
1427 _T("ENGLISH_BELIZE"),
1428 _T("ENGLISH_BOTSWANA"),
1429 _T("ENGLISH_CANADA"),
1430 _T("ENGLISH_CARIBBEAN"),
1431 _T("ENGLISH_DENMARK"),
1432 _T("ENGLISH_EIRE"),
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"),
1439 _T("ESPERANTO"),
1440 _T("ESTONIAN"),
1441 _T("FAEROESE"),
1442 _T("FARSI"),
1443 _T("FIJI"),
1444 _T("FINNISH"),
1445 _T("FRENCH"),
1446 _T("FRENCH_BELGIAN"),
1447 _T("FRENCH_CANADIAN"),
1448 _T("FRENCH_LUXEMBOURG"),
1449 _T("FRENCH_MONACO"),
1450 _T("FRENCH_SWISS"),
1451 _T("FRISIAN"),
1452 _T("GALICIAN"),
1453 _T("GEORGIAN"),
1454 _T("GERMAN"),
1455 _T("GERMAN_AUSTRIAN"),
1456 _T("GERMAN_BELGIUM"),
1457 _T("GERMAN_LIECHTENSTEIN"),
1458 _T("GERMAN_LUXEMBOURG"),
1459 _T("GERMAN_SWISS"),
1460 _T("GREEK"),
1461 _T("GREENLANDIC"),
1462 _T("GUARANI"),
1463 _T("GUJARATI"),
1464 _T("HAUSA"),
1465 _T("HEBREW"),
1466 _T("HINDI"),
1467 _T("HUNGARIAN"),
1468 _T("ICELANDIC"),
1469 _T("INDONESIAN"),
1470 _T("INTERLINGUA"),
1471 _T("INTERLINGUE"),
1472 _T("INUKTITUT"),
1473 _T("INUPIAK"),
1474 _T("IRISH"),
1475 _T("ITALIAN"),
1476 _T("ITALIAN_SWISS"),
1477 _T("JAPANESE"),
1478 _T("JAVANESE"),
1479 _T("KANNADA"),
1480 _T("KASHMIRI"),
1481 _T("KASHMIRI_INDIA"),
1482 _T("KAZAKH"),
1483 _T("KERNEWEK"),
1484 _T("KINYARWANDA"),
1485 _T("KIRGHIZ"),
1486 _T("KIRUNDI"),
1487 _T("KONKANI"),
1488 _T("KOREAN"),
1489 _T("KURDISH"),
1490 _T("LAOTHIAN"),
1491 _T("LATIN"),
1492 _T("LATVIAN"),
1493 _T("LINGALA"),
1494 _T("LITHUANIAN"),
1495 _T("MACEDONIAN"),
1496 _T("MALAGASY"),
1497 _T("MALAY"),
1498 _T("MALAYALAM"),
1499 _T("MALAY_BRUNEI_DARUSSALAM"),
1500 _T("MALAY_MALAYSIA"),
1501 _T("MALTESE"),
1502 _T("MANIPURI"),
1503 _T("MAORI"),
1504 _T("MARATHI"),
1505 _T("MOLDAVIAN"),
1506 _T("MONGOLIAN"),
1507 _T("NAURU"),
1508 _T("NEPALI"),
1509 _T("NEPALI_INDIA"),
1510 _T("NORWEGIAN_BOKMAL"),
1511 _T("NORWEGIAN_NYNORSK"),
1512 _T("OCCITAN"),
1513 _T("ORIYA"),
1514 _T("OROMO"),
1515 _T("PASHTO"),
1516 _T("POLISH"),
1517 _T("PORTUGUESE"),
1518 _T("PORTUGUESE_BRAZILIAN"),
1519 _T("PUNJABI"),
1520 _T("QUECHUA"),
1521 _T("RHAETO_ROMANCE"),
1522 _T("ROMANIAN"),
1523 _T("RUSSIAN"),
1524 _T("RUSSIAN_UKRAINE"),
1525 _T("SAMOAN"),
1526 _T("SANGHO"),
1527 _T("SANSKRIT"),
1528 _T("SCOTS_GAELIC"),
1529 _T("SERBIAN"),
1530 _T("SERBIAN_CYRILLIC"),
1531 _T("SERBIAN_LATIN"),
1532 _T("SERBO_CROATIAN"),
1533 _T("SESOTHO"),
1534 _T("SETSWANA"),
1535 _T("SHONA"),
1536 _T("SINDHI"),
1537 _T("SINHALESE"),
1538 _T("SISWATI"),
1539 _T("SLOVAK"),
1540 _T("SLOVENIAN"),
1541 _T("SOMALI"),
1542 _T("SPANISH"),
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"),
1558 _T("SPANISH_PERU"),
1559 _T("SPANISH_PUERTO_RICO"),
1560 _T("SPANISH_URUGUAY"),
1561 _T("SPANISH_US"),
1562 _T("SPANISH_VENEZUELA"),
1563 _T("SUNDANESE"),
1564 _T("SWAHILI"),
1565 _T("SWEDISH"),
1566 _T("SWEDISH_FINLAND"),
1567 _T("TAGALOG"),
1568 _T("TAJIK"),
1569 _T("TAMIL"),
1570 _T("TATAR"),
1571 _T("TELUGU"),
1572 _T("THAI"),
1573 _T("TIBETAN"),
1574 _T("TIGRINYA"),
1575 _T("TONGA"),
1576 _T("TSONGA"),
1577 _T("TURKISH"),
1578 _T("TURKMEN"),
1579 _T("TWI"),
1580 _T("UIGHUR"),
1581 _T("UKRAINIAN"),
1582 _T("URDU"),
1583 _T("URDU_INDIA"),
1584 _T("URDU_PAKISTAN"),
1585 _T("UZBEK"),
1586 _T("UZBEK_CYRILLIC"),
1587 _T("UZBEK_LATIN"),
1588 _T("VIETNAMESE"),
1589 _T("VOLAPUK"),
1590 _T("WELSH"),
1591 _T("WOLOF"),
1592 _T("XHOSA"),
1593 _T("YIDDISH"),
1594 _T("YORUBA"),
1595 _T("ZHUANG"),
1596 _T("ZULU"),
ec37df57
VZ
1597 };
1598
1599 if ( (size_t)lang < WXSIZEOF(languageNames) )
1600 return languageNames[lang];
1601 else
456ae26d 1602 return _T("INVALID");
ec37df57
VZ
1603}
1604
1605static void TestDefaultLang()
1606{
456ae26d 1607 wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
ec37df57
VZ
1608
1609 static const wxChar *langStrings[] =
1610 {
1611 NULL, // system default
1612 _T("C"),
1613 _T("fr"),
1614 _T("fr_FR"),
1615 _T("en"),
1616 _T("en_GB"),
1617 _T("en_US"),
1618 _T("de_DE.iso88591"),
1619 _T("german"),
1620 _T("?"), // invalid lang spec
1621 _T("klingonese"), // I bet on some systems it does exist...
1622 };
1623
dccce9ea
VZ
1624 wxPrintf(_T("The default system encoding is %s (%d)\n"),
1625 wxLocale::GetSystemEncodingName().c_str(),
1626 wxLocale::GetSystemEncoding());
1627
ec37df57
VZ
1628 for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
1629 {
456ae26d 1630 const wxChar *langStr = langStrings[n];
ec37df57 1631 if ( langStr )
dccce9ea
VZ
1632 {
1633 // FIXME: this doesn't do anything at all under Windows, we need
1634 // to create a new wxLocale!
ec37df57 1635 wxSetEnv(_T("LC_ALL"), langStr);
dccce9ea 1636 }
ec37df57
VZ
1637
1638 int lang = gs_localeDefault.GetSystemLanguage();
456ae26d
VZ
1639 wxPrintf(_T("Locale for '%s' is %s.\n"),
1640 langStr ? langStr : _T("system default"), GetLangName(lang));
ec37df57
VZ
1641 }
1642}
1643
1644#endif // TEST_LOCALE
1645
696e1ea0
VZ
1646// ----------------------------------------------------------------------------
1647// MIME types
1648// ----------------------------------------------------------------------------
1649
1650#ifdef TEST_MIME
1651
e84010cf 1652#include "wx/mimetype.h"
696e1ea0
VZ
1653
1654static void TestMimeEnum()
1655{
a6c65e88
VZ
1656 wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
1657
696e1ea0
VZ
1658 wxArrayString mimetypes;
1659
39189b9d 1660 size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
696e1ea0 1661
456ae26d 1662 wxPrintf(_T("*** All %u known filetypes: ***\n"), count);
696e1ea0
VZ
1663
1664 wxArrayString exts;
1665 wxString desc;
1666
1667 for ( size_t n = 0; n < count; n++ )
1668 {
39189b9d
VZ
1669 wxFileType *filetype =
1670 wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
696e1ea0 1671 if ( !filetype )
c61f4f6d 1672 {
456ae26d 1673 wxPrintf(_T("nothing known about the filetype '%s'!\n"),
97e0ceea 1674 mimetypes[n].c_str());
696e1ea0 1675 continue;
c61f4f6d
VZ
1676 }
1677
696e1ea0
VZ
1678 filetype->GetDescription(&desc);
1679 filetype->GetExtensions(exts);
1680
299fcbfe
VZ
1681 filetype->GetIcon(NULL);
1682
696e1ea0
VZ
1683 wxString extsAll;
1684 for ( size_t e = 0; e < exts.GetCount(); e++ )
1685 {
1686 if ( e > 0 )
1687 extsAll << _T(", ");
1688 extsAll += exts[e];
1689 }
1690
456ae26d 1691 wxPrintf(_T("\t%s: %s (%s)\n"),
54acce90 1692 mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
696e1ea0 1693 }
39189b9d 1694
e9d2bb6f 1695 wxPuts(wxEmptyString);
696e1ea0
VZ
1696}
1697
f6bcfd97
BP
1698static void TestMimeOverride()
1699{
1700 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
1701
39189b9d
VZ
1702 static const wxChar *mailcap = _T("/tmp/mailcap");
1703 static const wxChar *mimetypes = _T("/tmp/mime.types");
1704
1705 if ( wxFile::Exists(mailcap) )
1706 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
1707 mailcap,
1708 wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR"));
1709 else
1710 wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
1711 mailcap);
f6bcfd97 1712
39189b9d
VZ
1713 if ( wxFile::Exists(mimetypes) )
1714 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
1715 mimetypes,
1716 wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR"));
1717 else
1718 wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
1719 mimetypes);
1720
e9d2bb6f 1721 wxPuts(wxEmptyString);
f6bcfd97
BP
1722}
1723
1724static void TestMimeFilename()
1725{
1726 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
1727
1728 static const wxChar *filenames[] =
1729 {
1730 _T("readme.txt"),
1731 _T("document.pdf"),
1732 _T("image.gif"),
f06ef5f4 1733 _T("picture.jpeg"),
f6bcfd97
BP
1734 };
1735
1736 for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
1737 {
1738 const wxString fname = filenames[n];
1739 wxString ext = fname.AfterLast(_T('.'));
39189b9d 1740 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
f6bcfd97
BP
1741 if ( !ft )
1742 {
1743 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str());
1744 }
1745 else
1746 {
1747 wxString desc;
1748 if ( !ft->GetDescription(&desc) )
1749 desc = _T("<no description>");
1750
1751 wxString cmd;
1752 if ( !ft->GetOpenCommand(&cmd,
e9d2bb6f 1753 wxFileType::MessageParameters(fname, wxEmptyString)) )
f6bcfd97 1754 cmd = _T("<no command available>");
7aeebdcd 1755 else
2b5f62a0 1756 cmd = wxString(_T('"')) + cmd + _T('"');
f6bcfd97 1757
7aeebdcd 1758 wxPrintf(_T("To open %s (%s) do %s.\n"),
f6bcfd97
BP
1759 fname.c_str(), desc.c_str(), cmd.c_str());
1760
1761 delete ft;
1762 }
1763 }
39189b9d 1764
e9d2bb6f 1765 wxPuts(wxEmptyString);
f6bcfd97
BP
1766}
1767
c7ce8392
VZ
1768static void TestMimeAssociate()
1769{
1770 wxPuts(_T("*** Testing creation of filetype association ***\n"));
1771
a6c65e88
VZ
1772 wxFileTypeInfo ftInfo(
1773 _T("application/x-xyz"),
1774 _T("xyzview '%s'"), // open cmd
1775 _T(""), // print cmd
df0dc216
VZ
1776 _T("XYZ File"), // description
1777 _T(".xyz"), // extensions
1778 NULL // end of extensions
a6c65e88
VZ
1779 );
1780 ftInfo.SetShortDesc(_T("XYZFile")); // used under Win32 only
1781
39189b9d 1782 wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
c7ce8392
VZ
1783 if ( !ft )
1784 {
1785 wxPuts(_T("ERROR: failed to create association!"));
1786 }
1787 else
1788 {
a6c65e88 1789 // TODO: read it back
c7ce8392
VZ
1790 delete ft;
1791 }
39189b9d 1792
e9d2bb6f 1793 wxPuts(wxEmptyString);
c7ce8392
VZ
1794}
1795
696e1ea0
VZ
1796#endif // TEST_MIME
1797
89e60357
VZ
1798// ----------------------------------------------------------------------------
1799// misc information functions
1800// ----------------------------------------------------------------------------
1801
1802#ifdef TEST_INFO_FUNCTIONS
1803
e84010cf 1804#include "wx/utils.h"
89e60357 1805
3a994742
VZ
1806static void TestDiskInfo()
1807{
456ae26d 1808 wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
3a994742
VZ
1809
1810 for ( ;; )
1811 {
456ae26d
VZ
1812 wxChar pathname[128];
1813 wxPrintf(_T("\nEnter a directory name: "));
1814 if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
3a994742
VZ
1815 break;
1816
1817 // kill the last '\n'
456ae26d 1818 pathname[wxStrlen(pathname) - 1] = 0;
3a994742
VZ
1819
1820 wxLongLong total, free;
1821 if ( !wxGetDiskSpace(pathname, &total, &free) )
1822 {
1823 wxPuts(_T("ERROR: wxGetDiskSpace failed."));
1824 }
1825 else
1826 {
eadd7bd2
VZ
1827 wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
1828 (total / 1024).ToString().c_str(),
1829 (free / 1024).ToString().c_str(),
3a994742
VZ
1830 pathname);
1831 }
1832 }
1833}
1834
89e60357
VZ
1835static void TestOsInfo()
1836{
456ae26d 1837 wxPuts(_T("*** Testing OS info functions ***\n"));
89e60357
VZ
1838
1839 int major, minor;
1840 wxGetOsVersion(&major, &minor);
456ae26d 1841 wxPrintf(_T("Running under: %s, version %d.%d\n"),
89e60357
VZ
1842 wxGetOsDescription().c_str(), major, minor);
1843
456ae26d 1844 wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
89e60357 1845
456ae26d 1846 wxPrintf(_T("Host name is %s (%s).\n"),
89e60357 1847 wxGetHostName().c_str(), wxGetFullHostName().c_str());
bd3277fe 1848
e9d2bb6f 1849 wxPuts(wxEmptyString);
89e60357
VZ
1850}
1851
1852static void TestUserInfo()
1853{
456ae26d 1854 wxPuts(_T("*** Testing user info functions ***\n"));
89e60357 1855
456ae26d
VZ
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());
bd3277fe 1860
e9d2bb6f 1861 wxPuts(wxEmptyString);
89e60357
VZ
1862}
1863
1864#endif // TEST_INFO_FUNCTIONS
1865
39189b9d
VZ
1866// ----------------------------------------------------------------------------
1867// path list
1868// ----------------------------------------------------------------------------
1869
1870#ifdef TEST_PATHLIST
1871
ee3ef281
VZ
1872#ifdef __UNIX__
1873 #define CMD_IN_PATH _T("ls")
1874#else
1875 #define CMD_IN_PATH _T("command.com")
1876#endif
1877
39189b9d
VZ
1878static void TestPathList()
1879{
456ae26d 1880 wxPuts(_T("*** Testing wxPathList ***\n"));
39189b9d
VZ
1881
1882 wxPathList pathlist;
ee3ef281
VZ
1883 pathlist.AddEnvList(_T("PATH"));
1884 wxString path = pathlist.FindValidPath(CMD_IN_PATH);
39189b9d
VZ
1885 if ( path.empty() )
1886 {
456ae26d 1887 wxPrintf(_T("ERROR: command not found in the path.\n"));
39189b9d
VZ
1888 }
1889 else
1890 {
456ae26d 1891 wxPrintf(_T("Command found in the path as '%s'.\n"), path.c_str());
39189b9d
VZ
1892 }
1893}
1894
1895#endif // TEST_PATHLIST
1896
07a56e45
VZ
1897// ----------------------------------------------------------------------------
1898// regular expressions
1899// ----------------------------------------------------------------------------
1900
1901#ifdef TEST_REGEX
1902
e84010cf 1903#include "wx/regex.h"
07a56e45 1904
07a56e45
VZ
1905static void TestRegExInteractive()
1906{
1907 wxPuts(_T("*** Testing RE interactively ***"));
1908
1909 for ( ;; )
1910 {
456ae26d
VZ
1911 wxChar pattern[128];
1912 wxPrintf(_T("\nEnter a pattern: "));
1913 if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
07a56e45
VZ
1914 break;
1915
1916 // kill the last '\n'
456ae26d 1917 pattern[wxStrlen(pattern) - 1] = 0;
07a56e45
VZ
1918
1919 wxRegEx re;
1920 if ( !re.Compile(pattern) )
1921 {
1922 continue;
1923 }
1924
456ae26d 1925 wxChar text[128];
07a56e45
VZ
1926 for ( ;; )
1927 {
456ae26d
VZ
1928 wxPrintf(_T("Enter text to match: "));
1929 if ( !wxFgets(text, WXSIZEOF(text), stdin) )
07a56e45
VZ
1930 break;
1931
1932 // kill the last '\n'
456ae26d 1933 text[wxStrlen(text) - 1] = 0;
07a56e45
VZ
1934
1935 if ( !re.Matches(text) )
1936 {
456ae26d 1937 wxPrintf(_T("No match.\n"));
07a56e45
VZ
1938 }
1939 else
1940 {
456ae26d 1941 wxPrintf(_T("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());
07a56e45
VZ
1942
1943 size_t start, len;
1944 for ( size_t n = 1; ; n++ )
1945 {
1946 if ( !re.GetMatch(&start, &len, n) )
1947 {
1948 break;
1949 }
1950
456ae26d
VZ
1951 wxPrintf(_T("Subexpr %u matched '%s'\n"),
1952 n, wxString(text + start, len).c_str());
07a56e45
VZ
1953 }
1954 }
1955 }
1956 }
1957}
1958
1959#endif // TEST_REGEX
1960
8d5eff60
VZ
1961// ----------------------------------------------------------------------------
1962// database
1963// ----------------------------------------------------------------------------
1964
ba6ea19e
VZ
1965#if !wxUSE_ODBC
1966 #undef TEST_ODBC
1967#endif
1968
8d5eff60
VZ
1969#ifdef TEST_ODBC
1970
1971#include <wx/db.h>
1972
1973static void TestDbOpen()
1974{
1975 HENV henv;
1976 wxDb db(henv);
1977}
1978
1979#endif // TEST_ODBC
1980
7aeebdcd
VZ
1981// ----------------------------------------------------------------------------
1982// printf() tests
1983// ----------------------------------------------------------------------------
1984
1985/*
1986 NB: this stuff was taken from the glibc test suite and modified to build
be5a51fb 1987 in wxWidgets: if I read the copyright below properly, this shouldn't
7aeebdcd
VZ
1988 be a problem
1989 */
1990
1991#ifdef TEST_PRINTF
1992
1993#ifdef wxTEST_PRINTF
1994 // use our functions from wxchar.cpp
1995 #undef wxPrintf
1996 #undef wxSprintf
1997
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, ... );
2002#endif
2003
f1389d46
VZ
2004#include "wx/longlong.h"
2005
7aeebdcd
VZ
2006#include <float.h>
2007
2008static void rfg1 (void);
2009static void rfg2 (void);
2010
2011
2012static void
2013fmtchk (const wxChar *fmt)
2014{
2015 (void) wxPrintf(_T("%s:\t`"), fmt);
2016 (void) wxPrintf(fmt, 0x12);
2017 (void) wxPrintf(_T("'\n"));
2018}
2019
2020static void
2021fmtst1chk (const wxChar *fmt)
2022{
2023 (void) wxPrintf(_T("%s:\t`"), fmt);
2024 (void) wxPrintf(fmt, 4, 0x12);
2025 (void) wxPrintf(_T("'\n"));
2026}
2027
2028static void
2029fmtst2chk (const wxChar *fmt)
2030{
2031 (void) wxPrintf(_T("%s:\t`"), fmt);
2032 (void) wxPrintf(fmt, 4, 4, 0x12);
2033 (void) wxPrintf(_T("'\n"));
2034}
2035
2036/* This page is covered by the following copyright: */
2037
2038/* (C) Copyright C E Chew
2039 *
2040 * Feel free to copy, use and distribute this software provided:
2041 *
2042 * 1. you do not pretend that you wrote it
2043 * 2. you leave this copyright notice intact.
2044 */
2045
2046/*
2047 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
2048 */
2049
2050#define DEC -123
2051#define INT 255
2052#define UNS (~0)
2053
2054/* Formatted Output Test
2055 *
2056 * This exercises the output formatting code.
2057 */
2058
e9d2bb6f
DS
2059wxChar *PointerNull = NULL;
2060
7aeebdcd
VZ
2061static void
2062fp_test (void)
2063{
2064 int i, j, k, l;
2065 wxChar buf[7];
2066 wxChar *prefix = buf;
2067 wxChar tp[20];
2068
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 |"));
2084 wxPrintf(tp, DEC);
2085 wxStrcpy(tp, prefix);
2086 wxStrcat(tp, _T("6o |"));
2087 wxPrintf(tp, INT);
2088 wxStrcpy(tp, prefix);
2089 wxStrcat(tp, _T("6x |"));
2090 wxPrintf(tp, INT);
2091 wxStrcpy(tp, prefix);
2092 wxStrcat(tp, _T("6X |"));
2093 wxPrintf(tp, INT);
2094 wxStrcpy(tp, prefix);
2095 wxStrcat(tp, _T("6u |"));
2096 wxPrintf(tp, UNS);
2097 wxPrintf(_T("\n"));
2098 }
2099 }
2100 }
2101 }
e9d2bb6f
DS
2102 wxPrintf(_T("%10s\n"), PointerNull);
2103 wxPrintf(_T("%-10s\n"), PointerNull);
7aeebdcd
VZ
2104}
2105
2106static void TestPrintf()
2107{
2108 static wxChar shortstr[] = _T("Hi, Z.");
f1389d46
VZ
2109 static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \
2110I am ready for my first lesson today.");
7aeebdcd 2111 int result = 0;
e9d2bb6f 2112 wxString test_format;
7aeebdcd
VZ
2113
2114 fmtchk(_T("%.4x"));
2115 fmtchk(_T("%04x"));
2116 fmtchk(_T("%4.4x"));
2117 fmtchk(_T("%04.4x"));
2118 fmtchk(_T("%4.3x"));
2119 fmtchk(_T("%04.3x"));
2120
2121 fmtst1chk(_T("%.*x"));
2122 fmtst1chk(_T("%0*x"));
2123 fmtst2chk(_T("%*.*x"));
2124 fmtst2chk(_T("%0*.*x"));
2125
e9d2bb6f
DS
2126 wxString bad_format = _T("bad format:\t\"%b\"\n");
2127 wxPrintf(bad_format.c_str());
7aeebdcd
VZ
2128 wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL);
2129
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);
e9d2bb6f
DS
2137 test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
2138 wxPrintf(test_format.c_str(), -123456);
7aeebdcd
VZ
2139 wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
2140 wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
2141
e9d2bb6f
DS
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);
7aeebdcd
VZ
2146 wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr);
2147 wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr);
e9d2bb6f 2148 wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull);
7aeebdcd
VZ
2149 wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr);
2150
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);
2163
2164 wxPrintf (_T(" %6.5f\n"), .099999999860301614);
2165 wxPrintf (_T(" %6.5f\n"), .1);
2166 wxPrintf (_T("x%5.4fx\n"), .5);
2167
2168 wxPrintf (_T("%#03x\n"), 1);
2169
2170 //wxPrintf (_T("something really insane: %.10000f\n"), 1.0);
2171
2172 {
2173 double d = FLT_MIN;
2174 int niter = 17;
2175
2176 while (niter-- != 0)
2177 wxPrintf (_T("%.17e\n"), d / 2);
2178 fflush (stdout);
2179 }
2180
e9d2bb6f
DS
2181#ifndef __WATCOMC__
2182 // Open Watcom cause compiler error here
2183 // Error! E173: col(24) floating-point constant too small to represent
7aeebdcd 2184 wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
e9d2bb6f 2185#endif
7aeebdcd
VZ
2186
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);
2197#undef FORMAT
2198
2199 {
2200 wxChar buf[20];
2201 int rc = wxSnprintf (buf, WXSIZEOF(buf), _T("%30s"), _T("foo"));
2202
2203 wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"),
2204 rc, WXSIZEOF(buf), buf);
2205#if 0
2206 wxChar buf2[512];
2207 wxPrintf ("snprintf (\"%%.999999u\", 10)\n",
2208 wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10));
2209#endif
2210 }
2211
2212 fp_test ();
2213
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);
2221
2222 {
2223 double x=1.0;
2224 wxPrintf(_T("%.17f\n"),(1.0/x/10.0+1.0)*x-x);
2225 }
2226
2227 {
2228 wxChar buf[200];
2229
2230 wxSprintf(buf,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three"));
2231
2232 result |= wxStrcmp (buf,
2233 _T("onetwo three "));
2234
2235 wxPuts (result != 0 ? _T("Test failed!") : _T("Test ok."));
2236 }
2237
f1389d46 2238#ifdef wxLongLong_t
7aeebdcd 2239 {
f1389d46 2240 wxChar buf[200];
7aeebdcd 2241
2b5f62a0 2242 wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000));
f2cb8a17
JS
2243 #if 0
2244 // for some reason below line fails under Borland
f1389d46 2245 wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf);
f2cb8a17 2246 #endif
7aeebdcd 2247
f1389d46 2248 if (wxStrcmp (buf, _T("40000000000")) != 0)
7aeebdcd 2249 {
f1389d46
VZ
2250 result = 1;
2251 wxPuts (_T("\tFAILED"));
7aeebdcd 2252 }
e9d2bb6f
DS
2253 wxUnusedVar(result);
2254 wxPuts (wxEmptyString);
7aeebdcd 2255 }
f1389d46 2256#endif // wxLongLong_t
7aeebdcd
VZ
2257
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);
2260
2261 wxPuts (_T("--- Should be no further output. ---"));
2262 rfg1 ();
2263 rfg2 ();
2264
2265#if 0
2266 {
2267 wxChar bytes[7];
2268 wxChar buf[20];
2269
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')
2274 {
2275 wxPuts (_T("%hhn overwrite more bytes"));
2276 result = 1;
2277 }
2278 if (bytes[3] != 3)
2279 {
2280 wxPuts (_T("%hhn wrote incorrect value"));
2281 result = 1;
2282 }
2283 }
2284#endif
2285}
2286
2287static void
2288rfg1 (void)
2289{
2290 wxChar buf[100];
2291
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"));
2310}
2311
2312static void
2313rfg2 (void)
2314{
2315 int prec;
2316 wxChar buf[100];
e9d2bb6f 2317 wxString test_format;
7aeebdcd
VZ
2318
2319 prec = 0;
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"));
2323 prec = 0;
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"));
2327 prec = 0;
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"));
2331 prec = 3;
e9d2bb6f
DS
2332 test_format = _T("%04.*o");
2333 wxSprintf (buf, test_format.c_str(), prec, 33);
7aeebdcd
VZ
2334 if (wxStrcmp (buf, _T(" 041")) != 0)
2335 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041"));
2336 prec = 7;
e9d2bb6f
DS
2337 test_format = _T("%09.*u");
2338 wxSprintf (buf, test_format.c_str(), prec, 33);
7aeebdcd
VZ
2339 if (wxStrcmp (buf, _T(" 0000033")) != 0)
2340 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033"));
2341 prec = 3;
e9d2bb6f
DS
2342 test_format = _T("%04.*x");
2343 wxSprintf (buf, test_format.c_str(), prec, 33);
7aeebdcd
VZ
2344 if (wxStrcmp (buf, _T(" 021")) != 0)
2345 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
2346 prec = 3;
e9d2bb6f
DS
2347 test_format = _T("%04.*X");
2348 wxSprintf (buf, test_format.c_str(), prec, 33);
7aeebdcd
VZ
2349 if (wxStrcmp (buf, _T(" 021")) != 0)
2350 wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
2351}
2352
2353#endif // TEST_PRINTF
2354
6dfec4b8 2355// ----------------------------------------------------------------------------
7ba4fbeb 2356// registry and related stuff
6dfec4b8
VZ
2357// ----------------------------------------------------------------------------
2358
2359// this is for MSW only
2360#ifndef __WXMSW__
7ba4fbeb 2361 #undef TEST_REGCONF
6dfec4b8
VZ
2362 #undef TEST_REGISTRY
2363#endif
2364
7ba4fbeb
VZ
2365#ifdef TEST_REGCONF
2366
e84010cf
GD
2367#include "wx/confbase.h"
2368#include "wx/msw/regconf.h"
7ba4fbeb 2369
e9d2bb6f 2370#if 0
7ba4fbeb
VZ
2371static void TestRegConfWrite()
2372{
e9d2bb6f
DS
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"));
0aa29b6b 2378}
e9d2bb6f 2379#endif
0aa29b6b
VZ
2380
2381static void TestRegConfRead()
2382{
e9d2bb6f 2383 wxConfig *config = new wxConfig(_T("myapp"));
0aa29b6b
VZ
2384
2385 wxString str;
2386 long dummy;
e9d2bb6f
DS
2387 config->SetPath(_T("/"));
2388 wxPuts(_T("Enumerating / subgroups:"));
0aa29b6b
VZ
2389 bool bCont = config->GetFirstGroup(str, dummy);
2390 while(bCont)
2391 {
e9d2bb6f 2392 wxPuts(str);
0aa29b6b
VZ
2393 bCont = config->GetNextGroup(str, dummy);
2394 }
7ba4fbeb
VZ
2395}
2396
2397#endif // TEST_REGCONF
2398
6dfec4b8
VZ
2399#ifdef TEST_REGISTRY
2400
e84010cf 2401#include "wx/msw/registry.h"
6dfec4b8
VZ
2402
2403// I chose this one because I liked its name, but it probably only exists under
2404// NT
2405static const wxChar *TESTKEY =
2406 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
2407
2408static void TestRegistryRead()
2409{
456ae26d 2410 wxPuts(_T("*** testing registry reading ***"));
6dfec4b8
VZ
2411
2412 wxRegKey key(TESTKEY);
456ae26d 2413 wxPrintf(_T("The test key name is '%s'.\n"), key.GetName().c_str());
6dfec4b8
VZ
2414 if ( !key.Open() )
2415 {
456ae26d 2416 wxPuts(_T("ERROR: test key can't be opened, aborting test."));
6dfec4b8
VZ
2417
2418 return;
2419 }
2420
2421 size_t nSubKeys, nValues;
2422 if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
2423 {
456ae26d 2424 wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys, nValues);
6dfec4b8
VZ
2425 }
2426
456ae26d 2427 wxPrintf(_T("Enumerating values:\n"));
6dfec4b8
VZ
2428
2429 long dummy;
2430 wxString value;
2431 bool cont = key.GetFirstValue(value, dummy);
2432 while ( cont )
2433 {
456ae26d 2434 wxPrintf(_T("Value '%s': type "), value.c_str());
6dfec4b8
VZ
2435 switch ( key.GetValueType(value) )
2436 {
456ae26d
VZ
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;
6dfec4b8
VZ
2444 }
2445
456ae26d 2446 wxPrintf(_T(", value = "));
6dfec4b8
VZ
2447 if ( key.IsNumericValue(value) )
2448 {
2449 long val;
2450 key.QueryValue(value, &val);
456ae26d 2451 wxPrintf(_T("%ld"), val);
6dfec4b8
VZ
2452 }
2453 else // string
2454 {
2455 wxString val;
2456 key.QueryValue(value, val);
456ae26d 2457 wxPrintf(_T("'%s'"), val.c_str());
6dfec4b8
VZ
2458
2459 key.QueryRawValue(value, val);
456ae26d 2460 wxPrintf(_T(" (raw value '%s')"), val.c_str());
6dfec4b8
VZ
2461 }
2462
e9d2bb6f 2463 wxPutchar('\n');
6dfec4b8
VZ
2464
2465 cont = key.GetNextValue(value, dummy);
2466 }
2467}
2468
6ba63600
VZ
2469static void TestRegistryAssociation()
2470{
2471 /*
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
2475 */
2476
2477 wxRegKey key;
2478
f2cb8a17 2479 key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
6ba63600 2480 key.Create();
f2cb8a17
JS
2481 key = _T("ddxf_auto_file") ;
2482 key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
6ba63600 2483 key.Create();
f2cb8a17
JS
2484 key = _T("ddxf_auto_file") ;
2485 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
6ba63600 2486 key.Create();
f2cb8a17
JS
2487 key = _T("program,0") ;
2488 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
6ba63600 2489 key.Create();
f2cb8a17 2490 key = _T("program \"%1\"") ;
6ba63600 2491
f2cb8a17 2492 key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
6ba63600 2493 key.DeleteSelf();
f2cb8a17 2494 key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
6ba63600 2495 key.DeleteSelf();
f2cb8a17 2496 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
6ba63600 2497 key.DeleteSelf();
f2cb8a17 2498 key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
6ba63600
VZ
2499 key.DeleteSelf();
2500}
2501
6dfec4b8
VZ
2502#endif // TEST_REGISTRY
2503
c66cca2a
VZ
2504// ----------------------------------------------------------------------------
2505// scope guard
2506// ----------------------------------------------------------------------------
2507
df5168c4
MB
2508#ifdef TEST_SCOPEGUARD
2509
c66cca2a
VZ
2510#include "wx/scopeguard.h"
2511
2512static void function0() { puts("function0()"); }
2513static void function1(int n) { printf("function1(%d)\n", n); }
2514static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); }
2515
2516struct Object
2517{
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); }
2521};
2522
2523static void TestScopeGuard()
2524{
24c8053b
RN
2525 wxON_BLOCK_EXIT0(function0);
2526 wxON_BLOCK_EXIT1(function1, 17);
2527 wxON_BLOCK_EXIT2(function2, 3.14, 'p');
c66cca2a
VZ
2528
2529 Object obj;
24c8053b
RN
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');
c66cca2a
VZ
2533
2534 wxScopeGuard dismissed = wxMakeGuard(function0);
2535 dismissed.Dismiss();
2536}
2537
df5168c4
MB
2538#endif
2539
2c8e4738
VZ
2540// ----------------------------------------------------------------------------
2541// sockets
2542// ----------------------------------------------------------------------------
2543
2544#ifdef TEST_SOCKETS
2545
e84010cf
GD
2546#include "wx/socket.h"
2547#include "wx/protocol/protocol.h"
2548#include "wx/protocol/http.h"
8e907a13
VZ
2549
2550static void TestSocketServer()
2551{
456ae26d 2552 wxPuts(_T("*** Testing wxSocketServer ***\n"));
8e907a13 2553
ccdb23df
VZ
2554 static const int PORT = 3000;
2555
8e907a13 2556 wxIPV4address addr;
ccdb23df 2557 addr.Service(PORT);
8e907a13
VZ
2558
2559 wxSocketServer *server = new wxSocketServer(addr);
2560 if ( !server->Ok() )
2561 {
456ae26d 2562 wxPuts(_T("ERROR: failed to bind"));
ccdb23df
VZ
2563
2564 return;
8e907a13 2565 }
8dfea369 2566
cab8f76e
VZ
2567 bool quit = false;
2568 while ( !quit )
8dfea369 2569 {
456ae26d 2570 wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT);
8dfea369
VZ
2571
2572 wxSocketBase *socket = server->Accept();
2573 if ( !socket )
2574 {
456ae26d 2575 wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
8dfea369
VZ
2576 break;
2577 }
2578
456ae26d 2579 wxPuts(_T("Server: got a client."));
8dfea369 2580
ccdb23df
VZ
2581 server->SetTimeout(60); // 1 min
2582
cab8f76e
VZ
2583 bool close = false;
2584 while ( !close && socket->IsConnected() )
8dfea369 2585 {
ccdb23df 2586 wxString s;
456ae26d 2587 wxChar ch = _T('\0');
ccdb23df 2588 for ( ;; )
8dfea369 2589 {
ccdb23df
VZ
2590 if ( socket->Read(&ch, sizeof(ch)).Error() )
2591 {
2592 // don't log error if the client just close the connection
2593 if ( socket->IsConnected() )
2594 {
456ae26d 2595 wxPuts(_T("ERROR: in wxSocket::Read."));
ccdb23df 2596 }
8dfea369 2597
ccdb23df
VZ
2598 break;
2599 }
8dfea369 2600
ccdb23df
VZ
2601 if ( ch == '\r' )
2602 continue;
8dfea369 2603
ccdb23df
VZ
2604 if ( ch == '\n' )
2605 break;
8dfea369 2606
ccdb23df
VZ
2607 s += ch;
2608 }
8dfea369 2609
ccdb23df
VZ
2610 if ( ch != '\n' )
2611 {
2612 break;
2613 }
8dfea369 2614
456ae26d 2615 wxPrintf(_T("Server: got '%s'.\n"), s.c_str());
cab8f76e 2616 if ( s == _T("close") )
ccdb23df 2617 {
cab8f76e 2618 wxPuts(_T("Closing connection"));
8dfea369 2619
cab8f76e 2620 close = true;
ccdb23df 2621 }
cab8f76e
VZ
2622 else if ( s == _T("quit") )
2623 {
2624 close =
2625 quit = true;
ccdb23df 2626
cab8f76e
VZ
2627 wxPuts(_T("Shutting down the server"));
2628 }
2629 else // not a special command
2630 {
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());
2634 }
8dfea369
VZ
2635 }
2636
cab8f76e
VZ
2637 if ( !close )
2638 {
2639 wxPuts(_T("Server: lost a client unexpectedly."));
2640 }
8dfea369 2641
ccdb23df 2642 socket->Destroy();
8dfea369 2643 }
9fc3cba7 2644
ccdb23df
VZ
2645 // same as "delete server" but is consistent with GUI programs
2646 server->Destroy();
8e907a13 2647}
2c8e4738
VZ
2648
2649static void TestSocketClient()
2650{
456ae26d 2651 wxPuts(_T("*** Testing wxSocketClient ***\n"));
2c8e4738 2652
be5a51fb 2653 static const wxChar *hostname = _T("www.wxwidgets.org");
8e907a13
VZ
2654
2655 wxIPV4address addr;
2656 addr.Hostname(hostname);
2657 addr.Service(80);
2658
456ae26d 2659 wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname);
2c8e4738
VZ
2660
2661 wxSocketClient client;
8e907a13 2662 if ( !client.Connect(addr) )
2c8e4738 2663 {
456ae26d 2664 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
2c8e4738
VZ
2665 }
2666 else
2667 {
456ae26d 2668 wxPrintf(_T("--- Connected to %s:%u...\n"),
8e907a13
VZ
2669 addr.Hostname().c_str(), addr.Service());
2670
456ae26d 2671 wxChar buf[8192];
2c8e4738 2672
8e907a13
VZ
2673 // could use simply "GET" here I suppose
2674 wxString cmdGet =
456ae26d 2675 wxString::Format(_T("GET http://%s/\r\n"), hostname);
8e907a13 2676 client.Write(cmdGet, cmdGet.length());
456ae26d 2677 wxPrintf(_T("--- Sent command '%s' to the server\n"),
8e907a13 2678 MakePrintable(cmdGet).c_str());
2c8e4738 2679 client.Read(buf, WXSIZEOF(buf));
456ae26d 2680 wxPrintf(_T("--- Server replied:\n%s"), buf);
8e907a13
VZ
2681 }
2682}
2683
2e907fab
VZ
2684#endif // TEST_SOCKETS
2685
b92fd37c
VZ
2686// ----------------------------------------------------------------------------
2687// FTP
2688// ----------------------------------------------------------------------------
2689
2e907fab
VZ
2690#ifdef TEST_FTP
2691
e84010cf 2692#include "wx/protocol/ftp.h"
2e907fab 2693
b92fd37c
VZ
2694static wxFTP ftp;
2695
2696#define FTP_ANONYMOUS
2697
2698#ifdef FTP_ANONYMOUS
456ae26d
VZ
2699 static const wxChar *directory = _T("/pub");
2700 static const wxChar *filename = _T("welcome.msg");
b92fd37c 2701#else
456ae26d
VZ
2702 static const wxChar *directory = _T("/etc");
2703 static const wxChar *filename = _T("issue");
b92fd37c
VZ
2704#endif
2705
2706static bool TestFtpConnect()
8e907a13 2707{
456ae26d 2708 wxPuts(_T("*** Testing FTP connect ***"));
8e907a13 2709
b92fd37c 2710#ifdef FTP_ANONYMOUS
be5a51fb 2711 static const wxChar *hostname = _T("ftp.wxwidgets.org");
b92fd37c 2712
456ae26d 2713 wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
b92fd37c 2714#else // !FTP_ANONYMOUS
456ae26d 2715 static const wxChar *hostname = "localhost";
b92fd37c 2716
456ae26d
VZ
2717 wxChar user[256];
2718 wxFgets(user, WXSIZEOF(user), stdin);
2719 user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
b92fd37c
VZ
2720 ftp.SetUser(user);
2721
456ae26d
VZ
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'
b92fd37c
VZ
2726 ftp.SetPassword(password);
2727
456ae26d 2728 wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname, user);
b92fd37c
VZ
2729#endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
2730
2731 if ( !ftp.Connect(hostname) )
2732 {
456ae26d 2733 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
b92fd37c 2734
cab8f76e 2735 return false;
b92fd37c
VZ
2736 }
2737 else
2738 {
456ae26d 2739 wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
af33b199
VZ
2740 hostname, ftp.Pwd().c_str());
2741 ftp.Close();
b92fd37c
VZ
2742 }
2743
cab8f76e 2744 return true;
b92fd37c 2745}
b1229561 2746
b92fd37c
VZ
2747// test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
2748static void TestFtpWuFtpd()
2749{
2750 wxFTP ftp;
456ae26d 2751 static const wxChar *hostname = _T("ftp.eudora.com");
b1229561
VZ
2752 if ( !ftp.Connect(hostname) )
2753 {
456ae26d 2754 wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
b1229561
VZ
2755 }
2756 else
2757 {
456ae26d 2758 static const wxChar *filename = _T("eudora/pubs/draft-gellens-submit-09.txt");
b1229561
VZ
2759 wxInputStream *in = ftp.GetInputStream(filename);
2760 if ( !in )
2761 {
456ae26d 2762 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
b1229561
VZ
2763 }
2764 else
2765 {
4c51b688 2766 size_t size = in->GetSize();
456ae26d 2767 wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
b1229561 2768
456ae26d 2769 wxChar *data = new wxChar[size];
b1229561
VZ
2770 if ( !in->Read(data, size) )
2771 {
456ae26d 2772 wxPuts(_T("ERROR: read error"));
b1229561
VZ
2773 }
2774 else
2775 {
456ae26d 2776 wxPrintf(_T("Successfully retrieved the file.\n"));
b1229561
VZ
2777 }
2778
2779 delete [] data;
2780 delete in;
2781 }
2782 }
b92fd37c 2783}
b1229561 2784
b92fd37c
VZ
2785static void TestFtpList()
2786{
456ae26d 2787 wxPuts(_T("*** Testing wxFTP file listing ***\n"));
8e907a13 2788
b92fd37c
VZ
2789 // test CWD
2790 if ( !ftp.ChDir(directory) )
2791 {
456ae26d 2792 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
b92fd37c 2793 }
2e907fab 2794
456ae26d 2795 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
2e907fab 2796
b92fd37c
VZ
2797 // test NLIST and LIST
2798 wxArrayString files;
2799 if ( !ftp.GetFilesList(files) )
8e907a13 2800 {
456ae26d 2801 wxPuts(_T("ERROR: failed to get NLIST of files"));
8e907a13
VZ
2802 }
2803 else
2804 {
456ae26d 2805 wxPrintf(_T("Brief list of files under '%s':\n"), ftp.Pwd().c_str());
b92fd37c
VZ
2806 size_t count = files.GetCount();
2807 for ( size_t n = 0; n < count; n++ )
8e907a13 2808 {
456ae26d 2809 wxPrintf(_T("\t%s\n"), files[n].c_str());
8e907a13 2810 }
456ae26d 2811 wxPuts(_T("End of the file list"));
b92fd37c 2812 }
8e907a13 2813
b92fd37c
VZ
2814 if ( !ftp.GetDirList(files) )
2815 {
456ae26d 2816 wxPuts(_T("ERROR: failed to get LIST of files"));
b92fd37c
VZ
2817 }
2818 else
2819 {
456ae26d 2820 wxPrintf(_T("Detailed list of files under '%s':\n"), ftp.Pwd().c_str());
b92fd37c
VZ
2821 size_t count = files.GetCount();
2822 for ( size_t n = 0; n < count; n++ )
8e907a13 2823 {
456ae26d 2824 wxPrintf(_T("\t%s\n"), files[n].c_str());
2e907fab 2825 }
456ae26d 2826 wxPuts(_T("End of the file list"));
b92fd37c
VZ
2827 }
2828
2829 if ( !ftp.ChDir(_T("..")) )
2830 {
456ae26d 2831 wxPuts(_T("ERROR: failed to cd to .."));
b92fd37c 2832 }
2e907fab 2833
456ae26d 2834 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
b92fd37c
VZ
2835}
2836
2837static void TestFtpDownload()
2838{
456ae26d 2839 wxPuts(_T("*** Testing wxFTP download ***\n"));
b92fd37c
VZ
2840
2841 // test RETR
2842 wxInputStream *in = ftp.GetInputStream(filename);
2843 if ( !in )
2844 {
456ae26d 2845 wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
b92fd37c
VZ
2846 }
2847 else
2848 {
4c51b688 2849 size_t size = in->GetSize();
456ae26d 2850 wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
b92fd37c
VZ
2851 fflush(stdout);
2852
456ae26d 2853 wxChar *data = new wxChar[size];
b92fd37c 2854 if ( !in->Read(data, size) )
2e907fab 2855 {
456ae26d 2856 wxPuts(_T("ERROR: read error"));
2e907fab
VZ
2857 }
2858 else
2859 {
456ae26d 2860 wxPrintf(_T("\nContents of %s:\n%s\n"), filename, data);
8e907a13
VZ
2861 }
2862
b92fd37c
VZ
2863 delete [] data;
2864 delete in;
2865 }
2866}
8e907a13 2867
b92fd37c
VZ
2868static void TestFtpFileSize()
2869{
456ae26d 2870 wxPuts(_T("*** Testing FTP SIZE command ***"));
b92fd37c
VZ
2871
2872 if ( !ftp.ChDir(directory) )
2873 {
456ae26d 2874 wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
b92fd37c
VZ
2875 }
2876
456ae26d 2877 wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
b92fd37c
VZ
2878
2879 if ( ftp.FileExists(filename) )
2880 {
2881 int size = ftp.GetFileSize(filename);
2882 if ( size == -1 )
456ae26d 2883 wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename);
8e907a13 2884 else
456ae26d 2885 wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename, size);
b92fd37c
VZ
2886 }
2887 else
2888 {
456ae26d 2889 wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename);
b92fd37c
VZ
2890 }
2891}
2892
2893static void TestFtpMisc()
2894{
456ae26d 2895 wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
b92fd37c 2896
f2cb8a17 2897 if ( ftp.SendCommand(_T("STAT")) != '2' )
b92fd37c 2898 {
456ae26d 2899 wxPuts(_T("ERROR: STAT failed"));
b92fd37c
VZ
2900 }
2901 else
2902 {
456ae26d 2903 wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str());
b92fd37c
VZ
2904 }
2905
f2cb8a17 2906 if ( ftp.SendCommand(_T("HELP SITE")) != '2' )
b92fd37c 2907 {
456ae26d 2908 wxPuts(_T("ERROR: HELP SITE failed"));
b92fd37c
VZ
2909 }
2910 else
2911 {
456ae26d 2912 wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
b92fd37c
VZ
2913 ftp.GetLastResult().c_str());
2914 }
2915}
2916
2917static void TestFtpInteractive()
2918{
456ae26d 2919 wxPuts(_T("\n*** Interactive wxFTP test ***"));
b92fd37c 2920
456ae26d 2921 wxChar buf[128];
b92fd37c
VZ
2922
2923 for ( ;; )
2924 {
456ae26d
VZ
2925 wxPrintf(_T("Enter FTP command: "));
2926 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
b92fd37c
VZ
2927 break;
2928
2929 // kill the last '\n'
456ae26d 2930 buf[wxStrlen(buf) - 1] = 0;
b92fd37c
VZ
2931
2932 // special handling of LIST and NLST as they require data connection
2933 wxString start(buf, 4);
2934 start.MakeUpper();
f2cb8a17 2935 if ( start == _T("LIST") || start == _T("NLST") )
8e907a13 2936 {
b92fd37c 2937 wxString wildcard;
456ae26d 2938 if ( wxStrlen(buf) > 4 )
b92fd37c 2939 wildcard = buf + 5;
8e907a13 2940
b92fd37c 2941 wxArrayString files;
f2cb8a17 2942 if ( !ftp.GetList(files, wildcard, start == _T("LIST")) )
8e907a13 2943 {
456ae26d 2944 wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str());
8e907a13
VZ
2945 }
2946 else
2947 {
456ae26d 2948 wxPrintf(_T("--- %s of '%s' under '%s':\n"),
b92fd37c
VZ
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++ )
2952 {
456ae26d 2953 wxPrintf(_T("\t%s\n"), files[n].c_str());
b92fd37c 2954 }
456ae26d 2955 wxPuts(_T("--- End of the file list"));
8e907a13 2956 }
2e907fab 2957 }
b92fd37c 2958 else // !list
2e907fab 2959 {
456ae26d
VZ
2960 wxChar ch = ftp.SendCommand(buf);
2961 wxPrintf(_T("Command %s"), ch ? _T("succeeded") : _T("failed"));
b92fd37c
VZ
2962 if ( ch )
2963 {
456ae26d 2964 wxPrintf(_T(" (return code %c)"), ch);
b92fd37c 2965 }
2e907fab 2966
456ae26d 2967 wxPrintf(_T(", server reply:\n%s\n\n"), ftp.GetLastResult().c_str());
2e907fab 2968 }
2c8e4738 2969 }
b92fd37c 2970
456ae26d 2971 wxPuts(_T("\n*** done ***"));
2c8e4738
VZ
2972}
2973
b92fd37c 2974static void TestFtpUpload()
f6bcfd97 2975{
456ae26d 2976 wxPuts(_T("*** Testing wxFTP uploading ***\n"));
f6bcfd97 2977
b92fd37c 2978 // upload a file
456ae26d
VZ
2979 static const wxChar *file1 = _T("test1");
2980 static const wxChar *file2 = _T("test2");
b92fd37c
VZ
2981 wxOutputStream *out = ftp.GetOutputStream(file1);
2982 if ( out )
2983 {
456ae26d 2984 wxPrintf(_T("--- Uploading to %s ---\n"), file1);
b92fd37c
VZ
2985 out->Write("First hello", 11);
2986 delete out;
2987 }
f6bcfd97 2988
b92fd37c 2989 // send a command to check the remote file
f2cb8a17 2990 if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' )
f6bcfd97 2991 {
456ae26d 2992 wxPrintf(_T("ERROR: STAT %s failed\n"), file1);
f6bcfd97
BP
2993 }
2994 else
2995 {
456ae26d 2996 wxPrintf(_T("STAT %s returned:\n\n%s\n"),
b92fd37c
VZ
2997 file1, ftp.GetLastResult().c_str());
2998 }
2e907fab 2999
b92fd37c
VZ
3000 out = ftp.GetOutputStream(file2);
3001 if ( out )
3002 {
456ae26d 3003 wxPrintf(_T("--- Uploading to %s ---\n"), file1);
b92fd37c
VZ
3004 out->Write("Second hello", 12);
3005 delete out;
f6bcfd97
BP
3006 }
3007}
3008
2e907fab 3009#endif // TEST_FTP
2c8e4738 3010
af33b199
VZ
3011// ----------------------------------------------------------------------------
3012// standard paths
3013// ----------------------------------------------------------------------------
3014
3015#ifdef TEST_STDPATHS
3016
3017#include "wx/stdpaths.h"
3018
3019static void TestStandardPaths()
3020{
3021 wxPuts(_T("*** Testing wxStandardPaths ***\n"));
3022
3023 wxTheApp->SetAppName(_T("console"));
3024
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());
3033}
3034
3035#endif // TEST_STDPATHS
3036
83141d3a
VZ
3037// ----------------------------------------------------------------------------
3038// streams
3039// ----------------------------------------------------------------------------
3040
3041#ifdef TEST_STREAMS
3042
e84010cf
GD
3043#include "wx/wfstream.h"
3044#include "wx/mstream.h"
83141d3a 3045
24f25c8a
VZ
3046static void TestFileStream()
3047{
456ae26d 3048 wxPuts(_T("*** Testing wxFileInputStream ***"));
24f25c8a 3049
e9d2bb6f 3050 static const wxString filename = _T("testdata.fs");
24f25c8a
VZ
3051 {
3052 wxFileOutputStream fsOut(filename);
3053 fsOut.Write("foo", 3);
3054 }
3055
3056 wxFileInputStream fsIn(filename);
456ae26d 3057 wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
24f25c8a
VZ
3058 while ( !fsIn.Eof() )
3059 {
e9d2bb6f 3060 wxPutchar(fsIn.GetC());
24f25c8a
VZ
3061 }
3062
3063 if ( !wxRemoveFile(filename) )
3064 {
e9d2bb6f 3065 wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str());
24f25c8a
VZ
3066 }
3067
456ae26d 3068 wxPuts(_T("\n*** wxFileInputStream test done ***"));
24f25c8a
VZ
3069}
3070
83141d3a
VZ
3071static void TestMemoryStream()
3072{
99a5af7f
VZ
3073 wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
3074
3075 wxMemoryOutputStream memOutStream;
3076 wxPrintf(_T("Initially out stream offset: %lu\n"),
3077 (unsigned long)memOutStream.TellO());
3078
3079 for ( const wxChar *p = _T("Hello, stream!"); *p; p++ )
3080 {
3081 memOutStream.PutC(*p);
3082 }
3083
3084 wxPrintf(_T("Final out stream offset: %lu\n"),
3085 (unsigned long)memOutStream.TellO());
3086
3087 wxPuts(_T("*** Testing wxMemoryInputStream ***"));
83141d3a
VZ
3088
3089 wxChar buf[1024];
99a5af7f 3090 size_t len = memOutStream.CopyTo(buf, WXSIZEOF(buf));
83141d3a 3091
99a5af7f
VZ
3092 wxMemoryInputStream memInpStream(buf, len);
3093 wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
83141d3a
VZ
3094 while ( !memInpStream.Eof() )
3095 {
e9d2bb6f 3096 wxPutchar(memInpStream.GetC());
83141d3a
VZ
3097 }
3098
456ae26d 3099 wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
83141d3a
VZ
3100}
3101
3102#endif // TEST_STREAMS
3103
d31b7b68
VZ
3104// ----------------------------------------------------------------------------
3105// timers
3106// ----------------------------------------------------------------------------
3107
3108#ifdef TEST_TIMER
3109
e84010cf
GD
3110#include "wx/timer.h"
3111#include "wx/utils.h"
d31b7b68
VZ
3112
3113static void TestStopWatch()
3114{
456ae26d 3115 wxPuts(_T("*** Testing wxStopWatch ***\n"));
d31b7b68
VZ
3116
3117 wxStopWatch sw;
677eff07 3118 sw.Pause();
456ae26d 3119 wxPrintf(_T("Initially paused, after 2 seconds time is..."));
677eff07
VZ
3120 fflush(stdout);
3121 wxSleep(2);
456ae26d 3122 wxPrintf(_T("\t%ldms\n"), sw.Time());
677eff07 3123
456ae26d 3124 wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
677eff07
VZ
3125 fflush(stdout);
3126 sw.Resume();
d31b7b68 3127 wxSleep(3);
456ae26d 3128 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
d31b7b68
VZ
3129
3130 sw.Pause();
456ae26d 3131 wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
677eff07 3132 fflush(stdout);
d31b7b68 3133 wxSleep(2);
456ae26d 3134 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
d31b7b68
VZ
3135
3136 sw.Resume();
456ae26d 3137 wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
677eff07
VZ
3138 fflush(stdout);
3139 wxSleep(2);
456ae26d 3140 wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
87798c00
VZ
3141
3142 wxStopWatch sw2;
456ae26d 3143 wxPuts(_T("\nChecking for 'backwards clock' bug..."));
87798c00
VZ
3144 for ( size_t n = 0; n < 70; n++ )
3145 {
3146 sw2.Start();
89e6463c
GRG
3147
3148 for ( size_t m = 0; m < 100000; m++ )
87798c00 3149 {
89e6463c
GRG
3150 if ( sw.Time() < 0 || sw2.Time() < 0 )
3151 {
456ae26d 3152 wxPuts(_T("\ntime is negative - ERROR!"));
89e6463c 3153 }
87798c00
VZ
3154 }
3155
e9d2bb6f 3156 wxPutchar('.');
677eff07 3157 fflush(stdout);
87798c00
VZ
3158 }
3159
456ae26d 3160 wxPuts(_T(", ok."));
d31b7b68
VZ
3161}
3162
3163#endif // TEST_TIMER
3164
f6bcfd97
BP
3165// ----------------------------------------------------------------------------
3166// vCard support
3167// ----------------------------------------------------------------------------
3168
3169#ifdef TEST_VCARD
3170
e84010cf 3171#include "wx/vcard.h"
f6bcfd97
BP
3172
3173static void DumpVObject(size_t level, const wxVCardObject& vcard)
3174{
3175 void *cookie;
3176 wxVCardObject *vcObj = vcard.GetFirstProp(&cookie);
3177 while ( vcObj )
3178 {
456ae26d 3179 wxPrintf(_T("%s%s"),
f6bcfd97
BP
3180 wxString(_T('\t'), level).c_str(),
3181 vcObj->GetName().c_str());
3182
3183 wxString value;
3184 switch ( vcObj->GetType() )
3185 {
3186 case wxVCardObject::String:
3187 case wxVCardObject::UString:
3188 {
3189 wxString val;
3190 vcObj->GetValue(&val);
3191 value << _T('"') << val << _T('"');
3192 }
3193 break;
3194
3195 case wxVCardObject::Int:
3196 {
3197 unsigned int i;
3198 vcObj->GetValue(&i);
3199 value.Printf(_T("%u"), i);
3200 }
3201 break;
3202
3203 case wxVCardObject::Long:
3204 {
3205 unsigned long l;
3206 vcObj->GetValue(&l);
3207 value.Printf(_T("%lu"), l);
3208 }
3209 break;
3210
3211 case wxVCardObject::None:
3212 break;
3213
3214 case wxVCardObject::Object:
3215 value = _T("<node>");
3216 break;
3217
3218 default:
3219 value = _T("<unknown value type>");
3220 }
3221
3222 if ( !!value )
456ae26d 3223 wxPrintf(_T(" = %s"), value.c_str());
e9d2bb6f 3224 wxPutchar('\n');
f6bcfd97
BP
3225
3226 DumpVObject(level + 1, *vcObj);
3227
3228 delete vcObj;
3229 vcObj = vcard.GetNextProp(&cookie);
3230 }
3231}
3232
3233static void DumpVCardAddresses(const wxVCard& vcard)
3234{
456ae26d 3235 wxPuts(_T("\nShowing all addresses from vCard:\n"));
f6bcfd97
BP
3236
3237 size_t nAdr = 0;
3238 void *cookie;
3239 wxVCardAddress *addr = vcard.GetFirstAddress(&cookie);
3240 while ( addr )
3241 {
3242 wxString flagsStr;
3243 int flags = addr->GetFlags();
3244 if ( flags & wxVCardAddress::Domestic )
3245 {
3246 flagsStr << _T("domestic ");
3247 }
3248 if ( flags & wxVCardAddress::Intl )
3249 {
3250 flagsStr << _T("international ");
3251 }
3252 if ( flags & wxVCardAddress::Postal )
3253 {
3254 flagsStr << _T("postal ");
3255 }
3256 if ( flags & wxVCardAddress::Parcel )
3257 {
3258 flagsStr << _T("parcel ");
3259 }
3260 if ( flags & wxVCardAddress::Home )
3261 {
3262 flagsStr << _T("home ");
3263 }
3264 if ( flags & wxVCardAddress::Work )
3265 {
3266 flagsStr << _T("work ");
3267 }
3268
456ae26d 3269 wxPrintf(_T("Address %u:\n")
f6bcfd97
BP
3270 "\tflags = %s\n"
3271 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
3272 ++nAdr,
3273 flagsStr.c_str(),
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()
3281 );
3282
3283 delete addr;
3284 addr = vcard.GetNextAddress(&cookie);
3285 }
3286}
3287
3288static void DumpVCardPhoneNumbers(const wxVCard& vcard)
3289{
456ae26d 3290 wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
f6bcfd97
BP
3291
3292 size_t nPhone = 0;
3293 void *cookie;
3294 wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie);
3295 while ( phone )
3296 {
3297 wxString flagsStr;
3298 int flags = phone->GetFlags();
3299 if ( flags & wxVCardPhoneNumber::Voice )
3300 {
3301 flagsStr << _T("voice ");
3302 }
3303 if ( flags & wxVCardPhoneNumber::Fax )
3304 {
3305 flagsStr << _T("fax ");
3306 }
3307 if ( flags & wxVCardPhoneNumber::Cellular )
3308 {
3309 flagsStr << _T("cellular ");
3310 }
3311 if ( flags & wxVCardPhoneNumber::Modem )
3312 {
3313 flagsStr << _T("modem ");
3314 }
3315 if ( flags & wxVCardPhoneNumber::Home )
3316 {
3317 flagsStr << _T("home ");
3318 }
3319 if ( flags & wxVCardPhoneNumber::Work )
3320 {
3321 flagsStr << _T("work ");
3322 }
3323
456ae26d 3324 wxPrintf(_T("Phone number %u:\n")
f6bcfd97
BP
3325 "\tflags = %s\n"
3326 "\tvalue = %s\n",
3327 ++nPhone,
3328 flagsStr.c_str(),
3329 phone->GetNumber().c_str()
3330 );
3331
3332 delete phone;
3333 phone = vcard.GetNextPhoneNumber(&cookie);
3334 }
3335}
3336
3337static void TestVCardRead()
3338{
456ae26d 3339 wxPuts(_T("*** Testing wxVCard reading ***\n"));
f6bcfd97
BP
3340
3341 wxVCard vcard(_T("vcard.vcf"));
3342 if ( !vcard.IsOk() )
3343 {
456ae26d 3344 wxPuts(_T("ERROR: couldn't load vCard."));
f6bcfd97
BP
3345 }
3346 else
3347 {
3348 // read individual vCard properties
3349 wxVCardObject *vcObj = vcard.GetProperty("FN");
3350 wxString value;
3351 if ( vcObj )
3352 {
3353 vcObj->GetValue(&value);
3354 delete vcObj;
3355 }
3356 else
3357 {
3358 value = _T("<none>");
3359 }
3360
456ae26d 3361 wxPrintf(_T("Full name retrieved directly: %s\n"), value.c_str());
f6bcfd97
BP
3362
3363
3364 if ( !vcard.GetFullName(&value) )
3365 {
3366 value = _T("<none>");
3367 }
3368
456ae26d 3369 wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
f6bcfd97
BP
3370
3371 // now show how to deal with multiply occuring properties
3372 DumpVCardAddresses(vcard);
3373 DumpVCardPhoneNumbers(vcard);
3374
3375 // and finally show all
456ae26d 3376 wxPuts(_T("\nNow dumping the entire vCard:\n")
f6bcfd97
BP
3377 "-----------------------------\n");
3378
3379 DumpVObject(0, vcard);
3380 }
3381}
3382
3383static void TestVCardWrite()
3384{
456ae26d 3385 wxPuts(_T("*** Testing wxVCard writing ***\n"));
f6bcfd97
BP
3386
3387 wxVCard vcard;
3388 if ( !vcard.IsOk() )
3389 {
456ae26d 3390 wxPuts(_T("ERROR: couldn't create vCard."));
f6bcfd97
BP
3391 }
3392 else
3393 {
3394 // set some fields
3395 vcard.SetName("Zeitlin", "Vadim");
3396 vcard.SetFullName("Vadim Zeitlin");
be5a51fb 3397 vcard.SetOrganization("wxWidgets", "R&D");
f6bcfd97
BP
3398
3399 // just dump the vCard back
456ae26d
VZ
3400 wxPuts(_T("Entire vCard follows:\n"));
3401 wxPuts(vcard.Write());
f6bcfd97
BP
3402 }
3403}
3404
3405#endif // TEST_VCARD
3406
0e2c5534
VZ
3407// ----------------------------------------------------------------------------
3408// wxVolume tests
3409// ----------------------------------------------------------------------------
3410
ba6ea19e 3411#if !defined(__WIN32__) || !wxUSE_FSVOLUME
0e2c5534
VZ
3412 #undef TEST_VOLUME
3413#endif
3414
3415#ifdef TEST_VOLUME
3416
3417#include "wx/volume.h"
3418
3419static const wxChar *volumeKinds[] =
3420{
3421 _T("floppy"),
3422 _T("hard disk"),
3423 _T("CD-ROM"),
3424 _T("DVD-ROM"),
3425 _T("network volume"),
3426 _T("other volume"),
3427};
3428
3429static void TestFSVolume()
3430{
3431 wxPuts(_T("*** Testing wxFSVolume class ***"));
3432
3433 wxArrayString volumes = wxFSVolume::GetVolumes();
3434 size_t count = volumes.GetCount();
3435
3436 if ( !count )
3437 {
3438 wxPuts(_T("ERROR: no mounted volumes?"));
3439 return;
3440 }
3441
3442 wxPrintf(_T("%u mounted volumes found:\n"), count);
3443
3444 for ( size_t n = 0; n < count; n++ )
3445 {
3446 wxFSVolume vol(volumes[n]);
3447 if ( !vol.IsOk() )
3448 {
3449 wxPuts(_T("ERROR: couldn't create volume"));
3450 continue;
3451 }
3452
3453 wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
3454 n + 1,
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")
3460 : _T("fixed"));
3461 }
3462}
3463
3464#endif // TEST_VOLUME
3465
f6bcfd97 3466// ----------------------------------------------------------------------------
e7d41190 3467// wide char and Unicode support
f6bcfd97
BP
3468// ----------------------------------------------------------------------------
3469
3470#ifdef TEST_WCHAR
3471
e84010cf
GD
3472#include "wx/strconv.h"
3473#include "wx/fontenc.h"
3474#include "wx/encconv.h"
3475#include "wx/buffer.h"
f6bcfd97 3476
2b5f62a0 3477static const unsigned char utf8koi8r[] =
ac511156
VZ
3478{
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
3486};
3487
2b5f62a0
VZ
3488static const unsigned char utf8iso8859_1[] =
3489{
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
3495};
3496
3497static const unsigned char utf8Invalid[] =
3498{
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,
3503 0x6c, 0x61, 0x79, 0
3504};
3505
3506static const struct Utf8Data
3507{
3508 const unsigned char *text;
3509 size_t len;
3510 const wxChar *charset;
3511 wxFontEncoding encoding;
3512} utf8data[] =
3513{
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 },
3517};
456ae26d 3518
f6bcfd97
BP
3519static void TestUtf8()
3520{
456ae26d 3521 wxPuts(_T("*** Testing UTF8 support ***\n"));
f6bcfd97 3522
24f25c8a
VZ
3523 char buf[1024];
3524 wchar_t wbuf[1024];
2b5f62a0
VZ
3525
3526 for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
24f25c8a 3527 {
2b5f62a0
VZ
3528 const Utf8Data& u8d = utf8data[n];
3529 if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text,
3530 WXSIZEOF(wbuf)) == (size_t)-1 )
24f25c8a 3531 {
2b5f62a0 3532 wxPuts(_T("ERROR: UTF-8 decoding failed."));
24f25c8a
VZ
3533 }
3534 else
ac511156 3535 {
2b5f62a0
VZ
3536 wxCSConv conv(u8d.charset);
3537 if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 )
3538 {
3539 wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d.charset);
3540 }
3541 else
3542 {
3543 wxPrintf(_T("String in %s: %s\n"), u8d.charset, buf);
3544 }
ac511156 3545 }
ac511156 3546
5bc1deeb 3547 wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
2b5f62a0
VZ
3548 if ( s.empty() )
3549 s = _T("<< conversion failed >>");
3550 wxPrintf(_T("String in current cset: %s\n"), s.c_str());
3551
ac511156
VZ
3552 }
3553
e9d2bb6f 3554 wxPuts(wxEmptyString);
ac511156 3555}
f6bcfd97 3556
ac511156
VZ
3557static void TestEncodingConverter()
3558{
3559 wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
3560
3561 // using wxEncodingConverter should give the same result as above
3562 char buf[1024];
3563 wchar_t wbuf[1024];
2b5f62a0
VZ
3564 if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r,
3565 WXSIZEOF(utf8koi8r)) == (size_t)-1 )
ac511156 3566 {
456ae26d 3567 wxPuts(_T("ERROR: UTF-8 decoding failed."));
ac511156
VZ
3568 }
3569 else
3570 {
3571 wxEncodingConverter ec;
3572 ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
3573 ec.Convert(wbuf, buf);
2b5f62a0 3574 wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf);
24f25c8a 3575 }
ac511156 3576
e9d2bb6f 3577 wxPuts(wxEmptyString);
f6bcfd97
BP
3578}
3579
3580#endif // TEST_WCHAR
3581
3582// ----------------------------------------------------------------------------
3583// ZIP stream
3584// ----------------------------------------------------------------------------
3585
3586#ifdef TEST_ZIP
3587
2ca8b884
VZ
3588#include "wx/filesys.h"
3589#include "wx/fs_zip.h"
f6bcfd97
BP
3590#include "wx/zipstrm.h"
3591
2ca8b884
VZ
3592static const wxChar *TESTFILE_ZIP = _T("testdata.zip");
3593
f6bcfd97
BP
3594static void TestZipStreamRead()
3595{
456ae26d 3596 wxPuts(_T("*** Testing ZIP reading ***\n"));
f6bcfd97 3597
e9d2bb6f 3598 static const wxString filename = _T("foo");
2ca8b884 3599 wxZipInputStream istr(TESTFILE_ZIP, filename);
456ae26d 3600 wxPrintf(_T("Archive size: %u\n"), istr.GetSize());
f6bcfd97 3601
e9d2bb6f 3602 wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str());
f6bcfd97
BP
3603 while ( !istr.Eof() )
3604 {
e9d2bb6f 3605 wxPutchar(istr.GetC());
f6bcfd97
BP
3606 fflush(stdout);
3607 }
3608
456ae26d 3609 wxPuts(_T("\n----- done ------"));
f6bcfd97
BP
3610}
3611
2ca8b884
VZ
3612static void DumpZipDirectory(wxFileSystem& fs,
3613 const wxString& dir,
3614 const wxString& indent)
3615{
3616 wxString prefix = wxString::Format(_T("%s#zip:%s"),
3617 TESTFILE_ZIP, dir.c_str());
3618 wxString wildcard = prefix + _T("/*");
3619
3620 wxString dirname = fs.FindFirst(wildcard, wxDIR);
3621 while ( !dirname.empty() )
3622 {
3623 if ( !dirname.StartsWith(prefix + _T('/'), &dirname) )
3624 {
3625 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3626
3627 break;
3628 }
3629
3630 wxPrintf(_T("%s%s\n"), indent.c_str(), dirname.c_str());
3631
3632 DumpZipDirectory(fs, dirname,
3633 indent + wxString(_T(' '), 4));
3634
3635 dirname = fs.FindNext();
3636 }
3637
3638 wxString filename = fs.FindFirst(wildcard, wxFILE);
3639 while ( !filename.empty() )
3640 {
3641 if ( !filename.StartsWith(prefix, &filename) )
3642 {
3643 wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
3644
3645 break;
3646 }
3647
3648 wxPrintf(_T("%s%s\n"), indent.c_str(), filename.c_str());
3649
3650 filename = fs.FindNext();
3651 }
3652}
3653
3654static void TestZipFileSystem()
3655{
456ae26d 3656 wxPuts(_T("*** Testing ZIP file system ***\n"));
2ca8b884
VZ
3657
3658 wxFileSystem::AddHandler(new wxZipFSHandler);
3659 wxFileSystem fs;
3660 wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP);
3661
3662 DumpZipDirectory(fs, _T(""), wxString(_T(' '), 4));
3663}
3664
f6bcfd97
BP
3665#endif // TEST_ZIP
3666
b76b015e
VZ
3667// ----------------------------------------------------------------------------
3668// date time
3669// ----------------------------------------------------------------------------
3670
d31b7b68 3671#ifdef TEST_DATETIME
b76b015e 3672
551fe3a6
VZ
3673#include <math.h>
3674
e84010cf 3675#include "wx/datetime.h"
b76b015e 3676
2f02cb89 3677// this test miscellaneous static wxDateTime functions
4b586201
WS
3678
3679#if TEST_ALL
3680
2f02cb89
VZ
3681static void TestTimeStatic()
3682{
456ae26d 3683 wxPuts(_T("\n*** wxDateTime static methods test ***"));
2f02cb89
VZ
3684
3685 // some info about the current date
3686 int year = wxDateTime::GetCurrentYear();
456ae26d 3687 wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
2f02cb89
VZ
3688 year,
3689 wxDateTime::IsLeapYear(year) ? "" : "not ",
3690 wxDateTime::GetNumberOfDays(year));
3691
3692 wxDateTime::Month month = wxDateTime::GetCurrentMonth();
456ae26d 3693 wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
f0f951fa 3694 wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
2f02cb89
VZ
3695 wxDateTime::GetMonthName(month).c_str(),
3696 wxDateTime::GetNumberOfDays(month));
2f02cb89
VZ
3697}
3698
fcc3d7cb
VZ
3699// test time zones stuff
3700static void TestTimeZones()
3701{
456ae26d 3702 wxPuts(_T("\n*** wxDateTime timezone test ***"));
fcc3d7cb
VZ
3703
3704 wxDateTime now = wxDateTime::Now();
3705
456ae26d
VZ
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());
9d9b7755 3712
ccd6aacd
VZ
3713 wxPrintf(_T("%s\n"), wxDateTime::Now().Format(_T("Our timezone is %Z")).c_str());
3714
9d9b7755
VZ
3715 wxDateTime::Tm tm = now.GetTm();
3716 if ( wxDateTime(tm) != now )
3717 {
456ae26d
VZ
3718 wxPrintf(_T("ERROR: got %s instead of %s\n"),
3719 wxDateTime(tm).Format().c_str(), now.Format().c_str());
9d9b7755 3720 }
fcc3d7cb
VZ
3721}
3722
e6ec579c
VZ
3723// test some minimal support for the dates outside the standard range
3724static void TestTimeRange()
3725{
456ae26d 3726 wxPuts(_T("\n*** wxDateTime out-of-standard-range dates test ***"));
e6ec579c 3727
456ae26d 3728 static const wxChar *fmt = _T("%d-%b-%Y %H:%M:%S");
211c2250 3729
456ae26d
VZ
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());
e6ec579c
VZ
3740}
3741
239446b4
VZ
3742// test DST calculations
3743static void TestTimeDST()
3744{
456ae26d 3745 wxPuts(_T("\n*** wxDateTime DST test ***"));
239446b4 3746
456ae26d 3747 wxPrintf(_T("DST is%s in effect now.\n\n"),
e9d2bb6f 3748 wxDateTime::Now().IsDST() ? wxEmptyString : _T(" not"));
239446b4 3749
ccd6aacd 3750 for ( int year = 1990; year < 2005; year++ )
239446b4 3751 {
456ae26d
VZ
3752 wxPrintf(_T("DST period in Europe for year %d: from %s to %s\n"),
3753 year,
3754 wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
3755 wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
239446b4
VZ
3756 }
3757}
3758
4b586201
WS
3759#endif // TEST_ALL
3760
3761#if TEST_INTERACTIVE
3762
b92fd37c 3763static void TestDateTimeInteractive()
9d9b7755 3764{
456ae26d 3765 wxPuts(_T("\n*** interactive wxDateTime tests ***"));
9d9b7755 3766
456ae26d 3767 wxChar buf[128];
9d9b7755
VZ
3768
3769 for ( ;; )
3770 {
456ae26d
VZ
3771 wxPrintf(_T("Enter a date: "));
3772 if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
9d9b7755
VZ
3773 break;
3774
f6bcfd97 3775 // kill the last '\n'
456ae26d 3776 buf[wxStrlen(buf) - 1] = 0;
f6bcfd97 3777
9d9b7755 3778 wxDateTime dt;
456ae26d 3779 const wxChar *p = dt.ParseDate(buf);
f6bcfd97 3780 if ( !p )
9d9b7755 3781 {
456ae26d 3782 wxPrintf(_T("ERROR: failed to parse the date '%s'.\n"), buf);
9d9b7755
VZ
3783
3784 continue;
3785 }
f6bcfd97
BP
3786 else if ( *p )
3787 {
456ae26d 3788 wxPrintf(_T("WARNING: parsed only first %u characters.\n"), p - buf);
f6bcfd97 3789 }
9d9b7755 3790
456ae26d
VZ
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(),
3793 dt.GetDayOfYear(),
3794 dt.GetWeekOfMonth(wxDateTime::Monday_First),
3795 dt.GetWeekOfMonth(wxDateTime::Sunday_First),
3796 dt.GetWeekOfYear(wxDateTime::Monday_First));
9d9b7755
VZ
3797 }
3798
456ae26d 3799 wxPuts(_T("\n*** done ***"));
9d9b7755
VZ
3800}
3801
4b586201
WS
3802#endif // TEST_INTERACTIVE
3803
3804#if TEST_ALL
3805
f6bcfd97
BP
3806static void TestTimeMS()
3807{
456ae26d 3808 wxPuts(_T("*** testing millisecond-resolution support in wxDateTime ***"));
f6bcfd97
BP
3809
3810 wxDateTime dt1 = wxDateTime::Now(),
3811 dt2 = wxDateTime::UNow();
3812
456ae26d
VZ
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: "));
3ca6a5f0
BP
3816 for ( int i = 0; i < 6000; i++ )
3817 {
3818 //for ( int j = 0; j < 10; j++ )
3819 {
3820 wxString s;
ccd6aacd 3821 s.Printf(_T("%g"), sqrt((float)i));
3ca6a5f0
BP
3822 }
3823
3824 if ( !(i % 100) )
e9d2bb6f 3825 wxPutchar('.');
3ca6a5f0 3826 }
456ae26d 3827 wxPuts(_T(", done"));
3ca6a5f0
BP
3828
3829 dt1 = dt2;
3830 dt2 = wxDateTime::UNow();
456ae26d 3831 wxPrintf(_T("UNow = %s\n"), dt2.Format(_T("%H:%M:%S:%l")).c_str());
3ca6a5f0 3832
456ae26d 3833 wxPrintf(_T("Loop executed in %s ms\n"), (dt2 - dt1).Format(_T("%l")).c_str());
f6bcfd97 3834
456ae26d 3835 wxPuts(_T("\n*** done ***"));
f6bcfd97
BP
3836}
3837
0de868d9
VZ
3838static void TestTimeHolidays()
3839{
456ae26d 3840 wxPuts(_T("\n*** testing wxDateTimeHolidayAuthority ***\n"));
0de868d9
VZ
3841
3842 wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
3843 wxDateTime dtStart(1, tm.mon, tm.year),
3844 dtEnd = dtStart.GetLastMonthDay();
3845
3846 wxDateTimeArray hol;
3847 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
3848
456ae26d 3849 const wxChar *format = _T("%d-%b-%Y (%a)");
0de868d9 3850
456ae26d 3851 wxPrintf(_T("All holidays between %s and %s:\n"),
0de868d9
VZ
3852 dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
3853
3854 size_t count = hol.GetCount();
3855 for ( size_t n = 0; n < count; n++ )
3856 {
456ae26d 3857 wxPrintf(_T("\t%s\n"), hol[n].Format(format).c_str());
0de868d9
VZ
3858 }
3859
e9d2bb6f 3860 wxPuts(wxEmptyString);
0de868d9
VZ
3861}
3862
f6bcfd97
BP
3863static void TestTimeZoneBug()
3864{
456ae26d 3865 wxPuts(_T("\n*** testing for DST/timezone bug ***\n"));
f6bcfd97
BP
3866
3867 wxDateTime date = wxDateTime(1, wxDateTime::Mar, 2000);
3868 for ( int i = 0; i < 31; i++ )
3869 {
456ae26d 3870 wxPrintf(_T("Date %s: week day %s.\n"),
f6bcfd97
BP
3871 date.Format(_T("%d-%m-%Y")).c_str(),
3872 date.GetWeekDayName(date.GetWeekDay()).c_str());
3873
3874 date += wxDateSpan::Day();
3875 }
3876
e9d2bb6f 3877 wxPuts(wxEmptyString);
f6bcfd97
BP
3878}
3879
df05cdc5
VZ
3880static void TestTimeSpanFormat()
3881{
456ae26d 3882 wxPuts(_T("\n*** wxTimeSpan tests ***"));
df05cdc5 3883
456ae26d 3884 static const wxChar *formats[] =
df05cdc5
VZ
3885 {
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"),
a8625337 3892 _T("or also %S seconds"),
df05cdc5
VZ
3893 };
3894
3895 wxTimeSpan ts1(1, 2, 3, 4),
3896 ts2(111, 222, 333);
3897 for ( size_t n = 0; n < WXSIZEOF(formats); n++ )
3898 {
456ae26d 3899 wxPrintf(_T("ts1 = %s\tts2 = %s\n"),
df05cdc5
VZ
3900 ts1.Format(formats[n]).c_str(),
3901 ts2.Format(formats[n]).c_str());
3902 }
3903
e9d2bb6f 3904 wxPuts(wxEmptyString);
df05cdc5
VZ
3905}
3906
4b586201
WS
3907#endif // TEST_ALL
3908
d31b7b68 3909#endif // TEST_DATETIME
b76b015e 3910
39937656
VZ
3911// ----------------------------------------------------------------------------
3912// wxTextInput/OutputStream
3913// ----------------------------------------------------------------------------
3914
3915#ifdef TEST_TEXTSTREAM
3916
3917#include "wx/txtstrm.h"
3918#include "wx/wfstream.h"
3919
3920static void TestTextInputStream()
3921{
3922 wxPuts(_T("\n*** wxTextInputStream test ***"));
3923
e9d2bb6f
DS
3924 wxString filename = _T("testdata.fc");
3925 wxFileInputStream fsIn(filename);
39937656
VZ
3926 if ( !fsIn.Ok() )
3927 {
3928 wxPuts(_T("ERROR: couldn't open file."));
3929 }
3930 else
3931 {
3932 wxTextInputStream tis(fsIn);
3933
3934 size_t line = 1;
3935 for ( ;; )
3936 {
3937 const wxString s = tis.ReadLine();
3938
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() )
3942 break;
3943
3944 wxPrintf(_T("Line %d: %s\n"), line++, s.c_str());
3945 }
3946 }
3947}
3948
3949#endif // TEST_TEXTSTREAM
3950
e87271f3
VZ
3951// ----------------------------------------------------------------------------
3952// threads
3953// ----------------------------------------------------------------------------
3954
3955#ifdef TEST_THREADS
3956
e84010cf 3957#include "wx/thread.h"
37667812 3958
bbfa0322
VZ
3959static size_t gs_counter = (size_t)-1;
3960static wxCriticalSection gs_critsect;
c112e100 3961static wxSemaphore gs_cond;
bbfa0322 3962
b568d04f 3963class MyJoinableThread : public wxThread
bbfa0322
VZ
3964{
3965public:
b568d04f
VZ
3966 MyJoinableThread(size_t n) : wxThread(wxTHREAD_JOINABLE)
3967 { m_n = n; Create(); }
bbfa0322
VZ
3968
3969 // thread execution starts here
b568d04f 3970 virtual ExitCode Entry();
bbfa0322 3971
b568d04f
VZ
3972private:
3973 size_t m_n;
bbfa0322
VZ
3974};
3975
b568d04f 3976wxThread::ExitCode MyJoinableThread::Entry()
bbfa0322 3977{
b568d04f
VZ
3978 unsigned long res = 1;
3979 for ( size_t n = 1; n < m_n; n++ )
3980 {
3981 res *= n;
3982
3983 // it's a loooong calculation :-)
3984 Sleep(100);
3985 }
bbfa0322 3986
b568d04f 3987 return (ExitCode)res;
bbfa0322
VZ
3988}
3989
b568d04f
VZ
3990class MyDetachedThread : public wxThread
3991{
3992public:
456ae26d 3993 MyDetachedThread(size_t n, wxChar ch)
fcc3d7cb
VZ
3994 {
3995 m_n = n;
3996 m_ch = ch;
cab8f76e 3997 m_cancelled = false;
fcc3d7cb
VZ
3998
3999 Create();
4000 }
b568d04f
VZ
4001
4002 // thread execution starts here
4003 virtual ExitCode Entry();
4004
4005 // and stops here
4006 virtual void OnExit();
4007
4008private:
9fc3ad34 4009 size_t m_n; // number of characters to write
456ae26d 4010 wxChar m_ch; // character to write
fcc3d7cb 4011
cab8f76e 4012 bool m_cancelled; // false if we exit normally
b568d04f
VZ
4013};
4014
4015wxThread::ExitCode MyDetachedThread::Entry()
bbfa0322
VZ
4016{
4017 {
4018 wxCriticalSectionLocker lock(gs_critsect);
4019 if ( gs_counter == (size_t)-1 )
4020 gs_counter = 1;
4021 else
4022 gs_counter++;
4023 }
4024
9fc3ad34 4025 for ( size_t n = 0; n < m_n; n++ )
bbfa0322
VZ
4026 {
4027 if ( TestDestroy() )
fcc3d7cb 4028 {
cab8f76e 4029 m_cancelled = true;
fcc3d7cb 4030
bbfa0322 4031 break;
fcc3d7cb 4032 }
bbfa0322 4033
e9d2bb6f 4034 wxPutchar(m_ch);
bbfa0322
VZ
4035 fflush(stdout);
4036
4037 wxThread::Sleep(100);
4038 }
4039
b568d04f 4040 return 0;
bbfa0322
VZ
4041}
4042
b568d04f 4043void MyDetachedThread::OnExit()
bbfa0322 4044{
456ae26d 4045 wxLogTrace(_T("thread"), _T("Thread %ld is in OnExit"), GetId());
9fc3ad34 4046
bbfa0322 4047 wxCriticalSectionLocker lock(gs_critsect);
fcc3d7cb 4048 if ( !--gs_counter && !m_cancelled )
c112e100 4049 gs_cond.Post();
bbfa0322
VZ
4050}
4051
2f2f3e2a 4052static void TestDetachedThreads()
9fc3ad34 4053{
456ae26d 4054 wxPuts(_T("\n*** Testing detached threads ***"));
9fc3ad34
VZ
4055
4056 static const size_t nThreads = 3;
4057 MyDetachedThread *threads[nThreads];
4058 size_t n;
4059 for ( n = 0; n < nThreads; n++ )
4060 {
4061 threads[n] = new MyDetachedThread(10, 'A' + n);
4062 }
4063
4064 threads[0]->SetPriority(WXTHREAD_MIN_PRIORITY);
4065 threads[1]->SetPriority(WXTHREAD_MAX_PRIORITY);
4066
4067 for ( n = 0; n < nThreads; n++ )
4068 {
4069 threads[n]->Run();
4070 }
4071
4072 // wait until all threads terminate
4073 gs_cond.Wait();
4074
e9d2bb6f 4075 wxPuts(wxEmptyString);
9fc3ad34
VZ
4076}
4077
2f2f3e2a 4078static void TestJoinableThreads()
9fc3ad34 4079{
456ae26d 4080 wxPuts(_T("\n*** Testing a joinable thread (a loooong calculation...) ***"));
9fc3ad34
VZ
4081
4082 // calc 10! in the background
4083 MyJoinableThread thread(10);
4084 thread.Run();
4085
456ae26d 4086 wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
5bc1deeb 4087 (unsigned long)thread.Wait());
9fc3ad34
VZ
4088}
4089
2f2f3e2a 4090static void TestThreadSuspend()
9fc3ad34 4091{
456ae26d 4092 wxPuts(_T("\n*** Testing thread suspend/resume functions ***"));
2f02cb89
VZ
4093
4094 MyDetachedThread *thread = new MyDetachedThread(15, 'X');
9fc3ad34
VZ
4095
4096 thread->Run();
4097
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
4103 // in an error)
4104 wxThread::Sleep(300);
4105
4106 for ( size_t n = 0; n < 3; n++ )
4107 {
4108 thread->Pause();
4109
456ae26d 4110 wxPuts(_T("\nThread suspended"));
9fc3ad34
VZ
4111 if ( n > 0 )
4112 {
4113 // don't sleep but resume immediately the first time
4114 wxThread::Sleep(300);
4115 }
456ae26d 4116 wxPuts(_T("Going to resume the thread"));
9fc3ad34
VZ
4117
4118 thread->Resume();
4119 }
4120
456ae26d 4121 wxPuts(_T("Waiting until it terminates now"));
4c460b34 4122
9fc3ad34
VZ
4123 // wait until the thread terminates
4124 gs_cond.Wait();
4125
e9d2bb6f 4126 wxPuts(wxEmptyString);
9fc3ad34
VZ
4127}
4128
2f2f3e2a 4129static void TestThreadDelete()
2f02cb89
VZ
4130{
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!
4135
456ae26d 4136 wxPuts(_T("\n*** Testing thread delete function ***"));
2f02cb89 4137
4c460b34
VZ
4138 MyDetachedThread *thread0 = new MyDetachedThread(30, 'W');
4139
4140 thread0->Delete();
4141
456ae26d 4142 wxPuts(_T("\nDeleted a thread which didn't start to run yet."));
4c460b34 4143
2f02cb89
VZ
4144 MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y');
4145
4146 thread1->Run();
4147
4148 wxThread::Sleep(300);
4149
4150 thread1->Delete();
4151
456ae26d 4152 wxPuts(_T("\nDeleted a running thread."));
2f02cb89
VZ
4153
4154 MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z');
4155
4156 thread2->Run();
4157
4158 wxThread::Sleep(300);
4159
4160 thread2->Pause();
4161
4162 thread2->Delete();
4163
456ae26d 4164 wxPuts(_T("\nDeleted a sleeping thread."));
2f02cb89 4165
4c460b34
VZ
4166 MyJoinableThread thread3(20);
4167 thread3.Run();
2f02cb89 4168
4c460b34 4169 thread3.Delete();
2f02cb89 4170
456ae26d 4171 wxPuts(_T("\nDeleted a joinable thread."));
2f02cb89 4172
4c460b34
VZ
4173 MyJoinableThread thread4(2);
4174 thread4.Run();
2f02cb89
VZ
4175
4176 wxThread::Sleep(300);
4177
4c460b34 4178 thread4.Delete();
2f02cb89 4179
456ae26d 4180 wxPuts(_T("\nDeleted a joinable thread which already terminated."));
2f02cb89 4181
e9d2bb6f 4182 wxPuts(wxEmptyString);
2f02cb89
VZ
4183}
4184
2f2f3e2a
VZ
4185class MyWaitingThread : public wxThread
4186{
4187public:
c112e100 4188 MyWaitingThread( wxMutex *mutex, wxCondition *condition )
2f2f3e2a 4189 {
c112e100 4190 m_mutex = mutex;
2f2f3e2a
VZ
4191 m_condition = condition;
4192
4193 Create();
4194 }
4195
4196 virtual ExitCode Entry()
4197 {
456ae26d 4198 wxPrintf(_T("Thread %lu has started running.\n"), GetId());
2f2f3e2a
VZ
4199 fflush(stdout);
4200
c112e100 4201 gs_cond.Post();
2f2f3e2a 4202
456ae26d 4203 wxPrintf(_T("Thread %lu starts to wait...\n"), GetId());
2f2f3e2a
VZ
4204 fflush(stdout);
4205
c112e100 4206 m_mutex->Lock();
2f2f3e2a 4207 m_condition->Wait();
c112e100 4208 m_mutex->Unlock();
2f2f3e2a 4209
456ae26d 4210 wxPrintf(_T("Thread %lu finished to wait, exiting.\n"), GetId());
2f2f3e2a
VZ
4211 fflush(stdout);
4212
4213 return 0;
4214 }
4215
4216private:
c112e100 4217 wxMutex *m_mutex;
2f2f3e2a
VZ
4218 wxCondition *m_condition;
4219};
4220
4221static void TestThreadConditions()
4222{
c112e100
VZ
4223 wxMutex mutex;
4224 wxCondition condition(mutex);
2f2f3e2a 4225
8d5eff60
VZ
4226 // otherwise its difficult to understand which log messages pertain to
4227 // which condition
456ae26d 4228 //wxLogTrace(_T("thread"), _T("Local condition var is %08x, gs_cond = %08x"),
c112e100 4229 // condition.GetId(), gs_cond.GetId());
8d5eff60 4230
2f2f3e2a 4231 // create and launch threads
60ce696e 4232 MyWaitingThread *threads[10];
2f2f3e2a
VZ
4233
4234 size_t n;
4235 for ( n = 0; n < WXSIZEOF(threads); n++ )
4236 {
c112e100 4237 threads[n] = new MyWaitingThread( &mutex, &condition );
2f2f3e2a
VZ
4238 }
4239
4240 for ( n = 0; n < WXSIZEOF(threads); n++ )
4241 {
4242 threads[n]->Run();
4243 }
4244
4245 // wait until all threads run
456ae26d 4246 wxPuts(_T("Main thread is waiting for the other threads to start"));
2f2f3e2a
VZ
4247 fflush(stdout);
4248
4249 size_t nRunning = 0;
4250 while ( nRunning < WXSIZEOF(threads) )
4251 {
4252 gs_cond.Wait();
4253
2f2f3e2a 4254 nRunning++;
8d5eff60 4255
456ae26d 4256 wxPrintf(_T("Main thread: %u already running\n"), nRunning);
8d5eff60 4257 fflush(stdout);
2f2f3e2a
VZ
4258 }
4259
456ae26d 4260 wxPuts(_T("Main thread: all threads started up."));
2f2f3e2a
VZ
4261 fflush(stdout);
4262
8d5eff60
VZ
4263 wxThread::Sleep(500);
4264
60ce696e 4265#if 1
8d5eff60 4266 // now wake one of them up
456ae26d 4267 wxPrintf(_T("Main thread: about to signal the condition.\n"));
2f2f3e2a
VZ
4268 fflush(stdout);
4269 condition.Signal();
8d5eff60 4270#endif
2f2f3e2a 4271
60ce696e
VZ
4272 wxThread::Sleep(200);
4273
8d5eff60 4274 // wake all the (remaining) threads up, so that they can exit
456ae26d 4275 wxPrintf(_T("Main thread: about to broadcast the condition.\n"));
2f2f3e2a
VZ
4276 fflush(stdout);
4277 condition.Broadcast();
4278
8d5eff60
VZ
4279 // give them time to terminate (dirty!)
4280 wxThread::Sleep(500);
2f2f3e2a
VZ
4281}
4282
c112e100
VZ
4283#include "wx/utils.h"
4284
4285class MyExecThread : public wxThread
4286{
4287public:
4288 MyExecThread(const wxString& command) : wxThread(wxTHREAD_JOINABLE),
4289 m_command(command)
4290 {
4291 Create();
4292 }
4293
4294 virtual ExitCode Entry()
4295 {
4296 return (ExitCode)wxExecute(m_command, wxEXEC_SYNC);
4297 }
4298
4299private:
4300 wxString m_command;
4301};
4302
4303static void TestThreadExec()
4304{
4305 wxPuts(_T("*** Testing wxExecute interaction with threads ***\n"));
4306
4307 MyExecThread thread(_T("true"));
4308 thread.Run();
4309
4310 wxPrintf(_T("Main program exit code: %ld.\n"),
4311 wxExecute(_T("false"), wxEXEC_SYNC));
4312
4313 wxPrintf(_T("Thread exit code: %ld.\n"), (long)thread.Wait());
4314}
4315
4316// semaphore tests
4317#include "wx/datetime.h"
4318
4319class MySemaphoreThread : public wxThread
4320{
4321public:
4322 MySemaphoreThread(int i, wxSemaphore *sem)
4323 : wxThread(wxTHREAD_JOINABLE),
4324 m_sem(sem),
4325 m_i(i)
4326 {
4327 Create();
4328 }
4329
4330 virtual ExitCode Entry()
4331 {
f06ef5f4
VZ
4332 wxPrintf(_T("%s: Thread #%d (%ld) starting to wait for semaphore...\n"),
4333 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
c112e100
VZ
4334
4335 m_sem->Wait();
4336
f06ef5f4
VZ
4337 wxPrintf(_T("%s: Thread #%d (%ld) acquired the semaphore.\n"),
4338 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
c112e100
VZ
4339
4340 Sleep(1000);
4341
f06ef5f4
VZ
4342 wxPrintf(_T("%s: Thread #%d (%ld) releasing the semaphore.\n"),
4343 wxDateTime::Now().FormatTime().c_str(), m_i, (long)GetId());
c112e100
VZ
4344
4345 m_sem->Post();
4346
4347 return 0;
4348 }
4349
4350private:
4351 wxSemaphore *m_sem;
4352 int m_i;
4353};
4354
e9d2bb6f 4355WX_DEFINE_ARRAY_PTR(wxThread *, ArrayThreads);
c112e100
VZ
4356
4357static void TestSemaphore()
4358{
4359 wxPuts(_T("*** Testing wxSemaphore class. ***"));
4360
4361 static const int SEM_LIMIT = 3;
4362
4363 wxSemaphore sem(SEM_LIMIT, SEM_LIMIT);
4364 ArrayThreads threads;
4365
4366 for ( int i = 0; i < 3*SEM_LIMIT; i++ )
4367 {
4368 threads.Add(new MySemaphoreThread(i, &sem));
4369 threads.Last()->Run();
4370 }
4371
4372 for ( size_t n = 0; n < threads.GetCount(); n++ )
4373 {
4374 threads[n]->Wait();
4375 delete threads[n];
4376 }
4377}
4378
e87271f3
VZ
4379#endif // TEST_THREADS
4380
e87271f3
VZ
4381// ----------------------------------------------------------------------------
4382// entry point
4383// ----------------------------------------------------------------------------
4384
daa2c7d9
VZ
4385#ifdef TEST_SNGLINST
4386 #include "wx/snglinst.h"
4387#endif // TEST_SNGLINST
4388
bbfa0322 4389int main(int argc, char **argv)
37667812 4390{
6f35ed60 4391 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
9cb47ea2 4392
58b24a56
VZ
4393 wxInitializer initializer;
4394 if ( !initializer )
37667812 4395 {
be5a51fb 4396 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
58b24a56
VZ
4397
4398 return -1;
4399 }
4400
4401#ifdef TEST_SNGLINST
b5299791
VZ
4402 wxSingleInstanceChecker checker;
4403 if ( checker.Create(_T(".wxconsole.lock")) )
58b24a56 4404 {
b5299791
VZ
4405 if ( checker.IsAnotherRunning() )
4406 {
4407 wxPrintf(_T("Another instance of the program is running, exiting.\n"));
58b24a56 4408
b5299791
VZ
4409 return 1;
4410 }
37667812 4411
b5299791
VZ
4412 // wait some time to give time to launch another instance
4413 wxPrintf(_T("Press \"Enter\" to continue..."));
4414 wxFgetc(stdin);
4415 }
4416 else // failed to create
4417 {
4418 wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
4419 }
58b24a56
VZ
4420#endif // TEST_SNGLINST
4421
d34bce84 4422#ifdef TEST_CMDLINE
31f6de22
VZ
4423 TestCmdLineConvert();
4424
4425#if wxUSE_CMDLINE_PARSER
d34bce84
VZ
4426 static const wxCmdLineEntryDesc cmdLineDesc[] =
4427 {
456ae26d 4428 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"),
31a06b07 4429 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
456ae26d
VZ
4430 { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") },
4431 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
d34bce84 4432
456ae26d
VZ
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"),
31a06b07 4436 wxCMD_LINE_VAL_NUMBER },
456ae26d 4437 { wxCMD_LINE_OPTION, _T("d"), _T("date"), _T("output file date"),
31a06b07 4438 wxCMD_LINE_VAL_DATE },
d34bce84 4439
456ae26d 4440 { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
d34bce84
VZ
4441 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
4442
4443 { wxCMD_LINE_NONE }
4444 };
4445
456ae26d
VZ
4446#if wxUSE_UNICODE
4447 wxChar **wargv = new wxChar *[argc + 1];
4448
4449 {
f2cb8a17
JS
4450 int n;
4451
4452 for (n = 0; n < argc; n++ )
456ae26d
VZ
4453 {
4454 wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
4455 wargv[n] = wxStrdup(warg);
4456 }
4457
4458 wargv[n] = NULL;
4459 }
4460
4461 #define argv wargv
4462#endif // wxUSE_UNICODE
4463
d34bce84
VZ
4464 wxCmdLineParser parser(cmdLineDesc, argc, argv);
4465
456ae26d
VZ
4466#if wxUSE_UNICODE
4467 {
4468 for ( int n = 0; n < argc; n++ )
4469 free(wargv[n]);
4470
4471 delete [] wargv;
4472 }
4473#endif // wxUSE_UNICODE
4474
4475 parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
f6bcfd97
BP
4476 wxCMD_LINE_VAL_STRING,
4477 wxCMD_LINE_OPTION_MANDATORY | wxCMD_LINE_NEEDS_SEPARATOR);
4478
d34bce84
VZ
4479 switch ( parser.Parse() )
4480 {
4481 case -1:
456ae26d 4482 wxLogMessage(_T("Help was given, terminating."));
d34bce84
VZ
4483 break;
4484
4485 case 0:
4486 ShowCmdLine(parser);
4487 break;
4488
4489 default:
456ae26d 4490 wxLogMessage(_T("Syntax error detected, aborting."));
d34bce84
VZ
4491 break;
4492 }
31f6de22
VZ
4493#endif // wxUSE_CMDLINE_PARSER
4494
d34bce84
VZ
4495#endif // TEST_CMDLINE
4496
1944c6bd 4497#ifdef TEST_DIR
e9d2bb6f 4498 #if TEST_ALL
99a5af7f 4499 TestDirExists();
2f0c19d0 4500 TestDirEnum();
e9d2bb6f 4501 #endif
2f0c19d0 4502 TestDirTraverse();
1944c6bd
VZ
4503#endif // TEST_DIR
4504
f6bcfd97
BP
4505#ifdef TEST_DLLLOADER
4506 TestDllLoad();
4507#endif // TEST_DLLLOADER
4508
8fd0d89b
VZ
4509#ifdef TEST_ENVIRON
4510 TestEnvironment();
4511#endif // TEST_ENVIRON
4512
d93c719a
VZ
4513#ifdef TEST_EXECUTE
4514 TestExecute();
4515#endif // TEST_EXECUTE
4516
ee6e1b1d
VZ
4517#ifdef TEST_FILECONF
4518 TestFileConfRead();
4519#endif // TEST_FILECONF
4520
f6bcfd97
BP
4521#ifdef TEST_LIST
4522 TestListCtor();
df5168c4 4523 TestList();
f6bcfd97
BP
4524#endif // TEST_LIST
4525
ec37df57
VZ
4526#ifdef TEST_LOCALE
4527 TestDefaultLang();
4528#endif // TEST_LOCALE
4529
378b05f7 4530#ifdef TEST_LOG
cab8f76e
VZ
4531 wxPuts(_T("*** Testing wxLog ***"));
4532
378b05f7
VZ
4533 wxString s;
4534 for ( size_t n = 0; n < 8000; n++ )
4535 {
456ae26d 4536 s << (wxChar)(_T('A') + (n % 26));
378b05f7
VZ
4537 }
4538
cab8f76e
VZ
4539 wxLogWarning(_T("The length of the string is %lu"),
4540 (unsigned long)s.length());
4541
378b05f7 4542 wxString msg;
456ae26d 4543 msg.Printf(_T("A very very long message: '%s', the end!\n"), s.c_str());
378b05f7
VZ
4544
4545 // this one shouldn't be truncated
456ae26d 4546 wxPrintf(msg);
378b05f7
VZ
4547
4548 // but this one will because log functions use fixed size buffer
b568d04f
VZ
4549 // (note that it doesn't need '\n' at the end neither - will be added
4550 // by wxLog anyhow)
456ae26d 4551 wxLogMessage(_T("A very very long message 2: '%s', the end!"), s.c_str());
378b05f7
VZ
4552#endif // TEST_LOG
4553
f6bcfd97 4554#ifdef TEST_FILE
e9d2bb6f
DS
4555 TestFileRead();
4556 TestTextFileRead();
4557 TestFileCopy();
f6bcfd97
BP
4558#endif // TEST_FILE
4559
844f90fb 4560#ifdef TEST_FILENAME
e9d2bb6f
DS
4561 TestFileNameConstruction();
4562 TestFileNameMakeRelative();
4563 TestFileNameMakeAbsolute();
4564 TestFileNameSplit();
4565 TestFileNameTemp();
4566 TestFileNameCwd();
4567 TestFileNameDirManip();
4568 TestFileNameComparison();
4569 TestFileNameOperations();
844f90fb
VZ
4570#endif // TEST_FILENAME
4571
d56e2b97
VZ
4572#ifdef TEST_FILETIME
4573 TestFileGetTimes();
e9d2bb6f 4574 #if 0
d56e2b97 4575 TestFileSetTimes();
e9d2bb6f 4576 #endif
d56e2b97
VZ
4577#endif // TEST_FILETIME
4578
07a56e45
VZ
4579#ifdef TEST_FTP
4580 wxLog::AddTraceMask(FTP_TRACE_MASK);
4581 if ( TestFtpConnect() )
4582 {
e9d2bb6f 4583 #if TEST_ALL
07a56e45
VZ
4584 TestFtpList();
4585 TestFtpDownload();
4586 TestFtpMisc();
daa2c7d9 4587 TestFtpFileSize();
07a56e45 4588 TestFtpUpload();
af33b199 4589 #endif // TEST_ALL
daa2c7d9 4590
e9d2bb6f 4591 #if TEST_INTERACTIVE
daa2c7d9 4592 TestFtpInteractive();
e9d2bb6f 4593 #endif
07a56e45
VZ
4594 }
4595 //else: connecting to the FTP server failed
4596
e9d2bb6f 4597 #if 0
07a56e45 4598 TestFtpWuFtpd();
e9d2bb6f 4599 #endif
07a56e45
VZ
4600#endif // TEST_FTP
4601
0508ba2a
MB
4602#ifdef TEST_HASHMAP
4603 TestHashMap();
4604#endif // TEST_HASHMAP
4605
8142d704
MB
4606#ifdef TEST_HASHSET
4607 TestHashSet();
4608#endif // TEST_HASHSET
4609
696e1ea0 4610#ifdef TEST_MIME
f6bcfd97 4611 wxLog::AddTraceMask(_T("mime"));
e9d2bb6f 4612 #if TEST_ALL
f6bcfd97 4613 TestMimeEnum();
c7ce8392 4614 TestMimeOverride();
f06ef5f4 4615 TestMimeAssociate();
e9d2bb6f 4616 #endif
f06ef5f4 4617 TestMimeFilename();
696e1ea0
VZ
4618#endif // TEST_MIME
4619
89e60357 4620#ifdef TEST_INFO_FUNCTIONS
e9d2bb6f 4621 #if TEST_ALL
3a994742
VZ
4622 TestOsInfo();
4623 TestUserInfo();
19f45995 4624
e9d2bb6f 4625 #if TEST_INTERACTIVE
19f45995 4626 TestDiskInfo();
e9d2bb6f
DS
4627 #endif
4628 #endif
89e60357
VZ
4629#endif // TEST_INFO_FUNCTIONS
4630
39189b9d
VZ
4631#ifdef TEST_PATHLIST
4632 TestPathList();
4633#endif // TEST_PATHLIST
4634
8d5eff60
VZ
4635#ifdef TEST_ODBC
4636 TestDbOpen();
4637#endif // TEST_ODBC
4638
7aeebdcd
VZ
4639#ifdef TEST_PRINTF
4640 TestPrintf();
4641#endif // TEST_PRINTF
4642
7ba4fbeb 4643#ifdef TEST_REGCONF
e9d2bb6f
DS
4644 #if 0
4645 TestRegConfWrite();
4646 #endif
0aa29b6b 4647 TestRegConfRead();
7ba4fbeb
VZ
4648#endif // TEST_REGCONF
4649
bc10103e
VS
4650#if defined TEST_REGEX && TEST_INTERACTIVE
4651 TestRegExInteractive();
4652#endif // defined TEST_REGEX && TEST_INTERACTIVE
07a56e45 4653
6dfec4b8 4654#ifdef TEST_REGISTRY
daa2c7d9 4655 TestRegistryRead();
6ba63600 4656 TestRegistryAssociation();
6dfec4b8
VZ
4657#endif // TEST_REGISTRY
4658
2c8e4738 4659#ifdef TEST_SOCKETS
daa2c7d9
VZ
4660 TestSocketServer();
4661 TestSocketClient();
2c8e4738
VZ
4662#endif // TEST_SOCKETS
4663
83141d3a 4664#ifdef TEST_STREAMS
e9d2bb6f 4665 #if TEST_ALL
99a5af7f 4666 TestFileStream();
e9d2bb6f 4667 #endif
99a5af7f 4668 TestMemoryStream();
83141d3a
VZ
4669#endif // TEST_STREAMS
4670
39937656
VZ
4671#ifdef TEST_TEXTSTREAM
4672 TestTextInputStream();
4673#endif // TEST_TEXTSTREAM
4674
8d5eff60
VZ
4675#ifdef TEST_THREADS
4676 int nCPUs = wxThread::GetCPUCount();
456ae26d 4677 wxPrintf(_T("This system has %d CPUs\n"), nCPUs);
8d5eff60
VZ
4678 if ( nCPUs != -1 )
4679 wxThread::SetConcurrency(nCPUs);
4680
5bc1deeb
VZ
4681 TestJoinableThreads();
4682
e9d2bb6f 4683 #if TEST_ALL
8d5eff60 4684 TestJoinableThreads();
5bc1deeb 4685 TestDetachedThreads();
8d5eff60
VZ
4686 TestThreadSuspend();
4687 TestThreadDelete();
c112e100
VZ
4688 TestThreadConditions();
4689 TestThreadExec();
7aeebdcd 4690 TestSemaphore();
e9d2bb6f 4691 #endif
8d5eff60
VZ
4692#endif // TEST_THREADS
4693
d31b7b68
VZ
4694#ifdef TEST_TIMER
4695 TestStopWatch();
4696#endif // TEST_TIMER
4697
4698#ifdef TEST_DATETIME
e9d2bb6f 4699 #if TEST_ALL
9d9b7755
VZ
4700 TestTimeSet();
4701 TestTimeStatic();
4702 TestTimeRange();
4703 TestTimeZones();
4704 TestTimeTicks();
4705 TestTimeJDN();
4706 TestTimeDST();
4707 TestTimeWDays();
4708 TestTimeWNumber();
4709 TestTimeParse();
9d9b7755 4710 TestTimeArithmetics();
f6bcfd97 4711 TestTimeHolidays();
daa2c7d9 4712 TestTimeSpanFormat();
3ca6a5f0 4713 TestTimeMS();
f6bcfd97
BP
4714
4715 TestTimeZoneBug();
e9d2bb6f 4716 #endif
2b5f62a0 4717
e9d2bb6f 4718 #if TEST_INTERACTIVE
b92fd37c 4719 TestDateTimeInteractive();
e9d2bb6f 4720 #endif
d31b7b68 4721#endif // TEST_DATETIME
b76b015e 4722
df5168c4
MB
4723#ifdef TEST_SCOPEGUARD
4724 TestScopeGuard();
4725#endif
4726
af33b199
VZ
4727#ifdef TEST_STDPATHS
4728 TestStandardPaths();
4729#endif
4730
551fe3a6 4731#ifdef TEST_USLEEP
456ae26d 4732 wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
551fe3a6
VZ
4733 wxUsleep(3000);
4734#endif // TEST_USLEEP
4735
f6bcfd97 4736#ifdef TEST_VCARD
f6bcfd97
BP
4737 TestVCardRead();
4738 TestVCardWrite();
4739#endif // TEST_VCARD
4740
0e2c5534
VZ
4741#ifdef TEST_VOLUME
4742 TestFSVolume();
4743#endif // TEST_VOLUME
4744
f6bcfd97
BP
4745#ifdef TEST_WCHAR
4746 TestUtf8();
ac511156 4747 TestEncodingConverter();
f6bcfd97
BP
4748#endif // TEST_WCHAR
4749
4750#ifdef TEST_ZIP
daa2c7d9 4751 TestZipStreamRead();
2ca8b884 4752 TestZipFileSystem();
f6bcfd97
BP
4753#endif // TEST_ZIP
4754
e9d2bb6f
DS
4755 wxUnusedVar(argc);
4756 wxUnusedVar(argv);
37667812
VZ
4757 return 0;
4758}
f6bcfd97 4759