Debian Codegraph @

tests/unit/iconprovider/tst_iconprovider.cpp

raw
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <QtTest/QtTest>
18 #define private public
19 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
20 #include <LomiriToolkit-Qt6/private/lomirithemeiconprovider_p.h>
21 #else
22 #include <LomiriToolkit/private/lomirithemeiconprovider_p.h>
23 #endif
24 #undef private
25
26 UT_USE_NAMESPACE
27
28 class tst_IconProvider : public QObject
29 {
30 Q_OBJECT
31 public:
32 tst_IconProvider() {}
33
34 private Q_SLOTS:
35
36 void initTestCase()
37 {
38 qputenv("XDG_DATA_DIRS", SRCDIR);
39 }
40
41 void test_loadIcon_data()
42 {
43 QTest::addColumn<QString>("icon");
44 QTest::addColumn<QSize>("requestSize");
45 QTest::addColumn<QSize>("resultSize");
46
47 QTest::newRow("battery0") << "battery-100-charging" << QSize(-1, -1) << QSize(256, 166);
48 QTest::newRow("battery1") << "battery-100-charging" << QSize(-1, 16) << QSize(25, 16);
49 QTest::newRow("battery2") << "battery-100-charging" << QSize(16, -1) << QSize(16, 10);
50 QTest::newRow("battery3") << "battery-100-charging" << QSize(0, 16) << QSize(25, 16);
51 QTest::newRow("battery4") << "battery-100-charging" << QSize(16, 0) << QSize(16, 10);
52 QTest::newRow("battery5") << "battery-100-charging" << QSize(24, 16) << QSize(24, 16);
53 QTest::newRow("battery6") << "battery-100-charging" << QSize(24, 24) << QSize(24, 16);
54 QTest::newRow("battery7") << "battery-100-charging" << QSize(37, 24) << QSize(37, 24);
55 QTest::newRow("battery8") << "battery-100-charging" << QSize(15, 512) << QSize(15, 10);
56
57 QTest::newRow("gallery0") << "gallery-app" << QSize(-1, -1) << QSize(512, 512);
58 QTest::newRow("gallery1") << "gallery-app" << QSize(-1, 16) << QSize(16, 16);
59 QTest::newRow("gallery2") << "gallery-app" << QSize(16, -1) << QSize(16, 16);
60 QTest::newRow("gallery3") << "gallery-app" << QSize(0, 16) << QSize(16, 16);
61 QTest::newRow("gallery4") << "gallery-app" << QSize(16, 0) << QSize(16, 16);
62 QTest::newRow("gallery5") << "gallery-app" << QSize(24, 16) << QSize(16, 16);
63 QTest::newRow("gallery6") << "gallery-app" << QSize(24, 24) << QSize(24, 24);
64 }
65
66 void test_loadIcon()
67 {
68 QFETCH(QString, icon);
69 QFETCH(QSize, requestSize);
70 QFETCH(QSize, resultSize);
71
72 LomiriThemeIconProvider provider("mockTheme");
73 QSize returnedSize;
74 QImage i = provider.requestImage(icon, &returnedSize, requestSize);
75 QCOMPARE(i.size(), resultSize);
76 QCOMPARE(returnedSize, resultSize);
77
78 // Search again to make sure subsequent searches still work
79 i = provider.requestImage(icon, &returnedSize, requestSize);
80 QCOMPARE(i.size(), resultSize);
81 QCOMPARE(returnedSize, resultSize);
82 }
83
84 void test_hicolorLast()
85 {
86 QSize returnedSize;
87 LomiriThemeIconProvider provider("mockTheme");
88
89 // myapp is in MockTheme3 (white) and hicolor (black)
90 // MockTheme3 one is returned since hicolor is last per spec
91 QImage i = provider.requestImage("myapp", &returnedSize, QSize(-1, -1));
92 QVERIFY(!i.isNull());
93 QCOMPARE(QColor(i.pixel(0,0)), QColor(Qt::white));
94
95 // myapp2 is only in hicolor (black) so that's the one returned
96 i = provider.requestImage("myapp2", &returnedSize, QSize(-1, -1));
97 QVERIFY(!i.isNull());
98 QCOMPARE(QColor(i.pixel(0,0)), QColor(Qt::black));
99 }
100 };
101
102 QTEST_MAIN(tst_IconProvider)
103
104 #include "tst_iconprovider.moc"