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 |
40 | let instance = TestCase::new().unwrap(); |
41 | assert_eq!(instance.get_text1_foo(), 89); |
42 | assert_eq!(instance.get_some_prop(), 5); |
43 | assert_eq!(instance.get_other_prop(), 5000); |
44 | |
45 | instance.set_active_index(1); |
46 | assert_eq!(instance.get_text1_foo(), 11); |
47 | assert_eq!(instance.get_some_prop(), 5); |
48 | assert_eq!(instance.get_other_prop(), 5000); |
49 | |
50 | slint_testing::mock_elapsed_time(50); // In delay |
51 | assert_eq!(instance.get_text1_foo(), 11); |
52 | assert_eq!(instance.get_some_prop(), 5); |
53 | assert_eq!(instance.get_other_prop(), 5000); |
54 | |
55 | slint_testing::mock_elapsed_time(50); // some: in delay, other: end of delay |
56 | assert_eq!(instance.get_text1_foo(), 11); |
57 | assert_eq!(instance.get_some_prop(), 5); |
58 | assert_eq!(instance.get_other_prop(), 5000); |
59 | |
60 | slint_testing::mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms] |
61 | assert_eq!(instance.get_text1_foo(), 11); |
62 | assert_eq!(instance.get_some_prop(), 5); |
63 | assert!(instance.get_other_prop() < 4760); // should be 4750 |
64 | assert!(instance.get_other_prop() > 4740); |
65 | |
66 | slint_testing::mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms] |
67 | assert_eq!(instance.get_text1_foo(), 11); |
68 | assert_eq!(instance.get_some_prop(), 5); |
69 | assert!(instance.get_other_prop() < 760); // should be 750 |
70 | assert!(instance.get_other_prop() > 740); |
71 | |
72 | slint_testing::mock_elapsed_time(160); // some: in delay, other: ended [111ßms] |
73 | assert_eq!(instance.get_text1_foo(), 11); |
74 | assert_eq!(instance.get_some_prop(), 5); |
75 | assert_eq!(instance.get_other_prop(), 0); |
76 | |
77 | slint_testing::mock_elapsed_time(3840); // some: in delay, other: ended [4950ms] |
78 | assert_eq!(instance.get_text1_foo(), 11); |
79 | assert_eq!(instance.get_some_prop(), 5); |
80 | assert_eq!(instance.get_other_prop(), 0); |
81 | |
82 | slint_testing::mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms] |
83 | assert_eq!(instance.get_text1_foo(), 11); |
84 | assert!(instance.get_some_prop() > 202); // should be 204,5 |
85 | assert!(instance.get_some_prop() < 207); |
86 | assert_eq!(instance.get_other_prop(), 0); |
87 | |
88 | slint_testing::mock_elapsed_time(100); // some: ended, other: ended [5110ms] |
89 | assert_eq!(instance.get_text1_foo(), 11); |
90 | assert_eq!(instance.get_some_prop(), 2000); |
91 | assert_eq!(instance.get_other_prop(), 0); |
92 | |
93 | instance.set_active_index(2); |
94 | assert_eq!(instance.get_text1_foo(), 11); |
95 | assert_eq!(instance.get_some_prop(), 5); |
96 | assert_eq!(instance.get_other_prop(), 5000); |
97 | |
98 | slint_testing::mock_elapsed_time(50); // In delay |
99 | assert_eq!(instance.get_text1_foo(), 11); |
100 | assert_eq!(instance.get_some_prop(), 5); |
101 | assert_eq!(instance.get_other_prop(), 5000); |
102 | |
103 | slint_testing::mock_elapsed_time(440); |
104 | assert!(instance.get_text1_foo() > 70); |
105 | assert!(instance.get_text1_foo() < 87); |
106 | assert_eq!(instance.get_some_prop(), 5); |
107 | assert_eq!(instance.get_other_prop(), 5000); |
108 | |
109 | slint_testing::mock_elapsed_time(30); |
110 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
111 | assert_eq!(instance.get_some_prop(), 5); |
112 | assert_eq!(instance.get_other_prop(), 5000); |
113 | ``` |
114 | |
115 | |
116 | ```cpp |
117 | auto handle = TestCase::create(); |
118 | const TestCase &instance = *handle; |
119 | assert_eq(instance.get_text1_foo(), 85 + 4); |
120 | assert_eq(instance.get_some_prop(), 5); |
121 | assert_eq(instance.get_other_prop(), 5000); |
122 | |
123 | instance.set_active_index(1); |
124 | assert_eq(instance.get_text1_foo(), 11); |
125 | assert_eq(instance.get_some_prop(), 5); |
126 | assert_eq(instance.get_other_prop(), 5000); |
127 | |
128 | slint_testing::mock_elapsed_time(50); // In delay |
129 | assert_eq(instance.get_text1_foo(), 11); |
130 | assert_eq(instance.get_some_prop(), 5); |
131 | assert_eq(instance.get_other_prop(), 5000); |
132 | |
133 | slint_testing::mock_elapsed_time(50); // some: in delay, other: end of delay |
134 | assert_eq(instance.get_text1_foo(), 11); |
135 | assert_eq(instance.get_some_prop(), 5); |
136 | assert_eq(instance.get_other_prop(), 5000); |
137 | |
138 | slint_testing::mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms] |
139 | assert_eq(instance.get_text1_foo(), 11); |
140 | assert_eq(instance.get_some_prop(), 5); |
141 | assert(instance.get_other_prop() < 4760); // should be 4750 |
142 | assert(instance.get_other_prop() > 4740); |
143 | |
144 | slint_testing::mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms] |
145 | assert_eq(instance.get_text1_foo(), 11); |
146 | assert_eq(instance.get_some_prop(), 5); |
147 | assert(instance.get_other_prop() < 760); // should be 750 |
148 | assert(instance.get_other_prop() > 740); |
149 | |
150 | slint_testing::mock_elapsed_time(160); // some: in delay, other: ended [111ßms] |
151 | assert_eq(instance.get_text1_foo(), 11); |
152 | assert_eq(instance.get_some_prop(), 5); |
153 | assert_eq(instance.get_other_prop(), 0); |
154 | |
155 | slint_testing::mock_elapsed_time(3840); // some: in delay, other: ended [4950ms] |
156 | assert_eq(instance.get_text1_foo(), 11); |
157 | assert_eq(instance.get_some_prop(), 5); |
158 | assert_eq(instance.get_other_prop(), 0); |
159 | |
160 | slint_testing::mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms] |
161 | assert_eq(instance.get_text1_foo(), 11); |
162 | assert(instance.get_some_prop() > 202); // should be 204,5 |
163 | assert(instance.get_some_prop() < 207); |
164 | assert_eq(instance.get_other_prop(), 0); |
165 | |
166 | slint_testing::mock_elapsed_time(100); // some: ended, other: ended [5110ms] |
167 | assert_eq(instance.get_text1_foo(), 11); |
168 | assert_eq(instance.get_some_prop(), 2000); |
169 | assert_eq(instance.get_other_prop(), 0); |
170 | |
171 | instance.set_active_index(2); |
172 | assert_eq(instance.get_text1_foo(), 11); |
173 | assert_eq(instance.get_some_prop(), 5); |
174 | assert_eq(instance.get_other_prop(), 5000); |
175 | |
176 | slint_testing::mock_elapsed_time(50); // In delay |
177 | assert_eq(instance.get_text1_foo(), 11); |
178 | assert_eq(instance.get_some_prop(), 5); |
179 | assert_eq(instance.get_other_prop(), 5000); |
180 | |
181 | slint_testing::mock_elapsed_time(440); |
182 | assert(instance.get_text1_foo() > 70); |
183 | assert(instance.get_text1_foo() < 87); |
184 | assert_eq(instance.get_some_prop(), 5); |
185 | assert_eq(instance.get_other_prop(), 5000); |
186 | |
187 | slint_testing::mock_elapsed_time(30); |
188 | assert_eq(instance.get_text1_foo(), 85 + 4); |
189 | assert_eq(instance.get_some_prop(), 5); |
190 | assert_eq(instance.get_other_prop(), 5000); |
191 | ``` |
192 | |
193 | ```js |
194 | var instance = new slint.TestCase({}); |
195 | assert.equal(instance.text1_foo, 85 + 4); |
196 | assert.equal(instance.some_prop, 5); |
197 | assert.equal(instance.other_prop, 5000); |
198 | |
199 | instance.active_index = 1; |
200 | assert.equal(instance.text1_foo, 11); |
201 | assert.equal(instance.some_prop, 5); |
202 | assert.equal(instance.other_prop, 5000); |
203 | |
204 | slintlib.private_api.mock_elapsed_time(50); // In delay |
205 | assert.equal(instance.text1_foo, 11); |
206 | assert.equal(instance.some_prop, 5); |
207 | assert.equal(instance.other_prop, 5000); |
208 | |
209 | slintlib.private_api.mock_elapsed_time(50); // some: in delay, other: end of delay |
210 | assert.equal(instance.text1_foo, 11); |
211 | assert.equal(instance.some_prop, 5); |
212 | assert.equal(instance.other_prop, 5000); |
213 | |
214 | slintlib.private_api.mock_elapsed_time(50); // some: in delay, other: in play for 50ms [150ms] |
215 | assert.equal(instance.text1_foo, 11); |
216 | assert.equal(instance.some_prop, 5); |
217 | assert(instance.other_prop < 4760); // should be 4750 |
218 | assert(instance.other_prop > 4740); |
219 | |
220 | slintlib.private_api.mock_elapsed_time(800); // some: in delay, other: in play for 850ms [950ms] |
221 | assert.equal(instance.text1_foo, 11); |
222 | assert.equal(instance.some_prop, 5); |
223 | assert(instance.other_prop < 760); // should be 750 |
224 | assert(instance.other_prop > 740); |
225 | |
226 | slintlib.private_api.mock_elapsed_time(160); // some: in delay, other: ended [111ßms] |
227 | assert.equal(instance.text1_foo, 11); |
228 | assert.equal(instance.some_prop, 5); |
229 | assert.equal(instance.other_prop, 0); |
230 | |
231 | slintlib.private_api.mock_elapsed_time(3840); // some: in delay, other: ended [4950ms] |
232 | assert.equal(instance.text1_foo, 11); |
233 | assert.equal(instance.some_prop, 5); |
234 | assert.equal(instance.other_prop, 0); |
235 | |
236 | slintlib.private_api.mock_elapsed_time(60); // some: in play for 10ms, other: ended [5010ms] |
237 | assert.equal(instance.text1_foo, 11); |
238 | assert(instance.some_prop > 202); // should be 204,5 |
239 | assert(instance.some_prop < 207); |
240 | assert.equal(instance.other_prop, 0); |
241 | |
242 | slintlib.private_api.mock_elapsed_time(100); // some: ended, other: ended [5110ms] |
243 | assert.equal(instance.text1_foo, 11); |
244 | assert.equal(instance.some_prop, 2000); |
245 | assert.equal(instance.other_prop, 0); |
246 | |
247 | instance.active_index = 2; |
248 | assert.equal(instance.text1_foo, 11); |
249 | assert.equal(instance.some_prop, 5); |
250 | assert.equal(instance.other_prop, 5000); |
251 | |
252 | slintlib.private_api.mock_elapsed_time(50); // In delay |
253 | assert.equal(instance.text1_foo, 11); |
254 | assert.equal(instance.some_prop, 5); |
255 | assert.equal(instance.other_prop, 5000); |
256 | |
257 | slintlib.private_api.mock_elapsed_time(440); |
258 | assert(instance.text1_foo > 70); |
259 | assert(instance.text1_foo < 87); |
260 | assert.equal(instance.some_prop, 5); |
261 | assert.equal(instance.other_prop, 5000); |
262 | |
263 | slintlib.private_api.mock_elapsed_time(30); |
264 | assert.equal(instance.text1_foo, 85 + 4); |
265 | assert.equal(instance.some_prop, 5); |
266 | assert.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 | } |