File indexing completed on 2024-05-05 03:55:03

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include <kiconloader.h>
0009 #include <kpixmapsequenceloader.h>
0010 
0011 #include <QDir>
0012 #include <QRegularExpression>
0013 #include <QStandardPaths>
0014 #include <QTest>
0015 
0016 #include <KPixmapSequence>
0017 
0018 #include <KConfigGroup>
0019 #include <KSharedConfig>
0020 
0021 extern KICONTHEMES_EXPORT void uintToHex(uint32_t colorData, QChar *buffer);
0022 
0023 class KPixmapSequenceLoader_UnitTest : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     KPixmapSequenceLoader_UnitTest()
0028     {
0029     }
0030 
0031 private:
0032     QDir testDataDir;
0033     QDir testIconsDir;
0034 
0035 private Q_SLOTS:
0036     void initTestCase()
0037     {
0038         QStandardPaths::setTestModeEnabled(true);
0039 
0040         KConfigGroup cg(KSharedConfig::openConfig(), "Icons");
0041         cg.writeEntry("Theme", "oxygen");
0042         cg.sync();
0043 
0044         testDataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
0045         testIconsDir = QDir(testDataDir.absoluteFilePath(QStringLiteral("icons")));
0046 
0047         // we will be recursively deleting these, so a sanity check is in order
0048         QVERIFY(testIconsDir.absolutePath().contains(QLatin1String("qttest")));
0049 
0050         testIconsDir.removeRecursively();
0051 
0052         // set up a minimal Oxygen icon theme, in case it is not installed
0053         QVERIFY(testIconsDir.mkpath(QStringLiteral("oxygen/22x22/animations")));
0054         QVERIFY(QFile::copy(QStringLiteral(":/oxygen.theme"), testIconsDir.filePath(QStringLiteral("oxygen/index.theme"))));
0055         QVERIFY(QFile::copy(QStringLiteral(":/anim-22x22.png"), testIconsDir.filePath(QStringLiteral("oxygen/22x22/animations/process-working.png"))));
0056     }
0057 
0058     void cleanupTestCase()
0059     {
0060         if (testIconsDir != QDir()) {
0061             testIconsDir.removeRecursively();
0062         }
0063     }
0064 
0065     void init()
0066     {
0067         // Remove icon cache
0068         const QString cacheFile = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/icon-cache.kcache");
0069         QFile::remove(cacheFile);
0070 
0071         // Clear SHM cache
0072         KIconLoader::global()->reconfigure(QString());
0073     }
0074 
0075     void testLoadPixmapSequence()
0076     {
0077         KPixmapSequence seq = KPixmapSequenceLoader::load(QStringLiteral("process-working"), 22);
0078         QVERIFY(seq.isValid());
0079     }
0080 };
0081 
0082 QTEST_MAIN(KPixmapSequenceLoader_UnitTest)
0083 
0084 #include "kpixmapsequenceloadertest.moc"