[frameworks/kio] autotests: autotests: ask the mime database which type a test means
Méven Car <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 71fcfa96e292a15d395b2c756bb03afff1063d90 by Méven Car.
Committed on 10/08/2026 at 10:13.
Pushed by meven into branch 'master'.
autotests: ask the mime database which type a test means
shared-mime-info 2.5.1 made application/x-shellscript another name of
text/x-shellscript and made text/x-csrc a kind of text/x-c++src. Tests
that spell those names out fail on the renames alone, although the files
they look at are the same as ever.
M +3 -1 autotests/kdirlistertest.cpp
M +7 -2 autotests/mimetypefinderjobtest.cpp
https://invent.kde.org/frameworks/kio/-/commit/71fcfa96e292a15d395b2c756bb03afff1063d90
diff --git a/autotests/kdirlistertest.cpp b/autotests/kdirlistertest.cpp
index d45472757a..4fa88be50b 100644
--- a/autotests/kdirlistertest.cpp
+++ b/autotests/kdirlistertest.cpp
@@ -1536,7 +1536,9 @@ void KDirListerTest::testMimeFilter_data()
const QStringList files = {"bla.txt", "main.cpp", "main.c", "image.jpeg", "picture.png"};
- QTest::newRow("single_file_exact_mimetype") << files << QStringList{"text/x-c++src"} << QStringList{"main.cpp"};
+ // Not a C or C++ source: shared-mime-info made C source a kind of C++ source, so a
+ // filter on one of them takes both and says nothing about matching a type exactly.
+ QTest::newRow("single_file_exact_mimetype") << files << QStringList{"image/png"} << QStringList{"picture.png"};
QTest::newRow("inherited_mimetype") << files << QStringList{"text/plain"} << QStringList{"bla.txt", "main.cpp", "main.c"};
QTest::newRow("no_match") << files << QStringList{"audio/flac"} << QStringList{};
QTest::newRow("glob") << files << QStringList{"image/*"} << QStringList{"image.jpeg", "picture.png"};
diff --git a/autotests/mimetypefinderjobtest.cpp b/autotests/mimetypefinderjobtest.cpp
index 9a41ac7fc3..0be00dd119 100644
--- a/autotests/mimetypefinderjobtest.cpp
+++ b/autotests/mimetypefinderjobtest.cpp
@@ -12,6 +12,7 @@
#include <KConfigGroup>
#include <KSharedConfig>
+#include <QMimeDatabase>
#include <QStandardPaths>
#include <QTemporaryDir>
#include <QTest>
@@ -74,7 +75,11 @@ void MimeTypeFinderJobTest::determineMimeType()
// When running a MimeTypeFinderJob
KIO::MimeTypeFinderJob *job = new KIO::MimeTypeFinderJob(url, this);
QVERIFY2(job->exec(), qPrintable(job->errorString()));
- QCOMPARE(job->mimeType(), mimeType);
+ // The database gives a type one name of its own and knows it under others as well, so
+ // both sides are asked which type they mean rather than compared as they are spelled.
+ QMimeDatabase db;
+ const QString expected = db.mimeTypeForName(mimeType).name();
+ QCOMPARE(db.mimeTypeForName(job->mimeType()).name(), expected);
// Check that the result is the same when accessing the source, skip on Windows
#ifndef Q_OS_WIN
@@ -86,7 +91,7 @@ void MimeTypeFinderJobTest::determineMimeType()
job = new KIO::MimeTypeFinderJob(linkUrl, this);
QVERIFY2(job->exec(), qPrintable(job->errorString()));
- QCOMPARE(job->mimeType(), mimeType);
+ QCOMPARE(db.mimeTypeForName(job->mimeType()).name(), expected);
#endif
}