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 void TestEnvironment()
297 const wxChar
*var
= _T("wxTestVar");
299 puts("*** testing environment access functions ***");
301 printf("Initially getenv(%s) = '%s'\n", var
, wxGetenv(var
));
302 wxSetEnv(var
, _T("value for wxTestVar"));
303 printf("After wxSetEnv: getenv(%s) = '%s'\n", var
, wxGetenv(var
));
304 wxSetEnv(var
, _T("another value"));
305 printf("After 2nd wxSetEnv: getenv(%s) = '%s'\n", var
, wxGetenv(var
));
307 printf("After wxUnsetEnv: getenv(%s) = '%s'\n", var
, wxGetenv(var
));
310 #endif // TEST_ENVIRON
312 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
318 #include <wx/utils.h>
320 static void TestExecute()
322 puts("*** testing wxExecute ***");
325 #define COMMAND "cat -n ../../Makefile" // "echo hi"
326 #define SHELL_COMMAND "echo hi from shell"
327 #define REDIRECT_COMMAND COMMAND // "date"
328 #elif defined(__WXMSW__)
329 #define COMMAND "command.com -c 'echo hi'"
330 #define SHELL_COMMAND "echo hi"
331 #define REDIRECT_COMMAND COMMAND
333 #error "no command to exec"
336 printf("Testing wxShell: ");
338 if ( wxShell(SHELL_COMMAND
) )
343 printf("Testing wxExecute: ");
345 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
350 #if 0 // no, it doesn't work (yet?)
351 printf("Testing async wxExecute: ");
353 if ( wxExecute(COMMAND
) != 0 )
354 puts("Ok (command launched).");
359 printf("Testing wxExecute with redirection:\n");
360 wxArrayString output
;
361 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
367 size_t count
= output
.GetCount();
368 for ( size_t n
= 0; n
< count
; n
++ )
370 printf("\t%s\n", output
[n
].c_str());
377 #endif // TEST_EXECUTE
379 // ----------------------------------------------------------------------------
381 // ----------------------------------------------------------------------------
386 #include <wx/textfile.h>
388 static void TestFileRead()
390 puts("*** wxFile read test ***");
392 wxFile
file(_T("testdata.fc"));
393 if ( file
.IsOpened() )
395 printf("File length: %lu\n", file
.Length());
397 puts("File dump:\n----------");
399 static const off_t len
= 1024;
403 off_t nRead
= file
.Read(buf
, len
);
404 if ( nRead
== wxInvalidOffset
)
406 printf("Failed to read the file.");
410 fwrite(buf
, nRead
, 1, stdout
);
420 printf("ERROR: can't open test file.\n");
426 static void TestTextFileRead()
428 puts("*** wxTextFile read test ***");
430 wxTextFile
file(_T("testdata.fc"));
433 printf("Number of lines: %u\n", file
.GetLineCount());
434 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
438 puts("\nDumping the entire file:");
439 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
441 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
443 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
445 puts("\nAnd now backwards:");
446 for ( s
= file
.GetLastLine();
447 file
.GetCurrentLine() != 0;
448 s
= file
.GetPrevLine() )
450 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
452 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
456 printf("ERROR: can't open '%s'\n", file
.GetName());
464 // ----------------------------------------------------------------------------
466 // ----------------------------------------------------------------------------
470 #include <wx/confbase.h>
471 #include <wx/fileconf.h>
473 static const struct FileConfTestData
475 const wxChar
*name
; // value name
476 const wxChar
*value
; // the value from the file
479 { _T("value1"), _T("one") },
480 { _T("value2"), _T("two") },
481 { _T("novalue"), _T("default") },
484 static void TestFileConfRead()
486 puts("*** testing wxFileConfig loading/reading ***");
488 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
489 _T("testdata.fc"), wxEmptyString
,
490 wxCONFIG_USE_RELATIVE_PATH
);
492 // test simple reading
493 puts("\nReading config file:");
494 wxString
defValue(_T("default")), value
;
495 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
497 const FileConfTestData
& data
= fcTestData
[n
];
498 value
= fileconf
.Read(data
.name
, defValue
);
499 printf("\t%s = %s ", data
.name
, value
.c_str());
500 if ( value
== data
.value
)
506 printf("(ERROR: should be %s)\n", data
.value
);
510 // test enumerating the entries
511 puts("\nEnumerating all root entries:");
514 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
517 printf("\t%s = %s\n",
519 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
521 cont
= fileconf
.GetNextEntry(name
, dummy
);
525 #endif // TEST_FILECONF
527 // ----------------------------------------------------------------------------
529 // ----------------------------------------------------------------------------
537 Foo(int n_
) { n
= n_
; count
++; }
545 size_t Foo::count
= 0;
547 WX_DECLARE_LIST(Foo
, wxListFoos
);
548 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
550 #include <wx/listimpl.cpp>
552 WX_DEFINE_LIST(wxListFoos
);
554 static void TestHash()
556 puts("*** Testing wxHashTable ***\n");
560 hash
.DeleteContents(TRUE
);
562 printf("Hash created: %u foos in hash, %u foos totally\n",
563 hash
.GetCount(), Foo::count
);
565 static const int hashTestData
[] =
567 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
571 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
573 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
576 printf("Hash filled: %u foos in hash, %u foos totally\n",
577 hash
.GetCount(), Foo::count
);
579 puts("Hash access test:");
580 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
582 printf("\tGetting element with key %d, value %d: ",
584 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
587 printf("ERROR, not found.\n");
591 printf("%d (%s)\n", foo
->n
,
592 (size_t)foo
->n
== n
? "ok" : "ERROR");
596 printf("\nTrying to get an element not in hash: ");
598 if ( hash
.Get(1234) || hash
.Get(1, 0) )
600 puts("ERROR: found!");
604 puts("ok (not found)");
608 printf("Hash destroyed: %u foos left\n", Foo::count
);
613 // ----------------------------------------------------------------------------
615 // ----------------------------------------------------------------------------
621 WX_DECLARE_LIST(Bar
, wxListBars
);
622 #include <wx/listimpl.cpp>
623 WX_DEFINE_LIST(wxListBars
);
625 static void TestListCtor()
627 puts("*** Testing wxList construction ***\n");
631 list1
.Append(new Bar(_T("first")));
632 list1
.Append(new Bar(_T("second")));
634 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
635 list1
.GetCount(), Bar::GetNumber());
640 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
641 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
643 list1
.DeleteContents(TRUE
);
646 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
651 // ----------------------------------------------------------------------------
653 // ----------------------------------------------------------------------------
657 #include <wx/mimetype.h>
659 static wxMimeTypesManager g_mimeManager
;
661 static void TestMimeEnum()
663 wxArrayString mimetypes
;
665 size_t count
= g_mimeManager
.EnumAllFileTypes(mimetypes
);
667 printf("*** All %u known filetypes: ***\n", count
);
672 for ( size_t n
= 0; n
< count
; n
++ )
674 wxFileType
*filetype
= g_mimeManager
.GetFileTypeFromMimeType(mimetypes
[n
]);
677 printf("nothing known about the filetype '%s'!\n",
678 mimetypes
[n
].c_str());
682 filetype
->GetDescription(&desc
);
683 filetype
->GetExtensions(exts
);
685 filetype
->GetIcon(NULL
);
688 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
695 printf("\t%s: %s (%s)\n",
696 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
700 static void TestMimeOverride()
702 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
704 wxString mailcap
= _T("/tmp/mailcap"),
705 mimetypes
= _T("/tmp/mime.types");
707 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
709 g_mimeManager
.ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
710 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
712 g_mimeManager
.ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
715 static void TestMimeFilename()
717 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
719 static const wxChar
*filenames
[] =
726 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
728 const wxString fname
= filenames
[n
];
729 wxString ext
= fname
.AfterLast(_T('.'));
730 wxFileType
*ft
= g_mimeManager
.GetFileTypeFromExtension(ext
);
733 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
738 if ( !ft
->GetDescription(&desc
) )
739 desc
= _T("<no description>");
742 if ( !ft
->GetOpenCommand(&cmd
,
743 wxFileType::MessageParameters(fname
, _T(""))) )
744 cmd
= _T("<no command available>");
746 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
747 fname
.c_str(), desc
.c_str(), cmd
.c_str());
756 // ----------------------------------------------------------------------------
757 // misc information functions
758 // ----------------------------------------------------------------------------
760 #ifdef TEST_INFO_FUNCTIONS
762 #include <wx/utils.h>
764 static void TestOsInfo()
766 puts("*** Testing OS info functions ***\n");
769 wxGetOsVersion(&major
, &minor
);
770 printf("Running under: %s, version %d.%d\n",
771 wxGetOsDescription().c_str(), major
, minor
);
773 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
775 printf("Host name is %s (%s).\n",
776 wxGetHostName().c_str(), wxGetFullHostName().c_str());
781 static void TestUserInfo()
783 puts("*** Testing user info functions ***\n");
785 printf("User id is:\t%s\n", wxGetUserId().c_str());
786 printf("User name is:\t%s\n", wxGetUserName().c_str());
787 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
788 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
793 #endif // TEST_INFO_FUNCTIONS
795 // ----------------------------------------------------------------------------
797 // ----------------------------------------------------------------------------
801 #include <wx/longlong.h>
802 #include <wx/timer.h>
804 // make a 64 bit number from 4 16 bit ones
805 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
807 // get a random 64 bit number
808 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
810 #if wxUSE_LONGLONG_WX
811 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
812 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
813 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
814 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
815 #endif // wxUSE_LONGLONG_WX
817 static void TestSpeed()
819 static const long max
= 100000000;
826 for ( n
= 0; n
< max
; n
++ )
831 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
834 #if wxUSE_LONGLONG_NATIVE
839 for ( n
= 0; n
< max
; n
++ )
844 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
846 #endif // wxUSE_LONGLONG_NATIVE
852 for ( n
= 0; n
< max
; n
++ )
857 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
861 static void TestLongLongConversion()
863 puts("*** Testing wxLongLong conversions ***\n");
867 for ( size_t n
= 0; n
< 100000; n
++ )
871 #if wxUSE_LONGLONG_NATIVE
872 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
874 wxASSERT_MSG( a
== b
, "conversions failure" );
876 puts("Can't do it without native long long type, test skipped.");
879 #endif // wxUSE_LONGLONG_NATIVE
881 if ( !(nTested
% 1000) )
893 static void TestMultiplication()
895 puts("*** Testing wxLongLong multiplication ***\n");
899 for ( size_t n
= 0; n
< 100000; n
++ )
904 #if wxUSE_LONGLONG_NATIVE
905 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
906 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
908 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
909 #else // !wxUSE_LONGLONG_NATIVE
910 puts("Can't do it without native long long type, test skipped.");
913 #endif // wxUSE_LONGLONG_NATIVE
915 if ( !(nTested
% 1000) )
927 static void TestDivision()
929 puts("*** Testing wxLongLong division ***\n");
933 for ( size_t n
= 0; n
< 100000; n
++ )
935 // get a random wxLongLong (shifting by 12 the MSB ensures that the
936 // multiplication will not overflow)
937 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
939 // get a random long (not wxLongLong for now) to divide it with
944 #if wxUSE_LONGLONG_NATIVE
945 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
947 wxLongLongNative p
= m
/ l
, s
= m
% l
;
948 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
949 #else // !wxUSE_LONGLONG_NATIVE
951 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
952 #endif // wxUSE_LONGLONG_NATIVE
954 if ( !(nTested
% 1000) )
966 static void TestAddition()
968 puts("*** Testing wxLongLong addition ***\n");
972 for ( size_t n
= 0; n
< 100000; n
++ )
978 #if wxUSE_LONGLONG_NATIVE
979 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
980 wxLongLongNative(b
.GetHi(), b
.GetLo()),
981 "addition failure" );
982 #else // !wxUSE_LONGLONG_NATIVE
983 wxASSERT_MSG( c
- b
== a
, "addition failure" );
984 #endif // wxUSE_LONGLONG_NATIVE
986 if ( !(nTested
% 1000) )
998 static void TestBitOperations()
1000 puts("*** Testing wxLongLong bit operation ***\n");
1004 for ( size_t n
= 0; n
< 100000; n
++ )
1008 #if wxUSE_LONGLONG_NATIVE
1009 for ( size_t n
= 0; n
< 33; n
++ )
1012 #else // !wxUSE_LONGLONG_NATIVE
1013 puts("Can't do it without native long long type, test skipped.");
1016 #endif // wxUSE_LONGLONG_NATIVE
1018 if ( !(nTested
% 1000) )
1030 static void TestLongLongComparison()
1032 puts("*** Testing wxLongLong comparison ***\n");
1034 static const long testLongs
[] =
1045 static const long ls
[2] =
1051 wxLongLongWx lls
[2];
1055 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
1059 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
1061 res
= lls
[m
] > testLongs
[n
];
1062 printf("0x%lx > 0x%lx is %s (%s)\n",
1063 ls
[m
], testLongs
[n
], res
? "true" : "false",
1064 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
1066 res
= lls
[m
] < testLongs
[n
];
1067 printf("0x%lx < 0x%lx is %s (%s)\n",
1068 ls
[m
], testLongs
[n
], res
? "true" : "false",
1069 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
1071 res
= lls
[m
] == testLongs
[n
];
1072 printf("0x%lx == 0x%lx is %s (%s)\n",
1073 ls
[m
], testLongs
[n
], res
? "true" : "false",
1074 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
1082 #endif // TEST_LONGLONG
1084 // ----------------------------------------------------------------------------
1086 // ----------------------------------------------------------------------------
1088 // this is for MSW only
1090 #undef TEST_REGISTRY
1093 #ifdef TEST_REGISTRY
1095 #include <wx/msw/registry.h>
1097 // I chose this one because I liked its name, but it probably only exists under
1099 static const wxChar
*TESTKEY
=
1100 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1102 static void TestRegistryRead()
1104 puts("*** testing registry reading ***");
1106 wxRegKey
key(TESTKEY
);
1107 printf("The test key name is '%s'.\n", key
.GetName().c_str());
1110 puts("ERROR: test key can't be opened, aborting test.");
1115 size_t nSubKeys
, nValues
;
1116 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
1118 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
1121 printf("Enumerating values:\n");
1125 bool cont
= key
.GetFirstValue(value
, dummy
);
1128 printf("Value '%s': type ", value
.c_str());
1129 switch ( key
.GetValueType(value
) )
1131 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
1132 case wxRegKey::Type_String
: printf("SZ"); break;
1133 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
1134 case wxRegKey::Type_Binary
: printf("BINARY"); break;
1135 case wxRegKey::Type_Dword
: printf("DWORD"); break;
1136 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
1137 default: printf("other (unknown)"); break;
1140 printf(", value = ");
1141 if ( key
.IsNumericValue(value
) )
1144 key
.QueryValue(value
, &val
);
1150 key
.QueryValue(value
, val
);
1151 printf("'%s'", val
.c_str());
1153 key
.QueryRawValue(value
, val
);
1154 printf(" (raw value '%s')", val
.c_str());
1159 cont
= key
.GetNextValue(value
, dummy
);
1163 static void TestRegistryAssociation()
1166 The second call to deleteself genertaes an error message, with a
1167 messagebox saying .flo is crucial to system operation, while the .ddf
1168 call also fails, but with no error message
1173 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1175 key
= "ddxf_auto_file" ;
1176 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1178 key
= "ddxf_auto_file" ;
1179 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1182 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1184 key
= "program \"%1\"" ;
1186 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1188 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1190 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1192 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1196 #endif // TEST_REGISTRY
1198 // ----------------------------------------------------------------------------
1200 // ----------------------------------------------------------------------------
1204 #include <wx/socket.h>
1205 #include <wx/protocol/protocol.h>
1206 #include <wx/protocol/ftp.h>
1207 #include <wx/protocol/http.h>
1209 static void TestSocketServer()
1211 puts("*** Testing wxSocketServer ***\n");
1213 static const int PORT
= 3000;
1218 wxSocketServer
*server
= new wxSocketServer(addr
);
1219 if ( !server
->Ok() )
1221 puts("ERROR: failed to bind");
1228 printf("Server: waiting for connection on port %d...\n", PORT
);
1230 wxSocketBase
*socket
= server
->Accept();
1233 puts("ERROR: wxSocketServer::Accept() failed.");
1237 puts("Server: got a client.");
1239 server
->SetTimeout(60); // 1 min
1241 while ( socket
->IsConnected() )
1247 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
1249 // don't log error if the client just close the connection
1250 if ( socket
->IsConnected() )
1252 puts("ERROR: in wxSocket::Read.");
1272 printf("Server: got '%s'.\n", s
.c_str());
1273 if ( s
== _T("bye") )
1280 socket
->Write(s
.MakeUpper().c_str(), s
.length());
1281 socket
->Write("\r\n", 2);
1282 printf("Server: wrote '%s'.\n", s
.c_str());
1285 puts("Server: lost a client.");
1290 // same as "delete server" but is consistent with GUI programs
1294 static void TestSocketClient()
1296 puts("*** Testing wxSocketClient ***\n");
1298 static const char *hostname
= "www.wxwindows.org";
1301 addr
.Hostname(hostname
);
1304 printf("--- Attempting to connect to %s:80...\n", hostname
);
1306 wxSocketClient client
;
1307 if ( !client
.Connect(addr
) )
1309 printf("ERROR: failed to connect to %s\n", hostname
);
1313 printf("--- Connected to %s:%u...\n",
1314 addr
.Hostname().c_str(), addr
.Service());
1318 // could use simply "GET" here I suppose
1320 wxString::Format("GET http://%s/\r\n", hostname
);
1321 client
.Write(cmdGet
, cmdGet
.length());
1322 printf("--- Sent command '%s' to the server\n",
1323 MakePrintable(cmdGet
).c_str());
1324 client
.Read(buf
, WXSIZEOF(buf
));
1325 printf("--- Server replied:\n%s", buf
);
1329 static void TestProtocolFtp()
1331 puts("*** Testing wxFTP download ***\n");
1333 wxLog::AddTraceMask(_T("ftp"));
1335 static const char *hostname
= "ftp.wxwindows.org";
1337 printf("--- Attempting to connect to %s:21...\n", hostname
);
1340 if ( !ftp
.Connect(hostname
) )
1342 printf("ERROR: failed to connect to %s\n", hostname
);
1346 printf("--- Connected to %s, current directory is '%s'\n",
1347 hostname
, ftp
.Pwd().c_str());
1348 if ( !ftp
.ChDir(_T("pub")) )
1350 puts("ERROR: failed to cd to pub");
1353 wxArrayString files
;
1354 if ( !ftp
.GetList(files
) )
1356 puts("ERROR: failed to get list of files");
1360 printf("List of files under '%s':\n", ftp
.Pwd().c_str());
1361 size_t count
= files
.GetCount();
1362 for ( size_t n
= 0; n
< count
; n
++ )
1364 printf("\t%s\n", files
[n
].c_str());
1366 puts("End of the file list");
1369 if ( !ftp
.ChDir(_T("..")) )
1371 puts("ERROR: failed to cd to ..");
1374 static const char *filename
= "welcome.msg";
1375 wxInputStream
*in
= ftp
.GetInputStream(filename
);
1378 puts("ERROR: couldn't get input stream");
1382 size_t size
= in
->StreamSize();
1383 printf("Reading file %s (%u bytes)...", filename
, size
);
1385 char *data
= new char[size
];
1386 if ( !in
->Read(data
, size
) )
1388 puts("ERROR: read error");
1392 printf("\nContents of %s:\n%s\n", filename
, data
);
1401 static void TestProtocolFtpUpload()
1403 puts("*** Testing wxFTP uploading ***\n");
1405 wxLog::AddTraceMask(_T("ftp"));
1407 static const char *hostname
= "localhost";
1409 printf("--- Attempting to connect to %s:21...\n", hostname
);
1412 ftp
.SetUser("zeitlin");
1413 ftp
.SetPassword("insert your password here");
1414 if ( !ftp
.Connect(hostname
) )
1416 printf("ERROR: failed to connect to %s\n", hostname
);
1420 printf("--- Connected to %s, current directory is '%s'\n",
1421 hostname
, ftp
.Pwd().c_str());
1424 static const char *file1
= "test1";
1425 static const char *file2
= "test2";
1426 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
1429 printf("--- Uploading to %s ---\n", file1
);
1430 out
->Write("First hello", 11);
1434 out
= ftp
.GetOutputStream(file2
);
1437 printf("--- Uploading to %s ---\n", file1
);
1438 out
->Write("Second hello", 12);
1444 #endif // TEST_SOCKETS
1446 // ----------------------------------------------------------------------------
1448 // ----------------------------------------------------------------------------
1452 #include <wx/mstream.h>
1454 static void TestMemoryStream()
1456 puts("*** Testing wxMemoryInputStream ***");
1459 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
1461 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
1462 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
1463 while ( !memInpStream
.Eof() )
1465 putchar(memInpStream
.GetC());
1468 puts("\n*** wxMemoryInputStream test done ***");
1471 #endif // TEST_STREAMS
1473 // ----------------------------------------------------------------------------
1475 // ----------------------------------------------------------------------------
1479 #include <wx/timer.h>
1480 #include <wx/utils.h>
1482 static void TestStopWatch()
1484 puts("*** Testing wxStopWatch ***\n");
1487 printf("Sleeping 3 seconds...");
1489 printf("\telapsed time: %ldms\n", sw
.Time());
1492 printf("Sleeping 2 more seconds...");
1494 printf("\telapsed time: %ldms\n", sw
.Time());
1497 printf("And 3 more seconds...");
1499 printf("\telapsed time: %ldms\n", sw
.Time());
1502 puts("\nChecking for 'backwards clock' bug...");
1503 for ( size_t n
= 0; n
< 70; n
++ )
1507 for ( size_t m
= 0; m
< 100000; m
++ )
1509 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
1511 puts("\ntime is negative - ERROR!");
1521 #endif // TEST_TIMER
1523 // ----------------------------------------------------------------------------
1525 // ----------------------------------------------------------------------------
1529 #include <wx/vcard.h>
1531 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
1534 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
1538 wxString(_T('\t'), level
).c_str(),
1539 vcObj
->GetName().c_str());
1542 switch ( vcObj
->GetType() )
1544 case wxVCardObject::String
:
1545 case wxVCardObject::UString
:
1548 vcObj
->GetValue(&val
);
1549 value
<< _T('"') << val
<< _T('"');
1553 case wxVCardObject::Int
:
1556 vcObj
->GetValue(&i
);
1557 value
.Printf(_T("%u"), i
);
1561 case wxVCardObject::Long
:
1564 vcObj
->GetValue(&l
);
1565 value
.Printf(_T("%lu"), l
);
1569 case wxVCardObject::None
:
1572 case wxVCardObject::Object
:
1573 value
= _T("<node>");
1577 value
= _T("<unknown value type>");
1581 printf(" = %s", value
.c_str());
1584 DumpVObject(level
+ 1, *vcObj
);
1587 vcObj
= vcard
.GetNextProp(&cookie
);
1591 static void DumpVCardAddresses(const wxVCard
& vcard
)
1593 puts("\nShowing all addresses from vCard:\n");
1597 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
1601 int flags
= addr
->GetFlags();
1602 if ( flags
& wxVCardAddress::Domestic
)
1604 flagsStr
<< _T("domestic ");
1606 if ( flags
& wxVCardAddress::Intl
)
1608 flagsStr
<< _T("international ");
1610 if ( flags
& wxVCardAddress::Postal
)
1612 flagsStr
<< _T("postal ");
1614 if ( flags
& wxVCardAddress::Parcel
)
1616 flagsStr
<< _T("parcel ");
1618 if ( flags
& wxVCardAddress::Home
)
1620 flagsStr
<< _T("home ");
1622 if ( flags
& wxVCardAddress::Work
)
1624 flagsStr
<< _T("work ");
1627 printf("Address %u:\n"
1629 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
1632 addr
->GetPostOffice().c_str(),
1633 addr
->GetExtAddress().c_str(),
1634 addr
->GetStreet().c_str(),
1635 addr
->GetLocality().c_str(),
1636 addr
->GetRegion().c_str(),
1637 addr
->GetPostalCode().c_str(),
1638 addr
->GetCountry().c_str()
1642 addr
= vcard
.GetNextAddress(&cookie
);
1646 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
1648 puts("\nShowing all phone numbers from vCard:\n");
1652 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
1656 int flags
= phone
->GetFlags();
1657 if ( flags
& wxVCardPhoneNumber::Voice
)
1659 flagsStr
<< _T("voice ");
1661 if ( flags
& wxVCardPhoneNumber::Fax
)
1663 flagsStr
<< _T("fax ");
1665 if ( flags
& wxVCardPhoneNumber::Cellular
)
1667 flagsStr
<< _T("cellular ");
1669 if ( flags
& wxVCardPhoneNumber::Modem
)
1671 flagsStr
<< _T("modem ");
1673 if ( flags
& wxVCardPhoneNumber::Home
)
1675 flagsStr
<< _T("home ");
1677 if ( flags
& wxVCardPhoneNumber::Work
)
1679 flagsStr
<< _T("work ");
1682 printf("Phone number %u:\n"
1687 phone
->GetNumber().c_str()
1691 phone
= vcard
.GetNextPhoneNumber(&cookie
);
1695 static void TestVCardRead()
1697 puts("*** Testing wxVCard reading ***\n");
1699 wxVCard
vcard(_T("vcard.vcf"));
1700 if ( !vcard
.IsOk() )
1702 puts("ERROR: couldn't load vCard.");
1706 // read individual vCard properties
1707 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
1711 vcObj
->GetValue(&value
);
1716 value
= _T("<none>");
1719 printf("Full name retrieved directly: %s\n", value
.c_str());
1722 if ( !vcard
.GetFullName(&value
) )
1724 value
= _T("<none>");
1727 printf("Full name from wxVCard API: %s\n", value
.c_str());
1729 // now show how to deal with multiply occuring properties
1730 DumpVCardAddresses(vcard
);
1731 DumpVCardPhoneNumbers(vcard
);
1733 // and finally show all
1734 puts("\nNow dumping the entire vCard:\n"
1735 "-----------------------------\n");
1737 DumpVObject(0, vcard
);
1741 static void TestVCardWrite()
1743 puts("*** Testing wxVCard writing ***\n");
1746 if ( !vcard
.IsOk() )
1748 puts("ERROR: couldn't create vCard.");
1753 vcard
.SetName("Zeitlin", "Vadim");
1754 vcard
.SetFullName("Vadim Zeitlin");
1755 vcard
.SetOrganization("wxWindows", "R&D");
1757 // just dump the vCard back
1758 puts("Entire vCard follows:\n");
1759 puts(vcard
.Write());
1763 #endif // TEST_VCARD
1765 // ----------------------------------------------------------------------------
1766 // wide char (Unicode) support
1767 // ----------------------------------------------------------------------------
1771 #include <wx/strconv.h>
1772 #include <wx/buffer.h>
1774 static void TestUtf8()
1776 puts("*** Testing UTF8 support ***\n");
1778 wxString testString
= "français";
1780 "************ French - Français ****************"
1781 "Juste un petit exemple pour dire que les français aussi"
1782 "ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
1785 wxWCharBuffer wchBuf
= testString
.wc_str(wxConvUTF8
);
1786 const wchar_t *pwz
= (const wchar_t *)wchBuf
;
1787 wxString
testString2(pwz
, wxConvLocal
);
1789 printf("Decoding '%s' => '%s'\n", testString
.c_str(), testString2
.c_str());
1791 char *psz
= "fran" "\xe7" "ais";
1792 size_t len
= strlen(psz
);
1793 wchar_t *pwz2
= new wchar_t[len
+ 1];
1794 for ( size_t n
= 0; n
<= len
; n
++ )
1796 pwz2
[n
] = (wchar_t)(unsigned char)psz
[n
];
1799 wxString
testString3(pwz2
, wxConvUTF8
);
1802 printf("Encoding '%s' -> '%s'\n", psz
, testString3
.c_str());
1805 #endif // TEST_WCHAR
1807 // ----------------------------------------------------------------------------
1809 // ----------------------------------------------------------------------------
1813 #include "wx/zipstrm.h"
1815 static void TestZipStreamRead()
1817 puts("*** Testing ZIP reading ***\n");
1819 wxZipInputStream
istr(_T("idx.zip"), _T("IDX.txt"));
1820 printf("Archive size: %u\n", istr
.GetSize());
1822 puts("Dumping the file:");
1823 while ( !istr
.Eof() )
1825 putchar(istr
.GetC());
1829 puts("\n----- done ------");
1834 // ----------------------------------------------------------------------------
1836 // ----------------------------------------------------------------------------
1840 #include <wx/zstream.h>
1841 #include <wx/wfstream.h>
1843 static const wxChar
*FILENAME_GZ
= _T("test.gz");
1844 static const char *TEST_DATA
= "hello and hello again";
1846 static void TestZlibStreamWrite()
1848 puts("*** Testing Zlib stream reading ***\n");
1850 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
1851 wxZlibOutputStream
ostr(fileOutStream
, 0);
1852 printf("Compressing the test string... ");
1853 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
1856 puts("(ERROR: failed)");
1863 puts("\n----- done ------");
1866 static void TestZlibStreamRead()
1868 puts("*** Testing Zlib stream reading ***\n");
1870 wxFileInputStream
fileInStream(FILENAME_GZ
);
1871 wxZlibInputStream
istr(fileInStream
);
1872 printf("Archive size: %u\n", istr
.GetSize());
1874 puts("Dumping the file:");
1875 while ( !istr
.Eof() )
1877 putchar(istr
.GetC());
1881 puts("\n----- done ------");
1886 // ----------------------------------------------------------------------------
1888 // ----------------------------------------------------------------------------
1890 #ifdef TEST_DATETIME
1892 #include <wx/date.h>
1894 #include <wx/datetime.h>
1899 wxDateTime::wxDateTime_t day
;
1900 wxDateTime::Month month
;
1902 wxDateTime::wxDateTime_t hour
, min
, sec
;
1904 wxDateTime::WeekDay wday
;
1905 time_t gmticks
, ticks
;
1907 void Init(const wxDateTime::Tm
& tm
)
1916 gmticks
= ticks
= -1;
1919 wxDateTime
DT() const
1920 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
1922 bool SameDay(const wxDateTime::Tm
& tm
) const
1924 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
1927 wxString
Format() const
1930 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
1932 wxDateTime::GetMonthName(month
).c_str(),
1934 abs(wxDateTime::ConvertYearToBC(year
)),
1935 year
> 0 ? "AD" : "BC");
1939 wxString
FormatDate() const
1942 s
.Printf("%02d-%s-%4d%s",
1944 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1945 abs(wxDateTime::ConvertYearToBC(year
)),
1946 year
> 0 ? "AD" : "BC");
1951 static const Date testDates
[] =
1953 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
1954 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
1955 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
1956 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
1957 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
1958 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
1959 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
1960 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
1961 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
1962 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
1963 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
1964 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
1965 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
1966 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
1967 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
1970 // this test miscellaneous static wxDateTime functions
1971 static void TestTimeStatic()
1973 puts("\n*** wxDateTime static methods test ***");
1975 // some info about the current date
1976 int year
= wxDateTime::GetCurrentYear();
1977 printf("Current year %d is %sa leap one and has %d days.\n",
1979 wxDateTime::IsLeapYear(year
) ? "" : "not ",
1980 wxDateTime::GetNumberOfDays(year
));
1982 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
1983 printf("Current month is '%s' ('%s') and it has %d days\n",
1984 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1985 wxDateTime::GetMonthName(month
).c_str(),
1986 wxDateTime::GetNumberOfDays(month
));
1989 static const size_t nYears
= 5;
1990 static const size_t years
[2][nYears
] =
1992 // first line: the years to test
1993 { 1990, 1976, 2000, 2030, 1984, },
1995 // second line: TRUE if leap, FALSE otherwise
1996 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
1999 for ( size_t n
= 0; n
< nYears
; n
++ )
2001 int year
= years
[0][n
];
2002 bool should
= years
[1][n
] != 0,
2003 is
= wxDateTime::IsLeapYear(year
);
2005 printf("Year %d is %sa leap year (%s)\n",
2008 should
== is
? "ok" : "ERROR");
2010 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
2014 // test constructing wxDateTime objects
2015 static void TestTimeSet()
2017 puts("\n*** wxDateTime construction test ***");
2019 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2021 const Date
& d1
= testDates
[n
];
2022 wxDateTime dt
= d1
.DT();
2025 d2
.Init(dt
.GetTm());
2027 wxString s1
= d1
.Format(),
2030 printf("Date: %s == %s (%s)\n",
2031 s1
.c_str(), s2
.c_str(),
2032 s1
== s2
? "ok" : "ERROR");
2036 // test time zones stuff
2037 static void TestTimeZones()
2039 puts("\n*** wxDateTime timezone test ***");
2041 wxDateTime now
= wxDateTime::Now();
2043 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
2044 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
2045 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
2046 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
2047 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
2048 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
2050 wxDateTime::Tm tm
= now
.GetTm();
2051 if ( wxDateTime(tm
) != now
)
2053 printf("ERROR: got %s instead of %s\n",
2054 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
2058 // test some minimal support for the dates outside the standard range
2059 static void TestTimeRange()
2061 puts("\n*** wxDateTime out-of-standard-range dates test ***");
2063 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
2065 printf("Unix epoch:\t%s\n",
2066 wxDateTime(2440587.5).Format(fmt
).c_str());
2067 printf("Feb 29, 0: \t%s\n",
2068 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
2069 printf("JDN 0: \t%s\n",
2070 wxDateTime(0.0).Format(fmt
).c_str());
2071 printf("Jan 1, 1AD:\t%s\n",
2072 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
2073 printf("May 29, 2099:\t%s\n",
2074 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
2077 static void TestTimeTicks()
2079 puts("\n*** wxDateTime ticks test ***");
2081 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2083 const Date
& d
= testDates
[n
];
2084 if ( d
.ticks
== -1 )
2087 wxDateTime dt
= d
.DT();
2088 long ticks
= (dt
.GetValue() / 1000).ToLong();
2089 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2090 if ( ticks
== d
.ticks
)
2096 printf(" (ERROR: should be %ld, delta = %ld)\n",
2097 d
.ticks
, ticks
- d
.ticks
);
2100 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
2101 ticks
= (dt
.GetValue() / 1000).ToLong();
2102 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2103 if ( ticks
== d
.gmticks
)
2109 printf(" (ERROR: should be %ld, delta = %ld)\n",
2110 d
.gmticks
, ticks
- d
.gmticks
);
2117 // test conversions to JDN &c
2118 static void TestTimeJDN()
2120 puts("\n*** wxDateTime to JDN test ***");
2122 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2124 const Date
& d
= testDates
[n
];
2125 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2126 double jdn
= dt
.GetJulianDayNumber();
2128 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
2135 printf(" (ERROR: should be %f, delta = %f)\n",
2136 d
.jdn
, jdn
- d
.jdn
);
2141 // test week days computation
2142 static void TestTimeWDays()
2144 puts("\n*** wxDateTime weekday test ***");
2146 // test GetWeekDay()
2148 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2150 const Date
& d
= testDates
[n
];
2151 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2153 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
2156 wxDateTime::GetWeekDayName(wday
).c_str());
2157 if ( wday
== d
.wday
)
2163 printf(" (ERROR: should be %s)\n",
2164 wxDateTime::GetWeekDayName(d
.wday
).c_str());
2170 // test SetToWeekDay()
2171 struct WeekDateTestData
2173 Date date
; // the real date (precomputed)
2174 int nWeek
; // its week index in the month
2175 wxDateTime::WeekDay wday
; // the weekday
2176 wxDateTime::Month month
; // the month
2177 int year
; // and the year
2179 wxString
Format() const
2182 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
2184 case 1: which
= "first"; break;
2185 case 2: which
= "second"; break;
2186 case 3: which
= "third"; break;
2187 case 4: which
= "fourth"; break;
2188 case 5: which
= "fifth"; break;
2190 case -1: which
= "last"; break;
2195 which
+= " from end";
2198 s
.Printf("The %s %s of %s in %d",
2200 wxDateTime::GetWeekDayName(wday
).c_str(),
2201 wxDateTime::GetMonthName(month
).c_str(),
2208 // the array data was generated by the following python program
2210 from DateTime import *
2211 from whrandom import *
2212 from string import *
2214 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2215 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2217 week = DateTimeDelta(7)
2220 year = randint(1900, 2100)
2221 month = randint(1, 12)
2222 day = randint(1, 28)
2223 dt = DateTime(year, month, day)
2224 wday = dt.day_of_week
2226 countFromEnd = choice([-1, 1])
2229 while dt.month is month:
2230 dt = dt - countFromEnd * week
2231 weekNum = weekNum + countFromEnd
2233 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
2235 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
2236 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
2239 static const WeekDateTestData weekDatesTestData
[] =
2241 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
2242 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
2243 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
2244 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
2245 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
2246 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
2247 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
2248 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
2249 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
2250 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
2251 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
2252 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
2253 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
2254 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
2255 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
2256 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
2257 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
2258 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
2259 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
2260 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
2263 static const char *fmt
= "%d-%b-%Y";
2266 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
2268 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
2270 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
2272 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
2274 const Date
& d
= wd
.date
;
2275 if ( d
.SameDay(dt
.GetTm()) )
2281 dt
.Set(d
.day
, d
.month
, d
.year
);
2283 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
2288 // test the computation of (ISO) week numbers
2289 static void TestTimeWNumber()
2291 puts("\n*** wxDateTime week number test ***");
2293 struct WeekNumberTestData
2295 Date date
; // the date
2296 wxDateTime::wxDateTime_t week
; // the week number in the year
2297 wxDateTime::wxDateTime_t wmon
; // the week number in the month
2298 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
2299 wxDateTime::wxDateTime_t dnum
; // day number in the year
2302 // data generated with the following python script:
2304 from DateTime import *
2305 from whrandom import *
2306 from string import *
2308 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2309 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2311 def GetMonthWeek(dt):
2312 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
2313 if weekNumMonth < 0:
2314 weekNumMonth = weekNumMonth + 53
2317 def GetLastSundayBefore(dt):
2318 if dt.iso_week[2] == 7:
2321 return dt - DateTimeDelta(dt.iso_week[2])
2324 year = randint(1900, 2100)
2325 month = randint(1, 12)
2326 day = randint(1, 28)
2327 dt = DateTime(year, month, day)
2328 dayNum = dt.day_of_year
2329 weekNum = dt.iso_week[1]
2330 weekNumMonth = GetMonthWeek(dt)
2333 dtSunday = GetLastSundayBefore(dt)
2335 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
2336 weekNumMonth2 = weekNumMonth2 + 1
2337 dtSunday = dtSunday - DateTimeDelta(7)
2339 data = { 'day': rjust(`day`, 2), \
2340 'month': monthNames[month - 1], \
2342 'weekNum': rjust(`weekNum`, 2), \
2343 'weekNumMonth': weekNumMonth, \
2344 'weekNumMonth2': weekNumMonth2, \
2345 'dayNum': rjust(`dayNum`, 3) }
2347 print " { { %(day)s, "\
2348 "wxDateTime::%(month)s, "\
2351 "%(weekNumMonth)s, "\
2352 "%(weekNumMonth2)s, "\
2353 "%(dayNum)s }," % data
2356 static const WeekNumberTestData weekNumberTestDates
[] =
2358 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
2359 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
2360 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
2361 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
2362 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
2363 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
2364 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
2365 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
2366 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
2367 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
2368 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
2369 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
2370 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
2371 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
2372 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
2373 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
2374 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
2375 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
2376 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
2377 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
2380 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
2382 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
2383 const Date
& d
= wn
.date
;
2385 wxDateTime dt
= d
.DT();
2387 wxDateTime::wxDateTime_t
2388 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
2389 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2390 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2391 dnum
= dt
.GetDayOfYear();
2393 printf("%s: the day number is %d",
2394 d
.FormatDate().c_str(), dnum
);
2395 if ( dnum
== wn
.dnum
)
2401 printf(" (ERROR: should be %d)", wn
.dnum
);
2404 printf(", week in month is %d", wmon
);
2405 if ( wmon
== wn
.wmon
)
2411 printf(" (ERROR: should be %d)", wn
.wmon
);
2414 printf(" or %d", wmon2
);
2415 if ( wmon2
== wn
.wmon2
)
2421 printf(" (ERROR: should be %d)", wn
.wmon2
);
2424 printf(", week in year is %d", week
);
2425 if ( week
== wn
.week
)
2431 printf(" (ERROR: should be %d)\n", wn
.week
);
2436 // test DST calculations
2437 static void TestTimeDST()
2439 puts("\n*** wxDateTime DST test ***");
2441 printf("DST is%s in effect now.\n\n",
2442 wxDateTime::Now().IsDST() ? "" : " not");
2444 // taken from http://www.energy.ca.gov/daylightsaving.html
2445 static const Date datesDST
[2][2004 - 1900 + 1] =
2448 { 1, wxDateTime::Apr
, 1990 },
2449 { 7, wxDateTime::Apr
, 1991 },
2450 { 5, wxDateTime::Apr
, 1992 },
2451 { 4, wxDateTime::Apr
, 1993 },
2452 { 3, wxDateTime::Apr
, 1994 },
2453 { 2, wxDateTime::Apr
, 1995 },
2454 { 7, wxDateTime::Apr
, 1996 },
2455 { 6, wxDateTime::Apr
, 1997 },
2456 { 5, wxDateTime::Apr
, 1998 },
2457 { 4, wxDateTime::Apr
, 1999 },
2458 { 2, wxDateTime::Apr
, 2000 },
2459 { 1, wxDateTime::Apr
, 2001 },
2460 { 7, wxDateTime::Apr
, 2002 },
2461 { 6, wxDateTime::Apr
, 2003 },
2462 { 4, wxDateTime::Apr
, 2004 },
2465 { 28, wxDateTime::Oct
, 1990 },
2466 { 27, wxDateTime::Oct
, 1991 },
2467 { 25, wxDateTime::Oct
, 1992 },
2468 { 31, wxDateTime::Oct
, 1993 },
2469 { 30, wxDateTime::Oct
, 1994 },
2470 { 29, wxDateTime::Oct
, 1995 },
2471 { 27, wxDateTime::Oct
, 1996 },
2472 { 26, wxDateTime::Oct
, 1997 },
2473 { 25, wxDateTime::Oct
, 1998 },
2474 { 31, wxDateTime::Oct
, 1999 },
2475 { 29, wxDateTime::Oct
, 2000 },
2476 { 28, wxDateTime::Oct
, 2001 },
2477 { 27, wxDateTime::Oct
, 2002 },
2478 { 26, wxDateTime::Oct
, 2003 },
2479 { 31, wxDateTime::Oct
, 2004 },
2484 for ( year
= 1990; year
< 2005; year
++ )
2486 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
2487 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
2489 printf("DST period in the US for year %d: from %s to %s",
2490 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
2492 size_t n
= year
- 1990;
2493 const Date
& dBegin
= datesDST
[0][n
];
2494 const Date
& dEnd
= datesDST
[1][n
];
2496 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
2502 printf(" (ERROR: should be %s %d to %s %d)\n",
2503 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
2504 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
2510 for ( year
= 1990; year
< 2005; year
++ )
2512 printf("DST period in Europe for year %d: from %s to %s\n",
2514 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
2515 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
2519 // test wxDateTime -> text conversion
2520 static void TestTimeFormat()
2522 puts("\n*** wxDateTime formatting test ***");
2524 // some information may be lost during conversion, so store what kind
2525 // of info should we recover after a round trip
2528 CompareNone
, // don't try comparing
2529 CompareBoth
, // dates and times should be identical
2530 CompareDate
, // dates only
2531 CompareTime
// time only
2536 CompareKind compareKind
;
2538 } formatTestFormats
[] =
2540 { CompareBoth
, "---> %c" },
2541 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
2542 { CompareBoth
, "Date is %x, time is %X" },
2543 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
2544 { CompareNone
, "The day of year: %j, the week of year: %W" },
2545 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
2548 static const Date formatTestDates
[] =
2550 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
2551 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
2553 // this test can't work for other centuries because it uses two digit
2554 // years in formats, so don't even try it
2555 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
2556 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
2557 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
2561 // an extra test (as it doesn't depend on date, don't do it in the loop)
2562 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
2564 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
2568 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
2569 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
2571 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
2572 printf("%s", s
.c_str());
2574 // what can we recover?
2575 int kind
= formatTestFormats
[n
].compareKind
;
2579 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
2582 // converion failed - should it have?
2583 if ( kind
== CompareNone
)
2586 puts(" (ERROR: conversion back failed)");
2590 // should have parsed the entire string
2591 puts(" (ERROR: conversion back stopped too soon)");
2595 bool equal
= FALSE
; // suppress compilaer warning
2603 equal
= dt
.IsSameDate(dt2
);
2607 equal
= dt
.IsSameTime(dt2
);
2613 printf(" (ERROR: got back '%s' instead of '%s')\n",
2614 dt2
.Format().c_str(), dt
.Format().c_str());
2625 // test text -> wxDateTime conversion
2626 static void TestTimeParse()
2628 puts("\n*** wxDateTime parse test ***");
2630 struct ParseTestData
2637 static const ParseTestData parseTestDates
[] =
2639 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
2640 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
2643 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
2645 const char *format
= parseTestDates
[n
].format
;
2647 printf("%s => ", format
);
2650 if ( dt
.ParseRfc822Date(format
) )
2652 printf("%s ", dt
.Format().c_str());
2654 if ( parseTestDates
[n
].good
)
2656 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
2663 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
2668 puts("(ERROR: bad format)");
2673 printf("bad format (%s)\n",
2674 parseTestDates
[n
].good
? "ERROR" : "ok");
2679 static void TestInteractive()
2681 puts("\n*** interactive wxDateTime tests ***");
2687 printf("Enter a date: ");
2688 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2691 // kill the last '\n'
2692 buf
[strlen(buf
) - 1] = 0;
2695 const char *p
= dt
.ParseDate(buf
);
2698 printf("ERROR: failed to parse the date '%s'.\n", buf
);
2704 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
2707 printf("%s: day %u, week of month %u/%u, week of year %u\n",
2708 dt
.Format("%b %d, %Y").c_str(),
2710 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2711 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2712 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
2715 puts("\n*** done ***");
2718 static void TestTimeMS()
2720 puts("*** testing millisecond-resolution support in wxDateTime ***");
2722 wxDateTime dt1
= wxDateTime::Now(),
2723 dt2
= wxDateTime::UNow();
2725 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
2726 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2727 printf("Dummy loop: ");
2728 for ( int i
= 0; i
< 6000; i
++ )
2730 //for ( int j = 0; j < 10; j++ )
2733 s
.Printf("%g", sqrt(i
));
2742 dt2
= wxDateTime::UNow();
2743 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2745 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
2747 puts("\n*** done ***");
2750 static void TestTimeArithmetics()
2752 puts("\n*** testing arithmetic operations on wxDateTime ***");
2754 static const struct ArithmData
2756 ArithmData(const wxDateSpan
& sp
, const char *nam
)
2757 : span(sp
), name(nam
) { }
2761 } testArithmData
[] =
2763 ArithmData(wxDateSpan::Day(), "day"),
2764 ArithmData(wxDateSpan::Week(), "week"),
2765 ArithmData(wxDateSpan::Month(), "month"),
2766 ArithmData(wxDateSpan::Year(), "year"),
2767 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
2770 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
2772 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
2774 wxDateSpan span
= testArithmData
[n
].span
;
2778 const char *name
= testArithmData
[n
].name
;
2779 printf("%s + %s = %s, %s - %s = %s\n",
2780 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
2781 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
2783 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
2784 if ( dt1
- span
== dt
)
2790 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2793 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
2794 if ( dt2
+ span
== dt
)
2800 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2803 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
2804 if ( dt2
+ 2*span
== dt1
)
2810 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
2817 static void TestTimeHolidays()
2819 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
2821 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
2822 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
2823 dtEnd
= dtStart
.GetLastMonthDay();
2825 wxDateTimeArray hol
;
2826 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
2828 const wxChar
*format
= "%d-%b-%Y (%a)";
2830 printf("All holidays between %s and %s:\n",
2831 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
2833 size_t count
= hol
.GetCount();
2834 for ( size_t n
= 0; n
< count
; n
++ )
2836 printf("\t%s\n", hol
[n
].Format(format
).c_str());
2842 static void TestTimeZoneBug()
2844 puts("\n*** testing for DST/timezone bug ***\n");
2846 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
2847 for ( int i
= 0; i
< 31; i
++ )
2849 printf("Date %s: week day %s.\n",
2850 date
.Format(_T("%d-%m-%Y")).c_str(),
2851 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
2853 date
+= wxDateSpan::Day();
2861 // test compatibility with the old wxDate/wxTime classes
2862 static void TestTimeCompatibility()
2864 puts("\n*** wxDateTime compatibility test ***");
2866 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
2867 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
2869 double jdnNow
= wxDateTime::Now().GetJDN();
2870 long jdnMidnight
= (long)(jdnNow
- 0.5);
2871 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
2873 jdnMidnight
= wxDate().Set().GetJulianDate();
2874 printf("wxDateTime for today: %s\n",
2875 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
2877 int flags
= wxEUROPEAN
;//wxFULL;
2880 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
2881 for ( int n
= 0; n
< 7; n
++ )
2883 printf("Previous %s is %s\n",
2884 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
2885 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
2891 #endif // TEST_DATETIME
2893 // ----------------------------------------------------------------------------
2895 // ----------------------------------------------------------------------------
2899 #include <wx/thread.h>
2901 static size_t gs_counter
= (size_t)-1;
2902 static wxCriticalSection gs_critsect
;
2903 static wxCondition gs_cond
;
2905 class MyJoinableThread
: public wxThread
2908 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
2909 { m_n
= n
; Create(); }
2911 // thread execution starts here
2912 virtual ExitCode
Entry();
2918 wxThread::ExitCode
MyJoinableThread::Entry()
2920 unsigned long res
= 1;
2921 for ( size_t n
= 1; n
< m_n
; n
++ )
2925 // it's a loooong calculation :-)
2929 return (ExitCode
)res
;
2932 class MyDetachedThread
: public wxThread
2935 MyDetachedThread(size_t n
, char ch
)
2939 m_cancelled
= FALSE
;
2944 // thread execution starts here
2945 virtual ExitCode
Entry();
2948 virtual void OnExit();
2951 size_t m_n
; // number of characters to write
2952 char m_ch
; // character to write
2954 bool m_cancelled
; // FALSE if we exit normally
2957 wxThread::ExitCode
MyDetachedThread::Entry()
2960 wxCriticalSectionLocker
lock(gs_critsect
);
2961 if ( gs_counter
== (size_t)-1 )
2967 for ( size_t n
= 0; n
< m_n
; n
++ )
2969 if ( TestDestroy() )
2979 wxThread::Sleep(100);
2985 void MyDetachedThread::OnExit()
2987 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
2989 wxCriticalSectionLocker
lock(gs_critsect
);
2990 if ( !--gs_counter
&& !m_cancelled
)
2994 void TestDetachedThreads()
2996 puts("\n*** Testing detached threads ***");
2998 static const size_t nThreads
= 3;
2999 MyDetachedThread
*threads
[nThreads
];
3001 for ( n
= 0; n
< nThreads
; n
++ )
3003 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
3006 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
3007 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
3009 for ( n
= 0; n
< nThreads
; n
++ )
3014 // wait until all threads terminate
3020 void TestJoinableThreads()
3022 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
3024 // calc 10! in the background
3025 MyJoinableThread
thread(10);
3028 printf("\nThread terminated with exit code %lu.\n",
3029 (unsigned long)thread
.Wait());
3032 void TestThreadSuspend()
3034 puts("\n*** Testing thread suspend/resume functions ***");
3036 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3040 // this is for this demo only, in a real life program we'd use another
3041 // condition variable which would be signaled from wxThread::Entry() to
3042 // tell us that the thread really started running - but here just wait a
3043 // bit and hope that it will be enough (the problem is, of course, that
3044 // the thread might still not run when we call Pause() which will result
3046 wxThread::Sleep(300);
3048 for ( size_t n
= 0; n
< 3; n
++ )
3052 puts("\nThread suspended");
3055 // don't sleep but resume immediately the first time
3056 wxThread::Sleep(300);
3058 puts("Going to resume the thread");
3063 puts("Waiting until it terminates now");
3065 // wait until the thread terminates
3071 void TestThreadDelete()
3073 // As above, using Sleep() is only for testing here - we must use some
3074 // synchronisation object instead to ensure that the thread is still
3075 // running when we delete it - deleting a detached thread which already
3076 // terminated will lead to a crash!
3078 puts("\n*** Testing thread delete function ***");
3080 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3084 puts("\nDeleted a thread which didn't start to run yet.");
3086 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3090 wxThread::Sleep(300);
3094 puts("\nDeleted a running thread.");
3096 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
3100 wxThread::Sleep(300);
3106 puts("\nDeleted a sleeping thread.");
3108 MyJoinableThread
thread3(20);
3113 puts("\nDeleted a joinable thread.");
3115 MyJoinableThread
thread4(2);
3118 wxThread::Sleep(300);
3122 puts("\nDeleted a joinable thread which already terminated.");
3127 #endif // TEST_THREADS
3129 // ----------------------------------------------------------------------------
3131 // ----------------------------------------------------------------------------
3135 static void PrintArray(const char* name
, const wxArrayString
& array
)
3137 printf("Dump of the array '%s'\n", name
);
3139 size_t nCount
= array
.GetCount();
3140 for ( size_t n
= 0; n
< nCount
; n
++ )
3142 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
3146 static void PrintArray(const char* name
, const wxArrayInt
& array
)
3148 printf("Dump of the array '%s'\n", name
);
3150 size_t nCount
= array
.GetCount();
3151 for ( size_t n
= 0; n
< nCount
; n
++ )
3153 printf("\t%s[%u] = %d\n", name
, n
, array
[n
]);
3157 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
3158 const wxString
& second
)
3160 return first
.length() - second
.length();
3163 int wxCMPFUNC_CONV
IntCompare(int *first
,
3166 return *first
- *second
;
3169 int wxCMPFUNC_CONV
IntRevCompare(int *first
,
3172 return *second
- *first
;
3175 static void TestArrayOfInts()
3177 puts("*** Testing wxArrayInt ***\n");
3188 puts("After sort:");
3192 puts("After reverse sort:");
3193 a
.Sort(IntRevCompare
);
3197 #include "wx/dynarray.h"
3199 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
3200 #include "wx/arrimpl.cpp"
3201 WX_DEFINE_OBJARRAY(ArrayBars
);
3203 static void TestArrayOfObjects()
3205 puts("*** Testing wxObjArray ***\n");
3209 Bar
bar("second bar");
3211 printf("Initially: %u objects in the array, %u objects total.\n",
3212 bars
.GetCount(), Bar::GetNumber());
3214 bars
.Add(new Bar("first bar"));
3217 printf("Now: %u objects in the array, %u objects total.\n",
3218 bars
.GetCount(), Bar::GetNumber());
3222 printf("After Empty(): %u objects in the array, %u objects total.\n",
3223 bars
.GetCount(), Bar::GetNumber());
3226 printf("Finally: no more objects in the array, %u objects total.\n",
3230 #endif // TEST_ARRAYS
3232 // ----------------------------------------------------------------------------
3234 // ----------------------------------------------------------------------------
3238 #include "wx/timer.h"
3239 #include "wx/tokenzr.h"
3241 static void TestStringConstruction()
3243 puts("*** Testing wxString constructores ***");
3245 #define TEST_CTOR(args, res) \
3248 printf("wxString%s = %s ", #args, s.c_str()); \
3255 printf("(ERROR: should be %s)\n", res); \
3259 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
3260 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
3261 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
3262 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
3264 static const wxChar
*s
= _T("?really!");
3265 const wxChar
*start
= wxStrchr(s
, _T('r'));
3266 const wxChar
*end
= wxStrchr(s
, _T('!'));
3267 TEST_CTOR((start
, end
), _T("really"));
3272 static void TestString()
3282 for (int i
= 0; i
< 1000000; ++i
)
3286 c
= "! How'ya doin'?";
3289 c
= "Hello world! What's up?";
3294 printf ("TestString elapsed time: %ld\n", sw
.Time());
3297 static void TestPChar()
3305 for (int i
= 0; i
< 1000000; ++i
)
3307 strcpy (a
, "Hello");
3308 strcpy (b
, " world");
3309 strcpy (c
, "! How'ya doin'?");
3312 strcpy (c
, "Hello world! What's up?");
3313 if (strcmp (c
, a
) == 0)
3317 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
3320 static void TestStringSub()
3322 wxString
s("Hello, world!");
3324 puts("*** Testing wxString substring extraction ***");
3326 printf("String = '%s'\n", s
.c_str());
3327 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
3328 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
3329 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
3330 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
3331 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
3332 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
3334 static const wxChar
*prefixes
[] =
3338 _T("Hello, world!"),
3339 _T("Hello, world!!!"),
3345 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
3347 wxString prefix
= prefixes
[n
], rest
;
3348 bool rc
= s
.StartsWith(prefix
, &rest
);
3349 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
3352 printf(" (the rest is '%s')\n", rest
.c_str());
3363 static void TestStringFormat()
3365 puts("*** Testing wxString formatting ***");
3368 s
.Printf("%03d", 18);
3370 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
3371 printf("Number 18: %s\n", s
.c_str());
3376 // returns "not found" for npos, value for all others
3377 static wxString
PosToString(size_t res
)
3379 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
3380 : wxString::Format(_T("%u"), res
);
3384 static void TestStringFind()
3386 puts("*** Testing wxString find() functions ***");
3388 static const wxChar
*strToFind
= _T("ell");
3389 static const struct StringFindTest
3393 result
; // of searching "ell" in str
3396 { _T("Well, hello world"), 0, 1 },
3397 { _T("Well, hello world"), 6, 7 },
3398 { _T("Well, hello world"), 9, wxString::npos
},
3401 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
3403 const StringFindTest
& ft
= findTestData
[n
];
3404 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
3406 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
3407 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
3409 size_t resTrue
= ft
.result
;
3410 if ( res
== resTrue
)
3416 printf(_T("(ERROR: should be %s)\n"),
3417 PosToString(resTrue
).c_str());
3424 static void TestStringTokenizer()
3426 puts("*** Testing wxStringTokenizer ***");
3428 static const wxChar
*modeNames
[] =
3432 _T("return all empty"),
3437 static const struct StringTokenizerTest
3439 const wxChar
*str
; // string to tokenize
3440 const wxChar
*delims
; // delimiters to use
3441 size_t count
; // count of token
3442 wxStringTokenizerMode mode
; // how should we tokenize it
3443 } tokenizerTestData
[] =
3445 { _T(""), _T(" "), 0 },
3446 { _T("Hello, world"), _T(" "), 2 },
3447 { _T("Hello, world "), _T(" "), 2 },
3448 { _T("Hello, world"), _T(","), 2 },
3449 { _T("Hello, world!"), _T(",!"), 2 },
3450 { _T("Hello,, world!"), _T(",!"), 3 },
3451 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
3452 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
3453 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
3454 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
3455 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
3456 { _T("01/02/99"), _T("/-"), 3 },
3457 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
3460 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
3462 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
3463 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
3465 size_t count
= tkz
.CountTokens();
3466 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
3467 MakePrintable(tt
.str
).c_str(),
3469 MakePrintable(tt
.delims
).c_str(),
3470 modeNames
[tkz
.GetMode()]);
3471 if ( count
== tt
.count
)
3477 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
3482 // if we emulate strtok(), check that we do it correctly
3483 wxChar
*buf
, *s
= NULL
, *last
;
3485 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
3487 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
3488 wxStrcpy(buf
, tt
.str
);
3490 s
= wxStrtok(buf
, tt
.delims
, &last
);
3497 // now show the tokens themselves
3499 while ( tkz
.HasMoreTokens() )
3501 wxString token
= tkz
.GetNextToken();
3503 printf(_T("\ttoken %u: '%s'"),
3505 MakePrintable(token
).c_str());
3515 printf(" (ERROR: should be %s)\n", s
);
3518 s
= wxStrtok(NULL
, tt
.delims
, &last
);
3522 // nothing to compare with
3527 if ( count2
!= count
)
3529 puts(_T("\tERROR: token count mismatch"));
3538 static void TestStringReplace()
3540 puts("*** Testing wxString::replace ***");
3542 static const struct StringReplaceTestData
3544 const wxChar
*original
; // original test string
3545 size_t start
, len
; // the part to replace
3546 const wxChar
*replacement
; // the replacement string
3547 const wxChar
*result
; // and the expected result
3548 } stringReplaceTestData
[] =
3550 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
3551 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
3552 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
3553 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
3554 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
3557 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
3559 const StringReplaceTestData data
= stringReplaceTestData
[n
];
3561 wxString original
= data
.original
;
3562 original
.replace(data
.start
, data
.len
, data
.replacement
);
3564 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
3565 data
.original
, data
.start
, data
.len
, data
.replacement
,
3568 if ( original
== data
.result
)
3574 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
3581 #endif // TEST_STRINGS
3583 // ----------------------------------------------------------------------------
3585 // ----------------------------------------------------------------------------
3587 int main(int argc
, char **argv
)
3589 if ( !wxInitialize() )
3591 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
3595 puts("Sleeping for 3 seconds... z-z-z-z-z...");
3597 #endif // TEST_USLEEP
3600 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3602 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3603 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3605 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3606 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3607 { wxCMD_LINE_OPTION
, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER
},
3608 { wxCMD_LINE_OPTION
, "d", "date", "output file date", wxCMD_LINE_VAL_DATE
},
3610 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3611 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3616 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
3618 parser
.AddOption("project_name", "", "full path to project file",
3619 wxCMD_LINE_VAL_STRING
,
3620 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3622 switch ( parser
.Parse() )
3625 wxLogMessage("Help was given, terminating.");
3629 ShowCmdLine(parser
);
3633 wxLogMessage("Syntax error detected, aborting.");
3636 #endif // TEST_CMDLINE
3647 TestStringConstruction();
3650 TestStringTokenizer();
3651 TestStringReplace();
3653 #endif // TEST_STRINGS
3666 puts("*** Initially:");
3668 PrintArray("a1", a1
);
3670 wxArrayString
a2(a1
);
3671 PrintArray("a2", a2
);
3673 wxSortedArrayString
a3(a1
);
3674 PrintArray("a3", a3
);
3676 puts("*** After deleting a string from a1");
3679 PrintArray("a1", a1
);
3680 PrintArray("a2", a2
);
3681 PrintArray("a3", a3
);
3683 puts("*** After reassigning a1 to a2 and a3");
3685 PrintArray("a2", a2
);
3686 PrintArray("a3", a3
);
3688 puts("*** After sorting a1");
3690 PrintArray("a1", a1
);
3692 puts("*** After sorting a1 in reverse order");
3694 PrintArray("a1", a1
);
3696 puts("*** After sorting a1 by the string length");
3697 a1
.Sort(StringLenCompare
);
3698 PrintArray("a1", a1
);
3700 TestArrayOfObjects();
3703 #endif // TEST_ARRAYS
3709 #ifdef TEST_DLLLOADER
3711 #endif // TEST_DLLLOADER
3715 #endif // TEST_ENVIRON
3719 #endif // TEST_EXECUTE
3721 #ifdef TEST_FILECONF
3723 #endif // TEST_FILECONF
3731 for ( size_t n
= 0; n
< 8000; n
++ )
3733 s
<< (char)('A' + (n
% 26));
3737 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
3739 // this one shouldn't be truncated
3742 // but this one will because log functions use fixed size buffer
3743 // (note that it doesn't need '\n' at the end neither - will be added
3745 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
3755 int nCPUs
= wxThread::GetCPUCount();
3756 printf("This system has %d CPUs\n", nCPUs
);
3758 wxThread::SetConcurrency(nCPUs
);
3760 if ( argc
> 1 && argv
[1][0] == 't' )
3761 wxLog::AddTraceMask("thread");
3764 TestDetachedThreads();
3766 TestJoinableThreads();
3768 TestThreadSuspend();
3772 #endif // TEST_THREADS
3774 #ifdef TEST_LONGLONG
3775 // seed pseudo random generator
3776 srand((unsigned)time(NULL
));
3784 TestMultiplication();
3787 TestLongLongConversion();
3788 TestBitOperations();
3790 TestLongLongComparison();
3791 #endif // TEST_LONGLONG
3798 wxLog::AddTraceMask(_T("mime"));
3805 #ifdef TEST_INFO_FUNCTIONS
3808 #endif // TEST_INFO_FUNCTIONS
3810 #ifdef TEST_REGISTRY
3813 TestRegistryAssociation();
3814 #endif // TEST_REGISTRY
3823 TestProtocolFtpUpload();
3824 #endif // TEST_SOCKETS
3828 #endif // TEST_STREAMS
3832 #endif // TEST_TIMER
3834 #ifdef TEST_DATETIME
3847 TestTimeArithmetics();
3856 #endif // TEST_DATETIME
3862 #endif // TEST_VCARD
3866 #endif // TEST_WCHAR
3869 TestZipStreamRead();
3874 TestZlibStreamWrite();
3875 TestZlibStreamRead();