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
7struct Foo1 { member: int, }
8struct Foo2 { a: Foo1 }
9struct Foo3 { b: int }
10
11struct DeleteMe { c: color }
12
13struct Palette {
14 menuBar : brush,
15 mainContent : brush,
16 box : brush,
17}
18
19export 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
50let instance = TestCase::new().unwrap();
51
52assert_eq!(instance.invoke_cb1(Foo2{ a: Foo1{ member: 123 } }).b, 124);
53```
54
55```cpp
56auto handle = TestCase::create();
57const TestCase &instance = *handle;
58
59assert_eq(instance.invoke_cb1(Foo2{ Foo1{ 123 } }).b, 124);
60```
61
62```js
63var instance = new slint.TestCase();
64assert.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}