From 41b3b833356b40cb9b86bd7136b853cfb50ecf60 Mon Sep 17 00:00:00 2001 From: Shubham Jangra Date: Thu, 23 May 2019 16:35:27 +0530 Subject: [PATCH] Cleanup and constantify --- test/testdevicescanner.cpp | 15 ++++++-------- test/testexternalcommand.cpp | 39 ++++++++++++++++++------------------ test/testinit.cpp | 7 ++----- test/testlist.cpp | 15 ++++++-------- test/testsmart.cpp | 4 ++-- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/test/testdevicescanner.cpp b/test/testdevicescanner.cpp index 0629e6d..65605af 100644 --- a/test/testdevicescanner.cpp +++ b/test/testdevicescanner.cpp @@ -69,22 +69,19 @@ int main( int argc, char **argv ) QCoreApplication app(argc, argv); std::unique_ptr i; - if (argc != 2) - { + if (argc != 2) { i = std::make_unique(); if (!i->isValid()) return 1; - } - else - { + } else { i = std::make_unique( argv[1] ); if (!i->isValid()) return 1; } auto backend = CoreBackendManager::self()->backend(); - if (!backend) - { + + if (!backend) { qWarning() << "Could not get backend."; return 1; } @@ -96,8 +93,8 @@ int main( int argc, char **argv ) const auto devices = operationStack->previewDevices(); qDebug() << "Found" << devices.length() << "devices."; - for (const auto pdev : devices) - { + + for (const auto &pdev : devices) { qDebug() << "Device @" << (void *)pdev; qDebug() << " " << pdev->prettyName(); diff --git a/test/testexternalcommand.cpp b/test/testexternalcommand.cpp index 438224a..3678fd9 100644 --- a/test/testexternalcommand.cpp +++ b/test/testexternalcommand.cpp @@ -26,30 +26,29 @@ #include #include -class runcmd : public QThread { -public: - -void run() override +class runcmd : public QThread { - ExternalCommand blkidCmd(QStringLiteral("blkid"), {}); - -// ExternalCommadHelper will refuse to run this or any other command which is not whitelisted. -// See src/util/externalcommand_whitelist.h for whitelisted commands. - blkidCmd.run(); - qDebug().noquote() << blkidCmd.output(); -} + public: + void run() override + { + ExternalCommand blkidCmd(QStringLiteral("blkid"), {}); + // ExternalCommadHelper will refuse to run this or any other command which is not whitelisted. + // See src/util/externalcommand_whitelist.h for whitelisted commands. + blkidCmd.run(); + qDebug().noquote() << blkidCmd.output(); + } }; -class runcmd2 : public QThread { -public: - -void run() override +class runcmd2 : public QThread { - ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") }); - lsblkCmd.run(); - qDebug().noquote() << lsblkCmd.output(); -} + public: + void run() override + { + ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") }); + lsblkCmd.run(); + qDebug().noquote() << lsblkCmd.output(); + } }; @@ -60,8 +59,10 @@ int main( int argc, char **argv ) runcmd a; runcmd2 b; + a.start(); a.wait(); + b.start(); b.wait(); diff --git a/test/testinit.cpp b/test/testinit.cpp index fd97f56..977c284 100644 --- a/test/testinit.cpp +++ b/test/testinit.cpp @@ -28,13 +28,10 @@ int main( int argc, char** argv ) { QCoreApplication app(argc, argv); - if ( argc != 2 ) - { + if ( argc != 2 ) { KPMCoreInitializer i; return i.isValid() ? 0 : 1; - } - else - { + } else { KPMCoreInitializer i( argv[1] ); return i.isValid() ? 0 : 1; } diff --git a/test/testlist.cpp b/test/testlist.cpp index 703283b..1b92866 100644 --- a/test/testlist.cpp +++ b/test/testlist.cpp @@ -66,30 +66,27 @@ int main( int argc, char **argv ) QCoreApplication app(argc, argv); std::unique_ptr i; - if (argc != 2) - { + if (argc != 2) { i = std::make_unique(); if (!i->isValid()) return 1; - } - else - { + } else { i = std::make_unique( argv[1] ); if (!i->isValid()) return 1; } auto backend = CoreBackendManager::self()->backend(); - if (!backend) - { + + if (!backend) { qWarning() << "Could not get backend."; return 1; } const auto devices = backend->scanDevices(ScanFlag::includeLoopback); qDebug() << "Found" << devices.length() << "devices."; - for (const auto pdev : devices) - { + + for (const auto &pdev : devices) { qDebug() << "Device @" << (void *)pdev; qDebug() << " " << pdev->prettyName(); diff --git a/test/testsmart.cpp b/test/testsmart.cpp index 2236af7..eab0936 100644 --- a/test/testsmart.cpp +++ b/test/testsmart.cpp @@ -55,7 +55,7 @@ static QString getDefaultDevicePath() static bool testSmartStatus() { - QString devicePath = getDefaultDevicePath(); + const QString devicePath = getDefaultDevicePath(); SmartStatus smart(devicePath); @@ -85,7 +85,7 @@ static bool testSmartStatus() static bool testSmartParser() { - QString devicePath = getDefaultDevicePath(); + const QString devicePath = getDefaultDevicePath(); SmartParser parser(devicePath);