Changeset View
Changeset View
Standalone View
Standalone View
autotests/kiconloader_rcctest.cpp
- This file was added.
1 | /* This file is part of the KDE libraries | ||||
---|---|---|---|---|---|
2 | Copyright 2015 Christoph Cullmann <cullmann@kde.org> | ||||
3 | Copyright 2016 David Faure <faure@kde.org> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Library General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2 of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <kiconloader.h> | ||||
22 | #include <kicontheme.h> | ||||
23 | | ||||
24 | #include <QStandardPaths> | ||||
25 | #include <QPixmap> | ||||
26 | #include <QTest> | ||||
27 | | ||||
28 | #include <KSharedConfig> | ||||
29 | #include <KConfigGroup> | ||||
30 | | ||||
31 | // Install icontheme.rcc where KIconThemes will find it. | ||||
32 | // This must be done before QCoreApplication is even created, given the Q_COREAPP_STARTUP_FUNCTION in kiconthemes | ||||
33 | void earlyInit() | ||||
34 | { | ||||
35 | QStandardPaths::enableTestMode(true); | ||||
36 | qputenv("XDG_DATA_DIRS", "/doesnotexist"); // ensure hicolor/oxygen/breeze are not found | ||||
37 | QFile rcc("icontheme.rcc"); | ||||
38 | Q_ASSERT(rcc.exists()); | ||||
39 | QCoreApplication::setApplicationName("myappname"); // for a fixed location on Unix (appname is empty here otherwise) | ||||
40 | const QString destDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | ||||
41 | QDir().mkpath(destDir); | ||||
42 | const QString dest = destDir + "/icontheme.rcc"; | ||||
43 | QFile::remove(dest); | ||||
44 | if (!rcc.copy(dest)) { | ||||
45 | qWarning() << "Error copying to" << dest; | ||||
46 | } | ||||
47 | } | ||||
48 | Q_CONSTRUCTOR_FUNCTION(earlyInit) | ||||
49 | | ||||
50 | class KIconLoader_RCCThemeTest : public QObject | ||||
51 | { | ||||
52 | Q_OBJECT | ||||
53 | | ||||
54 | private Q_SLOTS: | ||||
55 | void testThemeName() | ||||
56 | { | ||||
57 | QCOMPARE(QIcon::themeName(), m_internalThemeName); | ||||
58 | } | ||||
59 | | ||||
60 | void testQIconFromTheme() | ||||
61 | { | ||||
62 | // load icon with Qt API | ||||
63 | QVERIFY(!QIcon::fromTheme(QStringLiteral("someiconintheme")).isNull()); | ||||
64 | } | ||||
65 | | ||||
66 | void testKIconLoader() | ||||
67 | { | ||||
68 | // Check that direct usage of KIconLoader (e.g. from KToolBar) works | ||||
69 | QVERIFY(KIconLoader::global()->theme()); | ||||
70 | QCOMPARE(KIconLoader::global()->theme()->internalName(), m_internalThemeName); | ||||
71 | | ||||
72 | // load icon with KIconLoader API (unlikely to happen in reality) | ||||
73 | QString path; | ||||
74 | KIconLoader::global()->loadIcon(QStringLiteral("someiconintheme"), KIconLoader::Desktop, 22, | ||||
75 | KIconLoader::DefaultState, QStringList(), | ||||
76 | &path); | ||||
77 | QCOMPARE(path, QString(QStringLiteral(":/icons/") + m_internalThemeName + QStringLiteral("/22x22/appsNoContext/someiconintheme.png"))); | ||||
78 | | ||||
79 | } | ||||
80 | private: | ||||
81 | const QString m_internalThemeName = "kf5_rcc_theme"; | ||||
82 | }; | ||||
83 | | ||||
84 | QTEST_MAIN(KIconLoader_RCCThemeTest) | ||||
85 | | ||||
86 | #include "kiconloader_rcctest.moc" |