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 | TestCase := 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 |
31 | let instance = TestCase::new().unwrap(); |
32 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("444")); |
33 | assert_eq!(instance.get_foo_b(), 12); |
34 | instance.invoke_change_foo(); |
35 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("hello")); |
36 | assert_eq!(instance.get_foo_b(), 20); |
37 | assert_eq!(instance.get_obj_cond_merge_b(), 0); |
38 | assert!(instance.get_obj_binop_merge()); |
39 | assert!(instance.get_test()); |
40 | |
41 | // This API to set with a tuple should maybe not be accessible? |
42 | instance.set_foo(("yo".into(), 33)); |
43 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("yo")); |
44 | assert_eq!(instance.get_foo_b(), 33); |
45 | |
46 | ``` |
47 | |
48 | ```cpp |
49 | auto handle = TestCase::create(); |
50 | const TestCase &instance = *handle; |
51 | assert_eq(instance.get_foo_a(), slint::SharedString("444")); |
52 | assert_eq(instance.get_foo_b(), 12); |
53 | instance.invoke_change_foo(); |
54 | assert_eq(instance.get_foo_a(), slint::SharedString("hello")); |
55 | assert_eq(instance.get_foo_b(), 20); |
56 | assert_eq(instance.get_obj_cond_merge_b(), 0); |
57 | assert_eq(instance.get_obj_binop_merge(), true); |
58 | assert(instance.get_test()); |
59 | |
60 | // This API to set with a tuple should maybe not be accessible? |
61 | instance.set_foo(std::make_tuple(slint::SharedString("yo"), 33)); |
62 | assert_eq(instance.get_foo_a(), slint::SharedString("yo")); |
63 | assert_eq(instance.get_foo_b(), 33); |
64 | ``` |
65 | |
66 | |
67 | ```js |
68 | var instance = new slint.TestCase({}); |
69 | assert.equal(instance.foo_a, ("444")); |
70 | assert.equal(instance.foo_b, 12); |
71 | instance.change_foo(); |
72 | assert.equal(instance.foo_a, "hello"); |
73 | assert.equal(instance.foo_b, 20); |
74 | assert.equal(instance.obj_cond_merge_b, 0); |
75 | assert(instance.obj_binop_merge); |
76 | assert(instance.test); |
77 | |
78 | instance.foo = { a: "yo", b: 33 }; |
79 | assert.equal(instance.foo_a, "yo"); |
80 | assert.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 | } |