|
1 | 1 | //! Tests for KeyLayoutMapManager file finding logic. |
2 | 2 | use assertables::{assert_iter_eq, assert_none, assert_ok, assert_result_ok, assert_some}; |
3 | | -use evdev_manager_core::android::android_codes::AKEYCODE_MINUS; |
| 3 | +use evdev_manager_core::android::android_codes::{ |
| 4 | + AKEYCODE_HOME, AKEYCODE_MINUS, AKEYCODE_MOVE_HOME, |
| 5 | +}; |
4 | 6 | use evdev_manager_core::android::keylayout::key_layout_map_manager::{ |
5 | 7 | KeyLayoutFileFinder, KeyLayoutMapManager, |
6 | 8 | }; |
@@ -237,6 +239,7 @@ fn test_map_key_reads_from_cache() { |
237 | 239 | ); |
238 | 240 | } |
239 | 241 |
|
| 242 | +#[test] |
240 | 243 | fn test_map_key_saves_to_cache() { |
241 | 244 | // Create a mock file finder that returns no files |
242 | 245 | let test_kl_path = get_test_data_path().join("Generic.kl"); |
@@ -285,3 +288,50 @@ fn test_map_key_finds_file_if_cache_miss() { |
285 | 288 |
|
286 | 289 | assert_eq!(map_key_result.key_code, AKEYCODE_MINUS); |
287 | 290 | } |
| 291 | + |
| 292 | +#[test] |
| 293 | +fn test_map_key_reads_first_found_path() { |
| 294 | + // Create a mock file finder that returns no files |
| 295 | + let mock_finder = MockFileFinder::new() |
| 296 | + .add_system_file("Generic", get_test_data_path().join("Generic.kl")) |
| 297 | + .add_system_file("gpio-keys", get_test_data_path().join("6t/gpio-keys.kl")); |
| 298 | + |
| 299 | + let manager = KeyLayoutMapManager::with_file_finder(Arc::new(mock_finder)); |
| 300 | + |
| 301 | + let device = DeviceIdentifier { |
| 302 | + name: "gpio-keys".to_string(), |
| 303 | + bus: 0x0003, |
| 304 | + vendor: 0x9999, |
| 305 | + product: 0x8888, |
| 306 | + version: 0x0001, |
| 307 | + }; |
| 308 | + |
| 309 | + // Verify the cached value is returned by comparing the pointers |
| 310 | + let map_key_result = manager.map_key(&device, 102).unwrap().unwrap(); |
| 311 | + |
| 312 | + // In gpio-keys.kl this is HOME and in Generic.kl this is MOVE_HOME |
| 313 | + assert_eq!(map_key_result.key_code, AKEYCODE_HOME); |
| 314 | +} |
| 315 | + |
| 316 | +#[test] |
| 317 | +fn test_map_key_reads_generic_if_device_specific_not_found() { |
| 318 | + // Create a mock file finder that returns no files |
| 319 | + let mock_finder = |
| 320 | + MockFileFinder::new().add_system_file("Generic", get_test_data_path().join("Generic.kl")); |
| 321 | + |
| 322 | + let manager = KeyLayoutMapManager::with_file_finder(Arc::new(mock_finder)); |
| 323 | + |
| 324 | + let device = DeviceIdentifier { |
| 325 | + name: "gpio-keys".to_string(), |
| 326 | + bus: 0x0003, |
| 327 | + vendor: 0x9999, |
| 328 | + product: 0x8888, |
| 329 | + version: 0x0001, |
| 330 | + }; |
| 331 | + |
| 332 | + // Verify the cached value is returned by comparing the pointers |
| 333 | + let map_key_result = manager.map_key(&device, 102).unwrap().unwrap(); |
| 334 | + |
| 335 | + // In gpio-keys.kl this is HOME and in Generic.kl this is MOVE_HOME |
| 336 | + assert_eq!(map_key_result.key_code, AKEYCODE_MOVE_HOME); |
| 337 | +} |
0 commit comments