diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-02-24 19:10:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-02-24 23:31:22 +0300 |
commit | 0bb68a88e6dc6a04685825e80b4e3dca1dc097d2 (patch) | |
tree | 07a4e3bd321c5199fe4d388a1c6cb9923a147c0c /src/fs/zip_unittest.cc | |
parent | d1b37a4b299809c3eb11b073ab4eafdb773b8a45 (diff) | |
download | plus-0bb68a88e6dc6a04685825e80b4e3dca1dc097d2.tar.gz plus-0bb68a88e6dc6a04685825e80b4e3dca1dc097d2.tar.bz2 plus-0bb68a88e6dc6a04685825e80b4e3dca1dc097d2.tar.xz plus-0bb68a88e6dc6a04685825e80b4e3dca1dc097d2.zip |
Add support for extract files from zip archives.
Diffstat (limited to 'src/fs/zip_unittest.cc')
-rw-r--r-- | src/fs/zip_unittest.cc | 117 |
1 files changed, 113 insertions, 4 deletions
diff --git a/src/fs/zip_unittest.cc b/src/fs/zip_unittest.cc index 3f0c49cdf..9661b7d19 100644 --- a/src/fs/zip_unittest.cc +++ b/src/fs/zip_unittest.cc @@ -40,7 +40,7 @@ TEST_CASE("Zip readArchiveInfo") if (Files::existsLocal(name) == false) prefix = "../"; - SECTION("test 1") + SECTION("test.zip") { name = prefix + "data/test/test.zip"; @@ -56,7 +56,7 @@ TEST_CASE("Zip readArchiveInfo") REQUIRE(headers[1]->uncompressSize == 1959); } - SECTION("test 2") + SECTION("test2.zip") { name = prefix + "data/test/test2.zip"; @@ -118,7 +118,7 @@ TEST_CASE("Zip readArchiveInfo") REQUIRE(headers[10]->uncompressSize == 306); } - SECTION("test 3") + SECTION("test3.zip") { name = prefix + "data/test/test3.zip"; @@ -134,7 +134,7 @@ TEST_CASE("Zip readArchiveInfo") REQUIRE(headers[1]->uncompressSize == 306); } - SECTION("test 4") + SECTION("test4.zip") { name = prefix + "data/test/test4.zip"; @@ -145,3 +145,112 @@ TEST_CASE("Zip readArchiveInfo") delete_all(headers); delete2(logger); } + +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 = "../"; + + SECTION("empty") + { + REQUIRE_THROWS(Zip::readCompressedFile(nullptr)); + } + + SECTION("test2.zip") + { + name = prefix + "data/test/test2.zip"; + + REQUIRE(Zip::readArchiveInfo(name, headers)); + REQUIRE(headers.size() == 11); + // test.txt + uint8_t *const buf = Zip::readCompressedFile(headers[0]); + REQUIRE(buf != nullptr); + delete [] buf; + } + + delete_all(headers); + delete2(logger); +} + +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 = "../"; + + SECTION("empty") + { + REQUIRE_THROWS(Zip::readFile(nullptr)); + } + + SECTION("test.zip") + { + name = prefix + "data/test/test.zip"; + + REQUIRE(Zip::readArchiveInfo(name, headers)); + REQUIRE(headers.size() == 2); + for (int f = 0; f < 2; f ++) + { + logger->log("test header: %s, %u, %u", + headers[f]->fileName.c_str(), + headers[f]->compressSize, + headers[f]->uncompressSize); + uint8_t *const buf = Zip::readFile(headers[f]); + REQUIRE(buf != nullptr); + delete [] buf; + } + } + + SECTION("test2.zip") + { + name = prefix + "data/test/test2.zip"; + + REQUIRE(Zip::readArchiveInfo(name, headers)); + REQUIRE(headers.size() == 11); + // test.txt + uint8_t *buf = Zip::readFile(headers[0]); + REQUIRE(buf != nullptr); + const std::string str = std::string(reinterpret_cast<char*>(buf), + headers[0]->uncompressSize); + REQUIRE(str == "test line 1\ntest line 2"); + delete [] buf; + for (int f = 0; f < 11; f ++) + { + logger->log("test header: %s, %u, %u", + headers[f]->fileName.c_str(), + headers[f]->compressSize, + headers[f]->uncompressSize); + buf = Zip::readFile(headers[f]); + REQUIRE(buf != nullptr); + delete [] buf; + } + } + + SECTION("test3.zip") + { + name = prefix + "data/test/test3.zip"; + + REQUIRE(Zip::readArchiveInfo(name, headers)); + REQUIRE(headers.size() == 2); + for (int f = 0; f < 2; f ++) + { + logger->log("test header: %s, %u, %u", + headers[f]->fileName.c_str(), + headers[f]->compressSize, + headers[f]->uncompressSize); + uint8_t *const buf = Zip::readFile(headers[f]); + REQUIRE(buf != nullptr); + delete [] buf; + } + } + + delete_all(headers); + delete2(logger); +} |