X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b1859b1a1b35194abb9d55a35d8bad202db39776..f1d5aa4eca541a2f90044a63f555985d6bd4adf3:/samples/console/console.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 1744e90776..ce887b1a59 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -49,7 +49,7 @@ // 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 +#define TEST_ALL 1 #if TEST_ALL @@ -88,7 +88,7 @@ #define TEST_WCHAR #define TEST_ZIP #else // #if TEST_ALL - #define TEST_CMDLINE + #define TEST_EXECUTE #endif // some tests are interactive, define this to run them @@ -468,7 +468,7 @@ static void TestDllListLoaded() for ( size_t n = 0; n < count; ++n ) { const wxDynamicLibraryDetails& details = dlls[n]; - printf("%-45s", details.GetPath().mb_str()); + printf("%-45s", (const char *)details.GetPath().mb_str()); void *addr; size_t len; @@ -478,7 +478,7 @@ static void TestDllListLoaded() (unsigned long)addr, (unsigned long)((char *)addr + len)); } - printf(" %s\n", details.GetVersion().mb_str()); + printf(" %s\n", (const char *)details.GetVersion().mb_str()); } } @@ -536,11 +536,13 @@ static void TestExecute() wxPuts(_T("*** testing wxExecute ***")); #ifdef __UNIX__ - #define COMMAND "cat -n ../../Makefile" // "echo hi" + #define COMMAND "echo hi" + #define ASYNC_COMMAND "xclock" #define SHELL_COMMAND "echo hi from shell" - #define REDIRECT_COMMAND COMMAND // "date" + #define REDIRECT_COMMAND "cat -n Makefile" #elif defined(__WXMSW__) #define COMMAND "command.com /c echo hi" + #define ASYNC_COMMAND "notepad" #define SHELL_COMMAND "echo hi" #define REDIRECT_COMMAND COMMAND #else @@ -556,19 +558,22 @@ static void TestExecute() wxPrintf(_T("Testing wxExecute: ")); fflush(stdout); - if ( wxExecute(_T(COMMAND), true /* sync */) == 0 ) + if ( wxExecute(_T(COMMAND), wxEXEC_SYNC) == 0 ) wxPuts(_T("Ok.")); else wxPuts(_T("ERROR.")); -#if 0 // no, it doesn't work (yet?) wxPrintf(_T("Testing async wxExecute: ")); fflush(stdout); - if ( wxExecute(COMMAND) != 0 ) + int pid = wxExecute(ASYNC_COMMAND); + if ( pid != 0 ) + { wxPuts(_T("Ok (command launched).")); + if ( wxKill(pid) == -1 ) + wxPuts("ERROR: failed to kill child process."); + } else wxPuts(_T("ERROR.")); -#endif // 0 wxPrintf(_T("Testing wxExecute with redirection:\n")); wxArrayString output; @@ -578,10 +583,25 @@ static void TestExecute() } else { - size_t count = output.GetCount(); - for ( size_t n = 0; n < count; n++ ) + // don't show too much output, MAX_LINES is enough + static const unsigned MAX_LINES = 20; + + const unsigned count = output.size(); + for ( unsigned n = 0; + n < (count > MAX_LINES ? MAX_LINES/2 : count); + n++ ) { - wxPrintf(_T("\t%s\n"), output[n].c_str()); + wxPrintf("%04u:\t%s\n", n + 1, output[n]); + } + + if ( count > MAX_LINES ) + { + wxPrintf("... skipping %u lines...\n", count - MAX_LINES); + + for ( unsigned n = count - MAX_LINES/2; n < count; n++ ) + { + wxPrintf("%04u:\t%s\n", n + 1, output[n]); + } } wxPuts(_T("Ok.")); @@ -1305,32 +1325,6 @@ static void TestMimeEnum() wxPuts(wxEmptyString); } -static void TestMimeOverride() -{ - wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n")); - - static const wxChar *mailcap = _T("/tmp/mailcap"); - static const wxChar *mimetypes = _T("/tmp/mime.types"); - - if ( wxFile::Exists(mailcap) ) - wxPrintf(_T("Loading mailcap from '%s': %s\n"), - mailcap, - wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR")); - else - wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), - mailcap); - - if ( wxFile::Exists(mimetypes) ) - wxPrintf(_T("Loading mime.types from '%s': %s\n"), - mimetypes, - wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR")); - else - wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), - mimetypes); - - wxPuts(wxEmptyString); -} - static void TestMimeFilename() { wxPuts(_T("*** Testing MIME type from filename query ***\n")); @@ -1375,6 +1369,35 @@ static void TestMimeFilename() wxPuts(wxEmptyString); } +// these tests were broken by wxMimeTypesManager changes, temporarily disabling +#if 0 + +static void TestMimeOverride() +{ + wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n")); + + static const wxChar *mailcap = _T("/tmp/mailcap"); + static const wxChar *mimetypes = _T("/tmp/mime.types"); + + if ( wxFile::Exists(mailcap) ) + wxPrintf(_T("Loading mailcap from '%s': %s\n"), + mailcap, + wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR")); + else + wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"), + mailcap); + + if ( wxFile::Exists(mimetypes) ) + wxPrintf(_T("Loading mime.types from '%s': %s\n"), + mimetypes, + wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR")); + else + wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"), + mimetypes); + + wxPuts(wxEmptyString); +} + static void TestMimeAssociate() { wxPuts(_T("*** Testing creation of filetype association ***\n")); @@ -1403,6 +1426,8 @@ static void TestMimeAssociate() wxPuts(wxEmptyString); } +#endif // 0 + #endif // TEST_MIME // ---------------------------------------------------------------------------- @@ -2063,7 +2088,7 @@ static void TestRegConfWrite() static void TestRegConfRead() { - wxConfig *config = new wxConfig(_T("myapp")); + wxRegConfig *config = new wxRegConfig(_T("myapp")); wxString str; long dummy; @@ -2719,12 +2744,12 @@ public: protected: virtual void OnStackFrame(const wxStackFrame& frame) { - printf("[%2d] ", frame.GetLevel()); + printf("[%2d] ", (int) frame.GetLevel()); wxString name = frame.GetName(); if ( !name.empty() ) { - printf("%-20.40s", name.mb_str()); + printf("%-20.40s", (const char*)name.mb_str()); } else { @@ -2734,8 +2759,8 @@ protected: if ( frame.HasSourceLocation() ) { printf("\t%s:%d", - frame.GetFileName().mb_str(), - frame.GetLine()); + (const char*)frame.GetFileName().mb_str(), + (int)frame.GetLine()); } puts(""); @@ -2743,7 +2768,9 @@ protected: wxString type, val; for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ ) { - printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str()); + printf("\t%s %s = %s\n", (const char*)type.mb_str(), + (const char*)name.mb_str(), + (const char*)val.mb_str()); } } }; @@ -3408,7 +3435,11 @@ static void TestZipStreamRead() wxPuts(_T("*** Testing ZIP reading ***\n")); static const wxString filename = _T("foo"); - wxZipInputStream istr(TESTFILE_ZIP, filename); + wxFFileInputStream in(TESTFILE_ZIP); + wxZipInputStream istr(in); + wxZipEntry entry(filename); + istr.OpenEntry(entry); + wxPrintf(_T("Archive size: %u\n"), istr.GetSize()); wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str()); @@ -4399,8 +4430,10 @@ int main(int argc, char **argv) #ifdef TEST_MIME //wxLog::AddTraceMask(_T("mime")); TestMimeEnum(); +#if 0 TestMimeOverride(); - // TestMimeAssociate(); + TestMimeAssociate(); +#endif TestMimeFilename(); #endif // TEST_MIME