1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/types"#]
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
5TestCase := Rectangle {
6 property<physical_length> l1: 12phx;
7 property<physical_length> l2: 12px;
8 property<physical_length> l3: 100phx + 12px;
9 property<physical_length> l4: 120 * 1phx;
10
11 property<length> ll1: 12phx;
12 property<length> ll2: 12px;
13 property<length> ll3: 100phx + 12px;
14 property<length> ll4: 120 * 1phx;
15
16 property<bool> value: l1 == 10phx + 2phx;
17
18 property<length> zero1: 0;
19 property<length> zero2: 0 + 1phx - 0 - 1phx;
20 property<bool> test_zero: zero2 == 0;
21
22 property <float> ratio: 1px / 1phx;
23
24 property<bool> test: (8phx * 5px * 3ms / 2phx) == (8px * (3ms / 2phx) * 5px) / ratio
25 && l1*l2 - ll1*ll2 == 0cm*0phx && value;
26
27}
28
29
30/*
31
32```cpp
33auto handle = TestCase::create();
34const TestCase &instance = *handle;
35float ratio = 1.;
36assert_eq(instance.get_l1(), 12.);
37assert_eq(instance.get_l2(), 12. * ratio);
38assert_eq(instance.get_l3(), 100. + 12. * ratio);
39assert_eq(instance.get_l4(), 120.);
40
41assert_eq(instance.get_ll1() * ratio, 12.);
42assert_eq(instance.get_ll2() * ratio, 12. * ratio);
43assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio);
44assert_eq(instance.get_ll4() * ratio, 120.);
45
46assert(instance.get_value());
47assert(instance.get_test_zero());
48assert(instance.get_test());
49
50ratio = 2.;
51instance.window().window_handle().set_scale_factor(ratio);
52assert_eq(instance.get_l1(), 12.);
53assert_eq(instance.get_l2(), 12. * ratio);
54assert_eq(instance.get_l3(), 100. + 12. * ratio);
55assert_eq(instance.get_l4(), 120.);
56
57assert_eq(instance.get_ll1() * ratio, 12.);
58assert_eq(instance.get_ll2() * ratio, 12. * ratio);
59assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio);
60assert_eq(instance.get_ll4() * ratio, 120.);
61
62assert(instance.get_value());
63assert(instance.get_test_zero());
64assert(instance.get_test());
65```
66
67
68```rust
69let ratio = 1.;
70let instance = TestCase::new().unwrap();
71assert_eq!(instance.get_l1(), 12.);
72assert_eq!(instance.get_l2(), 12. * ratio);
73assert_eq!(instance.get_l3(), 100. + 12. * ratio);
74assert_eq!(instance.get_l4(), 120.);
75
76assert_eq!(instance.get_ll1() * ratio, 12.);
77assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
78assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
79assert_eq!(instance.get_ll4() * ratio, 120.);
80
81assert!(instance.get_value());
82assert!(instance.get_test_zero());
83assert!(instance.get_test());
84
85let ratio = 2.;
86slint_testing::set_window_scale_factor(&instance, ratio);
87assert_eq!(instance.get_l1(), 12.);
88assert_eq!(instance.get_l2(), 12. * ratio);
89assert_eq!(instance.get_l3(), 100. + 12. * ratio);
90assert_eq!(instance.get_l4(), 120.);
91
92assert_eq!(instance.get_ll1() * ratio, 12.);
93assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
94assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
95assert_eq!(instance.get_ll4() * ratio, 120.);
96
97assert!(instance.get_value());
98assert!(instance.get_test_zero());
99assert!(instance.get_test());
100```
101
102```js
103// FIXME: test with different ratio
104var ratio = 1;
105var instance = new slint.TestCase({});
106assert.equal(instance.l1, 12.);
107assert.equal(instance.l2, 12. * ratio);
108assert.equal(instance.l3, 100. + 12 * ratio);
109assert.equal(instance.l4, 120.);
110
111assert.equal(instance.ll1 * ratio, 12.);
112assert.equal(instance.ll2 * ratio, 12. * ratio);
113assert.equal(instance.ll3 * ratio, 100. + 12. * ratio);
114assert.equal(instance.ll4 * ratio, 120.);
115
116assert(instance.value);
117assert(instance.test_zero);
118assert(instance.test);
119```
120
121*/
122}
123
124#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
125 use i_slint_backend_testing as slint_testing;
126 slint_testing::init();
127 let ratio = 1.;
128 let instance = TestCase::new().unwrap();
129 assert_eq!(instance.get_l1(), 12.);
130 assert_eq!(instance.get_l2(), 12. * ratio);
131 assert_eq!(instance.get_l3(), 100. + 12. * ratio);
132 assert_eq!(instance.get_l4(), 120.);
133
134 assert_eq!(instance.get_ll1() * ratio, 12.);
135 assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
136 assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
137 assert_eq!(instance.get_ll4() * ratio, 120.);
138
139 assert!(instance.get_value());
140 assert!(instance.get_test_zero());
141 assert!(instance.get_test());
142
143 let ratio = 2.;
144 slint_testing::set_window_scale_factor(&instance, ratio);
145 assert_eq!(instance.get_l1(), 12.);
146 assert_eq!(instance.get_l2(), 12. * ratio);
147 assert_eq!(instance.get_l3(), 100. + 12. * ratio);
148 assert_eq!(instance.get_l4(), 120.);
149
150 assert_eq!(instance.get_ll1() * ratio, 12.);
151 assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
152 assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
153 assert_eq!(instance.get_ll4() * ratio, 120.);
154
155 assert!(instance.get_value());
156 assert!(instance.get_test_zero());
157 assert!(instance.get_test());
158 Ok(())
159}