+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_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()
+{