]> git.saurik.com Git - wxWidgets.git/commitdiff
applied rest of streams test suite patch
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 18 Apr 2004 19:26:20 +0000 (19:26 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 18 Apr 2004 19:26:20 +0000 (19:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26863 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/streams/bstream.h
tests/streams/ffilestream.cpp
tests/streams/zlibstream.cpp
tests/test.bkl
tests/test.dsp

index fc196822b283b05009be448d0458c9edab2adfbe..d2c83c7c4928b33c30b392a0d8c74e1ac5e8fa11 100644 (file)
@@ -42,7 +42,12 @@ TEST_OBJECTS =  \
        test_regex.o \
        test_filesys.o \
        test_arrays.o \
        test_regex.o \
        test_filesys.o \
        test_arrays.o \
-       test_longlong.o
+       test_longlong.o \
+       test_bstream.o \
+       test_ffilestream.o \
+       test_filestream.o \
+       test_memstream.o \
+       test_zlibstream.o
 
 ### Conditionally set variables: ###
 
 
 ### Conditionally set variables: ###
 
@@ -126,6 +131,21 @@ test_arrays.o: $(srcdir)/arrays/arrays.cpp
 test_longlong.o: $(srcdir)/longlong/longlong.cpp
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
 
 test_longlong.o: $(srcdir)/longlong/longlong.cpp
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
 
+test_bstream.o: $(srcdir)/streams/bstream.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
+test_ffilestream.o: $(srcdir)/streams/ffilestream.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
+test_filestream.o: $(srcdir)/streams/filestream.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
+test_memstream.o: $(srcdir)/streams/memstream.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
+test_zlibstream.o: $(srcdir)/streams/zlibstream.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
 
 # Include dependency info, if present:
 @IF_GNU_MAKE@-include .deps/*.d
 
 # Include dependency info, if present:
 @IF_GNU_MAKE@-include .deps/*.d
index 26a2defa743e0b42a42954a13f567c9d96389e02..0ce0217ae33fa55f1dc314d1500bd9e48ec9abfd 100644 (file)
@@ -36,7 +36,12 @@ TEST_OBJECTS =  \
        $(OBJS)\test_regex.obj \
        $(OBJS)\test_filesys.obj \
        $(OBJS)\test_arrays.obj \
        $(OBJS)\test_regex.obj \
        $(OBJS)\test_filesys.obj \
        $(OBJS)\test_arrays.obj \
-       $(OBJS)\test_longlong.obj
+       $(OBJS)\test_longlong.obj \
+       $(OBJS)\test_bstream.obj \
+       $(OBJS)\test_ffilestream.obj \
+       $(OBJS)\test_filestream.obj \
+       $(OBJS)\test_memstream.obj \
+       $(OBJS)\test_zlibstream.obj
 
 ### Conditionally set variables: ###
 
 
 ### Conditionally set variables: ###
 
@@ -176,3 +181,18 @@ $(OBJS)\test_arrays.obj: .\arrays\arrays.cpp
 
 $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
 $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_bstream.obj: .\streams\bstream.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_filestream.obj: .\streams\filestream.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_memstream.obj: .\streams\memstream.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_zlibstream.obj: .\streams\zlibstream.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
index c4f0d334219afee26c0e81178f8d4cf69057105c..d04789b79608c06183c6388f7e53af23b4bb58cf 100644 (file)
@@ -27,7 +27,12 @@ TEST_OBJECTS =  \
        $(OBJS)\test_regex.o \
        $(OBJS)\test_filesys.o \
        $(OBJS)\test_arrays.o \
        $(OBJS)\test_regex.o \
        $(OBJS)\test_filesys.o \
        $(OBJS)\test_arrays.o \
-       $(OBJS)\test_longlong.o
+       $(OBJS)\test_longlong.o \
+       $(OBJS)\test_bstream.o \
+       $(OBJS)\test_ffilestream.o \
+       $(OBJS)\test_filestream.o \
+       $(OBJS)\test_memstream.o \
+       $(OBJS)\test_zlibstream.o
 
 ### Conditionally set variables: ###
 
 
 ### Conditionally set variables: ###
 
@@ -171,4 +176,19 @@ $(OBJS)\test_arrays.o: ./arrays/arrays.cpp
 $(OBJS)\test_longlong.o: ./longlong/longlong.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
 $(OBJS)\test_longlong.o: ./longlong/longlong.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_bstream.o: ./streams/bstream.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_ffilestream.o: ./streams/ffilestream.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_filestream.o: ./streams/filestream.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_memstream.o: ./streams/memstream.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_zlibstream.o: ./streams/zlibstream.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
 .PHONY: all clean
 .PHONY: all clean
index 9d5f4aab7ef1a3fa6bd2d2a9d67026626f8b257a..465cc7be8bc6f6d3ca0d3bc28a74e1005580410c 100644 (file)
@@ -29,7 +29,12 @@ TEST_OBJECTS =  \
        $(OBJS)\test_regex.obj \
        $(OBJS)\test_filesys.obj \
        $(OBJS)\test_arrays.obj \
        $(OBJS)\test_regex.obj \
        $(OBJS)\test_filesys.obj \
        $(OBJS)\test_arrays.obj \
-       $(OBJS)\test_longlong.obj
+       $(OBJS)\test_longlong.obj \
+       $(OBJS)\test_bstream.obj \
+       $(OBJS)\test_ffilestream.obj \
+       $(OBJS)\test_filestream.obj \
+       $(OBJS)\test_memstream.obj \
+       $(OBJS)\test_zlibstream.obj
 
 ### Conditionally set variables: ###
 
 
 ### Conditionally set variables: ###
 
@@ -232,3 +237,18 @@ $(OBJS)\test_arrays.obj: .\arrays\arrays.cpp
 
 $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
 $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_bstream.obj: .\streams\bstream.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_filestream.obj: .\streams\filestream.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_memstream.obj: .\streams\memstream.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
+$(OBJS)\test_zlibstream.obj: .\streams\zlibstream.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
index b5d6840b21968a17ada7ef8b407d6b0e889eeb5b..be5b8fcc95a77cb855c6172d30e7d7ef72ba5a93 100644 (file)
@@ -177,7 +177,12 @@ TEST_OBJECTS =  &
        $(OBJS)\test_regex.obj &
        $(OBJS)\test_filesys.obj &
        $(OBJS)\test_arrays.obj &
        $(OBJS)\test_regex.obj &
        $(OBJS)\test_filesys.obj &
        $(OBJS)\test_arrays.obj &
-       $(OBJS)\test_longlong.obj
+       $(OBJS)\test_longlong.obj &
+       $(OBJS)\test_bstream.obj &
+       $(OBJS)\test_ffilestream.obj &
+       $(OBJS)\test_filestream.obj &
+       $(OBJS)\test_memstream.obj &
+       $(OBJS)\test_zlibstream.obj
 
 
 all : $(OBJS)
 
 
 all : $(OBJS)
@@ -226,3 +231,18 @@ $(OBJS)\test_arrays.obj :  .AUTODEPEND .\arrays\arrays.cpp
 
 $(OBJS)\test_longlong.obj :  .AUTODEPEND .\longlong\longlong.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
 $(OBJS)\test_longlong.obj :  .AUTODEPEND .\longlong\longlong.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_bstream.obj :  .AUTODEPEND .\streams\bstream.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_ffilestream.obj :  .AUTODEPEND .\streams\ffilestream.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_filestream.obj :  .AUTODEPEND .\streams\filestream.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_memstream.obj :  .AUTODEPEND .\streams\memstream.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_zlibstream.obj :  .AUTODEPEND .\streams\zlibstream.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
index 4d1029ac3f7bfe74265ad9309bc98d4e88c93e92..3505fc33aadbb86786f2026a313d01134ce7b750 100644 (file)
@@ -60,6 +60,7 @@ public:
         :m_bSimpleTellITest(false),
          m_bSimpleTellOTest(false),
          m_bSeekInvalidBeyondEnd(true),
         :m_bSimpleTellITest(false),
          m_bSimpleTellOTest(false),
          m_bSeekInvalidBeyondEnd(true),
+         m_bEofAtLastRead(true),
          m_pCurrentIn(NULL),
          m_pCurrentOut(NULL)
     { /* Nothing extra */ }
          m_pCurrentIn(NULL),
          m_pCurrentOut(NULL)
     { /* Nothing extra */ }
@@ -135,18 +136,30 @@ protected:
         // Travel to the end of the stream.
         while(!stream_in.Eof())
         {
         // Travel to the end of the stream.
         while(!stream_in.Eof())
         {
-            // Double check to see if normal Eof works.
-            CPPUNIT_ASSERT_MESSAGE("Eof() doesn't return true when IsOk returns false!", stream_in.IsOk());
             // Read, we move one byte along.
             (void)stream_in.GetC();
             // Read, we move one byte along.
             (void)stream_in.GetC();
+#if 0
+            // EOF behaviour is different in streams, disabled (for now?)
+
+            if (m_bEofAtLastRead)
+                // EOF should only occure after the last successful get.
+                CPPUNIT_ASSERT_MESSAGE("Eof is detected too late.", !(stream_in.LastRead() != 1 && stream_in.Eof()));
+            else
+                // EOF should only occure after a failed get.
+                CPPUNIT_ASSERT_MESSAGE("Eof is detected too soon.", !(stream_in.LastRead() == 1 && stream_in.Eof()));
+#endif
         }
 
         }
 
+        // Check EOF stream state.
+        CPPUNIT_ASSERT_MESSAGE("EOF is not EOF?", stream_in.Eof());        
+
         // Ok we found the end, lets see if we can go past it.
         for (size_t i = 0; i < 100; i++)
             (void)stream_in.GetC();
 
         // Check for EOF correctness.
         CPPUNIT_ASSERT_MESSAGE("EOF is wrong when we read past EOF!", stream_in.Eof());
         // Ok we found the end, lets see if we can go past it.
         for (size_t i = 0; i < 100; i++)
             (void)stream_in.GetC();
 
         // Check for EOF correctness.
         CPPUNIT_ASSERT_MESSAGE("EOF is wrong when we read past EOF!", stream_in.Eof());
+        CPPUNIT_ASSERT_MESSAGE("Last error is not EOF while stream_in.Eof() is true", stream_in.GetLastError() == wxSTREAM_EOF);
     }
 
     // Just try to perform a LastRead() on the input stream.
     }
 
     // Just try to perform a LastRead() on the input stream.
@@ -352,7 +365,8 @@ protected:
                                 // Default false.
     bool m_bSeekInvalidBeyondEnd; // if true a SeekI|O beyond the end of the stream should return wxInvalidOffset
                                   // Default true.
                                 // Default false.
     bool m_bSeekInvalidBeyondEnd; // if true a SeekI|O beyond the end of the stream should return wxInvalidOffset
                                   // Default true.
-
+    bool m_bEofAtLastRead;      // Does EOF occure at the moment the last byte is read or when read past the last byte.
+                                // Default true.
 protected:
     TStreamIn &CreateInStream()
     { 
 protected:
     TStreamIn &CreateInStream()
     { 
index 66a4cd73c7a9ef0b2dce8b16e066f7cdd91a503c..de181e5d5753440a7dd77d2034f3239a57cb3b20 100644 (file)
@@ -85,6 +85,7 @@ private:
 ffileStream::ffileStream()
 {
     m_bSeekInvalidBeyondEnd = false;
 ffileStream::ffileStream()
 {
     m_bSeekInvalidBeyondEnd = false;
+    m_bEofAtLastRead = false;
 }
 
 ffileStream::~ffileStream()
 }
 
 ffileStream::~ffileStream()
index fa5779354b522673280ea94fe3bde5b7b77cf33b..d7c0424d156e0ab42e03f676447011aebf028686 100644 (file)
@@ -29,6 +29,8 @@
 #include "wx/wfstream.h"
 #include "wx/mstream.h"
 
 #include "wx/wfstream.h"
 #include "wx/mstream.h"
 
+#include "wx/txtstrm.h"
+
 #include "bstream.h"
 
 using namespace std;
 #include "bstream.h"
 
 using namespace std;
@@ -86,6 +88,9 @@ public:
         WXTEST_WITH_GZIP_CONDITION(TestStream_ZLibGZip);
         CPPUNIT_TEST(Decompress_BadData);
         CPPUNIT_TEST(Decompress_wx24Data);
         WXTEST_WITH_GZIP_CONDITION(TestStream_ZLibGZip);
         CPPUNIT_TEST(Decompress_BadData);
         CPPUNIT_TEST(Decompress_wx24Data);
+        CPPUNIT_TEST(Decompress_wx251_zlib114_Data_NoHeader);
+        CPPUNIT_TEST(Decompress_wx251_zlib114_Data_ZLib);
+        WXTEST_WITH_GZIP_CONDITION(Decompress_gzip135Data);
     CPPUNIT_TEST_SUITE_END();
 
 protected:
     CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -105,14 +110,19 @@ protected:
     void TestStream_ZLibGZip();
     // Try to decompress bad data.
     void Decompress_BadData();
     void TestStream_ZLibGZip();
     // Try to decompress bad data.
     void Decompress_BadData();
-    // Decompress a data file created with wx 2.4.
+    // Decompress data that was compress by an external app. 
+    // (like test wx 2.4.2, 2.5.1 and gzip data)
     // Note: This test is limited in testing range!
     void Decompress_wx24Data();
     // Note: This test is limited in testing range!
     void Decompress_wx24Data();
+    void Decompress_wx251_zlib114_Data_NoHeader();
+    void Decompress_wx251_zlib114_Data_ZLib();
+    void Decompress_gzip135Data();    
 
 
-private:
+private:    
     const char *GetDataBuffer();
     const unsigned char *GetCompressedData();
     void doTestStreamData(int input_flag, int output_flag, int compress_level);
     const char *GetDataBuffer();
     const unsigned char *GetCompressedData();
     void doTestStreamData(int input_flag, int output_flag, int compress_level);
+    void doDecompress_ExternalData(const unsigned char *data, const char *value, size_t data_size, size_t value_size, int flag = wxZLIB_AUTO);
 
 private:
     // Implement base class functions.
 
 private:
     // Implement base class functions.
@@ -121,6 +131,10 @@ private:
     virtual void DoDeleteInStream();
     virtual void DoDeleteOutStream();
 
     virtual void DoDeleteInStream();
     virtual void DoDeleteOutStream();
 
+    // Helper that can be used to create new wx compatibility tests... 
+    // Otherwise not used by the tests.
+    void genExtTestData(wxTextOutputStream &out, const char *buf, int flag);
+
 private:
     char            m_DataBuffer[DATABUFFER_SIZE];
     size_t          m_SizeCompressedData;
 private:
     char            m_DataBuffer[DATABUFFER_SIZE];
     size_t          m_SizeCompressedData;
@@ -144,6 +158,16 @@ zlibStream::zlibStream()
     // Set extra base config settings.
     m_bSimpleTellITest = true;
     m_bSimpleTellOTest = true;
     // 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"));
+        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);
+        genExtTestData(out, "zlib data created with wxWidgets 2.5.x [March 27], wxZLIB_ZLIB, zlib 1.1.4", wxZLIB_ZLIB);
+    }
+*/
 }
 
 zlibStream::~zlibStream()
 }
 
 zlibStream::~zlibStream()
@@ -209,8 +233,8 @@ void zlibStream::TestStream_ZLibGZip()
 {
     // Only use default compression level, as this test is 
     // for testing if the streams can determine the stream type info them self...
 {
     // Only use default compression level, as this test is 
     // for testing if the streams can determine the stream type info them self...
-    doTestStreamData(wxZLIB_ZLIB|wxZLIB_GZIP, wxZLIB_ZLIB, wxZ_DEFAULT_COMPRESSION);
-    doTestStreamData(wxZLIB_ZLIB|wxZLIB_GZIP, wxZLIB_GZIP, wxZ_DEFAULT_COMPRESSION);
+    doTestStreamData(wxZLIB_AUTO, wxZLIB_ZLIB, wxZ_DEFAULT_COMPRESSION);
+    doTestStreamData(wxZLIB_AUTO, wxZLIB_GZIP, wxZ_DEFAULT_COMPRESSION);
 }
 
 void zlibStream::Decompress_BadData()
 }
 
 void zlibStream::Decompress_BadData()
@@ -239,50 +263,42 @@ void zlibStream::Decompress_wx24Data()
     const char *wx24_value = "Hello world";
     // Size of the value and date items.
     const size_t data_size = sizeof(wx24_data);
     const char *wx24_value = "Hello world";
     // Size of the value and date items.
     const size_t data_size = sizeof(wx24_data);
-    const size_t value_size = strlen(wx24_value);
+    const size_t value_size = strlen(wx24_value) + 1; // +1 because the wx24 app also did this.
 
 
-    const unsigned char *buf = GetCompressedData();
-    m_pTmpMemInStream = new wxMemoryInputStream(buf, m_SizeCompressedData);
-
-    wxMemoryInputStream memstream_in(wx24_data, data_size);
-    CPPUNIT_ASSERT(memstream_in.IsOk());
-    wxZlibInputStream zstream_in(memstream_in);
-    CPPUNIT_ASSERT(zstream_in.IsOk());
+    // Perform a generic data test on the data.
+    doDecompress_ExternalData(wx24_data, wx24_value, data_size, value_size, wxZLIB_24COMPATIBLE);
+}
 
 
-    size_t i;
-    for (i = 0; !zstream_in.Eof(); i++)
-    {
-        char last_value = zstream_in.GetC();
-        if (last_value != wx24_value[i])
-            break;
+void zlibStream::Decompress_wx251_zlib114_Data_NoHeader()
+{
+    const unsigned char data[] = {171,202,201,76,82,72,73,44,73,84,72,46,74,77,44,73,77,81,40,207,44,201,80,40,175,8,207,76,73,79,45,41,86,48,210,51,213,171,80,136,246,77,44,74,206,80,48,50,143,213,1,202,69,249,120,58,197,251,249,199,123,184,58,186,184,6,233,40,84,129,12,49,212,51,212,51,1,0,32};
+    const char *value = "zlib data created with wxWidgets 2.5.x [March 27], wxZLIB_NO_HEADER, zlib 1.1.4";
+    const size_t data_size = sizeof(data);
+    const size_t value_size = strlen(value);
+    // We need to specify wxZLIB_NO_HEADER because wxZLIB_AUTO can't find it his self.
+    doDecompress_ExternalData(data, value, data_size, value_size, wxZLIB_NO_HEADER);
+}
 
 
-        // Don't go over the end of the value buffer...
-        if (wx24_value[i] == '\0')
-        {
-            // And if we do then try to see how long the stream actually is.
-            for (/* nothing */; !zstream_in.Eof(); i++)
-            {
-                // Move one item along in the stream.
-                (void)zstream_in.GetC();
-                
-                // 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 
-                //       nothing less to it.
-                if (i > (value_size*5)) 
-                {
-                    // Note: Please make sure Input_Eof test passed.
-                    CPPUNIT_FAIL("Infinite stream detected, breaking the infinite loop");
-                    return;
-                }
-            }
+void zlibStream::Decompress_wx251_zlib114_Data_ZLib()
+{
+    const unsigned char data[] = {120,156,171,202,201,76,82,72,73,44,73,84,72,46,74,77,44,73,77,81,40,207,44,201,80,40,175,8,207,76,73,79,45,41,86,48,210,51,213,171,80,136,246,77,44,74,206,80,48,50,143,213,1,202,69,249,120,58,197,131,8,29,133,42,144,126,67,61,67,61,19,0,191,86,23,216};
+    const char *value = "zlib data created with wxWidgets 2.5.x [March 27], wxZLIB_ZLIB, zlib 1.1.4";
+    const size_t data_size = sizeof(data);
+    const size_t value_size = strlen(value);
+    doDecompress_ExternalData(data, value, data_size, value_size);
+}
 
 
-            break;
-        }
-    }
+void zlibStream::Decompress_gzip135Data()
+{
+    // Compressed data was on the command line with gzip 1.3.5.
+    const unsigned char gzip135_data[] = {31,139,8,0,177,248,112,64,4,3,115,206,207,45,40,74,45,46,78,77,81,72,73,44,73,84,72,46,74,77,44,1,114,202,51,75,50,20,220,253,66,21,210,171,50,11,20,12,245,140,245,76,185,0,1,107,16,80,44,0,0,0,0};
+    const char *gzip135_value = "Compressed data created with GNU gzip 1.3.5\n";
+    // Size of the value and date items.
+    const size_t data_size = sizeof(gzip135_data);
+    const size_t value_size = strlen(gzip135_value);
 
 
-    CPPUNIT_ASSERT_MESSAGE("Could not decompress data that was compressed with wxWidgets 2.4.x", i == (value_size + 1));
+    // Perform a generic data test on the data.
+    doDecompress_ExternalData(gzip135_data, gzip135_value, data_size, value_size);
 }
 
 const char *zlibStream::GetDataBuffer()
 }
 
 const char *zlibStream::GetDataBuffer()
@@ -294,7 +310,6 @@ const unsigned char *zlibStream::GetCompressedData()
 {
     if (!m_pCompressedData)
     {
 {
     if (!m_pCompressedData)
     {
-#if 1
         // Construct the compressed data live.
         wxMemoryOutputStream memstream_out;
         {
         // Construct the compressed data live.
         wxMemoryOutputStream memstream_out;
         {
@@ -307,13 +322,6 @@ const unsigned char *zlibStream::GetCompressedData()
         m_SizeCompressedData = memstream_out.GetSize();
         m_pCompressedData = new unsigned char[m_SizeCompressedData];
         memstream_out.CopyTo(m_pCompressedData, m_SizeCompressedData);
         m_SizeCompressedData = memstream_out.GetSize();
         m_pCompressedData = new unsigned char[m_SizeCompressedData];
         memstream_out.CopyTo(m_pCompressedData, m_SizeCompressedData);
-#else
-        // Or use recorded compressed data.
-        const unsigned char tmp[] = {120,218,51,48,52,50,54,49,53,51,183,176,52,32,142,197,0,0,3,229,10,9,0};
-        m_SizeCompressedData = sizeof(tmp);
-        m_pCompressedData = new unsigned char[m_SizeCompressedData+1];
-        memcpy(m_pCompressedData, tmp, m_SizeCompressedData);
-#endif
     }
 
     CPPUNIT_ASSERT(m_pCompressedData != NULL);    
     }
 
     CPPUNIT_ASSERT(m_pCompressedData != NULL);    
@@ -329,17 +337,17 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
     {   // Part one: Create a compressed file.
         wxFileOutputStream fstream_out(FILENAME_GZ);
         CPPUNIT_ASSERT(fstream_out.IsOk());
     {   // Part one: Create a compressed file.
         wxFileOutputStream fstream_out(FILENAME_GZ);
         CPPUNIT_ASSERT(fstream_out.IsOk());
-        wxZlibOutputStream zstream_out(fstream_out, compress_level, output_flag);
-        if (!zstream_out.IsOk())
         {
         {
-            if (output_flag == wxZLIB_GZIP)
-                CPPUNIT_FAIL("Could not create the gzip output stream. Note: gzip requires zlib 1.2+!");
-            else
-                CPPUNIT_FAIL("Could not create the output stream");
+            wxZlibOutputStream zstream_out(fstream_out, compress_level, output_flag);
+            CPPUNIT_ASSERT_MESSAGE("Could not create the output stream", zstream_out.IsOk());
+
+            // 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);
+        // Next thing is required by zlib versions pre 1.2.0.
+        if (input_flag == wxZLIB_NO_HEADER)
+            fstream_out.PutC(' ');
     }
 
     {   // Part two: Verify that the compressed data when uncompressed 
     }
 
     {   // Part two: Verify that the compressed data when uncompressed 
@@ -354,7 +362,8 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
         for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
         {
             last_value = zstream_in.GetC();
         for (fail_pos = 0; !zstream_in.Eof(); fail_pos++)
         {
             last_value = zstream_in.GetC();
-            if (last_value != pbuf[fail_pos])
+            if (zstream_in.LastRead() != 1 || 
+                last_value != pbuf[fail_pos])
                 break;
         }
 
                 break;
         }
 
@@ -373,6 +382,96 @@ void zlibStream::doTestStreamData(int input_flag, int output_flag, int compress_
     }
 }
 
     }
 }
 
+void zlibStream::doDecompress_ExternalData(const unsigned char *data, const char *value, size_t data_size, size_t value_size, int flag)
+{
+    // See that the input is ok.
+    wxASSERT(data != NULL);
+    wxASSERT(value != NULL);
+    wxASSERT(data_size > 0);
+    wxASSERT(value_size > 0);
+
+    // Quickly try to see if the data is valid.
+    switch (flag)
+    {
+    case wxZLIB_NO_HEADER:
+        break;
+    case wxZLIB_24COMPATIBLE:
+    case wxZLIB_ZLIB:
+        if (!(data_size >= 1 && data[0] == 0x78))
+            wxLogError(_T("zlib data seems to not be zlib data!"));
+        break;
+    case wxZLIB_GZIP:
+        if (!(data_size >= 2 && data[0] == 0x1F && data[1] == 0x8B))
+            wxLogError(_T("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))
+            wxLogError(_T("Data seems to not be zlib or gzip data!"));
+    default:
+        wxLogError(_T("Unknown flag, skipping quick test."));
+    };
+
+    // Creat the needed streams.
+    wxMemoryInputStream memstream_in(data, data_size);
+    CPPUNIT_ASSERT(memstream_in.IsOk());
+    wxZlibInputStream zstream_in(memstream_in, flag);
+    CPPUNIT_ASSERT(zstream_in.IsOk());
+
+    bool bValueEq = true;
+    size_t i;
+    for (i = 0; !zstream_in.Eof(); i++)
+    {
+        char last_value = zstream_in.GetC();
+
+        // First check if it is a valid read.
+        if (zstream_in.LastRead() == 1)
+        {
+            // Check the values
+            if (last_value != value[i])
+            {
+                bValueEq = false;
+                break;
+            }
+        }
+        else
+        {
+            // If the read failed and turned the stream to Eof we stop reading.
+            if (zstream_in.Eof())
+                break;
+
+            CPPUNIT_ASSERT_MESSAGE("Stream is no longer ok!", zstream_in.IsOk());
+        }
+
+        // Don't go over the end of the value buffer...
+        if (i == value_size)
+        {
+            // And if we do then try to see how long the stream actually is.
+            while (!zstream_in.Eof())
+            {
+                // Move one item along in the stream.
+                (void)zstream_in.GetC();
+                i++;
+                
+                // 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 
+                //       nothing less to it.
+                if (i > (value_size*5)) 
+                {
+                    // Note: Please make sure Input_Eof test passed.
+                    CPPUNIT_FAIL("Infinite stream detected, breaking the infinite loop");
+                    return;
+                }
+            }
+        }
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Could not decompress the compressed data, original and restored value did not match.", 
+                           i == value_size && bValueEq);
+}
+
 wxZlibInputStream *zlibStream::DoCreateInStream()    
 { 
     const unsigned char *buf = GetCompressedData();
 wxZlibInputStream *zlibStream::DoCreateInStream()    
 { 
     const unsigned char *buf = GetCompressedData();
@@ -401,6 +500,48 @@ void zlibStream::DoDeleteOutStream()
     m_pTmpMemOutStream = NULL;
 }
 
     m_pTmpMemOutStream = NULL;
 }
 
+
+void zlibStream::genExtTestData(wxTextOutputStream &out, const char *buf, int flag)
+{
+    unsigned char *data = NULL;
+    size_t size = 0;
+    
+    {   // Gen data
+        wxMemoryOutputStream memstream_out;
+        {
+            wxZlibOutputStream zstream_out(memstream_out, wxZ_DEFAULT_COMPRESSION, flag);
+            zstream_out.Write(buf, strlen(buf));
+        }
+        if (flag == wxZLIB_NO_HEADER)
+            memstream_out.PutC(' ');
+        
+        size = memstream_out.GetSize();
+        data = new unsigned char[size];
+        memstream_out.CopyTo(data, size);
+    }
+
+    out << _T("void zlibStream::Decompress_wxXXXData()") << _T("\n");
+    out << _T("{") << _T("\n") << _T("    const unsigned char data[] = {");
+    
+    size_t i;
+    for (i = 0; i < size; i++)
+    {
+        if (i+1 != size)
+            out << wxString::Format(_T("%d,"), data[i]);
+        else
+            out << wxString::Format(_T("%d"), data[i]);
+    }    
+    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");
+}
+
+
 // Register the stream sub suite, by using some stream helper macro.
 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(zlibStream)
 // Register the stream sub suite, by using some stream helper macro.
 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(zlibStream)
index 1932b0ac07edb7e2aee61eaf3257e68b892ffe6a..7819fd082c4027ce53fc8241b488453deb8d5784 100644 (file)
@@ -3,22 +3,6 @@
 
 <makefile>
 
 
 <makefile>
 
-    <!-- FIXME: temporary hack.
-         Override this on command line, e.g.
-         bakefile_gen -f autoconf -b ../../tests/*.bkl -DBUILD_STREAM_TESTS=1
-    -->
-    <set var="BUILD_STREAM_TESTS">0</set>
-
-    <set var="STREAMS_FILES">
-        <if cond="BUILD_STREAM_TESTS=='1'">
-            streams/bstream.cpp
-            streams/ffilestream.cpp
-            streams/filestream.cpp
-            streams/memstream.cpp
-            streams/zlibstream.cpp
-        </if>
-    </set>
-
     <include file="../build/bakefiles/common_samples.bkl"/>
 
     <exe id="test" template="wx_test_console"
     <include file="../build/bakefiles/common_samples.bkl"/>
 
     <exe id="test" template="wx_test_console"
             filesys/filesys.cpp
             arrays/arrays.cpp
             longlong/longlong.cpp
             filesys/filesys.cpp
             arrays/arrays.cpp
             longlong/longlong.cpp
-            $(STREAMS_FILES)
+            streams/bstream.cpp
+            streams/ffilestream.cpp
+            streams/filestream.cpp
+            streams/memstream.cpp
+            streams/zlibstream.cpp
         </sources>
         <wx-lib>base</wx-lib>
     </exe>
         </sources>
         <wx-lib>base</wx-lib>
     </exe>
index c004bd4e38547df2d66c47238455c782280bce8d..291a684bf50d46ca9ea4b4a8e9c247356d06191f 100644 (file)
@@ -439,6 +439,18 @@ SOURCE=.\arrays\arrays.cpp
 # End Source File
 # Begin Source File
 
 # End Source File
 # Begin Source File
 
+SOURCE=.\streams\bstream.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\streams\ffilestream.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\streams\filestream.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\filesys\filesys.cpp
 # End Source File
 # Begin Source File
 SOURCE=.\filesys\filesys.cpp
 # End Source File
 # Begin Source File
@@ -455,12 +467,20 @@ SOURCE=.\mbconv\main.cpp
 # End Source File
 # Begin Source File
 
 # End Source File
 # Begin Source File
 
+SOURCE=.\streams\memstream.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\regex\regex.cpp
 # End Source File
 # Begin Source File
 
 SOURCE=.\test.cpp
 # End Source File
 SOURCE=.\regex\regex.cpp
 # End Source File
 # Begin Source File
 
 SOURCE=.\test.cpp
 # End Source File
+# Begin Source File
+
+SOURCE=.\streams\zlibstream.cpp
+# End Source File
 # End Group
 # End Target
 # End Project
 # End Group
 # End Target
 # End Project