|
1 | 1 | use uefi::boot; |
2 | 2 | use uefi::proto::shell::{Shell, ShellFileHandle}; |
3 | 3 | use uefi::CStr16; |
| 4 | +use uefi::data_types::Char16; |
4 | 5 |
|
5 | 6 | pub fn test() { |
6 | 7 | info!("Running shell protocol tests"); |
7 | 8 |
|
8 | 9 | let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles"); |
9 | | - // let mut fs = uefi::fs::FileSystem::new(sfs |
10 | | - // let (fs_handle, mut sfs) = find_test_disk(); |
11 | 10 |
|
12 | 11 | let mut shell = |
13 | 12 | boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol"); |
14 | 13 |
|
15 | 14 | // create some files |
16 | | - let mut test_buf = [0u16; 12]; |
17 | | - let test_str = CStr16::from_str_with_buf("test", &mut test_buf).unwrap(); |
| 15 | + // let mut test_buf = [0u16; 12]; |
| 16 | + // let test_str = CStr16::from_str_with_buf("test", &mut test_buf).unwrap(); |
18 | 17 |
|
19 | | - let cur_env_str = shell.get_env(None).expect("Could not get environment variable"); |
20 | | - info!("cur_env_str size: {}", cur_env_str.num_chars()); |
21 | | - info!("cur_env_str: {}", cur_env_str); |
| 18 | + /* Test retrieving list of environment variable names (null input) */ |
| 19 | + let cur_env_vec = shell.get_env(None).expect("Could not get environment variable").vec().unwrap(); |
| 20 | + let mut test_buf = [0u16; 64]; |
| 21 | + assert_eq!(*cur_env_vec.get(0).unwrap(), CStr16::from_str_with_buf("path", &mut test_buf).unwrap()); |
| 22 | + assert_eq!(*cur_env_vec.get(1).unwrap(), CStr16::from_str_with_buf("nonesting", &mut test_buf).unwrap()); |
22 | 23 |
|
23 | | - /* Testing setting and getting a specific environment variable */ |
| 24 | + // Debug statements TODO: Remove |
| 25 | + info!("cur_env_vec size: {}", cur_env_vec.len()); |
| 26 | + for (i, env_var) in cur_env_vec.iter().enumerate() { |
| 27 | + info!("i: {}, env_var: {}", i, env_var); |
| 28 | + } |
| 29 | + |
| 30 | + /* Test setting and getting a specific environment variable */ |
24 | 31 | let mut test_env_buf = [0u16; 32]; |
25 | 32 | let test_var = CStr16::from_str_with_buf("test_var", &mut test_env_buf).unwrap(); |
26 | 33 | let mut test_val_buf = [0u16; 32]; |
27 | 34 | let test_val = CStr16::from_str_with_buf("test_val", &mut test_val_buf).unwrap(); |
28 | 35 | assert!(shell.get_env(Some(test_var)).is_none()); |
29 | 36 | shell.set_env(test_var, test_val, false); |
30 | | - let cur_env_str = shell.get_env(Some(test_var)).expect("Could not get environment variable"); |
| 37 | + let cur_env_str = shell.get_env(Some(test_var)).expect("Could not get environment variable").val().unwrap(); |
31 | 38 | assert_eq!(cur_env_str, test_val); |
32 | 39 |
|
33 | | - // for (i, c) in cur_env_str.iter().enumerate() { |
34 | | - // info!("cur_env_str: i: {}, c: {}", i, c); |
35 | | - // } |
36 | | - |
37 | 40 | // let mut cur_fs_buf = [0u16; 32]; |
38 | 41 | // let cur_fs_str = CStr16::from_str_with_buf("", &mut cur_fs_buf).unwrap(); |
39 | 42 | // info!("cur_fs_str size 1: {}", cur_fs_str.num_chars()); |
|
0 commit comments