Changeset View
Changeset View
Standalone View
Standalone View
test/testdevice.cpp
- This file was added.
1 | /************************************************************************* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by Shubham <aryan100jangid@gmail.com> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or * | ||||
5 | * modify it under the terms of the GNU General Public License as * | ||||
6 | * published by the Free Software Foundation; either version 3 of * | ||||
7 | * the License, or (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | ||||
16 | *************************************************************************/ | ||||
17 | | ||||
18 | // SPDX-License-Identifier: GPL-3.0+ | ||||
19 | | ||||
20 | #include "helpers.h" | ||||
21 | #include "testdevice.h" | ||||
22 | | ||||
23 | #include "backend/corebackend.h" | ||||
24 | #include "backend/corebackendmanager.h" | ||||
25 | | ||||
26 | #include <QtAlgorithms> | ||||
27 | #include <QCoreApplication> | ||||
28 | #include <QDebug> | ||||
29 | | ||||
30 | int main(int argc, char **argv) | ||||
31 | { | ||||
32 | QCoreApplication app(argc, argv); | ||||
33 | | ||||
34 | KPMCoreInitializer init; | ||||
35 | | ||||
36 | if (argc == 2) | ||||
37 | init = KPMCoreInitializer(argv[1]); | ||||
38 | | ||||
39 | return init.isValid() ? true : false; | ||||
40 | | ||||
41 | CoreBackend *backend = CoreBackendManager::self()->backend(); | ||||
42 | | ||||
43 | if (!backend) { | ||||
44 | qWarning() << "Failed to load backend plugin"; | ||||
45 | return false; | ||||
46 | } | ||||
47 | | ||||
48 | TestDevice device; | ||||
49 | | ||||
50 | if (!device.testDeviceName() || !device.testDeviceNode() || !device.testDeviceSize() || !device.testDeviceTotalSectors()) | ||||
51 | return false; | ||||
52 | | ||||
53 | return app.exec(); | ||||
54 | } | ||||
55 | | ||||
56 | TestDevice::TestDevice() | ||||
57 | { | ||||
58 | operationStack = new OperationStack(); | ||||
59 | deviceScanner = new DeviceScanner(nullptr, *operationStack); | ||||
60 | deviceScanner->scan(); | ||||
61 | | ||||
62 | // Get list of available devices on the system | ||||
63 | devices = operationStack->previewDevices(); | ||||
64 | } | ||||
65 | | ||||
66 | TestDevice::~TestDevice() | ||||
67 | { | ||||
68 | delete operationStack; | ||||
69 | delete deviceScanner; | ||||
70 | | ||||
71 | // Delete the list of devices | ||||
72 | qDeleteAll(devices.begin(), devices.end()); | ||||
73 | devices.clear(); | ||||
74 | } | ||||
75 | | ||||
76 | bool TestDevice::testDeviceName() | ||||
77 | { | ||||
78 | if (devices.isEmpty()) { | ||||
79 | return false; | ||||
80 | } else { | ||||
81 | for (const auto &device : devices) { | ||||
82 | if (device->name() == QString()) | ||||
83 | return false; | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
87 | return true; | ||||
88 | } | ||||
89 | | ||||
90 | bool TestDevice::testDeviceNode() | ||||
91 | { | ||||
92 | if (devices.isEmpty()) { | ||||
93 | return false; | ||||
94 | } else { | ||||
95 | for (const auto &device : devices) { | ||||
96 | if (device->deviceNode() == QString()) | ||||
97 | return false; | ||||
98 | } | ||||
99 | } | ||||
100 | | ||||
101 | return true; | ||||
102 | } | ||||
103 | | ||||
104 | bool TestDevice::testDeviceSize() | ||||
105 | { | ||||
106 | if (devices.isEmpty()) { | ||||
107 | return false; | ||||
108 | } else { | ||||
109 | for (const auto &device : devices) { | ||||
110 | if (device->logicalSize() < 0) | ||||
111 | return false; | ||||
112 | } | ||||
113 | } | ||||
114 | | ||||
115 | return true; | ||||
116 | } | ||||
117 | | ||||
118 | bool TestDevice::testDeviceTotalSectors() | ||||
119 | { | ||||
120 | if (devices.isEmpty()) { | ||||
121 | return false; | ||||
122 | } else { | ||||
123 | for (const auto &device : devices) { | ||||
124 | if (device->totalLogical() < 0) | ||||
125 | return false; | ||||
126 | } | ||||
127 | } | ||||
128 | | ||||
129 | return true; | ||||
130 | } |