Changeset View
Changeset View
Standalone View
Standalone View
autotests/common/libwacomdata/testlibwacomdata.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of the KDE wacomtablet project. For copyright | ||||
3 | * information and license terms see the AUTHORS and COPYING files | ||||
4 | * in the top-level directory of this distribution. | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or | ||||
7 | * modify it under the terms of the GNU General Public License as | ||||
8 | * published by the Free Software Foundation; either version 2 of | ||||
9 | * the License, or (at your option) any later version. | ||||
10 | * | ||||
11 | * This program is distributed in the hope that it will be useful, | ||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | * GNU General Public License for more details. | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU General Public License | ||||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "common/libwacomwrapper.h" | ||||
21 | #include "common/tabletdatabase.h" | ||||
22 | #include "common/tabletinformation.h" | ||||
23 | | ||||
24 | //#include <QtTest> | ||||
25 | #include <QString> | ||||
26 | #include <QDebug> | ||||
27 | | ||||
28 | #include <algorithm> | ||||
29 | | ||||
30 | using namespace Wacom; | ||||
31 | | ||||
32 | class TestLibwacomData: public QObject | ||||
33 | { | ||||
34 | Q_OBJECT | ||||
35 | | ||||
36 | public: | ||||
37 | void testData(); | ||||
38 | }; | ||||
39 | | ||||
40 | static bool compare(TabletInformation &left, TabletInformation &right, const TabletInfo &info) { | ||||
41 | | ||||
42 | if (info == TabletInfo::NumPadButtons) { | ||||
43 | if (left.getInt(info) != right.getInt(info)) { | ||||
44 | qWarning() << "MISMATCH: Property" << info.key() << "mismatch for device" << left.get(TabletInfo::TabletName) | ||||
45 | << "DB:" << left.getInt(info) << "vs LIB:" << right.getInt(info); | ||||
46 | return false; | ||||
47 | } | ||||
48 | | ||||
49 | return true; | ||||
50 | } | ||||
51 | | ||||
52 | if (left.get(info) != right.get(info)) { | ||||
53 | qWarning() << "MISMATCH: Property" << info.key() << "mismatch for device" << left.get(TabletInfo::TabletName) | ||||
54 | << "DB:" << left.get(info) << "vs LIB:" << right.get(info); | ||||
55 | return false; | ||||
56 | } | ||||
57 | | ||||
58 | return true; | ||||
59 | } | ||||
60 | | ||||
61 | void TestLibwacomData::testData() | ||||
62 | { | ||||
63 | using namespace Wacom; | ||||
64 | | ||||
65 | int missingLocal = 0; | ||||
66 | int missingLibwacom = 0; | ||||
67 | int okay = 0; | ||||
68 | int mismatch = 0; | ||||
69 | | ||||
70 | int max = 0x0FFF; | ||||
71 | | ||||
72 | for (int deviceId = 0; deviceId < max; ++deviceId) { | ||||
73 | TabletInformation localInfo(deviceId); | ||||
74 | TabletInformation libwacomInfo(deviceId); | ||||
75 | | ||||
76 | localInfo.set(TabletInfo::CompanyId, QString::fromLatin1("056A")); | ||||
77 | libwacomInfo.set(TabletInfo::CompanyId, QString::fromLatin1("056A")); | ||||
78 | | ||||
79 | bool inLocal = false; | ||||
80 | bool inLibWacom = false; | ||||
81 | | ||||
82 | if (TabletDatabase::instance().lookupTablet(localInfo.get (TabletInfo::TabletId), localInfo)) { | ||||
83 | inLocal = true; | ||||
84 | } | ||||
85 | | ||||
86 | // lookup information in libWacom tablet database | ||||
87 | auto tabletId = localInfo.get(TabletInfo::TabletId).toInt(nullptr, 16); | ||||
88 | auto vendorId = localInfo.get(TabletInfo::CompanyId).toInt(nullptr, 16); | ||||
89 | if (libWacomWrapper::instance().lookupTabletInfo(tabletId, vendorId, libwacomInfo)) { | ||||
90 | inLibWacom = true; | ||||
91 | } | ||||
92 | | ||||
93 | if (inLocal && inLibWacom) { | ||||
94 | //qDebug() << "Comparing" << deviceId << inLocal << inLibWacom; | ||||
95 | bool identical = true; | ||||
96 | identical &= compare(localInfo, libwacomInfo, TabletInfo::HasLeftTouchStrip); | ||||
97 | identical &= compare(localInfo, libwacomInfo, TabletInfo::HasRightTouchStrip); | ||||
98 | identical &= compare(localInfo, libwacomInfo, TabletInfo::HasTouchRing); | ||||
99 | identical &= compare(localInfo, libwacomInfo, TabletInfo::HasWheel); | ||||
100 | identical &= compare(localInfo, libwacomInfo, TabletInfo::NumPadButtons); | ||||
101 | identical &= compare(localInfo, libwacomInfo, TabletInfo::StatusLEDs); | ||||
102 | | ||||
103 | // We don't really care about button order here, just compare the indices | ||||
104 | auto localMap = localInfo.getButtonMap().values(); | ||||
105 | auto libwacomMap = libwacomInfo.getButtonMap().values(); | ||||
106 | | ||||
107 | std::sort(localMap.begin(), localMap.end()); | ||||
108 | std::sort(libwacomMap.begin(), libwacomMap.end()); | ||||
109 | | ||||
110 | bool identicalmapping = localMap.size() == libwacomMap.size() | ||||
111 | && std::equal(localMap.begin(), localMap.end(), libwacomMap.begin()); | ||||
112 | | ||||
113 | if (!identicalmapping) { | ||||
114 | qWarning() << "MISMATCH: Mapping for device" << localInfo.get(TabletInfo::TabletName) << "differs." | ||||
115 | << "Local:" << localInfo.getButtonMap() << "Libwacom:" << libwacomInfo.getButtonMap(); | ||||
116 | } | ||||
117 | | ||||
118 | identical &= identicalmapping; | ||||
119 | | ||||
120 | if (identical) { | ||||
121 | okay++; | ||||
122 | qDebug() << "Device" << localInfo.get(TabletInfo::TabletName) << "is identical"; | ||||
123 | } else { | ||||
124 | mismatch++; | ||||
125 | } | ||||
126 | } else if(inLocal) { | ||||
127 | qDebug() << "Device" << localInfo.get(TabletInfo::TabletName) << "is missing from LibWacom"; | ||||
128 | missingLibwacom++; | ||||
129 | } else if(inLibWacom) { | ||||
130 | missingLocal++; | ||||
131 | } | ||||
132 | } | ||||
133 | | ||||
134 | qDebug() << "OK:" << okay << "MISMATCH:" << mismatch << "ONLYLOCAL" << missingLibwacom << "ONLYWACOM" << missingLocal; | ||||
135 | } | ||||
136 | | ||||
137 | int main() { | ||||
138 | TestLibwacomData test; | ||||
139 | test.testData(); | ||||
140 | } | ||||
141 | | ||||
142 | #include "testlibwacomdata.moc" |