-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathtest_animation.cpp
More file actions
1094 lines (1019 loc) · 36.6 KB
/
Copy pathtest_animation.cpp
File metadata and controls
1094 lines (1019 loc) · 36.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2015-2026 Meltytech, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with consumer library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <QString>
#include <QtTest>
#include <mlt++/Mlt.h>
using namespace Mlt;
class TestAnimation : public QObject
{
Q_OBJECT
private Q_SLOTS:
void DefaultConstructorIsInvalid()
{
Animation a;
QVERIFY(!a.is_valid());
}
void ConstructFromProperties()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation *a = p.get_anim("foo");
QVERIFY(a);
QVERIFY(a->is_valid());
delete a;
a = p.get_anim("bar");
QVERIFY(a);
QVERIFY(!a->is_valid());
}
void ConstructFromCType()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a1(p.get_animation("foo"));
QVERIFY(a1.is_valid());
Animation a2(a1.get_animation());
QVERIFY(a2.is_valid());
QVERIFY(a1.get_animation() == a2.get_animation());
}
void CopyConstructor()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a1(p.get_animation("foo"));
QVERIFY(a1.is_valid());
Animation a2(a1);
QVERIFY(a2.is_valid());
QVERIFY(a1.get_animation() == a2.get_animation());
}
void Assignment()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a1 = p.get_animation("foo");
QVERIFY(a1.is_valid());
Animation a2;
a2 = a1;
QVERIFY(a2.is_valid());
QVERIFY(a1.get_animation() == a2.get_animation());
}
void LengthIsCorrect()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.length(), 10);
}
void IsAKeyFrame()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QVERIFY(!a.is_key(5));
QVERIFY(a.is_key(10));
}
void KeyFrameTypeIsDiscrete()
{
Properties p;
p.anim_set("foo", "bar", 10);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.keyframe_type(0), mlt_keyframe_discrete);
QCOMPARE(a.keyframe_type(10), mlt_keyframe_discrete);
QCOMPARE(a.keyframe_type(11), mlt_keyframe_discrete);
}
void KeyFrameTypeIsLinear()
{
Properties p;
p.anim_set("foo", 1, 10);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.keyframe_type(0), mlt_keyframe_linear);
QCOMPARE(a.keyframe_type(10), mlt_keyframe_linear);
QCOMPARE(a.keyframe_type(11), mlt_keyframe_linear);
}
void KeyFrameTypeIsSmooth()
{
Properties p;
int pos = 10;
p.anim_set("foo", 1, pos, pos, mlt_keyframe_smooth);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.keyframe_type(0), mlt_keyframe_smooth);
QCOMPARE(a.keyframe_type(10), mlt_keyframe_smooth);
QCOMPARE(a.keyframe_type(11), mlt_keyframe_smooth);
}
void GetItem()
{
Properties p;
int pos = 10;
p.anim_set("foo", 1, pos, pos, mlt_keyframe_smooth);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
bool is_key = true;
mlt_keyframe_type type = mlt_keyframe_linear;
int error = a.get_item(10, is_key, type);
QVERIFY(!error);
QVERIFY(is_key);
QCOMPARE(type, mlt_keyframe_smooth);
error = a.get_item(1, is_key, type);
QVERIFY(!error);
QVERIFY(!is_key);
QCOMPARE(type, mlt_keyframe_smooth);
}
void AnimationFromStringProperty()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
Animation a = p.get_animation("foo");
QVERIFY(!a.is_valid());
// Cause the string to be interpreted as animated value.
p.anim_get("foo", 0);
a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.length(), 100);
}
void SetLength()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.length(), 100);
a.set_length(200);
QCOMPARE(a.length(), 200);
a.set_length(60);
QCOMPARE(a.length(), 60);
QCOMPARE(a.serialize_cut(), "50=100;60=60");
}
void RemoveMiddleKeyframe()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int error = a.remove(60);
QVERIFY(!error);
QCOMPARE(a.serialize_cut(), "50=100;100=0");
QCOMPARE(a.length(), 100);
QCOMPARE(p.anim_get_int("foo", 50), 100);
QCOMPARE(p.anim_get_int("foo", 75), 50);
QCOMPARE(p.anim_get_int("foo", 100), 0);
}
void RemoveFirstKeyframe()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int error = a.remove(0);
QVERIFY(error);
error = a.remove(50);
QVERIFY(!error);
QCOMPARE(a.serialize_cut(), "60=60;100=0");
QCOMPARE(a.length(), 100);
QCOMPARE(p.anim_get_int("foo", 50), 60);
QCOMPARE(p.anim_get_int("foo", 80), 30);
QCOMPARE(p.anim_get_int("foo", 100), 0);
}
void RemoveLastKeyframe()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int error = a.remove(101);
QVERIFY(error);
error = a.remove(100);
QVERIFY(!error);
QCOMPARE(a.serialize_cut(), "50=100;60=60");
QCOMPARE(a.length(), 60);
QCOMPARE(p.anim_get_int("foo", 50), 100);
QCOMPARE(p.anim_get_int("foo", 55), 80);
QCOMPARE(p.anim_get_int("foo", 60), 60);
}
void EmptyAnimationIsInvalid()
{
Properties p;
p.set("foo", "");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(!a.is_valid());
}
void NonEmptyAnimationKeyCount()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.key_count(), 3);
}
void RemoveKeyframeCount()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
a.remove(50);
QCOMPARE(a.key_count(), 2);
}
void GetKeyFrame()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int frame = -1;
mlt_keyframe_type type = mlt_keyframe_smooth;
int error = a.key_get(0, frame, type);
QVERIFY(!error);
QCOMPARE(frame, 50);
QCOMPARE(type, mlt_keyframe_linear);
QCOMPARE(a.key_count(), 3);
QCOMPARE(a.key_get_frame(0), 50);
QCOMPARE(a.key_get_frame(1), 60);
QCOMPARE(a.key_get_frame(2), 100);
QCOMPARE(a.key_get_frame(3), -1);
QCOMPARE(a.keyframe_type(0), mlt_keyframe_linear);
QCOMPARE(a.keyframe_type(1), mlt_keyframe_linear);
QCOMPARE(a.keyframe_type(2), mlt_keyframe_linear);
}
void SerializesInTimeFormat()
{
Profile profile;
Properties p;
p.set("_profile", profile.get_profile(), 0);
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.serialize_cut(mlt_time_clock), "00:00:02.000=100;00:00:02.400=60;00:00:04.000=0");
QCOMPARE(a.serialize_cut(mlt_time_smpte_ndf),
"00:00:02:00=100;00:00:02:10=60;00:00:04:00=0");
}
void GetPropertyInTimeFormat()
{
Profile profile;
Properties p;
p.set("_profile", profile.get_profile(), 0);
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
for (int i = 0; i < p.count(); i++) {
if (!qstrcmp(p.get_name(i), "foo")) {
QCOMPARE(p.get(i, mlt_time_clock),
"00:00:02.000=100;00:00:02.400=60;00:00:04.000=0");
QCOMPARE(p.get(i, mlt_time_smpte_ndf),
"00:00:02:00=100;00:00:02:10=60;00:00:04:00=0");
break;
}
}
}
void AnimationClears()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
p.clear("foo");
QCOMPARE(p.get_animation("foo"), mlt_animation(0));
}
void CanBeEscapedWithQuotes()
{
Properties p;
p.set("foo", "\"50=100; 60=60; 100=0\"");
// Quotes are retained when using the non-anim getter.
QCOMPARE(p.get("foo"), "\"50=100; 60=60; 100=0\"");
// Quotes are removed when using the anim getter.
QCOMPARE(p.anim_get("foo", 0), "50=100; 60=60; 100=0");
// Anim strings may contain delimiters and equal signs if quoted.
p.set("foo", "50=100; 60=\"60; 100=0\";0=\"hello=world\"");
QVERIFY(p.is_anim("foo"));
QCOMPARE(p.anim_get("foo", 0), "hello=world");
QCOMPARE(p.anim_get("foo", 50), "100");
QCOMPARE(p.anim_get("foo", 60), "60; 100=0");
}
void UrlWithEqualSignIsNotAnimation()
{
Properties p;
// A URL containing '=' in query parameters must not be treated as animation.
const char *url = "https://example.com/video?token=abc123&quality=high";
p.set("foo", url);
QVERIFY(!p.is_anim("foo"));
QCOMPARE(p.get("foo"), url);
QCOMPARE(p.anim_get("foo", 0), url);
// Verify the property is not animated.
p.anim_get("foo", 0);
QVERIFY(!p.get_animation("foo"));
}
void ParseUntilJunk()
{
Properties p;
// "foo=bar" is junk and parsing will stop after it
const char *str = "50=100;foo=bar;60=120";
p.set("foo", str);
QVERIFY(p.is_anim("foo"));
QCOMPARE(p.get("foo"), str);
QCOMPARE(p.anim_get("foo", 50), "100");
QCOMPARE(p.anim_get("foo", 60), "100"); // NOT 120
// Verify the property is animated and only has one key.
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
QCOMPARE(a.key_count(), 1);
}
void ShiftFramesPositive()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
a.shift_frames(60);
QCOMPARE(a.key_get_frame(0), 110);
QCOMPARE(a.key_get_frame(1), 120);
QCOMPARE(a.key_get_frame(2), 160);
QCOMPARE(a.key_get_frame(3), -1);
}
void ShiftFramesNegative()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
a.shift_frames(-60);
QCOMPARE(a.key_get_frame(0), -10);
QCOMPARE(a.key_get_frame(1), 0);
QCOMPARE(a.key_get_frame(2), 40);
QCOMPARE(a.key_get_frame(3), -1);
}
void NextKey()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int key;
bool ret;
ret = a.next_key(0, key);
QCOMPARE(ret, false);
QCOMPARE(key, 50);
ret = a.next_key(59, key);
QCOMPARE(ret, false);
QCOMPARE(key, 60);
ret = a.next_key(60, key);
QCOMPARE(ret, false);
QCOMPARE(key, 60);
ret = a.next_key(61, key);
QCOMPARE(ret, false);
QCOMPARE(key, 100);
ret = a.next_key(100, key);
QCOMPARE(ret, false);
QCOMPARE(key, 100);
key = 7; // random value
ret = a.next_key(101, key);
QCOMPARE(ret, true); // error - No next key
QCOMPARE(key, 7); // Not modified on error
}
void PreviousKey()
{
Properties p;
p.set("foo", "50=100; 60=60; 100=0");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
int key;
bool ret;
key = 7; // random value
ret = a.previous_key(0, key);
QCOMPARE(ret, true); // error - no previous key
QCOMPARE(key, 7); // Not modified on error
ret = a.previous_key(59, key);
QCOMPARE(ret, false);
QCOMPARE(key, 50);
ret = a.previous_key(60, key);
QCOMPARE(ret, false);
QCOMPARE(key, 60);
ret = a.previous_key(61, key);
QCOMPARE(ret, false);
QCOMPARE(key, 60);
ret = a.previous_key(100, key);
QCOMPARE(ret, false);
QCOMPARE(key, 100);
ret = a.previous_key(101, key);
QCOMPARE(ret, false);
QCOMPARE(key, 100);
}
void LinearInterpolationOneKey()
{
Properties p;
p.set("foo", "50=10");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 10
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 10);
}
}
void SmoothInterpolationOneKey()
{
Properties p;
p.set("foo", "50~=10");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 10
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 10);
}
}
void LinearInterpolationTwoKey()
{
Properties p;
double prev;
p.set("foo", "10=50; 20=100");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 50
for (int i = 0; i <= 10; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
// Values from 10 to 20 should step by 5
prev = 50 - 5;
for (int i = 10; i <= 20; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, prev + 5);
prev = current;
}
// Values after 20 should all be 100
for (int i = 20; i <= 30; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 100);
}
}
void SmoothInterpolationTwoKey()
{
Properties p;
double prev;
p.set("foo", "10~=50; 20~=100");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 50
for (int i = 0; i <= 10; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
// Values from 10 to 20 should increase but not exceed 100
prev = 49;
for (int i = 10; i <= 20; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current <= 100);
prev = current;
}
// Values after 20 should all be 100
for (int i = 20; i <= 30; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 100);
}
}
void LinearInterpolationThreeKey()
{
Properties p;
double prev;
p.set("foo", "10=50; 20=100; 30=50");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 50
for (int i = 0; i <= 10; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
// Values from 10 to 20 should step up by 5
prev = 50 - 5;
for (int i = 10; i <= 20; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, prev + 5);
prev = current;
}
// Values from 20 to 30 should step down by 5
prev = 100 + 5;
for (int i = 20; i <= 30; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, prev - 5);
prev = current;
}
// Values after 30 should all be 50
for (int i = 30; i <= 40; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
}
void SmoothInterpolationThreeKey()
{
Properties p;
double prev;
p.set("foo", "10~=50; 20~=100; 30~=50");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 10 should all be 50
for (int i = 0; i <= 10; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
// Values from 10 to 20 should increase but not exceed 100
prev = 49;
for (int i = 10; i <= 20; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current <= 100);
prev = current;
}
// Test two arbitrary intermediate points
QCOMPARE(p.anim_get_double("foo", 13), 64.475);
QCOMPARE(p.anim_get_double("foo", 18), 95.6);
// Values from 20 to 30 should decrease but not exceed 50
prev = 101;
for (int i = 20; i <= 30; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current < prev);
QVERIFY(current >= 50);
prev = current;
}
// Test two arbitrary intermediate points
QCOMPARE(p.anim_get_double("foo", 23), 90.775);
QCOMPARE(p.anim_get_double("foo", 28), 58.4);
// Values after 30 should all be 50
for (int i = 30; i <= 40; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 50);
}
}
void LinearDoesNotReverse()
{
Properties p;
double prev;
// This sequence of keyframes has abrupt changes. For some interpolation algorithms, this
// can result in values changing direction along the interpolation path (cusp or
// overshoot).
// The purpose of this test is to ensure that values do not reverse direction (exept as
// expected at keyframes if the user specified a direction change).
p.set("foo",
"50=0; 60=100; 100=110; 150=200; 200=110; 240=100; 260=50; 300=200; 301=10; 350=11");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 50 should all be 0
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 0);
}
// Values from 50 to 150 should only go up
prev = 0;
for (int i = 50; i <= 150; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current >= prev);
prev = current;
}
// Values from 150 to 260 should only go down
prev = 201;
for (int i = 150; i <= 260; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current < prev);
prev = current;
}
// Values from 260 to 300 should only go up
prev = 49;
for (int i = 260; i <= 300; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 200.01);
prev = current;
}
// Values above 301 to 350 should go up from 10 to 11
prev = 9.99;
for (int i = 301; i <= 350; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 11.01);
prev = current;
}
// Values above 350 should be 11
for (int i = 350; i <= 360; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 11);
}
}
void SmoothLooseCanReverse()
{
Properties p;
p.set("foo",
"50~=0; 60~=100; 100~=110; 150~=200; 200~=110; 240~=100; 260~=50; 300~=200; 301~=10; "
"350~=11");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 50 should all be 0
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 0);
}
// Values from 50 to 150 will cusp
for (int i = 50; i <= 150; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current >= 0);
QVERIFY(current < 200.01);
}
// Values from 150 to 260 will cusp
for (int i = 150; i <= 260; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current < 200.01);
QVERIFY(current > 47);
}
// Values from 260 to 300 will overshoot
for (int i = 260; i <= 300; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > 49.99);
QVERIFY(current < 205.01);
}
// Values above 301 to 350 will overshoot below 10
for (int i = 301; i <= 350; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > -3.8);
QVERIFY(current < 11.01);
}
// Values above 350 should be 11
for (int i = 350; i <= 360; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 11);
}
}
void SmoothNaturalDoesNotReverse()
{
Properties p;
double prev;
// This sequence of keyframes has abrupt changes. For some interpolation algorithms, this
// can result in values changing direction along the interpolation path (cusp or
// overshoot).
// The purpose of this test is to ensure that values do not reverse direction (exept as
// expected at keyframes if the user specified a direction change).
p.set("foo",
"50$=0; 60$=100; 100$=110; 150$=200; 200$=110; 240$=100; 260$=50; 300$=200; 301$=10; "
"350$=11");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 50 should all be 0
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 0);
}
// Values from 50 to 150 should only go up
prev = -0.01;
for (int i = 50; i <= 150; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 200.01);
prev = current;
}
// Values from 150 to 260 should only go down
prev = 200.01;
for (int i = 150; i <= 260; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current < prev);
prev = current;
}
// Values from 260 to 300 should only go up
prev = 49.99;
for (int i = 260; i <= 300; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 200.01);
prev = current;
}
// Values above 301 to 350 should go up from 10 to 11
prev = 9.99;
for (int i = 301; i <= 350; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 11.01);
prev = current;
}
// Values above 350 should be 11
for (int i = 350; i <= 360; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 11);
}
}
void SmoothTightDoesNotReverse()
{
Properties p;
double prev;
// This sequence of keyframes has abrupt changes. For some interpolation algorithms, this
// can result in values changing direction along the interpolation path (cusp or
// overshoot).
// The purpose of this test is to ensure that values do not reverse direction (exept as
// expected at keyframes if the user specified a direction change).
p.set("foo",
"50-=0; 60-=100; 100-=110; 150-=200; 200-=110; 240-=100; 260-=50; 300-=200; 301-=10; "
"350-=11");
// Cause the string to be interpreted as animated value.
p.anim_get_int("foo", 0);
Animation a = p.get_animation("foo");
QVERIFY(a.is_valid());
// Values from 0 to 50 should all be 0
for (int i = 0; i <= 50; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 0);
}
// Values from 50 to 150 should only go up
prev = -0.01;
for (int i = 50; i <= 150; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 200.01);
prev = current;
}
// Values from 150 to 260 should only go down
prev = 200.01;
for (int i = 150; i <= 260; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current < prev);
prev = current;
}
// Values from 260 to 300 should only go up
prev = 49.99;
for (int i = 260; i <= 300; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 200.01);
prev = current;
}
// Values above 301 to 350 should go up from 10 to 11
prev = 9.99;
for (int i = 301; i <= 350; i++) {
double current = p.anim_get_double("foo", i);
QVERIFY(current > prev);
QVERIFY(current < 11.01);
prev = current;
}
// Values above 350 should be 11
for (int i = 350; i <= 360; i++) {
double current = p.anim_get_double("foo", i);
QCOMPARE(current, 11);
}
}
void EaseIn()
{
Properties p;
p.set("sinu", "0a=0; 100a=100;");
p.set("quad", "0d=0; 100d=100;");
p.set("cube", "0g=0; 100g=100;");
p.set("quar", "0j=0; 100j=100;");
p.set("quin", "0m=0; 100m=100;");
p.set("expo", "0p=0; 100p=100;");
p.set("circ", "0s=0; 100s=100;");
p.set("back", "0v=0; 100v=100;");
p.set("elas", "0y=0; 100y=100;");
p.set("boun", "0B=0; 100B=100;");
p.anim_get_int("sinu", 0);
p.anim_get_int("quad", 0);
p.anim_get_int("cube", 0);
p.anim_get_int("quar", 0);
p.anim_get_int("quin", 0);
p.anim_get_int("expo", 0);
p.anim_get_int("circ", 0);
p.anim_get_int("back", 0);
p.anim_get_int("elas", 0);
p.anim_get_int("boun", 0);
// fprintf(stderr, "sinu\tquad\tcube\tquar\tquin\texpo\tcirc\tback\telas\tboun\n");
for (int i = 0; i <= 100; i++) {
double sinu = p.anim_get_double("sinu", i);
double quad = p.anim_get_double("quad", i);
double cube = p.anim_get_double("cube", i);
double quar = p.anim_get_double("quar", i);
double quin = p.anim_get_double("quin", i);
double expo = p.anim_get_double("expo", i);
double circ = p.anim_get_double("circ", i);
double back = p.anim_get_double("back", i);
double elas = p.anim_get_double("elas", i);
double boun = p.anim_get_double("boun", i);
// fprintf(stderr,"%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", sinu, quad, cube, quar, quin, expo, circ, back, elas, boun);
QVERIFY(sinu >= 0.0);
QVERIFY(sinu <= 100.0);
QVERIFY(quad >= 0.0);
QVERIFY(quad <= 100.0);
QVERIFY(quad <= sinu);
QVERIFY(cube >= 0.0);
QVERIFY(cube <= 100.0);
QVERIFY(cube <= quad);
QVERIFY(quar >= 0.0);
QVERIFY(quar <= 100.0);
QVERIFY(quar <= cube);
QVERIFY(quin >= 0.0);
QVERIFY(quin <= 100.0);
QVERIFY(quin <= quar);
QVERIFY(expo >= 0.0);
QVERIFY(expo <= 100.0);
QVERIFY(circ >= 0.0);
QVERIFY(circ <= 100.0);
QVERIFY(back >= -37.88);
QVERIFY(back <= 100.0);
QVERIFY(elas >= -36.39);
QVERIFY(elas <= 100.0);
QVERIFY(boun >= -0.00000001);
QVERIFY(boun <= 100.0);
}
}
void EaseOut()
{
Properties p;
p.set("sinu", "0b=0; 100b=100;");
p.set("quad", "0e=0; 100e=100;");
p.set("cube", "0h=0; 100h=100;");
p.set("quar", "0k=0; 100k=100;");
p.set("quin", "0n=0; 100n=100;");
p.set("expo", "0q=0; 100q=100;");
p.set("circ", "0t=0; 100t=100;");
p.set("back", "0w=0; 100w=100;");
p.set("elas", "0z=0; 100z=100;");
p.set("boun", "0C=0; 100C=100;");
p.anim_get_int("sinu", 0);
p.anim_get_int("quad", 0);
p.anim_get_int("cube", 0);
p.anim_get_int("quar", 0);
p.anim_get_int("quin", 0);
p.anim_get_int("expo", 0);
p.anim_get_int("circ", 0);
p.anim_get_int("back", 0);
p.anim_get_int("elas", 0);
p.anim_get_int("boun", 0);
// fprintf(stderr, "sinu\tquad\tcube\tquar\tquin\texpo\tcirc\tback\telas\tboun\n");
for (int i = 0; i <= 100; i++) {
double sinu = p.anim_get_double("sinu", i);
double quad = p.anim_get_double("quad", i);
double cube = p.anim_get_double("cube", i);
double quar = p.anim_get_double("quar", i);
double quin = p.anim_get_double("quin", i);
double expo = p.anim_get_double("expo", i);
double circ = p.anim_get_double("circ", i);
double back = p.anim_get_double("back", i);
double elas = p.anim_get_double("elas", i);
double boun = p.anim_get_double("boun", i);
// fprintf(stderr,"%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", sinu, quad, cube, quar, quin, expo, circ, back, elas, boun);
QVERIFY(sinu >= 0.0);
QVERIFY(sinu <= 100.0);
QVERIFY(quad >= 0.0);
QVERIFY(quad <= 100.0);
QVERIFY(quad >= sinu);
QVERIFY(cube >= 0.0);
QVERIFY(cube <= 100.0);
QVERIFY(cube >= quad);
QVERIFY(quar >= 0.0);
QVERIFY(quar <= 100.0);
QVERIFY(quar >= cube);