Debian Codegraph @

tests/auto/input/qaction/tst_qaction.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/private/qnode_p.h>
6 #include <Qt3DCore/private/qscene_p.h>
7
8 #include <Qt3DInput/QAction>
9 #include <Qt3DInput/QActionInput>
10 #include <Qt3DInput/private/qaction_p.h>
11 #include <Qt3DInput/private/qactioninput_p.h>
12 #include <testarbiter.h>
13
14 // We need to call QNode::clone which is protected
15 // We need to call QAction::sceneChangeEvent which is protected
16 // So we sublcass QNode instead of QObject
17 class tst_QAction: public Qt3DInput::QAction
18 {
19 Q_OBJECT
20 public:
21 tst_QAction()
22 {
23 }
24
25 private Q_SLOTS:
26
27
28
29 void checkPropertyUpdates()
30 {
31 // GIVEN
32 TestArbiter arbiter;
33 QScopedPointer<Qt3DInput::QAction> action(new Qt3DInput::QAction());
34 arbiter.setArbiterOnNode(action.data());
35
36 // WHEN
37 Qt3DInput::QActionInput *input = new Qt3DInput::QActionInput();
38 action->addInput(input);
39 QCoreApplication::processEvents();
40
41 // THEN
42 QCOMPARE(arbiter.dirtyNodes().size(), 1);
43 QCOMPARE(arbiter.dirtyNodes().front(), action.data());
44
45 arbiter.clear();
46
47 // WHEN
48 action->removeInput(input);
49 QCoreApplication::processEvents();
50
51 // THEN
52 QCOMPARE(arbiter.dirtyNodes().size(), 1);
53 QCOMPARE(arbiter.dirtyNodes().front(), action.data());
54 }
55
56 void checkActionInputBookkeeping()
57 {
58 // GIVEN
59 QScopedPointer<Qt3DInput::QAction> action(new Qt3DInput::QAction);
60 {
61 // WHEN
62 Qt3DInput::QActionInput input;
63 action->addInput(&input);
64
65 // THEN
66 QCOMPARE(input.parent(), action.data());
67 QCOMPARE(action->inputs().size(), 1);
68 }
69 // THEN (Should not crash and parameter be unset)
70 QVERIFY(action->inputs().empty());
71
72 {
73 // WHEN
74 Qt3DInput::QAction someOtherAction;
75 QScopedPointer<Qt3DInput::QActionInput> input(new Qt3DInput::QActionInput(&someOtherAction));
76 action->addInput(input.data());
77
78 // THEN
79 QCOMPARE(input->parent(), &someOtherAction);
80 QCOMPARE(action->inputs().size(), 1);
81
82 // WHEN
83 action.reset();
84 input.reset();
85
86 // THEN Should not crash when the input is destroyed (tests for failed removal of destruction helper)
87 }
88 }
89 };
90
91 QTEST_MAIN(tst_QAction)
92
93 #include "tst_qaction.moc"