Warning, file /frameworks/oxygen-icons/autotests/symlinktest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 Copyright 2015 Harald Sitter <sitter@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), which shall 0010 act as a proxy defined in Section 6 of version 3 of the license. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Lesser General Public License for more details. 0016 0017 You should have received a copy of the GNU Lesser General Public 0018 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include <QDirIterator> 0022 #include <QObject> 0023 #include <QTest> 0024 0025 #include "testhelpers.h" 0026 0027 class SymlinkTest : public QObject 0028 { 0029 Q_OBJECT 0030 0031 private Q_SLOTS: 0032 // Invalid symlinks shouldn't happen. 0033 void test_broken() 0034 { 0035 // By default broken symlinks are not listed unless the System filter 0036 // is used. System may however also include pipes and the like, so we 0037 // still manually need to filter for symlinks afterwards. 0038 QDirIterator it(PROJECT_SOURCE_DIR, QDir::System, QDirIterator::Subdirectories); 0039 QList<QFileInfo> brokenSymLinks; 0040 while (it.hasNext()) { 0041 it.next(); 0042 auto info = it.fileInfo(); 0043 if (!info.isSymLink() || info.exists()) { 0044 continue; 0045 } 0046 brokenSymLinks << info; 0047 } 0048 failSymlinkList(brokenSymLinks, QStringLiteral("Found broken symlinks:\n")); 0049 } 0050 0051 // Symlinks should never point to something outside the tree, even if valid! 0052 void test_outOfTree() 0053 { 0054 QDirIterator it(PROJECT_SOURCE_DIR, QDir::AllEntries, QDirIterator::Subdirectories); 0055 QList<QFileInfo> OOTSymLinks; 0056 while (it.hasNext()) { 0057 it.next(); 0058 auto info = it.fileInfo(); 0059 if (!info.isSymLink() || info.symLinkTarget().startsWith(PROJECT_SOURCE_DIR)) { 0060 continue; 0061 } 0062 OOTSymLinks << info; 0063 } 0064 failSymlinkList(OOTSymLinks, QStringLiteral("Found out-of-tree symlinks:\n")); 0065 } 0066 }; 0067 0068 QTEST_GUILESS_MAIN(SymlinkTest) 0069 0070 #include "symlinktest.moc"