Changeset View
Changeset View
Standalone View
Standalone View
autotests/dupetest.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include <QObject> | 21 | #include <QObject> | ||
22 | #include <QtTest> | 22 | #include <QtTest> | ||
23 | 23 | | |||
24 | #include "testhelpers.h" | 24 | #include "testhelpers.h" | ||
25 | #include "kiconloaderdummy.h" | ||||
25 | 26 | | |||
26 | class DupeTest : public QObject | 27 | class DupeTest : public QObject | ||
27 | { | 28 | { | ||
28 | Q_OBJECT | 29 | Q_OBJECT | ||
29 | 30 | | |||
30 | QStringList splitOnUnescapedSpace(const QString &line) | 31 | QStringList splitOnUnescapedSpace(const QString &line) | ||
31 | { | 32 | { | ||
32 | QStringList ret; | 33 | QStringList ret; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 83 | #else | |||
83 | // On Windows let's just skip it | 84 | // On Windows let's just skip it | ||
84 | QSKIP("this test needs the fdupes binary (1.51+) to run"); | 85 | QSKIP("this test needs the fdupes binary (1.51+) to run"); | ||
85 | #endif | 86 | #endif | ||
86 | } | 87 | } | ||
87 | for (auto dir : ICON_DIRS) { | 88 | for (auto dir : ICON_DIRS) { | ||
88 | dupesForDirectory(PROJECT_SOURCE_DIR + QStringLiteral("/") + dir); | 89 | dupesForDirectory(PROJECT_SOURCE_DIR + QStringLiteral("/") + dir); | ||
89 | } | 90 | } | ||
90 | } | 91 | } | ||
92 | | ||||
93 | void test_duplicateNames() | ||||
94 | { | ||||
95 | for (auto dir : ICON_DIRS) { | ||||
96 | auto themeDir = PROJECT_SOURCE_DIR + QStringLiteral("/") + dir; | ||||
97 | | ||||
98 | QHash<KIconLoaderDummy::Context, QList<QSharedPointer<Dir>>> contextHash; | ||||
99 | | ||||
100 | QSettings config(themeDir + "/index.theme", QSettings::IniFormat); | ||||
101 | auto keys = config.allKeys(); | ||||
102 | config.beginGroup("Icon Theme"); | ||||
103 | auto directoryPaths = config.value("Directories", QString()).toStringList(); | ||||
104 | config.endGroup(); | ||||
105 | QVERIFY(!directoryPaths.isEmpty()); | ||||
106 | for (auto directoryPath : directoryPaths) { | ||||
107 | config.beginGroup(directoryPath); | ||||
108 | QVERIFY2(keys.contains(directoryPath+"/Size"),QString("The theme %1 has an entry 'Directories' which specifies '%2' as directory, but there's no" | ||||
109 | " have no associated entry '%2/Size'").arg(themeDir + "/index.theme", directoryPath).toLatin1()); | ||||
110 | auto dir = QSharedPointer<Dir>::create(config, themeDir); | ||||
111 | config.endGroup(); | ||||
112 | contextHash[dir->context].append(dir); | ||||
113 | } | ||||
114 | | ||||
115 | QHash<QString, QHash<KIconLoaderDummy::Context, QList<QSharedPointer<Dir>>>> filesByName; | ||||
116 | for (auto it = contextHash.constBegin(), itEnd = contextHash.constEnd(); it != itEnd; ++it) { | ||||
117 | for (const auto &dir: *it) { | ||||
118 | for (const auto &file: dir->allIcons()) { | ||||
119 | filesByName[file.completeBaseName()][dir->context] << dir; | ||||
120 | } | ||||
121 | } | ||||
122 | } | ||||
123 | | ||||
124 | for (auto it = filesByName.constBegin(), itEnd = filesByName.constEnd(); it != itEnd; ++it) { | ||||
125 | if (it.value().count() > 1) { | ||||
126 | const auto alts = it.value(); | ||||
127 | qDebug() << "duplicated name" << it.key() << alts.keys().count(); | ||||
128 | for(auto itAlts = alts.cbegin(), itAltsEnd = alts.cend(); itAlts != itAltsEnd; ++itAlts) { | ||||
129 | QStringList paths; | ||||
130 | for(auto alt : itAlts.value()) { | ||||
131 | paths << alt->path; | ||||
132 | } | ||||
133 | qDebug() << "in" << itAlts.key() << paths.count() << paths; | ||||
134 | } | ||||
135 | } | ||||
136 | } | ||||
137 | } | ||||
138 | | ||||
139 | } | ||||
91 | }; | 140 | }; | ||
92 | 141 | | |||
93 | QTEST_GUILESS_MAIN(DupeTest) | 142 | QTEST_GUILESS_MAIN(DupeTest) | ||
94 | 143 | | |||
95 | #include "dupetest.moc" | 144 | #include "dupetest.moc" |