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
43 //#define TEST_ENVIRON
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());
766 static void TestMimeAssociate()
768 wxPuts(_T("*** Testing creation of filetype association ***\n"));
770 wxFileType
*ft
= g_mimeManager
.Associate
773 _T("application/x-xyz"),
774 _T("XYZFile"), // filetype (MSW only)
775 _T("XYZ File") // description (Unix only)
779 wxPuts(_T("ERROR: failed to create association!"));
783 if ( !ft
->SetOpenCommand(_T("myprogram")) )
785 wxPuts(_T("ERROR: failed to set open command!"));
794 // ----------------------------------------------------------------------------
795 // misc information functions
796 // ----------------------------------------------------------------------------
798 #ifdef TEST_INFO_FUNCTIONS
800 #include <wx/utils.h>
802 static void TestOsInfo()
804 puts("*** Testing OS info functions ***\n");
807 wxGetOsVersion(&major
, &minor
);
808 printf("Running under: %s, version %d.%d\n",
809 wxGetOsDescription().c_str(), major
, minor
);
811 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
813 printf("Host name is %s (%s).\n",
814 wxGetHostName().c_str(), wxGetFullHostName().c_str());
819 static void TestUserInfo()
821 puts("*** Testing user info functions ***\n");
823 printf("User id is:\t%s\n", wxGetUserId().c_str());
824 printf("User name is:\t%s\n", wxGetUserName().c_str());
825 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
826 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
831 #endif // TEST_INFO_FUNCTIONS
833 // ----------------------------------------------------------------------------
835 // ----------------------------------------------------------------------------
839 #include <wx/longlong.h>
840 #include <wx/timer.h>
842 // make a 64 bit number from 4 16 bit ones
843 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
845 // get a random 64 bit number
846 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
848 #if wxUSE_LONGLONG_WX
849 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
850 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
851 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
852 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
853 #endif // wxUSE_LONGLONG_WX
855 static void TestSpeed()
857 static const long max
= 100000000;
864 for ( n
= 0; n
< max
; n
++ )
869 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
872 #if wxUSE_LONGLONG_NATIVE
877 for ( n
= 0; n
< max
; n
++ )
882 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
884 #endif // wxUSE_LONGLONG_NATIVE
890 for ( n
= 0; n
< max
; n
++ )
895 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
899 static void TestLongLongConversion()
901 puts("*** Testing wxLongLong conversions ***\n");
905 for ( size_t n
= 0; n
< 100000; n
++ )
909 #if wxUSE_LONGLONG_NATIVE
910 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
912 wxASSERT_MSG( a
== b
, "conversions failure" );
914 puts("Can't do it without native long long type, test skipped.");
917 #endif // wxUSE_LONGLONG_NATIVE
919 if ( !(nTested
% 1000) )
931 static void TestMultiplication()
933 puts("*** Testing wxLongLong multiplication ***\n");
937 for ( size_t n
= 0; n
< 100000; n
++ )
942 #if wxUSE_LONGLONG_NATIVE
943 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
944 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
946 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
947 #else // !wxUSE_LONGLONG_NATIVE
948 puts("Can't do it without native long long type, test skipped.");
951 #endif // wxUSE_LONGLONG_NATIVE
953 if ( !(nTested
% 1000) )
965 static void TestDivision()
967 puts("*** Testing wxLongLong division ***\n");
971 for ( size_t n
= 0; n
< 100000; n
++ )
973 // get a random wxLongLong (shifting by 12 the MSB ensures that the
974 // multiplication will not overflow)
975 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
977 // get a random long (not wxLongLong for now) to divide it with
982 #if wxUSE_LONGLONG_NATIVE
983 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
985 wxLongLongNative p
= m
/ l
, s
= m
% l
;
986 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
987 #else // !wxUSE_LONGLONG_NATIVE
989 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
990 #endif // wxUSE_LONGLONG_NATIVE
992 if ( !(nTested
% 1000) )
1004 static void TestAddition()
1006 puts("*** Testing wxLongLong addition ***\n");
1010 for ( size_t n
= 0; n
< 100000; n
++ )
1016 #if wxUSE_LONGLONG_NATIVE
1017 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
1018 wxLongLongNative(b
.GetHi(), b
.GetLo()),
1019 "addition failure" );
1020 #else // !wxUSE_LONGLONG_NATIVE
1021 wxASSERT_MSG( c
- b
== a
, "addition failure" );
1022 #endif // wxUSE_LONGLONG_NATIVE
1024 if ( !(nTested
% 1000) )
1036 static void TestBitOperations()
1038 puts("*** Testing wxLongLong bit operation ***\n");
1042 for ( size_t n
= 0; n
< 100000; n
++ )
1046 #if wxUSE_LONGLONG_NATIVE
1047 for ( size_t n
= 0; n
< 33; n
++ )
1050 #else // !wxUSE_LONGLONG_NATIVE
1051 puts("Can't do it without native long long type, test skipped.");
1054 #endif // wxUSE_LONGLONG_NATIVE
1056 if ( !(nTested
% 1000) )
1068 static void TestLongLongComparison()
1070 puts("*** Testing wxLongLong comparison ***\n");
1072 static const long testLongs
[] =
1083 static const long ls
[2] =
1089 wxLongLongWx lls
[2];
1093 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
1097 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
1099 res
= lls
[m
] > testLongs
[n
];
1100 printf("0x%lx > 0x%lx is %s (%s)\n",
1101 ls
[m
], testLongs
[n
], res
? "true" : "false",
1102 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
1104 res
= lls
[m
] < testLongs
[n
];
1105 printf("0x%lx < 0x%lx is %s (%s)\n",
1106 ls
[m
], testLongs
[n
], res
? "true" : "false",
1107 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
1109 res
= lls
[m
] == testLongs
[n
];
1110 printf("0x%lx == 0x%lx is %s (%s)\n",
1111 ls
[m
], testLongs
[n
], res
? "true" : "false",
1112 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
1120 #endif // TEST_LONGLONG
1122 // ----------------------------------------------------------------------------
1124 // ----------------------------------------------------------------------------
1126 // this is for MSW only
1128 #undef TEST_REGISTRY
1131 #ifdef TEST_REGISTRY
1133 #include <wx/msw/registry.h>
1135 // I chose this one because I liked its name, but it probably only exists under
1137 static const wxChar
*TESTKEY
=
1138 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1140 static void TestRegistryRead()
1142 puts("*** testing registry reading ***");
1144 wxRegKey
key(TESTKEY
);
1145 printf("The test key name is '%s'.\n", key
.GetName().c_str());
1148 puts("ERROR: test key can't be opened, aborting test.");
1153 size_t nSubKeys
, nValues
;
1154 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
1156 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
1159 printf("Enumerating values:\n");
1163 bool cont
= key
.GetFirstValue(value
, dummy
);
1166 printf("Value '%s': type ", value
.c_str());
1167 switch ( key
.GetValueType(value
) )
1169 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
1170 case wxRegKey::Type_String
: printf("SZ"); break;
1171 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
1172 case wxRegKey::Type_Binary
: printf("BINARY"); break;
1173 case wxRegKey::Type_Dword
: printf("DWORD"); break;
1174 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
1175 default: printf("other (unknown)"); break;
1178 printf(", value = ");
1179 if ( key
.IsNumericValue(value
) )
1182 key
.QueryValue(value
, &val
);
1188 key
.QueryValue(value
, val
);
1189 printf("'%s'", val
.c_str());
1191 key
.QueryRawValue(value
, val
);
1192 printf(" (raw value '%s')", val
.c_str());
1197 cont
= key
.GetNextValue(value
, dummy
);
1201 static void TestRegistryAssociation()
1204 The second call to deleteself genertaes an error message, with a
1205 messagebox saying .flo is crucial to system operation, while the .ddf
1206 call also fails, but with no error message
1211 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1213 key
= "ddxf_auto_file" ;
1214 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1216 key
= "ddxf_auto_file" ;
1217 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1220 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1222 key
= "program \"%1\"" ;
1224 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1226 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1228 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1230 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1234 #endif // TEST_REGISTRY
1236 // ----------------------------------------------------------------------------
1238 // ----------------------------------------------------------------------------
1242 #include <wx/socket.h>
1243 #include <wx/protocol/protocol.h>
1244 #include <wx/protocol/ftp.h>
1245 #include <wx/protocol/http.h>
1247 static void TestSocketServer()
1249 puts("*** Testing wxSocketServer ***\n");
1251 static const int PORT
= 3000;
1256 wxSocketServer
*server
= new wxSocketServer(addr
);
1257 if ( !server
->Ok() )
1259 puts("ERROR: failed to bind");
1266 printf("Server: waiting for connection on port %d...\n", PORT
);
1268 wxSocketBase
*socket
= server
->Accept();
1271 puts("ERROR: wxSocketServer::Accept() failed.");
1275 puts("Server: got a client.");
1277 server
->SetTimeout(60); // 1 min
1279 while ( socket
->IsConnected() )
1285 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
1287 // don't log error if the client just close the connection
1288 if ( socket
->IsConnected() )
1290 puts("ERROR: in wxSocket::Read.");
1310 printf("Server: got '%s'.\n", s
.c_str());
1311 if ( s
== _T("bye") )
1318 socket
->Write(s
.MakeUpper().c_str(), s
.length());
1319 socket
->Write("\r\n", 2);
1320 printf("Server: wrote '%s'.\n", s
.c_str());
1323 puts("Server: lost a client.");
1328 // same as "delete server" but is consistent with GUI programs
1332 static void TestSocketClient()
1334 puts("*** Testing wxSocketClient ***\n");
1336 static const char *hostname
= "www.wxwindows.org";
1339 addr
.Hostname(hostname
);
1342 printf("--- Attempting to connect to %s:80...\n", hostname
);
1344 wxSocketClient client
;
1345 if ( !client
.Connect(addr
) )
1347 printf("ERROR: failed to connect to %s\n", hostname
);
1351 printf("--- Connected to %s:%u...\n",
1352 addr
.Hostname().c_str(), addr
.Service());
1356 // could use simply "GET" here I suppose
1358 wxString::Format("GET http://%s/\r\n", hostname
);
1359 client
.Write(cmdGet
, cmdGet
.length());
1360 printf("--- Sent command '%s' to the server\n",
1361 MakePrintable(cmdGet
).c_str());
1362 client
.Read(buf
, WXSIZEOF(buf
));
1363 printf("--- Server replied:\n%s", buf
);
1367 static void TestProtocolFtp()
1369 puts("*** Testing wxFTP download ***\n");
1371 wxLog::AddTraceMask(_T("ftp"));
1373 static const char *hostname
= "ftp.wxwindows.org";
1375 printf("--- Attempting to connect to %s:21...\n", hostname
);
1378 if ( !ftp
.Connect(hostname
) )
1380 printf("ERROR: failed to connect to %s\n", hostname
);
1384 printf("--- Connected to %s, current directory is '%s'\n",
1385 hostname
, ftp
.Pwd().c_str());
1386 if ( !ftp
.ChDir(_T("pub")) )
1388 puts("ERROR: failed to cd to pub");
1391 wxArrayString files
;
1392 if ( !ftp
.GetList(files
) )
1394 puts("ERROR: failed to get list of files");
1398 printf("List of files under '%s':\n", ftp
.Pwd().c_str());
1399 size_t count
= files
.GetCount();
1400 for ( size_t n
= 0; n
< count
; n
++ )
1402 printf("\t%s\n", files
[n
].c_str());
1404 puts("End of the file list");
1407 if ( !ftp
.ChDir(_T("..")) )
1409 puts("ERROR: failed to cd to ..");
1412 static const char *filename
= "welcome.msg";
1413 wxInputStream
*in
= ftp
.GetInputStream(filename
);
1416 puts("ERROR: couldn't get input stream");
1420 size_t size
= in
->StreamSize();
1421 printf("Reading file %s (%u bytes)...", filename
, size
);
1423 char *data
= new char[size
];
1424 if ( !in
->Read(data
, size
) )
1426 puts("ERROR: read error");
1430 printf("\nContents of %s:\n%s\n", filename
, data
);
1439 static void TestProtocolFtpUpload()
1441 puts("*** Testing wxFTP uploading ***\n");
1443 wxLog::AddTraceMask(_T("ftp"));
1445 static const char *hostname
= "localhost";
1447 printf("--- Attempting to connect to %s:21...\n", hostname
);
1450 ftp
.SetUser("zeitlin");
1451 ftp
.SetPassword("insert your password here");
1452 if ( !ftp
.Connect(hostname
) )
1454 printf("ERROR: failed to connect to %s\n", hostname
);
1458 printf("--- Connected to %s, current directory is '%s'\n",
1459 hostname
, ftp
.Pwd().c_str());
1462 static const char *file1
= "test1";
1463 static const char *file2
= "test2";
1464 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
1467 printf("--- Uploading to %s ---\n", file1
);
1468 out
->Write("First hello", 11);
1472 out
= ftp
.GetOutputStream(file2
);
1475 printf("--- Uploading to %s ---\n", file1
);
1476 out
->Write("Second hello", 12);
1482 #endif // TEST_SOCKETS
1484 // ----------------------------------------------------------------------------
1486 // ----------------------------------------------------------------------------
1490 #include <wx/mstream.h>
1492 static void TestMemoryStream()
1494 puts("*** Testing wxMemoryInputStream ***");
1497 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
1499 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
1500 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
1501 while ( !memInpStream
.Eof() )
1503 putchar(memInpStream
.GetC());
1506 puts("\n*** wxMemoryInputStream test done ***");
1509 #endif // TEST_STREAMS
1511 // ----------------------------------------------------------------------------
1513 // ----------------------------------------------------------------------------
1517 #include <wx/timer.h>
1518 #include <wx/utils.h>
1520 static void TestStopWatch()
1522 puts("*** Testing wxStopWatch ***\n");
1525 printf("Sleeping 3 seconds...");
1527 printf("\telapsed time: %ldms\n", sw
.Time());
1530 printf("Sleeping 2 more seconds...");
1532 printf("\telapsed time: %ldms\n", sw
.Time());
1535 printf("And 3 more seconds...");
1537 printf("\telapsed time: %ldms\n", sw
.Time());
1540 puts("\nChecking for 'backwards clock' bug...");
1541 for ( size_t n
= 0; n
< 70; n
++ )
1545 for ( size_t m
= 0; m
< 100000; m
++ )
1547 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
1549 puts("\ntime is negative - ERROR!");
1559 #endif // TEST_TIMER
1561 // ----------------------------------------------------------------------------
1563 // ----------------------------------------------------------------------------
1567 #include <wx/vcard.h>
1569 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
1572 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
1576 wxString(_T('\t'), level
).c_str(),
1577 vcObj
->GetName().c_str());
1580 switch ( vcObj
->GetType() )
1582 case wxVCardObject::String
:
1583 case wxVCardObject::UString
:
1586 vcObj
->GetValue(&val
);
1587 value
<< _T('"') << val
<< _T('"');
1591 case wxVCardObject::Int
:
1594 vcObj
->GetValue(&i
);
1595 value
.Printf(_T("%u"), i
);
1599 case wxVCardObject::Long
:
1602 vcObj
->GetValue(&l
);
1603 value
.Printf(_T("%lu"), l
);
1607 case wxVCardObject::None
:
1610 case wxVCardObject::Object
:
1611 value
= _T("<node>");
1615 value
= _T("<unknown value type>");
1619 printf(" = %s", value
.c_str());
1622 DumpVObject(level
+ 1, *vcObj
);
1625 vcObj
= vcard
.GetNextProp(&cookie
);
1629 static void DumpVCardAddresses(const wxVCard
& vcard
)
1631 puts("\nShowing all addresses from vCard:\n");
1635 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
1639 int flags
= addr
->GetFlags();
1640 if ( flags
& wxVCardAddress::Domestic
)
1642 flagsStr
<< _T("domestic ");
1644 if ( flags
& wxVCardAddress::Intl
)
1646 flagsStr
<< _T("international ");
1648 if ( flags
& wxVCardAddress::Postal
)
1650 flagsStr
<< _T("postal ");
1652 if ( flags
& wxVCardAddress::Parcel
)
1654 flagsStr
<< _T("parcel ");
1656 if ( flags
& wxVCardAddress::Home
)
1658 flagsStr
<< _T("home ");
1660 if ( flags
& wxVCardAddress::Work
)
1662 flagsStr
<< _T("work ");
1665 printf("Address %u:\n"
1667 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
1670 addr
->GetPostOffice().c_str(),
1671 addr
->GetExtAddress().c_str(),
1672 addr
->GetStreet().c_str(),
1673 addr
->GetLocality().c_str(),
1674 addr
->GetRegion().c_str(),
1675 addr
->GetPostalCode().c_str(),
1676 addr
->GetCountry().c_str()
1680 addr
= vcard
.GetNextAddress(&cookie
);
1684 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
1686 puts("\nShowing all phone numbers from vCard:\n");
1690 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
1694 int flags
= phone
->GetFlags();
1695 if ( flags
& wxVCardPhoneNumber::Voice
)
1697 flagsStr
<< _T("voice ");
1699 if ( flags
& wxVCardPhoneNumber::Fax
)
1701 flagsStr
<< _T("fax ");
1703 if ( flags
& wxVCardPhoneNumber::Cellular
)
1705 flagsStr
<< _T("cellular ");
1707 if ( flags
& wxVCardPhoneNumber::Modem
)
1709 flagsStr
<< _T("modem ");
1711 if ( flags
& wxVCardPhoneNumber::Home
)
1713 flagsStr
<< _T("home ");
1715 if ( flags
& wxVCardPhoneNumber::Work
)
1717 flagsStr
<< _T("work ");
1720 printf("Phone number %u:\n"
1725 phone
->GetNumber().c_str()
1729 phone
= vcard
.GetNextPhoneNumber(&cookie
);
1733 static void TestVCardRead()
1735 puts("*** Testing wxVCard reading ***\n");
1737 wxVCard
vcard(_T("vcard.vcf"));
1738 if ( !vcard
.IsOk() )
1740 puts("ERROR: couldn't load vCard.");
1744 // read individual vCard properties
1745 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
1749 vcObj
->GetValue(&value
);
1754 value
= _T("<none>");
1757 printf("Full name retrieved directly: %s\n", value
.c_str());
1760 if ( !vcard
.GetFullName(&value
) )
1762 value
= _T("<none>");
1765 printf("Full name from wxVCard API: %s\n", value
.c_str());
1767 // now show how to deal with multiply occuring properties
1768 DumpVCardAddresses(vcard
);
1769 DumpVCardPhoneNumbers(vcard
);
1771 // and finally show all
1772 puts("\nNow dumping the entire vCard:\n"
1773 "-----------------------------\n");
1775 DumpVObject(0, vcard
);
1779 static void TestVCardWrite()
1781 puts("*** Testing wxVCard writing ***\n");
1784 if ( !vcard
.IsOk() )
1786 puts("ERROR: couldn't create vCard.");
1791 vcard
.SetName("Zeitlin", "Vadim");
1792 vcard
.SetFullName("Vadim Zeitlin");
1793 vcard
.SetOrganization("wxWindows", "R&D");
1795 // just dump the vCard back
1796 puts("Entire vCard follows:\n");
1797 puts(vcard
.Write());
1801 #endif // TEST_VCARD
1803 // ----------------------------------------------------------------------------
1804 // wide char (Unicode) support
1805 // ----------------------------------------------------------------------------
1809 #include <wx/strconv.h>
1810 #include <wx/buffer.h>
1812 static void TestUtf8()
1814 puts("*** Testing UTF8 support ***\n");
1816 wxString testString
= "français";
1818 "************ French - Français ****************"
1819 "Juste un petit exemple pour dire que les français aussi"
1820 "ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
1823 wxWCharBuffer wchBuf
= testString
.wc_str(wxConvUTF8
);
1824 const wchar_t *pwz
= (const wchar_t *)wchBuf
;
1825 wxString
testString2(pwz
, wxConvLocal
);
1827 printf("Decoding '%s' => '%s'\n", testString
.c_str(), testString2
.c_str());
1829 char *psz
= "fran" "\xe7" "ais";
1830 size_t len
= strlen(psz
);
1831 wchar_t *pwz2
= new wchar_t[len
+ 1];
1832 for ( size_t n
= 0; n
<= len
; n
++ )
1834 pwz2
[n
] = (wchar_t)(unsigned char)psz
[n
];
1837 wxString
testString3(pwz2
, wxConvUTF8
);
1840 printf("Encoding '%s' -> '%s'\n", psz
, testString3
.c_str());
1843 #endif // TEST_WCHAR
1845 // ----------------------------------------------------------------------------
1847 // ----------------------------------------------------------------------------
1851 #include "wx/zipstrm.h"
1853 static void TestZipStreamRead()
1855 puts("*** Testing ZIP reading ***\n");
1857 wxZipInputStream
istr(_T("idx.zip"), _T("IDX.txt"));
1858 printf("Archive size: %u\n", istr
.GetSize());
1860 puts("Dumping the file:");
1861 while ( !istr
.Eof() )
1863 putchar(istr
.GetC());
1867 puts("\n----- done ------");
1872 // ----------------------------------------------------------------------------
1874 // ----------------------------------------------------------------------------
1878 #include <wx/zstream.h>
1879 #include <wx/wfstream.h>
1881 static const wxChar
*FILENAME_GZ
= _T("test.gz");
1882 static const char *TEST_DATA
= "hello and hello again";
1884 static void TestZlibStreamWrite()
1886 puts("*** Testing Zlib stream reading ***\n");
1888 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
1889 wxZlibOutputStream
ostr(fileOutStream
, 0);
1890 printf("Compressing the test string... ");
1891 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
1894 puts("(ERROR: failed)");
1901 puts("\n----- done ------");
1904 static void TestZlibStreamRead()
1906 puts("*** Testing Zlib stream reading ***\n");
1908 wxFileInputStream
fileInStream(FILENAME_GZ
);
1909 wxZlibInputStream
istr(fileInStream
);
1910 printf("Archive size: %u\n", istr
.GetSize());
1912 puts("Dumping the file:");
1913 while ( !istr
.Eof() )
1915 putchar(istr
.GetC());
1919 puts("\n----- done ------");
1924 // ----------------------------------------------------------------------------
1926 // ----------------------------------------------------------------------------
1928 #ifdef TEST_DATETIME
1930 #include <wx/date.h>
1932 #include <wx/datetime.h>
1937 wxDateTime::wxDateTime_t day
;
1938 wxDateTime::Month month
;
1940 wxDateTime::wxDateTime_t hour
, min
, sec
;
1942 wxDateTime::WeekDay wday
;
1943 time_t gmticks
, ticks
;
1945 void Init(const wxDateTime::Tm
& tm
)
1954 gmticks
= ticks
= -1;
1957 wxDateTime
DT() const
1958 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
1960 bool SameDay(const wxDateTime::Tm
& tm
) const
1962 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
1965 wxString
Format() const
1968 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
1970 wxDateTime::GetMonthName(month
).c_str(),
1972 abs(wxDateTime::ConvertYearToBC(year
)),
1973 year
> 0 ? "AD" : "BC");
1977 wxString
FormatDate() const
1980 s
.Printf("%02d-%s-%4d%s",
1982 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1983 abs(wxDateTime::ConvertYearToBC(year
)),
1984 year
> 0 ? "AD" : "BC");
1989 static const Date testDates
[] =
1991 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
1992 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
1993 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
1994 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
1995 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
1996 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
1997 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
1998 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
1999 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
2000 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
2001 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
2002 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
2003 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
2004 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
2005 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
2008 // this test miscellaneous static wxDateTime functions
2009 static void TestTimeStatic()
2011 puts("\n*** wxDateTime static methods test ***");
2013 // some info about the current date
2014 int year
= wxDateTime::GetCurrentYear();
2015 printf("Current year %d is %sa leap one and has %d days.\n",
2017 wxDateTime::IsLeapYear(year
) ? "" : "not ",
2018 wxDateTime::GetNumberOfDays(year
));
2020 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
2021 printf("Current month is '%s' ('%s') and it has %d days\n",
2022 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
2023 wxDateTime::GetMonthName(month
).c_str(),
2024 wxDateTime::GetNumberOfDays(month
));
2027 static const size_t nYears
= 5;
2028 static const size_t years
[2][nYears
] =
2030 // first line: the years to test
2031 { 1990, 1976, 2000, 2030, 1984, },
2033 // second line: TRUE if leap, FALSE otherwise
2034 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
2037 for ( size_t n
= 0; n
< nYears
; n
++ )
2039 int year
= years
[0][n
];
2040 bool should
= years
[1][n
] != 0,
2041 is
= wxDateTime::IsLeapYear(year
);
2043 printf("Year %d is %sa leap year (%s)\n",
2046 should
== is
? "ok" : "ERROR");
2048 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
2052 // test constructing wxDateTime objects
2053 static void TestTimeSet()
2055 puts("\n*** wxDateTime construction test ***");
2057 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2059 const Date
& d1
= testDates
[n
];
2060 wxDateTime dt
= d1
.DT();
2063 d2
.Init(dt
.GetTm());
2065 wxString s1
= d1
.Format(),
2068 printf("Date: %s == %s (%s)\n",
2069 s1
.c_str(), s2
.c_str(),
2070 s1
== s2
? "ok" : "ERROR");
2074 // test time zones stuff
2075 static void TestTimeZones()
2077 puts("\n*** wxDateTime timezone test ***");
2079 wxDateTime now
= wxDateTime::Now();
2081 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
2082 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
2083 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
2084 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
2085 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
2086 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
2088 wxDateTime::Tm tm
= now
.GetTm();
2089 if ( wxDateTime(tm
) != now
)
2091 printf("ERROR: got %s instead of %s\n",
2092 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
2096 // test some minimal support for the dates outside the standard range
2097 static void TestTimeRange()
2099 puts("\n*** wxDateTime out-of-standard-range dates test ***");
2101 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
2103 printf("Unix epoch:\t%s\n",
2104 wxDateTime(2440587.5).Format(fmt
).c_str());
2105 printf("Feb 29, 0: \t%s\n",
2106 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
2107 printf("JDN 0: \t%s\n",
2108 wxDateTime(0.0).Format(fmt
).c_str());
2109 printf("Jan 1, 1AD:\t%s\n",
2110 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
2111 printf("May 29, 2099:\t%s\n",
2112 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
2115 static void TestTimeTicks()
2117 puts("\n*** wxDateTime ticks test ***");
2119 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2121 const Date
& d
= testDates
[n
];
2122 if ( d
.ticks
== -1 )
2125 wxDateTime dt
= d
.DT();
2126 long ticks
= (dt
.GetValue() / 1000).ToLong();
2127 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2128 if ( ticks
== d
.ticks
)
2134 printf(" (ERROR: should be %ld, delta = %ld)\n",
2135 d
.ticks
, ticks
- d
.ticks
);
2138 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
2139 ticks
= (dt
.GetValue() / 1000).ToLong();
2140 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2141 if ( ticks
== d
.gmticks
)
2147 printf(" (ERROR: should be %ld, delta = %ld)\n",
2148 d
.gmticks
, ticks
- d
.gmticks
);
2155 // test conversions to JDN &c
2156 static void TestTimeJDN()
2158 puts("\n*** wxDateTime to JDN test ***");
2160 for ( size_t 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
);
2164 double jdn
= dt
.GetJulianDayNumber();
2166 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
2173 printf(" (ERROR: should be %f, delta = %f)\n",
2174 d
.jdn
, jdn
- d
.jdn
);
2179 // test week days computation
2180 static void TestTimeWDays()
2182 puts("\n*** wxDateTime weekday test ***");
2184 // test GetWeekDay()
2186 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2188 const Date
& d
= testDates
[n
];
2189 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2191 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
2194 wxDateTime::GetWeekDayName(wday
).c_str());
2195 if ( wday
== d
.wday
)
2201 printf(" (ERROR: should be %s)\n",
2202 wxDateTime::GetWeekDayName(d
.wday
).c_str());
2208 // test SetToWeekDay()
2209 struct WeekDateTestData
2211 Date date
; // the real date (precomputed)
2212 int nWeek
; // its week index in the month
2213 wxDateTime::WeekDay wday
; // the weekday
2214 wxDateTime::Month month
; // the month
2215 int year
; // and the year
2217 wxString
Format() const
2220 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
2222 case 1: which
= "first"; break;
2223 case 2: which
= "second"; break;
2224 case 3: which
= "third"; break;
2225 case 4: which
= "fourth"; break;
2226 case 5: which
= "fifth"; break;
2228 case -1: which
= "last"; break;
2233 which
+= " from end";
2236 s
.Printf("The %s %s of %s in %d",
2238 wxDateTime::GetWeekDayName(wday
).c_str(),
2239 wxDateTime::GetMonthName(month
).c_str(),
2246 // the array data was generated by the following python program
2248 from DateTime import *
2249 from whrandom import *
2250 from string import *
2252 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2253 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2255 week = DateTimeDelta(7)
2258 year = randint(1900, 2100)
2259 month = randint(1, 12)
2260 day = randint(1, 28)
2261 dt = DateTime(year, month, day)
2262 wday = dt.day_of_week
2264 countFromEnd = choice([-1, 1])
2267 while dt.month is month:
2268 dt = dt - countFromEnd * week
2269 weekNum = weekNum + countFromEnd
2271 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
2273 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
2274 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
2277 static const WeekDateTestData weekDatesTestData
[] =
2279 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
2280 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
2281 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
2282 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
2283 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
2284 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
2285 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
2286 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
2287 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
2288 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
2289 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
2290 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
2291 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
2292 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
2293 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
2294 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
2295 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
2296 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
2297 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
2298 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
2301 static const char *fmt
= "%d-%b-%Y";
2304 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
2306 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
2308 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
2310 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
2312 const Date
& d
= wd
.date
;
2313 if ( d
.SameDay(dt
.GetTm()) )
2319 dt
.Set(d
.day
, d
.month
, d
.year
);
2321 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
2326 // test the computation of (ISO) week numbers
2327 static void TestTimeWNumber()
2329 puts("\n*** wxDateTime week number test ***");
2331 struct WeekNumberTestData
2333 Date date
; // the date
2334 wxDateTime::wxDateTime_t week
; // the week number in the year
2335 wxDateTime::wxDateTime_t wmon
; // the week number in the month
2336 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
2337 wxDateTime::wxDateTime_t dnum
; // day number in the year
2340 // data generated with the following python script:
2342 from DateTime import *
2343 from whrandom import *
2344 from string import *
2346 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2347 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2349 def GetMonthWeek(dt):
2350 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
2351 if weekNumMonth < 0:
2352 weekNumMonth = weekNumMonth + 53
2355 def GetLastSundayBefore(dt):
2356 if dt.iso_week[2] == 7:
2359 return dt - DateTimeDelta(dt.iso_week[2])
2362 year = randint(1900, 2100)
2363 month = randint(1, 12)
2364 day = randint(1, 28)
2365 dt = DateTime(year, month, day)
2366 dayNum = dt.day_of_year
2367 weekNum = dt.iso_week[1]
2368 weekNumMonth = GetMonthWeek(dt)
2371 dtSunday = GetLastSundayBefore(dt)
2373 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
2374 weekNumMonth2 = weekNumMonth2 + 1
2375 dtSunday = dtSunday - DateTimeDelta(7)
2377 data = { 'day': rjust(`day`, 2), \
2378 'month': monthNames[month - 1], \
2380 'weekNum': rjust(`weekNum`, 2), \
2381 'weekNumMonth': weekNumMonth, \
2382 'weekNumMonth2': weekNumMonth2, \
2383 'dayNum': rjust(`dayNum`, 3) }
2385 print " { { %(day)s, "\
2386 "wxDateTime::%(month)s, "\
2389 "%(weekNumMonth)s, "\
2390 "%(weekNumMonth2)s, "\
2391 "%(dayNum)s }," % data
2394 static const WeekNumberTestData weekNumberTestDates
[] =
2396 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
2397 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
2398 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
2399 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
2400 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
2401 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
2402 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
2403 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
2404 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
2405 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
2406 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
2407 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
2408 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
2409 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
2410 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
2411 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
2412 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
2413 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
2414 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
2415 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
2418 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
2420 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
2421 const Date
& d
= wn
.date
;
2423 wxDateTime dt
= d
.DT();
2425 wxDateTime::wxDateTime_t
2426 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
2427 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2428 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2429 dnum
= dt
.GetDayOfYear();
2431 printf("%s: the day number is %d",
2432 d
.FormatDate().c_str(), dnum
);
2433 if ( dnum
== wn
.dnum
)
2439 printf(" (ERROR: should be %d)", wn
.dnum
);
2442 printf(", week in month is %d", wmon
);
2443 if ( wmon
== wn
.wmon
)
2449 printf(" (ERROR: should be %d)", wn
.wmon
);
2452 printf(" or %d", wmon2
);
2453 if ( wmon2
== wn
.wmon2
)
2459 printf(" (ERROR: should be %d)", wn
.wmon2
);
2462 printf(", week in year is %d", week
);
2463 if ( week
== wn
.week
)
2469 printf(" (ERROR: should be %d)\n", wn
.week
);
2474 // test DST calculations
2475 static void TestTimeDST()
2477 puts("\n*** wxDateTime DST test ***");
2479 printf("DST is%s in effect now.\n\n",
2480 wxDateTime::Now().IsDST() ? "" : " not");
2482 // taken from http://www.energy.ca.gov/daylightsaving.html
2483 static const Date datesDST
[2][2004 - 1900 + 1] =
2486 { 1, wxDateTime::Apr
, 1990 },
2487 { 7, wxDateTime::Apr
, 1991 },
2488 { 5, wxDateTime::Apr
, 1992 },
2489 { 4, wxDateTime::Apr
, 1993 },
2490 { 3, wxDateTime::Apr
, 1994 },
2491 { 2, wxDateTime::Apr
, 1995 },
2492 { 7, wxDateTime::Apr
, 1996 },
2493 { 6, wxDateTime::Apr
, 1997 },
2494 { 5, wxDateTime::Apr
, 1998 },
2495 { 4, wxDateTime::Apr
, 1999 },
2496 { 2, wxDateTime::Apr
, 2000 },
2497 { 1, wxDateTime::Apr
, 2001 },
2498 { 7, wxDateTime::Apr
, 2002 },
2499 { 6, wxDateTime::Apr
, 2003 },
2500 { 4, wxDateTime::Apr
, 2004 },
2503 { 28, wxDateTime::Oct
, 1990 },
2504 { 27, wxDateTime::Oct
, 1991 },
2505 { 25, wxDateTime::Oct
, 1992 },
2506 { 31, wxDateTime::Oct
, 1993 },
2507 { 30, wxDateTime::Oct
, 1994 },
2508 { 29, wxDateTime::Oct
, 1995 },
2509 { 27, wxDateTime::Oct
, 1996 },
2510 { 26, wxDateTime::Oct
, 1997 },
2511 { 25, wxDateTime::Oct
, 1998 },
2512 { 31, wxDateTime::Oct
, 1999 },
2513 { 29, wxDateTime::Oct
, 2000 },
2514 { 28, wxDateTime::Oct
, 2001 },
2515 { 27, wxDateTime::Oct
, 2002 },
2516 { 26, wxDateTime::Oct
, 2003 },
2517 { 31, wxDateTime::Oct
, 2004 },
2522 for ( year
= 1990; year
< 2005; year
++ )
2524 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
2525 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
2527 printf("DST period in the US for year %d: from %s to %s",
2528 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
2530 size_t n
= year
- 1990;
2531 const Date
& dBegin
= datesDST
[0][n
];
2532 const Date
& dEnd
= datesDST
[1][n
];
2534 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
2540 printf(" (ERROR: should be %s %d to %s %d)\n",
2541 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
2542 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
2548 for ( year
= 1990; year
< 2005; year
++ )
2550 printf("DST period in Europe for year %d: from %s to %s\n",
2552 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
2553 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
2557 // test wxDateTime -> text conversion
2558 static void TestTimeFormat()
2560 puts("\n*** wxDateTime formatting test ***");
2562 // some information may be lost during conversion, so store what kind
2563 // of info should we recover after a round trip
2566 CompareNone
, // don't try comparing
2567 CompareBoth
, // dates and times should be identical
2568 CompareDate
, // dates only
2569 CompareTime
// time only
2574 CompareKind compareKind
;
2576 } formatTestFormats
[] =
2578 { CompareBoth
, "---> %c" },
2579 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
2580 { CompareBoth
, "Date is %x, time is %X" },
2581 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
2582 { CompareNone
, "The day of year: %j, the week of year: %W" },
2583 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
2586 static const Date formatTestDates
[] =
2588 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
2589 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
2591 // this test can't work for other centuries because it uses two digit
2592 // years in formats, so don't even try it
2593 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
2594 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
2595 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
2599 // an extra test (as it doesn't depend on date, don't do it in the loop)
2600 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
2602 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
2606 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
2607 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
2609 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
2610 printf("%s", s
.c_str());
2612 // what can we recover?
2613 int kind
= formatTestFormats
[n
].compareKind
;
2617 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
2620 // converion failed - should it have?
2621 if ( kind
== CompareNone
)
2624 puts(" (ERROR: conversion back failed)");
2628 // should have parsed the entire string
2629 puts(" (ERROR: conversion back stopped too soon)");
2633 bool equal
= FALSE
; // suppress compilaer warning
2641 equal
= dt
.IsSameDate(dt2
);
2645 equal
= dt
.IsSameTime(dt2
);
2651 printf(" (ERROR: got back '%s' instead of '%s')\n",
2652 dt2
.Format().c_str(), dt
.Format().c_str());
2663 // test text -> wxDateTime conversion
2664 static void TestTimeParse()
2666 puts("\n*** wxDateTime parse test ***");
2668 struct ParseTestData
2675 static const ParseTestData parseTestDates
[] =
2677 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
2678 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
2681 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
2683 const char *format
= parseTestDates
[n
].format
;
2685 printf("%s => ", format
);
2688 if ( dt
.ParseRfc822Date(format
) )
2690 printf("%s ", dt
.Format().c_str());
2692 if ( parseTestDates
[n
].good
)
2694 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
2701 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
2706 puts("(ERROR: bad format)");
2711 printf("bad format (%s)\n",
2712 parseTestDates
[n
].good
? "ERROR" : "ok");
2717 static void TestInteractive()
2719 puts("\n*** interactive wxDateTime tests ***");
2725 printf("Enter a date: ");
2726 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2729 // kill the last '\n'
2730 buf
[strlen(buf
) - 1] = 0;
2733 const char *p
= dt
.ParseDate(buf
);
2736 printf("ERROR: failed to parse the date '%s'.\n", buf
);
2742 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
2745 printf("%s: day %u, week of month %u/%u, week of year %u\n",
2746 dt
.Format("%b %d, %Y").c_str(),
2748 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2749 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2750 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
2753 puts("\n*** done ***");
2756 static void TestTimeMS()
2758 puts("*** testing millisecond-resolution support in wxDateTime ***");
2760 wxDateTime dt1
= wxDateTime::Now(),
2761 dt2
= wxDateTime::UNow();
2763 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
2764 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2765 printf("Dummy loop: ");
2766 for ( int i
= 0; i
< 6000; i
++ )
2768 //for ( int j = 0; j < 10; j++ )
2771 s
.Printf("%g", sqrt(i
));
2780 dt2
= wxDateTime::UNow();
2781 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2783 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
2785 puts("\n*** done ***");
2788 static void TestTimeArithmetics()
2790 puts("\n*** testing arithmetic operations on wxDateTime ***");
2792 static const struct ArithmData
2794 ArithmData(const wxDateSpan
& sp
, const char *nam
)
2795 : span(sp
), name(nam
) { }
2799 } testArithmData
[] =
2801 ArithmData(wxDateSpan::Day(), "day"),
2802 ArithmData(wxDateSpan::Week(), "week"),
2803 ArithmData(wxDateSpan::Month(), "month"),
2804 ArithmData(wxDateSpan::Year(), "year"),
2805 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
2808 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
2810 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
2812 wxDateSpan span
= testArithmData
[n
].span
;
2816 const char *name
= testArithmData
[n
].name
;
2817 printf("%s + %s = %s, %s - %s = %s\n",
2818 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
2819 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
2821 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
2822 if ( dt1
- span
== dt
)
2828 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2831 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
2832 if ( dt2
+ span
== dt
)
2838 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2841 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
2842 if ( dt2
+ 2*span
== dt1
)
2848 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
2855 static void TestTimeHolidays()
2857 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
2859 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
2860 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
2861 dtEnd
= dtStart
.GetLastMonthDay();
2863 wxDateTimeArray hol
;
2864 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
2866 const wxChar
*format
= "%d-%b-%Y (%a)";
2868 printf("All holidays between %s and %s:\n",
2869 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
2871 size_t count
= hol
.GetCount();
2872 for ( size_t n
= 0; n
< count
; n
++ )
2874 printf("\t%s\n", hol
[n
].Format(format
).c_str());
2880 static void TestTimeZoneBug()
2882 puts("\n*** testing for DST/timezone bug ***\n");
2884 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
2885 for ( int i
= 0; i
< 31; i
++ )
2887 printf("Date %s: week day %s.\n",
2888 date
.Format(_T("%d-%m-%Y")).c_str(),
2889 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
2891 date
+= wxDateSpan::Day();
2899 // test compatibility with the old wxDate/wxTime classes
2900 static void TestTimeCompatibility()
2902 puts("\n*** wxDateTime compatibility test ***");
2904 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
2905 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
2907 double jdnNow
= wxDateTime::Now().GetJDN();
2908 long jdnMidnight
= (long)(jdnNow
- 0.5);
2909 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
2911 jdnMidnight
= wxDate().Set().GetJulianDate();
2912 printf("wxDateTime for today: %s\n",
2913 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
2915 int flags
= wxEUROPEAN
;//wxFULL;
2918 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
2919 for ( int n
= 0; n
< 7; n
++ )
2921 printf("Previous %s is %s\n",
2922 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
2923 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
2929 #endif // TEST_DATETIME
2931 // ----------------------------------------------------------------------------
2933 // ----------------------------------------------------------------------------
2937 #include <wx/thread.h>
2939 static size_t gs_counter
= (size_t)-1;
2940 static wxCriticalSection gs_critsect
;
2941 static wxCondition gs_cond
;
2943 class MyJoinableThread
: public wxThread
2946 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
2947 { m_n
= n
; Create(); }
2949 // thread execution starts here
2950 virtual ExitCode
Entry();
2956 wxThread::ExitCode
MyJoinableThread::Entry()
2958 unsigned long res
= 1;
2959 for ( size_t n
= 1; n
< m_n
; n
++ )
2963 // it's a loooong calculation :-)
2967 return (ExitCode
)res
;
2970 class MyDetachedThread
: public wxThread
2973 MyDetachedThread(size_t n
, char ch
)
2977 m_cancelled
= FALSE
;
2982 // thread execution starts here
2983 virtual ExitCode
Entry();
2986 virtual void OnExit();
2989 size_t m_n
; // number of characters to write
2990 char m_ch
; // character to write
2992 bool m_cancelled
; // FALSE if we exit normally
2995 wxThread::ExitCode
MyDetachedThread::Entry()
2998 wxCriticalSectionLocker
lock(gs_critsect
);
2999 if ( gs_counter
== (size_t)-1 )
3005 for ( size_t n
= 0; n
< m_n
; n
++ )
3007 if ( TestDestroy() )
3017 wxThread::Sleep(100);
3023 void MyDetachedThread::OnExit()
3025 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
3027 wxCriticalSectionLocker
lock(gs_critsect
);
3028 if ( !--gs_counter
&& !m_cancelled
)
3032 void TestDetachedThreads()
3034 puts("\n*** Testing detached threads ***");
3036 static const size_t nThreads
= 3;
3037 MyDetachedThread
*threads
[nThreads
];
3039 for ( n
= 0; n
< nThreads
; n
++ )
3041 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3044 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3045 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3047 for ( n
= 0; n
< nThreads
; n
++ )
3052 // wait until all threads terminate
3058 void TestJoinableThreads()
3060 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
3062 // calc 10! in the background
3063 MyJoinableThread
thread(10);
3066 printf("\nThread terminated with exit code %lu.\n",
3067 (unsigned long)thread
.Wait());
3070 void TestThreadSuspend()
3072 puts("\n*** Testing thread suspend/resume functions ***");
3074 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3078 // this is for this demo only, in a real life program we'd use another
3079 // condition variable which would be signaled from wxThread::Entry() to
3080 // tell us that the thread really started running - but here just wait a
3081 // bit and hope that it will be enough (the problem is, of course, that
3082 // the thread might still not run when we call Pause() which will result
3084 wxThread::Sleep(300);
3086 for ( size_t n
= 0; n
< 3; n
++ )
3090 puts("\nThread suspended");
3093 // don't sleep but resume immediately the first time
3094 wxThread::Sleep(300);
3096 puts("Going to resume the thread");
3101 puts("Waiting until it terminates now");
3103 // wait until the thread terminates
3109 void TestThreadDelete()
3111 // As above, using Sleep() is only for testing here - we must use some
3112 // synchronisation object instead to ensure that the thread is still
3113 // running when we delete it - deleting a detached thread which already
3114 // terminated will lead to a crash!
3116 puts("\n*** Testing thread delete function ***");
3118 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3122 puts("\nDeleted a thread which didn't start to run yet.");
3124 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3128 wxThread::Sleep(300);
3132 puts("\nDeleted a running thread.");
3134 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
3138 wxThread::Sleep(300);
3144 puts("\nDeleted a sleeping thread.");
3146 MyJoinableThread
thread3(20);
3151 puts("\nDeleted a joinable thread.");
3153 MyJoinableThread
thread4(2);
3156 wxThread::Sleep(300);
3160 puts("\nDeleted a joinable thread which already terminated.");
3165 #endif // TEST_THREADS
3167 // ----------------------------------------------------------------------------
3169 // ----------------------------------------------------------------------------
3173 static void PrintArray(const char* name
, const wxArrayString
& array
)
3175 printf("Dump of the array '%s'\n", name
);
3177 size_t nCount
= array
.GetCount();
3178 for ( size_t n
= 0; n
< nCount
; n
++ )
3180 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
3184 static void PrintArray(const char* name
, const wxArrayInt
& array
)
3186 printf("Dump of the array '%s'\n", name
);
3188 size_t nCount
= array
.GetCount();
3189 for ( size_t n
= 0; n
< nCount
; n
++ )
3191 printf("\t%s[%u] = %d\n", name
, n
, array
[n
]);
3195 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
3196 const wxString
& second
)
3198 return first
.length() - second
.length();
3201 int wxCMPFUNC_CONV
IntCompare(int *first
,
3204 return *first
- *second
;
3207 int wxCMPFUNC_CONV
IntRevCompare(int *first
,
3210 return *second
- *first
;
3213 static void TestArrayOfInts()
3215 puts("*** Testing wxArrayInt ***\n");
3226 puts("After sort:");
3230 puts("After reverse sort:");
3231 a
.Sort(IntRevCompare
);
3235 #include "wx/dynarray.h"
3237 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
3238 #include "wx/arrimpl.cpp"
3239 WX_DEFINE_OBJARRAY(ArrayBars
);
3241 static void TestArrayOfObjects()
3243 puts("*** Testing wxObjArray ***\n");
3247 Bar
bar("second bar");
3249 printf("Initially: %u objects in the array, %u objects total.\n",
3250 bars
.GetCount(), Bar::GetNumber());
3252 bars
.Add(new Bar("first bar"));
3255 printf("Now: %u objects in the array, %u objects total.\n",
3256 bars
.GetCount(), Bar::GetNumber());
3260 printf("After Empty(): %u objects in the array, %u objects total.\n",
3261 bars
.GetCount(), Bar::GetNumber());
3264 printf("Finally: no more objects in the array, %u objects total.\n",
3268 #endif // TEST_ARRAYS
3270 // ----------------------------------------------------------------------------
3272 // ----------------------------------------------------------------------------
3276 #include "wx/timer.h"
3277 #include "wx/tokenzr.h"
3279 static void TestStringConstruction()
3281 puts("*** Testing wxString constructores ***");
3283 #define TEST_CTOR(args, res) \
3286 printf("wxString%s = %s ", #args, s.c_str()); \
3293 printf("(ERROR: should be %s)\n", res); \
3297 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
3298 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
3299 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
3300 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
3302 static const wxChar
*s
= _T("?really!");
3303 const wxChar
*start
= wxStrchr(s
, _T('r'));
3304 const wxChar
*end
= wxStrchr(s
, _T('!'));
3305 TEST_CTOR((start
, end
), _T("really"));
3310 static void TestString()
3320 for (int i
= 0; i
< 1000000; ++i
)
3324 c
= "! How'ya doin'?";
3327 c
= "Hello world! What's up?";
3332 printf ("TestString elapsed time: %ld\n", sw
.Time());
3335 static void TestPChar()
3343 for (int i
= 0; i
< 1000000; ++i
)
3345 strcpy (a
, "Hello");
3346 strcpy (b
, " world");
3347 strcpy (c
, "! How'ya doin'?");
3350 strcpy (c
, "Hello world! What's up?");
3351 if (strcmp (c
, a
) == 0)
3355 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
3358 static void TestStringSub()
3360 wxString
s("Hello, world!");
3362 puts("*** Testing wxString substring extraction ***");
3364 printf("String = '%s'\n", s
.c_str());
3365 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
3366 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
3367 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
3368 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
3369 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
3370 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
3372 static const wxChar
*prefixes
[] =
3376 _T("Hello, world!"),
3377 _T("Hello, world!!!"),
3383 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
3385 wxString prefix
= prefixes
[n
], rest
;
3386 bool rc
= s
.StartsWith(prefix
, &rest
);
3387 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
3390 printf(" (the rest is '%s')\n", rest
.c_str());
3401 static void TestStringFormat()
3403 puts("*** Testing wxString formatting ***");
3406 s
.Printf("%03d", 18);
3408 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
3409 printf("Number 18: %s\n", s
.c_str());
3414 // returns "not found" for npos, value for all others
3415 static wxString
PosToString(size_t res
)
3417 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
3418 : wxString::Format(_T("%u"), res
);
3422 static void TestStringFind()
3424 puts("*** Testing wxString find() functions ***");
3426 static const wxChar
*strToFind
= _T("ell");
3427 static const struct StringFindTest
3431 result
; // of searching "ell" in str
3434 { _T("Well, hello world"), 0, 1 },
3435 { _T("Well, hello world"), 6, 7 },
3436 { _T("Well, hello world"), 9, wxString::npos
},
3439 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
3441 const StringFindTest
& ft
= findTestData
[n
];
3442 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
3444 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
3445 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
3447 size_t resTrue
= ft
.result
;
3448 if ( res
== resTrue
)
3454 printf(_T("(ERROR: should be %s)\n"),
3455 PosToString(resTrue
).c_str());
3462 static void TestStringTokenizer()
3464 puts("*** Testing wxStringTokenizer ***");
3466 static const wxChar
*modeNames
[] =
3470 _T("return all empty"),
3475 static const struct StringTokenizerTest
3477 const wxChar
*str
; // string to tokenize
3478 const wxChar
*delims
; // delimiters to use
3479 size_t count
; // count of token
3480 wxStringTokenizerMode mode
; // how should we tokenize it
3481 } tokenizerTestData
[] =
3483 { _T(""), _T(" "), 0 },
3484 { _T("Hello, world"), _T(" "), 2 },
3485 { _T("Hello, world "), _T(" "), 2 },
3486 { _T("Hello, world"), _T(","), 2 },
3487 { _T("Hello, world!"), _T(",!"), 2 },
3488 { _T("Hello,, world!"), _T(",!"), 3 },
3489 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
3490 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
3491 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
3492 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
3493 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
3494 { _T("01/02/99"), _T("/-"), 3 },
3495 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
3498 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
3500 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
3501 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
3503 size_t count
= tkz
.CountTokens();
3504 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
3505 MakePrintable(tt
.str
).c_str(),
3507 MakePrintable(tt
.delims
).c_str(),
3508 modeNames
[tkz
.GetMode()]);
3509 if ( count
== tt
.count
)
3515 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
3520 // if we emulate strtok(), check that we do it correctly
3521 wxChar
*buf
, *s
= NULL
, *last
;
3523 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
3525 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
3526 wxStrcpy(buf
, tt
.str
);
3528 s
= wxStrtok(buf
, tt
.delims
, &last
);
3535 // now show the tokens themselves
3537 while ( tkz
.HasMoreTokens() )
3539 wxString token
= tkz
.GetNextToken();
3541 printf(_T("\ttoken %u: '%s'"),
3543 MakePrintable(token
).c_str());
3553 printf(" (ERROR: should be %s)\n", s
);
3556 s
= wxStrtok(NULL
, tt
.delims
, &last
);
3560 // nothing to compare with
3565 if ( count2
!= count
)
3567 puts(_T("\tERROR: token count mismatch"));
3576 static void TestStringReplace()
3578 puts("*** Testing wxString::replace ***");
3580 static const struct StringReplaceTestData
3582 const wxChar
*original
; // original test string
3583 size_t start
, len
; // the part to replace
3584 const wxChar
*replacement
; // the replacement string
3585 const wxChar
*result
; // and the expected result
3586 } stringReplaceTestData
[] =
3588 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
3589 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
3590 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
3591 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
3592 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
3595 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
3597 const StringReplaceTestData data
= stringReplaceTestData
[n
];
3599 wxString original
= data
.original
;
3600 original
.replace(data
.start
, data
.len
, data
.replacement
);
3602 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
3603 data
.original
, data
.start
, data
.len
, data
.replacement
,
3606 if ( original
== data
.result
)
3612 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
3619 #endif // TEST_STRINGS
3621 // ----------------------------------------------------------------------------
3623 // ----------------------------------------------------------------------------
3625 int main(int argc
, char **argv
)
3627 if ( !wxInitialize() )
3629 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
3633 puts("Sleeping for 3 seconds... z-z-z-z-z...");
3635 #endif // TEST_USLEEP
3638 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3640 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3641 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3643 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3644 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3645 { wxCMD_LINE_OPTION
, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER
},
3646 { wxCMD_LINE_OPTION
, "d", "date", "output file date", wxCMD_LINE_VAL_DATE
},
3648 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3649 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3654 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
3656 parser
.AddOption("project_name", "", "full path to project file",
3657 wxCMD_LINE_VAL_STRING
,
3658 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3660 switch ( parser
.Parse() )
3663 wxLogMessage("Help was given, terminating.");
3667 ShowCmdLine(parser
);
3671 wxLogMessage("Syntax error detected, aborting.");
3674 #endif // TEST_CMDLINE
3685 TestStringConstruction();
3688 TestStringTokenizer();
3689 TestStringReplace();
3691 #endif // TEST_STRINGS
3704 puts("*** Initially:");
3706 PrintArray("a1", a1
);
3708 wxArrayString
a2(a1
);
3709 PrintArray("a2", a2
);
3711 wxSortedArrayString
a3(a1
);
3712 PrintArray("a3", a3
);
3714 puts("*** After deleting a string from a1");
3717 PrintArray("a1", a1
);
3718 PrintArray("a2", a2
);
3719 PrintArray("a3", a3
);
3721 puts("*** After reassigning a1 to a2 and a3");
3723 PrintArray("a2", a2
);
3724 PrintArray("a3", a3
);
3726 puts("*** After sorting a1");
3728 PrintArray("a1", a1
);
3730 puts("*** After sorting a1 in reverse order");
3732 PrintArray("a1", a1
);
3734 puts("*** After sorting a1 by the string length");
3735 a1
.Sort(StringLenCompare
);
3736 PrintArray("a1", a1
);
3738 TestArrayOfObjects();
3741 #endif // TEST_ARRAYS
3747 #ifdef TEST_DLLLOADER
3749 #endif // TEST_DLLLOADER
3753 #endif // TEST_ENVIRON
3757 #endif // TEST_EXECUTE
3759 #ifdef TEST_FILECONF
3761 #endif // TEST_FILECONF
3769 for ( size_t n
= 0; n
< 8000; n
++ )
3771 s
<< (char)('A' + (n
% 26));
3775 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
3777 // this one shouldn't be truncated
3780 // but this one will because log functions use fixed size buffer
3781 // (note that it doesn't need '\n' at the end neither - will be added
3783 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
3793 int nCPUs
= wxThread::GetCPUCount();
3794 printf("This system has %d CPUs\n", nCPUs
);
3796 wxThread::SetConcurrency(nCPUs
);
3798 if ( argc
> 1 && argv
[1][0] == 't' )
3799 wxLog::AddTraceMask("thread");
3802 TestDetachedThreads();
3804 TestJoinableThreads();
3806 TestThreadSuspend();
3810 #endif // TEST_THREADS
3812 #ifdef TEST_LONGLONG
3813 // seed pseudo random generator
3814 srand((unsigned)time(NULL
));
3822 TestMultiplication();
3825 TestLongLongConversion();
3826 TestBitOperations();
3828 TestLongLongComparison();
3829 #endif // TEST_LONGLONG
3836 wxLog::AddTraceMask(_T("mime"));
3843 TestMimeAssociate();
3846 #ifdef TEST_INFO_FUNCTIONS
3849 #endif // TEST_INFO_FUNCTIONS
3851 #ifdef TEST_REGISTRY
3854 TestRegistryAssociation();
3855 #endif // TEST_REGISTRY
3864 TestProtocolFtpUpload();
3865 #endif // TEST_SOCKETS
3869 #endif // TEST_STREAMS
3873 #endif // TEST_TIMER
3875 #ifdef TEST_DATETIME
3888 TestTimeArithmetics();
3897 #endif // TEST_DATETIME
3903 #endif // TEST_VCARD
3907 #endif // TEST_WCHAR
3910 TestZipStreamRead();
3915 TestZlibStreamWrite();
3916 TestZlibStreamRead();