1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/conditional"#]
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<int> value;
7 property<int> result : 3;
8 callback action;
9 action => {
10 if value == 5 {
11 result += 1;
12 result += 1;
13 }
14
15 if value != 8 {
16
17 } else {
18 result += 33;
19 }
20 }
21
22 callback xxx;
23 xxx => {
24 if false {
25 action();
26 }
27
28 if true {
29 result -=1;
30 } else {
31 action();
32 }
33 }
34
35 callback elseif(int) -> int;
36 elseif(v) => {
37 if v == 1 {
38 41
39 } else if v == 2 {
40 42
41 } else {
42 43
43 }
44 }
45}
46/*
47```cpp
48auto handle = TestCase::create();
49const TestCase &instance = *handle;
50instance.invoke_action();
51assert_eq(instance.get_result(), 3);
52instance.set_value(5);
53instance.invoke_action();
54assert_eq(instance.get_result(), 5);
55instance.set_value(8);
56instance.invoke_action();
57assert_eq(instance.get_result(), 5+33);
58instance.invoke_xxx();
59assert_eq(instance.get_result(), 5+33-1);
60assert_eq(instance.invoke_elseif(1), 41);
61assert_eq(instance.invoke_elseif(2), 42);
62assert_eq(instance.invoke_elseif(3), 43);
63```
64
65
66```rust
67let instance = TestCase::new().unwrap();
68instance.invoke_action();
69assert_eq!(instance.get_result(), 3);
70instance.set_value(5);
71instance.invoke_action();
72assert_eq!(instance.get_result(), 5);
73instance.set_value(8);
74instance.invoke_action();
75assert_eq!(instance.get_result(), 5+33);
76instance.invoke_xxx();
77assert_eq!(instance.get_result(), 5+33-1);
78assert_eq!(instance.invoke_elseif(1), 41);
79assert_eq!(instance.invoke_elseif(2), 42);
80assert_eq!(instance.invoke_elseif(3), 43);
81```
82
83```js
84var instance = new slint.TestCase({});
85instance.action();
86assert.equal(instance.result, 3);
87instance.value = 5;
88instance.action();
89assert.equal(instance.result, 5);
90instance.value = 8;
91instance.action();
92assert.equal(instance.result, 5+33);
93instance.xxx();
94assert.equal(instance.result, 5+33-1);
95assert.equal(instance.elseif(1), 41);
96assert.equal(instance.elseif(2), 42);
97assert.equal(instance.elseif(3), 43);
98```
99*/
100}
101
102#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
103 use i_slint_backend_testing as slint_testing;
104 slint_testing::init();
105 let instance = TestCase::new().unwrap();
106 instance.invoke_action();
107 assert_eq!(instance.get_result(), 3);
108 instance.set_value(5);
109 instance.invoke_action();
110 assert_eq!(instance.get_result(), 5);
111 instance.set_value(8);
112 instance.invoke_action();
113 assert_eq!(instance.get_result(), 5+33);
114 instance.invoke_xxx();
115 assert_eq!(instance.get_result(), 5+33-1);
116 assert_eq!(instance.invoke_elseif(1), 41);
117 assert_eq!(instance.invoke_elseif(2), 42);
118 assert_eq!(instance.invoke_elseif(3), 43);
119 Ok(())
120}