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