mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 05:29:41 +01:00
Zip: merge Zip64 support from develop
This commit is contained in:
@@ -4,19 +4,23 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CompressTest.h"
|
||||
#include "ZipTest.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Zip/Compress.h"
|
||||
#include "Poco/Zip/ZipManipulator.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#undef min
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace Poco::Zip;
|
||||
@@ -35,7 +39,7 @@ CompressTest::~CompressTest()
|
||||
void CompressTest::testSingleFile()
|
||||
{
|
||||
std::ofstream out("appinf.zip", std::ios::binary);
|
||||
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
|
||||
Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
|
||||
Compress c(out, true);
|
||||
c.addFile(theFile, theFile.getFileName());
|
||||
ZipArchive a(c.close());
|
||||
@@ -70,14 +74,14 @@ void CompressTest::testManipulator()
|
||||
{
|
||||
{
|
||||
std::ofstream out("appinf.zip", std::ios::binary);
|
||||
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
|
||||
Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
|
||||
Compress c(out, true);
|
||||
c.addFile(theFile, theFile.getFileName());
|
||||
ZipArchive a(c.close());
|
||||
}
|
||||
ZipManipulator zm("appinf.zip", true);
|
||||
zm.renameFile("test.zip", "renamedtest.zip");
|
||||
zm.addFile("doc/othertest.zip", ZipTest::getTestFile("test.zip"));
|
||||
zm.addFile("doc/othertest.zip", ZipTest::getTestFile("data", "test.zip"));
|
||||
ZipArchive archive=zm.commit();
|
||||
assert (archive.findHeader("doc/othertest.zip") != archive.headerEnd());
|
||||
}
|
||||
@@ -87,14 +91,14 @@ void CompressTest::testManipulatorDel()
|
||||
{
|
||||
{
|
||||
std::ofstream out("appinf.zip", std::ios::binary);
|
||||
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
|
||||
Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
|
||||
Compress c(out, true);
|
||||
c.addFile(theFile, theFile.getFileName());
|
||||
ZipArchive a(c.close());
|
||||
}
|
||||
ZipManipulator zm("appinf.zip", true);
|
||||
zm.deleteFile("test.zip");
|
||||
zm.addFile("doc/data.zip", ZipTest::getTestFile("data.zip"));
|
||||
zm.addFile("doc/data.zip", ZipTest::getTestFile("data", "data.zip"));
|
||||
ZipArchive archive=zm.commit();
|
||||
assert (archive.findHeader("test.zip") == archive.headerEnd());
|
||||
assert (archive.findHeader("doc/data.zip") != archive.headerEnd());
|
||||
@@ -105,13 +109,13 @@ void CompressTest::testManipulatorReplace()
|
||||
{
|
||||
{
|
||||
std::ofstream out("appinf.zip", std::ios::binary);
|
||||
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
|
||||
Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
|
||||
Compress c(out, true);
|
||||
c.addFile(theFile, theFile.getFileName());
|
||||
ZipArchive a(c.close());
|
||||
}
|
||||
ZipManipulator zm("appinf.zip", true);
|
||||
zm.replaceFile("test.zip", ZipTest::getTestFile("doc.zip"));
|
||||
zm.replaceFile("test.zip", ZipTest::getTestFile("data", "doc.zip"));
|
||||
|
||||
ZipArchive archive=zm.commit();
|
||||
assert (archive.findHeader("test.zip") != archive.headerEnd());
|
||||
@@ -123,7 +127,7 @@ void CompressTest::testSetZipComment()
|
||||
{
|
||||
std::string comment("Testing...123...");
|
||||
std::ofstream out("comment.zip", std::ios::binary);
|
||||
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
|
||||
Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
|
||||
Compress c(out, true);
|
||||
c.addFile(theFile, theFile.getFileName());
|
||||
c.setZipComment(comment);
|
||||
@@ -132,6 +136,60 @@ void CompressTest::testSetZipComment()
|
||||
}
|
||||
|
||||
|
||||
void CompressTest::createDataFile(const std::string& path, Poco::UInt64 size)
|
||||
{
|
||||
std::ofstream out(path.c_str(), std::ios::binary | std::ios::trunc);
|
||||
assert( ! out.fail() );
|
||||
Poco::Buffer<char> buffer(MB);
|
||||
for(int i = 0; size != 0; i++) {
|
||||
std::memset(buffer.begin(), i, buffer.size());
|
||||
Poco::UInt64 bytesToWrite = std::min(size, static_cast<Poco::UInt64>(buffer.size()));
|
||||
out.write(buffer.begin(), bytesToWrite);
|
||||
assert( ! out.fail() );
|
||||
size -= bytesToWrite;
|
||||
}
|
||||
out.flush();
|
||||
assert( ! out.fail() );
|
||||
out.close();
|
||||
assert( ! out.fail() );
|
||||
}
|
||||
|
||||
|
||||
void CompressTest::testZip64()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
std::map<std::string, Poco::UInt64> files;
|
||||
files["data1.bin"] = static_cast<Poco::UInt64>(KB)*4096+1;
|
||||
files["data2.bin"] = static_cast<Poco::UInt64>(KB)*16;
|
||||
files["data3.bin"] = static_cast<Poco::UInt64>(KB)*4096-1;
|
||||
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
std::cout << '\t' << "createDataFile(" << it->first << ", " << it->second << ");" << std::endl;
|
||||
createDataFile(it->first, it->second);
|
||||
}
|
||||
std::ofstream out("zip64.zip", std::ios::binary | std::ios::trunc);
|
||||
Compress c(out, true, true);
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
const std::string& path = it->first;
|
||||
std::cout << '\t' << "addFile(" << path << ");" << std::endl;
|
||||
c.addFile(path, path, ZipCommon::CM_STORE);
|
||||
}
|
||||
ZipArchive a(c.close());
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
const std::string& path = it->first;
|
||||
Poco::UInt64 size = it->second;
|
||||
ZipArchive::FileHeaders::const_iterator it2 = a.findHeader(path);
|
||||
assert (it2 != a.headerEnd());
|
||||
const Poco::Zip::ZipLocalFileHeader& file = it2->second;
|
||||
assert(file.getUncompressedSize() == size);
|
||||
assert(file.getCompressedSize() == size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CompressTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -152,6 +210,7 @@ CppUnit::Test* CompressTest::suite()
|
||||
CppUnit_addTest(pSuite, CompressTest, testManipulatorDel);
|
||||
CppUnit_addTest(pSuite, CompressTest, testManipulatorReplace);
|
||||
CppUnit_addTest(pSuite, CompressTest, testSetZipComment);
|
||||
CppUnit_addTest(pSuite, CompressTest, testZip64);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user