Debian Codegraph @

tests/auto/animation/fcurve/tst_fcurve.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 <private/fcurve_p.h>
6
7 using namespace Qt3DAnimation;
8 using namespace Qt3DAnimation::Animation;
9
10 class tst_FCurve : public QObject
11 {
12 Q_OBJECT
13
14 private Q_SLOTS:
15 void checkDefaultConstruction()
16 {
17 // WHEN
18 FCurve fcurve;
19
20 // THEN
21 QCOMPARE(fcurve.keyframeCount(), 0);
22 QCOMPARE(fcurve.startTime(), 0.0f);
23 QCOMPARE(fcurve.endTime(), 0.0f);
24 }
25
26 void checkAddingKeyframes()
27 {
28 // GIVEN
29 FCurve fcurve;
30
31 // WHEN
32 const Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation};
33 fcurve.appendKeyframe(0.0f, kf0);
34
35 // THEN
36 QCOMPARE(fcurve.keyframeCount(), 1);
37 QCOMPARE(fcurve.startTime(), 0.0f);
38 QCOMPARE(fcurve.endTime(), 0.0f);
39
40 // WHEN
41 const Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation};
42 fcurve.appendKeyframe(50.0f, kf1);
43
44 // THEN
45 QCOMPARE(fcurve.keyframeCount(), 2);
46 QCOMPARE(fcurve.startTime(), 0.0f);
47 QCOMPARE(fcurve.endTime(), 50.0f);
48 QCOMPARE(fcurve.keyframe(0), kf0);
49 QCOMPARE(fcurve.keyframe(1), kf1);
50 }
51
52 void checkClearKeyframes()
53 {
54 // GIVEN
55 FCurve fcurve;
56 fcurve.appendKeyframe(0.0f, Keyframe{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation});
57 fcurve.appendKeyframe(50.0f, Keyframe{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation});
58
59 // WHEN
60 fcurve.clearKeyframes();
61
62 // THEN
63 QCOMPARE(fcurve.keyframeCount(), 0);
64 QCOMPARE(fcurve.startTime(), 0.0f);
65 QCOMPARE(fcurve.endTime(), 0.0f);
66 }
67
68 void checkEvaluateAtTime_data()
69 {
70
71 QTest::addColumn<float>("time");
72 QTest::addColumn<float>("expectedValue");
73
74 QTest::addRow("Constant_before_time") << 0.0f << 1.0f;
75 QTest::addRow("Constant_1.5") << 1.5f << 1.0f;
76 QTest::addRow("Constant_2.5") << 2.5f << 2.0f;
77 QTest::addRow("Constant_after_time") << 3.5f << 4.0f;
78 }
79
80 void checkEvaluateAtTime()
81 {
82 QFETCH(float, time);
83 QFETCH(float, expectedValue);
84
85 FCurve curve;
86 curve.appendKeyframe(1.0, Keyframe{1.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation});
87 curve.appendKeyframe(2.0, Keyframe{2.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation});
88 curve.appendKeyframe(3.0, Keyframe{4.0, {0.0, 0.0}, {0.0,0.0}, QKeyFrame::ConstantInterpolation});
89
90 float actualValue = curve.evaluateAtTime(time);
91
92 QCOMPARE(expectedValue, actualValue);
93 }
94 };
95
96 QTEST_APPLESS_MAIN(tst_FCurve)
97
98 #include "tst_fcurve.moc"