Debian Codegraph @

tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5 #include <QFileIconProvider>
6 #include <QFileInfo>
7 #include <QTest>
8
9 class tst_QFileIconProvider : public QObject
10 {
11 Q_OBJECT
12
13 private slots:
14 void qfileiconprovider();
15
16 void iconType_data();
17 void iconType();
18
19 void iconInfo_data();
20 void iconInfo();
21
22 void type_data();
23 void type();
24
25 void iconPixmaps();
26 };
27
28 void tst_QFileIconProvider::qfileiconprovider()
29 {
30 // don't crash
31 QFileIconProvider provider;
32 }
33
34 Q_DECLARE_METATYPE(QFileIconProvider::IconType)
35 void tst_QFileIconProvider::iconType_data()
36 {
37 QTest::addColumn<QFileIconProvider::IconType>("type");
38
39 QTest::newRow("computer") << QFileIconProvider::Computer;
40 QTest::newRow("desktop") << QFileIconProvider::Desktop;
41 QTest::newRow("trashcan") << QFileIconProvider::Trashcan;
42 QTest::newRow("network") << QFileIconProvider::Network;
43 QTest::newRow("drive") << QFileIconProvider::Drive;
44 QTest::newRow("folder") << QFileIconProvider::Folder;
45 QTest::newRow("file") << QFileIconProvider::File;
46 }
47
48 // public QIcon icon(QFileIconProvider::IconType const& type) const
49 void tst_QFileIconProvider::iconType()
50 {
51 QGuiApplication::setDesktopSettingsAware(false);
52 QFETCH(QFileIconProvider::IconType, type);
53 QFileIconProvider provider;
54 QVERIFY(!provider.icon(type).isNull());
55 }
56
57 void tst_QFileIconProvider::iconInfo_data()
58 {
59 QTest::addColumn<QFileInfo>("info");
60 QTest::addColumn<bool>("setPath");
61
62 QTest::newRow("null") << QFileInfo() << false;
63 QTest::newRow("drive") << QFileInfo(QDir::rootPath()) << true;
64 QTest::newRow("home") << QFileInfo(QDir::homePath()) << true;
65 QTest::newRow("current") << QFileInfo(QDir::currentPath()) << true;
66 }
67
68 // public QIcon icon(QFileInfo const& info) const
69 void tst_QFileIconProvider::iconInfo()
70 {
71 QFETCH(QFileInfo, info);
72 QFETCH(bool, setPath);
73
74 if (setPath)
75 QVERIFY(info.exists());
76 QFileIconProvider provider;
77 // we should always get an icon
78 QVERIFY(!provider.icon(info).isNull());
79 }
80
81 void tst_QFileIconProvider::type_data()
82 {
83 QTest::addColumn<QFileInfo>("info");
84 // Return value is _very_ system dependent, hard to test
85 // QTest::addColumn<QString>("type");
86
87 QTest::newRow("null") << QFileInfo();
88 QTest::newRow("drive") << QFileInfo(QDir::rootPath());
89 QTest::newRow("home") << QFileInfo(QDir::homePath());
90 QTest::newRow("current") << QFileInfo(QDir::currentPath());
91 QTest::newRow("exe") << QFileInfo(QCoreApplication::applicationFilePath());
92 }
93
94 // public QString type(QFileInfo const& info) const
95 void tst_QFileIconProvider::type()
96 {
97 QFETCH(QFileInfo, info);
98 QFileIconProvider provider;
99 QVERIFY(!provider.type(info).isEmpty());
100 }
101
102 static QIcon getIcon()
103 {
104 QFileIconProvider fip;
105 return fip.icon(QFileInfo(QDir::currentPath()));
106 }
107
108 void tst_QFileIconProvider::iconPixmaps()
109 {
110 const QIcon &icon = getIcon();
111 const auto sizes = icon.availableSizes();
112 for (const QSize &size : sizes) {
113 QPixmap pixmap = icon.pixmap(size);
114 QVERIFY(!pixmap.isNull());
115 }
116 }
117
118 QTEST_MAIN(tst_QFileIconProvider)
119 #include "tst_qfileiconprovider.moc"
120