1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
SPDX-FileCopyrightText: 2019 Andrius Štikonas <andrius@stikonas.eu>
SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "testdevice.h"
#include "helpers.h"
#include "backend/corebackend.h"
#include "backend/corebackendmanager.h"
#include <QtAlgorithms>
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
KPMCoreInitializer init;
if (argc == 2)
init = KPMCoreInitializer(argv[1]);
return init.isValid() ? EXIT_SUCCESS : EXIT_FAILURE;
CoreBackend *backend = CoreBackendManager::self()->backend();
if (!backend) {
qWarning() << "Failed to load backend plugin";
return EXIT_FAILURE;
}
TestDevice device;
device.testDeviceName();
device.testDeviceNode();
device.testDeviceSize();
device.testDeviceTotalSectors();
return app.exec();
}
TestDevice::TestDevice()
{
operationStack = new OperationStack();
deviceScanner = new DeviceScanner(nullptr, *operationStack);
deviceScanner->scan();
// Get list of available devices on the system
devices = operationStack->previewDevices();
}
TestDevice::~TestDevice()
{
delete operationStack;
delete deviceScanner;
// Delete the list of devices
qDeleteAll(devices.begin(), devices.end());
devices.clear();
}
void TestDevice::testDeviceName()
{
if (devices.isEmpty()) {
exit(EXIT_FAILURE);
} else {
for (const auto &device : devices) {
if (device->name().isEmpty())
exit(EXIT_FAILURE);
}
}
}
void TestDevice::testDeviceNode()
{
if (devices.isEmpty()) {
exit(EXIT_FAILURE);
} else {
for (const auto &device : devices) {
if (device->deviceNode() == QString())
exit(EXIT_FAILURE);
}
}
}
void TestDevice::testDeviceSize()
{
if (devices.isEmpty()) {
exit(EXIT_FAILURE);
} else {
for (const auto &device : devices) {
if (device->logicalSize() < 0)
exit(EXIT_FAILURE);
}
}
}
void TestDevice::testDeviceTotalSectors()
{
if (devices.isEmpty()) {
exit(EXIT_FAILURE);
} else {
for (const auto &device : devices) {
if (device->totalLogical() < 0)
exit(EXIT_FAILURE);
}
}
}
|