| 1 | |
| 2 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 3 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 4 | |
| 5 | import { AboutSlint, Button } from "std-widgets.slint" ; |
| 6 | export component TestCase inherits Window { |
| 7 | |
| 8 | in-out property <string> app_title: "Application" ; |
| 9 | |
| 10 | in-out property <string> result; |
| 11 | |
| 12 | MenuBar { |
| 13 | Menu { |
| 14 | title: "File" ; |
| 15 | MenuItem { |
| 16 | title: "New" ; |
| 17 | activated => { result += self.title; debug("New" ); } |
| 18 | } |
| 19 | MenuItem { |
| 20 | title: "Open" ; |
| 21 | activated => { debug("Open" ); } |
| 22 | } |
| 23 | Menu { |
| 24 | title: "Open Recent" ; |
| 25 | for num in 45 : MenuItem { |
| 26 | title: "Recent " + num; |
| 27 | activated => { |
| 28 | if self.title != "Recent " + num { |
| 29 | result += "Error: invalid self.title" ; |
| 30 | } |
| 31 | result += self.title; |
| 32 | debug("Recent" , num); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | MenuItem { |
| 37 | title: "Save" ; |
| 38 | activated => { debug("Save" ); } |
| 39 | } |
| 40 | MenuSeparator {} |
| 41 | if true: MenuItem { |
| 42 | title: "Exit " + app_title; |
| 43 | activated => { |
| 44 | app_title = "Exited" ; |
| 45 | } |
| 46 | } |
| 47 | MenuSeparator {} |
| 48 | MenuSeparator {} |
| 49 | } |
| 50 | Menu { |
| 51 | title: "Edit" ; |
| 52 | MenuItem { |
| 53 | title: "Copy" ; |
| 54 | activated => { debug("Copy" ); } |
| 55 | } |
| 56 | MenuSeparator {} |
| 57 | if true: MenuItem { |
| 58 | title: "Paste" ; |
| 59 | activated => { debug("Paste" ); } |
| 60 | } |
| 61 | MenuSeparator {} |
| 62 | MenuItem { |
| 63 | title: "Disabled" ; |
| 64 | enabled: false; |
| 65 | activated => { result += self.title; } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | vl := VerticalLayout { |
| 70 | AboutSlint {} |
| 71 | Button { text: "Hello" ; } |
| 72 | } |
| 73 | |
| 74 | out property <bool> check-geometry: vl.x == 0 && vl.y == 0 && vl.width == root.width && vl.height == root.height; |
| 75 | |
| 76 | out property <bool> test: check-geometry; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | ```rust |
| 81 | use slint::{SharedString, platform::{Key}}; |
| 82 | let instance = TestCase::new().unwrap(); |
| 83 | assert!(instance.get_test()); |
| 84 | // click on the file menu |
| 85 | slint_testing::send_mouse_click(&instance, 10., 10.); |
| 86 | // navigate using the keys to the "Open Recent" menu item |
| 87 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 88 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 89 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 90 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow)); |
| 91 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow)); |
| 92 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow)); |
| 93 | assert_eq!(instance.get_result(), ""); |
| 94 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n")); |
| 95 | assert_eq!(instance.get_result(), "Recent 43"); |
| 96 | |
| 97 | instance.set_result("".into()); |
| 98 | slint_testing::send_mouse_click(&instance, 10., 10.); |
| 99 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 100 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n")); |
| 101 | assert_eq!(instance.get_result(), "New"); |
| 102 | |
| 103 | // ensure that disabled items can't activate |
| 104 | instance.set_result("".into()); |
| 105 | slint_testing::send_mouse_click(&instance, 100., 10.); |
| 106 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 107 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 108 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow)); |
| 109 | slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n")); |
| 110 | assert_eq!(instance.get_result(), ""); |
| 111 | |
| 112 | ``` |
| 113 | |
| 114 | ```cpp |
| 115 | auto handle = TestCase::create(); |
| 116 | const TestCase &instance = *handle; |
| 117 | assert(instance.get_test()); |
| 118 | // click on the file menu |
| 119 | slint_testing::send_mouse_click(&instance, 10., 10.); |
| 120 | // navigate using the keys to the "Open Recent" menu item |
| 121 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 122 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 123 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 124 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow); |
| 125 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow); |
| 126 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow); |
| 127 | assert_eq(instance.get_result(), ""); |
| 128 | slint_testing::send_keyboard_string_sequence(&instance, "\n"); |
| 129 | assert_eq(instance.get_result(), "Recent 43"); |
| 130 | |
| 131 | instance.set_result(""); |
| 132 | slint_testing::send_mouse_click(&instance, 10., 10.); |
| 133 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 134 | slint_testing::send_keyboard_string_sequence(&instance, "\n"); |
| 135 | assert_eq(instance.get_result(), "New"); |
| 136 | |
| 137 | // ensure that disabled items can't activate |
| 138 | instance.set_result(""); |
| 139 | slint_testing::send_mouse_click(&instance, 100., 10.); |
| 140 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 141 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 142 | slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow); |
| 143 | slint_testing::send_keyboard_string_sequence(&instance, "\n"); |
| 144 | assert_eq(instance.get_result(), ""); |
| 145 | |
| 146 | ``` |
| 147 | |
| 148 | ```js |
| 149 | var instance = new slint.TestCase(); |
| 150 | assert(instance.test); |
| 151 | // click on the file menu |
| 152 | slintlib.private_api.send_mouse_click(instance, 10., 10.); |
| 153 | // navigate using the keys to the "Open Recent" menu item |
| 154 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 155 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 156 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 157 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F703}"); |
| 158 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F700}"); |
| 159 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F700}"); |
| 160 | assert.equal(instance.result, ""); |
| 161 | slintlib.private_api.send_keyboard_string_sequence(instance, "\n"); |
| 162 | assert.equal(instance.result, "Recent 44"); |
| 163 | |
| 164 | instance.result = ""; |
| 165 | slintlib.private_api.send_mouse_click(instance, 10., 10.); |
| 166 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 167 | slintlib.private_api.send_keyboard_string_sequence(instance, "\n"); |
| 168 | assert.equal(instance.result, "New"); |
| 169 | |
| 170 | // ensure that disabled items can't activate |
| 171 | instance.result = ""; |
| 172 | slintlib.private_api.send_mouse_click(instance, 100., 10.); |
| 173 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 174 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 175 | slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}"); |
| 176 | slintlib.private_api.send_keyboard_string_sequence(instance, "\n"); |
| 177 | assert.equal(instance.result, ""); |
| 178 | |
| 179 | */ |
| 180 | |