1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/bindings"# ] |
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<brush> extra_background <=> background; |
7 | property<length> sub_width1 <=> sub.width; |
8 | property<length> sub_width2: sub.width; |
9 | |
10 | property<int> sub_foo1: 44; |
11 | property<int> sub_foo2: sub.foo; |
12 | |
13 | |
14 | sub := Rectangle { |
15 | width: 80phx; |
16 | property<int> foo <=> root.sub_foo1; |
17 | } |
18 | |
19 | if (true) : Rectangle { background: root.extra_background; } |
20 | } |
21 | |
22 | |
23 | /* |
24 | |
25 | ```rust |
26 | let instance = TestCase::new().unwrap(); |
27 | assert_eq!(instance.get_sub_width1(), 80.); |
28 | assert_eq!(instance.get_sub_width2(), 80.); |
29 | instance.set_sub_width1(99.); |
30 | assert_eq!(instance.get_sub_width1(), 99.); |
31 | assert_eq!(instance.get_sub_width2(), 99.); |
32 | |
33 | // breaks the binding |
34 | instance.set_sub_width2(23.); |
35 | assert_eq!(instance.get_sub_width1(), 99.); |
36 | assert_eq!(instance.get_sub_width2(), 23.); |
37 | instance.set_sub_width1(88.); |
38 | assert_eq!(instance.get_sub_width1(), 88.); |
39 | assert_eq!(instance.get_sub_width2(), 23.); |
40 | |
41 | |
42 | assert_eq!(instance.get_sub_foo1(), 44); |
43 | assert_eq!(instance.get_sub_foo2(), 44); |
44 | instance.set_sub_foo1(15); |
45 | assert_eq!(instance.get_sub_foo1(), 15); |
46 | assert_eq!(instance.get_sub_foo2(), 15); |
47 | ``` |
48 | |
49 | |
50 | ```cpp |
51 | auto handle = TestCase::create(); |
52 | const TestCase &instance = *handle; |
53 | assert_eq(instance.get_sub_width1(), 80.); |
54 | assert_eq(instance.get_sub_width2(), 80.); |
55 | instance.set_sub_width1(99.); |
56 | assert_eq(instance.get_sub_width1(), 99.); |
57 | assert_eq(instance.get_sub_width2(), 99.); |
58 | |
59 | // breaks the binding |
60 | instance.set_sub_width2(23.); |
61 | assert_eq(instance.get_sub_width1(), 99.); |
62 | assert_eq(instance.get_sub_width2(), 23.); |
63 | instance.set_sub_width1(88.); |
64 | assert_eq(instance.get_sub_width1(), 88.); |
65 | assert_eq(instance.get_sub_width2(), 23.); |
66 | |
67 | |
68 | assert_eq(instance.get_sub_foo1(), 44); |
69 | assert_eq(instance.get_sub_foo2(), 44); |
70 | instance.set_sub_foo1(15); |
71 | assert_eq(instance.get_sub_foo1(), 15); |
72 | assert_eq(instance.get_sub_foo2(), 15); |
73 | ``` |
74 | |
75 | ```js |
76 | var instance = new slint.TestCase({}); |
77 | assert.equal(instance.sub_width1, 80.); |
78 | assert.equal(instance.sub_width2, 80.); |
79 | instance.sub_width1 = (99.); |
80 | assert.equal(instance.sub_width1, 99.); |
81 | assert.equal(instance.sub_width2, 99.); |
82 | |
83 | // breaks the binding |
84 | instance.sub_width2 = (23.); |
85 | assert.equal(instance.sub_width1, 99.); |
86 | assert.equal(instance.sub_width2, 23.); |
87 | instance.sub_width1 = (88.); |
88 | assert.equal(instance.sub_width1, 88.); |
89 | assert.equal(instance.sub_width2, 23.); |
90 | |
91 | |
92 | assert.equal(instance.sub_foo1, 44); |
93 | assert.equal(instance.sub_foo2, 44); |
94 | instance.sub_foo1 = (15); |
95 | assert.equal(instance.sub_foo1, 15); |
96 | assert.equal(instance.sub_foo2, 15); |
97 | ``` |
98 | |
99 | */ |
100 | } |
101 | |
102 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
103 | use i_slint_backend_testing as slint_testing; |
104 | slint_testing::init(); |
105 | let instance = TestCase::new().unwrap(); |
106 | assert_eq!(instance.get_sub_width1(), 80.); |
107 | assert_eq!(instance.get_sub_width2(), 80.); |
108 | instance.set_sub_width1(99.); |
109 | assert_eq!(instance.get_sub_width1(), 99.); |
110 | assert_eq!(instance.get_sub_width2(), 99.); |
111 | |
112 | // breaks the binding |
113 | instance.set_sub_width2(23.); |
114 | assert_eq!(instance.get_sub_width1(), 99.); |
115 | assert_eq!(instance.get_sub_width2(), 23.); |
116 | instance.set_sub_width1(88.); |
117 | assert_eq!(instance.get_sub_width1(), 88.); |
118 | assert_eq!(instance.get_sub_width2(), 23.); |
119 | |
120 | |
121 | assert_eq!(instance.get_sub_foo1(), 44); |
122 | assert_eq!(instance.get_sub_foo2(), 44); |
123 | instance.set_sub_foo1(15); |
124 | assert_eq!(instance.get_sub_foo1(), 15); |
125 | assert_eq!(instance.get_sub_foo2(), 15); |
126 | Ok(()) |
127 | } |