X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/698dd55ced6ca66f67acd2bb35ec9e6caf717249..b5fe7ca67bf3121959a0b5a59afd00c1708f2f03:/tests/streams/zlibstream.cpp?ds=sidebyside diff --git a/tests/streams/zlibstream.cpp b/tests/streams/zlibstream.cpp index 8c3eae40c3..58b3c3b34e 100644 --- a/tests/streams/zlibstream.cpp +++ b/tests/streams/zlibstream.cpp @@ -23,8 +23,8 @@ #include "wx/zstream.h" #include "wx/wfstream.h" #include "wx/mstream.h" - #include "wx/txtstrm.h" +#include "wx/buffer.h" #include "bstream.h" @@ -55,6 +55,7 @@ public: CPPUNIT_TEST(Input_Read); CPPUNIT_TEST(Input_Eof); CPPUNIT_TEST(Input_LastRead); + CPPUNIT_TEST(Input_CanRead); CPPUNIT_TEST_FAIL(Input_SeekI); CPPUNIT_TEST(Input_TellI); CPPUNIT_TEST(Input_Peek); @@ -71,6 +72,7 @@ public: 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); @@ -79,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_Dictionary); WXTEST_WITH_GZIP_CONDITION(TestStream_ZLibGZip); CPPUNIT_TEST(Decompress_BadData); CPPUNIT_TEST(Decompress_wx251_zlib114_Data_NoHeader); @@ -92,6 +95,7 @@ protected: 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(); @@ -100,6 +104,7 @@ protected: 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(); @@ -113,7 +118,7 @@ protected: 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: @@ -131,6 +136,7 @@ private: 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; @@ -147,6 +153,8 @@ zlibStream::zlibStream() 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; @@ -186,6 +194,10 @@ void zlibStream::TestStream_NoHeader_BestComp() { 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() { @@ -220,6 +232,10 @@ void zlibStream::TestStream_GZip_BestComp() { 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() { @@ -306,7 +322,7 @@ const unsigned char *zlibStream::GetCompressedData() 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; @@ -319,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()); + if (buf) + zstream_out.SetDictionary(*buf); + // Next: Compress some data so the file is containing something. zstream_out.Write(GetDataBuffer(), DATABUFFER_SIZE); } @@ -335,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()); + 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++)