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