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 "common/libwacomwrapper.h" 0021 #include "common/tabletdatabase.h" 0022 #include "common/tabletinformation.h" 0023 0024 // #include <QtTest> 0025 #include <QDebug> 0026 #include <QString> 0027 0028 #include <algorithm> 0029 0030 using namespace Wacom; 0031 0032 class TestLibwacomData : public QObject 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 void testData(); 0038 }; 0039 0040 static bool compare(TabletInformation &left, TabletInformation &right, const TabletInfo &info) 0041 { 0042 if (info == TabletInfo::NumPadButtons) { 0043 if (left.getInt(info) != right.getInt(info)) { 0044 qWarning() << "MISMATCH: Property" << info.key() << "mismatch for device" << left.get(TabletInfo::TabletName) << "DB:" << left.getInt(info) 0045 << "vs LIB:" << right.getInt(info); 0046 return false; 0047 } 0048 0049 return true; 0050 } 0051 0052 if (left.get(info) != right.get(info)) { 0053 qWarning() << "MISMATCH: Property" << info.key() << "mismatch for device" << left.get(TabletInfo::TabletName) << "DB:" << left.get(info) 0054 << "vs LIB:" << right.get(info); 0055 return false; 0056 } 0057 0058 return true; 0059 } 0060 0061 void TestLibwacomData::testData() 0062 { 0063 using namespace Wacom; 0064 0065 int missingLocal = 0; 0066 int missingLibwacom = 0; 0067 int okay = 0; 0068 int mismatch = 0; 0069 0070 int max = 0x0FFF; 0071 0072 for (int deviceId = 0; deviceId < max; ++deviceId) { 0073 TabletInformation localInfo(deviceId); 0074 TabletInformation libwacomInfo(deviceId); 0075 0076 localInfo.set(TabletInfo::CompanyId, QString::fromLatin1("056A")); 0077 libwacomInfo.set(TabletInfo::CompanyId, QString::fromLatin1("056A")); 0078 0079 bool inLocal = false; 0080 bool inLibWacom = false; 0081 0082 if (TabletDatabase::instance().lookupTablet(localInfo.get(TabletInfo::TabletId), localInfo.get(TabletInfo::CompanyId), localInfo)) { 0083 inLocal = true; 0084 } 0085 0086 // lookup information in libWacom tablet database 0087 auto tabletId = localInfo.get(TabletInfo::TabletId).toInt(nullptr, 16); 0088 auto vendorId = localInfo.get(TabletInfo::CompanyId).toInt(nullptr, 16); 0089 if (libWacomWrapper::instance().lookupTabletInfo(tabletId, vendorId, libwacomInfo)) { 0090 inLibWacom = true; 0091 } 0092 0093 if (inLocal && inLibWacom) { 0094 // qDebug() << "Comparing" << deviceId << inLocal << inLibWacom; 0095 bool identical = true; 0096 identical &= compare(localInfo, libwacomInfo, TabletInfo::HasLeftTouchStrip); 0097 identical &= compare(localInfo, libwacomInfo, TabletInfo::HasRightTouchStrip); 0098 identical &= compare(localInfo, libwacomInfo, TabletInfo::HasTouchRing); 0099 identical &= compare(localInfo, libwacomInfo, TabletInfo::HasWheel); 0100 identical &= compare(localInfo, libwacomInfo, TabletInfo::NumPadButtons); 0101 identical &= compare(localInfo, libwacomInfo, TabletInfo::StatusLEDs); 0102 0103 // We don't really care about button order here, just compare the indices 0104 auto localMap = localInfo.getButtonMap().values(); 0105 auto libwacomMap = libwacomInfo.getButtonMap().values(); 0106 0107 std::sort(localMap.begin(), localMap.end()); 0108 std::sort(libwacomMap.begin(), libwacomMap.end()); 0109 0110 bool identicalmapping = localMap.size() == libwacomMap.size() && std::equal(localMap.begin(), localMap.end(), libwacomMap.begin()); 0111 0112 if (!identicalmapping) { 0113 qWarning() << "MISMATCH: Mapping for device" << localInfo.get(TabletInfo::TabletName) << "differs." 0114 << "Local:" << localInfo.getButtonMap() << "Libwacom:" << libwacomInfo.getButtonMap(); 0115 } 0116 0117 identical &= identicalmapping; 0118 0119 if (identical) { 0120 okay++; 0121 qDebug() << "Device" << localInfo.get(TabletInfo::TabletName) << "is identical"; 0122 } else { 0123 mismatch++; 0124 } 0125 } else if (inLocal) { 0126 qDebug() << "Device" << localInfo.get(TabletInfo::TabletName) << "is missing from LibWacom"; 0127 missingLibwacom++; 0128 } else if (inLibWacom) { 0129 missingLocal++; 0130 } 0131 } 0132 0133 qDebug() << "OK:" << okay << "MISMATCH:" << mismatch << "ONLYLOCAL" << missingLibwacom << "ONLYWACOM" << missingLocal; 0134 } 0135 0136 int main() 0137 { 0138 TestLibwacomData test; 0139 test.testData(); 0140 } 0141 0142 #include "testlibwacomdata.moc"