mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Improve similarity of testing APIs between C++ and Rust
Let send_mouse_click also take a component reference, like in C++.
This commit is contained in:
parent
4670854500
commit
23d54b1b89
12 changed files with 34 additions and 33 deletions
|
@ -269,12 +269,13 @@ pub mod testing {
|
|||
/// Simulate a mouse click
|
||||
pub fn send_mouse_click<
|
||||
X: vtable::HasStaticVTable<sixtyfps_corelib::component::ComponentVTable> + HasWindow + 'static,
|
||||
Component: Into<vtable::VRc<sixtyfps_corelib::component::ComponentVTable, X>> + Clone,
|
||||
>(
|
||||
component: impl Into<vtable::VRc<sixtyfps_corelib::component::ComponentVTable, X>>,
|
||||
component: &Component,
|
||||
x: f32,
|
||||
y: f32,
|
||||
) {
|
||||
let rc = component.into();
|
||||
let rc = component.clone().into();
|
||||
let dyn_rc = vtable::VRc::into_dyn(rc.clone());
|
||||
sixtyfps_corelib::tests::sixtyfps_send_mouse_click(&dyn_rc, x, y, rc.component_window());
|
||||
}
|
||||
|
|
|
@ -52,17 +52,17 @@ assert_eq(instance.get_touch2(), 1);
|
|||
```rust
|
||||
let instance = TestCase::new();
|
||||
// does not click on anything
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_touch1(), 0);
|
||||
assert_eq!(instance.get_touch2(), 0);
|
||||
|
||||
// click on second one
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 101., 101.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 101., 101.);
|
||||
assert_eq!(instance.get_touch1(), 0);
|
||||
assert_eq!(instance.get_touch2(), 1);
|
||||
|
||||
// click on first one only
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 108., 108.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 108., 108.);
|
||||
assert_eq!(instance.get_touch1(), 1);
|
||||
assert_eq!(instance.get_touch2(), 1);
|
||||
```
|
||||
|
|
|
@ -34,7 +34,7 @@ let instance = TestCase::new();
|
|||
assert!(!instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 150., 100.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 150., 100.);
|
||||
assert!(instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
|
||||
|
@ -42,7 +42,7 @@ sixtyfps::testing::send_keyboard_string_sequence(&instance, "Only for field 1");
|
|||
assert_eq!(instance.get_input1_text(), "Only for field 1");
|
||||
assert_eq!(instance.get_input2_text(), "");
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 150., 300.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 150., 300.);
|
||||
assert!(!instance.get_input1_focused());
|
||||
assert!(instance.get_input2_focused());
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ sixtyfps::testing::send_keyboard_string_sequence(&instance, "Only for field 1");
|
|||
assert_eq!(instance.get_input1_text(), "Only for field 1");
|
||||
assert_eq!(instance.get_input2_text(), "");
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 150., 100.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 150., 100.);
|
||||
assert!(instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 150., 300.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 150., 300.);
|
||||
assert!(!instance.get_input1_focused());
|
||||
assert!(instance.get_input2_focused());
|
||||
```
|
||||
|
|
|
@ -54,14 +54,14 @@ assert_eq(instance.get_value(), 1+1+2);
|
|||
```rust
|
||||
let instance = TestCase::new();
|
||||
use sixtyfps::re_exports::Component;
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), -1., -1.); // FIXME: Force creation of repeater components before computing the layout
|
||||
sixtyfps::testing::send_mouse_click(&instance, -1., -1.); // FIXME: Force creation of repeater components before computing the layout
|
||||
|
||||
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 190., 190.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 190., 190.);
|
||||
assert_eq!(instance.get_value(), 1+1);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 290.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 290.);
|
||||
assert_eq!(instance.get_value(), 1+1+2);
|
||||
|
||||
```
|
||||
|
|
|
@ -57,13 +57,13 @@ assert_eq(instance.get_value(), 9);
|
|||
```rust
|
||||
let instance = TestCase::new();
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_value(), -10);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 25., 25.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 25., 25.);
|
||||
assert_eq!(instance.get_value(), 8);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 45., 15.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 45., 15.);
|
||||
assert_eq!(instance.get_value(), 9);
|
||||
|
||||
```
|
||||
|
|
|
@ -109,13 +109,13 @@ assert_eq(instance.get_value(), 13+42);
|
|||
```rust
|
||||
let instance = TestCase::new();
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_value(), 10);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 15.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 15.);
|
||||
assert_eq!(instance.get_value(), 13);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 15.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 15.);
|
||||
assert_eq!(instance.get_value(), 13+42);
|
||||
|
||||
```
|
||||
|
|
|
@ -57,15 +57,15 @@ assert_eq(instance.get_top_level(), 92);
|
|||
```rust
|
||||
let instance = TestCase::new();
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_top_level(), 42);
|
||||
|
||||
instance.set_cond1(true);
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_top_level(), 92);
|
||||
|
||||
instance.set_cond1(false);
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 5., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||
assert_eq!(instance.get_top_level(), 92);
|
||||
```
|
||||
|
||||
|
|
|
@ -53,11 +53,11 @@ TestCase := Rectangle {
|
|||
let instance = TestCase::new();
|
||||
|
||||
// there should be nothing there
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 25., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 0);
|
||||
assert_eq!(instance.get_clicked_internal_state(), 0);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 789000);
|
||||
assert_eq!(instance.get_clicked_internal_state(), 1);
|
||||
|
||||
|
@ -71,32 +71,32 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::<ModelData>::from(
|
|||
|
||||
instance.set_model(sixtyfps::ModelHandle::new(another_model.clone()));
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 25., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 333000);
|
||||
assert_eq!(instance.get_clicked_internal_state(), 1);
|
||||
assert_eq!(instance.get_clicked_index(), 2);
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 222000);
|
||||
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("cruel"));
|
||||
assert_eq!(instance.get_clicked_internal_state(), 1);
|
||||
|
||||
another_model.push(("a4".into(), "!".into(), 444.));
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 35., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 35., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 444000);
|
||||
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("!"));
|
||||
assert_eq!(instance.get_clicked_internal_state(), 1);
|
||||
|
||||
use sixtyfps::Model;
|
||||
another_model.set_row_data(1, ("a2".into(), "idyllic".into(), 555.));
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 555000);
|
||||
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("idyllic"));
|
||||
assert_eq!(instance.get_clicked_internal_state(), 2);
|
||||
assert_eq!(instance.get_clicked_index(), 1);
|
||||
|
||||
another_model.remove(1);
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 333000);
|
||||
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("world"));
|
||||
assert_eq!(instance.get_clicked_internal_state(), 2);
|
||||
|
|
|
@ -46,7 +46,7 @@ TestCase := Rectangle {
|
|||
use sixtyfps::Model;
|
||||
let instance = TestCase::new();
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 15., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 791);
|
||||
|
||||
type ModelData = (sixtyfps::SharedString, sixtyfps::SharedString, f32);
|
||||
|
@ -59,10 +59,10 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::<ModelData>::from(
|
|||
|
||||
instance.set_model(sixtyfps::ModelHandle::new(another_model.clone()));
|
||||
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 25., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 335);
|
||||
assert_eq!(another_model.row_data(2).2, 335.);
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 25., 5.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||
assert_eq!(instance.get_clicked_score(), 337);
|
||||
assert_eq!(another_model.row_data(2).2, 337.);
|
||||
assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world"));
|
||||
|
|
|
@ -20,7 +20,7 @@ TestCase := TextInput {
|
|||
/*
|
||||
```rust
|
||||
let instance = TestCase::new();
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 50., 50.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert!(instance.get_input_focused());
|
||||
assert_eq!(instance.get_test_text(), "");
|
||||
sixtyfps::testing::send_keyboard_string_sequence(&instance, "Test");
|
||||
|
|
|
@ -20,7 +20,7 @@ TestCase := TextInput {
|
|||
/*
|
||||
```rust
|
||||
let instance = TestCase::new();
|
||||
sixtyfps::testing::send_mouse_click(instance.clone(), 50., 50.);
|
||||
sixtyfps::testing::send_mouse_click(&instance, 50., 50.);
|
||||
assert!(instance.get_input_focused());
|
||||
assert_eq!(instance.get_test_text(), "");
|
||||
sixtyfps::testing::send_keyboard_string_sequence(&instance, "😍");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue