diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -4,16 +4,6 @@ if(BUILD_TESTING) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Test) - find_package(KF5Config 5.0 QUIET) - find_package(KF5IconThemes 5.0 QUIET) - - set_package_properties(KF5Config PROPERTIES - PURPOSE "Auto tests" - TYPE OPTIONAL) - set_package_properties(KF5IconThemes PROPERTIES - PURPOSE "Auto tests" - TYPE OPTIONAL) - configure_file(testdata.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/testdata.h) ecm_add_test(symlinktest.cpp @@ -28,10 +18,8 @@ TEST_NAME "dupe" LINK_LIBRARIES Qt5::Test ) - if (KF5::IconThemes AND KF5::ConfigCore) - ecm_add_test(scalabletest.cpp - TEST_NAME "scalable" - LINK_LIBRARIES Qt5::Test KF5::IconThemes KF5::ConfigCore - ) - endif() + ecm_add_test(scalabletest.cpp + TEST_NAME "scalable" + LINK_LIBRARIES Qt5::Test + ) endif() diff --git a/autotests/scalabletest.cpp b/autotests/scalabletest.cpp --- a/autotests/scalabletest.cpp +++ b/autotests/scalabletest.cpp @@ -1,5 +1,6 @@ /* Copyright 2017 Harald Sitter + Copyright 2017 Sune Vuorela This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,51 +22,65 @@ #include #include -#include -#include -#include - +#include // parsing the ini files as desktop files #include "testhelpers.h" +// lift a bit of code from KIconLoader to get the unit test running without tier 3 libraries +class KIconLoaderDummy : public QObject +{ +Q_OBJECT +public: + enum Context { + Any, + Action, + Application, + Device, + FileSystem, + MimeType, + Animation, + Category, + Emblem, + Emote, + International, + Place, + StatusIcon + }; + Q_ENUM(Context) + enum Type { + Fixed, + Scalable, + Threshold + }; + Q_ENUM(Type) +}; + + /** * Represents icon directory to conduct simple icon lookup within. */ class Dir { public: - Dir(const KConfigGroup &cg, const QString &themeDir_) - : exists(checkExist(cg)) - , themeDir(themeDir_) - , path(cg.name()) - , size(cg.readEntry("Size", 0)) - , contextString(cg.readEntry("Context", QString())) + Dir(const QSettings &cg, const QString &themeDir_) + : + themeDir(themeDir_) + , path(cg.group()) + , size(cg.value("Size", 0).toInt()) + , contextString(cg.value("Context", QString()).toString()) , context(parseContext(contextString)) - , type(parseType(cg.readEntry("Type", QString("Threshold")))) + , type(parseType(cg.value("Type", QString("Threshold")).toString())) { QVERIFY2(context != -1, - QString("Don't know how to handle 'Context=%1' of config group '[%2]'").arg(contextString, cg.name()).toLatin1()); - } - - static void verify(const KConfigGroup &cg) - { - QVERIFY2(cg.exists(), - QString("The theme's 'Directories' specifies '%1' as directory which appears to" - " have no associated group entry '[%1]'").arg(cg.name()).toLatin1()); - } - - static bool checkExist(const KConfigGroup &cg) - { - verify(cg); // extra func since QVERIFY2 is a return - return cg.isValid(); + QString("Don't know how to handle 'Context=%1' of config group '[%2]'").arg(contextString, cg.group()).toLatin1()); } static QMetaEnum findEnum(const char *name) { - auto mo = KIconLoader::staticMetaObject; + auto mo = KIconLoaderDummy::staticMetaObject; for (int i = 0; i < mo.enumeratorCount(); ++i) { auto enumerator = mo.enumerator(i); if (strcmp(enumerator.name(), name) == 0) { - return KIconLoader::staticMetaObject.enumerator(i); + return KIconLoaderDummy::staticMetaObject.enumerator(i); } } Q_ASSERT(false); // failed to resolve enum @@ -78,28 +93,29 @@ return e; } - KIconLoader::Context parseContext(const QString &string) + static KIconLoaderDummy::Context parseContext(const QString &string) { // Can't use QMetaEnum as the enum names are singular, the entry values are plural though. static QHash hash { - { QStringLiteral("Actions"), KIconLoader::Action }, - { QStringLiteral("Applications"), KIconLoader::Application }, - { QStringLiteral("Categories"), KIconLoader::Category }, - { QStringLiteral("Devices"), KIconLoader::Device }, - { QStringLiteral("Emblems"), KIconLoader::Emblem }, - { QStringLiteral("Emotes"), KIconLoader::Emote }, - { QStringLiteral("MimeTypes"), KIconLoader::MimeType }, - { QStringLiteral("Places"), KIconLoader::Place }, - { QStringLiteral("Status"), KIconLoader::StatusIcon }, + { QStringLiteral("Actions"), KIconLoaderDummy::Action }, + { QStringLiteral("Applications"), KIconLoaderDummy::Application }, + { QStringLiteral("Categories"), KIconLoaderDummy::Category }, + { QStringLiteral("Devices"), KIconLoaderDummy::Device }, + { QStringLiteral("Emblems"), KIconLoaderDummy::Emblem }, + { QStringLiteral("Emotes"), KIconLoaderDummy::Emote }, + { QStringLiteral("MimeTypes"), KIconLoaderDummy::MimeType }, + { QStringLiteral("Places"), KIconLoaderDummy::Place }, + { QStringLiteral("Status"), KIconLoaderDummy::StatusIcon }, }; auto value = hash.value(string, -1); - return (KIconLoader::Context)value; + Q_ASSERT(value != -1); + return (KIconLoaderDummy::Context)value; } - KIconLoader::Type parseType(const QString &string) + static KIconLoaderDummy::Type parseType(const QString &string) { bool ok; - auto v = (KIconLoader::Type)typeEnum().keyToValue(string.toLatin1(), &ok); + auto v = (KIconLoaderDummy::Type)typeEnum().keyToValue(string.toLatin1(), &ok); Q_ASSERT(ok); return v; } @@ -124,49 +140,52 @@ return icons; } - bool exists; QString themeDir; QString path; uint size; QString contextString; - KIconLoader::Context context; - KIconLoader::Type type; + KIconLoaderDummy::Context context; + KIconLoaderDummy::Type type; }; // Declare so we can put them into the QTest data table. -Q_DECLARE_METATYPE(KIconLoader::Context) -Q_DECLARE_METATYPE(Dir*) +Q_DECLARE_METATYPE(KIconLoaderDummy::Context) +Q_DECLARE_METATYPE(QSharedPointer) class ScalableTest : public QObject { Q_OBJECT private Q_SLOTS: - // NB: test_scalable_data leaks Dir*. Should this test grow more slots it may be wise to - // introduce a cleanup() to make sure the test doesn't OOM. - void test_scalable_data() { for (auto dir : ICON_DIRS) { auto themeDir = PROJECT_SOURCE_DIR + QStringLiteral("/") + dir; - QHash> contextHash; - QHash contextStringHash; + QHash>> contextHash; + QHash contextStringHash; - KConfig config(themeDir + "/index.theme"); - auto directoryPaths = config.group("Icon Theme").readEntry("Directories", QString()).split(","); + QSettings config(themeDir + "/index.theme", QSettings::IniFormat); + auto keys = config.allKeys(); + config.beginGroup("Icon Theme"); + auto directoryPaths = config.value("Directories", QString()).toStringList(); + config.endGroup(); QVERIFY(!directoryPaths.isEmpty()); for (auto directoryPath : directoryPaths) { - auto dir = new Dir(config.group(directoryPath), themeDir); + config.beginGroup(directoryPath); + QVERIFY2(keys.contains(directoryPath+"/Size"),QString("The theme's 'Directories' specifies '%1' as directory which appears to" + " have no associated group entry '[%1]'").arg(directoryPath).toLatin1()); + auto dir = QSharedPointer::create(config, themeDir); + config.endGroup(); contextHash[dir->context].append(dir); contextStringHash[dir->context] = (dir->contextString); } - QTest::addColumn("context"); - QTest::addColumn>("dirs"); + QTest::addColumn("context"); + QTest::addColumn>>("dirs"); for (auto key : contextHash.keys()) { - if (key != KIconLoader::Application) { + if (key != KIconLoaderDummy::Application) { qDebug() << "Only testing Application context for now."; continue; } @@ -180,27 +199,27 @@ void test_scalable() { - QFETCH(KIconLoader::Context, context); - QFETCH(QList, dirs); + QFETCH(KIconLoaderDummy::Context, context); + QFETCH(QList>, dirs); - QList fixedDirs; - QList scalableDirs; + QList> fixedDirs; + QList> scalableDirs; for (auto dir : dirs) { switch (dir->type) { - case KIconLoader::Scalable: + case KIconLoaderDummy::Scalable: scalableDirs << dir; break; - case KIconLoader::Fixed: + case KIconLoaderDummy::Fixed: fixedDirs << dir; break; - case KIconLoader::Threshold: + case KIconLoaderDummy::Threshold: QVERIFY2(false, "Test does not support threshold icons right now."); } } // FIXME: context should be translated through qenum switch (context) { - case KIconLoader::Application: + case KIconLoaderDummy::Application: // Treat this as a problem. QVERIFY2(!scalableDirs.empty(), "This icon context has no scalable directory at all!"); break; @@ -248,18 +267,18 @@ void test_scalableDuplicates() { - QFETCH(QList, dirs); + QFETCH(QList>, dirs); - QList scalableDirs; + QList> scalableDirs; for (auto dir : dirs) { switch (dir->type) { - case KIconLoader::Scalable: + case KIconLoaderDummy::Scalable: scalableDirs << dir; break; - case KIconLoader::Fixed: + case KIconLoaderDummy::Fixed: // Not of interest in this test. break; - case KIconLoader::Threshold: + case KIconLoaderDummy::Threshold: QVERIFY2(false, "Test does not support threshold icons right now."); } }