1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/focus"# ] |
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 | import { SpinBox, LineEdit, HorizontalBox, VerticalBox, TabWidget } from "std-widgets.slint" ; |
6 | |
7 | TestCase := Window { |
8 | preferred-width: 500px; |
9 | preferred-height: 400px; |
10 | |
11 | property<[{name: string, account: string, score: float}]> model: [ |
12 | { |
13 | name: "Olivier" , |
14 | account: "ogoffart" , |
15 | score: 456, |
16 | }, |
17 | { |
18 | name: "Simon" , |
19 | account: "tronical" , |
20 | score: 789, |
21 | } |
22 | ]; |
23 | |
24 | property<string> result; |
25 | |
26 | VerticalBox { |
27 | FocusScope { |
28 | key-pressed(event) => { |
29 | if (event.text == "X" ) { |
30 | result += "T:" ; |
31 | return accept; |
32 | } |
33 | return reject; |
34 | } |
35 | } |
36 | |
37 | for person[i] in model: HorizontalBox { |
38 | FocusScope { |
39 | key-pressed(event) => { |
40 | if (event.text == "X" ) { |
41 | result += "1." + person.score + ":" ; |
42 | return accept; |
43 | } |
44 | return reject; |
45 | } |
46 | } |
47 | FocusScope { |
48 | enabled: false; |
49 | } |
50 | FocusScope { |
51 | key-pressed(event) => { |
52 | if (event.text == "X" ) { |
53 | result += "2." + i + ":" ; |
54 | return accept; |
55 | } |
56 | return reject; |
57 | } |
58 | } |
59 | if (true) : FocusScope { |
60 | enabled: false; |
61 | } |
62 | } |
63 | FocusScope { |
64 | key-pressed(event) => { |
65 | if (event.text == "X" ) { |
66 | result += "B:" ; |
67 | return accept; |
68 | } |
69 | return reject; |
70 | } |
71 | } |
72 | } |
73 | for xxx in [0, 1] : FocusScope { |
74 | enabled: false; |
75 | key-pressed(event) => { |
76 | result += "disabledA" + xxx; |
77 | accept |
78 | } |
79 | if (true) : FocusScope { |
80 | enabled: false; |
81 | key-pressed(event) => { |
82 | result += "disabledB" + xxx; |
83 | accept |
84 | } |
85 | } |
86 | } |
87 | } |
88 | |
89 | /* |
90 | ```rust |
91 | let instance = TestCase::new().unwrap(); |
92 | |
93 | // Forward: |
94 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
95 | assert_eq!(instance.get_result(), ""); |
96 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
97 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
98 | assert_eq!(instance.get_result(), "T:"); |
99 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
100 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
101 | assert_eq!(instance.get_result(), "T:1.456:"); |
102 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
103 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
104 | assert_eq!(instance.get_result(), "T:1.456:2.0:"); |
105 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
106 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
107 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:"); |
108 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
109 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
110 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:"); |
111 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
112 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
113 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:"); |
114 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
115 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
116 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:T:"); |
117 | |
118 | // Backwards: |
119 | instance.set_result("".into()); |
120 | assert_eq!(instance.get_result(), ""); |
121 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
122 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
123 | assert_eq!(instance.get_result(), "B:"); |
124 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
125 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
126 | assert_eq!(instance.get_result(), "B:2.1:"); |
127 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
128 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
129 | assert_eq!(instance.get_result(), "B:2.1:1.789:"); |
130 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
131 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
132 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:"); |
133 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
134 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
135 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:"); |
136 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
137 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
138 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:"); |
139 | slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}"); |
140 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
141 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:B:"); |
142 | ``` |
143 | |
144 | ```cpp |
145 | auto handle = TestCase::create(); |
146 | const TestCase &instance = *handle; |
147 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
148 | assert_eq(instance.get_result(), ""); |
149 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
150 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
151 | assert_eq(instance.get_result(), "T:"); |
152 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
153 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
154 | assert_eq(instance.get_result(), "T:1.456:"); |
155 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
156 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
157 | assert_eq(instance.get_result(), "T:1.456:2.0:"); |
158 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
159 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
160 | assert_eq(instance.get_result(), "T:1.456:2.0:1.789:"); |
161 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
162 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
163 | assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:"); |
164 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
165 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
166 | assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:"); |
167 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
168 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
169 | assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:T:"); |
170 | |
171 | // Backwards: |
172 | instance.set_result(""); |
173 | assert_eq(instance.get_result(), ""); |
174 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
175 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
176 | assert_eq(instance.get_result(), "B:"); |
177 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
178 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
179 | assert_eq(instance.get_result(), "B:2.1:"); |
180 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
181 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
182 | assert_eq(instance.get_result(), "B:2.1:1.789:"); |
183 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
184 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
185 | assert_eq(instance.get_result(), "B:2.1:1.789:2.0:"); |
186 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
187 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
188 | assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:"); |
189 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
190 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
191 | assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:"); |
192 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
193 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
194 | assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:B:"); |
195 | ``` |
196 | |
197 | ```js |
198 | var instance = new slint.TestCase(); |
199 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
200 | assert.equal(instance.result, ""); |
201 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
202 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
203 | assert.equal(instance.result, "T:"); |
204 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
205 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
206 | assert.equal(instance.result, "T:1.456:"); |
207 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
208 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
209 | assert.equal(instance.result, "T:1.456:2.0:"); |
210 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
211 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
212 | assert.equal(instance.result, "T:1.456:2.0:1.789:"); |
213 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
214 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
215 | assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:"); |
216 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
217 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
218 | assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:B:"); |
219 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
220 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
221 | assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:B:T:"); |
222 | |
223 | // Backwards: |
224 | instance.result = ""; |
225 | assert.equal(instance.result, ""); |
226 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
227 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
228 | assert.equal(instance.result, "B:"); |
229 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
230 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
231 | assert.equal(instance.result, "B:2.1:"); |
232 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
233 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
234 | assert.equal(instance.result, "B:2.1:1.789:"); |
235 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
236 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
237 | assert.equal(instance.result, "B:2.1:1.789:2.0:"); |
238 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
239 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
240 | assert.equal(instance.result, "B:2.1:1.789:2.0:1.456:"); |
241 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
242 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
243 | assert.equal(instance.result, "B:2.1:1.789:2.0:1.456:T:"); |
244 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
245 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
246 | assert.equal(instance.result, "B:2.1:1.789:2.0:1.456:T:B:"); |
247 | ``` |
248 | */ |
249 | } |
250 | |
251 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
252 | use i_slint_backend_testing as slint_testing; |
253 | slint_testing::init(); |
254 | let instance = TestCase::new().unwrap(); |
255 | |
256 | // Forward: |
257 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
258 | assert_eq!(instance.get_result(), "" ); |
259 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
260 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
261 | assert_eq!(instance.get_result(), "T:" ); |
262 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
263 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
264 | assert_eq!(instance.get_result(), "T:1.456:" ); |
265 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
266 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
267 | assert_eq!(instance.get_result(), "T:1.456:2.0:" ); |
268 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
269 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
270 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:" ); |
271 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
272 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
273 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:" ); |
274 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
275 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
276 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:" ); |
277 | slint_testing::send_keyboard_string_sequence(&instance, " \t" ); |
278 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
279 | assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:T:" ); |
280 | |
281 | // Backwards: |
282 | instance.set_result("" .into()); |
283 | assert_eq!(instance.get_result(), "" ); |
284 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
285 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
286 | assert_eq!(instance.get_result(), "B:" ); |
287 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
288 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
289 | assert_eq!(instance.get_result(), "B:2.1:" ); |
290 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
291 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
292 | assert_eq!(instance.get_result(), "B:2.1:1.789:" ); |
293 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
294 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
295 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:" ); |
296 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
297 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
298 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:" ); |
299 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
300 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
301 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:" ); |
302 | slint_testing::send_keyboard_string_sequence(&instance, " \u{0019}" ); |
303 | slint_testing::send_keyboard_string_sequence(&instance, "X" ); |
304 | assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:B:" ); |
305 | Ok(()) |
306 | } |