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 | |
4 | TestCase := 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 |
32 | auto handle = TestCase::create(); |
33 | const TestCase &instance = *handle; |
34 | float ratio = 1.; |
35 | assert_eq(instance.get_l1(), 12.); |
36 | assert_eq(instance.get_l2(), 12. * ratio); |
37 | assert_eq(instance.get_l3(), 100. + 12. * ratio); |
38 | assert_eq(instance.get_l4(), 120.); |
39 | |
40 | assert_eq(instance.get_ll1() * ratio, 12.); |
41 | assert_eq(instance.get_ll2() * ratio, 12. * ratio); |
42 | assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio); |
43 | assert_eq(instance.get_ll4() * ratio, 120.); |
44 | |
45 | assert(instance.get_value()); |
46 | assert(instance.get_test_zero()); |
47 | assert(instance.get_test()); |
48 | |
49 | ratio = 2.; |
50 | instance.window().window_handle().set_scale_factor(ratio); |
51 | assert_eq(instance.get_l1(), 12.); |
52 | assert_eq(instance.get_l2(), 12. * ratio); |
53 | assert_eq(instance.get_l3(), 100. + 12. * ratio); |
54 | assert_eq(instance.get_l4(), 120.); |
55 | |
56 | assert_eq(instance.get_ll1() * ratio, 12.); |
57 | assert_eq(instance.get_ll2() * ratio, 12. * ratio); |
58 | assert_eq(instance.get_ll3() * ratio, 100. + 12. * ratio); |
59 | assert_eq(instance.get_ll4() * ratio, 120.); |
60 | |
61 | assert(instance.get_value()); |
62 | assert(instance.get_test_zero()); |
63 | assert(instance.get_test()); |
64 | ``` |
65 | |
66 | |
67 | ```rust |
68 | let ratio = 1.; |
69 | let instance = TestCase::new().unwrap(); |
70 | assert_eq!(instance.get_l1(), 12.); |
71 | assert_eq!(instance.get_l2(), 12. * ratio); |
72 | assert_eq!(instance.get_l3(), 100. + 12. * ratio); |
73 | assert_eq!(instance.get_l4(), 120.); |
74 | |
75 | assert_eq!(instance.get_ll1() * ratio, 12.); |
76 | assert_eq!(instance.get_ll2() * ratio, 12. * ratio); |
77 | assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio); |
78 | assert_eq!(instance.get_ll4() * ratio, 120.); |
79 | |
80 | assert!(instance.get_value()); |
81 | assert!(instance.get_test_zero()); |
82 | assert!(instance.get_test()); |
83 | |
84 | let ratio = 2.; |
85 | slint_testing::set_window_scale_factor(&instance, ratio); |
86 | assert_eq!(instance.get_l1(), 12.); |
87 | assert_eq!(instance.get_l2(), 12. * ratio); |
88 | assert_eq!(instance.get_l3(), 100. + 12. * ratio); |
89 | assert_eq!(instance.get_l4(), 120.); |
90 | |
91 | assert_eq!(instance.get_ll1() * ratio, 12.); |
92 | assert_eq!(instance.get_ll2() * ratio, 12. * ratio); |
93 | assert_eq!(instance.get_ll3() * ratio, 100. + 12. * ratio); |
94 | assert_eq!(instance.get_ll4() * ratio, 120.); |
95 | |
96 | assert!(instance.get_value()); |
97 | assert!(instance.get_test_zero()); |
98 | assert!(instance.get_test()); |
99 | ``` |
100 | |
101 | ```js |
102 | // FIXME: test with different ratio |
103 | var ratio = 1; |
104 | var instance = new slint.TestCase({}); |
105 | assert.equal(instance.l1, 12.); |
106 | assert.equal(instance.l2, 12. * ratio); |
107 | assert.equal(instance.l3, 100. + 12 * ratio); |
108 | assert.equal(instance.l4, 120.); |
109 | |
110 | assert.equal(instance.ll1 * ratio, 12.); |
111 | assert.equal(instance.ll2 * ratio, 12. * ratio); |
112 | assert.equal(instance.ll3 * ratio, 100. + 12. * ratio); |
113 | assert.equal(instance.ll4 * ratio, 120.); |
114 | |
115 | assert(instance.value); |
116 | assert(instance.test_zero); |
117 | assert(instance.test); |
118 | ``` |
119 | |
120 | */ |
121 | |