1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4TestCase := Rectangle {
5 property<physical_length> l1: 12phx;
6 property<physical_length> l2: 12px;
7 property<physical_length> l3: 100phx + 12px;
8 property<physical_length> l4: 120 * 1phx;
9
10 property<length> ll1: 12phx;
11 property<length> ll2: 12px;
12 property<length> ll3: 100phx + 12px;
13 property<length> ll4: 120 * 1phx;
14
15 property<bool> value: l1 == 10phx + 2phx;
16
17 property<length> zero1: 0;
18 property<length> zero2: 0 + 1phx - 0 - 1phx;
19 property<bool> test_zero: zero2 == 0;
20
21 property <float> ratio: 1px / 1phx;
22
23 property<bool> test: (8phx * 5px * 3ms / 2phx) == (8px * (3ms / 2phx) * 5px) / ratio
24 && l1*l2 - ll1*ll2 == 0cm*0phx && value;
25
26}
27
28
29/*
30
31```cpp
32auto handle = TestCase::create();
33const TestCase &instance = *handle;
34float ratio = 1.;
35assert_eq(instance.get_l1(), 12.);
36assert_eq(instance.get_l2(), 12. * ratio);
37assert_eq(instance.get_l3(), 100. + 12. * ratio);
38assert_eq(instance.get_l4(), 120.);
39
40assert_eq(instance.get_ll1() * ratio, 12.);
41assert_eq(instance.get_ll2() * ratio, 12. * ratio);
42assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio);
43assert_eq(instance.get_ll4() * ratio, 120.);
44
45assert(instance.get_value());
46assert(instance.get_test_zero());
47assert(instance.get_test());
48
49ratio = 2.;
50instance.window().window_handle().set_scale_factor(ratio);
51assert_eq(instance.get_l1(), 12.);
52assert_eq(instance.get_l2(), 12. * ratio);
53assert_eq(instance.get_l3(), 100. + 12. * ratio);
54assert_eq(instance.get_l4(), 120.);
55
56assert_eq(instance.get_ll1() * ratio, 12.);
57assert_eq(instance.get_ll2() * ratio, 12. * ratio);
58assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio);
59assert_eq(instance.get_ll4() * ratio, 120.);
60
61assert(instance.get_value());
62assert(instance.get_test_zero());
63assert(instance.get_test());
64```
65
66
67```rust
68let ratio = 1.;
69let instance = TestCase::new().unwrap();
70assert_eq!(instance.get_l1(), 12.);
71assert_eq!(instance.get_l2(), 12. * ratio);
72assert_eq!(instance.get_l3(), 100. + 12. * ratio);
73assert_eq!(instance.get_l4(), 120.);
74
75assert_eq!(instance.get_ll1() * ratio, 12.);
76assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
77assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
78assert_eq!(instance.get_ll4() * ratio, 120.);
79
80assert!(instance.get_value());
81assert!(instance.get_test_zero());
82assert!(instance.get_test());
83
84let ratio = 2.;
85slint_testing::set_window_scale_factor(&instance, ratio);
86assert_eq!(instance.get_l1(), 12.);
87assert_eq!(instance.get_l2(), 12. * ratio);
88assert_eq!(instance.get_l3(), 100. + 12. * ratio);
89assert_eq!(instance.get_l4(), 120.);
90
91assert_eq!(instance.get_ll1() * ratio, 12.);
92assert_eq!(instance.get_ll2() * ratio, 12. * ratio);
93assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio);
94assert_eq!(instance.get_ll4() * ratio, 120.);
95
96assert!(instance.get_value());
97assert!(instance.get_test_zero());
98assert!(instance.get_test());
99```
100
101```js
102// FIXME: test with different ratio
103var ratio = 1;
104var instance = new slint.TestCase({});
105assert.equal(instance.l1, 12.);
106assert.equal(instance.l2, 12. * ratio);
107assert.equal(instance.l3, 100. + 12 * ratio);
108assert.equal(instance.l4, 120.);
109
110assert.equal(instance.ll1 * ratio, 12.);
111assert.equal(instance.ll2 * ratio, 12. * ratio);
112assert.equal(instance.ll3 * ratio, 100. + 12. * ratio);
113assert.equal(instance.ll4 * ratio, 120.);
114
115assert(instance.value);
116assert(instance.test_zero);
117assert(instance.test);
118```
119
120*/
121