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 | use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition}; |
18 | |
19 | let instance = TestCase::new().unwrap(); |
20 | slint_testing::send_mouse_click(&instance, 50., 50.); |
21 | assert!(instance.get_input_focused()); |
22 | assert_eq!(instance.get_test_text(), ""); |
23 | slint_testing::send_keyboard_string_sequence(&instance, "Hello World"); |
24 | assert_eq!(instance.get_test_text(), "Hello World"); |
25 | assert!(!instance.get_has_selection()); |
26 | |
27 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
28 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
29 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
30 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
31 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
32 | assert!(instance.get_has_selection()); |
33 | assert_eq!(instance.get_test_cursor_pos(), 11); |
34 | assert_eq!(instance.get_test_anchor_pos(), 0); |
35 | |
36 | slint_testing::send_keyboard_string_sequence(&instance, "-"); |
37 | assert_eq!(instance.get_test_text(), "-"); |
38 | ``` |
39 | */ |
40 | } |
41 | |
42 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
43 | use i_slint_backend_testing as slint_testing; |
44 | slint_testing::init(); |
45 | use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition}; |
46 | |
47 | let instance = TestCase::new().unwrap(); |
48 | slint_testing::send_mouse_click(&instance, 50., 50.); |
49 | assert!(instance.get_input_focused()); |
50 | assert_eq!(instance.get_test_text(), "" ); |
51 | slint_testing::send_keyboard_string_sequence(&instance, "Hello World" ); |
52 | assert_eq!(instance.get_test_text(), "Hello World" ); |
53 | assert!(!instance.get_has_selection()); |
54 | |
55 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
56 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
57 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
58 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
59 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(6.0, 0.0), button: PointerEventButton::Left }); |
60 | assert!(instance.get_has_selection()); |
61 | assert_eq!(instance.get_test_cursor_pos(), 11); |
62 | assert_eq!(instance.get_test_anchor_pos(), 0); |
63 | |
64 | slint_testing::send_keyboard_string_sequence(&instance, "-" ); |
65 | assert_eq!(instance.get_test_text(), "-" ); |
66 | Ok(()) |
67 | } |