File indexing completed on 2024-05-19 09:42:03

0001 /*
0002     SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
0003     SPDX-FileCopyrightText: 2019 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
0005 
0006     SPDX-License-Identifier: GPL-3.0-or-later
0007 */
0008 
0009 #include "testdevice.h" 
0010 #include "helpers.h"
0011 
0012 #include "backend/corebackend.h"
0013 #include "backend/corebackendmanager.h"
0014 
0015 #include <QtAlgorithms>
0016 #include <QCoreApplication>
0017 #include <QDebug>
0018 
0019 int main(int argc, char **argv)
0020 {
0021     QCoreApplication app(argc, argv);
0022     
0023     KPMCoreInitializer init;
0024     
0025     if (argc == 2)
0026         init = KPMCoreInitializer(argv[1]);
0027     
0028     return init.isValid() ? EXIT_SUCCESS : EXIT_FAILURE;
0029 
0030     CoreBackend *backend = CoreBackendManager::self()->backend();
0031     
0032     if (!backend) {
0033         qWarning() << "Failed to load backend plugin";
0034         return EXIT_FAILURE;
0035     }
0036     
0037     TestDevice device;
0038     
0039     device.testDeviceName();
0040     device.testDeviceNode();
0041     device.testDeviceSize();
0042     device.testDeviceTotalSectors();
0043     
0044     return app.exec();
0045 }
0046 
0047 TestDevice::TestDevice()
0048 {
0049     operationStack = new OperationStack();
0050     deviceScanner = new DeviceScanner(nullptr, *operationStack);
0051     deviceScanner->scan();
0052     
0053     // Get list of available devices on the system
0054     devices = operationStack->previewDevices(); 
0055 }
0056 
0057 TestDevice::~TestDevice()
0058 {    
0059     delete operationStack;
0060     delete deviceScanner;
0061     
0062     // Delete the list of devices
0063     qDeleteAll(devices.begin(), devices.end());
0064     devices.clear();
0065 }
0066 
0067 void TestDevice::testDeviceName()
0068 {
0069     if (devices.isEmpty()) {
0070         exit(EXIT_FAILURE);
0071     } else {
0072         for (const auto &device : devices) {
0073             if (device->name().isEmpty())
0074                 exit(EXIT_FAILURE);
0075         }
0076     }
0077 }
0078 
0079 void TestDevice::testDeviceNode()
0080 {
0081     if (devices.isEmpty()) {
0082         exit(EXIT_FAILURE);
0083     } else {
0084         for (const auto &device : devices) {
0085             if (device->deviceNode() == QString())
0086                 exit(EXIT_FAILURE);
0087         }
0088     }
0089 }
0090 
0091 void TestDevice::testDeviceSize()
0092 {
0093     if (devices.isEmpty()) {
0094         exit(EXIT_FAILURE);
0095     } else {
0096         for (const auto &device : devices) {
0097             if (device->logicalSize() < 0)
0098                 exit(EXIT_FAILURE);
0099         }
0100     }
0101 }
0102 
0103 void TestDevice::testDeviceTotalSectors()
0104 {
0105     if (devices.isEmpty()) {
0106         exit(EXIT_FAILURE);
0107     } else {
0108         for (const auto &device : devices) {
0109             if (device->totalLogical() < 0)
0110                 exit(EXIT_FAILURE);
0111         }
0112     }
0113 }