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// cSpell: ignore backtab
6
7import { VerticalBox, ListView } from "std-widgets.slint";
8
9TestCase := Window {
10 width: 500px;
11 height: 400px;
12
13 property <[string]> features : [ "f" ];
14 property <string> result;
15
16 VerticalBox {
17 VerticalBox {
18 if true: ListView {
19 for f in features: FocusScope {
20 key-pressed(event) => {
21 if (event.text == "X") {
22 result += "1:";
23 return accept;
24 }
25 return reject;
26 }
27 }
28 }
29 if false: Rectangle { }
30 }
31 FocusScope {
32 key-pressed(event) => {
33 if (event.text == "X") {
34 result += "2:";
35 return accept;
36 }
37 return reject;
38 }
39 }
40 }
41}
42
43/*
44```rust
45let instance = TestCase::new().unwrap();
46
47// Forward:
48slint_testing::send_keyboard_string_sequence(&instance, "X");
49assert_eq!(instance.get_result(), "");
50slint_testing::send_keyboard_string_sequence(&instance, "\t");
51slint_testing::send_keyboard_string_sequence(&instance, "X");
52assert_eq!(instance.get_result(), "1:", "one tab");
53slint_testing::send_keyboard_string_sequence(&instance, "\t");
54slint_testing::send_keyboard_string_sequence(&instance, "X");
55assert_eq!(instance.get_result(), "1:2:", "two tab");
56slint_testing::send_keyboard_string_sequence(&instance, "\t");
57slint_testing::send_keyboard_string_sequence(&instance, "X");
58assert_eq!(instance.get_result(), "1:2:1:", "three tab");
59
60instance.set_result("".into());
61
62// Backwards:
63slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
64slint_testing::send_keyboard_string_sequence(&instance, "X");
65assert_eq!(instance.get_result(), "2:", "one backtab");
66slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
67slint_testing::send_keyboard_string_sequence(&instance, "X");
68assert_eq!(instance.get_result(), "2:1:", "two backtab");
69slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
70slint_testing::send_keyboard_string_sequence(&instance, "X");
71assert_eq!(instance.get_result(), "2:1:2:", "three backtab");
72```
73
74```cpp
75auto handle = TestCase::create();
76const TestCase &instance = *handle;
77
78// Forward:
79slint_testing::send_keyboard_string_sequence(&instance, "X");
80assert_eq(instance.get_result(), "");
81slint_testing::send_keyboard_string_sequence(&instance, "\t");
82slint_testing::send_keyboard_string_sequence(&instance, "X");
83assert_eq(instance.get_result(), "1:");
84slint_testing::send_keyboard_string_sequence(&instance, "\t");
85slint_testing::send_keyboard_string_sequence(&instance, "X");
86assert_eq(instance.get_result(), "1:2:");
87slint_testing::send_keyboard_string_sequence(&instance, "\t");
88slint_testing::send_keyboard_string_sequence(&instance, "X");
89assert_eq(instance.get_result(), "1:2:1:");
90
91instance.set_result("");
92
93// Backwards:
94slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
95slint_testing::send_keyboard_string_sequence(&instance, "X");
96assert_eq(instance.get_result(), "2:");
97slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
98slint_testing::send_keyboard_string_sequence(&instance, "X");
99assert_eq(instance.get_result(), "2:1:");
100slint_testing::send_keyboard_string_sequence(&instance, "\u0019");
101slint_testing::send_keyboard_string_sequence(&instance, "X");
102assert_eq(instance.get_result(), "2:1:2:");
103```
104
105```js
106var instance = new slint.TestCase();
107
108// Forward:
109slintlib.private_api.send_keyboard_string_sequence(instance, "X");
110assert.equal(instance.result, "");
111slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
112slintlib.private_api.send_keyboard_string_sequence(instance, "X");
113assert.equal(instance.result, "1:");
114slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
115slintlib.private_api.send_keyboard_string_sequence(instance, "X");
116assert.equal(instance.result, "1:2:");
117slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
118slintlib.private_api.send_keyboard_string_sequence(instance, "X");
119assert.equal(instance.result, "1:2:1:");
120
121// Backwards:
122instance.result = "";
123assert.equal(instance.result, "");
124slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
125slintlib.private_api.send_keyboard_string_sequence(instance, "X");
126assert.equal(instance.result, "2:");
127slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
128slintlib.private_api.send_keyboard_string_sequence(instance, "X");
129assert.equal(instance.result, "2:1:");
130slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019");
131slintlib.private_api.send_keyboard_string_sequence(instance, "X");
132assert.equal(instance.result, "2:1:2:");
133```
134*/
135}
136
137#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
138 use i_slint_backend_testing as slint_testing;
139 slint_testing::init();
140 let instance = TestCase::new().unwrap();
141
142 // Forward:
143 slint_testing::send_keyboard_string_sequence(&instance, "X");
144 assert_eq!(instance.get_result(), "");
145 slint_testing::send_keyboard_string_sequence(&instance, "\t");
146 slint_testing::send_keyboard_string_sequence(&instance, "X");
147 assert_eq!(instance.get_result(), "1:", "one tab");
148 slint_testing::send_keyboard_string_sequence(&instance, "\t");
149 slint_testing::send_keyboard_string_sequence(&instance, "X");
150 assert_eq!(instance.get_result(), "1:2:", "two tab");
151 slint_testing::send_keyboard_string_sequence(&instance, "\t");
152 slint_testing::send_keyboard_string_sequence(&instance, "X");
153 assert_eq!(instance.get_result(), "1:2:1:", "three tab");
154
155 instance.set_result("".into());
156
157 // Backwards:
158 slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
159 slint_testing::send_keyboard_string_sequence(&instance, "X");
160 assert_eq!(instance.get_result(), "2:", "one backtab");
161 slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
162 slint_testing::send_keyboard_string_sequence(&instance, "X");
163 assert_eq!(instance.get_result(), "2:1:", "two backtab");
164 slint_testing::send_keyboard_string_sequence(&instance, "\u{19}");
165 slint_testing::send_keyboard_string_sequence(&instance, "X");
166 assert_eq!(instance.get_result(), "2:1:2:", "three backtab");
167 Ok(())
168}