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
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}
26
27/*
28
29```rust
30let instance = TestCase::new().unwrap();
31assert_eq!(instance.get_hello(), 40);
32assert_eq!(instance.get_binding_dep(), 100);
33instance.set_condition(false);
34instance.set_hello(60);
35// no time has elapsed yet
36assert_eq!(instance.get_hello(), 40);
37assert_eq!(instance.get_binding_dep(), 100);
38
39// Half the animation
40slint_testing::mock_elapsed_time(600);
41assert_eq!(instance.get_hello(), 50);
42assert_eq!(instance.get_binding_dep(), 125);
43
44
45// Remaining half
46slint_testing::mock_elapsed_time(600);
47assert_eq!(instance.get_hello(), 60);
48assert_eq!(instance.get_binding_dep(), 150);
49
50slint_testing::mock_elapsed_time(100);
51assert_eq!(instance.get_hello(), 60);
52assert_eq!(instance.get_binding_dep(), 150);
53
54// Changing the value and waiting should have effect without
55// querying the value (because te dirty event should cause the animation to start)
56instance.set_condition(true);
57instance.set_hello(30);
58slint_testing::mock_elapsed_time(600);
59assert_eq!(instance.get_hello(), 45);
60assert_eq!(instance.get_binding_dep(), 125);
61
62```
63
64
65```cpp
66auto handle = TestCase::create();
67const TestCase &instance = *handle;
68assert_eq(instance.get_hello(), 40);
69assert_eq(instance.get_binding_dep(), 100);
70instance.set_condition(false);
71instance.set_hello(60);
72// no time has elapsed yet
73assert_eq(instance.get_hello(), 40);
74assert_eq(instance.get_binding_dep(), 100);
75
76// Half the animation
77slint_testing::mock_elapsed_time(600);
78assert_eq(instance.get_hello(), 50);
79assert_eq(instance.get_binding_dep(), 125);
80
81
82// Remaining half
83slint_testing::mock_elapsed_time(600);
84assert_eq(instance.get_hello(), 60);
85assert_eq(instance.get_binding_dep(), 150);
86
87slint_testing::mock_elapsed_time(100);
88assert_eq(instance.get_hello(), 60);
89assert_eq(instance.get_binding_dep(), 150);
90
91// Changing the value and waiting should have effect without
92// querying the value (because te dirty event should cause the animation to start)
93instance.set_condition(true);
94instance.set_hello(30);
95slint_testing::mock_elapsed_time(600);
96assert_eq(instance.get_hello(), 45);
97assert_eq(instance.get_binding_dep(), 125);
98```
99
100```js
101var instance = new slint.TestCase({});
102assert.equal(instance.hello, 40);
103assert.equal(instance.binding_dep, 100);
104instance.condition = false;
105instance.hello = 60;
106// no time has elapsed yet
107assert.equal(instance.hello, 40);
108assert.equal(instance.binding_dep, 100);
109
110// Half the animation
111slintlib.private_api.mock_elapsed_time(600);
112assert.equal(instance.hello, 50);
113assert.equal(instance.binding_dep, 125);
114// Remaining half
115slintlib.private_api.mock_elapsed_time(600);
116assert.equal(instance.hello, 60);
117assert.equal(instance.binding_dep, 150);
118slintlib.private_api.mock_elapsed_time(100);
119assert.equal(instance.hello, 60);
120assert.equal(instance.binding_dep, 150);
121
122// Changing the value and waiting should have effect without
123// querying the value (because te dirty event should cause the animation to start)
124instance.condition = true;
125instance.hello = 30;
126slintlib.private_api.mock_elapsed_time(600);
127assert.equal(instance.hello, 45);
128assert.equal(instance.binding_dep, 125);
129
130```
131*/
132