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
5TestCase := 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
17use slint::{platform::WindowEvent, platform::Key, platform::PointerEventButton, LogicalPosition};
18
19let instance = TestCase::new().unwrap();
20// slint_testing::send_mouse_click(&instance, 50., 50.);
21assert!(instance.get_input_focused());
22assert_eq!(instance.get_test_text(), "");
23slint_testing::send_keyboard_string_sequence(&instance, "Hello World");
24assert_eq!(instance.get_test_text(), "Hello World");
25assert!(!instance.get_has_selection());
26
27instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left });
28instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left });
29instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left });
30assert!(instance.get_has_selection());
31assert_eq!(instance.get_test_cursor_pos(), 5);
32assert_eq!(instance.get_test_anchor_pos(), 0);
33slint_testing::send_keyboard_string_sequence(&instance, "-");
34assert_eq!(instance.get_test_text(), "- World");
35
36instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(10.0, 6.0), button: PointerEventButton::Left });
37slint_testing::mock_elapsed_time(1600);
38
39instance.set_test_text("Lorem Ipsum Dolor Sit::amet".into());
40instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left });
41slint_testing::mock_elapsed_time(100);
42instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left });
43slint_testing::mock_elapsed_time(100);
44instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left });
45assert_eq!(instance.get_test_anchor_pos(), 6);
46assert_eq!(instance.get_test_cursor_pos(), 11);
47slint_testing::mock_elapsed_time(1000);
48instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(30.0, 6.0) });
49assert_eq!(instance.get_test_anchor_pos(), 11);
50assert_eq!(instance.get_test_cursor_pos(), 0);
51instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(190.0, 6.0) });
52assert_eq!(instance.get_test_anchor_pos(), 6);
53assert_eq!(instance.get_test_cursor_pos(), 21);
54
55instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left });
56slint_testing::mock_elapsed_time(1000);
57
58slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), true);
59instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left });
60instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(33.0, 6.0), button: PointerEventButton::Left });
61slint_testing::send_keyboard_char(&instance, Key::ShiftR.into(), false);
62assert_eq!(instance.get_test_anchor_pos(), 6);
63assert_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}