1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/callbacks"# ] |
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 | // Verify that properties in the base type can be accessed from init |
6 | |
7 | |
8 | component Foo inherits VerticalLayout { |
9 | in property<string> title: "OK" ; |
10 | Text { |
11 | text <=> root.title; |
12 | } |
13 | } |
14 | |
15 | component Base { |
16 | out property <string> title: "OK" ; |
17 | } |
18 | |
19 | component CompoWithCond { |
20 | callback dontcrash(); |
21 | dontcrash() => {} |
22 | VerticalLayout { |
23 | if (true) : Rectangle { |
24 | init => { |
25 | dontcrash(); |
26 | } |
27 | } |
28 | } |
29 | } |
30 | |
31 | |
32 | export component TestCase inherits Rectangle { |
33 | width: 300phx; |
34 | height: 300phx; |
35 | |
36 | property <bool> ok; |
37 | out property <string> test1: "KO" ; |
38 | out property <string> test2: "KO" ; |
39 | |
40 | in property <bool> cond: false; |
41 | |
42 | if cond: Base { |
43 | init => { |
44 | root.test1 = self.title; |
45 | } |
46 | } |
47 | |
48 | if cond: Foo { |
49 | init => { |
50 | root.test2 = self.title; |
51 | } |
52 | } |
53 | |
54 | l := VerticalLayout { |
55 | CompoWithCond { |
56 | dontcrash => { |
57 | root.ok = true; |
58 | } |
59 | } |
60 | } |
61 | out property <bool> test: l.preferred-width == 0px && ok; |
62 | } |
63 | |
64 | |
65 | /* |
66 | ```rust |
67 | let instance = TestCase::new().unwrap(); |
68 | |
69 | assert_eq!(instance.get_test1(), "KO"); |
70 | assert_eq!(instance.get_test2(), "KO"); |
71 | assert!(instance.get_test()); |
72 | instance.set_cond(true); |
73 | slint_testing::send_mouse_click(&instance, 5., 5.); |
74 | assert_eq!(instance.get_test1(), "OK"); |
75 | assert_eq!(instance.get_test2(), "OK"); |
76 | ``` |
77 | |
78 | ```cpp |
79 | auto handle = TestCase::create(); |
80 | const TestCase &instance = *handle; |
81 | assert_eq(instance.get_test1(), "KO"); |
82 | assert_eq(instance.get_test2(), "KO"); |
83 | assert(instance.get_test()); |
84 | instance.set_cond(true); |
85 | slint_testing::send_mouse_click(&instance, 5., 5.); |
86 | assert_eq(instance.get_test1(), "OK"); |
87 | assert_eq(instance.get_test2(), "OK"); |
88 | ``` |
89 | |
90 | |
91 | ```js |
92 | var instance = new slint.TestCase({}); |
93 | assert.equal(instance.test1, "KO"); |
94 | assert.equal(instance.test2, "KO"); |
95 | assert(instance.test); |
96 | instance.cond = true; |
97 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
98 | assert.equal(instance.test1, "OK"); |
99 | assert.equal(instance.test2, "OK"); |
100 | ``` |
101 | |
102 | |
103 | */} |
104 | |
105 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
106 | use i_slint_backend_testing as slint_testing; |
107 | slint_testing::init(); |
108 | let instance = TestCase::new().unwrap(); |
109 | |
110 | assert_eq!(instance.get_test1(), "KO" ); |
111 | assert_eq!(instance.get_test2(), "KO" ); |
112 | assert!(instance.get_test()); |
113 | instance.set_cond(true); |
114 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
115 | assert_eq!(instance.get_test1(), "OK" ); |
116 | assert_eq!(instance.get_test2(), "OK" ); |
117 | Ok(()) |
118 | } |