File indexing completed on 2025-01-26 05:09:26

0001 /*
0002  * This file is part of the KDE wacomtablet project. For copyright
0003  * information and license terms see the AUTHORS and COPYING files
0004  * in the top-level directory of this distribution.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "kdedtestutils.h"
0021 
0022 #include <QtTest>
0023 
0024 using namespace Wacom;
0025 
0026 void KdedTestUtils::assertTabletInformation(const TabletInformation &expectedInformation, const TabletInformation &actualInformation)
0027 {
0028     // make sure the device list is equal
0029     QStringList expectedDeviceList = expectedInformation.getDeviceList();
0030     QStringList actualDeviceList = actualInformation.getDeviceList();
0031     QVERIFY(expectedDeviceList.size() == actualDeviceList.size());
0032 
0033     for (int i = 0; i < expectedDeviceList.size(); ++i) {
0034         QCOMPARE(expectedDeviceList.at(i), actualDeviceList.at(i));
0035     }
0036 
0037     // make sure the devices are equal
0038     foreach (const DeviceType &type, DeviceType::list()) {
0039         QCOMPARE(expectedInformation.getDeviceName(type), actualInformation.getDeviceName(type));
0040     }
0041 
0042     // compare tablet information
0043     QVERIFY(expectedInformation == actualInformation);
0044 
0045     foreach (const TabletInfo &info, TabletInfo::list()) {
0046         QCOMPARE(expectedInformation.get(info), actualInformation.get(info));
0047     }
0048 
0049     // check pad buttons
0050     QVERIFY(expectedInformation.hasButtons() == actualInformation.hasButtons());
0051 
0052     // check availability
0053     QVERIFY(expectedInformation.isAvailable() == actualInformation.isAvailable());
0054 }
0055 
0056 const QString KdedTestUtils::getAbsoluteDir(const QString &fileName)
0057 {
0058     if (fileName.isEmpty()) {
0059         return QString();
0060     }
0061 
0062     QFile file(fileName);
0063 
0064     if (!file.open(QIODevice::ReadOnly)) {
0065         return QString();
0066     }
0067 
0068     QFileInfo info(file);
0069     QString absoluteDir = info.absoluteDir().absolutePath();
0070 
0071     file.close();
0072 
0073     return absoluteDir;
0074 }
0075 
0076 const QString KdedTestUtils::getAbsolutePath(const QString &fileName)
0077 {
0078     if (fileName.isEmpty()) {
0079         return QString();
0080     }
0081 
0082     QFile file(fileName);
0083 
0084     if (!file.open(QIODevice::ReadOnly)) {
0085         return QString();
0086     }
0087 
0088     QFileInfo info(file);
0089     QString absolutePath = info.absoluteFilePath();
0090 
0091     file.close();
0092 
0093     return absolutePath;
0094 }