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 | // Test that structs work if they are only referenced by callbacks |
6 | |
7 | struct Foo1 { member: int, } |
8 | struct Foo2 { a: Foo1 } |
9 | struct Foo3 { b: int } |
10 | |
11 | struct DeleteMe { c: color } |
12 | |
13 | struct Palette { |
14 | menuBar : brush, |
15 | mainContent : brush, |
16 | box : brush, |
17 | } |
18 | |
19 | export component TestCase inherits Rectangle { |
20 | pure callback cb1(Foo2) -> Foo3; |
21 | cb1(foo) => { return { b: foo.a.member+1 }; } |
22 | |
23 | in-out property<Foo2> xx; |
24 | pure callback cb2(Foo2, Foo2)->Foo2; |
25 | in-out property<Foo2> xx2: root.cb2(root.xx, root.xx); |
26 | |
27 | |
28 | // Based on Issue #1733 |
29 | Rectangle { |
30 | property<[DeleteMe]> data; |
31 | for d[i] in self.data: Rectangle { } |
32 | } |
33 | |
34 | // Bug #2765 |
35 | out property<Palette> palette : xx.a.member > 32 ? { |
36 | menuBar : #6D7BFB, |
37 | mainContent : #fbfbfb, |
38 | box : #ffffff, |
39 | } : { |
40 | menuBar : #2937A7, |
41 | mainContent : #040404, |
42 | box : #000000, |
43 | }; |
44 | |
45 | } |
46 | |
47 | |
48 | /* |
49 | ```rust |
50 | let instance = TestCase::new().unwrap(); |
51 | |
52 | assert_eq!(instance.invoke_cb1(Foo2{ a: Foo1{ member: 123 } }).b, 124); |
53 | ``` |
54 | |
55 | ```cpp |
56 | auto handle = TestCase::create(); |
57 | const TestCase &instance = *handle; |
58 | |
59 | assert_eq(instance.invoke_cb1(Foo2{ Foo1{ 123 } }).b, 124); |
60 | ``` |
61 | |
62 | ```js |
63 | var instance = new slint.TestCase(); |
64 | assert.equal(instance.cb1({a: {member: 123}}).b, 124); |
65 | ``` |
66 | |
67 | */ |
68 | } |
69 | |
70 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
71 | use i_slint_backend_testing as slint_testing; |
72 | slint_testing::init(); |
73 | let instance = TestCase::new().unwrap(); |
74 | |
75 | assert_eq!(instance.invoke_cb1(Foo2{ a: Foo1{ member: 123 } }).b, 124); |
76 | Ok(()) |
77 | } |