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 | |
5 | TestCase := 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 |
48 | auto handle = TestCase::create(); |
49 | const TestCase &instance = *handle; |
50 | instance.invoke_action(); |
51 | assert_eq(instance.get_result(), 3); |
52 | instance.set_value(5); |
53 | instance.invoke_action(); |
54 | assert_eq(instance.get_result(), 5); |
55 | instance.set_value(8); |
56 | instance.invoke_action(); |
57 | assert_eq(instance.get_result(), 5+33); |
58 | instance.invoke_xxx(); |
59 | assert_eq(instance.get_result(), 5+33-1); |
60 | assert_eq(instance.invoke_elseif(1), 41); |
61 | assert_eq(instance.invoke_elseif(2), 42); |
62 | assert_eq(instance.invoke_elseif(3), 43); |
63 | ``` |
64 | |
65 | |
66 | ```rust |
67 | let instance = TestCase::new().unwrap(); |
68 | instance.invoke_action(); |
69 | assert_eq!(instance.get_result(), 3); |
70 | instance.set_value(5); |
71 | instance.invoke_action(); |
72 | assert_eq!(instance.get_result(), 5); |
73 | instance.set_value(8); |
74 | instance.invoke_action(); |
75 | assert_eq!(instance.get_result(), 5+33); |
76 | instance.invoke_xxx(); |
77 | assert_eq!(instance.get_result(), 5+33-1); |
78 | assert_eq!(instance.invoke_elseif(1), 41); |
79 | assert_eq!(instance.invoke_elseif(2), 42); |
80 | assert_eq!(instance.invoke_elseif(3), 43); |
81 | ``` |
82 | |
83 | ```js |
84 | var instance = new slint.TestCase({}); |
85 | instance.action(); |
86 | assert.equal(instance.result, 3); |
87 | instance.value = 5; |
88 | instance.action(); |
89 | assert.equal(instance.result, 5); |
90 | instance.value = 8; |
91 | instance.action(); |
92 | assert.equal(instance.result, 5+33); |
93 | instance.xxx(); |
94 | assert.equal(instance.result, 5+33-1); |
95 | assert.equal(instance.elseif(1), 41); |
96 | assert.equal(instance.elseif(2), 42); |
97 | assert.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 | } |