File indexing completed on 2024-12-22 05:17:13

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 
0022 #include <QtTest>
0023 
0024 #include "common/deviceproperty.h"
0025 
0026 using namespace Wacom;
0027 
0028 const long CommonTestUtils::DEVICEINFORMATION_DEVICE_ID = 42;
0029 const QString CommonTestUtils::DEVICEINFORMATION_DEVICE_NODE = QLatin1String("/dev/input/event1");
0030 const long CommonTestUtils::DEVICEINFORMATION_PRODUCT_ID = 1234;
0031 const long CommonTestUtils::DEVICEINFORMATION_TABLET_SERIAL = 123456;
0032 const long CommonTestUtils::DEVICEINFORMATION_VENDOR_ID = 4321;
0033 
0034 const QString CommonTestUtils::TABLETINFORMATION_COMPANY_ID = QLatin1String("1234");
0035 const QString CommonTestUtils::TABLETINFORMATION_COMPANY_NAME = QLatin1String("Wacom Ltd.");
0036 const QString CommonTestUtils::TABLETINFORMATION_TABLET_MODEL = QLatin1String("Bamboo Create");
0037 const QString CommonTestUtils::TABLETINFORMATION_TABLET_NAME = QLatin1String("Bamboo Touch");
0038 const QString CommonTestUtils::TABLETINFORMATION_TABLET_SERIAL = QLatin1String("6666");
0039 const QString CommonTestUtils::TABLETINFORMATION_TABLET_ID = QString::fromLatin1("%1").arg(6666, 4, 16, QLatin1Char('0')).toUpper();
0040 const bool CommonTestUtils::TABLETINFORMATION_HAS_BUTTONS = true;
0041 const bool CommonTestUtils::TABLETINFORMATION_HAS_TOUCHRING = true;
0042 const bool CommonTestUtils::TABLETINFORMATION_HAS_TOUCHSTRIPLEFT = true;
0043 const bool CommonTestUtils::TABLETINFORMATION_HAS_TOUCHSTRIPRIGHT = true;
0044 const bool CommonTestUtils::TABLETINFORMATION_HAS_WHEEL = true;
0045 const bool CommonTestUtils::TABLETINFORMATION_IS_AVAILABLE = true;
0046 const QString CommonTestUtils::TABLETINFORMATION_NUM_PAD_BUTTONS = QLatin1String("4");
0047 
0048 const QString CommonTestUtils::TABLETINFORMATION_DEV1_NAME = QLatin1String("Device Stylus");
0049 const QString CommonTestUtils::TABLETINFORMATION_DEV1_TYPE = QLatin1String("stylus");
0050 
0051 const QString CommonTestUtils::TABLETINFORMATION_DEV2_NAME = QLatin1String("Device Eraser");
0052 const QString CommonTestUtils::TABLETINFORMATION_DEV2_TYPE = QLatin1String("eraser");
0053 
0054 const QString CommonTestUtils::TABLETINFORMATION_DEV3_NAME = QLatin1String("Device Pad");
0055 const QString CommonTestUtils::TABLETINFORMATION_DEV3_TYPE = QLatin1String("pad");
0056 
0057 void CommonTestUtils::assertValues(const DeviceInformation &info, const DeviceType &expectedType, const QString &expectedName)
0058 {
0059     QVERIFY(info.getDeviceId() == DEVICEINFORMATION_DEVICE_ID);
0060     QCOMPARE(info.getDeviceNode(), DEVICEINFORMATION_DEVICE_NODE);
0061     QCOMPARE(info.getName(), expectedName);
0062     QVERIFY(info.getProductId() == DEVICEINFORMATION_PRODUCT_ID);
0063     QVERIFY(info.getTabletSerial() == DEVICEINFORMATION_TABLET_SERIAL);
0064     QVERIFY(info.getType() == expectedType);
0065     QVERIFY(info.getVendorId() == DEVICEINFORMATION_VENDOR_ID);
0066 }
0067 
0068 void CommonTestUtils::assertValues(DeviceProfile &profile, const char *name)
0069 {
0070     foreach (const DeviceProperty &property, DeviceProperty::list()) {
0071         QCOMPARE(profile.getProperty(property.id()), property.id().key());
0072     }
0073 
0074     if (name != nullptr) {
0075         QCOMPARE(profile.getName(), QLatin1String(name));
0076     } else {
0077         QCOMPARE(profile.getName(), DeviceType::Pad.key());
0078     }
0079 }
0080 
0081 void CommonTestUtils::assertValues(const TabletInformation &info)
0082 {
0083     QCOMPARE(info.get(TabletInfo::CompanyId), TABLETINFORMATION_COMPANY_ID);
0084     QCOMPARE(info.get(TabletInfo::CompanyName), TABLETINFORMATION_COMPANY_NAME);
0085     QCOMPARE(info.get(TabletInfo::TabletId), TABLETINFORMATION_TABLET_ID);
0086     QCOMPARE(info.get(TabletInfo::TabletModel), TABLETINFORMATION_TABLET_MODEL);
0087     QCOMPARE(info.get(TabletInfo::TabletName), TABLETINFORMATION_TABLET_NAME);
0088     QCOMPARE(info.get(TabletInfo::TabletSerial), TABLETINFORMATION_TABLET_SERIAL);
0089 
0090     QVERIFY(info.isAvailable() == TABLETINFORMATION_IS_AVAILABLE);
0091     QVERIFY(info.hasButtons() == TABLETINFORMATION_HAS_BUTTONS);
0092 
0093     QStringList deviceList = info.getDeviceList();
0094     QVERIFY(deviceList.size() == 3);
0095     QVERIFY(deviceList.contains(TABLETINFORMATION_DEV1_NAME));
0096     QVERIFY(deviceList.contains(TABLETINFORMATION_DEV2_NAME));
0097     QVERIFY(deviceList.contains(TABLETINFORMATION_DEV3_NAME));
0098 }
0099 
0100 void CommonTestUtils::setValues(DeviceInformation &info)
0101 {
0102     info.setDeviceId(DEVICEINFORMATION_DEVICE_ID);
0103     info.setDeviceNode(DEVICEINFORMATION_DEVICE_NODE);
0104     info.setProductId(DEVICEINFORMATION_PRODUCT_ID);
0105     info.setTabletSerial(DEVICEINFORMATION_TABLET_SERIAL);
0106     info.setVendorId(DEVICEINFORMATION_VENDOR_ID);
0107 }
0108 
0109 void CommonTestUtils::setValues(DeviceProfile &profile)
0110 {
0111     foreach (const DeviceProperty &property, DeviceProperty::list()) {
0112         profile.setProperty(property.id(), property.id().key());
0113     }
0114 
0115     if (profile.getDeviceType() == DeviceType::Unknown) {
0116         profile.setDeviceType(DeviceType::Pad);
0117     }
0118 }
0119 
0120 void CommonTestUtils::setValues(TabletInformation &info)
0121 {
0122     info.set(TabletInfo::CompanyId, TABLETINFORMATION_COMPANY_ID);
0123     info.set(TabletInfo::CompanyName, TABLETINFORMATION_COMPANY_NAME);
0124     info.set(TabletInfo::TabletModel, TABLETINFORMATION_TABLET_MODEL);
0125     info.set(TabletInfo::TabletName, TABLETINFORMATION_TABLET_NAME);
0126     info.set(TabletInfo::TabletSerial, TABLETINFORMATION_TABLET_SERIAL);
0127 
0128     info.set(TabletInfo::HasLeftTouchStrip, TABLETINFORMATION_HAS_TOUCHSTRIPLEFT);
0129     info.set(TabletInfo::HasRightTouchStrip, TABLETINFORMATION_HAS_TOUCHSTRIPRIGHT);
0130     info.set(TabletInfo::HasTouchRing, TABLETINFORMATION_HAS_TOUCHRING);
0131     info.set(TabletInfo::HasWheel, TABLETINFORMATION_HAS_WHEEL);
0132 
0133     info.setAvailable(TABLETINFORMATION_IS_AVAILABLE);
0134 
0135     DeviceInformation dev1Info(*DeviceType::find(TABLETINFORMATION_DEV1_TYPE), TABLETINFORMATION_DEV1_NAME);
0136     DeviceInformation dev2Info(*DeviceType::find(TABLETINFORMATION_DEV2_TYPE), TABLETINFORMATION_DEV2_NAME);
0137     DeviceInformation dev3Info(*DeviceType::find(TABLETINFORMATION_DEV3_TYPE), TABLETINFORMATION_DEV3_NAME);
0138 
0139     info.setDevice(dev1Info);
0140     info.setDevice(dev2Info);
0141     info.setDevice(dev3Info);
0142 }