Debian Codegraph @

tests/auto/input/qmousedevice/tst_qmousedevice.cpp

raw symbols SCIP
1 // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5 #include <QtTest/QTest>
6 #include <Qt3DInput/qmousedevice.h>
7 #include <Qt3DInput/qmouseevent.h>
8 #include <Qt3DInput/private/qmousedevice_p.h>
9 #include <QObject>
10 #include <QSignalSpy>
11 #include "testarbiter.h"
12
13 class tst_QMouseDevice : public QObject
14 {
15 Q_OBJECT
16
17 private Q_SLOTS:
18
19 void checkDefaultConstruction()
20 {
21 // GIVEN
22 Qt3DInput::QMouseDevice mouseDevice;
23
24 // THEN
25 QCOMPARE(mouseDevice.sensitivity(), 0.1f);
26 QCOMPARE(mouseDevice.updateAxesContinuously(), false);
27 QCOMPARE(mouseDevice.axisCount(), 4);
28 QCOMPARE(mouseDevice.buttonCount(), 3);
29 QCOMPARE(mouseDevice.axisNames(), QStringList()
30 << QStringLiteral("X")
31 << QStringLiteral("Y")
32 << QStringLiteral("WheelX")
33 << QStringLiteral("WheelY"));
34 QCOMPARE(mouseDevice.buttonNames(), QStringList()
35 << QStringLiteral("Left")
36 << QStringLiteral("Right")
37 << QStringLiteral("Center"));
38
39 QVERIFY(mouseDevice.axisIdentifier(QStringLiteral("X")) == Qt3DInput::QMouseDevice::X);
40 QVERIFY(mouseDevice.axisIdentifier(QStringLiteral("Y")) == Qt3DInput::QMouseDevice::Y);
41 QVERIFY(mouseDevice.axisIdentifier(QStringLiteral("WheelX")) == Qt3DInput::QMouseDevice::WheelX);
42 QVERIFY(mouseDevice.axisIdentifier(QStringLiteral("WheelY")) == Qt3DInput::QMouseDevice::WheelY);
43
44 QVERIFY(mouseDevice.buttonIdentifier(QStringLiteral("Left")) == Qt3DInput::QMouseEvent::LeftButton);
45 QVERIFY(mouseDevice.buttonIdentifier(QStringLiteral("Right")) == Qt3DInput::QMouseEvent::RightButton);
46 QVERIFY(mouseDevice.buttonIdentifier(QStringLiteral("Center")) == Qt3DInput::QMouseEvent::MiddleButton);
47 }
48
49 void checkPropertyChanges()
50 {
51 // GIVEN
52 Qt3DInput::QMouseDevice mouseDevice;
53
54 {
55 // WHEN
56 QSignalSpy spy(&mouseDevice, SIGNAL(sensitivityChanged(float)));
57 const float newValue = 0.5f;
58 mouseDevice.setSensitivity(newValue);
59
60 // THEN
61 QVERIFY(spy.isValid());
62 QCOMPARE(mouseDevice.sensitivity(), newValue);
63 QCOMPARE(spy.size(), 1);
64
65 // WHEN
66 spy.clear();
67 mouseDevice.setSensitivity(newValue);
68
69 // THEN
70 QCOMPARE(mouseDevice.sensitivity(), newValue);
71 QCOMPARE(spy.size(), 0);
72 }
73 {
74 // WHEN
75 QSignalSpy spy(&mouseDevice, SIGNAL(updateAxesContinuouslyChanged(bool)));
76 const bool newValue = true;
77 mouseDevice.setUpdateAxesContinuously(newValue);
78
79 // THEN
80 QVERIFY(spy.isValid());
81 QCOMPARE(mouseDevice.updateAxesContinuously(), newValue);
82 QCOMPARE(spy.size(), 1);
83
84 // WHEN
85 spy.clear();
86 mouseDevice.setUpdateAxesContinuously(newValue);
87
88 // THEN
89 QCOMPARE(mouseDevice.updateAxesContinuously(), newValue);
90 QCOMPARE(spy.size(), 0);
91 }
92 }
93
94 void checkSensitivityUpdate()
95 {
96 // GIVEN
97 TestArbiter arbiter;
98 Qt3DInput::QMouseDevice mouseDevice;
99 arbiter.setArbiterOnNode(&mouseDevice);
100
101 {
102 // WHEN
103 mouseDevice.setSensitivity(0.7f);
104 // THEN
105 QCOMPARE(arbiter.dirtyNodes().size(), 1);
106 QCOMPARE(arbiter.dirtyNodes().front(), &mouseDevice);
107 }
108
109 {
110 // WHEN
111 mouseDevice.setSensitivity(0.7f);
112
113 QCOMPARE(arbiter.dirtyNodes().size(), 1);
114 QCOMPARE(arbiter.dirtyNodes().front(), &mouseDevice);
115 }
116
117 }
118
119 void checkUpdateAxesContinuouslyUpdate()
120 {
121 // GIVEN
122 TestArbiter arbiter;
123 Qt3DInput::QMouseDevice mouseDevice;
124 arbiter.setArbiterOnNode(&mouseDevice);
125
126 {
127 // WHEN
128 mouseDevice.setUpdateAxesContinuously(true);
129 // THEN
130 QCOMPARE(arbiter.dirtyNodes().size(), 1);
131 QCOMPARE(arbiter.dirtyNodes().front(), &mouseDevice);
132 }
133
134 {
135 // WHEN
136 mouseDevice.setSensitivity(true);
137
138 QCOMPARE(arbiter.dirtyNodes().size(), 1);
139 QCOMPARE(arbiter.dirtyNodes().front(), &mouseDevice);
140 }
141
142 }
143
144 };
145
146 QTEST_MAIN(tst_QMouseDevice)
147
148 #include "tst_qmousedevice.moc"