Debian Codegraph @

tests/auto/input/qactioninput/tst_qactioninput.cpp

raw symbols SCIP
1 // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DCore/qnodeid.h>
6 #include <Qt3DCore/private/qnode_p.h>
7 #include <Qt3DCore/private/qscene_p.h>
8
9 #include <Qt3DInput/private/qactioninput_p.h>
10 #include <Qt3DInput/QActionInput>
11 #include <Qt3DInput/QAbstractPhysicalDevice>
12
13 #include "testdevice.h"
14 #include <testarbiter.h>
15
16 class tst_QActionInput: public QObject
17 {
18 Q_OBJECT
19 public:
20 tst_QActionInput()
21 {
22 qRegisterMetaType<Qt3DInput::QAbstractPhysicalDevice*>("Qt3DInput::QAbstractPhysicalDevice*");
23 }
24
25 private Q_SLOTS:
26
27 void checkPropertyUpdates()
28 {
29 // GIVEN
30 TestArbiter arbiter;
31 QScopedPointer<Qt3DInput::QActionInput> actionInput(new Qt3DInput::QActionInput());
32 arbiter.setArbiterOnNode(actionInput.data());
33
34 // WHEN
35 const QList<int> buttons = { 555 };
36 actionInput->setButtons(buttons);
37
38 // THEN
39 QCOMPARE(arbiter.dirtyNodes().size(), 1);
40 QCOMPARE(arbiter.dirtyNodes().front(), actionInput.data());
41
42 arbiter.clear();
43
44 // WHEN
45 TestDevice *device = new TestDevice(actionInput.data());
46 QCoreApplication::processEvents();
47
48 actionInput->setSourceDevice(device);
49
50 // THEN
51 QCOMPARE(arbiter.dirtyNodes().size(), 1);
52 QCOMPARE(arbiter.dirtyNodes().front(), actionInput.data());
53
54 arbiter.clear();
55 }
56
57 void checkSourceDeviceBookkeeping()
58 {
59 // GIVEN
60 QScopedPointer<Qt3DInput::QActionInput> actionInput(new Qt3DInput::QActionInput);
61 {
62 // WHEN
63 Qt3DInput::QAbstractPhysicalDevice device;
64 actionInput->setSourceDevice(&device);
65
66 // THEN
67 QCOMPARE(device.parent(), actionInput.data());
68 QCOMPARE(actionInput->sourceDevice(), &device);
69 }
70 // THEN (Should not crash and effect be unset)
71 QVERIFY(actionInput->sourceDevice() == nullptr);
72
73 {
74 // WHEN
75 Qt3DInput::QActionInput someOtherActionInput;
76 QScopedPointer<Qt3DInput::QAbstractPhysicalDevice> device(new Qt3DInput::QAbstractPhysicalDevice(&someOtherActionInput));
77 actionInput->setSourceDevice(device.data());
78
79 // THEN
80 QCOMPARE(device->parent(), &someOtherActionInput);
81 QCOMPARE(actionInput->sourceDevice(), device.data());
82
83 // WHEN
84 actionInput.reset();
85 device.reset();
86
87 // THEN Should not crash when the device is destroyed (tests for failed removal of destruction helper)
88 }
89 }
90 };
91
92 QTEST_MAIN(tst_QActionInput)
93
94 #include "tst_qactioninput.moc"