Changeset View
Changeset View
Standalone View
Standalone View
autotests/kservicetest.cpp
Show All 22 Lines | |||||
23 | #include <qtest.h> | 23 | #include <qtest.h> | ||
24 | 24 | | |||
25 | #include <kconfig.h> | 25 | #include <kconfig.h> | ||
26 | #include <kconfiggroup.h> | 26 | #include <kconfiggroup.h> | ||
27 | #include <kdesktopfile.h> | 27 | #include <kdesktopfile.h> | ||
28 | #include <ksycoca.h> | 28 | #include <ksycoca.h> | ||
29 | #include <kbuildsycoca_p.h> | 29 | #include <kbuildsycoca_p.h> | ||
30 | #include <../src/services/kserviceutil_p.h> | 30 | #include <../src/services/kserviceutil_p.h> | ||
31 | #include <../src/services/ktraderparsetree_p.h> | ||||
31 | 32 | | |||
32 | #include <kservicegroup.h> | 33 | #include <kservicegroup.h> | ||
33 | #include <kservicetypetrader.h> | 34 | #include <kservicetypetrader.h> | ||
34 | #include <kservicetype.h> | 35 | #include <kservicetype.h> | ||
35 | #include <kservicetypeprofile.h> | 36 | #include <kservicetypeprofile.h> | ||
36 | #include <kpluginmetadata.h> | 37 | #include <kpluginmetadata.h> | ||
37 | #include <kplugininfo.h> | 38 | #include <kplugininfo.h> | ||
38 | 39 | | |||
▲ Show 20 Lines • Show All 501 Lines • ▼ Show 20 Line(s) | 516 | { | |||
540 | QCOMPARE(offers.count(), 1); | 541 | QCOMPARE(offers.count(), 1); | ||
541 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | 542 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | ||
542 | 543 | | |||
543 | // "contains" case insensitive | 544 | // "contains" case insensitive | ||
544 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("'teXtPluGin' ~~ Library")); // note: "is contained in", not "contains"... | 545 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("'teXtPluGin' ~~ Library")); // note: "is contained in", not "contains"... | ||
545 | QCOMPARE(offers.count(), 1); | 546 | QCOMPARE(offers.count(), 1); | ||
546 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | 547 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | ||
547 | 548 | | |||
549 | // sub-sequence case sensitive | ||||
550 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("'txtlug' subseq Library")); | ||||
551 | QCOMPARE(offers.count(), 1); | ||||
552 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | ||||
553 | | ||||
554 | // sub-sequence case insensitive | ||||
555 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("'tXtLuG' ~subseq Library")); | ||||
556 | QCOMPARE(offers.count(), 1); | ||||
557 | QVERIFY(offerListHasService(offers, QStringLiteral("faketextplugin.desktop"))); | ||||
558 | | ||||
548 | if (m_hasNonCLocale) { | 559 | if (m_hasNonCLocale) { | ||
549 | 560 | | |||
550 | // Test float parsing, must use dot as decimal separator independent of locale. | 561 | // Test float parsing, must use dot as decimal separator independent of locale. | ||
551 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("([X-KDE-Version] > 4.559) and ([X-KDE-Version] < 4.561)")); | 562 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("([X-KDE-Version] > 4.559) and ([X-KDE-Version] < 4.561)")); | ||
552 | QCOMPARE(offers.count(), 1); | 563 | QCOMPARE(offers.count(), 1); | ||
553 | QVERIFY(offerListHasService(offers, QStringLiteral("fakeservice.desktop"))); | 564 | QVERIFY(offerListHasService(offers, QStringLiteral("fakeservice.desktop"))); | ||
554 | } | 565 | } | ||
555 | 566 | | |||
556 | // A test with an invalid query, to test for memleaks | 567 | // A test with an invalid query, to test for memleaks | ||
557 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("A == B OR C == D AND OR Foo == 'Parse Error'")); | 568 | offers = KServiceTypeTrader::self()->query(QStringLiteral("FakePluginType"), QStringLiteral("A == B OR C == D AND OR Foo == 'Parse Error'")); | ||
558 | QVERIFY(offers.isEmpty()); | 569 | QVERIFY(offers.isEmpty()); | ||
559 | } | 570 | } | ||
560 | 571 | | |||
572 | void KServiceTest::testSubseqConstraints() | ||||
573 | { | ||||
574 | auto test = [](const char* pattern, const char* text, bool sensitive) { | ||||
575 | return KTraderParse::ParseTreeSubsequenceMATCH::isSubseq( | ||||
576 | QString(pattern), | ||||
577 | QString(text), | ||||
578 | sensitive? Qt::CaseSensitive : Qt::CaseInsensitive | ||||
579 | ); | ||||
580 | }; | ||||
581 | | ||||
582 | // Case Sensitive | ||||
583 | QVERIFY2(!test("", "", 1), "both empty"); | ||||
584 | QVERIFY2(!test("", "something", 1), "empty pattern"); | ||||
585 | QVERIFY2(!test("something", "", 1), "empty text"); | ||||
586 | QVERIFY2(test("lngfile", "somereallylongfile", 1), "match ending"); | ||||
587 | QVERIFY2(test("somelong", "somereallylongfile", 1), "match beginning"); | ||||
588 | QVERIFY2(test("reallylong", "somereallylongfile", 1), "match middle"); | ||||
589 | QVERIFY2(test("across", "a 23 c @#! r o01 o 5 s_s", 1), "match across"); | ||||
590 | QVERIFY2(!test("nocigar", "soclosebutnociga", 1), "close but no match"); | ||||
591 | QVERIFY2(!test("god", "dog", 1), "incorrect letter order"); | ||||
592 | QVERIFY2(!test("mismatch", "mIsMaTcH", 1), "case sensitive mismatch"); | ||||
593 | | ||||
594 | // Case insensitive | ||||
595 | QVERIFY2(test("mismatch", "mIsMaTcH", 0), "case insensitive match"); | ||||
596 | QVERIFY2(test("tryhards", "Try Your Hardest", 0), "uppercase text"); | ||||
597 | QVERIFY2(test("TRYHARDS", "try your hardest", 0), "uppercase pattern"); | ||||
598 | } | ||||
599 | | ||||
561 | void KServiceTest::testHasServiceType1() // with services constructed with a full path (rare) | 600 | void KServiceTest::testHasServiceType1() // with services constructed with a full path (rare) | ||
562 | { | 601 | { | ||
563 | QString fakepartPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + "fakepart.desktop"); | 602 | QString fakepartPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + "fakepart.desktop"); | ||
564 | QVERIFY(!fakepartPath.isEmpty()); | 603 | QVERIFY(!fakepartPath.isEmpty()); | ||
565 | KService fakepart(fakepartPath); | 604 | KService fakepart(fakepartPath); | ||
566 | QVERIFY(fakepart.hasServiceType(QStringLiteral("FakeBasePart"))); | 605 | QVERIFY(fakepart.hasServiceType(QStringLiteral("FakeBasePart"))); | ||
567 | QVERIFY(fakepart.hasServiceType(QStringLiteral("FakeDerivedPart"))); | 606 | QVERIFY(fakepart.hasServiceType(QStringLiteral("FakeDerivedPart"))); | ||
568 | QCOMPARE(fakepart.mimeTypes(), QStringList() << QStringLiteral("text/plain") << QStringLiteral("text/html")); | 607 | QCOMPARE(fakepart.mimeTypes(), QStringList() << QStringLiteral("text/plain") << QStringLiteral("text/html")); | ||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |