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 
0024 #include <QtTest>
0025 
0026 using namespace Wacom;
0027 
0028 /**
0029  * @file testtabletprofile.cpp
0030  *
0031  * @test UnitTest for the profile manager
0032  */
0033 class TestTabletProfile : public QObject
0034 {
0035     Q_OBJECT
0036 
0037 private slots:
0038     void testClearDevices();
0039     void testConstructor();
0040     void testSetDevice();
0041     void testCopy();
0042 };
0043 
0044 QTEST_MAIN(TestTabletProfile)
0045 
0046 void TestTabletProfile::testConstructor()
0047 {
0048     TabletProfile profile1;
0049     QVERIFY(profile1.getName().isEmpty());
0050 
0051     QLatin1String name("TEST");
0052     TabletProfile profile2(name);
0053     QCOMPARE(profile2.getName(), name);
0054 }
0055 
0056 void TestTabletProfile::testClearDevices()
0057 {
0058     DeviceType deviceType = DeviceType::Touch;
0059     DeviceProfile deviceProfile(deviceType);
0060     TabletProfile tabletProfile(QLatin1String("TABLET"));
0061     tabletProfile.setDevice(deviceProfile);
0062 
0063     QVERIFY(tabletProfile.hasDevice(deviceType));
0064     QVERIFY(tabletProfile.listDevices().size() == 1);
0065 
0066     tabletProfile.clearDevices();
0067 
0068     QVERIFY(tabletProfile.listDevices().size() == 0);
0069 }
0070 
0071 void TestTabletProfile::testCopy()
0072 {
0073     DeviceProfile profile1;
0074     DeviceType profile1Type = DeviceType::Stylus;
0075     DeviceProfile profile2;
0076     DeviceType profile2Type = DeviceType::Eraser;
0077     CommonTestUtils::setValues(profile1);
0078     CommonTestUtils::setValues(profile2);
0079 
0080     // names have to be set AFTER CommonTestUtils::setValues()
0081     profile1.setDeviceType(profile1Type);
0082     profile2.setDeviceType(profile2Type);
0083     ;
0084 
0085     TabletProfile tabletProfile(QLatin1String("TABLET"));
0086     tabletProfile.setDevice(profile1);
0087     tabletProfile.setDevice(profile2);
0088 
0089     TabletProfile tabletProfileCopy = tabletProfile;
0090 
0091     QCOMPARE(tabletProfileCopy.getName(), tabletProfile.getName());
0092     QVERIFY(tabletProfileCopy.hasDevice(profile1Type));
0093     QVERIFY(tabletProfileCopy.hasDevice(profile2Type));
0094     QVERIFY(tabletProfileCopy.listDevices().contains(profile1.getName()));
0095     QVERIFY(tabletProfileCopy.listDevices().contains(profile2.getName()));
0096 
0097     DeviceProfile profile1Copy = tabletProfileCopy.getDevice(profile1Type);
0098     DeviceProfile profile2Copy = tabletProfileCopy.getDevice(profile2Type);
0099 
0100     CommonTestUtils::assertValues(profile1Copy, profile1Type.key().toLatin1().constData());
0101     CommonTestUtils::assertValues(profile2Copy, profile2Type.key().toLatin1().constData());
0102 }
0103 
0104 void TestTabletProfile::testSetDevice()
0105 {
0106     DeviceType deviceType = DeviceType::Cursor;
0107     DeviceProfile deviceProfile;
0108     CommonTestUtils::setValues(deviceProfile);
0109     deviceProfile.setDeviceType(deviceType);
0110 
0111     TabletProfile tabletProfile(QLatin1String("TABLET"));
0112     tabletProfile.setDevice(deviceProfile);
0113 
0114     QVERIFY(tabletProfile.hasDevice(deviceType));
0115     QVERIFY(tabletProfile.listDevices().size() == 1);
0116 
0117     DeviceProfile getProfile = tabletProfile.getDevice(deviceType);
0118     CommonTestUtils::assertValues(getProfile, deviceType.key().toLatin1().constData());
0119 }
0120 
0121 #include "testtabletprofile.moc"