Run clang-format on all cpp/h files

NO_CHANGELOG
This commit is contained in:
Ahmad Samir 2021-02-23 20:57:37 +02:00
parent 5df331acf2
commit fe594e8742
6 changed files with 51 additions and 63 deletions

View File

@ -143,4 +143,4 @@ kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
# Remove these 3 lines when the ECM version is bumped to 5.80 # Remove these 3 lines when the ECM version is bumped to 5.80
include(KDEClangFormat) include(KDEClangFormat)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format() kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})

View File

@ -19,9 +19,9 @@
*/ */
#include <QObject> #include <QObject>
#include <QTest>
#include <QStandardPaths>
#include <QProcess> #include <QProcess>
#include <QStandardPaths>
#include <QTest>
#include "testhelpers.h" #include "testhelpers.h"
@ -55,8 +55,7 @@ class DupeTest : public QObject
QString line; QString line;
while (proc.canReadLine() || proc.waitForReadyRead()) { while (proc.canReadLine() || proc.waitForReadyRead()) {
line = proc.readLine(); line = proc.readLine();
failListContent(splitOnUnescapedSpace(line.simplified()), failListContent(splitOnUnescapedSpace(line.simplified()), "The following files are duplicates but not links:\n");
"The following files are duplicates but not links:\n");
} }
} }
@ -64,11 +63,7 @@ class DupeTest : public QObject
{ {
QProcess proc; QProcess proc;
proc.setProgram(QStringLiteral("fdupes")); proc.setProgram(QStringLiteral("fdupes"));
proc.setArguments(QStringList() proc.setArguments(QStringList() << QStringLiteral("--recurse") << QStringLiteral("--sameline") << QStringLiteral("--nohidden") << path);
<< QStringLiteral("--recurse")
<< QStringLiteral("--sameline")
<< QStringLiteral("--nohidden")
<< path);
proc.start(); proc.start();
proc.waitForStarted(); proc.waitForStarted();
readLines(proc); readLines(proc);

View File

@ -33,19 +33,15 @@ private Q_SLOTS:
void test_whitespace() void test_whitespace()
{ {
QList<QString> brokenFiles; QList<QString> brokenFiles;
QDirIterator it(PROJECT_SOURCE_DIR, QDirIterator it(PROJECT_SOURCE_DIR, QDir::Files | QDir::System, QDirIterator::Subdirectories);
QDir::Files | QDir::System,
QDirIterator::Subdirectories);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if (it.fileName().simplified() != it.fileName()) { if (it.fileName().simplified() != it.fileName()) {
brokenFiles << it.filePath(); brokenFiles << it.filePath();
} }
} }
failListContent(brokenFiles, failListContent(brokenFiles, QStringLiteral("Found file with bad characters (http://doc.qt.io/qt-5/qstring.html#simplified):\n"));
QStringLiteral("Found file with bad characters (http://doc.qt.io/qt-5/qstring.html#simplified):\n"));
} }
}; };
QTEST_GUILESS_MAIN(NewlineTest) QTEST_GUILESS_MAIN(NewlineTest)

View File

@ -19,17 +19,17 @@
License along with this library. If not, see <http://www.gnu.org/licenses/>. License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QDirIterator>
#include <QObject> #include <QObject>
#include <QTest> #include <QTest>
#include <QDirIterator>
#include <QSettings> // parsing the ini files as desktop files
#include "testhelpers.h" #include "testhelpers.h"
#include <QSettings> // parsing the ini files as desktop files
// lift a bit of code from KIconLoader to get the unit test running without tier 3 libraries // lift a bit of code from KIconLoader to get the unit test running without tier 3 libraries
class KIconLoaderDummy : public QObject class KIconLoaderDummy : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Context { enum Context {
Any, Any,
@ -55,7 +55,6 @@ public:
Q_ENUM(Type) Q_ENUM(Type)
}; };
/** /**
* Represents icon directory to conduct simple icon lookup within. * Represents icon directory to conduct simple icon lookup within.
*/ */
@ -63,8 +62,7 @@ class Dir
{ {
public: public:
Dir(const QSettings &cg, const QString &themeDir_) Dir(const QSettings &cg, const QString &themeDir_)
: : themeDir(themeDir_)
themeDir(themeDir_)
, path(cg.group()) , path(cg.group())
, size(cg.value("Size", 0).toInt()) , size(cg.value("Size", 0).toInt())
, contextString(cg.value("Context", QString()).toString()) , contextString(cg.value("Context", QString()).toString())
@ -74,7 +72,10 @@ public:
QVERIFY2(!contextString.isEmpty(), QVERIFY2(!contextString.isEmpty(),
QString("Missing 'Context' key in file %1, config group '[%2]'").arg(cg.fileName(), cg.group()).toLatin1().constData()); QString("Missing 'Context' key in file %1, config group '[%2]'").arg(cg.fileName(), cg.group()).toLatin1().constData());
QVERIFY2(context != -1, QVERIFY2(context != -1,
QString("Don't know how to handle 'Context=%1' in file %2, config group '[%3]'").arg(contextString, cg.fileName(), cg.group()).toLatin1().constData()); QString("Don't know how to handle 'Context=%1' in file %2, config group '[%3]'")
.arg(contextString, cg.fileName(), cg.group())
.toLatin1()
.constData());
} }
static QMetaEnum findEnum(const char *name) static QMetaEnum findEnum(const char *name)
@ -99,17 +100,17 @@ public:
static KIconLoaderDummy::Context parseContext(const QString &string) static KIconLoaderDummy::Context parseContext(const QString &string)
{ {
// Can't use QMetaEnum as the enum names are singular, the entry values are plural though. // Can't use QMetaEnum as the enum names are singular, the entry values are plural though.
static QHash<QString, int> hash { static QHash<QString, int> hash{
{ QStringLiteral("Actions"), KIconLoaderDummy::Action }, {QStringLiteral("Actions"), KIconLoaderDummy::Action},
{ QStringLiteral("Animations"), KIconLoaderDummy::Animation }, {QStringLiteral("Animations"), KIconLoaderDummy::Animation},
{ QStringLiteral("Applications"), KIconLoaderDummy::Application }, {QStringLiteral("Applications"), KIconLoaderDummy::Application},
{ QStringLiteral("Categories"), KIconLoaderDummy::Category }, {QStringLiteral("Categories"), KIconLoaderDummy::Category},
{ QStringLiteral("Devices"), KIconLoaderDummy::Device }, {QStringLiteral("Devices"), KIconLoaderDummy::Device},
{ QStringLiteral("Emblems"), KIconLoaderDummy::Emblem }, {QStringLiteral("Emblems"), KIconLoaderDummy::Emblem},
{ QStringLiteral("Emotes"), KIconLoaderDummy::Emote }, {QStringLiteral("Emotes"), KIconLoaderDummy::Emote},
{ QStringLiteral("MimeTypes"), KIconLoaderDummy::MimeType }, {QStringLiteral("MimeTypes"), KIconLoaderDummy::MimeType},
{ QStringLiteral("Places"), KIconLoaderDummy::Place }, {QStringLiteral("Places"), KIconLoaderDummy::Place},
{ QStringLiteral("Status"), KIconLoaderDummy::StatusIcon }, {QStringLiteral("Status"), KIconLoaderDummy::StatusIcon},
}; };
const auto value = hash.value(string, -1); const auto value = hash.value(string, -1);
return static_cast<KIconLoaderDummy::Context>(value); // the caller will check that it wasn't -1 return static_cast<KIconLoaderDummy::Context>(value); // the caller will check that it wasn't -1
@ -179,8 +180,12 @@ private Q_SLOTS:
QVERIFY(!directoryPaths.isEmpty()); QVERIFY(!directoryPaths.isEmpty());
for (auto directoryPath : directoryPaths) { for (auto directoryPath : directoryPaths) {
config.beginGroup(directoryPath); config.beginGroup(directoryPath);
QVERIFY2(keys.contains(directoryPath+"/Size"),QString("The theme %1 has an entry 'Directories' which specifies '%2' as directory, but there's no" QVERIFY2(keys.contains(directoryPath + "/Size"),
" have no associated entry '%2/Size'").arg(themeDir + "/index.theme", directoryPath).toLatin1().constData()); QString("The theme %1 has an entry 'Directories' which specifies '%2' as directory, but there's no"
" have no associated entry '%2/Size'")
.arg(themeDir + "/index.theme", directoryPath)
.toLatin1()
.constData());
auto dir = QSharedPointer<Dir>::create(config, themeDir); auto dir = QSharedPointer<Dir>::create(config, themeDir);
config.endGroup(); config.endGroup();
contextHash[dir->context].append(dir); contextHash[dir->context].append(dir);
@ -261,9 +266,7 @@ private Q_SLOTS:
return; return;
} }
notScalableIcons.removeDuplicates(); notScalableIcons.removeDuplicates();
QFAIL(QString("The following icons are not available in a scalable directory:\n %1") QFAIL(QString("The following icons are not available in a scalable directory:\n %1").arg(notScalableIcons.join("\n ")).toLatin1().constData());
.arg(notScalableIcons.join("\n "))
.toLatin1().constData());
} }
void test_scalableDuplicates_data() void test_scalableDuplicates_data()
@ -297,7 +300,7 @@ private Q_SLOTS:
} }
QHash<QString, QList<QFileInfo>> duplicatedScalableIcons; QHash<QString, QList<QFileInfo>> duplicatedScalableIcons;
for (auto icon: scalableIcons.keys()) { for (auto icon : scalableIcons.keys()) {
auto list = scalableIcons[icon]; auto list = scalableIcons[icon];
if (list.size() > 1) { if (list.size() > 1) {
duplicatedScalableIcons[icon] = list; duplicatedScalableIcons[icon] = list;

View File

@ -40,9 +40,7 @@ private Q_SLOTS:
// By default broken symlinks are not listed unless the System filter // By default broken symlinks are not listed unless the System filter
// is used. System may however also include pipes and the like, so we // is used. System may however also include pipes and the like, so we
// still manually need to filter for symlinks afterwards. // still manually need to filter for symlinks afterwards.
QDirIterator it(PROJECT_SOURCE_DIR, QDirIterator it(PROJECT_SOURCE_DIR, QDir::System, QDirIterator::Subdirectories);
QDir::System,
QDirIterator::Subdirectories);
QList<QFileInfo> brokenSymLinks; QList<QFileInfo> brokenSymLinks;
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
@ -57,29 +55,25 @@ private Q_SLOTS:
} }
brokenSymLinks << info; brokenSymLinks << info;
} }
failSymlinkList(brokenSymLinks, failSymlinkList(brokenSymLinks, QStringLiteral("Found broken symlinks:\n"));
QStringLiteral("Found broken symlinks:\n"));
} }
// Symlinks should never point to something outside the tree, even if valid! // Symlinks should never point to something outside the tree, even if valid!
void test_outOfTree() void test_outOfTree()
{ {
QDirIterator it(PROJECT_SOURCE_DIR, QDirIterator it(PROJECT_SOURCE_DIR, QDir::AllEntries, QDirIterator::Subdirectories);
QDir::AllEntries,
QDirIterator::Subdirectories);
QList<QFileInfo> OOTSymLinks; QList<QFileInfo> OOTSymLinks;
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
auto info = it.fileInfo(); auto info = it.fileInfo();
if (!info.isSymLink() || if (!info.isSymLink() || info.symLinkTarget().startsWith(PROJECT_SOURCE_DIR)) {
info.symLinkTarget().startsWith(PROJECT_SOURCE_DIR)) {
continue; continue;
} }
OOTSymLinks << info; OOTSymLinks << info;
} }
failSymlinkList(OOTSymLinks, failSymlinkList(OOTSymLinks, QStringLiteral("Found out-of-tree symlinks:\n"));
QStringLiteral("Found out-of-tree symlinks:\n"));
} }
private: private:
QString m_buildDir; QString m_buildDir;
}; };

View File

@ -16,13 +16,13 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include <QCommandLineParser>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QString>
#include <QRegularExpression> #include <QRegularExpression>
#include <QDebug> #include <QString>
#include <QCommandLineParser>
QString link(const QString &path, const QString &fileName) QString link(const QString &path, const QString &fileName)
{ {
@ -46,11 +46,11 @@ QString link(const QString &path, const QString &fileName)
QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1)); QFileInfo linkInfo(path + QLatin1Char('/') + match.captured(1));
QString aliasLink = link(linkInfo.path(), linkInfo.fileName()); QString aliasLink = link(linkInfo.path(), linkInfo.fileName());
if (!aliasLink.isEmpty()) { if (!aliasLink.isEmpty()) {
//qDebug() << fileName << "=" << match.captured(1) << "=" << aliasLink; // qDebug() << fileName << "=" << match.captured(1) << "=" << aliasLink;
return aliasLink; return aliasLink;
} }
return path + QLatin1Char('/') + match.captured(1); return path + QLatin1Char('/') + match.captured(1);
} }
int parseFile(const QString &infile, const QString &outfile) int parseFile(const QString &infile, const QString &outfile)
@ -72,7 +72,7 @@ int parseFile(const QString &infile, const QString &outfile)
QString line = QString::fromLocal8Bit(in.readLine()); QString line = QString::fromLocal8Bit(in.readLine());
QRegularExpressionMatch match = imageReg.match(line); QRegularExpressionMatch match = imageReg.match(line);
if (!match.hasMatch()) { if (!match.hasMatch()) {
//qDebug() << "No Match: " << line; // qDebug() << "No Match: " << line;
out.write(qPrintable(line)); out.write(qPrintable(line));
continue; continue;
} }
@ -81,13 +81,13 @@ int parseFile(const QString &infile, const QString &outfile)
QString aliasLink = link(info.path(), info.fileName()); QString aliasLink = link(info.path(), info.fileName());
if (aliasLink.isEmpty()) { if (aliasLink.isEmpty()) {
//qDebug() << "No alias: " << line; // qDebug() << "No alias: " << line;
out.write(qPrintable(line)); out.write(qPrintable(line));
continue; continue;
} }
QString newLine = QStringLiteral("<file alias=\"%1\">%2</file>\n").arg(match.captured(1), aliasLink); QString newLine = QStringLiteral("<file alias=\"%1\">%2</file>\n").arg(match.captured(1), aliasLink);
//qDebug() << newLine; // qDebug() << newLine;
out.write(qPrintable(newLine)); out.write(qPrintable(newLine));
} }
return 0; return 0;
@ -103,9 +103,9 @@ int main(int argc, char *argv[])
QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile")); QCommandLineOption outOption(QStringList() << QLatin1String("o") << QLatin1String("outfile"), QStringLiteral("Output qrc file"), QStringLiteral("outfile"));
parser.setApplicationDescription( parser.setApplicationDescription(
QLatin1String("On Windows git handles symbolic links by converting them " QLatin1String("On Windows git handles symbolic links by converting them "
"to text files containing the links to the actual file. This application " "to text files containing the links to the actual file. This application "
"takes a .qrc file as input and outputs a .qrc file with the symbolic " "takes a .qrc file as input and outputs a .qrc file with the symbolic "
"links converted to qrc-aliases.")); "links converted to qrc-aliases."));
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
parser.addOption(inOption); parser.addOption(inOption);