diff --git a/autotests/kcompressiondevicetest.h b/autotests/kcompressiondevicetest.h --- a/autotests/kcompressiondevicetest.h +++ b/autotests/kcompressiondevicetest.h @@ -57,6 +57,8 @@ void testWriteErrorOnOpen(); void testWriteErrorOnClose(); + + void testSeekReadUncompressedBuffer(); }; #endif diff --git a/autotests/kcompressiondevicetest.cpp b/autotests/kcompressiondevicetest.cpp --- a/autotests/kcompressiondevicetest.cpp +++ b/autotests/kcompressiondevicetest.cpp @@ -18,6 +18,7 @@ */ #include "kcompressiondevicetest.h" +#include "kcompressiondevice_p.h" #include @@ -190,3 +191,29 @@ // THEN QCOMPARE(int(dev.error()), int(QFileDevice::WriteError)); } + +void KCompressionDeviceTest::testSeekReadUncompressedBuffer() +{ + const int dataSize = BUFFER_SIZE + BUFFER_SIZE / 2; + QByteArray ba(dataSize, 0); + + // all data is zero except after BUFFER_SIZE that it's 0 to 9 + for (int i = 0; i < 10; ++i) { + ba[BUFFER_SIZE + i] = i; + } + + QBuffer b; + b.setData(ba); + QVERIFY(b.open(QIODevice::ReadOnly)); + + KCompressionDevice kcd(&b, false, KCompressionDevice::GZip); + QVERIFY(kcd.open(QIODevice::ReadOnly)); + QVERIFY(kcd.seek(BUFFER_SIZE)); + + // the 10 bytes after BUFFER_SIZE should be 0 to 9 + const QByteArray kcdData = kcd.read(10); + QCOMPARE(kcdData.size(), 10); + for (int i = 0; i < kcdData.size(); ++i) { + QCOMPARE(kcdData[i], i); + } +} diff --git a/src/kcompressiondevice.cpp b/src/kcompressiondevice.cpp --- a/src/kcompressiondevice.cpp +++ b/src/kcompressiondevice.cpp @@ -18,6 +18,7 @@ */ #include "kcompressiondevice.h" +#include "kcompressiondevice_p.h" #include "loggingcategory.h" #include #include "kfilterbase.h" @@ -36,8 +37,6 @@ #include "kxzfilter.h" #endif -#define BUFFER_SIZE 8*1024 - #include class KCompressionDevicePrivate diff --git a/src/kcompressiondevice_p.h b/src/kcompressiondevice_p.h new file mode 100644 --- /dev/null +++ b/src/kcompressiondevice_p.h @@ -0,0 +1,24 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 David Faure + Copyright (C) 2011 Mario Bensi + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef __kcompressiondevice_p_h +#define __kcompressiondevice_p_h + +#define BUFFER_SIZE 8*1024 + +#endif