|
| 1 | +use alloc::string::{String, ToString}; |
| 2 | +use alloc::vec::Vec; |
| 3 | +use uefi::prelude::*; |
| 4 | + |
| 5 | +use uefi::proto::loaded_image::LoadedImage; |
| 6 | +use uefi::proto::media::file::{Directory, File, FileAttribute, FileMode, FileSystemInfo}; |
| 7 | +use uefi::proto::media::fs::SimpleFileSystem; |
| 8 | +use uefi::table::boot::ScopedProtocol; |
| 9 | +use uefi::{proto, Identify}; |
| 10 | +use uefi_fs::{FileSystem, FileSystemError}; |
| 11 | + |
| 12 | +/// Tests functionality from the `uefi-fs` crate. |
| 13 | +pub fn test(sfs: ScopedProtocol<SimpleFileSystem>) { |
| 14 | + let mut fs = FileSystem::new(sfs); |
| 15 | + |
| 16 | + fs.create_dir("test_file_system_abs").unwrap(); |
| 17 | + |
| 18 | + // slash is transparently transformed to backslash |
| 19 | + fs.write("test_file_system_abs/foo", "hello").unwrap(); |
| 20 | + // absolute or relative paths are supported; ./ is ignored |
| 21 | + fs.copy("\\test_file_system_abs/foo", "\\test_file_system_abs/./bar").unwrap(); |
| 22 | + let read = fs.read("\\test_file_system_abs\\bar").unwrap(); |
| 23 | + let read = String::from_utf8(read).unwrap(); |
| 24 | + assert_eq!(read, "hello"); |
| 25 | + |
| 26 | + assert_eq!( |
| 27 | + fs.try_exists("test_file_system_abs\\barfoo"), |
| 28 | + Err(FileSystemError::OpenError("\\test_file_system_abs\\barfoo".to_string())) |
| 29 | + ); |
| 30 | + fs.rename("test_file_system_abs\\bar", "test_file_system_abs\\barfoo").unwrap(); |
| 31 | + assert!(fs.try_exists("test_file_system_abs\\barfoo").is_ok()); |
| 32 | + |
| 33 | + let entries = fs.read_dir("test_file_system_abs").unwrap() |
| 34 | + .map(|e| e.unwrap().file_name().to_string()) |
| 35 | + .collect::<Vec<_>>(); |
| 36 | + assert_eq!(&[".", "..", "foo", "barfoo"], entries.as_slice()); |
| 37 | +} |
0 commit comments