// test.cpp
#include"../SimZip.h"#include<catch2/catch_test_macros.hpp>#include<fstream>#include<filesystem>voidgenerateData(){std::ofstreamfile("data.txt");if(file.is_open()){for(autoi=0;i<10;i++){file<<"this is data for test.";}file.close();}}TEST_CASE("create zip","[create_zip]"){generateData();SimZipzip("test.zip",SimZip::OpenMode::Create);REQUIRE(zip.add("data.txt")==true);REQUIRE(zip.add("data.txt","folder/rename.txt")==true);REQUIRE(zip.add("empty.txt")==false);zip.save();}TEST_CASE("extract zip","[extract_zip]"){SimZipzip("test.zip",SimZip::OpenMode::Read);SECTION("Extract single file from zip"){zip.extract("data.txt","output/");REQUIRE(fs::exists("output/data.txt"));}SECTION("Extract all files from zip"){zip.extractall("output/");std::vector<std::string>expected_files={"data.txt","folder/rename.txt"};for(constauto&file:expected_files){REQUIRE(fs::exists("output/"+file));}}}
预览: