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 := Window {
6 width: 100phx;
7 height: 100phx;
8 ti := TextInput {
9 }
10
11 property <bool> input_focused: ti.has_focus;
12 property <string> text <=> ti.text;
13}
14
15/*
16```rust
17use slint::platform::Key;
18
19let instance = TestCase::new().unwrap();
20slint_testing::send_mouse_click(&instance, 5., 5.);
21assert!(instance.get_input_focused());
22assert!(instance.get_text().is_empty());
23
24for code in [Key::Shift, Key::ShiftR, Key::Alt, Key::AltGr, Key::Control, Key::ControlR, Key::Meta, Key::MetaR] {
25 slint_testing::send_keyboard_char(&instance, code.into(), true);
26 assert!(instance.get_text().is_empty());
27 slint_testing::send_keyboard_char(&instance, code.into(), false);
28 assert!(instance.get_text().is_empty());
29}
30
31slint_testing::send_keyboard_char(&instance, 'a', true);
32assert_eq!(instance.get_text(), "a");
33```
34*/
35}
36
37#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
38 use i_slint_backend_testing as slint_testing;
39 slint_testing::init();
40 use slint::platform::Key;
41
42 let instance = TestCase::new().unwrap();
43 slint_testing::send_mouse_click(&instance, x:5., y:5.);
44 assert!(instance.get_input_focused());
45 assert!(instance.get_text().is_empty());
46
47 for code: Key in [Key::Shift, Key::ShiftR, Key::Alt, Key::AltGr, Key::Control, Key::ControlR, Key::Meta, Key::MetaR] {
48 slint_testing::send_keyboard_char(&instance, string:code.into(), pressed:true);
49 assert!(instance.get_text().is_empty());
50 slint_testing::send_keyboard_char(&instance, string:code.into(), pressed:false);
51 assert!(instance.get_text().is_empty());
52 }
53
54 slint_testing::send_keyboard_char(&instance, string:'a', pressed:true);
55 assert_eq!(instance.get_text(), "a");
56 Ok(())
57}