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 | TestCase := Window { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | FocusScope { |
9 | key-pressed(event) => { |
10 | r1 += event.text; |
11 | return event.text == "a" ? accept : reject; |
12 | } |
13 | |
14 | FocusScope { |
15 | key-pressed(event) => { |
16 | r2 += event.text; |
17 | return event.text == "b" ? accept : reject; |
18 | } |
19 | Rectangle { |
20 | FocusScope { |
21 | key-pressed(event) => { |
22 | r3 += event.text; |
23 | return event.text == "c" ? accept : reject; |
24 | } |
25 | |
26 | if (toggle) : FocusScope { |
27 | key-pressed(event) => { |
28 | r4 += event.text; |
29 | return event.text == "d" ? accept : reject; |
30 | } |
31 | FocusScope { |
32 | key-pressed(event) => { |
33 | r5 += event.text; |
34 | return event.text == "e" ? accept : reject; |
35 | } |
36 | TouchArea { |
37 | clicked => { |
38 | parent.focus(); |
39 | } |
40 | } |
41 | } |
42 | } |
43 | } |
44 | } |
45 | } |
46 | } |
47 | |
48 | property<bool> toggle: true; |
49 | property<string> r1; |
50 | property<string> r2; |
51 | property<string> r3; |
52 | property<string> r4; |
53 | property<string> r5; |
54 | } |
55 | |
56 | /* |
57 | ```rust |
58 | let instance = TestCase::new().unwrap(); |
59 | slint_testing::send_mouse_click(&instance, 50., 50.); |
60 | slint_testing::send_keyboard_string_sequence(&instance, "__abcdefghij__"); |
61 | assert_eq!(instance.get_r1(), "__afghij__"); |
62 | assert_eq!(instance.get_r2(), "__abfghij__"); |
63 | assert_eq!(instance.get_r3(), "__abcfghij__"); |
64 | assert_eq!(instance.get_r4(), "__abcdfghij__"); |
65 | assert_eq!(instance.get_r5(), "__abcdefghij__"); |
66 | ``` |
67 | |
68 | ```cpp |
69 | auto handle = TestCase::create(); |
70 | const TestCase &instance = *handle; |
71 | slint_testing::send_mouse_click(&instance, 50., 50.); |
72 | slint_testing::send_keyboard_string_sequence(&instance, "__abcdefghij__"); |
73 | assert_eq(instance.get_r1(), "__afghij__"); |
74 | assert_eq(instance.get_r2(), "__abfghij__"); |
75 | assert_eq(instance.get_r3(), "__abcfghij__"); |
76 | assert_eq(instance.get_r4(), "__abcdfghij__"); |
77 | assert_eq(instance.get_r5(), "__abcdefghij__"); |
78 | ``` |
79 | |
80 | ```js |
81 | var instance = new slint.TestCase(); |
82 | slintlib.private_api.send_mouse_click(instance, 50., 50.); |
83 | slintlib.private_api.send_keyboard_string_sequence(instance, "__abcdefghij__"); |
84 | assert.equal(instance.r1, "__afghij__"); |
85 | assert.equal(instance.r2, "__abfghij__"); |
86 | assert.equal(instance.r3, "__abcfghij__"); |
87 | assert.equal(instance.r4, "__abcdfghij__"); |
88 | assert.equal(instance.r5, "__abcdefghij__"); |
89 | |
90 | ``` |
91 | */ |
92 | } |
93 | |
94 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
95 | use i_slint_backend_testing as slint_testing; |
96 | slint_testing::init(); |
97 | let instance = TestCase::new().unwrap(); |
98 | slint_testing::send_mouse_click(&instance, x:50., y:50.); |
99 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"__abcdefghij__" ); |
100 | assert_eq!(instance.get_r1(), "__afghij__" ); |
101 | assert_eq!(instance.get_r2(), "__abfghij__" ); |
102 | assert_eq!(instance.get_r3(), "__abcfghij__" ); |
103 | assert_eq!(instance.get_r4(), "__abcdfghij__" ); |
104 | assert_eq!(instance.get_r5(), "__abcdefghij__" ); |
105 | Ok(()) |
106 | } |