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

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/deviceinformation.h"
0022 #include "common/devicetype.h"
0023 #include "common/tabletinfo.h"
0024 #include "common/tabletinformation.h"
0025 
0026 #include <QtTest>
0027 
0028 using namespace Wacom;
0029 
0030 /**
0031  * @file testtabletinformation.cpp
0032  *
0033  * @test UnitTest for the profile manager
0034  */
0035 class TestTabletInformation : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 private slots:
0040     void testCompare();
0041     void testConstructor();
0042     void testCopy();
0043     void testSetter();
0044 };
0045 
0046 QTEST_MAIN(TestTabletInformation)
0047 
0048 void TestTabletInformation::testCompare()
0049 {
0050     TabletInformation tabletInfo1;
0051     TabletInformation tabletInfo2;
0052 
0053     CommonTestUtils::setValues(tabletInfo1);
0054     CommonTestUtils::assertValues(tabletInfo1);
0055     QVERIFY(tabletInfo1 != tabletInfo2);
0056 
0057     CommonTestUtils::setValues(tabletInfo2);
0058     CommonTestUtils::assertValues(tabletInfo2);
0059     QVERIFY(tabletInfo1 == tabletInfo2);
0060 
0061     // changing the available flag shouldn't change anything
0062     tabletInfo2.setAvailable(!CommonTestUtils::TABLETINFORMATION_IS_AVAILABLE);
0063     QVERIFY(tabletInfo1 == tabletInfo2);
0064 }
0065 
0066 void TestTabletInformation::testConstructor()
0067 {
0068     // default constructor
0069     TabletInformation tabletInfo1;
0070 
0071     QVERIFY(tabletInfo1.getTabletSerial() == 0);
0072 
0073     foreach (const TabletInfo &info, TabletInfo::list()) {
0074         QVERIFY(tabletInfo1.get(info).isEmpty());
0075     }
0076 
0077     // serial constructor
0078     long expectedSerial = 1234;
0079     TabletInformation tabletInfo2(expectedSerial);
0080 
0081     QVERIFY(tabletInfo2.getTabletSerial() == expectedSerial);
0082 
0083     foreach (const TabletInfo &info, TabletInfo::list()) {
0084         QString value = tabletInfo2.get(info);
0085 
0086         if (info == TabletInfo::TabletSerial) {
0087             QVERIFY(value == QString::number(expectedSerial));
0088         } else if (info == TabletInfo::TabletId) {
0089             QVERIFY(value == QString::fromLatin1("%1").arg(expectedSerial, 4, 16, QLatin1Char('0')).toUpper());
0090         } else {
0091             QVERIFY(value.isEmpty());
0092         }
0093     }
0094 }
0095 
0096 void TestTabletInformation::testCopy()
0097 {
0098     TabletInformation tabletInfo1;
0099 
0100     CommonTestUtils::setValues(tabletInfo1);
0101     CommonTestUtils::assertValues(tabletInfo1);
0102 
0103     // Copy Constructor
0104     TabletInformation tabletInfo2(tabletInfo1);
0105     CommonTestUtils::assertValues(tabletInfo2);
0106 
0107     // Copy Operator
0108     TabletInformation tabletInfo3;
0109     tabletInfo3 = tabletInfo1;
0110     CommonTestUtils::assertValues(tabletInfo3);
0111 }
0112 
0113 void TestTabletInformation::testSetter()
0114 {
0115     TabletInformation info;
0116 
0117     CommonTestUtils::setValues(info);
0118     CommonTestUtils::assertValues(info);
0119 
0120     DeviceType dev1Type = *DeviceType::find(CommonTestUtils::TABLETINFORMATION_DEV1_TYPE);
0121     DeviceType dev2Type = *DeviceType::find(CommonTestUtils::TABLETINFORMATION_DEV2_TYPE);
0122     DeviceType dev3Type = *DeviceType::find(CommonTestUtils::TABLETINFORMATION_DEV3_TYPE);
0123 
0124     // getDevice()
0125     const DeviceInformation *dev1Info = info.getDevice(dev1Type);
0126     const DeviceInformation *dev2Info = info.getDevice(dev2Type);
0127     const DeviceInformation *dev3Info = info.getDevice(dev3Type);
0128     QVERIFY(dev1Info != NULL);
0129     QVERIFY(dev2Info != NULL);
0130     QVERIFY(dev3Info != NULL);
0131 
0132     // hasDevice()
0133     QVERIFY(info.hasDevice(dev1Type));
0134     QVERIFY(info.hasDevice(dev1Info->getDeviceId()));
0135     QVERIFY(info.hasDevice(dev2Type));
0136     QVERIFY(info.hasDevice(dev2Info->getDeviceId()));
0137     QVERIFY(info.hasDevice(dev3Type));
0138     QVERIFY(info.hasDevice(dev3Info->getDeviceId()));
0139 
0140     // getDeviceName()
0141     QCOMPARE(info.getDeviceName(dev1Type), CommonTestUtils::TABLETINFORMATION_DEV1_NAME);
0142     QCOMPARE(info.getDeviceName(dev2Type), CommonTestUtils::TABLETINFORMATION_DEV2_NAME);
0143     QCOMPARE(info.getDeviceName(dev3Type), CommonTestUtils::TABLETINFORMATION_DEV3_NAME);
0144 
0145     // getTabletSerial()
0146     QVERIFY(info.getTabletSerial() == CommonTestUtils::TABLETINFORMATION_TABLET_SERIAL.toLong());
0147 }
0148 
0149 #include "testtabletinformation.moc"