]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/streams/zlibstream.cpp
bracing 10.7+ constant
[wxWidgets.git] / tests / streams / zlibstream.cpp
index 423d5491591b7aa665a79a1aaeb9e44798504711..af5fd16cdd9853236f078e22214c362387ceba56 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Hans Van Leemputten
 // RCS-ID:      $Id$
 // Copyright:   (c) 2004 Hans Van Leemputten
 // Author:      Hans Van Leemputten
 // RCS-ID:      $Id$
 // Copyright:   (c) 2004 Hans Van Leemputten
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
 ///////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
@@ -23,8 +23,8 @@
 #include "wx/zstream.h"
 #include "wx/wfstream.h"
 #include "wx/mstream.h"
 #include "wx/zstream.h"
 #include "wx/wfstream.h"
 #include "wx/mstream.h"
-
 #include "wx/txtstrm.h"
 #include "wx/txtstrm.h"
+#include "wx/buffer.h"
 
 #include "bstream.h"
 
 
 #include "bstream.h"
 
@@ -35,7 +35,7 @@ using std::string;
 
 #define DATABUFFER_SIZE 1024
 
 
 #define DATABUFFER_SIZE 1024
 
-static const wxString FILENAME_GZ = _T("zlibtest.gz");
+static const wxString FILENAME_GZ = wxT("zlibtest.gz");
 
 ///////////////////////////////////////////////////////////////////////////////
 // The test case
 
 ///////////////////////////////////////////////////////////////////////////////
 // The test case
@@ -72,6 +72,7 @@ public:
         CPPUNIT_TEST(TestStream_NoHeader_NoComp);
         CPPUNIT_TEST(TestStream_NoHeader_SpeedComp);
         CPPUNIT_TEST(TestStream_NoHeader_BestComp);
         CPPUNIT_TEST(TestStream_NoHeader_NoComp);
         CPPUNIT_TEST(TestStream_NoHeader_SpeedComp);
         CPPUNIT_TEST(TestStream_NoHeader_BestComp);
+        CPPUNIT_TEST(TestStream_NoHeader_Dictionary);
         CPPUNIT_TEST(TestStream_ZLib_Default);
         CPPUNIT_TEST(TestStream_ZLib_NoComp);
         CPPUNIT_TEST(TestStream_ZLib_SpeedComp);
         CPPUNIT_TEST(TestStream_ZLib_Default);
         CPPUNIT_TEST(TestStream_ZLib_NoComp);
         CPPUNIT_TEST(TestStream_ZLib_SpeedComp);
@@ -80,6 +81,7 @@ public:
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_NoComp);
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_SpeedComp);
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_BestComp);
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_NoComp);
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_SpeedComp);
         WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_BestComp);
+        WXTEST_WITH_GZIP_CONDITION(TestStream_GZip_Dictionary);
         WXTEST_WITH_GZIP_CONDITION(TestStream_ZLibGZip);
         CPPUNIT_TEST(Decompress_BadData);
         CPPUNIT_TEST(Decompress_wx251_zlib114_Data_NoHeader);
         WXTEST_WITH_GZIP_CONDITION(TestStream_ZLibGZip);
         CPPUNIT_TEST(Decompress_BadData);
         CPPUNIT_TEST(Decompress_wx251_zlib114_Data_NoHeader);
@@ -93,6 +95,7 @@ protected:
     void TestStream_NoHeader_NoComp();
     void TestStream_NoHeader_SpeedComp();
     void TestStream_NoHeader_BestComp();
     void TestStream_NoHeader_NoComp();
     void TestStream_NoHeader_SpeedComp();
     void TestStream_NoHeader_BestComp();
+    void TestStream_NoHeader_Dictionary();
     void TestStream_ZLib_Default();
     void TestStream_ZLib_NoComp();
     void TestStream_ZLib_SpeedComp();
     void TestStream_ZLib_Default();
     void TestStream_ZLib_NoComp();
     void TestStream_ZLib_SpeedComp();
@@ -101,6 +104,7 @@ protected:
     void TestStream_GZip_NoComp();
     void TestStream_GZip_SpeedComp();
     void TestStream_GZip_BestComp();
     void TestStream_GZip_NoComp();
     void TestStream_GZip_SpeedComp();
     void TestStream_GZip_BestComp();
+    void TestStream_GZip_Dictionary();
     void TestStream_ZLibGZip();
     // Try to decompress bad data.
     void Decompress_BadData();
     void TestStream_ZLibGZip();
     // Try to decompress bad data.
     void Decompress_BadData();
@@ -114,7 +118,7 @@ protected:
 private:
     const char *GetDataBuffer();
     const unsigned char *GetCompressedData();
 private:
     const char *GetDataBuffer();
     const unsigned char *GetCompressedData();
-    void doTestStreamData(int input_flag, int output_flag, int compress_level);
+    void doTestStreamData(int input_flag, int output_flag, int compress_level, const wxMemoryBuffer *buf = NULL);
     void doDecompress_ExternalData(const unsigned char *data, const char *value, size_t data_size, size_t value_size, int flag = wxZLIB_AUTO);
 
 private:
     void doDecompress_ExternalData(const unsigned char *data, const char *value, size_t data_size, size_t value_size, int flag = wxZLIB_AUTO);
 
 private:
@@ -132,6 +136,7 @@ private:
     char            m_DataBuffer[DATABUFFER_SIZE];
     size_t          m_SizeCompressedData;
     unsigned char  *m_pCompressedData;
     char            m_DataBuffer[DATABUFFER_SIZE];
     size_t          m_SizeCompressedData;
     unsigned char  *m_pCompressedData;
+    wxMemoryBuffer  m_Dictionary;
 
     // Used by the base Creat[In|Out]Stream and Delete[In|Out]Stream.
     wxMemoryInputStream  *m_pTmpMemInStream;
 
     // Used by the base Creat[In|Out]Stream and Delete[In|Out]Stream.
     wxMemoryInputStream  *m_pTmpMemInStream;
@@ -148,13 +153,15 @@ zlibStream::zlibStream()
     for (size_t i = 0; i < DATABUFFER_SIZE; i++)
         m_DataBuffer[i] = (i % 0xFF);
 
     for (size_t i = 0; i < DATABUFFER_SIZE; i++)
         m_DataBuffer[i] = (i % 0xFF);
 
+    m_Dictionary.AppendData(m_DataBuffer, sizeof(m_DataBuffer) / 2);
+
     // Set extra base config settings.
     m_bSimpleTellITest = true;
     m_bSimpleTellOTest = true;
 
 /* Example code on how to produce test data...
     {
     // Set extra base config settings.
     m_bSimpleTellITest = true;
     m_bSimpleTellOTest = true;
 
 /* Example code on how to produce test data...
     {
-        wxFFileOutputStream fstream_out(_T("gentest.cpp"));
+        wxFFileOutputStream fstream_out(wxT("gentest.cpp"));
         wxTextOutputStream out( fstream_out );
 
         genExtTestData(out, "zlib data created with wxWidgets 2.5.x [March 27], wxZLIB_NO_HEADER, zlib 1.1.4", wxZLIB_NO_HEADER);
         wxTextOutputStream out( fstream_out );
 
         genExtTestData(out, "zlib data created with wxWidgets 2.5.x [March 27], wxZLIB_NO_HEADER, zlib 1.1.4", wxZLIB_NO_HEADER);
@@ -187,6 +194,10 @@ void zlibStream::TestStream_NoHeader_BestComp()
 {
     doTestStreamData(wxZLIB_NO_HEADER, wxZLIB_NO_HEADER, wxZ_BEST_COMPRESSION);
 }
 {
     doTestStreamData(wxZLIB_NO_HEADER, wxZLIB_NO_HEADER, wxZ_BEST_COMPRESSION);
 }
+void zlibStream::TestStream_NoHeader_Dictionary()
+{
+    doTestStreamData(wxZLIB_NO_HEADER, wxZLIB_NO_HEADER, wxZ_DEFAULT_COMPRESSION, &m_Dictionary);
+}
 
 void zlibStream::TestStream_ZLib_Default()
 {
 
 void zlibStream::TestStream_ZLib_Default()
 {
@@ -221,6 +232,10 @@ void zlibStream::TestStream_GZip_BestComp()
 {
     doTestStreamData(wxZLIB_GZIP, wxZLIB_GZIP, wxZ_BEST_COMPRESSION);
 }
 {
     doTestStreamData(wxZLIB_GZIP, wxZLIB_GZIP, wxZ_BEST_COMPRESSION);
 }
+void zlibStream::TestStream_GZip_Dictionary()
+{
+    doTestStreamData(wxZLIB_GZIP, wxZLIB_GZIP, wxZ_DEFAULT_COMPRESSION, &m_Dictionary);
+}
 
 void zlibStream::TestStream_ZLibGZip()
 {
 
 void zlibStream::TestStream_ZLibGZip()
 {
@@ -307,7 +322,7 @@ const unsigned char *zlibStream::GetCompressedData()
     return m_pCompressedData;
 }
 
     return m_pCompressedData;
 }
 
-void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_level)
+void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_level, const wxMemoryBuffer *buf)
 {
     size_t fail_pos;
     char last_value = 0;
 {
     size_t fail_pos;
     char last_value = 0;
@@ -320,6 +335,9 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
             wxZlibOutputStream zstream_out(fstream_out, compress_level, output_flag);
             CPPUNIT_ASSERT_MESSAGE("Could not create the output stream", zstream_out.IsOk());
 
             wxZlibOutputStream zstream_out(fstream_out, compress_level, output_flag);
             CPPUNIT_ASSERT_MESSAGE("Could not create the output stream", zstream_out.IsOk());
 
+            if (buf)
+                zstream_out.SetDictionary(*buf);
+
             // Next: Compress some data so the file is containing something.
             zstream_out.Write(GetDataBuffer(), DATABUFFER_SIZE);
         }
             // Next: Compress some data so the file is containing something.
             zstream_out.Write(GetDataBuffer(), DATABUFFER_SIZE);
         }
@@ -336,6 +354,9 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
         wxZlibInputStream zstream_in(fstream_in, input_flag);
         CPPUNIT_ASSERT_MESSAGE("Could not create the input stream", zstream_in.IsOk());
 
         wxZlibInputStream zstream_in(fstream_in, input_flag);
         CPPUNIT_ASSERT_MESSAGE("Could not create the input stream", zstream_in.IsOk());
 
+        if (buf)
+            zstream_in.SetDictionary(*buf);
+
         // Next: Check char per char if the returned data is valid.
         const char *pbuf = GetDataBuffer();
         for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
         // Next: Check char per char if the returned data is valid.
         const char *pbuf = GetDataBuffer();
         for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
@@ -356,10 +377,10 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
     if (fail_pos != DATABUFFER_SIZE || !bWasEOF)
     {
         wxString msg;
     if (fail_pos != DATABUFFER_SIZE || !bWasEOF)
     {
         wxString msg;
-        msg << _T("Wrong data item at pos ") << fail_pos
-            << _T(" (Org_val ") << GetDataBuffer()[fail_pos]
-            << _T(" != Zlib_val ") << last_value
-            << _T("), with compression level ") << compress_level;
+        msg << wxT("Wrong data item at pos ") << fail_pos
+            << wxT(" (Org_val ") << GetDataBuffer()[fail_pos]
+            << wxT(" != Zlib_val ") << last_value
+            << wxT("), with compression level ") << compress_level;
         CPPUNIT_FAIL(string(msg.mb_str()));
     }
 }
         CPPUNIT_FAIL(string(msg.mb_str()));
     }
 }
@@ -379,18 +400,24 @@ void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char
         break;
     case wxZLIB_ZLIB:
         if (!(data_size >= 1 && data[0] == 0x78))
         break;
     case wxZLIB_ZLIB:
         if (!(data_size >= 1 && data[0] == 0x78))
-            wxLogError(_T("zlib data seems to not be zlib data!"));
+        {
+            wxLogError(wxT("zlib data seems to not be zlib data!"));
+        }
         break;
     case wxZLIB_GZIP:
         if (!(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
         break;
     case wxZLIB_GZIP:
         if (!(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
-            wxLogError(_T("gzip data seems to not be gzip data!"));
+        {
+            wxLogError(wxT("gzip data seems to not be gzip data!"));
+        }
         break;
     case wxZLIB_AUTO:
         if (!(data_size >= 1 && data[0] == 0x78) ||
             !(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
         break;
     case wxZLIB_AUTO:
         if (!(data_size >= 1 && data[0] == 0x78) ||
             !(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
-            wxLogError(_T("Data seems to not be zlib or gzip data!"));
+        {
+            wxLogError(wxT("Data seems to not be zlib or gzip data!"));
+        }
     default:
     default:
-        wxLogError(_T("Unknown flag, skipping quick test."));
+        wxLogError(wxT("Unknown flag, skipping quick test."));
     };
 
     // Creat the needed streams.
     };
 
     // Creat the needed streams.
@@ -436,8 +463,8 @@ void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char
 
                 // Check if we are in an infinite loop by multiplying value_size
                 // by 5 to have a *much* bigger range then the real range.
 
                 // Check if we are in an infinite loop by multiplying value_size
                 // by 5 to have a *much* bigger range then the real range.
-                // Note: Incase you ask your self, why 5, the answer is no reason...
-                //       it is not to big and not to small a size, nothing more
+                // Note: In case you ask yourself, why 5, the answer is no reason...
+                //       it is not too big and not to small a size, nothing more
                 //       nothing less to it.
                 if (i > (value_size*5))
                 {
                 //       nothing less to it.
                 if (i > (value_size*5))
                 {
@@ -501,25 +528,25 @@ void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int fl
         memstream_out.CopyTo(data, size);
     }
 
         memstream_out.CopyTo(data, size);
     }
 
-    out << _T("void zlibStream::Decompress_wxXXXData()") << _T("\n");
-    out << _T("{") << _T("\n") << _T("    const unsigned char data[] = {");
+    out << wxT("void zlibStream::Decompress_wxXXXData()") << wxT("\n");
+    out << wxT("{") << wxT("\n") << wxT("    const unsigned char data[] = {");
 
     size_t i;
     for (i = 0; i < size; i++)
     {
         if (i+1 != size)
 
     size_t i;
     for (i = 0; i < size; i++)
     {
         if (i+1 != size)
-            out << wxString::Format(_T("%d,"), data[i]);
+            out << wxString::Format(wxT("%d,"), data[i]);
         else
         else
-            out << wxString::Format(_T("%d"), data[i]);
+            out << wxString::Format(wxT("%d"), data[i]);
     }
     delete [] data;
 
     }
     delete [] data;
 
-    out << _T("};") << _T("\n");
-    out << _T("    const char *value = \"") << wxString(buf, wxConvUTF8) << _T("\";") << _T("\n");
-    out << _T("    const size_t data_size = sizeof(data);") << _T("\n");
-    out << _T("    const size_t value_size = strlen(value);") << _T("\n");
-    out << _T("    doDecompress_ExternalData(data, value, data_size, value_size);") << _T("\n");
-    out << _T("}") << _T("\n");
+    out << wxT("};") << wxT("\n");
+    out << wxT("    const char *value = \"") << wxString(buf, wxConvUTF8) << wxT("\";") << wxT("\n");
+    out << wxT("    const size_t data_size = sizeof(data);") << wxT("\n");
+    out << wxT("    const size_t value_size = strlen(value);") << wxT("\n");
+    out << wxT("    doDecompress_ExternalData(data, value, data_size, value_size);") << wxT("\n");
+    out << wxT("}") << wxT("\n");
 }
 
 
 }