File indexing completed on 2024-12-29 05:08:32
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 "../commontestutils.h" 0021 #include "common/deviceprofile.h" 0022 #include "common/profilemanager.h" 0023 #include "common/tabletprofile.h" 0024 0025 #include <QDir> 0026 #include <QString> 0027 #include <QTemporaryFile> 0028 0029 #include <QtTest> 0030 0031 using namespace Wacom; 0032 0033 /** 0034 * @file testprofilemanager.cpp 0035 * 0036 * @test UnitTest for the profile manager 0037 */ 0038 class TestProfileManager : public QObject 0039 { 0040 Q_OBJECT 0041 0042 private slots: 0043 void testConfig(); 0044 }; 0045 0046 QTEST_MAIN(TestProfileManager) 0047 0048 void TestProfileManager::testConfig() 0049 { 0050 QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + QLatin1String("testprofilemanagerrc_XXXXXX")); 0051 QVERIFY(tempFile.open()); 0052 tempFile.close(); 0053 tempFile.setAutoRemove(true); 0054 0055 DeviceProfile writeDeviceProfile1; 0056 DeviceType writeDeviceProfile1Type = DeviceType::Stylus; 0057 DeviceProfile writeDeviceProfile2; 0058 DeviceType writeDeviceProfile2Type = DeviceType::Eraser; 0059 0060 CommonTestUtils::setValues(writeDeviceProfile1); 0061 CommonTestUtils::setValues(writeDeviceProfile2); 0062 writeDeviceProfile1.setDeviceType(writeDeviceProfile1Type); 0063 ; 0064 writeDeviceProfile2.setDeviceType(writeDeviceProfile2Type); 0065 ; 0066 0067 TabletProfile writeTabletProfile(QLatin1String("Test Tablet Profile")); 0068 writeTabletProfile.setDevice(writeDeviceProfile1); 0069 writeTabletProfile.setDevice(writeDeviceProfile2); 0070 0071 ProfileManager writeManager(tempFile.fileName()); 0072 0073 writeManager.readProfiles(QLatin1String("Test Tablet Device")); 0074 writeManager.saveProfile(writeTabletProfile); 0075 0076 QVERIFY(writeManager.hasIdentifier(QLatin1String("Test Tablet Device"))); 0077 QVERIFY(writeManager.hasProfile(writeTabletProfile.getName())); 0078 0079 ProfileManager readManager(tempFile.fileName()); 0080 QVERIFY(readManager.hasIdentifier(QLatin1String("Test Tablet Device"))); 0081 0082 readManager.readProfiles(QLatin1String("Test Tablet Device")); 0083 QVERIFY(readManager.hasProfile(writeTabletProfile.getName())); 0084 0085 TabletProfile readTabletProfile = readManager.loadProfile(writeTabletProfile.getName()); 0086 QCOMPARE(writeTabletProfile.getName(), readTabletProfile.getName()); 0087 QVERIFY(readTabletProfile.listDevices().size() == 2); 0088 QVERIFY(readTabletProfile.hasDevice(writeDeviceProfile1Type)); 0089 QVERIFY(readTabletProfile.hasDevice(writeDeviceProfile2Type)); 0090 0091 DeviceProfile readDeviceProfile1 = readTabletProfile.getDevice(writeDeviceProfile1Type); 0092 DeviceProfile readDeviceProfile2 = readTabletProfile.getDevice(writeDeviceProfile2Type); 0093 0094 QCOMPARE(writeDeviceProfile1.getName(), readDeviceProfile1.getName()); 0095 QCOMPARE(writeDeviceProfile2.getName(), readDeviceProfile2.getName()); 0096 0097 CommonTestUtils::assertValues(readDeviceProfile1, writeDeviceProfile1Type.key().toLatin1().constData()); 0098 CommonTestUtils::assertValues(readDeviceProfile2, writeDeviceProfile2Type.key().toLatin1().constData()); 0099 } 0100 0101 #include "testprofilemanager.moc"