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 | |
7 | import { VerticalBox, ListView } from "std-widgets.slint" ; |
8 | |
9 | TestCase := 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 |
45 | let instance = TestCase::new().unwrap(); |
46 | |
47 | // Forward: |
48 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
49 | assert_eq!(instance.get_result(), ""); |
50 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
51 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
52 | assert_eq!(instance.get_result(), "1:", "one tab"); |
53 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
54 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
55 | assert_eq!(instance.get_result(), "1:2:", "two tab"); |
56 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
57 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
58 | assert_eq!(instance.get_result(), "1:2:1:", "three tab"); |
59 | |
60 | instance.set_result("".into()); |
61 | |
62 | // Backwards: |
63 | slint_testing::send_keyboard_string_sequence(&instance, "\u{19}"); |
64 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
65 | assert_eq!(instance.get_result(), "2:", "one backtab"); |
66 | slint_testing::send_keyboard_string_sequence(&instance, "\u{19}"); |
67 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
68 | assert_eq!(instance.get_result(), "2:1:", "two backtab"); |
69 | slint_testing::send_keyboard_string_sequence(&instance, "\u{19}"); |
70 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
71 | assert_eq!(instance.get_result(), "2:1:2:", "three backtab"); |
72 | ``` |
73 | |
74 | ```cpp |
75 | auto handle = TestCase::create(); |
76 | const TestCase &instance = *handle; |
77 | |
78 | // Forward: |
79 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
80 | assert_eq(instance.get_result(), ""); |
81 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
82 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
83 | assert_eq(instance.get_result(), "1:"); |
84 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
85 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
86 | assert_eq(instance.get_result(), "1:2:"); |
87 | slint_testing::send_keyboard_string_sequence(&instance, "\t"); |
88 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
89 | assert_eq(instance.get_result(), "1:2:1:"); |
90 | |
91 | instance.set_result(""); |
92 | |
93 | // Backwards: |
94 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
95 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
96 | assert_eq(instance.get_result(), "2:"); |
97 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
98 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
99 | assert_eq(instance.get_result(), "2:1:"); |
100 | slint_testing::send_keyboard_string_sequence(&instance, "\u0019"); |
101 | slint_testing::send_keyboard_string_sequence(&instance, "X"); |
102 | assert_eq(instance.get_result(), "2:1:2:"); |
103 | ``` |
104 | |
105 | ```js |
106 | var instance = new slint.TestCase(); |
107 | |
108 | // Forward: |
109 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
110 | assert.equal(instance.result, ""); |
111 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
112 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
113 | assert.equal(instance.result, "1:"); |
114 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
115 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
116 | assert.equal(instance.result, "1:2:"); |
117 | slintlib.private_api.send_keyboard_string_sequence(instance, "\t"); |
118 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
119 | assert.equal(instance.result, "1:2:1:"); |
120 | |
121 | // Backwards: |
122 | instance.result = ""; |
123 | assert.equal(instance.result, ""); |
124 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
125 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
126 | assert.equal(instance.result, "2:"); |
127 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
128 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
129 | assert.equal(instance.result, "2:1:"); |
130 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u0019"); |
131 | slintlib.private_api.send_keyboard_string_sequence(instance, "X"); |
132 | assert.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 | } |