Commit 676dabdd authored by David Faure's avatar David Faure
Browse files

autotests: ensure there's at least one application for text/plain

+ many cleanups

Should fix CI
parent 643123d0
...@@ -61,30 +61,21 @@ private Q_SLOTS: ...@@ -61,30 +61,21 @@ private Q_SLOTS:
QVERIFY(QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/mime/packages"))); QVERIFY(QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/mime/packages")));
QFile::remove(m_localConfig.filePath(QStringLiteral("mimeapps.list"))); QFile::remove(m_localConfig.filePath(QStringLiteral("mimeapps.list")));
QFile::remove(m_localConfig.filePath(QStringLiteral("filetypesrc")));
// Create fake applications for some tests below. // Create fake applications for some tests below.
bool mustUpdateKSycoca = false;
fakeApplication = QStringLiteral("fakeapplication.desktop"); fakeApplication = QStringLiteral("fakeapplication.desktop");
if (createDesktopFile(m_localApps + fakeApplication)) createDesktopFile(m_localApps + fakeApplication, {QStringLiteral("image/png")});
mustUpdateKSycoca = true;
fakeApplication2 = QStringLiteral("fakeapplication2.desktop"); fakeApplication2 = QStringLiteral("fakeapplication2.desktop");
if (createDesktopFile(m_localApps + fakeApplication2)) createDesktopFile(m_localApps + fakeApplication2, {QStringLiteral("image/png"), QStringLiteral("text/plain")});
mustUpdateKSycoca = true;
// Cleanup after testMimeTypePatterns if it failed mid-way // Cleanup after testMimeTypePatterns if it failed mid-way
const QString packageFileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/mime/") + QStringLiteral("packages/text-plain.xml") ; const QString packageFileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/mime/") + QStringLiteral("packages/text-plain.xml") ;
if (!packageFileName.isEmpty()) { if (!packageFileName.isEmpty()) {
QFile::remove(packageFileName); QFile::remove(packageFileName);
MimeTypeWriter::runUpdateMimeDatabase(); MimeTypeWriter::runUpdateMimeDatabase();
mustUpdateKSycoca = true;
} }
QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + QStringLiteral("filetypesrc"));
if ( mustUpdateKSycoca ) {
// Update ksycoca in ~/.kde-unit-test after creating the above
runKBuildSycoca();
}
KService::Ptr fakeApplicationService = KService::serviceByStorageId(fakeApplication); KService::Ptr fakeApplicationService = KService::serviceByStorageId(fakeApplication);
QVERIFY(fakeApplicationService); QVERIFY(fakeApplicationService);
} }
...@@ -197,8 +188,7 @@ private Q_SLOTS: ...@@ -197,8 +188,7 @@ private Q_SLOTS:
MimeTypeData data(db.mimeTypeForName(mimeTypeName)); MimeTypeData data(db.mimeTypeForName(mimeTypeName));
QStringList appServices = data.appServices(); QStringList appServices = data.appServices();
//qDebug() << appServices; //qDebug() << appServices;
QVERIFY(!appServices.isEmpty()); QVERIFY(appServices.contains(fakeApplication2));
const QString oldPreferredApp = appServices.first();
QVERIFY(!appServices.contains(fakeApplication)); // already there? hmm can't really test then QVERIFY(!appServices.contains(fakeApplication)); // already there? hmm can't really test then
QVERIFY(!data.isDirty()); QVERIFY(!data.isDirty());
appServices.prepend(fakeApplication); appServices.prepend(fakeApplication);
...@@ -333,7 +323,6 @@ private Q_SLOTS: ...@@ -333,7 +323,6 @@ private Q_SLOTS:
QVERIFY(data.isDirty()); QVERIFY(data.isDirty());
QVERIFY(data.sync()); QVERIFY(data.sync());
MimeTypeWriter::runUpdateMimeDatabase(); MimeTypeWriter::runUpdateMimeDatabase();
//runKBuildSycoca();
QMimeType mime = db.mimeTypeForName(mimeTypeName); QMimeType mime = db.mimeTypeForName(mimeTypeName);
QVERIFY(mime.isValid()); QVERIFY(mime.isValid());
QCOMPARE(mime.comment(), fakeComment); QCOMPARE(mime.comment(), fakeComment);
...@@ -345,8 +334,9 @@ private Q_SLOTS: ...@@ -345,8 +334,9 @@ private Q_SLOTS:
void cleanupTestCase() void cleanupTestCase()
{ {
// If we remove it, then every run of the unit test has to run kbuildsycoca... slow. const QString localAppsDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
//QFile::remove(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QLatin1Char('/') + "fakeapplication.desktop"); QFile::remove(localAppsDir + QLatin1String("/fakeapplication.desktop"));
QFile::remove(localAppsDir + QLatin1String("/fakeapplication2.desktop"));
} }
private: // helper methods private: // helper methods
...@@ -403,18 +393,14 @@ private: // helper methods ...@@ -403,18 +393,14 @@ private: // helper methods
qDebug() << "got signal"; qDebug() << "got signal";
} }
bool createDesktopFile(const QString& path) void createDesktopFile(const QString& path, const QStringList &mimeTypes)
{ {
if (!QFile::exists(path)) { KDesktopFile file(path);
KDesktopFile file(path); KConfigGroup group = file.desktopGroup();
KConfigGroup group = file.desktopGroup(); group.writeEntry("Name", "FakeApplication");
group.writeEntry("Name", "FakeApplication"); group.writeEntry("Type", "Application");
group.writeEntry("Type", "Application"); group.writeEntry("Exec", "ls");
group.writeEntry("Exec", "ls"); group.writeXdgListEntry("MimeType", mimeTypes);
group.writeEntry("MimeType", "image/png");
return true;
}
return false;
} }
void checkMimeTypeServices(const QString& mimeTypeName, const QStringList& expectedServices) void checkMimeTypeServices(const QString& mimeTypeName, const QStringList& expectedServices)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment