Browse Source

Cleanup and constantify

master
Shubham Jangra 1 year ago
parent
commit
41b3b83335
5 changed files with 36 additions and 44 deletions
  1. +6
    -9
      test/testdevicescanner.cpp
  2. +20
    -19
      test/testexternalcommand.cpp
  3. +2
    -5
      test/testinit.cpp
  4. +6
    -9
      test/testlist.cpp
  5. +2
    -2
      test/testsmart.cpp

+ 6
- 9
test/testdevicescanner.cpp View File

@@ -69,22 +69,19 @@ int main( int argc, char **argv )
QCoreApplication app(argc, argv);
std::unique_ptr<KPMCoreInitializer> i;

if (argc != 2)
{
if (argc != 2) {
i = std::make_unique<KPMCoreInitializer>();
if (!i->isValid())
return 1;
}
else
{
} else {
i = std::make_unique<KPMCoreInitializer>( 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();



+ 20
- 19
test/testexternalcommand.cpp View File

@@ -26,30 +26,29 @@
#include <QDebug>
#include <QThread>

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();



+ 2
- 5
test/testinit.cpp View File

@@ -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;
}


+ 6
- 9
test/testlist.cpp View File

@@ -66,30 +66,27 @@ int main( int argc, char **argv )
QCoreApplication app(argc, argv);
std::unique_ptr<KPMCoreInitializer> i;

if (argc != 2)
{
if (argc != 2) {
i = std::make_unique<KPMCoreInitializer>();
if (!i->isValid())
return 1;
}
else
{
} else {
i = std::make_unique<KPMCoreInitializer>( 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();



+ 2
- 2
test/testsmart.cpp View File

@@ -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);



Loading…
Cancel
Save