From 9cb4c8073edea87d52bd0cf88f2317ead353eec2 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 2 Sep 2012 09:14:55 -0700 Subject: Fixing ZHandle, and adding a unit test for it. --- src/ZHandle.cc | 9 +++++---- tests/test-Handles.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/ZHandle.cc b/src/ZHandle.cc index 4f216c7..aa7bde7 100644 --- a/src/ZHandle.cc +++ b/src/ZHandle.cc @@ -22,14 +22,14 @@ Balau::ZStream::ZStream(const IO & h, int level, header_t header) : m_h( } void Balau::ZStream::close() throw (GeneralException) { - if (m_in) { - free(m_in); - m_in = NULL; - } if (m_h->canWrite()) finish(); inflateEnd(&m_zin); deflateEnd(&m_zout); + if (m_in) { + free(m_in); + m_in = NULL; + } if (!m_detached) m_h->close(); m_closed = true; @@ -78,6 +78,7 @@ ssize_t Balau::ZStream::read(void * buf, size_t count) throw (GeneralException) size_t r = m_h->read(m_in, BLOCK_SIZE); if (r <= 0) return readTotal; + m_zin.avail_in = r; } Task::operationYield(); int r = inflate(&m_zin, Z_SYNC_FLUSH); diff --git a/tests/test-Handles.cc b/tests/test-Handles.cc index d2e2396..04c35fc 100644 --- a/tests/test-Handles.cc +++ b/tests/test-Handles.cc @@ -125,5 +125,35 @@ void MainTask::Do() { z->writeString("foobar\n"); } + { + IO i(new Input("tests/out.z")); + IO z(new ZStream(i)); + IO s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + + { + IO i(new Input("tests/out.gz")); + IO z(new ZStream(i, Z_BEST_COMPRESSION, ZStream::GZIP)); + IO s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + + { + IO i(new Input("tests/out.raw")); + IO z(new ZStream(i, Z_BEST_COMPRESSION, ZStream::RAW)); + IO s(new BStream(z)); + z->detach(); + s->detach(); + String f = s->readString(); + TAssert(f == "foobar"); + } + Printer::log(M_STATUS, "Test::Handles passed."); } -- cgit v1.2.3