1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/layout"# ] |
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 | export TestCase := Window { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | property<int> value: -10; |
9 | property <bool> cond: true; |
10 | |
11 | VerticalLayout { |
12 | padding: 0px; |
13 | spacing: 0px; |
14 | |
15 | Rectangle { |
16 | background: orange; |
17 | TouchArea { |
18 | clicked => { |
19 | root.value = 0; |
20 | } |
21 | } |
22 | } |
23 | |
24 | if (true) : Rectangle { |
25 | background: blue; |
26 | TouchArea { |
27 | clicked => { |
28 | root.value = 1; |
29 | } |
30 | } |
31 | } |
32 | if (cond) : Rectangle { |
33 | background: red; |
34 | TouchArea { |
35 | clicked => { |
36 | root.value = 2; |
37 | } |
38 | } |
39 | } |
40 | if (false) : Rectangle { |
41 | background: green; |
42 | TouchArea { |
43 | clicked => { |
44 | root.value = 3; |
45 | } |
46 | } |
47 | } |
48 | |
49 | Rectangle { |
50 | background: pink; |
51 | TouchArea { |
52 | clicked => { |
53 | root.value = 4; |
54 | } |
55 | } |
56 | } |
57 | } |
58 | } |
59 | |
60 | // There should be 4 rectangle: so 100 divided by 4 is 25. |
61 | // when cond is false, there is 3, so 33.3 pixel per rectangle |
62 | |
63 | /* |
64 | ```cpp |
65 | auto handle = TestCase::create(); |
66 | const TestCase &instance = *handle; |
67 | |
68 | slint_testing::send_mouse_click(&instance, 5., 5.); |
69 | assert_eq(instance.get_value(), 0); |
70 | |
71 | slint_testing::send_mouse_click(&instance, 5., 52.); |
72 | assert_eq(instance.get_value(), 2); |
73 | |
74 | slint_testing::send_mouse_click(&instance, 5., 30.); |
75 | assert_eq(instance.get_value(), 1); |
76 | |
77 | slint_testing::send_mouse_click(&instance, 5., 80.); |
78 | assert_eq(instance.get_value(), 4); |
79 | |
80 | instance.set_cond(false); |
81 | slint_testing::send_mouse_click(&instance, 5., 35.); |
82 | assert_eq(instance.get_value(), 1); |
83 | slint_testing::send_mouse_click(&instance, 5., 30.); |
84 | assert_eq(instance.get_value(), 0); |
85 | slint_testing::send_mouse_click(&instance, 5., 67.); |
86 | assert_eq(instance.get_value(), 4); |
87 | |
88 | instance.set_cond(true); |
89 | slint_testing::send_mouse_click(&instance, 5., 70.); |
90 | assert_eq(instance.get_value(), 2); |
91 | |
92 | ``` |
93 | |
94 | |
95 | ```rust |
96 | let instance = TestCase::new().unwrap(); |
97 | |
98 | slint_testing::send_mouse_click(&instance, 5., 5.); |
99 | assert_eq!(instance.get_value(), 0); |
100 | |
101 | slint_testing::send_mouse_click(&instance, 5., 52.); |
102 | assert_eq!(instance.get_value(), 2); |
103 | |
104 | slint_testing::send_mouse_click(&instance, 5., 30.); |
105 | assert_eq!(instance.get_value(), 1); |
106 | |
107 | slint_testing::send_mouse_click(&instance, 5., 80.); |
108 | assert_eq!(instance.get_value(), 4); |
109 | |
110 | instance.set_cond(false); |
111 | slint_testing::send_mouse_click(&instance, 5., 35.); |
112 | assert_eq!(instance.get_value(), 1); |
113 | slint_testing::send_mouse_click(&instance, 5., 30.); |
114 | assert_eq!(instance.get_value(), 0); |
115 | slint_testing::send_mouse_click(&instance, 5., 67.); |
116 | assert_eq!(instance.get_value(), 4); |
117 | |
118 | instance.set_cond(true); |
119 | slint_testing::send_mouse_click(&instance, 5., 70.); |
120 | assert_eq!(instance.get_value(), 2); |
121 | |
122 | |
123 | ``` |
124 | |
125 | ```js |
126 | var instance = new slint.TestCase(); |
127 | |
128 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
129 | assert.equal(instance.value, 0); |
130 | |
131 | slintlib.private_api.send_mouse_click(instance, 5., 52.); |
132 | assert.equal(instance.value, 2); |
133 | |
134 | slintlib.private_api.send_mouse_click(instance, 5., 30.); |
135 | assert.equal(instance.value, 1); |
136 | |
137 | slintlib.private_api.send_mouse_click(instance, 5., 80); |
138 | assert.equal(instance.value, 4); |
139 | |
140 | instance.cond = false; |
141 | slintlib.private_api.send_mouse_click(instance, 5., 35.); |
142 | assert.equal(instance.value, 1); |
143 | slintlib.private_api.send_mouse_click(instance, 5., 30.); |
144 | assert.equal(instance.value, 0); |
145 | slintlib.private_api.send_mouse_click(instance, 5., 67.); |
146 | assert.equal(instance.value, 4); |
147 | |
148 | instance.cond = true; |
149 | slintlib.private_api.send_mouse_click(instance, 5., 70.); |
150 | assert.equal(instance.value, 2); |
151 | ``` |
152 | */ |
153 | } |
154 | |
155 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
156 | use i_slint_backend_testing as slint_testing; |
157 | slint_testing::init(); |
158 | let instance = TestCase::new().unwrap(); |
159 | |
160 | slint_testing::send_mouse_click(&instance, 5., 5.); |
161 | assert_eq!(instance.get_value(), 0); |
162 | |
163 | slint_testing::send_mouse_click(&instance, 5., 52.); |
164 | assert_eq!(instance.get_value(), 2); |
165 | |
166 | slint_testing::send_mouse_click(&instance, 5., 30.); |
167 | assert_eq!(instance.get_value(), 1); |
168 | |
169 | slint_testing::send_mouse_click(&instance, 5., 80.); |
170 | assert_eq!(instance.get_value(), 4); |
171 | |
172 | instance.set_cond(false); |
173 | slint_testing::send_mouse_click(&instance, 5., 35.); |
174 | assert_eq!(instance.get_value(), 1); |
175 | slint_testing::send_mouse_click(&instance, 5., 30.); |
176 | assert_eq!(instance.get_value(), 0); |
177 | slint_testing::send_mouse_click(&instance, 5., 67.); |
178 | assert_eq!(instance.get_value(), 4); |
179 | |
180 | instance.set_cond(true); |
181 | slint_testing::send_mouse_click(&instance, 5., 70.); |
182 | assert_eq!(instance.get_value(), 2); |
183 | |
184 | |
185 | Ok(()) |
186 | } |