Changeset View
Changeset View
Standalone View
Standalone View
autotests/kservicetest.cpp
Show First 20 Lines • Show All 242 Lines • ▼ Show 20 Line(s) | 240 | if (spy.isEmpty()) { | |||
---|---|---|---|---|---|
243 | qDebug() << "got signal"; | 243 | qDebug() << "got signal"; | ||
244 | } | 244 | } | ||
245 | } | 245 | } | ||
246 | 246 | | |||
247 | void KServiceTest::cleanupTestCase() | 247 | void KServiceTest::cleanupTestCase() | ||
248 | { | 248 | { | ||
249 | // If I want the konqueror unit tests to work, then I better not have a non-working part | 249 | // If I want the konqueror unit tests to work, then I better not have a non-working part | ||
250 | // as the preferred part for text/plain... | 250 | // as the preferred part for text/plain... | ||
251 | QStringList services; services << QStringLiteral("fakeservice.desktop") << QStringLiteral("fakepart.desktop") << QStringLiteral("faketextplugin.desktop") << QStringLiteral("fakeservice_querymustrebuild.desktop"); | 251 | const QStringList services = QStringList() << QStringLiteral("fakeservice.desktop") << QStringLiteral("fakepart.desktop") << QStringLiteral("faketextplugin.desktop") << QStringLiteral("fakeservice_querymustrebuild.desktop"); | ||
252 | Q_FOREACH (const QString &service, services) { | 252 | for (const QString &service : services) { | ||
253 | const QString fakeService = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/") + service; | 253 | const QString fakeService = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/") + service; | ||
254 | QFile::remove(fakeService); | 254 | QFile::remove(fakeService); | ||
255 | } | 255 | } | ||
256 | QStringList serviceTypes; serviceTypes << QStringLiteral("fakeplugintype.desktop"); | 256 | const QStringList serviceTypes = QStringList() << QStringLiteral("fakeplugintype.desktop"); | ||
257 | Q_FOREACH (const QString &serviceType, serviceTypes) { | 257 | for (const QString &serviceType : serviceTypes) { | ||
258 | const QString fakeServiceType = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservicetypes5/") + serviceType; | 258 | const QString fakeServiceType = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservicetypes5/") + serviceType; | ||
259 | //QFile::remove(fakeServiceType); | 259 | //QFile::remove(fakeServiceType); | ||
260 | } | 260 | } | ||
261 | KBuildSycoca builder; | 261 | KBuildSycoca builder; | ||
262 | builder.recreate(); | 262 | builder.recreate(); | ||
263 | } | 263 | } | ||
264 | 264 | | |||
265 | void KServiceTest::testByName() | 265 | void KServiceTest::testByName() | ||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 470 | { | |||
475 | // Querying trader for services associated with FakeBasePart | 475 | // Querying trader for services associated with FakeBasePart | ||
476 | KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("FakeBasePart")); | 476 | KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("FakeBasePart")); | ||
477 | QVERIFY(offers.count() > 0); | 477 | QVERIFY(offers.count() > 0); | ||
478 | 478 | | |||
479 | if (!offerListHasService(offers, QStringLiteral("fakepart.desktop")) | 479 | if (!offerListHasService(offers, QStringLiteral("fakepart.desktop")) | ||
480 | || !offerListHasService(offers, QStringLiteral("fakepart2.desktop")) | 480 | || !offerListHasService(offers, QStringLiteral("fakepart2.desktop")) | ||
481 | || !offerListHasService(offers, QStringLiteral("otherpart.desktop")) | 481 | || !offerListHasService(offers, QStringLiteral("otherpart.desktop")) | ||
482 | || !offerListHasService(offers, QStringLiteral("preferredpart.desktop"))) { | 482 | || !offerListHasService(offers, QStringLiteral("preferredpart.desktop"))) { | ||
483 | foreach (KService::Ptr service, offers) { | 483 | for (KService::Ptr service : qAsConst(offers)) { | ||
484 | qDebug("%s %s", qPrintable(service->name()), qPrintable(service->entryPath())); | 484 | qDebug("%s %s", qPrintable(service->name()), qPrintable(service->entryPath())); | ||
485 | } | 485 | } | ||
486 | } | 486 | } | ||
487 | 487 | | |||
488 | m_firstOffer = offers[0]->entryPath(); | 488 | m_firstOffer = offers[0]->entryPath(); | ||
489 | 489 | | |||
490 | QVERIFY(offerListHasService(offers, QStringLiteral("fakepart.desktop"))); | 490 | QVERIFY(offerListHasService(offers, QStringLiteral("fakepart.desktop"))); | ||
491 | QVERIFY(offerListHasService(offers, QStringLiteral("fakepart2.desktop"))); | 491 | QVERIFY(offerListHasService(offers, QStringLiteral("fakepart2.desktop"))); | ||
492 | QVERIFY(offerListHasService(offers, QStringLiteral("otherpart.desktop"))); | 492 | QVERIFY(offerListHasService(offers, QStringLiteral("otherpart.desktop"))); | ||
493 | QVERIFY(offerListHasService(offers, QStringLiteral("preferredpart.desktop"))); | 493 | QVERIFY(offerListHasService(offers, QStringLiteral("preferredpart.desktop"))); | ||
494 | 494 | | |||
495 | // Check ordering according to InitialPreference | 495 | // Check ordering according to InitialPreference | ||
496 | int lastPreference = -1; | 496 | int lastPreference = -1; | ||
497 | bool lastAllowedAsDefault = true; | 497 | bool lastAllowedAsDefault = true; | ||
498 | Q_FOREACH (KService::Ptr service, offers) { | 498 | for (KService::Ptr service : qAsConst(offers)) { | ||
499 | const QString path = service->entryPath(); | 499 | const QString path = service->entryPath(); | ||
500 | const int preference = service->initialPreference(); // ## might be wrong if we use per-servicetype preferences... | 500 | const int preference = service->initialPreference(); // ## might be wrong if we use per-servicetype preferences... | ||
501 | //qDebug( "%s has preference %d, allowAsDefault=%d", qPrintable( path ), preference, service->allowAsDefault() ); | 501 | //qDebug( "%s has preference %d, allowAsDefault=%d", qPrintable( path ), preference, service->allowAsDefault() ); | ||
502 | if (lastAllowedAsDefault && !service->allowAsDefault()) { | 502 | if (lastAllowedAsDefault && !service->allowAsDefault()) { | ||
503 | // first "not allowed as default" offer | 503 | // first "not allowed as default" offer | ||
504 | lastAllowedAsDefault = false; | 504 | lastAllowedAsDefault = false; | ||
505 | lastPreference = -1; // restart | 505 | lastPreference = -1; // restart | ||
506 | } | 506 | } | ||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | |||||
634 | void KServiceTest::testWriteServiceTypeProfile() | 634 | void KServiceTest::testWriteServiceTypeProfile() | ||
635 | { | 635 | { | ||
636 | const QString serviceType = QStringLiteral("FakeBasePart"); | 636 | const QString serviceType = QStringLiteral("FakeBasePart"); | ||
637 | KService::List services, disabledServices; | 637 | KService::List services, disabledServices; | ||
638 | services.append(KService::serviceByDesktopPath(QStringLiteral("preferredpart.desktop"))); | 638 | services.append(KService::serviceByDesktopPath(QStringLiteral("preferredpart.desktop"))); | ||
639 | services.append(KService::serviceByDesktopPath(QStringLiteral("fakepart.desktop"))); | 639 | services.append(KService::serviceByDesktopPath(QStringLiteral("fakepart.desktop"))); | ||
640 | disabledServices.append(KService::serviceByDesktopPath(QStringLiteral("fakepart2.desktop"))); | 640 | disabledServices.append(KService::serviceByDesktopPath(QStringLiteral("fakepart2.desktop"))); | ||
641 | 641 | | |||
642 | Q_FOREACH (const KService::Ptr &serv, services) { | 642 | for (const KService::Ptr &serv : qAsConst(services)) { | ||
643 | QVERIFY(serv); | 643 | QVERIFY(serv); | ||
644 | } | 644 | } | ||
645 | Q_FOREACH (const KService::Ptr &serv, disabledServices) { | 645 | for (const KService::Ptr &serv : qAsConst(disabledServices)) { | ||
646 | QVERIFY(serv); | 646 | QVERIFY(serv); | ||
647 | } | 647 | } | ||
648 | 648 | | |||
649 | KServiceTypeProfile::writeServiceTypeProfile(serviceType, services, disabledServices); | 649 | KServiceTypeProfile::writeServiceTypeProfile(serviceType, services, disabledServices); | ||
650 | 650 | | |||
651 | // Check that the file got written | 651 | // Check that the file got written | ||
652 | QString profilerc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/servicetype_profilerc"; | 652 | QString profilerc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/servicetype_profilerc"; | ||
653 | QVERIFY(!profilerc.isEmpty()); | 653 | QVERIFY(!profilerc.isEmpty()); | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 717 | { | |||
722 | KServiceGroup::Ptr group = root; | 722 | KServiceGroup::Ptr group = root; | ||
723 | QVERIFY(group); | 723 | QVERIFY(group); | ||
724 | const KServiceGroup::List list = group->entries(true /* sorted */, | 724 | const KServiceGroup::List list = group->entries(true /* sorted */, | ||
725 | true /* exclude no display entries */, | 725 | true /* exclude no display entries */, | ||
726 | false /* allow separators */, | 726 | false /* allow separators */, | ||
727 | true /* sort by generic name */); | 727 | true /* sort by generic name */); | ||
728 | 728 | | |||
729 | qDebug() << list.count(); | 729 | qDebug() << list.count(); | ||
730 | Q_FOREACH (KServiceGroup::SPtr s, list) { | 730 | for (KServiceGroup::SPtr s : list) { | ||
731 | qDebug() << s->name() << s->entryPath(); | 731 | qDebug() << s->name() << s->entryPath(); | ||
732 | } | 732 | } | ||
733 | 733 | | |||
734 | // No unit test here yet, but at least this can be valgrinded for errors. | 734 | // No unit test here yet, but at least this can be valgrinded for errors. | ||
735 | } | 735 | } | ||
736 | 736 | | |||
737 | void KServiceTest::testDeletingService() | 737 | void KServiceTest::testDeletingService() | ||
738 | { | 738 | { | ||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |