more performance optimizations + cleanup
This commit is contained in:
15 files changed
+396
-469
No files matched your search
@@ -123,14 +123,33 @@ private slots:
|
||||
|
||||
QVERIFY(!reader.chunks().isEmpty());
|
||||
|
||||
QString fullHtml = reader.chunks().join(QString());
|
||||
// Verify CSS styling inlined
|
||||
QVERIFY(fullHtml.contains(QStringLiteral("color:red")) || fullHtml.contains(QStringLiteral("italic")));
|
||||
// Verify embedded image resolved to image://epub/ with source path
|
||||
QVERIFY(fullHtml.contains(QStringLiteral("image://epub/OEBPS/images/fig1.png")));
|
||||
QVERIFY(fullHtml.contains(QStringLiteral("src=%2Fvirtual%2Fbook.epub")) || fullHtml.contains(QStringLiteral("src=/virtual/book.epub")));
|
||||
// Verify web image resolved to image://web/
|
||||
QVERIFY(fullHtml.contains(QStringLiteral("image://web/https://example.com/pic.jpg")));
|
||||
bool foundColorOrItalic = false;
|
||||
bool foundEpubImage = false;
|
||||
bool foundWebImage = false;
|
||||
|
||||
for (const auto &chunk : reader.chunks()) {
|
||||
QCOMPARE(chunk.sectionHref, QStringLiteral("OEBPS/text/ch1.xhtml"));
|
||||
for (const auto &b : chunk.blocks) {
|
||||
for (const auto &inl : b.inlines) {
|
||||
if (inl.style.color == QColor(Qt::red) || inl.style.italic) {
|
||||
foundColorOrItalic = true;
|
||||
}
|
||||
if (inl.kind == InlineItem::Kind::Image) {
|
||||
if (inl.imageUrl.contains(QStringLiteral("image://epub/OEBPS/images/fig1.png"))
|
||||
&& (inl.imageUrl.contains(QStringLiteral("src=%2Fvirtual%2Fbook.epub")) || inl.imageUrl.contains(QStringLiteral("src=/virtual/book.epub")))) {
|
||||
foundEpubImage = true;
|
||||
}
|
||||
if (inl.imageUrl.contains(QStringLiteral("image://web/https://example.com/pic.jpg"))) {
|
||||
foundWebImage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVERIFY(foundColorOrItalic);
|
||||
QVERIFY(foundEpubImage);
|
||||
QVERIFY(foundWebImage);
|
||||
}
|
||||
|
||||
void openEpub3WithNavDocument()
|
||||
@@ -187,7 +206,17 @@ private slots:
|
||||
QStringLiteral("EPUB/cover.png"),
|
||||
QStringLiteral("/virtual/epub3.epub")));
|
||||
QVERIFY(!reader.chunks().isEmpty());
|
||||
QVERIFY(reader.chunks().first().contains(QStringLiteral("Hello EPUB 3")));
|
||||
bool foundHello = false;
|
||||
for (const auto &chunk : reader.chunks()) {
|
||||
QCOMPARE(chunk.sectionHref, QStringLiteral("EPUB/ch1.xhtml"));
|
||||
for (const auto &b : chunk.blocks) {
|
||||
for (const auto &inl : b.inlines) {
|
||||
if (inl.text.contains(QStringLiteral("Hello EPUB 3")))
|
||||
foundHello = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
QVERIFY(foundHello);
|
||||
}
|
||||
|
||||
void chapterWrapperUnwrappedIntoGranularChunks()
|
||||
@@ -239,8 +268,13 @@ private slots:
|
||||
// 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")));
|
||||
for (const auto &chunk : reader.chunks()) {
|
||||
QCOMPARE(chunk.sectionHref, QStringLiteral("EPUB/ch1.xhtml"));
|
||||
for (const auto &b : chunk.blocks) {
|
||||
if (b.kind == BlockItem::Kind::Paragraph) {
|
||||
QCOMPARE(b.align, TextAlign::Justify);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,17 +324,27 @@ private slots:
|
||||
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;
|
||||
for (const auto &chunk : reader.chunks()) {
|
||||
for (const auto &b : chunk.blocks) {
|
||||
if (b.kind != BlockItem::Kind::Paragraph)
|
||||
continue;
|
||||
|
||||
QString paraText;
|
||||
for (const auto &inl : b.inlines) {
|
||||
paraText += inl.text;
|
||||
}
|
||||
|
||||
if (paraText.contains(QStringLiteral("Одноглазый"))) {
|
||||
// Must have both opening and closing quotes together in the same paragraph
|
||||
QVERIFY(paraText.contains(QStringLiteral("«")));
|
||||
QVERIFY(paraText.contains(QStringLiteral("»")));
|
||||
foundOdnoglazyiTogether = true;
|
||||
}
|
||||
if (paraText.contains(QStringLiteral("Когда я умру"))) {
|
||||
// Must have the attribution text in the same paragraph
|
||||
QVERIFY(paraText.contains(QStringLiteral("эта мысль странным образом утешала")));
|
||||
foundThoughtTogether = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user