Debian Codegraph @

tests/auto/core/qskeleton/tst_qskeleton.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/qskeleton.h>
6 #include <Qt3DCore/private/qskeleton_p.h>
7 #include <Qt3DCore/qjoint.h>
8
9 #include <Qt3DCore/private/qnode_p.h>
10 #include <Qt3DCore/private/qscene_p.h>
11
12 #include <QSignalSpy>
13 #include <testarbiter.h>
14
15 using namespace Qt3DCore;
16
17 class tst_QSkeleton: public QSkeleton
18 {
19 Q_OBJECT
20 public:
21 tst_QSkeleton()
22 {
23 qRegisterMetaType<Qt3DCore::QJoint*>();
24 }
25
26 private Q_SLOTS:
27 void checkDefaultConstruction()
28 {
29 // GIVEN
30 QSkeleton skeleton;
31
32 // THEN
33 QCOMPARE(skeleton.jointCount(), 0);
34 }
35
36 void checkPropertyUpdates()
37 {
38 // GIVEN
39 TestArbiter arbiter;
40 QScopedPointer<QSkeleton> skeleton(new QSkeleton());
41 arbiter.setArbiterOnNode(skeleton.data());
42
43 // WHEN
44 QJoint *joint = new QJoint(skeleton.data());
45 arbiter.clear();
46
47 skeleton->setRootJoint(joint);
48
49 // THEN
50 QCOMPARE(arbiter.dirtyNodes().size(), 1);
51 QCOMPARE(arbiter.dirtyNodes().front(), skeleton.data());
52
53 arbiter.clear();
54
55 // WHEN
56 skeleton->setRootJoint(nullptr);
57
58 // THEN
59 QCOMPARE(arbiter.dirtyNodes().size(), 1);
60 QCOMPARE(arbiter.dirtyNodes().front(), skeleton.data());
61
62 arbiter.clear();
63 }
64
65 void checkRootJointBookkeeping()
66 {
67 // GIVEN
68 QScopedPointer<QSkeleton> skeleton(new QSkeleton);
69 {
70 // WHEN
71 QJoint joint;
72 skeleton->setRootJoint(&joint);
73
74 // THEN
75 QCOMPARE(joint.parent(), skeleton.data());
76 QCOMPARE(skeleton->rootJoint(), &joint);
77 }
78 // THEN (Should not crash and parameter be unset)
79 QVERIFY(skeleton->rootJoint() == nullptr);
80
81 {
82 // WHEN
83 QSkeleton someOtherSkeleton;
84 QScopedPointer<QJoint> joint(new QJoint(&someOtherSkeleton));
85 skeleton->setRootJoint(joint.data());
86
87 // THEN
88 QCOMPARE(joint->parent(), &someOtherSkeleton);
89 QCOMPARE(skeleton->rootJoint(), joint.data());
90
91 // WHEN
92 skeleton.reset();
93 joint.reset();
94
95 // THEN Should not crash when the joint is destroyed (tests for failed removal of destruction helper)
96 }
97 }
98 };
99
100 QTEST_MAIN(tst_QSkeleton)
101
102 #include "tst_qskeleton.moc"