Use environment variable POCO_BASE for searching Zip test files.

This commit is contained in:
Francis ANDRE 2015-11-19 15:35:10 +01:00
parent 71ac932a90
commit e5d569cc62
3 changed files with 37 additions and 31 deletions

View File

@ -19,6 +19,7 @@
#include "Poco/FileStream.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include <iostream>
#include <fstream>
#undef min
#include <algorithm>
@ -40,7 +41,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());
@ -75,14 +76,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());
}
@ -92,14 +93,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());
@ -110,13 +111,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());
@ -128,7 +129,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);

View File

@ -27,6 +27,7 @@
#include "CppUnit/TestSuite.h"
#undef min
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
@ -46,7 +47,7 @@ ZipTest::~ZipTest()
void ZipTest::testSkipSingleFile()
{
std::string testFile = getTestFile("test.zip");
std::string testFile = getTestFile("data", "test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
SkipCallback skip;
@ -68,7 +69,7 @@ void ZipTest::testSkipSingleFile()
void ZipTest::testDecompressSingleFile()
{
std::string testFile = getTestFile("test.zip");
std::string testFile = getTestFile("data", "test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
ZipArchive arch(inp);
@ -83,7 +84,7 @@ void ZipTest::testDecompressSingleFile()
void ZipTest::testDecompressSingleFileInDir()
{
std::string testFile = getTestFile("test.zip");
std::string testFile = getTestFile("data","test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
ZipArchive arch(inp);
@ -98,7 +99,7 @@ void ZipTest::testDecompressSingleFileInDir()
void ZipTest::testCrcAndSizeAfterData()
{
std::string testFile = getTestFile("data.zip");
std::string testFile = getTestFile("data", "data.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
Decompress dec(inp, Poco::Path());
@ -112,7 +113,7 @@ void ZipTest::testCrcAndSizeAfterData()
void ZipTest::testCrcAndSizeAfterDataWithArchive()
{
std::string testFile = getTestFile("data.zip");
std::string testFile = getTestFile("data", "data.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
Poco::Zip::ZipArchive zip(inp);
@ -132,30 +133,34 @@ void ZipTest::testCrcAndSizeAfterDataWithArchive()
}
std::string ZipTest::getTestFile(const std::string& testFile)
std::string ZipTest::getTestFile(const std::string& directory, const std::string& file)
{
Poco::Path root;
root.makeAbsolute();
Poco::Path result;
while (!Poco::Path::find(root.toString(), "data", result))
std::ostringstream ostr;
ostr << directory << '/' << file;
std::string validDir(ostr.str());
Poco::Path pathPattern(validDir);
if (Poco::File(pathPattern).exists())
{
root.makeParent();
if (root.toString().empty() || root.toString() == "/")
throw Poco::FileNotFoundException("Didn't find data subdir");
return validDir;
}
result.makeDirectory();
result.setFileName(testFile);
Poco::File aFile(result.toString());
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
throw Poco::FileNotFoundException("Didn't find " + testFile);
return result.toString();
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("test.zip");
std::string testFile = getTestFile("data", "test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
Decompress dec(inp, Poco::Path());
@ -169,7 +174,7 @@ void ZipTest::testDecompress()
void ZipTest::testDecompressFlat()
{
std::string testFile = getTestFile("test.zip");
std::string testFile = getTestFile("data", "test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
assert (inp.good());
Decompress dec(inp, Poco::Path(), true);

View File

@ -45,7 +45,7 @@ public:
static CppUnit::Test* suite();
static std::string getTestFile(const std::string& testFile);
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);