mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 00:07:19 +01:00 
			
		
		
		
	Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
		
							
								
								
									
										221
									
								
								vendor/POCO/Zip/testsuite/src/CompressTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										221
									
								
								vendor/POCO/Zip/testsuite/src/CompressTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,221 @@
 | 
			
		||||
//
 | 
			
		||||
// CompressTest.cpp
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// 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>
 | 
			
		||||
#undef min
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace Poco::Zip;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CompressTest::CompressTest(const std::string& name): CppUnit::TestCase(name)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CompressTest::~CompressTest()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testSingleFile()
 | 
			
		||||
{
 | 
			
		||||
	Poco::FileOutputStream out(Poco::Path::temp() + "appinf.zip");
 | 
			
		||||
	Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
	Compress c(out, true);
 | 
			
		||||
	c.addFile(theFile, theFile.getFileName());
 | 
			
		||||
	ZipArchive a(c.close());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testDirectory()
 | 
			
		||||
{
 | 
			
		||||
	Poco::FileOutputStream out(Poco::Path::temp() + "pocobin.zip");
 | 
			
		||||
	Poco::File aFile("some/");
 | 
			
		||||
	if (aFile.exists()) aFile.remove(true);
 | 
			
		||||
	Poco::File aDir("some/recursive/dir/");
 | 
			
		||||
	aDir.createDirectories();
 | 
			
		||||
	Poco::File aDir2("some/other/recursive/dir/");
 | 
			
		||||
	aDir2.createDirectories();
 | 
			
		||||
	Poco::File aF("some/recursive/dir/test.file");
 | 
			
		||||
	aF.createFile();
 | 
			
		||||
	Poco::FileOutputStream fos(aF.path());
 | 
			
		||||
	fos << "just some test data";
 | 
			
		||||
	fos.close();
 | 
			
		||||
 | 
			
		||||
	Poco::Path theFile(aFile.path());
 | 
			
		||||
	theFile.makeDirectory();
 | 
			
		||||
	Compress c(out, true);
 | 
			
		||||
	c.addRecursive(theFile, ZipCommon::CL_MAXIMUM, false, theFile);
 | 
			
		||||
	ZipArchive a(c.close());
 | 
			
		||||
	Poco::File(aFile).remove(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testManipulator()
 | 
			
		||||
{
 | 
			
		||||
	{
 | 
			
		||||
		Poco::FileOutputStream out(Poco::Path::temp() + "appinf.zip");
 | 
			
		||||
		Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
		Compress c(out, true);
 | 
			
		||||
		c.addFile(theFile, theFile.getFileName());
 | 
			
		||||
		ZipArchive a(c.close());
 | 
			
		||||
	}
 | 
			
		||||
	ZipManipulator zm(Poco::Path::temp() + "appinf.zip", true);
 | 
			
		||||
	zm.renameFile("test.zip", "renamedtest.zip");
 | 
			
		||||
	zm.addFile("doc/othertest.zip", ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
	ZipArchive archive=zm.commit();
 | 
			
		||||
	assertTrue (archive.findHeader("doc/othertest.zip") != archive.headerEnd());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testManipulatorDel()
 | 
			
		||||
{
 | 
			
		||||
	{
 | 
			
		||||
		Poco::FileOutputStream out(Poco::Path::temp() + "appinf.zip");
 | 
			
		||||
		Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
		Compress c(out, true);
 | 
			
		||||
		c.addFile(theFile, theFile.getFileName());
 | 
			
		||||
		ZipArchive a(c.close());
 | 
			
		||||
	}
 | 
			
		||||
	ZipManipulator zm(Poco::Path::temp() + "appinf.zip", true);
 | 
			
		||||
	zm.deleteFile("test.zip");
 | 
			
		||||
	zm.addFile("doc/data.zip", ZipTest::getTestFile("data", "data.zip"));
 | 
			
		||||
	ZipArchive archive=zm.commit();
 | 
			
		||||
	assertTrue (archive.findHeader("test.zip") == archive.headerEnd());
 | 
			
		||||
	assertTrue (archive.findHeader("doc/data.zip") != archive.headerEnd());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testManipulatorReplace()
 | 
			
		||||
{
 | 
			
		||||
	{
 | 
			
		||||
		Poco::FileOutputStream out(Poco::Path::temp() + "appinf.zip");
 | 
			
		||||
		Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
		Compress c(out, true);
 | 
			
		||||
		c.addFile(theFile, theFile.getFileName());
 | 
			
		||||
		ZipArchive a(c.close());
 | 
			
		||||
	}
 | 
			
		||||
	ZipManipulator zm(Poco::Path::temp() + "appinf.zip", true);
 | 
			
		||||
	zm.replaceFile("test.zip", ZipTest::getTestFile("data", "doc.zip"));
 | 
			
		||||
 | 
			
		||||
	ZipArchive archive=zm.commit();
 | 
			
		||||
	assertTrue (archive.findHeader("test.zip") != archive.headerEnd());
 | 
			
		||||
	assertTrue (archive.findHeader("doc.zip") == archive.headerEnd());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testSetZipComment()
 | 
			
		||||
{
 | 
			
		||||
	std::string comment("Testing...123...");
 | 
			
		||||
	Poco::FileOutputStream out(Poco::Path::temp() + "comment.zip");
 | 
			
		||||
	Poco::Path theFile(ZipTest::getTestFile("data", "test.zip"));
 | 
			
		||||
	Compress c(out, true);
 | 
			
		||||
	c.addFile(theFile, theFile.getFileName());
 | 
			
		||||
	c.setZipComment(comment);
 | 
			
		||||
	ZipArchive a(c.close());
 | 
			
		||||
	assertTrue (a.getZipComment() == comment);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::createDataFile(const std::string& path, Poco::UInt64 size)
 | 
			
		||||
{
 | 
			
		||||
	Poco::FileOutputStream out(path.c_str(), std::ios::trunc);
 | 
			
		||||
	assertTrue ( ! 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);
 | 
			
		||||
		assertTrue ( ! out.fail() );
 | 
			
		||||
		size -= bytesToWrite;
 | 
			
		||||
	}
 | 
			
		||||
	out.flush();
 | 
			
		||||
	assertTrue ( ! out.fail() );
 | 
			
		||||
	out.close();
 | 
			
		||||
	assertTrue ( ! out.fail() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::testZip64()
 | 
			
		||||
{
 | 
			
		||||
	using FileMap = std::map<std::string, Poco::UInt64>;
 | 
			
		||||
 | 
			
		||||
	std::cout << std::endl;
 | 
			
		||||
	FileMap 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(FileMap::const_iterator it = files.begin(); it != files.end(); it++)
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << '\t' << "createDataFile(" << it->first << ", " << it->second << ");" << std::endl;
 | 
			
		||||
		createDataFile(it->first, it->second);
 | 
			
		||||
	}
 | 
			
		||||
	Poco::FileOutputStream out(Poco::Path::temp() + "zip64.zip", std::ios::trunc);
 | 
			
		||||
	Compress c(out, true, true);
 | 
			
		||||
	for(FileMap::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(FileMap::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);
 | 
			
		||||
		assertTrue (it2 != a.headerEnd());
 | 
			
		||||
		const Poco::Zip::ZipLocalFileHeader& file = it2->second;
 | 
			
		||||
		assertTrue (file.getUncompressedSize() == size);
 | 
			
		||||
		assertTrue (file.getCompressedSize() == size);
 | 
			
		||||
	}
 | 
			
		||||
	for (FileMap::const_iterator it = files.begin(); it != files.end(); it++)
 | 
			
		||||
	{
 | 
			
		||||
		Poco::File(it->first).remove();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::setUp()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void CompressTest::tearDown()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CppUnit::Test* CompressTest::suite()
 | 
			
		||||
{
 | 
			
		||||
	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CompressTest");
 | 
			
		||||
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testSingleFile);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testDirectory);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testManipulator);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testManipulatorDel);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testManipulatorReplace);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testSetZipComment);
 | 
			
		||||
	CppUnit_addTest(pSuite, CompressTest, testZip64);
 | 
			
		||||
 | 
			
		||||
	return pSuite;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								vendor/POCO/Zip/testsuite/src/CompressTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								vendor/POCO/Zip/testsuite/src/CompressTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
//
 | 
			
		||||
// CompressTest.h
 | 
			
		||||
//
 | 
			
		||||
// Definition of the CompressTest class.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef CompressTest_INCLUDED
 | 
			
		||||
#define CompressTest_INCLUDED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "Poco/Zip/Zip.h"
 | 
			
		||||
#include "CppUnit/TestCase.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CompressTest: public CppUnit::TestCase
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	CompressTest(const std::string& name);
 | 
			
		||||
	~CompressTest();
 | 
			
		||||
 | 
			
		||||
	void testSingleFile();
 | 
			
		||||
	void testDirectory();
 | 
			
		||||
	void testManipulator();
 | 
			
		||||
	void testManipulatorDel();
 | 
			
		||||
	void testManipulatorReplace();
 | 
			
		||||
	void testSetZipComment();
 | 
			
		||||
 | 
			
		||||
	static const Poco::UInt64 KB = 1024;
 | 
			
		||||
	static const Poco::UInt64 MB = 1024*KB;
 | 
			
		||||
	void createDataFile(const std::string& path, Poco::UInt64 size);
 | 
			
		||||
	void testZip64();
 | 
			
		||||
 | 
			
		||||
	void setUp();
 | 
			
		||||
	void tearDown();
 | 
			
		||||
 | 
			
		||||
	static CppUnit::Test* suite();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // CompressTest_INCLUDED
 | 
			
		||||
							
								
								
									
										17
									
								
								vendor/POCO/Zip/testsuite/src/Driver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								vendor/POCO/Zip/testsuite/src/Driver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
//
 | 
			
		||||
// Driver.cpp
 | 
			
		||||
//
 | 
			
		||||
// Console-based test driver for Poco Zip.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CppUnit/TestRunner.h"
 | 
			
		||||
#include "ZipTestSuite.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CppUnitMain(ZipTestSuite)
 | 
			
		||||
							
								
								
									
										147
									
								
								vendor/POCO/Zip/testsuite/src/PartialStreamTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								vendor/POCO/Zip/testsuite/src/PartialStreamTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,147 @@
 | 
			
		||||
//
 | 
			
		||||
// PartialStreamTest.cpp
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "PartialStreamTest.h"
 | 
			
		||||
#include "CppUnit/TestCaller.h"
 | 
			
		||||
#include "CppUnit/TestSuite.h"
 | 
			
		||||
#include "Poco/Zip/PartialStream.h"
 | 
			
		||||
#include "Poco/Zip/AutoDetectStream.h"
 | 
			
		||||
#include "Poco/Zip/ZipUtil.h"
 | 
			
		||||
#include "Poco/MemoryStream.h"
 | 
			
		||||
#include "Poco/StreamCopier.h"
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace Poco::Zip;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PartialStreamTest::PartialStreamTest(const std::string& name): CppUnit::TestCase(name)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PartialStreamTest::~PartialStreamTest()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::testReading()
 | 
			
		||||
{
 | 
			
		||||
	std::string message("some dummy message !");
 | 
			
		||||
	std::string prefix("pre ");
 | 
			
		||||
	std::string postfix(" post");
 | 
			
		||||
	std::string result(prefix+message+postfix);
 | 
			
		||||
	std::istringstream istr(message);
 | 
			
		||||
	PartialInputStream in(istr, 0, static_cast<std::streamoff>(message.length()), true, prefix, postfix);
 | 
			
		||||
	char buf[124];
 | 
			
		||||
	in.read(buf, 124);
 | 
			
		||||
	std::string res(buf, static_cast<std::string::size_type>(in.gcount()));
 | 
			
		||||
	assertTrue (res == result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::testWriting()
 | 
			
		||||
{
 | 
			
		||||
	std::string prefix("X");
 | 
			
		||||
	std::string message("some test message");
 | 
			
		||||
	std::string postfix("YYY");
 | 
			
		||||
	std::string result(prefix+message+postfix);
 | 
			
		||||
	std::ostringstream ostr;
 | 
			
		||||
	PartialOutputStream out(ostr, prefix.size(), postfix.size());
 | 
			
		||||
	out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
 | 
			
		||||
	assertTrue (out.good());
 | 
			
		||||
	out.close();
 | 
			
		||||
	std::string res (ostr.str());
 | 
			
		||||
	assertTrue (out.bytesWritten() == message.size());
 | 
			
		||||
	assertTrue (message == res);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::testWritingZero()
 | 
			
		||||
{
 | 
			
		||||
	std::string prefix("X");
 | 
			
		||||
	std::string message;
 | 
			
		||||
	std::string postfix("YYY");
 | 
			
		||||
	std::string result(prefix+message+postfix);
 | 
			
		||||
	std::ostringstream ostr;
 | 
			
		||||
	PartialOutputStream out(ostr, prefix.size(), postfix.size());
 | 
			
		||||
	out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
 | 
			
		||||
	assertTrue (out.good());
 | 
			
		||||
	out.close();
 | 
			
		||||
	std::string res (ostr.str());
 | 
			
		||||
	assertTrue (out.bytesWritten() == message.size());
 | 
			
		||||
	assertTrue (message == res);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::testWritingOne()
 | 
			
		||||
{
 | 
			
		||||
	std::string prefix("X");
 | 
			
		||||
	std::string message("a");
 | 
			
		||||
	std::string postfix("YYY");
 | 
			
		||||
	std::string result(prefix+message+postfix);
 | 
			
		||||
	std::ostringstream ostr;
 | 
			
		||||
	PartialOutputStream out(ostr, prefix.size(), postfix.size());
 | 
			
		||||
	out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
 | 
			
		||||
	assertTrue (out.good());
 | 
			
		||||
	out.close();
 | 
			
		||||
	std::string res (ostr.str());
 | 
			
		||||
	assertTrue (out.bytesWritten() == message.size());
 | 
			
		||||
	assertTrue (message == res);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::testAutoDetect()
 | 
			
		||||
{
 | 
			
		||||
	std::string header = ZipUtil::fakeZLibInitString(ZipCommon::CL_NORMAL);
 | 
			
		||||
	std::string crc("\01\02\03\04");
 | 
			
		||||
	const char data[] = 
 | 
			
		||||
	{
 | 
			
		||||
		'\x01', '\x02', '\x03', '\x04', 
 | 
			
		||||
		'\x05', '\x06', '\x07', '\x08', // fake data
 | 
			
		||||
		'\x50', '\x4b', '\x07', '\x08', // data signature in compressed data
 | 
			
		||||
		'\x01', '\x02', '\x03', '\x04',
 | 
			
		||||
		'\x50', 
 | 
			
		||||
		'\x50', '\x4b', '\x07', '\x08', // real data signature 
 | 
			
		||||
		'\x00', '\x00', '\x00', '\x00', // CRC (ignored)
 | 
			
		||||
		'\x11', '\x00', '\x00', '\x00', // compressed size
 | 
			
		||||
		'\x00', '\x00', '\x00', '\x00'  // uncompressed size (ignored)
 | 
			
		||||
	};
 | 
			
		||||
	
 | 
			
		||||
	Poco::MemoryInputStream istr(data, sizeof(data));
 | 
			
		||||
	AutoDetectInputStream adi(istr, header, crc, false, 0);
 | 
			
		||||
	std::string result;
 | 
			
		||||
	Poco::StreamCopier::copyToString(adi, result);
 | 
			
		||||
	assertTrue (result.size() == 23);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::setUp()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PartialStreamTest::tearDown()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CppUnit::Test* PartialStreamTest::suite()
 | 
			
		||||
{
 | 
			
		||||
	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PartialStreamTest");
 | 
			
		||||
 | 
			
		||||
	CppUnit_addTest(pSuite, PartialStreamTest, testReading);
 | 
			
		||||
	CppUnit_addTest(pSuite, PartialStreamTest, testWriting);
 | 
			
		||||
	CppUnit_addTest(pSuite, PartialStreamTest, testWritingZero);
 | 
			
		||||
	CppUnit_addTest(pSuite, PartialStreamTest, testWritingOne);
 | 
			
		||||
	CppUnit_addTest(pSuite, PartialStreamTest, testAutoDetect);
 | 
			
		||||
 | 
			
		||||
	return pSuite;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								vendor/POCO/Zip/testsuite/src/PartialStreamTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								vendor/POCO/Zip/testsuite/src/PartialStreamTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
//
 | 
			
		||||
// PartialStreamTest.h
 | 
			
		||||
//
 | 
			
		||||
// Definition of the PartialStreamTest class.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef PartialStreamTest_INCLUDED
 | 
			
		||||
#define PartialStreamTest_INCLUDED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "Poco/Zip/Zip.h"
 | 
			
		||||
#include "CppUnit/TestCase.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PartialStreamTest: public CppUnit::TestCase
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	PartialStreamTest(const std::string& name);
 | 
			
		||||
	~PartialStreamTest();
 | 
			
		||||
 | 
			
		||||
	void testReading();
 | 
			
		||||
	void testWriting();
 | 
			
		||||
	void testWritingZero();
 | 
			
		||||
	void testWritingOne();
 | 
			
		||||
	void testAutoDetect();
 | 
			
		||||
 | 
			
		||||
	void setUp();
 | 
			
		||||
	void tearDown();
 | 
			
		||||
 | 
			
		||||
	static CppUnit::Test* suite();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // PartialStreamTest_INCLUDED
 | 
			
		||||
							
								
								
									
										30
									
								
								vendor/POCO/Zip/testsuite/src/WinCEDriver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								vendor/POCO/Zip/testsuite/src/WinCEDriver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
//
 | 
			
		||||
// WinCEDriver.cpp
 | 
			
		||||
//
 | 
			
		||||
// Console-based test driver for Windows CE.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CppUnit/TestRunner.h"
 | 
			
		||||
#include "ZipTestSuite.h"
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int wmain(int argc, wchar_t* argv[])
 | 
			
		||||
{
 | 
			
		||||
	std::vector<std::string> args;
 | 
			
		||||
	for (int i = 0; i < argc; ++i)
 | 
			
		||||
	{
 | 
			
		||||
		char buffer[1024];
 | 
			
		||||
		std::wcstombs(buffer, argv[i], sizeof(buffer));
 | 
			
		||||
		args.push_back(std::string(buffer));
 | 
			
		||||
	}
 | 
			
		||||
	CppUnit::TestRunner runner;	
 | 
			
		||||
	runner.addTest("ZipTestSuite", ZipTestSuite::suite());
 | 
			
		||||
	return runner.run(args) ? 0 : 1;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								vendor/POCO/Zip/testsuite/src/WinDriver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								vendor/POCO/Zip/testsuite/src/WinDriver.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
//
 | 
			
		||||
// WinDriver.cpp
 | 
			
		||||
//
 | 
			
		||||
// Windows test driver for Poco Zip.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "WinTestRunner/WinTestRunner.h"
 | 
			
		||||
#include "ZipTestSuite.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestDriver: public CppUnit::WinTestRunnerApp
 | 
			
		||||
{
 | 
			
		||||
	void TestMain()
 | 
			
		||||
	{
 | 
			
		||||
		CppUnit::WinTestRunner runner;
 | 
			
		||||
		runner.addTest(ZipTestSuite::suite());
 | 
			
		||||
		runner.run();
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TestDriver theDriver;
 | 
			
		||||
							
								
								
									
										362
									
								
								vendor/POCO/Zip/testsuite/src/ZipTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										362
									
								
								vendor/POCO/Zip/testsuite/src/ZipTest.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,362 @@
 | 
			
		||||
//
 | 
			
		||||
// ZipTest.cpp
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "ZipTest.h"
 | 
			
		||||
#include "Poco/Zip/SkipCallback.h"
 | 
			
		||||
#include "Poco/Zip/ZipLocalFileHeader.h"
 | 
			
		||||
#include "Poco/Zip/ZipArchive.h"
 | 
			
		||||
#include "Poco/Zip/ZipStream.h"
 | 
			
		||||
#include "Poco/Zip/Decompress.h"
 | 
			
		||||
#include "Poco/Zip/ZipCommon.h"
 | 
			
		||||
#include "Poco/StreamCopier.h"
 | 
			
		||||
#include "Poco/File.h"
 | 
			
		||||
#include "Poco/FileStream.h"
 | 
			
		||||
#include "Poco/URI.h"
 | 
			
		||||
#include "Poco/Path.h"
 | 
			
		||||
#include "Poco/Delegate.h"
 | 
			
		||||
#include "Poco/StreamCopier.h"
 | 
			
		||||
#include "Poco/Environment.h"
 | 
			
		||||
#include "CppUnit/TestCaller.h"
 | 
			
		||||
#include "CppUnit/TestSuite.h"
 | 
			
		||||
#undef min
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace Poco::Zip;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ZipTest::ZipTest(const std::string& name): CppUnit::TestCase(name)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ZipTest::~ZipTest()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testSkipSingleFile()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "test.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	SkipCallback skip;
 | 
			
		||||
	ZipLocalFileHeader hdr(inp, false, skip);
 | 
			
		||||
	assertTrue (ZipCommon::HS_FAT == hdr.getHostSystem());
 | 
			
		||||
	int major = hdr.getMajorVersionNumber();
 | 
			
		||||
	int POCO_UNUSED minor = hdr.getMinorVersionNumber();
 | 
			
		||||
	assertTrue (major <= 2);
 | 
			
		||||
	std::size_t hdrSize = hdr.getHeaderSize();
 | 
			
		||||
	assertTrue (hdrSize > 30);
 | 
			
		||||
	ZipCommon::CompressionMethod POCO_UNUSED cm = hdr.getCompressionMethod();
 | 
			
		||||
	assertTrue (!hdr.isEncrypted());
 | 
			
		||||
	Poco::DateTime aDate = hdr.lastModifiedAt();
 | 
			
		||||
	Poco::UInt64 POCO_UNUSED cS = hdr.getCompressedSize();
 | 
			
		||||
	Poco::UInt64 POCO_UNUSED uS = hdr.getUncompressedSize();
 | 
			
		||||
	const std::string& POCO_UNUSED fileName = hdr.getFileName();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testCrcAndSizeAfterDataEncapsulated()
 | 
			
		||||
{
 | 
			
		||||
	// touch empty.txt
 | 
			
		||||
	// zip -fd foo.zip empty.txt
 | 
			
		||||
	// zip -fd encapsulated.zip foo.zip
 | 
			
		||||
	std::string testFile = getTestFile("data", "encapsulated.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue(inp.good());
 | 
			
		||||
 | 
			
		||||
	ZipArchive arch(inp);
 | 
			
		||||
	ZipArchive::FileHeaders::const_iterator it = arch.findHeader("foo.zip");
 | 
			
		||||
	assertTrue(it != arch.headerEnd());
 | 
			
		||||
	inp.clear(); // inp eof(), should clear
 | 
			
		||||
 | 
			
		||||
	ZipInputStream zipin(inp, it->second);
 | 
			
		||||
	std::ostringstream out(std::ios::binary);
 | 
			
		||||
	Poco::StreamCopier::copyStream(zipin, out);
 | 
			
		||||
 | 
			
		||||
	std::string result = out.str();
 | 
			
		||||
	// sub zip
 | 
			
		||||
	std::istringstream istr(result);
 | 
			
		||||
	ZipArchive subArch(istr);
 | 
			
		||||
	it = subArch.findHeader("empty.txt");
 | 
			
		||||
	assertTrue(it != subArch.headerEnd());
 | 
			
		||||
	assertTrue(it->second.getCompressedSize() == 0);
 | 
			
		||||
	assertTrue(it->second.getUncompressedSize() == 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressSingleFile()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "test.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	ZipArchive arch(inp);
 | 
			
		||||
	ZipArchive::FileHeaders::const_iterator it = arch.findHeader("testfile.txt");
 | 
			
		||||
	assertTrue (it != arch.headerEnd());
 | 
			
		||||
	ZipInputStream zipin (inp, it->second);
 | 
			
		||||
	std::ostringstream out(std::ios::binary);
 | 
			
		||||
	Poco::StreamCopier::copyStream(zipin, out);
 | 
			
		||||
	assertTrue (!out.str().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressSingleFileInDir()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data","test.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	ZipArchive arch(inp);
 | 
			
		||||
	ZipArchive::FileHeaders::const_iterator it = arch.findHeader("testdir/testfile.txt");
 | 
			
		||||
	assertTrue (it != arch.headerEnd());
 | 
			
		||||
	ZipInputStream zipin (inp, it->second);
 | 
			
		||||
	std::ostringstream out(std::ios::binary);
 | 
			
		||||
	Poco::StreamCopier::copyStream(zipin, out);
 | 
			
		||||
	assertTrue (!out.str().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testCrcAndSizeAfterData()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "data.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Decompress dec(inp, Poco::Path::temp());
 | 
			
		||||
	dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	dec.decompressAllFiles();
 | 
			
		||||
	dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	assertTrue (_errCnt == 0);
 | 
			
		||||
	assertTrue (!dec.mapping().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testCrcAndSizeAfterDataWithArchive()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "data.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Poco::Zip::ZipArchive zip(inp);
 | 
			
		||||
	inp.clear();
 | 
			
		||||
	inp.seekg(0);
 | 
			
		||||
	Poco::Zip::ZipArchive::FileHeaders::const_iterator it = zip.headerBegin();
 | 
			
		||||
	for ( ; it!=zip.headerEnd(); ++it)
 | 
			
		||||
	{
 | 
			
		||||
		Poco::Zip::ZipInputStream zipis(inp,it->second);
 | 
			
		||||
		Poco::Path path(it->second.getFileName());
 | 
			
		||||
		if (path.isFile())
 | 
			
		||||
		{
 | 
			
		||||
			Poco::FileOutputStream os(Poco::Path::temp() + "test.dat");
 | 
			
		||||
			Poco::StreamCopier::copyStream(zipis,os);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
std::string ZipTest::getTestFile(const std::string& directory, const std::string& file)
 | 
			
		||||
{
 | 
			
		||||
	std::ostringstream ostr;
 | 
			
		||||
	ostr << directory << '/' << file;
 | 
			
		||||
	std::string validDir(ostr.str());
 | 
			
		||||
	Poco::Path pathPattern(validDir);
 | 
			
		||||
	if (Poco::File(pathPattern).exists())
 | 
			
		||||
	{
 | 
			
		||||
		return validDir;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ostr.str("");
 | 
			
		||||
	ostr << "/Zip/testsuite/" << directory << '/' << file;
 | 
			
		||||
	validDir = Poco::Environment::get("POCO_BASE") + ostr.str();
 | 
			
		||||
	pathPattern = validDir;
 | 
			
		||||
 | 
			
		||||
	if (!Poco::File(pathPattern).exists())
 | 
			
		||||
	{
 | 
			
		||||
		std::cout << "Can't find " << validDir << std::endl;
 | 
			
		||||
		throw Poco::NotFoundException("cannot locate directory containing valid Zip test files");
 | 
			
		||||
	}
 | 
			
		||||
	return validDir;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompress()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "test.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Decompress dec(inp, Poco::Path::temp());
 | 
			
		||||
	dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	dec.decompressAllFiles();
 | 
			
		||||
	dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	assertTrue (_errCnt == 0);
 | 
			
		||||
	assertTrue (!dec.mapping().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressFlat()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "test.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Decompress dec(inp, Poco::Path::temp(), true);
 | 
			
		||||
	dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	dec.decompressAllFiles();
 | 
			
		||||
	dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	assertTrue (_errCnt == 0);
 | 
			
		||||
	assertTrue (!dec.mapping().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressVuln()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "vuln.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Decompress dec(inp, Poco::Path::temp());
 | 
			
		||||
	dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	dec.decompressAllFiles();
 | 
			
		||||
	dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	assertTrue (_errCnt == 1);
 | 
			
		||||
	assertTrue (dec.mapping().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressFlatVuln()
 | 
			
		||||
{
 | 
			
		||||
	std::string testFile = getTestFile("data", "vuln.zip");
 | 
			
		||||
	Poco::FileInputStream inp(testFile);
 | 
			
		||||
	assertTrue (inp.good());
 | 
			
		||||
	Decompress dec(inp, Poco::Path::temp(), true);
 | 
			
		||||
	dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	dec.decompressAllFiles();
 | 
			
		||||
	dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>>(this, &ZipTest::onDecompressError);
 | 
			
		||||
	assertTrue (_errCnt == 0);
 | 
			
		||||
	assertTrue (!dec.mapping().empty());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::verifyDataFile(const std::string& path, Poco::UInt64 size)
 | 
			
		||||
{
 | 
			
		||||
	Poco::FileInputStream in(path);
 | 
			
		||||
	assertTrue ( ! in.fail() );
 | 
			
		||||
	Poco::Buffer<char> buffer1(MB);
 | 
			
		||||
	Poco::Buffer<char> buffer2(MB);
 | 
			
		||||
	for (int i = 0; size != 0; i++)
 | 
			
		||||
	{
 | 
			
		||||
		std::memset(buffer1.begin(), i, buffer1.size());
 | 
			
		||||
		std::memset(buffer2.begin(), 0, buffer2.size());
 | 
			
		||||
		Poco::UInt64 bytesToRead = std::min(size, static_cast<Poco::UInt64>(buffer2.size()));
 | 
			
		||||
		in.read(buffer2.begin(), bytesToRead);
 | 
			
		||||
		assertTrue (!in.fail() );
 | 
			
		||||
		assertTrue (std::memcmp(buffer1.begin(), buffer2.begin(), static_cast<std::size_t>(bytesToRead)) == 0);
 | 
			
		||||
		size -= bytesToRead;
 | 
			
		||||
	}
 | 
			
		||||
	char c;
 | 
			
		||||
	in.read(&c, 1);
 | 
			
		||||
	assertTrue ( in.eof() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testDecompressZip64()
 | 
			
		||||
{
 | 
			
		||||
	std::map<std::string, Poco::UInt64> files;
 | 
			
		||||
	files[Poco::Path::temp() + "data1.bin"] = static_cast<Poco::UInt64>(KB)*4096+1;
 | 
			
		||||
	files[Poco::Path::temp() + "data2.bin"] = static_cast<Poco::UInt64>(KB)*16;
 | 
			
		||||
	files[Poco::Path::temp() + "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++)
 | 
			
		||||
	{
 | 
			
		||||
		Poco::File file(it->first);
 | 
			
		||||
		if(file.exists())
 | 
			
		||||
			file.remove();
 | 
			
		||||
	}
 | 
			
		||||
	Poco::FileInputStream in(Poco::Path::temp() + "zip64.zip");
 | 
			
		||||
	Decompress c(in, Poco::Path::temp());
 | 
			
		||||
	c.decompressAllFiles();
 | 
			
		||||
	for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
 | 
			
		||||
	{
 | 
			
		||||
		verifyDataFile(it->first, it->second);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::testValidPath()
 | 
			
		||||
{
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("."));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath(".file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("..file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("file.txt.."));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath(".file..txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("~file..txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("~file/~"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("dir/~"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some/dir"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some/dir/or/another"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some/dir/./another"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some/dir/or/another/file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("s~me\\d.r\\.or..\\an..her\\file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some\\dir\\or\\another"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("some\\dir\\or\\another\\file.txt"));
 | 
			
		||||
	assertTrue (ZipCommon::isValidPath("s~me\\d.r/.or..\\an..her\\file.txt"));
 | 
			
		||||
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("/../"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("/"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("\\..\\"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("/..\\"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("\\../"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath(".."));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("~/"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("~/~"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("/~"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("/file.txt"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("~/file.txt"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("some/dir/or/../another/file.txt"));
 | 
			
		||||
	assertTrue (!ZipCommon::isValidPath("C:\\Windows\\system32"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info)
 | 
			
		||||
{
 | 
			
		||||
	++_errCnt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::setUp()
 | 
			
		||||
{
 | 
			
		||||
	_errCnt = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ZipTest::tearDown()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CppUnit::Test* ZipTest::suite()
 | 
			
		||||
{
 | 
			
		||||
	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTest");
 | 
			
		||||
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testSkipSingleFile);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressSingleFile);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressSingleFileInDir);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompress);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressFlat);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressVuln);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressFlatVuln);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterData);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterDataWithArchive);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterDataEncapsulated);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testDecompressZip64);
 | 
			
		||||
	CppUnit_addTest(pSuite, ZipTest, testValidPath);
 | 
			
		||||
 | 
			
		||||
	return pSuite;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								vendor/POCO/Zip/testsuite/src/ZipTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								vendor/POCO/Zip/testsuite/src/ZipTest.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
//
 | 
			
		||||
// ZipTest.h
 | 
			
		||||
//
 | 
			
		||||
// Definition of the ZipTest class.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef ZipTest_INCLUDED
 | 
			
		||||
#define ZipTest_INCLUDED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "Poco/Zip/Zip.h"
 | 
			
		||||
#include "Poco/Zip/ZipLocalFileHeader.h"
 | 
			
		||||
#include "CppUnit/TestCase.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ZipTest: public CppUnit::TestCase
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	ZipTest(const std::string& name);
 | 
			
		||||
	~ZipTest();
 | 
			
		||||
 | 
			
		||||
	void testSkipSingleFile();
 | 
			
		||||
	void testDecompressSingleFile();
 | 
			
		||||
	void testDecompressSingleFileInDir();
 | 
			
		||||
	void testDecompress();
 | 
			
		||||
	void testDecompressFlat();
 | 
			
		||||
	void testDecompressVuln();
 | 
			
		||||
	void testDecompressFlatVuln();
 | 
			
		||||
	void testCrcAndSizeAfterData();
 | 
			
		||||
	void testCrcAndSizeAfterDataWithArchive();
 | 
			
		||||
	void testCrcAndSizeAfterDataEncapsulated();
 | 
			
		||||
 | 
			
		||||
	static const Poco::UInt64 KB = 1024;
 | 
			
		||||
	static const Poco::UInt64 MB = 1024*KB;
 | 
			
		||||
	void verifyDataFile(const std::string& path, Poco::UInt64 size);
 | 
			
		||||
	void testDecompressZip64();
 | 
			
		||||
	void testValidPath();
 | 
			
		||||
 | 
			
		||||
	void setUp();
 | 
			
		||||
	void tearDown();
 | 
			
		||||
 | 
			
		||||
	static CppUnit::Test* suite();
 | 
			
		||||
 | 
			
		||||
	static std::string getTestFile(const std::string& directory, const std::string& type);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info);
 | 
			
		||||
	
 | 
			
		||||
	int _errCnt;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // ZipTest_INCLUDED
 | 
			
		||||
							
								
								
									
										26
									
								
								vendor/POCO/Zip/testsuite/src/ZipTestSuite.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								vendor/POCO/Zip/testsuite/src/ZipTestSuite.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
//
 | 
			
		||||
// ZipTestSuite.cpp
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "ZipTestSuite.h"
 | 
			
		||||
#include "ZipTest.h"
 | 
			
		||||
#include "PartialStreamTest.h"
 | 
			
		||||
#include "CompressTest.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CppUnit::Test* ZipTestSuite::suite()
 | 
			
		||||
{
 | 
			
		||||
	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTestSuite");
 | 
			
		||||
 | 
			
		||||
	pSuite->addTest(CompressTest::suite());
 | 
			
		||||
	pSuite->addTest(ZipTest::suite());
 | 
			
		||||
	pSuite->addTest(PartialStreamTest::suite());
 | 
			
		||||
 | 
			
		||||
	return pSuite;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								vendor/POCO/Zip/testsuite/src/ZipTestSuite.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/POCO/Zip/testsuite/src/ZipTestSuite.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
//
 | 
			
		||||
// ZipTestSuite.h
 | 
			
		||||
//
 | 
			
		||||
// Definition of the ZipTestSuite class.
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
 | 
			
		||||
// and Contributors.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier:	BSL-1.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef ZipTestSuite_INCLUDED
 | 
			
		||||
#define ZipTestSuite_INCLUDED
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CppUnit/TestSuite.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ZipTestSuite
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	static CppUnit::Test* suite();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // ZipTestSuite_INCLUDED
 | 
			
		||||
		Reference in New Issue
	
	Block a user