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 | import { StyleMetrics } from "std-widgets.slint" ; |
9 | import { ExportedGlobal as ReexportedGlobal } from "export_globals.slint" ; |
10 | |
11 | struct MyStruct := { x:int, y: int, } |
12 | |
13 | global InternalGlobal := { |
14 | property <int> hello: 42; |
15 | property <MyStruct> my_struct; |
16 | pure callback sum(int, int)->int; |
17 | } |
18 | |
19 | export { InternalGlobal as PublicGlobal } |
20 | export { ReexportedGlobal } |
21 | |
22 | TestCase := Rectangle { |
23 | property <bool> test_global_prop_value: InternalGlobal.hello == 100; |
24 | property <int> test_call_callback: InternalGlobal.sum(6, 4); |
25 | } |
26 | |
27 | /* |
28 | ```rust |
29 | let instance = TestCase::new().unwrap(); |
30 | assert!(!instance.get_test_global_prop_value()); |
31 | assert_eq!(PublicGlobal::get(&instance).get_hello(), 42); |
32 | instance.global::<PublicGlobal<'_>>().set_hello(100); |
33 | assert!(instance.get_test_global_prop_value()); |
34 | |
35 | assert_eq!(ReexportedGlobal::get(&instance).get_foo(), 44); |
36 | |
37 | instance.global::<PublicGlobal<'_>>().on_sum(|a, b| a + b); |
38 | assert_eq!(instance.get_test_call_callback(), 10); |
39 | assert_eq!(instance.global::<PublicGlobal<'_>>().invoke_sum(4, 5), 9); |
40 | ``` |
41 | |
42 | ```cpp |
43 | auto handle = TestCase::create(); |
44 | const TestCase &instance = *handle; |
45 | assert(!instance.get_test_global_prop_value()); |
46 | assert_eq(instance.global<PublicGlobal>().get_hello(), 42); |
47 | instance.global<PublicGlobal>().set_hello(100); |
48 | assert(instance.get_test_global_prop_value()); |
49 | |
50 | assert_eq(instance.global<ReexportedGlobal>().get_foo(), 44); |
51 | |
52 | instance.global<PublicGlobal>().on_sum([](int a, int b) { return a + b; }); |
53 | assert_eq(instance.get_test_call_callback(), 10); |
54 | assert_eq(instance.global<PublicGlobal>().invoke_sum(4, 5), 9); |
55 | ``` |
56 | |
57 | ```js |
58 | let instance = new slint.TestCase({}); |
59 | assert(!instance.test_global_prop_value); |
60 | assert.equal(instance.PublicGlobal.hello, 42); |
61 | instance.PublicGlobal.hello = 100; |
62 | assert(instance.test_global_prop_value); |
63 | |
64 | assert.equal(instance.ReexportedGlobal.foo, 44); |
65 | instance.PublicGlobal.sum = function(a, b) { return a + b }; |
66 | assert.equal(instance.test_call_callback, 10); |
67 | assert.equal(instance.PublicGlobal.sum(4, 5), 9); |
68 | ``` |
69 | |
70 | */ |
71 | } |
72 | |
73 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
74 | use i_slint_backend_testing as slint_testing; |
75 | slint_testing::init(); |
76 | let instance = TestCase::new().unwrap(); |
77 | assert!(!instance.get_test_global_prop_value()); |
78 | assert_eq!(PublicGlobal::get(&instance).get_hello(), 42); |
79 | instance.global::<PublicGlobal<'_>>().set_hello(100); |
80 | assert!(instance.get_test_global_prop_value()); |
81 | |
82 | assert_eq!(ReexportedGlobal::get(&instance).get_foo(), 44); |
83 | |
84 | instance.global::<PublicGlobal<'_>>().on_sum(|a, b| a + b); |
85 | assert_eq!(instance.get_test_call_callback(), 10); |
86 | assert_eq!(instance.global::<PublicGlobal<'_>>().invoke_sum(4, 5), 9); |
87 | Ok(()) |
88 | } |