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 the init callback is invoked in the correct order
6
7import { ExportedGlobal } from "../../helper_components/export_globals.slint";
8
9export global InitOrder := {
10 property <string> observed-order: "start";
11}
12
13Sub1 := Rectangle {
14 init => {
15 InitOrder.observed-order += "|sub1";
16 }
17}
18
19Sub2 := Rectangle {
20 init => {
21 InitOrder.observed-order += "|sub2";
22 }
23}
24
25SubSub := Rectangle {
26 init => {
27 InitOrder.observed-order += "|subsub";
28 }
29}
30
31Sub3 := Rectangle {
32 property <string> some-value: "should-not-show-up";
33 init => {
34 InitOrder.observed-order += some-value;
35 }
36 SubSub {}
37}
38
39Container := Rectangle {
40 in property <string> name-inside: "container";
41 init => {
42 InitOrder.observed-order += "|" + self.name-inside;
43 }
44 @children
45}
46
47TestCase := Rectangle {
48 width: 300phx;
49 height: 300phx;
50 init => {
51 InitOrder.observed-order += "|root";
52 ExportedGlobal.foo += 1;
53 }
54 Sub1 {
55 init => {
56 InitOrder.observed-order += "|sub1-use-site";
57 }
58 }
59 Sub2 {
60 }
61 Sub3 {
62 some-value: "|sub3";
63 }
64
65 Container {
66 property <string> name-outside: "container-instantiation";
67 init => {
68 InitOrder.observed-order += "|" + self.name-outside;
69 }
70 }
71
72 Rectangle {
73 init => {
74 InitOrder.observed-order += "|element";
75 }
76 }
77
78 for i in 2: Rectangle {
79 init => {
80 InitOrder.observed-order += "|repeater";
81 InitOrder.observed-order += i;
82 }
83 }
84
85 property <string> test_global_prop_value: InitOrder.observed-order;
86
87 property <string> expected_static_order: "start|sub1|sub2|subsub|sub3|container|root|sub1-use-site|container-instantiation|element";
88
89 property <bool> test: InitOrder.observed-order == expected_static_order;
90}
91
92/*
93```rust
94let instance = TestCase::new().unwrap();
95
96assert!(instance.get_test());
97slint_testing::send_mouse_click(&instance, 5., 5.);
98assert_eq!(instance.global::<InitOrder<'_>>().get_observed_order(), instance.get_expected_static_order() + "|repeater0|repeater1");
99```
100
101```cpp
102auto handle = TestCase::create();
103const TestCase &instance = *handle;
104assert(instance.get_test());
105slint_testing::send_mouse_click(&instance, 5., 5.);
106assert_eq(instance.global<InitOrder>().get_observed_order(), instance.get_expected_static_order() + "|repeater0|repeater1");
107```
108
109
110```js
111var instance = new slint.TestCase({});
112assert(instance.test);
113slintlib.private_api.send_mouse_click(instance, 5., 5.);
114assert.equal(instance.test_global_prop_value, instance.expected_static_order + "|repeater0|repeater1");
115```
116
117
118*/
119}
120
121#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
122 use i_slint_backend_testing as slint_testing;
123 slint_testing::init();
124 let instance = TestCase::new().unwrap();
125
126 assert!(instance.get_test());
127 slint_testing::send_mouse_click(&instance, x:5., y:5.);
128 assert_eq!(instance.global::<InitOrder<'_>>().get_observed_order(), instance.get_expected_static_order() + "|repeater0|repeater1");
129 Ok(())
130}