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