summaryrefslogtreecommitdiff
path: root/src/fs/zip_unittest.cc
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-25 19:10:51 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-25 19:11:57 +0300
commite6198149823ee18e4167b0e6dd34cfb7f2e2f496 (patch)
tree013181d9d8e4f06433838cffaabf6159aa2f775b /src/fs/zip_unittest.cc
parent0bb68a88e6dc6a04685825e80b4e3dca1dc097d2 (diff)
downloadplus-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.gz
plus-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.bz2
plus-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.tar.xz
plus-e6198149823ee18e4167b0e6dd34cfb7f2e2f496.zip
Implement basic VirtFsZip for virtual fs based on zip archives.
Api similar to VirtFs. For now unused.
Diffstat (limited to 'src/fs/zip_unittest.cc')
-rw-r--r--src/fs/zip_unittest.cc82
1 files changed, 53 insertions, 29 deletions
diff --git a/src/fs/zip_unittest.cc b/src/fs/zip_unittest.cc
index 9661b7d19..72691c47e 100644
--- a/src/fs/zip_unittest.cc
+++ b/src/fs/zip_unittest.cc
@@ -23,6 +23,7 @@
#include "logger.h"
#include "fs/files.h"
+#include "fs/virtzipentry.h"
#include "fs/zip.h"
#include "fs/ziplocalheader.h"
@@ -36,7 +37,6 @@ TEST_CASE("Zip readArchiveInfo")
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
- std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -44,105 +44,113 @@ TEST_CASE("Zip readArchiveInfo")
{
name = prefix + "data/test/test.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(headers[0]->archiveName == name);
+ REQUIRE(entry->mArchiveName == name);
REQUIRE(headers[0]->fileName == "dir/hide.png");
REQUIRE(headers[0]->compressSize == 365);
REQUIRE(headers[0]->uncompressSize == 368);
- REQUIRE(headers[1]->archiveName == name);
REQUIRE(headers[1]->fileName == "dir/brimmedhat.png");
REQUIRE(headers[1]->compressSize == 1959);
REQUIRE(headers[1]->uncompressSize == 1959);
+
+ delete entry;
}
SECTION("test2.zip")
{
name = prefix + "data/test/test2.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
- REQUIRE(headers[0]->archiveName == name);
+ REQUIRE(entry->mArchiveName == name);
REQUIRE(headers[0]->fileName == "test.txt");
REQUIRE(headers[0]->compressSize == 17);
REQUIRE(headers[0]->uncompressSize == 23);
- REQUIRE(headers[1]->archiveName == name);
REQUIRE(headers[1]->fileName == "dir2/hide.png");
REQUIRE(headers[1]->compressSize == 365);
REQUIRE(headers[1]->uncompressSize == 368);
- REQUIRE(headers[2]->archiveName == name);
REQUIRE(headers[2]->fileName == "dir2/test.txt");
REQUIRE(headers[2]->compressSize == 17);
REQUIRE(headers[2]->uncompressSize == 23);
- REQUIRE(headers[3]->archiveName == name);
REQUIRE(headers[3]->fileName == "dir2/paths.xml");
REQUIRE(headers[3]->compressSize == 154);
REQUIRE(headers[3]->uncompressSize == 185);
- REQUIRE(headers[4]->archiveName == name);
REQUIRE(headers[4]->fileName == "dir2/units.xml");
REQUIRE(headers[4]->compressSize == 202);
REQUIRE(headers[4]->uncompressSize == 306);
- REQUIRE(headers[5]->archiveName == name);
REQUIRE(headers[5]->fileName == "dir/hide.png");
REQUIRE(headers[5]->compressSize == 365);
REQUIRE(headers[5]->uncompressSize == 368);
- REQUIRE(headers[6]->archiveName == name);
REQUIRE(headers[6]->fileName == "dir/1/test.txt");
REQUIRE(headers[6]->compressSize == 17);
REQUIRE(headers[6]->uncompressSize == 23);
- REQUIRE(headers[7]->archiveName == name);
REQUIRE(headers[7]->fileName == "dir/1/file1.txt");
REQUIRE(headers[7]->compressSize == 17);
REQUIRE(headers[7]->uncompressSize == 23);
- REQUIRE(headers[8]->archiveName == name);
REQUIRE(headers[8]->fileName == "dir/gpl/palette.gpl");
REQUIRE(headers[8]->compressSize == 128);
REQUIRE(headers[8]->uncompressSize == 213);
- REQUIRE(headers[9]->archiveName == name);
REQUIRE(headers[9]->fileName == "dir/dye.png");
REQUIRE(headers[9]->compressSize == 794);
REQUIRE(headers[9]->uncompressSize == 794);
- REQUIRE(headers[10]->archiveName == name);
REQUIRE(headers[10]->fileName == "units.xml");
REQUIRE(headers[10]->compressSize == 202);
REQUIRE(headers[10]->uncompressSize == 306);
+
+ delete entry;
}
SECTION("test3.zip")
{
name = prefix + "data/test/test3.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(headers[0]->archiveName == name);
+ REQUIRE(entry->mArchiveName == name);
REQUIRE(headers[0]->fileName == "test.txt");
REQUIRE(headers[0]->compressSize == 17);
REQUIRE(headers[0]->uncompressSize == 23);
- REQUIRE(headers[1]->archiveName == name);
REQUIRE(headers[1]->fileName == "units.xml");
REQUIRE(headers[1]->compressSize == 202);
REQUIRE(headers[1]->uncompressSize == 306);
+
+ delete entry;
}
SECTION("test4.zip")
{
name = prefix + "data/test/test4.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
+ REQUIRE(entry->mArchiveName == name);
REQUIRE(headers.size() == 0);
+
+ delete entry;
}
- delete_all(headers);
delete2(logger);
}
@@ -151,7 +159,6 @@ TEST_CASE("Zip readCompressedFile")
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
- std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -164,15 +171,19 @@ TEST_CASE("Zip readCompressedFile")
{
name = prefix + "data/test/test2.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
+ REQUIRE(entry->mArchiveName == name);
// test.txt
uint8_t *const buf = Zip::readCompressedFile(headers[0]);
REQUIRE(buf != nullptr);
delete [] buf;
+ delete entry;
}
- delete_all(headers);
delete2(logger);
}
@@ -181,7 +192,6 @@ TEST_CASE("Zip readFile")
logger = new Logger();
std::string name("data/test/test.zip");
std::string prefix;
- std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -194,8 +204,12 @@ TEST_CASE("Zip readFile")
{
name = prefix + "data/test/test.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
+ REQUIRE(entry->mArchiveName == name);
for (int f = 0; f < 2; f ++)
{
logger->log("test header: %s, %u, %u",
@@ -206,14 +220,19 @@ TEST_CASE("Zip readFile")
REQUIRE(buf != nullptr);
delete [] buf;
}
+ delete entry;
}
SECTION("test2.zip")
{
name = prefix + "data/test/test2.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
+ REQUIRE(entry->mArchiveName == name);
// test.txt
uint8_t *buf = Zip::readFile(headers[0]);
REQUIRE(buf != nullptr);
@@ -231,14 +250,19 @@ TEST_CASE("Zip readFile")
REQUIRE(buf != nullptr);
delete [] buf;
}
+ delete entry;
}
SECTION("test3.zip")
{
name = prefix + "data/test/test3.zip";
- REQUIRE(Zip::readArchiveInfo(name, headers));
+ VirtZipEntry *const entry = new VirtZipEntry(name);
+ std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
+
+ REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
+ REQUIRE(entry->mArchiveName == name);
for (int f = 0; f < 2; f ++)
{
logger->log("test header: %s, %u, %u",
@@ -249,8 +273,8 @@ TEST_CASE("Zip readFile")
REQUIRE(buf != nullptr);
delete [] buf;
}
+ delete entry;
}
- delete_all(headers);
delete2(logger);
}