91 lines
2.8 KiB
C++
91 lines
2.8 KiB
C++
#include "../import/EpubParser.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
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;
|
|
}
|
|
|
|
bool containsPath(const std::vector<std::string>& 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 version="1.0"?>
|
|
<container>
|
|
<rootfiles>
|
|
<rootfile full-path="OEBPS/content.opf"/>
|
|
</rootfiles>
|
|
</container>)xml");
|
|
|
|
writeFile(
|
|
fixtureDirectory / "OEBPS/content.opf",
|
|
R"xml(<?xml version="1.0"?>
|
|
<package version="3.0">
|
|
<metadata>
|
|
<dc:title>Image fixture</dc:title>
|
|
</metadata>
|
|
<manifest>
|
|
<item id="nav" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
|
<item id="chapter" href="Text/chapter.xhtml" media-type="application/xhtml+xml"/>
|
|
<item id="jpeg" href="Images/cover.jpg" media-type="image/jpeg"/>
|
|
<item id="png" href="Images/illustration.png" media-type="image/png"/>
|
|
<item id="webp" href="Images/illustration.webp" media-type="image/webp"/>
|
|
<item id="gif" href="Images/illustration.gif" media-type="image/gif"/>
|
|
<item id="svg" href="Images/illustration.svg" media-type="image/svg+xml"/>
|
|
</manifest>
|
|
<spine>
|
|
<itemref idref="chapter"/>
|
|
</spine>
|
|
</package>)xml");
|
|
|
|
writeFile(
|
|
fixtureDirectory / "OEBPS/toc.ncx",
|
|
R"xml(<?xml version="1.0"?>
|
|
<ncx>
|
|
<navMap>
|
|
<navPoint>
|
|
<navLabel><text>Chapter</text></navLabel>
|
|
<content src="Text/chapter.xhtml"/>
|
|
</navPoint>
|
|
</navMap>
|
|
</ncx>)xml");
|
|
writeFile(fixtureDirectory / "OEBPS/Text/chapter.xhtml",
|
|
"<html><body>Chapter</body></html>");
|
|
|
|
const EpubMetadata metadata = parseEpub(fixtureDirectory.string());
|
|
const std::filesystem::path imageDirectory = fixtureDirectory / "OEBPS/Images";
|
|
|
|
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"));
|
|
|
|
return 0;
|
|
}
|