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: 120phx; |
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::Key, 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(10.0, 6.0), button: PointerEventButton::Left }); |
28 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
29 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
30 | assert!(instance.get_has_selection()); |
31 | assert_eq!(instance.get_test_cursor_pos(), 5); |
32 | assert_eq!(instance.get_test_anchor_pos(), 0); |
33 | slint_testing::send_keyboard_string_sequence(&instance, "-"); |
34 | assert_eq!(instance.get_test_text(), "- World"); |
35 | |
36 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
37 | slint_testing::mock_elapsed_time(1600); |
38 | |
39 | instance.set_test_text("Lorem Ipsum Dolor Sit::amet".into()); |
40 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
41 | slint_testing::mock_elapsed_time(100); |
42 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
43 | slint_testing::mock_elapsed_time(100); |
44 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
45 | assert_eq!(instance.get_test_anchor_pos(), 6); |
46 | assert_eq!(instance.get_test_cursor_pos(), 11); |
47 | slint_testing::mock_elapsed_time(1000); |
48 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 6.0) }); |
49 | assert_eq!(instance.get_test_anchor_pos(), 11); |
50 | assert_eq!(instance.get_test_cursor_pos(), 0); |
51 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(190.0, 6.0) }); |
52 | assert_eq!(instance.get_test_anchor_pos(), 6); |
53 | assert_eq!(instance.get_test_cursor_pos(), 21); |
54 | |
55 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
56 | slint_testing::mock_elapsed_time(1000); |
57 | |
58 | slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), true); |
59 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left }); |
60 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left }); |
61 | slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), false); |
62 | assert_eq!(instance.get_test_anchor_pos(), 6); |
63 | assert_eq!(instance.get_test_cursor_pos(), 3); |
64 | |
65 | |
66 | |
67 | ``` |
68 | */ |
69 | } |
70 | |
71 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
72 | use i_slint_backend_testing as slint_testing; |
73 | slint_testing::init(); |
74 | use slint::{platform::WindowEvent, platform::Key, platform::PointerEventButton, LogicalPosition}; |
75 | |
76 | let instance = TestCase::new().unwrap(); |
77 | // slint_testing::send_mouse_click(&instance, 50., 50.); |
78 | assert!(instance.get_input_focused()); |
79 | assert_eq!(instance.get_test_text(), "" ); |
80 | slint_testing::send_keyboard_string_sequence(&instance, "Hello World" ); |
81 | assert_eq!(instance.get_test_text(), "Hello World" ); |
82 | assert!(!instance.get_has_selection()); |
83 | |
84 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
85 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
86 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
87 | assert!(instance.get_has_selection()); |
88 | assert_eq!(instance.get_test_cursor_pos(), 5); |
89 | assert_eq!(instance.get_test_anchor_pos(), 0); |
90 | slint_testing::send_keyboard_string_sequence(&instance, "-" ); |
91 | assert_eq!(instance.get_test_text(), "- World" ); |
92 | |
93 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left }); |
94 | slint_testing::mock_elapsed_time(1600); |
95 | |
96 | instance.set_test_text("Lorem Ipsum Dolor Sit::amet" .into()); |
97 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
98 | slint_testing::mock_elapsed_time(100); |
99 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
100 | slint_testing::mock_elapsed_time(100); |
101 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
102 | assert_eq!(instance.get_test_anchor_pos(), 6); |
103 | assert_eq!(instance.get_test_cursor_pos(), 11); |
104 | slint_testing::mock_elapsed_time(1000); |
105 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 6.0) }); |
106 | assert_eq!(instance.get_test_anchor_pos(), 11); |
107 | assert_eq!(instance.get_test_cursor_pos(), 0); |
108 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(190.0, 6.0) }); |
109 | assert_eq!(instance.get_test_anchor_pos(), 6); |
110 | assert_eq!(instance.get_test_cursor_pos(), 21); |
111 | |
112 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
113 | slint_testing::mock_elapsed_time(1000); |
114 | |
115 | slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), true); |
116 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left }); |
117 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left }); |
118 | slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), false); |
119 | assert_eq!(instance.get_test_anchor_pos(), 6); |
120 | assert_eq!(instance.get_test_cursor_pos(), 3); |
121 | |
122 | |
123 | |
124 | Ok(()) |
125 | } |