epubgrep/tests/test_zip_list.cpp

45 lines
1.1 KiB
C++

#include "fs-compat.hpp"
#include "zip.hpp"
#include <catch.hpp>
#include <clocale>
#include <exception>
#include <string>
#include <vector>
SCENARIO("epubgrep::zip::list() doesn't fail and returns the right file list")
{
std::setlocale(LC_CTYPE, ""); // Needed for utf-8 support in libarchive.
bool exception{false};
std::vector<std::string> filelist;
GIVEN("Our test zip file")
{
fs::path zipfile{"test.zip"};
REQUIRE(fs::exists(zipfile));
WHEN("We list the file contents")
{
try
{
filelist = epubgrep::zip::list(zipfile);
}
catch (const std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN("It returns the file contents correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(filelist.at(0) == "test folder/");
REQUIRE(filelist.at(1) == "test folder/test file");
REQUIRE(filelist.at(2) == "test folder/😊");
}
}
}
}