1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases"# ] |
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 component TestCase { } |
6 | |
7 | /* |
8 | ```cpp |
9 | auto handle = TestCase::create(); |
10 | const TestCase &instance = *handle; |
11 | |
12 | // Check time mocking without event delivery happening: |
13 | auto start_time = slint_testing::get_mocked_time(); |
14 | slint_testing::mock_elapsed_time(512); |
15 | assert(slint_testing::get_mocked_time() == start_time + 512); |
16 | slint_testing::mock_elapsed_time(10333); |
17 | auto pre_event1_time = slint_testing::get_mocked_time(); |
18 | assert_eq(pre_event1_time, start_time + 512 + 10333); |
19 | |
20 | // Test that the first mouse event keeps time consistent |
21 | slint_testing::send_mouse_click(&instance, 5., 5.); |
22 | auto post_event1_time = slint_testing::get_mocked_time(); |
23 | assert(post_event1_time >= pre_event1_time && post_event1_time < pre_event1_time + 100); // allow for a bit of time for event handling... |
24 | |
25 | // Test that a second mouse event keeps time consistent |
26 | slint_testing::send_mouse_click(&instance, 5., 5.); |
27 | auto post_event2_time = slint_testing::get_mocked_time(); |
28 | assert(post_event2_time >= post_event1_time && post_event2_time < post_event1_time + 100); |
29 | |
30 | // Test that mocking works after mouse event delivery: |
31 | slint_testing::mock_elapsed_time(500000); |
32 | auto pre_event3_time = slint_testing::get_mocked_time(); |
33 | assert(pre_event3_time == post_event2_time + 500000); |
34 | |
35 | // Test that a new event does not break the mocked time again |
36 | slint_testing::send_mouse_click(&instance, 5., 5.); |
37 | auto post_event3_time = slint_testing::get_mocked_time(); |
38 | assert(post_event3_time >= pre_event3_time && post_event3_time <= pre_event3_time + 100); |
39 | ``` |
40 | |
41 | ```rust |
42 | let instance = TestCase::new().unwrap(); |
43 | |
44 | // Check time mocking without event delivery happening: |
45 | let start_time = slint_testing::get_mocked_time(); |
46 | slint_testing::mock_elapsed_time(512); |
47 | assert_eq!(slint_testing::get_mocked_time(), start_time + 512, "Mocked time is wrong"); |
48 | slint_testing::mock_elapsed_time(10333); |
49 | let pre_event1_time = slint_testing::get_mocked_time(); |
50 | assert_eq!(pre_event1_time, start_time + 512 + 10333); |
51 | |
52 | // Test that the first mouse event keeps time consistent |
53 | slint_testing::send_mouse_click(&instance, 5., 5.); |
54 | let post_event1_time = slint_testing::get_mocked_time(); |
55 | assert!(post_event1_time >= pre_event1_time && post_event1_time < pre_event1_time + 100); // allow for a bit of time for event handling... |
56 | |
57 | // Test that a second mouse event keeps time consistent |
58 | slint_testing::send_mouse_click(&instance, 5., 5.); |
59 | let post_event2_time = slint_testing::get_mocked_time(); |
60 | assert!(post_event2_time >= post_event1_time && post_event2_time < post_event1_time + 100); |
61 | |
62 | // Test that mocking works after mouse event delivery: |
63 | slint_testing::mock_elapsed_time(500000); |
64 | let pre_event3_time = slint_testing::get_mocked_time(); |
65 | assert_eq!(pre_event3_time, post_event2_time + 500000); |
66 | |
67 | // Test that a new event does not break the mocked time again |
68 | slint_testing::send_mouse_click(&instance, 5., 5.); |
69 | let post_event3_time = slint_testing::get_mocked_time(); |
70 | assert!(post_event3_time >= pre_event3_time && post_event3_time <= pre_event3_time + 100); |
71 | ``` |
72 | |
73 | ```js |
74 | var instance = new slint.TestCase({}); |
75 | |
76 | let start_time = slintlib.private_api.get_mocked_time(); |
77 | slintlib.private_api.mock_elapsed_time(512); |
78 | assert(slintlib.private_api.get_mocked_time() == start_time + 512); |
79 | slintlib.private_api.mock_elapsed_time(122); |
80 | assert(slintlib.private_api.get_mocked_time() == start_time + 512 + 122); |
81 | slintlib.private_api.mock_elapsed_time(10333); |
82 | assert(slintlib.private_api.get_mocked_time() == start_time + 512 + 122 + 10333); |
83 | |
84 | // FIXME: Sending a mouse event undoes the mock_elapsed_time calls on Node at this time! |
85 | // slintlib.private_api.send_mouse_click(instance, 5., 5.); |
86 | // assert(slintlib.private_api.get_mocked_time() == start_time + 512 + 122 + 10333); |
87 | ``` |
88 | |
89 | */ |
90 | } |
91 | |
92 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
93 | use i_slint_backend_testing as slint_testing; |
94 | slint_testing::init(); |
95 | let instance = TestCase::new().unwrap(); |
96 | |
97 | // Check time mocking without event delivery happening: |
98 | let start_time = slint_testing::get_mocked_time(); |
99 | slint_testing::mock_elapsed_time(512); |
100 | assert_eq!(slint_testing::get_mocked_time(), start_time + 512, "Mocked time is wrong" ); |
101 | slint_testing::mock_elapsed_time(10333); |
102 | let pre_event1_time = slint_testing::get_mocked_time(); |
103 | assert_eq!(pre_event1_time, start_time + 512 + 10333); |
104 | |
105 | // Test that the first mouse event keeps time consistent |
106 | slint_testing::send_mouse_click(&instance, 5., 5.); |
107 | let post_event1_time = slint_testing::get_mocked_time(); |
108 | assert!(post_event1_time >= pre_event1_time && post_event1_time < pre_event1_time + 100); // allow for a bit of time for event handling... |
109 | |
110 | // Test that a second mouse event keeps time consistent |
111 | slint_testing::send_mouse_click(&instance, 5., 5.); |
112 | let post_event2_time = slint_testing::get_mocked_time(); |
113 | assert!(post_event2_time >= post_event1_time && post_event2_time < post_event1_time + 100); |
114 | |
115 | // Test that mocking works after mouse event delivery: |
116 | slint_testing::mock_elapsed_time(500000); |
117 | let pre_event3_time = slint_testing::get_mocked_time(); |
118 | assert_eq!(pre_event3_time, post_event2_time + 500000); |
119 | |
120 | // Test that a new event does not break the mocked time again |
121 | slint_testing::send_mouse_click(&instance, 5., 5.); |
122 | let post_event3_time = slint_testing::get_mocked_time(); |
123 | assert!(post_event3_time >= pre_event3_time && post_event3_time <= pre_event3_time + 100); |
124 | Ok(()) |
125 | } |