1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/properties"#]
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
5 TestCase := Rectangle {
6 property<int> top_level: 4;
7 property<int> active_index: 0;
8 property<int> some_prop: 5;
9 property<int> other_prop: 5000;
10 text1 := Text {
11 property<int> foo: 85 + top_level;
12 }
13
14 states [
15 xxx when active_index == 1 : {
16 text1.foo: 3 + 2 * top_level;
17 some_prop: 2000;
18 other_prop: 0;
19 }
20 ]
21
22 transitions [
23 in xxx: {
24 animate some_prop { delay: 5000ms; duration: 100ms; }
25 animate other_prop { delay: 100ms; duration: 1000ms; }
26 }
27 out xxx: {
28 animate text1.foo { delay: 200ms; duration: 300ms; }
29 }
30 ]
31
32 property<int> text1_foo: text1.foo;
33
34}
35
36
37/*
38
39```rust
40let instance = TestCase::new().unwrap();
41assert_eq!(instance.get_text1_foo(), 89);
42assert_eq!(instance.get_some_prop(), 5);
43assert_eq!(instance.get_other_prop(), 5000);
44
45instance.set_active_index(1);
46assert_eq!(instance.get_text1_foo(), 11);
47assert_eq!(instance.get_some_prop(), 5);
48assert_eq!(instance.get_other_prop(), 5000);
49
50slint_testing::mock_elapsed_time(50); // In delay
51assert_eq!(instance.get_text1_foo(), 11);
52assert_eq!(instance.get_some_prop(), 5);
53assert_eq!(instance.get_other_prop(), 5000);
54
55slint_testing::mock_elapsed_time(50); // some: in delay, other: end of delay
56assert_eq!(instance.get_text1_foo(), 11);
57assert_eq!(instance.get_some_prop(), 5);
58assert_eq!(instance.get_other_prop(), 5000);
59
60slint_testing::mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms]
61assert_eq!(instance.get_text1_foo(), 11);
62assert_eq!(instance.get_some_prop(), 5);
63assert!(instance.get_other_prop() < 4760); // should be 4750
64assert!(instance.get_other_prop() > 4740);
65
66slint_testing::mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms]
67assert_eq!(instance.get_text1_foo(), 11);
68assert_eq!(instance.get_some_prop(), 5);
69assert!(instance.get_other_prop() < 760); // should be 750
70assert!(instance.get_other_prop() > 740);
71
72slint_testing::mock_elapsed_time(160); // some: in delay, other: ended [111ßms]
73assert_eq!(instance.get_text1_foo(), 11);
74assert_eq!(instance.get_some_prop(), 5);
75assert_eq!(instance.get_other_prop(), 0);
76
77slint_testing::mock_elapsed_time(3840); // some: in delay, other: ended [4950ms]
78assert_eq!(instance.get_text1_foo(), 11);
79assert_eq!(instance.get_some_prop(), 5);
80assert_eq!(instance.get_other_prop(), 0);
81
82slint_testing::mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms]
83assert_eq!(instance.get_text1_foo(), 11);
84assert!(instance.get_some_prop() > 202); // should be 204,5
85assert!(instance.get_some_prop() < 207);
86assert_eq!(instance.get_other_prop(), 0);
87
88slint_testing::mock_elapsed_time(100); // some: ended, other: ended [5110ms]
89assert_eq!(instance.get_text1_foo(), 11);
90assert_eq!(instance.get_some_prop(), 2000);
91assert_eq!(instance.get_other_prop(), 0);
92
93instance.set_active_index(2);
94assert_eq!(instance.get_text1_foo(), 11);
95assert_eq!(instance.get_some_prop(), 5);
96assert_eq!(instance.get_other_prop(), 5000);
97
98slint_testing::mock_elapsed_time(50); // In delay
99assert_eq!(instance.get_text1_foo(), 11);
100assert_eq!(instance.get_some_prop(), 5);
101assert_eq!(instance.get_other_prop(), 5000);
102
103slint_testing::mock_elapsed_time(440);
104assert!(instance.get_text1_foo() > 70);
105assert!(instance.get_text1_foo() < 87);
106assert_eq!(instance.get_some_prop(), 5);
107assert_eq!(instance.get_other_prop(), 5000);
108
109slint_testing::mock_elapsed_time(30);
110assert_eq!(instance.get_text1_foo(), 85 + 4);
111assert_eq!(instance.get_some_prop(), 5);
112assert_eq!(instance.get_other_prop(), 5000);
113```
114
115
116```cpp
117auto handle = TestCase::create();
118const TestCase &instance = *handle;
119assert_eq(instance.get_text1_foo(), 85 + 4);
120assert_eq(instance.get_some_prop(), 5);
121assert_eq(instance.get_other_prop(), 5000);
122
123instance.set_active_index(1);
124assert_eq(instance.get_text1_foo(), 11);
125assert_eq(instance.get_some_prop(), 5);
126assert_eq(instance.get_other_prop(), 5000);
127
128slint_testing::mock_elapsed_time(50); // In delay
129assert_eq(instance.get_text1_foo(), 11);
130assert_eq(instance.get_some_prop(), 5);
131assert_eq(instance.get_other_prop(), 5000);
132
133slint_testing::mock_elapsed_time(50); // some: in delay, other: end of delay
134assert_eq(instance.get_text1_foo(), 11);
135assert_eq(instance.get_some_prop(), 5);
136assert_eq(instance.get_other_prop(), 5000);
137
138slint_testing::mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms]
139assert_eq(instance.get_text1_foo(), 11);
140assert_eq(instance.get_some_prop(), 5);
141assert(instance.get_other_prop() < 4760); // should be 4750
142assert(instance.get_other_prop() > 4740);
143
144slint_testing::mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms]
145assert_eq(instance.get_text1_foo(), 11);
146assert_eq(instance.get_some_prop(), 5);
147assert(instance.get_other_prop() < 760); // should be 750
148assert(instance.get_other_prop() > 740);
149
150slint_testing::mock_elapsed_time(160); // some: in delay, other: ended [111ßms]
151assert_eq(instance.get_text1_foo(), 11);
152assert_eq(instance.get_some_prop(), 5);
153assert_eq(instance.get_other_prop(), 0);
154
155slint_testing::mock_elapsed_time(3840); // some: in delay, other: ended [4950ms]
156assert_eq(instance.get_text1_foo(), 11);
157assert_eq(instance.get_some_prop(), 5);
158assert_eq(instance.get_other_prop(), 0);
159
160slint_testing::mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms]
161assert_eq(instance.get_text1_foo(), 11);
162assert(instance.get_some_prop() > 202); // should be 204,5
163assert(instance.get_some_prop() < 207);
164assert_eq(instance.get_other_prop(), 0);
165
166slint_testing::mock_elapsed_time(100); // some: ended, other: ended [5110ms]
167assert_eq(instance.get_text1_foo(), 11);
168assert_eq(instance.get_some_prop(), 2000);
169assert_eq(instance.get_other_prop(), 0);
170
171instance.set_active_index(2);
172assert_eq(instance.get_text1_foo(), 11);
173assert_eq(instance.get_some_prop(), 5);
174assert_eq(instance.get_other_prop(), 5000);
175
176slint_testing::mock_elapsed_time(50); // In delay
177assert_eq(instance.get_text1_foo(), 11);
178assert_eq(instance.get_some_prop(), 5);
179assert_eq(instance.get_other_prop(), 5000);
180
181slint_testing::mock_elapsed_time(440);
182assert(instance.get_text1_foo() > 70);
183assert(instance.get_text1_foo() < 87);
184assert_eq(instance.get_some_prop(), 5);
185assert_eq(instance.get_other_prop(), 5000);
186
187slint_testing::mock_elapsed_time(30);
188assert_eq(instance.get_text1_foo(), 85 + 4);
189assert_eq(instance.get_some_prop(), 5);
190assert_eq(instance.get_other_prop(), 5000);
191```
192
193```js
194var instance = new slint.TestCase({});
195assert.equal(instance.text1_foo, 85 + 4);
196assert.equal(instance.some_prop, 5);
197assert.equal(instance.other_prop, 5000);
198
199instance.active_index = 1;
200assert.equal(instance.text1_foo, 11);
201assert.equal(instance.some_prop, 5);
202assert.equal(instance.other_prop, 5000);
203
204slintlib.private_api.mock_elapsed_time(50); // In delay
205assert.equal(instance.text1_foo, 11);
206assert.equal(instance.some_prop, 5);
207assert.equal(instance.other_prop, 5000);
208
209slintlib.private_api.mock_elapsed_time(50); // some: in delay, other: end of delay
210assert.equal(instance.text1_foo, 11);
211assert.equal(instance.some_prop, 5);
212assert.equal(instance.other_prop, 5000);
213
214slintlib.private_api.mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms]
215assert.equal(instance.text1_foo, 11);
216assert.equal(instance.some_prop, 5);
217assert(instance.other_prop < 4760); // should be 4750
218assert(instance.other_prop > 4740);
219
220slintlib.private_api.mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms]
221assert.equal(instance.text1_foo, 11);
222assert.equal(instance.some_prop, 5);
223assert(instance.other_prop < 760); // should be 750
224assert(instance.other_prop > 740);
225
226slintlib.private_api.mock_elapsed_time(160); // some: in delay, other: ended [111ßms]
227assert.equal(instance.text1_foo, 11);
228assert.equal(instance.some_prop, 5);
229assert.equal(instance.other_prop, 0);
230
231slintlib.private_api.mock_elapsed_time(3840); // some: in delay, other: ended [4950ms]
232assert.equal(instance.text1_foo, 11);
233assert.equal(instance.some_prop, 5);
234assert.equal(instance.other_prop, 0);
235
236slintlib.private_api.mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms]
237assert.equal(instance.text1_foo, 11);
238assert(instance.some_prop > 202); // should be 204,5
239assert(instance.some_prop < 207);
240assert.equal(instance.other_prop, 0);
241
242slintlib.private_api.mock_elapsed_time(100); // some: ended, other: ended [5110ms]
243assert.equal(instance.text1_foo, 11);
244assert.equal(instance.some_prop, 2000);
245assert.equal(instance.other_prop, 0);
246
247instance.active_index = 2;
248assert.equal(instance.text1_foo, 11);
249assert.equal(instance.some_prop, 5);
250assert.equal(instance.other_prop, 5000);
251
252slintlib.private_api.mock_elapsed_time(50); // In delay
253assert.equal(instance.text1_foo, 11);
254assert.equal(instance.some_prop, 5);
255assert.equal(instance.other_prop, 5000);
256
257slintlib.private_api.mock_elapsed_time(440);
258assert(instance.text1_foo > 70);
259assert(instance.text1_foo < 87);
260assert.equal(instance.some_prop, 5);
261assert.equal(instance.other_prop, 5000);
262
263slintlib.private_api.mock_elapsed_time(30);
264assert.equal(instance.text1_foo, 85 + 4);
265assert.equal(instance.some_prop, 5);
266assert.equal(instance.other_prop, 5000);
267```
268
269*/
270}
271
272#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
273 use i_slint_backend_testing as slint_testing;
274 slint_testing::init();
275 let instance = TestCase::new().unwrap();
276 assert_eq!(instance.get_text1_foo(), 89);
277 assert_eq!(instance.get_some_prop(), 5);
278 assert_eq!(instance.get_other_prop(), 5000);
279
280 instance.set_active_index(1);
281 assert_eq!(instance.get_text1_foo(), 11);
282 assert_eq!(instance.get_some_prop(), 5);
283 assert_eq!(instance.get_other_prop(), 5000);
284
285 slint_testing::mock_elapsed_time(50); // In delay
286 assert_eq!(instance.get_text1_foo(), 11);
287 assert_eq!(instance.get_some_prop(), 5);
288 assert_eq!(instance.get_other_prop(), 5000);
289
290 slint_testing::mock_elapsed_time(50); // some: in delay, other: end of delay
291 assert_eq!(instance.get_text1_foo(), 11);
292 assert_eq!(instance.get_some_prop(), 5);
293 assert_eq!(instance.get_other_prop(), 5000);
294
295 slint_testing::mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms]
296 assert_eq!(instance.get_text1_foo(), 11);
297 assert_eq!(instance.get_some_prop(), 5);
298 assert!(instance.get_other_prop() < 4760); // should be 4750
299 assert!(instance.get_other_prop() > 4740);
300
301 slint_testing::mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms]
302 assert_eq!(instance.get_text1_foo(), 11);
303 assert_eq!(instance.get_some_prop(), 5);
304 assert!(instance.get_other_prop() < 760); // should be 750
305 assert!(instance.get_other_prop() > 740);
306
307 slint_testing::mock_elapsed_time(160); // some: in delay, other: ended [111ßms]
308 assert_eq!(instance.get_text1_foo(), 11);
309 assert_eq!(instance.get_some_prop(), 5);
310 assert_eq!(instance.get_other_prop(), 0);
311
312 slint_testing::mock_elapsed_time(3840); // some: in delay, other: ended [4950ms]
313 assert_eq!(instance.get_text1_foo(), 11);
314 assert_eq!(instance.get_some_prop(), 5);
315 assert_eq!(instance.get_other_prop(), 0);
316
317 slint_testing::mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms]
318 assert_eq!(instance.get_text1_foo(), 11);
319 assert!(instance.get_some_prop() > 202); // should be 204,5
320 assert!(instance.get_some_prop() < 207);
321 assert_eq!(instance.get_other_prop(), 0);
322
323 slint_testing::mock_elapsed_time(100); // some: ended, other: ended [5110ms]
324 assert_eq!(instance.get_text1_foo(), 11);
325 assert_eq!(instance.get_some_prop(), 2000);
326 assert_eq!(instance.get_other_prop(), 0);
327
328 instance.set_active_index(2);
329 assert_eq!(instance.get_text1_foo(), 11);
330 assert_eq!(instance.get_some_prop(), 5);
331 assert_eq!(instance.get_other_prop(), 5000);
332
333 slint_testing::mock_elapsed_time(50); // In delay
334 assert_eq!(instance.get_text1_foo(), 11);
335 assert_eq!(instance.get_some_prop(), 5);
336 assert_eq!(instance.get_other_prop(), 5000);
337
338 slint_testing::mock_elapsed_time(440);
339 assert!(instance.get_text1_foo() > 70);
340 assert!(instance.get_text1_foo() < 87);
341 assert_eq!(instance.get_some_prop(), 5);
342 assert_eq!(instance.get_other_prop(), 5000);
343
344 slint_testing::mock_elapsed_time(30);
345 assert_eq!(instance.get_text1_foo(), 85 + 4);
346 assert_eq!(instance.get_some_prop(), 5);
347 assert_eq!(instance.get_other_prop(), 5000);
348 Ok(())
349}