1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: a sample console (as opposed to GUI) progam using wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 #include <wx/string.h>
26 // without this pragma, the stupid compiler precompiles #defines below so that
27 // changing them doesn't "take place" later!
32 // ----------------------------------------------------------------------------
33 // conditional compilation
34 // ----------------------------------------------------------------------------
36 // what to test (in alphabetic order)?
39 //#define TEST_CMDLINE
40 //#define TEST_DATETIME
42 //#define TEST_DLLLOADER
44 //#define TEST_EXECUTE
46 //#define TEST_FILECONF
50 //#define TEST_LONGLONG
52 //#define TEST_INFO_FUNCTIONS
53 //#define TEST_REGISTRY
54 //#define TEST_SOCKETS
55 //#define TEST_STREAMS
56 //#define TEST_STRINGS
57 //#define TEST_THREADS
59 //#define TEST_VCARD -- don't enable this (VZ)
64 // ----------------------------------------------------------------------------
65 // test class for container objects
66 // ----------------------------------------------------------------------------
68 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
70 class Bar
// Foo is already taken in the hash test
73 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
76 static size_t GetNumber() { return ms_bars
; }
78 const char *GetName() const { return m_name
; }
83 static size_t ms_bars
;
86 size_t Bar::ms_bars
= 0;
88 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
90 // ============================================================================
92 // ============================================================================
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
100 // replace TABs with \t and CRs with \n
101 static wxString
MakePrintable(const wxChar
*s
)
104 (void)str
.Replace(_T("\t"), _T("\\t"));
105 (void)str
.Replace(_T("\n"), _T("\\n"));
106 (void)str
.Replace(_T("\r"), _T("\\r"));
111 #endif // MakePrintable() is used
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
119 #include <wx/cmdline.h>
120 #include <wx/datetime.h>
122 static void ShowCmdLine(const wxCmdLineParser
& parser
)
124 wxString s
= "Input files: ";
126 size_t count
= parser
.GetParamCount();
127 for ( size_t param
= 0; param
< count
; param
++ )
129 s
<< parser
.GetParam(param
) << ' ';
133 << "Verbose:\t" << (parser
.Found("v") ? "yes" : "no") << '\n'
134 << "Quiet:\t" << (parser
.Found("q") ? "yes" : "no") << '\n';
139 if ( parser
.Found("o", &strVal
) )
140 s
<< "Output file:\t" << strVal
<< '\n';
141 if ( parser
.Found("i", &strVal
) )
142 s
<< "Input dir:\t" << strVal
<< '\n';
143 if ( parser
.Found("s", &lVal
) )
144 s
<< "Size:\t" << lVal
<< '\n';
145 if ( parser
.Found("d", &dt
) )
146 s
<< "Date:\t" << dt
.FormatISODate() << '\n';
147 if ( parser
.Found("project_name", &strVal
) )
148 s
<< "Project:\t" << strVal
<< '\n';
153 #endif // TEST_CMDLINE
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
163 static void TestDirEnumHelper(wxDir
& dir
,
164 int flags
= wxDIR_DEFAULT
,
165 const wxString
& filespec
= wxEmptyString
)
169 if ( !dir
.IsOpened() )
172 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
175 printf("\t%s\n", filename
.c_str());
177 cont
= dir
.GetNext(&filename
);
183 static void TestDirEnum()
185 wxDir
dir(wxGetCwd());
187 puts("Enumerating everything in current directory:");
188 TestDirEnumHelper(dir
);
190 puts("Enumerating really everything in current directory:");
191 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
193 puts("Enumerating object files in current directory:");
194 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o");
196 puts("Enumerating directories in current directory:");
197 TestDirEnumHelper(dir
, wxDIR_DIRS
);
199 puts("Enumerating files in current directory:");
200 TestDirEnumHelper(dir
, wxDIR_FILES
);
202 puts("Enumerating files including hidden in current directory:");
203 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
207 #elif defined(__WXMSW__)
210 #error "don't know where the root directory is"
213 puts("Enumerating everything in root directory:");
214 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
216 puts("Enumerating directories in root directory:");
217 TestDirEnumHelper(dir
, wxDIR_DIRS
);
219 puts("Enumerating files in root directory:");
220 TestDirEnumHelper(dir
, wxDIR_FILES
);
222 puts("Enumerating files including hidden in root directory:");
223 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
225 puts("Enumerating files in non existing directory:");
226 wxDir
dirNo("nosuchdir");
227 TestDirEnumHelper(dirNo
);
232 // ----------------------------------------------------------------------------
234 // ----------------------------------------------------------------------------
236 #ifdef TEST_DLLLOADER
238 #include <wx/dynlib.h>
240 static void TestDllLoad()
242 #if defined(__WXMSW__)
243 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
244 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
245 #elif defined(__UNIX__)
246 // weird: using just libc.so does *not* work!
247 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
248 static const wxChar
*FUNC_NAME
= _T("strlen");
250 #error "don't know how to test wxDllLoader on this platform"
253 puts("*** testing wxDllLoader ***\n");
255 wxDllType dllHandle
= wxDllLoader::LoadLibrary(LIB_NAME
);
258 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
262 typedef int (*strlenType
)(char *);
263 strlenType pfnStrlen
= (strlenType
)wxDllLoader::GetSymbol(dllHandle
, FUNC_NAME
);
266 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
267 FUNC_NAME
, LIB_NAME
);
271 if ( pfnStrlen("foo") != 3 )
273 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
281 wxDllLoader::UnloadLibrary(dllHandle
);
285 #endif // TEST_DLLLOADER
287 // ----------------------------------------------------------------------------
289 // ----------------------------------------------------------------------------
293 #include <wx/utils.h>
295 static wxString
MyGetEnv(const wxString
& var
)
298 if ( !wxGetEnv(var
, &val
) )
301 val
= wxString(_T('\'')) + val
+ _T('\'');
306 static void TestEnvironment()
308 const wxChar
*var
= _T("wxTestVar");
310 puts("*** testing environment access functions ***");
312 printf("Initially getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
313 wxSetEnv(var
, _T("value for wxTestVar"));
314 printf("After wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
315 wxSetEnv(var
, _T("another value"));
316 printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
318 printf("After wxUnsetEnv: getenv(%s) = %s\n", var
, MyGetEnv(var
).c_str());
319 printf("PATH = %s\n", MyGetEnv(_T("PATH")));
322 #endif // TEST_ENVIRON
324 // ----------------------------------------------------------------------------
326 // ----------------------------------------------------------------------------
330 #include <wx/utils.h>
332 static void TestExecute()
334 puts("*** testing wxExecute ***");
337 #define COMMAND "cat -n ../../Makefile" // "echo hi"
338 #define SHELL_COMMAND "echo hi from shell"
339 #define REDIRECT_COMMAND COMMAND // "date"
340 #elif defined(__WXMSW__)
341 #define COMMAND "command.com -c 'echo hi'"
342 #define SHELL_COMMAND "echo hi"
343 #define REDIRECT_COMMAND COMMAND
345 #error "no command to exec"
348 printf("Testing wxShell: ");
350 if ( wxShell(SHELL_COMMAND
) )
355 printf("Testing wxExecute: ");
357 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
362 #if 0 // no, it doesn't work (yet?)
363 printf("Testing async wxExecute: ");
365 if ( wxExecute(COMMAND
) != 0 )
366 puts("Ok (command launched).");
371 printf("Testing wxExecute with redirection:\n");
372 wxArrayString output
;
373 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
379 size_t count
= output
.GetCount();
380 for ( size_t n
= 0; n
< count
; n
++ )
382 printf("\t%s\n", output
[n
].c_str());
389 #endif // TEST_EXECUTE
391 // ----------------------------------------------------------------------------
393 // ----------------------------------------------------------------------------
398 #include <wx/textfile.h>
400 static void TestFileRead()
402 puts("*** wxFile read test ***");
404 wxFile
file(_T("testdata.fc"));
405 if ( file
.IsOpened() )
407 printf("File length: %lu\n", file
.Length());
409 puts("File dump:\n----------");
411 static const off_t len
= 1024;
415 off_t nRead
= file
.Read(buf
, len
);
416 if ( nRead
== wxInvalidOffset
)
418 printf("Failed to read the file.");
422 fwrite(buf
, nRead
, 1, stdout
);
432 printf("ERROR: can't open test file.\n");
438 static void TestTextFileRead()
440 puts("*** wxTextFile read test ***");
442 wxTextFile
file(_T("testdata.fc"));
445 printf("Number of lines: %u\n", file
.GetLineCount());
446 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
450 puts("\nDumping the entire file:");
451 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
453 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
455 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
457 puts("\nAnd now backwards:");
458 for ( s
= file
.GetLastLine();
459 file
.GetCurrentLine() != 0;
460 s
= file
.GetPrevLine() )
462 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
464 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
468 printf("ERROR: can't open '%s'\n", file
.GetName());
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
482 #include <wx/confbase.h>
483 #include <wx/fileconf.h>
485 static const struct FileConfTestData
487 const wxChar
*name
; // value name
488 const wxChar
*value
; // the value from the file
491 { _T("value1"), _T("one") },
492 { _T("value2"), _T("two") },
493 { _T("novalue"), _T("default") },
496 static void TestFileConfRead()
498 puts("*** testing wxFileConfig loading/reading ***");
500 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
501 _T("testdata.fc"), wxEmptyString
,
502 wxCONFIG_USE_RELATIVE_PATH
);
504 // test simple reading
505 puts("\nReading config file:");
506 wxString
defValue(_T("default")), value
;
507 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
509 const FileConfTestData
& data
= fcTestData
[n
];
510 value
= fileconf
.Read(data
.name
, defValue
);
511 printf("\t%s = %s ", data
.name
, value
.c_str());
512 if ( value
== data
.value
)
518 printf("(ERROR: should be %s)\n", data
.value
);
522 // test enumerating the entries
523 puts("\nEnumerating all root entries:");
526 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
529 printf("\t%s = %s\n",
531 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
533 cont
= fileconf
.GetNextEntry(name
, dummy
);
537 #endif // TEST_FILECONF
539 // ----------------------------------------------------------------------------
541 // ----------------------------------------------------------------------------
549 Foo(int n_
) { n
= n_
; count
++; }
557 size_t Foo::count
= 0;
559 WX_DECLARE_LIST(Foo
, wxListFoos
);
560 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
562 #include <wx/listimpl.cpp>
564 WX_DEFINE_LIST(wxListFoos
);
566 static void TestHash()
568 puts("*** Testing wxHashTable ***\n");
572 hash
.DeleteContents(TRUE
);
574 printf("Hash created: %u foos in hash, %u foos totally\n",
575 hash
.GetCount(), Foo::count
);
577 static const int hashTestData
[] =
579 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
583 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
585 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
588 printf("Hash filled: %u foos in hash, %u foos totally\n",
589 hash
.GetCount(), Foo::count
);
591 puts("Hash access test:");
592 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
594 printf("\tGetting element with key %d, value %d: ",
596 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
599 printf("ERROR, not found.\n");
603 printf("%d (%s)\n", foo
->n
,
604 (size_t)foo
->n
== n
? "ok" : "ERROR");
608 printf("\nTrying to get an element not in hash: ");
610 if ( hash
.Get(1234) || hash
.Get(1, 0) )
612 puts("ERROR: found!");
616 puts("ok (not found)");
620 printf("Hash destroyed: %u foos left\n", Foo::count
);
625 // ----------------------------------------------------------------------------
627 // ----------------------------------------------------------------------------
633 WX_DECLARE_LIST(Bar
, wxListBars
);
634 #include <wx/listimpl.cpp>
635 WX_DEFINE_LIST(wxListBars
);
637 static void TestListCtor()
639 puts("*** Testing wxList construction ***\n");
643 list1
.Append(new Bar(_T("first")));
644 list1
.Append(new Bar(_T("second")));
646 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
647 list1
.GetCount(), Bar::GetNumber());
652 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
653 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
655 list1
.DeleteContents(TRUE
);
658 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
663 // ----------------------------------------------------------------------------
665 // ----------------------------------------------------------------------------
669 #include <wx/mimetype.h>
671 static wxMimeTypesManager g_mimeManager
;
673 static void TestMimeEnum()
675 wxArrayString mimetypes
;
677 size_t count
= g_mimeManager
.EnumAllFileTypes(mimetypes
);
679 printf("*** All %u known filetypes: ***\n", count
);
684 for ( size_t n
= 0; n
< count
; n
++ )
686 wxFileType
*filetype
= g_mimeManager
.GetFileTypeFromMimeType(mimetypes
[n
]);
689 printf("nothing known about the filetype '%s'!\n",
690 mimetypes
[n
].c_str());
694 filetype
->GetDescription(&desc
);
695 filetype
->GetExtensions(exts
);
697 filetype
->GetIcon(NULL
);
700 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
707 printf("\t%s: %s (%s)\n",
708 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
712 static void TestMimeOverride()
714 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
716 wxString mailcap
= _T("/tmp/mailcap"),
717 mimetypes
= _T("/tmp/mime.types");
719 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
721 g_mimeManager
.ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
722 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
724 g_mimeManager
.ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
727 static void TestMimeFilename()
729 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
731 static const wxChar
*filenames
[] =
738 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
740 const wxString fname
= filenames
[n
];
741 wxString ext
= fname
.AfterLast(_T('.'));
742 wxFileType
*ft
= g_mimeManager
.GetFileTypeFromExtension(ext
);
745 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
750 if ( !ft
->GetDescription(&desc
) )
751 desc
= _T("<no description>");
754 if ( !ft
->GetOpenCommand(&cmd
,
755 wxFileType::MessageParameters(fname
, _T(""))) )
756 cmd
= _T("<no command available>");
758 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
759 fname
.c_str(), desc
.c_str(), cmd
.c_str());
768 // ----------------------------------------------------------------------------
769 // misc information functions
770 // ----------------------------------------------------------------------------
772 #ifdef TEST_INFO_FUNCTIONS
774 #include <wx/utils.h>
776 static void TestOsInfo()
778 puts("*** Testing OS info functions ***\n");
781 wxGetOsVersion(&major
, &minor
);
782 printf("Running under: %s, version %d.%d\n",
783 wxGetOsDescription().c_str(), major
, minor
);
785 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
787 printf("Host name is %s (%s).\n",
788 wxGetHostName().c_str(), wxGetFullHostName().c_str());
793 static void TestUserInfo()
795 puts("*** Testing user info functions ***\n");
797 printf("User id is:\t%s\n", wxGetUserId().c_str());
798 printf("User name is:\t%s\n", wxGetUserName().c_str());
799 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
800 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
805 #endif // TEST_INFO_FUNCTIONS
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
813 #include <wx/longlong.h>
814 #include <wx/timer.h>
816 // make a 64 bit number from 4 16 bit ones
817 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
819 // get a random 64 bit number
820 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
822 #if wxUSE_LONGLONG_WX
823 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
824 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
825 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
826 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
827 #endif // wxUSE_LONGLONG_WX
829 static void TestSpeed()
831 static const long max
= 100000000;
838 for ( n
= 0; n
< max
; n
++ )
843 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
846 #if wxUSE_LONGLONG_NATIVE
851 for ( n
= 0; n
< max
; n
++ )
856 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
858 #endif // wxUSE_LONGLONG_NATIVE
864 for ( n
= 0; n
< max
; n
++ )
869 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
873 static void TestLongLongConversion()
875 puts("*** Testing wxLongLong conversions ***\n");
879 for ( size_t n
= 0; n
< 100000; n
++ )
883 #if wxUSE_LONGLONG_NATIVE
884 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
886 wxASSERT_MSG( a
== b
, "conversions failure" );
888 puts("Can't do it without native long long type, test skipped.");
891 #endif // wxUSE_LONGLONG_NATIVE
893 if ( !(nTested
% 1000) )
905 static void TestMultiplication()
907 puts("*** Testing wxLongLong multiplication ***\n");
911 for ( size_t n
= 0; n
< 100000; n
++ )
916 #if wxUSE_LONGLONG_NATIVE
917 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
918 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
920 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
921 #else // !wxUSE_LONGLONG_NATIVE
922 puts("Can't do it without native long long type, test skipped.");
925 #endif // wxUSE_LONGLONG_NATIVE
927 if ( !(nTested
% 1000) )
939 static void TestDivision()
941 puts("*** Testing wxLongLong division ***\n");
945 for ( size_t n
= 0; n
< 100000; n
++ )
947 // get a random wxLongLong (shifting by 12 the MSB ensures that the
948 // multiplication will not overflow)
949 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
951 // get a random long (not wxLongLong for now) to divide it with
956 #if wxUSE_LONGLONG_NATIVE
957 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
959 wxLongLongNative p
= m
/ l
, s
= m
% l
;
960 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
961 #else // !wxUSE_LONGLONG_NATIVE
963 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
964 #endif // wxUSE_LONGLONG_NATIVE
966 if ( !(nTested
% 1000) )
978 static void TestAddition()
980 puts("*** Testing wxLongLong addition ***\n");
984 for ( size_t n
= 0; n
< 100000; n
++ )
990 #if wxUSE_LONGLONG_NATIVE
991 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
992 wxLongLongNative(b
.GetHi(), b
.GetLo()),
993 "addition failure" );
994 #else // !wxUSE_LONGLONG_NATIVE
995 wxASSERT_MSG( c
- b
== a
, "addition failure" );
996 #endif // wxUSE_LONGLONG_NATIVE
998 if ( !(nTested
% 1000) )
1010 static void TestBitOperations()
1012 puts("*** Testing wxLongLong bit operation ***\n");
1016 for ( size_t n
= 0; n
< 100000; n
++ )
1020 #if wxUSE_LONGLONG_NATIVE
1021 for ( size_t n
= 0; n
< 33; n
++ )
1024 #else // !wxUSE_LONGLONG_NATIVE
1025 puts("Can't do it without native long long type, test skipped.");
1028 #endif // wxUSE_LONGLONG_NATIVE
1030 if ( !(nTested
% 1000) )
1042 static void TestLongLongComparison()
1044 puts("*** Testing wxLongLong comparison ***\n");
1046 static const long testLongs
[] =
1057 static const long ls
[2] =
1063 wxLongLongWx lls
[2];
1067 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
1071 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
1073 res
= lls
[m
] > testLongs
[n
];
1074 printf("0x%lx > 0x%lx is %s (%s)\n",
1075 ls
[m
], testLongs
[n
], res
? "true" : "false",
1076 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
1078 res
= lls
[m
] < testLongs
[n
];
1079 printf("0x%lx < 0x%lx is %s (%s)\n",
1080 ls
[m
], testLongs
[n
], res
? "true" : "false",
1081 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
1083 res
= lls
[m
] == testLongs
[n
];
1084 printf("0x%lx == 0x%lx is %s (%s)\n",
1085 ls
[m
], testLongs
[n
], res
? "true" : "false",
1086 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
1094 #endif // TEST_LONGLONG
1096 // ----------------------------------------------------------------------------
1098 // ----------------------------------------------------------------------------
1100 // this is for MSW only
1102 #undef TEST_REGISTRY
1105 #ifdef TEST_REGISTRY
1107 #include <wx/msw/registry.h>
1109 // I chose this one because I liked its name, but it probably only exists under
1111 static const wxChar
*TESTKEY
=
1112 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1114 static void TestRegistryRead()
1116 puts("*** testing registry reading ***");
1118 wxRegKey
key(TESTKEY
);
1119 printf("The test key name is '%s'.\n", key
.GetName().c_str());
1122 puts("ERROR: test key can't be opened, aborting test.");
1127 size_t nSubKeys
, nValues
;
1128 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
1130 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
1133 printf("Enumerating values:\n");
1137 bool cont
= key
.GetFirstValue(value
, dummy
);
1140 printf("Value '%s': type ", value
.c_str());
1141 switch ( key
.GetValueType(value
) )
1143 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
1144 case wxRegKey::Type_String
: printf("SZ"); break;
1145 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
1146 case wxRegKey::Type_Binary
: printf("BINARY"); break;
1147 case wxRegKey::Type_Dword
: printf("DWORD"); break;
1148 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
1149 default: printf("other (unknown)"); break;
1152 printf(", value = ");
1153 if ( key
.IsNumericValue(value
) )
1156 key
.QueryValue(value
, &val
);
1162 key
.QueryValue(value
, val
);
1163 printf("'%s'", val
.c_str());
1165 key
.QueryRawValue(value
, val
);
1166 printf(" (raw value '%s')", val
.c_str());
1171 cont
= key
.GetNextValue(value
, dummy
);
1175 static void TestRegistryAssociation()
1178 The second call to deleteself genertaes an error message, with a
1179 messagebox saying .flo is crucial to system operation, while the .ddf
1180 call also fails, but with no error message
1185 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1187 key
= "ddxf_auto_file" ;
1188 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1190 key
= "ddxf_auto_file" ;
1191 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1194 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1196 key
= "program \"%1\"" ;
1198 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1200 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1202 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1204 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1208 #endif // TEST_REGISTRY
1210 // ----------------------------------------------------------------------------
1212 // ----------------------------------------------------------------------------
1216 #include <wx/socket.h>
1217 #include <wx/protocol/protocol.h>
1218 #include <wx/protocol/ftp.h>
1219 #include <wx/protocol/http.h>
1221 static void TestSocketServer()
1223 puts("*** Testing wxSocketServer ***\n");
1225 static const int PORT
= 3000;
1230 wxSocketServer
*server
= new wxSocketServer(addr
);
1231 if ( !server
->Ok() )
1233 puts("ERROR: failed to bind");
1240 printf("Server: waiting for connection on port %d...\n", PORT
);
1242 wxSocketBase
*socket
= server
->Accept();
1245 puts("ERROR: wxSocketServer::Accept() failed.");
1249 puts("Server: got a client.");
1251 server
->SetTimeout(60); // 1 min
1253 while ( socket
->IsConnected() )
1259 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
1261 // don't log error if the client just close the connection
1262 if ( socket
->IsConnected() )
1264 puts("ERROR: in wxSocket::Read.");
1284 printf("Server: got '%s'.\n", s
.c_str());
1285 if ( s
== _T("bye") )
1292 socket
->Write(s
.MakeUpper().c_str(), s
.length());
1293 socket
->Write("\r\n", 2);
1294 printf("Server: wrote '%s'.\n", s
.c_str());
1297 puts("Server: lost a client.");
1302 // same as "delete server" but is consistent with GUI programs
1306 static void TestSocketClient()
1308 puts("*** Testing wxSocketClient ***\n");
1310 static const char *hostname
= "www.wxwindows.org";
1313 addr
.Hostname(hostname
);
1316 printf("--- Attempting to connect to %s:80...\n", hostname
);
1318 wxSocketClient client
;
1319 if ( !client
.Connect(addr
) )
1321 printf("ERROR: failed to connect to %s\n", hostname
);
1325 printf("--- Connected to %s:%u...\n",
1326 addr
.Hostname().c_str(), addr
.Service());
1330 // could use simply "GET" here I suppose
1332 wxString::Format("GET http://%s/\r\n", hostname
);
1333 client
.Write(cmdGet
, cmdGet
.length());
1334 printf("--- Sent command '%s' to the server\n",
1335 MakePrintable(cmdGet
).c_str());
1336 client
.Read(buf
, WXSIZEOF(buf
));
1337 printf("--- Server replied:\n%s", buf
);
1341 static void TestProtocolFtp()
1343 puts("*** Testing wxFTP download ***\n");
1345 wxLog::AddTraceMask(_T("ftp"));
1347 static const char *hostname
= "ftp.wxwindows.org";
1349 printf("--- Attempting to connect to %s:21...\n", hostname
);
1352 if ( !ftp
.Connect(hostname
) )
1354 printf("ERROR: failed to connect to %s\n", hostname
);
1358 printf("--- Connected to %s, current directory is '%s'\n",
1359 hostname
, ftp
.Pwd().c_str());
1360 if ( !ftp
.ChDir(_T("pub")) )
1362 puts("ERROR: failed to cd to pub");
1365 wxArrayString files
;
1366 if ( !ftp
.GetList(files
) )
1368 puts("ERROR: failed to get list of files");
1372 printf("List of files under '%s':\n", ftp
.Pwd().c_str());
1373 size_t count
= files
.GetCount();
1374 for ( size_t n
= 0; n
< count
; n
++ )
1376 printf("\t%s\n", files
[n
].c_str());
1378 puts("End of the file list");
1381 if ( !ftp
.ChDir(_T("..")) )
1383 puts("ERROR: failed to cd to ..");
1386 static const char *filename
= "welcome.msg";
1387 wxInputStream
*in
= ftp
.GetInputStream(filename
);
1390 puts("ERROR: couldn't get input stream");
1394 size_t size
= in
->StreamSize();
1395 printf("Reading file %s (%u bytes)...", filename
, size
);
1397 char *data
= new char[size
];
1398 if ( !in
->Read(data
, size
) )
1400 puts("ERROR: read error");
1404 printf("\nContents of %s:\n%s\n", filename
, data
);
1413 static void TestProtocolFtpUpload()
1415 puts("*** Testing wxFTP uploading ***\n");
1417 wxLog::AddTraceMask(_T("ftp"));
1419 static const char *hostname
= "localhost";
1421 printf("--- Attempting to connect to %s:21...\n", hostname
);
1424 ftp
.SetUser("zeitlin");
1425 ftp
.SetPassword("insert your password here");
1426 if ( !ftp
.Connect(hostname
) )
1428 printf("ERROR: failed to connect to %s\n", hostname
);
1432 printf("--- Connected to %s, current directory is '%s'\n",
1433 hostname
, ftp
.Pwd().c_str());
1436 static const char *file1
= "test1";
1437 static const char *file2
= "test2";
1438 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
1441 printf("--- Uploading to %s ---\n", file1
);
1442 out
->Write("First hello", 11);
1446 out
= ftp
.GetOutputStream(file2
);
1449 printf("--- Uploading to %s ---\n", file1
);
1450 out
->Write("Second hello", 12);
1456 #endif // TEST_SOCKETS
1458 // ----------------------------------------------------------------------------
1460 // ----------------------------------------------------------------------------
1464 #include <wx/mstream.h>
1466 static void TestMemoryStream()
1468 puts("*** Testing wxMemoryInputStream ***");
1471 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
1473 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
1474 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
1475 while ( !memInpStream
.Eof() )
1477 putchar(memInpStream
.GetC());
1480 puts("\n*** wxMemoryInputStream test done ***");
1483 #endif // TEST_STREAMS
1485 // ----------------------------------------------------------------------------
1487 // ----------------------------------------------------------------------------
1491 #include <wx/timer.h>
1492 #include <wx/utils.h>
1494 static void TestStopWatch()
1496 puts("*** Testing wxStopWatch ***\n");
1499 printf("Sleeping 3 seconds...");
1501 printf("\telapsed time: %ldms\n", sw
.Time());
1504 printf("Sleeping 2 more seconds...");
1506 printf("\telapsed time: %ldms\n", sw
.Time());
1509 printf("And 3 more seconds...");
1511 printf("\telapsed time: %ldms\n", sw
.Time());
1514 puts("\nChecking for 'backwards clock' bug...");
1515 for ( size_t n
= 0; n
< 70; n
++ )
1519 for ( size_t m
= 0; m
< 100000; m
++ )
1521 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
1523 puts("\ntime is negative - ERROR!");
1533 #endif // TEST_TIMER
1535 // ----------------------------------------------------------------------------
1537 // ----------------------------------------------------------------------------
1541 #include <wx/vcard.h>
1543 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
1546 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
1550 wxString(_T('\t'), level
).c_str(),
1551 vcObj
->GetName().c_str());
1554 switch ( vcObj
->GetType() )
1556 case wxVCardObject::String
:
1557 case wxVCardObject::UString
:
1560 vcObj
->GetValue(&val
);
1561 value
<< _T('"') << val
<< _T('"');
1565 case wxVCardObject::Int
:
1568 vcObj
->GetValue(&i
);
1569 value
.Printf(_T("%u"), i
);
1573 case wxVCardObject::Long
:
1576 vcObj
->GetValue(&l
);
1577 value
.Printf(_T("%lu"), l
);
1581 case wxVCardObject::None
:
1584 case wxVCardObject::Object
:
1585 value
= _T("<node>");
1589 value
= _T("<unknown value type>");
1593 printf(" = %s", value
.c_str());
1596 DumpVObject(level
+ 1, *vcObj
);
1599 vcObj
= vcard
.GetNextProp(&cookie
);
1603 static void DumpVCardAddresses(const wxVCard
& vcard
)
1605 puts("\nShowing all addresses from vCard:\n");
1609 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
1613 int flags
= addr
->GetFlags();
1614 if ( flags
& wxVCardAddress::Domestic
)
1616 flagsStr
<< _T("domestic ");
1618 if ( flags
& wxVCardAddress::Intl
)
1620 flagsStr
<< _T("international ");
1622 if ( flags
& wxVCardAddress::Postal
)
1624 flagsStr
<< _T("postal ");
1626 if ( flags
& wxVCardAddress::Parcel
)
1628 flagsStr
<< _T("parcel ");
1630 if ( flags
& wxVCardAddress::Home
)
1632 flagsStr
<< _T("home ");
1634 if ( flags
& wxVCardAddress::Work
)
1636 flagsStr
<< _T("work ");
1639 printf("Address %u:\n"
1641 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
1644 addr
->GetPostOffice().c_str(),
1645 addr
->GetExtAddress().c_str(),
1646 addr
->GetStreet().c_str(),
1647 addr
->GetLocality().c_str(),
1648 addr
->GetRegion().c_str(),
1649 addr
->GetPostalCode().c_str(),
1650 addr
->GetCountry().c_str()
1654 addr
= vcard
.GetNextAddress(&cookie
);
1658 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
1660 puts("\nShowing all phone numbers from vCard:\n");
1664 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
1668 int flags
= phone
->GetFlags();
1669 if ( flags
& wxVCardPhoneNumber::Voice
)
1671 flagsStr
<< _T("voice ");
1673 if ( flags
& wxVCardPhoneNumber::Fax
)
1675 flagsStr
<< _T("fax ");
1677 if ( flags
& wxVCardPhoneNumber::Cellular
)
1679 flagsStr
<< _T("cellular ");
1681 if ( flags
& wxVCardPhoneNumber::Modem
)
1683 flagsStr
<< _T("modem ");
1685 if ( flags
& wxVCardPhoneNumber::Home
)
1687 flagsStr
<< _T("home ");
1689 if ( flags
& wxVCardPhoneNumber::Work
)
1691 flagsStr
<< _T("work ");
1694 printf("Phone number %u:\n"
1699 phone
->GetNumber().c_str()
1703 phone
= vcard
.GetNextPhoneNumber(&cookie
);
1707 static void TestVCardRead()
1709 puts("*** Testing wxVCard reading ***\n");
1711 wxVCard
vcard(_T("vcard.vcf"));
1712 if ( !vcard
.IsOk() )
1714 puts("ERROR: couldn't load vCard.");
1718 // read individual vCard properties
1719 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
1723 vcObj
->GetValue(&value
);
1728 value
= _T("<none>");
1731 printf("Full name retrieved directly: %s\n", value
.c_str());
1734 if ( !vcard
.GetFullName(&value
) )
1736 value
= _T("<none>");
1739 printf("Full name from wxVCard API: %s\n", value
.c_str());
1741 // now show how to deal with multiply occuring properties
1742 DumpVCardAddresses(vcard
);
1743 DumpVCardPhoneNumbers(vcard
);
1745 // and finally show all
1746 puts("\nNow dumping the entire vCard:\n"
1747 "-----------------------------\n");
1749 DumpVObject(0, vcard
);
1753 static void TestVCardWrite()
1755 puts("*** Testing wxVCard writing ***\n");
1758 if ( !vcard
.IsOk() )
1760 puts("ERROR: couldn't create vCard.");
1765 vcard
.SetName("Zeitlin", "Vadim");
1766 vcard
.SetFullName("Vadim Zeitlin");
1767 vcard
.SetOrganization("wxWindows", "R&D");
1769 // just dump the vCard back
1770 puts("Entire vCard follows:\n");
1771 puts(vcard
.Write());
1775 #endif // TEST_VCARD
1777 // ----------------------------------------------------------------------------
1778 // wide char (Unicode) support
1779 // ----------------------------------------------------------------------------
1783 #include <wx/strconv.h>
1784 #include <wx/buffer.h>
1786 static void TestUtf8()
1788 puts("*** Testing UTF8 support ***\n");
1790 wxString testString
= "français";
1792 "************ French - Français ****************"
1793 "Juste un petit exemple pour dire que les français aussi"
1794 "ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
1797 wxWCharBuffer wchBuf
= testString
.wc_str(wxConvUTF8
);
1798 const wchar_t *pwz
= (const wchar_t *)wchBuf
;
1799 wxString
testString2(pwz
, wxConvLocal
);
1801 printf("Decoding '%s' => '%s'\n", testString
.c_str(), testString2
.c_str());
1803 char *psz
= "fran" "\xe7" "ais";
1804 size_t len
= strlen(psz
);
1805 wchar_t *pwz2
= new wchar_t[len
+ 1];
1806 for ( size_t n
= 0; n
<= len
; n
++ )
1808 pwz2
[n
] = (wchar_t)(unsigned char)psz
[n
];
1811 wxString
testString3(pwz2
, wxConvUTF8
);
1814 printf("Encoding '%s' -> '%s'\n", psz
, testString3
.c_str());
1817 #endif // TEST_WCHAR
1819 // ----------------------------------------------------------------------------
1821 // ----------------------------------------------------------------------------
1825 #include "wx/zipstrm.h"
1827 static void TestZipStreamRead()
1829 puts("*** Testing ZIP reading ***\n");
1831 wxZipInputStream
istr(_T("idx.zip"), _T("IDX.txt"));
1832 printf("Archive size: %u\n", istr
.GetSize());
1834 puts("Dumping the file:");
1835 while ( !istr
.Eof() )
1837 putchar(istr
.GetC());
1841 puts("\n----- done ------");
1846 // ----------------------------------------------------------------------------
1848 // ----------------------------------------------------------------------------
1852 #include <wx/zstream.h>
1853 #include <wx/wfstream.h>
1855 static const wxChar
*FILENAME_GZ
= _T("test.gz");
1856 static const char *TEST_DATA
= "hello and hello again";
1858 static void TestZlibStreamWrite()
1860 puts("*** Testing Zlib stream reading ***\n");
1862 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
1863 wxZlibOutputStream
ostr(fileOutStream
, 0);
1864 printf("Compressing the test string... ");
1865 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
1868 puts("(ERROR: failed)");
1875 puts("\n----- done ------");
1878 static void TestZlibStreamRead()
1880 puts("*** Testing Zlib stream reading ***\n");
1882 wxFileInputStream
fileInStream(FILENAME_GZ
);
1883 wxZlibInputStream
istr(fileInStream
);
1884 printf("Archive size: %u\n", istr
.GetSize());
1886 puts("Dumping the file:");
1887 while ( !istr
.Eof() )
1889 putchar(istr
.GetC());
1893 puts("\n----- done ------");
1898 // ----------------------------------------------------------------------------
1900 // ----------------------------------------------------------------------------
1902 #ifdef TEST_DATETIME
1904 #include <wx/date.h>
1906 #include <wx/datetime.h>
1911 wxDateTime::wxDateTime_t day
;
1912 wxDateTime::Month month
;
1914 wxDateTime::wxDateTime_t hour
, min
, sec
;
1916 wxDateTime::WeekDay wday
;
1917 time_t gmticks
, ticks
;
1919 void Init(const wxDateTime::Tm
& tm
)
1928 gmticks
= ticks
= -1;
1931 wxDateTime
DT() const
1932 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
1934 bool SameDay(const wxDateTime::Tm
& tm
) const
1936 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
1939 wxString
Format() const
1942 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
1944 wxDateTime::GetMonthName(month
).c_str(),
1946 abs(wxDateTime::ConvertYearToBC(year
)),
1947 year
> 0 ? "AD" : "BC");
1951 wxString
FormatDate() const
1954 s
.Printf("%02d-%s-%4d%s",
1956 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1957 abs(wxDateTime::ConvertYearToBC(year
)),
1958 year
> 0 ? "AD" : "BC");
1963 static const Date testDates
[] =
1965 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
1966 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
1967 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
1968 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
1969 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
1970 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
1971 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
1972 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
1973 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
1974 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
1975 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
1976 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
1977 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
1978 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
1979 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
1982 // this test miscellaneous static wxDateTime functions
1983 static void TestTimeStatic()
1985 puts("\n*** wxDateTime static methods test ***");
1987 // some info about the current date
1988 int year
= wxDateTime::GetCurrentYear();
1989 printf("Current year %d is %sa leap one and has %d days.\n",
1991 wxDateTime::IsLeapYear(year
) ? "" : "not ",
1992 wxDateTime::GetNumberOfDays(year
));
1994 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
1995 printf("Current month is '%s' ('%s') and it has %d days\n",
1996 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1997 wxDateTime::GetMonthName(month
).c_str(),
1998 wxDateTime::GetNumberOfDays(month
));
2001 static const size_t nYears
= 5;
2002 static const size_t years
[2][nYears
] =
2004 // first line: the years to test
2005 { 1990, 1976, 2000, 2030, 1984, },
2007 // second line: TRUE if leap, FALSE otherwise
2008 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
2011 for ( size_t n
= 0; n
< nYears
; n
++ )
2013 int year
= years
[0][n
];
2014 bool should
= years
[1][n
] != 0,
2015 is
= wxDateTime::IsLeapYear(year
);
2017 printf("Year %d is %sa leap year (%s)\n",
2020 should
== is
? "ok" : "ERROR");
2022 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
2026 // test constructing wxDateTime objects
2027 static void TestTimeSet()
2029 puts("\n*** wxDateTime construction test ***");
2031 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2033 const Date
& d1
= testDates
[n
];
2034 wxDateTime dt
= d1
.DT();
2037 d2
.Init(dt
.GetTm());
2039 wxString s1
= d1
.Format(),
2042 printf("Date: %s == %s (%s)\n",
2043 s1
.c_str(), s2
.c_str(),
2044 s1
== s2
? "ok" : "ERROR");
2048 // test time zones stuff
2049 static void TestTimeZones()
2051 puts("\n*** wxDateTime timezone test ***");
2053 wxDateTime now
= wxDateTime::Now();
2055 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
2056 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
2057 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
2058 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
2059 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
2060 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
2062 wxDateTime::Tm tm
= now
.GetTm();
2063 if ( wxDateTime(tm
) != now
)
2065 printf("ERROR: got %s instead of %s\n",
2066 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
2070 // test some minimal support for the dates outside the standard range
2071 static void TestTimeRange()
2073 puts("\n*** wxDateTime out-of-standard-range dates test ***");
2075 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
2077 printf("Unix epoch:\t%s\n",
2078 wxDateTime(2440587.5).Format(fmt
).c_str());
2079 printf("Feb 29, 0: \t%s\n",
2080 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
2081 printf("JDN 0: \t%s\n",
2082 wxDateTime(0.0).Format(fmt
).c_str());
2083 printf("Jan 1, 1AD:\t%s\n",
2084 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
2085 printf("May 29, 2099:\t%s\n",
2086 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
2089 static void TestTimeTicks()
2091 puts("\n*** wxDateTime ticks test ***");
2093 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2095 const Date
& d
= testDates
[n
];
2096 if ( d
.ticks
== -1 )
2099 wxDateTime dt
= d
.DT();
2100 long ticks
= (dt
.GetValue() / 1000).ToLong();
2101 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2102 if ( ticks
== d
.ticks
)
2108 printf(" (ERROR: should be %ld, delta = %ld)\n",
2109 d
.ticks
, ticks
- d
.ticks
);
2112 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
2113 ticks
= (dt
.GetValue() / 1000).ToLong();
2114 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2115 if ( ticks
== d
.gmticks
)
2121 printf(" (ERROR: should be %ld, delta = %ld)\n",
2122 d
.gmticks
, ticks
- d
.gmticks
);
2129 // test conversions to JDN &c
2130 static void TestTimeJDN()
2132 puts("\n*** wxDateTime to JDN test ***");
2134 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2136 const Date
& d
= testDates
[n
];
2137 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2138 double jdn
= dt
.GetJulianDayNumber();
2140 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
2147 printf(" (ERROR: should be %f, delta = %f)\n",
2148 d
.jdn
, jdn
- d
.jdn
);
2153 // test week days computation
2154 static void TestTimeWDays()
2156 puts("\n*** wxDateTime weekday test ***");
2158 // test GetWeekDay()
2160 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2162 const Date
& d
= testDates
[n
];
2163 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2165 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
2168 wxDateTime::GetWeekDayName(wday
).c_str());
2169 if ( wday
== d
.wday
)
2175 printf(" (ERROR: should be %s)\n",
2176 wxDateTime::GetWeekDayName(d
.wday
).c_str());
2182 // test SetToWeekDay()
2183 struct WeekDateTestData
2185 Date date
; // the real date (precomputed)
2186 int nWeek
; // its week index in the month
2187 wxDateTime::WeekDay wday
; // the weekday
2188 wxDateTime::Month month
; // the month
2189 int year
; // and the year
2191 wxString
Format() const
2194 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
2196 case 1: which
= "first"; break;
2197 case 2: which
= "second"; break;
2198 case 3: which
= "third"; break;
2199 case 4: which
= "fourth"; break;
2200 case 5: which
= "fifth"; break;
2202 case -1: which
= "last"; break;
2207 which
+= " from end";
2210 s
.Printf("The %s %s of %s in %d",
2212 wxDateTime::GetWeekDayName(wday
).c_str(),
2213 wxDateTime::GetMonthName(month
).c_str(),
2220 // the array data was generated by the following python program
2222 from DateTime import *
2223 from whrandom import *
2224 from string import *
2226 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2227 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2229 week = DateTimeDelta(7)
2232 year = randint(1900, 2100)
2233 month = randint(1, 12)
2234 day = randint(1, 28)
2235 dt = DateTime(year, month, day)
2236 wday = dt.day_of_week
2238 countFromEnd = choice([-1, 1])
2241 while dt.month is month:
2242 dt = dt - countFromEnd * week
2243 weekNum = weekNum + countFromEnd
2245 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
2247 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
2248 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
2251 static const WeekDateTestData weekDatesTestData
[] =
2253 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
2254 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
2255 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
2256 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
2257 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
2258 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
2259 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
2260 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
2261 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
2262 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
2263 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
2264 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
2265 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
2266 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
2267 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
2268 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
2269 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
2270 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
2271 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
2272 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
2275 static const char *fmt
= "%d-%b-%Y";
2278 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
2280 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
2282 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
2284 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
2286 const Date
& d
= wd
.date
;
2287 if ( d
.SameDay(dt
.GetTm()) )
2293 dt
.Set(d
.day
, d
.month
, d
.year
);
2295 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
2300 // test the computation of (ISO) week numbers
2301 static void TestTimeWNumber()
2303 puts("\n*** wxDateTime week number test ***");
2305 struct WeekNumberTestData
2307 Date date
; // the date
2308 wxDateTime::wxDateTime_t week
; // the week number in the year
2309 wxDateTime::wxDateTime_t wmon
; // the week number in the month
2310 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
2311 wxDateTime::wxDateTime_t dnum
; // day number in the year
2314 // data generated with the following python script:
2316 from DateTime import *
2317 from whrandom import *
2318 from string import *
2320 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2321 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2323 def GetMonthWeek(dt):
2324 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
2325 if weekNumMonth < 0:
2326 weekNumMonth = weekNumMonth + 53
2329 def GetLastSundayBefore(dt):
2330 if dt.iso_week[2] == 7:
2333 return dt - DateTimeDelta(dt.iso_week[2])
2336 year = randint(1900, 2100)
2337 month = randint(1, 12)
2338 day = randint(1, 28)
2339 dt = DateTime(year, month, day)
2340 dayNum = dt.day_of_year
2341 weekNum = dt.iso_week[1]
2342 weekNumMonth = GetMonthWeek(dt)
2345 dtSunday = GetLastSundayBefore(dt)
2347 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
2348 weekNumMonth2 = weekNumMonth2 + 1
2349 dtSunday = dtSunday - DateTimeDelta(7)
2351 data = { 'day': rjust(`day`, 2), \
2352 'month': monthNames[month - 1], \
2354 'weekNum': rjust(`weekNum`, 2), \
2355 'weekNumMonth': weekNumMonth, \
2356 'weekNumMonth2': weekNumMonth2, \
2357 'dayNum': rjust(`dayNum`, 3) }
2359 print " { { %(day)s, "\
2360 "wxDateTime::%(month)s, "\
2363 "%(weekNumMonth)s, "\
2364 "%(weekNumMonth2)s, "\
2365 "%(dayNum)s }," % data
2368 static const WeekNumberTestData weekNumberTestDates
[] =
2370 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
2371 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
2372 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
2373 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
2374 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
2375 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
2376 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
2377 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
2378 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
2379 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
2380 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
2381 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
2382 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
2383 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
2384 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
2385 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
2386 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
2387 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
2388 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
2389 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
2392 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
2394 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
2395 const Date
& d
= wn
.date
;
2397 wxDateTime dt
= d
.DT();
2399 wxDateTime::wxDateTime_t
2400 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
2401 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2402 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2403 dnum
= dt
.GetDayOfYear();
2405 printf("%s: the day number is %d",
2406 d
.FormatDate().c_str(), dnum
);
2407 if ( dnum
== wn
.dnum
)
2413 printf(" (ERROR: should be %d)", wn
.dnum
);
2416 printf(", week in month is %d", wmon
);
2417 if ( wmon
== wn
.wmon
)
2423 printf(" (ERROR: should be %d)", wn
.wmon
);
2426 printf(" or %d", wmon2
);
2427 if ( wmon2
== wn
.wmon2
)
2433 printf(" (ERROR: should be %d)", wn
.wmon2
);
2436 printf(", week in year is %d", week
);
2437 if ( week
== wn
.week
)
2443 printf(" (ERROR: should be %d)\n", wn
.week
);
2448 // test DST calculations
2449 static void TestTimeDST()
2451 puts("\n*** wxDateTime DST test ***");
2453 printf("DST is%s in effect now.\n\n",
2454 wxDateTime::Now().IsDST() ? "" : " not");
2456 // taken from http://www.energy.ca.gov/daylightsaving.html
2457 static const Date datesDST
[2][2004 - 1900 + 1] =
2460 { 1, wxDateTime::Apr
, 1990 },
2461 { 7, wxDateTime::Apr
, 1991 },
2462 { 5, wxDateTime::Apr
, 1992 },
2463 { 4, wxDateTime::Apr
, 1993 },
2464 { 3, wxDateTime::Apr
, 1994 },
2465 { 2, wxDateTime::Apr
, 1995 },
2466 { 7, wxDateTime::Apr
, 1996 },
2467 { 6, wxDateTime::Apr
, 1997 },
2468 { 5, wxDateTime::Apr
, 1998 },
2469 { 4, wxDateTime::Apr
, 1999 },
2470 { 2, wxDateTime::Apr
, 2000 },
2471 { 1, wxDateTime::Apr
, 2001 },
2472 { 7, wxDateTime::Apr
, 2002 },
2473 { 6, wxDateTime::Apr
, 2003 },
2474 { 4, wxDateTime::Apr
, 2004 },
2477 { 28, wxDateTime::Oct
, 1990 },
2478 { 27, wxDateTime::Oct
, 1991 },
2479 { 25, wxDateTime::Oct
, 1992 },
2480 { 31, wxDateTime::Oct
, 1993 },
2481 { 30, wxDateTime::Oct
, 1994 },
2482 { 29, wxDateTime::Oct
, 1995 },
2483 { 27, wxDateTime::Oct
, 1996 },
2484 { 26, wxDateTime::Oct
, 1997 },
2485 { 25, wxDateTime::Oct
, 1998 },
2486 { 31, wxDateTime::Oct
, 1999 },
2487 { 29, wxDateTime::Oct
, 2000 },
2488 { 28, wxDateTime::Oct
, 2001 },
2489 { 27, wxDateTime::Oct
, 2002 },
2490 { 26, wxDateTime::Oct
, 2003 },
2491 { 31, wxDateTime::Oct
, 2004 },
2496 for ( year
= 1990; year
< 2005; year
++ )
2498 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
2499 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
2501 printf("DST period in the US for year %d: from %s to %s",
2502 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
2504 size_t n
= year
- 1990;
2505 const Date
& dBegin
= datesDST
[0][n
];
2506 const Date
& dEnd
= datesDST
[1][n
];
2508 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
2514 printf(" (ERROR: should be %s %d to %s %d)\n",
2515 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
2516 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
2522 for ( year
= 1990; year
< 2005; year
++ )
2524 printf("DST period in Europe for year %d: from %s to %s\n",
2526 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
2527 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
2531 // test wxDateTime -> text conversion
2532 static void TestTimeFormat()
2534 puts("\n*** wxDateTime formatting test ***");
2536 // some information may be lost during conversion, so store what kind
2537 // of info should we recover after a round trip
2540 CompareNone
, // don't try comparing
2541 CompareBoth
, // dates and times should be identical
2542 CompareDate
, // dates only
2543 CompareTime
// time only
2548 CompareKind compareKind
;
2550 } formatTestFormats
[] =
2552 { CompareBoth
, "---> %c" },
2553 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
2554 { CompareBoth
, "Date is %x, time is %X" },
2555 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
2556 { CompareNone
, "The day of year: %j, the week of year: %W" },
2557 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
2560 static const Date formatTestDates
[] =
2562 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
2563 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
2565 // this test can't work for other centuries because it uses two digit
2566 // years in formats, so don't even try it
2567 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
2568 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
2569 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
2573 // an extra test (as it doesn't depend on date, don't do it in the loop)
2574 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
2576 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
2580 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
2581 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
2583 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
2584 printf("%s", s
.c_str());
2586 // what can we recover?
2587 int kind
= formatTestFormats
[n
].compareKind
;
2591 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
2594 // converion failed - should it have?
2595 if ( kind
== CompareNone
)
2598 puts(" (ERROR: conversion back failed)");
2602 // should have parsed the entire string
2603 puts(" (ERROR: conversion back stopped too soon)");
2607 bool equal
= FALSE
; // suppress compilaer warning
2615 equal
= dt
.IsSameDate(dt2
);
2619 equal
= dt
.IsSameTime(dt2
);
2625 printf(" (ERROR: got back '%s' instead of '%s')\n",
2626 dt2
.Format().c_str(), dt
.Format().c_str());
2637 // test text -> wxDateTime conversion
2638 static void TestTimeParse()
2640 puts("\n*** wxDateTime parse test ***");
2642 struct ParseTestData
2649 static const ParseTestData parseTestDates
[] =
2651 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
2652 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
2655 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
2657 const char *format
= parseTestDates
[n
].format
;
2659 printf("%s => ", format
);
2662 if ( dt
.ParseRfc822Date(format
) )
2664 printf("%s ", dt
.Format().c_str());
2666 if ( parseTestDates
[n
].good
)
2668 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
2675 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
2680 puts("(ERROR: bad format)");
2685 printf("bad format (%s)\n",
2686 parseTestDates
[n
].good
? "ERROR" : "ok");
2691 static void TestInteractive()
2693 puts("\n*** interactive wxDateTime tests ***");
2699 printf("Enter a date: ");
2700 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2703 // kill the last '\n'
2704 buf
[strlen(buf
) - 1] = 0;
2707 const char *p
= dt
.ParseDate(buf
);
2710 printf("ERROR: failed to parse the date '%s'.\n", buf
);
2716 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
2719 printf("%s: day %u, week of month %u/%u, week of year %u\n",
2720 dt
.Format("%b %d, %Y").c_str(),
2722 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2723 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2724 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
2727 puts("\n*** done ***");
2730 static void TestTimeMS()
2732 puts("*** testing millisecond-resolution support in wxDateTime ***");
2734 wxDateTime dt1
= wxDateTime::Now(),
2735 dt2
= wxDateTime::UNow();
2737 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
2738 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2739 printf("Dummy loop: ");
2740 for ( int i
= 0; i
< 6000; i
++ )
2742 //for ( int j = 0; j < 10; j++ )
2745 s
.Printf("%g", sqrt(i
));
2754 dt2
= wxDateTime::UNow();
2755 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2757 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
2759 puts("\n*** done ***");
2762 static void TestTimeArithmetics()
2764 puts("\n*** testing arithmetic operations on wxDateTime ***");
2766 static const struct ArithmData
2768 ArithmData(const wxDateSpan
& sp
, const char *nam
)
2769 : span(sp
), name(nam
) { }
2773 } testArithmData
[] =
2775 ArithmData(wxDateSpan::Day(), "day"),
2776 ArithmData(wxDateSpan::Week(), "week"),
2777 ArithmData(wxDateSpan::Month(), "month"),
2778 ArithmData(wxDateSpan::Year(), "year"),
2779 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
2782 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
2784 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
2786 wxDateSpan span
= testArithmData
[n
].span
;
2790 const char *name
= testArithmData
[n
].name
;
2791 printf("%s + %s = %s, %s - %s = %s\n",
2792 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
2793 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
2795 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
2796 if ( dt1
- span
== dt
)
2802 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2805 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
2806 if ( dt2
+ span
== dt
)
2812 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2815 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
2816 if ( dt2
+ 2*span
== dt1
)
2822 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
2829 static void TestTimeHolidays()
2831 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
2833 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
2834 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
2835 dtEnd
= dtStart
.GetLastMonthDay();
2837 wxDateTimeArray hol
;
2838 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
2840 const wxChar
*format
= "%d-%b-%Y (%a)";
2842 printf("All holidays between %s and %s:\n",
2843 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
2845 size_t count
= hol
.GetCount();
2846 for ( size_t n
= 0; n
< count
; n
++ )
2848 printf("\t%s\n", hol
[n
].Format(format
).c_str());
2854 static void TestTimeZoneBug()
2856 puts("\n*** testing for DST/timezone bug ***\n");
2858 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
2859 for ( int i
= 0; i
< 31; i
++ )
2861 printf("Date %s: week day %s.\n",
2862 date
.Format(_T("%d-%m-%Y")).c_str(),
2863 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
2865 date
+= wxDateSpan::Day();
2873 // test compatibility with the old wxDate/wxTime classes
2874 static void TestTimeCompatibility()
2876 puts("\n*** wxDateTime compatibility test ***");
2878 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
2879 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
2881 double jdnNow
= wxDateTime::Now().GetJDN();
2882 long jdnMidnight
= (long)(jdnNow
- 0.5);
2883 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
2885 jdnMidnight
= wxDate().Set().GetJulianDate();
2886 printf("wxDateTime for today: %s\n",
2887 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
2889 int flags
= wxEUROPEAN
;//wxFULL;
2892 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
2893 for ( int n
= 0; n
< 7; n
++ )
2895 printf("Previous %s is %s\n",
2896 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
2897 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
2903 #endif // TEST_DATETIME
2905 // ----------------------------------------------------------------------------
2907 // ----------------------------------------------------------------------------
2911 #include <wx/thread.h>
2913 static size_t gs_counter
= (size_t)-1;
2914 static wxCriticalSection gs_critsect
;
2915 static wxCondition gs_cond
;
2917 class MyJoinableThread
: public wxThread
2920 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
2921 { m_n
= n
; Create(); }
2923 // thread execution starts here
2924 virtual ExitCode
Entry();
2930 wxThread::ExitCode
MyJoinableThread::Entry()
2932 unsigned long res
= 1;
2933 for ( size_t n
= 1; n
< m_n
; n
++ )
2937 // it's a loooong calculation :-)
2941 return (ExitCode
)res
;
2944 class MyDetachedThread
: public wxThread
2947 MyDetachedThread(size_t n
, char ch
)
2951 m_cancelled
= FALSE
;
2956 // thread execution starts here
2957 virtual ExitCode
Entry();
2960 virtual void OnExit();
2963 size_t m_n
; // number of characters to write
2964 char m_ch
; // character to write
2966 bool m_cancelled
; // FALSE if we exit normally
2969 wxThread::ExitCode
MyDetachedThread::Entry()
2972 wxCriticalSectionLocker
lock(gs_critsect
);
2973 if ( gs_counter
== (size_t)-1 )
2979 for ( size_t n
= 0; n
< m_n
; n
++ )
2981 if ( TestDestroy() )
2991 wxThread::Sleep(100);
2997 void MyDetachedThread::OnExit()
2999 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
3001 wxCriticalSectionLocker
lock(gs_critsect
);
3002 if ( !--gs_counter
&& !m_cancelled
)
3006 void TestDetachedThreads()
3008 puts("\n*** Testing detached threads ***");
3010 static const size_t nThreads
= 3;
3011 MyDetachedThread
*threads
[nThreads
];
3013 for ( n
= 0; n
< nThreads
; n
++ )
3015 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3018 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3019 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3021 for ( n
= 0; n
< nThreads
; n
++ )
3026 // wait until all threads terminate
3032 void TestJoinableThreads()
3034 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
3036 // calc 10! in the background
3037 MyJoinableThread
thread(10);
3040 printf("\nThread terminated with exit code %lu.\n",
3041 (unsigned long)thread
.Wait());
3044 void TestThreadSuspend()
3046 puts("\n*** Testing thread suspend/resume functions ***");
3048 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3052 // this is for this demo only, in a real life program we'd use another
3053 // condition variable which would be signaled from wxThread::Entry() to
3054 // tell us that the thread really started running - but here just wait a
3055 // bit and hope that it will be enough (the problem is, of course, that
3056 // the thread might still not run when we call Pause() which will result
3058 wxThread::Sleep(300);
3060 for ( size_t n
= 0; n
< 3; n
++ )
3064 puts("\nThread suspended");
3067 // don't sleep but resume immediately the first time
3068 wxThread::Sleep(300);
3070 puts("Going to resume the thread");
3075 puts("Waiting until it terminates now");
3077 // wait until the thread terminates
3083 void TestThreadDelete()
3085 // As above, using Sleep() is only for testing here - we must use some
3086 // synchronisation object instead to ensure that the thread is still
3087 // running when we delete it - deleting a detached thread which already
3088 // terminated will lead to a crash!
3090 puts("\n*** Testing thread delete function ***");
3092 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3096 puts("\nDeleted a thread which didn't start to run yet.");
3098 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3102 wxThread::Sleep(300);
3106 puts("\nDeleted a running thread.");
3108 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
3112 wxThread::Sleep(300);
3118 puts("\nDeleted a sleeping thread.");
3120 MyJoinableThread
thread3(20);
3125 puts("\nDeleted a joinable thread.");
3127 MyJoinableThread
thread4(2);
3130 wxThread::Sleep(300);
3134 puts("\nDeleted a joinable thread which already terminated.");
3139 #endif // TEST_THREADS
3141 // ----------------------------------------------------------------------------
3143 // ----------------------------------------------------------------------------
3147 static void PrintArray(const char* name
, const wxArrayString
& array
)
3149 printf("Dump of the array '%s'\n", name
);
3151 size_t nCount
= array
.GetCount();
3152 for ( size_t n
= 0; n
< nCount
; n
++ )
3154 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
3158 static void PrintArray(const char* name
, const wxArrayInt
& array
)
3160 printf("Dump of the array '%s'\n", name
);
3162 size_t nCount
= array
.GetCount();
3163 for ( size_t n
= 0; n
< nCount
; n
++ )
3165 printf("\t%s[%u] = %d\n", name
, n
, array
[n
]);
3169 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
3170 const wxString
& second
)
3172 return first
.length() - second
.length();
3175 int wxCMPFUNC_CONV
IntCompare(int *first
,
3178 return *first
- *second
;
3181 int wxCMPFUNC_CONV
IntRevCompare(int *first
,
3184 return *second
- *first
;
3187 static void TestArrayOfInts()
3189 puts("*** Testing wxArrayInt ***\n");
3200 puts("After sort:");
3204 puts("After reverse sort:");
3205 a
.Sort(IntRevCompare
);
3209 #include "wx/dynarray.h"
3211 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
3212 #include "wx/arrimpl.cpp"
3213 WX_DEFINE_OBJARRAY(ArrayBars
);
3215 static void TestArrayOfObjects()
3217 puts("*** Testing wxObjArray ***\n");
3221 Bar
bar("second bar");
3223 printf("Initially: %u objects in the array, %u objects total.\n",
3224 bars
.GetCount(), Bar::GetNumber());
3226 bars
.Add(new Bar("first bar"));
3229 printf("Now: %u objects in the array, %u objects total.\n",
3230 bars
.GetCount(), Bar::GetNumber());
3234 printf("After Empty(): %u objects in the array, %u objects total.\n",
3235 bars
.GetCount(), Bar::GetNumber());
3238 printf("Finally: no more objects in the array, %u objects total.\n",
3242 #endif // TEST_ARRAYS
3244 // ----------------------------------------------------------------------------
3246 // ----------------------------------------------------------------------------
3250 #include "wx/timer.h"
3251 #include "wx/tokenzr.h"
3253 static void TestStringConstruction()
3255 puts("*** Testing wxString constructores ***");
3257 #define TEST_CTOR(args, res) \
3260 printf("wxString%s = %s ", #args, s.c_str()); \
3267 printf("(ERROR: should be %s)\n", res); \
3271 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
3272 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
3273 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
3274 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
3276 static const wxChar
*s
= _T("?really!");
3277 const wxChar
*start
= wxStrchr(s
, _T('r'));
3278 const wxChar
*end
= wxStrchr(s
, _T('!'));
3279 TEST_CTOR((start
, end
), _T("really"));
3284 static void TestString()
3294 for (int i
= 0; i
< 1000000; ++i
)
3298 c
= "! How'ya doin'?";
3301 c
= "Hello world! What's up?";
3306 printf ("TestString elapsed time: %ld\n", sw
.Time());
3309 static void TestPChar()
3317 for (int i
= 0; i
< 1000000; ++i
)
3319 strcpy (a
, "Hello");
3320 strcpy (b
, " world");
3321 strcpy (c
, "! How'ya doin'?");
3324 strcpy (c
, "Hello world! What's up?");
3325 if (strcmp (c
, a
) == 0)
3329 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
3332 static void TestStringSub()
3334 wxString
s("Hello, world!");
3336 puts("*** Testing wxString substring extraction ***");
3338 printf("String = '%s'\n", s
.c_str());
3339 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
3340 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
3341 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
3342 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
3343 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
3344 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
3346 static const wxChar
*prefixes
[] =
3350 _T("Hello, world!"),
3351 _T("Hello, world!!!"),
3357 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
3359 wxString prefix
= prefixes
[n
], rest
;
3360 bool rc
= s
.StartsWith(prefix
, &rest
);
3361 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
3364 printf(" (the rest is '%s')\n", rest
.c_str());
3375 static void TestStringFormat()
3377 puts("*** Testing wxString formatting ***");
3380 s
.Printf("%03d", 18);
3382 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
3383 printf("Number 18: %s\n", s
.c_str());
3388 // returns "not found" for npos, value for all others
3389 static wxString
PosToString(size_t res
)
3391 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
3392 : wxString::Format(_T("%u"), res
);
3396 static void TestStringFind()
3398 puts("*** Testing wxString find() functions ***");
3400 static const wxChar
*strToFind
= _T("ell");
3401 static const struct StringFindTest
3405 result
; // of searching "ell" in str
3408 { _T("Well, hello world"), 0, 1 },
3409 { _T("Well, hello world"), 6, 7 },
3410 { _T("Well, hello world"), 9, wxString::npos
},
3413 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
3415 const StringFindTest
& ft
= findTestData
[n
];
3416 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
3418 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
3419 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
3421 size_t resTrue
= ft
.result
;
3422 if ( res
== resTrue
)
3428 printf(_T("(ERROR: should be %s)\n"),
3429 PosToString(resTrue
).c_str());
3436 static void TestStringTokenizer()
3438 puts("*** Testing wxStringTokenizer ***");
3440 static const wxChar
*modeNames
[] =
3444 _T("return all empty"),
3449 static const struct StringTokenizerTest
3451 const wxChar
*str
; // string to tokenize
3452 const wxChar
*delims
; // delimiters to use
3453 size_t count
; // count of token
3454 wxStringTokenizerMode mode
; // how should we tokenize it
3455 } tokenizerTestData
[] =
3457 { _T(""), _T(" "), 0 },
3458 { _T("Hello, world"), _T(" "), 2 },
3459 { _T("Hello, world "), _T(" "), 2 },
3460 { _T("Hello, world"), _T(","), 2 },
3461 { _T("Hello, world!"), _T(",!"), 2 },
3462 { _T("Hello,, world!"), _T(",!"), 3 },
3463 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
3464 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
3465 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
3466 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
3467 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
3468 { _T("01/02/99"), _T("/-"), 3 },
3469 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
3472 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
3474 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
3475 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
3477 size_t count
= tkz
.CountTokens();
3478 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
3479 MakePrintable(tt
.str
).c_str(),
3481 MakePrintable(tt
.delims
).c_str(),
3482 modeNames
[tkz
.GetMode()]);
3483 if ( count
== tt
.count
)
3489 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
3494 // if we emulate strtok(), check that we do it correctly
3495 wxChar
*buf
, *s
= NULL
, *last
;
3497 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
3499 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
3500 wxStrcpy(buf
, tt
.str
);
3502 s
= wxStrtok(buf
, tt
.delims
, &last
);
3509 // now show the tokens themselves
3511 while ( tkz
.HasMoreTokens() )
3513 wxString token
= tkz
.GetNextToken();
3515 printf(_T("\ttoken %u: '%s'"),
3517 MakePrintable(token
).c_str());
3527 printf(" (ERROR: should be %s)\n", s
);
3530 s
= wxStrtok(NULL
, tt
.delims
, &last
);
3534 // nothing to compare with
3539 if ( count2
!= count
)
3541 puts(_T("\tERROR: token count mismatch"));
3550 static void TestStringReplace()
3552 puts("*** Testing wxString::replace ***");
3554 static const struct StringReplaceTestData
3556 const wxChar
*original
; // original test string
3557 size_t start
, len
; // the part to replace
3558 const wxChar
*replacement
; // the replacement string
3559 const wxChar
*result
; // and the expected result
3560 } stringReplaceTestData
[] =
3562 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
3563 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
3564 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
3565 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
3566 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
3569 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
3571 const StringReplaceTestData data
= stringReplaceTestData
[n
];
3573 wxString original
= data
.original
;
3574 original
.replace(data
.start
, data
.len
, data
.replacement
);
3576 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
3577 data
.original
, data
.start
, data
.len
, data
.replacement
,
3580 if ( original
== data
.result
)
3586 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
3593 #endif // TEST_STRINGS
3595 // ----------------------------------------------------------------------------
3597 // ----------------------------------------------------------------------------
3599 int main(int argc
, char **argv
)
3601 if ( !wxInitialize() )
3603 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
3607 puts("Sleeping for 3 seconds... z-z-z-z-z...");
3609 #endif // TEST_USLEEP
3612 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3614 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3615 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3617 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3618 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3619 { wxCMD_LINE_OPTION
, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER
},
3620 { wxCMD_LINE_OPTION
, "d", "date", "output file date", wxCMD_LINE_VAL_DATE
},
3622 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3623 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3628 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
3630 parser
.AddOption("project_name", "", "full path to project file",
3631 wxCMD_LINE_VAL_STRING
,
3632 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3634 switch ( parser
.Parse() )
3637 wxLogMessage("Help was given, terminating.");
3641 ShowCmdLine(parser
);
3645 wxLogMessage("Syntax error detected, aborting.");
3648 #endif // TEST_CMDLINE
3659 TestStringConstruction();
3662 TestStringTokenizer();
3663 TestStringReplace();
3665 #endif // TEST_STRINGS
3678 puts("*** Initially:");
3680 PrintArray("a1", a1
);
3682 wxArrayString
a2(a1
);
3683 PrintArray("a2", a2
);
3685 wxSortedArrayString
a3(a1
);
3686 PrintArray("a3", a3
);
3688 puts("*** After deleting a string from a1");
3691 PrintArray("a1", a1
);
3692 PrintArray("a2", a2
);
3693 PrintArray("a3", a3
);
3695 puts("*** After reassigning a1 to a2 and a3");
3697 PrintArray("a2", a2
);
3698 PrintArray("a3", a3
);
3700 puts("*** After sorting a1");
3702 PrintArray("a1", a1
);
3704 puts("*** After sorting a1 in reverse order");
3706 PrintArray("a1", a1
);
3708 puts("*** After sorting a1 by the string length");
3709 a1
.Sort(StringLenCompare
);
3710 PrintArray("a1", a1
);
3712 TestArrayOfObjects();
3715 #endif // TEST_ARRAYS
3721 #ifdef TEST_DLLLOADER
3723 #endif // TEST_DLLLOADER
3727 #endif // TEST_ENVIRON
3731 #endif // TEST_EXECUTE
3733 #ifdef TEST_FILECONF
3735 #endif // TEST_FILECONF
3743 for ( size_t n
= 0; n
< 8000; n
++ )
3745 s
<< (char)('A' + (n
% 26));
3749 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
3751 // this one shouldn't be truncated
3754 // but this one will because log functions use fixed size buffer
3755 // (note that it doesn't need '\n' at the end neither - will be added
3757 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
3767 int nCPUs
= wxThread::GetCPUCount();
3768 printf("This system has %d CPUs\n", nCPUs
);
3770 wxThread::SetConcurrency(nCPUs
);
3772 if ( argc
> 1 && argv
[1][0] == 't' )
3773 wxLog::AddTraceMask("thread");
3776 TestDetachedThreads();
3778 TestJoinableThreads();
3780 TestThreadSuspend();
3784 #endif // TEST_THREADS
3786 #ifdef TEST_LONGLONG
3787 // seed pseudo random generator
3788 srand((unsigned)time(NULL
));
3796 TestMultiplication();
3799 TestLongLongConversion();
3800 TestBitOperations();
3802 TestLongLongComparison();
3803 #endif // TEST_LONGLONG
3810 wxLog::AddTraceMask(_T("mime"));
3817 #ifdef TEST_INFO_FUNCTIONS
3820 #endif // TEST_INFO_FUNCTIONS
3822 #ifdef TEST_REGISTRY
3825 TestRegistryAssociation();
3826 #endif // TEST_REGISTRY
3835 TestProtocolFtpUpload();
3836 #endif // TEST_SOCKETS
3840 #endif // TEST_STREAMS
3844 #endif // TEST_TIMER
3846 #ifdef TEST_DATETIME
3859 TestTimeArithmetics();
3868 #endif // TEST_DATETIME
3874 #endif // TEST_VCARD
3878 #endif // TEST_WCHAR
3881 TestZipStreamRead();
3886 TestZlibStreamWrite();
3887 TestZlibStreamRead();