1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/expr"#]
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
5export global Foo {
6 in-out property<bool> bo: false;
7 public pure function return_bool() -> bool {
8 if (bo) {
9 return true;
10 }
11 false
12 }
13
14 callback cycle_instrument_param_end();
15}
16
17
18// extracted from chiptrack
19export component StepsFocusScope inherits FocusScope {
20 callback root_key_released(KeyEvent) -> EventResult;
21 key_released(e) => {
22 if (e.text == Key.Control) { Foo.cycle_instrument_param_end(); }
23 else {
24 return root_key_released(e);
25 }
26 accept
27 }
28}
29
30
31component Issue4070 {
32 function broken(event: string) -> EventResult {
33 if (event == "a") { }
34 else if (event == "s") { }
35 else {
36 debug("returning reject");
37 return reject;
38 }
39 debug("returning accept");
40 accept
41 }
42 out property<bool> test : broken("a") == EventResult.accept;
43}
44
45
46export component TestCase {
47
48 function return_false() -> bool { return false; }
49
50 out property <string> val;
51
52 public function proceed() {
53 if (return-false()) {
54 val += "e";
55 return;
56 }
57 if (!return-false()) {
58 val += "1";
59 if (return-false() == true) {
60 val += "error";
61 return "Nope";
62 } else {
63 val += "2";
64 if (false) {
65 return;
66 val += "x";
67 }
68 }
69 }
70 if (Foo.return-bool()) {
71 val += "nope";
72 } else {
73 val += "3";
74 if (!Foo.return-bool()) {
75 val += "4";
76 return;
77 val += "z";
78 "XXX";
79 }
80 val += "y";
81 }
82
83 val += "After";
84 if (true) {
85 return;
86 } else {
87 return;
88 }
89 return;
90
91 }
92
93 i4070 := Issue4070 {}
94
95 out property <bool> test: {
96 if (!i4070.test) {
97 return false;
98 }
99 if (false) {
100 return false;
101 }
102 if (false) {
103 return false;
104 }
105 //true;
106 if (true) {
107 if (false) {
108 return false;
109 }
110 if (true) {
111 return true;
112 } else {
113 return false;
114 }
115 return false;
116 }
117 return false;
118 false;
119 }
120
121 out property <bool> check_ok;
122 public function test-key() -> bool {
123 fs.key-released({text: "hi"}) == EventResult.reject
124 }
125 fs := StepsFocusScope {
126 root-key-released(e) => { check-ok = e.text == "hi"; EventResult.reject }
127 }
128}
129
130
131/*
132```cpp
133auto handle = TestCase::create();
134const TestCase &instance = *handle;
135assert(instance.get_test());
136instance.invoke_proceed();
137assert_eq(instance.get_val(), "1234");
138
139assert_eq(instance.invoke_test_key(), true);
140assert_eq(instance.get_check_ok(), true);
141
142```
143
144```rust
145let instance = TestCase::new().unwrap();
146assert!(instance.get_test());
147instance.invoke_proceed();
148assert_eq!(instance.get_val(), "1234");
149
150instance.global::<Foo<'_>>().on_cycle_instrument_param_end(|| panic!("should not happen"));
151assert_eq!(instance.invoke_test_key(), true);
152assert_eq!(instance.get_check_ok(), true);
153
154
155```
156
157
158*/
159}
160
161#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
162 use i_slint_backend_testing as slint_testing;
163 slint_testing::init();
164 let instance = TestCase::new().unwrap();
165 assert!(instance.get_test());
166 instance.invoke_proceed();
167 assert_eq!(instance.get_val(), "1234");
168
169 instance.global::<Foo<'_>>().on_cycle_instrument_param_end(|| panic!("should not happen"));
170 assert_eq!(instance.invoke_test_key(), true);
171 assert_eq!(instance.get_check_ok(), true);
172
173
174 Ok(())
175}