2019-07-21 20:48:31 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2019 by Shubham <aryan100jangid@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
|
|
|
|
#include "testdevice.h"
|
2019-12-09 16:09:53 +00:00
|
|
|
#include "helpers.h"
|
2019-07-21 20:48:31 +01:00
|
|
|
|
|
|
|
#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]);
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
return init.isValid() ? EXIT_SUCCESS : EXIT_FAILURE;
|
2019-07-21 20:48:31 +01:00
|
|
|
|
|
|
|
CoreBackend *backend = CoreBackendManager::self()->backend();
|
|
|
|
|
|
|
|
if (!backend) {
|
|
|
|
qWarning() << "Failed to load backend plugin";
|
2019-11-07 22:28:01 +00:00
|
|
|
return EXIT_FAILURE;
|
2019-07-21 20:48:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestDevice device;
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
device.testDeviceName();
|
|
|
|
device.testDeviceNode();
|
|
|
|
device.testDeviceSize();
|
|
|
|
device.testDeviceTotalSectors();
|
2019-07-21 20:48:31 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
void TestDevice::testDeviceName()
|
2019-07-21 20:48:31 +01:00
|
|
|
{
|
|
|
|
if (devices.isEmpty()) {
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
} else {
|
|
|
|
for (const auto &device : devices) {
|
2019-12-09 16:09:53 +00:00
|
|
|
if (device->name().isEmpty())
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
void TestDevice::testDeviceNode()
|
2019-07-21 20:48:31 +01:00
|
|
|
{
|
|
|
|
if (devices.isEmpty()) {
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
} else {
|
|
|
|
for (const auto &device : devices) {
|
|
|
|
if (device->deviceNode() == QString())
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
void TestDevice::testDeviceSize()
|
2019-07-21 20:48:31 +01:00
|
|
|
{
|
|
|
|
if (devices.isEmpty()) {
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
} else {
|
|
|
|
for (const auto &device : devices) {
|
|
|
|
if (device->logicalSize() < 0)
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 22:28:01 +00:00
|
|
|
void TestDevice::testDeviceTotalSectors()
|
2019-07-21 20:48:31 +01:00
|
|
|
{
|
|
|
|
if (devices.isEmpty()) {
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
} else {
|
|
|
|
for (const auto &device : devices) {
|
|
|
|
if (device->totalLogical() < 0)
|
2019-11-07 22:28:01 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2019-07-21 20:48:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|