X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bc10103ec8203b5affe1a16b943049a2f27936bd..f20a2e1f4066e4f0235698e6220f1eed91c73326:/samples/console/console.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 40c664bb08..5611534320 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -84,13 +84,10 @@ #define TEST_TEXTSTREAM #define TEST_THREADS #define TEST_TIMER - #define TEST_UNICODE // #define TEST_VCARD -- don't enable this (VZ) // #define TEST_VOLUME --FIXME! (RN) #define TEST_WCHAR #define TEST_ZIP - #define TEST_ZLIB - #define TEST_GZIP #else // #if TEST_ALL @@ -3825,43 +3822,6 @@ static void TestFSVolume() // wide char and Unicode support // ---------------------------------------------------------------------------- -#ifdef TEST_UNICODE - -static void TestUnicodeToFromAscii() -{ - wxPuts(_T("Testing wxString::To/FromAscii()\n")); - - static const char *msg = "Hello, world!"; - wxString s = wxString::FromAscii(msg); - - wxPrintf(_T("Message in Unicode: %s\n"), s.c_str()); - printf("Message in ASCII: %s\n", (const char *)s.ToAscii()); - - 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 #include "wx/strconv.h" @@ -4059,190 +4019,6 @@ static void TestZipFileSystem() #endif // TEST_ZIP -// ---------------------------------------------------------------------------- -// ZLIB stream -// ---------------------------------------------------------------------------- - -#ifdef TEST_ZLIB - -#include "wx/zstream.h" -#include "wx/wfstream.h" - -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() -{ - wxPuts(_T("*** Testing Zlib stream reading ***\n")); - - wxFileOutputStream fileOutStream(FILENAME_GZ); - wxZlibOutputStream ostr(fileOutStream); - wxPrintf(_T("Compressing the test string... ")); - ostr.Write(TEST_DATA, wxStrlen(TEST_DATA) + 1); - if ( !ostr ) - { - wxPuts(_T("(ERROR: failed)")); - } - else - { - wxPuts(_T("(ok)")); - } - - wxPuts(_T("\n----- done ------")); -} - -static void TestZlibStreamRead() -{ - wxPuts(_T("*** Testing Zlib stream reading ***\n")); - - wxFileInputStream fileInStream(FILENAME_GZ); - wxZlibInputStream istr(fileInStream); - wxPrintf(_T("Archive size: %u\n"), istr.GetSize()); - - wxPuts(_T("Dumping the file:")); - while ( !istr.Eof() ) - { - wxPutchar(istr.GetC()); - fflush(stdout); - } - - wxPuts(_T("\n----- done ------")); -} - -#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 // ---------------------------------------------------------------------------- @@ -6091,13 +5867,6 @@ int main(int argc, char **argv) TestFSVolume(); #endif // TEST_VOLUME -#ifdef TEST_UNICODE - TestUnicodeTextFileRead(); - #if TEST_ALL - TestUnicodeToFromAscii(); - #endif -#endif // TEST_UNICODE - #ifdef TEST_WCHAR TestUtf8(); TestEncodingConverter(); @@ -6108,15 +5877,6 @@ int main(int argc, char **argv) TestZipFileSystem(); #endif // TEST_ZIP -#ifdef TEST_ZLIB - TestZlibStreamWrite(); - TestZlibStreamRead(); -#endif // TEST_ZLIB - -#ifdef TEST_GZIP - TestGzip(); -#endif - wxUnusedVar(argc); wxUnusedVar(argv); return 0;