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