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
5TestCase := 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
26let instance = TestCase::new().unwrap();
27assert_eq!(instance.get_sub_width1(), 80.);
28assert_eq!(instance.get_sub_width2(), 80.);
29instance.set_sub_width1(99.);
30assert_eq!(instance.get_sub_width1(), 99.);
31assert_eq!(instance.get_sub_width2(), 99.);
32
33// breaks the binding
34instance.set_sub_width2(23.);
35assert_eq!(instance.get_sub_width1(), 99.);
36assert_eq!(instance.get_sub_width2(), 23.);
37instance.set_sub_width1(88.);
38assert_eq!(instance.get_sub_width1(), 88.);
39assert_eq!(instance.get_sub_width2(), 23.);
40
41
42assert_eq!(instance.get_sub_foo1(), 44);
43assert_eq!(instance.get_sub_foo2(), 44);
44instance.set_sub_foo1(15);
45assert_eq!(instance.get_sub_foo1(), 15);
46assert_eq!(instance.get_sub_foo2(), 15);
47```
48
49
50```cpp
51auto handle = TestCase::create();
52const TestCase &instance = *handle;
53assert_eq(instance.get_sub_width1(), 80.);
54assert_eq(instance.get_sub_width2(), 80.);
55instance.set_sub_width1(99.);
56assert_eq(instance.get_sub_width1(), 99.);
57assert_eq(instance.get_sub_width2(), 99.);
58
59// breaks the binding
60instance.set_sub_width2(23.);
61assert_eq(instance.get_sub_width1(), 99.);
62assert_eq(instance.get_sub_width2(), 23.);
63instance.set_sub_width1(88.);
64assert_eq(instance.get_sub_width1(), 88.);
65assert_eq(instance.get_sub_width2(), 23.);
66
67
68assert_eq(instance.get_sub_foo1(), 44);
69assert_eq(instance.get_sub_foo2(), 44);
70instance.set_sub_foo1(15);
71assert_eq(instance.get_sub_foo1(), 15);
72assert_eq(instance.get_sub_foo2(), 15);
73```
74
75```js
76var instance = new slint.TestCase({});
77assert.equal(instance.sub_width1, 80.);
78assert.equal(instance.sub_width2, 80.);
79instance.sub_width1 = (99.);
80assert.equal(instance.sub_width1, 99.);
81assert.equal(instance.sub_width2, 99.);
82
83// breaks the binding
84instance.sub_width2 = (23.);
85assert.equal(instance.sub_width1, 99.);
86assert.equal(instance.sub_width2, 23.);
87instance.sub_width1 = (88.);
88assert.equal(instance.sub_width1, 88.);
89assert.equal(instance.sub_width2, 23.);
90
91
92assert.equal(instance.sub_foo1, 44);
93assert.equal(instance.sub_foo2, 44);
94instance.sub_foo1 = (15);
95assert.equal(instance.sub_foo1, 15);
96assert.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}