1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/globals/../../helper_components"# ] |
2 | #[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/globals"# ] |
3 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
4 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
5 | |
6 | //include_path: ../../helper_components |
7 | |
8 | global MyGlobal := { |
9 | property <int> hello: 42; |
10 | } |
11 | |
12 | export { MyGlobal } |
13 | export { MyGlobal as GlobalAlias } |
14 | |
15 | TestCase := Rectangle { |
16 | property <bool> test_global_prop_value: MyGlobal.hello == 100; |
17 | } |
18 | |
19 | /* |
20 | ```rust |
21 | let instance = TestCase::new().unwrap(); |
22 | assert!(!instance.get_test_global_prop_value()); |
23 | assert_eq!(MyGlobal::get(&instance).get_hello(), 42); |
24 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 42); |
25 | instance.global::<MyGlobal<'_>>().set_hello(100); |
26 | assert!(instance.get_test_global_prop_value()); |
27 | assert_eq!(MyGlobal::get(&instance).get_hello(), 100); |
28 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 100); |
29 | ``` |
30 | |
31 | ```cpp |
32 | auto handle = TestCase::create(); |
33 | const TestCase &instance = *handle; |
34 | assert(!instance.get_test_global_prop_value()); |
35 | assert_eq(instance.global<MyGlobal>().get_hello(), 42); |
36 | assert_eq(instance.global<GlobalAlias>().get_hello(), 42); |
37 | instance.global<MyGlobal>().set_hello(100); |
38 | assert(instance.get_test_global_prop_value()); |
39 | assert_eq(instance.global<MyGlobal>().get_hello(), 100); |
40 | assert_eq(instance.global<GlobalAlias>().get_hello(), 100); |
41 | |
42 | ``` |
43 | |
44 | ```js |
45 | let instance = new slint.TestCase({}); |
46 | assert(!instance.test_global_prop_value); |
47 | assert.equal(instance.MyGlobal.hello, 42);; |
48 | assert.equal(instance.GlobalAlias.hello, 42);; |
49 | instance.MyGlobal.hello = 100; |
50 | assert(instance.test_global_prop_value); |
51 | assert.equal(instance.MyGlobal.hello, 100); |
52 | assert.equal(instance.GlobalAlias.hello, 100); |
53 | ``` |
54 | |
55 | */ |
56 | } |
57 | |
58 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
59 | use i_slint_backend_testing as slint_testing; |
60 | slint_testing::init(); |
61 | let instance = TestCase::new().unwrap(); |
62 | assert!(!instance.get_test_global_prop_value()); |
63 | assert_eq!(MyGlobal::get(&instance).get_hello(), 42); |
64 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 42); |
65 | instance.global::<MyGlobal<'_>>().set_hello(100); |
66 | assert!(instance.get_test_global_prop_value()); |
67 | assert_eq!(MyGlobal::get(&instance).get_hello(), 100); |
68 | assert_eq!(GlobalAlias::get(&instance).get_hello(), 100); |
69 | Ok(()) |
70 | } |