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 | |
5 | export 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 |
26 | auto handle = TestCase::create(); |
27 | const TestCase &instance = *handle; |
28 | |
29 | assert_eq(instance.get_num_ints(), 5); |
30 | assert_eq(instance.get_n(), 4); |
31 | assert_eq(instance.get_third_int(), 3); |
32 | assert_eq(instance.get_test(), true); |
33 | |
34 | auto model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2, 3, 4, 5, 6, 7}); |
35 | instance.set_ints(model); |
36 | assert_eq(instance.get_num_ints(), 7); |
37 | assert_eq(instance.get_third_int(), 3); |
38 | model->push_back(8); |
39 | assert_eq(instance.get_num_ints(), 8); |
40 | model->set_row_data(2, 100); |
41 | assert_eq(instance.get_third_int(), 100); |
42 | |
43 | assert_eq(instance.get_hello_world(), "world"); |
44 | ``` |
45 | |
46 | |
47 | ```rust |
48 | use slint::Model; |
49 | let instance = TestCase::new().unwrap(); |
50 | |
51 | assert_eq!(instance.get_num_ints(), 5); |
52 | assert_eq!(instance.get_n(), 4); |
53 | assert_eq!(instance.get_third_int(), 3); |
54 | assert_eq!(instance.get_test(), true); |
55 | |
56 | let model: std::rc::Rc<slint::VecModel<i32>> = std::rc::Rc::new(vec![1, 2, 3, 4, 5, 6, 7].into()); |
57 | instance.set_ints(slint::ModelRc::from(model.clone())); |
58 | assert_eq!(instance.get_num_ints(), 7); |
59 | assert_eq!(instance.get_third_int(), 3); |
60 | model.push(8); |
61 | assert_eq!(instance.get_num_ints(), 8); |
62 | model.set_row_data(2, 100); |
63 | assert_eq!(instance.get_third_int(), 100); |
64 | |
65 | assert_eq!(instance.get_hello_world(), slint::SharedString::from("world")); |
66 | ``` |
67 | |
68 | ```js |
69 | var instance = new slint.TestCase(); |
70 | |
71 | assert.equal(instance.num_ints, 5); |
72 | assert.equal(instance.n, 4); |
73 | assert.equal(instance.third_int, 3); |
74 | |
75 | let model = new slintlib.ArrayModel([1, 2, 3, 4, 5, 6, 7]); |
76 | instance.ints = model; |
77 | assert.equal(instance.num_ints, 7); |
78 | assert.equal(instance.third_int, 3); |
79 | model.push(8); |
80 | assert.equal(instance.num_ints, 8); |
81 | model.setRowData(2, 100); |
82 | assert.equal(instance.third_int, 100); |
83 | |
84 | assert.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 | } |