#include #include #include "backend/formats/ImageUrl.h" class ImageUrlTest : public QObject { Q_OBJECT private slots: void buildWithoutQuery() { QCOMPARE(ImageUrl::build(QStringLiteral("cbz"), QStringLiteral("page01.jpg")), QStringLiteral("image://cbz/page01.jpg")); } void buildWithSourcePath() { const QString url = ImageUrl::build(QStringLiteral("cbz"), QStringLiteral("page01.jpg"), QStringLiteral("/books/My Comic #1.cbz")); QVERIFY(url.startsWith(QStringLiteral("image://cbz/page01.jpg?src="))); // Source path must be percent-encoded (space and '#') QVERIFY(!url.contains(QLatin1Char(' '))); QVERIFY(!url.contains(QLatin1Char('#'))); } void roundTripThroughProviderId() { const QString sourcePath = QStringLiteral("/books/My Comic #1.cbz"); const QString url = ImageUrl::build(QStringLiteral("cbz"), QStringLiteral("page01.jpg"), sourcePath); // QML hands the provider everything after "image:///" const QString id = url.mid(QStringLiteral("image://cbz/").size()); const auto parsed = ImageUrl::parseProviderId(id); QCOMPARE(parsed.entry, QStringLiteral("page01.jpg")); QCOMPARE(parsed.sourcePath, sourcePath); } void providerIdWithoutQueryHasEmptySourcePath() { const auto parsed = ImageUrl::parseProviderId(QStringLiteral("page01.png")); QCOMPARE(parsed.entry, QStringLiteral("page01.png")); QVERIFY(parsed.sourcePath.isEmpty()); } void providerIdDecodesPercentEncodedEntry() { // QML percent-encodes entry names before they reach the provider const auto parsed = ImageUrl::parseProviderId(QStringLiteral("page%2001.jpg")); QCOMPARE(parsed.entry, QStringLiteral("page 01.jpg")); } }; QTEST_MAIN(ImageUrlTest) #include "ImageUrlTest.moc"