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
5import { SpinBox, LineEdit, HorizontalBox, VerticalBox, TabWidget } from "std-widgets.slint";
6
7TestCase := 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
91let instance = TestCase::new().unwrap();
92
93// Forward:
94slint_testing::send_keyboard_string_sequence(&instance, "X");
95assert_eq!(instance.get_result(), "");
96slint_testing::send_keyboard_string_sequence(&instance, "\t");
97slint_testing::send_keyboard_string_sequence(&instance, "X");
98assert_eq!(instance.get_result(), "T:");
99slint_testing::send_keyboard_string_sequence(&instance, "\t");
100slint_testing::send_keyboard_string_sequence(&instance, "X");
101assert_eq!(instance.get_result(), "T:1.456:");
102slint_testing::send_keyboard_string_sequence(&instance, "\t");
103slint_testing::send_keyboard_string_sequence(&instance, "X");
104assert_eq!(instance.get_result(), "T:1.456:2.0:");
105slint_testing::send_keyboard_string_sequence(&instance, "\t");
106slint_testing::send_keyboard_string_sequence(&instance, "X");
107assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:");
108slint_testing::send_keyboard_string_sequence(&instance, "\t");
109slint_testing::send_keyboard_string_sequence(&instance, "X");
110assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:");
111slint_testing::send_keyboard_string_sequence(&instance, "\t");
112slint_testing::send_keyboard_string_sequence(&instance, "X");
113assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:");
114slint_testing::send_keyboard_string_sequence(&instance, "\t");
115slint_testing::send_keyboard_string_sequence(&instance, "X");
116assert_eq!(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:T:");
117
118// Backwards:
119instance.set_result("".into());
120assert_eq!(instance.get_result(), "");
121slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
122slint_testing::send_keyboard_string_sequence(&instance, "X");
123assert_eq!(instance.get_result(), "B:");
124slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
125slint_testing::send_keyboard_string_sequence(&instance, "X");
126assert_eq!(instance.get_result(), "B:2.1:");
127slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
128slint_testing::send_keyboard_string_sequence(&instance, "X");
129assert_eq!(instance.get_result(), "B:2.1:1.789:");
130slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
131slint_testing::send_keyboard_string_sequence(&instance, "X");
132assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:");
133slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
134slint_testing::send_keyboard_string_sequence(&instance, "X");
135assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:");
136slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
137slint_testing::send_keyboard_string_sequence(&instance, "X");
138assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:");
139slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
140slint_testing::send_keyboard_string_sequence(&instance, "X");
141assert_eq!(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:B:");
142```
143
144```cpp
145auto handle = TestCase::create();
146const TestCase &instance = *handle;
147slint_testing::send_keyboard_string_sequence(&instance, "X");
148assert_eq(instance.get_result(), "");
149slint_testing::send_keyboard_string_sequence(&instance, "\t");
150slint_testing::send_keyboard_string_sequence(&instance, "X");
151assert_eq(instance.get_result(), "T:");
152slint_testing::send_keyboard_string_sequence(&instance, "\t");
153slint_testing::send_keyboard_string_sequence(&instance, "X");
154assert_eq(instance.get_result(), "T:1.456:");
155slint_testing::send_keyboard_string_sequence(&instance, "\t");
156slint_testing::send_keyboard_string_sequence(&instance, "X");
157assert_eq(instance.get_result(), "T:1.456:2.0:");
158slint_testing::send_keyboard_string_sequence(&instance, "\t");
159slint_testing::send_keyboard_string_sequence(&instance, "X");
160assert_eq(instance.get_result(), "T:1.456:2.0:1.789:");
161slint_testing::send_keyboard_string_sequence(&instance, "\t");
162slint_testing::send_keyboard_string_sequence(&instance, "X");
163assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:");
164slint_testing::send_keyboard_string_sequence(&instance, "\t");
165slint_testing::send_keyboard_string_sequence(&instance, "X");
166assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:");
167slint_testing::send_keyboard_string_sequence(&instance, "\t");
168slint_testing::send_keyboard_string_sequence(&instance, "X");
169assert_eq(instance.get_result(), "T:1.456:2.0:1.789:2.1:B:T:");
170
171// Backwards:
172instance.set_result("");
173assert_eq(instance.get_result(), "");
174slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
175slint_testing::send_keyboard_string_sequence(&instance, "X");
176assert_eq(instance.get_result(), "B:");
177slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
178slint_testing::send_keyboard_string_sequence(&instance, "X");
179assert_eq(instance.get_result(), "B:2.1:");
180slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
181slint_testing::send_keyboard_string_sequence(&instance, "X");
182assert_eq(instance.get_result(), "B:2.1:1.789:");
183slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
184slint_testing::send_keyboard_string_sequence(&instance, "X");
185assert_eq(instance.get_result(), "B:2.1:1.789:2.0:");
186slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
187slint_testing::send_keyboard_string_sequence(&instance, "X");
188assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:");
189slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
190slint_testing::send_keyboard_string_sequence(&instance, "X");
191assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:");
192slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
193slint_testing::send_keyboard_string_sequence(&instance, "X");
194assert_eq(instance.get_result(), "B:2.1:1.789:2.0:1.456:T:B:");
195```
196
197```js
198var instance = new slint.TestCase();
199slintlib.private_api.send_keyboard_string_sequence(instance, "X");
200assert.equal(instance.result, "");
201slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
202slintlib.private_api.send_keyboard_string_sequence(instance, "X");
203assert.equal(instance.result, "T:");
204slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
205slintlib.private_api.send_keyboard_string_sequence(instance, "X");
206assert.equal(instance.result, "T:1.456:");
207slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
208slintlib.private_api.send_keyboard_string_sequence(instance, "X");
209assert.equal(instance.result, "T:1.456:2.0:");
210slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
211slintlib.private_api.send_keyboard_string_sequence(instance, "X");
212assert.equal(instance.result, "T:1.456:2.0:1.789:");
213slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
214slintlib.private_api.send_keyboard_string_sequence(instance, "X");
215assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:");
216slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
217slintlib.private_api.send_keyboard_string_sequence(instance, "X");
218assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:B:");
219slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
220slintlib.private_api.send_keyboard_string_sequence(instance, "X");
221assert.equal(instance.result, "T:1.456:2.0:1.789:2.1:B:T:");
222
223// Backwards:
224instance.result = "";
225assert.equal(instance.result, "");
226slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
227slintlib.private_api.send_keyboard_string_sequence(instance, "X");
228assert.equal(instance.result, "B:");
229slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
230slintlib.private_api.send_keyboard_string_sequence(instance, "X");
231assert.equal(instance.result, "B:2.1:");
232slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
233slintlib.private_api.send_keyboard_string_sequence(instance, "X");
234assert.equal(instance.result, "B:2.1:1.789:");
235slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
236slintlib.private_api.send_keyboard_string_sequence(instance, "X");
237assert.equal(instance.result, "B:2.1:1.789:2.0:");
238slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
239slintlib.private_api.send_keyboard_string_sequence(instance, "X");
240assert.equal(instance.result, "B:2.1:1.789:2.0:1.456:");
241slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
242slintlib.private_api.send_keyboard_string_sequence(instance, "X");
243assert.equal(instance.result, "B:2.1:1.789:2.0:1.456:T:");
244slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
245slintlib.private_api.send_keyboard_string_sequence(instance, "X");
246assert.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}