1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4TestCase := Rectangle {
5 property <int> xx : 1000;
6
7 property <easing> ea: ease;
8
9 animate x {
10 duration: xx * 1ms;
11 easing: ea;
12 }
13
14 property<int> hello: 40;
15 animate hello {
16 duration: 1200ms;
17 }
18
19 property<bool> condition: true;
20 property<int> binding_dep: condition ? 100 : 150;
21 animate binding_dep {
22 duration: 1200ms;
23 }
24
25 property<int> direction: 100;
26 animate direction {
27 duration: 600ms;
28 direction: alternate-reverse;
29 iteration-count: 2;
30 }
31}
32
33/*
34
35```rust
36let instance = TestCase::new().unwrap();
37assert_eq!(instance.get_hello(), 40);
38assert_eq!(instance.get_binding_dep(), 100);
39assert_eq!(instance.get_direction(), 100);
40instance.set_condition(false);
41instance.set_hello(60);
42instance.set_direction(200);
43// no time has elapsed yet
44assert_eq!(instance.get_hello(), 40);
45assert_eq!(instance.get_binding_dep(), 100);
46assert_eq!(instance.get_direction(), 200);
47
48// Half the animation
49slint_testing::mock_elapsed_time(600);
50assert_eq!(instance.get_hello(), 50);
51assert_eq!(instance.get_binding_dep(), 125);
52assert_eq!(instance.get_direction(), 100);
53
54
55// Remaining half
56slint_testing::mock_elapsed_time(600);
57assert_eq!(instance.get_hello(), 60);
58assert_eq!(instance.get_binding_dep(), 150);
59assert_eq!(instance.get_direction(), 200);
60
61slint_testing::mock_elapsed_time(100);
62assert_eq!(instance.get_hello(), 60);
63assert_eq!(instance.get_binding_dep(), 150);
64assert_eq!(instance.get_direction(), 200);
65
66// Changing the value and waiting should have effect without
67// querying the value (because te dirty event should cause the animation to start)
68instance.set_condition(true);
69instance.set_hello(30);
70instance.set_direction(100);
71slint_testing::mock_elapsed_time(600);
72assert_eq!(instance.get_hello(), 45);
73assert_eq!(instance.get_binding_dep(), 125);
74assert_eq!(instance.get_direction(), 200);
75
76```
77
78
79```cpp
80auto handle = TestCase::create();
81const TestCase &instance = *handle;
82assert_eq(instance.get_hello(), 40);
83assert_eq(instance.get_binding_dep(), 100);
84assert_eq(instance.get_direction(), 100);
85instance.set_condition(false);
86instance.set_hello(60);
87instance.set_direction(200);
88// no time has elapsed yet
89assert_eq(instance.get_hello(), 40);
90assert_eq(instance.get_binding_dep(), 100);
91assert_eq(instance.get_direction(), 200);
92
93// Half the animation
94slint_testing::mock_elapsed_time(600);
95assert_eq(instance.get_hello(), 50);
96assert_eq(instance.get_binding_dep(), 125);
97assert_eq(instance.get_direction(), 100);
98
99
100// Remaining half
101slint_testing::mock_elapsed_time(600);
102assert_eq(instance.get_hello(), 60);
103assert_eq(instance.get_binding_dep(), 150);
104assert_eq(instance.get_direction(), 200);
105
106slint_testing::mock_elapsed_time(100);
107assert_eq(instance.get_hello(), 60);
108assert_eq(instance.get_binding_dep(), 150);
109assert_eq(instance.get_direction(), 200);
110
111// Changing the value and waiting should have effect without
112// querying the value (because te dirty event should cause the animation to start)
113instance.set_condition(true);
114instance.set_hello(30);
115instance.set_direction(100);
116slint_testing::mock_elapsed_time(600);
117assert_eq(instance.get_hello(), 45);
118assert_eq(instance.get_binding_dep(), 125);
119assert_eq(instance.get_direction(), 200);
120```
121
122```js
123var instance = new slint.TestCase({});
124assert.equal(instance.hello, 40);
125assert.equal(instance.binding_dep, 100);
126assert.equal(instance.direction, 100);
127instance.condition = false;
128instance.hello = 60;
129instance.direction = 200;
130// no time has elapsed yet
131assert.equal(instance.hello, 40);
132assert.equal(instance.binding_dep, 100);
133assert.equal(instance.direction, 200);
134
135// Half the animation
136slintlib.private_api.mock_elapsed_time(600);
137assert.equal(instance.hello, 50);
138assert.equal(instance.binding_dep, 125);
139assert.equal(instance.direction, 100);
140// Remaining half
141slintlib.private_api.mock_elapsed_time(600);
142assert.equal(instance.hello, 60);
143assert.equal(instance.binding_dep, 150);
144assert.equal(instance.direction, 200);
145slintlib.private_api.mock_elapsed_time(100);
146assert.equal(instance.hello, 60);
147assert.equal(instance.binding_dep, 150);
148assert.equal(instance.direction, 200);
149
150// Changing the value and waiting should have effect without
151// querying the value (because te dirty event should cause the animation to start)
152instance.condition = true;
153instance.hello = 30;
154instance.direction = 100;
155slintlib.private_api.mock_elapsed_time(600);
156assert.equal(instance.hello, 45);
157assert.equal(instance.binding_dep, 125);
158assert.equal(instance.direction, 200);
159```
160*/
161