1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4
5AnimatedObject := Rectangle {
6 property <int> animated_prop;
7 animate animated_prop { duration: aa_duration; }
8 property <duration> aa_duration: 1s;
9}
10
11NotAnimatedObject := Rectangle {
12 property <int> value;
13 property <int> animated_prop: value;
14}
15
16TestCase := Rectangle {
17 property <int> value : 1000;
18 property <int> o1_val: o1.animated_prop;
19 property <int> o2_val: o2.animated_prop;
20 property <int> o3_val: o3.animated_prop;
21 property <int> o4_val: o4.animated_prop;
22 o1 := AnimatedObject {
23 animated_prop: value;
24 }
25 o2 := AnimatedObject {
26 aa_duration: 2s;
27 animated_prop: value;
28 }
29 o3 := AnimatedObject {
30 animate animated_prop { duration: 3s; }
31 animated_prop: value;
32 }
33 o4 := NotAnimatedObject {
34 value: root.value;
35 animate animated_prop { duration: 4s; }
36 }
37}
38
39
40/*
41
42```rust
43let instance = TestCase::new().unwrap();
44assert_eq!(instance.get_o1_val(), 1000, "o1");
45assert_eq!(instance.get_o2_val(), 1000, "o2");
46assert_eq!(instance.get_o3_val(), 1000, "o3");
47assert_eq!(instance.get_o4_val(), 1000, "o4");
48instance.set_value(1600);
49// animation not started
50assert_eq!(instance.get_o1_val(), 1000, "o1 - 0");
51assert_eq!(instance.get_o2_val(), 1000, "o2 - 0");
52assert_eq!(instance.get_o3_val(), 1000, "o3 - 0");
53assert_eq!(instance.get_o4_val(), 1000, "o4 - 0");
54
55
56slint_testing::mock_elapsed_time(1000); // 1s
57assert_eq!(instance.get_o1_val(), 1000 + 600, "o1 - 1"); // done
58assert_eq!(instance.get_o2_val(), 1000 + 600/2, "o2 - 1"); // ½
59assert_eq!(instance.get_o3_val(), 1000 + 600/3, "o3 - 1"); // ⅓
60assert_eq!(instance.get_o4_val(), 1000 + 600/4, "o4 - 1"); // ¼
61
62slint_testing::mock_elapsed_time(1000);
63assert_eq!(instance.get_o1_val(), 1600, "o1 - 2");
64assert_eq!(instance.get_o2_val(), 1600, "o2 - 2");
65assert_eq!(instance.get_o3_val(), 1000 + 2*600/3, "o3 - 2");
66assert_eq!(instance.get_o4_val(), 1000 + 600/2, "o4 - 2");
67
68slint_testing::mock_elapsed_time(1000);
69assert_eq!(instance.get_o1_val(), 1600, "o1 - 3");
70assert_eq!(instance.get_o2_val(), 1600, "o2 - 3");
71assert_eq!(instance.get_o3_val(), 1600, "o3 - 3");
72assert_eq!(instance.get_o4_val(), 1000 + 3*600/4, "o4 - 3");
73
74
75slint_testing::mock_elapsed_time(1000);
76assert_eq!(instance.get_o1_val(), 1600, "o1 - 4");
77assert_eq!(instance.get_o2_val(), 1600, "o2 - 4");
78assert_eq!(instance.get_o3_val(), 1600, "o3 - 4");
79assert_eq!(instance.get_o4_val(), 1600, "o4 - 4");
80
81```
82
83*/
84