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/tabletprofile.h" 0023 #include "common/tabletprofileconfigadaptor.h" 0024 0025 #include <QDir> 0026 #include <QString> 0027 #include <QTemporaryFile> 0028 0029 #include <KConfigGroup> 0030 #include <KSharedConfig> 0031 0032 #include <QtTest> 0033 0034 using namespace Wacom; 0035 0036 /** 0037 * @file testtabletprofileconfigadaptor.cpp 0038 * 0039 * @test UnitTest for the profile config adaptor 0040 */ 0041 class TestTabletProfileConfigAdaptor : public QObject 0042 { 0043 Q_OBJECT 0044 0045 private slots: 0046 void testConfig(); 0047 }; 0048 0049 QTEST_MAIN(TestTabletProfileConfigAdaptor) 0050 0051 void TestTabletProfileConfigAdaptor::testConfig() 0052 { 0053 QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + QLatin1String("testtabletprofileconfigadaptorrc_XXXXXX")); 0054 QVERIFY(tempFile.open()); 0055 tempFile.close(); 0056 tempFile.setAutoRemove(true); 0057 0058 KSharedConfig::Ptr config = KSharedConfig::openConfig(tempFile.fileName(), KConfig::SimpleConfig); 0059 QVERIFY(config); 0060 0061 TabletProfile writeTabletProfile(QLatin1String("TABLET")); 0062 KConfigGroup configGroup = KConfigGroup(config, writeTabletProfile.getName()); 0063 0064 DeviceProfile writeDeviceProfile1; 0065 DeviceType writeDeviceProfile1Type = DeviceType::Eraser; 0066 DeviceProfile writeDeviceProfile2; 0067 DeviceType writeDeviceProfile2Type = DeviceType::Stylus; 0068 CommonTestUtils::setValues(writeDeviceProfile1); 0069 CommonTestUtils::setValues(writeDeviceProfile2); 0070 writeDeviceProfile1.setDeviceType(writeDeviceProfile1Type); 0071 ; 0072 writeDeviceProfile2.setDeviceType(writeDeviceProfile2Type); 0073 0074 writeTabletProfile.setDevice(writeDeviceProfile1); 0075 writeTabletProfile.setDevice(writeDeviceProfile2); 0076 0077 TabletProfileConfigAdaptor writeAdaptor(writeTabletProfile); 0078 writeAdaptor.saveConfig(configGroup); 0079 0080 config->sync(); 0081 0082 TabletProfile readTabletProfile; 0083 TabletProfileConfigAdaptor readAdaptor(readTabletProfile); 0084 readAdaptor.loadConfig(configGroup); 0085 0086 QCOMPARE(readTabletProfile.getName(), writeTabletProfile.getName()); 0087 QVERIFY(readTabletProfile.listDevices().size() == writeTabletProfile.listDevices().size()); 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 CommonTestUtils::assertValues(readDeviceProfile1, writeDeviceProfile1Type.key().toLatin1().constData()); 0095 CommonTestUtils::assertValues(readDeviceProfile2, writeDeviceProfile2Type.key().toLatin1().constData()); 0096 } 0097 0098 #include "testtabletprofileconfigadaptor.moc"