1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/text"# ] |
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 := TextInput { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | property<string> test_text: self.text; |
9 | property<int> test_cursor_pos: self.cursor_position_byte_offset; |
10 | property<int> test_anchor_pos: self.anchor_position_byte_offset; |
11 | property<bool> has_selection: self.test_cursor_pos != self.test_anchor_pos; |
12 | property<bool> input_focused: self.has_focus; |
13 | } |
14 | |
15 | /* |
16 | ```rust |
17 | |
18 | const LEFT_CODE: char = '\u{F702}'; |
19 | |
20 | let instance = TestCase::new().unwrap(); |
21 | slint_testing::send_mouse_click(&instance, 50., 50.); |
22 | assert!(instance.get_input_focused()); |
23 | assert_eq!(instance.get_test_text(), ""); |
24 | slint_testing::send_keyboard_string_sequence(&instance, "Test"); |
25 | assert_eq!(instance.get_test_text(), "Test"); |
26 | assert!(!instance.get_has_selection()); |
27 | |
28 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
29 | slint_testing::send_keyboard_string_sequence(&instance, "a"); |
30 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false); |
31 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true); |
32 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
33 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
34 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false); |
35 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
36 | slint_testing::send_keyboard_string_sequence(&instance, "x"); |
37 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false); |
38 | assert!(!instance.get_has_selection()); |
39 | assert_eq!(instance.get_test_text(), "st"); |
40 | assert_eq!(instance.get_test_cursor_pos(), 0); |
41 | ``` |
42 | */ |
43 | } |
44 | |
45 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
46 | use i_slint_backend_testing as slint_testing; |
47 | slint_testing::init(); |
48 | |
49 | const LEFT_CODE: char = ' \u{F702}' ; |
50 | |
51 | let instance = TestCase::new().unwrap(); |
52 | slint_testing::send_mouse_click(&instance, 50., 50.); |
53 | assert!(instance.get_input_focused()); |
54 | assert_eq!(instance.get_test_text(), "" ); |
55 | slint_testing::send_keyboard_string_sequence(&instance, "Test" ); |
56 | assert_eq!(instance.get_test_text(), "Test" ); |
57 | assert!(!instance.get_has_selection()); |
58 | |
59 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
60 | slint_testing::send_keyboard_string_sequence(&instance, "a" ); |
61 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false); |
62 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true); |
63 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
64 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
65 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false); |
66 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
67 | slint_testing::send_keyboard_string_sequence(&instance, "x" ); |
68 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false); |
69 | assert!(!instance.get_has_selection()); |
70 | assert_eq!(instance.get_test_text(), "st" ); |
71 | assert_eq!(instance.get_test_cursor_pos(), 0); |
72 | Ok(()) |
73 | } |