Commit 5f4c2247 authored by Harald Sitter's avatar Harald Sitter
Browse files

add symlink verification tech

to ensure greatest possible compatibility icon names are often symlinked
to other names. unfortunately symlinks can easily break without anyone
noticing. the symlinktest is supposed to prevent this by iterating the
entire project tree's symlinks and checking if they are actually pointing
to something.
additionally symlinks must not point to out-of-tree files. even if valid.

REVIEW: 126004
parent 51adbb6d
......@@ -12,8 +12,14 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_S
set(KF5_VERSION "5.16.0") # handled by release scripts
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
include(GtkUpdateIconCache)
# Dependencies
set(REQUIRED_QT_VERSION "5.3.0")
add_subdirectory(autotests)
add_subdirectory(icons)
add_subdirectory(icons-dark)
......
This diff is collapsed.
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
include(ECMAddTests)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Test)
configure_file(testdata.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/testdata.h)
ecm_add_test(symlinktest.cpp
TEST_NAME "symlink"
LINK_LIBRARIES Qt5::Test
)
/*
Copyright 2015 Harald Sitter <sitter@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDirIterator>
#include <QObject>
#include <QtTest>
#include "testdata.h"
class SymlinkTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void assertSymLinkListEmpty(const QList<QFileInfo> &list, const QString &header)
{
if (list.empty()) {
return;
}
QString indent(" ");
QString indent2 = indent + indent;
QString message = ("\n" + indent + header);
Q_FOREACH(const QFileInfo &info, list) {
message += (indent2 + info.filePath() + " => " + info.symLinkTarget() + "\n");
}
QFAIL(message.toLatin1());
}
// Invalid symlinks shouldn't happen.
void test_broken()
{
// By default broken symlinks are not listed unless the System filter
// is used. System may however also include pipes and the like, so we
// still manually need to filter for symlinks afterwards.
QDirIterator it(PROJECT_SOURCE_DIR,
QDir::System,
QDirIterator::Subdirectories);
QList<QFileInfo> brokenSymLinks;
while (it.hasNext()) {
it.next();
auto info = it.fileInfo();
if (!info.isSymLink() || info.exists()) {
continue;
}
brokenSymLinks << info;
}
assertSymLinkListEmpty(brokenSymLinks,
QStringLiteral("Found broken symlinks:\n"));
}
// Symlinks should never point to something outside the tree, even if valid!
void test_outOfTree()
{
QDirIterator it(PROJECT_SOURCE_DIR,
QDir::AllEntries,
QDirIterator::Subdirectories);
QList<QFileInfo> OOTSymLinks;
while (it.hasNext()) {
it.next();
auto info = it.fileInfo();
if (!info.isSymLink() ||
info.symLinkTarget().startsWith(PROJECT_SOURCE_DIR)) {
continue;
}
OOTSymLinks << info;
}
assertSymLinkListEmpty(OOTSymLinks,
QStringLiteral("Found out-of-tree symlinks:\n"));
}
};
QTEST_GUILESS_MAIN(SymlinkTest)
#include "symlinktest.moc"
#define PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment