File indexing completed on 2024-06-09 04:20:53

0001 /*
0002  *  SPDX-FileCopyrightText: 2011 Hanna Skott <hannaetscott@gmail.com>
0003  *  SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #include "TestInputDevice.h"
0007 
0008 #include <simpletest.h>
0009 #include "KoInputDevice.h"
0010 
0011 //Tests so the KoInputDevice created is of tablet type
0012 void TestInputDevice::testTabletConstructor()
0013 {
0014   QTabletEvent::TabletDevice parameterTabletDevice = QTabletEvent::Stylus;
0015   QTabletEvent::PointerType parameterPointerType = QTabletEvent::Eraser; 
0016   qint64 parameterUniqueTabletId = 0;
0017   KoInputDevice toTest(parameterTabletDevice, parameterPointerType, parameterUniqueTabletId);
0018   bool isMouse = toTest.isMouse();
0019   QVERIFY(!isMouse);
0020 }
0021 //Tests so the unique tablet ID of the default constructor is -1 like set.
0022 void TestInputDevice::testNoParameterConstructor()
0023 {
0024   KoInputDevice toTest;
0025   bool isMouse = toTest.isMouse();
0026   qint64 theUniqueTabletId = toTest.uniqueTabletId();
0027   qint64 toCompareWith = -1;
0028   QVERIFY(isMouse);
0029   QCOMPARE(theUniqueTabletId, toCompareWith);
0030 }
0031 //Tests so the single reference constructor can take both a tablet and a mouse as input device and set it correctly
0032 void TestInputDevice::testConstructorWithSingleReference()
0033 {
0034   QTabletEvent::TabletDevice parameterTabletDevice = QTabletEvent::Stylus;
0035   QTabletEvent::PointerType parameterPointerType = QTabletEvent::Eraser; 
0036   qint64 parameterUniqueTabletId = 0;
0037   KoInputDevice parameterTabletDevice2(parameterTabletDevice, parameterPointerType, parameterUniqueTabletId);
0038   KoInputDevice toTest(parameterTabletDevice2);
0039   bool isMouse = toTest.isMouse();
0040   QVERIFY(!isMouse);
0041   KoInputDevice parameterMouseDevice;
0042   toTest = KoInputDevice(parameterMouseDevice);
0043   isMouse = toTest.isMouse();
0044   QVERIFY(isMouse);
0045 }
0046 //tests so the equality operator is working
0047 void TestInputDevice::testEqualityCheckOperator()
0048 {
0049   QTabletEvent::TabletDevice parameterTabletDevice = QTabletEvent::Stylus;
0050   QTabletEvent::PointerType parameterPointerType = QTabletEvent::Eraser; 
0051   qint64 parameterUniqueTabletId = 0;
0052   KoInputDevice parameterTabletDevice2(parameterTabletDevice, parameterPointerType, parameterUniqueTabletId);
0053   KoInputDevice toTest(parameterTabletDevice2);
0054   KoInputDevice copy = toTest;
0055   KoInputDevice notSame;
0056   QVERIFY(toTest==copy);
0057   QVERIFY(toTest!=notSame);
0058 }
0059 //tests that the device is set properly in the constructor 
0060 void TestInputDevice::testDevice()
0061 {
0062   QTabletEvent::TabletDevice parameterTabletDevice = QTabletEvent::Stylus;
0063   QTabletEvent::PointerType parameterPointerType = QTabletEvent::Eraser; 
0064   qint64 parameterUniqueTabletId = 0;
0065   KoInputDevice parameterTabletDevice2(parameterTabletDevice, parameterPointerType, parameterUniqueTabletId);
0066   KoInputDevice toTest(parameterTabletDevice2);
0067   QTabletEvent::TabletDevice aTabletDevice = toTest.device();
0068 
0069   QCOMPARE(aTabletDevice, QTabletEvent::Stylus); 
0070 }
0071 //tests that the PointerType is set correctly by the constructor
0072 void TestInputDevice::testPointer()
0073 {
0074   QTabletEvent::TabletDevice parameterTabletDevice = QTabletEvent::Stylus;
0075   QTabletEvent::PointerType parameterPointerType = QTabletEvent::Eraser; 
0076   qint64 parameterUniqueTabletId = 0;
0077   KoInputDevice parameterTabletDevice2(parameterTabletDevice, parameterPointerType, parameterUniqueTabletId);
0078   KoInputDevice toTest(parameterTabletDevice2);
0079   QTabletEvent::PointerType aTabletDevice = toTest.pointer();
0080   
0081   QCOMPARE(aTabletDevice, QTabletEvent::Eraser);
0082 }
0083 //verifies that the device returned by the mouse() function is indeed a mouse device
0084 void TestInputDevice::testMouse()
0085 {
0086   KoInputDevice toTest = KoInputDevice::mouse();
0087   bool isMouse = toTest.isMouse();
0088   QVERIFY(isMouse);
0089 }
0090 //verifies that the device returned by the stylus() function is indeed a tablet device
0091 void TestInputDevice::testStylus()
0092 {
0093   KoInputDevice toTest = KoInputDevice::stylus();
0094   bool isMouse = toTest.isMouse();
0095   QVERIFY(!isMouse);
0096 }
0097 //verifies that the device returned by the eraser() function is indeed a tablet device
0098 void TestInputDevice::testEraser()
0099 {
0100   KoInputDevice toTest = KoInputDevice::eraser();
0101   bool isMouse = toTest.isMouse();
0102   QVERIFY(!isMouse);
0103 }
0104 
0105 
0106 SIMPLE_TEST_MAIN(TestInputDevice)