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 | let instance = TestCase::new().unwrap(); |
19 | slint_testing::send_mouse_click(&instance, 50., 50.); |
20 | assert!(instance.get_input_focused()); |
21 | assert_eq!(instance.get_test_text(), ""); |
22 | slint_testing::send_keyboard_string_sequence(&instance, "Test"); |
23 | assert_eq!(instance.get_test_text(), "Test"); |
24 | assert!(!instance.get_has_selection()); |
25 | |
26 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
27 | slint_testing::send_keyboard_string_sequence(&instance, "a"); |
28 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true); |
29 | assert!(instance.get_has_selection()); |
30 | assert_eq!(instance.get_test_cursor_pos(), 4); |
31 | assert_eq!(instance.get_test_anchor_pos(), 0); |
32 | ``` |
33 | */ |
34 | } |
35 | |
36 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
37 | use i_slint_backend_testing as slint_testing; |
38 | slint_testing::init(); |
39 | |
40 | let instance = TestCase::new().unwrap(); |
41 | slint_testing::send_mouse_click(&instance, x:50., y:50.); |
42 | assert!(instance.get_input_focused()); |
43 | assert_eq!(instance.get_test_text(), "" ); |
44 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"Test" ); |
45 | assert_eq!(instance.get_test_text(), "Test" ); |
46 | assert!(!instance.get_has_selection()); |
47 | |
48 | slint_testing::send_keyboard_char(&instance, string:slint::private_unstable_api::re_exports::Key::Control.into(), pressed:true); |
49 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"a" ); |
50 | slint_testing::send_keyboard_char(&instance, string:slint::private_unstable_api::re_exports::Key::Control.into(), pressed:true); |
51 | assert!(instance.get_has_selection()); |
52 | assert_eq!(instance.get_test_cursor_pos(), 4); |
53 | assert_eq!(instance.get_test_anchor_pos(), 0); |
54 | Ok(()) |
55 | } |