X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e0777dabb459e69b871c43d57a1bec2b37c77c3..94a77ff7aff70d0a44ae62ca3173151ad2ce6e44:/samples/console/console.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 8f932dcdd7..668093ddbe 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -19,10 +19,6 @@ #include "wx/defs.h" -#if wxUSE_GUI - #error "This sample can't be compiled in GUI mode." -#endif // wxUSE_GUI - #include #include "wx/string.h" @@ -48,9 +44,13 @@ tests individually in the "#else" branch below. */ -// what to test (in alphabetic order)? uncomment the line below to do all tests -//#define TEST_ALL -#ifdef TEST_ALL +// what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single +// test, define it to 1 to do all tests. +#define TEST_ALL 0 + + +#if TEST_ALL + #define TEST_ARRAYS #define TEST_CHARSET #define TEST_CMDLINE @@ -63,9 +63,10 @@ #define TEST_FILECONF #define TEST_FILENAME #define TEST_FILETIME - #define TEST_FTP + // #define TEST_FTP --FIXME! (RN) #define TEST_HASH #define TEST_HASHMAP + #define TEST_HASHSET #define TEST_INFO_FUNCTIONS #define TEST_LIST #define TEST_LOCALE @@ -78,8 +79,9 @@ #define TEST_REGCONF #define TEST_REGEX #define TEST_REGISTRY + #define TEST_SCOPEGUARD #define TEST_SNGLINST - #define TEST_SOCKETS +// #define TEST_SOCKETS --FIXME! (RN) #define TEST_STREAMS #define TEST_STRINGS #define TEST_TEXTSTREAM @@ -87,26 +89,25 @@ #define TEST_TIMER #define TEST_UNICODE // #define TEST_VCARD -- don't enable this (VZ) - #define TEST_VOLUME +// #define TEST_VOLUME --FIXME! (RN) #define TEST_WCHAR #define TEST_ZIP #define TEST_ZLIB + #define TEST_GZIP - #undef TEST_ALL - static const bool TEST_ALL = true; -#else - #define TEST_FILECONF +#else // #if TEST_ALL + + #define TEST_FILENAME - static const bool TEST_ALL = false; #endif // some tests are interactive, define this to run them #ifdef TEST_INTERACTIVE #undef TEST_INTERACTIVE - static const bool TEST_INTERACTIVE = true; + #define TEST_INTERACTIVE 1 #else - static const bool TEST_INTERACTIVE = false; + #define TEST_INTERACTIVE 0 #endif // ---------------------------------------------------------------------------- @@ -304,7 +305,7 @@ static void TestDirEnumHelper(wxDir& dir, cont = dir.GetNext(&filename); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestDirEnum() @@ -332,7 +333,7 @@ static void TestDirEnum() TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT); wxPuts(_T("Enumerating object files in current directory:")); - TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o*"); + TestDirEnumHelper(dir, wxDIR_DEFAULT, _T("*.o*")); wxPuts(_T("Enumerating directories in current directory:")); TestDirEnumHelper(dir, wxDIR_DIRS); @@ -358,14 +359,14 @@ static void TestDirEnum() TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN); wxPuts(_T("Enumerating files in non existing directory:")); - wxDir dirNo("nosuchdir"); + wxDir dirNo(_T("nosuchdir")); TestDirEnumHelper(dirNo); } class DirPrintTraverser : public wxDirTraverser { public: - virtual wxDirTraverseResult OnFile(const wxString& filename) + virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) { return wxDIR_CONTINUE; } @@ -409,7 +410,7 @@ static void TestDirTraverse() wxPuts(_T("Now enumerating directories:")); wxDir dir(TESTDIR); DirPrintTraverser traverser; - dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN); + dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN); } static void TestDirExists() @@ -563,14 +564,14 @@ static void TestExecute() wxPrintf(_T("Testing wxShell: ")); fflush(stdout); - if ( wxShell(SHELL_COMMAND) ) + if ( wxShell(_T(SHELL_COMMAND)) ) wxPuts(_T("Ok.")); else wxPuts(_T("ERROR.")); wxPrintf(_T("Testing wxExecute: ")); fflush(stdout); - if ( wxExecute(COMMAND, true /* sync */) == 0 ) + if ( wxExecute(_T(COMMAND), true /* sync */) == 0 ) wxPuts(_T("Ok.")); else wxPuts(_T("ERROR.")); @@ -586,7 +587,7 @@ static void TestExecute() wxPrintf(_T("Testing wxExecute with redirection:\n")); wxArrayString output; - if ( wxExecute(REDIRECT_COMMAND, output) != 0 ) + if ( wxExecute(_T(REDIRECT_COMMAND), output) != 0 ) { wxPuts(_T("ERROR.")); } @@ -649,7 +650,7 @@ static void TestFileRead() wxPrintf(_T("ERROR: can't open test file.\n")); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestTextFileRead() @@ -685,7 +686,7 @@ static void TestTextFileRead() wxPrintf(_T("ERROR: can't open '%s'\n"), file.GetName()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestFileCopy() @@ -700,8 +701,8 @@ static void TestFileCopy() } else { - wxFFile f1(filename1, "rb"), - f2(filename2, "rb"); + wxFFile f1(filename1, _T("rb")), + f2(filename2, _T("rb")); if ( !f1.IsOpened() || !f2.IsOpened() ) { @@ -734,7 +735,7 @@ static void TestFileCopy() wxPuts(_T("ERROR: failed to remove the file")); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } #endif // TEST_FILE @@ -816,8 +817,11 @@ static void TestFileConfRead() #include "wx/filename.h" -static void DumpFileName(const wxFileName& fn) +#if 0 +static void DumpFileName(const wxChar *desc, const wxFileName& fn) { + wxPuts(desc); + wxString full = fn.GetFullPath(); wxString vol, path, name, ext; @@ -846,6 +850,7 @@ static void DumpFileName(const wxFileName& fn) wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str()); } } +#endif static struct FileNameInfo { @@ -916,7 +921,7 @@ static void TestFileNameConstruction() isAbsolute ? "absolute" : "relative", isAbsolute == fni.isAbsolute ? "ok" : "ERROR"); - if ( !fn.Normalize(wxPATH_NORM_ALL, _T(""), fni.format) ) + if ( !fn.Normalize(wxPATH_NORM_ALL, wxEmptyString, fni.format) ) { wxPuts(_T("ERROR (couldn't be normalized)")); } @@ -926,7 +931,7 @@ static void TestFileNameConstruction() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestFileNameSplit() @@ -953,7 +958,7 @@ static void TestFileNameSplit() if ( ext != fni.ext ) wxPrintf(_T(" (ERROR: ext = '%s')"), fni.ext); - wxPuts(_T("")); + wxPuts(wxEmptyString); } } @@ -1010,11 +1015,11 @@ static void TestFileNameMakeRelative() switch ( fni.format ) { case wxPATH_UNIX: - base = "/usr/bin/"; + base = _T("/usr/bin/"); break; case wxPATH_DOS: - base = "c:\\"; + base = _T("c:\\"); break; case wxPATH_MAC: @@ -1024,7 +1029,7 @@ static void TestFileNameMakeRelative() case wxPATH_NATIVE: // make gcc happy default: - wxFAIL_MSG( "unexpected path format" ); + wxFAIL_MSG( _T("unexpected path format") ); } wxPrintf(_T("'%s' relative to '%s': "), @@ -1056,7 +1061,12 @@ static void TestFileNameMakeAbsolute() wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); +} + +static void TestFileNameDirManip() +{ + // TODO: test AppendDir(), RemoveDir(), ... } static void TestFileNameComparison() @@ -1105,6 +1115,7 @@ static void TestFileGetTimes() } } +#if 0 static void TestFileSetTimes() { wxFileName fn(_T("testdata.fc")); @@ -1114,6 +1125,7 @@ static void TestFileSetTimes() wxPrintf(_T("ERROR: Touch() failed.\n")); } } +#endif #endif // TEST_FILETIME @@ -1144,9 +1156,139 @@ WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos); WX_DEFINE_LIST(wxListFoos); +#include "wx/timer.h" + static void TestHash() { wxPuts(_T("*** Testing wxHashTable ***\n")); + const int COUNT = 100; + + wxStopWatch sw; + + sw.Start(); + + { + wxHashTable hash(wxKEY_INTEGER, 10), hash2(wxKEY_STRING); + wxObject o; + int i; + + for ( i = 0; i < COUNT; ++i ) + hash.Put(i, &o + i); + + hash.BeginFind(); + wxHashTable::compatibility_iterator it = hash.Next(); + i = 0; + + while (it) + { + ++i; + it = hash.Next(); + } + + if (i != COUNT) + wxPuts(_T("Error in wxHashTable::compatibility_iterator\n")); + + for ( i = 99; i >= 0; --i ) + if( hash.Get(i) != &o + i ) + wxPuts(_T("Error in wxHashTable::Get/Put\n")); + + for ( i = 0; i < COUNT; ++i ) + hash.Put(i, &o + i + 20); + + for ( i = 99; i >= 0; --i ) + if( hash.Get(i) != &o + i) + wxPuts(_T("Error (2) in wxHashTable::Get/Put\n")); + + for ( i = 0; i < COUNT/2; ++i ) + if( hash.Delete(i) != &o + i) + wxPuts(_T("Error in wxHashTable::Delete\n")); + + for ( i = COUNT/2; i < COUNT; ++i ) + if( hash.Get(i) != &o + i) + wxPuts(_T("Error (3) in wxHashTable::Get/Put\n")); + + for ( i = 0; i < COUNT/2; ++i ) + if( hash.Get(i) != &o + i + 20) + wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n")); + + for ( i = 0; i < COUNT/2; ++i ) + if( hash.Delete(i) != &o + i + 20) + wxPuts(_T("Error (2) in wxHashTable::Delete\n")); + + for ( i = 0; i < COUNT/2; ++i ) + if( hash.Get(i) != NULL) + wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n")); + + hash2.Put(_T("foo"), &o + 1); + hash2.Put(_T("bar"), &o + 2); + hash2.Put(_T("baz"), &o + 3); + + if (hash2.Get(_T("moo")) != NULL) + wxPuts(_T("Error in wxHashTable::Get\n")); + + if (hash2.Get(_T("bar")) != &o + 2) + wxPuts(_T("Error in wxHashTable::Get/Put\n")); + + hash2.Put(_T("bar"), &o + 0); + + if (hash2.Get(_T("bar")) != &o + 2) + wxPuts(_T("Error (2) in wxHashTable::Get/Put\n")); + } + + // and now some corner-case testing; 3 and 13 hash to the same bucket + { + wxHashTable hash(wxKEY_INTEGER, 10); + wxObject dummy; + + hash.Put(3, &dummy); + hash.Delete(3); + + if (hash.Get(3) != NULL) + wxPuts(_T("Corner case 1 failure\n")); + + hash.Put(3, &dummy); + hash.Put(13, &dummy); + hash.Delete(3); + + if (hash.Get(3) != NULL) + wxPuts(_T("Corner case 2 failure\n")); + + hash.Delete(13); + + if (hash.Get(13) != NULL) + wxPuts(_T("Corner case 3 failure\n")); + + hash.Put(3, &dummy); + hash.Put(13, &dummy); + hash.Delete(13); + + if (hash.Get(13) != NULL) + wxPuts(_T("Corner case 4 failure\n")); + + hash.Delete(3); + + if (hash.Get(3) != NULL) + wxPuts(_T("Corner case 5 failure\n")); + } + + { + wxHashTable hash(wxKEY_INTEGER, 10); + wxObject dummy; + + hash.Put(3, 7, &dummy + 7); + hash.Put(4, 8, &dummy + 8); + + if (hash.Get(7) != NULL) wxPuts(_T("Key/Hash 1 failure\n")); + if (hash.Get(3, 7) != &dummy + 7) wxPuts(_T("Key/Hash 2 failure\n")); + if (hash.Get(4) != NULL) wxPuts(_T("Key/Hash 3 failure\n")); + if (hash.Get(3) != NULL) wxPuts(_T("Key/Hash 4 failure\n")); + if (hash.Get(8) != NULL) wxPuts(_T("Key/Hash 5 failure\n")); + if (hash.Get(8, 4) != NULL) wxPuts(_T("Key/Hash 6 failure\n")); + + if (hash.Delete(7) != NULL) wxPuts(_T("Key/Hash 7 failure\n")); + if (hash.Delete(3) != NULL) wxPuts(_T("Key/Hash 8 failure\n")); + if (hash.Delete(3, 7) != &dummy + 7) wxPuts(_T("Key/Hash 8 failure\n")); + } { wxHashFoos hash; @@ -1196,9 +1338,20 @@ static void TestHash() { wxPuts(_T("ok (not found)")); } + + Foo* foo = hash.Delete(0); + + wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count); + + delete foo; + + wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count); } wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count); + wxPuts(_T("*** Testing wxHashTable finished ***\n")); + + wxPrintf(_T("Time: %ld\n"), sw.Time()); } #endif // TEST_HASH @@ -1349,6 +1502,100 @@ static void TestHashMap() #endif // TEST_HASHMAP +// ---------------------------------------------------------------------------- +// wxHashSet +// ---------------------------------------------------------------------------- + +#ifdef TEST_HASHSET + +#include "wx/hashset.h" + +// test compilation of basic map types +WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet ); +WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet ); +WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual, + myUnsignedHashSet ); +WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual, + myTestHashSet1 ); +WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, + myTestHashSet2 ); +WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual, + myTestHashSet3 ); +WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual, + myTestHashSet4 ); +WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, + myTestHashSet5 ); + +struct MyStruct +{ + int* ptr; + wxString str; +}; + +class MyHash +{ +public: + unsigned long operator()(const MyStruct& s) const + { return m_dummy(s.ptr); } + MyHash& operator=(const MyHash&) { return *this; } +private: + wxPointerHash m_dummy; +}; + +class MyEqual +{ +public: + bool operator()(const MyStruct& s1, const MyStruct& s2) const + { return s1.ptr == s2.ptr; } + MyEqual& operator=(const MyEqual&) { return *this; } +}; + +WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet ); + +typedef myTestHashSet5 wxStringHashSet; + +static void TestHashSet() +{ + wxPrintf(_T("*** Testing wxHashSet ***\n")); + + wxStringHashSet set1; + + set1.insert( _T("abc") ); + set1.insert( _T("bbc") ); + set1.insert( _T("cbc") ); + set1.insert( _T("abc") ); + + if( set1.size() != 3 ) + wxPrintf(_T("*** ERROR IN INSERT ***\n")); + + mySet set2; + int dummy; + MyStruct tmp; + + tmp.ptr = &dummy; tmp.str = _T("ABC"); + set2.insert( tmp ); + tmp.ptr = &dummy + 1; + set2.insert( tmp ); + tmp.ptr = &dummy; tmp.str = _T("CDE"); + set2.insert( tmp ); + + if( set2.size() != 2 ) + wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n")); + + mySet::iterator it = set2.find( tmp ); + + if( it == set2.end() ) + wxPrintf(_T("*** ERROR IN FIND - 1 ***\n")); + if( it->ptr != &dummy ) + wxPrintf(_T("*** ERROR IN FIND - 2 ***\n")); + if( it->str != _T("ABC") ) + wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n")); + + wxPrintf(_T("*** Finished testing wxHashSet ***\n")); +} + +#endif // TEST_HASHSET + // ---------------------------------------------------------------------------- // wxList // ---------------------------------------------------------------------------- @@ -1361,6 +1608,104 @@ WX_DECLARE_LIST(Bar, wxListBars); #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxListBars); +WX_DECLARE_LIST(int, wxListInt); +WX_DEFINE_LIST(wxListInt); + +static void TestList() +{ + wxPuts(_T("*** Testing wxList operations ***\n")); + { + wxListInt list1; + int dummy[5]; + int i; + + for ( i = 0; i < 5; ++i ) + list1.Append(dummy + i); + + if ( list1.GetCount() != 5 ) + wxPuts(_T("Wrong number of items in list\n")); + + if ( list1.Item(3)->GetData() != dummy + 3 ) + wxPuts(_T("Error in Item()\n")); + + if ( !list1.Find(dummy + 4) ) + wxPuts(_T("Error in Find()\n")); + + wxListInt::compatibility_iterator node = list1.GetFirst(); + i = 0; + + while (node) + { + if ( node->GetData() != dummy + i ) + wxPuts(_T("Error in compatibility_iterator\n")); + node = node->GetNext(); + ++i; + } + + if ( size_t(i) != list1.GetCount() ) + wxPuts(_T("Error in compatibility_iterator\n")); + + list1.Insert(dummy + 0); + list1.Insert(1, dummy + 1); + list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2); + + node = list1.GetFirst(); + i = 0; + + while (i < 3) + { + int* t = node->GetData(); + if ( t != dummy + i ) + wxPuts(_T("Error in Insert\n")); + node = node->GetNext(); + ++i; + } + } + + wxPuts(_T("*** Testing wxList operations finished ***\n")); + + wxPuts(_T("*** Testing std::list operations ***\n")); + + { + wxListInt list1; + wxListInt::iterator it, en; + wxListInt::reverse_iterator rit, ren; + int i; + for ( i = 0; i < 5; ++i ) + list1.push_back(i + &i); + + for ( it = list1.begin(), en = list1.end(), i = 0; + it != en; ++it, ++i ) + if ( *it != i + &i ) + wxPuts(_T("Error in iterator\n")); + + for ( rit = list1.rbegin(), ren = list1.rend(), i = 4; + rit != ren; ++rit, --i ) + if ( *rit != i + &i ) + wxPuts(_T("Error in reverse_iterator\n")); + + if ( *list1.rbegin() != *--list1.end() || + *list1.begin() != *--list1.rend() ) + wxPuts(_T("Error in iterator/reverse_iterator\n")); + if ( *list1.begin() != *--++list1.begin() || + *list1.rbegin() != *--++list1.rbegin() ) + wxPuts(_T("Error in iterator/reverse_iterator\n")); + + if ( list1.front() != &i || list1.back() != &i + 4 ) + wxPuts(_T("Error in front()/back()\n")); + + list1.erase(list1.begin()); + list1.erase(--list1.end()); + + for ( it = list1.begin(), en = list1.end(), i = 1; + it != en; ++it, ++i ) + if ( *it != i + &i ) + wxPuts(_T("Error in erase()\n")); + } + + wxPuts(_T("*** Testing std::list operations finished ***\n")); +} + static void TestListCtor() { wxPuts(_T("*** Testing wxList construction ***\n")); @@ -1379,7 +1724,11 @@ static void TestListCtor() wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"), list1.GetCount(), list2.GetCount(), Bar::GetNumber()); +#if !wxUSE_STL list1.DeleteContents(true); +#else + WX_CLEAR_LIST(wxListBars, list1); +#endif } wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber()); @@ -1731,7 +2080,7 @@ static void TestMimeEnum() mimetypes[n].c_str(), desc.c_str(), extsAll.c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestMimeOverride() @@ -1757,7 +2106,7 @@ static void TestMimeOverride() wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), mimetypes); - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestMimeFilename() @@ -1789,7 +2138,7 @@ static void TestMimeFilename() wxString cmd; if ( !ft->GetOpenCommand(&cmd, - wxFileType::MessageParameters(fname, _T(""))) ) + wxFileType::MessageParameters(fname, wxEmptyString)) ) cmd = _T(""); else cmd = wxString(_T('"')) + cmd + _T('"'); @@ -1801,7 +2150,7 @@ static void TestMimeFilename() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestMimeAssociate() @@ -1829,7 +2178,7 @@ static void TestMimeAssociate() delete ft; } - wxPuts(_T("")); + wxPuts(wxEmptyString); } #endif // TEST_MIME @@ -1885,7 +2234,7 @@ static void TestOsInfo() wxPrintf(_T("Host name is %s (%s).\n"), wxGetHostName().c_str(), wxGetFullHostName().c_str()); - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestUserInfo() @@ -1897,7 +2246,7 @@ static void TestUserInfo() wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str()); wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str()); - wxPuts(_T("")); + wxPuts(wxEmptyString); } #endif // TEST_INFO_FUNCTIONS @@ -1935,6 +2284,7 @@ inline bool operator==(const wxLongLongNative& a, const wxLongLongWx& b) { return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); } #endif // wxUSE_LONGLONG_WX +#if 0 static void TestSpeed() { static const long max = 100000000; @@ -1948,6 +2298,7 @@ static void TestSpeed() { l += n; } + wxUnusedVar(l); wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw.Time()); } @@ -1961,6 +2312,7 @@ static void TestSpeed() { l += n; } + wxUnusedVar(l); wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw.Time()); } @@ -1978,21 +2330,22 @@ static void TestSpeed() wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw.Time()); } } +#endif static void TestLongLongConversion() { wxPuts(_T("*** Testing wxLongLong conversions ***\n")); - wxLongLong a; size_t nTested = 0; for ( size_t n = 0; n < 100000; n++ ) { - a = RAND_LL(); - #if wxUSE_LONGLONG_NATIVE + wxLongLong a = RAND_LL(); + wxLongLongNative b(a.GetHi(), a.GetLo()); - wxASSERT_MSG( a == b, "conversions failure" ); + if( a != b) + wxPuts( _T("conversions failure") ); #else wxPuts(_T("Can't do it without native long long type, test skipped.")); @@ -2001,7 +2354,7 @@ static void TestLongLongConversion() if ( !(nTested % 1000) ) { - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -2015,18 +2368,18 @@ static void TestMultiplication() { wxPuts(_T("*** Testing wxLongLong multiplication ***\n")); - wxLongLong a, b; size_t nTested = 0; for ( size_t n = 0; n < 100000; n++ ) { - a = RAND_LL(); - b = RAND_LL(); - #if wxUSE_LONGLONG_NATIVE + wxLongLong a = RAND_LL(); + wxLongLong b = RAND_LL(); + wxLongLongNative aa(a.GetHi(), a.GetLo()); wxLongLongNative bb(b.GetHi(), b.GetLo()); - wxASSERT_MSG( a*b == aa*bb, "multiplication failure" ); + if( a*b != aa*bb ) + wxPuts( _T("multiplication failure") ); #else // !wxUSE_LONGLONG_NATIVE wxPuts(_T("Can't do it without native long long type, test skipped.")); @@ -2035,7 +2388,7 @@ static void TestMultiplication() if ( !(nTested % 1000) ) { - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -2073,7 +2426,9 @@ static void TestDivision() wxLongLongNative m(ll.GetHi(), ll.GetLo()); wxLongLongNative p = m / l, s = m % l; - wxASSERT_MSG( q == p && r == s, "division failure" ); + + if(q != p || r != s) + wxPuts( _T("division failure") ); #else // !wxUSE_LONGLONG_NATIVE // verify the result wxASSERT_MSG( ll == q*l + r, "division failure" ); @@ -2081,7 +2436,7 @@ static void TestDivision() if ( !(nTested % 1000) ) { - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -2106,14 +2461,14 @@ static void TestAddition() #if wxUSE_LONGLONG_NATIVE wxASSERT_MSG( c == wxLongLongNative(a.GetHi(), a.GetLo()) + wxLongLongNative(b.GetHi(), b.GetLo()), - "addition failure" ); + _T("addition failure") ); #else // !wxUSE_LONGLONG_NATIVE wxASSERT_MSG( c - b == a, "addition failure" ); #endif // wxUSE_LONGLONG_NATIVE if ( !(nTested % 1000) ) { - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -2145,7 +2500,7 @@ static void TestBitOperations() if ( !(nTested % 1000) ) { - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -2217,8 +2572,12 @@ static void TestLongLongPrintf() wxPuts(_T("*** Testing wxLongLong printing ***\n")); #ifdef wxLongLongFmtSpec +#ifndef __MINGW32__ wxLongLong ll = wxLL(0x1234567890abcdef); wxString s = wxString::Format(_T("%") wxLongLongFmtSpec _T("x"), ll); +#else + wxString s = _T("MinGW compiler does not allow wxLongLong in '...'"); +#endif wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"), s.c_str(), s == _T("1234567890abcdef") ? _T("ok") : _T("ERROR")); #else // !wxLongLongFmtSpec @@ -2310,7 +2669,7 @@ static void TestRegExCompile() wxPrintf(_T("'%s' is %sa valid RE (%s)\n"), data.pattern, - ok ? _T("") : _T("not "), + ok ? wxEmptyString : _T("not "), ok == data.correct ? _T("ok") : _T("ERROR")); } } @@ -2413,7 +2772,7 @@ static void TestRegExReplacement() wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("), data.text, data.repl, - nRepl, nRepl == 1 ? _T("") : _T("es"), + nRepl, nRepl == 1 ? wxEmptyString : _T("es"), text.c_str()); if ( text == data.result && nRepl == data.count ) { @@ -2581,6 +2940,8 @@ fmtst2chk (const wxChar *fmt) * This exercises the output formatting code. */ +wxChar *PointerNull = NULL; + static void fp_test (void) { @@ -2622,8 +2983,8 @@ fp_test (void) } } } - wxPrintf(_T("%10s\n"), (wxChar *) NULL); - wxPrintf(_T("%-10s\n"), (wxChar *) NULL); + wxPrintf(_T("%10s\n"), PointerNull); + wxPrintf(_T("%-10s\n"), PointerNull); } static void TestPrintf() @@ -2632,6 +2993,7 @@ static void TestPrintf() static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \ I am ready for my first lesson today."); int result = 0; + wxString test_format; fmtchk(_T("%.4x")); fmtchk(_T("%04x")); @@ -2645,7 +3007,8 @@ I am ready for my first lesson today."); fmtst2chk(_T("%*.*x")); fmtst2chk(_T("%0*.*x")); - wxPrintf(_T("bad format:\t\"%b\"\n")); + wxString bad_format = _T("bad format:\t\"%b\"\n"); + wxPrintf(bad_format.c_str()); wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL); wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345); @@ -2655,15 +3018,18 @@ I am ready for my first lesson today."); wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L); wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L); wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L); - wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456); + test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n"); + wxPrintf(test_format.c_str(), -123456); wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L); wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); - wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr); - wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr); + test_format = _T("zero-padded string:\t\"%010s\"\n"); + wxPrintf(test_format.c_str(), shortstr); + test_format = _T("left-adjusted Z string:\t\"%-010s\"\n"); + wxPrintf(test_format.c_str(), shortstr); wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr); wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr); - wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar *)NULL); + wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull); wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr); wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34); @@ -2696,7 +3062,11 @@ I am ready for my first lesson today."); fflush (stdout); } +#ifndef __WATCOMC__ + // Open Watcom cause compiler error here + // Error! E173: col(24) floating-point constant too small to represent wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324); +#endif #define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n") wxPrintf (FORMAT, 0.0, 0.0, 0.0); @@ -2754,14 +3124,18 @@ I am ready for my first lesson today."); wxChar buf[200]; wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000)); + #if 0 + // for some reason below line fails under Borland wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf); + #endif if (wxStrcmp (buf, _T("40000000000")) != 0) { result = 1; wxPuts (_T("\tFAILED")); } - wxPuts (_T("")); + wxUnusedVar(result); + wxPuts (wxEmptyString); } #endif // wxLongLong_t @@ -2824,6 +3198,7 @@ rfg2 (void) { int prec; wxChar buf[100]; + wxString test_format; prec = 0; wxSprintf (buf, _T("%.*g"), prec, 3.3); @@ -2838,19 +3213,23 @@ rfg2 (void) if (wxStrcmp (buf, _T(" 3")) != 0) wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3")); prec = 3; - wxSprintf (buf, _T("%04.*o"), prec, 33); + test_format = _T("%04.*o"); + wxSprintf (buf, test_format.c_str(), prec, 33); if (wxStrcmp (buf, _T(" 041")) != 0) wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041")); prec = 7; - wxSprintf (buf, _T("%09.*u"), prec, 33); + test_format = _T("%09.*u"); + wxSprintf (buf, test_format.c_str(), prec, 33); if (wxStrcmp (buf, _T(" 0000033")) != 0) wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033")); prec = 3; - wxSprintf (buf, _T("%04.*x"), prec, 33); + test_format = _T("%04.*x"); + wxSprintf (buf, test_format.c_str(), prec, 33); if (wxStrcmp (buf, _T(" 021")) != 0) wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); prec = 3; - wxSprintf (buf, _T("%04.*X"), prec, 33); + test_format = _T("%04.*X"); + wxSprintf (buf, test_format.c_str(), prec, 33); if (wxStrcmp (buf, _T(" 021")) != 0) wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); } @@ -2872,10 +3251,31 @@ rfg2 (void) #include "wx/confbase.h" #include "wx/msw/regconf.h" +#if 0 static void TestRegConfWrite() { - wxRegConfig regconf(_T("console"), _T("wxwindows")); - regconf.Write(_T("Hello"), wxString(_T("world"))); + wxConfig *config = new wxConfig(_T("myapp")); + config->SetPath(_T("/group1")); + config->Write(_T("entry1"), _T("foo")); + config->SetPath(_T("/group2")); + config->Write(_T("entry1"), _T("bar")); +} +#endif + +static void TestRegConfRead() +{ + wxConfig *config = new wxConfig(_T("myapp")); + + wxString str; + long dummy; + config->SetPath(_T("/")); + wxPuts(_T("Enumerating / subgroups:")); + bool bCont = config->GetFirstGroup(str, dummy); + while(bCont) + { + wxPuts(str); + bCont = config->GetNextGroup(str, dummy); + } } #endif // TEST_REGCONF @@ -2944,7 +3344,7 @@ static void TestRegistryRead() wxPrintf(_T(" (raw value '%s')"), val.c_str()); } - putchar('\n'); + wxPutchar('\n'); cont = key.GetNextValue(value, dummy); } @@ -2960,31 +3360,67 @@ static void TestRegistryAssociation() wxRegKey key; - key.SetName("HKEY_CLASSES_ROOT\\.ddf" ); + key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); key.Create(); - key = "ddxf_auto_file" ; - key.SetName("HKEY_CLASSES_ROOT\\.flo" ); + key = _T("ddxf_auto_file") ; + key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); key.Create(); - key = "ddxf_auto_file" ; - key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"); + key = _T("ddxf_auto_file") ; + key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); key.Create(); - key = "program,0" ; - key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"); + key = _T("program,0") ; + key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); key.Create(); - key = "program \"%1\"" ; + key = _T("program \"%1\"") ; - key.SetName("HKEY_CLASSES_ROOT\\.ddf" ); + key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") ); key.DeleteSelf(); - key.SetName("HKEY_CLASSES_ROOT\\.flo" ); + key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") ); key.DeleteSelf(); - key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"); + key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon")); key.DeleteSelf(); - key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"); + key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command")); key.DeleteSelf(); } #endif // TEST_REGISTRY +// ---------------------------------------------------------------------------- +// scope guard +// ---------------------------------------------------------------------------- + +#ifdef TEST_SCOPEGUARD + +#include "wx/scopeguard.h" + +static void function0() { puts("function0()"); } +static void function1(int n) { printf("function1(%d)\n", n); } +static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); } + +struct Object +{ + void method0() { printf("method0()\n"); } + void method1(int n) { printf("method1(%d)\n", n); } + void method2(double x, char c) { printf("method2(%g, %c)\n", x, c); } +}; + +static void TestScopeGuard() +{ + wxON_BLOCK_EXIT0(function0); + wxON_BLOCK_EXIT1(function1, 17); + wxON_BLOCK_EXIT2(function2, 3.14, 'p'); + + Object obj; + wxON_BLOCK_EXIT_OBJ0(obj, &Object::method0); + wxON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7); + wxON_BLOCK_EXIT_OBJ2(obj, &Object::method2, 2.71, 'e'); + + wxScopeGuard dismissed = wxMakeGuard(function0); + dismissed.Dismiss(); +} + +#endif + // ---------------------------------------------------------------------------- // sockets // ---------------------------------------------------------------------------- @@ -3341,7 +3777,7 @@ static void TestFtpMisc() { wxPuts(_T("*** Testing miscellaneous wxFTP functions ***")); - if ( ftp.SendCommand("STAT") != '2' ) + if ( ftp.SendCommand(_T("STAT")) != '2' ) { wxPuts(_T("ERROR: STAT failed")); } @@ -3350,7 +3786,7 @@ static void TestFtpMisc() wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str()); } - if ( ftp.SendCommand("HELP SITE") != '2' ) + if ( ftp.SendCommand(_T("HELP SITE")) != '2' ) { wxPuts(_T("ERROR: HELP SITE failed")); } @@ -3379,14 +3815,14 @@ static void TestFtpInteractive() // special handling of LIST and NLST as they require data connection wxString start(buf, 4); start.MakeUpper(); - if ( start == "LIST" || start == "NLST" ) + if ( start == _T("LIST") || start == _T("NLST") ) { wxString wildcard; if ( wxStrlen(buf) > 4 ) wildcard = buf + 5; wxArrayString files; - if ( !ftp.GetList(files, wildcard, start == "LIST") ) + if ( !ftp.GetList(files, wildcard, start == _T("LIST")) ) { wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str()); } @@ -3434,7 +3870,7 @@ static void TestFtpUpload() } // send a command to check the remote file - if ( ftp.SendCommand(wxString("STAT ") + file1) != '2' ) + if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' ) { wxPrintf(_T("ERROR: STAT %s failed\n"), file1); } @@ -3468,7 +3904,7 @@ static void TestFileStream() { wxPuts(_T("*** Testing wxFileInputStream ***")); - static const wxChar *filename = _T("testdata.fs"); + static const wxString filename = _T("testdata.fs"); { wxFileOutputStream fsOut(filename); fsOut.Write("foo", 3); @@ -3478,12 +3914,12 @@ static void TestFileStream() wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize()); while ( !fsIn.Eof() ) { - putchar(fsIn.GetC()); + wxPutchar(fsIn.GetC()); } if ( !wxRemoveFile(filename) ) { - wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename); + wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str()); } wxPuts(_T("\n*** wxFileInputStream test done ***")); @@ -3514,7 +3950,7 @@ static void TestMemoryStream() wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize()); while ( !memInpStream.Eof() ) { - putchar(memInpStream.GetC()); + wxPutchar(memInpStream.GetC()); } wxPuts(_T("\n*** wxMemoryInputStream test done ***")); @@ -3574,7 +4010,7 @@ static void TestStopWatch() } } - putchar('.'); + wxPutchar('.'); fflush(stdout); } @@ -3642,7 +4078,7 @@ static void DumpVObject(size_t level, const wxVCardObject& vcard) if ( !!value ) wxPrintf(_T(" = %s"), value.c_str()); - putchar('\n'); + wxPutchar('\n'); DumpVObject(level + 1, *vcObj); @@ -3903,6 +4339,26 @@ static void TestUnicodeToFromAscii() wxPutchar(_T('\n')); } +#include "wx/textfile.h" + +static void TestUnicodeTextFileRead() +{ + wxPuts(_T("Testing wxTextFile in Unicode build\n")); + + wxTextFile file; + if ( file.Open(_T("testdata.fc"), wxConvLocal) ) + { + const size_t count = file.GetLineCount(); + for ( size_t n = 0; n < count; n++ ) + { + const wxString& s = file[n]; + + wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"), + (unsigned)n, s.c_str(), (unsigned)s.length(), s.Last()); + } + } +} + #endif // TEST_UNICODE #ifdef TEST_WCHAR @@ -3982,14 +4438,14 @@ static void TestUtf8() } } - wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text), *wxConvCurrent); + wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text)); if ( s.empty() ) s = _T("<< conversion failed >>"); wxPrintf(_T("String in current cset: %s\n"), s.c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestEncodingConverter() @@ -4012,7 +4468,7 @@ static void TestEncodingConverter() wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } #endif // TEST_WCHAR @@ -4033,14 +4489,14 @@ static void TestZipStreamRead() { wxPuts(_T("*** Testing ZIP reading ***\n")); - static const wxChar *filename = _T("foo"); + static const wxString filename = _T("foo"); wxZipInputStream istr(TESTFILE_ZIP, filename); wxPrintf(_T("Archive size: %u\n"), istr.GetSize()); - wxPrintf(_T("Dumping the file '%s':\n"), filename); + wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str()); while ( !istr.Eof() ) { - putchar(istr.GetC()); + wxPutchar(istr.GetC()); fflush(stdout); } @@ -4111,7 +4567,7 @@ static void TestZipFileSystem() #include "wx/zstream.h" #include "wx/wfstream.h" -static const wxChar *FILENAME_GZ = _T("test.gz"); +static const wxString FILENAME_GZ = _T("test.gz"); static const wxChar *TEST_DATA = _T("hello and hello and hello and hello and hello"); static void TestZlibStreamWrite() @@ -4145,7 +4601,7 @@ static void TestZlibStreamRead() wxPuts(_T("Dumping the file:")); while ( !istr.Eof() ) { - putchar(istr.GetC()); + wxPutchar(istr.GetC()); fflush(stdout); } @@ -4154,6 +4610,138 @@ static void TestZlibStreamRead() #endif // TEST_ZLIB +// ---------------------------------------------------------------------------- +// Gzip streams +// ---------------------------------------------------------------------------- + +#ifdef TEST_GZIP + +#include "wx/wfstream.h" +#include "wx/gzstream.h" +#include "wx/filename.h" +#include "wx/txtstrm.h" + +// Reads two input streams and verifies that they are the same (and non-emtpy) +// +void GzipVerify(wxInputStream &in1, wxInputStream &in2) +{ + if (!in1 || !in2) { + wxPuts(_T(" Can't verify")); + return; + } + + const int BUFSIZE = 8192; + wxCharBuffer buf1(BUFSIZE); + wxCharBuffer buf2(BUFSIZE); + bool none = true; + + for (;;) + { + int n1 = in1.Read(buf1.data(), BUFSIZE).LastRead(); + int n2 = in2.Read(buf2.data(), BUFSIZE).LastRead(); + + if (n1 != n2 || (n1 && memcmp(buf1, buf2, n1) != 0) || (!n1 && none)) { + wxPuts(_T(" Failure")); + break; + } + + if (!n1) { + wxPuts(_T(" Success")); + break; + } + + none = false; + } + + while (in1.IsOk()) + in1.Read(buf1.data(), BUFSIZE); + while (in2.IsOk()) + in2.Read(buf2.data(), BUFSIZE); +} + +// Write a gzip file and read it back. +// +void TestGzip() +{ + wxPuts(_T("*** Testing gzip streams ***\n")); + + const wxString testname = _T("gziptest"); + const wxString gzipname = testname + _T(".gz"); + + // write some random test data to a testfile + wxPuts(_T("Writing random test data to ") + testname + _T("...")); + { + wxFFileOutputStream outstream(testname); + wxTextOutputStream textout(outstream); + + for (int i = 0; i < 1000 && outstream.Ok(); i++) + textout << rand() << rand() << rand() << rand() << endl; + + wxPuts(_T(" Done")); + } + + wxFileName fn(testname); + wxDateTime dt = fn.GetModificationTime(); + wxFFileInputStream instream(testname); + + // try writing a gzip file + wxPuts(_T("Writing ") + gzipname + _T(" using wxGzipOutputStream...")); + { + wxFFileOutputStream outstream(gzipname); + wxGzipOutputStream gzip(outstream, testname, dt); + + if (!gzip.Write(instream)) + wxPuts(_T(" Failure")); + else + wxPuts(_T(" Success")); + } + + // try reading the gzip file + wxPuts(_T("Reading ") + gzipname + _T(" using wxGzipInputStream...")); + { + instream.SeekI(0); + wxFFileInputStream instream2(gzipname); + wxGzipInputStream gzip(instream2); + GzipVerify(instream, gzip); + + if (gzip.GetName() != fn.GetFullName()) + wxPuts(gzipname + _T(" contains incorrect filename: ") + + gzip.GetName()); + if (dt.IsValid() && gzip.GetDateTime() != dt) + wxPuts(gzipname + _T(" contains incorrect timestamp: ") + + gzip.GetDateTime().Format()); + } + +#ifdef __UNIX__ + // then verify it using gzip program if it is in the path + wxPuts(_T("Reading ") + gzipname + _T(" using gzip program...")); + wxFFile file(popen((_T("gzip -d -c ") + gzipname).mb_str(), "r")); + if (file.fp()) { + wxFFileInputStream instream2(file); + instream.SeekI(0); + GzipVerify(instream, instream2); + pclose(file.fp()); + file.Detach(); + } + + // try reading a gzip created by gzip program + wxPuts(_T("Reading output of gzip program using wxGzipInputStream...")); + file.Attach(popen((_T("gzip -c ") + testname).mb_str(), "r")); + if (file.fp()) { + wxFFileInputStream instream2(file); + wxGzipInputStream gzip(instream2); + instream.SeekI(0); + GzipVerify(instream, gzip); + pclose(file.fp()); + file.Detach(); + } +#endif + + wxPuts(_T("\n--- Done gzip streams ---")); +} + +#endif // TEST_GZIP + // ---------------------------------------------------------------------------- // date time // ---------------------------------------------------------------------------- @@ -4386,7 +4974,7 @@ static void TestTimeTicks() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } // test conversions to JDN &c @@ -4440,7 +5028,7 @@ static void TestTimeWDays() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); // test SetToWeekDay() struct WeekDateTestData @@ -4717,7 +5305,7 @@ static void TestTimeDST() wxPuts(_T("\n*** wxDateTime DST test ***")); wxPrintf(_T("DST is%s in effect now.\n\n"), - wxDateTime::Now().IsDST() ? _T("") : _T(" not")); + wxDateTime::Now().IsDST() ? wxEmptyString : _T(" not")); // taken from http://www.energy.ca.gov/daylightsaving.html static const Date datesDST[2][2004 - 1900 + 1] = @@ -4783,7 +5371,7 @@ static void TestTimeDST() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); for ( year = 1990; year < 2005; year++ ) { @@ -4841,7 +5429,7 @@ static void TestTimeFormat() for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ ) { - wxPuts(_T("")); + wxPuts(wxEmptyString); wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT(); for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ ) @@ -5012,7 +5600,7 @@ static void TestTimeMS() } if ( !(i % 100) ) - putchar('.'); + wxPutchar('.'); } wxPuts(_T(", done")); @@ -5088,7 +5676,7 @@ static void TestTimeArithmetics() wxPrintf(_T(" (ERROR: should be %s)\n"), dt2.FormatISODate().c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } } @@ -5114,7 +5702,7 @@ static void TestTimeHolidays() wxPrintf(_T("\t%s\n"), hol[n].Format(format).c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestTimeZoneBug() @@ -5131,7 +5719,7 @@ static void TestTimeZoneBug() date += wxDateSpan::Day(); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestTimeSpanFormat() @@ -5158,7 +5746,7 @@ static void TestTimeSpanFormat() ts2.Format(formats[n]).c_str()); } - wxPuts(_T("")); + wxPuts(wxEmptyString); } #endif // TEST_DATETIME @@ -5176,7 +5764,8 @@ static void TestTextInputStream() { wxPuts(_T("\n*** wxTextInputStream test ***")); - wxFileInputStream fsIn(_T("testdata.fc")); + wxString filename = _T("testdata.fc"); + wxFileInputStream fsIn(filename); if ( !fsIn.Ok() ) { wxPuts(_T("ERROR: couldn't open file.")); @@ -5285,7 +5874,7 @@ wxThread::ExitCode MyDetachedThread::Entry() break; } - putchar(m_ch); + wxPutchar(m_ch); fflush(stdout); wxThread::Sleep(100); @@ -5326,7 +5915,7 @@ static void TestDetachedThreads() // wait until all threads terminate gs_cond.Wait(); - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestJoinableThreads() @@ -5338,7 +5927,7 @@ static void TestJoinableThreads() thread.Run(); wxPrintf(_T("\nThread terminated with exit code %lu.\n"), - (unsigned long)thread.Wait()); + (unsigned long)thread.Wait()); } static void TestThreadSuspend() @@ -5377,7 +5966,7 @@ static void TestThreadSuspend() // wait until the thread terminates gs_cond.Wait(); - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestThreadDelete() @@ -5433,7 +6022,7 @@ static void TestThreadDelete() wxPuts(_T("\nDeleted a joinable thread which already terminated.")); - wxPuts(_T("")); + wxPuts(wxEmptyString); } class MyWaitingThread : public wxThread @@ -5606,7 +6195,7 @@ private: int m_i; }; -WX_DEFINE_ARRAY(wxThread *, ArrayThreads); +WX_DEFINE_ARRAY_PTR(wxThread *, ArrayThreads); static void TestSemaphore() { @@ -5683,6 +6272,17 @@ static void PrintArray(const wxChar* name, const wxArrayString& array) } } +static void PrintArray(const wxChar* name, const wxSortedArrayString& array) +{ + wxPrintf(_T("Dump of the array '%s'\n"), name); + + size_t nCount = array.GetCount(); + for ( size_t n = 0; n < nCount; n++ ) + { + wxPrintf(_T("\t%s[%u] = '%s'\n"), name, n, array[n].c_str()); + } +} + int wxCMPFUNC_CONV StringLenCompare(const wxString& first, const wxString& second) { @@ -5747,18 +6347,65 @@ static void TestArrayOf ## name ## s() \ TestArrayOf(UShort); TestArrayOf(Int); +static void TestStlArray() +{ + wxPuts(_T("*** Testing std::vector operations ***\n")); + + { + wxArrayInt list1; + wxArrayInt::iterator it, en; + wxArrayInt::reverse_iterator rit, ren; + int i; + for ( i = 0; i < 5; ++i ) + list1.push_back(i); + + for ( it = list1.begin(), en = list1.end(), i = 0; + it != en; ++it, ++i ) + if ( *it != i ) + wxPuts(_T("Error in iterator\n")); + + for ( rit = list1.rbegin(), ren = list1.rend(), i = 4; + rit != ren; ++rit, --i ) + if ( *rit != i ) + wxPuts(_T("Error in reverse_iterator\n")); + + if ( *list1.rbegin() != *(list1.end()-1) || + *list1.begin() != *(list1.rend()-1) ) + wxPuts(_T("Error in iterator/reverse_iterator\n")); + + it = list1.begin()+1; + rit = list1.rbegin()+1; + if ( *list1.begin() != *(it-1) || + *list1.rbegin() != *(rit-1) ) + wxPuts(_T("Error in iterator/reverse_iterator\n")); + + if ( list1.front() != 0 || list1.back() != 4 ) + wxPuts(_T("Error in front()/back()\n")); + + list1.erase(list1.begin()); + list1.erase(list1.end()-1); + + for ( it = list1.begin(), en = list1.end(), i = 1; + it != en; ++it, ++i ) + if ( *it != i ) + wxPuts(_T("Error in erase()\n")); + } + + wxPuts(_T("*** Testing std::vector operations finished ***\n")); +} + static void TestArrayOfObjects() { wxPuts(_T("*** Testing wxObjArray ***\n")); { ArrayBars bars; - Bar bar("second bar (two copies!)"); + Bar bar(_T("second bar (two copies!)")); wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"), bars.GetCount(), Bar::GetNumber()); - bars.Add(new Bar("first bar")); + bars.Add(new Bar(_T("first bar"))); bars.Add(bar,2); wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"), @@ -5819,7 +6466,7 @@ static void TestStringConstruction() const wxChar *end = wxStrchr(s, _T('!')); TEST_CTOR((start, end), _T("really")); - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestString() @@ -5834,14 +6481,14 @@ static void TestString() for (int i = 0; i < 1000000; ++i) { - a = "Hello"; - b = " world"; - c = "! How'ya doin'?"; + a = _T("Hello"); + b = _T(" world"); + c = _T("! How'ya doin'?"); a += b; a += c; - c = "Hello world! What's up?"; + c = _T("Hello world! What's up?"); if (c != a) - c = "Doh!"; + c = _T("Doh!"); } wxPrintf(_T("TestString elapsed time: %ld\n"), sw.Time()); @@ -5872,7 +6519,7 @@ static void TestPChar() static void TestStringSub() { - wxString s("Hello, world!"); + wxString s(_T("Hello, world!")); wxPuts(_T("*** Testing wxString substring extraction ***")); @@ -5906,11 +6553,11 @@ static void TestStringSub() } else { - putchar('\n'); + wxPutchar('\n'); } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestStringFormat() @@ -5923,7 +6570,7 @@ static void TestStringFormat() wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str()); wxPrintf(_T("Number 18: %s\n"), s.c_str()); - wxPuts(_T("")); + wxPuts(wxEmptyString); } // returns "not found" for npos, value for all others @@ -5971,7 +6618,7 @@ static void TestStringFind() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestStringTokenizer() @@ -6073,7 +6720,7 @@ static void TestStringTokenizer() else { // nothing to compare with - wxPuts(_T("")); + wxPuts(wxEmptyString); } } @@ -6085,7 +6732,7 @@ static void TestStringTokenizer() delete [] buf; } - wxPuts(_T("")); + wxPuts(wxEmptyString); } static void TestStringReplace() @@ -6128,9 +6775,10 @@ static void TestStringReplace() } } - wxPuts(_T("")); + wxPuts(wxEmptyString); } +#if !TEST_ALL static void TestStringMatch() { wxPuts(_T("*** Testing wxString::Matches() ***")); @@ -6166,7 +6814,327 @@ static void TestStringMatch() matches == data.matches ? _T("ok") : _T("ERROR")); } - wxPuts(_T("")); + wxPuts(wxEmptyString); +} +#endif + +// Sigh, I want Test::Simple, Test::More and Test::Harness... +void ok(int line, bool ok, const wxString& msg = wxEmptyString) +{ + if( !ok ) + wxPuts(_T("NOT OK: (") + wxString::Format(_T("%d"), line) + + _T(") ") + msg); +} + +void is(int line, const wxString& got, const wxString& expected, + const wxString& msg = wxEmptyString) +{ + bool isOk = got == expected; + ok(line, isOk, msg); + if( !isOk ) + { + wxPuts(_T("Got: ") + got); + wxPuts(_T("Expected: ") + expected); + } +} + +#if 0 +void is(int line, const wxChar* got, const wxChar* expected, + const wxString& msg = wxEmptyString) +{ + bool isOk = wxStrcmp( got, expected ) == 0; + ok(line, isOk, msg); + if( !isOk ) + { + wxPuts(_T("Got: ") + wxString(got)); + wxPuts(_T("Expected: ") + wxString(expected)); + } +} +#endif + +void is(int line, const wxChar& got, const wxChar& expected, + const wxString& msg = wxEmptyString) +{ + bool isOk = got == expected; + ok(line, isOk, msg); + if( !isOk ) + { + wxPuts(_T("Got: ") + got); + wxPuts(_T("Expected: ") + expected); + } +} + +void is(int line, size_t got, size_t expected, + const wxString& msg = wxEmptyString) +{ + bool isOk = got == expected; + ok(line, isOk, msg); + if( !isOk ) + { + wxPuts(wxString::Format(_T("Got: %d"), got)); + wxPuts(wxString::Format(_T("Expected: %d"), expected)); + } +} + +#define is_m( got, expected, message ) is( __LINE__, (got), (expected), (message) ) +#define is_nom( got, expected ) is( __LINE__, (got), (expected), wxEmptyString ) + +void TestStdString() +{ + wxPuts(_T("*** Testing std::string operations ***\n")); + + // test ctors + wxString s1(_T("abcdefgh")), + s2(_T("abcdefghijklm"), 8), + s3(_T("abcdefghijklm")), + s4(8, _T('a')); + wxString s5(s1), + s6(s3, 0, 8), + s7(s3.begin(), s3.begin() + 8); + wxString s8(s1, 4, 8), s9, s10, s11; + + is( __LINE__, s1, _T("abcdefgh") ); + is( __LINE__, s2, s1 ); + is( __LINE__, s4, _T("aaaaaaaa") ); + is( __LINE__, s5, _T("abcdefgh") ); + is( __LINE__, s6, s1 ); + is( __LINE__, s7, s1 ); + is( __LINE__, s8, _T("efgh") ); + + // test append + s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("abc"); + s1.append(_T("def")); + s2.append(_T("defgh"), 3); + s3.append(wxString(_T("abcdef")), 3, 6); + s4.append(s1); + s5.append(3, _T('a')); + s6.append(s1.begin() + 3, s1.end()); + + is( __LINE__, s1, _T("abcdef") ); + is( __LINE__, s2, _T("abcdef") ); + is( __LINE__, s3, _T("abcdef") ); + is( __LINE__, s4, _T("abcabcdef") ); + is( __LINE__, s5, _T("abcaaa") ); + is( __LINE__, s6, _T("abcdef") ); + + // test assign + s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("abc"); + s1.assign(_T("def")); + s2.assign(_T("defgh"), 3); + s3.assign(wxString(_T("abcdef")), 3, 6); + s4.assign(s1); + s5.assign(3, _T('a')); + s6.assign(s1.begin() + 1, s1.end()); + + is( __LINE__, s1, _T("def") ); + is( __LINE__, s2, _T("def") ); + is( __LINE__, s3, _T("def") ); + is( __LINE__, s4, _T("def") ); + is( __LINE__, s5, _T("aaa") ); + is( __LINE__, s6, _T("ef") ); + + // test compare + s1 = _T("abcdefgh"); + s2 = _T("abcdefgh"); + s3 = _T("abc"); + s4 = _T("abcdefghi"); + s5 = _T("aaa"); + s6 = _T("zzz"); + s7 = _T("zabcdefg"); + + ok( __LINE__, s1.compare(s2) == 0 ); + ok( __LINE__, s1.compare(s3) > 0 ); + ok( __LINE__, s1.compare(s4) < 0 ); + ok( __LINE__, s1.compare(s5) > 0 ); + ok( __LINE__, s1.compare(s6) < 0 ); + ok( __LINE__, s1.compare(1, 12, s1) > 0); + ok( __LINE__, s1.compare(_T("abcdefgh")) == 0); + ok( __LINE__, s1.compare(1, 7, _T("bcdefgh")) == 0); + ok( __LINE__, s1.compare(1, 7, _T("bcdefgh"), 7) == 0); + + // test erase + s1.erase(1, 1); + s2.erase(4, 12); + wxString::iterator it = s3.erase(s3.begin() + 1); + wxString::iterator it2 = s4.erase(s4.begin() + 4, s4.begin() + 6); + wxString::iterator it3 = s7.erase(s7.begin() + 4, s7.begin() + 8); + + is( __LINE__, s1, _T("acdefgh") ); + is( __LINE__, s2, _T("abcd") ); + is( __LINE__, s3, _T("ac") ); + is( __LINE__, s4, _T("abcdghi") ); + is( __LINE__, s7, _T("zabc") ); + is( __LINE__, *it, _T('c') ); + is( __LINE__, *it2, _T('g') ); + ok( __LINE__, it3 == s7.end() ); + + // find + // 0 1 2 + // 01234567890123456789012345 + s1 = _T("abcdefgABCDEFGabcABCabcABC"); + s2 = _T("gAB"); + + is_nom( s1.find(_T('A')), 7u ); + is_nom( s1.find(_T('A'), 7), 7u ); + is_nom( s1.find(_T('Z')), wxString::npos ); + is_nom( s1.find(_T('C'), 22), 25u ); + + is_nom( s1.find(_T("gAB")), 6u ); + is_nom( s1.find(_T("gAB"), 7), wxString::npos ); + is_nom( s1.find(_T("gAB"), 6), 6u ); + + is_nom( s1.find(_T("gABZZZ"), 2, 3), 6u ); + is_nom( s1.find(_T("gABZZZ"), 7, 3), wxString::npos ); + + is_nom( s1.find(s2), 6u ); + is_nom( s1.find(s2, 7), wxString::npos ); + is_nom( s1.find(s2, 6), 6u ); + + // find_first_not_of + // 0 1 2 3 + // 01234567890123456789012345678901234 + s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd"); + s2 = _T("aaaaaa"); + + is_nom( s1.find_first_not_of(_T('a')), 6u ); + is_nom( s1.find_first_not_of(_T('a'), 7), 7u ); + is_nom( s2.find_first_not_of(_T('a')), wxString::npos ); + + is_nom( s1.find_first_not_of(_T("abde"), 4), 7u ); + is_nom( s1.find_first_not_of(_T("abde"), 7), 7u ); + is_nom( s1.find_first_not_of(_T("abcdefghijkl")), wxString::npos ); + + is_nom( s1.find_first_not_of(_T("abcdefghi"), 0, 4), 9u ); + + // find_first_of + is_nom( s1.find_first_of(_T('c')), 7u ); + is_nom( s1.find_first_of(_T('v')), wxString::npos ); + is_nom( s1.find_first_of(_T('c'), 10), 24u ); + + is_nom( s1.find_first_of(_T("ijkl")), 13u ); + is_nom( s1.find_first_of(_T("ddcfg"), 17), 24u ); + is_nom( s1.find_first_of(_T("ddcfga"), 17, 5), 24u ); + + // find_last_not_of + // 0 1 2 3 + // 01234567890123456789012345678901234 + s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd"); + s2 = _T("aaaaaa"); + + is_nom( s2.find_last_not_of(_T('a')), wxString::npos ); + is_nom( s1.find_last_not_of(_T('d')), 33u ); + is_nom( s1.find_last_not_of(_T('d'), 25), 24u ); + + is_nom( s1.find_last_not_of(_T("bcd")), 22u ); + is_nom( s1.find_last_not_of(_T("abc"), 24), 16u ); + + is_nom( s1.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3), 16u ); + + // find_last_of + is_nom( s2.find_last_of(_T('c')), wxString::npos ); + is_nom( s1.find_last_of(_T('a')), 22u ); + is_nom( s1.find_last_of(_T('b'), 24), 23u ); + + is_nom( s1.find_last_of(_T("ijklm")), 16u ); + is_nom( s1.find_last_of(_T("ijklma"), 33, 4), 16u ); + is_nom( s1.find_last_of(_T("a"), 17), 17u ); + + // test insert + s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("aaaa"); + s9 = s10 = _T("cdefg"); + + s1.insert(1, _T("cc") ); + s2.insert(2, _T("cdef"), 3); + s3.insert(2, s10); + s4.insert(2, s10, 3, 7); + s5.insert(1, 2, _T('c')); + it = s6.insert(s6.begin() + 3, _T('X')); + s7.insert(s7.begin(), s9.begin(), s9.end() - 1); + s8.insert(s8.begin(), 2, _T('c')); + + is( __LINE__, s1, _T("accaaa") ); + is( __LINE__, s2, _T("aacdeaa") ); + is( __LINE__, s3, _T("aacdefgaa") ); + is( __LINE__, s4, _T("aafgaa") ); + is( __LINE__, s5, _T("accaaa") ); + is( __LINE__, s6, _T("aaaXa") ); + is( __LINE__, s7, _T("cdefaaaa") ); + is( __LINE__, s8, _T("ccaaaa") ); + + s1 = s2 = s3 = _T("aaaa"); + s1.insert(0, _T("ccc"), 2); + s2.insert(4, _T("ccc"), 2); + + is( __LINE__, s1, _T("ccaaaa") ); + is( __LINE__, s2, _T("aaaacc") ); + + // test replace + s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("QWERTYUIOP"); + s9 = s10 = _T("werty"); + + s1.replace(3, 4, _T("rtyu")); + s1.replace(8, 7, _T("opopop")); + s2.replace(10, 12, _T("WWWW")); + s3.replace(1, 5, s9); + s4.replace(1, 4, s9, 0, 4); + s5.replace(1, 2, s9, 1, 12); + s6.replace(0, 123, s9, 0, 123); + s7.replace(2, 7, s9); + + is( __LINE__, s1, _T("QWErtyuIopopop") ); + is( __LINE__, s2, _T("QWERTYUIOPWWWW") ); + is( __LINE__, s3, _T("QwertyUIOP") ); + is( __LINE__, s4, _T("QwertYUIOP") ); + is( __LINE__, s5, _T("QertyRTYUIOP") ); + is( __LINE__, s6, s9); + is( __LINE__, s7, _T("QWwertyP") ); + + // rfind + // 0 1 2 + // 01234567890123456789012345 + s1 = _T("abcdefgABCDEFGabcABCabcABC"); + s2 = _T("gAB"); + s3 = _T("ab"); + + is_nom( s1.rfind(_T('A')), 23u ); + is_nom( s1.rfind(_T('A'), 7), 7u ); + is_nom( s1.rfind(_T('Z')), wxString::npos ); + is_nom( s1.rfind(_T('C'), 22), 19u ); + + is_nom( s1.rfind(_T("cAB")), 22u ); + is_nom( s1.rfind(_T("cAB"), 15), wxString::npos ); + is_nom( s1.rfind(_T("cAB"), 21), 16u ); + + is_nom( s1.rfind(_T("gABZZZ"), 7, 3), 6u ); + is_nom( s1.rfind(_T("gABZZZ"), 5, 3), wxString::npos ); + + is_nom( s1.rfind(s2), 6u ); + is_nom( s1.rfind(s2, 5), wxString::npos ); + is_nom( s1.rfind(s2, 6), 6u ); + is_nom( s1.rfind(s3, 1), 0u ); + + // resize + s1 = s2 = s3 = s4 = _T("abcABCdefDEF"); + + s1.resize( 12 ); + s2.resize( 10 ); + s3.resize( 14, _T(' ') ); + s4.resize( 14, _T('W') ); + + is_nom( s1, _T("abcABCdefDEF") ); + is_nom( s2, _T("abcABCdefD") ); + is_nom( s3, _T("abcABCdefDEF ") ); + is_nom( s4, _T("abcABCdefDEFWW") ); + + // substr + s1 = _T("abcdefgABCDEFG"); + + is_nom( s1.substr( 0, 14 ), s1 ); + is_nom( s1.substr( 1, 13 ), _T("bcdefgABCDEFG") ); + is_nom( s1.substr( 1, 20 ), _T("bcdefgABCDEFG") ); + is_nom( s1.substr( 14, 30 ), _T("") ); + + wxPuts(_T("*** Testing std::string operations finished ***\n")); } #endif // TEST_STRINGS @@ -6181,7 +7149,7 @@ static void TestStringMatch() int main(int argc, char **argv) { - wxApp::CheckBuildOptions(wxBuildOptions()); + wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); wxInitializer initializer; if ( !initializer ) @@ -6244,7 +7212,9 @@ int main(int argc, char **argv) wxChar **wargv = new wxChar *[argc + 1]; { - for ( int n = 0; n < argc; n++ ) + int n; + + for (n = 0; n < argc; n++ ) { wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); wargv[n] = wxStrdup(warg); @@ -6290,8 +7260,7 @@ int main(int argc, char **argv) #endif // TEST_CMDLINE #ifdef TEST_STRINGS - if ( TEST_ALL ) - { + #if TEST_ALL TestPChar(); TestString(); TestStringSub(); @@ -6300,16 +7269,15 @@ int main(int argc, char **argv) TestStringFind(); TestStringTokenizer(); TestStringReplace(); - } - else - { + #else TestStringMatch(); - } + #endif + + TestStdString(); #endif // TEST_STRINGS #ifdef TEST_ARRAYS - if ( TEST_ALL ) - { + #if TEST_ALL wxArrayString a1; a1.Add(_T("tiger")); a1.Add(_T("cat")); @@ -6325,46 +7293,57 @@ int main(int argc, char **argv) wxArrayString a2(a1); PrintArray(_T("a2"), a2); + #if !wxUSE_STL wxSortedArrayString a3(a1); + #else + wxSortedArrayString a3; + for (wxArrayString::iterator it = a1.begin(), en = a1.end(); + it != en; ++it) + a3.Add(*it); + #endif PrintArray(_T("a3"), a3); wxPuts(_T("*** After deleting three strings from a1")); - a1.Remove(2,3); + a1.RemoveAt(2,3); PrintArray(_T("a1"), a1); PrintArray(_T("a2"), a2); PrintArray(_T("a3"), a3); + #if !wxUSE_STL wxPuts(_T("*** After reassigning a1 to a2 and a3")); a3 = a2 = a1; PrintArray(_T("a2"), a2); PrintArray(_T("a3"), a3); + #endif wxPuts(_T("*** After sorting a1")); - a1.Sort(); + a1.Sort(false); PrintArray(_T("a1"), a1); wxPuts(_T("*** After sorting a1 in reverse order")); a1.Sort(true); PrintArray(_T("a1"), a1); + #if !wxUSE_STL wxPuts(_T("*** After sorting a1 by the string length")); - a1.Sort(StringLenCompare); + a1.Sort(&StringLenCompare); PrintArray(_T("a1"), a1); + #endif TestArrayOfObjects(); TestArrayOfUShorts(); - } + #endif TestArrayOfInts(); + TestStlArray(); #endif // TEST_ARRAYS #ifdef TEST_DIR - if ( TEST_ALL ) - { + #if TEST_ALL TestDirExists(); TestDirEnum(); - } + #endif TestDirTraverse(); #endif // TEST_DIR @@ -6386,6 +7365,7 @@ int main(int argc, char **argv) #ifdef TEST_LIST TestListCtor(); + TestList(); #endif // TEST_LIST #ifdef TEST_LOCALE @@ -6417,77 +7397,62 @@ int main(int argc, char **argv) #endif // TEST_LOG #ifdef TEST_FILE - if ( TEST_ALL ) - { - TestFileRead(); - TestTextFileRead(); - TestFileCopy(); - } + TestFileRead(); + TestTextFileRead(); + TestFileCopy(); #endif // TEST_FILE #ifdef TEST_FILENAME - if ( 0 ) - { - wxFileName fn; - fn.Assign(_T("c:\\foo"), _T("bar.baz")); - fn.Assign(_T("/u/os9-port/Viewer/tvision/WEI2HZ-3B3-14_05-04-00MSC1.asc")); - - DumpFileName(fn); - } - TestFileNameConstruction(); - if ( TEST_ALL ) - { - TestFileNameConstruction(); - TestFileNameMakeRelative(); - TestFileNameMakeAbsolute(); - TestFileNameSplit(); - TestFileNameTemp(); - TestFileNameCwd(); - TestFileNameComparison(); - TestFileNameOperations(); - } + TestFileNameMakeRelative(); + TestFileNameMakeAbsolute(); + TestFileNameSplit(); + TestFileNameTemp(); + TestFileNameCwd(); + TestFileNameDirManip(); + TestFileNameComparison(); + TestFileNameOperations(); #endif // TEST_FILENAME #ifdef TEST_FILETIME TestFileGetTimes(); - if ( 0 ) + #if 0 TestFileSetTimes(); + #endif #endif // TEST_FILETIME #ifdef TEST_FTP wxLog::AddTraceMask(FTP_TRACE_MASK); if ( TestFtpConnect() ) { - if ( TEST_ALL ) - { + #if TEST_ALL TestFtpList(); TestFtpDownload(); TestFtpMisc(); TestFtpFileSize(); TestFtpUpload(); - } + #endif - if ( TEST_INTERACTIVE ) + #if TEST_INTERACTIVE TestFtpInteractive(); + #endif } //else: connecting to the FTP server failed - if ( 0 ) + #if 0 TestFtpWuFtpd(); + #endif #endif // TEST_FTP #ifdef TEST_LONGLONG // seed pseudo random generator srand((unsigned)time(NULL)); - if ( 0 ) - { + #if 0 TestSpeed(); - } + #endif - if ( TEST_ALL ) - { + #if TEST_ALL TestMultiplication(); TestDivision(); TestAddition(); @@ -6496,7 +7461,7 @@ int main(int argc, char **argv) TestLongLongComparison(); TestLongLongToString(); TestLongLongPrintf(); - } + #endif #endif // TEST_LONGLONG #ifdef TEST_HASH @@ -6507,26 +7472,29 @@ int main(int argc, char **argv) TestHashMap(); #endif // TEST_HASHMAP +#ifdef TEST_HASHSET + TestHashSet(); +#endif // TEST_HASHSET + #ifdef TEST_MIME wxLog::AddTraceMask(_T("mime")); - if ( TEST_ALL ) - { + #if TEST_ALL TestMimeEnum(); TestMimeOverride(); TestMimeAssociate(); - } + #endif TestMimeFilename(); #endif // TEST_MIME #ifdef TEST_INFO_FUNCTIONS - if ( TEST_ALL ) - { + #if TEST_ALL TestOsInfo(); TestUserInfo(); - if ( TEST_INTERACTIVE ) + #if TEST_INTERACTIVE TestDiskInfo(); - } + #endif + #endif #endif // TEST_INFO_FUNCTIONS #ifdef TEST_PATHLIST @@ -6542,21 +7510,24 @@ int main(int argc, char **argv) #endif // TEST_PRINTF #ifdef TEST_REGCONF + #if 0 TestRegConfWrite(); + #endif + TestRegConfRead(); #endif // TEST_REGCONF #ifdef TEST_REGEX // TODO: write a real test using src/regex/tests file - if ( TEST_ALL ) - { + #if TEST_ALL TestRegExCompile(); TestRegExMatch(); TestRegExSubmatch(); TestRegExReplacement(); - if ( TEST_INTERACTIVE ) + #if TEST_INTERACTIVE TestRegExInteractive(); - } + #endif + #endif #endif // TEST_REGEX #ifdef TEST_REGISTRY @@ -6570,10 +7541,9 @@ int main(int argc, char **argv) #endif // TEST_SOCKETS #ifdef TEST_STREAMS - if ( TEST_ALL ) - { + #if TEST_ALL TestFileStream(); - } + #endif TestMemoryStream(); #endif // TEST_STREAMS @@ -6587,16 +7557,17 @@ int main(int argc, char **argv) if ( nCPUs != -1 ) wxThread::SetConcurrency(nCPUs); - TestDetachedThreads(); - if ( TEST_ALL ) - { TestJoinableThreads(); + + #if TEST_ALL + TestJoinableThreads(); + TestDetachedThreads(); TestThreadSuspend(); TestThreadDelete(); TestThreadConditions(); TestThreadExec(); TestSemaphore(); - } + #endif #endif // TEST_THREADS #ifdef TEST_TIMER @@ -6604,8 +7575,7 @@ int main(int argc, char **argv) #endif // TEST_TIMER #ifdef TEST_DATETIME - if ( TEST_ALL ) - { + #if TEST_ALL TestTimeSet(); TestTimeStatic(); TestTimeRange(); @@ -6623,14 +7593,17 @@ int main(int argc, char **argv) TestTimeMS(); TestTimeZoneBug(); - } + #endif - TestTimeWNumber(); - - if ( TEST_INTERACTIVE ) + #if TEST_INTERACTIVE TestDateTimeInteractive(); + #endif #endif // TEST_DATETIME +#ifdef TEST_SCOPEGUARD + TestScopeGuard(); +#endif + #ifdef TEST_USLEEP wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z...")); wxUsleep(3000); @@ -6646,7 +7619,10 @@ int main(int argc, char **argv) #endif // TEST_VOLUME #ifdef TEST_UNICODE - TestUnicodeToFromAscii(); + TestUnicodeTextFileRead(); + #if TEST_ALL + TestUnicodeToFromAscii(); + #endif #endif // TEST_UNICODE #ifdef TEST_WCHAR @@ -6664,6 +7640,12 @@ int main(int argc, char **argv) TestZlibStreamRead(); #endif // TEST_ZLIB +#ifdef TEST_GZIP + TestGzip(); +#endif + + wxUnusedVar(argc); + wxUnusedVar(argv); return 0; }