1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/models"#]
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 TestCase := Rectangle {
6 property<[int]> ints: [1, 2, 3, 4, 5];
7 property<int> num_ints: ints.length;
8 property<int> n: ints[ints[4] - ints[1]];
9 property<int> operations: ints.length < 1 ? ints.length : ints.length + ints.length;
10 property<[{a: [int]}]> empty_model;
11 property<[{a: [int]}]> empty_model2 : [];
12 property<[{a: [int]}]> empty_model3 : [{a:[]}];
13 property<[[int]]> array_of_array: [ints, ints, ints, []];
14
15 property<bool> test: num_ints == 5 && operations == 10
16 && hello_world == (["", "world"])[1] && empty_model.length == 0 && empty_model[45].a.length == 0
17 && array_of_array[1][1] == 2 && [].length == 0;
18 property<int> third_int: ints[2];
19 property<string> hello_world: [{t: "hello"}, {t: "world"}][1].t;
20
21 for xxx in (third_int == 0) ? ints : [] : Rectangle {}
22}
23
24/*
25```cpp
26auto handle = TestCase::create();
27const TestCase &instance = *handle;
28
29assert_eq(instance.get_num_ints(), 5);
30assert_eq(instance.get_n(), 4);
31assert_eq(instance.get_third_int(), 3);
32assert_eq(instance.get_test(), true);
33
34auto model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2, 3, 4, 5, 6, 7});
35instance.set_ints(model);
36assert_eq(instance.get_num_ints(), 7);
37assert_eq(instance.get_third_int(), 3);
38model->push_back(8);
39assert_eq(instance.get_num_ints(), 8);
40model->set_row_data(2, 100);
41assert_eq(instance.get_third_int(), 100);
42
43assert_eq(instance.get_hello_world(), "world");
44```
45
46
47```rust
48use slint::Model;
49let instance = TestCase::new().unwrap();
50
51assert_eq!(instance.get_num_ints(), 5);
52assert_eq!(instance.get_n(), 4);
53assert_eq!(instance.get_third_int(), 3);
54assert_eq!(instance.get_test(), true);
55
56let model: std::rc::Rc<slint::VecModel<i32>> = std::rc::Rc::new(vec![1, 2, 3, 4, 5, 6, 7].into());
57instance.set_ints(slint::ModelRc::from(model.clone()));
58assert_eq!(instance.get_num_ints(), 7);
59assert_eq!(instance.get_third_int(), 3);
60model.push(8);
61assert_eq!(instance.get_num_ints(), 8);
62model.set_row_data(2, 100);
63assert_eq!(instance.get_third_int(), 100);
64
65assert_eq!(instance.get_hello_world(), slint::SharedString::from("world"));
66```
67
68```js
69var instance = new slint.TestCase();
70
71assert.equal(instance.num_ints, 5);
72assert.equal(instance.n, 4);
73assert.equal(instance.third_int, 3);
74
75let model = new slintlib.ArrayModel([1, 2, 3, 4, 5, 6, 7]);
76instance.ints = model;
77assert.equal(instance.num_ints, 7);
78assert.equal(instance.third_int, 3);
79model.push(8);
80assert.equal(instance.num_ints, 8);
81model.setRowData(2, 100);
82assert.equal(instance.third_int, 100);
83
84assert.equal(instance.hello_world, "world");
85```
86*/
87}
88
89#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
90 use i_slint_backend_testing as slint_testing;
91 slint_testing::init();
92 use slint::Model;
93 let instance = TestCase::new().unwrap();
94
95 assert_eq!(instance.get_num_ints(), 5);
96 assert_eq!(instance.get_n(), 4);
97 assert_eq!(instance.get_third_int(), 3);
98 assert_eq!(instance.get_test(), true);
99
100 let model: std::rc::Rc<slint::VecModel<i32>> = std::rc::Rc::new(vec![1, 2, 3, 4, 5, 6, 7].into());
101 instance.set_ints(slint::ModelRc::from(model.clone()));
102 assert_eq!(instance.get_num_ints(), 7);
103 assert_eq!(instance.get_third_int(), 3);
104 model.push(8);
105 assert_eq!(instance.get_num_ints(), 8);
106 model.set_row_data(_row:2, _data:100);
107 assert_eq!(instance.get_third_int(), 100);
108
109 assert_eq!(instance.get_hello_world(), slint::SharedString::from("world"));
110 Ok(())
111}