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_EXECUTE
45 //#define TEST_FILECONF
49 //#define TEST_LONGLONG
51 //#define TEST_INFO_FUNCTIONS
53 //#define TEST_SOCKETS
54 //#define TEST_STREAMS
55 //#define TEST_STRINGS
56 //#define TEST_THREADS
58 //#define TEST_VCARD -- don't enable this (VZ)
63 // ----------------------------------------------------------------------------
64 // test class for container objects
65 // ----------------------------------------------------------------------------
67 #if defined(TEST_ARRAYS) || defined(TEST_LIST)
69 class Bar
// Foo is already taken in the hash test
72 Bar(const wxString
& name
) : m_name(name
) { ms_bars
++; }
75 static size_t GetNumber() { return ms_bars
; }
77 const char *GetName() const { return m_name
; }
82 static size_t ms_bars
;
85 size_t Bar::ms_bars
= 0;
87 #endif // defined(TEST_ARRAYS) || defined(TEST_LIST)
89 // ============================================================================
91 // ============================================================================
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #if defined(TEST_STRINGS) || defined(TEST_SOCKETS)
99 // replace TABs with \t and CRs with \n
100 static wxString
MakePrintable(const wxChar
*s
)
103 (void)str
.Replace(_T("\t"), _T("\\t"));
104 (void)str
.Replace(_T("\n"), _T("\\n"));
105 (void)str
.Replace(_T("\r"), _T("\\r"));
110 #endif // MakePrintable() is used
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
118 #include <wx/cmdline.h>
119 #include <wx/datetime.h>
121 static void ShowCmdLine(const wxCmdLineParser
& parser
)
123 wxString s
= "Input files: ";
125 size_t count
= parser
.GetParamCount();
126 for ( size_t param
= 0; param
< count
; param
++ )
128 s
<< parser
.GetParam(param
) << ' ';
132 << "Verbose:\t" << (parser
.Found("v") ? "yes" : "no") << '\n'
133 << "Quiet:\t" << (parser
.Found("q") ? "yes" : "no") << '\n';
138 if ( parser
.Found("o", &strVal
) )
139 s
<< "Output file:\t" << strVal
<< '\n';
140 if ( parser
.Found("i", &strVal
) )
141 s
<< "Input dir:\t" << strVal
<< '\n';
142 if ( parser
.Found("s", &lVal
) )
143 s
<< "Size:\t" << lVal
<< '\n';
144 if ( parser
.Found("d", &dt
) )
145 s
<< "Date:\t" << dt
.FormatISODate() << '\n';
146 if ( parser
.Found("project_name", &strVal
) )
147 s
<< "Project:\t" << strVal
<< '\n';
152 #endif // TEST_CMDLINE
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
162 static void TestDirEnumHelper(wxDir
& dir
,
163 int flags
= wxDIR_DEFAULT
,
164 const wxString
& filespec
= wxEmptyString
)
168 if ( !dir
.IsOpened() )
171 bool cont
= dir
.GetFirst(&filename
, filespec
, flags
);
174 printf("\t%s\n", filename
.c_str());
176 cont
= dir
.GetNext(&filename
);
182 static void TestDirEnum()
184 wxDir
dir(wxGetCwd());
186 puts("Enumerating everything in current directory:");
187 TestDirEnumHelper(dir
);
189 puts("Enumerating really everything in current directory:");
190 TestDirEnumHelper(dir
, wxDIR_DEFAULT
| wxDIR_DOTDOT
);
192 puts("Enumerating object files in current directory:");
193 TestDirEnumHelper(dir
, wxDIR_DEFAULT
, "*.o");
195 puts("Enumerating directories in current directory:");
196 TestDirEnumHelper(dir
, wxDIR_DIRS
);
198 puts("Enumerating files in current directory:");
199 TestDirEnumHelper(dir
, wxDIR_FILES
);
201 puts("Enumerating files including hidden in current directory:");
202 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
206 #elif defined(__WXMSW__)
209 #error "don't know where the root directory is"
212 puts("Enumerating everything in root directory:");
213 TestDirEnumHelper(dir
, wxDIR_DEFAULT
);
215 puts("Enumerating directories in root directory:");
216 TestDirEnumHelper(dir
, wxDIR_DIRS
);
218 puts("Enumerating files in root directory:");
219 TestDirEnumHelper(dir
, wxDIR_FILES
);
221 puts("Enumerating files including hidden in root directory:");
222 TestDirEnumHelper(dir
, wxDIR_FILES
| wxDIR_HIDDEN
);
224 puts("Enumerating files in non existing directory:");
225 wxDir
dirNo("nosuchdir");
226 TestDirEnumHelper(dirNo
);
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
235 #ifdef TEST_DLLLOADER
237 #include <wx/dynlib.h>
239 static void TestDllLoad()
241 #if defined(__WXMSW__)
242 static const wxChar
*LIB_NAME
= _T("kernel32.dll");
243 static const wxChar
*FUNC_NAME
= _T("lstrlenA");
244 #elif defined(__UNIX__)
245 // weird: using just libc.so does *not* work!
246 static const wxChar
*LIB_NAME
= _T("/lib/libc-2.0.7.so");
247 static const wxChar
*FUNC_NAME
= _T("strlen");
249 #error "don't know how to test wxDllLoader on this platform"
252 puts("*** testing wxDllLoader ***\n");
254 wxDllType dllHandle
= wxDllLoader::LoadLibrary(LIB_NAME
);
257 wxPrintf(_T("ERROR: failed to load '%s'.\n"), LIB_NAME
);
261 typedef int (*strlenType
)(char *);
262 strlenType pfnStrlen
= (strlenType
)wxDllLoader::GetSymbol(dllHandle
, FUNC_NAME
);
265 wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
266 FUNC_NAME
, LIB_NAME
);
270 if ( pfnStrlen("foo") != 3 )
272 wxPrintf(_T("ERROR: loaded function is not strlen()!\n"));
280 wxDllLoader::UnloadLibrary(dllHandle
);
284 #endif // TEST_DLLLOADER
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
292 #include <wx/utils.h>
294 static void TestExecute()
296 puts("*** testing wxExecute ***");
299 #define COMMAND "echo hi"
300 #define SHELL_COMMAND "echo hi from shell"
301 #define REDIRECT_COMMAND "date"
302 #elif defined(__WXMSW__)
303 #define COMMAND "command.com -c 'echo hi'"
304 #define SHELL_COMMAND "echo hi"
305 #define REDIRECT_COMMAND COMMAND
307 #error "no command to exec"
310 printf("Testing wxShell: ");
312 if ( wxShell(SHELL_COMMAND
) )
317 printf("Testing wxExecute: ");
319 if ( wxExecute(COMMAND
, TRUE
/* sync */) == 0 )
324 #if 0 // no, it doesn't work (yet?)
325 printf("Testing async wxExecute: ");
327 if ( wxExecute(COMMAND
) != 0 )
328 puts("Ok (command launched).");
333 printf("Testing wxExecute with redirection:\n");
334 wxArrayString output
;
335 if ( wxExecute(REDIRECT_COMMAND
, output
) != 0 )
341 size_t count
= output
.GetCount();
342 for ( size_t n
= 0; n
< count
; n
++ )
344 printf("\t%s\n", output
[n
].c_str());
351 #endif // TEST_EXECUTE
353 // ----------------------------------------------------------------------------
355 // ----------------------------------------------------------------------------
360 #include <wx/textfile.h>
362 static void TestFileRead()
364 puts("*** wxFile read test ***");
366 wxFile
file(_T("testdata.fc"));
367 if ( file
.IsOpened() )
369 printf("File length: %lu\n", file
.Length());
371 puts("File dump:\n----------");
373 static const off_t len
= 1024;
377 off_t nRead
= file
.Read(buf
, len
);
378 if ( nRead
== wxInvalidOffset
)
380 printf("Failed to read the file.");
384 fwrite(buf
, nRead
, 1, stdout
);
394 printf("ERROR: can't open test file.\n");
400 static void TestTextFileRead()
402 puts("*** wxTextFile read test ***");
404 wxTextFile
file(_T("testdata.fc"));
407 printf("Number of lines: %u\n", file
.GetLineCount());
408 printf("Last line: '%s'\n", file
.GetLastLine().c_str());
412 puts("\nDumping the entire file:");
413 for ( s
= file
.GetFirstLine(); !file
.Eof(); s
= file
.GetNextLine() )
415 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
417 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
419 puts("\nAnd now backwards:");
420 for ( s
= file
.GetLastLine();
421 file
.GetCurrentLine() != 0;
422 s
= file
.GetPrevLine() )
424 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
426 printf("%6u: %s\n", file
.GetCurrentLine() + 1, s
.c_str());
430 printf("ERROR: can't open '%s'\n", file
.GetName());
438 // ----------------------------------------------------------------------------
440 // ----------------------------------------------------------------------------
444 #include <wx/confbase.h>
445 #include <wx/fileconf.h>
447 static const struct FileConfTestData
449 const wxChar
*name
; // value name
450 const wxChar
*value
; // the value from the file
453 { _T("value1"), _T("one") },
454 { _T("value2"), _T("two") },
455 { _T("novalue"), _T("default") },
458 static void TestFileConfRead()
460 puts("*** testing wxFileConfig loading/reading ***");
462 wxFileConfig
fileconf(_T("test"), wxEmptyString
,
463 _T("testdata.fc"), wxEmptyString
,
464 wxCONFIG_USE_RELATIVE_PATH
);
466 // test simple reading
467 puts("\nReading config file:");
468 wxString
defValue(_T("default")), value
;
469 for ( size_t n
= 0; n
< WXSIZEOF(fcTestData
); n
++ )
471 const FileConfTestData
& data
= fcTestData
[n
];
472 value
= fileconf
.Read(data
.name
, defValue
);
473 printf("\t%s = %s ", data
.name
, value
.c_str());
474 if ( value
== data
.value
)
480 printf("(ERROR: should be %s)\n", data
.value
);
484 // test enumerating the entries
485 puts("\nEnumerating all root entries:");
488 bool cont
= fileconf
.GetFirstEntry(name
, dummy
);
491 printf("\t%s = %s\n",
493 fileconf
.Read(name
.c_str(), _T("ERROR")).c_str());
495 cont
= fileconf
.GetNextEntry(name
, dummy
);
499 #endif // TEST_FILECONF
501 // ----------------------------------------------------------------------------
503 // ----------------------------------------------------------------------------
511 Foo(int n_
) { n
= n_
; count
++; }
519 size_t Foo::count
= 0;
521 WX_DECLARE_LIST(Foo
, wxListFoos
);
522 WX_DECLARE_HASH(Foo
, wxListFoos
, wxHashFoos
);
524 #include <wx/listimpl.cpp>
526 WX_DEFINE_LIST(wxListFoos
);
528 static void TestHash()
530 puts("*** Testing wxHashTable ***\n");
534 hash
.DeleteContents(TRUE
);
536 printf("Hash created: %u foos in hash, %u foos totally\n",
537 hash
.GetCount(), Foo::count
);
539 static const int hashTestData
[] =
541 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
545 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
547 hash
.Put(hashTestData
[n
], n
, new Foo(n
));
550 printf("Hash filled: %u foos in hash, %u foos totally\n",
551 hash
.GetCount(), Foo::count
);
553 puts("Hash access test:");
554 for ( n
= 0; n
< WXSIZEOF(hashTestData
); n
++ )
556 printf("\tGetting element with key %d, value %d: ",
558 Foo
*foo
= hash
.Get(hashTestData
[n
], n
);
561 printf("ERROR, not found.\n");
565 printf("%d (%s)\n", foo
->n
,
566 (size_t)foo
->n
== n
? "ok" : "ERROR");
570 printf("\nTrying to get an element not in hash: ");
572 if ( hash
.Get(1234) || hash
.Get(1, 0) )
574 puts("ERROR: found!");
578 puts("ok (not found)");
582 printf("Hash destroyed: %u foos left\n", Foo::count
);
587 // ----------------------------------------------------------------------------
589 // ----------------------------------------------------------------------------
595 WX_DECLARE_LIST(Bar
, wxListBars
);
596 #include <wx/listimpl.cpp>
597 WX_DEFINE_LIST(wxListBars
);
599 static void TestListCtor()
601 puts("*** Testing wxList construction ***\n");
605 list1
.Append(new Bar(_T("first")));
606 list1
.Append(new Bar(_T("second")));
608 printf("After 1st list creation: %u objects in the list, %u objects total.\n",
609 list1
.GetCount(), Bar::GetNumber());
614 printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
615 list1
.GetCount(), list2
.GetCount(), Bar::GetNumber());
617 list1
.DeleteContents(TRUE
);
620 printf("After list destruction: %u objects left.\n", Bar::GetNumber());
625 // ----------------------------------------------------------------------------
627 // ----------------------------------------------------------------------------
631 #include <wx/mimetype.h>
633 static wxMimeTypesManager g_mimeManager
;
635 static void TestMimeEnum()
637 wxArrayString mimetypes
;
639 size_t count
= g_mimeManager
.EnumAllFileTypes(mimetypes
);
641 printf("*** All %u known filetypes: ***\n", count
);
646 for ( size_t n
= 0; n
< count
; n
++ )
648 wxFileType
*filetype
= g_mimeManager
.GetFileTypeFromMimeType(mimetypes
[n
]);
651 printf("nothing known about the filetype '%s'!\n",
652 mimetypes
[n
].c_str());
656 filetype
->GetDescription(&desc
);
657 filetype
->GetExtensions(exts
);
659 filetype
->GetIcon(NULL
);
662 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
669 printf("\t%s: %s (%s)\n",
670 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
674 static void TestMimeOverride()
676 wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
678 wxString mailcap
= _T("/tmp/mailcap"),
679 mimetypes
= _T("/tmp/mime.types");
681 wxPrintf(_T("Loading mailcap from '%s': %s\n"),
683 g_mimeManager
.ReadMailcap(mailcap
) ? _T("ok") : _T("ERROR"));
684 wxPrintf(_T("Loading mime.types from '%s': %s\n"),
686 g_mimeManager
.ReadMimeTypes(mimetypes
) ? _T("ok") : _T("ERROR"));
689 static void TestMimeFilename()
691 wxPuts(_T("*** Testing MIME type from filename query ***\n"));
693 static const wxChar
*filenames
[] =
700 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
702 const wxString fname
= filenames
[n
];
703 wxString ext
= fname
.AfterLast(_T('.'));
704 wxFileType
*ft
= g_mimeManager
.GetFileTypeFromExtension(ext
);
707 wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
712 if ( !ft
->GetDescription(&desc
) )
713 desc
= _T("<no description>");
716 if ( !ft
->GetOpenCommand(&cmd
,
717 wxFileType::MessageParameters(fname
, _T(""))) )
718 cmd
= _T("<no command available>");
720 wxPrintf(_T("To open %s (%s) do '%s'.\n"),
721 fname
.c_str(), desc
.c_str(), cmd
.c_str());
730 // ----------------------------------------------------------------------------
731 // misc information functions
732 // ----------------------------------------------------------------------------
734 #ifdef TEST_INFO_FUNCTIONS
736 #include <wx/utils.h>
738 static void TestOsInfo()
740 puts("*** Testing OS info functions ***\n");
743 wxGetOsVersion(&major
, &minor
);
744 printf("Running under: %s, version %d.%d\n",
745 wxGetOsDescription().c_str(), major
, minor
);
747 printf("%ld free bytes of memory left.\n", wxGetFreeMemory());
749 printf("Host name is %s (%s).\n",
750 wxGetHostName().c_str(), wxGetFullHostName().c_str());
755 static void TestUserInfo()
757 puts("*** Testing user info functions ***\n");
759 printf("User id is:\t%s\n", wxGetUserId().c_str());
760 printf("User name is:\t%s\n", wxGetUserName().c_str());
761 printf("Home dir is:\t%s\n", wxGetHomeDir().c_str());
762 printf("Email address:\t%s\n", wxGetEmailAddress().c_str());
767 #endif // TEST_INFO_FUNCTIONS
769 // ----------------------------------------------------------------------------
771 // ----------------------------------------------------------------------------
775 #include <wx/longlong.h>
776 #include <wx/timer.h>
778 // make a 64 bit number from 4 16 bit ones
779 #define MAKE_LL(x1, x2, x3, x4) wxLongLong((x1 << 16) | x2, (x3 << 16) | x3)
781 // get a random 64 bit number
782 #define RAND_LL() MAKE_LL(rand(), rand(), rand(), rand())
784 #if wxUSE_LONGLONG_WX
785 inline bool operator==(const wxLongLongWx
& a
, const wxLongLongNative
& b
)
786 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
787 inline bool operator==(const wxLongLongNative
& a
, const wxLongLongWx
& b
)
788 { return a
.GetHi() == b
.GetHi() && a
.GetLo() == b
.GetLo(); }
789 #endif // wxUSE_LONGLONG_WX
791 static void TestSpeed()
793 static const long max
= 100000000;
800 for ( n
= 0; n
< max
; n
++ )
805 printf("Summing longs took %ld milliseconds.\n", sw
.Time());
808 #if wxUSE_LONGLONG_NATIVE
813 for ( n
= 0; n
< max
; n
++ )
818 printf("Summing wxLongLong_t took %ld milliseconds.\n", sw
.Time());
820 #endif // wxUSE_LONGLONG_NATIVE
826 for ( n
= 0; n
< max
; n
++ )
831 printf("Summing wxLongLongs took %ld milliseconds.\n", sw
.Time());
835 static void TestLongLongConversion()
837 puts("*** Testing wxLongLong conversions ***\n");
841 for ( size_t n
= 0; n
< 100000; n
++ )
845 #if wxUSE_LONGLONG_NATIVE
846 wxLongLongNative
b(a
.GetHi(), a
.GetLo());
848 wxASSERT_MSG( a
== b
, "conversions failure" );
850 puts("Can't do it without native long long type, test skipped.");
853 #endif // wxUSE_LONGLONG_NATIVE
855 if ( !(nTested
% 1000) )
867 static void TestMultiplication()
869 puts("*** Testing wxLongLong multiplication ***\n");
873 for ( size_t n
= 0; n
< 100000; n
++ )
878 #if wxUSE_LONGLONG_NATIVE
879 wxLongLongNative
aa(a
.GetHi(), a
.GetLo());
880 wxLongLongNative
bb(b
.GetHi(), b
.GetLo());
882 wxASSERT_MSG( a
*b
== aa
*bb
, "multiplication failure" );
883 #else // !wxUSE_LONGLONG_NATIVE
884 puts("Can't do it without native long long type, test skipped.");
887 #endif // wxUSE_LONGLONG_NATIVE
889 if ( !(nTested
% 1000) )
901 static void TestDivision()
903 puts("*** Testing wxLongLong division ***\n");
907 for ( size_t n
= 0; n
< 100000; n
++ )
909 // get a random wxLongLong (shifting by 12 the MSB ensures that the
910 // multiplication will not overflow)
911 wxLongLong ll
= MAKE_LL((rand() >> 12), rand(), rand(), rand());
913 // get a random long (not wxLongLong for now) to divide it with
918 #if wxUSE_LONGLONG_NATIVE
919 wxLongLongNative
m(ll
.GetHi(), ll
.GetLo());
921 wxLongLongNative p
= m
/ l
, s
= m
% l
;
922 wxASSERT_MSG( q
== p
&& r
== s
, "division failure" );
923 #else // !wxUSE_LONGLONG_NATIVE
925 wxASSERT_MSG( ll
== q
*l
+ r
, "division failure" );
926 #endif // wxUSE_LONGLONG_NATIVE
928 if ( !(nTested
% 1000) )
940 static void TestAddition()
942 puts("*** Testing wxLongLong addition ***\n");
946 for ( size_t n
= 0; n
< 100000; n
++ )
952 #if wxUSE_LONGLONG_NATIVE
953 wxASSERT_MSG( c
== wxLongLongNative(a
.GetHi(), a
.GetLo()) +
954 wxLongLongNative(b
.GetHi(), b
.GetLo()),
955 "addition failure" );
956 #else // !wxUSE_LONGLONG_NATIVE
957 wxASSERT_MSG( c
- b
== a
, "addition failure" );
958 #endif // wxUSE_LONGLONG_NATIVE
960 if ( !(nTested
% 1000) )
972 static void TestBitOperations()
974 puts("*** Testing wxLongLong bit operation ***\n");
978 for ( size_t n
= 0; n
< 100000; n
++ )
982 #if wxUSE_LONGLONG_NATIVE
983 for ( size_t n
= 0; n
< 33; n
++ )
986 #else // !wxUSE_LONGLONG_NATIVE
987 puts("Can't do it without native long long type, test skipped.");
990 #endif // wxUSE_LONGLONG_NATIVE
992 if ( !(nTested
% 1000) )
1004 static void TestLongLongComparison()
1006 puts("*** Testing wxLongLong comparison ***\n");
1008 static const long testLongs
[] =
1019 static const long ls
[2] =
1025 wxLongLongWx lls
[2];
1029 for ( size_t n
= 0; n
< WXSIZEOF(testLongs
); n
++ )
1033 for ( size_t m
= 0; m
< WXSIZEOF(lls
); m
++ )
1035 res
= lls
[m
] > testLongs
[n
];
1036 printf("0x%lx > 0x%lx is %s (%s)\n",
1037 ls
[m
], testLongs
[n
], res
? "true" : "false",
1038 res
== (ls
[m
] > testLongs
[n
]) ? "ok" : "ERROR");
1040 res
= lls
[m
] < testLongs
[n
];
1041 printf("0x%lx < 0x%lx is %s (%s)\n",
1042 ls
[m
], testLongs
[n
], res
? "true" : "false",
1043 res
== (ls
[m
] < testLongs
[n
]) ? "ok" : "ERROR");
1045 res
= lls
[m
] == testLongs
[n
];
1046 printf("0x%lx == 0x%lx is %s (%s)\n",
1047 ls
[m
], testLongs
[n
], res
? "true" : "false",
1048 res
== (ls
[m
] == testLongs
[n
]) ? "ok" : "ERROR");
1056 #endif // TEST_LONGLONG
1058 // ----------------------------------------------------------------------------
1060 // ----------------------------------------------------------------------------
1062 // this is for MSW only
1064 #undef TEST_REGISTRY
1067 #ifdef TEST_REGISTRY
1069 #include <wx/msw/registry.h>
1071 // I chose this one because I liked its name, but it probably only exists under
1073 static const wxChar
*TESTKEY
=
1074 _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
1076 static void TestRegistryRead()
1078 puts("*** testing registry reading ***");
1080 wxRegKey
key(TESTKEY
);
1081 printf("The test key name is '%s'.\n", key
.GetName().c_str());
1084 puts("ERROR: test key can't be opened, aborting test.");
1089 size_t nSubKeys
, nValues
;
1090 if ( key
.GetKeyInfo(&nSubKeys
, NULL
, &nValues
, NULL
) )
1092 printf("It has %u subkeys and %u values.\n", nSubKeys
, nValues
);
1095 printf("Enumerating values:\n");
1099 bool cont
= key
.GetFirstValue(value
, dummy
);
1102 printf("Value '%s': type ", value
.c_str());
1103 switch ( key
.GetValueType(value
) )
1105 case wxRegKey::Type_None
: printf("ERROR (none)"); break;
1106 case wxRegKey::Type_String
: printf("SZ"); break;
1107 case wxRegKey::Type_Expand_String
: printf("EXPAND_SZ"); break;
1108 case wxRegKey::Type_Binary
: printf("BINARY"); break;
1109 case wxRegKey::Type_Dword
: printf("DWORD"); break;
1110 case wxRegKey::Type_Multi_String
: printf("MULTI_SZ"); break;
1111 default: printf("other (unknown)"); break;
1114 printf(", value = ");
1115 if ( key
.IsNumericValue(value
) )
1118 key
.QueryValue(value
, &val
);
1124 key
.QueryValue(value
, val
);
1125 printf("'%s'", val
.c_str());
1127 key
.QueryRawValue(value
, val
);
1128 printf(" (raw value '%s')", val
.c_str());
1133 cont
= key
.GetNextValue(value
, dummy
);
1137 static void TestRegistryAssociation()
1140 The second call to deleteself genertaes an error message, with a
1141 messagebox saying .flo is crucial to system operation, while the .ddf
1142 call also fails, but with no error message
1147 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1149 key
= "ddxf_auto_file" ;
1150 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1152 key
= "ddxf_auto_file" ;
1153 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1156 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1158 key
= "program \"%1\"" ;
1160 key
.SetName("HKEY_CLASSES_ROOT\\.ddf" );
1162 key
.SetName("HKEY_CLASSES_ROOT\\.flo" );
1164 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
1166 key
.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
1170 #endif // TEST_REGISTRY
1172 // ----------------------------------------------------------------------------
1174 // ----------------------------------------------------------------------------
1178 #include <wx/socket.h>
1179 #include <wx/protocol/protocol.h>
1180 #include <wx/protocol/ftp.h>
1181 #include <wx/protocol/http.h>
1183 static void TestSocketServer()
1185 puts("*** Testing wxSocketServer ***\n");
1187 static const int PORT
= 3000;
1192 wxSocketServer
*server
= new wxSocketServer(addr
);
1193 if ( !server
->Ok() )
1195 puts("ERROR: failed to bind");
1202 printf("Server: waiting for connection on port %d...\n", PORT
);
1204 wxSocketBase
*socket
= server
->Accept();
1207 puts("ERROR: wxSocketServer::Accept() failed.");
1211 puts("Server: got a client.");
1213 server
->SetTimeout(60); // 1 min
1215 while ( socket
->IsConnected() )
1221 if ( socket
->Read(&ch
, sizeof(ch
)).Error() )
1223 // don't log error if the client just close the connection
1224 if ( socket
->IsConnected() )
1226 puts("ERROR: in wxSocket::Read.");
1246 printf("Server: got '%s'.\n", s
.c_str());
1247 if ( s
== _T("bye") )
1254 socket
->Write(s
.MakeUpper().c_str(), s
.length());
1255 socket
->Write("\r\n", 2);
1256 printf("Server: wrote '%s'.\n", s
.c_str());
1259 puts("Server: lost a client.");
1264 // same as "delete server" but is consistent with GUI programs
1268 static void TestSocketClient()
1270 puts("*** Testing wxSocketClient ***\n");
1272 static const char *hostname
= "www.wxwindows.org";
1275 addr
.Hostname(hostname
);
1278 printf("--- Attempting to connect to %s:80...\n", hostname
);
1280 wxSocketClient client
;
1281 if ( !client
.Connect(addr
) )
1283 printf("ERROR: failed to connect to %s\n", hostname
);
1287 printf("--- Connected to %s:%u...\n",
1288 addr
.Hostname().c_str(), addr
.Service());
1292 // could use simply "GET" here I suppose
1294 wxString::Format("GET http://%s/\r\n", hostname
);
1295 client
.Write(cmdGet
, cmdGet
.length());
1296 printf("--- Sent command '%s' to the server\n",
1297 MakePrintable(cmdGet
).c_str());
1298 client
.Read(buf
, WXSIZEOF(buf
));
1299 printf("--- Server replied:\n%s", buf
);
1303 static void TestProtocolFtp()
1305 puts("*** Testing wxFTP download ***\n");
1307 wxLog::AddTraceMask(_T("ftp"));
1309 static const char *hostname
= "ftp.wxwindows.org";
1311 printf("--- Attempting to connect to %s:21...\n", hostname
);
1314 if ( !ftp
.Connect(hostname
) )
1316 printf("ERROR: failed to connect to %s\n", hostname
);
1320 printf("--- Connected to %s, current directory is '%s'\n",
1321 hostname
, ftp
.Pwd().c_str());
1322 if ( !ftp
.ChDir(_T("pub")) )
1324 puts("ERROR: failed to cd to pub");
1327 wxArrayString files
;
1328 if ( !ftp
.GetList(files
) )
1330 puts("ERROR: failed to get list of files");
1334 printf("List of files under '%s':\n", ftp
.Pwd().c_str());
1335 size_t count
= files
.GetCount();
1336 for ( size_t n
= 0; n
< count
; n
++ )
1338 printf("\t%s\n", files
[n
].c_str());
1340 puts("End of the file list");
1343 if ( !ftp
.ChDir(_T("..")) )
1345 puts("ERROR: failed to cd to ..");
1348 static const char *filename
= "welcome.msg";
1349 wxInputStream
*in
= ftp
.GetInputStream(filename
);
1352 puts("ERROR: couldn't get input stream");
1356 size_t size
= in
->StreamSize();
1357 printf("Reading file %s (%u bytes)...", filename
, size
);
1359 char *data
= new char[size
];
1360 if ( !in
->Read(data
, size
) )
1362 puts("ERROR: read error");
1366 printf("\nContents of %s:\n%s\n", filename
, data
);
1375 static void TestProtocolFtpUpload()
1377 puts("*** Testing wxFTP uploading ***\n");
1379 wxLog::AddTraceMask(_T("ftp"));
1381 static const char *hostname
= "localhost";
1383 printf("--- Attempting to connect to %s:21...\n", hostname
);
1386 ftp
.SetUser("zeitlin");
1387 ftp
.SetPassword("insert your password here");
1388 if ( !ftp
.Connect(hostname
) )
1390 printf("ERROR: failed to connect to %s\n", hostname
);
1394 printf("--- Connected to %s, current directory is '%s'\n",
1395 hostname
, ftp
.Pwd().c_str());
1398 static const char *file1
= "test1";
1399 static const char *file2
= "test2";
1400 wxOutputStream
*out
= ftp
.GetOutputStream(file1
);
1403 printf("--- Uploading to %s ---\n", file1
);
1404 out
->Write("First hello", 11);
1408 out
= ftp
.GetOutputStream(file2
);
1411 printf("--- Uploading to %s ---\n", file1
);
1412 out
->Write("Second hello", 12);
1418 #endif // TEST_SOCKETS
1420 // ----------------------------------------------------------------------------
1422 // ----------------------------------------------------------------------------
1426 #include <wx/mstream.h>
1428 static void TestMemoryStream()
1430 puts("*** Testing wxMemoryInputStream ***");
1433 wxStrncpy(buf
, _T("Hello, stream!"), WXSIZEOF(buf
));
1435 wxMemoryInputStream
memInpStream(buf
, wxStrlen(buf
));
1436 printf(_T("Memory stream size: %u\n"), memInpStream
.GetSize());
1437 while ( !memInpStream
.Eof() )
1439 putchar(memInpStream
.GetC());
1442 puts("\n*** wxMemoryInputStream test done ***");
1445 #endif // TEST_STREAMS
1447 // ----------------------------------------------------------------------------
1449 // ----------------------------------------------------------------------------
1453 #include <wx/timer.h>
1454 #include <wx/utils.h>
1456 static void TestStopWatch()
1458 puts("*** Testing wxStopWatch ***\n");
1461 printf("Sleeping 3 seconds...");
1463 printf("\telapsed time: %ldms\n", sw
.Time());
1466 printf("Sleeping 2 more seconds...");
1468 printf("\telapsed time: %ldms\n", sw
.Time());
1471 printf("And 3 more seconds...");
1473 printf("\telapsed time: %ldms\n", sw
.Time());
1476 puts("\nChecking for 'backwards clock' bug...");
1477 for ( size_t n
= 0; n
< 70; n
++ )
1481 for ( size_t m
= 0; m
< 100000; m
++ )
1483 if ( sw
.Time() < 0 || sw2
.Time() < 0 )
1485 puts("\ntime is negative - ERROR!");
1495 #endif // TEST_TIMER
1497 // ----------------------------------------------------------------------------
1499 // ----------------------------------------------------------------------------
1503 #include <wx/vcard.h>
1505 static void DumpVObject(size_t level
, const wxVCardObject
& vcard
)
1508 wxVCardObject
*vcObj
= vcard
.GetFirstProp(&cookie
);
1512 wxString(_T('\t'), level
).c_str(),
1513 vcObj
->GetName().c_str());
1516 switch ( vcObj
->GetType() )
1518 case wxVCardObject::String
:
1519 case wxVCardObject::UString
:
1522 vcObj
->GetValue(&val
);
1523 value
<< _T('"') << val
<< _T('"');
1527 case wxVCardObject::Int
:
1530 vcObj
->GetValue(&i
);
1531 value
.Printf(_T("%u"), i
);
1535 case wxVCardObject::Long
:
1538 vcObj
->GetValue(&l
);
1539 value
.Printf(_T("%lu"), l
);
1543 case wxVCardObject::None
:
1546 case wxVCardObject::Object
:
1547 value
= _T("<node>");
1551 value
= _T("<unknown value type>");
1555 printf(" = %s", value
.c_str());
1558 DumpVObject(level
+ 1, *vcObj
);
1561 vcObj
= vcard
.GetNextProp(&cookie
);
1565 static void DumpVCardAddresses(const wxVCard
& vcard
)
1567 puts("\nShowing all addresses from vCard:\n");
1571 wxVCardAddress
*addr
= vcard
.GetFirstAddress(&cookie
);
1575 int flags
= addr
->GetFlags();
1576 if ( flags
& wxVCardAddress::Domestic
)
1578 flagsStr
<< _T("domestic ");
1580 if ( flags
& wxVCardAddress::Intl
)
1582 flagsStr
<< _T("international ");
1584 if ( flags
& wxVCardAddress::Postal
)
1586 flagsStr
<< _T("postal ");
1588 if ( flags
& wxVCardAddress::Parcel
)
1590 flagsStr
<< _T("parcel ");
1592 if ( flags
& wxVCardAddress::Home
)
1594 flagsStr
<< _T("home ");
1596 if ( flags
& wxVCardAddress::Work
)
1598 flagsStr
<< _T("work ");
1601 printf("Address %u:\n"
1603 "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
1606 addr
->GetPostOffice().c_str(),
1607 addr
->GetExtAddress().c_str(),
1608 addr
->GetStreet().c_str(),
1609 addr
->GetLocality().c_str(),
1610 addr
->GetRegion().c_str(),
1611 addr
->GetPostalCode().c_str(),
1612 addr
->GetCountry().c_str()
1616 addr
= vcard
.GetNextAddress(&cookie
);
1620 static void DumpVCardPhoneNumbers(const wxVCard
& vcard
)
1622 puts("\nShowing all phone numbers from vCard:\n");
1626 wxVCardPhoneNumber
*phone
= vcard
.GetFirstPhoneNumber(&cookie
);
1630 int flags
= phone
->GetFlags();
1631 if ( flags
& wxVCardPhoneNumber::Voice
)
1633 flagsStr
<< _T("voice ");
1635 if ( flags
& wxVCardPhoneNumber::Fax
)
1637 flagsStr
<< _T("fax ");
1639 if ( flags
& wxVCardPhoneNumber::Cellular
)
1641 flagsStr
<< _T("cellular ");
1643 if ( flags
& wxVCardPhoneNumber::Modem
)
1645 flagsStr
<< _T("modem ");
1647 if ( flags
& wxVCardPhoneNumber::Home
)
1649 flagsStr
<< _T("home ");
1651 if ( flags
& wxVCardPhoneNumber::Work
)
1653 flagsStr
<< _T("work ");
1656 printf("Phone number %u:\n"
1661 phone
->GetNumber().c_str()
1665 phone
= vcard
.GetNextPhoneNumber(&cookie
);
1669 static void TestVCardRead()
1671 puts("*** Testing wxVCard reading ***\n");
1673 wxVCard
vcard(_T("vcard.vcf"));
1674 if ( !vcard
.IsOk() )
1676 puts("ERROR: couldn't load vCard.");
1680 // read individual vCard properties
1681 wxVCardObject
*vcObj
= vcard
.GetProperty("FN");
1685 vcObj
->GetValue(&value
);
1690 value
= _T("<none>");
1693 printf("Full name retrieved directly: %s\n", value
.c_str());
1696 if ( !vcard
.GetFullName(&value
) )
1698 value
= _T("<none>");
1701 printf("Full name from wxVCard API: %s\n", value
.c_str());
1703 // now show how to deal with multiply occuring properties
1704 DumpVCardAddresses(vcard
);
1705 DumpVCardPhoneNumbers(vcard
);
1707 // and finally show all
1708 puts("\nNow dumping the entire vCard:\n"
1709 "-----------------------------\n");
1711 DumpVObject(0, vcard
);
1715 static void TestVCardWrite()
1717 puts("*** Testing wxVCard writing ***\n");
1720 if ( !vcard
.IsOk() )
1722 puts("ERROR: couldn't create vCard.");
1727 vcard
.SetName("Zeitlin", "Vadim");
1728 vcard
.SetFullName("Vadim Zeitlin");
1729 vcard
.SetOrganization("wxWindows", "R&D");
1731 // just dump the vCard back
1732 puts("Entire vCard follows:\n");
1733 puts(vcard
.Write());
1737 #endif // TEST_VCARD
1739 // ----------------------------------------------------------------------------
1740 // wide char (Unicode) support
1741 // ----------------------------------------------------------------------------
1745 #include <wx/strconv.h>
1746 #include <wx/buffer.h>
1748 static void TestUtf8()
1750 puts("*** Testing UTF8 support ***\n");
1752 wxString testString
= "français";
1754 "************ French - Français ****************"
1755 "Juste un petit exemple pour dire que les français aussi"
1756 "ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
1759 wxWCharBuffer wchBuf
= testString
.wc_str(wxConvUTF8
);
1760 const wchar_t *pwz
= (const wchar_t *)wchBuf
;
1761 wxString
testString2(pwz
, wxConvLocal
);
1763 printf("Decoding '%s' => '%s'\n", testString
.c_str(), testString2
.c_str());
1765 char *psz
= "fran" "\xe7" "ais";
1766 size_t len
= strlen(psz
);
1767 wchar_t *pwz2
= new wchar_t[len
+ 1];
1768 for ( size_t n
= 0; n
<= len
; n
++ )
1770 pwz2
[n
] = (wchar_t)(unsigned char)psz
[n
];
1773 wxString
testString3(pwz2
, wxConvUTF8
);
1776 printf("Encoding '%s' -> '%s'\n", psz
, testString3
.c_str());
1779 #endif // TEST_WCHAR
1781 // ----------------------------------------------------------------------------
1783 // ----------------------------------------------------------------------------
1787 #include "wx/zipstrm.h"
1789 static void TestZipStreamRead()
1791 puts("*** Testing ZIP reading ***\n");
1793 wxZipInputStream
istr(_T("idx.zip"), _T("IDX.txt"));
1794 printf("Archive size: %u\n", istr
.GetSize());
1796 puts("Dumping the file:");
1797 while ( !istr
.Eof() )
1799 putchar(istr
.GetC());
1803 puts("\n----- done ------");
1808 // ----------------------------------------------------------------------------
1810 // ----------------------------------------------------------------------------
1814 #include <wx/zstream.h>
1815 #include <wx/wfstream.h>
1817 static const wxChar
*FILENAME_GZ
= _T("test.gz");
1818 static const char *TEST_DATA
= "hello and hello again";
1820 static void TestZlibStreamWrite()
1822 puts("*** Testing Zlib stream reading ***\n");
1824 wxFileOutputStream
fileOutStream(FILENAME_GZ
);
1825 wxZlibOutputStream
ostr(fileOutStream
, 0);
1826 printf("Compressing the test string... ");
1827 ostr
.Write(TEST_DATA
, sizeof(TEST_DATA
));
1830 puts("(ERROR: failed)");
1837 puts("\n----- done ------");
1840 static void TestZlibStreamRead()
1842 puts("*** Testing Zlib stream reading ***\n");
1844 wxFileInputStream
fileInStream(FILENAME_GZ
);
1845 wxZlibInputStream
istr(fileInStream
);
1846 printf("Archive size: %u\n", istr
.GetSize());
1848 puts("Dumping the file:");
1849 while ( !istr
.Eof() )
1851 putchar(istr
.GetC());
1855 puts("\n----- done ------");
1860 // ----------------------------------------------------------------------------
1862 // ----------------------------------------------------------------------------
1864 #ifdef TEST_DATETIME
1866 #include <wx/date.h>
1868 #include <wx/datetime.h>
1873 wxDateTime::wxDateTime_t day
;
1874 wxDateTime::Month month
;
1876 wxDateTime::wxDateTime_t hour
, min
, sec
;
1878 wxDateTime::WeekDay wday
;
1879 time_t gmticks
, ticks
;
1881 void Init(const wxDateTime::Tm
& tm
)
1890 gmticks
= ticks
= -1;
1893 wxDateTime
DT() const
1894 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
1896 bool SameDay(const wxDateTime::Tm
& tm
) const
1898 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
1901 wxString
Format() const
1904 s
.Printf("%02d:%02d:%02d %10s %02d, %4d%s",
1906 wxDateTime::GetMonthName(month
).c_str(),
1908 abs(wxDateTime::ConvertYearToBC(year
)),
1909 year
> 0 ? "AD" : "BC");
1913 wxString
FormatDate() const
1916 s
.Printf("%02d-%s-%4d%s",
1918 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1919 abs(wxDateTime::ConvertYearToBC(year
)),
1920 year
> 0 ? "AD" : "BC");
1925 static const Date testDates
[] =
1927 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
1928 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
1929 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
1930 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
1931 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
1932 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
1933 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
1934 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
1935 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
1936 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
1937 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
1938 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
1939 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
1940 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
1941 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
1944 // this test miscellaneous static wxDateTime functions
1945 static void TestTimeStatic()
1947 puts("\n*** wxDateTime static methods test ***");
1949 // some info about the current date
1950 int year
= wxDateTime::GetCurrentYear();
1951 printf("Current year %d is %sa leap one and has %d days.\n",
1953 wxDateTime::IsLeapYear(year
) ? "" : "not ",
1954 wxDateTime::GetNumberOfDays(year
));
1956 wxDateTime::Month month
= wxDateTime::GetCurrentMonth();
1957 printf("Current month is '%s' ('%s') and it has %d days\n",
1958 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
1959 wxDateTime::GetMonthName(month
).c_str(),
1960 wxDateTime::GetNumberOfDays(month
));
1963 static const size_t nYears
= 5;
1964 static const size_t years
[2][nYears
] =
1966 // first line: the years to test
1967 { 1990, 1976, 2000, 2030, 1984, },
1969 // second line: TRUE if leap, FALSE otherwise
1970 { FALSE
, TRUE
, TRUE
, FALSE
, TRUE
}
1973 for ( size_t n
= 0; n
< nYears
; n
++ )
1975 int year
= years
[0][n
];
1976 bool should
= years
[1][n
] != 0,
1977 is
= wxDateTime::IsLeapYear(year
);
1979 printf("Year %d is %sa leap year (%s)\n",
1982 should
== is
? "ok" : "ERROR");
1984 wxASSERT( should
== wxDateTime::IsLeapYear(year
) );
1988 // test constructing wxDateTime objects
1989 static void TestTimeSet()
1991 puts("\n*** wxDateTime construction test ***");
1993 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
1995 const Date
& d1
= testDates
[n
];
1996 wxDateTime dt
= d1
.DT();
1999 d2
.Init(dt
.GetTm());
2001 wxString s1
= d1
.Format(),
2004 printf("Date: %s == %s (%s)\n",
2005 s1
.c_str(), s2
.c_str(),
2006 s1
== s2
? "ok" : "ERROR");
2010 // test time zones stuff
2011 static void TestTimeZones()
2013 puts("\n*** wxDateTime timezone test ***");
2015 wxDateTime now
= wxDateTime::Now();
2017 printf("Current GMT time:\t%s\n", now
.Format("%c", wxDateTime::GMT0
).c_str());
2018 printf("Unix epoch (GMT):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::GMT0
).c_str());
2019 printf("Unix epoch (EST):\t%s\n", wxDateTime((time_t)0).Format("%c", wxDateTime::EST
).c_str());
2020 printf("Current time in Paris:\t%s\n", now
.Format("%c", wxDateTime::CET
).c_str());
2021 printf(" Moscow:\t%s\n", now
.Format("%c", wxDateTime::MSK
).c_str());
2022 printf(" New York:\t%s\n", now
.Format("%c", wxDateTime::EST
).c_str());
2024 wxDateTime::Tm tm
= now
.GetTm();
2025 if ( wxDateTime(tm
) != now
)
2027 printf("ERROR: got %s instead of %s\n",
2028 wxDateTime(tm
).Format().c_str(), now
.Format().c_str());
2032 // test some minimal support for the dates outside the standard range
2033 static void TestTimeRange()
2035 puts("\n*** wxDateTime out-of-standard-range dates test ***");
2037 static const char *fmt
= "%d-%b-%Y %H:%M:%S";
2039 printf("Unix epoch:\t%s\n",
2040 wxDateTime(2440587.5).Format(fmt
).c_str());
2041 printf("Feb 29, 0: \t%s\n",
2042 wxDateTime(29, wxDateTime::Feb
, 0).Format(fmt
).c_str());
2043 printf("JDN 0: \t%s\n",
2044 wxDateTime(0.0).Format(fmt
).c_str());
2045 printf("Jan 1, 1AD:\t%s\n",
2046 wxDateTime(1, wxDateTime::Jan
, 1).Format(fmt
).c_str());
2047 printf("May 29, 2099:\t%s\n",
2048 wxDateTime(29, wxDateTime::May
, 2099).Format(fmt
).c_str());
2051 static void TestTimeTicks()
2053 puts("\n*** wxDateTime ticks test ***");
2055 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2057 const Date
& d
= testDates
[n
];
2058 if ( d
.ticks
== -1 )
2061 wxDateTime dt
= d
.DT();
2062 long ticks
= (dt
.GetValue() / 1000).ToLong();
2063 printf("Ticks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2064 if ( ticks
== d
.ticks
)
2070 printf(" (ERROR: should be %ld, delta = %ld)\n",
2071 d
.ticks
, ticks
- d
.ticks
);
2074 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
2075 ticks
= (dt
.GetValue() / 1000).ToLong();
2076 printf("GMtks of %s:\t% 10ld", d
.Format().c_str(), ticks
);
2077 if ( ticks
== d
.gmticks
)
2083 printf(" (ERROR: should be %ld, delta = %ld)\n",
2084 d
.gmticks
, ticks
- d
.gmticks
);
2091 // test conversions to JDN &c
2092 static void TestTimeJDN()
2094 puts("\n*** wxDateTime to JDN test ***");
2096 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
2098 const Date
& d
= testDates
[n
];
2099 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
2100 double jdn
= dt
.GetJulianDayNumber();
2102 printf("JDN of %s is:\t% 15.6f", d
.Format().c_str(), jdn
);
2109 printf(" (ERROR: should be %f, delta = %f)\n",
2110 d
.jdn
, jdn
- d
.jdn
);
2115 // test week days computation
2116 static void TestTimeWDays()
2118 puts("\n*** wxDateTime weekday test ***");
2120 // test GetWeekDay()
2122 for ( 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
);
2127 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
2130 wxDateTime::GetWeekDayName(wday
).c_str());
2131 if ( wday
== d
.wday
)
2137 printf(" (ERROR: should be %s)\n",
2138 wxDateTime::GetWeekDayName(d
.wday
).c_str());
2144 // test SetToWeekDay()
2145 struct WeekDateTestData
2147 Date date
; // the real date (precomputed)
2148 int nWeek
; // its week index in the month
2149 wxDateTime::WeekDay wday
; // the weekday
2150 wxDateTime::Month month
; // the month
2151 int year
; // and the year
2153 wxString
Format() const
2156 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
2158 case 1: which
= "first"; break;
2159 case 2: which
= "second"; break;
2160 case 3: which
= "third"; break;
2161 case 4: which
= "fourth"; break;
2162 case 5: which
= "fifth"; break;
2164 case -1: which
= "last"; break;
2169 which
+= " from end";
2172 s
.Printf("The %s %s of %s in %d",
2174 wxDateTime::GetWeekDayName(wday
).c_str(),
2175 wxDateTime::GetMonthName(month
).c_str(),
2182 // the array data was generated by the following python program
2184 from DateTime import *
2185 from whrandom import *
2186 from string import *
2188 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2189 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2191 week = DateTimeDelta(7)
2194 year = randint(1900, 2100)
2195 month = randint(1, 12)
2196 day = randint(1, 28)
2197 dt = DateTime(year, month, day)
2198 wday = dt.day_of_week
2200 countFromEnd = choice([-1, 1])
2203 while dt.month is month:
2204 dt = dt - countFromEnd * week
2205 weekNum = weekNum + countFromEnd
2207 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
2209 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
2210 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
2213 static const WeekDateTestData weekDatesTestData
[] =
2215 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
2216 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
2217 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
2218 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
2219 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
2220 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
2221 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
2222 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
2223 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
2224 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
2225 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
2226 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
2227 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
2228 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
2229 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
2230 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
2231 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
2232 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
2233 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
2234 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
2237 static const char *fmt
= "%d-%b-%Y";
2240 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
2242 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
2244 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
2246 printf("%s is %s", wd
.Format().c_str(), dt
.Format(fmt
).c_str());
2248 const Date
& d
= wd
.date
;
2249 if ( d
.SameDay(dt
.GetTm()) )
2255 dt
.Set(d
.day
, d
.month
, d
.year
);
2257 printf(" (ERROR: should be %s)\n", dt
.Format(fmt
).c_str());
2262 // test the computation of (ISO) week numbers
2263 static void TestTimeWNumber()
2265 puts("\n*** wxDateTime week number test ***");
2267 struct WeekNumberTestData
2269 Date date
; // the date
2270 wxDateTime::wxDateTime_t week
; // the week number in the year
2271 wxDateTime::wxDateTime_t wmon
; // the week number in the month
2272 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
2273 wxDateTime::wxDateTime_t dnum
; // day number in the year
2276 // data generated with the following python script:
2278 from DateTime import *
2279 from whrandom import *
2280 from string import *
2282 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
2283 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
2285 def GetMonthWeek(dt):
2286 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
2287 if weekNumMonth < 0:
2288 weekNumMonth = weekNumMonth + 53
2291 def GetLastSundayBefore(dt):
2292 if dt.iso_week[2] == 7:
2295 return dt - DateTimeDelta(dt.iso_week[2])
2298 year = randint(1900, 2100)
2299 month = randint(1, 12)
2300 day = randint(1, 28)
2301 dt = DateTime(year, month, day)
2302 dayNum = dt.day_of_year
2303 weekNum = dt.iso_week[1]
2304 weekNumMonth = GetMonthWeek(dt)
2307 dtSunday = GetLastSundayBefore(dt)
2309 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
2310 weekNumMonth2 = weekNumMonth2 + 1
2311 dtSunday = dtSunday - DateTimeDelta(7)
2313 data = { 'day': rjust(`day`, 2), \
2314 'month': monthNames[month - 1], \
2316 'weekNum': rjust(`weekNum`, 2), \
2317 'weekNumMonth': weekNumMonth, \
2318 'weekNumMonth2': weekNumMonth2, \
2319 'dayNum': rjust(`dayNum`, 3) }
2321 print " { { %(day)s, "\
2322 "wxDateTime::%(month)s, "\
2325 "%(weekNumMonth)s, "\
2326 "%(weekNumMonth2)s, "\
2327 "%(dayNum)s }," % data
2330 static const WeekNumberTestData weekNumberTestDates
[] =
2332 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
2333 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
2334 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
2335 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
2336 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
2337 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
2338 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
2339 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
2340 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
2341 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
2342 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
2343 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
2344 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
2345 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
2346 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
2347 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
2348 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
2349 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
2350 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
2351 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
2354 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
2356 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
2357 const Date
& d
= wn
.date
;
2359 wxDateTime dt
= d
.DT();
2361 wxDateTime::wxDateTime_t
2362 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
2363 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2364 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2365 dnum
= dt
.GetDayOfYear();
2367 printf("%s: the day number is %d",
2368 d
.FormatDate().c_str(), dnum
);
2369 if ( dnum
== wn
.dnum
)
2375 printf(" (ERROR: should be %d)", wn
.dnum
);
2378 printf(", week in month is %d", wmon
);
2379 if ( wmon
== wn
.wmon
)
2385 printf(" (ERROR: should be %d)", wn
.wmon
);
2388 printf(" or %d", wmon2
);
2389 if ( wmon2
== wn
.wmon2
)
2395 printf(" (ERROR: should be %d)", wn
.wmon2
);
2398 printf(", week in year is %d", week
);
2399 if ( week
== wn
.week
)
2405 printf(" (ERROR: should be %d)\n", wn
.week
);
2410 // test DST calculations
2411 static void TestTimeDST()
2413 puts("\n*** wxDateTime DST test ***");
2415 printf("DST is%s in effect now.\n\n",
2416 wxDateTime::Now().IsDST() ? "" : " not");
2418 // taken from http://www.energy.ca.gov/daylightsaving.html
2419 static const Date datesDST
[2][2004 - 1900 + 1] =
2422 { 1, wxDateTime::Apr
, 1990 },
2423 { 7, wxDateTime::Apr
, 1991 },
2424 { 5, wxDateTime::Apr
, 1992 },
2425 { 4, wxDateTime::Apr
, 1993 },
2426 { 3, wxDateTime::Apr
, 1994 },
2427 { 2, wxDateTime::Apr
, 1995 },
2428 { 7, wxDateTime::Apr
, 1996 },
2429 { 6, wxDateTime::Apr
, 1997 },
2430 { 5, wxDateTime::Apr
, 1998 },
2431 { 4, wxDateTime::Apr
, 1999 },
2432 { 2, wxDateTime::Apr
, 2000 },
2433 { 1, wxDateTime::Apr
, 2001 },
2434 { 7, wxDateTime::Apr
, 2002 },
2435 { 6, wxDateTime::Apr
, 2003 },
2436 { 4, wxDateTime::Apr
, 2004 },
2439 { 28, wxDateTime::Oct
, 1990 },
2440 { 27, wxDateTime::Oct
, 1991 },
2441 { 25, wxDateTime::Oct
, 1992 },
2442 { 31, wxDateTime::Oct
, 1993 },
2443 { 30, wxDateTime::Oct
, 1994 },
2444 { 29, wxDateTime::Oct
, 1995 },
2445 { 27, wxDateTime::Oct
, 1996 },
2446 { 26, wxDateTime::Oct
, 1997 },
2447 { 25, wxDateTime::Oct
, 1998 },
2448 { 31, wxDateTime::Oct
, 1999 },
2449 { 29, wxDateTime::Oct
, 2000 },
2450 { 28, wxDateTime::Oct
, 2001 },
2451 { 27, wxDateTime::Oct
, 2002 },
2452 { 26, wxDateTime::Oct
, 2003 },
2453 { 31, wxDateTime::Oct
, 2004 },
2458 for ( year
= 1990; year
< 2005; year
++ )
2460 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
2461 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
2463 printf("DST period in the US for year %d: from %s to %s",
2464 year
, dtBegin
.Format().c_str(), dtEnd
.Format().c_str());
2466 size_t n
= year
- 1990;
2467 const Date
& dBegin
= datesDST
[0][n
];
2468 const Date
& dEnd
= datesDST
[1][n
];
2470 if ( dBegin
.SameDay(dtBegin
.GetTm()) && dEnd
.SameDay(dtEnd
.GetTm()) )
2476 printf(" (ERROR: should be %s %d to %s %d)\n",
2477 wxDateTime::GetMonthName(dBegin
.month
).c_str(), dBegin
.day
,
2478 wxDateTime::GetMonthName(dEnd
.month
).c_str(), dEnd
.day
);
2484 for ( year
= 1990; year
< 2005; year
++ )
2486 printf("DST period in Europe for year %d: from %s to %s\n",
2488 wxDateTime::GetBeginDST(year
, wxDateTime::Country_EEC
).Format().c_str(),
2489 wxDateTime::GetEndDST(year
, wxDateTime::Country_EEC
).Format().c_str());
2493 // test wxDateTime -> text conversion
2494 static void TestTimeFormat()
2496 puts("\n*** wxDateTime formatting test ***");
2498 // some information may be lost during conversion, so store what kind
2499 // of info should we recover after a round trip
2502 CompareNone
, // don't try comparing
2503 CompareBoth
, // dates and times should be identical
2504 CompareDate
, // dates only
2505 CompareTime
// time only
2510 CompareKind compareKind
;
2512 } formatTestFormats
[] =
2514 { CompareBoth
, "---> %c" },
2515 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
2516 { CompareBoth
, "Date is %x, time is %X" },
2517 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
2518 { CompareNone
, "The day of year: %j, the week of year: %W" },
2519 { CompareDate
, "ISO date without separators: %4Y%2m%2d" },
2522 static const Date formatTestDates
[] =
2524 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
2525 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
2527 // this test can't work for other centuries because it uses two digit
2528 // years in formats, so don't even try it
2529 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
2530 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
2531 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
2535 // an extra test (as it doesn't depend on date, don't do it in the loop)
2536 printf("%s\n", wxDateTime::Now().Format("Our timezone is %Z").c_str());
2538 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
2542 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
2543 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
2545 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
2546 printf("%s", s
.c_str());
2548 // what can we recover?
2549 int kind
= formatTestFormats
[n
].compareKind
;
2553 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
2556 // converion failed - should it have?
2557 if ( kind
== CompareNone
)
2560 puts(" (ERROR: conversion back failed)");
2564 // should have parsed the entire string
2565 puts(" (ERROR: conversion back stopped too soon)");
2569 bool equal
= FALSE
; // suppress compilaer warning
2577 equal
= dt
.IsSameDate(dt2
);
2581 equal
= dt
.IsSameTime(dt2
);
2587 printf(" (ERROR: got back '%s' instead of '%s')\n",
2588 dt2
.Format().c_str(), dt
.Format().c_str());
2599 // test text -> wxDateTime conversion
2600 static void TestTimeParse()
2602 puts("\n*** wxDateTime parse test ***");
2604 struct ParseTestData
2611 static const ParseTestData parseTestDates
[] =
2613 { "Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, TRUE
},
2614 { "Wed, 1 Dec 1999 05:17:20 +0300", { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, TRUE
},
2617 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
2619 const char *format
= parseTestDates
[n
].format
;
2621 printf("%s => ", format
);
2624 if ( dt
.ParseRfc822Date(format
) )
2626 printf("%s ", dt
.Format().c_str());
2628 if ( parseTestDates
[n
].good
)
2630 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
2637 printf("(ERROR: should be %s)\n", dtReal
.Format().c_str());
2642 puts("(ERROR: bad format)");
2647 printf("bad format (%s)\n",
2648 parseTestDates
[n
].good
? "ERROR" : "ok");
2653 static void TestInteractive()
2655 puts("\n*** interactive wxDateTime tests ***");
2661 printf("Enter a date: ");
2662 if ( !fgets(buf
, WXSIZEOF(buf
), stdin
) )
2665 // kill the last '\n'
2666 buf
[strlen(buf
) - 1] = 0;
2669 const char *p
= dt
.ParseDate(buf
);
2672 printf("ERROR: failed to parse the date '%s'.\n", buf
);
2678 printf("WARNING: parsed only first %u characters.\n", p
- buf
);
2681 printf("%s: day %u, week of month %u/%u, week of year %u\n",
2682 dt
.Format("%b %d, %Y").c_str(),
2684 dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
2685 dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
2686 dt
.GetWeekOfYear(wxDateTime::Monday_First
));
2689 puts("\n*** done ***");
2692 static void TestTimeMS()
2694 puts("*** testing millisecond-resolution support in wxDateTime ***");
2696 wxDateTime dt1
= wxDateTime::Now(),
2697 dt2
= wxDateTime::UNow();
2699 printf("Now = %s\n", dt1
.Format("%H:%M:%S:%l").c_str());
2700 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2701 printf("Dummy loop: ");
2702 for ( int i
= 0; i
< 6000; i
++ )
2704 //for ( int j = 0; j < 10; j++ )
2707 s
.Printf("%g", sqrt(i
));
2716 dt2
= wxDateTime::UNow();
2717 printf("UNow = %s\n", dt2
.Format("%H:%M:%S:%l").c_str());
2719 printf("Loop executed in %s ms\n", (dt2
- dt1
).Format("%l").c_str());
2721 puts("\n*** done ***");
2724 static void TestTimeArithmetics()
2726 puts("\n*** testing arithmetic operations on wxDateTime ***");
2728 static const struct ArithmData
2730 ArithmData(const wxDateSpan
& sp
, const char *nam
)
2731 : span(sp
), name(nam
) { }
2735 } testArithmData
[] =
2737 ArithmData(wxDateSpan::Day(), "day"),
2738 ArithmData(wxDateSpan::Week(), "week"),
2739 ArithmData(wxDateSpan::Month(), "month"),
2740 ArithmData(wxDateSpan::Year(), "year"),
2741 ArithmData(wxDateSpan(1, 2, 3, 4), "year, 2 months, 3 weeks, 4 days"),
2744 wxDateTime
dt(29, wxDateTime::Dec
, 1999), dt1
, dt2
;
2746 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
2748 wxDateSpan span
= testArithmData
[n
].span
;
2752 const char *name
= testArithmData
[n
].name
;
2753 printf("%s + %s = %s, %s - %s = %s\n",
2754 dt
.FormatISODate().c_str(), name
, dt1
.FormatISODate().c_str(),
2755 dt
.FormatISODate().c_str(), name
, dt2
.FormatISODate().c_str());
2757 printf("Going back: %s", (dt1
- span
).FormatISODate().c_str());
2758 if ( dt1
- span
== dt
)
2764 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2767 printf("Going forward: %s", (dt2
+ span
).FormatISODate().c_str());
2768 if ( dt2
+ span
== dt
)
2774 printf(" (ERROR: should be %s)\n", dt
.FormatISODate().c_str());
2777 printf("Double increment: %s", (dt2
+ 2*span
).FormatISODate().c_str());
2778 if ( dt2
+ 2*span
== dt1
)
2784 printf(" (ERROR: should be %s)\n", dt2
.FormatISODate().c_str());
2791 static void TestTimeHolidays()
2793 puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
2795 wxDateTime::Tm tm
= wxDateTime(29, wxDateTime::May
, 2000).GetTm();
2796 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
2797 dtEnd
= dtStart
.GetLastMonthDay();
2799 wxDateTimeArray hol
;
2800 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
2802 const wxChar
*format
= "%d-%b-%Y (%a)";
2804 printf("All holidays between %s and %s:\n",
2805 dtStart
.Format(format
).c_str(), dtEnd
.Format(format
).c_str());
2807 size_t count
= hol
.GetCount();
2808 for ( size_t n
= 0; n
< count
; n
++ )
2810 printf("\t%s\n", hol
[n
].Format(format
).c_str());
2816 static void TestTimeZoneBug()
2818 puts("\n*** testing for DST/timezone bug ***\n");
2820 wxDateTime date
= wxDateTime(1, wxDateTime::Mar
, 2000);
2821 for ( int i
= 0; i
< 31; i
++ )
2823 printf("Date %s: week day %s.\n",
2824 date
.Format(_T("%d-%m-%Y")).c_str(),
2825 date
.GetWeekDayName(date
.GetWeekDay()).c_str());
2827 date
+= wxDateSpan::Day();
2835 // test compatibility with the old wxDate/wxTime classes
2836 static void TestTimeCompatibility()
2838 puts("\n*** wxDateTime compatibility test ***");
2840 printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
2841 printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
2843 double jdnNow
= wxDateTime::Now().GetJDN();
2844 long jdnMidnight
= (long)(jdnNow
- 0.5);
2845 printf("wxDate for today: %s\n", wxDate(jdnMidnight
).FormatDate().c_str());
2847 jdnMidnight
= wxDate().Set().GetJulianDate();
2848 printf("wxDateTime for today: %s\n",
2849 wxDateTime((double)(jdnMidnight
+ 0.5)).Format("%c", wxDateTime::GMT0
).c_str());
2851 int flags
= wxEUROPEAN
;//wxFULL;
2854 printf("Today is %s\n", date
.FormatDate(flags
).c_str());
2855 for ( int n
= 0; n
< 7; n
++ )
2857 printf("Previous %s is %s\n",
2858 wxDateTime::GetWeekDayName((wxDateTime::WeekDay
)n
),
2859 date
.Previous(n
+ 1).FormatDate(flags
).c_str());
2865 #endif // TEST_DATETIME
2867 // ----------------------------------------------------------------------------
2869 // ----------------------------------------------------------------------------
2873 #include <wx/thread.h>
2875 static size_t gs_counter
= (size_t)-1;
2876 static wxCriticalSection gs_critsect
;
2877 static wxCondition gs_cond
;
2879 class MyJoinableThread
: public wxThread
2882 MyJoinableThread(size_t n
) : wxThread(wxTHREAD_JOINABLE
)
2883 { m_n
= n
; Create(); }
2885 // thread execution starts here
2886 virtual ExitCode
Entry();
2892 wxThread::ExitCode
MyJoinableThread::Entry()
2894 unsigned long res
= 1;
2895 for ( size_t n
= 1; n
< m_n
; n
++ )
2899 // it's a loooong calculation :-)
2903 return (ExitCode
)res
;
2906 class MyDetachedThread
: public wxThread
2909 MyDetachedThread(size_t n
, char ch
)
2913 m_cancelled
= FALSE
;
2918 // thread execution starts here
2919 virtual ExitCode
Entry();
2922 virtual void OnExit();
2925 size_t m_n
; // number of characters to write
2926 char m_ch
; // character to write
2928 bool m_cancelled
; // FALSE if we exit normally
2931 wxThread::ExitCode
MyDetachedThread::Entry()
2934 wxCriticalSectionLocker
lock(gs_critsect
);
2935 if ( gs_counter
== (size_t)-1 )
2941 for ( size_t n
= 0; n
< m_n
; n
++ )
2943 if ( TestDestroy() )
2953 wxThread::Sleep(100);
2959 void MyDetachedThread::OnExit()
2961 wxLogTrace("thread", "Thread %ld is in OnExit", GetId());
2963 wxCriticalSectionLocker
lock(gs_critsect
);
2964 if ( !--gs_counter
&& !m_cancelled
)
2968 void TestDetachedThreads()
2970 puts("\n*** Testing detached threads ***");
2972 static const size_t nThreads
= 3;
2973 MyDetachedThread
*threads
[nThreads
];
2975 for ( n
= 0; n
< nThreads
; n
++ )
2977 threads
[n
] = new MyDetachedThread(10, 'A' + n
);
2980 threads
[0]->SetPriority(WXTHREAD_MIN_PRIORITY
);
2981 threads
[1]->SetPriority(WXTHREAD_MAX_PRIORITY
);
2983 for ( n
= 0; n
< nThreads
; n
++ )
2988 // wait until all threads terminate
2994 void TestJoinableThreads()
2996 puts("\n*** Testing a joinable thread (a loooong calculation...) ***");
2998 // calc 10! in the background
2999 MyJoinableThread
thread(10);
3002 printf("\nThread terminated with exit code %lu.\n",
3003 (unsigned long)thread
.Wait());
3006 void TestThreadSuspend()
3008 puts("\n*** Testing thread suspend/resume functions ***");
3010 MyDetachedThread
*thread
= new MyDetachedThread(15, 'X');
3014 // this is for this demo only, in a real life program we'd use another
3015 // condition variable which would be signaled from wxThread::Entry() to
3016 // tell us that the thread really started running - but here just wait a
3017 // bit and hope that it will be enough (the problem is, of course, that
3018 // the thread might still not run when we call Pause() which will result
3020 wxThread::Sleep(300);
3022 for ( size_t n
= 0; n
< 3; n
++ )
3026 puts("\nThread suspended");
3029 // don't sleep but resume immediately the first time
3030 wxThread::Sleep(300);
3032 puts("Going to resume the thread");
3037 puts("Waiting until it terminates now");
3039 // wait until the thread terminates
3045 void TestThreadDelete()
3047 // As above, using Sleep() is only for testing here - we must use some
3048 // synchronisation object instead to ensure that the thread is still
3049 // running when we delete it - deleting a detached thread which already
3050 // terminated will lead to a crash!
3052 puts("\n*** Testing thread delete function ***");
3054 MyDetachedThread
*thread0
= new MyDetachedThread(30, 'W');
3058 puts("\nDeleted a thread which didn't start to run yet.");
3060 MyDetachedThread
*thread1
= new MyDetachedThread(30, 'Y');
3064 wxThread::Sleep(300);
3068 puts("\nDeleted a running thread.");
3070 MyDetachedThread
*thread2
= new MyDetachedThread(30, 'Z');
3074 wxThread::Sleep(300);
3080 puts("\nDeleted a sleeping thread.");
3082 MyJoinableThread
thread3(20);
3087 puts("\nDeleted a joinable thread.");
3089 MyJoinableThread
thread4(2);
3092 wxThread::Sleep(300);
3096 puts("\nDeleted a joinable thread which already terminated.");
3101 #endif // TEST_THREADS
3103 // ----------------------------------------------------------------------------
3105 // ----------------------------------------------------------------------------
3109 static void PrintArray(const char* name
, const wxArrayString
& array
)
3111 printf("Dump of the array '%s'\n", name
);
3113 size_t nCount
= array
.GetCount();
3114 for ( size_t n
= 0; n
< nCount
; n
++ )
3116 printf("\t%s[%u] = '%s'\n", name
, n
, array
[n
].c_str());
3120 static void PrintArray(const char* name
, const wxArrayInt
& array
)
3122 printf("Dump of the array '%s'\n", name
);
3124 size_t nCount
= array
.GetCount();
3125 for ( size_t n
= 0; n
< nCount
; n
++ )
3127 printf("\t%s[%u] = %d\n", name
, n
, array
[n
]);
3131 int wxCMPFUNC_CONV
StringLenCompare(const wxString
& first
,
3132 const wxString
& second
)
3134 return first
.length() - second
.length();
3137 int wxCMPFUNC_CONV
IntCompare(int *first
,
3140 return *first
- *second
;
3143 int wxCMPFUNC_CONV
IntRevCompare(int *first
,
3146 return *second
- *first
;
3149 static void TestArrayOfInts()
3151 puts("*** Testing wxArrayInt ***\n");
3162 puts("After sort:");
3166 puts("After reverse sort:");
3167 a
.Sort(IntRevCompare
);
3171 #include "wx/dynarray.h"
3173 WX_DECLARE_OBJARRAY(Bar
, ArrayBars
);
3174 #include "wx/arrimpl.cpp"
3175 WX_DEFINE_OBJARRAY(ArrayBars
);
3177 static void TestArrayOfObjects()
3179 puts("*** Testing wxObjArray ***\n");
3183 Bar
bar("second bar");
3185 printf("Initially: %u objects in the array, %u objects total.\n",
3186 bars
.GetCount(), Bar::GetNumber());
3188 bars
.Add(new Bar("first bar"));
3191 printf("Now: %u objects in the array, %u objects total.\n",
3192 bars
.GetCount(), Bar::GetNumber());
3196 printf("After Empty(): %u objects in the array, %u objects total.\n",
3197 bars
.GetCount(), Bar::GetNumber());
3200 printf("Finally: no more objects in the array, %u objects total.\n",
3204 #endif // TEST_ARRAYS
3206 // ----------------------------------------------------------------------------
3208 // ----------------------------------------------------------------------------
3212 #include "wx/timer.h"
3213 #include "wx/tokenzr.h"
3215 static void TestStringConstruction()
3217 puts("*** Testing wxString constructores ***");
3219 #define TEST_CTOR(args, res) \
3222 printf("wxString%s = %s ", #args, s.c_str()); \
3229 printf("(ERROR: should be %s)\n", res); \
3233 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
3234 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
3235 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
3236 // TEST_CTOR((_T("Hello"), 6), _T("Hello")); -- should give assert failure
3238 static const wxChar
*s
= _T("?really!");
3239 const wxChar
*start
= wxStrchr(s
, _T('r'));
3240 const wxChar
*end
= wxStrchr(s
, _T('!'));
3241 TEST_CTOR((start
, end
), _T("really"));
3246 static void TestString()
3256 for (int i
= 0; i
< 1000000; ++i
)
3260 c
= "! How'ya doin'?";
3263 c
= "Hello world! What's up?";
3268 printf ("TestString elapsed time: %ld\n", sw
.Time());
3271 static void TestPChar()
3279 for (int i
= 0; i
< 1000000; ++i
)
3281 strcpy (a
, "Hello");
3282 strcpy (b
, " world");
3283 strcpy (c
, "! How'ya doin'?");
3286 strcpy (c
, "Hello world! What's up?");
3287 if (strcmp (c
, a
) == 0)
3291 printf ("TestPChar elapsed time: %ld\n", sw
.Time());
3294 static void TestStringSub()
3296 wxString
s("Hello, world!");
3298 puts("*** Testing wxString substring extraction ***");
3300 printf("String = '%s'\n", s
.c_str());
3301 printf("Left(5) = '%s'\n", s
.Left(5).c_str());
3302 printf("Right(6) = '%s'\n", s
.Right(6).c_str());
3303 printf("Mid(3, 5) = '%s'\n", s(3, 5).c_str());
3304 printf("Mid(3) = '%s'\n", s
.Mid(3).c_str());
3305 printf("substr(3, 5) = '%s'\n", s
.substr(3, 5).c_str());
3306 printf("substr(3) = '%s'\n", s
.substr(3).c_str());
3308 static const wxChar
*prefixes
[] =
3312 _T("Hello, world!"),
3313 _T("Hello, world!!!"),
3319 for ( size_t n
= 0; n
< WXSIZEOF(prefixes
); n
++ )
3321 wxString prefix
= prefixes
[n
], rest
;
3322 bool rc
= s
.StartsWith(prefix
, &rest
);
3323 printf("StartsWith('%s') = %s", prefix
.c_str(), rc
? "TRUE" : "FALSE");
3326 printf(" (the rest is '%s')\n", rest
.c_str());
3337 static void TestStringFormat()
3339 puts("*** Testing wxString formatting ***");
3342 s
.Printf("%03d", 18);
3344 printf("Number 18: %s\n", wxString::Format("%03d", 18).c_str());
3345 printf("Number 18: %s\n", s
.c_str());
3350 // returns "not found" for npos, value for all others
3351 static wxString
PosToString(size_t res
)
3353 wxString s
= res
== wxString::npos
? wxString(_T("not found"))
3354 : wxString::Format(_T("%u"), res
);
3358 static void TestStringFind()
3360 puts("*** Testing wxString find() functions ***");
3362 static const wxChar
*strToFind
= _T("ell");
3363 static const struct StringFindTest
3367 result
; // of searching "ell" in str
3370 { _T("Well, hello world"), 0, 1 },
3371 { _T("Well, hello world"), 6, 7 },
3372 { _T("Well, hello world"), 9, wxString::npos
},
3375 for ( size_t n
= 0; n
< WXSIZEOF(findTestData
); n
++ )
3377 const StringFindTest
& ft
= findTestData
[n
];
3378 size_t res
= wxString(ft
.str
).find(strToFind
, ft
.start
);
3380 printf(_T("Index of '%s' in '%s' starting from %u is %s "),
3381 strToFind
, ft
.str
, ft
.start
, PosToString(res
).c_str());
3383 size_t resTrue
= ft
.result
;
3384 if ( res
== resTrue
)
3390 printf(_T("(ERROR: should be %s)\n"),
3391 PosToString(resTrue
).c_str());
3398 static void TestStringTokenizer()
3400 puts("*** Testing wxStringTokenizer ***");
3402 static const wxChar
*modeNames
[] =
3406 _T("return all empty"),
3411 static const struct StringTokenizerTest
3413 const wxChar
*str
; // string to tokenize
3414 const wxChar
*delims
; // delimiters to use
3415 size_t count
; // count of token
3416 wxStringTokenizerMode mode
; // how should we tokenize it
3417 } tokenizerTestData
[] =
3419 { _T(""), _T(" "), 0 },
3420 { _T("Hello, world"), _T(" "), 2 },
3421 { _T("Hello, world "), _T(" "), 2 },
3422 { _T("Hello, world"), _T(","), 2 },
3423 { _T("Hello, world!"), _T(",!"), 2 },
3424 { _T("Hello,, world!"), _T(",!"), 3 },
3425 { _T("Hello, world!"), _T(",!"), 3, wxTOKEN_RET_EMPTY_ALL
},
3426 { _T("username:password:uid:gid:gecos:home:shell"), _T(":"), 7 },
3427 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 4 },
3428 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 6, wxTOKEN_RET_EMPTY
},
3429 { _T("1 \t3\t4 6 "), wxDEFAULT_DELIMITERS
, 9, wxTOKEN_RET_EMPTY_ALL
},
3430 { _T("01/02/99"), _T("/-"), 3 },
3431 { _T("01-02/99"), _T("/-"), 3, wxTOKEN_RET_DELIMS
},
3434 for ( size_t n
= 0; n
< WXSIZEOF(tokenizerTestData
); n
++ )
3436 const StringTokenizerTest
& tt
= tokenizerTestData
[n
];
3437 wxStringTokenizer
tkz(tt
.str
, tt
.delims
, tt
.mode
);
3439 size_t count
= tkz
.CountTokens();
3440 printf(_T("String '%s' has %u tokens delimited by '%s' (mode = %s) "),
3441 MakePrintable(tt
.str
).c_str(),
3443 MakePrintable(tt
.delims
).c_str(),
3444 modeNames
[tkz
.GetMode()]);
3445 if ( count
== tt
.count
)
3451 printf(_T("(ERROR: should be %u)\n"), tt
.count
);
3456 // if we emulate strtok(), check that we do it correctly
3457 wxChar
*buf
, *s
= NULL
, *last
;
3459 if ( tkz
.GetMode() == wxTOKEN_STRTOK
)
3461 buf
= new wxChar
[wxStrlen(tt
.str
) + 1];
3462 wxStrcpy(buf
, tt
.str
);
3464 s
= wxStrtok(buf
, tt
.delims
, &last
);
3471 // now show the tokens themselves
3473 while ( tkz
.HasMoreTokens() )
3475 wxString token
= tkz
.GetNextToken();
3477 printf(_T("\ttoken %u: '%s'"),
3479 MakePrintable(token
).c_str());
3489 printf(" (ERROR: should be %s)\n", s
);
3492 s
= wxStrtok(NULL
, tt
.delims
, &last
);
3496 // nothing to compare with
3501 if ( count2
!= count
)
3503 puts(_T("\tERROR: token count mismatch"));
3512 static void TestStringReplace()
3514 puts("*** Testing wxString::replace ***");
3516 static const struct StringReplaceTestData
3518 const wxChar
*original
; // original test string
3519 size_t start
, len
; // the part to replace
3520 const wxChar
*replacement
; // the replacement string
3521 const wxChar
*result
; // and the expected result
3522 } stringReplaceTestData
[] =
3524 { _T("012-AWORD-XYZ"), 4, 5, _T("BWORD"), _T("012-BWORD-XYZ") },
3525 { _T("increase"), 0, 2, _T("de"), _T("decrease") },
3526 { _T("wxWindow"), 8, 0, _T("s"), _T("wxWindows") },
3527 { _T("foobar"), 3, 0, _T("-"), _T("foo-bar") },
3528 { _T("barfoo"), 0, 6, _T("foobar"), _T("foobar") },
3531 for ( size_t n
= 0; n
< WXSIZEOF(stringReplaceTestData
); n
++ )
3533 const StringReplaceTestData data
= stringReplaceTestData
[n
];
3535 wxString original
= data
.original
;
3536 original
.replace(data
.start
, data
.len
, data
.replacement
);
3538 wxPrintf(_T("wxString(\"%s\").replace(%u, %u, %s) = %s "),
3539 data
.original
, data
.start
, data
.len
, data
.replacement
,
3542 if ( original
== data
.result
)
3548 wxPrintf(_T("(ERROR: should be '%s')\n"), data
.result
);
3555 #endif // TEST_STRINGS
3557 // ----------------------------------------------------------------------------
3559 // ----------------------------------------------------------------------------
3561 int main(int argc
, char **argv
)
3563 if ( !wxInitialize() )
3565 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
3569 puts("Sleeping for 3 seconds... z-z-z-z-z...");
3571 #endif // TEST_USLEEP
3574 static const wxCmdLineEntryDesc cmdLineDesc
[] =
3576 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
3577 { wxCMD_LINE_SWITCH
, "q", "quiet", "be quiet" },
3579 { wxCMD_LINE_OPTION
, "o", "output", "output file" },
3580 { wxCMD_LINE_OPTION
, "i", "input", "input dir" },
3581 { wxCMD_LINE_OPTION
, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER
},
3582 { wxCMD_LINE_OPTION
, "d", "date", "output file date", wxCMD_LINE_VAL_DATE
},
3584 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file",
3585 wxCMD_LINE_VAL_STRING
, wxCMD_LINE_PARAM_MULTIPLE
},
3590 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
3592 parser
.AddOption("project_name", "", "full path to project file",
3593 wxCMD_LINE_VAL_STRING
,
3594 wxCMD_LINE_OPTION_MANDATORY
| wxCMD_LINE_NEEDS_SEPARATOR
);
3596 switch ( parser
.Parse() )
3599 wxLogMessage("Help was given, terminating.");
3603 ShowCmdLine(parser
);
3607 wxLogMessage("Syntax error detected, aborting.");
3610 #endif // TEST_CMDLINE
3621 TestStringConstruction();
3624 TestStringTokenizer();
3625 TestStringReplace();
3627 #endif // TEST_STRINGS
3640 puts("*** Initially:");
3642 PrintArray("a1", a1
);
3644 wxArrayString
a2(a1
);
3645 PrintArray("a2", a2
);
3647 wxSortedArrayString
a3(a1
);
3648 PrintArray("a3", a3
);
3650 puts("*** After deleting a string from a1");
3653 PrintArray("a1", a1
);
3654 PrintArray("a2", a2
);
3655 PrintArray("a3", a3
);
3657 puts("*** After reassigning a1 to a2 and a3");
3659 PrintArray("a2", a2
);
3660 PrintArray("a3", a3
);
3662 puts("*** After sorting a1");
3664 PrintArray("a1", a1
);
3666 puts("*** After sorting a1 in reverse order");
3668 PrintArray("a1", a1
);
3670 puts("*** After sorting a1 by the string length");
3671 a1
.Sort(StringLenCompare
);
3672 PrintArray("a1", a1
);
3674 TestArrayOfObjects();
3677 #endif // TEST_ARRAYS
3683 #ifdef TEST_DLLLOADER
3685 #endif // TEST_DLLLOADER
3689 #endif // TEST_EXECUTE
3691 #ifdef TEST_FILECONF
3693 #endif // TEST_FILECONF
3701 for ( size_t n
= 0; n
< 8000; n
++ )
3703 s
<< (char)('A' + (n
% 26));
3707 msg
.Printf("A very very long message: '%s', the end!\n", s
.c_str());
3709 // this one shouldn't be truncated
3712 // but this one will because log functions use fixed size buffer
3713 // (note that it doesn't need '\n' at the end neither - will be added
3715 wxLogMessage("A very very long message 2: '%s', the end!", s
.c_str());
3725 int nCPUs
= wxThread::GetCPUCount();
3726 printf("This system has %d CPUs\n", nCPUs
);
3728 wxThread::SetConcurrency(nCPUs
);
3730 if ( argc
> 1 && argv
[1][0] == 't' )
3731 wxLog::AddTraceMask("thread");
3734 TestDetachedThreads();
3736 TestJoinableThreads();
3738 TestThreadSuspend();
3742 #endif // TEST_THREADS
3744 #ifdef TEST_LONGLONG
3745 // seed pseudo random generator
3746 srand((unsigned)time(NULL
));
3754 TestMultiplication();
3757 TestLongLongConversion();
3758 TestBitOperations();
3760 TestLongLongComparison();
3761 #endif // TEST_LONGLONG
3768 wxLog::AddTraceMask(_T("mime"));
3775 #ifdef TEST_INFO_FUNCTIONS
3778 #endif // TEST_INFO_FUNCTIONS
3780 #ifdef TEST_REGISTRY
3783 TestRegistryAssociation();
3784 #endif // TEST_REGISTRY
3793 TestProtocolFtpUpload();
3794 #endif // TEST_SOCKETS
3798 #endif // TEST_STREAMS
3802 #endif // TEST_TIMER
3804 #ifdef TEST_DATETIME
3817 TestTimeArithmetics();
3826 #endif // TEST_DATETIME
3832 #endif // TEST_VCARD
3836 #endif // TEST_WCHAR
3839 TestZipStreamRead();
3844 TestZlibStreamWrite();
3845 TestZlibStreamRead();