hopefully true virtual list layout
This commit is contained in:
10 files changed
+522
-37
No files matched your search
@@ -189,6 +189,124 @@ private slots:
|
||||
QVERIFY(!reader.chunks().isEmpty());
|
||||
QVERIFY(reader.chunks().first().contains(QStringLiteral("Hello EPUB 3")));
|
||||
}
|
||||
|
||||
void chapterWrapperUnwrappedIntoGranularChunks()
|
||||
{
|
||||
auto src = std::make_unique<InMemoryByteSource>();
|
||||
|
||||
src->m_entries.insert(QStringLiteral("META-INF/container.xml"),
|
||||
"<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\n"
|
||||
" <rootfiles>\n"
|
||||
" <rootfile full-path=\"EPUB/package.opf\" media-type=\"application/oebps-package+xml\"/>\n"
|
||||
" </rootfiles>\n"
|
||||
"</container>");
|
||||
|
||||
src->m_entries.insert(QStringLiteral("EPUB/package.opf"),
|
||||
"<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\">\n"
|
||||
" <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
|
||||
" <dc:title>Unwrap Test</dc:title>\n"
|
||||
" </metadata>\n"
|
||||
" <manifest>\n"
|
||||
" <item id=\"c1\" href=\"ch1.xhtml\" media-type=\"application/xhtml+xml\"/>\n"
|
||||
" </manifest>\n"
|
||||
" <spine>\n"
|
||||
" <itemref idref=\"c1\"/>\n"
|
||||
" </spine>\n"
|
||||
"</package>");
|
||||
|
||||
// Generates several long paragraphs inside a single wrapper div
|
||||
QString xhtml = QStringLiteral(
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\"><body>\n"
|
||||
"<div class=\"calibre1\" style=\"text-align: justify;\">\n"
|
||||
);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
xhtml += QStringLiteral("<p>This is paragraph %1 with sufficient text to exceed the target chunk size when combined together with other paragraphs in the chapter.</p>\n").arg(i);
|
||||
}
|
||||
xhtml += QStringLiteral("</div></body></html>");
|
||||
|
||||
src->m_entries.insert(QStringLiteral("EPUB/ch1.xhtml"), xhtml.toUtf8());
|
||||
|
||||
auto sharedEntries = std::make_shared<QHash<QString, QByteArray>>(src->m_entries);
|
||||
auto factory = [sharedEntries]() {
|
||||
auto s = std::make_unique<InMemoryByteSource>();
|
||||
s->m_entries = *sharedEntries;
|
||||
return s;
|
||||
};
|
||||
|
||||
EpubReader reader(factory, QStringLiteral("epub"));
|
||||
QVERIFY(reader.open(QStringLiteral("/virtual/unwrap.epub")));
|
||||
|
||||
// Must be split into multiple granular chunks instead of one single monolithic chunk
|
||||
QVERIFY(reader.chunks().size() >= 3);
|
||||
// Children must inherit text-align: justify
|
||||
for (const QString &c : reader.chunks()) {
|
||||
QVERIFY(c.contains(QStringLiteral("text-align:justify")) || c.contains(QStringLiteral("text-align: justify")));
|
||||
}
|
||||
}
|
||||
|
||||
void divParagraphWithInlineElementsNotBroken()
|
||||
{
|
||||
auto src = std::make_unique<InMemoryByteSource>();
|
||||
|
||||
src->m_entries.insert(QStringLiteral("META-INF/container.xml"),
|
||||
"<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\n"
|
||||
" <rootfiles>\n"
|
||||
" <rootfile full-path=\"EPUB/package.opf\" media-type=\"application/oebps-package+xml\"/>\n"
|
||||
" </rootfiles>\n"
|
||||
"</container>");
|
||||
|
||||
src->m_entries.insert(QStringLiteral("EPUB/package.opf"),
|
||||
"<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\">\n"
|
||||
" <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"
|
||||
" <dc:title>Inline Div Test</dc:title>\n"
|
||||
" </metadata>\n"
|
||||
" <manifest>\n"
|
||||
" <item id=\"c1\" href=\"ch1.xhtml\" media-type=\"application/xhtml+xml\"/>\n"
|
||||
" </manifest>\n"
|
||||
" <spine>\n"
|
||||
" <itemref idref=\"c1\"/>\n"
|
||||
" </spine>\n"
|
||||
"</package>");
|
||||
|
||||
QString xhtml = QStringLiteral(
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\"><body>\n"
|
||||
"<div class=\"calibre1\">\n"
|
||||
" <div class=\"p\">«<em>Одноглазый</em>».</div>\n"
|
||||
" <div class=\"p\"><em>«Когда я умру, они съедят меня и оставят только кости»</em>, — эта мысль странным образом утешала.</div>\n"
|
||||
"</div></body></html>"
|
||||
);
|
||||
src->m_entries.insert(QStringLiteral("EPUB/ch1.xhtml"), xhtml.toUtf8());
|
||||
|
||||
auto sharedEntries = std::make_shared<QHash<QString, QByteArray>>(src->m_entries);
|
||||
auto factory = [sharedEntries]() {
|
||||
auto s = std::make_unique<InMemoryByteSource>();
|
||||
s->m_entries = *sharedEntries;
|
||||
return s;
|
||||
};
|
||||
|
||||
EpubReader reader(factory, QStringLiteral("epub"));
|
||||
QVERIFY(reader.open(QStringLiteral("/virtual/inline_div.epub")));
|
||||
|
||||
bool foundOdnoglazyiTogether = false;
|
||||
bool foundThoughtTogether = false;
|
||||
|
||||
for (const QString &chunk : reader.chunks()) {
|
||||
if (chunk.contains(QStringLiteral("Одноглазый"))) {
|
||||
// Must have both opening and closing quotes together in the same chunk
|
||||
QVERIFY(chunk.contains(QStringLiteral("«")));
|
||||
QVERIFY(chunk.contains(QStringLiteral("»")));
|
||||
foundOdnoglazyiTogether = true;
|
||||
}
|
||||
if (chunk.contains(QStringLiteral("Когда я умру"))) {
|
||||
// Must have the attribution text in the same chunk
|
||||
QVERIFY(chunk.contains(QStringLiteral("эта мысль странным образом утешала")));
|
||||
foundThoughtTogether = true;
|
||||
}
|
||||
}
|
||||
|
||||
QVERIFY(foundOdnoglazyiTogether);
|
||||
QVERIFY(foundThoughtTogether);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(EpubReaderTest)
|
||||
|
||||
Reference in new issue
Block a user