Some more total_out fixes and tests
This commit is contained in:
parent
a58f70c140
commit
4a2fcb7859
6 changed files with 79 additions and 30 deletions
|
@ -1509,15 +1509,9 @@ extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned in
|
|||
|
||||
if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
|
||||
{
|
||||
uLong uTotalOutBefore = zi->ci.stream.total_out;
|
||||
uInt uAvailOutBefore = zi->ci.stream.avail_out;
|
||||
err=deflate(&zi->ci.stream, Z_NO_FLUSH);
|
||||
if(uTotalOutBefore > zi->ci.stream.total_out)
|
||||
{
|
||||
int bBreak = 0;
|
||||
bBreak++;
|
||||
}
|
||||
|
||||
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
|
||||
zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1571,7 +1565,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
|
|||
{
|
||||
while (err==ZIP_OK)
|
||||
{
|
||||
uLong uTotalOutBefore;
|
||||
uLong uAvailOutBefore;
|
||||
if (zi->ci.stream.avail_out == 0)
|
||||
{
|
||||
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
|
||||
|
@ -1579,9 +1573,9 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
|
|||
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
|
||||
zi->ci.stream.next_out = zi->ci.buffered_data;
|
||||
}
|
||||
uTotalOutBefore = zi->ci.stream.total_out;
|
||||
uAvailOutBefore = zi->ci.stream.avail_out;
|
||||
err=deflate(&zi->ci.stream, Z_FINISH);
|
||||
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
|
||||
zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
|
||||
}
|
||||
}
|
||||
else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
|
||||
|
|
|
@ -43,7 +43,7 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
|||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
bool createTestFiles(const QStringList &fileNames, const QString &dir)
|
||||
bool createTestFiles(const QStringList &fileNames, int size, const QString &dir)
|
||||
{
|
||||
QDir curDir;
|
||||
foreach (QString fileName, fileNames) {
|
||||
|
@ -69,8 +69,14 @@ bool createTestFiles(const QStringList &fileNames, const QString &dir)
|
|||
fileName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
QTextStream testStream(&testFile);
|
||||
testStream << "This is a test file named " << fileName << endl;
|
||||
if (size == -1) {
|
||||
QTextStream testStream(&testFile);
|
||||
testStream << "This is a test file named " << fileName << endl;
|
||||
} else {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
testFile.putChar(static_cast<char>('0' + i % 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -30,8 +30,9 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
|||
#include <QStringList>
|
||||
#include <QTextCodec>
|
||||
|
||||
extern bool createTestFiles(const QStringList &fileNames, const QString
|
||||
&dir = "tmp");
|
||||
extern bool createTestFiles(const QStringList &fileNames,
|
||||
int size = -1,
|
||||
const QString &dir = "tmp");
|
||||
extern void removeTestFiles(const QStringList &fileNames, const QString
|
||||
&dir = "tmp");
|
||||
extern bool createTestArchive(const QString &zipName,
|
||||
|
|
|
@ -139,7 +139,7 @@ void TestJlCompress::compressDir()
|
|||
if (!curDir.remove(zipName))
|
||||
QFAIL("Can't remove zip file");
|
||||
}
|
||||
if (!createTestFiles(fileNames, "compressDir_tmp")) {
|
||||
if (!createTestFiles(fileNames, -1, "compressDir_tmp")) {
|
||||
QFAIL("Can't create test files");
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
|
@ -43,20 +43,24 @@ void TestQuaZipFile::zipUnzip_data()
|
|||
QTest::addColumn<QByteArray>("fileNameCodec");
|
||||
QTest::addColumn<QByteArray>("password");
|
||||
QTest::addColumn<bool>("zip64");
|
||||
QTest::addColumn<int>("size");
|
||||
QTest::newRow("simple") << "simple.zip" << (
|
||||
QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< QByteArray() << QByteArray() << false;
|
||||
<< QByteArray() << QByteArray() << false << -1;
|
||||
QTest::newRow("Cyrillic") << "cyrillic.zip" << (
|
||||
QStringList()
|
||||
<< QString::fromUtf8("русское имя файла с пробелами.txt"))
|
||||
<< QByteArray("IBM866") << QByteArray() << false;
|
||||
<< QByteArray("IBM866") << QByteArray() << false << -1;
|
||||
QTest::newRow("password") << "password.zip" << (
|
||||
QStringList() << "test.txt")
|
||||
<< QByteArray() << QByteArray("PassPass") << false;
|
||||
<< QByteArray() << QByteArray("PassPass") << false << -1;
|
||||
QTest::newRow("zip64") << "zip64.zip" << (
|
||||
QStringList() << "test64.txt")
|
||||
<< QByteArray() << QByteArray() << true;
|
||||
<< QByteArray() << QByteArray() << true << -1;
|
||||
QTest::newRow("large enough to flush") << "flush.zip" << (
|
||||
QStringList() << "flush.txt")
|
||||
<< QByteArray() << QByteArray() << true << 65536 * 2;
|
||||
}
|
||||
|
||||
void TestQuaZipFile::zipUnzip()
|
||||
|
@ -66,13 +70,14 @@ void TestQuaZipFile::zipUnzip()
|
|||
QFETCH(QByteArray, fileNameCodec);
|
||||
QFETCH(QByteArray, password);
|
||||
QFETCH(bool, zip64);
|
||||
QFETCH(int, size);
|
||||
QFile testFile(zipName);
|
||||
if (testFile.exists()) {
|
||||
if (!testFile.remove()) {
|
||||
QFAIL("Couldn't remove existing archive to create a new one");
|
||||
}
|
||||
}
|
||||
if (!createTestFiles(fileNames)) {
|
||||
if (!createTestFiles(fileNames, size)) {
|
||||
QFAIL("Couldn't create test files for zipping");
|
||||
}
|
||||
QuaZip testZip(&testFile);
|
||||
|
@ -158,17 +163,21 @@ void TestQuaZipFile::bytesAvailable_data()
|
|||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::addColumn<int>("size");
|
||||
QTest::newRow("simple") << "test.zip" << (
|
||||
QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt");
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt") << -1;
|
||||
QTest::newRow("large enough to flush")
|
||||
<< "flush.zip" << (QStringList() << "test.txt") << 65536 * 4;
|
||||
}
|
||||
|
||||
void TestQuaZipFile::bytesAvailable()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(int, size);
|
||||
QDir curDir;
|
||||
if (!createTestFiles(fileNames)) {
|
||||
if (!createTestFiles(fileNames, size)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
if (!JlCompress::compressDir(zipName, "tmp")) {
|
||||
|
@ -202,8 +211,9 @@ void TestQuaZipFile::atEnd()
|
|||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(int, size);
|
||||
QDir curDir;
|
||||
if (!createTestFiles(fileNames)) {
|
||||
if (!createTestFiles(fileNames, size)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
if (!JlCompress::compressDir(zipName, "tmp")) {
|
||||
|
@ -228,17 +238,18 @@ void TestQuaZipFile::atEnd()
|
|||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestQuaZipFile::pos_data()
|
||||
void TestQuaZipFile::posRead_data()
|
||||
{
|
||||
bytesAvailable_data();
|
||||
}
|
||||
|
||||
void TestQuaZipFile::pos()
|
||||
void TestQuaZipFile::posRead()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(int, size);
|
||||
QDir curDir;
|
||||
if (!createTestFiles(fileNames)) {
|
||||
if (!createTestFiles(fileNames, size)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
if (!JlCompress::compressDir(zipName, "tmp")) {
|
||||
|
@ -263,6 +274,41 @@ void TestQuaZipFile::pos()
|
|||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestQuaZipFile::posWrite_data()
|
||||
{
|
||||
posRead_data();
|
||||
}
|
||||
|
||||
void TestQuaZipFile::posWrite()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(int, size);
|
||||
if (size == -1)
|
||||
size = 20;
|
||||
QDir curDir;
|
||||
QuaZip testZip(zipName);
|
||||
QVERIFY(testZip.open(QuaZip::mdCreate));
|
||||
foreach (QString fileName, fileNames) {
|
||||
QuaZipFile zipFile(&testZip);
|
||||
QVERIFY(zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileName)));
|
||||
QCOMPARE(zipFile.pos(), (qint64) 0);
|
||||
zipFile.putChar('0');
|
||||
QCOMPARE(zipFile.pos(), (qint64) 1);
|
||||
QByteArray buffer(size / 2 - 1, '\0');
|
||||
for (int i = 0; i < buffer.size(); ++i)
|
||||
buffer[i] = static_cast<char>(qrand());
|
||||
zipFile.write(buffer);
|
||||
QCOMPARE(zipFile.pos(), size / 2);
|
||||
for (int i = 0; i < size - size / 2; ++i) {
|
||||
zipFile.putChar(static_cast<char>(qrand()));
|
||||
}
|
||||
QCOMPARE(zipFile.pos(), size);
|
||||
}
|
||||
testZip.close();
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestQuaZipFile::getZip()
|
||||
{
|
||||
QuaZip testZip;
|
||||
|
|
|
@ -37,8 +37,10 @@ private slots:
|
|||
void bytesAvailable();
|
||||
void atEnd_data();
|
||||
void atEnd();
|
||||
void pos_data();
|
||||
void pos();
|
||||
void posRead_data();
|
||||
void posRead();
|
||||
void posWrite_data();
|
||||
void posWrite();
|
||||
void getZip();
|
||||
void setZipName();
|
||||
void getFileInfo();
|
||||
|
|
Loading…
Reference in a new issue