1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/callbacks"#]
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// Verify that properties in the base type can be accessed from init
6
7
8component Foo inherits VerticalLayout {
9 in property<string> title: "OK";
10 Text {
11 text <=> root.title;
12 }
13}
14
15component Base {
16 out property <string> title: "OK";
17}
18
19component CompoWithCond {
20 callback dontcrash();
21 dontcrash() => {}
22 VerticalLayout {
23 if (true) : Rectangle {
24 init => {
25 dontcrash();
26 }
27 }
28 }
29}
30
31
32export component TestCase inherits Rectangle {
33 width: 300phx;
34 height: 300phx;
35
36 property <bool> ok;
37 out property <string> test1: "KO";
38 out property <string> test2: "KO";
39
40 in property <bool> cond: false;
41
42 if cond: Base {
43 init => {
44 root.test1 = self.title;
45 }
46 }
47
48 if cond: Foo {
49 init => {
50 root.test2 = self.title;
51 }
52 }
53
54 l := VerticalLayout {
55 CompoWithCond {
56 dontcrash => {
57 root.ok = true;
58 }
59 }
60 }
61 out property <bool> test: l.preferred-width == 0px && ok;
62}
63
64
65/*
66```rust
67let instance = TestCase::new().unwrap();
68
69assert_eq!(instance.get_test1(), "KO");
70assert_eq!(instance.get_test2(), "KO");
71assert!(instance.get_test());
72instance.set_cond(true);
73slint_testing::send_mouse_click(&instance, 5., 5.);
74assert_eq!(instance.get_test1(), "OK");
75assert_eq!(instance.get_test2(), "OK");
76```
77
78```cpp
79auto handle = TestCase::create();
80const TestCase &instance = *handle;
81assert_eq(instance.get_test1(), "KO");
82assert_eq(instance.get_test2(), "KO");
83assert(instance.get_test());
84instance.set_cond(true);
85slint_testing::send_mouse_click(&instance, 5., 5.);
86assert_eq(instance.get_test1(), "OK");
87assert_eq(instance.get_test2(), "OK");
88```
89
90
91```js
92var instance = new slint.TestCase({});
93assert.equal(instance.test1, "KO");
94assert.equal(instance.test2, "KO");
95assert(instance.test);
96instance.cond = true;
97slintlib.private_api.send_mouse_click(instance, 5., 5.);
98assert.equal(instance.test1, "OK");
99assert.equal(instance.test2, "OK");
100```
101
102
103*/}
104
105#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
106 use i_slint_backend_testing as slint_testing;
107 slint_testing::init();
108 let instance = TestCase::new().unwrap();
109
110 assert_eq!(instance.get_test1(), "KO");
111 assert_eq!(instance.get_test2(), "KO");
112 assert!(instance.get_test());
113 instance.set_cond(true);
114 slint_testing::send_mouse_click(&instance, x:5., y:5.);
115 assert_eq!(instance.get_test1(), "OK");
116 assert_eq!(instance.get_test2(), "OK");
117 Ok(())
118}