diff options
author | Robert Griebl <robert.griebl@qt.io> | 2023-12-21 23:51:53 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2024-01-08 22:12:27 +0100 |
commit | 0fdf77ce4af97ba2c58cfd628050d3789622d037 (patch) | |
tree | dab24b0f985b2b9f45dafaf3ff68022c3c9e73f0 /tests/auto | |
parent | d82261fd1cce14a63902033e9b1305f0312af856 (diff) |
Clazy: fix tests
Change-Id: I86f6883a90fe9fcc816f65fa34bae19656625498
Pick-to: 6.7
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/application/tst_application.cpp | 2 | ||||
-rw-r--r-- | tests/auto/applicationinfo/tst_applicationinfo.cpp | 10 | ||||
-rw-r--r-- | tests/auto/applicationinstaller/tst_applicationinstaller.cpp | 19 | ||||
-rw-r--r-- | tests/auto/configuration/tst_configuration.cpp | 4 | ||||
-rw-r--r-- | tests/auto/controller-tool/tst_controller-tool.cpp | 2 | ||||
-rw-r--r-- | tests/auto/debugwrapper/tst_debugwrapper.cpp | 2 | ||||
-rw-r--r-- | tests/auto/installationreport/tst_installationreport.cpp | 2 | ||||
-rw-r--r-- | tests/auto/main/tst_main.cpp | 4 | ||||
-rw-r--r-- | tests/auto/packageextractor/tst_packageextractor.cpp | 4 | ||||
-rw-r--r-- | tests/auto/packager-tool/tst_packager-tool.cpp | 2 | ||||
-rw-r--r-- | tests/auto/processreader/tst_processreader.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qml/crash/qmlcrash/qmlcrash.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/crash/qmlcrash/qmlcrash.h | 4 | ||||
-rw-r--r-- | tests/auto/runtime/tst_runtime.cpp | 2 | ||||
-rw-r--r-- | tests/auto/signature/tst_signature.cpp | 8 | ||||
-rw-r--r-- | tests/auto/sudo/tst_sudo.cpp | 53 |
16 files changed, 64 insertions, 68 deletions
diff --git a/tests/auto/application/tst_application.cpp b/tests/auto/application/tst_application.cpp index 299758bb..fc207077 100644 --- a/tests/auto/application/tst_application.cpp +++ b/tests/auto/application/tst_application.cpp @@ -42,7 +42,7 @@ public slots: void stop(bool forceKill) override { - Q_UNUSED(forceKill); + Q_UNUSED(forceKill) m_state = Am::NotRunning; } }; diff --git a/tests/auto/applicationinfo/tst_applicationinfo.cpp b/tests/auto/applicationinfo/tst_applicationinfo.cpp index 8c6e7192..585bf5b0 100644 --- a/tests/auto/applicationinfo/tst_applicationinfo.cpp +++ b/tests/auto/applicationinfo/tst_applicationinfo.cpp @@ -87,6 +87,8 @@ public: QString lastLoadFailure() const { return m_lastLoadFailure; } private: + Q_DISABLE_COPY_MOVE(TestPackageLoader) + QDir m_dataDir; QString m_lastLoadFailure; PackageInfo *m_pi = nullptr; @@ -215,7 +217,7 @@ void tst_ApplicationInfo::full() QCOMPARE(p->applications().size(), pl.info()->applications().size()); QCOMPARE(pl.intents().size(), pl.info()->intents().size()); - Application *a = qobject_cast<Application *>(p->applications().last()); + Application *a = p->applications().constLast(); QVERIFY(a); QCOMPARE(a->id(), ai->id()); @@ -230,7 +232,7 @@ void tst_ApplicationInfo::full() QCOMPARE(a->runtimeName(), ai->runtimeName()); QCOMPARE(a->runtimeParameters(), ai->runtimeParameters()); - Intent *i = pl.intents().last(); + Intent *i = pl.intents().constLast(); QVERIFY(i); QCOMPARE(i->intentId(), ii->id()); @@ -342,7 +344,7 @@ void tst_ApplicationInfo::inherit() QCOMPARE(p->descriptions(), qmlStringMap(pl.info()->descriptions())); QCOMPARE(p->categories(), pl.info()->categories()); - Application *a = qobject_cast<Application *>(p->applications().first()); + Application *a = p->applications().constFirst(); QVERIFY(a); QCOMPARE(a->icon(), p->icon()); @@ -351,7 +353,7 @@ void tst_ApplicationInfo::inherit() QCOMPARE(a->names(), p->names()); QCOMPARE(a->descriptions(), p->descriptions()); - Intent *i = pl.intents().first(); + Intent *i = pl.intents().constFirst(); QVERIFY(i); QCOMPARE(i->icon(), p->icon()); diff --git a/tests/auto/applicationinstaller/tst_applicationinstaller.cpp b/tests/auto/applicationinstaller/tst_applicationinstaller.cpp index b1016ee2..435ec5fc 100644 --- a/tests/auto/applicationinstaller/tst_applicationinstaller.cpp +++ b/tests/auto/applicationinstaller/tst_applicationinstaller.cpp @@ -26,8 +26,6 @@ using namespace Qt::StringLiterals; QT_USE_NAMESPACE_AM -static bool startedSudoServer = false; -static QString sudoServerError; static int spyTimeout = 5000; // shorthand for specifying QSignalSpy timeouts @@ -68,6 +66,8 @@ public: private: bool m_oldUnsigned; bool m_oldDevMode; + + Q_DISABLE_COPY_MOVE(AllowInstallations) }; class tst_PackageManager : public QObject @@ -76,7 +76,10 @@ class tst_PackageManager : public QObject public: tst_PackageManager(QObject *parent = nullptr); - ~tst_PackageManager(); + ~tst_PackageManager() override; + + static bool startedSudoServer; + static QString sudoServerError; private slots: void initTestCase(); @@ -175,6 +178,8 @@ private: QSignalSpy *m_failedSpy = nullptr; }; +bool tst_PackageManager::startedSudoServer = false; +QString tst_PackageManager::sudoServerError; tst_PackageManager::tst_PackageManager(QObject *parent) : QObject(parent) @@ -275,7 +280,7 @@ void tst_PackageManager::initTestCase() QVERIFY2(storecaFile.open(QIODevice::ReadOnly), qPrintable(storecaFile.errorString())); QVERIFY2(caFile.open(QIODevice::ReadOnly), qPrintable(caFile.errorString())); - QList<QByteArray> chainOfTrust; + QByteArrayList chainOfTrust; chainOfTrust << devcaFile.readAll() << caFile.readAll(); QVERIFY(!chainOfTrust.at(0).isEmpty()); QVERIFY(!chainOfTrust.at(1).isEmpty()); @@ -789,8 +794,10 @@ int main(int argc, char **argv) { try { Sudo::forkServer(Sudo::DropPrivilegesPermanently); - startedSudoServer = true; - } catch (...) { } + tst_PackageManager::startedSudoServer = true; + } catch (const Exception &e) { + tst_PackageManager::sudoServerError = e.errorString(); + } QCoreApplication a(argc, argv); tstPackageManager = new tst_PackageManager(&a); diff --git a/tests/auto/configuration/tst_configuration.cpp b/tests/auto/configuration/tst_configuration.cpp index f3e6cc15..45e4fa36 100644 --- a/tests/auto/configuration/tst_configuration.cpp +++ b/tests/auto/configuration/tst_configuration.cpp @@ -439,8 +439,8 @@ void tst_Configuration::commandLineConfig() << "main-cl.qml"; QStringList strCommandLine; - for (const auto &c : std::as_const(commandLine)) - strCommandLine << QString::fromLatin1(c); + for (const auto &cl : std::as_const(commandLine)) + strCommandLine << QString::fromLatin1(cl); c.parseWithArguments(strCommandLine); diff --git a/tests/auto/controller-tool/tst_controller-tool.cpp b/tests/auto/controller-tool/tst_controller-tool.cpp index 0698fddb..4dd553e7 100644 --- a/tests/auto/controller-tool/tst_controller-tool.cpp +++ b/tests/auto/controller-tool/tst_controller-tool.cpp @@ -169,7 +169,7 @@ void tst_ControllerTool::initTestCase() qInfo() << "Verbose mode is" << (verbose ? "on" : "off") << "(change by (un)setting $AM_VERBOSE_TEST)"; m_argc = 2; - m_argv = new char * [m_argc + 1]; + m_argv = new char * [size_t(m_argc) + 1]; m_argv[0] = qstrdup("tst_controller-tool"); m_argv[1] = qstrdup("--no-cache"); m_argv[m_argc] = nullptr; diff --git a/tests/auto/debugwrapper/tst_debugwrapper.cpp b/tests/auto/debugwrapper/tst_debugwrapper.cpp index 123f57ed..0b205c07 100644 --- a/tests/auto/debugwrapper/tst_debugwrapper.cpp +++ b/tests/auto/debugwrapper/tst_debugwrapper.cpp @@ -18,7 +18,7 @@ class tst_DebugWrapper : public QObject public: tst_DebugWrapper(QObject *parent = nullptr); - ~tst_DebugWrapper(); + ~tst_DebugWrapper() override; private slots: void specification_data(); diff --git a/tests/auto/installationreport/tst_installationreport.cpp b/tests/auto/installationreport/tst_installationreport.cpp index adf3403b..e4efbe6f 100644 --- a/tests/auto/installationreport/tst_installationreport.cpp +++ b/tests/auto/installationreport/tst_installationreport.cpp @@ -76,7 +76,7 @@ void tst_InstallationReport::test() QByteArray &yaml = buffer.buffer(); QVERIFY(!yaml.isEmpty()); - int pos = yaml.lastIndexOf("\n---\nhmac: '"); + qsizetype pos = yaml.lastIndexOf("\n---\nhmac: '"); QVERIFY(pos > 0); pos += 12; QByteArray hmac = QMessageAuthenticationCode::hash("data", "key", QCryptographicHash::Sha256).toHex(); diff --git a/tests/auto/main/tst_main.cpp b/tests/auto/main/tst_main.cpp index be285c90..d890c763 100644 --- a/tests/auto/main/tst_main.cpp +++ b/tests/auto/main/tst_main.cpp @@ -30,7 +30,7 @@ class tst_Main : public QObject public: tst_Main(); - ~tst_Main(); + ~tst_Main() override; private slots: void initTestCase(); @@ -110,7 +110,7 @@ void tst_Main::init() void tst_Main::initMain(const QString &mainQml) { argc = mainQml.isNull() ? 4 : 5; - argv = new char*[argc + 1]; + argv = new char*[size_t(argc) + 1]; argv[0] = qstrdup("tst_Main"); argv[1] = qstrdup("--dbus"); argv[2] = qstrdup("none"); diff --git a/tests/auto/packageextractor/tst_packageextractor.cpp b/tests/auto/packageextractor/tst_packageextractor.cpp index e9f21b90..81147f09 100644 --- a/tests/auto/packageextractor/tst_packageextractor.cpp +++ b/tests/auto/packageextractor/tst_packageextractor.cpp @@ -227,7 +227,7 @@ public: #endif } - ~FifoSource() + ~FifoSource() override { #ifdef Q_OS_UNIX ::unlink(m_fifoPath); @@ -251,7 +251,7 @@ public: while (!m_file.atEnd()) { qint64 bytesRead = m_file.read(buffer.data(), buffer.size()); QVERIFY(bytesRead >= 0); - qint64 bytesWritten = QT_WRITE(fifoFd, buffer.constData(), bytesRead); + qint64 bytesWritten = QT_WRITE(fifoFd, buffer.constData(), size_t(bytesRead)); QCOMPARE(bytesRead, bytesWritten); } QT_CLOSE(fifoFd); diff --git a/tests/auto/packager-tool/tst_packager-tool.cpp b/tests/auto/packager-tool/tst_packager-tool.cpp index 8758c10b..68b98120 100644 --- a/tests/auto/packager-tool/tst_packager-tool.cpp +++ b/tests/auto/packager-tool/tst_packager-tool.cpp @@ -96,7 +96,7 @@ void tst_PackagerTool::initTestCase() QVERIFY2(devcaFile.open(QIODevice::ReadOnly), qPrintable(devcaFile.errorString())); QVERIFY2(caFile.open(QIODevice::ReadOnly), qPrintable(devcaFile.errorString())); - QList<QByteArray> chainOfTrust; + QByteArrayList chainOfTrust; chainOfTrust << devcaFile.readAll() << caFile.readAll(); QVERIFY(!chainOfTrust.at(0).isEmpty()); QVERIFY(!chainOfTrust.at(1).isEmpty()); diff --git a/tests/auto/processreader/tst_processreader.cpp b/tests/auto/processreader/tst_processreader.cpp index 8b4aa4f2..d7ec5688 100644 --- a/tests/auto/processreader/tst_processreader.cpp +++ b/tests/auto/processreader/tst_processreader.cpp @@ -24,7 +24,7 @@ private slots: void memAdvanced(); private: - void printMem(const ProcessReader &reader); + void printMem(); ProcessReader reader; }; @@ -62,7 +62,7 @@ void tst_ProcessReader::memTestProcess() const QByteArray file = "/proc/" + QByteArray::number(QCoreApplication::applicationPid()) + "/smaps"; QVERIFY(reader.testReadSmaps(file)); - //printMem(reader); + //printMem(); QVERIFY(reader.memory.totalVm >= reader.memory.totalRss); QVERIFY(reader.memory.totalRss >= reader.memory.totalPss); QVERIFY(reader.memory.textVm >= reader.memory.textRss); @@ -74,7 +74,7 @@ void tst_ProcessReader::memTestProcess() void tst_ProcessReader::memBasic() { QVERIFY(reader.testReadSmaps(QFINDTESTDATA("basic.smaps").toLocal8Bit())); - //printMem(reader); + //printMem(); QCOMPARE(reader.memory.totalVm, 107384u); QCOMPARE(reader.memory.totalRss, 20352u); QCOMPARE(reader.memory.totalPss, 13814u); @@ -89,7 +89,7 @@ void tst_ProcessReader::memBasic() void tst_ProcessReader::memAdvanced() { QVERIFY(reader.testReadSmaps(QFINDTESTDATA("advanced.smaps").toLocal8Bit())); - //printMem(reader); + //printMem(); QCOMPARE(reader.memory.totalVm, 77728u); QCOMPARE(reader.memory.totalRss, 17612u); QCOMPARE(reader.memory.totalPss, 17547u); @@ -101,7 +101,7 @@ void tst_ProcessReader::memAdvanced() QCOMPARE(reader.memory.heapPss, 15740u); } -void tst_ProcessReader::printMem(const ProcessReader &reader) +void tst_ProcessReader::printMem() { qDebug() << "totalVm:" << reader.memory.totalVm; qDebug() << "totalRss:" << reader.memory.totalRss; diff --git a/tests/auto/qml/crash/qmlcrash/qmlcrash.cpp b/tests/auto/qml/crash/qmlcrash/qmlcrash.cpp index 19ad337a..3e2155bf 100644 --- a/tests/auto/qml/crash/qmlcrash/qmlcrash.cpp +++ b/tests/auto/qml/crash/qmlcrash/qmlcrash.cpp @@ -24,14 +24,14 @@ void QmlCrashPlugin::registerTypes(const char *uri) } -static void abortWithVeryLongSymbolNameOnTheStack800CharactersLong_CallMeIshmaelSomeYearsAgoNeverMindHowLongPreciselyHavingLittleOrNoMoneyInMyPurseAndNothingParticularToInterestMeOnShoreIThoughIWouldSailAboutALittlAndSeeTheWateryPartOfTheWorldItIsAWayIHaveOfDrivingOffTheSpleenAndRegulatingTheCirculationWhenenverIFindMyselfGrowingGrimAboutTheMouthWheneverItIsADampDrizzlyNovemberInMySoulWheneverIFindMyselfInvoluntarilyPausingBeforeCoffinWarehousesAndBringingUpTheRearOfEveryFuneralIMeetAndEspeciallyWheneverMyHyposGetSuchAnUpperHandOfMeThatItRequiresAStrongMoralPrincipleToPreventMeFromDeliberatelySteppingIntoTheStreetAndMethodicallyKnockingPeoplesHatsOffThenIAccountItHighTimeToGetToSeaAsSoonAsICanThisIsMySubstituteForPistolAndBallWithAPhilosophicalFlourishCatoThrowsHimselfUponHisSwordIQuietlyTakeToTheShip() +[[noreturn]] static void abortWithVeryLongSymbolNameOnTheStack800CharactersLong_CallMeIshmaelSomeYearsAgoNeverMindHowLongPreciselyHavingLittleOrNoMoneyInMyPurseAndNothingParticularToInterestMeOnShoreIThoughIWouldSailAboutALittlAndSeeTheWateryPartOfTheWorldItIsAWayIHaveOfDrivingOffTheSpleenAndRegulatingTheCirculationWhenenverIFindMyselfGrowingGrimAboutTheMouthWheneverItIsADampDrizzlyNovemberInMySoulWheneverIFindMyselfInvoluntarilyPausingBeforeCoffinWarehousesAndBringingUpTheRearOfEveryFuneralIMeetAndEspeciallyWheneverMyHyposGetSuchAnUpperHandOfMeThatItRequiresAStrongMoralPrincipleToPreventMeFromDeliberatelySteppingIntoTheStreetAndMethodicallyKnockingPeoplesHatsOffThenIAccountItHighTimeToGetToSeaAsSoonAsICanThisIsMySubstituteForPistolAndBallWithAPhilosophicalFlourishCatoThrowsHimselfUponHisSwordIQuietlyTakeToTheShip() { ::abort(); } void QmlCrash::accessIllegalMemory() const { - *(int*)1 = 42; + *reinterpret_cast<int *>(1) = 42; } void QmlCrash::accessIllegalMemoryInThread() diff --git a/tests/auto/qml/crash/qmlcrash/qmlcrash.h b/tests/auto/qml/crash/qmlcrash/qmlcrash.h index dd6b4b98..876840a9 100644 --- a/tests/auto/qml/crash/qmlcrash/qmlcrash.h +++ b/tests/auto/qml/crash/qmlcrash/qmlcrash.h @@ -32,8 +32,8 @@ public: Q_INVOKABLE void divideByZero() const; Q_INVOKABLE void abort() const; Q_INVOKABLE void raise(int sig) const; - Q_INVOKABLE void throwUnhandledException() const; - Q_INVOKABLE void exitGracefully() const; + [[noreturn]] Q_INVOKABLE void throwUnhandledException() const; + [[noreturn]] Q_INVOKABLE void exitGracefully() const; }; diff --git a/tests/auto/runtime/tst_runtime.cpp b/tests/auto/runtime/tst_runtime.cpp index d86e9865..839cfb78 100644 --- a/tests/auto/runtime/tst_runtime.cpp +++ b/tests/auto/runtime/tst_runtime.cpp @@ -56,7 +56,7 @@ public slots: void stop(bool forceKill) override { - Q_UNUSED(forceKill); + Q_UNUSED(forceKill) m_state = Am::NotRunning; } }; diff --git a/tests/auto/signature/tst_signature.cpp b/tests/auto/signature/tst_signature.cpp index babfd3a4..46887b43 100644 --- a/tests/auto/signature/tst_signature.cpp +++ b/tests/auto/signature/tst_signature.cpp @@ -30,7 +30,7 @@ private: QByteArray m_signingP12; QByteArray m_signingNoKeyP12; QByteArray m_signingPassword; - QList<QByteArray> m_verifyingPEM; + QByteArrayList m_verifyingPEM; }; tst_Signature::tst_Signature() @@ -90,11 +90,11 @@ void tst_Signature::check() Signature s3(QByteArray(4096, 'x')); QVERIFY(!s3.create(m_signingP12, m_signingPassword).isEmpty()); - QVERIFY(!s.verify(signature, QList<QByteArray>())); + QVERIFY(!s.verify(signature, QByteArrayList())); QVERIFY2(s.errorString().contains(u"Failed to verify"_s), qPrintable(s.errorString())); - QVERIFY(!s.verify(signature, QList<QByteArray>() << m_signingP12)); + QVERIFY(!s.verify(signature, QByteArrayList() << m_signingP12)); QVERIFY2(s.errorString().contains(u"not load"_s), qPrintable(s.errorString())); - QVERIFY(!s.verify(hash, QList<QByteArray>() << m_signingP12)); + QVERIFY(!s.verify(hash, QByteArrayList() << m_signingP12)); QVERIFY2(s.errorString().contains(u"not read"_s), qPrintable(s.errorString())); Signature s4 { QByteArray() }; diff --git a/tests/auto/sudo/tst_sudo.cpp b/tests/auto/sudo/tst_sudo.cpp index b4faae0e..99547773 100644 --- a/tests/auto/sudo/tst_sudo.cpp +++ b/tests/auto/sudo/tst_sudo.cpp @@ -10,36 +10,11 @@ #endif #include "utilities.h" +#include "exception.h" #include "sudo.h" QT_USE_NAMESPACE_AM -static int processTimeout = 3000; - -static bool startedSudoServer = false; -static QString sudoServerError; - -// sudo RAII style -class ScopedRootPrivileges -{ -public: - ScopedRootPrivileges() - { - m_uid = getuid(); - m_gid = getgid(); - if (setresuid(0, 0, 0) || setresgid(0, 0, 0)) - QFAIL("cannot re-gain root privileges"); - } - ~ScopedRootPrivileges() - { - if (setresgid(m_gid, m_gid, 0) || setresuid(m_uid, m_uid, 0)) - QFAIL("cannot drop root privileges"); - } -private: - uid_t m_uid; - gid_t m_gid; -}; - class tst_Sudo : public QObject { @@ -47,7 +22,10 @@ class tst_Sudo : public QObject public: tst_Sudo(QObject *parent = nullptr); - ~tst_Sudo(); + ~tst_Sudo() override; + + static bool startedSudoServer; + static QString sudoServerError; private slots: void initTestCase(); @@ -59,6 +37,9 @@ private: SudoClient *m_sudo = nullptr; }; +bool tst_Sudo::startedSudoServer = false; +QString tst_Sudo::sudoServerError; + tst_Sudo::tst_Sudo(QObject *parent) : QObject(parent) { } @@ -68,8 +49,6 @@ tst_Sudo::~tst_Sudo() void tst_Sudo::initTestCase() { - processTimeout *= timeoutFactor(); - QVERIFY2(startedSudoServer, qPrintable(sudoServerError)); m_sudo = SudoClient::instance(); QVERIFY(m_sudo); @@ -79,7 +58,13 @@ void tst_Sudo::initTestCase() void tst_Sudo::privileges() { - ScopedRootPrivileges sudo; + uid_t uid = getuid(); + gid_t gid = getgid(); + if (setresuid(0, 0, 0) || setresgid(0, 0, 0)) + QFAIL("cannot re-gain root privileges"); + + if (setresgid(gid, gid, 0) || setresuid(uid, uid, 0)) + QFAIL("cannot drop root privileges"); } void tst_Sudo::cleanupTestCase() @@ -94,8 +79,10 @@ int main(int argc, char **argv) { try { Sudo::forkServer(Sudo::DropPrivilegesRegainable); - startedSudoServer = true; - } catch (...) { } + tst_Sudo::startedSudoServer = true; + } catch (const Exception &e) { + tst_Sudo::sudoServerError = e.errorString(); + } QCoreApplication a(argc, argv); tstSudo = new tst_Sudo(&a); @@ -104,7 +91,7 @@ int main(int argc, char **argv) auto crashHandler = [](int sigNum) -> void { // we are doing very unsafe things from a within a signal handler, but // we've crashed anyway at this point and the alternative is that we are - // leaking mounts and attached loopback devices. + // potentially leaking mounts. tstSudo->~tst_Sudo(); |