#include "../import/EpubParser.hpp" #include #include #include #include #include #include namespace { void writeFile(const std::filesystem::path& path, const std::string& content) { std::filesystem::create_directories(path.parent_path()); std::ofstream file(path); file << content; } std::string readFile(const std::filesystem::path& path) { std::ifstream file(path); return {std::istreambuf_iterator(file), std::istreambuf_iterator()}; } bool containsPath(const std::vector& paths, const std::filesystem::path& expectedPath) { return std::find(paths.begin(), paths.end(), expectedPath.string()) != paths.end(); } } // namespace int main(int argc, char** argv) { assert(argc == 2); const std::filesystem::path fixtureDirectory = argv[1]; std::filesystem::remove_all(fixtureDirectory); writeFile( fixtureDirectory / "META-INF/container.xml", R"xml( )xml"); writeFile( fixtureDirectory / "OEBPS/content.opf", R"xml( Image fixture )xml"); writeFile( fixtureDirectory / "OEBPS/toc.ncx", R"xml( Chapter )xml"); writeFile( fixtureDirectory / "OEBPS/Text/chapter.xhtml", R"xml( Chapter art )xml"); writeFile( fixtureDirectory / "OEBPS/Text/cover.xhtml", R"xml()xml"); const EpubMetadata metadata = parseEpub(fixtureDirectory.string()); const std::filesystem::path imageDirectory = fixtureDirectory / "OEBPS/Images"; assert(metadata.name == "Image fixture"); assert(metadata.imagePaths.size() == 5); assert(containsPath(metadata.imagePaths, imageDirectory / "cover.jpg")); assert(containsPath(metadata.imagePaths, imageDirectory / "illustration.png")); assert(containsPath(metadata.imagePaths, imageDirectory / "illustration.webp")); assert(containsPath(metadata.imagePaths, imageDirectory / "illustration.gif")); assert(containsPath(metadata.imagePaths, imageDirectory / "illustration.svg")); assert(metadata.cover == (imageDirectory / "cover.jpg").string()); assert(metadata.chapters.size() == 2); assert(metadata.chapters.front().path == (fixtureDirectory / "OEBPS/Text/cover.xhtml").string()); assert(metadata.chapters[1].name == "Chapter"); const std::string coverChapter = readFile(fixtureDirectory / "OEBPS/Text/cover.xhtml"); assert(coverChapter.find("