Changeset View
Changeset View
Standalone View
Standalone View
autotests/kmimeassociationstest.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
69 | }; | 69 | }; | ||
70 | 70 | | |||
71 | // Helper method for all the trader tests, comes from kmimetypetest.cpp | 71 | // Helper method for all the trader tests, comes from kmimetypetest.cpp | ||
72 | static bool offerListHasService(const KService::List &offers, | 72 | static bool offerListHasService(const KService::List &offers, | ||
73 | const QString &entryPath, | 73 | const QString &entryPath, | ||
74 | bool expected /* if set, show error if not found */) | 74 | bool expected /* if set, show error if not found */) | ||
75 | { | 75 | { | ||
76 | bool found = false; | 76 | bool found = false; | ||
77 | Q_FOREACH (const KService::Ptr &serv, offers) { | 77 | for (const KService::Ptr &serv : offers) { | ||
78 | if (serv->entryPath() == entryPath) { | 78 | if (serv->entryPath() == entryPath) { | ||
79 | if (found) { // should be there only once | 79 | if (found) { // should be there only once | ||
80 | qWarning("ERROR: %s was found twice in the list", qPrintable(entryPath)); | 80 | qWarning("ERROR: %s was found twice in the list", qPrintable(entryPath)); | ||
81 | return false; // make test fail | 81 | return false; // make test fail | ||
82 | } | 82 | } | ||
83 | found = true; | 83 | found = true; | ||
84 | } | 84 | } | ||
85 | } | 85 | } | ||
86 | if (!found && expected) { | 86 | if (!found && expected) { | ||
87 | qWarning() << "ERROR:" << entryPath << "not found in offer list. Here's the full list:"; | 87 | qWarning() << "ERROR:" << entryPath << "not found in offer list. Here's the full list:"; | ||
88 | Q_FOREACH (const KService::Ptr &serv, offers) { | 88 | for (const KService::Ptr &serv : offers) { | ||
89 | qDebug() << serv->entryPath(); | 89 | qDebug() << serv->entryPath(); | ||
90 | } | 90 | } | ||
91 | } | 91 | } | ||
92 | return found; | 92 | return found; | ||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | static void writeAppDesktopFile(const QString &path, const QStringList &mimeTypes, int initialPreference = 1) | 95 | static void writeAppDesktopFile(const QString &path, const QStringList &mimeTypes, int initialPreference = 1) | ||
96 | { | 96 | { | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 117 | { | |||
170 | KServiceFactory *factory = new FakeServiceFactory(KSycoca::self()); | 170 | KServiceFactory *factory = new FakeServiceFactory(KSycoca::self()); | ||
171 | KSycocaPrivate::self()->m_serviceFactory = factory; | 171 | KSycocaPrivate::self()->m_serviceFactory = factory; | ||
172 | QCOMPARE(KSycocaPrivate::self()->serviceFactory(), factory); | 172 | QCOMPARE(KSycocaPrivate::self()->serviceFactory(), factory); | ||
173 | 173 | | |||
174 | // For debugging: print all services and their storageId | 174 | // For debugging: print all services and their storageId | ||
175 | #if 0 | 175 | #if 0 | ||
176 | const KService::List lst = KService::allServices(); | 176 | const KService::List lst = KService::allServices(); | ||
177 | QVERIFY(!lst.isEmpty()); | 177 | QVERIFY(!lst.isEmpty()); | ||
178 | Q_FOREACH (const KService::Ptr &serv, lst) { | 178 | for (const KService::Ptr &serv : lst) { | ||
179 | qDebug() << serv->entryPath() << serv->storageId() /*<< serv->desktopEntryName()*/; | 179 | qDebug() << serv->entryPath() << serv->storageId() /*<< serv->desktopEntryName()*/; | ||
180 | } | 180 | } | ||
181 | #endif | 181 | #endif | ||
182 | 182 | | |||
183 | KService::Ptr fakeApplicationService = KService::serviceByStorageId(QStringLiteral("faketextapplication.desktop")); | 183 | KService::Ptr fakeApplicationService = KService::serviceByStorageId(QStringLiteral("faketextapplication.desktop")); | ||
184 | QVERIFY(fakeApplicationService); | 184 | QVERIFY(fakeApplicationService); | ||
185 | 185 | | |||
186 | m_mimeAppsFileContents = "[Added Associations]\n" | 186 | m_mimeAppsFileContents = "[Added Associations]\n" | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 227 | { | |||
243 | for (ExpectedResultsMap::const_iterator it = preferredApps.constBegin(), | 243 | for (ExpectedResultsMap::const_iterator it = preferredApps.constBegin(), | ||
244 | end = preferredApps.constEnd(); it != end; ++it) { | 244 | end = preferredApps.constEnd(); it != end; ++it) { | ||
245 | const QString mime = it.key(); | 245 | const QString mime = it.key(); | ||
246 | // The data for derived types and aliases isn't for this test (which only looks at mimeapps.list) | 246 | // The data for derived types and aliases isn't for this test (which only looks at mimeapps.list) | ||
247 | if (mime == QLatin1String("text/x-csrc") || mime == QLatin1String("application/msword")) { | 247 | if (mime == QLatin1String("text/x-csrc") || mime == QLatin1String("application/msword")) { | ||
248 | continue; | 248 | continue; | ||
249 | } | 249 | } | ||
250 | const QList<KServiceOffer> offers = offerHash.offersFor(mime); | 250 | const QList<KServiceOffer> offers = offerHash.offersFor(mime); | ||
251 | Q_FOREACH (const QString &service, it.value()) { | 251 | for (const QString &service : it.value()) { | ||
252 | KService::Ptr serv = KService::serviceByStorageId(service); | 252 | KService::Ptr serv = KService::serviceByStorageId(service); | ||
253 | if (serv && !offersContains(offers, serv)) { | 253 | if (serv && !offersContains(offers, serv)) { | ||
254 | qDebug() << "expected offer" << serv->entryPath() << "not in offers for" << mime << ":"; | 254 | qDebug() << "expected offer" << serv->entryPath() << "not in offers for" << mime << ":"; | ||
255 | Q_FOREACH (const KServiceOffer &offer, offers) { | 255 | for (const KServiceOffer &offer : offers) { | ||
256 | qDebug() << offer.service()->storageId(); | 256 | qDebug() << offer.service()->storageId(); | ||
257 | } | 257 | } | ||
258 | QFAIL("offer does not have servicetype"); | 258 | QFAIL("offer does not have servicetype"); | ||
259 | } | 259 | } | ||
260 | } | 260 | } | ||
261 | } | 261 | } | ||
262 | 262 | | |||
263 | for (ExpectedResultsMap::const_iterator it = removedApps.constBegin(), | 263 | for (ExpectedResultsMap::const_iterator it = removedApps.constBegin(), | ||
264 | end = removedApps.constEnd(); it != end; ++it) { | 264 | end = removedApps.constEnd(); it != end; ++it) { | ||
265 | const QString mime = it.key(); | 265 | const QString mime = it.key(); | ||
266 | const QList<KServiceOffer> offers = offerHash.offersFor(mime); | 266 | const QList<KServiceOffer> offers = offerHash.offersFor(mime); | ||
267 | Q_FOREACH (const QString &service, it.value()) { | 267 | for (const QString &service : it.value()) { | ||
268 | KService::Ptr serv = KService::serviceByStorageId(service); | 268 | KService::Ptr serv = KService::serviceByStorageId(service); | ||
269 | if (serv && offersContains(offers, serv)) { | 269 | if (serv && offersContains(offers, serv)) { | ||
270 | //qDebug() << serv.data() << serv->entryPath() << "does not have" << mime; | 270 | //qDebug() << serv.data() << serv->entryPath() << "does not have" << mime; | ||
271 | QFAIL("offer should not have servicetype"); | 271 | QFAIL("offer should not have servicetype"); | ||
272 | } | 272 | } | ||
273 | } | 273 | } | ||
274 | } | 274 | } | ||
275 | } | 275 | } | ||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | 470 | { | |||
474 | mimeAppsFile.write(contents); | 474 | mimeAppsFile.write(contents); | ||
475 | mimeAppsFile.close(); | 475 | mimeAppsFile.close(); | ||
476 | 476 | | |||
477 | runKBuildSycoca(); | 477 | runKBuildSycoca(); | ||
478 | } | 478 | } | ||
479 | 479 | | |||
480 | static bool offersContains(const QList<KServiceOffer> &offers, KService::Ptr serv) | 480 | static bool offersContains(const QList<KServiceOffer> &offers, KService::Ptr serv) | ||
481 | { | 481 | { | ||
482 | Q_FOREACH (const KServiceOffer &offer, offers) { | 482 | for (const KServiceOffer &offer : offers) { | ||
483 | if (offer.service()->storageId() == serv->storageId()) { | 483 | if (offer.service()->storageId() == serv->storageId()) { | ||
484 | return true; | 484 | return true; | ||
485 | } | 485 | } | ||
486 | } | 486 | } | ||
487 | return false; | 487 | return false; | ||
488 | } | 488 | } | ||
489 | static QStringList assembleOffers(const QList<KServiceOffer> &offers) | 489 | static QStringList assembleOffers(const QList<KServiceOffer> &offers) | ||
490 | { | 490 | { | ||
491 | QStringList lst; | 491 | QStringList lst; | ||
492 | Q_FOREACH (const KServiceOffer &offer, offers) { | 492 | for (const KServiceOffer &offer : offers) { | ||
493 | lst.append(offer.service()->storageId()); | 493 | lst.append(offer.service()->storageId()); | ||
494 | } | 494 | } | ||
495 | return lst; | 495 | return lst; | ||
496 | } | 496 | } | ||
497 | static QStringList assembleServices(const QList<KService::Ptr> &services, int maxCount = -1) | 497 | static QStringList assembleServices(const QList<KService::Ptr> &services, int maxCount = -1) | ||
498 | { | 498 | { | ||
499 | QStringList lst; | 499 | QStringList lst; | ||
500 | Q_FOREACH (const KService::Ptr &service, services) { | 500 | for (const KService::Ptr &service : services) { | ||
501 | lst.append(service->storageId()); | 501 | lst.append(service->storageId()); | ||
502 | if (maxCount > -1 && lst.count() == maxCount) { | 502 | if (maxCount > -1 && lst.count() == maxCount) { | ||
503 | break; | 503 | break; | ||
504 | } | 504 | } | ||
505 | } | 505 | } | ||
506 | return lst; | 506 | return lst; | ||
507 | } | 507 | } | ||
508 | 508 | | |||
Show All 35 Lines |