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