X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/399376561413cc8fdd10a24256f346377ce096ac..9e023db73b44392a07c52f88c9b11d34d312e89f:/samples/console/console.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index f2c4785572..90178e2339 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -28,6 +28,7 @@ #include "wx/string.h" #include "wx/file.h" #include "wx/app.h" +#include "wx/log.h" // without this pragma, the stupid compiler precompiles #defines below so that // changing them doesn't "take place" later! @@ -92,20 +93,20 @@ #define TEST_ZLIB #undef TEST_ALL - static const bool TEST_ALL = TRUE; + static const bool TEST_ALL = true; #else - #define TEST_TEXTSTREAM + #define TEST_SOCKETS - static const bool TEST_ALL = FALSE; + 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; + static const bool TEST_INTERACTIVE = true; #else - static const bool TEST_INTERACTIVE = FALSE; + static const bool TEST_INTERACTIVE = false; #endif // ---------------------------------------------------------------------------- @@ -206,7 +207,6 @@ static void TestCharset() #include "wx/cmdline.h" #include "wx/datetime.h" -#include "wx/log.h" #if wxUSE_CMDLINE_PARSER @@ -279,7 +279,7 @@ static void TestCmdLineConvert() #ifdef __UNIX__ static const wxChar *ROOTDIR = _T("/"); - static const wxChar *TESTDIR = _T("/usr"); + static const wxChar *TESTDIR = _T("/usr/local/share"); #elif defined(__WXMSW__) static const wxChar *ROOTDIR = _T("c:\\"); static const wxChar *TESTDIR = _T("d:\\"); @@ -406,6 +406,7 @@ static void TestDirTraverse() } // enum again with custom traverser + wxPuts(_T("Now enumerating directories:")); wxDir dir(TESTDIR); DirPrintTraverser traverser; dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN); @@ -569,7 +570,7 @@ static void TestExecute() wxPrintf(_T("Testing wxExecute: ")); fflush(stdout); - if ( wxExecute(COMMAND, TRUE /* sync */) == 0 ) + if ( wxExecute(COMMAND, true /* sync */) == 0 ) wxPuts(_T("Ok.")); else wxPuts(_T("ERROR.")); @@ -852,39 +853,39 @@ static struct FileNameInfo } filenames[] = { // Unix file names - { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), TRUE, wxPATH_UNIX }, - { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), TRUE, wxPATH_UNIX }, - { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), TRUE, wxPATH_UNIX }, - { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), FALSE, wxPATH_UNIX }, - { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_UNIX }, - { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), TRUE, wxPATH_UNIX }, - { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), TRUE, wxPATH_UNIX }, - { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), FALSE, wxPATH_UNIX }, - { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), TRUE, wxPATH_UNIX }, + { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX }, + { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX }, + { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX }, + { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX }, + { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX }, + { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX }, + { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX }, + { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX }, + { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX }, // Windows file names - { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_DOS }, - { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), FALSE, wxPATH_DOS }, - { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), FALSE, wxPATH_DOS }, - { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS }, - { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), TRUE, wxPATH_DOS }, - { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS }, - { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS }, + { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS }, + { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS }, + { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS }, + { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS }, + { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS }, + { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS }, + { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS }, // wxFileName support for Mac file names is broken currently #if 0 // Mac file names - { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE, wxPATH_MAC }, - { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), TRUE, wxPATH_MAC }, - { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), TRUE, wxPATH_MAC }, - { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), FALSE, wxPATH_MAC }, - { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE, wxPATH_MAC }, - { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), FALSE, wxPATH_MAC }, + { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC }, + { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC }, + { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC }, + { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC }, + { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC }, + { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC }, #endif // 0 // VMS file names - { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), TRUE, wxPATH_VMS }, - { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), FALSE, wxPATH_VMS }, + { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS }, + { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS }, }; static void TestFileNameConstruction() @@ -1034,6 +1035,24 @@ static void TestFileNameMakeRelative() } } +static void TestFileNameMakeAbsolute() +{ + wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***")); + + for ( size_t n = 0; n < WXSIZEOF(filenames); n++ ) + { + const FileNameInfo& fni = filenames[n]; + wxFileName fn(fni.fullname, fni.format); + + wxPrintf(_T("'%s' absolutized: "), + fn.GetFullPath(fni.format).c_str()); + fn.MakeAbsolute(); + wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str()); + } + + wxPuts(_T("")); +} + static void TestFileNameComparison() { // TODO! @@ -1125,7 +1144,7 @@ static void TestHash() { wxHashFoos hash; - hash.DeleteContents(TRUE); + hash.DeleteContents(true); wxPrintf(_T("Hash created: %u foos in hash, %u foos totally\n"), hash.GetCount(), Foo::count); @@ -1354,7 +1373,7 @@ 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()); - list1.DeleteContents(TRUE); + list1.DeleteContents(true); } wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber()); @@ -2255,26 +2274,26 @@ static void TestRegExCompile() bool correct; } regExCompTestData[] = { - { _T("foo"), TRUE }, - { _T("foo("), FALSE }, - { _T("foo(bar"), FALSE }, - { _T("foo(bar)"), TRUE }, - { _T("foo["), FALSE }, - { _T("foo[bar"), FALSE }, - { _T("foo[bar]"), TRUE }, - { _T("foo{"), TRUE }, - { _T("foo{1"), FALSE }, - { _T("foo{bar"), TRUE }, - { _T("foo{1}"), TRUE }, - { _T("foo{1,2}"), TRUE }, - { _T("foo{bar}"), TRUE }, - { _T("foo*"), TRUE }, - { _T("foo**"), FALSE }, - { _T("foo+"), TRUE }, - { _T("foo++"), FALSE }, - { _T("foo?"), TRUE }, - { _T("foo??"), FALSE }, - { _T("foo?+"), FALSE }, + { _T("foo"), true }, + { _T("foo("), false }, + { _T("foo(bar"), false }, + { _T("foo(bar)"), true }, + { _T("foo["), false }, + { _T("foo[bar"), false }, + { _T("foo[bar]"), true }, + { _T("foo{"), true }, + { _T("foo{1"), false }, + { _T("foo{bar"), true }, + { _T("foo{1}"), true }, + { _T("foo{1,2}"), true }, + { _T("foo{bar}"), true }, + { _T("foo*"), true }, + { _T("foo**"), false }, + { _T("foo+"), true }, + { _T("foo++"), false }, + { _T("foo?"), true }, + { _T("foo??"), false }, + { _T("foo?+"), false }, }; wxRegEx re; @@ -2301,12 +2320,12 @@ static void TestRegExMatch() bool correct; } regExMatchTestData[] = { - { _T("foo"), _T("bar"), FALSE }, - { _T("foo"), _T("foobar"), TRUE }, - { _T("^foo"), _T("foobar"), TRUE }, - { _T("^foo"), _T("barfoo"), FALSE }, - { _T("bar$"), _T("barbar"), TRUE }, - { _T("bar$"), _T("barbar "), FALSE }, + { _T("foo"), _T("bar"), false }, + { _T("foo"), _T("foobar"), true }, + { _T("^foo"), _T("foobar"), true }, + { _T("^foo"), _T("barfoo"), false }, + { _T("bar$"), _T("barbar"), true }, + { _T("bar$"), _T("barbar "), false }, }; for ( size_t n = 0; n < WXSIZEOF(regExMatchTestData); n++ ) @@ -2987,7 +3006,8 @@ static void TestSocketServer() return; } - for ( ;; ) + bool quit = false; + while ( !quit ) { wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT); @@ -3002,7 +3022,8 @@ static void TestSocketServer() server->SetTimeout(60); // 1 min - while ( socket->IsConnected() ) + bool close = false; + while ( !close && socket->IsConnected() ) { wxString s; wxChar ch = _T('\0'); @@ -3034,19 +3055,31 @@ static void TestSocketServer() } wxPrintf(_T("Server: got '%s'.\n"), s.c_str()); - if ( s == _T("bye") ) + if ( s == _T("close") ) { - delete socket; + wxPuts(_T("Closing connection")); - break; + close = true; } + else if ( s == _T("quit") ) + { + close = + quit = true; - socket->Write(s.MakeUpper().c_str(), s.length()); - socket->Write("\r\n", 2); - wxPrintf(_T("Server: wrote '%s'.\n"), s.c_str()); + wxPuts(_T("Shutting down the server")); + } + else // not a special command + { + socket->Write(s.MakeUpper().c_str(), s.length()); + socket->Write("\r\n", 2); + wxPrintf(_T("Server: wrote '%s'.\n"), s.c_str()); + } } - wxPuts(_T("Server: lost a client.")); + if ( !close ) + { + wxPuts(_T("Server: lost a client unexpectedly.")); + } socket->Destroy(); } @@ -3141,7 +3174,7 @@ static bool TestFtpConnect() { wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname); - return FALSE; + return false; } else { @@ -3149,7 +3182,7 @@ static bool TestFtpConnect() hostname, ftp.Pwd().c_str()); } - return TRUE; + return true; } // test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0? @@ -4229,8 +4262,8 @@ static void TestTimeStatic() // first line: the years to test { 1990, 1976, 2000, 2030, 1984, }, - // second line: TRUE if leap, FALSE otherwise - { FALSE, TRUE, TRUE, FALSE, TRUE } + // second line: true if leap, false otherwise + { false, true, true, false, true } }; for ( size_t n = 0; n < nYears; n++ ) @@ -4832,7 +4865,7 @@ static void TestTimeFormat() } else { - bool equal = FALSE; // suppress compilaer warning + bool equal = false; // suppress compilaer warning switch ( kind ) { case CompareBoth: @@ -4876,8 +4909,8 @@ static void TestTimeParse() static const ParseTestData parseTestDates[] = { - { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, TRUE }, - { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec, 1999, 03, 17, 20 }, TRUE }, + { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, true }, + { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec, 1999, 03, 17, 20 }, true }, }; for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ ) @@ -5242,7 +5275,7 @@ public: { m_n = n; m_ch = ch; - m_cancelled = FALSE; + m_cancelled = false; Create(); } @@ -5257,7 +5290,7 @@ private: size_t m_n; // number of characters to write wxChar m_ch; // character to write - bool m_cancelled; // FALSE if we exit normally + bool m_cancelled; // false if we exit normally }; wxThread::ExitCode MyDetachedThread::Entry() @@ -5274,7 +5307,7 @@ wxThread::ExitCode MyDetachedThread::Entry() { if ( TestDestroy() ) { - m_cancelled = TRUE; + m_cancelled = true; break; } @@ -5893,7 +5926,7 @@ static void TestStringSub() { wxString prefix = prefixes[n], rest; bool rc = s.StartsWith(prefix, &rest); - wxPrintf(_T("StartsWith('%s') = %s"), prefix.c_str(), rc ? _T("TRUE") : _T("FALSE")); + wxPrintf(_T("StartsWith('%s') = %s"), prefix.c_str(), rc ? _T("true") : _T("false")); if ( rc ) { wxPrintf(_T(" (the rest is '%s')\n"), rest.c_str()); @@ -6339,7 +6372,7 @@ int main(int argc, char **argv) PrintArray(_T("a1"), a1); wxPuts(_T("*** After sorting a1 in reverse order")); - a1.Sort(TRUE); + a1.Sort(true); PrintArray(_T("a1"), a1); wxPuts(_T("*** After sorting a1 by the string length")); @@ -6357,9 +6390,9 @@ int main(int argc, char **argv) if ( TEST_ALL ) { TestDirExists(); - TestDirTraverse(); + TestDirEnum(); } - TestDirEnum(); + TestDirTraverse(); #endif // TEST_DIR #ifdef TEST_DLLLOADER @@ -6387,12 +6420,17 @@ int main(int argc, char **argv) #endif // TEST_LOCALE #ifdef TEST_LOG + wxPuts(_T("*** Testing wxLog ***")); + wxString s; for ( size_t n = 0; n < 8000; n++ ) { s << (wxChar)(_T('A') + (n % 26)); } + wxLogWarning(_T("The length of the string is %lu"), + (unsigned long)s.length()); + wxString msg; msg.Printf(_T("A very very long message: '%s', the end!\n"), s.c_str()); @@ -6429,6 +6467,7 @@ int main(int argc, char **argv) { TestFileNameConstruction(); TestFileNameMakeRelative(); + TestFileNameMakeAbsolute(); TestFileNameSplit(); TestFileNameTemp(); TestFileNameCwd();