mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Change the C++ test API of the send_mouse_click
So that rust and C++ have the same code that can be copy pasted
This commit is contained in:
parent
69a1b7d4b7
commit
a36edfffbe
13 changed files with 38 additions and 39 deletions
|
@ -17,11 +17,10 @@ inline void mock_elapsed_time(int64_t time_in_ms)
|
||||||
cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms);
|
cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms);
|
||||||
}
|
}
|
||||||
template<typename Component>
|
template<typename Component>
|
||||||
inline void send_mouse_click(const ComponentHandle<Component> *component, float x, float y)
|
inline void send_mouse_click(const Component *component, float x, float y)
|
||||||
{
|
{
|
||||||
cbindgen_private::sixtyfps_send_mouse_click(
|
auto crc = *component->self_weak.into_dyn().lock();
|
||||||
reinterpret_cast<const vtable::VRc<private_api::ComponentVTable>*>(component),
|
cbindgen_private::sixtyfps_send_mouse_click(&crc, x, y, &component->window);
|
||||||
x, y, &(*component)->window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Component>
|
template<typename Component>
|
||||||
|
|
|
@ -917,7 +917,7 @@ fn generate_component(
|
||||||
));
|
));
|
||||||
|
|
||||||
component_struct.members.push((
|
component_struct.members.push((
|
||||||
Access::Private,
|
Access::Public, // FIXME: Used for the tests
|
||||||
Declaration::Var(Var {
|
Declaration::Var(Var {
|
||||||
ty: format!(
|
ty: format!(
|
||||||
"vtable::VWeak<sixtyfps::private_api::ComponentVTable, {}>",
|
"vtable::VWeak<sixtyfps::private_api::ComponentVTable, {}>",
|
||||||
|
|
|
@ -33,17 +33,17 @@ auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
// does not click on anything
|
// does not click on anything
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_touch1(), 0);
|
assert_eq(instance.get_touch1(), 0);
|
||||||
assert_eq(instance.get_touch2(), 0);
|
assert_eq(instance.get_touch2(), 0);
|
||||||
|
|
||||||
// click on second one
|
// click on second one
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 101., 101.);
|
sixtyfps::testing::send_mouse_click(&instance, 101., 101.);
|
||||||
assert_eq(instance.get_touch1(), 0);
|
assert_eq(instance.get_touch1(), 0);
|
||||||
assert_eq(instance.get_touch2(), 1);
|
assert_eq(instance.get_touch2(), 1);
|
||||||
|
|
||||||
// click on first one only
|
// click on first one only
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 108., 108.);
|
sixtyfps::testing::send_mouse_click(&instance, 108., 108.);
|
||||||
assert_eq(instance.get_touch1(), 1);
|
assert_eq(instance.get_touch1(), 1);
|
||||||
assert_eq(instance.get_touch2(), 1);
|
assert_eq(instance.get_touch2(), 1);
|
||||||
```
|
```
|
||||||
|
|
|
@ -73,7 +73,7 @@ assert_eq!(instance.get_r5(), "__abcdefghij__");
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 50., 50.);
|
sixtyfps::testing::send_mouse_click(&instance, 50., 50.);
|
||||||
sixtyfps::testing::send_keyboard_string_sequence(&instance, "__abcdefghij__");
|
sixtyfps::testing::send_keyboard_string_sequence(&instance, "__abcdefghij__");
|
||||||
assert_eq(instance.get_r1(), "__afghij__");
|
assert_eq(instance.get_r1(), "__afghij__");
|
||||||
assert_eq(instance.get_r2(), "__abfghij__");
|
assert_eq(instance.get_r2(), "__abfghij__");
|
||||||
|
|
|
@ -57,7 +57,7 @@ const TestCase &instance = *handle;
|
||||||
assert(!instance.get_input1_focused());
|
assert(!instance.get_input1_focused());
|
||||||
assert(!instance.get_input2_focused());
|
assert(!instance.get_input2_focused());
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 150., 100.);
|
sixtyfps::testing::send_mouse_click(&instance, 150., 100.);
|
||||||
assert(instance.get_input1_focused());
|
assert(instance.get_input1_focused());
|
||||||
assert(!instance.get_input2_focused());
|
assert(!instance.get_input2_focused());
|
||||||
|
|
||||||
|
@ -65,7 +65,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_input1_text(), "Only for field 1");
|
||||||
assert_eq(instance.get_input2_text(), "");
|
assert_eq(instance.get_input2_text(), "");
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 150., 300.);
|
sixtyfps::testing::send_mouse_click(&instance, 150., 300.);
|
||||||
assert(!instance.get_input1_focused());
|
assert(!instance.get_input1_focused());
|
||||||
assert(instance.get_input2_focused());
|
assert(instance.get_input2_focused());
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,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_input1_text(), "Only for field 1");
|
||||||
assert_eq(instance.get_input2_text(), "");
|
assert_eq(instance.get_input2_text(), "");
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 150., 100.);
|
sixtyfps::testing::send_mouse_click(&instance, 150., 100.);
|
||||||
assert(instance.get_input1_focused());
|
assert(instance.get_input1_focused());
|
||||||
assert(!instance.get_input2_focused());
|
assert(!instance.get_input2_focused());
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 150., 300.);
|
sixtyfps::testing::send_mouse_click(&instance, 150., 300.);
|
||||||
assert(!instance.get_input1_focused());
|
assert(!instance.get_input1_focused());
|
||||||
assert(instance.get_input2_focused());
|
assert(instance.get_input2_focused());
|
||||||
```
|
```
|
||||||
|
|
|
@ -40,13 +40,13 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
sixtyfps::testing::send_mouse_click(&handle, -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
|
||||||
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
|
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 190., 190.);
|
sixtyfps::testing::send_mouse_click(&instance, 190., 190.);
|
||||||
assert_eq(instance.get_value(), 1+1);
|
assert_eq(instance.get_value(), 1+1);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 290.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 290.);
|
||||||
assert_eq(instance.get_value(), 1+1+2);
|
assert_eq(instance.get_value(), 1+1+2);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,13 @@ export TestCase := Rectangle {
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_value(), -10);
|
assert_eq(instance.get_value(), -10);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 25., 25.);
|
sixtyfps::testing::send_mouse_click(&instance, 25., 25.);
|
||||||
assert_eq(instance.get_value(), 8);
|
assert_eq(instance.get_value(), 8);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 45., 15.);
|
sixtyfps::testing::send_mouse_click(&instance, 45., 15.);
|
||||||
assert_eq(instance.get_value(), 9);
|
assert_eq(instance.get_value(), 9);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,13 @@ TestCase := Window {
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 455.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 455.);
|
||||||
assert_eq(instance.get_last_clicked(), 0);
|
assert_eq(instance.get_last_clicked(), 0);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 305.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 305.);
|
||||||
assert_eq(instance.get_last_clicked(), 11);
|
assert_eq(instance.get_last_clicked(), 11);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 295.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 295.);
|
||||||
assert_eq(instance.get_last_clicked(), 3);
|
assert_eq(instance.get_last_clicked(), 3);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 95.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 95.);
|
||||||
assert_eq(instance.get_last_clicked(), 1);
|
assert_eq(instance.get_last_clicked(), 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -95,13 +95,13 @@ export TestCase := Rectangle {
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_value(), 10);
|
assert_eq(instance.get_value(), 10);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 15.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 15.);
|
||||||
assert_eq(instance.get_value(), 13);
|
assert_eq(instance.get_value(), 13);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 15.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 15.);
|
||||||
assert_eq(instance.get_value(), 13+42);
|
assert_eq(instance.get_value(), 13+42);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,15 @@ auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
// condition is false
|
// condition is false
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_top_level(), 42);
|
assert_eq(instance.get_top_level(), 42);
|
||||||
|
|
||||||
instance.set_cond1(true);
|
instance.set_cond1(true);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_top_level(), 92);
|
assert_eq(instance.get_top_level(), 92);
|
||||||
|
|
||||||
instance.set_cond1(false);
|
instance.set_cond1(false);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_top_level(), 92);
|
assert_eq(instance.get_top_level(), 92);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -109,11 +109,11 @@ auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
// there should be nothing there
|
// there should be nothing there
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 25., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 0);
|
assert_eq(instance.get_clicked_score(), 0);
|
||||||
assert_eq(instance.get_clicked_internal_state(), 0);
|
assert_eq(instance.get_clicked_internal_state(), 0);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 789000);
|
assert_eq(instance.get_clicked_score(), 789000);
|
||||||
assert_eq(instance.get_clicked_internal_state(), 1);
|
assert_eq(instance.get_clicked_internal_state(), 1);
|
||||||
|
|
||||||
|
@ -125,31 +125,31 @@ array.push_back(ModelData{"a3", "world", 333.});
|
||||||
auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
|
auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
|
||||||
instance.set_model(another_model);
|
instance.set_model(another_model);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 25., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 333000);
|
assert_eq(instance.get_clicked_score(), 333000);
|
||||||
assert_eq(instance.get_clicked_internal_state(), 1);
|
assert_eq(instance.get_clicked_internal_state(), 1);
|
||||||
assert_eq(instance.get_clicked_index(), 2);
|
assert_eq(instance.get_clicked_index(), 2);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 222000);
|
assert_eq(instance.get_clicked_score(), 222000);
|
||||||
assert_eq(instance.get_clicked_name(), "cruel");
|
assert_eq(instance.get_clicked_name(), "cruel");
|
||||||
assert_eq(instance.get_clicked_internal_state(), 1);
|
assert_eq(instance.get_clicked_internal_state(), 1);
|
||||||
|
|
||||||
another_model->push_back({"a4", "!", 444.});
|
another_model->push_back({"a4", "!", 444.});
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 35., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 35., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 444000);
|
assert_eq(instance.get_clicked_score(), 444000);
|
||||||
assert_eq(instance.get_clicked_name(), "!");
|
assert_eq(instance.get_clicked_name(), "!");
|
||||||
assert_eq(instance.get_clicked_internal_state(), 1);
|
assert_eq(instance.get_clicked_internal_state(), 1);
|
||||||
|
|
||||||
another_model->set_row_data(1, {"a2", "idyllic", 555.});
|
another_model->set_row_data(1, {"a2", "idyllic", 555.});
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 555000);
|
assert_eq(instance.get_clicked_score(), 555000);
|
||||||
assert_eq(instance.get_clicked_name(), "idyllic");
|
assert_eq(instance.get_clicked_name(), "idyllic");
|
||||||
assert_eq(instance.get_clicked_internal_state(), 2);
|
assert_eq(instance.get_clicked_internal_state(), 2);
|
||||||
assert_eq(instance.get_clicked_index(), 1);
|
assert_eq(instance.get_clicked_index(), 1);
|
||||||
|
|
||||||
another_model->erase(1);
|
another_model->erase(1);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 333000);
|
assert_eq(instance.get_clicked_score(), 333000);
|
||||||
assert_eq(instance.get_clicked_name(), "world");
|
assert_eq(instance.get_clicked_name(), "world");
|
||||||
assert_eq(instance.get_clicked_internal_state(), 2);
|
assert_eq(instance.get_clicked_internal_state(), 2);
|
||||||
|
|
|
@ -71,7 +71,7 @@ assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world"));
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 15., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 15., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 791);
|
assert_eq(instance.get_clicked_score(), 791);
|
||||||
|
|
||||||
using ModelData = std::tuple<sixtyfps::SharedString, sixtyfps::SharedString, float>;
|
using ModelData = std::tuple<sixtyfps::SharedString, sixtyfps::SharedString, float>;
|
||||||
|
@ -82,10 +82,10 @@ array.push_back(ModelData{"a3", "world", 333.});
|
||||||
auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
|
auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
|
||||||
instance.set_model(another_model);
|
instance.set_model(another_model);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 25., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 335);
|
assert_eq(instance.get_clicked_score(), 335);
|
||||||
assert_eq(std::get<2>(another_model->row_data(2)), 335.);
|
assert_eq(std::get<2>(another_model->row_data(2)), 335.);
|
||||||
sixtyfps::testing::send_mouse_click(&handle, 25., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 25., 5.);
|
||||||
assert_eq(instance.get_clicked_score(), 337);
|
assert_eq(instance.get_clicked_score(), 337);
|
||||||
assert_eq(std::get<2>(another_model->row_data(2)), 337.);
|
assert_eq(std::get<2>(another_model->row_data(2)), 337.);
|
||||||
assert_eq(std::get<1>(another_model->row_data(2)), "world");
|
assert_eq(std::get<1>(another_model->row_data(2)), "world");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue