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 "../kdedtestutils.h"
0021 #include "common/tabletdatabase.h"
0022 #include "common/tabletinformation.h"
0023 
0024 #include <QList>
0025 #include <QMap>
0026 
0027 #include <QtTest>
0028 
0029 using namespace Wacom;
0030 
0031 /**
0032  * @file testtabletdatabase.cpp
0033  *
0034  * @test UnitTest for ...
0035  */
0036 class TestTabletDatabase : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 private slots:
0041     void initTestCase();
0042 
0043     void testLookupBackend();
0044     void testLookupDevice();
0045 };
0046 
0047 QTEST_MAIN(TestTabletDatabase)
0048 
0049 void TestTabletDatabase::initTestCase()
0050 {
0051     QString companyFile = QLatin1String("testtabletdatabase.companylist");
0052     QString dataDirectory = KdedTestUtils::getAbsoluteDir(companyFile);
0053 
0054     TabletDatabase::instance().setDatabase(dataDirectory, companyFile);
0055 }
0056 
0057 void TestTabletDatabase::testLookupBackend()
0058 {
0059     QCOMPARE(TabletDatabase::instance().lookupBackend(QLatin1String("056A")), QLatin1String("wacom-tools"));
0060     QCOMPARE(TabletDatabase::instance().lookupBackend(QLatin1String("08ca")), QLatin1String("aiptek"));
0061 }
0062 
0063 void TestTabletDatabase::testLookupDevice()
0064 {
0065     TabletInformation info;
0066 
0067     QVERIFY(TabletDatabase::instance().lookupTablet(QLatin1String("00df"), info));
0068 
0069     QCOMPARE(info.get(TabletInfo::CompanyId), QLatin1String("056A"));
0070     QCOMPARE(info.get(TabletInfo::CompanyName), QLatin1String("Wacom Co., Ltd"));
0071 
0072     QCOMPARE(info.get(TabletInfo::TabletId), QLatin1String("00DF"));
0073     QCOMPARE(info.get(TabletInfo::TabletModel), QLatin1String("CTH-670/K"));
0074     QCOMPARE(info.get(TabletInfo::TabletName), QLatin1String("Bamboo Create"));
0075 
0076     QVERIFY(info.hasButtons());
0077 
0078     QMap<QString, QString> buttonMap = info.getButtonMap();
0079 
0080     QVERIFY(buttonMap.size() == 4);
0081 
0082     QList<QString> keys = buttonMap.keys();
0083     foreach (const QString &key, keys) {
0084         QVERIFY(!buttonMap.value(key).isEmpty());
0085     }
0086 }
0087 
0088 #include "testtabletdatabase.moc"