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
5TestCase := Rectangle {
6 property<{a: string, b: int}> foo: {a : "444", b: 12 };
7 property<{a: string, b: int}> obj_conversion: { b: 12, a : 444, c: "nothing" };
8 property<{a: string, b: int}> obj_conversion2: { a: "hello" };
9 property<{a: string, b: int}> obj_cond: true ? { b: 12, a : "ddd" } : { a: 12, b : 444, c: "nothing" };
10 property<{a: int, b: int}> obj_cond_merge : true ? { a: 1 } : { b: 10 };
11 property<bool> obj_binop_merge : { foo: 0, x: 1 } == { bar: 0, x: 1 };
12
13 property<string> foo_a : foo.a;
14 property<int> foo_b : foo.b;
15 property<int> obj_cond_merge_b : obj_cond_merge.b;
16 callback change_foo;
17 change_foo => {
18 foo.a = obj_conversion2.a;
19 foo.b += 8 + obj_conversion2.b;
20 }
21
22 function return_object() -> { aa: { bb: int } }
23 { return { aa: { bb: { cc: 42 }.cc } }; }
24 property <bool> test: return_object().aa.bb == 42 && obj_binop_merge;
25
26}
27
28
29/*
30```rust
31let instance = TestCase::new().unwrap();
32assert_eq!(instance.get_foo_a(), slint::SharedString::from("444"));
33assert_eq!(instance.get_foo_b(), 12);
34instance.invoke_change_foo();
35assert_eq!(instance.get_foo_a(), slint::SharedString::from("hello"));
36assert_eq!(instance.get_foo_b(), 20);
37assert_eq!(instance.get_obj_cond_merge_b(), 0);
38assert!(instance.get_obj_binop_merge());
39assert!(instance.get_test());
40
41// This API to set with a tuple should maybe not be accessible?
42instance.set_foo(("yo".into(), 33));
43assert_eq!(instance.get_foo_a(), slint::SharedString::from("yo"));
44assert_eq!(instance.get_foo_b(), 33);
45
46```
47
48```cpp
49auto handle = TestCase::create();
50const TestCase &instance = *handle;
51assert_eq(instance.get_foo_a(), slint::SharedString("444"));
52assert_eq(instance.get_foo_b(), 12);
53instance.invoke_change_foo();
54assert_eq(instance.get_foo_a(), slint::SharedString("hello"));
55assert_eq(instance.get_foo_b(), 20);
56assert_eq(instance.get_obj_cond_merge_b(), 0);
57assert_eq(instance.get_obj_binop_merge(), true);
58assert(instance.get_test());
59
60// This API to set with a tuple should maybe not be accessible?
61instance.set_foo(std::make_tuple(slint::SharedString("yo"), 33));
62assert_eq(instance.get_foo_a(), slint::SharedString("yo"));
63assert_eq(instance.get_foo_b(), 33);
64```
65
66
67```js
68var instance = new slint.TestCase({});
69assert.equal(instance.foo_a, ("444"));
70assert.equal(instance.foo_b, 12);
71instance.change_foo();
72assert.equal(instance.foo_a, "hello");
73assert.equal(instance.foo_b, 20);
74assert.equal(instance.obj_cond_merge_b, 0);
75assert(instance.obj_binop_merge);
76assert(instance.test);
77
78instance.foo = { a: "yo", b: 33 };
79assert.equal(instance.foo_a, "yo");
80assert.equal(instance.foo_b, 33);
81```
82*/
83}
84
85#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
86 use i_slint_backend_testing as slint_testing;
87 slint_testing::init();
88 let instance = TestCase::new().unwrap();
89 assert_eq!(instance.get_foo_a(), slint::SharedString::from("444"));
90 assert_eq!(instance.get_foo_b(), 12);
91 instance.invoke_change_foo();
92 assert_eq!(instance.get_foo_a(), slint::SharedString::from("hello"));
93 assert_eq!(instance.get_foo_b(), 20);
94 assert_eq!(instance.get_obj_cond_merge_b(), 0);
95 assert!(instance.get_obj_binop_merge());
96 assert!(instance.get_test());
97
98 // This API to set with a tuple should maybe not be accessible?
99 instance.set_foo(("yo".into(), 33));
100 assert_eq!(instance.get_foo_a(), slint::SharedString::from("yo"));
101 assert_eq!(instance.get_foo_b(), 33);
102
103 Ok(())
104}